materialBaseInfoIdSet = immediateInventoryPOS.stream()
@@ -173,6 +163,19 @@ public class StatementStatisticsService {
return immediateInventoryPOS;
}
+ /**
+ * 获取库存数量合计
+ * @param immediateInventoryDO 查询参数
+ * @return 库存数量合计
+ */
+ public BigDecimal sumImmediateInventoryQuantity(ImmediateInventoryDO immediateInventoryDO) {
+ BigDecimal totalInventoryQuantity = materialInventoryDomainService.sumImmediateInventoryQuantity(immediateInventoryDO);
+ if (totalInventoryQuantity == null) {
+ totalInventoryQuantity = BigDecimal.ZERO;
+ }
+ return totalInventoryQuantity;
+ }
+
/**
* 为物料库存设置更多属性(从库存表中获取值)
* @param materialInventoryPOList 物料库存列表
diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/inventoryAdjustmentRecord/service/InventoryAdjustmentRecordDomainService.java b/mhd_wms/src/main/java/com/mhd/wms/domain/inventoryAdjustmentRecord/service/InventoryAdjustmentRecordDomainService.java
index 9bccb9db7..2f0fe6053 100644
--- a/mhd_wms/src/main/java/com/mhd/wms/domain/inventoryAdjustmentRecord/service/InventoryAdjustmentRecordDomainService.java
+++ b/mhd_wms/src/main/java/com/mhd/wms/domain/inventoryAdjustmentRecord/service/InventoryAdjustmentRecordDomainService.java
@@ -1,15 +1,21 @@
package com.mhd.wms.domain.inventoryAdjustmentRecord.service;
import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson2.JSONObject;
import com.aliyun.oss.ServiceException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mhd.common.core.constant.SnowFlakeConstants;
import com.mhd.common.core.domain.po.UserPo;
+import com.mhd.common.core.domain.po.WarehousePO;
import com.mhd.common.core.utils.OrderSequence;
import com.mhd.common.core.utils.uuid.IdGenerator;
+import com.mhd.common.core.utils.StringUtils;
+import com.mhd.common.core.web.domain.AjaxResult;
import com.mhd.common.core.web.domain.BaseVOEntity;
import com.mhd.common.security.utils.SecurityUtils;
import com.mhd.system.api.OmsServiceFeign;
+import com.mhd.system.api.SystemServiceFeign;
import com.mhd.system.api.domain.*;
import com.mhd.system.api.model.LoginUser;
import com.mhd.wms.domain.inventoryAdjustmentRecord.repository.facade.IInventoryAdjustmentRecordService;
@@ -56,6 +62,8 @@ public class InventoryAdjustmentRecordDomainService {
private IdGenerator idGenerator;
@Autowired
private OmsServiceFeign omsServiceFeign;
+ @Autowired
+ private SystemServiceFeign systemServiceFeign;
@@ -106,6 +114,15 @@ public class InventoryAdjustmentRecordDomainService {
*/
@Transactional
public Boolean inventoryAdjust(InventoryAdjustmentRecordDO inventoryAdjustmentRecordDO) {
+ // 根据仓库ID获取仓库信息,用于后续库存调整的仓库判断
+ AjaxResult warehouseInfoByWarehouseId = systemServiceFeign.getWarehouseInfoByWarehouseId(inventoryAdjustmentRecordDO.getWarehouseId());
+ if (warehouseInfoByWarehouseId == null) {
+ throw new ServiceException("仓库不存在");
+ } else if (!warehouseInfoByWarehouseId.get("code").equals(200)) {
+ throw new ServiceException("网络错误请重试 --- " + warehouseInfoByWarehouseId.get("msg"));
+ }
+ // 获取仓库信息
+ WarehousePO warehousePO = JSON.parseObject(JSONObject.toJSONString(warehouseInfoByWarehouseId.get("data")), WarehousePO.class);
InventoryAdjustmentRecordDO inventoryAdjustmentRecord = new InventoryAdjustmentRecordDO();
inventoryAdjustmentRecord.setAdjustAction("库存调整");
LoginUser loginUser = SecurityUtils.getLoginUser();
@@ -115,6 +132,17 @@ public class InventoryAdjustmentRecordDomainService {
inventoryAdjustmentRecord.setCreateBy(loginUser.getUserid());
inventoryAdjustmentRecord.setCreateByName(loginUser.getUsername());
inventoryAdjustmentRecord.setCreateTime(new Date());
+ if (inventoryAdjustmentRecordDO.getAdjustType() == null) {
+ throw new ServiceException("调整类型不能为空");
+ }
+ if (inventoryAdjustmentRecordDO.getAdjustType() == 1
+ && inventoryAdjustmentRecordDO.getMaterialInventoryId() == null) {
+ throw new ServiceException("请选择要调整的库存");
+ }
+ if (inventoryAdjustmentRecordDO.getAdjustQuantity() == null
+ || inventoryAdjustmentRecordDO.getAdjustQuantity().compareTo(BigDecimal.ZERO) == 0) {
+ throw new ServiceException("调整数量不能为空且不能为0");
+ }
MaterialInventory materialInventory = null;
//根据调整类型判断,数量调整只调整当前库存记录数量,状态调整减少当前原物料状态库存数量和可用数量,增加到现状态库存数量和可用数量
if (inventoryAdjustmentRecordDO.getAdjustType() != null && inventoryAdjustmentRecordDO.getAdjustType() == 1) {
@@ -180,8 +208,8 @@ public class InventoryAdjustmentRecordDomainService {
.eq(MaterialInventory::getStorageSectionId,inventoryAdjustmentRecordDO.getStorageSectionId())
.eq(MaterialInventory::getStorageLocationId,inventoryAdjustmentRecordDO.getStorageLocationId())
.eq(MaterialInventory::getMaterialStatusCode,inventoryAdjustmentRecordDO.getAdjustBeforeStatusCode())
- .eq(MaterialInventory::getBatchNumber,inventoryAdjustmentRecordDO.getBatchNumber())
- .eq(MaterialInventory::getContainerId,inventoryAdjustmentRecordDO.getContainerId())
+ .eq(StringUtils.isNotBlank(inventoryAdjustmentRecordDO.getBatchNumber()),MaterialInventory::getBatchNumber,inventoryAdjustmentRecordDO.getBatchNumber())
+ .eq(inventoryAdjustmentRecordDO.getContainerId() != null, MaterialInventory::getContainerId, inventoryAdjustmentRecordDO.getContainerId())
.eq(BaseVOEntity::getDelFlag, 1));
if (ObjectUtil.isNotNull(materialInventory)) {
BeanUtils.copyProperties(materialInventory, inventoryAdjustmentRecord);
@@ -218,6 +246,8 @@ public class InventoryAdjustmentRecordDomainService {
inventoryAdjustmentRecord.setAdjustedGrossWeight(materialInventory.getGrossWeight());
inventoryAdjustmentRecord.setAdjustedVolume(materialInventory.getVolume());
inventoryAdjustmentRecord.setAdjustedArea(materialInventory.getArea());
+ // ===== 新增:原状态库存扣减后立即落库,避免依赖末尾统一更新 =====
+ materialInventoryService.updateById(materialInventory);
} else {
throw new ServiceException("根据原物料状态查询不到物料库存信息!");
}
@@ -228,8 +258,8 @@ public class InventoryAdjustmentRecordDomainService {
.eq(MaterialInventory::getStorageSectionId,inventoryAdjustmentRecordDO.getStorageSectionId())
.eq(MaterialInventory::getStorageLocationId,inventoryAdjustmentRecordDO.getStorageLocationId())
.eq(MaterialInventory::getMaterialStatusCode,inventoryAdjustmentRecordDO.getAdjustAfterStatusCode())
- .eq(MaterialInventory::getBatchNumber,inventoryAdjustmentRecordDO.getBatchNumber())
- .eq(MaterialInventory::getContainerId,inventoryAdjustmentRecordDO.getContainerId())
+ .eq(StringUtils.isNotBlank(inventoryAdjustmentRecordDO.getBatchNumber()),MaterialInventory::getBatchNumber,inventoryAdjustmentRecordDO.getBatchNumber())
+ .eq(inventoryAdjustmentRecordDO.getContainerId() != null,MaterialInventory::getContainerId,inventoryAdjustmentRecordDO.getContainerId())
.eq(BaseVOEntity::getDelFlag, 1));
if (ObjectUtil.isNotNull(materialInventory1)) {
materialInventory1.setInventoryQuantity(materialInventory1.getInventoryQuantity().add(inventoryAdjustmentRecordDO.getAdjustQuantity()));
@@ -245,21 +275,49 @@ public class InventoryAdjustmentRecordDomainService {
inventoryAdjustmentRecord.setAdjustAfterStatusCode(inventoryAdjustmentRecordDO.getAdjustAfterStatusCode());
inventoryAdjustmentRecord.setAdjustAfterStatusName(inventoryAdjustmentRecordDO.getAdjustAfterStatusName());
}
+ // ===== 新增:adjustType 合法性兜底,避免异常类型导致 materialInventory 为 null 静默走完流程 =====
+ if (ObjectUtil.isNull(materialInventory)) {
+ throw new ServiceException("不支持的调整类型:" + inventoryAdjustmentRecordDO.getAdjustType());
+ }
//生成库存调整追溯记录
if (ObjectUtil.isNotNull(materialInventory)){
genInventoryStandingDetail(materialInventory, inventoryAdjustmentRecordDO.getAdjustQuantity());
}
-
- materialInventoryService.updateById(materialInventory);
+ // ===== 修复:末尾更新加 null 保护 =====
+ if (ObjectUtil.isNotNull(materialInventory)) {
+ materialInventoryService.updateById(materialInventory);
+ }
Boolean insert = inventoryAdjustmentRecordService.insert(inventoryAdjustmentRecord);
//推送oms库存调整记录
- pushOms(materialInventory, inventoryAdjustmentRecordDO);
+ try{
+ // 当仓库启用 oms 才进行推送
+ if (warehousePO.getIsEnable() == 1) {
+ Boolean pushSuccess = pushOms(materialInventory, inventoryAdjustmentRecordDO);
+ if (!pushSuccess) {
+ throw new ServiceException("库存调整推送OMS失败,请稍后重试");
+ }
+ }
+ }catch (Exception e){
+ log.error("推送OMS库存调整记录异常,materialBaseInfoId={}, adjustDirection={}",
+ inventoryAdjustmentRecordDO.getMaterialBaseInfoId(),
+ inventoryAdjustmentRecordDO.getAdjustDirection());
+ throw new ServiceException("库存调整推送OMS失败,请稍后重试");
+ }
+ System.out.println("库存调整时间结束 ----" + System.currentTimeMillis());
return insert;
}
-
- private void pushOms(MaterialInventory materialInventory,InventoryAdjustmentRecordDO inventoryAdjustmentRecordDO) {
+ /**
+ * 推送库存调整信息至OMS系统
+ *
+ * 根据调整方向(1=增加库存,2=减少库存)分别构造入库调整单或出库调整单,
+ * 并通过Feign接口推送至OMS系统,同时推送对应的物料明细信息。
+ *
+ * @param materialInventory 调整涉及的物料库存信息,包含仓库、库区、库位、货主等上下文数据
+ * @param inventoryAdjustmentRecordDO 库存调整记录,包含调整方向、调整数量、物料编码等数据
+ */
+ private Boolean pushOms(MaterialInventory materialInventory,InventoryAdjustmentRecordDO inventoryAdjustmentRecordDO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
UserPo userPo = loginUser.getUserPo();
MaterialBaseInfo materialBaseInfo = materialBaseInfoService.getById(materialInventory.getMaterialBaseInfoId());
@@ -327,8 +385,16 @@ public class InventoryAdjustmentRecordDomainService {
inMaterialDetail.setStorageLocationCode(materialInventory.getStorageLocationCode());
inMaterialDetail.setStorageLocationName(materialInventory.getStorageLocationName());
inMaterialDetail.setSingleGrossWeight(materialBaseInfo.getWeightLimit());
- omsServiceFeign.pushInOrder(stockInOrder);
- omsServiceFeign.pushInOrderDetail(inMaterialDetail);
+ AjaxResult inOrderResult = omsServiceFeign.pushInOrder(stockInOrder);
+ AjaxResult inOrderDetailResult = omsServiceFeign.pushInOrderDetail(inMaterialDetail);
+ if (inOrderResult == null || inOrderDetailResult == null
+ || !"200".equals(String.valueOf(inOrderResult.get("code")))
+ || !"200".equals(String.valueOf(inOrderDetailResult.get("code")))
+ ) {
+ log.error("推送OMS入库调整单失败,pushInOrder={}, pushInOrderDetail={}",
+ inOrderResult, inOrderDetailResult);
+ return false;
+ }
} else {
StockOutOrderTZPD stockOutOrder = new StockOutOrderTZPD();
stockOutOrder.setOrganizationId(loginUser.getUserPo().getOrganizationId());
@@ -391,9 +457,18 @@ public class InventoryAdjustmentRecordDomainService {
outMaterialDetail.setStorageLocationCode(materialInventory.getStorageLocationCode());
outMaterialDetail.setStorageLocationName(materialInventory.getStorageLocationName());
outMaterialDetail.setSingleGrossWeight(materialBaseInfo.getWeightLimit());
- omsServiceFeign.pushOutOrder(stockOutOrder);
- omsServiceFeign.pushOutOrderDetail(outMaterialDetail);
+ AjaxResult inOrderResult = omsServiceFeign.pushOutOrder(stockOutOrder);
+ AjaxResult inOrderDetailResult = omsServiceFeign.pushOutOrderDetail(outMaterialDetail);
+ if (inOrderResult == null || inOrderDetailResult == null
+ || !"200".equals(String.valueOf(inOrderResult.get("code")))
+ || !"200".equals(String.valueOf(inOrderDetailResult.get("code")))
+ ) {
+ log.error("推送OMS入库调整单失败,pushInOrder={}, pushInOrderDetail={}",
+ inOrderResult, inOrderDetailResult);
+ return false;
+ }
}
+ return true;
}
/**
diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/materialInventory/repository/mapper/MaterialInventoryMapper.java b/mhd_wms/src/main/java/com/mhd/wms/domain/materialInventory/repository/mapper/MaterialInventoryMapper.java
index 2cb15e4f0..58fbf0e2f 100644
--- a/mhd_wms/src/main/java/com/mhd/wms/domain/materialInventory/repository/mapper/MaterialInventoryMapper.java
+++ b/mhd_wms/src/main/java/com/mhd/wms/domain/materialInventory/repository/mapper/MaterialInventoryMapper.java
@@ -38,6 +38,8 @@ public interface MaterialInventoryMapper extends BaseMapper
public List queryListByHz(MaterialInventoryDO materialInventoryDO);
//查物料库存列表-货主+物料(同一物料在不同货主下各一行)
public List queryListByHzWl(MaterialInventoryDO materialInventoryDO);
+ //查物料库存列表-按货主+物料+仓库(库存查询第三个页签,update_time 取合并后最大值)
+ public List queryListByHzWlUnit(MaterialInventoryDO materialInventoryDO);
/**
* @description 批量增加库存
diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/materialInventory/repository/persistence/MaterialInventoryImpl.java b/mhd_wms/src/main/java/com/mhd/wms/domain/materialInventory/repository/persistence/MaterialInventoryImpl.java
index 4b1e1b14e..a536436ce 100644
--- a/mhd_wms/src/main/java/com/mhd/wms/domain/materialInventory/repository/persistence/MaterialInventoryImpl.java
+++ b/mhd_wms/src/main/java/com/mhd/wms/domain/materialInventory/repository/persistence/MaterialInventoryImpl.java
@@ -77,17 +77,19 @@ public class MaterialInventoryImpl extends ServiceImpl queryImmediateInventoryList(ImmediateInventoryDTO immediateInventoryDTO)
{
//转换实体
ImmediateInventoryDO immediateInventoryDO = immediateInventoryAssembler.toDO(immediateInventoryDTO);
startPage();
List list = statementStatisticsService.queryImmediateInventoryList(immediateInventoryDO);
- return getDataTable(list);
+ BigDecimal bigDecimal = statementStatisticsService.sumImmediateInventoryQuantity(immediateInventoryDO);
+ return getDataTableWarehouse(list,bigDecimal);
}
/**
* 分页查询入库日报表列表
@@ -129,4 +132,18 @@ public class StatementStatisticsApi {
rspData.setTotal(new PageInfo(list).getTotal());
return rspData;
}
+
+ /**
+ * 响应请求分页、仓库数量 数据
+ */
+ protected HashMap getDataTableWarehouse(List> list,BigDecimal bigDecimal)
+ {
+ HashMap stringObjectHashMap = new HashMap<>();
+ stringObjectHashMap.put("data",list);
+ stringObjectHashMap.put("total",new PageInfo(list).getTotal());
+ stringObjectHashMap.put("code",HttpStatus.SUCCESS);
+ stringObjectHashMap.put("msg","查询成功");
+ stringObjectHashMap.put("totalInventoryQuantity",bigDecimal);
+ return stringObjectHashMap;
+ }
}
diff --git a/mhd_wms/src/main/resources/mapper/materialInventory/MaterialInventoryMapper.xml b/mhd_wms/src/main/resources/mapper/materialInventory/MaterialInventoryMapper.xml
index 5a5708903..8656e711d 100644
--- a/mhd_wms/src/main/resources/mapper/materialInventory/MaterialInventoryMapper.xml
+++ b/mhd_wms/src/main/resources/mapper/materialInventory/MaterialInventoryMapper.xml
@@ -528,6 +528,55 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
loc.storage_location_id, loc.storage_location_code, loc.storage_location_name order by sort_order, a.update_time desc
+
+
+
+ a.shipper_id, a.shipper_code, a.shipper_name,
+ b.material_base_info_id, b.material_code, b.material_name, b.SPECIFICATION_MODEL,
+ a.warehouse_id, a.warehouse_code, a.warehouse_name,
+ a.organization_id, a.organization_name, a.top_organization_id,
+ MAX(b.material_type) AS material_type,
+ MAX(b.material_type_name) AS material_type_name,
+ MAX(b.bar_code) AS bar_code,
+ MAX(nvl(a.unit_name, b.unit_name)) AS unit_name,
+ MAX(b.pack_id) AS pack_id,
+ MAX(b.pack_code) AS pack_code,
+ MAX(b.pack_name) AS pack_name,
+ MAX(a.unit) AS unit,
+ IFNULL(SUM(a.freeze_quantity), 0) AS freeze_quantity,
+ IFNULL(SUM(a.inventory_quantity), 0) AS inventory_quantity,
+ IFNULL(SUM(a.allocation_quantity), 0) AS allocation_quantity,
+ IFNULL(SUM(a.area), 0) AS area,
+ IFNULL(SUM(a.NET_WEIGHT), 0) AS NET_WEIGHT,
+ IFNULL(SUM(a.GROSS_WEIGHT), 0) AS GROSS_WEIGHT,
+ IFNULL(SUM(a.VOLUME), 0) AS VOLUME,
+ MIN(a.create_time) AS create_time, -- 新增:首次入库时间
+ MAX(a.update_time) AS update_time,
+ CASE WHEN IFNULL(SUM(a.inventory_quantity), 0) = 0 THEN 1 ELSE 0 END AS sort_order
+
+
+
+