自动化立体仓库 - WMS系统
#
luxiaotao1123
2021-01-21 37a846870b5f66637010bcc7f636069793472679
#
5个文件已修改
255 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/service/BasCrnpService.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/BasCrnpServiceImpl.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/model/Shelves.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/service/CommonService.java 176 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/BasCrnpService.java
@@ -5,6 +5,8 @@
public interface BasCrnpService extends IService<BasCrnp> {
    BasCrnp checkSiteStatus(Integer crnId);
    BasCrnp checkSiteStatus(Integer crnId, boolean pakin);
    boolean checkSiteError(Integer crnNo, boolean pakin);
}
src/main/java/com/zy/asrs/service/impl/BasCrnpServiceImpl.java
@@ -3,26 +3,68 @@
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasCrnError;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.mapper.BasCrnErrorMapper;
import com.zy.asrs.mapper.BasCrnpMapper;
import com.zy.asrs.service.BasCrnpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service("basCrnpService")
public class BasCrnpServiceImpl extends ServiceImpl<BasCrnpMapper, BasCrnp> implements BasCrnpService {
    @Autowired
    private BasCrnErrorMapper basCrnErrorMapper;
    @Override
    public BasCrnp checkSiteStatus(Integer crnId) {
    public BasCrnp checkSiteStatus(Integer crnId, boolean pakin) {
        BasCrnp crnp = this.selectById(crnId);
        if (Cools.isEmpty(crnp)) {
            throw new CoolException(crnId + "号堆垛机不存在");
        }
        if ("N".equals(crnp.getInEnable())) {
            throw new CoolException(crnId + "堆垛机不可入");
        if (crnp.getCrnErr() != null && crnp.getCrnErr() > 0) {
            BasCrnError basCrnError = basCrnErrorMapper.selectById(crnp.getCrnErr());
            throw new CoolException(crnId + "号堆垛机出现"+ ( basCrnError == null? crnp.getCrnErr() : basCrnError.getErrName()) +"异常,无法作业!");
        }
        if ("N".equals(crnp.getOutEnable())) {
            throw new CoolException(crnId + "堆垛机不可出");
        if (pakin) {
            if ("N".equals(crnp.getInEnable())) {
                throw new CoolException(crnId + "堆垛机不可入");
            }
        } else {
            if ("N".equals(crnp.getOutEnable())) {
                throw new CoolException(crnId + "堆垛机不可出");
            }
        }
        return crnp;
    }
    @Override
    public boolean checkSiteError(Integer crnNo, boolean pakin) {
        BasCrnp crnp = this.selectById(crnNo);
        if (Cools.isEmpty(crnp)) {
            log.error("{}号堆垛机不存在", crnNo);
            return false;
        }
        if (crnp.getCrnErr() != null && crnp.getCrnErr() > 0) {
            BasCrnError basCrnError = basCrnErrorMapper.selectById(crnp.getCrnErr());
            log.error("{}号堆垛机出现{}异常,无法作业!", crnNo, basCrnError == null? crnp.getCrnErr() : basCrnError.getErrName());
            return false;
        }
        if (pakin) {
            if ("N".equals(crnp.getInEnable())) {
                log.error("{}号堆垛机不可入", crnNo);
                return false;
            }
        } else {
            if ("N".equals(crnp.getOutEnable())) {
                log.error("{}号堆垛机不可出", crnNo);
                return false;
            }
        }
        return true;
    }
}
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -72,7 +72,7 @@
        int workNo = commonService.getWorkNo(DEFAULT_WORK_NO_TYPE);
        // 检索库位
        List<String> matNos = param.getList().stream().map(FullStoreParam.MatCodeStore::getMatNo).distinct().collect(Collectors.toList());
        StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 1, param.getDevpNo(), matNos);
        StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 1, param.getDevpNo(), matNos, 0);
        // 生成工作档
        WrkMast wrkMast = new WrkMast();
        wrkMast.setWrkNo(workNo);
@@ -254,7 +254,7 @@
        // 生成工作号
        int workNo = commonService.getWorkNo(DEFAULT_WORK_NO_TYPE);
        // 检索库位
        StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 10, devpNo, null);
        StartupDto dto = commonService.getLocNo(DEFAULT_ROW_NO_TYPE, 10, devpNo, null, 0);
        // 生成工作档
        WrkMast wrkMast = new WrkMast();
        wrkMast.setWrkNo(workNo);
