PointUtil.java
2.6 KB
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
package com.myproject.util;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.query.Criteria;
import java.util.concurrent.ExecutionException;
public class PointUtil {
protected static final transient Logger log = LogManager.getLogger(PointUtil.class);
public static Point getPosPoint(String posId ) {
return getPosPoint(posId,true );
}
/**
* 获取坐标
* @param posId 库位号
* @param isUpdatePos true=更新库位坐标。false=查询使用
* @return
*/
public static Point getPosPoint(String posId, boolean isUpdatePos) {
// 库位号格式:
// 例:05AA03040102
// 05:表示料仓编号,01-08
// AA:存储机构A面或B面,AA或者BB
// 03:表示抽屉在第几行
// 04:表示抽屉在第几列
// 01:表示在抽屉中的第几行
// 02:表示在抽屉中的第几列
Point p = new Point(0, 0);
try {
if (posId.length() == 12) {
double storageNum = 0;
int storage = Integer.parseInt(posId.substring(0, 2));
String typeStr = posId.substring(2, 4);
if (typeStr.equals("AA")) {
if(isUpdatePos){
storageNum = storage * 10 + 1;
}else{
storageNum = storage * 10 + 2;
}
} else {
if(isUpdatePos){
storageNum = storage * 10 + 2;
}else{
storageNum = storage * 10 + 1;
}
}
double row = Integer.parseInt(posId.substring(4, 6));
double column = Integer.parseInt(posId.substring(6, 8));
double x = storageNum + column / 100;
double y = storageNum + row / 1000;
double drawerRow=1;
double drawerColumn=1;
if (isUpdatePos) {
drawerRow = Integer.parseInt(posId.substring(8, 10));
drawerColumn = Integer.parseInt(posId.substring(10, 12));
}
x += drawerColumn / 100 / 1000;
y += +drawerRow / 1000 / 100;
p = new Point(x, y);
}
} catch (Exception ex) {
log.error("解析库位[" + posId + "]的坐标出错:" + ex);
}
// log.info("解析库位[" + posId + "]的坐标结果:" + p.toString());
return p;
}
}