|  |  | @ -56,9 +56,7 @@ public class IoStatDayServiceImpl implements IoStatDayService { | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void statData(Date date) { |  |  |  |     public void statData(Date date) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         //汇总前一天的数据
 |  |  |  |         //汇总前一天的数据
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         DateTime yesterday = DateUtil.offsetDay(date, -1); |  |  |  |         DateTime yesterday = DateUtil.offsetDay(date, -1); | 
			
		
	
		
		
			
				
					
					|  |  |  |         List<IoOrderDetailResultEntity> orderDetailResultEntities = ioOrderDetailResultDao.selectList(new QueryWrapper<IoOrderDetailResultEntity>() |  |  |  |         List<IoOrderDetailResultEntity> orderDetailResultEntities = ioOrderDetailResultDao.selectStatDataByTime(yesterday.toString("yyyy-MM-dd")); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 .select("orderIdFk", "bindRlFk", "nameCode", "batchNo", "productDate", "expireDate", "coName", "spec", "price", "count", "reCount") |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .between("createTime", DateUtil.beginOfDay(yesterday), DateUtil.endOfDay(yesterday))); |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         if (CollUtil.isNotEmpty(orderDetailResultEntities)) { |  |  |  |         if (CollUtil.isNotEmpty(orderDetailResultEntities)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             //声明用于存放汇总数据的集合
 |  |  |  |             //声明用于存放汇总数据的集合
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             List<IoStatDayEntity> dataList = new ArrayList<>(); |  |  |  |             List<IoStatDayEntity> dataList = new ArrayList<>(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -71,43 +69,17 @@ public class IoStatDayServiceImpl implements IoStatDayService { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (order.getMainAction().equals(ConstantType.TYPE_PUT)) { |  |  |  |                 if (order.getMainAction().equals(ConstantType.TYPE_PUT)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //入库
 |  |  |  |                     //入库
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     statData.setInCount(orderDetailResultEntity.getReCount() + statData.getInCount()); |  |  |  |                     statData.setInCount(orderDetailResultEntity.getReCount() + statData.getInCount()); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     statData.setInPrice(orderDetailResultEntity.getPrice()); |  |  |  |                     if (null != orderDetailResultEntity.getPrice()) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                         BigDecimal inAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount())); |  |  |  |                         BigDecimal inAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount())); | 
			
		
	
		
		
			
				
					
					|  |  |  |                         statData.setInAmount(inAmount.add(statData.getInAmount())); |  |  |  |                         statData.setInAmount(inAmount.add(statData.getInAmount())); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //计算结余金额
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     long balanceCount; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     BigDecimal balanceAmount; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (statData.getBalanceCount() == 0) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         balanceCount = statData.getBeginCount() + statData.getInCount(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         balanceAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(balanceCount)); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } else { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         balanceCount = statData.getBalanceCount() + orderDetailResultEntity.getReCount(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         balanceAmount = statData.getBalanceAmount().add(statData.getInAmount()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     statData.setBalanceCount(Long.valueOf(balanceCount).intValue()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     statData.setBalanceAmount(balanceAmount); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } else if (order.getMainAction().equals(ConstantType.TYPE_OUT)) { |  |  |  |                 } else if (order.getMainAction().equals(ConstantType.TYPE_OUT)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //出库
 |  |  |  |                     //出库
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     statData.setOutCount(orderDetailResultEntity.getReCount() + statData.getOutCount()); |  |  |  |                     statData.setOutCount(orderDetailResultEntity.getReCount() + statData.getOutCount()); | 
			
		
	
		
		
			
				
					
					|  |  |  |                     statData.setOutPrice(orderDetailResultEntity.getPrice()); |  |  |  |                     if (null != orderDetailResultEntity.getPrice()) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                     BigDecimal outAmount = statData.getBeginAmount().add(orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount()))); |  |  |  |                         BigDecimal outAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount())); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                         statData.setOutAmount(outAmount.add(statData.getOutAmount())); |  |  |  |                         statData.setOutAmount(outAmount.add(statData.getOutAmount())); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //计算结余金额
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     long balanceCount; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     BigDecimal balanceAmount; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     if (statData.getBalanceCount() == 0) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         balanceCount = Long.valueOf(statData.getBeginCount()) - orderDetailResultEntity.getReCount(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         balanceAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(balanceCount)); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } else { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         balanceCount = statData.getBalanceCount() + orderDetailResultEntity.getReCount(); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                         balanceAmount = statData.getBalanceAmount().subtract(statData.getOutAmount()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } |  |  |  |                     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     statData.setBalanceCount(Long.valueOf(balanceCount).intValue()); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                     statData.setBalanceAmount(balanceAmount); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             }); |  |  |  |             }); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -137,7 +109,7 @@ public class IoStatDayServiceImpl implements IoStatDayService { | 
			
		
	
		
		
			
				
					
					|  |  |  |     private IoStatDayEntity getStatData(List<IoStatDayEntity> dataList, IoOrderDetailResultEntity orderDetailResultEntity, DateTime yesterday) { |  |  |  |     private IoStatDayEntity getStatData(List<IoStatDayEntity> dataList, IoOrderDetailResultEntity orderDetailResultEntity, DateTime yesterday) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (CollUtil.isNotEmpty(dataList)) { |  |  |  |         if (CollUtil.isNotEmpty(dataList)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             for (IoStatDayEntity statDayEntity : dataList) { |  |  |  |             for (IoStatDayEntity statDayEntity : dataList) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 if (statDayEntity.getRelIdFk().equals(orderDetailResultEntity.getBindRlFk())) { |  |  |  |                 if (Long.valueOf(statDayEntity.getRelIdFk()).equals(orderDetailResultEntity.getBindRlFk())) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     if ((StrUtil.isNotBlank(statDayEntity.getBatchNo()) && StrUtil.isNotBlank(orderDetailResultEntity.getBatchNo())) && statDayEntity.getBatchNo().equals(orderDetailResultEntity.getBatchNo())) { |  |  |  |                     if ((StrUtil.isNotBlank(statDayEntity.getBatchNo()) && StrUtil.isNotBlank(orderDetailResultEntity.getBatchNo())) && statDayEntity.getBatchNo().equals(orderDetailResultEntity.getBatchNo())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                         return statDayEntity; |  |  |  |                         return statDayEntity; | 
			
		
	
		
		
			
				
					
					|  |  |  |                     } else if (StrUtil.isBlank(statDayEntity.getBatchNo()) && StrUtil.isBlank(orderDetailResultEntity.getBatchNo())) { |  |  |  |                     } else if (StrUtil.isBlank(statDayEntity.getBatchNo()) && StrUtil.isBlank(orderDetailResultEntity.getBatchNo())) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -161,11 +133,11 @@ public class IoStatDayServiceImpl implements IoStatDayService { | 
			
		
	
		
		
			
				
					
					|  |  |  |         statData.setBalancePrice(orderDetailResultEntity.getPrice()); |  |  |  |         statData.setBalancePrice(orderDetailResultEntity.getPrice()); | 
			
		
	
		
		
			
				
					
					|  |  |  |         //设置初始化出入库数量和价格
 |  |  |  |         //设置初始化出入库数量和价格
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         statData.setInCount(0); |  |  |  |         statData.setInCount(0); | 
			
		
	
		
		
			
				
					
					|  |  |  |         statData.setInPrice(orderDetailResultEntity.getPrice()); |  |  |  |         statData.setInPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice()); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         statData.setInAmount(BigDecimal.ZERO); |  |  |  |         statData.setInAmount(BigDecimal.ZERO); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         statData.setOutCount(0); |  |  |  |         statData.setOutCount(0); | 
			
		
	
		
		
			
				
					
					|  |  |  |         statData.setOutPrice(orderDetailResultEntity.getPrice()); |  |  |  |         statData.setOutPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice()); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         statData.setOutAmount(BigDecimal.ZERO); |  |  |  |         statData.setOutAmount(BigDecimal.ZERO); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         //设置期初数据
 |  |  |  |         //设置期初数据
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -173,11 +145,11 @@ public class IoStatDayServiceImpl implements IoStatDayService { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (null == statDayEntity) { |  |  |  |         if (null == statDayEntity) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             //第一次汇总日数据
 |  |  |  |             //第一次汇总日数据
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             statData.setBeginCount(0); |  |  |  |             statData.setBeginCount(0); | 
			
		
	
		
		
			
				
					
					|  |  |  |             statData.setBeginPrice(orderDetailResultEntity.getPrice()); |  |  |  |             statData.setBeginPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice()); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             statData.setBeginAmount(BigDecimal.ZERO); |  |  |  |             statData.setBeginAmount(BigDecimal.ZERO); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             statData.setBalanceCount(0); |  |  |  |             statData.setBalanceCount(0); | 
			
		
	
		
		
			
				
					
					|  |  |  |             statData.setBalancePrice(orderDetailResultEntity.getPrice()); |  |  |  |             statData.setBalanceAmount(BigDecimal.ZERO); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } else { |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |             //已存在此产品汇总数据,基于旧数据生成新的汇总数据
 |  |  |  |             //已存在此产品汇总数据,基于旧数据生成新的汇总数据
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             statData.setBeginCount(statDayEntity.getBalanceCount()); |  |  |  |             statData.setBeginCount(statDayEntity.getBalanceCount()); | 
			
		
	
	
		
		
			
				
					|  |  | @ -189,7 +161,7 @@ public class IoStatDayServiceImpl implements IoStatDayService { | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         //设置结余价格
 |  |  |  |         //设置结余价格
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         statData.setBalancePrice(orderDetailResultEntity.getPrice()); |  |  |  |         statData.setBalancePrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice()); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         dataList.add(statData); |  |  |  |         dataList.add(statData); | 
			
		
	
		
		
			
				
					
					|  |  |  |         return statData; |  |  |  |         return statData; | 
			
		
	
	
		
		
			
				
					|  |  | @ -222,6 +194,11 @@ public class IoStatDayServiceImpl implements IoStatDayService { | 
			
		
	
		
		
			
				
					
					|  |  |  |         dataList.forEach(statDayEntity -> { |  |  |  |         dataList.forEach(statDayEntity -> { | 
			
		
	
		
		
			
				
					
					|  |  |  |             statDayEntity.setUpdateTime(updateTime); |  |  |  |             statDayEntity.setUpdateTime(updateTime); | 
			
		
	
		
		
			
				
					
					|  |  |  |             statDayEntity.setRecordKeyFk(orderNo); |  |  |  |             statDayEntity.setRecordKeyFk(orderNo); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //计算结余数据
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             statDayEntity.setBalanceCount(statDayEntity.getBalanceCount() + statDayEntity.getInCount() - statDayEntity.getOutCount()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             statDayEntity.setBalanceAmount(statDayEntity.getBalanceAmount().add(statDayEntity.getInAmount()).subtract(statDayEntity.getOutAmount())); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             mapper.insert(statDayEntity); |  |  |  |             mapper.insert(statDayEntity); | 
			
		
	
		
		
			
				
					
					|  |  |  |         }); |  |  |  |         }); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | 
 |