BUGFIX:代码优化;
This commit is contained in:
@@ -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)) {
|
||||
@@ -517,14 +521,12 @@ public class PythonService {
|
||||
|
||||
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,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<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;
|
||||
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);
|
||||
}
|
||||
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());
|
||||
@@ -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<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 = 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::getApparel, 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::getApparel, 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": {
|
||||
|
||||
@@ -306,19 +306,34 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> 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<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());
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user