AI接口返回值解析失败问题修改

master
gongzhenkun 2 years ago
parent ba8ee83f6a
commit 9396815f3b

@ -621,34 +621,17 @@ public class AppController extends BaseController
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"};
List<JSONObject> parents=new ArrayList<>();
try
{
parents.add(jsonObject.getJSONObject("data").getJSONObject("shezhi").getJSONObject("shemian"));
parents.add(jsonObject.getJSONObject("data").getJSONObject("shezhi").getJSONObject("yudian"));
parents.add(jsonObject.getJSONObject("data").getJSONObject("shezhi").getJSONObject("yuban"));
parents.add(jsonObject.getJSONObject("data").getJSONObject("shezhi").getJSONObject("liewen"));
parents.add(jsonObject.getJSONObject("data").getJSONObject("shetai"));
parents.add(jsonObject.getJSONObject("data").getJSONObject("shexia"));
parents.add(jsonObject.getJSONObject("data").getJSONObject("shexia"));
for (int i=0;i<keys.length;i++)
{
String imageKey=keys[i];
String imgStr=parents.get(i).getJSONObject(imageKey).getString("v");
String path=FileUtils.GenerateImage(imgStr,imageKey);
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);
// 保存图片到数据库,thirdId(recordId),path,name(imageKey)
}
List<String> jsonKeyList = new ArrayList<String>(){{
add("img_sz");
add("img_sz_yudian");
add("img_sz_yuban");
add("img_sz_liewen");
add("img_st");
add("img_sx");
add("img_sx_vein");
}};
try {
doRemoveBase64Image(jsonObject.getJSONObject("data"), "data", jsonKeyList, recordId);
}
catch (Exception e)
{
@ -667,6 +650,48 @@ public class AppController extends BaseController
}
/**
* base64
*
* @param obj obj
* @param listName listName
* @param imageKeys imageKeys
* @param recordId recordId
*/
public void doRemoveBase64Image(Object obj, String listName, List<String> imageKeys, Long recordId) {
// 遍历json
if (obj instanceof JSONObject) {
for (Map.Entry<String, Object> entry : ((JSONObject) obj).entrySet()) {
// 如果key包含在图片
if (imageKeys.contains(entry.getKey())) {
String imageStr = null;
if (entry.getValue() instanceof JSONObject) {
String v = ((JSONObject) entry.getValue()).getString("v");
if (null != v) {
imageStr = v;
}
} else {
imageStr = (String) entry.getValue();
}
if (null != imageStr) {
// 将base64转为图片存在服务器并将返回值置空
String path=FileUtils.GenerateImage(imageStr, entry.getKey());
TImage tImage = new TImage();
tImage.setName(entry.getKey());
tImage.setPath(path);
tImage.setCreateTime(new Date());
tImage.setThirdId(recordId);
imageService.insertTImage(tImage);
entry.setValue("");
}
}
if (!(entry.getValue() instanceof String)) {
doRemoveBase64Image(entry.getValue(), entry.getKey(), imageKeys, recordId);
}
}
}
}
/**
*
*

Loading…
Cancel
Save