Sfoglia il codice sorgente

优化调拨入库

Your Name 2 anni fa
parent
commit
07e4279d63

+ 13 - 0
service-store/src/main/java/com/java110/store/bmo/allocation/IAllocationBMO.java

@@ -0,0 +1,13 @@
+package com.java110.store.bmo.allocation;
+
+import com.java110.dto.purchase.AllocationStorehouseDto;
+
+public interface IAllocationBMO {
+
+    /**
+     * 调拨
+     * @param tmpAllocationStorehouseDto
+     * @param allocationStock
+     */
+    void doToAllocationStorehouse(AllocationStorehouseDto tmpAllocationStorehouseDto, int allocationStock);
+}

+ 139 - 0
service-store/src/main/java/com/java110/store/bmo/allocation/impl/AllocationBMOImpl.java

@@ -0,0 +1,139 @@
+package com.java110.store.bmo.allocation.impl;
+
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.purchase.AllocationStorehouseDto;
+import com.java110.dto.resource.ResourceStoreDto;
+import com.java110.dto.resource.ResourceStoreTimesDto;
+import com.java110.intf.common.IAllocationStorehouseUserInnerServiceSMO;
+import com.java110.intf.store.*;
+import com.java110.po.purchase.ResourceStorePo;
+import com.java110.po.resource.ResourceStoreTimesPo;
+import com.java110.store.bmo.allocation.IAllocationBMO;
+import com.java110.utils.util.BeanConvertUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class AllocationBMOImpl implements IAllocationBMO {
+
+    @Autowired
+    private IAllocationStorehouseApplyInnerServiceSMO allocationStorehouseApplyInnerServiceSMOImpl;
+
+    @Autowired
+    private IResourceStoreTimesV1InnerServiceSMO resourceStoreTimesV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IResourceStoreInnerServiceSMO resourceStoreInnerServiceSMOImpl;
+
+    @Autowired
+    private IAllocationStorehouseUserInnerServiceSMO allocationStorehouseUserInnerServiceSMOImpl;
+
+    @Autowired
+    private IUserStorehouseInnerServiceSMO userStorehouseInnerServiceSMOImpl;
+
+    @Autowired
+    private IAllocationStorehouseApplyV1InnerServiceSMO allocationStorehouseApplyV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IAllocationStorehouseV1InnerServiceSMO allocationStorehouseV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IResourceStoreV1InnerServiceSMO resourceStoreV1InnerServiceSMOImpl;
+
+    @Override
+    public void doToAllocationStorehouse(AllocationStorehouseDto tmpAllocationStorehouseDto, int allocationStock) {
+
+        // todo -------------------------------------------------原仓库中做扣除 (start)-----------------------------------------------------//
+        // todo 原仓库中扣除 数量
+        ResourceStoreDto resourceStoreDto = new ResourceStoreDto();
+        resourceStoreDto.setResCode(tmpAllocationStorehouseDto.getResCode());
+        resourceStoreDto.setShId(tmpAllocationStorehouseDto.getShIda());
+        List<ResourceStoreDto> resourceStoreDtoAs = resourceStoreInnerServiceSMOImpl.queryResourceStores(resourceStoreDto);
+        //todo 这种场景不存在
+        if (resourceStoreDtoAs == null || resourceStoreDtoAs.size() < 1) {
+            return;
+        }
+
+        ResourceStoreTimesDto resourceStoreTimesDto = new ResourceStoreTimesDto();
+        resourceStoreTimesDto.setTimesId(tmpAllocationStorehouseDto.getTimesId());
+        resourceStoreTimesDto.setShId(tmpAllocationStorehouseDto.getShIda());
+        List<ResourceStoreTimesDto> resourceStoreTimesDtoAs = resourceStoreTimesV1InnerServiceSMOImpl.queryResourceStoreTimess(resourceStoreTimesDto);
+        //todo 这种场景不存在
+        if (resourceStoreTimesDtoAs == null || resourceStoreTimesDtoAs.size() < 1) {
+            return;
+        }
+
+        int stockA = Integer.parseInt(resourceStoreDtoAs.get(0).getStock());
+
+        //todo 库存不够时,只能调拨 库存,这种场景应该执行不到 前文做了校验
+        if (stockA < allocationStock) {
+            allocationStock = stockA;
+        }
+        ResourceStorePo resourceStorePo = new ResourceStorePo();
+        resourceStorePo.setResId(resourceStoreDtoAs.get(0).getResId());
+        resourceStorePo.setStoreId(resourceStoreDtoAs.get(0).getStoreId());
+        resourceStorePo.setStock(allocationStock * -1 + "");// 这里去扣出
+        resourceStoreInnerServiceSMOImpl.updateResourceStore(resourceStorePo);
+
+        stockA = Integer.parseInt(resourceStoreTimesDtoAs.get(0).getStock());
+
+        //todo 库存不够时,只能调拨 库存,这种场景应该执行不到 前文做了校验
+        if (stockA < allocationStock) {
+            allocationStock = stockA;
+        }
+
+        ResourceStoreTimesPo resourceStoreTimesPo = new ResourceStoreTimesPo();
+        resourceStoreTimesPo.setPrice(resourceStoreTimesDtoAs.get(0).getPrice());
+        resourceStoreTimesPo.setShId(resourceStoreTimesDtoAs.get(0).getShId());
+        resourceStoreTimesPo.setResCode(resourceStoreTimesDtoAs.get(0).getResCode());
+        resourceStoreTimesPo.setStoreId(resourceStoreTimesDtoAs.get(0).getStoreId());
+        resourceStoreTimesPo.setStock(allocationStock * -1 + "");// 这里去扣出
+        resourceStoreTimesV1InnerServiceSMOImpl.saveOrUpdateResourceStoreTimes(resourceStoreTimesPo);
+        // todo -------------------------------------------------原仓库中做扣除 (end)-----------------------------------------------------//
+
+        // todo -------------------------------------------------目标仓库中做增加 (start)-----------------------------------------------------//
+        //todo 查询目标仓库中 库存
+        resourceStoreDto = new ResourceStoreDto();
+        resourceStoreDto.setResCode(tmpAllocationStorehouseDto.getResCode());
+        resourceStoreDto.setShId(tmpAllocationStorehouseDto.getShIdz());
+        List<ResourceStoreDto> resourceStoreDtoZs = resourceStoreInnerServiceSMOImpl.queryResourceStores(resourceStoreDto);
+        //todo 这种场景不存在
+        if (resourceStoreDtoZs == null || resourceStoreDtoZs.size() < 1) {
+            //todo 添加物品到该仓库
+            ResourceStorePo tmpResourceStorePo = BeanConvertUtil.covertBean(resourceStoreDtoAs.get(0), ResourceStorePo.class);
+            tmpResourceStorePo.setResId(GenerateCodeFactory.getGeneratorId("11"));
+            tmpResourceStorePo.setStock(allocationStock + "");
+            tmpResourceStorePo.setShId(tmpAllocationStorehouseDto.getShIdz());
+            resourceStoreV1InnerServiceSMOImpl.saveResourceStore(tmpResourceStorePo);
+
+            // todo 添加 times
+            ResourceStoreTimesPo tmpResourceStoreTimesPo = BeanConvertUtil.covertBean(resourceStoreTimesDtoAs.get(0), ResourceStoreTimesPo.class);
+            tmpResourceStoreTimesPo.setTimesId(GenerateCodeFactory.getGeneratorId("11"));
+            tmpResourceStoreTimesPo.setStock(allocationStock + "");
+            tmpResourceStoreTimesPo.setShId(tmpAllocationStorehouseDto.getShIdz());
+
+            resourceStoreTimesV1InnerServiceSMOImpl.saveResourceStoreTimes(tmpResourceStoreTimesPo);
+            return;
+        }
+
+        resourceStorePo = new ResourceStorePo();
+        resourceStorePo.setResId(resourceStoreDtoZs.get(0).getResId());
+        resourceStorePo.setStoreId(resourceStoreDtoZs.get(0).getResId());
+        resourceStorePo.setStock(allocationStock + "");// 这里去扣出
+        resourceStoreInnerServiceSMOImpl.updateResourceStore(resourceStorePo);
+
+
+        resourceStoreTimesPo = new ResourceStoreTimesPo();
+        resourceStoreTimesPo.setPrice(resourceStoreTimesDtoAs.get(0).getPrice());
+        resourceStoreTimesPo.setShId(resourceStoreDtoZs.get(0).getShId());
+        resourceStoreTimesPo.setResCode(resourceStoreTimesDtoAs.get(0).getResCode());
+        resourceStoreTimesPo.setStoreId(resourceStoreTimesDtoAs.get(0).getStoreId());
+        resourceStoreTimesPo.setStock(allocationStock + "");// 这里去增加
+        resourceStoreTimesV1InnerServiceSMOImpl.saveOrUpdateResourceStoreTimes(resourceStoreTimesPo);
+        // todo -------------------------------------------------目标仓库中做增加 (end)-----------------------------------------------------//
+
+
+    }
+}

