作者 钟来

初始提交

正在显示 62 个修改的文件 包含 4460 行增加170 行删除
@@ -12,12 +12,11 @@ @@ -12,12 +12,11 @@
12 <artifactId>lh-mqtt-service</artifactId> 12 <artifactId>lh-mqtt-service</artifactId>
13 13
14 <dependencies> 14 <dependencies>
15 - <!-- 通用工具--> 15 + <!-- SpringBoot Web容器 -->
16 <dependency> 16 <dependency>
17 - <groupId>com.zhonglai.luhui</groupId>  
18 - <artifactId>ruoyi-common</artifactId> 17 + <groupId>org.springframework.boot</groupId>
  18 + <artifactId>spring-boot-starter-web</artifactId>
19 </dependency> 19 </dependency>
20 -  
21 <!-- 文档 --> 20 <!-- 文档 -->
22 <dependency> 21 <dependency>
23 <groupId>io.springfox</groupId> 22 <groupId>io.springfox</groupId>
@@ -52,16 +51,6 @@ @@ -52,16 +51,6 @@
52 <version>${swagger-ui.version}</version> 51 <version>${swagger-ui.version}</version>
53 </dependency> 52 </dependency>
54 53
55 - <dependency>  
56 - <groupId>tk.mybatis</groupId>  
57 - <artifactId>mapper</artifactId>  
58 - <!-- 建议使用最新版本,最新版本请从项目首页查找 -->  
59 - </dependency>  
60 - <dependency>  
61 - <groupId>tk.mybatis</groupId>  
62 - <artifactId>mapper-spring-boot-starter</artifactId>  
63 - </dependency>  
64 -  
65 <!-- mqtt --> 54 <!-- mqtt -->
66 <dependency> 55 <dependency>
67 <groupId>org.eclipse.paho</groupId> 56 <groupId>org.eclipse.paho</groupId>
@@ -100,6 +89,42 @@ @@ -100,6 +89,42 @@
100 <artifactId>mysql-connector-java</artifactId> 89 <artifactId>mysql-connector-java</artifactId>
101 <version>8.0.17</version> 90 <version>8.0.17</version>
102 </dependency> 91 </dependency>
  92 +
  93 + <!-- 支持data -->
  94 + <dependency>
  95 + <groupId>org.projectlombok</groupId>
  96 + <artifactId>lombok</artifactId>
  97 + </dependency>
  98 +
  99 +
  100 + <!-- 阿里JSON解析器 -->
  101 + <dependency>
  102 + <groupId>com.alibaba</groupId>
  103 + <artifactId>fastjson</artifactId>
  104 + </dependency>
  105 +
  106 + <!--常用工具类 -->
  107 + <dependency>
  108 + <groupId>org.apache.commons</groupId>
  109 + <artifactId>commons-lang3</artifactId>
  110 + </dependency>
  111 +
  112 + <!-- redis 缓存操作 -->
  113 + <dependency>
  114 + <groupId>org.springframework.boot</groupId>
  115 + <artifactId>spring-boot-starter-data-redis</artifactId>
  116 + </dependency>
  117 +
  118 + <!-- Token生成与解析-->
  119 + <dependency>
  120 + <groupId>io.jsonwebtoken</groupId>
  121 + <artifactId>jjwt</artifactId>
  122 + </dependency>
  123 +
  124 + <dependency>
  125 + <groupId>com.squareup.okhttp3</groupId>
  126 + <artifactId>okhttp</artifactId>
  127 + </dependency>
