From d903f312cf6a1d0fc4c5745832a9d6fa681e5141 Mon Sep 17 00:00:00 2001
From: 于紫祥_1901 <email@yuzixiang_1910>
Date: Tue, 30 Jun 2020 09:16:07 +0800
Subject: [PATCH] update(无组织排放)
---
src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java | 633 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 598 insertions(+), 35 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
index 22c16d9..3f1f427 100644
--- a/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
@@ -1,25 +1,47 @@
package com.moral.service.impl;
+import java.math.BigDecimal;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
+import javax.validation.constraints.NotNull;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.moral.mapper.DictionaryDataMapper;
+import com.moral.mapper.OrganizationMapper;
+import com.moral.service.HistoryHourlyService;
+import com.moral.util.MyLatLng;
+import com.moral.util.mapUtils;
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
import com.github.pagehelper.PageHelper;
import com.moral.common.bean.Constants;
import com.moral.common.bean.PageBean;
-import com.moral.common.util.*;
+import com.moral.common.util.ExampleUtil;
+import com.moral.common.util.ParameterUtils;
+import com.moral.common.util.RedisUtils;
+import com.moral.common.util.StringUtils;
+import com.moral.common.util.ValidateUtil;
import com.moral.entity.Device;
-import com.moral.mapper.DeviceMapper;
-import org.apache.commons.collections.CollectionUtils;
-import org.springframework.stereotype.Service;
-
import com.moral.entity.MonitorPoint;
+import com.moral.mapper.DeviceMapper;
import com.moral.mapper.MonitorPointMapper;
+import com.moral.service.DeviceService;
import com.moral.service.MonitorPointService;
+import com.moral.service.OrganizationService;
+
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;
@@ -30,7 +52,21 @@
@Resource
private DeviceMapper deviceMapper;
@Resource
+ private OrganizationMapper orgMapper;
+ @Resource
RedisUtils redisUtils;
+ @Resource
+ DictionaryDataMapper dictionaryDataMapper;
+
+ @Resource
+ private DeviceService deviceService;
+
+ @Resource
+ private OrganizationService organizationService;
+
+ @Resource
+ private HistoryHourlyService historyHourlyService;
+
private static Class ENTITY_CLASS = MonitorPoint.class;
@Override
public List<MonitorPoint> getMonitorPointsByAreaName(Map<String, Object> parameters) {
@@ -39,12 +75,20 @@
}
@Override
public List<MonitorPoint> queryWithStateByMap(Map<String, Object> params){
- List<MonitorPoint> monitorPointList = monitorPointMapper.selectByMap(params);
- for(MonitorPoint monitorPoint:monitorPointList){
- Integer state = getStateFromRedis(monitorPoint.getId());
- monitorPoint.setState(state);
+ params.put("isDelete",Constants.IS_DELETE_FALSE);
+ Object orgIdObj = params.get("orgId");
+ List<MonitorPoint> monitorPointList = null;
+ if(orgIdObj != null) {
+ Integer orgId = Integer.parseInt(orgIdObj.toString());
+ List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId);
+ params.put("orgIds",orgIds);
+ monitorPointList = monitorPointMapper.selectByMap(params);
+// for(MonitorPoint monitorPoint:monitorPointList){
+// Integer state = getStateFromRedis(monitorPoint.getId());
+// monitorPoint.setState(state);
+// }
}
- return monitorPointList;
+ return monitorPointList == null ? new ArrayList<>() : monitorPointList;
}
private Integer getStateFromRedis(Integer monitorPointId){
StringBuilder key = new StringBuilder();
@@ -64,13 +108,6 @@
public PageBean queryByPageBean(PageBean pageBean) {
Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean);
List<Example.Criteria> criteriaList = example.getOredCriteria();
- if(criteriaList!=null&&criteriaList.size()>0){
- for(Example.Criteria cri : criteriaList){
- cri.andNotEqualTo("isDelete", Constants.IS_DELETE_TRUE);
- }
- }else {
- example.or().andNotEqualTo("isDelete",Constants.IS_DELETE_TRUE);
- }
PageHelper.startPage(pageBean.getPageIndex(),pageBean.getPageSize());
List<MonitorPoint> monitorPointList = monitorPointMapper.selectWithAreaNameByExample(example);
return new PageBean(monitorPointList);
@@ -89,9 +126,17 @@
monitorPoint.setIsDelete(Constants.IS_DELETE_FALSE);
monitorPointMapper.insertSelective(monitorPoint);
}else{
+ MonitorPoint queryMonitorPoint = new MonitorPoint();
+ queryMonitorPoint.setId(monitorPoint.getId());
+ queryMonitorPoint.setOrganizationId(monitorPoint.getOrganizationId());
+ // num = 1,���������������,������������������������
+ Integer num = monitorPointMapper.selectCount(queryMonitorPoint);
+ boolean needRefreshCach = (num!=1);
monitorPointMapper.updateByPrimaryKeySelective(monitorPoint);
- // ������������������������������ ���redis���������������
- refreshDevicesInRedis(monitorPoint.getId());
+ if(needRefreshCach){
+ // ������������������������������ ���redis���������������
+ refreshDevicesInRedis(monitorPoint.getId());
+ }
}
}
catch (Exception ex){
@@ -102,24 +147,24 @@
������������������������������ ���redis���������������
*/
private void refreshDevicesInRedis(int monitorPointId){
- Device device = new Device();
- device.setMonitorPointId(monitorPointId);
- List<Device> deviceList = deviceMapper.select(device);
+ Device queryDevice = new Device();
+ queryDevice.setMonitorPointId(monitorPointId);
+ List<Device> deviceList = deviceMapper.select(queryDevice);
if (!CollectionUtils.isEmpty(deviceList)){
List<Integer> orgIds = monitorPointMapper.selectOrganizationIds(monitorPointId);
if (!CollectionUtils.isEmpty(orgIds)){
deviceList.stream().forEach(dev ->{
if(!StringUtils.isNullOrEmpty(dev.getMac())){
String key = "device_"+dev.getMac();
- // ��������������������� ������������redis
- Device simpleDevice = new Device();
- simpleDevice.setId(dev.getId());
- simpleDevice.setDeviceVersion(dev.getDeviceVersion());
- simpleDevice.setMac(dev.getMac());
- simpleDevice.setMonitorPointId(dev.getMonitorPointId());
+// // ��������������������� ������������redis
+// Device simpleDevice = new Device();
+// simpleDevice.setId(dev.getId());
+// simpleDevice.setDeviceVersion(dev.getDeviceVersion());
+// simpleDevice.setMac(dev.getMac());
+// simpleDevice.setMonitorPointId(dev.getMonitorPointId());
// ������������������������������������������������������������������
- simpleDevice.setOrganizationIds(orgIds);
- redisUtils.set(key,simpleDevice);
+ dev.setOrganizationIds(orgIds);
+ redisUtils.set(key,dev);
}
});
}
@@ -149,10 +194,25 @@
Criteria criteria = example.createCriteria();
criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE).andLike("name", "%" + name + "%");
- example.or().andEqualTo("isDelete", Constants.IS_DELETE_FALSE).andCondition("getPY(name) like ", "%" + name + "%");
+ example.or().andEqualTo("isDelete", Constants.IS_DELETE_FALSE)
+ .andCondition("getPY(" + getReplaceStr("name") + ") like ", "%" + name + "%");
List<MonitorPoint> monitorPoints = monitorPointMapper.selectByExample(example);
return monitorPoints;
+ }
+
+ private String getReplaceStr(String name){
+ List<String[]> list = new ArrayList<String[]>();
+ list.add(new String[]{"���",""});
+ list.add(new String[]{"���",""});
+ for (String[] string : list) {
+ name = replace(name,string[0],string[1]);
+ }
+ return name;
+ }
+
+ private String replace(String name,String fromStr,String toStr){
+ return "REPLACE (" + name + ",'" + fromStr + "','" + toStr + "')";
}
/**
@@ -172,13 +232,516 @@
return list;
}
+ /**
+ * ������������������������������������
+ * @param orgId
+ * @return
+ */
+ @Override
+ public Integer countOfSubOrgs(@NotNull Integer orgId){
+ Example example = new Example(ENTITY_CLASS);
+ //���������������������������
+ if(!dictionaryDataMapper.isSupperOrgId(orgId)){
+ List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId);
+ example.or().andIn("organizationId",orgIds);
+ }
+ return monitorPointMapper.selectCountByExample(example);
+ }
@Override
public List<MonitorPoint> getMonitorPointsByOrganizationId(Integer orgId) {
- MonitorPoint monitorPoint = new MonitorPoint();
- monitorPoint.setIsDelete(Constants.IS_DELETE_FALSE);
+ Example example = new Example(MonitorPoint.class);
+ Criteria criteria = example.createCriteria();
+
+ criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE);
if (Constants.isNotSpecialOrgId(orgId)) {
- monitorPoint.setOrganizationId(orgId);
+ //criteria.andEqualTo("organizationId", orgId);
+ Set<Integer> organizationIds = organizationService.getChildOrganizationIds(orgId);
+ criteria.andIn("organizationId", organizationIds);
+
}
- return monitorPointMapper.select(monitorPoint);
+ example.orderBy("name").asc();
+ return monitorPointMapper.selectByExample(example);
}
+ @Override
+ public List<MonitorPoint> getMonitorPointsByRegion(Map<String, Object> parameters) {
+ Example example = new Example(MonitorPoint.class);
+ Criteria criteria = example.createCriteria();
+
+ criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE);
+ criteria.andEqualTo(parameters.get("name").toString(), parameters.get("value"));
+ return monitorPointMapper.selectByExample(example);
+ }
+ @Override
+ public List<Integer> queryVersionsById(Integer id){
+ return monitorPointMapper.selectVersionsById(id);
+ }
+ @Override
+ public MonitorPoint queryMonitorPointById(Integer mpointId) {
+ return this.monitorPointMapper.selectByPrimaryKey(mpointId);
+ }
+
+ @Override
+ public List<MonitorPoint> getMonitorPointsAndDevicesByRegion(Map<String, Object> parameters) {
+ //������������
+ Object organizationId = parameters.remove("organizationId");
+ ValidateUtil.notNull(organizationId, "param.is.null");
+ ValidateUtil.notNull(parameters.get("regionCode"), "param.is.null");
+
+ //������������������
+ ParameterUtils.getRegionType4RegionCode(parameters);
+
+ Example example = new Example(MonitorPoint.class);
+ Criteria criteria = example.createCriteria();
+ criteria.andEqualTo("isDelete", Constants.IS_DELETE_FALSE);
+ if (Constants.isNotSpecialOrgId(Integer.valueOf(organizationId.toString()))) {
+ //criteria.andEqualTo("organizationId", organizationId);
+ Set<Integer> organizationIds = organizationService.getChildOrganizationIds(Integer.valueOf(organizationId.toString()));
+ criteria.andIn("organizationId", organizationIds);
+ }
+ criteria.andEqualTo(parameters.get("regionType") + "Code", parameters.remove("regionCode"));
+
+ //���������������������
+ List<MonitorPoint> monitorPoints = monitorPointMapper.selectByExample(example);
+ //���������������������������������
+ Iterator<MonitorPoint> iterator = monitorPoints.iterator();
+ while (iterator.hasNext()) {
+ MonitorPoint monitorPoint = iterator.next();
+ List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPoint.getId());
+ if (ObjectUtils.isEmpty(devices)) {
+ iterator.remove();
+ } else {
+ monitorPoint.setDevices(devices);
+ }
+
+ }
+ return monitorPoints;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Collection<Object> getDevicesStateByRegion(Map<String, Object> parameters) {
+ //������������
+ Object organizationId = parameters.remove("organizationId");
+ ValidateUtil.notNull(organizationId, "param.is.null");
+ ValidateUtil.notNull(parameters.get("regionCode"), "param.is.null");
+
+ //������������������
+ ParameterUtils.getRegionType4RegionCode(parameters);
+
+ if (Constants.isNotSpecialOrgId(Integer.valueOf(organizationId.toString()))) {
+ Set<Integer> organizationIds = organizationService.getChildOrganizationIds(Integer.valueOf(organizationId.toString()));
+ parameters.put("orgIds", organizationIds);
+ }
+ List<Map<String, Object>> monitorPoints = deviceMapper.getDevicesStateByRegion(parameters);
+ Map<String, Object> result = new HashMap<String, Object>();
+ Map<String,Object> device;
+ List<Map<String, Object>> devices;
+ for (Map<String, Object> map : monitorPoints) {
+ String id = map.get("id").toString();
+
+ device = new HashMap<String,Object>();
+ device.put("id", map.remove("deviceId"));
+ device.put("name", map.remove("deviceName"));
+ device.put("state", map.remove("state"));
+ device.put("mac", map.remove("mac"));
+
+ if (result.containsKey(id)) {
+ Map<String, Object> monitorPoint = (Map<String, Object>) result.get(id);
+ devices = (List<Map<String, Object>>) monitorPoint.get("devices");
+ } else {
+ devices = new ArrayList<Map<String, Object>>();
+ result.put(id, map);
+ }
+ devices.add(device);
+ map.put("devices", devices);
+ result.put(id, map);
+ }
+
+ return result.values();
+ }
+
+ @Override
+ public void isCompensateCalculation(Map<String, Object> parameters) {
+ MonitorPoint monitorPoint = monitorPointMapper.selectByPrimaryKey(Integer.valueOf(parameters.get("monitorPointId").toString()));
+ if (Integer.valueOf(320581).equals(monitorPoint.getAreaCode())) {
+ parameters.put("compensate", true);
+ }
+
+ }
+ @Override
+ public Map<String, Object> selectAllById(String id) {
+ int id2 = Integer.parseInt(id);
+ Map<String, Object> map = monitorPointMapper.selectAllById(id2);
+ return map;
+ }
+
+ @Override
+ public List<Device> getDeviceList(int id) {
+ return monitorPointMapper.getDeviceList(id);
+ }
+
+ @Override
+ public JSONObject getMonitorPointById(int id, String Time, int i, String sensor) {
+ JSONObject params = new JSONObject();
+ MonitorPoint monitorPoint = monitorPointMapper.getMonitorPointById(id);
+ if (i == 1) {
+ Double longitude = monitorPoint.getLongitude();
+ Double latitude = monitorPoint.getLatitude();
+
+ Double workshop = 0.0;
+
+ Double flue = 0.0;
+ //������������
+ List<Device> device1 = deviceService.getDeviceById1(id);
+
+ //������������
+ List<Device> device2 = deviceService.getDeviceById2(id);
+
+ //������������
+ List<Device> device3 = deviceService.getDeviceById3(id);
+
+
+ String purificationRate = null;//���������
+
+ if (device3.size() == 0) {
+ purificationRate = "���������������������������������������������";
+ params.put("device2", device2);
+ params.put("device1", device1);
+ } else {
+ params.put("device1", device1);
+ params.put("device2", device2);
+ params.put("device3", device3);
+ for (Device device33 : device3) {
+ String mac3 = device33.getMac();
+ String tvoc = historyHourlyService.getTVOCByMac(mac3, Time,sensor);
+ if (tvoc != null) {
+ workshop = Double.parseDouble(tvoc);
+ } else {
+ workshop = 0.0;
+ }
+ }
+ if (device1.size() == 0) {
+ purificationRate = "���������������������������������������������";
+ } else {
+ for (Device device11 : device1) {
+ String mac1 = device11.getMac();
+ flue = Double.parseDouble(historyHourlyService.getTVOCByMac(mac1, Time,sensor));
+ if (workshop == 0.0) {
+ purificationRate = "���������������������������������������������������";
+ } else {
+ if (flue == 0.0) {
+ purificationRate = "���������������������������������������������������";
+ } else {
+ BigDecimal b = new BigDecimal(((workshop - flue) / workshop) * 100);
+ double purity2 = b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
+ purificationRate = (purity2) + "%";
+ }
+ }
+ }
+ }
+ }
+ params.put("latitude", latitude);
+ params.put("longitude", longitude);
+ params.put("purificationRate", purificationRate);
+ }
+ if (i == 2) {
+ Double longitude = monitorPoint.getLongitude();
+ Double latitude = monitorPoint.getLatitude();
+ //������������
+ List<Device> device1 = deviceService.getDeviceById1(id);
+ //������������
+ List<Device> device2 = deviceService.getDeviceById2(id);
+ //������������
+ List<Device> device3 = deviceService.getDeviceById3(id);
+ String collectionRate = null;//���������
+ Double pressure = 0.0;//������������
+ List<Double> list1 = new ArrayList();
+ if (device3.size() == 0) {
+ collectionRate = "������������������������������������������������";
+ params.put("device1", device1);
+ params.put("device2", device2);
+ } else {
+ params.put("device3", device3);
+ if (device2.size() == 0) {
+ collectionRate = "������������������������������������������������";
+ params.put("device1", device1);
+ } else {
+ params.put("device2", device2);
+ params.put("device1", device1);
+ Double sum = 0.0;
+ for (Device device22 : device2) {
+ String mac2 = device22.getMac();
+ String pressure2 = historyHourlyService.getPressureByMac(mac2, Time);
+ if (pressure2 != null) {
+ pressure = Double.parseDouble(pressure2);
+ list1.add(pressure);
+ }else {
+ collectionRate = "������������������������������������������������������������";
+ }
+
+ }
+ for (Double d : list1) {
+ sum = sum + d;
+ }
+ if (list1.size() != 0) {
+ pressure = sum / list1.size();
+ } else {
+ collectionRate = "������������������������������������������������������������";
+ }
+ Double pressure33 = 0.0;
+ for (Device device33 : device3) {
+ String mac3 = device33.getMac();
+ String pressure3 = historyHourlyService.getPressureByMac(mac3, Time);
+ if (pressure3 != null) {
+ pressure33 = Double.parseDouble(pressure3);
+ BigDecimal b = new BigDecimal((pressure - pressure33 + 3.5) * 20);//���������2.5���������������������������������
+ double collection = b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
+ collectionRate = collection + "%";
+ }
+ }
+ }
+ }
+ params.put("latitude", latitude);
+ params.put("longitude", longitude);
+ params.put("collectionRate", collectionRate);
+ }
+
+ if (i == 3) {
+ Double longitudeCompany = monitorPoint.getLongitude();
+ Double latitudeCompany = monitorPoint.getLatitude();
+ Double longitude = 0.0;//������������������������
+ Double latitude = 0.0;//������������������������
+ List<Device> deviceList = deviceService.getDeviceById2(id);
+ //List<Device> deviceList = monitorPointService.getDeviceList(id);
+ List<Map> list = new ArrayList<Map>();//������historyHourly���json������
+ String smac = "";//������������������Mac���
+ List<Map> windList = new ArrayList<Map>();//���������������������������������������
+ Map<String, Object> jsonMap = new HashMap<String, Object>();//���������������������
+ Map<String, Object> deviceMap = null;
+ if (deviceList.size()>1){
+ for (Device device : deviceList) {
+ deviceMap = new HashMap<String, Object>();
+ smac = device.getMac();
+ latitude = device.getLatitude();
+ longitude = device.getLongitude();
+
+ jsonMap = historyHourlyService.getDataByMac(smac, Time);
+ deviceMap.put("longitude", longitude);
+ deviceMap.put("latitude", latitude);
+ if (jsonMap != null) {
+ deviceMap.put("jsonMap", jsonMap);
+ } else {
+ deviceMap.put("jsonMap", "������������������������������");
+ }
+
+ list.add(deviceMap);
+ }
+ Map<String, Object> mapData = new HashMap<String, Object>();
+ Map<String, Object> mapDevice;
+ JSONArray windDir;
+ for (Map<String, Object> objectMap : list) {
+ mapDevice = new HashMap<String, Object>();
+ Map<String, Object> map = null;
+ if (!(objectMap.get("jsonMap") instanceof String)) {
+ mapData = (Map<String, Object>) objectMap.get("jsonMap");
+ map = (Map) JSON.parseObject((String) mapData.get("json"));
+ windDir = (JSONArray) JSONArray.toJSON(map.get("e23"));
+ JSONArray concentration = (JSONArray) JSONArray.toJSON(map.get(sensor));
+
+ BigDecimal bigDecimal1=new BigDecimal(0);
+ BigDecimal bigDecimal=new BigDecimal(0);
+ if (concentration!=null){
+ if (concentration.get(0) instanceof Integer){
+ bigDecimal1 =new BigDecimal(concentration.get(0).toString());
+ }else {
+ bigDecimal1= (BigDecimal) concentration.get(0);
+ }
+ if (windDir!=null){
+ if (windDir.get(0) instanceof Integer){
+ bigDecimal =new BigDecimal(windDir.get(0).toString());
+ }else {
+ bigDecimal=(BigDecimal) windDir.get(0);
+ }
+ mapDevice.put("e23", bigDecimal.doubleValue());
+ mapDevice.put("sensor", bigDecimal1.doubleValue());
+ mapDevice.put("longitude", objectMap.get("longitude"));
+ mapDevice.put("latitude", objectMap.get("latitude"));
+ }else {
+ mapDevice.put("noSensor", "���������������");
+ mapDevice.put("longitude", objectMap.get("longitude"));
+ mapDevice.put("latitude", objectMap.get("latitude"));
+ }
+ }
+ } else {
+ mapDevice.put("info", objectMap.get("jsonMap"));
+ mapDevice.put("longitude", objectMap.get("longitude"));
+ mapDevice.put("latitude", objectMap.get("latitude"));
+ }
+ windList.add(mapDevice);
+ }
+ // if (windDir!=null){}
+ Double differenceNum = 0.0;
+ Map<String, Object> indexMap;
+ List<Map> mapList = new ArrayList<>();
+ for (int j = 0; j < windList.size(); j++) {
+ for (int k = 0; k < windList.size(); k++) {
+ if (k != j) {
+ indexMap = new HashMap<String, Object>();
+ if (windList.get(k).containsKey("e23") && windList.get(j).containsKey("e23")) {
+ Double e23Numk = (Double) windList.get(k).get("e23");
+ Double e23Numj = (Double) windList.get(j).get("e23");
+ Double diff = e23Numk - e23Numj;
+ BigDecimal b = new BigDecimal(Math.abs(diff));
+
+ differenceNum = b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
+ if (differenceNum > 180) {
+ differenceNum = 360 - differenceNum;
+ }
+ indexMap.put("k", k);
+ indexMap.put("j", j);
+ indexMap.put("diff", differenceNum);
+ } else {
+ indexMap.put("k", k);
+ indexMap.put("j", j);
+ indexMap.put("info", "���������������");
+ }
+
+// indexMap.put("longitude",windList.get(k).get("longitude"));
+// indexMap.put("latitude",windList.get(k).get("latitude"));
+ mapList.add(indexMap);
+ } else {
+ continue;
+ }
+
+ }
+ }
+ Double min = 0.0;
+ int indexMin = 0;
+ if (mapList.size()>0){
+ if (mapList.get(0).containsKey("diff")) {
+ min = (Double) mapList.get(0).get("diff");
+ for (int q = 1; q < mapList.size(); q++) {
+ if (mapList.get(q).containsKey("diff")) {
+ if (min > (Double) mapList.get(q).get("diff")) {
+ min = (Double) mapList.get(q).get("diff");
+ indexMin = q;
+ }
+ } else {
+ indexMin = q;
+ }
+ }
+ }
+ }
+
+ Map twoDeviceMap = mapList.get(indexMin);
+ List<Map> list1 = new ArrayList<Map>(); //���������������������������������������������������
+ list1.add(windList.get((Integer) twoDeviceMap.get("k")));
+ list1.add(windList.get((Integer) twoDeviceMap.get("j")));
+
+ Double wind = 0.0;
+ Double sum = 0.0;
+ if (list1.get(0).containsKey("e23")) {
+ if (Math.abs((Double) list1.get(0).get("e23") - (Double) list1.get(1).get("e23")) > 180) {
+ sum = (Double) list1.get(0).get("e23") + (Double) list1.get(1).get("e23");
+ wind = sum / 2 + 180;
+ if (wind > 360) {
+ wind = wind - 360;
+ }
+ } else {
+ for (Map map : list1) {
+ sum += (Double) map.get("e23");
+ }
+ wind = sum / 2;
+ }
+ } else {
+ wind = 0.0;
+ }
+ Map<String, Object> longAndLatiMap;
+ List<Map> longAndLatiList = new ArrayList<>();//������������������������������������windList������������������������������������������������������������������
+ List<Map> preAngleDeviceList = new ArrayList<Map>(); //���������������������������������������
+ if (wind != 0.0) {
+ for (int f = 0; f < windList.size(); f++) {
+ for (int h = 0; h < windList.size(); h++) {
+ if (f != h) {
+ longAndLatiMap = new HashMap<String, Object>();
+ longAndLatiMap.put("h", h);
+ longAndLatiMap.put("f", f);
+ Double angle = mapUtils.getAngle(
+ new MyLatLng((Double) windList.get(h).get("longitude"),
+ (Double) windList.get(h).get("latitude")),
+ new MyLatLng((Double) windList.get(f).get("longitude"),
+ (Double) windList.get(f).get("latitude")));
+ Double angleDiff = Math.abs(angle - wind);
+ longAndLatiMap.put("angle", angleDiff);
+ longAndLatiList.add(longAndLatiMap);
+ }
+ }
+ }
+ Double minAngle = (Double) longAndLatiList.get(0).get("angle");
+ int indexAngle = 0;
+ for (int j = 0; j < longAndLatiList.size(); j++) {
+ if (minAngle > (Double) longAndLatiList.get(j).get("angle")) {
+ minAngle = (Double) longAndLatiList.get(j).get("angle");
+ indexAngle = j;
+ }
+ }
+ //windList.get((Integer) longAndLatiList.get(indexAngle).get("f"))������������������������
+ preAngleDeviceList.add(windList.get((Integer) longAndLatiList.get(indexAngle).get("h")));
+ preAngleDeviceList.add(windList.get((Integer) longAndLatiList.get(indexAngle).get("f")));
+
+ Double length = mapUtils.getDistance((Double) preAngleDeviceList.get(0).get("longitude"), (Double) preAngleDeviceList.get(0).get("latitude"),
+ (Double) preAngleDeviceList.get(1).get("longitude"), (Double) preAngleDeviceList.get(1).get("latitude"));
+ Double subLength = length/5;
+ Double subLength1 = length/6.1;
+ Double angle = mapUtils.getAngle(
+ new MyLatLng((Double) preAngleDeviceList.get(0).get("longitude"),
+ (Double) preAngleDeviceList.get(0).get("latitude")),
+ new MyLatLng((Double) preAngleDeviceList.get(1).get("longitude"),
+ (Double) preAngleDeviceList.get(1).get("latitude")));
+
+ params.put("preAngleDeviceList", preAngleDeviceList);
+ params.put("angle", angle);
+ List locationList = new ArrayList();
+ String[] firstLocation = mapUtils.calLocationByDistanceAndLocationAndDirection(angle, (Double) preAngleDeviceList.get(0).get("longitude"),
+ (Double) preAngleDeviceList.get(0).get("latitude"), subLength);
+ String[] secondLoction = mapUtils.calLocationByDistanceAndLocationAndDirection(angle, Double.parseDouble(firstLocation[0]),
+ Double.parseDouble(firstLocation[1]), subLength);
+ String[] thirdLocation = mapUtils.calLocationByDistanceAndLocationAndDirection(angle, Double.parseDouble(secondLoction[0]),
+ Double.parseDouble(secondLoction[1]), subLength);
+ String[] fourthLoction = mapUtils.calLocationByDistanceAndLocationAndDirection(angle, Double.parseDouble(thirdLocation[0]),
+ Double.parseDouble(thirdLocation[1]), subLength);
+ String[] fivethLoction = mapUtils.calLocationByDistanceAndLocationAndDirection(angle, Double.parseDouble(fourthLoction[0]),
+ Double.parseDouble(fourthLoction[1]), subLength1);
+ locationList.add(firstLocation);
+ locationList.add(secondLoction);
+ locationList.add(thirdLocation);
+ locationList.add(fourthLoction);
+ locationList.add(fivethLoction);
+ params.put("locationList", locationList);
+
+ String preAngleDeviceString = JSON.toJSON(preAngleDeviceList).toString();
+ params.put("preAngleDeviceString", preAngleDeviceString);//���������������������������
+ } else {
+ params.put("preAngleDeviceString", 0);
+ }
+ params.put("wind", wind);
+ //String preAngleDeviceString=preAngleDeviceList.
+ params.put("deviceList", deviceList);
+ }else {
+ if (deviceList.size()!=0){
+ params.put("deviceList", deviceList.get(0));
+ }else {
+ params.put("deviceList","");
+ }
+ params.put("preAngleDeviceString", 1);
+ params.put("locationList", "");
+ }
+
+ params.put("latitudeCompany", latitudeCompany);
+ params.put("longitudeCompany", longitudeCompany);
+ }
+ return params;
+ }
+
+
}
--
Gitblit v1.8.0