自动化立体仓库 - WCS系统
#
Junjie
2023-12-12 a01af25e1b22558174014839581de144d683ad10
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -409,10 +409,6 @@
            for (DevpSlave devp : slaveProperties.getDevp()) {
                // 遍历拣料入库口
                for (DevpSlave.Sta pickSta : devp.getPickInSta()) {
                    if (pickSta.getStaNo() == 325 || pickSta.getStaNo() == 331 || pickSta.getStaNo() == 333 || pickSta.getStaNo() == 339) {
                        continue;
                    }
                    // 获取拣料入库站信息
                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
@@ -450,27 +446,27 @@
                            continue;
                        }
                        //*********************同库位组校验*********************
                        boolean flag = false;
                        String th = "";
                        List<String> innerLoc = Utils.getGroupInnerLoc(wrkMast.getSourceLocNo());
                        for (String loc : innerLoc) {
                            LocMast locMast = locMastService.selectById(loc);
                            if (locMast == null) {
                                continue;
                            }
                            if (!locMast.getLocSts().equals("F")) {
                                flag = true;
                                th = loc + "库位存在未回库任务";
                                break;
                            }
                        }
                        if (flag) {
                            News.info(th);
                            continue;
                        }
                        //*********************同库位组校验*********************
//                        //*********************同库位组校验*********************
//                        boolean flag = false;
//                        String th = "";
//                        List<String> innerLoc = Utils.getGroupInnerLoc(wrkMast.getSourceLocNo());
//                        for (String loc : innerLoc) {
//                            LocMast locMast = locMastService.selectById(loc);
//                            if (locMast == null) {
//                                continue;
//                            }
//
//                            if (!locMast.getLocSts().equals("F")) {
//                                flag = true;
//                                th = loc + "库位存在未回库任务";
//                                break;
//                            }
//                        }
//                        if (flag) {
//                            News.info(th);
//                            continue;
//                        }
//                        //*********************同库位组校验*********************
                        // 保存工作主档历史档
                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
@@ -478,35 +474,51 @@
                            continue;
                        }
                        String sourceLocNo = wrkMast.getSourceLocNo().trim();
                        LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(sourceLocNo));//获取回库提升机目标站
                        if (liftStaProtocol == null) {
                            continue;
                        }
                        try {
                            LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());//源库位
                            SearchLocParam param = new SearchLocParam();
                            param.setWrkNo(wrkMast.getWrkNo());
                            param.setBarcode(wrkMast.getBarcode());
                            param.setIoType(wrkMast.getIoType());
                            param.setSourceStaNo(pickSta.getStaNo());
                            param.setLocType1(locMast.getLocType1());
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
                                    .setPath("/rpc/pakin/loc/v2")
                                    .setJson(JSON.toJSONString(param))
                                    .build()
                                    .doPost();
                            JSONObject jsonObject = JSON.parseObject(response);
                            Integer code = jsonObject.getInteger("code");
                            if (code.equals(200)) {
                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                        // 更新工作档数据状态
                        wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54,107->57
                        wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
                        wrkMast.setSourceStaNo(pickSta.getBackSta()); // 源站
//                            wrkMast.setStaNo(dto.getStaNo()); // 目标站
//                            wrkMast.setCrnNo(dto.getCrnNo());
                        wrkMast.setStaNo(liftStaProtocol.getStaNo());//目标站
                        wrkMast.setLocNo(sourceLocNo); // 目标库位 = 出库时的源库位
                        wrkMast.setShuttleNo(null); // 穿梭车清空
                        wrkMast.setLiftNo(null);// 提升机清空
                        wrkMast.setModiTime(new Date());
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            News.info(wrkMast.getWrkNo() + "更新工作档数据状态失败");
                            continue;
                        }
                                //获取回库提升机目标站
                                LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(dto.getLocNo()));
                                if (liftStaProtocol == null) {
                                    News.info(wrkMast.getWrkNo() + "获取回库提升机目标站失败");
                                    continue;
                                }
                        // 修改库位状态 Q.拣料/盘点/并板再入库
                        LocMast locMast = locMastService.selectById(sourceLocNo);
                        locMast.setLocSts("Q");
                        locMast.setModiTime(new Date());
                        if (!locMastService.updateById(locMast)) {
                            News.info("修改库位状态失败");
                            continue;
                                // 更新工作档数据状态
                                wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54
                                wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
                                wrkMast.setSourceStaNo(dto.getSourceStaNo()); // 源站
                                wrkMast.setStaNo(liftStaProtocol.getStaNo());//目标站
                                wrkMast.setLocNo(dto.getLocNo()); // 目标库位
                                wrkMast.setShuttleNo(null); // 穿梭车清空
                                wrkMast.setLiftNo(null);// 提升机清空
                                wrkMast.setModiTime(new Date());
                                if (wrkMastMapper.updateById(wrkMast) == 0) {
                                    News.info(wrkMast.getWrkNo() + "更新工作档数据状态失败");
                                    continue;
                                }
                            } else if (code == 500) {
                                News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        }
                    }
                }
