From 8c61d5e2c0bdaf815a666a643079896e49520055 Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: 星期二, 30 五月 2023 02:28:21 +0800
Subject: [PATCH] 优化代码

---
 service-store/src/main/java/com/java110/store/cmd/purchase/UrgentPurchaseApplyCmd.java |   74 ++++++++++++++++++++++++++++++++----
 1 files changed, 65 insertions(+), 9 deletions(-)

diff --git a/service-store/src/main/java/com/java110/store/cmd/purchase/UrgentPurchaseApplyCmd.java b/service-store/src/main/java/com/java110/store/cmd/purchase/UrgentPurchaseApplyCmd.java
index c7599d8..f38e201 100644
--- a/service-store/src/main/java/com/java110/store/cmd/purchase/UrgentPurchaseApplyCmd.java
+++ b/service-store/src/main/java/com/java110/store/cmd/purchase/UrgentPurchaseApplyCmd.java
@@ -3,18 +3,23 @@
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.annotation.Java110Transactional;
 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.CommunitySettingFactory;
 import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.dto.allocationStorehouse.AllocationStorehouseDto;
-import com.java110.dto.allocationStorehouseApply.AllocationStorehouseApplyDto;
+import com.java110.dto.allocationStorehouse.AllocationStorehouseApplyDto;
 import com.java110.dto.purchaseApply.PurchaseApplyDto;
 import com.java110.dto.resourceStore.ResourceStoreDto;
+import com.java110.dto.user.UserDto;
 import com.java110.intf.store.*;
+import com.java110.intf.user.IUserV1InnerServiceSMO;
 import com.java110.po.purchase.PurchaseApplyDetailPo;
 import com.java110.po.purchase.PurchaseApplyPo;
 import com.java110.po.purchase.ResourceStorePo;
+import com.java110.po.resourceStoreTimes.ResourceStoreTimesPo;
 import com.java110.store.bmo.purchase.IPurchaseApplyBMO;
 import com.java110.utils.cache.MappingCache;
 import com.java110.utils.exception.CmdException;
@@ -22,6 +27,7 @@
 import com.java110.utils.util.BeanConvertUtil;
 import com.java110.utils.util.DateUtil;
 import com.java110.utils.util.StringUtil;
+import com.java110.vo.ResultVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 
@@ -57,6 +63,12 @@
     @Autowired
     private IPurchaseApplyBMO purchaseApplyBMOImpl;
 
+    @Autowired
+    private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IResourceStoreTimesV1InnerServiceSMO resourceStoreTimesV1InnerServiceSMOImpl;
+
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
         Assert.hasKeyAndValue(reqJson, "resourceStores", "蹇呭~锛岃濉啓鐢宠閲囪喘鐨勭墿璧�");
@@ -64,10 +76,28 @@
         Assert.hasKeyAndValue(reqJson, "resOrderType", "蹇呭~锛岃濉啓鐢宠绫诲瀷");
     }
 
+    /**
+     * 绱ф�ラ噰璐�-浠撳簱鐗╁搧鍏ュ簱
+     * @param event              浜嬩欢瀵硅薄
+     * @param context 鏁版嵁涓婃枃瀵硅薄
+     * @param reqJson            璇锋眰鎶ユ枃
+     * @throws CmdException
+     */
     @Override
+    @Java110Transactional
     public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
         String userId = context.getReqHeaders().get("user-id");
         String userName = context.getReqHeaders().get("user-name");
+        UserDto userDto = new UserDto();
+        userDto.setUserId(userId);
+        userDto.setRow(1);
+        userDto.setPage(1);
+        List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
+
+        Assert.listOnlyOne(userDtos,"鐢ㄦ埛涓嶅瓨鍦�");
+
+        userName = userDtos.get(0).getName();
+
         String storeId = context.getReqHeaders().get("store-id");
         PurchaseApplyDto purchaseApplyDto = new PurchaseApplyDto();
         purchaseApplyDto.setResOrderType(reqJson.getString("resOrderType"));
@@ -80,13 +110,18 @@
         //鏌ヨ褰撴湀绱ф�ラ噰璐殑娆℃暟
         int count = purchaseApplyInnerServiceSMOImpl.queryPurchaseApplysCount(purchaseApplyDto);
         //鍙栧嚭寮�鍏虫槧灏勭殑鍊�
-        String value = MappingCache.getValue(DOMAIN_COMMON, URGRNT_NUMBER);
+        String value = CommunitySettingFactory.getValue(purchaseApplyDto.getCommunityId(), URGRNT_NUMBER);
+        if (StringUtil.isEmpty(value)) {
+            value = MappingCache.getValue(DOMAIN_COMMON, URGRNT_NUMBER);
+        }
         if (StringUtil.isEmpty(value)) {
             throw new IllegalArgumentException("鏄犲皠鍊间负绌猴紒");
         }
         int number = Integer.parseInt(value);
         if (count >= number) {
-            throw new IllegalArgumentException("鏈湀绱ф�ラ噰璐鏁板凡瓒呰繃" + number + "娆★紝璇蜂笅鏈堝啀浣跨敤锛�");
+            ResponseEntity<String> responseEntity = ResultVo.createResponseEntity(ResultVo.CODE_BUSINESS_VERIFICATION, "鏈湀绱ф�ラ噰璐鏁板凡瓒呰繃" + number + "娆★紝璇蜂笅鏈堝啀浣跨敤锛�");
+            context.setResponseEntity(responseEntity);
+            return;
         }
         PurchaseApplyPo purchaseApplyPo = new PurchaseApplyPo();
         purchaseApplyPo.setApplyOrderId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_applyOrderId));
