自动化立体仓库 - WCS系统
#
Junjie
2023-11-27 d8cef0a05401284e18fefcfcf51ebc1b0f6da702
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -2,14 +2,12 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.WMSAndAGVInterfaceParam;
import com.zy.asrs.mapper.BasCrnErrorMapper;
import com.zy.asrs.mapper.TaskWrkMapper;
import com.zy.asrs.mapper.WaitPakinMapper;
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.mapper.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.CommandUtils;
import com.zy.asrs.utils.PostMesDataUtils;
@@ -18,14 +16,18 @@
import com.zy.common.utils.HttpHandler;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.*;
import com.zy.core.model.CrnSlave;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.Task;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.protocol.CrnProtocol;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.BarcodeThread;
import com.zy.core.thread.LedThread;
import com.zy.core.thread.SiemensDevpThread;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
@@ -70,11 +72,93 @@
    private TaskWrkService taskWrkService;
    @Autowired
    private ConfigService configService;
    @Autowired
    private StaDescMapper staDescMapper;
    @Value("${wms.url}")
    private String wmsUrl;
    @Value("${wms.movePath}")
    private String movePath;
    public void generateStoreWrkFile() {
        // 根据输送线plc遍历
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历入库口
            for (DevpSlave.Sta inSta : devp.getInSta()) {
                // 获取入库站信息
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                Short workNo = staProtocol.getWorkNo();
                // 判断是否满足入库条件
                if (staProtocol.isAutoing() && staProtocol.isLoading()
                        && !staProtocol.isInEnable()
                        && !staProtocol.isEmptyMk() && (workNo >= 0)
                        && staProtocol.isPakMk()) {
                    // 尺寸检测异常
                    boolean back = false;
                    String errMsg = "";
                    if (staProtocol.isFrontErr()) {
                        errMsg = "前超限";
                        back = true;
                    }
                    if (!back && staProtocol.isBackErr()) {
                        errMsg = "后超限";
                        back = true;
                    }
                    if (!back && staProtocol.isHighErr()) {
                        errMsg = "高超限";
                        back = true;
                    }
                    if (!back && staProtocol.isLeftErr()) {
                        errMsg = "左超限";
                        back = true;
                    }
                    if (!back && staProtocol.isRightErr()) {
                        errMsg = "右超限";
                        back = true;
                    }
                    if (!back && staProtocol.isWeightErr()) {
                        errMsg = "超重";
                        back = true;
                    }
                    if (!back && staProtocol.isBarcodeErr()) {
                        errMsg = "扫码失败";
                        back = true;
                    }
                    // 退回
                    if (back) {
//                        News.warn("扫码入库失败,{}入库站因{}异常,托盘已被退回", inSta.getStaNo(), errMsg);
                        staProtocol.setWorkNo(workNo);
                        staProtocol.setStaNo(inSta.getBackSta().shortValue());
                        devpThread.setPakMk(staProtocol.getSiteId(), false);
                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        continue;
                    }
                    // 获取条码扫描仪信息
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
                    if (barcodeThread == null) {
                        continue;
                    }
                    String barcode = barcodeThread.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                    }
                }
            }
        }
    }
    /**
     * 堆垛机站出库到出库站
@@ -84,56 +168,60 @@
        for (CrnSlave crnSlave : slaveProperties.getCrn()) {
            // 遍历堆垛机出库站
            for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) {
                // 获取堆垛机出库站信息
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
                StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
                    // 查询工作档
                    TaskWrk taskWrk = taskWrkMapper.selectCrnStaWorking(crnSlave.getId(), staProtocol.getSiteId().toString());
                    if (taskWrk == null) {
                List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", crnSlave.getId()).eq("crn_stn", crnStn.getStaNo()));
                for (StaDesc staDesc : staDescs){
                    // 获取堆垛机出库站信息
                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
                    StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    // 判断工作档条件
                    if (taskWrk.getWrkSts() == 12 && taskWrk.getIoType() == 2) {
                        // 判断吊车是否实际已完成,且电脑状态在move中,以备电脑进行更新工作档
                        CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, taskWrk.getCrnNo());
                        CrnProtocol crnProtocol = crnThread.getCrnProtocol();
                        if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) {
                            // 移动中
                    if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == 0)) {
                        // 查询工作档
                        TaskWrk taskWrk = taskWrkMapper.selectCrnStaWorking(crnSlave.getId(), staDesc.getStnNo().toString());
                        if (taskWrk == null) {
                            continue;
                        }
                        //  判断堆垛机状态等待确认
                        if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(taskWrk.getWrkNo().shortValue())
                                && crnProtocol.getTaskFinish() == 1
                                && crnProtocol.forkPosType == CrnForkPosType.HOME) {
                            // 命令下发区 --------------------------------------------------------------------------
                            // 下发站点信息
                            staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue());
                            String targetPoint = taskWrk.getTargetPoint();
                            int i = Integer.parseInt(targetPoint);
                            staProtocol.setStaNo((short)i);
                            if (!CommandUtils.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) {
                        // 判断工作档条件
                        if (taskWrk.getWrkSts() == 12 && taskWrk.getIoType() == 2) {
                            // 判断吊车是否实际已完成,且电脑状态在move中,以备电脑进行更新工作档
                            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, taskWrk.getCrnNo());
                            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
                            if (crnProtocol.statusType == CrnStatusType.FETCHING || crnProtocol.statusType == CrnStatusType.PUTTING) {
                                // 移动中
                                continue;
                            }
                            //  判断堆垛机状态等待确认
                            if (crnProtocol.statusType == CrnStatusType.HANDLING_COMPLETED && crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(taskWrk.getWrkNo().shortValue())
                                    && crnProtocol.getTaskFinish() == 0
                                    && crnProtocol.forkPosType == CrnForkPosType.HOME) {
                                // 命令下发区 --------------------------------------------------------------------------
                            // 更新工作档状态为14失败
                            taskWrk.setWrkSts(14);
                            if (taskWrkMapper.updateById(taskWrk) != 0) {
                                // 复位堆垛机
                                crnThread.setResetFlag(true);
                            } else {
                                log.error("更新工作档的工作状态为14失败!!! [工作号:{}]", taskWrk.getWrkNo());
                                // 下发站点信息
                                staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue());
                                String targetPoint = taskWrk.getTargetPoint();
                                int i = Integer.parseInt(targetPoint);
                                staProtocol.setStaNo((short)i);
                                if (!CommandUtils.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) {
                                    continue;
                                }
                                // 更新工作档状态为14失败
                                taskWrk.setWrkSts(14);
                                if (taskWrkMapper.updateById(taskWrk) != 0) {
                                    // 复位堆垛机
                                    crnThread.setResetFlag(true);
                                } else {
                                    log.error("更新工作档的工作状态为14失败!!! [工作号:{}]", taskWrk.getWrkNo());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
@@ -188,78 +276,72 @@
     */
    public void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol){
        for (CrnSlave.CrnStn crnStn : slave.getCrnInStn()) {
            boolean flag = false;
            // 获取堆垛机入库站信息
            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;
            }
            // 获取工作状态为2(设备上走)的入库工作档
            TaskWrk taskWrk = taskWrkMapper.selectPakIn(slave.getId(), staProtocol.getWorkNo().intValue(), crnStn.getStaNo().toString());
            if(null == taskWrk) {
                continue;
            }
            // 获取库位信息
            String locNo = taskWrk.getTargetPoint();
            LocMast locMast = locMastService.selectById(locNo);
            if (locMast == null) {
                log.error("查询库存无数据--库位号{}", locNo);
                continue;
            }
            if (!locMast.getLocSts().equals("S") && !locMast.getLocSts().equals("Q")) {
                log.error("入库操作库位状态不符合--状态, 库位号={},库位状态={}", locNo, locMast.getLocSts());
                continue;
            }
            List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", slave.getId()).eq("crn_stn", crnStn.getStaNo()));
            for (StaDesc staDesc : staDescs) {
                boolean flag = false;
                // 获取堆垛机入库站信息
                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;
                }
                // 获取工作状态为2(设备上走)的入库工作档
                TaskWrk taskWrk = taskWrkMapper.selectPakIn(slave.getId(), staProtocol.getWorkNo().intValue(), staDesc.getStnNo().toString());
                if(null == taskWrk) {
                    continue;
                }
            // 堆垛机控制过滤
            if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
                continue;
            }
                // 堆垛机控制过滤
                if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
                    continue;
                }
            // 已经存在吊车执行任务时,则过滤
            if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) {
                continue;
            }
                // 已经存在吊车执行任务时,则过滤
                if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) {
                    continue;
                }
            // 命令下发区 --------------------------------------------------------------------------
            CrnCommand crnCommand = new CrnCommand();
            crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
            crnCommand.setTaskNo(taskWrk.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.setDestinationPosX(locMast.getRow1().shortValue());     // 目标库位排
            crnCommand.setDestinationPosY(locMast.getBay1().shortValue());     // 目标库位列
            crnCommand.setDestinationPosZ(locMast.getLev1().shortValue());     // 目标库位层
            if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));
            } else {
                // 修改工作档状态 2.设备上走 => 3.吊车入库中
                Date now = new Date();
                taskWrk.setWrkSts(3);
                taskWrk.setModiTime(now);
                if (taskWrkMapper.updateById(taskWrk) == 0) {
                    log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", taskWrk.getWrkNo());
                // 命令下发区 --------------------------------------------------------------------------
                CrnCommand crnCommand = new CrnCommand();
                crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
                crnCommand.setTaskNo(taskWrk.getWrkNo().shortValue()); // 工作号
                crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
                crnCommand.setSourcePosX(crnStn.getBay().shortValue());     // 源库位列
                crnCommand.setSourcePosY(crnStn.getLev().shortValue());     // 源库位层
                crnCommand.setSourcePosZ(crnStn.getRow().shortValue());     // 源库位排
                crnCommand.setDestinationPosX(Utils.getBayShort(taskWrk.getTargetPoint()));     // 目标库位列
                crnCommand.setDestinationPosY(Utils.getLevShort(taskWrk.getTargetPoint()));     // 目标库位层
                crnCommand.setDestinationPosZ(Utils.getRowShort(taskWrk.getTargetPoint()));     // 目标库位排
                crnCommand.setCommand((short)1);
                if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));
                } else {
                    // 修改工作档状态 2.设备上走 => 3.吊车入库中
                    Date now = new Date();
                    taskWrk.setWrkSts(3);
                    taskWrk.setModiTime(now);
                    if (taskWrkMapper.updateById(taskWrk) == 0) {
                        log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", taskWrk.getWrkNo());
                    }
                }
            }
            return;
        }
    }
