This commit is contained in:
龚祖望 2023-03-07 18:01:00 +08:00
commit a764bcf554
11 changed files with 442 additions and 8 deletions

View File

@ -75,7 +75,7 @@ public class DataForwardController {
public ResultRespons executeSql(@RequestParam String sql){
ArrayList resultData = null;
try {
resultData = TDengineJDBCUtil.executeSql(sql);
resultData = TDengineJDBCUtil.executeQuerySql(sql);
} catch (Exception e) {
log.error(e.getMessage());
}

View File

@ -0,0 +1,64 @@
package com.aiit.xiuos.controller;
import com.aiit.xiuos.Utils.Constant;
import com.aiit.xiuos.Utils.GenerateIdUtil;
import com.aiit.xiuos.Utils.MyUtils;
import com.aiit.xiuos.Utils.ResultRespons;
import com.aiit.xiuos.model.DeviceInfo;
import com.aiit.xiuos.model.FzDeviceInfo;
import com.aiit.xiuos.model.UserInfo;
import com.aiit.xiuos.service.FzDeviceInfoService;
import com.aiit.xiuos.tdengine.TDengineJDBCUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@RestController
@RequestMapping("/fzDevice")
@Slf4j
public class FzDeviceManageController {
@Autowired
FzDeviceInfoService fzDeviceInfoService;
@PostMapping("/add")
public ResultRespons addDevice(@RequestBody FzDeviceInfo fzDeviceInfo, HttpServletRequest request){
int res = fzDeviceInfoService.addDevice(fzDeviceInfo);
if(1==res){
return new ResultRespons(Constant.SUCCESS_CODE,"新建设备信息成功!");
}
return new ResultRespons(Constant.ERROR_CODE,"新建设备信息失败!");
}
@PostMapping("/update")
public ResultRespons updateDevice(@RequestBody FzDeviceInfo fzDeviceInfo, HttpServletRequest request){
int res =fzDeviceInfoService.updateDevice(fzDeviceInfo);
if(1==res){
return new ResultRespons(Constant.SUCCESS_CODE,"更新设备信息成功!");
}
return new ResultRespons(Constant.ERROR_CODE,"更新设备信息失败!");
}
@PostMapping("/delete")
public ResultRespons deleteDevice(@RequestBody FzDeviceInfo fzDeviceInfo, HttpServletRequest request){
int res = fzDeviceInfoService.deleteDevice(fzDeviceInfo.getFzDeviceNo());
if(1==res){
return new ResultRespons(Constant.SUCCESS_CODE,"删除设备信息成功!");
}
return new ResultRespons(Constant.ERROR_CODE,"删除设备信息失败!");
}
@GetMapping("/select")
public ResultRespons selectDevice(@RequestParam("type") String type, HttpServletRequest request){
List<FzDeviceInfo> fzDeviceInfos = fzDeviceInfoService.selectByType(type);
return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",fzDeviceInfos);
}
@GetMapping("/selectAll")
public ResultRespons selectDevice(){
List<FzDeviceInfo> fzDeviceInfos = fzDeviceInfoService.selectAll();
return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",fzDeviceInfos);
}
}

View File

@ -0,0 +1,29 @@
package com.aiit.xiuos.dao.mappers;
import com.aiit.xiuos.model.FzDeviceInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface FzDeviceInfoMapper {
int deleteByPrimaryKey(String fzDeviceNo);
int insert(FzDeviceInfo record);
int insertSelective(FzDeviceInfo record);
FzDeviceInfo selectByPrimaryKey(String fzDeviceNo);
int updateByPrimaryKeySelective(FzDeviceInfo record);
int updateByPrimaryKey(FzDeviceInfo record);
@Select("select * from fz_device_info")
List<FzDeviceInfo> selectAll();
@Select("select * from fz_device_info where fz_device_type =#{type}")
List<FzDeviceInfo> selectByType(@Param("type") String type);
}

View File

@ -0,0 +1,33 @@
package com.aiit.xiuos.model;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class FzDeviceInfo {
private String fzDeviceNo;
private String fzDeviceStatus;
private String fzDeviceType;
private String fzDeviceUser;
private String fzOuttime;
private String fzRemark;
public FzDeviceInfo(String fzDeviceNo, String fzDeviceStatus, String fzDeviceType, String fzDeviceUser, String fzOuttime, String fzRemark) {
this.fzDeviceNo = fzDeviceNo;
this.fzDeviceStatus = fzDeviceStatus;
this.fzDeviceType = fzDeviceType;
this.fzDeviceUser = fzDeviceUser;
this.fzOuttime = fzOuttime;
this.fzRemark = fzRemark;
}
public FzDeviceInfo() {
super();
}
}

View File

@ -53,7 +53,6 @@ public class MqttConfiguration {
// /#结尾表示订阅所有以test开头的主题
myMqttClient.subscribe(defaultTopic, 0);
log.info("订阅成功"+defaultTopic);
System.out.println("订阅成功"+defaultTopic);
return myMqttClient;
}
}

View File

@ -0,0 +1,14 @@
package com.aiit.xiuos.service;
import com.aiit.xiuos.model.FzDeviceInfo;
import java.util.List;
public interface FzDeviceInfoService {
List<FzDeviceInfo> selectAll();
List<FzDeviceInfo> selectByType(String type);
int addDevice(FzDeviceInfo fzDeviceInfo);
int updateDevice(FzDeviceInfo fzDeviceInfo);
int deleteDevice(String deviceNo);
}

View File

@ -0,0 +1,38 @@
package com.aiit.xiuos.service.impl;
import com.aiit.xiuos.dao.mappers.FzDeviceInfoMapper;
import com.aiit.xiuos.model.FzDeviceInfo;
import com.aiit.xiuos.service.FzDeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class FzDeviceInfoServiceImpl implements FzDeviceInfoService {
@Autowired
FzDeviceInfoMapper fzDeviceInfoMapper;
@Override
public List<FzDeviceInfo> selectAll() {
return fzDeviceInfoMapper.selectAll();
}
@Override
public List<FzDeviceInfo> selectByType(String type) {
return fzDeviceInfoMapper.selectByType(type);
}
@Override
public int addDevice(FzDeviceInfo fzDeviceInfo) {
return fzDeviceInfoMapper.insert(fzDeviceInfo);
}
@Override
public int updateDevice(FzDeviceInfo fzDeviceInfo) {
return fzDeviceInfoMapper.updateByPrimaryKeySelective(fzDeviceInfo);
}
@Override
public int deleteDevice(String deviceNo) {
return fzDeviceInfoMapper.deleteByPrimaryKey(deviceNo);
}
}

View File

@ -71,7 +71,7 @@ public class TDengineJDBCUtil {
return null;
}
public static ArrayList<String> executeSql(String sql) throws Exception {
public static ArrayList<String> executeQuerySql(String sql) throws Exception {
Connection connection = null;
ArrayList<String> arrayList =new ArrayList<>();
try {
@ -89,12 +89,10 @@ public class TDengineJDBCUtil {
sb.append(columnLabel+":"+value+" ");
}
arrayList.add(sb.toString());
System.out.println(sb.toString());
log.info(sb.toString());
}
return arrayList;
} catch (SQLException e) {
System.out.println("ERROR Message: " + e.getMessage());
System.out.println("ERROR Code: " + e.getErrorCode());
log.error(e.getMessage());
}finally {
try {
@ -152,8 +150,6 @@ public class TDengineJDBCUtil {
log.info("tdengine executeQuery:"+sql);
stmt.executeUpdate(sql);
} catch (SQLException e) {
System.out.println("ERROR Message: " + e.getMessage());
System.out.println("ERROR Code: " + e.getErrorCode());
log.error(e.getMessage());
} catch (Exception e) {
log.error(e.getMessage());

View File

@ -0,0 +1,153 @@
<?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.AlarmInfoMapper">
<resultMap id="BaseResultMap" type="com.aiit.xiuos.model.AlarmInfo">
<constructor>
<idArg column="device_no" javaType="java.lang.String" jdbcType="VARCHAR" />
<idArg column="alarm_name" javaType="java.lang.String" jdbcType="VARCHAR" />
<idArg column="alarm_level" javaType="java.lang.Integer" jdbcType="INTEGER" />
<arg column="alarm_time" javaType="java.util.Date" jdbcType="TIMESTAMP" />
<arg column="device_type" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="alarm_status" javaType="java.lang.Integer" jdbcType="INTEGER" />
<arg column="alarm_res" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="org" javaType="java.lang.String" jdbcType="VARCHAR" />
</constructor>
</resultMap>
<sql id="Base_Column_List">
device_no, alarm_name, alarm_level, alarm_time, device_type, alarm_status, alarm_res,
org
</sql>
<select id="selectByPrimaryKey" parameterType="map" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from alarm_info
where device_no = #{deviceNo,jdbcType=VARCHAR}
and alarm_name = #{alarmName,jdbcType=VARCHAR}
and alarm_level = #{alarmLevel,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="map">
delete from alarm_info
where device_no = #{deviceNo,jdbcType=VARCHAR}
and alarm_name = #{alarmName,jdbcType=VARCHAR}
and alarm_level = #{alarmLevel,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.aiit.xiuos.model.AlarmInfo">
insert into alarm_info (device_no, alarm_name, alarm_level,
alarm_time, device_type, alarm_status,
alarm_res, org)
values (#{deviceNo,jdbcType=VARCHAR}, #{alarmName,jdbcType=VARCHAR}, #{alarmLevel,jdbcType=INTEGER},
#{alarmTime,jdbcType=TIMESTAMP}, #{deviceType,jdbcType=VARCHAR}, #{alarmStatus,jdbcType=INTEGER},
#{alarmRes,jdbcType=VARCHAR}, #{org,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.aiit.xiuos.model.AlarmInfo">
insert into alarm_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deviceNo != null">
device_no,
</if>
<if test="alarmName != null">
alarm_name,
</if>
<if test="alarmLevel != null">
alarm_level,
</if>
<if test="alarmTime != null">
alarm_time,
</if>
<if test="deviceType != null">
device_type,
</if>
<if test="alarmStatus != null">
alarm_status,
</if>
<if test="alarmRes != null">
alarm_res,
</if>
<if test="org != null">
org,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deviceNo != null">
#{deviceNo,jdbcType=VARCHAR},
</if>
<if test="alarmName != null">
#{alarmName,jdbcType=VARCHAR},
</if>
<if test="alarmLevel != null">
#{alarmLevel,jdbcType=INTEGER},
</if>
<if test="alarmTime != null">
#{alarmTime,jdbcType=TIMESTAMP},
</if>
<if test="deviceType != null">
#{deviceType,jdbcType=VARCHAR},
</if>
<if test="alarmStatus != null">
#{alarmStatus,jdbcType=INTEGER},
</if>
<if test="alarmRes != null">
#{alarmRes,jdbcType=VARCHAR},
</if>
<if test="org != null">
#{org,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.AlarmInfo">
update alarm_info
<set>
<if test="alarmTime != null">
alarm_time = #{alarmTime,jdbcType=TIMESTAMP},
</if>
<if test="deviceType != null">
device_type = #{deviceType,jdbcType=VARCHAR},
</if>
<if test="alarmStatus != null">
alarm_status = #{alarmStatus,jdbcType=INTEGER},
</if>
<if test="alarmRes != null">
alarm_res = #{alarmRes,jdbcType=VARCHAR},
</if>
<if test="org != null">
org = #{org,jdbcType=VARCHAR},
</if>
</set>
where device_no = #{deviceNo,jdbcType=VARCHAR}
and alarm_name = #{alarmName,jdbcType=VARCHAR}
and alarm_level = #{alarmLevel,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.aiit.xiuos.model.AlarmInfo">
update alarm_info
set alarm_time = #{alarmTime,jdbcType=TIMESTAMP},
device_type = #{deviceType,jdbcType=VARCHAR},
alarm_status = #{alarmStatus,jdbcType=INTEGER},
alarm_res = #{alarmRes,jdbcType=VARCHAR},
org = #{org,jdbcType=VARCHAR}
where device_no = #{deviceNo,jdbcType=VARCHAR}
and alarm_name = #{alarmName,jdbcType=VARCHAR}
and alarm_level = #{alarmLevel,jdbcType=INTEGER}
</update>
<select id="selectByParam" parameterType="com.aiit.xiuos.model.AlarmInfo" resultMap="BaseResultMap">
select * from alarm_info where org= #{org,jdbcType=VARCHAR}
<if test="deviceNo != null">
and device_no = #{deviceNo,jdbcType=VARCHAR}
</if>
<if test="alarmName != null">
and alarm_name = #{alarmName,jdbcType=VARCHAR}
</if>
<if test="alarmTime != null">
and alarm_time = #{alarmTime,jdbcType=TIMESTAMP}
</if>
<if test="deviceType != null">
and device_type = #{deviceType,jdbcType=VARCHAR}
</if>
<if test="alarmStatus != null">
and alarm_status = #{alarmStatus,jdbcType=INTEGER}
</if>
<if test="alarmLevel != null">
and alarm_level = #{alarmLevel,jdbcType=INTEGER}
</if>
order by alarm_time desc;
</select>
</mapper>

View File

@ -0,0 +1,108 @@
<?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.FzDeviceInfoMapper">
<resultMap id="BaseResultMap" type="com.aiit.xiuos.model.FzDeviceInfo">
<constructor>
<idArg column="fz_device_no" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="fz_device_status" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="fz_device_type" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="fz_device_user" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="fz_outtime" javaType="java.lang.String" jdbcType="VARCHAR" />
<arg column="fz_remark" javaType="java.lang.String" jdbcType="VARCHAR" />
</constructor>
</resultMap>
<sql id="Base_Column_List">
fz_device_no, fz_device_status, fz_device_type, fz_device_user, fz_outtime, fz_remark
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from fz_device_info
where fz_device_no = #{fzDeviceNo,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from fz_device_info
where fz_device_no = #{fzDeviceNo,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.aiit.xiuos.model.FzDeviceInfo">
insert into fz_device_info (fz_device_no, fz_device_status, fz_device_type,
fz_device_user, fz_outtime, fz_remark
)
values (#{fzDeviceNo,jdbcType=VARCHAR}, #{fzDeviceStatus,jdbcType=VARCHAR}, #{fzDeviceType,jdbcType=VARCHAR},
#{fzDeviceUser,jdbcType=VARCHAR}, #{fzOuttime,jdbcType=VARCHAR}, #{fzRemark,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.aiit.xiuos.model.FzDeviceInfo">
insert into fz_device_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="fzDeviceNo != null">
fz_device_no,
</if>
<if test="fzDeviceStatus != null">
fz_device_status,
</if>
<if test="fzDeviceType != null">
fz_device_type,
</if>
<if test="fzDeviceUser != null">
fz_device_user,
</if>
<if test="fzOuttime != null">
fz_outtime,
</if>
<if test="fzRemark != null">
fz_remark,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="fzDeviceNo != null">
#{fzDeviceNo,jdbcType=VARCHAR},
</if>
<if test="fzDeviceStatus != null">
#{fzDeviceStatus,jdbcType=VARCHAR},
</if>
<if test="fzDeviceType != null">
#{fzDeviceType,jdbcType=VARCHAR},
</if>
<if test="fzDeviceUser != null">
#{fzDeviceUser,jdbcType=VARCHAR},
</if>
<if test="fzOuttime != null">
#{fzOuttime,jdbcType=VARCHAR},
</if>
<if test="fzRemark != null">
#{fzRemark,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.FzDeviceInfo">
update fz_device_info
<set>
<if test="fzDeviceStatus != null">
fz_device_status = #{fzDeviceStatus,jdbcType=VARCHAR},
</if>
<if test="fzDeviceType != null">
fz_device_type = #{fzDeviceType,jdbcType=VARCHAR},
</if>
<if test="fzDeviceUser != null">
fz_device_user = #{fzDeviceUser,jdbcType=VARCHAR},
</if>
<if test="fzOuttime != null">
fz_outtime = #{fzOuttime,jdbcType=VARCHAR},
</if>
<if test="fzRemark != null">
fz_remark = #{fzRemark,jdbcType=VARCHAR},
</if>
</set>
where fz_device_no = #{fzDeviceNo,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.aiit.xiuos.model.FzDeviceInfo">
update fz_device_info
set fz_device_status = #{fzDeviceStatus,jdbcType=VARCHAR},
fz_device_type = #{fzDeviceType,jdbcType=VARCHAR},
fz_device_user = #{fzDeviceUser,jdbcType=VARCHAR},
fz_outtime = #{fzOuttime,jdbcType=VARCHAR},
fz_remark = #{fzRemark,jdbcType=VARCHAR}
where fz_device_no = #{fzDeviceNo,jdbcType=VARCHAR}
</update>
</mapper>

View File