TASK:generate 修复逻辑Bug

This commit is contained in:
2024-01-25 13:37:17 +08:00
parent 65bed9dada
commit c35a188abb
7 changed files with 75 additions and 44 deletions

View File

@@ -107,7 +107,7 @@ public class PythonService {
if (Objects.nonNull(response.body())) {
responseBody = response.body().string();
JSONObject responseObj = JSON.parseObject(responseBody);
log.info("moodboard与printboard图片合成 python返回###{}",responseObj);
log.info("moodboard与printboard图片合成 python返回###{}", responseObj);
return responseObj.get("data").toString();
}
} catch (IOException | JSONException e) {
@@ -389,7 +389,7 @@ public class PythonService {
all.addAll(new ArrayList<>(DesignPythonItem.SKIRT_TROUSERS));
return all;
}
}else if (modelSex.equals(Sex.MALE.getValue())) {
} else if (modelSex.equals(Sex.MALE.getValue())) {
Long randomIndex = RandomsUtil.randomSysFile(0L, 3L);
if (randomIndex == 0) {
return DesignPythonItem.TOPS;
@@ -422,11 +422,11 @@ public class PythonService {
long noPinNum = printBoardElements.stream().filter(f -> f.getHasPin() == 0).count();
if (noPinNum == 0L) {
return 0;
}else {
} else {
long pinNum = printBoardElements.stream().filter(f -> f.getHasPin() == 1).count();
if (8 - pinNum < 4) {
return RandomsUtil.randomSysFile(0L, 8 - pinNum + 1);
}else {
} else {
return RandomsUtil.randomSysFile(0L, 4L + 1);
}
}
@@ -1600,7 +1600,7 @@ public class PythonService {
printBoardElements = elementVO.getPrintBoardElements()
.stream()
.filter(f -> !elementVO.getHasUseMd5List().contains(f.getMd5())).collect(Collectors.toList());
}else {
} else {
printBoardElements = elementVO.getPrintBoardElements();
}
if (CollectionUtil.isEmpty(printBoardElements)) {
@@ -2081,7 +2081,7 @@ public class PythonService {
skirt.setPrint(designPythonItemPrint);
skirt.setPath("aida-sys-image/images/female/trousers/trousers_974.jpg");
response.add(skirt);
}else {
} else {
DesignPythonItem top = new DesignPythonItem();
top.setType(MalePosition.TOPS.getValue());
top.setColor("none");
@@ -2195,7 +2195,9 @@ public class PythonService {
throw new BusinessException("design.interface.exception");
}
/** 暂时未用 */
/**
* 暂时未用
*/
public String generateSketchCaption(String url) {
//限流校验
AccessLimitUtils.validate("generateSketchCaption", 5);
@@ -2259,7 +2261,7 @@ public class PythonService {
.addHeader("Content-Type", "application/json")
.build();
Response response = null;
String bodyString ;
String bodyString;
try {
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue));
response = client.newCall(request).execute();
@@ -2276,7 +2278,7 @@ public class PythonService {
log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!");
// throw new BusinessException("generate.interface.error");
throw new BusinessException("PythonService##generateSketchOrPrint异常###: response or body is empty!");
} else if (response.code() != HttpURLConnection.HTTP_OK){
} else if (response.code() != HttpURLConnection.HTTP_OK) {
log.error("PythonService##generateSketchOrPrint异常###{}", "Response error!Response code ## " + response.code() + " ##");
// throw new BusinessException("generate.interface.error");
throw new BusinessException("PythonService##generateSketchOrPrint异常### Response error!Response code ## " + response.code() + " ##");
@@ -2356,7 +2358,7 @@ public class PythonService {
if (Objects.isNull(response) || Objects.isNull(response.body())) {
log.error("PythonService##composeLayers异常###{}", "response or body is empty!");
throw new BusinessException("compose-layer.interface.exception");
}else if (response.code() != HttpURLConnection.HTTP_OK){
} else if (response.code() != HttpURLConnection.HTTP_OK) {
log.error("PythonService##composeLayers异常###{}", "Response error!Response code ## " + response.code() + " ##");
throw new BusinessException("compose-layer.interface.exception");
} else {
@@ -2381,10 +2383,10 @@ public class PythonService {
return item0.getString("synthesis_url");
}
public String getClothCategory(String path,String gender){
public String getClothCategory(String path, String gender) {
HashMap<String, String> content = new HashMap<>();
content.put("sketch_img_url",path);
content.put("colony",gender);
content.put("sketch_img_url", path);
content.put("colony", gender);
List<HashMap<String, String>> contents = Collections.singletonList(content);
String jsonString = JSON.toJSONString(contents, SerializerFeature.WriteNullStringAsEmpty);
@@ -2397,7 +2399,7 @@ public class PythonService {
if (Objects.isNull(response) || Objects.isNull(response.body())) {
log.error("PythonService##GetClothCategory###{}", "response or body is empty!");
throw new BusinessException("cloth-classification.interface.exception");
} else if (response.code() != HttpURLConnection.HTTP_OK){
} else if (response.code() != HttpURLConnection.HTTP_OK) {
log.error("PythonService##GetClothCategory###{}", "Response error!Response code ## " + response.code() + " ##");
throw new BusinessException("cloth-classification.interface.exception");
} else {
@@ -2408,7 +2410,7 @@ public class PythonService {
}
}
JSONObject jsonObject = JSON.parseObject(bodyString);
try{
try {
Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful");
if (result && jsonObject.get("msg").equals("OK!")) {
JSONObject data = jsonObject.getJSONObject("data");
@@ -2416,7 +2418,7 @@ public class PythonService {
JSONObject map = (JSONObject) list.get(0);
return map.get("category").toString();
}
}catch (NullPointerException e){
} catch (NullPointerException e) {
log.info("getClothCategory 失败###{}未返回category", jsonObject);
throw new BusinessException("cloth-classification.interface.exception");
}
@@ -2425,14 +2427,14 @@ public class PythonService {
throw new BusinessException("cloth-classification.interface.exception");
}
public Boolean cancelGenerateTask(String taskId){
public Boolean cancelGenerateTask(String taskId) {
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
.build();
String url = accessPythonIp + ":" + accessPythonPort + "/api/generate_cancel/" + taskId + "/";
String url = accessPythonIp + ":" + accessPythonPort + "/api/generate_cancel/" + taskId;
Request request = new Request.Builder()
.url(url)
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
@@ -2444,12 +2446,14 @@ public class PythonService {
response = client.newCall(request).execute();
} catch (IOException ioException) {
log.error("PythonService##cancelGenerateTask异常###{}", ExceptionUtil.getThrowableList(ioException));
throw new BusinessException("generate.interface.error");
return null;
}
if (response.code() != HttpURLConnection.HTTP_OK){
if (response.code() != HttpURLConnection.HTTP_OK) {
log.info("generate-python 取消请求失败");
return Boolean.FALSE;
}
log.info("generate-python 取消请求成功");
return Boolean.TRUE;
}