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;
|
}
|
}
|