package com.ld.igds.timer;
|
|
import com.bstek.bdf2.core.model.DefaultCompany;
|
import com.bstek.dorado.annotation.Expose;
|
import com.ld.igds.common.CoreCommonService;
|
import com.ld.igds.constant.Constant;
|
import com.ld.igds.constant.DepotStatus;
|
import com.ld.igds.inout.InoutConstant;
|
import com.ld.igds.inout.dto.InoutData;
|
import com.ld.igds.inout.dto.InoutParam;
|
import com.ld.igds.inout.service.InoutService;
|
import com.ld.igds.m.service.InoutCommonService;
|
import com.ld.igds.models.*;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.util.DateUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @Desc: 出入库定时任务。
|
* 1、通知单完成量统计
|
* 2、出入库库存管理统计
|
* @author: Andy
|
* @update-time: 2022/11/22
|
*/
|
@Slf4j
|
@Component(InoutScheduled.BEAN_ID)
|
public class InoutScheduled {
|
|
public static final String BEAN_ID = "basic.inoutScheduled";
|
|
@Resource
|
private InoutCommonService inoutCommonService;
|
|
@Resource
|
private InoutService inoutService;
|
|
@Resource
|
private CoreCommonService commonService;
|
|
|
/**
|
* 每天晚上11点进行更新未完成出入库通知单的完成量
|
*/
|
@Scheduled(cron = "0 0 23 * * ?")
|
public void scheduled1() {
|
|
List<DefaultCompany> listCompany = commonService.getCompanyList();
|
if (null == listCompany) return;
|
|
//获取3天内的出入库记录,如果有记录则执行,如果没有,则无需执行
|
Date start = DateUtil.getNewByDay(null, -3);
|
InoutParam param;
|
List<InoutData> listRecord;
|
for (DefaultCompany company : listCompany) {
|
param = new InoutParam();
|
param.setStart(start);
|
param.setCompanyId(company.getId());
|
listRecord = inoutService.listRecordData(param);
|
|
noticeCompleteExe(company.getId(), listRecord);
|
|
sumDepotStoreExe(company.getId(), listRecord);
|
}
|
|
}
|
|
|
/**
|
* basic.inoutScheduled#sumDepotStoreExeByHand
|
* <p>
|
* <p>
|
* 手动执行出入库库存统计入口
|
*
|
* @param start
|
* @return
|
*/
|
@Expose
|
public String sumDepotStoreExeByHand(Date start) {
|
|
if (null == start) start = new Date();
|
|
start = DateUtil.getCurZero(start);
|
|
//获取3天内的出入库记录,如果有记录则执行,如果没有,则无需执行
|
start = DateUtil.getNewByDay(null, -3);
|
String companyId = ContextUtil.getCompanyId();
|
|
InoutParam param = new InoutParam();
|
param.setStart(start);
|
param.setCompanyId(companyId);
|
|
List<InoutData> listRecord = inoutService.listRecordData(param);
|
|
sumDepotStoreExe(companyId, listRecord);
|
|
return "SUCCESS";
|
}
|
|
/**
|
* 同步仓库库存,根据近期出入库记录,如果没有记录则表示无出入库操作,取消执行
|
*
|
* @param companyId
|
* @param listRecord
|
*/
|
private void sumDepotStoreExe(String companyId, List<InoutData> listRecord) {
|
|
if (null == listRecord || listRecord.isEmpty()) {
|
log.info("-----------系统自动同步库存,近期无出入库记录,取消同步仓库库存……{}", companyId);
|
return;
|
}
|
|
//获取有出入库记录的仓库
|
Map<String, InoutRecord> map = new HashMap<>();
|
String key;
|
DepotStore lastStore;
|
double sumRecordWeight = 0.0;
|
InoutParam param;
|
for (InoutData data : listRecord) {
|
key = data.getDepotId() + "_" + data.getType();
|
if (null != map.get(key)) continue;
|
|
|
map.put(key, data);
|
|
//根据最后一车进行汇总统计,开始时间是仓库库存最后一个时间截止到当前
|
lastStore = commonService.getLastDepotStore(data.getDepotId());
|
if (null == lastStore) {
|
log.error("--------出入库定时任务-----没有获取到仓库最后库存信息,取消自动统计,请核对业务逻辑--仓库-{}", data.getDepotId());
|
continue;
|
}
|
|
|
//只有出入库状态的仓库才进行统计,其他状态表示出入库作业完成,不在执行统计
|
if (DepotStatus.STATUS_03.getCode().equals(lastStore.getDepotStatus()) ||
|
DepotStatus.STATUS_04.getCode().equals(lastStore.getDepotStatus())) {
|
|
param = new InoutParam();
|
param.setStart(lastStore.getCreateDate());
|
param.setEnd(new Date());
|
param.setDeptId(data.getDeptId());
|
param.setDepotId(data.getDepotId());
|
param.setCompanyId(data.getCompanyId());
|
param.setType(data.getType());
|
|
//出入库重量合计
|
sumRecordWeight = inoutService.sumRecordWeight(param);
|
|
//新增一条库存记录
|
lastStore.setRemark("系统定时生成记录");
|
lastStore.setId(ContextUtil.getUUID());
|
lastStore.setUpdateUser(null);
|
lastStore.setUpdateDate(new Date());
|
lastStore.setCreateDate(new Date());
|
|
if (InoutConstant.TYPE_IN.equals(data.getType())) {
|
lastStore.setStorageReal(lastStore.getStorageReal() + sumRecordWeight);
|
}
|
|
if (InoutConstant.TYPE_OUT.equals(data.getType())) {
|
lastStore.setStorageReal(lastStore.getStorageReal() - sumRecordWeight);
|
}
|
|
commonService.addDepotStore(lastStore, true);
|
}
|
|
}
|
}
|
|
|
/**
|
* 同步通知单完成量,根据近期出入库记录,如果无近期出入库记录,则表示无出入库作业,取消执行
|
*
|
* @param companyId
|
* @param listRecord
|
*/
|
public void noticeCompleteExe(String companyId, List<InoutData> listRecord) {
|
log.info("----------系统定时更新出入库通知单完成量----------");
|
|
if (null == listRecord || listRecord.isEmpty()) {
|
log.info("-----------系统自动同步库存,近期无出入库记录,取消同步通知单完成量……{}", companyId);
|
return;
|
}
|
|
|
List<InoutSysConf> inoutSysConfList = inoutCommonService.getCacheInoutSysConf(companyId);
|
|
//不配置说明没有启动出入库
|
if (null == inoutSysConfList || inoutSysConfList.isEmpty()) {
|
return;
|
}
|
|
//获取所有未完成状态的出库通知单
|
List<InoutNoticeOut> noticeOutList = inoutCommonService.getUnComNoticeOut(companyId);
|
|
|
//获取所有未完成状态的入库通知单
|
List<InoutNoticeIn> noticeInList = inoutCommonService.getUnComNoticeIn(companyId);
|
|
|
for (InoutSysConf inoutSysConf : inoutSysConfList) {
|
|
// 判断入库通知单是否启用
|
if (Constant.YN_Y.equals(inoutSysConf.getNoticeTagIn())) {
|
//更新入库通知单完成量
|
inoutCommonService.updateSumNoticeIn(inoutSysConf.getDeptId(), noticeInList);
|
}
|
|
// 判断出库通知单是否启用
|
if (Constant.YN_Y.equals(inoutSysConf.getNoticeTagOut())) {
|
//更新出库通知单完成量
|
inoutCommonService.updateSumNoticeOut(inoutSysConf.getDeptId(), noticeOutList);
|
}
|
}
|
}
|
|
}
|