正在显示
30 个修改的文件
包含
358 行增加
和
64 行删除
| @@ -16,4 +16,9 @@ public interface ThingsModelBase<T> { | @@ -16,4 +16,9 @@ public interface ThingsModelBase<T> { | ||
| 16 | boolean checkValue(); | 16 | boolean checkValue(); |
| 17 | 17 | ||
| 18 | void setSaveView(String value); | 18 | void setSaveView(String value); |
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 反转值 | ||
| 22 | + */ | ||
| 23 | + void reverse(String value); | ||
| 19 | } | 24 | } |
| @@ -15,65 +15,56 @@ import lombok.Data; | @@ -15,65 +15,56 @@ import lombok.Data; | ||
| 15 | @Data | 15 | @Data |
| 16 | public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> | 16 | public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> |
| 17 | { | 17 | { |
| 18 | - | ||
| 19 | - public static ThingsModelItemBase newhingsModelItem(ThingsModelDataTypeEnum thingsModelDataTypeEnum,IotThingsModel thingsModel,JsonElement jsonElement) | 18 | + /** |
| 19 | + * 下位机端数据转换物模型 | ||
| 20 | + * @param thingsModelDataTypeEnum | ||
| 21 | + * @param thingsModel | ||
| 22 | + * @param jsonElement | ||
| 23 | + * @return | ||
| 24 | + */ | ||
| 25 | + public static ThingsModelItemBase newhingsModel(ThingsModelDataTypeEnum thingsModelDataTypeEnum,IotThingsModel thingsModel,JsonElement jsonElement) | ||
| 20 | { | 26 | { |
| 21 | if (!jsonElement.isJsonNull()) | 27 | if (!jsonElement.isJsonNull()) |
| 22 | { | 28 | { |
| 23 | - String specs = thingsModel.getSpecs(); | ||
| 24 | - if(StringUtils.isEmpty(specs)) | ||
| 25 | - { | ||
| 26 | - specs = new JsonObject().toString(); | ||
| 27 | - } | ||
| 28 | - ThingsModelItemBase thingsModelItemBase = GsonConstructor.get().fromJson(specs,StringModelOutput.class); | ||
| 29 | - switch (thingsModelDataTypeEnum) | ||
| 30 | - { | ||
| 31 | - case STRING: | ||
| 32 | - thingsModelItemBase.setValue(jsonElement.getAsString()); | ||
| 33 | - break; | ||
| 34 | - case BOOL: | ||
| 35 | - thingsModelItemBase = GsonConstructor.get().fromJson(specs,BoolModelOutput.class); | ||
| 36 | - thingsModelItemBase.setValue(Boolean.parseBoolean(jsonElement.getAsString()) || jsonElement.getAsString().equals("1")); | ||
| 37 | - break; | ||
| 38 | - case ENUM: | ||
| 39 | - thingsModelItemBase = GsonConstructor.get().fromJson(specs,EnumModelOutput.class); | ||
| 40 | - thingsModelItemBase.setValue(jsonElement.getAsString()); | ||
| 41 | - break; | ||
| 42 | - case ARRAY: | ||
| 43 | - thingsModelItemBase = GsonConstructor.get().fromJson(specs,ArrayModelOutput.class); | ||
| 44 | - thingsModelItemBase.setValue(jsonElement.getAsJsonArray()); | ||
| 45 | - break; | ||
| 46 | - case DECIMAL: | ||
| 47 | - thingsModelItemBase = GsonConstructor.get().fromJson(specs,DecimalModelOutput.class); | ||
| 48 | - thingsModelItemBase.setValue(jsonElement.getAsBigDecimal()); | ||
| 49 | - break; | ||
| 50 | - case INTEGER: | ||
| 51 | - thingsModelItemBase = GsonConstructor.get().fromJson(specs,IntegerModelOutput.class); | ||
| 52 | - thingsModelItemBase.setValue(jsonElement.getAsInt()); | ||
| 53 | - break; | ||
| 54 | - } | ||
| 55 | - thingsModelItemBase.setSaveView(jsonElement.getAsString()); | 29 | + ThingsModelItemBase thingsModelItemBase = createThingsModelItemBase(thingsModelDataTypeEnum,thingsModel,jsonElement); |
| 56 | thingsModelItemBase.conversionThingsModel(thingsModel); | 30 | thingsModelItemBase.conversionThingsModel(thingsModel); |
| 57 | - | 31 | + thingsModelItemBase.setSaveView(jsonElement.getAsString()); |
| 58 | return thingsModelItemBase; | 32 | return thingsModelItemBase; |
| 59 | } | 33 | } |
| 60 | return null; | 34 | return null; |
| 61 | } | 35 | } |
| 62 | 36 | ||
| 63 | - public static ThingsModelItemBase newhingsModelItemFromControl(ThingsModelDataTypeEnum thingsModelDataTypeEnum,IotThingsModel thingsModel,JsonElement jsonElement) | 37 | + /** |
| 38 | + * 上位机端数据转换物模型 | ||
| 39 | + * @param thingsModelDataTypeEnum | ||
| 40 | + * @param thingsModel | ||
| 41 | + * @param jsonElement | ||
| 42 | + * @return | ||
| 43 | + */ | ||
| 44 | + public static ThingsModelItemBase newhingsModelReverse(ThingsModelDataTypeEnum thingsModelDataTypeEnum,IotThingsModel thingsModel,JsonElement jsonElement) | ||
| 64 | { | 45 | { |
| 65 | if (!jsonElement.isJsonNull()) | 46 | if (!jsonElement.isJsonNull()) |
| 66 | { | 47 | { |
| 48 | + ThingsModelItemBase thingsModelItemBase = createThingsModelItemBase(thingsModelDataTypeEnum,thingsModel,jsonElement); | ||
| 49 | + thingsModelItemBase.conversionThingsModel(thingsModel); | ||
| 50 | + thingsModelItemBase.reverse(jsonElement.getAsString()); | ||
| 51 | + return thingsModelItemBase; | ||
| 52 | + } | ||
| 53 | + return null; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + private static ThingsModelItemBase createThingsModelItemBase(ThingsModelDataTypeEnum thingsModelDataTypeEnum,IotThingsModel thingsModel,JsonElement jsonElement) | ||
| 57 | + { | ||
| 67 | String specs = thingsModel.getSpecs(); | 58 | String specs = thingsModel.getSpecs(); |
| 68 | if(StringUtils.isEmpty(specs)) | 59 | if(StringUtils.isEmpty(specs)) |
| 69 | { | 60 | { |
| 70 | specs = new JsonObject().toString(); | 61 | specs = new JsonObject().toString(); |
| 71 | } | 62 | } |
| 72 | - ThingsModelItemBase thingsModelItemBase = GsonConstructor.get().fromJson(specs,StringModelOutput.class); | 63 | + ThingsModelItemBase thingsModelItemBase = null; |
| 73 | switch (thingsModelDataTypeEnum) | 64 | switch (thingsModelDataTypeEnum) |
| 74 | { | 65 | { |
| 75 | case STRING: | 66 | case STRING: |
| 76 | - thingsModelItemBase.setSaveView(jsonElement.getAsString()); | 67 | + thingsModelItemBase = GsonConstructor.get().fromJson(specs,StringModelOutput.class); |
| 77 | break; | 68 | break; |
| 78 | case BOOL: | 69 | case BOOL: |
| 79 | thingsModelItemBase = GsonConstructor.get().fromJson(specs,BoolModelOutput.class); | 70 | thingsModelItemBase = GsonConstructor.get().fromJson(specs,BoolModelOutput.class); |
| @@ -90,14 +81,12 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> | @@ -90,14 +81,12 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> | ||
| 90 | case INTEGER: | 81 | case INTEGER: |
| 91 | thingsModelItemBase = GsonConstructor.get().fromJson(specs,IntegerModelOutput.class); | 82 | thingsModelItemBase = GsonConstructor.get().fromJson(specs,IntegerModelOutput.class); |
| 92 | break; | 83 | break; |
| 84 | + default: | ||
| 85 | + thingsModelItemBase = GsonConstructor.get().fromJson(specs,StringModelOutput.class); | ||
| 86 | + break; | ||
| 93 | } | 87 | } |
| 94 | - thingsModelItemBase.setSaveView(jsonElement.getAsString()); | ||
| 95 | - thingsModelItemBase.conversionThingsModel(thingsModel); | ||
| 96 | - | ||
| 97 | return thingsModelItemBase; | 88 | return thingsModelItemBase; |
| 98 | } | 89 | } |
| 99 | - return null; | ||
| 100 | - } | ||
| 101 | 90 | ||
| 102 | public static ThingsModelItemBase newhingsModelItem(JsonObject jsonObject) | 91 | public static ThingsModelItemBase newhingsModelItem(JsonObject jsonObject) |
| 103 | { | 92 | { |
| @@ -48,4 +48,9 @@ public class ArrayModelOutput extends ThingsModelItemBase<JsonArray> | @@ -48,4 +48,9 @@ public class ArrayModelOutput extends ThingsModelItemBase<JsonArray> | ||
| 48 | public void setSaveView(String value) { | 48 | public void setSaveView(String value) { |
| 49 | setValue(JSONArray.parseObject(value, JsonArray.class)); | 49 | setValue(JSONArray.parseObject(value, JsonArray.class)); |
| 50 | } | 50 | } |
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public void reverse(String value) { | ||
| 54 | + setValue(JSONArray.parseObject(value, JsonArray.class)); | ||
| 55 | + } | ||
| 51 | } | 56 | } |
| @@ -48,4 +48,9 @@ public class BoolModelOutput extends ThingsModelItemBase<Boolean> | @@ -48,4 +48,9 @@ public class BoolModelOutput extends ThingsModelItemBase<Boolean> | ||
| 48 | public void setSaveView(String value) { | 48 | public void setSaveView(String value) { |
| 49 | setValue(value.equals("1") || Boolean.parseBoolean(value) ); | 49 | setValue(value.equals("1") || Boolean.parseBoolean(value) ); |
| 50 | } | 50 | } |
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public void reverse(String value) { | ||
| 54 | + setValue(value.equals("1") || Boolean.parseBoolean(value) ); | ||
| 55 | + } | ||
| 51 | } | 56 | } |
| @@ -69,6 +69,12 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal> | @@ -69,6 +69,12 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal> | ||
| 69 | } | 69 | } |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | + @Override | ||
| 73 | + public void reverse(String value) { | ||
| 74 | + BigDecimal bigDecimalValue = new BigDecimal(value); | ||
| 75 | + setValue(bigDecimalValue); | ||
| 76 | + } | ||
| 77 | + | ||
| 72 | private int getDecimalPlaces(BigDecimal number) { | 78 | private int getDecimalPlaces(BigDecimal number) { |
| 73 | if (number == null || number.scale() <= 0) { | 79 | if (number == null || number.scale() <= 0) { |
| 74 | return 0; | 80 | return 0; |
| @@ -69,6 +69,11 @@ public class EnumModelOutput extends ThingsModelItemBase<String> | @@ -69,6 +69,11 @@ public class EnumModelOutput extends ThingsModelItemBase<String> | ||
| 69 | setValue(value); | 69 | setValue(value); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | + @Override | ||
| 73 | + public void reverse(String value) { | ||
| 74 | + setValue(value); | ||
| 75 | + } | ||
| 76 | + | ||
| 72 | private static Object conversion(Object data ,String clas) { | 77 | private static Object conversion(Object data ,String clas) { |
| 73 | try { | 78 | try { |
| 74 | return stringToTarget(String.valueOf(data),Class.forName(clas)); | 79 | return stringToTarget(String.valueOf(data),Class.forName(clas)); |
| @@ -75,6 +75,12 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> | @@ -75,6 +75,12 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> | ||
| 75 | @Override | 75 | @Override |
| 76 | public void setSaveView(String value) { | 76 | public void setSaveView(String value) { |
| 77 | BigDecimal bigDecimal = new BigDecimal(value); | 77 | BigDecimal bigDecimal = new BigDecimal(value); |
| 78 | + setValue(bigDecimal.intValue()); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + @Override | ||
| 82 | + public void reverse(String value) { | ||
| 83 | + BigDecimal bigDecimal = new BigDecimal(value); | ||
| 78 | setValue(bigDecimal.multiply(new BigDecimal(acy)).intValue()); | 84 | setValue(bigDecimal.multiply(new BigDecimal(acy)).intValue()); |
| 79 | } | 85 | } |
| 80 | } | 86 | } |
| @@ -40,4 +40,9 @@ public class StringModelOutput extends ThingsModelItemBase<String> | @@ -40,4 +40,9 @@ public class StringModelOutput extends ThingsModelItemBase<String> | ||
| 40 | public void setSaveView(String value) { | 40 | public void setSaveView(String value) { |
| 41 | setValue(value); | 41 | setValue(value); |
| 42 | } | 42 | } |
| 43 | + | ||
| 44 | + @Override | ||
| 45 | + public void reverse(String value) { | ||
| 46 | + setValue(value); | ||
| 47 | + } | ||
| 43 | } | 48 | } |
| 1 | package com.zhonglai.luhui.device.analysis.comm.service; | 1 | package com.zhonglai.luhui.device.analysis.comm.service; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | +import com.google.gson.JsonElement; | ||
| 5 | +import com.google.gson.JsonObject; | ||
| 6 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 4 | import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; | 7 | import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; |
| 5 | import com.zhonglai.luhui.device.analysis.comm.db.DeviceService; | 8 | import com.zhonglai.luhui.device.analysis.comm.db.DeviceService; |
| 9 | +import com.zhonglai.luhui.device.analysis.comm.db.mode.TerminalDataThingsModeService; | ||
| 6 | import com.zhonglai.luhui.device.analysis.comm.dto.ServerDto; | 10 | import com.zhonglai.luhui.device.analysis.comm.dto.ServerDto; |
| 11 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelBase; | ||
| 12 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | ||
| 13 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 7 | import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; | 14 | import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; |
| 8 | import com.zhonglai.luhui.device.analysis.dto.SaveDataDto; | 15 | import com.zhonglai.luhui.device.analysis.dto.SaveDataDto; |
| 9 | import com.zhonglai.luhui.device.analysis.dto.topic.AddPostDto; | 16 | import com.zhonglai.luhui.device.analysis.dto.topic.AddPostDto; |
| @@ -11,6 +18,8 @@ import com.zhonglai.luhui.device.analysis.dto.topic.AllPostDto; | @@ -11,6 +18,8 @@ import com.zhonglai.luhui.device.analysis.dto.topic.AllPostDto; | ||
| 11 | import com.zhonglai.luhui.device.domain.IotDevice; | 18 | import com.zhonglai.luhui.device.domain.IotDevice; |
| 12 | import com.zhonglai.luhui.device.domain.IotTerminal; | 19 | import com.zhonglai.luhui.device.domain.IotTerminal; |
| 13 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 20 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 21 | +import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 22 | +import org.apache.commons.lang3.EnumUtils; | ||
| 14 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; | 24 | import org.slf4j.LoggerFactory; |
| 16 | import org.springframework.beans.BeanUtils; | 25 | import org.springframework.beans.BeanUtils; |
| @@ -49,6 +58,9 @@ public class BusinessDataUpdateService { | @@ -49,6 +58,9 @@ public class BusinessDataUpdateService { | ||
| 49 | 58 | ||
| 50 | @Value("${sys.isText:false}") | 59 | @Value("${sys.isText:false}") |
| 51 | private Boolean isText; | 60 | private Boolean isText; |
| 61 | + | ||
| 62 | + @Autowired | ||
| 63 | + private TerminalDataThingsModeService terminalDataThingsModeService; | ||
| 52 | /** | 64 | /** |
| 53 | * 更新数据 | 65 | * 更新数据 |
| 54 | * @param type | 66 | * @param type |
| @@ -256,4 +268,6 @@ public class BusinessDataUpdateService { | @@ -256,4 +268,6 @@ public class BusinessDataUpdateService { | ||
| 256 | String[] notNullField = new String[notNullFieldSet.size()]; | 268 | String[] notNullField = new String[notNullFieldSet.size()]; |
| 257 | return notNullFieldSet.toArray(notNullField); | 269 | return notNullFieldSet.toArray(notNullField); |
| 258 | } | 270 | } |
| 271 | + | ||
| 272 | + | ||
| 259 | } | 273 | } |
| @@ -89,7 +89,7 @@ public class DataModeAnalysisService { | @@ -89,7 +89,7 @@ public class DataModeAnalysisService { | ||
| 89 | { | 89 | { |
| 90 | data_type = ThingsModelDataTypeEnum.STRING.name(); | 90 | data_type = ThingsModelDataTypeEnum.STRING.name(); |
| 91 | } | 91 | } |
| 92 | - ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel, gsonData.get(key)); | 92 | + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModel(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel, gsonData.get(key)); |
| 93 | 93 | ||
| 94 | if(!thingsModelItemBase.checkValue()) | 94 | if(!thingsModelItemBase.checkValue()) |
| 95 | { | 95 | { |
| @@ -55,6 +55,7 @@ public class RocketMqService { | @@ -55,6 +55,7 @@ public class RocketMqService { | ||
| 55 | org.apache.rocketmq.common.message.Message msg = new org.apache.rocketmq.common.message.Message(topic,null==operation_token?sendTags:operation_token,payload); | 55 | org.apache.rocketmq.common.message.Message msg = new org.apache.rocketmq.common.message.Message(topic,null==operation_token?sendTags:operation_token,payload); |
| 56 | try { | 56 | try { |
| 57 | org.apache.rocketmq.common.message.Message ms = rocketMQTemplate.getProducer().request(msg,30000l); | 57 | org.apache.rocketmq.common.message.Message ms = rocketMQTemplate.getProducer().request(msg,30000l); |
| 58 | + | ||
| 58 | JSONObject jsonObject = (JSONObject) JSON.parse(new String(ms.getBody())); | 59 | JSONObject jsonObject = (JSONObject) JSON.parse(new String(ms.getBody())); |
| 59 | return new Message(MessageCode.getMessageCode(jsonObject.getInteger("code")),jsonObject.getString("message"),jsonObject.get("data")); | 60 | return new Message(MessageCode.getMessageCode(jsonObject.getInteger("code")),jsonObject.getString("message"),jsonObject.get("data")); |
| 60 | } catch (RequestTimeoutException e) { | 61 | } catch (RequestTimeoutException e) { |
| @@ -174,7 +174,7 @@ public class IotDeviceController extends BaseController | @@ -174,7 +174,7 @@ public class IotDeviceController extends BaseController | ||
| 174 | } | 174 | } |
| 175 | String[] sts = iotProductClass.getSub_topics().split(","); | 175 | String[] sts = iotProductClass.getSub_topics().split(","); |
| 176 | 176 | ||
| 177 | - if(iotDevice.getCompletion_auth()==1) | 177 | + if(iotDevice.getCompletion_auth()==0) |
| 178 | { | 178 | { |
| 179 | String name= ""; | 179 | String name= ""; |
| 180 | for (int i=0;i<sts.length;i++) | 180 | for (int i=0;i<sts.length;i++) |
| @@ -13,6 +13,7 @@ import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | @@ -13,6 +13,7 @@ import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 13 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
| 14 | import org.slf4j.LoggerFactory; | 14 | import org.slf4j.LoggerFactory; |
| 15 | 15 | ||
| 16 | +import java.nio.charset.StandardCharsets; | ||
| 16 | import java.util.Arrays; | 17 | import java.util.Arrays; |
| 17 | 18 | ||
| 18 | /** | 19 | /** |
| @@ -49,10 +50,16 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | @@ -49,10 +50,16 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | ||
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | @Override | 52 | @Override |
| 52 | - public boolean notice(String deviceId, JsonObject jsonObject) { | 53 | + public NoticeMessageDto notice(String deviceId, JsonObject jsonObject) { |
| 53 | ParserDeviceHostDto parserDeviceHostDto = DeviceCach.getDeviceHost(deviceId); | 54 | ParserDeviceHostDto parserDeviceHostDto = DeviceCach.getDeviceHost(deviceId); |
| 54 | HttpNoticeCach.putUpdataData(parserDeviceHostDto,jsonObject); | 55 | HttpNoticeCach.putUpdataData(parserDeviceHostDto,jsonObject); |
| 55 | - return true; | 56 | + NoticeMessageDto noticeMessageDomain = new NoticeMessageDto(); |
| 57 | + noticeMessageDomain.setTopicconfig(topicconfig); | ||
| 58 | + noticeMessageDomain.setCommd(jsonObject.toString().getBytes(StandardCharsets.UTF_8)); | ||
| 59 | + Topic topic = new Topic(); | ||
| 60 | + topic.setClientid(deviceId); | ||
| 61 | + noticeMessageDomain.setTopic(topic); | ||
| 62 | + return noticeMessageDomain; | ||
| 56 | } | 63 | } |
| 57 | 64 | ||
| 58 | 65 |
| @@ -46,8 +46,8 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | @@ -46,8 +46,8 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | ||
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | @Override | 48 | @Override |
| 49 | - public boolean notice(String deviceId, JsonObject jsonObject) { | ||
| 50 | - return false; | 49 | + public NoticeMessageDto notice(String deviceId, JsonObject jsonObject) { |
| 50 | + return null; | ||
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | /** | 53 | /** |
| 1 | package com.zhonglai.luhui.device.protocol.factory.config; | 1 | package com.zhonglai.luhui.device.protocol.factory.config; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 3 | import com.google.gson.JsonObject; | 4 | import com.google.gson.JsonObject; |
| 5 | +import com.google.gson.internal.LinkedTreeMap; | ||
| 6 | +import com.google.gson.reflect.TypeToken; | ||
| 4 | import com.ruoyi.common.utils.GsonConstructor; | 7 | import com.ruoyi.common.utils.GsonConstructor; |
| 5 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | 8 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; |
| 6 | import net.jodah.expiringmap.ExpirationListener; | 9 | import net.jodah.expiringmap.ExpirationListener; |
| @@ -30,11 +33,12 @@ public class HttpNoticeCach { | @@ -30,11 +33,12 @@ public class HttpNoticeCach { | ||
| 30 | 33 | ||
| 31 | public static void putUpdataData(ParserDeviceHostDto parserDeviceHostDto, JsonObject jsonObject) | 34 | public static void putUpdataData(ParserDeviceHostDto parserDeviceHostDto, JsonObject jsonObject) |
| 32 | { | 35 | { |
| 36 | + Map<String, Object> map = JSONObject.parseObject(jsonObject.toString(), new com.alibaba.fastjson.TypeReference<Map<String, Object>>(){}); | ||
| 33 | if(noticeUpdataData.containsKey(parserDeviceHostDto.getId())) | 37 | if(noticeUpdataData.containsKey(parserDeviceHostDto.getId())) |
| 34 | { | 38 | { |
| 35 | - noticeUpdataData.put(parserDeviceHostDto.getId(), GsonConstructor.get().fromJson(jsonObject.toString(), HashMap.class)); | 39 | + noticeUpdataData.put(parserDeviceHostDto.getId(), map); |
| 36 | }else { | 40 | }else { |
| 37 | - noticeUpdataData.put(parserDeviceHostDto.getId(),GsonConstructor.get().fromJson(jsonObject.toString(), HashMap.class),parserDeviceHostDto.getDevice_life()*3,TimeUnit.SECONDS); | 41 | + noticeUpdataData.put(parserDeviceHostDto.getId(),map,parserDeviceHostDto.getDevice_life()*3,TimeUnit.SECONDS); |
| 38 | } | 42 | } |
| 39 | } | 43 | } |
| 40 | 44 |
| @@ -3,15 +3,18 @@ package com.zhonglai.luhui.device.protocol.factory.control; | @@ -3,15 +3,18 @@ package com.zhonglai.luhui.device.protocol.factory.control; | ||
| 3 | import cn.hutool.extra.spring.SpringUtil; | 3 | import cn.hutool.extra.spring.SpringUtil; |
| 4 | import com.google.gson.JsonObject; | 4 | import com.google.gson.JsonObject; |
| 5 | import com.ruoyi.common.utils.GsonConstructor; | 5 | import com.ruoyi.common.utils.GsonConstructor; |
| 6 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 6 | import com.zhonglai.luhui.device.analysis.comm.clien.ClienConnection; | 7 | import com.zhonglai.luhui.device.analysis.comm.clien.ClienConnection; |
| 7 | import com.zhonglai.luhui.device.analysis.comm.clien.impl.ClienConnectionImpl; | 8 | import com.zhonglai.luhui.device.analysis.comm.clien.impl.ClienConnectionImpl; |
| 8 | import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; | 9 | import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; |
| 9 | import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; | 10 | import com.zhonglai.luhui.device.analysis.comm.dto.ApiClientRePlyDto; |
| 10 | import com.zhonglai.luhui.device.analysis.comm.dto.TerminalClientRePlyDto; | 11 | import com.zhonglai.luhui.device.analysis.comm.dto.TerminalClientRePlyDto; |
| 11 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 12 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 13 | +import com.zhonglai.luhui.device.analysis.comm.service.BusinessDataUpdateService; | ||
| 12 | import com.zhonglai.luhui.device.analysis.dto.Message; | 14 | import com.zhonglai.luhui.device.analysis.dto.Message; |
| 13 | import com.zhonglai.luhui.device.analysis.dto.MessageCode; | 15 | import com.zhonglai.luhui.device.analysis.dto.MessageCode; |
| 14 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; | 16 | import com.zhonglai.luhui.device.analysis.util.TopicUtil; |
| 17 | +import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 15 | import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; | 18 | import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; |
| 16 | import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | 19 | import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; |
| 17 | import com.zhonglai.luhui.device.protocol.factory.config.PluginsClassLoader; | 20 | import com.zhonglai.luhui.device.protocol.factory.config.PluginsClassLoader; |
| @@ -54,7 +57,7 @@ import java.util.concurrent.TimeUnit; | @@ -54,7 +57,7 @@ import java.util.concurrent.TimeUnit; | ||
| 54 | * 设备指令监听服务 | 57 | * 设备指令监听服务 |
| 55 | */ | 58 | */ |
| 56 | @Service | 59 | @Service |
| 57 | -@RocketMQMessageListener(consumerGroup = "deviceCommand", topic = "deviceCommandListen",selectorType = SelectorType.TAG,selectorExpression = "${rocketmq.operationToken}",messageModel = MessageModel.BROADCASTING) | 60 | +@RocketMQMessageListener(consumerGroup = "${rocketmq.consumerGroup}", topic = "deviceCommandListen",selectorType = SelectorType.TAG,selectorExpression = "${rocketmq.operationToken}",messageModel = MessageModel.BROADCASTING) |
| 58 | public class DeviceCommandListenService implements RocketMQReplyListener<MessageExt, Message>, RocketMQPushConsumerLifecycleListener { | 61 | public class DeviceCommandListenService implements RocketMQReplyListener<MessageExt, Message>, RocketMQPushConsumerLifecycleListener { |
| 59 | private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenService.class); | 62 | private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenService.class); |
| 60 | 63 | ||
| @@ -80,6 +83,8 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | @@ -80,6 +83,8 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | ||
| 80 | 83 | ||
| 81 | private String selectorExpression; | 84 | private String selectorExpression; |
| 82 | private DefaultMQPushConsumer defaultMQPushConsumer; | 85 | private DefaultMQPushConsumer defaultMQPushConsumer; |
| 86 | + | ||
| 87 | + | ||
| 83 | @Override | 88 | @Override |
| 84 | public Message onMessage(MessageExt messageExt) { | 89 | public Message onMessage(MessageExt messageExt) { |
| 85 | log.info("监听到消息{}",messageExt); | 90 | log.info("监听到消息{}",messageExt); |
| @@ -124,7 +129,16 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | @@ -124,7 +129,16 @@ public class DeviceCommandListenService implements RocketMQReplyListener<Message | ||
| 124 | } | 129 | } |
| 125 | return sendMessage(noticeMessageDomain); | 130 | return sendMessage(noticeMessageDomain); |
| 126 | case notice: | 131 | case notice: |
| 127 | - if(deviceCommandServiceFactory.notice(deviceCommand.getDeviceId(), deviceCommand.getData())) | 132 | + IotThingsModelService iotThingsModelService = SpringUtils.getBean(IotThingsModelService.class); |
| 133 | + | ||
| 134 | + JsonObject jsonObject = iotThingsModelService.reverseModeData(parserDeviceHostDto.getIotProduct().getId(), deviceCommand.getData()); | ||
| 135 | + noticeMessageDomain = deviceCommandServiceFactory.notice(deviceCommand.getDeviceId(), jsonObject); | ||
| 136 | + | ||
| 137 | + if(null == noticeMessageDomain) | ||
| 138 | + { | ||
| 139 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"该设备不支持写入功能"); | ||
| 140 | + } | ||
| 141 | + if(clienNoticeServiceFactory.sendMessage(noticeMessageDomain)) | ||
| 128 | { | 142 | { |
| 129 | return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); | 143 | return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"指令发送成功"); |
| 130 | }else { | 144 | }else { |
| @@ -10,5 +10,5 @@ public interface DeviceCommandServiceFactory { | @@ -10,5 +10,5 @@ public interface DeviceCommandServiceFactory { | ||
| 10 | NoticeMessageDto read(String deviceId, JsonObject jsonObject); | 10 | NoticeMessageDto read(String deviceId, JsonObject jsonObject); |
| 11 | NoticeMessageDto write(String deviceId, JsonObject jsonObject); | 11 | NoticeMessageDto write(String deviceId, JsonObject jsonObject); |
| 12 | 12 | ||
| 13 | - boolean notice(String deviceId, JsonObject jsonObject); | 13 | + NoticeMessageDto notice(String deviceId, JsonObject jsonObject); |
| 14 | } | 14 | } |
| @@ -23,7 +23,7 @@ import java.util.Arrays; | @@ -23,7 +23,7 @@ import java.util.Arrays; | ||
| 23 | import java.util.Set; | 23 | import java.util.Set; |
| 24 | 24 | ||
| 25 | @Service | 25 | @Service |
| 26 | -@RocketMQMessageListener(consumerGroup = "deviceCommand", topic = "deviceCommandListen",selectorType = SelectorType.TAG,selectorExpression = "SysCommand",messageModel = MessageModel.BROADCASTING) | 26 | +@RocketMQMessageListener(consumerGroup = "deviceCommand-${rocketmq.consumerGroup}", topic = "deviceCommandListen",selectorType = SelectorType.TAG,selectorExpression = "SysCommand",messageModel = MessageModel.BROADCASTING) |
| 27 | public class SysCommandListenService implements RocketMQReplyListener<MessageExt, Message> , RocketMQPushConsumerLifecycleListener { | 27 | public class SysCommandListenService implements RocketMQReplyListener<MessageExt, Message> , RocketMQPushConsumerLifecycleListener { |
| 28 | private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenService.class); | 28 | private static final Logger log = LoggerFactory.getLogger(DeviceCommandListenService.class); |
| 29 | 29 | ||
| @@ -65,6 +65,8 @@ public class SysCommandListenService implements RocketMQReplyListener<MessageExt | @@ -65,6 +65,8 @@ public class SysCommandListenService implements RocketMQReplyListener<MessageExt | ||
| 65 | case upProductPayloadModelNumber: | 65 | case upProductPayloadModelNumber: |
| 66 | iotThingsModelService.upProductPayloadModelNumberCach(deviceCommand.getData().get("product_ids").getAsInt()); | 66 | iotThingsModelService.upProductPayloadModelNumberCach(deviceCommand.getData().get("product_ids").getAsInt()); |
| 67 | return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"更新产品模型编号关系成功"); | 67 | return new Message(MessageCode.DEFAULT_SUCCESS_CODE,"更新产品模型编号关系成功"); |
| 68 | + case delSubscribe: //取消订阅 | ||
| 69 | + mqttSubscribeService.unSubscribe(deviceCommand.getData().get("ip").getAsString(),deviceCommand.getData().get("product_ids").getAsString()); | ||
| 68 | default: | 70 | default: |
| 69 | return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令类型不存在,请联系管理员"); | 71 | return new Message(MessageCode.DEFAULT_FAIL_CODE,"指令类型不存在,请联系管理员"); |
| 70 | } | 72 | } |
| @@ -177,7 +177,7 @@ public class DefaultProtocolPurificationFactoryImpl implements ProtocolPurificat | @@ -177,7 +177,7 @@ public class DefaultProtocolPurificationFactoryImpl implements ProtocolPurificat | ||
| 177 | { | 177 | { |
| 178 | data_type = ThingsModelDataTypeEnum.STRING.name(); | 178 | data_type = ThingsModelDataTypeEnum.STRING.name(); |
| 179 | } | 179 | } |
| 180 | - return ThingsModelItemBase.newhingsModelItem(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel, jsonElement); | 180 | + return ThingsModelItemBase.newhingsModel(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel, jsonElement); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | private DeviceSensorData getDeviceSensorData(Integer time,String sensorNumber,Topic topic,IotThingsModel thingsModel,ThingsModelItemBase thingsModelItemBase) | 183 | private DeviceSensorData getDeviceSensorData(Integer time,String sensorNumber,Topic topic,IotThingsModel thingsModel,ThingsModelItemBase thingsModelItemBase) |
| 1 | package com.zhonglai.luhui.device.protocol.factory.service; | 1 | package com.zhonglai.luhui.device.protocol.factory.service; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.google.gson.JsonElement; | ||
| 3 | import com.google.gson.JsonObject; | 5 | import com.google.gson.JsonObject; |
| 6 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 4 | import com.ruoyi.common.utils.StringUtils; | 7 | import com.ruoyi.common.utils.StringUtils; |
| 8 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelBase; | ||
| 5 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | 9 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; |
| 10 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 6 | import com.zhonglai.luhui.device.domain.IotProductPayloadModelNumber; | 11 | import com.zhonglai.luhui.device.domain.IotProductPayloadModelNumber; |
| 7 | import com.zhonglai.luhui.device.domain.IotProductTranslate; | 12 | import com.zhonglai.luhui.device.domain.IotProductTranslate; |
| 8 | import com.zhonglai.luhui.device.domain.IotThingsModel; | 13 | import com.zhonglai.luhui.device.domain.IotThingsModel; |
| 9 | import com.zhonglai.luhui.device.protocol.factory.config.ProductPayloadModelNumberCach; | 14 | import com.zhonglai.luhui.device.protocol.factory.config.ProductPayloadModelNumberCach; |
| 15 | +import org.apache.commons.lang3.EnumUtils; | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| 12 | 18 | ||
| @@ -130,4 +136,149 @@ public class IotThingsModelService { | @@ -130,4 +136,149 @@ public class IotThingsModelService { | ||
| 130 | } | 136 | } |
| 131 | } | 137 | } |
| 132 | } | 138 | } |
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * 逆向翻译模式数据 | ||
| 142 | + * @param product_id | ||
| 143 | + * @param jsonObject | ||
| 144 | + * @return | ||
| 145 | + */ | ||
| 146 | + public JSONObject reverseModeData(Integer product_id, JSONObject jsonObject ) | ||
| 147 | + { | ||
| 148 | + if(null != jsonObject && jsonObject.size() !=0 ) | ||
| 149 | + { | ||
| 150 | + JSONObject vjsonObject = jsonObject.clone(); | ||
| 151 | + return reverseTranslateModeData(product_id,vjsonObject); | ||
| 152 | + } | ||
| 153 | + return null; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + /** | ||
| 157 | + * 逆向翻译模式数据 | ||
| 158 | + * @param product_id | ||
| 159 | + * @param jsonObject | ||
| 160 | + * @return | ||
| 161 | + */ | ||
| 162 | + public JsonObject reverseModeData(Integer product_id, JsonObject jsonObject ) | ||
| 163 | + { | ||
| 164 | + if(null != jsonObject && jsonObject.size() !=0 ) | ||
| 165 | + { | ||
| 166 | + JSONObject vjsonObject = GsonConstructor.get().fromJson(jsonObject.toString(),JSONObject.class); | ||
| 167 | + vjsonObject = reverseTranslateModeData(product_id,vjsonObject); | ||
| 168 | + if(null != vjsonObject) | ||
| 169 | + { | ||
| 170 | + return GsonConstructor.get().fromJson(vjsonObject.toString(),JsonObject.class); | ||
| 171 | + } | ||
| 172 | + } | ||
| 173 | + return null; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + /** | ||
| 177 | + * 解析模式数据 | ||
| 178 | + * @param product_id | ||
| 179 | + * @param jsonObject | ||
| 180 | + * @return | ||
| 181 | + */ | ||
| 182 | + public JSONObject modeData(Integer product_id, JSONObject jsonObject ) | ||
| 183 | + { | ||
| 184 | + if(null != jsonObject && jsonObject.size() !=0 ) | ||
| 185 | + { | ||
| 186 | + JSONObject vjsonObject = jsonObject.clone(); | ||
| 187 | + return translateModeData(product_id,vjsonObject); | ||
| 188 | + } | ||
| 189 | + return null; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + /** | ||
| 193 | + * 解析模式数据 | ||
| 194 | + * @param product_id | ||
| 195 | + * @param jsonObject | ||
| 196 | + * @return | ||
| 197 | + */ | ||
| 198 | + public JsonObject modeData(Integer product_id, JsonObject jsonObject ) | ||
| 199 | + { | ||
| 200 | + if(null != jsonObject && jsonObject.size() !=0 ) | ||
| 201 | + { | ||
| 202 | + JSONObject vjsonObject = GsonConstructor.get().fromJson(jsonObject.toString(),JSONObject.class); | ||
| 203 | + vjsonObject = translateModeData(product_id,vjsonObject); | ||
| 204 | + if(null != vjsonObject) | ||
| 205 | + { | ||
| 206 | + return GsonConstructor.get().fromJson(vjsonObject.toString(),JsonObject.class); | ||
| 207 | + } | ||
| 208 | + } | ||
| 209 | + return null; | ||
| 210 | + } | ||
| 211 | + /** | ||
| 212 | + * 解析模式数据 | ||
| 213 | + * @param product_id | ||
| 214 | + * @param vjsonObject | ||
| 215 | + * @return | ||
| 216 | + */ | ||
| 217 | + private JSONObject translateModeData(Integer product_id, JSONObject vjsonObject ) | ||
| 218 | + { | ||
| 219 | + for(String vkey:vjsonObject.keySet()) | ||
| 220 | + { | ||
| 221 | + JSONObject jsData = vjsonObject.getJSONObject(vkey); | ||
| 222 | + for(String key:jsData.keySet()) | ||
| 223 | + { | ||
| 224 | + IotThingsModel thingsModel = getThingsModelBase(product_id,key); | ||
| 225 | + String data_type = thingsModel.getData_type().toUpperCase(); | ||
| 226 | + if(!EnumUtils.isValidEnum(ThingsModelDataTypeEnum.class,data_type)) | ||
| 227 | + { | ||
| 228 | + data_type = ThingsModelDataTypeEnum.STRING.name(); | ||
| 229 | + } | ||
| 230 | + ThingsModelBase thingsModelBase = ThingsModelItemBase.newhingsModel(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel, GsonConstructor.get().fromJson(jsData.get(key).toString(), JsonElement.class)); | ||
| 231 | + jsData.put(key,thingsModelBase); | ||
| 232 | + } | ||
| 233 | + vjsonObject.put(vkey,jsData); | ||
| 234 | + } | ||
| 235 | + return vjsonObject; | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + /** | ||
| 239 | + * 反向翻译模式数据 | ||
| 240 | + * @param product_id | ||
| 241 | + * @param vjsonObject | ||
| 242 | + * @return | ||
| 243 | + */ | ||
| 244 | + private JSONObject reverseTranslateModeData(Integer product_id, JSONObject vjsonObject ) | ||
| 245 | + { | ||
| 246 | + for(String vkey:vjsonObject.keySet()) | ||
| 247 | + { | ||
| 248 | + JSONObject jsData = vjsonObject.getJSONObject(vkey); | ||
| 249 | + for(String key:jsData.keySet()) | ||
| 250 | + { | ||
| 251 | + IotThingsModel thingsModel = getThingsModelBase(product_id,key); | ||
| 252 | + String data_type = thingsModel.getData_type().toUpperCase(); | ||
| 253 | + if(!EnumUtils.isValidEnum(ThingsModelDataTypeEnum.class,data_type)) | ||
| 254 | + { | ||
| 255 | + data_type = ThingsModelDataTypeEnum.STRING.name(); | ||
| 256 | + } | ||
| 257 | + ThingsModelItemBase thingsModelBase = ThingsModelItemBase.newhingsModelReverse(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel, GsonConstructor.get().fromJson(jsData.get(key).toString(), JsonElement.class)); | ||
| 258 | + jsData.put(key,thingsModelBase.getValue()); | ||
| 259 | + } | ||
| 260 | + vjsonObject.put(vkey,jsData); | ||
| 261 | + } | ||
| 262 | + return vjsonObject; | ||
| 263 | + } | ||
| 264 | + | ||
| 265 | + private IotThingsModel getThingsModelBase(Integer product_id,String identifier) | ||
| 266 | + { | ||
| 267 | + IotThingsModel thingsModel = getIotThingsModel(product_id,identifier); | ||
| 268 | + if(null == thingsModel) //没有配置的 都按字符串处理 | ||
| 269 | + { | ||
| 270 | + thingsModel = new IotThingsModel(); | ||
| 271 | + thingsModel.setData_type(ThingsModelDataTypeEnum.STRING.name()); | ||
| 272 | + thingsModel.setIdentifier(identifier); | ||
| 273 | + thingsModel.setModel_name(identifier); | ||
| 274 | + thingsModel.setIs_top(0); | ||
| 275 | + thingsModel.setIs_monitor(0); | ||
| 276 | + thingsModel.setIs_save_log(0); | ||
| 277 | + thingsModel.setIs_config(0); | ||
| 278 | + JsonObject specs = new JsonObject(); | ||
| 279 | + specs.addProperty("maxLength",255); | ||
| 280 | + thingsModel.setSpecs(specs.toString()); | ||
| 281 | + } | ||
| 282 | + return thingsModel; | ||
| 283 | + } | ||
| 133 | } | 284 | } |
| @@ -129,6 +129,38 @@ public class MqttSubscribeService { | @@ -129,6 +129,38 @@ public class MqttSubscribeService { | ||
| 129 | return null; | 129 | return null; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | + public Set<String> unSubscribe(String ip,String productids) | ||
| 133 | + { | ||
| 134 | + if(SysParameter.service_ip.equals(ip)) | ||
| 135 | + { | ||
| 136 | + | ||
| 137 | + try { | ||
| 138 | + List<ProtocolSubTopics> list = persistenceDBService.getProtocolSubTopicsFromProductids(productids,false); | ||
| 139 | + Set<String> sts = new HashSet<>(); | ||
| 140 | + for (ProtocolSubTopics protocolSubTopics:list) | ||
| 141 | + { | ||
| 142 | + String[] ps = protocolSubTopics.getSub_topics().split(","); | ||
| 143 | + for (String p:ps) | ||
| 144 | + { | ||
| 145 | + String topic = generateTopicFromSub_topics(protocolSubTopics.getRole_id(),protocolSubTopics.getMqtt_username(),p); | ||
| 146 | + if(topics.contains(topic)) | ||
| 147 | + { | ||
| 148 | + topics.remove(topic); | ||
| 149 | + sts.add(topic); | ||
| 150 | + } | ||
| 151 | + } | ||
| 152 | + } | ||
| 153 | + mqttclient.unsubscribe(sts.toArray(new String[sts.size()])); | ||
| 154 | + return sts; | ||
| 155 | + } catch (MqttException e) { | ||
| 156 | + return null; | ||
| 157 | + } | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + return null; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + | ||
| 132 | /** | 164 | /** |
| 133 | * 根据产品订阅信息和ip,生成topic | 165 | * 根据产品订阅信息和ip,生成topic |
| 134 | * ip用户来判断是否和当前服务器ip一直,如果不一直就卸载topic,一致就订阅topic | 166 | * ip用户来判断是否和当前服务器ip一直,如果不一直就卸载topic,一致就订阅topic |
| @@ -48,8 +48,8 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | @@ -48,8 +48,8 @@ public class DeviceCommandListenServiceImpl implements DeviceCommandServiceFacto | ||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | @Override | 50 | @Override |
| 51 | - public boolean notice(String deviceId, JsonObject jsonObject) { | ||
| 52 | - return false; | 51 | + public NoticeMessageDto notice(String deviceId, JsonObject jsonObject) { |
| 52 | + return null; | ||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | 55 |
| 1 | package com.zhonglai.luhui.http.service.proxy.controller; | 1 | package com.zhonglai.luhui.http.service.proxy.controller; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | import com.google.gson.JsonElement; | 5 | import com.google.gson.JsonElement; |
| 5 | import com.google.gson.JsonObject; | 6 | import com.google.gson.JsonObject; |
| 6 | import com.ruoyi.common.core.domain.AjaxResult; | 7 | import com.ruoyi.common.core.domain.AjaxResult; |
| @@ -11,6 +12,7 @@ import com.zhonglai.luhui.device.domain.IotDevice; | @@ -11,6 +12,7 @@ import com.zhonglai.luhui.device.domain.IotDevice; | ||
| 11 | import com.zhonglai.luhui.device.protocol.factory.ProtocolParserAndPurificationFactory; | 12 | import com.zhonglai.luhui.device.protocol.factory.ProtocolParserAndPurificationFactory; |
| 12 | import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; | 13 | import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; |
| 13 | import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; | 14 | import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; |
| 15 | +import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | ||
| 14 | import com.zhonglai.luhui.device.protocol.factory.config.HttpNoticeCach; | 16 | import com.zhonglai.luhui.device.protocol.factory.config.HttpNoticeCach; |
| 15 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | 17 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; |
| 16 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | 18 | import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; |
| @@ -85,7 +87,6 @@ public class HttpDataProxyController { | @@ -85,7 +87,6 @@ public class HttpDataProxyController { | ||
| 85 | } | 87 | } |
| 86 | rmap.put("0",config); | 88 | rmap.put("0",config); |
| 87 | } | 89 | } |
| 88 | - | ||
| 89 | List<ParserDeviceInfoDto> parserDeviceInfoDtoList = protocolPurificationModel.getParserDeviceInfoDtoList(); | 90 | List<ParserDeviceInfoDto> parserDeviceInfoDtoList = protocolPurificationModel.getParserDeviceInfoDtoList(); |
| 90 | if (null != parserDeviceInfoDtoList && parserDeviceInfoDtoList.size() != 0) | 91 | if (null != parserDeviceInfoDtoList && parserDeviceInfoDtoList.size() != 0) |
| 91 | { | 92 | { |
| @@ -104,9 +105,18 @@ public class HttpDataProxyController { | @@ -104,9 +105,18 @@ public class HttpDataProxyController { | ||
| 104 | } | 105 | } |
| 105 | } | 106 | } |
| 106 | rmap.put(parserDeviceInfoDto.getId().substring(parserDeviceInfoDto.getId().indexOf("_")+1),config); | 107 | rmap.put(parserDeviceInfoDto.getId().substring(parserDeviceInfoDto.getId().indexOf("_")+1),config); |
| 108 | + }else if(null != parserDeviceInfoDto.getData() && parserDeviceInfoDto.getData().size()>0 && parserDeviceInfoDto.getData().has("isSendConfig") && parserDeviceInfoDto.getData().get("isSendConfig").getAsBoolean()) | ||
| 109 | + { | ||
| 110 | + JsonObject config = DeviceCach.getDeviceInfo(parserDeviceInfoDto.getId()).getConfig(); | ||
| 111 | + if(null != config && config.size() !=0) | ||
| 112 | + { | ||
| 113 | + rmap.put(parserDeviceInfoDto.getId().substring(parserDeviceInfoDto.getId().indexOf("_")+1),JSONObject.parseObject(config.toString(), new com.alibaba.fastjson.TypeReference<Map<String, Object>>(){})); | ||
| 114 | + } | ||
| 115 | + | ||
| 107 | } | 116 | } |
| 108 | } | 117 | } |
| 109 | } | 118 | } |
| 119 | + | ||
| 110 | if(rmap.size()!= 0) | 120 | if(rmap.size()!= 0) |
| 111 | { | 121 | { |
| 112 | log.info("返回的数据【{}】",rmap); | 122 | log.info("返回的数据【{}】",rmap); |
| 1 | package com.zhonglai.luhui.http.service.proxy.service; | 1 | package com.zhonglai.luhui.http.service.proxy.service; |
| 2 | 2 | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | ||
| 3 | import com.zhonglai.luhui.device.protocol.factory.control.ClienNoticeServiceFactory; | 6 | import com.zhonglai.luhui.device.protocol.factory.control.ClienNoticeServiceFactory; |
| 4 | import com.zhonglai.luhui.device.protocol.factory.dto.NoticeMessageDto; | 7 | import com.zhonglai.luhui.device.protocol.factory.dto.NoticeMessageDto; |
| 8 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 9 | +import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 6 | 12 | ||
| 13 | +import java.nio.charset.StandardCharsets; | ||
| 14 | + | ||
| 7 | @Service | 15 | @Service |
| 8 | public class HttpClienNoticeServiceImpl implements ClienNoticeServiceFactory { | 16 | public class HttpClienNoticeServiceImpl implements ClienNoticeServiceFactory { |
| 17 | + @Autowired | ||
| 18 | + private HttpCallback httpCallback; | ||
| 9 | @Override | 19 | @Override |
| 10 | public boolean sendMessage(NoticeMessageDto noticeMessageDomain) { | 20 | public boolean sendMessage(NoticeMessageDto noticeMessageDomain) { |
| 21 | + if(null != noticeMessageDomain.getCommd() && noticeMessageDomain.getCommd().length!=0) | ||
| 22 | + { | ||
| 23 | + String clientid = noticeMessageDomain.getTopic().getClientid(); | ||
| 24 | + ParserDeviceHostDto parserDeviceHostDto = DeviceCach.getDeviceHost(clientid); | ||
| 25 | + if(null == parserDeviceHostDto) | ||
| 26 | + { | ||
| 27 | + return false; | ||
| 28 | + } | ||
| 29 | + JsonObject jsonObject = GsonConstructor.get().fromJson(new String(noticeMessageDomain.getCommd()),JsonObject.class); | ||
| 30 | + String topic = "/"+parserDeviceHostDto.getIotProduct().getRole_id()+"/"+parserDeviceHostDto.getIotProduct().getMqtt_username()+"/"+clientid+"/Json/ADD_POST/"+new Long(System.currentTimeMillis()).intValue(); | ||
| 31 | + httpCallback.messageArrived(clientid,topic,jsonObject.toString().getBytes(StandardCharsets.UTF_8)); | ||
| 32 | + return true; | ||
| 33 | + } | ||
| 34 | + | ||
| 11 | return false; | 35 | return false; |
| 12 | } | 36 | } |
| 13 | } | 37 | } |
| @@ -25,5 +25,6 @@ mqtt: | @@ -25,5 +25,6 @@ mqtt: | ||
| 25 | #rocketmq配置信息 | 25 | #rocketmq配置信息 |
| 26 | rocketmq: | 26 | rocketmq: |
| 27 | #nameservice服务器地址(多个以英文逗号隔开) | 27 | #nameservice服务器地址(多个以英文逗号隔开) |
| 28 | - name-server: 47.115.144.179:9876 | 28 | + name-server: 8.129.224.117:9876 |
| 29 | + consumerGroup: lh-mqtt-service-listen${random.uuid} | ||
| 29 | operationToken: local_lh-http-service-proxy | 30 | operationToken: local_lh-http-service-proxy |
| @@ -35,4 +35,5 @@ mqtt: | @@ -35,4 +35,5 @@ mqtt: | ||
| 35 | rocketmq: | 35 | rocketmq: |
| 36 | #nameservice服务器地址(多个以英文逗号隔开) | 36 | #nameservice服务器地址(多个以英文逗号隔开) |
| 37 | name-server: 8.129.224.117:9876 | 37 | name-server: 8.129.224.117:9876 |
| 38 | + consumerGroup: lh-mqtt-service-listen${random.uuid} | ||
| 38 | operationToken: local_lh-mqtt-service-listen | 39 | operationToken: local_lh-mqtt-service-listen |
lh-modules/lh-mqtt-service/src/main/java/com/zhonglai/luhui/mqtt/comm/service/MqttDeviceService.java
| @@ -135,7 +135,7 @@ public class MqttDeviceService extends DeviceService{ | @@ -135,7 +135,7 @@ public class MqttDeviceService extends DeviceService{ | ||
| 135 | String data_type = thingsModel.getData_type().toUpperCase(); | 135 | String data_type = thingsModel.getData_type().toUpperCase(); |
| 136 | Object object = jsonObject.get(skey); | 136 | Object object = jsonObject.get(skey); |
| 137 | 137 | ||
| 138 | - ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItemFromControl(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel,gsonobject.get(skey)); | 138 | + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelReverse(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel,gsonobject.get(skey)); |
| 139 | 139 | ||
| 140 | jsonObject.put(skey,thingsModelItemBase.getCmdView(object)); | 140 | jsonObject.put(skey,thingsModelItemBase.getCmdView(object)); |
| 141 | 141 |
| @@ -74,7 +74,7 @@ public class ReadReqTopic implements BusinessAgreement<ReadReqDto> { | @@ -74,7 +74,7 @@ public class ReadReqTopic implements BusinessAgreement<ReadReqDto> { | ||
| 74 | { | 74 | { |
| 75 | data_type = ThingsModelDataTypeEnum.STRING.name(); | 75 | data_type = ThingsModelDataTypeEnum.STRING.name(); |
| 76 | } | 76 | } |
| 77 | - ThingsModelBase thingsModelBase = ThingsModelItemBase.newhingsModelItem(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel, GsonConstructor.get().fromJson(jsData.get(key).toString(), JsonElement.class)); | 77 | + ThingsModelBase thingsModelBase = ThingsModelItemBase.newhingsModel(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel, GsonConstructor.get().fromJson(jsData.get(key).toString(), JsonElement.class)); |
| 78 | // Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class,data_type).getaClass(); | 78 | // Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class,data_type).getaClass(); |
| 79 | // ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(),aClass); | 79 | // ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(),aClass); |
| 80 | // thingsModelBase.conversionThingsModel(thingsModel); | 80 | // thingsModelBase.conversionThingsModel(thingsModel); |
-
请 注册 或 登录 后发表评论