于紫祥_1901
2020-10-10 00e38ff225eb948f5234934afc01aa54c94e0de6
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
package com.moral.service.impl;
 
import com.moral.entity.Device;
import com.moral.entity.DeviceRoad;
import com.moral.entity.MonitorPoint;
import com.moral.mapper.DeviceRoadMapper;
import com.moral.mapper.MonitorPointMapper;
import com.moral.service.DeviceRoadService;
import com.moral.util.MyLatLng;
import com.moral.util.mapUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.sockjs.transport.handler.JsonpPollingTransportHandler;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class DeviceRoadServiceImpl implements DeviceRoadService {
    @Resource
    private MonitorPointMapper monitorPointMapper;
    @Resource
    private DeviceRoadMapper deviceRoadMapper;
 
    @Override
    public List<DeviceRoad> getAlarmData(String windData, String code, String mac, String speedLevel) {
        int len = code.length();
        Map params = new HashMap();
        String townCode = null;
        String areaCode = null;
        String cityCode = null;
        if (len == 12) {
            townCode = code;
        } else if (code.substring(4, 6).equals("00")) {
            cityCode = code;
        } else {
            areaCode = code;
        }
        params.put("townCode", townCode);
        params.put("areaCode", areaCode);
        params.put("cityCode", cityCode);
        List<MonitorPoint> monitorPointList = monitorPointMapper.byCodeGetMonitor(params);
        List<MonitorPoint> monitorPoints = new ArrayList();
        List<Device> allDeviceList = new ArrayList();
        //找出所有国控站站点放到一个集合中;将几台国控站的所有设备放到一个集合中
        for (MonitorPoint monitorPoint : monitorPointList) {
            String description = monitorPoint.getDescription();
            if (description != null) {
                if (monitorPoint.getDescription().equals("国控站")) {
                    int monitorId = monitorPoint.getId();
                    MonitorPoint monitorPointG = monitorPointMapper.getMonitorPointById(monitorId);
                    monitorPoints.add(monitorPointG);
                    List<Device> deviceList = monitorPointMapper.getDeviceList(monitorId);
                    for (Device device : deviceList) {
                        String state = device.getState();
                        if (state.equals("1") || state.equals("2") || state.equals("0")) {
                            allDeviceList.add(device);
                        }
                    }
                }
            }
        }
        List drlist = null;
        if (allDeviceList.size() > 0) {
            for (int i = 0; i < allDeviceList.size(); i++) {
                if (/*allDeviceList.get(i).getMac()*/("p5dnd7a0392210").equals(mac)) {
 
                    Double lng = allDeviceList.get(i).getLongitude();
                    Double lat = allDeviceList.get(i).getLatitude();
                    List<Integer> iList = new ArrayList<Integer>();
                    //求出每台设备和每台国控站的距离,距离大于5000米的舍弃
                    for (int j = 0; j < monitorPoints.size(); j++) {
                        Double distance = 0.0;
                        Double mLat = monitorPoints.get(j).getLatitude();
                        Double mLng = monitorPoints.get(j).getLongitude();
                        distance = mapUtils.getDistance(lng, lat, mLng, mLat);
                        if (distance < 5000) {
                            iList.add(j);
                        } else {
                            continue;
                        }
                    }
                    List<Integer> indexList = new ArrayList<Integer>();
                    if (iList.size() > 0) {
                        for (int q = 0; q < iList.size(); q++) {
                            int index = iList.get(q);
                            Double latitude = monitorPoints.get(index).getLatitude();
                            Double longitude = monitorPoints.get(index).getLongitude();
                            Double angle = mapUtils.getAngle(new MyLatLng(lng, lat), new MyLatLng(longitude, latitude));
                            Double angleDiff = angle - Double.parseDouble(windData);
                            if (Math.abs(angleDiff) < 30.0) {
                                indexList.add(index);
                            } else {
                                continue;
                            }
                        }
                    }
                    List<MonitorPoint> monitorPoints1 = new ArrayList<MonitorPoint>();
                    if (indexList.size() > 0) {
                        for (int k = 0; k < indexList.size(); k++) {
                            MonitorPoint monitorPoint1 = monitorPoints.get(indexList.get(k));
                            monitorPoints1.add(monitorPoint1);
                        }
                    }
 
 
                    //System.out.println(monitorPoints1.size());
                    if (monitorPoints1.size() > 0) {
                        drlist = new ArrayList();
                        for (MonitorPoint point : monitorPoints1) {
                            List<DeviceRoad> list = deviceRoadMapper.getData(mac, point.getId());
                            drlist.add(list);
                        }
 
                    }
 
 
                    //System.out.println("==========" + drlist);
                }
            }
 
        }
 
        return drlist;
    }
}