#
lty
昨天 276d837c0bb808e6d93ac7c7ba6abe654c75552e
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -6,9 +6,11 @@
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.*;
import com.core.exception.CoolException;
import com.zy.asrs.controller.TaskWrkController;
import com.zy.asrs.domain.enums.LedErrorAreaType;
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.InboundTaskApplyParam;
import com.zy.asrs.mapper.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.*;
@@ -66,9 +68,9 @@
    @Autowired
    private WrkDetlService wrkDetlService;
    @Autowired
    private LocMastService locMastService;
    private BasDevpOptService basDevpOptService;
    @Autowired
    private StaDescService staDescService;
    private LocMastService locMastService;
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
@@ -76,15 +78,13 @@
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private BasErrLogService basErrLogService;
    @Autowired
    private BasCrnErrorMapper basCrnErrorMapper;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private BasDevpPositionService basDevpPositionService;
    @Autowired
    private TaskWrkService taskWrkService;
    @Autowired
    private OpenService openService;
    @Value("${wms.url}")
    private String wmsUrl;
@@ -140,16 +140,6 @@
                if (barcodeThread == null) {
                    continue;
                }
                String barcode = barcodeThread.getBarcode();
                if (!Cools.isEmpty(barcode)) {
//                    log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
                    if ("00000000".endsWith(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode) || !CodeDetectionUtil.barcodeDetection(barcode)) {
                        continue;
                    }
                } else {
                    continue;
                }
                // 获取入库站信息
//                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
@@ -159,6 +149,17 @@
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                String barcode = barcodeThread.getBarcode();
                if (!Cools.isEmpty(barcode)) {
//                    log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
                    if ("00000000".endsWith(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode) || !CodeDetectionUtil.barcodeDetection(barcode)) {
                        continue;
                    }
                } else {
                    continue;
                }
                // 尺寸检测异常
