YYC
2023-07-11 9d1eb684e0b0a3f6a9107db3cc64fc782989a654
igds-inout/src/main/java/com/ld/igds/inout/manager/InoutManager.java
@@ -3,7 +3,6 @@
import com.ld.igds.check.CheckStandardManager;
import com.ld.igds.check.dto.CheckItemData;
import com.ld.igds.check.dto.CheckUpdateResult;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.constant.RespCodeEnum;
import com.ld.igds.data.Page;
import com.ld.igds.data.PageResponse;
@@ -15,15 +14,12 @@
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.Depot;
import com.ld.igds.models.InoutConf;
import com.ld.igds.models.InoutPrice;
import com.ld.igds.models.InoutSysConf;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
@@ -31,7 +27,6 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@@ -50,13 +45,11 @@
    @Resource
    private CoreFileService fileService;
    @Resource
    private CoreCommonService commonService;
    @Resource
    private InoutCommonService inoutCommonService;
    @Resource
    private CheckStandardManager checkStandardManager;
    @Resource
    private InoutDeviceManager inoutDeviceManager;
    private InoutEventControlManager inoutEventControl;
    /**
     * 直接从数据库查询,不考虑信息状态
@@ -200,27 +193,26 @@
     * @param data
     * @return
     */
    private CheckUpdateResult updateCheckItems(InoutData data) {
        CheckUpdateResult result = new CheckUpdateResult();
        if (null == data.getCheckItems())
            return result;
    private InoutData updateCheckItems(InoutData data, boolean toSave) throws Exception {
        try {
            // 更新检验项数据
            result = checkStandardManager.updateCheckItems(data.getCheckId(),
                    data.getCompanyId(), data.getCheckItems());
        if (null == data.getCheckItems()) return data;
            // 将化验数据存入缓存中
            inoutService.setCheckCache(data);
        //设置没有质检ID,取消执行持久化
        if (!toSave) data.setCheckId(null);
            return result;
        // 更新检验项数据
        CheckUpdateResult checkUpdateResult = checkStandardManager.updateCheckItems(data.getCheckId(), data.getCompanyId(), data.getCheckItems());
        } catch (Exception e) {
            log.error("后台异常:{}", e);
            result.setMsg("执行异常:" + e.getMessage());
        if (data.getDeCheck() == 0) {
            data.setDeCheck(checkUpdateResult.getDeSum());
        }
        return result;
        if (data.getAddCheck() == 0) {
            data.setAddCheck(checkUpdateResult.getAddSum());
        }
        return data;
    }
    /**
     * 从缓存中获取下一流程
@@ -298,46 +290,6 @@
        return data;
    }
    public PageResponse<InoutData> submitComplete(InoutData data)
            throws Exception {
        if (StringUtils.isEmpty(data.getId())
                || StringUtils.isEmpty(data.getType())
                || StringUtils.isEmpty(data.getProgress())) {
            return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(),
                    "没有获取到车辆信息。", data);
        }
        data.setUpdateTime(new Date());
        if (null == data.getCompleteTime()) {
            data.setCompleteTime(DateUtil.getNewByMinute(new Date(), 2));
        }
        if (null == data.getCompleteUser()) {
            data.setCompleteUser(ContextUtil.getLoginUserCName());
        }
        // 设置流程节点直接完成
        InoutParam param = new InoutParam();
        param.setCompanyId(data.getCompanyId());
        param.setId(data.getId());
        param.setType(data.getType());
        param.setDeptId(data.getDeptId());
        param.setIntelCard(data.getIntelCard());
        param.setUserId(data.getCompleteUser());
        param.setDepotId(data.getDepotId());
        param.setCompleteTime(data.getCompleteTime());
        param.setProgress(InoutConstant.PROGRESS_RECORD);
        String msg = inoutService.toComplete(param);
        if (null != msg) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
        }
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), null, data);
    }
    /**
     * 卡回收逻辑处理
     *
@@ -378,6 +330,52 @@
                data);
    }
    public PageResponse<InoutData> submitComplete(InoutData data)
            throws Exception {
        if (StringUtils.isEmpty(data.getId())
                || StringUtils.isEmpty(data.getType())
                || StringUtils.isEmpty(data.getProgress())) {
            return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(),
                    "没有获取到车辆信息。", data);
        }
        data.setUpdateTime(new Date());
        if (null == data.getCompleteTime()) {
            data.setCompleteTime(DateUtil.getNewByMinute(new Date(), 2));
        }
        if (null == data.getCompleteUser()) {
            data.setCompleteUser(ContextUtil.getLoginUserCName());
        }
        // 设置流程节点直接完成
        InoutParam param = new InoutParam();
        param.setCompanyId(data.getCompanyId());
        param.setId(data.getId());
        param.setType(data.getType());
        param.setDeptId(data.getDeptId());
        param.setIntelCard(data.getIntelCard());
        param.setUserId(data.getCompleteUser());
        param.setDepotId(data.getDepotId());
        param.setCompleteTime(new Date());
        param.setProgress(InoutConstant.PROGRESS_RECORD);
        String msg = inoutService.toComplete(param);
        if (null != msg) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
        }
        data.setCompleteTime(param.getCompleteTime());
        data.setProgress(InoutConstant.PROGRESS_RECORD);
        inoutService.updateInoutCache(data);
        // 流程完成收事件
        inoutEventControl.onInoutComplete(data);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), null, data);
    }
    /**
     * 补单操作 补单因为完成时间不确定,所以需要系统根据当前数据进行自动检测,调整原来流水信息和库存
     *
@@ -388,7 +386,7 @@
    public String addInoutData(InoutData data) throws Exception {
        if (data.getSettleWeight() <= 0.0) {
            return "补单数据要求结算重量必须大于0";
            return "系统:补单数据要求结算重量必须大于0";
        }
        // 补单数据直接到结果状态
@@ -420,40 +418,34 @@
            data.setCheckUser(loginUser);
        }
        // 保存检测项目
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
            if (null == data.getFullWeightTime()) {
                data.setFullWeightTime(DateUtil.getNewByMinute(new Date(), -50));
            }
            if (null == data.getEmptyWeightTime()) {
                data.setEmptyWeightTime(DateUtil
                        .getNewByMinute(new Date(), -10));
                data.setEmptyWeightTime(DateUtil.getNewByMinute(new Date(), -10));
            }
            // 先执行化验信息保存
            CheckUpdateResult checkResult = checkStandardManager
                    .updateCheckItems(data.getCheckId(), data.getCompanyId(),
                            data.getCheckItems());
            if (null != checkResult) {
                // if (null == data.getWet())data.setWet(checkResult.getWet());
                // if (null ==
                // data.getImpurity())data.setImpurity(checkResult.getImpurity());
            }
            data = this.updateCheckItems(data, false);
        } else {
            if (null == data.getEmptyWeightTime()) {
                data.setEmptyWeightTime(DateUtil
                        .getNewByMinute(new Date(), -50));
                data.setEmptyWeightTime(DateUtil.getNewByMinute(new Date(), -50));
            }
            if (null == data.getFullWeightTime()) {
                data.setFullWeightTime(DateUtil.getNewByMinute(new Date(), -10));
            }
        }
        // 添加补单数据
        String msg = inoutService.insertData(data);
        return msg;
        //先保存主表,后执行子表
        inoutService.insertData(data);
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
            this.updateCheckItems(data, true);
        }
        return null;
    }
    /**
@@ -470,44 +462,17 @@
            return "系统:已经删除的数据不支持修改!";
        }
        // 如果流程未结束,只更新数据
        if (!InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) {
            return inoutService.updateData(data);
        }
        // 如果是已经完成的数据,先获取到修改直接的数据根据数据进行对比
        InoutParam param = new InoutParam();
        param.setId(data.getId());
        param.setCompanyId(data.getCompanyId());
        param.setType(data.getType());
        InoutData record = inoutService.inoutQueryById(param);
        if (null == record) {
            return "当前修改数据已经不存在!";
        }
        // 避免数据库中的数据已经被其他人修改
        if (InoutConstant.RECORD_STATUS_DEL.equals(record.getRecordStatus())) {
            return "系统:已经删除的数据不支持修改!";
        if (InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) {
            return "系统:流程已经结束的数据不支持修改!";
        }
        // 保存检测项目
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
            // 先执行化验信息保存
            CheckUpdateResult checkResult = checkStandardManager
                    .updateCheckItems(data.getCheckId(), data.getCompanyId(),
                            data.getCheckItems());
            if (null != checkResult) {
                // if (null == data.getWet())
                // data.setWet(checkResult.getWet());
                // if (null == data.getImpurity())
                // data.setImpurity(checkResult.getImpurity());
            }
            data = updateCheckItems(data, true);
        }
        // 更新数据
        inoutService.updateData(data);
        return null;
        return inoutService.updateData(data);
    }
@@ -591,8 +556,13 @@
        return msg;
    }
    public void initLpr(InoutConf conf) {
        inoutDeviceManager.initLpr(conf);
    /**
     * 出入库登记初始化
     *
     * @param conf 车牌识别配置信息
     */
    public void initInoutRegister(InoutConf conf) {
        inoutEventControl.initInoutRegister(conf);
    }
    /**
@@ -602,8 +572,7 @@
     * @return
     * @throws Exception
     */
    public PageResponse<InoutData> submitRegisterInout(InoutData data)
            throws Exception {
    public PageResponse<InoutData> submitRegisterInout(InoutData data) throws Exception {
        // 首先判断流程中是否有已经存在的车辆信息未执行完成,直接从数据库中查询
        InoutParam param = new InoutParam();
@@ -637,20 +606,20 @@
        String msg = inoutService.insertData(data);
        if (null != msg) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg,
                    data);
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg, data);
        }
        // 执行附件信息
        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(),
                data.getId(), curProgress);
        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(), data.getId(), curProgress);
        //登记完成事件
        inoutEventControl.onInoutRegister(data);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功",
                data);
    }
    public PageResponse<InoutData> submitWeightIn(InoutData data)
            throws Exception {
    public PageResponse<InoutData> submitWeightIn(InoutData data) throws Exception {
        // 获取系统参数配置
        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(
                data.getCompanyId(), data.getDeptId());
@@ -666,13 +635,7 @@
        data = updateBasicInfo(data, curProgress, nextProgress);
        // 入库称重可能调整质检单
        CheckUpdateResult checkUpdateResult = updateCheckItems(data);
        if (data.getDeCheck() == 0) {
            data.setDeCheck(checkUpdateResult.getDeSum());
        }
        if (data.getAddCheck() == 0) {
            data.setAddCheck(checkUpdateResult.getAddSum());
        }
        data = updateCheckItems(data, true);
        // 执行数据更新
        String msg = inoutService.updateData(data);
@@ -683,14 +646,12 @@
        }
        // 执行附件信息
        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(),
                data.getId(), curProgress);
        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(), data.getId(), curProgress);
        // 称重完成,调用出入库控制逻辑处理
        inoutDeviceManager.controlWeight(data, curProgress, nextProgress);
        // 称重完成事件
        inoutEventControl.onInoutWeight(data, curProgress, nextProgress);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功",
                data);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功", data);
    }
    public PageResponse<InoutData> submitWeightOut(InoutData data)
@@ -721,11 +682,11 @@
        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(),
                data.getId(), curProgress);
        // 称重后根据当前流程状态和下一个状态,通知称重控制器
        inoutDeviceManager.controlWeight(data, curProgress, nextProgress);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功",
                data);
        // 称重完成事件
        inoutEventControl.onInoutWeight(data, curProgress, nextProgress);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功", data);
    }
    public PageResponse<InoutData> submitHandle(InoutData data)
@@ -736,8 +697,7 @@
        }
        // 获取系统参数配置
        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(
                data.getCompanyId(), data.getDeptId());
        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
        if (null == inoutSysConf) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "提示:当前系统中流程配置异常,请联系管理员", data);
@@ -745,24 +705,23 @@
        // 获取下一个流程状态
        String curProgress = data.getProgress();
        String nextProgress = getNextProgress(curProgress, data.getType(),
                inoutSysConf);
        String nextProgress = getNextProgress(curProgress, data.getType(), inoutSysConf);
        data = updateBasicInfo(data, curProgress, nextProgress);
        // 执行数据更新
        String msg = inoutService.updateDataByHandle(data);
        if (null != msg) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg,
                    data);
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg, data);
        }
        // 执行附件信息
        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(),
                data.getId(), curProgress);
        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(), data.getId(), curProgress);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功",
                data);
        // 值仓完成触发事件
        inoutEventControl.onInoutHandle(data, curProgress, nextProgress);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功", data);
    }
    /**
@@ -831,6 +790,9 @@
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
        }
        // 扦样完成触发事件
        inoutEventControl.onInSimple(data);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功");
    }
@@ -859,7 +821,6 @@
                    "当前流程已经结束,不支持修改");
        }
        // 更新化验项信息
        CheckUpdateResult checkResult = checkStandardManager.updateCheckItems(data.getCheckId(), data.getCompanyId(), data.getCheckItems());
        if (StringUtils.isNotEmpty(checkResult.getMsg())) {
@@ -881,6 +842,7 @@
            data.setCheckTime(new Date());
        }
        curData.setCheckStatus(data.getCheckStatus());
        curData.setFoodYear(data.getFoodYear());
        // 获取下一个流程状态
@@ -895,6 +857,13 @@
        curData.setProgress(curData.getProgress());
        curData.setType(curData.getType());
        curData.setFoodLevel(data.getFoodLevel());
        curData.setFoodVariety(data.getFoodVariety());
        curData.setPrice(data.getPrice());
        curData.setRemarks(data.getRemarks());
        curData.setCheckItems(data.getCheckItems());
        curData.setCheckTime(data.getCheckTime());
        curData.setDepotId(data.getDepotId());
        if (StringUtils.isEmpty(data.getCheckUser())) {
            curData.setCheckUser(ContextUtil.getLoginUserCName());
@@ -909,7 +878,52 @@
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
        }
        // 质检完成触发事件
        inoutEventControl.onInCheck(data, curProgress, nextProgress);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功");
    }
    public PageResponse<InoutCheckData> submitCheckData(InoutCheckData data) throws Exception {
        // 获取业务数据信息
        InoutParam param = new InoutParam();
        param.setCompanyId(data.getCompanyId());
        param.setId(data.getId());
        InoutData curData = inoutService.inoutProgressQuery(param);
        if (null == curData) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "没有获取到入库业务数据信息,更新失败", data);
        }
        if (InoutConstant.PROGRESS_RECORD.equals(curData.getProgress())) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "当前流程已经结束,不支持修改");
        }
        // 更新化验项信息
        CheckUpdateResult checkResult = checkStandardManager.updateCheckItems(data.getCheckId(), data.getCompanyId(), data.getCheckItems());
        if (StringUtils.isNotEmpty(checkResult.getMsg())) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "后台执行异常:" + checkResult.getMsg(), data);
        }
        curData.setType(curData.getType());
        curData.setFoodLevel(data.getFoodLevel());
        curData.setFoodVariety(data.getFoodVariety());
        curData.setPrice(data.getPrice());
        curData.setDepotId(data.getDepotId());
        curData.setCheckItems(data.getCheckItems());
        String msg = inoutService.updateCheckData(curData);
        if (null != msg) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
        }
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "保存成功");
    }
    /**
@@ -950,7 +964,7 @@
        try {
            List<CheckItemData> result = checkStandardManager.listCheckItem(
                    param.getCheckId(), param.getCompanyId(),
                    param.getCompanyId(), param.getCheckId(),
                    param.getFoodVariety());
            return new PageResponse<>(RespCodeEnum.CODE_0000, result);
@@ -983,4 +997,35 @@
        }
    }
    /**
     * @param param
     * @return
     */
    public PageResponse<InoutCheckData> inoutDataByCheckId(InoutCheckParam param) {
        if (StringUtils.isEmpty(param.getCheckId())) {
            return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(),
                    "查询参数不完整,查询失败!");
        }
        InoutCheckData result;
        try {
            param.setProgress(InoutConstant.PROGRESS_CHECK);
            result = inoutService.inoutDataByCheckId(param);
            if (null == result) {
                return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
                        "系统未查询到执行中的车辆信息", null);
            }
            return new PageResponse<>(RespCodeEnum.CODE_0000, result);
        } catch (Exception e) {
            return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
                    e.getMessage());
        }
    }
    public void initInoutWeight(List<InoutConf> listInoutConf, String sort) {
        inoutEventControl.initInoutWeight(listInoutConf, sort);
    }
}