Files
aida_back/src/main/java/com/ai/da/controller/ElementController.java

144 lines
6.7 KiB
Java
Raw Normal View History

2023-01-06 15:17:37 +08:00
package com.ai.da.controller;
2023-10-31 14:07:43 +08:00
import com.ai.da.common.config.exception.BusinessException;
2023-01-06 15:17:37 +08:00
import com.ai.da.common.response.Response;
import com.ai.da.common.utils.MD5Utils;
import com.ai.da.model.dto.*;
import com.ai.da.model.vo.*;
import com.ai.da.service.CollectionElementService;
import com.ai.da.service.PanToneService;
import com.ai.da.service.SysFileService;
2025-12-11 10:35:08 +08:00
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
2023-01-06 15:17:37 +08:00
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
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;
import jakarta.validation.constraints.Pattern;
2025-04-14 13:26:56 +08:00
import java.util.Arrays;
2023-01-06 15:17:37 +08:00
import java.util.List;
2025-04-14 13:26:56 +08:00
import java.util.stream.Collectors;
2023-01-06 15:17:37 +08:00
2025-12-11 10:35:08 +08:00
@Tag(name = "collection模块")
2023-01-06 15:17:37 +08:00
@Slf4j
@RestController
@RequestMapping("/api/element")
public class ElementController {
@Resource
private CollectionElementService collectionElementService;
@Resource
private PanToneService panToneService;
@Resource
private SysFileService sysFileService;
2025-12-11 10:35:08 +08:00
@Operation(summary = "初始化系统文件")
2023-01-06 15:17:37 +08:00
@PostMapping("/initDefaultSysFile")
public Response<Boolean> initDefaultSysFile(@RequestParam("validate") String validateUse) {
if (validateUse.equals("da_fl_mm_dad88888")) {
//防止被调用
sysFileService.initDefaultSysFile();
}
return Response.success();
}
2025-12-11 10:35:08 +08:00
@Operation(summary = "element文件上传")
2023-01-06 15:17:37 +08:00
@PostMapping("/upload")
public Response<CollectionElementVO> upload(@RequestParam("file") MultipartFile file,
2025-12-11 10:35:08 +08:00
@Parameter(description = "一级类型 Moodboard Printboard Sketchboard MarketingSketch Colorboard")
2023-01-06 15:17:37 +08:00
@RequestParam(value = "level1Type") String level1Type,
2023-12-11 15:32:53 +08:00
@RequestParam(name = "gender", required = false) String gender,
@RequestParam(name = "level2Type", required = false) String level2Type,
@RequestParam(name = "projectId", required = false) Long projectId,
2025-12-11 10:35:08 +08:00
@Parameter(description = "本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取")
2023-01-06 15:17:37 +08:00
@RequestParam(value = "timeZone") String timeZone) {
2023-10-31 14:07:43 +08:00
if (null == file || StringUtils.isEmpty(file.getOriginalFilename())) {
throw new BusinessException("file.cannot.be.empty");
}
2023-01-06 15:17:37 +08:00
return Response.success(collectionElementService.upload(
new CollectionElementUploadDTO(file, projectId, level1Type, level2Type, gender, timeZone, MD5Utils.encryptFile(file))));
2023-01-06 15:17:37 +08:00
}
2025-12-11 10:35:08 +08:00
@Operation(summary = "element文件删除")
2023-01-06 15:17:37 +08:00
@PostMapping("/delete")
public Response<Boolean> delete(@Valid @RequestBody CollectionDeleteFileDTO deleteFileDTO) {
collectionElementService.delete(deleteFileDTO.getId());
return Response.success();
}
/** 该功能已删除 */
@Deprecated
2025-12-11 10:35:08 +08:00
@Operation(summary = "生成印花")
2023-01-06 15:17:37 +08:00
@PostMapping("/generatePrint")
public Response<GenerateCollectionItemVO> generatePrint(@Valid @RequestBody CollectionGeneratePrintDTO generatePrintDTO) {
2023-01-06 15:17:37 +08:00
return Response.success(collectionElementService.generatePrint(generatePrintDTO));
}
2025-12-11 10:35:08 +08:00
@Operation(summary = "保存印花")
2023-01-06 15:17:37 +08:00
@PostMapping("/savePrint")
public Response<Boolean> savePrint(@Valid @RequestBody CollectionSavePrintDTO savePrintDTO) {
return Response.success(collectionElementService.savePrint(savePrintDTO));
}
2025-12-11 10:35:08 +08:00
@Operation(summary = "通过tcx值获取潘通信息")
2023-01-06 15:17:37 +08:00
@GetMapping("/getRgbByTcx")
2025-12-11 10:35:08 +08:00
public Response<PantoneVO> getRgbByHsv(@Parameter(description = "tcx") @RequestParam("tcx") String tcx) {
2023-01-06 15:17:37 +08:00
return Response.success(panToneService.getByTCX(tcx));
}
2025-12-11 10:35:08 +08:00
@Operation(summary = "通过hsv值获取潘通信息")
2023-01-06 15:17:37 +08:00
@GetMapping("/getRgbByHsv")
public Response<PantoneVO> getRgbByHsv(@RequestParam("h") Integer h,
@RequestParam("s") Integer s, @RequestParam("v") Integer v) {
return Response.success(panToneService.getByHSV(h, s, v));
}
2025-12-11 10:35:08 +08:00
@Operation(summary = "通过hsv值数组批量获取潘通信息")
2023-01-06 15:17:37 +08:00
@PostMapping("/getRgbByHsvBatch")
public Response<List<PantoneVO>> getRgbByHsvBatch(@RequestBody @Valid List<GetRgbByHsvBatchDTO> rgbByHsvBatch) {
return Response.success(panToneService.getRgbByHsvBatch(rgbByHsvBatch));
}
2023-10-20 14:47:18 +08:00
2025-12-11 10:35:08 +08:00
@Operation(summary = "刷新历史数据")
@PostMapping("/refreshHistoryData")
public Response<Boolean> refreshHistoryData() {
collectionElementService.refreshHistoryData();
return Response.success();
}
2023-01-06 15:17:37 +08:00
2025-12-11 10:35:08 +08:00
@Operation(summary = "图片分割")
2025-04-14 13:26:56 +08:00
@PostMapping("/imageSegmentation")
public Response<List<CollectionElementVO>> selectedImageSeg(
2025-04-14 15:18:54 +08:00
@RequestPart(value = "file", required = false) MultipartFile[] file,
2025-06-23 13:44:56 +08:00
@RequestParam(value = "type", required = false) @Pattern(regexp = "sketch|product", message = "Please choose the image type") String type,
@RequestParam(value = "id", required = false) Long id,
2025-06-23 13:44:56 +08:00
@RequestParam(value = "sourceType", required = false) @Pattern(regexp = "Library|Upload", message = "Select an image from the library or upload one.") String sourceType) {
2025-04-14 13:26:56 +08:00
// 过滤空文件
2025-04-14 15:18:54 +08:00
List<MultipartFile> nonEmptyFiles = Arrays.stream(file)
.filter(item -> !item.isEmpty())
2025-04-14 13:26:56 +08:00
.collect(Collectors.toList());
// 参数校验
if ((nonEmptyFiles.isEmpty()) && id == null) {
throw new BusinessException("必须提供文件上传或ID");
}
if (!nonEmptyFiles.isEmpty() && id != null) {
throw new BusinessException("不能同时提供文件上传和ID");
}
return Response.success(collectionElementService.selectedImageSeg(nonEmptyFiles, id, type, sourceType));
2025-04-14 13:26:56 +08:00
}
2025-12-11 10:35:08 +08:00
@Operation(summary = "更新element level2type")
@GetMapping("/updateElementLevel2Type")
public Response<String> updateLibraryLevel2Type(@RequestParam(value = "elementId") Long elementId, @RequestParam(value = "level2Type") String level2Type) {
collectionElementService.updateElementLevel2Type(elementId, level2Type);
return Response.success("success");
}
2023-01-06 15:17:37 +08:00
}