+ 128 - 0
service-store/src/main/java/com/java110/store/cmd/resourceStore/AllocationStoreEnterCmd.java

@@ -0,0 +1,128 @@
+package com.java110.store.cmd.resourceStore;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.purchase.AllocationStorehouseApplyDto;
+import com.java110.dto.purchase.AllocationStorehouseDto;
+import com.java110.dto.resource.ResourceStoreDto;
+import com.java110.dto.resource.ResourceStoreTimesDto;
+import com.java110.dto.store.StorehouseDto;
+import com.java110.intf.common.IAllocationStorehouseUserInnerServiceSMO;
+import com.java110.intf.store.*;
+import com.java110.po.purchase.AllocationStorehouseApplyPo;
+import com.java110.po.purchase.ResourceStorePo;
+import com.java110.po.resource.ResourceStoreTimesPo;
+import com.java110.store.bmo.allocation.IAllocationBMO;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.text.ParseException;
+import java.util.List;
+
+/**
+ * 调拨入库
+ */
+@Java110Cmd(serviceCode = "resourceStore.allocationStoreEnter")
+public class AllocationStoreEnterCmd extends Cmd {
+
+    @Autowired
+    private IAllocationStorehouseApplyInnerServiceSMO allocationStorehouseApplyInnerServiceSMOImpl;
+
+    @Autowired
+    private IResourceStoreTimesV1InnerServiceSMO resourceStoreTimesV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IResourceStoreInnerServiceSMO resourceStoreInnerServiceSMOImpl;
+
+    @Autowired
+    private IAllocationStorehouseUserInnerServiceSMO allocationStorehouseUserInnerServiceSMOImpl;
+
+    @Autowired
+    private IUserStorehouseInnerServiceSMO userStorehouseInnerServiceSMOImpl;
+
+    @Autowired
+    private IAllocationStorehouseApplyV1InnerServiceSMO allocationStorehouseApplyV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IAllocationStorehouseV1InnerServiceSMO allocationStorehouseV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IResourceStoreV1InnerServiceSMO resourceStoreV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IAllocationBMO allocationBMOImpl;
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        Assert.hasKeyAndValue(reqJson, "applyId", "订单ID为空");
+
+        AllocationStorehouseApplyDto allocationStorehouseApplyDto = new AllocationStorehouseApplyDto();
+        allocationStorehouseApplyDto.setApplyId(reqJson.getString("applyId"));
+        List<AllocationStorehouseApplyDto> allocationStorehouseDtos
+                = allocationStorehouseApplyInnerServiceSMOImpl.queryAllocationStorehouseApplys(allocationStorehouseApplyDto);
+        Assert.listOnlyOne(allocationStorehouseDtos, "调拨申请单存在多条");
+
+        if (reqJson.containsKey("resourceStores")) {
+            throw new CmdException("未包含物品");
+        }
+        JSONArray resourceStores = reqJson.getJSONArray("resourceStores");
+
+        if (resourceStores == null || resourceStores.size() < 1) {
+            throw new CmdException("未包含物品");
+        }
+        JSONObject resourceStore = null;
+        ResourceStoreTimesDto resourceStoreTimesDto = null;
+        List<ResourceStoreTimesDto> resourceStoreTimesDtos = null;
+        int originStock = 0;
+        for (int detailIndex = 0; detailIndex < resourceStores.size(); detailIndex++) {
+            resourceStore = resourceStores.getJSONObject(detailIndex);
+            Assert.hasKeyAndValue(resourceStore, "quantity", "调拨数量未包含");
+            Assert.hasKeyAndValue(resourceStore, "shIda", "原仓库不存在");
+            Assert.hasKeyAndValue(resourceStore, "shIdz", "目标仓库不存在");
+            Assert.hasKeyAndValue(resourceStore, "timesId", "单价未填写");
+            Assert.hasKeyAndValue(resourceStore, "resCode", "物品编码未填写");
+            Assert.hasKeyAndValue(resourceStore, "asId", "调拨明细未填写");
+
+
+            resourceStoreTimesDto = new ResourceStoreTimesDto();
+            resourceStoreTimesDto.setTimesId(resourceStore.getString("timesId"));
+            resourceStoreTimesDto.setShId(resourceStore.getString("shIda"));
+            resourceStoreTimesDtos = resourceStoreTimesV1InnerServiceSMOImpl.queryResourceStoreTimess(resourceStoreTimesDto);
+
+            Assert.listOnlyOne(resourceStoreTimesDtos, "物品不存在");
+            originStock = Integer.parseInt(resourceStoreTimesDtos.get(0).getStock());
+            if(originStock < resourceStore.getIntValue("quantity")){
+                throw new CmdException(reqJson.getString("resCode")+"库存不足");
+            }
+        }
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+
+
+
+        JSONArray resourceStores = reqJson.getJSONArray("resourceStores");
+        JSONObject resourceStore = null;
+        int quantity = 0;
+        for (int detailIndex = 0; detailIndex < resourceStores.size(); detailIndex++) {
+            resourceStore = resourceStores.getJSONObject(detailIndex);
+            //todo 查询调拨记录
+            AllocationStorehouseDto allocationStorehouseDto = new AllocationStorehouseDto();
+            allocationStorehouseDto.setApplyId(reqJson.getString("applyId"));
+            allocationStorehouseDto.setAsId(reqJson.getString("asId"));
+            List<AllocationStorehouseDto> allocationStorehouseDtos = allocationStorehouseV1InnerServiceSMOImpl.queryAllocationStorehouses(allocationStorehouseDto);
+            quantity = resourceStore.getIntValue("quantity");
+            //todo 每条记录调拨
+            allocationBMOImpl.doToAllocationStorehouse(allocationStorehouseDtos.get(0), quantity);
+        }
+    }
+
+}

