From 43ec55dfb6373bbfea1c1bcc19c5bf2a1a70ef48 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 21 Feb 2024 13:53:46 +0800 Subject: [PATCH 1/2] BUGFIX:Single design; --- .../ai/da/model/vo/QueryLibraryPageVO.java | 3 + .../java/com/ai/da/python/PythonService.java | 227 +++++++++++------- .../ai/da/service/impl/DesignServiceImpl.java | 10 +- 3 files changed, 150 insertions(+), 90 deletions(-) diff --git a/src/main/java/com/ai/da/model/vo/QueryLibraryPageVO.java b/src/main/java/com/ai/da/model/vo/QueryLibraryPageVO.java index eca67503..eaff197f 100644 --- a/src/main/java/com/ai/da/model/vo/QueryLibraryPageVO.java +++ b/src/main/java/com/ai/da/model/vo/QueryLibraryPageVO.java @@ -23,6 +23,9 @@ public class QueryLibraryPageVO { @ApiModelProperty("二级类型") private String level2Type; + @ApiModelProperty("三级类型") + private String level3Type; + @ApiModelProperty("design类型 用户design生成时候区别library和collection") private String designType; diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index 3179e1bd..44b25d68 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -311,21 +311,21 @@ public class PythonService { return result.setScale(0, RoundingMode.HALF_UP).intValue(); } - private int calculatePinSketchNum(List sketchBoardElements, List hasUseMd5List) { - List 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 sketchBoardElements, List hasUseMd5List) { +// List 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 +377,23 @@ public class PythonService { } //计算Pin图片张数 - private int calculatePinPictureNum(List sketchBoardElements, List hasUseMd5List) { - List 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 sketchBoardElements, List hasUseMd5List) { +// List 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,42 +478,42 @@ public class PythonService { } } - private List coverToDesignPythonItem(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType) { - //Pin的数据 - List pinData = getPinData(elementVO.getSketchBoardElements(), elementVO.getHasUseMd5List()); - //计算填充PythonItemBlouse - List items = Lists.newArrayList(); - if (elementVO.getModelSex().equals("Female")) { - List 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 coverToDesignPythonItem(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType) { +// //Pin的数据 +// List pinData = getPinData(elementVO.getSketchBoardElements(), elementVO.getHasUseMd5List()); +// //计算填充PythonItemBlouse +// List items = Lists.newArrayList(); +// if (elementVO.getModelSex().equals("Female")) { +// List 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 coverToDesignPythonItemNew(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, BigDecimal systemScale) { List itemList = new ArrayList<>(); @@ -575,7 +575,12 @@ public class PythonService { } case NO_PIN: case SYS_FILE: { - List collectNoPin = elementVO.getSketchBoardElements().stream().filter(o -> o.getHasPin() == 0 && o.getLevel2Type().equals(styleCategory)).collect(Collectors.toList()); + List collectNoPin; + if (CollectionUtils.isEmpty(elementVO.getSketchBoardElements())) { + collectNoPin = null; + }else { + 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(); @@ -887,8 +892,7 @@ public class PythonService { List noPinData = getNoPinData(elementVO); if (CollectionUtil.isEmpty(noPinData)) { // 根据pin的获取 type - List sketchBoardPins = elementVO.getSketchBoardElements() - .stream().filter(v -> v.getHasPin() == 1).collect(Collectors.toList()); + List sketchBoardPins = getPinDataWhole(elementVO); if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) { sketchBoardPins = sketchBoardPins.stream().filter(o -> o.getLevel2Type().equals(elementVO.getSwitchCategory())).collect(Collectors.toList()); } @@ -924,16 +928,23 @@ public class PythonService { case SYS_FILE: { // 根据pin noPin的获取 type List sketchBoardPins = elementVO.getSketchBoardElements(); - if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) { - sketchBoardPins = sketchBoardPins.stream().filter(o -> o.getLevel2Type().equals(elementVO.getSwitchCategory())).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(sketchBoardPins)) { + if (elementVO.getModelSex().equals(Sex.MALE.getValue())) { + sketchBoardPins = sketchBoardPins.stream().filter(o -> MALE_CATEGORY.contains(o.getLevel2Type())).collect(Collectors.toList()); + } + if (elementVO.getModelSex().equals(Sex.FEMALE.getValue())) { + sketchBoardPins = sketchBoardPins.stream().filter(o -> FEMALE_CATEGORY.contains(o.getLevel2Type())).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()); + } } - 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 qw = new QueryWrapper<>(); qw.lambda().eq(Dressing::getApparel, elementVO.getModelSex()); if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) { @@ -2004,7 +2015,7 @@ public class PythonService { } private List getPinData(ValidateElementVO elementVO) { - List pinData = getPinData(elementVO.getSketchBoardElements(), elementVO.getHasUseMd5List()); + List 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 +2027,52 @@ public class PythonService { } } - private List getPinData(List sketchBoardElements, List hasUseMd5List) { + private List getPinDataWhole(ValidateElementVO elementVO) { + List 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 getPinDataWhole(List sketchBoardElements, List hasUseMd5List, String modelSex) { + if (CollectionUtils.isEmpty(sketchBoardElements)) { + return null; + } + List 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 FEMALE_CATEGORY = Arrays.asList("Dress","Blouse","Skirt","Trousers","Outwear"); + public final static List MALE_CATEGORY = Arrays.asList("Tops","Bottoms","Outwear"); + + private List getPinData(List sketchBoardElements, List hasUseMd5List, String modelSex) { if (CollectionUtils.isEmpty(sketchBoardElements)) { return null; } List 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 +2081,28 @@ public class PythonService { private List getNoPinData(ValidateElementVO elementVO) { if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) { - List noPinData = getNoPinData(elementVO.getSketchBoardElements()); + List 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 getNoPinData(List sketchBoardElements) { + private List getNoPinData(List sketchBoardElements, String modelSex) { if (CollectionUtils.isEmpty(sketchBoardElements)) { return null; } List 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; } diff --git a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java index 783b2038..e0f27be9 100644 --- a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java @@ -304,7 +304,7 @@ public class DesignServiceImpl extends ServiceImpl impleme //保存design Long designId = saveOne(designDTO, collectionId, userInfo.getId()); //计算library - calculateLibraryAndSysFile(designDTO, elementVO, userInfo); +// calculateLibraryAndSysFile(designDTO, elementVO, userInfo); //组装design入参 DesignPythonObjects pythonObjects = pythonService.covertDesignParam(designDTO.getSystemScale(), designDTO.getSingleOverall(), designDTO.getSwitchCategory(), elementVO, designDTO.getProcessId()); @@ -702,10 +702,10 @@ public class DesignServiceImpl extends ServiceImpl impleme throw new BusinessException("collection.not.found"); } AuthPrincipalVo userInfo = UserContext.getUserHolder(); - //查询用户 sketch library - List libraryVos = libraryService.selectByAccountIdAnd1TypeList(userInfo.getId(), - Arrays.asList(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName(), - CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName())); +// //查询用户 sketch library +// List 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); From 22330b674afbc34a87ad89bd71e645660e8b5159 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 21 Feb 2024 15:16:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?BUGFIX:=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ai/da/python/PythonService.java | 436 ++++++++---------- .../ai/da/service/impl/DesignServiceImpl.java | 59 +-- 2 files changed, 238 insertions(+), 257 deletions(-) diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index 44b25d68..4d7da8d2 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -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 objects = Lists.newArrayList(); + List 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 pinData = getPinData(elementVO); if (CollectionUtil.isNotEmpty(pinData)) { @@ -517,14 +521,12 @@ public class PythonService { private List coverToDesignPythonItemNew(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, BigDecimal systemScale) { List 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 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,76 +541,62 @@ public class PythonService { private DesignPythonItem processAttributeRecognition(JSONObject attributeRecognition, ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, String styleCategory, BigDecimal systemScale) { switch (designPictureType) { - case PIN: { - // 优先去pin里面找符合类别的 - List 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 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 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 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 collectNoPin; - if (CollectionUtils.isEmpty(elementVO.getSketchBoardElements())) { - collectNoPin = null; - }else { - 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 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 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 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 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 collectNoPin = getFilteredCollectionElements(elementVO.getSketchBoardElements(), 0, styleCategory); + return processNoPinOrSysFileAttributeRecognitionWithPool(collectNoPin, attributeRecognition, elementVO, styleCategory, systemScale); + } + + private DesignPythonItem processNoPinOrSysFileAttributeRecognitionWithPool(List 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 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 list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum); + int randomNum = RandomsUtil.randomSysFile(list.size()); + return coverSketchToDesignPythonItem(null, list.get(randomNum), elementVO); + } + + private List getFilteredCollectionElements(List 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 list = getSystemSketchPoolBySameCategory(attributeRecognition, styleCategory, elementVO.getModelSex()); int randomNum = RandomsUtil.randomSysFile(list.size()); @@ -750,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); @@ -767,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) { @@ -876,98 +848,100 @@ public class PythonService { return null; } - private DesignPythonItem calculatePythonItem(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType) { - switch (designPictureType) { - case PIN: { - List 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 noPinData = getNoPinData(elementVO); - if (CollectionUtil.isEmpty(noPinData)) { - // 根据pin的获取 type - List sketchBoardPins = getPinDataWhole(elementVO); - 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 qw = new QueryWrapper<>(); - qw.lambda().eq(Dressing::getApparel, elementVO.getModelSex()); - if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) { - qw.lambda().eq(Dressing::getApparel, elementVO.getSwitchCategory()); - } - List 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 sketchBoardPins = elementVO.getSketchBoardElements(); - if (!CollectionUtils.isEmpty(sketchBoardPins)) { - if (elementVO.getModelSex().equals(Sex.MALE.getValue())) { - sketchBoardPins = sketchBoardPins.stream().filter(o -> MALE_CATEGORY.contains(o.getLevel2Type())).collect(Collectors.toList()); - } - if (elementVO.getModelSex().equals(Sex.FEMALE.getValue())) { - sketchBoardPins = sketchBoardPins.stream().filter(o -> FEMALE_CATEGORY.contains(o.getLevel2Type())).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 qw = new QueryWrapper<>(); - qw.lambda().eq(Dressing::getApparel, elementVO.getModelSex()); - if (elementVO.getSingleOverall().equals(SingleOverallEnum.SINGLE.getRealName())) { - qw.lambda().eq(Dressing::getApparel, elementVO.getSwitchCategory()); - } - List 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 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 noPinCollectionData = getNoPinData(validateElementVO); + if (CollectionUtil.isEmpty(noPinCollectionData)) { + List 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 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 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 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 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 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": { diff --git a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java index e0f27be9..f5fe6222 100644 --- a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java @@ -306,19 +306,34 @@ public class DesignServiceImpl extends ServiceImpl impleme //计算library // 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 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 relationElements = collectionElementService.getByOnlyCollectionId(collectionId); List 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()); } @@ -1015,49 +1030,41 @@ public class DesignServiceImpl extends ServiceImpl 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;