#
Junjie
6 小时以前 f5e49b2c04137fdc88c453cbe5d190cf7daab079
src/main/java/com/zy/common/service/CommonService.java
@@ -1,6 +1,7 @@
package com.zy.common.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
@@ -8,11 +9,13 @@
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
import com.zy.common.entity.FindCrnNoResult;
import com.zy.common.model.NavigateNode;
import com.zy.common.utils.NavigateUtils;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
import com.zy.core.enums.WrkIoType;
import com.zy.core.enums.WrkStsType;
import com.zy.core.model.StationObjModel;
@@ -20,6 +23,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -36,9 +40,9 @@
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private NavigateUtils navigateUtils;
    private BasDualCrnpService basDualCrnpService;
    @Autowired
    private CommonService commonService;
    private NavigateUtils navigateUtils;
    @Autowired
    private RedisUtil redisUtil;
@@ -139,19 +143,20 @@
            ioPri = param.getTaskPri().doubleValue();
        }
        Integer sourceCrnNo = commonService.findCrnNoByLocNo(sourceLocMast.getLocNo());
        if (sourceCrnNo == null) {
        FindCrnNoResult sourceCrnResult = this.findCrnNoByLocNo(sourceLocMast.getLocNo());
        if (sourceCrnResult == null) {
            throw new CoolException("未找到对应堆垛机");
        }
        Integer crnNo = commonService.findCrnNoByLocNo(locMast.getLocNo());
        if (crnNo == null) {
        FindCrnNoResult targetCrnResult = this.findCrnNoByLocNo(locMast.getLocNo());
        if (targetCrnResult == null) {
            throw new CoolException("未找到对应堆垛机");
        }
        if (!sourceCrnNo.equals(crnNo)) {
        if (!sourceCrnResult.getCrnNo().equals(targetCrnResult.getCrnNo())) {
            throw new CoolException("源库位和目标库位不在同一巷道");
        }
        Integer crnNo = targetCrnResult.getCrnNo();
        // 获取工作号
        int workNo = getWorkNo(WrkIoType.LOC_MOVE.id);
@@ -166,6 +171,7 @@
        wrkMast.setLocNo(param.getLocNo()); // 目标库位
        wrkMast.setCrnNo(crnNo);
        wrkMast.setWmsWrkNo(param.getTaskNo());
        wrkMast.setBarcode(sourceLocMast.getBarcode());
        wrkMast.setAppeTime(now);
        wrkMast.setModiTime(now);
        boolean res = wrkMastService.insert(wrkMast);
@@ -186,7 +192,7 @@
    }
    //入库任务
    public boolean createInTask(CreateInTaskParam param) {
    public WrkMast createInTask(CreateInTaskParam param) {
        Date now = new Date();
        LocMast locMast = locMastService.queryByLoc(param.getLocNo());
        if (null == locMast) {
@@ -202,10 +208,11 @@
            ioPri = param.getTaskPri().doubleValue();
        }
        Integer crnNo = commonService.findCrnNoByLocNo(locMast.getLocNo());
        if (crnNo == null) {
        FindCrnNoResult findCrnResult = this.findCrnNoByLocNo(locMast.getLocNo());
        if (findCrnResult == null) {
            throw new CoolException("未找到对应堆垛机");
        }
        Integer crnNo = findCrnResult.getCrnNo();
        // 获取工作号
        int workNo = getWorkNo(WrkIoType.IN.id);
@@ -221,9 +228,20 @@
        wrkMast.setStaNo(param.getStaNo());//目标站
        wrkMast.setWmsWrkNo(param.getTaskNo());
        wrkMast.setBarcode(param.getBarcode());
        wrkMast.setCrnNo(crnNo);
        wrkMast.setAppeTime(now);
        wrkMast.setModiTime(now);
        if (findCrnResult.getCrnType().equals(SlaveType.Crn)) {
            wrkMast.setCrnNo(findCrnResult.getCrnNo());
            //缓存记录当前命令堆垛机编号
            redisUtil.set(RedisKeyType.CURRENT_CIRCLE_TASK_CRN_NO.key, crnNo, 60 * 60 * 24);
        } else if (findCrnResult.getCrnType().equals(SlaveType.DualCrn)) {
            wrkMast.setDualCrnNo(findCrnResult.getCrnNo());
        }else {
            throw new CoolException("未知设备类型");
        }
        boolean res = wrkMastService.insert(wrkMast);
        if (!res) {
            News.error("入库任务 --- 保存工作档失败!");
@@ -233,10 +251,7 @@
        locMast.setLocSts("S");
        locMast.setModiTime(new Date());
        locMastService.updateById(locMast);
        //缓存记录当前命令堆垛机编号
        redisUtil.set(RedisKeyType.CURRENT_CIRCLE_TASK_CRN_NO.key, crnNo, 60 * 60 * 24);
        return true;
        return wrkMast;
    }
    //出库任务
@@ -256,12 +271,13 @@
            ioPri = param.getTaskPri().doubleValue();
        }
        Integer crnNo = commonService.findCrnNoByLocNo(locMast.getLocNo());
        if (crnNo == null) {
        FindCrnNoResult findCrnResult = this.findCrnNoByLocNo(locMast.getLocNo());
        if (findCrnResult == null) {
            throw new CoolException("未找到对应堆垛机");
        }
        Integer crnNo = findCrnResult.getCrnNo();
        Integer sourceStationId = commonService.findOutStationId(crnNo, param.getStaNo());
        Integer sourceStationId = this.findOutStationId(findCrnResult, param.getStaNo());
        if (sourceStationId == null) {
            throw new CoolException("未找到输送目标站点可走行路径");
        }
@@ -280,9 +296,45 @@
        wrkMast.setStaNo(param.getStaNo());//目标站
        wrkMast.setWmsWrkNo(param.getTaskNo());
        wrkMast.setBarcode(locMast.getBarcode());
        wrkMast.setCrnNo(crnNo);
        wrkMast.setAppeTime(now);
        wrkMast.setModiTime(now);
        if (findCrnResult.getCrnType().equals(SlaveType.Crn)) {
            BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
            if(basCrnp == null) {
                throw new CoolException("未找到对应堆垛机数据");
            }
            List<WrkMast> outWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .eq("crn_no", crnNo)
                    .eq("io_type", WrkIoType.OUT.id)
            );
            // 检查是否超过最大出库任务数
            if(outWrkMasts.size() >= basCrnp.getMaxOutTask()){
                News.info("堆垛机:{} 已达最大出库任务数,当前任务数:{}", basCrnp.getCrnNo(), outWrkMasts.size());
                throw new CoolException("堆垛机:" + basCrnp.getCrnNo() + "已达最大出库任务数,当前任务数:" + outWrkMasts.size());
            }
            wrkMast.setCrnNo(findCrnResult.getCrnNo());
        } else if (findCrnResult.getCrnType().equals(SlaveType.DualCrn)) {
            BasDualCrnp basDualCrnp = basDualCrnpService.selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", crnNo));
            if(basDualCrnp == null) {
                throw new CoolException("未找到对应双工位堆垛机数据");
            }
            List<WrkMast> outWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .eq("dual_crn_no", crnNo)
                    .eq("io_type", WrkIoType.OUT.id)
            );
            // 检查是否超过最大出库任务数
            if(outWrkMasts.size() >= basDualCrnp.getMaxOutTask()){
                News.info("双工位堆垛机:{} 已达最大出库任务数,当前任务数:{}", basDualCrnp.getCrnNo(), outWrkMasts.size());
                throw new CoolException("双工位堆垛机:" + basDualCrnp.getCrnNo() + "已达最大出库任务数,当前任务数:" + outWrkMasts.size());
            }
            wrkMast.setDualCrnNo(findCrnResult.getCrnNo());
        }else {
            throw new CoolException("未知设备类型");
        }
        boolean res = wrkMastService.insert(wrkMast);
        if (!res) {
            News.error("出库任务 --- 保存工作档失败!");
@@ -292,38 +344,59 @@
        locMast.setLocSts("R");
        locMast.setModiTime(new Date());
        locMastService.updateById(locMast);
        return true;
    }
    public Integer findCrnNoByLocNo(String locNo) {
    public FindCrnNoResult findCrnNoByLocNo(String locNo) {
        List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
        for (BasCrnp basCrnp : basCrnps) {
            String controlRows = basCrnp.getControlRows();
            if (Cools.isEmpty(controlRows)) {
                continue;
            List<List<Integer>> rowList = basCrnp.getControlRows$();
            for (List<Integer> rows : rowList) {
                if(rows.contains(Utils.getRow(locNo))) {
                    FindCrnNoResult result = new FindCrnNoResult();
                    result.setCrnNo(basCrnp.getCrnNo());
                    result.setCrnType(SlaveType.Crn);
                    return result;
                }
            }
        }
            List<Integer> rowList = JSON.parseArray(controlRows, Integer.class);
            if(rowList.contains(Utils.getRow(locNo))) {
                return basCrnp.getCrnNo();
        List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(new EntityWrapper<>());
        for (BasDualCrnp basDualCrnp : basDualCrnps) {
            List<List<Integer>> rowList = basDualCrnp.getControlRows$();
            for (List<Integer> rows : rowList) {
                if(rows.contains(Utils.getRow(locNo))) {
                    FindCrnNoResult result = new FindCrnNoResult();
                    result.setCrnNo(basDualCrnp.getCrnNo());
                    result.setCrnType(SlaveType.DualCrn);
                    return result;
                }
            }
        }
        return null;
    }
    public Integer findInStationId(Integer crnNo, Integer sourceStationId) {
        BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
        if(basCrnp == null) {
            return null;
    public Integer findInStationId(FindCrnNoResult findCrnNoResult, Integer sourceStationId) {
        List<StationObjModel> stationList = new ArrayList<>();
        Integer crnNo = findCrnNoResult.getCrnNo();
        if (findCrnNoResult.getCrnType().equals(SlaveType.Crn)) {
            BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
            if(basCrnp == null) {
                return null;
            }
            stationList = basCrnp.getInStationList$();
        } else if (findCrnNoResult.getCrnType().equals(SlaveType.DualCrn)) {
            BasDualCrnp basDualCrnp = basDualCrnpService.selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", crnNo));
            if(basDualCrnp == null) {
                return null;
            }
            stationList = basDualCrnp.getInStationList$();
        }
        Integer targetStationId = null;
        List<StationObjModel> stationList = basCrnp.getInStationList$();
        for (StationObjModel stationObjModel : stationList) {
            try {
                String startLev = String.valueOf(sourceStationId).substring(0, 1);
                List<NavigateNode> navigateNodes = navigateUtils.calcByStationId(Integer.parseInt(startLev), sourceStationId, stationObjModel.getStationId());
                List<NavigateNode> navigateNodes = navigateUtils.calcByStationId(sourceStationId, stationObjModel.getStationId());
                if(navigateNodes != null) {
                    targetStationId = stationObjModel.getStationId();
                    break;
@@ -335,18 +408,27 @@
        return targetStationId;
    }
    public Integer findOutStationId(Integer crnNo, Integer targetStationId) {
        BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
        if(basCrnp == null) {
            return null;
    public Integer findOutStationId(FindCrnNoResult findCrnNoResult, Integer targetStationId) {
        List<StationObjModel> stationList = new ArrayList<>();
        Integer crnNo = findCrnNoResult.getCrnNo();
        if (findCrnNoResult.getCrnType().equals(SlaveType.Crn)) {
            BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo));
            if(basCrnp == null) {
                return null;
            }
            stationList = basCrnp.getOutStationList$();
        } else if (findCrnNoResult.getCrnType().equals(SlaveType.DualCrn)) {
            BasDualCrnp basDualCrnp = basDualCrnpService.selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", crnNo));
            if(basDualCrnp == null) {
                return null;
            }
            stationList = basDualCrnp.getOutStationList$();
        }
        Integer finalSourceStationId = null;
        List<StationObjModel> stationList = basCrnp.getOutStationList$();
        for (StationObjModel stationObjModel : stationList) {
            try {
                String startLev = String.valueOf(targetStationId).substring(0, 1);
                List<NavigateNode> navigateNodes = navigateUtils.calcByStationId(Integer.parseInt(startLev), stationObjModel.getStationId(), targetStationId);
                List<NavigateNode> navigateNodes = navigateUtils.calcByStationId(stationObjModel.getStationId(), targetStationId);
                if(navigateNodes != null) {
                    finalSourceStationId = stationObjModel.getStationId();
                    break;