design detail代码转移,临时存储

This commit is contained in:
徐佩
2023-09-06 13:53:15 +08:00
parent 2d924ca1e6
commit 90edb573d9
15 changed files with 329 additions and 18 deletions

View 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;
}
}

View File

@@ -3,7 +3,6 @@ package com.ai.da.controller;
import com.ai.da.common.response.Response; import com.ai.da.common.response.Response;
import com.ai.da.model.dto.*; import com.ai.da.model.dto.*;
import com.ai.da.model.vo.DesignCollectionVO; 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.model.vo.DesignLikeVO;
import com.ai.da.service.DesignService; import com.ai.da.service.DesignService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;

View File

@@ -26,7 +26,8 @@ public class DesignItemClothesDetailVO {
private String path; private String path;
@ApiModelProperty(" 颜色 存 RGB值 中间空格分隔 比如 58 58 169") @ApiModelProperty(" 颜色 存 RGB值 中间空格分隔 比如 58 58 169")
private String color; // private String color;
private PantoneVO color;
@ApiModelProperty("对应的print图片对象") @ApiModelProperty("对应的print图片对象")
private DesignPythonItemPrint printObject; private DesignPythonItemPrint printObject;

View File

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

View File

@@ -19,7 +19,8 @@ public class DesignItemOthersDetailVO {
private String path; private String path;
@ApiModelProperty(" 颜色 存 RGB值 中间空格分隔 比如 58 58 169") @ApiModelProperty(" 颜色 存 RGB值 中间空格分隔 比如 58 58 169")
private String color; // private String color;
private PantoneVO color;
@ApiModelProperty("对应的print图片的绝对路径") @ApiModelProperty("对应的print图片的绝对路径")
private DesignPythonItemPrint printObject; private DesignPythonItemPrint printObject;

View File

@@ -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;
}

View 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;
}

View File

