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 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,15 +409,12 @@ 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();
Map<String,String> map = new HashMap<>();
if(!StringUtils.isEmpty(base64_resized_img_sm.getFront())){
map.put("sm_front",base64_resized_img_sm.getFront());
}
if(!StringUtils.isEmpty(base64_resized_img_sx.getFront())){
map.put("sx_front",base64_resized_img_sx.getFront());
}
map.forEach((name,value)->{
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());
@ -419,26 +422,30 @@ public class AppController extends BaseController
String path=GenerateImage(value);
tImage.setPath(path);
imageService.insertTImage(tImage);
}
});
}
// 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 Map<String,String> imageKey(Base64ResizedRmgSm param,String key){
Map<String,String> map = new HashMap<>();
if(!StringUtils.isEmpty(param.getFront())){
map.put(key+"_front",param.getFront());
}
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)
{

@ -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;
}

@ -5,10 +5,9 @@ import java.util.List;
public class Base64ResizedRmgSm
{
private String front;
// private String left;
// private String right;
//// private List<String> other;
// private String other;
private String left;
private String right;
private List<String> 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<String> getOther()
{
return other;
}
public void setOther(List<String> other)
{
this.other = other;
}
}

Loading…
Cancel
Save