@@ -269,116 +351,116 @@
     * 2022-06-09 TQS修改,查询工作档LIST,遍历下发,防止第一个任务堵塞出库
     */
    public void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol){
        List<TaskWrk> taskWrksInitial = taskWrkMapper.selectPakOut(slave.getId(), null);
        if (taskWrksInitial.size()==0){
            return;
        }
        for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) {
            // 获取工作状态为11(生成出库ID)的出库工作档
            List<TaskWrk> taskWrks = taskWrkMapper.selectPakOut(slave.getId(), crnStn.getStaNo().toString());
            for (TaskWrk taskWrk : taskWrks){
                if (taskWrk == null) {
                    continue;
                }
                // 工作档状态判断
                if (taskWrk.getIoType() != 2 || taskWrk.getTargetPoint() == null) {
                    log.error("查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", taskWrk.getWrkNo(), taskWrk.getTargetPoint(), taskWrk.getIoType());
                    continue;
                }
                // 获取源库位信息
                String locNo = taskWrk.getStartPoint();
                LocMast sourceSta = locMastService.selectById(locNo);
                if (!sourceSta.getLocSts().equals("R") &&!sourceSta.getLocSts().equals("P")) {
                    log.error("出库操作库位状态不符合--状态, 库位号={},库位状态={}", locNo, sourceSta.getLocSts());
                    continue;
                }
                // 获取堆垛机出库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
                StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
                if (staProtocol == null) {
                    break;
                } else {
                    staProtocol = staProtocol.clone();
                }
            List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", slave.getId()).eq("crn_stn", crnStn.getStaNo()));
            for (StaDesc staDesc : staDescs){
                // 获取工作状态为11(生成出库ID)的出库工作档
                List<TaskWrk> taskWrks = taskWrkMapper.selectPakOut(slave.getId(),staDesc.getStnNo().toString());
                for (TaskWrk taskWrk : taskWrks){
                    if (taskWrk == null) {
                        continue;
                    }
                    // 工作档状态判断
                    if (taskWrk.getIoType() != 2 || taskWrk.getTargetPoint() == null || taskWrk.getStartPoint() == null) {
                        log.error("查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", taskWrk.getWrkNo(), taskWrk.getStartPoint(), taskWrk.getIoType());
                        continue;
                    }
                    // 获取堆垛机出库站信息
                    SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
                    StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
                    if (staProtocol == null) {
                        break;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                // 查询站点详细信息
                BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
                if (staDetl == null) {
                    log.error("出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                    break;
                }
                // 判断堆垛机出库站状态
                if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() !=null && staDetl.getCanouting().equals("Y")
                        && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
                    // 命令下发区 --------------------------------------------------------------------------
                    // 堆垛机控制过滤
                    if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
                    // 查询站点详细信息
                    BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
                    if (staDetl == null) {
                        log.error("出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                        break;
                    }
                    // 已经存在吊车执行任务时,则过滤
                    if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) {
                        break;
                    }
                    // 判断堆垛机出库站状态
                    if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() !=null && staDetl.getCanouting().equals("Y")
                            && staProtocol.getWorkNo() == 0 && staProtocol.isOutEnable()) {
                        // 命令下发区 --------------------------------------------------------------------------
                    // 双深库位且浅库位有货,则需先对浅库位进行库位移转
                    if (Utils.isDeepLoc(slaveProperties, taskWrk.getStartPoint())) {
                        taskWrkMapper.selectPakOutIoType(taskWrk.getCrnNo());
                        List<TaskWrk> taskWrks1 = taskWrkMapper.selectPakOutIoType(taskWrk.getCrnNo());
                        if (Cools.isEmpty(taskWrks1) && taskWrks1.size()!=0){
                            continue;
                        // 堆垛机控制过滤
                        if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
                            break;
                        }
                        String shallowLocNo = Utils.getShallowLoc(slaveProperties, taskWrk.getStartPoint());
                        TaskWrk hallowLocNoTask = taskWrkMapper.selectByStartPoint(shallowLocNo);
                        if (!Cools.isEmpty(hallowLocNoTask)){
                            if (!Cools.isEmpty(hallowLocNoTask.getTargetPoint())){
                        // 已经存在吊车执行任务时,则过滤
                        if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) {
                            break;
                        }
                        // 双深库位且浅库位有货,则需先对浅库位进行库位移转
                        if (Utils.isDeepLoc(slaveProperties, taskWrk.getStartPoint())) {
                            taskWrkMapper.selectPakOutIoType(taskWrk.getCrnNo());
                            List<TaskWrk> taskWrks1 = taskWrkMapper.selectPakOutIoType(taskWrk.getCrnNo());
                            if (Cools.isEmpty(taskWrks1) && taskWrks1.size()!=0){
                                continue;
                            }
//                            new PostMesDataUtils().postMesData("移库任务分配库位",wmsUrl,movePath,hallowLocNoTask);
                            try {
                                String response = new HttpHandler.Builder()
                                        .setUri(wmsUrl)
                                        .setPath(movePath)
                                        .setJson(JSON.toJSONString(hallowLocNoTask))
                                        .build()
                                        .doPost();
                                System.out.println("response:"+response);
                                JSONObject jsonObject = JSON.parseObject(response);
                                if (jsonObject.getInteger("code").equals(200)) {
                                    //解析
                            String shallowLocNo = Utils.getShallowLoc(slaveProperties, taskWrk.getStartPoint());
                            TaskWrk hallowLocNoTask = taskWrkMapper.selectByStartPoint(shallowLocNo);
                            if (!Cools.isEmpty(hallowLocNoTask)){
                                if (!Cools.isEmpty(hallowLocNoTask.getTargetPoint())){
                                    continue;
                                }
                            }catch (Exception e){
                                log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl+"/"+movePath, JSON.toJSONString(hallowLocNoTask), "请求移库任务分配库位");
//                            new PostMesDataUtils().postMesData("移库任务分配库位",wmsUrl,movePath,hallowLocNoTask);
                                try {
                                    String response = new HttpHandler.Builder()
                                            .setUri(wmsUrl)
                                            .setPath(movePath)
                                            .setJson(JSON.toJSONString(hallowLocNoTask))
                                            .build()
                                            .doPost();
                                    System.out.println("response:"+response);
                                    JSONObject jsonObject = JSON.parseObject(response);
                                    if (jsonObject.getInteger("code").equals(200)) {
                                        //解析
                                    }
                                }catch (Exception e){
                                    log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl+"/"+movePath, JSON.toJSONString(hallowLocNoTask), "请求移库任务分配库位");
                                }
                                continue;
                            }
                            continue;
                        }
                    }
                    // 1.堆垛机开始移动
                    CrnCommand crnCommand = new CrnCommand();
                    crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
                    crnCommand.setTaskNo(taskWrk.getWrkNo().shortValue()); // 工作号
                    crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                    crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
                    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());     // 目标库位层
                    if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                        log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));
                    } else {
                        // 修改工作档状态 11.生成出库ID => 12.吊车出库中
                        Date now = new Date();
                        taskWrk.setWrkSts(12);
                        taskWrk.setModiTime(now);
                        if (taskWrkMapper.updateById(taskWrk) == 0) {
                            log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo());
                        // 1.堆垛机开始移动
                        CrnCommand crnCommand = new CrnCommand();
                        crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
                        crnCommand.setTaskNo(taskWrk.getWrkNo().shortValue()); // 工作号
                        crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                        crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
                        crnCommand.setSourcePosX(Utils.getBayShort(taskWrk.getStartPoint()));     // 源库位排
                        crnCommand.setSourcePosY(Utils.getLevShort(taskWrk.getStartPoint()));     // 源库位列
                        crnCommand.setSourcePosZ(Utils.getRowShort(taskWrk.getStartPoint()));     // 源库位层
                        crnCommand.setDestinationPosX(crnStn.getBay().shortValue());     // 目标库位排
                        crnCommand.setDestinationPosY(crnStn.getLev().shortValue());     // 目标库位列
                        crnCommand.setDestinationPosZ(crnStn.getRow().shortValue());     // 目标库位层
                        crnCommand.setCommand((short)1);
                        if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                            log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));
                        } else {
                            // 修改工作档状态 11.生成出库ID => 12.吊车出库中
                            Date now = new Date();
                            taskWrk.setWrkSts(12);
                            taskWrk.setModiTime(now);
                            if (taskWrkMapper.updateById(taskWrk) == 0) {
                                log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo());
                            }
                        }
                        break;
                        return;
                    }
                    return;
                }
            }
        }
