From 3d8ec5c23ef49d0908195c8b5b892920a46aaa8c Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 30 五月 2023 11:42:48 +0800
Subject: [PATCH] Merge branch 'master' of http://git.homecommunity.cn/supervip/MicroCommunity
---
service-store/src/main/java/com/java110/store/cmd/resourceStore/SaveAllocationStorehouseCmd.java | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 100 insertions(+), 3 deletions(-)
diff --git a/service-store/src/main/java/com/java110/store/cmd/resourceStore/SaveAllocationStorehouseCmd.java b/service-store/src/main/java/com/java110/store/cmd/resourceStore/SaveAllocationStorehouseCmd.java
index a06ad58..e22d695 100644
--- a/service-store/src/main/java/com/java110/store/cmd/resourceStore/SaveAllocationStorehouseCmd.java
+++ b/service-store/src/main/java/com/java110/store/cmd/resourceStore/SaveAllocationStorehouseCmd.java
@@ -5,18 +5,22 @@
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.context.ICmdDataFlowContext;
-import com.java110.core.event.cmd.AbstractServiceCmdListener;
+import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
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.resourceStore.ResourceStoreDto;
+import com.java110.dto.resourceStoreTimes.ResourceStoreTimesDto;
+import com.java110.dto.user.UserDto;
import com.java110.dto.userStorehouse.UserStorehouseDto;
import com.java110.intf.common.IAllocationStorehouseUserInnerServiceSMO;
import com.java110.intf.store.*;
+import com.java110.intf.user.IUserV1InnerServiceSMO;
import com.java110.po.allocationStorehouse.AllocationStorehousePo;
import com.java110.po.allocationStorehouseApply.AllocationStorehouseApplyPo;
import com.java110.po.purchase.ResourceStorePo;
+import com.java110.po.resourceStoreTimes.ResourceStoreTimesPo;
import com.java110.po.userStorehouse.UserStorehousePo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.lock.DistributedLock;
@@ -36,7 +40,7 @@
*
*/
@Java110Cmd(serviceCode = "resourceStore.saveAllocationStorehouse")
-public class SaveAllocationStorehouseCmd extends AbstractServiceCmdListener {
+public class SaveAllocationStorehouseCmd extends Cmd {
@Autowired
private IResourceStoreInnerServiceSMO resourceStoreInnerServiceSMOImpl;
@@ -58,6 +62,12 @@
@Autowired
private IUserStorehouseV1InnerServiceSMO userStorehouseV1InnerServiceSMOImpl;
+
+ @Autowired
+ private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
+
+ @Autowired
+ private IResourceStoreTimesV1InnerServiceSMO resourceStoreTimesV1InnerServiceSMOImpl;
@Override
public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
@@ -129,12 +139,29 @@
}
}
+ /**
+ * 璋冩嫧鐢宠-璋冩嫧鐢宠鍙戣捣
+ * @param event 浜嬩欢瀵硅薄
+ * @param cmdDataFlowContext
+ * @param reqJson 璇锋眰鎶ユ枃
+ * @throws CmdException
+ */
@Override
@Java110Transactional
public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
int flag = 0;
//鑾峰彇璋冩嫧杩旇繕鐘舵�佹爣璇�
String applyType = reqJson.getString("apply_type");
+
+ // 鏌ヨ鐢ㄦ埛鍚嶇О
+ UserDto userDto = new UserDto();
+ userDto.setUserId(reqJson.getString("userId"));
+ List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto);
+
+ Assert.listOnlyOne(userDtos, "鐢ㄦ埛涓嶅瓨鍦�");
+ reqJson.put("userName", userDtos.get(0).getName());
+
+
//灏佽璋冩嫧瀵硅薄
AllocationStorehouseApplyPo allocationStorehouseApplyPo = covertAllocationStorehouseApply(reqJson);
JSONArray resourceStores = reqJson.getJSONArray("resourceStores");
@@ -274,6 +301,21 @@
if (flag < 1) {
throw new CmdException("淇濆瓨淇敼鐗╁搧澶辫触");
}
+ // 淇濆瓨鑷� 鐗╁搧 times琛�
+ //鏌ヨ璋冩嫧鎵规浠锋牸
+ ResourceStoreTimesDto resourceStoreTimesDto = new ResourceStoreTimesDto();
+ resourceStoreTimesDto.setTimesId(resObj.getString("timesId"));
+ List<ResourceStoreTimesDto> resourceStoreTimesDtos = resourceStoreTimesV1InnerServiceSMOImpl.queryResourceStoreTimess(resourceStoreTimesDto);
+
+ ResourceStoreTimesPo resourceStoreTimesPo = new ResourceStoreTimesPo();
+ resourceStoreTimesPo.setApplyOrderId(GenerateCodeFactory.getGeneratorId("10"));
+ resourceStoreTimesPo.setPrice(resourceStoreTimesDtos.get(0).getPrice());
+ resourceStoreTimesPo.setStock(resObj.getString("curStock"));
+ resourceStoreTimesPo.setResCode(resObj.getString("resCode"));
+ resourceStoreTimesPo.setStoreId(reqJson.getString("storeId"));
+ resourceStoreTimesPo.setTimesId(GenerateCodeFactory.getGeneratorId("10"));
+ resourceStoreTimesPo.setShId(resObj.getString("shzId"));
+ resourceStoreTimesV1InnerServiceSMOImpl.saveOrUpdateResourceStoreTimes(resourceStoreTimesPo);
}
} else { //濡傛灉鐩爣浠撳簱涓嬫病鏈夎繖涓墿鍝佷俊鎭紝灏辨彃鍏ヤ竴鏉$墿鍝佷俊鎭�
ResourceStoreDto resourceStore = new ResourceStoreDto();
@@ -324,6 +366,26 @@
if (flag < 1) {
throw new CmdException("淇濆瓨淇敼鐗╁搧澶辫触");
}
+
+
+ // 淇濆瓨鑷� 鐗╁搧 times琛�
+ //鏌ヨ璋冩嫧鎵规浠锋牸
+ ResourceStoreTimesDto resourceStoreTimesDto = new ResourceStoreTimesDto();
+ resourceStoreTimesDto.setTimesId(resObj.getString("timesId"));
+ List<ResourceStoreTimesDto> resourceStoreTimesDtos = resourceStoreTimesV1InnerServiceSMOImpl.queryResourceStoreTimess(resourceStoreTimesDto);
+
+ ResourceStoreTimesPo resourceStoreTimesPo = new ResourceStoreTimesPo();
+ resourceStoreTimesPo.setApplyOrderId(GenerateCodeFactory.getGeneratorId("10"));
+ resourceStoreTimesPo.setPrice(resourceStoreTimesDtos.get(0).getPrice());
+ resourceStoreTimesPo.setStock(resObj.getString("curStock"));
+ resourceStoreTimesPo.setResCode(resourceStoreList.get(0).getResCode());
+ resourceStoreTimesPo.setStoreId(reqJson.getString("storeId"));
+ resourceStoreTimesPo.setTimesId(GenerateCodeFactory.getGeneratorId("10"));
+ resourceStoreTimesPo.setShId(resObj.getString("shzId"));
+ resourceStoreTimesV1InnerServiceSMOImpl.saveOrUpdateResourceStoreTimes(resourceStoreTimesPo);
+
+
+
}
}
@@ -370,6 +432,9 @@
BigDecimal oldCurStore = new BigDecimal(allocationStorehouseApplyPo.getApplyCount());
oldCurStore = oldCurStore.add(new BigDecimal(resObj.getString("curStock")));
allocationStorehouseApplyPo.setApplyCount(oldCurStore.toString());
+ //鍔犲叆 浠庡簱瀛樹腑鎵e噺
+ subResourceStoreTimesStock(resObj);
+
} finally {
DistributedLock.releaseDistributedLock(requestId, key);
}
@@ -396,6 +461,7 @@
allocationStorehousePo.setRemark(reqJson.getString("remark"));
allocationStorehousePo.setStartUserId(reqJson.getString("userId"));
allocationStorehousePo.setStartUserName(reqJson.getString("userName"));
+ allocationStorehousePo.setTimesId(resObj.getString("timesId"));
int flag = allocationStorehouseV1InnerServiceSMOImpl.saveAllocationStorehouse(allocationStorehousePo);
if (flag < 1) {
@@ -430,4 +496,35 @@
return allocationStorehouseApplyPo;
}
+
+ /**
+ * 浠巘imes涓墸鍑�
+ *
+ * @param resObj
+ */
+ private void subResourceStoreTimesStock(JSONObject resObj) {
+ String applyQuantity = resObj.getString("curStock");
+ ResourceStoreTimesDto resourceStoreTimesDto = new ResourceStoreTimesDto();
+ resourceStoreTimesDto.setResCode(resObj.getString("resCode"));
+ resourceStoreTimesDto.setTimesId(resObj.getString("timesId"));
+ List<ResourceStoreTimesDto> resourceStoreTimesDtos = resourceStoreTimesV1InnerServiceSMOImpl.queryResourceStoreTimess(resourceStoreTimesDto);
+
+ if (resourceStoreTimesDtos == null || resourceStoreTimesDtos.size() < 1) {
+ return;
+ }
+ int stock = 0;
+ int quantity = Integer.parseInt(applyQuantity);
+ ResourceStoreTimesPo resourceStoreTimesPo = null;
+
+ stock = Integer.parseInt(resourceStoreTimesDtos.get(0).getStock());
+ if (stock < quantity) {
+ throw new CmdException(resourceStoreTimesDtos.get(0).getResCode() + "浠锋牸涓猴細" + resourceStoreTimesDtos.get(0).getPrice() + "鐨勫簱瀛�" + resourceStoreTimesDtos.get(0).getStock() + ",搴撳瓨涓嶈冻");
+ }
+
+ stock = stock - quantity;
+ resourceStoreTimesPo = new ResourceStoreTimesPo();
+ resourceStoreTimesPo.setTimesId(resourceStoreTimesDtos.get(0).getTimesId());
+ resourceStoreTimesPo.setStock(stock + "");
+ resourceStoreTimesV1InnerServiceSMOImpl.updateResourceStoreTimes(resourceStoreTimesPo);
+ }
}
--
Gitblit v1.8.0