diff --git a/pom.xml b/pom.xml index 38ccd9555b8de71bb12686cd7a59efd9a963f7f5..b19ea87502c4ac96debbc1622627723d9a1c02b1 100644 --- a/pom.xml +++ b/pom.xml @@ -170,7 +170,12 @@ <artifactId>ruoyi-quartz</artifactId> <version>${ruoyi.version}</version> </dependency> - + <!--mqtt --> + <dependency> + <groupId>com.ruoyi</groupId> + <artifactId>ruoyi-mqtt</artifactId> + <version>${ruoyi.version}</version> + </dependency> <!-- 代ç 生æˆ--> <dependency> <groupId>com.ruoyi</groupId> @@ -209,6 +214,7 @@ <module>ruoyi-quartz</module> <module>ruoyi-generator</module> <module>ruoyi-common</module> + <module>ruoyi-mqtt</module> </modules> <packaging>pom</packaging> diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index febca0402470b40c695ecd2b4b07d8c39e60ceb7..6871e0494cf768cd8353b117573f6b4c382ec3ad 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -54,7 +54,11 @@ <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> - + <dependency> + <groupId>com.oracle</groupId> + <artifactId>ojdbc8</artifactId> + <version>11.2.0.1.0</version> + </dependency> <!-- æ ¸å¿ƒæ¨¡å—--> <dependency> <groupId>com.ruoyi</groupId> @@ -66,7 +70,10 @@ <groupId>com.ruoyi</groupId> <artifactId>ruoyi-quartz</artifactId> </dependency> - + <dependency> + <groupId>com.ruoyi</groupId> + <artifactId>ruoyi-mqtt</artifactId> + </dependency> <!-- 代ç 生æˆ--> <dependency> <groupId>com.ruoyi</groupId> diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/topology/IndexController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/topology/IndexController.java index 7c7fdfc567889782f6878056c8c6668d97e3a9b9..1d03ad03dee4f384fd1c1795cd70a380d1371dae 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/topology/IndexController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/topology/IndexController.java @@ -1,22 +1,19 @@ package com.ruoyi.web.controller.topology; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.annotation.Log; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.topology.TopologyData; -import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.file.FileUtils; -import com.ruoyi.common.core.websocket.WebSocketServer; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; import com.ruoyi.topology.service.ITopologyService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; -import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; @@ -29,12 +26,10 @@ import java.util.List; @RequestMapping("/topology") public class IndexController extends BaseController { - @Value(("${ruoyi.profile}")) - private String profile; + @Autowired private ITopologyService iTopologyService; - @Autowired - private WebSocketServer webSocketServer; + @Autowired private StringRedisTemplate stringRedisTemplate; /** @@ -43,12 +38,13 @@ public class IndexController extends BaseController { * @param topologyData * @return AjaxResult */ + @PreAuthorize("@ss.hasAnyPermi('topology:params:set,topology:index:add,topology:index:edit')") @PostMapping("/save") public AjaxResult save(@RequestBody TopologyData topologyData) throws IOException { List<TopologyData> list =null; TopologyData t=null; if (topologyData.getId() == null) { - iTopologyService.saveTopologyToId(topologyData ) ; + iTopologyService.saveTopologyToId(topologyData ); stringRedisTemplate.opsForValue().set(Constants.TOPOLOGY_DATA+topologyData.getId(),JSONObject.toJSONString( topologyData.getData()) ); return AjaxResult.success( topologyData ); }else{ @@ -62,15 +58,23 @@ public class IndexController extends BaseController { return AjaxResult.error( "ä¿å˜å¤±è´¥ï¼Œè¯·æ£€æŸ¥id是å¦å˜åœ¨" ); } - - @GetMapping("/preview") - public AjaxResult preview() { + @PreAuthorize("@ss.hasPermi('topology:index:showhide')") + @Log(title = "ç»„æ€æ˜¾ç¤º/éšè—", businessType = BusinessType.OTHER) + @PostMapping("/updateTopology") + public AjaxResult updateTopology(@RequestBody TopologyData topologyData) throws IOException { + iTopologyService.updateTopologyById(topologyData); + return AjaxResult.success(); + } + @PreAuthorize( "@ss.hasAnyPermi('topology:index:list')") + @GetMapping("/list") + public TableDataInfo list() { + startPage(); TopologyData topologyData = new TopologyData(); List<TopologyData> list = iTopologyService.getTopology( topologyData ); for(TopologyData t:list){ t.setData( stringRedisTemplate.opsForValue().get( Constants.TOPOLOGY_DATA+t.getId() ) ); } - return AjaxResult.success( list ); + return getDataTable(list); } @GetMapping("/getTopology/{id}") @@ -82,24 +86,34 @@ public class IndexController extends BaseController { return AjaxResult.success( t ); } + @PreAuthorize("@ss.hasPermi('topology:index:delete')") + @Log(title = "åˆ é™¤ç»„æ€", businessType = BusinessType.DELETE) @DeleteMapping("/deleteTopology/{id}") public AjaxResult deleteTopology(@PathVariable("id") Integer id) { if(iTopologyService.deleteTopologyById( id )>0){ stringRedisTemplate.delete( Constants.TOPOLOGY_DATA+id ); return AjaxResult.success(); - } return AjaxResult.error( "åˆ é™¤å¤±è´¥" ); - } + @PreAuthorize("@ss.hasPermi('topology:index:deleteTopologyHandle')") + @Log(title = "åˆ é™¤ç»„æ€å‚æ•°é…ç½®", businessType = BusinessType.DELETE) + @DeleteMapping("/deleteTopologyHandle/{id}") + public AjaxResult deleteTopologyHandle(@PathVariable("id") Integer id){ + JSONObject jsonObject=JSONObject.parseObject( stringRedisTemplate.opsForValue().get( Constants.TOPOLOGY_DATA+id ) ); + jsonObject.remove( "topologyHandle" ); + stringRedisTemplate.opsForValue().set( Constants.TOPOLOGY_DATA+id,jsonObject.toJSONString() ); + return AjaxResult.success(); + } @GetMapping("/test") public void test() throws IOException { - JSONObject jsonObject= JSON.parseObject( "{\n" + - " tag: 'numA', //tag节点\n" + - " fontColor: 'red', //æ•°æ®é¢œè‰²\n" + - " text: 'test', //文本内容\n" + - " }" ); - webSocketServer.sendInfo(jsonObject.toJSONString() ,"1" ); +// JSONObject jsonObject= JSON.parseObject( "{\n" + +// " tag: 'numA', //tag节点\n" + +// " fontColor: 'red', //æ•°æ®é¢œè‰²\n" + +// " text: 'test', //文本内容\n" + +// " }" ); +// webSocketServer.sendInfo(jsonObject.toJSONString() ,"1" ); + System.out.println("他请求æˆåŠŸäº†"); } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/topology/ParamsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/topology/ParamsController.java index 88cd71b5915c3b286a26512446ea0ff1afa9667b..c077ed1978f6d6da2dca2b7b4e24cb383b03e5f1 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/topology/ParamsController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/topology/ParamsController.java @@ -1,30 +1,49 @@ package com.ruoyi.web.controller.topology; +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.AjaxResult; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.utils.sign.RsaUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.web.bind.annotation.*; /** + * 组æ€å…¬å…±è°ƒç”¨æ–¹æ³• * @author jianglw * @version 1.0 * @date 2021/4/7 10:34 */ @RestController @RequestMapping("/params") +@Slf4j public class ParamsController { - + @Autowired + private StringRedisTemplate stringRedisTemplate; /** * - * @param topologyData + * @param id + * @param tag + * @param fun * @return */ - @PostMapping("/addChange") - public AjaxResult addChange(@RequestBody String topologyData){ - System.out.println(topologyData); - - + @GetMapping("/show") + public AjaxResult show(@RequestParam(value = "id") String id, + @RequestParam(value = "tag") String tag, + @RequestParam(value = "fun") String fun){ + Integer ids; + try { + ids= Integer.parseInt( RsaUtils.encryptByPrivateKey( id ) ); + } catch (Exception e) { + log.error(e.getLocalizedMessage()); + e.printStackTrace(); + return AjaxResult.error("idè§£æžå¤±è´¥"); + } + String value=stringRedisTemplate.opsForValue().get( Constants.TOPOLOGY_DATA+ids ); + JSONObject jsonObject=JSONObject.parseObject( value ); + JSONObject topologyHandle =jsonObject.getJSONObject( "topologyHandle" ); + Integer dataAcquisition =topologyHandle.getInteger( "dataAcquisitionMode" ); return AjaxResult.success(); } diff --git a/ruoyi-admin/src/main/resources/application-druid.yml b/ruoyi-admin/src/main/resources/application-druid.yml index d3a274cfc3bca0443e6a56540e9c49813338502b..f4b3a295074befd0769f78c80da89ad2a6e0a111 100644 --- a/ruoyi-admin/src/main/resources/application-druid.yml +++ b/ruoyi-admin/src/main/resources/application-druid.yml @@ -2,20 +2,36 @@ spring: datasource: type: com.alibaba.druid.pool.DruidDataSource - driverClassName: com.mysql.cj.jdbc.Driver druid: # ä¸»åº“æ•°æ®æº master: url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: root + driverClassName: com.mysql.cj.jdbc.Driver # ä»Žåº“æ•°æ®æº slave: # ä»Žæ•°æ®æºå¼€å…³/é»˜è®¤å…³é— enabled: false - url: - username: - password: + url: + username: + password: + driverClassName: + # ä»Žåº“æ•°æ®æº + mysql: + # ä»Žæ•°æ®æºå¼€å…³/é»˜è®¤å…³é— + enabled: true + url: jdbc:mysql://localhost:3306/d5000?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + username: root + password: root + driverClassName: com.mysql.cj.jdbc.Driver + oracle: + # ä»Žæ•°æ®æºå¼€å…³/é»˜è®¤å…³é— + enabled: true + url: jdbc:oracle:thin:@221.180.252.34:1521:xe + username: scott + password: scott + driverClassName: oracle.jdbc.driver.OracleDriver # åˆå§‹è¿žæŽ¥æ•° initialSize: 5 # 最å°è¿žæŽ¥æ± æ•°é‡ diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index e6efdbb68b0bcf2eb5ea7cb3312be481e675afa2..26d5cb831b3477d8eef8ba29f4eebd9840b389b7 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -96,8 +96,8 @@ token: header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz - # 令牌有效期(默认30分钟) - expireTime: 30 + # 令牌有效期(默认30分钟)30,当å‰ä¸ƒå¤© + expireTime: 10080 # MyBatisé…ç½® mybatis: @@ -131,3 +131,14 @@ xss: # 匹é…链接 urlPatterns: /system/*,/monitor/*,/tool/* +# influxdb +influxdb: + enabled: true + url: http://192.168.2.223:8086 + token: ruhoz8G-ROLdtjSCb_NYyZ_Oehq55868iMih9iJVL-y71-2Syl08o5d9m2_58-0ywEu77pdOlO62_99dvZf0sw== + bucket: topology + org: sspss +#mqtt +mqtt: + enabled: false + diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index b5401dc3bae6788d3258ade6a7dcf01356ef5c36..81d7939e56bd7c67263b54fd7405b15430f92efc 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -105,11 +105,7 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> - <!-- mqtt--> - <dependency> - <groupId>org.springframework.integration</groupId> - <artifactId>spring-integration-mqtt</artifactId> - </dependency> + <!-- pool å¯¹è±¡æ± --> <dependency> <groupId>org.apache.commons</groupId> @@ -132,6 +128,30 @@ <artifactId>snakeyaml</artifactId> <version>1.25</version> </dependency> +<!-- 共享æœåŠ¡ç«¯--> + <dependency> + <groupId>com.hrhx</groupId> + <artifactId>shareserverconconnector</artifactId> + <version>[1.0,)</version> + </dependency> +<!-- influxdb--> + <dependency> + <groupId>com.influxdb</groupId> + <artifactId>influxdb-client-java</artifactId> + <version>1.8.0</version> + </dependency> </dependencies> - + <repositories> + <repository> + <id>hrhx-repos</id> + <name>hrhx Repository</name> + <url>http://221.180.252.34:8081/nexus/content/groups/public</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> </project> \ No newline at end of file diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/topology/TopologyData.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/topology/TopologyData.java index 7f1e306edb77a78e8580c196cdd02a8d1aa97b41..da044196e1538137238cf428f42b9488fe0125bf 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/topology/TopologyData.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/topology/TopologyData.java @@ -10,9 +10,18 @@ public class TopologyData { private Integer id; private String name; private Object data; + private String switchIt; private String createdTime; private String alterTime; + public String getSwitchIt() { + return switchIt; + } + + public void setSwitchIt(String switchIt) { + this.switchIt = switchIt; + } + public String getCreatedTime() { return createdTime; } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/websocket/WebSocketServer.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/websocket/WebSocketServer.java index 2e8cb8ad145b5647db45a2b10b5b6120d033fd3c..eb4c34c0d7bf72f78c60f793f8b6bb09672c22c2 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/websocket/WebSocketServer.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/websocket/WebSocketServer.java @@ -2,6 +2,7 @@ package com.ruoyi.common.core.websocket; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,12 +52,11 @@ public class WebSocketServer { } log.info("用户连接:"+topologyId+",当å‰åœ¨çº¿äººæ•°ä¸º:" + getOnlineCount()); - - try { - sendMessage("连接æˆåŠŸ"); - } catch (IOException e) { - log.error("用户:"+topologyId+",网络异常!!!!!!"); - } +// try { +// sendMessage( JSONObject.parseObject( AjaxResult.success().toString() ).toJSONString() ); +// } catch (IOException e) { +// log.error("用户:"+topologyId+",网络异常!!!!!!"); +// } } /** diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/DataSourceType.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/DataSourceType.java index 4b5341d198b4f8b54cdc273a7ef40968b861e726..72399f562a744b7daa784bcd14f17abb8e31107a 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/enums/DataSourceType.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/DataSourceType.java @@ -15,5 +15,13 @@ public enum DataSourceType /** * 从库 */ - SLAVE + SLAVE, + /** + * mysql + */ + MYSQL, + /** + * oracle + */ + ORACLE } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/NodeLineParams.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/NodeLineParams.java new file mode 100644 index 0000000000000000000000000000000000000000..6bbf3e56e6be13a49dfee0fa8db36325212a08cb --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/NodeLineParams.java @@ -0,0 +1,35 @@ +package com.ruoyi.common.enums; + +import com.ruoyi.common.topology.handletype.DataParam; +import com.ruoyi.common.topology.handletype.DefaultParam; +import com.ruoyi.common.topology.handletype.DoParam; +import com.ruoyi.common.topology.handletype.NodeLineParamsInt; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/6/1 17:15 + */ +public enum NodeLineParams { + /** + * node/line傿•° + */ + DO( "do", new DoParam() ), + DATA("data",new DataParam()); + + public String type; + public NodeLineParamsInt nodeLineParamsInt; + NodeLineParams(String type,NodeLineParamsInt nodeLineParamsInt){ + this.type=type; + this.nodeLineParamsInt=nodeLineParamsInt; + } + public static NodeLineParamsInt match(String type){ + NodeLineParams[] values = NodeLineParams.values(); + for (NodeLineParams value : values) { + if (value.type.equals( type )) { + return value.nodeLineParamsInt; + } + } + return new DefaultParam(); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/AssembleData.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/AssembleData.java new file mode 100644 index 0000000000000000000000000000000000000000..59475cf13f7755a2eb4e02a68de22fbc9d930ca7 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/AssembleData.java @@ -0,0 +1,59 @@ +package com.ruoyi.common.topology.change; + +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/6/1 17:38 + */ +public class AssembleData { + public static Object getData(Handle handle, Map<String,Object> map){ + //共享判æ–与éžå…±äº«åˆ¤æ– + if(map.get( handle.getShareType() ) instanceof Map){ + Map<Integer,Object> map1=(Map<Integer,Object>)map.get( handle.getShareType() ); + if(!handle.getJudge()) { + return map1.get( Integer.parseInt( handle.getPoint() ) ); + }else{ + if(handle.getPointValue().contains( "," ) && handle.getChangeValue().contains( "," )){ + String[] pointValue= handle.getPointValue().split( "," ); + String[] changeValue=handle.getChangeValue().split( "," ); + if(pointValue.length==changeValue.length){ + for(int i =0;i<pointValue.length;i++){ + if(pointValue[i].equals( map1.get( Integer.parseInt(handle.getPoint()) ) )){ + return changeValue[i]; + } + } + } + }else{ + if(handle.getPointValue().equals( map1.get( Integer.parseInt(handle.getPoint()) ) )){ + return handle.getChangeValue(); + } + } + } + }else{ + if(!handle.getJudge()){ + return map.get( handle.getPoint() ); + }else{ + if(handle.getPointValue().contains( "," ) && handle.getChangeValue().contains( "," )){ + String[] pointValue= handle.getPointValue().split( "," ); + String[] changeValue=handle.getChangeValue().split( "," ); + if(pointValue.length==changeValue.length){ + for(int i =0;i<pointValue.length;i++){ + if(pointValue[i].equals( map.get( handle.getPoint() ) )){ + return changeValue[i]; + } + } + } + }else{ + if(handle.getPointValue().equals( map.get( handle.getPoint() ) )){ + return handle.getChangeValue(); + } + } + + } + } + + return ""; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/ChangePointAndData.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/ChangePointAndData.java deleted file mode 100644 index 019d1b169f7d152047f76ed2a1a33c867bbfc955..0000000000000000000000000000000000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/ChangePointAndData.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.ruoyi.common.topology.change; - -import com.alibaba.fastjson.JSONObject; - -import java.util.List; -import java.util.Map; - -/** - * @author jianglw - * @version 1.0 - * @date 2021/4/10 11:20 - */ -public class ChangePointAndData { - public List<Map<String,Object>> assemble(Map<String,Object> map, JSONObject jsonObject){ - Change topologyChange=jsonObject.toJavaObject( Change.class ); - - return null; - } -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/Change.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/ChangeSub.java similarity index 72% rename from ruoyi-common/src/main/java/com/ruoyi/common/topology/change/Change.java rename to ruoyi-common/src/main/java/com/ruoyi/common/topology/change/ChangeSub.java index f46347570b9543751b93dc6f1fb27a0376c6d943..769c55be7e3a77d675e662a261220dd6b4121737 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/Change.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/ChangeSub.java @@ -5,13 +5,22 @@ import java.util.List; /** * @author jianglw * @version 1.0 - * @date 2021/4/10 11:07 + * @date 2021/4/16 10:28 */ -public class Change { +public class ChangeSub { private String tag; private Integer type; + private String echarts; private List<Handle> handle; + public String getEcharts() { + return echarts; + } + + public void setEcharts(String echarts) { + this.echarts = echarts; + } + public String getTag() { return tag; } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/EchartsSet.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/EchartsSet.java new file mode 100644 index 0000000000000000000000000000000000000000..572775ee592248f2cd66a379c60f816e81ba75d0 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/EchartsSet.java @@ -0,0 +1,46 @@ +package com.ruoyi.common.topology.change; + +/** + * Echarts设置 + * @author jianglw + * @version 1.0 + * @date 2021/6/1 17:04 + */ +public class EchartsSet { + private String axis; + private String name; + private String point; + private String seriesType; + + public String getAxis() { + return axis; + } + + public void setAxis(String axis) { + this.axis = axis; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPoint() { + return point; + } + + public void setPoint(String point) { + this.point = point; + } + + public String getSeriesType() { + return seriesType; + } + + public void setSeriesType(String seriesType) { + this.seriesType = seriesType; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/Handle.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/Handle.java index 86808fd8f03a395f1eaec95be1d1454a4ea46ae1..c6359b4e7e634b72349b62c3cbf9521673e2d4ba 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/Handle.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/Handle.java @@ -1,5 +1,7 @@ package com.ruoyi.common.topology.change; +import java.util.List; + /** * @author jianglw * @version 1.0 @@ -8,9 +10,45 @@ package com.ruoyi.common.topology.change; public class Handle { private String type; private String point; + private String shareType; private Boolean judge; private String pointValue; private String changeValue; + private String title; + private Boolean customChart; + private List<EchartsSet> echartsArray; + + public Boolean getCustomChart() { + return customChart; + } + + public void setCustomChart(Boolean customChart) { + this.customChart = customChart; + } + + public List<EchartsSet> getEchartsArray() { + return echartsArray; + } + + public void setEchartsArray(List<EchartsSet> echartsArray) { + this.echartsArray = echartsArray; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getShareType() { + return shareType; + } + + public void setShareType(String shareType) { + this.shareType = shareType; + } public String getType() { return type; diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/PointAndData.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/PointAndData.java new file mode 100644 index 0000000000000000000000000000000000000000..b82744556e0990f79107a0e8c075a7214bd8a9d5 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/topology/change/PointAndData.java @@ -0,0 +1,53 @@ +package com.ruoyi.common.topology.change; + +import com.alibaba.fastjson.JSONArray; +import com.ruoyi.common.enums.NodeLineParams; +import com.ruoyi.common.topology.handletype.NodeLineParamsInt; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/26 9:41 + */ +public class PointAndData { + /** + * ç»„è£…æ•°æ® + * @param map + * @param jsonArray + * @return + */ + public static List<Map<String,Object>> assemble(Map<String,Object> map, JSONArray jsonArray){ + List<ChangeSub> list=jsonArray.toJavaList( ChangeSub.class ); + List<Map<String,Object>> list1=new LinkedList<>( ); + for(ChangeSub changeSub:list){ + List<Handle> handleList=changeSub.getHandle(); + list1.add( handle( map,handleList,changeSub.getTag(),changeSub.getEcharts() ) ); + } + return list1; + } + private static Map<String, Object> handle(Map<String,Object> map, List<Handle> list, String tag,String echarts){ + Map<String, Object> map1 =new HashMap<>( ); + Map<String, Object> map2=null; + List<Map<String, Object>> list1=null; + for(Handle handle:list){ + NodeLineParamsInt nodeLineParamsInt= NodeLineParams.match( handle.getType() ); + nodeLineParamsInt.getDataToParams( handle,map,map1,echarts ); +// if(handle.getType().equals( "do" )){ +// map2=new HashMap<>( ); +// list1=new LinkedList<>( ); +// map2.put( handle.getType(),AssembleData.getData( handle,map) ); +// list1.add( map2 ); +// map1.put( "actions", list1); +// }else{ +// map1.put( handle.getType(),AssembleData.getData(handle,map) ); +// } + } + map1.put( "tag", tag); + return map1; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/InfluxdbType.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/InfluxdbType.java deleted file mode 100644 index 8f2e7d2d3d6869fa35a1a6eb92b51c6c74064d09..0000000000000000000000000000000000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/InfluxdbType.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ruoyi.common.topology.collect; - -import com.alibaba.fastjson.JSONArray; - -import java.util.Map; - -/** - * @author jianglw - * @version 1.0 - * @date 2021/4/9 10:29 - */ -public class InfluxdbType implements CollectTopologyType { - @Override - public Map<String,Object> getData(String param) { - return null; - } -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/MysqlType.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/MysqlType.java deleted file mode 100644 index 241c236d21963d8d4a2441b1ad790b9ead377a17..0000000000000000000000000000000000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/MysqlType.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ruoyi.common.topology.collect; - -import com.alibaba.fastjson.JSONArray; - -import java.util.Map; - -/** - * @author jianglw - * @version 1.0 - * @date 2021/4/9 9:57 - */ -public class MysqlType implements CollectTopologyType { - @Override - public Map<String,Object> getData(String param) { - return null; - } -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/ShareServerType.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/ShareServerType.java deleted file mode 100644 index 5316e43ef5120506260dc20a63b3bd610ad7ae8a..0000000000000000000000000000000000000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/ShareServerType.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.ruoyi.common.topology.collect; - -import java.util.Map; - -/** - * @author jianglw - * @version 1.0 - * @date 2021/4/9 10:34 - */ -public class ShareServerType implements CollectTopologyType { - @Override - public Map<String,Object> getData(String param) { - return null; - } -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/DataParam.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/DataParam.java new file mode 100644 index 0000000000000000000000000000000000000000..64e60798553597ac0751b54412afefd87a751bc9 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/DataParam.java @@ -0,0 +1,78 @@ +package com.ruoyi.common.topology.handletype; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.topology.change.AssembleData; +import com.ruoyi.common.topology.change.EchartsSet; +import com.ruoyi.common.topology.change.Handle; +import com.ruoyi.common.utils.StringUtils; +import lombok.extern.slf4j.Slf4j; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * 组装echartsæ•°æ® + * @author jianglw + * @version 1.0 + * @date 2021/6/1 17:26 + */ +@Slf4j +public class DataParam implements NodeLineParamsInt{ + + @Override + public void getDataToParams(Handle handle, Map<String, Object> map, Map<String, Object> map1, String echarts) { + + //åˆ¤æ–æ˜¯å¦ä¸ºè‡ªå®šä¹‰å›¾è¡¨ + if(!handle.getCustomChart()){ + map1.put( handle.getType(), AssembleData.getData( handle,map)); + }else{ + if(StringUtils.isNotBlank( echarts )){ + JSONObject jsonObject=JSONObject.parseObject( echarts ); + JSONObject jsonObject1=JSONObject.parseObject( echarts ).getJSONObject( "option" ); + jsonObject1.getJSONObject( "title" ).put( "text",handle.getTitle() ); + List<String> list=new LinkedList<>(); + List<String> xList=new LinkedList<>(); + List<Map<String,Object>> seriesList=new LinkedList<>(); + Map<String,Object> map2=null; + for(EchartsSet echartsSet:handle.getEchartsArray()){ + if(echartsSet.getAxis().equals( "yAxis" )){ + map2=new HashMap<>(); + map2.put( "name",echartsSet.getName() ); + map2.put( "type" ,echartsSet.getSeriesType()); + map2.put( "data",map.get( echartsSet.getPoint() )+"" ); + seriesList.add( map2 ); + list.add( echartsSet.getName() ); + } + if(echartsSet.getAxis().equals( "xAxis" )){ + xList.add( map.get( echartsSet.getPoint() )+"" ); + } + } + JSONArray jsonArray=jsonObject1.getJSONArray( "series" ); + if(jsonArray.size()==seriesList.size()){ + for(int i=0;i<jsonArray.size();i++){ + for(Map<String,Object> m:seriesList){ + if(jsonArray.getJSONObject( i ).getString( "name" ).equals( m.get( "name" ) )){ + JSONObject jsonObject2=jsonArray.getJSONObject( i ); + jsonObject2=JSONObject.parseObject( JSON.toJSONString( m ) ); + } + } + } + }else{ + jsonArray=JSONArray.parseArray( JSON.toJSONString( seriesList ) ); + } + jsonObject1.getJSONObject( "xAxis" ).put( "data",xList ); + jsonObject1.getJSONObject( "legend" ).put( "data",list ); + map1.put( "data", jsonObject.toJSONString()); + }else{ + log.debug( "未获å–到组æ€ä¸çš„图表信æ¯"); + } + } + //echarts 在canvas上刷新使用 + map1.put( "elementRendered", false); + + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/DefaultParam.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/DefaultParam.java new file mode 100644 index 0000000000000000000000000000000000000000..6f62d51919c731d5e2f2bd70babd645e876f7fed --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/DefaultParam.java @@ -0,0 +1,19 @@ +package com.ruoyi.common.topology.handletype; + +import com.ruoyi.common.topology.change.AssembleData; +import com.ruoyi.common.topology.change.Handle; + +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/6/1 17:28 + */ +public class DefaultParam implements NodeLineParamsInt{ + + @Override + public void getDataToParams(Handle handle, Map<String, Object> map, Map<String, Object> map1, String echarts) { + map1.put( handle.getType(), AssembleData.getData(handle,map) ); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/DoParam.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/DoParam.java new file mode 100644 index 0000000000000000000000000000000000000000..fb865d4d94e7431520dab35c0fcd4bac6b8cf336 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/DoParam.java @@ -0,0 +1,26 @@ +package com.ruoyi.common.topology.handletype; + +import com.ruoyi.common.topology.change.AssembleData; +import com.ruoyi.common.topology.change.Handle; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/6/1 17:26 + */ +public class DoParam implements NodeLineParamsInt{ + + @Override + public void getDataToParams(Handle handle, Map<String, Object> map, Map<String, Object> map1, String echarts) { + Map<String,Object> map2=new HashMap<>( ); + List<Map<String, Object>> list1=new LinkedList<>( ); + map2.put( handle.getType(), AssembleData.getData( handle,map) ); + list1.add( map2 ); + map1.put( "actions", list1); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/NodeLineParamsInt.java b/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/NodeLineParamsInt.java new file mode 100644 index 0000000000000000000000000000000000000000..83a8bb6dd432fb3e3c1fa6980d867362c49f6f6c --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/topology/handletype/NodeLineParamsInt.java @@ -0,0 +1,14 @@ +package com.ruoyi.common.topology.handletype; + +import com.ruoyi.common.topology.change.Handle; + +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/6/1 17:17 + */ +public interface NodeLineParamsInt { + void getDataToParams(Handle handle, Map<String,Object> map,Map<String,Object> map1,String echarts); +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java index 43e78aebeaca373303d5dd9be863ac5a7a263b74..0b47dafcdeed879d1cfda6214abbc06324772620 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/CaptchaConfig.java @@ -53,7 +53,7 @@ public class CaptchaConfig // 边框颜色 默认为Color.BLACK properties.setProperty(KAPTCHA_BORDER_COLOR, "105,179,90"); // 验è¯ç 文本å—符颜色 默认为Color.BLACK - properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "blue"); + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "119,255,0"); // 验è¯ç 图片宽度 默认为200 properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); // 验è¯ç 图片高度 默认为50 @@ -71,11 +71,11 @@ public class CaptchaConfig // 验è¯ç 文本å—ä½“æ ·å¼ é»˜è®¤ä¸ºnew Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); // 验è¯ç 噪点颜色 默认为Color.BLACK - properties.setProperty(KAPTCHA_NOISE_COLOR, "white"); + properties.setProperty(KAPTCHA_NOISE_COLOR, "135,206,250"); // 干扰实现类 properties.setProperty(KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise"); // å›¾ç‰‡æ ·å¼ æ°´çº¹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy - properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); + properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.WaterRipple"); Config config = new Config(properties); defaultKaptcha.setConfig(config); return defaultKaptcha; diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/DruidConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/DruidConfig.java index f671b3a3030233caa1e06de22423959ddcbaad73..f6c90457fe06028a9431168921f4f70578c918e0 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/DruidConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/DruidConfig.java @@ -48,6 +48,23 @@ public class DruidConfig DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); return druidProperties.dataSource(dataSource); } + @Bean + @ConfigurationProperties("spring.datasource.druid.mysql") + @ConditionalOnProperty(prefix = "spring.datasource.druid.mysql", name = "enabled", havingValue = "true") + public DataSource mysqlDataSource(DruidProperties druidProperties) + { + DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); + return druidProperties.dataSource(dataSource); + } + + @Bean + @ConfigurationProperties("spring.datasource.druid.oracle") + @ConditionalOnProperty(prefix = "spring.datasource.druid.oracle", name = "enabled", havingValue = "true") + public DataSource oracleDataSource(DruidProperties druidProperties) + { + DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); + return druidProperties.dataSource(dataSource); + } @Bean(name = "dynamicDataSource") @Primary @@ -56,6 +73,8 @@ public class DruidConfig Map<Object, Object> targetDataSources = new HashMap<>(); targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource); setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource"); + setDataSource(targetDataSources, DataSourceType.MYSQL.name(), "mysqlDataSource"); + setDataSource(targetDataSources, DataSourceType.ORACLE.name(), "oracleDataSource"); return new DynamicDataSource(masterDataSource, targetDataSources); } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/InfluxDBConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/InfluxDBConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..b832bc1be96ad13efd7f15c7a797d526f958845b --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/InfluxDBConfig.java @@ -0,0 +1,39 @@ +package com.ruoyi.framework.config; + +import com.influxdb.client.InfluxDBClient; +import com.influxdb.client.InfluxDBClientFactory; +import com.influxdb.client.InfluxDBClientOptions; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/27 17:22 + */ +@Configuration +public class InfluxDBConfig { + @Value( "${influxdb.url}" ) + private String url; + + @Value( "${influxdb.token}" ) + private String token; + @Value( "${influxdb.bucket}" ) + private String bucket; + @Value( "${influxdb.org}" ) + private String org; + + @Bean(name = "getInfluxDB") + @ConditionalOnProperty(prefix = "influxdb", name = "enabled", havingValue = "true") + public InfluxDBClient getInfluxDB(){ + return InfluxDBClientFactory.create(url, token.toCharArray(),org); + } + + @Bean(name = "getBucket") + @ConditionalOnProperty(prefix = "influxdb", name = "enabled", havingValue = "true") + public String getBucket(){ + return this.bucket; + } +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index bf6946ce229ca59204407e4a3840fbea47500755..848c195830eb066a75554a73f1ce0b8b39cbb41c 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -106,7 +106,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter "/**/*.js" ).permitAll() .antMatchers("/profile/**").anonymous() -// .antMatchers( "/topology/**" ).anonymous() + .antMatchers( "/topology/test" ).anonymous() + .antMatchers( "/mqttDemo/**" ).anonymous() .antMatchers( "/imserver/**" ).anonymous() .antMatchers( "/sendMqttMessage" ).anonymous() .antMatchers("/common/download**").anonymous() diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/task/RyTask.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/task/RyTask.java new file mode 100644 index 0000000000000000000000000000000000000000..01da36107fb7f0c844d22f15f5ea65e75045412f --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/task/RyTask.java @@ -0,0 +1,92 @@ +package com.ruoyi.framework.task; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.influxdb.client.InfluxDBClient; +import com.influxdb.client.WriteApi; +import com.influxdb.client.domain.FluxResponse; +import com.influxdb.client.domain.WritePrecision; +import com.influxdb.client.write.Point; +import com.influxdb.query.FluxRecord; +import com.influxdb.query.FluxTable; +import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.utils.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; + +import java.text.DecimalFormat; +import java.time.Instant; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +/** + * 定时任务调度测试 + * + * @author ruoyi + */ +@Component("ryTask") +public class RyTask { + @Autowired + private StringRedisTemplate stringRedisTemplate; + @Autowired + private InfluxDBClient influxDBClient; + + @Value( "${influxdb.bucket}" ) + private String bucket; + @Value( "${influxdb.org}" ) + private String org; + + Random random = new Random(); + + DecimalFormat decimalFormat=new DecimalFormat(".00"); + final String str = "total_power,start_power,theory,theory_1,available," + + "a_1,a_2,a_3,a_4,a_5,a_6,a_7,Ua,Ub,Uc,Uab,Ubc,Uca,3U0," + + "p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17," + + "p18,p19,p20,p21,p22,p23,p24,p25,p26,p27,p28,p29,p30,p31,p32," + + "p33,p34,p35,p36,p37,p38,p39,p40,p41,p42"; + + + public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { + System.out.println( StringUtils.format( "æ‰§è¡Œå¤šå‚æ–¹æ³•: å—符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i ) ); + } + + public void ryParams(String params) { + Map<String,Object> map=new LinkedHashMap<>( ); + map.put( "tag1",random.nextFloat() ); + map.put( "tag2",random.nextFloat() ); + Point point = Point + .measurement("mem") + .addFields( map ) + .time( Instant.now(), WritePrecision.NS); + try (WriteApi writeApi = influxDBClient.getWriteApi()) { + writeApi.writePoint(bucket, org, point); + } + + } + + public void ryNoParams() { +// JSONObject jsonObject = new JSONObject(); +// +// String[] strArr = str.split( "," ); +// for (int i = 0; i < strArr.length; i++) { +// jsonObject.put( strArr[i], decimalFormat.format( random.nextFloat() * 100 ) ); +// } +// stringRedisTemplate.opsForValue().set( "gf:data", jsonObject.toJSONString() ); +// System.out.println( "æ‰§è¡Œæ— å‚æ–¹æ³•" ); + JSONObject jsonObject=JSONObject.parseObject( stringRedisTemplate.opsForValue().get( Constants.TOPOLOGY_DATA+"38" ) ); + JSONArray jsonArray=jsonObject.getJSONArray( "pens" ); + JSONObject jsonObject2=new JSONObject(); + for(int i=0;i<jsonArray.size();i++){ + JSONObject jsonObject1=jsonArray.getJSONObject( i ); + if(jsonObject1.getJSONArray( "tags" ).size()>0 ){ + jsonObject2.put( jsonObject1.getJSONArray( "tags" ).getString( 0 ),random.nextBoolean()?"1":"0" ); + } + } + System.out.println(jsonObject2.toJSONString()); + stringRedisTemplate.opsForValue().set( "fd:data", jsonObject2.toJSONString() ); + } +} diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/TopologyTask.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/task/TopologyTask.java similarity index 75% rename from ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/TopologyTask.java rename to ruoyi-framework/src/main/java/com/ruoyi/framework/task/TopologyTask.java index f7ae35aac6bd35afdc331655e56cefc37c0b9077..e225f7b17320a792ee6eb56effad86035e8a7c29 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/TopologyTask.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/task/TopologyTask.java @@ -1,10 +1,12 @@ -package com.ruoyi.quartz.task; +package com.ruoyi.framework.task; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.websocket.WebSocketServer; -import com.ruoyi.common.enums.CollectTopology; -import com.ruoyi.common.topology.collect.CollectTopologyType; +import com.ruoyi.framework.topology.emnus.CollectTopology; +import com.ruoyi.common.topology.change.PointAndData; +import com.ruoyi.framework.topology.collect.CollectTopologyType; import com.ruoyi.common.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,6 +15,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; import java.io.IOException; +import java.util.List; import java.util.Map; /** @@ -25,7 +28,7 @@ public class TopologyTask { @Autowired private StringRedisTemplate stringRedisTemplate; @Autowired - WebSocketServer webSocketServer; + private WebSocketServer webSocketServer; private static final Logger log = LoggerFactory.getLogger( TopologyTask.class ); @@ -46,25 +49,25 @@ public class TopologyTask { if (StringUtils.isNotEmpty( data ) && stringRedisTemplate.hasKey( Constants.TOPOLOGY_DATA+data )) { String top = stringRedisTemplate.opsForValue().get( Constants.TOPOLOGY_DATA+data ); JSONObject jsonObject = JSONObject.parseObject( top ); - JSONObject topologyHandle =JSONObject.parseObject( jsonObject.get( "topologyHandle" ).toString() ); + JSONObject topologyHandle =jsonObject.getJSONObject( "topologyHandle" ); Integer dataAcquisition =topologyHandle.getInteger( "dataAcquisitionMode" ); /** * èŽ·å–æ•°æ® */ CollectTopologyType collectTopologyType=CollectTopology.match( dataAcquisition ); assert collectTopologyType != null; - Map<String,Object> stringObjectMap = collectTopologyType.getData( topologyHandle.getString( "sentence" ) ); + Map<String,Object> stringObjectMap = collectTopologyType.getData( topologyHandle.getString( "sentence" ) ,topologyHandle.getJSONArray( "change" )); /** * é…ç½®æ•°æ® */ - + List<Map<String,Object>> list=PointAndData.assemble( stringObjectMap,topologyHandle.getJSONArray( "change" ) ); /** * mqtt与socket */ if (StringUtils.isNotEmpty( jsonObject.getString( "websocket" ) )) { String webSocket = jsonObject.getString( "websocket" ); try { - webSocketServer.sendInfo( "", webSocket.substring( webSocket.lastIndexOf( "/" ), webSocket.length() ) ); + WebSocketServer.sendInfo( JSONArray.toJSONString( list ), webSocket.substring( webSocket.lastIndexOf( "/" )+1, webSocket.length() ) ); } catch (IOException e) { log.error( "websocket连接失败" ); e.printStackTrace(); diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/CollectTopologyType.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/CollectTopologyType.java similarity index 56% rename from ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/CollectTopologyType.java rename to ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/CollectTopologyType.java index 1d0b8a368aeaba3ad23b4d1f37f4a4fd0010b97b..78a545687b3a06e3a2628cbc618e7a63d33e009c 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/CollectTopologyType.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/CollectTopologyType.java @@ -1,6 +1,5 @@ -package com.ruoyi.common.topology.collect; +package com.ruoyi.framework.topology.collect; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import java.util.Map; @@ -11,5 +10,5 @@ import java.util.Map; * @date 2021/4/9 9:55 */ public interface CollectTopologyType { - public Map<String,Object> getData(String param); + public Map<String,Object> getData(String param,JSONArray jsonArray); } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/InfluxdbType.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/InfluxdbType.java new file mode 100644 index 0000000000000000000000000000000000000000..f4a031620272271624a0e32a73516737a76e8236 --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/InfluxdbType.java @@ -0,0 +1,36 @@ +package com.ruoyi.framework.topology.collect; + +import com.alibaba.fastjson.JSONArray; +import com.influxdb.client.InfluxDBClient; +import com.influxdb.query.FluxRecord; +import com.influxdb.query.FluxTable; +import com.ruoyi.common.utils.spring.SpringUtils; + +import javax.management.Query; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/9 10:29 + */ +public class InfluxdbType implements CollectTopologyType { + + InfluxDBClient influxDBClient= SpringUtils.getBean( "getInfluxDB" ); + + @Override + public Map<String,Object> getData(String param, JSONArray jsonArray) { + List<FluxTable> list=influxDBClient.getQueryApi().query( param ); + Map<String,Object> map1=new LinkedHashMap<>( ); + + for(FluxTable fluxTable:list){ + List<FluxRecord> records = fluxTable.getRecords(); + for (FluxRecord fluxRecord : records) { + map1.put( fluxRecord.getField(),fluxRecord.getValue() ); + } + } + return map1; + } +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/MysqlType.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/MysqlType.java new file mode 100644 index 0000000000000000000000000000000000000000..b1b6f3f5c28647fca0573cb2c1bb902a197521be --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/MysqlType.java @@ -0,0 +1,20 @@ +package com.ruoyi.framework.topology.collect; + +import com.alibaba.fastjson.JSONArray; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.topology.service.impl.MysqlServiceImpl; + +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/9 9:57 + */ +public class MysqlType implements CollectTopologyType { + MysqlServiceImpl mysqlService= SpringUtils.getBean( MysqlServiceImpl.class ); + @Override + public Map<String,Object> getData(String param,JSONArray jsonArray) { + return mysqlService.getMysqlData( param ); + } +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/OracleType.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/OracleType.java new file mode 100644 index 0000000000000000000000000000000000000000..e21a53cd7af0a63ddcca24f78b8db05f29d0a01f --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/OracleType.java @@ -0,0 +1,20 @@ +package com.ruoyi.framework.topology.collect; + +import com.alibaba.fastjson.JSONArray; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.topology.service.impl.OracleServiceImpl; + +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/26 19:48 + */ +public class OracleType implements CollectTopologyType { + OracleServiceImpl oracleService= SpringUtils.getBean( "OracleServiceImpl" ); + @Override + public Map<String, Object> getData(String param, JSONArray jsonArray) { + return oracleService.getOracleData( param ); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/RedisType.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/RedisType.java similarity index 75% rename from ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/RedisType.java rename to ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/RedisType.java index 3354575a755db0e9a9dc987acd6693e56f31f3e5..f16f6005fc36c7a67707a7d6a0e091e6aec084df 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/topology/collect/RedisType.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/RedisType.java @@ -1,10 +1,8 @@ -package com.ruoyi.common.topology.collect; +package com.ruoyi.framework.topology.collect; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; import com.ruoyi.common.utils.spring.SpringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import java.util.Map; @@ -18,7 +16,7 @@ public class RedisType implements CollectTopologyType { private StringRedisTemplate stringRedisTemplate = SpringUtils.getBean( StringRedisTemplate.class ); @Override - public Map<String,Object> getData(String param) { + public Map<String,Object> getData(String param,JSONArray jsonArray) { String data =stringRedisTemplate.opsForValue().get( param ); Map<String,Object> map= JSONObject.parseObject( data,Map.class ); return map; diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/ShareServerType.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/ShareServerType.java new file mode 100644 index 0000000000000000000000000000000000000000..efb1272a5244463dc633fa45b97e112122aeca76 --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/collect/ShareServerType.java @@ -0,0 +1,63 @@ +package com.ruoyi.framework.topology.collect; + +import com.alibaba.fastjson.JSONArray; +import com.ruoyi.common.enums.NodeLineParams; +import com.ruoyi.common.topology.change.EchartsSet; +import com.ruoyi.framework.topology.emnus.ShareDataType; +import com.ruoyi.common.topology.change.ChangeSub; +import com.ruoyi.common.topology.change.Handle; +import shareconnector.netty.ShareServerFactory; +import shareconnector.service.SendAndRequestService; + +import java.util.*; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/9 10:34 + */ +public class ShareServerType implements CollectTopologyType { + ShareServerFactory shareServerFactory=ShareServerFactory.getInstance(); + @Override + public Map<String,Object> getData(String param, JSONArray jsonArray) { + String[] params=param.split( ":" ); + shareServerFactory.setIp( params[0] ).setPort( Integer.parseInt( params[1] ) ); + List<ChangeSub> list=jsonArray.toJavaList( ChangeSub.class ); + Map<String, Set<Integer>> map =new LinkedHashMap<>( ); + Set<Integer> set=null; + for(ChangeSub changeSub:list) { + List<Handle> handleList = changeSub.getHandle(); + for(Handle handle:handleList){ + //获å–echartsæ•°æ® + if(handle.getType().equals( NodeLineParams.DATA.type )){ + for(EchartsSet echartsSet:handle.getEchartsArray()){ + //echartsæ•°æ®å‡ä¸ºFloat类型 + if(map.containsKey( ShareDataType.FLOAT.name() )){ + map.get( handle.getShareType() ).add( Integer.parseInt( echartsSet.getPoint() ) ); + }else{ + set=new LinkedHashSet<>( ); + set.add( Integer.parseInt( echartsSet.getPoint() ) ); + map.put( ShareDataType.FLOAT.name(),set ); + } + } + //获å–除echartsæ•°æ® + }else{ + if(map.containsKey( handle.getShareType() )){ + map.get( handle.getShareType() ).add( Integer.parseInt( handle.getPoint() ) ); + }else{ + set=new LinkedHashSet<>( ); + set.add( Integer.parseInt( handle.getPoint() ) ); + map.put( handle.getShareType(),set ); + } + } + + } + } + Map<String,Object> map1=new LinkedHashMap<>( ); + for(Map.Entry<String,Set<Integer>> setEntry:map.entrySet()){ + Map<Integer,Object> map2=SendAndRequestService.getInstance().getDatas(setEntry.getValue(), ShareDataType.match(setEntry.getKey()) ); + map1.put( setEntry.getKey(),map2 ); + } + return map1; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/CollectTopology.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/emnus/CollectTopology.java similarity index 55% rename from ruoyi-common/src/main/java/com/ruoyi/common/enums/CollectTopology.java rename to ruoyi-framework/src/main/java/com/ruoyi/framework/topology/emnus/CollectTopology.java index 80b3b958897d65ee80f57be1b81b8904a2f4ecef..da99e7a8b1c68d90ebcbb02ed7c98ea56da454dd 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/enums/CollectTopology.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/emnus/CollectTopology.java @@ -1,43 +1,46 @@ -package com.ruoyi.common.enums; +package com.ruoyi.framework.topology.emnus; -import com.ruoyi.common.handlefile.HandleFile; -import com.ruoyi.common.topology.collect.*; +import com.ruoyi.framework.topology.collect.*; /** * 获å–topology + * * @author jianglw * @version 1.0 * @date 2021/4/9 10:31 */ -public enum CollectTopology { +public enum CollectTopology { /** * mysql */ - MYSQL(0,new MysqlType() ), + MYSQL( 0, new MysqlType() ), + ORACLE(1,new OracleType()), /** * redis */ - REDIS(3,new RedisType() ), + REDIS( 3, new RedisType() ), /** * influxdb */ - INFLUXDB(2,new InfluxdbType() ), + INFLUXDB( 2, new InfluxdbType() ), /** * shareserver */ - SHARESERVER(4,new ShareServerType() ); + SHARESERVER( 4, new ShareServerType() ); public int i; public CollectTopologyType collectTopologyType; + CollectTopology(int i, CollectTopologyType collectTopologyType) { - this.i=i; - this.collectTopologyType=collectTopologyType; + this.i = i; + this.collectTopologyType = collectTopologyType; } + //åŒ¹é… - public static CollectTopologyType match(int i){ + public static CollectTopologyType match(int i) { CollectTopology[] values = CollectTopology.values(); for (CollectTopology value : values) { - if(value.i==i){ + if (value.i == i) { return value.collectTopologyType; } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/emnus/ShareDataType.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/emnus/ShareDataType.java new file mode 100644 index 0000000000000000000000000000000000000000..40b5c99216bf361059943d9de0680805f2e8fb49 --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/topology/emnus/ShareDataType.java @@ -0,0 +1,31 @@ +package com.ruoyi.framework.topology.emnus; + +import shareconnector.domain.DataType; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/25 16:19 + */ +public enum ShareDataType { + FLOAT("FLOAT", DataType.FLOAT ), + INT("INT", DataType.INTEGER), + BOOLEAN("BOOLEAN", DataType.BOOLEAN), + STRING("STRING", DataType.STRING); + String type; + DataType dataType; + ShareDataType(String type, DataType dataType) { + this.type=type; + this.dataType=dataType; + } + //åŒ¹é… + public static DataType match(String type) { + ShareDataType[] values = ShareDataType.values(); + for (ShareDataType value : values) { + if (value.type .equals( type ) ) { + return value.dataType; + } + } + return null; + } +} diff --git a/ruoyi-mqtt/pom.xml b/ruoyi-mqtt/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..fc52e57bcd57434b2099ad5f701abd5e6b8fb1b1 --- /dev/null +++ b/ruoyi-mqtt/pom.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>ruoyi</artifactId> + <groupId>com.ruoyi</groupId> + <version>3.3.0</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>ruoyi-mqtt</artifactId> + <description> + mqtt + </description> + <dependencies> +<!-- <dependency>--> +<!-- <groupId>io.github.quickmsg</groupId>--> +<!-- <artifactId>smqtt-core</artifactId>--> +<!-- <version>1.0.4</version>--> +<!-- </dependency>--> +<!-- <dependency>--> +<!-- <artifactId>smqtt-registry-scube</artifactId>--> +<!-- <groupId>io.github.quickmsg</groupId>--> +<!-- <version>1.0.4</version>--> +<!-- </dependency>--> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-integration</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.integration</groupId> + <artifactId>spring-integration-stream</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.integration</groupId> + <artifactId>spring-integration-mqtt</artifactId> + </dependency> + <!-- 通用工具--> + <dependency> + <groupId>com.ruoyi</groupId> + <artifactId>ruoyi-common</artifactId> + </dependency> + + </dependencies> + +</project> \ No newline at end of file diff --git a/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/MqttConfiguration.java b/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/MqttConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..fa59ca540dcdea0d16aaef53eb751c63e47f0ee3 --- /dev/null +++ b/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/MqttConfiguration.java @@ -0,0 +1,43 @@ +package com.ruoyi.mqtt.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/5/20 9:42 + * mqtté…置类 获å–mqtt连接 + */ +@Slf4j +@Component +public class MqttConfiguration { + @Autowired + private MqttPushClient mqttPushClient; + + public static String host="tcp://127.0.0.1:1883"; + public static String clientId="mqttjs_cloud"; + public static String userName="admin"; + public static String password="public"; + public static int timeout=1000; + public static int keepAlive=10; + /** + * 连接至mqttæœåŠ¡å™¨ï¼ŒèŽ·å–mqtt连接 + * @return + */ + @Bean + @Primary + @ConditionalOnProperty(prefix = "mqtt", name = "enabled", havingValue = "true") + public MqttPushClient getMqttPushClient() { + log.info( host,clientId ); + //连接至mqttæœåŠ¡å™¨ï¼ŒèŽ·å–mqtt连接 + mqttPushClient.connect(host, clientId, userName, password, timeout, keepAlive); + //一连接mqtt,就订阅默认需è¦è®¢é˜…的主题(如test_queue) + new MqttSubClient(mqttPushClient); + return mqttPushClient; + } +} diff --git a/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/MqttPushClient.java b/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/MqttPushClient.java new file mode 100644 index 0000000000000000000000000000000000000000..9b926d99bb265b10d4822b67827e6ad42cda1563 --- /dev/null +++ b/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/MqttPushClient.java @@ -0,0 +1,92 @@ +package com.ruoyi.mqtt.config; + +import lombok.extern.slf4j.Slf4j; +import org.eclipse.paho.client.mqttv3.*; +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/5/20 9:43 + * 消æ¯å‘é€ç±» + */ +@Slf4j +@Component +public class MqttPushClient { + @Autowired + private PushCallback pushCallback; + + private static MqttClient client; + + + public static void setClient(MqttClient client) { + MqttPushClient.client = client; + } + + public static MqttClient getClient() { + return client; + } + + public void connect(String host, String clientID, String username, String password, int timeout, int keepalive) { + 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(keepalive); + MqttPushClient.setClient(client); + try { + //设置回调类 + client.setCallback(pushCallback); + //client.connect(options); + IMqttToken iMqttToken = client.connectWithResult(options); + boolean complete = iMqttToken.isComplete(); + log.info("MQTT连接"+(complete?"æˆåŠŸ":"失败")); + } catch (Exception e) { + e.printStackTrace(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + + /** + * å‘布,默认qos为0ï¼ŒéžæŒä¹…化 + * + * @param topic 主题å + * @param pushMessage æ¶ˆæ¯ + */ + public void publish(String topic, String pushMessage) { + publish(0, false, topic, pushMessage); + } + + /** + * å‘布 + * + * @param qos + * @param retained + * @param topic + * @param pushMessage + */ + public void publish(int qos, boolean retained, String topic, String pushMessage) { + MqttMessage message = new MqttMessage(); + message.setQos(qos); + message.setRetained(retained); + message.setPayload(pushMessage.getBytes()); + MqttTopic mTopic = client.getTopic(topic); + if (null == mTopic) { + log.error("主题ä¸å˜åœ¨:{}",mTopic); + } + try { + mTopic.publish(message); + } catch (Exception e) { + log.error("mqttå‘逿¶ˆæ¯å¼‚常:",e); + } + } +} diff --git a/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/MqttSubClient.java b/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/MqttSubClient.java new file mode 100644 index 0000000000000000000000000000000000000000..1849581f974a32f0d953a5ef492065e116fd57e7 --- /dev/null +++ b/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/MqttSubClient.java @@ -0,0 +1,52 @@ +package com.ruoyi.mqtt.config; + +import lombok.extern.slf4j.Slf4j; +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.MqttException; +import org.springframework.stereotype.Component; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/5/20 9:44 + * 消æ¯è®¢é˜…接收 + */ +@Slf4j +@Component +public class MqttSubClient { + public MqttSubClient(MqttPushClient client){ + subScribeDataPublishTopic(); + } + + + private void subScribeDataPublishTopic(){ + //订阅test_queue主题 + subscribe("test_queue"); + } + + /** + * 订阅æŸä¸ªä¸»é¢˜ï¼Œqos默认为0 + * + * @param topic + */ + public void subscribe(String topic) { + subscribe(topic, 0); + } + + /** + * 订阅æŸä¸ªä¸»é¢˜ + * + * @param topic 主题å + * @param qos + */ + public void subscribe(String topic, int qos) { + try { + MqttClient client = MqttPushClient.getClient(); + if (client == null) return; + client.subscribe(topic, qos); + log.info("订阅主题:{}",topic); + } catch ( MqttException e) { + e.printStackTrace(); + } + } +} diff --git a/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/PushCallback.java b/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/PushCallback.java new file mode 100644 index 0000000000000000000000000000000000000000..392620ab65ac36621b068b67e30b48a23a269b34 --- /dev/null +++ b/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/config/PushCallback.java @@ -0,0 +1,56 @@ +package com.ruoyi.mqtt.config; + +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.MqttMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/5/20 9:44 + * 消æ¯å›žè°ƒé‡è¿ž + */ +@Slf4j +@Component +public class PushCallback implements MqttCallback { + @Autowired + private MqttConfiguration mqttConfiguration; + + @Override + public void connectionLost(Throwable cause) { // 连接丢失åŽï¼Œä¸€èˆ¬åœ¨è¿™é‡Œé¢è¿›è¡Œé‡è¿ž + log.info("连接æ–开,æ£åœ¨é‡è¿ž"); + MqttPushClient mqttPushClient = mqttConfiguration.getMqttPushClient(); + if (null != mqttPushClient) { + mqttPushClient.connect(MqttConfiguration.host, MqttConfiguration.clientId, MqttConfiguration.userName, + MqttConfiguration.password, MqttConfiguration.timeout, MqttConfiguration.keepAlive); + log.info("å·²é‡è¿ž"); + } + + } + + /** + * å‘逿¶ˆæ¯ï¼Œæ¶ˆæ¯åˆ°è¾¾åŽå¤„ç†æ–¹æ³• + * @param token + */ + @Override + public void deliveryComplete(IMqttDeliveryToken token) { + + } + + /** + * 订阅主题接收到消æ¯å¤„ç†æ–¹æ³• + * @param topic + * @param message + */ + @Override + public void messageArrived(String topic, MqttMessage message) { + // subscribeåŽå¾—到的消æ¯ä¼šæ‰§è¡Œåˆ°è¿™é‡Œé¢,è¿™é‡Œåœ¨æŽ§åˆ¶å°æœ‰è¾“出 + log.info("接收消æ¯ä¸»é¢˜ : " + topic); + log.info("接收消æ¯Qos : " + message.getQos()); + log.info("接收消æ¯å†…容 : " + new String(message.getPayload())); + + } +} diff --git a/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/controller/MqttDemoController.java b/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/controller/MqttDemoController.java new file mode 100644 index 0000000000000000000000000000000000000000..db106d36801d45b459e1d78453e4613c53c30752 --- /dev/null +++ b/ruoyi-mqtt/src/main/java/com/ruoyi/mqtt/controller/MqttDemoController.java @@ -0,0 +1,33 @@ +package com.ruoyi.mqtt.controller; + +import com.ruoyi.mqtt.config.MqttPushClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/5/20 10:06 + */ +@RestController +@RequestMapping("/mqttDemo") +public class MqttDemoController { + @Autowired + private MqttPushClient mqttPushClient; + /** + * 通过MqttPushClientç±»publish方法的å‘é€"è¿™æ˜¯ä¸€æ¡æµ‹è¯•消æ¯"到å为"test_queue"çš„ä¸»é¢˜ï¼Œå¦‚æžœéœ€è¦æ‹¿åˆ°è¿™æ¡æ¶ˆæ¯ï¼Œ + * 需è¦åœ¨MqttSubClient类的subScribeDataPublishTopic方法进行é…置和订阅该主题(这个DEMOå·²ç»é…置好,并在连接mqttæœåŠ¡å™¨æ—¶å°±å·²ç»è®¢é˜…), + * é…置完æˆåŽ PushCallBack类的messageArrived方法会接收到已订阅主题接收到的消æ¯(订阅主题åŽå¯ä»¥åœ¨è¯¥æ–¹æ³•ä¸å¤„ç†æŽ¥æ”¶åˆ°çš„æ¶ˆæ¯) + */ + @RequestMapping("/testPublishMessage1") + public void testPublishMessage() { + mqttPushClient.publish("test_queue","è¿™æ˜¯ä¸€æ¡æµ‹è¯•消æ¯"); + } + + @RequestMapping("/testPublishMessage2") + public void testPublishMessage2( @RequestBody String message){ + mqttPushClient.publish("test_queue",message); + } +} diff --git a/ruoyi-mqtt/src/test/java/Test.java b/ruoyi-mqtt/src/test/java/Test.java new file mode 100644 index 0000000000000000000000000000000000000000..e1b8d5b3ccc87c9ab5a29ce8844ea5227af6a2b0 --- /dev/null +++ b/ruoyi-mqtt/src/test/java/Test.java @@ -0,0 +1,11 @@ + +/** + * @author jianglw + * @version 1.0 + * @date 2021/5/17 17:12 + */ +public class Test { + public static void main(String[] args) { + + } +} diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java deleted file mode 100644 index 25d1ddd029ca91c53e64c5d0b4dfa8ba4f1bdcbc..0000000000000000000000000000000000000000 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.ruoyi.quartz.task; - -import org.springframework.stereotype.Component; -import com.ruoyi.common.utils.StringUtils; - -/** - * 定时任务调度测试 - * - * @author ruoyi - */ -@Component("ryTask") -public class RyTask -{ - public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) - { - System.out.println(StringUtils.format("æ‰§è¡Œå¤šå‚æ–¹æ³•: å—符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); - } - - public void ryParams(String params) - { - System.out.println("æ‰§è¡Œæœ‰å‚æ–¹æ³•:" + params); - } - - public void ryNoParams() - { - System.out.println("æ‰§è¡Œæ— å‚æ–¹æ³•"); - } -} diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java index 6826787a67ca822749de60b49440ba0c66f7ef62..e9fbe9cdd65dd2d463c8380fa4f3891698698baf 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java @@ -61,3 +61,4 @@ public class CronUtils } } } + \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/topology/mapper/DBMapper.java b/ruoyi-system/src/main/java/com/ruoyi/topology/mapper/DBMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..9b81cfae4a875c4fa03f1c6ae404375fda234832 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/topology/mapper/DBMapper.java @@ -0,0 +1,16 @@ +package com.ruoyi.topology.mapper; + +import org.apache.ibatis.annotations.Select; +import org.springframework.stereotype.Service; + +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/26 10:22 + */ +public interface DBMapper { + @Select("${sql}") + Map<String,Object> getDBData(String sql); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/topology/mapper/TopologyMapper.java b/ruoyi-system/src/main/java/com/ruoyi/topology/mapper/TopologyMapper.java index 1ea1caec138890bcc8081f71000aa01fdde9946f..e8cd5292521f5b349d1989c950a99339a950c89c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/topology/mapper/TopologyMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/topology/mapper/TopologyMapper.java @@ -2,8 +2,10 @@ package com.ruoyi.topology.mapper; import com.ruoyi.common.core.domain.topology.TopologyData; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import java.util.List; +import java.util.Map; /** * @author jianglw @@ -21,4 +23,7 @@ public interface TopologyMapper { void updateTopologyById(TopologyData topologyData); Integer deleteTopologyById(Integer id); + + @Select( "${sql}" ) + Map<String,Object> getData(String sql); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/topology/service/IMysqlService.java b/ruoyi-system/src/main/java/com/ruoyi/topology/service/IMysqlService.java new file mode 100644 index 0000000000000000000000000000000000000000..5a11d9ee24bc50104f7309093cde991efd99480d --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/topology/service/IMysqlService.java @@ -0,0 +1,12 @@ +package com.ruoyi.topology.service; + +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/26 10:13 + */ +public interface IMysqlService { + Map<String,Object> getMysqlData(String sql); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/topology/service/IOracleService.java b/ruoyi-system/src/main/java/com/ruoyi/topology/service/IOracleService.java new file mode 100644 index 0000000000000000000000000000000000000000..aeb16d162ad444380ab6990b6aaffc13f3bb9a12 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/topology/service/IOracleService.java @@ -0,0 +1,12 @@ +package com.ruoyi.topology.service; + +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/26 10:19 + */ +public interface IOracleService { + Map<String,Object> getOracleData(String sql); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/topology/service/ITopologyService.java b/ruoyi-system/src/main/java/com/ruoyi/topology/service/ITopologyService.java index a789c04671f64cc1eedc08a3c878464a2cd56ab4..03b70bd2065fb32af9e7ede624563592cc678a97 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/topology/service/ITopologyService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/topology/service/ITopologyService.java @@ -3,6 +3,7 @@ package com.ruoyi.topology.service; import com.ruoyi.common.core.domain.topology.TopologyData; import java.util.List; +import java.util.Map; /** * @author jianglw @@ -19,4 +20,6 @@ public interface ITopologyService { void updateTopologyById(TopologyData topologyData); Integer deleteTopologyById(Integer id); + + Map<String,Object> getData(String sql); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/topology/service/impl/MysqlServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/topology/service/impl/MysqlServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..8cc82b8544ceb40da4e8069e6fd43705d20875e6 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/topology/service/impl/MysqlServiceImpl.java @@ -0,0 +1,28 @@ +package com.ruoyi.topology.service.impl; + +import com.ruoyi.common.annotation.DataSource; +import com.ruoyi.common.enums.DataSourceType; +import com.ruoyi.topology.mapper.DBMapper; +import com.ruoyi.topology.service.IMysqlService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/26 10:16 + */ + +@Service +public class MysqlServiceImpl implements IMysqlService { + @Autowired + private DBMapper dbMapper; + + @DataSource(DataSourceType.MYSQL) + @Override + public Map<String, Object> getMysqlData(String sql) { + return dbMapper.getDBData( sql ); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/topology/service/impl/OracleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/topology/service/impl/OracleServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..97c14ae153ec1f82a98ab5b5c0ccb48ce95080fd --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/topology/service/impl/OracleServiceImpl.java @@ -0,0 +1,28 @@ +package com.ruoyi.topology.service.impl; + +import com.ruoyi.common.annotation.DataSource; +import com.ruoyi.common.enums.DataSourceType; +import com.ruoyi.topology.mapper.DBMapper; +import com.ruoyi.topology.service.IOracleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.xml.ws.Action; +import java.util.Map; + +/** + * @author jianglw + * @version 1.0 + * @date 2021/4/26 10:20 + */ +@Service("OracleServiceImpl") +public class OracleServiceImpl implements IOracleService { + @Autowired + private DBMapper dbMapper; + + @DataSource(DataSourceType.ORACLE) + @Override + public Map<String, Object> getOracleData(String sql) { + return dbMapper.getDBData( sql ); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/topology/service/impl/TopologyService.java b/ruoyi-system/src/main/java/com/ruoyi/topology/service/impl/TopologyService.java index ce19933b8ec31843d039640963da03ece9663c94..94345bf0cdf8719f156fe21fc320fda85f1ecb56 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/topology/service/impl/TopologyService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/topology/service/impl/TopologyService.java @@ -1,12 +1,14 @@ package com.ruoyi.topology.service.impl; import com.ruoyi.common.core.domain.topology.TopologyData; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.topology.mapper.TopologyMapper; import com.ruoyi.topology.service.ITopologyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Map; /** * @author jianglw @@ -24,6 +26,9 @@ public class TopologyService implements ITopologyService { @Override public List<TopologyData> getTopology(TopologyData topologyData) { + if(!SecurityUtils.isAdmin( SecurityUtils.getLoginUser().getUser().getUserId() )){ + topologyData.setSwitchIt( "1" ); + } return topologyMapper.getTopology(topologyData); } @@ -41,4 +46,9 @@ public class TopologyService implements ITopologyService { public Integer deleteTopologyById(Integer id) { return topologyMapper.deleteTopologyById(id); } + + @Override + public Map<String,Object> getData(String sql) { + return topologyMapper.getData(sql); + } } diff --git a/ruoyi-system/src/main/resources/mapper/topology/TopologyMapper.xml b/ruoyi-system/src/main/resources/mapper/topology/TopologyMapper.xml index f2ec724fe27f1cef0611f8e79231f1d0c5c4c86a..7bccdcdabdeee3316d51f4f1378dfd9d84c613b1 100644 --- a/ruoyi-system/src/main/resources/mapper/topology/TopologyMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/topology/TopologyMapper.xml @@ -4,26 +4,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.ruoyi.topology.mapper.TopologyMapper"> <insert id="saveTopologyToId" parameterType="com.ruoyi.common.core.domain.topology.TopologyData" useGeneratedKeys="true" keyProperty="id"> - insert into topology_user (name,created_time) values (#{name},now()) + insert into topology (name,created_time,switch_it) values (#{name},now(),1) </insert> <select id="getTopology" parameterType="com.ruoyi.common.core.domain.topology.TopologyData" resultType="com.ruoyi.common.core.domain.topology.TopologyData"> - select id,name as name,date_format(created_time,'%Y-%m-%d %H:%i:%s') as createdTime,date_format(alter_time,'%Y-%m-%d %H:%i:%s') as alterTime from topology_user + select id,name as name,date_format(created_time,'%Y-%m-%d %H:%i:%s') as createdTime,date_format(alter_time,'%Y-%m-%d %H:%i:%s') as alterTime,switch_it as switchIt from topology <where> <if test="id !=null and id!=''">and id = #{id}</if> + <if test="switchIt !=null and switchIt!=''">and switch_it = #{switchIt}</if> </where> </select> <select id="getTopologyById" resultType="com.ruoyi.common.core.domain.topology.TopologyData"> - select id,name as name,date_format(created_time,'%Y-%m-%d %H:%i:%s') as createdTime,date_format(alter_time,'%Y-%m-%d %H:%i:%s') as alterTime from topology_user where id = #{id} + select id,name as name,date_format(created_time,'%Y-%m-%d %H:%i:%s') as createdTime,date_format(alter_time,'%Y-%m-%d %H:%i:%s') as alterTime,switch_it as switchIt from topology where id = #{id} </select> <update id="updateTopologyById" parameterType="com.ruoyi.common.core.domain.topology.TopologyData"> - update topology_user + update topology <trim prefix="set" suffixOverrides=","> <if test="name !=null and name !=''">name = #{name},</if> + <if test="switchIt !=null and switchIt !=''">switch_it = #{switchIt},</if> alter_time = now() </trim> where id =#{id} </update> <delete id="deleteTopologyById"> - delete from topology_user where id =#{id} + delete from topology where id =#{id} </delete> </mapper> \ No newline at end of file