@@ -400,38 +482,7 @@
                    log.error("查询工作档数据不符合条件--入出类型/目标库位号, 工作号={},源库位={},入出类型={}", taskWrk.getWrkNo(), taskWrk.getTargetPoint(), taskWrk.getIoType());
                    continue;
                }
                // 获取源库位信息
                String locNo = taskWrk.getStartPoint();
                LocMast sourceSta = locMastService.selectById(locNo);
                if (!sourceSta.getLocSts().equals("R") &&!sourceSta.getLocSts().equals("P")) {
                    log.error("出库操作库位状态不符合--状态, 库位号={},库位状态={}", locNo, sourceSta.getLocSts());
                    continue;
                }
                // 获取目标库位信息
                String locNoEnd = taskWrk.getTargetPoint();
                LocMast sourceEnd = locMastService.selectById(locNoEnd);
                if (!sourceEnd.getLocSts().equals("S") && !sourceEnd.getLocSts().equals("Q")) {
                    log.error("出库操作库位状态不符合--状态, 库位号={},库位状态={}", locNo, sourceSta.getLocSts());
                    continue;
                }
//                // 获取堆垛机出库站信息
//                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
//                StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
//                if (staProtocol == null) {
//                    break;
//                } else {
//                    staProtocol = staProtocol.clone();
//                }
                // 查询站点详细信息
                BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
                if (staDetl == null) {
                    log.error("出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                    continue;
                }
                // 命令下发区 --------------------------------------------------------------------------
                // 堆垛机控制过滤
@@ -444,38 +495,6 @@
                    continue;
                }
                // 起始深库位浅库位不为空
                if (Utils.isDeepLoc(slaveProperties, taskWrk.getStartPoint())) {
                    // 获取浅库位信息
                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, taskWrk.getStartPoint());
                    LocMast shallowLocMast = locMastService.selectById(shallowLocNo);
                    if (!shallowLocMast.getLocSts().equals("O")) {
                        log.error("移库操作起始库位浅库位状态不符合--状态, 库位号={},库位状态={}", locNo, shallowLocMast.getLocSts());
                        continue;
                    }
                }
                // 目标库位为深库位且浅库位不为空
                if (Utils.isDeepLoc(slaveProperties, taskWrk.getTargetPoint())) {
                    // 获取浅库位信息
                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, taskWrk.getTargetPoint());
                    LocMast shallowLocMast = locMastService.selectById(shallowLocNo);
                    if (!shallowLocMast.getLocSts().equals("O")) {
                        log.error("移库操作目标库位浅库位状态不符合--状态, 库位号={},库位状态={}", locNo, shallowLocMast.getLocSts());
                        continue;
                    }
                }
                // 目标库位为浅库位且深库位无货
                if (Utils.isShallowLoc(slaveProperties, taskWrk.getTargetPoint())) {
                    // 获取深库位信息
                    String deepLocNo = Utils.getDeepLoc(slaveProperties, taskWrk.getTargetPoint());
                    LocMast deepLocMast = locMastService.selectById(deepLocNo);
                    if (!deepLocMast.getLocSts().equals("F") && !deepLocMast.getLocSts().equals("D") ) {
                        log.error("移库操作目标库位深库位状态不符合--状态, 库位号={},库位状态={}", locNo, deepLocMast.getLocSts());
                        continue;
                    }
                }
                // 1.堆垛机开始移动
                CrnCommand crnCommand = new CrnCommand();
