|
|
|
@ -4,8 +4,6 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
|
|
import com.ruoyi.common.config.RuoYiConfig;
|
|
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
@ -17,7 +15,6 @@ import com.ruoyi.common.utils.SecurityUtils;
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
|
import com.ruoyi.common.utils.file.FileUtils;
|
|
|
|
|
import com.ruoyi.common.utils.http.HttpUtils;
|
|
|
|
|
import com.ruoyi.framework.config.ServerConfig;
|
|
|
|
|
import com.ruoyi.system.domain.*;
|
|
|
|
|
import com.ruoyi.system.domain.req.*;
|
|
|
|
|
import com.ruoyi.system.domain.resp.TRecordResp;
|
|
|
|
@ -29,14 +26,8 @@ import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import sun.misc.BASE64Encoder;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.imageio.stream.FileImageInputStream;
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@ -70,9 +61,6 @@ public class AppController extends BaseController
|
|
|
|
|
@Resource
|
|
|
|
|
private ITImageService imageService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ServerConfig serverConfig;
|
|
|
|
|
|
|
|
|
|
@Value("${aiPost.ip}")
|
|
|
|
|
private String ip;
|
|
|
|
|
@Value("${aiPost.port}")
|
|
|
|
@ -422,122 +410,6 @@ public class AppController extends BaseController
|
|
|
|
|
return AjaxResult.success(images);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/ai2/{recordId}")
|
|
|
|
|
@Log(title = "ai接口备用")
|
|
|
|
|
@ApiOperation("ai接口备用")
|
|
|
|
|
public AjaxResult aiPost2(@PathVariable("recordId") Long recordId, @RequestBody AiPostReq aiPostReq)
|
|
|
|
|
{
|
|
|
|
|
//删除同一次预约调用多次ai接口的图片数据
|
|
|
|
|
imageService.deleteTImageByThirdId(recordId);
|
|
|
|
|
// saveImage(aiPostReq,recordId);
|
|
|
|
|
// revertImageToBase64(aiPostReq);
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
String URL = RequestParamsUtil.HTTP + ip + RequestParamsUtil.SEPARATOR + port + url;
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
TRecord tRecord = new TRecord();
|
|
|
|
|
tRecord.setId(recordId);
|
|
|
|
|
tRecord.setStatus("1");
|
|
|
|
|
tRecordService.updateTRecord(tRecord);
|
|
|
|
|
String result;
|
|
|
|
|
Date start;
|
|
|
|
|
Date end;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
start = new Date();
|
|
|
|
|
result = HttpUtils.sendPost(URL, mapper.writeValueAsString(delNullData(aiPostReq)));
|
|
|
|
|
end = new Date();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
throw new ServiceException(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtils.isEmpty(result))
|
|
|
|
|
{
|
|
|
|
|
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.setUploadTime(start);
|
|
|
|
|
tRecord.setAiResultReturnTime(end);
|
|
|
|
|
tRecord.setAiResult(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));
|
|
|
|
|
tRecord.setAiResult2(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));
|
|
|
|
|
tRecordService.updateTRecord(tRecord);
|
|
|
|
|
}
|
|
|
|
|
Map<String,Object> data = new HashMap<>();
|
|
|
|
|
data.put("result",jsonObject);
|
|
|
|
|
TImage tImage = new TImage();
|
|
|
|
|
tImage.setThirdId(recordId);
|
|
|
|
|
List<TImage> images = imageService.selectTImageList(tImage);
|
|
|
|
|
data.put("image", images);
|
|
|
|
|
return AjaxResult.success(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AiPostReq revertImageToBase64(AiPostReq aiPostReq,Long recordId)
|
|
|
|
|
{
|
|
|
|
|
Base64ResizedRmgSm base64_resized_img_sm = aiPostReq.getBase64_resized_img_sm();
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(base64_resized_img_sm));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jsonObject.forEach((key,value)->{
|
|
|
|
|
if(value instanceof String){
|
|
|
|
|
jsonObject.put(key,toBase64((String) value));
|
|
|
|
|
TImage tImage = new TImage();
|
|
|
|
|
tImage.setThirdId(recordId);
|
|
|
|
|
tImage.setPath((String) value);
|
|
|
|
|
tImage.setCreateTime(new Date());
|
|
|
|
|
tImage.setName("sm_"+key);
|
|
|
|
|
imageService.insertTImage(tImage);
|
|
|
|
|
}
|
|
|
|
|
if(value instanceof List){
|
|
|
|
|
((List<?>) value).forEach(o -> {
|
|
|
|
|
jsonObject.put(key,toBase64((String) o));
|
|
|
|
|
TImage tImage = new TImage();
|
|
|
|
|
tImage.setThirdId(recordId);
|
|
|
|
|
tImage.setPath((String) o);
|
|
|
|
|
tImage.setCreateTime(new Date());
|
|
|
|
|
tImage.setName("sm_"+ key+"_" +((List<?>) value).indexOf(o));
|
|
|
|
|
imageService.insertTImage(tImage);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Base64ResizedRmgSm base64ResizedRmgSm = JSONObject.parseObject(jsonObject.toJSONString(), Base64ResizedRmgSm.class);
|
|
|
|
|
aiPostReq.setBase64_resized_img_sm(base64ResizedRmgSm);
|
|
|
|
|
});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String toBase64(String path){
|
|
|
|
|
return sourceToBase64(RuoYiConfig.getProfile() + StringUtils.substringAfter(path, Constants.RESOURCE_PREFIX));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String sourceToBase64(String path) {
|
|
|
|
|
byte[] data = null;
|
|
|
|
|
FileImageInputStream input = null;
|
|
|
|
|
try {
|
|
|
|
|
input = new FileImageInputStream(new File(path));
|
|
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
|
|
byte[] buf = new byte[1024];
|
|
|
|
|
int numBytesRead = 0;
|
|
|
|
|
while((numBytesRead = input.read(buf)) != -1){
|
|
|
|
|
output.write(buf, 0, numBytesRead);
|
|
|
|
|
}
|
|
|
|
|
data = output.toByteArray();
|
|
|
|
|
output.close();
|
|
|
|
|
input.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
BASE64Encoder base64Encoder = new BASE64Encoder();
|
|
|
|
|
return base64Encoder.encode(data);
|
|
|
|
|
}
|
|
|
|
|
private void saveImage(AiPostReq aiPostReq,Long recordId)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|