From b4f685a25d171950de4ce5c1592abe147fcb100e Mon Sep 17 00:00:00 2001 From: zhaoqing <3160641494@qq.com> Date: Tue, 23 Jun 2026 14:01:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E8=88=AC=E8=B4=B8?= =?UTF-8?q?=E6=98=93=E7=9A=84=E8=AF=A6=E6=83=85=E6=9F=A5=E8=AF=A2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9D=A5=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mhd/system/api/WmsServiceFeign.java | 6 ++ .../api/factory/RemoteWmsFallbackFactory.java | 9 +++ .../MaterialInfoApplicationService.java | 42 +++++++++++ .../entity/MaterialPushRecord.java | 65 +++++++++++++++++ .../mapper/MaterialPushRecordMapper.java | 9 +++ .../service/MaterialPushRecordService.java | 73 +++++++++++++++++++ .../MaterialPushRecordApi.java | 25 +++++++ .../MaterialPushRecordMapper.xml | 28 +++++++ 8 files changed, 257 insertions(+) create mode 100644 mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/entity/MaterialPushRecord.java create mode 100644 mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/repository/mapper/MaterialPushRecordMapper.java create mode 100644 mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/service/MaterialPushRecordService.java create mode 100644 mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/materialPushRecord/MaterialPushRecordApi.java create mode 100644 mhd_oms/src/main/resources/mapper/materialPushRecord/MaterialPushRecordMapper.xml diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WmsServiceFeign.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WmsServiceFeign.java index 9a459adc1..b7698b1cc 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WmsServiceFeign.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WmsServiceFeign.java @@ -115,4 +115,10 @@ public interface WmsServiceFeign { @RequestParam(value = "pushTime",required = false) String pushTime, @RequestParam(value = "pushBy",required = false) Long pushBy, @RequestParam(value = "pushByName",required = false) String pushByName); + + /** + * 根据物料ID列表批量查询物料信息 + */ + @GetMapping("/materialBaseInfoApi/getBatchByIds") + public TableDataInfo getBatchByIds(@RequestParam("materialBaseInfoIds") List materialBaseInfoIds); } \ No newline at end of file diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWmsFallbackFactory.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWmsFallbackFactory.java index a62144e1f..55ab7572a 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWmsFallbackFactory.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWmsFallbackFactory.java @@ -90,6 +90,15 @@ public class RemoteWmsFallbackFactory implements FallbackFactory updateMaterialPushStatus(Long materialBaseInfoId, Integer pushStatus, String pushTime, Long pushBy, String pushByName) { return AjaxResult.error(cause.getMessage()); } + + @Override + public TableDataInfo getBatchByIds(List materialBaseInfoIds) { + TableDataInfo tableDataInfo = new TableDataInfo(); + tableDataInfo.setData(new ArrayList<>()); + tableDataInfo.setTotal(0); + tableDataInfo.setCode(500); + return tableDataInfo; + } }; } } \ No newline at end of file diff --git a/mhd_oms/src/main/java/com/mhd/oms/application/service/materialInfo/MaterialInfoApplicationService.java b/mhd_oms/src/main/java/com/mhd/oms/application/service/materialInfo/MaterialInfoApplicationService.java index 15f15da38..57627ebb5 100644 --- a/mhd_oms/src/main/java/com/mhd/oms/application/service/materialInfo/MaterialInfoApplicationService.java +++ b/mhd_oms/src/main/java/com/mhd/oms/application/service/materialInfo/MaterialInfoApplicationService.java @@ -2,6 +2,7 @@ package com.mhd.oms.application.service.materialInfo; import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.mhd.common.core.exception.ServiceException; import com.mhd.common.core.web.domain.AjaxResult; @@ -9,6 +10,9 @@ import com.mhd.common.core.web.page.TableDataInfo; import com.mhd.common.security.utils.SecurityUtils; import com.mhd.oms.domain.gwLog.entity.GwLog; import com.mhd.oms.domain.gwLog.repository.mapper.GwLogMapper; +import com.mhd.oms.domain.materialPushRecord.entity.MaterialPushRecord; +import com.mhd.oms.domain.materialPushRecord.repository.mapper.MaterialPushRecordMapper; +import com.mhd.oms.domain.reservationStockInOrder.repository.po.MaterialBaseInfoPO; import com.mhd.oms.domain.businessDocumentOrder.repository.mapper.BusinessDocumentOrderMapper; import com.mhd.system.api.WmsServiceFeign; import com.mhd.system.api.domain.MaterialInfoDTO; @@ -45,6 +49,9 @@ public class MaterialInfoApplicationService { @Resource private BusinessDocumentOrderMapper businessDocumentOrderMapper; + @Resource + private MaterialPushRecordMapper materialPushRecordMapper; + private final WmsServiceFeign wmsServiceFeign; public MaterialInfoApplicationService(WmsServiceFeign wmsServiceFeign) { @@ -88,6 +95,7 @@ public class MaterialInfoApplicationService { int successCount = 0; int failCount = 0; StringBuilder failMsg = new StringBuilder(); + List successIds = new ArrayList<>(); for (MaterialInfoDTO dto : dtoList) { Map item = new HashMap<>(); @@ -147,6 +155,7 @@ public class MaterialInfoApplicationService { gwLog.setStatus(2); updatePushStatus(dto.getMaterialBaseInfoId(), 3, new Date(), pushBy, pushByName); successCount++; + successIds.add(dto.getMaterialBaseInfoId()); } else { gwLog.setStatus(3); gwLog.setErrorMsg(responseString); @@ -181,6 +190,39 @@ public class MaterialInfoApplicationService { } } + // 推送成功后,保存物料快照到物料推送记录表 + if (!successIds.isEmpty()) { + try { + Date now = new Date(); + TableDataInfo wmsResult = wmsServiceFeign.getBatchByIds(successIds); + if (wmsResult != null && wmsResult.getData() != null) { + List materialList = JSONArray.parseArray( + JSONObject.toJSONString(wmsResult.getData()), MaterialBaseInfoPO.class); + for (MaterialBaseInfoPO material : materialList) { + MaterialPushRecord record = new MaterialPushRecord(); + record.setMaterialBaseInfoId(material.getMaterialBaseInfoId()); + record.setMaterialCode(material.getMaterialCode()); + record.setMaterialName(material.getMaterialName()); + record.setGoodsType(material.getGoodsType()); + record.setSpecificationModel(material.getSpecificationModel()); + record.setDeclarationUnit(material.getDeclarationUnit()); + record.setCurrency(material.getCurrency()); + record.setUnitPrice(material.getUnitPrice()); + record.setNetWeight(material.getWeightLimit()); + record.setGrossWeight(material.getGrossWeight()); + record.setPushTime(now); + record.setDelFlag(1); + record.setCreateBy(pushBy); + record.setCreateTime(now); + record.setUpdateTime(now); + materialPushRecordMapper.insert(record); + } + } + } catch (Exception e) { + log.error("保存物料推送快照失败: {}", e.getMessage()); + } + } + String resultMsg = "推送完成: 成功" + successCount + "条, 失败" + failCount + "条"; if (failCount > 0) { resultMsg += "[" + failMsg.toString() + "]"; diff --git a/mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/entity/MaterialPushRecord.java b/mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/entity/MaterialPushRecord.java new file mode 100644 index 000000000..57a3e85dd --- /dev/null +++ b/mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/entity/MaterialPushRecord.java @@ -0,0 +1,65 @@ +package com.mhd.oms.domain.materialPushRecord.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.mhd.common.core.web.domain.BaseVOEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * 物料推送记录表 + */ +@Data +@ApiModel(value = "物料推送记录对象") +@TableName("material_push_record") +public class MaterialPushRecord extends BaseVOEntity { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("主键") + @TableId(type = IdType.AUTO) + private Long id; + + @ApiModelProperty("物料ID") + private Long materialBaseInfoId; + + @ApiModelProperty("物料编码") + private String materialCode; + + @ApiModelProperty("物料名称") + private String materialName; + + @ApiModelProperty("规格型号") + private String specificationModel; + + @ApiModelProperty("申报单位") + private String declarationUnit; + + @ApiModelProperty("数量") + private BigDecimal cargoNum; + + @ApiModelProperty("币制") + private String currency; + + @ApiModelProperty("单价") + private BigDecimal unitPrice; + + @ApiModelProperty("净重(kg)") + private BigDecimal netWeight; + + @ApiModelProperty("毛重(kg)") + private BigDecimal grossWeight; + + @ApiModelProperty("商品类型(0物料,1半成品,2成品)") + private Integer goodsType; + + @ApiModelProperty("推送时间") + private Date pushTime; + + @ApiModelProperty("删除标志(1-正常,2-删除)") + private Integer delFlag; +} diff --git a/mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/repository/mapper/MaterialPushRecordMapper.java b/mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/repository/mapper/MaterialPushRecordMapper.java new file mode 100644 index 000000000..cf0e9007e --- /dev/null +++ b/mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/repository/mapper/MaterialPushRecordMapper.java @@ -0,0 +1,9 @@ +package com.mhd.oms.domain.materialPushRecord.repository.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mhd.oms.domain.materialPushRecord.entity.MaterialPushRecord; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface MaterialPushRecordMapper extends BaseMapper { +} diff --git a/mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/service/MaterialPushRecordService.java b/mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/service/MaterialPushRecordService.java new file mode 100644 index 000000000..84d1036ba --- /dev/null +++ b/mhd_oms/src/main/java/com/mhd/oms/domain/materialPushRecord/service/MaterialPushRecordService.java @@ -0,0 +1,73 @@ +package com.mhd.oms.domain.materialPushRecord.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.mhd.common.core.web.page.TableDataInfo; +import com.mhd.oms.domain.materialPushRecord.entity.MaterialPushRecord; +import com.mhd.oms.domain.materialPushRecord.repository.mapper.MaterialPushRecordMapper; +import com.mhd.system.api.WmsServiceFeign; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class MaterialPushRecordService { + + @Resource + private MaterialPushRecordMapper materialPushRecordMapper; + + @Resource + private WmsServiceFeign wmsServiceFeign; + + /** + * 按物料ID列表查询物料数据 + * 优先查物料推送快照,没有则调WMS查实时数据 + */ + public TableDataInfo getBatchByIds(List materialBaseInfoIds) { + if (materialBaseInfoIds == null || materialBaseInfoIds.isEmpty()) { + TableDataInfo emptyResult = new TableDataInfo(); + emptyResult.setData(new ArrayList<>()); + emptyResult.setTotal(0); + emptyResult.setCode(200); + return emptyResult; + } + + // 1. 先查物料推送记录表 + List pushRecords = materialPushRecordMapper.selectList( + new LambdaQueryWrapper() + .in(MaterialPushRecord::getMaterialBaseInfoId, materialBaseInfoIds) + .eq(MaterialPushRecord::getDelFlag, 1)); + + if (pushRecords != null && !pushRecords.isEmpty()) { + // 检查是否所有请求的物料ID都查到了 + Set foundIds = pushRecords.stream() + .map(MaterialPushRecord::getMaterialBaseInfoId) + .collect(Collectors.toSet()); + if (foundIds.containsAll(materialBaseInfoIds)) { + // 全部ID都有推送快照,直接返回 + TableDataInfo result = new TableDataInfo(); + result.setData(pushRecords); + result.setTotal(pushRecords.size()); + result.setCode(200); + return result; + } + } + + // 2. 有物料没有推送数据,调WMS查全部实时数据 + try { + return wmsServiceFeign.getBatchByIds(materialBaseInfoIds); + } catch (Exception e) { + log.error("调用WMS查询物料信息失败: {}", e.getMessage()); + TableDataInfo errorResult = new TableDataInfo(); + errorResult.setData(new ArrayList<>()); + errorResult.setTotal(0); + errorResult.setCode(500); + return errorResult; + } + } +} diff --git a/mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/materialPushRecord/MaterialPushRecordApi.java b/mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/materialPushRecord/MaterialPushRecordApi.java new file mode 100644 index 000000000..e2448e49f --- /dev/null +++ b/mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/materialPushRecord/MaterialPushRecordApi.java @@ -0,0 +1,25 @@ +package com.mhd.oms.interfaces.facade.materialPushRecord; + +import com.mhd.common.core.web.domain.AjaxResult; +import com.mhd.oms.domain.materialPushRecord.service.MaterialPushRecordService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +@Api(tags = "物料推送记录") +@RestController +@RequestMapping("/materialPushRecordApi") +public class MaterialPushRecordApi { + + @Resource + private MaterialPushRecordService materialPushRecordService; + + @ApiOperation("批量查询物料推送数据(优先查推送快照,没有则调WMS查实时数据)") + @GetMapping("/getBatchByIds") + public AjaxResult getBatchByIds(@RequestParam("materialBaseInfoIds") List materialBaseInfoIds) { + return AjaxResult.success(materialPushRecordService.getBatchByIds(materialBaseInfoIds)); + } +} diff --git a/mhd_oms/src/main/resources/mapper/materialPushRecord/MaterialPushRecordMapper.xml b/mhd_oms/src/main/resources/mapper/materialPushRecord/MaterialPushRecordMapper.xml new file mode 100644 index 000000000..2df87e3bb --- /dev/null +++ b/mhd_oms/src/main/resources/mapper/materialPushRecord/MaterialPushRecordMapper.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +