#
lsh
2024-06-25 f30358a20ae9a74ee7f6c604a8d102c1b9b24659
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -11,10 +11,7 @@
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.CodeDetectionUtil;
import com.zy.asrs.utils.RouteUtils;
import com.zy.asrs.utils.Utils;
import com.zy.asrs.utils.VersionUtils;
import com.zy.asrs.utils.*;
import com.zy.common.model.LocTypeDto;
import com.zy.common.model.MatDto;
import com.zy.common.model.SearchLocParam;
@@ -30,9 +27,7 @@
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.*;
import com.zy.core.model.*;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.command.LedCommand;
import com.zy.core.model.command.RgvCommand;
import com.zy.core.model.command.*;
import com.zy.core.model.cpmmandParam.CrnCommandParam;
import com.zy.core.model.protocol.*;
import com.zy.core.properties.SlaveProperties;
@@ -1167,6 +1162,7 @@
        }
        return false;
    }
    public synchronized boolean crnStnToOutStnTwo(CrnSlave.CrnStn crnStn ,Integer conStation) {
        try{
            Date now = new Date();
@@ -1288,6 +1284,7 @@
        }
        return false;
    }
    public synchronized boolean crnStnToOutStnThree(CrnSlave.CrnStn crnStn ) {
        try{
            // 获取堆垛机出库站信息
@@ -2938,6 +2935,7 @@
            }
        }
    }
    public synchronized boolean storeFinishedExecuteOne(CrnSlave crn) {
        try{
            // 获取堆垛机信息
@@ -3003,6 +3001,7 @@
        }
        return false;
    }
    public synchronized boolean storeFinishedExecuteTwo(CrnSlave crn) {
        try{
            // 获取堆垛机信息
@@ -3094,6 +3093,7 @@
        }
        return false;
    }
    public synchronized boolean storeFinishedExecuteThree(CrnSlave crn) {
        try{
            // 获取堆垛机信息
@@ -3613,6 +3613,7 @@
            }
        }
    }
    /**
     * 空栈板初始化入库,叉车入库站放货
     */
