From c4948017824b1efa71faeb163e3609bec91f5719 Mon Sep 17 00:00:00 2001 From: cuikaidong <ckd2942379034@163.com> Date: 星期五, 15 八月 2025 10:02:00 +0800 Subject: [PATCH] MDC,IOT合并 --- lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Config.java | 28 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentLogServiceImpl.java | 61 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ControlSystemServiceImpl.java | 18 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/SystemType.java | 16 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/StringEntity.java | 15 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/Equipment.java | 152 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/IotTree.java | 27 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ControlSystemMapper.xml | 4 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Parameter.java | 38 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentLogService.java | 33 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ServerDeployMapper.xml | 5 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/HttpClientUtil.java | 178 + lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ServeDeployController.java | 391 ++ lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/RealParameterServiceImpl.java | 286 + lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/EmptyParameterMapper.xml | 18 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/RealParameter.java | 139 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/EquipmentMapper.xml | 5 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/config/MqttCustomerClient.java | 179 + lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/RegisterInfo.java | 23 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DefaultParameter.java | 15 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/TimeEntity.java | 16 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/FunctionEntity.java | 29 lxzn-module-system/lxzn-system-start/src/main/resources/application-dev.yml | 34 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ProjectClassifyMapper.xml | 5 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/MathEntity.java | 15 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/FileUtil.java | 371 ++ lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ByteOrder.java | 18 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ParameterGroupMapper.xml | 5 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IControlSystemService.java | 13 pom.xml | 37 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentMapper.java | 32 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/MdcDriveTypeParamConfigMapper.java | 29 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/ConvertEntity.java | 16 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/MdcDriveTypeParamConfigMapper.xml | 23 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IMqttDeployService.java | 31 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DataType.java | 18 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttClient.java | 16 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/Functions.java | 35 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/MqttDeployMapper.java | 16 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IEquipmentService.java | 124 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/FtpUtil.java | 434 ++ lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ConnectionInfo.java | 19 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttParameter.java | 40 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/CustomEntity.java | 16 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentAlarmService.java | 18 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IMdcDriveTypeParamConfigService.java | 31 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/message/websocket/WebSocket.java | 20 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/EmptyParameter.java | 120 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/InfluxdbDeploy.java | 68 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/MqttDeployMapper.xml | 5 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentServiceImpl.java | 48 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IServerDeployService.java | 46 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ControlSystem.java | 56 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/InfluxdbDeployMapper.java | 15 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ParameterGroupController.java | 133 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IRealParameterService.java | 107 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/NodeAttribute.java | 29 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/MqttDeployServiceImpl.java | 31 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/FileEntity.java | 16 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/InfluxdbTest.java | 82 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ParameterGroup.java | 63 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IInfluxdbDeployService.java | 33 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/InfluxdbDeployServiceImpl.java | 31 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/quartz/job/SampleParamJob.java | 344 ++ lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ByteOrderType.java | 15 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/EmptyParameterController.java | 183 + lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DriveType.java | 25 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Protocol.java | 32 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IProjectClassifyService.java | 35 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ServerDeployServiceImpl.java | 362 ++ lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/EquipmentAlarm.java | 37 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/AESUtil.java | 205 + lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/DbConfig.java | 19 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentService.java | 63 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/RegisterType.java | 16 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/SystemDataType.java | 17 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/RealParameterMapper.xml | 46 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/quartz/job/SampleJob.java | 41 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/EmptyParameterMapper.java | 28 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/MdcDriveTypeParamConfigServiceImpl.java | 36 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/MysqlDataWriter.java | 237 + lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/MdcDriveTypeParamConfig.java | 66 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/DatabaseEntity.java | 16 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/JaxbUtil.java | 51 lxzn-module-system/lxzn-system-start/src/main/resources/application-prod.yml | 79 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/callback/PushCallback.java | 272 + lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentLogMapper.java | 24 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/Influxdb.java | 36 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ProjectClassify.java | 45 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/InfluxdbDeployMapper.xml | 5 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ControlSystem.java | 22 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/config/MqttConfiguration.java | 102 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/EquipmentServiceImpl.java | 515 +++ lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/EquipmentController.java | 444 ++ lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttDeploy.java | 72 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Type.java | 17 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ProjectClassifyMapper.java | 15 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ProjectClassifyController.java | 212 + lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ParameterGroupServiceImpl.java | 82 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ProjectClassifyServiceImpl.java | 60 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/EquipmentMapper.xml | 5 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ParameterGroupMapper.java | 15 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/RealParameterController.java | 176 + lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ServerDeployMapper.java | 16 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentAlarmServiceImpl.java | 30 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ScriptCompilation.java | 33 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ControlSystemMapper.java | 18 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/RealParameterMapper.java | 25 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentAlarmMapper.java | 18 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IEmptyParameterService.java | 84 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IParameterGroupService.java | 47 /dev/null | 18 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/EmptyParameterServiceImpl.java | 639 ++++ lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/Equipment.java | 188 + lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/EquipmentMapper.java | 18 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/DispatchUtil.java | 21 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ServerDeploy.java | 142 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/EquipmentLog.java | 43 lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/EquipmentLogMapper.xml | 28 119 files changed, 9,349 insertions(+), 66 deletions(-) diff --git a/lxzn-boot-base-core/lxzn-boot-base-core.iml b/lxzn-boot-base-core/lxzn-boot-base-core.iml deleted file mode 100644 index ddddf7a..0000000 --- a/lxzn-boot-base-core/lxzn-boot-base-core.iml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module version="4"> - <component name="FacetManager"> - <facet type="JRebel" name="JRebel"> - <configuration> - <option name="ideModuleStorage"> - <map> - <entry key="com.zeroturnaround.jrebel.FormatVersion" value="7.0.0" /> - <entry key="jrebelEnabled" value="false" /> - <entry key="lastExternalPluginCheckTime" value="1754530568586" /> - <entry key="rebelXmlGenerationInvariantToken" value="PGFwcGxpY2F0aW9uIGdlbmVyYXRlZC1ieT0iaW50ZWxsaWoiPjxpZD5seHpuLWJvb3QtYmFzZS1jb3JlPC9pZD48Y2xhc3NwYXRoPjxkaXIgbmFtZT0iRjovamF2YV93b3Jrc3BhY2UvbWRjX3pmL2x4em4tYm9vdC1iYXNlLWNvcmUvdGFyZ2V0L2NsYXNzZXMiPjwvZGlyPjwvY2xhc3NwYXRoPjwvYXBwbGljYXRpb24+" /> - </map> - </option> - <option name="version" value="8" /> - </configuration> - </facet> - </component> -</module> \ No newline at end of file diff --git a/lxzn-module-mdc/lxzn-module-mdc.iml b/lxzn-module-mdc/lxzn-module-mdc.iml deleted file mode 100644 index 7b19469..0000000 --- a/lxzn-module-mdc/lxzn-module-mdc.iml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module version="4"> - <component name="FacetManager"> - <facet type="JRebel" name="JRebel"> - <configuration> - <option name="ideModuleStorage"> - <map> - <entry key="com.zeroturnaround.jrebel.FormatVersion" value="7.0.0" /> - <entry key="jrebelEnabled" value="false" /> - <entry key="lastExternalPluginCheckTime" value="1754530568590" /> - <entry key="rebelXmlGenerationInvariantToken" value="PGFwcGxpY2F0aW9uIGdlbmVyYXRlZC1ieT0iaW50ZWxsaWoiPjxpZD5seHpuLW1vZHVsZS1tZGM8L2lkPjxjbGFzc3BhdGg+PGRpciBuYW1lPSJGOi9qYXZhX3dvcmtzcGFjZS9tZGNfemYvbHh6bi1tb2R1bGUtbWRjL3RhcmdldC9jbGFzc2VzIj48L2Rpcj48L2NsYXNzcGF0aD48L2FwcGxpY2F0aW9uPg==" /> - </map> - </option> - <option name="version" value="8" /> - </configuration> - </facet> - </component> -</module> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-api/lxzn-system-cloud-api/lxzn-system-cloud-api.iml b/lxzn-module-system/lxzn-system-api/lxzn-system-cloud-api/lxzn-system-cloud-api.iml deleted file mode 100644 index d53ccce..0000000 --- a/lxzn-module-system/lxzn-system-api/lxzn-system-cloud-api/lxzn-system-cloud-api.iml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module version="4"> - <component name="FacetManager"> - <facet type="JRebel" name="JRebel"> - <configuration> - <option name="ideModuleStorage"> - <map> - <entry key="com.zeroturnaround.jrebel.FormatVersion" value="7.0.0" /> - <entry key="jrebelEnabled" value="false" /> - <entry key="lastExternalPluginCheckTime" value="1754530568601" /> - <entry key="rebelXmlGenerationInvariantToken" value="PGFwcGxpY2F0aW9uIGdlbmVyYXRlZC1ieT0iaW50ZWxsaWoiPjxpZD5seHpuLXN5c3RlbS1jbG91ZC1hcGk8L2lkPjxjbGFzc3BhdGg+PGRpciBuYW1lPSJGOi9qYXZhX3dvcmtzcGFjZS9tZGNfemYvbHh6bi1tb2R1bGUtc3lzdGVtL2x4em4tc3lzdGVtLWFwaS9seHpuLXN5c3RlbS1jbG91ZC1hcGkvdGFyZ2V0L2NsYXNzZXMiPjwvZGlyPjwvY2xhc3NwYXRoPjwvYXBwbGljYXRpb24+" /> - </map> - </option> - <option name="version" value="8" /> - </configuration> - </facet> - </component> -</module> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-api/lxzn-system-local-api/lxzn-system-local-api.iml b/lxzn-module-system/lxzn-system-api/lxzn-system-local-api/lxzn-system-local-api.iml deleted file mode 100644 index 2df57c7..0000000 --- a/lxzn-module-system/lxzn-system-api/lxzn-system-local-api/lxzn-system-local-api.iml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module version="4"> - <component name="FacetManager"> - <facet type="JRebel" name="JRebel"> - <configuration> - <option name="ideModuleStorage"> - <map> - <entry key="com.zeroturnaround.jrebel.FormatVersion" value="7.0.0" /> - <entry key="jrebelEnabled" value="false" /> - <entry key="lastExternalPluginCheckTime" value="1754530568590" /> - <entry key="rebelXmlGenerationInvariantToken" value="PGFwcGxpY2F0aW9uIGdlbmVyYXRlZC1ieT0iaW50ZWxsaWoiPjxpZD5seHpuLXN5c3RlbS1sb2NhbC1hcGk8L2lkPjxjbGFzc3BhdGg+PGRpciBuYW1lPSJGOi9qYXZhX3dvcmtzcGFjZS9tZGNfemYvbHh6bi1tb2R1bGUtc3lzdGVtL2x4em4tc3lzdGVtLWFwaS9seHpuLXN5c3RlbS1sb2NhbC1hcGkvdGFyZ2V0L2NsYXNzZXMiPjwvZGlyPjwvY2xhc3NwYXRoPjwvYXBwbGljYXRpb24+" /> - </map> - </option> - <option name="version" value="8" /> - </configuration> - </facet> - </component> -</module> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/lxzn-system-biz.iml b/lxzn-module-system/lxzn-system-biz/lxzn-system-biz.iml deleted file mode 100644 index 6b220ae..0000000 --- a/lxzn-module-system/lxzn-system-biz/lxzn-system-biz.iml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module version="4"> - <component name="FacetManager"> - <facet type="JRebel" name="JRebel"> - <configuration> - <option name="ideModuleStorage"> - <map> - <entry key="com.zeroturnaround.jrebel.FormatVersion" value="7.0.0" /> - <entry key="jrebelEnabled" value="false" /> - <entry key="lastExternalPluginCheckTime" value="1754530568599" /> - <entry key="rebelXmlGenerationInvariantToken" value="PGFwcGxpY2F0aW9uIGdlbmVyYXRlZC1ieT0iaW50ZWxsaWoiPjxpZD5seHpuLXN5c3RlbS1iaXo8L2lkPjxjbGFzc3BhdGg+PGRpciBuYW1lPSJGOi9qYXZhX3dvcmtzcGFjZS9tZGNfemYvbHh6bi1tb2R1bGUtc3lzdGVtL2x4em4tc3lzdGVtLWJpei90YXJnZXQvY2xhc3NlcyI+PC9kaXI+PC9jbGFzc3BhdGg+PC9hcHBsaWNhdGlvbj4=" /> - </map> - </option> - <option name="version" value="8" /> - </configuration> - </facet> - </component> -</module> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/EmptyParameterController.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/EmptyParameterController.java new file mode 100644 index 0000000..20dc69d --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/EmptyParameterController.java @@ -0,0 +1,183 @@ +package org.jeecg.modules.iot.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.aspect.annotation.AutoLog; +import org.jeecg.common.system.base.controller.JeecgController; +import org.jeecg.common.system.query.QueryGenerator; +import org.jeecg.modules.iot.entity.EmptyParameter; +import org.jeecg.modules.iot.entity.Equipment; +import org.jeecg.modules.iot.entity.ServerDeploy; +import org.jeecg.modules.iot.mdc.service.IMdcDriveTypeParamConfigService; +import org.jeecg.modules.iot.service.IEmptyParameterService; +import org.jeecg.modules.iot.service.IEquipmentService; +import org.jeecg.modules.iot.service.IServerDeployService; +import org.jeecg.modules.iot.util.HttpClientUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * @Description: 铏氳澶囧弬鏁� + * @Author: cuikaidong + * @Date: 2025-1-7 + * @Version: V1.0 + */ +@Api(tags = "铏氳澶囧弬鏁�") +@RestController +@RequestMapping("/empty/parameter") +@Slf4j +public class EmptyParameterController extends JeecgController<EmptyParameter, IEmptyParameterService> { + @Autowired + private IEmptyParameterService emptyParameterService; + @Autowired + private IEquipmentService equipmentService; + + /** + * 鍒嗛〉鍒楄〃鏌ヨ + * + * @param emptyParameter + * @param pageNo + * @param pageSize + * @return + */ + @ApiOperation(value = "铏氳澶囧弬鏁�-鍒嗛〉鍒楄〃鏌ヨ", notes = "铏氳澶囧弬鏁�-鍒嗛〉鍒楄〃鏌ヨ") + @GetMapping(value = "/list") + public Result<?> queryPageList(EmptyParameter emptyParameter, + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest req) { + QueryWrapper<EmptyParameter> queryWrapper = QueryGenerator.initQueryWrapper(emptyParameter, req.getParameterMap()); + Page<EmptyParameter> page = new Page<>(pageNo, pageSize); + IPage<EmptyParameter> pageList = emptyParameterService.page(page, queryWrapper); + List<EmptyParameter> records = pageList.getRecords(); + if (records.size() > 0) { + // 鏍规嵁璁惧id鏌ヨ璁惧缂栧彿 + Equipment equipment = equipmentService.getById(records.get(0).getEquipmentId()); + records.forEach(e -> { + e.setEqptCode(equipment.getEqptCode()); + e.setEqptName(equipment.getEqptName()); + e.setServeId(equipment.getServerId()); + }); + } + return Result.ok(pageList); + } + + /** + * 閫氳繃id鏌ヨ + * + * @param id + * @return + */ + @GetMapping(value = "/queryById") + public Result<?> queryById(@RequestParam(name = "id", required = true) String id) { + EmptyParameter RealParameter = emptyParameterService.getById(id); + return Result.ok(RealParameter); + } + + /** + * 淇濆瓨鑴氭湰 + * + * @param emptyParameter + * @return + */ + @AutoLog(value = "铏氳澶囧弬鏁�-淇濆瓨鑴氭湰") + @ApiOperation(value = "铏氳澶囧弬鏁�-淇濆瓨鑴氭湰", notes = "铏氳澶囧弬鏁�-淇濆瓨鑴氭湰") + @PostMapping(value = "/preserveScript") + public Result<?> preserveScript(@RequestBody EmptyParameter emptyParameter) { + return emptyParameterService.preserveScript(emptyParameter); + } + + /** + * 缂栬瘧鑴氭湰 + * + * @param emptyParameter + * @return + */ + @AutoLog(value = "铏氳澶囧弬鏁�-缂栬瘧鑴氭湰") + @ApiOperation(value = "铏氳澶囧弬鏁�-缂栬瘧鑴氭湰", notes = "铏氳澶囧弬鏁�-缂栬瘧鑴氭湰") + @PostMapping(value = "/handleCompile") + public Result<?> handleCompile(@RequestBody EmptyParameter emptyParameter) { + return emptyParameterService.handleCompile(emptyParameter); + } + + /** + * 铏氳澶囧弬鏁版坊鍔� + * + * @param emptyParameter + * @return + */ + @AutoLog(value = "铏氳澶囧弬鏁�-娣诲姞") + @ApiOperation(value = "铏氳澶囧弬鏁�-娣诲姞", notes = "铏氳澶囧弬鏁�-娣诲姞") + @PostMapping(value = "/add") + public Result<?> add(@RequestBody EmptyParameter emptyParameter) { + return emptyParameterService.addEmptyParameter(emptyParameter); + } + + /** + * 鎵归噺鏂板 + * + * @param emptyParameters + * @return + */ + @AutoLog(value = "铏氳澶囧弬鏁�-鎵归噺鏂板") + @ApiOperation(value = "铏氳澶囧弬鏁�-鎵归噺鏂板", notes = "铏氳澶囧弬鏁�-鎵归噺鏂板") + @PostMapping(value = "/addBatch") + public Result<?> addBatch(@RequestBody List<EmptyParameter> emptyParameters) { + return emptyParameterService.addBatchEmptyParameter(emptyParameters); + } + + + /** + * 缂栬緫 + * + * @param realParameter + * @return + */ + @AutoLog(value = "铏氳澶囧弬鏁�-缂栬緫") + @ApiOperation(value = "铏氳澶囧弬鏁�-缂栬緫", notes = "铏氳澶囧弬鏁�-缂栬緫") + @PutMapping(value = "/edit") + public Result<?> edit(@RequestBody EmptyParameter realParameter) { + emptyParameterService.editEmptyParameter(realParameter); + return Result.ok("缂栬緫鎴愬姛!"); + } + + /** + * 閫氳繃id鍒犻櫎 + * + * @param id + * @return + */ + @AutoLog(value = "铏氳澶囧弬鏁�-閫氳繃id鍒犻櫎") + @ApiOperation(value = "铏氳澶囧弬鏁�-閫氳繃id鍒犻櫎", notes = "铏氳澶囧弬鏁�-閫氳繃id鍒犻櫎") + @DeleteMapping(value = "/delete") + public Result<?> delete(@RequestParam(name = "id", required = true) String id) { + emptyParameterService.deleteEmptyParameter(id); + return Result.ok("鍒犻櫎鎴愬姛!"); + } + + + /** + * 鏍规嵁鍑芥暟绫诲瀷鏌ヨ鍑芥暟淇℃伅 + * + * @param functionType 鍑芥暟绫诲瀷 + * @return + */ + @ApiOperation(value = "鏍规嵁鍑芥暟绫诲瀷鏌ヨ鍑芥暟淇℃伅", notes = "鏍规嵁鍑芥暟绫诲瀷鏌ヨ鍑芥暟淇℃伅") + @GetMapping(value = "/function") + public Result<?> queryFunctionList(@RequestParam(name = "functionType", required = true) String functionType) { + return Result.ok(equipmentService.findFunctionInformationList(functionType)); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/EquipmentController.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/EquipmentController.java new file mode 100644 index 0000000..756d220 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/EquipmentController.java @@ -0,0 +1,444 @@ +package org.jeecg.modules.iot.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.aspect.annotation.AutoLog; +import org.jeecg.common.system.base.controller.JeecgController; +import org.jeecg.common.system.query.QueryGenerator; +import org.jeecg.modules.iot.entity.*; +import org.jeecg.modules.iot.entity.xmlEntity.*; +import org.jeecg.modules.iot.entity.xmlEntity.ControlSystem; +import org.jeecg.modules.iot.service.*; +import org.jeecg.modules.iot.util.HttpClientUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.*; + + +/** + * @Description: 璁惧 + * @Author: cuikaidong + * @Date: 2024-12-23 + * @Version: V1.0 + */ +@Api(tags = "璁惧") +@RequestMapping("/equipment") +@RestController("iotEquipmentController") +@Slf4j +public class EquipmentController extends JeecgController<Equipment, IEquipmentService> { + @Value("${ftp.address}") + private String ftpAddress; + @Autowired + private org.jeecg.modules.iot.mdc.service.IEquipmentService mdcEquipmentService; + @Autowired + private IEquipmentService equipmentService; + @Autowired + private IServerDeployService serverDeployService; + @Autowired + private IParameterGroupService parameterGroupService; + @Autowired + private IControlSystemService controlSystemService; + + /** + * 鍒嗛〉鍒楄〃鏌ヨ + * + * @param equipment + * @param pageNo + * @param pageSize + * @param serverCode + * @return + */ + @ApiOperation(value = "璁惧-鍒嗛〉鍒楄〃鏌ヨ", notes = "璁惧-鍒嗛〉鍒楄〃鏌ヨ") + @GetMapping(value = "/list") + public Result<?> queryPageList(Equipment equipment, + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + @RequestParam(name = "serverCode", required = false) String serverCode, + HttpServletRequest req) { + QueryWrapper<Equipment> queryWrapper = QueryGenerator.initQueryWrapper(equipment, req.getParameterMap()); + Page<Equipment> page = new Page<>(pageNo, pageSize); + IPage<Equipment> pageList = equipmentService.page(page, queryWrapper); + List<Equipment> records = pageList.getRecords(); + return Result.ok(pageList); + } + + /** + * 閫氳繃id鏌ヨ + * + * @param id + * @return + */ + @GetMapping(value = "/queryById") + public Result<?> queryById(@RequestParam(name = "id", required = true) String id) { + Equipment equipment = equipmentService.getById(id); + return Result.ok(equipment); + } + + /** + * 娣诲姞 + * + * @param equipment + * @return + */ + @AutoLog(value = "瀹炶澶�-娣诲姞") + @ApiOperation(value = "瀹炶澶�-娣诲姞", notes = "瀹炶澶�-娣诲姞") + @PostMapping(value = "/add") + public Result<?> add(@RequestBody Equipment equipment) { + // 楠岃瘉缂栫爜鍚嶇О鏄惁閲嶅 + if (equipmentService.findEquipmentByName(equipment,1)) { + return Result.error("璁惧鍚嶇О宸插瓨鍦紒"); + } + if (equipmentService.findEquipmentByCode(equipment)) { + return Result.error("璁惧缂栧彿宸插瓨鍦紒"); + } + // 鍒嗙被 + equipment.setEquipmentType(1); + // 璁㈤槄涓婚 + ServerDeploy serverDeploy = serverDeployService.getById(equipment.getServerId()); + // 楠岃瘉璁惧缂栧彿鍜岃澶囧悕绉� + equipmentService.save(equipment); + equipment.setReadTopic("IOT/" + serverDeploy.getServerCode() + "/ActualDevices/" + equipment.getEqptCode() + "/Read"); + equipment.setWriteTopic("IOT/" + serverDeploy.getServerCode() + "/ActualDevices/" + equipment.getEqptCode() + "/Write"); + equipmentService.updateById(equipment); + return Result.ok("娣诲姞鎴愬姛锛�"); + } + + /** + * 铏氳澶� + * + * @param equipment + * @return + */ + @AutoLog(value = "铏氳澶�-娣诲姞") + @ApiOperation(value = "铏氳澶�-娣诲姞", notes = "铏氳澶�-娣诲姞") + @PostMapping(value = "/add/empty") + public Result<?> addEmpty(@RequestBody Equipment equipment) { + return equipmentService.addEmpty(equipment); + } + + /** + * 缂栬緫 + * + * @param equipment + * @return + */ + @AutoLog(value = "璁惧-缂栬緫") + @ApiOperation(value = "璁惧-缂栬緫", notes = "璁惧-缂栬緫") + @PutMapping(value = "/edit") + public Result<?> edit(@RequestBody Equipment equipment) { + equipment.setCreateTime(new Date()); + // 楠岃瘉鏄惁鏄櫄璁惧 + if (equipment.getEquipmentType() == 0) { + Equipment equipmentById = equipmentService.getById(equipment.getId()); + // 楠岃瘉鏄惁缂栬緫浜嗚櫄璁惧鍚嶇О + if (!equipment.getEqptName().equals(equipmentById.getEqptName())){ + ServerDeploy serverDeploy = serverDeployService.getById(equipment.getServerId()); + Map<String, String> param = new HashMap<>(); + // 鍙戦�佹枃浠跺湴鍧� + param.put("path", ftpAddress + serverDeploy.getServerCode() + "/script"); + HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/ProjectPath", param); + param.clear(); + // 鍒犻櫎鍘熸潵鐨勬枃浠� + param.put("id", equipmentById.getEqptCode()); + HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/DeleteDevicescript", param); + param.clear(); + // 娣诲姞鏂版枃浠� + param.put("id", equipment.getEqptCode()); + HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/AddDevicescript", param); + org.jeecg.modules.iot.mdc.entity.Equipment mdcEquipment = mdcEquipmentService.findEquipmentByEquipmentId(equipment.getEqptCode()); + if (mdcEquipment != null){ + mdcEquipment.setEquipmentname(equipment.getEqptName()); + mdcEquipmentService.updateById(mdcEquipment); + } + } + } + equipmentService.updateById(equipment); + return Result.ok("缂栬緫鎴愬姛!"); + } + + /** + * 閫氳繃id鍒犻櫎 + * + * @param id + * @return + */ + @AutoLog(value = "璁惧-閫氳繃id鍒犻櫎") + @ApiOperation(value = "璁惧-閫氳繃id鍒犻櫎", notes = "璁惧-閫氳繃id鍒犻櫎") + @DeleteMapping(value = "/delete") + public Result<?> delete(@RequestParam(name = "id", required = true) String id) { + List<ParameterGroup> parameterGroupList = parameterGroupService.findParameterGroupByServerId(id); + if (parameterGroupList.size() > 0) { + return Result.error("鍒犻櫎澶辫触锛岃鍏堝垹闄ゅ弬鏁扮粍!"); + } + Equipment equipment = equipmentService.getById(id); + if (equipment.getEquipmentType().equals(0)) { + ServerDeploy serverDeploy = serverDeployService.getById(equipment.getServerId()); + //鍒犻櫎铏氳澶囨椂璋冪敤 + Map<String, String> param = new HashMap<>(); + param.put("path", ftpAddress + serverDeploy.getServerCode() + "/script"); + HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/ProjectPath", param); + param.clear(); + param.put("id", equipment.getEqptCode()); + HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/DeleteDevicescript", param); + } + equipmentService.removeById(id); + return Result.ok("鍒犻櫎鎴愬姛!"); + } + + /** + * 鏍规嵁鏈嶅姟鍣╥d鏌ヨ璁惧璁㈤槄鍒楄〃 + * + * @return + */ + @ApiOperation(value = "鏍规嵁鏈嶅姟鍣╥d鏌ヨ璁惧璁㈤槄鍒楄〃", notes = "鏍规嵁鏈嶅姟鍣╥d鏌ヨ璁惧璁㈤槄鍒楄〃") + @GetMapping(value = "/subscribe") + public Result<?> queryEquipmentSubscribe(@RequestParam(name = "id") String id) { + Object[] subscribeList = equipmentService.queryEquipmentSubscribeList(id); + return Result.ok(subscribeList); + } + + /** + * 鏌ヨ绯荤粺绫诲瀷 + * + * @return + */ + @ApiOperation(value = "鏌ヨ绯荤粺绫诲瀷", notes = "鏌ヨ绯荤粺绫诲瀷") + @GetMapping(value = "/querySystemType") + public Result<?> querySystemType() { + List<SystemType> systemTypes = equipmentService.findProjectCode(); + return Result.ok(systemTypes); + } + + /** + * 鏍规嵁绯荤粺绫诲瀷鏌ヨ鎺у埗绯荤粺鍒楄〃 + * + * @return + */ + @ApiOperation(value = "鏌ヨ鎺у埗绯荤粺鍒楄〃", notes = "鏌ヨ鎺у埗绯荤粺鍒楄〃") + @GetMapping(value = "/queryControlSystem") + public Result<?> queryControlSystem(@RequestParam(name = "type") String type) { + List<ControlSystem> controlSystems = equipmentService.findControlSystems(type); + return Result.ok(controlSystems); + } + + /** + * 鏌ヨ瀛楄妭椤哄簭鍒楄〃 + * + * @return + */ + @ApiOperation(value = "鏌ヨ瀛楄妭椤哄簭鍒楄〃", notes = "鏌ヨ瀛楄妭椤哄簭鍒楄〃") + @GetMapping(value = "/queryByteOrder") + public Result<?> queryByteOrder() { + List<ByteOrder> byteOrders = equipmentService.findByteOrder(); + return Result.ok(byteOrders); + } + + /** + * 鏌ヨ鍙傛暟绫诲瀷鍒楄〃 + * + * @return + */ + @ApiOperation(value = "鏌ヨ鍙傛暟绫诲瀷鍒楄〃", notes = "鏌ヨ鍙傛暟绫诲瀷鍒楄〃") + @GetMapping(value = "/querySystemDataType") + public Result<?> querySystemDataType() { + List<SystemDataType> systemDataTypeList = equipmentService.findSystemDataTypeList(); + return Result.ok(systemDataTypeList); + } + + /** + * 鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧閲囬泦鍙傛暟 + * + * @return + */ + @ApiOperation(value = "鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧閲囬泦鍙傛暟", notes = "鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧閲囬泦鍙傛暟") + @GetMapping(value = "/queryParameter") + public Result<?> queryParameter(@RequestParam(name = "id") String id) { + List<Parameter> controlSystems = equipmentService.findParameterById(id); + return Result.ok(controlSystems); + } + /** + * 鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧鑷畾涔夐噰闆嗗弬鏁� + * + * @return + */ + @ApiOperation(value = "鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧鑷畾涔夐噰闆嗗弬鏁�", notes = "鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧鑷畾涔夐噰闆嗗弬鏁�") + @GetMapping(value = "/customize/queryParameter") + public Result<?> queryParameterCustomize(@RequestParam(name = "id") String id) { + List<Parameter> controlSystems = equipmentService.findParameterCustomizeById(id); + return Result.ok(controlSystems); + } + + /** + * 鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧閲囬泦鍙傛暟绫诲瀷 + * + * @return + */ + @ApiOperation(value = "鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧閲囬泦鍙傛暟绫诲瀷", notes = "鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧閲囬泦鍙傛暟绫诲瀷") + @GetMapping(value = "/queryDataType") + public Result<?> queryDataType(@RequestParam(name = "id") String id) { + List<Parameter> parameters = equipmentService.findDataTypeById(id); + return Result.ok(parameters); + } + + /** + * 鏍规嵁铏氳澶噄d鏌ヨ璁惧鍒嗙被鏍� + * + * @return projectClassifyList + */ + @AutoLog(value = "鏍规嵁铏氳澶噄d鏌ヨ璁惧鍒嗙被鏍�") + @ApiOperation(value = "鏍规嵁铏氳澶噄d鏌ヨ璁惧鍒嗙被鏍�", notes = "鏌ヨ椤圭洰鍒嗙被鏍戠粨鏋�") + @GetMapping(value = "/tree") + public Result<?> queryPageList(@RequestParam(name = "id") String id) { + Equipment equipment = equipmentService.getById(id); + ServerDeploy serverDeploy = serverDeployService.getById(equipment.getServerId()); + // 鏍戝浘鏍� + Map<String, String> iconIot = new HashMap<>(); + iconIot.put("icon", "iot"); + Map<String, String> iconProject = new HashMap<>(); + iconProject.put("icon", "classify"); + Map<String, String> iconProject1 = new HashMap<>(); + iconProject1.put("icon", "project"); + Map<String, String> iconEmpty = new HashMap<>(); + iconEmpty.put("icon", ""); + Map<String, String> iconSolid = new HashMap<>(); + iconSolid.put("icon", ""); + // 鏌ヨ鏁版嵁 + List<Equipment> equipmentList = equipmentService.findEquipmentByServerId(serverDeploy.getId()); + List<ParameterGroup> groupList = parameterGroupService.findParameterGroupByServerId(serverDeploy.getId()); + // 鏍戠粨鏋� + List<IotTree> trees1 = new ArrayList<>(); + List<IotTree> treeList = new ArrayList<>(); + + IotTree iotTree = new IotTree(); + iotTree.setTitle(serverDeploy.getServerName()); + iotTree.setKey("fwq_" + serverDeploy.getServerCode()); + iotTree.setSlots(iconIot); + + + // 閬嶅巻璁惧淇℃伅 + equipmentList.forEach(eq -> { + IotTree emptyEquipment = new IotTree(); + emptyEquipment.setTitle(eq.getEqptName()); + List<IotTree> treeList4 = new ArrayList<>();// 鍙傛暟缁� + // 閬嶅巻鍙傛暟缁勪俊鎭� + groupList.forEach(g -> { + if (eq.getId().equals(g.getEquipmentId())) { + IotTree groupTree = new IotTree(); + groupTree.setTitle(g.getName()); + groupTree.setKey("ssb_" + g.getId()); + groupTree.setSlots(iconSolid); + treeList4.add(groupTree); + } + }); + if (serverDeploy.getId().equals(eq.getServerId()) && eq.getEquipmentType().equals(1)) { + emptyEquipment.setSlots(iconSolid); + emptyEquipment.setKey("group_" + eq.getId()); + emptyEquipment.setChildren(treeList4); + trees1.add(emptyEquipment); + } + iotTree.setChildren(treeList4); + }); + + iotTree.setChildren(trees1); + treeList.add(iotTree); + return Result.ok(treeList); + } + + /** + * 鏍规嵁鏈嶅姟鍣╥d鏌ヨ鏈嶅姟鍣ㄤ笅璁惧鍒嗙被鏍� + * + * @return projectClassifyList + */ + @AutoLog(value = "鏍规嵁鏈嶅姟鍣╥d鏌ヨ鏈嶅姟鍣ㄤ笅璁惧鍒嗙被鏍�") + @ApiOperation(value = "鏍规嵁鏈嶅姟鍣╥d鏌ヨ鏈嶅姟鍣ㄤ笅璁惧鍒嗙被鏍�", notes = "鏍规嵁鏈嶅姟鍣╥d鏌ヨ鏈嶅姟鍣ㄤ笅璁惧鍒嗙被鏍�") + @GetMapping(value = "/tree/collect") + public Result<?> queryCollectTree(@RequestParam(name = "id") String id) { + ServerDeploy serverDeploy = serverDeployService.getById(id); + // 鏍戝浘鏍� + Map<String, String> iconProject1 = new HashMap<>(); // 鏈嶅姟鍣ㄥ浘鏍� + iconProject1.put("icon", "project"); + Map<String, String> iconEmpty = new HashMap<>(); + iconEmpty.put("icon", "empty"); + Map<String, String> iconSolid = new HashMap<>(); + iconSolid.put("icon", "solid"); + Map<String, String> iconParameter = new HashMap<>(); + iconParameter.put("icon", ""); + // 鏌ヨ鏁版嵁 + List<Equipment> equipmentList = equipmentService.findEquipmentByServerId(serverDeploy.getId()); + List<ParameterGroup> groupList = parameterGroupService.findParameterGroupByServerId(serverDeploy.getId()); + // 鏍戠粨鏋� + List<IotTree> trees2 = new ArrayList<>(); + List<IotTree> treeList = new ArrayList<>(); + + IotTree iotTree = new IotTree(); + iotTree.setTitle(serverDeploy.getServerName()); + iotTree.setKey("fwq_" + serverDeploy.getServerCode()); + iotTree.setSlots(iconProject1); + List<IotTree> treeList1 = new ArrayList<>();// 瀹炶澶� + List<IotTree> treeList2 = new ArrayList<>(); //铏氳澶� + // 瀹炶澶囨坊鍔� + IotTree empty = new IotTree(); + empty.setTitle("瀹炶澶�"); + empty.setKey("solid_" + serverDeploy.getServerCode()); + empty.setSlots(iconParameter); + // 铏氳澶囨坊鍔� + IotTree solid = new IotTree(); + solid.setTitle("铏氳澶�"); + solid.setKey("empty_" + serverDeploy.getServerCode()); + solid.setSlots(iconParameter); + // 閬嶅巻璁惧淇℃伅 + equipmentList.forEach(eq -> { + IotTree emptyEquipment = new IotTree(); + emptyEquipment.setTitle(eq.getEqptName()); + List<IotTree> treeList4 = new ArrayList<>();// 鍙傛暟缁� + // 閬嶅巻鍙傛暟缁勪俊鎭� + groupList.forEach(g -> { + if (eq.getId().equals(g.getEquipmentId())) { + IotTree groupTree = new IotTree(); + groupTree.setTitle(g.getName()); + groupTree.setKey("ssb_" + g.getId()); + groupTree.setSlots(iconParameter); + treeList4.add(groupTree); + } + }); + if (serverDeploy.getId().equals(eq.getServerId()) && eq.getEquipmentType().equals(1)) { + emptyEquipment.setSlots(iconSolid); + emptyEquipment.setKey("group_" + eq.getId()); + emptyEquipment.setChildren(treeList4); + treeList1.add(emptyEquipment); + } else if (serverDeploy.getId().equals(eq.getServerId()) && eq.getEquipmentType().equals(0)) { + emptyEquipment.setKey("xxb_" + eq.getId()); + emptyEquipment.setSlots(iconEmpty); + treeList2.add(emptyEquipment); + } + + }); + solid.setChildren(treeList2); + empty.setChildren(treeList1); + trees2.add(empty); + trees2.add(solid); + iotTree.setChildren(trees2); + treeList.add(iotTree); + return Result.ok(treeList); + } + + /** + * 鏌ヨ鎺у埗绯荤粺淇℃伅鍒楄〃 + * + * @return + */ + @ApiOperation(value = "鏌ヨ鎺у埗绯荤粺淇℃伅鍒楄〃", notes = "鏌ヨ鎺у埗绯荤粺淇℃伅鍒楄〃") + @GetMapping(value = "/findControlSystem") + public Result<?> findControlSystem() { + return Result.ok(controlSystemService.list()); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ParameterGroupController.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ParameterGroupController.java new file mode 100644 index 0000000..35bec8f --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ParameterGroupController.java @@ -0,0 +1,133 @@ +package org.jeecg.modules.iot.controller; + + +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.aspect.annotation.AutoLog; +import org.jeecg.common.system.base.controller.JeecgController; +import org.jeecg.common.system.query.QueryGenerator; +import org.jeecg.modules.iot.entity.Equipment; +import org.jeecg.modules.iot.entity.ParameterGroup; +import org.jeecg.modules.iot.entity.RealParameter; +import org.jeecg.modules.iot.service.IEquipmentService; +import org.jeecg.modules.iot.service.IParameterGroupService; +import org.jeecg.modules.iot.service.IRealParameterService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + + +/** + * @Description: 鍙傛暟缁� + * @Author: cuikaidong + * @Date: 2024-12-23 + * @Version: V1.0 + */ +@Api(tags = "鍙傛暟缁�") +@RestController +@RequestMapping("/parameter/group") +@Slf4j +public class ParameterGroupController extends JeecgController<ParameterGroup, IParameterGroupService> { + + private final IParameterGroupService parameterGroupService; + + public ParameterGroupController(IParameterGroupService parameterGroupService) { + this.parameterGroupService = parameterGroupService; + } + + @Autowired + private IEquipmentService equipmentService; + @Autowired + private IRealParameterService realParameterService; + + /** + * 鍒嗛〉鍒楄〃鏌ヨ + * + * @param parameterGroup 鍙傛暟缁� + * @param pageNo 寮�濮� + * @param pageSize 缁撴潫 + * @return 鍙傛暟缁勫垪琛� + */ + @ApiOperation(value = "鍙傛暟缁�-鍒嗛〉鍒楄〃鏌ヨ", notes = "鍙傛暟缁�-鍒嗛〉鍒楄〃鏌ヨ") + @GetMapping(value = "/list") + public Result<?> queryPageList(ParameterGroup parameterGroup, + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest req) { + QueryWrapper<ParameterGroup> queryWrapper = QueryGenerator.initQueryWrapper(parameterGroup, req.getParameterMap()); + Page<ParameterGroup> page = new Page<>(pageNo, pageSize); + IPage<ParameterGroup> pageList = parameterGroupService.page(page, queryWrapper); + return Result.ok(pageList); + } + + /** + * 娣诲姞 + * + * @param parameterGroup 鍙傛暟缁� + * @return 鎴愬姛娑堟伅 + */ + @AutoLog(value = "瀹炲弬鏁扮粍-娣诲姞") + @ApiOperation(value = "瀹炲弬鏁扮粍-娣诲姞", notes = "瀹炲弬鏁扮粍-娣诲姞") + @PostMapping(value = "/add") + public Result<?> add(@RequestBody ParameterGroup parameterGroup) { + return parameterGroupService.addParameterGroup(parameterGroup); + } + + /** + * 缂栬緫 + * + * @param parameterGroup 鍙傛暟缁� + * @return 鎴愬姛娑堟伅 + */ + @AutoLog(value = "鍙傛暟缁�-缂栬緫") + @ApiOperation(value = "鍙傛暟缁�-缂栬緫", notes = "鍙傛暟缁�-缂栬緫") + @PutMapping(value = "/edit") + public Result<?> edit(@RequestBody ParameterGroup parameterGroup) { + parameterGroupService.updateById(parameterGroup); + return Result.ok("缂栬緫鎴愬姛!"); + } + + /** + * 閫氳繃id鍒犻櫎 + * + * @param id 鍙傛暟缁刬d + * @return 鎻愮ず + */ + @AutoLog(value = "鍙傛暟缁�-閫氳繃id鍒犻櫎") + @ApiOperation(value = "鍙傛暟缁�-閫氳繃id鍒犻櫎", notes = "鍙傛暟缁�-閫氳繃id鍒犻櫎") + @DeleteMapping(value = "/delete") + public Result<?> delete(@RequestParam(name = "id") String id) { + // 鏌ヨ鍙傛暟缁勪笅鍙傛暟淇℃伅 + Set<String> ids = new HashSet<>(); + ids.add(id); + List<RealParameter> realParameter = realParameterService.findRealParameterByIds(ids); + if (CollectionUtil.isNotEmpty(realParameter)) { + return Result.error("鍒犻櫎澶辫触锛岃鍏堝垹闄ゅ弬鏁颁俊鎭�!"); + } + parameterGroupService.removeById(id); + return Result.ok("鍒犻櫎鎴愬姛!"); + } + + /** + * 閫氳繃鍙傛暟缁刬d鏌ヨ璁惧淇℃伅 + * + * @param id + * @return + */ + @GetMapping(value = "/queryById") + public Result<?> queryById(@RequestParam(name = "id", required = true) String id) { + ParameterGroup parameterGroup = parameterGroupService.getById(id); + Equipment equipment = equipmentService.getById(parameterGroup.getEquipmentId()); + return Result.ok(equipment); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ProjectClassifyController.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ProjectClassifyController.java new file mode 100644 index 0000000..22c3564 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ProjectClassifyController.java @@ -0,0 +1,212 @@ +package org.jeecg.modules.iot.controller; + + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.aspect.annotation.AutoLog; +import org.jeecg.common.system.base.controller.JeecgController; +import org.jeecg.modules.iot.entity.*; +import org.jeecg.modules.iot.service.IEquipmentService; +import org.jeecg.modules.iot.service.IParameterGroupService; +import org.jeecg.modules.iot.service.IProjectClassifyService; +import org.jeecg.modules.iot.service.IServerDeployService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.*; + + +/** + * @Description: 椤圭洰鍒嗙被 + * @Author: cuikaidong + * @Date: 2024-12-20 + * @Version: V1.0 + */ +@Api(tags = "椤圭洰鍒嗙被") +@RestController +@RequestMapping("/projectClassify") +@Slf4j +public class ProjectClassifyController extends JeecgController<ProjectClassify, IProjectClassifyService> { + @Autowired + private IProjectClassifyService projectClassifyService; + @Autowired + private IServerDeployService serverDeployService; + @Autowired + private IEquipmentService equipmentService; + @Autowired + private IParameterGroupService parameterGroupService; + + /** + * 鏌ヨ椤圭洰鍒嗙被鏍戠粨鏋� + * + * @return projectClassifyList + */ + @AutoLog(value = "鏌ヨ椤圭洰鍒嗙被鏍戠粨鏋�") + @ApiOperation(value = "鏌ヨ椤圭洰鍒嗙被鏍戠粨鏋�", notes = "鏌ヨ椤圭洰鍒嗙被鏍戠粨鏋�") + @GetMapping(value = "/tree") + public Result<?> queryPageList() { + // 鏍戝浘鏍� + Map<String, String> iconIot = new HashMap<>(); // iot鍥炬爣 + iconIot.put("icon", "iot"); + Map<String, String> iconProject = new HashMap<>(); // + iconProject.put("icon", "classify"); + Map<String, String> iconProject1 = new HashMap<>(); // 鏈嶅姟鍣ㄥ浘鏍� + iconProject1.put("icon", "project"); + Map<String, String> iconEmpty = new HashMap<>(); + iconEmpty.put("icon", "empty"); + Map<String, String> iconSolid = new HashMap<>(); + iconSolid.put("icon", "solid"); + Map<String, String> iconParameter = new HashMap<>(); + iconParameter.put("icon", ""); + // 鏌ヨ鏁版嵁 + List<ProjectClassify> projectList = projectClassifyService.list(); + List<ServerDeploy> serverDeployList = serverDeployService.list(); + List<Equipment> equipmentList = equipmentService.list(); + List<ParameterGroup> groupList = parameterGroupService.list(); + // 鏍戠粨鏋� + List<IotTree> trees1 = new ArrayList<>(); + List<IotTree> trees2 = new ArrayList<>(); + List<IotTree> treeList = new ArrayList<>(); + + IotTree iotTree = new IotTree(); + iotTree.setTitle("IOT閲囬泦骞冲彴"); + iotTree.setKey("0"); + iotTree.setSlots(iconIot); + for (ProjectClassify project : projectList) { + IotTree it = new IotTree(); + it.setTitle(project.getProjectName()); + it.setKey(project.getProjectCode()); + it.setSlots(iconProject); + trees2 = new ArrayList<>(); + for (ServerDeploy serverDeploy : serverDeployList) { + if (project.getId().equals(serverDeploy.getProjectClassifyId())) { + List<IotTree> treeList1 = new ArrayList<>();// 瀹炶澶� + List<IotTree> treeList2 = new ArrayList<>(); //铏氳澶� + List<IotTree> trees3 = new ArrayList<>(); // 鍒嗙被 + IotTree itProject = new IotTree(); + itProject.setTitle(serverDeploy.getServerCode() + "-" + serverDeploy.getServerName()); + itProject.setKey("fwq_" + serverDeploy.getServerCode()); + itProject.setSlots(iconProject1); + // 瀹炶澶囨坊鍔� + IotTree empty = new IotTree(); + empty.setTitle("瀹炶澶�"); + empty.setKey("solid_" + serverDeploy.getServerCode()); + empty.setSlots(iconParameter); + // 铏氳澶囨坊鍔� + IotTree solid = new IotTree(); + solid.setTitle("铏氳澶�"); + solid.setKey("empty_" + serverDeploy.getServerCode()); + solid.setSlots(iconParameter); + // 閬嶅巻璁惧淇℃伅 + equipmentList.forEach(eq -> { + IotTree emptyEquipment = new IotTree(); + emptyEquipment.setTitle(eq.getEqptName()); + List<IotTree> treeList4 = new ArrayList<>();// 鍙傛暟缁� + // 閬嶅巻鍙傛暟缁勪俊鎭� + groupList.forEach(g -> { + if (eq.getId().equals(g.getEquipmentId())) { + IotTree groupTree = new IotTree(); + groupTree.setTitle(g.getName()); + groupTree.setKey("ssb_" + g.getId()); + groupTree.setSlots(iconParameter); + treeList4.add(groupTree); + } + }); + if (serverDeploy.getId().equals(eq.getServerId()) && eq.getEquipmentType().equals(1)) { + emptyEquipment.setSlots(iconSolid); + emptyEquipment.setKey("group_" + eq.getId()); + emptyEquipment.setChildren(treeList4); + treeList1.add(emptyEquipment); + } else if (serverDeploy.getId().equals(eq.getServerId()) && eq.getEquipmentType().equals(0)) { + emptyEquipment.setKey("xxb_" + eq.getId()); + emptyEquipment.setSlots(iconEmpty); + treeList2.add(emptyEquipment); + } + + }); + solid.setChildren(treeList2); + empty.setChildren(treeList1); + trees3.add(empty); + trees3.add(solid); + itProject.setChildren(trees3); + trees2.add(itProject); + } + } + + it.setChildren(trees2); + trees1.add(it); + + } + iotTree.setChildren(trees1); + treeList.add(iotTree); + return Result.ok(treeList); + } + + /** + * 閫氳繃projectCode鏌ヨ + * + * @param projectCode + * @return + */ + @ApiOperation(value = "椤圭洰鍒嗙被-閫氳繃projectCode鏌ヨ", notes = "椤圭洰鍒嗙被-閫氳繃projectCode鏌ヨ") + @GetMapping(value = "/queryByProjectCode") + public Result<?> queryByProjectCode(@RequestParam(name = "projectCode", required = true) String projectCode) { + ProjectClassify projectClassify = projectClassifyService.findByProjectCode(projectCode); + return Result.ok(projectClassify); + } + + /** + * 娣诲姞 + * + * @param projectClassify + * @return + */ + @AutoLog(value = "椤圭洰鍒嗙被-娣诲姞") + @ApiOperation(value = "椤圭洰鍒嗙被-娣诲姞", notes = "椤圭洰鍒嗙被-娣诲姞") + @PostMapping(value = "/add") + public Result<?> add(@RequestBody ProjectClassify projectClassify) { + projectClassify.setProjectCode(randomDigit()); + projectClassifyService.addProjectClassify(projectClassify); + return Result.ok("娣诲姞鎴愬姛锛�"); + } + + /** + * 缂栬緫 + * + * @param projectClassify + * @return + */ + @AutoLog(value = "椤圭洰鍒嗙被-缂栬緫") + @ApiOperation(value = "椤圭洰鍒嗙被-缂栬緫", notes = "椤圭洰鍒嗙被-缂栬緫") + @PutMapping(value = "/edit") + public Result<?> edit(@RequestBody ProjectClassify projectClassify) { + projectClassifyService.updateById(projectClassify); + return Result.ok("缂栬緫鎴愬姛!"); + } + + /** + * 閫氳繃id鍒犻櫎 + * + * @param id + * @return + */ + @AutoLog(value = "椤圭洰鍒嗙被-閫氳繃id鍒犻櫎") + @ApiOperation(value = "椤圭洰鍒嗙被-閫氳繃id鍒犻櫎", notes = "椤圭洰鍒嗙被-閫氳繃id鍒犻櫎") + @DeleteMapping(value = "/delete") + public Result<?> delete(@RequestParam(name = "id", required = true) String id) { + return Result.ok(projectClassifyService.projectClassifyRemoveById(id)); + } + + private String randomDigit() { + Random random = new Random(); + String randomNumber = "xm_" + random.nextInt(9000) + 1000; + ProjectClassify projectClassify = projectClassifyService.findByProjectCode(randomNumber); + if (projectClassify != null) { + randomDigit(); + } + return randomNumber; + } + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/RealParameterController.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/RealParameterController.java new file mode 100644 index 0000000..67f9bcf --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/RealParameterController.java @@ -0,0 +1,176 @@ +package org.jeecg.modules.iot.controller; + + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.aspect.annotation.AutoLog; +import org.jeecg.common.system.base.controller.JeecgController; +import org.jeecg.modules.iot.entity.RealParameter; +import org.jeecg.modules.iot.service.IRealParameterService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; + + +/** + * @Description: 瀹炶澶囧弬鏁� + * @Author: cuikaidong + * @Date: 2024-12-23 + * @Version: V1.0 + */ +@Api(tags = "瀹炶澶囧弬鏁�") +@RestController +@RequestMapping("/real/parameter") +@Slf4j +public class RealParameterController extends JeecgController<RealParameter, IRealParameterService> { + + @Autowired + private IRealParameterService realParameterService; + + /** + * 鍒嗛〉鍒楄〃鏌ヨ + * + * @param pageNo + * @param pageSize + * @return + */ + @ApiOperation(value = "瀹炶澶囧弬鏁�-鍒嗛〉鍒楄〃鏌ヨ", notes = "瀹炶澶囧弬鏁�-鍒嗛〉鍒楄〃鏌ヨ") + @GetMapping(value = "/list") + public Result<?> queryPageList(RealParameter realParameter, + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest req) { + Page<RealParameter> page = new Page<>(pageNo, pageSize); + Map<String, Object> params = new HashMap<>(); + params.put("parameterGroupId", realParameter.getParameterGroupId()); + params.put("parameterName", realParameter.getParameterName()); + params.put("parameterCode", realParameter.getParameterCode()); + IPage<RealParameter> pageList = realParameterService.findRealParameterPage(page, params); + return Result.ok(pageList); + } + + /** + * 閫氳繃id鏌ヨ + * + * @param id + * @return + */ + @GetMapping(value = "/queryById") + public Result<?> queryById(@RequestParam(name = "id", required = true) String id) { + RealParameter RealParameter = realParameterService.getById(id); + return Result.ok(RealParameter); + } + + /** + * 鏍囧噯鍙傛暟鎵归噺瀵煎叆 + * + * @param id + * @return + */ + @GetMapping(value = "/canonicalParameter") + public Result<?> canonicalParameter(@RequestParam(name = "id", required = true) String id) { + return realParameterService.canonicalParameter(id); + } + + + + /** + * 娣诲姞 + * + * @param realParameter + * @return + */ + @AutoLog(value = "瀹炶澶囧弬鏁�-娣诲姞") + @ApiOperation(value = "瀹炶澶囧弬鏁�-娣诲姞", notes = "瀹炶澶囧弬鏁�-娣诲姞") + @PostMapping(value = "/add") + public Result<?> add(@RequestBody RealParameter realParameter) { + // 鏌ヨ鏈�鏂扮紪鍙� + realParameter.setParameterCode(realParameterService.findRealParameterGroupId(realParameter.getParameterGroupId())); + // 楠岃瘉缂栫爜鍚嶇О鏄惁閲嶅 + if (realParameterService.findRealParameterByName(realParameter)) { + return Result.error("鍙傛暟鍚嶇О宸插瓨鍦紒"); + } + + // 楠岃瘉瀹炶澶囧弬鏁扮紪鍙峰拰瀹炶澶囧弬鏁板悕绉� + realParameterService.save(realParameter); + return Result.ok("娣诲姞鎴愬姛锛�"); + } + + + /** + * 缂栬緫 + * + * @param realParameter + * @return + */ + @AutoLog(value = "瀹炶澶囧弬鏁�-缂栬緫") + @ApiOperation(value = "瀹炶澶囧弬鏁�-缂栬緫", notes = "瀹炶澶囧弬鏁�-缂栬緫") + @PutMapping(value = "/edit") + public Result<?> edit(@RequestBody RealParameter realParameter) { + realParameterService.updateById(realParameter); + return Result.ok("缂栬緫鎴愬姛!"); + } + + /** + * 瀹炶澶囧弬鏁板啓鍏� + * + * @param realParameter + * @return + */ + @AutoLog(value = "瀹炶澶囧弬鏁�-鍐欏叆") + @ApiOperation(value = "瀹炶澶囧弬鏁�-鍐欏叆", notes = "瀹炶澶囧弬鏁�-鍐欏叆") + @PutMapping(value = "/writing") + public Result<?> writing(@RequestBody RealParameter realParameter) { + return realParameterService.parameterWriting(realParameter); + } + + /** + * 閫氳繃id鍒犻櫎 + * + * @param id + * @return + */ + @AutoLog(value = "瀹炶澶囧弬鏁�-閫氳繃id鍒犻櫎") + @ApiOperation(value = "瀹炶澶囧弬鏁�-閫氳繃id鍒犻櫎", notes = "瀹炶澶囧弬鏁�-閫氳繃id鍒犻櫎") + @DeleteMapping(value = "/delete") + public Result<?> delete(@RequestParam(name = "id", required = true) String id) { + realParameterService.removeById(id); + return Result.ok("鍒犻櫎鎴愬姛!"); + } + + /** + * 瀵煎嚭excel + * + * @param request + * @param realParameter + */ + //@RequiresPermissions("org.jeecg.modules.demo:qa_element:exportXls") + @RequestMapping(value = "/exportXls") + public ModelAndView exportXls(HttpServletRequest request, RealParameter realParameter) { + return realParameterService.exportXls(request, realParameter,"璁惧鍙傛暟"); + } + + + /** + * 閫氳繃excel瀵煎叆鏁版嵁 + * + * @param request + * @param response + * @return + */ + @ApiOperation(value = "瀹炶澶囧弬鏁�-閫氳繃excel瀵煎叆鏁版嵁", notes = "瀹炶澶囧弬鏁�-閫氳繃excel瀵煎叆鏁版嵁") + //@RequiresPermissions("qa_element:importExcel") + @RequestMapping(value = "/importExcel", method = RequestMethod.POST) + public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { + return realParameterService.importExcel(request, response); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ServeDeployController.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ServeDeployController.java new file mode 100644 index 0000000..892cec1 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/controller/ServeDeployController.java @@ -0,0 +1,391 @@ +package org.jeecg.modules.iot.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.aspect.annotation.AutoLog; +import org.jeecg.common.system.base.controller.JeecgController; +import org.jeecg.common.system.query.QueryGenerator; +import org.jeecg.modules.iot.entity.*; +import org.jeecg.modules.iot.mqtt.config.MqttCustomerClient; +import org.jeecg.modules.iot.service.IEquipmentService; +import org.jeecg.modules.iot.service.IInfluxdbDeployService; +import org.jeecg.modules.iot.service.IMqttDeployService; +import org.jeecg.modules.iot.service.IServerDeployService; +import org.jeecg.modules.iot.util.FileUtil; +import org.jeecg.modules.iot.util.FtpUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.RestTemplate; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.Date; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.stream.Collectors; + + +/** + * @Description: 椤圭洰鍒嗙被 + * @Author: cuikaidong + * @Date: 2024-12-22 + * @Version: V1.0 + */ +@Api(tags = "鏈嶅姟鍣ㄩ厤缃�") +@RestController +@RequestMapping("/serve/deploy") +@Slf4j +public class ServeDeployController extends JeecgController<ServerDeploy, IServerDeployService> { + @Autowired + private IServerDeployService serverDeployService; + @Autowired + private IInfluxdbDeployService influxdbDeployService; + @Autowired + private IMqttDeployService mqttDeployService; + @Autowired + private MqttCustomerClient mqttCustomerClient; + @Resource + private RestTemplate restTemplate; + @Autowired + private IEquipmentService equipmentService; + @Value("${ftp.address}") + private String ftpAddress; + + /** + * 閫氳繃projectCode鏌ヨ + * + * @param projectCode + * @return + */ + @ApiOperation(value = "椤圭洰鍒嗙被-閫氳繃projectCode鏌ヨ", notes = "椤圭洰鍒嗙被-閫氳繃projectCode鏌ヨ") + @GetMapping(value = "/queryByProjectCode") + public Result<?> queryByProjectCode(@RequestParam(name = "projectCode", required = true) String projectCode) { + ServerDeploy serverDeploy = serverDeployService.findByServerCode(projectCode); + return Result.ok(serverDeploy); + } + + /** + * 鍒嗛〉鍒楄〃鏌ヨ + * + * @param serverDeploy + * @param pageNo + * @param pageSize + * @param projectClassifyId + * @return + */ + @ApiOperation(value = "鏈嶅姟鍣ㄩ厤缃�-鍒嗛〉鍒楄〃鏌ヨ", notes = "鏈嶅姟鍣ㄩ厤缃�-鍒嗛〉鍒楄〃鏌ヨ") + @GetMapping(value = "/list") + public Result<?> queryPageList(ServerDeploy serverDeploy, + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + @RequestParam(name = "projectClassifyId", required = false) String projectClassifyId, + HttpServletRequest req) { + QueryWrapper<ServerDeploy> queryWrapper = QueryGenerator.initQueryWrapper(serverDeploy, req.getParameterMap()); + Page<ServerDeploy> page = new Page<>(pageNo, pageSize); + IPage<ServerDeploy> pageList = serverDeployService.page(page, queryWrapper); + List<ServerDeploy> records = pageList.getRecords(); + if (!records.isEmpty()) { + Set<String> collect = records.stream().map(ServerDeploy::getId).collect(Collectors.toSet()); + // 鏌ヨmqtt鏁版嵁 + List<MqttDeploy> mqttDeployList = mqttDeployService.findByServerIdsMqttDeploy(collect); + // 鏌ヨInfluxdb鏁版嵁 + List<InfluxdbDeploy> influxdbList = influxdbDeployService.findByServerIdsInfluxdbDeploy(collect); + records.forEach(r -> { + // 缁堢鍦板潃 + r.setAddress("http://" + r.getServerAddress() + ":" + r.getServerPort()); + mqttDeployList.forEach(m -> { + if (m.getServerDeployId().equals(r.getId())) { + r.setMqttDeploy(m); + } + }); + influxdbList.forEach(i -> { + if (i.getServerDeployId().equals(r.getId())) { + r.setInfluxdbDeploy(i); + } + }); + }); + } + return Result.ok(pageList); + } + + /** + * 娣诲姞 + * + * @param serverDeploy + * @return + */ + @ApiOperation(value = "鏈嶅姟鍣ㄩ厤缃�-娣诲姞", notes = "鏈嶅姟鍣ㄩ厤缃�-娣诲姞") + @PostMapping(value = "/add") + public Result<?> add(@RequestBody ServerDeploy serverDeploy) { + serverDeploy.setServerCode(this.randomDigit()); + serverDeploy.setGuardState(0); + serverDeploy.setCollectState(0); + serverDeploy.setDeployIssueTime(new Date()); + serverDeployService.save(serverDeploy); + // 璁㈤槄Mqtt涓婚 + String[] topic = new String[2]; + topic[0] = "IOT\\" + serverDeploy.getServerCode() + "\\Mutually2"; + topic[1] = "IOT\\" + serverDeploy.getServerCode() + "\\WriteMessage"; + mqttCustomerClient.subscribe(topic); + // 鍒涘缓ftp鏂囦欢澶圭洰褰� + FtpUtil.createFolder("/log", serverDeploy.getServerCode()); + FtpUtil.createFolder("/deploy", serverDeploy.getServerCode()); + FtpUtil.createFolder("/deploy/" + serverDeploy.getServerCode(), "software"); + FtpUtil.createFolder("/deploy/" + serverDeploy.getServerCode(), "deploy"); + // 鐢熸垚鏈湴鏂囦欢澶� + boolean b = FileUtil.queryCatalogue(ftpAddress + serverDeploy.getServerCode()); + if (b) { + FileUtil.createDir(ftpAddress + serverDeploy.getServerCode() + "/deploy"); + FileUtil.createDir(ftpAddress + serverDeploy.getServerCode() + "/software"); + } + FileUtil.createDir(ftpAddress + serverDeploy.getServerCode() + "/script"); + return Result.ok("娣诲姞鎴愬姛锛�"); + } + + /** + * 娣诲姞Mqtt + * + * @param mqttDeploy + * @return + */ + @ApiOperation(value = "mqtt-娣诲姞", notes = "mqtt-娣诲姞") + @PostMapping(value = "/add/mqtt") + public Result<?> addMqtt(@RequestBody MqttDeploy mqttDeploy) { + mqttDeployService.save(mqttDeploy); + return Result.ok("娣诲姞鎴愬姛锛�"); + } + + /** + * 缂栬緫 + * + * @param mqttDeploy + * @return + */ + @ApiOperation(value = "mqtt-缂栬緫", notes = "mqtt-缂栬緫") + @PutMapping(value = "/edit/mqtt") + public Result<?> editMqtt(@RequestBody MqttDeploy mqttDeploy) { + mqttDeployService.updateById(mqttDeploy); + return Result.ok("缂栬緫鎴愬姛!"); + } + + /** + * 缂栬緫 + * + * @param influxdbDeploy + * @return + */ + @ApiOperation(value = "influxdb-缂栬緫", notes = "influxdb-缂栬緫") + @PutMapping(value = "/edit/influxdb") + public Result<?> editInfluxdb(@RequestBody InfluxdbDeploy influxdbDeploy) { + influxdbDeployService.updateById(influxdbDeploy); + return Result.ok("缂栬緫鎴愬姛!"); + } + + /** + * 娣诲姞influxdb + * + * @param influxdbDeploy + * @return + */ + @ApiOperation(value = "influxdb-娣诲姞", notes = "influxdb-娣诲姞") + @PostMapping(value = "/add/influxdb") + public Result<?> addMqtt(@RequestBody InfluxdbDeploy influxdbDeploy) { + influxdbDeployService.save(influxdbDeploy); + return Result.ok("娣诲姞鎴愬姛锛�"); + } + + /** + * 閲囬泦杞欢鍚仠 + * + * @param serverDeploy + * @return + */ + @ApiOperation(value = "鏈嶅姟鍣ㄩ厤缃�-閲囬泦杞欢鍚仠", notes = "鏈嶅姟鍣ㄩ厤缃�-閲囬泦杞欢鍚仠") + @PutMapping(value = "/collect/put") + public Result<?> collectPut(@RequestBody ServerDeploy serverDeploy) { + Integer collectState = serverDeploy.getCollectState(); + MqttParameter mqttParameter = new MqttParameter(); + mqttParameter.setId(serverDeploy.getServerCode()); + // 鍚姩閲囬泦杞欢 + mqttParameter.setType("start"); + if (collectState == 0) { + mqttParameter.setParameter1("1"); + } else { + mqttParameter.setParameter1("0"); + } + mqttCustomerClient.pushlish(2, false, serverDeploy.getServerCode(), mqttParameter); + return Result.ok(); + } + + /** + * 鑾峰彇鏃ュ織 + * + * @param serverCode + * @return + */ + @ApiOperation(value = "鏈嶅姟鍣ㄩ厤缃�-鑾峰彇鏃ュ織", notes = "鏈嶅姟鍣ㄩ厤缃�-鑾峰彇鏃ュ織") + @GetMapping(value = "/obtain/log") + public Result<?> obtainLog(@RequestParam(name = "serverCode") String serverCode, + @RequestParam(name = "dayStart") String dayStart, + @RequestParam(name = "dayEnd") String dayEnd) { + MqttParameter mqttParameter = new MqttParameter(); + mqttParameter.setId(serverCode); + // 鍚姩閲囬泦杞欢 + mqttParameter.setType("log"); + mqttParameter.setParameter1(dayStart); + mqttParameter.setParameter2(dayEnd); + mqttParameter.setParameter3("log/" + serverCode + "/"); + mqttCustomerClient.pushlish(2, false, serverCode, mqttParameter); + return Result.ok("涓婁紶鎴愬姛锛�"); + } + + /** + * 缂栬緫 + * + * @param serverDeploy + * @return + */ + @ApiOperation(value = "鏈嶅姟鍣ㄩ厤缃�-缂栬緫", notes = "鏈嶅姟鍣ㄩ厤缃�-缂栬緫") + @PutMapping(value = "/edit") + public Result<?> edit(@RequestBody ServerDeploy serverDeploy) { + serverDeployService.updateById(serverDeploy); + return Result.ok("缂栬緫鎴愬姛!"); + } + + /** + * 鏇存柊閲囬泦杞欢 + * + * @param serverDeploy + * @return + */ + @ApiOperation(value = "鏈嶅姟鍣ㄩ厤缃�-鏇存柊閲囬泦杞欢", notes = "鏈嶅姟鍣ㄩ厤缃�-鏇存柊閲囬泦杞欢") + @PutMapping(value = "/edit/collect") + public Result<?> editCollectVersion(@RequestBody ServerDeploy serverDeploy) { + serverDeployService.updateById(serverDeploy); + String path = ftpAddress + serverDeploy.getNewCollectAddress(); + if (!path.endsWith(".zip")) { + return Result.error("璇蜂笂浼�.zip鏂囦欢!"); + } + // 鏂板缓ftp鏂囦欢澶� + FtpUtil.createFolder("/deploy/" + serverDeploy.getServerCode() + "/software/", serverDeploy.getLatestCollectVersion()); + // 澶嶅埗閲囬泦杞欢鍒癴tp + // 涓婁紶鍒癴tp + String newCollectAddress = serverDeploy.getNewCollectAddress(); + String basePath = "/deploy/"; // FTP鏈嶅姟鍣ㄥ熀纭�鐩綍 + String filePath = serverDeploy.getServerCode() + "/software/" + serverDeploy.getLatestCollectVersion(); // FTP鏈嶅姟鍣ㄦ枃浠跺瓨鏀捐矾寰勩�備緥濡傚垎鏃ユ湡瀛樻斁锛�/2015/01/01銆傛枃浠剁殑璺緞涓篵asePath+filePath + String filename = newCollectAddress.substring(14, newCollectAddress.length());// 涓婁紶鍒癋TP鏈嶅姟鍣ㄤ笂鐨勬枃浠跺悕 + try { + FileInputStream fileInputStream = new FileInputStream(ftpAddress + newCollectAddress); + FtpUtil.uploadFile(basePath, filePath, filename, fileInputStream); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + // 鍙戦�佹秷鎭� + // 鍚姩閲囬泦杞欢 + MqttParameter mqttParameter = new MqttParameter(); + mqttParameter.setId(serverDeploy.getServerCode()); + mqttParameter.setType("version"); + mqttParameter.setParameter1(serverDeploy.getLatestCollectVersion()); + // 閲囬泦杞欢 + String newCollectVersion = "/deploy/" + serverDeploy.getServerCode() + "/software/" + serverDeploy.getLatestCollectVersion(); + mqttParameter.setParameter3(newCollectVersion); + mqttCustomerClient.pushlish(2, false, serverDeploy.getServerCode(), mqttParameter); + return Result.ok("鏇存柊鎴愬姛!"); + } + + + /** + * 閫氳繃id鍒犻櫎 + * + * @param id + * @return + */ + @AutoLog(value = "鏈嶅姟鍣ㄩ厤缃�-閫氳繃id鍒犻櫎") + @ApiOperation(value = "鏈嶅姟鍣ㄩ厤缃�-閫氳繃id鍒犻櫎", notes = "鏈嶅姟鍣ㄩ厤缃�-閫氳繃id鍒犻櫎") + @DeleteMapping(value = "/delete") + public Result<?> delete(@RequestParam(name = "id", required = true) String id) { + List<Equipment> equipmentList = equipmentService.findEquipmentByServerId(id); + if (equipmentList.size() > 0) { + return Result.error("鍒犻櫎澶辫触锛岃鍏堝垹闄よ澶�!"); + } + serverDeployService.removeById(id); + return Result.ok("鍒犻櫎鎴愬姛!"); + } + + + /** + * 閫氳繃id鏌ヨ + * + * @param id + * @return + */ + @ApiOperation(value = "鏈嶅姟鍣ㄩ厤缃�-閫氳繃id鏌ヨ", notes = "鏈嶅姟鍣ㄩ厤缃�-閫氳繃id鏌ヨ") + @GetMapping(value = "/queryById") + public Result<?> queryById(@RequestParam(name = "id", required = true) String id) { + ServerDeploy serverDeploy = serverDeployService.getById(id); + return Result.ok(serverDeploy); + } + + /** + * 閫氳繃id鏌ヨ + * + * @param id + * @return + */ + @ApiOperation(value = "mqtt閰嶇疆-閫氳繃鏈嶅姟鍣╥d鏌ヨ", notes = "mqtt閰嶇疆-閫氳繃鏈嶅姟鍣╥d鏌ヨ") + @GetMapping(value = "/mqtt/queryById") + public Result<?> mqttQueryById(@RequestParam(name = "id", required = true) String id) { + return Result.ok(mqttDeployService.findByServerIdMqttDeploy(id)); + } + + /** + * 閫氳繃serverCode鏌ヨ + * + * @param serverCode + * @return + */ + @ApiOperation(value = "鏈嶅姟鍣ㄩ厤缃�-閫氳繃serverCode鏌ヨ", notes = "鏈嶅姟鍣ㄩ厤缃�-閫氳繃serverCode鏌ヨ") + @GetMapping(value = "/queryByServerCode") + public Result<?> queryByServerCode(@RequestParam(name = "serverCode", required = true) String serverCode) { + ServerDeploy serverDeploy = serverDeployService.findByServerCode(serverCode); + return Result.ok(serverDeploy); + } + + /** + * 閫氳繃id鐢熸垚閰嶇疆鏂囦欢 + * + * @param id + * @return + */ + @ApiOperation(value = "鏈嶅姟鍣ㄩ厤缃�-閫氳繃id鐢熸垚閰嶇疆鏂囦欢", notes = "鏈嶅姟鍣ㄩ厤缃�-閫氳繃id鐢熸垚閰嶇疆鏂囦欢") + @GetMapping(value = "/deploy/document") + public Result<?> addDeploy(@RequestParam(name = "id", required = true) String id) { + return serverDeployService.addDeployDocument(id); + } + + /** + * 缁堢缂栧彿鑾峰彇 + * + * @return + */ + private String randomDigit() { + Random random = new Random(); + String randomNumber = random.nextInt(9000) + 1000 + ""; + ServerDeploy byServerCode = serverDeployService.findByServerCode(randomNumber); + if (byServerCode != null) { + randomDigit(); + } + return randomNumber; + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/DbConfig.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/DbConfig.java new file mode 100644 index 0000000..df87e5e --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/DbConfig.java @@ -0,0 +1,19 @@ +package org.jeecg.modules.iot.depository; + +/** + * @author cuikaidong + * @date 2025/5/6 + */ +public class DbConfig { + // mysql杩炴帴鍦板潃 +// public static final String DATABASE = "sqlserver"; +// public static final String URL = "jdbc:mysql://127.0.0.1:3306/lx_iot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai"; +// public static final String USER = "root"; +// public static final String PASSWORD = "root"; + + // sqlserver杩炴帴鍦板潃 + public static final String DATABASE = "sqlserver"; + public static final String URL = "jdbc:sqlserver://localhost:1433;selectMethod=cursor;databaseName=lx_iot;user=sa;password=MyPassword!"; + public static final String USER = "sa"; + public static final String PASSWORD = "123456"; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/Influxdb.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/Influxdb.java new file mode 100644 index 0000000..ab13819 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/Influxdb.java @@ -0,0 +1,36 @@ +package org.jeecg.modules.iot.depository; + +import lombok.Data; + +import java.util.List; +import java.util.Map; + +@Data +public class Influxdb { + + /** + * 閲囬泦鏃堕棿 + */ + private String time; + /** + * 鍊� + */ + private String value; + /** + * 瀛楁鍚� + */ + private String parameter; + /** + * 琛ㄥ悕 + */ + private String measurement; + /** + * 灞炴�� + */ + private String field; + + /** + * 閲囬泦鏃堕棿 + */ + private String acquisitionTime; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/InfluxdbTest.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/InfluxdbTest.java new file mode 100644 index 0000000..de38061 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/InfluxdbTest.java @@ -0,0 +1,82 @@ +package org.jeecg.modules.iot.depository; + + +import com.influxdb.query.FluxRecord; +import com.influxdb.query.FluxTable; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class InfluxdbTest { + /** + * @param connection + * @throws SQLException + */ + public static void createTable(Connection connection) throws SQLException { + String createTableQuery = "CREATE TABLE IF NOT EXISTS influxdb_data (" + + "id INT AUTO_INCREMENT PRIMARY KEY, " + + "time VARCHAR(255), " + + "measurement VARCHAR(255), " + + "field_key VARCHAR(255), " + + "field_value VARCHAR(255))"; + try (PreparedStatement statement = connection.prepareStatement(createTableQuery)) { + statement.execute(); + } + } + + public static List<Influxdb> processAndInsert(List<FluxTable> tables, Connection mysqlConnection) throws SQLException { +// String insertQuery = "INSERT INTO influxdb_data (time, measurement, field_key, field_value, field) " + +// "VALUES (?, ?, ?, ?, ?)"; + List<Influxdb> influxdbList = new ArrayList<>(); +// try (PreparedStatement insertStatement = mysqlConnection.prepareStatement(insertQuery)) { + + for (FluxTable table : tables) { + List<FluxRecord> records = table.getRecords(); + for (FluxRecord record : records) { + Influxdb influxdb = new Influxdb(); + for (Map.Entry<String, Object> entry : record.getValues().entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); +// System.out.println("Key: " + key + ", Value: " + value); + // 鎷嗗垎琛ㄦ暟鎹� + if (key.equals("_time")) { + // 瑙f瀽 ISO 8601 瀛楃涓� + OffsetDateTime odt = OffsetDateTime.parse(value.toString()); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); + String customFormat = odt.format(formatter); + influxdb.setTime(customFormat); +// insertStatement.setString(1, customFormat); + } else if (key.equals("_value")) { + if (value != null) { + influxdb.setValue(value.toString()); +// insertStatement.setString(4, value.toString()); + } else { +// insertStatement.setString(4, ""); + influxdb.setValue(""); + } + } else if (key.equals("Parameter")) { + influxdb.setParameter(value.toString()); +// insertStatement.setString(3, value.toString()); + + } else if (key.equals("_measurement")) { + influxdb.setMeasurement(value.toString()); +// insertStatement.setString(2, value.toString()); + } else if (key.equals("_field")) { + influxdb.setField(value.toString()); +// insertStatement.setString(5, value.toString()); + } + } + influxdbList.add(influxdb); +// insertStatement.executeUpdate(); + } + } +// } + return influxdbList; + } +} \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/MysqlDataWriter.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/MysqlDataWriter.java new file mode 100644 index 0000000..d330e4b --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/depository/MysqlDataWriter.java @@ -0,0 +1,237 @@ +package org.jeecg.modules.iot.depository; + +import com.baomidou.dynamic.datasource.annotation.DS; +import org.springframework.stereotype.Service; + +import java.sql.*; +import java.util.List; + +/** + * @author cuikaidong + * @date 2025/5/6 + */ +@Service +public class MysqlDataWriter { + // 鍒涘缓MysqlTable琛� + public static void createMysqlTable(String tableName, String... columns) { + if (DbConfig.DATABASE.equals("sqlserver")) { + // 璋冪敤mysql鍒涘缓琛ㄦ柟娉� + createSqlserverTable(tableName, columns); + } else if (DbConfig.DATABASE.equals("mysql")) { + String sql = String.format("CREATE TABLE IF NOT EXISTS %s (%s)", tableName, String.join(", ", columns)); + + try (Connection conn = DriverManager.getConnection(DbConfig.URL, DbConfig.USER, DbConfig.PASSWORD); + Statement stmt = conn.createStatement()) { + stmt.executeUpdate(sql); + System.out.println("琛ㄥ垱寤烘垚鍔�: " + tableName); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + } + + // 鍐欏叆鏁版嵁 + public static void insertMysqlData(String tableName, String[] columns, Object[] values) { + if (columns.length != values.length) { + throw new IllegalArgumentException("瀛楁涓庡�肩殑鏁伴噺涓嶅尮閰�"); + } + String placeholders = String.join(", ", java.util.Collections.nCopies(columns.length, "?")); + String columnNames = String.join(", ", columns); + String sql = String.format("INSERT INTO %s (%s) VALUES (%s)", tableName, columnNames, placeholders); + + try (Connection conn = DriverManager.getConnection(DbConfig.URL, DbConfig.USER, DbConfig.PASSWORD); + PreparedStatement pstmt = conn.prepareStatement(sql)) { + + for (int i = 0; i < values.length; i++) { + pstmt.setObject(i + 1, values[i]); + } + pstmt.executeUpdate(); +// System.out.println("鏁版嵁鍐欏叆鎴愬姛"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + // 澧炲姞瀛楁 鍦� 绫讳腑娣诲姞浠ヤ笅鏂规硶 + public static void addMysqlColumn(String tableName, String columnDefinition, String columnName) { + if (isColumnExists(tableName, columnName)) { + System.out.println("瀛楁宸插瓨鍦紝鏃犻渶娣诲姞: " + columnName); + return; + } + String sql = String.format("ALTER TABLE %s ADD COLUMN %s", tableName, columnDefinition); + try (Connection conn = DriverManager.getConnection(DbConfig.URL, DbConfig.USER, DbConfig.PASSWORD); + Statement stmt = conn.createStatement()) { + stmt.executeUpdate(sql); + System.out.println("瀛楁娣诲姞鎴愬姛: " + columnDefinition); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + // 杈呭姪鏂规硶锛氭鏌ヨ〃涓槸鍚﹀凡瀛樺湪鎸囧畾瀛楁 + private static boolean isColumnExists(String tableName, String columnName) { + String sql = String.format( + "SELECT COUNT(*) FROM information_schema.columns " + + "WHERE table_name = '%s' AND column_name = '%s'", + tableName, columnName + ); + + try (Connection conn = DriverManager.getConnection(DbConfig.URL, DbConfig.USER, DbConfig.PASSWORD); + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(sql)) { + if (rs.next()) { + return rs.getInt(1) > 0; + } + } catch (SQLException e) { + e.printStackTrace(); + } + return false; + } + + // 鎵归噺瀵煎叆瀛楁 + public static void addMysqlColumns(String tableName, List<String> columnDefinitions, List<String> columnNames) { + if (columnDefinitions.size() != columnNames.size()) { + throw new IllegalArgumentException("瀛楁瀹氫箟鍜屽瓧娈靛悕鐨勬暟閲忓繀椤讳竴鑷�"); + } + + StringBuilder sqlBuilder = new StringBuilder("ALTER TABLE ").append(tableName).append(" ADD COLUMN ( "); + for (int i = 0; i < columnDefinitions.size(); i++) { + String columnName = columnNames.get(i); + if (batchIsColumnExists(tableName, columnName)) { + System.out.println("瀛楁宸插瓨鍦紝鏃犻渶娣诲姞: " + columnName); + continue; + } + String columnDefinition = columnDefinitions.get(i); + if (i > 0) { + sqlBuilder.append(", "); + } + sqlBuilder.append(columnDefinition); + } + sqlBuilder.append(" ) "); + String sql = sqlBuilder.toString(); + if (sql.endsWith(" ADD COLUMN ( )")) { + System.out.println("娌℃湁闇�瑕佹坊鍔犵殑鏂板瓧娈�"); + return; + } + try (Connection conn = DriverManager.getConnection(DbConfig.URL, DbConfig.USER, DbConfig.PASSWORD); + Statement stmt = conn.createStatement()) { + stmt.executeUpdate(sql); + System.out.println("瀛楁鎵归噺娣诲姞鎴愬姛"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + // 楠岃瘉瀛楁鏄惁閲嶅 + private static boolean batchIsColumnExists(String tableName, String columnName) { + String sql = String.format( + "SELECT COUNT(*) FROM information_schema.columns " + + "WHERE TABLE_SCHEMA = 'lx_iot' AND table_name = '%s' AND column_name = '%s'", + tableName, columnName + ); + + try (Connection conn = DriverManager.getConnection(DbConfig.URL, DbConfig.USER, DbConfig.PASSWORD); + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(sql)) { + if (rs.next()) { + return rs.getInt(1) > 0; + } + } catch (SQLException e) { + e.printStackTrace(); + } + return false; + } + + + /************************************************************ sqlserver鐗堟湰 ***************************************/ + // 鍒涘缓sqlserver琛� + public static void createSqlserverTable(String tableName, String... columns) { + String schemaName = "dbo"; + // 鍒涘缓琛ㄧ殑 SQL锛堝鏋滀笉瀛樺湪锛� + String tableSql = String.format( + "IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = '%s' AND schema_id = SCHEMA_ID('%s')) " + + "CREATE TABLE [%s].[%s] (%s)", + tableName, schemaName, schemaName, tableName, String.join(", ", columns) + ); +// String sql = String.format("CREATE TABLE IF NOT EXISTS %s (%s)", tableName, String.join(", ", columns)); + try (Connection conn = DriverManager.getConnection(DbConfig.URL, DbConfig.USER, DbConfig.PASSWORD); + Statement stmt = conn.createStatement()) { + stmt.executeUpdate(tableSql); + System.out.println("琛ㄥ垱寤烘垚鍔�: " + tableName); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + // 鎵归噺瀵煎叆瀛楁锛圫QL Server 鐗堟湰锛� + public static void addSqlserverColumns(String schemaName, String tableName, List<String> columnDefinitions, List<String> columnNames) { + if (columnDefinitions.size() != columnNames.size()) { + throw new IllegalArgumentException("瀛楁瀹氫箟鍜屽瓧娈靛悕鐨勬暟閲忓繀椤讳竴鑷�"); + } + + // 杞箟琛ㄥ悕涓殑鏂规嫭鍙凤紝闃叉SQL娉ㄥ叆 + tableName = tableName.replace("[", "[[").replace("]", "]]"); + + StringBuilder sqlBuilder = new StringBuilder(); + sqlBuilder.append("ALTER TABLE [").append(schemaName).append("].[") + .append(tableName).append("] ADD "); + + boolean hasNewColumns = false; + for (int i = 0; i < columnDefinitions.size(); i++) { + String columnName = columnNames.get(i); + if (sqlServeBatchIsColumnExists(schemaName, tableName, columnName)) { + System.out.println("瀛楁宸插瓨鍦紝鏃犻渶娣诲姞: " + columnName); + continue; + } + + String columnDefinition = columnDefinitions.get(i); + if (hasNewColumns) { + sqlBuilder.append(", "); + } + sqlBuilder.append("[").append(columnName.replace("[", "[[").replace("]", "]]")).append("] ") + .append(columnDefinition); + hasNewColumns = true; + } + + String sql = sqlBuilder.toString(); + if (!hasNewColumns) { + System.out.println("娌℃湁闇�瑕佹坊鍔犵殑鏂板瓧娈�"); + return; + } + + try (Connection conn = DriverManager.getConnection(DbConfig.URL, DbConfig.USER, DbConfig.PASSWORD); + Statement stmt = conn.createStatement()) { + System.out.println("鎵цSQL: " + sql); // 璋冭瘯鐢� + stmt.executeUpdate(sql); + System.out.println("瀛楁鎵归噺娣诲姞鎴愬姛"); + } catch (SQLException e) { + System.err.println("鎵归噺娣诲姞瀛楁澶辫触: " + sql); + e.printStackTrace(); + } + } + + /** + * 楠岃瘉瀛楁鏄惁瀛樺湪锛圫QL Server 鐗堟湰锛� + */ + private static boolean sqlServeBatchIsColumnExists(String schemaName, String tableName, String columnName) { + String sql = "SELECT COUNT(*) FROM sys.columns " + + "WHERE object_id = OBJECT_ID('[" + schemaName + "].[" + tableName + "]') " + + "AND name = @columnName"; + + try (Connection conn = DriverManager.getConnection(DbConfig.URL, DbConfig.USER, DbConfig.PASSWORD); + PreparedStatement pstmt = conn.prepareStatement(sql)) { + pstmt.setString(1, columnName); + + try (ResultSet rs = pstmt.executeQuery()) { + if (rs.next()) { + return rs.getInt(1) > 0; + } + } + } catch (SQLException e) { + System.err.println("妫�鏌ュ瓧娈靛瓨鍦ㄦ�уけ璐�: " + sql); + e.printStackTrace(); + } + return false; + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ControlSystem.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ControlSystem.java new file mode 100644 index 0000000..802d237 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ControlSystem.java @@ -0,0 +1,56 @@ +package org.jeecg.modules.iot.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * @Description: 鎺у埗绯荤粺淇℃伅 + * @Author: cuikaidong + * @Date: 2025-1-2 + * @Version: V1.0 + */ +@Data +@TableName("iot_control_system") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "ControlSystem瀵硅薄", description = "鎺у埗绯荤粺淇℃伅") +public class ControlSystem implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @TableId(type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "ID") + private String id; + /** + * 绯荤粺缂栫爜 + */ + @ApiModelProperty(value = "绯荤粺缂栫爜") + private String code; + /** + * 鍙傛暟绫诲瀷 + */ + @ApiModelProperty(value = "椹卞姩绫诲瀷") + private String driveType; + + /** + * 鏁版嵁鏍囧織 + */ + @ApiModelProperty(value = "鏁版嵁鏍囧織") + private Integer dataFlag; + + /** + * 澶囨敞 + */ + @ApiModelProperty(value = "澶囨敞") + private String remark; +} \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/EmptyParameter.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/EmptyParameter.java new file mode 100644 index 0000000..9207b94 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/EmptyParameter.java @@ -0,0 +1,120 @@ +package org.jeecg.modules.iot.entity; + +import java.io.Serializable; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.system.base.entity.JeecgEntity; + +/** + * @Description: 铏氳澶囧弬鏁� + * @Author: cuikaidong + * @Date: 2025-1-2 + * @Version: V1.0 + */ +@Data +@TableName("iot_empty_parameter") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "EmptyParameter瀵硅薄", description = "铏氳澶囧弬鏁�") +public class EmptyParameter extends JeecgEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 璁惧id + */ + @ApiModelProperty(value = "璁惧id") + private String equipmentId; + + /** + * 瀹炶澶囧弬鏁癷d + */ + @ApiModelProperty(value = "瀹炶澶囧弬鏁癷d") + private String parameterId; + + /** + * 鍙傛暟鍚嶇О + */ + @ApiModelProperty(value = "鍙傛暟鍚嶇О") + private String parameterName; + + /** + * 鍙傛暟缂栧彿 + */ + @ApiModelProperty(value = "鍙傛暟缂栧彿") + private Integer parameterCode; + + /** + * 鍙傛暟鎻忚堪 + */ + @ApiModelProperty(value = "鍙傛暟鎻忚堪") + private String parameterDescribe; + + /** + * 鍙傛暟绫诲瀷 + */ + @ApiModelProperty(value = "鍙傛暟绫诲瀷") + private String parameterType; + + /** + * 绯荤粺鏁版嵁绫诲瀷 + */ + @ApiModelProperty(value = "绯荤粺鏁版嵁绫诲瀷") + private String systemDataType; + + /** + * 鍙傛暟鍦板潃 + */ + @ApiModelProperty(value = "鍙傛暟鍦板潃") + private String address; + + /** + * 璇诲啓绫诲瀷 + */ + @ApiModelProperty(value = "璇诲啓绫诲瀷") + private String readWriteType; + + /** + * 绫诲瀷 + */ + @ApiModelProperty(value = "绫诲瀷") + private String type; + + /** + * 瀛楃涓查暱搴� + */ + @ApiModelProperty(value = "瀛楃涓查暱搴�") + private String dataLength; + + /** + * 鑴氭湰鍐呭 + */ + @ApiModelProperty(value = "鑴氭湰鍐呭") + private String scriptContent; + + /** + * 鑴氭湰鏍囪鍒楄〃 + */ + @ApiModelProperty(value = "鑴氭湰鏍囪鍒楄〃") + private String scriptTagList; + + @TableField(exist = false) + private String eqptCode; + @TableField(exist = false) + private String eqptName; + /** + * 鏈嶅姟鍣╥d + */ + @TableField(exist = false) + private String serveId; + /** + * 鑴氭湰 + */ + @TableField(exist = false) + private String script; +} \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/Equipment.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/Equipment.java new file mode 100644 index 0000000..5a04931 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/Equipment.java @@ -0,0 +1,152 @@ +package org.jeecg.modules.iot.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.system.base.entity.JeecgEntity; + +import java.io.Serializable; + +/** + * @Description: 璁惧 + * @Author: cuikaidong + * @Date: 2024-12-23 + * @Version: V1.0 + */ +@Data +@TableName("iot_equipment") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "equipment瀵硅薄", description = "璁惧") +public class Equipment extends JeecgEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 鏈嶅姟鍣╥d + */ + @ApiModelProperty(value = "鏈嶅姟鍣╥d") + private String serverId; + + /** + * 璁惧缂栧彿 + */ + @ApiModelProperty(value = "璁惧缂栧彿") + private String eqptCode; + + /** + * 璁惧鍚嶇О + */ + @ApiModelProperty(value = "璁惧鍚嶇О") + private String eqptName; + + /** + * 璁惧鍒嗙被 + */ + @ApiModelProperty(value = "璁惧鍒嗙被") + private Integer equipmentType; + + /** + * 璁惧鍨嬪彿 + */ + @ApiModelProperty(value = "璁惧鍨嬪彿") + private String eqptModel; + + /** + * 璁惧鎻忚堪 + */ + @ApiModelProperty(value = "璁惧鎻忚堪") + private String eqptDescribe; + + /** + * 璁惧绫诲瀷 + */ + @ApiModelProperty(value = "璁惧绫诲瀷") + private String eqptType; + + /** + * 绯荤粺鍚嶇О + */ + @ApiModelProperty(value = "绯荤粺鍚嶇О") + private String controlSystem; + + /** + * 椹卞姩鍗忚 + */ + @ApiModelProperty(value = "椹卞姩鍗忚") + private String protocol; + + /** + * 椹卞姩绫诲瀷 + */ + @ApiModelProperty(value = "椹卞姩绫诲瀷") + private String driveType; + + /** + * 椹卞姩搴撳悕绉� + */ + @ApiModelProperty(value = "椹卞姩搴撳悕绉�") + private String libraryName; + + /** + * 绫诲悕绉� + */ + @ApiModelProperty(value = "绫诲悕绉�") + private String className; + + /** + * 椹卞姩搴撶増鏈� + */ + @ApiModelProperty(value = "椹卞姩搴撶増鏈�") + private String libraryVersion; + + /** + * 杩炴帴鍦板潃 + */ + @ApiModelProperty(value = "杩炴帴鍦板潃") + private String address; + + /** + * 閲囬泦鍛ㄦ湡 + */ + @ApiModelProperty(value = "閲囬泦鍛ㄦ湡") + private String collectionCycle; + + /** + * 閲嶈繛鍛ㄦ湡 + */ + @ApiModelProperty(value = "閲嶈繛鍛ㄦ湡") + private String reconnectCycle; + + /** + * 鏄惁閲囬泦 + */ + @ApiModelProperty(value = "鏄惁閲囬泦") + private String isCollection; + + /** + * 娴偣鏁板瓧鑺傞『搴� + */ + @ApiModelProperty(value = "娴偣鏁板瓧鑺傞『搴�") + private String floatPosition; + + /** + * 鍙戝竷涓婚鍚嶇О + */ + @ApiModelProperty(value = "鍙戝竷涓婚鍚嶇О") + private String readTopic; + + /** + * 璁㈤槄涓婚鍚嶇О + */ + @ApiModelProperty(value = "璁㈤槄涓婚鍚嶇О") + private String writeTopic; + + /** + * 澶囨敞 + */ + @ApiModelProperty(value = "澶囨敞") + private String remark; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/InfluxdbDeploy.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/InfluxdbDeploy.java new file mode 100644 index 0000000..fe364d8 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/InfluxdbDeploy.java @@ -0,0 +1,68 @@ +package org.jeecg.modules.iot.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.system.base.entity.JeecgEntity; + +import java.io.Serializable; + +/** + * @Description: influxdb閰嶇疆 + * @Author: cuikaidong + * @Date: 2024-12-10 + * @Version: V1.0 + */ +@Data +@TableName("iot_influxdb_deploy") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "influxdb_deploy瀵硅薄", description = "influxdb閰嶇疆") +public class InfluxdbDeploy extends JeecgEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 椤圭洰鍒嗙被id + */ + @ApiModelProperty(value = "椤圭洰鍒嗙被id") + private String projectClassifyId; + /** + * 鏈嶅姟鍣╥d + */ + @ApiModelProperty(value = "鏈嶅姟鍣╥d") + private String serverDeployId; + /** + * 鎺堟潈鐮� + */ + @ApiModelProperty(value = "鎺堟潈鐮�") + private String authorizeCode; + /** + * 妗� + */ + @ApiModelProperty(value = "妗�") + private String bucket; + /** + * 缁勭粐 + */ + @ApiModelProperty(value = "缁勭粐") + private String organization; + /** + * 绔彛 + */ + @ApiModelProperty(value = "绔彛") + private Integer port; + /** + * 鍦板潃 + */ + @ApiModelProperty(value = "鍦板潃") + private String address; + /** + * 瀵嗙爜 + */ + @ApiModelProperty(value = "瀵嗙爜") + private String password; + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/IotTree.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/IotTree.java new file mode 100644 index 0000000..427f1f6 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/IotTree.java @@ -0,0 +1,27 @@ +package org.jeecg.modules.iot.entity; + +import lombok.Data; + +import java.util.List; +import java.util.Map; + +@Data +public class IotTree { + + /** + * 鍚嶇О + */ + private String title; + /** + * 缂栧彿 + */ + private String key; + /** + * 鍥炬爣 + */ + private Map<String, String> slots; + /** + * 涓嬩竴灞� + */ + private List<IotTree> children; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttClient.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttClient.java new file mode 100644 index 0000000..5a632e1 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttClient.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.iot.entity; + +import lombok.Data; + +/** + * mqtt瀹㈡埛绔� + */ +@Data +public class MqttClient { + + /** + * 瀹㈡埛绔痠d + */ + private String clientid; + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttDeploy.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttDeploy.java new file mode 100644 index 0000000..b7b635f --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttDeploy.java @@ -0,0 +1,72 @@ +package org.jeecg.modules.iot.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.system.base.entity.JeecgEntity; + +import java.io.Serializable; + +/** + * @Description: mqtt閰嶇疆 + * @Author: cuikaidong + * @Date: 2024-12-10 + * @Version: V1.0 + */ +@Data +@TableName("iot_mqtt_deploy") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "mqtt_deploy瀵硅薄", description = "mqtt閰嶇疆") +public class MqttDeploy extends JeecgEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 椤圭洰鍒嗙被id + */ + @ApiModelProperty(value = "椤圭洰鍒嗙被id") + private String projectClassifyId; + /** + * 鏈嶅姟鍣╥d + */ + @ApiModelProperty(value = "鏈嶅姟鍣╥d") + private String serverDeployId; + + /** + * 鏈嶅姟鍣ㄥ悕绉� + */ + @ApiModelProperty(value = "鏈嶅姟鍣ㄥ悕绉�") + private String serverName; + /** + * 鍦板潃 + */ + @ApiModelProperty(value = "鍦板潃") + private String address; + /** + * 鐢ㄦ埛鍚� + */ + @ApiModelProperty(value = "鐢ㄦ埛鍚�") + private String userName; + /** + * 瀵嗙爜 + */ + @ApiModelProperty(value = "瀵嗙爜") + private String userPassword; + /** + * 瀹㈡埛绔痠d + */ + @ApiModelProperty(value = "瀹㈡埛绔痠d") + private String clintId; + /** + * 绔彛 + */ + @ApiModelProperty(value = "绔彛") + private Integer port; + + + + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttParameter.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttParameter.java new file mode 100644 index 0000000..3f75f38 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/MqttParameter.java @@ -0,0 +1,40 @@ +package org.jeecg.modules.iot.entity; + +import lombok.Data; + +@Data +public class MqttParameter { + + /** + * 鏈嶅姟鍣ㄧ紪鍙� + */ + private String id; + /** + * 鍔熻兘绫诲瀷(palpitate蹇冭烦锛寁ersion鐗堟湰锛宭og鏃ュ織锛宻tart 鍚仠锛宑ollect閲囬泦鐘舵��) + */ + private String type; + /** + * 鍙戝竷鏃堕棿 + */ + private String time; + /** + * 鍙傛暟1 + */ + private String parameter1; + /** + * 鍙傛暟2 + */ + private String parameter2; + /** + * 鍙傛暟3 + */ + private String parameter3; + /** + * 鍙傛暟4 + */ + private String parameter4; + /** + * 鍙傛暟5 + */ + private String parameter5; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ParameterGroup.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ParameterGroup.java new file mode 100644 index 0000000..c42dae5 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ParameterGroup.java @@ -0,0 +1,63 @@ +package org.jeecg.modules.iot.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.system.base.entity.JeecgEntity; + +import java.io.Serializable; + + +/** + * @Description: 鍙傛暟缁� + * @Author: cuikaidong + * @Date: 2024-12-31 + * @Version: V1.0 + */ +@Data +@TableName("iot_parameter_group") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "ParameterGroup瀵硅薄", description = "鍙傛暟缁�") +public class ParameterGroup extends JeecgEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 鏈嶅姟鍣╥d + */ + @ApiModelProperty(value = "鏈嶅姟鍣╥d") + private String serverDeployId; + + /** + * 璁惧id + */ + @ApiModelProperty(value = "璁惧id") + private String equipmentId; + + /** + * 鍙傛暟缁勫悕绉� + */ + @ApiModelProperty(value = "鍙傛暟缁勫悕绉�") + private String name; + + /** + * 鍙傛暟缁勭紪鍙� + */ + @ApiModelProperty(value = "鍙傛暟缁勭紪鍙�") + private String code; + + /** + * 閲囬泦鍛ㄦ湡 + */ + @ApiModelProperty(value = "閲囬泦鍛ㄦ湡") + private String collectionCycle; + + /** + * 澶囨敞 + */ + @ApiModelProperty(value = "澶囨敞") + private String remark; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ProjectClassify.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ProjectClassify.java new file mode 100644 index 0000000..b8deac3 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ProjectClassify.java @@ -0,0 +1,45 @@ +package org.jeecg.modules.iot.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.system.base.entity.JeecgEntity; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; + +/** + * @Description: 椤圭洰鍒嗙被 + * @Author: cuikaidong + * @Date: 2024-12-20 + * @Version: V1.0 + */ +@Data +@TableName("iot_project_classify") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "project_classify瀵硅薄", description = "椤圭洰鍒嗙被") +public class ProjectClassify extends JeecgEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 椤圭洰鍚嶇О + */ + @Excel(name = "椤圭洰鍚嶇О", width = 15) + @ApiModelProperty(value = "椤圭洰鍚嶇О") + private String projectName; + /** + * 椤圭洰缂栧彿 + */ + @Excel(name = "椤圭洰缂栧彿", width = 15) + @ApiModelProperty(value = "椤圭洰缂栧彿") + private String projectCode; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/RealParameter.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/RealParameter.java new file mode 100644 index 0000000..6e1284a --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/RealParameter.java @@ -0,0 +1,139 @@ +package org.jeecg.modules.iot.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.system.base.entity.JeecgEntity; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; + +/** + * @Description: 瀹炶澶囧弬鏁� + * @Author: cuikaidong + * @Date: 2025-1-2 + * @Version: V1.0 + */ +@Data +@TableName("iot_real_parameter") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "RealParameter瀵硅薄", description = "瀹炶澶囧弬鏁�") +public class RealParameter implements Serializable { + private static final long serialVersionUID = 1L; + + /** ID */ + @TableId(type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "ID") + private String id; + /** 鍒涘缓浜� */ + @ApiModelProperty(value = "鍒涘缓浜�") + private String createBy; + /** 鍒涘缓鏃堕棿 */ + @ApiModelProperty(value = "鍒涘缓鏃堕棿") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private java.util.Date createTime; + /** 鏇存柊浜� */ + @ApiModelProperty(value = "鏇存柊浜�") + private String updateBy; + /** 鏇存柊鏃堕棿 */ + @ApiModelProperty(value = "鏇存柊鏃堕棿") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private java.util.Date updateTime; + /** + * 鍙傛暟缁刬d + */ + @ApiModelProperty(value = "鍙傛暟缁刬d") + private String parameterGroupId; + + + /** + * 鍙傛暟鍚嶇О + */ + @Excel(name = "鍚嶇О", width = 15) + @ApiModelProperty(value = "鍙傛暟鍚嶇О") + private String parameterName; + + /** + * 鍙傛暟绫诲瀷 + */ + @ApiModelProperty(value = "鍙傛暟绫诲瀷") + @Excel(name = "鏁版嵁绫诲瀷", width = 15) + private String parameterType; + + /** + * 鍙傛暟缂栧彿 + */ + @ApiModelProperty(value = "鍙傛暟缂栧彿") + private Integer parameterCode; + + /** + * 鍙傛暟鍦板潃 + */ + @Excel(name = "鍦板潃", width = 30) + @ApiModelProperty(value = "鍦板潃") + private String address; + + /** + * 瀛楃涓查暱搴� + */ + @Excel(name = "瀛楃涓查暱搴�", width = 15) + @ApiModelProperty(value = "瀛楃涓查暱搴�") + private Integer dataLength; + + /** + * 鍙傛暟鎻忚堪 + */ + @Excel(name = "鍙傛暟鎻忚堪", width = 50) + @ApiModelProperty(value = "鍙傛暟鎻忚堪") + private String parameterDescribe; + + /** + * 绯荤粺鏁版嵁绫诲瀷 + */ + @ApiModelProperty(value = "绯荤粺鏁版嵁绫诲瀷") + private String systemDataType; + /** + * 璇诲啓绫诲瀷 + */ + @Excel(name = "璇诲啓绫诲瀷", width = 10) + @ApiModelProperty(value = "璇诲啓绫诲瀷") + private String readWriteType; + + @TableField(exist = false) + private String groupCode; + @TableField(exist = false) + private String groupName; + @TableField(exist = false) + private String serverCode; + @TableField(exist = false) + private String serverId; + @TableField(exist = false) + private String equipmentId; + @TableField(exist = false) + private String dataType; + /******************************************* 璁㈤槄 *******************************************/ + @TableField(exist = false) + private String parameterValue; + @TableField(exist = false) + private String quality; + @TableField(exist = false) + private String timeStamp; + @TableField(exist = false) + private String eqptCode; + @TableField(exist = false) + private String eqptName; + @TableField(exist = false) + private String writingValue; + +} \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ScriptCompilation.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ScriptCompilation.java new file mode 100644 index 0000000..fe34094 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ScriptCompilation.java @@ -0,0 +1,33 @@ +package org.jeecg.modules.iot.entity; + +import lombok.Data; + +import java.util.Map; + +/** + * 鑴氭湰缂栬瘧瀹炰綋 + */ +@Data +public class ScriptCompilation { + + /** + * 铏氳澶噄d + */ + private String deviceId; + /** + * 鍙傛暟绫诲瀷 + */ + private String parameterDataType; + /** + * 鍙傛暟鍚嶇О + */ + private String parameterName; + /** + * 鑴氭湰 + */ + private String parameterCode; + /** + * 鍙傛暟 + */ + private Map<String, String> referenceinfo; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ServerDeploy.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ServerDeploy.java new file mode 100644 index 0000000..ff56e92 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/ServerDeploy.java @@ -0,0 +1,142 @@ +package org.jeecg.modules.iot.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.system.base.entity.JeecgEntity; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; + +/** + * @Description: 鏈嶅姟鍣ㄩ厤缃� + * @Author: cuikaidong + * @Date: 2024-12-22 + * @Version: V1.0 + */ +@Data +@TableName("iot_server_deploy") +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "server_deploy瀵硅薄", description = "鏈嶅姟鍣ㄩ厤缃�") +public class ServerDeploy extends JeecgEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 鏈嶅姟鍣ㄥ悕绉� + */ + @Excel(name = "鏈嶅姟鍣ㄥ悕绉�", width = 15) + @ApiModelProperty(value = "鏈嶅姟鍣ㄥ悕绉�") + private String serverName; + /** + * 鏈嶅姟鍣ㄧ紪鍙� + */ + @Excel(name = "鏈嶅姟鍣ㄧ紪鍙�", width = 15) + @ApiModelProperty(value = "鏈嶅姟鍣ㄧ紪鍙�") + private String serverCode; + /** + * 鏈嶅姟鍣ㄥ湴鍧� + */ + @Excel(name = "鏈嶅姟鍣ㄥ湴鍧�", width = 15) + @ApiModelProperty(value = "鏈嶅姟鍣ㄥ湴鍧�") + private String serverAddress; + /** + * 鏈嶅姟鍣ㄧ鍙� + */ + @Excel(name = "鏈嶅姟鍣ㄧ鍙�", width = 15) + @ApiModelProperty(value = "鏈嶅姟鍣ㄧ鍙�") + private String serverPort; + /** + * 閲囬泦杞欢鐘舵�� + */ + @Excel(name = "閲囬泦杞欢鐘舵��", width = 15) + @ApiModelProperty(value = "閲囬泦杞欢鐘舵��") + private Integer collectState; + /** + * 瀹堟姢杩炴帴鐘舵�� + */ + @Excel(name = "瀹堟姢杩炴帴鐘舵��", width = 15) + @ApiModelProperty(value = "瀹堟姢杩炴帴鐘舵��") + private Integer guardState; + /** + * 褰撳墠閲囬泦鐗堟湰 + */ + @Excel(name = "褰撳墠閲囬泦鐗堟湰", width = 15) + @ApiModelProperty(value = "褰撳墠閲囬泦鐗堟湰") + private String newCollectVersion; + /** + * 褰撳墠閲囬泦鐗堟湰鍦板潃 + */ + @Excel(name = "褰撳墠閲囬泦鐗堟湰鍦板潃", width = 15) + @ApiModelProperty(value = "褰撳墠閲囬泦鐗堟湰鍦板潃") + private String newCollectAddress; + /** + * 鏈�鏂伴噰闆嗙増鏈� + */ + @Excel(name = "鏈�鏂伴噰闆嗙増鏈�", width = 15) + @ApiModelProperty(value = "鏈�鏂伴噰闆嗙増鏈�") + private String latestCollectVersion; + /** + * 鏈�鏂伴厤缃枃浠剁増鏈� + */ + @Excel(name = "鏈�鏂伴厤缃枃浠剁増鏈�", width = 15) + @ApiModelProperty(value = "鏈�鏂伴厤缃枃浠剁増鏈�") + private String latestDeployVersion; + /** + * 閰嶇疆鏂囦欢鐗堟湰 + */ + @Excel(name = "閰嶇疆鏂囦欢鐗堟湰", width = 15) + @ApiModelProperty(value = "閰嶇疆鏂囦欢鐗堟湰") + private String newDeployVersion; + /** + * 椤圭洰鍒嗙被id + */ + @Excel(name = "椤圭洰鍒嗙被id", width = 15) + @ApiModelProperty(value = "椤圭洰鍒嗙被id") + private String projectClassifyId; + /** + * 鎺堟潈淇℃伅 + */ + @Excel(name = "鎺堟潈淇℃伅", width = 15) + @ApiModelProperty(value = "鎺堟潈淇℃伅") + private String authorize; + + /** 閰嶇疆涓嬪彂鏃堕棿 */ + @ApiModelProperty(value = "閰嶇疆涓嬪彂鏃堕棿") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private java.util.Date deployIssueTime; + /** + * 澶囨敞 + */ + @Excel(name = "澶囨敞", width = 15) + private String remark; + /** 閲囬泦鏃堕棿 */ + @ApiModelProperty(value = "閲囬泦鏃堕棿") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private java.util.Date collectTime; + + /*********************************************** 鎵╁睍瀛楁 **************************************************************/ + + @TableField(exist = false) + private InfluxdbDeploy influxdbDeploy; + + @TableField(exist = false) + private MqttDeploy mqttDeploy; + @TableField(exist = false) + private String collectVersion; + @TableField(exist = false) + private String deployVersion; + /* + * 缁堢鍦板潃 + */ + @TableField(exist = false) + private String address; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ByteOrder.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ByteOrder.java new file mode 100644 index 0000000..c6e8f06 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ByteOrder.java @@ -0,0 +1,18 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlType(name = "ByteOrder") +@XmlRootElement(name = "ByteOrder") +@XmlAccessorType(XmlAccessType.FIELD) +public class ByteOrder { + + // 绯荤粺绫诲瀷 + @XmlElement(name = "Type", type = ByteOrderType.class) + private List<ByteOrderType> typeList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ByteOrderType.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ByteOrderType.java new file mode 100644 index 0000000..07573fd --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ByteOrderType.java @@ -0,0 +1,15 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; + +@Data +@XmlRootElement(name ="ByteOrderType") +@XmlType(name = "ByteOrderType") +@XmlAccessorType(XmlAccessType.FIELD) +public class ByteOrderType { + + @XmlAttribute(name = "Name") + private String name; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Config.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Config.java new file mode 100644 index 0000000..834bea9 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Config.java @@ -0,0 +1,28 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlType(name = "Config") +@XmlRootElement(name = "Config") +@XmlAccessorType(XmlAccessType.FIELD) +public class Config { + + // 绯荤粺绫诲瀷 + @XmlElement(name = "SystemType", type = SystemType.class) + private List<SystemType> systemTypeList; + // 绯荤粺 + @XmlElement(name = "ControlSystem", type = ControlSystem.class) + public List<ControlSystem> controlSystemList; + // 瀛楄妭椤哄簭 + @XmlElement(name = "ByteOrder", type = ByteOrder.class) + public List<ByteOrder> byteOrderList; + // 鍙傛暟绫诲瀷 + @XmlElement(name = "SystemDataType", type = SystemDataType.class) + public List<SystemDataType> systemDataTypeList; + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ConnectionInfo.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ConnectionInfo.java new file mode 100644 index 0000000..b6065b5 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ConnectionInfo.java @@ -0,0 +1,19 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name ="ConnectionInfo") +@XmlType(name = "ConnectionInfo") +@XmlAccessorType(XmlAccessType.FIELD) +public class ConnectionInfo { + + @XmlAttribute(name = "Case") + private String case1; + + @XmlElement(name = "Parameter", type = Parameter.class) + public List<Parameter> parameterList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ControlSystem.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ControlSystem.java new file mode 100644 index 0000000..2835ac7 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/ControlSystem.java @@ -0,0 +1,22 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name ="ControlSystem") +@XmlType(name = "ControlSystem") +@XmlAccessorType(XmlAccessType.FIELD) +public class ControlSystem { + + @XmlAttribute(name = "Name") + private String name; + + @XmlAttribute(name = "Type") + private String type; + + @XmlElement(name = "Protocol", type = Protocol.class) + public List<Protocol> protocolList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DataType.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DataType.java new file mode 100644 index 0000000..0dabaf3 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DataType.java @@ -0,0 +1,18 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name = "DataType") +@XmlType(name = "DataType") +@XmlAccessorType(XmlAccessType.FIELD) +public class DataType { + + @XmlElement(name = "Parameter", type = Parameter.class) + public List<Parameter> parameterList; + + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DefaultParameter.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DefaultParameter.java new file mode 100644 index 0000000..c43b2fb --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DefaultParameter.java @@ -0,0 +1,15 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name = "DefaultParameter") +@XmlType(name = "DefaultParameter") +@XmlAccessorType(XmlAccessType.FIELD) +public class DefaultParameter { + @XmlElement(name = "Parameter", type = Parameter.class) + public List<Parameter> parameterList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DriveType.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DriveType.java new file mode 100644 index 0000000..373eae0 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/DriveType.java @@ -0,0 +1,25 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name ="DriveType") +@XmlType(name = "DriveType") +@XmlAccessorType(XmlAccessType.FIELD) +public class DriveType { + + @XmlAttribute(name = "Name") + private String name; + + @XmlAttribute(name = "FloatByteOrder") + private String floatByteOrder; + + @XmlElement(name = "ConnectionInfo", type = ConnectionInfo.class) + public List<ConnectionInfo> connectionInfoList; + + @XmlElement(name = "RegisterInfo", type = RegisterInfo.class) + public List<RegisterInfo> registerInfoList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/NodeAttribute.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/NodeAttribute.java new file mode 100644 index 0000000..b42d14c --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/NodeAttribute.java @@ -0,0 +1,29 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; + +@Data +@XmlRootElement(name = "NodeAttribute") +@XmlType(name = "NodeAttribute") +@XmlAccessorType(XmlAccessType.FIELD) +public class NodeAttribute { + + @XmlAttribute(name = "Id") + private String id; + + @XmlAttribute(name = "Name") + private String name; + + @XmlAttribute(name = "Describe") + private String describe; + + @XmlAttribute(name = "DataType") + private String dataType; + + @XmlAttribute(name = "Default") + private String default1; + + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Parameter.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Parameter.java new file mode 100644 index 0000000..486b6a4 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Parameter.java @@ -0,0 +1,38 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name ="Parameter") +@XmlType(name = "Parameter") +@XmlAccessorType(XmlAccessType.FIELD) +public class Parameter { + + @XmlAttribute(name = "Id") + private String id; + + @XmlAttribute(name = "Name") + private String name; + + @XmlAttribute(name = "Describe") + private String describe; + + @XmlAttribute(name = "DataType") + private String dataType; + + @XmlAttribute(name = "Default") + private String default1; + + @XmlAttribute(name = "systemDataType") + private String systemDataType; + + @XmlAttribute(name = "case") + private String case1; + + @XmlElement(name = "NodeAttribute", type = NodeAttribute.class) + public List<NodeAttribute> nodeAttributeList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Protocol.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Protocol.java new file mode 100644 index 0000000..2242e1d --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Protocol.java @@ -0,0 +1,32 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name = "Protocol") +@XmlType(name = "Protocol") +@XmlAccessorType(XmlAccessType.FIELD) +public class Protocol { + + // 绯荤粺绫诲瀷 + @XmlAttribute(name = "Name") + private String name; + + //绯荤粺鍚嶇О + @XmlAttribute(name = "LibraryName") + private String libraryName; + + //绯荤粺鍚嶇О + @XmlAttribute(name = "class") + private String class1; + + //绯荤粺鍚嶇О + @XmlAttribute(name = "version") + private String version; + + @XmlElement(name = "DriveType", type = DriveType.class) + public List<DriveType> driveTypeList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/RegisterInfo.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/RegisterInfo.java new file mode 100644 index 0000000..402e11a --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/RegisterInfo.java @@ -0,0 +1,23 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name = "RegisterInfo") +@XmlType(name = "RegisterInfo") +@XmlAccessorType(XmlAccessType.FIELD) +public class RegisterInfo { + + @XmlElement(name = "DataType", type = DataType.class) + public List<DataType> dataTypeList; + + @XmlElement(name = "RegisterType", type = RegisterType.class) + public List<RegisterType> registerTypeList; + + @XmlElement(name = "DefaultParameter", type = DefaultParameter.class) + public List<DefaultParameter> defaultParameterList; + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/RegisterType.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/RegisterType.java new file mode 100644 index 0000000..1361ce0 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/RegisterType.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name = "RegisterType") +@XmlType(name = "RegisterType") +@XmlAccessorType(XmlAccessType.FIELD) +public class RegisterType { + + @XmlElement(name = "Parameter",type = Parameter.class) + public List<Parameter> parameterList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/SystemDataType.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/SystemDataType.java new file mode 100644 index 0000000..995405c --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/SystemDataType.java @@ -0,0 +1,17 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlType(name = "SystemDataType") +@XmlRootElement(name = "SystemDataType") +@XmlAccessorType(XmlAccessType.FIELD) +public class SystemDataType { + + @XmlElement(name = "Type", type = ByteOrderType.class) + private List<ByteOrderType> typeList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/SystemType.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/SystemType.java new file mode 100644 index 0000000..615d60f --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/SystemType.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "SystemType") +@XmlRootElement(name = "SystemType") +public class SystemType { + + @XmlElement(name = "Type",type = Type.class) + public List<Type> typeList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Type.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Type.java new file mode 100644 index 0000000..9bc57fa --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/Type.java @@ -0,0 +1,17 @@ +package org.jeecg.modules.iot.entity.xmlEntity; + +import lombok.Data; + +import javax.xml.bind.annotation.*; + +@Data +@XmlRootElement(name ="Type") +@XmlType(name = "Type") +@XmlAccessorType(XmlAccessType.FIELD) +public class Type { + @XmlAttribute(name = "Name") + private String name; + + @XmlAttribute(name = "Describe") + private String describe; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/ConvertEntity.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/ConvertEntity.java new file mode 100644 index 0000000..4704696 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/ConvertEntity.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.iot.entity.xmlEntity.script; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name = "Convert") +@XmlType(name = "Convert") +@XmlAccessorType(XmlAccessType.FIELD) +public class ConvertEntity { + + @XmlElement(name = "Function", type = FunctionEntity.class) + public List<FunctionEntity> functionList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/CustomEntity.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/CustomEntity.java new file mode 100644 index 0000000..49dbd09 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/CustomEntity.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.iot.entity.xmlEntity.script; + +import lombok.Data; +import org.jeecg.modules.iot.entity.xmlEntity.Protocol; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name ="Custom") +@XmlType(name = "Custom") +@XmlAccessorType(XmlAccessType.FIELD) +public class CustomEntity { + @XmlElement(name = "Function", type = FunctionEntity.class) + public List<FunctionEntity> functionEntityList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/DatabaseEntity.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/DatabaseEntity.java new file mode 100644 index 0000000..0151b0d --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/DatabaseEntity.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.iot.entity.xmlEntity.script; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name = "Database") +@XmlType(name = "Database") +@XmlAccessorType(XmlAccessType.FIELD) +public class DatabaseEntity { + + @XmlElement(name = "Function", type = FunctionEntity.class) + public List<FunctionEntity> functionEntityList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/FileEntity.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/FileEntity.java new file mode 100644 index 0000000..a01c0aa --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/FileEntity.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.iot.entity.xmlEntity.script; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name = "File") +@XmlType(name = "File") +@XmlAccessorType(XmlAccessType.FIELD) +public class FileEntity { + + @XmlElement(name = "Function", type = FunctionEntity.class) + public List<FunctionEntity> functionEntityList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/FunctionEntity.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/FunctionEntity.java new file mode 100644 index 0000000..ec3a406 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/FunctionEntity.java @@ -0,0 +1,29 @@ +package org.jeecg.modules.iot.entity.xmlEntity.script; + +import lombok.Data; + +import javax.xml.bind.annotation.*; + +@Data +@XmlRootElement(name = "Function") +@XmlType(name = "Function") +@XmlAccessorType(XmlAccessType.FIELD) +public class FunctionEntity { + @XmlAttribute(name = "Name") + private String name; + + @XmlAttribute(name = "Describe") + private String describe; + + @XmlAttribute(name = "State") + private String state; + + @XmlAttribute(name = "DataType") + private String dataType; + + @XmlAttribute(name = "Tag") + private String tag; + + @XmlAttribute(name = "Codes") + private String codes; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/Functions.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/Functions.java new file mode 100644 index 0000000..40458fb --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/Functions.java @@ -0,0 +1,35 @@ +package org.jeecg.modules.iot.entity.xmlEntity.script; + + +import lombok.Data; + +import javax.xml.bind.annotation.*; + +@Data +@XmlType(name = "Functions") +@XmlRootElement(name = "Functions") +@XmlAccessorType(XmlAccessType.FIELD) +public class Functions { + + @XmlElement(name = "Convert", type = ConvertEntity.class) + private ConvertEntity convertEntity; + + @XmlElement(name = "Math", type = MathEntity.class) + private MathEntity mathEntity; + + @XmlElement(name = "String", type = StringEntity.class) + private StringEntity stringEntity; + + @XmlElement(name = "File", type = FileEntity.class) + private FileEntity fileEntity; + + @XmlElement(name = "Time", type = TimeEntity.class) + private TimeEntity timeEntity; + + @XmlElement(name = "Database", type = DatabaseEntity.class) + private DatabaseEntity databaseEntity; + + @XmlElement(name = "Custom", type = CustomEntity.class) + private CustomEntity customEntity; + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/MathEntity.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/MathEntity.java new file mode 100644 index 0000000..5e32be8 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/MathEntity.java @@ -0,0 +1,15 @@ +package org.jeecg.modules.iot.entity.xmlEntity.script; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name = "Math") +@XmlType(name = "Math") +@XmlAccessorType(XmlAccessType.FIELD) +public class MathEntity { + @XmlElement(name = "Function", type = FunctionEntity.class) + public List<FunctionEntity> functionEntityList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/StringEntity.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/StringEntity.java new file mode 100644 index 0000000..31f7607 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/StringEntity.java @@ -0,0 +1,15 @@ +package org.jeecg.modules.iot.entity.xmlEntity.script; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name = "String") +@XmlType(name = "String") +@XmlAccessorType(XmlAccessType.FIELD) +public class StringEntity { + @XmlElement(name = "Function", type = FunctionEntity.class) + public List<FunctionEntity> functionEntityList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/TimeEntity.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/TimeEntity.java new file mode 100644 index 0000000..067c7c7 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/entity/xmlEntity/script/TimeEntity.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.iot.entity.xmlEntity.script; + +import lombok.Data; + +import javax.xml.bind.annotation.*; +import java.util.List; + +@Data +@XmlRootElement(name = "Time") +@XmlType(name = "Time") +@XmlAccessorType(XmlAccessType.FIELD) +public class TimeEntity { + + @XmlElement(name = "Function", type = FunctionEntity.class) + public List<FunctionEntity> functionEntityList; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ControlSystemMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ControlSystemMapper.java new file mode 100644 index 0000000..1b215da --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ControlSystemMapper.java @@ -0,0 +1,18 @@ +package org.jeecg.modules.iot.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.jeecg.modules.iot.entity.ControlSystem; +import org.springframework.stereotype.Component; + +/** + * @Description: 鎺у埗绯荤粺淇℃伅 + * @Author: cuikaidong + * @Date: 2025-6-3 + * @Version: V1.0 + */ +@Component("iotControlSystemMapper") +public interface ControlSystemMapper extends BaseMapper<ControlSystem> { + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/EmptyParameterMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/EmptyParameterMapper.java new file mode 100644 index 0000000..97dd814 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/EmptyParameterMapper.java @@ -0,0 +1,28 @@ +package org.jeecg.modules.iot.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.lettuce.core.dynamic.annotation.Param; +import org.apache.ibatis.annotations.Select; +import org.jeecg.modules.iot.entity.EmptyParameter; + +import java.util.Date; +import java.util.List; + +/** + * @Description: 铏氳澶囧弬鏁� + * @Author: cuikaidong + * @Date: 2025-1-7 + * @Version: V1.0 + */ +public interface EmptyParameterMapper extends BaseMapper<EmptyParameter> { + + List<EmptyParameter> findEmptyParameterList(@Param("list") List<String> list); + + /** + * 鏍规嵁鏃堕棿锛岀粓绔煡璇� + */ + @Select("SELECT p.*,e.eqpt_code FROM iot_empty_parameter p LEFT JOIN iot_equipment e ON e.id = p.equipment_id WHERE p.create_time > #{deployDate} AND e.server_id = #{serverId};") +// @Select("SELECT p.*,e.eqpt_code FROM `iot_empty_parameter` p LEFT JOIN iot_equipment e ON e.id = p.equipment_id WHERE p.create_time > #{deployDate} AND e.server_id = #{serverId};") + public List<EmptyParameter> findEmptyParameterListByTime(Date deployDate, String serverId); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/EquipmentMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/EquipmentMapper.java new file mode 100644 index 0000000..c731978 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/EquipmentMapper.java @@ -0,0 +1,18 @@ +package org.jeecg.modules.iot.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.jeecg.modules.iot.entity.Equipment; +import org.jeecg.modules.iot.entity.ServerDeploy; +import org.springframework.stereotype.Component; + +/** + * @Description: 璁惧 + * @Author: cuikaidong + * @Date: 2024-12-20 + * @Version: V1.0 + */ +@Component("iotEquipmentMapper") +public interface EquipmentMapper extends BaseMapper<Equipment> { + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/InfluxdbDeployMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/InfluxdbDeployMapper.java new file mode 100644 index 0000000..074841b --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/InfluxdbDeployMapper.java @@ -0,0 +1,15 @@ +package org.jeecg.modules.iot.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.jeecg.modules.iot.entity.InfluxdbDeploy; + +/** + * @Description: influxdb閰嶇疆 + * @Author: cuikaidong + * @Date: 2024-12-10 + * @Version: V1.0 + */ +public interface InfluxdbDeployMapper extends BaseMapper<InfluxdbDeploy> { + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/MqttDeployMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/MqttDeployMapper.java new file mode 100644 index 0000000..f0aca69 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/MqttDeployMapper.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.iot.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.jeecg.modules.iot.entity.InfluxdbDeploy; +import org.jeecg.modules.iot.entity.MqttDeploy; + +/** + * @Description: Mqtt閰嶇疆 + * @Author: cuikaidong + * @Date: 2024-12-10 + * @Version: V1.0 + */ +public interface MqttDeployMapper extends BaseMapper<MqttDeploy> { + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ParameterGroupMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ParameterGroupMapper.java new file mode 100644 index 0000000..24223fd --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ParameterGroupMapper.java @@ -0,0 +1,15 @@ +package org.jeecg.modules.iot.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.jeecg.modules.iot.entity.ParameterGroup; + +/** + * @Description: 鍙傛暟缁� + * @Author: cuikaidong + * @Date: 2024-12-31 + * @Version: V1.0 + */ +public interface ParameterGroupMapper extends BaseMapper<ParameterGroup> { + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ProjectClassifyMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ProjectClassifyMapper.java new file mode 100644 index 0000000..c2eae62 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ProjectClassifyMapper.java @@ -0,0 +1,15 @@ +package org.jeecg.modules.iot.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.jeecg.modules.iot.entity.ProjectClassify; + +/** + * @Description: 椤圭洰鍒嗙被 + * @Author: cuikaidong + * @Date: 2024-12-20 + * @Version: V1.0 + */ +public interface ProjectClassifyMapper extends BaseMapper<ProjectClassify> { + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/RealParameterMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/RealParameterMapper.java new file mode 100644 index 0000000..0fe69a6 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/RealParameterMapper.java @@ -0,0 +1,25 @@ +package org.jeecg.modules.iot.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.lettuce.core.dynamic.annotation.Param; +import org.jeecg.modules.iot.entity.EmptyParameter; +import org.jeecg.modules.iot.entity.RealParameter; + +import java.util.List; +import java.util.Map; + +/** + * @Description: 瀹炶澶囧弬鏁� + * @Author: cuikaidong + * @Date: 2025-1-2 + * @Version: V1.0 + */ +public interface RealParameterMapper extends BaseMapper<RealParameter> { + + IPage<RealParameter> findRealParameterPage(Page<RealParameter> pages, @Param("params") Map<String, Object> params); + + List<RealParameter> findRealParameterList(@Param("list") List<String> list); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ServerDeployMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ServerDeployMapper.java new file mode 100644 index 0000000..cd3fe9c --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/ServerDeployMapper.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.iot.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.jeecg.modules.iot.entity.ProjectClassify; +import org.jeecg.modules.iot.entity.ServerDeploy; + +/** + * @Description: 鏈嶅姟鍣ㄩ厤缃� + * @Author: cuikaidong + * @Date: 2024-12-20 + * @Version: V1.0 + */ +public interface ServerDeployMapper extends BaseMapper<ServerDeploy> { + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ControlSystemMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ControlSystemMapper.xml new file mode 100644 index 0000000..ff6155d --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ControlSystemMapper.xml @@ -0,0 +1,4 @@ +<?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="org.jeecg.modules.iot.mapper.ControlSystemMapper"> +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/EmptyParameterMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/EmptyParameterMapper.xml new file mode 100644 index 0000000..9cd21e6 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/EmptyParameterMapper.xml @@ -0,0 +1,18 @@ +<?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="org.jeecg.modules.iot.mapper.EmptyParameterMapper"> + + <select id="findEmptyParameterList" resultType="org.jeecg.modules.iot.entity.EmptyParameter"> + SELECT + p.system_data_type AS systemDataType, + p.parameter_type AS parameterType, + CONCAT( 'IOT_', e.eqpt_name, '_', p.parameter_name ) AS address + FROM + iot_empty_parameter p + LEFT JOIN iot_equipment e ON e.id = p.equipment_id + WHERE CONCAT( 'IOT_', e.eqpt_name, '_', p.parameter_name ) in + <foreach item="attribute" collection="list" separator="," open="(" close=")"> + #{attribute} + </foreach> + </select> +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/EquipmentMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/EquipmentMapper.xml new file mode 100644 index 0000000..c7fe3de --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/EquipmentMapper.xml @@ -0,0 +1,5 @@ +<?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="org.jeecg.modules.iot.mapper.EquipmentMapper"> + +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/InfluxdbDeployMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/InfluxdbDeployMapper.xml new file mode 100644 index 0000000..56b74ea --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/InfluxdbDeployMapper.xml @@ -0,0 +1,5 @@ +<?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="org.jeecg.modules.iot.mapper.InfluxdbDeployMapper"> + +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/MqttDeployMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/MqttDeployMapper.xml new file mode 100644 index 0000000..ef45809 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/MqttDeployMapper.xml @@ -0,0 +1,5 @@ +<?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="org.jeecg.modules.iot.mapper.MqttDeployMapper"> + +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ParameterGroupMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ParameterGroupMapper.xml new file mode 100644 index 0000000..107045a --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ParameterGroupMapper.xml @@ -0,0 +1,5 @@ +<?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="org.jeecg.modules.iot.mapper.ParameterGroupMapper"> + +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ProjectClassifyMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ProjectClassifyMapper.xml new file mode 100644 index 0000000..e78ff34 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ProjectClassifyMapper.xml @@ -0,0 +1,5 @@ +<?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="org.jeecg.modules.iot.mapper.ProjectClassifyMapper"> + +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/RealParameterMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/RealParameterMapper.xml new file mode 100644 index 0000000..f5eab46 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/RealParameterMapper.xml @@ -0,0 +1,46 @@ +<?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="org.jeecg.modules.iot.mapper.RealParameterMapper"> + + <select id="findRealParameterPage" resultType="org.jeecg.modules.iot.entity.RealParameter"> + SELECT + r.*, + g.code groupCode, + g.name groupName, + s.server_code serverCode, + s.id serverId, + g.equipment_id equipmentId, + e.eqpt_type dataType, + e.eqpt_code eqptCode, + e.eqpt_name eqptName + FROM + iot_real_parameter r + LEFT JOIN iot_parameter_group g on g.id = r.parameter_group_id + LEFT JOIN iot_server_deploy s on s.id = g.server_deploy_id + LEFT JOIN iot_equipment e on e.id = g.equipment_id + where 1 = 1 + <if test="params.parameterGroupId != null and params.parameterGroupId != ''"> + and r.parameter_group_id = '${params.parameterGroupId}' + </if> + <if test="params.parameterName != null and params.parameterName != ''"> + and r.parameter_name like '%${params.parameterName}%' + </if> + <if test="params.parameterCode != null and params.parameterCode != ''"> + and r.parameter_code like '%${params.parameterCode}%' + </if> + ORDER BY r.parameter_code DESC; + </select> + <select id="findRealParameterList" resultType="org.jeecg.modules.iot.entity.RealParameter"> + SELECT + r.system_data_type, + r.parameter_type AS parameterType, + CONCAT( 'IOT_', e.eqpt_name, '_', g.name, '_', r.parameter_name ) AS address + FROM iot_real_parameter r + LEFT JOIN iot_parameter_group g ON g.id = r.parameter_group_id + LEFT JOIN iot_equipment e ON e.id = g.equipment_id + WHERE CONCAT( 'IOT_', e.eqpt_name, '_', g.name, '_', r.parameter_name ) in + <foreach item="attribute" collection="list" separator="," open="(" close=")"> + #{attribute} + </foreach> + </select> +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ServerDeployMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ServerDeployMapper.xml new file mode 100644 index 0000000..1368755 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mapper/xml/ServerDeployMapper.xml @@ -0,0 +1,5 @@ +<?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="org.jeecg.modules.iot.mapper.ServerDeployMapper"> + +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/Equipment.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/Equipment.java new file mode 100644 index 0000000..2e1109c --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/Equipment.java @@ -0,0 +1,188 @@ +package org.jeecg.modules.iot.mdc.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; +import java.util.Date; + +/** + * @Description: 閲囬泦璁惧琛� + * @Author: liuS + * @Date: 2023-03-23 + * @Version: V1.0 + */ +@Data +@TableName("equipment") +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@ApiModel(value = "Equipment瀵硅薄", description = "閲囬泦璁惧琛�") +public class Equipment { + + /** + * 绯荤粺id + */ + @Excel(name = "绯荤粺id", width = 15) + @ApiModelProperty(value = "绯荤粺id") + private String beltlineid; + /** + * 璁惧缂栫爜 + */ + @Excel(name = "璁惧缂栫爜", width = 15) + @ApiModelProperty(value = "璁惧缂栫爜") + @TableId(type = IdType.ASSIGN_ID) + private String equipmentid; + /** + * 宸ュ巶id + */ + @Excel(name = "宸ュ巶id", width = 15) + @ApiModelProperty(value = "宸ュ巶id") + private String factoryid; + /** + * 绯荤粺鍚嶇О + */ + @Excel(name = "绯荤粺鍚嶇О", width = 15) + @ApiModelProperty(value = "绯荤粺鍚嶇О") + private String beltlinename; + /** + * 璁惧绫诲瀷 + */ + @Excel(name = "璁惧绫诲瀷", width = 15) + @ApiModelProperty(value = "璁惧绫诲瀷") + private String equipmentmodel; + /** + * 璁惧鍚嶇О + */ + @Excel(name = "璁惧鍚嶇О", width = 15) + @ApiModelProperty(value = "璁惧鍚嶇О") + private String equipmentname; + /** + * 璁惧鍒嗙被 + */ + @Excel(name = "璁惧鍒嗙被", width = 15) + @ApiModelProperty(value = "璁惧鍒嗙被") + private String equipmentclassify; + /** + * 璁惧浣嶇疆 + */ + @Excel(name = "璁惧浣嶇疆", width = 15) + @ApiModelProperty(value = "璁惧浣嶇疆") + private String equipmentlocation; + /** + * 鎶ヨ鍙� + */ + @Excel(name = "鎶ヨ鍙�", width = 15) + @ApiModelProperty(value = "鎶ヨ鍙�") + private String alarm; + /** + * 閲囬泦鏃堕棿 + */ + @Excel(name = "閲囬泦鏃堕棿", width = 20, format = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "閲囬泦鏃堕棿") + private Date collecttime; + /** + * 璁惧绫诲瀷 + */ + @Excel(name = "璁惧绫诲瀷", width = 15) + @ApiModelProperty(value = "璁惧绫诲瀷") + private String equipmenttype; + /** + * 鍥哄畾浣嶇疆 + */ + @Excel(name = "鍥哄畾浣嶇疆", width = 15) + @ApiModelProperty(value = "鍥哄畾浣嶇疆") + private String fixlocation; + /** + * 瀹炴椂鐘舵�� + */ + @Excel(name = "瀹炴椂鐘舵��", width = 15) + @ApiModelProperty(value = "瀹炴椂鐘舵��") + private Integer oporation; + /** + * 璁惧鏁版嵁 + */ + @Excel(name = "璁惧鏁版嵁", width = 15) + @ApiModelProperty(value = "璁惧鏁版嵁") + private Object equipmentdata; + /** + * 璁惧ip + */ + @Excel(name = "璁惧ip", width = 15) + @ApiModelProperty(value = "璁惧ip") + private String equipmentip; + /** + * 澶囨敞 + */ + @Excel(name = "澶囨敞", width = 15) + @ApiModelProperty(value = "澶囨敞") + private String remark; + /** + * 鎶ヨ鍙� + */ + @Excel(name = "鎶ヨ鍙�", width = 15) + @ApiModelProperty(value = "鎶ヨ鍙�") + private String alarmno; + /** + * 鎶ヨ鍐呭 + */ + @Excel(name = "鎶ヨ鍐呭", width = 15) + @ApiModelProperty(value = "鎶ヨ鍐呭") + private String alarmcontent; + /** + * 浜у搧鏁伴噺 + */ + @Excel(name = "浜у搧鏁伴噺", width = 15) + @ApiModelProperty(value = "浜у搧鏁伴噺") + private String productcount; + /** + * 椹卞姩绫诲瀷 + */ + @Excel(name = "椹卞姩绫诲瀷", width = 15) + @ApiModelProperty(value = "椹卞姩绫诲瀷") + private String drivetype; + /** + * 鏁版嵁绔彛 + */ + @Excel(name = "鏁版嵁绔彛", width = 15) + @ApiModelProperty(value = "鏁版嵁绔彛") + private String dataport; + /** + * 鎺у埗绯荤粺 + */ + @Excel(name = "鎺у埗绯荤粺", width = 15) + @ApiModelProperty(value = "鎺у埗绯荤粺") + private String controlsystem; + /** + * 琛ㄥ悕 + */ + @Excel(name = "琛ㄥ悕", width = 15) + @ApiModelProperty(value = "琛ㄥ悕") + private String savetablename; + /** + * 閲嶈鎬� + */ + @Excel(name = "閲嶈鎬�", width = 15) + @ApiModelProperty(value = "閲嶈鎬�") + private Integer isimportant; + /** + * 缁存姢鐘舵�� + */ + @Excel(name = "缁存姢鐘舵��", width = 15) + @ApiModelProperty(value = "缁存姢鐘舵��") + private Integer maintaintype; + /** + * 楂樹綆鎺у埗 + */ + @Excel(name = "楂樹綆鎺у埗", width = 15) + @ApiModelProperty(value = "楂樹綆鎺у埗") + private String highlowcontrol; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/EquipmentAlarm.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/EquipmentAlarm.java new file mode 100644 index 0000000..804ad92 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/EquipmentAlarm.java @@ -0,0 +1,37 @@ +package org.jeecg.modules.iot.mdc.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; + +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("equipmentalarm") +public class EquipmentAlarm implements Serializable { + + private static final long serialVersionUID = -4762333096168370779L; + +// @TableId(type = IdType.AUTO) + private String equipmentid; + private Date collecttime; + + @TableField(value = "alarmNo") + private String alarmNo; + + @TableField(value = "alarmContent") + private String alarmContent; + private String isexamine; + private String iseffective; + private Date examinetime; + private String examineperson; + private String remark; + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/EquipmentLog.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/EquipmentLog.java new file mode 100644 index 0000000..03a7ea0 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/EquipmentLog.java @@ -0,0 +1,43 @@ +package org.jeecg.modules.iot.mdc.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; + +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("equipmentlog") +@ApiModel(value = "璁惧鍘嗗彶琛�") +public class EquipmentLog implements Serializable { + + private static final long serialVersionUID = 6978749606363390023L; + + @ApiModelProperty(value = "璁惧ID") + @TableId(value = "EquipmentID") + private String equipmentId; + + @TableField(value = "EquipmentName") + private String equipmentName; + + @TableField(value = "CollectTime") + private Date collectTime; + @TableField(value = "Oporation") + private Integer oporation; + @TableField(value = "Alarm") + private String alarm; + + @TableField(exist = false) + private String createBy = "admin"; + @TableField(exist = false) + private String oporationName; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/MdcDriveTypeParamConfig.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/MdcDriveTypeParamConfig.java new file mode 100644 index 0000000..e72de8f --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/entity/MdcDriveTypeParamConfig.java @@ -0,0 +1,66 @@ +package org.jeecg.modules.iot.mdc.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.jeecg.common.system.base.entity.JeecgEntity; +import org.jeecgframework.poi.excel.annotation.Excel; + +/** + * @Description: 椹卞姩鍙傛暟閰嶇疆 + * @Author: jeecg-boot + * @Date: 2023-04-20 + * @Version: V1.0 + */ +@Data +@TableName("mdc_drive_type_param_config") +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@ApiModel(value = "mdc_drive_type_param_config瀵硅薄", description = "椹卞姩鍙傛暟閰嶇疆") +public class MdcDriveTypeParamConfig extends JeecgEntity { + + /** + * 鎺у埗绯荤粺绫诲瀷 + */ + @Excel(name = "鎺у埗绯荤粺绫诲瀷", width = 15) + @ApiModelProperty(value = "鎺у埗绯荤粺绫诲瀷") + private String controlSystemType; + /** + * 涓枃鍚嶇О + */ + @Excel(name = "涓枃鍚嶇О", width = 15) + @ApiModelProperty(value = "涓枃鍚嶇О") + private String chineseName; + /** + * 鑻辨枃鍚嶇О + */ + @Excel(name = "鑻辨枃鍚嶇О", width = 15) + @ApiModelProperty(value = "鑻辨枃鍚嶇О") + private String englishName; + /** + * 搴忓彿 + */ + @Excel(name = "搴忓彿", width = 15) + @ApiModelProperty(value = "搴忓彿") + private Integer sortNo; + /** + * 灞曠ず鏍囧織 + */ + @Excel(name = "灞曠ず鏍囧織", width = 15, replace = {"鏄痏Y", "鍚N"}) + @ApiModelProperty(value = "灞曠ず鏍囧織") + private String showFlag; + /** + * 宸ヤ綔鏇茬嚎鐢熸垚鏍囪 + */ + @Excel(name = "宸ヤ綔鏇茬嚎鐢熸垚鏍囪", width = 15, replace = {"鏄痏Y", "鍚N"}) + @ApiModelProperty(value = "宸ヤ綔鏇茬嚎鐢熸垚鏍囪") + private String curveGenerationFlags; + + @TableField(exist = false) + @ApiModelProperty(value = "閲囬泦鍊�") + private String value; +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentAlarmMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentAlarmMapper.java new file mode 100644 index 0000000..3c2ffdc --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentAlarmMapper.java @@ -0,0 +1,18 @@ +package org.jeecg.modules.iot.mdc.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.jeecg.modules.iot.mdc.entity.EquipmentAlarm; +import org.jeecg.modules.iot.mdc.entity.EquipmentLog; +import org.springframework.stereotype.Component; + +/** + * @author: LiuS + * @create: 2023-04-12 16:39 + */ +@Component("iotEquipmentAlarmMapper") +public interface EquipmentAlarmMapper extends BaseMapper<EquipmentAlarm> { + @Select("SELECT TOP 1 * FROM EquipmentAlarm WHERE EquipmentID = #{ equipmentId } ORDER BY CollectTime DESC") + EquipmentAlarm selectEquipmentAlarmByEquipmentId(@Param("equipmentId") String equipmentId); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentLogMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentLogMapper.java new file mode 100644 index 0000000..83c0a2e --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentLogMapper.java @@ -0,0 +1,24 @@ +package org.jeecg.modules.iot.mdc.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; +import org.jeecg.modules.iot.mdc.entity.EquipmentLog; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.List; + +/** + * @author: LiuS + * @create: 2023-04-12 14:44 + */ +@Component("iotEquipmentLogMapper") +public interface EquipmentLogMapper extends BaseMapper<EquipmentLog> { + + + EquipmentLog getRow(@Param("equipmentid") String equipmentid, @Param("startTime") Date startTime); + + EquipmentLog selectEquipmentOporation(@Param("equipmentId") String equipmentId); + + List<EquipmentLog> getEquipmentStatusList(@Param("equipmentIdList") List<String> equipmentIdList); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentMapper.java new file mode 100644 index 0000000..fe294b8 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/EquipmentMapper.java @@ -0,0 +1,32 @@ +package org.jeecg.modules.iot.mdc.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.*; +import org.jeecg.modules.iot.mdc.entity.Equipment; +import org.springframework.stereotype.Component; + +/** + * @Description: 閲囬泦璁惧琛� + * @Author: liuS + * @Date: 2023-03-23 + * @Version: V1.0 + */ +@Component("iotMdcEquipmentMapper") +@Mapper +public interface EquipmentMapper extends BaseMapper<Equipment> { + + @Select(" SELECT name FROM SysObjects Where XType='U' AND name = '${saveTableName}' ") + String checkTableExists(@Param("saveTableName") String saveTableName); + + @Select(" SELECT COUNT(CollectTime) num FROM ${saveTableName} WHERE CollectTime < '${day}' ") + Integer checkTableDataNum(@Param("saveTableName") String saveTableName, @Param("day") String day); + + @Insert(" INSERT INTO ${tableName} SELECT * FROM ${lastTableName} WHERE CollectTime < '${date}' ") + void insertTableData(@Param("tableName") String tableName, @Param("lastTableName") String lastTableName, @Param("date") String date); + + @Delete(" delete from ${tableName} where CollectTime < '${day}' ") + void deleteTableData(@Param("tableName") String saveTableName, @Param("day") String day); + + @Insert(" SELECT * INTO ${tableName} FROM ${lastTableName} WHERE CollectTime < '${date}' ") + void insertNoTableData(@Param("tableName") String tableName, @Param("lastTableName") String lastTableName, @Param("date") String date); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/MdcDriveTypeParamConfigMapper.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/MdcDriveTypeParamConfigMapper.java new file mode 100644 index 0000000..7d35ba4 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/MdcDriveTypeParamConfigMapper.java @@ -0,0 +1,29 @@ +package org.jeecg.modules.iot.mdc.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; +import org.jeecg.modules.iot.mdc.entity.MdcDriveTypeParamConfig; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * @Description: 椹卞姩鍙傛暟閰嶇疆 + * @Author: jeecg-boot + * @Date: 2023-04-20 + * @Version: V1.0 + */ +@Component("iotMdcDriveTypeParamConfigMapper") +public interface MdcDriveTypeParamConfigMapper extends BaseMapper<MdcDriveTypeParamConfig> { + + /** + * 鏍规嵁璁惧缂栫爜鑾峰彇宸ヤ綔鏇茬嚎鍙傛暟 + */ + List<MdcDriveTypeParamConfig> findWorkCurveParamList(@Param("equipmentId") String equipmentId); + + /** + * 鑾峰彇鎺у埗绯荤粺绫诲瀷涓嬫媺妗嗛�夐」 + */ + List<String> getDriveParamOptions(); + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/EquipmentLogMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/EquipmentLogMapper.xml new file mode 100644 index 0000000..c542c3b --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/EquipmentLogMapper.xml @@ -0,0 +1,28 @@ +<?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="org.jeecg.modules.iot.mdc.mapper.EquipmentLogMapper"> + + <select id="getRow" resultType="org.jeecg.modules.iot.mdc.entity.EquipmentLog"> + SELECT top 1 * FROM EquipmentLog WHERE EquipmentID = #{ equipmentid } AND CollectTime <= #{ startTime } AND Oporation in ('0','1','2','3') ORDER BY CollectTime ASC + </select> + + <select id="selectEquipmentOporation" resultType="org.jeecg.modules.iot.mdc.entity.EquipmentLog"> + SELECT TOP 1 * FROM EquipmentLog WHERE EquipmentID = #{ equipmentId } ORDER BY CollectTime DESC + </select> + + <!--鏌ヨ璁惧鏈�鏂颁竴鏉℃暟鎹�--> + <select id="getEquipmentStatusList" resultType="org.jeecg.modules.iot.mdc.entity.EquipmentLog"> + SELECT + t1.* + FROM + EquipmentLog t1 + INNER JOIN ( SELECT MAX ( CollectTime ) AS CollectTime, EquipmentID FROM EquipmentLog GROUP BY EquipmentID ) t2 ON t1.CollectTime= t2.CollectTime + AND t1.EquipmentID= t2.EquipmentID + <if test="equipmentIdList != null and equipmentIdList.size() > 0"> + AND t1.EquipmentID IN + <foreach collection="equipmentIdList" index="index" item="id" open="(" separator="," close=")"> + #{id} + </foreach> + </if> + </select> +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/EquipmentMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/EquipmentMapper.xml new file mode 100644 index 0000000..d42edf5 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/EquipmentMapper.xml @@ -0,0 +1,5 @@ +<?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="org.jeecg.modules.iot.mdc.mapper.EquipmentMapper"> + +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/MdcDriveTypeParamConfigMapper.xml b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/MdcDriveTypeParamConfigMapper.xml new file mode 100644 index 0000000..0d2a9a7 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/mapper/xml/MdcDriveTypeParamConfigMapper.xml @@ -0,0 +1,23 @@ +<?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="org.jeecg.modules.iot.mdc.mapper.MdcDriveTypeParamConfigMapper"> + + <!--鏍规嵁璁惧缂栫爜鑾峰彇宸ヤ綔鏇茬嚎鍙傛暟--> + <select id="findWorkCurveParamList" resultType="org.jeecg.modules.iot.mdc.entity.MdcDriveTypeParamConfig"> + SELECT + mdtpc.* + FROM + mdc_drive_type_param_config mdtpc + LEFT JOIN mdc_equipment me ON mdtpc.control_system_type = me.drive_type + WHERE + mdtpc.curve_generation_flags = 'Y' + AND me.equipment_id = #{equipmentId} + </select> + + <select id="getDriveParamOptions" resultType="java.lang.String"> + SELECT DISTINCT + control_system_type + FROM + mdc_drive_type_param_config + </select> +</mapper> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentAlarmService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentAlarmService.java new file mode 100644 index 0000000..c90d0d8 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentAlarmService.java @@ -0,0 +1,18 @@ +package org.jeecg.modules.iot.mdc.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.iot.mdc.entity.EquipmentAlarm; +import org.jeecg.modules.iot.mdc.entity.EquipmentLog; + +import java.util.Date; +import java.util.List; + +/** + * @author: LiuS + * @create: 2023-04-12 16:38 + */ +public interface IEquipmentAlarmService extends IService<EquipmentAlarm> { + List<EquipmentAlarm> findEquipmentAlarmByDate(String equipmentId, Date startTime, Date endTime); + + EquipmentAlarm selectEquipmentAlarmByEquipmentId(String equipmentId); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentLogService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentLogService.java new file mode 100644 index 0000000..17a1dc5 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentLogService.java @@ -0,0 +1,33 @@ +package org.jeecg.modules.iot.mdc.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.iot.mdc.entity.EquipmentLog; + +import java.util.Date; +import java.util.List; + +/** + * @author: LiuS + * @create: 2023-04-12 14:40 + */ +public interface IEquipmentLogService extends IService<EquipmentLog> { + + /** + * 鏌ヨ鏌愪釜璁惧鏌愪釜鏃堕棿鐐逛箣鍚庣殑鏁版嵁 + */ + List<EquipmentLog> findEquipmentLogByEndTime(String equipmentId, Date maxDate); + + /** + * 鏌ヨ鏌愪釜璁惧鏌愪釜鏃堕棿鐐逛箣鍚庣殑鏁版嵁(鎶ヨ鏁版嵁) + */ + List<EquipmentLog> findEquipmentLogByErrorEndTime(String equipmentId, Date endTime); + + /** + * 鑾峰彇璁惧鏌愪釜鏃堕棿鐐逛箣鍚庣殑鏈�鏂颁竴鏉℃暟鎹� + */ + EquipmentLog getRow(String equipmentid, Date startTime); + + EquipmentLog selectEquipmentOporation(String equipmentId); + + List<EquipmentLog> getEquipmentStatusList(List<String> equipmentIdList); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentService.java new file mode 100644 index 0000000..076f5f0 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IEquipmentService.java @@ -0,0 +1,63 @@ +package org.jeecg.modules.iot.mdc.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.iot.mdc.entity.Equipment; + +/** + * @Description: 閲囬泦璁惧琛� + * @Author: liuS + * @Date: 2023-03-23 + * @Version: V1.0 + */ +public interface IEquipmentService extends IService<Equipment> { + + /** + * 鏍规嵁鏁版嵁琛ㄥ悕绉版煡璇㈡暟鎹〃鏄惁瀛樺湪 + * + * @param saveTableName + * @return + */ + String checkTableExists(String saveTableName); + + /** + * 鏌ヨ闇�澶囦唤鏁版嵁閲� + * + * @param saveTableName + * @param day + * @return + */ + Integer checkTableDataNum(String saveTableName, String day); + + /** + * 鏁版嵁杩佺Щ + * + * @param backupTableName + * @param tableName + * @param day + */ + void insertTableData(String backupTableName, String tableName, String day); + + /** + * 鍒犻櫎鍘熸暟鎹〃鏁版嵁 + * + * @param tableName + * @param day + */ + void deleteTableData(String tableName, String day); + + /** + * 鍒涘缓澶囦唤琛� + * + * @param backupTableName + * @param tableName + * @param day + */ + void insertNoTableData(String backupTableName, String tableName, String day); + + /** + * 鏍规嵁璁惧id鏌ヨ璁惧淇℃伅 + * + * @param equipmentId + */ + Equipment findEquipmentByEquipmentId(String equipmentId); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IMdcDriveTypeParamConfigService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IMdcDriveTypeParamConfigService.java new file mode 100644 index 0000000..4159ff2 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/IMdcDriveTypeParamConfigService.java @@ -0,0 +1,31 @@ +package org.jeecg.modules.iot.mdc.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.iot.mdc.entity.MdcDriveTypeParamConfig; + +/** + * @Description: 椹卞姩鍙傛暟閰嶇疆 + * @Author: jeecg-boot + * @Date: 2023-04-20 + * @Version: V1.0 + */ +public interface IMdcDriveTypeParamConfigService extends IService<MdcDriveTypeParamConfig> { + + /** + * 鏍规嵁椹卞姩锛屽弬鏁板悕绉帮紝鏌ヨ椹卞姩鍙傛暟閰嶇疆 + * + * @param controlSystemType + * @param englishName + * @return + */ + MdcDriveTypeParamConfig selectMdcDriveTypeParamConfigByEquipment(String controlSystemType, String englishName); + + /** + * 鏍规嵁椹卞姩锛屽弬鏁板悕绉帮紝鏌ヨ椹卞姩鍙傛暟鏄惁閲嶅 + * + * @param controlSystemType + * @param englishName + * @return + */ + boolean selectEnglishNameByEquipment(String controlSystemType, String englishName); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentAlarmServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentAlarmServiceImpl.java new file mode 100644 index 0000000..1db5d07 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentAlarmServiceImpl.java @@ -0,0 +1,30 @@ +package org.jeecg.modules.iot.mdc.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.modules.iot.mdc.entity.EquipmentAlarm; +import org.jeecg.modules.iot.mdc.mapper.EquipmentAlarmMapper; +import org.jeecg.modules.iot.mdc.service.IEquipmentAlarmService; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * @author: LiuS + * @create: 2023-04-12 16:39 + */ +@Service("iotEquipmentAlarmServiceImpl") +public class EquipmentAlarmServiceImpl extends ServiceImpl<EquipmentAlarmMapper, EquipmentAlarm> implements IEquipmentAlarmService { + @Override + public List<EquipmentAlarm> findEquipmentAlarmByDate(String equipmentId, Date startTime, Date endTime) { + return this.list(new LambdaQueryWrapper<EquipmentAlarm>() + .ge(EquipmentAlarm::getCollecttime, startTime).le(EquipmentAlarm::getCollecttime, endTime) + .eq(EquipmentAlarm::getEquipmentid, equipmentId).orderByDesc(EquipmentAlarm::getCollecttime)); + } + + @Override + public EquipmentAlarm selectEquipmentAlarmByEquipmentId(String equipmentId) { + return this.baseMapper.selectEquipmentAlarmByEquipmentId(equipmentId); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentLogServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentLogServiceImpl.java new file mode 100644 index 0000000..a6a8a39 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentLogServiceImpl.java @@ -0,0 +1,61 @@ +package org.jeecg.modules.iot.mdc.service.impl; + +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.modules.iot.mdc.entity.EquipmentLog; +import org.jeecg.modules.iot.mdc.mapper.EquipmentLogMapper; +import org.jeecg.modules.iot.mdc.service.IEquipmentLogService; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +/** + * @author: LiuS + * @create: 2023-04-12 14:41 + */ +@Service("EquipmentLogServiceImpl") +public class EquipmentLogServiceImpl extends ServiceImpl<EquipmentLogMapper, EquipmentLog> implements IEquipmentLogService { + + + @Override + public List<EquipmentLog> findEquipmentLogByEndTime(String equipmentId, Date maxDate) { + LambdaQueryChainWrapper<EquipmentLog> lambdaQuery = this.lambdaQuery(); + lambdaQuery.eq(EquipmentLog::getEquipmentId, equipmentId); + if (maxDate != null) { + lambdaQuery.ge(EquipmentLog::getCollectTime, maxDate); + } + lambdaQuery.ne(EquipmentLog::getOporation, 22); + lambdaQuery.ne(EquipmentLog::getOporation, 23); + lambdaQuery.orderByAsc(EquipmentLog::getCollectTime); + return lambdaQuery.list(); + } + + @Override + public List<EquipmentLog> findEquipmentLogByErrorEndTime(String equipmentId, Date endTime) { + LambdaQueryChainWrapper<EquipmentLog> lambdaQuery = this.lambdaQuery(); + lambdaQuery.eq(EquipmentLog::getEquipmentId, equipmentId); + if (endTime != null) { + lambdaQuery.ge(EquipmentLog::getCollectTime, endTime); + } + lambdaQuery.in(EquipmentLog::getOporation, Arrays.asList(0, 22, 23)); + lambdaQuery.orderByAsc(EquipmentLog::getCollectTime); + return lambdaQuery.list(); + } + + @Override + public EquipmentLog getRow(String equipmentid, Date startTime) { + return this.baseMapper.getRow(equipmentid, startTime); + } + + @Override + public EquipmentLog selectEquipmentOporation(String equipmentId) { + return this.baseMapper.selectEquipmentOporation(equipmentId); + } + + @Override + public List<EquipmentLog> getEquipmentStatusList(List<String> equipmentIdList) { + return this.baseMapper.getEquipmentStatusList(equipmentIdList); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentServiceImpl.java new file mode 100644 index 0000000..16e164a --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/EquipmentServiceImpl.java @@ -0,0 +1,48 @@ +package org.jeecg.modules.iot.mdc.service.impl; + +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.modules.iot.mdc.entity.Equipment; +import org.jeecg.modules.iot.mdc.mapper.EquipmentMapper; +import org.jeecg.modules.iot.mdc.service.IEquipmentService; +import org.springframework.stereotype.Service; + +/** + * @Description: 閲囬泦璁惧琛� + * @Author: liuS + * @Date: 2023-03-23 + * @Version: V1.0 + */ +@Service("iotMdcEquipmentServiceImpl") +public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment> implements IEquipmentService { + + @Override + public String checkTableExists(String saveTableName) { + return this.baseMapper.checkTableExists(saveTableName); + } + + @Override + public Integer checkTableDataNum(String saveTableName, String day) { + return this.baseMapper.checkTableDataNum(saveTableName, day); + } + + @Override + public void insertTableData(String backupTableName, String tableName, String day) { + this.baseMapper.insertTableData(backupTableName, tableName, day); + } + + @Override + public void deleteTableData(String tableName, String day) { + this.baseMapper.deleteTableData(tableName, day); + } + + @Override + public void insertNoTableData(String backupTableName, String tableName, String day) { + this.baseMapper.insertNoTableData(backupTableName, tableName, day); + } + + @Override + public Equipment findEquipmentByEquipmentId(String equipmentId) { + return new LambdaQueryChainWrapper<>(baseMapper).eq(Equipment::getEquipmentid,equipmentId).one(); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/MdcDriveTypeParamConfigServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/MdcDriveTypeParamConfigServiceImpl.java new file mode 100644 index 0000000..625f634 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mdc/service/impl/MdcDriveTypeParamConfigServiceImpl.java @@ -0,0 +1,36 @@ +package org.jeecg.modules.iot.mdc.service.impl; + +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.common.constant.CommonConstant; +import org.jeecg.modules.iot.mdc.entity.MdcDriveTypeParamConfig; +import org.jeecg.modules.iot.mdc.mapper.MdcDriveTypeParamConfigMapper; +import org.jeecg.modules.iot.mdc.service.IMdcDriveTypeParamConfigService; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.List; + +/** + * @Description: 椹卞姩鍙傛暟閰嶇疆 + * @Author: jeecg-boot + * @Date: 2023-04-20 + * @Version: V1.0 + */ +@Service("iotMdcDriveTypeParamConfigServiceImpl") +public class MdcDriveTypeParamConfigServiceImpl extends ServiceImpl<MdcDriveTypeParamConfigMapper, MdcDriveTypeParamConfig> implements IMdcDriveTypeParamConfigService { + @Override + public MdcDriveTypeParamConfig selectMdcDriveTypeParamConfigByEquipment(String controlSystemType, String englishName) { + return new LambdaQueryChainWrapper<>(baseMapper) + .eq(MdcDriveTypeParamConfig::getControlSystemType, controlSystemType) + .eq(MdcDriveTypeParamConfig::getEnglishName, englishName).one(); + } + + @Override + public boolean selectEnglishNameByEquipment(String controlSystemType, String englishName) { + Long count = new LambdaQueryChainWrapper<>(baseMapper) + .eq(MdcDriveTypeParamConfig::getControlSystemType, controlSystemType) + .eq(MdcDriveTypeParamConfig::getEnglishName, englishName).count(); + return count > 0; + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/callback/PushCallback.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/callback/PushCallback.java new file mode 100644 index 0000000..e181ebb --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/callback/PushCallback.java @@ -0,0 +1,272 @@ +package org.jeecg.modules.iot.mqtt.callback; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; +import org.eclipse.paho.client.mqttv3.MqttCallback; +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.jeecg.common.util.DateUtils; +import org.jeecg.modules.iot.entity.MqttParameter; +import org.jeecg.modules.iot.entity.ServerDeploy; +import org.jeecg.modules.iot.mqtt.config.MqttConfiguration; +import org.jeecg.modules.iot.mqtt.config.MqttCustomerClient; +import org.jeecg.modules.iot.service.IServerDeployService; +import org.jeecg.modules.message.websocket.WebSocket; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + + +/** + * 娑堣垂鐩戝惉 + * + * @author: cuikaidong + * @create: 2023-09-27 11:36 + */ +@Slf4j +@Component +public class PushCallback implements MqttCallback { + + private static MqttClient client; + @Lazy + @Autowired + private MqttConfiguration mqttConfiguration; + @Autowired + private IServerDeployService serverDeployService; + @Autowired + private WebSocket webSocket; + + @Override + public void connectionLost(Throwable throwable) { + log.error("MQTT杩炴帴宸叉柇寮�", throwable); + + int retryCount = 0; + final long baseDelay = 1000; // 鍒濆寤惰繜1绉� + final long maxDelay = 60000; // 鏈�澶у欢杩�60绉掞紙閬垮厤寤惰繜杩囬暱锛� + final double backoffFactor = 2.0; // 鎸囨暟閫�閬垮洜瀛� + + while (true) { // 鏃犻檺寰幆锛岀洿鍒拌繛鎺ユ垚鍔� + try { + // 璁$畻閫�閬垮欢杩燂紝浣跨敤Math.min纭繚涓嶈秴杩囨渶澶у欢杩� + long delay = (long) Math.min(baseDelay * Math.pow(backoffFactor, retryCount), maxDelay); + if (retryCount > 0) { + log.info("绗瑊}娆¢噸杩炲皾璇曞皢鍦▄}ms鍚庤繘琛�", retryCount + 1, delay); + Thread.sleep(delay); + } + + log.info("寮�濮嬬{}娆¢噸杩炲皾璇�", retryCount + 1); + + MqttCustomerClient mqttCustomerClient = mqttConfiguration.getMqttCustomerClient(); + + // 灏濊瘯杩炴帴 + mqttCustomerClient.connect( + mqttConfiguration.getHost(), + mqttConfiguration.getClientId(), + mqttConfiguration.getUsername(), + mqttConfiguration.getPassword(), + mqttConfiguration.getTimeout(), + mqttConfiguration.getKeepalive() + ); + + // 璁㈤槄涓婚 + log.info("MQTT杩炴帴宸叉仮澶嶏紝姝e湪閲嶆柊璁㈤槄涓婚"); + + List<ServerDeploy> serverDeploys = serverDeployService.list(); + String[] deviceTopics = serverDeploys.stream() + .map(deploy -> "IOT\\" + deploy.getServerCode() + "\\Mutually2") + .toArray(String[]::new); + List<ServerDeploy> newDeploys = new ArrayList<>(); + for (ServerDeploy server : serverDeploys) { + ServerDeploy deploy = new ServerDeploy(); + deploy.setServerCode("IOT/" + server.getServerCode() + "/WriteMessage"); + newDeploys.add(deploy); + } + serverDeploys.addAll(newDeploys); + if (deviceTopics.length > 0) { + mqttCustomerClient.subscribe(deviceTopics); + log.info("宸查噸鏂拌闃厈}涓澶囦富棰�", deviceTopics.length); + } + + String[] systemTopics = {"$SYS/brokers/+/clients/#"}; + mqttCustomerClient.subscribe(systemTopics); + log.info("宸查噸鏂拌闃呯郴缁熶富棰�"); + + log.info("MQTT杩炴帴宸插畬鍏ㄦ仮澶嶏紝鍏卞皾璇晎}娆�", retryCount + 1); + return; // 杩炴帴鍜岃闃呮垚鍔燂紝閫�鍑哄惊鐜� + } catch (Exception e) { + retryCount++; + log.error("绗瑊}娆¢噸杩炲皾璇曞け璐�: {}", retryCount, e.getMessage(), e); + } + } + } + + /** + * mqtt璁㈤槄鏁版嵁 + * + * @param topic + * @param message + * @throws Exception + */ + @Override + public void messageArrived(String topic, MqttMessage message) throws Exception { + // 璁㈤槄鏁版嵁 + // 閫氳繃topic鍖哄垎娑堟伅 + // 鍏抽敭淇敼锛氭樉寮忔寚瀹歎TF-8缂栫爜 + String content = new String(message.getPayload(), StandardCharsets.UTF_8); + JSONObject jsonObject = JSON.parseObject(content); + String clientId = String.valueOf(jsonObject.get("id")); + if (clientId.equals("null")) { + clientId = String.valueOf(jsonObject.get("clientid")); + } + ServerDeploy serverDeploy = serverDeployService.findByServerCode(clientId); + if (serverDeploy == null && !topic.endsWith("WriteMessage")) { + + return; + } + // 瀹㈡埛绔凡鎺夌嚎 + if (topic.endsWith("disconnected")) { + // 淇敼瀹堟姢鍜岄噰闆嗚繛鎺ョ姸鎬� + updateCollectState(topic, serverDeploy); + // 瀹㈡埛绔凡涓婄嚎 + } else if (topic.endsWith("connected")) { + // 淇敼瀹堟姢鍜岄噰闆嗚繛鎺ョ姸鎬� + updateCollectState(topic, serverDeploy); + } else if (topic.endsWith("Mutually2")) { + receiveCollectMessage(jsonObject, serverDeploy); + }else if(topic.endsWith("WriteMessage")) { + parameterWritingMessage(jsonObject); + } + } + + @Override + public void deliveryComplete(IMqttDeliveryToken token) { +// log.info("deliveryComplete---------" + token.isComplete()); + } + + /** + * 淇敼瀹堟姢鍜岄噰闆嗚繛鎺ョ姸鎬� + * + * @param topic + * @param serverDeploy + */ + void updateCollectState(String topic, ServerDeploy serverDeploy) { + JSONObject obj = new JSONObject(); + obj.put("cmd", "collect");//涓氬姟绫诲瀷 + obj.put("id", serverDeploy.getServerCode());//娑堟伅id + if (topic.endsWith("disconnected")) { + serverDeploy.setGuardState(0); + serverDeploy.setCollectState(0); + obj.put("message1", 0); + obj.put("message", 0); + } else { + serverDeploy.setGuardState(1); + obj.put("message1", 1); + } + webSocket.sendAllMessage(obj.toJSONString()); + serverDeployService.updateById(serverDeploy); + } + + /** + * 鍐欏叆娑堟伅瑙f瀽 + * + * @param jsonObject + */ + void parameterWritingMessage(JSONObject jsonObject) { + String deviceID = String.valueOf(jsonObject.get("DeviceID")); + String type = String.valueOf(jsonObject.get("GroupID")); + String id = String.valueOf(jsonObject.get("ID")); + String name = String.valueOf(jsonObject.get("Name")); + String value = String.valueOf(jsonObject.get("Value")); + String state = String.valueOf(jsonObject.get("State")); + String message = String.valueOf(jsonObject.get("Message")); + JSONObject obj = new JSONObject(); + obj.put("cmd", "writing");//涓氬姟绫诲瀷 + obj.put("id", deviceID);//娑堟伅id + obj.put("state", 1); // 姝e父 + if (!message.equals("Write successful!")) { + obj.put("state", 0); // 涓嶆甯� + } + obj.put("message", message); + webSocket.sendAllMessage(obj.toJSONString()); + } + + /** + * 閲囬泦娑堟伅瑙f瀽 + * + * @param jsonObject + */ + void receiveCollectMessage(JSONObject jsonObject, ServerDeploy serverDeploy) { + String clientId = String.valueOf(jsonObject.get("id")); + String type = String.valueOf(jsonObject.get("type")); + String time = String.valueOf(jsonObject.get("time")); + MqttParameter mqttParameter = new MqttParameter(); + String parameter1 = String.valueOf(jsonObject.get("parameter1")); + String parameter2 = String.valueOf(jsonObject.get("parameter2")); + String parameter3 = String.valueOf(jsonObject.get("parameter3")); + String parameter4 = String.valueOf(jsonObject.get("parameter4")); + String parameter5 = String.valueOf(jsonObject.get("parameter5")); + JSONObject obj = new JSONObject(); + obj.put("cmd", type);//涓氬姟绫诲瀷 + obj.put("id", clientId);//娑堟伅id + switch (type) { + // 蹇冭烦鎺ユ敹 + case "palpitate": +// log.info("蹇冭烦鐘舵�佹帴鏀�! 鏈嶅姟鍣ㄥ悕绉�:" + serverDeploy.getServerName() + " 鏃堕棿:" + DateUtils.getTimestamp()); + break; + case "version": + // 灞曠ず閲囬泦杞欢閰嶇疆鏂囦欢鐗堟湰 ,淇敼閲囬泦杞欢鐗堟湰鍙� + if (parameter1 != null && !parameter1.equals("null") && !parameter1.equals("0")) { + obj.put("state", parameter1); + // 閲囬泦杞欢 + serverDeploy.setNewCollectVersion(parameter1); + } + if (parameter2 != null && !parameter2.equals("null") && !parameter2.equals("0")) { + obj.put("message", parameter2); + // 閰嶇疆鏂囦欢 + serverDeploy.setNewDeployVersion(parameter2); + } + serverDeployService.updateById(serverDeploy); + //閲囬泦杞欢娑堟伅鍐呭 + //閰嶇疆鏂囦欢娑堟伅鍐呭 + log.info("瀹堟姢鏈嶅姟杩炴帴鎴愬姛! 鏈嶅姟鍣ㄥ悕绉�:" + serverDeploy.getServerName() + " 鏃堕棿:" + DateUtils.getTimestamp()); + break; + case "log": + // 鏃ュ織 + obj.put("state", parameter4);//娑堟伅鍐呭 + obj.put("message", parameter5);//娑堟伅鍐呭 + log.info("鏃ュ織涓婁紶鎺ユ敹! 鏈嶅姟鍣ㄥ悕绉�:" + serverDeploy.getServerName() + " 鏃堕棿:" + DateUtils.getTimestamp()); + break; + case "start": + // 鍚姩閲囬泦杞欢 + obj.put("state", parameter2); + obj.put("message", parameter3); + int collectState = Integer.parseInt(parameter1); + serverDeploy.setCollectState(collectState); + if (parameter2.equals("1")) { + serverDeployService.updateById(serverDeploy); + } + log.info("鍚姩閲囬泦杞欢鎺ユ敹! 鏈嶅姟鍣ㄥ悕绉�:" + serverDeploy.getServerName() + " 鏃堕棿:" + DateUtils.getTimestamp()); + break; + case "collect": + // 閲囬泦鐘舵�� + obj.put("message", parameter1); + if (!serverDeploy.getCollectState().toString().equals(parameter1)) { + serverDeploy.setCollectState(Integer.parseInt(parameter1)); + serverDeployService.updateById(serverDeploy); + } + log.info("蹇冭烦鈾ラ噰闆嗙姸鎬佹帴鏀�! 鏈嶅姟鍣ㄥ悕绉�:" + serverDeploy.getServerName() + " 鏃堕棿:" + DateUtils.getTimestamp()); + break; + default: + return; + } + if (obj.size() > 2) { + webSocket.sendAllMessage(obj.toJSONString()); + } + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/config/MqttConfiguration.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/config/MqttConfiguration.java new file mode 100644 index 0000000..cd9fb5b --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/config/MqttConfiguration.java @@ -0,0 +1,102 @@ +package org.jeecg.modules.iot.mqtt.config; + + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import okhttp3.Credentials; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.jeecg.modules.iot.entity.MqttClient; +import org.jeecg.modules.iot.entity.ServerDeploy; +import org.jeecg.modules.iot.service.IServerDeployService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * @author: cuikaidong + * @create: 2023-09-27 11:36 + */ +@Component +@Configuration +@Data +public class MqttConfiguration { + + @Lazy + @Autowired + private MqttCustomerClient mqttCustomerClient; + @Autowired + private IServerDeployService serverDeployService; + + @Value("${mqtt.host}") + private String host; + @Value("${mqtt.clientId}") + private String clientId; + @Value("${mqtt.username}") + private String username; + @Value("${mqtt.password}") + private String password; + private String[] topic; + @Value("${mqtt.timeout}") + private int timeout; + @Value("${mqtt.keepalive}") + private int keepalive; + @Value("${mqtt.apiKey}") + private String apiKey; + @Value("${mqtt.secretKey}") + private String secretKey; + @Value("${mqtt.clientUrl}") + private String clientUrl; + + @Bean + public MqttCustomerClient getMqttCustomerClient() { + mqttCustomerClient.connect(host, clientId, username, password, timeout, keepalive); + // 浠�/#缁撳熬琛ㄧず璁㈤槄鎵�鏈変互test寮�澶寸殑涓婚 + List<ServerDeploy> serverDeploys = serverDeployService.list(); + for (ServerDeploy serverDeploy : serverDeploys) { + serverDeploy.setAddress(serverDeploy.getServerCode()); + serverDeploy.setServerCode("IOT\\" + serverDeploy.getServerCode() + "\\Mutually2"); + } + List<ServerDeploy> newDeploys = new ArrayList<>(); + for (ServerDeploy server : serverDeploys) { + ServerDeploy deploy = new ServerDeploy(); + deploy.setServerCode("IOT/" + server.getAddress() + "/WriteMessage"); + newDeploys.add(deploy); + } + ServerDeploy serverDeploy = new ServerDeploy(); + serverDeploy.setServerCode("$SYS/brokers/+/clients/#"); + serverDeploys.add(serverDeploy); + serverDeploys.addAll(newDeploys); + mqttCustomerClient.subscribe(serverDeploys.stream().map(ServerDeploy::getServerCode).distinct() + .toArray(String[]::new)); + // 鏌ヨ瀹㈡埛绔垪琛� + try { + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url(clientUrl) + .header("Content-Type", "application/json") + .header("Authorization", Credentials.basic(apiKey, secretKey)) + .build(); + Response response = client.newCall(request).execute(); + String json = response.body().string(); + JSONObject jsonObject = JSON.parseObject(json); + String data = String.valueOf(jsonObject.get("data")); + List<MqttClient> studentList = JSONObject.parseArray(data, MqttClient.class); + serverDeployService.updateServerGuardState(studentList); + } catch (IOException e) { + e.printStackTrace(); + } + return mqttCustomerClient; + } + +} \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/config/MqttCustomerClient.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/config/MqttCustomerClient.java new file mode 100644 index 0000000..92b9cda --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/mqtt/config/MqttCustomerClient.java @@ -0,0 +1,179 @@ +package org.jeecg.modules.iot.mqtt.config; + +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.paho.client.mqttv3.*; +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; +import org.jeecg.modules.iot.entity.MqttParameter; +import org.jeecg.modules.iot.mqtt.callback.PushCallback; +import org.jeecg.modules.iot.util.DispatchUtil; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * mqtt瀹㈡埛绔� + * + * @author: cuikaidong + * @create: 2023-09-27 11:36 + */ +@Slf4j +@Component +public class MqttCustomerClient { + + @Resource + private PushCallback pushCallback; + + + private static MqttClient client; + + public static MqttClient getClient() { + return client; + } + + public static void setClient(MqttClient client) { + MqttCustomerClient.client = client; + } + + /** + * 瀹㈡埛绔繛鎺� + * + * @param host ip+绔彛 + * @param clientID 瀹㈡埛绔疘d + * @param username 鐢ㄦ埛鍚� + * @param password 瀵嗙爜 + * @param timeout 瓒呮椂鏃堕棿 + * @param keeplive 淇濈暀鏁� + */ + public void connect(String host, String clientID, String username, String password, int timeout, int keeplive) { + MqttClient client; + + try { + client = new MqttClient(host, clientID, new MemoryPersistence()); + MqttConnectOptions options = new MqttConnectOptions(); + options.setCleanSession(true); + options.setUserName(username); + options.setPassword(password.toCharArray()); + options.setConnectionTimeout(timeout); + options.setKeepAliveInterval(keeplive); + MqttCustomerClient.setClient(client); + try { + client.setCallback(pushCallback); + client.connect(options); + } catch (Exception e) { + e.printStackTrace(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 鍙戝竷锛岄粯璁os涓�0锛岄潪鎸佷箙鍖� + * + * @param topic + * @param mqttParameter + */ + public void pushlish(String topic, MqttParameter mqttParameter) { + pushlish(0, false, topic, mqttParameter); + } + + /** + * 鍙戝竷 + * + * @param qos 杩炴帴鏂瑰紡 + * @param retained 鏄惁淇濈暀 + * @param topic 涓婚 + * @param mqttParameter 鍙傛暟瀵硅薄 + */ + public void pushlish(int qos, boolean retained, String topic, MqttParameter mqttParameter) { + topic = "IOT\\" + topic + "\\Mutually1"; + Map<String, String> map = new LinkedHashMap<>(); + map.put("id", mqttParameter.getId()); + map.put("type", mqttParameter.getType()); + LocalDateTime now = LocalDateTime.now(); + DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + map.put("time", now.format(formatter2)); + map.put("parameter1", mqttParameter.getParameter1()); + map.put("parameter2", mqttParameter.getParameter2()); + map.put("parameter3", mqttParameter.getParameter3()); + map.put("parameter4", mqttParameter.getParameter4()); + map.put("parameter5", mqttParameter.getParameter5()); + Object json = JSONObject.toJSON(map); + String pushMessage = DispatchUtil.replaceBlank(json.toString()); + MqttMessage message = new MqttMessage(); + message.setQos(qos); + message.setRetained(retained); + message.setPayload(pushMessage.getBytes()); + MqttTopic mqttTopic = MqttCustomerClient.getClient().getTopic(topic); + if (null == mqttTopic) { + log.error("topic not exist"); + } + MqttDeliveryToken token; + try { + token = mqttTopic.publish(message); + token.waitForCompletion(); + } catch (MqttPersistenceException e) { + e.printStackTrace(); + } catch (MqttException e) { + e.printStackTrace(); + // 閲嶈繛 + pushCallback.connectionLost(null); + } + } + /** + * 鍙傛暟鍐欏叆鍙戝竷 + * + * @param qos 杩炴帴鏂瑰紡 + * @param retained 鏄惁淇濈暀 + * @param topic 涓婚 + * @param map 鍙傛暟 + */ + public void pushlishWriting(int qos, boolean retained, String topic, Map<String, Object> map) { + Object json = JSONObject.toJSON(map); + String pushMessage = DispatchUtil.replaceBlank(json.toString()); + MqttMessage message = new MqttMessage(); + message.setQos(qos); + message.setRetained(retained); + message.setPayload(pushMessage.getBytes(StandardCharsets.UTF_8)); + MqttTopic mqttTopic = MqttCustomerClient.getClient().getTopic(topic); + if (null == mqttTopic) { + log.error("topic not exist"); + } + MqttDeliveryToken token; + try { + token = mqttTopic.publish(message); + token.waitForCompletion(); + } catch (MqttPersistenceException e) { + e.printStackTrace(); + } catch (MqttException e) { + e.printStackTrace(); + // 閲嶈繛 + pushCallback.connectionLost(null); + } + } + /** + * 璁㈤槄鏌愪釜涓婚锛宷os涓�0 + * + * @param topic + */ + public void subscribe(String[] topic) { + log.info("寮�濮嬭闃呬富棰�" + Arrays.toString(topic)); + try { + int[] qos = new int[topic.length]; + for (int i = 0; i < topic.length; i++) { + qos[i] = 2; + } + MqttCustomerClient.getClient().subscribe(topic, qos); + } catch (MqttException e) { + e.printStackTrace(); + } + } + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IControlSystemService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IControlSystemService.java new file mode 100644 index 0000000..c1f120c --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IControlSystemService.java @@ -0,0 +1,13 @@ +package org.jeecg.modules.iot.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.iot.entity.ControlSystem; + +/** + * @Description: 鎺у埗绯荤粺淇℃伅 + * @Author: cuikaidong + * @Date: 2025-6-3 + * @Version: V1.0 + */ +public interface IControlSystemService extends IService<ControlSystem> { +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IEmptyParameterService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IEmptyParameterService.java new file mode 100644 index 0000000..b03e3fd --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IEmptyParameterService.java @@ -0,0 +1,84 @@ +package org.jeecg.modules.iot.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.iot.entity.EmptyParameter; + +import java.util.List; +import java.util.Set; + +/** + * @Description: 铏氳澶囧弬鏁� + * @Author: cuikaidong + * @Date: 2025-1-7 + * @Version: V1.0 + */ +public interface IEmptyParameterService extends IService<EmptyParameter> { + /** + * 娣诲姞铏氳澶囧弬鏁� + * + * @param emptyParameter + */ + Result<?> addEmptyParameter(EmptyParameter emptyParameter); + /** + * 鎵归噺铏氳澶囧弬鏁� + * + * @param emptyParameterList + */ + Result<?> addBatchEmptyParameter(List<EmptyParameter> emptyParameterList); + /** + * 缂栬緫铏氳澶囧弬鏁� + * + * @param emptyParameter + */ + void editEmptyParameter(EmptyParameter emptyParameter); + + /** + * 閫氳繃id鍒犻櫎铏氳澶囧弬鏁� + * + * @param id + */ + void deleteEmptyParameter(String id); + + /** + * 鏍规嵁璁惧ids锛屾煡璇㈠弬鏁板垪琛� + * + * @param ids + * @return + */ + List<EmptyParameter> findParameterByEquipmentIds(Set<String> ids); + + /** + * 鑴氭湰缂栬瘧 + * + * @param emptyParameter + */ + Result<?> handleCompile(EmptyParameter emptyParameter); + + /** + * 淇濆瓨鑴氭湰 + * + * @param emptyParameter + */ + Result<?> preserveScript(EmptyParameter emptyParameter); + + /** + * 鏍规嵁璁惧id鏌ヨ璁惧涓嬫湁澶氬皯涓弬鏁� + * + * @param equipmentId + * @return + */ + Integer findEmptyParameterCode(String equipmentId); + + /** + * 鏌ヨ铏氳澶囦笅鍙傛暟鍚嶇О鏄惁閲嶅 + * + * @return + */ + Boolean findEmptyParameterByName(EmptyParameter emptyParameter); + + /** + * 鏍规嵁鐢熸垚閰嶇疆鏃堕棿锛屽垱寤哄搴旂殑瀛楁 + */ + void createEmptyEmptyField(java.util.Date deployDate, String serverId); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IEquipmentService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IEquipmentService.java new file mode 100644 index 0000000..90300cf --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IEquipmentService.java @@ -0,0 +1,124 @@ +package org.jeecg.modules.iot.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.iot.entity.Equipment; +import org.jeecg.modules.iot.entity.xmlEntity.*; +import org.jeecg.modules.iot.entity.xmlEntity.script.FunctionEntity; + +import javax.xml.crypto.Data; +import java.util.List; + +/** + * @Description: 璁惧 + * @Author: cuikaidong + * @Date: 2024-12-23 + * @Version: V1.0 + */ +public interface IEquipmentService extends IService<Equipment> { + + /** + * 鏌ヨ绯荤粺绫诲瀷鍒楄〃 + * + * @return + */ + List<SystemType> findProjectCode(); + + /** + * 鏍规嵁鏈嶅姟鍣╥d鏌ヨ璁惧璁㈤槄鍒楄〃 + * + * @return + */ + Object[] queryEquipmentSubscribeList(String id); + + /** + * 鏍规嵁绯荤粺绫诲瀷鏌ヨ鎺у埗绯荤粺鍒楄〃 + */ + List<ControlSystem> findControlSystems(String type); + + /** + * 鏌ヨ瀛楄妭椤哄簭鍒楄〃 + */ + List<ByteOrder> findByteOrder(); + + /** + * 鏌ヨ鍙傛暟绫诲瀷鍒楄〃 + */ + List<SystemDataType> findSystemDataTypeList(); + + /** + * 鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧閲囬泦鍙傛暟 + */ + List<Parameter> findParameterById(String id); + + /** + * 鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧鑷畾涔夐噰闆嗗弬鏁� + */ + List<Parameter> findParameterCustomizeById(String id); + + /** + * 鏍规嵁鍙傛暟缁刬d鏌ヨ璁惧閲囬泦鍙傛暟绫诲瀷 + */ + List<Parameter> findDataTypeById(String id); + + /** + * 鏍规嵁鏈嶅姟鍣╥d鏌ヨ璁惧鍒楄〃 + * + * @return + */ + List<Equipment> findEquipmentByServerId(String id); + + /** + * 鏌ヨ褰撳墠鏈嶅姟鍣ㄤ笅璁惧鍚嶇О鏄惁閲嶅 + * type 1 瀹炶澶囷紝0铏氳澶� + * + * @return + */ + Boolean findEquipmentByName(Equipment equipment, Integer type); + + /** + * 鏌ヨ褰撳墠鏈嶅姟鍣ㄤ笅璁惧缂栧彿鏄惁閲嶅 + * + * @return + */ + Boolean findEquipmentByCode(Equipment equipment); + + /** + * 鏌ヨ鍑芥暟淇℃伅 + */ + List<FunctionEntity> findFunctionInformationList(String functionType); + + /** + * 鏍规嵁鐢熸垚閰嶇疆鏃堕棿锛屽垱寤哄搴旂殑琛� + */ + void createEmptyEquipmentTable(java.util.Date deployDate, String serverId); + + /** + * 铏氳澶囨坊鍔� + * + * @param equipment + * @return + */ + Result<?> addEmpty(Equipment equipment); + + /** + * 鏍规嵁璁惧缂栫爜鏌ヨ璁惧淇℃伅 + * + * @return + */ + Equipment findEquipmentByCode(String id); + + /** + * 鍐欏叆influxdb鏁版嵁 + * + * @return + */ + void insertSqlServerData(String tableName, String[] columns, Object[] values); + + /** + * 鍐欏叆influxdb鏁版嵁 + * + * @return + */ + void insertMySqlData(String tableName, String[] columns, Object[] values); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IInfluxdbDeployService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IInfluxdbDeployService.java new file mode 100644 index 0000000..7a580d9 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IInfluxdbDeployService.java @@ -0,0 +1,33 @@ +package org.jeecg.modules.iot.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.iot.entity.InfluxdbDeploy; + +import java.util.List; +import java.util.Set; + +/** + * @Description: Influxdb閰嶇疆 + * @Author: cuikaidong + * @Date: 2024-12-10 + * @Version: V1.0 + */ +public interface IInfluxdbDeployService extends IService<InfluxdbDeploy> { + + /** + * 鏍规嵁鏈嶅姟鍣╥ds鏌ヨ + * + * @param serverIds + * @return + */ + List<InfluxdbDeploy> findByServerIdsInfluxdbDeploy(Set<String> serverIds); + + /** + * 鏍规嵁鏈嶅姟鍣╥d鏌ヨinfluxdb閰嶇疆淇℃伅 + * + * @param id 鏈嶅姟鍣╥d + * @return + */ + InfluxdbDeploy findByServerIdInfluxdb(String id); + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IMqttDeployService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IMqttDeployService.java new file mode 100644 index 0000000..33a538f --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IMqttDeployService.java @@ -0,0 +1,31 @@ +package org.jeecg.modules.iot.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.iot.entity.MqttDeploy; + +import java.util.List; +import java.util.Set; + +/** + * @Description: Mqtt閰嶇疆 + * @Author: cuikaidong + * @Date: 2024-12-10 + * @Version: V1.0 + */ +public interface IMqttDeployService extends IService<MqttDeploy> { + /** + * 鏍规嵁鏈嶅姟鍣╥ds鏌ヨ + * + * @param serverIds + * @return + */ + List<MqttDeploy> findByServerIdsMqttDeploy(Set<String> serverIds); + + /** + * 鏍规嵁鏈嶅姟鍣╥d鏌ヨmqtt閰嶇疆淇℃伅 + * + * @param id 鏈嶅姟鍣╥d + * @return + */ + MqttDeploy findByServerIdMqttDeploy(String id); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IParameterGroupService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IParameterGroupService.java new file mode 100644 index 0000000..819e6fd --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IParameterGroupService.java @@ -0,0 +1,47 @@ +package org.jeecg.modules.iot.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.iot.entity.Equipment; +import org.jeecg.modules.iot.entity.ParameterGroup; + +import java.util.List; + +/** + * @Description: 鍙傛暟缁� + * @Author: cuikaidong + * @Date: 2024-12-31 + * @Version: V1.0 + */ +public interface IParameterGroupService extends IService<ParameterGroup> { + + /** + * 鏍规嵁鏈嶅姟鍣╥d鏌ヨ鍙傛暟缁勪俊鎭� + * + * @param serverDeployId + * @return + */ + List<ParameterGroup> findParameterGroupByServerId(String serverDeployId); + + /** + * 鏌ヨ褰撳墠璁惧涓嬪弬鏁扮粍鍚嶇О鏄惁閲嶅 + * + * @return + */ + Boolean findParameterGroupByName(ParameterGroup parameterGroup); + + /** + * 鏌ヨ褰撳墠璁惧涓嬪弬鏁扮粍缂栧彿鏄惁閲嶅 + * + * @return + */ + Boolean findParameterGroupByCode(ParameterGroup parameterGroup); + + /** + * 鏂板鍙傛暟缁� + * + * @param parameterGroup + * @return + */ + Result<?> addParameterGroup(ParameterGroup parameterGroup); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IProjectClassifyService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IProjectClassifyService.java new file mode 100644 index 0000000..0f3afbf --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IProjectClassifyService.java @@ -0,0 +1,35 @@ +package org.jeecg.modules.iot.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.iot.entity.ProjectClassify; + +/** + * @Description: 椤圭洰鍒嗙被 + * @Author: cuikaidong + * @Date: 2024-12-20 + * @Version: V1.0 + */ +public interface IProjectClassifyService extends IService<ProjectClassify> { + + /** + * 鏍规嵁椤圭洰缂栧彿鍒犻櫎椤圭洰 + * + * @param projectCode + */ + String projectClassifyRemoveById(String projectCode); + + /** + * 娣诲姞椤圭洰鍒嗙被 + * + * @param projectClassify + */ + void addProjectClassify(ProjectClassify projectClassify); + + /** + * 閫氳繃椤圭洰缂栫爜鏌ヨ + * + * @param projectCode + */ + ProjectClassify findByProjectCode(String projectCode); + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IRealParameterService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IRealParameterService.java new file mode 100644 index 0000000..47e184b --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IRealParameterService.java @@ -0,0 +1,107 @@ +package org.jeecg.modules.iot.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import io.lettuce.core.dynamic.annotation.Param; +import org.apache.poi.ss.formula.functions.T; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.iot.entity.ParameterGroup; +import org.jeecg.modules.iot.entity.RealParameter; +import org.jeecg.modules.iot.entity.ServerDeploy; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @Description: 瀹炶澶囧弬鏁� + * @Author: cuikaidong + * @Date: 2025-1-2 + * @Version: V1.0 + */ +public interface IRealParameterService extends IService<RealParameter> { + + /** + * 鏍规嵁鍙傛暟缂栫爜鏌ヨ鍙傛暟淇℃伅 + * + * @param parameterCode + * @return + */ + RealParameter findByParameterCode(String parameterCode); + + /** + * 鏍规嵁鍙傛暟缁刬ds锛屾煡璇㈠弬鏁板垪琛� + * + * @param ids + * @return + */ + List<RealParameter> findRealParameterByIds(Set<String> ids); + + /** + * 鍒嗛〉鏌ヨ瀹炶澶囧弬鏁板垪琛� + * + * @param pages + * @param params + * @return + */ + IPage<RealParameter> findRealParameterPage(Page<RealParameter> pages, @Param("params") Map<String, Object> params); + + /** + * 鏌ヨ褰撳墠鍙傛暟缁勪笅鍙傛暟鍚嶇О鏄惁閲嶅 + * + * @return + */ + Boolean findRealParameterByName(RealParameter realParameter); + + /** + * 鏌ヨ褰撳墠鍙傛暟缁勪笅鍙傛暟缂栧彿鏄惁閲嶅 + * + * @return + */ + Boolean findRealParameterByCode(RealParameter realParameter); + + + /** + * 瀹炶澶囧弬鏁板啓鍏� + * + * @param realParameter + * @return + */ + Result<?> parameterWriting(RealParameter realParameter); + + /** + * 閫氳繃excel瀵煎叆鏁版嵁 + * + * @param request + * @param response + * @return + */ + Result<?> importExcel(HttpServletRequest request, HttpServletResponse response); + + /** + * 瀵煎嚭excel + * + * @param request + */ + ModelAndView exportXls(HttpServletRequest request, RealParameter realParameter, String title); + + /** + * 鏍规嵁鍙傛暟缁勭紪鍙锋煡璇㈡渶鍚庝竴涓弬鏁扮紪鍙� + * + * @param groupId + * @return + */ + Integer findRealParameterGroupId(String groupId); + + /** + * 鏍规嵁鍙傛暟缁刬d鎵归噺瀵煎叆鏍囧噯鍙傛暟 + * @param id + * @return + */ + Result<?> canonicalParameter(String id); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IServerDeployService.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IServerDeployService.java new file mode 100644 index 0000000..a2894fa --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/IServerDeployService.java @@ -0,0 +1,46 @@ +package org.jeecg.modules.iot.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.iot.entity.MqttClient; +import org.jeecg.modules.iot.entity.ServerDeploy; + +import java.util.List; + +/** + * @Description: 鏈嶅姟鍣� + * @Author: cuikaidong + * @Date: 2024-12-20 + * @Version: V1.0 + */ +public interface IServerDeployService extends IService<ServerDeploy> { + + /** + * 鏍规嵁鏈嶅姟鍣ㄧ紪鍙锋煡璇㈡湇鍔″櫒淇℃伅 + * + * @param serverCode + */ + ServerDeploy findByServerCode(String serverCode); + + /** + * 鏍规嵁椤圭洰id鏌ヨ鏈嶅姟鍣ㄤ俊鎭� + * + * @param id + */ + List<ServerDeploy> findByProjectClassifyId(String id); + + /** + * 鏍规嵁mqtt瀹㈡埛绔痠d锛屾壒閲忎慨鏀瑰畧鎶ょ▼搴忕姸鎬� + * + * @param mqttClient + */ + void updateServerGuardState(List<MqttClient> mqttClient); + + /** + * 鏍规嵁鏈嶅姟鍣╥d鐢熸垚閰嶇疆鏂囦欢 + * + * @param id + * @return + */ + Result<?> addDeployDocument(String id); +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ControlSystemServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ControlSystemServiceImpl.java new file mode 100644 index 0000000..1f08442 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ControlSystemServiceImpl.java @@ -0,0 +1,18 @@ +package org.jeecg.modules.iot.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.modules.iot.entity.ControlSystem; +import org.jeecg.modules.iot.mapper.ControlSystemMapper; +import org.jeecg.modules.iot.service.IControlSystemService; +import org.springframework.stereotype.Service; + +/** + * @Description: 鎺у埗绯荤粺淇℃伅 + * @Author: cuikaidong + * @Date: 2025-6-3 + * @Version: V1.0 + */ +@Service("iotControlSystemServiceImpl") +public class ControlSystemServiceImpl extends ServiceImpl<ControlSystemMapper, ControlSystem> implements IControlSystemService { + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/EmptyParameterServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/EmptyParameterServiceImpl.java new file mode 100644 index 0000000..39a6577 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/EmptyParameterServiceImpl.java @@ -0,0 +1,639 @@ +package org.jeecg.modules.iot.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.commons.collections.CollectionUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.iot.depository.DbConfig; +import org.jeecg.modules.iot.depository.MysqlDataWriter; +import org.jeecg.modules.iot.entity.*; +import org.jeecg.modules.iot.mapper.EmptyParameterMapper; +import org.jeecg.modules.iot.mapper.RealParameterMapper; +import org.jeecg.modules.iot.mdc.entity.MdcDriveTypeParamConfig; +import org.jeecg.modules.iot.mdc.service.IMdcDriveTypeParamConfigService; +import org.jeecg.modules.iot.service.IEmptyParameterService; +import org.jeecg.modules.iot.service.IEquipmentService; +import org.jeecg.modules.iot.service.IServerDeployService; +import org.jeecg.modules.iot.util.AESUtil; +import org.jeecg.modules.iot.util.HttpClientUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import javax.sql.DataSource; +import java.sql.*; +import java.util.*; +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * @Description: 铏氳澶囧弬鏁� + * @Author: cuikaidong + * @Date: 2025-1-7 + * @Version: V1.0 + */ +@Service +public class EmptyParameterServiceImpl extends ServiceImpl<EmptyParameterMapper, EmptyParameter> implements IEmptyParameterService { + @Value("${databaseType}") + private String databaseType; + @Value("${ftp.address}") + private String ftpAddress; + @Resource + private RealParameterMapper realParameterMapper; + @Autowired + private IEquipmentService equipmentService; + @Autowired + private IServerDeployService serverDeployService; + @Autowired + private DataSource dataSource; + @Autowired + private IMdcDriveTypeParamConfigService driveTypeParamConfigService; + + @Override + @Transactional(rollbackFor = Exception.class) + public Result<?> addEmptyParameter(EmptyParameter emptyParameter) { + // 楠岃瘉缂栫爜鍚嶇О鏄惁閲嶅 + if (findEmptyParameterByName(emptyParameter)) { + return Result.error("鍙傛暟鍚嶇О宸插瓨鍦紒"); + } + emptyParameter.setParameterCode(findEmptyParameterCode(emptyParameter.getEquipmentId())); + emptyParameter.setDataLength("1"); + baseMapper.insert(emptyParameter); + + // 鏌ヨ璁惧淇℃伅 + Equipment equipment = equipmentService.getById(emptyParameter.getEquipmentId()); + if (equipment == null) { + return Result.error("璁惧淇℃伅涓嶅瓨鍦紒"); + } + // 楠岃瘉mdc鏄惁瀛樺湪椹卞姩鍙傛暟 + boolean englishNameBoolean = driveTypeParamConfigService.selectEnglishNameByEquipment(equipment.getControlSystem(), emptyParameter.getParameterName()); + if (!englishNameBoolean) { + // 缁檓dc鍐欏叆椹卞姩鍙傛暟 + MdcDriveTypeParamConfig mdcDriveTypeParamConfig = new MdcDriveTypeParamConfig(); + mdcDriveTypeParamConfig.setControlSystemType(equipment.getControlSystem()); + mdcDriveTypeParamConfig.setEnglishName(emptyParameter.getParameterName()); + mdcDriveTypeParamConfig.setChineseName(emptyParameter.getParameterDescribe()); + mdcDriveTypeParamConfig.setShowFlag("Y"); + mdcDriveTypeParamConfig.setCurveGenerationFlags("N"); + driveTypeParamConfigService.save(mdcDriveTypeParamConfig); + } + return Result.ok("娣诲姞鎴愬姛锛�"); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result<?> addBatchEmptyParameter(List<EmptyParameter> emptyParameters) { + Integer parameterCode = findEmptyParameterCode(emptyParameters.get(0).getEquipmentId()); + final int[] code = {parameterCode - 1}; + for (EmptyParameter e : emptyParameters) { + code[0] = code[0] + 1; + e.setParameterCode(code[0]); + // 楠岃瘉缂栫爜鍚嶇О鏄惁閲嶅 + if (findEmptyParameterByName(e)) { + return Result.error(e.getParameterName() + "鍙傛暟鍚嶇О宸插瓨鍦紒"); + } + } + this.saveBatch(emptyParameters); + // 鏌ヨ璁惧淇℃伅 + Equipment equipment = equipmentService.getById(emptyParameters.get(0).getEquipmentId()); + if (equipment == null) { + return Result.error("璁惧淇℃伅涓嶅瓨鍦紒"); + } + List<MdcDriveTypeParamConfig> driveTypeParamConfigs = new ArrayList<>(); + for (EmptyParameter emptyParameter : emptyParameters) { + // 楠岃瘉mdc鏄惁瀛樺湪椹卞姩鍙傛暟 + boolean englishNameBoolean = driveTypeParamConfigService.selectEnglishNameByEquipment(equipment.getControlSystem(), emptyParameter.getParameterName()); + if (!englishNameBoolean) { + // 缁檓dc鍐欏叆椹卞姩鍙傛暟 + MdcDriveTypeParamConfig mdcDriveTypeParamConfig = new MdcDriveTypeParamConfig(); + mdcDriveTypeParamConfig.setControlSystemType(equipment.getControlSystem()); + mdcDriveTypeParamConfig.setEnglishName(emptyParameter.getParameterName()); + mdcDriveTypeParamConfig.setChineseName(emptyParameter.getParameterDescribe()); + mdcDriveTypeParamConfig.setShowFlag("Y"); + mdcDriveTypeParamConfig.setCurveGenerationFlags("N"); + driveTypeParamConfigs.add(mdcDriveTypeParamConfig); + } + } + if (driveTypeParamConfigs.size() > 0) { + driveTypeParamConfigService.saveBatch(driveTypeParamConfigs); + } + return Result.ok("鎵归噺娣诲姞鎴愬姛锛�"); + } + + @Override + public void editEmptyParameter(EmptyParameter emptyParameter) { + // 鏌ヨ璁惧淇℃伅 + Equipment equipment = equipmentService.getById(emptyParameter.getEquipmentId()); + emptyParameter.setCreateTime(new Date()); + EmptyParameter emptyParameter1 = baseMapper.selectById(emptyParameter.getId()); + baseMapper.updateById(emptyParameter); + if (!emptyParameter1.getParameterName().equals(emptyParameter.getParameterName())) { + MdcDriveTypeParamConfig mdcDriveTypeParamConfig = driveTypeParamConfigService.selectMdcDriveTypeParamConfigByEquipment(equipment.getControlSystem(), emptyParameter1.getParameterName()); + mdcDriveTypeParamConfig.setEnglishName(emptyParameter.getParameterName()); + driveTypeParamConfigService.updateById(mdcDriveTypeParamConfig); + } + } + + @Override + public void deleteEmptyParameter(String id) { + EmptyParameter emptyParameter = baseMapper.selectById(id); + if (emptyParameter.getType().equals("0")) { + //鍒犻櫎铏氳澶囨椂璋冪敤` + Map<String, String> param = new HashMap<>(); + Equipment equipment = equipmentService.getById(emptyParameter.getEquipmentId()); + ServerDeploy serverDeploy = serverDeployService.getById(equipment.getServerId()); + param.put("path", ftpAddress + serverDeploy.getServerCode() + "/script"); + HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/ProjectPath", param); + param.clear(); + param.put("deviceid", emptyParameter.getEquipmentId()); + + param.put("id", equipment.getEqptName()); + HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/DeleteParameterScript", param); + } + baseMapper.deleteById(id); + // 鏌ヨ璁惧淇℃伅 + Equipment equipment = equipmentService.getById(emptyParameter.getEquipmentId()); + // 鍒犻櫎mdc璁惧鍙傛暟淇℃伅 + MdcDriveTypeParamConfig mdcDriveTypeParamConfig = driveTypeParamConfigService.selectMdcDriveTypeParamConfigByEquipment(equipment.getControlSystem(), emptyParameter.getParameterName()); + if (mdcDriveTypeParamConfig != null) { + driveTypeParamConfigService.removeById(mdcDriveTypeParamConfig); + } + } + + @Override + public List<EmptyParameter> findParameterByEquipmentIds(Set<String> ids) { + return new LambdaQueryChainWrapper<>(baseMapper).in(EmptyParameter::getEquipmentId, ids).list(); + } + + @Override + public Result<?> handleCompile(EmptyParameter emptyParameter) { + Map<String, String> referenceInfo = new HashMap<>(); + // 楠岃瘉鑴氭湰瀹炶澶� + List<String> attributes = new ArrayList<>(getAttributes(emptyParameter.getScript(), "IOT_[\\p{L}\\p{N}_]+_[\\p{L}\\p{N}_]+_[\\p{L}\\p{N}_]+")); + if (!attributes.isEmpty()) { + List<RealParameter> realParameterList = realParameterMapper.findRealParameterList(attributes); + // 鍒ゆ柇瀹炶澶囧弬鏁版暟閲忔槸鍚︾浉绛� + if (attributes.size() != realParameterList.size()) { + // 姹傚樊闆� + Set<String> difference1 = new HashSet<>(attributes); + // 浣跨敤 Stream API 灏� name 瀛楁杞崲涓� Set<String> + Set<String> difference2 = realParameterList.stream() + .map(RealParameter::getAddress).collect(Collectors.toSet()); + difference1.removeAll(difference2); + return Result.error(difference1 + "灞炴�ф湁璇紒锛侊紒"); + } + realParameterList.forEach(r -> { + if (r.getSystemDataType().isEmpty()) { + referenceInfo.put(r.getAddress(), r.getParameterType()); + } else { + referenceInfo.put(r.getAddress(), r.getSystemDataType()); + } + }); + } + // 楠岃瘉铏氳澶� + List<String> empAttributes = new ArrayList<>(getAttributes(emptyParameter.getScript(), "IOT_[\\p{L}\\p{N}_]+_[\\p{L}\\p{N}_]+")); + if (!empAttributes.isEmpty()) { + List<EmptyParameter> emptyParameterList = new ArrayList<>(); + Set<String> difference = new HashSet<>(empAttributes); + if (!attributes.isEmpty()) { + // 姹傚樊闆� + difference.removeAll(attributes); + List<String> www = new ArrayList<>(difference); + // 鏌ヨ鏁版嵁搴撲腑鍖归厤鐨勬暟閲� + if (!www.isEmpty()) { + emptyParameterList = baseMapper.findEmptyParameterList(www); + } + } else { + emptyParameterList = baseMapper.findEmptyParameterList(empAttributes); + } + // 浣跨敤 HashSet 鍘婚噸 + Set<EmptyParameter> personSet = new HashSet<>(emptyParameterList); + // 鍒ゆ柇铏氳澶囧弬鏁版暟閲忔槸鍚︾浉绛� + if (difference.size() != personSet.size()) { + // 姹傚樊闆� + Set<String> difference1 = new HashSet<>(difference); + // 浣跨敤 Stream API 灏� name 瀛楁杞崲涓� Set<String> + Set<String> difference2 = personSet.stream() + .map(EmptyParameter::getAddress).collect(Collectors.toSet()); + difference1.removeAll(difference2); + return Result.error(difference1 + "灞炴�ф湁璇紒锛侊紒"); + } + personSet.forEach(p -> { + if (p.getSystemDataType().isEmpty()) { + referenceInfo.put(p.getAddress(), p.getParameterType()); + } else { + referenceInfo.put(p.getAddress(), p.getSystemDataType()); + } + }); + } + // --------AES_CBC鍔犲瘑--------- + String cbcResult = AESUtil.encryptCBC(emptyParameter.getScript(), "xhVs6DRXLfUGxw+AhtfQdpQGoa+8SA9d"); + try { + ScriptCompilation scriptCompilation = new ScriptCompilation(); + Equipment equipment = equipmentService.getById(emptyParameter.getEquipmentId()); + scriptCompilation.setDeviceId(equipment.getEqptCode()); + scriptCompilation.setParameterCode(cbcResult); + scriptCompilation.setParameterDataType(emptyParameter.getParameterType()); + scriptCompilation.setParameterName(emptyParameter.getParameterName()); + scriptCompilation.setReferenceinfo(referenceInfo); + String jsonPayload = JSONObject.toJSONString(scriptCompilation); + + // 鍒涘缓 HttpClient 瀹炰緥 + HttpClient httpClient = HttpClients.createDefault(); + // 鍒涘缓 HttpPost 璇锋眰瀹炰緥 + HttpPost httpPost = new HttpPost("http://localhost:3002/ScriptCompiler/ScriptCompiler"); + // 璁剧疆璇锋眰澶达紝鎸囧畾鍐呭绫诲瀷涓� JSON锛岀紪鐮佷负 UTF-8 + httpPost.setHeader("Content-Type", "application/json; charset=UTF-8"); + + // 鍒涘缓 StringEntity 骞舵寚瀹氱紪鐮佷负 UTF-8 + StringEntity entity = new StringEntity(jsonPayload, "UTF-8"); + httpPost.setEntity(entity); + + // 鎵ц璇锋眰骞惰幏鍙栧搷搴� + HttpResponse response = httpClient.execute(httpPost); + // 鑾峰彇鍝嶅簲瀹炰綋鍐呭 + String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8"); + boolean isContain = responseBody.contains("缂栬瘧鎴愬姛"); + if (isContain) { + return Result.ok(responseBody); + } else { + // 杈撳嚭鍝嶅簲鍐呭 + return Result.error(responseBody); + } + } catch (Exception e) { + e.printStackTrace(); + } + return Result.error("缂栬瘧澶辫触"); + } + + @Override + public Result<?> preserveScript(EmptyParameter emptyParameter) { + Map<String, String> referenceInfo = new HashMap<>(); + // 楠岃瘉鑴氭湰瀹炶澶� + List<String> attributes = new ArrayList<>(getAttributes(emptyParameter.getScript(), "IOT_[\\p{L}\\p{N}_]+_[\\p{L}\\p{N}_]+_[\\p{L}\\p{N}_]+")); + if (!attributes.isEmpty()) { + List<RealParameter> realParameterList = realParameterMapper.findRealParameterList(attributes); + realParameterList.forEach(r -> { + if (r.getSystemDataType().isEmpty()) { + referenceInfo.put(r.getAddress(), r.getParameterType()); + } else { + referenceInfo.put(r.getAddress(), r.getSystemDataType()); + } + }); + } + // 楠岃瘉铏氳澶� + List<String> empAttributes = new ArrayList<>(getAttributes(emptyParameter.getScript(), "IOT_[\\p{L}\\p{N}_]+_[\\p{L}\\p{N}_]+")); + if (!empAttributes.isEmpty()) { + List<EmptyParameter> emptyParameterList = new ArrayList<>(); + Set<String> difference = new HashSet<>(empAttributes); + if (!attributes.isEmpty()) { + // 姹傚樊闆� + difference.removeAll(attributes); + List<String> www = new ArrayList<>(difference); + // 鏌ヨ鏁版嵁搴撲腑鍖归厤鐨勬暟閲� + if (!www.isEmpty()) { + emptyParameterList = baseMapper.findEmptyParameterList(www); + } + } else { + emptyParameterList = baseMapper.findEmptyParameterList(empAttributes); + } + // 浣跨敤 HashSet 鍘婚噸 + Set<EmptyParameter> personSet = new HashSet<>(emptyParameterList); + personSet.forEach(p -> { + if (p.getSystemDataType().isEmpty()) { + referenceInfo.put(p.getAddress(), p.getParameterType()); + } else { + referenceInfo.put(p.getAddress(), p.getSystemDataType()); + } + }); + } + // --------AES_CBC鍔犲瘑--------- + String cbcResult = AESUtil.encryptCBC(emptyParameter.getScript(), "xhVs6DRXLfUGxw+AhtfQdpQGoa+8SA9d"); + try { + ScriptCompilation scriptCompilation = new ScriptCompilation(); + Equipment equipment = equipmentService.getById(emptyParameter.getEquipmentId()); + scriptCompilation.setDeviceId(equipment.getEqptCode()); + scriptCompilation.setParameterCode(cbcResult); + scriptCompilation.setParameterDataType(emptyParameter.getParameterType()); + scriptCompilation.setParameterName(emptyParameter.getParameterName()); + scriptCompilation.setReferenceinfo(referenceInfo); + String jsonPayload = JSONObject.toJSONString(scriptCompilation); + + // 鍒涘缓 HttpClient 瀹炰緥 + HttpClient httpClient = HttpClients.createDefault(); + Map<String, String> param = new HashMap<>(); + // 鍙戦�佹枃浠跺湴鍧� + ServerDeploy serverDeploy = serverDeployService.getById(equipment.getServerId()); + param.put("path", ftpAddress + serverDeploy.getServerCode() + "/script"); + HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/ProjectPath", param); + // 鍒涘缓 HttpPost 璇锋眰瀹炰緥 + HttpPost httpPost = new HttpPost("http://localhost:3002/ScriptCompiler/ScriptSave"); + // 璁剧疆璇锋眰澶达紝鎸囧畾鍐呭绫诲瀷涓� JSON锛岀紪鐮佷负 UTF-8 + httpPost.setHeader("Content-Type", "application/json; charset=UTF-8"); + + // 鍒涘缓 StringEntity 骞舵寚瀹氱紪鐮佷负 UTF-8 + StringEntity entity = new StringEntity(jsonPayload, "UTF-8"); + httpPost.setEntity(entity); + + // 鎵ц璇锋眰骞惰幏鍙栧搷搴� + HttpResponse response = httpClient.execute(httpPost); + // 鑾峰彇鍝嶅簲瀹炰綋鍐呭 + String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8"); + boolean isContain = responseBody.contains("淇濆瓨鎴愬姛"); + // 灏� JSON 瀛楃涓茶浆鎹负 JSONObject + cn.hutool.json.JSONObject jsonObject = new cn.hutool.json.JSONObject(responseBody); + // 璁块棶 JSON 瀵硅薄鐨勫睘鎬� + String message = jsonObject.getStr("Message"); + if (isContain) { + // 淇濆瓨鑴氭湰鏍囪鍒楄〃 + StringBuilder scriptTagList = new StringBuilder(); + for (String key : referenceInfo.keySet()) { + if (scriptTagList.toString().equals("")) { + scriptTagList = new StringBuilder(key); + } else { + scriptTagList.append("|").append(key); + } + } + // 淇濆瓨灞炴�� + emptyParameter.setScriptTagList(scriptTagList.toString()); + // 淇濆瓨鑴氭湰 + emptyParameter.setScriptContent(emptyParameter.getScript()); + baseMapper.updateById(emptyParameter); + return Result.ok(message); + } else { + // 杈撳嚭鍝嶅簲鍐呭 + return Result.error(message); + } + } catch (Exception e) { + e.printStackTrace(); + } + return Result.error("缂栬瘧澶辫触"); + } + + @Override + public Integer findEmptyParameterCode(String equipmentId) { + List<EmptyParameter> list = new LambdaQueryChainWrapper<>(baseMapper) + .eq(EmptyParameter::getEquipmentId, equipmentId) + .orderByDesc(EmptyParameter::getParameterCode) + .list(); + if (list.size() == 0) { + return 1; + } + return list.get(0).getParameterCode() + 1; + } + + @Override + public Boolean findEmptyParameterByName(EmptyParameter emptyParameter) { + List<EmptyParameter> realParameters = new LambdaQueryChainWrapper<>(baseMapper) + .eq(EmptyParameter::getEquipmentId, emptyParameter.getEquipmentId()) + .eq(EmptyParameter::getParameterName, emptyParameter.getParameterName()) + .list(); + return realParameters.size() > 0; + } + + @Override + public void createEmptyEmptyField(Date deployDate, String serverId) { + List<EmptyParameter> emptyParameterList = baseMapper.findEmptyParameterListByTime(deployDate, serverId); + Map<String, List<EmptyParameter>> emptyParameterListMap = emptyParameterList.stream() + .collect(Collectors.groupingBy(EmptyParameter::getEqptCode)); + emptyParameterListMap.forEach((eqptCode, parameterList) -> { + // 灏嗘墍鏈夌殑 '-' 鏇挎崲涓� '_' + String code = eqptCode.replace("-", "_"); + Equipment equipment = equipmentService.findEquipmentByCode(eqptCode); + List<String> columnDefinitions = new ArrayList<>(); + Set<String> columnNames = new HashSet<>(); + // 閬嶅巻褰撳墠璁惧涓嬬殑鎵�鏈夊弬鏁� + parameterList.forEach(param -> { + columnNames.add(param.getParameterName()); + if (databaseType.equals("SqlServer")) { + columnDefinitions.add("NVARCHAR(100) DEFAULT ''"); + } else if (databaseType.equals("MySql")) { + columnDefinitions.add("VARCHAR(100) CHARACTER SET utf8mb4"); + } + }); + if (CollectionUtils.isEmpty(columnNames)){ + return; + } + if (databaseType.equals("SqlServer")) { + addSqlserverColumns(equipment.getControlSystem() + '_' + code, new ArrayList<>(columnDefinitions), + new ArrayList<>(columnNames)); + } else if (databaseType.equals("MySql")) { + addMySqlColumns(equipment.getControlSystem() + '_' + code, new ArrayList<>(columnDefinitions), + new ArrayList<>(columnNames)); + } + }); + } + + /** + * // 鎵归噺瀵煎叆瀛楁锛圫QL Server 鐗堟湰锛� + * + * @param tableName + * @param columnDefinitions + * @param columnNames + */ + public void addSqlserverColumns(String tableName, List<String> columnDefinitions, List<String> columnNames) { + if (columnDefinitions.size() != columnNames.size()) { + throw new IllegalArgumentException("瀛楁瀹氫箟鍜屽瓧娈靛悕鐨勬暟閲忓繀椤讳竴鑷�"); + } + + // 杞箟琛ㄥ悕涓殑鏂规嫭鍙凤紝闃叉SQL娉ㄥ叆 + tableName = tableName.replace("[", "[[").replace("]", "]]"); + + StringBuilder sqlBuilder = new StringBuilder(); + sqlBuilder.append("ALTER TABLE").append("[") + .append(tableName).append("] ADD "); + + boolean hasNewColumns = false; + for (int i = 0; i < columnDefinitions.size(); i++) { + String columnName = columnNames.get(i); + if (sqlServeBatchIsColumnExists(tableName, columnName)) { + System.out.println("瀛楁宸插瓨鍦紝鏃犻渶娣诲姞: " + columnName); + continue; + } + + String columnDefinition = columnDefinitions.get(i); + if (hasNewColumns) { + sqlBuilder.append(", "); + } + sqlBuilder.append("[").append(columnName.replace("[", "[[").replace("]", "]]")).append("] ") + .append(columnDefinition); + hasNewColumns = true; + } + + String sql = sqlBuilder.toString(); + if (!hasNewColumns) { + System.out.println("娌℃湁闇�瑕佹坊鍔犵殑鏂板瓧娈�"); + return; + } + + try (Connection conn = dataSource.getConnection(); + Statement stmt = conn.createStatement()) { + System.out.println("鎵цSQL: " + sql); // 璋冭瘯鐢� + stmt.executeUpdate(sql); + System.out.println("瀛楁鎵归噺娣诲姞鎴愬姛"); + } catch (SQLException e) { + System.err.println("鎵归噺娣诲姞瀛楁澶辫触: " + sql); + e.printStackTrace(); + } + } + + /** + * 楠岃瘉瀛楁鏄惁瀛樺湪锛圫QL Server 鐗堟湰锛� + */ + private boolean sqlServeBatchIsColumnExists(String tableName, String columnName) { + // 鑷姩杞箟琛ㄥ悕锛堝鐞嗘柟鎷彿鍜岀壒娈婂瓧绗︼級 + String quotedTable = "[" + tableName.replace("]", "]]") + "]"; + + String sql = "SELECT COUNT(*) FROM sys.columns " + + "WHERE object_id = OBJECT_ID(?) AND name = ?"; + + try (Connection conn = dataSource.getConnection(); + PreparedStatement stmt = conn.prepareStatement(sql)) { + // 璁剧疆绗竴涓弬鏁帮細杞箟鍚庣殑琛ㄥ悕 + stmt.setString(1, quotedTable); + // 璁剧疆绗簩涓弬鏁帮細瀛楁鍚� + stmt.setString(2, columnName); + + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + return rs.getInt(1) > 0; + } + } + } catch (SQLException e) { +// log.error("妫�鏌ュ瓧娈� {} 鍦ㄨ〃 {} 涓槸鍚﹀瓨鍦ㄦ椂鍑洪敊", columnName, tableName, e); + return false; + } + return false; + } + + /** + * 鎵归噺瀵煎叆瀛楁锛圡ySQL 鐗堟湰锛� + * + * @param tableName 琛ㄥ悕 + * @param columnDefinitions 鍒楀畾涔夊垪琛紝鏍煎紡濡� "VARCHAR(255) NOT NULL" + * @param columnNames 鍒楀悕鍒楄〃 + */ + public void addMySqlColumns(String tableName, List<String> columnDefinitions, List<String> columnNames) { + if (columnDefinitions.size() != columnNames.size()) { + throw new IllegalArgumentException("瀛楁瀹氫箟鍜屽瓧娈靛悕鐨勬暟閲忓繀椤讳竴鑷�"); + } + + tableName = sanitizeSqlIdentifier(tableName); + + // 瀵规瘡涓垪鍗曠嫭鎵ц ALTER TABLE 璇彞 + for (int i = 0; i < columnNames.size(); i++) { + String columnName = sanitizeSqlIdentifier(columnNames.get(i)); + if (columnName.isEmpty()) { + System.out.println("蹇界暐鏃犳晥瀛楁鍚�: " + columnNames.get(i)); + continue; + } + + if (mySqlBatchIsColumnExists(tableName, columnName)) { + System.out.println("瀛楁宸插瓨鍦紝鏃犻渶娣诲姞: " + columnName); + continue; + } + + String columnDefinition = columnDefinitions.get(i); + // 纭繚鏍煎紡姝g‘ + columnDefinition = formatMySqlColumnDefinition(columnDefinition); + + String sql = String.format( + "ALTER TABLE `%s` ADD `%s` %s", + tableName, columnName, columnDefinition + ); + + try (Connection conn = dataSource.getConnection(); + Statement stmt = conn.createStatement()) { + System.out.println("鎵цSQL: " + sql); + stmt.executeUpdate(sql); + System.out.println("瀛楁娣诲姞鎴愬姛: " + columnName); + } catch (SQLException e) { + System.err.println("娣诲姞瀛楁澶辫触: " + sql); + e.printStackTrace(); + } + } + } + + // 纭繚 MySQL 鍒楀畾涔夋牸寮忔纭� + private String formatMySqlColumnDefinition(String definition) { + // 淇 VARCHAR 鏍煎紡 + definition = definition.replaceAll("VARCHAR\\s*\\(\\s*(\\d+)\\s*\\)", "VARCHAR($1)"); + + // 纭繚 CHARACTER SET 绱ц窡鏁版嵁绫诲瀷 + definition = definition.replaceAll("(VARCHAR\\(\\d+\\))\\s+(CHARACTER SET)", "$1 $2"); + + // 绉婚櫎澶氫綑绌烘牸 + definition = definition.replaceAll("\\s+", " "); + + return definition; + } + + // 娓呯悊 SQL 鏍囪瘑绗� + private String sanitizeSqlIdentifier(String identifier) { + if (identifier == null || identifier.isEmpty()) { + return "_invalid_"; + } + return identifier.replaceAll("[^a-zA-Z0-9_]", "_"); + } + + /** + * 妫�鏌ySQL琛ㄤ腑鏄惁瀛樺湪鎸囧畾鍒� + * + * @param tableName 琛ㄥ悕 + * @param columnName 鍒楀悕 + * @return true if column exists + */ + private boolean mySqlBatchIsColumnExists(String tableName, String columnName) { + String escapedTableName = tableName.replace("`", "``"); + String escapedColumnName = columnName.replace("`", "``"); + String sql = "SELECT COUNT(*) FROM information_schema.columns " + + "WHERE table_name = ? AND column_name = ? " + + "AND table_schema = DATABASE()"; + + try (Connection conn = dataSource.getConnection(); + PreparedStatement pstmt = conn.prepareStatement(sql)) { + pstmt.setString(1, escapedTableName); + pstmt.setString(2, escapedColumnName); + try (ResultSet rs = pstmt.executeQuery()) { + if (rs.next()) { + return rs.getInt(1) > 0; + } + } + } catch (SQLException e) { + e.printStackTrace(); + } + return false; + } + + /** + * 鏍规嵁琛ㄨ揪寮忔煡璇㈣剼鏈腑鍖呭惈鐨勫睘鎬� + * + * @param script 鑴氭湰 + * @param regex 琛ㄨ揪寮� + * @return 灞炴�� + */ + Set<String> getAttributes(String script, String regex) { + Set<String> scriptList = new HashSet<>(); + // 缂栬瘧姝e垯琛ㄨ揪寮� + Pattern pattern = Pattern.compile(regex); + // 鍒涘缓 Matcher 瀵硅薄 + Matcher matcher = pattern.matcher(script); + // 鏌ユ壘鎵�鏈夊尮閰嶇殑瀛愬瓧绗︿覆 + while (matcher.find()) { + // 鑾峰彇褰撳墠鍖归厤鍒扮殑鍐呭 + scriptList.add(matcher.group()); + } + return scriptList; + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/EquipmentServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/EquipmentServiceImpl.java new file mode 100644 index 0000000..e5e80ec --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/EquipmentServiceImpl.java @@ -0,0 +1,515 @@ +package org.jeecg.modules.iot.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.iot.depository.DbConfig; +import org.jeecg.modules.iot.depository.InfluxdbTest; +import org.jeecg.modules.iot.depository.MysqlDataWriter; +import org.jeecg.modules.iot.entity.Equipment; +import org.jeecg.modules.iot.entity.ParameterGroup; +import org.jeecg.modules.iot.entity.ServerDeploy; +import org.jeecg.modules.iot.entity.xmlEntity.*; +import org.jeecg.modules.iot.entity.xmlEntity.script.FunctionEntity; +import org.jeecg.modules.iot.entity.xmlEntity.script.Functions; +import org.jeecg.modules.iot.mapper.EquipmentMapper; +import org.jeecg.modules.iot.service.IEquipmentService; +import org.jeecg.modules.iot.service.IParameterGroupService; +import org.jeecg.modules.iot.service.IServerDeployService; +import org.jeecg.modules.iot.util.HttpClientUtil; +import org.jeecg.modules.iot.util.JaxbUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.sql.DataSource; +import java.sql.*; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.Date; +import java.util.stream.Collectors; + +/** + * @Description: 璁惧 + * @Author: cuikaidong + * @Date: 2024-12-23 + * @Version: V1.0 + */ +@Service("iotEquipmentServiceImpl") +public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment> implements IEquipmentService { + @Value("${script}") + private String script; + @Value("${databaseType}") + private String databaseType; + @Value("${ftp.address}") + private String ftpAddress; + @Autowired + private IParameterGroupService parameterGroupService; + @Lazy + @Autowired + private IServerDeployService serverDeployService; + @Autowired + private org.jeecg.modules.iot.mdc.service.IEquipmentService equipmentService; + @Autowired + private DataSource dataSource; + + @Value("${drive}") + private String drive; + + @Override + public List<SystemType> findProjectCode() { + Config entity = (Config) JaxbUtil.xmlToBean(drive, Config.class); + return entity.getSystemTypeList(); + } + + @Override + public Object[] queryEquipmentSubscribeList(String id) { + Object[] strings = new Object[0]; + List<Equipment> equipmentList = new LambdaQueryChainWrapper<>(baseMapper) + .eq(Equipment::getServerId, id).list(); + if (CollectionUtil.isNotEmpty(equipmentList)) { + Object[] objects = new Object[equipmentList.size()]; + for (int i = 0; i < equipmentList.size(); i++) { + objects[i] = equipmentList.get(i).getReadTopic(); + } + return objects; + } + return strings; + } + + @Override + public List<ControlSystem> findControlSystems(String type) { + Config entity = (Config) JaxbUtil.xmlToBean(drive, Config.class); + List<ControlSystem> controlSystemList = entity.getControlSystemList(); + return controlSystemList.stream().filter(c -> c.getType().equals(type)).collect(Collectors.toList()); + } + + @Override + public List<ByteOrder> findByteOrder() { + Config entity = (Config) JaxbUtil.xmlToBean(drive, Config.class); + return entity.getByteOrderList(); + } + + @Override + public List<SystemDataType> findSystemDataTypeList() { + Config entity = (Config) JaxbUtil.xmlToBean(drive, Config.class); + return entity.getSystemDataTypeList(); + } + + @Override + public List<Parameter> findParameterById(String id) { + ParameterGroup parameterGroup = parameterGroupService.getById(id); + Equipment equipment = this.baseMapper.selectById(parameterGroup.getEquipmentId()); + Config entity = (Config) JaxbUtil.xmlToBean(drive, Config.class); + List<ControlSystem> controlSystemList = entity.getControlSystemList(); + List<ControlSystem> list1 = controlSystemList.stream().filter(c -> c.getType().equals(equipment.getEqptType()) && c.getName().equals(equipment.getControlSystem())).collect(Collectors.toList()); + List<Protocol> controlSystem = list1.get(0).protocolList; + List<Protocol> list2 = controlSystem.stream().filter(c -> c.getName().equals(equipment.getProtocol())).collect(Collectors.toList()); + List<DriveType> driveTypeList = list2.get(0).driveTypeList; + List<DriveType> list3 = driveTypeList.stream().filter(c -> c.getName().equals(equipment.getDriveType())).collect(Collectors.toList()); + return list3.get(0).registerInfoList.get(0).defaultParameterList.get(0).parameterList; + } + + @Override + public List<Parameter> findParameterCustomizeById(String id) { + ParameterGroup parameterGroup = parameterGroupService.getById(id); + Equipment equipment = this.baseMapper.selectById(parameterGroup.getEquipmentId()); + Config entity = (Config) JaxbUtil.xmlToBean(drive, Config.class); + List<ControlSystem> controlSystemList = entity.getControlSystemList(); + List<ControlSystem> list1 = controlSystemList.stream().filter(c -> c.getType().equals(equipment.getEqptType()) && c.getName().equals(equipment.getControlSystem())).collect(Collectors.toList()); + List<Protocol> controlSystem = list1.get(0).protocolList; + List<Protocol> list2 = controlSystem.stream().filter(c -> c.getName().equals(equipment.getProtocol())).collect(Collectors.toList()); + List<DriveType> driveTypeList = list2.get(0).driveTypeList; + List<DriveType> list3 = driveTypeList.stream().filter(c -> c.getName().equals(equipment.getDriveType())).collect(Collectors.toList()); + return list3.get(0).registerInfoList.get(0).registerTypeList.get(0).parameterList; + } + + @Override + public List<Parameter> findDataTypeById(String id) { + ParameterGroup parameterGroup = parameterGroupService.getById(id); + Equipment equipment = this.baseMapper.selectById(parameterGroup.getEquipmentId()); + Config entity = (Config) JaxbUtil.xmlToBean(drive, Config.class); + List<ControlSystem> controlSystemList = entity.getControlSystemList(); + List<ControlSystem> list1 = controlSystemList.stream().filter(c -> c.getType().equals(equipment.getEqptType()) && c.getName().equals(equipment.getControlSystem())).collect(Collectors.toList()); + List<Protocol> controlSystem = list1.get(0).protocolList; + List<Protocol> list2 = controlSystem.stream().filter(c -> c.getName().equals(equipment.getProtocol())).collect(Collectors.toList()); + List<DriveType> driveTypeList = list2.get(0).driveTypeList; + List<DriveType> list3 = driveTypeList.stream().filter(c -> c.getName().equals(equipment.getDriveType())).collect(Collectors.toList()); + return list3.get(0).registerInfoList.get(0).dataTypeList.get(0).parameterList; + } + + @Override + public List<Equipment> findEquipmentByServerId(String id) { + return new LambdaQueryChainWrapper<>(baseMapper).eq(Equipment::getServerId, id).list(); + } + + @Override + public Boolean findEquipmentByName(Equipment equipment, Integer type) { + List<Equipment> equipmentList = new LambdaQueryChainWrapper<>(baseMapper) + .eq(Equipment::getServerId, equipment.getServerId()) + .eq(Equipment::getEquipmentType, type) + .eq(Equipment::getEqptName, equipment.getEqptName()) + .list(); + return equipmentList.size() > 0; + } + + @Override + public Boolean findEquipmentByCode(Equipment equipment) { + List<Equipment> equipmentList = new LambdaQueryChainWrapper<>(baseMapper) + .eq(Equipment::getServerId, equipment.getServerId()) + .eq(Equipment::getEqptCode, equipment.getEqptCode()) + .list(); + return equipmentList.size() > 0; + } + + @Override + public List<FunctionEntity> findFunctionInformationList(String functionType) { + Functions entity = (Functions) JaxbUtil.xmlToBean(script, Functions.class); + switch (functionType) { + case "Convert": + return entity.getConvertEntity().getFunctionList(); + case "Math": + return entity.getMathEntity().getFunctionEntityList(); + case "String": + return entity.getStringEntity().getFunctionEntityList(); + case "File": + return entity.getFileEntity().getFunctionEntityList(); + case "Time": + return entity.getTimeEntity().getFunctionEntityList(); + case "Database": + return entity.getDatabaseEntity().getFunctionEntityList(); + case "Custom": + return entity.getCustomEntity().getFunctionEntityList(); + default: + return null; + } + } + + @Override + public void createEmptyEquipmentTable(Date deployDate, String serverId) { + List<Equipment> equipmentList = new LambdaQueryChainWrapper<>(baseMapper) + .eq(Equipment::getServerId, serverId) + .eq(Equipment::getEquipmentType, 0) + .ge(Equipment::getCreateTime, deployDate) + .list(); + equipmentList.forEach(equipment -> { + // 灏嗘墍鏈夌殑 '-' 鏇挎崲涓� '_' + equipment.setEqptCode(equipment.getEqptCode().replace("-", "_")); + if (databaseType.equals("SqlServer")) { + createSqlServerTable(equipment.getControlSystem() + '_' + equipment.getEqptCode(), + "CollectTime DATETIME DEFAULT GETDATE() NOT NULL", + "EquipmentID NVARCHAR(50) NOT NULL", + "PRIMARY KEY (CollectTime)" + ); + } else if (databaseType.equals("MySql")) { + createMySqlTable(equipment.getControlSystem() + '_' + equipment.getEqptCode(), + "CollectTime DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL", + "EquipmentID VARCHAR(50) CHARACTER SET utf8mb4 NOT NULL", + "PRIMARY KEY (CollectTime)" + ); + } + // 缁檓dc璁惧琛ㄥ鍔犺澶囦俊鎭� + org.jeecg.modules.iot.mdc.entity.Equipment mdcEquipment = new org.jeecg.modules.iot.mdc.entity.Equipment(); + mdcEquipment.setEquipmentid(equipment.getEqptCode()); + mdcEquipment.setEquipmentname(equipment.getEqptName()); + mdcEquipment.setSavetablename(equipment.getControlSystem() + '_' + equipment.getEqptCode()); + mdcEquipment.setDrivetype(equipment.getControlSystem()); + equipmentService.save(mdcEquipment); + }); + } + + /** + * 鍒涘缓瀹炴椂鏁版嵁琛� + * + * @param tableName + * @param columns + */ + private void createSqlServerTable(String tableName, String... columns) { + String tableSql = String.format( + "IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = '%s' ) " + + "CREATE TABLE [%s] (%s)", + tableName, tableName, String.join(", ", columns) + ); + try (Connection conn = dataSource.getConnection()) { + Statement stmt = conn.createStatement(); + stmt.executeUpdate(tableSql); + System.out.println("琛ㄥ垱寤烘垚鍔�: " + tableName); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + /** + * 鍒涘缓MySQL鏁版嵁琛� + * + * @param tableName 琛ㄥ悕 + * @param columns 鍒楀畾涔夛紝鏍煎紡濡� "column_name DATATYPE [CONSTRAINT]" + */ + private void createMySqlTable(String tableName, String... columns) { + String tableSql = String.format( + "CREATE TABLE IF NOT EXISTS `%s` (%s)", + tableName, String.join(", ", columns) + ); + try (Connection conn = dataSource.getConnection()) { + Statement stmt = conn.createStatement(); + stmt.executeUpdate(tableSql); + System.out.println("琛ㄥ垱寤烘垚鍔�: " + tableName); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result<?> addEmpty(Equipment equipment) { + // 楠岃瘉缂栫爜鍚嶇О鏄惁閲嶅 + if (this.findEquipmentByName(equipment, 0)) { + return Result.error("璁惧鍚嶇О宸插瓨鍦紒"); + } + if (this.findEquipmentByCode(equipment)) { + return Result.error("璁惧缂栧彿宸插瓨鍦紒"); + } + // 鍒嗙被 + equipment.setEquipmentType(0); + ServerDeploy serverDeploy = serverDeployService.getById(equipment.getServerId()); + this.save(equipment); + equipment.setReadTopic("IOT/" + serverDeploy.getServerCode() + "/VirtualDevices/" + equipment.getEqptCode() + "/Read"); + equipment.setWriteTopic("IOT." + serverDeploy.getServerCode() + ".VirtualDevices." + equipment.getEqptCode()); + this.updateById(equipment); + // 鏂板铏氳澶囨椂璋冪敤 + // 鏂板缓椤圭洰鐩綍鏃舵垨鑰呴」鐩浇鍏ユ椂璋冪敤 + Map<String, String> param = new HashMap<>(); + param.put("path", ftpAddress + serverDeploy.getServerCode() + "/script"); + HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/ProjectPath", param); + param.clear(); + param.put("id", equipment.getEqptCode()); + HttpClientUtil.doGet("http://localhost:3002/ScriptCompiler/AddDevicescript", param); + return Result.ok("娣诲姞鎴愬姛锛�"); + } + + @Override + public Equipment findEquipmentByCode(String code) { + return new LambdaQueryChainWrapper<>(baseMapper) + .eq(Equipment::getEqptCode, code) + .one(); + } + + @Override + public void insertSqlServerData(String tableName, String[] columns, Object[] values) { + if (columns.length != values.length) { + throw new IllegalArgumentException("瀛楁涓庡�肩殑鏁伴噺涓嶅尮閰�"); + } + + // 杞箟琛ㄥ悕鍜屽垪鍚嶏紙SQL Server浣跨敤鏂规嫭鍙穂]锛� + String escapedTableName = "[" + tableName.replace("]", "]]") + "]"; + + // 鏋勫缓鍒楀悕鍜屽崰浣嶇 + StringBuilder columnBuilder = new StringBuilder(); + StringBuilder placeholderBuilder = new StringBuilder(); + + for (int i = 0; i < columns.length; i++) { + if (i > 0) { + columnBuilder.append(", "); + placeholderBuilder.append(", "); + } + // 杞箟鍒楀悕锛屽鐞嗗彲鑳藉寘鍚殑鐗规畩瀛楃 + String escapedColumn = "[" + columns[i].replace("]", "]]") + "]"; + columnBuilder.append(escapedColumn); + placeholderBuilder.append("?"); + } + + String sql = String.format("INSERT INTO %s (%s) VALUES (%s)", + escapedTableName, + columnBuilder.toString(), + placeholderBuilder.toString()); + +// log.debug("鏋勫缓SQL: {}", sql); + + try (Connection conn = dataSource.getConnection(); + PreparedStatement pstmt = conn.prepareStatement(sql)) { + + // 璁剧疆鍙傛暟锛屾牴鎹�肩被鍨嬮�夋嫨鍚堥�傜殑set鏂规硶 + for (int i = 0; i < values.length; i++) { + Object value = values[i]; + String columnName = columns[i]; + +// log.debug("璁剧疆鍙傛暟 {}: 鍒楀悕={}, 鍊�={}, 绫诲瀷={}", +// i+1, columnName, value, value != null ? value.getClass().getName() : "NULL"); + + if (value == null) { + // 瀵逛簬NULL鍊硷紝闇�瑕佹寚瀹氱被鍨� + if (columnName.toLowerCase().contains("bool")) { + pstmt.setNull(i + 1, Types.BIT); + } else if (columnName.toLowerCase().contains("int")) { + pstmt.setNull(i + 1, Types.INTEGER); + } else if (columnName.toLowerCase().contains("time") || + columnName.toLowerCase().contains("date")) { + pstmt.setNull(i + 1, Types.TIMESTAMP); + } else { + pstmt.setNull(i + 1, Types.VARCHAR); + } + } else if (value instanceof String) { + pstmt.setString(i + 1, (String) value); + } else if (value instanceof Integer) { + pstmt.setInt(i + 1, (Integer) value); + } else if (value instanceof Long) { + pstmt.setLong(i + 1, (Long) value); + } else if (value instanceof Boolean) { + pstmt.setBoolean(i + 1, (Boolean) value); + } else if (value instanceof Date) { + // 灏唈ava.util.Date杞崲涓簀ava.sql.Timestamp + pstmt.setTimestamp(i + 1, new Timestamp(((Date) value).getTime())); + } else if (value instanceof Calendar) { + pstmt.setTimestamp(i + 1, new Timestamp( + ((Calendar) value).getTimeInMillis())); + } else if (value instanceof byte[]) { + pstmt.setBytes(i + 1, (byte[]) value); + } else if (value instanceof boolean[]) { + // 甯冨皵鏁扮粍澶勭悊锛氳浆鎹负閫楀彿鍒嗛殧鐨勫瓧绗︿覆 + boolean[] boolArray = (boolean[]) value; + StringBuilder sb = new StringBuilder(); + for (int j = 0; j < boolArray.length; j++) { + if (j > 0) sb.append(","); + sb.append(boolArray[j] ? "1" : "0"); + } + pstmt.setString(i + 1, sb.toString()); + } else if (value instanceof int[]) { + // 鏁存暟鏁扮粍澶勭悊锛氳浆鎹负閫楀彿鍒嗛殧鐨勫瓧绗︿覆 + int[] intArray = (int[]) value; + StringBuilder sb = new StringBuilder(); + for (int j = 0; j < intArray.length; j++) { + if (j > 0) sb.append(","); + sb.append(intArray[j]); + } + pstmt.setString(i + 1, sb.toString()); + } else { + LocalDateTime localDateTime = LocalDateTime.parse(values[i].toString()); + pstmt.setTimestamp(i + 1, Timestamp.valueOf(localDateTime)); + } + } + + pstmt.executeUpdate(); +// log.debug("鏁版嵁鎻掑叆鎴愬姛: {}", tableName); + } catch (SQLException e) { + log.error("SQL Server鎻掑叆鏁版嵁澶辫触: " + sql, e); + throw new RuntimeException("SQL Server鎻掑叆鏁版嵁澶辫触", e); + } + } + + /** + * 鍚慚ySQL琛ㄦ彃鍏ユ暟鎹� + * + * @param tableName 琛ㄥ悕 + * @param columns 鍒楀悕鏁扮粍 + * @param values 瀵瑰簲鐨勫�兼暟缁� + */ + public void insertMySqlData(String tableName, String[] columns, Object[] values) { + if (columns.length != values.length) { + throw new IllegalArgumentException("瀛楁涓庡�肩殑鏁伴噺涓嶅尮閰�"); + } + + // 杞箟琛ㄥ悕锛圡ySQL浣跨敤鍙嶅紩鍙穈`锛� + String escapedTableName = "`" + tableName.replace("`", "``") + "`"; + + // 鏋勫缓鍒楀悕鍜屽崰浣嶇 + StringBuilder columnBuilder = new StringBuilder(); + StringBuilder placeholderBuilder = new StringBuilder(); + + for (int i = 0; i < columns.length; i++) { + if (i > 0) { + columnBuilder.append(", "); + placeholderBuilder.append(", "); + } + // 杞箟鍒楀悕锛屽鐞嗙壒娈婂瓧绗� + String escapedColumn = "`" + columns[i].replace("`", "``") + "`"; + columnBuilder.append(escapedColumn); + placeholderBuilder.append("?"); + } + + String sql = String.format("INSERT INTO %s (%s) VALUES (%s)", + escapedTableName, + columnBuilder.toString(), + placeholderBuilder.toString()); + + try (Connection conn = dataSource.getConnection(); + PreparedStatement pstmt = conn.prepareStatement(sql)) { + + // 璁剧疆鍙傛暟锛岄�傞厤MySQL绫诲瀷 + for (int i = 0; i < values.length; i++) { + Object value = values[i]; + String columnName = columns[i]; + + if (value == null) { + // MySQL瀵筃ULL鍊肩殑绫诲瀷澶勭悊鏇寸伒娲伙紝浣嗕粛寤鸿鎸囧畾 + if (columnName.toLowerCase().contains("bool")) { + pstmt.setNull(i + 1, Types.BOOLEAN); // MySQL浣跨敤BOOLEAN鑰岄潪BIT + } else if (columnName.toLowerCase().contains("int")) { + pstmt.setNull(i + 1, Types.INTEGER); + } else if (columnName.toLowerCase().contains("time") || + columnName.toLowerCase().contains("date")) { + pstmt.setNull(i + 1, Types.TIMESTAMP); + } else { + pstmt.setNull(i + 1, Types.VARCHAR); + } + } else if (value instanceof String) { + // MySQL鐨刅ARCHAR鏈夐暱搴﹂檺鍒讹紝杩欓噷鍙牴鎹渶瑕佹埅鏂垨鏍¢獙 + String strValue = (String) value; + pstmt.setString(i + 1, strValue); + } else if (value instanceof Integer) { + pstmt.setInt(i + 1, (Integer) value); + } else if (value instanceof Long) { + pstmt.setLong(i + 1, (Long) value); + } else if (value instanceof Boolean) { + // MySQL涓竷灏斿�煎瓨鍌ㄤ负1锛坱rue锛夊拰0锛坒alse锛� + pstmt.setBoolean(i + 1, (Boolean) value); + } else if (value instanceof Date) { + // MySQL鎺ㄨ崘浣跨敤Timestamp绫诲瀷 + pstmt.setTimestamp(i + 1, new Timestamp(((Date) value).getTime())); + } else if (value instanceof Calendar) { + pstmt.setTimestamp(i + 1, new Timestamp( + ((Calendar) value).getTimeInMillis())); + } else if (value instanceof byte[]) { + pstmt.setBytes(i + 1, (byte[]) value); + } else if (value instanceof boolean[]) { + // 甯冨皵鏁扮粍杞负閫楀彿鍒嗛殧瀛楃涓诧紙鍚孲QL Server閫昏緫锛� + boolean[] boolArray = (boolean[]) value; + StringBuilder sb = new StringBuilder(); + for (int j = 0; j < boolArray.length; j++) { + if (j > 0) sb.append(","); + sb.append(boolArray[j] ? "1" : "0"); + } + pstmt.setString(i + 1, sb.toString()); + } else if (value instanceof int[]) { + // 鏁存暟鏁扮粍杞负閫楀彿鍒嗛殧瀛楃涓� + int[] intArray = (int[]) value; + StringBuilder sb = new StringBuilder(); + for (int j = 0; j < intArray.length; j++) { + if (j > 0) sb.append(","); + sb.append(intArray[j]); + } + pstmt.setString(i + 1, sb.toString()); + } else if (value instanceof LocalDateTime) { + // 鐩存帴澶勭悊Java 8鏃堕棿绫诲瀷锛圡ySQL 8.0+鎺ㄨ崘锛� + pstmt.setTimestamp(i + 1, Timestamp.valueOf((LocalDateTime) value)); + } else { + // 鏈煡绫诲瀷杞负瀛楃涓� + pstmt.setString(i + 1, value.toString()); + } + } + + pstmt.executeUpdate(); + System.out.println("鏁版嵁鎻掑叆鎴愬姛: " + tableName); + } catch (SQLException e) { + System.err.println("MySQL鎻掑叆鏁版嵁澶辫触: " + sql); + e.printStackTrace(); + throw new RuntimeException("MySQL鎻掑叆鏁版嵁澶辫触", e); + } + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/InfluxdbDeployServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/InfluxdbDeployServiceImpl.java new file mode 100644 index 0000000..2dd52e9 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/InfluxdbDeployServiceImpl.java @@ -0,0 +1,31 @@ +package org.jeecg.modules.iot.service.impl; + +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.modules.iot.entity.InfluxdbDeploy; +import org.jeecg.modules.iot.mapper.InfluxdbDeployMapper; +import org.jeecg.modules.iot.service.IInfluxdbDeployService; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Set; + +/** + * @Description: Influxdb閰嶇疆 + * @Author: cuikaidong + * @Date: 2024-12-10 + * @Version: V1.0 + */ +@Service +public class InfluxdbDeployServiceImpl extends ServiceImpl<InfluxdbDeployMapper, InfluxdbDeploy> implements IInfluxdbDeployService { + + @Override + public List<InfluxdbDeploy> findByServerIdsInfluxdbDeploy(Set<String> serverIds) { + return new LambdaQueryChainWrapper<>(baseMapper).in(InfluxdbDeploy::getServerDeployId, serverIds).list(); + } + + @Override + public InfluxdbDeploy findByServerIdInfluxdb(String id) { + return new LambdaQueryChainWrapper<>(baseMapper).eq(InfluxdbDeploy::getServerDeployId, id).one(); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/MqttDeployServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/MqttDeployServiceImpl.java new file mode 100644 index 0000000..43cc59b --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/MqttDeployServiceImpl.java @@ -0,0 +1,31 @@ +package org.jeecg.modules.iot.service.impl; + +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.modules.iot.entity.MqttDeploy; +import org.jeecg.modules.iot.mapper.MqttDeployMapper; +import org.jeecg.modules.iot.service.IMqttDeployService; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Set; + +/** + * @Description: Mqtt閰嶇疆 + * @Author: cuikaidong + * @Date: 2024-12-10 + * @Version: V1.0 + */ +@Service +public class MqttDeployServiceImpl extends ServiceImpl<MqttDeployMapper, MqttDeploy> implements IMqttDeployService { + + @Override + public List<MqttDeploy> findByServerIdsMqttDeploy(Set<String> serverIds) { + return new LambdaQueryChainWrapper<>(baseMapper).in(MqttDeploy::getServerDeployId, serverIds).list(); + } + + @Override + public MqttDeploy findByServerIdMqttDeploy(String id) { + return new LambdaQueryChainWrapper<>(baseMapper).eq(MqttDeploy::getServerDeployId, id).one(); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ParameterGroupServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ParameterGroupServiceImpl.java new file mode 100644 index 0000000..18aabde --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ParameterGroupServiceImpl.java @@ -0,0 +1,82 @@ +package org.jeecg.modules.iot.service.impl; + +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.iot.entity.Equipment; +import org.jeecg.modules.iot.entity.ParameterGroup; +import org.jeecg.modules.iot.entity.RealParameter; +import org.jeecg.modules.iot.mapper.ParameterGroupMapper; +import org.jeecg.modules.iot.service.IEquipmentService; +import org.jeecg.modules.iot.service.IParameterGroupService; +import org.jeecg.modules.iot.service.IRealParameterService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * @Description: 鍙傛暟缁� + * @Author: cuikaidong + * @Date: 2024-12-31 + * @Version: V1.0 + */ +@Service +public class ParameterGroupServiceImpl extends ServiceImpl<ParameterGroupMapper, ParameterGroup> implements IParameterGroupService { + @Autowired + private IRealParameterService realParameterService; + @Autowired + @Lazy + private IEquipmentService equipmentService; + + @Override + public List<ParameterGroup> findParameterGroupByServerId(String serverDeployId) { + return new LambdaQueryChainWrapper<>(baseMapper).eq(ParameterGroup::getServerDeployId,serverDeployId).list(); + } + + @Override + public Boolean findParameterGroupByName(ParameterGroup parameterGroup) { + List<ParameterGroup> equipmentList = new LambdaQueryChainWrapper<>(baseMapper) + .eq(ParameterGroup::getEquipmentId, parameterGroup.getEquipmentId()) + .eq(ParameterGroup::getName, parameterGroup.getName()) + .list(); + return equipmentList.size() > 0; + } + + @Override + public Boolean findParameterGroupByCode(ParameterGroup parameterGroup) { + List<ParameterGroup> equipmentList = new LambdaQueryChainWrapper<>(baseMapper) + .eq(ParameterGroup::getEquipmentId, parameterGroup.getEquipmentId()) + .eq(ParameterGroup::getCode, parameterGroup.getCode()) + .list(); + return equipmentList.size() > 0; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result<?> addParameterGroup(ParameterGroup parameterGroup) { + // 楠岃瘉缂栫爜鍚嶇О鏄惁閲嶅 + if (findParameterGroupByName(parameterGroup)){ + return Result.error("鍙傛暟缁勫悕绉板凡瀛樺湪锛�"); + } + if (findParameterGroupByCode(parameterGroup)){ + return Result.error("鍙傛暟缁勭紪鍙峰凡瀛樺湪锛�"); + } + Equipment equipment = equipmentService.getById(parameterGroup.getEquipmentId()); + parameterGroup.setServerDeployId(equipment.getServerId()); + baseMapper.insert(parameterGroup); + RealParameter realParameter = new RealParameter(); + realParameter.setParameterGroupId(parameterGroup.getId()); + realParameter.setParameterName("IsConnected"); + realParameter.setParameterDescribe("杩炴帴鐘舵��"); + realParameter.setParameterCode(0); + realParameter.setParameterType("Bool"); + realParameter.setAddress("IsConnected"); + realParameter.setSystemDataType("bool"); + realParameter.setReadWriteType("鍙"); + realParameterService.save(realParameter); + return Result.ok("娣诲姞鎴愬姛锛�"); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ProjectClassifyServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ProjectClassifyServiceImpl.java new file mode 100644 index 0000000..41a0224 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ProjectClassifyServiceImpl.java @@ -0,0 +1,60 @@ +package org.jeecg.modules.iot.service.impl; + +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.commons.collections.CollectionUtils; +import org.jeecg.modules.iot.entity.ProjectClassify; +import org.jeecg.modules.iot.entity.ServerDeploy; +import org.jeecg.modules.iot.mapper.ProjectClassifyMapper; +import org.jeecg.modules.iot.service.IEquipmentService; +import org.jeecg.modules.iot.service.IProjectClassifyService; +import org.jeecg.modules.iot.service.IServerDeployService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Description: 椤圭洰鍒嗙被 + * @Author: cuikaidong + * @Date: 2024-12-20 + * @Version: V1.0 + */ +@Service +public class ProjectClassifyServiceImpl extends ServiceImpl<ProjectClassifyMapper, ProjectClassify> implements IProjectClassifyService { + + @Autowired + private IServerDeployService serverDeployService; + + @Override + public String projectClassifyRemoveById(String projectCode) { + ProjectClassify projectClassify = new LambdaQueryChainWrapper<>(baseMapper) + .eq(ProjectClassify::getProjectCode, projectCode).one(); + // 鏌ヨ椤圭洰涓嬫槸鍚︽湁璁惧 + List<ServerDeploy> serverDeploys = serverDeployService.findByProjectClassifyId(projectClassify.getId()); + if (CollectionUtils.isEmpty(serverDeploys)){ + baseMapper.deleteById(projectClassify.getId()); + return "鍒犻櫎鎴愬姛"; + }else { + return "鍒犻櫎澶辫触锛岃鍏堝垹闄ょ粓绔�!"; + } + } + + /** + * 娣诲姞椤圭洰鍒嗙被 + * + * @param projectClassify + */ + @Override + public void addProjectClassify(ProjectClassify projectClassify) { + this.baseMapper.insert(projectClassify); + } + + @Override + public ProjectClassify findByProjectCode(String projectCode) { + return new LambdaQueryChainWrapper<>(baseMapper) + .eq(ProjectClassify::getProjectCode, projectCode) + .one(); + } + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/RealParameterServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/RealParameterServiceImpl.java new file mode 100644 index 0000000..334438d --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/RealParameterServiceImpl.java @@ -0,0 +1,286 @@ +package org.jeecg.modules.iot.service.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.apache.shiro.SecurityUtils; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.common.util.DateUtils; +import org.jeecg.modules.iot.entity.Equipment; +import org.jeecg.modules.iot.entity.ParameterGroup; +import org.jeecg.modules.iot.entity.RealParameter; +import org.jeecg.modules.iot.entity.xmlEntity.Parameter; +import org.jeecg.modules.iot.mapper.RealParameterMapper; +import org.jeecg.modules.iot.mqtt.config.MqttCustomerClient; +import org.jeecg.modules.iot.service.IEquipmentService; +import org.jeecg.modules.iot.service.IParameterGroupService; +import org.jeecg.modules.iot.service.IRealParameterService; +import org.jeecgframework.poi.excel.ExcelImportUtil; +import org.jeecgframework.poi.excel.def.NormalExcelConstants; +import org.jeecgframework.poi.excel.entity.ExportParams; +import org.jeecgframework.poi.excel.entity.ImportParams; +import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; + +/** + * @Description: 瀹炶澶囧弬鏁� + * @Author: cuikaidong + * @Date: 2025-1-2 + * @Version: V1.0 + */ +@Slf4j +@Service +public class RealParameterServiceImpl extends ServiceImpl<RealParameterMapper, RealParameter> implements IRealParameterService { + @Lazy + @Autowired + private IEquipmentService equipmentService; + @Lazy + @Autowired + private MqttCustomerClient mqttCustomerClient; + @Lazy + @Autowired + private IParameterGroupService parameterGroupService; + + @Override + public RealParameter findByParameterCode(String parameterCode) { + return new LambdaQueryChainWrapper<>(baseMapper) + .eq(RealParameter::getParameterCode, parameterCode) + .one(); + } + + @Override + public List<RealParameter> findRealParameterByIds(Set<String> ids) { + return new LambdaQueryChainWrapper<>(baseMapper).in(RealParameter::getParameterGroupId, ids).list(); + } + + @Override + public IPage<RealParameter> findRealParameterPage(Page<RealParameter> pages, Map<String, Object> params) { + return baseMapper.findRealParameterPage(pages, params); + } + + @Override + public Boolean findRealParameterByName(RealParameter realParameter) { + List<RealParameter> realParameters = new LambdaQueryChainWrapper<>(baseMapper) + .eq(RealParameter::getParameterGroupId, realParameter.getParameterGroupId()) + .eq(RealParameter::getParameterName, realParameter.getParameterName()) + .list(); + return realParameters.size() > 0; + } + + @Override + public Boolean findRealParameterByCode(RealParameter realParameter) { + List<RealParameter> realParameters = new LambdaQueryChainWrapper<>(baseMapper) + .eq(RealParameter::getParameterGroupId, realParameter.getParameterGroupId()) + .eq(RealParameter::getParameterCode, realParameter.getParameterCode()) + .list(); + return realParameters.size() > 0; + } + + @Override + public Result<?> parameterWriting(RealParameter realParameter) { + ParameterGroup parameterGroup = parameterGroupService.getById(realParameter.getParameterGroupId()); + Equipment equipment = equipmentService.getById(parameterGroup.getEquipmentId()); + if (realParameter.getWritingValue().isEmpty()) { + return Result.error("鍙傛暟鍐欏叆澶辫触: 鍊间负绌�"); + } + // 鍒涘缓椤跺眰 Map + Map<String, Object> map = new HashMap<>(); + // 璁剧疆 GroupID 鍜� GroupName + map.put("GroupID", parameterGroup.getCode() + ""); + map.put("GroupName", parameterGroup.getName()); + // 鍒涘缓 Tags 鍒楄〃 + List<Map<String, Object>> tagsList = new ArrayList<>(); + // 鍒涘缓骞跺~鍏呯涓�涓� Tag 瀵硅薄 + Map<String, Object> tag1 = new HashMap<>(); + tag1.put("TagID", realParameter.getParameterCode() + ""); + tag1.put("TagName", realParameter.getParameterName()); + tag1.put("Value", realParameter.getWritingValue()); + // 灏� Tag 娣诲姞鍒� Tags 鍒楄〃 + tagsList.add(tag1); + // 灏� Tags 鍒楄〃娣诲姞鍒伴《灞� Map + map.put("Tags", tagsList); + mqttCustomerClient.pushlishWriting(2, false, equipment.getWriteTopic(), map); + return Result.ok("鍙傛暟鍐欏叆鎴愬姛"); + } + + /** + * 閫氳繃excel瀵煎叆鏁版嵁 + * + * @param request + * @param response + * @return + */ + @Override + public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { + String parameterGroupId = request.getParameter("param1"); + if (parameterGroupId.isEmpty()) { + return Result.error("鏂囦欢瀵煎叆澶辫触: 鏌ヨ涓嶅埌鍙傛暟缁勪俊鎭�"); + } + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); + for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { + MultipartFile file = entity.getValue();// 鑾峰彇涓婁紶鏂囦欢瀵硅薄 + ImportParams params = new ImportParams(); + params.setTitleRows(2); + params.setHeadRows(1); + params.setNeedSave(true); + try { + List<RealParameter> realList = ExcelImportUtil.importExcel(file.getInputStream(), RealParameter.class, params); + // 鏌ヨ鏈�鏂扮紪鍙� + AtomicReference<Integer> parameterCode = new AtomicReference<>(this.findRealParameterGroupId(parameterGroupId)); + parameterCode.set(parameterCode.get() - 1); + for (int i = 0; i < realList.size(); i++) { + Integer line = i + 2; + RealParameter real = realList.get(i); + if (StringUtils.isEmpty(real.getParameterName())) { + return Result.error("鏂囦欢瀵煎叆澶辫触:" + line + "琛岋紝鍙傛暟鍚嶇О鏈~鍐�"); + } + // 鍙傛暟鍚嶇О鍘婚櫎绌烘牸 + real.setParameterName(real.getParameterName().replace(" ", "")); + if (StringUtils.isEmpty(real.getParameterType())) { + return Result.error("鏂囦欢瀵煎叆澶辫触:" + line + "琛岋紝鏁版嵁绫诲瀷鏈~鍐�"); + } + if (StringUtils.isEmpty(real.getAddress())) { + return Result.error("鏂囦欢瀵煎叆澶辫触:" + line + "琛岋紝鍦板潃鏈~鍐�"); + } + if (StringUtils.isEmpty(real.getReadWriteType())) { + return Result.error("鏂囦欢瀵煎叆澶辫触:" + line + "琛岋紝璇诲啓绫诲瀷鏈~鍐�"); + } + List<Parameter> parameterList = equipmentService.findDataTypeById(parameterGroupId); + parameterList.forEach(p -> { + String replaceWithX = replaceWithX(real.getParameterType()); + if (replaceWithX.equals(p.getName())) { + real.setSystemDataType(p.getSystemDataType()); + } + }); +// if (real.getSystemDataType().isEmpty()){ +// return Result.error("鏂囦欢瀵煎叆澶辫触:" + line + "琛岋紝鏁版嵁绫诲瀷涓嶅尮閰�"); +// +// } + // 濉厖鍙傛暟 + parameterCode.set(parameterCode.get() + 1); + real.setParameterGroupId(parameterGroupId); + real.setParameterCode(parameterCode.get()); + // 楠岃瘉鍙傛暟鍚嶇О鏄惁閲嶅 + if (this.findRealParameterByName(real)) { + return Result.error("鏂囦欢瀵煎叆澶辫触:" + line + "琛岋紝" + real.getParameterName() + "鍙傛暟鍚嶇О宸查噸澶�"); + } + // 濡傛灉鏄痵tring蹇呴』濉啓瀛楃涓查暱搴� + if (real.getReadWriteType().equals("String")) { + if (real.getDataLength() == null) { + return Result.error("鏂囦欢瀵煎叆澶辫触:" + line + "琛岋紝瀛楃涓查暱搴︽湭濉啓"); + } + } + } + //update-begin-author:taoyan date:20190528 for:鎵归噺鎻掑叆鏁版嵁 + long start = System.currentTimeMillis(); + saveBatch(realList); + //400鏉� saveBatch娑堣�楁椂闂�1592姣 寰幆鎻掑叆娑堣�楁椂闂�1947姣 + //1200鏉� saveBatch娑堣�楁椂闂�3687姣 寰幆鎻掑叆娑堣�楁椂闂�5212姣 + log.info("娑堣�楁椂闂�" + (System.currentTimeMillis() - start) + "姣"); + //update-end-author:taoyan date:20190528 for:鎵归噺鎻掑叆鏁版嵁 + return Result.ok("鏂囦欢瀵煎叆鎴愬姛锛佹暟鎹鏁帮細" + realList.size()); + } catch (Exception e) { + log.error(e.getMessage(), e); + return Result.error("鏂囦欢瀵煎叆澶辫触:" + e.getMessage()); + } finally { + try { + file.getInputStream().close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return Result.error("鏂囦欢瀵煎叆澶辫触锛�"); + } + + /** + * 灏嗗瓧绗︿覆涓嫭鍙峰唴鐨勫唴瀹规浛鎹负x + * + * @param input 杈撳叆瀛楃涓诧紙濡�"Float16(16)"锛� + * @return 鏇挎崲鍚庣殑瀛楃涓诧紙濡�"Float16(x)"锛� + */ + public static String replaceWithX(String input) { + if (input == null || input.isEmpty() || !input.contains("(") || !input.contains(")")) { + return input; // 鏃犳嫭鍙锋垨鏍煎紡涓嶅畬鏁存椂鐩存帴杩斿洖 + } + return input.replaceFirst("\\(.*?\\)", "(x)"); + } + + @Override + public ModelAndView exportXls(HttpServletRequest request, RealParameter realParameter, String title) { + LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + // Step.2 鑾峰彇瀵煎嚭鏁版嵁 + List<RealParameter> pageList = new LambdaQueryChainWrapper<>(baseMapper) + .eq(RealParameter::getParameterGroupId, realParameter.getParameterGroupId()) + .list(); + // Step.3 AutoPoi 瀵煎嚭Excel + ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); + mv.addObject(NormalExcelConstants.FILE_NAME, title); //姝ゅ璁剧疆鐨刦ilename鏃犳晥 ,鍓嶇浼氶噸鏇存柊璁剧疆涓�涓� + mv.addObject(NormalExcelConstants.CLASS, RealParameter.class); + mv.addObject(NormalExcelConstants.PARAMS, new ExportParams(title + "鎶ヨ〃", "瀵煎嚭浜�:" + sysUser.getRealname(), title)); + mv.addObject(NormalExcelConstants.DATA_LIST, pageList); + return mv; + } + + @Override + public Integer findRealParameterGroupId(String groupCode) { + List<RealParameter> list = new LambdaQueryChainWrapper<>(baseMapper) + .eq(RealParameter::getParameterGroupId, groupCode) + .orderByDesc(RealParameter::getParameterCode) + .list(); + if (list.size() == 0) { + return 1; + } + return list.get(0).getParameterCode() + 1; + } + + @Override + public Result<?> canonicalParameter(String id) { + // 鏌ヨ鏈�鏂扮紪鍙� + Integer parameterCode = findRealParameterGroupId(id) - 1; + List<Parameter> parameters = equipmentService.findParameterById(id); + if (parameters == null) { + return Result.error("鏆傛棤鏍囧噯鍙傛暟"); + } + List<RealParameter> realParameter = new ArrayList<>(); + for (Parameter parameter : parameters) { + RealParameter real = new RealParameter(); + real.setParameterName(parameter.getName()); + real.setParameterType(parameter.getDataType()); + real.setAddress(parameter.getDefault1()); + real.setReadWriteType("鍙"); + List<Parameter> parameterList = equipmentService.findDataTypeById(id); + parameterList.forEach(p -> { + String replaceWithX = replaceWithX(real.getParameterType()); + if (replaceWithX.equals(p.getName())) { + real.setSystemDataType(p.getSystemDataType()); + } + }); + // 濉厖鍙傛暟 + parameterCode = parameterCode + 1; + real.setParameterGroupId(id); + real.setParameterCode(parameterCode); + realParameter.add(real); + } +// saveBatch(realParameter); + return Result.ok("瀵煎叆鎴愬姛"); + } + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ServerDeployServiceImpl.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ServerDeployServiceImpl.java new file mode 100644 index 0000000..c30890e --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/service/impl/ServerDeployServiceImpl.java @@ -0,0 +1,362 @@ +package org.jeecg.modules.iot.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.iot.entity.*; +import org.jeecg.modules.iot.service.*; +import org.jeecg.modules.iot.util.FtpUtil; +import org.jeecg.modules.iot.mapper.ServerDeployMapper; +import org.jeecg.modules.iot.mqtt.config.MqttCustomerClient; +import org.jeecg.modules.iot.util.FileUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Description: 椤圭洰鍒嗙被 + * @Author: cuikaidong + * @Date: 2024-12-20 + * @Version: V1.0 + */ +@Service +public class ServerDeployServiceImpl extends ServiceImpl<ServerDeployMapper, ServerDeploy> implements IServerDeployService { + + @Value("${ftp.address}") + private String ftpAddress; + @Autowired + private IInfluxdbDeployService influxdbDeployService; + @Autowired + private IMqttDeployService mqttDeployService; + @Autowired + @Lazy + private MqttCustomerClient mqttCustomerClient; + @Autowired + private IEquipmentService equipmentService; + @Autowired + private IParameterGroupService parameterGroupService; + @Autowired + private IRealParameterService realParameterService; + @Autowired + @Lazy + private IEmptyParameterService emptyParameterService; + + @Override + public ServerDeploy findByServerCode(String serverCode) { + ServerDeploy serverDeploy = new LambdaQueryChainWrapper<>(baseMapper) + .eq(ServerDeploy::getServerCode, serverCode) + .one(); + return serverDeploy; + } + + @Override + public List<ServerDeploy> findByProjectClassifyId(String id) { + return new LambdaQueryChainWrapper<>(baseMapper) + .eq(ServerDeploy::getProjectClassifyId, id) + .list(); + } + + @Override + public void updateServerGuardState(List<MqttClient> mqttClient) { + List<ServerDeploy> serverDeploys = this.list(); + serverDeploys.forEach(s -> { + s.setGuardState(0); + s.setCollectState(0); + }); + this.updateBatchById(serverDeploys); + // 淇敼瀹堟姢绋嬪簭鍦ㄧ嚎鐘舵�� + if (mqttClient != null && !mqttClient.isEmpty()) { + Set<String> collect = mqttClient.stream().map(MqttClient::getClientid).collect(Collectors.toSet()); + // 鏂规涓�锛氫娇鐢ㄦ潯浠跺垽鏂紝閬垮厤浼犲叆绌洪泦鍚� + List<ServerDeploy> serverDeployList; + if (CollectionUtils.isNotEmpty(collect)) { + serverDeployList = new LambdaQueryChainWrapper<>(baseMapper) + .in(ServerDeploy::getServerCode, collect) + .list(); + } else { + // 闆嗗悎涓虹┖鏃惰繑鍥炵┖鍒楄〃锛岄伩鍏嶆煡璇� + serverDeployList = Collections.emptyList(); + } + serverDeployList.forEach(l -> l.setGuardState(1)); + this.updateBatchById(serverDeployList); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result<?> addDeployDocument(String id) { + // 楠岃瘉FTP杩炴帴 + boolean isConnected = FtpUtil.testFtpConnection(); + if (!isConnected) { + return Result.error("FTP杩炴帴澶辫触锛岃妫�鏌ラ厤缃紒"); + } + // 鑾峰彇褰撳墠鏃堕棿 + Date now = new Date(); + // 瀹氫箟鏃ユ湡鏍煎紡 + SimpleDateFormat formatter = new SimpleDateFormat("MMddHHmmss"); + // 鏍煎紡鍖栧綋鍓嶆椂闂� + String formattedDate = formatter.format(now); + // 鏈嶅姟鍣ㄩ厤缃� + ServerDeploy serverDeploy = baseMapper.selectById(id); + // Mqtt閰嶇疆 + MqttDeploy mqttDeploy = mqttDeployService.findByServerIdMqttDeploy(id); + // influxdb閰嶇疆 + InfluxdbDeploy influxdbDeploy = influxdbDeployService.findByServerIdInfluxdb(id); + if (mqttDeploy == null) { + return Result.error("璇峰厛閰嶇疆MQTT鏈嶅姟"); + } + if (influxdbDeploy == null) { + return Result.error("璇峰厛閰嶇疆influxdb鏈嶅姟"); + } + + // 璁惧淇℃伅 + List<Equipment> equipmentList = equipmentService.findEquipmentByServerId(id); + // 鍙傛暟缁勪俊鎭� + List<ParameterGroup> parameterGroups = parameterGroupService.findParameterGroupByServerId(id); + // 瀹炶澶囧弬鏁� + List<RealParameter> realParameters = new ArrayList<>(); + if (!CollectionUtils.isEmpty(parameterGroups)) { + Set<String> parameterGroupIds = parameterGroups.stream().map(ParameterGroup::getId).collect(Collectors.toSet()); + realParameters = realParameterService.findRealParameterByIds(parameterGroupIds); + } + // 铏氳澶囧弬鏁� + List<EmptyParameter> emptyParameters = new ArrayList<>(); + if (!CollectionUtils.isEmpty(equipmentList)) { + Set<String> equipmentIds = equipmentList.stream().map(Equipment::getId).collect(Collectors.toSet()); + emptyParameters = emptyParameterService.findParameterByEquipmentIds(equipmentIds); + } + try { + // 鍒涘缓瑙f瀽鍣ㄥ伐鍘� + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = factory.newDocumentBuilder(); + Document document = db.newDocument(); + // 涓嶆樉绀簊tandalone="no" + document.setXmlStandalone(true); + Element bookstore = document.createElement("ServiceInfo"); + // 涓篵ookstore鑺傜偣娣诲姞灞炴�� + bookstore.setAttribute("ID", serverDeploy.getServerCode()); + bookstore.setAttribute("Name", serverDeploy.getServerName()); + bookstore.setAttribute("IP", serverDeploy.getServerAddress()); + bookstore.setAttribute("Port", serverDeploy.getServerPort()); + bookstore.setAttribute("FileVersion", serverDeploy.getLatestCollectVersion()); + bookstore.setAttribute("ParameterVersion", formattedDate); + // 鍚慴ookstore鏍硅妭鐐逛腑娣诲姞瀛愯妭鐐筨ook + // 鎺堟潈淇℃伅 + Element authorize = document.createElement("Authorize"); + // 涓篴uthorize鑺傜偣娣诲姞灞炴�� + authorize.setAttribute("Licence", serverDeploy.getAuthorize()); + // 灏哹ook鑺傜偣娣诲姞鍒癰ookstore鏍硅妭鐐逛腑 + bookstore.appendChild(authorize); + // 鎺ュ彛淇℃伅 + Element Interface = document.createElement("Interface"); + Element mqttService = document.createElement("MqttService"); + // 涓篒nterface鑺傜偣娣诲姞灞炴�� + if (mqttDeploy != null) { + mqttService.setAttribute("IP", mqttDeploy.getAddress()); + mqttService.setAttribute("Port", mqttDeploy.getPort().toString()); + mqttService.setAttribute("ClientID", mqttDeploy.getClintId()); + mqttService.setAttribute("User", mqttDeploy.getUserName()); + mqttService.setAttribute("PassWord", mqttDeploy.getUserPassword()); + } else { + mqttService.setAttribute("IP", ""); + mqttService.setAttribute("Port", ""); + mqttService.setAttribute("ClientID", ""); + mqttService.setAttribute("User", ""); + mqttService.setAttribute("PassWord", ""); + } + Element timingLibrary = document.createElement("TimingLibrary"); + if (influxdbDeploy != null) { + timingLibrary.setAttribute("IP", influxdbDeploy.getAddress()); + timingLibrary.setAttribute("Port", influxdbDeploy.getPort().toString()); + timingLibrary.setAttribute("Bucket", influxdbDeploy.getBucket()); + timingLibrary.setAttribute("Org", influxdbDeploy.getOrganization()); + timingLibrary.setAttribute("Token", influxdbDeploy.getAuthorizeCode()); + } else { + timingLibrary.setAttribute("IP", ""); + timingLibrary.setAttribute("Port", ""); + timingLibrary.setAttribute("Bucket", ""); + timingLibrary.setAttribute("Org", ""); + timingLibrary.setAttribute("Token", ""); + } + Interface.appendChild(mqttService); + Interface.appendChild(timingLibrary); + // 瀹炶澶囷紝铏氳澶囦俊鎭� + Element deviceInfos = document.createElement("DeviceInfos"); + // 娣诲姞灞炴�� + deviceInfos.setAttribute("WriteMessage", "IOT/" + serverDeploy.getServerCode() + "/WriteMessage"); + // 瀹炶澶囧垪琛ㄨ妭鐐� + Element actualDevices = document.createElement("ActualDevices"); + // 铏氳澶囧垪琛ㄨ妭鐐� + Element virtualDevices = document.createElement("VirtualDevices"); + // 閬嶅巻璁惧淇℃伅 + List<RealParameter> finalRealParameters = realParameters; + List<EmptyParameter> finalEmptyParameters = emptyParameters; + equipmentList.forEach(e -> { + if (e.getEquipmentType().equals(1)) { + Element deviceInfo = document.createElement("DeviceInfo"); // 璁惧鑺傜偣 + deviceInfo.setAttribute("ID", e.getEqptCode()); + deviceInfo.setAttribute("Name", e.getEqptName()); + deviceInfo.setAttribute("Model", e.getEqptModel()); + deviceInfo.setAttribute("Type", e.getEqptType()); + deviceInfo.setAttribute("Describe", e.getEqptDescribe()); + deviceInfo.setAttribute("ControlSystem", e.getControlSystem()); + deviceInfo.setAttribute("Protocol", e.getProtocol()); + deviceInfo.setAttribute("DriveType", e.getDriveType()); + deviceInfo.setAttribute("Address", e.getAddress()); + deviceInfo.setAttribute("LibraryName", e.getLibraryName()); + deviceInfo.setAttribute("Class", e.getClassName()); + deviceInfo.setAttribute("LibraryVersion", e.getLibraryVersion()); + deviceInfo.setAttribute("CollectionCycle", e.getCollectionCycle()); + deviceInfo.setAttribute("ReconnectCycle", e.getReconnectCycle()); + deviceInfo.setAttribute("IsCollection", e.getIsCollection()); + deviceInfo.setAttribute("FloatPosition", e.getFloatPosition()); + deviceInfo.setAttribute("ReadTopic", e.getReadTopic()); + deviceInfo.setAttribute("WriteTopic", e.getWriteTopic()); + actualDevices.appendChild(deviceInfo); + // 鍙傛暟缁勪俊鎭� + parameterGroups.forEach(p -> { + if (p.getEquipmentId().equals(e.getId())) { + Element groupInfo = document.createElement("GroupInfo"); // 鍙傛暟缁勮妭鐐� + groupInfo.setAttribute("ID", p.getCode()); + groupInfo.setAttribute("Name", p.getName()); + groupInfo.setAttribute("Describe", p.getRemark()); + groupInfo.setAttribute("CollectionCycle", p.getCollectionCycle()); + deviceInfo.appendChild(groupInfo); + if (!CollectionUtils.isEmpty(finalRealParameters)) { + finalRealParameters.forEach(r -> { + if (p.getId().equals(r.getParameterGroupId())) { + Element tagInfo = document.createElement("TagInfo"); // 鍙傛暟鑺傜偣 + tagInfo.setAttribute("ID", r.getParameterCode().toString()); + tagInfo.setAttribute("Name", r.getParameterName()); + tagInfo.setAttribute("Address", r.getAddress()); + tagInfo.setAttribute("DataType", r.getParameterType()); + if (r.getReadWriteType().equals("鍙")){ + tagInfo.setAttribute("ReadOrWrite", "R"); + }else{ + tagInfo.setAttribute("ReadOrWrite", "R/W"); + } + tagInfo.setAttribute("Describe", r.getParameterDescribe()); + tagInfo.setAttribute("TagType", "OutsideTag"); + tagInfo.setAttribute("DataLength", r.getDataLength() + ""); + groupInfo.appendChild(tagInfo); + } + }); + } + } + }); + } else if (e.getEquipmentType().equals(0)) { + Element emptyDeviceInfo = document.createElement("DeviceInfo"); // 璁惧鑺傜偣 + emptyDeviceInfo.setAttribute("ID", e.getEqptCode()); + emptyDeviceInfo.setAttribute("Name", e.getEqptName()); + if (e.getIsCollection().equals("1")) { + emptyDeviceInfo.setAttribute("IsCollection", "Y"); + } else { + emptyDeviceInfo.setAttribute("IsCollection", "N"); + } + emptyDeviceInfo.setAttribute("Remarks", e.getRemark()); + emptyDeviceInfo.setAttribute("ReadTopic", e.getReadTopic()); + emptyDeviceInfo.setAttribute("Measurement", e.getWriteTopic()); + virtualDevices.appendChild(emptyDeviceInfo); + // 鍙傛暟淇℃伅 + if (!CollectionUtils.isEmpty(equipmentList)) { + finalEmptyParameters.forEach(empty -> { + if (empty.getEquipmentId().equals(e.getId())) { + Element tagInfo = document.createElement("TagInfo"); // 鍙傛暟鑺傜偣 + tagInfo.setAttribute("ID", empty.getParameterCode() + ""); + tagInfo.setAttribute("Name", empty.getParameterName()); + tagInfo.setAttribute("SourcePath", empty.getAddress()); + tagInfo.setAttribute("DataType", empty.getParameterType()); + if (empty.getReadWriteType().equals("鍙")) { + tagInfo.setAttribute("ReadOrWrite", "R"); + } else { + tagInfo.setAttribute("ReadOrWrite", "R/W"); + } + tagInfo.setAttribute("Describe", empty.getParameterDescribe()); + if (empty.getType().equals("1")) { + tagInfo.setAttribute("TagType", "InsideTag"); + } else { + tagInfo.setAttribute("TagType", "CustomTag"); + } + tagInfo.setAttribute("ScriptName", ""); // 鑴氭湰鍚嶇О + tagInfo.setAttribute("ScriptTagList", empty.getScriptTagList());// 鑴氭湰鍦板潃 + tagInfo.setAttribute("DataLength", empty.getDataLength()); + emptyDeviceInfo.appendChild(tagInfo); + } + }); + } + } + }); + // 閬嶅巻鍙傛暟缁勪俊鎭� + // 閬嶅巻鍙傛暟淇℃伅 + deviceInfos.appendChild(actualDevices); // 缁欏疄璁惧锛岃櫄璁惧淇℃伅娣诲姞瀛愯妭鐐� + deviceInfos.appendChild(virtualDevices); // 缁欏疄璁惧锛岃櫄璁惧淇℃伅娣诲姞瀛愯妭鐐� + bookstore.appendChild(Interface); + bookstore.appendChild(deviceInfos); + // 灏哹ookstore鑺傜偣锛堝凡鍖呭惈book锛夋坊鍔犲埌dom鏍戜腑 + document.appendChild(bookstore); + // 鍒涘缓TransformerFactory瀵硅薄 + TransformerFactory tff = TransformerFactory.newInstance(); + // 鍒涘缓 Transformer瀵硅薄 + Transformer tf = tff.newTransformer(); + // 杈撳嚭鍐呭鏄惁浣跨敤鎹㈣ + tf.setOutputProperty(OutputKeys.ENCODING, "GB2312"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + // 鍒涘缓xml鏂囦欢骞跺啓鍏ュ唴瀹� + tf.transform(new DOMSource(document), new StreamResult(new File("/iot/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate + "/CollectionConfiguration.lmx"))); + // 鍒涘缓鍐欏簱琛ㄧ粨鏋勬煡璇㈣櫄璁惧鍒楄〃锛屽鍔犺澶囪〃 + equipmentService.createEmptyEquipmentTable(serverDeploy.getDeployIssueTime(),serverDeploy.getId()); + // 鏌ヨ铏氳澶囧弬鏁帮紝澧炲姞瀛楁 + emptyParameterService.createEmptyEmptyField(serverDeploy.getDeployIssueTime(),serverDeploy.getId()); + } catch (Exception e) { + e.printStackTrace(); + return Result.error("閰嶇疆鏂囦欢鐢熸垚澶辫触"); + } + // 鏇存柊鐗堟湰 + serverDeploy.setLatestDeployVersion(formattedDate); + serverDeploy.setDeployIssueTime(new Date()); + baseMapper.updateById(serverDeploy); + // 鐢熸垚鏈湴鏂囦欢澶� +// FileUtil.createDir("D:/iot/" + serverDeploy.getServerCode() + "/deploy/" + formattedDate); + FileUtil.createDir(ftpAddress + serverDeploy.getServerCode() + "/deploy/" + formattedDate + "/script"); + // 涓婁紶鍒癴tp + String basePath = "/deploy"; // FTP鏈嶅姟鍣ㄥ熀纭�鐩綍 + String filePath = serverDeploy.getServerCode() + "/deploy/" + formattedDate; // FTP鏈嶅姟鍣ㄦ枃浠跺瓨鏀捐矾寰勩�備緥濡傚垎鏃ユ湡瀛樻斁锛�/2015/01/01銆傛枃浠剁殑璺緞涓篵asePath+filePath + String filename = "CollectionConfiguration.lmx";// 涓婁紶鍒癋TP鏈嶅姟鍣ㄤ笂鐨勬枃浠跺悕 + //鍒涘缓涓�涓緭鍏ユ祦 + try { + FileInputStream fileInputStream = new FileInputStream(ftpAddress + serverDeploy.getServerCode() + "/deploy/" + formattedDate + "/CollectionConfiguration.lmx"); + FtpUtil.uploadFile(basePath, filePath, filename, fileInputStream); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + // 瀛樺偍鑴氭湰锛屽鍒舵暣涓枃浠跺す + FtpUtil.uploadFolder(new File(ftpAddress+serverDeploy.getServerCode()+"/script/"), "/deploy/"+serverDeploy.getServerCode()+"/deploy/"+formattedDate+"/script"); + // 鐢熸垚鑴氭湰 + // 鍙戦�侀厤缃枃浠剁増淇″彿 + MqttParameter mqttParameter = new MqttParameter(); + mqttParameter.setId(serverDeploy.getServerCode()); + mqttParameter.setType("version"); + mqttParameter.setParameter2(formattedDate); + mqttParameter.setParameter4(basePath +"/" +filePath); + mqttCustomerClient.pushlish(2, false, serverDeploy.getServerCode(), mqttParameter); + return Result.ok("閰嶇疆鏂囦欢鐢熸垚鎴愬姛"); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/AESUtil.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/AESUtil.java new file mode 100644 index 0000000..cdb1598 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/AESUtil.java @@ -0,0 +1,205 @@ +package org.jeecg.modules.iot.util; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.Base64Utils; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +/** + * AES鍔犲瘑宸ュ叿绫� + * + * @author ACGkaka + * @since 2021-06-18 19:11:03 + */ +public class AESUtil { + /** + * 鏃ュ織鐩稿叧 + */ + private static final Logger LOGGER = LoggerFactory.getLogger(AESUtil.class); + /** + * 缂栫爜 + */ + private static final String ENCODING = "UTF-8"; + /** + * 绠楁硶瀹氫箟 + */ + private static final String AES_ALGORITHM = "AES"; + /** + * 鎸囧畾濉厖鏂瑰紡 + */ + private static final String CIPHER_PADDING = "AES/ECB/PKCS5Padding"; + private static final String CIPHER_CBC_PADDING = "AES/CBC/PKCS5Padding"; + /** + * 鍋忕Щ閲�(CBC涓娇鐢紝澧炲己鍔犲瘑绠楁硶寮哄害) + */ + private static final String IV_SEED = "0000000000000000"; + + /** + * AES鍔犲瘑 + * + * @param content 寰呭姞瀵嗗唴瀹� + * @param aesKey 瀵嗙爜 + * @return + */ + public static String encrypt(String content, String aesKey) { + if (StringUtils.isBlank(content)) { + LOGGER.info("AES encrypt: the content is null!"); + return null; + } + //鍒ゆ柇绉橀挜鏄惁涓�16浣� + if (StringUtils.isNotBlank(aesKey) && aesKey.length() == 16) { + try { + //瀵瑰瘑鐮佽繘琛岀紪鐮� + byte[] bytes = aesKey.getBytes(ENCODING); + //璁剧疆鍔犲瘑绠楁硶锛岀敓鎴愮閽� + SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM); + // "绠楁硶/妯″紡/琛ョ爜鏂瑰紡" + Cipher cipher = Cipher.getInstance(CIPHER_PADDING); + //閫夋嫨鍔犲瘑 + cipher.init(Cipher.ENCRYPT_MODE, skeySpec); + //鏍规嵁寰呭姞瀵嗗唴瀹圭敓鎴愬瓧鑺傛暟缁� + byte[] encrypted = cipher.doFinal(content.getBytes(ENCODING)); + //杩斿洖base64瀛楃涓� + return Base64Utils.encodeToString(encrypted); + } catch (Exception e) { + LOGGER.info("AES encrypt exception:" + e.getMessage()); + throw new RuntimeException(e); + } + + } else { + LOGGER.info("AES encrypt: the aesKey is null or error!"); + return null; + } + } + + /** + * 瑙e瘑 + * + * @param content 寰呰В瀵嗗唴瀹� + * @param aesKey 瀵嗙爜 + * @return + */ + public static String decrypt(String content, String aesKey) { + if (StringUtils.isBlank(content)) { + LOGGER.info("AES decrypt: the content is null!"); + return null; + } + //鍒ゆ柇绉橀挜鏄惁涓�16浣� + if (StringUtils.isNotBlank(aesKey) && aesKey.length() == 16) { + try { + //瀵瑰瘑鐮佽繘琛岀紪鐮� + byte[] bytes = aesKey.getBytes(ENCODING); + //璁剧疆瑙e瘑绠楁硶锛岀敓鎴愮閽� + SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM); + // "绠楁硶/妯″紡/琛ョ爜鏂瑰紡" + Cipher cipher = Cipher.getInstance(CIPHER_PADDING); + //閫夋嫨瑙e瘑 + cipher.init(Cipher.DECRYPT_MODE, skeySpec); + + //鍏堣繘琛孊ase64瑙g爜 + byte[] decodeBase64 = Base64Utils.decodeFromString(content); + + //鏍规嵁寰呰В瀵嗗唴瀹硅繘琛岃В瀵� + byte[] decrypted = cipher.doFinal(decodeBase64); + //灏嗗瓧鑺傛暟缁勮浆鎴愬瓧绗︿覆 + return new String(decrypted, ENCODING); + } catch (Exception e) { + LOGGER.info("AES decrypt exception:" + e.getMessage()); + throw new RuntimeException(e); + } + + } else { + LOGGER.info("AES decrypt: the aesKey is null or error!"); + return null; + } + } + + /** + * AES_CBC鍔犲瘑 + * + * @param content 寰呭姞瀵嗗唴瀹� + * @param aesKey 瀵嗙爜 + * @return + */ + public static String encryptCBC(String content, String aesKey) { + if (StringUtils.isBlank(content)) { + LOGGER.info("AES_CBC encrypt: the content is null!"); + return null; + } + //鍒ゆ柇绉橀挜鏄惁涓�16浣� + if (StringUtils.isNotBlank(aesKey)) { + try { + //瀵瑰瘑鐮佽繘琛岀紪鐮� + byte[] bytes = aesKey.getBytes(ENCODING); + //璁剧疆鍔犲瘑绠楁硶锛岀敓鎴愮閽� + SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM); + // "绠楁硶/妯″紡/琛ョ爜鏂瑰紡" + Cipher cipher = Cipher.getInstance(CIPHER_CBC_PADDING); + //鍋忕Щ + IvParameterSpec iv = new IvParameterSpec(IV_SEED.getBytes(ENCODING)); + //閫夋嫨鍔犲瘑 + cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); + //鏍规嵁寰呭姞瀵嗗唴瀹圭敓鎴愬瓧鑺傛暟缁� + byte[] encrypted = cipher.doFinal(content.getBytes(ENCODING)); + //杩斿洖base64瀛楃涓� + return Base64Utils.encodeToString(encrypted); + } catch (Exception e) { + LOGGER.info("AES_CBC encrypt exception:" + e.getMessage()); + throw new RuntimeException(e); + } + + } else { + LOGGER.info("AES_CBC encrypt: the aesKey is null or error!"); + return null; + } + } + + /** + * AES_CBC瑙e瘑 + * + * @param content 寰呰В瀵嗗唴瀹� + * @param aesKey 瀵嗙爜 + * @return + */ + public static String decryptCBC(String content, String aesKey) { + if (StringUtils.isBlank(content)) { + LOGGER.info("AES_CBC decrypt: the content is null!"); + return null; + } + //鍒ゆ柇绉橀挜鏄惁涓�16浣� + if (StringUtils.isNotBlank(aesKey)) { + try { + //瀵瑰瘑鐮佽繘琛岀紪鐮� + byte[] bytes = aesKey.getBytes(ENCODING); + //璁剧疆瑙e瘑绠楁硶锛岀敓鎴愮閽� + SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM); + //鍋忕Щ + IvParameterSpec iv = new IvParameterSpec(IV_SEED.getBytes(ENCODING)); + // "绠楁硶/妯″紡/琛ョ爜鏂瑰紡" + Cipher cipher = Cipher.getInstance(CIPHER_CBC_PADDING); + //閫夋嫨瑙e瘑 + cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); + + //鍏堣繘琛孊ase64瑙g爜 + byte[] decodeBase64 = Base64Utils.decodeFromString(content); + + //鏍规嵁寰呰В瀵嗗唴瀹硅繘琛岃В瀵� + byte[] decrypted = cipher.doFinal(decodeBase64); + //灏嗗瓧鑺傛暟缁勮浆鎴愬瓧绗︿覆 + return new String(decrypted, ENCODING); + } catch (Exception e) { + LOGGER.info("AES_CBC decrypt exception:" + e.getMessage()); + throw new RuntimeException(e); + } + + } else { + LOGGER.info("AES_CBC decrypt: the aesKey is null or error!"); + return null; + } + } + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/DispatchUtil.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/DispatchUtil.java new file mode 100644 index 0000000..bce0695 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/DispatchUtil.java @@ -0,0 +1,21 @@ +package org.jeecg.modules.iot.util; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class DispatchUtil { + /** + * java鍘婚櫎瀛楃涓蹭腑鐨勭┖鏍笺�佸洖杞︺�佹崲琛岀銆佸埗琛ㄧ + * @param str + * @return + */ + public static String replaceBlank(String str) { + String dest = ""; + if (str!=null) { + Pattern p = Pattern.compile("\\s*|\t|\r|\n"); + Matcher m = p.matcher(str); + dest = m.replaceAll(""); + } + return dest; + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/FileUtil.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/FileUtil.java new file mode 100644 index 0000000..a0be9e2 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/FileUtil.java @@ -0,0 +1,371 @@ +package org.jeecg.modules.iot.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.io.*; + +public class FileUtil { + // 楠岃瘉瀛楃涓叉槸鍚︿负姝g‘璺緞鍚嶇殑姝e垯琛ㄨ揪寮� + private static String matches = "[A-Za-z]:\\\\[^:?\"><*]*"; + // 閫氳繃 sPath.matches(matches) 鏂规硶鐨勮繑鍥炲�煎垽鏂槸鍚︽纭� + // sPath 涓鸿矾寰勫瓧绗︿覆 + private static boolean flag = false; + private static File file; + + /** + * 鍒犻櫎鎸囧畾鐩綍鎴栨枃浠�(鏃犺瀛樺湪涓庡惁) + * + * @param deletePath String 鐩綍鎴栨枃浠惰矾寰� 濡� c:/fqf 鎴� c:/fd.txt + * @return boolean + */ + public static boolean deleteFolder(String deletePath) { + flag = false; + if (deletePath.matches(matches)) { + file = new File(deletePath); + if (!file.exists()) {// 鍒ゆ柇鐩綍鎴栨枃浠舵槸鍚﹀瓨鍦� + return flag; // 涓嶅瓨鍦ㄨ繑鍥� false + } else { + + if (file.isFile()) {// 鍒ゆ柇鏄惁涓烘枃浠� + return deleteFile(deletePath);// 涓烘枃浠舵椂璋冪敤鍒犻櫎鏂囦欢鏂规硶 + } else { + return deleteDirectory(deletePath);// 涓虹洰褰曟椂璋冪敤鍒犻櫎鐩綍鏂规硶 + } + } + } else { + System.out.println("瑕佷紶鍏ユ纭矾寰勶紒"); + return false; + } + } + + /** + * 鍒犻櫎鎸囧畾鏂囦欢 + * + * @param filePath String 鏂囦欢璺緞 濡� c:/fd.txt + * @return boolean + */ + public static boolean deleteFile(String filePath) { + flag = false; + file = new File(filePath); + if (file.isFile() && file.exists()) {// 璺緞涓烘枃浠朵笖涓嶄负绌哄垯杩涜鍒犻櫎 + file.delete();// 鏂囦欢鍒犻櫎 + flag = true; + } + return flag; + } + + /** + * 鍒犻櫎鐩綍锛堟枃浠跺す锛変互鍙婄洰褰曚笅鐨勬枃浠� + * + * @param dirPath String 鐩綍璺緞 濡� c:/fqf + * @return boolean + */ + public static boolean deleteDirectory(String dirPath) { + // 濡傛灉sPath涓嶄互鏂囦欢鍒嗛殧绗︾粨灏撅紝鑷姩娣诲姞鏂囦欢鍒嗛殧绗� + if (!dirPath.endsWith(File.separator)) { + dirPath = dirPath + File.separator; + } + File dirFile = new File(dirPath); + // 濡傛灉dir瀵瑰簲鐨勬枃浠朵笉瀛樺湪锛屾垨鑰呬笉鏄竴涓洰褰曪紝鍒欓��鍑� + if (!dirFile.exists() || !dirFile.isDirectory()) { + return false; + } + flag = true; + File[] files = dirFile.listFiles();// 鑾峰緱浼犲叆璺緞涓嬬殑鎵�鏈夋枃浠� + for (int i = 0; i < files.length; i++) {// 寰幆閬嶅巻鍒犻櫎鏂囦欢澶逛笅鐨勬墍鏈夋枃浠�(鍖呮嫭瀛愮洰褰�) + if (files[i].isFile()) {// 鍒犻櫎瀛愭枃浠� + flag = deleteFile(files[i].getAbsolutePath()); + System.out.println(files[i].getAbsolutePath() + " 鍒犻櫎鎴愬姛"); + if (!flag) + break;// 濡傛灉鍒犻櫎澶辫触锛屽垯璺冲嚭 + } else {// 杩愮敤閫掑綊锛屽垹闄ゅ瓙鐩綍 + flag = deleteDirectory(files[i].getAbsolutePath()); + if (!flag) + break;// 濡傛灉鍒犻櫎澶辫触锛屽垯璺冲嚭 + } + } + if (!flag) + return false; + if (dirFile.delete()) {// 鍒犻櫎褰撳墠鐩綍 + return true; + } else { + return false; + } + } + + /** + * 鍒涘缓鍗曚釜鏂囦欢 + * + * @param filePath String 鏂囦欢璺緞 濡� c:/fqf.txt + * @return boolean + */ + public static boolean createFile(String filePath) { + File file = new File(filePath); + if (file.exists()) {// 鍒ゆ柇鏂囦欢鏄惁瀛樺湪 + System.out.println("鐩爣鏂囦欢宸插瓨鍦�" + filePath); + return false; + } + if (filePath.endsWith(File.separator)) {// 鍒ゆ柇鏂囦欢鏄惁涓虹洰褰� + System.out.println("鐩爣鏂囦欢涓嶈兘涓虹洰褰曪紒"); + return false; + } + if (!file.getParentFile().exists()) {// 鍒ゆ柇鐩爣鏂囦欢鎵�鍦ㄧ殑鐩綍鏄惁瀛樺湪 + // 濡傛灉鐩爣鏂囦欢鎵�鍦ㄧ殑鏂囦欢澶逛笉瀛樺湪锛屽垯鍒涘缓鐖舵枃浠跺す + System.out.println("鐩爣鏂囦欢鎵�鍦ㄧ洰褰曚笉瀛樺湪锛屽噯澶囧垱寤哄畠锛�"); + if (!file.getParentFile().mkdirs()) {// 鍒ゆ柇鍒涘缓鐩綍鏄惁鎴愬姛 + System.out.println("鍒涘缓鐩爣鏂囦欢鎵�鍦ㄧ殑鐩綍澶辫触锛�"); + return false; + } + } + try { + if (file.createNewFile()) {// 鍒涘缓鐩爣鏂囦欢 + System.out.println("鍒涘缓鏂囦欢鎴愬姛:" + filePath); + return true; + } else { + System.out.println("鍒涘缓鏂囦欢澶辫触锛�"); + return false; + } + } catch (IOException e) {// 鎹曡幏寮傚父 + e.printStackTrace(); + System.out.println("鍒涘缓鏂囦欢澶辫触锛�" + e.getMessage()); + return false; + } + } + + /** + * 鏂板缓鏂囦欢 + * + * @param filePathAndName String 鏂囦欢璺緞鍙婂悕绉� 濡俢:/fqf.txt + * @param fileContent String 鏂囦欢鍐呭 + * @return void + */ + public static void createFile(String filePathAndName, String fileContent) { + + try { + String filePath = filePathAndName; + filePath = filePath.toString(); + File myFilePath = new File(filePath); + if (!myFilePath.exists()) { + myFilePath.createNewFile(); + } + FileWriter resultFile = new FileWriter(myFilePath); + PrintWriter myFile = new PrintWriter(resultFile); + String strContent = fileContent; + myFile.println(strContent); + resultFile.close(); + System.out.println("鏂板缓鏂囦欢鎴愬姛" + filePathAndName); + } catch (Exception e) { + System.out.println("鏂板缓鏂囦欢鎿嶄綔鍑洪敊"); + e.printStackTrace(); + + } + + } + + /** + * 鏌ヨ鐩綍鏄惁瀛樺湪锛堟枃浠跺す锛� + * + * @param catalogueName String 鐩綍璺緞 濡� c:/fqf + * @return boolean + */ + public static boolean queryCatalogue(String catalogueName) { + File dir = new File(catalogueName); + if (dir.exists()) {// 鍒ゆ柇鐩綍鏄惁瀛樺湪 + System.out.println("鍒涘缓鐩綍澶辫触锛岀洰鏍囩洰褰曞凡瀛樺湪锛�"); + return false; + } + return true; + } + + /** + * 鍒涘缓鐩綍锛堟枃浠跺す锛� + * + * @param destDirName String 鐩綍璺緞 濡� c:/fqf + * @return boolean + */ + public static boolean createDir(String destDirName) { + File dir = new File(destDirName); + if (dir.exists()) {// 鍒ゆ柇鐩綍鏄惁瀛樺湪 + System.out.println("鍒涘缓鐩綍澶辫触锛岀洰鏍囩洰褰曞凡瀛樺湪锛�"); + return false; + } + if (!destDirName.endsWith(File.separator)) {// 缁撳熬鏄惁浠�"/"缁撴潫 + destDirName = destDirName + File.separator; + } + if (dir.mkdirs()) {// 鍒涘缓鐩爣鐩綍 + System.out.println("鍒涘缓鐩綍鎴愬姛锛�" + destDirName); + return true; + } else { + System.out.println("鍒涘缓鐩綍澶辫触锛�"); + return false; + } + } + + /** + * 澶嶅埗鍗曚釜鏂囦欢 + * + * @param oldPath String 鍘熸枃浠惰矾寰� 濡傦細c:/fqf.txt + * @param newPath String 澶嶅埗鍚庤矾寰� 濡傦細f:/fqf.txt + * @return boolean + */ + public static void copyFile(String oldPath, String newPath) { + try { + int bytesum = 0; + int byteread = 0; + File oldfile = new File(oldPath); + if (oldfile.exists()) { //鏂囦欢瀛樺湪鏃� + InputStream inStream = new FileInputStream(oldPath); //璇诲叆鍘熸枃浠� + FileOutputStream fs = new FileOutputStream(newPath); + byte[] buffer = new byte[1444]; + int length; + while ((byteread = inStream.read(buffer)) != -1) { + bytesum += byteread; //瀛楄妭鏁� 鏂囦欢澶у皬 + System.out.println("鏂囦欢澶у皬锛�" + bytesum + "瀛楄妭"); + fs.write(buffer, 0, byteread); + } + inStream.close(); + fs.close(); + } + } catch (Exception e) { + System.out.println("澶嶅埗鍗曚釜鏂囦欢鎿嶄綔鍑洪敊"); + e.printStackTrace(); + } + } + + /** + * 澶嶅埗鍗曚釜鏂囦欢 + * + * @param source String 鍘熸枃浠惰矾寰� 濡傦細c:/fqf.txt + * @param dest String 澶嶅埗鍚庤矾寰� 濡傦細f:/fqf.txt + * @return boolean + */ + private static void copyFile2(String source, String dest) { + try { + File in = new File(source); + File out = new File(dest); + FileInputStream inFile = new FileInputStream(in); + FileOutputStream outFile = new FileOutputStream(out); + byte[] buffer = new byte[1024]; + int i = 0; + while ((i = inFile.read(buffer)) != -1) { + outFile.write(buffer, 0, i); + }//end while + inFile.close(); + outFile.close(); + }//end try + catch (Exception e) { + + }//end catch + }//end copyFile + + /** + * 澶嶅埗鏁翠釜鏂囦欢澶瑰唴瀹� + * + * @param oldPath String 鍘熸枃浠惰矾寰� 濡傦細c:/fqf + * @param newPath String 澶嶅埗鍚庤矾寰� 濡傦細f:/fqf/ff + * @return boolean + */ + public static void copyFolder(String oldPath, String newPath) { + try { + (new File(newPath)).mkdirs(); //濡傛灉鏂囦欢澶逛笉瀛樺湪 鍒欏缓绔嬫柊鏂囦欢澶� + File a = new File(oldPath); + String[] file = a.list(); + File temp = null; + for (int i = 0; i < file.length; i++) { + if (oldPath.endsWith(File.separator)) { + temp = new File(oldPath + file[i]); + } else { + temp = new File(oldPath + File.separator + file[i]); + } + + if (temp.isFile()) { + FileInputStream input = new FileInputStream(temp); + FileOutputStream output = new FileOutputStream(newPath + "/" + + (temp.getName()).toString()); + byte[] b = new byte[1024 * 5]; + int len; + while ((len = input.read(b)) != -1) { + output.write(b, 0, len); + } + output.flush(); + output.close(); + input.close(); + } + if (temp.isDirectory()) {//濡傛灉鏄瓙鏂囦欢澶� + copyFolder(oldPath + "/" + file[i], newPath + "/" + file[i]); + } + } + System.out.println("澶嶅埗鏁翠釜鏂囦欢澶瑰唴瀹规垚鍔燂紝鏂囦欢鎬绘暟锛�" + file.length); + } catch (Exception e) { + System.out.println("澶嶅埗鏁翠釜鏂囦欢澶瑰唴瀹规搷浣滃嚭閿�"); + e.printStackTrace(); + } + } + + /** + * 绉诲姩鏂囦欢鍒版寚瀹氱洰褰� + * + * @param oldPath String 濡傦細c:/fqf.txt + * @param newPath String 濡傦細d:/fqf.txt + */ + public static void moveFile(String oldPath, String newPath) { + copyFile(oldPath, newPath); + deleteFolder(oldPath); + } + + /** + * 绉诲姩鏂囦欢澶瑰埌鎸囧畾鐩綍 + * + * @param oldPath String 濡傦細c:/fqf.txt + * @param newPath String 濡傦細d:/fqf.txt + */ + public static void moveFolder(String oldPath, String newPath) { + copyFolder(oldPath, newPath); + deleteFolder(oldPath); + } + + /** + * 鍒涘缓涓存椂鏂囦欢 + * + * @param prefix String 鏂囦欢鍚嶇О鍓嶇紑 濡� temp2478577457.txt + * @param suffix String 鏂囦欢绫诲瀷 濡� .txt /.docx + * @return string + */ + public static String createTempFile(String prefix, String suffix, + String dirName) { + File tempFile = null; + if (dirName == null) {// 鐩綍濡傛灉涓虹┖ + try { + tempFile = File.createTempFile(prefix, suffix);// 鍦ㄩ粯璁ゆ枃浠跺す涓嬪垱寤轰复鏃舵枃浠� + return tempFile.getCanonicalPath();// 杩斿洖涓存椂鏂囦欢鐨勮矾寰� + } catch (IOException e) {// 鎹曡幏寮傚父 + e.printStackTrace(); + System.out.println("鍒涘缓涓存椂鏂囦欢澶辫触锛�" + e.getMessage()); + return null; + } + } else { + // 鎸囧畾鐩綍瀛樺湪 + File dir = new File(dirName);// 鍒涘缓鐩綍 + if (!dir.exists()) { + // 濡傛灉鐩綍涓嶅瓨鍦ㄥ垯鍒涘缓鐩綍 + if (FileUtil.createDir(dirName)) { + System.out.println("鍒涘缓涓存椂鏂囦欢澶辫触锛屼笉鑳藉垱寤轰复鏃舵枃浠舵墍鍦ㄧ殑鐩綍锛�"); + return null; + } + } + try { + tempFile = File.createTempFile(prefix, suffix, dir);// 鍦ㄦ寚瀹氱洰褰曚笅鍒涘缓涓存椂鏂囦欢 + return tempFile.getCanonicalPath();// 杩斿洖涓存椂鏂囦欢鐨勮矾寰� + } catch (IOException e) {// 鎹曡幏寮傚父 + e.printStackTrace(); + System.out.println("鍒涘缓涓存椂鏂囦欢澶辫触!" + e.getMessage()); + return null; + } + } + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/FtpUtil.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/FtpUtil.java new file mode 100644 index 0000000..3372d31 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/FtpUtil.java @@ -0,0 +1,434 @@ + +package org.jeecg.modules.iot.util; + +/** + * @Description: Ftp閰嶇疆 + * @Author: cuikaidong + * @Date: 2024-12-10 + * @Version: V1.0 + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.net.ftp.FTP; +import org.apache.commons.net.ftp.FTPClient; +import org.apache.commons.net.ftp.FTPReply; +import org.springframework.beans.factory.annotation.Value; + +import java.io.*; +import java.net.SocketException; + +public class FtpUtil { + private final static Log logger = LogFactory.getLog(FtpUtil.class); + + /** + * 鏈湴瀛楃缂栫爜 + */ + private static String LOCAL_CHARSET = "GBK"; + + // FTP鍗忚閲岄潰锛岃瀹氭枃浠跺悕缂栫爜涓篿so-8859-1 + private static String SERVER_CHARSET = "ISO-8859-1"; + //ftp鏈嶅姟鍣↖P鍦板潃 锛屾柊鐏偓10.210.199.2,璧疯惤鏋�10.0.221.200 + private static String ftpHost = "10.10.10.98"; + //ftp鏈嶅姟鍣ㄧ鍙� + private static int ftpPort = 21; + //ftp鏈嶅姟鍣ㄧ敤鎴峰悕 + private static String ftpUserName = "admin"; + //ftp鏈嶅姟鍣ㄥ瘑鐮� + private static String ftpPassword = "lx@2024"; + + + /** + * 楠岃瘉FTP杩炴帴鏄惁鍙敤 + * + * @return true锛氳繛鎺ユ垚鍔燂紱false锛氳繛鎺ュけ璐� + */ + public static boolean testFtpConnection() { + FTPClient ftpClient = new FTPClient(); + try { + // 杩炴帴FTP鏈嶅姟鍣� + ftpClient.connect(ftpHost, ftpPort); + // 鐧诲綍楠岃瘉 + boolean loginResult = ftpClient.login(ftpUserName, ftpPassword); + + // 妫�鏌ヨ繛鎺ョ姸鎬佸拰鐧诲綍缁撴灉 + int replyCode = ftpClient.getReplyCode(); + boolean isConnected = FTPReply.isPositiveCompletion(replyCode) && loginResult; + + if (isConnected) { + logger.info("FTP杩炴帴楠岃瘉鎴愬姛锛�"); + } else { + logger.error("FTP杩炴帴澶辫触锛氱敤鎴峰悕/瀵嗙爜閿欒鎴栨湇鍔″櫒涓嶅彲杈�"); + } + return isConnected; + } catch (SocketException e) { + logger.error("FTP鏈嶅姟鍣↖P鍦板潃閿欒鎴栫鍙h鍗犵敤锛�" + e.getMessage()); + } catch (IOException e) { + logger.error("FTP杩炴帴寮傚父锛�" + e.getMessage()); + } finally { + // 閲婃斁璧勬簮 + if (ftpClient.isConnected()) { + try { + ftpClient.logout(); + ftpClient.disconnect(); + } catch (IOException e) { + logger.warn("鍏抽棴FTP杩炴帴鏃跺彂鐢熷紓甯革細" + e.getMessage()); + } + } + } + return false; + } + + /** + * 鑾峰彇FTPClient瀵硅薄 + * + * @return + */ + public static FTPClient getFTPClient() { + + FTPClient ftpClient = null; + try { + ftpClient = new FTPClient(); + ftpClient.connect(ftpHost, ftpPort);// 杩炴帴FTP鏈嶅姟鍣� + ftpClient.login(ftpUserName, ftpPassword);// 鐧婚檰FTP鏈嶅姟鍣� + if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { + logger.info("鏈繛鎺ュ埌FTP锛岀敤鎴峰悕鎴栧瘑鐮侀敊璇��"); + ftpClient.disconnect(); + } else { + logger.info("FTP杩炴帴鎴愬姛銆�"); + } + } catch (SocketException e) { + e.printStackTrace(); + logger.info("FTP鐨処P鍦板潃鍙兘閿欒锛岃姝g‘閰嶇疆銆�"); + } catch (IOException e) { + e.printStackTrace(); + logger.info("FTP鐨勭鍙i敊璇�,璇锋纭厤缃��"); + } + return ftpClient; + } + + /** + * 浠嶧TP鏈嶅姟鍣ㄤ笅杞芥枃浠� + * + * @param ftpHost FTP IP鍦板潃 + * @param ftpUserName FTP 鐢ㄦ埛鍚� + * @param ftpPassword FTP鐢ㄦ埛鍚嶅瘑鐮� + * @param ftpPort FTP绔彛 + * @param ftpPath FTP鏈嶅姟鍣ㄤ腑鏂囦欢鎵�鍦ㄨ矾寰� 鏍煎紡锛� ftptest/aa + * @param localPath 涓嬭浇鍒版湰鍦扮殑浣嶇疆 鏍煎紡锛欻:/download + * @param fileName 鏂囦欢鍚嶇О + */ + public static void downloadFtpFile(String ftpHost, String ftpUserName, String ftpPassword, int ftpPort, + String ftpPath, String localPath, String fileName) { + + FTPClient ftpClient = null; + + try { + ftpClient = getFTPClient(); + // 璁剧疆涓婁紶鏂囦欢鐨勭被鍨嬩负浜岃繘鍒剁被鍨� + if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) {// 寮�鍚湇鍔″櫒瀵筓TF-8鐨勬敮鎸侊紝濡傛灉鏈嶅姟鍣ㄦ敮鎸佸氨鐢║TF-8缂栫爜锛屽惁鍒欏氨浣跨敤鏈湴缂栫爜锛圙BK锛�. + LOCAL_CHARSET = "UTF-8"; + } + ftpClient.setControlEncoding(LOCAL_CHARSET); + ftpClient.enterLocalPassiveMode();// 璁剧疆琚姩妯″紡 + ftpClient.setFileType(FTP.BINARY_FILE_TYPE);// 璁剧疆浼犺緭鐨勬ā寮� + // 涓婁紶鏂囦欢 + //瀵逛腑鏂囨枃浠跺悕杩涜杞爜锛屽惁鍒欎腑鏂囧悕绉扮殑鏂囦欢涓嬭浇澶辫触 + String fileNameTemp = new String(fileName.getBytes(LOCAL_CHARSET), SERVER_CHARSET); + ftpClient.changeWorkingDirectory(ftpPath); + + InputStream retrieveFileStream = ftpClient.retrieveFileStream(fileNameTemp); + + // 绗竴绉嶆柟寮忎笅杞芥枃浠�(鎺ㄨ崘) + /* File localFile = new File(localPath + File.separatorChar + fileName); + OutputStream os = new FileOutputStream(localFile); + ftpClient.retrieveFile(fileName, os); os.close();*/ + + + // 绗簩绉嶆柟寮忎笅杞斤細灏嗚緭鍏ユ祦杞垚瀛楄妭锛屽啀鐢熸垚鏂囦欢锛岃繖绉嶆柟寮忔柟渚垮皢瀛楄妭鏁扮粍鐩存帴杩斿洖缁欏墠鍙癹sp椤甸潰 + byte[] input2byte = input2byte(retrieveFileStream); + byte2File(input2byte, localPath, fileName); + + if (null != retrieveFileStream) { + retrieveFileStream.close(); + } + } catch (FileNotFoundException e) { + logger.error("娌℃湁鎵惧埌" + ftpPath + "鏂囦欢"); + e.printStackTrace(); + } catch (SocketException e) { + logger.error("杩炴帴FTP澶辫触."); + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + logger.error("鏂囦欢璇诲彇閿欒銆�"); + e.printStackTrace(); + } finally { + + if (ftpClient.isConnected()) { + try { + //閫�鍑虹櫥褰� + ftpClient.logout(); + //鍏抽棴杩炴帴 + ftpClient.disconnect(); + } catch (IOException e) { + } + } + } + } + + /** + * Description: 鍚慒TP鏈嶅姟鍣ㄤ笂浼犳枃浠� + * + * @param basePath FTP鏈嶅姟鍣ㄥ熀纭�鐩綍 + * @param filePath FTP鏈嶅姟鍣ㄦ枃浠跺瓨鏀捐矾寰勩�備緥濡傚垎鏃ユ湡瀛樻斁锛�/2015/01/01銆傛枃浠剁殑璺緞涓篵asePath+filePath + * @param filename 涓婁紶鍒癋TP鏈嶅姟鍣ㄤ笂鐨勬枃浠跺悕 + * @param input 杈撳叆娴� + * @return 鎴愬姛杩斿洖true锛屽惁鍒欒繑鍥瀎alse + */ + public static boolean uploadFile(String basePath, String filePath, String filename, InputStream input) { + boolean result = false; + FTPClient ftpClient = null; + try { + int reply; + ftpClient = getFTPClient(); + reply = ftpClient.getReplyCode(); + if (!FTPReply.isPositiveCompletion(reply)) { + ftpClient.disconnect(); + return result; + } + // 鍒囨崲鍒颁笂浼犵洰褰� + if (!ftpClient.changeWorkingDirectory(basePath + filePath)) { + // 濡傛灉鐩綍涓嶅瓨鍦ㄥ垱寤虹洰褰� + String[] dirs = filePath.split("/"); + String tempPath = basePath; + for (String dir : dirs) { + if (null == dir || "".equals(dir)) + continue; + tempPath += "/" + dir; + if (!ftpClient.changeWorkingDirectory(tempPath)) { + if (!ftpClient.makeDirectory(tempPath)) { + return result; + } else { + ftpClient.changeWorkingDirectory(tempPath); + } + } + } + } + // 璁剧疆涓婁紶鏂囦欢鐨勭被鍨嬩负浜岃繘鍒剁被鍨� + if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) {// 寮�鍚湇鍔″櫒瀵筓TF-8鐨勬敮鎸侊紝濡傛灉鏈嶅姟鍣ㄦ敮鎸佸氨鐢║TF-8缂栫爜锛屽惁鍒欏氨浣跨敤鏈湴缂栫爜锛圙BK锛�. + LOCAL_CHARSET = "UTF-8"; + } + ftpClient.setControlEncoding(LOCAL_CHARSET); + ftpClient.enterLocalPassiveMode();// 璁剧疆琚姩妯″紡 + ftpClient.setFileType(FTP.BINARY_FILE_TYPE);// 璁剧疆浼犺緭鐨勬ā寮� + // 涓婁紶鏂囦欢 + filename = new String(filename.getBytes(LOCAL_CHARSET), SERVER_CHARSET); + if (!ftpClient.storeFile(filename, input)) { + return result; + } + + if (null != input) { + input.close(); + } + + result = true; + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (ftpClient.isConnected()) { + try { + //閫�鍑虹櫥褰� + ftpClient.logout(); + //鍏抽棴杩炴帴 + ftpClient.disconnect(); + } catch (IOException ioe) { + } + } + } + return result; + } + + /** + * 鍒犻櫎鏂囦欢 鏈祴璇� + * + * @param ftpHost FTP鏈嶅姟鍣ㄥ湴鍧� + * @param ftpPort FTP鏈嶅姟鍣ㄧ鍙e彿 + * @param ftpUserName FTP鐧诲綍甯愬彿 + * @param ftpPassword FTP鐧诲綍瀵嗙爜 + * @param pathname FTP鏈嶅姟鍣ㄤ繚瀛樼洰褰� + * @param filename 瑕佸垹闄ょ殑鏂囦欢鍚嶇О + * @return + */ + public static boolean deleteFile(String ftpHost, int ftpPort, String ftpUserName, String ftpPassword, String pathname, + String filename) { + boolean flag = false; + FTPClient ftpClient = new FTPClient(); + try { + ftpClient = getFTPClient(); + // 楠岃瘉FTP鏈嶅姟鍣ㄦ槸鍚︾櫥褰曟垚鍔� + int replyCode = ftpClient.getReplyCode(); + if (!FTPReply.isPositiveCompletion(replyCode)) { + return flag; + } + // 鍒囨崲FTP鐩綍 + ftpClient.changeWorkingDirectory(pathname); + // 璁剧疆涓婁紶鏂囦欢鐨勭被鍨嬩负浜岃繘鍒剁被鍨� + if (FTPReply.isPositiveCompletion(ftpClient.sendCommand("OPTS UTF8", "ON"))) {// 寮�鍚湇鍔″櫒瀵筓TF-8鐨勬敮鎸侊紝濡傛灉鏈嶅姟鍣ㄦ敮鎸佸氨鐢║TF-8缂栫爜锛屽惁鍒欏氨浣跨敤鏈湴缂栫爜锛圙BK锛�. + LOCAL_CHARSET = "UTF-8"; + } + ftpClient.setControlEncoding(LOCAL_CHARSET); + ftpClient.enterLocalPassiveMode();// 璁剧疆琚姩妯″紡 + ftpClient.setFileType(FTP.BINARY_FILE_TYPE);// 璁剧疆浼犺緭鐨勬ā寮� + //瀵逛腑鏂囧悕绉拌繘琛岃浆鐮� + filename = new String(filename.getBytes(LOCAL_CHARSET), SERVER_CHARSET); + ftpClient.dele(filename); + flag = true; + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (ftpClient.isConnected()) { + try { + //閫�鍑虹櫥褰� + ftpClient.logout(); + //鍏抽棴杩炴帴 + ftpClient.disconnect(); + } catch (IOException e) { + } + } + } + return flag; + } + + /** + * 鍒涘缓鏂囦欢澶� + * + * @param pathname + * @param filename + * @return + */ + public static boolean createFolder(String pathname, String filename) { + boolean flag = false; + FTPClient ftpClient = new FTPClient(); + try { + ftpClient = getFTPClient(); + // 楠岃瘉FTP鏈嶅姟鍣ㄦ槸鍚︾櫥褰曟垚鍔� + int replyCode = ftpClient.getReplyCode(); + if (!FTPReply.isPositiveCompletion(replyCode)) { + return flag; + } + // 鍒囨崲FTP鐩綍 + ftpClient.changeWorkingDirectory(pathname); + boolean created = ftpClient.makeDirectory(filename); + if (created) { + logger.info(filename + "鏂囦欢澶瑰垱寤烘垚鍔�"); + } else { + logger.info(filename + "鍒涘缓鏂囦欢澶瑰け璐�"); + } + flag = true; + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (ftpClient.isConnected()) { + try { + //閫�鍑虹櫥褰� + ftpClient.logout(); + //鍏抽棴杩炴帴 + ftpClient.disconnect(); + } catch (IOException e) { + } + } + } + return flag; + } + + public static void uploadFolder(File localFolder, String remoteFolder) { + if (!localFolder.exists()) { + return; + } + FTPClient ftpClient = getFTPClient(); + try { + // 鍒涘缓杩滅▼鏂囦欢澶� + if (!ftpClient.changeWorkingDirectory(remoteFolder)) { + ftpClient.makeDirectory(remoteFolder); + ftpClient.changeWorkingDirectory(remoteFolder); + } + } catch (IOException e) { + e.printStackTrace(); + } + // 閬嶅巻鏈湴鏂囦欢澶逛腑鐨勬枃浠跺拰瀛愭枃浠跺す + File[] files = localFolder.listFiles(); + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + // 閫掑綊涓婁紶瀛愭枃浠跺す + uploadFolder(file, remoteFolder + "/" + file.getName()); + } else { + try { + // 涓婁紶鏂囦欢 + uploadFile1(ftpClient, file, remoteFolder); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + } + + private static void uploadFile1(FTPClient ftpClient, File localFile, String remoteFolder) throws IOException { + try (FileInputStream inputStream = new FileInputStream(localFile)) { + ftpClient.storeFile(remoteFolder + "/" + localFile.getName(), inputStream); + } + } + + // 灏嗗瓧鑺傛暟缁勮浆鎹负杈撳叆娴� + public static final InputStream byte2Input(byte[] buf) { + return new ByteArrayInputStream(buf); + } + + // 灏嗚緭鍏ユ祦杞负byte[] + public static final byte[] input2byte(InputStream inStream) throws IOException { + ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); + byte[] buff = new byte[100]; + int rc = 0; + while ((rc = inStream.read(buff, 0, 100)) > 0) { + swapStream.write(buff, 0, rc); + } + byte[] in2b = swapStream.toByteArray(); + return in2b; + } + + // 灏哹yte[]杞负鏂囦欢 + public static void byte2File(byte[] buf, String filePath, String fileName) { + BufferedOutputStream bos = null; + FileOutputStream fos = null; + File file = null; + try { + File dir = new File(filePath); + if (!dir.exists() && dir.isDirectory()) { + dir.mkdirs(); + } + file = new File(filePath + File.separator + fileName); + fos = new FileOutputStream(file); + bos = new BufferedOutputStream(fos); + bos.write(buf); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (bos != null) { + try { + bos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/HttpClientUtil.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/HttpClientUtil.java new file mode 100644 index 0000000..32aa778 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/HttpClientUtil.java @@ -0,0 +1,178 @@ +package org.jeecg.modules.iot.util; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.apache.http.NameValuePair; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +import java.net.URI; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +public class HttpClientUtil { + + public static String doGet(String url, Map<String, String> param) { + + // 鍒涘缓Httpclient瀵硅薄 + CloseableHttpClient httpclient = HttpClients.createDefault(); + + String resultString = ""; + CloseableHttpResponse response = null; + try { + // 鍒涘缓uri + URIBuilder builder = new URIBuilder(url); + if (param != null) { + for (String key : param.keySet()) { + builder.addParameter(key, param.get(key)); + } + } + URI uri = builder.build(); + + // 鍒涘缓http GET璇锋眰 + HttpGet httpGet = new HttpGet(uri); + + // 鎵ц璇锋眰 + response = httpclient.execute(httpGet); + // 鍒ゆ柇杩斿洖鐘舵�佹槸鍚︿负200 + if (response.getStatusLine().getStatusCode() == 200) { + resultString = EntityUtils.toString(response.getEntity(), "UTF-8"); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (response != null) { + response.close(); + } + httpclient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return resultString; + } + + public static String doGet(String url) { + return doGet(url, null); + } + + public static String doPost(String url, Map<String, String> param) { + // 鍒涘缓Httpclient瀵硅薄 + CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpResponse response = null; + String resultString = ""; + try { + // 鍒涘缓Http Post璇锋眰 + HttpPost httpPost = new HttpPost(url); + // 鍒涘缓鍙傛暟鍒楄〃 + if (param != null) { + List<NameValuePair> paramList = new ArrayList<>(); + for (String key : param.keySet()) { + paramList.add(new BasicNameValuePair(key, param.get(key))); + } + // 妯℃嫙琛ㄥ崟 + UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList); + httpPost.setEntity(entity); + } + // 鎵цhttp璇锋眰 + response = httpClient.execute(httpPost); + resultString = EntityUtils.toString(response.getEntity(), "utf-8"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + response.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + return resultString; + } + + public static String doPost(String url) { + return doPost(url, null); + } + + public static String doPostJson(String url, String json) { + // 鍒涘缓Httpclient瀵硅薄 + CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpResponse response = null; + String resultString = ""; + try { + // 鍒涘缓Http Post璇锋眰 + HttpPost httpPost = new HttpPost(url); + // 鍒涘缓璇锋眰鍐呭 + StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); + httpPost.setEntity(entity); + // 鎵цhttp璇锋眰 + response = httpClient.execute(httpPost); + resultString = EntityUtils.toString(response.getEntity(), "utf-8"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + response.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + return resultString; + } + + /** + * 楠岃瘉甯︽煡璇㈠弬鏁扮殑鎺ュ彛锛坧ath 涓哄繀濉煡璇㈠弬鏁帮級 + * @param baseUrl 鎺ュ彛鍩虹 URL锛堝 http://localhost:3002/ScriptCompiler锛� + * @param pathValue path 鍙傛暟鍊� + * @param timeoutMs 瓒呮椂鏃堕棿锛堟绉掞級 + * @return 杩為�氳繑鍥� true锛屽惁鍒欒繑鍥� false + */ + public static boolean verifyConnectionWithQueryParam( + String baseUrl, + String pathValue, + int timeoutMs) { + + // 瀵� path 鍙傛暟杩涜 URL 缂栫爜锛堝鐞嗙壒娈婂瓧绗︼紝濡備腑鏂囥�佺┖鏍肩瓑锛� + String encodedPath = pathValue; + + // 鎷兼帴瀹屾暣 URL锛�?path=缂栫爜鍚庣殑鍊硷級 + String fullUrl = baseUrl + "?path=" + encodedPath; + + OkHttpClient client = new OkHttpClient.Builder() + .connectTimeout(timeoutMs, TimeUnit.MILLISECONDS) + .readTimeout(timeoutMs, TimeUnit.MILLISECONDS) + .build(); + + Request request = new Request.Builder() + .url(fullUrl) + .get() + .build(); + + try (Response response = client.newCall(request).execute()) { + int statusCode = response.code(); + return statusCode >= 200 && statusCode < 300; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } +} + diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/JaxbUtil.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/JaxbUtil.java new file mode 100644 index 0000000..05ebca3 --- /dev/null +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/iot/util/JaxbUtil.java @@ -0,0 +1,51 @@ +package org.jeecg.modules.iot.util; + +import lombok.extern.slf4j.Slf4j; + +import javax.xml.bind.*; +import java.io.*; + +/** + * JAXB宸ュ叿绫� + * + * @author cuikaidong + * 2024骞�12鏈�20鏃� + */ +@Slf4j +public class JaxbUtil { + private static JAXBContext jaxbContext; + + //xml杞琷ava瀵硅薄 + public static Object xmlToBean(String str, Class<?> load) { + Object object = null; + try { + File file = new File(str); + JAXBContext jaxbContext = JAXBContext.newInstance(load); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + object = unmarshaller.unmarshal(file); + } catch (JAXBException e) { + log.error("xml杞崲鍒板疄浣撴椂鍑洪敊锛寈ml淇℃伅={},鎶ラ敊淇℃伅={}!", str, e); + } + return object; + } + + //java瀵硅薄杞瑇ml + public static String beanToXml(Object obj) { + StringWriter writer = null; + try { + jaxbContext = JAXBContext.newInstance(obj.getClass()); + Marshaller marshaller = jaxbContext.createMarshaller(); + //Marshaller.JAXB_FRAGMENT:鏄惁鐪佺暐xml澶翠俊鎭�,true鐪佺暐锛宖alse涓嶇渷鐣� + marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); + //Marshaller.JAXB_FORMATTED_OUTPUT:鍐冲畾鏄惁鍦ㄨ浆鎹㈡垚xml鏃跺悓鏃惰繘琛屾牸寮忓寲锛堝嵆鎸夋爣绛捐嚜鍔ㄦ崲琛岋紝鍚﹀垯鍗虫槸涓�琛岀殑xml锛� + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + //Marshaller.JAXB_ENCODING:xml鐨勭紪鐮佹柟寮� + marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); + writer = new StringWriter(); + marshaller.marshal(obj, writer); + } catch (JAXBException e) { + log.info(e.getMessage()); + } + return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + writer.toString(); + } +} diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/message/websocket/WebSocket.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/message/websocket/WebSocket.java index b2ccf23..fe881f7 100644 --- a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/message/websocket/WebSocket.java +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/message/websocket/WebSocket.java @@ -1,7 +1,9 @@ package org.jeecg.modules.message.websocket; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; import javax.annotation.Resource; import javax.websocket.*; import javax.websocket.server.PathParam; @@ -23,7 +25,8 @@ @Slf4j @ServerEndpoint("/websocket/{userId}") public class WebSocket { - + + private static CopyOnWriteArraySet<WebSocket> webSockets =new CopyOnWriteArraySet<>(); /**绾跨▼瀹夊叏Map*/ private static ConcurrentHashMap<String, Session> sessionPool = new ConcurrentHashMap<>(); @@ -33,6 +36,7 @@ public static final String REDIS_TOPIC_NAME = "socketHandler"; @Resource private JeecgRedisClient jeecgRedisClient; + private Session session; //==========銆恮ebsocket鎺ュ彈銆佹帹閫佹秷鎭瓑鏂规硶 鈥斺�� 鍏蜂綋鏈嶅姟鑺傜偣鎺ㄩ�亀s娑堟伅銆�======================================================================================== @@ -187,5 +191,17 @@ } } //=======銆愰噰鐢╮edis鍙戝竷璁㈤槄妯″紡鈥斺�旀帹閫佹秷鎭��========================================================================================== - + // 姝や负骞挎挱娑堟伅 + public void sendAllMessage(String message) { +// log.info("銆恮ebsocket娑堟伅銆戝箍鎾秷鎭�:"+message); + for(WebSocket webSocket : webSockets) { + try { + if(webSocket.session.isOpen()) { + webSocket.session.getAsyncRemote().sendText(message); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } } \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/quartz/job/SampleJob.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/quartz/job/SampleJob.java index db37777..b51176e 100644 --- a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/quartz/job/SampleJob.java +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/quartz/job/SampleJob.java @@ -1,23 +1,58 @@ package org.jeecg.modules.quartz.job; import org.jeecg.common.util.DateUtils; +import org.jeecg.modules.iot.entity.MqttParameter; +import org.jeecg.modules.iot.entity.ServerDeploy; +import org.jeecg.modules.iot.mqtt.config.MqttCustomerClient; +import org.jeecg.modules.iot.service.IServerDeployService; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; /** * 绀轰緥涓嶅甫鍙傚畾鏃朵换鍔� - * + * * @Author Scott */ @Slf4j public class SampleJob implements Job { + @Autowired + private IServerDeployService serverDeployService; + @Autowired + private MqttCustomerClient mqttCustomerClient; + @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { - log.info(" Job Execution key锛�"+jobExecutionContext.getJobDetail().getKey()); - log.info(String.format(" Jeecg-Boot 鏅�氬畾鏃朵换鍔� SampleJob ! 鏃堕棿:" + DateUtils.getTimestamp())); + List<ServerDeploy> serverDeploys = serverDeployService.list(); + if (serverDeploys != null) { + serverDeploys.forEach(sd -> { + if (sd.getGuardState().equals(1)) { + // 鍙戦�佸績璺充俊鍙� + MqttParameter mqttParameter = new MqttParameter(); + mqttParameter.setId(sd.getServerCode()); + mqttParameter.setType("palpitate"); + mqttParameter.setParameter1("0"); + mqttCustomerClient.pushlish(2, false, sd.getServerCode(), mqttParameter); + // 鍙戦�侀噰闆嗙姸鎬� + MqttParameter parameter = new MqttParameter(); + parameter.setId(sd.getServerCode()); + parameter.setType("collect"); + parameter.setParameter1("0"); + mqttCustomerClient.pushlish(2, false, sd.getServerCode(), parameter); + log.info("蹇冭烦鈾ラ噰闆嗙姸鎬佸彂閫佹垚鍔�! 鏈嶅姟鍣ㄧ紪鍙�:" + sd.getServerCode() + " 鏃堕棿:" + DateUtils.getTimestamp()); + } + }); + } + + // 鏌ヨ铏氳澶囦笅鍙傛暟瀛樺湪oporation鐨勮櫄璁惧鍒楄〃 + List<ServerDeploy> serverDeploy = serverDeployService.list(); + // 鏌ヨ鏄惁瀛樺湪璁惧鐘舵�� + } } diff --git a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/quartz/job/SampleParamJob.java b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/quartz/job/SampleParamJob.java index db2a71c..e5ae82d 100644 --- a/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/quartz/job/SampleParamJob.java +++ b/lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/quartz/job/SampleParamJob.java @@ -1,32 +1,348 @@ package org.jeecg.modules.quartz.job; -import org.jeecg.common.util.DateUtils; +import com.influxdb.client.InfluxDBClient; +import com.influxdb.client.InfluxDBClientFactory; +import com.influxdb.client.QueryApi; +import com.influxdb.query.FluxTable; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.CollectionUtils; +import org.jeecg.modules.iot.depository.Influxdb; +import org.jeecg.modules.iot.depository.InfluxdbTest; +import org.jeecg.modules.iot.entity.Equipment; +import org.jeecg.modules.iot.entity.InfluxdbDeploy; +import org.jeecg.modules.iot.entity.ServerDeploy; +import org.jeecg.modules.iot.mdc.entity.EquipmentAlarm; +import org.jeecg.modules.iot.mdc.entity.EquipmentLog; +import org.jeecg.modules.iot.mdc.service.IEquipmentAlarmService; +import org.jeecg.modules.iot.mdc.service.IEquipmentLogService; +import org.jeecg.modules.iot.service.IEquipmentService; +import org.jeecg.modules.iot.service.IInfluxdbDeployService; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; -import lombok.extern.slf4j.Slf4j; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; /** * 绀轰緥甯﹀弬瀹氭椂浠诲姟 - * + * * @Author Scott */ @Slf4j public class SampleParamJob implements Job { - - /** - * 鑻ュ弬鏁板彉閲忓悕淇敼 QuartzJobController涓篃闇�瀵瑰簲淇敼 - */ - private String parameter; - - public void setParameter(String parameter) { - this.parameter = parameter; - } + @Value("${databaseType}") + private String databaseType; + @Autowired + private IInfluxdbDeployService influxdbDeployService; + @Autowired + private DataSource dataSource; + @Autowired + private IEquipmentService equipmentService; + @Autowired + private IEquipmentLogService equipmentLogService; + @Autowired + private org.jeecg.modules.iot.mdc.service.IEquipmentService mdcEquipmentService; + @Autowired + private IEquipmentAlarmService equipmentAlarmService; + @Autowired + private org.jeecg.modules.iot.service.IServerDeployService serverDeployService; @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { - log.info(" Job Execution key锛�"+jobExecutionContext.getJobDetail().getKey()); - log.info( String.format("welcome %s! Jeecg-Boot 甯﹀弬鏁板畾鏃朵换鍔� SampleParamJob ! 鏃堕棿:" + DateUtils.now(), this.parameter)); + List<InfluxdbDeploy> influxdbDeployList = influxdbDeployService.list(); + List<ServerDeploy> serverDeployList = serverDeployService.list(); + + influxdbDeployList.forEach(in -> { + // InfluxDB 2.0 杩炴帴淇℃伅 + String influxUrl = "http://" + in.getAddress() + ":" + in.getPort(); + String influxToken = in.getAuthorizeCode(); + String influxOrg = in.getOrganization(); + String influxBucket = in.getBucket(); + // 杩炴帴 InfluxDB 2.0 + InfluxDBClient influxDBClient = InfluxDBClientFactory.create(influxUrl, influxToken.toCharArray()); + QueryApi queryApi = influxDBClient.getQueryApi(); + // 杩炴帴 SqlServer + try (Connection mysqlConnection = dataSource.getConnection()) { + // 澶勭悊鏃堕棿 + DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + AtomicReference<String> start = new AtomicReference<>(""); + AtomicReference<String> end = new AtomicReference<>(""); + AtomicReference<Date> endDate = new AtomicReference<>(null); // 閲囬泦鏃堕棿 + serverDeployList.forEach(s -> { + if (s.getId().equals(in.getServerDeployId()) && s.getCollectTime() != null) { + start.set(sdf.format(s.getCollectTime())); + // 鑾峰彇褰撳墠鏃堕棿 + LocalDateTime now = LocalDateTime.now(); + // 鍑忓幓涓�鍒嗛挓 +// LocalDateTime oneMinuteAgo = now.minusMinutes(1); + LocalDateTime oneMinuteAgo = now.minusSeconds(2); + // 鏍煎紡鍖栦负瀛楃涓诧紙鍙�夛級 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String formattedTime = oneMinuteAgo.format(formatter); + // 杞崲涓� Date 绫诲瀷锛堜娇鐢ㄧ郴缁熼粯璁ゆ椂鍖猴級 + Date date = Date.from(oneMinuteAgo.atZone(ZoneId.systemDefault()).toInstant()); + endDate.set(date); + end.set(formattedTime); + } + }); + if (start.get().equals("")){ + return; + } + LocalDateTime startTime = LocalDateTime.parse(start.get(), inputFormatter); + LocalDateTime endTime = LocalDateTime.parse(end.get(), inputFormatter); + // 瀹氫箟鏃ユ湡鏃堕棿鏍煎紡鍣紙ISO_LOCAL_DATE_TIME 瀵瑰簲 "yyyy-MM-ddTHH:mm:ss"锛� + DateTimeFormatter formatter1 = DateTimeFormatter.ISO_LOCAL_DATE_TIME; + + // 瑙f瀽瀛楃涓蹭负 LocalDateTime 瀵硅薄 + LocalDateTime startDateTime = LocalDateTime.parse(startTime.toString(), formatter1);// 瑙f瀽瀛楃涓蹭负 LocalDateTime 瀵硅薄 + LocalDateTime endDateTime = LocalDateTime.parse(endTime.toString(), formatter1); + + // 鍔犱笂 8 灏忔椂 + LocalDateTime startNewDateTime = startDateTime.minusHours(8); + LocalDateTime endNewDateTime = endDateTime.minusHours(8); +// String query = "from(bucket: \"IOT\") \n" + +// "|> range(start: "+startNewDateTime+"Z, stop: "+endNewDateTime+"Z) \n" + +// "|> fill(usePrevious: true) \n" + +// "|> filter(fn: (r) => r[\"_field\"] == \"TimeStamp\" or r[\"_field\"] == \"Value\")"; + String query = "from(bucket: \"" + influxBucket + "\") " + + "|> range(start: -5s) " + + "|> filter(fn: (r) => r[\"_field\"] == \"TimeStamp\" or r[\"_field\"] == \"Value\")"; + + // 鎵ц鏌ヨ + try { + List<FluxTable> tables = queryApi.query(query, influxOrg); + // 澶勭悊鏌ヨ缁撴灉骞舵彃鍏ュ埌 MySQL + List<Influxdb> influxdbs = InfluxdbTest.processAndInsert(tables, mysqlConnection); + // 鏍规嵁绫诲瀷鎷嗗垎 + Map<String, List<Influxdb>> fieldistMap = influxdbs.stream() + .collect(Collectors.groupingBy(Influxdb::getField)); + List<Influxdb> valueList = new ArrayList<>(); + List<Influxdb> timeStampList = new ArrayList<>(); + fieldistMap.forEach((field, timeList) -> { + if (field.equals("Value")) { + valueList.addAll(timeList); + } else { + timeStampList.addAll(timeList); + } + }); + for (int i = 0; i < valueList.size(); i++) { + valueList.get(i).setAcquisitionTime(timeStampList.get(i).getValue()); + } + // 鏍规嵁璁惧杩涜鍒嗙粍 + Map<String, List<Influxdb>> measurementListMap = valueList.stream() + .collect(Collectors.groupingBy(Influxdb::getMeasurement)); + measurementListMap.forEach((table, timeList) -> { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + Map<String, List<Influxdb>> timeListMap = timeList.stream() + .collect(Collectors.groupingBy( + Influxdb::getAcquisitionTime, + () -> new TreeMap<>(Comparator.comparing( + timeStr -> LocalDateTime.parse(timeStr, formatter) + )), + Collectors.toList() + )); + + // 澶勭悊璁惧鐘舵�� + int lastIndex = table.lastIndexOf('.'); + String code = table.substring(lastIndex + 1); + EquipmentLog equipmentLog = equipmentLogService.selectEquipmentOporation(code); + // 璁惧鐘舵�� + Integer equipmentState = null; + for (Map.Entry<String, List<Influxdb>> entry : timeListMap.entrySet()) { + String measurement = entry.getKey(); + List<Influxdb> influxdbList = entry.getValue(); + Equipment equipment = equipmentService.findEquipmentByCode(code); + String tableName = equipment.getControlSystem() + '_' + equipment.getEqptCode(); + // 鑾峰彇琛ㄥ悕 + String[] columns = new String[influxdbList.size() + 2]; + Object[] values = new Object[influxdbList.size() + 2]; + String state = ""; // 璁惧鐘舵�� + String isAlarm = ""; // 鎶ヨ鐘舵�� + String alarm = ""; // 鎶ヨ鍙� + String alarmContent = ""; // 鎶ヨ鍐呭 + // 閬嶅巻褰撳墠璁惧涓嬬殑鎵�鏈夊弬鏁� + for (int i = 0; i < influxdbList.size(); i++) { + String parameter = influxdbList.get(i).getParameter(); + columns[i] = parameter.substring(parameter.lastIndexOf('-') + 1); + values[i] = influxdbList.get(i).getValue(); + if (values[i] == null || values[i] == "") { + values[i] = ""; + } else { + if (columns[i].equals("Oporation")) { + state = values[i].toString(); + } else if (columns[i].equals("AlarmNo")) { + alarm = values[i].toString(); + } else if (columns[i].equals("AlarmContent")) { + alarmContent = values[i].toString(); + } else if (columns[i].equals("IsAlarm")) { + isAlarm = values[i].toString(); + } + } + + } + // 楠岃瘉鏁版嵁鏄惁閮戒负绌� + if (!allEmptyStrings(values)) { + columns[influxdbList.size() + 1] = "CollectTime"; + columns[influxdbList.size()] = "EquipmentID"; + // 杞崲涓� LocalDateTime + LocalDateTime dateTime = LocalDateTime.parse(influxdbList.get(0).getAcquisitionTime(), formatter); + values[influxdbList.size() + 1] = dateTime; + values[influxdbList.size()] = tableName.replace("-", "_"); + // 鎻掑叆鏁版嵁 + if (databaseType.equals("SqlServer")) { + equipmentService.insertSqlServerData(tableName, columns, values); + } else if (databaseType.equals("MySql")) { + equipmentService.insertMySqlData(tableName, columns, values); + + } + if (!state.equals("")) { + EquipmentLog log = new EquipmentLog(); + log.setOporation(Integer.parseInt(state)); + log.setEquipmentId(equipment.getEqptCode()); + log.setEquipmentName(equipment.getEqptName()); + log.setCollectTime(Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant())); + // True 鎶ヨ寮�濮嬶紝False鎶ヨ缁撴潫 + if (isAlarm.equals("True")) { + // 鎶ヨ寮�濮� + if (equipmentLog == null && equipmentState == null) { + // 楠岃瘉鏄惁鎶ヨ + log.setOporation(22); + log.setAlarm(alarm); + equipmentLogService.save(log); + equipmentState = 22; + equipmentStateModification(equipment.getEqptCode(), 22); + } else if (equipmentLog != null && equipmentState == null && equipmentLog.getOporation() != 22) { + log.setOporation(22); + log.setAlarm(alarm); + equipmentState = 22; + equipmentLogService.save(log); + equipmentStateModification(equipment.getEqptCode(), 22); + } else if (equipmentLog != null && equipmentState != null && equipmentState != 22) { + log.setOporation(22); + log.setAlarm(alarm); + equipmentState = 22; + equipmentLogService.save(log); + equipmentStateModification(equipment.getEqptCode(), 22); + } + } else if (isAlarm.equals("False")) { + // 鎶ヨ缁撴潫 + if (equipmentLog == null && equipmentState == null) { + // 楠岃瘉鏄惁鎶ヨ + equipmentLogService.save(log); + equipmentState = Integer.parseInt(state); + equipmentStateModification(equipment.getEqptCode(), equipmentState); + } else if (equipmentLog != null && equipmentState == null && equipmentLog.getOporation() == 22) { + log.setOporation(23); + equipmentState = 23; + equipmentLogService.save(log); + equipmentStateModification(equipment.getEqptCode(), equipmentState); + } else if (equipmentLog != null && equipmentState != null && equipmentState == 22) { + log.setOporation(23); + equipmentState = 23; + equipmentLogService.save(log); + equipmentStateModification(equipment.getEqptCode(), 23); + } else { + if (equipmentLog != null && equipmentState == null && equipmentLog.getOporation() != Integer.parseInt(state)) { + equipmentState = Integer.parseInt(state); + equipmentLogService.save(log); + equipmentStateModification(equipment.getEqptCode(), equipmentState); + //楠岃瘉鏄惁鏄姤璀︼紝鎴栬�呮姤璀︾粨鏉� + } else if (equipmentLog != null && equipmentState != null && equipmentState != Integer.parseInt(state)) { + equipmentState = Integer.parseInt(state); + equipmentLogService.save(log); + equipmentStateModification(equipment.getEqptCode(), equipmentState); + } + } + } + // 澶勭悊鎶ヨ淇℃伅 + if (isAlarm.equals("True")) { + EquipmentAlarm equipmentAlarm = equipmentAlarmService.selectEquipmentAlarmByEquipmentId(equipment.getEqptCode()); + if (equipmentAlarm != null && !equipmentAlarm.getAlarmNo().equals(alarm)) { + addEquipmentAlarm(alarm, equipment, dateTime, alarmContent); + } else if (equipmentAlarm == null) { + addEquipmentAlarm(alarm, equipment, dateTime, alarmContent); + } + } + } + } + } + }); + // 濡傛灉鏈夋煡璇㈡暟鎹紝鏃堕棿涓嶄负绌� + + if (endDate.get() != null && CollectionUtils.isNotEmpty(tables)) { + for (ServerDeploy s : serverDeployList) { + if (s.getId().equals(in.getServerDeployId())) { + s.setCollectTime(endDate.get()); + return; + } + } + } + } catch (Exception e) { + log.error(String.valueOf(e)); + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + influxDBClient.close(); + } + }); + serverDeployService.updateBatchById(serverDeployList); + // 鐩存帴鍦ㄨ緭鍑鸿鍙ヤ腑鏍煎紡鍖� + log.info("瀹炴椂鏁版嵁浠诲姟鎵ц锛屽綋鍓嶆椂闂达細" + + LocalDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault()) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"))); + } + + public static boolean allEmptyStrings(Object[] values) { + if (values == null) { + return false; // 濡傛灉鏁扮粍鏈韩涓簄ull锛岃繑鍥瀎alse + } + for (Object str : values) { + if (str != null && !str.toString().equals("")) { + return false; // 濡傛灉鍏冪礌涓嶆槸String绫诲瀷锛岃繑鍥瀎alse + } + } + + return true; // 鎵�鏈夊厓绱犻兘鏄┖瀛楃涓� + } + + /** + * 鎶ヨ淇℃伅澶勭悊 + * + * @param alarm 鎶ヨ鍙� + * @param equipment 璁惧淇℃伅 + * @param dateTime 鎶ヨ鏃堕棿 + * @param alarmContent 鎶ヨ鍐呭 + */ + public void addEquipmentAlarm(String alarm, Equipment equipment, LocalDateTime dateTime, String alarmContent) { + // 楠岃瘉鏄惁鎶ヨ + EquipmentAlarm equipmentAlarm = new EquipmentAlarm(); + equipmentAlarm.setEquipmentid(equipment.getEqptCode()); + equipmentAlarm.setCollecttime(Date.from(dateTime.atZone(java.time.ZoneId.systemDefault()).toInstant())); + equipmentAlarm.setAlarmNo(alarm); + equipmentAlarm.setAlarmContent(alarmContent); + equipmentAlarmService.save(equipmentAlarm); + + } + + void equipmentStateModification(String eqptCode, Integer state) { + org.jeecg.modules.iot.mdc.entity.Equipment mdcEquipment = mdcEquipmentService.findEquipmentByEquipmentId(eqptCode); + if (mdcEquipment != null) { + mdcEquipment.setOporation(state); + mdcEquipmentService.updateById(mdcEquipment); + } } } diff --git a/lxzn-module-system/lxzn-system-start/lxzn-system-start.iml b/lxzn-module-system/lxzn-system-start/lxzn-system-start.iml deleted file mode 100644 index 364688f..0000000 --- a/lxzn-module-system/lxzn-system-start/lxzn-system-start.iml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module version="4"> - <component name="FacetManager"> - <facet type="JRebel" name="JRebel"> - <configuration> - <option name="ideModuleStorage"> - <map> - <entry key="com.zeroturnaround.jrebel.FormatVersion" value="7.0.0" /> - <entry key="jrebelEnabled" value="false" /> - <entry key="lastExternalPluginCheckTime" value="1754530568587" /> - <entry key="rebelXmlGenerationInvariantToken" value="PGFwcGxpY2F0aW9uIGdlbmVyYXRlZC1ieT0iaW50ZWxsaWoiPjxpZD5seHpuLXN5c3RlbS1zdGFydDwvaWQ+PGNsYXNzcGF0aD48ZGlyIG5hbWU9IkY6L2phdmFfd29ya3NwYWNlL21kY196Zi9seHpuLW1vZHVsZS1zeXN0ZW0vbHh6bi1zeXN0ZW0tc3RhcnQvdGFyZ2V0L2NsYXNzZXMiPjwvZGlyPjwvY2xhc3NwYXRoPjwvYXBwbGljYXRpb24+" /> - </map> - </option> - <option name="version" value="8" /> - </configuration> - </facet> - </component> -</module> \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-start/src/main/resources/application-dev.yml b/lxzn-module-system/lxzn-system-start/src/main/resources/application-dev.yml index 3871bb1..0b3c4a6 100644 --- a/lxzn-module-system/lxzn-system-start/src/main/resources/application-dev.yml +++ b/lxzn-module-system/lxzn-system-start/src/main/resources/application-dev.yml @@ -125,14 +125,14 @@ poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 # 閰嶇疆鐩戞帶缁熻鎷︽埅鐨刦ilters锛屽幓鎺夊悗鐩戞帶鐣岄潰sql鏃犳硶缁熻锛�'wall'鐢ㄤ簬闃茬伀澧� - filters: stat,wall,slf4j + filters: stat,slf4j # 閫氳繃connectProperties灞炴�ф潵鎵撳紑mergeSql鍔熻兘锛涙參SQL璁板綍 connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 datasource: master: - url: jdbc:mysql://127.0.0.1:3306/lxzn_mdc_zf?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai + url: jdbc:mysql://192.168.1.118:3306/lxzn_mdc_zf?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai username: root - password: 123456 + password: root driver-class-name: com.mysql.cj.jdbc.Driver # 澶氭暟鎹簮閰嶇疆 #multi-datasource1: @@ -145,7 +145,7 @@ database: 10 host: 127.0.0.1 port: 6379 - password: '123456' +# password: '123456' #mybatis plus 璁剧疆 mybatis-plus: mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml @@ -295,3 +295,29 @@ # appSecret client-secret: ?? agent-id: ?? +mqtt: + host: tcp://192.168.1.123:1883 + clientId: mqtt_manage_platform_dev + username: admin + password: public + timeout: 30000 + keepalive: 300 + clientUrl: http://192.168.1.123:18083/api/v5/clients + #API鎺堟潈KEY + apiKey: fb5d13d541c4ebd9 + #API鎺堟潈瀵嗛挜 + secretKey: J9A4pFcUyYzyo6uhFh6AKcVBi7xHcUgcNoNMCWylrCHE +#椹卞姩鏂囦欢鍦板潃 +drive: /iot/configuration/DriveConfig.xml +script: /iot/configuration/FunctionConfig.xml +#ftp杩炴帴鍦板潃 +ftp: + LOCAL_CHARSET: GBK + SERVER_CHARSET: ISO-8859-1 + ftpHost: 10.0.221.200 + ftpPort: 21 + ftpUserName: admin + ftpPassword: lx@2024 + address: /iot/ +#鏁版嵁搴� MySql | SqlServer +databaseType: MySql \ No newline at end of file diff --git a/lxzn-module-system/lxzn-system-start/src/main/resources/application-prod.yml b/lxzn-module-system/lxzn-system-start/src/main/resources/application-prod.yml index 424cb23..32dc42f 100644 --- a/lxzn-module-system/lxzn-system-start/src/main/resources/application-prod.yml +++ b/lxzn-module-system/lxzn-system-start/src/main/resources/application-prod.yml @@ -52,13 +52,12 @@ instanceName: MyScheduler instanceId: AUTO jobStore: - selectWithLockSQL: SELECT* FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ? - # class: org.springframework.scheduling.quartz.LocalDataSourceJobStore - # driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate - # tablePrefix: QRTZ_ - # isClustered: true - # misfireThreshold: 12000 - # clusterCheckinInterval: 15000 + class: org.springframework.scheduling.quartz.LocalDataSourceJobStore + driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate + tablePrefix: QRTZ_ + isClustered: true + misfireThreshold: 12000 + clusterCheckinInterval: 15000 threadPool: class: org.quartz.simpl.SimpleThreadPool threadCount: 10 @@ -70,7 +69,6 @@ time-zone: GMT+8 jpa: open-in-view: false - database-platform: org.hibernate.dialect.SQLServerDialect aop: proxy-target-class: true #閰嶇疆freemarker @@ -112,7 +110,7 @@ # 鍒濆鍖栧ぇ灏忥紝鏈�灏忥紝鏈�澶� initial-size: 5 min-idle: 5 - maxActive: 1000 + maxActive: 20 # 閰嶇疆鑾峰彇杩炴帴绛夊緟瓒呮椂鐨勬椂闂� maxWait: 60000 # 閰嶇疆闂撮殧澶氫箙鎵嶈繘琛屼竴娆℃娴嬶紝妫�娴嬮渶瑕佸叧闂殑绌洪棽杩炴帴锛屽崟浣嶆槸姣 @@ -127,21 +125,27 @@ poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 # 閰嶇疆鐩戞帶缁熻鎷︽埅鐨刦ilters锛屽幓鎺夊悗鐩戞帶鐣岄潰sql鏃犳硶缁熻锛�'wall'鐢ㄤ簬闃茬伀澧� - filters: stat,wall,slf4j + filters: stat,slf4j # 閫氳繃connectProperties灞炴�ф潵鎵撳紑mergeSql鍔熻兘锛涙參SQL璁板綍 connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 datasource: master: - url: jdbc:sqlserver://localhost:1433;databasename=LXZN_TEST_COMMON - username: sa - password: 123 - driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver + url: jdbc:mysql://127.0.0.1:3306/lxzn_mdc_zf?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver + # 澶氭暟鎹簮閰嶇疆 + #multi-datasource1: + #url: jdbc:mysql://localhost:3306/jeecg-boot2?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai + #username: root + #password: root + #driver-class-name: com.mysql.cj.jdbc.Driver #redis 閰嶇疆 redis: - database: 0 + database: 10 host: 127.0.0.1 port: 6379 - password: +# password: '123456' #mybatis plus 璁剧疆 mybatis-plus: mapper-locations: classpath*:org/jeecg/modules/**/xml/*Mapper.xml @@ -176,25 +180,24 @@ app: http://localhost:8051 path: #鏂囦欢涓婁紶鏍圭洰褰� 璁剧疆 - upload: C://opt//upFiles + upload: /opt/upFiles #webapp鏂囦欢璺緞 - webapp: C://opt//upFiles + webapp: /opt/webapp shiro: - excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/**,/api/getUserInfo + excludeUrls: /test/jeecgDemo/demo3,/test/jeecgDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/** #闃块噷浜憃ss瀛樺偍鍜屽ぇ楸肩煭淇$閽ラ厤缃� oss: accessKey: ?? secretKey: ?? endpoint: oss-cn-beijing.aliyuncs.com bucketName: jeecgdev - staticDomain: https://static.jeecg.com - # ElasticSearch 璁剧疆 + # ElasticSearch 6璁剧疆 elasticsearch: cluster-name: jeecg-ES cluster-nodes: 127.0.0.1:9200 check-enabled: false # 鍦ㄧ嚎棰勮鏂囦欢鏈嶅姟鍣ㄥ湴鍧�閰嶇疆 - file-view-domain: http://fileview.jeecg.com + file-view-domain: 127.0.0.1:8012 # minio鏂囦欢涓婁紶 minio: minio_url: http://minio.jeecg.com @@ -203,7 +206,7 @@ bucketName: otatest #澶у睆鎶ヨ〃鍙傛暟璁剧疆 jmreport: - mode: prod + mode: dev #鏁版嵁瀛楀吀鏄惁杩涜saas鏁版嵁闅旂锛岃嚜宸辩湅鑷繁鐨勫瓧鍏� saas: false #鏄惁闇�瑕佹牎楠宼oken @@ -241,7 +244,7 @@ #寮�鍚敓浜х幆澧冨睆钄� production: false basic: - enable: true + enable: false username: jeecg password: jeecg1314 #绗笁鏂圭櫥褰� @@ -291,4 +294,30 @@ client-id: ?? # appSecret client-secret: ?? - agent-id: ?? \ No newline at end of file + agent-id: ?? +mqtt: + host: tcp://10.10.10.98:1883 + clientId: mqtt_manage_platform_dev + username: admin + password: public + timeout: 30000 + keepalive: 300 + clientUrl: http://10.10.10.98:18083/api/v5/clients + #API鎺堟潈KEY + apiKey: 47f5b38274a6084e + #API鎺堟潈瀵嗛挜 + secretKey: CAQ9A2PkFs4kKcOdbd7xx9caonv16mt5xYxYdfqFkHAIK +#椹卞姩鏂囦欢鍦板潃 +drive: /iot/configuration/DriveConfig.xml +script: /iot/configuration/FunctionConfig.xml +#ftp杩炴帴鍦板潃 +ftp: + LOCAL_CHARSET: GBK + SERVER_CHARSET: ISO-8859-1 + ftpHost: 10.10.10.98 + ftpPort: 21 + ftpUserName: admin + ftpPassword: lx@2024 + address: /iot/ +#鏁版嵁搴� MySql | SqlServer +databaseType: MySql \ No newline at end of file diff --git a/pom.xml b/pom.xml index c74ec3b..b516fa3 100644 --- a/pom.xml +++ b/pom.xml @@ -99,6 +99,43 @@ <dependencies> <dependency> + <groupId>cn.hutool</groupId> + <artifactId>hutool-all</artifactId> + <version>5.3.8</version> + </dependency> + + <dependency> + <groupId>com.opencsv</groupId> + <artifactId>opencsv</artifactId> + <version>5.7.1</version> + </dependency> + <dependency> + <groupId>com.squareup.okhttp3</groupId> + <artifactId>okhttp</artifactId> + <version>3.14.9</version> <!-- 浣跨敤鍏煎鐨勭増鏈� --> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib</artifactId> + <version>1.9.20</version> <!-- 浣跨敤浣犻渶瑕佺殑 Kotlin 鐗堟湰 --> + </dependency> + <!-- InfluxDB 2.0 瀹㈡埛绔� --> + <dependency> + <groupId>com.influxdb</groupId> + <artifactId>influxdb-client-java</artifactId> + <version>6.10.0</version> + </dependency> + <dependency> + <groupId>commons-net</groupId> + <artifactId>commons-net</artifactId> + <version>3.5</version> + </dependency> + <dependency> + <groupId>org.eclipse.paho</groupId> + <artifactId>org.eclipse.paho.client.mqttv3</artifactId> + <version>1.2.5</version> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> -- Gitblit v1.9.3