Browse Source

提供首页数据接口

王先生 2 years ago
parent
commit
3f3e4076d6
18 changed files with 320 additions and 25 deletions
  1. 64 0
      eladmin-common/src/main/java/me/zhengjie/base/BaseResponse.java
  2. 33 0
      eladmin-common/src/main/java/me/zhengjie/base/QueryPageParams.java
  3. 3 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historydata/domain/DmEnvHistoryData.java
  4. 1 2
      eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historydata/service/dto/DmEnvHistoryDataDto.java
  5. 3 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historymodbusdata/domain/DmEnvHistoryModbusData.java
  6. 1 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historymodbusdata/service/dto/DmEnvHistoryModbusDataDto.java
  7. 5 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historywarnconfig/repository/DmEnvHistoryWarnConfigRepository.java
  8. 2 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historywarnconfig/service/DmEnvHistoryWarnConfigService.java
  9. 5 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historywarnconfig/service/impl/DmEnvHistoryWarnConfigServiceImpl.java
  10. 6 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/domain/DmModbusDevice.java
  11. 3 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/repository/DmModbusDeviceRepository.java
  12. 23 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/rest/DmModbusDeviceController.java
  13. 2 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/service/DmModbusDeviceService.java
  14. 2 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/service/dto/DmModbusDeviceDto.java
  15. 5 0
      eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/service/impl/DmModbusDeviceServiceImpl.java
  16. 118 23
      eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/ModbusTask.java
  17. 1 0
      eladmin-system/src/main/java/me/zhengjie/modules/thirdparty/v1/modbus/ModbusController.java
  18. 43 0
      eladmin-system/src/main/java/me/zhengjie/modules/thirdparty/v1/rocket/RocketController.java

+ 64 - 0
eladmin-common/src/main/java/me/zhengjie/base/BaseResponse.java

