Merge branch 'dev/dev' into dev/dev_shb
# Conflicts: # src/main/java/com/ai/da/controller/AccountController.java # src/main/java/com/ai/da/mapper/primary/entity/GenerateCancel.java # src/main/java/com/ai/da/mapper/primary/entity/LibraryCopy.java # src/main/java/com/ai/da/mapper/primary/entity/LibraryModelPointCopy.java # src/main/java/com/ai/da/service/AccountService.java # src/main/java/com/ai/da/service/LibraryService.java # src/main/java/com/ai/da/service/impl/AccountServiceImpl.java # src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java # src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java # src/main/resources/application-prod.properties # src/main/resources/application-test.properties
This commit is contained in:
@@ -56,6 +56,7 @@ public class PythonService {
|
||||
private String accessPythonIp;
|
||||
@Value("${access.python.port:''}")
|
||||
private String accessPythonPort;
|
||||
|
||||
@Resource
|
||||
private PythonTAllInfoService pythonTAllInfoService;
|
||||
|
||||
@@ -106,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) {
|
||||
@@ -410,7 +411,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;
|
||||
@@ -443,11 +444,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);
|
||||
}
|
||||
}
|
||||
@@ -1621,7 +1622,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)) {
|
||||
@@ -2102,7 +2103,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");
|
||||
@@ -2216,7 +2217,9 @@ public class PythonService {
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
|
||||
/** 暂时未用 */
|
||||
/**
|
||||
* 暂时未用
|
||||
*/
|
||||
public String generateSketchCaption(String url) {
|
||||
//限流校验
|
||||
AccessLimitUtils.validate("generateSketchCaption", 5);
|
||||
@@ -2259,9 +2262,9 @@ public class PythonService {
|
||||
throw new BusinessException("system error!");
|
||||
}
|
||||
|
||||
public List<String> generateSketchOrPrint(Long userId, String url, String category, String text, int mode, String modelName, String gender) {
|
||||
public List<String> generateSketchOrPrint(GenerateToPythonDTO generateToPythonDTO) {
|
||||
//限流校验
|
||||
AccessLimitUtils.validate("generateSketchOrPrint", 5);
|
||||
// AccessLimitUtils.validate("generateSketchOrPrint", 5);
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
@@ -2269,46 +2272,45 @@ public class PythonService {
|
||||
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||
.build();
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
Map<String, Object> content = Maps.newHashMap();
|
||||
content.put("user_id", userId);
|
||||
content.put("image_url", url);
|
||||
content.put("category", category);
|
||||
content.put("mode", mode);
|
||||
content.put("str", text);
|
||||
content.put("version", "1");
|
||||
content.put("gender", gender);
|
||||
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content, SerializerFeature.WriteMapNullValue));
|
||||
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue));
|
||||
Request request = new Request.Builder()
|
||||
// .url(accessPythonIp + ":2828/aida/diffusion")
|
||||
// .url("http://18.167.251.121:9992")
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/diffusion")
|
||||
// .url("http://127.0.0.1:5000/api/diffusion")
|
||||
// .url(accessPythonIp + ":" + accessPythonPort + "/api/diffusion")
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/generate_image")
|
||||
.method("POST", body)
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response = null;
|
||||
String bodyString ;
|
||||
String bodyString;
|
||||
try {
|
||||
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content, SerializerFeature.WriteMapNullValue));
|
||||
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue));
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
// throw new BusinessException("generate.interface.error");
|
||||
throw new BusinessException(ioException.getMessage());
|
||||
}
|
||||
//去除限流
|
||||
AccessLimitUtils.validateOut("generateSketchOrPrint");
|
||||
// AccessLimitUtils.validateOut("generateSketchOrPrint");
|
||||
|
||||
// 判断是否生成失败
|
||||
if (Objects.isNull(response) || Objects.isNull(response.body())) {
|
||||
if (Objects.isNull(response.body())) {
|
||||
log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!");
|
||||
throw new BusinessException("generate.interface.error");
|
||||
} else if (response.code() != HttpURLConnection.HTTP_OK){
|
||||
// throw new BusinessException("generate.interface.error");
|
||||
throw new BusinessException("PythonService##generateSketchOrPrint异常###: response or body is empty!");
|
||||
} 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("generate.interface.error");
|
||||
throw new BusinessException("PythonService##generateSketchOrPrint异常### Response error!Response code ## " + response.code() + " ##");
|
||||
} else {
|
||||
try {
|
||||
bodyString = response.body().string();
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException("generate.interface.error");
|
||||
log.error(e.getMessage());
|
||||
// throw new BusinessException("generate.interface.error");
|
||||
throw new BusinessException(e.getMessage());
|
||||
}
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(bodyString);
|
||||
@@ -2378,7 +2380,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 {
|
||||
@@ -2403,10 +2405,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);
|
||||
|
||||
@@ -2419,7 +2421,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 {
|
||||
@@ -2430,7 +2432,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");
|
||||
@@ -2438,7 +2440,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");
|
||||
}
|
||||
@@ -2446,4 +2448,35 @@ public class PythonService {
|
||||
//生成失败
|
||||
throw new BusinessException("cloth-classification.interface.exception");
|
||||
}
|
||||
|
||||
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;
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
// .addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response;
|
||||
try {
|
||||
log.info("cancelGenerateTask请求入参content###{}", taskId);
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService##cancelGenerateTask异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (response.code() != HttpURLConnection.HTTP_OK) {
|
||||
log.info("generate-python 取消请求失败");
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
log.info("generate-python 取消请求成功");
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user