ai接口插入图片

master
chenfei 2 years ago
parent f8b93c8f28
commit 673b07b728

@ -318,6 +318,8 @@ public class AppController extends BaseController
@ApiOperation("ai接口") @ApiOperation("ai接口")
public AjaxResult aiPost(@PathVariable("recordId") Long recordId, @RequestBody AiPostReq aiPostReq) public AjaxResult aiPost(@PathVariable("recordId") Long recordId, @RequestBody AiPostReq aiPostReq)
{ {
//删除同一次预约调用多次ai接口的图片数据
imageService.deleteTImageByThirdId(recordId);
saveImage(aiPostReq,recordId); saveImage(aiPostReq,recordId);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
String URL = RequestParamsUtil.HTTP + ip + RequestParamsUtil.SEPARATOR + port + url; 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)); tRecord.setAiResult2(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));
tRecordService.updateTRecord(tRecord); 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}") @GetMapping("/image/{recordId}")
@ -359,43 +367,45 @@ public class AppController extends BaseController
private void saveImage(AiPostReq aiPostReq,Long recordId) private void saveImage(AiPostReq aiPostReq,Long recordId)
{ {
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(); 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<>(); Map<String,String> map = new HashMap<>();
if(!StringUtils.isEmpty(param.getFront())){ if(!StringUtils.isEmpty(base64_resized_img_sm.getFront())){
map.put(key+"-front",param.getFront()); map.put("sm_front",base64_resized_img_sm.getFront());
} }
// if(!StringUtils.isEmpty(param.getLeft())){ if(!StringUtils.isEmpty(base64_resized_img_sx.getFront())){
// map.put(key+"-left",param.getLeft()); map.put("sx_front",base64_resized_img_sx.getFront());
// } }
// if(!StringUtils.isEmpty(param.getFront())){ map.forEach((name,value)->{
// map.put(key+"-right",param.getRight()); TImage tImage = new TImage();
// } tImage.setThirdId(recordId);
// if(!CollectionUtils.isEmpty(param.getOther())){ tImage.setCreateTime(new Date());
// for (int i = 0; i < param.getOther().size(); i++) tImage.setName(name);
// { String path=GenerateImage(value);
// map.put(key+"-other"+i,param.getOther().get(i)); tImage.setPath(path);
// } 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)
{ {
String []keys={"img_sz","img_sz_yudian","img_sz_yuban","img_sz_liewen","img_st","img_sx","img_sx_vein"}; String []keys={"img_sz","img_sz_yudian","img_sz_yuban","img_sz_liewen","img_st","img_sx","img_sx_vein"};
@ -416,13 +426,13 @@ public class AppController extends BaseController
String imgStr=parents.get(i).getJSONObject(imageKey).getString("v"); String imgStr=parents.get(i).getJSONObject(imageKey).getString("v");
String path=GenerateImage(imgStr); String path=GenerateImage(imgStr);
parents.get(i).getJSONObject(keys[i]).put("v",null); parents.get(i).getJSONObject(keys[i]).put("v",null);
// TImage tImage = new TImage(); TImage tImage = new TImage();
// tImage.setName(imageKey); tImage.setName(imageKey);
// tImage.setPath(path); tImage.setPath(path);
// tImage.setCreateTime(new Date()); tImage.setCreateTime(new Date());
// tImage.setThirdId(recordId); tImage.setThirdId(recordId);
// imageService.insertTImage(tImage); imageService.insertTImage(tImage);
//保存图片到数据库,thirdId(recordId),path,name(imageKey) // 保存图片到数据库,thirdId(recordId),path,name(imageKey)
} }

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

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

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

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