#
Junjie
1 天以前 c4b6b51afdd3374735ed5f358457987eaa6e476f
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
package com.zy.common.utils;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.NavigateNode;
import com.zy.core.enums.RedisKeyType;
 
import java.util.HashMap;
 
/**
 * 库位编号和A*算法的xy轴转换工具类
 */
public class NavigatePositionConvert {
 
    public static String xyToPosition(int x, int y, int z) {
        String locNo = Utils.getLocNo(x, y, z);
        String code = null;
 
        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
        Object object = redisUtil.get(RedisKeyType.POINT_MAP.key);
 
        if(object == null) {
            //库位号转小车二维码
            LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                    .eq("loc_no", locNo)
                    .eq("status", 1));
            if (locMast == null) {
                return null;
            }
 
            code = locMast.getQrCodeValue();
        }else {
            HashMap<String, String> cache = (HashMap<String, String>) object;
            code = cache.get(locNo);
        }
        return code;
    }
 
    //小车条形码转路径算法节点
    public static NavigateNode codeToNode(String code) {
        NavigateNode node = null;
 
        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
        Object object = redisUtil.get(RedisKeyType.LOC_MAP.key);
 
        if (object == null) {
            LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                    .eq("qr_code_value", code)
                    .eq("status", 1));
            if (locMast == null) {
                return null;
            }
            node = new NavigateNode(locMast.getRow1(), locMast.getBay1());
            node.setZ(locMast.getLev1());
        } else {
            HashMap<String, String> cache = (HashMap<String, String>) object;
            String locNo = cache.get(code);
 
            node = new NavigateNode(Utils.getRow(locNo), Utils.getBay(locNo));
            node.setZ(Utils.getLev(locNo));
        }
        return node;
    }
 
    //坐标编号转xy轴
    public static int[] positionToXY(String position) {
        int col = Integer.parseInt(position.substring(0, 2));
        int row = Integer.parseInt(position.substring(2, 5));
        int[] newPosition = coverPosition(col,row);
        //返回x和y
//        return new int[]{row, col};
        return newPosition;
    }
 
    //WCS系统库位号转路径算法节点
    public static NavigateNode locNoToNode(String locNo) {
        int col = Integer.parseInt(locNo.substring(0, 2));
        int row = Integer.parseInt(locNo.substring(2, 5));
        int[] newPosition = coverPosition(col,row);
        NavigateNode node = new NavigateNode(col, row);
        node.setZ(Utils.getLev(locNo));
        return node;
    }
 
    //路径算法节点转WCS系统库位号
    public static String nodeToLocNo(NavigateNode node) {
        return xyzToLocNo(node.getX(), node.getY(), node.getZ());
    }
 
    //WCS坐标转WCS库位号
    public static String xyzToLocNo(int x, int y, int z) {
        String locNo = Utils.getLocNo(x, y, z);
        return locNo;
    }
 
    //牛眼坐标转WCS库位号
    public static String nyXyzToLocNo(int x, int y, int z) {
        int[] ints = NyXyzToWCSXyz(x, y, z);
        String locNo = Utils.getLocNo(ints[0],ints[1],ints[2]);
        return locNo;
    }
 
    //WCS系统坐标转牛眼坐标
    public static int[] WCSXyzToNyXyz(int x, int y, int z) {
        //WCS系统Y轴 => 牛眼X轴转换公式
        int x1 = Math.abs(y - 61) + 11;
        //WCS系统X轴 => 牛眼Y轴转换公式
        int y1 = x + 10;
        return new int[]{x1, y1, z};
    }
 
    //牛眼坐标转WCS系统坐标
    public static int[] NyXyzToWCSXyz(int x, int y, int z) {
        //牛眼X轴 => WCS系统Y轴公式
        int y1 = Math.abs(x - 11 - 61);
        //牛眼Y轴 => WCS系统X轴公式
        int x1 = y - 10;
        return new int[]{x1, y1, z};
    }
 
    public static int[] coverPosition(int col,int row) {
        return new int[]{col, row};
    }
 
    public static boolean equalsNode(NavigateNode node1, NavigateNode node2) {
        if(node1.getX() ==  node2.getX() && node1.getY() == node2.getY() && node1.getZ() == node2.getZ()) {
            return true;
        }
        return false;
    }
}