zjj
2024-03-28 9e19804493a3c4fdd894779b2b4664fe2f9ca9fe
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -182,7 +182,7 @@
                String maxKeySql = "select min(FInterID) as num from CPICMO";
                List<ERPselectParam> maxKeyList = erpSqlServer.select(maxKeySql, ERPselectParam.class);
                Integer maxKey = maxKeyList.get(0).getNum();
                String ErpSql = "insert into CPICMO(FBrNo, FSourceBillNo, FBillNo, FTranType, FStatus, FMRP, FItemID, FQty, FCommitQty, FSourceEntryID, FClosed, FUnitID, FAuxCommitQty, FCancellation, FQtyFinish, FQtyScrap, FQtyLost, FAuxQtyFinish, FAuxQtyScrap, FAuxQtyLost, FMrpClosed, FBomInterID, FQtyPass, FAuxQtyPass, FQtyBack, FAuxQtyBack, FFinishTime, FReadyTIme, FPowerCutTime, FFixTime, FWaitItemTime, FWaitToolTime, FTaskID, FWorkTypeID, FCostObjID, FStockQty, FAuxStockQty, FSuspend, FReleasedQty, FReleasedAuxQty, FUnScheduledQty, FUnScheduledAuxQty, FSubEntryID, FScheduleID, FPlanOrderInterID, FProcessPrice, FProcessFee, FGMPBatchNo, FGMPCollectRate, FGMPItemBalance, FGMPBulkQty, FCustID, FMRPLockFlag, FHandworkClose, FInHighLimit, FInHighLimitQty, FInLowLimit, FInLowLimitQty, FChangeTimes, FCheckCommitQty, FAuxCheckCommitQty, FPlanConfirmed, FPlanMode, FMTONo, FPrintCount, FFinClosed, FStockFlag, FStartFlag, FVchBillNo, FVchInterID, FCardClosed, FHRReadyTime, FSourceTranType, FSourceInterId, FInterID, FAuxQty, FAuxInHighLimitQty, FAuxInLowLimitQty, Fnumber, FWorkShop) values (0, ''{6}'', '0', 85, 0, 1052, 0, 0, 0, 0, 0, 250, {5,number,#}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14036, '0', 0, 0, 14215, 0, '0', 0, 1059, 0, 0, 0, 0, {0,number,#}, {1,number,#}, {2,number,#}, {3,number,#}, ''{4}'', 11378)";
                String ErpSql = "insert into CPICMO(FBrNo, FSourceBillNo, FBillNo, FTranType, FStatus, FMRP, FItemID, FQty, FCommitQty, FSourceEntryID, FClosed, FUnitID, FAuxCommitQty, FCancellation, FQtyFinish, FQtyScrap, FQtyLost, FAuxQtyFinish, FAuxQtyScrap, FAuxQtyLost, FMrpClosed, FBomInterID, FQtyPass, FAuxQtyPass, FQtyBack, FAuxQtyBack, FFinishTime, FReadyTIme, FPowerCutTime, FFixTime, FWaitItemTime, FWaitToolTime, FTaskID, FWorkTypeID, FCostObjID, FStockQty, FAuxStockQty, FSuspend, FReleasedQty, FReleasedAuxQty, FUnScheduledQty, FUnScheduledAuxQty, FSubEntryID, FScheduleID, FPlanOrderInterID, FProcessPrice, FProcessFee, FGMPBatchNo, FGMPCollectRate, FGMPItemBalance, FGMPBulkQty, FCustID, FMRPLockFlag, FHandworkClose, FInHighLimit, FInHighLimitQty, FInLowLimit, FInLowLimitQty, FChangeTimes, FCheckCommitQty, FAuxCheckCommitQty, FPlanConfirmed, FPlanMode, FMTONo, FPrintCount, FFinClosed, FStockFlag, FStartFlag, FVchBillNo, FVchInterID, FCardClosed, FHRReadyTime, FSourceTranType, FSourceInterId, FInterID, FAuxQty, FAuxInHighLimitQty, FAuxInLowLimitQty, Fnumber, FWorkShop, Fflag_rw) values (0, ''{6}'', '0', 85, 0, 1052, 0, 0, 0, 0, 0, 250, {5,number,#}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14036, '0', 0, 0, 14215, 0, '0', 0, 1059, 0, 0, 0, 0, {0,number,#}, {1,number,#}, {2,number,#}, {3,number,#}, ''{4}'', 11378, 1)";
                ErpSql = MessageFormat.format(ErpSql, maxKey - 1, es.getCount(), es.getCount(), es.getCount(), es.getMatNo(), es.getCount(), es.getStr5());
                erpSqlServer.update(ErpSql);
            }
