czt
2023-06-12 d9e1a4fe6e51958c4571efe2ced4d4172ed385db
igds-inout/src/main/java/com/ld/igds/inout/manager/InoutManager.java
@@ -16,6 +16,7 @@
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;
@@ -23,7 +24,6 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@@ -48,8 +48,8 @@
    private CoreFileService fileService;
    @Autowired
    private CoreCommonService commonService;
    @Autowired
    private InoutCommonService inoutManagerService;
    @Resource
    private InoutCommonService inoutCommonService;
    @Autowired
    private CheckStandardManager checkStandardManager;
    @Resource
@@ -143,14 +143,14 @@
        List<FileData> files = data.getFiles();
        // 更新下一个状态和基本信息
        InoutSysConf inoutSysConf = inoutManagerService.getCacheInoutSysConf(
        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(
                data.getCompanyId(), data.getDeptId());
        if (null == inoutSysConf
                || StringUtils.isEmpty(inoutSysConf.getProgressIn())) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "当前库区未配置出库流程信息,请联系管理员配置。", data);
        }
        data = updateOutBasicInfo(data, inoutSysConf);
        data = updateBasicInfo(data, inoutSysConf);
        // 如果当前节点是注册,则需要验证下,是否有为完成的流程在执行中
        if (InoutConstant.PROGRESS_REGISTER.equals(curProgress)) {
@@ -211,7 +211,7 @@
        }
        // 更新下一个状态和基本信息
        InoutSysConf inoutSysConf = inoutManagerService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
        if (null == inoutSysConf
                || StringUtils.isEmpty(inoutSysConf.getProgressIn())) {
@@ -219,7 +219,7 @@
                    "当前库区未配置入库流程信息,请联系管理员配置。", data);
        }
        data = updateInBasicInfo(data, inoutSysConf);
        data = updateBasicInfo(data, inoutSysConf);
        // 如果当前节点是注册,则需要验证下,是否有为完成的流程在执行中
        if (InoutConstant.PROGRESS_REGISTER.equals(curProgress)) {
@@ -284,96 +284,84 @@
        return inoutService.inoutProgressQuery(param);
    }
    @Transactional(rollbackFor = Exception.class)
    public PageResponse<InoutData> updateCheck(InoutData data) throws Exception {
        if (InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "当前流程已经结束,不支持修改", data);
        }
        CheckUpdateResult checkResult = this.updateCheckItems(data);
        String tag = checkResult.getMsg();
        if (null != tag) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "后台执行异常:" + tag, data);
        }
        // 获取业务数据信息
        InoutParam param = new InoutParam();
        param.setCompanyId(data.getCompanyId());
        param.setId(data.getId());
        InoutData progressData = inoutService.inoutProgressQuery(param);
        if (null == progressData) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "没有获取到出入库业务数据信息,更新失败", data);
        }
        if (InoutConstant.PROGRESS_RECORD.equals(progressData.getProgress())) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "当前流程已经结束,不支持修改");
        }
        progressData.setCheckStatus(data.getCheckStatus());
        // 更新下一个状态和基本信息
        if (InoutConstant.PROGRESS_CHECK.equals(progressData.getProgress())) {
            progressData = updateInBasicInfo(progressData, null);
            // 若化验结果不合格,判断配置后续流程
            if (InoutConstant.STATUS_UNPASS.equals(progressData
                    .getCheckStatus())) {
                progressData = checkNoPass(progressData);
            }
        }
        progressData.setCheckUser(ContextUtil.getLoginUserCName());
