Browse Source

MRP欠量统计

yzc 10 months ago
parent
commit
9a8bf78e90

+ 11 - 1
hx-common/src/main/java/com/fjhx/common/entity/AvailableStockBo.java

@@ -30,8 +30,18 @@ public class AvailableStockBo {
     private BigDecimal inStockQuantity;
     private BigDecimal inStockQuantity;
 
 
     /**
     /**
-     * 需采购量
+     * 需采购量
      */
      */
     private BigDecimal demandPurchaseCount;
     private BigDecimal demandPurchaseCount;
 
 
+    /**
+     * 已经采购数量
+     */
+    private BigDecimal purchaseQuantity;
+
+    /**
+     * 需求量
+     */
+    private BigDecimal requiredQuantity;
+
 }
 }

+ 3 - 3
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -554,7 +554,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
                 BigDecimal requiredQuantity = stockThreshold.subtract(subtract);
                 BigDecimal requiredQuantity = stockThreshold.subtract(subtract);
 
 
                 //返回需采购量
                 //返回需采购量
-                inOutBo.setQuantity(requiredQuantity);
+                inOutBo.setRequiredQuantity(requiredQuantity);
 
 
                 //计算可用库存
                 //计算可用库存
                 if (requiredQuantity.compareTo(BigDecimal.ZERO) < 0) {
                 if (requiredQuantity.compareTo(BigDecimal.ZERO) < 0) {
@@ -620,7 +620,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
                     //计数需要采购的数量(需采购量 = 安全库存 - (可用库存 - 合同量)若 需采购量<0,则按0算不采购)
                     //计数需要采购的数量(需采购量 = 安全库存 - (可用库存 - 合同量)若 需采购量<0,则按0算不采购)
                     BigDecimal subtract1 = availableQuantity.subtract(subtract);
                     BigDecimal subtract1 = availableQuantity.subtract(subtract);
                     BigDecimal requiredQuantity = stockThreshold.subtract(subtract1);
                     BigDecimal requiredQuantity = stockThreshold.subtract(subtract1);
-                    inOutBo.setNewQuantity(requiredQuantity);
+                    inOutBo.setRequiredQuantity(requiredQuantity);
 
 
 
 
                     //修改可用库存
                     //修改可用库存
@@ -656,7 +656,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
 
 
 
 
                     //需采购量直接为0
                     //需采购量直接为0
-                    inOutBo.setNewQuantity(BigDecimal.ZERO);
+                    inOutBo.setRequiredQuantity(BigDecimal.ZERO);
 
 
                 }
                 }
             } else {
             } else {

+ 35 - 2
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -90,10 +90,12 @@ import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
 import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
 import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
 import com.fjhx.tenant.service.dict.DictTenantDataService;
 import com.fjhx.tenant.service.dict.DictTenantDataService;
 import com.fjhx.tenant.utils.DictUtils;
 import com.fjhx.tenant.utils.DictUtils;
+import com.fjhx.wms.entity.contract.po.ContractMrpInfo;
 import com.fjhx.wms.entity.stock.emums.JournalType;
 import com.fjhx.wms.entity.stock.emums.JournalType;
 import com.fjhx.wms.entity.stock.po.StockWait;
 import com.fjhx.wms.entity.stock.po.StockWait;
 import com.fjhx.wms.entity.stock.po.StockWaitDetails;
 import com.fjhx.wms.entity.stock.po.StockWaitDetails;
 import com.fjhx.wms.entity.stock.vo.StockWaitDetailsVo;
 import com.fjhx.wms.entity.stock.vo.StockWaitDetailsVo;
+import com.fjhx.wms.service.contract.ContractMrpInfoService;
 import com.fjhx.wms.service.stock.StockWaitDetailsService;
 import com.fjhx.wms.service.stock.StockWaitDetailsService;
 import com.fjhx.wms.service.stock.StockWaitService;
 import com.fjhx.wms.service.stock.StockWaitService;
 import com.ruoyi.common.annotation.TenantIgnore;
 import com.ruoyi.common.annotation.TenantIgnore;
@@ -122,6 +124,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestBody;
 
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.math.RoundingMode;
@@ -241,6 +244,8 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
     private EhsdPurchaseProductMapper ehsdPurchaseProductMapper;
     private EhsdPurchaseProductMapper ehsdPurchaseProductMapper;
     @Autowired
     @Autowired
     private FlowProcessService flowProcessService;
     private FlowProcessService flowProcessService;
+    @Resource
+    private ContractMrpInfoService contractMrpInfoService;
 
 
     /**
     /**
      * 合同和样品单 下拉分页
      * 合同和样品单 下拉分页
@@ -3628,7 +3633,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         productInfoService.editAvailableQuantity(collect, contractId, ProductAvailableRecordType.SALE_PASS, companyId);
         productInfoService.editAvailableQuantity(collect, contractId, ProductAvailableRecordType.SALE_PASS, companyId);
         for (AvailableStockBo inOutBo : collect) {
         for (AvailableStockBo inOutBo : collect) {
             Long materialId = inOutBo.getProductId();
             Long materialId = inOutBo.getProductId();
-            BigDecimal requiredQuantity = inOutBo.getQuantity();
+            BigDecimal requiredQuantity = inOutBo.getRequiredQuantity();
 
 
             //需要采购的数量大于0生成待采购数据
             //需要采购的数量大于0生成待采购数据
             if (requiredQuantity.compareTo(BigDecimal.ZERO) > 0) {
             if (requiredQuantity.compareTo(BigDecimal.ZERO) > 0) {
@@ -3641,6 +3646,13 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                 subscribeDetail.setCompanyId(companyId);
                 subscribeDetail.setCompanyId(companyId);
 //                subscribeDetail.setProdOrderId(productionOrder.getId());
 //                subscribeDetail.setProdOrderId(productionOrder.getId());
                 subscribeDetailList.add(subscribeDetail);
                 subscribeDetailList.add(subscribeDetail);
+
+                //生成合同MRP库存信息
+                ContractMrpInfo contractMrpInfo = new ContractMrpInfo();
+                contractMrpInfo.setContractId(contractId);
+                contractMrpInfo.setMaterialId(materialId);
+                contractMrpInfo.setStockQuantity(inOutBo.getQuantity().subtract(requiredQuantity));
+                contractMrpInfoService.save(contractMrpInfo);
             }
             }
         }
         }
         //保存待采购明细
         //保存待采购明细
@@ -3712,6 +3724,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
             availableStockBo.setQuantity(oldContractProductBom.getQuantity());
             availableStockBo.setQuantity(oldContractProductBom.getQuantity());
             availableStockBo.setNewQuantity(newQuantity);
             availableStockBo.setNewQuantity(newQuantity);
             availableStockBo.setInStockQuantity(purchaseQuantity);
             availableStockBo.setInStockQuantity(purchaseQuantity);
+            availableStockBo.setPurchaseQuantity(purchaseQuantity);
             availableStockBo.setDemandPurchaseCount(demandPurchaseCount);
             availableStockBo.setDemandPurchaseCount(demandPurchaseCount);
 
 
             availableStockBoList.add(availableStockBo);
             availableStockBoList.add(availableStockBo);
@@ -3736,6 +3749,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
             availableStockBo.setNewQuantity(newPurchaseProduct.getQuantity());
             availableStockBo.setNewQuantity(newPurchaseProduct.getQuantity());
             availableStockBo.setInStockQuantity(BigDecimal.ZERO);
             availableStockBo.setInStockQuantity(BigDecimal.ZERO);
             availableStockBo.setDemandPurchaseCount(BigDecimal.ZERO);
             availableStockBo.setDemandPurchaseCount(BigDecimal.ZERO);
+            availableStockBo.setPurchaseQuantity(BigDecimal.ZERO);
 
 
             availableStockBoList.add(availableStockBo);
             availableStockBoList.add(availableStockBo);
         }
         }
@@ -3754,7 +3768,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                     .eq(SubscribeDetail::getCompanyId, companyId)
                     .eq(SubscribeDetail::getCompanyId, companyId)
             );
             );
 
 
-            BigDecimal requiredQuantity = availableStockBo.getNewQuantity();
+            BigDecimal requiredQuantity = availableStockBo.getRequiredQuantity();
 
 
 
 
             //需采购量>0
             //需采购量>0
@@ -3791,6 +3805,25 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
             }
             }
 
 
 
 
+            //生成合同MRP库存信息,待采购=需求量-已采购:if(差额 - 待采购 >0){库存 = 库存-(差额 - 待采购)}
+            BigDecimal subtract = availableStockBo.getQuantity().subtract(availableStockBo.getNewQuantity());
+            BigDecimal waitPurchaseQuantity = availableStockBo.getDemandPurchaseCount().subtract(availableStockBo.getPurchaseQuantity());
+            BigDecimal subtract1 = subtract.subtract(waitPurchaseQuantity);
+            if (subtract1.compareTo(BigDecimal.ZERO) > 0) {
+                ContractMrpInfo contractMrpInfo = contractMrpInfoService.getOne(q -> q
+                        .eq(ContractMrpInfo::getContractId, newContractId)
+                        .eq(ContractMrpInfo::getMaterialId, materialId)
+                );
+                if (ObjectUtil.isEmpty(contractMrpInfo)) {
+                    contractMrpInfo = new ContractMrpInfo();
+                    contractMrpInfo.setContractId(newContractId);
+                    contractMrpInfo.setMaterialId(materialId);
+                }
+                contractMrpInfo.setStockQuantity(contractMrpInfo.getStockQuantity().subtract(subtract1));
+                contractMrpInfoService.saveOrUpdate(contractMrpInfo);
+            }
+
+
         }
         }
 
 
         //---------------------------------------------------------------
         //---------------------------------------------------------------

+ 166 - 0
hx-wms/src/main/java/com/fjhx/wms/a-json/ContractMrpInfoApi.json

@@ -0,0 +1,166 @@
+{
+  "openapi": "3.0.1",
+  "tags": [
+    {
+      "name": "合同物料MRP信息"
+    }
+  ],
+  "paths": {
+    "/contractMrpInfo/page": {
+      "post": {
+        "summary": "分页",
+        "tags": [
+          "合同物料MRP信息"
+        ],
+        "requestBody": {
+          "content": {
+            "application/json": {
+              "schema": {
+                "type": "object",
+                "required": [
+                  "pageNum",
+                  "pageSize"
+                ],
+                "title": null,
+                "properties": {
+                  "pageNum": {
+                    "type": "integer",
+                    "required": null,
+                    "title": "页数",
+                    "properties": null,
+                    "items": null
+                  },
+                  "pageSize": {
+                    "type": "integer",
+                    "required": null,
+                    "title": "每页大小",
+                    "properties": null,
+                    "items": null
+                  }
+                },
+                "items": null
+              }
+            }
+          }
+        },
+        "responses": {
+          "200": {
+            "description": "成功",
+            "content": {
+              "application/json": {
+                "schema": {
+                  "type": "object",
+                  "required": [
+                    "code",
+                    "success",
+                    "msg",
+                    "data"
+                  ],
+                  "title": null,
+                  "properties": {
+                    "code": {
+                      "type": "Integer",
+                      "required": null,
+                      "title": null,
+                      "properties": null,
+                      "items": null
+                    },
+                    "success": {
+                      "type": "boolean",
+                      "required": null,
+                      "title": null,
+                      "properties": null,
+                      "items": null
+                    },
+                    "msg": {
+                      "type": "string",
+                      "required": null,
+                      "title": null,
+                      "properties": null,
+                      "items": null
+                    },
+                    "data": {
+                      "type": "object",
+                      "required": [
+                        "rows",
+                        "total"
+                      ],
+                      "title": null,
+                      "properties": {
+                        "records": {
+                          "type": "array",
+                          "required": null,
+                          "title": "分页数据",
+                          "properties": null,
+                          "items": {
+                            "type": "object",
+                            "required": null,
+                            "title": null,
+                            "properties": {
+                              "id": {
+                                "type": "integer",
+                                "required": null,
+                                "title": "",
+                                "properties": null,
+                                "items": null
+                              },
+                              "contractId": {
+                                "type": "integer",
+                                "required": null,
+                                "title": "合同id",
+                                "properties": null,
+                                "items": null
+                              },
+                              "materialId": {
+                                "type": "integer",
+                                "required": null,
+                                "title": "物料id",
+                                "properties": null,
+                                "items": null
+                              },
+                              "stockQuantity": {
+                                "type": "number",
+                                "required": null,
+                                "title": "库存数量",
+                                "properties": null,
+                                "items": null
+                              },
+                              "createTime": {
+                                "type": "string",
+                                "required": null,
+                                "title": "创建时间",
+                                "properties": null,
+                                "items": null
+                              },
+                              "updateTime": {
+                                "type": "string",
+                                "required": null,
+                                "title": "修改时间",
+                                "properties": null,
+                                "items": null
+                              }
+                            },
+                            "items": null
+                          }
+                        },
+                        "total": {
+                          "type": "integer",
+                          "required": null,
+                          "title": "总条数",
+                          "properties": null,
+                          "items": null
+                        }
+                      },
+                      "items": null
+                    }
+                  },
+                  "items": null
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}

+ 37 - 0
hx-wms/src/main/java/com/fjhx/wms/controller/contract/ContractMrpInfoController.java

@@ -0,0 +1,37 @@
+package com.fjhx.wms.controller.contract;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.wms.entity.contract.dto.ContractMrpInfoSelectDto;
+import com.fjhx.wms.entity.contract.vo.ContractMrpInfoVo;
+import com.fjhx.wms.service.contract.ContractMrpInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+/**
+ * <p>
+ * 合同物料MRP信息 前端控制器
+ * </p>
+ *
+ * @author
+ * @since 2024-06-24
+ */
+@RestController
+@RequestMapping("/contractMrpInfo")
+public class ContractMrpInfoController {
+
+    @Autowired
+    private ContractMrpInfoService contractMrpInfoService;
+
+    /**
+     * 合同物料MRP信息分页
+     */
+    @PostMapping("/page")
+    public Page<ContractMrpInfoVo> page(@RequestBody ContractMrpInfoSelectDto dto) {
+        return contractMrpInfoService.getPage(dto);
+    }
+
+}

+ 17 - 0
hx-wms/src/main/java/com/fjhx/wms/entity/contract/dto/ContractMrpInfoDto.java

@@ -0,0 +1,17 @@
+package com.fjhx.wms.entity.contract.dto;
+
+import com.fjhx.wms.entity.contract.po.ContractMrpInfo;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 合同物料MRP信息新增编辑入参实体
+ *
+ * @author
+ * @since 2024-06-24
+ */
+@Getter
+@Setter
+public class ContractMrpInfoDto extends ContractMrpInfo {
+
+}

+ 17 - 0
hx-wms/src/main/java/com/fjhx/wms/entity/contract/dto/ContractMrpInfoSelectDto.java

@@ -0,0 +1,17 @@
+package com.fjhx.wms.entity.contract.dto;
+
+import com.ruoyi.common.core.domain.BaseSelectDto;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 合同物料MRP信息列表查询入参实体
+ *
+ * @author
+ * @since 2024-06-24
+ */
+@Getter
+@Setter
+public class ContractMrpInfoSelectDto extends BaseSelectDto {
+
+}

+ 38 - 0
hx-wms/src/main/java/com/fjhx/wms/entity/contract/po/ContractMrpInfo.java

@@ -0,0 +1,38 @@
+package com.fjhx.wms.entity.contract.po;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.ruoyi.common.core.domain.BasePo;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/**
+ * <p>
+ * 合同物料MRP信息
+ * </p>
+ *
+ * @author
+ * @since 2024-06-24
+ */
+@Getter
+@Setter
+@TableName("contract_mrp_info")
+public class ContractMrpInfo extends BasePo {
+
+    /**
+     * 合同id
+     */
+    private Long contractId;
+
+    /**
+     * 物料id
+     */
+    private Long materialId;
+
+    /**
+     * 库存数量
+     */
+    private BigDecimal stockQuantity;
+
+}

+ 17 - 0
hx-wms/src/main/java/com/fjhx/wms/entity/contract/vo/ContractMrpInfoVo.java

@@ -0,0 +1,17 @@
+package com.fjhx.wms.entity.contract.vo;
+
+import com.fjhx.wms.entity.contract.po.ContractMrpInfo;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 合同物料MRP信息列表查询返回值实体
+ *
+ * @author
+ * @since 2024-06-24
+ */
+@Getter
+@Setter
+public class ContractMrpInfoVo extends ContractMrpInfo {
+
+}

+ 26 - 0
hx-wms/src/main/java/com/fjhx/wms/mapper/contract/ContractMrpInfoMapper.java

@@ -0,0 +1,26 @@
+package com.fjhx.wms.mapper.contract;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.wms.entity.contract.po.ContractMrpInfo;
+import com.fjhx.wms.entity.contract.vo.ContractMrpInfoVo;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import org.apache.ibatis.annotations.Param;
+
+
+/**
+ * <p>
+ * 合同物料MRP信息 Mapper 接口
+ * </p>
+ *
+ * @author
+ * @since 2024-06-24
+ */
+public interface ContractMrpInfoMapper extends BaseMapper<ContractMrpInfo> {
+
+    /**
+     * 合同物料MRP信息分页
+     */
+    Page<ContractMrpInfoVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<ContractMrpInfo> wrapper);
+
+}

