TASK:AiDA
This commit is contained in:
@@ -41,6 +41,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@@ -237,6 +238,9 @@ public class PythonService {
|
||||
int[] sketchNumbers = new int[3];
|
||||
|
||||
int designNum = elementVO.getDesignNum();
|
||||
Set<DesignPythonObject> assembledObjects = new HashSet<>(); // 用于存储已组装的 DesignPythonObject
|
||||
DesignPythonObject lastAssembledObject = null; // 上一次组装的对象
|
||||
|
||||
for (int i = 0; i < designNum; i++) {
|
||||
CurrentDesignPictureTypeEnum designPictureType = calculateCurrentDesignPictureTypeNew(elementVO, sketchNumbers, systemScale);
|
||||
if (designPictureType == null) break;
|
||||
@@ -256,13 +260,28 @@ public class PythonService {
|
||||
noPrintNum--;
|
||||
break;
|
||||
}
|
||||
// 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, i);
|
||||
|
||||
// 如果当前对象与已组装的对象重复,则跳过当前组装
|
||||
if (assembledObjects.contains(pythonObject)) {
|
||||
if (lastAssembledObject != null && assembledObjects.contains(lastAssembledObject)) {
|
||||
// 如果当前组装与前一个组装的对象重复,且前一个组装也重复,结束组装
|
||||
System.out.println("当前组装的对象与前两个组装的对象重复,结束组装。");
|
||||
break;
|
||||
}
|
||||
// 否则,跳过当前组装
|
||||
continue;
|
||||
}
|
||||
|
||||
// 将当前对象添加到已组装的集合中,并记录
|
||||
assembledObjects.add(pythonObject);
|
||||
lastAssembledObject = pythonObject; // 更新上一次组装的对象
|
||||
|
||||
objects.add(pythonObject);
|
||||
redisUtil.addProcessId(processId, i + 1);
|
||||
}
|
||||
@@ -3672,29 +3691,44 @@ public class PythonService {
|
||||
throw new BusinessException("Atribute recognition exception!");
|
||||
}
|
||||
|
||||
public JSONObject designBatch(DesignPythonObjects designPythonObjects) {
|
||||
public String designBatch(DesignPythonObjects designPythonObjects, Long accountId, int designNum, String taskId) {
|
||||
// todo 限流校验
|
||||
// AccessLimitUtils.validate("design",5);
|
||||
// AccessLimitUtils.validate("design",5);
|
||||
|
||||
// 将 designPythonObjects 写入文件
|
||||
File file = new File("design_batch_test.txt");
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
String param = JSON.toJSONString(designPythonObjects, SerializerFeature.DisableCircularReferenceDetect);
|
||||
writer.write(param);
|
||||
log.info("设计请求参数已写入文件:####{}", file.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
log.error("写入文件异常:{}", e.getMessage());
|
||||
throw new BusinessException("file.write.exception");
|
||||
}
|
||||
|
||||
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(designPythonObjects, SerializerFeature.DisableCircularReferenceDetect);
|
||||
log.info("design请求python 参数:####{}", param);
|
||||
RequestBody body = RequestBody.create(mediaType, param);
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/design_batch_generate")
|
||||
// .url(fastApiPythonAddress + "/api/design")
|
||||
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
// 构建 multipart 表单
|
||||
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
|
||||
.addFormDataPart("file", "design_batch_test.txt",
|
||||
RequestBody.create(MediaType.parse("text/plain"), file))
|
||||
.addFormDataPart("tasks_id", taskId)
|
||||
.addFormDataPart("user_id", String.valueOf(accountId))
|
||||
.addFormDataPart("file_name", "design_batch_test" + taskId + ".json")
|
||||
.addFormDataPart("total", String.valueOf(designNum))
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url("http://18.167.251.121:9994/api/design_batch_generate")
|
||||
.method("POST", body)
|
||||
.addHeader("Content-Type", "multipart/form-data")
|
||||
.build();
|
||||
|
||||
Response response;
|
||||
String responseBody;
|
||||
try {
|
||||
@@ -3705,15 +3739,13 @@ public class PythonService {
|
||||
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;
|
||||
return taskId;
|
||||
}
|
||||
throw new BusinessException("design.interface.exception");
|
||||
} catch (IOException | JSONException e) {
|
||||
@@ -3722,7 +3754,7 @@ public class PythonService {
|
||||
}
|
||||
}
|
||||
log.error("PythonService##design异常response###{}", response);
|
||||
//生成失败
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user