@@ -0,0 +1,64 @@
+package me.zhengjie.base;
+
+import java.io.Serializable;
+
+public class BaseResponse<T>  implements Serializable {
+
+    private int status;
+    private String message;
+    private T data;
+    private Long timestamp;
+
+    public BaseResponse(T data) {
+        this.setStatus(200);
+        this.setData(data);
+        this.setMessage("sucess");
+        this.setTimestamp(System.currentTimeMillis());
+    }
+
+    public BaseResponse(T data, int code) {
+        this.setStatus(code);
+        this.setData(data);
+        this.setMessage("sucess");
+        this.setTimestamp(System.currentTimeMillis());
+    }
+
+    public BaseResponse(T data, int code, String message) {
+        this.setStatus(code);
+        this.setData(data);
+        this.setMessage(message);
+        this.setTimestamp(System.currentTimeMillis());
+    }
+
+    public int getStatus() {
+        return status;
+    }
+
+    public void setStatus(int status) {
+        this.status = status;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public T getData() {
+        return data;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+
+    public Long getTimestamp() {
+        return timestamp;
+    }
+
+    public void setTimestamp(Long timestamp) {
+        this.timestamp = timestamp;
+    }
+}

+ 33 - 0
eladmin-common/src/main/java/me/zhengjie/base/QueryPageParams.java

@@ -0,0 +1,33 @@
+package me.zhengjie.base;
+
+public class QueryPageParams<T> {
+    private String timestamp;
+    private String nonce;
+
+    public String getTimestamp() {
+        return timestamp;
+    }
+
+    public void setTimestamp(String timestamp) {
+        this.timestamp = timestamp;
+    }
+
+    public String getNonce() {
+        return nonce;
+    }
+
+    public void setNonce(String nonce) {
+        this.nonce = nonce;
+    }
+
+    private T query;
+
+    public T getQuery() {
+        return query;
+    }
+
+    public void setQuery(T query) {
+        this.query = query;
+    }
+
+}

+ 3 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historydata/domain/DmEnvHistoryData.java

@@ -15,6 +15,8 @@
 */
 package me.zhengjie.modules.dm.envmonitor.historydata.domain;
 
+import com.alibaba.fastjson.annotation.JSONField;
+import com.alibaba.fastjson.serializer.ToStringSerializer;
 import lombok.Data;
 import cn.hutool.core.bean.BeanUtil;
 import io.swagger.annotations.ApiModelProperty;
@@ -50,6 +52,7 @@ public class DmEnvHistoryData extends BaseEntity implements Serializable {
     @GeneratedValue(strategy = GenerationType.IDENTITY)
     @Column(name = "id")
     @ApiModelProperty(value = "主键")
+    @JSONField(serializeUsing = ToStringSerializer.class)
     private Long id;
 
     @Column(name = "device_identifier")

+ 1 - 2
eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historydata/service/dto/DmEnvHistoryDataDto.java

@@ -16,12 +16,11 @@
 package me.zhengjie.modules.dm.envmonitor.historydata.service.dto;
 
 import com.alibaba.fastjson.annotation.JSONField;
-import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.alibaba.fastjson.serializer.ToStringSerializer;
 import lombok.Data;
 import me.zhengjie.base.BaseDTO;
 import me.zhengjie.modules.dm.envmonitor.historymodbusdata.domain.DmEnvHistoryModbusData;
 
-import java.sql.Timestamp;
 import java.io.Serializable;
 import java.util.Set;
 

+ 3 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historymodbusdata/domain/DmEnvHistoryModbusData.java

@@ -15,6 +15,8 @@
 */
 package me.zhengjie.modules.dm.envmonitor.historymodbusdata.domain;
 
+import com.alibaba.fastjson.annotation.JSONField;
+import com.alibaba.fastjson.serializer.ToStringSerializer;
 import lombok.Data;
 import cn.hutool.core.bean.BeanUtil;
 import io.swagger.annotations.ApiModelProperty;
@@ -38,6 +40,7 @@ public class DmEnvHistoryModbusData implements Serializable {
     @Id
     @Column(name = "id")
     @ApiModelProperty(value = "主键")
+    @JSONField(serializeUsing = ToStringSerializer.class)
     private Long id;
 
     @Column(name = "CHO")

+ 1 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historymodbusdata/service/dto/DmEnvHistoryModbusDataDto.java

@@ -51,6 +51,7 @@ public class DmEnvHistoryModbusDataDto implements Serializable {
     private String voc;
 
     /** 关联对象id */
+    @JSONField(serializeUsing = ToStringSerializer.class)
     private Long dataId;
 
     private Date createTime;

+ 5 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historywarnconfig/repository/DmEnvHistoryWarnConfigRepository.java

@@ -18,6 +18,8 @@ package me.zhengjie.modules.dm.envmonitor.historywarnconfig.repository;
 import me.zhengjie.modules.dm.envmonitor.historywarnconfig.domain.DmEnvHistoryWarnConfig;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 
 /**
 * @website https://el-admin.vip
@@ -25,4 +27,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 * @date 2022-05-19
 **/
 public interface DmEnvHistoryWarnConfigRepository extends JpaRepository<DmEnvHistoryWarnConfig, Long>, JpaSpecificationExecutor<DmEnvHistoryWarnConfig> {
+
+   @Query(value = "SELECT config.* FROM dm_env_history_warn_config config where config.data_item = :cho",nativeQuery = true)
+    DmEnvHistoryWarnConfig selectWarnDataByName(@Param("cho") String cho);
 }

+ 2 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historywarnconfig/service/DmEnvHistoryWarnConfigService.java

@@ -80,4 +80,6 @@ public interface DmEnvHistoryWarnConfigService {
     * @throws IOException /
     */
     void download(List<DmEnvHistoryWarnConfigDto> all, HttpServletResponse response) throws IOException;
+
+    DmEnvHistoryWarnConfig selectWarnDataByName(String cho);
 }

+ 5 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/envmonitor/historywarnconfig/service/impl/DmEnvHistoryWarnConfigServiceImpl.java

@@ -106,4 +106,9 @@ public class DmEnvHistoryWarnConfigServiceImpl implements DmEnvHistoryWarnConfig
         }
         FileUtil.downloadExcel(list, response);
     }
+
+    @Override
+    public DmEnvHistoryWarnConfig selectWarnDataByName(String cho) {
+        return dmEnvHistoryWarnConfigRepository.selectWarnDataByName(cho);
+    }
 }

+ 6 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/domain/DmModbusDevice.java

@@ -126,6 +126,12 @@ public class DmModbusDevice extends BaseEntity implements Serializable {
     @JSONField(serializeUsing = ToStringSerializer.class)
     private Long channelId;
 
+
+    @ApiModelProperty(value = "状态")
+    @Column(name = "device_status",nullable = false)
+    @NotNull
+    private String deviceStatus;
+
     @ApiModelProperty(value = "关联的分组")
     @OneToMany(fetch = FetchType.LAZY,cascade = {CascadeType.REFRESH})
     @JoinColumn(name = "device_id")

+ 3 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/repository/DmModbusDeviceRepository.java

@@ -18,6 +18,7 @@ package me.zhengjie.modules.dm.modbus.device.repository;
 import me.zhengjie.modules.dm.modbus.device.domain.DmModbusDevice;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
 
 /**
 * @website https://el-admin.vip
@@ -25,4 +26,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 * @date 2022-05-20
 **/
 public interface DmModbusDeviceRepository extends JpaRepository<DmModbusDevice, Long>, JpaSpecificationExecutor<DmModbusDevice> {
+   @Query(value = " select count(distinct(device_id)) from dm_modbus_device where  if(:status IS NOT NULL,device_status = :status,1=1 ) ",nativeQuery = true)
+    Long getModbusCount(Integer status);
 }

+ 23 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/rest/DmModbusDeviceController.java

@@ -28,6 +28,9 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import io.swagger.annotations.*;
 import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
 import javax.servlet.http.HttpServletResponse;
 
 /**
@@ -84,4 +87,24 @@ public class DmModbusDeviceController {
         dmModbusDeviceService.deleteAll(ids);
         return new ResponseEntity<>(HttpStatus.OK);
     }
+
+    @Log("统计modbus设备信息")
+    @ApiOperation("统计modbus设别信息")
+    @GetMapping(value = "getModbusStatistics")
+    public ResponseEntity<Object> getModbusStatistics(){
+        //获取在线设备数量
+        Long online = dmModbusDeviceService.getModbusCount(1);
+        // 获取离线设备数量
+        Long offline = dmModbusDeviceService.getModbusCount(0);
+        // 获取全部设备数量
+        Long allCount = dmModbusDeviceService.getModbusCount(null);
+        // 获取在线率
+         BigDecimal onlineRate = (BigDecimal.valueOf(online).divide(BigDecimal.valueOf(allCount), 2, BigDecimal.ROUND_HALF_UP)).multiply(BigDecimal.valueOf(100));
+        Map<String,Object> map = new HashMap<>();
+        map.put("allCount", allCount);
+        map.put("online",online);
+        map.put("offline",offline);
+        map.put("onlineRate",onlineRate.toString());
+        return new ResponseEntity<>(map,HttpStatus.OK);
+    }
 }

+ 2 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/service/DmModbusDeviceService.java

@@ -80,4 +80,6 @@ public interface DmModbusDeviceService {
     * @throws IOException /
     */
     void download(List<DmModbusDeviceDto> all, HttpServletResponse response) throws IOException;
+
+    Long getModbusCount(Integer status);
 }

+ 2 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/service/dto/DmModbusDeviceDto.java

@@ -90,4 +90,6 @@ public class DmModbusDeviceDto extends BaseDTO implements Serializable {
 
     /** 关联的分组 */
     private Set<DmModbusGroup> dmModbusGroup;
+
+    private String deviceStatus;
 }

+ 5 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/modbus/device/service/impl/DmModbusDeviceServiceImpl.java

@@ -121,4 +121,9 @@ public class DmModbusDeviceServiceImpl implements DmModbusDeviceService {
         }
         FileUtil.downloadExcel(list, response);
     }
+
+    @Override
+    public Long getModbusCount(Integer status) {
+        return dmModbusDeviceRepository.getModbusCount(status);
+    }
 }

+ 118 - 23
eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/ModbusTask.java

@@ -11,6 +11,7 @@ package me.zhengjie.modules.quartz.task;/**
  * Description: iot-ykt
  */
 
+import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.digitalpetri.modbus.codec.Modbus;
 import com.digitalpetri.modbus.master.ModbusTcpMaster;
@@ -27,28 +28,29 @@ import io.netty.buffer.ByteBuf;
 import io.netty.util.ReferenceCountUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import me.zhengjie.modules.dm.envmonitor.historydata.domain.DmEnvHistoryData;
 import me.zhengjie.modules.dm.envmonitor.historymodbusdata.domain.DmEnvHistoryModbusData;
 import me.zhengjie.modules.dm.envmonitor.historymodbusdata.service.DmEnvHistoryModbusDataService;
+import me.zhengjie.modules.dm.envmonitor.historywarn.domain.DmEnvHistoryWarn;
+import me.zhengjie.modules.dm.envmonitor.historywarn.service.DmEnvHistoryWarnService;
+import me.zhengjie.modules.dm.envmonitor.historywarnconfig.domain.DmEnvHistoryWarnConfig;
+import me.zhengjie.modules.dm.envmonitor.historywarnconfig.service.DmEnvHistoryWarnConfigService;
 import me.zhengjie.modules.dm.modbus.channel.domain.DmModbusChannel;
 import me.zhengjie.modules.dm.modbus.data.domain.DmModbusData;
 import me.zhengjie.modules.dm.modbus.device.domain.DmModbusDevice;
