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