103 </dependencies> 128 </dependencies>
104 129
105 <build> 130 <build>
@@ -2,17 +2,15 @@ package com.zhonglai.luhui.mqtt; @@ -2,17 +2,15 @@ package com.zhonglai.luhui.mqtt;
2 2
3 import org.slf4j.Logger; 3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory; 4 import org.slf4j.LoggerFactory;
5 -import org.springframework.beans.factory.annotation.Autowired;  
6 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.boot.autoconfigure.SpringBootApplication;
7 import org.springframework.boot.builder.SpringApplicationBuilder; 6 import org.springframework.boot.builder.SpringApplicationBuilder;
8 import org.springframework.context.annotation.ComponentScan; 7 import org.springframework.context.annotation.ComponentScan;
9 8
10 9
11 @ComponentScan(basePackages = { 10 @ComponentScan(basePackages = {
12 - "com.luhui.ly.device.mqtt.comm.config",  
13 - "com.luhui.ly.device.mqtt.comm.factory",  
14 - "com.luhui.ly.device.mqtt.comm.agreement",  
15 - "com.luhui.ly.device.mqtt.comm.service", 11 + "com.zhonglai.luhui.mqtt.comm.config",
  12 + "com.zhonglai.luhui.mqtt.comm.agreement",
  13 + "com.zhonglai.luhui.mqtt.comm.service",
16 "com.zhonglai.luhui.mqtt.config", 14 "com.zhonglai.luhui.mqtt.config",
17 "com.zhonglai.luhui.mqtt.agreement", 15 "com.zhonglai.luhui.mqtt.agreement",
18 "com.zhonglai.luhui.mqtt.service", 16 "com.zhonglai.luhui.mqtt.service",
1 package com.zhonglai.luhui.mqtt.agreement; 1 package com.zhonglai.luhui.mqtt.agreement;
2 2
3 -import com.luhui.ly.device.mqtt.comm.dto.ServerDto;  
4 -import com.luhui.ly.device.mqtt.comm.factory.BusinessAgreement;  
5 -import com.luhui.ly.device.mqtt.comm.factory.Topic;  
6 -import com.zhonglai.luhui.mqtt.dto.PutReqDto; 3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
  5 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  6 +import com.zhonglai.luhui.mqtt.dto.topic.PutReqDto;
7 import org.springframework.stereotype.Service; 7 import org.springframework.stereotype.Service;
8 8
9 @Service("PUT_REQ") 9 @Service("PUT_REQ")
@@ -17,7 +17,6 @@ public class PutReqAgreement implements BusinessAgreement<PutReqDto> { @@ -17,7 +17,6 @@ public class PutReqAgreement implements BusinessAgreement<PutReqDto> {
17 17
18 @Override 18 @Override
19 public PutReqDto toData(byte[] bytes) { 19 public PutReqDto toData(byte[] bytes) {
20 -  
21 String str = new String(bytes); 20 String str = new String(bytes);
22 return new PutReqDto().setData(str); 21 return new PutReqDto().setData(str);
23 } 22 }
1 package com.zhonglai.luhui.mqtt.comm.clien; 1 package com.zhonglai.luhui.mqtt.comm.clien;
2 2
3 3
4 -import com.ruoyi.common.core.domain.Message;  
5 import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; 4 import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent;
  5 +import com.zhonglai.luhui.mqtt.dto.Message;
6 6
7 /** 7 /**
8 * 客户端链接 8 * 客户端链接
1 package com.zhonglai.luhui.mqtt.comm.clien.impl; 1 package com.zhonglai.luhui.mqtt.comm.clien.impl;
2 2
3 3
4 -import com.ruoyi.common.core.domain.Message;  
5 -import com.ruoyi.common.core.domain.MessageCode;  
6 -import com.ruoyi.common.core.domain.MessageCodeType;  
7 import com.zhonglai.luhui.mqtt.comm.clien.ClienConnection; 4 import com.zhonglai.luhui.mqtt.comm.clien.ClienConnection;
8 import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; 5 import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent;
  6 +import com.zhonglai.luhui.mqtt.dto.Message;
  7 +import com.zhonglai.luhui.mqtt.dto.MessageCode;
  8 +import com.zhonglai.luhui.mqtt.dto.MessageCodeType;
9 9
10 public class ClienConnectionImpl implements ClienConnection { 10 public class ClienConnectionImpl implements ClienConnection {
11 private Message message = new Message(); 11 private Message message = new Message();
1 -package com.zhonglai.luhui.mqtt.comm.config;  
2 -  
3 -import org.aspectj.lang.JoinPoint;  
4 -import org.aspectj.lang.annotation.AfterReturning;  
5 -import org.aspectj.lang.annotation.Aspect;  
6 -import org.aspectj.lang.annotation.Before;  
7 -import org.aspectj.lang.annotation.Pointcut;  
8 -import org.slf4j.Logger;  
9 -import org.slf4j.LoggerFactory;  
10 -import org.springframework.stereotype.Component;  
11 -import org.springframework.web.context.request.RequestContextHolder;  
12 -import org.springframework.web.context.request.ServletRequestAttributes;  
13 -  
14 -import javax.servlet.http.HttpServletRequest;  
15 -import java.util.Enumeration;  
16 -import java.util.HashMap;  
17 -import java.util.Map;  
18 -  
19 -@Aspect  
20 -@Component  
21 -public class ControllerLogAspect {  
22 - private Logger logger = LoggerFactory.getLogger(this.getClass());  
23 -  
24 - @Pointcut("execution(public * com.zhonglai.luhui.mqtt.*.controller..*.*(..))")  
25 - public void controllerLog() {  
26 -  
27 - }  
28 -  
29 - @Before("controllerLog()")  
30 - public void doBefore(JoinPoint joinPoint)  
31 - {  
32 - // 接收到请求,记录请求内容  
33 - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();  
34 - HttpServletRequest request = attributes.getRequest();  
35 - Enumeration<String> hs = request.getHeaderNames();  
36 - Map<String,Object> map = new HashMap<>();  
37 - while (hs.hasMoreElements())  
38 - {  
39 - String key= hs.nextElement();  
40 - map.put(key,request.getHeader(key));  
41 - }  
42 - logger.info("请求url:{},请求head:{},请求IP:{},请求方法:{},请求参数:{}",request.getRequestURL(),map,request.getRemoteAddr(),joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName(),joinPoint.getArgs());  
43 - }  
44 -  
45 - @AfterReturning(returning = "ret", pointcut = "controllerLog()")  
46 - public void doAfterReturning(Object ret) {  
47 - // 处理完请求,返回内容  
48 - logger.info("返回 {} " , GsonConstructor.get().toJson(ret));  
49 - }  
50 -}  
1 package com.zhonglai.luhui.mqtt.comm.config; 1 package com.zhonglai.luhui.mqtt.comm.config;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 -import com.ruoyi.common.utils.http.HttpUtils; 4 +import com.zhonglai.luhui.mqtt.comm.util.http.HttpUtils;
5 import org.slf4j.Logger; 5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 6 import org.slf4j.LoggerFactory;
7 import org.springframework.beans.factory.annotation.Value; 7 import org.springframework.beans.factory.annotation.Value;
@@ -50,7 +50,7 @@ public class BaseDao { @@ -50,7 +50,7 @@ public class BaseDao {
50 {// 50 {//
51 Method method; 51 Method method;
52 try { 52 try {
53 - method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(field.getName())); 53 + method = object.getClass().getMethod("get"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName(field.getName()));
54 Object value = method.invoke(object); 54 Object value = method.invoke(object);
55 if(null != value) 55 if(null != value)
56 { 56 {
@@ -165,7 +165,7 @@ public class BaseDao { @@ -165,7 +165,7 @@ public class BaseDao {
165 {// 165 {//
166 Method method; 166 Method method;
167 try { 167 try {
168 - method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(field.getName())); 168 + method = object.getClass().getMethod("get"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName(field.getName()));
169 Object value = method.invoke(object); 169 Object value = method.invoke(object);
170 if(!"(".equals(values) ) 170 if(!"(".equals(values) )
171 { 171 {
@@ -233,7 +233,7 @@ public class BaseDao { @@ -233,7 +233,7 @@ public class BaseDao {
233 { 233 {
234 Field field = fields[i]; 234 Field field = fields[i];
235 try { 235 try {
236 - Method method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(field.getName())); 236 + Method method = object.getClass().getMethod("get"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName(field.getName()));
237 Object value = method.invoke(object); 237 Object value = method.invoke(object);
238 if(null != value) 238 if(null != value)
239 { 239 {
@@ -273,7 +273,7 @@ public class BaseDao { @@ -273,7 +273,7 @@ public class BaseDao {
273 for(int i =0;i<wheres.length;i++) 273 for(int i =0;i<wheres.length;i++)
274 { 274 {
275 try { 275 try {
276 - Method method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(wheres[i])); 276 + Method method = object.getClass().getMethod("get"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName(wheres[i]));
277 Object value = method.invoke(object); 277 Object value = method.invoke(object);
278 sql += " and "; 278 sql += " and ";
279 sql += changTableNameFromObject(wheres[i]) + "=?"; 279 sql += changTableNameFromObject(wheres[i]) + "=?";
@@ -300,7 +300,7 @@ public class BaseDao { @@ -300,7 +300,7 @@ public class BaseDao {
300 }else{ 300 }else{
301 Method method = null; 301 Method method = null;
302 try { 302 try {
303 - method = object.getClass().getMethod("get"+ com.ruoyi.common.utils.StringUtils.getName("id")); 303 + method = object.getClass().getMethod("get"+ com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName("id"));
304 Object value = method.invoke(object); 304 Object value = method.invoke(object);
305 sql += " and "; 305 sql += " and ";
306 sql += "id=?"; 306 sql += "id=?";
@@ -690,7 +690,7 @@ public class BaseDao { @@ -690,7 +690,7 @@ public class BaseDao {
690 Field field = fields[i]; 690 Field field = fields[i];
691 try { 691 try {
692 Method method; 692 Method method;
693 - method = object.getClass().getMethod("get"+ com.ruoyi.common.utils.StringUtils.getName(field.getName())); 693 + method = object.getClass().getMethod("get"+ com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName(field.getName()));
694 Object value = method.invoke(object); 694 Object value = method.invoke(object);
695 if(!(null == value)) 695 if(!(null == value))
696 { 696 {
@@ -759,7 +759,7 @@ public class BaseDao { @@ -759,7 +759,7 @@ public class BaseDao {
759 {// 759 {//
760 Method method; 760 Method method;
761 try { 761 try {
762 - method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(field.getName())); 762 + method = object.getClass().getMethod("get"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName(field.getName()));
763 Object value = method.invoke(object); 763 Object value = method.invoke(object);
764 if(null != value) 764 if(null != value)
765 { 765 {
@@ -841,7 +841,7 @@ public class BaseDao { @@ -841,7 +841,7 @@ public class BaseDao {
841 Field field = fields[j]; 841 Field field = fields[j];
842 Method method; 842 Method method;
843 try { 843 try {
844 - method = object.getClass().getMethod("get"+com.ruoyi.common.utils.StringUtils.getName(field.getName())); 844 + method = object.getClass().getMethod("get"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.getName(field.getName()));
845 Object value = method.invoke(object); 845 Object value = method.invoke(object);
846 if(null == value) 846 if(null == value)
847 { 847 {
@@ -945,6 +945,6 @@ public class BaseDao { @@ -945,6 +945,6 @@ public class BaseDao {
945 e.printStackTrace(); 945 e.printStackTrace();
946 } 946 }
947 947
948 - return com.ruoyi.common.utils.StringUtils.toUnderScoreCase(tableNmae); 948 + return com.zhonglai.luhui.mqtt.comm.util.StringUtils.toUnderScoreCase(tableNmae);
949 } 949 }
950 } 950 }
1 package com.zhonglai.luhui.mqtt.comm.dto; 1 package com.zhonglai.luhui.mqtt.comm.dto;
2 2
3 -import com.luhui.domain.log.LogDeviceOperation;  
4 3
5 /** 4 /**
6 * 设备操作类型 5 * 设备操作类型
1 package com.zhonglai.luhui.mqtt.comm.dto; 1 package com.zhonglai.luhui.mqtt.comm.dto;
2 2
  3 +import com.zhonglai.luhui.mqtt.dto.Message;
3 import lombok.Data; 4 import lombok.Data;
4 5
5 @Data 6 @Data
@@ -2,6 +2,7 @@ package com.zhonglai.luhui.mqtt.comm.dto; @@ -2,6 +2,7 @@ package com.zhonglai.luhui.mqtt.comm.dto;
2 2
3 3
4 import com.zhonglai.luhui.mqtt.comm.factory.Topic; 4 import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  5 +import com.zhonglai.luhui.mqtt.dto.Message;
5 6
6 public interface ServerAgreementContent { 7 public interface ServerAgreementContent {
7 String getClienConnectionId(); 8 String getClienConnectionId();
1 package com.zhonglai.luhui.mqtt.comm.dto; 1 package com.zhonglai.luhui.mqtt.comm.dto;
2 2
3 -import com.luhui.ly.service.comm.nio.util.TableUtil; 3 +
  4 +import com.zhonglai.luhui.mqtt.comm.util.TableUtil;
4 5
5 import java.util.Date; 6 import java.util.Date;
6 7
  1 +package com.zhonglai.luhui.mqtt.comm.dto.iot;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import org.apache.commons.lang3.builder.ToStringBuilder;
  6 +import org.apache.commons.lang3.builder.ToStringStyle;
  7 +
  8 +/**
  9 + * 主机/网关对象 iot_device
  10 + *
  11 + * @author 钟来
  12 + * @date 2022-08-26
  13 + */
  14 +@ApiModel("主机/网关")
  15 +public class IotDevice
  16 +{
  17 + private static final long serialVersionUID = 1L;
  18 +
  19 + /** 激活时间 */
  20 + @ApiModelProperty("激活时间")
  21 + private Integer active_time;
  22 +
  23 + /** 主键 */
  24 + @ApiModelProperty("主键")
  25 + private String client_id;
  26 +
  27 + /** 是否补充权限,前面加${{roleid}}/${{username}}/${{clientid}}(0否,1是) */
  28 + @ApiModelProperty("是否补充权限,前面加${{roleid}}/${{username}}/${{clientid}}(0否,1是)")
  29 + private Integer completion_auth;
  30 +
  31 + /** 创建者 */
  32 + @ApiModelProperty("创建者")
  33 + private String create_by;
  34 +
  35 + /** 创建时间 */
  36 + @ApiModelProperty("创建时间")
  37 + private Integer create_time;
  38 +
  39 + /** 删除标志(0代表存在 2代表删除) */
  40 + @ApiModelProperty("删除标志(0代表存在 2代表删除)")
  41 + private Integer del_flag;
  42 +
  43 + /** 固件版本 */
  44 + @ApiModelProperty("固件版本")
  45 + private Float firmware_version;
  46 +
  47 + /** 图片地址 */
  48 + @ApiModelProperty("图片地址")
  49 + private String img_url;
  50 +
  51 + /** 是否启用设备影子(0=禁用,1=启用) */
  52 + @ApiModelProperty("是否启用设备影子(0=禁用,1=启用)")
  53 + private Integer is_shadow;
  54 +
  55 + /** 设备纬度 */
  56 + @ApiModelProperty("设备纬度")
  57 + private Double latitude;
  58 +
  59 + /** 定位方式(1=ip自动定位,2=设备定位,3=自定义) */
  60 + @ApiModelProperty("定位方式(1=ip自动定位,2=设备定位,3=自定义)")
  61 + private Integer location_way;
  62 +
  63 + /** 设备经度 */
  64 + @ApiModelProperty("设备经度")
  65 + private Double longitude;
  66 +
  67 + /** 设备名称 */
  68 + @ApiModelProperty("设备名称")
  69 + private String name;
  70 +
  71 + /** 设备所在地址 */
  72 + @ApiModelProperty("设备所在地址")
  73 + private String network_address;
  74 +
  75 + /** 设备入网IP */
  76 + @ApiModelProperty("设备入网IP")
  77 + private String network_ip;
  78 +
  79 + /** 信号强度( 信号极好4格[-55— 0], 信号好3格[-70— -55], 信号一般2格[-85— -70], 信号差1格[-100— -85]) */
  80 + @ApiModelProperty("信号强度( 信号极好4格[-55— 0], 信号好3格[-70— -55], 信号一般2格[-85— -70], 信号差1格[-100— -85])")
  81 + private Integer rssi;
  82 +
  83 + /** 设备状态(1-未激活,2-禁用,3-在线,4-离线) */
  84 + @ApiModelProperty("设备状态(1-未激活,2-禁用,3-在线,4-离线)")
  85 + private Integer status;
  86 +
  87 + /** 设备摘要,格式[{"name":"device"},{"chip":"esp8266"}] */
  88 + @ApiModelProperty("设备摘要,格式[{\"name\":\"device\"},{\"chip\":\"esp8266\"}]")
  89 + private String summary;
  90 +
  91 + /** 物模型值 */
  92 + @ApiModelProperty("物模型值")
  93 + private String things_model_value;
  94 +
  95 + /** 更新者 */
  96 + @ApiModelProperty("更新者")
  97 + private String update_by;
  98 +
  99 + /** 更新时间 */
  100 + @ApiModelProperty("更新时间")
  101 + private Integer update_time;
  102 +
  103 + /** 用户id */
  104 + @ApiModelProperty("用户id")
  105 + private Integer user_id;
  106 +
  107 + @ApiModelProperty("负载类型(String,Json,Bite16,Bite32)")
  108 + private String payload_type;
  109 +
  110 + public String getPayload_type() {
  111 + return payload_type;
  112 + }
  113 +
  114 + public void setPayload_type(String payload_type) {
  115 + this.payload_type = payload_type;
  116 + }
  117 +
  118 + public void setActive_time(Integer active_time)
  119 + {
  120 + this.active_time = active_time;
  121 + }
  122 +
  123 + public Integer getActive_time()
  124 + {
  125 + return active_time;
  126 + }
  127 + public void setClient_id(String client_id)
  128 + {
  129 + this.client_id = client_id;
  130 + }
  131 +
  132 + public String getClient_id()
  133 + {
  134 + return client_id;
  135 + }
  136 + public void setCompletion_auth(Integer completion_auth)
  137 + {
  138 + this.completion_auth = completion_auth;
  139 + }
  140 +
  141 + public Integer getCompletion_auth()
  142 + {
  143 + return completion_auth;
  144 + }
  145 + public void setCreate_by(String create_by)
  146 + {
  147 + this.create_by = create_by;
  148 + }
  149 +
  150 + public String getCreate_by()
  151 + {
  152 + return create_by;
  153 + }
  154 + public void setCreate_time(Integer create_time)
  155 + {
  156 + this.create_time = create_time;
  157 + }
  158 +
  159 + public Integer getCreate_time()
  160 + {
  161 + return create_time;
  162 + }
  163 + public void setDel_flag(Integer del_flag)
  164 + {
  165 + this.del_flag = del_flag;
  166 + }
  167 +
  168 + public Integer getDel_flag()
  169 + {
  170 + return del_flag;
  171 + }
  172 + public void setFirmware_version(Float firmware_version)
  173 + {
  174 + this.firmware_version = firmware_version;
  175 + }
  176 +
  177 + public Float getFirmware_version()
  178 + {
  179 + return firmware_version;
  180 + }
  181 + public void setImg_url(String img_url)
  182 + {
  183 + this.img_url = img_url;
  184 + }
  185 +
  186 + public String getImg_url()
  187 + {
  188 + return img_url;
  189 + }
  190 + public void setIs_shadow(Integer is_shadow)
  191 + {
  192 + this.is_shadow = is_shadow;
  193 + }
  194 +
  195 + public Integer getIs_shadow()
  196 + {
  197 + return is_shadow;
  198 + }
  199 + public void setLatitude(Double latitude)
  200 + {
  201 + this.latitude = latitude;
  202 + }
  203 +
  204 + public Double getLatitude()
  205 + {
  206 + return latitude;
  207 + }
  208 + public void setLocation_way(Integer location_way)
  209 + {
  210 + this.location_way = location_way;
  211 + }
  212 +
  213 + public Integer getLocation_way()
  214 + {
  215 + return location_way;
  216 + }
  217 + public void setLongitude(Double longitude)
  218 + {
  219 + this.longitude = longitude;
  220 + }
  221 +
  222 + public Double getLongitude()
  223 + {
  224 + return longitude;
  225 + }
  226 + public void setName(String name)
  227 + {
  228 + this.name = name;
  229 + }
  230 +
  231 + public String getName()
  232 + {
  233 + return name;
  234 + }
  235 + public void setNetwork_address(String network_address)
  236 + {
  237 + this.network_address = network_address;
  238 + }
  239 +
  240 + public String getNetwork_address()
  241 + {
  242 + return network_address;
  243 + }
  244 + public void setNetwork_ip(String network_ip)
  245 + {
  246 + this.network_ip = network_ip;
  247 + }
  248 +
  249 + public String getNetwork_ip()
  250 + {
  251 + return network_ip;
  252 + }
  253 + public void setRssi(Integer rssi)
  254 + {
  255 + this.rssi = rssi;
  256 + }
  257 +
  258 + public Integer getRssi()
  259 + {
  260 + return rssi;
  261 + }
  262 + public void setStatus(Integer status)
  263 + {
  264 + this.status = status;
  265 + }
  266 +
  267 + public Integer getStatus()
  268 + {
  269 + return status;
  270 + }
  271 + public void setSummary(String summary)
  272 + {
  273 + this.summary = summary;
  274 + }
  275 +
  276 + public String getSummary()
  277 + {
  278 + return summary;
  279 + }
  280 + public void setThings_model_value(String things_model_value)
  281 + {
  282 + this.things_model_value = things_model_value;
  283 + }
  284 +
  285 + public String getThings_model_value()
  286 + {
  287 + return things_model_value;
  288 + }
  289 + public void setUpdate_by(String update_by)
  290 + {
  291 + this.update_by = update_by;
  292 + }
  293 +
  294 + public String getUpdate_by()
  295 + {
  296 + return update_by;
  297 + }
  298 + public void setUpdate_time(Integer update_time)
  299 + {
  300 + this.update_time = update_time;
  301 + }
  302 +
  303 + public Integer getUpdate_time()
  304 + {
  305 + return update_time;
  306 + }
  307 + public void setUser_id(Integer user_id)
  308 + {
  309 + this.user_id = user_id;
  310 + }
  311 +
  312 + public Integer getUser_id()
  313 + {
  314 + return user_id;
  315 + }
  316 +
  317 + public String toString() {
  318 + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
  319 + .append("active_time", getActive_time())
  320 + .append("client_id", getClient_id())
  321 + .append("completion_auth", getCompletion_auth())
  322 + .append("create_by", getCreate_by())
  323 + .append("create_time", getCreate_time())
  324 + .append("del_flag", getDel_flag())
  325 + .append("firmware_version", getFirmware_version())
  326 + .append("img_url", getImg_url())
  327 + .append("is_shadow", getIs_shadow())
  328 + .append("latitude", getLatitude())
  329 + .append("location_way", getLocation_way())
  330 + .append("longitude", getLongitude())
  331 + .append("name", getName())
  332 + .append("network_address", getNetwork_address())
  333 + .append("network_ip", getNetwork_ip())
  334 + .append("rssi", getRssi())
  335 + .append("status", getStatus())
  336 + .append("summary", getSummary())
  337 + .append("things_model_value", getThings_model_value())
  338 + .append("update_by", getUpdate_by())
  339 + .append("update_time", getUpdate_time())
  340 + .append("user_id", getUser_id())
  341 + .toString();
  342 + }
  343 +}
  1 +package com.zhonglai.luhui.mqtt.comm.dto.iot;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import org.apache.commons.lang3.builder.ToStringBuilder;
  6 +import org.apache.commons.lang3.builder.ToStringStyle;
  7 +
  8 +/**
  9 + * topic权限控制对象 iot_permission
  10 + *
  11 + * @author 钟来
  12 + * @date 2022-08-26
  13 + */
  14 +@ApiModel("topic权限控制")
  15 +public class IotPermission
  16 +{
  17 + private static final long serialVersionUID = 1L;
  18 +
  19 + /** 动作(PUBLISH,SUBSCRIBE,ALL) */
  20 + @ApiModelProperty("动作(PUBLISH,SUBSCRIBE,ALL)")
  21 + private String activity;
  22 +
  23 + /** 创建时间 */
  24 + @ApiModelProperty("创建时间")
  25 + private Integer create_time;
  26 +
  27 + /** 描述 */
  28 + @ApiModelProperty("描述")
  29 + private String describe;
  30 +
  31 + /** 主键 */
  32 + @ApiModelProperty("主键")
  33 + private Integer id;
  34 +
  35 + /** 质量(ZERO,ONE,TWO,ZERO_ONE,ZERO_TWO,ONE_TWO,ALL) */
  36 + @ApiModelProperty("质量(ZERO,ONE,TWO,ZERO_ONE,ZERO_TWO,ONE_TWO,ALL)")
  37 + private String qos;
  38 +
  39 + /** 是否保留(RETAINED,NOT_RETAINED,ALL) */
  40 + @ApiModelProperty("是否保留(RETAINED,NOT_RETAINED,ALL)")
  41 + private String retain;
  42 +
  43 + /** 角色id */
  44 + @ApiModelProperty("角色id")
  45 + private Integer role_id;
  46 +
  47 + /** 共享组 */
  48 + @ApiModelProperty("共享组")
  49 + private String shared_group;
  50 +
  51 + /** 共享订阅(SHARED,NOT_SHARED,ALL) */
  52 + @ApiModelProperty("共享订阅(SHARED,NOT_SHARED,ALL)")
  53 + private String shared_subscription;
  54 +
  55 + /** topic(同一角色有切只有一个) */
  56 + @ApiModelProperty("topic(同一角色有切只有一个)")
  57 + private String topic;
  58 +
  59 + public void setActivity(String activity)
  60 + {
  61 + this.activity = activity;
  62 + }
  63 +
  64 + public String getActivity()
  65 + {
  66 + return activity;
  67 + }
  68 + public void setCreate_time(Integer create_time)
  69 + {
  70 + this.create_time = create_time;
  71 + }
  72 +
  73 + public Integer getCreate_time()
  74 + {
  75 + return create_time;
  76 + }
  77 + public void setDescribe(String describe)
  78 + {
  79 + this.describe = describe;
  80 + }
  81 +
  82 + public String getDescribe()
  83 + {
  84 + return describe;
  85 + }
  86 + public void setId(Integer id)
  87 + {
  88 + this.id = id;
  89 + }
  90 +
  91 + public Integer getId()
  92 + {
  93 + return id;
  94 + }
  95 + public void setQos(String qos)
  96 + {
  97 + this.qos = qos;
  98 + }
  99 +
  100 + public String getQos()
  101 + {
  102 + return qos;
  103 + }
  104 + public void setRetain(String retain)
  105 + {
  106 + this.retain = retain;
  107 + }
  108 +
  109 + public String getRetain()
  110 + {
  111 + return retain;
  112 + }
  113 + public void setRole_id(Integer role_id)
  114 + {
  115 + this.role_id = role_id;
  116 + }
  117 +
  118 + public Integer getRole_id()
  119 + {
  120 + return role_id;
  121 + }
  122 + public void setShared_group(String shared_group)
  123 + {
  124 + this.shared_group = shared_group;
  125 + }
  126 +
  127 + public String getShared_group()
  128 + {
  129 + return shared_group;
  130 + }
  131 + public void setShared_subscription(String shared_subscription)
  132 + {
  133 + this.shared_subscription = shared_subscription;
  134 + }
  135 +
  136 + public String getShared_subscription()
  137 + {
  138 + return shared_subscription;
  139 + }
  140 + public void setTopic(String topic)
  141 + {
  142 + this.topic = topic;
  143 + }
  144 +
  145 + public String getTopic()
  146 + {
  147 + return topic;
  148 + }
  149 +
  150 + public String toString() {
  151 + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
  152 + .append("activity", getActivity())
  153 + .append("create_time", getCreate_time())
  154 + .append("describe", getDescribe())
  155 + .append("id", getId())
  156 + .append("qos", getQos())
  157 + .append("retain", getRetain())
  158 + .append("role_id", getRole_id())
  159 + .append("shared_group", getShared_group())
  160 + .append("shared_subscription", getShared_subscription())
  161 + .append("topic", getTopic())
  162 + .toString();
  163 + }
  164 +}
  1 +package com.zhonglai.luhui.mqtt.comm.dto.iot;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import org.apache.commons.lang3.builder.ToStringBuilder;
  6 +import org.apache.commons.lang3.builder.ToStringStyle;
  7 +
  8 +/**
  9 + * 公司对象 iot_role
  10 + *
  11 + * @author 钟来
  12 + * @date 2022-08-26
  13 + */
  14 +@ApiModel("公司")
  15 +public class IotRole
  16 +{
  17 + private static final long serialVersionUID = 1L;
  18 +
  19 + /** 创建时间 */
  20 + @ApiModelProperty("创建时间")
  21 + private Integer create_time;
  22 +
  23 + /** 描述 */
  24 + @ApiModelProperty("描述")
  25 + private String describe;
  26 +
  27 + /** 主键 */
  28 + @ApiModelProperty("主键")
  29 + private Integer id;
  30 +
  31 + /** 名称 */
  32 + @ApiModelProperty("名称")
  33 + private String name;
  34 +
  35 + /** 是否使用(0否,1是) */
  36 + @ApiModelProperty("是否使用(0否,1是)")
  37 + private Integer used;
  38 +
  39 + public void setCreate_time(Integer create_time)
  40 + {
  41 + this.create_time = create_time;
  42 + }
  43 +
  44 + public Integer getCreate_time()
  45 + {
  46 + return create_time;
  47 + }
  48 + public void setDescribe(String describe)
  49 + {
  50 + this.describe = describe;
  51 + }
  52 +
  53 + public String getDescribe()
  54 + {
  55 + return describe;
  56 + }
  57 + public void setId(Integer id)
  58 + {
  59 + this.id = id;
  60 + }
  61 +
  62 + public Integer getId()
  63 + {
  64 + return id;
  65 + }
  66 + public void setName(String name)
  67 + {
  68 + this.name = name;
  69 + }
  70 +
  71 + public String getName()
  72 + {
  73 + return name;
  74 + }
  75 + public void setUsed(Integer used)
  76 + {
  77 + this.used = used;
  78 + }
  79 +
  80 + public Integer getUsed()
  81 + {
  82 + return used;
  83 + }
  84 +
  85 + public String toString() {
  86 + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
  87 + .append("create_time", getCreate_time())
  88 + .append("describe", getDescribe())
  89 + .append("id", getId())
  90 + .append("name", getName())
  91 + .append("used", getUsed())
  92 + .toString();
  93 + }
  94 +}
  1 +package com.zhonglai.luhui.mqtt.comm.dto.iot;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import org.apache.commons.lang3.builder.ToStringBuilder;
  6 +import org.apache.commons.lang3.builder.ToStringStyle;
  7 +
  8 +/**
  9 + * 终端对象 iot_terminal
  10 + *
  11 + * @author 钟来
  12 + * @date 2022-08-26
  13 + */
  14 +@ApiModel("终端")
  15 +public class IotTerminal
  16 +{
  17 + private static final long serialVersionUID = 1L;
  18 +
  19 + /** 网关id */
  20 + @ApiModelProperty("网关id")
  21 + private String device_id;
  22 +
  23 + /** 主键id */
  24 + @ApiModelProperty("主键id")
  25 + private String id;
  26 +
  27 + /** 终端名称 */
  28 + @ApiModelProperty("终端名称")
  29 + private String name;
  30 +
  31 + /** 物模型值 */
  32 + @ApiModelProperty("物模型值")
  33 + private String things_model_value;
  34 +
  35 + /** 更新时间 */
  36 + @ApiModelProperty("更新时间")
  37 + private Integer update_time;
  38 +
  39 + public void setDevice_id(String device_id)
  40 + {
  41 + this.device_id = device_id;
  42 + }
  43 +
  44 + public String getDevice_id()
  45 + {
  46 + return device_id;
  47 + }
  48 + public void setId(String id)
  49 + {
  50 + this.id = id;
  51 + }
  52 +
  53 + public String getId()
  54 + {
  55 + return id;
  56 + }
  57 + public void setName(String name)
  58 + {
  59 + this.name = name;
  60 + }
  61 +
  62 + public String getName()
  63 + {
  64 + return name;
  65 + }
  66 + public void setThings_model_value(String things_model_value)
  67 + {
  68 + this.things_model_value = things_model_value;
  69 + }
  70 +
  71 + public String getThings_model_value()
  72 + {
  73 + return things_model_value;
  74 + }
  75 + public void setUpdate_time(Integer update_time)
  76 + {
  77 + this.update_time = update_time;
  78 + }
  79 +
  80 + public Integer getUpdate_time()
  81 + {
  82 + return update_time;
  83 + }
  84 +
  85 + public String toString() {
  86 + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
  87 + .append("device_id", getDevice_id())
  88 + .append("id", getId())
  89 + .append("name", getName())
  90 + .append("things_model_value", getThings_model_value())
  91 + .append("update_time", getUpdate_time())
  92 + .toString();
  93 + }
  94 +}
  1 +package com.zhonglai.luhui.mqtt.comm.dto.iot;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import org.apache.commons.lang3.builder.ToStringBuilder;
  6 +import org.apache.commons.lang3.builder.ToStringStyle;
  7 +
  8 +/**
  9 + * 物模型模板对象 iot_things_model
  10 + *
  11 + * @author 钟来
  12 + * @date 2022-08-26
  13 + */
  14 +@ApiModel("物模型模板")
  15 +public class IotThingsModel
  16 +{
  17 + private static final long serialVersionUID = 1L;
  18 +
  19 + /** 创建者 */
  20 + @ApiModelProperty("创建者")
  21 + private String create_by;
  22 +
  23 + /** 创建时间 */
  24 + @ApiModelProperty("创建时间")
  25 + private java.util.Date create_time;
  26 +
  27 + /** 数据类型(integer、decimal、string、bool、array、enum) */
  28 + @ApiModelProperty("数据类型(integer、decimal、string、bool、array、enum)")
  29 + private String data_type;
  30 +
  31 + /** 删除标志(0代表存在 2代表删除) */
  32 + @ApiModelProperty("删除标志(0代表存在 2代表删除)")
  33 + private String del_flag;
  34 +
  35 + /** 标识符,用户下唯一 */
  36 + @ApiModelProperty("标识符,用户下唯一")
  37 + private String identifier;
  38 +
  39 + /** 是否实时监测(0-否,1-是) */
  40 + @ApiModelProperty("是否实时监测(0-否,1-是)")
  41 + private Integer is_monitor;
  42 +
  43 + /** 是否记录日志(0否,1是) */
  44 + @ApiModelProperty("是否记录日志(0否,1是)")
  45 + private Integer is_save_log;
  46 +
  47 + /** 是否首页显示(0-否,1-是) */
  48 + @ApiModelProperty("是否首页显示(0-否,1-是)")
  49 + private Integer is_top;
  50 +
  51 + /** 物模型ID */
  52 + @ApiModelProperty("物模型ID")
  53 + private Integer model_id;
  54 +
  55 + /** 物模型名称 */
  56 + @ApiModelProperty("物模型名称")
  57 + private String model_name;
  58 +
  59 + /** 数据定义 */
  60 + @ApiModelProperty("数据定义")
  61 + private String specs;
  62 +
  63 + /** 模型类别(1-属性,2-功能,3-事件) */
  64 + @ApiModelProperty("模型类别(1-属性,2-功能,3-事件)")
  65 + private Integer type;
  66 +
  67 + /** 更新者 */
  68 + @ApiModelProperty("更新者")
  69 + private String update_by;
  70 +
  71 + /** 更新时间 */
  72 + @ApiModelProperty("更新时间")
  73 + private java.util.Date update_time;
  74 +
  75 + /** 用户id */
  76 + @ApiModelProperty("用户id")
  77 + private Integer user_id;
  78 +
  79 + public void setCreate_by(String create_by)
  80 + {
  81 + this.create_by = create_by;
  82 + }
  83 +
  84 + public String getCreate_by()
  85 + {
  86 + return create_by;
  87 + }
  88 + public void setCreate_time(java.util.Date create_time)
  89 + {
  90 + this.create_time = create_time;
  91 + }
  92 +
  93 + public java.util.Date getCreate_time()
  94 + {
  95 + return create_time;
  96 + }
  97 + public void setData_type(String data_type)
  98 + {
  99 + this.data_type = data_type;
  100 + }
  101 +
  102 + public String getData_type()
  103 + {
  104 + return data_type;
  105 + }
  106 + public void setDel_flag(String del_flag)
  107 + {
  108 + this.del_flag = del_flag;
  109 + }
  110 +
  111 + public String getDel_flag()
  112 + {
  113 + return del_flag;
  114 + }
  115 + public void setIdentifier(String identifier)
  116 + {
  117 + this.identifier = identifier;
  118 + }
  119 +
  120 + public String getIdentifier()
  121 + {
  122 + return identifier;
  123 + }
  124 + public void setIs_monitor(Integer is_monitor)
  125 + {
  126 + this.is_monitor = is_monitor;
  127 + }
  128 +
  129 + public Integer getIs_monitor()
  130 + {
  131 + return is_monitor;
  132 + }
  133 + public void setIs_save_log(Integer is_save_log)
  134 + {
  135 + this.is_save_log = is_save_log;
  136 + }
  137 +
  138 + public Integer getIs_save_log()
  139 + {
  140 + return is_save_log;
  141 + }
  142 + public void setIs_top(Integer is_top)
  143 + {
  144 + this.is_top = is_top;
  145 + }
  146 +
  147 + public Integer getIs_top()
  148 + {
  149 + return is_top;
  150 + }
  151 + public void setModel_id(Integer model_id)
  152 + {
  153 + this.model_id = model_id;
  154 + }
  155 +
  156 + public Integer getModel_id()
  157 + {
  158 + return model_id;
  159 + }
  160 + public void setModel_name(String model_name)
  161 + {
  162 + this.model_name = model_name;
  163 + }
  164 +
  165 + public String getModel_name()
  166 + {
  167 + return model_name;
  168 + }
  169 + public void setSpecs(String specs)
  170 + {
  171 + this.specs = specs;
  172 + }
  173 +
  174 + public String getSpecs()
  175 + {
  176 + return specs;
  177 + }
  178 + public void setType(Integer type)
  179 + {
  180 + this.type = type;
  181 + }
  182 +
  183 + public Integer getType()
  184 + {
  185 + return type;
  186 + }
  187 + public void setUpdate_by(String update_by)
  188 + {
  189 + this.update_by = update_by;
  190 + }
  191 +
  192 + public String getUpdate_by()
  193 + {
  194 + return update_by;
  195 + }
  196 + public void setUpdate_time(java.util.Date update_time)
  197 + {
  198 + this.update_time = update_time;
  199 + }
  200 +
  201 + public java.util.Date getUpdate_time()
  202 + {
  203 + return update_time;
  204 + }
  205 + public void setUser_id(Integer user_id)
  206 + {
  207 + this.user_id = user_id;
  208 + }
  209 +
  210 + public Integer getUser_id()
  211 + {
  212 + return user_id;
  213 + }
  214 +
  215 + public String toString() {
  216 + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
  217 + .append("create_by", getCreate_by())
  218 + .append("create_time", getCreate_time())
  219 + .append("data_type", getData_type())
  220 + .append("del_flag", getDel_flag())
  221 + .append("identifier", getIdentifier())
  222 + .append("is_monitor", getIs_monitor())
  223 + .append("is_save_log", getIs_save_log())
  224 + .append("is_top", getIs_top())
  225 + .append("model_id", getModel_id())
  226 + .append("model_name", getModel_name())
  227 + .append("specs", getSpecs())
  228 + .append("type", getType())
  229 + .append("update_by", getUpdate_by())
  230 + .append("update_time", getUpdate_time())
  231 + .append("user_id", getUser_id())
  232 + .toString();
  233 + }
  234 +}
  1 +package com.zhonglai.luhui.mqtt.comm.dto.iot;
  2 +
  3 +import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import org.apache.commons.lang3.builder.ToStringBuilder;
  6 +import org.apache.commons.lang3.builder.ToStringStyle;
  7 +
  8 +/**
  9 + * 产品对象 iot_user
  10 + *
  11 + * @author 钟来
  12 + * @date 2022-08-26
  13 + */
  14 +@ApiModel("产品")
  15 +public class IotUser
  16 +{
  17 + private static final long serialVersionUID = 1L;
  18 +
  19 + /** 创建时间 */
  20 + @ApiModelProperty("创建时间")
  21 + private Integer create_time;
  22 +
  23 + /** 加密类型 */
  24 + @ApiModelProperty("加密类型")
  25 + private String encryption_type;
  26 +
  27 + /** 主键id */
  28 + @ApiModelProperty("主键id")
  29 + private Integer id;
  30 +
  31 + /** 开启加密(0不开启,1开启) */
  32 + @ApiModelProperty("开启加密(0不开启,1开启)")
  33 + private Integer open_encryption;
  34 +
  35 + /** 密码 */
  36 + @ApiModelProperty("密码")
  37 + private String password;
  38 +
  39 + /** 角色id */
  40 + @ApiModelProperty("角色id")
  41 + private Integer role_id;
  42 +
  43 + /** 盐 */
  44 + @ApiModelProperty("盐")
  45 + private String salt;
  46 +
  47 + /** 是否使用(0否,1是) */
  48 + @ApiModelProperty("是否使用(0否,1是)")
  49 + private Integer used;
  50 +
  51 + /** 用户名 */
  52 + @ApiModelProperty("用户名")
  53 + private String username;
  54 +
  55 + public void setCreate_time(Integer create_time)
  56 + {
  57 + this.create_time = create_time;
  58 + }
  59 +
  60 + public Integer getCreate_time()
  61 + {
  62 + return create_time;
  63 + }
  64 + public void setEncryption_type(String encryption_type)
  65 + {
  66 + this.encryption_type = encryption_type;
  67 + }
  68 +
  69 + public String getEncryption_type()
  70 + {
  71 + return encryption_type;
  72 + }
  73 + public void setId(Integer id)
  74 + {
  75 + this.id = id;
  76 + }
  77 +
  78 + public Integer getId()
  79 + {
  80 + return id;
  81 + }
  82 + public void setOpen_encryption(Integer open_encryption)
  83 + {
  84 + this.open_encryption = open_encryption;
  85 + }
  86 +
  87 + public Integer getOpen_encryption()
  88 + {
  89 + return open_encryption;
  90 + }
  91 + public void setPassword(String password)
  92 + {
  93 + this.password = password;
  94 + }
  95 +
  96 + public String getPassword()
  97 + {
  98 + return password;
  99 + }
  100 + public void setRole_id(Integer role_id)
  101 + {
  102 + this.role_id = role_id;
  103 + }
  104 +
  105 + public Integer getRole_id()
  106 + {
  107 + return role_id;
  108 + }
  109 + public void setSalt(String salt)
  110 + {
  111 + this.salt = salt;
  112 + }
  113 +
  114 + public String getSalt()
  115 + {
  116 + return salt;
  117 + }
  118 + public void setUsed(Integer used)
  119 + {
  120 + this.used = used;
  121 + }
  122 +
  123 + public Integer getUsed()
  124 + {
  125 + return used;
  126 + }
  127 + public void setUsername(String username)
  128 + {
  129 + this.username = username;
  130 + }
  131 +
  132 + public String getUsername()
  133 + {
  134 + return username;
  135 + }
  136 +
  137 + public String toString() {
  138 + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
  139 + .append("create_time", getCreate_time())
  140 + .append("encryption_type", getEncryption_type())
  141 + .append("id", getId())
  142 + .append("open_encryption", getOpen_encryption())
  143 + .append("password", getPassword())
  144 + .append("role_id", getRole_id())
  145 + .append("salt", getSalt())
  146 + .append("used", getUsed())
  147 + .append("username", getUsername())
  148 + .toString();
  149 + }
  150 +}
@@ -3,18 +3,25 @@ package com.zhonglai.luhui.mqtt.comm.factory; @@ -3,18 +3,25 @@ package com.zhonglai.luhui.mqtt.comm.factory;
3 import com.zhonglai.luhui.mqtt.comm.config.RedisConfig; 3 import com.zhonglai.luhui.mqtt.comm.config.RedisConfig;
4 import com.zhonglai.luhui.mqtt.comm.config.SysParameter; 4 import com.zhonglai.luhui.mqtt.comm.config.SysParameter;
5 import com.zhonglai.luhui.mqtt.comm.dto.MyException; 5 import com.zhonglai.luhui.mqtt.comm.dto.MyException;
  6 +import com.zhonglai.luhui.mqtt.comm.service.MqttCallback;
6 import lombok.Data; 7 import lombok.Data;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
7 10
  11 +import java.lang.reflect.Field;
8 import java.util.Optional; 12 import java.util.Optional;
9 13
10 @Data 14 @Data
11 public class Topic { 15 public class Topic {
  16 + private static final Logger log = LoggerFactory.getLogger(Topic.class);
  17 +
12 private String roleid; 18 private String roleid;
13 private String username; 19 private String username;
14 private String clientid; 20 private String clientid;
15 private String topicType; 21 private String topicType;
16 private String redicKey; 22 private String redicKey;
17 private String messageid; 23 private String messageid;
  24 + private String payloadtype;
18 public Topic(String topic) 25 public Topic(String topic)
19 { 26 {
20 topic = Optional.ofNullable(topic).orElseThrow(()->new MyException("topic为空")); 27 topic = Optional.ofNullable(topic).orElseThrow(()->new MyException("topic为空"));
@@ -23,23 +30,13 @@ public class Topic { @@ -23,23 +30,13 @@ public class Topic {
23 for(int i=0;i<config.length;i++) 30 for(int i=0;i<config.length;i++)
24 { 31 {
25 String cf = config[i].replace("{{","").replace("}}",""); 32 String cf = config[i].replace("{{","").replace("}}","");
26 - switch (cf)  
27 - {  
28 - case "roleid":  
29 - roleid = sts[i];  
30 - break;  
31 - case "username":  
32 - username = sts[i];  
33 - break;  
34 - case "clientid":  
35 - clientid = sts[i];  
36 - break;  
37 - case "topicType":  
38 - topicType = sts[i];  
39 - break;  
40 - case "messageid":  
41 - messageid = sts[i];  
42 - break; 33 + try {
  34 + Field field = this.getClass().getField(cf);
  35 + field.set(this,sts[i]);
  36 + } catch (NoSuchFieldException e) {
  37 + log.info("{}生成topic时没有属性",topic,cf);
  38 + } catch (IllegalAccessException e) {
  39 + log.info("{}生成topic时无法给{}赋值{}",topic,cf,sts[i]);
43 } 40 }
44 } 41 }
45 } 42 }
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
3 -import com.ruoyi.common.core.domain.Message;  
4 -import com.ruoyi.common.utils.ByteUtil;  
5 import com.zhonglai.luhui.mqtt.comm.clien.ClienConnection; 3 import com.zhonglai.luhui.mqtt.comm.clien.ClienConnection;
6 import com.zhonglai.luhui.mqtt.comm.clien.impl.ClienConnectionImpl; 4 import com.zhonglai.luhui.mqtt.comm.clien.impl.ClienConnectionImpl;
7 import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; 5 import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
8 import com.zhonglai.luhui.mqtt.comm.factory.Topic; 6 import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  7 +import com.zhonglai.luhui.mqtt.comm.util.ByteUtil;
  8 +import com.zhonglai.luhui.mqtt.dto.Message;
9 import net.jodah.expiringmap.ExpirationListener; 9 import net.jodah.expiringmap.ExpirationListener;
10 import net.jodah.expiringmap.ExpirationPolicy; 10 import net.jodah.expiringmap.ExpirationPolicy;
11 import net.jodah.expiringmap.ExpiringMap; 11 import net.jodah.expiringmap.ExpiringMap;
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
3 -import com.ruoyi.common.utils.DateUtils;  
4 import com.zhonglai.luhui.mqtt.comm.dao.BaseDao; 3 import com.zhonglai.luhui.mqtt.comm.dao.BaseDao;
5 import com.zhonglai.luhui.mqtt.comm.dto.*; 4 import com.zhonglai.luhui.mqtt.comm.dto.*;
6 import com.zhonglai.luhui.mqtt.comm.factory.Topic; 5 import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  6 +import com.zhonglai.luhui.mqtt.comm.util.DateUtils;
7 import com.zhonglai.luhui.mqtt.comm.util.TableUtil; 7 import com.zhonglai.luhui.mqtt.comm.util.TableUtil;
8 import org.apache.commons.lang3.StringUtils; 8 import org.apache.commons.lang3.StringUtils;
9 9
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
3 -import com.luhui.ly.device.mqtt.comm.dto.ServerDto;  
4 -import com.luhui.ly.device.mqtt.comm.factory.BusinessAgreement;  
5 -import com.luhui.ly.device.mqtt.comm.factory.BusinessAgreementFactory;  
6 -import com.luhui.ly.device.mqtt.comm.factory.Topic;  
7 -import com.luhui.ly.device.mqtt.comm.service.CacheService;  
8 -import com.luhui.ly.device.mqtt.comm.service.ClienNoticeService;  
9 -import com.luhui.ly.device.mqtt.comm.service.DataPersistenceService;  
10 -import com.luhui.ly.device.mqtt.comm.service.TerminalService; 3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
  5 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreementFactory;
  6 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  7 +import com.zhonglai.luhui.mqtt.comm.util.ByteUtil;
11 import lombok.SneakyThrows; 8 import lombok.SneakyThrows;
12 import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; 9 import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
13 import org.eclipse.paho.client.mqttv3.MqttCallbackExtended; 10 import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
@@ -20,7 +17,7 @@ import org.springframework.stereotype.Component; @@ -20,7 +17,7 @@ import org.springframework.stereotype.Component;
20 17
21 @Component 18 @Component
22 public class MqttCallback implements MqttCallbackExtended { 19 public class MqttCallback implements MqttCallbackExtended {
23 - private static final Logger log = LoggerFactory.getLogger(com.luhui.ly.device.mqtt.comm.service.MqttCallback.class); 20 + private static final Logger log = LoggerFactory.getLogger(MqttCallback.class);
24 @Autowired 21 @Autowired
25 private BusinessAgreementFactory businessAgreementFactory; 22 private BusinessAgreementFactory businessAgreementFactory;
26 @Autowired 23 @Autowired
@@ -51,7 +48,7 @@ public class MqttCallback implements MqttCallbackExtended { @@ -51,7 +48,7 @@ public class MqttCallback implements MqttCallbackExtended {
51 @Override 48 @Override
52 public void messageArrived(String s, MqttMessage mqttMessage) { 49 public void messageArrived(String s, MqttMessage mqttMessage) {
53 //接收到消息 50 //接收到消息
54 -// log.info("接收到消息topc:{}, mqttMessage {},payload 十六进制 {}",s,mqttMessage,ByteUtil.hexStringToSpace(ByteUtil.toHexString(mqttMessage.getPayload()))); 51 + log.info("接收到消息topc:{}, mqttMessage {},payload 十六进制 {}",s,mqttMessage, ByteUtil.hexStringToSpace(ByteUtil.toHexString(mqttMessage.getPayload())));
55 Topic topic = new Topic(s); 52 Topic topic = new Topic(s);
56 53
57 BusinessAgreement businessAgreement = businessAgreementFactory.createBusinessAgreement(topic.getTopicType()); 54 BusinessAgreement businessAgreement = businessAgreementFactory.createBusinessAgreement(topic.getTopicType());
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
3 -import com.luhui.ly.device.mqtt.comm.config.RedisConfig;  
4 -import com.luhui.ly.device.mqtt.comm.service.DataPersistenceService; 3 +import com.zhonglai.luhui.mqtt.comm.config.RedisConfig;
5 import org.springframework.beans.factory.annotation.Autowired; 4 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.data.redis.connection.Message; 5 import org.springframework.data.redis.connection.Message;
7 import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; 6 import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
3 -import com.luhui.ly.comm.util.GsonConstructor; 3 +import com.alibaba.fastjson.JSONObject;
4 import org.slf4j.Logger; 4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
6 import org.springframework.beans.factory.annotation.Value; 6 import org.springframework.beans.factory.annotation.Value;
@@ -18,7 +18,7 @@ import java.util.stream.Collectors; @@ -18,7 +18,7 @@ import java.util.stream.Collectors;
18 */ 18 */
19 @Service 19 @Service
20 public class RedisService { 20 public class RedisService {
21 - private static final Logger log = LoggerFactory.getLogger(com.luhui.ly.device.mqtt.comm.service.RedisService.class); 21 + private static final Logger log = LoggerFactory.getLogger(RedisService.class);
22 22
23 @Resource 23 @Resource
24 private RedisTemplate<String,Object> redisTemplate; 24 private RedisTemplate<String,Object> redisTemplate;
@@ -359,9 +359,9 @@ public class RedisService { @@ -359,9 +359,9 @@ public class RedisService {
359 Map<Object, Object> hmget = hmget(key); 359 Map<Object, Object> hmget = hmget(key);
360 if(CollectionUtils.isEmpty(hmget)) return null; 360 if(CollectionUtils.isEmpty(hmget)) return null;
361 //查询到了 先把数据转成json字符串 361 //查询到了 先把数据转成json字符串
362 - String s = GsonConstructor.get().toJson(hmget); 362 + String s = JSONObject.toJSONString(hmget);
363 //再把json字符串转回对象 363 //再把json字符串转回对象
364 - return GsonConstructor.get().fromJson(s,tClass); 364 + return JSONObject.parseObject(s,tClass);
365 } 365 }
366 366
367 /** 367 /**
@@ -380,8 +380,8 @@ public class RedisService { @@ -380,8 +380,8 @@ public class RedisService {
380 } 380 }
381 public boolean hmset(String key,Object object){ 381 public boolean hmset(String key,Object object){
382 try { 382 try {
383 - String s = GsonConstructor.get().toJson(object);  
384 - Map<String, String> map = GsonConstructor.get().fromJson(s,HashMap.class); 383 + String s = JSONObject.toJSONString(object);
  384 + Map<String, String> map = JSONObject.parseObject(s,HashMap.class);
385 redisTemplate.opsForHash().putAll(key, map); 385 redisTemplate.opsForHash().putAll(key, map);
386 return true; 386 return true;
387 }catch (Exception e){ 387 }catch (Exception e){
1 package com.zhonglai.luhui.mqtt.comm.service; 1 package com.zhonglai.luhui.mqtt.comm.service;
2 2
3 -import com.luhui.ly.device.mqtt.comm.config.SysParameter;  
4 -import com.luhui.ly.device.mqtt.comm.service.MqttCallback; 3 +import com.zhonglai.luhui.mqtt.comm.config.SysParameter;
5 import org.eclipse.paho.client.mqttv3.MqttClient; 4 import org.eclipse.paho.client.mqttv3.MqttClient;
6 import org.eclipse.paho.client.mqttv3.MqttConnectOptions; 5 import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
7 import org.eclipse.paho.client.mqttv3.MqttException; 6 import org.eclipse.paho.client.mqttv3.MqttException;
@@ -26,7 +25,7 @@ import java.util.concurrent.TimeUnit; @@ -26,7 +25,7 @@ import java.util.concurrent.TimeUnit;
26 */ 25 */
27 @Service 26 @Service
28 public class TerminalService { 27 public class TerminalService {
29 - private static final Logger log = LoggerFactory.getLogger(com.luhui.ly.device.mqtt.comm.service.TerminalService.class); 28 + private static final Logger log = LoggerFactory.getLogger(TerminalService.class);
30 @Autowired 29 @Autowired
31 private MqttCallback mqttCallback; 30 private MqttCallback mqttCallback;
32 31
  1 +package com.zhonglai.luhui.mqtt.comm.util;
  2 +
  3 +import java.util.Arrays;
  4 +
  5 +public class ByteUtil {
  6 + /**
  7 + * byte数组中取int数值,本方法适用于(低位在前,高位在后)的顺序,和和intToBytes()配套使用
  8 + *
  9 + * @param src
  10 + * byte数组
  11 + * @param offset
  12 + * 从数组的第offset位开始
  13 + * @return int数值
  14 + */
  15 + public static long bytesToLongASC(byte[] src, int offset,int lenth) {
  16 + int value = 0;
  17 + for(int i=0;i<lenth;i++)
  18 + {
  19 + value = value | ((src[offset+i] & 0xFF)<<(8*i));
  20 + }
  21 + return value;
  22 + }
  23 +
  24 + /**
  25 + * 把16进制字符串转换成字节数组
  26 + *
  27 + * @param hex
  28 + * @return
  29 + */
  30 + public static byte[] hexStringToByte(String hex) {
  31 + int len = (hex.length() / 2);
  32 + byte[] result = new byte[len];
  33 + char[] achar = hex.toCharArray();
  34 + for (int i = 0; i < len; i++) {
  35 + int pos = i * 2;
  36 + result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1]));
  37 + }
  38 + return result;
  39 + }
  40 + private static byte toByte(char c) {
  41 + byte b = (byte) "0123456789ABCDEF".indexOf(c);
  42 + return b;
  43 + }
  44 +
  45 + /**
  46 + * 把16进制字符串转换成字节数组
  47 + *
  48 + * @param hex
  49 + * @return
  50 + */
  51 + public static String hexStringToSpace(String hex) {
  52 + if (null == hex) {
  53 + return null;
  54 + } else {
  55 + StringBuilder sb = new StringBuilder(hex.length() << 1);
  56 +
  57 + for(int i = 0; i < hex.length(); i+=2) {
  58 + sb.append(hex.substring(i,i+2)).append(" ");
  59 + }
  60 + return sb.toString();
  61 + }
  62 + }
  63 +
  64 + /**
  65 + * 把原数组加点目标数组后面
  66 + * @param dest 目标数组
  67 + * @param src 原数组
  68 + * @return
  69 + */
  70 + public static byte[] addBytes(byte[] dest,byte[] src )
  71 + {
  72 + int dl = dest.length;
  73 + int sl = src.length;
  74 + dest = Arrays.copyOf(dest, dl+sl);//数组扩容
  75 + System.arraycopy(src,0,dest,dl,src.length);
  76 + return dest;
  77 + }
  78 +
  79 + /**
  80 + * 将int数值转换为占四个字节的byte数组,本方法适用于(高位在前,低位在后)的顺序。 和bytesToInt2()配套使用
  81 + */
  82 + public static byte[] intToBytesDESC(long value,int lenth)
  83 + {
  84 + byte[] src = new byte[lenth];
  85 + for(int i=0;i<lenth;i++)
  86 + {
  87 + src[i] = (byte) ((value>>(8*(lenth-i-1))) & 0xFF);
  88 + }
  89 + return src;
  90 + }
  91 +
  92 + /**
  93 + * 将int数值转换为占四个字节的byte数组,本方法适用于(低位在前,高位在后)的顺序。 和bytesToInt()配套使用
  94 + * @param value
  95 + * 要转换的int值
  96 + * @return byte数组
  97 + */
  98 + public static byte[] intToBytesASC( long value,int lenth)
  99 + {
  100 + byte[] src = new byte[lenth];
  101 + for(int i=lenth;i>0;i--)
  102 + {
  103 + src[i-1] = (byte) ((value>>(8*(i-1))) & 0xFF);
  104 + }
  105 + return src;
  106 + }
  107 +
  108 + public static void main(String[] args) {
  109 + System.out.println(ByteUtil.toHexString( ByteUtil.intToBytesASC(2011239256,4)));
  110 + }
  111 +
  112 + /**
  113 + * ip转化位4byte
  114 + * @param ip
  115 + * @return
  116 + */
  117 + public static byte[] ipTo4Byte(String ip)
  118 + {
  119 + String[] ips = ip.split(".");
  120 + return new byte[]{(byte) Integer.parseInt(ips[0]),(byte) Integer.parseInt(ips[1]),(byte) Integer.parseInt(ips[2]),(byte) Integer.parseInt(ips[3])};
  121 + }
  122 +
  123 + /**
  124 + * byte数组中取int数值,本方法适用于(低位在后,高位在前)的顺序。和intToBytes2()配套使用
  125 + */
  126 + public static long bytesToLongDESC(byte[] src, int offset,int lenth) {
  127 + long value = 0;
  128 + for(int i=lenth;i>0;i--)
  129 + {
  130 + value = value | ((src[offset+(lenth-i)] & 0xFF)<<(8*(i-1)));
  131 + }
  132 + return value;
  133 + }
  134 +
  135 + private static final char[] hex = "0123456789abcdef".toCharArray();
  136 + public static String toHexString(byte[] bytes) {
  137 + if (null == bytes) {
  138 + return null;
  139 + } else {
  140 + StringBuilder sb = new StringBuilder(bytes.length << 1);
  141 +
  142 + for(int i = 0; i < bytes.length; ++i) {
  143 + sb.append(hex[(bytes[i] & 240) >> 4]).append(hex[bytes[i] & 15]);
  144 + }
  145 +
  146 + return sb.toString();
  147 + }
  148 + }
  149 +
  150 + /**
  151 + * 计算CRC16/Modbus校验码 低位在前,高位在后
  152 + *
  153 + * @param str 十六进制字符串
  154 + * @return
  155 + */
  156 + public static String getCRC16(String str) {
  157 + byte[] bytes = hexStringToByte(str);
  158 + return getCRC16(bytes);
  159 + }
  160 +
  161 + /**
  162 + * 计算CRC16/Modbus校验码 低位在前,高位在后
  163 + *
  164 + * @return
  165 + */
  166 + public static String getCRC16( byte[] bytes) {
  167 + int CRC = 0x0000ffff;
  168 + int POLYNOMIAL = 0x0000a001;
  169 +
  170 + int i, j;
  171 + for (i = 0; i < bytes.length; i++) {
  172 + CRC ^= ((int) bytes[i] & 0x000000ff);
  173 + for (j = 0; j < 8; j++) {
  174 + if ((CRC & 0x00000001) != 0) {
  175 + CRC >>= 1;
  176 + CRC ^= POLYNOMIAL;
  177 + } else {
  178 + CRC >>= 1;
  179 + }
  180 + }
  181 + }
  182 + String crc = Integer.toHexString(CRC);
  183 + if (crc.length() == 2) {
  184 + crc = "00" + crc;
  185 + } else if (crc.length() == 3) {
  186 + crc = "0" + crc;
  187 + }
  188 + crc = crc.substring(2, 4) + crc.substring(0, 2);
  189 + return crc.toUpperCase();
  190 + }
  191 +}
  1 +package com.zhonglai.luhui.mqtt.comm.util;
  2 +
  3 +import java.nio.charset.Charset;
  4 +import java.nio.charset.StandardCharsets;
  5 +
  6 +/**
  7 + * 字符集工具类
  8 + *
  9 + * @author ruoyi
  10 + */
  11 +public class CharsetKit
  12 +{
  13 + /** ISO-8859-1 */
  14 + public static final String ISO_8859_1 = "ISO-8859-1";
  15 + /** UTF-8 */
  16 + public static final String UTF_8 = "UTF-8";
  17 + /** GBK */
  18 + public static final String GBK = "GBK";
  19 +
  20 + /** ISO-8859-1 */
  21 + public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1);
  22 + /** UTF-8 */
  23 + public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8);
  24 + /** GBK */
  25 + public static final Charset CHARSET_GBK = Charset.forName(GBK);
  26 +
  27 + /**
  28 + * 转换为Charset对象
  29 + *
  30 + * @param charset 字符集,为空则返回默认字符集
  31 + * @return Charset
  32 + */
  33 + public static Charset charset(String charset)
  34 + {
  35 + return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset);
  36 + }
  37 +
  38 + /**
  39 + * 转换字符串的字符集编码
  40 + *
  41 + * @param source 字符串
  42 + * @param srcCharset 源字符集,默认ISO-8859-1
  43 + * @param destCharset 目标字符集,默认UTF-8
  44 + * @return 转换后的字符集
  45 + */
  46 + public static String convert(String source, String srcCharset, String destCharset)
  47 + {
  48 + return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset));
  49 + }
  50 +
  51 + /**
  52 + * 转换字符串的字符集编码
  53 + *
  54 + * @param source 字符串
  55 + * @param srcCharset 源字符集,默认ISO-8859-1
  56 + * @param destCharset 目标字符集,默认UTF-8
  57 + * @return 转换后的字符集
  58 + */
  59 + public static String convert(String source, Charset srcCharset, Charset destCharset)
  60 + {
  61 + if (null == srcCharset)
  62 + {
  63 + srcCharset = StandardCharsets.ISO_8859_1;
  64 + }
  65 +
  66 + if (null == destCharset)
  67 + {
  68 + destCharset = StandardCharsets.UTF_8;
  69 + }
  70 +
  71 + if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset))
  72 + {
  73 + return source;
  74 + }
  75 + return new String(source.getBytes(srcCharset), destCharset);
  76 + }
  77 +
  78 + /**
  79 + * @return 系统字符集编码
  80 + */
  81 + public static String systemCharset()
  82 + {
  83 + return Charset.defaultCharset().name();
  84 + }
  85 +}
  1 +package com.zhonglai.luhui.mqtt.comm.util;
  2 +
  3 +import io.jsonwebtoken.Claims;
  4 +
  5 +/**
  6 + * 通用常量信息
  7 + *
  8 + * @author ruoyi
  9 + */
  10 +public class Constants
  11 +{
  12 + /**
  13 + * UTF-8 字符集
  14 + */
  15 + public static final String UTF8 = "UTF-8";
  16 +
  17 + /**
  18 + * GBK 字符集
  19 + */
  20 + public static final String GBK = "GBK";
  21 +
  22 + /**
  23 + * http请求
  24 + */
  25 + public static final String HTTP = "http://";
  26 +
  27 + /**
  28 + * https请求
  29 + */
  30 + public static final String HTTPS = "https://";
  31 +
  32 + /**
  33 + * 通用成功标识
  34 + */
  35 + public static final String SUCCESS = "0";
  36 +
  37 + /**
  38 + * 通用失败标识
  39 + */
  40 + public static final String FAIL = "1";
  41 +
  42 + /**
  43 + * 登录成功
  44 + */
  45 + public static final String LOGIN_SUCCESS = "Success";
  46 +
  47 + /**
  48 + * 注销
  49 + */
  50 + public static final String LOGOUT = "Logout";
  51 +
  52 + /**
  53 + * 注册
  54 + */
  55 + public static final String REGISTER = "Register";
  56 +
  57 + /**
  58 + * 登录失败
  59 + */
  60 + public static final String LOGIN_FAIL = "Error";
  61 +
  62 + /**
  63 + * 验证码 redis key
  64 + */
  65 + public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
  66 +
  67 + /**
  68 + * 登录用户 redis key
  69 + */
  70 + public static final String LOGIN_TOKEN_KEY = "login_tokens:";
  71 +
  72 + /**
  73 + * 防重提交 redis key
  74 + */
  75 + public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";
  76 +
  77 + /**
  78 + * 限流 redis key
  79 + */
  80 + public static final String RATE_LIMIT_KEY = "rate_limit:";
  81 +
  82 + /**
  83 + * 验证码有效期(分钟)
  84 + */
  85 + public static final Integer CAPTCHA_EXPIRATION = 2;
  86 +
  87 + /**
  88 + * 令牌
  89 + */
  90 + public static final String TOKEN = "token";
  91 +
  92 + /**
  93 + * 令牌前缀
  94 + */
  95 + public static final String TOKEN_PREFIX = "Bearer ";
  96 +
  97 + /**
  98 + * 令牌前缀
  99 + */
  100 + public static final String LOGIN_USER_KEY = "login_user_key";
  101 +
  102 + /**
  103 + * 用户ID
  104 + */
  105 + public static final String JWT_USERID = "userid";
  106 +
  107 + /**
  108 + * 用户名称
  109 + */
  110 + public static final String JWT_USERNAME = Claims.SUBJECT;
  111 +
  112 + /**
  113 + * 用户头像
  114 + */
  115 + public static final String JWT_AVATAR = "avatar";
  116 +
  117 + /**
  118 + * 创建时间
  119 + */
  120 + public static final String JWT_CREATED = "created";
  121 +
  122 + /**
  123 + * 用户权限
  124 + */
  125 + public static final String JWT_AUTHORITIES = "authorities";
  126 +
  127 + /**
  128 + * 参数管理 cache key
  129 + */
  130 + public static final String SYS_CONFIG_KEY = "sys_config:";
  131 +
  132 + /**
  133 + * 字典管理 cache key
  134 + */
  135 + public static final String SYS_DICT_KEY = "sys_dict:";
  136 +
  137 + /**
  138 + * 资源映射路径 前缀
  139 + */
  140 + public static final String RESOURCE_PREFIX = "/profile";
  141 +
  142 + /**
  143 + * RMI 远程方法调用
  144 + */
  145 + public static final String LOOKUP_RMI = "rmi:";
  146 +
  147 + /**
  148 + * LDAP 远程方法调用
  149 + */
  150 + public static final String LOOKUP_LDAP = "ldap:";
  151 +
  152 + /**
  153 + * LDAPS 远程方法调用
  154 + */
  155 + public static final String LOOKUP_LDAPS = "ldaps:";
  156 +
  157 + /**
  158 + * 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
  159 + */
  160 + public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" };
  161 +
  162 + /**
  163 + * 定时任务违规的字符
  164 + */
  165 + public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
  166 + "org.springframework", "org.apache", "com.ruoyi.common.utils.file" };
  167 +}
  1 +package com.zhonglai.luhui.mqtt.comm.util;
  2 +
  3 +import org.apache.commons.lang3.ArrayUtils;
  4 +
  5 +import java.math.BigDecimal;
  6 +import java.math.BigInteger;
  7 +import java.nio.ByteBuffer;
  8 +import java.nio.charset.Charset;
  9 +import java.text.NumberFormat;
  10 +import java.util.Set;
  11 +
  12 +/**
  13 + * 类型转换器
  14 + *
  15 + * @author ruoyi
  16 + */
  17 +public class Convert
  18 +{
  19 + /**
  20 + * 转换为字符串<br>
  21 + * 如果给定的值为null,或者转换失败,返回默认值<br>
  22 + * 转换失败不会报错
  23 + *
  24 + * @param value 被转换的值
  25 + * @param defaultValue 转换错误时的默认值
  26 + * @return 结果
  27 + */
  28 + public static String toStr(Object value, String defaultValue)
  29 + {
  30 + if (null == value)
  31 + {
  32 + return defaultValue;
  33 + }
  34 + if (value instanceof String)
  35 + {
  36 + return (String) value;
  37 + }
  38 + return value.toString();
  39 + }
  40 +
  41 + /**
  42 + * 转换为字符串<br>
  43 + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
  44 + * 转换失败不会报错
  45 + *
  46 + * @param value 被转换的值
  47 + * @return 结果
  48 + */
  49 + public static String toStr(Object value)
  50 + {
  51 + return toStr(value, null);
  52 + }
  53 +
  54 + /**
  55 + * 转换为字符<br>
  56 + * 如果给定的值为null,或者转换失败,返回默认值<br>
  57 + * 转换失败不会报错
  58 + *
  59 + * @param value 被转换的值
  60 + * @param defaultValue 转换错误时的默认值
  61 + * @return 结果
  62 + */
  63 + public static Character toChar(Object value, Character defaultValue)
  64 + {
  65 + if (null == value)
  66 + {
  67 + return defaultValue;
  68 + }
  69 + if (value instanceof Character)
  70 + {
  71 + return (Character) value;
  72 + }
  73 +
  74 + final String valueStr = toStr(value, null);
  75 + return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0);
  76 + }
  77 +
  78 + /**
  79 + * 转换为字符<br>
  80 + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
  81 + * 转换失败不会报错
  82 + *
  83 + * @param value 被转换的值
  84 + * @return 结果
  85 + */
  86 + public static Character toChar(Object value)
  87 + {
  88 + return toChar(value, null);
  89 + }
  90 +
  91 + /**
  92 + * 转换为byte<br>
  93 + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br>
  94 + * 转换失败不会报错
  95 + *
  96 + * @param value 被转换的值
  97 + * @param defaultValue 转换错误时的默认值
  98 + * @return 结果
  99 + */
  100 + public static Byte toByte(Object value, Byte defaultValue)
  101 + {
  102 + if (value == null)
  103 + {
  104 + return defaultValue;
  105 + }
  106 + if (value instanceof Byte)
  107 + {
  108 + return (Byte) value;
  109 + }
  110 + if (value instanceof Number)
  111 + {
  112 + return ((Number) value).byteValue();
  113 + }
  114 + final String valueStr = toStr(value, null);
  115 + if (StringUtils.isEmpty(valueStr))
  116 + {
  117 + return defaultValue;
  118 + }
  119 + try
  120 + {
  121 + return Byte.parseByte(valueStr);
  122 + }
  123 + catch (Exception e)
  124 + {
  125 + return defaultValue;
  126 + }
  127 + }
  128 +
  129 + /**
  130 + * 转换为byte<br>
  131 + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
  132 + * 转换失败不会报错
  133 + *
  134 + * @param value 被转换的值
  135 + * @return 结果
  136 + */
  137 + public static Byte toByte(Object value)
  138 + {
  139 + return toByte(value, null);
  140 + }
  141 +
  142 + /**
  143 + * 转换为Short<br>
  144 + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br>
  145 + * 转换失败不会报错
  146 + *
  147 + * @param value 被转换的值
  148 + * @param defaultValue 转换错误时的默认值
  149 + * @return 结果
  150 + */
  151 + public static Short toShort(Object value, Short defaultValue)
  152 + {
  153 + if (value == null)
  154 + {
  155 + return defaultValue;
  156 + }
  157 + if (value instanceof Short)
  158 + {
  159 + return (Short) value;
  160 + }
  161 + if (value instanceof Number)
  162 + {
  163 + return ((Number) value).shortValue();
  164 + }
  165 + final String valueStr = toStr(value, null);
  166 + if (StringUtils.isEmpty(valueStr))
  167 + {
  168 + return defaultValue;
  169 + }
  170 + try
  171 + {
  172 + return Short.parseShort(valueStr.trim());
  173 + }
  174 + catch (Exception e)
  175 + {
  176 + return defaultValue;
  177 + }
  178 + }
  179 +
  180 + /**
  181 + * 转换为Short<br>
  182 + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
  183 + * 转换失败不会报错
  184 + *
  185 + * @param value 被转换的值
  186 + * @return 结果
  187 + */
  188 + public static Short toShort(Object value)
  189 + {
  190 + return toShort(value, null);
  191 + }
  192 +
  193 + /**
  194 + * 转换为Number<br>
  195 + * 如果给定的值为空,或者转换失败,返回默认值<br>
  196 + * 转换失败不会报错
  197 + *
  198 + * @param value 被转换的值
  199 + * @param defaultValue 转换错误时的默认值
  200 + * @return 结果
  201 + */
  202 + public static Number toNumber(Object value, Number defaultValue)
  203 + {
  204 + if (value == null)
  205 + {
  206 + return defaultValue;
  207 + }
  208 + if (value instanceof Number)
  209 + {
  210 + return (Number) value;
  211 + }
  212 + final String valueStr = toStr(value, null);
  213 + if (StringUtils.isEmpty(valueStr))
  214 + {
  215 + return defaultValue;
  216 + }
  217 + try
  218 + {
  219 + return NumberFormat.getInstance().parse(valueStr);
  220 + }
  221 + catch (Exception e)
  222 + {
  223 + return defaultValue;
  224 + }
  225 + }
  226 +
  227 + /**
  228 + * 转换为Number<br>
  229 + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
  230 + * 转换失败不会报错
  231 + *
  232 + * @param value 被转换的值
  233 + * @return 结果
  234 + */
  235 + public static Number toNumber(Object value)
  236 + {
  237 + return toNumber(value, null);
  238 + }
  239 +
  240 + /**
  241 + * 转换为int<br>
  242 + * 如果给定的值为空,或者转换失败,返回默认值<br>
  243 + * 转换失败不会报错
  244 + *
  245 + * @param value 被转换的值
  246 + * @param defaultValue 转换错误时的默认值
  247 + * @return 结果
  248 + */
  249 + public static Integer toInt(Object value, Integer defaultValue)
  250 + {
  251 + if (value == null)
  252 + {
  253 + return defaultValue;
  254 + }
  255 + if (value instanceof Integer)
  256 + {
  257 + return (Integer) value;
  258 + }
  259 + if (value instanceof Number)
  260 + {
  261 + return ((Number) value).intValue();
  262 + }
  263 + final String valueStr = toStr(value, null);
  264 + if (StringUtils.isEmpty(valueStr))
  265 + {
  266 + return defaultValue;
  267 + }
  268 + try
  269 + {
  270 + return Integer.parseInt(valueStr.trim());
  271 + }
  272 + catch (Exception e)
  273 + {
  274 + return defaultValue;
  275 + }
  276 + }
  277 +
  278 + /**
  279 + * 转换为int<br>
  280 + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
  281 + * 转换失败不会报错
  282 + *
  283 + * @param value 被转换的值
  284 + * @return 结果
  285 + */
  286 + public static Integer toInt(Object value)
  287 + {
  288 + return toInt(value, null);
  289 + }
  290 +
  291 + /**
  292 + * 转换为Integer数组<br>
  293 + *
  294 + * @param str 被转换的值
  295 + * @return 结果
  296 + */
  297 + public static Integer[] toIntArray(String str)
  298 + {
  299 + return toIntArray(",", str);
  300 + }
  301 +
  302 + /**
  303 + * 转换为Long数组<br>
  304 + *
  305 + * @param str 被转换的值
  306 + * @return 结果
  307 + */
  308 + public static Long[] toLongArray(String str)
  309 + {
  310 + return toLongArray(",", str);
  311 + }
  312 +
  313 + /**
  314 + * 转换为Integer数组<br>
  315 + *
  316 + * @param split 分隔符
  317 + * @param split 被转换的值
  318 + * @return 结果
  319 + */
  320 + public static Integer[] toIntArray(String split, String str)
  321 + {
  322 + if (StringUtils.isEmpty(str))
  323 + {
  324 + return new Integer[] {};
  325 + }
  326 + String[] arr = str.split(split);
  327 + final Integer[] ints = new Integer[arr.length];
  328 + for (int i = 0; i < arr.length; i++)
  329 + {
  330 + final Integer v = toInt(arr[i], 0);
  331 + ints[i] = v;
  332 + }
  333 + return ints;
  334 + }
  335 +
  336 + /**
  337 + * 转换为Long数组<br>
  338 + *
  339 + * @param split 分隔符
  340 + * @param str 被转换的值
  341 + * @return 结果
  342 + */
  343 + public static Long[] toLongArray(String split, String str)
  344 + {
  345 + if (StringUtils.isEmpty(str))
  346 + {
  347 + return new Long[] {};
  348 + }
  349 + String[] arr = str.split(split);
  350 + final Long[] longs = new Long[arr.length];
  351 + for (int i = 0; i < arr.length; i++)
  352 + {
  353 + final Long v = toLong(arr[i], null);
  354 + longs[i] = v;
  355 + }
  356 + return longs;
  357 + }
  358 +
  359 + /**
  360 + * 转换为String数组<br>
  361 + *
  362 + * @param str 被转换的值
  363 + * @return 结果
  364 + */
  365 + public static String[] toStrArray(String str)
  366 + {
  367 + return toStrArray(",", str);
  368 + }
  369 +
  370 + /**
  371 + * 转换为String数组<br>
  372 + *
  373 + * @param split 分隔符
  374 + * @param split 被转换的值
  375 + * @return 结果
  376 + */
  377 + public static String[] toStrArray(String split, String str)
  378 + {
  379 + return str.split(split);
  380 + }
  381 +
  382 + /**
  383 + * 转换为long<br>
  384 + * 如果给定的值为空,或者转换失败,返回默认值<br>
  385 + * 转换失败不会报错
  386 + *
  387 + * @param value 被转换的值
  388 + * @param defaultValue 转换错误时的默认值
  389 + * @return 结果
  390 + */
  391 + public static Long toLong(Object value, Long defaultValue)
  392 + {
  393 + if (value == null)
  394 + {
  395 + return defaultValue;
  396 + }
  397 + if (value instanceof Long)
  398 + {
  399 + return (Long) value;
  400 + }
  401 + if (value instanceof Number)
  402 + {
  403 + return ((Number) value).longValue();
  404 + }
  405 + final String valueStr = toStr(value, null);
  406 + if (StringUtils.isEmpty(valueStr))
  407 + {
  408 + return defaultValue;
  409 + }
  410 + try
  411 + {
  412 + // 支持科学计数法
  413 + return new BigDecimal(valueStr.trim()).longValue();
  414 + }
  415 + catch (Exception e)
  416 + {
  417 + return defaultValue;
  418 + }
  419 + }
  420 +
  421 + /**
  422 + * 转换为long<br>
  423 + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br>
  424 + * 转换失败不会报错
  425 + *
  426 + * @param value 被转换的值
  427 + * @return 结果
  428 + */
  429 + public static Long toLong(Object value)
  430 + {
  431 + return toLong(value, null);
  432 + }
  433 +
  434 + /**
  435 + * 转换为double<br>
  436 + * 如果给定的值为空,或者转换失败,返回默认值<br>
  437 + * 转换失败不会报错
  438 + *
  439 + * @param value 被转换的值
  440 + * @param defaultValue 转换错误时的默认值
  441 + * @return 结果
  442 + */
  443 + public static Double toDouble(Object value, Double defaultValue)
  444 + {
  445 + if (value == null)
  446 + {
  447 + return defaultValue;
  448 + }
  449 + if (value instanceof Double)
  450 + {
  451 + return (Double) value;
  452 + }
  453 + if (value instanceof Number)
  454 + {
  455 + return ((Number) value).doubleValue();
  456 + }
  457 + final String valueStr = toStr(value, null);
  458 + if (StringUtils.isEmpty(valueStr))
  459 + {
  460 + return defaultValue;
  461 + }
  462 + try
  463 + {
  464 + // 支持科学计数法
  465 + return new BigDecimal(valueStr.trim()).doubleValue();
  466 + }
  467 + catch (Exception e)
  468 + {
  469 + return defaultValue;
  470 + }
  471 + }
  472 +
  473 + /**
  474 + * 转换为double<br>
  475 + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
  476 + * 转换失败不会报错
  477 + *
  478 + * @param value 被转换的值
  479 + * @return 结果
  480 + */
  481 + public static Double toDouble(Object value)
  482 + {
  483 + return toDouble(value, null);
  484 + }
  485 +
  486 + /**
  487 + * 转换为Float<br>
  488 + * 如果给定的值为空,或者转换失败,返回默认值<br>
  489 + * 转换失败不会报错
  490 + *
  491 + * @param value 被转换的值
  492 + * @param defaultValue 转换错误时的默认值
  493 + * @return 结果
  494 + */
  495 + public static Float toFloat(Object value, Float defaultValue)
  496 + {
  497 + if (value == null)
  498 + {
  499 + return defaultValue;
  500 + }
  501 + if (value instanceof Float)
  502 + {
  503 + return (Float) value;
  504 + }
  505 + if (value instanceof Number)
  506 + {
  507 + return ((Number) value).floatValue();
  508 + }
  509 + final String valueStr = toStr(value, null);
  510 + if (StringUtils.isEmpty(valueStr))
  511 + {
  512 + return defaultValue;
  513 + }
  514 + try
  515 + {
  516 + return Float.parseFloat(valueStr.trim());
  517 + }
  518 + catch (Exception e)
  519 + {
  520 + return defaultValue;
  521 + }
  522 + }
  523 +
  524 + /**
  525 + * 转换为Float<br>
  526 + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
  527 + * 转换失败不会报错
  528 + *
  529 + * @param value 被转换的值
  530 + * @return 结果
  531 + */
  532 + public static Float toFloat(Object value)
  533 + {
  534 + return toFloat(value, null);
  535 + }
  536 +
  537 + /**
  538 + * 转换为boolean<br>
  539 + * String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值<br>
  540 + * 转换失败不会报错
  541 + *
  542 + * @param value 被转换的值
  543 + * @param defaultValue 转换错误时的默认值
  544 + * @return 结果
  545 + */
  546 + public static Boolean toBool(Object value, Boolean defaultValue)
  547 + {
  548 + if (value == null)
  549 + {
  550 + return defaultValue;
  551 + }
  552 + if (value instanceof Boolean)
  553 + {
  554 + return (Boolean) value;
  555 + }
  556 + String valueStr = toStr(value, null);
  557 + if (StringUtils.isEmpty(valueStr))
  558 + {
  559 + return defaultValue;
  560 + }
  561 + valueStr = valueStr.trim().toLowerCase();
  562 + switch (valueStr)
  563 + {
  564 + case "true":
  565 + return true;
  566 + case "false":
  567 + return false;
  568 + case "yes":
  569 + return true;
  570 + case "ok":
  571 + return true;
  572 + case "no":
  573 + return false;
  574 + case "1":
  575 + return true;
  576 + case "0":
  577 + return false;
  578 + default:
  579 + return defaultValue;
  580 + }
  581 + }
  582 +
  583 + /**
  584 + * 转换为boolean<br>
  585 + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
  586 + * 转换失败不会报错
  587 + *
  588 + * @param value 被转换的值
  589 + * @return 结果
  590 + */
  591 + public static Boolean toBool(Object value)
  592 + {
  593 + return toBool(value, null);
  594 + }
  595 +
  596 + /**
  597 + * 转换为Enum对象<br>
  598 + * 如果给定的值为空,或者转换失败,返回默认值<br>
  599 + *
  600 + * @param clazz Enum的Class
  601 + * @param value 值
  602 + * @param defaultValue 默认值
  603 + * @return Enum
  604 + */
  605 + public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue)
  606 + {
  607 + if (value == null)
  608 + {
  609 + return defaultValue;
  610 + }
  611 + if (clazz.isAssignableFrom(value.getClass()))
  612 + {
  613 + @SuppressWarnings("unchecked")
  614 + E myE = (E) value;
  615 + return myE;
  616 + }
  617 + final String valueStr = toStr(value, null);
  618 + if (StringUtils.isEmpty(valueStr))
  619 + {
  620 + return defaultValue;
  621 + }
  622 + try
  623 + {
  624 + return Enum.valueOf(clazz, valueStr);
  625 + }
  626 + catch (Exception e)
  627 + {
  628 + return defaultValue;
  629 + }
  630 + }
  631 +
  632 + /**
  633 + * 转换为Enum对象<br>
  634 + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
  635 + *
  636 + * @param clazz Enum的Class
  637 + * @param value 值
  638 + * @return Enum
  639 + */
  640 + public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value)
  641 + {
  642 + return toEnum(clazz, value, null);
  643 + }
  644 +
  645 + /**
  646 + * 转换为BigInteger<br>
  647 + * 如果给定的值为空,或者转换失败,返回默认值<br>
  648 + * 转换失败不会报错
  649 + *
  650 + * @param value 被转换的值
  651 + * @param defaultValue 转换错误时的默认值
  652 + * @return 结果
  653 + */
  654 + public static BigInteger toBigInteger(Object value, BigInteger defaultValue)
  655 + {
  656 + if (value == null)
  657 + {
  658 + return defaultValue;
  659 + }
  660 + if (value instanceof BigInteger)
  661 + {
  662 + return (BigInteger) value;
  663 + }
  664 + if (value instanceof Long)
  665 + {
  666 + return BigInteger.valueOf((Long) value);
  667 + }
  668 + final String valueStr = toStr(value, null);
  669 + if (StringUtils.isEmpty(valueStr))
  670 + {
  671 + return defaultValue;
  672 + }
  673 + try
  674 + {
  675 + return new BigInteger(valueStr);
  676 + }
  677 + catch (Exception e)
  678 + {
  679 + return defaultValue;
  680 + }
  681 + }
  682 +
  683 + /**
  684 + * 转换为BigInteger<br>
  685 + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br>
  686 + * 转换失败不会报错
  687 + *
  688 + * @param value 被转换的值
  689 + * @return 结果
  690 + */
  691 + public static BigInteger toBigInteger(Object value)
  692 + {
  693 + return toBigInteger(value, null);
  694 + }
  695 +
  696 + /**
  697 + * 转换为BigDecimal<br>
  698 + * 如果给定的值为空,或者转换失败,返回默认值<br>
  699 + * 转换失败不会报错
  700 + *
  701 + * @param value 被转换的值
  702 + * @param defaultValue 转换错误时的默认值
  703 + * @return 结果
  704 + */
  705 + public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue)
  706 + {
  707 + if (value == null)
  708 + {
  709 + return defaultValue;
  710 + }
  711 + if (value instanceof BigDecimal)
  712 + {
  713 + return (BigDecimal) value;
  714 + }
  715 + if (value instanceof Long)
  716 + {
  717 + return new BigDecimal((Long) value);
  718 + }
  719 + if (value instanceof Double)
  720 + {
  721 + return new BigDecimal((Double) value);
  722 + }
  723 + if (value instanceof Integer)
  724 + {
  725 + return new BigDecimal((Integer) value);
  726 + }
  727 + final String valueStr = toStr(value, null);
  728 + if (StringUtils.isEmpty(valueStr))
  729 + {
  730 + return defaultValue;
  731 + }
  732 + try
  733 + {
  734 + return new BigDecimal(valueStr);
  735 + }
  736 + catch (Exception e)
  737 + {
  738 + return defaultValue;
  739 + }
  740 + }
  741 +
  742 + /**
  743 + * 转换为BigDecimal<br>
  744 + * 如果给定的值为空,或者转换失败,返回默认值<br>
  745 + * 转换失败不会报错
  746 + *
  747 + * @param value 被转换的值
  748 + * @return 结果
  749 + */
  750 + public static BigDecimal toBigDecimal(Object value)
  751 + {
  752 + return toBigDecimal(value, null);
  753 + }
  754 +
  755 + /**
  756 + * 将对象转为字符串<br>
  757 + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
  758 + *
  759 + * @param obj 对象
  760 + * @return 字符串
  761 + */
  762 + public static String utf8Str(Object obj)
  763 + {
  764 + return str(obj, CharsetKit.CHARSET_UTF_8);
  765 + }
  766 +
  767 + /**
  768 + * 将对象转为字符串<br>
  769 + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
  770 + *
  771 + * @param obj 对象
  772 + * @param charsetName 字符集
  773 + * @return 字符串
  774 + */
  775 + public static String str(Object obj, String charsetName)
  776 + {
  777 + return str(obj, Charset.forName(charsetName));
  778 + }
  779 +
  780 + /**
  781 + * 将对象转为字符串<br>
  782 + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
  783 + *
  784 + * @param obj 对象
  785 + * @param charset 字符集
  786 + * @return 字符串
  787 + */
  788 + public static String str(Object obj, Charset charset)
  789 + {
  790 + if (null == obj)
  791 + {
  792 + return null;
  793 + }
  794 +
  795 + if (obj instanceof String)
  796 + {
  797 + return (String) obj;
  798 + }
  799 + else if (obj instanceof byte[])
  800 + {
  801 + return str((byte[]) obj, charset);
  802 + }
  803 + else if (obj instanceof Byte[])
  804 + {
  805 + byte[] bytes = ArrayUtils.toPrimitive((Byte[]) obj);
  806 + return str(bytes, charset);
  807 + }
  808 + else if (obj instanceof ByteBuffer)
  809 + {
  810 + return str((ByteBuffer) obj, charset);
  811 + }
  812 + return obj.toString();
  813 + }
  814 +
  815 + /**
  816 + * 将byte数组转为字符串
  817 + *
  818 + * @param bytes byte数组
  819 + * @param charset 字符集
  820 + * @return 字符串
  821 + */
  822 + public static String str(byte[] bytes, String charset)
  823 + {
  824 + return str(bytes, StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset));
  825 + }
  826 +
  827 + /**
  828 + * 解码字节码
  829 + *
  830 + * @param data 字符串
  831 + * @param charset 字符集,如果此字段为空,则解码的结果取决于平台
  832 + * @return 解码后的字符串
  833 + */
  834 + public static String str(byte[] data, Charset charset)
  835 + {
  836 + if (data == null)
  837 + {
  838 + return null;
  839 + }
  840 +
  841 + if (null == charset)
  842 + {
  843 + return new String(data);
  844 + }
  845 + return new String(data, charset);
  846 + }
  847 +
  848 + /**
  849 + * 将编码的byteBuffer数据转换为字符串
  850 + *
  851 + * @param data 数据
  852 + * @param charset 字符集,如果为空使用当前系统字符集
  853 + * @return 字符串
  854 + */
  855 + public static String str(ByteBuffer data, String charset)
  856 + {
  857 + if (data == null)
  858 + {
  859 + return null;
  860 + }
  861 +
  862 + return str(data, Charset.forName(charset));
  863 + }
  864 +
  865 + /**
  866 + * 将编码的byteBuffer数据转换为字符串
  867 + *
  868 + * @param data 数据
  869 + * @param charset 字符集,如果为空使用当前系统字符集
  870 + * @return 字符串
  871 + */
  872 + public static String str(ByteBuffer data, Charset charset)
  873 + {
  874 + if (null == charset)
  875 + {
  876 + charset = Charset.defaultCharset();
  877 + }
  878 + return charset.decode(data).toString();
  879 + }
  880 +
  881 + // ----------------------------------------------------------------------- 全角半角转换
  882 + /**
  883 + * 半角转全角
  884 + *
  885 + * @param input String.
  886 + * @return 全角字符串.
  887 + */
  888 + public static String toSBC(String input)
  889 + {
  890 + return toSBC(input, null);
  891 + }
  892 +
  893 + /**
  894 + * 半角转全角
  895 + *
  896 + * @param input String
  897 + * @param notConvertSet 不替换的字符集合
  898 + * @return 全角字符串.
  899 + */
  900 + public static String toSBC(String input, Set<Character> notConvertSet)
  901 + {
  902 + char c[] = input.toCharArray();
  903 + for (int i = 0; i < c.length; i++)
  904 + {
  905 + if (null != notConvertSet && notConvertSet.contains(c[i]))
  906 + {
  907 + // 跳过不替换的字符
  908 + continue;
  909 + }
  910 +
  911 + if (c[i] == ' ')
  912 + {
  913 + c[i] = '\u3000';
  914 + }
  915 + else if (c[i] < '\177')
  916 + {
  917 + c[i] = (char) (c[i] + 65248);
  918 +
  919 + }
  920 + }
  921 + return new String(c);
  922 + }
  923 +
  924 + /**
  925 + * 全角转半角
  926 + *
  927 + * @param input String.
  928 + * @return 半角字符串
  929 + */
  930 + public static String toDBC(String input)
  931 + {
  932 + return toDBC(input, null);
  933 + }
  934 +
  935 + /**
  936 + * 替换全角为半角
  937 + *
  938 + * @param text 文本
  939 + * @param notConvertSet 不替换的字符集合
  940 + * @return 替换后的字符
  941 + */
  942 + public static String toDBC(String text, Set<Character> notConvertSet)
  943 + {
  944 + char c[] = text.toCharArray();
  945 + for (int i = 0; i < c.length; i++)
  946 + {
  947 + if (null != notConvertSet && notConvertSet.contains(c[i]))
  948 + {
  949 + // 跳过不替换的字符
  950 + continue;
  951 + }
  952 +
  953 + if (c[i] == '\u3000')
  954 + {
  955 + c[i] = ' ';
  956 + }
  957 + else if (c[i] > '\uFF00' && c[i] < '\uFF5F')
  958 + {
  959 + c[i] = (char) (c[i] - 65248);
  960 + }
  961 + }
  962 + String returnString = new String(c);
  963 +
  964 + return returnString;
  965 + }
  966 +
  967 + /**
  968 + * 数字金额大写转换 先写个完整的然后将如零拾替换成零
  969 + *
  970 + * @param n 数字
  971 + * @return 中文大写数字
  972 + */
  973 + public static String digitUppercase(double n)
  974 + {
  975 + String[] fraction = { "角", "分" };
  976 + String[] digit = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  977 + String[][] unit = { { "元", "万", "亿" }, { "", "拾", "佰", "仟" } };
  978 +
  979 + String head = n < 0 ? "负" : "";
  980 + n = Math.abs(n);
  981 +
  982 + String s = "";
  983 + for (int i = 0; i < fraction.length; i++)
  984 + {
  985 + s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
  986 + }
  987 + if (s.length() < 1)
  988 + {
  989 + s = "整";
  990 + }
  991 + int integerPart = (int) Math.floor(n);
  992 +
  993 + for (int i = 0; i < unit[0].length && integerPart > 0; i++)
  994 + {
  995 + String p = "";
  996 + for (int j = 0; j < unit[1].length && n > 0; j++)
  997 + {
  998 + p = digit[integerPart % 10] + unit[1][j] + p;
  999 + integerPart = integerPart / 10;
  1000 + }
  1001 + s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i] + s;
  1002 + }
  1003 + return head + s.replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整");
  1004 + }
  1005 +}
  1 +package com.zhonglai.luhui.mqtt.comm.util;
  2 +
  3 +import org.apache.commons.lang3.time.DateFormatUtils;
  4 +
  5 +import java.lang.management.ManagementFactory;
  6 +import java.text.ParseException;
  7 +import java.text.SimpleDateFormat;
  8 +import java.time.*;
  9 +import java.util.Date;
  10 +
  11 +/**
  12 + * 时间工具类
  13 + *
  14 + * @author ruoyi
  15 + */
  16 +public class DateUtils extends org.apache.commons.lang3.time.DateUtils
  17 +{
  18 + public static String YYYY = "yyyy";
  19 +
  20 + public static String YYYY_MM = "yyyy-MM";
  21 +
  22 + public static String YYYY_MM_DD = "yyyy-MM-dd";
  23 +
  24 + public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
  25 +
  26 + public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
  27 +
  28 + private static String[] parsePatterns = {
  29 + "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
  30 + "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
  31 + "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
  32 +
  33 + /**
  34 + * 获取当前Date型日期
  35 + *
  36 + * @return Date() 当前日期
  37 + */
  38 + public static Date getNowDate()
  39 + {
  40 + return new Date();
  41 + }
  42 +
  43 + /**
  44 + * 获取当前日期, 默认格式为yyyy-MM-dd
  45 + *
  46 + * @return String
  47 + */
  48 + public static String getDate()
  49 + {
  50 + return dateTimeNow(YYYY_MM_DD);
  51 + }
  52 +
  53 + public static final String getTime()
  54 + {
  55 + return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
  56 + }
  57 +
  58 + public static final String dateTimeNow()
  59 + {
  60 + return dateTimeNow(YYYYMMDDHHMMSS);
  61 + }
  62 +
  63 + public static final String dateTimeNow(final String format)
  64 + {
  65 + return parseDateToStr(format, new Date());
  66 + }
  67 +
  68 + public static final String dateTime(final Date date)
  69 + {
  70 + return parseDateToStr(YYYY_MM_DD, date);
  71 + }
  72 +
  73 + public static final String parseDateToStr(final String format, final Date date)
  74 + {
  75 + return new SimpleDateFormat(format).format(date);
  76 + }
  77 +
  78 + public static final Date dateTime(final String format, final String ts)
  79 + {
  80 + try
  81 + {
  82 + return new SimpleDateFormat(format).parse(ts);
  83 + }
  84 + catch (ParseException e)
  85 + {
  86 + throw new RuntimeException(e);
  87 + }
  88 + }
  89 +
  90 + /**
  91 + * 日期路径 即年/月/日 如2018/08/08
  92 + */
  93 + public static final String datePath()
  94 + {
  95 + Date now = new Date();
  96 + return DateFormatUtils.format(now, "yyyy/MM/dd");
  97 + }
  98 +
  99 + /**
  100 + * 日期路径 即年/月/日 如20180808
  101 + */
  102 + public static final String dateTime()
  103 + {
  104 + Date now = new Date();
  105 + return DateFormatUtils.format(now, "yyyyMMdd");
  106 + }
  107 +
  108 + /**
  109 + * 日期型字符串转化为日期 格式
  110 + */
  111 + public static Date parseDate(Object str)
  112 + {
  113 + if (str == null)
  114 + {
  115 + return null;
  116 + }
  117 + try
  118 + {
  119 + return parseDate(str.toString(), parsePatterns);
  120 + }
  121 + catch (ParseException e)
  122 + {
  123 + return null;
  124 + }
  125 + }
  126 +
  127 + /**
  128 + * 获取服务器启动时间
  129 + */
  130 + public static Date getServerStartDate()
  131 + {
  132 + long time = ManagementFactory.getRuntimeMXBean().getStartTime();
  133 + return new Date(time);
  134 + }
  135 +
  136 + /**
  137 + * 计算相差天数
  138 + */
  139 + public static int differentDaysByMillisecond(Date date1, Date date2)
  140 + {
  141 + return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24)));
  142 + }
  143 +
  144 + /**
  145 + * 计算两个时间差
  146 + */
  147 + public static String getDatePoor(Date endDate, Date nowDate)
  148 + {
  149 + long nd = 1000 * 24 * 60 * 60;
  150 + long nh = 1000 * 60 * 60;
  151 + long nm = 1000 * 60;
  152 + // long ns = 1000;
  153 + // 获得两个时间的毫秒时间差异
  154 + long diff = endDate.getTime() - nowDate.getTime();
  155 + // 计算差多少天
  156 + long day = diff / nd;
  157 + // 计算差多少小时
  158 + long hour = diff % nd / nh;
  159 + // 计算差多少分钟
  160 + long min = diff % nd % nh / nm;
  161 + // 计算差多少秒//输出结果
  162 + // long sec = diff % nd % nh % nm / ns;
  163 + return day + "天" + hour + "小时" + min + "分钟";
  164 + }
  165 +
  166 + /**
  167 + * 增加 LocalDateTime ==> Date
  168 + */
  169 + public static Date toDate(LocalDateTime temporalAccessor)
  170 + {
  171 + ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault());
  172 + return Date.from(zdt.toInstant());
  173 + }
  174 +
  175 + /**
  176 + * 增加 LocalDate ==> Date
  177 + */
  178 + public static Date toDate(LocalDate temporalAccessor)
  179 + {
  180 + LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0));
  181 + ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
  182 + return Date.from(zdt.toInstant());
  183 + }
  184 +
  185 + public static Integer getNowTimeMilly() {
  186 + String time = System.currentTimeMillis() / 1000L + "";
  187 + return Integer.parseInt(time);
  188 + }
  189 +}
  1 +package com.zhonglai.luhui.mqtt.comm.util;
  2 +
  3 +/**
  4 + * 字符串格式化
  5 + *
  6 + * @author ruoyi
  7 + */
  8 +public class StrFormatter
  9 +{
  10 + public static final String EMPTY_JSON = "{}";
  11 + public static final char C_BACKSLASH = '\\';
  12 + public static final char C_DELIM_START = '{';
  13 + public static final char C_DELIM_END = '}';
  14 +
  15 + /**
  16 + * 格式化字符串<br>
  17 + * 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
  18 + * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br>
  19 + * 例:<br>
  20 + * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br>
  21 + * 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
  22 + * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
  23 + *
  24 + * @param strPattern 字符串模板
  25 + * @param argArray 参数列表
  26 + * @return 结果
  27 + */
  28 + public static String format(final String strPattern, final Object... argArray)
  29 + {
  30 + if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray))
  31 + {
  32 + return strPattern;
  33 + }
  34 + final int strPatternLength = strPattern.length();
  35 +
  36 + // 初始化定义好的长度以获得更好的性能
  37 + StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
  38 +
  39 + int handledPosition = 0;
  40 + int delimIndex;// 占位符所在位置
  41 + for (int argIndex = 0; argIndex < argArray.length; argIndex++)
  42 + {
  43 + delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition);
  44 + if (delimIndex == -1)
  45 + {
  46 + if (handledPosition == 0)
  47 + {
  48 + return strPattern;
  49 + }
  50 + else
  51 + { // 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果
  52 + sbuf.append(strPattern, handledPosition, strPatternLength);
  53 + return sbuf.toString();
  54 + }
  55 + }
  56 + else
  57 + {
  58 + if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH)
  59 + {
  60 + if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH)
  61 + {
  62 + // 转义符之前还有一个转义符,占位符依旧有效
  63 + sbuf.append(strPattern, handledPosition, delimIndex - 1);
  64 + sbuf.append(Convert.utf8Str(argArray[argIndex]));
  65 + handledPosition = delimIndex + 2;
  66 + }
  67 + else
  68 + {
  69 + // 占位符被转义
  70 + argIndex--;
  71 + sbuf.append(strPattern, handledPosition, delimIndex - 1);
  72 + sbuf.append(C_DELIM_START);
  73 + handledPosition = delimIndex + 1;
  74 + }
  75 + }
  76 + else
  77 + {
  78 + // 正常占位符
  79 + sbuf.append(strPattern, handledPosition, delimIndex);
  80 + sbuf.append(Convert.utf8Str(argArray[argIndex]));
  81 + handledPosition = delimIndex + 2;
  82 + }
  83 + }
  84 + }
  85 + // 加入最后一个占位符后所有的字符
  86 + sbuf.append(strPattern, handledPosition, strPattern.length());
  87 +
  88 + return sbuf.toString();
  89 + }
  90 +}
  1 +package com.zhonglai.luhui.mqtt.comm.util;
  2 +
  3 +import org.springframework.util.AntPathMatcher;
  4 +
  5 +import java.util.*;
  6 +
  7 +/**
  8 + * 字符串工具类
  9 + *
  10 + * @author ruoyi
  11 + */
  12 +public class StringUtils extends org.apache.commons.lang3.StringUtils
  13 +{
  14 + /** 空字符串 */
  15 + private static final String NULLSTR = "";
  16 +
  17 + /** 下划线 */
  18 + private static final char SEPARATOR = '_';
  19 +
  20 + /**
  21 + * 获取参数不为空值
  22 + *
  23 + * @param value defaultValue 要判断的value
  24 + * @return value 返回值
  25 + */
  26 + public static <T> T nvl(T value, T defaultValue)
  27 + {
  28 + return value != null ? value : defaultValue;
  29 + }
  30 +
  31 + /**
  32 + * * 判断一个Collection是否为空, 包含List,Set,Queue
  33 + *
  34 + * @param coll 要判断的Collection
  35 + * @return true:为空 false:非空
  36 + */
  37 + public static boolean isEmpty(Collection<?> coll)
  38 + {
  39 + return isNull(coll) || coll.isEmpty();
  40 + }
  41 +
  42 + /**
  43 + * * 判断一个Collection是否非空,包含List,Set,Queue
  44 + *
  45 + * @param coll 要判断的Collection
  46 + * @return true:非空 false:空
  47 + */
  48 + public static boolean isNotEmpty(Collection<?> coll)
  49 + {
  50 + return !isEmpty(coll);
  51 + }
  52 +
  53 + /**
  54 + * * 判断一个对象数组是否为空
  55 + *
  56 + * @param objects 要判断的对象数组
  57 + ** @return true:为空 false:非空
  58 + */
  59 + public static boolean isEmpty(Object[] objects)
  60 + {
  61 + return isNull(objects) || (objects.length == 0);
  62 + }
  63 +
  64 + /**
  65 + * * 判断一个对象数组是否非空
  66 + *
  67 + * @param objects 要判断的对象数组
  68 + * @return true:非空 false:空
  69 + */
  70 + public static boolean isNotEmpty(Object[] objects)
  71 + {
  72 + return !isEmpty(objects);
  73 + }
  74 +
  75 + /**
  76 + * * 判断一个Map是否为空
  77 + *
  78 + * @param map 要判断的Map
  79 + * @return true:为空 false:非空
  80 + */
  81 + public static boolean isEmpty(Map<?, ?> map)
  82 + {
  83 + return isNull(map) || map.isEmpty();
  84 + }
  85 +
  86 + /**
  87 + * * 判断一个Map是否为空
  88 + *
  89 + * @param map 要判断的Map
  90 + * @return true:非空 false:空
  91 + */
  92 + public static boolean isNotEmpty(Map<?, ?> map)
  93 + {
  94 + return !isEmpty(map);
  95 + }
  96 +
  97 + /**
  98 + * * 判断一个字符串是否为空串
  99 + *
  100 + * @param str String
  101 + * @return true:为空 false:非空
  102 + */
  103 + public static boolean isEmpty(String str)
  104 + {
  105 + return isNull(str) || NULLSTR.equals(str.trim());
  106 + }
  107 +
  108 + /**
  109 + * * 判断一个字符串是否为非空串
  110 + *
  111 + * @param str String
  112 + * @return true:非空串 false:空串
  113 + */
  114 + public static boolean isNotEmpty(String str)
  115 + {
  116 + return !isEmpty(str);
  117 + }
  118 +
  119 + /**
  120 + * * 判断一个对象是否为空
  121 + *
  122 + * @param object Object
  123 + * @return true:为空 false:非空
  124 + */
  125 + public static boolean isNull(Object object)
  126 + {
  127 + return object == null;
  128 + }
  129 +
  130 + /**
  131 + * * 判断一个对象是否非空
  132 + *
  133 + * @param object Object
  134 + * @return true:非空 false:空
  135 + */
  136 + public static boolean isNotNull(Object object)
  137 + {
  138 + return !isNull(object);
  139 + }
  140 +
  141 + /**
  142 + * * 判断一个对象是否是数组类型(Java基本型别的数组)
  143 + *
  144 + * @param object 对象
  145 + * @return true:是数组 false:不是数组
  146 + */
  147 + public static boolean isArray(Object object)
  148 + {
  149 + return isNotNull(object) && object.getClass().isArray();
  150 + }
  151 +
  152 + /**
  153 + * 去空格
  154 + */
  155 + public static String trim(String str)
  156 + {
  157 + return (str == null ? "" : str.trim());
  158 + }
  159 +
  160 + /**
  161 + * 截取字符串
  162 + *
  163 + * @param str 字符串
  164 + * @param start 开始
  165 + * @return 结果
  166 + */
  167 + public static String substring(final String str, int start)
  168 + {
  169 + if (str == null)
  170 + {
  171 + return NULLSTR;
  172 + }
  173 +
  174 + if (start < 0)
  175 + {
  176 + start = str.length() + start;
  177 + }
  178 +
  179 + if (start < 0)
  180 + {
  181 + start = 0;
  182 + }
  183 + if (start > str.length())
  184 + {
  185 + return NULLSTR;
  186 + }
  187 +
  188 + return str.substring(start);
  189 + }
  190 +
  191 + /**
  192 + * 截取字符串
  193 + *
  194 + * @param str 字符串
  195 + * @param start 开始
  196 + * @param end 结束
  197 + * @return 结果
  198 + */
  199 + public static String substring(final String str, int start, int end)
  200 + {
  201 + if (str == null)
  202 + {
  203 + return NULLSTR;
  204 + }
  205 +
  206 + if (end < 0)
  207 + {
  208 + end = str.length() + end;
  209 + }
  210 + if (start < 0)
  211 + {
  212 + start = str.length() + start;
  213 + }
  214 +
  215 + if (end > str.length())
  216 + {
  217 + end = str.length();
  218 + }
  219 +
  220 + if (start > end)
  221 + {
  222 + return NULLSTR;
  223 + }
  224 +
  225 + if (start < 0)
  226 + {
  227 + start = 0;
  228 + }
  229 + if (end < 0)
  230 + {
  231 + end = 0;
  232 + }
  233 +
  234 + return str.substring(start, end);
  235 + }
  236 +
  237 + /**
  238 + * 格式化文本, {} 表示占位符<br>
  239 + * 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
  240 + * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br>
  241 + * 例:<br>
  242 + * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br>
  243 + * 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br>
  244 + * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br>
  245 + *
  246 + * @param template 文本模板,被替换的部分用 {} 表示
  247 + * @param params 参数值
  248 + * @return 格式化后的文本
  249 + */
  250 + public static String format(String template, Object... params)
  251 + {
  252 + if (isEmpty(params) || isEmpty(template))
  253 + {
  254 + return template;
  255 + }
  256 + return StrFormatter.format(template, params);
  257 + }
  258 +
  259 + /**
  260 + * 是否为http(s)://开头
  261 + *
  262 + * @param link 链接
  263 + * @return 结果
  264 + */
  265 + public static boolean ishttp(String link)
  266 + {
  267 + return StringUtils.startsWithAny(link, Constants.HTTP, Constants.HTTPS);
  268 + }
  269 +
  270 + /**
  271 + * 字符串转set
  272 + *
  273 + * @param str 字符串
  274 + * @param sep 分隔符
  275 + * @return set集合
  276 + */
  277 + public static final Set<String> str2Set(String str, String sep)
  278 + {
  279 + return new HashSet<String>(str2List(str, sep, true, false));
  280 + }
  281 +
  282 + /**
  283 + * 字符串转list
  284 + *
  285 + * @param str 字符串
  286 + * @param sep 分隔符
  287 + * @param filterBlank 过滤纯空白
  288 + * @param trim 去掉首尾空白
  289 + * @return list集合
  290 + */
  291 + public static final List<String> str2List(String str, String sep, boolean filterBlank, boolean trim)
  292 + {
  293 + List<String> list = new ArrayList<String>();
  294 + if (StringUtils.isEmpty(str))
  295 + {
  296 + return list;
  297 + }
  298 +
  299 + // 过滤空白字符串
  300 + if (filterBlank && StringUtils.isBlank(str))
  301 + {
  302 + return list;
  303 + }
  304 + String[] split = str.split(sep);
  305 + for (String string : split)
  306 + {
  307 + if (filterBlank && StringUtils.isBlank(string))
  308 + {
  309 + continue;
  310 + }
  311 + if (trim)
  312 + {
  313 + string = string.trim();
  314 + }
  315 + list.add(string);
  316 + }
  317 +
  318 + return list;
  319 + }
  320 +
  321 + /**
  322 + * 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写
  323 + *
  324 + * @param cs 指定字符串
  325 + * @param searchCharSequences 需要检查的字符串数组
  326 + * @return 是否包含任意一个字符串
  327 + */
  328 + public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences)
  329 + {
  330 + if (isEmpty(cs) || isEmpty(searchCharSequences))
  331 + {
  332 + return false;
  333 + }
  334 + for (CharSequence testStr : searchCharSequences)
  335 + {
  336 + if (containsIgnoreCase(cs, testStr))
  337 + {
  338 + return true;
  339 + }
  340 + }
  341 + return false;
  342 + }
  343 +
  344 + /**
  345 + * 驼峰转下划线命名
  346 + */
  347 + public static String toUnderScoreCase(String str)
  348 + {
  349 + if (str == null)
  350 + {
  351 + return null;
  352 + }
  353 + StringBuilder sb = new StringBuilder();
  354 + // 前置字符是否大写
  355 + boolean preCharIsUpperCase = true;
  356 + // 当前字符是否大写
  357 + boolean curreCharIsUpperCase = true;
  358 + // 下一字符是否大写
  359 + boolean nexteCharIsUpperCase = true;
  360 + for (int i = 0; i < str.length(); i++)
  361 + {
  362 + char c = str.charAt(i);
  363 + if (i > 0)
  364 + {
  365 + preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1));
  366 + }
  367 + else
  368 + {
  369 + preCharIsUpperCase = false;
  370 + }
  371 +
  372 + curreCharIsUpperCase = Character.isUpperCase(c);
  373 +
  374 + if (i < (str.length() - 1))
  375 + {
  376 + nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
  377 + }
  378 +
  379 + if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase)
  380 + {
  381 + sb.append(SEPARATOR);
  382 + }
  383 + else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase)
  384 + {
  385 + sb.append(SEPARATOR);
  386 + }
  387 + sb.append(Character.toLowerCase(c));
  388 + }
  389 +
  390 + return sb.toString();
  391 + }
  392 +
  393 + /**
  394 + * 是否包含字符串
  395 + *
  396 + * @param str 验证字符串
  397 + * @param strs 字符串组
  398 + * @return 包含返回true
  399 + */
  400 + public static boolean inStringIgnoreCase(String str, String... strs)
  401 + {
  402 + if (str != null && strs != null)
  403 + {
  404 + for (String s : strs)
  405 + {
  406 + if (str.equalsIgnoreCase(trim(s)))
  407 + {
  408 + return true;
  409 + }
  410 + }
  411 + }
  412 + return false;
  413 + }
  414 +
  415 + /**
  416 + * 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld
  417 + *
  418 + * @param name 转换前的下划线大写方式命名的字符串
  419 + * @return 转换后的驼峰式命名的字符串
  420 + */
  421 + public static String convertToCamelCase(String name)
  422 + {
  423 + StringBuilder result = new StringBuilder();
  424 + // 快速检查
  425 + if (name == null || name.isEmpty())
  426 + {
  427 + // 没必要转换
  428 + return "";
  429 + }
  430 + else if (!name.contains("_"))
  431 + {
  432 + // 不含下划线,仅将首字母大写
  433 + return name.substring(0, 1).toUpperCase() + name.substring(1);
  434 + }
  435 + // 用下划线将原始字符串分割
  436 + String[] camels = name.split("_");
  437 + for (String camel : camels)
  438 + {
  439 + // 跳过原始字符串中开头、结尾的下换线或双重下划线
  440 + if (camel.isEmpty())
  441 + {
  442 + continue;
  443 + }
  444 + // 首字母大写
  445 + result.append(camel.substring(0, 1).toUpperCase());
  446 + result.append(camel.substring(1).toLowerCase());
  447 + }
  448 + return result.toString();
  449 + }
  450 +
  451 + /**
  452 + * 驼峰式命名法 例如:user_name->userName
  453 + */
  454 + public static String toCamelCase(String s)
  455 + {
  456 + if (s == null)
  457 + {
  458 + return null;
  459 + }
  460 + s = s.toLowerCase();
  461 + StringBuilder sb = new StringBuilder(s.length());
  462 + boolean upperCase = false;
  463 + for (int i = 0; i < s.length(); i++)
  464 + {
  465 + char c = s.charAt(i);
  466 +
  467 + if (c == SEPARATOR)
  468 + {
  469 + upperCase = true;
  470 + }
  471 + else if (upperCase)
  472 + {
  473 + sb.append(Character.toUpperCase(c));
  474 + upperCase = false;
  475 + }
  476 + else
  477 + {
  478 + sb.append(c);
  479 + }
  480 + }
  481 + return sb.toString();
  482 + }
  483 +
  484 + /**
  485 + * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
  486 + *
  487 + * @param str 指定字符串
  488 + * @param strs 需要检查的字符串数组
  489 + * @return 是否匹配
  490 + */
  491 + public static boolean matches(String str, List<String> strs)
  492 + {
  493 + if (isEmpty(str) || isEmpty(strs))
  494 + {
  495 + return false;
  496 + }
  497 + for (String pattern : strs)
  498 + {
  499 + if (isMatch(pattern, str))
  500 + {
  501 + return true;
  502 + }
  503 + }
  504 + return false;
  505 + }
  506 +
  507 + /**
  508 + * 判断url是否与规则配置:
  509 + * ? 表示单个字符;
  510 + * * 表示一层路径内的任意字符串,不可跨层级;
  511 + * ** 表示任意层路径;
  512 + *
  513 + * @param pattern 匹配规则
  514 + * @param url 需要匹配的url
  515 + * @return
  516 + */
  517 + public static boolean isMatch(String pattern, String url)
  518 + {
  519 + AntPathMatcher matcher = new AntPathMatcher();
  520 + return matcher.match(pattern, url);
  521 + }
  522 +
  523 + @SuppressWarnings("unchecked")
  524 + public static <T> T cast(Object obj)
  525 + {
  526 + return (T) obj;
  527 + }
  528 +
  529 + /**
  530 + * 数字左边补齐0,使之达到指定长度。注意,如果数字转换为字符串后,长度大于size,则只保留 最后size个字符。
  531 + *
  532 + * @param num 数字对象
  533 + * @param size 字符串指定长度
  534 + * @return 返回数字的字符串格式,该字符串为指定长度。
  535 + */
  536 + public static final String padl(final Number num, final int size)
  537 + {
  538 + return padl(num.toString(), size, '0');
  539 + }
  540 +
  541 + /**
  542 + * 字符串左补齐。如果原始字符串s长度大于size,则只保留最后size个字符。
  543 + *
  544 + * @param s 原始字符串
  545 + * @param size 字符串指定长度
  546 + * @param c 用于补齐的字符
  547 + * @return 返回指定长度的字符串,由原字符串左补齐或截取得到。
  548 + */
  549 + public static final String padl(final String s, final int size, final char c)
  550 + {
  551 + final StringBuilder sb = new StringBuilder(size);
  552 + if (s != null)
  553 + {
  554 + final int len = s.length();
  555 + if (s.length() <= size)
  556 + {
  557 + for (int i = size - len; i > 0; i--)
  558 + {
  559 + sb.append(c);
  560 + }
  561 + sb.append(s);
  562 + }
  563 + else
  564 + {
  565 + return s.substring(len - size, len);
  566 + }
  567 + }
  568 + else
  569 + {
  570 + for (int i = size; i > 0; i--)
  571 + {
  572 + sb.append(c);
  573 + }
  574 + }
  575 + return sb.toString();
  576 + }
  577 +
  578 + /**
  579 + * [简要描述]:首字母大写
  580 + *
  581 + * @author com.zhonglai
  582 + * @param str
  583 + * @return
  584 + */
  585 + public static String getName(String str) {
  586 + char ch = str.toCharArray()[0];
  587 + ch = (char) ((ch - 97) + 'A');
  588 + str = ch + str.substring(1);
  589 + return str;
  590 + }
  591 +}