+ 25 - 0
hx-wms/src/main/java/com/fjhx/wms/service/contract/ContractMrpInfoService.java

@@ -0,0 +1,25 @@
+package com.fjhx.wms.service.contract;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.wms.entity.contract.dto.ContractMrpInfoSelectDto;
+import com.fjhx.wms.entity.contract.po.ContractMrpInfo;
+import com.fjhx.wms.entity.contract.vo.ContractMrpInfoVo;
+import com.ruoyi.common.core.service.BaseService;
+
+
+/**
+ * <p>
+ * 合同物料MRP信息 服务类
+ * </p>
+ *
+ * @author
+ * @since 2024-06-24
+ */
+public interface ContractMrpInfoService extends BaseService<ContractMrpInfo> {
+
+    /**
+     * 合同物料MRP信息分页
+     */
+    Page<ContractMrpInfoVo> getPage(ContractMrpInfoSelectDto dto);
+
+}

+ 33 - 0
hx-wms/src/main/java/com/fjhx/wms/service/contract/impl/ContractMrpInfoServiceImpl.java

@@ -0,0 +1,33 @@
+package com.fjhx.wms.service.contract.impl;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.wms.entity.contract.dto.ContractMrpInfoSelectDto;
+import com.fjhx.wms.entity.contract.po.ContractMrpInfo;
+import com.fjhx.wms.entity.contract.vo.ContractMrpInfoVo;
+import com.fjhx.wms.mapper.contract.ContractMrpInfoMapper;
+import com.fjhx.wms.service.contract.ContractMrpInfoService;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * <p>
+ * 合同物料MRP信息 服务实现类
+ * </p>
+ *
+ * @author
+ * @since 2024-06-24
+ */
+@Service
+public class ContractMrpInfoServiceImpl extends ServiceImpl<ContractMrpInfoMapper, ContractMrpInfo> implements ContractMrpInfoService {
+
+    @Override
+    public Page<ContractMrpInfoVo> getPage(ContractMrpInfoSelectDto dto) {
+        IWrapper<ContractMrpInfo> wrapper = getWrapper();
+        wrapper.orderByDesc("cmi", ContractMrpInfo::getId);
+        Page<ContractMrpInfoVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
+        return page;
+    }
+
+}

