2023-01-06 15:17:37 +08:00
|
|
|
package com.ai.da.controller;
|
|
|
|
|
|
|
|
|
|
import com.ai.da.common.config.FileProperties;
|
2023-10-04 06:47:48 +08:00
|
|
|
import com.ai.da.common.config.exception.BusinessException;
|
2023-01-06 15:17:37 +08:00
|
|
|
import com.ai.da.common.context.UserContext;
|
|
|
|
|
import com.ai.da.common.enums.LibraryLevel1TypeEnum;
|
|
|
|
|
import com.ai.da.common.response.PageBaseResponse;
|
|
|
|
|
import com.ai.da.common.response.Response;
|
2023-09-29 21:44:43 +08:00
|
|
|
import com.ai.da.common.utils.*;
|
2024-01-19 16:36:34 +08:00
|
|
|
import com.ai.da.mapper.primary.entity.Library;
|
|
|
|
|
import com.ai.da.mapper.primary.entity.LibraryModelPoint;
|
2023-01-06 15:17:37 +08:00
|
|
|
import com.ai.da.model.dto.*;
|
|
|
|
|
import com.ai.da.model.vo.*;
|
|
|
|
|
import com.ai.da.service.LibraryModelPointService;
|
|
|
|
|
import com.ai.da.service.LibraryService;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2023-10-19 16:12:42 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2023-01-06 15:17:37 +08:00
|
|
|
import org.springframework.util.StringUtils;
|
2025-08-18 16:18:51 +08:00
|
|
|
import org.springframework.validation.annotation.Validated;
|
2023-01-06 15:17:37 +08:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
2025-11-25 16:46:05 +08:00
|
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
import jakarta.validation.Valid;
|
2023-01-06 15:17:37 +08:00
|
|
|
import java.io.File;
|
2024-01-26 13:17:59 +08:00
|
|
|
import java.text.ParseException;
|
2025-05-19 14:02:42 +08:00
|
|
|
import java.util.*;
|
2023-01-06 15:17:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@Api(tags = "library模块")
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/library")
|
|
|
|
|
public class LibraryController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private LibraryService libraryService;
|
|
|
|
|
@Resource
|
|
|
|
|
private LibraryModelPointService libraryModelPointService;
|
|
|
|
|
@Resource
|
|
|
|
|
private FileProperties fileProperties;
|
2023-09-29 21:44:43 +08:00
|
|
|
@Resource
|
|
|
|
|
private MinioUtil minioUtil;
|
2023-01-06 15:17:37 +08:00
|
|
|
|
2023-10-19 16:12:42 +08:00
|
|
|
@Value("${minio.bucketName.sysImage}")
|
|
|
|
|
private String sysImage;
|
|
|
|
|
|
2023-01-06 15:17:37 +08:00
|
|
|
@ApiOperation(value = "Library分页列表")
|
|
|
|
|
@PostMapping("/queryLibraryPage")
|
|
|
|
|
public Response<PageBaseResponse<QueryLibraryPageVO>> queryLibraryPage(@Valid @RequestBody QueryLibraryPageDTO query) {
|
2023-10-20 14:47:18 +08:00
|
|
|
return Response.success(libraryService.queryLibraryPage(CopyUtil.copyObject(query, QueryLibraryPageServiceDTO.class)));
|
2023-01-06 15:17:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "Library分页列表(查询top和bottom)")
|
|
|
|
|
@PostMapping("/queryLibraryTopAndBottomPage")
|
|
|
|
|
public Response<PageBaseResponse<QueryLibraryPageVO>> queryLibraryTopAndBottomPage(@Valid @RequestBody QueryLibraryTopPageDTO query) {
|
2023-10-20 14:47:18 +08:00
|
|
|
return Response.success(libraryService.queryLibraryPage(CopyUtil.copyObject(query, QueryLibraryPageServiceDTO.class)));
|
2023-01-06 15:17:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "Library文件上传")
|
|
|
|
|
@PostMapping("/upload")
|
|
|
|
|
public Response<LibraryUpdateVo> upload(@RequestParam("file") MultipartFile file,
|
|
|
|
|
@ApiParam("一级类型 Moodboard Printboard Sketchboard MarketingSketch Models")
|
2023-10-20 14:47:18 +08:00
|
|
|
@RequestParam(value = "level1Type") String level1Type,
|
2023-01-06 15:17:37 +08:00
|
|
|
@ApiParam("二级类型 争对 Sketchboard; 有 Outwear Dress Blouse Skirt Trousers")
|
2023-10-20 14:47:18 +08:00
|
|
|
@RequestParam(value = "level2Type", required = false) String level2Type,
|
2023-01-06 15:17:37 +08:00
|
|
|
@ApiParam("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取")
|
2023-10-20 14:47:18 +08:00
|
|
|
@RequestParam(value = "timeZone") String timeZone,
|
2023-10-04 06:47:48 +08:00
|
|
|
@RequestParam(value = "modelType") String modelType,
|
2023-10-18 14:58:12 +08:00
|
|
|
@RequestParam(value = "sex") String sex,
|
2025-04-01 15:20:59 +08:00
|
|
|
@RequestParam(value = "ageGroup") String ageGroup,
|
2023-10-18 14:58:12 +08:00
|
|
|
@RequestParam(value = "checkMd5") Integer checkMd5) {
|
2023-10-31 14:07:43 +08:00
|
|
|
if (null == file || StringUtils.isEmpty(file.getOriginalFilename())) {
|
|
|
|
|
throw new BusinessException("file.cannot.be.empty");
|
|
|
|
|
}
|
2023-10-20 14:47:18 +08:00
|
|
|
Integer high = null;
|
|
|
|
|
Integer width = null;
|
|
|
|
|
if (level1Type.equals(LibraryLevel1TypeEnum.MODELS.getRealName())) {
|
2023-10-04 06:47:48 +08:00
|
|
|
if (StringUtils.isEmpty(modelType)) {
|
2023-10-31 14:07:43 +08:00
|
|
|
throw new BusinessException("modelType.cannot.be.empty");
|
2023-10-04 06:47:48 +08:00
|
|
|
}
|
2023-11-03 14:59:19 +08:00
|
|
|
if (StringUtils.isEmpty(sex)) {
|
2023-10-31 14:07:43 +08:00
|
|
|
throw new BusinessException("modelSex.cannot.be.empty");
|
2023-10-04 06:47:48 +08:00
|
|
|
}
|
2023-01-06 15:17:37 +08:00
|
|
|
FileVO fileVO = FileUtil.getFileSize(file);
|
|
|
|
|
high = fileVO.getHigh();
|
|
|
|
|
width = fileVO.getWidth();
|
|
|
|
|
}
|
2023-10-18 14:58:12 +08:00
|
|
|
String md5 = MD5Utils.encryptFile(file);
|
|
|
|
|
if (checkMd5 == null || checkMd5 == 1) {
|
2023-10-18 15:54:23 +08:00
|
|
|
if (!libraryService.checkMd5(level1Type, level2Type, sex, md5)) {
|
|
|
|
|
LibraryUpdateVo libraryUpdateVo = new LibraryUpdateVo();
|
|
|
|
|
libraryUpdateVo.setCheckMd5(Boolean.FALSE);
|
|
|
|
|
return Response.success(libraryUpdateVo);
|
|
|
|
|
}
|
2023-10-18 14:58:12 +08:00
|
|
|
}
|
2023-10-20 14:47:18 +08:00
|
|
|
return Response.success(libraryService.upload(new LibraryUploadDTO(file, level1Type, level2Type,
|
2025-04-01 15:20:59 +08:00
|
|
|
timeZone, md5, high, width, modelType, sex, ageGroup)));
|
2023-01-06 15:17:37 +08:00
|
|
|
}
|
2023-10-20 14:47:18 +08:00
|
|
|
|
2023-01-06 15:17:37 +08:00
|
|
|
@ApiOperation(value = "保存或者编辑template打点")
|
|
|
|
|
@PostMapping("/saveOrEditTemplatePoint")
|
|
|
|
|
public Response<LibraryModelPointVO> saveOrEditTemplatePoint(@Valid @RequestBody LibraryModelPointDTO libraryModelPoint) {
|
|
|
|
|
return Response.success(libraryModelPointService.saveOrEditTemplatePoint(libraryModelPoint));
|
|
|
|
|
}
|
2023-10-20 14:47:18 +08:00
|
|
|
|
2023-01-06 15:17:37 +08:00
|
|
|
@ApiOperation(value = "批量Library修改用户文件名")
|
|
|
|
|
@PostMapping("/batchUpdateLibraryName")
|
|
|
|
|
public Response<Boolean> batchUpdateLibraryName(@Valid @RequestBody LibraryUpdateDTO libraryUpdateDTO) {
|
|
|
|
|
libraryService.updateLibraryName(libraryUpdateDTO);
|
|
|
|
|
return Response.success(Boolean.TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "批量删除library")
|
|
|
|
|
@PostMapping("/batchDeleteLibrary")
|
|
|
|
|
public Response<Boolean> batchDeleteLibrary(@Valid @RequestBody LibraryDeleteDTO deleteDTO) {
|
2023-11-07 11:32:03 +08:00
|
|
|
libraryService.batchDeleteLibrary(deleteDTO);
|
2023-01-06 15:17:37 +08:00
|
|
|
return Response.success(Boolean.TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "Models打点预览")
|
|
|
|
|
@PostMapping("/modelsDot")
|
2023-10-20 14:47:18 +08:00
|
|
|
public Response<String> modelsDot(@ApiParam("file") @RequestPart(value = "file", required = false) MultipartFile file,
|
|
|
|
|
@ApiParam("models对象") @RequestPart("models") ModelsDotDTO modelsDotDTO) {
|
|
|
|
|
if (Objects.nonNull(file)) {
|
2023-10-31 14:07:43 +08:00
|
|
|
if (StringUtils.isEmpty(file.getOriginalFilename())) {
|
|
|
|
|
throw new BusinessException("file.cannot.be.empty");
|
|
|
|
|
}
|
2023-01-06 15:17:37 +08:00
|
|
|
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
|
|
|
|
//需要宽高和地址参数design
|
|
|
|
|
FileVO fileVO = FileUtil.getFileSize(file);
|
|
|
|
|
modelsDotDTO.setHigh(fileVO.getHigh());
|
|
|
|
|
modelsDotDTO.setWidth(fileVO.getWidth());
|
|
|
|
|
//存储template临时地址
|
2023-10-16 10:53:37 +08:00
|
|
|
String path = calculateTempFileUrlNew(userInfo.getId());
|
|
|
|
|
String uploadPath = minioUtil.upload("aida-tmp", path, file);
|
2023-10-16 11:42:20 +08:00
|
|
|
String minioPath = libraryService.processMannequins(uploadPath);
|
|
|
|
|
modelsDotDTO.setTemplateUrl(minioPath);
|
2023-10-20 14:47:18 +08:00
|
|
|
} else {
|
2023-10-31 14:07:43 +08:00
|
|
|
if (null == modelsDotDTO.getLibraryId()) {
|
|
|
|
|
throw new BusinessException("libraryId.cannot.be.empty");
|
|
|
|
|
}
|
|
|
|
|
if (null == modelsDotDTO.getTemplateId()) {
|
|
|
|
|
throw new BusinessException("templateId.cannot.be.empty");
|
|
|
|
|
}
|
2023-01-06 15:17:37 +08:00
|
|
|
LibraryModelPoint modelPoint = libraryModelPointService.getById(modelsDotDTO.getTemplateId());
|
2023-10-31 14:07:43 +08:00
|
|
|
if (Objects.isNull(modelPoint)) {
|
|
|
|
|
throw new BusinessException("modelPoint.not.found");
|
|
|
|
|
}
|
2023-01-06 15:17:37 +08:00
|
|
|
Library library = libraryService.getById(modelsDotDTO.getLibraryId());
|
2023-10-31 14:07:43 +08:00
|
|
|
if (Objects.isNull(library)) {
|
|
|
|
|
throw new BusinessException("library.not.found");
|
|
|
|
|
}
|
2023-01-06 15:17:37 +08:00
|
|
|
modelsDotDTO.setHigh(library.getHigh());
|
|
|
|
|
modelsDotDTO.setWidth(library.getWidth());
|
|
|
|
|
modelsDotDTO.setTemplateUrl(library.getUrl());
|
|
|
|
|
}
|
2023-10-20 14:47:18 +08:00
|
|
|
Response<String> response = new Response();
|
2023-01-06 15:17:37 +08:00
|
|
|
log.info("Models打点预览入参####{}", JSON.toJSONString(modelsDotDTO));
|
|
|
|
|
String url = libraryModelPointService.modelsDot(modelsDotDTO);
|
2024-07-03 16:43:22 +08:00
|
|
|
response.setData(minioUtil.getPreSignedUrl(url, 24 * 60));
|
2023-01-06 15:17:37 +08:00
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-29 21:44:43 +08:00
|
|
|
@ApiOperation(value = "更新sketchboard level2type")
|
|
|
|
|
@PostMapping("/updateLibraryLevel2Type")
|
2025-08-18 16:18:51 +08:00
|
|
|
public Response<Boolean> updateLibraryLevel2Type(@Validated @RequestBody LibraryLevel2TypeUpdateDTO libraryLevel2TypeUpdateDTO) {
|
2023-09-29 21:44:43 +08:00
|
|
|
return Response.success(libraryService.updateLibraryLevel2Type(libraryLevel2TypeUpdateDTO));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 15:17:37 +08:00
|
|
|
private String calculateTempFileUrl(Long userId) {
|
|
|
|
|
String rootPath = fileProperties.getSys().getPath();
|
|
|
|
|
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
2023-10-27 10:09:19 +08:00
|
|
|
return rootPath + day + File.separator + "tmp" + File.separator + userId + File.separator + UUID.randomUUID();
|
2023-01-06 15:17:37 +08:00
|
|
|
}
|
2023-09-22 16:28:33 +08:00
|
|
|
|
2023-10-16 10:53:37 +08:00
|
|
|
private String calculateTempFileUrlNew(Long userId) {
|
|
|
|
|
return userId.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-20 14:47:18 +08:00
|
|
|
private String calculateTemplateUrl(File uploadFile) {
|
2023-01-06 15:17:37 +08:00
|
|
|
String linuxDomain = fileProperties.getLinuxDomain();
|
|
|
|
|
if (!StringUtils.isEmpty(linuxDomain)) {
|
|
|
|
|
//linux 系统
|
|
|
|
|
String oldPath = fileProperties.getSys().getPath();
|
|
|
|
|
return uploadFile.getAbsolutePath().replace(oldPath, linuxDomain);
|
|
|
|
|
}
|
|
|
|
|
//本地用
|
|
|
|
|
// return "/home/pangkaicheng/python_code/Multi-layer-Virtual-Try-on/dataset_for_test/Img_model.png";
|
|
|
|
|
return "/workspace/python_code/Multi-layer-Virtual-Try-on/dataset_for_test/Img_model.png";
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 13:17:59 +08:00
|
|
|
@PostMapping("moveLibraryData")
|
|
|
|
|
@ApiOperation(value = "用户library数据迁移")
|
|
|
|
|
public Response<Boolean> moveLibraryDate() throws ParseException {
|
|
|
|
|
libraryService.moveLibraryDate();
|
|
|
|
|
return Response.success(true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 17:15:38 +08:00
|
|
|
@ApiOperation(value = "将系统模特添加到个人library")
|
2025-04-02 11:08:35 +08:00
|
|
|
@GetMapping("addSysModelToLib")
|
2025-04-02 13:32:12 +08:00
|
|
|
public Response<Map<String, String>> addSysModelToLib(@ApiParam("系统模特id") @RequestParam("sysModelId")long sysModelId){
|
2025-04-01 17:15:38 +08:00
|
|
|
return Response.success(libraryService.addSysModelToLib(sysModelId));
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-19 14:02:42 +08:00
|
|
|
@ApiOperation(value = "将个人library元素添加到公共库")
|
|
|
|
|
@GetMapping("addToPublicLibrary")
|
|
|
|
|
public Response<String> addToPublicLibrary(@ApiParam("元素的libraryId") @RequestParam("libraryId") Long libraryId){
|
|
|
|
|
boolean b = libraryService.saveToOrganizationLibrary(libraryId);
|
|
|
|
|
if (b){
|
|
|
|
|
return Response.success("success");
|
|
|
|
|
}else {
|
|
|
|
|
return Response.success("fail");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "将个人library元素从公共库中删除")
|
|
|
|
|
@GetMapping("deleteFromPublicLib")
|
|
|
|
|
public Response<String> deleteFromPublicLib(@ApiParam("元素的libraryId") @RequestParam("libraryId") Long libraryId){
|
|
|
|
|
libraryService.deleteFromPublicLib(libraryId);
|
|
|
|
|
return Response.success("success");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "获取公共库")
|
|
|
|
|
@GetMapping("getPublicLib")
|
|
|
|
|
public Response<PageBaseResponse<Library>> getPublicLib(@ApiParam("排序" ) @RequestParam(value = "order", defaultValue = "DESC", required = false) String order,
|
|
|
|
|
@ApiParam("page") @RequestParam(value = "page", defaultValue = "1", required = false) Long page,
|
|
|
|
|
@ApiParam("size") @RequestParam(value = "size", defaultValue = "20", required = false) Long size){
|
|
|
|
|
|
|
|
|
|
return Response.success(libraryService.getPublicLib(order, page, size));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "管理员获取所有子账号lib元素")
|
|
|
|
|
@GetMapping("getAllSubAccLib")
|
|
|
|
|
public Response<PageBaseResponse<Library>> getAllSubAccLib(@ApiParam("排序") @RequestParam(value = "order", defaultValue = "DESC", required = false) String order,
|
|
|
|
|
@ApiParam("page") @RequestParam(value = "page", defaultValue = "1", required = false) Long page,
|
|
|
|
|
@ApiParam("size") @RequestParam(value = "size", defaultValue = "20", required = false) Long size){
|
|
|
|
|
return Response.success(libraryService.getAllSubAccLib(order, page, size));
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-13 11:40:37 +08:00
|
|
|
@ApiOperation(value = "将系统sketch添加到library")
|
|
|
|
|
@GetMapping("addSysSketchToLibrary")
|
|
|
|
|
public Response<String> addSysSketchToLibrary(Long clothId, String path) {
|
|
|
|
|
return Response.success(libraryService.addSysSketchToLibrary(clothId, path));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 15:17:37 +08:00
|
|
|
}
|