|
|
@ -28,7 +28,6 @@ import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import sun.misc.BASE64Encoder;
|
|
|
|
import sun.misc.BASE64Encoder;
|
|
|
@ -328,7 +327,8 @@ public class AppController extends BaseController
|
|
|
|
if (tRecordResps.isEmpty()) {
|
|
|
|
if (tRecordResps.isEmpty()) {
|
|
|
|
return AjaxResult.success(new ArrayList<TRecordResp>());
|
|
|
|
return AjaxResult.success(new ArrayList<TRecordResp>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<TRecordResp> respList = tRecordResps.stream().sorted(Comparator.comparing(TRecordResp::getUploadTime).reversed()).collect(Collectors.toList());
|
|
|
|
List<TRecordResp> respList = tRecordResps.stream()
|
|
|
|
|
|
|
|
.sorted(Comparator.comparing(TRecordResp::getUploadTime, Comparator.nullsLast(Date::compareTo)).reversed()).collect(Collectors.toList());
|
|
|
|
return AjaxResult.success(respList);
|
|
|
|
return AjaxResult.success(respList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -416,11 +416,18 @@ public class AppController extends BaseController
|
|
|
|
@PostMapping("/ai/{recordId}")
|
|
|
|
@PostMapping("/ai/{recordId}")
|
|
|
|
@ApiOperation("ai接口")
|
|
|
|
@ApiOperation("ai接口")
|
|
|
|
@Log(title = "调用ai接口", businessType = BusinessType.OTHER)
|
|
|
|
@Log(title = "调用ai接口", businessType = BusinessType.OTHER)
|
|
|
|
@Transactional
|
|
|
|
|
|
|
|
public AjaxResult aiPost(@PathVariable("recordId") Long recordId, @RequestBody AIPostReqEx aiPostReqEx)
|
|
|
|
public AjaxResult aiPost(@PathVariable("recordId") Long recordId, @RequestBody AIPostReqEx aiPostReqEx)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AiPostReq aiPostReq = new AiPostReq();
|
|
|
|
AiPostReq aiPostReq = new AiPostReq();
|
|
|
|
BeanUtils.copyProperties(aiPostReqEx, aiPostReq);
|
|
|
|
BeanUtils.copyProperties(aiPostReqEx, aiPostReq);
|
|
|
|
|
|
|
|
logger.info("update recordId is '{}' status. system time is '{}'", recordId, System.currentTimeMillis());
|
|
|
|
|
|
|
|
TRecord tRecord = new TRecord();
|
|
|
|
|
|
|
|
tRecord.setId(recordId);
|
|
|
|
|
|
|
|
// APP跳转页面,需要立刻修改记录状态
|
|
|
|
|
|
|
|
tRecord.setStatus("2");
|
|
|
|
|
|
|
|
tRecord.setAppDealTime(aiPostReqEx.getAppDealTime());
|
|
|
|
|
|
|
|
logger.info("update record status is '{}', record is '{}'",tRecord.getStatus(), tRecord);
|
|
|
|
|
|
|
|
tRecordService.updateTRecord(tRecord);
|
|
|
|
//删除同一次预约调用多次ai接口的图片数据
|
|
|
|
//删除同一次预约调用多次ai接口的图片数据
|
|
|
|
logger.info("aiPost param is {}", aiPostReq);
|
|
|
|
logger.info("aiPost param is {}", aiPostReq);
|
|
|
|
imageService.deleteTImageByThirdId(recordId);
|
|
|
|
imageService.deleteTImageByThirdId(recordId);
|
|
|
@ -428,16 +435,11 @@ public class AppController extends BaseController
|
|
|
|
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;
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
TRecord tRecord = new TRecord();
|
|
|
|
|
|
|
|
tRecord.setId(recordId);
|
|
|
|
|
|
|
|
tRecord.setStatus("1");
|
|
|
|
|
|
|
|
tRecord.setAppDealTime(aiPostReqEx.getAppDealTime());
|
|
|
|
|
|
|
|
tRecordService.updateTRecord(tRecord);
|
|
|
|
|
|
|
|
String result;
|
|
|
|
String result;
|
|
|
|
Date start;
|
|
|
|
Date start;
|
|
|
|
Date end;
|
|
|
|
Date end;
|
|
|
|
try
|
|
|
|
Map<String,Object> data = new HashMap<>();
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
start = new Date();
|
|
|
|
start = new Date();
|
|
|
|
if (aiPostReq.getUsr() != null) {
|
|
|
|
if (aiPostReq.getUsr() != null) {
|
|
|
|
aiPostReq.getUsr().setTs_submit_ai(start.getTime());
|
|
|
|
aiPostReq.getUsr().setTs_submit_ai(start.getTime());
|
|
|
@ -445,37 +447,39 @@ public class AppController extends BaseController
|
|
|
|
logger.info("ai param is {}", aiPostReq);
|
|
|
|
logger.info("ai param is {}", aiPostReq);
|
|
|
|
result = HttpUtils.sendPost(URL, mapper.writeValueAsString(delNullData(aiPostReq)));
|
|
|
|
result = HttpUtils.sendPost(URL, mapper.writeValueAsString(delNullData(aiPostReq)));
|
|
|
|
end = new Date();
|
|
|
|
end = new Date();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
catch (Exception e)
|
|
|
|
// AI接口异常,需要重置当前记录状态
|
|
|
|
{
|
|
|
|
updateRecordStatus(recordId, "0");
|
|
|
|
throw new ServiceException(e.getMessage());
|
|
|
|
logger.error("AI result exception, msg is {}", e.getMessage());
|
|
|
|
}
|
|
|
|
return AjaxResult.error("AI result exception, please try again!", data);
|
|
|
|
if (!StringUtils.isEmpty(result))
|
|
|
|
}
|
|
|
|
{
|
|
|
|
if (StringUtils.isEmpty(result)) {
|
|
|
|
JSONObject data = JSONObject.parseObject(result);
|
|
|
|
// AI接口非正常返回,需要重置当前记录状态
|
|
|
|
Integer code = data.getInteger("code");
|
|
|
|
updateRecordStatus(recordId, "0");
|
|
|
|
if(code != 200 && code != 204){
|
|
|
|
return AjaxResult.error(200,"AI result is null. please try again!");
|
|
|
|
TRecord tRecord1 = new TRecord();
|
|
|
|
} else {
|
|
|
|
tRecord1.setId(recordId);
|
|
|
|
JSONObject resultJB = JSONObject.parseObject(result);
|
|
|
|
tRecord1.setStatus("0");
|
|
|
|
Integer code = resultJB.getInteger("code");
|
|
|
|
tRecordService.updateTRecord(tRecord1);
|
|
|
|
if (code != 200 && code != 204) {
|
|
|
|
throw new ServiceException(data.getString("msg"));
|
|
|
|
// AI接口非正常返回,需要重置当前记录状态
|
|
|
|
|
|
|
|
updateRecordStatus(recordId, "0");
|
|
|
|
|
|
|
|
throw new ServiceException(resultJB.getString("msg"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (code == 204) {
|
|
|
|
if (code == 204) {
|
|
|
|
TRecord tRecord1 = new TRecord();
|
|
|
|
// AI接口非正常返回,需要重置当前记录状态
|
|
|
|
tRecord1.setId(recordId);
|
|
|
|
updateRecordStatus(recordId, "0");
|
|
|
|
tRecord1.setStatus("0");
|
|
|
|
return AjaxResult.error(code, resultJB.getString("msg"));
|
|
|
|
tRecordService.updateTRecord(tRecord1);
|
|
|
|
|
|
|
|
return AjaxResult.error(code, data.getString("msg"));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
jsonObject = removeBase64Image(data,recordId);
|
|
|
|
// 正常返回,记录状态置为“1”
|
|
|
|
|
|
|
|
tRecord.setStatus("1");
|
|
|
|
|
|
|
|
jsonObject = removeBase64Image(resultJB, recordId);
|
|
|
|
tRecord.setUploadTime(start);
|
|
|
|
tRecord.setUploadTime(start);
|
|
|
|
tRecord.setAiResultReturnTime(end);
|
|
|
|
tRecord.setAiResultReturnTime(end);
|
|
|
|
tRecord.setAiResult(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));
|
|
|
|
tRecord.setAiResult(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));
|
|
|
|
tRecord.setAiResult2(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));
|
|
|
|
tRecord.setAiResult2(JSONObject.toJSONString(jsonObject, SerializerFeature.WriteMapNullValue));
|
|
|
|
|
|
|
|
logger.info("update record status is '{}', record is '{}'",tRecord.getStatus(), tRecord);
|
|
|
|
tRecordService.updateTRecord(tRecord);
|
|
|
|
tRecordService.updateTRecord(tRecord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Map<String,Object> data = new HashMap<>();
|
|
|
|
|
|
|
|
data.put("result",jsonObject);
|
|
|
|
data.put("result",jsonObject);
|
|
|
|
TImage tImage = new TImage();
|
|
|
|
TImage tImage = new TImage();
|
|
|
|
tImage.setThirdId(recordId);
|
|
|
|
tImage.setThirdId(recordId);
|
|
|
@ -484,6 +488,13 @@ public class AppController extends BaseController
|
|
|
|
return AjaxResult.success(data);
|
|
|
|
return AjaxResult.success(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateRecordStatus(Long recordId, String status) {
|
|
|
|
|
|
|
|
TRecord tRecord1 = new TRecord();
|
|
|
|
|
|
|
|
tRecord1.setId(recordId);
|
|
|
|
|
|
|
|
tRecord1.setStatus(status);
|
|
|
|
|
|
|
|
tRecordService.updateTRecord(tRecord1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/image/{recordId}")
|
|
|
|
@GetMapping("/image/{recordId}")
|
|
|
|
@ApiOperation("获取图片接口")
|
|
|
|
@ApiOperation("获取图片接口")
|
|
|
|
@Log(title = "获取图片接口", businessType = BusinessType.OTHER)
|
|
|
|
@Log(title = "获取图片接口", businessType = BusinessType.OTHER)
|
|
|
|