@@ -4418,7 +4419,7 @@
    public synchronized void jarMastGenerate() {
        for (JarSlave jarSlave : slaveProperties.getJar()) {
            try{
                if (wrkMastExecuteService.getWrkMastByJarIdCount(jarSlave.getId())!=0){
                if (wrkMastExecuteService.getWrkMastExecuteByJarIdCount(jarSlave.getId())!=0){
                    continue;
                }
                for(JarSlave.StaStn staStn : jarSlave.getJarInSta()){
@@ -4473,7 +4474,7 @@
                            if (!Cools.isEmpty(basJarMast)){
                                continue;
                            }
                            WrkMastExecute wrkMastExecute = wrkMastExecuteService.getWrkMastByWrkNo(wrkMast.getWrkNo().longValue());
                            WrkMastExecute wrkMastExecute = wrkMastExecuteService.getWrkMastExecuteByWrkNo(wrkMast.getWrkNo().longValue());
                            if (!Cools.isEmpty(wrkMastExecute)){
                                continue;
                            }
@@ -4605,7 +4606,7 @@
        for (JarSlave jarSlave : slaveProperties.getJar()) {
            int i = jarSlave.getId()>2? 1:0;
            try{
                if (wrkMastExecuteService.getWrkMastByJarIdCount(jarSlave.getId())!=0){
                if (wrkMastExecuteService.getWrkMastExecuteByJarIdCount(jarSlave.getId())!=0){
                    continue;
                }
@@ -4670,11 +4671,14 @@
    public synchronized boolean[] jarWrkMastExecuteGenerateBurial(boolean[] signExecute,Integer sign) {
        for (JarSlave jarSlave : slaveProperties.getJar()) {
            if (jarSlave.getId()<5){
                continue;
            }
            try{
                if (signExecute[jarSlave.getId()-5]){
                    continue;
                }
                if (wrkMastExecuteService.getWrkMastByJarIdCount(jarSlave.getId())!=0){
                if (wrkMastExecuteService.getWrkMastExecuteByJarIdCount(jarSlave.getId())!=0){
                    signExecute[jarSlave.getId()-5] = true;
                    continue;
                }
@@ -4716,11 +4720,14 @@
    public synchronized boolean[] jarWrkMastExecuteGenerateSte(boolean[] signExecute,Integer sign) {
        for (JarSlave jarSlave : slaveProperties.getJar()) {
            if (jarSlave.getId()<5){
                continue;
            }
            try{
                if (signExecute[jarSlave.getId()-5]){
                    continue;
                }
                if (wrkMastExecuteService.getWrkMastByJarIdCount(jarSlave.getId())!=0){
                if (wrkMastExecuteService.getWrkMastExecuteByJarIdCount(jarSlave.getId())!=0){
                    continue;
                }
@@ -4774,7 +4781,7 @@
     */
    public synchronized boolean jarWrkMastExecuteGenerate1(JarSlave jarSlave,Integer sign) {
        try{
            if (wrkMastExecuteService.getWrkMastByJarIdCount(jarSlave.getId())!=0){
            if (wrkMastExecuteService.getWrkMastExecuteByJarIdCount(jarSlave.getId())!=0){
                return false;
            }
            List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusList(jarSlave.getId(), new ArrayList<Integer>() {{
@@ -4847,13 +4854,13 @@
                                && !jarOtherProtocol.isLeftDoor() && jarOtherProtocol.leftDoorOpen==0  && jarOtherProtocol.leftDoorClose==0){
                            if (!jarProtocol.isLeftDoor() && basJarMast.getStatus()==0){
                                //生成开门任务 OpenTheDoor
                                if (!jarWrkMastExecuteGenerateExecute(basJar,basJarMast,basJar.getJarNo(),new int[]{basJar.getEnterSteNo(),basJar.getEnterRgvId(),1,1})){
                                if (!jarWrkMastExecuteGenerateExecute(basJar,basJarMast,basJar.getJarNo(),new int[]{basJar.getEnterSteNo(),basJar.getEnterRgvNo(),1,1})){
                                    log.error("JarWrkMastExecute任务创建===>执行异常===》异常数据:BasJar:"+ JSON.toJSONString(basJar)+";BasJarMast:"+JSON.toJSONString(basJarMast));
                                }
                                return true;
                            } else if (jarProtocol.statusType == JarStatusType.WAITING3 && jarProtocol.isLeftDoor()){
                                //生成入硫化罐任务
                                if (!jarWrkMastExecuteGenerateExecute(basJar,basJarMast,basJar.getJarNo(),new int[]{basJar.getEnterSteNo(),basJar.getEnterRgvId(),5,1})){
                                if (!jarWrkMastExecuteGenerateExecute(basJar,basJarMast,basJar.getJarNo(),new int[]{basJar.getEnterSteNo(),basJar.getEnterRgvNo(),5,1})){
                                    log.error("JarWrkMastExecute任务创建===>执行异常===》异常数据:BasJar:"+ JSON.toJSONString(basJar)+";BasJarMast:"+JSON.toJSONString(basJarMast));
                                }
                                return true;
@@ -4881,7 +4888,7 @@
     */
    public synchronized boolean jarWrkMastExecuteGenerate2(JarSlave jarSlave,Integer sign) {
        try{
            if (wrkMastExecuteService.getWrkMastByJarIdCount(jarSlave.getId())!=0){
            if (wrkMastExecuteService.getWrkMastExecuteByJarIdCount(jarSlave.getId())!=0){
                return false;
            }
            List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusList(jarSlave.getId(), new ArrayList<Integer>() {{
@@ -4928,7 +4935,7 @@
                        && !jarProtocol.isRightDoor() && jarProtocol.isLeftDoor()
                        && jarProtocol.leftDoorOpen==0  && jarProtocol.leftDoorClose==0 && jarProtocol.rightDoorOpen==0  && jarProtocol.rightDoorClose==0){
                    //关进料门
                    if (!jarWrkMastExecuteGenerateExecute(basJar,basJarMastSign,basJar.getJarNo(),new int[]{basJar.getEnterSteNo(),basJar.getEnterRgvId(),2,1})){
                    if (!jarWrkMastExecuteGenerateExecute(basJar,basJarMastSign,basJar.getJarNo(),new int[]{basJar.getEnterSteNo(),basJar.getEnterRgvNo(),2,1})){
                        log.error("JarWrkMastExecute任务创建===>执行异常===》异常数据:BasJar:"+ JSON.toJSONString(basJar)+";BasJarMast:"+JSON.toJSONString(basJarMastSign));
                    }
                    return true;
@@ -4950,7 +4957,7 @@
     */
    public synchronized boolean jarWrkMastExecuteGenerate3(JarSlave jarSlave,Integer sign) {
        try{
            if (wrkMastExecuteService.getWrkMastByJarIdCount(jarSlave.getId())!=0){
            if (wrkMastExecuteService.getWrkMastExecuteByJarIdCount(jarSlave.getId())!=0){
                return false;
            }
            List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusList(jarSlave.getId(), new ArrayList<Integer>() {{
@@ -4997,7 +5004,7 @@
                        && !jarProtocol.isLeftDoor() && !jarProtocol.isRightDoor()
                        && jarProtocol.leftDoorOpen==0  && jarProtocol.leftDoorClose==0 && jarProtocol.rightDoorOpen==0  && jarProtocol.rightDoorClose==0){
                    //开出料门
                    if (!jarWrkMastExecuteGenerateExecute(basJar,basJarMastSign,basJar.getJarNo(),new int[]{basJar.getOutSteId(),basJar.getOutRgvId(),3,1})){
                    if (!jarWrkMastExecuteGenerateExecute(basJar,basJarMastSign,basJar.getJarNo(),new int[]{basJar.getOutSteNo(),basJar.getOutRgvNo(),3,1})){
                        log.error("JarWrkMastExecute任务创建===>执行异常===》异常数据:BasJar:"+ JSON.toJSONString(basJar)+";BasJarMast:"+JSON.toJSONString(basJarMastSign));
                    }
                    return true;
@@ -5019,7 +5026,7 @@
     */
    public synchronized boolean jarWrkMastExecuteGenerate4(JarSlave jarSlave,Integer sign) {
        try{
            if (wrkMastExecuteService.getWrkMastByJarIdCount(jarSlave.getId())!=0){
            if (wrkMastExecuteService.getWrkMastExecuteByJarIdCount(jarSlave.getId())!=0){
                return false;
            }
            List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusList(jarSlave.getId(), new ArrayList<Integer>() {{
@@ -5067,7 +5074,7 @@
                        && !jarProtocol.isLeftDoor() && jarProtocol.isRightDoor()
                        && jarProtocol.leftDoorOpen==0  && jarProtocol.leftDoorClose==0 && jarProtocol.rightDoorOpen==0  && jarProtocol.rightDoorClose==0){
                    //关进料门
                    if (!jarWrkMastExecuteGenerateExecute(basJar,jarMastByJarIdMin,basJar.getJarNo(),new int[]{basJar.getOutSteId(),basJar.getOutRgvId(),3,1})){
                    if (!jarWrkMastExecuteGenerateExecute(basJar,jarMastByJarIdMin,basJar.getJarNo(),new int[]{basJar.getOutSteNo(),basJar.getOutRgvNo(),3,1})){
                        log.error("JarWrkMastExecute任务创建===>执行异常===》异常数据:BasJar:"+ JSON.toJSONString(basJar)+";BasJarMast:"+JSON.toJSONString(jarMastByJarIdMin));
                    }
                    return true;
@@ -5089,7 +5096,7 @@
     */
    public synchronized boolean jarWrkMastExecuteGenerate5(JarSlave jarSlave,Integer sign) {
        try{
            if (wrkMastExecuteService.getWrkMastByJarIdCount(jarSlave.getId())!=0){
            if (wrkMastExecuteService.getWrkMastExecuteByJarIdCount(jarSlave.getId())!=0){
                return false;
            }
            List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusList(jarSlave.getId(), new ArrayList<Integer>() {{
@@ -5136,7 +5143,7 @@
                //门作业  无
                if (jarProtocol.isAutoing() && jarProtocol.jarErr==0){
                    //关进料门
                    if (!jarWrkMastExecuteGenerateExecute(basJar,jarMastByJarIdMin,basJar.getBurial(),new int[]{basJar.getOutSteId(),basJar.getOutRgvId(),3,1})){
                    if (!jarWrkMastExecuteGenerateExecute(basJar,jarMastByJarIdMin,basJar.getBurial(),new int[]{basJar.getOutSteNo(),basJar.getOutRgvNo(),3,1})){
                        log.error("JarWrkMastExecute任务创建===>执行异常===》异常数据:BasJar:"+ JSON.toJSONString(basJar)+";BasJarMast:"+JSON.toJSONString(jarMastByJarIdMin));
                    }
                    return true;
@@ -5154,6 +5161,9 @@
    /**
     *  判断STE小车状态  //完成
     *  1:A面  进料面
     *  2:B面 出料面
     *  3:冷却槽B面 上输送线
     */
    public synchronized boolean jarWrkMastExecuteGenerateSteStatus(Integer steNo,Integer type) {
        try{
@@ -5201,9 +5211,17 @@
        }
        return false;
    }
    /**
     *  判断RGV小车状态  //完成
     */
    /*
     * 判断RGV小车状态  //完成
     * RGV1;//小车无货空闲
     * RGV2;//小车输送线取货到位
     * RGV3;//小车运行中
     * RGV3;//小车运行中
     * RGV4;//小车改左侧货物目标站   取1(左)货物
     * RGV5;//小车改右侧货物目标站   取2(右)货物
     * RGV6;//上位机清除平移车资料
     * */
    public synchronized boolean jarWrkMastExecuteGenerateRgvStatus(Integer rgvNo,Integer rgvPlcId,Integer type) {
        try{
            //检测RGV状态
@@ -5217,6 +5235,7 @@
            if (staProtocolRGV == null) {
                return false;
            }
            return staProtocolRGV.rgvBoolean(type);
        } catch (Exception e){
            log.error("{}号RGV状态判断状态异常,异常原因={}",rgvNo,e.getMessage());
@@ -5242,6 +5261,46 @@
        return false;
    }
    /*
    * JarWrkMastExecute任务创建==>下发
    * Action
    * */
    public synchronized void jarWrkMastExecuteAction(Integer sign) {
        try{
            List<WrkMastExecute> wrkMastExecuteList = wrkMastExecuteService.sselectWrkMastExecuteByTypeAndIoTyper(0, 0);
            for (WrkMastExecute wrkMastExecute : wrkMastExecuteList){
                /*
                * 任务类型 0: 未知
                * 1: 开进料门  2: 关进料门  3: 开出料门  4: 关出料门
                * 5: 入硫化罐
                * 6: 入冷却槽
                * 7: 穿梭车进冷却槽  8: 穿梭车离开冷却槽
                * 9: 出冷却槽
                * 10:A=>B 11:B=>A
                * */
                switch (wrkMastExecute.getIoType()){
                    case 1:
                        jarWrkMastExecuteActionExecute1(wrkMastExecute,sign);
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                    case 7:
                    case 8:
                    case 9:
                    case 10:
                    case 11:
                    case 12:
                    case 13:
                }
            }
        } catch (Exception e){
        }
    }
    /**
     *  JarWrkMastExecute任务完成   //未完成
     */
@@ -5253,24 +5312,131 @@
        }
    }
    /**
     *  JarWrkMastExecute任务创建==>下发 //未完成
     *  开进料门
     *  任务下发
     */
    public synchronized boolean jarWrkMastExecuteActionExecute1(WrkMastExecute wrkMastExecute,Integer sign) {
        try{
            List<WrkMastExecute> wrkMastExecuteByJarNo = wrkMastExecuteService.getWrkMastExecuteByJarNo(wrkMastExecute.getJarId());
            if (wrkMastExecuteByJarNo.size()!=1 || !wrkMastExecuteByJarNo.get(0).getWrkNo().equals(wrkMastExecute.getWrkNo())){
                return false;
            }
            // 获取硫化罐信息
            JarThread jarThread = (JarThread) SlaveConnection.get(SlaveType.Jar, wrkMastExecute.getJarId());
            JarProtocol jarProtocol = jarThread.getJarProtocol();
            if (jarProtocol == null) {
                return false;
            }
            if (jarProtocol.modeType != JarModeType.AUTO){
                return false;
            }
            BasJar basJar = basJarMapper.selectByJarNo(jarProtocol.getJarNo());
            if (Cools.isEmpty(basJar)){
                log.error("{}号硫化罐查询设备档案无信息!!!",jarProtocol.getJarNo());
                return false;
            }
            //判断小车状态
            if (!jarWrkMastExecuteGenerateSteStatus(basJar.getEnterSteNo(),1)){
                return false;
            }
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 1);
            StaProtocol staProtocolRGV = devpThread.getStation().get(basJar.getEnterRgvNo());
            if (staProtocolRGV == null) {
                return false;
            } else {
                staProtocolRGV = staProtocolRGV.clone();
            }
            if (staProtocolRGV == null) {
                return false;
            }
            if (staProtocolRGV.rgvBoolean(1)){
                //门作业  无
                //自动、空闲、  进料们关闭需打开
                if (jarProtocol.isAutoing() && jarProtocol.jarErr==0
                        && jarProtocol.leftDoorOpen==0  && jarProtocol.leftDoorClose==0 && jarProtocol.rightDoorOpen==0  && jarProtocol.rightDoorClose==0){
                    if (SteAndJarUtil.steAndJarNowRow(staProtocolRGV.getNowRow() , jarProtocol.getJarNo())){
                        //移走  == > 2
                    } else {
                        //直接开门
                    }
                }
                return false;
            } else {
                log.error("jarWrkMastExecuteActionExecute1===>执行异常===》RGV不满足条件,等待===》异常数据:BasJar:"+ JSON.toJSONString(basJar.getEnterRgvNo())+";WrkMastExecute:"+JSON.toJSONString(wrkMastExecute));
                return false;
            }
        } catch (Exception e){
            log.error("jarWrkMastExecuteActionExecute1任务执行下发异常==》wrkMastExecute={},异常原因={}",wrkMastExecute,e.getMessage());
        }
        return false;
    }
    /*
     * Rgv  动作
     * */
    public synchronized boolean jarRgvTake(Integer rgvNo,WrkMastExecute wrkMastExecute,Integer type){
    public synchronized boolean jarRgvTake(WrkMastExecute wrkMastExecute,Integer endRow){
        try {
            StaProtocol staProtocol = new StaProtocol();
            staProtocol.setSiteId(wrkMastExecute.getRgvId());
            staProtocol.setEndRow(endRow.shortValue());
            // 下发站点信息
            if (!MessageQueue.offer(SlaveType.Devp, 2, new Task(9, staProtocol))) {
                log.error("平衡车Rgv命令下发失败,堆垛机号={},任务数据={},下发数据={}", wrkMastExecute.getRgvId(), JSON.toJSON(wrkMastExecute), JSON.toJSON(staProtocol));
                return false;
            }
            return true;
        }catch (Exception e){
            log.error("平衡车Rgv命令下发失败,Rgv号={},任务数据={},endRow={}", wrkMastExecute.getSteId(), JSON.toJSON(wrkMastExecute), JSON.toJSON(endRow));
        }
        return false;
    }
    /*
     * Ste  动作
     * */
    public synchronized boolean jarSteTake(Integer steNo,WrkMastExecute wrkMastExecute,Integer type){
    public synchronized boolean jarSteTake(WrkMastExecute wrkMastExecute,Integer startLoad,Integer endLoad,SteTaskModeType steTaskModeType,boolean complete){
        try {
            SteCommand steCommand = new SteCommand();
            steCommand.setSteNo(wrkMastExecute.getSteId());
            steCommand.setStartLoad(startLoad);
            steCommand.setEndLoad(endLoad);
            steCommand.setTaskModeType(steTaskModeType);
            steCommand.setComplete(complete);
            if (!MessageQueue.offer(SlaveType.Ste, steCommand.getSteNo(), new Task(2, steCommand))) {
                log.error("穿梭车Ste命令下发失败,堆垛机号={},任务数据={},下发数据={},complete={}", steCommand.getSteNo(), JSON.toJSON(wrkMastExecute), JSON.toJSON(steCommand),complete);
                return false;
            }
            return true;
        }catch (Exception e){
            log.error("穿梭车Ste命令下发失败,堆垛机号={},任务数据={},complete={}", wrkMastExecute.getSteId(), JSON.toJSON(wrkMastExecute), JSON.toJSON(complete));
        }
        return false;
    }
    /*
     * Jar  动作
     * */
    public synchronized boolean jarDoorTake(Integer jarNo,WrkMastExecute wrkMastExecute,Integer type){
    public synchronized boolean jarDoorTake(WrkMastExecute wrkMastExecute,JarTaskModeType jarTaskModeType){
        try{
            JarCommand jarCommand = new JarCommand();
            jarCommand.setJarNo(wrkMastExecute.getJarId());
            jarCommand.setTaskModeType(jarTaskModeType);
            if (!MessageQueue.offer(SlaveType.Jar, jarCommand.getJarNo(), new Task(2, jarCommand))) {
                log.error("硫化罐Jar命令下发失败,堆垛机号={},任务数据={},下发数据={}", jarCommand.getJarNo(), JSON.toJSON(wrkMastExecute), JSON.toJSON(jarCommand));
                return false;
            }
            return true;
        }catch (Exception e){
            log.error("硫化罐Jar命令下发失败,堆垛机号={},任务数据={},下发数据={}", wrkMastExecute.getJarId(), JSON.toJSON(wrkMastExecute), JSON.toJSON(jarTaskModeType));
        }
        return false;
    }