From 05683f2b2bdbdbe21cf17ad523c21ab338bd1c54 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期二, 19 七月 2022 21:49:55 +0800
Subject: [PATCH] 优化添加设备 功能
---
service-store/src/main/java/com/java110/store/api/PurchaseApi.java | 235 ++++------------------------------------------------------
1 files changed, 16 insertions(+), 219 deletions(-)
diff --git a/service-store/src/main/java/com/java110/store/api/PurchaseApi.java b/service-store/src/main/java/com/java110/store/api/PurchaseApi.java
index ef94d2e..9fee1fd 100755
--- a/service-store/src/main/java/com/java110/store/api/PurchaseApi.java
+++ b/service-store/src/main/java/com/java110/store/api/PurchaseApi.java
@@ -23,6 +23,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+import java.math.BigDecimal;
import java.util.*;
@RestController
@@ -100,12 +101,19 @@
purchaseApplyDetailPos.add(purchaseApplyDetailPo);
}
purchaseApplyPo.setPurchaseApplyDetailPos(purchaseApplyDetailPos);
- return purchaseApplyBMOImpl.apply(purchaseApplyPo);
+ return purchaseApplyBMOImpl.apply(purchaseApplyPo,reqJson);
}
@RequestMapping(value = "/resourceEnter", method = RequestMethod.POST)
public ResponseEntity<String> resourceEnter(@RequestBody JSONObject reqJson) {
Assert.hasKeyAndValue(reqJson, "applyOrderId", "璁㈠崟ID涓虹┖");
+ PurchaseApplyDto purchaseApplyDto = new PurchaseApplyDto();
+ purchaseApplyDto.setApplyOrderId(reqJson.getString("applyOrderId"));
+ purchaseApplyDto.setStatusCd("0");
+ List<PurchaseApplyDto> purchaseApplyDtoList = purchaseApplyInnerServiceSMOImpl.queryPurchaseApplys(purchaseApplyDto);
+ if(purchaseApplyDtoList!=null && PurchaseApplyDto.STATE_AUDITED.equals(purchaseApplyDtoList.get(0).getState())){
+ throw new IllegalArgumentException("璇ヨ鍗曞凡缁忓鐞嗭紝璇峰埛鏂扮‘璁よ鍗曠姸鎬侊紒");
+ }
JSONArray purchaseApplyDetails = reqJson.getJSONArray("purchaseApplyDetailVo");
List<PurchaseApplyDetailPo> purchaseApplyDetailPos = new ArrayList<>();
for (int detailIndex = 0; detailIndex < purchaseApplyDetails.size(); detailIndex++) {
@@ -173,236 +181,25 @@
resourceStorePo.setStock(purchaseApplyDetailPo.getPurchaseQuantity());
resourceStorePo.setResOrderType(PurchaseApplyDto.RES_ORDER_TYPE_ENTER);
//鑾峰彇閲囪喘鏁伴噺
- double purchaseQuantity = Double.parseDouble(purchaseApplyDetailPo.getPurchaseQuantity());
+ BigDecimal purchaseQuantity = new BigDecimal(purchaseApplyDetailPo.getPurchaseQuantity());
//鑾峰彇鍘熸湁鏈�灏忚閲忔�绘暟
- double miniStock = Double.parseDouble(resourceStore.getString("miniStock"));
+ BigDecimal miniStock = new BigDecimal(resourceStore.getString("miniStock"));
//鑾峰彇鏈�灏忓崟浣嶆暟閲�
- double newMiniStock = 0.0;
+ BigDecimal newMiniStock = new BigDecimal(0);
if (StringUtil.isEmpty(resourceStore.getString("miniUnitStock"))) {
throw new IllegalArgumentException("鏈�灏忚閲忓崟浣嶆暟閲忎笉鑳戒负绌猴紒");
}
- double miniUnitStock = Double.parseDouble(resourceStore.getString("miniUnitStock"));
+ BigDecimal miniUnitStock = new BigDecimal(resourceStore.getString("miniUnitStock"));
//璁$畻鏈�灏忚閲忔�绘暟
if (StringUtil.isEmpty(resourceStore.getString("miniStock"))) {
- newMiniStock = purchaseQuantity * miniUnitStock;
+ newMiniStock = purchaseQuantity.multiply(miniUnitStock);
} else {
- newMiniStock = (purchaseQuantity * miniUnitStock) + miniStock;
+ newMiniStock = (purchaseQuantity.multiply(miniUnitStock)).add(miniStock);
}
resourceStorePo.setMiniStock(String.valueOf(newMiniStock));
resourceStoreInnerServiceSMOImpl.updateResourceStore(resourceStorePo);
}
purchaseApplyPo.setPurchaseApplyDetailPos(purchaseApplyDetailPos);
- return purchaseApplyBMOImpl.apply(purchaseApplyPo);
- }
-
- /**
- * 绱ф�ラ噰璐叆搴�
- *
- * @author fqz
- * @date 2021-07-07 15:46
- */
- @RequestMapping(value = "/urgentPurchaseApply", method = RequestMethod.POST)
- public ResponseEntity<String> urgentPurchaseApply(@RequestBody JSONObject reqJson,
- @RequestHeader(value = "user-id") String userId,
- @RequestHeader(value = "user-name") String userName,
- @RequestHeader(value = "store-id") String storeId) {
- Assert.hasKeyAndValue(reqJson, "resourceStores", "蹇呭~锛岃濉啓鐢宠閲囪喘鐨勭墿璧�");
- Assert.hasKeyAndValue(reqJson, "description", "蹇呭~锛岃濉啓閲囪喘鐢宠璇存槑");
- Assert.hasKeyAndValue(reqJson, "resOrderType", "蹇呭~锛岃濉啓鐢宠绫诲瀷");
- PurchaseApplyDto purchaseApplyDto = new PurchaseApplyDto();
- purchaseApplyDto.setResOrderType(reqJson.getString("resOrderType"));
- //绱ф�ラ噰璐叆搴�
- purchaseApplyDto.setWarehousingWay(PurchaseApplyDto.WAREHOUSING_TYPE_URGENT);
- purchaseApplyDto.setCommunityId(reqJson.getString("communityId"));
- purchaseApplyDto.setUserId(userId);
- //鏌ヨ褰撴湀鏁版嵁鏍囪瘑锛屽綋鍊间负1鏃舵煡璇㈠綋鏈堟暟鎹�
- purchaseApplyDto.setUrgentFlag("1");
- //鏌ヨ褰撴湀绱ф�ラ噰璐殑娆℃暟
- int count = purchaseApplyInnerServiceSMOImpl.queryPurchaseApplysCount(purchaseApplyDto);
- //鍙栧嚭寮�鍏虫槧灏勭殑鍊�
- String 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 + "娆★紝璇蜂笅鏈堝啀浣跨敤锛�");
- }
- PurchaseApplyPo purchaseApplyPo = new PurchaseApplyPo();
- purchaseApplyPo.setApplyOrderId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_applyOrderId));
- purchaseApplyPo.setDescription(reqJson.getString("description"));
- purchaseApplyPo.setUserId(userId);
- purchaseApplyPo.setUserName(userName);
- purchaseApplyPo.setEndUserName(reqJson.getString("endUserName"));
- purchaseApplyPo.setEndUserTel(reqJson.getString("endUserTel"));
- purchaseApplyPo.setStoreId(storeId);
- purchaseApplyPo.setResOrderType(PurchaseApplyDto.RES_ORDER_TYPE_ENTER);
- purchaseApplyPo.setState(PurchaseApplyDto.STATE_END);
- purchaseApplyPo.setCreateTime(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
- purchaseApplyPo.setDescription(reqJson.getString("description"));
- purchaseApplyPo.setCreateUserId(userId);
- purchaseApplyPo.setCreateUserName(userName);
- purchaseApplyPo.setWarehousingWay(PurchaseApplyDto.WAREHOUSING_TYPE_URGENT);
- purchaseApplyPo.setCommunityId(reqJson.getString("communityId"));
- //鑾峰彇閲囪喘鐗╁搧淇℃伅
- JSONArray resourceStores = reqJson.getJSONArray("resourceStores");
- List<PurchaseApplyDetailPo> purchaseApplyDetailPos = new ArrayList<>();
- //鏌ヨ褰撳墠灏忓尯鐨勫皬鍖轰粨搴�
- StorehouseDto storehouseDto = new StorehouseDto();
- storehouseDto.setShObjId(reqJson.getString("communityId"));
- storehouseDto.setShType(StorehouseDto.SH_TYPE_COMMUNITY);//灏忓尯浠撳簱
- //鑾峰彇褰撳墠灏忓尯鐨勫皬鍖轰粨搴�
- List<StorehouseDto> storehouseDtos = storehouseInnerServiceSMOImpl.queryStorehouses(storehouseDto);
- //Assert.listOnlyOne(storehouseDtos, "娌℃湁鏌ヨ鍒板綋鍓嶅皬鍖轰粨搴撴垨鏌ヨ鍑哄涓皬鍖轰粨搴擄紒");
- for (int resourceStoreIndex = 0; resourceStoreIndex < resourceStores.size(); resourceStoreIndex++) {
- JSONObject resourceStore = resourceStores.getJSONObject(resourceStoreIndex);
- PurchaseApplyDetailPo purchaseApplyDetailPo = BeanConvertUtil.covertBean(resourceStore, PurchaseApplyDetailPo.class);
- purchaseApplyDetailPo.setId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_applyOrderId));
- purchaseApplyDetailPo.setPurchaseQuantity(resourceStore.get("quantity").toString());
- purchaseApplyDetailPo.setPurchaseRemark(resourceStore.get("remark").toString());
- purchaseApplyDetailPo.setOriginalStock(resourceStore.getString("stock"));
- purchaseApplyDetailPo.setPrice(resourceStore.getString("urgentPrice"));
- purchaseApplyDetailPos.add(purchaseApplyDetailPo);
- //鏌ヨ褰撳墠灏忓尯浠撳簱涓嬭鐗╁搧淇℃伅
- ResourceStoreDto resourceStoreDto = new ResourceStoreDto();
- resourceStoreDto.setResCode(resourceStore.getString("resCode"));
- resourceStoreDto.setShId(storehouseDtos.get(0).getShId());
- List<ResourceStoreDto> resourceStoreDtos = resourceStoreInnerServiceSMOImpl.queryResourceStores(resourceStoreDto);
- //璋冩暣闆嗗洟浠撳簱鐗╁搧淇℃伅
- ResourceStorePo resourceStorePo = new ResourceStorePo();
- resourceStorePo.setResId(purchaseApplyDetailPo.getResId());
- resourceStorePo.setPurchasePrice(resourceStore.getString("urgentPrice"));
- resourceStorePo.setStock(purchaseApplyDetailPo.getQuantity());
- 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();
- allocationStorehouseDto.setAsId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_allocationStorehouseId));
- allocationStorehouseDto.setbId("-1");
- allocationStorehouseDto.setShIda(resourceStore.getString("shId"));
- allocationStorehouseDto.setShIdz(storehouseDtos.get(0).getShId());
- allocationStorehouseDto.setResId(resourceStoreDtos.get(0).getResId());
- allocationStorehouseDto.setResName(resourceStoreDtos.get(0).getResName());
- allocationStorehouseDto.setStoreId(storeId);
- allocationStorehouseDto.setStock(purchaseApplyDetailPo.getQuantity());
- allocationStorehouseDto.setStartUserId(userId);
- allocationStorehouseDto.setStartUserName(userName);
- allocationStorehouseDto.setCreateTime(new Date());
- allocationStorehouseDto.setRemark("绱ф�ラ噰璐叆搴撳苟璋冩嫧");
- allocationStorehouseDto.setApplyId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_applyId));
- allocationStorehouseDto.setOriginalStock(resourceStoreDtos.get(0).getStock());
- allocationStorehouseInnerServiceSMOImpl.saveAllocationStorehouses(allocationStorehouseDto);
- //鐢熸垚璋冩嫧鐢宠璁板綍
- AllocationStorehouseApplyDto allocationStorehouseApplyDto = new AllocationStorehouseApplyDto();
- allocationStorehouseApplyDto.setApplyId(allocationStorehouseDto.getApplyId());
- allocationStorehouseApplyDto.setbId("-1");
- allocationStorehouseApplyDto.setStartUserId(allocationStorehouseDto.getStartUserId());
- allocationStorehouseApplyDto.setStartUserName(allocationStorehouseDto.getStartUserName());
- allocationStorehouseApplyDto.setRemark("绱ф�ラ噰璐叆搴撳苟璋冩嫧");
- allocationStorehouseApplyDto.setApplyCount(purchaseApplyDetailPo.getQuantity());
- allocationStorehouseApplyDto.setStoreId(storeId);
- allocationStorehouseApplyDto.setCreateTime(new Date());
- allocationStorehouseApplyDto.setState(AllocationStorehouseDto.STATE_SUCCESS);
- allocationStorehouseApplyDto.setCommunityId(reqJson.getString("communityId"));
- //璋冩嫧
- allocationStorehouseApplyDto.setApplyType("30000");
- allocationStorehouseApplyInnerServiceSMOImpl.saveAllocationStorehouseApplys(allocationStorehouseApplyDto);
-
- //璋冩暣灏忓尯浠撳簱鐗╁搧鍧囦环銆佹暟閲�
-
- //闆嗗洟浠撳簱鍟嗗搧淇℃伅
- ResourceStoreDto resourceStoreDto2 = new ResourceStoreDto();
- resourceStoreDto2.setResCode(resourceStore.getString("resCode"));
- resourceStoreDto2.setResId(purchaseApplyDetailPo.getResId());
- List<ResourceStoreDto> resourceStoreDtoList = resourceStoreInnerServiceSMOImpl.queryResourceStores(resourceStoreDto2);
-
- ResourceStorePo resourceStorePo1 = new ResourceStorePo();
- resourceStorePo1.setPurchasePrice(resourceStore.getString("urgentPrice"));
- resourceStorePo1.setResId(resourceStoreDtos.get(0).getResId());
- resourceStorePo1.setStock(purchaseApplyDetailPo.getQuantity());
- resourceStorePo1.setAveragePrice(resourceStoreDtoList.get(0).getAveragePrice());
- resourceStorePo1.setPrice(resourceStoreDtoList.get(0).getPrice());
- resourceStorePo1.setResOrderType(PurchaseApplyDto.WAREHOUSING_TYPE_URGENT);
- resourceStorePo1.setOperationType(PurchaseApplyDto.WEIGHTED_MEAN_FALSE);
- //鑾峰彇绱ф�ラ噰璐暟閲�
- double purchaseQuantity = Double.parseDouble(purchaseApplyDetailPo.getQuantity());
- //鑾峰彇鍘熸湁鏈�灏忚閲忔�绘暟
- if(StringUtil.isEmpty(resourceStoreDtos.get(0).getMiniStock())){
- throw new IllegalArgumentException("鏈�灏忚閲忔�绘暟涓嶈兘涓虹┖锛�");
- }
- double miniStock = Double.parseDouble(resourceStoreDtos.get(0).getMiniStock());
- //鑾峰彇鏈�灏忚閲忓崟浣嶆暟閲�
- if (StringUtil.isEmpty(resourceStoreDtos.get(0).getMiniUnitStock())) {
- throw new IllegalArgumentException("鏈�灏忚閲忓崟浣嶆暟閲忎笉鑳戒负绌猴紒");
- }
- double miniUnitStock = Double.parseDouble(resourceStoreDtos.get(0).getMiniUnitStock());
- //璁$畻鏈�灏忚閲忔�绘暟
- double newMiniStock = (purchaseQuantity * miniUnitStock) + 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"));
- allocationStorehouseDto.setShIdz(storehouseDtos.get(0).getShId());
- allocationStorehouseDto.setResId(resourceStore.getString("resId"));
- allocationStorehouseDto.setResName(resourceStore.getString("resName"));
- allocationStorehouseDto.setStoreId(storeId);
- allocationStorehouseDto.setStock(purchaseApplyDetailPo.getQuantity());
- allocationStorehouseDto.setStartUserId(userId);
- allocationStorehouseDto.setStartUserName(userName);
- allocationStorehouseDto.setCreateTime(new Date());
- allocationStorehouseDto.setRemark("绱ф�ラ噰璐叆搴撳苟璋冩嫧");
- allocationStorehouseDto.setApplyId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_applyId));
- allocationStorehouseDto.setOriginalStock("0");
- allocationStorehouseInnerServiceSMOImpl.saveAllocationStorehouses(allocationStorehouseDto);
- //鐢熸垚璋冩嫧鐢宠璁板綍
- AllocationStorehouseApplyDto allocationStorehouseApplyDto = new AllocationStorehouseApplyDto();
- allocationStorehouseApplyDto.setApplyId(allocationStorehouseDto.getApplyId());
- allocationStorehouseApplyDto.setbId("-1");
- allocationStorehouseApplyDto.setStartUserId(allocationStorehouseDto.getStartUserId());
- allocationStorehouseApplyDto.setStartUserName(allocationStorehouseDto.getStartUserName());
- allocationStorehouseApplyDto.setRemark("绱ф�ラ噰璐叆搴撳苟璋冩嫧");
- allocationStorehouseApplyDto.setApplyCount(purchaseApplyDetailPo.getQuantity());
- allocationStorehouseApplyDto.setStoreId(storeId);
- allocationStorehouseApplyDto.setCreateTime(new Date());
- allocationStorehouseApplyDto.setState(AllocationStorehouseDto.STATE_SUCCESS);
- allocationStorehouseApplyDto.setCommunityId(reqJson.getString("communityId"));
- //璋冩嫧
- allocationStorehouseApplyDto.setApplyType("30000");
- allocationStorehouseApplyInnerServiceSMOImpl.saveAllocationStorehouseApplys(allocationStorehouseApplyDto);
- //灏忓尯浠撳簱杩涜鍏ュ簱鎻掑叆
- //闆嗗洟浠撳簱鍟嗗搧淇℃伅
- ResourceStoreDto resourceStoreDto2 = new ResourceStoreDto();
- resourceStoreDto2.setResCode(resourceStore.getString("resCode"));
- resourceStoreDto2.setResId(purchaseApplyDetailPo.getResId());
- List<ResourceStoreDto> resourceStoreDtoList = resourceStoreInnerServiceSMOImpl.queryResourceStores(resourceStoreDto2);
- ResourceStoreDto resourceStoreDto1 = BeanConvertUtil.covertBean(resourceStoreDtoList.get(0), ResourceStoreDto.class);
- resourceStoreDto1.setResId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_resId));
- resourceStoreDto1.setShId(storehouseDtos.get(0).getShId());
- resourceStoreDto1.setbId("-1");
- resourceStoreDto1.setStock(purchaseApplyDetailPo.getQuantity());
- resourceStoreDto1.setCreateTime(new Date());
- //鑾峰彇绱ф�ラ噰璐暟閲�
- double purchaseQuantity = Double.parseDouble(purchaseApplyDetailPo.getQuantity());
- //鑾峰彇鏈�灏忚閲忓崟浣嶆暟閲�
- if (StringUtil.isEmpty(resourceStore.getString("miniUnitStock"))) {
- throw new IllegalArgumentException("鏈�灏忚閲忓崟浣嶆暟閲忎笉鑳戒负绌猴紒");
- }
- double miniUnitStock = Double.parseDouble(resourceStore.getString("miniUnitStock"));
- //璁$畻鏈�灏忚閲忔�绘暟
- double miniStock = purchaseQuantity * miniUnitStock;
- resourceStoreDto1.setMiniStock(String.valueOf(miniStock));
- resourceStoreInnerServiceSMOImpl.saveResourceStore(resourceStoreDto1);
- }
- }
- purchaseApplyPo.setPurchaseApplyDetailPos(purchaseApplyDetailPos);
- return purchaseApplyBMOImpl.apply(purchaseApplyPo);
+ return purchaseApplyBMOImpl.apply(purchaseApplyPo,reqJson);
}
}
--
Gitblit v1.8.0