自动化立体仓库 - WCS系统
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
package com.zy.common.utils;
 
import com.core.common.RadixTools;
 
import java.math.BigDecimal;
 
/**
 * Created by vincent on 2020-06-03
 */
public class CommonUtils {
 
    public static Integer parseInt(Object value){
        if(null == value){
            return null;
        }
        String name = value.getClass().getSimpleName().toLowerCase();
        if(name.equals("float")){
            return ((Float)value).intValue();
        } else if(name.equals("double")){
            return ((Double)value).intValue();
        } else if(name.equals("bigdecimal")) {
            return ((BigDecimal)value).intValue();
        } else if(name.equals("long")) {
            return ((Long)value).intValue();
        } else if(name.contains("int")) {
            return (Integer)value;
        } else {
            return Double.valueOf(""+value).intValue();
        }
    }
 
    //int转short数组
    public static short[] intToShorts(int num) {
        //先将int转为byte数组,再将byte数组转成两个short,分别占用4和5空间
        byte[] bytes = RadixTools.intToBytes(num);
        byte[] tmp1 = {bytes[0], bytes[1]};
        short byteToShort = RadixTools.byteToShort(tmp1);
        byte[] tmp2 = {bytes[2], bytes[3]};
        short byteToShort2 = RadixTools.byteToShort(tmp2);
        return new short[]{byteToShort, byteToShort2};
    }
 
    public static boolean intToBoolean(Integer num) {
        return num != 0;
    }
 
    public static boolean shortToBoolean(Short num) {
        return num != 0;
    }
 
    //从row、bay、lev参数获取完整库位号
    public static String getLocNoFromRBL(Integer row, Integer bay, Integer lev) {
        StringBuffer sb = new StringBuffer();
        if (row < 10) {
            sb.append("0");
        }
        sb.append(row);
        if (bay < 10) {
            sb.append("00");
        } else if (bay < 100) {
            sb.append("0");
        }
        sb.append(bay);
        if (lev < 10) {
            sb.append("0");
        }
        sb.append(lev);
        return sb.toString();
    }
 
    public static int[] byteToBits(byte by) {
        StringBuffer sb = new StringBuffer();
        sb.append((by >> 0) & 0x1);
        sb.append((by >> 1) & 0x1);
        sb.append((by >> 2) & 0x1);
        sb.append((by >> 3) & 0x1);
        sb.append((by >> 4) & 0x1);
        sb.append((by >> 5) & 0x1);
        sb.append((by >> 6) & 0x1);
        sb.append((by >> 7) & 0x1);
        sb.append((by >> 8) & 0x1);
        sb.append((by >> 9) & 0x1);
        sb.append((by >> 10) & 0x1);
        sb.append((by >> 11) & 0x1);
        sb.append((by >> 12) & 0x1);
 
        int[] data = new int[13];
        for (int i = 0; i < sb.length(); i++) {
            data[i] = Integer.parseInt(String.valueOf(sb.charAt(i)));
        }
 
        return data;
    }
 
    public static String bytesToBarcode(byte[] bytes) {
        StringBuffer sb = new StringBuffer();
        for (byte by : bytes) {
            sb.append(by);
        }
        return sb.toString();
    }
 
}