| 
					
				 | 
			
			
				@@ -583,14 +583,18 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			List<String> cInvIdList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			// 获取物理id列表 编码+颜色+批号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			for (Map<String,Object> item : findList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				cInvIdList.add(item.get("cInvCode").toString()+item.get("cColor").toString()+item.get("cBatch").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (item.get("cInvIdAfter") == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					String cInvId = item.get("cInvCode").toString()+item.get("cColor").toString()+item.get("cBatch").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.put("cInvIdAfter", cInvId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				cInvIdList.add(item.get("cInvIdAfter").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			// 获取转换前入库金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			List<Map<String,Object>> orgInList = fabricLossMapper.getOrgInList(cInvIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			// 设置入库类型,入库单价 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			int replaceSum = 0; // 替换的数量,为了防止死循环,替换数量小于查找数量,退出 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			for (Map<String,Object> item : findList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				Optional<Map<String,Object>> findOrgInOpt = orgInList.stream().filter(e->e.get("cInvIdAfter").toString().equals(item.get("cInvCode").toString()+item.get("cColor").toString()+item.get("cBatch").toString())).findFirst(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Optional<Map<String,Object>> findOrgInOpt = orgInList.stream().filter(e->e.get("cInvIdAfter").toString().equals(item.get("cInvIdAfter").toString())).findFirst(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				if (findOrgInOpt.isPresent()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 					replaceSum++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 					Map<String,Object> findOrgIn = findOrgInOpt.get(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -598,6 +602,7 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 					Double d = DoubleOperation.div(oConvertUtils.getDouble(findOrgIn.get("iPurchuseMoney").toString(), 0),oConvertUtils.getDouble(findOrgIn.get("iQuantity").toString(),0),4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 					d = DoubleOperation.mul(oConvertUtils.getDouble(item.get("iQuantity").toString(), 0),d); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 					item.put("iPurchuseMoney", d); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					item.put("cInvIdAfter", findOrgIn.get("cInvIdBefore").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			if (replaceSum<findList.size()){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -605,6 +610,83 @@ public class FabricLossServiceImpl extends ServiceImpl<FabricLossMapper, FabricL 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		}while(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		// 如果是其他委外订单入库的材料,获取成本,只计算一层 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<Map<String,Object>> findOtherPlanOmList = rowInList.stream().filter(e-> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"委外加工".equals(e.get("cBusType").toString()) && 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				oConvertUtils.getString(e.get("moCode")).indexOf(code) !=0 && 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				e.get("MODetailsID") != null).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<Map<String,Object>> findOtherPlanOmList2 = rowInListWithAV.stream().filter(e-> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				"委外加工".equals(e.get("cBusType").toString()) && 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						oConvertUtils.getString(e.get("moCode")).indexOf(code) !=0 && 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						e.get("MODetailsID") != null).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		findOtherPlanOmList.addAll(findOtherPlanOmList2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (findOtherPlanOmList.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<String> moDetailIdList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			for (Map<String,Object> item : findOtherPlanOmList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				moDetailIdList.add(item.get("MODetailsID").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			// 出入库详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Map<String,Object>> inOutDetailList = fabricLossMapper.getOmInOutInfoListByDetailId(moDetailIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			// 出入库详情每行设置出库材料入库类型,采购金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			do{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<Map<String,Object>> findList = inOutDetailList.stream().filter(e->e.get("cBusType") == null || "转换入库".equals(e.get("cBusType"))).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (findList.size()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<String> cInvIdList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				for (Map<String,Object> item : findList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					if (item.get("cInvIdAfter") == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						String cInvId = item.get("cInvIdOut").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						item.put("cInvIdAfter", cInvId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					cInvIdList.add(item.get("cInvIdAfter").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				// 获取转换前入库金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<Map<String,Object>> orgInList = fabricLossMapper.getOrgInList(cInvIdList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				// 设置入库类型,入库单价 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				int replaceSum = 0; // 替换的数量,为了防止死循环,替换数量小于查找数量,退出 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				for (Map<String,Object> item : findList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					Optional<Map<String,Object>> findOrgInOpt = orgInList.stream().filter(e->e.get("cInvIdAfter").toString().equals(item.get("cInvIdAfter").toString())).findFirst(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					if (findOrgInOpt.isPresent()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						replaceSum++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						Map<String,Object> findOrgIn = findOrgInOpt.get(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						item.put("cBusType", findOrgIn.get("cBusType").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						Double d = DoubleOperation.div(oConvertUtils.getDouble(findOrgIn.get("iPurchuseMoney").toString(), 0),oConvertUtils.getDouble(findOrgIn.get("iQuantity").toString(),0),4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						d = DoubleOperation.mul(oConvertUtils.getDouble(item.get("iQuantityOut").toString(), 0),d); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						item.put("iPurchuseMoney", d); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+						item.put("cInvIdAfter", findOrgIn.get("cInvIdBefore").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (replaceSum<findList.size()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			}while(true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			// 每行设置金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			for (Map<String,Object> item : findOtherPlanOmList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				String detailId = item.get("MODetailsID").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				List<Map<String,Object>> findInOutList = inOutDetailList.stream().filter(e->e.get("MODetailsID").toString().equals(detailId)).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if (findInOutList.size() == 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Double iProcessFee = oConvertUtils.getDouble(findInOutList.get(0).get("iProcessFee").toString(),0);// 加工费 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Double iQuantityIn = oConvertUtils.getDouble(findInOutList.get(0).get("iQuantityIn").toString(),0);// 入库数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Double iOutTotalMoney = 0.0;//出库材料费用总额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				for (Map<String,Object> inOutItem : findInOutList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+					iOutTotalMoney += oConvertUtils.getDouble(oConvertUtils.getString(inOutItem.get("iPurchuseMoney")), 0);// 出库金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				// 入库单价 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Double iPrice = DoubleOperation.add(iProcessFee,iOutTotalMoney); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				iPrice = DoubleOperation.div(iPrice,iQuantityIn,4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				// 入库材料出库数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Double iQuantity = oConvertUtils.getDouble(item.get("iQuantity").toString(),0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				// 入库金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Double iPurchuseMoney = DoubleOperation.mul(iPrice, iQuantity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				item.put("iPurchuseMoney", iPurchuseMoney); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |