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)
} }

@ -5,15 +5,15 @@ import com.ruoyi.system.domain.TImage;
/** /**
* Mapper * Mapper
* *
* @author ruoyi * @author ruoyi
* @date 2022-08-15 * @date 2022-08-15
*/ */
public interface TImageMapper public interface TImageMapper
{ {
/** /**
* *
* *
* @param id * @param id
* @return * @return
*/ */
@ -21,7 +21,7 @@ public interface TImageMapper
/** /**
* *
* *
* @param tImage * @param tImage
* @return * @return
*/ */
@ -29,7 +29,7 @@ public interface TImageMapper
/** /**
* *
* *
* @param tImage * @param tImage
* @return * @return
*/ */
@ -37,7 +37,7 @@ public interface TImageMapper
/** /**
* *
* *
* @param tImage * @param tImage
* @return * @return
*/ */
@ -45,7 +45,7 @@ public interface TImageMapper
/** /**
* *
* *
* @param id * @param id
* @return * @return
*/ */
@ -53,9 +53,11 @@ public interface TImageMapper
/** /**
* *
* *
* @param ids * @param ids
* @return * @return
*/ */
public int deleteTImageByIds(Long[] ids); public int deleteTImageByIds(Long[] ids);
int deleteTImageByThirdId(Long id);
} }

@ -5,15 +5,15 @@ import com.ruoyi.system.domain.TImage;
/** /**
* Service * Service
* *
* @author ruoyi * @author ruoyi
* @date 2022-08-15 * @date 2022-08-15
*/ */
public interface ITImageService public interface ITImageService
{ {
/** /**
* *
* *
* @param id * @param id
* @return * @return
*/ */
@ -21,7 +21,7 @@ public interface ITImageService
/** /**
* *
* *
* @param tImage * @param tImage
* @return * @return
*/ */
@ -29,7 +29,7 @@ public interface ITImageService
/** /**
* *
* *
* @param tImage * @param tImage
* @return * @return
*/ */
@ -37,7 +37,7 @@ public interface ITImageService
/** /**
* *
* *
* @param tImage * @param tImage
* @return * @return
*/ */
@ -45,7 +45,7 @@ public interface ITImageService
/** /**
* *
* *
* @param ids * @param ids
* @return * @return
*/ */
@ -53,9 +53,11 @@ public interface ITImageService
/** /**
* *
* *
* @param id * @param id
* @return * @return
*/ */
public int deleteTImageById(Long id); public int deleteTImageById(Long id);
int deleteTImageByThirdId(Long id);
} }

@ -10,19 +10,19 @@ import com.ruoyi.system.service.ITImageService;
/** /**
* Service * Service
* *
* @author ruoyi * @author ruoyi
* @date 2022-08-15 * @date 2022-08-15
*/ */
@Service @Service
public class TImageServiceImpl implements ITImageService public class TImageServiceImpl implements ITImageService
{ {
@Autowired @Autowired
private TImageMapper tImageMapper; private TImageMapper tImageMapper;
/** /**
* *
* *
* @param id * @param id
* @return * @return
*/ */
@ -34,7 +34,7 @@ public class TImageServiceImpl implements ITImageService
/** /**
* *
* *
* @param tImage * @param tImage
* @return * @return
*/ */
@ -46,7 +46,7 @@ public class TImageServiceImpl implements ITImageService
/** /**
* *
* *
* @param tImage * @param tImage
* @return * @return
*/ */
@ -59,7 +59,7 @@ public class TImageServiceImpl implements ITImageService
/** /**
* *
* *
* @param tImage * @param tImage
* @return * @return
*/ */
@ -71,7 +71,7 @@ public class TImageServiceImpl implements ITImageService
/** /**
* *
* *
* @param ids * @param ids
* @return * @return
*/ */
@ -83,7 +83,7 @@ public class TImageServiceImpl implements ITImageService
/** /**
* *
* *
* @param id * @param id
* @return * @return
*/ */
@ -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格式错误");
} }

@ -3,7 +3,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.TImageMapper"> <mapper namespace="com.ruoyi.system.mapper.TImageMapper">
<resultMap type="TImage" id="TImageResult"> <resultMap type="TImage" id="TImageResult">
<result property="id" column="id" /> <result property="id" column="id" />
<result property="thirdId" column="third_id" /> <result property="thirdId" column="third_id" />
@ -18,18 +18,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectTImageList" parameterType="TImage" resultMap="TImageResult"> <select id="selectTImageList" parameterType="TImage" resultMap="TImageResult">
<include refid="selectTImageVo"/> <include refid="selectTImageVo"/>
<where> <where>
<if test="thirdId != null "> and third_id = #{thirdId}</if> <if test="thirdId != null "> and third_id = #{thirdId}</if>
<if test="path != null and path != ''"> and path = #{path}</if> <if test="path != null and path != ''"> and path = #{path}</if>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if> <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
</where> </where>
</select> </select>
<select id="selectTImageById" parameterType="Long" resultMap="TImageResult"> <select id="selectTImageById" parameterType="Long" resultMap="TImageResult">
<include refid="selectTImageVo"/> <include refid="selectTImageVo"/>
where id = #{id} where id = #{id}
</select> </select>
<insert id="insertTImage" parameterType="TImage" useGeneratedKeys="true" keyProperty="id"> <insert id="insertTImage" parameterType="TImage" useGeneratedKeys="true" keyProperty="id">
insert into t_image insert into t_image
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
@ -62,9 +62,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete> </delete>
<delete id="deleteTImageByIds" parameterType="String"> <delete id="deleteTImageByIds" parameterType="String">
delete from t_image where id in delete from t_image where id in
<foreach item="id" collection="array" open="(" separator="," close=")"> <foreach item="id" collection="array" open="(" separator="," close=")">
#{id} #{id}
</foreach> </foreach>
</delete> </delete>
</mapper>
<delete id="deleteTImageByThirdId" parameterType="Long">
delete from t_image where third_id = #{id}
</delete>
</mapper>

Loading…
Cancel
Save