+ 43 - 3
hx-wms/src/main/java/com/fjhx/wms/service/stock/impl/StockWaitServiceImpl.java

@@ -12,6 +12,7 @@ import com.fjhx.file.utils.ObsFileUtil;
 import com.fjhx.item.entity.product.po.ProductStockInfo;
 import com.fjhx.item.entity.product.po.ProductStockInfo;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.item.service.product.ProductStockInfoService;
 import com.fjhx.item.service.product.ProductStockInfoService;
+import com.fjhx.wms.entity.contract.po.ContractMrpInfo;
 import com.fjhx.wms.entity.stock.dto.StockJournalDetailsDto;
 import com.fjhx.wms.entity.stock.dto.StockJournalDetailsDto;
 import com.fjhx.wms.entity.stock.dto.StockWaitDto;
 import com.fjhx.wms.entity.stock.dto.StockWaitDto;
 import com.fjhx.wms.entity.stock.dto.StockWaitSelectDto;
 import com.fjhx.wms.entity.stock.dto.StockWaitSelectDto;
@@ -22,6 +23,7 @@ import com.fjhx.wms.entity.stock.vo.StockWaitVo;
 import com.fjhx.wms.entity.warehouse.po.Warehouse;
 import com.fjhx.wms.entity.warehouse.po.Warehouse;
 import com.fjhx.wms.mapper.stock.StockWaitMapper;
 import com.fjhx.wms.mapper.stock.StockWaitMapper;
 import com.fjhx.wms.service.WmsService;
 import com.fjhx.wms.service.WmsService;
