diff --git a/src/main/java/com/ai/da/common/enums/CollectionLevel2TypeEnum.java b/src/main/java/com/ai/da/common/enums/CollectionLevel2TypeEnum.java index 6bd35aad..cc344c9e 100644 --- a/src/main/java/com/ai/da/common/enums/CollectionLevel2TypeEnum.java +++ b/src/main/java/com/ai/da/common/enums/CollectionLevel2TypeEnum.java @@ -28,7 +28,13 @@ public enum CollectionLevel2TypeEnum { * 裤子 */ TROUSERS("Trousers"), + /** + * 男装上装 + */ TOPS("Tops"), + /** + * 男装下装 + */ BOTTOMS("Bottoms"), ; diff --git a/src/main/java/com/ai/da/controller/ElementController.java b/src/main/java/com/ai/da/controller/ElementController.java index b3a431be..a319abe4 100644 --- a/src/main/java/com/ai/da/controller/ElementController.java +++ b/src/main/java/com/ai/da/controller/ElementController.java @@ -49,13 +49,14 @@ public class ElementController { public Response upload(@RequestParam("file") MultipartFile file, @ApiParam("一级类型 Moodboard Printboard Sketchboard MarketingSketch Colorboard") @RequestParam(value = "level1Type") String level1Type, + @RequestParam(value = "gender") String gender, @ApiParam("本地时区,比如 'Asia/Tokyo' 东京时间 , 'Asia/Shanghai' 北京时间 由js本地获取") @RequestParam(value = "timeZone") String timeZone) { if (null == file || StringUtils.isEmpty(file.getOriginalFilename())) { throw new BusinessException("file.cannot.be.empty"); } return Response.success(collectionElementService.upload( - new CollectionElementUploadDTO(file, level1Type, timeZone, MD5Utils.encryptFile(file)))); + new CollectionElementUploadDTO(file, level1Type, gender, timeZone, MD5Utils.encryptFile(file)))); } @ApiOperation(value = "element文件删除") diff --git a/src/main/java/com/ai/da/model/dto/CollectionElementUploadDTO.java b/src/main/java/com/ai/da/model/dto/CollectionElementUploadDTO.java index a65ca671..3e0b6bb3 100644 --- a/src/main/java/com/ai/da/model/dto/CollectionElementUploadDTO.java +++ b/src/main/java/com/ai/da/model/dto/CollectionElementUploadDTO.java @@ -22,6 +22,9 @@ public class CollectionElementUploadDTO { @ApiModelProperty("一级类型") private String level1Type; + @ApiModelProperty("性别") + private String gender; + @ApiModelProperty("时区") private String timeZone; diff --git a/src/main/java/com/ai/da/model/vo/ChatRobotVO.java b/src/main/java/com/ai/da/model/vo/ChatRobotVO.java index d1fbedd4..9ef86aa7 100644 --- a/src/main/java/com/ai/da/model/vo/ChatRobotVO.java +++ b/src/main/java/com/ai/da/model/vo/ChatRobotVO.java @@ -10,4 +10,6 @@ public class ChatRobotVO extends ChatRobot { private List chatRobotLibraryList; + private Boolean isTutorial = Boolean.FALSE; + } diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index 569ad4a7..f8f390c5 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -37,6 +37,7 @@ import javax.annotation.Resource; import java.io.File; import java.io.IOException; import java.math.BigDecimal; +import java.net.HttpURLConnection; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -1965,23 +1966,6 @@ public class PythonService { return new DesignPythonItemPrint(new ArrayList<>(), false); } DesignPythonItemPrint print = CopyUtil.copyObject(printObject, DesignPythonItemPrint.class); -// if(StringUtils.isEmpty(printObject.getPath())){ -// print.setPrint_path_list(new ArrayList<>()); -// }else { -// print.setPrint_path_list(Collections.singletonList(printObject.getPath())); -// } -// if (StringUtils.isEmpty(clothesPath) -// || "none".equals(clothesPath) -// || CollectionUtils.isEmpty(printObject.getPrints())) { -// return print; -// } - //图片宽 高 -// FileVO fileVO = FileUtil.getFileSize(FileUtil.getOriginFile(clothesPath)); - /* List> locations = printObject.getLocation(); - locations.forEach(location -> { - location.set(0, location.get(0) * fileVO.getWidth()); - location.set(1, location.get(1) * fileVO.getHigh()); - });*/ List> location = new ArrayList<>(printObject.getPrints().size()); List scale = new ArrayList<>(printObject.getPrints().size()); @@ -2270,6 +2254,9 @@ public class PythonService { if (Objects.isNull(response) || 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){ + log.error("PythonService##generateSketchOrPrint异常###{}", "Response error!Response code ## " + response.code() + " ##"); + throw new BusinessException("generate.interface.error"); } else { try { bodyString = response.body().string(); @@ -2328,7 +2315,7 @@ public class PythonService { return imageUrlList; } - public String composeLayers(List layersDetail) throws IOException { + public String composeLayers(List layersDetail) { HashMap> layers = new HashMap<>(); HashMap>> content = new HashMap<>(); layers.put("layers", layersDetail); @@ -2343,9 +2330,16 @@ public class PythonService { // 生成失败 if (Objects.isNull(response) || Objects.isNull(response.body())) { log.error("PythonService##composeLayers异常###{}", "response or body is empty!"); - throw new BusinessException("generate exception!"); + throw new BusinessException("compose-layer.interface.exception"); + }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 { - bodyString = response.body().string(); + try { + bodyString = response.body().string(); + } catch (IOException e) { + throw new BusinessException("compose-layer.interface.exception"); + } } JSONObject jsonObject = JSON.parseObject(bodyString); Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful"); @@ -2354,11 +2348,50 @@ public class PythonService { } log.info("composeLayers 失败###{}", jsonObject); //生成失败 - throw new BusinessException("composeLayers Exception!"); + throw new BusinessException("compose-layer.interface.exception"); } private String getCompositeImage(JSONObject jsonObject) { JSONObject item0 = jsonObject.getJSONObject("0"); return item0.getString("synthesis_url"); } + + public String getClothCategory(String path,String gender){ + HashMap content = new HashMap<>(); + content.put("sketch_img_url",path); + content.put("colony",gender); + List> contents = Collections.singletonList(content); + String jsonString = JSON.toJSONString(contents, SerializerFeature.WriteNullStringAsEmpty); + + // todo 添加限流 + Response response = this.sendPostToModel(jsonString, "9992/api/category_recognition", "getClothCategory"); + // todo 结束限流 + + String bodyString; + // 生成失败 + 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){ + log.error("PythonService##GetClothCategory###{}", "Response error!Response code ## " + response.code() + " ##"); + throw new BusinessException("cloth-classification.interface.exception"); + } else { + try { + bodyString = response.body().string(); + } catch (IOException e) { + throw new BusinessException("cloth-classification.interface.exception"); + } + } + JSONObject jsonObject = JSON.parseObject(bodyString); + Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful"); + if (result && jsonObject.get("msg").equals("OK!")) { + JSONObject data = jsonObject.getJSONObject("data"); + JSONArray list = JSONArray.parseArray(data.get("list").toString()); + JSONObject map = (JSONObject) list.get(0); + return map.get("category").toString(); + } + log.info("getClothCategory 失败###{}", jsonObject); + //生成失败 + throw new BusinessException("cloth-classification.interface.exception"); + } } diff --git a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java index 65514a5f..d7d103d5 100644 --- a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java @@ -31,6 +31,7 @@ import lombok.extern.slf4j.Slf4j; import okhttp3.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; @@ -79,6 +80,7 @@ public class ChatRobotServiceImpl implements ChatRobotService { Integer timeout = 99999999; @Override + @Transactional(rollbackFor = Exception.class) public ChatRobotVO sendMessageToChatRobot(ChatSendDTO chatSendDTO) { // SseEmitter emitter = new SseEmitter(); // String requestBody = gson.toJson(chatSendDTO); @@ -221,6 +223,7 @@ public class ChatRobotServiceImpl implements ChatRobotService { chatRobot.setSuccessful(1); chatRobotMapper.insert(chatRobot); } + chatRobotVO.setIsTutorial(output.contains("tutorial")); return chatRobotVO; } log.error("ChatRobot response data is null!"); diff --git a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java index 12595e57..0ef568bd 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java @@ -86,8 +86,13 @@ public class CollectionElementServiceImpl extends ServiceImpl