diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java index 3c86a70..d911114 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java @@ -20,6 +20,7 @@ import com.ruoyi.system.domain.resp.TRecordResp; import com.ruoyi.system.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -355,24 +356,29 @@ public class AppController extends BaseController String URL = RequestParamsUtil.HTTP + ip + RequestParamsUtil.SEPARATOR + port + url; JSONObject jsonObject = new JSONObject(); String result; - TRecord tRecord = new TRecord(); - tRecord.setId(recordId); - tRecord.setStatus("1"); - tRecordService.updateTRecord(tRecord); try { - result = HttpUtils.sendPost(URL, mapper.writeValueAsString(aiPostReq)); + result = HttpUtils.sendPost(URL, mapper.writeValueAsString(delNullData(aiPostReq))); } catch (Exception e) { - tRecord.setStatus("0"); - tRecordService.updateTRecord(tRecord); throw new ServiceException(e.getMessage()); } if (!StringUtils.isEmpty(result)) { - - jsonObject = removeBase64Image(JSONObject.parseObject(result),recordId); + TRecord tRecord = new TRecord(); + tRecord.setId(recordId); + tRecord.setStatus("1"); + tRecordService.updateTRecord(tRecord); + JSONObject data = JSONObject.parseObject(result); + if(data.getInteger("code") != 200){ + TRecord tRecord1 = new TRecord(); + tRecord1.setId(recordId); + tRecord1.setStatus("0"); + tRecordService.updateTRecord(tRecord1); + throw new ServiceException(data.getString("msg")); + } + jsonObject = removeBase64Image(data,recordId); tRecord.setUpdateTime(new Date()); tRecord.setAiResult(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue)); tRecord.setAiResult2(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue)); @@ -403,42 +409,43 @@ public class AppController extends BaseController { Base64ResizedRmgSm base64_resized_img_sm = aiPostReq.getBase64_resized_img_sm(); - Base64ResizedRmgSx base64_resized_img_sx = aiPostReq.getBase64_resized_img_sx(); + Base64ResizedRmgSm base64_resized_img_sx = aiPostReq.getBase64_resized_img_sx(); + Map smMap = imageKey(base64_resized_img_sm,"sm"); + Map sxMap = imageKey(base64_resized_img_sx, "sx"); + smMap.putAll(sxMap); + smMap.forEach((name,value)->{ + if(!StringUtils.isEmpty(value)){ + TImage tImage = new TImage(); + tImage.setThirdId(recordId); + tImage.setCreateTime(new Date()); + tImage.setName(name); + String path=GenerateImage(value); + tImage.setPath(path); + imageService.insertTImage(tImage); + } + }); + } + + public Map imageKey(Base64ResizedRmgSm param,String key){ Map map = new HashMap<>(); - if(!StringUtils.isEmpty(base64_resized_img_sm.getFront())){ - map.put("sm_front",base64_resized_img_sm.getFront()); + if(!StringUtils.isEmpty(param.getFront())){ + map.put(key+"_front",param.getFront()); } - if(!StringUtils.isEmpty(base64_resized_img_sx.getFront())){ - map.put("sx_front",base64_resized_img_sx.getFront()); + if(!StringUtils.isEmpty(param.getLeft())){ + map.put(key+"_left",param.getLeft()); } - map.forEach((name,value)->{ - TImage tImage = new TImage(); - tImage.setThirdId(recordId); - tImage.setCreateTime(new Date()); - tImage.setName(name); - String path=GenerateImage(value); - tImage.setPath(path); - imageService.insertTImage(tImage); - }); - } + if(!StringUtils.isEmpty(param.getFront())){ + map.put(key+"_right",param.getRight()); + } + if(!CollectionUtils.isEmpty(param.getOther())){ + for (int i = 0; i < param.getOther().size(); i++) + { + map.put(key+"_other_"+i,param.getOther().get(i)); + } + } + return map; -// public Map imageKey(Base64ResizedRmgSm param,String key){ -// -//// if(!StringUtils.isEmpty(param.getLeft())){ -//// map.put(key+"-left",param.getLeft()); -//// } -//// if(!StringUtils.isEmpty(param.getFront())){ -//// map.put(key+"-right",param.getRight()); -//// } -//// if(!CollectionUtils.isEmpty(param.getOther())){ -//// for (int i = 0; i < param.getOther().size(); i++) -//// { -//// map.put(key+"-other"+i,param.getOther().get(i)); -//// } -//// } -// return map; -// -// } + } public JSONObject removeBase64Image(JSONObject jsonObject,Long recordId) { @@ -473,11 +480,20 @@ public class AppController extends BaseController } catch (Exception e) { + TRecord tRecord = new TRecord(); + tRecord.setId(recordId); + tRecord.setStatus("0"); + tRecordService.updateTRecord(tRecord); throw new ServiceException("JSON解析错误:" + jsonObject.toJSONString()); } return jsonObject; } + public JSONObject delNullData(AiPostReq aiPostReq){ + JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(aiPostReq)); + return jsonObject; + + } public static String GenerateImage(String imgStr) { diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/AiPostReq.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/AiPostReq.java index 576dc82..28b8b1d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/AiPostReq.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/AiPostReq.java @@ -8,7 +8,7 @@ import java.util.List; public class AiPostReq { private Base64ResizedRmgSm base64_resized_img_sm; - private Base64ResizedRmgSx base64_resized_img_sx; + private Base64ResizedRmgSm base64_resized_img_sx; public Base64ResizedRmgSm getBase64_resized_img_sm() { @@ -20,12 +20,12 @@ public class AiPostReq this.base64_resized_img_sm = base64_resized_img_sm; } - public Base64ResizedRmgSx getBase64_resized_img_sx() + public Base64ResizedRmgSm getBase64_resized_img_sx() { return base64_resized_img_sx; } - public void setBase64_resized_img_sx(Base64ResizedRmgSx base64_resized_img_sx) + public void setBase64_resized_img_sx(Base64ResizedRmgSm base64_resized_img_sx) { this.base64_resized_img_sx = base64_resized_img_sx; } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/Base64ResizedRmgSm.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/Base64ResizedRmgSm.java index 4ecd7fe..aedf0d7 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/Base64ResizedRmgSm.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/Base64ResizedRmgSm.java @@ -5,10 +5,9 @@ import java.util.List; public class Base64ResizedRmgSm { private String front; -// private String left; -// private String right; -//// private List other; -// private String other; + private String left; + private String right; + private List other; public String getFront() { return front; @@ -19,33 +18,33 @@ public class Base64ResizedRmgSm this.front = front; } -// public String getLeft() -// { -// return left; -// } -// -// public void setLeft(String left) -// { -// this.left = left; -// } -// -// public String getRight() -// { -// return right; -// } -// -// public void setRight(String right) -// { -// this.right = right; -// } -// -// public String getOther() -// { -// return other; -// } -// -// public void setOther(String other) -// { -// this.other = other; -// } + public String getLeft() + { + return left; + } + + public void setLeft(String left) + { + this.left = left; + } + + public String getRight() + { + return right; + } + + public void setRight(String right) + { + this.right = right; + } + + public List getOther() + { + return other; + } + + public void setOther(List other) + { + this.other = other; + } }