@@ -11,7 +11,7 @@ import javax.validation.constraints.NotBlank;
@ApiModel("潘通-响应") @ApiModel("潘通-响应")
public class PantoneVO { public class PantoneVO {
@ApiModelProperty("id") @ApiModelProperty("id -> pantoneIndex")
private Integer id; private Integer id;
@ApiModelProperty("名字") @ApiModelProperty("名字")

View File

@@ -41,6 +41,8 @@ public interface PanToneService extends IService<PanTone> {
*/ */
PantoneVO getByRGB(Integer r,Integer g,Integer b); PantoneVO getByRGB(Integer r,Integer g,Integer b);
PantoneVO getPantoneByRgb(String color);
/** /**
* 根据hsv批量查询 * 根据hsv批量查询
* @param rgbByHsvBatch * @param rgbByHsvBatch

View File

@@ -157,6 +157,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
LibraryModelPoint modelPoint = libraryModelPointService.getById(design.getTemplateId()); LibraryModelPoint modelPoint = libraryModelPointService.getById(design.getTemplateId());
Assert.notNull(modelPoint,"template does not exists!"); Assert.notNull(modelPoint,"template does not exists!");
Library library = libraryService.getById(modelPoint.getLibraryId()); Library library = libraryService.getById(modelPoint.getLibraryId());
// ??和上面重复
Assert.notNull(modelPoint,"template does not exists!"); Assert.notNull(modelPoint,"template does not exists!");
designLibraryModelPointVO = collectionElementService.calculateTemplatePoint(modelPoint,library.getHigh(),library.getWidth(),library.getUrl()); designLibraryModelPointVO = collectionElementService.calculateTemplatePoint(modelPoint,library.getHigh(),library.getWidth(),library.getUrl());
} }
@@ -170,6 +171,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
//designSingle //designSingle
DesignCollectionItemVO response = saveSingleDesignItemAndDetail(objects,design.getId(),designSingleDTO.getDesignItemId(), DesignCollectionItemVO response = saveSingleDesignItemAndDetail(objects,design.getId(),designSingleDTO.getDesignItemId(),
design.getCollectionId(),userInfo,designSingleDTO.getTimeZone()); design.getCollectionId(),userInfo,designSingleDTO.getTimeZone());
// ??
designItem.setDesignUrl(response.getDesignItemUrl()); designItem.setDesignUrl(response.getDesignItemUrl());
return response; return response;
} }

View File

@@ -25,6 +25,7 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.expression.operators.relational.OldOracleJoinBinaryExpression; import net.sf.jsqlparser.expression.operators.relational.OldOracleJoinBinaryExpression;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -74,6 +75,8 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
private SysFileService sysFileService; private SysFileService sysFileService;
@Resource @Resource
private TCollectionElementRelationService tCollectionElementRelationService; private TCollectionElementRelationService tCollectionElementRelationService;
@Resource
private PanToneService panToneService;
// @Transactional // @Transactional
@Override @Override
@@ -528,11 +531,14 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
Assert.notNull(design,"design does not exist!"); Assert.notNull(design,"design does not exist!");
List<DesignItemDetail> designItemDetails = designItemDetailService.selectByDesignItemId(designItemId); List<DesignItemDetail> designItemDetails = designItemDetailService.selectByDesignItemId(designItemId);
Assert.notEmpty(designItemDetails,"designItemDetails does not exist!"); Assert.notEmpty(designItemDetails,"designItemDetails does not exist!");
// 添加判断designPythonOutfitId是否存在
DesignItemDetailVO response = new DesignItemDetailVO(); DesignItemDetailVO response = new DesignItemDetailVO();
response.setSingleOverall(design.getSingleOverall()); response.setSingleOverall(design.getSingleOverall());
response.setSwitchCategory(design.getSwitchCategory()); response.setSwitchCategory(design.getSwitchCategory());
response.setDesignItemId(designItemId); response.setDesignItemId(designItemId);
response.setDesignItemUrl(designItem.getDesignUrl()); // response.setDesignItemUrl(designItem.getDesignUrl());
response.setHighDesignUrl(designItem.getHighDesignUrl()); response.setHighDesignUrl(designItem.getHighDesignUrl());
List<DesignItemDetail> filterDetail = designItemDetails.stream() List<DesignItemDetail> filterDetail = designItemDetails.stream()
.filter(f -> OUTWEAR_DRESS_BLOUSE.contains(f.getType()) || SKIRT_TROUSERS.contains(f.getType())) .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.setId(o.getBusinessId());
d.setPrintObject(new DesignPythonItemPrint()); d.setPrintObject(new DesignPythonItemPrint());
})); }));
return response; return editResponseColor(designItemDetails,response);
} }
private String converTypeToLevel1(String type){ private String converTypeToLevel1(String type){
if(StringUtils.isEmpty(type)){ if(StringUtils.isEmpty(type)){
@@ -596,5 +602,46 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
return design.getId(); 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;
}
} }

View File

@@ -3,7 +3,7 @@ package com.ai.da.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.ai.da.common.config.exception.BusinessException; import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.utils.CopyUtil; 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.ColorLookupTable;
import com.ai.da.mapper.entity.PanTone; import com.ai.da.mapper.entity.PanTone;
import com.ai.da.mapper.PanToneMapper; 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; 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.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.util.*;
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.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -35,6 +30,8 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
@Resource @Resource
private PanToneMapper panToneMapper; private PanToneMapper panToneMapper;
@Resource @Resource
private PanToneService panToneService;
@Resource
private ColorLoopUpTableService colorLoopUpTableService; private ColorLoopUpTableService colorLoopUpTableService;
@Override @Override
@@ -74,6 +71,49 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
return coverPanToneToVo(panTones); 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 @Override
public List<PantoneVO> getRgbByHsvBatch(List<GetRgbByHsvBatchDTO> hsvBatch) { public List<PantoneVO> getRgbByHsvBatch(List<GetRgbByHsvBatchDTO> hsvBatch) {
if(hsvBatch.size() >15){ if(hsvBatch.size() >15){

View File

@@ -0,0 +1,47 @@
server.port=7766
#datasource
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.datasource.url=jdbc:mysql://18.167.251.121:33006/aida?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
spring.datasource.url=jdbc:mysql://localhost:3306/aida?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=root
#security
spring.security.jwtSecret=JWTSECRET
spring.security.jwtTokenHeader=Authorization
spring.security.jwtTokenPrefix=Bearer-
## 24Сʱ
spring.security.jwtExpiration=8640000000
#spring security权限设置 认证了token还要认证权限 不然报错Full authentication is required to access this resource
spring.security.ignorePaths=/,/favicon.ico,/doc.html,/webjars/**,/swagger-resources,/v2/api-docs,\
/api/account/**,/api/element/**,/api/python/**,/api/design/**,/api/history/**,/api/library/**,/api/third/party/**,/api/generate/**
spring.security.authApi=/auth/login
rsa.private_key=MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9pB6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZUBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3tTbklZkD2A==
#mybatis
mybatis-plus.global-config.banner=false
mybatis-plus.mapper-locations=classpath:mapper/*Mapper.xml
#mybatis-plus.configuration.log-impl= org.apache.ibatis.logging.stdout.StdOutImpl
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
file.mac.path=~/file/
file.linux.path=/workspace/home/aida/file/
#linux服务器域名(预览和下载用)
#file.linuxDomain=http://18.162.111.141:5568/download/
file.linuxDomain=http://18.167.251.121:5568/download/
file.windows.path=D:\\upload\\
spring.servlet.multipart.max-file-size = 5MB
spring.servlet.multipart.max-request-size= 5MB
#访问python服务的ip(对应环境)
#access.python.ip=http://18.167.251.121
access.python.ip=http://43.198.80.117

View File

@@ -4,8 +4,7 @@
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.ai.da.mapper.entity.PanTone"> <resultMap id="BaseResultMap" type="com.ai.da.mapper.entity.PanTone">
<id column="id" property="id" /> <id column="pantone_index" property="pantoneIndex" />
<result column="pantone_index" property="pantoneIndex" />
<result column="name" property="name" /> <result column="name" property="name" />
<result column="tcx" property="tcx" /> <result column="tcx" property="tcx" />
<result column="r" property="r" /> <result column="r" property="r" />

View File

@@ -0,0 +1,65 @@
package com.ai.da.controller;
import com.ai.da.AiDaApplication;
import com.ai.da.common.utils.PantoneUtils;
import com.ai.da.service.DesignService;
import com.ai.da.service.PanToneService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = AiDaApplication.class)
public class PantoneTest {
@Resource
private PanToneService panToneService;
@Resource
private DesignService designService;
@Test
public void testGetPantoneByRgbBatch(){
List<String> colors = Arrays.asList("244 222 222","120 57 55","229 208 207","223 184 182","80 49 48");
// System.out.println(panToneService.getPantoneByRgbBatch(colors));
}
@Test
public void testDesign(){
System.out.println(designService.detail(34182L));
}
@Test
public void testRgbToHsv(){
// 42 228 194
// 226 194 194
// 174 226 20
int[] rgb1 = {174,226,20};
System.out.println(Arrays.toString(rgb1));
rgb1 = PantoneUtils.rgbToHsv(rgb1);
System.out.println(Arrays.toString(rgb1));
System.out.println(rgb1[0] * 101 * 101 + rgb1[1] * 101 + rgb1[2]);
int[] rgb2 = {226,194,194};
System.out.println(Arrays.toString(rgb2));
System.out.println(Arrays.toString(PantoneUtils.rgbToHsv(rgb2)));
System.out.println(rgb2[0] * 101 * 101 + rgb2[1] * 101 + rgb2[2]);
int[] rgb3 = {42,228,194};
System.out.println(Arrays.toString(rgb3));
System.out.println(Arrays.toString(PantoneUtils.rgbToHsv(rgb3)));
System.out.println(rgb3[0] * 101 * 101 + rgb3[1] * 101 + rgb3[2]);
int[] rgb4 = {246,227,180};
System.out.println(Arrays.toString(rgb4));
rgb4 = PantoneUtils.rgbToHsv(rgb4);
System.out.println(Arrays.toString(rgb4));
System.out.println(rgb4[0] * 101 * 101 + rgb4[1] * 101 + rgb4[2]);
}
}