-import me.zhengjie.modules.dm.modbus.drive.domain.DmModbusDrive;
 import me.zhengjie.modules.dm.modbus.drive.service.DmModbusDriveService;
 import me.zhengjie.modules.dm.modbus.drive.service.dto.DmModbusDriveDto;
 import me.zhengjie.modules.dm.modbus.group.domain.DmModbusGroup;
-import me.zhengjie.modules.system.repository.UserRepository;
 import me.zhengjie.utils.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
-import org.springframework.web.bind.annotation.InitBinder;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import java.sql.Timestamp;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * <功能简要> <br>
@@ -67,11 +69,15 @@ public class ModbusTask {
 
     private final DmEnvHistoryModbusDataService dmEnvHistoryModbusDataService;
 
+    private final DmEnvHistoryWarnConfigService dmEnvHistoryWarnConfigService;
+
+    private final DmEnvHistoryWarnService dmEnvHistoryWarnService;
+
     @Value("${modbusUrl}")
     private String modbusUrl; // modbus默认地址
     private final int modbusPort = 502; // modbus默认端口号
     private final int modbusSalveId = 1;  //modbus默认从机地址
-    private static ModbusTcpMaster master;
+    private ModbusTcpMaster master;
 
     /**
      * 获取TCP协议的Master
@@ -89,7 +95,7 @@ public class ModbusTask {
 
     public void  gainModbusData() {
         try {
-            init();
+//            init();
             /**
              * 根据sql查询所有总集合
              */
@@ -123,7 +129,7 @@ public class ModbusTask {
 //                                               DmEnvHistoryData dmEnvHistoryData = new DmEnvHistoryData();
 //                                              Set<DmEnvHistoryData> dmEnvHistoryDataSet = new HashSet<>();
                                               //已经确认 空气质量统一用3X(Input  Register)  数据类型为short
-
+                                               AtomicReference<String> F = new AtomicReference<>("");
                                               dmModbusData.forEach(data->{
                                                   try {
                                                       switch (data.getSoftwareRegisterType()){
@@ -172,49 +178,138 @@ public class ModbusTask {
                                                               //默认使用 3X(Input  Register)
                                                               log.info("调用读取InputRegisters模拟量数据");
                                                                   // 读取数据 数据类型为 float Integer.valueOf(data.getSoftwareRegisterAddress())
-                                                                  Number number = readInputRegisters(Integer.valueOf(data.getSoftwareRegisterAddress()), 4, modbusSalveId);
+                                                                  Number number = readInputRegisters(Integer.valueOf(data.getSoftwareRegisterAddress())-1, 4, modbusSalveId);
+//                                                                    Number number = 321;
                                                                   //获取点名 例如 1F_CO2
                                                                   String callTheRoll = data.getCallTheRoll();
                                                                   log.info("{}寄存器地址:{}",callTheRoll,data.getSoftwareRegisterAddress());
                                                                   // 获取楼层id
-                                                                  String F = StringUtils.substringBefore(callTheRoll, "F");
+                                                                   F.set(StringUtils.substringBefore(callTheRoll, "F"));
                                                                   // 获取检测的数据名称
                                                                   String dataName = StringUtils.substringAfterLast(callTheRoll, "_");
                                                                   switch (dataName){
                                                                       case "CHO":
+                                                                          DmEnvHistoryWarnConfig dmEnvHistoryWarnConfigCho = dmEnvHistoryWarnConfigService.selectWarnDataByName("CHO");
                                                                           dmEnvHistoryModbusData.setCho(number.toString());
+                                                                          if (!ObjectUtil.isEmpty(dmEnvHistoryWarnConfigCho) && Integer.valueOf(dmEnvHistoryModbusData.getCho())>=Integer.valueOf(dmEnvHistoryWarnConfigCho.getWarnValue())){
+                                                                              DmEnvHistoryWarn dmEnvHistoryWarn = new DmEnvHistoryWarn();
+                                                                              dmEnvHistoryWarn.setCreateTime(new Timestamp(System.currentTimeMillis()));
+                                                                              dmEnvHistoryWarn.setDeviceIdentifier(device.getDeviceId().toString());
+                                                                              dmEnvHistoryWarn.setDeviceName(device.getDeviceName());
+                                                                              dmEnvHistoryWarn.setWarnIndex(dmEnvHistoryWarnConfigCho.getWarnValue());
+                                                                              dmEnvHistoryWarn.setWarnValue(dmEnvHistoryModbusData.getCho());
+                                                                              dmEnvHistoryWarn.setWarnContent("甲醛过高");
+                                                                              dmEnvHistoryWarnService.create(dmEnvHistoryWarn);
+                                                                          }
                                                                           break;
                                                                       case "CO2":
+                                                                          DmEnvHistoryWarnConfig dmEnvHistoryWarnConfigCo2 = dmEnvHistoryWarnConfigService.selectWarnDataByName("CO2");
                                                                           dmEnvHistoryModbusData.setCo2(number.toString());
+                                                                          if (!ObjectUtil.isEmpty(dmEnvHistoryWarnConfigCo2) && Integer.valueOf(dmEnvHistoryModbusData.getCo2())>=Integer.valueOf(dmEnvHistoryWarnConfigCo2.getWarnValue())){
+                                                                              DmEnvHistoryWarn dmEnvHistoryWarn = new DmEnvHistoryWarn();
+                                                                              dmEnvHistoryWarn.setCreateTime(new Timestamp(System.currentTimeMillis()));
+                                                                              dmEnvHistoryWarn.setDeviceIdentifier(device.getDeviceId().toString());
+                                                                              dmEnvHistoryWarn.setDeviceName(device.getDeviceName());
+                                                                              dmEnvHistoryWarn.setWarnIndex(dmEnvHistoryWarnConfigCo2.getWarnValue());
+                                                                              dmEnvHistoryWarn.setWarnValue(dmEnvHistoryModbusData.getCo2());
+                                                                              dmEnvHistoryWarn.setWarnContent("二氧化碳过高");
+                                                                              dmEnvHistoryWarnService.create(dmEnvHistoryWarn);
+                                                                          }
                                                                           break;
                                                                       case "H":
+                                                                          DmEnvHistoryWarnConfig dmEnvHistoryWarnConfigH = dmEnvHistoryWarnConfigService.selectWarnDataByName("H");
                                                                           dmEnvHistoryModbusData.setH(number.toString());
+                                                                          if (!ObjectUtil.isEmpty(dmEnvHistoryWarnConfigH) && Integer.valueOf(dmEnvHistoryModbusData.getH())>=Integer.valueOf(dmEnvHistoryWarnConfigH.getWarnValue())){
+                                                                              DmEnvHistoryWarn dmEnvHistoryWarn = new DmEnvHistoryWarn();
+                                                                              dmEnvHistoryWarn.setCreateTime(new Timestamp(System.currentTimeMillis()));
+                                                                              dmEnvHistoryWarn.setDeviceIdentifier(device.getDeviceId().toString());
+                                                                              dmEnvHistoryWarn.setDeviceName(device.getDeviceName());
+                                                                              dmEnvHistoryWarn.setWarnIndex(dmEnvHistoryWarnConfigH.getWarnValue());
+                                                                              dmEnvHistoryWarn.setWarnValue(dmEnvHistoryModbusData.getH());
+                                                                              dmEnvHistoryWarn.setWarnContent("湿度过高");
+                                                                              dmEnvHistoryWarnService.create(dmEnvHistoryWarn);
+                                                                          }
                                                                           break;
                                                                       case "PM10":
+                                                                          DmEnvHistoryWarnConfig dmEnvHistoryWarnConfigPm10 = dmEnvHistoryWarnConfigService.selectWarnDataByName("PM10");
                                                                           dmEnvHistoryModbusData.setPm10(number.toString());
+                                                                          if (!ObjectUtil.isEmpty(dmEnvHistoryWarnConfigPm10) && Integer.valueOf(dmEnvHistoryModbusData.getPm10())>=Integer.valueOf(dmEnvHistoryWarnConfigPm10.getWarnValue())){
+                                                                              DmEnvHistoryWarn dmEnvHistoryWarn = new DmEnvHistoryWarn();
+                                                                              dmEnvHistoryWarn.setCreateTime(new Timestamp(System.currentTimeMillis()));
+                                                                              dmEnvHistoryWarn.setDeviceIdentifier(device.getDeviceId().toString());
+                                                                              dmEnvHistoryWarn.setDeviceName(device.getDeviceName());
+                                                                              dmEnvHistoryWarn.setWarnIndex(dmEnvHistoryWarnConfigPm10.getWarnValue());
+                                                                              dmEnvHistoryWarn.setWarnValue(dmEnvHistoryModbusData.getPm10());
+                                                                              dmEnvHistoryWarn.setWarnContent("pm10过高");
+                                                                              dmEnvHistoryWarnService.create(dmEnvHistoryWarn);
+                                                                          }
+                                                                          break;
+                                                                      case "PM25":
+                                                                          DmEnvHistoryWarnConfig dmEnvHistoryWarnConfigPm25 = dmEnvHistoryWarnConfigService.selectWarnDataByName("PM25");
+                                                                          dmEnvHistoryModbusData.setPm25(number.toString());
+                                                                          if (!ObjectUtil.isEmpty(dmEnvHistoryWarnConfigPm25) && Integer.valueOf(dmEnvHistoryModbusData.getPm25())>=Integer.valueOf(dmEnvHistoryWarnConfigPm25.getWarnValue())){
+                                                                              DmEnvHistoryWarn dmEnvHistoryWarn = new DmEnvHistoryWarn();
+                                                                              dmEnvHistoryWarn.setCreateTime(new Timestamp(System.currentTimeMillis()));
+                                                                              dmEnvHistoryWarn.setDeviceIdentifier(device.getDeviceId().toString());
+                                                                              dmEnvHistoryWarn.setDeviceName(device.getDeviceName());
+                                                                              dmEnvHistoryWarn.setWarnIndex(dmEnvHistoryWarnConfigPm25.getWarnValue());
+                                                                              dmEnvHistoryWarn.setWarnValue(dmEnvHistoryModbusData.getPm25());
+                                                                              dmEnvHistoryWarn.setWarnContent("pm2.5过高");
+                                                                              dmEnvHistoryWarnService.create(dmEnvHistoryWarn);
+                                                                          }
                                                                           break;
                                                                       case "T":
+                                                                          DmEnvHistoryWarnConfig dmEnvHistoryWarnConfigT = dmEnvHistoryWarnConfigService.selectWarnDataByName("T");
                                                                           dmEnvHistoryModbusData.setT(number.toString());
+                                                                          if (!ObjectUtil.isEmpty(dmEnvHistoryWarnConfigT) && Integer.valueOf(dmEnvHistoryModbusData.getT())>=Integer.valueOf(dmEnvHistoryWarnConfigT.getWarnValue())){
+                                                                              DmEnvHistoryWarn dmEnvHistoryWarn = new DmEnvHistoryWarn();
+                                                                              dmEnvHistoryWarn.setCreateTime(new Timestamp(System.currentTimeMillis()));
+                                                                              dmEnvHistoryWarn.setDeviceIdentifier(device.getDeviceId().toString());
+                                                                              dmEnvHistoryWarn.setDeviceName(device.getDeviceName());
+                                                                              dmEnvHistoryWarn.setWarnIndex(dmEnvHistoryWarnConfigT.getWarnValue());
+                                                                              dmEnvHistoryWarn.setWarnValue(dmEnvHistoryModbusData.getT());
+                                                                              dmEnvHistoryWarn.setWarnContent("温度过高");
+                                                                              dmEnvHistoryWarnService.create(dmEnvHistoryWarn);
+                                                                          }
                                                                           break;
                                                                       case "VOC":
+                                                                          DmEnvHistoryWarnConfig dmEnvHistoryWarnConfigVoc = dmEnvHistoryWarnConfigService.selectWarnDataByName("VOC");
                                                                           dmEnvHistoryModbusData.setVoc(number.toString());
+                                                                          if (!ObjectUtil.isEmpty(dmEnvHistoryWarnConfigVoc) && Integer.valueOf(dmEnvHistoryModbusData.getVoc())>=Integer.valueOf(dmEnvHistoryWarnConfigVoc.getWarnValue())){
+                                                                              DmEnvHistoryWarn dmEnvHistoryWarn = new DmEnvHistoryWarn();
+                                                                              dmEnvHistoryWarn.setCreateTime(new Timestamp(System.currentTimeMillis()));
+                                                                              dmEnvHistoryWarn.setDeviceIdentifier(device.getDeviceId().toString());
+                                                                              dmEnvHistoryWarn.setDeviceName(device.getDeviceName());
+                                                                              dmEnvHistoryWarn.setWarnIndex(dmEnvHistoryWarnConfigVoc.getWarnValue());
+                                                                              dmEnvHistoryWarn.setWarnValue(dmEnvHistoryModbusData.getVoc());
+                                                                              dmEnvHistoryWarn.setWarnContent("VOC过高");
+                                                                              dmEnvHistoryWarnService.create(dmEnvHistoryWarn);
+                                                                          }
                                                                           break;
                                                                   }
-                                                                  //设置关联id
-                                                                  dmEnvHistoryModbusData.setDataId(Long.valueOf(F));
+
                                                                   break;
                                                       }
-                                                  }catch (InterruptedException e) {
-                                                      log.error("调用读取InputRegisters模拟量数据,modbus读取数据失败,失败原因:{}",e.getMessage());
-                                                      return;
-                                                  } catch (ExecutionException e) {
+                                                  }catch (Exception e) {
                                                       log.error("调用读取InputRegisters模拟量数据,modbus读取数据失败,失败原因:{}",e.getMessage());
                                                       return;
                                                   }
+//                                                  catch (InterruptedException e) {
+//                                                      log.error("调用读取InputRegisters模拟量数据,modbus读取数据失败,失败原因:{}",e.getMessage());
+//                                                      return;
+//                                                  } catch (ExecutionException e) {
+//                                                      log.error("调用读取InputRegisters模拟量数据,modbus读取数据失败,失败原因:{}",e.getMessage());
+//                                                      return;
+//                                                  }
                                               });
-                                              dmEnvHistoryModbusData.setCreateTime(new Date());
-                                              dmEnvHistoryModbusDataService.create(dmEnvHistoryModbusData);
-                                              log.info("添加的modbus的数据,{}" + JSONObject.toJSONString(dmEnvHistoryModbusData) );
+
+                                              if (!ObjectUtil.isEmpty(dmEnvHistoryModbusData)){
+                                                  //设置关联id
+                                                  dmEnvHistoryModbusData.setDataId(Long.valueOf(F.get()));
+                                                  dmEnvHistoryModbusData.setCreateTime(new Date());
+                                                  dmEnvHistoryModbusDataService.create(dmEnvHistoryModbusData);
+                                                  log.info("添加的modbus的数据,{}" + JSONObject.toJSONString(dmEnvHistoryModbusData) );
+                                              }
                                           }
                                      });
                                  }