@@ -194,6 +195,15 @@
                }
                // 退回
                if (back) {
                    barcodeThread.setBarcode("");
                    // 获取工作号
                    int workNo = commonService.getWorkNo(3);
                    staProtocol.setWorkNo(workNo);
                    staProtocol.setStaNo(inSta.getBackSta().shortValue());
                    devpThread.setPakMk(staProtocol.getSiteId(), false,201);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    // led 异常显示
                    LedErrorThreadUtil.ledErrorThread(errMsg,inSta.getLed(), LedErrorAreaType.FOUR_BARCODE.getDesc());
                    continue;
@@ -232,7 +242,7 @@
//                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                        barcodeThread.setBarcode("");
                        staProtocol.setWorkNo(wrkMast.getWrkNo());
                        staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                        staProtocol.setStaNo(wrkMast.getStaNoSou$().shortValue());
                        devpThread.setPakMk(staProtocol.getSiteId(), false,238);
                        boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
@@ -251,46 +261,84 @@
                    try {
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
                        SearchLocParam param = new SearchLocParam();
                        param.setBarcode(barcode);
                        param.setIoType(1);
                        param.setSourceStaNo(inSta.getStaNo());
                        param.setLocType1(locTypeDto.getLocType1());
                        // 替换为新的任务申请接口
                        InboundTaskApplyParam applyParam = new InboundTaskApplyParam();
                        applyParam.setBarcode(barcode);
                        applyParam.setStationCode(String.valueOf(inSta.getStaNo()));
                        applyParam.setStatus(1); // 1:满板
                        String response = new HttpHandler.Builder()
                                .setUri(wmsUrl)
                                .setPath("/rpc/pakin/loc/v1")
                                .setJson(JSON.toJSONString(param))
                                .setPath("/inboundTaskApply")
                                .setJson(JSON.toJSONString(applyParam))
                                .build()
                                .doPost();
                        // 解析响应,只确认申请是否成功
                        JSONObject jsonObject = JSON.parseObject(response);
                        if (jsonObject.getInteger("code").equals(200)) {
                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
//                            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                            barcodeThread.setBarcode("");
                            staProtocol.setWorkNo(dto.getWorkNo());
//                            if(Cools.isEmpty(dto.getRgvNo()) || dto.getRgvNo() <= 0) {
//                                staProtocol.setStaNo(607);//607
//                            } else {//如果存在RGV编号,说明需要RGV接驳,先下发任务到RGV源站
                            staProtocol.setStaNo(dto.getRgvSstaNo().shortValue());
//                            }
                            devpThread.setPakMk(staProtocol.getSiteId(), false,283);
                        if (jsonObject != null && jsonObject.getInteger("code") != null && jsonObject.getInteger("code") == 200) {
                            log.info("入库任务申请成功,等待WMS下发任务。条码:{},站点:{}", barcode, inSta.getStaNo());
                            staProtocol.setWorkNo(9998);//设置为9998等待上位机下发任务/9997是空板入库判断,待下发时也写入9998
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            if (!result) {
                                LedErrorThreadUtil.ledErrorThread("更新plc站点信息失败!站点号:"+inSta.getStaNo(),inSta.getLed(), LedErrorAreaType.ONE_OTHER.getDesc());
                                throw new CoolException("更新plc站点信息失败");
                            }
                        } else {
                            //                            // 获取工作号
                            int workNo = commonService.getWorkNo(3);
                            staProtocol.setWorkNo(workNo);
                            staProtocol.setStaNo(inSta.getBackSta().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false,201);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            // led 异常显示
                            LedErrorThreadUtil.ledErrorThread("入库请求失败"+jsonObject.getInteger("code"),inSta.getLed(), LedErrorAreaType.ONE_OTHER.getDesc());
                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/inboundTaskApply", JSON.toJSONString(applyParam), response);
                        }
                        // 原有逻辑注释掉
//                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
//
//                        SearchLocParam param = new SearchLocParam();
//                        param.setBarcode(barcode);
//                        param.setIoType(1);
//                        param.setSourceStaNo(inSta.getStaNo());
//                        param.setLocType1(locTypeDto.getLocType1());
//                        String response = new HttpHandler.Builder()
//                                .setUri(wmsUrl)
//                                .setPath("/rpc/pakin/loc/v1")
//                                .setJson(JSON.toJSONString(param))
//                                .build()
//                                .doPost();
//                        JSONObject jsonObject = JSON.parseObject(response);
//                        if (jsonObject.getInteger("code").equals(200)) {
//                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
//
//                            barcodeThread.setBarcode("");
//                            staProtocol.setWorkNo(dto.getWorkNo());
//                            staProtocol.setStaNo(wrkMast.getStaNoSou$().shortValue());
//
//                            devpThread.setPakMk(staProtocol.getSiteId(), false,283);
//                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
//                            if (!result) {
//                                LedErrorThreadUtil.ledErrorThread("更新plc站点信息失败!站点号:"+inSta.getStaNo(),inSta.getLed(), LedErrorAreaType.ONE_OTHER.getDesc());
//                                throw new CoolException("更新plc站点信息失败");
//                            }
//                        } else {
//                            // 获取工作号
//                            int workNo = commonService.getWorkNo(3);
//
//                            staProtocol.setWorkNo(workNo);
//                            staProtocol.setStaNo(inSta.getBackSta().shortValue());
//
//                            devpThread.setPakMk(staProtocol.getSiteId(), false,201);
//                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
//                            // led 异常显示
//                            LedErrorThreadUtil.ledErrorThread("入库请求失败"+jsonObject.getInteger("code"),inSta.getLed(), LedErrorAreaType.ONE_OTHER.getDesc());
//                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
//                        }
                    } catch (Exception e) {
                        e.printStackTrace();
@@ -307,7 +355,7 @@
     */
    public synchronized void storeEmptyPlt() {
        for (DevpSlave devp : slaveProperties.getDevp()) {
            if (devp.getId()==1) continue;
//            if (devp.getId()==1) continue;
            // 遍历空板入库口
            for (DevpSlave.Sta emptyInSta : devp.getEmptyInSta()) {
                // 获取空板入库站信息
@@ -320,36 +368,35 @@
                }
                // 站点条件判断
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable()
                        && staProtocol.isEmptyMk() && ((staProtocol.getWorkNo() > 9000 && staProtocol.getWorkNo() <= 9999) || staProtocol.getWorkNo()==0)  && staProtocol.isPakMk()) {
                        && staProtocol.isEmptyMk() && ((staProtocol.getWorkNo() > 9000 && staProtocol.getWorkNo() <= 9997) || staProtocol.getWorkNo()==0)  && staProtocol.isPakMk()) {
                    try {
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
                        SearchLocParam param = new SearchLocParam();
                        param.setIoType(10);
                        param.setSourceStaNo(emptyInSta.getStaNo());
                        param.setLocType1(locTypeDto.getLocType1());
                        InboundTaskApplyParam applyParam = new InboundTaskApplyParam();
                        applyParam.setBarcode(null);
                        applyParam.setStationCode(String.valueOf(emptyInSta.getStaNo()));
                        applyParam.setStatus(0); // 1:满板
                        String response = new HttpHandler.Builder()
                                .setUri(wmsUrl)
                                .setPath("/rpc/pakin/loc/v1")
                                .setJson(JSON.toJSONString(param))
                                .setPath("/inboundTaskApply")
                                .setJson(JSON.toJSONString(applyParam))
                                .build()
                                .doPost();
                        JSONObject jsonObject = JSON.parseObject(response);
                        if (jsonObject.getInteger("code").equals(200)) {
                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                            // 更新站点信息 且 下发plc命令
                            staProtocol.setWorkNo(dto.getWorkNo());
                            staProtocol.setStaNo(dto.getStaNo().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false,4087);
                        // 解析响应,只确认申请是否成功
                        JSONObject jsonObject = JSON.parseObject(response);
                        if (jsonObject != null && jsonObject.getInteger("code") != null && jsonObject.getInteger("code") == 200) {
                            log.info("入库任务申请成功,等待WMS下发任务,站点:{}",emptyInSta.getStaNo());
                            staProtocol.setWorkNo(9998);//设置为9998等待上位机下发任务
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            if (!result) {
                                LedErrorThreadUtil.ledErrorThread("更新plc站点信息失败!站点号:"+emptyInSta.getStaNo(),emptyInSta.getLed(), LedErrorAreaType.ONE_OTHER.getDesc());
                                throw new CoolException("更新plc站点信息失败");
                            }
                        } else {
                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/inboundTaskApply", JSON.toJSONString(applyParam), response);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
@@ -528,6 +575,10 @@
                        if (wrkMastMapper.updateById(wrkMast) != 0) {
                            // 复位堆垛机
                            crnThread.setResetFlag(true);
                            if(wrkMast.getIoType() == 103 || wrkMast.getIoType() == 107) { //拣料出库任务状态上报,其他上报在wms任务完成定时任务中
                                openService.reportTaskStatus(String.valueOf(wrkMast.getWrkNo()),3,1,wrkMast.getBarcode());
                            }
                        } else {
                            log.error("更新工作档的工作状态为14失败!!! [工作号:{}]", wrkMast.getWrkNo());
                        }
@@ -733,7 +784,7 @@
            }
            // 双深库位且浅库位有货,则需先对浅库位进行库位移转
            if (Utils.isDeepLoc(slaveProperties, wrkMast.getLocNo())) {
            if (Utils.isDeepLoc(slaveProperties, wrkMast.getLocNo()) && crnProtocol.getCrnNo()!=3) {
                String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getLocNo());
                LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                // O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!
@@ -880,7 +931,7 @@
                }
                // 双深库位且浅库位有货,则需先对浅库位进行库位移转
                if (Utils.isDeepLoc(slaveProperties, wrkMast.getSourceLocNo())) {
                if (Utils.isDeepLoc(slaveProperties, wrkMast.getSourceLocNo()) && crnProtocol.getCrnNo()!=3) {
                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, wrkMast.getSourceLocNo());
                    LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                    // O.空库位、Q.拣料/盘点/并板再入库、S.入库预约、X.禁用 直接搬!
@@ -890,10 +941,10 @@
                            log.error("{}库位异常,未检索到相应工作档!", shallowLocNo);
                        } else {
                            if (waitWrkMast.getWrkSts() == 11) {
                                if (waitWrkMast.getIoPri() + 100000D < 999999999D) {
                                    waitWrkMast.setIoPri(waitWrkMast.getIoPri()+100000D);
                                if (waitWrkMast.getIoPri() + 10D < 9999D) {
                                    waitWrkMast.setIoPri(waitWrkMast.getIoPri()+10D);
                                } else {
                                    waitWrkMast.setIoPri(999999999D);
                                    waitWrkMast.setIoPri(9999D);
                                }
                                waitWrkMast.setModiTime(new Date());
                                if (wrkMastMapper.updateById(waitWrkMast) == 0) {
@@ -1149,6 +1200,192 @@
        }
    }
    /**
     * 出库  ===>> 工作档信息写入led显示器
     */
    public synchronized void ledExecute() {
        for (LedSlave led : slaveProperties.getLed()) {
            // 获取输送线plc线程
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
            // 命令集合
            List<LedCommand> commands = new ArrayList<>();
            // 工作档集合
            List<WrkMast> wrkMasts = new ArrayList<>();
            for (Integer staNo : led.getStaArr()) {
                // 获取叉车站点
                StaProtocol staProtocol = devpThread.getStation().get(staNo);
                if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                // 获取工作档数据
                WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
                if (null == wrkMast) {
                    if(staProtocol.getWorkNo() > 9999){ //异常退出
                        String err = basDevpOptService.getErr(staProtocol.getWorkNo());
                        MessageQueue.offer(SlaveType.Led, led.getId(), new Task(3, err));
                    }
                    continue;
                }
                wrkMasts.add(wrkMast);
                // 组装命令
                LedCommand ledCommand = new LedCommand();
                ledCommand.setWorkNo(wrkMast.getWrkNo());
                ledCommand.setIoType(wrkMast.getIoType());
                // 出库模式
                switch (wrkMast.getIoType()) {
                    case 1:
                        ledCommand.setTitle("全板入库");
                        break;
                    case 10:
                        ledCommand.setTitle("空板入库");
                        break;
                    case 12:
                        ledCommand.setTitle("物料衔接");
                        break;
                    case 57:
                        ledCommand.setTitle("盘点再入库");
                        break;
                    case 53:
                        ledCommand.setTitle("拣料再入库");
                        break;
                    case 101:
                        ledCommand.setTitle("全板出库");
                        break;
                    case 103:
                        ledCommand.setTitle("拣料出库");
                        break;
                    case 104:
                        ledCommand.setTitle("并板出库");
                        break;
                    case 107:
                        ledCommand.setTitle("盘点出库");
                        break;
                    case 110:
                        ledCommand.setTitle("空板出库");
                        ledCommand.setEmptyMk(true);
                        break;
                    default:
                        News.error("任务入出库类型错误!!![工作号:{}] [入出库类型:{}]", wrkMast.getWrkNo(), wrkMast.getIoType());
                        break;
                }
                ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
                ledCommand.setStaNo(wrkMast.getStaNo());
                ledCommand.setBarcode(wrkMast.getBarcode());
                if(wrkMast.getIoType() == 12){
                    List<WrkDetl> wrkDetls = wrkDetlService.findByBarcode(wrkMast.getBarcode());
                    wrkDetls.forEach(wrkDetl -> {
                        Double total = 0.0;
                        EntityWrapper<LocDetl> wrapper = new EntityWrapper<>();
                        LocDetl locDetl = locDetlService.selectOne(wrapper.eq("zpallet", wrkDetl.getZpallet()).eq("matnr", wrkDetl.getMatnr()));
                        if (Cools.isEmpty(locDetl)) {
                            total = wrkDetl.getAnfme();
                        } else {
                            total = locDetl.getAnfme();
                        }
                        ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getOrderNo(), wrkDetl.getSupp(), wrkDetl.getSku(),wrkDetl.getAnfme(),total));
                    });
                }
                if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) {
                    List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
                    wrkDetls.forEach(wrkDetl -> {
                        Double total = 0.0;
                        EntityWrapper<LocDetl> wrapper = new EntityWrapper<>();
                        LocDetl locDetl = locDetlService.selectOne(wrapper.eq("zpallet", wrkDetl.getZpallet()).eq("matnr", wrkDetl.getMatnr()));
                        if (Cools.isEmpty(locDetl)) {
                            total = wrkDetl.getAnfme();
                        } else {
                            total = locDetl.getAnfme();
                        }
                        if (wrkMast.getIoType() == 101 || wrkMast.getIoType() == 1) {
                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getOrderNo(), wrkDetl.getSupp(), wrkDetl.getSku(),wrkDetl.getAnfme(),total));
                        }
                        if (wrkMast.getIoType() == 103 && (null == wrkDetl.getInspect() || 0 == wrkDetl.getInspect())) {
                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getOrderNo(), wrkDetl.getSupp(), wrkDetl.getSku(),wrkDetl.getAnfme(),total));
                        }
                        if (wrkMast.getIoType() == 107) {
                            ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getOrderNo(), wrkDetl.getSupp(), wrkDetl.getSku(),wrkDetl.getAnfme(),total));
                        }
                    });
                }
                commands.add(ledCommand);
            }
            Set<Integer> workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet());
            // 获取LED线程
            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
            // 相同工作号集合则过滤
            if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) {
                continue;
            }
            // 命令下发 -------------------------------------------------------------------------------
            if (!commands.isEmpty()) {
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
                    News.error("{}号LED显示内容命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    continue;
                }
            }
            try {
                // 修改主档led标记
                for (WrkMast wrkMast : wrkMasts) {
                    wrkMast.setOveMk("Y");
                    wrkMast.setModiTime(new Date());
                    if (wrkMastMapper.updateById(wrkMast) == 0) {
                        throw new CoolException("更新工作档失败");
                    }
                }
                // 更新线程当前工作号集合
                ledThread.setWorkNos(workNos);
            } catch (Exception e) {
                e.printStackTrace();
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
        }
    }
    /**
     * 其他  ===>> LED显示器复位,显示默认信息
     */
    public synchronized void ledReset() {
        for (LedSlave led : slaveProperties.getLed()) {
            // 获取输送线plc线程
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
            // 命令集合
            boolean reset = true;
            for (Integer staNo : led.getStaArr()) {
//                System.out.println("staArr = " + staNo);
                // 获取叉车站点
                StaProtocol staProtocol = devpThread.getStation().get(staNo);
                if (staProtocol == null) { continue; }
                if (staProtocol.getWorkNo() != 0 || staProtocol.isErr()) {
                    reset = false;
                    break;
                }
            }
            // 获取led线程
            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
            // led显示默认内容
            if (reset) {
                if (ledThread == null) {
                    continue;
                }
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
                    News.error("{}号LED显示默认命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                }
//                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
//                    News.error("{}号LED显示默认命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
//                }
            }
        }
    }
    /**
     * 堆垛机5分钟无任务则回到源点
     */
@@ -1180,7 +1417,7 @@
                        if (!WrkMastLogList.isEmpty()) {
                            boolean signT = false;
                            for (WrkMast wrkMast : WrkMastLogList){
                                Date completeTime = wrkMast.getIoTime();
                                Date completeTime = wrkMast.getModiTime();
                                if (completeTime==null){
                                    continue;
                                }
@@ -1204,7 +1441,7 @@
                        crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                        crnCommand.setTaskMode(CrnTaskModeType.GO_ORIGIN); // 任务模式:  站位移转4
                        Integer crnNo = crnProtocol.getCrnNo();
                        int row1 = crnNo * 4;
                        int row1 = crnNo * 4-1;
                        if (crnNo>2){
                            row1 = row1-2;
                        }
@@ -1242,6 +1479,45 @@
    /////////////////////////////////////RGV调度/////////////////////////////////////
    public synchronized void taskCreate() {
        for (RgvSlave rgvSlave : slaveProperties.getRgv()) {
            try {
                for (RgvSlave.RgvStn inSta : rgvSlave.getRgvInSta()) {
                    WrkMast wrkMast = deviceDetectionCreate(inSta);
                    if (!Cools.isEmpty(wrkMast)) {
                        TaskWrk taskWrk = new TaskWrk(wrkMast);
                        taskWrkService.insert(taskWrk);
                    }
                }
            } catch (Exception e){
            }
        }
    }
    public synchronized void taskCancel() {
        try {
            List<String> taskList = new ArrayList<>();
            for (RgvSlave rgvSlave : slaveProperties.getRgv()) {
                RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId());
                TaskProtocolCache taskProtocolCache = rgvThread.getTaskProtocolCache();
                ConcurrentHashMap<String, TaskProtocol> allTaskProtocol = taskProtocolCache.getAllTaskProtocol();
                for (TaskProtocol taskProtocol : allTaskProtocol.values()){
                    taskList.add(taskProtocol.getTaskNo().toString());
                }
            }
            Wrapper<TaskWrk> wrkWrapper = new EntityWrapper<TaskWrk>().eq("status", 5);
            for (String taskNo : taskList){
                wrkWrapper.ne("task_no", taskNo);
            }
            int count = taskWrkService.selectCount(wrkWrapper);
            if (count>0){
                taskWrkService.delete(wrkWrapper);
            }
        } catch (Exception e){
        }
    }
    public synchronized void taskStart() {
        for (RgvSlave rgvSlave : slaveProperties.getRgv()) {
            try {
@@ -1724,6 +2000,34 @@
        return true;
    }
    public WrkMast deviceDetectionCreate(RgvSlave.RgvStn inSta) {
        DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, inSta.getDevpPlcId());
        StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
        if (staProtocol == null) {
            return null;
        }
        // 判断是否满足取货条件
        if (staProtocol.isAutoing()
//                && staProtocol.isLoading()
//                && staProtocol.isStaOk()
                && staProtocol.getWorkNo() != 0) {
            WrkMast wrkMast = wrkMastService.selectByWrkNo(staProtocol.getWorkNo());
            if (!Cools.isEmpty(wrkMast)){
                if (inSta.getStaNo()==117 || inSta.getStaNo()==120 || inSta.getStaNo()==123
                        || inSta.getStaNo()==217 || inSta.getStaNo()==220 || inSta.getStaNo()==223){
                    if (wrkMast.getIoType()>100){
                        return null;
                    }
                }
                TaskWrk taskWrk = taskWrkService.selectByTaskNo(staProtocol.getWorkNo());
                if (Cools.isEmpty(taskWrk)){
                    return wrkMast;
                }
            }
        }
        return null;
    }
    public TaskWrk deviceDetection(RgvSlave.RgvStn inSta) {
        DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, inSta.getDevpPlcId());
@@ -1741,7 +2045,7 @@
//                && staProtocol.isLoading()
//                && staProtocol.isStaOk()
                && staProtocol.getWorkNo() != 0) {
            TaskWrk taskWrk = taskWrkService.selectByWrkNo(staProtocol.getWorkNo());
            TaskWrk taskWrk = taskWrkService.selectByTaskNo(staProtocol.getWorkNo());
            if (taskWrk != null) {
                Integer stano = staProtocol.getStaNo().intValue();
                if (staProtocol.getSiteId() == 1004 || staProtocol.getSiteId()==1020){
@@ -1859,7 +2163,7 @@
                // 判断是否满足取货条件
                if (staProtocolOther.isAutoing()
                        && staProtocolOther.getWorkNo() != 0) {
                    TaskWrk taskWrkOther = taskWrkService.selectByWrkNo(staProtocolOther.getWorkNo());
                    TaskWrk taskWrkOther = taskWrkService.selectByTaskNo(staProtocolOther.getWorkNo());
                    if (taskWrkOther != null) {
                        return taskWrkOther;
                    }
@@ -1969,6 +2273,7 @@
                issuedTake.setTaskNo(Long.valueOf(taskWrk.getWrkNo()));
                issuedTake.setTaskStatus(2);
                issuedTake.setTargetPositionStaNo(basDevpPositionSou.getDevNo());
                issuedTake.setTargetPositionStaNoEnd(basDevpPositionSou.getDevNo$());
                issuedTake.setTargetPositionStaNoPlcId(basDevpPositionSou.getPlcId());
                issuedTake.setTaskNoDirection(issuedTake.gettaskNoDirection$(issuedTake.getTaskNo(), issuedTake.getTaskStatus()));
                issuedTake.setTargetPosition(basDevpPositionSou.getPlcPosition());
@@ -1979,6 +2284,7 @@
                issuedPut.setTaskNo(Long.valueOf(taskWrk.getWrkNo()));
                issuedPut.setTaskStatus(3);
                issuedPut.setTargetPositionStaNo(basDevpPositionEnd.getDevNo());
                issuedPut.setTargetPositionStaNoEnd(basDevpPositionEnd.getDevNo$());
                issuedPut.setTargetPositionStaNoPlcId(basDevpPositionEnd.getPlcId());
                issuedPut.setTaskNoDirection(issuedPut.gettaskNoDirection$(issuedPut.getTaskNo(), issuedPut.getTaskStatus()));
                issuedPut.setTargetPosition(basDevpPositionEnd.getPlcPosition());
@@ -1986,13 +2292,11 @@
                issuedPut.setDirection(basDevpPositionEnd.getRgvSign()==1);
                try{
                    if (taskWrk.getIoType()==2 && basDevpPositionEnd.getRgvSign()==1){
                        Date now = new Date();
                        taskWrk.setStatus(TaskStatusType.OVER.id);
                        taskWrk.setModiTime(now);//更新时间
                        taskWrk.setCompleteTime(now);//完结时间
                        taskWrkService.updateById(taskWrk);
                    }
                    Date now = new Date();
                    taskWrk.setStatus(TaskStatusType.OVER.id);
                    taskWrk.setModiTime(now);//更新时间
                    taskWrk.setCompleteTime(now);//完结时间
                    taskWrkService.updateById(taskWrk);
                } catch (Exception e){
                }