|
|
|
@ -4,18 +4,27 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.gaotao.common.utils.HttpUtils; |
|
|
|
import com.gaotao.common.utils.IfsErrorMessageUtils; |
|
|
|
import com.gaotao.common.utils.PageUtils; |
|
|
|
import com.gaotao.modules.api.dao.IfsCallErrorLogMapper; |
|
|
|
import com.gaotao.modules.api.entity.IfsCallErrorLog; |
|
|
|
import com.gaotao.modules.api.entity.IfsCallErrorLogData; |
|
|
|
import com.gaotao.modules.api.service.IfsCallErrorLogService; |
|
|
|
import com.gaotao.modules.sys.entity.SysUserEntity; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.shiro.SecurityUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description IFS接口调用错误日志服务实现类 - rqrq |
|
|
|
@ -27,6 +36,19 @@ import java.util.Date; |
|
|
|
public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMapper, IfsCallErrorLog> |
|
|
|
implements IfsCallErrorLogService { |
|
|
|
|
|
|
|
// IFS配置参数 - rqrq |
|
|
|
@Value("${custom.ifs-url}") |
|
|
|
private String ifsUrl; |
|
|
|
|
|
|
|
@Value("${custom.ifs-ifsDBName}") |
|
|
|
private String ifsDBName; |
|
|
|
|
|
|
|
@Value("${custom.ifs-domainUserID}") |
|
|
|
private String domainUserID; |
|
|
|
|
|
|
|
@Value("${ldap-control.control-flag:false}") |
|
|
|
private Boolean ldapFlag; |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(propagation = Propagation.REQUIRES_NEW) |
|
|
|
public Long logIfsError(String site, String interfaceName, String methodType, |
|
|
|
@ -179,4 +201,152 @@ public class IfsCallErrorLogServiceImpl extends ServiceImpl<IfsCallErrorLogMappe |
|
|
|
|
|
|
|
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 |
|
|
|
errorLog.setProcessStatus("PROCESSED"); |
|
|
|
errorLog.setProcessedAt(new Date()); |
|
|
|
errorLog.setProcessedBy(processedBy); |
|
|
|
errorLog.setRemark("手工重试成功"); |
|
|
|
errorLog.setUpdatedAt(new Date()); |
|
|
|
this.updateById(errorLog); |
|
|
|
|
|
|
|
System.out.println("IFS接口重试成功"); |
|
|
|
System.out.println("========== 手工重试IFS接口调用结束 =========="); |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
// 失败 - 增加重试次数 - rqrq |
|
|
|
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"); |
|
|
|
errorLog.setProcessedAt(new Date()); |
|
|
|
errorLog.setProcessedBy("SYSTEM"); |
|
|
|
errorLog.setRemark("超过最大重试次数(" + errorLog.getMaxRetry() + "),自动忽略"); |
|
|
|
} |
|
|
|
|
|
|
|
this.updateById(errorLog); |
|
|
|
|
|
|
|
System.out.println("IFS接口重试失败,重试次数: " + errorLog.getRetryCount()); |
|
|
|
System.out.println("========== 手工重试IFS接口调用结束 =========="); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 重试调用IFS接口(独立方法,复制自syncSingleGroupToIFSForPallet,不影响原有逻辑)- rqrq |
|
|
|
* @param errorLog 错误日志 |
|
|
|
* @return 是否成功 |
|
|
|
* @author rqrq |
|
|
|
* @date 2025/10/08 |
|
|
|
*/ |
|
|
|
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()) { |
|
|
|
// 如果没有保存请求数据,重新构建 - rqrq |
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("ifsDBName", ifsDBName); |
|
|
|
params.put("domainUserID", domainUserID); |
|
|
|
params.put("ifsSiteID", errorLog.getSite()); |
|
|
|
params.put("partNo", errorLog.getPartNo()); |
|
|
|
params.put("qtyToIssue", errorLog.getQty()); |
|
|
|
params.put("locationNo", errorLog.getSourceLocation()); |
|
|
|
params.put("destLocationNo", errorLog.getDestLocation()); |
|
|
|
params.put("lotBatchNo", errorLog.getLotBatchNo()); |
|
|
|
|
|
|
|
if (errorLog.getExpiredDate() != null) { |
|
|
|
params.put("expiredDate", new SimpleDateFormat("yyyy-MM-dd").format(errorLog.getExpiredDate())); |
|
|
|
} else { |
|
|
|
params.put("expiredDate", null); |
|
|
|
} |
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
jsonBody = objectMapper.writeValueAsString(params); |
|
|
|
} else { |
|
|
|
// 使用保存的请求数据 - rqrq |
|
|
|
jsonBody = errorLog.getRequestData(); |
|
|
|
} |
|
|
|
|
|
|
|
System.out.println("请求数据: " + jsonBody); |
|
|
|
|
|
|
|
// 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 |
|
|
|
* @author rqrq |
|
|
|
* @date 2025/10/08 |
|
|
|
*/ |
|
|
|
private String getCurrentDomainUserID() { |
|
|
|
|
|
|
|
return domainUserID; |
|
|
|
} |
|
|
|
} |