ai上传参数修改字段

master
chenfei 2 years ago
parent 9436a2c889
commit 5ff44991c3

@ -20,6 +20,7 @@ import com.ruoyi.system.domain.resp.TRecordResp;
import com.ruoyi.system.service.*; import com.ruoyi.system.service.*;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; 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; String URL = RequestParamsUtil.HTTP + ip + RequestParamsUtil.SEPARATOR + port + url;
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
String result; String result;
TRecord tRecord = new TRecord();
tRecord.setId(recordId);
tRecord.setStatus("1");
tRecordService.updateTRecord(tRecord);
try try
{ {
result = HttpUtils.sendPost(URL, mapper.writeValueAsString(aiPostReq)); result = HttpUtils.sendPost(URL, mapper.writeValueAsString(delNullData(aiPostReq)));
} }
catch (Exception e) catch (Exception e)
{ {
tRecord.setStatus("0");
tRecordService.updateTRecord(tRecord);
throw new ServiceException(e.getMessage()); throw new ServiceException(e.getMessage());
} }
if (!StringUtils.isEmpty(result)) if (!StringUtils.isEmpty(result))
{ {
TRecord tRecord = new TRecord();
jsonObject = removeBase64Image(JSONObject.parseObject(result),recordId); 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.setUpdateTime(new Date());
tRecord.setAiResult(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue)); tRecord.setAiResult(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));
tRecord.setAiResult2(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(); 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<String, String> smMap = imageKey(base64_resized_img_sm,"sm");
Map<String, String> 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<String,String> imageKey(Base64ResizedRmgSm param,String key){
Map<String,String> map = new HashMap<>(); Map<String,String> map = new HashMap<>();
if(!StringUtils.isEmpty(base64_resized_img_sm.getFront())){ if(!StringUtils.isEmpty(param.getFront())){
map.put("sm_front",base64_resized_img_sm.getFront()); map.put(key+"_front",param.getFront());
} }
if(!StringUtils.isEmpty(base64_resized_img_sx.getFront())){ if(!StringUtils.isEmpty(param.getLeft())){
map.put("sx_front",base64_resized_img_sx.getFront()); map.put(key+"_left",param.getLeft());
} }
map.forEach((name,value)->{ if(!StringUtils.isEmpty(param.getFront())){
TImage tImage = new TImage(); map.put(key+"_right",param.getRight());
tImage.setThirdId(recordId); }
tImage.setCreateTime(new Date()); if(!CollectionUtils.isEmpty(param.getOther())){
tImage.setName(name); for (int i = 0; i < param.getOther().size(); i++)
String path=GenerateImage(value); {
tImage.setPath(path); map.put(key+"_other_"+i,param.getOther().get(i));
imageService.insertTImage(tImage); }
}); }
} return map;
// public Map<String,String> 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) public JSONObject removeBase64Image(JSONObject jsonObject,Long recordId)
{ {
@ -473,11 +480,20 @@ public class AppController extends BaseController
} }
catch (Exception e) catch (Exception e)
{ {
TRecord tRecord = new TRecord();
tRecord.setId(recordId);
tRecord.setStatus("0");
tRecordService.updateTRecord(tRecord);
throw new ServiceException("JSON解析错误:" + jsonObject.toJSONString()); throw new ServiceException("JSON解析错误:" + jsonObject.toJSONString());
} }
return jsonObject; return jsonObject;
} }
public JSONObject delNullData(AiPostReq aiPostReq){
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(aiPostReq));
return jsonObject;
}
public static String GenerateImage(String imgStr) public static String GenerateImage(String imgStr)
{ {

@ -8,7 +8,7 @@ import java.util.List;
public class AiPostReq public class AiPostReq
{ {
private Base64ResizedRmgSm base64_resized_img_sm; private Base64ResizedRmgSm base64_resized_img_sm;
private Base64ResizedRmgSx base64_resized_img_sx; private Base64ResizedRmgSm base64_resized_img_sx;
public Base64ResizedRmgSm getBase64_resized_img_sm() public Base64ResizedRmgSm getBase64_resized_img_sm()
{ {
@ -20,12 +20,12 @@ public class AiPostReq
this.base64_resized_img_sm = base64_resized_img_sm; 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; 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; this.base64_resized_img_sx = base64_resized_img_sx;
} }

@ -5,10 +5,9 @@ import java.util.List;
public class Base64ResizedRmgSm public class Base64ResizedRmgSm
{ {
private String front; private String front;
// private String left; private String left;
// private String right; private String right;
//// private List<String> other; private List<String> other;
// private String other;
public String getFront() public String getFront()
{ {
return front; return front;
@ -19,33 +18,33 @@ public class Base64ResizedRmgSm
this.front = front; this.front = front;
} }
// public String getLeft() public String getLeft()
// { {
// return left; return left;
// } }
//
// public void setLeft(String left) public void setLeft(String left)
// { {
// this.left = left; this.left = left;
// } }
//
// public String getRight() public String getRight()
// { {
// return right; return right;
// } }
//
// public void setRight(String right) public void setRight(String right)
// { {
// this.right = right; this.right = right;
// } }
//
// public String getOther() public List<String> getOther()
// { {
// return other; return other;
// } }
//
// public void setOther(String other) public void setOther(List<String> other)
// { {
// this.other = other; this.other = other;
// } }
} }

Loading…
Cancel
Save