@@ -554,27 +566,27 @@
                            continue;
                        }
                        //*********************同库位组校验*********************
                        boolean flag = false;
                        String th = "";
                        List<String> innerLoc = Utils.getGroupInnerLoc(wrkMast.getSourceLocNo());
                        for (String loc : innerLoc) {
                            LocMast locMast = locMastService.selectById(loc);
                            if (locMast == null) {
                                continue;
                            }
                            if (!locMast.getLocSts().equals("F")) {
                                flag = true;
                                th = loc + "库位存在未回库任务";
                                break;
                            }
                        }
                        if (flag) {
                            News.info(th);
                            continue;
                        }
                        //*********************同库位组校验*********************
//                        //*********************同库位组校验*********************
//                        boolean flag = false;
//                        String th = "";
//                        List<String> innerLoc = Utils.getGroupInnerLoc(wrkMast.getSourceLocNo());
//                        for (String loc : innerLoc) {
//                            LocMast locMast = locMastService.selectById(loc);
//                            if (locMast == null) {
//                                continue;
//                            }
//
//                            if (!locMast.getLocSts().equals("F")) {
//                                flag = true;
//                                th = loc + "库位存在未回库任务";
//                                break;
//                            }
//                        }
//                        if (flag) {
//                            News.info(th);
//                            continue;
//                        }
//                        //*********************同库位组校验*********************
                        // 保存工作主档历史档
                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
@@ -582,39 +594,55 @@
                            continue;
                        }
                        String sourceLocNo = wrkMast.getSourceLocNo().trim();
                        LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(sourceLocNo));//获取回库提升机目标站
                        if (liftStaProtocol == null) {
                            continue;
                        }
                        try {
                            LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());//源库位
                            SearchLocParam param = new SearchLocParam();
                            param.setWrkNo(wrkMast.getWrkNo());
                            param.setBarcode(wrkMast.getBarcode());
                            param.setIoType(wrkMast.getIoType());
                            param.setSourceStaNo(pickSta.getStaNo());
                            param.setLocType1(locMast.getLocType1());
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
                                    .setPath("/rpc/pakin/loc/v2")
                                    .setJson(JSON.toJSONString(param))
                                    .build()
                                    .doPost();
                            JSONObject jsonObject = JSON.parseObject(response);
                            Integer code = jsonObject.getInteger("code");
                            if (code.equals(200)) {
                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                        // 更新工作档数据状态
                        wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54,107->57
                        wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
                        wrkMast.setSourceStaNo(pickSta.getBackSta()); // 源站
//                            wrkMast.setStaNo(dto.getStaNo()); // 目标站
//                            wrkMast.setCrnNo(dto.getCrnNo());
                        wrkMast.setStaNo(liftStaProtocol.getStaNo());//目标站
                        wrkMast.setLocNo(sourceLocNo); // 目标库位 = 出库时的源库位
                        wrkMast.setShuttleNo(null); // 穿梭车清空
                        wrkMast.setLiftNo(null);// 提升机清空
                        wrkMast.setModiTime(new Date());
                        if (wrkMastMapper.updateById(wrkMast) == 0) {
                            News.info(wrkMast.getWrkNo() + "更新工作档数据状态失败");
                            continue;
                        }
                                //获取回库提升机目标站
                                LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(dto.getLocNo()));
                                if (liftStaProtocol == null) {
                                    News.info(wrkMast.getWrkNo() + "获取回库提升机目标站失败");
                                    continue;
                                }
                        // 修改库位状态 Q.拣料/盘点/并板再入库
                        LocMast locMast = locMastService.selectById(sourceLocNo);
                        locMast.setLocSts("Q");
                        locMast.setModiTime(new Date());
                        if (!locMastService.updateById(locMast)) {
                            News.info("修改库位状态失败");
                            continue;
                        }
                                // 更新工作档数据状态
                                wrkMast.setIoType(wrkMast.getIoType() - 50); // 入出库类型: 103->53,104->54
                                wrkMast.setWrkSts(2L); // 工作状态: 2.设备上走
                                wrkMast.setSourceStaNo(dto.getSourceStaNo()); // 源站
                                wrkMast.setStaNo(liftStaProtocol.getStaNo());//目标站
                                wrkMast.setLocNo(dto.getLocNo()); // 目标库位
                                wrkMast.setShuttleNo(null); // 穿梭车清空
                                wrkMast.setLiftNo(null);// 提升机清空
                                wrkMast.setModiTime(new Date());
                                if (wrkMastMapper.updateById(wrkMast) == 0) {
                                    News.info(wrkMast.getWrkNo() + "更新工作档数据状态失败");
                                    continue;
                                }
                        staProtocol.setStaNo(pickSta.getBackSta().shortValue());//写入目标站
                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                                staProtocol.setStaNo(dto.getSourceStaNo().shortValue());//写入目标站
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            } else if (code == 500) {
                                News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        }
                    }
                }
