ai接口插入图片

master
chenfei 2 years ago
parent f8b93c8f28
commit 673b07b728

@ -318,6 +318,8 @@ public class AppController extends BaseController
@ApiOperation("ai接口")
public AjaxResult aiPost(@PathVariable("recordId") Long recordId, @RequestBody AiPostReq aiPostReq)
{
//删除同一次预约调用多次ai接口的图片数据
imageService.deleteTImageByThirdId(recordId);
saveImage(aiPostReq,recordId);
ObjectMapper mapper = new ObjectMapper();
String URL = RequestParamsUtil.HTTP + ip + RequestParamsUtil.SEPARATOR + port + url;
@ -342,7 +344,13 @@ public class AppController extends BaseController
tRecord.setAiResult2(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));
tRecordService.updateTRecord(tRecord);
}
return AjaxResult.success(jsonObject);
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);
}
@GetMapping("/image/{recordId}")
@ -359,42 +367,44 @@ public class AppController extends BaseController
private void saveImage(AiPostReq aiPostReq,Long recordId)
{
Base64ResizedRmgSm base64_resized_img_sm = aiPostReq.getBase64_resized_img_sm();
Base64ResizedRmgSx base64_resized_img_sx = aiPostReq.getBase64_resized_img_sx();
Map<String, String> smMap = imageKey(base64_resized_img_sm,"base64_resized_img_sm");
// Map<String, String> sxMap = imageKey(base64_resized_img_sx, "base64_resized_img_sx");
// smMap.putAll(sxMap);
// sxMap.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);
// });
}
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(base64_resized_img_sm.getFront())){
map.put("sm_front",base64_resized_img_sm.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;
if(!StringUtils.isEmpty(base64_resized_img_sx.getFront())){
map.put("sx_front",base64_resized_img_sx.getFront());
}
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);
});
}
// 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)
{
@ -416,12 +426,12 @@ public class AppController extends BaseController
String imgStr=parents.get(i).getJSONObject(imageKey).getString("v");
String path=GenerateImage(imgStr);
parents.get(i).getJSONObject(keys[i]).put("v",null);
// TImage tImage = new TImage();
// tImage.setName(imageKey);
// tImage.setPath(path);
// tImage.setCreateTime(new Date());
// tImage.setThirdId(recordId);
// imageService.insertTImage(tImage);
TImage tImage = new TImage();
tImage.setName(imageKey);
tImage.setPath(path);
tImage.setCreateTime(new Date());
tImage.setThirdId(recordId);
imageService.insertTImage(tImage);
// 保存图片到数据库,thirdId(recordId),path,name(imageKey)
}

@ -58,4 +58,6 @@ public interface TImageMapper
* @return
*/
public int deleteTImageByIds(Long[] ids);
int deleteTImageByThirdId(Long id);
}

@ -58,4 +58,6 @@ public interface ITImageService
* @return
*/
public int deleteTImageById(Long id);
int deleteTImageByThirdId(Long id);
}

@ -92,4 +92,10 @@ public class TImageServiceImpl implements ITImageService
{
return tImageMapper.deleteTImageById(id);
}
@Override
public int deleteTImageByThirdId(Long id)
{
return tImageMapper.deleteTImageByThirdId(id);
}
}

@ -163,9 +163,9 @@ public class TRecordServiceImpl implements ITRecordService
}
List<TRecord> records = tRecords.stream().sorted(Comparator.comparing(TRecord::getCreateTime)).collect(Collectors.toList());
List<String> jsonKeyList = new ArrayList<String>(){{
add("shemian-sz_avg_red");
add("st_avg_yellow");
add("sx_vein_color");
add("shemian-img_sz");
add("img_st");
add("img_sx");
}};
RecordHistoryDataResp recordHistoryDataRespMap = getDataList(records,jsonKeyList);
return AjaxResult.success(recordHistoryDataRespMap);
@ -199,9 +199,9 @@ public class TRecordServiceImpl implements ITRecordService
Integer value3 ;
try
{
value1 = jsonObject.getJSONObject("data").getJSONObject("shezhi").getJSONObject(keys0[0]).getInteger(keys0[1]);
value2 = jsonObject.getJSONObject("data").getJSONObject("shetai").getInteger(key1);
value3 = jsonObject.getJSONObject("data").getJSONObject("shexia").getInteger(key2);
value1 = jsonObject.getJSONObject("data").getJSONObject("shezhi").getJSONObject(keys0[0]).getJSONObject(keys0[1]).getInteger("anomaly");
value2 = jsonObject.getJSONObject("data").getJSONObject("shetai").getJSONObject(key1).getInteger("anomaly");
value3 = jsonObject.getJSONObject("data").getJSONObject("shexia").getJSONObject(key2).getInteger("anomaly");
}catch (Exception e){
throw new ServiceException("JSON格式错误");
}

@ -67,4 +67,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<delete id="deleteTImageByThirdId" parameterType="Long">
delete from t_image where third_id = #{id}
</delete>
</mapper>
Loading…
Cancel
Save