diff --git a/2024新增脚本.sql b/2024新增脚本.sql
index b35be3f..6033a94 100644
--- a/2024新增脚本.sql
+++ b/2024新增脚本.sql
@@ -220,4 +220,17 @@ EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'停止位', @l
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'校验位', @level0type=N'Schema', @level0name=N'dbo', @level1type=N'Table', @level1name=N'device_params', @level2type=N'Column', @level2name=N'parity';
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注', @level0type=N'Schema', @level0name=N'dbo', @level1type=N'Table', @level1name=N'device_params', @level2type=N'Column', @level2name=N'remark';
--- 2024-08-22
\ No newline at end of file
+-- 2024-08-22
+
+-- 2028-09-02
+ALTER TABLE devices_manage ADD factory_barcode varchar(100) NULL;
+EXEC sys.sp_addextendedproperty 'MS_Description', N'出厂条码', 'schema', N'dbo', 'table', N'devices_manage', 'column', N'factory_barcode';
+ALTER TABLE devices_manage ADD imu_code varchar(100) NULL;
+EXEC sys.sp_addextendedproperty 'MS_Description', N'IMU编码', 'schema', N'dbo', 'table', N'devices_manage', 'column', N'imu_code';
+
+ALTER TABLE meter_manage ADD register_size int DEFAULT 1 NULL;
+EXEC sys.sp_addextendedproperty 'MS_Description', N'寄存器大小', 'schema', N'dbo', 'table', N'meter_manage', 'column', N'register_size';
+
+ALTER TABLE meter_manage ADD is_use bit DEFAULT 1 NULL;
+EXEC sys.sp_addextendedproperty 'MS_Description', N'当前采集点位是否启用', 'schema', N'dbo', 'table', N'meter_manage', 'column', N'is_use';
+
diff --git a/common/pom.xml b/common/pom.xml
index 978d63e..e741fed 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -31,27 +31,40 @@
- com.github.pagehelper
- pagehelper
- 6.1.0
-
-
- com.github.jsqlparser
- jsqlparser
-
-
-
-
- com.github.pagehelper
- sqlparser4.5
- 6.1.0
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.5.7
+
com.github.pagehelper
- sqlparser-timeout
- 6.1.0
+ pagehelper-spring-boot-starter
+ 2.1.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
org.springframework.boot
diff --git a/common/src/main/java/com/mh/common/page/PageRequest.java b/common/src/main/java/com/mh/common/page/PageRequest.java
index 97ed3dd..0853802 100644
--- a/common/src/main/java/com/mh/common/page/PageRequest.java
+++ b/common/src/main/java/com/mh/common/page/PageRequest.java
@@ -20,7 +20,7 @@ public class PageRequest {
/**
* 每页数量
*/
- private Map columnFilters = new HashMap();
+ private Map columnFilter = new HashMap();
public int getPageNum() {
return pageNum;
@@ -34,13 +34,13 @@ public class PageRequest {
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
- public Map getColumnFilters() {
- return columnFilters;
+ public Map getColumnFilter() {
+ return columnFilter;
}
- public void setColumnFilters(Map columnFilters) {
- this.columnFilters = columnFilters;
+ public void setColumnFilter(Map columnFilters) {
+ this.columnFilter = columnFilters;
}
public ColumnFilter getColumnFilter(String name) {
- return columnFilters.get(name);
+ return columnFilter.get(name);
}
}
diff --git a/user-service/pom.xml b/user-service/pom.xml
index d11c324..854ea4b 100644
--- a/user-service/pom.xml
+++ b/user-service/pom.xml
@@ -86,18 +86,6 @@
-
- com.baomidou
- mybatis-plus-boot-starter
- 3.5.7
-
-
- com.github.jsqlparser
- jsqlparser
-
-
-
-
diff --git a/user-service/src/main/java/com/mh/user/constants/Constant.java b/user-service/src/main/java/com/mh/user/constants/Constant.java
index a4a65c6..65589e8 100644
--- a/user-service/src/main/java/com/mh/user/constants/Constant.java
+++ b/user-service/src/main/java/com/mh/user/constants/Constant.java
@@ -9,10 +9,21 @@ package com.mh.user.constants;
*/
public class Constant {
- public static boolean CONTROL_WEB_FLAG = false;
+ public static final String FAIL = "fail";
+ public static final String SUCCESS = "success";
+ public static boolean CONTROL_WEB_FLAG = false;
public static boolean SEND_STATUS = false; // 指令发送状态
public static boolean FLAG = false;
public static boolean WEB_FLAG = false; // 判断是否有前端指令下发
public static int projectId=1; // 项目编号
+
+ public static Long THREE_METER = 1L; // 三相电表
+
+ public static Long COOLING_METER = 2L; // 冷量计
+
+ public static Long DIG_DISPLAY_METER = 3L; // 数显电表
+
+ public static float CARBON_EMISSION_FACTOR = 0.6379f;
+
}
diff --git a/user-service/src/main/java/com/mh/user/constants/ProtocolEnum.java b/user-service/src/main/java/com/mh/user/constants/ProtocolEnum.java
new file mode 100644
index 0000000..739f5da
--- /dev/null
+++ b/user-service/src/main/java/com/mh/user/constants/ProtocolEnum.java
@@ -0,0 +1,60 @@
+package com.mh.user.constants;
+
+import com.mh.user.factory.CJ188Protocol;
+import com.mh.user.factory.EleProtocol;
+import com.mh.user.factory.ModbusProtocol;
+import com.mh.user.factory.Protocol;
+
+/**
+ * @author LJF
+ * @version 1.0
+ * @project mh_esi
+ * @description 协议枚举类
+ * @date 2024-09-12 10:31:53
+ */
+public enum ProtocolEnum {
+
+ CJ188_PROTOCOL("0", CJ188Protocol.getInstance()),
+
+ MODBUS_PROTOCOL("1", ModbusProtocol.getInstance()),
+
+ ELE_97_PROTOCOL("2", EleProtocol.getInstance()),
+
+ ELE_07_PROTOCOL("3", EleProtocol.getInstance()),
+
+ ;
+
+ private String protocolType;
+
+ private Protocol protocol;
+
+ private ProtocolEnum(String protocolType, Protocol protocol) {
+ this.protocolType = protocolType;
+ this.protocol = protocol;
+ }
+
+ public String getProtocolType() {
+ return protocolType;
+ }
+
+ public void setProtocolType(String protocolType) {
+ this.protocolType = protocolType;
+ }
+
+ public Protocol getProtocol() {
+ return protocol;
+ }
+
+ public void setProtocol(Protocol protocol) {
+ this.protocol = protocol;
+ }
+
+ public static Protocol getProtocol(String protocolType) {
+ for (ProtocolEnum protocolEnum : ProtocolEnum.values()) {
+ if (protocolEnum.getProtocolType().equals(protocolType)) {
+ return protocolEnum.getProtocol();
+ }
+ }
+ return null;
+ }
+}
diff --git a/user-service/src/main/java/com/mh/user/constants/ProtocolStrategyEnum.java b/user-service/src/main/java/com/mh/user/constants/ProtocolStrategyEnum.java
new file mode 100644
index 0000000..90a8e91
--- /dev/null
+++ b/user-service/src/main/java/com/mh/user/constants/ProtocolStrategyEnum.java
@@ -0,0 +1,60 @@
+package com.mh.user.constants;
+
+import com.mh.user.strategy.CJ188ProtocolStrategy;
+import com.mh.user.strategy.EleProtocolStrategy;
+import com.mh.user.strategy.ModbusProtocolStrategy;
+import com.mh.user.strategy.ProtocolStrategy;
+
+/**
+ * @author LJF
+ * @version 1.0
+ * @project mh_esi
+ * @description 协议枚举类
+ * @date 2024-09-12 10:31:53
+ */
+public enum ProtocolStrategyEnum {
+
+ CJ188_PROTOCOL("0", CJ188ProtocolStrategy.getInstance()),
+
+ MODBUS_PROTOCOL("1", ModbusProtocolStrategy.getInstance()),
+
+ ELE_97_PROTOCOL("2", EleProtocolStrategy.getInstance()),
+
+ ELE_07_PROTOCOL("3", EleProtocolStrategy.getInstance()),
+
+ ;
+
+ private String protocolType;
+
+ private ProtocolStrategy protocolStrategy;
+
+ ProtocolStrategyEnum(String protocolType, ProtocolStrategy protocolStrategy) {
+ this.protocolType = protocolType;
+ this.protocolStrategy = protocolStrategy;
+ }
+
+ public String getProtocolType() {
+ return protocolType;
+ }
+
+ public void setProtocolType(String protocolType) {
+ this.protocolType = protocolType;
+ }
+
+ public ProtocolStrategy getProtocolStrategy() {
+ return protocolStrategy;
+ }
+
+ public void setProtocolStrategy(ProtocolStrategy protocolStrategy) {
+ this.protocolStrategy = protocolStrategy;
+ }
+
+ public static ProtocolStrategy getProtocolStrategy(String protocolType) {
+ for (ProtocolStrategyEnum protocolStrategyEnum : ProtocolStrategyEnum.values()) {
+ if (protocolStrategyEnum.getProtocolType().equals(protocolType)) {
+ return protocolStrategyEnum.getProtocolStrategy();
+ }
+ }
+ return null;
+ }
+}
diff --git a/user-service/src/main/java/com/mh/user/controller/ChillersController.java b/user-service/src/main/java/com/mh/user/controller/ChillersController.java
index 23d4218..ba6817b 100644
--- a/user-service/src/main/java/com/mh/user/controller/ChillersController.java
+++ b/user-service/src/main/java/com/mh/user/controller/ChillersController.java
@@ -1,5 +1,6 @@
package com.mh.user.controller;
+import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.mh.common.http.HttpResult;
@@ -11,10 +12,7 @@ import com.mh.user.service.chillers.DeviceDisplayService;
import com.mh.user.service.chillers.GaugeService;
import com.mh.user.vo.HostListVO;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -37,6 +35,12 @@ public class ChillersController {
this.deviceDisplayService = deviceDisplayService;
}
+ /**
+ * 查询主机列表详情信息
+ * @param proId
+ * @param systemId
+ * @return
+ */
@GetMapping("/queryListByProId")
public HttpResult queryChillersByProId(@RequestParam(value = "proId", required = false) String proId,
@RequestParam("systemId") String systemId) {
@@ -44,5 +48,34 @@ public class ChillersController {
return HttpResult.ok(resultJson);
}
+ /**
+ * 查询主机详情主页信息:计算制冷量,用电量,碳排放,平均COP等
+ * @param systemId
+ * @param proId
+ * @param deviceId
+ * @return
+ */
+ @GetMapping("/queryHomeDetail/totalData")
+ public HttpResult totalData(@RequestParam("systemId") String systemId,
+ @RequestParam(value = "proId", required = false) String proId,
+ @RequestParam("deviceId") String deviceId) {
+ JSONObject resultJson = chillersService.queryTotalData(systemId, proId, deviceId);
+ return HttpResult.ok(resultJson);
+ }
+
+ /**
+ * 查询主机详情主页信息:当日能耗分析
+ * @param systemId
+ * @param proId
+ * @param deviceId
+ * @return
+ */
+ @GetMapping("/queryHomeDetail/chartData")
+ public HttpResult chartData(@RequestParam("systemId") String systemId,
+ @RequestParam(value = "proId", required = false) String proId,
+ @RequestParam("deviceId") String deviceId) {
+ JSONObject resultJson = chillersService.queryChartData(systemId, proId, deviceId);
+ return HttpResult.ok(resultJson);
+ }
}
diff --git a/user-service/src/main/java/com/mh/user/controller/DevicesManageController.java b/user-service/src/main/java/com/mh/user/controller/DevicesManageController.java
index d4c7eb9..2be74c2 100644
--- a/user-service/src/main/java/com/mh/user/controller/DevicesManageController.java
+++ b/user-service/src/main/java/com/mh/user/controller/DevicesManageController.java
@@ -38,7 +38,7 @@ public class DevicesManageController {
@SysLogger(value="资产管理信息",optDesc = "根据项目id查询对应信息")
@GetMapping("/findById")
- public HttpResult findById(@RequestParam("id") Integer id) {
+ public HttpResult findById(@RequestParam("id") Long id) {
DevicesManageEntity entity = devicesManageService.findById(id);
return HttpResult.ok(entity);
}
diff --git a/user-service/src/main/java/com/mh/user/controller/DevicesParamsController.java b/user-service/src/main/java/com/mh/user/controller/DevicesParamsController.java
index 9d3a867..ed3337e 100644
--- a/user-service/src/main/java/com/mh/user/controller/DevicesParamsController.java
+++ b/user-service/src/main/java/com/mh/user/controller/DevicesParamsController.java
@@ -38,7 +38,7 @@ public class DevicesParamsController {
@SysLogger(value="资产管理信息",optDesc = "根据项目id查询对应信息")
@GetMapping("/findById")
- public HttpResult findById(@RequestParam("id") Integer id) {
+ public HttpResult findById(@RequestParam("id") Long id) {
DeviceParamsEntity entity = deviceParamsService.findById(id);
return HttpResult.ok(entity);
}
diff --git a/user-service/src/main/java/com/mh/user/controller/GatewayManageController.java b/user-service/src/main/java/com/mh/user/controller/GatewayManageController.java
index 0303cfd..39e4e15 100644
--- a/user-service/src/main/java/com/mh/user/controller/GatewayManageController.java
+++ b/user-service/src/main/java/com/mh/user/controller/GatewayManageController.java
@@ -39,7 +39,7 @@ public class GatewayManageController {
@SysLogger(value="网关管理信息",optDesc = "根据项目id查询对应信息")
@GetMapping("/findById")
- public HttpResult findById(@RequestParam("id") Integer id) {
+ public HttpResult findById(@RequestParam("id") Long id) {
GatewayManageEntity gatewayManageEntity = gatewayManageService.findById(id);
return HttpResult.ok(gatewayManageEntity);
}
diff --git a/user-service/src/main/java/com/mh/user/controller/MeterManageController.java b/user-service/src/main/java/com/mh/user/controller/MeterManageController.java
index 4450d1d..bcf5aeb 100644
--- a/user-service/src/main/java/com/mh/user/controller/MeterManageController.java
+++ b/user-service/src/main/java/com/mh/user/controller/MeterManageController.java
@@ -38,7 +38,7 @@ public class MeterManageController {
@SysLogger(value="仪表管理信息",optDesc = "根据项目id查询对应信息")
@GetMapping("/findById")
- public HttpResult findById(@RequestParam("id") Integer id) {
+ public HttpResult findById(@RequestParam("id") Long id) {
MeterManageEntity entity = meterManageService.findById(id);
return HttpResult.ok(entity);
}
diff --git a/user-service/src/main/java/com/mh/user/controller/ProjectInfoController.java b/user-service/src/main/java/com/mh/user/controller/ProjectInfoController.java
index 2487bfb..b057267 100644
--- a/user-service/src/main/java/com/mh/user/controller/ProjectInfoController.java
+++ b/user-service/src/main/java/com/mh/user/controller/ProjectInfoController.java
@@ -41,7 +41,7 @@ public class ProjectInfoController {
@SysLogger(value="项目信息",optDesc = "根据项目id查询对应信息")
@GetMapping("/findById")
- public HttpResult findById(@RequestParam("id") Integer id) {
+ public HttpResult findById(@RequestParam("id") Long id) {
ProjectInfoEntity projectInfoEntity = projectInfoService.findById(id);
return HttpResult.ok(projectInfoEntity);
}
diff --git a/user-service/src/main/java/com/mh/user/entity/DeviceCodeParamEntity.java b/user-service/src/main/java/com/mh/user/entity/DeviceCodeParamEntity.java
index 378fcc7..17dde8d 100644
--- a/user-service/src/main/java/com/mh/user/entity/DeviceCodeParamEntity.java
+++ b/user-service/src/main/java/com/mh/user/entity/DeviceCodeParamEntity.java
@@ -11,7 +11,7 @@ import java.util.Date;
@Getter
@ToString
@TableName("device_code_param")
-public class DeviceCodeParamEntity {
+public class DeviceCodeParamEntity implements Cloneable {
private Long id;
private String deviceAddr;
@@ -31,4 +31,35 @@ public class DeviceCodeParamEntity {
private Date createTime;
private String projectId;
+ /**
+ * 重置
+ */
+ public void reset() {
+ this.deviceAddr = null;
+ this.deviceName = null;
+ this.deviceType = null;
+ this.strData = null;
+ this.dataPort = null;
+ this.baudRate = 0;
+ this.parity = null;
+ this.brand = null;
+ this.funCode = null;
+ this.registerAddr = null;
+ this.registerName = null;
+ this.digit = 0;
+ this.grade = 0;
+ this.dataValue = null;
+ this.createTime = null;
+ this.projectId = null;
+ }
+
+ @Override
+ public DeviceCodeParamEntity clone() {
+ try {
+ // TODO: copy mutable state here, so the clone can't change the internals of the original
+ return (DeviceCodeParamEntity) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new AssertionError();
+ }
+ }
}
diff --git a/user-service/src/main/java/com/mh/user/entity/DeviceManageEntity.java b/user-service/src/main/java/com/mh/user/entity/DeviceManageEntity.java
index dfbbffd..6d643e9 100644
--- a/user-service/src/main/java/com/mh/user/entity/DeviceManageEntity.java
+++ b/user-service/src/main/java/com/mh/user/entity/DeviceManageEntity.java
@@ -39,6 +39,17 @@ public class DeviceManageEntity extends BaseEntity {
private String createTimes;
private String updateTimes;
+
+ /**
+ * 出厂编码
+ */
+ private String factoryBarcode;
+
+ /**
+ * imuCode
+ */
+ private String imuCode;
+
@Override
public String toString() {
return "DeviceManageEntity{" +
diff --git a/user-service/src/main/java/com/mh/user/entity/MeterManageEntity.java b/user-service/src/main/java/com/mh/user/entity/MeterManageEntity.java
index e572048..00e4865 100644
--- a/user-service/src/main/java/com/mh/user/entity/MeterManageEntity.java
+++ b/user-service/src/main/java/com/mh/user/entity/MeterManageEntity.java
@@ -161,7 +161,7 @@ public class MeterManageEntity implements Serializable {
/**
* 协议类型
*/
- private Long protocolType;
+ private int protocolType;
/**
* 备注
@@ -188,6 +188,11 @@ public class MeterManageEntity implements Serializable {
*/
private Long communicationType;
+ /**
+ * 读取寄存器大小
+ */
+ private int registerSize;
+
@Override
public String toString() {
return "MeterManageEntity{" +
@@ -223,6 +228,8 @@ public class MeterManageEntity implements Serializable {
", grade=" + grade +
", systemId=" + systemId +
", projectId=" + projectId +
+ ", communicationType=" + communicationType +
+ ", registerSize=" + registerSize +
'}';
}
}
diff --git a/user-service/src/main/java/com/mh/user/factory/CJ188Protocol.java b/user-service/src/main/java/com/mh/user/factory/CJ188Protocol.java
new file mode 100644
index 0000000..222d6be
--- /dev/null
+++ b/user-service/src/main/java/com/mh/user/factory/CJ188Protocol.java
@@ -0,0 +1,48 @@
+package com.mh.user.factory;
+
+import com.mh.user.entity.MeterManageEntity;
+import com.mh.user.strategy.ProtocolStrategy;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * @author LJF
+ * @version 1.0
+ * @project mh_esi
+ * @description 水表标准协议
+ * @date 2024-09-12 14:04:01
+ */
+@Slf4j
+public class CJ188Protocol implements Protocol {
+
+ private ProtocolStrategy cj188ProtocolStrategy;
+
+ private static class SingletonHolder{
+ private static final CJ188Protocol INSTANCE = new CJ188Protocol();
+ }
+
+ private CJ188Protocol(){
+ // 防止外部直接实例化
+ }
+
+ public static CJ188Protocol getInstance(){
+ return SingletonHolder.INSTANCE;
+ }
+
+ @Override
+ public void setStrategy(ProtocolStrategy protocolStrategy) {
+ this.cj188ProtocolStrategy = protocolStrategy;
+ }
+
+ @Override
+ public String createOrder(MeterManageEntity meterManageEntity) {
+ log.info("水表标准协议:工厂创建报文");
+ return cj188ProtocolStrategy.createOrder(meterManageEntity);
+ }
+
+ @Override
+ public String analysisReceiveData(MeterManageEntity meterManageEntity, String receiveData) {
+ log.info("水表标准协议:工厂解析报文");
+ return cj188ProtocolStrategy.analysisReceiveData(meterManageEntity, receiveData);
+ }
+
+}
diff --git a/user-service/src/main/java/com/mh/user/factory/EleProtocol.java b/user-service/src/main/java/com/mh/user/factory/EleProtocol.java
new file mode 100644
index 0000000..27ba102
--- /dev/null
+++ b/user-service/src/main/java/com/mh/user/factory/EleProtocol.java
@@ -0,0 +1,48 @@
+package com.mh.user.factory;
+
+import com.mh.user.entity.MeterManageEntity;
+import com.mh.user.strategy.ProtocolStrategy;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * @author LJF
+ * @version 1.0
+ * @project mh_esi
+ * @description 水表标准协议
+ * @date 2024-09-12 14:04:01
+ */
+@Slf4j
+public class EleProtocol implements Protocol {
+
+ private ProtocolStrategy eleProtocolStrategy;
+
+ private static class SingletonHolder{
+ private static final EleProtocol INSTANCE = new EleProtocol();
+ }
+
+ private EleProtocol(){
+ // 防止外部直接实例化
+ }
+
+ public static EleProtocol getInstance(){
+ return SingletonHolder.INSTANCE;
+ }
+
+ @Override
+ public void setStrategy(ProtocolStrategy protocolStrategy) {
+ this.eleProtocolStrategy = protocolStrategy;
+ }
+
+ @Override
+ public String createOrder(MeterManageEntity meterManageEntity) {
+ log.info("电表97/07规约协议:工厂创建报文");
+ return eleProtocolStrategy.createOrder(meterManageEntity);
+ }
+
+ @Override
+ public String analysisReceiveData(MeterManageEntity meterManageEntity, String receiveData) {
+ log.info("电表97/07规约协议:工厂解析报文");
+ return eleProtocolStrategy.analysisReceiveData(meterManageEntity, receiveData);
+ }
+
+}
diff --git a/user-service/src/main/java/com/mh/user/factory/ModbusProtocol.java b/user-service/src/main/java/com/mh/user/factory/ModbusProtocol.java
new file mode 100644
index 0000000..6bf1308
--- /dev/null
+++ b/user-service/src/main/java/com/mh/user/factory/ModbusProtocol.java
@@ -0,0 +1,47 @@
+package com.mh.user.factory;
+
+import com.mh.user.entity.MeterManageEntity;
+import com.mh.user.strategy.ProtocolStrategy;
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * @author LJF
+ * @version 1.0
+ * @project mh_esi
+ * @description modbus协议
+ * @date 2024-09-12 16:38:44
+ */
+@Slf4j
+public class ModbusProtocol implements Protocol {
+
+ private ProtocolStrategy modbusProtocolStrategy;
+
+ private static class SingletonHolder{
+ private static final ModbusProtocol INSTANCE = new ModbusProtocol();
+ }
+
+ private ModbusProtocol(){
+ // 防止外部直接实例化
+ }
+
+ public static ModbusProtocol getInstance(){
+ return ModbusProtocol.SingletonHolder.INSTANCE;
+ }
+
+ @Override
+ public void setStrategy(ProtocolStrategy protocolStrategy) {
+ this.modbusProtocolStrategy = protocolStrategy;
+ }
+
+ @Override
+ public String createOrder(MeterManageEntity meterManageEntity) {
+ log.info("modbus标准协议:工厂创建报文");
+ return modbusProtocolStrategy.createOrder(meterManageEntity);
+ }
+
+ @Override
+ public String analysisReceiveData(MeterManageEntity meterManageEntity, String receiveData) {
+ log.info("modbus标准协议:工厂解析报文");
+ return modbusProtocolStrategy.analysisReceiveData(meterManageEntity, receiveData);
+ }
+}
diff --git a/user-service/src/main/java/com/mh/user/factory/Protocol.java b/user-service/src/main/java/com/mh/user/factory/Protocol.java
new file mode 100644
index 0000000..85ec88b
--- /dev/null
+++ b/user-service/src/main/java/com/mh/user/factory/Protocol.java
@@ -0,0 +1,36 @@
+package com.mh.user.factory;
+
+import com.mh.user.entity.MeterManageEntity;
+import com.mh.user.strategy.ProtocolStrategy;
+
+/**
+ * @author LJF
+ * @version 1.0
+ * @project mh_esi
+ * @description 根据协议实现对设备的生产和解析
+ * @date 2024-09-12 11:17:20
+ */
+public interface Protocol {
+
+ /**
+ * 设置协议策略
+ * @param protocolStrategy
+ */
+ void setStrategy(ProtocolStrategy protocolStrategy);
+
+ /**
+ * 创建指令
+ * @param meterManageEntity
+ * @return
+ */
+ String createOrder(MeterManageEntity meterManageEntity);
+
+ /**
+ * 解析指令
+ * @param meterManageEntity
+ * @param receiveData
+ * @return
+ */
+ String analysisReceiveData(MeterManageEntity meterManageEntity, String receiveData);
+
+}
diff --git a/user-service/src/main/java/com/mh/user/factory/ProtocolFactory.java b/user-service/src/main/java/com/mh/user/factory/ProtocolFactory.java
new file mode 100644
index 0000000..94f7815
--- /dev/null
+++ b/user-service/src/main/java/com/mh/user/factory/ProtocolFactory.java
@@ -0,0 +1,17 @@
+package com.mh.user.factory;
+
+import com.mh.user.constants.ProtocolEnum;
+
+/**
+ * @author LJF
+ * @version 1.0
+ * @project mh_esi
+ * @description 协议工厂
+ * @date 2024-09-12 10:29:51
+ */
+public class ProtocolFactory {
+
+ public static Protocol matchProtocol(String protocolType) {
+ return ProtocolEnum.getProtocol(protocolType);
+ }
+}
diff --git a/user-service/src/main/java/com/mh/user/job/CollectionLoopRunner.java b/user-service/src/main/java/com/mh/user/job/CollectionLoopRunner.java
index 9ca35e7..62409f3 100644
--- a/user-service/src/main/java/com/mh/user/job/CollectionLoopRunner.java
+++ b/user-service/src/main/java/com/mh/user/job/CollectionLoopRunner.java
@@ -1,8 +1,13 @@
package com.mh.user.job;
-import com.mh.user.entity.ProjectInfoEntity;
+import com.mh.common.page.PageRequest;
+import com.mh.user.entity.*;
+import com.mh.user.factory.Protocol;
+import com.mh.user.factory.ProtocolFactory;
import com.mh.user.netty.EchoServer;
-import com.mh.user.service.ProjectInfoService;
+import com.mh.user.service.*;
+import com.mh.user.strategy.ProtocolStrategy;
+import com.mh.user.strategy.ProtocolStrategyFactory;
import com.mh.user.utils.GetReadOrder485;
import gnu.io.SerialPort;
import lombok.extern.slf4j.Slf4j;
@@ -10,7 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
-import java.util.List;
+
+import java.util.*;
/**
* @author ljf
@@ -23,25 +29,117 @@ import java.util.List;
@Component
public class CollectionLoopRunner implements ApplicationRunner {
- public static SerialPort serialPort = null;
+ public static SerialPort serialPort = null;
- @Autowired
- ProjectInfoService projectInfoService;
+ @Autowired
+ ProjectInfoService projectInfoService;
- @Override
- public void run(ApplicationArguments args) throws Exception {
- GetReadOrder485 getReadOrder485=new GetReadOrder485();
- List projectInfoEntities = projectInfoService.queryProjectInfo("1");
- if (null != projectInfoEntities && !projectInfoEntities.isEmpty()) {
- for (ProjectInfoEntity projectInfoEntity : projectInfoEntities) {
- getReadOrder485.createOrderParam(String.valueOf(projectInfoEntity.getId())); //生成采集参数,1新珠江(6000),2广合科技(6001),3广大科技(6002),6珠江国际,7保利山庄,8东莞迎宾馆
- }
- }
- try{
- new EchoServer(6001).start(); // 调用服务器的start方法,网关作为客户端,6006新珠江,6001广合科技,6077广大科技 6028(6006)珠江国际,5000保利山庄,6004东莞迎宾馆
- }catch (Exception e){
- log.info("6001端口已占用!");
+ @Autowired
+ private MeterManageService meterManageService;
+
+ @Autowired
+ private DeviceCodeParamService deviceCodeParamService;
+
+ @Autowired
+ private GatewayManageService gatewayManageService;
+
+ @Autowired
+ private DeviceParamsService deviceParamsService;
+
+ @Override
+ public void run(ApplicationArguments args) throws Exception {
+ List projectInfoEntities = projectInfoService.queryProjectInfo("1");
+ if (null != projectInfoEntities && !projectInfoEntities.isEmpty()) {
+ for (ProjectInfoEntity projectInfoEntity : projectInfoEntities) {
+ // getReadOrder485.createOrderParam(String.valueOf(projectInfoEntity.getId())); //生成采集参数,1新珠江(6000),2广合科技(6001),3广大科技(6002),6珠江国际,7保利山庄,8东莞迎宾馆
+ createOrderParamByStrategy(projectInfoEntity.getSystemId(), String.valueOf(projectInfoEntity.getId()));
+ }
+ }
+ try {
+ new EchoServer(6001).start(); // 调用服务器的start方法,网关作为客户端,6006新珠江,6001广合科技,6077广大科技 6028(6006)珠江国际,5000保利山庄,6004东莞迎宾馆
+ } catch (Exception e) {
+ log.info("6001端口已占用!");
+ }
+ }
+
+ public void createOrderParamByStrategy(String systemId, String projectId) throws InterruptedException {
+ int r;
+ if (projectId != null && !projectId.isEmpty()) {
+ r = deviceCodeParamService.queryCount(projectId);//查询记录数
+ } else {
+ r = deviceCodeParamService.queryCount2();//查询记录数
+ }
+ if (r > 0) {
+ return;
+ }
+ List deviceCodeParamEntityList = new ArrayList<>();
+ List meterManageEntities = Collections.emptyList();
+
+ if (projectId != null && !projectId.isEmpty()) {
+ meterManageEntities = meterManageService.queryBySystemIdAndProjectId(systemId, projectId);
+ }
+
+ DeviceCodeParamEntity deviceCodeParamEntity = new DeviceCodeParamEntity();
+
+ // 根据协议进行匹配生成采集报文
+ for (MeterManageEntity meterManageEntity : meterManageEntities) {
+ // 重置采集参数
+ deviceCodeParamEntity.reset();
+
+ // 创建设备报文
+ String protocolType = String.valueOf(meterManageEntity.getProtocolType());
+ Protocol protocol = ProtocolFactory.matchProtocol(protocolType);
+ ProtocolStrategy strategy = ProtocolStrategyFactory.matchProtocolStrategy(protocolType);
+
+ if (strategy == null) {
+ continue;
+ }
+
+ protocol.setStrategy(strategy);
+ String sendStr = protocol.createOrder(meterManageEntity);
+ log.info("采集指令===> {}", sendStr);
+
+ deviceCodeParamEntity.setDeviceAddr(meterManageEntity.getMtCode());
+ deviceCodeParamEntity.setDeviceName(meterManageEntity.getMtName());
+ deviceCodeParamEntity.setDeviceType(String.valueOf(meterManageEntity.getMtType()));
+ deviceCodeParamEntity.setStrData(sendStr);
+
+ try {
+ GatewayManageEntity gatewayManageEntity = gatewayManageService.findById(meterManageEntity.getGatewayId());
+ if (gatewayManageEntity != null) {
+ deviceCodeParamEntity.setDataPort(String.valueOf(gatewayManageEntity.getPort()));
+ }
+ } catch (Exception e) {
+ log.error("查询网关信息失败: {}", e.getMessage());
+ }
+
+ try {
+ DeviceParamsEntity paramsEntity = deviceParamsService.findById(meterManageEntity.getParamId());
+ if (paramsEntity != null) {
+ deviceCodeParamEntity.setBaudRate(paramsEntity.getBaudRate());
+ deviceCodeParamEntity.setParity(paramsEntity.getParity());
+ }
+ } catch (Exception e) {
+ log.error("查询设备参数失败: {}", e.getMessage());
+ }
+
+ deviceCodeParamEntity.setBrand(meterManageEntity.getMtBrand());
+ deviceCodeParamEntity.setFunCode(meterManageEntity.getFuncCode());
+ deviceCodeParamEntity.setRegisterAddr(meterManageEntity.getRegisterAddr());
+ deviceCodeParamEntity.setRegisterName(meterManageEntity.getOtherName());
+ deviceCodeParamEntity.setDigit(meterManageEntity.getDigits());
+ deviceCodeParamEntity.setGrade(meterManageEntity.getGrade());
+ deviceCodeParamEntity.setDataValue(null); // 传入值(目前不需要)
+ deviceCodeParamEntity.setProjectId(projectId);
+ deviceCodeParamEntity.setCreateTime(new Date());
+
+ deviceCodeParamEntityList.add(deviceCodeParamEntity.clone());
+ }
+
+ if (!deviceCodeParamEntityList.isEmpty()) {
+ deviceCodeParamService.insertDeviceCodeParamList(deviceCodeParamEntityList);
}
- }
+
+ }
}
diff --git a/user-service/src/main/java/com/mh/user/mapper/chillers/ChillersMapper.java b/user-service/src/main/java/com/mh/user/mapper/chillers/ChillersMapper.java
index ddd2bd7..e346bde 100644
--- a/user-service/src/main/java/com/mh/user/mapper/chillers/ChillersMapper.java
+++ b/user-service/src/main/java/com/mh/user/mapper/chillers/ChillersMapper.java
@@ -9,6 +9,7 @@ import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import java.util.List;
+import java.util.Map;
/**
* @author ljf
@@ -181,4 +182,17 @@ public interface ChillersMapper {
@Result(column = "last_time", property = "lastTime")
})
List getStopChillers();
+
+ @Select("select mt_type, cur_value, cur_time from meter_manage " +
+ " where system_id = #{systemId} and project_id = #{proId} and device_id = #{deviceId} " +
+ " and grade between 0 and 9 group by mt_type, cur_value, cur_time ")
+ List