@@ -633,10 +661,6 @@
            for (DevpSlave devp : slaveProperties.getDevp()) {
                // 遍历拣料入库口
                for (DevpSlave.Sta pickSta : devp.getPickInSta()) {
//                if (pickSta.getStaNo() == 325 || pickSta.getStaNo() == 331 || pickSta.getStaNo() == 333 || pickSta.getStaNo() == 339) {
//                    continue;
//                }
                    // 获取拣料入库站信息
                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
@@ -648,10 +672,22 @@
                    if (staProtocol.isAutoing()
                            && staProtocol.isLoading()
                            && staProtocol.isInEnable()
                            && (staProtocol.getWorkNo() > 0)
//                            && (staProtocol.getWorkNo() > 0)
                            && staProtocol.isPakMk()) {
                        WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue());
                        // 获取条码扫描仪信息
                        BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
                        if (barcodeThread == null) {
                            continue;
                        }
                        String barcode = barcodeThread.getBarcode();
                        if (Cools.isEmpty(barcode)) {
                            continue;
                        }
                        if ("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
                            continue;
                        }
                        WrkMast wrkMast = wrkMastMapper.selectByBarcode(barcode);
                        if (wrkMast == null) {//找不到工作档
                            continue;
                        }
@@ -660,28 +696,6 @@
                                || Cools.isEmpty(wrkMast.getStaNo()) || Cools.isEmpty(wrkMast.getSourceStaNo())) {
                            continue;
                        }
                        //*********************同库位组校验*********************
                        boolean flag = false;
                        String th = "";
                        List<String> innerLoc = Utils.getGroupInnerLoc(wrkMast.getSourceLocNo());
                        for (String loc : innerLoc) {
                            LocMast locMast = locMastService.selectById(loc);
                            if (locMast == null) {
                                continue;
                            }
                            if (!locMast.getLocSts().equals("F")) {
                                flag = true;
                                th = loc + "库位存在未回库任务";
                                break;
                            }
                        }
                        if (flag) {
                            News.info(th);
                            continue;
                        }
                        //*********************同库位组校验*********************
                        // 保存工作主档历史档
                        if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
@@ -696,11 +710,11 @@
                            param.setWrkNo(wrkMast.getWrkNo());
                            param.setBarcode(wrkMast.getBarcode());
                            param.setIoType(107);//盘点
                            param.setSourceStaNo(wrkMast.getStaNo());
                            param.setSourceStaNo(pickSta.getStaNo());
                            param.setLocType1(locMast.getLocType1());
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
                                    .setPath("/rpc/pakin/loc/v1")
                                    .setPath("/rpc/pakin/loc/v2")
                                    .setJson(JSON.toJSONString(param))
                                    .build()
                                    .doPost();
@@ -1301,6 +1315,15 @@
            if (!(liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && !liftStaProtocol.getHasTray())) {
                News.info("{}任务,{}内部输送站,不满足自动、空闲、无托盘状态", wrkMast.getWrkNo(), liftStaProtocol.getStaNo());
                return false;//站点必须自动、空闲、没有托盘
            }
            if (wrkMast.getStaNo() == 300) {
                //出300站,检测300站任务数量
                List<WrkMast> wrkMasts = wrkMastMapper.select300Wrk();
                if (wrkMasts.size() >= 20) {
                    News.info("{}任务,输送线任务过载{}", wrkMast.getWrkNo(), wrkMasts.size());
                    return false;
                }
            }
            if (wrkMast.getShuttleNo() == null) {//没有绑定小车,进行调度
@@ -2915,6 +2938,7 @@
                    ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
                    ledCommand.setLocNo(wrkMast.getLocNo());
                    ledCommand.setStaNo(wrkMast.getStaNo());
                    ledCommand.setBarcode(wrkMast.getBarcode());
                    if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) {
                        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", wrkMast.getSourceLocNo()));
                        locDetls.forEach(locDetl -> {
@@ -2923,8 +2947,7 @@
                            Utils.wapperSetCondition(wrapper, "three_code", locDetl.getThreeCode());
                            Utils.wapperSetCondition(wrapper, "dead_time", locDetl.getDeadTime());
                            Utils.wapperSetCondition(wrapper, "supp_code", locDetl.getSuppCode());//料箱码
                            WrkDetl detl = wrkDetlService.selectOne(wrapper);
                            List<WrkDetl> detl = wrkDetlService.selectList(wrapper);
                            if (Cools.isEmpty(detl)) {
                                String suppCode = "";
                                if (locDetl.getSuppCode() != null) {
@@ -2932,21 +2955,21 @@
                                }
                                ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode));
                            } else {
                                String suppCode = "";
                                String orderNo = detl.getOrderNo();
                                if (detl.getSuppCode() != null) {
                                    suppCode = detl.getSuppCode();
                                //出库数量累计
                                Double conut = 0.0;
                                for (WrkDetl wrkDetl : detl) {
                                    conut = conut + wrkDetl.getAnfme();
                                }
                                try {
                                    JSONArray orders = JSON.parseArray(orderNo);
                                    for (Object order : orders) {
                                        JSONObject order1 = (JSONObject) order;
                                        ledCommand.getMatDtos().add(new MatDto(detl.getMatnr(), detl.getMaktx(), (Double) order1.get("anfme"), (locDetl.getAnfme() - detl.getAnfme()), detl.getSpecs(), suppCode,(String) order1.get("orderNo")));
                                for (WrkDetl wrkDetl : detl) {
                                    String suppCode = "";
                                    if (wrkDetl.getSuppCode() != null) {
                                        suppCode = wrkDetl.getSuppCode();
                                    }
                                } catch (Exception e) {
                                    ledCommand.getMatDtos().add(new MatDto(detl.getMatnr(), detl.getMaktx(), detl.getAnfme(), (locDetl.getAnfme() - detl.getAnfme()), detl.getSpecs(), suppCode,detl.getOrderNo()));
                                    ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (locDetl.getAnfme() - conut), wrkDetl.getSpecs(), suppCode, wrkDetl.getOrderNo()));
                                }
                            }
                        });
                        if (locDetls.isEmpty()) {
@@ -3954,63 +3977,36 @@
        return true;
    }
    /**
     * 出入库模式切换
     */
    public synchronized void outAndIn() {
        try {
            // 根据输送线plc遍历
            for (DevpSlave devp : slaveProperties.getDevp()) {
                for (DevpSlave.Sta inSta : devp.getInSta()) {
                    Thread.sleep(500);
                    boolean a=true,b=true;
                    List<WrkMast> wrkMasts = wrkMastMapper.selectAll(inSta.getStaNo());
                    if (Cools.isEmpty(wrkMasts)){
                        b=false;
                    }else {
                        for (WrkMast wrkMast:wrkMasts){
                            if (wrkMast.getSourceStaNo() > wrkMast.getStaNo()){
                                a=false;
                                break;
                            }
                        }
                    }
                    switch (inSta.getStaNo()) {
                        case 102://1F
                            if (a && b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 11));
                            }else if (b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 12));
                            }else {
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 10));
                            }
                            break;
                        case 202://2F
                            if (a && b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 21));
                            }else if (b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 22));
                            }else {
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 20));
                            }
                            break;
                        case 302://3F
                            if (a && b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 31));
                            }else if (b){
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 32));
                            }else {
                                MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, 30));
                            }
                            break;
                    }
                }
    //扫描设备PakMk标记是否超时
    public synchronized void scanDevicePakMk() {
        //扫描小车
        for (ShuttleSlave slave : slaveProperties.getShuttle()) {
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace();
            if ((System.currentTimeMillis() - shuttleProtocol.getSendTime() > (1000*60*5)) && shuttleProtocol.getPakMk()) {
                //设备超过5分钟还没复位标记
                shuttleProtocol.setPakMk(false);//复位标记
            }
        }
    }
        //扫描提升机
        for (LiftSlave slave : slaveProperties.getLift()) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, slave.getId());
            LiftProtocol liftProtocol = liftThread.getLiftProtocol();
            if (liftProtocol == null) {
                continue;
            }
            if ((System.currentTimeMillis() - liftProtocol.getSendTime() > (1000*60*5)) && liftProtocol.getPakMk()) {
                //设备超过5分钟还没复位标记
                liftProtocol.setPakMk(false);//复位标记
            }
        }
    }
}