@@ -225,10 +320,10 @@ public class ModbusTask {
             });
 
             log.info("所有的驱动下的数据,{}" + JSONObject.toJSONString(dmModbusDriveDtos) );
-            release();
+//            release();
         }catch (Exception e){
             log.error("modbus获取失败,失败原因:{}",e.getMessage());
-            release();
+//            release();
             return;
         }
 
@@ -321,7 +416,7 @@ public class ModbusTask {
      * @throws ExecutionException
      *             异常
      */
-    public static Number readHoldingRegisters(int address, int quantity, int unitId)
+    public  Number readHoldingRegisters(int address, int quantity, int unitId)
             throws InterruptedException, ExecutionException {
         Number result = null;
         CompletableFuture<ReadHoldingRegistersResponse> future = master
@@ -350,7 +445,7 @@ public class ModbusTask {
      * @throws ExecutionException
      *             异常
      */
-    public static Number readInputRegisters(int address, int quantity, int unitId)
+    public  Number readInputRegisters(int address, int quantity, int unitId)
             throws InterruptedException, ExecutionException {
         Number result = null;
         CompletableFuture<ReadInputRegistersResponse> future = master

+ 1 - 0
eladmin-system/src/main/java/me/zhengjie/modules/thirdparty/v1/modbus/ModbusController.java

@@ -16,6 +16,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.annotation.rest.AnonymousGetMapping;
 import me.zhengjie.annotation.rest.AnonymousPostMapping;
+import me.zhengjie.base.BaseResponse;
 import me.zhengjie.modules.quartz.task.ModbusTask;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;

+ 43 - 0
eladmin-system/src/main/java/me/zhengjie/modules/thirdparty/v1/rocket/RocketController.java

@@ -0,0 +1,43 @@
+/**
+ * Copyright (C), 2022-04-13
+ * FileName: RocketController
+ * Author:   wanglongda
+ * Date:     2022/4/13 16:10
+ * Description: rocket
+ */
+package me.zhengjie.modules.thirdparty.v1.rocket;/**
+ * Created Name: wanglongda
+ * Created Time: 2022/4/13 16:10
+ * Description: iot-ykt
+ */
+
+import io.swagger.annotations.Api;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <功能简要> <br>
+ * <rocket>
+ *
+ * @Author wanglongda
+ * @createTime 2022/4/13 16:10
+ * @Version 1.0.0
+ */
+@Slf4j
+@RestController
+@RequiredArgsConstructor
+@Api(tags = "MQ接口")
+@RequestMapping("/MQTest")
+public class RocketController {
+    private final String topic = "accessTrafficTopic";
+//    @Resource
+//    private Producer producer;
+//
+//    @AnonymousGetMapping("/sendMessage")
+//    public String sendMessage(String message) {
+//        producer.sendMessage(topic, message);
+//        return "消息发送完成";
+//    }
+}