修改 design single功能

This commit is contained in:
xupei
2023-09-14 12:58:49 +08:00
parent 165449084b
commit cf771a5b77
31 changed files with 687 additions and 102 deletions

View File

@@ -3,7 +3,7 @@ package com.ai.da.common.enums;
import lombok.Getter;
@Getter
public enum GenerateTypeEnum {
public enum GenerateModeEnum {
/**
* 通过文本生成
@@ -23,7 +23,7 @@ public enum GenerateTypeEnum {
private Integer code;
private String value;
GenerateTypeEnum(int code,String value) {
GenerateModeEnum(int code, String value) {
this.code = code;
this.value = value;
}

View File

@@ -1,5 +1,6 @@
package com.ai.da.common.enums;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -70,4 +71,21 @@ public enum SysFileLevel2TypeEnum {
public static List<String> ofPythonPath(){
return Stream.of(BLOUSE,DRESS,OUTWEAR,SKIRT,TROUSERS).map(SysFileLevel2TypeEnum::getUploadPathName).collect(Collectors.toList());
}
public static final List<String> ACCESSORIES_LIST = Arrays.asList(
SysFileLevel2TypeEnum.BAG.getRealName(),
SysFileLevel2TypeEnum.EARRINGS.getRealName(),
SysFileLevel2TypeEnum.HAIRSTYLE.getRealName(),
SysFileLevel2TypeEnum.SHOES.getRealName(),
SysFileLevel2TypeEnum.BODY.getRealName()
);
public static final List<String> IMAGES_LIST = Arrays.asList(
SysFileLevel2TypeEnum.BLOUSE.getRealName(),
SysFileLevel2TypeEnum.DRESS.getRealName(),
SysFileLevel2TypeEnum.OUTWEAR.getRealName(),
SysFileLevel2TypeEnum.SKIRT.getRealName(),
SysFileLevel2TypeEnum.TROUSERS.getRealName()
);
}

View File

@@ -74,6 +74,16 @@ public class MD5Utils {
return md5;
}
public static String encryptFile(InputStream inputStream) {
String md5 = null;
try {
md5 = DigestUtils.md5DigestAsHex(inputStream);
} catch (IOException ioException) {
log.error("文件InputStream md5加密异常ioException##{}", ExceptionUtil.getThrowableList(ioException));
}
return md5;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
File file1 = new File("/Users/yanglei/Documents/阳磊日报2019-04-23.numbers");
File file2 = new File("/Users/yanglei/Documents/7777.numbers");

View File

@@ -1,8 +1,6 @@
package com.ai.da.controller;
import com.ai.da.common.response.Response;
import com.ai.da.mapper.entity.CollectionElement;
import com.ai.da.mapper.entity.DesignItem;
import com.ai.da.model.dto.*;
import com.ai.da.model.vo.*;
import com.ai.da.service.DesignItemService;
@@ -15,7 +13,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;
@Api(tags = "design Detail模块")
@@ -46,7 +43,7 @@ public class DesignDetailController {
@GetMapping("/getDetail")
public Response<DesignItemDetailVO> getDetail(@ApiParam("designItemId") @RequestParam("designItemId") Long designItemId,
@ApiParam("designPythonOutfitId") @RequestParam(value = "designPythonOutfitId",required = false) Long designPythonOutfitId) {
return Response.success(designService.detail(designItemId,designItemId));
return Response.success(designService.detail(designPythonOutfitId,designItemId));
}
@ApiOperation(value = "切换系统的element")
@@ -58,8 +55,8 @@ public class DesignDetailController {
}
@ApiOperation(value = "单个design")
@PostMapping("/designSingle")
public Response<DesignCollectionItemVO> designSingle(@Valid @RequestBody DesignSingleDTO designSingleDTO ) {
return Response.success(designItemService.designSingle(designSingleDTO));
public Response<DesignSingleVO> designSingle(@Valid @RequestBody DesignSingleIncludeLayersDTO designSingleIncludeLayersDTO ) {
return Response.success(designItemService.designSingleIncludeLayers(designSingleIncludeLayersDTO));
}
@ApiOperation(value = "print打点")

View File

@@ -66,4 +66,16 @@ public class SysFile implements Serializable {
* 更新时间
*/
private Date updateDate;
public SysFile() {
}
public SysFile(String level1Type, String level2Type, String name, String md5, String url,Date createDate) {
this.level1Type = level1Type;
this.level2Type = level2Type;
this.name = name;
this.md5 = md5;
this.url = url;
this.createDate = createDate;
}
}

View File

@@ -30,6 +30,8 @@ public class TDesignPythonOutfit implements Serializable {
@ApiModelProperty(value = "ID")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
private Long designItemId;
/**
* 关联的design ID
*/

View File

@@ -50,6 +50,9 @@ public class TDesignPythonOutfitDetail implements Serializable {
*/
@ApiModelProperty(value = "图层")
private String imageCategory;
@ApiModelProperty(value = "图层大小")
private String imageSize;
/**
* 对应的图片的绝对路径
*/

View File

@@ -26,6 +26,11 @@ public class DesignSingleDTO {
@ApiModelProperty("others 元素")
private List<DesignSingleItemDTO> others;
private DesignSingleItemDTO designSingleItem;
@ApiModelProperty("preview -> true submit -> false")
private Boolean isPreview;
@NotBlank(message = "timeZone cannot be empty!")
@ApiModelProperty("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取")
private String timeZone;

View File

@@ -0,0 +1,26 @@
package com.ai.da.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
@Data
public class DesignSingleIncludeLayersDTO {
@ApiModelProperty("designItemId")
@NotNull(message = "designItemId cannot be empty!")
private Long designItemId;
private List<DesignSingleItemDTO> designSingleItemDTOList;
@NotNull(message = "isPreview cannot be null")
@ApiModelProperty("preview -> true submit -> false")
private Boolean isPreview;
@NotBlank(message = "timeZone cannot be empty!")
@ApiModelProperty("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取")
private String timeZone;
}

View File

@@ -1,6 +1,5 @@
package com.ai.da.model.dto;
import com.ai.da.python.vo.DesignPythonItemPrint;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -25,5 +24,6 @@ public class DesignSingleItemDTO {
private String color;
@ApiModelProperty("对应的print图片对象")
private DesignPythonItemPrint printObject;
// private DesignPythonItemPrint printObject;
private DesignSinglePrintDTO printObject;
}

View File

@@ -0,0 +1,23 @@
package com.ai.da.model.dto;
import com.ai.da.model.vo.DesignSinglePrint;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
@ApiModel("design single 印花请求信息")
public class DesignSinglePrintDTO {
@ApiModelProperty("印花url")
private String path;
@ApiModelProperty("single -> true,overall -> false")
private Boolean ifSingle;
@ApiModelProperty("印花详细")
private List<DesignSinglePrint> prints;
}

View File

@@ -3,10 +3,8 @@ package com.ai.da.model.vo;
import com.ai.da.python.vo.DesignPythonItemPrint;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
@@ -31,4 +29,7 @@ public class DesignItemClothesDetailVO {
@ApiModelProperty("对应的print图片对象")
private DesignPythonItemPrint printObject;
@ApiModelProperty("对应图层信息")
private List<DesignPythonOutfitVO> layersObject;
}

View File

@@ -15,7 +15,8 @@ public class DesignItemDetailVO {
private Long designItemId;
@ApiModelProperty("designItem图片")
private DesignPythonOutfitVO designItemUrl;
// private DesignPythonOutfitVO designItemUrl;
private String designItemUrl;
@ApiModelProperty("design高级图片")
private String highDesignUrl;

View File

@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
@ApiModel("designItem detail others 响应")
public class DesignItemOthersDetailVO {
@@ -24,4 +26,7 @@ public class DesignItemOthersDetailVO {
@ApiModelProperty("对应的print图片的绝对路径")
private DesignPythonItemPrint printObject;
@ApiModelProperty("对应图层信息")
private List<DesignPythonOutfitVO> layersObject;
}

View File

@@ -1,6 +1,5 @@
package com.ai.da.model.vo;
import com.ai.da.mapper.entity.TDesignPythonOutfitDetail;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -11,14 +10,36 @@ import java.util.List;
@ApiModel("designItem detail从python端获取的合成图+各图层响应")
public class DesignPythonOutfitVO {
@ApiModelProperty("当前图片无图层信息时,为空")
private Long designPythonOutfitId;
/**
* ID
*/
@ApiModelProperty(value = "ID")
private Long id;
@ApiModelProperty("合成图")
String designPythonOutfitUrl;
/**
* 图层
*/
@ApiModelProperty(value = "图层名")
private String imageCategory;
// TODO
// 需明确,不需要的数据不要返回
@ApiModelProperty("各部分图层信息")
List<TDesignPythonOutfitDetail> designItemDetailLayers;
/**
* 图层大小
*/
@ApiModelProperty(value = "图层大小")
private List<Long> imageSize;
/**
* 对应的图片的绝对路径
*/
@ApiModelProperty(value = "对应的图片的绝对路径")
private String imageUrl;
/**
* mask_url
*/
@ApiModelProperty(value = "遮罩")
private String maskUrl;
/**
* 位置
*/
@ApiModelProperty(value = "位置")
private List<Long> position;
}

View File

@@ -0,0 +1,31 @@
package com.ai.da.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.Min;
import java.util.List;
@Data
@ApiModel("design single 印花详情")
public class DesignSinglePrint {
@ApiModelProperty("印花位置")
@Range(max = 1L,message = "印花坐标需用大于等于0小于等于1的数表示")
private List<Float> location;
@ApiModelProperty("印花大小")
@Range(max = 1,message = "印花缩放值需用大于等于0小于等于1的数表示")
private Float scale;
@Range(min = -360,max = 360,message = "印花旋转角度范围为-360° ~ 360°")
@ApiModelProperty("印花角度")
private Float angle;
@Min(value = 1)
@ApiModelProperty("印花优先级")
private Integer priority;
}

View File

@@ -0,0 +1,22 @@
package com.ai.da.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class DesignSingleVO {
private Long designItemId;
/**
* 全身图
*/
private String designItemUrl;
@ApiModelProperty("clothes 数组")
private List<DesignItemClothesDetailVO> clothes;
}

File diff suppressed because one or more lines are too long

View File

@@ -53,6 +53,11 @@ public class DesignPythonItem {
*/
private String body_mask_path;
/**
* url在t_sys_file中的id
*/
private Long image_id;
public static List<String> OUTWEAR_DRESS_BLOUSE = Arrays.asList(CollectionLevel2TypeEnum.OUTWEAR.getRealName(),
CollectionLevel2TypeEnum.DRESS.getRealName(),CollectionLevel2TypeEnum.BLOUSE.getRealName());
@@ -67,4 +72,22 @@ public class DesignPythonItem {
public static List<String> SYS_HAIRSTYLE_SHOES = Arrays.asList(
SysFileLevel2TypeEnum.HAIRSTYLE.getRealName(), SysFileLevel2TypeEnum.SHOES.getRealName(),
SysFileLevel2TypeEnum.EARRINGS.getRealName());
public DesignPythonItem() {
}
public DesignPythonItem(String type, String bodyPath, Long image_id) {
this.type = type;
this.body_path = bodyPath;
this.image_id = image_id;
}
public DesignPythonItem(String type, String path, String color, DesignPythonItemPrint print, String icon, Long image_id) {
this.type = type;
this.path = path;
this.color = color;
this.print = print;
this.icon = icon;
this.image_id = image_id;
}
}

View File

@@ -12,7 +12,9 @@ public class DesignPythonItemPrint {
* print 绝对路径
*/
@ApiModelProperty("图片绝对路径")
private String path;
private String singlePath;
private List<String> path;
@ApiModelProperty("上传时候对应的类型,一级类型 Printboard ")
private String level1Type;
@@ -21,35 +23,41 @@ public class DesignPythonItemPrint {
* print_scale
*/
@ApiModelProperty("print_scale")
private Float scale;
private Float print_scale;
/**
* 是否打点
*/
@ApiModelProperty("是否打点 是传true 否则false")
private Boolean IfSingle;
@ApiModelProperty("打点的位置 传 [[0.2, 0.2]]")
@ApiModelProperty("print的位置 传 [[0.2, 0.2]]")
private List<List<Float>> location;
@ApiModelProperty("print的缩放比例 传 [0.2, 0.2]")
private List<Float> scale;
@ApiModelProperty("print的旋转角度 传 [0.2, 0.2]")
private List<Float> angle;
@JSONField(name="IfSingle")
public Boolean getIfSingle() {
return IfSingle;
}
public DesignPythonItemPrint(String path, String level1Type, Float scale, Boolean ifSingle) {
this.path = path;
// todo
public DesignPythonItemPrint(String singlePath, String level1Type, Float scale, Boolean ifSingle) {
this.singlePath = singlePath;
this.level1Type = level1Type;
this.scale = scale;
this.print_scale = scale;
IfSingle = ifSingle;
}
public DesignPythonItemPrint() {
}
public DesignPythonItemPrint(String path) {
this.path = path;
public DesignPythonItemPrint(String singlePath) {
this.singlePath = singlePath;
}
}

View File

@@ -2,10 +2,8 @@ package com.ai.da.service;
import com.ai.da.mapper.entity.DesignItem;
import com.ai.da.model.dto.DesignSingleDTO;
import com.ai.da.model.vo.DesignCollectionItemVO;
import com.ai.da.model.vo.DesignCollectionVO;
import com.ai.da.model.vo.DesignItemOthersDetailVO;
import com.ai.da.model.vo.GetNextSysElementVO;
import com.ai.da.model.dto.DesignSingleIncludeLayersDTO;
import com.ai.da.model.vo.*;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
@@ -47,4 +45,6 @@ public interface DesignItemService extends IService<DesignItem> {
*/
String printDot(DesignSingleDTO designSingleDTO);
DesignSingleVO designSingleIncludeLayers(DesignSingleIncludeLayersDTO designSingleIncludeLayersDTO);
}

View File

@@ -2,6 +2,7 @@ package com.ai.da.service;
import com.ai.da.mapper.entity.TDesignPythonOutfitDetail;
import com.ai.da.model.vo.DesignPythonOutfitVO;
import com.ai.da.model.vo.TDesignPythonOutfitDetailVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
@@ -31,4 +32,6 @@ public interface ITDesignPythonOutfitDetailService extends IService<TDesignPytho
* @return
*/
List<TDesignPythonOutfitDetail> getDetailByDesignPythonOutfitId(Long designPythonOutfitId);
DesignPythonOutfitVO convertToDesignPythonOutfitVO(TDesignPythonOutfitDetail detail);
}

View File

@@ -22,4 +22,5 @@ public interface ITDesignPythonOutfitService extends IService<TDesignPythonOutfi
*/
IPage<TDesignPythonOutfitVO> selectTDesignPythonOutfitPage(IPage<TDesignPythonOutfitVO> page, TDesignPythonOutfitVO tDesignPythonOutfit);
TDesignPythonOutfit getByDesignItemId(Long designItemId);
}

View File

@@ -1,7 +1,6 @@
package com.ai.da.service;
import com.ai.da.mapper.entity.SysFile;
import com.ai.da.model.vo.LibraryVo;
import com.ai.da.model.vo.SysFileVO;
import com.baomidou.mybatisplus.extension.service.IService;
@@ -50,4 +49,11 @@ public interface SysFileService extends IService<SysFile> {
* @param urlList
*/
List<SysFileVO> getByUrlList(List<String> urlList);
/**
* 根据单条url查询
* @param url
* @return
*/
SysFileVO getByUrl(String url, String type,String timeZone);
}

View File

@@ -3,7 +3,6 @@ package com.ai.da.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
import com.ai.da.common.enums.SingleOverallEnum;
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
import com.ai.da.common.utils.CopyUtil;
@@ -11,6 +10,7 @@ import com.ai.da.common.utils.DateUtil;
import com.ai.da.mapper.DesignItemMapper;
import com.ai.da.mapper.entity.*;
import com.ai.da.model.dto.DesignSingleDTO;
import com.ai.da.model.dto.DesignSingleIncludeLayersDTO;
import com.ai.da.model.dto.DesignSingleItemDTO;
import com.ai.da.model.vo.*;
import com.ai.da.python.PythonService;
@@ -19,21 +19,17 @@ import com.ai.da.python.vo.DesignPythonItemPrint;
import com.ai.da.python.vo.DesignPythonObjects;
import com.ai.da.service.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.mysql.cj.jdbc.result.UpdatableResultSet;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -61,6 +57,12 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
private LibraryService libraryService;
@Resource
private CollectionElementService collectionElementService;
@Resource
private ITDesignPythonOutfitService designPythonOutfitService;
@Resource
private ITDesignPythonOutfitDetailService designPythonOutfitDetailService;
@Resource
private PanToneService panToneService;
@Override
public Long saveOne(DesignItem designItem) {
@@ -256,7 +258,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
}
designItemDetail.setIconPath(detail.getIcon());
DesignPythonItemPrint printObject = detail.getPrint();
designItemDetail.setPrintPath(Objects.isNull(printObject)? "" :printObject.getPath());
designItemDetail.setPrintPath(Objects.isNull(printObject)? "" :printObject.getSinglePath());
designItemDetail.setPrintJson(JSON.toJSONString(printObject));
designItemDetails.add(designItemDetail);
});
@@ -270,6 +272,84 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
return response;
}
private List<TDesignPythonOutfitDetail> saveDesignSingleItemDetailAndLayers(DesignPythonObjects pythonObjects
, Long designId,Long designItemId, Long collectionId, AuthPrincipalVo userInfo
, JSONObject responseJSONObject, String timeZone){
DesignItem designItem = new DesignItem();
String url = pythonObjects.getObjects().get(0).getBasic().getSave_name();
designItem.setUpdateDate(DateUtil.getByTimeZone(timeZone));
designItem.setDesignUrl(url);
designItem.setId(designItemId);
//更新item
updateById(designItem);
//删除itemDetail
designItemDetailService.deleteByDesignItemId(designItemId);
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
// 保存designItem
pythonObjects.getObjects().get(0).getItems().forEach(detail ->{
if(null == detail){
return;
}
DesignItemDetail designItemDetail = CopyUtil.copyObject(detail,DesignItemDetail.class);
designItemDetail.setAccountId(userInfo.getId());
designItemDetail.setDesignId(designId);
designItemDetail.setDesignItemId(designItemId);
designItemDetail.setCollectionElementId(detail.getElementId());
designItemDetail.setCreateDate(DateUtil.getByTimeZone(timeZone));
if(SysFileLevel2TypeEnum.BODY.getRealName().equals(detail.getType())){
designItemDetail.setPath(detail.getBody_path());
//BODY不关联businessId
designItemDetail.setBusinessId(0L);
}
designItemDetail.setIconPath(detail.getIcon());
DesignPythonItemPrint printObject = detail.getPrint();
designItemDetail.setPrintPath(Objects.isNull(printObject)? "" :printObject.getSinglePath());
designItemDetail.setPrintJson(JSON.toJSONString(printObject));
designItemDetails.add(designItemDetail);
});
designItemDetailService.saveBatch(designItemDetails);
// 更新
JSONObject data = responseJSONObject.getJSONObject("data");
JSONObject outfit = data.getJSONObject("0");
TDesignPythonOutfit designPythonOutfit = new TDesignPythonOutfit();
designPythonOutfit.setUserId(userInfo.getId());
designPythonOutfit.setDesignId(designId);
designPythonOutfit.setCollectionId(collectionId);
designPythonOutfit.setDesignItemId(designItemId);
designPythonOutfit.setDesignUrl(outfit.getString("synthesis_url"));
designPythonOutfitService.save(designPythonOutfit);
JSONArray layers = outfit.getJSONArray("layers");
List<TDesignPythonOutfitDetail> list = setTDesignPythonOutfitDetailList(layers, designId, designPythonOutfit.getId(), userInfo.getId());
designPythonOutfitDetailService.saveBatch(list);
return list;
}
public List<TDesignPythonOutfitDetail> setTDesignPythonOutfitDetailList(JSONArray layers, Long designId, Long designPythonOutfitId, Long userId){
// 保存图层信息;
List<TDesignPythonOutfitDetail> list = new ArrayList<>();
for (int i = 0; i < layers.size(); i++) {
JSONObject jsonObject = layers.getJSONObject(i);
TDesignPythonOutfitDetail designPythonOutfitDetail = new TDesignPythonOutfitDetail();
designPythonOutfitDetail.setDesignId(designId);
designPythonOutfitDetail.setDesignPythonOutfitId(designPythonOutfitId);
designPythonOutfitDetail.setPosition(jsonObject.getString("position"));
designPythonOutfitDetail.setImageUrl(jsonObject.getString("image_url"));
designPythonOutfitDetail.setImageSize(jsonObject.getString("image_size"));
designPythonOutfitDetail.setImageCategory(jsonObject.getString("image_category"));
designPythonOutfitDetail.setMaskUrl(jsonObject.getString("mask_url"));
designPythonOutfitDetail.setUserId(userId);
list.add(designPythonOutfitDetail);
}
return list;
}
private DesignItem selectById(Long id) {
QueryWrapper<DesignItem> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", id);
@@ -281,4 +361,129 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
queryWrapper.eq("id", id);
return designItemMapper.exists(queryWrapper);
}
@Override
public DesignSingleVO designSingleIncludeLayers(DesignSingleIncludeLayersDTO designSingleIncludeLayersDTO) {
AuthPrincipalVo userInfo = UserContext.getUserHolder();
DesignItem designItem = selectById(designSingleIncludeLayersDTO.getDesignItemId());
Assert.notNull(designItem,"design item does not exists!");
Design design = designService.getById(designItem.getDesignId());
Assert.notNull(design,"design does not exists!");
DesignLibraryModelPointVO designLibraryModelPointVO = null;
// 设置模特
if (Objects.nonNull(design.getTemplateId())){
LibraryModelPoint modelPoint = libraryModelPointService.getById(design.getTemplateId());
Assert.notNull(modelPoint,"template does not exists!");
Library library = libraryService.getById(modelPoint.getLibraryId());
Assert.notNull(library,"template does not exists!");
designLibraryModelPointVO = collectionElementService.calculateTemplatePoint(modelPoint,library.getHigh(),library.getWidth(),library.getUrl());
}
DesignPythonObjects objects =pythonService.covertDesignSingleParam(
designSingleIncludeLayersDTO,design.getSingleOverall(),design.getSwitchCategory(),designLibraryModelPointVO);
// JSONObject jsonObject = pythonService.designNew(objects);
JSONObject jsonObject = getJsonString();
// preview -> 不存数据库 submit -> 存数据库
List<TDesignPythonOutfitDetail> tDesignPythonOutfitDetails;
if (!designSingleIncludeLayersDTO.getIsPreview()){
// todo 这里要再想想
tDesignPythonOutfitDetails = saveDesignSingleItemDetailAndLayers(objects, design.getId(), designSingleIncludeLayersDTO.getDesignItemId(),
design.getCollectionId(), userInfo, jsonObject, designSingleIncludeLayersDTO.getTimeZone());
}else {
JSONObject data = jsonObject.getJSONObject("data");
// todo 空指针
JSONObject outfit = data.getJSONObject("0");
JSONArray layers = outfit.getJSONArray("layers");
tDesignPythonOutfitDetails = setTDesignPythonOutfitDetailList(layers,designItem.getDesignId(),null,userInfo.getId());
}
List<DesignPythonOutfitVO> detailsVO = new ArrayList<>();
tDesignPythonOutfitDetails.forEach(detail -> {
detailsVO.add(designPythonOutfitDetailService.convertToDesignPythonOutfitVO(detail));
});
TDesignPythonOutfit designPythonOutfit = designPythonOutfitService.getByDesignItemId(designSingleIncludeLayersDTO.getDesignItemId());
// todo designPythonOutFit 空指针
return assembleDesignSingleResponse(designItem.getId(),designPythonOutfit.getDesignUrl(),
designSingleIncludeLayersDTO.getDesignSingleItemDTOList(),detailsVO);
}
private DesignSingleVO assembleDesignSingleResponse(Long designItemId,String designItemUrl,
List<DesignSingleItemDTO> designSingleItemDTOList,
List<DesignPythonOutfitVO> layersObject){
DesignSingleVO designSingleVO = new DesignSingleVO();
ArrayList<DesignItemClothesDetailVO> clothes = new ArrayList<>();
designSingleVO.setDesignItemId(designItemId);
designSingleVO.setDesignItemUrl(designItemUrl);
designSingleVO.setClothes(clothes);
designSingleItemDTOList.forEach(singleItem -> {
DesignItemClothesDetailVO designItemClothesDetailVO = new DesignItemClothesDetailVO();
designItemClothesDetailVO.setType(singleItem.getType());
designItemClothesDetailVO.setColor(panToneService.getPantoneByRgb(singleItem.getColor()));
designItemClothesDetailVO.setPrintObject(new DesignPythonItemPrint(singleItem.getPrintObject().getPath()));
designItemClothesDetailVO.setLayersObject(layersObject.stream().filter(
layers -> singleItem.getType().toLowerCase().equals(layers.getImageCategory().split("_")[0])).collect(Collectors.toList()));
clothes.add(designItemClothesDetailVO);
});
return designSingleVO;
}
private JSONObject getJsonString(){
return JSONObject.parseObject("{\n" +
" \"code\": 200,\n" +
" \"data\": {\n" +
" \"0\": {\n" +
" \"layers\": [\n" +
" {\n" +
" \"image_category\": \"blouse_back\",\n" +
" \"image_size\": [\n" +
" 287,\n" +
" 477\n" +
" ],\n" +
" \"image_url\": \"image/image_1694613014.7537637.png\",\n" +
" \"mask_url\": \"mask/mask_1694613014.7537637.png\",\n" +
" \"position\": [\n" +
" 495,\n" +
" 714\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"image_category\": \"body\",\n" +
" \"image_size\": [\n" +
" 1672,\n" +
" 1672\n" +
" ],\n" +
" \"image_url\": \"model_1693218345.2714431.png\",\n" +
" \"mask_url\": null,\n" +
" \"position\": [\n" +
" 0,\n" +
" 0\n" +
" ]\n" +
" },\n" +
" {\n" +
" \"image_category\": \"blouse_front\",\n" +
" \"image_size\": [\n" +
" 287,\n" +
" 477\n" +
" ],\n" +
" \"image_url\": \"image/image_1694613014.687538.png\",\n" +
" \"mask_url\": \"mask/mask_1694613014.687538.png\",\n" +
" \"position\": [\n" +
" 495,\n" +
" 714\n" +
" ]\n" +
" }\n" +
" ],\n" +
" \"synthesis_url\": \"result_1694613014.8975976.png\"\n" +
" }\n" +
" },\n" +
" \"msg\": \"OK!\"\n" +
"}");
}
}

View File

@@ -350,7 +350,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
}
designItemDetail.setIconPath(detail.getIcon());
DesignPythonItemPrint printObject = detail.getPrint();
designItemDetail.setPrintPath(Objects.isNull(printObject)? "" :printObject.getPath());
designItemDetail.setPrintPath(Objects.isNull(printObject)? "" :printObject.getSinglePath());
designItemDetails.add(designItemDetail);
});
designItemDetailService.saveBatch(designItemDetails);
@@ -423,7 +423,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
}
designItemDetail.setIconPath(detail.getIcon());
DesignPythonItemPrint printObject = detail.getPrint();
designItemDetail.setPrintPath(Objects.isNull(printObject)? "" :printObject.getPath());
designItemDetail.setPrintPath(Objects.isNull(printObject)? "" :printObject.getSinglePath());
designItemDetails.add(designItemDetail);
});
designItemDetailService.saveBatch(designItemDetails);
@@ -682,7 +682,8 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
}));
//single 和 Models(模特)时候 系统元素为空
List<DesignItemDetail> filterDetail2 =designItemDetails.stream()
.filter(f -> SYS_HAIRSTYLE_SHOES.contains(f.getType()) )
// .filter(f -> SYS_HAIRSTYLE_SHOES.contains(f.getType()) )
.filter(f -> SYS_HAIRSTYLE_SHOES_BODY.contains(f.getType()) )
.collect(Collectors.toList());
response.setOthers(CopyUtil.copyList(filterDetail2,DesignItemOthersDetailVO.class,(o,d)->{
d.setId(o.getBusinessId());
@@ -728,12 +729,6 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
return design.getId();
}
/**
*
* @param designItemDetails
* @param designItemDetailVO
* @return
*/
private DesignItemDetailVO editResponseColor(List<DesignItemDetail> designItemDetails,DesignItemDetailVO designItemDetailVO){
/*designItemDetails.forEach(d -> {
if (!StringUtil.isNullOrEmpty(d.getColor())){
@@ -778,25 +773,40 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
}
private DesignItemDetailVO editDesignItemLayer(Boolean flag,TDesignPythonOutfit designPythonOutfit,String designItemId,DesignItemDetailVO designItemDetailVO){
DesignPythonOutfitVO designPythonOutfitVO = new DesignPythonOutfitVO();
private DesignItemDetailVO editDesignItemLayer(Boolean flag,TDesignPythonOutfit designPythonOutfit,String designItemUrl,DesignItemDetailVO designItemDetailVO){
ArrayList<DesignPythonOutfitVO> detailsVO = new ArrayList<>();
if (flag){
// 1、判断designPythonOutfitId查出的图层信息是否为空不允许为空系统内部错误
List<TDesignPythonOutfitDetail> details = designPythonOutfitDetailService.getDetailByDesignPythonOutfitId(designPythonOutfit.getId());
Assert.notEmpty(details,"Some errors occurred, please restart the design");
details.forEach(detail -> {
detailsVO.add(designPythonOutfitDetailService.convertToDesignPythonOutfitVO(detail));
});
// 2、将查询出的图层信息填充到designItemDetailVO中
designPythonOutfitVO.setDesignPythonOutfitId(designPythonOutfit.getId());
designPythonOutfitVO.setDesignPythonOutfitUrl(designPythonOutfit.getDesignUrl());
designPythonOutfitVO.setDesignItemDetailLayers(details);
}else{
designPythonOutfitVO.setDesignPythonOutfitUrl(designItemId);
}
designItemDetailVO.setDesignItemUrl(designPythonOutfit.getDesignUrl());
// 2.1 填充clothes
designItemDetailVO.getClothes().forEach(c -> {
String type = c.getType().toLowerCase();
List<DesignPythonOutfitVO> outfitVOS = detailsVO.stream().filter(detail -> detail.getImageCategory().equals(type + "_back") ||
detail.getImageCategory().equals(type + "_front")).collect(Collectors.toList());
designItemDetailVO.setDesignItemUrl(designPythonOutfitVO);
c.setLayersObject(outfitVOS);
});
// 2.2 填充others
designItemDetailVO.getOthers().forEach(o -> {
String type = o.getType().toLowerCase();
List<DesignPythonOutfitVO> outfitVOS = detailsVO.stream().filter(detail -> detail.getImageCategory().equals(type + "_back") ||
detail.getImageCategory().equals(type + "_front") ||
detail.getImageCategory().equals("body")).collect(Collectors.toList());
o.setLayersObject(outfitVOS);
});
}else{
designItemDetailVO.setDesignItemUrl(designItemUrl);
}
return designItemDetailVO;
}
}

View File

@@ -3,7 +3,7 @@ package com.ai.da.service.impl;
import cn.hutool.core.lang.Assert;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
import com.ai.da.common.enums.GenerateTypeEnum;
import com.ai.da.common.enums.GenerateModeEnum;
import com.ai.da.common.enums.ModelNameEnum;
import com.ai.da.common.utils.DateUtil;
import com.ai.da.common.utils.MD5Utils;
@@ -83,10 +83,12 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper,Generate> im
save(generate);
// 4、向模型发起请求
int mode = GenerateTypeEnum.TEXT.getValue().equals(generate.getGenerateType()) ? GenerateTypeEnum.TEXT.getCode() : GenerateTypeEnum.TEXT_IMAGE.getCode();
// String generatedSketchUrl = pythonService.generateSketchOrPrint(collectionElement.getUrl(),text,mode,generateThroughImageTextDTO.getVersion());
int mode = GenerateModeEnum.TEXT.getValue().equals(generate.getGenerateType()) ? GenerateModeEnum.TEXT.getCode() : GenerateModeEnum.TEXT_IMAGE.getCode();
String category = generateThroughImageTextDTO.getLevel1Type().equals(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName()) ? "sketch" :
generateThroughImageTextDTO.getLevel1Type().equals(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName()) ? "print" : "moodboard";
List<String> generatedSketchUrl = pythonService.generateSketchOrPrint(accountId,collectionElement.getUrl(),category,text,mode,generateThroughImageTextDTO.getVersion());
List<String> generatedSketchUrl = Arrays.asList("testUrl1","testUrl2","testUrl3","testUrl4");
// List<String> generatedSketchUrl = Arrays.asList("testUrl1","testUrl2","testUrl3","testUrl4");
// 5、处理模型返回的数据
// 5.1 将相应的url保存到数据库

View File

@@ -5,18 +5,9 @@ import com.ai.da.common.config.FileProperties;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.enums.SysFileLevel1TypeEnum;
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.response.Response;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.FileUtil;
import com.ai.da.common.utils.LocalCacheUtils;
import com.ai.da.common.utils.MD5Utils;
import com.ai.da.common.utils.*;
import com.ai.da.mapper.SysFileMapper;
import com.ai.da.mapper.entity.Collection;
import com.ai.da.mapper.entity.Library;
import com.ai.da.mapper.entity.SysFile;
import com.ai.da.mapper.entity.UserLikeGroup;
import com.ai.da.model.vo.LibraryVo;
import com.ai.da.model.vo.SysFileVO;
import com.ai.da.service.SysFileService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -26,7 +17,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.est.CACertsResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -36,6 +26,7 @@ import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@@ -259,4 +250,26 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
queryWrapper.in("url", urlList);
return CopyUtil.copyList(sysFileMapper.selectList(queryWrapper),SysFileVO.class);
}
@Override
public SysFileVO getByUrl(String url, String type,String timeZone){
QueryWrapper<SysFile> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("url", url);
SysFile sysFile = sysFileMapper.selectOne(queryWrapper);
// 如果当前url不存在先将其插入表中
if (Objects.isNull(sysFile)){
sysFile = setSysFileEntity(url,type,timeZone);
sysFileMapper.insert(sysFile);
}
return CopyUtil.copyObject(sysFile,SysFileVO.class);
}
private SysFile setSysFileEntity(String url,String type,String timeZone){
InputStream originFile = FileUtil.getOriginFile(url);
String[] arr = url.split("/");
String level1Type = SysFileLevel2TypeEnum.ACCESSORIES_LIST.contains(type) ? SysFileLevel1TypeEnum.ACCESSORIES.getRealName() :
SysFileLevel2TypeEnum.IMAGES_LIST.contains(type) ? SysFileLevel1TypeEnum.IMAGES.getRealName() : SysFileLevel1TypeEnum.ICON_C.getRealName();
return new SysFile(level1Type, type, arr[arr.length - 1], MD5Utils.encryptFile(originFile), url, DateUtil.getByTimeZone(timeZone));
}
}

View File

@@ -1,15 +1,19 @@
package com.ai.da.service.impl;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.mapper.TDesignPythonOutfitDetailMapper;
import com.ai.da.mapper.entity.TDesignPythonOutfitDetail;
import com.ai.da.model.vo.DesignPythonOutfitVO;
import com.ai.da.model.vo.TDesignPythonOutfitDetailVO;
import com.ai.da.service.ITDesignPythonOutfitDetailService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
import java.util.Objects;
/**
* design item详情表 服务实现类
@@ -31,7 +35,18 @@ public class TDesignPythonOutfitDetailServiceImpl extends ServiceImpl<TDesignPyt
queryWrapper.eq("design_python_outfit_id",designPythonOutfitId);
return baseMapper.selectList(queryWrapper);
}
@Override
public DesignPythonOutfitVO convertToDesignPythonOutfitVO(TDesignPythonOutfitDetail detail){
if (Objects.isNull(detail)) {
return null;
}
DesignPythonOutfitVO designPythonOutfitVO = CopyUtil.copyObject(detail,DesignPythonOutfitVO.class);
designPythonOutfitVO.setPosition((List<Long>) JSON.parse(detail.getPosition()));
designPythonOutfitVO.setImageSize((List<Long>) JSON.parse(detail.getImageSize()));
return designPythonOutfitVO;
}
}

View File

@@ -4,6 +4,7 @@ import com.ai.da.mapper.TDesignPythonOutfitMapper;
import com.ai.da.mapper.entity.TDesignPythonOutfit;
import com.ai.da.model.vo.TDesignPythonOutfitVO;
import com.ai.da.service.ITDesignPythonOutfitService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -22,4 +23,12 @@ public class TDesignPythonOutfitServiceImpl extends ServiceImpl<TDesignPythonOut
return page.setRecords(baseMapper.selectTDesignPythonOutfitPage(page, tDesignPythonOutfit));
}
@Override
public TDesignPythonOutfit getByDesignItemId(Long designItemId){
QueryWrapper<TDesignPythonOutfit> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("design_item_id",designItemId);
return getOne(queryWrapper);
}
}