BUGFIX: 模特删除校验;

TASK: 多语言;
This commit is contained in:
shahaibo
2023-11-07 11:32:03 +08:00
parent bb1c56182e
commit 008d0d626e
7 changed files with 93 additions and 14 deletions

View File

@@ -74,7 +74,7 @@ public class AccountController {
return Response.success(accountService.getUserLanguage());
}
@ApiOperation(value = "获取当前用户语言")
@ApiOperation(value = "切换当前用户语言")
@PostMapping("/changeUserLanguage")
public Response<String> changeUserLanguage(String language) {
return Response.success(accountService.changeUserLanguage(language));

View File

@@ -123,17 +123,7 @@ public class LibraryController {
@ApiOperation(value = "批量删除library")
@PostMapping("/batchDeleteLibrary")
public Response<Boolean> batchDeleteLibrary(@Valid @RequestBody LibraryDeleteDTO deleteDTO) {
List<Library> librarys = libraryService.getByIds(deleteDTO.getLibraryIds());
if (CollectionUtils.isEmpty(librarys)) {
throw new BusinessException("librarys.not.found");
}
libraryService.removeBatchByIds(deleteDTO.getLibraryIds());
for (Library library : librarys) {
if (library.getUrl().startsWith(sysImage)) {
continue;
}
minioUtil.deleteObject(library.getUrl());
}
libraryService.batchDeleteLibrary(deleteDTO);
return Response.success(Boolean.TRUE);
}

View File

@@ -19,4 +19,5 @@ public class LibraryDeleteDTO {
@ApiModelProperty("libraryId数组")
private List<Long> libraryIds;
private Integer deleteModelConfirm;
}

View File

@@ -20,7 +20,7 @@ public class LibraryModelPointVO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("libraryId")
@ApiModelProperty("relationId")
private Long relationId;
@ApiModelProperty("templateId")

View File

@@ -79,4 +79,6 @@ public interface LibraryService extends IService<Library> {
String processMannequins(String uploadPath);
Boolean checkMd5(String level1Type, String level2Type, String sex, String md5);
void batchDeleteLibrary(LibraryDeleteDTO deleteDTO);
}

View File

@@ -1,5 +1,6 @@
package com.ai.da.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.system.UserInfo;
import com.ai.da.common.config.FileProperties;
@@ -12,13 +13,17 @@ import com.ai.da.common.utils.DateUtil;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.mapper.LibraryMapper;
import com.ai.da.mapper.SysFileMapper;
import com.ai.da.mapper.WorkspaceMapper;
import com.ai.da.mapper.entity.*;
import com.ai.da.model.dto.*;
import com.ai.da.model.enums.MannequinType;
import com.ai.da.model.enums.ModelType;
import com.ai.da.model.enums.Sex;
import com.ai.da.model.vo.*;
import com.ai.da.python.vo.ModelPathObject;
import com.ai.da.service.LibraryModelPointService;
import com.ai.da.service.LibraryService;
import com.ai.da.service.WorkspaceService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
@@ -60,6 +65,8 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
@Resource
private LibraryModelPointService libraryModelPointService;
@Resource
private WorkspaceService workspaceService;
@Resource
private MinioUtil minioUtil;
@Value("${minio.bucketName.users}")
@@ -298,6 +305,84 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
}
}
@Override
public void batchDeleteLibrary(LibraryDeleteDTO deleteDTO) {
List<Library> librarys = libraryMapper.selectBatchIds(deleteDTO.getLibraryIds());
if (CollectionUtils.isEmpty(librarys)) {
throw new BusinessException("librarys.not.found");
}
List<Long> femaleModelIds = librarys.stream()
.filter(o -> o.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName()) && o.getLevel2Type().equals(Sex.FEMALE.getValue()))
.map(Library::getId)
.collect(Collectors.toList());
List<Long> maleModelIds = librarys.stream()
.filter(o -> o.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName()) && o.getLevel2Type().equals(Sex.FEMALE.getValue()))
.map(Library::getId)
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(femaleModelIds)) {
// 检测模特是否被工作空间引用
checkModel(Sex.FEMALE.getValue(), femaleModelIds, deleteDTO.getDeleteModelConfirm());
}
if (CollectionUtil.isNotEmpty(maleModelIds)) {
checkModel(Sex.MALE.getValue(), maleModelIds, deleteDTO.getDeleteModelConfirm());
}
libraryMapper.deleteBatchIds(deleteDTO.getLibraryIds());
// for (Library library : librarys) {
// if (library.getUrl().startsWith(sysImage)) {
// continue;
// }
// minioUtil.deleteObject(library.getUrl());
// }
}
private void checkModel(String value, List<Long> modelIds, Integer deleteModelConfirm) {
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
QueryWrapper<Workspace> qw = new QueryWrapper<>();
qw.lambda().eq(Workspace::getUserName, authPrincipalVo.getUsername());
if (value.equals(Sex.FEMALE.getValue())) {
qw.lambda().in(Workspace::getMannequinFemaleId, modelIds);
}
if (value.equals(Sex.MALE.getValue())) {
qw.lambda().in(Workspace::getMannequinMaleId, modelIds);
}
// TODO:isDeleted设置
qw.lambda().eq(Workspace::getIsDeleted, 0L);
List<Workspace> workspaceList = workspaceService.list(qw);
if (CollectionUtil.isNotEmpty(workspaceList)) {
if (deleteModelConfirm.equals(0)) {
throw new BusinessException("the.model.has.been.referenced.by.the.workspace");
}
if (value.equals(Sex.FEMALE.getValue())) {
QueryWrapper<SysFile> systemFemaleQw = new QueryWrapper<>();
systemFemaleQw.lambda().eq(SysFile::getLevel1Type, "Models");
systemFemaleQw.lambda().eq(SysFile::getLevel2Type, "Female");
List<SysFile> sysFemaleFiles = sysFileMapper.selectList(systemFemaleQw);
if (!CollectionUtils.isEmpty(sysFemaleFiles)) {
for (Workspace workspace : workspaceList) {
workspace.setMannequinFemaleId(sysFemaleFiles.get(0).getId());
workspace.setMannequinFemaleType(MannequinType.SYSTEM.getValue());
}
workspaceService.updateBatchById(workspaceList);
}
}
if (value.equals(Sex.MALE.getValue())) {
QueryWrapper<SysFile> systemMaleQw = new QueryWrapper<>();
systemMaleQw.lambda().eq(SysFile::getLevel1Type, "Models");
systemMaleQw.lambda().eq(SysFile::getLevel2Type, "Male");
List<SysFile> sysMaleFiles = sysFileMapper.selectList(systemMaleQw);
if (!CollectionUtils.isEmpty(sysMaleFiles)) {
for (Workspace workspace : workspaceList) {
workspace.setMannequinMaleId(sysMaleFiles.get(0).getId());
workspace.setMannequinMaleType(MannequinType.SYSTEM.getValue());
}
workspaceService.updateBatchById(workspaceList);
}
}
}
}
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);