Merge remote-tracking branch 'origin/0714-新增接口记录补偿' into release

# Conflicts:
#	dxhy-erp/src/main/java/com/dxhy/erp/controller/InterfaceController.java
#	dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java
release
WangQi 2 years ago
commit 0aaf2d9bad
  1. 45
      dxhy-erp/src/main/java/com/dxhy/erp/controller/InterfaceController.java
  2. 55
      dxhy-erp/src/main/java/com/dxhy/erp/controller/RequestRecallController.java
  3. 180
      dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java
  4. 13
      dxhy-erp/src/main/java/com/dxhy/erp/dao/RequestRecordDao.java
  5. 23
      dxhy-erp/src/main/java/com/dxhy/erp/entity/BaseRequestRecordVO.java
  6. 22
      dxhy-erp/src/main/java/com/dxhy/erp/entity/RequestRecord.java
  7. 64
      dxhy-erp/src/main/java/com/dxhy/erp/enums/RequestRecordEnum.java
  8. 11
      dxhy-erp/src/main/java/com/dxhy/erp/service/RequestRecordService.java
  9. 197
      dxhy-erp/src/main/java/com/dxhy/erp/service/impl/RequestRecordServiceImpl.java
  10. 64
      dxhy-erp/src/main/resources/mapper/RequestRecordMapper.xml

