|
|
|
@ -10,6 +10,7 @@ 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.res.inv.IoOrderDetailStatRsponse;
|
|
|
|
|
import com.glxp.api.service.inout.IoStatQuarterService;
|
|
|
|
|
import com.glxp.api.util.GennerOrderUtils;
|
|
|
|
|
import com.glxp.api.util.OrderNoTypeBean;
|
|
|
|
@ -54,15 +55,15 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
|
|
|
|
|
//查询上一季度各个月度的数据
|
|
|
|
|
int quarter = yesterday.quarter();
|
|
|
|
|
int year = yesterday.year();
|
|
|
|
|
String topDate=getStartDayOfQuarter(year,quarter);
|
|
|
|
|
String lastDate=getLastDayOfQuarter(year,quarter);
|
|
|
|
|
String topDate = getStartDayOfQuarter(year, quarter);
|
|
|
|
|
String lastDate = getLastDayOfQuarter(year, quarter);
|
|
|
|
|
//查询单号
|
|
|
|
|
List<String> orderIdFkList = new ArrayList<>();
|
|
|
|
|
//汇总上一个季度的数据
|
|
|
|
|
List<IoStatQuarterEntity> dataList = new ArrayList<>();
|
|
|
|
|
orderIdFkList = orderDao.selectOrderfirstAndLastIdList(lastDate, topDate);
|
|
|
|
|
List<IoOrderDetailResultEntity> orderDetailResultEntities = new ArrayList<>();
|
|
|
|
|
if(orderIdFkList.size()>0){
|
|
|
|
|
List<IoOrderDetailStatRsponse> orderDetailResultEntities = new ArrayList<>();
|
|
|
|
|
if (orderIdFkList.size() > 0) {
|
|
|
|
|
orderDetailResultEntities = ioOrderDetailResultDao.selectStatDataByTime(orderIdFkList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -73,7 +74,7 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
|
|
|
|
|
IoStatQuarterEntity statData = getStatData(dataList, orderDetailResultEntity, yesterday);
|
|
|
|
|
|
|
|
|
|
//查询此单是出库还是入库
|
|
|
|
|
IoOrderEntity order = orderDao.selectOne(new QueryWrapper<IoOrderEntity>().select("mainAction").eq("billNo", orderDetailResultEntity.getOrderIdFk()).eq("deptCode",orderDetailResultEntity.getDeptCode()));
|
|
|
|
|
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());
|
|
|
|
@ -95,9 +96,9 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
|
|
|
|
|
//获取上上天的数据
|
|
|
|
|
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);
|
|
|
|
|
ew.eq("quarter", yesterday.quarter() - 1);
|
|
|
|
|
List<IoStatQuarterEntity> ioStatMonthEntityList = statQuarterDao.selectList(ew);
|
|
|
|
|
List<IoStatQuarterEntity> newOrOldDate = getNewOrOldDate(dataList, ioStatMonthEntityList, yesterday);
|
|
|
|
|
dataList.addAll(newOrOldDate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -127,40 +128,48 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
|
|
|
|
|
* 插入汇总数据
|
|
|
|
|
*
|
|
|
|
|
* @param yesterday 时间
|
|
|
|
|
* @param dataList 数据集合
|
|
|
|
|
*/
|
|
|
|
|
private void saveData(DateTime yesterday, List<IoStatQuarterEntity> dataList) {
|
|
|
|
|
//生成汇总记录
|
|
|
|
|
IoStatOrderEntity statOrderEntity = new IoStatOrderEntity();
|
|
|
|
|
//生成记录号
|
|
|
|
|
OrderNoTypeBean orderNoTypeBean = new OrderNoTypeBean("STATQ", "yyyyMMdd");
|
|
|
|
|
String orderNo = gennerOrderUtils.createStatOrderNo(orderNoTypeBean);
|
|
|
|
|
statOrderEntity.setRecordKey(orderNo);
|
|
|
|
|
statOrderEntity.setType(2);
|
|
|
|
|
DateTime dateTime=DateUtil.offsetDay(yesterday,+1);
|
|
|
|
|
statOrderEntity.setDate(dateTime);
|
|
|
|
|
statOrderEntity.setTitle(yesterday.year() + " 年 " + yesterday.quarter() + " 季度出入库汇总");
|
|
|
|
|
|
|
|
|
|
Date updateTime = new Date();
|
|
|
|
|
statOrderEntity.setUpdateTime(updateTime);
|
|
|
|
|
|
|
|
|
|
statOrderDao.insert(statOrderEntity);
|
|
|
|
|
|
|
|
|
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
|
|
|
|
|
IoStatQuarterDao mapper = sqlSession.getMapper(IoStatQuarterDao.class);
|
|
|
|
|
dataList.forEach(statQuarterEntity -> {
|
|
|
|
|
statQuarterEntity.setUpdateTime(updateTime);
|
|
|
|
|
statQuarterEntity.setRecordKeyFk(orderNo);
|
|
|
|
|
|
|
|
|
|
//设置结余数据
|
|
|
|
|
statQuarterEntity.setBalanceCount(statQuarterEntity.getBalanceCount() + statQuarterEntity.getInCount() - statQuarterEntity.getOutCount());
|
|
|
|
|
statQuarterEntity.setBalanceAmount(statQuarterEntity.getBalanceAmount().add(statQuarterEntity.getInAmount()).subtract(statQuarterEntity.getOutAmount()));
|
|
|
|
|
|
|
|
|
|
mapper.insert(statQuarterEntity);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sqlSession.commit();
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
private void saveData(DateTime yesterday, List<IoStatQuarterEntity> statQuarterEntities) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, List<IoStatQuarterEntity>> stringListMap = statQuarterEntities.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(IoStatQuarterEntity::getInvCode));
|
|
|
|
|
|
|
|
|
|
for (String key : stringListMap.keySet()) {
|
|
|
|
|
List<IoStatQuarterEntity> dataList = stringListMap.get(key);
|
|
|
|
|
//生成汇总记录
|
|
|
|
|
IoStatOrderEntity statOrderEntity = new IoStatOrderEntity();
|
|
|
|
|
//生成记录号
|
|
|
|
|
OrderNoTypeBean orderNoTypeBean = new OrderNoTypeBean("STATQ", "yyyyMMdd");
|
|
|
|
|
String orderNo = gennerOrderUtils.createStatOrderNo(orderNoTypeBean);
|
|
|
|
|
statOrderEntity.setRecordKey(orderNo);
|
|
|
|
|
statOrderEntity.setType(2);
|
|
|
|
|
DateTime dateTime = DateUtil.offsetDay(yesterday, +1);
|
|
|
|
|
statOrderEntity.setDate(dateTime);
|
|
|
|
|
statOrderEntity.setTitle(yesterday.year() + " 年 " + yesterday.quarter() + " 季度出入库汇总");
|
|
|
|
|
|
|
|
|
|
Date updateTime = new Date();
|
|
|
|
|
statOrderEntity.setUpdateTime(updateTime);
|
|
|
|
|
|
|
|
|
|
statOrderDao.insert(statOrderEntity);
|
|
|
|
|
|
|
|
|
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
|
|
|
|
|
IoStatQuarterDao mapper = sqlSession.getMapper(IoStatQuarterDao.class);
|
|
|
|
|
dataList.forEach(statQuarterEntity -> {
|
|
|
|
|
statQuarterEntity.setUpdateTime(updateTime);
|
|
|
|
|
statQuarterEntity.setRecordKeyFk(orderNo);
|
|
|
|
|
|
|
|
|
|
//设置结余数据
|
|
|
|
|
statQuarterEntity.setBalanceCount(statQuarterEntity.getBalanceCount() + statQuarterEntity.getInCount() - statQuarterEntity.getOutCount());
|
|
|
|
|
statQuarterEntity.setBalanceAmount(statQuarterEntity.getBalanceAmount().add(statQuarterEntity.getInAmount()).subtract(statQuarterEntity.getOutAmount()));
|
|
|
|
|
|
|
|
|
|
mapper.insert(statQuarterEntity);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sqlSession.commit();
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -171,7 +180,7 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
|
|
|
|
|
* @param yesterday
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private IoStatQuarterEntity getStatData(List<IoStatQuarterEntity> dataList, IoOrderDetailResultEntity orderDetailResultEntity, DateTime yesterday) {
|
|
|
|
|
private IoStatQuarterEntity getStatData(List<IoStatQuarterEntity> dataList, IoOrderDetailStatRsponse orderDetailResultEntity, DateTime yesterday) {
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(dataList)) {
|
|
|
|
|
for (IoStatQuarterEntity statDayEntity : dataList) {
|
|
|
|
@ -238,7 +247,7 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
|
|
|
|
|
* @param yesterday
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private QueryWrapper<IoStatQuarterEntity> buildQueryWrapper(IoOrderDetailResultEntity ioOrderDetailResultEntity, DateTime yesterday) {
|
|
|
|
|
private QueryWrapper<IoStatQuarterEntity> buildQueryWrapper(IoOrderDetailStatRsponse ioOrderDetailResultEntity, DateTime yesterday) {
|
|
|
|
|
QueryWrapper<IoStatQuarterEntity> wrapper = new QueryWrapper<>();
|
|
|
|
|
if (yesterday.quarter() == 1) {
|
|
|
|
|
//当前汇总的记录为第一季度,上一季度时间取前一年的第四季度数据
|
|
|
|
@ -274,7 +283,7 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
|
|
|
|
|
|
|
|
|
|
// 创建 SimpleDateFormat 对象,用于格式化日期时间
|
|
|
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
// 使用 SimpleDateFormat 格式化 Calendar 对象,得到格式化之后的字符串
|
|
|
|
|
// 使用 SimpleDateFormat 格式化 Calendar 对象,得到格式化之后的字符串
|
|
|
|
|
String dateString = df.format(cal.getTime());
|
|
|
|
|
|
|
|
|
|
return dateString;
|
|
|
|
@ -329,7 +338,7 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
|
|
|
|
|
ioStatDayEntity.setBeginCount(ioStatDayEntity.getBalanceCount());
|
|
|
|
|
ioStatDayEntity.setBeginAmount(ioStatDayEntity.getBalanceAmount());
|
|
|
|
|
ioStatDayEntity.setBeginPrice(ioStatDayEntity.getBalancePrice());
|
|
|
|
|
ioStatDayEntity.setQuarter(ioStatDayEntity.getQuarter()+1);
|
|
|
|
|
ioStatDayEntity.setQuarter(ioStatDayEntity.getQuarter() + 1);
|
|
|
|
|
ioStatDayEntity.setInAmount(new BigDecimal(0));
|
|
|
|
|
ioStatDayEntity.setOutAmount(new BigDecimal(0));
|
|
|
|
|
ioStatDayEntity.setInCount(0);
|
|
|
|
|