@@ -214,6 +214,35 @@
        if (!locDetlDtos.isEmpty()) {
            // 启动出库开始 101.出库
            stockOut(staNo, locDetlDtos, null, userId, agvSite);
        } else {
            throw new CoolException("库位物料不存在");
        }
    }
    @Override
    @Transactional
    public void startupFullTakeStoreToP(StockOutParam param, Long userId) {
        // 目标站点状态检测
        BasDevp staNo = basDevpService.checkSiteStatus(param.getOutSite());
        int agvSite = 0;
        if (!Cools.isEmpty(staNo.getFronting()) && staNo.getFronting().equals("Y")) {
            agvSite = staNo.getDevNo();
            staNo = basDevpService.checkSiteStatus(201);
        }
        // 获取库位明细
        List<LocDetlDto> locDetlDtos = new ArrayList<>();
        for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) {
            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getCount())) {
                LocDetl sqlParam = new LocDetl();
                sqlParam.setLocNo(paramLocDetl.getLocNo());
                sqlParam.setMatnr(paramLocDetl.getMatnr());
                LocDetl one = locDetlService.selectOne(new EntityWrapper<>(sqlParam));
                if (null != one) locDetlDtos.add(new LocDetlDto(one, paramLocDetl.getCount()));
            }
        }
        if (!locDetlDtos.isEmpty()) {
            // 启动出库开始 101.出库
            stockOutToP(staNo, locDetlDtos, null, userId, agvSite,param.getWarehouse());
        } else {
            throw new CoolException("库位物料不存在");
        }