@ -1223,13 +1223,13 @@ public class InterfaceController extends AbstractController {
try {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
if (esOutPutResp.getZMESSAGE().contains("不存在")) {
requestRecordService.saveRecord(receiveErpInvoiceMessageRecord, 1,1, JsonUtils.getInstance().toJsonString(outPut),0);
requestRecordService.saveFailedRequestRecord(receiveErpInvoiceMessageRecord, 0, JsonUtils.getInstance().toJsonString(outPut),
esOutPutResp.getZMESSAGE());
} else {
requestRecordService.saveRecord(receiveErpInvoiceMessageRecord, 0,0, JsonUtils.getInstance().toJsonString(outPut));
requestRecordService.saveSuccessfulRequestRecord(receiveErpInvoiceMessageRecord, JsonUtils.getInstance().toJsonString(outPut));
}
} catch (Exception e) {
log.error("FI847接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("FI847接口记录保存失败,errormsg:{}",e);
}
return JsonUtils.getInstance().toJsonString(outPut);
@ -1242,11 +1242,13 @@ public class InterfaceController extends AbstractController {
esOutPutResp.setZTYPE("E");
esOutPutResp.setZMESSAGE("程序内部错误");
outPut.setES_OUTPUT(esOutPutResp);
try {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveRecord(receiveErpInvoiceMessageRecord, 1,1, JsonUtils.getInstance().toJsonString(outPut), 1);
}catch (Exception e1) {
log.error("errorMsg", e);
requestRecordService.saveFailedRequestRecord(receiveErpInvoiceMessageRecord, 1, JsonUtils.getInstance().toJsonString(outPut),
"FI847接口接收erp发票数据出错,异常信息:"+"{"+JSONObject.toJSONString(e)+"}");
} catch (Exception exception) {
log.error("FI847接口记录保存失败,errormsg:{}",e);
}
return JsonUtils.getInstance().toJsonString(outPut);
@ -1260,14 +1262,20 @@ public class InterfaceController extends AbstractController {
List<String> fpdms = new ArrayList<>();
List<String> fphms = new ArrayList<>();
List<String> bzdhs = new ArrayList<>();
for (Map<String ,Object> map:list) {
String invoiceCode =(String) map.get("ZFPDM");
String invoiceNo = (String)map.get("ZFPHM");
String bzdh = map.get("ZBZDH")==null?"":map.get("ZBZDH").toString();
fpdms.add(invoiceCode);
fphms.add(invoiceNo);
bzdhs.add(bzdh);
}
log.info("进项税转出(FI849)接收到的发票号码为:{}\n进项税转出(FI849)接收到的发票代码为:{}\n进项税转出(FI849)接收到的报账单号为:{}\n",
JSONObject.toJSONString(fphms),JSONObject.toJSONString(fpdms),JSONObject.toJSONString(bzdhs));
RequestRecord transferOutRecord =requestRecordService.getBaseRequestRecord(JSONObject.toJSONString(erpInvoiceData),
"/po", JSONObject.toJSONString(fpdms),JSONObject.toJSONString(fphms), "transferOut");
transferOutRecord.setBzdh(JSONObject.toJSONString(bzdhs));
for(Map<String ,Object> map:list){
String invoiceCode =(String) map.get("ZFPDM");
@ -1288,10 +1296,11 @@ public class InterfaceController extends AbstractController {
outPut.setES_OUTPUT(es);
try {
requestRecordService.saveRecord(transferOutRecord, 1, 1, JsonUtils.getInstance().toJsonString(outPut), 0);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(transferOutRecord, 0, JsonUtils.getInstance().toJsonString(outPut),
es.getZMESSAGE());
} catch (Exception e) {
log.error("FI849接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("FI849接口记录保存失败,errormsg:{}",e);
}
return JsonUtils.getInstance().toJsonString(outPut);
@ -1340,15 +1349,15 @@ public class InterfaceController extends AbstractController {
}
try {
requestRecordService.saveRecord(transferOutRecord,0, 0, transfer);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveSuccessfulRequestRecord(transferOutRecord, transfer);
} catch (Exception e) {
log.error("FI849接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("FI849接口记录保存失败,errormsg:{}",e);
}
return transfer;
}catch (Exception e){
e.printStackTrace();
log.error("error", e);
OutPut outPut = new OutPut();
EsOutPutResp es = new EsOutPutResp();
es.setSAPKEY(erpInvoiceData.getIS_INPUT().getSAPKEY());
@ -1357,7 +1366,13 @@ public class InterfaceController extends AbstractController {
es.setZMESSAGE("系统内部错误");
outPut.setES_OUTPUT(es);
requestRecordService.saveRecord(transferOutRecord,1, 1, JsonUtils.getInstance().toJsonString(outPut), 1);
try {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(transferOutRecord,1, JsonUtils.getInstance().toJsonString(outPut),
"进项税转出(FI849)处理出现异常,异常信息:"+"{"+JSONObject.toJSONString(e)+"}");
} catch (Exception exception) {
log.error("FI849接口记录保存失败,errormsg:{}",e);
}
return JsonUtils.getInstance().toJsonString(outPut);
}

@ -1,13 +1,66 @@
package com.dxhy.erp.controller;
import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.util.DateTimeHelper;
import com.dxhy.common.utils.R;
import com.dxhy.erp.entity.RequestRecord;
import com.dxhy.erp.service.RequestRecordService;
import com.dxhy.erp.utils.DateUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;
@SuppressWarnings("AlibabaMethodTooLong")
@RequestMapping("/recall")
@RestController
public class RequestRecallController {
@Slf4j
public class RequestRecallController extends AbstractController {
@Resource
RequestRecordService requestRecordService;
@ApiOperation(value = "重调接口入口", notes = "重调接口入口")
@RequestMapping(path = "/requestRecordRecall", method = {RequestMethod.POST})
public ResponseEntity<?> recall(@RequestBody RequestRecord requestRecord) {
log.info("重调用接口调用开始");
log.info("重调用接口入参:{}", JSONObject.toJSONString(requestRecord));
ResponseEntity responseEntity = requestRecordService.reCall(requestRecord);
log.info("重调用接口调用结束,返回参数:{}", JSONObject.toJSONString(responseEntity));
return responseEntity;
}
@ApiOperation(value = "接口记录查询", notes = "接口记录查询")
@RequestMapping(path = "/requestRecordBatch", method = {RequestMethod.POST})
public ResponseEntity<?> batchRequestRecord(@RequestBody Map<String, Object> params) {
String portName = (String) params.get("portName");
String startTime = (String) params.get("startTime");
String endTime = (String) params.get("endTime");
Integer status = (Integer) params.get("status");
String methodName = (String) params.get("methodName");
Integer pageNumber = (Integer) params.get("pageNumber");
Integer pageSize = (Integer) params.get("pageSize");
Integer orderBy = (Integer) params.get("orderBy");
JSONObject resultJson = requestRecordService.getRecordList(portName, DateUtil.strToDate(startTime),
DateUtil.strToDate(endTime), status, methodName, pageNumber, pageSize, orderBy);
return ResponseEntity.ok(R.ok().put("data",resultJson));
}
@ApiOperation(value = "接口记录详细查询", notes = "接口记录详细查询")
@RequestMapping(path = "/requestDetailRecordBatch", method = {RequestMethod.POST, RequestMethod.GET})
public ResponseEntity<?> batchRequestDetailRecord(@RequestBody Long id) {
JSONObject resultJson = requestRecordService.getDetailRecord(id);
return ResponseEntity.ok(R.ok().put("data",resultJson));
}
}

@ -11,6 +11,7 @@ import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.enums.SNFplxEnum;
import com.dxhy.common.exception.BaseException;
import com.dxhy.common.util.InvoiceUtil;
import com.dxhy.common.utils.Base64Encoding;
import com.dxhy.common.utils.R;
@ -135,10 +136,10 @@ public class SDNYMainProcessController extends AbstractController {
data.put("data", checkInvoiceResult);
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord, 0,0, JSONObject.toJSONString(data));
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveSuccessfulRequestRecord(singleInvoiceCheckRecord, JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
@ -154,10 +155,10 @@ public class SDNYMainProcessController extends AbstractController {
if (StringUtils.isBlank(pramsMap.get("invoiceNumber"))) {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("发票号码不能为空!")),0);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,JSONObject.toJSONString(R.error("发票号码不能为空!")), "发票号码不能为空!");
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error("发票号码不能为空!")));
@ -173,10 +174,11 @@ public class SDNYMainProcessController extends AbstractController {
} else {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("开票日期不能为空!")), 0);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,
JSONObject.toJSONString(R.error("开票日期不能为空!")), "开票日期不能为空!");
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error("开票日期不能为空!")));
@ -185,10 +187,11 @@ public class SDNYMainProcessController extends AbstractController {
if (StringUtils.isBlank(pramsMap.get("invoiceType"))) {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("发票类型不能为空!")), 0);
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,
JSONObject.toJSONString(R.error("发票类型不能为空!")), "发票类型不能为空!");
} catch (BaseException e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error("发票类型不能为空!")));
@ -203,10 +206,11 @@ public class SDNYMainProcessController extends AbstractController {
if (StringUtils.isBlank(pramsMap.get("totalAmount"))) {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("金额不能为空!")), 0);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,
JSONObject.toJSONString(R.error("金额不能为空!")), "金额不能为空!");
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error("金额不能为空!")));
@ -215,10 +219,11 @@ public class SDNYMainProcessController extends AbstractController {
if (StringUtils.isBlank(pramsMap.get("checkCode"))) {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("校验码不能为空!")), 0);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,
JSONObject.toJSONString(R.error("校验码不能为空!")), "校验码不能为空!");
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error("校验码不能为空!")));
@ -237,10 +242,11 @@ public class SDNYMainProcessController extends AbstractController {
if (notes != null) {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error(notes)), 0);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,
JSONObject.toJSONString(R.error(notes)), notes);
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error(notes)));
@ -274,6 +280,7 @@ public class SDNYMainProcessController extends AbstractController {
List<String> activeCallRequest = new ArrayList<>();
activeCallRequest.add(JSONObject.toJSONString(pramsMap));
activeCallRequest.add(JSONObject.toJSONString(null));
singleInvoiceCheckRecord.setActiveCallRequestDetail(JSONObject.toJSONString(activeCallRequest));
singleInvoiceCheckRecord.setActiveCall("singleCheckInvoice");
singleInvoiceCheckRecord.setActiveCallResponse(JSONObject.toJSONString(checkInvoiceResult));
@ -298,18 +305,23 @@ public class SDNYMainProcessController extends AbstractController {
// saveCheckLog(pramsMap, checkInvoice);
try {
if (checkInvoiceResult!=null && checkInvoiceResult.containsKey("code")) {
if (checkInvoiceResult.containsKey("cyjg")) {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(data), 0);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
if (checkInvoiceResult != null) {
if (checkInvoiceResult.containsKey("code")) {
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord, 0,JSONObject.toJSONString(data),
(String) checkInvoiceResult.get("message"));
}
if (checkInvoiceResult.containsKey("cyjg") && !"0001".equals(checkInvoiceResult.getString("cyjg"))) {
log.info("进项票池已存在发票,查验结果:{}",JSONObject.toJSON(checkInvoiceResult));
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord, 0,JSONObject.toJSONString(data),
(String) checkInvoiceResult.get("cyjgxx"));
}
} else {
requestRecordService.saveRecord(singleInvoiceCheckRecord,0,0,JSONObject.toJSONString(data));
requestRecordService.saveSuccessfulRequestRecord(singleInvoiceCheckRecord,JSONObject.toJSONString(data));
}
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(data));
@ -337,10 +349,10 @@ public class SDNYMainProcessController extends AbstractController {
// saveCheckLog(pramsMap,checkInvoice);
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,0,0,JSONObject.toJSONString(data));
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveSuccessfulRequestRecord(singleInvoiceCheckRecord, JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(data));
@ -350,6 +362,11 @@ public class SDNYMainProcessController extends AbstractController {
try {
checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap,"1");
List<String> activeCallRequest = new ArrayList<>();
activeCallRequest.add(JSONObject.toJSONString(pramsMap));
activeCallRequest.add(JSONObject.toJSONString("1"));
singleInvoiceCheckRecord.setActiveCallRequestDetail(JSONObject.toJSONString(activeCallRequest));
singleInvoiceCheckRecord.setActiveCall("singleCheckInvoice");
singleInvoiceCheckRecord.setActiveCallResponse(JSONObject.toJSONString(checkInvoiceResult));
@ -359,10 +376,11 @@ public class SDNYMainProcessController extends AbstractController {
log.error("查验失败,errormsg:{}",e.getMessage());
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("查验失败,"+e.getMessage())), 1);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,1,JSONObject.toJSONString(R.error("查验失败,"+e.getMessage())),
"查验失败,异常信息:{}"+JSONObject.toJSONString(e.getMessage()));
} catch (Exception exception) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
exception.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error("查验失败,"+e.getMessage())));
@ -375,10 +393,11 @@ public class SDNYMainProcessController extends AbstractController {
data = errorInfo(checkInvoiceResult, data);
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(data), 0);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord, 0,JSONObject.toJSONString(data),
(String) checkInvoiceResult.get("cyjgxx"));
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(data));
@ -395,10 +414,10 @@ public class SDNYMainProcessController extends AbstractController {
signSaveInvoiceInfoService.saveQueryInvoiceResult(checkInvoiceResult, userid, "1", dbName);
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,0,0,JSONObject.toJSONString(data));
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveSuccessfulRequestRecord(singleInvoiceCheckRecord,JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
}
@ -433,10 +452,10 @@ public class SDNYMainProcessController extends AbstractController {
}
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,0,0,JSONObject.toJSONString(data));
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveSuccessfulRequestRecord(singleInvoiceCheckRecord,JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(data));
@ -444,10 +463,11 @@ public class SDNYMainProcessController extends AbstractController {
}
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error().put("data", checkInvoiceResult)),0);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,JSONObject.toJSONString(R.error().put("data", checkInvoiceResult)),
"未知异常,请联系管理员");
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票查验接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error().put("data", checkInvoiceResult)));
@ -693,13 +713,13 @@ public class SDNYMainProcessController extends AbstractController {
List<String> invoiceNos = new ArrayList<>();
RequestRecord record=null;
if (snRequestObject.getInvoiceInfoList()!=null && snRequestObject.getInvoiceInfoList().size()>0) {
log.info("影像系统同步数据的发票号码为:{}", JSONObject.toJSONString(invoiceNos));
log.info("影像系统同步数据的发票代码为:{}", JSONObject.toJSONString(invoiceCodes));
snRequestObject.getInvoiceInfoList().stream().forEach(invoiceInfo->{
invoiceCodes.add(invoiceInfo.getInvoiceCode());
invoiceNos.add(invoiceInfo.getInvoiceNumber());
});
if (invoiceCodes.get(0)!=null) {
log.info("影像系统同步数据的发票号码为:{}", JSONObject.toJSONString(invoiceNos));
log.info("影像系统同步数据的发票代码为:{}", JSONObject.toJSONString(invoiceCodes));
if (invoiceCodes.size()>0) {
record = requestRecordService.getBaseRequestRecord(JSONObject.toJSONString(snRequestObject),
"/syncInvoiceInfo",
JSONObject.toJSONString(invoiceCodes),
@ -782,10 +802,10 @@ public class SDNYMainProcessController extends AbstractController {
data.put("data", result);
try {
requestRecordService.saveRecord(record,0, 0, JSONObject.toJSONString(R.error(result)));
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(record,0, JSONObject.toJSONString(R.error(result)), result);
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票同步接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error(result)));
@ -800,12 +820,10 @@ public class SDNYMainProcessController extends AbstractController {
JSONObject request = new JSONObject();
request.put("IS_INPUT", object);
// RequestRecord pushCheckResultToSAPRecord =requestRecordService.getBaseRequestRecord(request.toJSONString(),
// "/syncInvoiceInfo",
// JSONObject.toJSONString(invoiceCodes),
// JSONObject.toJSONString(invoiceNos),
// "pushCheckResultToSAP", 1);
try {
List<String> requestList = new ArrayList<>();
requestList.add(request.toJSONString());
record.setActiveCallRequestDetail(JSONObject.toJSONString(requestList));
record.setActiveCall("pushCheckResultToSAP");
//将信息推送到影像系统
result = snPushCheckRecordService.pushCheckResultToSAP(request.toJSONString());
@ -816,10 +834,10 @@ public class SDNYMainProcessController extends AbstractController {
data.put("data", result);
try {
requestRecordService.saveRecord(record,0, 0, JSONObject.toJSONString(data));
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveSuccessfulRequestRecord(record, JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票同步接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(data));
@ -829,10 +847,11 @@ public class SDNYMainProcessController extends AbstractController {
// requestRecordService.saveRecord(pushCheckResultToSAPRecord,1, 1, JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_PUSH_SDNY)), 1);
try {
requestRecordService.saveRecord(record,1, 1, JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_PUSH_SDNY)), 1);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(record,1, JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_PUSH_SDNY)),
"推送sap失败,失败原因:"+"{"+JSONObject.toJSONString(e)+"}");
} catch (Exception exception) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
exception.printStackTrace();
log.error("发票同步接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_PUSH_SDNY)));
@ -856,10 +875,10 @@ public class SDNYMainProcessController extends AbstractController {
data.put("data", "");
try {
requestRecordService.saveRecord(record,0, 0, JSONObject.toJSONString(data));
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveSuccessfulRequestRecord(record, JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票同步接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(data));
@ -881,10 +900,10 @@ public class SDNYMainProcessController extends AbstractController {
data.put("data", "");
try {
requestRecordService.saveRecord(record,0, 0, JSONObject.toJSONString(data));
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveSuccessfulRequestRecord(record, JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票同步接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(data));
@ -896,10 +915,11 @@ public class SDNYMainProcessController extends AbstractController {
exception.printStackTrace();
try {
requestRecordService.saveRecord(record,1, 1, JSONObject.toJSONString(R.error(CommonConstants.CONNECT_TIMEOUT)),1);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(record,1, JSONObject.toJSONString(R.error(CommonConstants.CONNECT_TIMEOUT)),
"同步SAP失败,报错信息为:"+"{"+JSONObject.toJSONString(exception)+"}");
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票同步接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error(CommonConstants.CONNECT_TIMEOUT)));
@ -908,10 +928,11 @@ public class SDNYMainProcessController extends AbstractController {
exception.printStackTrace();
try {
requestRecordService.saveRecord(record,1, 1, JSONObject.toJSONString(R.error(CommonConstants.NULL_POINTER_TIMEOUT)), 1);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(record,1, JSONObject.toJSONString(R.error(CommonConstants.NULL_POINTER_TIMEOUT)),
"同步SAP失败,报错信息为:"+"{"+JSONObject.toJSONString(exception)+"}");
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票同步接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error(CommonConstants.NULL_POINTER_TIMEOUT)));
@ -920,10 +941,11 @@ public class SDNYMainProcessController extends AbstractController {
exception.printStackTrace();
try {
requestRecordService.saveRecord(record,1, 1, JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_DEFAULT)),1);
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(record,1, JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_DEFAULT)),
"同步SAP失败,报错信息为:"+"{"+JSONObject.toJSONString(exception)+"}");
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
log.error("发票同步接口记录保存失败,errormsg:{}",e);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_DEFAULT)));

@ -1,6 +1,7 @@
package com.dxhy.erp.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dxhy.erp.entity.BaseRequestRecordVO;
import com.dxhy.erp.entity.RequestRecord;
import com.dxhy.erp.entity.TdxRecordInvoiceStatistics;
import org.apache.ibatis.annotations.Mapper;
@ -21,9 +22,17 @@ public interface RequestRecordDao extends BaseMapper<RequestRecord> {
* @param methodName 方法名
* @return
*/
List<RequestRecord> selectRecordList(@Param("portName") String portName,
List<BaseRequestRecordVO> selectRecordList(@Param("portName") String portName,
@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("status") Integer status,
@Param("methodName") String methodName);
@Param("methodName") String methodName,
@Param("orderBy") Integer orderBy);
/**
* 查询记录详情
* @param id
* @return
*/
RequestRecord selectDetailRecord(Long id);
}

@ -0,0 +1,23 @@
package com.dxhy.erp.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseRequestRecordVO {
private Long id;
private String requestDetail;
private String responseDetail;
private String portName;
private Integer retryTimes;
private Integer failedTimes;
private Date createTime;
private Integer status;
private String methodName;
}

@ -105,10 +105,22 @@ public class RequestRecord {
private String activeCall;
/**
* 失败原因0参数校验未通过1其他原因
* 主动调用其它系统的接口参数
*/
@TableField("active_call_request_detail")
private String activeCallRequestDetail;
/**
* 失败原因
*/
@TableField("failed_reason")
private Integer failedReason;
private String failedReason;
/**
* 是否可重调0不可重调1可重调
*/
@TableField("is_recall")
private Integer isRecall;
/**
* 重调用后的返回参数
@ -122,4 +134,10 @@ public class RequestRecord {
@TableField("active_call_response")
private String activeCallResponse;
/**
* 主动调用其它系统的返回参数重调用
*/
@TableField("active_call_recall_response")
private String activeCallRecallResponse;
}

@ -1,44 +1,50 @@
package com.dxhy.erp.enums;
import com.dxhy.erp.controller.InterfaceController;
import com.dxhy.erp.controller.SDNYMainProcessController;
import com.dxhy.erp.service.SNPushCheckRecordService;
import com.alibaba.fastjson.JSONObject;
import com.dxhy.erp.entity.sdny.SNRequestObject;
import org.springframework.http.ResponseEntity;
import java.util.Map;
public enum RequestRecordEnum {
SYNC_INVOICE_INFO("/syncInvoiceInfo", "syncInvoiceInfo", SDNYMainProcessController.class),
SYNC_INVOICE_INFO("/sn/syncInvoiceInfo", "syncInvoiceInfo", ResponseEntity.class,"SDNYMainProcessController", Map.class),
SINGLE_INVOICE_CHECK("/singleInvoiceCheck", "singleInvoiceCheck", SDNYMainProcessController.class),
SINGLE_INVOICE_CHECK("/sn/singleInvoiceCheck", "singleInvoiceCheck", ResponseEntity.class, "SDNYMainProcessController", SNRequestObject.class),
RECEIVE_ERP_INVOICE_MESSAGE("/po", "receiveErpInvoiceMessage", InterfaceController.class),
SINGLE_CHECK_INVOICE("singleCheckInvoice", JSONObject.class, "SNPushCheckRecordService", Map.class, String.class),
TRANSFER_OUT("/po", "transferOut", InterfaceController.class),
INSERT_VOUNCHER_RECORD("/po", "insertVouncherRecord", InterfaceController.class),
PUSH_CHECK_RESULT_TO_SAP("pushCheckResultToSAP", SNPushCheckRecordService.class, String.class),
SING_CHECK_INVOICE("singleCheckInvoice",SNPushCheckRecordService.class, Map.class);
PUSH_CHECK_RESULT_TO_SAP("pushCheckResultToSAP", String.class, "SNPushCheckRecordService", String.class);
private String className;
private String portName;
private String methodName;
private Class<?> argClass;
private Class<?> controllerName;
private Class<?>[] argClass;
private Class<?> responseEntityClass;
RequestRecordEnum(String portName, String methodName, Class<?> controllerClass) {
RequestRecordEnum(String portName, String methodName, Class<?> responseEntityClass, String className, Class<?>... argClass) {
this.className = className;
this.portName = portName;
this.methodName = methodName;
this.controllerName = controllerClass;
this.argClass = argClass;
this.responseEntityClass = responseEntityClass;
}
RequestRecordEnum(String methodName, Class<?> controllerClass, Class<?> argClass) {
RequestRecordEnum(String methodName, Class<?> responseEntityClass, String className, Class<?>... argClass) {
this.className = className;
this.methodName = methodName;
this.controllerName = controllerClass;
this.argClass = argClass;
this.responseEntityClass = responseEntityClass;
}
public void setResponseEntityClass(Class<?> responseEntityClass) {
this.responseEntityClass = responseEntityClass;
}
public Class<?> getResponseEntityClass() {
return responseEntityClass;
}
public void setPortName(String portName) {
@ -49,10 +55,6 @@ public enum RequestRecordEnum {
this.methodName = methodName;
}
public void setControllerName(Class<?> controllerName) {
this.controllerName = controllerName;
}
public String getPortName() {
return portName;
}
@ -61,15 +63,19 @@ public enum RequestRecordEnum {
return methodName;
}
public Class<?> getControllerName() {
return controllerName;
}
public Class<?> getArgClass() {
public Class<?>[] getArgClass() {
return argClass;
}
public void setArgClass(Class<?> argClass) {
public void setArgClass(Class<?>[] argClass) {
this.argClass = argClass;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
}

@ -1,17 +1,21 @@
package com.dxhy.erp.service;
import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.service.MpBaseService;
import com.dxhy.erp.entity.RequestRecord;
import org.springframework.http.ResponseEntity;
import java.util.Date;
import java.util.List;
public interface RequestRecordService extends MpBaseService<RequestRecord> {
int saveRecord(RequestRecord requestRecord,Integer failedTimes, Integer status, String responseDetail,Integer... failedReason);
int saveSuccessfulRequestRecord(RequestRecord record, String responseDetail);
List<RequestRecord> getRecordList(String portName, Date startTime, Date endTime, Integer status, String methodName, Integer pageNumber, Integer PageSize);
int saveFailedRequestRecord(RequestRecord record, Integer isRecall, String responseDetail, String failedReason);
JSONObject getRecordList(String portName, Date startTime, Date endTime, Integer status, String methodName, Integer pageNumber, Integer PageSize, Integer orderBy);
JSONObject getDetailRecord(Long id);
RequestRecord getBaseRequestRecord(String requestDetail, String portName, String invoiceCode, String invoiceNo, String methodName);
@ -20,4 +24,5 @@ public interface RequestRecordService extends MpBaseService<RequestRecord> {
RequestRecord getBaseRequestRecord(String requestDetail, String portName, String invoiceNo, String methodName);
ResponseEntity<?> reCall(RequestRecord requestRecord);
}

@ -2,16 +2,20 @@ package com.dxhy.erp.service.impl;
import cn.hutool.core.util.ReflectUtil;
import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.constant.CommonConstants;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.annotation.DataSource;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.common.utils.R;
import com.dxhy.erp.dao.RequestRecordDao;
import com.dxhy.erp.entity.BaseRequestRecordVO;
import com.dxhy.erp.entity.RequestRecord;
import com.dxhy.erp.enums.RequestRecordEnum;
import com.dxhy.erp.service.RequestRecordService;
import com.dxhy.erp.service.SNPushCheckRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@ -20,42 +24,85 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
@Slf4j
@Service
public class RequestRecordServiceImpl extends MpBaseServiceImpl<RequestRecordDao, RequestRecord> implements RequestRecordService {
private final Integer MAX_TIMES = 10;
private final String dbname = "business";
@Resource
RequestRecordDao requestRecordDao;
private RequestRecordDao requestRecordDao;
@Resource
private SNPushCheckRecordService snPushCheckRecordService;
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public int saveRecord(RequestRecord record, Integer failedTimes, Integer status, String responseDetail, Integer... failedReason) {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
record.setFailedTimes(failedTimes);
record.setStatus(status);
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public int saveSuccessfulRequestRecord(RequestRecord record, String responseDetail) {
record.setFailedTimes(0);
record.setStatus(0);
record.setResponseDetail(responseDetail);
if (failedReason.length > 0) {
record.setFailedReason(failedReason[0]);
log.info("接口调用记录正在保存,调用记录详情:{}", JSONObject.toJSONString(record));
int insert = requestRecordDao.insert(record);
return insert;
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public int saveFailedRequestRecord(RequestRecord record, Integer isRecall, String responseDetail, String failedReason) {
record.setFailedTimes(1);
record.setStatus(1);
record.setResponseDetail(responseDetail);
record.setFailedReason(failedReason);
record.setIsRecall(isRecall);
log.info("接口调用记录正在保存,调用记录详情:{}", JSONObject.toJSONString(record));
int insert = super.getBaseMapper().insert(record);
int insert = requestRecordDao.insert(record);
return insert;
}
@Override
public List<RequestRecord> getRecordList(String portName, Date startTime, Date endTime, Integer status, String methodName, Integer pageNumber, Integer PageSize) {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
PageHelper.startPage(pageNumber, PageSize);
List<RequestRecord> recordList = requestRecordDao.selectRecordList(portName, startTime, endTime, status, methodName);
return recordList;
@DataSource(name = "business_business_read")
public JSONObject getRecordList(String portName, Date startTime, Date endTime,
Integer status, String methodName, Integer pageNumber, Integer pageSize, Integer orderBy) {
JSONObject json = new JSONObject();
try {
PageHelper.startPage(pageNumber, pageSize);
List<BaseRequestRecordVO> recordList = requestRecordDao.selectRecordList(portName, startTime, endTime, status, methodName, orderBy);
PageInfo<BaseRequestRecordVO> pageInfo = new PageInfo<>(recordList);
json.put("datalist",recordList);
json.put("total",pageInfo.getTotal());
log.info("查询结果:{}", JSONObject.toJSONString(recordList));
return json;
} catch (Exception e) {
log.error("请求出现异常,异常信息:{}",e);
json.put("datalist",null);
return json;
}
}
@Override
@DataSource(name = "business_business_read")
public JSONObject getDetailRecord(Long id) {
log.info("查询的id:{}",id);
JSONObject json = new JSONObject();
try {
RequestRecord detailRecord = requestRecordDao.selectById(id);
log.info("查询结果:{}", JSONObject.toJSONString(detailRecord));
return json;
} catch (Exception e) {
log.error("查询记录详情出现异常,异常信息:{}",e);
json.put("data",null);
return json;
}
}
@Override
@ -91,59 +138,127 @@ public class RequestRecordServiceImpl extends MpBaseServiceImpl<RequestRecordDao
.build();
}
@Override
public ResponseEntity<?> reCall(RequestRecord requestRecord) {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
try {
DynamicContextHolder.push(dbname + DbConstant.BUSINESS_READ);
RequestRecord dbRecord = requestRecordDao.selectById(requestRecord.getId());
if (!dbRecord.getRequestDetail().equals(requestRecord.getRequestDetail())
|| !dbRecord.getResponseDetail().equals(requestRecord.getResponseDetail())
|| !dbRecord.getMethodName().equals(dbRecord.getMethodName())) {
log.info("数据库匹配信息:{}", JSONObject.toJSONString(dbRecord));
if (dbRecord == null) {
return ResponseEntity.ok(JSONObject.toJSONString(R.error("请求信息错误,请确认后再发送!")));
}
if (dbRecord.getFailedReason() == 0) {
return ResponseEntity.ok(JSONObject.toJSONString(R.error("该请求参数不符合标准,无法进行重调,请校验参数后再申请!")));
if (dbRecord.getActiveCall() == null) {
return ResponseEntity.ok(JSONObject.toJSONString(R.error("暂只支持发票系统主动调用外部系统的补偿!")));
}
if (dbRecord.getFailedTimes() > MAX_TIMES) {
return ResponseEntity.ok(JSONObject.toJSONString(R.error("该请求已达到最大重调用次数,无法再重新请求!")));
if (dbRecord.getStatus() == 0) {
return ResponseEntity.ok(JSONObject.toJSONString(R.error("该请求已成功,无法继续重调!")));
}
if (dbRecord.getIsRecall() == 0) {
return ResponseEntity.ok(JSONObject.toJSONString(R.error("该请求参数不符合标准,无法进行重调!")));
}
RequestRecordEnum[] RequestRecordEnums = RequestRecordEnum.values();
log.info("获取到的枚举类型:{}", JSONObject.toJSONString(RequestRecordEnums));
for (RequestRecordEnum recordenum : RequestRecordEnums) {
if (recordenum.getMethodName().equals(dbRecord.getMethodName())) {
if (recordenum.getPortName() == null) {
Method method = ReflectUtil.getMethod(recordenum.getControllerName(), recordenum.getMethodName());
Object invokeResponse;
try {
invokeResponse = method.invoke(snPushCheckRecordService, JSONObject.parseObject(dbRecord.getRequestDetail(), recordenum.getArgClass()));
updateRecord(dbRecord, 1, JSONObject.toJSONString(invokeResponse));
if (recordenum.getMethodName().equals(dbRecord.getActiveCall())) {
Method method = ReflectUtil.getMethodByName(snPushCheckRecordService.getClass(), recordenum.getMethodName());
log.info("通过反射获取到的方法名:{}", JSONObject.toJSONString(method.getName()));
Object invokeResponse = null;
R data = new R(1000, "default success");
try {
DynamicContextHolder.push(dbname + DbConstant.BUSINESS_WRITE);
List<String> arglist = JSONObject.parseObject(dbRecord.getActiveCallRequestDetail(), List.class);
List<Object> args = new ArrayList<>();
arglist.forEach(strArg -> args.add(JSONObject.parseObject(strArg, recordenum.getArgClass()[arglist.indexOf(strArg)])));
invokeResponse = method.invoke(snPushCheckRecordService, args.toArray());
log.info("重调后得到的结果:{}", JSONObject.toJSONString(invokeResponse));
JSONObject rspJson = JSONObject.parseObject(invokeResponse.toString(), JSONObject.class);
data.put("data", invokeResponse);
if (rspJson.containsKey("SAPKEY")) {
if (!rspJson.containsKey("处理成功")) {
updateFailedRecallRecord(dbRecord, 1, JSONObject.toJSONString(rspJson), JSONObject.toJSONString(data), rspJson.getString("ZMESSAGE"), 0);
return ResponseEntity.ok(JSONObject.toJSONString(data));
}
}
if (rspJson.containsKey("code")) {
updateFailedRecallRecord(dbRecord, 1, JSONObject.toJSONString(rspJson), JSONObject.toJSONString(data), rspJson.getString("message"), 0);
return ResponseEntity.ok(JSONObject.toJSONString(data));
} else {
if (rspJson.containsKey("cyjg")) {
updateFailedRecallRecord(dbRecord, 1, JSONObject.toJSONString(rspJson), JSONObject.toJSONString(data), rspJson.getString("cyjgxx"), 0);
return ResponseEntity.ok(JSONObject.toJSONString(data));
}
}
updateSuccessfulRecallRecord(dbRecord, 0, JSONObject.toJSONString(rspJson), JSONObject.toJSONString(data));
return ResponseEntity.ok(JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("重调用失败,错误信息:{}", e);
updateRecord(dbRecord, 1);
e.printStackTrace();
if (recordenum.getMethodName().equals("singleCheckInvoice")) {
return ResponseEntity.ok(JSONObject.toJSONString(R.error("查验失败,错误信息:" + e.getMessage())));
log.error("重调出现异常,异常信息:{}", e);
try {
updateFailedRecallRecord(dbRecord, 1, JSONObject.toJSONString(invokeResponse),
JSONObject.toJSONString(data), "重调用出现异常:" + JSONObject.toJSONString(e.getMessage()), 1);
} catch (Exception exception) {
log.error("接口重调用保存异常:{}", exception);
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error("推送失败,错误信息:" + e.getMessage())));
return ResponseEntity.ok(JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_DEFAULT)));
}
}
}
} catch (Exception e) {
log.info("请求处理异常,异常信息:{}", e);
return ResponseEntity.ok(JSONObject.toJSONString(R.error("请求处理异常,请校正参数!")));
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error("未找到相应信息!")));
return ResponseEntity.ok(JSONObject.toJSONString(R.error("未找到相应信息!")));
}
private int updateSuccessfulRecallRecord(RequestRecord record, Integer status, String activeCallRecallResponse, String recallResponseDetail) {
setResponse(record, activeCallRecallResponse, recallResponseDetail);
record.setLastRetryTime(new Date());
record.setRetryTimes(record.getRetryTimes() + 1);
record.setStatus(status);
record.setIsRecall(0);
return requestRecordDao.updateById(record);
}
private int updateRecord(RequestRecord record, Integer status, String... responseDetail) {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
private int updateFailedRecallRecord(RequestRecord record, Integer status, String activeCallResponse, String recallResponseDetail, String failedReason, Integer isRecall) {
setResponse(record, activeCallResponse, recallResponseDetail);
record.setLastRetryTime(new Date());
record.setRetryTimes(record.getRetryTimes() + 1);
record.setStatus(status);
record.setRecallResponseDetail(responseDetail[0]);
requestRecordDao.updateById(record);
record.setFailedReason(failedReason);
record.setIsRecall(isRecall);
return requestRecordDao.updateById(record);
}
private void setResponse(RequestRecord record, String activeCallRecallResponse, String recallResponseDetail) {
LinkedHashMap<String, String> activeCallrecallMap = JSONObject.parseObject(record.getRecallResponseDetail(), LinkedHashMap.class);
LinkedHashMap<String, String> reCallMap = JSONObject.parseObject(record.getRecallResponseDetail(), LinkedHashMap.class);
if (record.getRetryTimes() == 0) {
activeCallrecallMap = new LinkedHashMap<>();
reCallMap = new LinkedHashMap<>();
activeCallrecallMap.put("第1次主动调用重调返回结果", activeCallRecallResponse);
reCallMap.put("第1次重调返回结果", recallResponseDetail);
log.info("第1次重调返回结果:{}",JSONObject.toJSONString(reCallMap));
} else {
reCallMap.put("第" + (record.getRetryTimes() + 1) + "次重调结果", recallResponseDetail);
activeCallrecallMap.put("第" + (record.getRetryTimes() + 1) + "次主动调用重调结果", activeCallRecallResponse);
}
record.setActiveCallRecallResponse(JSONObject.toJSONString(activeCallrecallMap));
record.setRecallResponseDetail(JSONObject.toJSONString(reCallMap));
}
}

@ -4,7 +4,19 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dxhy.erp.dao.RequestRecordDao">
<resultMap id="BaseResultMap" type="com.dxhy.erp.entity.RequestRecord">
<resultMap id="BaseResultMap" type="com.dxhy.erp.entity.BaseRequestRecordVO">
<id column="id" property="id" />
<result column="request_detail" property="requestDetail" />
<result column="response_detail" property="responseDetail" />
<result column="port_name" property="portName" />
<result column="retry_times" property="retryTimes" />
<result column="failed_times" property="failedTimes" />
<result column="create_time" property="createTime" />
<result column="status" property="status" />
<result column="method_name" property="methodName" />
</resultMap>
<resultMap id="DetailResultMap" type="com.dxhy.erp.entity.RequestRecord">
<id column="id" property="id" />
<result column="bzdh" property="bzdh" />
<result column="invoice_code" property="invoiceCode" />
@ -20,25 +32,25 @@
<result column="status" property="status" />
<result column="method_name" property="methodName" />
<result column="active_call" property="activeCall"/>
<result column="failed_reason" property="failedReason"/>
<result column="recall_response_detail" property="recallResponseDetail"/>
<result column="active_call_response" property="activeCallResponse"/>
<result column="is_recall" property="isRecall"/>
<result column="active_call_recall_response" property="activeCallRecallResponse"/>
<result column="active_call_request_detail" property="activeCallRequestDetail"/>
</resultMap>
<select id="selectRecordList" resultMap="BaseResultMap">
select
id,
bzdh,
invoice_code,
image_id,
invoice_no,
request_detail,
response_detail,
port_name,
retry_times,
failed_times,
create_time,
last_retry_time,
status,
method_name,
active_call from t_dx_erp_request_record
method_name from t_dx_erp_request_record
<where>
<if test="portName!=null and portName!=''">
and port_name=#{portName}
@ -48,7 +60,7 @@
</if>
<if test="endTime!=null and endTime!=''">
<![CDATA[
and create_time<=#{create_time}
and create_time<=#{endTime}
]]>
</if>
<if test="status!=null and status!=''">
@ -58,7 +70,39 @@
and method_name=#{methodName}
</if>
</where>
order by create_time
<if test="orderBy==1">
order by create_time desc
</if>
<if test="orderBy==0">
order by create_time asc
</if>
</select>
<select id="selectDetailRecord" resultMap="DetailResultMap">
select
id,
bzdh,
invoice_code,
image_id,
invoice_no,
request_detail,
response_detail,
port_name,
retry_times,
failed_times,
create_time,
status,
last_retry_time,
method_name,
active_call,
failed_reason,
recall_response_detail,
active_call_response,
is_recall,
active_call_recall_response,
active_call_request_detail
from t_dx_erp_request_record where id = #{id}
</select>
</mapper>
Loading…
Cancel
Save