| | |
| | | package com.ld.igds.inout.manager; |
| | | |
| | | import com.bstek.bdf2.core.business.IUser; |
| | | import com.ld.igds.check.CheckStandardManager; |
| | | import com.ld.igds.check.dto.CheckItemData; |
| | | import com.ld.igds.check.dto.CheckUpdateResult; |
| | |
| | | import com.ld.igds.data.Page; |
| | | import com.ld.igds.data.PageResponse; |
| | | import com.ld.igds.file.CoreFileService; |
| | | import com.ld.igds.file.dto.FileData; |
| | | import com.ld.igds.inout.InoutConstant; |
| | | import com.ld.igds.inout.dto.*; |
| | | import com.ld.igds.inout.dto.InoutCheckData; |
| | | import com.ld.igds.inout.dto.InoutCheckParam; |
| | | 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.Depot; |
| | |
| | | import com.ld.igds.models.InoutSysConf; |
| | | import com.ld.igds.util.ContextUtil; |
| | | import com.ld.igds.util.DateUtil; |
| | | import com.ld.igds.util.NumberUtil; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.commons.lang3.time.DateUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | @Component |
| | | public class InoutManager { |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private InoutService inoutService; |
| | | @Autowired |
| | | @Resource |
| | | private CoreFileService fileService; |
| | | @Autowired |
| | | @Resource |
| | | private CoreCommonService commonService; |
| | | @Resource |
| | | private InoutCommonService inoutCommonService; |
| | | @Autowired |
| | | @Resource |
| | | private CheckStandardManager checkStandardManager; |
| | | @Resource |
| | | private InoutDeviceManager inoutDeviceManager; |
| | | |
| | | |
| | | /** |
| | | * 直接从数据库查询,不考虑信息状态 |
| | | * |
| | | * @param param |
| | | * @return |
| | | */ |
| | | public PageResponse<InoutData> inoutQueryBack(InoutParam param) { |
| | | if (StringUtils.isEmpty(param.getPlateNum()) |
| | | && StringUtils.isEmpty(param.getIntelCard()) |
| | | && StringUtils.isEmpty(param.getUserId())) { |
| | | |
| | | return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(), |
| | | "查询参数不完整,查询失败!"); |
| | | } |
| | | |
| | | //获取三天以内最后一天记录 |
| | | param.setStart(DateUtil.getNewByDay(new Date(), -3)); |
| | | param.setType(null); |
| | | param.setProgress(null); |
| | | |
| | | InoutData result = inoutService.getLastRecord(param); |
| | | |
| | | if (null == result) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_1007.getCode(), |
| | | "根据当前条件未查询到车辆信息!"); |
| | | } |
| | | |
| | | if (InoutConstant.PROGRESS_RECORD.equals(result.getProgress())) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "当前车辆流程已经结束", result); |
| | | } |
| | | |
| | | if (!InoutConstant.PROGRESS_CARD_BACK.equals(result.getProgress())) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_1008.getCode(), "当前车辆流程不在当前环节,无法执行出库", result); |
| | | } |
| | | |
| | | return new PageResponse<>(RespCodeEnum.CODE_0000, result); |
| | | } |
| | | |
| | | /** |
| | | * 首先从缓存中获取,缓存中,从数据库中获取 |
| | |
| | | } |
| | | } |
| | | |
| | | public PageResponse<InoutData> outNextStep(InoutData data) throws Exception { |
| | | String msg; |
| | | IUser user = ContextUtil.getLoginUser(); |
| | | if (StringUtils.isEmpty(data.getCompanyId())) { |
| | | data.setCompanyId(user.getCompanyId()); |
| | | } |
| | | if (StringUtils.isEmpty(data.getDeptId())) { |
| | | data.setDeptId(ContextUtil.subDeptId(user)); |
| | | } |
| | | if (StringUtils.isEmpty(data.getIntelCard())) { |
| | | data.setIntelCard(data.getUserId()); |
| | | } |
| | | |
| | | String curProgress = data.getProgress(); |
| | | List<FileData> files = data.getFiles(); |
| | | |
| | | // 更新下一个状态和基本信息 |
| | | InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf( |
| | | data.getCompanyId(), data.getDeptId()); |
| | | if (null == inoutSysConf |
| | | || StringUtils.isEmpty(inoutSysConf.getProgressIn())) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), |
| | | "当前库区未配置出库流程信息,请联系管理员配置。", data); |
| | | } |
| | | data = updateBasicInfo(data, inoutSysConf); |
| | | |
| | | // 如果当前节点是注册,则需要验证下,是否有为完成的流程在执行中 |
| | | if (InoutConstant.PROGRESS_REGISTER.equals(curProgress)) { |
| | | InoutData progressData = this.inoutProgressQuery(data); |
| | | if (null != progressData) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), |
| | | "当前卡片/车牌号有流程未结束。", progressData); |
| | | } |
| | | } |
| | | |
| | | if (null != data.getPrice() && null != data.getRecordWeight()) { |
| | | data.setSettleMoney(NumberUtil.keepPrecision(data.getPrice() * data.getRecordWeight(), 2)); |
| | | } |
| | | |
| | | // 流程完成,直接调用流程完成接口 |
| | | if (InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) { |
| | | inoutService.updateData(data); |
| | | // 执行附件信息 |
| | | if (null != files) { |
| | | fileService.saveInoutFiles(files, data.getCompanyId(), |
| | | data.getId(), curProgress); |
| | | } |
| | | |
| | | // 通知称重主控流程结束 |
| | | inoutDeviceManager.noticeProgressComplete(data); |
| | | |
| | | return inoutComplete(data); |
| | | } |
| | | |
| | | // 调用保存方法执行 |
| | | if (StringUtils.isEmpty(data.getId())) { |
| | | msg = inoutService.insertData(data); |
| | | } else { |
| | | msg = inoutService.updateData(data); |
| | | } |
| | | |
| | | // 执行附件信息 |
| | | if (null != files) { |
| | | fileService.saveInoutFiles(files, data.getCompanyId(), |
| | | data.getId(), curProgress); |
| | | } |
| | | |
| | | if (null != msg) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg, |
| | | data); |
| | | } |
| | | return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功", |
| | | data); |
| | | } |
| | | |
| | | public PageResponse<InoutData> inNextStep(InoutData data) throws Exception { |
| | | String msg; |
| | | |
| | | String curProgress = data.getProgress(); |
| | | List<FileData> files = data.getFiles(); |
| | | if (StringUtils.isEmpty(data.getIntelCard())) { |
| | | data.setIntelCard(data.getUserId()); |
| | | } |
| | | |
| | | // 更新下一个状态和基本信息 |
| | | InoutSysConf inoutSysConf = inoutCommonService.getCacheInoutSysConf(data.getCompanyId(), data.getDeptId()); |
| | | |
| | | if (null == inoutSysConf |
| | | || StringUtils.isEmpty(inoutSysConf.getProgressIn())) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), |
| | | "当前库区未配置入库流程信息,请联系管理员配置。", data); |
| | | } |
| | | |
| | | data = updateBasicInfo(data, inoutSysConf); |
| | | |
| | | // 如果当前节点是注册,则需要验证下,是否有为完成的流程在执行中 |
| | | if (InoutConstant.PROGRESS_REGISTER.equals(curProgress)) { |
| | | InoutData progressData = this.inoutProgressQuery(data); |
| | | if (null != progressData) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), |
| | | "当前卡片/车牌号有流程未结束。", progressData); |
| | | } |
| | | } |
| | | |
| | | if (null != data.getPrice() && null != data.getRecordWeight()) { |
| | | data.setSettleMoney(NumberUtil.keepPrecision(data.getPrice() * data.getRecordWeight(), 2)); |
| | | } |
| | | |
| | | // 流程完成,直接调用流程完成接口 |
| | | if (InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) { |
| | | if (StringUtils.isEmpty(data.getCompanyId())) { |
| | | data.setCompanyId(ContextUtil.getCompanyId()); |
| | | } |
| | | |
| | | inoutService.updateData(data); |
| | | // 执行附件信息 |
| | | if (null != files) { |
| | | fileService.saveInoutFiles(files, data.getCompanyId(), |
| | | data.getId(), curProgress); |
| | | } |
| | | |
| | | // 通知称重主控流程结束 |
| | | inoutDeviceManager.noticeProgressComplete(data); |
| | | |
| | | return inoutComplete(data); |
| | | } |
| | | |
| | | // 调用保存方法执行 |
| | | if (StringUtils.isEmpty(data.getId())) { |
| | | msg = inoutService.insertData(data); |
| | | } else { |
| | | msg = inoutService.updateData(data); |
| | | } |
| | | |
| | | // 执行附件信息 |
| | | if (null != files) { |
| | | fileService.saveInoutFiles(files, data.getCompanyId(), |
| | | data.getId(), curProgress); |
| | | } |
| | | |
| | | if (null != msg) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg); |
| | | } |
| | | |
| | | return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行成功", |
| | | data); |
| | | } |
| | | |
| | | public InoutData inoutProgressQuery(InoutData data) throws Exception { |
| | | InoutParam param = new InoutParam(); |
| | |
| | | |
| | | 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 = 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(), "执行成功"); |
| | | // } |
| | | |
| | | /** |
| | | * 化验结果不通过时校验配置信息 |
| | |
| | | } |
| | | |
| | | |
| | | public PageResponse<InoutData> inoutComplete(InoutData data) throws Exception { |
| | | public PageResponse<InoutData> submitComplete(InoutData data) throws Exception { |
| | | |
| | | if (StringUtils.isEmpty(data.getId()) |
| | | || StringUtils.isEmpty(data.getType())) { |
| | | || 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(ContextUtil.getLoginUserCName()); |
| | | param.setUserId(data.getCompleteUser()); |
| | | param.setDepotId(data.getDepotId()); |
| | | param.setCompleteTime(data.getCompleteTime()); |
| | | if (null == param.getCompleteTime()) { |
| | | param.setCompleteTime(new Date()); |
| | | } |
| | | // 设置流程节点直接完成 |
| | | param.setProgress(InoutConstant.PROGRESS_RECORD); |
| | | |
| | | if (null == data.getCompleteTime()) { |
| | | data.setCompleteTime(DateUtil.getNewByMinute(new Date(), 2)); |
| | | } |
| | | |
| | | String msg = inoutService.toComplete(param); |
| | | |
| | | if (null != msg) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), msg); |
| | | } |
| | | |
| | | // 库存调整 |
| | | commonService.initInoutDepotStore(data); |
| | | |
| | | 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<InoutData> deleteInoutData(InoutData data, String msg) { |
| | | try { |
| | | data.setRemarks(msg); |
| | | String result = this.delInoutData(data, false); |
| | | if (null != result) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), |
| | | result, data); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("后台异常:{}", e); |
| | | return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), "后台异常:" |
| | | + e.getMessage(), data); |
| | | } |
| | | return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "执行完成", |
| | | data); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param data |
| | | * @return |
| | | */ |
| | | public PageResponse<InoutData> inoutBack(InoutData data) { |
| | | public PageResponse<InoutData> submitCardBack(InoutData data) { |
| | | try { |
| | | // 从缓存中获取最新的数据,如果没有则表示流程已经结束。 |
| | | InoutParam param = new InoutParam(); |
| | | param.setCompanyId(data.getCompanyId()); |
| | | param.setId(data.getId()); |
| | | InoutData curData = inoutService.inoutProgressQuery(param); |
| | | if (InoutConstant.PROGRESS_RECORD.equals(curData.getProgress())) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), |
| | | "当前卡流程已经完成,无需执行卡回收", data); |
| | | //如果当前数据已经结束 |
| | | if (InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) { |
| | | |
| | | //删除缓存 |
| | | inoutService.delFromCache(data.getDeptId(), data.getType(), data.getId()); |
| | | |
| | | return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), |
| | | "当车辆流程已经完成,卡片已回收", data); |
| | | } |
| | | if (InoutConstant.RECORD_STATUS_DEL.equals(curData |
| | | .getRecordStatus())) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), |
| | | "当前卡信息已被删除,不能执行卡回收", data); |
| | | |
| | | |
| | | //如果当前流程不是卡回收 |
| | | if (!InoutConstant.PROGRESS_CARD_BACK.equals(data.getProgress())) { |
| | | |
| | | return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), |
| | | "当前流程环节不正确,不能执行卡回收", data); |
| | | } |
| | | |
| | | // 如果当前流程状态是卡回收状态,就是完成流程。 |
| | | if (InoutConstant.PROGRESS_CARD_BACK.equals(curData.getProgress())) { |
| | | return inoutComplete(curData); |
| | | if (InoutConstant.PROGRESS_CARD_BACK.equals(data.getProgress())) { |
| | | return submitComplete(data); |
| | | } |
| | | |
| | | // 如果是其他状态,则执行删除逻辑 |
| | | return deleteInoutData(curData, "卡回收删除"); |
| | | |
| | | } catch (Exception e) { |
| | | return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(), |
| | | "后端执行异常:" + e.getMessage()); |
| | | } |
| | | |
| | | return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), |
| | | "执行成功", data); |
| | | } |
| | | |
| | | /* ============================== 详单页面相关操作 ================================= */ |
| | | |
| | | /** |
| | | * 补单操作 补单因为完成时间不确定,所以需要系统根据当前数据进行自动检测,调整原来流水信息和库存 |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Transactional |
| | | public String addInoutData(InoutData data) throws Exception { |
| | | |
| | | if (data.getSettleWeight() <= 0.0) { |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @javax.transaction.Transactional(rollbackOn = Exception.class) |
| | | @Transactional |
| | | public String updateInoutData(InoutData data) throws Exception { |
| | | |
| | | if (InoutConstant.RECORD_STATUS_DEL.equals(data.getRecordStatus())) { |
| | |
| | | RespCodeEnum.CODE_1111.getCode(), "后台异常:" + e.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |