#
Junjie
2024-01-17 bb3941c91f4d400ec13044f5ada027b9bc3c07d3
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
package com.zy.asrs.common.utils;
 
import com.zy.asrs.common.wms.service.LocDirectionService;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.SpringUtils;
 
import java.security.SecureRandom;
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 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 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 String generateString(int length) {
        String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; // 可选的字符集合
        SecureRandom random = new SecureRandom();
        StringBuilder sb = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(characters.length());
            char randomChar = characters.charAt(index);
            sb.append(randomChar);
        }
        return sb.toString();
    }
 
    /**
     * 获取库位组
     */
    public static List<String> getGroupLoc(String locNo, Long hostId) {
        int row = getRow(locNo);
        List<String> result = new ArrayList<>();
        LocDirectionService locDirectionService = SpringUtils.getBean(LocDirectionService.class);
        List<ArrayList<Integer>> naturalList = locDirectionService.getNaturalList(hostId);
        for (ArrayList<Integer> list : naturalList) {
            if (list.contains(row)) {
                for (Integer row0 : list) {
                    result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
                }
                return result;
            }
        }
 
        return result;
    }
 
    /**
     * 获取外侧方向的库位组
     */
    public static List<String> getGroupOuterLoc(String locNo, Long hostId) {
        int row = getRow(locNo);
        List<String> result = new ArrayList<>();
        LocDirectionService locDirectionService = SpringUtils.getBean(LocDirectionService.class);
        List<ArrayList<Integer>> outerList = locDirectionService.getOuterList(hostId);
        for (ArrayList<Integer> list : outerList) {
            if (list.contains(row)) {
                for (Integer row0 : list) {
                    if (row0 == row) {
                        break;
                    }
                    result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
                }
                return result;
            }
        }
 
        return result;
    }
 
    /**
     * 获取内侧方向的库位组
     */
    public static List<String> getGroupInnerLoc(String locNo, Long hostId) {
        int row = getRow(locNo);
        List<String> result = new ArrayList<>();
        LocDirectionService locDirectionService = SpringUtils.getBean(LocDirectionService.class);
        List<ArrayList<Integer>> innerList = locDirectionService.getInnerList(hostId);
        for (ArrayList<Integer> list : innerList) {
            if (list.contains(row)) {
                for (Integer row0 : list) {
                    if (row0 == row) {
                        break;
                    }
                    result.add(zerofill(String.valueOf(row0), 2) + locNo.substring(2));
                }
                return result;
            }
        }
 
        return result;
    }
 
}