正在显示
37 个修改的文件
包含
451 行增加
和
81 行删除
| @@ -35,7 +35,11 @@ | @@ -35,7 +35,11 @@ | ||
| 35 | <groupId>com.zhonglai.luhui</groupId> | 35 | <groupId>com.zhonglai.luhui</groupId> |
| 36 | <artifactId>ruoyi-generator</artifactId> | 36 | <artifactId>ruoyi-generator</artifactId> |
| 37 | </dependency> | 37 | </dependency> |
| 38 | - | 38 | + <!-- 代码生成模块--> |
| 39 | + <dependency> | ||
| 40 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 41 | + <artifactId>lh-mqtt-service</artifactId> | ||
| 42 | + </dependency> | ||
| 39 | <!-- 文档 --> | 43 | <!-- 文档 --> |
| 40 | <dependency > | 44 | <dependency > |
| 41 | <groupId>io.springfox</groupId> | 45 | <groupId>io.springfox</groupId> |
| @@ -3,7 +3,9 @@ package com.zhonglai.luhui.admin.controller.iot; | @@ -3,7 +3,9 @@ package com.zhonglai.luhui.admin.controller.iot; | ||
| 3 | import java.util.List; | 3 | import java.util.List; |
| 4 | import javax.servlet.http.HttpServletResponse; | 4 | import javax.servlet.http.HttpServletResponse; |
| 5 | 5 | ||
| 6 | +import com.ruoyi.common.utils.http.HttpUtils; | ||
| 6 | import io.swagger.annotations.Api; | 7 | import io.swagger.annotations.Api; |
| 8 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 7 | import io.swagger.annotations.ApiOperation; | 9 | import io.swagger.annotations.ApiOperation; |
| 8 | import org.springframework.security.access.prepost.PreAuthorize; | 10 | import org.springframework.security.access.prepost.PreAuthorize; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -82,7 +84,7 @@ public class IotDeviceController extends BaseController | @@ -82,7 +84,7 @@ public class IotDeviceController extends BaseController | ||
| 82 | @ApiOperation("新增主机/网关") | 84 | @ApiOperation("新增主机/网关") |
| 83 | @PreAuthorize("@ss.hasPermi('iot:IotDevice:add')") | 85 | @PreAuthorize("@ss.hasPermi('iot:IotDevice:add')") |
| 84 | @Log(title = "主机/网关", businessType = BusinessType.INSERT) | 86 | @Log(title = "主机/网关", businessType = BusinessType.INSERT) |
| 85 | - @PostMapping | 87 | + @PostMapping("add") |
| 86 | public AjaxResult add(@RequestBody IotDevice iotDevice) | 88 | public AjaxResult add(@RequestBody IotDevice iotDevice) |
| 87 | { | 89 | { |
| 88 | return toAjax(iotDeviceService.insertIotDevice(iotDevice)); | 90 | return toAjax(iotDeviceService.insertIotDevice(iotDevice)); |
| @@ -94,7 +96,7 @@ public class IotDeviceController extends BaseController | @@ -94,7 +96,7 @@ public class IotDeviceController extends BaseController | ||
| 94 | @ApiOperation("修改主机/网关") | 96 | @ApiOperation("修改主机/网关") |
| 95 | @PreAuthorize("@ss.hasPermi('iot:IotDevice:edit')") | 97 | @PreAuthorize("@ss.hasPermi('iot:IotDevice:edit')") |
| 96 | @Log(title = "主机/网关", businessType = BusinessType.UPDATE) | 98 | @Log(title = "主机/网关", businessType = BusinessType.UPDATE) |
| 97 | - @PutMapping | 99 | + @PutMapping("edit") |
| 98 | public AjaxResult edit(@RequestBody IotDevice iotDevice) | 100 | public AjaxResult edit(@RequestBody IotDevice iotDevice) |
| 99 | { | 101 | { |
| 100 | return toAjax(iotDeviceService.updateIotDevice(iotDevice)); | 102 | return toAjax(iotDeviceService.updateIotDevice(iotDevice)); |
| @@ -111,4 +113,27 @@ public class IotDeviceController extends BaseController | @@ -111,4 +113,27 @@ public class IotDeviceController extends BaseController | ||
| 111 | { | 113 | { |
| 112 | return toAjax(iotDeviceService.deleteIotDeviceByClient_ids(client_ids)); | 114 | return toAjax(iotDeviceService.deleteIotDeviceByClient_ids(client_ids)); |
| 113 | } | 115 | } |
| 116 | + | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * 修改主机/网关 | ||
| 120 | + */ | ||
| 121 | + @ApiOperation("修改主机/网关") | ||
| 122 | + @PreAuthorize("@ss.hasPermi('iot:IotDevice:restart')") | ||
| 123 | + @Log(title = "主机/网关", businessType = BusinessType.UPDATE) | ||
| 124 | + @PutMapping("restart") | ||
| 125 | + public AjaxResult restart(@RequestBody IotDevice iotDevice) | ||
| 126 | + { | ||
| 127 | + return toAjax(iotDeviceService.updateIotDevice(iotDevice)); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | +// @ApiOperation("固件版本更新") | ||
| 131 | +// @ApiImplicitParam(value = "版本号",name = "firmwareVersion") | ||
| 132 | +// @PreAuthorize("@ss.hasPermi('iot:IotDevice:firmwareUp')") | ||
| 133 | +// @Log(title = "主机/网关", businessType = BusinessType.UPDATE) | ||
| 134 | +// @PutMapping | ||
| 135 | +// public AjaxResult firmwareUp(String firmwareVersion) | ||
| 136 | +// { | ||
| 137 | +// return redirect("/device/control"); | ||
| 138 | +// } | ||
| 114 | } | 139 | } |
| 1 | package com.zhonglai.luhui.admin.controller.iot; | 1 | package com.zhonglai.luhui.admin.controller.iot; |
| 2 | 2 | ||
| 3 | +import java.util.Date; | ||
| 3 | import java.util.List; | 4 | import java.util.List; |
| 4 | import javax.servlet.http.HttpServletResponse; | 5 | import javax.servlet.http.HttpServletResponse; |
| 5 | 6 | ||
| 7 | +import com.alibaba.fastjson.JSON; | ||
| 8 | +import com.alibaba.fastjson.JSONObject; | ||
| 9 | +import com.ruoyi.common.utils.DateUtils; | ||
| 10 | +import com.zhonglai.luhui.admin.dto.IotThingsModelAddApi; | ||
| 11 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 12 | +import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs.*; | ||
| 6 | import io.swagger.annotations.Api; | 13 | import io.swagger.annotations.Api; |
| 7 | import io.swagger.annotations.ApiOperation; | 14 | import io.swagger.annotations.ApiOperation; |
| 8 | import org.springframework.security.access.prepost.PreAuthorize; | 15 | import org.springframework.security.access.prepost.PreAuthorize; |
| @@ -83,8 +90,39 @@ public class IotThingsModelController extends BaseController | @@ -83,8 +90,39 @@ public class IotThingsModelController extends BaseController | ||
| 83 | @PreAuthorize("@ss.hasPermi('iot:IotThingsModel:add')") | 90 | @PreAuthorize("@ss.hasPermi('iot:IotThingsModel:add')") |
| 84 | @Log(title = "物模型模板", businessType = BusinessType.INSERT) | 91 | @Log(title = "物模型模板", businessType = BusinessType.INSERT) |
| 85 | @PostMapping | 92 | @PostMapping |
| 86 | - public AjaxResult add(@RequestBody IotThingsModel iotThingsModel) | 93 | + public AjaxResult add(@RequestBody IotThingsModelAddApi iotThingsModelAddApi) |
| 87 | { | 94 | { |
| 95 | + IotThingsModel iotThingsModel = iotThingsModelAddApi.getIotThingsModel(); | ||
| 96 | + iotThingsModel.setCreate_by(getUsername()); | ||
| 97 | + ThingsModelItemBase thingsModelItemBase = null; | ||
| 98 | + switch (iotThingsModel.getData_type()) | ||
| 99 | + { | ||
| 100 | + case "integer": | ||
| 101 | + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), IntegerModelOutput.class); | ||
| 102 | + break; | ||
| 103 | + case "decimal": | ||
| 104 | + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), DecimalModelOutput.class); | ||
| 105 | + break; | ||
| 106 | + case "string": | ||
| 107 | + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), StringModelOutput.class); | ||
| 108 | + | ||
| 109 | + break; | ||
| 110 | + case "bool": | ||
| 111 | + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), BoolModelOutput.class); | ||
| 112 | + | ||
| 113 | + break; | ||
| 114 | + case "array": | ||
| 115 | + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), ArrayModelOutput.class); | ||
| 116 | + | ||
| 117 | + break; | ||
| 118 | + case "enum": | ||
| 119 | + thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), EnumModelOutput.class); | ||
| 120 | + break; | ||
| 121 | + } | ||
| 122 | + if(null == thingsModelItemBase) | ||
| 123 | + { | ||
| 124 | + return AjaxResult.error("请输入数模型"); | ||
| 125 | + } | ||
| 88 | return toAjax(iotThingsModelService.insertIotThingsModel(iotThingsModel)); | 126 | return toAjax(iotThingsModelService.insertIotThingsModel(iotThingsModel)); |
| 89 | } | 127 | } |
| 90 | 128 |
| 1 | +package com.zhonglai.luhui.admin.dto; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.ruoyi.system.domain.IotThingsModel; | ||
| 5 | +import io.swagger.annotations.ApiModel; | ||
| 6 | +import io.swagger.annotations.ApiModelProperty; | ||
| 7 | + | ||
| 8 | +import java.util.Map; | ||
| 9 | + | ||
| 10 | +@ApiModel("物模型添加对象") | ||
| 11 | +public class IotThingsModelAddApi { | ||
| 12 | + @ApiModelProperty("物模型信息") | ||
| 13 | + private IotThingsModel iotThingsModel; | ||
| 14 | + @ApiModelProperty("specs数据定义对象") | ||
| 15 | + private Map<String,Object> thingsModelBase; | ||
| 16 | + | ||
| 17 | + public IotThingsModel getIotThingsModel() { | ||
| 18 | + return iotThingsModel; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public void setIotThingsModel(IotThingsModel iotThingsModel) { | ||
| 22 | + this.iotThingsModel = iotThingsModel; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public Map<String,Object> getThingsModelBase() { | ||
| 26 | + return thingsModelBase; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public void setThingsModelBase(Map<String,Object> thingsModelBase) { | ||
| 30 | + this.thingsModelBase = thingsModelBase; | ||
| 31 | + } | ||
| 32 | +} |
| 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.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel; | ||
| 5 | +import com.zhonglai.luhui.mqtt.comm.factory.Topic; | ||
| 6 | +import com.zhonglai.luhui.mqtt.comm.service.DataModeAnalysisService; | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.util.http.HttpUtils; | 7 | import com.zhonglai.luhui.mqtt.comm.util.http.HttpUtils; |
| 8 | +import org.apache.commons.lang3.StringUtils; | ||
| 5 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
| 6 | import org.slf4j.LoggerFactory; | 10 | import org.slf4j.LoggerFactory; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | import org.springframework.beans.factory.annotation.Value; | 12 | import org.springframework.beans.factory.annotation.Value; |
| 8 | import org.springframework.context.annotation.Configuration; | 13 | import org.springframework.context.annotation.Configuration; |
| 9 | 14 | ||
| 10 | import javax.annotation.PostConstruct; | 15 | import javax.annotation.PostConstruct; |
| 16 | +import java.util.HashMap; | ||
| 17 | +import java.util.Map; | ||
| 11 | 18 | ||
| 12 | @Configuration | 19 | @Configuration |
| 13 | public class SysParameter { | 20 | public class SysParameter { |
| @@ -18,10 +25,15 @@ public class SysParameter { | @@ -18,10 +25,15 @@ public class SysParameter { | ||
| 18 | @Value("${mqtt.topicconfig:/{{roleid}}/{{username}}/{{clientid}}/{{topicType}}/{{messageid}}}") | 25 | @Value("${mqtt.topicconfig:/{{roleid}}/{{username}}/{{clientid}}/{{topicType}}/{{messageid}}}") |
| 19 | public String tempTopicconfig ; //topic 配置 | 26 | public String tempTopicconfig ; //topic 配置 |
| 20 | 27 | ||
| 28 | + @Value("${mqtt.topics") | ||
| 29 | + public String topics ; //topic | ||
| 30 | + | ||
| 21 | public static String topicconfig ; //topic 配置 | 31 | public static String topicconfig ; //topic 配置 |
| 22 | 32 | ||
| 33 | + private static Map<String, IotThingsModel> terminalDataThingsMode = new HashMap<>(); //topic 终端数据模型 | ||
| 34 | + | ||
| 23 | @PostConstruct | 35 | @PostConstruct |
| 24 | - public static void init() { | 36 | + public void init() { |
| 25 | String service_ip_url = "http://ly.userlogin.yu2le.com/ip"; | 37 | String service_ip_url = "http://ly.userlogin.yu2le.com/ip"; |
| 26 | JSONObject jsonObject = JSONObject.parseObject(HttpUtils.sendGet(service_ip_url)); | 38 | JSONObject jsonObject = JSONObject.parseObject(HttpUtils.sendGet(service_ip_url)); |
| 27 | service_ip = jsonObject.getString("data"); | 39 | service_ip = jsonObject.getString("data"); |
| @@ -32,4 +44,14 @@ public class SysParameter { | @@ -32,4 +44,14 @@ public class SysParameter { | ||
| 32 | { | 44 | { |
| 33 | topicconfig = tempTopicconfig; | 45 | topicconfig = tempTopicconfig; |
| 34 | } | 46 | } |
| 47 | + | ||
| 48 | + public static void setTerminalDataThingsMode(String username,IotThingsModel thingsModel) | ||
| 49 | + { | ||
| 50 | + terminalDataThingsMode.put(username+":"+thingsModel.getIdentifier(),thingsModel); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public static IotThingsModel getTerminalDataThingsMode(String username,String identifier) | ||
| 54 | + { | ||
| 55 | + return terminalDataThingsMode.get(username+":"+identifier); | ||
| 56 | + } | ||
| 35 | } | 57 | } |
| 1 | package com.zhonglai.luhui.mqtt.comm.dto; | 1 | package com.zhonglai.luhui.mqtt.comm.dto; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import java.util.List; | ||
| 5 | + | ||
| 4 | public interface ServerDto { | 6 | public interface ServerDto { |
| 5 | ServerAgreementContent getServerAgreementContent(); | 7 | ServerAgreementContent getServerAgreementContent(); |
| 6 | boolean isReplyMessage(); | 8 | boolean isReplyMessage(); |
| 9 | + List<DeviceSensorData> getDeviceSensorData(); | ||
| 10 | + List<LogDeviceOperation> getOperationLog(); | ||
| 7 | } | 11 | } |
| @@ -78,13 +78,13 @@ public class IotThingsModel | @@ -78,13 +78,13 @@ public class IotThingsModel | ||
| 78 | 78 | ||
| 79 | /** 用户id */ | 79 | /** 用户id */ |
| 80 | @ApiModelProperty("用户名称") | 80 | @ApiModelProperty("用户名称") |
| 81 | - private Integer user_name; | 81 | + private String user_name; |
| 82 | 82 | ||
| 83 | - public Integer getUser_name() { | 83 | + public String getUser_name() { |
| 84 | return user_name; | 84 | return user_name; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | - public void setUser_name(Integer user_name) { | 87 | + public void setUser_name(String user_name) { |
| 88 | this.user_name = user_name; | 88 | this.user_name = user_name; |
| 89 | } | 89 | } |
| 90 | 90 |
| 1 | package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels; | 1 | package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.annotation.JSONField; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel; | 4 | import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel; |
| 4 | 5 | ||
| 5 | /** | 6 | /** |
| @@ -8,5 +9,7 @@ import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel; | @@ -8,5 +9,7 @@ import com.zhonglai.luhui.mqtt.comm.dto.iot.IotThingsModel; | ||
| 8 | public interface ThingsModelBase<T> { | 9 | public interface ThingsModelBase<T> { |
| 9 | void conversionThingsModel(IotThingsModel thingsModel); | 10 | void conversionThingsModel(IotThingsModel thingsModel); |
| 10 | void addValue(T t); | 11 | void addValue(T t); |
| 12 | +// @JSONField(serialize=false) | ||
| 11 | String getView(); | 13 | String getView(); |
| 14 | + String getSaveView(); | ||
| 12 | } | 15 | } |
lh-mqtt-service/src/main/java/com/zhonglai/luhui/mqtt/comm/dto/thingsmodels/ThingsModelItemBase.java
| @@ -37,4 +37,5 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> | @@ -37,4 +37,5 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> | ||
| 37 | is_save_log = thingsModel.getIs_save_log(); | 37 | is_save_log = thingsModel.getIs_save_log(); |
| 38 | mode_type = thingsModel.getType(); | 38 | mode_type = thingsModel.getType(); |
| 39 | } | 39 | } |
| 40 | + | ||
| 40 | } | 41 | } |
| 1 | package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs; | 1 | package com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONArray; | 3 | import com.alibaba.fastjson.JSONArray; |
| 4 | +import com.alibaba.fastjson.annotation.JSONField; | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; |
| 5 | import lombok.Data; | 6 | import lombok.Data; |
| 6 | 7 | ||
| @@ -22,4 +23,9 @@ public class ArrayModelOutput extends ThingsModelItemBase<JSONArray> | @@ -22,4 +23,9 @@ public class ArrayModelOutput extends ThingsModelItemBase<JSONArray> | ||
| 22 | } | 23 | } |
| 23 | return ""; | 24 | return ""; |
| 24 | } | 25 | } |
| 26 | + | ||
| 27 | + @Override | ||
| 28 | + public String getSaveView() { | ||
| 29 | + return JSONArray.toJSONString(getValue()); | ||
| 30 | + } | ||
| 25 | } | 31 | } |
| @@ -24,4 +24,9 @@ public class BoolModelOutput extends ThingsModelItemBase<Boolean> | @@ -24,4 +24,9 @@ public class BoolModelOutput extends ThingsModelItemBase<Boolean> | ||
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | } | 26 | } |
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public String getSaveView() { | ||
| 30 | + return getValue().toString(); | ||
| 31 | + } | ||
| 27 | } | 32 | } |
| @@ -20,6 +20,11 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal> | @@ -20,6 +20,11 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal> | ||
| 20 | 20 | ||
| 21 | @Override | 21 | @Override |
| 22 | public String getView() { | 22 | public String getView() { |
| 23 | - return getView()+unit; | 23 | + return getValue().doubleValue()+unit; |
| 24 | + } | ||
| 25 | + | ||
| 26 | + @Override | ||
| 27 | + public String getSaveView() { | ||
| 28 | + return getValue().toString(); | ||
| 24 | } | 29 | } |
| 25 | } | 30 | } |
| @@ -27,4 +27,9 @@ public class EnumModelOutput extends ThingsModelItemBase<String> | @@ -27,4 +27,9 @@ public class EnumModelOutput extends ThingsModelItemBase<String> | ||
| 27 | } | 27 | } |
| 28 | return getValue(); | 28 | return getValue(); |
| 29 | } | 29 | } |
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public String getSaveView() { | ||
| 33 | + return getValue(); | ||
| 34 | + } | ||
| 30 | } | 35 | } |
| @@ -4,14 +4,17 @@ import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | @@ -4,14 +4,17 @@ import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 4 | import lombok.Data; | 4 | import lombok.Data; |
| 5 | 5 | ||
| 6 | import java.math.BigDecimal; | 6 | import java.math.BigDecimal; |
| 7 | +import java.math.RoundingMode; | ||
| 8 | + | ||
| 7 | 9 | ||
| 8 | @Data | 10 | @Data |
| 9 | public class IntegerModelOutput extends ThingsModelItemBase<Integer> | 11 | public class IntegerModelOutput extends ThingsModelItemBase<Integer> |
| 10 | { | 12 | { |
| 11 | - private BigDecimal min; | ||
| 12 | - private BigDecimal max; | ||
| 13 | - private BigDecimal step; | ||
| 14 | - private String unit; | 13 | + private BigDecimal min; //最大值 |
| 14 | + private BigDecimal max; //最小值 | ||
| 15 | + private BigDecimal step; //步长 | ||
| 16 | + private String unit; //单位 | ||
| 17 | + private Integer acy; //精度 | ||
| 15 | 18 | ||
| 16 | @Override | 19 | @Override |
| 17 | public void addValue(Integer object) { | 20 | public void addValue(Integer object) { |
| @@ -20,6 +23,12 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> | @@ -20,6 +23,12 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> | ||
| 20 | 23 | ||
| 21 | @Override | 24 | @Override |
| 22 | public String getView() { | 25 | public String getView() { |
| 23 | - return getView()+unit; | 26 | + return getSaveView()+unit; |
| 27 | + } | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public String getSaveView() { | ||
| 31 | + BigDecimal bigDecimal = new BigDecimal(getValue().toString()); | ||
| 32 | + return bigDecimal.divide(new BigDecimal(acy),acy.toString().length()-1, RoundingMode.HALF_UP).toString(); | ||
| 24 | } | 33 | } |
| 25 | } | 34 | } |
| @@ -20,4 +20,9 @@ public class StringModelOutput extends ThingsModelItemBase<Object> | @@ -20,4 +20,9 @@ public class StringModelOutput extends ThingsModelItemBase<Object> | ||
| 20 | public String getView() { | 20 | public String getView() { |
| 21 | return null!=getValue()?getValue()+"":null; | 21 | return null!=getValue()?getValue()+"":null; |
| 22 | } | 22 | } |
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public String getSaveView() { | ||
| 26 | + return getView(); | ||
| 27 | + } | ||
| 23 | } | 28 | } |
| @@ -27,7 +27,12 @@ public class Topic { | @@ -27,7 +27,12 @@ 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=1;i<config.length;i++) | 30 | + int number = sts.length; |
| 31 | + if(number>config.length) | ||
| 32 | + { | ||
| 33 | + number = config.length; | ||
| 34 | + } | ||
| 35 | + for(int i=1;i<number;i++) | ||
| 31 | { | 36 | { |
| 32 | String cf = config[i].replace("{{","").replace("}}",""); | 37 | String cf = config[i].replace("{{","").replace("}}",""); |
| 33 | try { | 38 | try { |
| 1 | package com.zhonglai.luhui.mqtt.comm.service; | 1 | package com.zhonglai.luhui.mqtt.comm.service; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | 5 | 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.IotDevice; |
| 6 | import com.zhonglai.luhui.mqtt.comm.dto.iot.IotTerminal; | 7 | import com.zhonglai.luhui.mqtt.comm.dto.iot.IotTerminal; |
| @@ -32,9 +33,8 @@ public class BusinessDataUpdateService { | @@ -32,9 +33,8 @@ public class BusinessDataUpdateService { | ||
| 32 | * @param topic | 33 | * @param topic |
| 33 | * @param data | 34 | * @param data |
| 34 | */ | 35 | */ |
| 35 | - public void updataDta(Type type,Topic topic, JSONObject data) | 36 | + public void updataDta(Type type,Topic topic, JSONObject data,boolean isOperLog,List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list) |
| 36 | { | 37 | { |
| 37 | - List<LogDeviceOperation> operateHisList = new ArrayList<>(); | ||
| 38 | for(String key:data.keySet()) | 38 | for(String key:data.keySet()) |
| 39 | { | 39 | { |
| 40 | Object o = data.get(key); | 40 | Object o = data.get(key); |
| @@ -43,20 +43,15 @@ public class BusinessDataUpdateService { | @@ -43,20 +43,15 @@ public class BusinessDataUpdateService { | ||
| 43 | JSONObject jsData = data.getJSONObject(key); | 43 | JSONObject jsData = data.getJSONObject(key); |
| 44 | if("0".equals(key)) //主机 | 44 | if("0".equals(key)) //主机 |
| 45 | { | 45 | { |
| 46 | - IotDevice iotDevice = translateDevice(type,topic,jsData,operateHisList); | 46 | + IotDevice iotDevice = translateDevice(type,topic,jsData,isOperLog,operateHisList,list); |
| 47 | deviceService.updataDevice(iotDevice); | 47 | deviceService.updataDevice(iotDevice); |
| 48 | 48 | ||
| 49 | }else{ //终端 | 49 | }else{ //终端 |
| 50 | - IotTerminal iotTerminal = translateTerminal(type,key,topic,jsData,operateHisList); | 50 | + IotTerminal iotTerminal = translateTerminal(type,key,topic,jsData,isOperLog,operateHisList,list); |
| 51 | deviceService.updataTerminal(iotTerminal); | 51 | deviceService.updataTerminal(iotTerminal); |
| 52 | } | 52 | } |
| 53 | } | 53 | } |
| 54 | } | 54 | } |
| 55 | - | ||
| 56 | - if(null != operateHisList && operateHisList.size() !=0 ) | ||
| 57 | - { | ||
| 58 | - deviceLogService.saveOperationLog(operateHisList); | ||
| 59 | - } | ||
| 60 | } | 55 | } |
| 61 | 56 | ||
| 62 | /** | 57 | /** |
| @@ -67,7 +62,7 @@ public class BusinessDataUpdateService { | @@ -67,7 +62,7 @@ public class BusinessDataUpdateService { | ||
| 67 | * @param operateHisList | 62 | * @param operateHisList |
| 68 | * @return | 63 | * @return |
| 69 | */ | 64 | */ |
| 70 | - private IotDevice translateDevice(Type type,Topic topic , JSONObject jsData, List<LogDeviceOperation> operateHisList) | 65 | + private IotDevice translateDevice(Type type,Topic topic , JSONObject jsData,boolean isOperLog, List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list) |
| 71 | { | 66 | { |
| 72 | IotDevice olddevice = deviceService.getRedicDevice(topic.getClientid()); | 67 | IotDevice olddevice = deviceService.getRedicDevice(topic.getClientid()); |
| 73 | JSONObject summaryObjec = null; | 68 | JSONObject summaryObjec = null; |
| @@ -86,7 +81,7 @@ public class BusinessDataUpdateService { | @@ -86,7 +81,7 @@ public class BusinessDataUpdateService { | ||
| 86 | device.setSummary(summaryObjec.toString()); | 81 | device.setSummary(summaryObjec.toString()); |
| 87 | } | 82 | } |
| 88 | 83 | ||
| 89 | - JSONObject saveJson = dataModeAnalysisService.analysisThingsModelValue( topic.getClientid(),topic.getUsername(),jsData,true,"主机本地"); | 84 | + JSONObject saveJson = dataModeAnalysisService.analysisThingsModelValue( topic.getClientid(),topic.getUsername(),jsData,"主机本地",isOperLog,operateHisList,list); |
| 90 | //更新数据 | 85 | //更新数据 |
| 91 | if(null != olddevice && "ADD".equals(type.name())) | 86 | if(null != olddevice && "ADD".equals(type.name())) |
| 92 | { | 87 | { |
| @@ -109,10 +104,10 @@ public class BusinessDataUpdateService { | @@ -109,10 +104,10 @@ public class BusinessDataUpdateService { | ||
| 109 | * @param operateHisList | 104 | * @param operateHisList |
| 110 | * @return | 105 | * @return |
| 111 | */ | 106 | */ |
| 112 | - private IotTerminal translateTerminal(Type type,String key, Topic topic , JSONObject jsData, List<LogDeviceOperation> operateHisList) | 107 | + private IotTerminal translateTerminal(Type type,String key, Topic topic , JSONObject jsData,boolean isOperLog, List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list) |
| 113 | { | 108 | { |
| 114 | String id = topic.getClientid()+"_"+key; | 109 | String id = topic.getClientid()+"_"+key; |
| 115 | - JSONObject saveJson = dataModeAnalysisService.analysisThingsModelValue( id,topic.getUsername(),jsData,true,"终端本地"); | 110 | + JSONObject saveJson = dataModeAnalysisService.analysisThingsModelValue( id,topic.getUsername(),jsData,"终端本地",isOperLog,operateHisList,list); |
| 116 | IotTerminal terminal = new IotTerminal(); | 111 | IotTerminal terminal = new IotTerminal(); |
| 117 | terminal.setId(id); | 112 | terminal.setId(id); |
| 118 | terminal.setUpdate_time(DateUtils.getNowTimeMilly()); | 113 | terminal.setUpdate_time(DateUtils.getNowTimeMilly()); |
| @@ -3,6 +3,7 @@ package com.zhonglai.luhui.mqtt.comm.service; | @@ -3,6 +3,7 @@ package com.zhonglai.luhui.mqtt.comm.service; | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.zhonglai.luhui.mqtt.comm.config.RedisConfig; | 5 | import com.zhonglai.luhui.mqtt.comm.config.RedisConfig; |
| 6 | +import com.zhonglai.luhui.mqtt.comm.config.SysParameter; | ||
| 6 | import com.zhonglai.luhui.mqtt.comm.dao.BaseDao; | 7 | 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.DeviceSensorData; |
| 8 | import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | 9 | import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; |
| @@ -11,11 +12,13 @@ import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelBase; | @@ -11,11 +12,13 @@ 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.ThingsModelDataTypeEnum; |
| 12 | import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; | 13 | import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase; |
| 13 | import com.zhonglai.luhui.mqtt.comm.util.DateUtils; | 14 | import com.zhonglai.luhui.mqtt.comm.util.DateUtils; |
| 15 | +import com.zhonglai.luhui.mqtt.comm.util.StringUtils; | ||
| 14 | import org.slf4j.Logger; | 16 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; | 17 | import org.slf4j.LoggerFactory; |
| 16 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
| 17 | import org.springframework.stereotype.Service; | 19 | import org.springframework.stereotype.Service; |
| 18 | 20 | ||
| 21 | +import javax.annotation.PostConstruct; | ||
| 19 | import java.util.ArrayList; | 22 | import java.util.ArrayList; |
| 20 | import java.util.List; | 23 | import java.util.List; |
| 21 | import java.util.Map; | 24 | import java.util.Map; |
| @@ -28,8 +31,6 @@ public class DataModeAnalysisService { | @@ -28,8 +31,6 @@ public class DataModeAnalysisService { | ||
| 28 | private static final Logger log = LoggerFactory.getLogger(DataModeAnalysisService.class); | 31 | private static final Logger log = LoggerFactory.getLogger(DataModeAnalysisService.class); |
| 29 | 32 | ||
| 30 | private BaseDao baseDao = new BaseDao(); | 33 | private BaseDao baseDao = new BaseDao(); |
| 31 | - @Autowired | ||
| 32 | - private RedisService redisService ; | ||
| 33 | 34 | ||
| 34 | @Autowired | 35 | @Autowired |
| 35 | private DeviceLogService dviceLogService; | 36 | private DeviceLogService dviceLogService; |
| @@ -37,43 +38,39 @@ public class DataModeAnalysisService { | @@ -37,43 +38,39 @@ public class DataModeAnalysisService { | ||
| 37 | /** | 38 | /** |
| 38 | * 初始化物模型数据 | 39 | * 初始化物模型数据 |
| 39 | */ | 40 | */ |
| 40 | - public void initDataThingsMode() | 41 | + public void initDataThingsMode(String roleIds,String usernames) |
| 42 | + { | ||
| 43 | + String sql = "SELECT a.*,b.username user_name FROM `mqtt_broker`.`iot_things_model` a LEFT JOIN `mqtt_broker`.`iot_user` b ON a.`user_id`=b.`id` WHERE a.del_flag=0 AND b.`role_id` IN("+roleIds+")"; | ||
| 44 | + if(StringUtils.isNotEmpty(usernames)) | ||
| 41 | { | 45 | { |
| 42 | - List<IotThingsModel> list = baseDao.findBysql("select * from `mqtt_broker`.`iot_things_model` where del_flag=0", IotThingsModel.class); | 46 | + sql += " AND b.`username` IN("+usernames+")"; |
| 47 | + } | ||
| 48 | + List<IotThingsModel> list = baseDao.findBysql(sql, IotThingsModel.class); | ||
| 43 | 49 | ||
| 44 | if(null != list && list.size() != 0) | 50 | if(null != list && list.size() != 0) |
| 45 | { | 51 | { |
| 46 | for(IotThingsModel thingsModel:list) | 52 | for(IotThingsModel thingsModel:list) |
| 47 | { | 53 | { |
| 48 | - redisService.hset(RedisConfig.FIELD+RedisConfig.THINGS_MODEL+thingsModel.getUser_name(),thingsModel.getIdentifier(),thingsModel); | 54 | + SysParameter.setTerminalDataThingsMode(thingsModel.getUser_name(),thingsModel); |
| 49 | } | 55 | } |
| 50 | } | 56 | } |
| 51 | } | 57 | } |
| 52 | - public JSONObject analysisThingsModelValue(String id, String userName , JSONObject jsData) | ||
| 53 | - { | ||
| 54 | - return analysisThingsModelValue(id,userName,jsData,false,null); | ||
| 55 | - } | 58 | + |
| 56 | /** | 59 | /** |
| 57 | * 解析物模型数据 | 60 | * 解析物模型数据 |
| 58 | */ | 61 | */ |
| 59 | - public JSONObject analysisThingsModelValue(String id,String userName ,JSONObject jsData,boolean isSaveLog,String controlModel) | 62 | + public JSONObject analysisThingsModelValue(String id,String userName ,JSONObject jsData,String controlModel,boolean isOperLog, List<LogDeviceOperation> operateHisList, List<DeviceSensorData> list) |
| 60 | { | 63 | { |
| 61 | if(null != jsData && jsData.size() != 0 ) | 64 | if(null != jsData && jsData.size() != 0 ) |
| 62 | { | 65 | { |
| 63 | - Map<Object, Object> thingsModelMap = redisService.hmget(RedisConfig.FIELD+RedisConfig.THINGS_MODEL+userName); | ||
| 64 | JSONObject rObjec = new JSONObject(); | 66 | JSONObject rObjec = new JSONObject(); |
| 65 | 67 | ||
| 66 | - List<DeviceSensorData> list = new ArrayList<>(); | ||
| 67 | - List<LogDeviceOperation> oplist = new ArrayList<>(); | ||
| 68 | 68 | ||
| 69 | for(String key:jsData.keySet()) | 69 | for(String key:jsData.keySet()) |
| 70 | { | 70 | { |
| 71 | - Object object = thingsModelMap.get(key); | ||
| 72 | - IotThingsModel thingsModel = null; | ||
| 73 | - if(object instanceof IotThingsModel) | 71 | + IotThingsModel thingsModel = SysParameter.getTerminalDataThingsMode(userName,key); |
| 72 | + if(null == thingsModel) //没有配置的 都按字符串处理 | ||
| 74 | { | 73 | { |
| 75 | - thingsModel = (IotThingsModel)object; | ||
| 76 | - }else{ //没有配置的 都按字符串处理 | ||
| 77 | thingsModel = new IotThingsModel(); | 74 | thingsModel = new IotThingsModel(); |
| 78 | thingsModel.setData_type(ThingsModelDataTypeEnum.STRING.name()); | 75 | thingsModel.setData_type(ThingsModelDataTypeEnum.STRING.name()); |
| 79 | thingsModel.setIdentifier(key); | 76 | thingsModel.setIdentifier(key); |
| @@ -85,9 +82,15 @@ public class DataModeAnalysisService { | @@ -85,9 +82,15 @@ public class DataModeAnalysisService { | ||
| 85 | jsonObject.put("maxLength",255); | 82 | jsonObject.put("maxLength",255); |
| 86 | thingsModel.setSpecs(jsonObject.toString()); | 83 | thingsModel.setSpecs(jsonObject.toString()); |
| 87 | } | 84 | } |
| 88 | - Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class,thingsModel.getData_type()).getaClass(); | 85 | + String data_type = thingsModel.getData_type().toUpperCase(); |
| 86 | + if(!jsData.get(key).getClass().getSimpleName().toUpperCase().equals(data_type)) | ||
| 87 | + { | ||
| 88 | + data_type = ThingsModelDataTypeEnum.STRING.name(); | ||
| 89 | + } | ||
| 90 | + Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class,data_type).getaClass(); | ||
| 89 | ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(),aClass); | 91 | ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(),aClass); |
| 90 | thingsModelBase.conversionThingsModel(thingsModel); | 92 | thingsModelBase.conversionThingsModel(thingsModel); |
| 93 | + | ||
| 91 | thingsModelBase.addValue(jsData.get(key)); | 94 | thingsModelBase.addValue(jsData.get(key)); |
| 92 | 95 | ||
| 93 | ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase; | 96 | ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase; |
| @@ -96,7 +99,7 @@ public class DataModeAnalysisService { | @@ -96,7 +99,7 @@ public class DataModeAnalysisService { | ||
| 96 | { | 99 | { |
| 97 | DeviceSensorData sensorData = new DeviceSensorData(); | 100 | DeviceSensorData sensorData = new DeviceSensorData(); |
| 98 | sensorData.setDataType(key); | 101 | sensorData.setDataType(key); |
| 99 | - sensorData.setDataValue(jsData.getString(key)); | 102 | + sensorData.setDataValue(thingsModelBase.getSaveView()); |
| 100 | sensorData.setCreatTime(DateUtils.getNowTimeMilly()); | 103 | sensorData.setCreatTime(DateUtils.getNowTimeMilly()); |
| 101 | sensorData.setDeviceModel(userName); | 104 | sensorData.setDeviceModel(userName); |
| 102 | sensorData.setDeviceInfoId(id); | 105 | sensorData.setDeviceInfoId(id); |
| @@ -104,14 +107,14 @@ public class DataModeAnalysisService { | @@ -104,14 +107,14 @@ public class DataModeAnalysisService { | ||
| 104 | } | 107 | } |
| 105 | 108 | ||
| 106 | //记录操作日志 | 109 | //记录操作日志 |
| 107 | - oplist.add(dviceLogService.newLogDeviceOperation(id,jsData.getString(key),null,controlModel+thingsModelItemBase.getName()+"为"+thingsModelBase.getView(),jsData.toString())); | 110 | + if(isOperLog) |
| 111 | + { | ||
| 112 | + operateHisList.add(dviceLogService.newLogDeviceOperation(id,thingsModelBase.getSaveView(),null,controlModel+thingsModelItemBase.getName()+"为"+thingsModelBase.getView(),jsData.toString())); | ||
| 113 | + } | ||
| 108 | 114 | ||
| 109 | rObjec.put(key,JSONObject.toJSONString(thingsModelBase)); | 115 | rObjec.put(key,JSONObject.toJSONString(thingsModelBase)); |
| 110 | } | 116 | } |
| 111 | 117 | ||
| 112 | - //日志入库 | ||
| 113 | - dviceLogService.saveDeviceSensorDataLog(list); | ||
| 114 | - dviceLogService.saveOperationLog(oplist); | ||
| 115 | return rObjec; | 118 | return rObjec; |
| 116 | } | 119 | } |
| 117 | return null; | 120 | return null; |
| 1 | package com.zhonglai.luhui.mqtt.comm.service; | 1 | package com.zhonglai.luhui.mqtt.comm.service; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; | 6 | import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDto; |
| 5 | import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDtoClassNew; | 7 | import com.zhonglai.luhui.mqtt.comm.dto.business.BusinessDtoClassNew; |
| @@ -19,6 +21,8 @@ import org.slf4j.LoggerFactory; | @@ -19,6 +21,8 @@ import org.slf4j.LoggerFactory; | ||
| 19 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
| 20 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
| 21 | 23 | ||
| 24 | +import java.util.List; | ||
| 25 | + | ||
| 22 | @Component | 26 | @Component |
| 23 | public class MqttCallback implements MqttCallbackExtended { | 27 | public class MqttCallback implements MqttCallbackExtended { |
| 24 | private static final Logger log = LoggerFactory.getLogger(MqttCallback.class); | 28 | private static final Logger log = LoggerFactory.getLogger(MqttCallback.class); |
| @@ -79,15 +83,10 @@ public class MqttCallback implements MqttCallbackExtended { | @@ -79,15 +83,10 @@ public class MqttCallback implements MqttCallbackExtended { | ||
| 79 | log.info("{} 解析到的dto【{}】",dto); | 83 | log.info("{} 解析到的dto【{}】",dto); |
| 80 | 84 | ||
| 81 | //缓存数据 | 85 | //缓存数据 |
| 82 | - boolean isPersistence = cacheService.updateCache(topic,dto); | 86 | + cacheService.updateCache(topic,dto); |
| 83 | 87 | ||
| 84 | //数据持久化 | 88 | //数据持久化 |
| 85 | - if(isPersistence) | ||
| 86 | - { | ||
| 87 | - log.info("【{}】数据有更新",topic); | ||
| 88 | dataPersistenceService.persistence(topic,dto); | 89 | dataPersistenceService.persistence(topic,dto); |
| 89 | - } | ||
| 90 | - dataPersistenceService.addDeviceSensorData(topic,dto); | ||
| 91 | 90 | ||
| 92 | } catch (Exception e) { | 91 | } catch (Exception e) { |
| 93 | log.error(s+"消息解析异常",e); | 92 | log.error(s+"消息解析异常",e); |
| 1 | package com.zhonglai.luhui.mqtt.comm.service; | 1 | package com.zhonglai.luhui.mqtt.comm.service; |
| 2 | 2 | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.config.SysParameter; | 3 | import com.zhonglai.luhui.mqtt.comm.config.SysParameter; |
| 4 | +import com.zhonglai.luhui.mqtt.comm.factory.Topic; | ||
| 5 | +import org.apache.commons.lang3.StringUtils; | ||
| 4 | import org.eclipse.paho.client.mqttv3.MqttClient; | 6 | import org.eclipse.paho.client.mqttv3.MqttClient; |
| 5 | import org.eclipse.paho.client.mqttv3.MqttConnectOptions; | 7 | import org.eclipse.paho.client.mqttv3.MqttConnectOptions; |
| 6 | import org.eclipse.paho.client.mqttv3.MqttException; | 8 | import org.eclipse.paho.client.mqttv3.MqttException; |
| @@ -32,6 +34,9 @@ public class TerminalService { | @@ -32,6 +34,9 @@ public class TerminalService { | ||
| 32 | @Autowired | 34 | @Autowired |
| 33 | private SysParameter sysParameter; | 35 | private SysParameter sysParameter; |
| 34 | 36 | ||
| 37 | + @Autowired | ||
| 38 | + private DataModeAnalysisService dataModeAnalysisService; | ||
| 39 | + | ||
| 35 | //业务处理异步线程池,线程池参数可以根据您的业务特点调整,或者您也可以用其他异步方式处理接收到的消息。 | 40 | //业务处理异步线程池,线程池参数可以根据您的业务特点调整,或者您也可以用其他异步方式处理接收到的消息。 |
| 36 | private final static ExecutorService executorService = new ThreadPoolExecutor( | 41 | private final static ExecutorService executorService = new ThreadPoolExecutor( |
| 37 | Runtime.getRuntime().availableProcessors(), | 42 | Runtime.getRuntime().availableProcessors(), |
| @@ -81,10 +86,47 @@ public class TerminalService { | @@ -81,10 +86,47 @@ public class TerminalService { | ||
| 81 | log.info("-----------开始启动mqtt监听服务--------------------"); | 86 | log.info("-----------开始启动mqtt监听服务--------------------"); |
| 82 | init(); | 87 | init(); |
| 83 | log.info("-----------启动参数{}--------------------",options); | 88 | log.info("-----------启动参数{}--------------------",options); |
| 89 | + sysParameter.inittopicconfig(); | ||
| 90 | + log.info("-----------topic配置模型{}--------------------",SysParameter.topicconfig); | ||
| 91 | + initDataThingsMode(); | ||
| 92 | + log.info("-----------终端数据模型配置成功--------------------"); | ||
| 84 | connect(); | 93 | connect(); |
| 94 | + log.info("-----------mqtt连接服务器成功--------------------"); | ||
| 85 | subscribe(); | 95 | subscribe(); |
| 86 | - sysParameter.inittopicconfig(); | ||
| 87 | - log.info("-----------mqtt监听服务启动成功--------------------"); | 96 | + log.info("-----------订阅{}成功--------------------",topics); |
| 97 | + | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + private void initDataThingsMode() | ||
| 101 | + { | ||
| 102 | + String roleids=""; | ||
| 103 | + String usernames=""; | ||
| 104 | + for(String topicstr:topics.split(",")) | ||
| 105 | + { | ||
| 106 | + Topic topic = new Topic(topicstr); | ||
| 107 | + if(null != topic) | ||
| 108 | + { | ||
| 109 | + String rild = topic.getRoleid(); | ||
| 110 | + if(StringUtils.isNoneBlank(rild)) | ||
| 111 | + { | ||
| 112 | + if(!"".equals(roleids)) | ||
| 113 | + { | ||
| 114 | + roleids +=","; | ||
| 115 | + } | ||
| 116 | + roleids +=rild; | ||
| 117 | + } | ||
| 118 | + String username = topic.getUsername(); | ||
| 119 | + if(StringUtils.isNoneBlank(username) && !"+".equals(username)) | ||
| 120 | + { | ||
| 121 | + if(!"".equals(usernames)) | ||
| 122 | + { | ||
| 123 | + usernames +=","; | ||
| 124 | + } | ||
| 125 | + usernames +="'"+username+"'"; | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + } | ||
| 129 | + dataModeAnalysisService.initDataThingsMode(roleids,usernames); | ||
| 88 | } | 130 | } |
| 89 | 131 | ||
| 90 | public void subscribe(String[] topicFilters) throws MqttException { | 132 | public void subscribe(String[] topicFilters) throws MqttException { |
| @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject; | @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject; | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService; | 4 | import com.zhonglai.luhui.mqtt.comm.service.ClienNoticeService; |
| 5 | import com.zhonglai.luhui.mqtt.comm.util.DateUtils; | 5 | import com.zhonglai.luhui.mqtt.comm.util.DateUtils; |
| 6 | import com.zhonglai.luhui.mqtt.dto.Message; | 6 | import com.zhonglai.luhui.mqtt.dto.Message; |
| 7 | -import com.zhonglai.luhui.mqtt.dto.topic.PutDto; | ||
| 8 | import io.swagger.annotations.Api; | 7 | import io.swagger.annotations.Api; |
| 9 | import io.swagger.annotations.ApiOperation; | 8 | import io.swagger.annotations.ApiOperation; |
| 10 | import org.eclipse.paho.client.mqttv3.MqttException; | 9 | import org.eclipse.paho.client.mqttv3.MqttException; |
| 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.alibaba.fastjson.JSONObject; |
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 5 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; | 6 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; |
| 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 7 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 6 | import lombok.Data; | 8 | import lombok.Data; |
| 7 | import lombok.experimental.Accessors; | 9 | import lombok.experimental.Accessors; |
| 8 | 10 | ||
| 11 | +import java.util.ArrayList; | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 9 | @Data | 14 | @Data |
| 10 | @Accessors(chain = true) | 15 | @Accessors(chain = true) |
| 11 | public class AddPostDto implements ServerDto { | 16 | public class AddPostDto implements ServerDto { |
| 17 | + private List<LogDeviceOperation> operateHisList = new ArrayList<>(); | ||
| 18 | + private List<DeviceSensorData> list = new ArrayList<>(); | ||
| 12 | private JSONObject data; | 19 | private JSONObject data; |
| 13 | @Override | 20 | @Override |
| 14 | public ServerAgreementContent getServerAgreementContent() { | 21 | public ServerAgreementContent getServerAgreementContent() { |
| @@ -19,4 +26,14 @@ public class AddPostDto implements ServerDto { | @@ -19,4 +26,14 @@ public class AddPostDto implements ServerDto { | ||
| 19 | public boolean isReplyMessage() { | 26 | public boolean isReplyMessage() { |
| 20 | return false; | 27 | return false; |
| 21 | } | 28 | } |
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public List<DeviceSensorData> getDeviceSensorData() { | ||
| 32 | + return list; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public List<LogDeviceOperation> getOperationLog() { | ||
| 37 | + return operateHisList; | ||
| 38 | + } | ||
| 22 | } | 39 | } |
| 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.alibaba.fastjson.JSONObject; |
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 5 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; | 6 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; |
| 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 7 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 6 | import lombok.Data; | 8 | import lombok.Data; |
| 7 | import lombok.experimental.Accessors; | 9 | import lombok.experimental.Accessors; |
| 8 | 10 | ||
| 11 | +import java.util.ArrayList; | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 9 | @Data | 14 | @Data |
| 10 | @Accessors(chain = true) | 15 | @Accessors(chain = true) |
| 11 | public class AllPostDto implements ServerDto { | 16 | public class AllPostDto implements ServerDto { |
| 17 | + private List<LogDeviceOperation> operateHisList = new ArrayList<>(); | ||
| 18 | + private List<DeviceSensorData> list = new ArrayList<>(); | ||
| 12 | private JSONObject data; | 19 | private JSONObject data; |
| 13 | @Override | 20 | @Override |
| 14 | public ServerAgreementContent getServerAgreementContent() { | 21 | public ServerAgreementContent getServerAgreementContent() { |
| @@ -19,4 +26,14 @@ public class AllPostDto implements ServerDto { | @@ -19,4 +26,14 @@ public class AllPostDto implements ServerDto { | ||
| 19 | public boolean isReplyMessage() { | 26 | public boolean isReplyMessage() { |
| 20 | return false; | 27 | return false; |
| 21 | } | 28 | } |
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public List<DeviceSensorData> getDeviceSensorData() { | ||
| 32 | + return list; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public List<LogDeviceOperation> getOperationLog() { | ||
| 37 | + return operateHisList; | ||
| 38 | + } | ||
| 22 | } | 39 | } |
| 1 | package com.zhonglai.luhui.mqtt.dto.topic; | 1 | package com.zhonglai.luhui.mqtt.dto.topic; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; |
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 6 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 7 | 9 | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 8 | @Data | 12 | @Data |
| 9 | @Accessors(chain = true) | 13 | @Accessors(chain = true) |
| 10 | public class DbDistributeDto implements ServerDto { | 14 | public class DbDistributeDto implements ServerDto { |
| @@ -17,4 +21,14 @@ public class DbDistributeDto implements ServerDto { | @@ -17,4 +21,14 @@ public class DbDistributeDto implements ServerDto { | ||
| 17 | public boolean isReplyMessage() { | 21 | public boolean isReplyMessage() { |
| 18 | return false; | 22 | return false; |
| 19 | } | 23 | } |
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public List<DeviceSensorData> getDeviceSensorData() { | ||
| 27 | + return null; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public List<LogDeviceOperation> getOperationLog() { | ||
| 32 | + return null; | ||
| 33 | + } | ||
| 20 | } | 34 | } |
| 1 | package com.zhonglai.luhui.mqtt.dto.topic; | 1 | package com.zhonglai.luhui.mqtt.dto.topic; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; |
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 6 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 7 | 9 | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 8 | @Data | 12 | @Data |
| 9 | @Accessors(chain = true) | 13 | @Accessors(chain = true) |
| 10 | public class GetDto implements ServerDto { | 14 | public class GetDto implements ServerDto { |
| @@ -17,4 +21,14 @@ public class GetDto implements ServerDto { | @@ -17,4 +21,14 @@ public class GetDto implements ServerDto { | ||
| 17 | public boolean isReplyMessage() { | 21 | public boolean isReplyMessage() { |
| 18 | return false; | 22 | return false; |
| 19 | } | 23 | } |
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public List<DeviceSensorData> getDeviceSensorData() { | ||
| 27 | + return null; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public List<LogDeviceOperation> getOperationLog() { | ||
| 32 | + return null; | ||
| 33 | + } | ||
| 20 | } | 34 | } |
| 1 | package com.zhonglai.luhui.mqtt.dto.topic; | 1 | package com.zhonglai.luhui.mqtt.dto.topic; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; |
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 6 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 7 | 9 | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 8 | @Data | 12 | @Data |
| 9 | @Accessors(chain = true) | 13 | @Accessors(chain = true) |
| 10 | public class GetReqDto implements ServerDto { | 14 | public class GetReqDto implements ServerDto { |
| @@ -17,4 +21,14 @@ public class GetReqDto implements ServerDto { | @@ -17,4 +21,14 @@ public class GetReqDto implements ServerDto { | ||
| 17 | public boolean isReplyMessage() { | 21 | public boolean isReplyMessage() { |
| 18 | return false; | 22 | return false; |
| 19 | } | 23 | } |
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public List<DeviceSensorData> getDeviceSensorData() { | ||
| 27 | + return null; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public List<LogDeviceOperation> getOperationLog() { | ||
| 32 | + return null; | ||
| 33 | + } | ||
| 20 | } | 34 | } |
| 1 | package com.zhonglai.luhui.mqtt.dto.topic; | 1 | package com.zhonglai.luhui.mqtt.dto.topic; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; |
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 6 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 5 | import lombok.Data; | 7 | import lombok.Data; |
| 6 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 7 | 9 | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 8 | @Data | 12 | @Data |
| 9 | @Accessors(chain = true) | 13 | @Accessors(chain = true) |
| 10 | public class OnlineDto implements ServerDto { | 14 | public class OnlineDto implements ServerDto { |
| @@ -17,4 +21,14 @@ public class OnlineDto implements ServerDto { | @@ -17,4 +21,14 @@ public class OnlineDto implements ServerDto { | ||
| 17 | public boolean isReplyMessage() { | 21 | public boolean isReplyMessage() { |
| 18 | return false; | 22 | return false; |
| 19 | } | 23 | } |
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public List<DeviceSensorData> getDeviceSensorData() { | ||
| 27 | + return null; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public List<LogDeviceOperation> getOperationLog() { | ||
| 32 | + return null; | ||
| 33 | + } | ||
| 20 | } | 34 | } |
| 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.DeviceSensorData; |
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; |
| 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 6 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 6 | import lombok.Data; | 7 | import lombok.Data; |
| 7 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 8 | 9 | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 9 | /** | 12 | /** |
| 10 | * 服务器下发数据 | 13 | * 服务器下发数据 |
| 11 | */ | 14 | */ |
| @@ -23,4 +26,14 @@ public class PutDto implements ServerDto { | @@ -23,4 +26,14 @@ public class PutDto implements ServerDto { | ||
| 23 | public boolean isReplyMessage() { | 26 | public boolean isReplyMessage() { |
| 24 | return false; | 27 | return false; |
| 25 | } | 28 | } |
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public List<DeviceSensorData> getDeviceSensorData() { | ||
| 32 | + return null; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public List<LogDeviceOperation> getOperationLog() { | ||
| 37 | + return null; | ||
| 38 | + } | ||
| 26 | } | 39 | } |
| 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.alibaba.fastjson.JSONObject; |
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 5 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; | 6 | import com.zhonglai.luhui.mqtt.comm.dto.ServerAgreementContent; |
| 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 7 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 6 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; | 8 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; |
| @@ -9,6 +11,8 @@ import com.zhonglai.luhui.mqtt.dto.MessageCode; | @@ -9,6 +11,8 @@ import com.zhonglai.luhui.mqtt.dto.MessageCode; | ||
| 9 | import lombok.Data; | 11 | import lombok.Data; |
| 10 | import lombok.experimental.Accessors; | 12 | import lombok.experimental.Accessors; |
| 11 | 13 | ||
| 14 | +import java.util.List; | ||
| 15 | + | ||
| 12 | @Data | 16 | @Data |
| 13 | @Accessors(chain = true) | 17 | @Accessors(chain = true) |
| 14 | public class PutReqDto implements ServerDto { | 18 | public class PutReqDto implements ServerDto { |
| @@ -55,4 +59,14 @@ public class PutReqDto implements ServerDto { | @@ -55,4 +59,14 @@ public class PutReqDto implements ServerDto { | ||
| 55 | public boolean isReplyMessage() { | 59 | public boolean isReplyMessage() { |
| 56 | return true; | 60 | return true; |
| 57 | } | 61 | } |
| 62 | + | ||
| 63 | + @Override | ||
| 64 | + public List<DeviceSensorData> getDeviceSensorData() { | ||
| 65 | + return null; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + @Override | ||
| 69 | + public List<LogDeviceOperation> getOperationLog() { | ||
| 70 | + return null; | ||
| 71 | + } | ||
| 58 | } | 72 | } |
| @@ -10,7 +10,6 @@ import org.springframework.stereotype.Service; | @@ -10,7 +10,6 @@ import org.springframework.stereotype.Service; | ||
| 10 | public class CacheServiceImpl implements CacheService { | 10 | public class CacheServiceImpl implements CacheService { |
| 11 | @Override | 11 | @Override |
| 12 | public boolean updateCache(Topic topic, ServerDto serverDto) { | 12 | public boolean updateCache(Topic topic, ServerDto serverDto) { |
| 13 | - PutReqDto putReqDto = (PutReqDto) serverDto; | ||
| 14 | return true; | 13 | return true; |
| 15 | } | 14 | } |
| 16 | } | 15 | } |
| 1 | package com.zhonglai.luhui.mqtt.service; | 1 | package com.zhonglai.luhui.mqtt.service; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.mqtt.comm.dto.DeviceSensorData; | ||
| 4 | +import com.zhonglai.luhui.mqtt.comm.dto.LogDeviceOperation; | ||
| 3 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; | 5 | import com.zhonglai.luhui.mqtt.comm.dto.ServerDto; |
| 6 | +import com.zhonglai.luhui.mqtt.comm.dto.TableGenerateSqlEnum; | ||
| 4 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; | 7 | import com.zhonglai.luhui.mqtt.comm.factory.Topic; |
| 5 | import com.zhonglai.luhui.mqtt.comm.service.DataPersistenceService; | 8 | import com.zhonglai.luhui.mqtt.comm.service.DataPersistenceService; |
| 9 | +import com.zhonglai.luhui.mqtt.comm.service.DeviceLogService; | ||
| 10 | +import com.zhonglai.luhui.mqtt.dto.topic.AddPostDto; | ||
| 11 | +import com.zhonglai.luhui.mqtt.dto.topic.AllPostDto; | ||
| 6 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
| 7 | import org.slf4j.LoggerFactory; | 13 | import org.slf4j.LoggerFactory; |
| 14 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
| 9 | 16 | ||
| 17 | +import java.util.List; | ||
| 18 | + | ||
| 10 | @Service | 19 | @Service |
| 11 | public class DataPersistenceServiceImpl extends DataPersistenceService { | 20 | public class DataPersistenceServiceImpl extends DataPersistenceService { |
| 12 | private static final Logger log = LoggerFactory.getLogger(DataPersistenceServiceImpl.class); | 21 | private static final Logger log = LoggerFactory.getLogger(DataPersistenceServiceImpl.class); |
| 13 | - | 22 | + @Autowired |
| 23 | + private DeviceLogService dviceLogService; | ||
| 14 | @Override | 24 | @Override |
| 15 | public void persistence(Topic topic, ServerDto serverDto) { | 25 | public void persistence(Topic topic, ServerDto serverDto) { |
| 16 | 26 | ||
| 27 | + //日志入库 | ||
| 28 | + List<DeviceSensorData> dsdList = serverDto.getDeviceSensorData(); | ||
| 29 | + if(null != dsdList && dsdList.size() != 0) | ||
| 30 | + { | ||
| 31 | + dviceLogService.saveDeviceSensorDataLog(dsdList); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + List<LogDeviceOperation> doList = serverDto.getOperationLog(); | ||
| 35 | + if(null != doList && doList.size() != 0) | ||
| 36 | + { | ||
| 37 | + dviceLogService.saveOperationLog(doList); | ||
| 38 | + } | ||
| 17 | } | 39 | } |
| 18 | 40 | ||
| 19 | @Override | 41 | @Override |
| 20 | public void addDeviceSensorData(Topic topic, ServerDto serverDto) { | 42 | public void addDeviceSensorData(Topic topic, ServerDto serverDto) { |
| 21 | - | 43 | + if(serverDto instanceof AddPostDto) |
| 44 | + { | ||
| 45 | + AddPostDto addPostDto = (AddPostDto) serverDto; | ||
| 46 | + List<DeviceSensorData> list = addPostDto.getList(); | ||
| 47 | + if(null != list && list.size() != 0) | ||
| 48 | + { | ||
| 49 | + baseDao.insertList(list, TableGenerateSqlEnum.DeviceSensorData.getNowTableName()); | ||
| 50 | + } | ||
| 51 | + }else if(serverDto instanceof AllPostDto) | ||
| 52 | + { | ||
| 53 | + AllPostDto allPostDto = (AllPostDto) serverDto; | ||
| 54 | + List<DeviceSensorData> list = allPostDto.getList(); | ||
| 55 | + if(null != list && list.size() != 0) | ||
| 56 | + { | ||
| 57 | + baseDao.insertList(list, TableGenerateSqlEnum.DeviceSensorData.getNowTableName()); | ||
| 58 | + } | ||
| 59 | + } | ||
| 22 | } | 60 | } |
| 23 | 61 | ||
| 24 | @Override | 62 | @Override |
| @@ -121,16 +121,6 @@ public class DeviceService { | @@ -121,16 +121,6 @@ public class DeviceService { | ||
| 121 | setRedicTerminal(terminal); | 121 | setRedicTerminal(terminal); |
| 122 | baseDao.saveOrUpdateObject(terminal); | 122 | baseDao.saveOrUpdateObject(terminal); |
| 123 | } | 123 | } |
| 124 | - /** | ||
| 125 | - * 获取 | ||
| 126 | - * @param username | ||
| 127 | - * @return | ||
| 128 | - */ | ||
| 129 | - public IotThingsModel getThingsModelsByUserIdAndIdentifier(String username, String identifier) | ||
| 130 | - { | ||
| 131 | - Object object = redisService.hget(RedisConfig.FIELD+RedisConfig.THINGS_MODEL+username,identifier); | ||
| 132 | - return null != object?(IotThingsModel)object:null; | ||
| 133 | - } | ||
| 134 | 124 | ||
| 135 | /** | 125 | /** |
| 136 | * 增量更新数据 | 126 | * 增量更新数据 |
| @@ -21,8 +21,9 @@ public class AddPostTopic implements BusinessAgreement<AddPostDto> { | @@ -21,8 +21,9 @@ public class AddPostTopic implements BusinessAgreement<AddPostDto> { | ||
| 21 | private BusinessDataUpdateService businessDataUpdateService ; | 21 | private BusinessDataUpdateService businessDataUpdateService ; |
| 22 | @Override | 22 | @Override |
| 23 | public ServerDto analysis(Topic topic, AddPostDto data) { | 23 | public ServerDto analysis(Topic topic, AddPostDto data) { |
| 24 | - businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ADD,topic,data.getData()); | ||
| 25 | - return null; | 24 | + |
| 25 | + businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ADD,topic,data.getData(),true,data.getOperateHisList(),data.getList()); | ||
| 26 | + return data; | ||
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | @Override | 29 | @Override |
| @@ -21,8 +21,8 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | @@ -21,8 +21,8 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | ||
| 21 | private BusinessDataUpdateService businessDataUpdateService ; | 21 | private BusinessDataUpdateService businessDataUpdateService ; |
| 22 | @Override | 22 | @Override |
| 23 | 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()); | ||
| 25 | - return null; | 24 | + businessDataUpdateService.updataDta(BusinessDataUpdateService.Type.ALL,topic,data.getData(),false,data.getOperateHisList(),data.getList()); |
| 25 | + return data; | ||
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | @Override | 28 | @Override |
| @@ -44,7 +44,7 @@ mqtt: | @@ -44,7 +44,7 @@ mqtt: | ||
| 44 | #唯一标识 | 44 | #唯一标识 |
| 45 | clientId: lh-mqtt-service-001 | 45 | clientId: lh-mqtt-service-001 |
| 46 | #订阅的topic | 46 | #订阅的topic |
| 47 | - topics: "/+/+/+/+/ADD_POST,/+/+/+/+/ALL_POST,/+/+/+/+/DB_TOPIC_DISTRIBUTE,/+/+/+/+/GET,/+/+/+/online,/+/+/+/+/PUT_REQ" | 47 | + topics: "/2/+/+/+/ADD_POST,/2/+/+/+/ALL_POST,/2/+/+/+/DB_TOPIC_DISTRIBUTE,/2/+/+/+/GET,/2/+/+/+/online,/2/+/+/+/PUT_REQ" |
| 48 | topicconfig: "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}" | 48 | topicconfig: "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}" |
| 49 | username: sysuser | 49 | username: sysuser |
| 50 | password: "!@#1qaz" | 50 | password: "!@#1qaz" |
| @@ -155,5 +155,23 @@ | @@ -155,5 +155,23 @@ | ||
| 155 | <groupId>com.squareup.okhttp3</groupId> | 155 | <groupId>com.squareup.okhttp3</groupId> |
| 156 | <artifactId>okhttp</artifactId> | 156 | <artifactId>okhttp</artifactId> |
| 157 | </dependency> | 157 | </dependency> |
| 158 | + | ||
| 159 | + <!-- 自定义验证注解 --> | ||
| 160 | + <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation --> | ||
| 161 | + <dependency> | ||
| 162 | + <groupId>org.springframework.boot</groupId> | ||
| 163 | + <artifactId>spring-boot-starter-validation</artifactId> | ||
| 164 | + </dependency> | ||
| 165 | + | ||
| 166 | + <dependency> | ||
| 167 | + <groupId>org.jboss.logging</groupId> | ||
| 168 | + <artifactId>jboss-logging</artifactId> | ||
| 169 | + <version>3.4.3.Final</version> | ||
| 170 | + </dependency> | ||
| 171 | + <dependency> | ||
| 172 | + <groupId>jakarta.validation</groupId> | ||
| 173 | + <artifactId>jakarta.validation-api</artifactId> | ||
| 174 | + <version>2.0.2</version> | ||
| 175 | + </dependency> | ||
| 158 | </dependencies> | 176 | </dependencies> |
| 159 | </project> | 177 | </project> |
| @@ -72,7 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -72,7 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 72 | <if test="update_by != null">#{update_by},</if> | 72 | <if test="update_by != null">#{update_by},</if> |
| 73 | <if test="update_time != null">#{update_time},</if> | 73 | <if test="update_time != null">#{update_time},</if> |
| 74 | <if test="user_id != null">#{user_id},</if> | 74 | <if test="user_id != null">#{user_id},</if> |
| 75 | - UNIX_TIMESTAMP(NOW()), | 75 | + TIMESTAMP(NOW()), |
| 76 | </trim> | 76 | </trim> |
| 77 | </insert> | 77 | </insert> |
| 78 | 78 |
-
请 注册 或 登录 后发表评论