正在显示
42 个修改的文件
包含
820 行增加
和
84 行删除
| 1 | -driverClassName=com.mysql.jdbc.Driver | 1 | +driverClassName=com.mysql.cj.jdbc.Driver |
| 2 | url=jdbc:mysql://rm-wz9740un21f09iokuao.mysql.rds.aliyuncs.com:3306/mqtt_broker?useUnicode=true&characterEncoding=utf8&autoReconnect=true | 2 | url=jdbc:mysql://rm-wz9740un21f09iokuao.mysql.rds.aliyuncs.com:3306/mqtt_broker?useUnicode=true&characterEncoding=utf8&autoReconnect=true |
| 3 | username=luhui | 3 | username=luhui |
| 4 | password=Luhui586 | 4 | password=Luhui586 |
| @@ -125,6 +125,7 @@ | @@ -125,6 +125,7 @@ | ||
| 125 | <groupId>com.squareup.okhttp3</groupId> | 125 | <groupId>com.squareup.okhttp3</groupId> |
| 126 | <artifactId>okhttp</artifactId> | 126 | <artifactId>okhttp</artifactId> |
| 127 | </dependency> | 127 | </dependency> |
| 128 | + | ||
| 128 | </dependencies> | 129 | </dependencies> |
| 129 | 130 | ||
| 130 | <build> | 131 | <build> |
| @@ -12,7 +12,6 @@ import org.springframework.context.annotation.ComponentScan; | @@ -12,7 +12,6 @@ import org.springframework.context.annotation.ComponentScan; | ||
| 12 | "com.zhonglai.luhui.mqtt.comm.agreement", | 12 | "com.zhonglai.luhui.mqtt.comm.agreement", |
| 13 | "com.zhonglai.luhui.mqtt.comm.service", | 13 | "com.zhonglai.luhui.mqtt.comm.service", |
| 14 | "com.zhonglai.luhui.mqtt.config", | 14 | "com.zhonglai.luhui.mqtt.config", |
| 15 | - "com.zhonglai.luhui.mqtt.agreement", | ||
| 16 | "com.zhonglai.luhui.mqtt.service", | 15 | "com.zhonglai.luhui.mqtt.service", |
| 17 | "com.zhonglai.luhui.mqtt.controller", | 16 | "com.zhonglai.luhui.mqtt.controller", |
| 18 | }) | 17 | }) |
| 1 | package com.zhonglai.luhui.mqtt.comm.agreement; | 1 | package com.zhonglai.luhui.mqtt.comm.agreement; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | -import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; | ||
| 5 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; | 4 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; |
| 6 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreementFactory; | 5 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreementFactory; |
| 7 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; | 6 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; |
| 8 | -import com.zhonglai.luhui.mqtt.comm.util.StringUtils; | ||
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.stereotype.Component; | 8 | import org.springframework.stereotype.Component; |
| 11 | 9 | ||
| @@ -19,8 +17,9 @@ public class BusinessAgreementFactoryImpl implements BusinessAgreementFactory { | @@ -19,8 +17,9 @@ public class BusinessAgreementFactoryImpl implements BusinessAgreementFactory { | ||
| 19 | @Autowired | 17 | @Autowired |
| 20 | private Map<String, BusinessAgreement> businessAgreementMap; | 18 | private Map<String, BusinessAgreement> businessAgreementMap; |
| 21 | 19 | ||
| 20 | + | ||
| 22 | @Override | 21 | @Override |
| 23 | - public BusinessAgreement createBusinessAgreement(Topic topic, BusinessDto businessDto) { | 22 | + public BusinessAgreement createBusinessAgreement(Topic topic) { |
| 24 | BusinessAgreement businessAgreement = businessAgreementMap.get(topic.getTopicType().toUpperCase()); | 23 | BusinessAgreement businessAgreement = businessAgreementMap.get(topic.getTopicType().toUpperCase()); |
| 25 | if(null == businessAgreement) //没有找到就用默认的 | 24 | if(null == businessAgreement) //没有找到就用默认的 |
| 26 | { | 25 | { |
| @@ -29,12 +28,4 @@ public class BusinessAgreementFactoryImpl implements BusinessAgreementFactory { | @@ -29,12 +28,4 @@ public class BusinessAgreementFactoryImpl implements BusinessAgreementFactory { | ||
| 29 | return businessAgreement; | 28 | return businessAgreement; |
| 30 | } | 29 | } |
| 31 | 30 | ||
| 32 | - public void toBusinessDto(String payloadtype,byte[] data) | ||
| 33 | - { | ||
| 34 | - if(StringUtils.isBlank(payloadtype)) | ||
| 35 | - { | ||
| 36 | - payloadtype = "String"; | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - } | ||
| 40 | } | 31 | } |
| 1 | package com.zhonglai.luhui.mqtt.comm.agreement; | 1 | package com.zhonglai.luhui.mqtt.comm.agreement; |
| 2 | 2 | ||
| 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.dto.business.BusinessDto; | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; | 5 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; |
| 5 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; | 6 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; |
| 6 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
| @@ -20,7 +21,8 @@ public class DefaultAgreement implements BusinessAgreement<byte[]> { | @@ -20,7 +21,8 @@ public class DefaultAgreement implements BusinessAgreement<byte[]> { | ||
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | @Override | 23 | @Override |
| 23 | - public byte[] toData(byte[] data) { | ||
| 24 | - return data; | 24 | + public ServerDto toData(BusinessDto data) { |
| 25 | + return null; | ||
| 25 | } | 26 | } |
| 27 | + | ||
| 26 | } | 28 | } |
| @@ -148,7 +148,7 @@ public class BaseDao { | @@ -148,7 +148,7 @@ public class BaseDao { | ||
| 148 | { | 148 | { |
| 149 | attributeStr += ","; | 149 | attributeStr += ","; |
| 150 | } | 150 | } |
| 151 | - attributeStr += "`"+changTableNameFromObject(field.getName())+"`"; | 151 | + attributeStr += "`"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.toUnderScoreCase(field.getName())+"`"; |
| 152 | } | 152 | } |
| 153 | attributeStr += ")"; | 153 | attributeStr += ")"; |
| 154 | return attributeStr; | 154 | return attributeStr; |
| @@ -769,13 +769,12 @@ public class BaseDao { | @@ -769,13 +769,12 @@ public class BaseDao { | ||
| 769 | values += ","; | 769 | values += ","; |
| 770 | update += ","; | 770 | update += ","; |
| 771 | } | 771 | } |
| 772 | - sql += "`"+changTableNameFromObject(field.getName())+"`"; | 772 | + sql += "`"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.toUnderScoreCase(field.getName())+"`"; |
| 773 | values += "'"+ value+"'"; | 773 | values += "'"+ value+"'"; |
| 774 | - update += "`"+changTableNameFromObject(field.getName())+"`"+"=VALUES("+"`"+changTableNameFromObject(field.getName())+"`)"; | 774 | + update += "`"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.toUnderScoreCase(field.getName())+"`"+"=VALUES("+"`"+com.zhonglai.luhui.mqtt.comm.util.StringUtils.toUnderScoreCase(field.getName())+"`)"; |
| 775 | } | 775 | } |
| 776 | } catch (NoSuchMethodException e) { | 776 | } catch (NoSuchMethodException e) { |
| 777 | - // TODO Auto-generated catch block | ||
| 778 | - e.printStackTrace(); | 777 | + System.out.println("未找到"+field.getName()+"的get方法"); |
| 779 | } catch (SecurityException e) { | 778 | } catch (SecurityException e) { |
| 780 | // TODO Auto-generated catch block | 779 | // TODO Auto-generated catch block |
| 781 | e.printStackTrace(); | 780 | e.printStackTrace(); |
| @@ -938,7 +937,7 @@ public class BaseDao { | @@ -938,7 +937,7 @@ public class BaseDao { | ||
| 938 | tableNmae = (String) tObject; | 937 | tableNmae = (String) tObject; |
| 939 | } | 938 | } |
| 940 | } catch (NoSuchMethodException e) { | 939 | } catch (NoSuchMethodException e) { |
| 941 | - e.printStackTrace(); | 940 | + System.out.println("未找到getTableName"); |
| 942 | } catch (IllegalAccessException e) { | 941 | } catch (IllegalAccessException e) { |
| 943 | e.printStackTrace(); | 942 | e.printStackTrace(); |
| 944 | } catch (InvocationTargetException e) { | 943 | } catch (InvocationTargetException e) { |
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +@Data | ||
| 6 | +public class DeviceSensorData { | ||
| 7 | + private String deviceInfoId; //设备信息id | ||
| 8 | + private String dataType; //数据类型 | ||
| 9 | + private String dataValue; //L数据值 | ||
| 10 | + private Integer creatTime; //创建时间 | ||
| 11 | + private String deviceModel; // VARCHAR(10) NOT NULL COMMENT '设备型号,(3,5,6)', | ||
| 12 | +} |
| 1 | package com.zhonglai.luhui.mqtt.comm.dto.business; | 1 | package com.zhonglai.luhui.mqtt.comm.dto.business; |
| 2 | 2 | ||
| 3 | -import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | ||
| 4 | 3 | ||
| 5 | public interface BusinessDto { | 4 | public interface BusinessDto { |
| 6 | BusinessDto analyticalModel(String modeData); | 5 | BusinessDto analyticalModel(String modeData); |
| 7 | - ServerDto toServerDto(); | 6 | + Object getContentData(); |
| 8 | } | 7 | } |
| 1 | package com.zhonglai.luhui.mqtt.comm.dto.business; | 1 | package com.zhonglai.luhui.mqtt.comm.dto.business; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | ||
| 4 | import lombok.Data; | 5 | import lombok.Data; |
| 5 | import org.apache.commons.lang3.ArrayUtils; | 6 | import org.apache.commons.lang3.ArrayUtils; |
| 6 | 7 | ||
| 8 | +import javax.script.*; | ||
| 9 | + | ||
| 7 | /** | 10 | /** |
| 8 | * 字节payload内容协议 | 11 | * 字节payload内容协议 |
| 9 | */ | 12 | */ |
| @@ -12,7 +15,7 @@ public class ByteBusinessDto implements BusinessDto{ | @@ -12,7 +15,7 @@ public class ByteBusinessDto implements BusinessDto{ | ||
| 12 | private int functionCode; //功能码 | 15 | private int functionCode; //功能码 |
| 13 | private int verification; //校验码 | 16 | private int verification; //校验码 |
| 14 | private byte[] data; //数据 | 17 | private byte[] data; //数据 |
| 15 | - | 18 | + private int datalength; //数据长度 |
| 16 | private byte[] srcData; // 原始数据 | 19 | private byte[] srcData; // 原始数据 |
| 17 | 20 | ||
| 18 | public ByteBusinessDto(byte[] data ) | 21 | public ByteBusinessDto(byte[] data ) |
| @@ -22,6 +25,24 @@ public class ByteBusinessDto implements BusinessDto{ | @@ -22,6 +25,24 @@ public class ByteBusinessDto implements BusinessDto{ | ||
| 22 | 25 | ||
| 23 | @Override | 26 | @Override |
| 24 | public BusinessDto analyticalModel(String modeData) { | 27 | public BusinessDto analyticalModel(String modeData) { |
| 28 | + ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript"); | ||
| 29 | + try { | ||
| 30 | + engine.eval(modeData); | ||
| 31 | + if (engine instanceof Invocable) { | ||
| 32 | + Invocable invoke = (Invocable) engine; | ||
| 33 | + functionCode = (int) invoke.invokeFunction("getFunctionCode", srcData); | ||
| 34 | + verification = (int) invoke.invokeFunction("getVerification", srcData); | ||
| 35 | + data = (byte[]) invoke.invokeFunction("getData", srcData); | ||
| 36 | + datalength = (int) invoke.invokeFunction("getDatalength", srcData); | ||
| 37 | + } else { | ||
| 38 | + System.out.println("error"); | ||
| 39 | + } | ||
| 40 | + } catch (ScriptException e) { | ||
| 41 | + System.out.println("表达式runtime错误:" + e.getMessage()); | ||
| 42 | + } catch (NoSuchMethodException e) { | ||
| 43 | + e.printStackTrace(); | ||
| 44 | + } | ||
| 45 | + | ||
| 25 | Mode mode = JSONObject.parseObject(modeData,Mode.class); | 46 | Mode mode = JSONObject.parseObject(modeData,Mode.class); |
| 26 | this.functionCode = srcData[mode.functionCodeAdr]; | 47 | this.functionCode = srcData[mode.functionCodeAdr]; |
| 27 | this.verification = srcData[mode.verificationAdr]; | 48 | this.verification = srcData[mode.verificationAdr]; |
| @@ -29,6 +50,11 @@ public class ByteBusinessDto implements BusinessDto{ | @@ -29,6 +50,11 @@ public class ByteBusinessDto implements BusinessDto{ | ||
| 29 | return this; | 50 | return this; |
| 30 | } | 51 | } |
| 31 | 52 | ||
| 53 | + @Override | ||
| 54 | + public Object getContentData() { | ||
| 55 | + return data; | ||
| 56 | + } | ||
| 57 | + | ||
| 32 | @Data | 58 | @Data |
| 33 | class Mode | 59 | class Mode |
| 34 | { | 60 | { |
| @@ -37,4 +63,29 @@ public class ByteBusinessDto implements BusinessDto{ | @@ -37,4 +63,29 @@ public class ByteBusinessDto implements BusinessDto{ | ||
| 37 | int functionCodeAdr; //功能码地址 | 63 | int functionCodeAdr; //功能码地址 |
| 38 | int verificationAdr; //校验码地址 | 64 | int verificationAdr; //校验码地址 |
| 39 | } | 65 | } |
| 66 | + | ||
| 67 | + public static void main(String[] args) throws ScriptException, NoSuchMethodException { | ||
| 68 | + String regular = "function hexToString(str){\n" + | ||
| 69 | + " var arr = str.split(\",\");\n" + | ||
| 70 | + " \t\tvar val;\n" + | ||
| 71 | + " for(var i = 0; i < arr.length; i++){\n" + | ||
| 72 | + " val[i] = arr[i].fromCharCode(i);\n" + | ||
| 73 | + " }\n" + | ||
| 74 | + " return val;\n" + | ||
| 75 | + "}"; | ||
| 76 | + ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript"); | ||
| 77 | + try { | ||
| 78 | + engine.eval(regular); | ||
| 79 | + if (engine instanceof Invocable) { | ||
| 80 | + Invocable invoke = (Invocable) engine; | ||
| 81 | + String result = invoke.invokeFunction("hexToString", "01,03,70,02,00,01,3F,0A").toString(); | ||
| 82 | + System.out.println(result); | ||
| 83 | + } else { | ||
| 84 | + System.out.println("error"); | ||
| 85 | + } | ||
| 86 | + } catch (ScriptException e) { | ||
| 87 | + System.out.println("表达式runtime错误:" + e.getMessage()); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + | ||
| 40 | } | 91 | } |
| @@ -30,8 +30,7 @@ public class JsonBusinessDto implements BusinessDto{ | @@ -30,8 +30,7 @@ public class JsonBusinessDto implements BusinessDto{ | ||
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | @Override | 32 | @Override |
| 33 | - public ServerDto toServerDto() { | ||
| 34 | - | ||
| 35 | - return null; | 33 | + public Object getContentData() { |
| 34 | + return data; | ||
| 36 | } | 35 | } |
| 37 | } | 36 | } |
| 1 | package com.zhonglai.luhui.mqtt.comm.dto.business; | 1 | package com.zhonglai.luhui.mqtt.comm.dto.business; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | ||
| 3 | import lombok.Data; | 4 | import lombok.Data; |
| 4 | 5 | ||
| 5 | /** | 6 | /** |
| @@ -17,4 +18,9 @@ public class StringBusinessDto implements BusinessDto{ | @@ -17,4 +18,9 @@ public class StringBusinessDto implements BusinessDto{ | ||
| 17 | public BusinessDto analyticalModel(String modeData) { | 18 | public BusinessDto analyticalModel(String modeData) { |
| 18 | return this; | 19 | return this; |
| 19 | } | 20 | } |
| 21 | + | ||
| 22 | + @Override | ||
| 23 | + public Object getContentData() { | ||
| 24 | + return srcData; | ||
| 25 | + } | ||
| 20 | } | 26 | } |
| @@ -5,6 +5,9 @@ import io.swagger.annotations.ApiModelProperty; | @@ -5,6 +5,9 @@ import io.swagger.annotations.ApiModelProperty; | ||
| 5 | import org.apache.commons.lang3.builder.ToStringBuilder; | 5 | import org.apache.commons.lang3.builder.ToStringBuilder; |
| 6 | import org.apache.commons.lang3.builder.ToStringStyle; | 6 | import org.apache.commons.lang3.builder.ToStringStyle; |
| 7 | 7 | ||
| 8 | +import java.util.List; | ||
| 9 | +import java.util.Map; | ||
| 10 | + | ||
| 8 | /** | 11 | /** |
| 9 | * 主机/网关对象 iot_device | 12 | * 主机/网关对象 iot_device |
| 10 | * | 13 | * |
| @@ -107,7 +110,6 @@ public class IotDevice | @@ -107,7 +110,6 @@ public class IotDevice | ||
| 107 | @ApiModelProperty("负载类型(String,Json,Bite16,Bite32)") | 110 | @ApiModelProperty("负载类型(String,Json,Bite16,Bite32)") |
| 108 | private String payload_type; | 111 | private String payload_type; |
| 109 | @ApiModelProperty("payload 协议模型") | 112 | @ApiModelProperty("payload 协议模型") |
| 110 | - | ||
| 111 | private String business_model; //payload 协议模型 | 113 | private String business_model; //payload 协议模型 |
| 112 | 114 | ||
| 113 | public String getBusiness_model() { | 115 | public String getBusiness_model() { |
| @@ -76,6 +76,18 @@ public class IotThingsModel | @@ -76,6 +76,18 @@ public class IotThingsModel | ||
| 76 | @ApiModelProperty("用户id") | 76 | @ApiModelProperty("用户id") |
| 77 | private Integer user_id; | 77 | private Integer user_id; |
| 78 | 78 | ||
| 79 | + /** 用户id */ | ||
| 80 | + @ApiModelProperty("用户名称") | ||
| 81 | + private Integer user_name; | ||
| 82 | + | ||
| 83 | + public Integer getUser_name() { | ||
| 84 | + return user_name; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public void setUser_name(Integer user_name) { | ||
| 88 | + this.user_name = user_name; | ||
| 89 | + } | ||
| 90 | + | ||
| 79 | public void setCreate_by(String create_by) | 91 | public void setCreate_by(String create_by) |
| 80 | { | 92 | { |
| 81 | this.create_by = create_by; | 93 | this.create_by = create_by; |
lh-mqtt-service/src/main/java/com/zhonglai/luhui/mqtt/comm/dto/thingsmodels/EventDto.java
0 → 100644
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 事件物模型 | ||
| 8 | + */ | ||
| 9 | +@Data | ||
| 10 | +public class EventDto { | ||
| 11 | + /** 物模型唯一标识符 */ | ||
| 12 | + private String id; | ||
| 13 | + /** 物模型名称 */ | ||
| 14 | + private String name; | ||
| 15 | + /** 数据定义 */ | ||
| 16 | + private JSONObject datatype; | ||
| 17 | +} |
lh-mqtt-service/src/main/java/com/zhonglai/luhui/mqtt/comm/dto/thingsmodels/FunctionDto.java
0 → 100644
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 功能物模型 | ||
| 8 | + */ | ||
| 9 | +@Data | ||
| 10 | +public class FunctionDto { | ||
| 11 | + /** 物模型唯一标识符 */ | ||
| 12 | + private String id; | ||
| 13 | + /** 物模型名称 */ | ||
| 14 | + private String name; | ||
| 15 | + /** 是否首页显示(0-否,1-是) */ | ||
| 16 | + private Integer isTop; | ||
| 17 | + /** 数据定义 */ | ||
| 18 | + private JSONObject datatype; | ||
| 19 | +} |
lh-mqtt-service/src/main/java/com/zhonglai/luhui/mqtt/comm/dto/thingsmodels/PropertyDto.java
0 → 100644
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 属性物模型 | ||
| 8 | + */ | ||
| 9 | +@Data | ||
| 10 | +public class PropertyDto { | ||
| 11 | + /** 物模型唯一标识符 */ | ||
| 12 | + private String id; | ||
| 13 | + /** 物模型名称 */ | ||
| 14 | + private String name; | ||
| 15 | + /** 是否首页显示(0-否,1-是) */ | ||
| 16 | + private Integer isTop; | ||
| 17 | + /** 是否实时监测(0-否,1-是) */ | ||
| 18 | + private Integer isMonitor; | ||
| 19 | + /** 数据定义 */ | ||
| 20 | + private JSONObject datatype; | ||
| 21 | +} |
lh-mqtt-service/src/main/java/com/zhonglai/luhui/mqtt/comm/dto/thingsmodels/ThingsModelBase.java
0 → 100644
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 物模型工厂 | ||
| 7 | + */ | ||
| 8 | +public interface ThingsModelBase<T> { | ||
| 9 | + void conversionThingsModel(IotThingsModel thingsModel); | ||
| 10 | + void addValue(T t); | ||
| 11 | + String getView(); | ||
| 12 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs.*; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 物模型数据类型,及对应显示解析方案 | ||
| 8 | + */ | ||
| 9 | +public enum ThingsModelDataTypeEnum { | ||
| 10 | + INTEGER(IntegerModelOutput.class), | ||
| 11 | + DECIMAL(DecimalModelOutput.class), | ||
| 12 | + STRING(StringModelOutput.class), | ||
| 13 | + BOOL(BoolModelOutput.class), | ||
| 14 | + ARRAY(ArrayModelOutput.class), | ||
| 15 | + ENUM(EnumModelOutput.class); | ||
| 16 | + | ||
| 17 | + private Class aClass; | ||
| 18 | + ThingsModelDataTypeEnum(Class aClass) { | ||
| 19 | + this.aClass = aClass; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public Class getaClass() { | ||
| 23 | + return aClass; | ||
| 24 | + } | ||
| 25 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItem; | ||
| 2 | + | ||
| 3 | +import java.math.BigDecimal; | ||
| 4 | + | ||
| 5 | +public class ReadOnlyModelOutput | ||
| 6 | +{ | ||
| 7 | + private BigDecimal min; | ||
| 8 | + private BigDecimal max; | ||
| 9 | + private BigDecimal step; | ||
| 10 | + private String unit; | ||
| 11 | + private String arrayType; | ||
| 12 | + private String falseText; | ||
| 13 | + private String trueText; | ||
| 14 | + private int maxLength; | ||
| 15 | +} |
lh-mqtt-service/src/main/java/com/zhonglai/luhui/mqtt/comm/dto/thingsmodels/ThingsModelItemBase.java
0 → 100644
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 物模型工厂的公用方法 | ||
| 8 | + * @param <T> | ||
| 9 | + */ | ||
| 10 | +@Data | ||
| 11 | +public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> | ||
| 12 | +{ | ||
| 13 | + /** 物模型唯一标识符 */ | ||
| 14 | + private String id; | ||
| 15 | + /** 物模型名称 */ | ||
| 16 | + private String name; | ||
| 17 | + /** 物模型值 */ | ||
| 18 | + private T value; | ||
| 19 | + /** 是否首页显示(0-否,1-是) */ | ||
| 20 | + private Integer isTop; | ||
| 21 | + /** 是否实时监测(0-否,1-是) */ | ||
| 22 | + private Integer isMonitor; | ||
| 23 | + /** 数据类型 */ | ||
| 24 | + private String type; | ||
| 25 | + /** 是否记录日志(0否,1是) */ | ||
| 26 | + private Integer is_save_log; | ||
| 27 | + /** 模型类别(1-属性,2-功能,3-事件) */ | ||
| 28 | + private Integer mode_type; | ||
| 29 | + | ||
| 30 | + public void conversionThingsModel(IotThingsModel thingsModel) | ||
| 31 | + { | ||
| 32 | + id = thingsModel.getIdentifier(); | ||
| 33 | + name = thingsModel.getModel_name(); | ||
| 34 | + isTop = thingsModel.getIs_top(); | ||
| 35 | + isMonitor = thingsModel.getIs_monitor(); | ||
| 36 | + type = thingsModel.getData_type(); | ||
| 37 | + is_save_log = thingsModel.getIs_save_log(); | ||
| 38 | + mode_type = thingsModel.getType(); | ||
| 39 | + } | ||
| 40 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONArray; | ||
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +@Data | ||
| 8 | +public class ArrayModelOutput extends ThingsModelItemBase<JSONArray> | ||
| 9 | +{ | ||
| 10 | + private String arrayType; | ||
| 11 | + | ||
| 12 | + @Override | ||
| 13 | + public void addValue(JSONArray jsonArray) { | ||
| 14 | + setValue(jsonArray); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + @Override | ||
| 18 | + public String getView() { | ||
| 19 | + if(null != getValue()) | ||
| 20 | + { | ||
| 21 | + return JSONArray.toJSONString(getValue()); | ||
| 22 | + } | ||
| 23 | + return ""; | ||
| 24 | + } | ||
| 25 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +@Data | ||
| 7 | +public class BoolModelOutput extends ThingsModelItemBase<Boolean> | ||
| 8 | +{ | ||
| 9 | + private String falseText; | ||
| 10 | + private String trueText; | ||
| 11 | + | ||
| 12 | + @Override | ||
| 13 | + public void addValue(Boolean bl) { | ||
| 14 | + setValue( bl); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + @Override | ||
| 18 | + public String getView() { | ||
| 19 | + if(getValue()) | ||
| 20 | + { | ||
| 21 | + return trueText; | ||
| 22 | + }else { | ||
| 23 | + return falseText; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + } | ||
| 27 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +import java.math.BigDecimal; | ||
| 7 | + | ||
| 8 | +@Data | ||
| 9 | +public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal> | ||
| 10 | +{ | ||
| 11 | + private BigDecimal min; | ||
| 12 | + private BigDecimal max; | ||
| 13 | + private BigDecimal step; | ||
| 14 | + private String unit; | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + public void addValue(BigDecimal object) { | ||
| 18 | + setValue(object); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + public String getView() { | ||
| 23 | + return getView()+unit; | ||
| 24 | + } | ||
| 25 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.EnumItemOutput; | ||
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +@Data | ||
| 10 | +public class EnumModelOutput extends ThingsModelItemBase<String> | ||
| 11 | +{ | ||
| 12 | + private List<EnumItemOutput> enumList; | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public void addValue(String object) { | ||
| 16 | + setValue(object); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public String getView() { | ||
| 21 | + for(EnumItemOutput enumItemOutput:enumList) | ||
| 22 | + { | ||
| 23 | + if(enumItemOutput.getValue().equals(getValue())) | ||
| 24 | + { | ||
| 25 | + return enumItemOutput.getText(); | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | + return getValue(); | ||
| 29 | + } | ||
| 30 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +import java.math.BigDecimal; | ||
| 7 | + | ||
| 8 | +@Data | ||
| 9 | +public class IntegerModelOutput extends ThingsModelItemBase<Integer> | ||
| 10 | +{ | ||
| 11 | + private BigDecimal min; | ||
| 12 | + private BigDecimal max; | ||
| 13 | + private BigDecimal step; | ||
| 14 | + private String unit; | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + public void addValue(Integer object) { | ||
| 18 | + setValue(object); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + public String getView() { | ||
| 23 | + return getView()+unit; | ||
| 24 | + } | ||
| 25 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 字符串可以适配所有 | ||
| 8 | + */ | ||
| 9 | +@Data | ||
| 10 | +public class StringModelOutput extends ThingsModelItemBase<Object> | ||
| 11 | +{ | ||
| 12 | + private int maxLength; | ||
| 13 | + | ||
| 14 | + @Override | ||
| 15 | + public void addValue(Object object) { | ||
| 16 | + setValue(null!=getValue()?getValue()+"":null); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public String getView() { | ||
| 21 | + return null!=getValue()?getValue()+"":null; | ||
| 22 | + } | ||
| 23 | +} |
| @@ -2,10 +2,12 @@ package com.zhonglai.luhui.mqtt.comm.factory; | @@ -2,10 +2,12 @@ package com.zhonglai.luhui.mqtt.comm.factory; | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 5 | +import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; | ||
| 5 | 6 | ||
| 6 | /** | 7 | /** |
| 7 | * mqtt业务协议 | 8 | * mqtt业务协议 |
| 8 | */ | 9 | */ |
| 9 | public interface BusinessAgreement<T> { | 10 | public interface BusinessAgreement<T> { |
| 10 | ServerDto analysis(Topic topic, T data) throws Exception; //解析协议 | 11 | ServerDto analysis(Topic topic, T data) throws Exception; //解析协议 |
| 12 | + ServerDto toData(BusinessDto data); | ||
| 11 | } | 13 | } |
| @@ -27,14 +27,14 @@ public class Topic { | @@ -27,14 +27,14 @@ public class Topic { | ||
| 27 | topic = Optional.ofNullable(topic).orElseThrow(()->new MyException("topic为空")); | 27 | topic = Optional.ofNullable(topic).orElseThrow(()->new MyException("topic为空")); |
| 28 | String[] sts = topic.split("/"); | 28 | String[] sts = topic.split("/"); |
| 29 | String[] config = SysParameter.topicconfig.split("/"); | 29 | String[] config = SysParameter.topicconfig.split("/"); |
| 30 | - for(int i=0;i<config.length;i++) | 30 | + for(int i=1;i<config.length;i++) |
| 31 | { | 31 | { |
| 32 | String cf = config[i].replace("{{","").replace("}}",""); | 32 | String cf = config[i].replace("{{","").replace("}}",""); |
| 33 | try { | 33 | try { |
| 34 | - Field field = this.getClass().getField(cf); | 34 | + Field field = this.getClass().getDeclaredField(cf); |
| 35 | field.set(this,sts[i]); | 35 | field.set(this,sts[i]); |
| 36 | } catch (NoSuchFieldException e) { | 36 | } catch (NoSuchFieldException e) { |
| 37 | - log.info("{}生成topic时没有属性",topic,cf); | 37 | + log.info("{}生成topic时没有属性{}",topic,cf); |
| 38 | } catch (IllegalAccessException e) { | 38 | } catch (IllegalAccessException e) { |
| 39 | log.info("{}生成topic时无法给{}赋值{}",topic,cf,sts[i]); | 39 | log.info("{}生成topic时无法给{}赋值{}",topic,cf,sts[i]); |
| 40 | } | 40 | } |
lh-mqtt-service/src/main/java/com/zhonglai/luhui/mqtt/comm/service/BusinessDataUpdateService.java
0 → 100644
| 1 | +package com.zhonglai.luhui.mqtt.comm.service; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 5 | +import com.zhonglai.luhui.mqtt.comm.dto.iot.IotDevice; | ||
| 6 | +import com.zhonglai.luhui.mqtt.comm.dto.iot.IotTerminal; | ||
| 7 | +import com.zhonglai.luhui.mqtt.comm.factory.Topic; | ||
| 8 | +import com.zhonglai.luhui.mqtt.comm.util.DateUtils; | ||
| 9 | +import com.zhonglai.luhui.mqtt.dto.topic.AddPostDto; | ||
| 10 | +import com.zhonglai.luhui.mqtt.service.db.DeviceService; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.stereotype.Service; | ||
| 13 | + | ||
| 14 | +import java.util.ArrayList; | ||
| 15 | +import java.util.List; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * 业务数据更新服务 | ||
| 19 | + */ | ||
| 20 | +@Service | ||
| 21 | +public class BusinessDataUpdateService { | ||
| 22 | + @Autowired | ||
| 23 | + private DataModeAnalysisService dataModeAnalysisService ; | ||
| 24 | + @Autowired | ||
| 25 | + private DeviceLogService deviceLogService ; | ||
| 26 | + @Autowired | ||
| 27 | + private DeviceService deviceService ; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 更新数据 | ||
| 31 | + * @param type | ||
| 32 | + * @param topic | ||
| 33 | + * @param data | ||
| 34 | + */ | ||
| 35 | + public void updataDta(Type type,Topic topic, JSONObject data) | ||
| 36 | + { | ||
| 37 | + List<LogDeviceOperation> operateHisList = new ArrayList<>(); | ||
| 38 | + for(String key:data.keySet()) | ||
| 39 | + { | ||
| 40 | + Object o = data.get(key); | ||
| 41 | + if(o instanceof JSONObject) | ||
| 42 | + { | ||
| 43 | + JSONObject jsData = data.getJSONObject(key); | ||
| 44 | + if("0".equals(key)) //主机 | ||
| 45 | + { | ||
| 46 | + IotDevice iotDevice = translateDevice(type,topic,jsData,operateHisList); | ||
| 47 | + deviceService.updataDevice(iotDevice); | ||
| 48 | + | ||
| 49 | + }else{ //终端 | ||
| 50 | + IotTerminal iotTerminal = translateTerminal(type,key,topic,jsData,operateHisList); | ||
| 51 | + deviceService.updataTerminal(iotTerminal); | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + if(null != operateHisList && operateHisList.size() !=0 ) | ||
| 57 | + { | ||
| 58 | + deviceLogService.saveOperationLog(operateHisList); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 更新网关 | ||
| 64 | + * @param type | ||
| 65 | + * @param topic | ||
| 66 | + * @param jsData | ||
| 67 | + * @param operateHisList | ||
| 68 | + * @return | ||
| 69 | + */ | ||
| 70 | + private IotDevice translateDevice(Type type,Topic topic , JSONObject jsData, List<LogDeviceOperation> operateHisList) | ||
| 71 | + { | ||
| 72 | + IotDevice olddevice = deviceService.getRedicDevice(topic.getClientid()); | ||
| 73 | + JSONObject summaryObjec = null; | ||
| 74 | + if(jsData.containsKey("summary") && null != jsData.get("summary") && jsData.get("summary") instanceof JSONObject) | ||
| 75 | + { | ||
| 76 | + summaryObjec = jsData.getJSONObject("summary"); | ||
| 77 | + //记录summary内容变更日志 | ||
| 78 | + operateHisList.add(deviceLogService.newLogDeviceOperation(topic.getClientid(),summaryObjec.toString(),olddevice.getSummary(),"主机本地summary状态更新",jsData.toJSONString())); | ||
| 79 | + jsData.remove("summary"); | ||
| 80 | + } | ||
| 81 | + IotDevice device = JSONObject.parseObject(JSONObject.toJSONString(jsData),IotDevice.class); | ||
| 82 | + device.setClient_id(topic.getClientid()); | ||
| 83 | + device.setUpdate_time(DateUtils.getNowTimeMilly()); | ||
| 84 | + if(null != summaryObjec) | ||
| 85 | + { | ||
| 86 | + device.setSummary(summaryObjec.toString()); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + JSONObject saveJson = dataModeAnalysisService.analysisThingsModelValue( topic.getClientid(),topic.getUsername(),jsData,true,"主机本地"); | ||
| 90 | + //更新数据 | ||
| 91 | + if(null != olddevice && "ADD".equals(type.name())) | ||
| 92 | + { | ||
| 93 | + String str = olddevice.getThings_model_value(); | ||
| 94 | + String newStr = deviceService.getNewAdddate(str,saveJson).toJSONString(); | ||
| 95 | + device.setThings_model_value(newStr); | ||
| 96 | + }else{ | ||
| 97 | + device.setThings_model_value(saveJson.toJSONString()); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + return device; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * 更新终端 | ||
| 105 | + * @param type "ADD"增量更新,"ALL"全量更新 | ||
| 106 | + * @param key | ||
| 107 | + * @param topic | ||
| 108 | + * @param jsData | ||
| 109 | + * @param operateHisList | ||
| 110 | + * @return | ||
| 111 | + */ | ||
| 112 | + private IotTerminal translateTerminal(Type type,String key, Topic topic , JSONObject jsData, List<LogDeviceOperation> operateHisList) | ||
| 113 | + { | ||
| 114 | + String id = topic.getClientid()+"_"+key; | ||
| 115 | + JSONObject saveJson = dataModeAnalysisService.analysisThingsModelValue( id,topic.getUsername(),jsData,true,"终端本地"); | ||
| 116 | + IotTerminal terminal = new IotTerminal(); | ||
| 117 | + terminal.setId(id); | ||
| 118 | + terminal.setUpdate_time(DateUtils.getNowTimeMilly()); | ||
| 119 | + | ||
| 120 | + //更新数据 | ||
| 121 | + IotTerminal oldterminal = deviceService.getRedicTerminal(id); | ||
| 122 | + if(null != oldterminal && "ADD".equals(type.name())) | ||
| 123 | + { | ||
| 124 | + String str = oldterminal.getThings_model_value(); | ||
| 125 | + terminal.setThings_model_value(deviceService.getNewAdddate(str,saveJson).toJSONString()); | ||
| 126 | + }else{ | ||
| 127 | + terminal.setThings_model_value(saveJson.toJSONString()); | ||
| 128 | + } | ||
| 129 | + return terminal; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public enum Type | ||
| 133 | + { | ||
| 134 | + ADD,ALL | ||
| 135 | + } | ||
| 136 | +} |
lh-mqtt-service/src/main/java/com/zhonglai/luhui/mqtt/comm/service/DataModeAnalysisService.java
0 → 100644
| 1 | +package com.zhonglai.luhui.mqtt.comm.service; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.alibaba.fastjson.JSONObject; | ||
| 5 | +import com.zhonglai.luhui.mqtt.comm.config.RedisConfig; | ||
| 6 | +import com.zhonglai.luhui.mqtt.comm.dao.BaseDao; | ||
| 7 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 8 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 9 | +import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel; | ||
| 10 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelBase; | ||
| 11 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | ||
| 12 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 13 | +import com.zhonglai.luhui.mqtt.comm.util.DateUtils; | ||
| 14 | +import org.slf4j.Logger; | ||
| 15 | +import org.slf4j.LoggerFactory; | ||
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 17 | +import org.springframework.stereotype.Service; | ||
| 18 | + | ||
| 19 | +import java.util.ArrayList; | ||
| 20 | +import java.util.List; | ||
| 21 | +import java.util.Map; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * 数据模型解析服务 | ||
| 25 | + */ | ||
| 26 | +@Service | ||
| 27 | +public class DataModeAnalysisService { | ||
| 28 | + private static final Logger log = LoggerFactory.getLogger(DataModeAnalysisService.class); | ||
| 29 | + | ||
| 30 | + private BaseDao baseDao = new BaseDao(); | ||
| 31 | + @Autowired | ||
| 32 | + private RedisService redisService ; | ||
| 33 | + | ||
| 34 | + @Autowired | ||
| 35 | + private DeviceLogService dviceLogService; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 初始化物模型数据 | ||
| 39 | + */ | ||
| 40 | + public void initDataThingsMode() | ||
| 41 | + { | ||
| 42 | + List<IotThingsModel> list = baseDao.findBysql("select * from `mqtt_broker`.`iot_things_model` where del_flag=0", IotThingsModel.class); | ||
| 43 | + | ||
| 44 | + if(null != list && list.size() != 0) | ||
| 45 | + { | ||
| 46 | + for(IotThingsModel thingsModel:list) | ||
| 47 | + { | ||
| 48 | + redisService.hset(RedisConfig.FIELD+RedisConfig.THINGS_MODEL+thingsModel.getUser_name(),thingsModel.getIdentifier(),thingsModel); | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + public JSONObject analysisThingsModelValue(String id, String userName , JSONObject jsData) | ||
| 53 | + { | ||
| 54 | + return analysisThingsModelValue(id,userName,jsData,false,null); | ||
| 55 | + } | ||
| 56 | + /** | ||
| 57 | + * 解析物模型数据 | ||
| 58 | + */ | ||
| 59 | + public JSONObject analysisThingsModelValue(String id,String userName ,JSONObject jsData,boolean isSaveLog,String controlModel) | ||
| 60 | + { | ||
| 61 | + if(null != jsData && jsData.size() != 0 ) | ||
| 62 | + { | ||
| 63 | + Map<Object, Object> thingsModelMap = redisService.hmget(RedisConfig.FIELD+RedisConfig.THINGS_MODEL+userName); | ||
| 64 | + JSONObject rObjec = new JSONObject(); | ||
| 65 | + | ||
| 66 | + List<DeviceSensorData> list = new ArrayList<>(); | ||
| 67 | + List<LogDeviceOperation> oplist = new ArrayList<>(); | ||
| 68 | + | ||
| 69 | + for(String key:jsData.keySet()) | ||
| 70 | + { | ||
| 71 | + Object object = thingsModelMap.get(key); | ||
| 72 | + IotThingsModel thingsModel = null; | ||
| 73 | + if(object instanceof IotThingsModel) | ||
| 74 | + { | ||
| 75 | + thingsModel = (IotThingsModel)object; | ||
| 76 | + }else{ //没有配置的 都按字符串处理 | ||
| 77 | + thingsModel = new IotThingsModel(); | ||
| 78 | + thingsModel.setData_type(ThingsModelDataTypeEnum.STRING.name()); | ||
| 79 | + thingsModel.setIdentifier(key); | ||
| 80 | + thingsModel.setModel_name(key); | ||
| 81 | + thingsModel.setIs_top(0); | ||
| 82 | + thingsModel.setIs_monitor(0); | ||
| 83 | + thingsModel.setIs_save_log(0); | ||
| 84 | + JSONObject jsonObject = new JSONObject(); | ||
| 85 | + jsonObject.put("maxLength",255); | ||
| 86 | + thingsModel.setSpecs(jsonObject.toString()); | ||
| 87 | + } | ||
| 88 | + Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class,thingsModel.getData_type()).getaClass(); | ||
| 89 | + ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(),aClass); | ||
| 90 | + thingsModelBase.conversionThingsModel(thingsModel); | ||
| 91 | + thingsModelBase.addValue(jsData.get(key)); | ||
| 92 | + | ||
| 93 | + ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase; | ||
| 94 | + //记录数据日志 | ||
| 95 | + if(1==thingsModelItemBase.getIs_save_log()) | ||
| 96 | + { | ||
| 97 | + DeviceSensorData sensorData = new DeviceSensorData(); | ||
| 98 | + sensorData.setDataType(key); | ||
| 99 | + sensorData.setDataValue(jsData.getString(key)); | ||
| 100 | + sensorData.setCreatTime(DateUtils.getNowTimeMilly()); | ||
| 101 | + sensorData.setDeviceModel(userName); | ||
| 102 | + sensorData.setDeviceInfoId(id); | ||
| 103 | + list.add(sensorData); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + //记录操作日志 | ||
| 107 | + oplist.add(dviceLogService.newLogDeviceOperation(id,jsData.getString(key),null,controlModel+thingsModelItemBase.getName()+"为"+thingsModelBase.getView(),jsData.toString())); | ||
| 108 | + | ||
| 109 | + rObjec.put(key,JSONObject.toJSONString(thingsModelBase)); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + //日志入库 | ||
| 113 | + dviceLogService.saveDeviceSensorDataLog(list); | ||
| 114 | + dviceLogService.saveOperationLog(oplist); | ||
| 115 | + return rObjec; | ||
| 116 | + } | ||
| 117 | + return null; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.comm.service; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dao.BaseDao; | ||
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 5 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 6 | +import com.zhonglai.luhui.mqtt.comm.dto.TableGenerateSqlEnum; | ||
| 7 | +import com.zhonglai.luhui.mqtt.comm.util.DateUtils; | ||
| 8 | +import org.springframework.stereotype.Service; | ||
| 9 | + | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +@Service | ||
| 13 | +public class DeviceLogService { | ||
| 14 | + private BaseDao baseDao = new BaseDao(); | ||
| 15 | + | ||
| 16 | + public void saveOperationLog(List<LogDeviceOperation> list) | ||
| 17 | + { | ||
| 18 | + if(null != list && list.size() != 0 ) | ||
| 19 | + { | ||
| 20 | + baseDao.insertList(list, TableGenerateSqlEnum.LogDeviceOperation.getNowTableName()); | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public void saveDeviceSensorDataLog(List<DeviceSensorData> list) | ||
| 25 | + { | ||
| 26 | + if(null != list && list.size() != 0 ) | ||
| 27 | + { | ||
| 28 | + baseDao.insertList(list, TableGenerateSqlEnum.DeviceSensorData.getNowTableName()); | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public LogDeviceOperation newLogDeviceOperation(String id,String newStr,String oldstr,String operationDescribe,String operationInstruction) | ||
| 33 | + { | ||
| 34 | + LogDeviceOperation operateHis = new LogDeviceOperation(); | ||
| 35 | + operateHis.setDeviceInfoId(id); | ||
| 36 | + operateHis.setDeviceNewState(newStr); | ||
| 37 | + operateHis.setDeviceOldState(oldstr); | ||
| 38 | + if(null != operateHis.getDeviceNewState() && !operateHis.getDeviceNewState().equals(operateHis.getDeviceOldState())) | ||
| 39 | + { | ||
| 40 | + operateHis.setIsStateChange(1); | ||
| 41 | + } | ||
| 42 | + operateHis.setOperationInstruction(operationInstruction); | ||
| 43 | + operateHis.setDeviceOperationTime(DateUtils.getNowTimeMilly()); | ||
| 44 | + operateHis.setDeviceOperationType(-1); | ||
| 45 | + operateHis.setOperationDescribe(operationDescribe); | ||
| 46 | + return operateHis; | ||
| 47 | + } | ||
| 48 | +} |
| @@ -26,8 +26,7 @@ public class MqttCallback implements MqttCallbackExtended { | @@ -26,8 +26,7 @@ public class MqttCallback implements MqttCallbackExtended { | ||
| 26 | private BusinessAgreementFactory businessAgreementFactory; | 26 | private BusinessAgreementFactory businessAgreementFactory; |
| 27 | @Autowired | 27 | @Autowired |
| 28 | private TerminalService terminalService; //客户端服务 | 28 | private TerminalService terminalService; //客户端服务 |
| 29 | - @Autowired | ||
| 30 | - private ClienNoticeService clienNoticeService; //客户端通知服务 | 29 | + |
| 31 | @Autowired | 30 | @Autowired |
| 32 | private DataPersistenceService dataPersistenceService; //数据持久化 | 31 | private DataPersistenceService dataPersistenceService; //数据持久化 |
| 33 | 32 | ||
| @@ -62,13 +61,17 @@ public class MqttCallback implements MqttCallbackExtended { | @@ -62,13 +61,17 @@ public class MqttCallback implements MqttCallbackExtended { | ||
| 62 | log.error("消息{},topic为空,不做解析"); | 61 | log.error("消息{},topic为空,不做解析"); |
| 63 | return; | 62 | return; |
| 64 | } | 63 | } |
| 65 | - //解析协议 | 64 | + //准备数据 |
| 66 | byte[] data = mqttMessage.getPayload(); | 65 | byte[] data = mqttMessage.getPayload(); |
| 66 | + IotDevice iotDevice = deviceService.getDeviceById(topic.getClientid()); | ||
| 67 | + | ||
| 68 | + //转化为协议对象 | ||
| 69 | + BusinessDto businessDto = BusinessDtoClassNew.newBean(topic.getPayloadtype(),data).analyticalModel(iotDevice.getThings_model_value()); | ||
| 70 | + | ||
| 67 | BusinessAgreement businessAgreement = businessAgreementFactory.createBusinessAgreement(topic); | 71 | BusinessAgreement businessAgreement = businessAgreementFactory.createBusinessAgreement(topic); |
| 68 | try { | 72 | try { |
| 69 | - IotDevice iotDevice = deviceService.getDeviceById(topic.getClientid()); | ||
| 70 | - BusinessDto businessDto = BusinessDtoClassNew.newBean(topic.getPayloadtype(),data).analyticalModel(iotDevice.getBusiness_model()); | ||
| 71 | - ServerDto dto = businessAgreement.analysis(topic,businessDto.toServerDto()); | 73 | + //解析为业务对象 |
| 74 | + ServerDto dto = businessAgreement.analysis(topic,businessAgreement.toData(businessDto)); | ||
| 72 | if(null == dto) | 75 | if(null == dto) |
| 73 | { | 76 | { |
| 74 | return; | 77 | return; |
| @@ -86,11 +89,6 @@ public class MqttCallback implements MqttCallbackExtended { | @@ -86,11 +89,6 @@ public class MqttCallback implements MqttCallbackExtended { | ||
| 86 | } | 89 | } |
| 87 | dataPersistenceService.addDeviceSensorData(topic,dto); | 90 | dataPersistenceService.addDeviceSensorData(topic,dto); |
| 88 | 91 | ||
| 89 | - //回复客户端消息 | ||
| 90 | - clienNoticeService.replySendMessage(topic,dto); | ||
| 91 | - | ||
| 92 | - //回复终端消息 | ||
| 93 | - clienNoticeService.replyTerminalMessage(topic,dto); | ||
| 94 | } catch (Exception e) { | 92 | } catch (Exception e) { |
| 95 | log.error(s+"消息解析异常",e); | 93 | log.error(s+"消息解析异常",e); |
| 96 | } | 94 | } |
| 1 | package com.zhonglai.luhui.mqtt.dto.topic; | 1 | package com.zhonglai.luhui.mqtt.dto.topic; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; | 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; |
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 5 | import lombok.Data; | 6 | import lombok.Data; |
| @@ -8,6 +9,7 @@ import lombok.experimental.Accessors; | @@ -8,6 +9,7 @@ import lombok.experimental.Accessors; | ||
| 8 | @Data | 9 | @Data |
| 9 | @Accessors(chain = true) | 10 | @Accessors(chain = true) |
| 10 | public class AllPostDto implements ServerDto { | 11 | public class AllPostDto implements ServerDto { |
| 12 | + private JSONObject data; | ||
| 11 | @Override | 13 | @Override |
| 12 | public ServerAgreementContent getServerAgreementContent() { | 14 | public ServerAgreementContent getServerAgreementContent() { |
| 13 | return null; | 15 | return null; |
| @@ -50,33 +50,6 @@ public class DeviceService { | @@ -50,33 +50,6 @@ public class DeviceService { | ||
| 50 | return (IotDevice) baseDao.get(IotDevice.class,"client_id='"+id+"'","`mqtt_broker`.`iot_device`"); | 50 | return (IotDevice) baseDao.get(IotDevice.class,"client_id='"+id+"'","`mqtt_broker`.`iot_device`"); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | - /** | ||
| 54 | - * 全量更新终端模型数据 | ||
| 55 | - * @param JSONObject | ||
| 56 | - * @param id | ||
| 57 | - */ | ||
| 58 | - public void fullUpdateTerminal(JSONObject JSONObject,String id) | ||
| 59 | - { | ||
| 60 | - IotTerminal terminal = new IotTerminal(); | ||
| 61 | - terminal.setThings_model_value(JSONObject.toString()); | ||
| 62 | - terminal.setId(id); | ||
| 63 | - terminal.setUpdate_time(DateUtils.getNowTimeMilly()); | ||
| 64 | - baseDao.update(terminal,"id"); | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - /** | ||
| 68 | - * 全量更新网关的模型数据 | ||
| 69 | - * @param JSONObject | ||
| 70 | - * @param id | ||
| 71 | - */ | ||
| 72 | - public void fullUpdateDevice(JSONObject JSONObject,String id) | ||
| 73 | - { | ||
| 74 | - IotTerminal terminal = new IotTerminal(); | ||
| 75 | - terminal.setThings_model_value(JSONObject.toString()); | ||
| 76 | - terminal.setId(id); | ||
| 77 | - terminal.setUpdate_time(DateUtils.getNowTimeMilly()); | ||
| 78 | - baseDao.update(terminal,"id"); | ||
| 79 | - } | ||
| 80 | 53 | ||
| 81 | /** | 54 | /** |
| 82 | * 获取缓存网关信息 | 55 | * 获取缓存网关信息 |
| @@ -89,14 +62,15 @@ public class DeviceService { | @@ -89,14 +62,15 @@ public class DeviceService { | ||
| 89 | if(null != object) | 62 | if(null != object) |
| 90 | { | 63 | { |
| 91 | return (IotDevice)object; | 64 | return (IotDevice)object; |
| 65 | + }else{ | ||
| 66 | + return getDeviceById(id); | ||
| 92 | } | 67 | } |
| 93 | - return null; | ||
| 94 | } | 68 | } |
| 95 | 69 | ||
| 96 | - public void updataDevice(IotDevice device) | 70 | + public void updataDevice(IotDevice iotDevice) |
| 97 | { | 71 | { |
| 98 | - setRedicDevice(device); | ||
| 99 | - baseDao.saveOrUpdateObject(device); | 72 | + setRedicDevice(iotDevice); |
| 73 | + baseDao.saveOrUpdateObject(iotDevice); | ||
| 100 | } | 74 | } |
| 101 | 75 | ||
| 102 | /** | 76 | /** |
| @@ -149,17 +123,22 @@ public class DeviceService { | @@ -149,17 +123,22 @@ public class DeviceService { | ||
| 149 | } | 123 | } |
| 150 | /** | 124 | /** |
| 151 | * 获取 | 125 | * 获取 |
| 152 | - * @param userId | 126 | + * @param username |
| 153 | * @return | 127 | * @return |
| 154 | */ | 128 | */ |
| 155 | - public IotThingsModel getThingsModelsByUserIdAndIdentifier(Integer userId, String identifier) | 129 | + public IotThingsModel getThingsModelsByUserIdAndIdentifier(String username, String identifier) |
| 156 | { | 130 | { |
| 157 | - Object object = redisService.hget(RedisConfig.FIELD+RedisConfig.THINGS_MODEL+userId,identifier); | 131 | + Object object = redisService.hget(RedisConfig.FIELD+RedisConfig.THINGS_MODEL+username,identifier); |
| 158 | return null != object?(IotThingsModel)object:null; | 132 | return null != object?(IotThingsModel)object:null; |
| 159 | } | 133 | } |
| 160 | 134 | ||
| 161 | - | ||
| 162 | - public JSONObject getNewdate(String oldstr, JSONObject saveJson) | 135 | + /** |
| 136 | + * 增量更新数据 | ||
| 137 | + * @param oldstr | ||
| 138 | + * @param saveJson | ||
| 139 | + * @return | ||
| 140 | + */ | ||
| 141 | + public JSONObject getNewAdddate(String oldstr, JSONObject saveJson) | ||
| 163 | { | 142 | { |
| 164 | JSONObject oldjs = new JSONObject(); | 143 | JSONObject oldjs = new JSONObject(); |
| 165 | if(StringUtils.isNoneBlank(oldstr)) | 144 | if(StringUtils.isNoneBlank(oldstr)) |
| 1 | package com.zhonglai.luhui.mqtt.service.topic; | 1 | package com.zhonglai.luhui.mqtt.service.topic; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 5 | +import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; | 6 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; |
| 5 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; | 7 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; |
| 8 | +import com.zhonglai.luhui.mqtt.comm.service.BusinessDataUpdateService; | ||
| 6 | import com.zhonglai.luhui.mqtt.dto.topic.AddPostDto; | 9 | import com.zhonglai.luhui.mqtt.dto.topic.AddPostDto; |
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 8 | 12 | ||
| 9 | 13 | ||
| 14 | + | ||
| 10 | /** | 15 | /** |
| 11 | * 增量上报数据,不需要返回 | 16 | * 增量上报数据,不需要返回 |
| 12 | */ | 17 | */ |
| 13 | @Service("ADD_POST") | 18 | @Service("ADD_POST") |
| 14 | public class AddPostTopic implements BusinessAgreement<AddPostDto> { | 19 | public class AddPostTopic implements BusinessAgreement<AddPostDto> { |
| 15 | - | 20 | + @Autowired |
| 21 | + private BusinessDataUpdateService businessDataUpdateService ; | ||
| 16 | @Override | 22 | @Override |
| 17 | - public ServerDto analysis(Topic topic, AddPostDto data) throws Exception { | ||
| 18 | - | 23 | + public ServerDto analysis(Topic topic, AddPostDto data) { |
| 24 | + businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ADD,topic,data.getData()); | ||
| 19 | return null; | 25 | return null; |
| 20 | } | 26 | } |
| 21 | 27 | ||
| 28 | + @Override | ||
| 29 | + public ServerDto toData(BusinessDto data) { | ||
| 30 | + AddPostDto serverDto = new AddPostDto(); | ||
| 31 | + return serverDto.setData((JSONObject) data.getContentData()); | ||
| 32 | + } | ||
| 33 | + | ||
| 22 | } | 34 | } |
| 1 | package com.zhonglai.luhui.mqtt.service.topic; | 1 | package com.zhonglai.luhui.mqtt.service.topic; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; |
| 5 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; | 6 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; |
| 6 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; | 7 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; |
| 8 | +import com.zhonglai.luhui.mqtt.comm.service.BusinessDataUpdateService; | ||
| 9 | +import com.zhonglai.luhui.mqtt.dto.topic.AddPostDto; | ||
| 7 | import com.zhonglai.luhui.mqtt.dto.topic.AllPostDto; | 10 | import com.zhonglai.luhui.mqtt.dto.topic.AllPostDto; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 9 | 13 | ||
| 14 | + | ||
| 10 | /** | 15 | /** |
| 11 | * 全量上报数据,不需要返回 | 16 | * 全量上报数据,不需要返回 |
| 12 | */ | 17 | */ |
| 13 | @Service("ALL_POST") | 18 | @Service("ALL_POST") |
| 14 | public class AllPostTopic implements BusinessAgreement<AllPostDto> { | 19 | public class AllPostTopic implements BusinessAgreement<AllPostDto> { |
| 20 | + @Autowired | ||
| 21 | + private BusinessDataUpdateService businessDataUpdateService ; | ||
| 15 | @Override | 22 | @Override |
| 16 | public ServerDto analysis(Topic topic, AllPostDto data) throws Exception { | 23 | public ServerDto analysis(Topic topic, AllPostDto data) throws Exception { |
| 24 | + businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ALL,topic,data.getData()); | ||
| 17 | return null; | 25 | return null; |
| 18 | } | 26 | } |
| 19 | 27 | ||
| 20 | @Override | 28 | @Override |
| 21 | public AllPostDto toData(BusinessDto data) { | 29 | public AllPostDto toData(BusinessDto data) { |
| 22 | - return null; | 30 | + AllPostDto serverDto = new AllPostDto(); |
| 31 | + return serverDto.setData((JSONObject) data.getContentData()); | ||
| 23 | } | 32 | } |
| 24 | } | 33 | } |
| 1 | package com.zhonglai.luhui.mqtt.service.topic; | 1 | package com.zhonglai.luhui.mqtt.service.topic; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; |
| 5 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; | 6 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; |
| 6 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; | 7 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; |
| 8 | +import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService; | ||
| 9 | +import com.zhonglai.luhui.mqtt.dto.topic.AllPostDto; | ||
| 7 | import com.zhonglai.luhui.mqtt.dto.topic.GetDto; | 10 | import com.zhonglai.luhui.mqtt.dto.topic.GetDto; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 9 | 13 | ||
| 10 | /** | 14 | /** |
| @@ -12,6 +16,9 @@ import org.springframework.stereotype.Service; | @@ -12,6 +16,9 @@ import org.springframework.stereotype.Service; | ||
| 12 | */ | 16 | */ |
| 13 | @Service("GET") | 17 | @Service("GET") |
| 14 | public class GetTopic implements BusinessAgreement<GetDto> { | 18 | public class GetTopic implements BusinessAgreement<GetDto> { |
| 19 | + @Autowired | ||
| 20 | + private ClienNoticeService clienNoticeService; //客户端通知服务 | ||
| 21 | + | ||
| 15 | @Override | 22 | @Override |
| 16 | public ServerDto analysis(Topic topic, GetDto data) throws Exception { | 23 | public ServerDto analysis(Topic topic, GetDto data) throws Exception { |
| 17 | return null; | 24 | return null; |
| @@ -19,6 +26,19 @@ public class GetTopic implements BusinessAgreement<GetDto> { | @@ -19,6 +26,19 @@ public class GetTopic implements BusinessAgreement<GetDto> { | ||
| 19 | 26 | ||
| 20 | @Override | 27 | @Override |
| 21 | public GetDto toData(BusinessDto data) { | 28 | public GetDto toData(BusinessDto data) { |
| 22 | - return null; | 29 | + GetDto serverDto = new GetDto(); |
| 30 | + return serverDto; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 回复客户端消息 | ||
| 35 | + * @param topic | ||
| 36 | + * @param dto | ||
| 37 | + */ | ||
| 38 | + private void replySendMessage(Topic topic,ServerDto dto) | ||
| 39 | + { | ||
| 40 | + //回复客户端消息 | ||
| 41 | + clienNoticeService.replySendMessage(topic,dto); | ||
| 23 | } | 42 | } |
| 43 | + | ||
| 24 | } | 44 | } |
| 1 | package com.zhonglai.luhui.mqtt.service.topic; | 1 | package com.zhonglai.luhui.mqtt.service.topic; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; |
| 5 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; | 6 | import com.zhonglai.luhui.mqtt.comm.factory.BusinessAgreement; |
| 6 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; | 7 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; |
| 8 | +import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService; | ||
| 9 | +import com.zhonglai.luhui.mqtt.dto.topic.AllPostDto; | ||
| 7 | import com.zhonglai.luhui.mqtt.dto.topic.PutReqDto; | 10 | import com.zhonglai.luhui.mqtt.dto.topic.PutReqDto; |
| 11 | +import org.eclipse.paho.client.mqttv3.MqttException; | ||
| 12 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | import org.springframework.stereotype.Service; | 13 | import org.springframework.stereotype.Service; |
| 9 | 14 | ||
| 10 | /** | 15 | /** |
| @@ -12,6 +17,10 @@ import org.springframework.stereotype.Service; | @@ -12,6 +17,10 @@ import org.springframework.stereotype.Service; | ||
| 12 | */ | 17 | */ |
| 13 | @Service("PUT_REQ") | 18 | @Service("PUT_REQ") |
| 14 | public class PutReqTopic implements BusinessAgreement<PutReqDto> { | 19 | public class PutReqTopic implements BusinessAgreement<PutReqDto> { |
| 20 | + | ||
| 21 | + @Autowired | ||
| 22 | + private ClienNoticeService clienNoticeService; //客户端通知服务 | ||
| 23 | + | ||
| 15 | @Override | 24 | @Override |
| 16 | public ServerDto analysis(Topic topic, PutReqDto data) throws Exception { | 25 | public ServerDto analysis(Topic topic, PutReqDto data) throws Exception { |
| 17 | return null; | 26 | return null; |
| @@ -19,6 +28,12 @@ public class PutReqTopic implements BusinessAgreement<PutReqDto> { | @@ -19,6 +28,12 @@ public class PutReqTopic implements BusinessAgreement<PutReqDto> { | ||
| 19 | 28 | ||
| 20 | @Override | 29 | @Override |
| 21 | public PutReqDto toData(BusinessDto data) { | 30 | public PutReqDto toData(BusinessDto data) { |
| 22 | - return null; | 31 | + PutReqDto putReqDto = new PutReqDto(); |
| 32 | + return putReqDto.setData((String) data.getContentData()); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + private void replyTerminalMessage(Topic topic,ServerDto dto) throws MqttException { | ||
| 36 | + //回复终端消息 | ||
| 37 | + clienNoticeService.replyTerminalMessage(topic,dto); | ||
| 23 | } | 38 | } |
| 24 | } | 39 | } |
lh-mqtt-service/src/main/resources/test.js
0 → 100644
| @@ -590,4 +590,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils | @@ -590,4 +590,8 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils | ||
| 590 | str = ch + str.substring(1); | 590 | str = ch + str.substring(1); |
| 591 | return str; | 591 | return str; |
| 592 | } | 592 | } |
| 593 | + | ||
| 594 | + public static void main(String[] args) { | ||
| 595 | + System.out.println(StringUtils.toUnderScoreCase("deviceInfoId")); | ||
| 596 | + } | ||
| 593 | } | 597 | } |
-
请 注册 或 登录 后发表评论