| | |
| | | |
| | | List<ErpOrderDetl> detls = dto.getOrderItems(); |
| | | |
| | | // ===== 参数校验 ===== |
| | | if (Cools.isEmpty(order.getOrderNo()) || order.getOrderType() == null |
| | | || Cools.isEmpty(order.getWkType()) || order.getBusinessTime() == null |
| | | || order.getCreateTime() == null || Cools.isEmpty(order.getWarehouseId())) { |
| | | throw new CoolException("订单参数不完整"); |
| | | throw new CoolException("订单参数不完整:" + |
| | | "orderNo=" + order.getOrderNo() + |
| | | ",orderType=" + order.getOrderType() + |
| | | ",wkType=" + order.getWkType() + |
| | | ",warehouseId=" + order.getWarehouseId()); |
| | | } |
| | | |
| | | if (Cools.isEmpty(detls)) { |
| | | throw new CoolException("订单明细为空"); |
| | | throw new CoolException("订单明细为空:" + order.getOrderNo()); |
| | | } |
| | | |
| | | // ===== 调外部接口 ===== |
| | | for (ErpOrderDetl d : detls) { |
| | | if (d == null || Cools.isEmpty(d.getLineId()) |
| | | || Cools.isEmpty(d.getMatNr()) |
| | | || d.getAnfme() == null) { |
| | | String lineId = d != null ? d.getLineId() : null; |
| | | String matnr = d != null ? d.getMatNr() : null; |
| | | throw new CoolException("明细参数不完整:" + |
| | | "orderNo=" + order.getOrderNo() + |
| | | ",lineId=" + lineId + |
| | | ",matnr=" + matnr); |
| | | } |
| | | } |
| | | |
| | | if (!erpOrderService.insert(order)) { |
| | | throw new CoolException("订单插入失败:" + order.getOrderNo()); |
| | | } |
| | | |
| | | if (order.getId() == null) { |
| | | throw new CoolException("订单插入失败,未返回orderId:" + order.getOrderNo()); |
| | | } |
| | | |
| | | for (ErpOrderDetl detl : detls) { |
| | | detl.setOrderId(order.getId()); |
| | | if (!erpOrderDetlService.insert(detl)) { |
| | | throw new CoolException("订单明细插入失败:" + |
| | | "orderNo=" + order.getOrderNo() + |
| | | ",lineId=" + detl.getLineId()); |
| | | } |
| | | } |
| | | |
| | | String syncError = null; |
| | | String whId = order.getWarehouseId(); |
| | | Integer orderType = order.getOrderType(); |
| | |
| | | } else if ("WH3".equals(whId)) { |
| | | syncError = syncOrderToWarehouse3(order, detls, orderType); |
| | | } else { |
| | | throw new CoolException("未找到对应仓库编号"); |
| | | throw new CoolException("未找到对应仓库编号:" + |
| | | "orderNo=" + order.getOrderNo() + |
| | | ",warehouseId=" + whId); |
| | | } |
| | | } |
| | | |
| | | if (syncError != null) { |
| | | throw new CoolException(syncError); |
| | | } |
| | | |
| | | // ===== 插入主表 ===== |
| | | if (!erpOrderService.insert(order)) { |
| | | throw new CoolException("订单插入失败"); |
| | | } |
| | | |
| | | if (order.getId() == null) { |
| | | throw new CoolException("订单插入失败,未返回orderId"); |
| | | } |
| | | |
| | | // ===== 插入明细(这里异常会触发回滚)===== |
| | | for (ErpOrderDetl detl : detls) { |
| | | if (detl == null || Cools.isEmpty(detl.getLineId()) |
| | | || Cools.isEmpty(detl.getMatNr()) |
| | | || detl.getAnfme() == null) { |
| | | throw new CoolException("明细参数不完整"); |
| | | } |
| | | |
| | | detl.setOrderId(order.getId()); |
| | | |
| | | if (!erpOrderDetlService.insert(detl)) { |
| | | throw new CoolException("订单明细插入失败"); |
| | | } |
| | | throw new CoolException("外部接口同步失败:" + |
| | | "orderNo=" + order.getOrderNo() + |
| | | ",warehouseId=" + whId + |
| | | ",原因=" + syncError); |
| | | } |
| | | } |
| | | @Override |
| | |
| | | for (OrderDto dto : orders) { |
| | | String orderNo = dto != null ? dto.getOrderNo() : null; |
| | | try { |
| | | // ⭐ 调用独立事务方法 |
| | | processOneOrder(dto); |
| | | successOrders.add(orderNo); |
| | | } catch (Exception e) { |
| | | Map<String, Object> fail = new HashMap<>(); |
| | | String whId = dto != null ? dto.getWareHouseId() : null; |
| | | Integer orderType = dto != null ? dto.getOrderType() : null; |
| | | fail.put("orderNo", orderNo); |
| | | fail.put("warehouseId", whId); |
| | | fail.put("orderType", orderType); |
| | | fail.put("msg", e.getMessage()); |
| | | fail.put("exception", e.getClass().getSimpleName()); |
| | | Throwable cause = e.getCause(); |
| | | if (cause != null && cause != e) { |
| | | fail.put("cause", cause.getClass().getSimpleName() + ":" + cause.getMessage()); |
| | | } |
| | | failOrders.add(fail); |
| | | } |
| | | } |