@@ -134,13 +169,24 @@
             resourceStorePo.setResOrderType(PurchaseApplyDto.WAREHOUSING_TYPE_URGENT);
             resourceStorePo.setOperationType(PurchaseApplyDto.WEIGHTED_MEAN_TRUE);
             resourceStoreInnerServiceSMOImpl.updateResourceStore(resourceStorePo);
-            if (resourceStoreDtos != null && resourceStoreDtos.size() == 1) {
-                //鐢熸垚璋冩嫧璁板綍
-                AllocationStorehouseDto allocationStorehouseDto = new AllocationStorehouseDto();
+            // 淇濆瓨鑷� 鐗╁搧 times琛�  (璋冩暣鍘熶粨搴� 鎵规)
+            ResourceStoreTimesPo resourceStoreTimesPo1 = new ResourceStoreTimesPo();
+            resourceStoreTimesPo1.setApplyOrderId(purchaseApplyPo.getApplyOrderId());
+            resourceStoreTimesPo1.setPrice(purchaseApplyDetailPo.getPrice());//閲囪喘浠�
+            resourceStoreTimesPo1.setResCode(resourceStore.getString("resCode"));
+            resourceStoreTimesPo1.setStock("0");
+            resourceStoreTimesPo1.setStoreId(storeId);
+            resourceStoreTimesPo1.setShId(resourceStore.getString("shId"));
+            resourceStoreTimesV1InnerServiceSMOImpl.saveOrUpdateResourceStoreTimes(resourceStoreTimesPo1);
+
+            AllocationStorehouseDto allocationStorehouseDto = new AllocationStorehouseDto();
+
+            if (resourceStoreDtos != null && resourceStoreDtos.size() == 1) {//鐩爣浠撳簱鏈夋鐗╁搧
+                //鐢熸垚璋冩嫧璇︽儏璁板綍
                 allocationStorehouseDto.setAsId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_allocationStorehouseId));
                 allocationStorehouseDto.setbId("-1");
-                allocationStorehouseDto.setShIda(resourceStore.getString("shId"));
-                allocationStorehouseDto.setShIdz(resourceStore.getString("shzId"));//灏忓尯浠撳簱
+                allocationStorehouseDto.setShIda(resourceStore.getString("shId"));//鍘熶粨搴�
+                allocationStorehouseDto.setShIdz(resourceStore.getString("shzId"));//鐩爣浠撳簱
                 allocationStorehouseDto.setResId(resourceStoreDtos.get(0).getResId());
                 allocationStorehouseDto.setResName(resourceStoreDtos.get(0).getResName());
                 allocationStorehouseDto.setStoreId(storeId);
@@ -200,11 +246,12 @@
                 BigDecimal newMiniStock = purchaseQuantity.multiply(miniUnitStock).add(miniStock);
                 resourceStorePo1.setMiniStock(String.valueOf(newMiniStock));
                 resourceStoreInnerServiceSMOImpl.updateResourceStore(resourceStorePo1);
+
+
             } else if (resourceStoreDtos != null && resourceStoreDtos.size() > 1) {
                 throw new IllegalArgumentException("鏌ヨ鍟嗗搧閿欒锛�");
             } else {
                 //鐢熸垚璋冩嫧璁板綍
-                AllocationStorehouseDto allocationStorehouseDto = new AllocationStorehouseDto();
                 allocationStorehouseDto.setAsId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_allocationStorehouseId));
                 allocationStorehouseDto.setbId("-1");
                 allocationStorehouseDto.setShIda(resourceStore.getString("shId"));
@@ -259,6 +306,15 @@
                 resourceStoreDto1.setMiniStock(String.valueOf(miniStock));
                 resourceStoreInnerServiceSMOImpl.saveResourceStore(resourceStoreDto1);
             }
+            // 淇濆瓨鑷� 鐗╁搧 times琛�  (璋冩暣鐩爣浠撳簱 鎵规)
+            ResourceStoreTimesPo resourceStoreTimesPo = new ResourceStoreTimesPo();
+            resourceStoreTimesPo.setApplyOrderId(allocationStorehouseDto.getApplyId());
+            resourceStoreTimesPo.setPrice(purchaseApplyDetailPo.getPrice());
+            resourceStoreTimesPo.setResCode(resourceStore.getString("resCode"));
+            resourceStoreTimesPo.setStock(purchaseApplyDetailPo.getQuantity());
+            resourceStoreTimesPo.setStoreId(storeId);
+            resourceStoreTimesPo.setShId(resourceStore.getString("shzId"));
+            resourceStoreTimesV1InnerServiceSMOImpl.saveOrUpdateResourceStoreTimes(resourceStoreTimesPo);
         }
         purchaseApplyPo.setPurchaseApplyDetailPos(purchaseApplyDetailPos);
         ResponseEntity responseEntity = purchaseApplyBMOImpl.apply(purchaseApplyPo, reqJson);

--
Gitblit v1.8.0