#
luxiaotao1123
2021-01-02 33a41f5e08632da78428ea3be4bb06da71c0592a
#
2个文件已添加
1个文件已修改
381 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/utils/Utils.java 175 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/model/LocTypeDto.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/service/CommonService.java 154 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/utils/Utils.java
New file
@@ -0,0 +1,175 @@
package com.zy.asrs.utils;
import com.core.common.Arith;
import com.core.common.Cools;
import com.zy.common.properties.SlaveProperties;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by vincent on 2020/8/27
 */
public class Utils {
    private static final DecimalFormat fmt = new DecimalFormat("##0.00");
    public static float scale(Float f){
        if (f == null || f == 0f || Float.isNaN(f)) {
            return 0f;
        }
        return (float) Arith.multiplys(2, f, 1);
    }
    public static String zerofill(String msg, Integer count){
        if (msg.length() == count){
            return msg;
        } else if (msg.length() > count){
            return msg.substring(0, 16);
        } else {
            StringBuilder msgBuilder = new StringBuilder(msg);
            for (int i = 0; i<count-msg.length(); i++){
                msgBuilder.insert(0,"0");
            }
            return msgBuilder.toString();
        }
    }
    /**
     * 判断是否为深库位
     */
    public static boolean isDeepLoc(SlaveProperties slaveProperties, String locNo){
        if (slaveProperties.isDoubleDeep()) {
            int row = getRow(locNo);
            return slaveProperties.getDoubleLocs().contains(row);
        } else {
            return false;
        }
    }
    /**
     * 判断是否为深库位
     */
    public static boolean isDeepLoc(SlaveProperties slaveProperties, Integer row){
        if (slaveProperties.isDoubleDeep()) {
            return slaveProperties.getDoubleLocs().contains(row);
        } else {
            return false;
        }
    }
    /**
     * 判断是否为浅库位
     */
    public static boolean isShallowLoc(SlaveProperties slaveProperties, String locNo){
        if (slaveProperties.isDoubleDeep()) {
            int row = getRow(locNo);
            return !slaveProperties.getDoubleLocs().contains(row);
        } else {
            return false;
        }
    }
    /**
     * 判断是否为浅库位
     */
    public static boolean isShallowLoc(SlaveProperties slaveProperties, Integer row){
        if (slaveProperties.isDoubleDeep()) {
            return !slaveProperties.getDoubleLocs().contains(row);
        } else {
            return false;
        }
    }
    /**
     * 获取 深库位对应的浅库位号
     */
    public static String getShallowLoc(SlaveProperties slaveProperties, String deepLoc) {
        int row = getRow(deepLoc);
        int remainder = (int) Arith.remainder(row, slaveProperties.getGroupCount());
        int shallowRow = remainder == 1 ? (row + 1) : (row - 1);
        return zerofill(String.valueOf(shallowRow), 2) + deepLoc.substring(2);
    }
    /**
     * 获取 深库位排对应的浅库位排
     */
    public static Integer getShallowRow(SlaveProperties slaveProperties, Integer deepRow) {
        int remainder = (int) Arith.remainder(deepRow, slaveProperties.getGroupCount());
        return remainder == 1 ? (deepRow + 1) : (deepRow - 1);
    }
    /**
     * 获取 浅库位对应的深库位号
     */
    public static String getDeepLoc(SlaveProperties slaveProperties, String shallowLoc) {
        int row = getRow(shallowLoc);
        int remainder = (int) Arith.remainder(row, slaveProperties.getGroupCount());
        int targetRow;
        if (remainder == 2) {
            targetRow = row - 1;
        } else if (remainder == 3) {
            targetRow = row + 1;
        } else {
            throw new RuntimeException(shallowLoc + "不是浅库位,系统繁忙");
        }
        return zerofill(String.valueOf(targetRow), 2) + shallowLoc.substring(2);
    }
    /**
     * 获取 浅库位排对应的深库位排
     */
    public static Integer getDeepRow(SlaveProperties slaveProperties, Integer shallowRow) {
        int remainder = (int) Arith.remainder(shallowRow, slaveProperties.getGroupCount());
        int targetRow;
        if (remainder == 2) {
            targetRow = shallowRow - 1;
        } else if (remainder == 3) {
            targetRow = shallowRow + 1;
        } else {
            throw new RuntimeException(shallowRow + "不是浅库位排,系统繁忙");
        }
        return targetRow;
    }
    /**
     * 通过库位号获取 排
     */
    public static int getRow(String locNo) {
        if (!Cools.isEmpty(locNo)) {
            return Integer.parseInt(locNo.substring(0, 2));
        }
        throw new RuntimeException("库位解析异常");
    }
    /**
     * 当检索到双深库位的浅库位时,如果深库位无货,则放入对应的深库位
     */
    public static void toDeepIfEmptyByShallow(String shallowLoc) {
        int row = getRow(shallowLoc);
        int remainder = (int) Arith.remainder(row, 4);
        int targetRow = 0;
        if (remainder == 2) {
            targetRow = row - 1;
        } else if (remainder == 3) {
            targetRow = row + 1;
        } else {
            throw new RuntimeException(shallowLoc + "不是浅库位,系统繁忙");
        }
        String targetLoc = zerofill(String.valueOf(targetRow), 2) + shallowLoc.substring(2);
    }
    public static void main(String[] args) {
        SlaveProperties slaveProperties = new SlaveProperties();
        slaveProperties.setDoubleDeep(true);
        List<Integer> list = new ArrayList<>();
        list.add(1);list.add(4);list.add(5);list.add(8);list.add(9);list.add(12);
        slaveProperties.setDoubleLocs(list);
        slaveProperties.setGroupCount(4);
        Integer deepRow = getDeepRow(slaveProperties, 6);
        System.out.println(deepRow);
    }
}
src/main/java/com/zy/common/model/LocTypeDto.java
New file
@@ -0,0 +1,52 @@
package com.zy.common.model;
import com.core.exception.CoolException;
import com.zy.core.model.protocol.StaProtocol;
import lombok.Data;
/**
 * Created by vincent on 2020/10/19
 */