+ 5 - 102
service-store/src/main/java/com/java110/store/cmd/resourceStore/SaveAllocationStorehouseCmd.java

@@ -28,6 +28,7 @@ import com.java110.po.purchase.AllocationStorehouseApplyPo;
 import com.java110.po.purchase.ResourceStorePo;
 import com.java110.po.resource.ResourceStoreTimesPo;
 import com.java110.po.user.UserStorehousePo;
+import com.java110.store.bmo.allocation.IAllocationBMO;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.lock.DistributedLock;
 import com.java110.utils.util.Assert;
@@ -85,6 +86,9 @@ public class SaveAllocationStorehouseCmd extends Cmd {
     @Autowired
     private IOaWorkflowActivitiInnerServiceSMO oaWorkflowActivitiInnerServiceSMOImpl;
 
+    @Autowired
+    private IAllocationBMO allocationBMOImpl;
+
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
         Assert.hasKeyAndValue(reqJson, "remark", "请求报文中未包含申请信息");
@@ -308,109 +312,8 @@ public class SaveAllocationStorehouseCmd extends Cmd {
         for (AllocationStorehouseDto tmpAllocationStorehouseDto : allocationStorehouseDtos) {
             int allocationStock = Integer.parseInt(tmpAllocationStorehouseDto.getStock());
             //todo 每条记录调拨
-            doToAllocationStorehouse(tmpAllocationStorehouseDto, allocationStock);
-        }
-    }
-
-    /**
-     * 调拨实现
-     *
-     * @param tmpAllocationStorehouseDto
-     * @param allocationStock
-     */
-    private void doToAllocationStorehouse(AllocationStorehouseDto tmpAllocationStorehouseDto, int allocationStock) {
-
-
-        // todo -------------------------------------------------原仓库中做扣除 (start)-----------------------------------------------------//
-        // todo 原仓库中扣除 数量
-        ResourceStoreDto resourceStoreDto = new ResourceStoreDto();
-        resourceStoreDto.setResCode(tmpAllocationStorehouseDto.getResCode());
-        resourceStoreDto.setShId(tmpAllocationStorehouseDto.getShIda());
-        List<ResourceStoreDto> resourceStoreDtoAs = resourceStoreInnerServiceSMOImpl.queryResourceStores(resourceStoreDto);
-        //todo 这种场景不存在
-        if (resourceStoreDtoAs == null || resourceStoreDtoAs.size() < 1) {
-            return;
-        }
-
-        ResourceStoreTimesDto resourceStoreTimesDto = new ResourceStoreTimesDto();
-        resourceStoreTimesDto.setTimesId(tmpAllocationStorehouseDto.getTimesId());
-        resourceStoreTimesDto.setShId(tmpAllocationStorehouseDto.getShIda());
-        List<ResourceStoreTimesDto> resourceStoreTimesDtoAs = resourceStoreTimesV1InnerServiceSMOImpl.queryResourceStoreTimess(resourceStoreTimesDto);
-        //todo 这种场景不存在
-        if (resourceStoreTimesDtoAs == null || resourceStoreTimesDtoAs.size() < 1) {
-            return;
+            allocationBMOImpl.doToAllocationStorehouse(tmpAllocationStorehouseDto, allocationStock);
         }
-
-        int stockA = Integer.parseInt(resourceStoreDtoAs.get(0).getStock());
-
-        //todo 库存不够时,只能调拨 库存,这种场景应该执行不到 前文做了校验
-        if (stockA < allocationStock) {
-            allocationStock = stockA;
-        }
-        ResourceStorePo resourceStorePo = new ResourceStorePo();
-        resourceStorePo.setResId(resourceStoreDtoAs.get(0).getResId());
-        resourceStorePo.setStoreId(resourceStoreDtoAs.get(0).getStoreId());
-        resourceStorePo.setStock(allocationStock * -1 + "");// 这里去扣出
-        resourceStoreInnerServiceSMOImpl.updateResourceStore(resourceStorePo);
-
-        stockA = Integer.parseInt(resourceStoreTimesDtoAs.get(0).getStock());
-
-        //todo 库存不够时,只能调拨 库存,这种场景应该执行不到 前文做了校验
-        if (stockA < allocationStock) {
-            allocationStock = stockA;
-        }
-
-        ResourceStoreTimesPo resourceStoreTimesPo = new ResourceStoreTimesPo();
-        resourceStoreTimesPo.setPrice(resourceStoreTimesDtoAs.get(0).getPrice());
-        resourceStoreTimesPo.setShId(resourceStoreTimesDtoAs.get(0).getShId());
-        resourceStoreTimesPo.setResCode(resourceStoreTimesDtoAs.get(0).getResCode());
-        resourceStoreTimesPo.setStoreId(resourceStoreTimesDtoAs.get(0).getStoreId());
-        resourceStoreTimesPo.setStock(allocationStock * -1 + "");// 这里去扣出
-        resourceStoreTimesV1InnerServiceSMOImpl.saveOrUpdateResourceStoreTimes(resourceStoreTimesPo);
-        // todo -------------------------------------------------原仓库中做扣除 (end)-----------------------------------------------------//
-
-        // todo -------------------------------------------------目标仓库中做增加 (start)-----------------------------------------------------//
-        //todo 查询目标仓库中 库存
-        resourceStoreDto = new ResourceStoreDto();
-        resourceStoreDto.setResCode(tmpAllocationStorehouseDto.getResCode());
-        resourceStoreDto.setShId(tmpAllocationStorehouseDto.getShIdz());
-        List<ResourceStoreDto> resourceStoreDtoZs = resourceStoreInnerServiceSMOImpl.queryResourceStores(resourceStoreDto);
-        //todo 这种场景不存在
-        if (resourceStoreDtoZs == null || resourceStoreDtoZs.size() < 1) {
-            //todo 添加物品到该仓库
-            ResourceStorePo tmpResourceStorePo = BeanConvertUtil.covertBean(resourceStoreDtoAs.get(0), ResourceStorePo.class);
-            tmpResourceStorePo.setResId(GenerateCodeFactory.getGeneratorId("11"));
-            tmpResourceStorePo.setStock(allocationStock + "");
-            tmpResourceStorePo.setShId(tmpAllocationStorehouseDto.getShIdz());
-            resourceStoreV1InnerServiceSMOImpl.saveResourceStore(tmpResourceStorePo);
-
-            // todo 添加 times
-            ResourceStoreTimesPo tmpResourceStoreTimesPo = BeanConvertUtil.covertBean(resourceStoreTimesDtoAs.get(0), ResourceStoreTimesPo.class);
-            tmpResourceStoreTimesPo.setTimesId(GenerateCodeFactory.getGeneratorId("11"));
-            tmpResourceStoreTimesPo.setStock(allocationStock + "");
-            tmpResourceStoreTimesPo.setShId(tmpAllocationStorehouseDto.getShIdz());
-
-            resourceStoreTimesV1InnerServiceSMOImpl.saveResourceStoreTimes(tmpResourceStoreTimesPo);
-            return;
-        }
-
-        resourceStorePo = new ResourceStorePo();
-        resourceStorePo.setResId(resourceStoreDtoZs.get(0).getResId());
-        resourceStorePo.setStoreId(resourceStoreDtoZs.get(0).getResId());
-        resourceStorePo.setStock(allocationStock + "");// 这里去扣出
-        resourceStoreInnerServiceSMOImpl.updateResourceStore(resourceStorePo);
-
-
-        resourceStoreTimesPo = new ResourceStoreTimesPo();
-        resourceStoreTimesPo.setPrice(resourceStoreTimesDtoAs.get(0).getPrice());
-        resourceStoreTimesPo.setShId(resourceStoreDtoZs.get(0).getShId());
-        resourceStoreTimesPo.setResCode(resourceStoreTimesDtoAs.get(0).getResCode());
-        resourceStoreTimesPo.setStoreId(resourceStoreTimesDtoAs.get(0).getStoreId());
-        resourceStoreTimesPo.setStock(allocationStock + "");// 这里去增加
-        resourceStoreTimesV1InnerServiceSMOImpl.saveOrUpdateResourceStoreTimes(resourceStoreTimesPo);
-        // todo -------------------------------------------------目标仓库中做增加 (end)-----------------------------------------------------//
-
-
     }
 
     /**