From 07e50535f7bd7a96b09bb7506ca2344468d971ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=B8=E7=86=9F=E5=90=B4=E5=BD=A6=E7=A5=96?= Date: Wed, 8 Oct 2025 14:35:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IfsCallErrorLogController.java | 25 +++ .../api/service/IfsCallErrorLogService.java | 10 ++ .../impl/IfsCallErrorLogServiceImpl.java | 170 ++++++++++++++++++ .../service/impl/WmsMessageServiceImpl.java | 2 +- 4 files changed, 206 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gaotao/modules/api/controller/IfsCallErrorLogController.java b/src/main/java/com/gaotao/modules/api/controller/IfsCallErrorLogController.java index 76b923b..70a6e97 100644 --- a/src/main/java/com/gaotao/modules/api/controller/IfsCallErrorLogController.java +++ b/src/main/java/com/gaotao/modules/api/controller/IfsCallErrorLogController.java @@ -99,4 +99,29 @@ public class IfsCallErrorLogController extends AbstractController { return R.error("获取站点列表失败"); } } + + /** + * @Description 手工重试IFS接口调用 - rqrq + * @Title retryIfsCall + * @param data 包含id + * @return R + * @author rqrq + * @date 2025/10/08 + */ + @PostMapping("/retry") + public R retryIfsCall(@RequestBody IfsCallErrorLogData data) { + try { + String processedBy = getUser().getUsername(); + boolean success = ifsCallErrorLogService.retryIfsCall(data.getId(), processedBy); + + if (success) { + return R.ok().put("msg", "重试成功,IFS接口调用完成"); + } else { + return R.error("重试失败,请查看错误日志或联系管理员"); + } + } catch (Exception e) { + logger.error("重试IFS接口调用失败", e); + return R.error("重试失败:" + e.getMessage()); + } + } } diff --git a/src/main/java/com/gaotao/modules/api/service/IfsCallErrorLogService.java b/src/main/java/com/gaotao/modules/api/service/IfsCallErrorLogService.java index 324359a..300dca5 100644 --- a/src/main/java/com/gaotao/modules/api/service/IfsCallErrorLogService.java +++ b/src/main/java/com/gaotao/modules/api/service/IfsCallErrorLogService.java @@ -65,4 +65,14 @@ public interface IfsCallErrorLogService extends IService { * @date 2025/10/08 */ void markAsIgnored(Long id, String processedBy, String remark); + + /** + * @Description 手工重试IFS接口调用 - rqrq + * @param id 错误日志ID + * @param processedBy 操作人 + * @return 是否成功 + * @author rqrq + * @date 2025/10/08 + */ + boolean retryIfsCall(Long id, String processedBy); } diff --git a/src/main/java/com/gaotao/modules/api/service/impl/IfsCallErrorLogServiceImpl.java b/src/main/java/com/gaotao/modules/api/service/impl/IfsCallErrorLogServiceImpl.java index f101695..35e9c76 100644 --- a/src/main/java/com/gaotao/modules/api/service/impl/IfsCallErrorLogServiceImpl.java +++ b/src/main/java/com/gaotao/modules/api/service/impl/IfsCallErrorLogServiceImpl.java @@ -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 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= 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 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; + } } diff --git a/src/main/java/com/gaotao/modules/api/service/impl/WmsMessageServiceImpl.java b/src/main/java/com/gaotao/modules/api/service/impl/WmsMessageServiceImpl.java index b90c6a4..1ee6ae9 100644 --- a/src/main/java/com/gaotao/modules/api/service/impl/WmsMessageServiceImpl.java +++ b/src/main/java/com/gaotao/modules/api/service/impl/WmsMessageServiceImpl.java @@ -394,7 +394,7 @@ public class WmsMessageServiceImpl implements WmsMessageService { // 创建移库出库TransDetail TransDetail stoDetail = createTransDetail(stoTransNo, itemNo, firstHU, - totalQty, "-", fromLocationId); + totalQty, "-", groupHUs.getFirst().getLocationId()); transDetailService.save(stoDetail); // 创建移库入库TransDetail