TASK:AiDA
This commit is contained in:
@@ -230,13 +230,14 @@ public class PythonService {
|
||||
designPythonObjects.setProcess_id(processId);
|
||||
|
||||
long pinPrintNum = calculateDesignPinPrintNum(elementVO.getPrintBoardElements());
|
||||
long noPinPrintNum = calculateDesignNoPinPrintNum(elementVO.getPrintBoardElements());
|
||||
long noPrintNum = 8 - pinPrintNum - noPinPrintNum;
|
||||
long noPinPrintNum = calculateDesignNoPinPrintNum(elementVO.getPrintBoardElements(), elementVO.getDesignNum());
|
||||
long noPrintNum = elementVO.getDesignNum() - pinPrintNum - noPinPrintNum;
|
||||
elementVO.setNoPinPrintNum(noPinPrintNum);
|
||||
|
||||
int[] sketchNumbers = new int[3];
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
int designNum = elementVO.getDesignNum();
|
||||
for (int i = 0; i < designNum; i++) {
|
||||
CurrentDesignPictureTypeEnum designPictureType = calculateCurrentDesignPictureTypeNew(elementVO, sketchNumbers, systemScale);
|
||||
if (designPictureType == null) break;
|
||||
|
||||
@@ -261,7 +262,7 @@ public class PythonService {
|
||||
elementVO.setDesignPythonItemPrint(designPythonItemPrint);
|
||||
elementVO.setDesignPrintPictureTypeLayoutList(calculateCurrentDesignPintPictureTypeLayout(elementVO.getModelSex()));
|
||||
|
||||
DesignPythonObject pythonObject = createDesignPythonObject(elementVO, designPictureType, systemScale, singleOverall, switchCategory);
|
||||
DesignPythonObject pythonObject = createDesignPythonObject(elementVO, designPictureType, systemScale, singleOverall, switchCategory, i);
|
||||
objects.add(pythonObject);
|
||||
redisUtil.addProcessId(processId, i + 1);
|
||||
}
|
||||
@@ -296,22 +297,24 @@ public class PythonService {
|
||||
}
|
||||
}
|
||||
|
||||
private DesignPythonObject createDesignPythonObject(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, BigDecimal systemScale, String singleOverall, String switchCategory) {
|
||||
private DesignPythonObject createDesignPythonObject(ValidateElementVO elementVO, CurrentDesignPictureTypeEnum designPictureType, BigDecimal systemScale, String singleOverall, String switchCategory, int i) {
|
||||
DesignPythonObject pythonObject = new DesignPythonObject();
|
||||
pythonObject.setItems(coverToDesignPythonItemNew(elementVO, designPictureType, systemScale));
|
||||
pythonObject.setBasic(coverToBasic(pythonObject.getItems().get(0), singleOverall, switchCategory, elementVO.getDesignLibraryModelPoint()));
|
||||
pythonObject.setObjectSign(elementVO.getRequestIdList().get(i));
|
||||
return pythonObject;
|
||||
}
|
||||
|
||||
|
||||
private CurrentDesignPictureTypeEnum calculateCurrentDesignPictureTypeNew(ValidateElementVO elementVO, int[] sketchNumbers, BigDecimal systemScale) {
|
||||
List<CollectionElement> pinData = getPinData(elementVO);
|
||||
Integer designNum = elementVO.getDesignNum();
|
||||
if (CollectionUtil.isNotEmpty(pinData)) {
|
||||
return CurrentDesignPictureTypeEnum.PIN;
|
||||
} else {
|
||||
if (sketchNumbers[1] == 0 && sketchNumbers[2] == 0) {
|
||||
sketchNumbers[1] = systemScale.multiply(BigDecimal.valueOf(8 - sketchNumbers[0])).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
|
||||
sketchNumbers[2] = 8 - sketchNumbers[0] - sketchNumbers[1];
|
||||
sketchNumbers[1] = systemScale.multiply(BigDecimal.valueOf(designNum - sketchNumbers[0])).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
|
||||
sketchNumbers[2] = designNum - sketchNumbers[0] - sketchNumbers[1];
|
||||
}
|
||||
if (sketchNumbers[2] > 0 && sketchNumbers[1] > 0) {
|
||||
Long l = RandomsUtil.randomSysFile(0l, 2l);
|
||||
@@ -491,7 +494,7 @@ public class PythonService {
|
||||
}
|
||||
|
||||
//计算print 非Pin图片剩余张数
|
||||
private long calculateDesignNoPinPrintNum(List<CollectionElement> printBoardElements) {
|
||||
private long calculateDesignNoPinPrintNum(List<CollectionElement> printBoardElements, Integer designNum) {
|
||||
if (CollectionUtils.isEmpty(printBoardElements)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -500,10 +503,10 @@ public class PythonService {
|
||||
return 0;
|
||||
} else {
|
||||
long pinNum = printBoardElements.stream().filter(f -> f.getHasPin() == 1).count();
|
||||
if (8 - pinNum < 4) {
|
||||
return RandomsUtil.randomSysFile(0L, 8 - pinNum + 1);
|
||||
if (designNum - pinNum < designNum/2) {
|
||||
return RandomsUtil.randomSysFile(0L, designNum - pinNum + 1);
|
||||
} else {
|
||||
return RandomsUtil.randomSysFile(0L, 4L + 1);
|
||||
return RandomsUtil.randomSysFile(0L, (long) (designNum/2 + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -553,7 +556,7 @@ public class PythonService {
|
||||
if (elementVO.getSingleOverall().equals(SingleOverallEnum.OVERALL.getRealName())) {
|
||||
List<String> otherSketchCategoryList = getOtherSketchCategoryList(elementVO.getModelSex(), designPythonItem);
|
||||
if (!otherSketchCategoryList.isEmpty()) {
|
||||
JSONObject attributeRecognition = getAttributeRecognition(designPythonItem, designPythonItem.getType(), elementVO.getModelSex());
|
||||
JSONObject attributeRecognition = getAttributeRecognition(designPythonItem.getPath(), designPythonItem.getType(), elementVO.getModelSex());
|
||||
for (String styleCategory : otherSketchCategoryList) {
|
||||
DesignPythonItem otherSketch = processAttributeRecognition(attributeRecognition, elementVO, designPictureType, styleCategory, systemScale);
|
||||
itemList.add(otherSketch);
|
||||
@@ -790,7 +793,7 @@ public class PythonService {
|
||||
return attributeRetrieval;
|
||||
}
|
||||
|
||||
public JSONObject getAttributeRecognition(DesignPythonItem designPythonItem, String styleCategory, String modelSex) {
|
||||
public JSONObject getAttributeRecognition(String sketchImgUrl, String styleCategory, String modelSex) {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
@@ -801,7 +804,7 @@ public class PythonService {
|
||||
JSONObject paramJSONObject = new JSONObject();
|
||||
paramJSONObject.put("category", styleCategory);
|
||||
paramJSONObject.put("colony", modelSex);
|
||||
paramJSONObject.put("sketch_img_url", designPythonItem.getPath());
|
||||
paramJSONObject.put("sketch_img_url", sketchImgUrl);
|
||||
JSONArray paramArray = new JSONArray();
|
||||
paramArray.add(paramJSONObject);
|
||||
String param = JSON.toJSONString(paramArray, SerializerFeature.DisableCircularReferenceDetect);
|
||||
@@ -3003,6 +3006,58 @@ public class PythonService {
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
|
||||
public JSONObject designStream(DesignPythonObjects designPythonObjects) {
|
||||
// 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)//写入超时(单位:秒)
|
||||
.build();
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
//关闭FastJson的引用检测 防止出现$ref 现象
|
||||
String param = JSON.toJSONString(designPythonObjects, SerializerFeature.DisableCircularReferenceDetect);
|
||||
log.info("design请求python 参数:####{}", param);
|
||||
RequestBody body = RequestBody.create(mediaType, param);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/design_v2")
|
||||
// .url(fastApiPythonAddress + "/api/design")
|
||||
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
|
||||
.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");
|
||||
}
|
||||
}
|
||||
log.error("PythonService##design异常response###{}", response);
|
||||
//生成失败
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂时未用
|
||||
*/
|
||||
@@ -3566,4 +3621,54 @@ public class PythonService {
|
||||
//生成失败
|
||||
throw new BusinessException("bright.interface.exception");
|
||||
}
|
||||
|
||||
public JSONObject attributeRecognition(List<String> pictureUrls,List<String> ids, List<String> category) {
|
||||
//限流校验
|
||||
AccessLimitUtils.validate("attributeRecognition", 20);
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
.readTimeout(300, TimeUnit.SECONDS)//读取超时(单位:秒)
|
||||
.writeTimeout(300, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||
.build();
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
Map<String, List<String>> content = Maps.newHashMap();
|
||||
//识别图片路径数组
|
||||
content.put("upload_img_path", pictureUrls);
|
||||
//识别图片id数组
|
||||
content.put("upload_img_id", ids);
|
||||
content.put("upload_img_category", category);
|
||||
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":9993/api/attribute")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response = null;
|
||||
String bodyStr = null;
|
||||
try {
|
||||
log.info("识别python对应的属性标签值请求入参content###{}", JSON.toJSONString(content));
|
||||
response = client.newCall(request).execute();
|
||||
bodyStr = response.body().string();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService###attributeRecognition异常##{}", ExceptionUtil.getThrowableList(ioException));
|
||||
}
|
||||
log.info("识别python对应的属性标签值结果###{}",bodyStr.trim());
|
||||
//去除限流
|
||||
AccessLimitUtils.validateOut("attributeRecognition");
|
||||
if (Objects.isNull(response)) {
|
||||
log.error("PythonService##attributeRecognition异常###{}", "response or body is empty!");
|
||||
throw new BusinessException("attribute recognition exception!");
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
|
||||
Boolean result = jsonObject.getBoolean("successful");
|
||||
if (result) {
|
||||
JSONObject attributeJSONObject = JSON.parseObject(bodyStr.trim());
|
||||
return attributeJSONObject;
|
||||
}
|
||||
log.info("识别python对应的属性标签值异常###{}", jsonObject);
|
||||
//生成失败
|
||||
throw new BusinessException("Atribute recognition exception!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,6 @@ public class DesignPythonObject {
|
||||
* basic 选项
|
||||
*/
|
||||
DesignPythonBasic basic;
|
||||
|
||||
private String objectSign;
|
||||
}
|
||||
|
||||
@@ -16,4 +16,6 @@ public class DesignPythonObjects {
|
||||
* design新增的library
|
||||
*/
|
||||
List<Library> addLibrary;
|
||||
|
||||
private String requestId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user