| 
					
				 | 
			
			
				@@ -2,6 +2,7 @@ package com.gree.mall.manager.logic.material.stock; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.core.collection.CollectionUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.core.metadata.IPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.toolkit.IdWorker; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.bean.admin.AdminUserCom; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.bean.listvo.material.WebsitStockAccPVO; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -9,6 +10,8 @@ import com.gree.mall.manager.bean.listvo.material.WebsitStockAccVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.bean.listvo.material.WebsitStockPVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.bean.listvo.material.WebsitStockVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.commonmapper.CommonMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.manager.enums.ExamineStatusEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.manager.enums.IsYesNoEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.enums.material.DirectFlagEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.enums.material.PartsAttrEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.enums.material.WebsitGoodsTypeEnum; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -44,6 +47,8 @@ public class WebsitStockLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final GoodsMaterialStockAccService goodsMaterialStockAccService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final StorageService storageService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final GoodsMaterialStorageService goodsMaterialStorageService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final WebsitPurchaseService websitPurchaseService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final WebsitPurchaseItemService websitPurchaseItemService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 网点库存列表 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -196,6 +201,8 @@ public class WebsitStockLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (websitGoodsTypeEnum.getKey().equals(WebsitGoodsTypeEnum.M.getKey()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 && CollectionUtil.isNotEmpty(websitStocks)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             List<WebsitGoodsPrice> priceList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<WebsitPurchaseItem> purchaseItemList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             List<WebsitGoodsPrice> goodsPrices = websitGoodsPriceService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     .eq(WebsitGoodsPrice::getCompanyWechatId, websitStocks.get(0).getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     .eq(WebsitGoodsPrice::getWebsitId, websitStocks.get(0).getWebsitId()) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -217,6 +224,9 @@ public class WebsitStockLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Map<String, BigDecimal> goodsMap = goodsList.stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     .collect(Collectors.toMap(WebsitGoods::getGoodsId, WebsitGoods::getMarketPrice, (key1,key2) -> key2)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            final String purchaseId = IdWorker.getIdStr(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal purchaseTotalAmount = BigDecimal.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for (WebsitStock stock : websitStocks) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (!priceMap.containsKey(stock.getGoodsId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     BigDecimal goodsPrice = goodsMap.get(stock.getGoodsId()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -231,15 +241,70 @@ public class WebsitStockLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     price.setRemark("初始化"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     priceList.add(price); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    // 初始化采购明细 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    WebsitPurchaseItem purchaseItem = new WebsitPurchaseItem(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    purchaseItem.setPurchaseId(purchaseId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setCompanyWechatId(websitStocks.get(0).getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setWebsitId(websitStocks.get(0).getWebsitId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setWebsitName(websitStocks.get(0).getWebsitName()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setGoodsType(WebsitGoodsTypeEnum.M.getKey()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setGoodsId(stock.getGoodsId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setGoodsName(stock.getGoodsName()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setApplyCost(stock.getLastCost()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setApplyCostValue(stock.getLastCost().multiply(stock.getQty())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setApplyQty(stock.getQty()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setCheckQty(stock.getQty()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setCost(stock.getLastCost()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setCostValue(stock.getLastCost().multiply(stock.getQty())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setRecQty(stock.getQty()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setNote("库存初始化") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setInStockQty(stock.getQty()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setInStockCost(stock.getLastCost()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    purchaseTotalAmount = purchaseTotalAmount.add(purchaseItem.getCostValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    purchaseItemList.add(purchaseItem); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (CollectionUtil.isNotEmpty(priceList)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 websitGoodsPriceService.saveBatch(priceList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (CollectionUtil.isNotEmpty(purchaseItemList)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 初始化辅材采购入库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                WebsitPurchase purchase = new WebsitPurchase(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                purchase.setPurchaseId(purchaseId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setCompanyWechatId(websitStocks.get(0).getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setCompanyWechatName(websitStocks.get(0).getCompanyWechatName()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setWebsitId(websitStocks.get(0).getWebsitId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setWebsitName(websitStocks.get(0).getWebsitName()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setGoodsType(WebsitGoodsTypeEnum.M.getKey()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setVenderId("1010") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setVenderName("其他") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setFlag(ExamineStatusEnum.OK.getKey()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setIsRecheck(IsYesNoEnum.YES.getKey()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setConfirmRemark("库存初始化") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setStorageId(websitStocks.get(0).getStorageId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setStorageName("默认") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setConfirmBy(adminUser.getNickName()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setConfirmTime(websitStocks.get(0).getCreateTime()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setCheckTime(websitStocks.get(0).getCreateTime()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setSubmitTime(websitStocks.get(0).getCreateTime()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .setTotalAmount(purchaseTotalAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                websitPurchaseService.save(purchase); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                websitPurchaseItemService.saveBatch(purchaseItemList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         websitStockService.saveBatch(websitStocks); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         websitStockAccService.saveBatch(websitStockAccs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |