SectionServiceImpl.java
3.03 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
package com.bsth.service.impl;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.entity.Section;
import com.bsth.repository.SectionRepository;
import com.bsth.service.SectionService;
/**
*
* @ClassName: SectionServiceImpl(路段service业务层实现类)
*
* @Extends : BaseService
*
* @Description: TODO(路段service业务层)
*
* @Author bsth@lq
*
* @Date 2016年05月03日 上午9:21:17
*
* @Version 公交调度系统BS版 0.1
*
*/
@Service
public class SectionServiceImpl extends BaseServiceImpl<Section, Integer> implements SectionService{
@Autowired
SectionRepository repository;
@Override
public Map<String, Object> sectionUpdate(Map<String, Object> map) {
Map<String, Object> resultMap = new HashMap<String, Object>();
try {
Integer sectionId = map.get("sectionId").equals("") ? 0 : Integer.parseInt(map.get("sectionId").toString());
// 路段信息字符串
String sectionJSON = map.get("sectionJSON").toString().equals("") ? "" : map.get("sectionJSON").toString();
// 如果路段信息JSON字符串不为空
if(!sectionJSON.equals("")) {
// 转换成JSON数组
JSONArray sectionsArray = JSONArray.parseArray(sectionJSON);
// 原始线状图形坐标集合
String sectionsBpoints = "";
// WGS线状图形坐标集合
String sectionsWJPpoints = "";
// 遍历
for(int s = 0 ;s<sectionsArray.size();s++) {
String pointsLngStr = sectionsArray.getJSONObject(s).get("lng").toString();
String pointsLatStr = sectionsArray.getJSONObject(s).get("lat").toString();
String WGSLngStr = JSONObject.parseObject(sectionsArray.getJSONObject(s).get("WGSpotion").toString()).get("Lng").toString();
String WGSLatStr = JSONObject.parseObject(sectionsArray.getJSONObject(s).get("WGSpotion").toString()).get("Lat").toString();
if(s==0) {
sectionsBpoints = pointsLngStr + " " + pointsLatStr;
sectionsWJPpoints = WGSLngStr + " " + WGSLatStr;
}else {
sectionsBpoints = sectionsBpoints + "," + pointsLngStr + " " + pointsLatStr;
sectionsWJPpoints = sectionsWJPpoints + "," + WGSLngStr + " " + WGSLatStr;
}
}
// WGS坐标点集合
String gsectionVector = "LINESTRING(" + sectionsWJPpoints +")";
// 原坐标点集合
String bsectionVector = "LINESTRING(" + sectionsBpoints + ")";
repository.sectionUpdate(sectionId, gsectionVector, bsectionVector);
}
resultMap.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
resultMap.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
}
return resultMap;
}
}