@@ -483,12 +502,12 @@
                crnCommand.setTaskNo(taskWrk.getWrkNo().shortValue()); // 工作号
                crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
                crnCommand.setSourcePosX(sourceSta.getRow1().shortValue());     // 源库位排
                crnCommand.setSourcePosY(sourceSta.getBay1().shortValue());     // 源库位列
                crnCommand.setSourcePosZ(sourceSta.getLev1().shortValue());     // 源库位层
                crnCommand.setDestinationPosX(sourceEnd.getRow1().shortValue());     // 目标库位排
                crnCommand.setDestinationPosY(sourceEnd.getBay1().shortValue());     // 目标库位列
                crnCommand.setDestinationPosZ(sourceEnd.getLev1().shortValue());     // 目标库位层
                crnCommand.setSourcePosX(Utils.getRowShort(taskWrk.getStartPoint()));     // 源库位排
                crnCommand.setSourcePosY(Utils.getBayShort(taskWrk.getStartPoint()));     // 源库位列
                crnCommand.setSourcePosZ(Utils.getLevShort(taskWrk.getStartPoint()));     // 源库位层
                crnCommand.setDestinationPosX(Utils.getRowShort(taskWrk.getTargetPoint()));     // 目标库位排
                crnCommand.setDestinationPosY(Utils.getBayShort(taskWrk.getTargetPoint()));     // 目标库位列
                crnCommand.setDestinationPosZ(Utils.getLevShort(taskWrk.getTargetPoint()));     // 目标库位层
                if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));
                } else {
@@ -518,15 +537,15 @@
            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
            if (crnProtocol == null) { continue; }
            //  状态:等待确认 并且  任务完成位 = 1
            if (crnProtocol.getTaskFinish() == 1 && crnProtocol.getTaskNo() != 0) {
            if (crnProtocol.getTaskFinish() == 0 && crnProtocol.statusType == CrnStatusType.HANDLING_COMPLETED && crnProtocol.getTaskNo() != 0) {
                // 获取入库待确认工作档
                TaskWrk taskWrk = taskWrkMapper.selectCrnNoWorking(crn.getId(),crnProtocol.getTaskNo().intValue());
                if (taskWrk == null) {
                if (Cools.isEmpty(taskWrk)) {
                    log.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", crn.getId(), crnProtocol.getTaskNo());
                    continue;
                }
                // 入库 + 库位转移  ==> 4.入库完成
                if (taskWrk.getWrkSts() == 3 || (taskWrk.getWrkSts() == 12 && taskWrk.getIoType() == 3)) {
                if ((taskWrk.getWrkSts() == 3 && taskWrk.getIoType() == 1) || (taskWrk.getWrkSts() == 12 && taskWrk.getIoType() == 3)) {
                    taskWrk.setWrkSts(4);
                } else {
                    continue;