#
Administrator
2024-07-25 e628feceb32d3a42b85d2f25864700af82527d3d
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -3,7 +3,6 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
@@ -21,7 +20,6 @@
import com.zy.common.utils.CollectionUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.RedisUtil;
import com.zy.common.utils.RgvUtils;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
@@ -881,6 +879,48 @@
            }
        }
    }
    /**
     * 堆垛机站出库到出库站
     */
    public synchronized void crnStnToOutStn1() {
        for (CrnSlave crnSlave : slaveProperties.getCrn()) {
            // 遍历堆垛机出库站
            for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) {
                // 查询工作档
                WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(crnStn.getStaNo());
                if (wrkMast == null) {
                    continue;
                }
                // 判断工作档条件
                if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) {
                    continue;
                }
                // 判断吊车是否实际已完成,且电脑状态在move中,以备电脑进行更新工作档
                CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo());
                CrnProtocol crnProtocol = crnThread.getCrnProtocol();
                if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) {
                    // 移动中
                    continue;
                }
                //  判断堆垛机状态等待确认
                if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
                        && crnProtocol.statusType == CrnStatusType.WAITING
                        && crnProtocol.forkPosType == CrnForkPosType.HOME) {
                    // 命令下发区 --------------------------------------------------------------------------
                    // 更新工作档状态为14
                    wrkMast.setWrkSts(13L);
                    wrkMast.setCrnEndTime(new Date());
                    if (wrkMastMapper.updateById(wrkMast) != 0) {
                        // 复位堆垛机
                        crnThread.setResetFlag(true);
                    } else {
                        log.error("更新工作档的工作状态为14失败!!! [工作号:{}]", wrkMast.getWrkNo());
                    }
                }
            }
        }
    }
    /**
     * 堆垛机站出库到出库站
@@ -1275,28 +1315,28 @@
                continue;
            }
            boolean flag = false;
            boolean flag = true;
            // 获取堆垛机入库站信息
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
            StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
            if (staProtocol == null) {
                continue;
            } else {
                staProtocol = staProtocol.clone();
            }
            // 查询站点详细信息
            BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
            if (staDetl == null) {
                log.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                continue;
            }
            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable()
                    && staDetl.getCanining() != null && staDetl.getCanining().equals("Y")) {
                flag = true;
            }
            if (!flag) {
                continue;
            }
//            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
//            StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
//            if (staProtocol == null) {
//                continue;
//            } else {
//                staProtocol = staProtocol.clone();
//            }
//            // 查询站点详细信息
//            BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
//            if (staDetl == null) {
//                log.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
//                continue;
//            }
//            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable()
//                    && staDetl.getCanining() != null && staDetl.getCanining().equals("Y")) {
//                flag = true;
//            }
//            if (!flag) {
//                continue;
//            }
            // 获取库位信息
            LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
@@ -1357,18 +1397,19 @@
                }
            }
            // 命令下发区 --------------------------------------------------------------------------
            // 入库命令下发区 --------------------------------------------------------------------------
            CrnCommand crnCommand = new CrnCommand();
            crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
            crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
            crnCommand.setAckFinish((short) 0);  // 任务完成确认位
            crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
            crnCommand.setSourcePosX(crnStn.getRow().shortValue());     // 源库位排
            crnCommand.setSourcePosY(crnStn.getBay().shortValue());     // 源库位列
            crnCommand.setSourcePosZ(crnStn.getLev().shortValue());     // 源库位层
            //crnCommand.setSourcePosX(crnStn.getRow().shortValue());     // 源库位排
            //crnCommand.setSourcePosY(crnStn.getBay().shortValue());     // 源库位列
            //crnCommand.setSourcePosZ(crnStn.getLev().shortValue());     // 源库位层
            crnCommand.setDestinationPosX(locMast.getRow1().shortValue());     // 目标库位排
            crnCommand.setDestinationPosY(locMast.getBay1().shortValue());     // 目标库位列
            crnCommand.setDestinationPosZ(locMast.getLev1().shortValue());     // 目标库位层
            crnCommand.setSourceStaNo(crnStn.getPlatNo().shortValue());     // 源库位排
            if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
                log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
            } else {
@@ -1530,6 +1571,11 @@
    public synchronized void locToCrnStn1(CrnSlave slave, CrnProtocol crnProtocol) {
        List<WrkMast> wrkMasts = wrkMastMapper.selectPakOutStep12(slave.getId());
        for (WrkMast wrkMast : wrkMasts) {
            // 判断堆垛机站点是否可用
            if (!crnEnabled(wrkMast)){
                continue;
            }
            if (wrkMast == null) {
                continue;
            }
@@ -1550,13 +1596,6 @@
                log.error("查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
                continue;
            }
            //退库模式跳过118、119出库任务
            if (wrkMast.getStaNo()==118 || wrkMast.getStaNo()==119){
                RgvOneSign rgvOneSign = rgvOneSignMapper.selectOneSign();
                if (Cools.isEmpty(rgvOneSign) || rgvOneSign.getRgvOneSign()==1){
                    continue;
                }
            }
            // 获取源库位信息
            LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
            if (!sourceSta.getLocSts().equals("R") && !sourceSta.getLocSts().equals("P")) {
@@ -1564,20 +1603,20 @@
                continue;
            }
            // 获取堆垛机出库站信息
            SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
            StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
            if (staProtocol == null) {
                break;
//                    continue;
            } else {
                staProtocol = staProtocol.clone();
            }
            //SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
            //StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
//            if (staProtocol == null) {
//                break;
////                    continue;
//            } else {
//                staProtocol = staProtocol.clone();
//            }
//            // 入出库模式判断
//            if (devpThread.ioMode != IoModeType.PAKOUT_MODE) { continue; }
            if (wrkMast.getStaNo() == 204 && devpThread.ioModeOf2F != IoModeType.PAKOUT_MODE) {
                continue;
            }
//            if (wrkMast.getStaNo() == 204 && devpThread.ioModeOf2F != IoModeType.PAKOUT_MODE) {
//                continue;
//            }
            // 查询站点详细信息
            BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
@@ -1587,8 +1626,9 @@
//                    continue;
            }
            // 判断堆垛机出库站状态
            if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")
                    && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
            //if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")
            //        && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
            if (staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")) {
                // 命令下发区 --------------------------------------------------------------------------
                // 堆垛机控制过滤
@@ -1647,7 +1687,7 @@
//                        return;
                }
                // 1.堆垛机开始移动
                // 1.堆垛机开始移动   出库命令
                CrnCommand crnCommand = new CrnCommand();
                crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
                crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
@@ -1656,9 +1696,10 @@
                crnCommand.setSourcePosX(sourceSta.getRow1().shortValue());     // 源库位排
                crnCommand.setSourcePosY(sourceSta.getBay1().shortValue());     // 源库位列
                crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue());     // 源库位层
                crnCommand.setDestinationPosX(crnStn.getRow().shortValue());     // 目标库位排
                crnCommand.setDestinationPosY(crnStn.getBay().shortValue());     // 目标库位列
                crnCommand.setDestinationPosZ(crnStn.getLev().shortValue());     // 目标库位层
//                crnCommand.setDestinationPosX(crnStn.getRow().shortValue());     // 目标库位排
//                crnCommand.setDestinationPosY(crnStn.getBay().shortValue());     // 目标库位列
//                crnCommand.setDestinationPosZ(crnStn.getLev().shortValue());     // 目标库位层
                crnCommand.setDestinationStaNo(crnStn.getPlatNo().shortValue());
                if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
                } else {
@@ -1678,6 +1719,72 @@
    }
    /**
     * 确认出库码头是否可用
     * @param wrkMast 工作档
     * @return 是否可用
     */
    private boolean crnEnabled(WrkMast wrkMast) {
        String url = "http://192.168.14.249:8008";
        String path = "/api/Task/DockStatus";
        // 获取请求头
        Map<String,Object> headers = new HashMap<>();
        headers.put("digi-type","sync ");
        headers.put("digi-protocol","raw");
        headers.put("digi-datakey"," XCommon.ImportData");
        // 构造请求体
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("staNo", wrkMast.getSourceStaNo());
        jsonObject.put("workNo", wrkMast.getWrkNo());
        String body = jsonObject.toJSONString();
        boolean success;
        String response;
        try {
            response = new HttpHandler.Builder()
                    .setUri(url)
                    .setPath(path)
                    .setHeaders(headers)
                    .setJson(body)
                    .build()
                    .doPost();
            if (!Cools.isEmpty(response)) {
                JSONObject jsonObject1 = JSONObject.parseObject(response);
                if ((Integer) jsonObject1.get("code") == 200 && (Integer) jsonObject1.get("data") == 1){
                    success = true;
                }else {
                    success = false;
                }
            } else {
                log.error("请求接口失败!!!url:{};request:{};response:{}", url + path, body, response);
                throw new CoolException("下发出库任务给GWCS(从出库码头到出库口)失败");
            }
        } catch (Exception e) {
            success = false;
            log.error("确认出库码头是否可用异常,工作号:{},{}", wrkMast.getWrkNo(),e.getMessage());
        } finally {
//            try {
//                // 保存接口日志
//                apiLogService.save(
//                        "从出库码头到出库口",
//                        MesConstant.URL + MesConstant.PAKIN_URL,
//                        null,
//                        "127.0.0.1",
//                        jsonObject.toJSONString(),
//                        response,
//                        success
//                );
//            } catch (Exception e) {
//                log.error("接口日志保存异常", e);
//            }
        }
        return success;
    }
    /**
     * 查找工作状态为2(设备上走),且RGV入库接驳站符合的的入库工作档,提取出最多2笔
     * @param slave
     * @return