Browse Source

重试request

master
han\hanst 2 months ago
parent
commit
6af954b2c7
  1. 110
      src/main/java/com/gaotao/modules/api/service/impl/IfsCallErrorLogServiceImpl.java

110
src/main/java/com/gaotao/modules/api/service/impl/IfsCallErrorLogServiceImpl.java

@ -36,7 +36,7 @@ import java.util.Map;
@Service
public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMapper, IfsCallErrorLog>
implements IfsCallErrorLogService {
// IFS配置参数 - rqrq
@Value("${custom.ifs-url}")
private String ifsUrl;
@ -57,11 +57,11 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
String sourceLocation, String destLocation,
BigDecimal qty, Date expiredDate,
String requestData, String responseData, String errorMessage) {
System.out.println("========== IFS错误日志记录开始 ==========");
System.out.println("站点: " + site + ", 接口: " + interfaceName + ", 方法: " + methodType);
System.out.println("物料: " + partNo + ", 批次: " + lotBatchNo);
try {
IfsCallErrorLog errorLog = new IfsCallErrorLog();
errorLog.setSite(site);
@ -80,14 +80,14 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
errorLog.setRetryCount(0);
errorLog.setMaxRetry(3);
errorLog.setCreatedAt(new Date());
this.save(errorLog);
System.out.println("IFS错误日志记录成功,日志ID: " + errorLog.getId());
System.out.println("========== IFS错误日志记录结束 ==========");
return errorLog.getId();
} catch (Exception e) {
log.error("记录IFS错误日志失败: {}", e.getMessage(), e);
System.out.println("IFS错误日志记录失败: " + e.getMessage());
@ -95,52 +95,52 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
return null;
}
}
@Override
public PageUtils queryPage(IfsCallErrorLogData data) throws Exception {
System.out.println("========== IFS错误日志查询开始 ==========");
System.out.println("查询条件 - 站点: " + data.getSite() + ", 状态: " + data.getProcessStatus());
// 构建分页对象 - rqrq
int pageNum = data.getPage() != null ? data.getPage() :
int pageNum = data.getPage() != null ? data.getPage() :
(data.getPageNum() != null ? data.getPageNum() : 1);
int pageSize = data.getLimit() != null ? data.getLimit() :
(data.getPageSize() != null ? data.getPageSize() : 10);
Page<IfsCallErrorLog> page = new Page<>(pageNum, pageSize);
// 构建查询条件 - rqrq
QueryWrapper<IfsCallErrorLog> wrapper = new QueryWrapper<>();
// 站点 - rqrq
if (StringUtils.hasText(data.getSite())) {
wrapper.eq("site", data.getSite());
}
// 接口名称 - rqrq
if (StringUtils.hasText(data.getInterfaceName())) {
wrapper.eq("interface_name", data.getInterfaceName());
}
// 方法类型 - rqrq
if (StringUtils.hasText(data.getMethodType())) {
wrapper.eq("method_type", data.getMethodType());
}
// 物料编号 - rqrq
if (StringUtils.hasText(data.getPartNo())) {
wrapper.like("part_no", data.getPartNo());
}
// 批次号 - rqrq
if (StringUtils.hasText(data.getLotBatchNo())) {
wrapper.like("lot_batch_no", data.getLotBatchNo());
}
// 处理状态 - rqrq
if (StringUtils.hasText(data.getProcessStatus())) {
wrapper.eq("process_status", data.getProcessStatus());
}
// 日期范围 - rqrq
if (data.getStartDate() != null) {
wrapper.ge("created_at", data.getStartDate());
@ -148,25 +148,25 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
if (data.getEndDate() != null) {
wrapper.le("created_at", data.getEndDate());
}
// 按创建时间倒序 - rqrq
wrapper.orderByDesc("created_at");
// 执行分页查询 - rqrq
IPage<IfsCallErrorLog> pageResult = baseMapper.selectPage(page, wrapper);
System.out.println("查询结果总数: " + pageResult.getTotal());
System.out.println("========== IFS错误日志查询结束 ==========");
return new PageUtils(pageResult);
}
@Override
@Transactional
public void markAsProcessed(Long id, String processedBy, String remark) {
System.out.println("========== 标记IFS错误日志为已处理 ==========");
System.out.println("日志ID: " + id + ", 处理人: " + processedBy);
IfsCallErrorLog errorLog = this.getById(id);
if (errorLog != null) {
errorLog.setProcessStatus("PROCESSED");
@ -175,19 +175,19 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
errorLog.setRemark(remark);
errorLog.setUpdatedAt(new Date());
this.updateById(errorLog);
System.out.println("标记成功");
}
System.out.println("========== 标记IFS错误日志结束 ==========");
}
@Override
@Transactional
public void markAsIgnored(Long id, String processedBy, String remark) {
System.out.println("========== 标记IFS错误日志为已忽略 ==========");
System.out.println("日志ID: " + id + ", 处理人: " + processedBy);
IfsCallErrorLog errorLog = this.getById(id);
if (errorLog != null) {
errorLog.setProcessStatus("IGNORED");
@ -196,35 +196,35 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
errorLog.setRemark(remark);
errorLog.setUpdatedAt(new Date());
this.updateById(errorLog);
System.out.println("标记成功");
}
System.out.println("========== 标记IFS错误日志结束 ==========");
}
@Override
@Transactional
public boolean retryIfsCall(Long id, String processedBy) {
System.out.println("========== 手工重试IFS接口调用开始 ==========");
System.out.println("错误日志ID: " + id + ", 操作人: " + processedBy);
// 1. 查询错误日志记录 - rqrq
IfsCallErrorLog errorLog = this.getById(id);
if (errorLog == null) {
System.out.println("错误日志不存在,ID: " + id);
return false;
}
// 2. 检查状态 - rqrq
if (!"PENDING".equals(errorLog.getProcessStatus())) {
System.out.println("错误日志状态不是待处理,无法重试。当前状态: " + errorLog.getProcessStatus());
return false;
}
// 3. 调用IFS接口独立实现不影响原有逻辑- rqrq
boolean success = retryCallIfsInterface(errorLog);
// 4. 更新记录状态 - rqrq
if (success) {
// 成功 - 标记为已处理 - rqrq
@ -234,7 +234,7 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
errorLog.setRemark("手工重试成功");
errorLog.setUpdatedAt(new Date());
this.updateById(errorLog);
System.out.println("IFS接口重试成功");
System.out.println("========== 手工重试IFS接口调用结束 ==========");
return true;
@ -243,7 +243,7 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
Integer currentRetry = errorLog.getRetryCount() != null ? errorLog.getRetryCount() : 0;
errorLog.setRetryCount(currentRetry + 1);
errorLog.setUpdatedAt(new Date());
// 如果重试次数超过最大重试次数自动标记为已忽略 - rqrq
if (errorLog.getRetryCount() >= errorLog.getMaxRetry()) {
errorLog.setProcessStatus("IGNORED");
@ -251,9 +251,9 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
errorLog.setProcessedBy("SYSTEM");
errorLog.setRemark("超过最大重试次数(" + errorLog.getMaxRetry() + "),自动忽略");
}
this.updateById(errorLog);
System.out.println("IFS接口重试失败,重试次数: " + errorLog.getRetryCount());
System.out.println("========== 手工重试IFS接口调用结束 ==========");
return false;
@ -268,7 +268,7 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
errorLog.setProcessedAt(new Date());
this.updateById(errorLog);
}
/**
* @Description 重试调用IFS接口独立方法复制自syncSingleGroupToIFSForPallet不影响原有逻辑- rqrq
* @param errorLog 错误日志
@ -278,10 +278,10 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
*/
private boolean retryCallIfsInterface(IfsCallErrorLog errorLog) {
System.out.println("开始调用IFS接口 - " + errorLog.getInterfaceName());
String jsonBody = null;
String ifsResponse = null;
try {
// 1. 从错误日志中恢复请求参数 - rqrq
// if (errorLog.getRequestData() == null || errorLog.getRequestData().isEmpty()) {
@ -295,13 +295,13 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
params.put("locationNo", errorLog.getSourceLocation());
params.put("destLocationNo", errorLog.getDestLocation());
params.put("lotBatchNo", errorLog.getLotBatchNo());
if (errorLog.getExpiredDate() != null) {
params.put("expiryDate", new SimpleDateFormat("yyyy-MM-dd").format(errorLog.getExpiredDate()));
} else {
params.put("expiryDate", null);
}
ObjectMapper objectMapper = new ObjectMapper();
jsonBody = objectMapper.writeValueAsString(params);
// } else {
@ -310,45 +310,45 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe
// }
//
System.out.println("请求数据: " + jsonBody);
jsonBody = errorLog.getRequestData();
// 2. 调用IFS接口 - rqrq
ifsResponse = HttpUtils.doPost(ifsUrl + errorLog.getInterfaceName(), jsonBody, null);
System.out.println("IFS响应: " + ifsResponse);
// 3. 判断结果 - rqrq
if ("IFSUpdated".equals(ifsResponse) || "\"IFSUpdated\"".equals(ifsResponse)) {
System.out.println("IFS接口调用成功 - 物料: " + errorLog.getPartNo() + ", 批次: " + errorLog.getLotBatchNo());
// 更新响应数据 - rqrq
errorLog.setResponseData(ifsResponse);
errorLog.setErrorMessage("重试成功");
return true;
} else {
// 失败提取错误信息 - rqrq
String errorMessage = IfsErrorMessageUtils.extractOracleErrorMessage(ifsResponse);
System.out.println("IFS接口调用失败 - 响应: " + ifsResponse);
// 更新响应和错误信息 - rqrq
errorLog.setResponseData(ifsResponse);
errorLog.setErrorMessage(errorMessage);
return false;
}
} catch (Exception e) {
System.out.println("IFS接口调用异常: " + e.getMessage());
e.printStackTrace();
// 更新错误信息 - rqrq
errorLog.setResponseData(ifsResponse != null ? ifsResponse : "未收到响应");
errorLog.setErrorMessage("重试异常: " + e.getMessage());
return false;
}
}
/**
* @Description 获取当前用户的域控账号 - rqrq
* @return String

Loading…
Cancel
Save