@@ -285,6 +314,123 @@
            }
            // 生成工作档明细
            for (LocDetlDto detlDto : dto.getLocDetlDtos()) {
                // 如果为捡料出库需要判断托盘码是否为空
                if (ioType == 103) {
                    String zpallet = detlDto.getLocDetl().getZpallet();
                    if (Cools.isEmpty(zpallet)) {
                        throw new CoolException("拣料出库必须含有托盘码");
                    }
                }
                // 出库时,数量为0的直接忽略
                if (detlDto.getCount() == null || detlDto.getCount() <= 0.0D) {
                    continue;
                }
                WrkDetl wrkDetl = new WrkDetl();
                wrkDetl.setWrkNo(workNo);
                wrkDetl.setIoTime(new Date());
                Double anfme = ioType == 101 ? detlDto.getLocDetl().getAnfme() : detlDto.getCount();
                wrkDetl.setAnfme(anfme); // 数量
                VersionUtils.setWrkDetl(wrkDetl, detlDto.getLocDetl()); // 版本控制
                wrkDetl.setAppeTime(new Date());
                wrkDetl.setAppeUser(userId);
                wrkDetl.setModiTime(new Date());
                wrkDetl.setModiUser(userId);
                if (!wrkDetlService.insert(wrkDetl)) {
                    throw new CoolException("保存工作档明细失败");
                }
            }
            // 修改库位状态:   F.在库 ====>>> R.出库预约/P.拣料/盘点/并板出库中
            locMast = locMastService.selectById(dto.getLocNo());
            if (locMast.getLocSts().equals("F")) {
                locMast.setLocSts(ioType == 101 ? "R" : "P");
                locMast.setModiUser(userId);
                locMast.setModiTime(new Date());
                if (!locMastService.updateById(locMast)) {
                    throw new CoolException("预约库位状态失败,库位号:" + dto.getLocNo());
                }
            } else {
                throw new CoolException(dto.getLocNo() + "库位不是在库状态");
            }
        }
        // todo:luxiaotao
        // 同一列的同时出库,则优先出浅库位
    }
    @Transactional
    public void stockOutToP(BasDevp staNo, List<LocDetlDto> locDetlDtos, Integer ioType, Long userId, Integer agvSite ,String warehouse) {
        // 合并同类项
        Set<String> locNos = new HashSet<>();
        locDetlDtos.forEach(dto -> locNos.add(dto.getLocDetl().getLocNo()));
        List<OutLocDto> dtos = new ArrayList<>();
        for (String locNo : locNos) {
            List<LocDetlDto> list = new ArrayList<>();
            Iterator<LocDetlDto> iterator = locDetlDtos.iterator();
            while (iterator.hasNext()) {
                LocDetlDto dto = iterator.next();
                if (locNo.equals(dto.getLocDetl().getLocNo())) {
                    list.add(dto);
                    iterator.remove();
                }
            }
            dtos.add(new OutLocDto(locNo, list));
        }
        // 生成工作档
        for (OutLocDto dto : dtos) {
            // 判断入出库类型:101.全板出库 or 103.拣料出库
            if (ioType == null) {
                ioType = dto.isAll() ? 101 : 103;
            }
            // 获取库位
            LocMast locMast = locMastService.selectById(dto.getLocNo());
            // 获取路径
            Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                    .eq("type_no", ioType)
                    .eq("stn_no", staNo.getDevNo())
                    .eq("crn_no", locMast.getCrnNo());
            StaDesc staDesc = staDescService.selectOne(wrapper);
            if (Cools.isEmpty(staDesc)) {
                throw new CoolException("出库路径不存在");
            }
            // 生成工作号
            int workNo = commonService.getWorkNo(DEFAULT_WORK_NO_TYPE);
            // 生成工作档
            WrkMast wrkMast = new WrkMast();
            wrkMast.setWrkNo(workNo);
            wrkMast.setIoTime(new Date());
            wrkMast.setWrkSts(11L); // 工作状态:11.生成出库ID
            wrkMast.setIoType(ioType); // 入出库状态
            wrkMast.setIoPri(13D); // 优先级:13
            wrkMast.setCrnNo(locMast.getCrnNo());
            wrkMast.setSourceStaNo(staDesc.getCrnStn()); // 源站
            wrkMast.setStaNo(staDesc.getStnNo()); // 目标站
            wrkMast.setSourceLocNo(dto.getLocNo()); // 源库位
            wrkMast.setBarcode(locMast.getBarcode()); // 条码
            wrkMast.setFullPlt("Y"); // 满板:Y
            wrkMast.setPicking("N"); // 拣料
            wrkMast.setExitMk("N"); // 退出
            wrkMast.setEmptyMk("N"); // 空板
            wrkMast.setLinkMis("N");
            wrkMast.setCtnKind(agvSite); // 出库下的小车工作区站好
            wrkMast.setExitMk("N"); // 小车是否搬运
            wrkMast.setAppeUser(userId); // 操作人员数据
            wrkMast.setAppeTime(new Date());
            wrkMast.setModiUser(userId);
            wrkMast.setModiTime(new Date());
            wrkMast.setPdcType("Y"); //用作移库标记
            wrkMast.setLogErrMemo(warehouse); //用作存储仓库标记
            if (!wrkMastService.insert(wrkMast)) {
                throw new CoolException("保存工作档失败,出库库位号:" + dto.getLocNo());
            }
            // 生成工作档明细
            for (LocDetlDto detlDto : dto.getLocDetlDtos()) {
                // 如果为捡料出库需要判断托盘码是否为空
                if (ioType == 103) {
                    String zpallet = detlDto.getLocDetl().getZpallet();
                    if (Cools.isEmpty(zpallet)) {
                        throw new CoolException("拣料出库必须含有托盘码");
                    }
                }
                // 出库时,数量为0的直接忽略
                if (detlDto.getCount() == null || detlDto.getCount() <= 0.0D) {
                    continue;
@@ -494,6 +640,9 @@
            if (Cools.isEmpty(locMast)) {
                throw new CoolException(locNo + "库位不存在");
            }
            if(!locMast.getLocSts().equals("D")){ //非在库状态
                continue;
            }
            // 获取源站
            Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                    .eq("type_no", 110)