+import com.fjhx.wms.service.contract.ContractMrpInfoService;
 import com.fjhx.wms.service.stock.*;
 import com.fjhx.wms.service.stock.*;
 import com.fjhx.wms.service.warehouse.WarehouseService;
 import com.fjhx.wms.service.warehouse.WarehouseService;
 import com.fjhx.wms.utils.CodeEnum;
 import com.fjhx.wms.utils.CodeEnum;
@@ -35,6 +37,7 @@ import com.ruoyi.system.utils.UserUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
@@ -70,6 +73,8 @@ public class StockWaitServiceImpl extends ServiceImpl<StockWaitMapper, StockWait
     private CustomerService customerService;
     private CustomerService customerService;
     @Autowired
     @Autowired
     private WmsService wmsService;
     private WmsService wmsService;
+    @Resource
+    private ContractMrpInfoService contractMrpInfoService;
 
 
     @Override
     @Override
     public Page<StockWaitVo> getPage(StockWaitSelectDto dto) {
     public Page<StockWaitVo> getPage(StockWaitSelectDto dto) {
@@ -230,6 +235,13 @@ public class StockWaitServiceImpl extends ServiceImpl<StockWaitMapper, StockWait
                 .filter(item -> ObjectUtil.isNotEmpty(item.getQuantity()) && item.getQuantity().compareTo(BigDecimal.ZERO) > 0)
                 .filter(item -> ObjectUtil.isNotEmpty(item.getQuantity()) && item.getQuantity().compareTo(BigDecimal.ZERO) > 0)
                 .collect(Collectors.toList());
                 .collect(Collectors.toList());
 
 
+
+        //赋值产品id
+        stockWaitDetailsService.attributeAssign(stockWaitDetailsDtoList, StockWaitDetails::getId, (item, swd) -> {
+            item.setProductId(swd.getProductId());
+        });
+
+
         //更新已出入库数量以及待出入库状态
         //更新已出入库数量以及待出入库状态
         stockWaitDetailsService.changeStockWaitStatus(stockWaitDto);
         stockWaitDetailsService.changeStockWaitStatus(stockWaitDto);
         StockWait stockWait = getById(stockWaitDto.getId());
         StockWait stockWait = getById(stockWaitDto.getId());
@@ -294,21 +306,49 @@ public class StockWaitServiceImpl extends ServiceImpl<StockWaitMapper, StockWait
 
 
         //更新生产状态
         //更新生产状态
         //销售出库 修改生产订单为已出库
         //销售出库 修改生产订单为已出库
-        if (Objects.equals(JournalType.SALE_OUT, JournalType.getByDetailType(stockWait.getBusinessType()))) {
+        if (Objects.equals(JournalType.SALE_OUT, journalType)) {
             List<Long> cpIds = stockWaitDetailsService.listObject(StockWaitDetails::getContractDetailId, q -> q.eq(StockWaitDetails::getStockWaitId, stockWait.getId()));
             List<Long> cpIds = stockWaitDetailsService.listObject(StockWaitDetails::getContractDetailId, q -> q.eq(StockWaitDetails::getStockWaitId, stockWait.getId()));
             Long prodOrderId = stockWait.getProdOrderId();
             Long prodOrderId = stockWait.getProdOrderId();
             wmsService.updateProdStatus(cpIds, prodOrderId);
             wmsService.updateProdStatus(cpIds, prodOrderId);
         }
         }
 
 
         //如果生产订单全部完工入库 自动触发出货申请
         //如果生产订单全部完工入库 自动触发出货申请
-        if (Objects.equals(JournalType.COMPLETION_IN, JournalType.getByDetailType(stockWait.getBusinessType()))) {
+        if (Objects.equals(JournalType.COMPLETION_IN, journalType)) {
             wmsService.saleOutboundByOrderId(stockWait.getProdOrderId());
             wmsService.saleOutboundByOrderId(stockWait.getProdOrderId());
         }
         }
 
 
         //如果是生产领料
         //如果是生产领料
-        if (Objects.equals(JournalType.PROD_OUT, JournalType.getByDetailType(stockWait.getBusinessType()))) {
+        if (Objects.equals(JournalType.PROD_OUT, journalType)) {
             wmsService.beginWorkCheck(stockWait.getProdTaskId());
             wmsService.beginWorkCheck(stockWait.getProdTaskId());
         }
         }
+
+        //操作MRP数据
+        for (StockWaitDetails waitDetails : stockWaitDetailsDtoList) {
+            //如果是生产领料||采购退货
+            if (Objects.equals(JournalType.PROD_OUT, journalType) || Objects.equals(JournalType.PURCHASE_IN, journalType)) {
+                //减少MRP库存
+                contractMrpInfoService.update(q -> q
+                        .eq(ContractMrpInfo::getContractId, stockWait.getContractId())
+                        .eq(ContractMrpInfo::getMaterialId, waitDetails.getProductId())
+                        .setSql("stock_quantity = stock_quantity - " + waitDetails.getQuantity())
+                        .set(ContractMrpInfo::getUpdateTime, new Date())
+                        .set(ContractMrpInfo::getUpdateUser, SecurityUtils.getUserId())
+                );
+            }
+
+            //如果是采购到货
+            if (Objects.equals(JournalType.PURCHASE_IN, journalType)) {
+                //增加MRP库存
+                contractMrpInfoService.update(q -> q
+                        .eq(ContractMrpInfo::getContractId, stockWait.getContractId())
+                        .eq(ContractMrpInfo::getMaterialId, waitDetails.getProductId())
+                        .setSql("stock_quantity = stock_quantity + " + waitDetails.getQuantity())
+                        .set(ContractMrpInfo::getUpdateTime, new Date())
+                        .set(ContractMrpInfo::getUpdateUser, SecurityUtils.getUserId())
+                );
+            }
+        }
+
     }
     }
 
 
     @Override
     @Override

+ 17 - 0
hx-wms/src/main/resources/mapper/contract/ContractMrpInfoMapper.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fjhx.wms.mapper.contract.ContractMrpInfoMapper">
+    <select id="getPage" resultType="com.fjhx.wms.entity.contract.vo.ContractMrpInfoVo">
+        select cmi.id,
+               cmi.contract_id,
+               cmi.material_id,
+               cmi.stock_quantity,
+               cmi.create_user,
+               cmi.create_time,
+               cmi.update_user,
+               cmi.update_time
+        from contract_mrp_info cmi
+            ${ew.customSqlSegment}
+    </select>
+
+</mapper>