Merge remote-tracking branch 'origin/dev/dev' into dev/dev

This commit is contained in:
2024-02-22 10:25:25 +08:00
3 changed files with 365 additions and 324 deletions

View File

@@ -23,6 +23,9 @@ public class QueryLibraryPageVO {
@ApiModelProperty("二级类型")
private String level2Type;
@ApiModelProperty("三级类型")
private String level3Type;
@ApiModelProperty("design类型 用户design生成时候区别library和collection")
private String designType;

View File

@@ -217,71 +217,75 @@ public class PythonService {
public DesignPythonObjects covertDesignParam(BigDecimal systemScale, String singleOverall,
String switchCategory, ValidateElementVO elementVO, String processId) {
DesignPythonObjects designPythonObjects = new DesignPythonObjects();
List<DesignPythonObject> objects = Lists.newArrayList();
List<DesignPythonObject> objects = new ArrayList<>();
designPythonObjects.setObjects(objects);
designPythonObjects.setProcess_id(processId);
long pinPrintNum = calculateDesignPinPrintNum(elementVO.getPrintBoardElements());
long noPinPrintNum = calculateDesignNoPinPrintNum(elementVO.getPrintBoardElements());
//没有print的
long noPrintNum = 8 - pinPrintNum - noPinPrintNum;
elementVO.setNoPinPrintNum(noPinPrintNum);
//系统比列
// BigDecimal sysRatio = systemScale;
int pinSketchNum = 0;
int sysSketchNum = 0;
int noPinSketchNum = 0;
for (int i = 0; i < 8; i++) {
//sketch计算
CurrentDesignPictureTypeEnum designPictureType = calculateCurrentDesignPictureTypeNew(elementVO, pinSketchNum, sysSketchNum, noPinSketchNum, systemScale);
if (Objects.isNull(designPictureType)) {
break;
}
//print计算
if (designPictureType == null) break;
CurrentDesignPrintPictureTypeEnum designPrintPictureType = calculateCurrentDesignPintPictureType(pinPrintNum, noPinPrintNum, noPrintNum);
if (Objects.isNull(designPrintPictureType)) {
break;
}
switch (designPictureType) {
case PIN:
pinSketchNum ++;
break;
case NO_PIN:
noPinSketchNum --;
break;
case SYS_FILE:
sysSketchNum --;
break;
default:
}
switch (designPrintPictureType) {
case PIN:
pinPrintNum--;
break;
case NO_PIN:
noPinPrintNum--;
break;
case NO:
noPrintNum--;
break;
default:
}
//确定本次designSingle是否print
if (designPrintPictureType == null) break;
updateSketchNumbers(designPictureType, pinSketchNum, sysSketchNum, noPinSketchNum);
updatePrintNumbers(designPrintPictureType, pinPrintNum, noPinPrintNum, noPrintNum);
DesignPythonItemPrint designPythonItemPrint = getRandomPrint(elementVO, designPrintPictureType);
elementVO.setDesignPythonItemPrint(designPythonItemPrint);
//参数透传 确定本次designSingle如果需要print对应的种类
elementVO.setDesignPrintPictureTypeLayoutList(calculateCurrentDesignPintPictureTypeLayout(elementVO.getModelSex()));
//designSingle具体参数组装
DesignPythonObject pythonObject = new DesignPythonObject();
pythonObject.setItems(coverToDesignPythonItemNew(elementVO, designPictureType, systemScale));
pythonObject.setBasic(coverToBasic(pythonObject.getItems().get(0),
singleOverall, switchCategory, elementVO.getDesignLibraryModelPoint()));
DesignPythonObject pythonObject = createDesignPythonObject(elementVO, designPictureType, systemScale, singleOverall, switchCategory);
objects.add(pythonObject);
}
return designPythonObjects;
}
private void updateSketchNumbers(CurrentDesignPictureTypeEnum designPictureType, int pinSketchNum, int sysSketchNum, int noPinSketchNum) {
switch (designPictureType) {
case PIN:
pinSketchNum++;
break;
case NO_PIN:
noPinSketchNum--;
break;
case SYS_FILE:
sysSketchNum--;
break;
}
}
private void updatePrintNumbers(CurrentDesignPrintPictureTypeEnum designPrintPictureType, long pinPrintNum, long noPinPrintNum, long noPrintNum) {
switch (designPrintPictureType) {
case PIN:
pinPrintNum--;
break;
case NO_PIN:
noPinPrintNum--;
break;
case NO:
noPrintNum--;
break;
}
}
private DesignPythonObject createDesignPythonObject(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, BigDecimal systemScale, String singleOverall, String switchCategory) {
DesignPythonObject pythonObject = new DesignPythonObject();
pythonObject.setItems(coverToDesignPythonItemNew(elementVO, designPictureType, systemScale));
pythonObject.setBasic(coverToBasic(pythonObject.getItems().get(0), singleOverall, switchCategory, elementVO.getDesignLibraryModelPoint()));
return pythonObject;
}
private CurrentDesignPictureTypeEnum calculateCurrentDesignPictureTypeNew(ValidateElementVO elementVO, int pinSketchNum, int sysSketchNum, int noPinSketchNum, BigDecimal systemScale) {
List<CollectionElement> pinData = getPinData(elementVO);
if (CollectionUtil.isNotEmpty(pinData)) {
@@ -311,21 +315,21 @@ public class PythonService {
return result.setScale(0, RoundingMode.HALF_UP).intValue();
}
private int calculatePinSketchNum(List<CollectionElement> sketchBoardElements, List<String> hasUseMd5List) {
List<CollectionElement> pinData = getPinData(sketchBoardElements, hasUseMd5List);
if (CollectionUtil.isEmpty(pinData)) {
return 0;
}
// long topNum = sketchBoardElements.stream()
// .filter(skecth -> skecth.getHasPin() == 1
// && DesignPythonItem.OUTWEAR_DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
// long bottomNum = sketchBoardElements.stream()
// .filter(skecth -> skecth.getHasPin() == 1
// && DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
// int num = Arrays.asList(topNum, bottomNum).stream().max(Comparator.comparing(Long::valueOf)).get().intValue();
int num = pinData.size();
return Math.min(num, 8);
}
// private int calculatePinSketchNum(List<CollectionElement> sketchBoardElements, List<String> hasUseMd5List) {
// List<CollectionElement> pinData = getPinData(sketchBoardElements, hasUseMd5List);
// if (CollectionUtil.isEmpty(pinData)) {
// return 0;
// }
//// long topNum = sketchBoardElements.stream()
//// .filter(skecth -> skecth.getHasPin() == 1
//// && DesignPythonItem.OUTWEAR_DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
//// long bottomNum = sketchBoardElements.stream()
//// .filter(skecth -> skecth.getHasPin() == 1
//// && DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
//// int num = Arrays.asList(topNum, bottomNum).stream().max(Comparator.comparing(Long::valueOf)).get().intValue();
// int num = pinData.size();
// return Math.min(num, 8);
// }
//计算当前的图片类型
private CurrentDesignPictureTypeEnum calculateCurrentDesignPictureType(int pinSketchNum, int sysSketchNum, int noPinSketchNum) {
@@ -377,23 +381,23 @@ public class PythonService {
}
//计算Pin图片张数
private int calculatePinPictureNum(List<CollectionElement> sketchBoardElements, List<String> hasUseMd5List) {
List<CollectionElement> pinData = getPinData(sketchBoardElements, hasUseMd5List);
if (CollectionUtil.isEmpty(pinData)) {
return 0;
}
long topNum = sketchBoardElements.stream()
.filter(skecth -> skecth.getHasPin() == 1
&& DesignPythonItem.OUTWEAR_DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
long bottomNum = sketchBoardElements.stream()
.filter(skecth -> skecth.getHasPin() == 1
&& DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
int num = Arrays.asList(topNum, bottomNum).stream().max(Comparator.comparing(Long::valueOf)).get().intValue();
if (num > 8) {
return 8;
}
return num;
}
// private int calculatePinPictureNum(List<CollectionElement> sketchBoardElements, List<String> hasUseMd5List) {
// List<CollectionElement> pinData = getPinData(sketchBoardElements, hasUseMd5List);
// if (CollectionUtil.isEmpty(pinData)) {
// return 0;
// }
// long topNum = sketchBoardElements.stream()
// .filter(skecth -> skecth.getHasPin() == 1
// && DesignPythonItem.OUTWEAR_DRESS_BLOUSE.contains(skecth.getLevel2Type())).count();
// long bottomNum = sketchBoardElements.stream()
// .filter(skecth -> skecth.getHasPin() == 1
// && DesignPythonItem.SKIRT_TROUSERS.contains(skecth.getLevel2Type())).count();
// int num = Arrays.asList(topNum, bottomNum).stream().max(Comparator.comparing(Long::valueOf)).get().intValue();
// if (num > 8) {
// return 8;
// }
// return num;
// }
//计算当前的Print图片类型
private CurrentDesignPrintPictureTypeEnum calculateCurrentDesignPintPictureType(long pinPrintNum, long noPinPrintNum, long noPrintNum) {
@@ -478,53 +482,51 @@ public class PythonService {
}
}
private List<DesignPythonItem> coverToDesignPythonItem(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType) {
//Pin的数据
List<CollectionElement> pinData = getPinData(elementVO.getSketchBoardElements(), elementVO.getHasUseMd5List());
//计算填充PythonItemBlouse
List<DesignPythonItem> items = Lists.newArrayList();
if (elementVO.getModelSex().equals("Female")) {
List<DesignPythonItem> blouseList = calculatePythonItemBlouse(pinData, elementVO, designPictureType);
if (!CollectionUtils.isEmpty(blouseList)) {
items.addAll(blouseList);
}
//计算填充PythonItemSkirt
DesignPythonItem skirt = calculatePythonItemSkirt(pinData, elementVO, designPictureType);
if (Objects.nonNull(skirt)) {
items.add(skirt);
}
} else {
// 男装逻辑
DesignPythonItem top = calculatePythonItemTop(pinData, elementVO, designPictureType);
if (Objects.nonNull(top)) {
items.add(top);
}
DesignPythonItem bottom = calculatePythonItemBottom(pinData, elementVO, designPictureType);
if (Objects.nonNull(bottom)) {
items.add(bottom);
}
if (SingleOverallEnum.SINGLE.getRealName().equals(elementVO.getSingleOverall()) && elementVO.getSwitchCategory().equals("Outwear")) {
DesignPythonItem outwear = calculatePythonItemOutwear(pinData, elementVO, designPictureType);
if (Objects.nonNull(outwear)) {
items.add(outwear);
}
}
}
//计算填充Hairstyle Earring Shoes Body
items.addAll(calculatePythonItemHairstyleShoes(elementVO, elementVO.getDesignLibraryModelPoint()));
return items;
}
// private List<DesignPythonItem> coverToDesignPythonItem(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType) {
// //Pin的数据
// List<CollectionElement> pinData = getPinData(elementVO.getSketchBoardElements(), elementVO.getHasUseMd5List());
// //计算填充PythonItemBlouse
// List<DesignPythonItem> items = Lists.newArrayList();
// if (elementVO.getModelSex().equals("Female")) {
// List<DesignPythonItem> blouseList = calculatePythonItemBlouse(pinData, elementVO, designPictureType);
// if (!CollectionUtils.isEmpty(blouseList)) {
// items.addAll(blouseList);
// }
// //计算填充PythonItemSkirt
// DesignPythonItem skirt = calculatePythonItemSkirt(pinData, elementVO, designPictureType);
// if (Objects.nonNull(skirt)) {
// items.add(skirt);
// }
// } else {
// // 男装逻辑
// DesignPythonItem top = calculatePythonItemTop(pinData, elementVO, designPictureType);
// if (Objects.nonNull(top)) {
// items.add(top);
// }
// DesignPythonItem bottom = calculatePythonItemBottom(pinData, elementVO, designPictureType);
// if (Objects.nonNull(bottom)) {
// items.add(bottom);
// }
// if (SingleOverallEnum.SINGLE.getRealName().equals(elementVO.getSingleOverall()) && elementVO.getSwitchCategory().equals("Outwear")) {
// DesignPythonItem outwear = calculatePythonItemOutwear(pinData, elementVO, designPictureType);
// if (Objects.nonNull(outwear)) {
// items.add(outwear);
// }
// }
// }
// //计算填充Hairstyle Earring Shoes Body
// items.addAll(calculatePythonItemHairstyleShoes(elementVO, elementVO.getDesignLibraryModelPoint()));
// return items;
// }
private List<DesignPythonItem> coverToDesignPythonItemNew(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, BigDecimal systemScale) {
List<DesignPythonItem> itemList = new ArrayList<>();
// 根据当前designPictureType确定单一部位的sketch
DesignPythonItem designPythonItem = calculatePythonItem(elementVO, designPictureType);
if (Objects.nonNull(designPythonItem)) {
itemList.add(designPythonItem);
if (elementVO.getSingleOverall().equals(SingleOverallEnum.OVERALL.getRealName())) {
// 根据确定的单一部位sketch确定一整套穿搭
List<String> otherSketchCategoryList = getOtherSketchCategoryList(elementVO.getModelSex(), designPythonItem);
if (!CollectionUtils.isEmpty(otherSketchCategoryList)) {
if (!otherSketchCategoryList.isEmpty()) {
JSONObject attributeRecognition = getAttributeRecognition(designPythonItem, designPythonItem.getType(), elementVO.getModelSex());
for (String styleCategory : otherSketchCategoryList) {
DesignPythonItem otherSketch = processAttributeRecognition(attributeRecognition, elementVO, designPictureType, styleCategory, systemScale);
@@ -539,71 +541,62 @@ public class PythonService {
private DesignPythonItem processAttributeRecognition(JSONObject attributeRecognition, ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, String styleCategory, BigDecimal systemScale) {
switch (designPictureType) {
case PIN: {
// 优先去pin里面找符合类别的
List<CollectionElement> collectPin = elementVO.getSketchBoardElements().stream().filter(o -> o.getHasPin() == 1 && o.getLevel2Type().equals(styleCategory)).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(collectPin)) {
int randomNum = RandomsUtil.randomSysFile(collectPin.size());
elementVO.getHasUseMd5List().add(collectPin.get(randomNum).getMd5());
return coverSketchToDesignPythonItem(collectPin.get(randomNum).getId(), collectPin.get(randomNum), elementVO);
}else {
// 找不到就根据特征找一个系统池子与noPinSketch组成一个池子如果没有noPinSketch就只由系统池子作为池子。
List<CollectionElement> collectNoPin = elementVO.getSketchBoardElements().stream().filter(o -> o.getHasPin() == 0 && o.getLevel2Type().equals(styleCategory)).collect(Collectors.toList());
int poolNum = 20;
if (CollectionUtil.isNotEmpty(collectNoPin)) {
int collectionNoPinSize = collectNoPin.size();
if (systemScale.compareTo(BigDecimal.ZERO) == 0) {
int randomNum = RandomsUtil.randomSysFile(collectNoPin.size());
return coverSketchToDesignPythonItem(null, collectNoPin.get(randomNum), elementVO);
}else if (systemScale.compareTo(BigDecimal.ONE) != 0) {
BigDecimal collectNoPinSize = BigDecimal.valueOf(collectNoPin.size());
poolNum = collectNoPinSize.divide(systemScale, 0, RoundingMode.DOWN).intValue();
List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum);
collectNoPin.addAll(list);
int randomNum = RandomsUtil.randomSysFile(collectNoPin.size());
if (randomNum < collectionNoPinSize) {
return coverSketchToDesignPythonItem(collectNoPin.get(randomNum).getId(), collectNoPin.get(randomNum), elementVO);
}else {
return coverSketchToDesignPythonItem(null, collectNoPin.get(randomNum), elementVO);
}
}
}
List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum);
int randomNum = RandomsUtil.randomSysFile(list.size());
return coverSketchToDesignPythonItem(null, list.get(randomNum), elementVO);
}
}
case PIN:
return processPinAttributeRecognition(attributeRecognition, elementVO, styleCategory, systemScale);
case NO_PIN:
case SYS_FILE: {
List<CollectionElement> collectNoPin = elementVO.getSketchBoardElements().stream().filter(o -> o.getHasPin() == 0 && o.getLevel2Type().equals(styleCategory)).collect(Collectors.toList());
int poolNum = 20;
if (CollectionUtil.isNotEmpty(collectNoPin)) {
int collectionNoPinSize = collectNoPin.size();
if (systemScale.compareTo(BigDecimal.ZERO) == 0) {
int randomNum = RandomsUtil.randomSysFile(collectNoPin.size());
return coverSketchToDesignPythonItem(null, collectNoPin.get(randomNum), elementVO);
}else if (systemScale.compareTo(BigDecimal.ONE) != 0) {
BigDecimal collectNoPinSize = BigDecimal.valueOf(collectNoPin.size());
poolNum = collectNoPinSize.divide(systemScale, 0, RoundingMode.DOWN).intValue();
List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum);
collectNoPin.addAll(list);
int randomNum = RandomsUtil.randomSysFile(collectNoPin.size());
if (randomNum < collectionNoPinSize) {
return coverSketchToDesignPythonItem(collectNoPin.get(randomNum).getId(), collectNoPin.get(randomNum), elementVO);
}else {
return coverSketchToDesignPythonItem(null, collectNoPin.get(randomNum), elementVO);
}
}
}
List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum);
int randomNum = RandomsUtil.randomSysFile(list.size());
return coverSketchToDesignPythonItem(null, list.get(randomNum), elementVO);
}
case SYS_FILE:
return processNoPinOrSysFileAttributeRecognition(attributeRecognition, elementVO, styleCategory, systemScale);
default:
throw new BusinessException("unknown designPictureType");
}
}
private DesignPythonItem processPinAttributeRecognition(JSONObject attributeRecognition, ValidateElementVO elementVO, String styleCategory, BigDecimal systemScale) {
List<CollectionElement> collectPin = getFilteredCollectionElements(elementVO.getSketchBoardElements(), 1, styleCategory);
if (CollectionUtil.isNotEmpty(collectPin)) {
int randomNum = RandomsUtil.randomSysFile(collectPin.size());
elementVO.getHasUseMd5List().add(collectPin.get(randomNum).getMd5());
return coverSketchToDesignPythonItem(collectPin.get(randomNum).getId(), collectPin.get(randomNum), elementVO);
} else {
List<CollectionElement> collectNoPin = getFilteredCollectionElements(elementVO.getSketchBoardElements(), 0, styleCategory);
return processNoPinOrSysFileAttributeRecognitionWithPool(collectNoPin, attributeRecognition, elementVO, styleCategory, systemScale);
}
}
private DesignPythonItem processNoPinOrSysFileAttributeRecognition(JSONObject attributeRecognition, ValidateElementVO elementVO, String styleCategory, BigDecimal systemScale) {
List<CollectionElement> collectNoPin = getFilteredCollectionElements(elementVO.getSketchBoardElements(), 0, styleCategory);
return processNoPinOrSysFileAttributeRecognitionWithPool(collectNoPin, attributeRecognition, elementVO, styleCategory, systemScale);
}
private DesignPythonItem processNoPinOrSysFileAttributeRecognitionWithPool(List<CollectionElement> collectionElements, JSONObject attributeRecognition, ValidateElementVO elementVO, String styleCategory, BigDecimal systemScale) {
int poolNum = 20;
if (CollectionUtil.isNotEmpty(collectionElements)) {
int collectionNoPinSize = collectionElements.size();
if (systemScale.compareTo(BigDecimal.ZERO) == 0) {
int randomNum = RandomsUtil.randomSysFile(collectionNoPinSize);
return coverSketchToDesignPythonItem(null, collectionElements.get(randomNum), elementVO);
} else if (systemScale.compareTo(BigDecimal.ONE) != 0) {
BigDecimal collectNoPinSize = BigDecimal.valueOf(collectionNoPinSize);
poolNum = collectNoPinSize.divide(systemScale, 0, RoundingMode.DOWN).intValue();
List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum);
collectionElements.addAll(list);
int randomNum = RandomsUtil.randomSysFile(collectionElements.size());
if (randomNum < collectionNoPinSize) {
return coverSketchToDesignPythonItem(collectionElements.get(randomNum).getId(), collectionElements.get(randomNum), elementVO);
} else {
return coverSketchToDesignPythonItem(null, collectionElements.get(randomNum), elementVO);
}
}
}
List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum);
int randomNum = RandomsUtil.randomSysFile(list.size());
return coverSketchToDesignPythonItem(null, list.get(randomNum), elementVO);
}
private List<CollectionElement> getFilteredCollectionElements(List<CollectionElement> elements, int hasPin, String styleCategory) {
return CollectionUtil.isNotEmpty(elements) ? elements.stream().filter(o -> o.getHasPin() == hasPin && o.getLevel2Type().equals(styleCategory)).collect(Collectors.toList()) : null;
}
private DesignPythonItem processAttributeRecognitionBySameCategory(JSONObject attributeRecognition, ValidateElementVO elementVO, String styleCategory) {
List<CollectionElement> list = getSystemSketchPoolBySameCategory(attributeRecognition, styleCategory, elementVO.getModelSex());
int randomNum = RandomsUtil.randomSysFile(list.size());
@@ -745,16 +738,13 @@ public class PythonService {
}
public JSONObject getAttributeRecognition(DesignPythonItem designPythonItem, String styleCategory, String modelSex) {
// todo 限流校验
// AccessLimitUtils.validate("design",5);
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build();
MediaType mediaType = MediaType.parse("application/json");
//关闭FastJson的引用检测 防止出现$ref 现象
JSONObject paramJSONObject = new JSONObject();
paramJSONObject.put("category", styleCategory);
paramJSONObject.put("colony", modelSex);
@@ -762,42 +752,29 @@ public class PythonService {
JSONArray paramArray = new JSONArray();
paramArray.add(paramJSONObject);
String param = JSON.toJSONString(paramArray, SerializerFeature.DisableCircularReferenceDetect);
log.info("design请求python 参数:####{}", param);
log.info("PythonService##design 请求参数:####{}", param);
RequestBody body = RequestBody.create(mediaType, param);
Request request = new Request.Builder()
.url(accessPythonIp + ":" + accessPythonPort + "/api/attribute_recognition")
.method("POST", body)
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json")
.build();
Response response;
String responseBody;
try {
response = client.newCall(request).execute();
} catch (IOException ioException) {
AccessLimitUtils.validateOut("design");
log.error("PythonService##design异常###{}", ExceptionUtil.getThrowableList(ioException));
throw new BusinessException("design.interface.exception");
}
//去除限流
// AccessLimitUtils.validateOut("design");
if (response.isSuccessful()) {
try {
if (Objects.nonNull(response.body())) {
responseBody = response.body().string();
JSONObject responseObject = JSON.parseObject(responseBody);
log.info("PythonService##responseObject###{}", responseObject);
return responseObject;
}
throw new BusinessException("design.interface.exception");
} catch (IOException | JSONException e) {
log.error("PythonService##design异常###{}", e.getMessage());
throw new BusinessException("design.interface.exception");
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
String responseBody = Objects.requireNonNull(response.body()).string();
JSONObject responseObject = JSON.parseObject(responseBody);
log.info("PythonService##responseObject###{}", responseObject);
return responseObject;
} else {
log.error("PythonService##design 请求异常:{}", response);
throw new BusinessException("attributeRecognition.interface.exception");
}
} catch (IOException e) {
log.error("PythonService##design 请求异常:{}", e.getMessage());
throw new BusinessException("attributeRecognition.interface.exception");
}
log.error("PythonService##design异常response###{}", response);
//生成失败
throw new BusinessException("design.interface.exception");
}
public JSONObject getAttributeRecognitionBySameCategory(CollectionElement element, String modelSex) {
@@ -871,92 +848,100 @@ public class PythonService {
return null;
}
private DesignPythonItem calculatePythonItem(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType) {
switch (designPictureType) {
case PIN: {
List<CollectionElement> pinData = getPinData(elementVO);
if (CollectionUtil.isEmpty(pinData)) {
throw new BusinessException("pinData is null");
}
Random random = new Random();
int randomNumber = random.nextInt(pinData.size());
elementVO.getHasUseMd5List().add(pinData.get(randomNumber).getMd5());
return coverSketchToDesignPythonItem(pinData.get(randomNumber).getId(), pinData.get(randomNumber), elementVO);
}
case NO_PIN: {
List<CollectionElement> noPinData = getNoPinData(elementVO);
if (CollectionUtil.isEmpty(noPinData)) {
// 根据pin的获取 type
List<CollectionElement> sketchBoardPins = elementVO.getSketchBoardElements()
.stream().filter(v -> v.getHasPin() == 1).collect(Collectors.toList());
if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) {
sketchBoardPins = sketchBoardPins.stream().filter(o -> o.getLevel2Type().equals(elementVO.getSwitchCategory())).collect(Collectors.toList());
}
if (CollectionUtil.isNotEmpty(sketchBoardPins)) {
Integer randomNum = RandomsUtil.randomSysFile(sketchBoardPins.size());
CollectionElement element = sketchBoardPins.get(randomNum);
JSONObject attributeRecognition = getAttributeRecognitionBySameCategory(element, elementVO.getModelSex());
return processAttributeRecognitionBySameCategory(attributeRecognition, elementVO, element.getLevel2Type());
}
QueryWrapper<Dressing> qw = new QueryWrapper<>();
qw.lambda().eq(Dressing::getApparel, elementVO.getModelSex());
if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) {
qw.lambda().eq(Dressing::getStyleCategory, elementVO.getSwitchCategory());
}
List<Dressing> dressings = dressingMapper.selectList(qw);
if (CollectionUtil.isEmpty(dressings)) {
throw new BusinessException("dressings is null");
}
Integer randomNum = RandomsUtil.randomSysFile(dressings.size());
String category = dressings.get(randomNum).getStyleCategory();
String tableName;
tableName = getTableName(elementVO.getModelSex(), category);
AttributeRetrieval attributeRetrieval = attributeRetrievalMapper.getSystemRandom(tableName);
CollectionElement collectionElement = toCollectionElement(attributeRetrieval, category, elementVO.getModelSex());
return coverSketchToDesignPythonItem(null, collectionElement, elementVO);
}
Random random = new Random();
int randomNumber = random.nextInt(noPinData.size());
return coverSketchToDesignPythonItem(noPinData.get(randomNumber).getId(), noPinData.get(randomNumber), elementVO);
}
case SYS_FILE: {
// 根据pin noPin的获取 type
List<CollectionElement> sketchBoardPins = elementVO.getSketchBoardElements();
if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) {
sketchBoardPins = sketchBoardPins.stream().filter(o -> o.getLevel2Type().equals(elementVO.getSwitchCategory())).collect(Collectors.toList());
}
if (CollectionUtil.isNotEmpty(sketchBoardPins)) {
Integer randomNum = RandomsUtil.randomSysFile(sketchBoardPins.size());
CollectionElement element = sketchBoardPins.get(randomNum);
JSONObject attributeRecognition = getAttributeRecognitionBySameCategory(element, elementVO.getModelSex());
return processAttributeRecognitionBySameCategory(attributeRecognition, elementVO, element.getLevel2Type());
}
QueryWrapper<Dressing> qw = new QueryWrapper<>();
qw.lambda().eq(Dressing::getApparel, elementVO.getModelSex());
if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) {
qw.lambda().eq(Dressing::getStyleCategory, elementVO.getSwitchCategory());
}
List<Dressing> dressings = dressingMapper.selectList(qw);
if (CollectionUtil.isEmpty(dressings)) {
throw new BusinessException("dressings is null");
}
Integer randomNum = RandomsUtil.randomSysFile(dressings.size());
String category = dressings.get(randomNum).getStyleCategory();
String tableName;
tableName = getTableName(elementVO.getModelSex(), category);
AttributeRetrieval attributeRetrieval = attributeRetrievalMapper.getSystemRandom(tableName);
CollectionElement collectionElement = toCollectionElement(attributeRetrieval, category, elementVO.getModelSex());
return coverSketchToDesignPythonItem(null, collectionElement, elementVO);
}
private DesignPythonItem calculatePythonItem(ValidateElementVO validateElementVO, CurrentDesignPictureTypeEnum currentDesignPictureType) {
switch (currentDesignPictureType) {
case PIN:
return calculatePinPythonItem(validateElementVO);
case NO_PIN:
return calculateNoPinPythonItem(validateElementVO);
case SYS_FILE:
return calculateSysFilePythonItem(validateElementVO);
default:
return null;
}
}
private DesignPythonItem calculatePinPythonItem(ValidateElementVO validateElementVO) {
List<CollectionElement> pinCollectionData = getPinData(validateElementVO);
if (CollectionUtil.isEmpty(pinCollectionData)) {
throw new BusinessException("pinData is null");
}
Random random = new Random();
int randomNumber = random.nextInt(pinCollectionData.size());
validateElementVO.getHasUseMd5List().add(pinCollectionData.get(randomNumber).getMd5());
return coverSketchToDesignPythonItem(pinCollectionData.get(randomNumber).getId(), pinCollectionData.get(randomNumber), validateElementVO);
}
private DesignPythonItem calculateNoPinPythonItem(ValidateElementVO validateElementVO) {
List<CollectionElement> noPinCollectionData = getNoPinData(validateElementVO);
if (CollectionUtil.isEmpty(noPinCollectionData)) {
List<CollectionElement> sketchBoardPins = getPinDataWhole(validateElementVO);
if (validateElementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) {
sketchBoardPins = sketchBoardPins.stream().filter(o -> o.getLevel2Type().equals(validateElementVO.getSwitchCategory())).collect(Collectors.toList());
}
if (CollectionUtil.isNotEmpty(sketchBoardPins)) {
Integer randomNum = RandomsUtil.randomSysFile(sketchBoardPins.size());
CollectionElement element = sketchBoardPins.get(randomNum);
JSONObject attributeRecognition = getAttributeRecognitionBySameCategory(element, validateElementVO.getModelSex());
return processAttributeRecognitionBySameCategory(attributeRecognition, validateElementVO, element.getLevel2Type());
}
QueryWrapper<Dressing> qw = new QueryWrapper<>();
qw.lambda().eq(Dressing::getApparel, validateElementVO.getModelSex());
if (validateElementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) {
qw.lambda().eq(Dressing::getApparel, validateElementVO.getSwitchCategory());
}
List<Dressing> dressings = dressingMapper.selectList(qw);
if (CollectionUtil.isEmpty(dressings)) {
throw new BusinessException("dressings is null");
}
Integer randomNum = RandomsUtil.randomSysFile(dressings.size());
String category = dressings.get(randomNum).getStyleCategory();
String tableName = getTableName(validateElementVO.getModelSex(), category);
AttributeRetrieval attributeRetrieval = attributeRetrievalMapper.getSystemRandom(tableName);
CollectionElement collectionElement = toCollectionElement(attributeRetrieval, category, validateElementVO.getModelSex());
return coverSketchToDesignPythonItem(null, collectionElement, validateElementVO);
}
Random random = new Random();
int randomNumber = random.nextInt(noPinCollectionData.size());
return coverSketchToDesignPythonItem(noPinCollectionData.get(randomNumber).getId(), noPinCollectionData.get(randomNumber), validateElementVO);
}
private DesignPythonItem calculateSysFilePythonItem(ValidateElementVO validateElementVO) {
List<CollectionElement> sketchBoardCollectionElements = validateElementVO.getSketchBoardElements();
if (!CollectionUtils.isEmpty(sketchBoardCollectionElements)) {
if (validateElementVO.getModelSex().equals(Sex.MALE.getValue())) {
sketchBoardCollectionElements = sketchBoardCollectionElements.stream().filter(o -> MALE_CATEGORY.contains(o.getLevel2Type())).collect(Collectors.toList());
}
if (validateElementVO.getModelSex().equals(Sex.FEMALE.getValue())) {
sketchBoardCollectionElements = sketchBoardCollectionElements.stream().filter(o -> FEMALE_CATEGORY.contains(o.getLevel2Type())).collect(Collectors.toList());
}
if (validateElementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) {
sketchBoardCollectionElements = sketchBoardCollectionElements.stream().filter(o -> o.getLevel2Type().equals(validateElementVO.getSwitchCategory())).collect(Collectors.toList());
}
if (CollectionUtil.isNotEmpty(sketchBoardCollectionElements)) {
Integer randomNum = RandomsUtil.randomSysFile(sketchBoardCollectionElements.size());
CollectionElement element = sketchBoardCollectionElements.get(randomNum);
JSONObject attributeRecognition = getAttributeRecognitionBySameCategory(element, validateElementVO.getModelSex());
return processAttributeRecognitionBySameCategory(attributeRecognition, validateElementVO, element.getLevel2Type());
}
}
QueryWrapper<Dressing> qw = new QueryWrapper<>();
qw.lambda().eq(Dressing::getApparel, validateElementVO.getModelSex());
if (validateElementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) {
qw.lambda().eq(Dressing::getApparel, validateElementVO.getSwitchCategory());
}
List<Dressing> dressings = dressingMapper.selectList(qw);
if (CollectionUtil.isEmpty(dressings)) {
throw new BusinessException("dressings is null");
}
Integer randomNum = RandomsUtil.randomSysFile(dressings.size());
String category = dressings.get(randomNum).getStyleCategory();
String tableName = getTableName(validateElementVO.getModelSex(), category);
AttributeRetrieval attributeRetrieval = attributeRetrievalMapper.getSystemRandom(tableName);
CollectionElement collectionElement = toCollectionElement(attributeRetrieval, category, validateElementVO.getModelSex());
return coverSketchToDesignPythonItem(null, collectionElement, validateElementVO);
}
private String getTableName(String modelSex, String category) {
switch (modelSex) {
case "Female": {
@@ -2004,7 +1989,7 @@ public class PythonService {
}
private List<CollectionElement> getPinData(ValidateElementVO elementVO) {
List<CollectionElement> pinData = getPinData(elementVO.getSketchBoardElements(), elementVO.getHasUseMd5List());
List<CollectionElement> pinData = getPinData(elementVO.getSketchBoardElements(), elementVO.getHasUseMd5List(), elementVO.getModelSex());
if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) {
if (!CollectionUtils.isEmpty(pinData)) {
return pinData.stream().filter(o -> o.getLevel2Type().equals(elementVO.getSwitchCategory())).collect(Collectors.toList());
@@ -2016,12 +2001,52 @@ public class PythonService {
}
}
private List<CollectionElement> getPinData(List<CollectionElement> sketchBoardElements, List<String> hasUseMd5List) {
private List<CollectionElement> getPinDataWhole(ValidateElementVO elementVO) {
List<CollectionElement> pinData = getPinDataWhole(elementVO.getSketchBoardElements(), elementVO.getHasUseMd5List(), elementVO.getModelSex());
if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) {
if (!CollectionUtils.isEmpty(pinData)) {
return pinData.stream().filter(o -> o.getLevel2Type().equals(elementVO.getSwitchCategory())).collect(Collectors.toList());
}else {
return pinData;
}
}else {
return pinData;
}
}
private List<CollectionElement> getPinDataWhole(List<CollectionElement> sketchBoardElements, List<String> hasUseMd5List, String modelSex) {
if (CollectionUtils.isEmpty(sketchBoardElements)) {
return null;
}
List<CollectionElement> sketchBoardPins = sketchBoardElements
.stream().filter(v -> v.getHasPin() == 1).collect(Collectors.toList());
if (modelSex.equals(Sex.MALE.getValue())) {
sketchBoardPins = sketchBoardPins.stream().filter(o -> MALE_CATEGORY.contains(o.getLevel2Type())).collect(Collectors.toList());
}
if (modelSex.equals(Sex.FEMALE.getValue())) {
sketchBoardPins = sketchBoardPins.stream().filter(o -> FEMALE_CATEGORY.contains(o.getLevel2Type())).collect(Collectors.toList());
}
if (CollectionUtils.isEmpty(sketchBoardPins)) {
return null;
}
return sketchBoardPins;
}
public final static List<String> FEMALE_CATEGORY = Arrays.asList("Dress","Blouse","Skirt","Trousers","Outwear");
public final static List<String> MALE_CATEGORY = Arrays.asList("Tops","Bottoms","Outwear");
private List<CollectionElement> getPinData(List<CollectionElement> sketchBoardElements, List<String> hasUseMd5List, String modelSex) {
if (CollectionUtils.isEmpty(sketchBoardElements)) {
return null;
}
List<CollectionElement> sketchBoardPins = sketchBoardElements
.stream().filter(v -> v.getHasPin() == 1 && (!hasUseMd5List.contains(v.getMd5()))).collect(Collectors.toList());
if (modelSex.equals(Sex.MALE.getValue())) {
sketchBoardPins = sketchBoardPins.stream().filter(o -> MALE_CATEGORY.contains(o.getLevel2Type())).collect(Collectors.toList());
}
if (modelSex.equals(Sex.FEMALE.getValue())) {
sketchBoardPins = sketchBoardPins.stream().filter(o -> FEMALE_CATEGORY.contains(o.getLevel2Type())).collect(Collectors.toList());
}
if (CollectionUtils.isEmpty(sketchBoardPins)) {
return null;
}
@@ -2030,22 +2055,28 @@ public class PythonService {
private List<CollectionElement> getNoPinData(ValidateElementVO elementVO) {
if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) {
List<CollectionElement> noPinData = getNoPinData(elementVO.getSketchBoardElements());
List<CollectionElement> noPinData = getNoPinData(elementVO.getSketchBoardElements(), elementVO.getModelSex());
if (CollectionUtils.isEmpty(noPinData)) {
return null;
}
return noPinData.stream().filter(o -> o.getLevel2Type().equals(elementVO.getSwitchCategory())).collect(Collectors.toList());
}else {
return getNoPinData(elementVO.getSketchBoardElements());
return getNoPinData(elementVO.getSketchBoardElements(), elementVO.getModelSex());
}
}
private List<CollectionElement> getNoPinData(List<CollectionElement> sketchBoardElements) {
private List<CollectionElement> getNoPinData(List<CollectionElement> sketchBoardElements, String modelSex) {
if (CollectionUtils.isEmpty(sketchBoardElements)) {
return null;
}
List<CollectionElement> sketchBoardPins = sketchBoardElements
.stream().filter(v -> v.getHasPin() == 0).collect(Collectors.toList());
if (modelSex.equals(Sex.MALE.getValue())) {
sketchBoardPins = sketchBoardPins.stream().filter(o -> MALE_CATEGORY.contains(o.getLevel2Type())).collect(Collectors.toList());
}
if (modelSex.equals(Sex.FEMALE.getValue())) {
sketchBoardPins = sketchBoardPins.stream().filter(o -> FEMALE_CATEGORY.contains(o.getLevel2Type())).collect(Collectors.toList());
}
if (CollectionUtils.isEmpty(sketchBoardPins)) {
return null;
}

View File

@@ -304,21 +304,36 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
//保存design
Long designId = saveOne(designDTO, collectionId, userInfo.getId());
//计算library
calculateLibraryAndSysFile(designDTO, elementVO, userInfo);
// calculateLibraryAndSysFile(designDTO, elementVO, userInfo);
//组装design入参
long startTime = System.currentTimeMillis();
DesignPythonObjects pythonObjects = pythonService.covertDesignParam(designDTO.getSystemScale(),
designDTO.getSingleOverall(), designDTO.getSwitchCategory(), elementVO, designDTO.getProcessId());
long endTime = System.currentTimeMillis();
long totalTimeInSeconds = (endTime - startTime) / 1000;
log.info("组装入参运行时间:" + totalTimeInSeconds + "");
// pythonObjects增加image_id关联
startTime = System.currentTimeMillis();
List<Long> imageIds = relationImageIds(pythonObjects);
System.out.println(imageIds);
endTime = System.currentTimeMillis();
totalTimeInSeconds = (endTime - startTime) / 1000;
log.info("增加image_id关联运行时间" + totalTimeInSeconds + "");
//design
startTime = System.currentTimeMillis();
JSONObject responseJSONObject = pythonService.designNew(pythonObjects);
endTime = System.currentTimeMillis();
totalTimeInSeconds = (endTime - startTime) / 1000;
log.info("design python端运行时间" + totalTimeInSeconds + "");
//生成library
startTime = System.currentTimeMillis();
generateLibrary(elementVO, designDTO.getTimeZone());
//处理关联关系,修复element覆盖得情况
List<CollectionElement> relationElements = collectionElementService.getByOnlyCollectionId(collectionId);
List<Long> relationElementIds = relationElements.stream().map(CollectionElement::getId).collect(Collectors.toList());
handleCollectionElementRelation(collectionId, null != collectionIdParam, relationElementIds);
endTime = System.currentTimeMillis();
totalTimeInSeconds = (endTime - startTime) / 1000;
log.info("处理关联关系运行时间:" + totalTimeInSeconds + "");
//保存python返回信息;保存designItem和detail
return savePythonDesignItemAndDetail(pythonObjects, designId, collectionId, userInfo, designDTO.getTimeZone(), responseJSONObject, designDTO.getSingleOverall());
}
@@ -702,10 +717,10 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
throw new BusinessException("collection.not.found");
}
AuthPrincipalVo userInfo = UserContext.getUserHolder();
//查询用户 sketch library
List<LibraryVo> libraryVos = libraryService.selectByAccountIdAnd1TypeList(userInfo.getId(),
Arrays.asList(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName(),
CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName()));
// //查询用户 sketch library
// List<LibraryVo> libraryVos = libraryService.selectByAccountIdAnd1TypeList(userInfo.getId(),
// Arrays.asList(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName(),
// CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName()));
//校验collection element
DesignCollectionDTO designCollectionDTO = CopyUtil.copyObject(reDesignDTO, DesignCollectionDTO.class);
ValidateElementVO elementVO = collectionElementService.validateElement(designCollectionDTO);
@@ -1015,49 +1030,41 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
public Integer designProcess(String processId) {
ProcessIdObject object = new ProcessIdObject();
object.setProcess_id(processId);
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.pingInterval(5, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build();
MediaType mediaType = MediaType.parse("application/json");
//关闭FastJson的引用检测 防止出现$ref 现象
String param = JSON.toJSONString(object, SerializerFeature.DisableCircularReferenceDetect);
log.info("designProcess请求python 参数:####{}", param);
RequestBody body = RequestBody.create(mediaType, param);
Request request = new Request.Builder()
// .url("http://18.167.251.121:9991/api/get_progress")
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
.url(accessPythonIp + ":" + accessPythonPort + "/api/get_progress")
.method("POST", body)
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json")
.build();
Response response;
try {
response = client.newCall(request).execute();
} catch (IOException e) {
log.error("PythonService##design进度条异常###{}", ExceptionUtil.getThrowableList(e));
return 0;
}
if (response.isSuccessful()) {
try {
if (Objects.nonNull(response.body())) {
String responseBody = response.body().string();
JSONObject responseObject = JSON.parseObject(responseBody);
String num = responseObject.getString("data");
return Integer.valueOf(num);
}
return 0;
} catch (IOException | JSONException e) {
log.error("PythonService##design进度条异常###{}", ExceptionUtil.getThrowableList(e));
return 0;
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
String responseBody = Objects.requireNonNull(response.body()).string();
JSONObject responseObject = JSON.parseObject(responseBody);
String num = responseObject.getString("data");
return Integer.valueOf(num);
}
} catch (IOException | JSONException e) {
log.error("PythonService##design进度条异常###{}", ExceptionUtil.getThrowableList(e));
}
return 0;
}
private String converTypeToLevel1(String type) {
if (StringUtils.isEmpty(type)) {
return null;