//      if (StringUtils.isNotEmpty(data.getCustomerName())) {
//         progressData.setCustomerId(data.getCustomerId());
//         progressData.setCustomerName(data.getCustomerName());
//      }
        if (StringUtils.isNotEmpty(data.getDepotId())) {
            progressData.setDepotId(data.getDepotId());
        }
        if (StringUtils.isNotEmpty(data.getFoodVariety())) {
            progressData.setFoodVariety(data.getFoodVariety());
        }
        if (StringUtils.isNotEmpty(data.getFoodLevel())) {
            progressData.setFoodLevel(data.getFoodLevel());
        }
        if (StringUtils.isNotEmpty(data.getFoodLocation())) {
            progressData.setFoodLocation(data.getFoodLocation());
        }
        if (StringUtils.isNotEmpty(data.getFoodYear())) {
            progressData.setFoodYear(data.getFoodYear());
        }
        if (null != data.getPrice()) {
            progressData.setPrice(data.getPrice());
        }
        if (StringUtils.isNotEmpty(data.getRemarks())) {
            progressData.setRemarks(data.getRemarks());
        }
        if (StringUtils.isNotEmpty(data.getNoticeId())) {
            progressData.setNoticeId(data.getNoticeId());
        }
//      // 回填水分和杂质
//      if (checkResult.getWet() > 0) {
//         progressData.setWet(checkResult.getWet());
//      }
//    @Transactional(rollbackFor = Exception.class)
//    public PageResponse<InoutData> updateCheck(InoutData data) throws Exception {
//
//      if (checkResult.getImpurity() > 0) {
//         progressData.setImpurity(checkResult.getImpurity());
//      }
        String msg = inoutService.updateData(progressData);
        if (null != msg) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
        }
        if (InoutConstant.PROGRESS_RECORD.equals(progressData.getProgress())) {
            inoutComplete(progressData);
        }
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功");
    }
