IThirdServiceImpl.java
5.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
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
package com.jkdata.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.jkdata.tool.CommonConstant;
import com.jkdata.entity.ThirdPosition;
import com.jkdata.mapper.ThirdMapper;
import com.jkdata.service.IThirdService;
import com.jkdata.tool.RedisUtil;
import com.jkdata.tool.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
@Service
public class IThirdServiceImpl implements IThirdService {
@Autowired
private ThirdMapper thirdMapper;
private static DecimalFormat df = new DecimalFormat("######0.0000");
private static SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Autowired
private RedisUtil redisUtil;
@Override
public void savePosition(JSONObject jsonObject) {
Date t = new Date();
boolean ok = addMsgLog(jsonObject,sf.format(t));//添加接收报文日志
if(ok){
ThirdPosition thirdPosition = new ThirdPosition();
thirdPosition.setNodeId(jsonObject.getString("NodeId"));
Map xyMap = jsonObject.getObject("position",Map.class);
thirdPosition.setPositionx(xyMap.get("x").toString());
thirdPosition.setPositiony(xyMap.get("y").toString());
thirdPosition.setSystemId(jsonObject.getString("SystemId"));
thirdPosition.setType(jsonObject.getString("Type"));
thirdPosition.setGroup(jsonObject.getString("group"));
thirdPosition.setGroupNumber(jsonObject.getInteger("groupNumber"));
thirdPosition.setCreateTime(t);
//判断是B1、B2
changCoordinateB1(thirdPosition);
// changCoordinateB2(thirdPosition);
}
}
/**
* 收报文日志
* @param jsonObject
*/
private boolean addMsgLog(JSONObject jsonObject, String format) {
String sql = "INSERT INTO sys_msg_log ( mag_log,create_by,create_time ) VALUES " +
"( '"+jsonObject.toJSONString()+"','"+CommonConstant.CMCC+"','"+format+"' )";
System.out.println("**********"+sql);
boolean ok = addDataToDataBase(sql);
return ok;
}
//SQL插入数据库
private boolean addDataToDataBase(String sql) {
boolean ok = thirdMapper.addDataToDataBase(sql);
return ok;
}
//B1定位坐标
private void changCoordinateB1(ThirdPosition thirdPosition) {
// String x1 = "101.1636962890625";
// String y1 = "325.2133483886719";
String x1 = thirdPosition.getPositionx();
String y1 = thirdPosition.getPositiony();
double fd_x = CommonConstant.BLC1*(Double.valueOf(x1)-CommonConstant.LT_B1_X)+CommonConstant.LT_B1_X;
double fd_y = CommonConstant.BLC1*(Double.valueOf(y1)+CommonConstant.LT_B1_Y)-CommonConstant.LT_B1_Y;
System.out.println("放大后的坐标为:X:"+fd_x+",Y:"+fd_y);
double a = CommonConstant.MQ_B1_X - CommonConstant.LT_B1_X;//原点偏移x
double b = CommonConstant.MQ_B1_Y - CommonConstant.LT_B1_Y;//原点偏移y
System.out.println("偏移a:"+a+",b:"+b);
double x = Double.valueOf(fd_x) + a;
double y = Double.valueOf(fd_y) + b;
System.out.println("新坐标为:X:"+x+",Y:-"+y);
//原点偏移
// double new_fd_x = 10*(Double.valueOf(x)-CommonConstant.MQ_B1_X)+CommonConstant.MQ_B1_X;
// double new_fd_y = 10*(Double.valueOf(y)+CommonConstant.MQ_B1_Y)-CommonConstant.MQ_B1_Y;
// System.out.println("新放大后的坐标为:X:"+new_fd_x+",Y:"+new_fd_y);
thirdPosition.setPositionx(String.valueOf(x));
thirdPosition.setPositiony(String.valueOf(y));
addPositionInfo(thirdPosition);//添加转换后坐标信息
}
//B2定位坐标
private void changCoordinateB2(ThirdPosition thirdPosition) {
String x1 = thirdPosition.getPositionx();
String y1 = thirdPosition.getPositiony();
double fd_x = CommonConstant.BLC2*(Double.valueOf(x1)-CommonConstant.LT_B2_X)+CommonConstant.LT_B2_X;
double fd_y = CommonConstant.BLC2*(Double.valueOf(y1)+CommonConstant.LT_B2_Y)-CommonConstant.LT_B2_Y;
System.out.println("放大后的坐标为:X:"+fd_x+",Y:"+fd_y);
double a = CommonConstant.MQ_B2_X - CommonConstant.LT_B2_X;//原点偏移x
double b = CommonConstant.MQ_B2_Y - CommonConstant.LT_B2_Y;//原点偏移y
System.out.println("偏移a:"+a+",b:"+b);
double x = Double.valueOf(fd_x) + a;
double y = Double.valueOf(fd_y) + b;
System.out.println("新坐标为:X:"+x+",Y:-"+y);
thirdPosition.setPositionx(String.valueOf(x));
thirdPosition.setPositiony(String.valueOf(y));
addPositionInfo(thirdPosition);//添加转换后坐标信息
}
private boolean addPositionInfo(ThirdPosition thirdPosition) {
String uuid = UUIDGenerator.creatUUID();
String sql = "INSERT INTO sys_cmcc_position ( `position_id`,`node_id`,`system_id`,`type`,`group`," +
"`group_number`,`position_x`,`position_y`,`create_by`,`create_time` ) VALUES " +
" ( '"+uuid+"','"+thirdPosition.getNodeId()+"','"+thirdPosition.getSystemId()+"','"+thirdPosition.getType()+"','"+thirdPosition.getGroup()+"'," +
""+thirdPosition.getGroupNumber()+",'"+thirdPosition.getPositionx()+"','"+thirdPosition.getPositiony()+"','"+CommonConstant.CMCC+"','"+sf.format(thirdPosition.getCreateTime())+"' )";
System.out.println("**********"+sql);
boolean ok = addDataToDataBase(sql);
return ok;
}
}