Merge branch 'dev/dev_shb' into dev/dev

# Conflicts:
#	src/main/java/com/ai/da/python/PythonService.java
This commit is contained in:
shahaibo
2024-02-21 15:27:57 +08:00
2 changed files with 238 additions and 257 deletions

View File

@@ -217,32 +217,40 @@ public class PythonService {
public DesignPythonObjects covertDesignParam(BigDecimal systemScale, String singleOverall, public DesignPythonObjects covertDesignParam(BigDecimal systemScale, String singleOverall,
String switchCategory, ValidateElementVO elementVO, String processId) { String switchCategory, ValidateElementVO elementVO, String processId) {
DesignPythonObjects designPythonObjects = new DesignPythonObjects(); DesignPythonObjects designPythonObjects = new DesignPythonObjects();
List<DesignPythonObject> objects = Lists.newArrayList(); List<DesignPythonObject> objects = new ArrayList<>();
designPythonObjects.setObjects(objects); designPythonObjects.setObjects(objects);
designPythonObjects.setProcess_id(processId); designPythonObjects.setProcess_id(processId);
long pinPrintNum = calculateDesignPinPrintNum(elementVO.getPrintBoardElements()); long pinPrintNum = calculateDesignPinPrintNum(elementVO.getPrintBoardElements());
long noPinPrintNum = calculateDesignNoPinPrintNum(elementVO.getPrintBoardElements()); long noPinPrintNum = calculateDesignNoPinPrintNum(elementVO.getPrintBoardElements());
//没有print的
long noPrintNum = 8 - pinPrintNum - noPinPrintNum; long noPrintNum = 8 - pinPrintNum - noPinPrintNum;
elementVO.setNoPinPrintNum(noPinPrintNum); elementVO.setNoPinPrintNum(noPinPrintNum);
//系统比列
// BigDecimal sysRatio = systemScale;
int pinSketchNum = 0; int pinSketchNum = 0;
int sysSketchNum = 0; int sysSketchNum = 0;
int noPinSketchNum = 0; int noPinSketchNum = 0;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
//sketch计算
CurrentDesignPictureTypeEnum designPictureType = calculateCurrentDesignPictureTypeNew(elementVO, pinSketchNum, sysSketchNum, noPinSketchNum, systemScale); CurrentDesignPictureTypeEnum designPictureType = calculateCurrentDesignPictureTypeNew(elementVO, pinSketchNum, sysSketchNum, noPinSketchNum, systemScale);
if (Objects.isNull(designPictureType)) { if (designPictureType == null) break;
break;
}
//print计算
CurrentDesignPrintPictureTypeEnum designPrintPictureType = calculateCurrentDesignPintPictureType(pinPrintNum, noPinPrintNum, noPrintNum); CurrentDesignPrintPictureTypeEnum designPrintPictureType = calculateCurrentDesignPintPictureType(pinPrintNum, noPinPrintNum, noPrintNum);
if (Objects.isNull(designPrintPictureType)) { if (designPrintPictureType == null) break;
break;
updateSketchNumbers(designPictureType, pinSketchNum, sysSketchNum, noPinSketchNum);
updatePrintNumbers(designPrintPictureType, pinPrintNum, noPinPrintNum, noPrintNum);
DesignPythonItemPrint designPythonItemPrint = getRandomPrint(elementVO, designPrintPictureType);
elementVO.setDesignPythonItemPrint(designPythonItemPrint);
elementVO.setDesignPrintPictureTypeLayoutList(calculateCurrentDesignPintPictureTypeLayout(elementVO.getModelSex()));
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) { switch (designPictureType) {
case PIN: case PIN:
pinSketchNum++; pinSketchNum++;
@@ -253,8 +261,10 @@ public class PythonService {
case SYS_FILE: case SYS_FILE:
sysSketchNum--; sysSketchNum--;
break; break;
default:
} }
}
private void updatePrintNumbers(CurrentDesignPrintPictureTypeEnum designPrintPictureType, long pinPrintNum, long noPinPrintNum, long noPrintNum) {
switch (designPrintPictureType) { switch (designPrintPictureType) {
case PIN: case PIN:
pinPrintNum--; pinPrintNum--;
@@ -265,23 +275,17 @@ public class PythonService {
case NO: case NO:
noPrintNum--; noPrintNum--;
break; break;
default:
} }
//确定本次designSingle是否print }
DesignPythonItemPrint designPythonItemPrint = getRandomPrint(elementVO, designPrintPictureType);
elementVO.setDesignPythonItemPrint(designPythonItemPrint); private DesignPythonObject createDesignPythonObject(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, BigDecimal systemScale, String singleOverall, String switchCategory) {
//参数透传 确定本次designSingle如果需要print对应的种类
elementVO.setDesignPrintPictureTypeLayoutList(calculateCurrentDesignPintPictureTypeLayout(elementVO.getModelSex()));
//designSingle具体参数组装
DesignPythonObject pythonObject = new DesignPythonObject(); DesignPythonObject pythonObject = new DesignPythonObject();
pythonObject.setItems(coverToDesignPythonItemNew(elementVO, designPictureType, systemScale)); pythonObject.setItems(coverToDesignPythonItemNew(elementVO, designPictureType, systemScale));
pythonObject.setBasic(coverToBasic(pythonObject.getItems().get(0), pythonObject.setBasic(coverToBasic(pythonObject.getItems().get(0), singleOverall, switchCategory, elementVO.getDesignLibraryModelPoint()));
singleOverall, switchCategory, elementVO.getDesignLibraryModelPoint())); return pythonObject;
objects.add(pythonObject);
}
return designPythonObjects;
} }
private CurrentDesignPictureTypeEnum calculateCurrentDesignPictureTypeNew(ValidateElementVO elementVO, int pinSketchNum, int sysSketchNum, int noPinSketchNum, BigDecimal systemScale) { private CurrentDesignPictureTypeEnum calculateCurrentDesignPictureTypeNew(ValidateElementVO elementVO, int pinSketchNum, int sysSketchNum, int noPinSketchNum, BigDecimal systemScale) {
List<CollectionElement> pinData = getPinData(elementVO); List<CollectionElement> pinData = getPinData(elementVO);
if (CollectionUtil.isNotEmpty(pinData)) { if (CollectionUtil.isNotEmpty(pinData)) {
@@ -517,14 +521,12 @@ public class PythonService {
private List<DesignPythonItem> coverToDesignPythonItemNew(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, BigDecimal systemScale) { private List<DesignPythonItem> coverToDesignPythonItemNew(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, BigDecimal systemScale) {
List<DesignPythonItem> itemList = new ArrayList<>(); List<DesignPythonItem> itemList = new ArrayList<>();
// 根据当前designPictureType确定单一部位的sketch
DesignPythonItem designPythonItem = calculatePythonItem(elementVO, designPictureType); DesignPythonItem designPythonItem = calculatePythonItem(elementVO, designPictureType);
if (Objects.nonNull(designPythonItem)) { if (Objects.nonNull(designPythonItem)) {
itemList.add(designPythonItem); itemList.add(designPythonItem);
if (elementVO.getSingleOverall().equals(SingleOverallEnum.OVERALL.getRealName())) { if (elementVO.getSingleOverall().equals(SingleOverallEnum.OVERALL.getRealName())) {
// 根据确定的单一部位sketch确定一整套穿搭
List<String> otherSketchCategoryList = getOtherSketchCategoryList(elementVO.getModelSex(), designPythonItem); List<String> otherSketchCategoryList = getOtherSketchCategoryList(elementVO.getModelSex(), designPythonItem);
if (!CollectionUtils.isEmpty(otherSketchCategoryList)) { if (!otherSketchCategoryList.isEmpty()) {
JSONObject attributeRecognition = getAttributeRecognition(designPythonItem, designPythonItem.getType(), elementVO.getModelSex()); JSONObject attributeRecognition = getAttributeRecognition(designPythonItem, designPythonItem.getType(), elementVO.getModelSex());
for (String styleCategory : otherSketchCategoryList) { for (String styleCategory : otherSketchCategoryList) {
DesignPythonItem otherSketch = processAttributeRecognition(attributeRecognition, elementVO, designPictureType, styleCategory, systemScale); DesignPythonItem otherSketch = processAttributeRecognition(attributeRecognition, elementVO, designPictureType, styleCategory, systemScale);
@@ -539,32 +541,50 @@ public class PythonService {
private DesignPythonItem processAttributeRecognition(JSONObject attributeRecognition, ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, String styleCategory, BigDecimal systemScale) { private DesignPythonItem processAttributeRecognition(JSONObject attributeRecognition, ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, String styleCategory, BigDecimal systemScale) {
switch (designPictureType) { switch (designPictureType) {
case PIN: { case PIN:
// 优先去pin里面找符合类别的 return processPinAttributeRecognition(attributeRecognition, elementVO, styleCategory, systemScale);
List<CollectionElement> collectPin = elementVO.getSketchBoardElements().stream().filter(o -> o.getHasPin() == 1 && o.getLevel2Type().equals(styleCategory)).collect(Collectors.toList()); case NO_PIN:
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)) { if (CollectionUtil.isNotEmpty(collectPin)) {
int randomNum = RandomsUtil.randomSysFile(collectPin.size()); int randomNum = RandomsUtil.randomSysFile(collectPin.size());
elementVO.getHasUseMd5List().add(collectPin.get(randomNum).getMd5()); elementVO.getHasUseMd5List().add(collectPin.get(randomNum).getMd5());
return coverSketchToDesignPythonItem(collectPin.get(randomNum).getId(), collectPin.get(randomNum), elementVO); return coverSketchToDesignPythonItem(collectPin.get(randomNum).getId(), collectPin.get(randomNum), elementVO);
} else { } else {
// 找不到就根据特征找一个系统池子与noPinSketch组成一个池子如果没有noPinSketch就只由系统池子作为池子。 List<CollectionElement> collectNoPin = getFilteredCollectionElements(elementVO.getSketchBoardElements(), 0, styleCategory);
List<CollectionElement> collectNoPin = elementVO.getSketchBoardElements().stream().filter(o -> o.getHasPin() == 0 && o.getLevel2Type().equals(styleCategory)).collect(Collectors.toList()); 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; int poolNum = 20;
if (CollectionUtil.isNotEmpty(collectNoPin)) { if (CollectionUtil.isNotEmpty(collectionElements)) {
int collectionNoPinSize = collectNoPin.size(); int collectionNoPinSize = collectionElements.size();
if (systemScale.compareTo(BigDecimal.ZERO) == 0) { if (systemScale.compareTo(BigDecimal.ZERO) == 0) {
int randomNum = RandomsUtil.randomSysFile(collectNoPin.size()); int randomNum = RandomsUtil.randomSysFile(collectionNoPinSize);
return coverSketchToDesignPythonItem(null, collectNoPin.get(randomNum), elementVO); return coverSketchToDesignPythonItem(null, collectionElements.get(randomNum), elementVO);
} else if (systemScale.compareTo(BigDecimal.ONE) != 0) { } else if (systemScale.compareTo(BigDecimal.ONE) != 0) {
BigDecimal collectNoPinSize = BigDecimal.valueOf(collectNoPin.size()); BigDecimal collectNoPinSize = BigDecimal.valueOf(collectionNoPinSize);
poolNum = collectNoPinSize.divide(systemScale, 0, RoundingMode.DOWN).intValue(); poolNum = collectNoPinSize.divide(systemScale, 0, RoundingMode.DOWN).intValue();
List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum); List<CollectionElement> list = getSystemSketchPool(attributeRecognition, styleCategory, elementVO.getModelSex(), poolNum);
collectNoPin.addAll(list); collectionElements.addAll(list);
int randomNum = RandomsUtil.randomSysFile(collectNoPin.size()); int randomNum = RandomsUtil.randomSysFile(collectionElements.size());
if (randomNum < collectionNoPinSize) { if (randomNum < collectionNoPinSize) {
return coverSketchToDesignPythonItem(collectNoPin.get(randomNum).getId(), collectNoPin.get(randomNum), elementVO); return coverSketchToDesignPythonItem(collectionElements.get(randomNum).getId(), collectionElements.get(randomNum), elementVO);
} else { } else {
return coverSketchToDesignPythonItem(null, collectNoPin.get(randomNum), elementVO); return coverSketchToDesignPythonItem(null, collectionElements.get(randomNum), elementVO);
} }
} }
} }
@@ -572,41 +592,9 @@ public class PythonService {
int randomNum = RandomsUtil.randomSysFile(list.size()); int randomNum = RandomsUtil.randomSysFile(list.size());
return coverSketchToDesignPythonItem(null, list.get(randomNum), elementVO); return coverSketchToDesignPythonItem(null, list.get(randomNum), elementVO);
} }
}
case NO_PIN: private List<CollectionElement> getFilteredCollectionElements(List<CollectionElement> elements, int hasPin, String styleCategory) {
case SYS_FILE: { return CollectionUtil.isNotEmpty(elements) ? elements.stream().filter(o -> o.getHasPin() == hasPin && o.getLevel2Type().equals(styleCategory)).collect(Collectors.toList()) : null;
List<CollectionElement> 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<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);
}
default:
throw new BusinessException("unknown designPictureType");
}
} }
private DesignPythonItem processAttributeRecognitionBySameCategory(JSONObject attributeRecognition, ValidateElementVO elementVO, String styleCategory) { private DesignPythonItem processAttributeRecognitionBySameCategory(JSONObject attributeRecognition, ValidateElementVO elementVO, String styleCategory) {
@@ -750,16 +738,13 @@ public class PythonService {
} }
public JSONObject getAttributeRecognition(DesignPythonItem designPythonItem, String styleCategory, String modelSex) { public JSONObject getAttributeRecognition(DesignPythonItem designPythonItem, String styleCategory, String modelSex) {
// todo 限流校验
// AccessLimitUtils.validate("design",5);
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒) .readTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒) .writeTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.build(); .build();
MediaType mediaType = MediaType.parse("application/json"); MediaType mediaType = MediaType.parse("application/json");
//关闭FastJson的引用检测 防止出现$ref 现象
JSONObject paramJSONObject = new JSONObject(); JSONObject paramJSONObject = new JSONObject();
paramJSONObject.put("category", styleCategory); paramJSONObject.put("category", styleCategory);
paramJSONObject.put("colony", modelSex); paramJSONObject.put("colony", modelSex);
@@ -767,43 +752,30 @@ public class PythonService {
JSONArray paramArray = new JSONArray(); JSONArray paramArray = new JSONArray();
paramArray.add(paramJSONObject); paramArray.add(paramJSONObject);
String param = JSON.toJSONString(paramArray, SerializerFeature.DisableCircularReferenceDetect); String param = JSON.toJSONString(paramArray, SerializerFeature.DisableCircularReferenceDetect);
log.info("design请求python 参数:####{}", param);
log.info("PythonService##design 请求参数:####{}", param);
RequestBody body = RequestBody.create(mediaType, param); RequestBody body = RequestBody.create(mediaType, param);
Request request = new Request.Builder() Request request = new Request.Builder()
.url(accessPythonIp + ":" + accessPythonPort + "/api/attribute_recognition") .url(accessPythonIp + ":" + accessPythonPort + "/api/attribute_recognition")
.method("POST", body) .method("POST", body)
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json") .addHeader("Content-Type", "application/json")
.build(); .build();
Response response;
String responseBody; try (Response response = client.newCall(request).execute()) {
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()) { if (response.isSuccessful()) {
try { String responseBody = Objects.requireNonNull(response.body()).string();
if (Objects.nonNull(response.body())) {
responseBody = response.body().string();
JSONObject responseObject = JSON.parseObject(responseBody); JSONObject responseObject = JSON.parseObject(responseBody);
log.info("PythonService##responseObject###{}", responseObject); log.info("PythonService##responseObject###{}", responseObject);
return responseObject; return responseObject;
} else {
log.error("PythonService##design 请求异常:{}", response);
throw new BusinessException("attributeRecognition.interface.exception");
} }
throw new BusinessException("design.interface.exception"); } catch (IOException e) {
} catch (IOException | JSONException e) { log.error("PythonService##design 请求异常:{}", e.getMessage());
log.error("PythonService##design异常###{}", e.getMessage()); throw new BusinessException("attributeRecognition.interface.exception");
throw new BusinessException("design.interface.exception");
} }
} }
log.error("PythonService##design异常response###{}", response);
//生成失败
throw new BusinessException("design.interface.exception");
}
public JSONObject getAttributeRecognitionBySameCategory(CollectionElement element, String modelSex) { public JSONObject getAttributeRecognitionBySameCategory(CollectionElement element, String modelSex) {
// todo 限流校验 // todo 限流校验
@@ -876,98 +848,100 @@ public class PythonService {
return null; return null;
} }
private DesignPythonItem calculatePythonItem(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType) { private DesignPythonItem calculatePythonItem(ValidateElementVO validateElementVO, CurrentDesignPictureTypeEnum currentDesignPictureType) {
switch (designPictureType) { switch (currentDesignPictureType) {
case PIN: { case PIN:
List<CollectionElement> pinData = getPinData(elementVO); return calculatePinPythonItem(validateElementVO);
if (CollectionUtil.isEmpty(pinData)) { case NO_PIN:
throw new BusinessException("pinData is null"); return calculateNoPinPythonItem(validateElementVO);
} case SYS_FILE:
Random random = new Random(); return calculateSysFilePythonItem(validateElementVO);
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 = 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<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 (!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<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);
}
default: default:
return null; 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) { private String getTableName(String modelSex, String category) {
switch (modelSex) { switch (modelSex) {
case "Female": { case "Female": {

View File

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