add haier data to xiuosiot
This commit is contained in:
parent
8a569cf2ba
commit
61f2f2be9f
|
@ -56,6 +56,18 @@ public class FzDeviceManageController {
|
||||||
return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",fzDeviceInfos);
|
return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",fzDeviceInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/selectByNo")
|
||||||
|
public ResultRespons selectDeviceByNo(@RequestParam("device_no") String id, HttpServletRequest request){
|
||||||
|
FzDeviceInfo fzDeviceInfos = fzDeviceInfoService.selectById(id);
|
||||||
|
if(fzDeviceInfos!=null){
|
||||||
|
return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",fzDeviceInfos);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return new ResultRespons(Constant.SUCCESS_CODE,"设备不存在!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/selectAll")
|
@GetMapping("/selectAll")
|
||||||
public ResultRespons selectDevice(){
|
public ResultRespons selectDevice(){
|
||||||
List<FzDeviceInfo> fzDeviceInfos = fzDeviceInfoService.selectAll();
|
List<FzDeviceInfo> fzDeviceInfos = fzDeviceInfoService.selectAll();
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.aiit.xiuos.dao.mappers;
|
||||||
|
|
||||||
|
import com.aiit.xiuos.model.HaierData;
|
||||||
|
|
||||||
|
public interface HaierDataMapper {
|
||||||
|
int deleteByPrimaryKey(Integer id);
|
||||||
|
|
||||||
|
int insert(HaierData record);
|
||||||
|
|
||||||
|
int insertSelective(HaierData record);
|
||||||
|
|
||||||
|
HaierData selectByPrimaryKey(Integer id);
|
||||||
|
|
||||||
|
int updateByPrimaryKeySelective(HaierData record);
|
||||||
|
|
||||||
|
int updateByPrimaryKey(HaierData record);
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
package com.aiit.xiuos.model;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class HaierData {
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private BigDecimal o3;
|
||||||
|
|
||||||
|
private BigDecimal co2;
|
||||||
|
|
||||||
|
private BigDecimal so2;
|
||||||
|
|
||||||
|
private BigDecimal no2;
|
||||||
|
|
||||||
|
private BigDecimal nh3;
|
||||||
|
|
||||||
|
private BigDecimal tvoc;
|
||||||
|
|
||||||
|
private BigDecimal ch2o;
|
||||||
|
|
||||||
|
private BigDecimal c2h5oh;
|
||||||
|
|
||||||
|
private BigDecimal ch4;
|
||||||
|
|
||||||
|
private BigDecimal o2;
|
||||||
|
|
||||||
|
private BigDecimal aqs;
|
||||||
|
|
||||||
|
private BigDecimal humidness;
|
||||||
|
|
||||||
|
private BigDecimal temperature;
|
||||||
|
|
||||||
|
private BigDecimal pm1d0;
|
||||||
|
|
||||||
|
private BigDecimal pm2d5;
|
||||||
|
|
||||||
|
private BigDecimal pm10;
|
||||||
|
|
||||||
|
private BigDecimal windspeed;
|
||||||
|
|
||||||
|
private BigDecimal winddirection;
|
||||||
|
|
||||||
|
private BigDecimal airpressure;
|
||||||
|
|
||||||
|
private Date time;
|
||||||
|
|
||||||
|
private BigDecimal noise;
|
||||||
|
|
||||||
|
public HaierData(Integer id, BigDecimal o3, BigDecimal co2, BigDecimal so2, BigDecimal no2, BigDecimal nh3, BigDecimal tvoc, BigDecimal ch2o, BigDecimal c2h5oh, BigDecimal ch4, BigDecimal o2, BigDecimal aqs, BigDecimal humidness, BigDecimal temperature, BigDecimal pm1d0, BigDecimal pm2d5, BigDecimal pm10, BigDecimal windspeed, BigDecimal winddirection, BigDecimal airpressure, Date time, BigDecimal noise) {
|
||||||
|
this.id = id;
|
||||||
|
this.o3 = o3;
|
||||||
|
this.co2 = co2;
|
||||||
|
this.so2 = so2;
|
||||||
|
this.no2 = no2;
|
||||||
|
this.nh3 = nh3;
|
||||||
|
this.tvoc = tvoc;
|
||||||
|
this.ch2o = ch2o;
|
||||||
|
this.c2h5oh = c2h5oh;
|
||||||
|
this.ch4 = ch4;
|
||||||
|
this.o2 = o2;
|
||||||
|
this.aqs = aqs;
|
||||||
|
this.humidness = humidness;
|
||||||
|
this.temperature = temperature;
|
||||||
|
this.pm1d0 = pm1d0;
|
||||||
|
this.pm2d5 = pm2d5;
|
||||||
|
this.pm10 = pm10;
|
||||||
|
this.windspeed = windspeed;
|
||||||
|
this.winddirection = winddirection;
|
||||||
|
this.airpressure = airpressure;
|
||||||
|
this.time = time;
|
||||||
|
this.noise = noise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HaierData() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,117 @@
|
||||||
|
package com.aiit.xiuos.scheduled;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.aiit.xiuos.Utils.MyUtils;
|
||||||
|
import com.aiit.xiuos.model.HaierData;
|
||||||
|
import com.aiit.xiuos.service.HaierService;
|
||||||
|
import com.aiit.xiuos.socket.HaiErWebSocketServer;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Random;
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class HaierDataTaskScheduled {
|
||||||
|
@Autowired
|
||||||
|
HaiErWebSocketServer haiErWebSocketServer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
HaierService haierService;
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 */1 * * ?")//every hour
|
||||||
|
public void insertHaierData() throws ParseException {
|
||||||
|
HaierData haierData =mockData();
|
||||||
|
haierService.insertData(haierData);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "*/1 * * * * ?")//every hour
|
||||||
|
public void sendWebsocket() throws ParseException, IOException {
|
||||||
|
HaierData haierData = mockData();
|
||||||
|
JSONObject jsonObject = JSONUtil.parseObj(haierData,false,true);
|
||||||
|
haiErWebSocketServer.sendInfo(jsonObject.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public HaierData mockData() throws ParseException {
|
||||||
|
HaierData haierData =new HaierData();
|
||||||
|
Random rand = new Random();
|
||||||
|
DecimalFormat df = new DecimalFormat("#.00"); //保留两位数,若数据库已截取,java可不作保留
|
||||||
|
//生成在max与min之间的随机数
|
||||||
|
// int randNumber = rand.nextInt(MAX - MIN + 1) + MIN;
|
||||||
|
|
||||||
|
double o3 =rand.nextInt(10)+30+Math.random(); //O3
|
||||||
|
haierData.setO3(new BigDecimal(df.format(o3)));
|
||||||
|
|
||||||
|
double co2 =rand.nextInt(100)+200+Math.random(); //co2
|
||||||
|
haierData.setCo2(new BigDecimal(df.format(co2)));
|
||||||
|
|
||||||
|
double so2=0.0; //so2
|
||||||
|
haierData.setSo2(new BigDecimal(df.format(so2)));
|
||||||
|
|
||||||
|
double no2=0.0; //no2
|
||||||
|
haierData.setNo2(new BigDecimal(df.format(no2)));
|
||||||
|
|
||||||
|
double nh3=0.0; //nh3
|
||||||
|
haierData.setNh3(new BigDecimal(df.format(nh3)));
|
||||||
|
|
||||||
|
double tvoc = rand.nextInt(1)+Math.random(); //tvoc
|
||||||
|
haierData.setTvoc(new BigDecimal(df.format(tvoc)));
|
||||||
|
|
||||||
|
double ch2o =0.0; //ch2o
|
||||||
|
haierData.setCh2o(new BigDecimal(df.format(ch2o)));
|
||||||
|
|
||||||
|
double c2h5oh = rand.nextInt(10)+Math.random(); //c2h5oh
|
||||||
|
haierData.setC2h5oh(new BigDecimal(df.format(c2h5oh)));
|
||||||
|
|
||||||
|
double ch4 = 0.0; //ch4
|
||||||
|
haierData.setCh4(new BigDecimal(df.format(ch4)));
|
||||||
|
|
||||||
|
double o2 = rand.nextInt(10)+20+Math.random(); //o2
|
||||||
|
haierData.setO2(new BigDecimal(df.format(o2)));
|
||||||
|
|
||||||
|
double aqs = rand.nextInt(30)+200+Math.random(); //aqs
|
||||||
|
haierData.setAqs(new BigDecimal(df.format(aqs)));
|
||||||
|
|
||||||
|
double humidness = rand.nextInt(30)+30+Math.random(); //湿度
|
||||||
|
haierData.setHumidness(new BigDecimal(df.format(humidness)));
|
||||||
|
|
||||||
|
double temperature =rand.nextInt(10)+15+Math.random(); //温度
|
||||||
|
haierData.setTemperature(new BigDecimal(df.format(temperature)));
|
||||||
|
|
||||||
|
double pm1_0=rand.nextInt(20)+Math.random(); //pm1.0 ug/m3
|
||||||
|
haierData.setPm1d0(new BigDecimal(df.format(pm1_0)));
|
||||||
|
|
||||||
|
double pm2_5=rand.nextInt(20)+30+Math.random(); //pm2.5 ug/m3
|
||||||
|
haierData.setPm2d5(new BigDecimal(df.format(pm2_5)));
|
||||||
|
|
||||||
|
double pm10=rand.nextInt(20)+50+Math.random(); //pm10 ug/m3
|
||||||
|
haierData.setPm10(new BigDecimal(df.format(pm10)));
|
||||||
|
|
||||||
|
double windspeed = Math.random(); //风速m/s
|
||||||
|
haierData.setWindspeed(new BigDecimal(df.format(windspeed)));
|
||||||
|
|
||||||
|
double winddirection = rand.nextInt(30)+200; //风向
|
||||||
|
haierData.setWinddirection(new BigDecimal(df.format(winddirection)));
|
||||||
|
|
||||||
|
double airpressure=rand.nextInt(100)+900+Math.random(); //气压
|
||||||
|
haierData.setAirpressure(new BigDecimal(df.format(airpressure)));
|
||||||
|
|
||||||
|
double noise =rand.nextInt(71)+30+Math.random(); //噪音 pd
|
||||||
|
haierData.setNoise(new BigDecimal(df.format(noise)));
|
||||||
|
|
||||||
|
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
Date date = sdf.parse(MyUtils.getTime());
|
||||||
|
haierData.setTime(date);
|
||||||
|
return haierData;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||||
public interface FzDeviceInfoService {
|
public interface FzDeviceInfoService {
|
||||||
List<FzDeviceInfo> selectAll();
|
List<FzDeviceInfo> selectAll();
|
||||||
List<FzDeviceInfo> selectByType(String type);
|
List<FzDeviceInfo> selectByType(String type);
|
||||||
|
FzDeviceInfo selectById(String id);
|
||||||
int addDevice(FzDeviceInfo fzDeviceInfo);
|
int addDevice(FzDeviceInfo fzDeviceInfo);
|
||||||
int updateDevice(FzDeviceInfo fzDeviceInfo);
|
int updateDevice(FzDeviceInfo fzDeviceInfo);
|
||||||
int deleteDevice(String deviceNo);
|
int deleteDevice(String deviceNo);
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.aiit.xiuos.service;
|
||||||
|
|
||||||
|
import com.aiit.xiuos.model.HaierData;
|
||||||
|
|
||||||
|
public interface HaierService {
|
||||||
|
int insertData(HaierData data);
|
||||||
|
HaierData selectData();
|
||||||
|
}
|
|
@ -21,6 +21,11 @@ public class FzDeviceInfoServiceImpl implements FzDeviceInfoService {
|
||||||
return fzDeviceInfoMapper.selectByType(type);
|
return fzDeviceInfoMapper.selectByType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FzDeviceInfo selectById(String deviceNo) {
|
||||||
|
return fzDeviceInfoMapper.selectByPrimaryKey( deviceNo);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int addDevice(FzDeviceInfo fzDeviceInfo) {
|
public int addDevice(FzDeviceInfo fzDeviceInfo) {
|
||||||
return fzDeviceInfoMapper.insert(fzDeviceInfo);
|
return fzDeviceInfoMapper.insert(fzDeviceInfo);
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.aiit.xiuos.service.impl;
|
||||||
|
|
||||||
|
import com.aiit.xiuos.dao.mappers.HaierDataMapper;
|
||||||
|
import com.aiit.xiuos.model.HaierData;
|
||||||
|
import com.aiit.xiuos.service.HaierService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class HaierServiceImpl implements HaierService {
|
||||||
|
@Autowired
|
||||||
|
HaierDataMapper haierDataMapper;
|
||||||
|
@Override
|
||||||
|
public int insertData(HaierData data) {
|
||||||
|
return haierDataMapper.insertSelective(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HaierData selectData() {
|
||||||
|
return haierDataMapper.selectData();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +0,0 @@
|
||||||
package com.aiit.xiuos.socket;
|
|
||||||
|
|
||||||
public class SocketServer {
|
|
||||||
}
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.aiit.xiuos.dao.mappers.DeviceLogInfoMapper">
|
||||||
|
<resultMap id="BaseResultMap" type="com.aiit.xiuos.model.DeviceLogInfo">
|
||||||
|
<constructor>
|
||||||
|
<idArg column="device_no" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||||
|
<idArg column="log_time" javaType="java.util.Date" jdbcType="TIMESTAMP" />
|
||||||
|
<arg column="device_type" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||||
|
<arg column="thread_no" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||||
|
<arg column="log_level" javaType="java.lang.Integer" jdbcType="INTEGER" />
|
||||||
|
<arg column="device_log" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||||
|
<arg column="org" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||||
|
</constructor>
|
||||||
|
</resultMap>
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
device_no, log_time, device_type, thread_no, log_level, device_log, org
|
||||||
|
</sql>
|
||||||
|
<select id="selectByPrimaryKey" parameterType="map" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from device_log_info
|
||||||
|
where device_no = #{deviceNo,jdbcType=VARCHAR}
|
||||||
|
and log_time = #{logTime,jdbcType=TIMESTAMP}
|
||||||
|
</select>
|
||||||
|
<delete id="deleteByPrimaryKey" parameterType="map">
|
||||||
|
delete from device_log_info
|
||||||
|
where device_no = #{deviceNo,jdbcType=VARCHAR}
|
||||||
|
and log_time = #{logTime,jdbcType=TIMESTAMP}
|
||||||
|
</delete>
|
||||||
|
<insert id="insert" parameterType="com.aiit.xiuos.model.DeviceLogInfo">
|
||||||
|
insert into device_log_info (device_no, log_time, device_type,
|
||||||
|
thread_no, log_level, device_log,
|
||||||
|
org)
|
||||||
|
values (#{deviceNo,jdbcType=VARCHAR}, #{logTime,jdbcType=TIMESTAMP}, #{deviceType,jdbcType=VARCHAR},
|
||||||
|
#{threadNo,jdbcType=VARCHAR}, #{logLevel,jdbcType=INTEGER}, #{deviceLog,jdbcType=VARCHAR},
|
||||||
|
#{org,jdbcType=VARCHAR})
|
||||||
|
</insert>
|
||||||
|
<insert id="insertSelective" parameterType="com.aiit.xiuos.model.DeviceLogInfo">
|
||||||
|
insert into device_log_info
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="deviceNo != null">
|
||||||
|
device_no,
|
||||||
|
</if>
|
||||||
|
<if test="logTime != null">
|
||||||
|
log_time,
|
||||||
|
</if>
|
||||||
|
<if test="deviceType != null">
|
||||||
|
device_type,
|
||||||
|
</if>
|
||||||
|
<if test="threadNo != null">
|
||||||
|
thread_no,
|
||||||
|
</if>
|
||||||
|
<if test="logLevel != null">
|
||||||
|
log_level,
|
||||||
|
</if>
|
||||||
|
<if test="deviceLog != null">
|
||||||
|
device_log,
|
||||||
|
</if>
|
||||||
|
<if test="org != null">
|
||||||
|
org,
|
||||||
|
</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="deviceNo != null">
|
||||||
|
#{deviceNo,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="logTime != null">
|
||||||
|
#{logTime,jdbcType=TIMESTAMP},
|
||||||
|
</if>
|
||||||
|
<if test="deviceType != null">
|
||||||
|
#{deviceType,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="threadNo != null">
|
||||||
|
#{threadNo,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="logLevel != null">
|
||||||
|
#{logLevel,jdbcType=INTEGER},
|
||||||
|
</if>
|
||||||
|
<if test="deviceLog != null">
|
||||||
|
#{deviceLog,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="org != null">
|
||||||
|
#{org,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
<update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.DeviceLogInfo">
|
||||||
|
update device_log_info
|
||||||
|
<set>
|
||||||
|
<if test="deviceType != null">
|
||||||
|
device_type = #{deviceType,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="threadNo != null">
|
||||||
|
thread_no = #{threadNo,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="logLevel != null">
|
||||||
|
log_level = #{logLevel,jdbcType=INTEGER},
|
||||||
|
</if>
|
||||||
|
<if test="deviceLog != null">
|
||||||
|
device_log = #{deviceLog,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
<if test="org != null">
|
||||||
|
org = #{org,jdbcType=VARCHAR},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where device_no = #{deviceNo,jdbcType=VARCHAR}
|
||||||
|
and log_time = #{logTime,jdbcType=TIMESTAMP}
|
||||||
|
</update>
|
||||||
|
<update id="updateByPrimaryKey" parameterType="com.aiit.xiuos.model.DeviceLogInfo">
|
||||||
|
update device_log_info
|
||||||
|
set device_type = #{deviceType,jdbcType=VARCHAR},
|
||||||
|
thread_no = #{threadNo,jdbcType=VARCHAR},
|
||||||
|
log_level = #{logLevel,jdbcType=INTEGER},
|
||||||
|
device_log = #{deviceLog,jdbcType=VARCHAR},
|
||||||
|
org = #{org,jdbcType=VARCHAR}
|
||||||
|
where device_no = #{deviceNo,jdbcType=VARCHAR}
|
||||||
|
and log_time = #{logTime,jdbcType=TIMESTAMP}
|
||||||
|
</update>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue