zjj
19 小时以前 da20b84fb1dbb266939deff9fd52f9a16f4e32fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.vincent.rsf.server.api.utils;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.vincent.rsf.framework.common.Arith;
import com.vincent.rsf.framework.common.Cools;
import com.vincent.rsf.framework.common.SpringUtils;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.api.entity.dto.LocTypeDto;
import com.vincent.rsf.server.manager.entity.DeviceBind;
import com.vincent.rsf.server.manager.entity.Loc;
import com.vincent.rsf.server.manager.service.DeviceBindService;
 
 
import java.util.List;
 
public class LocUtils {
 
    /**
     * 获取 浅库位对应的深库位号
     */
    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 CoolException(shallowLoc + "不是浅库位,系统繁忙");
        }
        return zerofill(String.valueOf(targetRow), 2) + shallowLoc.substring(2);
    }
 
    /**
     * 获取 深库位对应的浅库位号
     */
    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 boolean isShallowLoc(SlaveProperties slaveProperties, String locNo) {
        if (slaveProperties.isDoubleDeep()) {
            int row = getRow(locNo);
            return !slaveProperties.getDoubleLocs().contains(row);
        } else {
            return false;
        }
    }
 
    //获取站点对应的库类型
    public static Long getAreaType(Integer sourceStaNo) {
        DeviceBindService rowLastnoService = SpringUtils.getBean(DeviceBindService.class);
        List<DeviceBind> deviceBinds = rowLastnoService.list(new LambdaQueryWrapper<DeviceBind>());
        for (DeviceBind deviceBind : deviceBinds) {
            String[] staNoList = deviceBind.getStaList().split(";");
            for (String staNo : staNoList) {
                if (staNo.equals(sourceStaNo.toString())) {
                    return deviceBind.getId();
                }
            }
        }
        return 0L;
    }
 
    //库位排号分配
    public static int[] LocNecessaryParameters(DeviceBind deviceBind, Integer curRow, Integer crnNumber) {
 
      return LocNecessaryParametersDoubleExtension(curRow, crnNumber); //已完善
 
 
    }
 
    //经典双伸库位
    public static int[] LocNecessaryParametersDoubleExtension( Integer curRow, Integer crnNumber) {
        int[] necessaryParameters = new int[]{0, 0, 0, 0};
 
        necessaryParameters[0] = crnNumber; // 轮询次数
        //满板正常入库
        if (curRow.equals(crnNumber * 4)) {
            necessaryParameters[1] = 1;    //curRow   最深库位排
            necessaryParameters[2] = 1;     //crnNo     堆垛机号
            necessaryParameters[3] = 2;    //nearRow  最浅库位排
        } else if (curRow.equals(crnNumber * 4 - 3)) {
            necessaryParameters[1] = 4;    //curRow   最深库位排
            necessaryParameters[2] = 1;     //crnNo     堆垛机号
            necessaryParameters[3] = 3;    //nearRow  最浅库位排
        } else {
            curRow = curRow + 4;
            if (curRow < 1 || curRow > (crnNumber * 4)) {
                throw new CoolException("库位排号异常:排号:" + curRow);
            }
            if ((curRow - 1) % 4 == 0) {
                necessaryParameters[1] = curRow;    //curRow   最深库位排
                necessaryParameters[2] = (curRow + 3) / 4;     //crnNo     堆垛机号
                necessaryParameters[3] = curRow + 1;    //nearRow  最浅库位排
            } else if (curRow % 4 == 0) {
                necessaryParameters[1] = curRow;    //curRow   最深库位排
                necessaryParameters[2] = curRow / 4;     //crnNo     堆垛机号
                necessaryParameters[3] = curRow - 1;    //nearRow  最浅库位排
            } else {
                throw new CoolException("库位排号异常:排号:" + curRow);
            }
        }
 
        return necessaryParameters;
    }
 
    /**
     * 通过库位号获取 排
     */
    public static int getRow(String locNo) {
        if (!Cools.isEmpty(locNo)) {
            return Integer.parseInt(locNo.substring(0, 2));
        }
        throw new RuntimeException("库位解析异常");
    }
 
    /**
     * 通过库位号获取 列
     */
    public static int getBay(String locNo) {
        if (!Cools.isEmpty(locNo)) {
            return Integer.parseInt(locNo.substring(2, 5));
        }
        throw new RuntimeException("库位解析异常");
    }
 
    /**
     * 通过库位号获取 层
     */
    public static int getLev(String locNo) {
        if (!Cools.isEmpty(locNo)) {
            return Integer.parseInt(locNo.substring(5, 7));
        }
        throw new RuntimeException("库位解析异常");
    }
 
    /**
     * 类型检测
     * 完全检测
     **/
    public static boolean locMoveCheckLocTypeComplete(Loc loc, LocTypeDto dto) {
        // 如果源库位是高库位,目标库位是低库位
        return dto.getLocType1().equals(Integer.parseInt(loc.getType()));
    }
    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();
        }
    }
}