代码修改

release
xuliangwei 2 years ago
parent 883931566d
commit bd39d859e4
  1. 72
      dxhy-erp/src/main/java/com/dxhy/erp/service/impl/RequestRecordServiceImpl.java

@ -15,8 +15,6 @@ import com.dxhy.erp.service.RequestRecordService;
import com.dxhy.erp.service.SNPushCheckRecordService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
@ -24,7 +22,10 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
@Slf4j
@Service
@ -46,7 +47,7 @@ public class RequestRecordServiceImpl extends MpBaseServiceImpl<RequestRecordDao
record.setFailedTimes(0);
record.setStatus(0);
record.setResponseDetail(responseDetail);
log.info("接口调用记录正在保存,调用记录详情:{}",JSONObject.toJSONString(record));
log.info("接口调用记录正在保存,调用记录详情:{}", JSONObject.toJSONString(record));
int insert = requestRecordDao.insert(record);
return insert;
}
@ -59,7 +60,7 @@ public class RequestRecordServiceImpl extends MpBaseServiceImpl<RequestRecordDao
record.setResponseDetail(responseDetail);
record.setFailedReason(failedReason);
record.setIsRecall(isRecall);
log.info("接口调用记录正在保存,调用记录详情:{}",JSONObject.toJSONString(record));
log.info("接口调用记录正在保存,调用记录详情:{}", JSONObject.toJSONString(record));
int insert = requestRecordDao.insert(record);
return insert;
}
@ -69,7 +70,7 @@ public class RequestRecordServiceImpl extends MpBaseServiceImpl<RequestRecordDao
public List<RequestRecord> getRecordList(String portName, Date startTime, Date endTime, Integer status, String methodName, Integer pageNumber, Integer PageSize) {
PageHelper.startPage(pageNumber, PageSize);
List<RequestRecord> recordList = requestRecordDao.selectRecordList(portName, startTime, endTime, status, methodName);
log.info("查询结果:{}",JSONObject.toJSONString(recordList));
log.info("查询结果:{}", JSONObject.toJSONString(recordList));
return recordList;
}
@ -110,7 +111,7 @@ public class RequestRecordServiceImpl extends MpBaseServiceImpl<RequestRecordDao
@Override
public ResponseEntity<?> reCall(RequestRecord requestRecord) {
try {
DynamicContextHolder.push(dbname+DbConstant.BUSINESS_READ);
DynamicContextHolder.push(dbname + DbConstant.BUSINESS_READ);
RequestRecord dbRecord = requestRecordDao.selectById(requestRecord.getId());
log.info("数据库匹配信息:{}", JSONObject.toJSONString(dbRecord));
if (dbRecord == null) {
@ -124,30 +125,30 @@ public class RequestRecordServiceImpl extends MpBaseServiceImpl<RequestRecordDao
}
RequestRecordEnum[] RequestRecordEnums = RequestRecordEnum.values();
log.info("获取到的枚举类型:{}",JSONObject.toJSONString(RequestRecordEnums));
log.info("获取到的枚举类型:{}", JSONObject.toJSONString(RequestRecordEnums));
for (RequestRecordEnum recordenum : RequestRecordEnums) {
if (recordenum.getMethodName().equals(dbRecord.getActiveCall())) {
log.info("通过反射获取到的snPushCheckRecordService是否为空:{}",JSONObject.toJSONString(snPushCheckRecordService == null));
Method method = ReflectUtil.getMethodByName(snPushCheckRecordService.getClass(),recordenum.getMethodName());
log.info("通过反射获取到的方法是否为空:{}",JSONObject.toJSONString(method == null));
log.info("通过反射获取到的snPushCheckRecordService是否为空:{}", JSONObject.toJSONString(snPushCheckRecordService == null));
Method method = ReflectUtil.getMethodByName(snPushCheckRecordService.getClass(), recordenum.getMethodName());
log.info("通过反射获取到的方法是否为空:{}", JSONObject.toJSONString(method == null));
if (method != null) {
log.info("通过反射获取到的方法名:{}",JSONObject.toJSONString(method.getName()));
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);
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)])));
arglist.forEach(strArg -> args.add(JSONObject.parseObject(strArg, recordenum.getArgClass()[arglist.indexOf(strArg)])));
invokeResponse = method.invoke(snPushCheckRecordService, args.toArray());
log.info("重调后得到的结果:{}",JSONObject.toJSONString(invokeResponse));
log.info("重调后得到的结果:{}", JSONObject.toJSONString(invokeResponse));
JSONObject rspJson = JSONObject.parseObject(invokeResponse.toString(), JSONObject.class);
log.info("重调后返回信息:{}",rspJson);
log.info("重调后返回信息:{}", rspJson);
data.put("data", invokeResponse);
@ -169,13 +170,13 @@ public class RequestRecordServiceImpl extends MpBaseServiceImpl<RequestRecordDao
updateSuccessfulRecallRecord(dbRecord, 0, JSONObject.toJSONString(rspJson), JSONObject.toJSONString(data));
return ResponseEntity.ok(JSONObject.toJSONString(data));
}catch (Exception e) {
log.error("重调出现异常,异常信息:{}",e.getMessage());
} catch (Exception e) {
log.error("重调出现异常,异常信息:{}", e.getMessage());
try {
updateFailedRecallRecord(dbRecord, 1, JSONObject.toJSONString(invokeResponse),
JSONObject.toJSONString(data), "重调用出现异常:"+JSONObject.toJSONString(e.getMessage()), 0);
JSONObject.toJSONString(data), "重调用出现异常:" + JSONObject.toJSONString(e.getMessage()), 0);
} catch (Exception exception) {
log.error("接口重调用保存异常:{}",exception.getMessage());
log.error("接口重调用保存异常:{}", exception.getMessage());
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_DEFAULT)));
}
@ -213,36 +214,19 @@ public class RequestRecordServiceImpl extends MpBaseServiceImpl<RequestRecordDao
}
private void setResponse(RequestRecord record, String activeCallRecallResponse, String recallResponseDetail) {
HashMap<String, String> activeCallrecallMap = JSONObject.parseObject(record.getRecallResponseDetail(),HashMap.class);
HashMap<String, String> reCallMap = JSONObject.parseObject(record.getRecallResponseDetail(),HashMap.class);
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 HashMap<>();
reCallMap = new HashMap<>();
activeCallrecallMap = new LinkedHashMap<>();
reCallMap = new LinkedHashMap<>();
activeCallrecallMap.put("第1次主动调用重调返回结果", activeCallRecallResponse);
activeCallrecallMap.put("第1次重调返回结果", recallResponseDetail);
} else {
reCallMap.put("第"+ record.getRetryTimes() + 1+"次重调结果", recallResponseDetail);
activeCallrecallMap.put("第"+ record.getRetryTimes() + 1+"次主动调用重调结果", activeCallRecallResponse);
reCallMap.put("第" + (record.getRetryTimes() + 1) + "次重调结果", recallResponseDetail);
activeCallrecallMap.put("第" + (record.getRetryTimes() + 1) + "次主动调用重调结果", activeCallRecallResponse);
}
record.setActiveCallRecallResponse(JSONObject.toJSONString(activeCallrecallMap));
record.setRecallResponseDetail(JSONObject.toJSONString(reCallMap));
}
// @Override
// @DataSource(name = "business_business_write")
// @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = BaseException.class)
// public int saveTestRequestRecord(RequestRecord record, Integer isRecall, String responseDetail, String failedReason) throws BaseException{
// 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);
// throw new BaseException("测试用");
// }
}

Loading…
Cancel
Save