TASK: 拼贴功能保存用户上传的图片并返回

This commit is contained in:
2025-07-15 18:11:12 +08:00
parent 64318de24a
commit 301f58bc62
6 changed files with 54 additions and 4 deletions

View File

@@ -53,13 +53,15 @@ public class ElementController {
@ApiParam("一级类型 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,
@ApiParam("本地时区,比如 '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, level1Type, gender, timeZone, MD5Utils.encryptFile(file))));
new CollectionElementUploadDTO(file, projectId, level1Type, level2Type, gender, timeZone, MD5Utils.encryptFile(file))));
}
@ApiOperation(value = "element文件删除")
@@ -131,4 +133,11 @@ public class ElementController {
return Response.success(collectionElementService.selectedImageSeg(nonEmptyFiles, id, type, sourceType));
}
@ApiOperation(value = "更新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");
}
}

View File

@@ -19,9 +19,15 @@ public class CollectionElementUploadDTO {
@NotNull(message = "file.cannot.be.empty")
private MultipartFile file;
@ApiModelProperty("项目id")
private Long projectId;
@ApiModelProperty("一级类型")
private String level1Type;
@ApiModelProperty("二级类型")
private String level2Type;
@ApiModelProperty("性别")
private String gender;

View File

@@ -1,8 +1,10 @@
package com.ai.da.model.vo;
import com.alibaba.fastjson.JSONObject;
import com.ai.da.mapper.primary.entity.CollectionElement;
import lombok.Data;
import java.util.List;
@Data
public class SketchReconstructionVO {
@@ -14,4 +16,6 @@ public class SketchReconstructionVO {
private String categoryValue;
private List<CollectionElement> uploadImages;
}

View File

@@ -141,4 +141,5 @@ public interface CollectionElementService extends IService<CollectionElement> {
List<CollectionElementVO> selectedImageSeg(List<MultipartFile> files, Long id, String type, String sourceType);
void updateElementLevel2Type(Long elementId, String level2Type);
}

View File

@@ -13,6 +13,7 @@ import com.ai.da.mapper.primary.GenerateDetailMapper;
import com.ai.da.mapper.primary.entity.*;
import com.ai.da.model.dto.*;
import com.ai.da.model.enums.ModelType;
import com.ai.da.model.enums.Module;
import com.ai.da.model.enums.Sex;
import com.ai.da.model.vo.*;
import com.ai.da.python.PythonService;
@@ -96,10 +97,15 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
//用户信息
AuthPrincipalVo userInfo = UserContext.getUserHolder();
CollectionLevel1TypeEnum level1TypeEnum = CollectionLevel1TypeEnum.uploadOf(uploadDTO.getLevel1Type());
if (Objects.isNull(level1TypeEnum)) {
String name;
if (Objects.isNull(level1TypeEnum) && !uploadDTO.getLevel1Type().equals(Module.deReconstruction.getValue())) {
throw new BusinessException("unknown.parameter.level1Type");
} else if (uploadDTO.getLevel1Type().equals(Module.deReconstruction.getValue())){
name = "Construction";
} else {
name = level1TypeEnum.getRealName();
}
String objectName = userInfo.getId() + "/" + level1TypeEnum.getRealName();
String objectName = userInfo.getId() + "/" + name;
String path = minioUtil.upload(collectionElement, objectName, uploadDTO.getFile());
String level2Type = null;
@@ -108,6 +114,8 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
throw new BusinessException("gender.cannot.be.empty");
}
level2Type = pythonService.getClothCategory(path,uploadDTO.getGender());
}else if (!StringUtil.isNullOrEmpty(uploadDTO.getLevel2Type())){
level2Type = uploadDTO.getLevel2Type();
}
//保存element元素
@@ -187,6 +195,9 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
//按时区计算
element.setCreateDate(DateUtil.getByTimeZone(uploadDTO.getTimeZone()));
element.setLevel2Type(level2Type);
if (Objects.nonNull(uploadDTO.getProjectId())){
element.setProjectId(uploadDTO.getProjectId());
}
// String linuxDomain = fileProperties.getLinuxDomain();
// if (!StringUtils.isEmpty(linuxDomain)) {
// //linux 系统
@@ -1101,4 +1112,13 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
return vo;
}
public void updateElementLevel2Type(Long elementId, String level2Type){
CollectionElement collectionElement = baseMapper.selectById(elementId);
if (Objects.nonNull(collectionElement)){
collectionElement.setLevel2Type(level2Type);
collectionElement.setUpdateDate(new Date());
baseMapper.updateById(collectionElement);
}
}
}

View File

@@ -1725,6 +1725,16 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
String messageFromResource = BusinessException.getMessageFromResource(clothCategory.toUpperCase());
vo.setCategory(clothCategory);
vo.setCategoryValue(messageFromResource);
List<CollectionElement> collectionElements = collectionElementService.getByProjectId(projectId);
if (!collectionElements.isEmpty()){
collectionElements.forEach(item -> {
item.setUrl(StringUtil.isNullOrEmpty(item.getUrl()) ? null : minioUtil.getPreSignedUrl(item.getUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
});
vo.setUploadImages(collectionElements);
}else {
vo.setUploadImages(new ArrayList<>());
}
}
return vo;
}