BUGFIX:代码优化;

This commit is contained in:
shahaibo
2024-02-21 15:16:51 +08:00
parent 43ec55dfb6
commit 22330b674a
2 changed files with 238 additions and 257 deletions

View File

@@ -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;