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

@@ -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;
}
}