src/main/java/com/zy/common/model/Shelves.java
@@ -1,5 +1,8 @@
package com.zy.common.model;
import com.alibaba.fastjson.JSON;
import com.core.exception.CoolException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -11,13 +14,13 @@
public class Shelves {
    // 货架排数量
    private final int size;
    public final int size;
    // 货架组数量
    private final int group;
    public final int group;
    // 偏移量[default:0]
    private final int offset;
    public final int offset;
    // 货架实例节点集合
    public List<List<Integer>> nodes;
@@ -97,6 +100,16 @@
        return -1;
    }
    public Integer getCrnNo(Integer curRow) {
        for (List<Integer> node : nodes){
            if (node.contains(curRow)) {
                return nodes.indexOf(node) + 1;
            }
        }
        throw new CoolException("货排检索系统报错, node:" + JSON.toJSONString(nodes) + ", curRow:" + curRow);
    }
    public static void main(String[] args) throws InterruptedException {
        Shelves shelves = new Shelves(8,2);
src/main/java/com/zy/common/service/CommonService.java
@@ -9,6 +9,7 @@
import com.zy.asrs.service.*;
import com.zy.common.model.Shelves;
import com.zy.common.model.StartupDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -18,6 +19,7 @@
 * 货架核心功能
 * Created by vincent on 2020/6/11
 */
@Slf4j
@Service
public class CommonService {
@@ -88,11 +90,13 @@
     * @param matNos 产品号集合
     * @return locNo 检索到的库位号
     */
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos) {
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, int times) {
        if (sourceStaNo == 3) {
            whsType = 1;
        } else if (sourceStaNo == 7) {
            whsType = 2;
        } else if (sourceStaNo == 19) {
            whsType = 3;
        } else {
            throw new CoolException("无效入库站");
        }
@@ -101,105 +105,89 @@
        if (Cools.isEmpty(rowLastno)) {
            throw new CoolException("数据异常,请联系管理员");
        }
        if (whsType == 1 || whsType == 2){
            int curRow = rowLastno.getCurrentRow();
            int sRow = rowLastno.getsRow();
            int eRow = rowLastno.geteRow();
            int crn_qty = rowLastno.getCrnQty();
            int rowCount = eRow - sRow + 1;
            // 目标堆垛机号
            int crnNo = 0;
            // 目标库位
            LocMast locMast = null;
        int curRow = rowLastno.getCurrentRow();
        int sRow = rowLastno.getsRow();
        int eRow = rowLastno.geteRow();
        int crn_qty = rowLastno.getCrnQty();
        int rowCount = eRow - sRow + 1;
        // 目标堆垛机号
        int crnNo = 0;
        // 目标库位
        LocMast locMast = null;
            // 同一天同规格货物靠近摆法规则 todo:luxiaotao
//            if (!Cools.isEmpty(matNos)) {
//                List<String> locNos = locDetlService.getSameDetlToday(matNos.get(0));
//                for (String locNo : locNos) {
//                    // 获取排
//                    int row = Integer.parseInt(locNo.substring(0, 2));
//                    // 判断是否为深库位
//                    double remainder = Arith.remainder(row, rowCount / crn_qty);
//                    int targetRow;
//                    if (remainder == 1) {
//                        // 得到当前库位的外围库位
//                        targetRow =  row + 1;
//                    } else if (remainder == 0) {
//                        // 得到当前库位的内围库位
//                        targetRow =  row - 1;
//                    } else {
//                        continue;
//                    }
//                    String targetLocNo = zerofill(String.valueOf(targetRow), 2)+locNo.substring(2);
//                    // 检测目标库位是否为空库位
//                    LocMast targetLocMast = locMastService.selectById(targetLocNo);
//                    if (targetLocMast != null && targetLocMast.getLocSts().equals("O")) {
//                        locMast = targetLocMast;
//                        crnNo = locMast.getCrnNo();
//                        break;
//                    }
//                }
//            }
            // 如果没有相近产品,则按规则轮询货架
            if (null == locMast) {
                // 获取目标站所在货架排号  todo:luxiaotao
                if (curRow == sRow) {
                    curRow = eRow;
                } else {
                    curRow = sRow;
                }
                crnNo = whsType;
//                Shelves shelves = new Shelves(rowCount, crn_qty);
//                curRow = shelves.start(curRow);
//                if (curRow < 0) {
//                    throw new CoolException("检索库位失败,请联系管理员");
//                }
//                for (List<Integer> node : shelves.nodes){
//                    if (node.contains(curRow)) {
//                        crnNo = shelves.nodes.indexOf(node) + 1;
//                        break;
//                    }
//                }
            }
            basCrnpService.checkSiteStatus(crnNo);
            // 获取目标站
            Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                    .eq("type_no", staDescId)
                    .eq("stn_no", sourceStaNo)
                    .eq("crn_no", crnNo);
            StaDesc staDesc = staDescService.selectOne(wrapper);
            if (Cools.isEmpty(staDesc)) {
                throw new CoolException("入库路径不存在");
            }
            BasDevp staNo = basDevpService.selectById(staDesc.getCrnStn());
            int inQty = staNo.getInQty()==null?0:staNo.getInQty();
            if (staNo.getAutoing().equals("Y") && inQty<2) {
                // 查找库位
                if (locMast == null) {
                    locMast = locMastService.queryFreeLocMast(curRow);
                }
                if (Cools.isEmpty(locMast)) {
                    throw new CoolException("没有空库位");
                }
                String locNo = locMast.getLocNo();
                // 更新库位排号
                rowLastno.setCurrentRow(curRow);
                rowLastnoService.updateById(rowLastno);
                // 返回dto
                startupDto.setCrnNo(crnNo);
                startupDto.setSourceStaNo(sourceStaNo);
                startupDto.setStaNo(staNo.getDevNo());
                startupDto.setLocNo(locNo);
        // 按规则轮询货架
        if (whsType == 1 || whsType == 2) {
            if (curRow == sRow) {
                curRow = eRow;
            } else {
                throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用");
                curRow = sRow;
            }
            crnNo = whsType;
            basCrnpService.checkSiteStatus(crnNo, true);
        } else {
            throw new CoolException(rowLastno.getWhsType()+"号库位排号分配规则不可用");
            Shelves shelves = new Shelves(rowCount, crn_qty);
            curRow = curRow - 4;
            for (int i = 0; i < shelves.group; i ++) {
                curRow = shelves.start(curRow);
                if (curRow < 0) {
                    throw new CoolException("检索库位失败,请联系管理员");
                }
                Integer crnNo1 = shelves.getCrnNo(curRow);
                if (basCrnpService.checkSiteError(crnNo1 + 2, true)) {
                    // 偏移量补偿
                    curRow = curRow + 4;
                    crnNo = crnNo1 + 2;
                    break;
                }
            }
        }
        if (crnNo == 0) {
            throw new CoolException("没有可用的堆垛机");
        }
        // 获取目标站
        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                .eq("type_no", staDescId)
                .eq("stn_no", sourceStaNo)
                .eq("crn_no", crnNo);
        StaDesc staDesc = staDescService.selectOne(wrapper);
        if (Cools.isEmpty(staDesc)) {
            log.error("入库路径不存在, staDescId={}, sourceStaNo={}, crnNo={}", staDescId, sourceStaNo, crnNo);
            throw new CoolException("入库路径不存在");
        }
        // 检测目标站
        BasDevp staNo = basDevpService.selectById(staDesc.getCrnStn());
        if (!staNo.getAutoing().equals("Y")) {
            throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用");
        }
        // 更新库位排号
        rowLastno.setCurrentRow(curRow);
        rowLastnoService.updateById(rowLastno);
        // 开始查找库位 ==============================>>
        // 查找库位
        locMast = locMastService.queryFreeLocMast(curRow);
        if (Cools.isEmpty(locMast)) {
            // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归
            if (times >= rowCount) {
                log.error("系统没有空库位!!!");
                throw new CoolException("没有空库位");
            }
            times = times + 1;
            return getLocNo(1, staDescId, sourceStaNo, matNos, times);
        }
        String locNo = locMast.getLocNo();
        // 返回dto
        startupDto.setCrnNo(crnNo);
        startupDto.setSourceStaNo(sourceStaNo);
        startupDto.setStaNo(staNo.getDevNo());
        startupDto.setLocNo(locNo);
        return startupDto;
    }