pom.xml
@@ -41,11 +41,27 @@ </repositories> <dependencies> <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.5</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.json/json --> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20160810</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> src/main/java/com/moral/controller/ScreenController.java
@@ -1,9 +1,7 @@ package com.moral.controller; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.*; import java.lang.reflect.Array; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.SimpleDateFormat; @@ -17,7 +15,9 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.Expression; import com.moral.common.bean.Constants; @@ -29,15 +29,7 @@ import com.moral.common.util.ValidateUtil; import com.moral.common.util.WebUtils; import com.moral.common.xml.Version; import com.moral.entity.Account; import com.moral.entity.AreaNames; import com.moral.entity.Device; import com.moral.entity.DeviceVersion; import com.moral.entity.MapBounds; import com.moral.entity.MonitorPoint; import com.moral.entity.Organization; import com.moral.entity.Point; import com.moral.entity.Region; import com.moral.entity.*; import com.moral.entity.alarm.AlarmConfig; import com.moral.entity.alarm.AlarmConfigValue; import com.moral.entity.alarm.AlarmSensorLevel; @@ -65,12 +57,14 @@ import com.moral.service.WeatherService; import com.moral.util.*; import com.rabbitmq.client.*; import com.rabbitmq.client.Channel; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import jdk.nashorn.internal.runtime.regexp.joni.Regex; import net.sf.json.JSONString; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.net.ftp.FTPClient; @@ -1953,6 +1947,71 @@ return params; } @GetMapping("/allDevice") @ResponseBody public Map<String,List> getAllDevice() { List<String> macList=deviceService.getAllMac(); Map<String,List> latlngMap=new HashMap<String,List>(); Map devMap=null; List list=new ArrayList(); for (String mac : macList) { devMap=new HashMap(); if (mac!=null){ Device device=deviceService.byMacGetDevice(mac); List list1= LatLngTransformation.Convert_BD09_To_GCJ02(device.getLatitude(),device.getLongitude()); devMap.put("lat",list1.get(1)); devMap.put("lng",list1.get(0)); devMap.put("monitorPointId",device.getMonitorPointId()); //System.out.println(device); list.add(devMap); }else { continue; } } latlngMap.put("latlng",list); return latlngMap; } @GetMapping("/windAndDeviceData") @ResponseBody public List windAndDeviceData(HttpServletRequest request, String monitorPointId) { Calendar c = Calendar.getInstance();//可以对每个时间域单独修改 对时间进行加减操作等 int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); String mon=""; if (month+1<10){ mon="0"+(month+1); }else { mon=(month+1)+""; } int date = c.get(Calendar.DATE); String dt=""; if(date<10){ dt="0"+date; }else { dt=""+date; } int hour = c.get(Calendar.HOUR_OF_DAY); String hu=""; if (hour<10){ hu="0"+hour; }else { hu=""+hour; } int minute = c.get(Calendar.MINUTE); String mu=""; if (minute<10){ mu="0"+minute; }else { mu=""+minute; } String time=year + "-" + mon + "-" + dt + " " +hu + ":" +mu + ":" + "00"; String table="history_minutely_"+year+mon; List list=deviceService.byMonitorIdGetDeviceAndWind(monitorPointId,time,table); return list; } @GetMapping("forecastO3") @ApiOperation(value = "预测和实际臭氧对比", notes = "预测和实际臭氧对比") @ApiImplicitParams(value = { src/main/java/com/moral/entity/DeviceAndWind.java
New file @@ -0,0 +1,64 @@ package com.moral.entity; public class DeviceAndWind { private Double longitude; private Double latitude; private Double windDir; private Double windSpeed; private Double tVoc; public Double gettVoc() { return tVoc; } public void settVoc(Double tVoc) { this.tVoc = tVoc; } public Double getLongitude() { return longitude; } public void setLongitude(Double longitude) { this.longitude = longitude; } public Double getLatitude() { return latitude; } public void setLatitude(Double latitude) { this.latitude = latitude; } public Double getWindDir() { return windDir; } public void setWindDir(Double windDir) { this.windDir = windDir; } public Double getWindSpeed() { return windSpeed; } public void setWindSpeed(Double windSpeed) { this.windSpeed = windSpeed; } @Override public String toString() { return "DeviceAndWind{" + "longitude=" + longitude + ", latitude=" + latitude + ", windDir=" + windDir + ", windSpeed=" + windSpeed + ", tVoc=" + tVoc + '}'; } } src/main/java/com/moral/mapper/DeviceMapper.java
@@ -7,6 +7,7 @@ import com.moral.common.mapper.BaseMapper; import com.moral.entity.Device; import com.moral.entity.DeviceAndWind; import org.apache.ibatis.annotations.Param; import tk.mybatis.mapper.entity.Example; @@ -55,6 +56,18 @@ List<Device> selectDevicesAll(Map<String, Object> params); List<DeviceAndWind> getAllDevice(); List<String> getAllMac(); Device byMacGetDevice(@Param("mac") String mac); DeviceAndWind getDeviceAndWindByMac(@Param("mac") String mac,@Param("time") String time, @Param("table") String table); List<DeviceAndWind> byMonitorIdGetDeviceAndWind(@Param("id") String id,@Param("time") String time, @Param("table") String table); List<Device> getDeviceListByMonitorPointIds(List<Integer> list); Map<String, Object> selectAllFieldByMac(Map<String, Object> params); src/main/java/com/moral/mapper/MonitorPointMapper.java
@@ -24,6 +24,7 @@ MonitorPoint getMonitorPointById(@Param("id") int id); List<MonitorPoint> getMonitorPointListByAccountId(@Param("id") int id); MonitorPoint byIdGetMonitorPoint(@Param("id")int id); MonitorPoint getFirstMonitorPointByAreaCode(@Param("areaCode") int areaCode); src/main/java/com/moral/service/DeviceService.java
@@ -7,6 +7,7 @@ import com.moral.common.bean.PageBean; import com.moral.common.bean.PageResult; import com.moral.entity.Device; import com.moral.entity.DeviceAndWind; import com.moral.entity.DeviceProperty; public interface DeviceService { @@ -72,4 +73,14 @@ List<Device> queryDevice(Map<String,Object> map); Map<String, Object> getAllFieldByMac(Map<String, Object> parameters); List<DeviceAndWind> getAllDevice(); List<String> getAllMac(); Device byMacGetDevice(String mac); List<DeviceAndWind> byMonitorIdGetDeviceAndWind(String id,String time,String tab); DeviceAndWind getDeviceAndWindByMac(String mac,String time,String table); } src/main/java/com/moral/service/MonitorPointService.java
@@ -8,6 +8,7 @@ import com.moral.common.bean.PageBean; import com.moral.entity.Device; import com.moral.entity.MonitorPoint; import org.apache.xmlbeans.impl.jam.mutable.MPackage; public interface MonitorPointService { @@ -53,4 +54,6 @@ JSONObject getMacList(int id); List<MonitorPoint> getMonitorPointListByAccountId(int id); MonitorPoint byIdGetMonitorPoint(int id); } src/main/java/com/moral/service/impl/DeviceServiceImpl.java
@@ -1,16 +1,12 @@ package com.moral.service.impl; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.*; import java.util.stream.Collectors; import javax.annotation.Resource; import javax.validation.constraints.NotNull; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.TypeReference; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; @@ -22,6 +18,7 @@ import com.moral.common.util.RedisUtils; import com.moral.common.util.ValidateUtil; import com.moral.entity.Device; import com.moral.entity.DeviceAndWind; import com.moral.entity.DeviceProperty; import com.moral.entity.MonitorPoint; import com.moral.mapper.DeviceMapper; @@ -32,6 +29,7 @@ import com.moral.mapper.OrganizationMapper; import com.moral.service.AccountService; import com.moral.service.DeviceService; import com.moral.util.LatLngTransformation; import com.moral.util.TkMybatisUtils; import org.apache.commons.collections.MapUtils; @@ -703,4 +701,182 @@ Map<String, Object> deviceMap = deviceMapper.selectAllFieldByMac(parameters); return deviceMap; } @Override public List<DeviceAndWind> getAllDevice() { return deviceMapper.getAllDevice(); } @Override public List<String> getAllMac() { return deviceMapper.getAllMac(); } @Override public Device byMacGetDevice(String mac) { return deviceMapper.byMacGetDevice(mac); } @Override public List byMonitorIdGetDeviceAndWind(String id,String time,String tab) { List<DeviceAndWind> deviceAndWinds=deviceMapper.byMonitorIdGetDeviceAndWind(id,time,tab); List list1=new ArrayList(); List loList=new ArrayList(); List laList=new ArrayList(); Double U=0.0; Double V=0.0; for (DeviceAndWind andWind : deviceAndWinds) { List list2=new ArrayList(); Double lo=andWind.getLongitude(); Double la=andWind.getLatitude(); List list= LatLngTransformation.Convert_BD09_To_GCJ02(la,lo); Double transLo=(Double) list.get(0); Double transLa=(Double) list.get(1); loList.add(transLo); laList.add(transLa); } Double loma= (Double) Collections.max(loList); Double lomi= (Double) Collections.min(loList); Double lama= (Double) Collections.max(laList); Double lami= (Double) Collections.min(laList); Map laLaMap=new HashMap(); laLaMap.put("maxLo",loma); laLaMap.put("minLo",lomi); laLaMap.put("maxLa",lama); laLaMap.put("lami",lami); Double lo1=lomi-250*0.00001141; Double lo2=loma+250*0.00001141; Double la2=lami-250*0.00000899; Double la1=lama+250*0.00000899; Double dx=0.00001141*20; Double dy=0.00000899*20; int nx=(int) Math.floor((lo2-lo1)/dx); int ny=(int) Math.floor((la1-la2)/dy); String header1 = "\"" + "header" + "\"" + ": " + "{" + "\"" + "parameterUnit" + "\"" + ": " + "\"" + "m/s" + "\"" + ", " + "\"" + "parameterNumber" + "\"" + ": " + 2 + ", " + "\"" + "dx" + "\"" + ": " + dx + ", " + "\"" + "dy" + "\"" + ": " + dy + ", " + "\"" + "parameterNumberName" + "\"" + ": " + "\"" + "eastward_wind" + "\"" + ", " + "\"" + "la1" + "\"" + ": " + la1 + ", " + "\"" + "la2" + "\"" + ": " + la2 + ", " + "\"" + "parameterCategory" + "\"" + ": " + 2 + ", " + "\"" + "lo1" + "\"" + ": " + lo1 + ", " + "\"" + "lo2" + "\"" + ": " + lo2 + ", " + "\"" + "nx" + "\"" + ": " + nx + ", " + "\"" + "ny" + "\"" + ": " + ny + ", " + "\"" + "refTime" + "\"" + ": " + "\"" + "2020-07-22 23:00:00" + "\"" + "}"; String header2 = "\"" + "header" + "\"" + ": " + "{" + "\"" + "parameterUnit" + "\"" + ": " + "\"" + "m/s" + "\"" + ", " + "\"" + "parameterNumber" + "\"" + ": " + 3 + ", " + "\"" + "dx" + "\"" + ": " + dx + ", " + "\"" + "dy" + "\"" + ": " + dy + ", " + "\"" + "parameterNumberName" + "\"" + ": " + "\"" + "eastward_wind" + "\"" + ", " + "\"" + "la1" + "\"" + ": " + la1 + ", " + "\"" + "la2" + "\"" + ": " + la2 + ", " + "\"" + "parameterCategory" + "\"" + ": " + 2 + ", " + "\"" + "lo1" + "\"" + ": " + lo1 + ", " + "\"" + "lo2" + "\"" + ": " + lo2 + ", " + "\"" + "nx" + "\"" + ": " + nx + ", " + "\"" + "ny" + "\"" + ": " + ny + ", " + "\"" + "refTime" + "\"" + ": " + "\"" + "2020-07-22 23:00:00" + "\"" + "}"; List<Double> uList=new ArrayList<Double> (); List<Double> vList=new ArrayList<Double> (); int x=0; int y=0; List<Map> mapList=new ArrayList<Map>(); for (int j = 0; j <deviceAndWinds.size() ; j++) { Map<String,Double> map=new HashMap<String,Double> (); Double windDir= deviceAndWinds.get(j).getWindDir(); Double windSpeed=deviceAndWinds.get(j).getWindSpeed(); if (windDir==null){ windDir=0.0; windSpeed=0.0; } Double tvoc=deviceAndWinds.get(j).gettVoc(); List list= LatLngTransformation.Convert_BD09_To_GCJ02(deviceAndWinds.get(j).getLatitude(),deviceAndWinds.get(j).getLongitude()); Double transLo=(Double) list.get(0); Double transLa=(Double) list.get(1); if (tvoc==null){ tvoc=0.0; } Double dir = (270.0 - windDir * Math.PI / 180.0); U = windSpeed * Math.cos(dir); V = windSpeed * Math.sin(dir); map.put("lo",transLo); map.put("la",transLa); map.put("U",U); map.put("V",V); mapList.add(map); } System.out.println(mapList); for (int i = 0; i <mapList.size() ; i++) { Double lo= (Double) mapList.get(i).get("lo"); Double la= (Double) mapList.get(i).get("la"); x= (int) Math.floor((lo-lo1)/dx); y=Math.abs((int)Math.floor((la-la1)/dy)); //y=Math.floor(Math.abs(la-la1)/dy); U=(Double) mapList.get(i).get("U"); V=(Double) mapList.get(i).get("V"); if (i==0){ for (int j = 0; j <nx*ny ; j++) { uList.add(0.0); vList.add(0.0); } } for (int j = 0; j <nx*ny ; j++) { if (i==0){ if ((y>=2 && j==(y)*nx+x)){ int k; System.out.println(nx*ny); for (k = j-2*nx; k <=j+2*nx ;k=k+nx) { System.out.println(k); System.out.println("----------------"); System.out.println(uList.size()); uList.set(k,U); uList.set(k-1,U); uList.set(k-2,U); uList.set(k+1,U); uList.set(k+2,U); vList.set(k,V); vList.set(k-1,V); vList.set(k-2,V); vList.set(k+1,V); vList.set(k+2,V); } } }else { if (y>=1 && j==y*nx+x && uList.get(j)==0.0 && vList.get(j)==0.0){ int k; for (k = j-2*nx; k <=j+2*nx ;) { uList.set(k-1,U); uList.set(k-2,U); uList.set(k+1,U); uList.set(k+2,U); vList.set(k-1,V); vList.set(k-2,V); vList.set(k+1,V); vList.set(k+2,V); k=k+nx; } uList.set(j,U); vList.set(j,V); } } } } String uData = "\"" + "data" + "\"" + ": " + uList; String vData = "\"" + "data" + "\"" + ": " + vList; String s1 = "[" + "{" + header1 + ", " + uData + "}" + ", " + "{" + header2 + ", " + vData + "}" + "]"; JSONArray jsonArray = JSONArray.parseArray(s1); MonitorPoint monitorPoint=monitorPointMapper.byIdGetMonitorPoint(Integer.parseInt(id)); Double monitorLo=monitorPoint.getLongitude(); Double monitorLa=monitorPoint.getLatitude(); List transList= LatLngTransformation.Convert_BD09_To_GCJ02(monitorLa,monitorLo); Double transLo=(Double) transList.get(0); Double transLa=(Double) transList.get(1); List list=new ArrayList(); list.add(jsonArray); list.add(transLo); list.add(transLa); list.add(laLaMap); return list; } @Override public DeviceAndWind getDeviceAndWindByMac(String mac,String time,String table) { return deviceMapper.getDeviceAndWindByMac(mac,time,table); } } src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
@@ -817,5 +817,10 @@ return monitorPointMapper.getMonitorPointListByAccountId(id); } @Override public MonitorPoint byIdGetMonitorPoint(int id) { return monitorPointMapper.byIdGetMonitorPoint(id); } } src/main/java/com/moral/service/impl/OrganizationServiceImpl.java
@@ -60,7 +60,10 @@ return orgIds; } @Override public Organization getOrganizationByMac(Map<String, Object> parameters) { return organizationMapper.getOrganizationByMac(parameters); } @Override public List<Organization> getOrganizationsByAreaName(Map<String, Object> parameters) { ValidateUtil.notNull(parameters.get("areaName"), "param.is.null"); src/main/java/com/moral/webSocketServer/WebSocketServerNew.java
@@ -35,11 +35,6 @@ // 与某个客户端的连接会话,需要通过它来给客户端发送数据 private Session session; private String orgId; private String accountId; private Connection connection; private Channel channel; @@ -116,9 +111,7 @@ @OnClose public void onClose() { //**从安全Set中 移除当前连接对象*//**//**//**//**//**//**//**//* webSocketSet.remove(this); try { connection.close(); src/main/resources/mapper/DeviceMapper.xml
@@ -71,7 +71,8 @@ </when> <when test="criterion.listValue"> and ${criterion.condition} <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=","> #{listItem} </foreach> </when> @@ -82,10 +83,11 @@ </foreach> </where> </sql> <sql id="Base_Column_List"> <sql id="Base_Column_List">z id, name, address, longitude, latitude, mac, operate_user_id, state, is_delete, create_time, install_time, monitor_point_id, device_version_id </sql> <select id="countByTimes" resultType="java.util.Map"> select DATE_FORMAT(create_time,#{format}) as time, COUNT(*) as count from device where create_time >= #{start} @@ -364,6 +366,29 @@ AND mp.is_delete = 0 AND mp.organization_id = #{organizationId} </select> <select id="getAllMac" resultType="java.lang.String"> SELECT mac FROM `device` where state!=4; </select> <select id="byMacGetDevice" resultType="com.moral.entity.Device" resultMap="ResultMap"> SELECT * from device where mac=#{mac} </select> <select id="getDeviceAndWindByMac" resultType="com.moral.entity.DeviceAndWind"> select d.longitude as longitude,d.latitude as latitude, case when h.json->"$.e18[0]"=0 then 0.1 else h.json->"$.e18[0]" end as windSpeed, h.json->"$.e23[0]" as windDir, h.json->"$.e17[0]" as tVoc from ${table} h ,`device` as d where d.mac=h.mac and d.mac=#{mac} and h.time=#{time} </select> <select id="byMonitorIdGetDeviceAndWind" resultType="com.moral.entity.DeviceAndWind"> select d.longitude as longitude,d.latitude as latitude, case when h.json->"$.e18[0]"=0 then 0.1 else h.json->"$.e18[0]" end as windSpeed, h.json->"$.e23[0]" as windDir, h.json->"$.e17[0]" as tVoc from ${table} h ,`device` as d where d.mac=h.mac and h.time=#{time} and d.mac in (select d.mac from device , monitor_point as m where d.monitor_point_id=m.id and m.id=#{id}) </select> <select id="getDevicesStateByRegion" resultType="map"> @@ -480,6 +505,15 @@ AND dev.is_delete =0 </where> </select> <select id="getAllDevice" resultType="com.moral.entity.DeviceAndWind"> select d.longitude as longitude,d.latitude as latitude, case when h.json->"$.e18[0]"=0 then 0.1 else h.json->"$.e18[0]" end as windSpeed, h.json->"$.e23[0]" as windDir from history_minutely_202007 h ,`device` as d where h.time="2020-07-20 15:30:00" and h.json->"$.e23[0]" is not null and h.mac in(SELECT d.mac FROM monitor_point m where d.monitor_point_id=m.id ) </select> <select id="getDeviceListByMonitorPointIds" resultType="com.moral.entity.Device"> select * from device where monitor_point_id in src/main/resources/mapper/MonitorPointMapper.xml
@@ -172,6 +172,9 @@ and o.id=mp.organization_id and a.id=#{id}; </select> <select id="byIdGetMonitorPoint" resultType="com.moral.entity.MonitorPoint"> SELECT * FROM `monitor_point` where id=#{id} </select> <select id="getFirstMonitorPointByAreaCode" resultType="com.moral.entity.MonitorPoint" resultMap="BaseResultMap"> select * from monitor_point where area_code=#{areaCode} limit 0,1 src/main/webapp/view/newUnorganizedMap.jsp
@@ -19,7 +19,7 @@ #box { width: 300px; height: 400px; top: 220px; top: 30px; right: 30px; position: absolute; z-index: 1; @@ -157,10 +157,17 @@ moralMap.showSensors(JSON.parse(JSON.parse(msg.data))); }*/ }; window.onbeforeunload=function(e){ e = window.event||e; //关闭事件 e.returnValue=("确定离开当前页面吗?"); ws.onclose = function () { }; alert(1) } //关闭事件 /*ws.onclose = function () { };*/ //发生了错误事件 ws.onerror = function () { }; src/main/webapp/view/unorganizedMap.jsp
@@ -18,7 +18,7 @@ #box { width:300px; height:400px; top:220px; top:30px; right:30px; position:absolute; z-index:1;