From 1e61760d458314846ba8dc50cfd3e3ac5cf7647a Mon Sep 17 00:00:00 2001 From: zhaoqing <1670883518@qq.com> Date: Thu, 28 May 2026 18:29:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E5=8F=A3=E8=AE=A2=E5=8D=95=E6=8E=A8?= =?UTF-8?q?=E9=80=81-=E6=95=B0=E6=8D=AE=E6=8E=A8=E9=80=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20=20=E5=87=BA=E5=8F=A3=E4=BB=93=E5=8D=95=E6=8E=A8?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...vationStockOutOrderApplicationService.java | 163 ++++++++++++------ .../PickingOrderApplicationService.java | 163 ++++++++++++++++++ .../pickingOrder/PickingOrderApi.java | 13 ++ 3 files changed, 289 insertions(+), 50 deletions(-) diff --git a/mhd_oms/src/main/java/com/mhd/oms/domain/reservationStockOutOrder/service/ReservationStockOutOrderApplicationService.java b/mhd_oms/src/main/java/com/mhd/oms/domain/reservationStockOutOrder/service/ReservationStockOutOrderApplicationService.java index 55e36b6b2..9aa0f5ed4 100644 --- a/mhd_oms/src/main/java/com/mhd/oms/domain/reservationStockOutOrder/service/ReservationStockOutOrderApplicationService.java +++ b/mhd_oms/src/main/java/com/mhd/oms/domain/reservationStockOutOrder/service/ReservationStockOutOrderApplicationService.java @@ -1089,67 +1089,130 @@ public class ReservationStockOutOrderApplicationService { int failCount = 0; StringBuilder failMsg = new StringBuilder(); + for (Long id : idList) { - GwStockOutOrder gwStockOutOrder = new GwStockOutOrder(); + + +// 查询出库单 ReservationStockOutOrder reservationStockOutOrder = reservationStockOutOrderMapper.selectById(id); + if (reservationStockOutOrder == null) { + failCount++; + failMsg.append("id:").append(id).append("不存在;"); + continue; + } + + // 获取货主NC编码 Long shipperId = reservationStockOutOrder.getShipperId(); String userNcCode = reservationStockInOrderMapper.getUserNcCode(shipperId); - gwStockOutOrder.setBill_no(reservationStockOutOrder.getOutOrderNumber()); - gwStockOutOrder.setBill_date(reservationStockOutOrder.getDocumentDate()); - gwStockOutOrder.setIe_flag("E"); - gwStockOutOrder.setCorp_code(userNcCode); + // 构建主单Map + Map order = new HashMap<>(); + order.put("billNo", reservationStockOutOrder.getOutOrderNumber()); + order.put("ieFlag", "E"); + order.put("billDate", reservationStockOutOrder.getDocumentDate()); + order.put("corpCode", userNcCode != null ? userNcCode : ""); - List reservationOutMaterialDetails = reservationOutMaterialDetailMapper.selectList(new LambdaQueryWrapper().eq(ReservationOutMaterialDetail::getOutOrderNumber, reservationStockOutOrder.getOutOrderNumber())); - Integer lineNum = 1; - List orderList = new LinkedList<>(); - for (ReservationOutMaterialDetail reservationOutMaterialDetail : reservationOutMaterialDetails) { - GwOutDetail gwOutDetail = new GwOutDetail(); - Long materialBaseInfoId = reservationOutMaterialDetail.getMaterialBaseInfoId(); - gwOutDetail.setBill_no(gwStockOutOrder.getBill_no()); - gwOutDetail.setLine_num(lineNum); - lineNum++; - gwOutDetail.setItem_no(materialBaseInfoId.toString()); - gwOutDetail.setItem_name(reservationOutMaterialDetail.getMaterialName()); - MaterialBaseInfoPO materialBaseInfoPO = reservationStockInOrderMapper.getinfo(materialBaseInfoId); - gwOutDetail.setSpec(materialBaseInfoPO.getSpecificationModel()); - gwOutDetail.setUnit(materialBaseInfoPO.getDeclarationUnit()); - gwOutDetail.setQty(reservationOutMaterialDetail.getQuantity()); - gwOutDetail.setErp_curr(materialBaseInfoPO.getCurrency()); - gwOutDetail.setErp_price(materialBaseInfoPO.getUnitPrice()); - BigDecimal unitPrice = materialBaseInfoPO.getUnitPrice(); - BigDecimal quantity = reservationOutMaterialDetail.getQuantity(); - if (unitPrice != null && quantity != null && unitPrice.compareTo(BigDecimal.ZERO) != 0&&quantity.compareTo(BigDecimal.ZERO) != 0) { - BigDecimal Amount = unitPrice.multiply(quantity).setScale(2, BigDecimal.ROUND_HALF_UP); - gwOutDetail.setAmount(Amount); - } - orderList.add(gwOutDetail); + // 查询出库物料明细 + List reservationOutMaterialDetails = + reservationOutMaterialDetailMapper.selectList( + new LambdaQueryWrapper() + .eq(ReservationOutMaterialDetail::getOutOrderNumber, reservationStockOutOrder.getOutOrderNumber()) + ); - Long kcId = reservationOutMaterialDetailMapper.getKcId(reservationOutMaterialDetail.getLotNo()); - String inOrderNumber = reservationOutMaterialDetailMapper.getInOrderNumber(kcId); - String inLotNo = reservationOutMaterialDetailMapper.getInLotNo(inOrderNumber,materialBaseInfoId); - String warehouse = reservationOutMaterialDetailMapper.getWarehouse(kcId); - String opWhLoc = reservationOutMaterialDetailMapper.getOpWhLoc(kcId); - Integer result = null; - if (inLotNo != null && inLotNo.contains("-")) { - // 截取最后一个 "-" 后面的内容(兼容多 "-" 场景) - String numStr = inLotNo.substring(inLotNo.lastIndexOf("-") + 1); - // 转成 Integer - result = Integer.valueOf(numStr); - } - gwOutDetail.setOrder_i_no(inOrderNumber); - gwOutDetail.setBill_i(inLotNo); - gwOutDetail.setOrder_i_row(result); - gwOutDetail.setBill_i_row(result); - gwOutDetail.setWarehouse(warehouse); - gwOutDetail.setOp_wh_loc(opWhLoc); + if (reservationOutMaterialDetails == null || reservationOutMaterialDetails.isEmpty()) { + failCount++; + failMsg.append("id:").append(id).append("无物料明细;"); + continue; } - gwStockOutOrder.setOrderList(orderList); + + // 构建明细List + List> orderList = new ArrayList<>(); + int lineNum = 1; + for (ReservationOutMaterialDetail detail : reservationOutMaterialDetails) { + Map item = new HashMap<>(); + item.put("billNo", reservationStockOutOrder.getOutOrderNumber()); + item.put("lineNum", lineNum++); + item.put("itemNo", detail.getMaterialBaseInfoId() != null ? detail.getMaterialBaseInfoId().toString() : ""); + item.put("itemName", detail.getMaterialName() != null ? detail.getMaterialName() : ""); + item.put("spec", detail.getSpecificationModel() != null ? detail.getSpecificationModel() : ""); + item.put("unit", detail.getDeclareUnit() != null ? detail.getDeclareUnit() : ""); + item.put("qty", detail.getQuantity()); + + // 获取物料详情 + if (detail.getMaterialBaseInfoId() != null) { + MaterialBaseInfoPO materialBaseInfoPO = reservationStockInOrderMapper.getinfo(detail.getMaterialBaseInfoId()); + if (materialBaseInfoPO != null) { + item.put("erpCurr", materialBaseInfoPO.getCurrency() != null ? materialBaseInfoPO.getCurrency() : ""); + item.put("erpPrice", materialBaseInfoPO.getUnitPrice()); + + // 计算金额 + BigDecimal unitPrice = materialBaseInfoPO.getUnitPrice(); + BigDecimal quantity = detail.getQuantity(); + if (unitPrice != null && quantity != null && unitPrice.compareTo(BigDecimal.ZERO) != 0 && quantity.compareTo(BigDecimal.ZERO) != 0) { + BigDecimal amount = unitPrice.multiply(quantity).setScale(2, BigDecimal.ROUND_HALF_UP); + item.put("amount", amount); + } + } + } + + // 库存关联信息 + if (detail.getLotNo() != null) { + Long kcId = reservationOutMaterialDetailMapper.getKcId(detail.getLotNo()); + if (kcId != null) { + String inOrderNumber = reservationOutMaterialDetailMapper.getInOrderNumber(kcId); + String inLotNo = inOrderNumber != null ? reservationOutMaterialDetailMapper.getInLotNo(inOrderNumber, detail.getMaterialBaseInfoId()) : null; + String warehouse = reservationOutMaterialDetailMapper.getWarehouse(kcId); + String opWhLoc = reservationOutMaterialDetailMapper.getOpWhLoc(kcId); + + item.put("orderINo", inOrderNumber != null ? inOrderNumber : ""); + item.put("warehouse", warehouse != null ? warehouse : ""); + item.put("opWhLoc", opWhLoc != null ? opWhLoc : ""); + item.put("billI", inLotNo != null ? inLotNo : ""); + + // 处理批次号中的数字 + if (inLotNo != null && inLotNo.contains("-")) { + String numStr = inLotNo.substring(inLotNo.lastIndexOf("-") + 1); + try { + Integer result = Integer.valueOf(numStr); + item.put("orderIRow", result); + item.put("billIRow", result); + } catch (NumberFormatException e) { + item.put("orderIRow", null); + item.put("billIRow", null); + } + } else { + item.put("orderIRow", null); + item.put("billIRow", null); + } + } else { + item.put("orderINo", ""); + item.put("orderIRow", null); + item.put("warehouse", ""); + item.put("opWhLoc", ""); + item.put("billI", ""); + item.put("billIRow", null); + } + } else { + item.put("orderINo", ""); + item.put("orderIRow", null); + item.put("warehouse", ""); + item.put("opWhLoc", ""); + item.put("billI", ""); + item.put("billIRow", null); + } + + orderList.add(item); + } + order.put("orderList", orderList); + + // 构建推送body + List> bodyList = new ArrayList<>(); + bodyList.add(order); GwLog gwLog = new GwLog(); gwLog.setType("出口订单"); gwLog.setBusinessId(id); - gwLog.setRequestBody(com.alibaba.fastjson.JSONObject.toJSONString(gwStockOutOrder)); + gwLog.setRequestBody(com.alibaba.fastjson.JSONObject.toJSONString(bodyList)); gwLog.setResponseBody(""); gwLog.setStatus(1); gwLog.setSendTime(new Date()); @@ -1165,7 +1228,7 @@ public class ReservationStockOutOrderApplicationService { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(PUSH_API_URL); - StringEntity postingString = new StringEntity(com.alibaba.fastjson.JSONObject.toJSONString(gwStockOutOrder), "UTF-8"); + StringEntity postingString = new StringEntity(com.alibaba.fastjson.JSONObject.toJSONString(bodyList), "UTF-8"); httpPost.setEntity(postingString); httpPost.setHeader("Content-type", "application/json"); httpPost.setHeader("apiName", API_NAME); diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/pickingOrder/PickingOrderApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/pickingOrder/PickingOrderApplicationService.java index 6fa84ad4d..45b2e4d6c 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/pickingOrder/PickingOrderApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/pickingOrder/PickingOrderApplicationService.java @@ -4,15 +4,18 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.mhd.common.core.domain.po.UserPo; import com.mhd.common.core.exception.ServiceException; import com.mhd.common.core.utils.StringUtils; import com.mhd.common.core.utils.bean.BeanUtils; import com.mhd.common.core.web.domain.AjaxResult; import com.mhd.common.security.utils.SecurityUtils; +import com.mhd.system.api.OmsServiceFeign; import com.mhd.system.api.SystemServiceFeign; import com.mhd.system.api.UserServiceFeign; import com.mhd.system.api.domain.BatchDetailFeignPO; +import com.mhd.system.api.domain.GwLogDTO; import com.mhd.system.api.domain.StorageLocationFeignPO; import com.mhd.system.api.domain.cache.AssociationWarehouseCacheDO; import com.mhd.system.api.domain.cache.SystemServiceCacheUtil; @@ -21,6 +24,8 @@ import com.mhd.wms.domain.materialMoreDetail.repository.po.MaterialMoreDetailPO; import com.mhd.wms.domain.pickingMaterialDetail.repository.po.PickingMaterialDetailPO; import com.mhd.wms.domain.pickingMaterialDetail.repository.todo.PickingMaterialDetailDO; import com.mhd.wms.domain.pickingMaterialDetail.service.PickingMaterialDetailDomainService; +import com.mhd.wms.domain.pickingOrder.entity.PickingOrder; +import com.mhd.wms.domain.pickingOrder.repository.mapper.PickingOrderMapper; import com.mhd.wms.domain.pickingOrder.repository.po.PickingOrderPO; import com.mhd.wms.domain.pickingOrder.repository.todo.PickingOrderDO; import com.mhd.wms.domain.pickingOrder.service.PickingOrderDomainService; @@ -28,13 +33,22 @@ import com.mhd.wms.domain.materialGoodsRule.repository.facade.IMaterialGoodsRule import com.mhd.wms.domain.outMaterialDetail.repository.facade.IOutMaterialDetailService; import com.mhd.wms.domain.outMaterialDetail.entity.OutMaterialDetail; import com.mhd.wms.domain.outMaterialDetail.repository.po.OutMaterialDetailPO; +import com.mhd.wms.domain.stockShelfOrder.entity.StockShelfOrder; import com.mhd.wms.util.ReceiptBatchDetailFilter; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.extern.slf4j.Slf4j; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import javax.annotation.Resource; +import java.io.IOException; import java.lang.reflect.Field; import java.math.BigDecimal; import java.text.SimpleDateFormat; @@ -60,9 +74,18 @@ public class PickingOrderApplicationService { @Autowired private SystemServiceFeign systemServiceFeign; @Autowired + private OmsServiceFeign omsServiceFeign; + @Autowired private IMaterialGoodsRuleService materialGoodsRuleService; @Autowired private IOutMaterialDetailService outMaterialDetailService; + @Resource + private PickingOrderMapper pickingOrderMapper; + + + private static final String PUSH_API_URL = "http://10.33.0.100/nagu-erp-api/transfer/pushData"; + private static final String API_NAME = "save_qnBill_i"; + private static final String VERIFY = "tjPZMT9fwhZRnv+eTXKF75QXmXzCn7phPagmoUQsvsh2ZTWDjuRxHAgcP0GZENHP"; /** @@ -685,4 +708,144 @@ public class PickingOrderApplicationService { returnPickingOrderDO.setMaterialDetailList(returnPickingMaterialDetailDOList); return returnPickingOrderDO; } + + + + + public AjaxResult batchPush(List idList) { + if (idList == null || idList.isEmpty()) { + return AjaxResult.error("没有数据需要推送"); + } + + LoginUser loginUser = SecurityUtils.getLoginUser(); + Long pushBy = loginUser != null ? loginUser.getUserid() : null; + String pushByName = loginUser != null ? loginUser.getUsername() : null; + Long organizationId = loginUser != null ? loginUser.getUserPo().getOrganizationId() : null; + Long topOrganizationId = loginUser != null ? loginUser.getUserPo().getTopOrganizationId() : null; + String organizationName = loginUser != null ? loginUser.getUserPo().getOrganizationName() : null; + + int successCount = 0; + int failCount = 0; + StringBuilder failMsg = new StringBuilder(); + + for(Long id : idList){ + + + + + + List> bodyList = new ArrayList<>(); + // bodyList.add(); + + GwLogDTO gwLogDTO = new GwLogDTO(); + gwLogDTO.setType("出口订单"); + gwLogDTO.setBusinessId(id); + gwLogDTO.setRequestBody(com.alibaba.fastjson.JSONObject.toJSONString(bodyList)); + gwLogDTO.setResponseBody(""); + gwLogDTO.setStatus(1); + gwLogDTO.setSendTime(new Date()); + gwLogDTO.setOrganizationId(organizationId); + gwLogDTO.setTopOrganizationId(topOrganizationId); + gwLogDTO.setOrganizationName(organizationName); + gwLogDTO.setCreateBy(pushBy); + gwLogDTO.setCreateTime(new Date()); + //gwLogMapper.insert(gwLogDTO); + Long gwLogId = null; + try { + AjaxResult insertResult = omsServiceFeign.insertGwLog(gwLogDTO); + if(insertResult !=null && "200".equals(String.valueOf(insertResult.get("code")))){ + Mapdata = (Map)insertResult.get("data"); + gwLogId = ((Number)data.get("id")).longValue(); + } + + }catch(Exception e){ + log.error("保存Gwlog失败:{}",e.getMessage()); + } + + updatePushStatus(id, 2, new Date(), pushBy,pushByName); + + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(PUSH_API_URL); + StringEntity postingString = new StringEntity(com.alibaba.fastjson.JSONObject.toJSONString(bodyList), "UTF-8"); + httpPost.setEntity(postingString); + httpPost.setHeader("Content-type", "application/json"); + httpPost.setHeader("apiName", API_NAME); + httpPost.setHeader("verify", VERIFY); + + try { + CloseableHttpResponse response = httpClient.execute(httpPost); + String responseString = EntityUtils.toString(response.getEntity()); + gwLogDTO.setResponseBody(responseString); + + if (response.getStatusLine().getStatusCode() == 200) { + gwLogDTO.setStatus(2); + updatePushStatus(id, 3, new Date(), pushBy,pushByName); + successCount++; + } else { + gwLogDTO.setStatus(3); + gwLogDTO.setErrorMsg(responseString); + updatePushStatus(id, 4, new Date(), pushBy,pushByName); + failCount++; + failMsg.append("id:").append(id).append("失败;"); + } + if (gwLogId != null){ + gwLogDTO.setLogId(gwLogId); + try{ + AjaxResult updateResult = omsServiceFeign.updateGwLog(gwLogDTO); + }catch (Exception e){ + log.error("更新GwLog失败:{}",e.getMessage()); + } + } +// gwLogMapper.updateById(gwLog); + + response.close(); + } catch (IOException e) { + gwLogDTO.setStatus(3); + gwLogDTO.setErrorMsg(e.getMessage()); + gwLogDTO.setResponseBody("请求异常:" + e.getMessage()); +// gwLogMapper.updateById(gwLog); + if (gwLogId != null){ + gwLogDTO.setLogId(gwLogId); + try{ + AjaxResult updateResult = omsServiceFeign.updateGwLog(gwLogDTO); + }catch (Exception ex){ + log.error("更新GwLog失败:{}",ex.getMessage()); + } + } + + updatePushStatus(id, 4, new Date(), pushBy,pushByName); + failCount++; + failMsg.append("id:").append(id).append("异常:").append(e.getMessage()).append(";"); + log.error("保税仓推送异常: id={}, error={}", id, e.getMessage()); + } finally { + try { + httpClient.close(); + } catch (Exception e) { + log.error("关闭httpClient异常: {}", e.getMessage()); + } + } + } + + String resultMsg = "推送完成: 成功" + successCount + "条, 失败" + failCount + "条"; + if (failCount > 0) { + resultMsg += "[" + failMsg.toString() + "]"; + } + return AjaxResult.success(resultMsg); + } + + private void updatePushStatus(Long id, Integer pushStatus, Date pushTime, Long pushBy,String pushByName) { + PickingOrder entity = new PickingOrder(); + entity.setPickingOrderId(id); + entity.setPushStatus(pushStatus); + if (pushTime != null) { + entity.setPushTime(pushTime); + } + if (pushBy != null) { + entity.setPushBy(pushBy); + } + if (pushByName != null) { + entity.setPushByName(pushByName); + } + pickingOrderMapper.updateById(entity); + } } \ No newline at end of file diff --git a/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/pickingOrder/PickingOrderApi.java b/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/pickingOrder/PickingOrderApi.java index a0bc87498..17a85bae1 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/pickingOrder/PickingOrderApi.java +++ b/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/pickingOrder/PickingOrderApi.java @@ -116,4 +116,17 @@ public class PickingOrderApi extends BaseController { PickingOrderDO pickingOrderDO = pickingOrderAssembler.toDO(pickingOrderDTO); return toAjax(pickingOrderApplicationService.completePicking(pickingOrderDO)); } + + + @ApiOperation("批量推送") + @PostMapping("/batchPush") + public AjaxResult batchPush(@RequestBody List idList){ + if(idList == null || idList.isEmpty()){ + return AjaxResult.error("没有数据需要推送"); + } + return pickingOrderApplicationService.batchPush(idList); + + } + + } \ No newline at end of file