pang.jiabao
2024-07-10 50e5164f1dc957eba4494bda01171afdc86d5782
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -4,21 +4,18 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.R;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.TaskOverToWms;
import com.zy.asrs.entity.param.WMSAndAGVInterfaceParam;
import com.zy.asrs.entity.param.taskCreateParam;
import com.zy.asrs.mapper.*;
import com.zy.asrs.mapper.BasCrnErrorMapper;
import com.zy.asrs.mapper.StaDescMapper;
import com.zy.asrs.mapper.TaskWrkMapper;
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.CommandUtils;
import com.zy.asrs.utils.PostMesDataUtils;
import com.zy.asrs.utils.Utils;
import com.zy.common.service.CommonService;
import com.zy.common.utils.HttpHandler;
import com.zy.core.CrnThread;
import com.zy.core.DevpThread;
@@ -34,7 +31,6 @@
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;
@@ -91,6 +87,13 @@
    @Autowired
    private ApiLogService apiLogService;
//
//    // 入库站点号对应的堆垛机
//    private static final Map<Integer,Integer> staNoToCrnMap = new HashMap<Integer,Integer>(){{
//        put(103,1); put(205,1); put(107,2); put(211,2);
//        put(111,3); put(217,3); put(115,4); put(223,4);
//        put(119,5); put(229,5); put(123,6); put(235,6);
//    }};
    @Value("${wms.url}")
    private String wmsUrl;
@@ -170,18 +173,36 @@
                        }
                        continue;
                    }
//                // 入库站点对应堆垛机,判断堆垛机状态,不是自动,先弹窗,然后continue
//                if (getCrnByStaNo(inSta.getStaNo())) {
//                    continue;
//                }
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
                if (barcodeThread == null) {
                    continue;
                }
                String barcode = barcodeThread.getBarcode();
                staProtocol.setBarcode(barcode);
                if(Cools.isEmpty(barcode) || barcode.equals("00000000")) {
                    continue;
                }
                TaskWrk taskWrk = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode));
                if (!Cools.isEmpty(taskWrk) && staProtocol.isLoading()){
                    // 写组拓信号
                    MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(4, staProtocol));
//                    Thread.sleep(500);
//                    continue;
                }
                // 判断是否满足入库条件
                if (staProtocol.isAutoing() && staProtocol.isLoading()
                        && staProtocol.isInEnable()
                        && !staProtocol.isEmptyMk() && (workNo >= 0)
                        && staProtocol.isPakMk()) {
                    // 获取条码扫描仪信息
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
                    if (barcodeThread == null) {
                        continue;
                    }
                    String barcode = barcodeThread.getBarcode();
                    staProtocol.setBarcode(barcode);
                    if(!Cools.isEmpty(barcode)) {
                        StaDescService staDescService = SpringUtils.getBean(StaDescService.class);
@@ -189,14 +210,18 @@
                        Map<String, Object> map = new HashMap<>();
                        map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2");
                        TaskWrk taskWrk = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode));
                        if (Cools.isEmpty(taskWrk)){
                            continue;
                        }
                        //StaDesc staDesc1 = staDescService.selectOne(new EntityWrapper<StaDesc>().eq("stn_no",inSta.getBackSta()));
                        if (taskWrk.getTargetPoint() != null && taskWrk.getStartPoint() != null){
                        boolean sign = true;
                        if (inSta.getBarcode() == 7 || inSta.getBarcode() == 8){
                        }else {
                            if (taskWrk.getCrnNo() != inSta.getBarcode()){
                                sign = false;
                            }
                        }
                        if (taskWrk.getTargetPoint() != null && taskWrk.getStartPoint() != null && sign){
                            if ( taskWrk.getWrkNo() != null && taskWrk.getWrkNo().shortValue() == workNo ){
                                continue;
                            }
@@ -261,6 +286,11 @@
                                taskWrk.setOriginTargetPoint(getWmsDto.getTargetLocationCode());
                                taskWrk.setTargetPoint(Utils.getWcsLocNo(getWmsDto.getTargetLocationCode()));
                                taskWrk.setStartPoint(String.valueOf(inSta.getBackSta()));
                                if (inSta.getBarcode() == 7 || inSta.getBarcode() == 8){
                                }else {
                                    taskWrk.setCrnNo(inSta.getBarcode());
                                }
                                if (!taskWrkService.updateById(taskWrk)){
                                    log.error("保存wms库位号失败");
                                }
@@ -278,6 +308,12 @@
            }
        }
    }
//
//    private boolean getCrnByStaNo(Integer staNo) {
//        int crn = staNoToCrnMap.get(staNo);
//        BasCrnp crnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crn));
//        return crnp.getCrnSts() == 0;
//    }
    /**
@@ -344,6 +380,8 @@
                                } else if (taskWrk.getIoType() == 2) {
                                    taskWrk.setWrkSts(14);
                                }
                                Date now = new Date();
                                taskWrk.setCompleteTime(now);
                                if (!taskWrkService.updateById(taskWrk)){
                                    log.error(taskWrk.getTaskNo()+ " 堆垛机任务完成,改变任务状态失败");
                                }
@@ -451,16 +489,17 @@
                log.error("进入修改工作档流程");
                Date now = new Date();
                taskWrk.setWrkSts(3);
                taskWrk.setExecuteTime(now);
                taskWrk.setModiTime(now);
                if (taskWrkMapper.updateById(taskWrk) == 0) {
                    log.error("修改工作档状态 2.设备上走 => 3.吊车入库中 失败!!,工作号={}", taskWrk.getWrkNo());
                }
                TaskWrk taskWrk2 = taskWrkService.selectByWrkNo(staProtocol.getWorkNo().intValue());
                TaskWrk taskWrk2 = taskWrkService.selectByWrkNo(taskWrk.getWrkNo());
                if (taskWrk2.getWrkSts() != 3){
                    continue;
                }
                log.error("进入修改工作档流程完成,taskWrk=", JSON.toJSONString(taskWrk));
                log.error("进入修改工作档流程完成,taskWrk=", taskWrk.getWrkNo());
                //取出命令
@@ -573,6 +612,18 @@
                        // 双深库位且浅库位有货,则需先对浅库位进行库位移转
                        if (Utils.isDeepLoc(slaveProperties, taskWrk.getStartPoint())) {
                            // 获取浅库位,状态为S直接出,状态为R,则找到这个库位的工作档,提升优先级先出
                            String shallowLoc = Utils.getShallowLoc(slaveProperties, taskWrk.getStartPoint());
                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", shallowLoc));
                            if (locMast.getLocSts().equals("R")) {
                                List<TaskWrk> wrkMastList = taskWrkMapper.selectList(new EntityWrapper<TaskWrk>().eq("source_loc_no", locMast.getLocNo()));
                                if (!wrkMastList.isEmpty()) {
                                    TaskWrk wrkMast = wrkMastList.get(0);
                                    wrkMast.setIoPri(99);
                                    taskWrkMapper.updateById(wrkMast);
                                    continue;
                                }
                            }
                            taskWrkMapper.selectPakOutIoType(taskWrk.getCrnNo());
@@ -629,6 +680,7 @@
                            // 修改工作档状态 11.生成出库ID => 12.吊车出库中
                            Date now = new Date();
                            taskWrk.setWrkSts(12);
                            taskWrk.setExecuteTime(now);
                            taskWrk.setModiTime(now);
                            if (taskWrkMapper.updateById(taskWrk) == 0) {
                                log.error("修改工作档状态 11.生成出库ID => 12.吊车出库中 失败!!,工作号={}", taskWrk.getWrkNo());
@@ -792,27 +844,27 @@
                }
                //获取指令ID
                Integer commandId = crnProtocol.getCommandId();
                CommandInfo commandInfo = new CommandInfo();
                if (Cools.isEmpty(commandId)){
                    commandInfo = commandInfoService.selectOne(new EntityWrapper<CommandInfo>()
                            .eq("wrk_no",crnProtocol.getTaskNo())
                            .eq("device","Crn"));
                }else {
                    commandInfo = commandInfoService.selectById(commandId);
                }
//                Integer commandId = crnProtocol.getCommandId();
//                CommandInfo commandInfo = new CommandInfo();
//                if (Cools.isEmpty(commandId)){
//                    commandInfo = commandInfoService.selectOne(new EntityWrapper<CommandInfo>()
//                            .eq("wrk_no",crnProtocol.getTaskNo())
//                            .eq("device","Crn"));
//                }else {
//                    commandInfo = commandInfoService.selectById(commandId);
//                }
                if (commandInfo == null) {
                    //指令不存在
                    continue;
                }
                if (commandInfo.getCommandStatus() == 3){
                    continue;
                }
                commandInfo.setCommandStatus(CommandStatusType.COMPLETE.id);//指令完成
                commandInfo.setCompleteTime(new Date());//指令完成时间
                if (commandInfoService.updateById(commandInfo)) {//修改成功后复位堆垛机
//                if (commandInfo == null) {
//                    //指令不存在
//                    continue;
//                }
//                if (commandInfo.getCommandStatus() == 3){
//                    continue;
//                }
//                commandInfo.setCommandStatus(CommandStatusType.COMPLETE.id);//指令完成
//                commandInfo.setCompleteTime(new Date());//指令完成时间
//                if (commandInfoService.updateById(commandInfo)) {//修改成功后复位堆垛机
                    // 堆垛机复位
                    crnThread.setResetFlag(true);
                    if (taskWrk.getIoType() == 1 || taskWrk.getIoType() == 3){
@@ -820,10 +872,12 @@
                    } else if (taskWrk.getIoType() == 2) {
                        taskWrk.setWrkSts(14);
                    }
                    Date now = new Date();
                    taskWrk.setCompleteTime(now);
                    if (!taskWrkService.updateById(taskWrk)){
                        log.error(taskWrk.getTaskNo()+ " 堆垛机任务完成,改变任务状态失败");
                    }
                }
//                }
            }
        }
    }
@@ -1015,24 +1069,24 @@
    public synchronized void autoCompleteTask() {
        List<TaskWrk> taskWrks = taskWrkMapper.selectWorkingTask();
        for (TaskWrk taskWrk : taskWrks) {
            //获取命令集合
            List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskWrk.getTaskNo());
            if (taskWrk.getCommandStep() < commandInfos.size()) {
                continue;//当前步序没有到达最后一条命令
            }
            //判断末端命令是否执行完成
            if (!commandInfos.isEmpty()){
                CommandInfo commandInfo = commandInfos.get(commandInfos.size() - 1);
                if (commandInfo.getCommandStatus() != CommandStatusType.COMPLETE.id) {
                    continue;//指令未完成
                }
            }
//            //获取命令集合
//            List<CommandInfo> commandInfos = commandInfoService.selectByTaskNo(taskWrk.getTaskNo());
//            if (taskWrk.getCommandStep() < commandInfos.size()) {
//                continue;//当前步序没有到达最后一条命令
//            }
//
//            //判断末端命令是否执行完成
//            if (!commandInfos.isEmpty()){
//                CommandInfo commandInfo = commandInfos.get(commandInfos.size() - 1);
//                if (commandInfo.getCommandStatus() != CommandStatusType.COMPLETE.id) {
//                    continue;//指令未完成
//                }
//            }
            Date now = new Date();
            //指令已完成,更新任务
            if (taskWrk.getIoType() == 1) {
            if (taskWrk.getIoType() == 1 && taskWrk.getWrkSts() == 5) {
                //入库任务
//                taskWrk.setWrkSts(4);//3.吊车入库中 => 4.入库完成
                taskWrk.setStatus(TaskStatusType.OVER.id);
@@ -1046,7 +1100,7 @@
                locMast.setModiTime(now);
                locMast.setModiUser(9999L);
                locMastService.updateById(locMast);
            } else if (taskWrk.getIoType() == 2) {
            } else if (taskWrk.getIoType() == 2 && taskWrk.getWrkSts() == 15) {
                //出库任务
//                taskWrk.setWrkSts(14);//12.吊车出库中 => 14.出库完成
                taskWrk.setStatus(TaskStatusType.OVER.id);
@@ -1060,7 +1114,7 @@
                locMast.setModiTime(now);
                locMast.setModiUser(9999L);
                locMastService.updateById(locMast);
            } else if (taskWrk.getIoType() == 3) {
            } else if (taskWrk.getIoType() == 3 && taskWrk.getWrkSts() == 5) {
                //更新起始库位状态
                LocMast locMastStart = locMastService.selectByLocNo(taskWrk.getStartPoint());