@Data
public class LocTypeDto {
    // 高低类型{0:未知,1:低库位,2:高库位}
    private Short locType1;
    // 宽窄类型{0:未知,1:窄库位,2:宽库位}
    private Short locType2;
    // 轻重类型{0:未知,1:轻库位,2:重库位}
    private Short locType3;
    public LocTypeDto() {
    }
    public LocTypeDto(StaProtocol staProtocol) {
        if (staProtocol.isHigh() == staProtocol.isLow()) {
            throw new CoolException("plc高低检测异常");
        }
        if (staProtocol.isLow()) {
            this.locType1 = 1; // 低库位
        } else {
            this.locType1 = 2; // 高库位
        }
    }
    /**
     * 库位类型解析
     */
    public static LocTypeDto process(StaProtocol staProtocol) {
        LocTypeDto dto = new LocTypeDto();
        if (staProtocol.isHigh() == staProtocol.isLow()) {
            throw new CoolException("plc高低检测异常");
        }
        if (staProtocol.isLow()) {
            dto.setLocType1((short) 1); // 低库位
        } else {
            dto.setLocType1((short) 2); // 高库位
        }
        return dto;
    }
}
src/main/java/com/zy/common/service/CommonService.java
@@ -6,10 +6,13 @@
import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.Shelves;
import com.zy.common.model.StartupDto;
import com.zy.common.model.enums.WorkNoType;
import com.zy.common.properties.SlaveProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@@ -36,6 +39,8 @@
    private LocMastService locMastService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private SlaveProperties slaveProperties;
    /**
     * 生成工作号
@@ -79,43 +84,133 @@
    /**
     * 检索库位号
     * @param whsType 类型 1:双深式货架
     * @param staDescId 路径ID
     * @param staDescId 路径工作类型
     * @param sourceStaNo 源站
     * @param matNos 物料号集合
     * @return locNo 检索到的库位号
     */
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos) {
    @Transactional
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto) {
        StartupDto startupDto = new StartupDto();
        // 生成工作号
        int workNo = getWorkNo(WorkNoType.getWorkNoType(staDescId));
        startupDto.setWorkNo(workNo);
        if (sourceStaNo < 100) {
            whsType = 1;
        } else {
        int workNo = getWorkNo(0);
        switch (sourceStaNo) {
            case 202:
            whsType = 2;
                break;
            case 205:
                whsType = 1;
                break;
            case 126:
                whsType = 3;
                break;
            default:
                throw new CoolException("库位排号分配错误, 源站号:" + sourceStaNo);
        }
        startupDto.setWorkNo(workNo);
        RowLastno rowLastno = rowLastnoService.selectById(whsType);
        if (Cools.isEmpty(rowLastno)) {
            throw new CoolException("数据异常,请联系管理员");
        }
        if (whsType == 1 || whsType == 2){
        // ===============>>>> 开始执行
            int curRow = rowLastno.getCurrentRow();
            int sRow = rowLastno.getsRow();
            int eRow = rowLastno.geteRow();
            // 获取目标站所在货架排号
            curRow = curRow == sRow ? eRow : sRow;
        int crn_qty = rowLastno.getCrnQty();
        int rowCount = eRow - sRow + 1;
            // 目标堆垛机号
            int crnNo;
            switch (whsType) {
                case 1:
                    crnNo = 1;
        int crnNo = 0;
        // 目标库位
        LocMast locMast = null;
        // 靠近摆放规则 --- 同天同规格物料
        if (!Cools.isEmpty(matNos)) {
            List<String> locNos = locDetlService.getSameDetlToday(matNos.get(0));
            for (String locNo : locNos) {
                if (Utils.isShallowLoc(slaveProperties, locNo)) {
                    continue;
                }
                String shallowLocNo = Utils.getShallowLoc(slaveProperties, locNo);
                // 检测目标库位是否为空库位
                LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
                    locMast = shallowLoc;
                    crnNo = locMast.getCrnNo();
                    break;
                case 2:
                    crnNo = 2;
                }
            }
        }
        // 靠近摆放规则 --- 空托
        if (staDescId == 10) {
            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", "D"));
            if (locMasts.size() > 0) {
                for (LocMast loc : locMasts) {
                    if (Utils.isShallowLoc(slaveProperties, loc.getLocNo())) {
                        continue;
                    }
                    String shallowLocNo = Utils.getShallowLoc(slaveProperties,  loc.getLocNo());
                    // 检测目标库位是否为空库位
                    LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                    if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
                        locMast = shallowLoc;
                        crnNo = locMast.getCrnNo();
                    break;
                default:
                    throw new CoolException("检索库位 -- 检索堆垛机号失败");
                    }
                }
            }
        }
        // 如果没有相近物料,则按规则轮询货架
        if (null == locMast) {
            // 1-4排
            if (whsType == 1) {
                // 获取目标站所在货架排号
                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;
                    }
                }
                // 5-8排
            } else if (whsType == 2) {
                // 获取目标站所在货架排号
                Shelves shelves = new Shelves(rowCount, crn_qty);
                curRow = shelves.start(curRow - 4);
                if (curRow < 0) {
                    throw new CoolException("检索库位失败,请联系管理员");
                }
                for (List<Integer> node : shelves.nodes){
                    if (node.contains(curRow)) {
                        crnNo = shelves.nodes.indexOf(node) + 1;
                        break;
                    }
                }
                // 偏移量补偿
                curRow = curRow + 4;
                crnNo = crnNo + 1;
                // 126空板入 1-8排
            } else {
                // 获取目标站所在货架排号
                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);
@@ -132,8 +227,21 @@
            int inQty = staNo.getInQty()==null?0:staNo.getInQty();
            if (staNo.getAutoing().equals("Y") && inQty<2) {
                // 查找库位
                LocMast locMast = locMastService.queryFreeLocMast(curRow);
            if (locMast == null) {
                if (Utils.isShallowLoc(slaveProperties, curRow)) {
                    Integer deepRow = Utils.getDeepRow(slaveProperties, curRow);
                    locMast = locMastService.queryFreeLocMast(deepRow, locTypeDto.getLocType1());
                }
                if (Cools.isEmpty(locMast)) {
                    locMast = locMastService.queryFreeLocMast(curRow, locTypeDto.getLocType1());
                }
            }
            if (Cools.isEmpty(locMast)) {
                // 轻货物找轻库位为空时,可以去找重库位仓
                if (locTypeDto.getLocType1() == 1) {
                    locTypeDto.setLocType1((short) 2);
                    return getLocNo(null, staDescId, sourceStaNo, matNos, locTypeDto);
                }
                    throw new CoolException("没有空库位");
                }
                String locNo = locMast.getLocNo();
@@ -150,12 +258,10 @@
            } else {
                throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用");
            }
        } else {
            throw new CoolException(rowLastno.getWhsType()+"号库位排号分配规则不可用");
        }
        return startupDto;
    }
    public static String zerofill(String msg, Integer count) {
        if (msg.length() == count) {
            return msg;