接口修改:存储offset并返回给前端

This commit is contained in:
xupei
2023-10-11 10:37:11 +08:00
parent 2cd94fd026
commit 2d8672e0a8
6 changed files with 30 additions and 13 deletions

View File

@@ -71,6 +71,11 @@ public class TDesignPythonOutfitDetail implements Serializable {
*/
@ApiModelProperty(value = "位置")
private String position;
/**
* 偏移量
*/
@ApiModelProperty(value = "偏移量")
private String offset;
/**
* 图层缩放大小
*/

View File

@@ -46,7 +46,9 @@ public class DesignPythonOutfitVO {
*/
@ApiModelProperty(value = "位置")
private List<Long> position;
/**
* 偏移量
*/
@ApiModelProperty(value = "偏移量")
private List<Long> offset;
/**

View File

@@ -33,7 +33,7 @@ public interface ITDesignPythonOutfitDetailService extends IService<TDesignPytho
*/
List<TDesignPythonOutfitDetail> getDetailByDesignPythonOutfitId(Long designPythonOutfitId);
DesignPythonOutfitVO convertToDesignPythonOutfitVO(TDesignPythonOutfitDetail detail,List<Long> type);
DesignPythonOutfitVO convertToDesignPythonOutfitVO(TDesignPythonOutfitDetail detail,List<Long> offset);
void deleteByDesignPythonOutfitId(Long designPythonOutfitId);

View File

@@ -334,14 +334,19 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
// 7、将新生成的图层信息存入designPythonOutfitDetail表
JSONArray layers = outfit.getJSONArray("layers");
List<TDesignPythonOutfitDetail> list = setTDesignPythonOutfitDetailList(layers, designId, designPythonOutfit.getId(), userInfo.getId());
// 需要将request中的offset也存入数据库通过type与image_category将sketch与layers关联
Map<String, List<Long>> typeOffset = designSingleItemDTOList.stream()
.collect(Collectors.toMap(d -> d.getType().toLowerCase(), DesignSingleItemDTO::getOffset));
List<TDesignPythonOutfitDetail> list = setTDesignPythonOutfitDetailList(layers, designId, designPythonOutfit.getId(), userInfo.getId(),typeOffset);
designPythonOutfitDetailService.saveBatch(list);
return list;
}
public List<TDesignPythonOutfitDetail> setTDesignPythonOutfitDetailList(JSONArray layers, Long designId, Long designPythonOutfitId, Long userId){
public List<TDesignPythonOutfitDetail> setTDesignPythonOutfitDetailList(JSONArray layers, Long designId,
Long designPythonOutfitId, Long userId,
Map<String, List<Long>> typeOffset){
// 设置图层信息;
List<TDesignPythonOutfitDetail> list = new ArrayList<>();
for (int i = 0; i < layers.size(); i++) {
@@ -356,6 +361,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
designPythonOutfitDetail.setMaskUrl(jsonObject.getString("mask_url"));
designPythonOutfitDetail.setScale(Objects.isNull(jsonObject.getString("resize_scale")) ? "1.0" : jsonObject.getString("resize_scale"));
designPythonOutfitDetail.setUserId(userId);
designPythonOutfitDetail.setOffset(String.valueOf(typeOffset.get(jsonObject.getString("image_category").split("_")[0])));
list.add(designPythonOutfitDetail);
}
return list;
@@ -422,20 +428,21 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
throw new BusinessException("python response data is null");
}
JSONObject outfit = data.getJSONObject("0");
// 通过type将offset关联到layers
Map<String, List<Long>> typeOffset = designSingleIncludeLayersDTO.getDesignSingleItemDTOList().stream()
.collect(Collectors.toMap(d -> d.getType().toLowerCase(), DesignSingleItemDTO::getOffset));
if (!designSingleIncludeLayersDTO.getIsPreview()){
// 更新及保存图层信息
tDesignPythonOutfitDetails = saveDesignSingleItemDetailAndLayers(objects, design.getId(), designSingleIncludeLayersDTO.getDesignItemId(),
userInfo, outfit, designSingleIncludeLayersDTO.getTimeZone(),designSingleIncludeLayersDTO.getDesignSingleItemDTOList());
}else {
JSONArray layers = outfit.getJSONArray("layers");
tDesignPythonOutfitDetails = setTDesignPythonOutfitDetailList(layers,designItem.getDesignId(),null,userInfo.getId());
tDesignPythonOutfitDetails = setTDesignPythonOutfitDetailList(layers,designItem.getDesignId(),null,userInfo.getId(),typeOffset);
}
List<DesignPythonOutfitVO> detailsVO = new ArrayList<>();
tDesignPythonOutfitDetails.forEach(detail -> {
Map<String, List<Long>> typeOffset = designSingleIncludeLayersDTO.getDesignSingleItemDTOList().stream()
.collect(Collectors.toMap(d -> d.getType().toLowerCase(), DesignSingleItemDTO::getOffset));
String type = detail.getImageCategory().split("_")[0];
detailsVO.add(designPythonOutfitDetailService.convertToDesignPythonOutfitVO(detail,typeOffset.get(type)));
});

View File

@@ -992,7 +992,13 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
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,null));
List<Long> offset = new ArrayList<>();
if (detail.getOffset().equals("null")){
offset = Arrays.asList(0L,0L);
}else {
offset = Arrays.stream(detail.getOffset().replaceAll("\\[|\\]", "").split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
}
detailsVO.add(designPythonOutfitDetailService.convertToDesignPythonOutfitVO(detail,offset));
});
// 2、将查询出的图层信息填充到designItemDetailVO中

View File

@@ -1,9 +1,9 @@
package com.ai.da.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.mapper.TDesignPythonOutfitDetailMapper;
import com.ai.da.mapper.entity.DesignItemDetail;
import com.ai.da.mapper.entity.TDesignPythonOutfitDetail;
import com.ai.da.model.vo.DesignPythonOutfitVO;
import com.ai.da.model.vo.TDesignPythonOutfitDetailVO;
@@ -13,16 +13,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* design item详情表 服务实现类
@@ -62,7 +59,7 @@ public class TDesignPythonOutfitDetailServiceImpl extends ServiceImpl<TDesignPyt
designPythonOutfitVO.setMaskUrl(StringUtil.isNullOrEmpty(detail.getMaskUrl()) ? null : minIoUtil.splitThenGetPreviewUrl(detail.getMaskUrl(),480));
designPythonOutfitVO.setMaskMinioUrl(StringUtil.isNullOrEmpty(detail.getMaskUrl()) ? null : detail.getMaskUrl());
designPythonOutfitVO.setScale(Float.parseFloat(detail.getScale()));
designPythonOutfitVO.setOffset(offset);
designPythonOutfitVO.setOffset(CollectionUtil.isEmpty(offset) ? Arrays.asList(0L,0L) : offset);
/*if (!StringUtil.isNullOrEmpty(detail.getImageSize())){
List<Long> size = Arrays.stream(detail.getImageSize().replaceAll("\\[|\\]", "").split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());