统计汇总代码提交

pro
郑明梁 2 years ago
parent fed1bc9bde
commit bfbb85eb57

@ -154,4 +154,7 @@ public class IoStatQuarterEntity {
@TableField(value = "deptCode")
private String deptCode;
@TableField(exist = false)
private String deptName;
}

@ -148,5 +148,8 @@ public class IoStatYearEntity {
@TableField(value = "deptCode")
private String deptCode;
@TableField(exist = false)
private String deptName;
}

@ -141,6 +141,7 @@ public class UdiRelevanceResponse {
}
public Boolean getUseDy() {
if (isUseDy == null)
return false;

@ -260,6 +260,8 @@ public class IoStatDayServiceImpl implements IoStatDayService {
ioStatDayEntity.setDay(yesterday.dayOfMonth());
ioStatDayEntity.setInCount(0);
ioStatDayEntity.setOutCount(0);
ioStatDayEntity.setInAmount(new BigDecimal(0));
ioStatDayEntity.setOutAmount(new BigDecimal(0));
}
return IoStatDayEntityList;
}

@ -9,7 +9,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.glxp.api.constant.ConstantType;
import com.glxp.api.dao.inout.*;
import com.glxp.api.dao.schedule.SystemParamConfigDao;
import com.glxp.api.entity.inout.*;
import com.glxp.api.entity.system.SystemParamConfigEntity;
import com.glxp.api.req.inout.FilterStatDataDetailRequest;
import com.glxp.api.res.inv.DateRequest;
import com.glxp.api.service.inout.IoStatMonthService;
@ -49,13 +51,16 @@ public class IoStatMonthServiceImpl implements IoStatMonthService {
private IoOrderDao orderDao;
@Resource
private IoOrderDetailResultDao ioOrderDetailResultDao;
@Resource
private SystemParamConfigDao systemParamConfigDao;
@Override
public void statData(Date date) {
DateTime lastMonth = DateUtil.lastMonth();
DateTime lastMonth = DateUtil.offsetMonth(date,-1);
//汇总上一个月的数据
DateRequest dateRequest = getYearAndMonth(1);
SystemParamConfigEntity systemParamConfigEntity=systemParamConfigDao.selectByParamKey("date1");
String y=systemParamConfigEntity.getParamValue();
DateRequest dateRequest = getYearAndMonth(Integer.valueOf(y));
DateRequest dateRequest1 = getfirstDayAndLastDay(dateRequest.getYear(), dateRequest.getMomth());
List<IoStatMonthEntity> dataList = new ArrayList<>();
//查询单号
@ -279,10 +284,12 @@ public class IoStatMonthServiceImpl implements IoStatMonthService {
ioStatDayEntity.setId(null);
ioStatDayEntity.setBeginCount(ioStatDayEntity.getBalanceCount());
ioStatDayEntity.setMonth(lastMonth.monthBaseOne());
ioStatDayEntity.setBalanceAmount(ioStatDayEntity.getBalanceAmount());
ioStatDayEntity.setBeginAmount(ioStatDayEntity.getBalanceAmount());
ioStatDayEntity.setBeginPrice(ioStatDayEntity.getBalancePrice());
ioStatDayEntity.setInCount(0);
ioStatDayEntity.setOutCount(0);
ioStatDayEntity.setInAmount(new BigDecimal(0));
ioStatDayEntity.setOutAmount(new BigDecimal(0));
}
return ioStatMonthEntityList;
}

@ -6,13 +6,12 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.glxp.api.dao.inout.IoStatMonthDao;
import com.glxp.api.dao.inout.IoStatOrderDao;
import com.glxp.api.dao.inout.IoStatQuarterDao;
import com.glxp.api.entity.inout.IoStatMonthEntity;
import com.glxp.api.entity.inout.IoStatOrderEntity;
import com.glxp.api.entity.inout.IoStatQuarterEntity;
import com.glxp.api.constant.ConstantType;
import com.glxp.api.dao.inout.*;
import com.glxp.api.entity.inout.*;
import com.glxp.api.entity.system.SystemParamConfigEntity;
import com.glxp.api.req.inout.FilterStatDataDetailRequest;
import com.glxp.api.res.inv.DateRequest;
import com.glxp.api.service.inout.IoStatQuarterService;
import com.glxp.api.util.GennerOrderUtils;
import com.glxp.api.util.OrderNoTypeBean;
@ -26,7 +25,9 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
@ -43,31 +44,65 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
private GennerOrderUtils gennerOrderUtils;
@Resource
private SqlSessionFactory sqlSessionFactory;
@Resource
private IoOrderDao orderDao;
@Resource
private IoOrderDetailResultDao ioOrderDetailResultDao;
@Override
public void statData(Date date) {
//汇总上一季度的数据
DateTime yesterday = DateUtil.offsetDay(date, -1);
//查询上一季度各个月度的数据
List<IoStatMonthEntity> statMonthList = getMonthStatList(yesterday);
if (CollUtil.isNotEmpty(statMonthList)) {
//声明用于存放汇总数据的集合
int quarter = yesterday.quarter();
int year = yesterday.year();
String topDate=getStartDayOfQuarter(year,quarter);
String lastDate=getLastDayOfQuarter(year,quarter);
//查询单号
List<String> orderIdFkList = new ArrayList<>();
//汇总上一个季度的数据
List<IoStatQuarterEntity> dataList = new ArrayList<>();
statMonthList.forEach(statMonthEntity -> {
//获取新的汇总数据
IoStatQuarterEntity statData = getStatData(dataList, statMonthEntity, yesterday);
orderIdFkList = orderDao.selectOrderfirstAndLastIdList(lastDate, topDate);
List<IoOrderDetailResultEntity> orderDetailResultEntities = new ArrayList<>();
if(orderIdFkList.size()>0){
orderDetailResultEntities = ioOrderDetailResultDao.selectStatDataByTime(orderIdFkList);
}
//设置入库数据
statData.setInCount(statData.getInCount() + statMonthEntity.getInCount());
statData.setInPrice(statMonthEntity.getInPrice());
statData.setInAmount(statData.getInAmount().add(statMonthEntity.getInAmount()));
if (CollUtil.isNotEmpty(orderDetailResultEntities)) {
//声明用于存放汇总数据的集合
orderDetailResultEntities.forEach(orderDetailResultEntity -> {
//获取新的汇总数据
IoStatQuarterEntity statData = getStatData(dataList, orderDetailResultEntity, yesterday);
//设置出库数据
statData.setOutCount(statData.getOutCount() + statMonthEntity.getOutCount());
statData.setOutPrice(statMonthEntity.getOutPrice());
statData.setOutAmount(statData.getOutAmount().add(statMonthEntity.getOutAmount()));
//查询此单是出库还是入库
IoOrderEntity order = orderDao.selectOne(new QueryWrapper<IoOrderEntity>().select("mainAction").eq("billNo", orderDetailResultEntity.getOrderIdFk()).eq("deptCode",orderDetailResultEntity.getDeptCode()));
if (order.getMainAction().equals(ConstantType.TYPE_PUT)) {
//入库
statData.setInCount(orderDetailResultEntity.getReCount() + statData.getInCount());
if (null != orderDetailResultEntity.getPrice()) {
BigDecimal inAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount()));
statData.setInAmount(inAmount.add(statData.getInAmount()));
}
} else if (order.getMainAction().equals(ConstantType.TYPE_OUT)) {
//出库
statData.setOutCount(orderDetailResultEntity.getReCount() + statData.getOutCount());
if (null != orderDetailResultEntity.getPrice()) {
BigDecimal outAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount()));
statData.setOutAmount(outAmount.add(statData.getOutAmount()));
}
}
});
//汇总上一季度存在上上一季度不存在产品的汇总数据
//获取上上天的数据
QueryWrapper<IoStatQuarterEntity> ew = new QueryWrapper<>();
ew.eq("year", yesterday.year());
ew.eq("quarter", yesterday.quarter()-1);
List<IoStatQuarterEntity> ioStatMonthEntityList=statQuarterDao.selectList(ew);
List<IoStatQuarterEntity> newOrOldDate=getNewOrOldDate(dataList,ioStatMonthEntityList,yesterday);
dataList.addAll(newOrOldDate);
//插入汇总数据
saveData(yesterday, dataList);
}
@ -103,7 +138,7 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
OrderNoTypeBean orderNoTypeBean = new OrderNoTypeBean("STATQ", "yyyyMMdd");
String orderNo = gennerOrderUtils.createStatOrderNo(orderNoTypeBean);
statOrderEntity.setRecordKey(orderNo);
statOrderEntity.setType(3);
statOrderEntity.setType(2);
statOrderEntity.setDate(yesterday);
statOrderEntity.setTitle(yesterday.year() + " 年 " + yesterday.quarter() + " 季度出入库汇总");
@ -133,18 +168,19 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
*
*
* @param dataList
* @param statMonthEntity
* @param orderDetailResultEntity
* @param yesterday
* @return
*/
private IoStatQuarterEntity getStatData(List<IoStatQuarterEntity> dataList, IoStatMonthEntity statMonthEntity, DateTime yesterday) {
private IoStatQuarterEntity getStatData(List<IoStatQuarterEntity> dataList, IoOrderDetailResultEntity orderDetailResultEntity, DateTime yesterday) {
if (CollUtil.isNotEmpty(dataList)) {
for (IoStatQuarterEntity statQuarterEntity : dataList) {
if (statQuarterEntity.getRelIdFk().equals(statMonthEntity.getRelIdFk())) {
if ((StrUtil.isNotBlank(statQuarterEntity.getBatchNo()) && StrUtil.isNotBlank(statMonthEntity.getBatchNo())) && statQuarterEntity.getBatchNo().equals(statMonthEntity.getBatchNo())) {
return statQuarterEntity;
} else if (StrUtil.isBlank(statQuarterEntity.getBatchNo()) && StrUtil.isBlank(statMonthEntity.getBatchNo())) {
return statQuarterEntity;
for (IoStatQuarterEntity statDayEntity : dataList) {
if (Long.valueOf(statDayEntity.getRelIdFk()).equals(orderDetailResultEntity.getBindRlFk()) && statDayEntity.getDeptCode().equals(orderDetailResultEntity.getDeptCode())) {
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())) {
return statDayEntity;
}
}
}
@ -152,30 +188,30 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
//未存在于集合中,构造新数据
IoStatQuarterEntity statData = new IoStatQuarterEntity();
statData.setDeptCode(orderDetailResultEntity.getDeptCode());
statData.setYear(yesterday.year());
statData.setQuarter(yesterday.quarter());
statData.setRelIdFk(statMonthEntity.getRelIdFk());
statData.setNameCode(statMonthEntity.getNameCode());
statData.setProductName(statMonthEntity.getProductName());
statData.setGgxh(statMonthEntity.getGgxh());
statData.setBatchNo(statMonthEntity.getBatchNo());
statData.setRelIdFk(String.valueOf(orderDetailResultEntity.getBindRlFk()));
statData.setNameCode(orderDetailResultEntity.getNameCode());
statData.setProductName(orderDetailResultEntity.getCoName());
statData.setGgxh(orderDetailResultEntity.getSpec());
statData.setBatchNo(orderDetailResultEntity.getBatchNo());
//设置结余价格
statData.setBalancePrice(statMonthEntity.getBalancePrice());
statData.setBalancePrice(orderDetailResultEntity.getPrice());
//设置初始化出入库数量和价格
statData.setInCount(0);
statData.setInPrice(statMonthEntity.getBalancePrice());
statData.setInPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice());
statData.setInAmount(BigDecimal.ZERO);
statData.setOutCount(0);
statData.setOutPrice(statMonthEntity.getBalancePrice());
statData.setOutPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice());
statData.setOutAmount(BigDecimal.ZERO);
//设置期初数据
IoStatQuarterEntity statQuarterEntity = statQuarterDao.selectOne(buildQueryWrapper(statMonthEntity, yesterday));
IoStatQuarterEntity statQuarterEntity = statQuarterDao.selectOne(buildQueryWrapper(orderDetailResultEntity, yesterday));
if (null == statQuarterEntity) {
//第一次汇总季度数据
statData.setBeginCount(0);
statData.setBalancePrice(statMonthEntity.getBalancePrice());
statData.setBeginPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice());
statData.setBeginAmount(BigDecimal.ZERO);
statData.setBalanceCount(0);
@ -190,7 +226,7 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
}
//设置结余价格
statData.setBalancePrice(statMonthEntity.getBalancePrice());
statData.setBalancePrice(statData.getBeginPrice());
dataList.add(statData);
return statData;
@ -199,11 +235,11 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
/**
*
*
* @param statMonthEntity
* @param ioOrderDetailResultEntity
* @param yesterday
* @return
*/
private QueryWrapper<IoStatQuarterEntity> buildQueryWrapper(IoStatMonthEntity statMonthEntity, DateTime yesterday) {
private QueryWrapper<IoStatQuarterEntity> buildQueryWrapper(IoOrderDetailResultEntity ioOrderDetailResultEntity, DateTime yesterday) {
QueryWrapper<IoStatQuarterEntity> wrapper = new QueryWrapper<>();
if (yesterday.quarter() == 1) {
//当前汇总的记录为第一季度,上一季度时间取前一年的第四季度数据
@ -213,42 +249,93 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
wrapper.eq("year", yesterday.year())
.eq("quarter", yesterday.quarter() - 1);
}
wrapper.eq("relIdFk", statMonthEntity.getRelIdFk())
.eq(StrUtil.isNotBlank(statMonthEntity.getBatchNo()), "batchNo", statMonthEntity.getBatchNo())
.eq(StrUtil.isNotBlank(statMonthEntity.getNameCode()), "nameCode", statMonthEntity.getNameCode());
wrapper.eq("relIdFk", ioOrderDetailResultEntity.getBindRlFk());
wrapper.eq(StrUtil.isNotBlank(ioOrderDetailResultEntity.getBatchNo()), "batchNo", ioOrderDetailResultEntity.getBatchNo());
wrapper.eq(StrUtil.isNotBlank(ioOrderDetailResultEntity.getNameCode()), "nameCode", ioOrderDetailResultEntity.getNameCode());
return wrapper;
}
/**
*
*
* @param quarter 1
* @return
*/
private List<IoStatMonthEntity> getMonthStatList(DateTime yesterday) {
int quarter = yesterday.quarter();
List<Integer> months = new ArrayList<>(3);
switch (quarter) {
case 1:
months.addAll(Arrays.asList(1, 2, 3));
break;
case 2:
months.addAll(Arrays.asList(4, 5, 6));
break;
case 3:
months.addAll(Arrays.asList(7, 8, 9));
break;
case 4:
months.addAll(Arrays.asList(10, 11, 12));
break;
default:
break;
}
List<IoStatMonthEntity> list = statMonthDao.selectList(new QueryWrapper<IoStatMonthEntity>()
.eq("year", yesterday.year())
.eq("quarter", yesterday.quarter())
.in("month", months)
);
return list;
//计算季初
public static String getStartDayOfQuarter(int year, int quarter) {
int startMonth = (quarter - 1) * 3;
// 根据月获取开始时间
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, startMonth);
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
// 创建 SimpleDateFormat 对象,用于格式化日期时间
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
// 使用 SimpleDateFormat 格式化 Calendar 对象,得到格式化之后的字符串
String dateString = df.format(cal.getTime());
return dateString;
}
//计算季末
public static String getLastDayOfQuarter(int year, int quarter) {
int lastMonth = quarter * 3 - 1;
// 根据月获取开始时间
// 根据月获取开始时间
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, lastMonth);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
// 创建 SimpleDateFormat 对象,用于格式化日期时间
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
// 使用 SimpleDateFormat 格式化 Calendar 对象,得到格式化之后的字符串
String dateString = df.format(cal.getTime());
return dateString;
}
private List<IoStatQuarterEntity> getNewOrOldDate(List<IoStatQuarterEntity> newIoStatDayEntity, List<IoStatQuarterEntity> oldIoStatDayEntity, DateTime lastMonth) {
// 计算出两个集合之间产品批次号组成的差异
// List<IoStatMonthEntity> ioStatMonthEntityList = oldIoStatDayEntity.stream().filter(notComment -> {
// List<IoStatMonthEntity> filtered = newIoStatDayEntity.stream().filter(all -> all.getBatchNo().equals(notComment.getBatchNo()) && all.getRelIdFk().equals(notComment.getRelIdFk())).collect(Collectors.toList());
// return filtered.isEmpty();
// }).collect(Collectors.toList());
List<IoStatQuarterEntity> ioStatMonthEntityList = oldIoStatDayEntity.stream()
.filter(notComment -> {
List<IoStatQuarterEntity> filtered = newIoStatDayEntity.stream().filter(all ->
Objects.equals(all.getBatchNo(), notComment.getBatchNo()) // 使用 Objects.equals 来进行非空判断
&& Objects.equals(all.getRelIdFk(), notComment.getRelIdFk())
&& Objects.equals(all.getDeptCode(), notComment.getDeptCode()))
.collect(Collectors.toList());
return filtered.isEmpty();
}).collect(Collectors.toList());
for (IoStatQuarterEntity ioStatDayEntity : ioStatMonthEntityList) {
ioStatDayEntity.setId(null);
ioStatDayEntity.setBeginCount(ioStatDayEntity.getBalanceCount());
ioStatDayEntity.setBeginAmount(ioStatDayEntity.getBalanceAmount());
ioStatDayEntity.setBeginPrice(ioStatDayEntity.getBalancePrice());
ioStatDayEntity.setQuarter(ioStatDayEntity.getQuarter()+1);
ioStatDayEntity.setInAmount(new BigDecimal(0));
ioStatDayEntity.setOutAmount(new BigDecimal(0));
ioStatDayEntity.setInCount(0);
ioStatDayEntity.setOutCount(0);
}
return ioStatMonthEntityList;
}
}

@ -6,12 +6,9 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.glxp.api.dao.inout.IoStatOrderDao;
import com.glxp.api.dao.inout.IoStatQuarterDao;
import com.glxp.api.dao.inout.IoStatYearDao;
import com.glxp.api.entity.inout.IoStatOrderEntity;
import com.glxp.api.entity.inout.IoStatQuarterEntity;
import com.glxp.api.entity.inout.IoStatYearEntity;
import com.glxp.api.constant.ConstantType;
import com.glxp.api.dao.inout.*;
import com.glxp.api.entity.inout.*;
import com.glxp.api.req.inout.FilterStatDataDetailRequest;
import com.glxp.api.service.inout.IoStatYearService;
import com.glxp.api.util.GennerOrderUtils;
@ -26,10 +23,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
@ -46,31 +41,60 @@ public class IoStatYearServiceImpl implements IoStatYearService {
private GennerOrderUtils gennerOrderUtils;
@Resource
private SqlSessionFactory sqlSessionFactory;
@Resource
private IoOrderDao orderDao;
@Resource
private IoOrderDetailResultDao ioOrderDetailResultDao;
@Override
public void statData(Date date) {
//汇总上一年度的数据
DateTime yesterday = DateUtil.offsetDay(date, -1);
List<IoStatYearEntity> dataList = new ArrayList<>();
//查询上一年度各个季度的数据
List<IoStatQuarterEntity> statQuarterList = getQuarterStatList(yesterday);
if (CollUtil.isNotEmpty(statQuarterList)) {
//查询单号
List<String> orderIdFkList = new ArrayList<>();
//汇总上一个季度的数据
orderIdFkList = orderDao.selectOrderfirstAndLastIdList(yesterday.year()+"-12-31", yesterday.year()+"-01-01");
List<IoOrderDetailResultEntity> orderDetailResultEntities = new ArrayList<>();
if(orderIdFkList.size()>0){
orderDetailResultEntities = ioOrderDetailResultDao.selectStatDataByTime(orderIdFkList);
}
if (CollUtil.isNotEmpty(orderDetailResultEntities)) {
//声明用于存放汇总数据的集合
List<IoStatYearEntity> dataList = new ArrayList<>();
statQuarterList.forEach(statQuarterEntity -> {
orderDetailResultEntities.forEach(orderDetailResultEntity -> {
//获取新的汇总数据
IoStatYearEntity statData = getStatData(dataList, statQuarterEntity, yesterday);
//设置入库数据
statData.setInCount(statData.getInCount() + statQuarterEntity.getInCount());
statData.setInPrice(statQuarterEntity.getInPrice());
statData.setInAmount(statData.getInAmount().add(statQuarterEntity.getInAmount()));
IoStatYearEntity statData = getStatData(dataList, orderDetailResultEntity, yesterday);
//设置出库数据
statData.setOutCount(statData.getOutCount() + statQuarterEntity.getOutCount());
statData.setOutPrice(statQuarterEntity.getOutPrice());
statData.setOutAmount(statData.getOutAmount().add(statQuarterEntity.getOutAmount()));
//查询此单是出库还是入库
IoOrderEntity order = orderDao.selectOne(new QueryWrapper<IoOrderEntity>().select("mainAction").eq("billNo", orderDetailResultEntity.getOrderIdFk()).eq("deptCode",orderDetailResultEntity.getDeptCode()));
if (order.getMainAction().equals(ConstantType.TYPE_PUT)) {
//入库
statData.setInCount(orderDetailResultEntity.getReCount() + statData.getInCount());
if (null != orderDetailResultEntity.getPrice()) {
BigDecimal inAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount()));
statData.setInAmount(inAmount.add(statData.getInAmount()));
}
} else if (order.getMainAction().equals(ConstantType.TYPE_OUT)) {
//出库
statData.setOutCount(orderDetailResultEntity.getReCount() + statData.getOutCount());
if (null != orderDetailResultEntity.getPrice()) {
BigDecimal outAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount()));
statData.setOutAmount(outAmount.add(statData.getOutAmount()));
}
}
});
//汇总上一季度存在上上一季度不存在产品的汇总数据
//获取上上天的数据
QueryWrapper<IoStatYearEntity> ew = new QueryWrapper<>();
ew.eq("year", yesterday.year()-1);
List<IoStatYearEntity> ioStatMonthEntityList=statYearDao.selectList(ew);
List<IoStatYearEntity> newOrOldDate=getNewOrOldDate(dataList,ioStatMonthEntityList,yesterday);
dataList.addAll(newOrOldDate);
//插入汇总数据
saveData(yesterday, dataList);
}
@ -105,7 +129,7 @@ public class IoStatYearServiceImpl implements IoStatYearService {
OrderNoTypeBean orderNoTypeBean = new OrderNoTypeBean("STATY", "yyyyMMdd");
String orderNo = gennerOrderUtils.createStatOrderNo(orderNoTypeBean);
statOrderEntity.setRecordKey(orderNo);
statOrderEntity.setType(3);
statOrderEntity.setType(1);
statOrderEntity.setDate(yesterday);
statOrderEntity.setTitle(yesterday.year() + " 年度出入库汇总");
@ -134,18 +158,19 @@ public class IoStatYearServiceImpl implements IoStatYearService {
*
*
* @param dataList
* @param statQuarterEntity
* @param orderDetailResultEntity
* @param yesterday
* @return
*/
private IoStatYearEntity getStatData(List<IoStatYearEntity> dataList, IoStatQuarterEntity statQuarterEntity, DateTime yesterday) {
private IoStatYearEntity getStatData(List<IoStatYearEntity> dataList, IoOrderDetailResultEntity orderDetailResultEntity, DateTime yesterday) {
if (CollUtil.isNotEmpty(dataList)) {
for (IoStatYearEntity statYearEntity : dataList) {
if (statYearEntity.getRelIdFk().equals(statQuarterEntity.getRelIdFk())) {
if ((StrUtil.isNotBlank(statYearEntity.getBatchNo()) && StrUtil.isNotBlank(statQuarterEntity.getBatchNo())) && statYearEntity.getBatchNo().endsWith(statQuarterEntity.getBatchNo())) {
return statYearEntity;
} else if (StrUtil.isBlank(statYearEntity.getBatchNo()) && StrUtil.isBlank(statQuarterEntity.getBatchNo())) {
return statYearEntity;
for (IoStatYearEntity statDayEntity : dataList) {
if (Long.valueOf(statDayEntity.getRelIdFk()).equals(orderDetailResultEntity.getBindRlFk()) && statDayEntity.getDeptCode().equals(orderDetailResultEntity.getDeptCode())) {
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())) {
return statDayEntity;
}
}
}
@ -154,28 +179,29 @@ public class IoStatYearServiceImpl implements IoStatYearService {
//未在于集合中,构造新数据
IoStatYearEntity statData = new IoStatYearEntity();
statData.setYear(yesterday.year());
statData.setRelIdFk(statQuarterEntity.getRelIdFk());
statData.setNameCode(statQuarterEntity.getNameCode());
statData.setProductName(statQuarterEntity.getProductName());
statData.setGgxh(statQuarterEntity.getGgxh());
statData.setBatchNo(statQuarterEntity.getBatchNo());
statData.setDeptCode(orderDetailResultEntity.getDeptCode());
statData.setRelIdFk(String.valueOf(orderDetailResultEntity.getBindRlFk()));
statData.setNameCode(orderDetailResultEntity.getNameCode());
statData.setProductName(orderDetailResultEntity.getCoName());
statData.setGgxh(orderDetailResultEntity.getSpec());
statData.setBatchNo(orderDetailResultEntity.getBatchNo());
//设置结余价格
statData.setBalancePrice(statQuarterEntity.getBalancePrice());
statData.setBalancePrice(orderDetailResultEntity.getPrice());
//设置初始化出入库数量和价格
statData.setInCount(0);
statData.setInPrice(statQuarterEntity.getBalancePrice());
statData.setInPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice());
statData.setInAmount(BigDecimal.ZERO);
statData.setOutCount(0);
statData.setOutPrice(statQuarterEntity.getBalancePrice());
statData.setOutPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice());
statData.setOutAmount(BigDecimal.ZERO);
//设置期初数据
IoStatYearEntity statYearEntity = statYearDao.selectOne(buildQueryWrapper(statQuarterEntity, yesterday));
IoStatYearEntity statYearEntity = statYearDao.selectOne(buildQueryWrapper(orderDetailResultEntity, yesterday));
if (null == statYearEntity) {
//第一次汇总度数据
//第一次汇总度数据
statData.setBeginCount(0);
statData.setBalancePrice(statYearEntity.getBalancePrice());
statData.setBeginPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice());
statData.setBeginAmount(BigDecimal.ZERO);
statData.setBalanceCount(0);
@ -190,7 +216,7 @@ public class IoStatYearServiceImpl implements IoStatYearService {
}
//设置结余价格
statData.setBalancePrice(statYearEntity.getBalancePrice());
statData.setBalancePrice(statData.getBeginPrice());
dataList.add(statData);
return statData;
@ -199,15 +225,15 @@ public class IoStatYearServiceImpl implements IoStatYearService {
/**
*
*
* @param statQuarterEntity
* @param ioOrderDetailResultEntity
* @param yesterday
*/
private QueryWrapper<IoStatYearEntity> buildQueryWrapper(IoStatQuarterEntity statQuarterEntity, DateTime yesterday) {
private QueryWrapper<IoStatYearEntity> buildQueryWrapper(IoOrderDetailResultEntity ioOrderDetailResultEntity, DateTime yesterday) {
QueryWrapper<IoStatYearEntity> wrapper = new QueryWrapper<>();
wrapper.eq("year", yesterday.year() - 1)
.eq("relIdFk", statQuarterEntity.getRelIdFk())
.eq(StrUtil.isNotBlank(statQuarterEntity.getBatchNo()), "batchNo", statQuarterEntity.getBatchNo())
.eq(StrUtil.isNotBlank(statQuarterEntity.getNameCode()), "nameCode", statQuarterEntity.getNameCode());
wrapper.eq("year", yesterday.year() - 1);
wrapper.eq("relIdFk", ioOrderDetailResultEntity.getBindRlFk());
wrapper.eq(StrUtil.isNotBlank(ioOrderDetailResultEntity.getBatchNo()), "batchNo", ioOrderDetailResultEntity.getBatchNo());
wrapper.eq(StrUtil.isNotBlank(ioOrderDetailResultEntity.getNameCode()), "nameCode", ioOrderDetailResultEntity.getNameCode());
return wrapper;
}
@ -223,4 +249,36 @@ public class IoStatYearServiceImpl implements IoStatYearService {
);
return list;
}
private List<IoStatYearEntity> getNewOrOldDate(List<IoStatYearEntity> newIoStatDayEntity, List<IoStatYearEntity> oldIoStatDayEntity, DateTime lastMonth) {
// 计算出两个集合之间产品批次号组成的差异
// List<IoStatMonthEntity> ioStatMonthEntityList = oldIoStatDayEntity.stream().filter(notComment -> {
// List<IoStatMonthEntity> filtered = newIoStatDayEntity.stream().filter(all -> all.getBatchNo().equals(notComment.getBatchNo()) && all.getRelIdFk().equals(notComment.getRelIdFk())).collect(Collectors.toList());
// return filtered.isEmpty();
// }).collect(Collectors.toList());
List<IoStatYearEntity> ioStatMonthEntityList = oldIoStatDayEntity.stream()
.filter(notComment -> {
List<IoStatYearEntity> filtered = newIoStatDayEntity.stream().filter(all ->
Objects.equals(all.getBatchNo(), notComment.getBatchNo()) // 使用 Objects.equals 来进行非空判断
&& Objects.equals(all.getRelIdFk(), notComment.getRelIdFk())
&& Objects.equals(all.getDeptCode(), notComment.getDeptCode()))
.collect(Collectors.toList());
return filtered.isEmpty();
}).collect(Collectors.toList());
for (IoStatYearEntity ioStatDayEntity : ioStatMonthEntityList) {
ioStatDayEntity.setId(null);
ioStatDayEntity.setBeginCount(ioStatDayEntity.getBalanceCount());
ioStatDayEntity.setBeginAmount(ioStatDayEntity.getBalanceAmount());
ioStatDayEntity.setBeginPrice(ioStatDayEntity.getBalancePrice());
ioStatDayEntity.setYear(ioStatDayEntity.getYear()+1);
ioStatDayEntity.setInAmount(new BigDecimal(0));
ioStatDayEntity.setOutAmount(new BigDecimal(0));
ioStatDayEntity.setInCount(0);
ioStatDayEntity.setOutCount(0);
}
return ioStatMonthEntityList;
}
}

@ -72,17 +72,17 @@ public class IoStatOrderTask implements SchedulingConfigurer {
if (DateUtil.isYearStart(today)) {
//年初第一天,依次生成 日 -> 月 -> 季度 -> 年度 汇总数据
ThreadUtil.execAsync(() -> {
log.info("开始生成每日物资出入库汇总数据");
statDayService.statData(today);
log.info("每日物资出入库数据汇总生成结束");
log.info("本日为月初,生成月度物资出入库汇总数据");
statMonthService.statData(today);
log.info("月度物资出入库汇总数据生成结束");
log.info("本日为季初,生成季度物资出入库汇总数据");
statQuarterService.statData(today);
log.info("季度物资出入库汇总数据生成结束");
// log.info("开始生成每日物资出入库汇总数据");
// statDayService.statData(today);
// log.info("每日物资出入库数据汇总生成结束");
//
// log.info("本日为月初,生成月度物资出入库汇总数据");
// statMonthService.statData(today);
// log.info("月度物资出入库汇总数据生成结束");
//
// log.info("本日为季初,生成季度物资出入库汇总数据");
// statQuarterService.statData(today);
// log.info("季度物资出入库汇总数据生成结束");
log.info("本日为年初,生成年度物资出入库汇总数据");
statYearService.statData(today);

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.glxp.api.dao.inout.IoStatQuarterDao">
<select id="filterList" resultType="com.glxp.api.entity.inout.IoStatQuarterEntity">
select *
select *, ( SELECT NAME FROM auth_dept WHERE io_stat_quarter.deptCode = auth_dept.CODE ) deptName
from io_stat_quarter
<where>
<if test="recordKey != null and recordKey != ''">

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.glxp.api.dao.inout.IoStatYearDao">
<select id="filterList" resultType="com.glxp.api.entity.inout.IoStatYearEntity">
select *
select *, ( SELECT NAME FROM auth_dept WHERE io_stat_year.deptCode = auth_dept.CODE ) deptName
from io_stat_year
<where>
<if test="recordKey != null and recordKey != ''">

Loading…
Cancel
Save