//        if (InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) {
//            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
//                    "当前流程已经结束,不支持修改", data);
//        }
//
//        CheckUpdateResult checkResult = this.updateCheckItems(data);
//        String tag = checkResult.getMsg();
//
//        if (null != tag) {
//            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
//                    "后台执行异常:" + tag, data);
//        }
//
//        // 获取业务数据信息
//        InoutParam param = new InoutParam();
//        param.setCompanyId(data.getCompanyId());
//        param.setId(data.getId());
//        InoutData progressData = inoutService.inoutProgressQuery(param);
//        if (null == progressData) {
//            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
//                    "没有获取到出入库业务数据信息,更新失败", data);
//        }
//        if (InoutConstant.PROGRESS_RECORD.equals(progressData.getProgress())) {
//            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
//                    "当前流程已经结束,不支持修改");
//        }
//        progressData.setCheckStatus(data.getCheckStatus());
//
//        // 更新下一个状态和基本信息
//        if (InoutConstant.PROGRESS_CHECK.equals(progressData.getProgress())) {
//            progressData = updateBasicInfo(progressData, null);
//            // 若化验结果不合格,判断配置后续流程
//            if (InoutConstant.STATUS_UNPASS.equals(progressData
//                    .getCheckStatus())) {
//                progressData = checkNoPass(progressData);
//            }
//        }
//        progressData.setCheckUser(ContextUtil.getLoginUserCName());
//
//        if (StringUtils.isNotEmpty(data.getDepotId())) {
//            progressData.setDepotId(data.getDepotId());
//        }
//        if (StringUtils.isNotEmpty(data.getFoodVariety())) {
//            progressData.setFoodVariety(data.getFoodVariety());
//        }
//        if (StringUtils.isNotEmpty(data.getFoodLevel())) {
//            progressData.setFoodLevel(data.getFoodLevel());
//        }
//        if (StringUtils.isNotEmpty(data.getFoodLocation())) {
//            progressData.setFoodLocation(data.getFoodLocation());
//        }
//        if (StringUtils.isNotEmpty(data.getFoodYear())) {
//            progressData.setFoodYear(data.getFoodYear());
//        }
//        if (null != data.getPrice()) {
//            progressData.setPrice(data.getPrice());
//        }
//        if (StringUtils.isNotEmpty(data.getRemarks())) {
//            progressData.setRemarks(data.getRemarks());
//        }
//        if (StringUtils.isNotEmpty(data.getNoticeId())) {
//            progressData.setNoticeId(data.getNoticeId());
//        }
//
//        String msg = inoutService.updateData(progressData);
//
//        if (null != msg) {
//            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
//        }
//        if (InoutConstant.PROGRESS_RECORD.equals(progressData.getProgress())) {
//
//            inoutComplete(progressData);
//        }
//        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功");
//    }
    /**
     * 化验结果不通过时校验配置信息
@@ -382,7 +370,7 @@
     * @return
     */
    private InoutData checkNoPass(InoutData data) {
        InoutSysConf inoutSysConf = inoutManagerService.getCacheInoutSysConf(
        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(
                data.getCompanyId(), data.getDeptId());
        if (inoutSysConf.getNoPassNext().equals(InoutConstant.CHECK_NOPASS_RECORD)) {
@@ -397,14 +385,20 @@
        return data;
    }
    /**
     * 更新质检信息
     *
     * @param data
     * @return
     */
    private CheckUpdateResult updateCheckItems(InoutData data) {
        CheckUpdateResult result = new CheckUpdateResult();
        if (null == data.getCheckItems())
            return result;
        if (null == data.getCheckItems()) return result;
        try {
            // 更新检验项数据
            result = checkStandardManager.updateCheckItems(data.getCheckId(),
                    data.getCompanyId(), data.getCheckItems());
            result = checkStandardManager.updateCheckItems(data.getCheckId(), data.getCompanyId(), data.getCheckItems());
            // 将化验数据存入缓存中
            inoutService.setCheckCache(data);
@@ -444,17 +438,63 @@
    }
    /**
     * 根据数据当前状态和下一个状态,更新基础信息
     *
     * @param data
     * @return
     */
    private InoutData updateBasicInfo(InoutData data, String curProgress, String nextProgress) {
        if (InoutConstant.PROGRESS_REGISTER.equals(curProgress)) {
            data.setRegisterTime(new Date());
            data.setRegisterUser(ContextUtil.getLoginUserCName());
            data.setProgress(nextProgress);
        }
        if (InoutConstant.PROGRESS_CHECK.equals(data.getProgress())) {
            data.setCheckUser(ContextUtil.getLoginUserCName());
            data.setProgress(nextProgress);
            return data;
        }
        if (InoutConstant.PROGRESS_WEIGHT_EMPTY.equals(curProgress)) {
            data.setEmptyWeightTime(new Date());
            data.setEmptyWeightUser(ContextUtil.getLoginUserCName());
            data.setProgress(nextProgress);
        }
        if (InoutConstant.PROGRESS_WEIGHT_FULL.equals(curProgress)) {
            data.setFullWeightTime(new Date());
            data.setFullWeightUser(ContextUtil.getLoginUserCName());
            data.setProgress(nextProgress);
        }
        if (InoutConstant.PROGRESS_HANDLE.equals(curProgress)) {
            if (null == data.getHandleUser()) {
                data.setHandleUser(ContextUtil.getLoginUserCName());
            }
            data.setProgress(nextProgress);
        }
        //如果下一个数据状态=流程结束,直接补充完整信息
        if (InoutConstant.PROGRESS_RECORD.equals(nextProgress)) {
            data.setCompleteTime(DateUtils.addMinutes(new Date(), 2));
            data.setCompleteUser(ContextUtil.getLoginUserCName());
            data.setProgress(nextProgress);
        }
        return data;
    }
    /**
     * 当前方法需要删除
     * <p>
     * 根据需要保存的数据,调整下一个流程状态 不同的仓库组织流程可能不一样,需要根据实际调整
     *
     * @param data
     * @return
     */
    private InoutData updateInBasicInfo(InoutData data, InoutSysConf sysConf) {
        if (null == sysConf) {
            sysConf = inoutManagerService.getCacheInoutSysConf(
                    data.getCompanyId(), data.getDeptId());
        }
    private InoutData updateBasicInfo(InoutData data, InoutSysConf sysConf) {
        if (InoutConstant.PROGRESS_REGISTER.equals(data.getProgress())) {
            data.setRegisterTime(new Date());
            data.setRegisterUser(ContextUtil.getLoginUserCName());
@@ -464,13 +504,6 @@
            return data;
        }
        if (InoutConstant.PROGRESS_WEIGHT_FULL.equals(data.getProgress())) {
            data.setFullWeightTime(new Date());
            data.setFullWeightUser(ContextUtil.getLoginUserCName());
            data.setProgress(getNextProgress(data.getProgress(),
                    data.getType(), sysConf));
            return data;
        }
        if (InoutConstant.PROGRESS_CHECK.equals(data.getProgress())) {
            data.setCheckUser(ContextUtil.getLoginUserCName());
            data.setProgress(getNextProgress(data.getProgress(),
@@ -481,56 +514,6 @@
        if (InoutConstant.PROGRESS_WEIGHT_EMPTY.equals(data.getProgress())) {
            data.setEmptyWeightTime(new Date());
            data.setEmptyWeightUser(ContextUtil.getLoginUserCName());
            data.setProgress(getNextProgress(data.getProgress(),
                    data.getType(), sysConf));
            if (InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) {
                data.setCompleteTime(DateUtils.addMinutes(new Date(), 2));
                data.setCompleteUser(ContextUtil.getLoginUserCName());
            }
            return data;
        }
        if (InoutConstant.PROGRESS_HANDLE.equals(data.getProgress())) {
            // 查询缓存中仓库信息,根据仓库id设置值仓人为仓库保管员
            Depot depot = commonService.getCacheDepot(data.getCompanyId(),
                    data.getDepotId());
            data.setHandleUser(depot == null ? "" : depot.getStoreKeeperName());
            data.setProgress(getNextProgress(data.getProgress(),
                    data.getType(), sysConf));
            return data;
        }
        if (InoutConstant.PROGRESS_CARD_BACK.equals(data.getProgress())) {
            data.setCompleteTime(new Date());
            data.setCompleteUser(ContextUtil.getLoginUserCName());
            data.setProgress(getNextProgress(data.getProgress(),
                    data.getType(), sysConf));
            return data;
        }
        return data;
    }
    /**
     * 根据需要保存的数据,调整下一个流程状态 不同的仓库组织流程可能不一样,需要根据实际调整
     *
     * @param data
     * @return
     */
    private InoutData updateOutBasicInfo(InoutData data, InoutSysConf sysConf) {
        if (InoutConstant.PROGRESS_REGISTER.equals(data.getProgress())) {
            data.setRegisterTime(new Date());
            data.setRegisterUser(ContextUtil.getLoginUserCName());
            data.setProgress(getNextProgress(data.getProgress(),
                    data.getType(), sysConf));
            return data;
        }
        if (InoutConstant.PROGRESS_WEIGHT_EMPTY.equals(data.getProgress())) {
            data.setEmptyWeightTime(new Date());
            data.setEmptyWeightUser(ContextUtil.getLoginUserCName());
            data.setProgress(getNextProgress(data.getProgress(),
                    data.getType(), sysConf));
@@ -570,36 +553,6 @@
        }
        return data;
    }
    public PageResponse<Page<InoutData>> pageRecordData(InoutParam param) {
        log.debug("分页信息--page={},limit={},cuur={}", param.getPage(),
                param.getLimit(), param.getCurr());
        Page<InoutData> result = inoutService.pageRecordData(param);
        if (null == result.getRecords() || result.getRecords().isEmpty()) {
            return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
                    "获取到数据信息为空");
        }
        return new PageResponse<>(RespCodeEnum.CODE_0000, result);
    }
    /**
     * @param param
     * @return
     */
    public PageResponse<Page<InoutData>> pageCheckData(InoutParam param) {
        // 如果是已化验,则将流程状态置空,如果是未化验,则流程状态不处理,仍是CHECK状态
        if (!"NONE".equals(param.getCheckStatus())) {
            param.setProgress(null);
        }
        // 设置分库Id
        String deptId = ContextUtil.subDeptId(null);
        param.setDeptId(deptId);
        return pageRecordData(param);
    }
@@ -642,20 +595,20 @@
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), null, data);
    }
    /**
     * 扦样化验页面获取检验项条目信息
     *
     * @param data
     * @return
     */
    public PageResponse<List<CheckItemData>> getCheckItem(InoutData data) {
        List<CheckItemData> result = checkStandardManager.listCheckItem(
                data.getCheckId(), data.getCompanyId(), data.getDeptId(),
                data.getFoodVariety());
        return new PageResponse<>(RespCodeEnum.CODE_0000, result);
    }
//    /**
//     * 扦样化验页面获取检验项条目信息
//     *
//     * @param data
//     * @return
//     */
//    public PageResponse<List<CheckItemData>> getCheckItem(InoutData data) {
//
//        List<CheckItemData> result = checkStandardManager.listCheckItem(
//                data.getCheckId(), data.getCompanyId(), data.getDeptId(),
//                data.getFoodVariety());
//
//        return new PageResponse<>(RespCodeEnum.CODE_0000, result);
//    }
    /**
     * 删除并完成
@@ -768,9 +721,6 @@
            if (null == data.getFullWeightTime()) {
                data.setFullWeightTime(DateUtil.getNewByMinute(new Date(), -50));
            }
            if (null == data.getHandleEnd()) {
                data.setHandleEnd(DateUtil.getNewByMinute(new Date(), -40));
            }
            if (null == data.getEmptyWeightTime()) {
                data.setEmptyWeightTime(DateUtil.getNewByMinute(new Date(), -10));
            }
@@ -784,9 +734,6 @@
        } else {
            if (null == data.getEmptyWeightTime()) {
                data.setEmptyWeightTime(DateUtil.getNewByMinute(new Date(), -50));
            }
            if (null == data.getHandleEnd()) {
                data.setHandleEnd(DateUtil.getNewByMinute(new Date(), -40));
            }
            if (null == data.getFullWeightTime()) {
                data.setFullWeightTime(DateUtil.getNewByMinute(new Date(), -10));
@@ -858,7 +805,6 @@
        // 更新数据
        inoutService.updateData(data);
        // this.autoCheckByUpdate(data, record);
        return null;
    }
@@ -972,9 +918,6 @@
        if (StringUtils.isEmpty(data.getDepotId())) {
            return "请填写仓库信息!";
        }
//      if (StringUtils.isEmpty(data.getCustomerId())) {
//         return "请填写往来单位信息!";
//      }
        if (StringUtils.isEmpty(data.getFoodYear())) {
            return "请填写粮食年份信息!";
        }
@@ -997,28 +940,6 @@
    public void initLpr(InoutConf conf) {
        inoutDeviceManager.initLpr(conf);
    }
    /**
     * 获取出入库设备配置信息
     *
     * @param companyId
     * @param deptId
     * @return
     */
    public List<InoutConf> getListInoutConf(String companyId, String deptId) {
        return inoutManagerService.getCacheInoutConf(companyId, deptId);
    }
    /**
     * 操作道闸设备
     *
     * @param param
     * @return
     */
    public PageResponse<List<CheckItemData>> gateCtrl(InoutGateDto param) {
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "", null);
    }
    /**
@@ -1046,19 +967,19 @@
        //获取系统参数配置
        InoutSysConf inoutSysConf = inoutManagerService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
        if (null == inoutSysConf) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "提示:当前库区未配置出入库流程信息,请联系管理员", data);
        }
        String curProgress = data.getProgress();
        //获取下一个流程状态
        String curProgress = data.getProgress();
        String nextProgress = getNextProgress(curProgress, data.getType(), inoutSysConf);
        data.setRegisterTime(new Date());
        data.setRegisterUser(ContextUtil.getLoginUserCName());
        data.setProgress(nextProgress);
        data = updateBasicInfo(data, curProgress, nextProgress);
        String msg = inoutService.insertData(data);
@@ -1070,6 +991,104 @@
        // 执行附件信息
        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(), data.getId(), curProgress);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功", data);
    }
    public PageResponse<InoutData> submitWeightIn(InoutData data) throws Exception {
        //获取系统参数配置
        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
        if (null == inoutSysConf) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "提示:当前系统中流程配置异常,请联系管理员", data);
        }
        //获取下一个流程状态
        String curProgress = data.getProgress();
        String nextProgress = getNextProgress(curProgress, data.getType(), inoutSysConf);
        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());
        }
        //执行数据更新
        String msg = inoutService.updateData(data);
        if (null != msg) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg, data);
        }
        // 执行附件信息
        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(), data.getId(), curProgress);
        //称重完成,调用出入库控制逻辑处理
        inoutDeviceManager.controlWeight(data, curProgress, nextProgress);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功", data);
    }
    public PageResponse<InoutData> submitWeightOut(InoutData data) throws Exception {
        //获取系统参数配置
        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
        if (null == inoutSysConf) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "提示:当前系统中流程配置异常,请联系管理员", data);
        }
        //获取下一个流程状态
        String curProgress = data.getProgress();
        String nextProgress = getNextProgress(curProgress, data.getType(), inoutSysConf);
        data = updateBasicInfo(data, curProgress, nextProgress);
        //执行数据更新
        String msg = inoutService.updateData(data);
        if (null != msg) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg, data);
        }
        // 执行附件信息
        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(), data.getId(), curProgress);
        //称重后根据当前流程状态和下一个状态,通知称重控制器
        inoutDeviceManager.controlWeight(data, curProgress, nextProgress);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功", data);
    }
    public PageResponse<InoutData> submitHandle(InoutData data) throws Exception {
        //获取系统参数配置
        InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
        if (null == inoutSysConf) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "提示:当前系统中流程配置异常,请联系管理员", data);
        }
        //获取下一个流程状态
        String curProgress = data.getProgress();
        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);
        }
        // 执行附件信息
        fileService.saveInoutFiles(data.getFiles(), data.getCompanyId(), data.getId(), curProgress);
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功", data);
    }
@@ -1091,7 +1110,7 @@
        }
        //若查询条件为已扦样,则流程置空;若未扦样,则流程不处理,仍为扦样化验流程(CHECK)
        if ("SAMPLE".equals(param.getSampleStatus())) {
        if (!"NONE".equals(param.getSampleStatus())) {
            param.setProgress(null);
        }
@@ -1107,34 +1126,182 @@
    }
    @Transactional(rollbackFor = Exception.class)
    public PageResponse<InoutCheckData> updateSampleData(InoutCheckData data) throws Exception {
    public PageResponse<InoutCheckData> updateSampleData(InoutCheckData data) {
        // 获取业务数据信息
        InoutParam param = new InoutParam();
        param.setCompanyId(data.getCompanyId());
        param.setId(data.getId());
        InoutData curData = inoutService.inoutProgressQuery(param);
        if (null == curData) {
        try {
            // 获取业务数据信息
            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(),
                        "当前流程已经结束,不支持修改");
            }
            //扦样时间和扦样人
            if (StringUtils.isEmpty(data.getSampleUser())) {
                data.setSampleUser(ContextUtil.getLoginUserCName());
            }
            if (null == data.getSampleTime()) {
                data.setSampleTime(new Date());
            }
            String msg = inoutService.updateSampleData(data);
            if (null != msg) {
                return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
            }
            return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功");
        } catch (Exception e) {
            log.error("后台异常:{}", e);
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "没有获取到入库业务数据信息,更新失败", data);
                    "后台异常:" + e.getMessage(), null);
        }
        if (InoutConstant.PROGRESS_RECORD.equals(curData.getProgress())) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "当前流程已经结束,不支持修改");
        }
        //扦样信息
        curData.setSampleTime(data.getSampleTime());
        curData.setSampleType(data.getSampleType());
        curData.setSampleUser(data.getSampleUser());
        String msg = inoutService.updateSampleData(curData);
        if (null != msg) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
        }
        return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功");
    }
    /**
     * @param param
     * @return
     */
    public PageResponse<Page<InoutCheckData>> pageCheckData(InoutCheckParam param) {
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        if (StringUtils.isEmpty(param.getDeptId())) {
            param.setDeptId(ContextUtil.subDeptId(null));
        }
        // 如果是已化验,则将流程状态置空,如果是未化验,则流程状态不处理,仍是CHECK状态
        if (!"NONE".equals(param.getCheckStatus())) {
            param.setProgress(null);
        }
        Page<InoutCheckData> checkList = inoutService.pageCheckData(param);
        if (null == checkList.getRecords() || checkList.getRecords().isEmpty()) {
            return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
                    "获取到数据信息为空");
        }
        return new PageResponse<>(RespCodeEnum.CODE_0000, checkList);
    }
    /**
     * 获取化验项信息
     *
     * @param param
     * @return
     */
    public PageResponse<List<CheckItemData>> getCheckItemData(InoutCheckParam param) {
        try {
            List<CheckItemData> result = checkStandardManager.listCheckItem(param.getCheckId(),
                    param.getCompanyId(), param.getFoodVariety());
            return new PageResponse<>(RespCodeEnum.CODE_0000, result);
        } catch (Exception e) {
            return new PageResponse<>(
                    RespCodeEnum.CODE_1111.getCode(), "后台异常:" + e.getMessage(), null);
        }
    }
    @Transactional(rollbackFor = Exception.class)
    public PageResponse<InoutCheckData> updateCheckData(InoutCheckData data) {
        try {
            // 获取业务数据信息
            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);
            }
            //设置化验信息
            if (checkResult.getDeSum() > 0) {
                data.setDeCheck(checkResult.getDeSum());
            }
            if (checkResult.getAddSum() > 0) {
                data.setAddCheck(checkResult.getAddSum());
            }
            if (null == data.getCheckTime()) {
                data.setCheckTime(new Date());
            }
            curData.setCheckStatus(data.getCheckStatus());
            //获取系统参数配置
            InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId());
            if (null == inoutSysConf) {
                return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                        "提示:当前库区未配置出入库流程信息,请联系管理员", data);
            }
            //更新下一流程状态
            if (InoutConstant.PROGRESS_CHECK.equals(curData.getProgress())) {
                curData = updateBasicInfo(curData, inoutSysConf);
                // 若化验结果不合格,判断配置后续流程
                if (InoutConstant.STATUS_UNPASS.equals(curData.getCheckStatus())) {
                    curData = checkNoPass(curData);
                }
            }
            //化验人、化验时间
            data.setCheckStatus(curData.getCheckStatus());
            data.setProgress(curData.getProgress());
            if (StringUtils.isEmpty(data.getCheckUser())) {
                data.setCheckUser(ContextUtil.getLoginUserCName());
            }
            if (null == data.getCheckTime()) {
                data.setCheckTime(new Date());
            }
            String msg = inoutService.updateCheckData(data);
            if (null != msg) {
                return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg);
            }
            return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功");
        } catch (Exception e) {
            return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
                    "后台异常:" + e.getMessage(), null);
        }
    }
    /**
     * 获取单价信息
     *
     * @param param
     * @return
     */
    public PageResponse<InoutPrice> getPrice(InoutCheckParam param) {
        try {
            List<InoutPrice> price = inoutService.getPrice(param);
            if(null == price || price.isEmpty()){
                return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "未获取到粮食定价配置信息");
            }
            return new PageResponse<>(RespCodeEnum.CODE_0000, price.get(0));
        } catch (Exception e) {
            return new PageResponse<>(
                    RespCodeEnum.CODE_1111.getCode(), "后台异常:" + e.getMessage(), null);
        }
    }
}