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