TASK: 全局异常优化;

This commit is contained in:
shahaibo
2023-10-31 14:07:43 +08:00
parent 68d28995b8
commit 44a30bf9b5
40 changed files with 517 additions and 211 deletions

View File

@@ -1,5 +1,6 @@
package com.ai.da.controller;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.response.Response;
import com.ai.da.common.utils.FileUtil;
import com.ai.da.common.utils.MD5Utils;
@@ -53,7 +54,9 @@ public class ElementController {
@RequestParam(value = "level1Type") String level1Type,
@ApiParam("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取")
@RequestParam(value = "timeZone") String timeZone) {
Assert.isTrue(!StringUtils.isEmpty(file.getOriginalFilename()), "Please select a file!");
if (null == file || StringUtils.isEmpty(file.getOriginalFilename())) {
throw new BusinessException("file.cannot.be.empty");
}
return Response.success(collectionElementService.upload(
new CollectionElementUploadDTO(file, level1Type, timeZone, MD5Utils.encryptFile(file))));
}

View File

@@ -23,6 +23,7 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -78,15 +79,17 @@ public class LibraryController {
@RequestParam(value = "modelType") String modelType,
@RequestParam(value = "sex") String sex,
@RequestParam(value = "checkMd5") Integer checkMd5) {
Assert.isTrue(!StringUtils.isEmpty(file.getOriginalFilename()), "Please select a file!");
if (null == file || StringUtils.isEmpty(file.getOriginalFilename())) {
throw new BusinessException("file.cannot.be.empty");
}
Integer high = null;
Integer width = null;
if (level1Type.equals(LibraryLevel1TypeEnum.MODELS.getRealName())) {
if (StringUtils.isEmpty(modelType)) {
throw new BusinessException("modelType can't be null");
throw new BusinessException("modelType.cannot.be.empty");
}
if (modelType.equals(ModelType.SYSTEM.getValue()) && StringUtils.isEmpty(sex)) {
throw new BusinessException("sex can't be null");
throw new BusinessException("modelSex.cannot.be.empty");
}
FileVO fileVO = FileUtil.getFileSize(file);
high = fileVO.getHigh();
@@ -121,7 +124,9 @@ public class LibraryController {
@PostMapping("/batchDeleteLibrary")
public Response<Boolean> batchDeleteLibrary(@Valid @RequestBody LibraryDeleteDTO deleteDTO) {
List<Library> librarys = libraryService.getByIds(deleteDTO.getLibraryIds());
Assert.notEmpty(librarys, "librarys does not exist!");
if (CollectionUtils.isEmpty(librarys)) {
throw new BusinessException("librarys.not.found");
}
libraryService.removeBatchByIds(deleteDTO.getLibraryIds());
for (Library library : librarys) {
if (library.getUrl().startsWith(sysImage)) {
@@ -138,7 +143,9 @@ public class LibraryController {
public Response<String> modelsDot(@ApiParam("file") @RequestPart(value = "file", required = false) MultipartFile file,
@ApiParam("models对象") @RequestPart("models") ModelsDotDTO modelsDotDTO) {
if (Objects.nonNull(file)) {
Assert.isTrue(!StringUtils.isEmpty(file.getOriginalFilename()), "Please select a file!");
if (StringUtils.isEmpty(file.getOriginalFilename())) {
throw new BusinessException("file.cannot.be.empty");
}
AuthPrincipalVo userInfo = UserContext.getUserHolder();
//需要宽高和地址参数design
FileVO fileVO = FileUtil.getFileSize(file);
@@ -150,12 +157,20 @@ public class LibraryController {
String minioPath = libraryService.processMannequins(uploadPath);
modelsDotDTO.setTemplateUrl(minioPath);
} else {
Assert.notNull(modelsDotDTO.getLibraryId(), "libraryId cannot be empty!");
Assert.notNull(modelsDotDTO.getTemplateId(), "templateId cannot be empty!");
if (null == modelsDotDTO.getLibraryId()) {
throw new BusinessException("libraryId.cannot.be.empty");
}
if (null == modelsDotDTO.getTemplateId()) {
throw new BusinessException("templateId.cannot.be.empty");
}
LibraryModelPoint modelPoint = libraryModelPointService.getById(modelsDotDTO.getTemplateId());
Assert.notNull(modelPoint, "template does not exist!");
if (Objects.isNull(modelPoint)) {
throw new BusinessException("modelPoint.not.found");
}
Library library = libraryService.getById(modelsDotDTO.getLibraryId());
Assert.notNull(library, "library does not exist!");
if (Objects.isNull(library)) {
throw new BusinessException("library.not.found");
}
modelsDotDTO.setHigh(library.getHigh());
modelsDotDTO.setWidth(library.getWidth());
modelsDotDTO.setTemplateUrl(library.getUrl());

View File

@@ -1,5 +1,6 @@
package com.ai.da.controller;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.response.PageResponse;
@@ -75,7 +76,9 @@ public class SavedCollectionController {
}
List<Long> groupIds = page.getRecords().stream().map(UserLikeGroup::getId).collect(Collectors.toList());
List<UserLikeVO> groupDetails = userLikeService.getGroupDetails(groupIds);
Assert.notEmpty(groupDetails, "History detail does not exist!");
if (CollectionUtils.isEmpty(groupDetails)) {
throw new BusinessException("groupDetails.not.found");
}
Map<Long, List<UserLikeVO>> groupDetailMap = groupDetails.stream()
.collect(Collectors.groupingBy(UserLikeVO::getUserLikeGroupId));