design detail代码转移,临时存储
This commit is contained in:
59
src/main/java/com/ai/da/common/utils/PantoneUtils.java
Normal file
59
src/main/java/com/ai/da/common/utils/PantoneUtils.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package com.ai.da.common.utils;
|
||||
|
||||
public class PantoneUtils {
|
||||
|
||||
public static int[] rgbToHsv(int[] rgb) {
|
||||
//切割rgb数组
|
||||
int R = rgb[0];
|
||||
int G = rgb[1];
|
||||
int B = rgb[2];
|
||||
//公式运算 /255
|
||||
float R_1 = R / 255f;
|
||||
float G_1 = G / 255f;
|
||||
float B_1 = B / 255f;
|
||||
//重新拼接运算用数组
|
||||
float[] all = {R_1, G_1, B_1};
|
||||
float max = all[0];
|
||||
float min = all[0];
|
||||
//循环查找最大值和最小值
|
||||
for (int i = 0; i < all.length; i++) {
|
||||
if (max <= all[i]) {
|
||||
max = all[i];
|
||||
}
|
||||
if (min >= all[i]) {
|
||||
min = all[i];
|
||||
}
|
||||
}
|
||||
float C_max = max;
|
||||
float C_min = min;
|
||||
//计算差值
|
||||
float diff = C_max - C_min;
|
||||
float hue = 0f;
|
||||
//判断情况计算色调H
|
||||
if (diff == 0f) {
|
||||
hue = 0f;
|
||||
} else {
|
||||
if (C_max == R_1) {
|
||||
hue = (((G_1 - B_1) / diff) % 6) * 60f;
|
||||
}
|
||||
if (C_max == G_1) {
|
||||
hue = (((B_1 - R_1) / diff) + 2f) * 60f;
|
||||
}
|
||||
if (C_max == B_1) {
|
||||
hue = (((R_1 - G_1) / diff) + 4f) * 60f;
|
||||
}
|
||||
}
|
||||
//计算饱和度S
|
||||
float saturation;
|
||||
if (C_max == 0f) {
|
||||
saturation = 0f;
|
||||
} else {
|
||||
saturation = diff / C_max;
|
||||
}
|
||||
//计算明度V
|
||||
float value = C_max;
|
||||
int[] result = {Math.round(hue), Math.round(saturation * 100), Math.round(value * 100)};
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.ai.da.controller;
|
||||
import com.ai.da.common.response.Response;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.DesignCollectionVO;
|
||||
import com.ai.da.model.vo.DesignItemDetailVO;
|
||||
import com.ai.da.model.vo.DesignLikeVO;
|
||||
import com.ai.da.service.DesignService;
|
||||
import io.swagger.annotations.Api;
|
||||
|
||||
@@ -26,7 +26,8 @@ public class DesignItemClothesDetailVO {
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty(" 颜色 存 RGB值 中间空格分隔 比如 58 58 169")
|
||||
private String color;
|
||||
// private String color;
|
||||
private PantoneVO color;
|
||||
|
||||
@ApiModelProperty("对应的print图片对象")
|
||||
private DesignPythonItemPrint printObject;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class DesignItemDetailVO {
|
||||
private Long designItemId;
|
||||
|
||||
@ApiModelProperty("designItem图片")
|
||||
private String designItemUrl;
|
||||
private DesignPythonOutfitVO designItemUrl;
|
||||
|
||||
@ApiModelProperty("design高级图片")
|
||||
private String highDesignUrl;
|
||||
|
||||
@@ -19,7 +19,8 @@ public class DesignItemOthersDetailVO {
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty(" 颜色 存 RGB值 中间空格分隔 比如 58 58 169")
|
||||
private String color;
|
||||
// private String color;
|
||||
private PantoneVO color;
|
||||
|
||||
@ApiModelProperty("对应的print图片的绝对路径")
|
||||
private DesignPythonItemPrint printObject;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ai.da.model.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel("designItem detail layer响应")
|
||||
public class DesignPythonOutfitDetailVO {
|
||||
|
||||
@ApiModelProperty("各图层id")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty("图片所属分类 earring_back/front,hairstyle_back/front,skirt_back/front,shoes_left/right,body 等")
|
||||
private String imageCategory;
|
||||
|
||||
@ApiModelProperty("图片url")
|
||||
private String imageUrl;
|
||||
|
||||
@ApiModelProperty("蒙版url")
|
||||
private String maskUrl;
|
||||
|
||||
@ApiModelProperty("坐标")
|
||||
private String position;
|
||||
|
||||
@ApiModelProperty("优先级")
|
||||
private Integer priority;
|
||||
}
|
||||
21
src/main/java/com/ai/da/model/vo/DesignPythonOutfitVO.java
Normal file
21
src/main/java/com/ai/da/model/vo/DesignPythonOutfitVO.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.ai.da.model.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ApiModel("designItem detail从python端获取的合成图+各图层响应")
|
||||
public class DesignPythonOutfitVO {
|
||||
|
||||
@ApiModelProperty("designPythonOutfitId")
|
||||
private Long designPythonOutfitId;
|
||||
|
||||
@ApiModelProperty("合成图")
|
||||
String designPythonOutfitUrl;
|
||||
|
||||
@ApiModelProperty("各部分图层信息")
|
||||
List<DesignPythonOutfitDetailVO> designItemDetailLayers;
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import javax.validation.constraints.NotBlank;
|
||||
@ApiModel("潘通-响应")
|
||||
public class PantoneVO {
|
||||
|
||||
@ApiModelProperty("id")
|
||||
@ApiModelProperty("id -> pantoneIndex")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("名字")
|
||||
|
||||
@@ -41,6 +41,8 @@ public interface PanToneService extends IService<PanTone> {
|
||||
*/
|
||||
PantoneVO getByRGB(Integer r,Integer g,Integer b);
|
||||
|
||||
PantoneVO getPantoneByRgb(String color);
|
||||
|
||||
/**
|
||||
* 根据hsv批量查询
|
||||
* @param rgbByHsvBatch
|
||||
|
||||
@@ -157,6 +157,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
LibraryModelPoint modelPoint = libraryModelPointService.getById(design.getTemplateId());
|
||||
Assert.notNull(modelPoint,"template does not exists!");
|
||||
Library library = libraryService.getById(modelPoint.getLibraryId());
|
||||
// ??和上面重复
|
||||
Assert.notNull(modelPoint,"template does not exists!");
|
||||
designLibraryModelPointVO = collectionElementService.calculateTemplatePoint(modelPoint,library.getHigh(),library.getWidth(),library.getUrl());
|
||||
}
|
||||
@@ -170,6 +171,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
//designSingle
|
||||
DesignCollectionItemVO response = saveSingleDesignItemAndDetail(objects,design.getId(),designSingleDTO.getDesignItemId(),
|
||||
design.getCollectionId(),userInfo,designSingleDTO.getTimeZone());
|
||||
// ??
|
||||
designItem.setDesignUrl(response.getDesignItemUrl());
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.expression.operators.relational.OldOracleJoinBinaryExpression;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -74,6 +75,8 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
private SysFileService sysFileService;
|
||||
@Resource
|
||||
private TCollectionElementRelationService tCollectionElementRelationService;
|
||||
@Resource
|
||||
private PanToneService panToneService;
|
||||
|
||||
// @Transactional
|
||||
@Override
|
||||
@@ -528,11 +531,14 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
Assert.notNull(design,"design does not exist!");
|
||||
List<DesignItemDetail> designItemDetails = designItemDetailService.selectByDesignItemId(designItemId);
|
||||
Assert.notEmpty(designItemDetails,"designItemDetails does not exist!");
|
||||
// 添加判断designPythonOutfitId是否存在
|
||||
|
||||
|
||||
DesignItemDetailVO response = new DesignItemDetailVO();
|
||||
response.setSingleOverall(design.getSingleOverall());
|
||||
response.setSwitchCategory(design.getSwitchCategory());
|
||||
response.setDesignItemId(designItemId);
|
||||
response.setDesignItemUrl(designItem.getDesignUrl());
|
||||
// response.setDesignItemUrl(designItem.getDesignUrl());
|
||||
response.setHighDesignUrl(designItem.getHighDesignUrl());
|
||||
List<DesignItemDetail> filterDetail = designItemDetails.stream()
|
||||
.filter(f -> OUTWEAR_DRESS_BLOUSE.contains(f.getType()) || SKIRT_TROUSERS.contains(f.getType()))
|
||||
@@ -556,7 +562,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
d.setId(o.getBusinessId());
|
||||
d.setPrintObject(new DesignPythonItemPrint());
|
||||
}));
|
||||
return response;
|
||||
return editResponseColor(designItemDetails,response);
|
||||
}
|
||||
private String converTypeToLevel1(String type){
|
||||
if(StringUtils.isEmpty(type)){
|
||||
@@ -596,5 +602,46 @@ 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())){
|
||||
PantoneVO pantoneByRgb = panToneService.getPantoneByRgb(d.getColor());
|
||||
DesignItemClothesDetailVO clothesDetailVO = designItemDetailVO.getClothes().stream()
|
||||
.filter(v -> v.getId().equals(d.getBusinessId()))
|
||||
.findFirst().orElse(null);
|
||||
if (Objects.nonNull(clothesDetailVO)){
|
||||
clothesDetailVO.setColor(pantoneByRgb);
|
||||
} else {
|
||||
DesignItemOthersDetailVO othersDetailVO = designItemDetailVO.getOthers().stream()
|
||||
.filter(v -> v.getId().equals(d.getBusinessId()))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
if (Objects.nonNull(othersDetailVO)) {
|
||||
othersDetailVO.setColor(pantoneByRgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
return designItemDetailVO;
|
||||
}
|
||||
|
||||
|
||||
private DesignItemDetailVO editDesignItemLayer(Long designPythonOutfitId,DesignItemDetailVO designItemDetailVO){
|
||||
// 1、判断designPythonOutfitId查出的图层信息是否为空(不允许为空,系统内部错误)
|
||||
|
||||
// 2、将查询出的图层信息填充到designItemDetailVO中
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ 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.utils.CopyUtil;
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.common.utils.PantoneUtils;
|
||||
import com.ai.da.mapper.entity.ColorLookupTable;
|
||||
import com.ai.da.mapper.entity.PanTone;
|
||||
import com.ai.da.mapper.PanToneMapper;
|
||||
@@ -15,17 +15,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -35,6 +30,8 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
|
||||
@Resource
|
||||
private PanToneMapper panToneMapper;
|
||||
@Resource
|
||||
private PanToneService panToneService;
|
||||
@Resource
|
||||
private ColorLoopUpTableService colorLoopUpTableService;
|
||||
|
||||
@Override
|
||||
@@ -74,6 +71,49 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
|
||||
return coverPanToneToVo(panTones);
|
||||
}
|
||||
|
||||
public Map<String,PantoneVO> getPantoneByRgbBatch(List<String> colors){
|
||||
|
||||
HashMap<Integer,String> colorValueRgb = new HashMap<>();
|
||||
HashMap<Integer,String> colorIndexRgb = new HashMap<>();
|
||||
ArrayList<Integer> values = new ArrayList<>();
|
||||
colors.forEach(color -> {
|
||||
int[] rgb = Arrays.stream(color.split("\\s+")).mapToInt(Integer::parseInt).toArray();
|
||||
int[] hsv = PantoneUtils.rgbToHsv(rgb);
|
||||
|
||||
int value = (hsv[0] * 101 *101)+ (hsv[1]*101) +hsv[2];
|
||||
colorValueRgb.put(value,color);
|
||||
values.add(value);
|
||||
});
|
||||
List<ColorLookupTable> colorValueList = colorLoopUpTableService.getByColorValueList(values);
|
||||
colorValueList.forEach(colorValue ->{
|
||||
colorIndexRgb.put(colorValue.getColorIndex(),colorValueRgb.get(colorValue.getColorValue()));
|
||||
});
|
||||
|
||||
List<PanTone> panTones = panToneService.listByIds(colorIndexRgb.values());
|
||||
ArrayList<PantoneVO> pantoneVOS = new ArrayList<>();
|
||||
panTones.forEach(panTone -> {
|
||||
pantoneVOS.add(coverPanToneToVo(panTone));
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PantoneVO getPantoneByRgb(String color){
|
||||
GetRgbByHsvBatchDTO getRgbByHsvBatchDTO = new GetRgbByHsvBatchDTO();
|
||||
if (!StringUtil.isNullOrEmpty(color)){
|
||||
int[] rgb = Arrays.stream(color.split("\\s+")).mapToInt(Integer::parseInt).toArray();
|
||||
int[] hsv = PantoneUtils.rgbToHsv(rgb);
|
||||
|
||||
getRgbByHsvBatchDTO.setH(hsv[0]);
|
||||
getRgbByHsvBatchDTO.setS(hsv[1]);
|
||||
getRgbByHsvBatchDTO.setV(hsv[2]);
|
||||
}
|
||||
|
||||
return getByHSV(getRgbByHsvBatchDTO.getH(),getRgbByHsvBatchDTO.getS(),getRgbByHsvBatchDTO.getV());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PantoneVO> getRgbByHsvBatch(List<GetRgbByHsvBatchDTO> hsvBatch) {
|
||||
if(hsvBatch.size() >15){
|
||||
|
||||
Reference in New Issue
Block a user