自动化立体仓库 - WCS系统
#
luxiaotao1123
2020-08-11 6c258de9be7d09a3f9f8d043a6a68bc03f073fc2
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -1,5 +1,6 @@
package com.zy.asrs.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
@@ -7,10 +8,7 @@
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.WaitPakinMapper;
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.StaDescService;
import com.zy.asrs.service.WrkDetlService;
import com.zy.asrs.service.*;
import com.zy.common.model.StartupDto;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
@@ -19,6 +17,7 @@
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;
@@ -58,6 +57,8 @@
    private StaDescService staDescService;
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
@@ -244,7 +245,7 @@
                StaProtocol staProtocol = devpThread.getStation().get(outSta.getStaNo());
                if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
                    // 查询工作档
                    WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(staProtocol.getSiteId());
                    WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(staProtocol.getSiteId());
                    if (wrkMast == null) {
                        continue;
                    }
@@ -302,8 +303,8 @@
            if (basCrnp == null) {
                continue;
            }
            // 只有当堆垛机空闲 或者 无任务时才继续执行
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE || crnProtocol.getTaskNo() == 0) {
            // 只有当堆垛机空闲 并且 无任务时才继续执行
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0) {
                // 如果最近一次是入库模式
                if (crnProtocol.getLastIo().equals("I")) {
                    if (basCrnp.getInEnable().equals("Y")) {
@@ -340,17 +341,46 @@
            // 获取堆垛机入库站信息
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
            StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
            // todo:luxiaotao
            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0) {
            // 查询站点详细信息
            BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
            if (staDetl == null) {
                log.error("入库库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                continue;
            }
            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staDetl.getCanining().equals("Y")) {
                flag = true;
            }
            if (!flag) {
                return;
                continue;
            }
            WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
            // 获取工作状态为2(设备上走)的入库工作档
            WrkMast wrkMast = wrkMastMapper.selectPakInStep2(slave.getId(), staProtocol.getWorkNo());
            if(null == wrkMast) {
                log.error("查询无待入库数据--wrk_sts=2, 工作号={}", staProtocol.getWorkNo());
                continue;
            }
            // 获取库位信息
            LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
            if (locMast == null) {
                log.error("查询库存无数据--库位号{}", wrkMast.getLocNo());
                continue;
            }
            if (!locMast.getLocSts().equals("S") && !locMast.getLocSts().equals("Q")) {
                log.error("入库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), locMast.getLocSts());
                continue;
            }
            // 命令下发区 --------------------------------------------------------------------------
//            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, slave.getId());
//            CrnProtocol crnProtocol = crnThread.getCrnProtocol();
            CrnCommand crnCommand = new CrnCommand();
            crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
            crnCommand.setDestinationPosX(locMast.getRow1().shortValue()); // 排
            crnCommand.setDestinationPosY(locMast.getBay1().shortValue()); // 列
            crnCommand.setDestinationPosZ(locMast.getLev1().shortValue()); // 层
            if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task<>(2, crnCommand))) {
                log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
            }
        }
    }
@@ -359,12 +389,43 @@
     */
    private void locToCrnStn(CrnSlave slave){
        for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) {
            // 获取工作状态为11(生成出库ID)的出库工作档
            WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId());
            if (wrkMast == null) {
                continue;
            }
            // 工作档状态判断
            if (wrkMast.getIoType() < 100 || wrkMast.getSourceStaNo() == null){
                log.error("查询工作档数据不符合条件--入出类型/站点, 工作号={},源库位={},入出类型={}", wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getIoType());
                continue;
            }
            // 获取源库位信息
            LocMast sourceSta = locMastService.selectById(wrkMast.getSourceLocNo());
            if (!sourceSta.getLocSts().equals("R") &&!sourceSta.getLocSts().equals("P")) {
                log.error("出库操作库位状态不符合--状态, 库位号={},库位状态={}", wrkMast.getLocNo(), sourceSta.getLocSts());
                continue;
            }
            // 获取堆垛机出库站信息
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
            StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
            // 查询站点详细信息
            BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
            if (staDetl == null) {
                log.error("出库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                continue;
            }
            // 判断堆垛机出库站状态
            if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting().equals("Y")
                    && staProtocol.getWorkNo() == 0) {
                // 命令下发区 --------------------------------------------------------------------------
                CrnCommand crnCommand = new CrnCommand();
                crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
                crnCommand.setAckFinish((short) 1);  // 任务完成确认位
                if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task<>(2, crnCommand))) {
                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
                }
            }
        }
    }