BUGFIX: library upload md5重复校验优化;

This commit is contained in:
shahaibo
2023-10-18 14:58:12 +08:00
parent 89d3349b49
commit 2b2fd1a72c
3 changed files with 32 additions and 3 deletions

View File

@@ -72,7 +72,8 @@ public class LibraryController {
@ApiParam("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取")
@RequestParam(value = "timeZone") String timeZone,
@RequestParam(value = "modelType") String modelType,
@RequestParam(value = "sex") String sex) {
@RequestParam(value = "sex") String sex,
@RequestParam(value = "checkMd5") Integer checkMd5) {
Assert.isTrue(!StringUtils.isEmpty(file.getOriginalFilename()),"Please select a file!");
Integer high =null;
Integer width =null;
@@ -87,8 +88,12 @@ public class LibraryController {
high = fileVO.getHigh();
width = fileVO.getWidth();
}
String md5 = MD5Utils.encryptFile(file);
if (checkMd5 == null || checkMd5 == 1) {
libraryService.checkMd5(level1Type, level2Type, sex, md5);
}
return Response.success(libraryService.upload(new LibraryUploadDTO(file, level1Type,level2Type,
timeZone, MD5Utils.encryptFile(file),high,width,modelType,sex)));
timeZone, md5,high,width,modelType,sex)));
}
@ApiOperation(value = "保存或者编辑template打点")
@PostMapping("/saveOrEditTemplatePoint")

View File

@@ -71,4 +71,6 @@ public interface LibraryService extends IService<Library> {
Boolean updateLibraryLevel2Type(LibraryLevel2TypeUpdateDTO libraryLevel2TypeUpdateDTO);
String processMannequins(String uploadPath);
void checkMd5(String level1Type, String level2Type, String sex, String md5);
}

View File

@@ -1,6 +1,7 @@
package com.ai.da.service.impl;
import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.system.UserInfo;
import com.ai.da.common.config.FileProperties;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.context.UserContext;
@@ -256,6 +257,27 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
throw new BusinessException("generate design exception!");
}
@Override
public void checkMd5(String level1Type, String level2Type, String sex, String md5) {
AuthPrincipalVo userInfo = UserContext.getUserHolder();
QueryWrapper<Library> qw = new QueryWrapper<>();
qw.lambda().eq(Library::getAccountId, userInfo.getId());
qw.lambda().eq(Library::getLevel1Type, level1Type);
if (!StringUtils.isEmpty(sex)) {
if (level1Type.equals(LibraryLevel1TypeEnum.SKETCH_BOARD)) {
qw.lambda().eq(Library::getLevel2Type, level2Type);
qw.lambda().eq(Library::getLevel3Type, sex);
}else {
qw.lambda().eq(Library::getLevel2Type, sex);
}
}
qw.lambda().eq(Library::getMd5, md5);
List<Library> libraryList = libraryMapper.selectList(qw);
if (!CollectionUtils.isEmpty(libraryList)) {
throw new BusinessException("Your library already contains the images you uploaded, Are you sure to upload them");
}
}
private Library resolveData(LibraryUploadDTO uploadDTO, AuthPrincipalVo userInfo, String filePath) {
if (StringUtils.isEmpty(uploadDTO.getModelType()) || uploadDTO.getModelType().equals(ModelType.LIBRARY.getValue())) {
Library library = CopyUtil.copyObject(uploadDTO, Library.class);
@@ -293,7 +315,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
if (StringUtils.isEmpty(modelSex)) {
return StringUtils.isEmpty(level2Type) ? userId + "/" + level1TypeEnum.getRealName().toLowerCase() : userId + "/" + level1TypeEnum.getRealName().toLowerCase() + "/" + level2Type;
}else {
return StringUtils.isEmpty(level2Type) ? userId + "/" + level1TypeEnum.getRealName().toLowerCase() + "/" + modelSex : userId + "/" + level1TypeEnum.getRealName().toLowerCase() + "/" + modelSex + "/" + level2Type;
return StringUtils.isEmpty(level2Type) ? userId + "/" + level1TypeEnum.getRealName().toLowerCase() + "/" + modelSex.toLowerCase() : userId + "/" + level1TypeEnum.getRealName().toLowerCase() + "/" + modelSex.toLowerCase() + "/" + level2Type;
}
}