1 package com.zhonglai.luhui.mqtt.comm.util; 1 package com.zhonglai.luhui.mqtt.comm.util;
2 2
3 3
4 -import com.ruoyi.common.utils.DateUtils;  
5 4
6 import java.util.Date; 5 import java.util.Date;
7 6
  1 +package com.zhonglai.luhui.mqtt.comm.util.http;
  2 +
  3 +import org.apache.commons.lang3.exception.ExceptionUtils;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +
  7 +import javax.servlet.ServletRequest;
  8 +import java.io.BufferedReader;
  9 +import java.io.IOException;
  10 +import java.io.InputStream;
  11 +import java.io.InputStreamReader;
  12 +import java.nio.charset.StandardCharsets;
  13 +
  14 +/**
  15 + * 通用http工具封装
  16 + *
  17 + * @author ruoyi
  18 + */
  19 +public class HttpHelper
  20 +{
  21 + private static final Logger LOGGER = LoggerFactory.getLogger(HttpHelper.class);
  22 +
  23 + public static String getBodyString(ServletRequest request)
  24 + {
  25 + StringBuilder sb = new StringBuilder();
  26 + BufferedReader reader = null;
  27 + try (InputStream inputStream = request.getInputStream())
  28 + {
  29 + reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
  30 + String line = "";
  31 + while ((line = reader.readLine()) != null)
  32 + {
  33 + sb.append(line);
  34 + }
  35 + }
  36 + catch (IOException e)
  37 + {
  38 + LOGGER.warn("getBodyString出现问题!");
  39 + }
  40 + finally
  41 + {
  42 + if (reader != null)
  43 + {
  44 + try
  45 + {
  46 + reader.close();
  47 + }
  48 + catch (IOException e)
  49 + {
  50 + LOGGER.error(ExceptionUtils.getMessage(e));
  51 + }
  52 + }
  53 + }
  54 + return sb.toString();
  55 + }
  56 +}
  1 +package com.zhonglai.luhui.mqtt.comm.util.http;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.util.Constants;
  4 +import com.zhonglai.luhui.mqtt.comm.util.StringUtils;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +
  8 +import javax.net.ssl.*;
  9 +import java.io.*;
  10 +import java.net.ConnectException;
  11 +import java.net.SocketTimeoutException;
  12 +import java.net.URL;
  13 +import java.net.URLConnection;
  14 +import java.nio.charset.StandardCharsets;
  15 +import java.security.cert.X509Certificate;
  16 +
  17 +/**
  18 + * 通用http发送方法
  19 + *
  20 + * @author ruoyi
  21 + */
  22 +public class HttpUtils
  23 +{
  24 + private static final Logger log = LoggerFactory.getLogger(HttpUtils.class);
  25 +
  26 + /**
  27 + * 向指定 URL 发送GET方法的请求
  28 + *
  29 + * @param url 发送请求的 URL
  30 + * @return 所代表远程资源的响应结果
  31 + */
  32 + public static String sendGet(String url)
  33 + {
  34 + return sendGet(url, StringUtils.EMPTY);
  35 + }
  36 +
  37 + /**
  38 + * 向指定 URL 发送GET方法的请求
  39 + *
  40 + * @param url 发送请求的 URL
  41 + * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
  42 + * @return 所代表远程资源的响应结果
  43 + */
  44 + public static String sendGet(String url, String param)
  45 + {
  46 + return sendGet(url, param, Constants.UTF8);
  47 + }
  48 +
  49 + /**
  50 + * 向指定 URL 发送GET方法的请求
  51 + *
  52 + * @param url 发送请求的 URL
  53 + * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
  54 + * @param contentType 编码类型
  55 + * @return 所代表远程资源的响应结果
  56 + */
  57 + public static String sendGet(String url, String param, String contentType)
  58 + {
  59 + StringBuilder result = new StringBuilder();
  60 + BufferedReader in = null;
  61 + try
  62 + {
  63 + String urlNameString = StringUtils.isNotBlank(param) ? url + "?" + param : url;
  64 + log.info("sendGet - {}", urlNameString);
  65 + URL realUrl = new URL(urlNameString);
  66 + URLConnection connection = realUrl.openConnection();
  67 + connection.setRequestProperty("accept", "*/*");
  68 + connection.setRequestProperty("connection", "Keep-Alive");
  69 + connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
  70 + connection.connect();
  71 + in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType));
  72 + String line;
  73 + while ((line = in.readLine()) != null)
  74 + {
  75 + result.append(line);
  76 + }
  77 + log.info("recv - {}", result);
  78 + }
  79 + catch (ConnectException e)
  80 + {
  81 + log.error("调用HttpUtils.sendGet ConnectException, url=" + url + ",param=" + param, e);
  82 + }
  83 + catch (SocketTimeoutException e)
  84 + {
  85 + log.error("调用HttpUtils.sendGet SocketTimeoutException, url=" + url + ",param=" + param, e);
  86 + }
  87 + catch (IOException e)
  88 + {
  89 + log.error("调用HttpUtils.sendGet IOException, url=" + url + ",param=" + param, e);
  90 + }
  91 + catch (Exception e)
  92 + {
  93 + log.error("调用HttpsUtil.sendGet Exception, url=" + url + ",param=" + param, e);
  94 + }
  95 + finally
  96 + {
  97 + try
  98 + {
  99 + if (in != null)
  100 + {
  101 + in.close();
  102 + }
  103 + }
  104 + catch (Exception ex)
  105 + {
  106 + log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
  107 + }
  108 + }
  109 + return result.toString();
  110 + }
  111 +
  112 + /**
  113 + * 向指定 URL 发送POST方法的请求
  114 + *
  115 + * @param url 发送请求的 URL
  116 + * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
  117 + * @return 所代表远程资源的响应结果
  118 + */
  119 + public static String sendPost(String url, String param)
  120 + {
  121 + PrintWriter out = null;
  122 + BufferedReader in = null;
  123 + StringBuilder result = new StringBuilder();
  124 + try
  125 + {
  126 + log.info("sendPost - {}", url);
  127 + URL realUrl = new URL(url);
  128 + URLConnection conn = realUrl.openConnection();
  129 + conn.setRequestProperty("accept", "*/*");
  130 + conn.setRequestProperty("connection", "Keep-Alive");
  131 + conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
  132 + conn.setRequestProperty("Accept-Charset", "utf-8");
  133 + conn.setRequestProperty("contentType", "utf-8");
  134 + conn.setDoOutput(true);
  135 + conn.setDoInput(true);
  136 + out = new PrintWriter(conn.getOutputStream());
  137 + out.print(param);
  138 + out.flush();
  139 + in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
  140 + String line;
  141 + while ((line = in.readLine()) != null)
  142 + {
  143 + result.append(line);
  144 + }
  145 + log.info("recv - {}", result);
  146 + }
  147 + catch (ConnectException e)
  148 + {
  149 + log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
  150 + }
  151 + catch (SocketTimeoutException e)
  152 + {
  153 + log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
  154 + }
  155 + catch (IOException e)
  156 + {
  157 + log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
  158 + }
  159 + catch (Exception e)
  160 + {
  161 + log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
  162 + }
  163 + finally
  164 + {
  165 + try
  166 + {
  167 + if (out != null)
  168 + {
  169 + out.close();
  170 + }
  171 + if (in != null)
  172 + {
  173 + in.close();
  174 + }
  175 + }
  176 + catch (IOException ex)
  177 + {
  178 + log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
  179 + }
  180 + }
  181 + return result.toString();
  182 + }
  183 +
  184 + public static String sendSSLPost(String url, String param)
  185 + {
  186 + StringBuilder result = new StringBuilder();
  187 + String urlNameString = url + "?" + param;
  188 + try
  189 + {
  190 + log.info("sendSSLPost - {}", urlNameString);
  191 + SSLContext sc = SSLContext.getInstance("SSL");
  192 + sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
  193 + URL console = new URL(urlNameString);
  194 + HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
  195 + conn.setRequestProperty("accept", "*/*");
  196 + conn.setRequestProperty("connection", "Keep-Alive");
  197 + conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
  198 + conn.setRequestProperty("Accept-Charset", "utf-8");
  199 + conn.setRequestProperty("contentType", "utf-8");
  200 + conn.setDoOutput(true);
  201 + conn.setDoInput(true);
  202 +
  203 + conn.setSSLSocketFactory(sc.getSocketFactory());
  204 + conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
  205 + conn.connect();
  206 + InputStream is = conn.getInputStream();
  207 + BufferedReader br = new BufferedReader(new InputStreamReader(is));
  208 + String ret = "";
  209 + while ((ret = br.readLine()) != null)
  210 + {
  211 + if (ret != null && !"".equals(ret.trim()))
  212 + {
  213 + result.append(new String(ret.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
  214 + }
  215 + }
  216 + log.info("recv - {}", result);
  217 + conn.disconnect();
  218 + br.close();
  219 + }
  220 + catch (ConnectException e)
  221 + {
  222 + log.error("调用HttpUtils.sendSSLPost ConnectException, url=" + url + ",param=" + param, e);
  223 + }
  224 + catch (SocketTimeoutException e)
  225 + {
  226 + log.error("调用HttpUtils.sendSSLPost SocketTimeoutException, url=" + url + ",param=" + param, e);
  227 + }
  228 + catch (IOException e)
  229 + {
  230 + log.error("调用HttpUtils.sendSSLPost IOException, url=" + url + ",param=" + param, e);
  231 + }
  232 + catch (Exception e)
  233 + {
  234 + log.error("调用HttpsUtil.sendSSLPost Exception, url=" + url + ",param=" + param, e);
  235 + }
  236 + return result.toString();
  237 + }
  238 +
  239 +
  240 +
  241 + private static class TrustAnyTrustManager implements X509TrustManager
  242 + {
  243 + @Override
  244 + public void checkClientTrusted(X509Certificate[] chain, String authType)
  245 + {
  246 + }
  247 +
  248 + @Override
  249 + public void checkServerTrusted(X509Certificate[] chain, String authType)
  250 + {
  251 + }
  252 +
  253 + @Override
  254 + public X509Certificate[] getAcceptedIssuers()
  255 + {
  256 + return new X509Certificate[] {};
  257 + }
  258 + }
  259 +
  260 + private static class TrustAnyHostnameVerifier implements HostnameVerifier
  261 + {
  262 + @Override
  263 + public boolean verify(String hostname, SSLSession session)
  264 + {
  265 + return true;
  266 + }
  267 + }
  268 +}
  1 +package com.zhonglai.luhui.mqtt.comm.util.http;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import okhttp3.*;
  5 +import org.apache.commons.lang3.ArrayUtils;
  6 +import org.apache.commons.lang3.math.NumberUtils;
  7 +
  8 +import javax.imageio.ImageIO;
  9 +import java.awt.*;
  10 +import java.awt.image.BufferedImage;
  11 +import java.io.ByteArrayInputStream;
  12 +import java.io.ByteArrayOutputStream;
  13 +import java.io.IOException;
  14 +import java.util.Map;
  15 +import java.util.concurrent.TimeUnit;
  16 +
  17 +public class OkHttpUtils {
  18 + private static OkHttpClient okHttpClient = new OkHttpClient.Builder()
  19 + .connectTimeout(10, TimeUnit.SECONDS)
  20 + .writeTimeout(10, TimeUnit.SECONDS)
  21 + .readTimeout(30, TimeUnit.SECONDS)
  22 + .build();
  23 + public static String generateGetUrl(String url, Map<String,String> map)
  24 + {
  25 + StringBuffer stringBuffer = new StringBuffer();
  26 + stringBuffer.append(url);
  27 + if(null != map && map.size() !=0)
  28 + {
  29 + stringBuffer.append("?1=1");
  30 + for(String key:map.keySet())
  31 + {
  32 + stringBuffer.append("&");
  33 + stringBuffer.append(key+"="+map.get(key));
  34 + }
  35 + }
  36 + return stringBuffer.toString();
  37 + }
  38 +
  39 + public static JSONObject reqstFormBodyHttp(RequestFunction requestFunction, String url)
  40 + {
  41 + FormBody.Builder builder = new FormBody.Builder();
  42 + requestFunction.builderParameter(builder);
  43 + return reqstHttp(url,builder.build());
  44 + }
  45 +
  46 + public static JSONObject reqstHttp(String url, RequestBody requestBody)
  47 + {
  48 + Response response = httpPostJson(url,requestBody);
  49 + JSONObject clJs = null;
  50 + try {
  51 + clJs = JSONObject.parseObject(response.body().string());
  52 + } catch (IOException e) {
  53 + e.printStackTrace();
  54 + }
  55 + System.out.println(clJs.toJSONString());
  56 + return clJs;
  57 + }
  58 +
  59 + public static Response httpPostJson(String url, RequestBody requestBody) {
  60 + Request request = getPostRequest( url, requestBody);
  61 + return response(request,3);
  62 + }
  63 +
  64 + public static Response response(Request request,int number) {
  65 +
  66 + Response response = null;
  67 + if(null == request)
  68 + {
  69 + System.out.println("request为空:");
  70 + return response;
  71 + }
  72 + try {
  73 + response = okHttpClient.newCall(request).execute();
  74 + } catch (IOException e) {
  75 + System.out.println("请求出错:"+e.getMessage());
  76 + if(0<number)
  77 + {
  78 + try {
  79 + Thread.sleep(1000);
  80 + } catch (InterruptedException ex) {
  81 + ex.printStackTrace();
  82 + }
  83 + response(request,number-1);
  84 + }else{
  85 + e.printStackTrace();
  86 + }
  87 + }
  88 +
  89 + try {
  90 + if (!response.isSuccessful()) {
  91 + throw new Exception("Unexpected code " + response);
  92 + }
  93 + } catch (Exception e) {
  94 + response.body().close();
  95 + }
  96 + return response;
  97 + }
  98 +
  99 + public static Request getPostRequest(String url, RequestBody requestBody)
  100 + {
  101 + return new Request.Builder()
  102 + .url(url)
  103 + .post(requestBody)
  104 + .build();
  105 + }
  106 +
  107 + public interface RequestFunction
  108 + {
  109 + void builderParameter(FormBody.Builder builder);
  110 + }
  111 +
  112 +
  113 + /**
  114 + *
  115 + * 压缩图片,并等比缩小。
  116 + *
  117 + * @author aren
  118 + * @param data
  119 + * 输入图片数据的byte[]。
  120 + * @param width
  121 + * 最大输出宽度,但是最后会根据图片本身比例调整。推荐值800。
  122 + * @param height
  123 + * 最大输出高度,但是最后会根据图片本身比例调整。推荐值600。
  124 + * @param type
  125 + * 指定最后存储的图片类型,支持字符串jpg,png,gif,bmp,jpeg。如果为null,则默认输出jpg格式图片。
  126 + * @param maxSize
  127 + * 指定最大输出图片的容量大小。可以为null表示不指定压缩容量大小。不要小于10000,推荐100000。
  128 + * @return 输出图片数据的byte[]。
  129 + * @throws Exception
  130 + */
  131 + public static byte[] zipImageToScaledSize(byte[] data, int width, int height, String type, Integer maxSize)
  132 + throws Exception {
  133 + if (data == null) {
  134 + return null;
  135 + }
  136 + if (width <= 0 || height <= 0) {
  137 + width = 800;
  138 + height = 600;
  139 + }
  140 + // 设定输出格式
  141 + String[] supportType = new String[] { "jpg", "png", "bmp", "jpeg", "gif" };
  142 + if (type == null || !ArrayUtils.contains(supportType, type)) {
  143 + type = "jpg";
  144 + }
  145 + int pointedHeight;
  146 + int pointedWidth;
  147 + ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
  148 + BufferedImage bufferedImage = ImageIO.read(inputStream);
  149 + inputStream.close();
  150 + int originalHeight = bufferedImage.getHeight();
  151 + int originalWidth = bufferedImage.getWidth();
  152 + // 设定等比例压缩。
  153 + if ((originalHeight / (double) height) > (originalWidth / (double) width)) {
  154 + pointedHeight = NumberUtils.min(height, originalHeight);
  155 + pointedWidth = -1;
  156 + } else {
  157 + pointedHeight = -1;
  158 + pointedWidth = NumberUtils.min(width, originalWidth);
  159 + }
  160 + // 压缩图片,此处附上颜色类型BufferedImage.TYPE_INT_RGB。Color.WHITE,可以有效避免png转jpg时图片发红的问题。
  161 + Image newImage = bufferedImage.getScaledInstance(pointedWidth, pointedHeight, Image.SCALE_SMOOTH);
  162 + BufferedImage newBufferedImage = new BufferedImage(newImage.getWidth(null), newImage.getHeight(null),
  163 + BufferedImage.TYPE_INT_RGB);
  164 + newBufferedImage.getGraphics().drawImage(newImage, 0, 0,Color.WHITE, null);
  165 + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  166 + ImageIO.write(newBufferedImage, type, byteArrayOutputStream);
  167 + byteArrayOutputStream.close();
  168 + data = byteArrayOutputStream.toByteArray();
  169 + if (maxSize != null && data.length > maxSize) {
  170 + // 设定递归的保险,以免图片质量太差
  171 + if (maxSize < 5000 && (data.length > 10 * maxSize)) {
  172 + maxSize = 5000;
  173 + }
  174 + // 递归压缩
  175 + double scale = Math.max(Math.pow(maxSize / (double) data.length, 0.5), 0.9);
  176 + return zipImageToScaledSize(data, (int) (width * scale), (int) (height * scale), type, maxSize);
  177 + } else {
  178 + return data;
  179 + }
  180 + }
  181 +}
1 package com.zhonglai.luhui.mqtt.controller; 1 package com.zhonglai.luhui.mqtt.controller;
2 2
3 -import com.luhui.ly.comm.util.CommonUtil;  
4 -import com.luhui.ly.device.mqtt.comm.service.ClienNoticeService;  
5 -import com.zhonglai.dto.Message;  
6 -import com.zhonglai.luhui.mqtt.dto.PutDto; 3 +import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService;
  4 +import com.zhonglai.luhui.mqtt.comm.util.DateUtils;
  5 +import com.zhonglai.luhui.mqtt.dto.Message;
  6 +import com.zhonglai.luhui.mqtt.dto.topic.PutDto;
7 import io.swagger.annotations.Api; 7 import io.swagger.annotations.Api;
8 import io.swagger.annotations.ApiOperation; 8 import io.swagger.annotations.ApiOperation;
9 import org.eclipse.paho.client.mqttv3.MqttException; 9 import org.eclipse.paho.client.mqttv3.MqttException;
@@ -26,7 +26,7 @@ public class DeviceController { @@ -26,7 +26,7 @@ public class DeviceController {
26 // ByteBuf message = Unpooled.buffer(bs.length); 26 // ByteBuf message = Unpooled.buffer(bs.length);
27 // message.writeBytes(bs); 27 // message.writeBytes(bs);
28 mqttMessage.setPayload(bs); 28 mqttMessage.setPayload(bs);
29 - Message message = clienNoticeService.sendMessage(clienid,mqttMessage, CommonUtil.getNowTimeMilly()+""); 29 + Message message = clienNoticeService.sendMessage(clienid,mqttMessage, DateUtils.getNowTimeMilly()+"");
30 return message; 30 return message;
31 } 31 }
32 32
  1 +package com.zhonglai.luhui.mqtt.dto;
  2 +
  3 +import lombok.Data;
  4 +
  5 +@Data
  6 +public class Message {
  7 + private int code;
  8 + private String message;
  9 + private Object data;
  10 +
  11 + public Message() {
  12 + }
  13 +
  14 + public Message(MessageCodeType code, String message, Object data) {
  15 + this.code = code.getCode();
  16 + this.message = message;
  17 + if (null == message || "".equals(message)) {
  18 + this.message = code.getMessage();
  19 + }
  20 +
  21 + this.data = data;
  22 + }
  23 +
  24 + public Message(MessageCodeType code, Object data) {
  25 + this.code = code.getCode();
  26 + this.message = code.getMessage();
  27 + this.data = data;
  28 + }
  29 +
  30 + public Message(MessageCodeType code, String message) {
  31 + this.code = code.getCode();
  32 + this.message = message;
  33 + this.data = null;
  34 + }
  35 +
  36 + public Message(MessageCodeType code) {
  37 + this.code = code.getCode();
  38 + this.message = code.getMessage();
  39 + }
  40 +
  41 + public void setCode(MessageCode messageCode )
  42 + {
  43 + code = messageCode.code;
  44 + }
  45 +
  46 + public void setCode(MessageCodeType code) {
  47 + this.code = code.getCode();
  48 + }
  49 +}
  1 +package com.zhonglai.luhui.mqtt.dto;
  2 +
  3 +public enum MessageCode implements MessageCodeType{
  4 + DEFAULT_FAIL_CODE(0, "请求失败"),
  5 + DEFAULT_SUCCESS_CODE(1, "请求成功"),
  6 + SESSION_TIME_OUT(2, "会话超时,请刷新令牌"),
  7 + USER_INVALID(4, "用户失效,请重新登录"),
  8 + SYS_ERROR(3, "已知系统错误"),
  9 + REQUEST_METHOD_ERROR(6, "请求方式错误"),
  10 + REQUEST_PATH_ERROR(7, "请求路径错误"),
  11 + UNKNOWN_SYS_ERROR(5, "未知系统错误");
  12 +
  13 + public int code;
  14 + public String message;
  15 +
  16 + public int getCode() {
  17 + return this.code;
  18 + }
  19 +
  20 + public String getMessage() {
  21 + return this.message;
  22 + }
  23 +
  24 + private MessageCode(int code, String message) {
  25 + this.code = code;
  26 + this.message = message;
  27 + }
  28 +}
  1 +package com.zhonglai.luhui.mqtt.dto;
  2 +
  3 +public interface MessageCodeType {
  4 + int getCode();
  5 +
  6 + String getMessage();
  7 +}
1 -package com.zhonglai.luhui.mqtt.dto;  
2 -  
3 -import lombok.Data;  
4 -  
5 -/**  
6 - * 服务器下发数据  
7 - */  
8 -@Data  
9 -public class PutDto {  
10 - private String data;  
11 -}  
  1 +package com.zhonglai.luhui.mqtt.dto.topic;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent;
  5 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  6 +import lombok.Data;
  7 +import lombok.experimental.Accessors;
  8 +
  9 +@Data
  10 +@Accessors(chain = true)
  11 +public class AddPostDto implements ServerDto {
  12 + private JSONObject data;
  13 + @Override
  14 + public ServerAgreementContent getServerAgreementContent() {
  15 + return null;
  16 + }
  17 +
  18 + @Override
  19 + public boolean isReplyMessage() {
  20 + return false;
  21 + }
  22 +}
  1 +package com.zhonglai.luhui.mqtt.dto.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent;
  4 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  5 +import lombok.Data;
  6 +import lombok.experimental.Accessors;
  7 +
  8 +@Data
  9 +@Accessors(chain = true)
  10 +public class AllPostDto implements ServerDto {
  11 + @Override
  12 + public ServerAgreementContent getServerAgreementContent() {
  13 + return null;
  14 + }
  15 +
  16 + @Override
  17 + public boolean isReplyMessage() {
  18 + return false;
  19 + }
  20 +}
  1 +package com.zhonglai.luhui.mqtt.dto.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent;
  4 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  5 +import lombok.Data;
  6 +import lombok.experimental.Accessors;
  7 +
  8 +@Data
  9 +@Accessors(chain = true)
  10 +public class DbDistributeDto implements ServerDto {
  11 + @Override
  12 + public ServerAgreementContent getServerAgreementContent() {
  13 + return null;
  14 + }
  15 +
  16 + @Override
  17 + public boolean isReplyMessage() {
  18 + return false;
  19 + }
  20 +}
  1 +package com.zhonglai.luhui.mqtt.dto.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent;
  4 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  5 +import lombok.Data;
  6 +import lombok.experimental.Accessors;
  7 +
  8 +@Data
  9 +@Accessors(chain = true)
  10 +public class GetDto implements ServerDto {
  11 + @Override
  12 + public ServerAgreementContent getServerAgreementContent() {
  13 + return null;
  14 + }
  15 +
  16 + @Override
  17 + public boolean isReplyMessage() {
  18 + return false;
  19 + }
  20 +}
  1 +package com.zhonglai.luhui.mqtt.dto.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent;
  4 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  5 +import lombok.Data;
  6 +import lombok.experimental.Accessors;
  7 +
  8 +@Data
  9 +@Accessors(chain = true)
  10 +public class GetReqDto implements ServerDto {
  11 + @Override
  12 + public ServerAgreementContent getServerAgreementContent() {
  13 + return null;
  14 + }
  15 +
  16 + @Override
  17 + public boolean isReplyMessage() {
  18 + return false;
  19 + }
  20 +}
  1 +package com.zhonglai.luhui.mqtt.dto.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent;
  4 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  5 +import lombok.Data;
  6 +import lombok.experimental.Accessors;
  7 +
  8 +@Data
  9 +@Accessors(chain = true)
  10 +public class OnlineDto implements ServerDto {
  11 + @Override
  12 + public ServerAgreementContent getServerAgreementContent() {
  13 + return null;
  14 + }
  15 +
  16 + @Override
  17 + public boolean isReplyMessage() {
  18 + return false;
  19 + }
  20 +}
  1 +package com.zhonglai.luhui.mqtt.dto.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent;
  4 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  5 +import lombok.Data;
  6 +import lombok.experimental.Accessors;
  7 +
  8 +/**
  9 + * 服务器下发数据
  10 + */
  11 +@Data
  12 +@Accessors(chain = true)
  13 +public class PutDto implements ServerDto {
  14 + private String data;
  15 +
  16 + @Override
  17 + public ServerAgreementContent getServerAgreementContent() {
  18 + return null;
  19 + }
  20 +
  21 + @Override
  22 + public boolean isReplyMessage() {
  23 + return false;
  24 + }
  25 +}
1 -package com.zhonglai.luhui.mqtt.dto; 1 +package com.zhonglai.luhui.mqtt.dto.topic;
2 2
3 -import com.google.gson.JsonObject;  
4 -import com.luhui.ly.comm.util.GsonConstructor;  
5 -import com.luhui.ly.device.mqtt.comm.dto.ServerAgreementContent;  
6 -import com.luhui.ly.device.mqtt.comm.dto.ServerDto;  
7 -import com.luhui.ly.device.mqtt.comm.factory.Topic;  
8 -import com.zhonglai.dto.Message;  
9 -import com.zhonglai.dto.MessageCode; 3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent;
  5 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  6 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  7 +import com.zhonglai.luhui.mqtt.dto.Message;
  8 +import com.zhonglai.luhui.mqtt.dto.MessageCode;
10 import lombok.Data; 9 import lombok.Data;
11 import lombok.experimental.Accessors; 10 import lombok.experimental.Accessors;
12 11
@@ -28,9 +27,9 @@ public class PutReqDto implements ServerDto { @@ -28,9 +27,9 @@ public class PutReqDto implements ServerDto {
28 27
29 @Override 28 @Override
30 public byte[] getCommd() { 29 public byte[] getCommd() {
31 - JsonObject jsonObject = GsonConstructor.get().fromJson(GsonConstructor.get().toJson(putReqDto), JsonObject.class); 30 + JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(putReqDto));
32 jsonObject.remove("messageid"); 31 jsonObject.remove("messageid");
33 - return GsonConstructor.get().toJson(jsonObject).getBytes(); 32 + return jsonObject.toJSONString().getBytes();
34 } 33 }
35 34
36 @Override 35 @Override
@@ -3,7 +3,7 @@ package com.zhonglai.luhui.mqtt.service; @@ -3,7 +3,7 @@ package com.zhonglai.luhui.mqtt.service;
3 import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; 3 import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
4 import com.zhonglai.luhui.mqtt.comm.factory.Topic; 4 import com.zhonglai.luhui.mqtt.comm.factory.Topic;
5 import com.zhonglai.luhui.mqtt.comm.service.CacheService; 5 import com.zhonglai.luhui.mqtt.comm.service.CacheService;
6 -import com.zhonglai.luhui.mqtt.dto.PutReqDto; 6 +import com.zhonglai.luhui.mqtt.dto.topic.PutReqDto;
7 import org.springframework.stereotype.Service; 7 import org.springframework.stereotype.Service;
8 8
9 @Service 9 @Service
  1 +package com.zhonglai.luhui.mqtt.service.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
  5 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  6 +import com.zhonglai.luhui.mqtt.dto.topic.AddPostDto;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +
  10 +/**
  11 + * 增量上报数据,不需要返回
  12 + */
  13 +@Service("ADD_POST")
  14 +public class AddPostTopic implements BusinessAgreement<AddPostDto> {
  15 +
  16 +
  17 + @Override
  18 + public ServerDto analysis(Topic topic, AddPostDto data) throws Exception {
  19 + return null;
  20 + }
  21 +
  22 + @Override
  23 + public AddPostDto toData(byte[] data) {
  24 + return null;
  25 + }
  26 +}
  1 +package com.zhonglai.luhui.mqtt.service.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
  5 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  6 +import com.zhonglai.luhui.mqtt.dto.topic.AllPostDto;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +/**
  10 + * 全量上报数据,不需要返回
  11 + */
  12 +@Service("ALL_POST")
  13 +public class AllPostTopic implements BusinessAgreement<AllPostDto> {
  14 + @Override
  15 + public ServerDto analysis(Topic topic, AllPostDto data) throws Exception {
  16 + return null;
  17 + }
  18 +
  19 + @Override
  20 + public AllPostDto toData(byte[] data) {
  21 + return null;
  22 + }
  23 +}
  1 +package com.zhonglai.luhui.mqtt.service.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
  5 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  6 +import com.zhonglai.luhui.mqtt.dto.topic.DbDistributeDto;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +/**
  10 + * 数据库topic分发
  11 + */
  12 +@Service("DB_TOPIC_DISTRIBUTE")
  13 +public class DbDistributeTopic implements BusinessAgreement<DbDistributeDto> {
  14 + @Override
  15 + public ServerDto analysis(Topic topic, DbDistributeDto data) throws Exception {
  16 + return null;
  17 + }
  18 +
  19 + @Override
  20 + public DbDistributeDto toData(byte[] data) {
  21 + return null;
  22 + }
  23 +}
  1 +package com.zhonglai.luhui.mqtt.service.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
  5 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  6 +import com.zhonglai.luhui.mqtt.dto.topic.GetReqDto;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +/**
  10 + * 获取数据的返回结果
  11 + */
  12 +@Service("GET_REQ")
  13 +public class GetReqTopic implements BusinessAgreement<GetReqDto> {
  14 + @Override
  15 + public ServerDto analysis(Topic topic, GetReqDto data) throws Exception {
  16 + return null;
  17 + }
  18 +
  19 + @Override
  20 + public GetReqDto toData(byte[] data) {
  21 + return null;
  22 + }
  23 +}
  1 +package com.zhonglai.luhui.mqtt.service.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
  5 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  6 +import com.zhonglai.luhui.mqtt.dto.topic.GetDto;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +/**
  10 + * 获取数据
  11 + */
  12 +@Service("GET")
  13 +public class GetTopic implements BusinessAgreement<GetDto> {
  14 + @Override
  15 + public ServerDto analysis(Topic topic, GetDto data) throws Exception {
  16 + return null;
  17 + }
  18 +
  19 + @Override
  20 + public GetDto toData(byte[] data) {
  21 + return null;
  22 + }
  23 +}
  1 +package com.zhonglai.luhui.mqtt.service.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
  5 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  6 +import com.zhonglai.luhui.mqtt.dto.topic.OnlineDto;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +
  10 +@Service("ONLINE")
  11 +public class OnlineTopic implements BusinessAgreement<OnlineDto> {
  12 + @Override
  13 + public ServerDto analysis(Topic topic, OnlineDto data) throws Exception {
  14 + return null;
  15 + }
  16 +
  17 + @Override
  18 + public OnlineDto toData(byte[] data) {
  19 + return null;
  20 + }
  21 +}
  1 +package com.zhonglai.luhui.mqtt.service.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
  5 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  6 +import com.zhonglai.luhui.mqtt.dto.topic.PutReqDto;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +/**
  10 + * 更新数据的执行结果
  11 + */
  12 +@Service("PUT_REQ")
  13 +public class PutReqTopic implements BusinessAgreement<PutReqDto> {
  14 + @Override
  15 + public ServerDto analysis(Topic topic, PutReqDto data) throws Exception {
  16 + return null;
  17 + }
  18 +
  19 + @Override
  20 + public PutReqDto toData(byte[] data) {
  21 + return null;
  22 + }
  23 +}
  1 +package com.zhonglai.luhui.mqtt.service.topic;
  2 +
  3 +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto;
  4 +import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement;
  5 +import com.zhonglai.luhui.mqtt.comm.factory.Topic;
  6 +import com.zhonglai.luhui.mqtt.dto.topic.PutDto;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +/**
  10 + * 更新数据,需要返回执行结果
  11 + */
  12 +@Service("PUT")
  13 +public class PutTopic implements BusinessAgreement<PutDto> {
  14 +
  15 + @Override
  16 + public ServerDto analysis(Topic topic, PutDto data) throws Exception {
  17 + return null;
  18 + }
  19 +
  20 + @Override
  21 + public PutDto toData(byte[] data) {
  22 + return null;
  23 + }
  24 +}
@@ -44,8 +44,8 @@ mqtt: @@ -44,8 +44,8 @@ mqtt:
44 #唯一标识 44 #唯一标识
45 clientId: lh-mqtt-service-001 45 clientId: lh-mqtt-service-001
46 #订阅的topic 46 #订阅的topic
47 - topics: "/2/2/X6/+/PUT_REQ"  
48 - topicconfig: "/{{roleid}}/{{userid}}/{{username}}/{{clientid}}/{{topicType}}" 47 + topics: "/2/#"
  48 + topicconfig: "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}"
49 username: sysuser 49 username: sysuser
50 password: "!@#1qaz" 50 password: "!@#1qaz"
51 client: 51 client:
@@ -61,4 +61,5 @@ mqtt: @@ -61,4 +61,5 @@ mqtt:
61 61
62 sys: 62 sys:
63 redis: 63 redis:
64 - field: "lh:mqtt:service:"  
  64 + field: "lh:mqtt:service:"
  65 +
@@ -60,12 +60,12 @@ public class SysLoginService @@ -60,12 +60,12 @@ public class SysLoginService
60 */ 60 */
61 public String login(String username, String password, String code, String uuid) 61 public String login(String username, String password, String code, String uuid)
62 { 62 {
63 - boolean captchaOnOff = configService.selectCaptchaOnOff();  
64 - // 验证码开关  
65 - if (captchaOnOff)  
66 - {  
67 - validateCaptcha(username, code, uuid);  
68 - } 63 +// boolean captchaOnOff = configService.selectCaptchaOnOff();
  64 +// // 验证码开关
  65 +// if (captchaOnOff)
  66 +// {
  67 +// validateCaptcha(username, code, uuid);
  68 +// }
69 // 用户验证 69 // 用户验证
70 Authentication authentication = null; 70 Authentication authentication = null;
71 try 71 try
@@ -106,7 +106,18 @@ public class IotDevice extends BaseEntity @@ -106,7 +106,18 @@ public class IotDevice extends BaseEntity
106 @ApiModelProperty("用户id") 106 @ApiModelProperty("用户id")
107 private Integer user_id; 107 private Integer user_id;
108 108
109 - public void setActive_time(Integer active_time) 109 + @ApiModelProperty("负载类型(String,Json,Bite16,Bite32)")
  110 + private String payload_type;
  111 +
  112 + public String getPayload_type() {
  113 + return payload_type;
  114 + }
  115 +
  116 + public void setPayload_type(String payload_type) {
  117 + this.payload_type = payload_type;
  118 + }
  119 +
  120 + public void setActive_time(Integer active_time)
110 { 121 {
111 this.active_time = active_time; 122 this.active_time = active_time;
112 } 123 }
@@ -28,10 +28,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -28,10 +28,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
28 <result property="update_by" column="update_by" /> 28 <result property="update_by" column="update_by" />
29 <result property="update_time" column="update_time" /> 29 <result property="update_time" column="update_time" />
30 <result property="user_id" column="user_id" /> 30 <result property="user_id" column="user_id" />
  31 + <result property="payload_type" column="payload_type" />
  32 +
31 </resultMap> 33 </resultMap>
32 34
33 <sql id="selectIotDeviceVo"> 35 <sql id="selectIotDeviceVo">
34 - select active_time, client_id, completion_auth, create_by, create_time, del_flag, firmware_version, img_url, is_shadow, latitude, location_way, longitude, name, network_address, network_ip, remark, rssi, status, summary, things_model_value, update_by, update_time, user_id from iot_device 36 + select active_time, client_id, completion_auth, create_by, create_time, del_flag, firmware_version, img_url, is_shadow, latitude, location_way, longitude, `name`, network_address, network_ip, remark, rssi, status, summary, things_model_value, update_by, update_time, user_id,payload_type from iot_device
35 </sql> 37 </sql>
36 38
37 <select id="selectIotDeviceList" parameterType="IotDevice" resultMap="IotDeviceResult"> 39 <select id="selectIotDeviceList" parameterType="IotDevice" resultMap="IotDeviceResult">
@@ -71,6 +73,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -71,6 +73,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
71 <if test="update_by != null">update_by,</if> 73 <if test="update_by != null">update_by,</if>
72 <if test="update_time != null">update_time,</if> 74 <if test="update_time != null">update_time,</if>
73 <if test="user_id != null">user_id,</if> 75 <if test="user_id != null">user_id,</if>
  76 + <if test="payload_type != null">payload_type,</if>
  77 +
74 </trim> 78 </trim>
75 <trim prefix="values (" suffix=")" suffixOverrides=","> 79 <trim prefix="values (" suffix=")" suffixOverrides=",">
76 <if test="active_time != null">#{active_time},</if> 80 <if test="active_time != null">#{active_time},</if>
@@ -96,6 +100,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -96,6 +100,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
96 <if test="update_by != null">#{update_by},</if> 100 <if test="update_by != null">#{update_by},</if>
97 <if test="update_time != null">#{update_time},</if> 101 <if test="update_time != null">#{update_time},</if>
98 <if test="user_id != null">#{user_id},</if> 102 <if test="user_id != null">#{user_id},</if>
  103 + <if test="payload_type != null">#{payload_type},</if>
99 </trim> 104 </trim>
100 </insert> 105 </insert>
101 106
@@ -124,6 +129,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -124,6 +129,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
124 <if test="update_by != null">update_by = #{update_by},</if> 129 <if test="update_by != null">update_by = #{update_by},</if>
125 <if test="update_time != null">update_time = #{update_time},</if> 130 <if test="update_time != null">update_time = #{update_time},</if>
126 <if test="user_id != null">user_id = #{user_id},</if> 131 <if test="user_id != null">user_id = #{user_id},</if>
  132 + <if test="payload_type != null">user_id = #{payload_type},</if>
127 </trim> 133 </trim>
128 where client_id = #{client_id} 134 where client_id = #{client_id}
129 </update> 135 </update>