新增贵州酒厂数据接入并展示

This commit is contained in:
wty 2023-12-11 10:19:47 +08:00
parent 42c415f37d
commit b67a674caa
2 changed files with 108 additions and 89 deletions

View File

@ -1,7 +1,11 @@
package com.aiit.xiuos.controller; package com.aiit.xiuos.controller;
import cn.hutool.json.JSONUtil;
import com.aiit.xiuos.Utils.MyUtils; import com.aiit.xiuos.Utils.MyUtils;
import com.aiit.xiuos.model.GZJCData;
import com.aiit.xiuos.scheduled.TaskScheduled; import com.aiit.xiuos.scheduled.TaskScheduled;
import com.aiit.xiuos.service.GZJCService;
import com.aiit.xiuos.service.impl.ProtocolServiceImpl; import com.aiit.xiuos.service.impl.ProtocolServiceImpl;
import com.aiit.xiuos.socket.GZJCWebSocketServer;
import com.aiit.xiuos.socket.WebSocketServer; import com.aiit.xiuos.socket.WebSocketServer;
import com.aiit.xiuos.tdengine.TDengineJDBCUtil; import com.aiit.xiuos.tdengine.TDengineJDBCUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
@ -9,9 +13,11 @@ import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@RestController @RestController
@RequestMapping("/exclude") @RequestMapping("/exclude")
@Slf4j @Slf4j
@ -20,7 +26,10 @@ public class ExcludeController {
ProtocolServiceImpl protocolService; ProtocolServiceImpl protocolService;
@Autowired @Autowired
TaskScheduled taskScheduled; TaskScheduled taskScheduled;
@Autowired
GZJCWebSocketServer GZJCWebSocketServer;
@Autowired
GZJCService GZJCService;
@Autowired @Autowired
WebSocketServer webSocketServer; WebSocketServer webSocketServer;
@PostMapping("/addjxsd") @PostMapping("/addjxsd")
@ -40,6 +49,16 @@ public class ExcludeController {
} }
@PostMapping("/addgzjc")
public void addGZJC(@RequestBody GZJCData gzjcData, HttpServletRequest request) throws ParseException {
GZJCWebSocketServer.sendInfo(JSONUtil.toJsonStr(gzjcData));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse(MyUtils.getTime());
gzjcData.setTime(date);
GZJCService.insertData(gzjcData);
}
@GetMapping("/executeAlarmTask") @GetMapping("/executeAlarmTask")
public void executeTask(){ public void executeTask(){
try { try {

View File

@ -27,91 +27,91 @@ public class GZJCTaskScheduled {
@Autowired @Autowired
GZJCService GZJCService; GZJCService GZJCService;
@Scheduled(cron = "0 0 */1 * * ?")//every hour // @Scheduled(cron = "0 0 */1 * * ?")//every hour
public void insertHaierData() throws ParseException { // public void insertHaierData() throws ParseException {
GZJCData GZJCData =mockData(); // GZJCData GZJCData =mockData();
GZJCService.insertData(GZJCData); // GZJCService.insertData(GZJCData);
//
} // }
//
@Scheduled(cron = "0 */1 * * * ?")//every minute // @Scheduled(cron = "0 */1 * * * ?")//every minute
public void sendWebsocket() throws ParseException, IOException { // public void sendWebsocket() throws ParseException, IOException {
GZJCData GZJCData = mockData(); // GZJCData GZJCData = mockData();
JSONObject jsonObject = JSONUtil.parseObj(GZJCData,false,true); // JSONObject jsonObject = JSONUtil.parseObj(GZJCData,false,true);
GZJCWebSocketServer.sendInfo(jsonObject.toString()); // GZJCWebSocketServer.sendInfo(jsonObject.toString());
} // }
//
public GZJCData mockData() throws ParseException { // public GZJCData mockData() throws ParseException {
GZJCData GZJCData =new GZJCData(); // GZJCData GZJCData =new GZJCData();
Random rand = new Random(); // Random rand = new Random();
DecimalFormat df = new DecimalFormat("#.00"); //保留两位数若数据库已截取java可不作保留 // DecimalFormat df = new DecimalFormat("#.00"); //保留两位数若数据库已截取java可不作保留
//生成在max与min之间的随机数 // //生成在max与min之间的随机数
// int randNumber = rand.nextInt(MAX - MIN + 1) + MIN; // // int randNumber = rand.nextInt(MAX - MIN + 1) + MIN;
//
double o3 =rand.nextInt(10)+30+Math.random(); //O3 // double o3 =rand.nextInt(10)+30+Math.random(); //O3
GZJCData.setO3(new BigDecimal(df.format(o3))); // GZJCData.setO3(new BigDecimal(df.format(o3)));
//
double co2 =rand.nextInt(100)+200+Math.random(); //co2 // double co2 =rand.nextInt(100)+200+Math.random(); //co2
GZJCData.setCo2(new BigDecimal(df.format(co2))); // GZJCData.setCo2(new BigDecimal(df.format(co2)));
//
double so2=0.0; //so2 // double so2=0.0; //so2
GZJCData.setSo2(new BigDecimal(df.format(so2))); // GZJCData.setSo2(new BigDecimal(df.format(so2)));
//
double no2=0.0; //no2 // double no2=0.0; //no2
GZJCData.setNo2(new BigDecimal(df.format(no2))); // GZJCData.setNo2(new BigDecimal(df.format(no2)));
//
double nh3=0.0; //nh3 // double nh3=0.0; //nh3
GZJCData.setNh3(new BigDecimal(df.format(nh3))); // GZJCData.setNh3(new BigDecimal(df.format(nh3)));
//
double tvoc = rand.nextInt(1)+Math.random(); //tvoc // double tvoc = rand.nextInt(1)+Math.random(); //tvoc
GZJCData.setTvoc(new BigDecimal(df.format(tvoc))); // GZJCData.setTvoc(new BigDecimal(df.format(tvoc)));
//
double ch2o =0.0; //ch2o // double ch2o =0.0; //ch2o
GZJCData.setCh2o(new BigDecimal(df.format(ch2o))); // GZJCData.setCh2o(new BigDecimal(df.format(ch2o)));
//
double c2h5oh = rand.nextInt(10)+Math.random(); //c2h5oh // double c2h5oh = rand.nextInt(10)+Math.random(); //c2h5oh
GZJCData.setC2h5oh(new BigDecimal(df.format(c2h5oh))); // GZJCData.setC2h5oh(new BigDecimal(df.format(c2h5oh)));
//
double ch4 = 0.0; //ch4 // double ch4 = 0.0; //ch4
GZJCData.setCh4(new BigDecimal(df.format(ch4))); // GZJCData.setCh4(new BigDecimal(df.format(ch4)));
//
double o2 = rand.nextInt(10)+20+Math.random(); //o2 // double o2 = rand.nextInt(10)+20+Math.random(); //o2
GZJCData.setO2(new BigDecimal(df.format(o2))); // GZJCData.setO2(new BigDecimal(df.format(o2)));
//
double aqs = rand.nextInt(30)+200+Math.random(); //aqs // double aqs = rand.nextInt(30)+200+Math.random(); //aqs
GZJCData.setAqs(new BigDecimal(df.format(aqs))); // GZJCData.setAqs(new BigDecimal(df.format(aqs)));
//
double humidness = rand.nextInt(30)+30+Math.random(); //湿度 // double humidness = rand.nextInt(30)+30+Math.random(); //湿度
GZJCData.setHumidness(new BigDecimal(df.format(humidness))); // GZJCData.setHumidness(new BigDecimal(df.format(humidness)));
//
double temperature =rand.nextInt(10)+15+Math.random(); //温度 // double temperature =rand.nextInt(10)+15+Math.random(); //温度
GZJCData.setTemperature(new BigDecimal(df.format(temperature))); // GZJCData.setTemperature(new BigDecimal(df.format(temperature)));
//
double pm1_0=rand.nextInt(20)+Math.random(); //pm1.0 ug/m3 // double pm1_0=rand.nextInt(20)+Math.random(); //pm1.0 ug/m3
GZJCData.setPm1d0(new BigDecimal(df.format(pm1_0))); // GZJCData.setPm1d0(new BigDecimal(df.format(pm1_0)));
//
double pm2_5=rand.nextInt(20)+30+Math.random(); //pm2.5 ug/m3 // double pm2_5=rand.nextInt(20)+30+Math.random(); //pm2.5 ug/m3
GZJCData.setPm2d5(new BigDecimal(df.format(pm2_5))); // GZJCData.setPm2d5(new BigDecimal(df.format(pm2_5)));
//
double pm10=rand.nextInt(20)+50+Math.random(); //pm10 ug/m3 // double pm10=rand.nextInt(20)+50+Math.random(); //pm10 ug/m3
GZJCData.setPm10(new BigDecimal(df.format(pm10))); // GZJCData.setPm10(new BigDecimal(df.format(pm10)));
//
double windspeed = Math.random(); //风速m/s // double windspeed = Math.random(); //风速m/s
GZJCData.setWindspeed(new BigDecimal(df.format(windspeed))); // GZJCData.setWindspeed(new BigDecimal(df.format(windspeed)));
//
double winddirection = rand.nextInt(30)+200; //风向 // double winddirection = rand.nextInt(30)+200; //风向
GZJCData.setWinddirection(new BigDecimal(df.format(winddirection))); // GZJCData.setWinddirection(new BigDecimal(df.format(winddirection)));
//
double airpressure=rand.nextInt(100)+900; //气压 // double airpressure=rand.nextInt(100)+900; //气压
GZJCData.setAirpressure(new BigDecimal(df.format(airpressure))); // GZJCData.setAirpressure(new BigDecimal(df.format(airpressure)));
//
double noise =rand.nextInt(70)+30+Math.random(); //噪音 pd // double noise =rand.nextInt(70)+30+Math.random(); //噪音 pd
GZJCData.setNoise(new BigDecimal(df.format(noise))); // GZJCData.setNoise(new BigDecimal(df.format(noise)));
//
//
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse(MyUtils.getTime()); // Date date = sdf.parse(MyUtils.getTime());
GZJCData.setTime(date); // GZJCData.setTime(date);
return GZJCData; // return GZJCData;
} // }
} }