奥体项目数据问题修改
正在显示
3 个修改的文件
包含
213 行增加
和
1 行删除
... | @@ -1415,6 +1415,16 @@ public class OlympicCenterServiceImpl implements IOlympicCenterService { | ... | @@ -1415,6 +1415,16 @@ public class OlympicCenterServiceImpl implements IOlympicCenterService { |
1415 | map.put("name",whatStructData.getMonitorName()); | 1415 | map.put("name",whatStructData.getMonitorName()); |
1416 | map.put("time",""); | 1416 | map.put("time",""); |
1417 | map.put("value",""); | 1417 | map.put("value",""); |
1418 | for (Map<String, Object> mMap : monitorList ) { | ||
1419 | if(whatStructData.getMonitorId()!=null){ | ||
1420 | if(whatStructData.getMonitorId().equals(mMap.get("monitorid"))){ | ||
1421 | map.put("time",timeStampToDateStr(mMap.get("time"))); | ||
1422 | map.put("value",formatDouble(Double.parseDouble(mMap.get("monitorvalue").toString())*Double.parseDouble(whatStructData.getMonitorZoom()))); | ||
1423 | } | ||
1424 | }else{ | ||
1425 | break; | ||
1426 | } | ||
1427 | } | ||
1418 | list.add(map); | 1428 | list.add(map); |
1419 | } | 1429 | } |
1420 | }else{ | 1430 | }else{ | ... | ... |
... | @@ -119,7 +119,7 @@ public class YwLocationServiceImpl implements ILocationService { | ... | @@ -119,7 +119,7 @@ public class YwLocationServiceImpl implements ILocationService { |
119 | userBaseInfo.setUserType("员工"); | 119 | userBaseInfo.setUserType("员工"); |
120 | if(onlineMap.get(userBaseInfoYwResult.getDeviceno())!=null){ | 120 | if(onlineMap.get(userBaseInfoYwResult.getDeviceno())!=null){ |
121 | userBaseInfo.setUserStatus("1"); | 121 | userBaseInfo.setUserStatus("1"); |
122 | UserLocation userLocation = JSON.parseObject(onlineMap.get(userBaseInfoYwResult.getDeviceno()).toString(), UserLocation.class); | 122 | UserLocation userLocation = JSON.parseObject(JSON.toJSONString(onlineMap.get(userBaseInfoYwResult.getDeviceno())), UserLocation.class); |
123 | userBaseInfo.setX(userLocation.getX()); | 123 | userBaseInfo.setX(userLocation.getX()); |
124 | userBaseInfo.setY(userLocation.getY()); | 124 | userBaseInfo.setY(userLocation.getY()); |
125 | userBaseInfo.setFloor(userLocation.getFloor()); | 125 | userBaseInfo.setFloor(userLocation.getFloor()); | ... | ... |
1 | package com.skua.modules.quartz.job; | ||
2 | |||
3 | |||
4 | import cn.hutool.http.HttpRequest; | ||
5 | import cn.hutool.http.HttpUtil; | ||
6 | import cn.hutool.http.Method; | ||
7 | import com.fasterxml.jackson.databind.ObjectMapper; | ||
8 | import com.skua.core.cache.RedisUtil; | ||
9 | import com.skua.core.context.SpringContextUtils; | ||
10 | import lombok.SneakyThrows; | ||
11 | import lombok.extern.slf4j.Slf4j; | ||
12 | import org.quartz.Job; | ||
13 | import org.quartz.JobExecutionContext; | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | ||
15 | import org.springframework.jdbc.core.JdbcTemplate; | ||
16 | |||
17 | import java.math.BigDecimal; | ||
18 | import java.text.DecimalFormat; | ||
19 | import java.time.LocalDateTime; | ||
20 | import java.time.format.DateTimeFormatter; | ||
21 | import java.util.Map; | ||
22 | import java.util.Random; | ||
23 | |||
24 | /** | ||
25 | * 同步河南焦作采集数据 | ||
26 | */ | ||
27 | @Slf4j | ||
28 | public class SyncHnjzDataJob implements Job { | ||
29 | |||
30 | // private static final String HNJZ_URL = "https://399w65q886.oicp.vip/parsing/api/RiverMonitoring/RiverwayHXW";//河南焦作数据同步地址-测试 | ||
31 | private static final String HNJZ_URL = "http://123.60.20.81:9876/parsing/api/RiverMonitoring/RiverwayHXW";//河南焦作数据同步地址-正式 | ||
32 | @Autowired | ||
33 | private RedisUtil redisUtil; | ||
34 | //格式化时间 | ||
35 | private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
36 | |||
37 | private String parameter; | ||
38 | |||
39 | public void setParameter(String parameter) { | ||
40 | this.parameter = parameter; | ||
41 | } | ||
42 | |||
43 | @SneakyThrows | ||
44 | @Override | ||
45 | public void execute(JobExecutionContext jobExecutionContext) { | ||
46 | LocalDateTime now = LocalDateTime.now(); | ||
47 | String cjDateTime = now.format(formatter); | ||
48 | log.info(String.format(" 同步河南焦作采集数据 ! 时间:" + cjDateTime)); | ||
49 | JdbcTemplate hxDB = (JdbcTemplate) SpringContextUtils.getBean("mysql-hx"); | ||
50 | String sql = "SELECT " + | ||
51 | " id,\n" + | ||
52 | " create_by as createBy,\n" + | ||
53 | " create_time as createTime,\n" + | ||
54 | " update_by as updateBy,\n" + | ||
55 | " update_time as updateTime,\n" + | ||
56 | " sys_org_code as sysOrgCode,\n" + | ||
57 | " del_flag as delFlag,\n" + | ||
58 | " eqm_id as eqmId,\n" + | ||
59 | " eqm_no as eqmNo,\n" + | ||
60 | " eqm_name as eqmName,\n" + | ||
61 | " project_id as projectId,\n" + | ||
62 | " area_id as areaId,\n" + | ||
63 | " temperature,\n" + | ||
64 | " humidity,\n" + | ||
65 | " battery,\n" + | ||
66 | " rssi,\n" + | ||
67 | " sinr,\n" + | ||
68 | " batpercent,\n" + | ||
69 | " datatype1,\n" + | ||
70 | " datavalue1,\n" + | ||
71 | " newdatavalue1,\n" + | ||
72 | " datatype2,\n" + | ||
73 | " datavalue2,\n" + | ||
74 | " newdatavalue2,\n" + | ||
75 | " datatype3,\n" + | ||
76 | " datavalue3,\n" + | ||
77 | " newdatavalue3,\n" + | ||
78 | " datatype4,\n" + | ||
79 | " datavalue4,\n" + | ||
80 | " newdatavalue4,\n" + | ||
81 | " collect_time as collectTime,\n" + | ||
82 | " remark,\n" + | ||
83 | " platform_id as platformId,\n" + | ||
84 | " tcp_flag as tcpFlag,\n" + | ||
85 | " datatype5,\n" + | ||
86 | " datavalue5,\n" + | ||
87 | " datatype6,\n" + | ||
88 | " datavalue6,\n" + | ||
89 | " datatype7,\n" + | ||
90 | " datavalue7,\n" + | ||
91 | " datatype8,\n" + | ||
92 | " datavalue8,\n" + | ||
93 | " light,\n" + | ||
94 | " lat,\n" + | ||
95 | " lng,\n" + | ||
96 | " x_axis as xAxis,\n" + | ||
97 | " y_axis as yAxis,\n" + | ||
98 | " hostch_no as hostchNo\n" + | ||
99 | " FROM\n" + | ||
100 | " dcs_current_info \n" + | ||
101 | " WHERE\n" + | ||
102 | " platform_id = 'JJ202309250005' \n" + | ||
103 | " ORDER BY\n" + | ||
104 | " create_time DESC \n" + | ||
105 | " LIMIT 1"; | ||
106 | Map<String,Object> map = hxDB.queryForMap(sql); | ||
107 | if("mn".equals(this.parameter)){ | ||
108 | map.put("id",null); | ||
109 | map.put("temperature",randomZhengShu(17,19)); | ||
110 | map.put("humidity",randomZhengShu(50,60)); | ||
111 | map.put("battery",randomXiaoShu(7.00,8.00)); | ||
112 | map.put("rssi",randomZhengShu(-113,-100)); | ||
113 | map.put("sinr",randomZhengShu(20,26)); | ||
114 | map.put("batpercent",randomZhengShu(60,100)); | ||
115 | map.put("datatype1",1); | ||
116 | double datavalue1 = randomXiaoShu(0.03,0.06); | ||
117 | map.put("datavalue1",datavalue1); | ||
118 | map.put("newdatavalue1",datavalue1); | ||
119 | map.put("datatype2",2); | ||
120 | double datavalue2 = randomXiaoShu(0.01,0.015); | ||
121 | map.put("datavalue2",datavalue2); | ||
122 | map.put("newdatavalue2",datavalue2); | ||
123 | map.put("dataValueSsll",calculateLS( datavalue1, datavalue2, 1.65)); | ||
124 | map.put("collectTime",cjDateTime); | ||
125 | map.put("createTime",cjDateTime); | ||
126 | map.put("updateTime",cjDateTime); | ||
127 | map.put("light",randomXiaoShu(3.00,4.00)); | ||
128 | map.put("remark",null); | ||
129 | log.info("河南焦作数据同步请求参数为:"+map); | ||
130 | }else{ | ||
131 | if(map.size() > 0){ | ||
132 | String collectTime = map.get("collectTime").toString(); | ||
133 | double yw = 0.00; | ||
134 | double ls = 0.00; | ||
135 | if(map.get("datavalue1")!=null){ | ||
136 | yw = Double.parseDouble(map.get("datavalue1").toString()); | ||
137 | } | ||
138 | if(map.get("datavalue2")!=null){ | ||
139 | ls = Double.parseDouble(map.get("datavalue2").toString()); | ||
140 | } | ||
141 | map.put("dataValueSsll",calculateLS( yw, ls, 1.65)); | ||
142 | String key = "hnjz-"+collectTime; | ||
143 | Object code = redisUtil.get(key); | ||
144 | if(code==null){ | ||
145 | redisUtil.set(key, map); | ||
146 | log.info("河南焦作数据同步请求参数为("+key+"):"+map); | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | ObjectMapper mapper = new ObjectMapper(); | ||
151 | String json = mapper.writeValueAsString(map); | ||
152 | HttpRequest request = HttpUtil.createPost(HNJZ_URL); | ||
153 | request.contentType("application/json"); | ||
154 | request.body(json); | ||
155 | String post = request.execute().body(); | ||
156 | log.info("回复的消息为:"+post); | ||
157 | } | ||
158 | |||
159 | public static void main(String[] args) { | ||
160 | System.out.println("随机数:" + calculateLS( 0.03, 0.015, 1.65)); | ||
161 | } | ||
162 | |||
163 | public static int randomZhengShu(int min, int max){ | ||
164 | Random random = new Random(); | ||
165 | int randomNumber = random.nextInt(max - min + 1) + min; | ||
166 | return randomNumber; | ||
167 | } | ||
168 | |||
169 | public static double randomXiaoShu(double min,double max){ | ||
170 | Random random = new Random(); | ||
171 | double randomNumber = min + (max - min) * random.nextDouble(); | ||
172 | DecimalFormat decimalFormat = new DecimalFormat("#.###"); | ||
173 | String formattedNumber = decimalFormat.format(randomNumber); | ||
174 | return Double.parseDouble(formattedNumber); | ||
175 | } | ||
176 | |||
177 | /** | ||
178 | * 流量计算 | ||
179 | * @param currentValue | ||
180 | * @param speedValue | ||
181 | * @param tubedia | ||
182 | * @return | ||
183 | */ | ||
184 | public static String calculateLS(double currentValue, double speedValue, double tubedia) { | ||
185 | double H = currentValue; //水深(液位),计算流量的设备一定会同时上传流速speed(单位m/s)和液位值level(单位m/s) | ||
186 | double D = tubedia; //圆管直径diam,单位m | ||
187 | double R = D / 2; //管道半径 | ||
188 | double S = 0; //圆管截面积 | ||
189 | if (H >= D) { | ||
190 | S = Math.PI * R * R; | ||
191 | } else if (H <= R) { | ||
192 | double ang = Math.acos((R - H) / R) * R * R; | ||
193 | S = ang - Math.sqrt(R * R - (R - H) * (R - H)) * Math.abs(R - H); | ||
194 | } else if (R < H && H < D) { | ||
195 | double ang = Math.acos((R - H) / R) * R * R; | ||
196 | S = ang + Math.sqrt(R * R - (R - H) * (R - H)) * Math.abs(R - H); | ||
197 | } | ||
198 | //计算瞬时流量flow,单位m3/s | ||
199 | DecimalFormat df = new DecimalFormat("#.####"); | ||
200 | return df.format(speedValue * S); | ||
201 | } | ||
202 | } |
-
请 注册 或 登录 后发表评论