From 15ad247568c26ca595367773af5c49e85ad53713 Mon Sep 17 00:00:00 2001 From: wty <419034340@qq.com> Date: Mon, 27 Feb 2023 11:20:05 +0800 Subject: [PATCH 1/2] add fan zai device management --- .../controller/DataForwardController.java | 2 +- .../controller/FzDeviceManageController.java | 64 +++++++++++++++++++ .../xiuos/dao/mappers/FzDeviceInfoMapper.java | 29 +++++++++ .../com/aiit/xiuos/model/FzDeviceInfo.java | 33 ++++++++++ .../aiit/xiuos/mqtt/MqttConfiguration.java | 1 - .../xiuos/service/FzDeviceInfoService.java | 14 ++++ .../service/impl/FzDeviceInfoServiceImpl.java | 38 +++++++++++ .../aiit/xiuos/tdengine/TDengineJDBCUtil.java | 8 +-- xiuosiot-backend/xiuosiot | 0 9 files changed, 181 insertions(+), 8 deletions(-) create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/FzDeviceManageController.java create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/FzDeviceInfoMapper.java create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/model/FzDeviceInfo.java create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/service/FzDeviceInfoService.java create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/FzDeviceInfoServiceImpl.java create mode 100644 xiuosiot-backend/xiuosiot diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/DataForwardController.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/DataForwardController.java index f1f345a..1626e68 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/DataForwardController.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/DataForwardController.java @@ -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()); } diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/FzDeviceManageController.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/FzDeviceManageController.java new file mode 100644 index 0000000..37fd310 --- /dev/null +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/FzDeviceManageController.java @@ -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 fzDeviceInfos = fzDeviceInfoService.selectByType(type); + return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",fzDeviceInfos); + } + + @GetMapping("/selectAll") + public ResultRespons selectDevice(){ + List fzDeviceInfos = fzDeviceInfoService.selectAll(); + return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",fzDeviceInfos); + } +} diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/FzDeviceInfoMapper.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/FzDeviceInfoMapper.java new file mode 100644 index 0000000..1a68843 --- /dev/null +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/FzDeviceInfoMapper.java @@ -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 selectAll(); + + @Select("select * from fz_device_info where fz_device_type =#{type}") + List selectByType(@Param("type") String type); +} \ No newline at end of file diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/FzDeviceInfo.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/FzDeviceInfo.java new file mode 100644 index 0000000..f9be7a2 --- /dev/null +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/FzDeviceInfo.java @@ -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(); + } +} \ No newline at end of file diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/mqtt/MqttConfiguration.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/mqtt/MqttConfiguration.java index 3d7bd53..546cdaa 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/mqtt/MqttConfiguration.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/mqtt/MqttConfiguration.java @@ -53,7 +53,6 @@ public class MqttConfiguration { // 以/#结尾表示订阅所有以test开头的主题 myMqttClient.subscribe(defaultTopic, 0); log.info("订阅成功"+defaultTopic); - System.out.println("订阅成功"+defaultTopic); return myMqttClient; } } diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/FzDeviceInfoService.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/FzDeviceInfoService.java new file mode 100644 index 0000000..90aaa4f --- /dev/null +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/FzDeviceInfoService.java @@ -0,0 +1,14 @@ +package com.aiit.xiuos.service; + +import com.aiit.xiuos.model.FzDeviceInfo; + +import java.util.List; + +public interface FzDeviceInfoService { + List selectAll(); + List selectByType(String type); + int addDevice(FzDeviceInfo fzDeviceInfo); + int updateDevice(FzDeviceInfo fzDeviceInfo); + int deleteDevice(String deviceNo); + +} diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/FzDeviceInfoServiceImpl.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/FzDeviceInfoServiceImpl.java new file mode 100644 index 0000000..b4fa91e --- /dev/null +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/FzDeviceInfoServiceImpl.java @@ -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 selectAll() { + return fzDeviceInfoMapper.selectAll(); + } + + @Override + public List 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); + } +} diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/tdengine/TDengineJDBCUtil.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/tdengine/TDengineJDBCUtil.java index d84dabd..97aa5b7 100644 --- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/tdengine/TDengineJDBCUtil.java +++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/tdengine/TDengineJDBCUtil.java @@ -71,7 +71,7 @@ public class TDengineJDBCUtil { return null; } - public static ArrayList executeSql(String sql) throws Exception { + public static ArrayList executeQuerySql(String sql) throws Exception { Connection connection = null; ArrayList 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()); diff --git a/xiuosiot-backend/xiuosiot b/xiuosiot-backend/xiuosiot new file mode 100644 index 0000000..e69de29 From e5a974efc266631aba3b1c05b0b069a9b1583be6 Mon Sep 17 00:00:00 2001 From: wty <419034340@qq.com> Date: Mon, 27 Feb 2023 11:22:09 +0800 Subject: [PATCH 2/2] add new mapper.xml --- .../resources/mappers/AlarmInfoMapper.xml | 153 ++++++++++++++++++ .../resources/mappers/FzDeviceInfoMapper.xml | 108 +++++++++++++ 2 files changed, 261 insertions(+) create mode 100644 xiuosiot-backend/src/main/resources/mappers/AlarmInfoMapper.xml create mode 100644 xiuosiot-backend/src/main/resources/mappers/FzDeviceInfoMapper.xml diff --git a/xiuosiot-backend/src/main/resources/mappers/AlarmInfoMapper.xml b/xiuosiot-backend/src/main/resources/mappers/AlarmInfoMapper.xml new file mode 100644 index 0000000..7944124 --- /dev/null +++ b/xiuosiot-backend/src/main/resources/mappers/AlarmInfoMapper.xml @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + device_no, alarm_name, alarm_level, alarm_time, device_type, alarm_status, alarm_res, + org + + + + delete from alarm_info + where device_no = #{deviceNo,jdbcType=VARCHAR} + and alarm_name = #{alarmName,jdbcType=VARCHAR} + and alarm_level = #{alarmLevel,jdbcType=INTEGER} + + + 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 into alarm_info + + + device_no, + + + alarm_name, + + + alarm_level, + + + alarm_time, + + + device_type, + + + alarm_status, + + + alarm_res, + + + org, + + + + + #{deviceNo,jdbcType=VARCHAR}, + + + #{alarmName,jdbcType=VARCHAR}, + + + #{alarmLevel,jdbcType=INTEGER}, + + + #{alarmTime,jdbcType=TIMESTAMP}, + + + #{deviceType,jdbcType=VARCHAR}, + + + #{alarmStatus,jdbcType=INTEGER}, + + + #{alarmRes,jdbcType=VARCHAR}, + + + #{org,jdbcType=VARCHAR}, + + + + + update alarm_info + + + 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 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} + + + \ No newline at end of file diff --git a/xiuosiot-backend/src/main/resources/mappers/FzDeviceInfoMapper.xml b/xiuosiot-backend/src/main/resources/mappers/FzDeviceInfoMapper.xml new file mode 100644 index 0000000..0077392 --- /dev/null +++ b/xiuosiot-backend/src/main/resources/mappers/FzDeviceInfoMapper.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + fz_device_no, fz_device_status, fz_device_type, fz_device_user, fz_outtime, fz_remark + + + + delete from fz_device_info + where fz_device_no = #{fzDeviceNo,jdbcType=VARCHAR} + + + 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 into fz_device_info + + + fz_device_no, + + + fz_device_status, + + + fz_device_type, + + + fz_device_user, + + + fz_outtime, + + + fz_remark, + + + + + #{fzDeviceNo,jdbcType=VARCHAR}, + + + #{fzDeviceStatus,jdbcType=VARCHAR}, + + + #{fzDeviceType,jdbcType=VARCHAR}, + + + #{fzDeviceUser,jdbcType=VARCHAR}, + + + #{fzOuttime,jdbcType=VARCHAR}, + + + #{fzRemark,jdbcType=VARCHAR}, + + + + + update fz_device_info + + + 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 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} + + \ No newline at end of file