CZT
2023-08-16 7fbb3a0cec59554367b527f55d81e3997eacf4c9
igds-inout/src/main/java/com/ld/igds/timer/DepotStoreScheduled.java
@@ -2,12 +2,14 @@
import com.bstek.bdf2.core.model.DefaultCompany;
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.models.DepotStore;
import com.ld.igds.models.InoutLossOver;
import com.ld.igds.models.InoutRecord;
import com.ld.igds.util.ContextUtil;
import lombok.extern.slf4j.Slf4j;
@@ -53,14 +55,81 @@
        param.setStart(DateUtils.addDays(param.getEnd(), -1));
        List<InoutData> listRecord;
        List<InoutLossOver> listLossOver;
        for (DefaultCompany company : listCompany) {
            param.setCompanyId(company.getId());
            listRecord = inoutService.listRecordData(param);
            //根据出入库信息,同步库存信息
            // 根据出入库信息,同步库存信息
            sumDepotStoreExe(company.getId(), listRecord, param);
            listLossOver = inoutService.listLossOver(param);
            // 根据损耗信息,同步库存信息
            sumDepotStoreByLossOver(company.getId(), listLossOver, param);
        }
    }
    /**
     * 同步仓库库存,根据近期出入库记录,如果没有记录则表示无出入库操作,取消执行
     *
     * @param companyId
     * @param listLossOver
     */
    private void sumDepotStoreByLossOver(String companyId, List<InoutLossOver> listLossOver, InoutParam param) {
        if (null == listLossOver || listLossOver.isEmpty()) {
            log.info("-----------系统自动同步库存,近期无损益记录,取消同步仓库库存……{}", companyId);
            return;
        }
        // 获取有出入库记录的仓库
        Map<String, InoutLossOver> map = new HashMap<>();
        String key;
        DepotStore lastStore;
        double sumRecordWeight = 0.0;
        for (InoutLossOver data : listLossOver) {
            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;
            }
            param.setDeptId(data.getDeptId());
            param.setDepotId(data.getDepotId());
            param.setCompanyId(data.getCompanyId());
            param.setType(data.getType());
            //获取出入库的重量信息
            sumRecordWeight = inoutService.sumLossOverWeight(param);
            //新增一条库存记录
            lastStore.setRemark("系统定时生成记录");
            lastStore.setId(ContextUtil.getUUID());
            lastStore.setUpdateUser("系统管理员");
            lastStore.setUpdateDate(new Date());
            lastStore.setCreateDate(new Date());
            if(Constant.LOSS_OVER_LOSS.equals(data.getType())){
                lastStore.setStorageReal(lastStore.getStorageReal() + sumRecordWeight);
            }
            if(Constant.LOSS_OVER_OVER.equals(data.getType())){
                lastStore.setStorageReal(lastStore.getStorageReal() - sumRecordWeight);
            }
            lastStore.setStorageSettle(lastStore.getStorageReal());
            commonService.addDepotStore(lastStore, true);
        }
    }
    /**
@@ -126,10 +195,6 @@
            //设置入库时间
            if(null == lastStore.getStoreDate()){
               lastStore.setStoreDate(data.getCompleteTime());
            }
            //若出库后数量为负数,则设置库存数为0.0
            if(lastStore.getStorageReal() < 0){
               lastStore.setStorageReal(0.0);
            }
         }