正在显示
99 个修改的文件
包含
3717 行增加
和
289 行删除
| @@ -137,7 +137,6 @@ public class PublicSQL { | @@ -137,7 +137,6 @@ public class PublicSQL { | ||
| 137 | { | 137 | { |
| 138 | Object object = map.get("object"); | 138 | Object object = map.get("object"); |
| 139 | String tableName = changTableNameFromObject(object); | 139 | String tableName = changTableNameFromObject(object); |
| 140 | - String primaryKey = (String) map.get("primaryKey"); | ||
| 141 | if(map.containsKey("tableName")) | 140 | if(map.containsKey("tableName")) |
| 142 | { | 141 | { |
| 143 | tableName = map.get("tableName").toString(); | 142 | tableName = map.get("tableName").toString(); |
| @@ -16,6 +16,7 @@ public interface PublicMapper { | @@ -16,6 +16,7 @@ public interface PublicMapper { | ||
| 16 | * 添加对象 | 16 | * 添加对象 |
| 17 | */ | 17 | */ |
| 18 | @InsertProvider(type = PublicSQL.class, method = "insert") | 18 | @InsertProvider(type = PublicSQL.class, method = "insert") |
| 19 | + @Options(useGeneratedKeys=true, keyProperty="id") | ||
| 19 | int insert(Object object); | 20 | int insert(Object object); |
| 20 | 21 | ||
| 21 | /** | 22 | /** |
| @@ -23,7 +24,7 @@ public interface PublicMapper { | @@ -23,7 +24,7 @@ public interface PublicMapper { | ||
| 23 | */ | 24 | */ |
| 24 | @InsertProvider(type = PublicSQL.class, method = "insertToTable") | 25 | @InsertProvider(type = PublicSQL.class, method = "insertToTable") |
| 25 | @Options(useGeneratedKeys = true, keyProperty = "object.id") | 26 | @Options(useGeneratedKeys = true, keyProperty = "object.id") |
| 26 | - int insertToTable(@Param("object") Object object,@Param("tableName") String tableName,@Param("primaryKey") String primaryKey); | 27 | + int insertToTable(@Param("object") Object object,@Param("tableName") String tableName); |
| 27 | 28 | ||
| 28 | /** | 29 | /** |
| 29 | * 添加对象集合 | 30 | * 添加对象集合 |
| @@ -63,7 +64,7 @@ public interface PublicMapper { | @@ -63,7 +64,7 @@ public interface PublicMapper { | ||
| 63 | * @return | 64 | * @return |
| 64 | */ | 65 | */ |
| 65 | @SelectProvider(type = PublicSQL.class, method = "getObject") | 66 | @SelectProvider(type = PublicSQL.class, method = "getObject") |
| 66 | - <T> T getObject(@Param("class") Class<?> clas, @Param("idName") String idName, @Param("values") String values); | 67 | + Map<String,Object> getObject(@Param("class") Class<?> clas, @Param("idName") String idName, @Param("values") String values); |
| 67 | 68 | ||
| 68 | @SelectProvider(type = PublicSQL.class, method = "selectCountBySql") | 69 | @SelectProvider(type = PublicSQL.class, method = "selectCountBySql") |
| 69 | Long selectCountBySql(@Param("sql") String sql); | 70 | Long selectCountBySql(@Param("sql") String sql); |
| @@ -49,7 +49,7 @@ public interface PublicService { | @@ -49,7 +49,7 @@ public interface PublicService { | ||
| 49 | * @param values | 49 | * @param values |
| 50 | * @return | 50 | * @return |
| 51 | */ | 51 | */ |
| 52 | - <T> T getObject( Class<?> clas, String idName, String values); | 52 | + <T> T getObject( Class<T> clas, String idName, String values); |
| 53 | 53 | ||
| 54 | /** | 54 | /** |
| 55 | * 查询 通过条件查询 | 55 | * 查询 通过条件查询 |
| @@ -29,12 +29,12 @@ public class PublicServiceImpl implements PublicService { | @@ -29,12 +29,12 @@ public class PublicServiceImpl implements PublicService { | ||
| 29 | */ | 29 | */ |
| 30 | public int insertToTable(Object object, String tableName) | 30 | public int insertToTable(Object object, String tableName) |
| 31 | { | 31 | { |
| 32 | - return publicMapper.insertToTable(object,tableName,"id"); | 32 | + return publicMapper.insertToTable(object,tableName); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | public int insertToTable(Object object, String tableName,String primaryKey) | 35 | public int insertToTable(Object object, String tableName,String primaryKey) |
| 36 | { | 36 | { |
| 37 | - return publicMapper.insertToTable(object,tableName,primaryKey); | 37 | + return publicMapper.insertToTable(object,tableName); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | /** | 40 | /** |
| @@ -89,9 +89,14 @@ public class PublicServiceImpl implements PublicService { | @@ -89,9 +89,14 @@ public class PublicServiceImpl implements PublicService { | ||
| 89 | * @param values | 89 | * @param values |
| 90 | * @return | 90 | * @return |
| 91 | */ | 91 | */ |
| 92 | - public <T> T getObject(Class<?> clas, String idName, String values) | 92 | + public <T> T getObject(Class<T> clas, String idName, String values) |
| 93 | { | 93 | { |
| 94 | - return publicMapper.getObject(clas,idName,values); | 94 | + Object oj =publicMapper.getObject(clas,idName,values); |
| 95 | + if(null != oj) | ||
| 96 | + { | ||
| 97 | + return JSONObject.parseObject(JSONObject.toJSONString(oj),clas); | ||
| 98 | + } | ||
| 99 | + return null; | ||
| 95 | } | 100 | } |
| 96 | 101 | ||
| 97 | /** | 102 | /** |
lh-common/lh-service-dao/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-common</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <groupId>com.luhui</groupId> | ||
| 13 | + <artifactId>lh-service-dao</artifactId> | ||
| 14 | + | ||
| 15 | + <properties> | ||
| 16 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 17 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 18 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 19 | + </properties> | ||
| 20 | + | ||
| 21 | +</project> |
| @@ -31,6 +31,7 @@ | @@ -31,6 +31,7 @@ | ||
| 31 | <module>ruoyi-common-security</module> | 31 | <module>ruoyi-common-security</module> |
| 32 | <module>ruoyi-framework</module> | 32 | <module>ruoyi-framework</module> |
| 33 | <module>ruoyi-generator</module> | 33 | <module>ruoyi-generator</module> |
| 34 | + <module>lh-service-dao</module> | ||
| 34 | </modules> | 35 | </modules> |
| 35 | 36 | ||
| 36 | <packaging>pom</packaging> | 37 | <packaging>pom</packaging> |
| 1 | +package com.zhonglai.luhui.redis.listener; | ||
| 2 | + | ||
| 3 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | +import org.springframework.context.annotation.Bean; | ||
| 5 | +import org.springframework.data.redis.connection.RedisConnection; | ||
| 6 | +import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
| 7 | +import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
| 8 | +import org.springframework.stereotype.Component; | ||
| 9 | +import org.springframework.util.StringUtils; | ||
| 10 | + | ||
| 11 | +import java.util.Properties; | ||
| 12 | + | ||
| 13 | +@Component | ||
| 14 | +public class RedisAllKeyListener { | ||
| 15 | + private String keyspaceNotificationsConfigParameter = "KEA"; | ||
| 16 | + | ||
| 17 | + @Autowired | ||
| 18 | + private RedisDeleteListener redisDeleteListener ; | ||
| 19 | + @Autowired | ||
| 20 | + private RedisExpiredListener redisExpiredListener ; | ||
| 21 | + @Bean | ||
| 22 | + RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) { | ||
| 23 | + RedisConnection connection = connectionFactory.getConnection(); | ||
| 24 | + Properties config = connection.info("notify-keyspace-events"); | ||
| 25 | + | ||
| 26 | + if (!StringUtils.hasText(config.getProperty("notify-keyspace-events"))) { | ||
| 27 | + connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter); | ||
| 28 | + } | ||
| 29 | + RedisMessageListenerContainer container = new RedisMessageListenerContainer(); | ||
| 30 | + container.setConnectionFactory(connectionFactory); | ||
| 31 | + //监听所有key的删除事件 | ||
| 32 | + container.addMessageListener(redisDeleteListener,redisDeleteListener.getTopic()); | ||
| 33 | + //监听所有key的过期事件 | ||
| 34 | + container.addMessageListener(redisExpiredListener,redisExpiredListener.getTopic()); | ||
| 35 | + return container; | ||
| 36 | + } | ||
| 37 | +} |
| 1 | -package com.zhonglai.luhui.device.analysis.comm.service; | 1 | +package com.zhonglai.luhui.redis.listener; |
| 2 | 2 | ||
| 3 | import org.springframework.beans.factory.annotation.Autowired; | 3 | import org.springframework.beans.factory.annotation.Autowired; |
| 4 | import org.springframework.data.redis.connection.Message; | 4 | import org.springframework.data.redis.connection.Message; |
| @@ -14,27 +14,26 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene | @@ -14,27 +14,26 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene | ||
| 14 | @Autowired | 14 | @Autowired |
| 15 | private DataPersistenceService dtaPersistenceService; | 15 | private DataPersistenceService dtaPersistenceService; |
| 16 | 16 | ||
| 17 | - | ||
| 18 | public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) { | 17 | public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) { |
| 19 | super(listenerContainer); | 18 | super(listenerContainer); |
| 20 | } | 19 | } |
| 21 | 20 | ||
| 22 | @Override | 21 | @Override |
| 23 | public void onMessage(Message message, byte[] pattern) { | 22 | public void onMessage(Message message, byte[] pattern) { |
| 24 | -// String expiredKey = message.toString(); | ||
| 25 | -// | ||
| 26 | -// String devicePath = deviceService.getRedicDeviceKeyPath(); | ||
| 27 | -// String terminalPath = deviceService.getRedicTerminalKeyPath(); | ||
| 28 | -// if(expiredKey.startsWith(devicePath)) //如果是主机 | ||
| 29 | -// { | ||
| 30 | -// String imei = expiredKey.replace(devicePath,"").replace(":",""); | ||
| 31 | -// dtaPersistenceService.offLine(imei); | ||
| 32 | -// } | ||
| 33 | -// | ||
| 34 | -// if(expiredKey.startsWith(terminalPath)) //如果是终端 | ||
| 35 | -// { | ||
| 36 | -// String imei = expiredKey.replace(devicePath,"").replace(":",""); | ||
| 37 | -// dtaPersistenceService.offLine(imei); | ||
| 38 | -// } | 23 | + String expiredKey = message.toString(); |
| 24 | + | ||
| 25 | + String devicePath = dtaPersistenceService.getRedicDeviceKeyPath(); | ||
| 26 | + String terminalPath = dtaPersistenceService.getRedicTerminalKeyPath(); | ||
| 27 | + if(expiredKey.startsWith(devicePath)) //如果是主机 | ||
| 28 | + { | ||
| 29 | + String imei = expiredKey.replace(devicePath,"").replace(":",""); | ||
| 30 | + dtaPersistenceService.offLine(imei); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + if(expiredKey.startsWith(terminalPath)) //如果是终端 | ||
| 34 | + { | ||
| 35 | + String imei = expiredKey.replace(devicePath,"").replace(":",""); | ||
| 36 | + dtaPersistenceService.offLine(imei); | ||
| 37 | + } | ||
| 39 | } | 38 | } |
| 40 | } | 39 | } |
| 1 | -package com.zhonglai.luhui.device.analysis.comm.service.redis; | 1 | +package com.zhonglai.luhui.redis.service; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | import org.slf4j.Logger; | 4 | import org.slf4j.Logger; |
| 5 | import org.slf4j.LoggerFactory; | 5 | import org.slf4j.LoggerFactory; |
| 6 | import org.springframework.data.redis.core.RedisTemplate; | 6 | import org.springframework.data.redis.core.RedisTemplate; |
| 7 | -import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
| 8 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
| 9 | import org.springframework.util.CollectionUtils; | 8 | import org.springframework.util.CollectionUtils; |
| 10 | 9 |
| @@ -160,6 +160,11 @@ public class Constants | @@ -160,6 +160,11 @@ public class Constants | ||
| 160 | public static final String LOOKUP_LDAPS = "ldaps:"; | 160 | public static final String LOOKUP_LDAPS = "ldaps:"; |
| 161 | 161 | ||
| 162 | /** | 162 | /** |
| 163 | + * JSON 资源 | ||
| 164 | + */ | ||
| 165 | + public static String CONTENT_TYPE = "application/json; charset=utf-8"; | ||
| 166 | + | ||
| 167 | + /** | ||
| 163 | * 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加) | 168 | * 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加) |
| 164 | */ | 169 | */ |
| 165 | public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" }; | 170 | public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" }; |
| @@ -26,5 +26,9 @@ | @@ -26,5 +26,9 @@ | ||
| 26 | <groupId>com.zhonglai.luhui</groupId> | 26 | <groupId>com.zhonglai.luhui</groupId> |
| 27 | <artifactId>ruoyi-common</artifactId> | 27 | <artifactId>ruoyi-common</artifactId> |
| 28 | </dependency> | 28 | </dependency> |
| 29 | + <dependency> | ||
| 30 | + <groupId>cn.hutool</groupId> | ||
| 31 | + <artifactId>hutool-all</artifactId> | ||
| 32 | + </dependency> | ||
| 29 | </dependencies> | 33 | </dependencies> |
| 30 | </project> | 34 | </project> |
| @@ -11,11 +11,20 @@ import com.ruoyi.common.utils.DateUtils; | @@ -11,11 +11,20 @@ import com.ruoyi.common.utils.DateUtils; | ||
| 11 | import com.ruoyi.common.utils.PageUtils; | 11 | import com.ruoyi.common.utils.PageUtils; |
| 12 | import com.ruoyi.common.utils.StringUtils; | 12 | import com.ruoyi.common.utils.StringUtils; |
| 13 | import com.ruoyi.common.utils.sql.SqlUtil; | 13 | import com.ruoyi.common.utils.sql.SqlUtil; |
| 14 | +import com.zhonglai.luhui.config.TokenConfig; | ||
| 15 | +import com.zhonglai.luhui.dto.LoginToken; | ||
| 14 | import org.slf4j.Logger; | 16 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; | 17 | import org.slf4j.LoggerFactory; |
| 18 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 19 | +import org.springframework.beans.factory.annotation.Value; | ||
| 16 | import org.springframework.web.bind.WebDataBinder; | 20 | import org.springframework.web.bind.WebDataBinder; |
| 17 | import org.springframework.web.bind.annotation.InitBinder; | 21 | import org.springframework.web.bind.annotation.InitBinder; |
| 22 | +import org.springframework.web.context.request.RequestContextHolder; | ||
| 23 | +import org.springframework.web.context.request.ServletRequestAttributes; | ||
| 18 | 24 | ||
| 25 | +import javax.servlet.http.HttpServletRequest; | ||
| 26 | +import javax.servlet.http.HttpServletResponse; | ||
| 27 | +import javax.servlet.http.HttpSession; | ||
| 19 | import java.beans.PropertyEditorSupport; | 28 | import java.beans.PropertyEditorSupport; |
| 20 | import java.util.Date; | 29 | import java.util.Date; |
| 21 | import java.util.List; | 30 | import java.util.List; |
| @@ -29,6 +38,9 @@ public class BaseController | @@ -29,6 +38,9 @@ public class BaseController | ||
| 29 | { | 38 | { |
| 30 | protected final Logger logger = LoggerFactory.getLogger(this.getClass()); | 39 | protected final Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 31 | 40 | ||
| 41 | + @Autowired | ||
| 42 | + protected TokenConfig tokenConfig ; | ||
| 43 | + | ||
| 32 | /** | 44 | /** |
| 33 | * 将前台传递过来的日期格式的字符串,自动转化为Date类型 | 45 | * 将前台传递过来的日期格式的字符串,自动转化为Date类型 |
| 34 | */ | 46 | */ |
| @@ -46,6 +58,32 @@ public class BaseController | @@ -46,6 +58,32 @@ public class BaseController | ||
| 46 | }); | 58 | }); |
| 47 | } | 59 | } |
| 48 | 60 | ||
| 61 | + protected LoginToken getLoginToken() | ||
| 62 | + { | ||
| 63 | + HttpSession session = getSession(); | ||
| 64 | + if(null != session && null != session.getAttribute(tokenConfig.getLogin_token_key())) | ||
| 65 | + { | ||
| 66 | + return (LoginToken)session.getAttribute(tokenConfig.getLogin_token_key()); | ||
| 67 | + } | ||
| 68 | + return null; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + protected HttpSession getSession() { | ||
| 72 | + return getRequest().getSession(); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + protected HttpServletRequest getRequest() { | ||
| 76 | + ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder | ||
| 77 | + .getRequestAttributes(); | ||
| 78 | + return attrs.getRequest(); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + protected HttpServletResponse getResponse() { | ||
| 82 | + ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder | ||
| 83 | + .getRequestAttributes(); | ||
| 84 | + return attrs.getResponse(); | ||
| 85 | + } | ||
| 86 | + | ||
| 49 | /** | 87 | /** |
| 50 | * 设置请求分页数据 | 88 | * 设置请求分页数据 |
| 51 | */ | 89 | */ |
| 1 | +package com.zhonglai.luhui.config; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | +import org.springframework.beans.factory.annotation.Value; | ||
| 5 | +import org.springframework.stereotype.Component; | ||
| 6 | + | ||
| 7 | +@Component | ||
| 8 | +@Data | ||
| 9 | +public class TokenConfig { | ||
| 10 | + @Value("${token.header: loginToken}") | ||
| 11 | + private String login_token_key; | ||
| 12 | + @Value("${token.expireTime: 120}") | ||
| 13 | + private Integer expireTime; | ||
| 14 | +} |
| 1 | +package com.zhonglai.luhui.dto; | ||
| 2 | + | ||
| 3 | +import cn.hutool.crypto.SecureUtil; | ||
| 4 | +import cn.hutool.crypto.asymmetric.KeyType; | ||
| 5 | +import cn.hutool.crypto.symmetric.AES; | ||
| 6 | +import cn.hutool.crypto.symmetric.SymmetricAlgorithm; | ||
| 7 | +import cn.hutool.crypto.symmetric.SymmetricCrypto; | ||
| 8 | +import com.ruoyi.common.utils.DateUtils; | ||
| 9 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 10 | +import lombok.Data; | ||
| 11 | + | ||
| 12 | +@Data | ||
| 13 | +public class LoginToken { | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * 用户id | ||
| 17 | + */ | ||
| 18 | + private String id; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 时间戳 | ||
| 22 | + */ | ||
| 23 | + private Integer startTime; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 过期时间 | ||
| 27 | + */ | ||
| 28 | + private Integer endTime; | ||
| 29 | + | ||
| 30 | + private static String key = "njlaikun.com"; | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + private static String partition = "_"; | ||
| 34 | + | ||
| 35 | + public String toToken() | ||
| 36 | + { | ||
| 37 | + return new SymmetricCrypto(SymmetricAlgorithm.DES, key.getBytes()).encryptHex(id+partition+startTime+partition+endTime); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public static LoginToken forToken(String token) | ||
| 41 | + { | ||
| 42 | + try { | ||
| 43 | + String decStr = new SymmetricCrypto(SymmetricAlgorithm.DES, key.getBytes()).decryptStr(token); | ||
| 44 | + String[] strs = decStr.split(partition); | ||
| 45 | + LoginToken loginToken = new LoginToken(); | ||
| 46 | + loginToken.setId(strs[0]); | ||
| 47 | + loginToken.setStartTime(Integer.parseInt(strs[1])); | ||
| 48 | + loginToken.setEndTime(Integer.parseInt(strs[2])); | ||
| 49 | + return loginToken; | ||
| 50 | + }catch (Exception e) | ||
| 51 | + { | ||
| 52 | + return null; | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public static void main(String[] args) { | ||
| 57 | + LoginToken loginToken = new LoginToken(); | ||
| 58 | + loginToken.setId("1"); | ||
| 59 | + loginToken.setStartTime(DateUtils.getNowTimeMilly()); | ||
| 60 | + loginToken.setEndTime(DateUtils.getNowTimeMilly()); | ||
| 61 | + String token = loginToken.toToken(); | ||
| 62 | + System.out.println(token); | ||
| 63 | + System.out.println(GsonConstructor.get().toJson(forToken(token))); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | +} |
lh-jar/lh-jar-device-analysis/src/main/java/com/zhonglai/luhui/device/analysis/comm/dao/BaseDao.java
| @@ -117,7 +117,7 @@ public class BaseDao { | @@ -117,7 +117,7 @@ public class BaseDao { | ||
| 117 | * 指定表名插入对象集合 | 117 | * 指定表名插入对象集合 |
| 118 | * @param objectList | 118 | * @param objectList |
| 119 | */ | 119 | */ |
| 120 | - public void insertList(List<?> objectList ,String tableName) | 120 | + public int insertList(List<?> objectList ,String tableName) |
| 121 | { | 121 | { |
| 122 | QueryRunner runner = new QueryRunner(dBFactory.getDataSource()); | 122 | QueryRunner runner = new QueryRunner(dBFactory.getDataSource()); |
| 123 | 123 | ||
| @@ -133,10 +133,11 @@ public class BaseDao { | @@ -133,10 +133,11 @@ public class BaseDao { | ||
| 133 | sql += tableName + msaicAttribute(object) + " values " +msaicValues(objectList,valueList); | 133 | sql += tableName + msaicAttribute(object) + " values " +msaicValues(objectList,valueList); |
| 134 | 134 | ||
| 135 | try { | 135 | try { |
| 136 | - runner.update(sql,valueList.toArray()); | 136 | + return runner.update(sql,valueList.toArray()); |
| 137 | } catch (SQLException e) { | 137 | } catch (SQLException e) { |
| 138 | e.printStackTrace(); | 138 | e.printStackTrace(); |
| 139 | } | 139 | } |
| 140 | + return 0; | ||
| 140 | } | 141 | } |
| 141 | 142 | ||
| 142 | /** | 143 | /** |
| @@ -218,9 +219,9 @@ public class BaseDao { | @@ -218,9 +219,9 @@ public class BaseDao { | ||
| 218 | * 以主键id更新对象 | 219 | * 以主键id更新对象 |
| 219 | * @param object | 220 | * @param object |
| 220 | */ | 221 | */ |
| 221 | - public void update(Object object) | 222 | + public int update(Object object) |
| 222 | { | 223 | { |
| 223 | - update(object,null); | 224 | + return update(object,null); |
| 224 | } | 225 | } |
| 225 | 226 | ||
| 226 | /** | 227 | /** |
| @@ -228,7 +229,7 @@ public class BaseDao { | @@ -228,7 +229,7 @@ public class BaseDao { | ||
| 228 | * @param object 传值对象 | 229 | * @param object 传值对象 |
| 229 | * @param whereFieldNames 条件(多个用,分割) | 230 | * @param whereFieldNames 条件(多个用,分割) |
| 230 | */ | 231 | */ |
| 231 | - public void update(Object object,String whereFieldNames) | 232 | + public int update(Object object,String whereFieldNames) |
| 232 | { | 233 | { |
| 233 | QueryRunner runner = new QueryRunner(dBFactory.getDataSource()); | 234 | QueryRunner runner = new QueryRunner(dBFactory.getDataSource()); |
| 234 | 235 | ||
| @@ -352,10 +353,11 @@ public class BaseDao { | @@ -352,10 +353,11 @@ public class BaseDao { | ||
| 352 | } | 353 | } |
| 353 | 354 | ||
| 354 | try { | 355 | try { |
| 355 | - runner.update(sql,valueList.toArray()); | 356 | + return runner.update(sql,valueList.toArray()); |
| 356 | } catch (SQLException e) { | 357 | } catch (SQLException e) { |
| 357 | e.printStackTrace(); | 358 | e.printStackTrace(); |
| 358 | } | 359 | } |
| 360 | + return 0; | ||
| 359 | } | 361 | } |
| 360 | 362 | ||
| 361 | /** | 363 | /** |
| @@ -3,28 +3,20 @@ package com.zhonglai.luhui.device.analysis.comm.db; | @@ -3,28 +3,20 @@ package com.zhonglai.luhui.device.analysis.comm.db; | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | import com.alibaba.fastjson.JSONArray; | 4 | import com.alibaba.fastjson.JSONArray; |
| 5 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
| 6 | -import com.zhonglai.luhui.device.analysis.comm.db.mode.TerminalDataThingsModeService; | ||
| 7 | import com.zhonglai.luhui.device.analysis.comm.service.CacheServiceImpl; | 6 | import com.zhonglai.luhui.device.analysis.comm.service.CacheServiceImpl; |
| 8 | -import com.zhonglai.luhui.device.analysis.comm.service.DataPersistenceServiceImpl; | ||
| 9 | import com.zhonglai.luhui.device.domain.IotDevice; | 7 | import com.zhonglai.luhui.device.domain.IotDevice; |
| 10 | import com.zhonglai.luhui.device.domain.IotTerminal; | 8 | import com.zhonglai.luhui.device.domain.IotTerminal; |
| 11 | -import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 12 | import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; | 9 | import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; |
| 13 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | 10 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; |
| 14 | -import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelBase; | ||
| 15 | -import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | ||
| 16 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | 11 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; |
| 17 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 12 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 18 | -import com.zhonglai.luhui.device.analysis.comm.service.BusinessDataUpdateService; | ||
| 19 | import com.zhonglai.luhui.device.analysis.comm.service.DeviceLogService; | 13 | import com.zhonglai.luhui.device.analysis.comm.service.DeviceLogService; |
| 20 | -import com.zhonglai.luhui.device.analysis.comm.service.redis.RedisService; | 14 | +import com.zhonglai.luhui.redis.service.RedisService; |
| 21 | import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; | 15 | import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; |
| 22 | import com.zhonglai.luhui.device.analysis.dto.Message; | 16 | import com.zhonglai.luhui.device.analysis.dto.Message; |
| 23 | import com.zhonglai.luhui.device.analysis.dto.MessageCode; | 17 | import com.zhonglai.luhui.device.analysis.dto.MessageCode; |
| 24 | -import com.zhonglai.luhui.device.analysis.dto.topic.AddPostDto; | ||
| 25 | import org.apache.commons.lang3.StringUtils; | 18 | import org.apache.commons.lang3.StringUtils; |
| 26 | import org.eclipse.paho.client.mqttv3.MqttException; | 19 | import org.eclipse.paho.client.mqttv3.MqttException; |
| 27 | -import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
| 28 | import org.slf4j.Logger; | 20 | import org.slf4j.Logger; |
| 29 | import org.slf4j.LoggerFactory; | 21 | import org.slf4j.LoggerFactory; |
| 30 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -2,7 +2,7 @@ package com.zhonglai.luhui.device.analysis.comm.db.mode; | @@ -2,7 +2,7 @@ package com.zhonglai.luhui.device.analysis.comm.db.mode; | ||
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | import com.zhonglai.luhui.device.domain.IotThingsModel; | 4 | import com.zhonglai.luhui.device.domain.IotThingsModel; |
| 5 | -import com.zhonglai.luhui.device.analysis.comm.service.redis.RedisService; | 5 | +import com.zhonglai.luhui.redis.service.RedisService; |
| 6 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
| 8 | 8 |
| 1 | package com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels; | 1 | package com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import com.google.gson.JsonElement; | ||
| 4 | import com.zhonglai.luhui.device.domain.IotThingsModel; | 5 | import com.zhonglai.luhui.device.domain.IotThingsModel; |
| 5 | 6 | ||
| 6 | /** | 7 | /** |
| 7 | * 物模型工厂 | 8 | * 物模型工厂 |
| 8 | */ | 9 | */ |
| 9 | public interface ThingsModelBase<T> { | 10 | public interface ThingsModelBase<T> { |
| 10 | - void conversionThingsModel(IotThingsModel thingsModel); | ||
| 11 | - void addValue(Object t); | 11 | + |
| 12 | // @JSONField(serialize=false) | 12 | // @JSONField(serialize=false) |
| 13 | String getView(); | 13 | String getView(); |
| 14 | String getSaveView(); | 14 | String getSaveView(); |
| @@ -7,19 +7,10 @@ import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs.*; | @@ -7,19 +7,10 @@ import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs.*; | ||
| 7 | * 物模型数据类型,及对应显示解析方案 | 7 | * 物模型数据类型,及对应显示解析方案 |
| 8 | */ | 8 | */ |
| 9 | public enum ThingsModelDataTypeEnum { | 9 | public enum ThingsModelDataTypeEnum { |
| 10 | - INTEGER(IntegerModelOutput.class), | ||
| 11 | - DECIMAL(DecimalModelOutput.class), | ||
| 12 | - STRING(StringModelOutput.class), | ||
| 13 | - BOOL(BoolModelOutput.class), | ||
| 14 | - ARRAY(ArrayModelOutput.class), | ||
| 15 | - ENUM(EnumModelOutput.class); | ||
| 16 | - | ||
| 17 | - private Class aClass; | ||
| 18 | - ThingsModelDataTypeEnum(Class aClass) { | ||
| 19 | - this.aClass = aClass; | ||
| 20 | - } | ||
| 21 | - | ||
| 22 | - public Class getaClass() { | ||
| 23 | - return aClass; | ||
| 24 | - } | 10 | + INTEGER, |
| 11 | + DECIMAL, | ||
| 12 | + STRING, | ||
| 13 | + BOOL, | ||
| 14 | + ARRAY, | ||
| 15 | + ENUM; | ||
| 25 | } | 16 | } |
| 1 | package com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels; | 1 | package com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels; |
| 2 | 2 | ||
| 3 | +import com.google.gson.JsonElement; | ||
| 4 | +import com.google.gson.JsonObject; | ||
| 5 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 6 | +import com.ruoyi.common.utils.StringUtils; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs.*; | ||
| 3 | import com.zhonglai.luhui.device.domain.IotThingsModel; | 8 | import com.zhonglai.luhui.device.domain.IotThingsModel; |
| 4 | import lombok.Data; | 9 | import lombok.Data; |
| 5 | 10 | ||
| @@ -10,6 +15,86 @@ import lombok.Data; | @@ -10,6 +15,86 @@ import lombok.Data; | ||
| 10 | @Data | 15 | @Data |
| 11 | public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> | 16 | public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> |
| 12 | { | 17 | { |
| 18 | + | ||
| 19 | + public static ThingsModelItemBase newhingsModelItem(ThingsModelDataTypeEnum thingsModelDataTypeEnum,IotThingsModel thingsModel,JsonElement jsonElement) | ||
| 20 | + { | ||
| 21 | + if (!jsonElement.isJsonNull()) | ||
| 22 | + { | ||
| 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(jsonElement.getAsBoolean()); | ||
| 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.conversionThingsModel(thingsModel); | ||
| 56 | + | ||
| 57 | + return thingsModelItemBase; | ||
| 58 | + } | ||
| 59 | + return null; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + | ||
| 63 | + public static ThingsModelItemBase newhingsModelItem(JsonObject jsonObject) | ||
| 64 | + { | ||
| 65 | + String type = "STRING"; | ||
| 66 | + if(jsonObject.has("type")) | ||
| 67 | + { | ||
| 68 | + type = jsonObject.get("type").getAsString(); | ||
| 69 | + } | ||
| 70 | + ThingsModelItemBase thingsModelItemBase = new StringModelOutput(); | ||
| 71 | + | ||
| 72 | + ThingsModelDataTypeEnum thingsModelDataTypeEnum = Enum.valueOf(ThingsModelDataTypeEnum.class,type); | ||
| 73 | + switch (thingsModelDataTypeEnum) | ||
| 74 | + { | ||
| 75 | + case STRING: | ||
| 76 | + thingsModelItemBase = GsonConstructor.get().fromJson(jsonObject.toString(),StringModelOutput.class); | ||
| 77 | + break; | ||
| 78 | + case BOOL: | ||
| 79 | + thingsModelItemBase = GsonConstructor.get().fromJson(jsonObject.toString(),BoolModelOutput.class); | ||
| 80 | + break; | ||
| 81 | + case ENUM: | ||
| 82 | + thingsModelItemBase = GsonConstructor.get().fromJson(jsonObject.toString(),EnumModelOutput.class); | ||
| 83 | + break; | ||
| 84 | + case ARRAY: | ||
| 85 | + thingsModelItemBase = GsonConstructor.get().fromJson(jsonObject.toString(),ArrayModelOutput.class); | ||
| 86 | + break; | ||
| 87 | + case DECIMAL: | ||
| 88 | + thingsModelItemBase = GsonConstructor.get().fromJson(jsonObject.toString(),DecimalModelOutput.class); | ||
| 89 | + break; | ||
| 90 | + case INTEGER: | ||
| 91 | + thingsModelItemBase = GsonConstructor.get().fromJson(jsonObject.toString(),IntegerModelOutput.class); | ||
| 92 | + break; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + return thingsModelItemBase; | ||
| 96 | + } | ||
| 97 | + | ||
| 13 | /** 物模型唯一标识符 */ | 98 | /** 物模型唯一标识符 */ |
| 14 | private String id; | 99 | private String id; |
| 15 | /** 物模型名称 */ | 100 | /** 物模型名称 */ |
| @@ -2,18 +2,16 @@ package com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs; | @@ -2,18 +2,16 @@ package com.zhonglai.luhui.device.analysis.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.alibaba.fastjson.annotation.JSONField; |
| 5 | +import com.google.gson.JsonArray; | ||
| 6 | +import com.google.gson.JsonElement; | ||
| 5 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | 7 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; |
| 6 | import lombok.Data; | 8 | import lombok.Data; |
| 7 | 9 | ||
| 8 | @Data | 10 | @Data |
| 9 | -public class ArrayModelOutput extends ThingsModelItemBase<JSONArray> | 11 | +public class ArrayModelOutput extends ThingsModelItemBase<JsonArray> |
| 10 | { | 12 | { |
| 11 | private String arrayType; | 13 | private String arrayType; |
| 12 | 14 | ||
| 13 | - @Override | ||
| 14 | - public void addValue(Object jsonArray) { | ||
| 15 | - setValue((JSONArray) jsonArray); | ||
| 16 | - } | ||
| 17 | 15 | ||
| 18 | @Override | 16 | @Override |
| 19 | public String getView() { | 17 | public String getView() { |
| @@ -9,10 +9,6 @@ public class BoolModelOutput extends ThingsModelItemBase<Boolean> | @@ -9,10 +9,6 @@ public class BoolModelOutput extends ThingsModelItemBase<Boolean> | ||
| 9 | private String falseText; | 9 | private String falseText; |
| 10 | private String trueText; | 10 | private String trueText; |
| 11 | 11 | ||
| 12 | - @Override | ||
| 13 | - public void addValue(Object bl) { | ||
| 14 | - setValue((Boolean) bl); | ||
| 15 | - } | ||
| 16 | 12 | ||
| 17 | @Override | 13 | @Override |
| 18 | public String getView() { | 14 | public String getView() { |
| @@ -13,13 +13,6 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal> | @@ -13,13 +13,6 @@ public class DecimalModelOutput extends ThingsModelItemBase<BigDecimal> | ||
| 13 | private BigDecimal step; | 13 | private BigDecimal step; |
| 14 | private String unit; | 14 | private String unit; |
| 15 | 15 | ||
| 16 | - @Override | ||
| 17 | - public void addValue(Object object) { | ||
| 18 | - if(null != object) | ||
| 19 | - { | ||
| 20 | - setValue(new BigDecimal(object.toString())); | ||
| 21 | - } | ||
| 22 | - } | ||
| 23 | 16 | ||
| 24 | @Override | 17 | @Override |
| 25 | public String getView() { | 18 | public String getView() { |
| @@ -10,15 +10,11 @@ import java.util.Date; | @@ -10,15 +10,11 @@ import java.util.Date; | ||
| 10 | import java.util.List; | 10 | import java.util.List; |
| 11 | 11 | ||
| 12 | @Data | 12 | @Data |
| 13 | -public class EnumModelOutput extends ThingsModelItemBase<Object> | 13 | +public class EnumModelOutput extends ThingsModelItemBase<String> |
| 14 | { | 14 | { |
| 15 | private String clas; | 15 | private String clas; |
| 16 | private List<EnumItemOutput> enumList; | 16 | private List<EnumItemOutput> enumList; |
| 17 | 17 | ||
| 18 | - @Override | ||
| 19 | - public void addValue(Object object) { | ||
| 20 | - setValue(object); | ||
| 21 | - } | ||
| 22 | 18 | ||
| 23 | @Override | 19 | @Override |
| 24 | public String getView() { | 20 | public String getView() { |
| @@ -49,10 +45,6 @@ public class EnumModelOutput extends ThingsModelItemBase<Object> | @@ -49,10 +45,6 @@ public class EnumModelOutput extends ThingsModelItemBase<Object> | ||
| 49 | return getValue()+""; | 45 | return getValue()+""; |
| 50 | } | 46 | } |
| 51 | 47 | ||
| 52 | - public static void main(String[] args) { | ||
| 53 | - EnumModelOutput enumModelOutput = new EnumModelOutput(); | ||
| 54 | - System.out.println(enumModelOutput.getCmdView(1)); | ||
| 55 | - } | ||
| 56 | 48 | ||
| 57 | @Override | 49 | @Override |
| 58 | public Object getCmdView(Object object) { | 50 | public Object getCmdView(Object object) { |
| 1 | package com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs; | 1 | package com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs; |
| 2 | 2 | ||
| 3 | -import com.alibaba.fastjson.JSON; | ||
| 4 | -import com.alibaba.fastjson.JSONObject; | ||
| 5 | -import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelBase; | ||
| 6 | -import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | ||
| 7 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | 3 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; |
| 8 | -import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 9 | import lombok.Data; | 4 | import lombok.Data; |
| 10 | -import org.apache.commons.lang3.EnumUtils; | ||
| 11 | 5 | ||
| 12 | import java.math.BigDecimal; | 6 | import java.math.BigDecimal; |
| 13 | import java.math.RoundingMode; | 7 | import java.math.RoundingMode; |
| @@ -22,14 +16,6 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> | @@ -22,14 +16,6 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> | ||
| 22 | private String unit; //单位 | 16 | private String unit; //单位 |
| 23 | private Integer acy; //精度 | 17 | private Integer acy; //精度 |
| 24 | 18 | ||
| 25 | - @Override | ||
| 26 | - public void addValue(Object object) { | ||
| 27 | - if(null == object) | ||
| 28 | - { | ||
| 29 | - return; | ||
| 30 | - } | ||
| 31 | - setValue(new Double(String.valueOf(object)).intValue()); | ||
| 32 | - } | ||
| 33 | 19 | ||
| 34 | @Override | 20 | @Override |
| 35 | public String getView() { | 21 | public String getView() { |
| @@ -85,63 +71,4 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> | @@ -85,63 +71,4 @@ public class IntegerModelOutput extends ThingsModelItemBase<Integer> | ||
| 85 | } | 71 | } |
| 86 | return false; | 72 | return false; |
| 87 | } | 73 | } |
| 88 | - | ||
| 89 | - public static void main(String[] args) { | ||
| 90 | - IotThingsModel thingsModel = JSONObject.parseObject("{\"@type\":\"com.zhonglai.luhui.device.domain.IotThingsModel\",\"ascription\":\"1\",\"create_by\":\"admin\",\"data_type\":\"integer\",\"identifier\":\"turbidity\",\"is_config\":0,\"is_monitor\":0,\"is_save_log\":1,\"is_top\":0,\"model_id\":395,\"model_name\":\"浊度\",\"mqtt_username\":\"6_WP\",\"product_id\":9,\"specs\":\"{\\\"acy\\\":10,\\\"max\\\":999999,\\\"min\\\":0,\\\"step\\\":0.1,\\\"unit\\\":\\\"NTU\\\"}\",\"type\":1}\n", IotThingsModel.class); | ||
| 91 | - String data_type = thingsModel.getData_type().toUpperCase(); | ||
| 92 | - if (!EnumUtils.isValidEnum(ThingsModelDataTypeEnum.class, data_type)) { | ||
| 93 | - data_type = ThingsModelDataTypeEnum.STRING.name(); | ||
| 94 | - } | ||
| 95 | - Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class, data_type).getaClass(); | ||
| 96 | - ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(), aClass); | ||
| 97 | - thingsModelBase.conversionThingsModel(thingsModel); | ||
| 98 | - | ||
| 99 | - JSONObject jsData = JSONObject.parseObject("{\n" + | ||
| 100 | - " \"id\": 1714026179,\n" + | ||
| 101 | - " \"0\": {\n" + | ||
| 102 | - " \"rssi\": 18,\n" + | ||
| 103 | - " \"at\": 369,\n" + | ||
| 104 | - " \"bar\": 107987\n" + | ||
| 105 | - " },\n" + | ||
| 106 | - " \"10_1\": {\n" + | ||
| 107 | - " \"type\": 1,\n" + | ||
| 108 | - " \"mode\": 0,\n" + | ||
| 109 | - " \"state\": 0,\n" + | ||
| 110 | - " \"map\": \"1_1\"\n" + | ||
| 111 | - " },\n" + | ||
| 112 | - " \"10_2\": {\n" + | ||
| 113 | - " \"type\": 1,\n" + | ||
| 114 | - " \"mode\": 0,\n" + | ||
| 115 | - " \"state\": 0,\n" + | ||
| 116 | - " \"map\": \"1_2\"\n" + | ||
| 117 | - " },\n" + | ||
| 118 | - " \"10_3\": {\n" + | ||
| 119 | - " \"type\": 1,\n" + | ||
| 120 | - " \"mode\": 0,\n" + | ||
| 121 | - " \"state\": 0,\n" + | ||
| 122 | - " \"map\": \"1_3\"\n" + | ||
| 123 | - " },\n" + | ||
| 124 | - " \"10_4\": {\n" + | ||
| 125 | - " \"type\": 1,\n" + | ||
| 126 | - " \"mode\": 0,\n" + | ||
| 127 | - " \"state\": 0,\n" + | ||
| 128 | - " \"map\": \"1_4\"\n" + | ||
| 129 | - " },\n" + | ||
| 130 | - " \"1_3\": {\n" + | ||
| 131 | - " \"alarm\": 0,\n" + | ||
| 132 | - " \"turbidity\": 69,\n" + | ||
| 133 | - " \"wt\": 290\n" + | ||
| 134 | - " }\n" + | ||
| 135 | - "}", JSONObject.class); | ||
| 136 | - thingsModelBase.addValue(jsData.get("turbidity")); | ||
| 137 | - | ||
| 138 | - if (!thingsModelBase.checkValue()) { | ||
| 139 | - System.out.println("校验通过"); | ||
| 140 | - ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase; | ||
| 141 | - if(1==thingsModelItemBase.getIs_save_log() ) | ||
| 142 | - { | ||
| 143 | - System.out.println("要记录日志"); | ||
| 144 | - } | ||
| 145 | - } | ||
| 146 | - } | ||
| 147 | } | 74 | } |
| @@ -11,10 +11,6 @@ public class StringModelOutput extends ThingsModelItemBase<String> | @@ -11,10 +11,6 @@ public class StringModelOutput extends ThingsModelItemBase<String> | ||
| 11 | { | 11 | { |
| 12 | private int maxLength; | 12 | private int maxLength; |
| 13 | 13 | ||
| 14 | - @Override | ||
| 15 | - public void addValue(Object object) { | ||
| 16 | - setValue(null!=object?object+"":null); | ||
| 17 | - } | ||
| 18 | 14 | ||
| 19 | @Override | 15 | @Override |
| 20 | public String getView() { | 16 | public String getView() { |
| @@ -56,9 +56,9 @@ public class BusinessDataUpdateService { | @@ -56,9 +56,9 @@ public class BusinessDataUpdateService { | ||
| 56 | */ | 56 | */ |
| 57 | public void updataDta(Type type, Topic topic, ServerDto serverDto, String operationType, boolean isLog) | 57 | public void updataDta(Type type, Topic topic, ServerDto serverDto, String operationType, boolean isLog) |
| 58 | { | 58 | { |
| 59 | - logger.info("{} 开始更新数据",topic.getClientid()); | 59 | +// logger.info("{} 开始更新数据",topic.getClientid()); |
| 60 | IotDevice olddevice = cacheService.getIotDevice(topic.getClientid()); | 60 | IotDevice olddevice = cacheService.getIotDevice(topic.getClientid()); |
| 61 | - logger.info("{} 老数据获取成",topic.getClientid()); | 61 | +// logger.info("{} 老数据获取成",topic.getClientid()); |
| 62 | JSONObject data = new JSONObject(); | 62 | JSONObject data = new JSONObject(); |
| 63 | switch (type) | 63 | switch (type) |
| 64 | { | 64 | { |
| @@ -70,11 +70,11 @@ public class BusinessDataUpdateService { | @@ -70,11 +70,11 @@ public class BusinessDataUpdateService { | ||
| 70 | break; | 70 | break; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | - logger.info("{} 开始解析终端数据",topic.getClientid()); | 73 | +// logger.info("{} 开始解析终端数据",topic.getClientid()); |
| 74 | for(String key:data.keySet()) | 74 | for(String key:data.keySet()) |
| 75 | { | 75 | { |
| 76 | Object o = data.get(key); | 76 | Object o = data.get(key); |
| 77 | - logger.info("开始解析{}终端的数据,数据类型{}",key,o.getClass()); | 77 | +// logger.info("开始解析{}终端的数据,数据类型{}",key,o.getClass()); |
| 78 | 78 | ||
| 79 | if(o instanceof JSONObject) | 79 | if(o instanceof JSONObject) |
| 80 | { | 80 | { |
| @@ -97,7 +97,7 @@ public class BusinessDataUpdateService { | @@ -97,7 +97,7 @@ public class BusinessDataUpdateService { | ||
| 97 | iotDevice.setName(olddevice.getName()); | 97 | iotDevice.setName(olddevice.getName()); |
| 98 | serverDto.setIotDevice(iotDevice); | 98 | serverDto.setIotDevice(iotDevice); |
| 99 | }else{ //终端 | 99 | }else{ //终端 |
| 100 | - logger.info("{} 解析终端 {} 的数据",key,jsData.toJSONString()); | 100 | +// logger.info("{} 解析终端 {} 的数据",key,jsData.toJSONString()); |
| 101 | IotTerminal iotTerminal = translateTerminal(type,key,olddevice,jsData,serverDto,operationType,isLog); | 101 | IotTerminal iotTerminal = translateTerminal(type,key,olddevice,jsData,serverDto,operationType,isLog); |
| 102 | iotTerminal.setData_update_time(DateUtils.getNowTimeMilly()); | 102 | iotTerminal.setData_update_time(DateUtils.getNowTimeMilly()); |
| 103 | if(null== iotTerminal.getOnline() || 1 == iotTerminal.getOnline() || 4==iotTerminal.getOnline()) | 103 | if(null== iotTerminal.getOnline() || 1 == iotTerminal.getOnline() || 4==iotTerminal.getOnline()) |
| @@ -7,23 +7,17 @@ import com.zhonglai.luhui.device.analysis.comm.config.CacheConfig; | @@ -7,23 +7,17 @@ import com.zhonglai.luhui.device.analysis.comm.config.CacheConfig; | ||
| 7 | import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; | 7 | import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; |
| 8 | import com.zhonglai.luhui.device.analysis.comm.dto.ServerDto; | 8 | import com.zhonglai.luhui.device.analysis.comm.dto.ServerDto; |
| 9 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 9 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 10 | -import com.zhonglai.luhui.device.analysis.comm.service.redis.RedisService; | 10 | +import com.zhonglai.luhui.redis.service.RedisService; |
| 11 | import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; | 11 | import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; |
| 12 | -import com.zhonglai.luhui.device.analysis.comm.redis.RedisDeleteListener; | ||
| 13 | -import com.zhonglai.luhui.device.analysis.comm.redis.RedisExpiredListener; | 12 | +//import com.zhonglai.luhui.device.analysis.comm.redis.RedisDeleteListener; |
| 13 | +//import com.zhonglai.luhui.device.analysis.comm.redis.RedisExpiredListener; | ||
| 14 | import org.slf4j.Logger; | 14 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; | 15 | import org.slf4j.LoggerFactory; |
| 16 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
| 17 | -import org.springframework.context.annotation.Bean; | ||
| 18 | -import org.springframework.data.redis.connection.RedisConnection; | ||
| 19 | -import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
| 20 | -import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
| 21 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| 22 | -import org.springframework.util.StringUtils; | ||
| 23 | 18 | ||
| 24 | import java.util.List; | 19 | import java.util.List; |
| 25 | import java.util.Map; | 20 | import java.util.Map; |
| 26 | -import java.util.Properties; | ||
| 27 | import java.util.Set; | 21 | import java.util.Set; |
| 28 | 22 | ||
| 29 | @Service | 23 | @Service |
| @@ -46,7 +40,6 @@ public class CacheServiceImpl implements CacheService { | @@ -46,7 +40,6 @@ public class CacheServiceImpl implements CacheService { | ||
| 46 | iotDevice.setStatus(3); | 40 | iotDevice.setStatus(3); |
| 47 | } | 41 | } |
| 48 | setIotDeviceToRedis(iotDevice); | 42 | setIotDeviceToRedis(iotDevice); |
| 49 | - log.info("缓存更新 {} ",iotDevice); | ||
| 50 | 43 | ||
| 51 | List<IotTerminal> list = serverDto.getIotTerminalList(); | 44 | List<IotTerminal> list = serverDto.getIotTerminalList(); |
| 52 | if(null != list && list.size() != 0 ) | 45 | if(null != list && list.size() != 0 ) |
| @@ -56,7 +49,6 @@ public class CacheServiceImpl implements CacheService { | @@ -56,7 +49,6 @@ public class CacheServiceImpl implements CacheService { | ||
| 56 | setIotTerminalToRedis(iotTerminal); | 49 | setIotTerminalToRedis(iotTerminal); |
| 57 | } | 50 | } |
| 58 | } | 51 | } |
| 59 | - log.info("缓存更新 {} ",list); | ||
| 60 | return true; | 52 | return true; |
| 61 | } | 53 | } |
| 62 | 54 | ||
| @@ -253,26 +245,6 @@ public class CacheServiceImpl implements CacheService { | @@ -253,26 +245,6 @@ public class CacheServiceImpl implements CacheService { | ||
| 253 | return CacheConfig.FIELD+ CacheConfig.TERMINAL; | 245 | return CacheConfig.FIELD+ CacheConfig.TERMINAL; |
| 254 | } | 246 | } |
| 255 | 247 | ||
| 256 | - private String keyspaceNotificationsConfigParameter = "KEA"; | ||
| 257 | 248 | ||
| 258 | - @Autowired | ||
| 259 | - private RedisDeleteListener redisDeleteListener ; | ||
| 260 | - @Autowired | ||
| 261 | - private RedisExpiredListener redisExpiredListener ; | ||
| 262 | - @Bean | ||
| 263 | - RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) { | ||
| 264 | - RedisConnection connection = connectionFactory.getConnection(); | ||
| 265 | - Properties config = connection.info("notify-keyspace-events"); | ||
| 266 | 249 | ||
| 267 | - if (!StringUtils.hasText(config.getProperty("notify-keyspace-events"))) { | ||
| 268 | - connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter); | ||
| 269 | - } | ||
| 270 | - RedisMessageListenerContainer container = new RedisMessageListenerContainer(); | ||
| 271 | - container.setConnectionFactory(connectionFactory); | ||
| 272 | - //监听所有key的删除事件 | ||
| 273 | - container.addMessageListener(redisDeleteListener,redisDeleteListener.getTopic()); | ||
| 274 | - //监听所有key的过期事件 | ||
| 275 | - container.addMessageListener(redisExpiredListener,redisExpiredListener.getTopic()); | ||
| 276 | - return container; | ||
| 277 | - } | ||
| 278 | } | 250 | } |
| 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.JSON; | ||
| 4 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | +import com.google.gson.JsonObject; | ||
| 5 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; | 6 | import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; |
| 6 | import com.zhonglai.luhui.device.analysis.comm.db.mode.TerminalDataThingsModeService; | 7 | import com.zhonglai.luhui.device.analysis.comm.db.mode.TerminalDataThingsModeService; |
| 7 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | 8 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; |
| 8 | import com.zhonglai.luhui.device.analysis.comm.dto.ServerDto; | 9 | import com.zhonglai.luhui.device.analysis.comm.dto.ServerDto; |
| 9 | -import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelBase; | ||
| 10 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | 10 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; |
| 11 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | 11 | import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; |
| 12 | import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; | 12 | import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; |
| @@ -66,8 +66,8 @@ public class DataModeAnalysisService { | @@ -66,8 +66,8 @@ public class DataModeAnalysisService { | ||
| 66 | JSONObject data = new JSONObject(); | 66 | JSONObject data = new JSONObject(); |
| 67 | 67 | ||
| 68 | JSONObject config = new JSONObject(); | 68 | JSONObject config = new JSONObject(); |
| 69 | - | ||
| 70 | - for(String key:jsData.keySet()) | 69 | + JsonObject gsonData = GsonConstructor.get().fromJson(jsData.toJSONString(), JsonObject.class); |
| 70 | + for(String key:gsonData.keySet()) | ||
| 71 | { | 71 | { |
| 72 | IotThingsModel thingsModel = terminalDataThingsModeService.getIotThingsModel(userName,key); | 72 | IotThingsModel thingsModel = terminalDataThingsModeService.getIotThingsModel(userName,key); |
| 73 | if(null == thingsModel) //没有配置的 都按字符串处理 | 73 | if(null == thingsModel) //没有配置的 都按字符串处理 |
| @@ -89,24 +89,19 @@ public class DataModeAnalysisService { | @@ -89,24 +89,19 @@ public class DataModeAnalysisService { | ||
| 89 | { | 89 | { |
| 90 | data_type = ThingsModelDataTypeEnum.STRING.name(); | 90 | data_type = ThingsModelDataTypeEnum.STRING.name(); |
| 91 | } | 91 | } |
| 92 | - Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class,data_type).getaClass(); | ||
| 93 | - ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(),aClass); | ||
| 94 | - thingsModelBase.conversionThingsModel(thingsModel); | ||
| 95 | - | ||
| 96 | - thingsModelBase.addValue(jsData.get(key)); | 92 | + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel, gsonData.get(key)); |
| 97 | 93 | ||
| 98 | - if(!thingsModelBase.checkValue()) | 94 | + if(!thingsModelItemBase.checkValue()) |
| 99 | { | 95 | { |
| 100 | continue; | 96 | continue; |
| 101 | } | 97 | } |
| 102 | - ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase; | ||
| 103 | //记录数据日志 | 98 | //记录数据日志 |
| 104 | - log.info("设备{}的数据{}记录日志,【条件{},{}】",id,key,thingsModelItemBase.getIs_save_log(),null != serverDto.getDeviceSensorDataList()); | 99 | +// log.info("设备{}的数据{}记录日志,【条件{},{}】",id,key,thingsModelItemBase.getIs_save_log(),null != serverDto.getDeviceSensorDataList()); |
| 105 | if(1==thingsModelItemBase.getIs_save_log() && null != serverDto.getDeviceSensorDataList()) | 100 | if(1==thingsModelItemBase.getIs_save_log() && null != serverDto.getDeviceSensorDataList()) |
| 106 | { | 101 | { |
| 107 | DeviceSensorData sensorData = new DeviceSensorData(); | 102 | DeviceSensorData sensorData = new DeviceSensorData(); |
| 108 | sensorData.setDataType(key); | 103 | sensorData.setDataType(key); |
| 109 | - sensorData.setDataValue(thingsModelBase.getSaveView()); | 104 | + sensorData.setDataValue(thingsModelItemBase.getSaveView()); |
| 110 | sensorData.setCreatTime(DateUtils.getNowTimeMilly()); | 105 | sensorData.setCreatTime(DateUtils.getNowTimeMilly()); |
| 111 | sensorData.setDeviceModel(userName); | 106 | sensorData.setDeviceModel(userName); |
| 112 | sensorData.setDeviceInfoId(id); | 107 | sensorData.setDeviceInfoId(id); |
| @@ -116,17 +111,17 @@ public class DataModeAnalysisService { | @@ -116,17 +111,17 @@ public class DataModeAnalysisService { | ||
| 116 | switch (thingsModel.getIs_config()) | 111 | switch (thingsModel.getIs_config()) |
| 117 | { | 112 | { |
| 118 | case 0: | 113 | case 0: |
| 119 | - data.put(key,thingsModelBase); | 114 | + data.put(key,thingsModelItemBase); |
| 120 | break; | 115 | break; |
| 121 | case 1: | 116 | case 1: |
| 122 | - config.put(key,thingsModelBase); | 117 | + config.put(key,thingsModelItemBase); |
| 123 | break; | 118 | break; |
| 124 | case 2: | 119 | case 2: |
| 125 | - config.put(key,thingsModelBase); | ||
| 126 | - data.put(key,thingsModelBase); | 120 | + config.put(key,thingsModelItemBase); |
| 121 | + data.put(key,thingsModelItemBase); | ||
| 127 | break; | 122 | break; |
| 128 | default: | 123 | default: |
| 129 | - data.put(key,thingsModelBase); | 124 | + data.put(key,thingsModelItemBase); |
| 130 | break; | 125 | break; |
| 131 | } | 126 | } |
| 132 | } | 127 | } |
| 1 | -package com.zhonglai.luhui.mqtt.comm.util; | 1 | +package com.zhonglai.luhui.device.analysis.util; |
| 2 | 2 | ||
| 3 | import com.zhonglai.luhui.device.analysis.comm.dto.MyException; | 3 | import com.zhonglai.luhui.device.analysis.comm.dto.MyException; |
| 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 4 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| @@ -16,8 +16,13 @@ public class TopicUtil { | @@ -16,8 +16,13 @@ public class TopicUtil { | ||
| 16 | public static Topic initTopic(String topic) | 16 | public static Topic initTopic(String topic) |
| 17 | { | 17 | { |
| 18 | topic = Optional.ofNullable(topic).orElseThrow(()->new MyException("topic为空")); | 18 | topic = Optional.ofNullable(topic).orElseThrow(()->new MyException("topic为空")); |
| 19 | + return initTopicFromModelStr(topic,SysParameter.topicconfig); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public static Topic initTopicFromModelStr(String topic,String modelStr) | ||
| 23 | + { | ||
| 19 | String[] sts = topic.split("/"); | 24 | String[] sts = topic.split("/"); |
| 20 | - String[] config = SysParameter.topicconfig.split("/"); | 25 | + String[] config = modelStr.split("/"); |
| 21 | int number = sts.length; | 26 | int number = sts.length; |
| 22 | if(number>config.length) | 27 | if(number>config.length) |
| 23 | { | 28 | { |
| @@ -127,6 +127,7 @@ public class IotDevice implements Serializable | @@ -127,6 +127,7 @@ public class IotDevice implements Serializable | ||
| 127 | @ApiModelProperty("数据更新时间") | 127 | @ApiModelProperty("数据更新时间") |
| 128 | private Integer data_update_time; | 128 | private Integer data_update_time; |
| 129 | 129 | ||
| 130 | + | ||
| 130 | public Integer getData_update_time() { | 131 | public Integer getData_update_time() { |
| 131 | return data_update_time; | 132 | return data_update_time; |
| 132 | } | 133 | } |
| @@ -60,6 +60,49 @@ public class IotProduct implements Serializable | @@ -60,6 +60,49 @@ public class IotProduct implements Serializable | ||
| 60 | private String product_name; | 60 | private String product_name; |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | + @ApiModelProperty("是否需要同步数据库(0否,1是)") | ||
| 64 | + private Integer is_sync_db; | ||
| 65 | + | ||
| 66 | + @ApiModelProperty("需要同步数据库的名称") | ||
| 67 | + private String sync_db; | ||
| 68 | + | ||
| 69 | + @ApiModelProperty("解析服务") | ||
| 70 | + private String analysis_clas; // varchar(100) DEFAULT 'com.zhonglai.luhui.device.protocol.factory.analysis.DefaultProtocolParserFactoryImpl' COMMENT '解析服务', | ||
| 71 | + | ||
| 72 | + @ApiModelProperty("清洗服务") | ||
| 73 | + private String purification_clas; // varchar(100) DEFAULT 'com.zhonglai.luhui.device.protocol.factory.purification.DefaultProtocolPurificationFactoryImpl' COMMENT '清洗服务', | ||
| 74 | + | ||
| 75 | + public String getPurification_clas() { | ||
| 76 | + return purification_clas; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void setPurification_clas(String purification_clas) { | ||
| 80 | + this.purification_clas = purification_clas; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public String getAnalysis_clas() { | ||
| 84 | + return analysis_clas; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public void setAnalysis_clas(String analysis_clas) { | ||
| 88 | + this.analysis_clas = analysis_clas; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public Integer getIs_sync_db() { | ||
| 92 | + return is_sync_db; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public void setIs_sync_db(Integer is_sync_db) { | ||
| 96 | + this.is_sync_db = is_sync_db; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public String getSync_db() { | ||
| 100 | + return sync_db; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public void setSync_db(String sync_db) { | ||
| 104 | + this.sync_db = sync_db; | ||
| 105 | + } | ||
| 63 | public void setCreate_time(Integer create_time) | 106 | public void setCreate_time(Integer create_time) |
| 64 | { | 107 | { |
| 65 | this.create_time = create_time; | 108 | this.create_time = create_time; |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-device-protocol-parser</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <artifactId>lh-device-http-public</artifactId> | ||
| 13 | + | ||
| 14 | + <properties> | ||
| 15 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 16 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 17 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 18 | + </properties> | ||
| 19 | + | ||
| 20 | + <dependencies> | ||
| 21 | + <dependency> | ||
| 22 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 23 | + <artifactId>lh-device-protocol-factory</artifactId> | ||
| 24 | + </dependency> | ||
| 25 | + </dependencies> | ||
| 26 | +</project> |
| 1 | +package com.zhonglai.luhui.device.protocol.http.analysis.analysis; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.google.gson.JsonObject; | ||
| 5 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; | ||
| 9 | +import org.springframework.stereotype.Service; | ||
| 10 | + | ||
| 11 | +import java.util.Map; | ||
| 12 | + | ||
| 13 | +@Service | ||
| 14 | +public class ProtocolParserServiceImpl implements ProtocolParserFactory<JsonObject> { | ||
| 15 | + private static final String topicModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{imei}}/{{topicType}}"; | ||
| 16 | + | ||
| 17 | + @Override | ||
| 18 | + public Topic analysisTopic(String topicStr) { | ||
| 19 | + // /13/jiulin/476210165B365166812345678Userdata/Json/476210165B365166812345678/pub_data | ||
| 20 | + Topic topic = TopicUtil.initTopicFromModelStr(topicStr,topicModel); | ||
| 21 | + return topic; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public JsonObject analysisPayload(Topic topic, JsonObject payload) { | ||
| 26 | + return payload; | ||
| 27 | + } | ||
| 28 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.http.analysis.purification; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.DateUtils; | ||
| 5 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 7 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | ||
| 9 | +import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 10 | +import com.zhonglai.luhui.device.protocol.factory.purification.ProtocolPurificationFactory; | ||
| 11 | +import org.springframework.stereotype.Service; | ||
| 12 | + | ||
| 13 | +import java.util.ArrayList; | ||
| 14 | +import java.util.List; | ||
| 15 | +import java.util.Map; | ||
| 16 | + | ||
| 17 | +@Service("http_purification") | ||
| 18 | +public class ProtocolPurificationServiceImpl implements ProtocolPurificationFactory { | ||
| 19 | + | ||
| 20 | + @Override | ||
| 21 | + public ProtocolPurificationModel purification(Integer product_id, Topic topic, JsonObject analysisObject ) { | ||
| 22 | + return null; | ||
| 23 | + } | ||
| 24 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.http.analysis.service; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; | ||
| 4 | +import com.zhonglai.luhui.device.domain.IotDevice; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.http.analysis.service.db.LsyDBFactoryImp; | ||
| 6 | +import org.springframework.stereotype.Service; | ||
| 7 | + | ||
| 8 | +import java.util.List; | ||
| 9 | +import java.util.Map; | ||
| 10 | + | ||
| 11 | +@Service | ||
| 12 | +public class LsyDbService { | ||
| 13 | + private BaseDao lsy_baseDao = new BaseDao(new LsyDBFactoryImp()); | ||
| 14 | + | ||
| 15 | + public IotDevice getLsyDeviceById(String id) | ||
| 16 | + { | ||
| 17 | + List<Map<String,Object>> list = lsy_baseDao.findListBysql("SELECT order_dtu_imei,device_type FROM `order_dtu` WHERE order_dtu_imei='"+id+"'"); | ||
| 18 | + if(null != list && list.size() != 0) | ||
| 19 | + { | ||
| 20 | + Map<String,Object> map = list.get(0); | ||
| 21 | + IotDevice iotDevice = new IotDevice(); | ||
| 22 | + iotDevice.setClient_id(id); | ||
| 23 | + iotDevice.setMqtt_username(map.get("device_type")+""); | ||
| 24 | + return iotDevice; | ||
| 25 | + } | ||
| 26 | + return null; | ||
| 27 | + } | ||
| 28 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.http.analysis.service.db; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.analysis.comm.dao.DBFactory; | ||
| 4 | +import org.apache.commons.dbcp.BasicDataSourceFactory; | ||
| 5 | + | ||
| 6 | +import javax.sql.DataSource; | ||
| 7 | +import java.io.FileInputStream; | ||
| 8 | +import java.util.Properties; | ||
| 9 | + | ||
| 10 | +public class LsyDBFactoryImp implements DBFactory { | ||
| 11 | + private static DataSource ds = null; | ||
| 12 | + static { | ||
| 13 | + try { | ||
| 14 | + if(null==ds ) | ||
| 15 | + { | ||
| 16 | + String dbPath = System.getProperty("dbPath"); | ||
| 17 | + String path = null != dbPath?dbPath:System.getProperty("user.dir")+"/configs/"; | ||
| 18 | + Properties p = new Properties(); | ||
| 19 | + System.out.println("》》》》》》》》》》》》》数据库配置文件地址:"+path+"lsy_dbcpconfig.properties"); | ||
| 20 | + p.load(new FileInputStream(path+"lsy_dbcpconfig.properties")); | ||
| 21 | +// p.load(DBFactory.class | ||
| 22 | +// .getClassLoader().getResourceAsStream("configs/dbcpconfig.properties")); | ||
| 23 | + ds = BasicDataSourceFactory.createDataSource(p); | ||
| 24 | + } | ||
| 25 | + } catch (Exception e) { | ||
| 26 | + e.printStackTrace(); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public DataSource getDataSource() { | ||
| 32 | + return ds; | ||
| 33 | + } | ||
| 34 | +} |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-device-protocol-parser</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <artifactId>lh-device-protocol-factory</artifactId> | ||
| 13 | + | ||
| 14 | + <properties> | ||
| 15 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 16 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 17 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 18 | + </properties> | ||
| 19 | + | ||
| 20 | + <dependencies> | ||
| 21 | + <dependency> | ||
| 22 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 23 | + <artifactId>lh-jar-device-analysis</artifactId> | ||
| 24 | + <scope>compile</scope> | ||
| 25 | + </dependency> | ||
| 26 | + </dependencies> | ||
| 27 | + | ||
| 28 | + <description> | ||
| 29 | + 协议工厂 | ||
| 30 | + </description> | ||
| 31 | +</project> |
| 1 | +package com.zhonglai.luhui.device.protocol.factory; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; | ||
| 7 | +import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; | ||
| 9 | +import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; | ||
| 10 | +import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 11 | +import com.zhonglai.luhui.device.protocol.factory.purification.ProtocolPurificationFactory; | ||
| 12 | +import org.slf4j.Logger; | ||
| 13 | +import org.slf4j.LoggerFactory; | ||
| 14 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 15 | +import org.springframework.stereotype.Component; | ||
| 16 | + | ||
| 17 | +import java.util.Map; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * 协议解析工厂 | ||
| 21 | + */ | ||
| 22 | +@Component | ||
| 23 | +public class ProtocolParserAndPurificationFactory<T> { | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 根据topic对payload数据进行解析和清洗 | ||
| 27 | + * @param topicStr 身份信息 | ||
| 28 | + * @param payload 数据信息 | ||
| 29 | + * @return | ||
| 30 | + */ | ||
| 31 | + public ProtocolPurificationModel analysisAndPurification(Integer product_id,String topicStr, T payload ,String analysis_clas,String purification_clas) throws ClassNotFoundException { | ||
| 32 | + Topic baseTopic = TopicUtil.initTopicFromModelStr(topicStr,"/{{roleid}}/{{username}}"); //我们定义的topic | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + //根据产品类型找到对应的解析服务 | ||
| 36 | + ProtocolParserFactory protocolParserFactory = (ProtocolParserFactory) SpringUtils.getBean(Class.forName(analysis_clas)); | ||
| 37 | + //根据产品类型找到对应的清洗服务 | ||
| 38 | + ProtocolPurificationFactory protocolPurificationFactory = (ProtocolPurificationFactory) SpringUtils.getBean(Class.forName(purification_clas)); | ||
| 39 | + | ||
| 40 | + if(null != protocolParserFactory && null != protocolPurificationFactory) //需要解析服务和清除服务都存在业务才能进行下去 | ||
| 41 | + { | ||
| 42 | + //通过解析服务获取到topic | ||
| 43 | + Topic topic = protocolParserFactory.analysisTopic(topicStr); | ||
| 44 | + //通过解析服务器将数据解析成键值对的形式存储到json对象里面,方便清洗 | ||
| 45 | + JsonObject jsonObject = protocolParserFactory.analysisPayload(topic,payload); | ||
| 46 | + | ||
| 47 | + //通过模式对解析结果进行清洗,获得到的数据就是业务数据 | ||
| 48 | + ProtocolPurificationModel protocolPurificationModel = protocolPurificationFactory.purification(product_id,topic,jsonObject); | ||
| 49 | + return protocolPurificationModel; | ||
| 50 | + | ||
| 51 | + } | ||
| 52 | + DeviceDataLog.error(baseTopic.getClientid(), DataLogType.解析消息,"没有找到可以解析的服务:"+baseTopic.getUsername()); | ||
| 53 | + | ||
| 54 | + return null; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.analysis; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; | ||
| 7 | +import org.springframework.stereotype.Service; | ||
| 8 | + | ||
| 9 | +@Service | ||
| 10 | +public class DefaultProtocolParserFactoryImpl implements ProtocolParserFactory<byte[]>{ | ||
| 11 | + private static final String topicModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{imei}}/{{topicType}}"; | ||
| 12 | + | ||
| 13 | + @Override | ||
| 14 | + public Topic analysisTopic(String topicStr) { | ||
| 15 | + // /13/jiulin/476210165B365166812345678Userdata/Json/476210165B365166812345678/pub_data | ||
| 16 | + Topic topic = TopicUtil.initTopicFromModelStr(topicStr,topicModel); | ||
| 17 | + return topic; | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + @Override | ||
| 21 | + public JsonObject analysisPayload(Topic topic, byte[] payload) { | ||
| 22 | + return GsonConstructor.get().fromJson(new String(payload), JsonObject.class); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.analysis; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 协议解析工厂 | ||
| 8 | + * @param <T> | ||
| 9 | + */ | ||
| 10 | +public interface ProtocolParserFactory<T> { | ||
| 11 | + Topic analysisTopic(String topicStr); | ||
| 12 | + JsonObject analysisPayload(Topic topic, T payload); | ||
| 13 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.comm; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.protocol.factory.ProtocolParserAndPurificationFactory; | ||
| 4 | +import org.slf4j.Logger; | ||
| 5 | +import org.slf4j.LoggerFactory; | ||
| 6 | + | ||
| 7 | +public class DeviceDataLog { | ||
| 8 | + /** | ||
| 9 | + * 自定义设备数据交付日志 | ||
| 10 | + */ | ||
| 11 | + private static final Logger mylog = LoggerFactory.getLogger("myDatalog"); | ||
| 12 | + | ||
| 13 | + public static void info(String imei,DataLogType dataLogType,String topic,Object message) | ||
| 14 | + { | ||
| 15 | + mylog.info("【{}】【{}】【{}】【{}】",imei,dataLogType,topic,message); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + public static void error(String imei,DataLogType dataLogType,Object message) | ||
| 19 | + { | ||
| 20 | + mylog.error("【{}】【{}】【{}】【{}】",imei,dataLogType,message); | ||
| 21 | + } | ||
| 22 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.config; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 4 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | ||
| 5 | +import net.jodah.expiringmap.ExpirationListener; | ||
| 6 | +import net.jodah.expiringmap.ExpirationPolicy; | ||
| 7 | +import net.jodah.expiringmap.ExpiringMap; | ||
| 8 | +import org.slf4j.Logger; | ||
| 9 | +import org.slf4j.LoggerFactory; | ||
| 10 | + | ||
| 11 | +import java.util.concurrent.TimeUnit; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 用map管理内存中的设备信息 | ||
| 15 | + */ | ||
| 16 | +public class DeviceCach { | ||
| 17 | + private static Logger log = LoggerFactory.getLogger(DeviceCach.class); | ||
| 18 | + // maxSize: 设置最大值,添加第11个entry时,会导致第1个立马过期(即使没到过期时间) | ||
| 19 | + // expiration:设置每个key有效时间10s, 如果key不设置过期时间,key永久有效。 | ||
| 20 | + // variableExpiration: 允许更新过期时间值,如果不设置variableExpiration,不允许后面更改过期时间,一旦执行更改过期时间操作会抛异常UnsupportedOperationException | ||
| 21 | + // policy: | ||
| 22 | + // CREATED: 只在put和replace方法清零过期时间 | ||
| 23 | + // ACCESSED: 在CREATED策略基础上增加, 在还没过期时get方法清零过期时间。 | ||
| 24 | + // 清零过期时间也就是重置过期时间,重新计算过期时间. | ||
| 25 | + private static ExpiringMap<String, ParserDeviceInfoDto> parserDeviceInfoDtoMap = ExpiringMap.builder().maxSize(20000).expiration(60, TimeUnit.SECONDS) | ||
| 26 | + .variableExpiration() | ||
| 27 | + .asyncExpirationListener(new ExpirationListener<String, ParserDeviceInfoDto>() { | ||
| 28 | + @Override | ||
| 29 | + public void expired(String s, ParserDeviceInfoDto parserDeviceInfoDto) { | ||
| 30 | + log.info("超时清除>>>>>>>:{} ",s); | ||
| 31 | + } | ||
| 32 | + }) | ||
| 33 | + .expirationPolicy(ExpirationPolicy.CREATED).build(); | ||
| 34 | + | ||
| 35 | + private static ExpiringMap<String, ParserDeviceHostDto> parserDeviceHostDtoMap = ExpiringMap.builder().maxSize(20000).expiration(60, TimeUnit.SECONDS) | ||
| 36 | + .variableExpiration() | ||
| 37 | + .asyncExpirationListener(new ExpirationListener<String, ParserDeviceHostDto>() { | ||
| 38 | + @Override | ||
| 39 | + public void expired(String s, ParserDeviceHostDto parserDeviceHostDto) { | ||
| 40 | + log.info("超时清除>>>>>>>:{} ",s); | ||
| 41 | + } | ||
| 42 | + }) | ||
| 43 | + .expirationPolicy(ExpirationPolicy.CREATED).build(); | ||
| 44 | + | ||
| 45 | + public static void putDeviceInfo(ParserDeviceInfoDto parserDeviceInfoDto,Long device_life) | ||
| 46 | + { | ||
| 47 | + parserDeviceInfoDtoMap.put(parserDeviceInfoDto.getId(),parserDeviceInfoDto,device_life,TimeUnit.SECONDS); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + public static void putDeviceHost(ParserDeviceHostDto parserDeviceHostDto,Long device_life) | ||
| 51 | + { | ||
| 52 | + parserDeviceHostDtoMap.put(parserDeviceHostDto.getId(),parserDeviceHostDto,device_life,TimeUnit.SECONDS); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public static ParserDeviceInfoDto getDeviceInfo(String deviceInfoId) | ||
| 56 | + { | ||
| 57 | + return parserDeviceInfoDtoMap.get(deviceInfoId); | ||
| 58 | + } | ||
| 59 | + public static ParserDeviceHostDto getDeviceHost(String deviceId) | ||
| 60 | + { | ||
| 61 | + return parserDeviceHostDtoMap.get(deviceId); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + public static void reDeviceInfo(String deviceInfoId) | ||
| 65 | + { | ||
| 66 | + parserDeviceInfoDtoMap.remove(deviceInfoId); | ||
| 67 | + } | ||
| 68 | + public static void reDeviceHost(String deviceId) | ||
| 69 | + { | ||
| 70 | + parserDeviceHostDtoMap.remove(deviceId); | ||
| 71 | + } | ||
| 72 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.dto; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +@Data | ||
| 10 | +public class AnalysisDto { | ||
| 11 | + private JsonObject things_model_value; | ||
| 12 | + private JsonObject things_model_config; | ||
| 13 | + private List<DeviceSensorData> deviceSensorDataList; | ||
| 14 | + | ||
| 15 | + public AnalysisDto pushDeviceSensorData(List<DeviceSensorData> deviceSensorDataList) | ||
| 16 | + { | ||
| 17 | + if(null != deviceSensorDataList && null != this.deviceSensorDataList && this.deviceSensorDataList.size() != 0) | ||
| 18 | + { | ||
| 19 | + deviceSensorDataList.addAll(this.deviceSensorDataList); | ||
| 20 | + } | ||
| 21 | + return this; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public ParserDeviceHostDto toParserDeviceHostDto(String id) | ||
| 25 | + { | ||
| 26 | + ParserDeviceHostDto parserDeviceHostDto = new ParserDeviceHostDto(); | ||
| 27 | + parserDeviceHostDto.setData(things_model_value); | ||
| 28 | + parserDeviceHostDto.setConfig(things_model_config); | ||
| 29 | + parserDeviceHostDto.setId(id); | ||
| 30 | + return parserDeviceHostDto; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public ParserDeviceInfoDto toParserDeviceInfoDto(String id) | ||
| 34 | + { | ||
| 35 | + ParserDeviceInfoDto parserDeviceInfoDto = new ParserDeviceInfoDto(); | ||
| 36 | + parserDeviceInfoDto.setData(things_model_value); | ||
| 37 | + parserDeviceInfoDto.setConfig(things_model_config); | ||
| 38 | + parserDeviceInfoDto.setId(id); | ||
| 39 | + return parserDeviceInfoDto; | ||
| 40 | + } | ||
| 41 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.dto; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import io.swagger.annotations.ApiModelProperty; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +@Data | ||
| 8 | +public class ParserDeviceHostDto { | ||
| 9 | + /** | ||
| 10 | + * 主键id | ||
| 11 | + */ | ||
| 12 | + private String id; | ||
| 13 | + /** | ||
| 14 | + * 数据 | ||
| 15 | + */ | ||
| 16 | + private JsonObject data; | ||
| 17 | + /** | ||
| 18 | + * 配置 | ||
| 19 | + */ | ||
| 20 | + private JsonObject config; | ||
| 21 | + /** | ||
| 22 | + * 数据更新时间 | ||
| 23 | + */ | ||
| 24 | + private Integer updateTime; | ||
| 25 | + /** | ||
| 26 | + * 生命周期 | ||
| 27 | + */ | ||
| 28 | + private Long device_life; | ||
| 29 | + /** | ||
| 30 | + * 数据类型 | ||
| 31 | + */ | ||
| 32 | + private String device_type; | ||
| 33 | + /** | ||
| 34 | + *同步数据的 | ||
| 35 | + */ | ||
| 36 | + private String sync_db; | ||
| 37 | + /** | ||
| 38 | + *是否同步数据 | ||
| 39 | + */ | ||
| 40 | + private boolean is_sync_db; | ||
| 41 | + /** | ||
| 42 | + *产品id | ||
| 43 | + */ | ||
| 44 | + private Integer product_id; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 解析服务 | ||
| 48 | + */ | ||
| 49 | + private String analysis_clas; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 清洗服务 | ||
| 53 | + */ | ||
| 54 | + private String purification_clas; | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 设备摘要,格式{{"name":"device"},{"chip":"esp8266"}} | ||
| 58 | + */ | ||
| 59 | + private JsonObject summary; | ||
| 60 | + | ||
| 61 | + private boolean is_config_up; | ||
| 62 | + private boolean is_data_up; | ||
| 63 | + private boolean is_summary_up; | ||
| 64 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.dto; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +@Data | ||
| 7 | +public class ParserDeviceInfoDto { | ||
| 8 | + private String id; | ||
| 9 | + private String deviceInfoName; | ||
| 10 | + private JsonObject data; | ||
| 11 | + private JsonObject config; | ||
| 12 | + private Integer updateTime; | ||
| 13 | + private boolean is_data_up; | ||
| 14 | + private boolean is_conf_up; | ||
| 15 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.dto; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | ||
| 6 | +import lombok.Data; | ||
| 7 | + | ||
| 8 | +import java.util.ArrayList; | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 协议清洗模型 | ||
| 13 | + */ | ||
| 14 | +public class ProtocolPurificationModel { | ||
| 15 | + private ParserDeviceHostDto parserDeviceHostDto = new ParserDeviceHostDto(); | ||
| 16 | + private List<ParserDeviceInfoDto> parserDeviceInfoDtoList = new ArrayList<>(); | ||
| 17 | + private List<DeviceSensorData> deviceSensorDataList = new ArrayList<>(); | ||
| 18 | + private List<LogDeviceOperation> logDeviceOperationList = new ArrayList<>(); | ||
| 19 | + | ||
| 20 | + public ParserDeviceHostDto getParserDeviceHostDto() { | ||
| 21 | + return parserDeviceHostDto; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public void setParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto) { | ||
| 25 | + this.parserDeviceHostDto = parserDeviceHostDto; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public List<ParserDeviceInfoDto> getParserDeviceInfoDtoList() { | ||
| 29 | + return parserDeviceInfoDtoList; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public void setParserDeviceInfoDtoList(List<ParserDeviceInfoDto> parserDeviceInfoDtoList) { | ||
| 33 | + this.parserDeviceInfoDtoList = parserDeviceInfoDtoList; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public List<DeviceSensorData> getDeviceSensorDataList() { | ||
| 37 | + return deviceSensorDataList; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public void setDeviceSensorDataList(List<DeviceSensorData> deviceSensorDataList) { | ||
| 41 | + this.deviceSensorDataList = deviceSensorDataList; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public List<LogDeviceOperation> getLogDeviceOperationList() { | ||
| 45 | + return logDeviceOperationList; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public void setLogDeviceOperationList(List<LogDeviceOperation> logDeviceOperationList) { | ||
| 49 | + this.logDeviceOperationList = logDeviceOperationList; | ||
| 50 | + } | ||
| 51 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.purification; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.alibaba.fastjson.JSONObject; | ||
| 5 | +import com.google.gson.JsonElement; | ||
| 6 | +import com.google.gson.JsonObject; | ||
| 7 | +import com.ruoyi.common.utils.DateUtils; | ||
| 8 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 9 | +import com.ruoyi.common.utils.StringUtils; | ||
| 10 | +import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | ||
| 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; | ||
| 14 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 15 | +import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 16 | +import com.zhonglai.luhui.device.protocol.factory.dto.AnalysisDto; | ||
| 17 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 18 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | ||
| 19 | +import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 20 | +import com.zhonglai.luhui.device.protocol.factory.service.IotThingsModelService; | ||
| 21 | +import com.zhonglai.luhui.device.protocol.factory.service.PersistenceDBService; | ||
| 22 | +import org.apache.commons.lang3.EnumUtils; | ||
| 23 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 24 | +import org.springframework.stereotype.Service; | ||
| 25 | + | ||
| 26 | +import java.util.ArrayList; | ||
| 27 | +import java.util.List; | ||
| 28 | +import java.util.Map; | ||
| 29 | + | ||
| 30 | +@Service("default_purification") | ||
| 31 | +public class DefaultProtocolPurificationFactoryImpl implements ProtocolPurificationFactory{ | ||
| 32 | + @Autowired | ||
| 33 | + private IotThingsModelService iotThingsModelService; | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public ProtocolPurificationModel purification(Integer product_id,Topic topic, JsonObject protocolParserModel ) { | ||
| 37 | + if(null != protocolParserModel && protocolParserModel.size()!=0) | ||
| 38 | + { | ||
| 39 | + ProtocolPurificationModel protocolPurificationModel = new ProtocolPurificationModel(); | ||
| 40 | + ParserDeviceHostDto parserDeviceHostDto = analysisHost(product_id,topic,protocolParserModel,protocolPurificationModel.getDeviceSensorDataList()); | ||
| 41 | + protocolPurificationModel.setParserDeviceHostDto(parserDeviceHostDto); | ||
| 42 | + | ||
| 43 | + List<ParserDeviceInfoDto> parserDeviceInfoDtoList = analysisDeviceInfo(product_id,topic,protocolParserModel,protocolPurificationModel.getDeviceSensorDataList()); | ||
| 44 | + protocolPurificationModel.setParserDeviceInfoDtoList(parserDeviceInfoDtoList); | ||
| 45 | + return protocolPurificationModel; | ||
| 46 | + } | ||
| 47 | + return null; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + private ParserDeviceHostDto analysisHost(Integer product_id,Topic topic, JsonObject data,List<DeviceSensorData> deviceSensorDataList ) | ||
| 51 | + { | ||
| 52 | + if(data.has("0")) | ||
| 53 | + { | ||
| 54 | + JsonObject jsonObjectData = GsonConstructor.get().fromJson(GsonConstructor.get().toJson(data.get("0")),JsonObject.class); | ||
| 55 | + JsonObject summary = null; | ||
| 56 | + //解析设备摘要 | ||
| 57 | + if(jsonObjectData.has("summary") && null != jsonObjectData.get("summary") && jsonObjectData.get("summary").isJsonObject()) | ||
| 58 | + { | ||
| 59 | + summary = jsonObjectData.get("summary").getAsJsonObject(); | ||
| 60 | + jsonObjectData.remove("summary"); | ||
| 61 | + } | ||
| 62 | + ParserDeviceHostDto parserDeviceHostDto = null; | ||
| 63 | + if(null != jsonObjectData && jsonObjectData.size() != 0) | ||
| 64 | + { | ||
| 65 | + parserDeviceHostDto = analysisJsonData(product_id,topic,jsonObjectData).pushDeviceSensorData(deviceSensorDataList).toParserDeviceHostDto(topic.getClientid()); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + if(null != summary && summary.size() != 0) | ||
| 69 | + { | ||
| 70 | + if(null == parserDeviceHostDto) | ||
| 71 | + { | ||
| 72 | + parserDeviceHostDto = new ParserDeviceHostDto(); | ||
| 73 | + parserDeviceHostDto.setId(topic.getClientid()); | ||
| 74 | + } | ||
| 75 | + parserDeviceHostDto.setSummary(summary); | ||
| 76 | + } | ||
| 77 | + return parserDeviceHostDto; | ||
| 78 | + } | ||
| 79 | + return null; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + private List<ParserDeviceInfoDto> analysisDeviceInfo(Integer product_id,Topic topic, JsonObject data,List<DeviceSensorData> deviceSensorDataList) | ||
| 83 | + { | ||
| 84 | + List<ParserDeviceInfoDto> list = new ArrayList<>(); | ||
| 85 | + | ||
| 86 | + for (String key:data.keySet()) | ||
| 87 | + { | ||
| 88 | + if(!key.equals("0") && data.get(key).isJsonObject()) | ||
| 89 | + { | ||
| 90 | + ParserDeviceInfoDto parserDeviceInfoDto = analysisJsonData(product_id,topic,data.get(key).getAsJsonObject()).pushDeviceSensorData(deviceSensorDataList).toParserDeviceInfoDto(topic.getClientid()+"_"+key); | ||
| 91 | + list.add(parserDeviceInfoDto); | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + return list; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + private AnalysisDto analysisJsonData(Integer product_id,Topic topic, JsonObject jsonObjectData ) | ||
| 99 | + { | ||
| 100 | + if(null != jsonObjectData && jsonObjectData.size() !=0) | ||
| 101 | + { | ||
| 102 | + AnalysisDto analysisDto = new AnalysisDto(); | ||
| 103 | + | ||
| 104 | + JsonObject things_model_value = new JsonObject(); //存放数据 | ||
| 105 | + analysisDto.setThings_model_value(things_model_value); | ||
| 106 | + | ||
| 107 | + JsonObject things_model_config = new JsonObject(); //存放配置 | ||
| 108 | + analysisDto.setThings_model_config(things_model_config); | ||
| 109 | + for (String key: jsonObjectData.keySet()) | ||
| 110 | + { | ||
| 111 | + IotThingsModel thingsModel = iotThingsModelService.getIotThingsModel(product_id, key); | ||
| 112 | + | ||
| 113 | + JsonElement jsonElement = jsonObjectData.get(key); | ||
| 114 | + if(null != jsonElement && !jsonElement.isJsonNull() ) | ||
| 115 | + { | ||
| 116 | + ThingsModelItemBase thingsModelItemBase = getThingsModelItemBase(thingsModel,jsonElement); | ||
| 117 | + if(!thingsModelItemBase.checkValue()) | ||
| 118 | + { | ||
| 119 | + continue; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + switch (thingsModel.getIs_config()) | ||
| 123 | + { | ||
| 124 | + case 0: | ||
| 125 | + things_model_value.add(key,GsonConstructor.get().fromJson(JSONObject.toJSONString(thingsModelItemBase),JsonObject.class)); | ||
| 126 | + break; | ||
| 127 | + case 1: | ||
| 128 | + things_model_config.add(key,GsonConstructor.get().fromJson(JSONObject.toJSONString(thingsModelItemBase),JsonObject.class)); | ||
| 129 | + break; | ||
| 130 | + case 2: | ||
| 131 | + things_model_config.add(key,GsonConstructor.get().fromJson(JSONObject.toJSONString(thingsModelItemBase),JsonObject.class)); | ||
| 132 | + things_model_value.add(key,GsonConstructor.get().fromJson(JSONObject.toJSONString(thingsModelItemBase),JsonObject.class)); | ||
| 133 | + break; | ||
| 134 | + default: | ||
| 135 | + things_model_value.add(key,GsonConstructor.get().fromJson(JSONObject.toJSONString(thingsModelItemBase),JsonObject.class)); | ||
| 136 | + break; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + //记录数据日志 | ||
| 140 | + if(1==thingsModelItemBase.getIs_save_log() ) | ||
| 141 | + { | ||
| 142 | + List<DeviceSensorData> deviceSensorDataList = analysisDto.getDeviceSensorDataList(); | ||
| 143 | + if(null == deviceSensorDataList) | ||
| 144 | + { | ||
| 145 | + deviceSensorDataList = new ArrayList<>(); | ||
| 146 | + analysisDto.setDeviceSensorDataList(deviceSensorDataList); | ||
| 147 | + } | ||
| 148 | + deviceSensorDataList.add(getDeviceSensorData(topic,thingsModel,thingsModelItemBase)); | ||
| 149 | + } | ||
| 150 | + } | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + return analysisDto; | ||
| 154 | + } | ||
| 155 | + return null; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + | ||
| 159 | + | ||
| 160 | + | ||
| 161 | + private ThingsModelItemBase getThingsModelItemBase(IotThingsModel thingsModel,JsonElement jsonElement) | ||
| 162 | + { | ||
| 163 | + String data_type = thingsModel.getData_type().toUpperCase(); | ||
| 164 | + if(!EnumUtils.isValidEnum(ThingsModelDataTypeEnum.class,data_type)) | ||
| 165 | + { | ||
| 166 | + data_type = ThingsModelDataTypeEnum.STRING.name(); | ||
| 167 | + } | ||
| 168 | + return ThingsModelItemBase.newhingsModelItem(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel, jsonElement); | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + private DeviceSensorData getDeviceSensorData(Topic topic,IotThingsModel thingsModel,ThingsModelItemBase thingsModelItemBase) | ||
| 172 | + { | ||
| 173 | + DeviceSensorData sensorData = new DeviceSensorData(); | ||
| 174 | + sensorData.setDataType(thingsModel.getIdentifier()); | ||
| 175 | + sensorData.setDataValue(thingsModelItemBase.getSaveView()); | ||
| 176 | + sensorData.setCreatTime(com.zhonglai.luhui.device.analysis.comm.util.DateUtils.getNowTimeMilly()); | ||
| 177 | + sensorData.setDeviceModel(topic.getUsername()); | ||
| 178 | + sensorData.setDeviceInfoId(topic.getClientid()); | ||
| 179 | + return sensorData; | ||
| 180 | + | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.purification; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 协议清洗工厂 | ||
| 9 | + */ | ||
| 10 | +public interface ProtocolPurificationFactory { | ||
| 11 | + ProtocolPurificationModel purification(Integer product_id,Topic topic, JsonObject analysisObject ); | ||
| 12 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.service; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.protocol.factory.ProtocolParserAndPurificationFactory; | ||
| 4 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 6 | +import org.slf4j.Logger; | ||
| 7 | +import org.slf4j.LoggerFactory; | ||
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 数据业务层 | ||
| 12 | + * @param <T> | ||
| 13 | + */ | ||
| 14 | +public abstract class BaseCallback<T> { | ||
| 15 | + /** | ||
| 16 | + * 系统日志 | ||
| 17 | + */ | ||
| 18 | + protected final Logger log = LoggerFactory.getLogger(this.getClass()); | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 数据处理工厂 | ||
| 22 | + */ | ||
| 23 | + @Autowired | ||
| 24 | + protected ProtocolParserAndPurificationFactory<T> protocolParserAndPurificationFactory; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 内存处理服务 | ||
| 28 | + */ | ||
| 29 | + @Autowired | ||
| 30 | + protected DeviceCashUpService deviceCashUpService; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 公共持久化服务 | ||
| 34 | + */ | ||
| 35 | + @Autowired | ||
| 36 | + protected PersistenceDBService persistenceDBService; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 数据处理的工作流 | ||
| 40 | + */ | ||
| 41 | + protected void messageArrived(String imei,String s,T payload) throws ClassNotFoundException { | ||
| 42 | + //判断网关是否存在 | ||
| 43 | + ParserDeviceHostDto oldparserDeviceHostDto = persistenceDBService.getOldParserDeviceHostDto(imei); | ||
| 44 | + if(null == oldparserDeviceHostDto) | ||
| 45 | + { | ||
| 46 | + log.info("设备{}不存在",imei); | ||
| 47 | + return; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + //解析和清洗body | ||
| 51 | + ProtocolPurificationModel protocolPurificationModel = protocolParserAndPurificationFactory.analysisAndPurification( oldparserDeviceHostDto.getProduct_id(),s,payload,oldparserDeviceHostDto.getAnalysis_clas(),oldparserDeviceHostDto.getPurification_clas()); | ||
| 52 | + | ||
| 53 | + //缓存更新 | ||
| 54 | + int i = deviceCashUpService.upProtocolPurificationModel(protocolPurificationModel,oldparserDeviceHostDto); | ||
| 55 | + | ||
| 56 | + //持久化 | ||
| 57 | + persistenceDBService.upDB(protocolPurificationModel); | ||
| 58 | + | ||
| 59 | + //同步 | ||
| 60 | + persistenceDBService.syncDB(protocolPurificationModel); | ||
| 61 | + | ||
| 62 | + } | ||
| 63 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.service; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 6 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | ||
| 7 | +import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | +import org.springframework.stereotype.Service; | ||
| 10 | + | ||
| 11 | +import java.util.ArrayList; | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * 缓存更新 | ||
| 16 | + */ | ||
| 17 | +@Service | ||
| 18 | +public class DeviceCashUpService { | ||
| 19 | + @Autowired | ||
| 20 | + private PersistenceDBService persistenceDBService; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 更新清洗数据 | ||
| 24 | + * @param protocolPurificationModel | ||
| 25 | + * @return | ||
| 26 | + */ | ||
| 27 | + public int upProtocolPurificationModel(ProtocolPurificationModel protocolPurificationModel,ParserDeviceHostDto oldparserDeviceHostDto ) | ||
| 28 | + { | ||
| 29 | + //更新主机信息 | ||
| 30 | + int i = upParserDeviceHostDto(protocolPurificationModel,oldparserDeviceHostDto); | ||
| 31 | + | ||
| 32 | + //更新终端信息 | ||
| 33 | + i += upParserDeviceInfoDtoList(protocolPurificationModel,oldparserDeviceHostDto); | ||
| 34 | + | ||
| 35 | + return i; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 更新主机信息 | ||
| 40 | + * @param protocolPurificationModel | ||
| 41 | + * @return | ||
| 42 | + */ | ||
| 43 | + private int upParserDeviceHostDto( ProtocolPurificationModel protocolPurificationModel , ParserDeviceHostDto oldparserDeviceHostDto) | ||
| 44 | + { | ||
| 45 | + ParserDeviceHostDto parserDeviceHostDto = protocolPurificationModel.getParserDeviceHostDto(); | ||
| 46 | + int i=0; | ||
| 47 | + JsonObject oldData = oldparserDeviceHostDto.getData(); | ||
| 48 | + JsonObject newData = parserDeviceHostDto.getData(); | ||
| 49 | + if(null != newData) | ||
| 50 | + { | ||
| 51 | + if(null == oldData) | ||
| 52 | + { | ||
| 53 | + oldparserDeviceHostDto.setData(newData); | ||
| 54 | + i++; | ||
| 55 | + oldparserDeviceHostDto.set_data_up(true); | ||
| 56 | + }else { | ||
| 57 | + if(newToOldJsonObject(oldData,newData)) | ||
| 58 | + { | ||
| 59 | + i++; | ||
| 60 | + oldparserDeviceHostDto.set_data_up(true); | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + JsonObject oldConfig = oldparserDeviceHostDto.getConfig(); | ||
| 66 | + JsonObject newConfig = parserDeviceHostDto.getConfig(); | ||
| 67 | + if(null != newConfig) | ||
| 68 | + { | ||
| 69 | + if(null == oldConfig) | ||
| 70 | + { | ||
| 71 | + oldparserDeviceHostDto.setConfig(newConfig); | ||
| 72 | + i++; | ||
| 73 | + oldparserDeviceHostDto.set_config_up(true); | ||
| 74 | + }else { | ||
| 75 | + if(newToOldJsonObject(oldConfig,newConfig)) | ||
| 76 | + { | ||
| 77 | + i++; | ||
| 78 | + oldparserDeviceHostDto.set_config_up(true); | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + JsonObject oldSummary = oldparserDeviceHostDto.getSummary(); | ||
| 84 | + JsonObject newSummary = parserDeviceHostDto.getSummary(); | ||
| 85 | + if(null != newSummary) | ||
| 86 | + { | ||
| 87 | + if(null == oldSummary) | ||
| 88 | + { | ||
| 89 | + oldparserDeviceHostDto.setSummary(newSummary); | ||
| 90 | + i++; | ||
| 91 | + oldparserDeviceHostDto.set_summary_up(true); | ||
| 92 | + }else { | ||
| 93 | + if(newToOldJsonObject(oldSummary,newSummary)) | ||
| 94 | + { | ||
| 95 | + i++; | ||
| 96 | + oldparserDeviceHostDto.set_summary_up(true); | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + protocolPurificationModel.setParserDeviceHostDto(oldparserDeviceHostDto); | ||
| 102 | + | ||
| 103 | + //更新主机缓存 | ||
| 104 | + DeviceCach.putDeviceHost(oldparserDeviceHostDto,oldparserDeviceHostDto.getDevice_life()); | ||
| 105 | + return i; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + /** | ||
| 109 | + * 批量更新终端 | ||
| 110 | + * @param protocolPurificationModel | ||
| 111 | + * @param oldparserDeviceHostDto | ||
| 112 | + * @return | ||
| 113 | + */ | ||
| 114 | + private int upParserDeviceInfoDtoList(ProtocolPurificationModel protocolPurificationModel, ParserDeviceHostDto oldparserDeviceHostDto) | ||
| 115 | + { | ||
| 116 | + List<ParserDeviceInfoDto> parserDeviceInfoDtoList = protocolPurificationModel.getParserDeviceInfoDtoList(); | ||
| 117 | + int i=0; | ||
| 118 | + if(null != parserDeviceInfoDtoList && parserDeviceInfoDtoList.size()!=0) | ||
| 119 | + { | ||
| 120 | + List<ParserDeviceInfoDto> oldParserDeviceInfoDtoList = new ArrayList<>(); | ||
| 121 | + for (ParserDeviceInfoDto parserDeviceInfoDto:parserDeviceInfoDtoList) | ||
| 122 | + { | ||
| 123 | + ParserDeviceInfoDto oldparserDeviceInfoDto = persistenceDBService.getOldParserDeviceInfoDto(parserDeviceInfoDto.getId(),parserDeviceInfoDto.getDeviceInfoName(),oldparserDeviceHostDto); | ||
| 124 | + if(null == oldparserDeviceInfoDto) | ||
| 125 | + { | ||
| 126 | + continue; | ||
| 127 | + } | ||
| 128 | + oldparserDeviceInfoDto.setUpdateTime(parserDeviceInfoDto.getUpdateTime()); | ||
| 129 | + i+=upParserDeviceInfoDto(parserDeviceInfoDto,oldparserDeviceInfoDto); | ||
| 130 | + | ||
| 131 | + oldParserDeviceInfoDtoList.add(oldparserDeviceInfoDto); | ||
| 132 | + //更新缓存 | ||
| 133 | + DeviceCach.putDeviceInfo(oldparserDeviceInfoDto,oldparserDeviceHostDto.getDevice_life()); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + protocolPurificationModel.setParserDeviceInfoDtoList(oldParserDeviceInfoDtoList); | ||
| 137 | + } | ||
| 138 | + return i; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * 更新终端 | ||
| 144 | + * @param parserDeviceInfoDto | ||
| 145 | + * @return | ||
| 146 | + */ | ||
| 147 | + private int upParserDeviceInfoDto( ParserDeviceInfoDto parserDeviceInfoDto , ParserDeviceInfoDto oldparserDeviceInfoDto) | ||
| 148 | + { | ||
| 149 | + int i=0; | ||
| 150 | + JsonObject oldData = oldparserDeviceInfoDto.getData(); | ||
| 151 | + JsonObject newData = parserDeviceInfoDto.getData(); | ||
| 152 | + if(null != newData) | ||
| 153 | + { | ||
| 154 | + if(null == oldData) | ||
| 155 | + { | ||
| 156 | + oldparserDeviceInfoDto.setData(newData); | ||
| 157 | + i++; | ||
| 158 | + oldparserDeviceInfoDto.set_data_up(true); | ||
| 159 | + }else { | ||
| 160 | + if(newToOldJsonObject(oldData,newData)) | ||
| 161 | + { | ||
| 162 | + i++; | ||
| 163 | + oldparserDeviceInfoDto.set_data_up(true); | ||
| 164 | + } | ||
| 165 | + } | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + JsonObject oldConfig = oldparserDeviceInfoDto.getConfig(); | ||
| 169 | + JsonObject newConfig = parserDeviceInfoDto.getConfig(); | ||
| 170 | + if(null != newConfig) | ||
| 171 | + { | ||
| 172 | + if(null == oldConfig) | ||
| 173 | + { | ||
| 174 | + oldparserDeviceInfoDto.setConfig(newConfig); | ||
| 175 | + i++; | ||
| 176 | + oldparserDeviceInfoDto.set_conf_up(true); | ||
| 177 | + }else { | ||
| 178 | + if(newToOldJsonObject(oldConfig,newConfig)) | ||
| 179 | + { | ||
| 180 | + i++; | ||
| 181 | + oldparserDeviceInfoDto.set_conf_up(true); | ||
| 182 | + } | ||
| 183 | + } | ||
| 184 | + } | ||
| 185 | + return i; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + | ||
| 189 | + public void upOnline(String state) | ||
| 190 | + { | ||
| 191 | + switch (state) | ||
| 192 | + { | ||
| 193 | + case "1": | ||
| 194 | + return; | ||
| 195 | + case "2": | ||
| 196 | + return; | ||
| 197 | + case "3": | ||
| 198 | + return; | ||
| 199 | + default: | ||
| 200 | + return; | ||
| 201 | + } | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + | ||
| 205 | + private boolean newToOldJsonObject(JsonObject oldJson,JsonObject newJson) | ||
| 206 | + { | ||
| 207 | + boolean ischange = false; | ||
| 208 | + for(String key:newJson.keySet()) | ||
| 209 | + { | ||
| 210 | + if(!newJson.get(key).equals(oldJson.get(key))) | ||
| 211 | + { | ||
| 212 | + oldJson.add(key,newJson.get(key)); | ||
| 213 | + ischange = true; | ||
| 214 | + } | ||
| 215 | + } | ||
| 216 | + return ischange; | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.service; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | ||
| 5 | +import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | +import org.springframework.stereotype.Service; | ||
| 8 | + | ||
| 9 | +import java.util.HashMap; | ||
| 10 | +import java.util.Map; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 物模型业务 | ||
| 14 | + */ | ||
| 15 | +@Service | ||
| 16 | +public class IotThingsModelService { | ||
| 17 | + | ||
| 18 | + private static Map<Integer, Map<String, IotThingsModel>> iotThingsModelMap = new HashMap<>(); | ||
| 19 | + | ||
| 20 | + @Autowired | ||
| 21 | + private PersistenceDBService persistenceDBService; | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + public IotThingsModel getIotThingsModel(Integer product_id,String identifier) | ||
| 25 | + { | ||
| 26 | + Map<String, IotThingsModel> iotThingsModelMap = getIotThingsModelMap( product_id); | ||
| 27 | + if(null == iotThingsModelMap || null == iotThingsModelMap.get(identifier)) //没有配置的 都按字符串处理 | ||
| 28 | + { | ||
| 29 | + IotThingsModel thingsModel = new IotThingsModel(); | ||
| 30 | + thingsModel.setData_type(ThingsModelDataTypeEnum.STRING.name()); | ||
| 31 | + thingsModel.setIdentifier(identifier); | ||
| 32 | + thingsModel.setModel_name(identifier); | ||
| 33 | + thingsModel.setIs_top(0); | ||
| 34 | + thingsModel.setIs_monitor(0); | ||
| 35 | + thingsModel.setIs_save_log(0); | ||
| 36 | + thingsModel.setIs_config(0); | ||
| 37 | + JsonObject jsonObject = new JsonObject(); | ||
| 38 | + jsonObject.addProperty("maxLength",255); | ||
| 39 | + thingsModel.setSpecs(jsonObject.toString()); | ||
| 40 | + return thingsModel; | ||
| 41 | + } | ||
| 42 | + return iotThingsModelMap.get(identifier); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + | ||
| 46 | + private Map<String, IotThingsModel> getIotThingsModelMap(Integer product_id) | ||
| 47 | + { | ||
| 48 | + if(!iotThingsModelMap.containsKey(product_id)) | ||
| 49 | + { | ||
| 50 | + Map<String,IotThingsModel> map = persistenceDBService.getIotThingsModelMap(product_id); | ||
| 51 | + if(null == map || map.size() == 0) | ||
| 52 | + { | ||
| 53 | + return null; | ||
| 54 | + } | ||
| 55 | + iotThingsModelMap.put(product_id,map); | ||
| 56 | + } | ||
| 57 | + return iotThingsModelMap.get(product_id); | ||
| 58 | + } | ||
| 59 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.service; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.ruoyi.common.utils.StringUtils; | ||
| 6 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | ||
| 8 | +import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | ||
| 9 | +import com.zhonglai.luhui.device.domain.IotDevice; | ||
| 10 | +import com.zhonglai.luhui.device.domain.IotProduct; | ||
| 11 | +import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 12 | +import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach; | ||
| 13 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 14 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | ||
| 15 | +import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 16 | +import com.zhonglai.luhui.device.protocol.factory.service.impl.DefaultDbService; | ||
| 17 | +import com.zhonglai.luhui.device.protocol.factory.sync.ProtocolSyncFactory; | ||
| 18 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 19 | +import org.springframework.stereotype.Service; | ||
| 20 | + | ||
| 21 | +import java.util.HashMap; | ||
| 22 | +import java.util.List; | ||
| 23 | +import java.util.Map; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * 和数据库有个的操作都在这里 | ||
| 27 | + */ | ||
| 28 | +@Service | ||
| 29 | +public class PersistenceDBService { | ||
| 30 | + | ||
| 31 | + @Autowired | ||
| 32 | + private DefaultDbService defaultDbService; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 更新数据库 | ||
| 36 | + * @param protocolPurificationModel | ||
| 37 | + */ | ||
| 38 | + public void upDB(ProtocolPurificationModel protocolPurificationModel) | ||
| 39 | + { | ||
| 40 | + //主机 | ||
| 41 | + ParserDeviceHostDto parserDeviceHostDto = protocolPurificationModel.getParserDeviceHostDto(); | ||
| 42 | + defaultDbService.updateParserDeviceHostDto(parserDeviceHostDto); | ||
| 43 | + | ||
| 44 | + //终端 | ||
| 45 | + List<ParserDeviceInfoDto> parserDeviceInfoDtoList = protocolPurificationModel.getParserDeviceInfoDtoList(); | ||
| 46 | + defaultDbService.updateParserDeviceInfoDtoList(parserDeviceInfoDtoList); | ||
| 47 | + | ||
| 48 | + //传感器指标 | ||
| 49 | + List<DeviceSensorData> deviceSensorDataList = protocolPurificationModel.getDeviceSensorDataList(); | ||
| 50 | + defaultDbService.updateDeviceSensorDataList(deviceSensorDataList); | ||
| 51 | + | ||
| 52 | + //数据操作 | ||
| 53 | + List<LogDeviceOperation> logDeviceOperationList = protocolPurificationModel.getLogDeviceOperationList(); | ||
| 54 | + defaultDbService.updateLogDeviceOperationList(logDeviceOperationList); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 同步数据库 | ||
| 59 | + */ | ||
| 60 | + public void syncDB(ProtocolPurificationModel protocolPurificationModel) throws ClassNotFoundException { | ||
| 61 | + //主机 | ||
| 62 | + ParserDeviceHostDto parserDeviceHostDto = protocolPurificationModel.getParserDeviceHostDto(); | ||
| 63 | + if (parserDeviceHostDto.is_sync_db() && StringUtils.isNotEmpty(parserDeviceHostDto.getSync_db())) | ||
| 64 | + { | ||
| 65 | + ProtocolSyncFactory protocolSyncFactory = getProtocolSyncService(parserDeviceHostDto.getSync_db()); | ||
| 66 | + if(null != protocolSyncFactory) | ||
| 67 | + { | ||
| 68 | + protocolSyncFactory.updateParserDeviceHostDto(parserDeviceHostDto); | ||
| 69 | + | ||
| 70 | + //终端 | ||
| 71 | + List<ParserDeviceInfoDto> parserDeviceInfoDtoList = protocolPurificationModel.getParserDeviceInfoDtoList(); | ||
| 72 | + protocolSyncFactory.updateParserDeviceInfoDtoList(parserDeviceInfoDtoList); | ||
| 73 | + | ||
| 74 | + //传感器指标 | ||
| 75 | + List<DeviceSensorData> deviceSensorDataList = protocolPurificationModel.getDeviceSensorDataList(); | ||
| 76 | + protocolSyncFactory.updateDeviceSensorDataList(deviceSensorDataList); | ||
| 77 | + | ||
| 78 | + //数据操作 | ||
| 79 | + List<LogDeviceOperation> logDeviceOperationList = protocolPurificationModel.getLogDeviceOperationList(); | ||
| 80 | + protocolSyncFactory.updateLogDeviceOperationList(logDeviceOperationList); | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * 获取老的终端数据 | ||
| 90 | + * @param id | ||
| 91 | + * @param name | ||
| 92 | + * @param oldparserDeviceHostDto | ||
| 93 | + * @return | ||
| 94 | + */ | ||
| 95 | + public ParserDeviceInfoDto getOldParserDeviceInfoDto(String id,String name,ParserDeviceHostDto oldparserDeviceHostDto) | ||
| 96 | + { | ||
| 97 | + ParserDeviceInfoDto oldparserDeviceInfoDto = DeviceCach.getDeviceInfo(id); | ||
| 98 | + if(null == oldparserDeviceInfoDto ) | ||
| 99 | + { | ||
| 100 | + oldparserDeviceInfoDto = defaultDbService.getParserDeviceInfoDtoFromDb(id,name,oldparserDeviceHostDto); | ||
| 101 | + if(null == oldparserDeviceInfoDto) | ||
| 102 | + { | ||
| 103 | + return null; | ||
| 104 | + } | ||
| 105 | + DeviceCach.putDeviceInfo(oldparserDeviceInfoDto,oldparserDeviceHostDto.getDevice_life()); | ||
| 106 | + } | ||
| 107 | + return oldparserDeviceInfoDto; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * 获取网关 | ||
| 112 | + * @param id | ||
| 113 | + * @return | ||
| 114 | + */ | ||
| 115 | + public IotDevice getDeviceHostById(String id) | ||
| 116 | + { | ||
| 117 | + return defaultDbService.getDeviceById(id); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * 获取产品 | ||
| 122 | + * @param id | ||
| 123 | + * @return | ||
| 124 | + */ | ||
| 125 | + public IotProduct getIotProductById(Integer id) | ||
| 126 | + { | ||
| 127 | + return defaultDbService.getIotProductById(id); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + public Map<String,IotThingsModel> getIotThingsModelMap(Integer product_id) | ||
| 131 | + { | ||
| 132 | + List<IotThingsModel> list = defaultDbService.getIotThingsModelList(product_id); | ||
| 133 | + if(null != list && list.size() != 0 ) | ||
| 134 | + { | ||
| 135 | + Map<String,IotThingsModel> map = new HashMap<>(); | ||
| 136 | + for (IotThingsModel iotThingsModel:list) | ||
| 137 | + { | ||
| 138 | + map.put(iotThingsModel.getIdentifier(),iotThingsModel); | ||
| 139 | + } | ||
| 140 | + return map; | ||
| 141 | + } | ||
| 142 | + return null; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * 获取默认数据库的操作服务 | ||
| 147 | + * @return | ||
| 148 | + */ | ||
| 149 | + public DefaultDbService getDefaultDbService() | ||
| 150 | + { | ||
| 151 | + return SpringUtils.getBean(DefaultDbService.class); | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + /** | ||
| 155 | + * 获取指定数据库的操作服务 | ||
| 156 | + * @return | ||
| 157 | + */ | ||
| 158 | + public ProtocolSyncFactory getProtocolSyncService(String clasname) throws ClassNotFoundException { | ||
| 159 | + if(StringUtils.isEmpty(clasname)) | ||
| 160 | + { | ||
| 161 | + return null; | ||
| 162 | + } | ||
| 163 | + return (ProtocolSyncFactory) SpringUtils.getBean(Class.forName(clasname)); | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + /** | ||
| 167 | + * 获取主机信息 | ||
| 168 | + * @param imei | ||
| 169 | + * @return | ||
| 170 | + */ | ||
| 171 | + | ||
| 172 | + public ParserDeviceHostDto getOldParserDeviceHostDto(String imei) | ||
| 173 | + { | ||
| 174 | + ParserDeviceHostDto oldParserDeviceHostDto = DeviceCach.getDeviceHost(imei); | ||
| 175 | + if(null == oldParserDeviceHostDto) | ||
| 176 | + { | ||
| 177 | + IotDevice iotDevice = getDeviceHostById(imei); | ||
| 178 | + if(null == iotDevice) | ||
| 179 | + { | ||
| 180 | + return null; | ||
| 181 | + } | ||
| 182 | + if(iotDevice.getStatus()==2 || iotDevice.getStatus()==5) | ||
| 183 | + { | ||
| 184 | + return null; | ||
| 185 | + } | ||
| 186 | + oldParserDeviceHostDto = new ParserDeviceHostDto(); | ||
| 187 | + oldParserDeviceHostDto.setId(iotDevice.getClient_id()); | ||
| 188 | + if(StringUtils.isNotEmpty(iotDevice.getSummary())) | ||
| 189 | + { | ||
| 190 | + oldParserDeviceHostDto.setData(GsonConstructor.get().fromJson(iotDevice.getSummary(), JsonObject.class)); | ||
| 191 | + } | ||
| 192 | + if(null == iotDevice.getDevice_life()) | ||
| 193 | + { | ||
| 194 | + iotDevice.setDevice_life(60l); | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + IotProduct iotProduct = getIotProductById(iotDevice.getProduct_id()); | ||
| 198 | + | ||
| 199 | + oldParserDeviceHostDto.setDevice_life(iotDevice.getDevice_life()); | ||
| 200 | + oldParserDeviceHostDto.setDevice_type(iotDevice.getMqtt_username()); | ||
| 201 | + oldParserDeviceHostDto.set_sync_db(iotProduct.getIs_sync_db()==1); | ||
| 202 | + oldParserDeviceHostDto.setSync_db(iotProduct.getSync_db()); | ||
| 203 | + oldParserDeviceHostDto.setProduct_id(iotDevice.getProduct_id()); | ||
| 204 | + | ||
| 205 | + oldParserDeviceHostDto.setAnalysis_clas(iotProduct.getAnalysis_clas()); | ||
| 206 | + oldParserDeviceHostDto.setPurification_clas(iotProduct.getPurification_clas()); | ||
| 207 | + //设置同步设备 | ||
| 208 | +// if("1".equals(iotProduct.getIs_sync_db()) && StringUtils.isNotEmpty(iotProduct.getSync_db())) | ||
| 209 | +// { | ||
| 210 | +// ParserDeviceHostDto parserDeviceHostDto = getSyncDeviceById(iotDevice.getClient_id(),iotProduct.getSync_db()); | ||
| 211 | +// if(null != parserDeviceHostDto) | ||
| 212 | +// { | ||
| 213 | +// if(StringUtils.isNull(parserDeviceHostDto.getDevice_life())) | ||
| 214 | +// { | ||
| 215 | +// parserDeviceHostDto.setDevice_life(iotDevice.getDevice_life()); | ||
| 216 | +// } | ||
| 217 | +// parserDeviceHostDto.setId(iotProduct.getSync_db()+"|"+parserDeviceHostDto.getId()); | ||
| 218 | +// DeviceCach.putDeviceHost(parserDeviceHostDto,parserDeviceHostDto.getDevice_life()); | ||
| 219 | +// } | ||
| 220 | +// } | ||
| 221 | + } | ||
| 222 | + return oldParserDeviceHostDto; | ||
| 223 | + } | ||
| 224 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.service.impl; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.ruoyi.common.utils.StringUtils; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | ||
| 8 | +import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | ||
| 9 | +import com.zhonglai.luhui.device.analysis.comm.dto.TableGenerateSqlEnum; | ||
| 10 | +import com.zhonglai.luhui.device.domain.IotDevice; | ||
| 11 | +import com.zhonglai.luhui.device.domain.IotProduct; | ||
| 12 | +import com.zhonglai.luhui.device.domain.IotTerminal; | ||
| 13 | +import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 14 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 15 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | ||
| 16 | +import org.springframework.stereotype.Service; | ||
| 17 | + | ||
| 18 | +import java.util.ArrayList; | ||
| 19 | +import java.util.List; | ||
| 20 | +import java.util.Map; | ||
| 21 | + | ||
| 22 | +@Service | ||
| 23 | +public class DefaultDbService { | ||
| 24 | + private BaseDao baseDao = new BaseDao(); | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + public List<String> getTopicFromRole() | ||
| 28 | + { | ||
| 29 | + List<String> rlist= new ArrayList<>(); | ||
| 30 | + List<Map> list = baseDao.findListBysql("SELECT id FROM `iot_role` WHERE id NOT IN(1,2,3,8,9,10)"); | ||
| 31 | + if(null != list && list.size() !=0) | ||
| 32 | + { | ||
| 33 | + for(Map map:list) | ||
| 34 | + { | ||
| 35 | + rlist.add("/"+map.get("id")+"/#"); | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + return rlist; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public IotDevice getDeviceById(String id) | ||
| 42 | + { | ||
| 43 | + return (IotDevice) baseDao.get(IotDevice.class,"client_id='"+id+"'","`mqtt_broker`.`iot_device`"); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + public IotProduct getIotProductById(Integer id) | ||
| 47 | + { | ||
| 48 | + return (IotProduct) baseDao.get(IotProduct.class,"id='"+id+"'","`mqtt_broker`.`iot_product`"); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public IotTerminal getDeviceInfoById(String id) | ||
| 52 | + { | ||
| 53 | + return (IotTerminal) baseDao.get(IotTerminal.class,"id='"+id+"'","`mqtt_broker`.`iot_terminal`"); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public List<IotThingsModel> getIotThingsModelList(Integer product_id) | ||
| 57 | + { | ||
| 58 | + IotThingsModel iotThingsModel = new IotThingsModel(); | ||
| 59 | + iotThingsModel.setProduct_id(product_id); | ||
| 60 | + return baseDao.find(iotThingsModel); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public void insertIotTerminal(IotTerminal iotTerminal) | ||
| 64 | + { | ||
| 65 | + baseDao.insert(iotTerminal); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + | ||
| 69 | + public ParserDeviceHostDto getParserDeviceHostDtoFromDb(String id) { | ||
| 70 | + IotDevice iotDevice = getDeviceById(id); | ||
| 71 | + ParserDeviceHostDto parserDeviceHostDto = new ParserDeviceHostDto(); | ||
| 72 | + parserDeviceHostDto.setId(id); | ||
| 73 | + if(StringUtils.isNotEmpty(iotDevice.getSummary())) | ||
| 74 | + { | ||
| 75 | + parserDeviceHostDto.setData(GsonConstructor.get().fromJson(iotDevice.getSummary(),JsonObject.class)); | ||
| 76 | + } | ||
| 77 | + parserDeviceHostDto.setUpdateTime(iotDevice.getData_update_time()); | ||
| 78 | + parserDeviceHostDto.setDevice_life(iotDevice.getDevice_life()); | ||
| 79 | + parserDeviceHostDto.setDevice_type(iotDevice.getMqtt_username()); | ||
| 80 | + | ||
| 81 | + IotProduct iotProduct = getIotProductById(iotDevice.getProduct_id()); | ||
| 82 | + | ||
| 83 | + parserDeviceHostDto.setSync_db(iotProduct.getSync_db()); | ||
| 84 | + parserDeviceHostDto.setProduct_id(iotDevice.getProduct_id()); | ||
| 85 | + return parserDeviceHostDto; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + public ParserDeviceInfoDto getParserDeviceInfoDtoFromDb(String id,String name, ParserDeviceHostDto oldparserDeviceHostDto) { | ||
| 89 | + IotTerminal iotTerminal = (IotTerminal) baseDao.get(IotTerminal.class,id); | ||
| 90 | + if(null == iotTerminal) | ||
| 91 | + { | ||
| 92 | + iotTerminal = new IotTerminal(); | ||
| 93 | + iotTerminal.setId(id); | ||
| 94 | + iotTerminal.setDevice_id(oldparserDeviceHostDto.getId()); | ||
| 95 | + iotTerminal.setMqtt_username(oldparserDeviceHostDto.getDevice_type()); | ||
| 96 | + iotTerminal.setCreate_time(oldparserDeviceHostDto.getUpdateTime()); | ||
| 97 | + iotTerminal.setProduct_id(oldparserDeviceHostDto.getProduct_id()); | ||
| 98 | + if(StringUtils.isNotEmpty(name)) | ||
| 99 | + { | ||
| 100 | + iotTerminal.setName(name); | ||
| 101 | + } | ||
| 102 | + baseDao.insert(iotTerminal); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + ParserDeviceInfoDto oldparserDeviceInfoDto = new ParserDeviceInfoDto(); | ||
| 106 | + oldparserDeviceInfoDto.setId(id); | ||
| 107 | + oldparserDeviceInfoDto.setDeviceInfoName(iotTerminal.getName()); | ||
| 108 | + if(StringUtils.isNotEmpty(iotTerminal.getThings_model_value())) | ||
| 109 | + { | ||
| 110 | + oldparserDeviceInfoDto.setData(GsonConstructor.get().fromJson(iotTerminal.getThings_model_value(),JsonObject.class)); | ||
| 111 | + } | ||
| 112 | + if(StringUtils.isNotEmpty(iotTerminal.getThings_model_config())) | ||
| 113 | + { | ||
| 114 | + oldparserDeviceInfoDto.setConfig(GsonConstructor.get().fromJson(iotTerminal.getThings_model_config(),JsonObject.class)); | ||
| 115 | + } | ||
| 116 | + return oldparserDeviceInfoDto; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + public int updateParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto) | ||
| 120 | + { | ||
| 121 | + IotDevice iotDevice = new IotDevice(); | ||
| 122 | + iotDevice.setClient_id(parserDeviceHostDto.getId()); | ||
| 123 | + iotDevice.setData_update_time(parserDeviceHostDto.getUpdateTime()); | ||
| 124 | + if(parserDeviceHostDto.is_summary_up()) | ||
| 125 | + { | ||
| 126 | + if(null != parserDeviceHostDto.getSummary() && parserDeviceHostDto.getSummary().size() != 0) | ||
| 127 | + { | ||
| 128 | + iotDevice.setSummary(parserDeviceHostDto.getSummary().toString()); | ||
| 129 | + } | ||
| 130 | + parserDeviceHostDto.set_summary_up(false); | ||
| 131 | + } | ||
| 132 | + if(parserDeviceHostDto.is_data_up()) | ||
| 133 | + { | ||
| 134 | + if(null != parserDeviceHostDto.getData() && parserDeviceHostDto.getData().size() != 0) | ||
| 135 | + { | ||
| 136 | + iotDevice.setThings_model_value(parserDeviceHostDto.getData().toString()); | ||
| 137 | + } | ||
| 138 | + parserDeviceHostDto.set_data_up(false); | ||
| 139 | + } | ||
| 140 | + if(parserDeviceHostDto.is_config_up()) | ||
| 141 | + { | ||
| 142 | + if(null != parserDeviceHostDto.getConfig() && parserDeviceHostDto.getConfig().size() != 0) | ||
| 143 | + { | ||
| 144 | + iotDevice.setThings_model_config(parserDeviceHostDto.getConfig().toString()); | ||
| 145 | + } | ||
| 146 | + parserDeviceHostDto.set_config_up(false); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + int i = baseDao.update(iotDevice); | ||
| 150 | + return i; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public int updateParserDeviceInfoDtoList(List<ParserDeviceInfoDto> parserDeviceInfoDtoList) { | ||
| 154 | + int i=0; | ||
| 155 | + if(null != parserDeviceInfoDtoList && parserDeviceInfoDtoList.size() != 0) | ||
| 156 | + { | ||
| 157 | + for (ParserDeviceInfoDto parserDeviceInfoDto:parserDeviceInfoDtoList) | ||
| 158 | + { | ||
| 159 | + IotTerminal iotTerminal = new IotTerminal(); | ||
| 160 | + iotTerminal.setId(parserDeviceInfoDto.getId()); | ||
| 161 | + iotTerminal.setData_update_time(parserDeviceInfoDto.getUpdateTime()); | ||
| 162 | + iotTerminal.setOnline(1); | ||
| 163 | + if(parserDeviceInfoDto.is_data_up()) | ||
| 164 | + { | ||
| 165 | + iotTerminal.setThings_model_value(parserDeviceInfoDto.getData().toString()); | ||
| 166 | + parserDeviceInfoDto.set_data_up(false); | ||
| 167 | + } | ||
| 168 | + if(parserDeviceInfoDto.is_conf_up()) | ||
| 169 | + { | ||
| 170 | + iotTerminal.setThings_model_config(parserDeviceInfoDto.getConfig().toString()); | ||
| 171 | + parserDeviceInfoDto.set_conf_up(false); | ||
| 172 | + } | ||
| 173 | + i+=baseDao.update(iotTerminal); | ||
| 174 | + | ||
| 175 | + } | ||
| 176 | + } | ||
| 177 | + return i; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + public int updateDeviceSensorDataList(List<DeviceSensorData> deviceSensorDataList) { | ||
| 181 | + if(null != deviceSensorDataList && deviceSensorDataList.size() != 0) | ||
| 182 | + { | ||
| 183 | + return baseDao.insertList(deviceSensorDataList, TableGenerateSqlEnum.DeviceSensorData.getNowTableName()); | ||
| 184 | + } | ||
| 185 | + return 0; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + public int updateLogDeviceOperationList(List<LogDeviceOperation> logDeviceOperationList) { | ||
| 189 | + if(null != logDeviceOperationList && logDeviceOperationList.size() != 0 ) | ||
| 190 | + { | ||
| 191 | + return baseDao.insertList(logDeviceOperationList, TableGenerateSqlEnum.LogDeviceOperation.getNowTableName()); | ||
| 192 | + } | ||
| 193 | + return 0; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.factory.sync; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 6 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | ||
| 7 | + | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 10 | +public interface ProtocolSyncFactory { | ||
| 11 | + //主机 | ||
| 12 | + void updateParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto); | ||
| 13 | + | ||
| 14 | + //终端 | ||
| 15 | + void updateParserDeviceInfoDtoList( List<ParserDeviceInfoDto> parserDeviceInfoDtoList); | ||
| 16 | + | ||
| 17 | + //传感器指标 | ||
| 18 | + void updateDeviceSensorDataList(List<DeviceSensorData> deviceSensorDataList); | ||
| 19 | + | ||
| 20 | + //数据操作 | ||
| 21 | + void updateLogDeviceOperationList(List<LogDeviceOperation> logDeviceOperationList); | ||
| 22 | +} |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-device-protocol-parser</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 13 | + <artifactId>lh-device-xinjie</artifactId> | ||
| 14 | + | ||
| 15 | + <properties> | ||
| 16 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 17 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 18 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 19 | + </properties> | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + <dependencies> | ||
| 23 | + <dependency> | ||
| 24 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 25 | + <artifactId>lh-device-protocol-factory</artifactId> | ||
| 26 | + </dependency> | ||
| 27 | + </dependencies> | ||
| 28 | +</project> |
| 1 | +package com.zhonglai.luhui.device.protocol.xinjie.analysis; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.DateUtils; | ||
| 5 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 6 | +import com.ruoyi.common.utils.StringUtils; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 8 | +import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; | ||
| 9 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; | ||
| 10 | +import com.zhonglai.luhui.device.protocol.factory.analysis.ProtocolParserFactory; | ||
| 11 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 12 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | ||
| 13 | +import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 14 | +import com.zhonglai.luhui.device.protocol.xinjie.dto.Variant; | ||
| 15 | +import com.zhonglai.luhui.device.protocol.xinjie.dto.XinJieDto; | ||
| 16 | +import org.springframework.stereotype.Service; | ||
| 17 | + | ||
| 18 | +import java.util.ArrayList; | ||
| 19 | +import java.util.List; | ||
| 20 | + | ||
| 21 | +@Service | ||
| 22 | +public class ProtocolParserServiceImpl implements ProtocolParserFactory<byte[]> { | ||
| 23 | + private static final String topicModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{imei}}/{{topicType}}"; | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public Topic analysisTopic(String topicStr) { | ||
| 27 | + // /13/jiulin/476210165B365166812345678Userdata/Json/476210165B365166812345678/pub_data | ||
| 28 | + Topic topic = TopicUtil.initTopicFromModelStr(topicStr,topicModel); | ||
| 29 | + return topic; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + public JsonObject analysisPayload(Topic topic, byte[] payload) { | ||
| 34 | + String data = new String(payload); | ||
| 35 | + XinJieDto xinJieDto = GsonConstructor.get().fromJson(data, XinJieDto.class); | ||
| 36 | + if(null != xinJieDto.getVariant() && xinJieDto.getVariant().size()!=0) | ||
| 37 | + { | ||
| 38 | + JsonObject rj = new JsonObject(); | ||
| 39 | + | ||
| 40 | + analysisHost(rj,xinJieDto); | ||
| 41 | + analysisDeviceInfo(rj,xinJieDto); | ||
| 42 | + | ||
| 43 | + return rj; | ||
| 44 | + } | ||
| 45 | + return GsonConstructor.get().fromJson(data, JsonObject.class); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + private void analysisHost(JsonObject rj,XinJieDto xinJieDto) | ||
| 49 | + { | ||
| 50 | + Variant variant = xinJieDto.getVariant().get(0); | ||
| 51 | + JsonObject data = new JsonObject(); | ||
| 52 | + | ||
| 53 | + JsonObject summary = new JsonObject(); | ||
| 54 | + summary.addProperty("Unix",variant.getUnix()); | ||
| 55 | + summary.addProperty("Version",variant.getVersion()); | ||
| 56 | + data.add("summary",summary); | ||
| 57 | + rj.add("0",data); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + private void analysisDeviceInfo(JsonObject rj,XinJieDto xinJieDto ) | ||
| 61 | + { | ||
| 62 | + Variant variant = xinJieDto.getVariant().get(0); | ||
| 63 | + | ||
| 64 | + int i =1; | ||
| 65 | + for (String key:variant.getPub_Data().keySet()) | ||
| 66 | + { | ||
| 67 | + rj.add(ByteUtil.changerTwoStr(i+""),variant.getPub_Data().get(key).getAsJsonObject()); | ||
| 68 | + i++; | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.xinjie.db; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.analysis.comm.dao.DBFactory; | ||
| 4 | +import org.apache.commons.dbcp.BasicDataSourceFactory; | ||
| 5 | + | ||
| 6 | +import javax.sql.DataSource; | ||
| 7 | +import java.io.FileInputStream; | ||
| 8 | +import java.util.Properties; | ||
| 9 | + | ||
| 10 | +public class LsyDBFactoryImp implements DBFactory { | ||
| 11 | + private static DataSource ds = null; | ||
| 12 | + static { | ||
| 13 | + try { | ||
| 14 | + if(null==ds ) | ||
| 15 | + { | ||
| 16 | + String dbPath = System.getProperty("dbPath"); | ||
| 17 | + String path = null != dbPath?dbPath:System.getProperty("user.dir")+"/configs/"; | ||
| 18 | + Properties p = new Properties(); | ||
| 19 | + System.out.println("》》》》》》》》》》》》》数据库配置文件地址:"+path+"lsy_dbcpconfig.properties"); | ||
| 20 | + p.load(new FileInputStream(path+"lsy_dbcpconfig.properties")); | ||
| 21 | +// p.load(DBFactory.class | ||
| 22 | +// .getClassLoader().getResourceAsStream("configs/dbcpconfig.properties")); | ||
| 23 | + ds = BasicDataSourceFactory.createDataSource(p); | ||
| 24 | + } | ||
| 25 | + } catch (Exception e) { | ||
| 26 | + e.printStackTrace(); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public DataSource getDataSource() { | ||
| 32 | + return ds; | ||
| 33 | + } | ||
| 34 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.xinjie.dto; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 设备对象 | ||
| 5 | + * Created by zhonglai on 2016/12/15. | ||
| 6 | + */ | ||
| 7 | +public class DeviceInfo { | ||
| 8 | + private String id;// varchar(50) NOT NULL COMMENT '设备主键ID(设备IMEI加编号)', | ||
| 9 | + private String deviceName;// varchar(50) NOT NULL COMMENT '设备名称', | ||
| 10 | + private Integer userId;// int(11) NOT NULL COMMENT '用户ID', | ||
| 11 | + private String userLoginName;// varchar(50) NOT NULL COMMENT '用户登录名', | ||
| 12 | + private Integer baseId;// int(11) NOT NULL COMMENT '基地ID', | ||
| 13 | + private String baseName;// varchar(50) NOT NULL COMMENT '基地名称', | ||
| 14 | + private Integer pondType;// int(11) NOT NULL COMMENT '塘口类型(0-外塘,1-水槽)', | ||
| 15 | + private Integer pondId;// int(11) NOT NULL COMMENT '水槽或外塘ID', | ||
| 16 | + private String pondName; // varchar(50) NOT NULL COMMENT '水槽或外塘名称', | ||
| 17 | + private String deviceType;// int(11) DEFAULT NULL COMMENT '设备类型(0-PLC,1-鱼儿乐)', | ||
| 18 | + private Integer deviceTerminalTypeKey;// int(11) DEFAULT NULL COMMENT '终端类型(0-排污,1-投饵,2-增氧,3-鱼儿乐,4-曝气,5-水流计量)', | ||
| 19 | + private String deviceTerminalType;// varchar(50) DEFAULT NULL COMMENT '终端名称', | ||
| 20 | + private String dataValue;// varchar(50) DEFAULT NULL COMMENT '数据值(json字符串)', | ||
| 21 | + private String alarmCode;// varchar(50) DEFAULT '00' COMMENT '告警代码(00-正常)', | ||
| 22 | + private Integer dataUpdateTime;// int(11) DEFAULT NULL COMMENT '更新时间', | ||
| 23 | + private String deviceServiceIp;// varchar(100) DEFAULT NULL COMMENT '设备服务器IP', | ||
| 24 | + private Integer createTime;// int(11) NOT NULL COMMENT '创建时间', | ||
| 25 | + private String remark;// varchar(100) DEFAULT NULL COMMENT '备注', | ||
| 26 | + private String online; | ||
| 27 | + private Integer alarmUpdateTime; //告警更新时间 | ||
| 28 | + | ||
| 29 | + public String getId() { | ||
| 30 | + return id; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public void setId(String id) { | ||
| 34 | + this.id = id; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public String getDeviceName() { | ||
| 38 | + return deviceName; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setDeviceName(String deviceName) { | ||
| 42 | + this.deviceName = deviceName; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public Integer getUserId() { | ||
| 46 | + return userId; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void setUserId(Integer userId) { | ||
| 50 | + this.userId = userId; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public String getUserLoginName() { | ||
| 54 | + return userLoginName; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public void setUserLoginName(String userLoginName) { | ||
| 58 | + this.userLoginName = userLoginName; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public Integer getBaseId() { | ||
| 62 | + return baseId; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public void setBaseId(Integer baseId) { | ||
| 66 | + this.baseId = baseId; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public String getBaseName() { | ||
| 70 | + return baseName; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public void setBaseName(String baseName) { | ||
| 74 | + this.baseName = baseName; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public Integer getPondType() { | ||
| 78 | + return pondType; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public void setPondType(Integer pondType) { | ||
| 82 | + this.pondType = pondType; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public Integer getPondId() { | ||
| 86 | + return pondId; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public void setPondId(Integer pondId) { | ||
| 90 | + this.pondId = pondId; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + public String getPondName() { | ||
| 94 | + return pondName; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public void setPondName(String pondName) { | ||
| 98 | + this.pondName = pondName; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public String getDeviceType() { | ||
| 102 | + return deviceType; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public void setDeviceType(String deviceType) { | ||
| 106 | + this.deviceType = deviceType; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public Integer getDeviceTerminalTypeKey() { | ||
| 110 | + return deviceTerminalTypeKey; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + public void setDeviceTerminalTypeKey(Integer deviceTerminalTypeKey) { | ||
| 114 | + this.deviceTerminalTypeKey = deviceTerminalTypeKey; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + public String getDeviceTerminalType() { | ||
| 118 | + return deviceTerminalType; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + public void setDeviceTerminalType(String deviceTerminalType) { | ||
| 122 | + this.deviceTerminalType = deviceTerminalType; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + public String getDataValue() { | ||
| 126 | + return dataValue; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + public void setDataValue(String dataValue) { | ||
| 130 | + this.dataValue = dataValue; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public String getDeviceServiceIp() { | ||
| 134 | + return deviceServiceIp; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public void setDeviceServiceIp(String deviceServiceIp) { | ||
| 138 | + this.deviceServiceIp = deviceServiceIp; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + public String getAlarmCode() { | ||
| 142 | + return alarmCode; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + public void setAlarmCode(String alarmCode) { | ||
| 146 | + this.alarmCode = alarmCode; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public Integer getDataUpdateTime() { | ||
| 150 | + return dataUpdateTime; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public void setDataUpdateTime(Integer dataUpdateTime) { | ||
| 154 | + this.dataUpdateTime = dataUpdateTime; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + public Integer getCreateTime() { | ||
| 158 | + return createTime; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + public void setCreateTime(Integer createTime) { | ||
| 162 | + this.createTime = createTime; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + public String getRemark() { | ||
| 166 | + return remark; | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + public void setRemark(String remark) { | ||
| 170 | + this.remark = remark; | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + public String getOnline() { | ||
| 174 | + return online; | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + public void setOnline(String online) { | ||
| 178 | + this.online = online; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + public Integer getAlarmUpdateTime() { | ||
| 182 | + return alarmUpdateTime; | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + public void setAlarmUpdateTime(Integer alarmUpdateTime) { | ||
| 186 | + this.alarmUpdateTime = alarmUpdateTime; | ||
| 187 | + } | ||
| 188 | +} |
| 1 | +package com.zhonglai.luhui.device.protocol.xinjie.sync; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | ||
| 8 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | ||
| 9 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 10 | +import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.specs.*; | ||
| 11 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 12 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto; | ||
| 13 | +import com.zhonglai.luhui.device.protocol.factory.sync.ProtocolSyncFactory; | ||
| 14 | +import com.zhonglai.luhui.device.protocol.xinjie.dto.DeviceInfo; | ||
| 15 | +import com.zhonglai.luhui.device.protocol.xinjie.db.LsyDBFactoryImp; | ||
| 16 | +import org.springframework.stereotype.Service; | ||
| 17 | + | ||
| 18 | +import java.util.List; | ||
| 19 | + | ||
| 20 | +@Service | ||
| 21 | +public class LsyProtocolSyncFactoryImpl implements ProtocolSyncFactory { | ||
| 22 | + | ||
| 23 | + private BaseDao lsy_baseDao = new BaseDao(new LsyDBFactoryImp()); | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public void updateParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto) { | ||
| 27 | + | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public void updateParserDeviceInfoDtoList(List<ParserDeviceInfoDto> parserDeviceInfoDtoList) { | ||
| 32 | + if(null != parserDeviceInfoDtoList && parserDeviceInfoDtoList.size() != 0) | ||
| 33 | + { | ||
| 34 | + for (ParserDeviceInfoDto parserDeviceInfoDto:parserDeviceInfoDtoList) | ||
| 35 | + { | ||
| 36 | + DeviceInfo deviceInfo = new DeviceInfo(); | ||
| 37 | + deviceInfo.setId(parserDeviceInfoDto.getId()); | ||
| 38 | + deviceInfo.setDataUpdateTime(parserDeviceInfoDto.getUpdateTime()); | ||
| 39 | + deviceInfo.setOnline("1"); | ||
| 40 | + | ||
| 41 | + JsonObject datavalue = new JsonObject(); | ||
| 42 | + | ||
| 43 | + JsonObject parserDeviceInfoDtoJson = parserDeviceInfoDto.getData(); | ||
| 44 | + if(null != parserDeviceInfoDtoJson && parserDeviceInfoDtoJson.size() !=0) | ||
| 45 | + { | ||
| 46 | + | ||
| 47 | + for (String key:parserDeviceInfoDtoJson.keySet()) | ||
| 48 | + { | ||
| 49 | + JsonObject jsonObject = parserDeviceInfoDtoJson.get(key).getAsJsonObject(); | ||
| 50 | + | ||
| 51 | + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(jsonObject); | ||
| 52 | + | ||
| 53 | + datavalue.addProperty(key,thingsModelItemBase.getSaveView()); | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + deviceInfo.setDataValue(datavalue.toString()); | ||
| 57 | + | ||
| 58 | + lsy_baseDao.update(deviceInfo); | ||
| 59 | + | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public void updateDeviceSensorDataList(List<DeviceSensorData> deviceSensorDataList) { | ||
| 66 | + | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @Override | ||
| 70 | + public void updateLogDeviceOperationList(List<LogDeviceOperation> logDeviceOperationList) { | ||
| 71 | + | ||
| 72 | + } | ||
| 73 | +} |
lh-modules/lh-device-protocol-parser/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-modules</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 13 | + <artifactId>lh-device-protocol-parser</artifactId> | ||
| 14 | + | ||
| 15 | + <properties> | ||
| 16 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 17 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 18 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 19 | + </properties> | ||
| 20 | + | ||
| 21 | + <packaging>pom</packaging> | ||
| 22 | + | ||
| 23 | + <modules> | ||
| 24 | + <module>lh-device-xinjie</module> | ||
| 25 | + <module>lh-device-protocol-factory</module> | ||
| 26 | + <module>lh-device-http-public</module> | ||
| 27 | + </modules> | ||
| 28 | + <description> | ||
| 29 | + 设备协议解析工厂 | ||
| 30 | + </description> | ||
| 31 | +</project> |
lh-modules/lh-http-service-proxy/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-modules</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <groupId>com.luhui</groupId> | ||
| 13 | + <artifactId>lh-http-service-proxy</artifactId> | ||
| 14 | + | ||
| 15 | + <properties> | ||
| 16 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 17 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 18 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 19 | + </properties> | ||
| 20 | + | ||
| 21 | + <dependencies> | ||
| 22 | + <!-- spring-boot-devtools --> | ||
| 23 | + <dependency> | ||
| 24 | + <groupId>org.springframework.boot</groupId> | ||
| 25 | + <artifactId>spring-boot-devtools</artifactId> | ||
| 26 | + <optional>true</optional> <!-- 表示依赖不会传递 --> | ||
| 27 | + </dependency> | ||
| 28 | + <!-- SpringBoot Web容器 --> | ||
| 29 | + <dependency> | ||
| 30 | + <groupId>org.springframework.boot</groupId> | ||
| 31 | + <artifactId>spring-boot-starter-web</artifactId> | ||
| 32 | + </dependency> | ||
| 33 | + <!-- Spring框架基本的核心工具 --> | ||
| 34 | + <dependency> | ||
| 35 | + <groupId>org.springframework</groupId> | ||
| 36 | + <artifactId>spring-context-support</artifactId> | ||
| 37 | + </dependency> | ||
| 38 | + <!-- SpringWeb模块 --> | ||
| 39 | + <dependency> | ||
| 40 | + <groupId>org.springframework</groupId> | ||
| 41 | + <artifactId>spring-web</artifactId> | ||
| 42 | + </dependency> | ||
| 43 | + <!-- yml解析器 --> | ||
| 44 | + <dependency> | ||
| 45 | + <groupId>org.yaml</groupId> | ||
| 46 | + <artifactId>snakeyaml</artifactId> | ||
| 47 | + </dependency> | ||
| 48 | + <!-- servlet包 --> | ||
| 49 | + <dependency> | ||
| 50 | + <groupId>javax.servlet</groupId> | ||
| 51 | + <artifactId>javax.servlet-api</artifactId> | ||
| 52 | + </dependency> | ||
| 53 | + <dependency> | ||
| 54 | + <groupId>org.apache.commons</groupId> | ||
| 55 | + <artifactId>commons-text</artifactId> | ||
| 56 | + </dependency> | ||
| 57 | + | ||
| 58 | + <!-- 文档 --> | ||
| 59 | + <dependency> | ||
| 60 | + <groupId>io.springfox</groupId> | ||
| 61 | + <artifactId>springfox-swagger2</artifactId> | ||
| 62 | + <version>${swagger.version}</version> | ||
| 63 | + <exclusions> | ||
| 64 | + <exclusion> | ||
| 65 | + <groupId>io.swagger</groupId> | ||
| 66 | + <artifactId>swagger-models</artifactId> | ||
| 67 | + </exclusion> | ||
| 68 | + <exclusion> | ||
| 69 | + <groupId>com.google.guava</groupId> | ||
| 70 | + <artifactId>guava</artifactId> | ||
| 71 | + </exclusion> | ||
| 72 | + </exclusions> | ||
| 73 | + </dependency> | ||
| 74 | + <!--https://mvnrepository.com/artifact/io.swagger/swagger-models--> | ||
| 75 | + <dependency> | ||
| 76 | + <groupId>io.swagger</groupId> | ||
| 77 | + <artifactId>swagger-models</artifactId> | ||
| 78 | + <version>${swagger-models.version}</version> | ||
| 79 | + </dependency> | ||
| 80 | + <dependency> | ||
| 81 | + <groupId>io.springfox</groupId> | ||
| 82 | + <artifactId>springfox-swagger-ui</artifactId> | ||
| 83 | + <version>${swagger.version}</version> | ||
| 84 | + </dependency> | ||
| 85 | + <!--<!– https://mvnrepository.com/artifact/com.github.xiaoymin/swagger-bootstrap-ui –>--> | ||
| 86 | + <dependency> | ||
| 87 | + <groupId>com.github.xiaoymin</groupId> | ||
| 88 | + <artifactId>swagger-bootstrap-ui</artifactId> | ||
| 89 | + <version>${swagger-ui.version}</version> | ||
| 90 | + </dependency> | ||
| 91 | + | ||
| 92 | + <!-- 支持data --> | ||
| 93 | + <dependency> | ||
| 94 | + <groupId>org.projectlombok</groupId> | ||
| 95 | + <artifactId>lombok</artifactId> | ||
| 96 | + </dependency> | ||
| 97 | + | ||
| 98 | + <!--常用工具类 --> | ||
| 99 | + <dependency> | ||
| 100 | + <groupId>org.apache.commons</groupId> | ||
| 101 | + <artifactId>commons-lang3</artifactId> | ||
| 102 | + </dependency> | ||
| 103 | + | ||
| 104 | + | ||
| 105 | + <dependency> | ||
| 106 | + <groupId>com.squareup.okhttp3</groupId> | ||
| 107 | + <artifactId>okhttp</artifactId> | ||
| 108 | + </dependency> | ||
| 109 | + | ||
| 110 | + <!-- 通用工具--> | ||
| 111 | + <dependency> | ||
| 112 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 113 | + <artifactId>lh-domain</artifactId> | ||
| 114 | + </dependency> | ||
| 115 | + <dependency> | ||
| 116 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 117 | + <artifactId>lh-device-protocol-factory</artifactId> | ||
| 118 | + </dependency> | ||
| 119 | + <dependency> | ||
| 120 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 121 | + <artifactId>lh-device-http-public</artifactId> | ||
| 122 | + </dependency> | ||
| 123 | + </dependencies> | ||
| 124 | + | ||
| 125 | + <build> | ||
| 126 | + <finalName>lh-http-service-proxy</finalName> | ||
| 127 | + <plugins> | ||
| 128 | + <plugin> | ||
| 129 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 130 | + <artifactId>maven-jar-plugin</artifactId> | ||
| 131 | + <version>2.4</version> | ||
| 132 | + <configuration> | ||
| 133 | + <archive> | ||
| 134 | + <!-- | ||
| 135 | + 生成的jar中,不要包含pom.xml和pom.properties这两个文件 | ||
| 136 | + --> | ||
| 137 | + <addMavenDescriptor>false</addMavenDescriptor> | ||
| 138 | + <manifest> | ||
| 139 | + <!-- | ||
| 140 | + 是否要把第三方jar放到manifest的classpath中 | ||
| 141 | + --> | ||
| 142 | + <addClasspath>true</addClasspath> | ||
| 143 | + | ||
| 144 | + <!-- | ||
| 145 | + 生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/ | ||
| 146 | + --> | ||
| 147 | + <classpathPrefix>lib/</classpathPrefix> | ||
| 148 | + <mainClass>com.zhonglai.luhui.http.service.proxy.LhHttpServiceProxyApplication</mainClass> | ||
| 149 | + </manifest> | ||
| 150 | + </archive> | ||
| 151 | + </configuration> | ||
| 152 | + </plugin> | ||
| 153 | + | ||
| 154 | + <!-- The configuration of maven-assembly-plugin --> | ||
| 155 | + <plugin> | ||
| 156 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 157 | + <artifactId>maven-assembly-plugin</artifactId> | ||
| 158 | + <version>2.4</version> | ||
| 159 | + <configuration> | ||
| 160 | + <descriptors> | ||
| 161 | + <descriptor>src/main/resources/package.xml</descriptor> | ||
| 162 | + </descriptors> | ||
| 163 | + </configuration> | ||
| 164 | + <executions> | ||
| 165 | + <execution> | ||
| 166 | + <id>make-assembly</id> | ||
| 167 | + <phase>package</phase> | ||
| 168 | + <goals> | ||
| 169 | + <goal>single</goal> | ||
| 170 | + </goals> | ||
| 171 | + </execution> | ||
| 172 | + </executions> | ||
| 173 | + </plugin> | ||
| 174 | + </plugins> | ||
| 175 | + </build> | ||
| 176 | +</project> |
| 1 | +package com.zhonglai.luhui.http.service.proxy; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.analysis.comm.config.CacheConfig; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.comm.config.FastJson2JsonRedisSerializer; | ||
| 5 | +import org.slf4j.Logger; | ||
| 6 | +import org.slf4j.LoggerFactory; | ||
| 7 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| 8 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
| 9 | +import org.springframework.boot.builder.SpringApplicationBuilder; | ||
| 10 | +import org.springframework.context.annotation.ComponentScan; | ||
| 11 | +import org.springframework.context.annotation.FilterType; | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +@ComponentScan(basePackages = { | ||
| 15 | + "com.ruoyi.common.utils.spring", | ||
| 16 | + "com.zhonglai.luhui.device.protocol", | ||
| 17 | + "com.zhonglai.luhui.device.analysis.comm.config", | ||
| 18 | + "com.zhonglai.luhui.http.service.proxy" | ||
| 19 | +},excludeFilters = @ComponentScan.Filter( | ||
| 20 | + type = FilterType.ASSIGNABLE_TYPE, | ||
| 21 | + classes = {CacheConfig.class, FastJson2JsonRedisSerializer.class} | ||
| 22 | +) ) | ||
| 23 | +@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) | ||
| 24 | +public class LhHttpServiceProxyApplication { | ||
| 25 | + private static Logger log = LoggerFactory.getLogger(LhHttpServiceProxyApplication.class); | ||
| 26 | + | ||
| 27 | + public static void main(String[] args) { | ||
| 28 | + log.info("启动服务"); | ||
| 29 | + SpringApplicationBuilder builder = new SpringApplicationBuilder(LhHttpServiceProxyApplication.class); | ||
| 30 | + builder.run( args); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | +} |
| 1 | +package com.zhonglai.luhui.http.service.proxy.config; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiOperation; | ||
| 4 | +import org.springframework.context.annotation.Bean; | ||
| 5 | +import org.springframework.context.annotation.Configuration; | ||
| 6 | +import springfox.documentation.builders.ApiInfoBuilder; | ||
| 7 | +import springfox.documentation.builders.PathSelectors; | ||
| 8 | +import springfox.documentation.builders.RequestHandlerSelectors; | ||
| 9 | +import springfox.documentation.service.ApiInfo; | ||
| 10 | +import springfox.documentation.service.Contact; | ||
| 11 | +import springfox.documentation.spi.DocumentationType; | ||
| 12 | +import springfox.documentation.spring.web.plugins.Docket; | ||
| 13 | +import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +@Configuration | ||
| 17 | +@EnableSwagger2 | ||
| 18 | +public class SwaggerConfig { | ||
| 19 | + @Bean | ||
| 20 | + public Docket createRestApi() { | ||
| 21 | + return new Docket(DocumentationType.SWAGGER_2) | ||
| 22 | + .apiInfo(apiInfo()) | ||
| 23 | + .select() | ||
| 24 | + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) | ||
| 25 | + .paths(PathSelectors.any()) | ||
| 26 | + .build(); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 添加摘要信息 | ||
| 31 | + */ | ||
| 32 | + private ApiInfo apiInfo() | ||
| 33 | + { | ||
| 34 | + // 用ApiInfoBuilder进行定制 | ||
| 35 | + return new ApiInfoBuilder() | ||
| 36 | + // 设置标题 | ||
| 37 | + .title("标题:http协议服务监听") | ||
| 38 | + // 描述 | ||
| 39 | + .description("描述:用于通过http发送指令控制终端端操作") | ||
| 40 | + // 作者信息 | ||
| 41 | + .contact(new Contact("", null, null)) | ||
| 42 | + // 版本 | ||
| 43 | + .version("版本号:1.1.1" ) | ||
| 44 | + .build(); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | +} |
| 1 | +package com.zhonglai.luhui.http.service.proxy.controller; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.core.domain.AjaxResult; | ||
| 5 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; | ||
| 7 | +import com.zhonglai.luhui.device.domain.IotDevice; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.factory.ProtocolParserAndPurificationFactory; | ||
| 9 | +import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; | ||
| 10 | +import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; | ||
| 11 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 12 | +import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 13 | +import com.zhonglai.luhui.device.protocol.factory.service.DeviceCashUpService; | ||
| 14 | +import com.zhonglai.luhui.device.protocol.factory.service.PersistenceDBService; | ||
| 15 | +import com.zhonglai.luhui.http.service.proxy.service.HttpCallback; | ||
| 16 | +import io.swagger.annotations.Api; | ||
| 17 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 18 | +import io.swagger.annotations.ApiImplicitParams; | ||
| 19 | +import io.swagger.annotations.ApiOperation; | ||
| 20 | +import org.slf4j.Logger; | ||
| 21 | +import org.slf4j.LoggerFactory; | ||
| 22 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 23 | +import org.springframework.stereotype.Controller; | ||
| 24 | +import org.springframework.util.StreamUtils; | ||
| 25 | +import org.springframework.web.bind.annotation.*; | ||
| 26 | + | ||
| 27 | +import javax.servlet.http.HttpServletRequest; | ||
| 28 | +import java.io.IOException; | ||
| 29 | +import java.util.HashMap; | ||
| 30 | +import java.util.Map; | ||
| 31 | +import java.util.concurrent.ExecutorService; | ||
| 32 | +import java.util.concurrent.LinkedBlockingQueue; | ||
| 33 | +import java.util.concurrent.ThreadPoolExecutor; | ||
| 34 | +import java.util.concurrent.TimeUnit; | ||
| 35 | + | ||
| 36 | +@Api(tags = "数据提交") | ||
| 37 | +@RestController | ||
| 38 | +@RequestMapping("/httpDataProxy") | ||
| 39 | +public class HttpDataProxyController { | ||
| 40 | + | ||
| 41 | + @Autowired | ||
| 42 | + private HttpCallback httpCallback; | ||
| 43 | + | ||
| 44 | + @ApiOperation(value = "post提交数据",notes = "数据由body传值") | ||
| 45 | + @ApiImplicitParams({ | ||
| 46 | + @ApiImplicitParam(value = "时间(时间戳单位毫秒)",name = "time"), | ||
| 47 | + @ApiImplicitParam(value = "设备imei",name = "imei"), | ||
| 48 | + @ApiImplicitParam(value = "产品id",name = "role"), | ||
| 49 | + @ApiImplicitParam(value = "用户名",name = "username"), | ||
| 50 | + }) | ||
| 51 | + @RequestMapping(value = "post/{role}/{username}/{imei}/{time}",method = RequestMethod.POST) | ||
| 52 | + public AjaxResult post(@PathVariable String role, @PathVariable String username, @PathVariable String imei, @PathVariable Integer time, HttpServletRequest request) throws IOException { | ||
| 53 | + byte[] bodyBytes = StreamUtils.copyToByteArray(request.getInputStream()); | ||
| 54 | + String body = new String(bodyBytes, request.getCharacterEncoding()); | ||
| 55 | + JsonObject jsonObject = GsonConstructor.get().fromJson(body,JsonObject.class); | ||
| 56 | + DeviceDataLog.info(imei, DataLogType.发来数据,"/"+role+"/"+username+"/"+imei+"/Json/"+time,jsonObject); | ||
| 57 | + | ||
| 58 | + httpCallback.messageArrived(role,username,imei,jsonObject); | ||
| 59 | + | ||
| 60 | + return AjaxResult.success(); | ||
| 61 | + } | ||
| 62 | +} |
| 1 | +package com.zhonglai.luhui.http.service.proxy.manager; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.Threads; | ||
| 4 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | +import org.springframework.stereotype.Service; | ||
| 7 | + | ||
| 8 | +import java.util.TimerTask; | ||
| 9 | +import java.util.concurrent.Executors; | ||
| 10 | +import java.util.concurrent.ScheduledExecutorService; | ||
| 11 | +import java.util.concurrent.TimeUnit; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 异步任务管理器 | ||
| 15 | + * | ||
| 16 | + * @author ruoyi | ||
| 17 | + */ | ||
| 18 | +@Service | ||
| 19 | +public class AsyncManager | ||
| 20 | +{ | ||
| 21 | + /** | ||
| 22 | + * 操作延迟10毫秒 | ||
| 23 | + */ | ||
| 24 | + private final int OPERATE_DELAY_TIME = 10; | ||
| 25 | + private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(100); | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 执行任务 | ||
| 29 | + * | ||
| 30 | + * @param task 任务 | ||
| 31 | + */ | ||
| 32 | + public void execute(TimerTask task) | ||
| 33 | + { | ||
| 34 | + scheduler.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 停止任务线程池 | ||
| 39 | + */ | ||
| 40 | + public void shutdown() | ||
| 41 | + { | ||
| 42 | + Threads.shutdownAndAwaitTermination(scheduler); | ||
| 43 | + } | ||
| 44 | +} |
| 1 | +package com.zhonglai.luhui.http.service.proxy.manager; | ||
| 2 | + | ||
| 3 | +import org.slf4j.Logger; | ||
| 4 | +import org.slf4j.LoggerFactory; | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | +import org.springframework.stereotype.Component; | ||
| 7 | + | ||
| 8 | +import javax.annotation.PreDestroy; | ||
| 9 | +import java.util.concurrent.ScheduledExecutorService; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 确保应用退出时能关闭后台线程 | ||
| 13 | + * | ||
| 14 | + * @author ruoyi | ||
| 15 | + */ | ||
| 16 | +@Component | ||
| 17 | +public class ShutdownManager | ||
| 18 | +{ | ||
| 19 | + private static final Logger logger = LoggerFactory.getLogger(ShutdownManager.class); | ||
| 20 | + | ||
| 21 | + @Autowired | ||
| 22 | + private AsyncManager asyncManager; | ||
| 23 | + | ||
| 24 | + @PreDestroy | ||
| 25 | + public void destroy() | ||
| 26 | + { | ||
| 27 | + shutdownAsyncManager(); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 停止异步执行任务 | ||
| 32 | + */ | ||
| 33 | + private void shutdownAsyncManager() | ||
| 34 | + { | ||
| 35 | + try | ||
| 36 | + { | ||
| 37 | + logger.info("====关闭后台任务任务线程池===="); | ||
| 38 | + asyncManager.shutdown(); | ||
| 39 | + } | ||
| 40 | + catch (Exception e) | ||
| 41 | + { | ||
| 42 | + logger.error(e.getMessage(), e); | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | +} |
| 1 | +package com.zhonglai.luhui.http.service.proxy.service; | ||
| 2 | + | ||
| 3 | +import com.google.gson.JsonObject; | ||
| 4 | +import com.ruoyi.common.core.domain.AjaxResult; | ||
| 5 | +import com.zhonglai.luhui.device.protocol.factory.ProtocolParserAndPurificationFactory; | ||
| 6 | +import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto; | ||
| 7 | +import com.zhonglai.luhui.device.protocol.factory.dto.ProtocolPurificationModel; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.factory.service.BaseCallback; | ||
| 9 | +import com.zhonglai.luhui.device.protocol.factory.service.DeviceCashUpService; | ||
| 10 | +import com.zhonglai.luhui.device.protocol.factory.service.PersistenceDBService; | ||
| 11 | +import com.zhonglai.luhui.http.service.proxy.manager.AsyncManager; | ||
| 12 | +import org.slf4j.Logger; | ||
| 13 | +import org.slf4j.LoggerFactory; | ||
| 14 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 15 | +import org.springframework.stereotype.Service; | ||
| 16 | + | ||
| 17 | +import java.util.Map; | ||
| 18 | +import java.util.TimerTask; | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +@Service | ||
| 22 | +public class HttpCallback extends BaseCallback<JsonObject> { | ||
| 23 | + | ||
| 24 | + @Autowired | ||
| 25 | + private AsyncManager asyncManager; | ||
| 26 | + | ||
| 27 | + public void messageArrived(String role, String username, String imei, JsonObject data) | ||
| 28 | + { | ||
| 29 | + try { | ||
| 30 | + HttpCallback.super.messageArrived(imei,"/"+role+"/"+username+"/"+imei+"/Json",data); | ||
| 31 | + } catch (ClassNotFoundException e) { | ||
| 32 | + throw new RuntimeException(e); | ||
| 33 | + } | ||
| 34 | +// asyncManager.execute(new TimerTask() { | ||
| 35 | +// @Override | ||
| 36 | +// public void run() { | ||
| 37 | +// | ||
| 38 | +// } | ||
| 39 | +// }); | ||
| 40 | + | ||
| 41 | + } | ||
| 42 | +} |
| 1 | +##服务器配置 | ||
| 2 | +server: | ||
| 3 | + tomcat: | ||
| 4 | + uri-encoding: UTF-8 | ||
| 5 | + port: 4886 | ||
| 6 | + servlet: | ||
| 7 | + context-path: / | ||
| 8 | + | ||
| 9 | +spring: | ||
| 10 | + messages: | ||
| 11 | + encoding: UTF-8 | ||
| 12 | + mvc: | ||
| 13 | + #出现错误时, 直接抛出异常 | ||
| 14 | + throw-exception-if-no-handler-found: true | ||
| 15 | + jackson: | ||
| 16 | + date-format: yyyy-MM-dd HH:mm:ss | ||
| 17 | + time-zone: GMT+8 | ||
| 18 | + default-property-inclusion: non_null |
| 1 | +log4j.rootLogger=info,indicator,FILE | ||
| 2 | + | ||
| 3 | +log4j.appender.indicator=org.apache.log4j.ConsoleAppender | ||
| 4 | +log4j.appender.indicator.layout=org.apache.log4j.PatternLayout | ||
| 5 | +log4j.appender.indicator.layout.ConversionPattern=%d{HH:mm:ss} [%p] %l -%m%n | ||
| 6 | + | ||
| 7 | +log4j.appender.FILE = org.apache.log4j.RollingFileAppender | ||
| 8 | +log4j.appender.FILE.File = logs/output.log | ||
| 9 | +log4j.appender.FILE.MaxFileSize = 2000KB | ||
| 10 | +log4j.appender.FILE.MaxBackupIndex = 5 | ||
| 11 | +log4j.appender.FILE.layout = org.apache.log4j.PatternLayout | ||
| 12 | +log4j.appender.FILE.layout.ConversionPattern = %d{HH:mm:ss} [%p] %l -%m%n | ||
| 13 | + | ||
| 14 | +log4j.logger.myDatalog= info, datalog | ||
| 15 | +log4j.additivity.myDatalog = false | ||
| 16 | +log4j.appender.datalog = org.apache.log4j.RollingFileAppender | ||
| 17 | +log4j.appender.datalog.File = datalog/output.log | ||
| 18 | +log4j.appender.datalog.MaxFileSize = 2000KB | ||
| 19 | +log4j.appender.datalog.MaxBackupIndex = 5 | ||
| 20 | +log4j.appender.datalog.layout = org.apache.log4j.PatternLayout | ||
| 21 | +log4j.appender.datalog.layout.ConversionPattern = %d{HH:mm:ss} [%p] %l -%m%n |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | + | ||
| 3 | +<assembly> | ||
| 4 | + <id>bin</id> | ||
| 5 | + <!-- 最终打包成一个用于发布的zip文件 --> | ||
| 6 | + <formats> | ||
| 7 | + <format>zip</format> | ||
| 8 | + </formats> | ||
| 9 | + | ||
| 10 | + <!-- Adds dependencies to zip package under lib directory --> | ||
| 11 | + <dependencySets> | ||
| 12 | + <dependencySet> | ||
| 13 | + <!-- | ||
| 14 | + 不使用项目的artifact,第三方jar不要解压,打包进zip文件的lib目录 | ||
| 15 | + --> | ||
| 16 | + <useProjectArtifact>false</useProjectArtifact> | ||
| 17 | + <outputDirectory>lib</outputDirectory> | ||
| 18 | + <unpack>false</unpack> | ||
| 19 | + </dependencySet> | ||
| 20 | + </dependencySets> | ||
| 21 | + | ||
| 22 | + <fileSets> | ||
| 23 | + <!-- 把项目相关的说明文件,打包进zip文件的根目录 --> | ||
| 24 | + <fileSet> | ||
| 25 | + <directory>${project.basedir}</directory> | ||
| 26 | + <outputDirectory>/</outputDirectory> | ||
| 27 | + <includes> | ||
| 28 | + <include>README*</include> | ||
| 29 | + <include>LICENSE*</include> | ||
| 30 | + <include>NOTICE*</include> | ||
| 31 | + </includes> | ||
| 32 | + </fileSet> | ||
| 33 | + | ||
| 34 | + <!-- 把项目的配置文件,打包进zip文件的config目录 --> | ||
| 35 | + <fileSet> | ||
| 36 | + <directory>${project.basedir}\src\main\resources\configs</directory> | ||
| 37 | + <outputDirectory>../configs</outputDirectory> | ||
| 38 | + <includes> | ||
| 39 | + <include>*.properties</include> | ||
| 40 | + </includes> | ||
| 41 | + </fileSet> | ||
| 42 | + | ||
| 43 | + <!-- 把项目的配置文件,提出来 --> | ||
| 44 | + <fileSet> | ||
| 45 | + <directory>${project.basedir}\src\main\resources</directory> | ||
| 46 | + <outputDirectory>/</outputDirectory> | ||
| 47 | + <includes> | ||
| 48 | + <include>*.properties</include> | ||
| 49 | + <include>*.yml</include> | ||
| 50 | + </includes> | ||
| 51 | + </fileSet> | ||
| 52 | + | ||
| 53 | + <!-- 把项目的脚本文件目录( src/main/scripts )中的启动脚本文件,打包进zip文件的跟目录 --> | ||
| 54 | + <fileSet> | ||
| 55 | + <directory>${project.basedir}\bin</directory> | ||
| 56 | + <outputDirectory></outputDirectory> | ||
| 57 | + <includes> | ||
| 58 | + <include>start.*</include> | ||
| 59 | + <include>stop.*</include> | ||
| 60 | + </includes> | ||
| 61 | + </fileSet> | ||
| 62 | + | ||
| 63 | + <!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 --> | ||
| 64 | + <fileSet> | ||
| 65 | + <directory>${project.build.directory}</directory> | ||
| 66 | + <outputDirectory></outputDirectory> | ||
| 67 | + <includes> | ||
| 68 | + <include>*.jar</include> | ||
| 69 | + </includes> | ||
| 70 | + </fileSet> | ||
| 71 | + </fileSets> | ||
| 72 | +</assembly> |
lh-modules/lh-mqtt-service-listen/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <modelVersion>4.0.0</modelVersion> | ||
| 6 | + <parent> | ||
| 7 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 8 | + <artifactId>lh-modules</artifactId> | ||
| 9 | + <version>1.0-SNAPSHOT</version> | ||
| 10 | + </parent> | ||
| 11 | + | ||
| 12 | + <groupId>com.luhui</groupId> | ||
| 13 | + <artifactId>lh-mqtt-service-listen</artifactId> | ||
| 14 | + | ||
| 15 | + <properties> | ||
| 16 | + <maven.compiler.source>8</maven.compiler.source> | ||
| 17 | + <maven.compiler.target>8</maven.compiler.target> | ||
| 18 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| 19 | + </properties> | ||
| 20 | + | ||
| 21 | + <dependencies> | ||
| 22 | + <!-- spring-boot-devtools --> | ||
| 23 | + <dependency> | ||
| 24 | + <groupId>org.springframework.boot</groupId> | ||
| 25 | + <artifactId>spring-boot-devtools</artifactId> | ||
| 26 | + <optional>true</optional> <!-- 表示依赖不会传递 --> | ||
| 27 | + </dependency> | ||
| 28 | + <!-- SpringBoot Web容器 --> | ||
| 29 | + <dependency> | ||
| 30 | + <groupId>org.springframework.boot</groupId> | ||
| 31 | + <artifactId>spring-boot-starter-web</artifactId> | ||
| 32 | + </dependency> | ||
| 33 | + <!-- Spring框架基本的核心工具 --> | ||
| 34 | + <dependency> | ||
| 35 | + <groupId>org.springframework</groupId> | ||
| 36 | + <artifactId>spring-context-support</artifactId> | ||
| 37 | + </dependency> | ||
| 38 | + <!-- SpringWeb模块 --> | ||
| 39 | + <dependency> | ||
| 40 | + <groupId>org.springframework</groupId> | ||
| 41 | + <artifactId>spring-web</artifactId> | ||
| 42 | + </dependency> | ||
| 43 | + <!-- yml解析器 --> | ||
| 44 | + <dependency> | ||
| 45 | + <groupId>org.yaml</groupId> | ||
| 46 | + <artifactId>snakeyaml</artifactId> | ||
| 47 | + </dependency> | ||
| 48 | + <!-- servlet包 --> | ||
| 49 | + <dependency> | ||
| 50 | + <groupId>javax.servlet</groupId> | ||
| 51 | + <artifactId>javax.servlet-api</artifactId> | ||
| 52 | + </dependency> | ||
| 53 | + <dependency> | ||
| 54 | + <groupId>org.apache.commons</groupId> | ||
| 55 | + <artifactId>commons-text</artifactId> | ||
| 56 | + </dependency> | ||
| 57 | + | ||
| 58 | + <!-- 文档 --> | ||
| 59 | + <dependency> | ||
| 60 | + <groupId>io.springfox</groupId> | ||
| 61 | + <artifactId>springfox-swagger2</artifactId> | ||
| 62 | + <version>${swagger.version}</version> | ||
| 63 | + <exclusions> | ||
| 64 | + <exclusion> | ||
| 65 | + <groupId>io.swagger</groupId> | ||
| 66 | + <artifactId>swagger-models</artifactId> | ||
| 67 | + </exclusion> | ||
| 68 | + <exclusion> | ||
| 69 | + <groupId>com.google.guava</groupId> | ||
| 70 | + <artifactId>guava</artifactId> | ||
| 71 | + </exclusion> | ||
| 72 | + </exclusions> | ||
| 73 | + </dependency> | ||
| 74 | + <!--https://mvnrepository.com/artifact/io.swagger/swagger-models--> | ||
| 75 | + <dependency> | ||
| 76 | + <groupId>io.swagger</groupId> | ||
| 77 | + <artifactId>swagger-models</artifactId> | ||
| 78 | + <version>${swagger-models.version}</version> | ||
| 79 | + </dependency> | ||
| 80 | + <dependency> | ||
| 81 | + <groupId>io.springfox</groupId> | ||
| 82 | + <artifactId>springfox-swagger-ui</artifactId> | ||
| 83 | + <version>${swagger.version}</version> | ||
| 84 | + </dependency> | ||
| 85 | + <!--<!– https://mvnrepository.com/artifact/com.github.xiaoymin/swagger-bootstrap-ui –>--> | ||
| 86 | + <dependency> | ||
| 87 | + <groupId>com.github.xiaoymin</groupId> | ||
| 88 | + <artifactId>swagger-bootstrap-ui</artifactId> | ||
| 89 | + <version>${swagger-ui.version}</version> | ||
| 90 | + </dependency> | ||
| 91 | + | ||
| 92 | + <!-- 支持data --> | ||
| 93 | + <dependency> | ||
| 94 | + <groupId>org.projectlombok</groupId> | ||
| 95 | + <artifactId>lombok</artifactId> | ||
| 96 | + </dependency> | ||
| 97 | + | ||
| 98 | + <!-- 阿里JSON解析器 --> | ||
| 99 | + <dependency> | ||
| 100 | + <groupId>com.alibaba</groupId> | ||
| 101 | + <artifactId>fastjson</artifactId> | ||
| 102 | + </dependency> | ||
| 103 | + | ||
| 104 | + <!--常用工具类 --> | ||
| 105 | + <dependency> | ||
| 106 | + <groupId>org.apache.commons</groupId> | ||
| 107 | + <artifactId>commons-lang3</artifactId> | ||
| 108 | + </dependency> | ||
| 109 | + | ||
| 110 | + <!-- redis 缓存操作 --> | ||
| 111 | + <dependency> | ||
| 112 | + <groupId>org.springframework.boot</groupId> | ||
| 113 | + <artifactId>spring-boot-starter-data-redis</artifactId> | ||
| 114 | + <exclusions> | ||
| 115 | + <exclusion> | ||
| 116 | + <groupId>io.lettuce</groupId> | ||
| 117 | + <artifactId>lettuce-core</artifactId> | ||
| 118 | + </exclusion> | ||
| 119 | + </exclusions> | ||
| 120 | + </dependency> | ||
| 121 | + <dependency> | ||
| 122 | + <groupId>redis.clients</groupId> | ||
| 123 | + <artifactId>jedis</artifactId> | ||
| 124 | + </dependency> | ||
| 125 | + <!-- Token生成与解析--> | ||
| 126 | + <dependency> | ||
| 127 | + <groupId>io.jsonwebtoken</groupId> | ||
| 128 | + <artifactId>jjwt</artifactId> | ||
| 129 | + </dependency> | ||
| 130 | + | ||
| 131 | + <dependency> | ||
| 132 | + <groupId>com.squareup.okhttp3</groupId> | ||
| 133 | + <artifactId>okhttp</artifactId> | ||
| 134 | + </dependency> | ||
| 135 | + | ||
| 136 | + <!-- 通用工具--> | ||
| 137 | + <dependency> | ||
| 138 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 139 | + <artifactId>lh-domain</artifactId> | ||
| 140 | + </dependency> | ||
| 141 | + | ||
| 142 | + <dependency> | ||
| 143 | + <groupId>org.apache.rocketmq</groupId> | ||
| 144 | + <artifactId>rocketmq-spring-boot-starter</artifactId> | ||
| 145 | + </dependency> | ||
| 146 | + <dependency> | ||
| 147 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 148 | + <artifactId>lh-jar-device-service</artifactId> | ||
| 149 | + </dependency> | ||
| 150 | + <dependency> | ||
| 151 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 152 | + <artifactId>lh-device-protocol-factory</artifactId> | ||
| 153 | + </dependency> | ||
| 154 | + <dependency> | ||
| 155 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 156 | + <artifactId>lh-device-xinjie</artifactId> | ||
| 157 | + </dependency> | ||
| 158 | + </dependencies> | ||
| 159 | + | ||
| 160 | + <build> | ||
| 161 | + <finalName>lh-mqtt-service-listen</finalName> | ||
| 162 | + <plugins> | ||
| 163 | + <plugin> | ||
| 164 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 165 | + <artifactId>maven-jar-plugin</artifactId> | ||
| 166 | + <version>2.4</version> | ||
| 167 | + <configuration> | ||
| 168 | + <archive> | ||
| 169 | + <!-- | ||
| 170 | + 生成的jar中,不要包含pom.xml和pom.properties这两个文件 | ||
| 171 | + --> | ||
| 172 | + <addMavenDescriptor>false</addMavenDescriptor> | ||
| 173 | + <manifest> | ||
| 174 | + <!-- | ||
| 175 | + 是否要把第三方jar放到manifest的classpath中 | ||
| 176 | + --> | ||
| 177 | + <addClasspath>true</addClasspath> | ||
| 178 | + | ||
| 179 | + <!-- | ||
| 180 | + 生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/ | ||
| 181 | + --> | ||
| 182 | + <classpathPrefix>lib/</classpathPrefix> | ||
| 183 | + <mainClass>com.zhonglai.luhui.mqtt.service.proxy.MqttServiceListenApplication</mainClass> | ||
| 184 | + </manifest> | ||
| 185 | + </archive> | ||
| 186 | + </configuration> | ||
| 187 | + </plugin> | ||
| 188 | + | ||
| 189 | + <!-- The configuration of maven-assembly-plugin --> | ||
| 190 | + <plugin> | ||
| 191 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 192 | + <artifactId>maven-assembly-plugin</artifactId> | ||
| 193 | + <version>2.4</version> | ||
| 194 | + <configuration> | ||
| 195 | + <descriptors> | ||
| 196 | + <descriptor>src/main/resources/package.xml</descriptor> | ||
| 197 | + </descriptors> | ||
| 198 | + </configuration> | ||
| 199 | + <executions> | ||
| 200 | + <execution> | ||
| 201 | + <id>make-assembly</id> | ||
| 202 | + <phase>package</phase> | ||
| 203 | + <goals> | ||
| 204 | + <goal>single</goal> | ||
| 205 | + </goals> | ||
| 206 | + </execution> | ||
| 207 | + </executions> | ||
| 208 | + </plugin> | ||
| 209 | + </plugins> | ||
| 210 | + </build> | ||
| 211 | +</project> |
| 1 | +package com.zhonglai.luhui.mqtt.service.proxy; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.analysis.comm.config.CacheConfig; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.comm.config.FastJson2JsonRedisSerializer; | ||
| 5 | +import org.slf4j.Logger; | ||
| 6 | +import org.slf4j.LoggerFactory; | ||
| 7 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| 8 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
| 9 | +import org.springframework.boot.builder.SpringApplicationBuilder; | ||
| 10 | +import org.springframework.context.annotation.ComponentScan; | ||
| 11 | +import org.springframework.context.annotation.FilterType; | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +@ComponentScan(basePackages = { | ||
| 15 | + "com.ruoyi.common.utils.spring", | ||
| 16 | + "com.zhonglai.luhui.device.protocol", | ||
| 17 | + "com.zhonglai.luhui.device.analysis.comm.config", | ||
| 18 | + "com.zhonglai.luhui.mqtt.service.proxy", | ||
| 19 | +},excludeFilters = @ComponentScan.Filter( | ||
| 20 | + type = FilterType.ASSIGNABLE_TYPE, | ||
| 21 | + classes = {CacheConfig.class, FastJson2JsonRedisSerializer.class} | ||
| 22 | +) ) | ||
| 23 | +@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) | ||
| 24 | +public class MqttServiceListenApplication { | ||
| 25 | + private static Logger log = LoggerFactory.getLogger(MqttServiceListenApplication.class); | ||
| 26 | + | ||
| 27 | + public static void main(String[] args) { | ||
| 28 | + log.info("启动服务"); | ||
| 29 | + SpringApplicationBuilder builder = new SpringApplicationBuilder(MqttServiceListenApplication.class); | ||
| 30 | + builder.run( args); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.service.proxy.comm.service; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 4 | +import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; | ||
| 6 | +import com.zhonglai.luhui.device.protocol.factory.comm.DataLogType; | ||
| 7 | +import com.zhonglai.luhui.device.protocol.factory.comm.DeviceDataLog; | ||
| 8 | +import com.zhonglai.luhui.device.protocol.factory.service.BaseCallback; | ||
| 9 | +import lombok.SneakyThrows; | ||
| 10 | +import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; | ||
| 11 | +import org.eclipse.paho.client.mqttv3.MqttCallbackExtended; | ||
| 12 | +import org.eclipse.paho.client.mqttv3.MqttException; | ||
| 13 | +import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
| 14 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 15 | +import org.springframework.stereotype.Component; | ||
| 16 | + | ||
| 17 | +@Component | ||
| 18 | +public class MqttCallback extends BaseCallback implements MqttCallbackExtended { | ||
| 19 | + | ||
| 20 | + private static final String topicOnlineModel = "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{imei}}/{{topicType}}"; | ||
| 21 | + | ||
| 22 | + @Autowired | ||
| 23 | + private TerminalService terminalService; //客户端服务 | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + @SneakyThrows | ||
| 27 | + @Override | ||
| 28 | + public void connectComplete(boolean b, String s) { | ||
| 29 | + // 连接成功 | ||
| 30 | + log.info("连接成功"); | ||
| 31 | + terminalService.subscribe(); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public void connectionLost(Throwable throwable) { | ||
| 36 | + //连接丢失 | ||
| 37 | + log.error("连接丢失",throwable); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public void messageArrived(String s, MqttMessage mqttMessage) { | ||
| 42 | + log.info("mqtt发来消息>>>>>>>:{} 《===============》 字符串:【{}】 十六进制:【{}】",s,mqttMessage.toString().replaceAll("\\n","").replaceAll("\\s", ""),ByteUtil.hexStringToSpace(ByteUtil.toHexString(mqttMessage.getPayload()))); | ||
| 43 | + | ||
| 44 | + Topic baseTopic = TopicUtil.initTopicFromModelStr(s,topicOnlineModel); //我们定义的topic | ||
| 45 | + | ||
| 46 | + DeviceDataLog.info(baseTopic.getClientid(), DataLogType.发来数据,s,mqttMessage.toString().replaceAll("\\n","").replaceAll("\\s", "")); | ||
| 47 | + | ||
| 48 | + try { | ||
| 49 | + //过滤在线消息 | ||
| 50 | + if (s.endsWith("online")) | ||
| 51 | + { | ||
| 52 | + String state = new String(mqttMessage.getPayload()); | ||
| 53 | + deviceCashUpService.upOnline(state); | ||
| 54 | + return ; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + messageArrived(baseTopic.getClientid(),s,mqttMessage.getPayload()); | ||
| 58 | + | ||
| 59 | + }catch (Exception e) | ||
| 60 | + { | ||
| 61 | + log.error(s+"解析失败",e); | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) { | ||
| 67 | + // 成功发出消息 | ||
| 68 | + try { | ||
| 69 | + DeviceDataLog.info(iMqttDeliveryToken.getClient().getClientId(),DataLogType.发送数据,null,iMqttDeliveryToken.getMessage()); | ||
| 70 | + } catch (MqttException e) { | ||
| 71 | + DeviceDataLog.info(iMqttDeliveryToken.getClient().getClientId(),DataLogType.发送数据,null,e.getMessage()); | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public MqttCallback binldTerminalService(TerminalService terminalService) | ||
| 76 | + { | ||
| 77 | + this.terminalService = terminalService; | ||
| 78 | + return this; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.service.proxy.comm.service; | ||
| 2 | + | ||
| 3 | +import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; | ||
| 4 | +import com.zhonglai.luhui.device.protocol.factory.service.impl.DefaultDbService; | ||
| 5 | +import org.eclipse.paho.client.mqttv3.MqttClient; | ||
| 6 | +import org.eclipse.paho.client.mqttv3.MqttConnectOptions; | ||
| 7 | +import org.eclipse.paho.client.mqttv3.MqttException; | ||
| 8 | +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; | ||
| 9 | +import org.slf4j.Logger; | ||
| 10 | +import org.slf4j.LoggerFactory; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.beans.factory.annotation.Value; | ||
| 13 | +import org.springframework.stereotype.Service; | ||
| 14 | + | ||
| 15 | +import javax.annotation.PostConstruct; | ||
| 16 | +import java.util.List; | ||
| 17 | +import java.util.concurrent.ExecutorService; | ||
| 18 | +import java.util.concurrent.LinkedBlockingQueue; | ||
| 19 | +import java.util.concurrent.ThreadPoolExecutor; | ||
| 20 | +import java.util.concurrent.TimeUnit; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * 终端服务 | ||
| 24 | + */ | ||
| 25 | +@Service | ||
| 26 | +public class TerminalService { | ||
| 27 | + private static final Logger log = LoggerFactory.getLogger(TerminalService.class); | ||
| 28 | + @Autowired | ||
| 29 | + private MqttCallback mqttCallback; | ||
| 30 | + | ||
| 31 | + @Autowired | ||
| 32 | + private DefaultDbService dbService; | ||
| 33 | + | ||
| 34 | + @Autowired | ||
| 35 | + private SysParameter sysParameter; | ||
| 36 | + | ||
| 37 | + | ||
| 38 | + //业务处理异步线程池,线程池参数可以根据您的业务特点调整,或者您也可以用其他异步方式处理接收到的消息。 | ||
| 39 | + private final static ExecutorService executorService = new ThreadPoolExecutor( | ||
| 40 | + Runtime.getRuntime().availableProcessors(), | ||
| 41 | + Runtime.getRuntime().availableProcessors() * 2, 60, TimeUnit.SECONDS, | ||
| 42 | + new LinkedBlockingQueue<>(50000)); | ||
| 43 | + | ||
| 44 | + @Value("${mqtt.broker}") | ||
| 45 | + private String broker; | ||
| 46 | + @Value("${mqtt.clientId}") | ||
| 47 | + private String clientId; | ||
| 48 | + @Value("${mqtt.username}") | ||
| 49 | + private String username; | ||
| 50 | + @Value("${mqtt.password}") | ||
| 51 | + private String password; | ||
| 52 | + | ||
| 53 | + private MqttClient mqttclient; | ||
| 54 | + | ||
| 55 | + private MqttConnectOptions options; | ||
| 56 | + | ||
| 57 | + private void init() throws MqttException { | ||
| 58 | + if(null == mqttclient) | ||
| 59 | + { | ||
| 60 | + mqttclient = new MqttClient(broker, clientId, new MemoryPersistence()); | ||
| 61 | + } | ||
| 62 | + options = new MqttConnectOptions(); | ||
| 63 | + options.setCleanSession(true); | ||
| 64 | + options.setConnectionTimeout(15); | ||
| 65 | + //设置断开后重新连接 | ||
| 66 | + options.setAutomaticReconnect(true); | ||
| 67 | + mqttclient.setCallback(mqttCallback.binldTerminalService(this)); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + private void connect() throws MqttException { | ||
| 71 | + options.setUserName(username); | ||
| 72 | + options.setPassword(password.toCharArray()); | ||
| 73 | + mqttclient.connect(options); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public List<String> subscribe() throws MqttException { | ||
| 77 | + List<String> ts = getCompletionTopics(); | ||
| 78 | + if(null != ts && ts.size() !=0) | ||
| 79 | + { | ||
| 80 | + mqttclient.subscribe(ts.toArray(new String[ts.size()])); | ||
| 81 | + } | ||
| 82 | + return ts; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public List<String> getCompletionTopics() | ||
| 86 | + { | ||
| 87 | + return dbService.getTopicFromRole(); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @PostConstruct | ||
| 91 | + public void startMqttListenerService() throws MqttException { | ||
| 92 | + log.info("-----------开始启动mqtt监听服务--------------------"); | ||
| 93 | + init(); | ||
| 94 | + log.info("-----------启动参数{}--------------------",options); | ||
| 95 | + sysParameter.inittopicconfig(); | ||
| 96 | + connect(); | ||
| 97 | + log.info("-----------mqtt连接服务器成功--------------------"); | ||
| 98 | + List<String> topics = subscribe(); | ||
| 99 | + log.info("-----------订阅{}成功--------------------",topics); | ||
| 100 | + | ||
| 101 | + } | ||
| 102 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.service.proxy.config; | ||
| 2 | + | ||
| 3 | +import io.swagger.annotations.ApiOperation; | ||
| 4 | +import org.springframework.context.annotation.Bean; | ||
| 5 | +import org.springframework.context.annotation.Configuration; | ||
| 6 | +import springfox.documentation.builders.ApiInfoBuilder; | ||
| 7 | +import springfox.documentation.builders.PathSelectors; | ||
| 8 | +import springfox.documentation.builders.RequestHandlerSelectors; | ||
| 9 | +import springfox.documentation.service.ApiInfo; | ||
| 10 | +import springfox.documentation.service.Contact; | ||
| 11 | +import springfox.documentation.spi.DocumentationType; | ||
| 12 | +import springfox.documentation.spring.web.plugins.Docket; | ||
| 13 | +import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +@Configuration | ||
| 17 | +@EnableSwagger2 | ||
| 18 | +public class SwaggerConfig { | ||
| 19 | + @Bean | ||
| 20 | + public Docket createRestApi() { | ||
| 21 | + return new Docket(DocumentationType.SWAGGER_2) | ||
| 22 | + .apiInfo(apiInfo()) | ||
| 23 | + .select() | ||
| 24 | + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) | ||
| 25 | + .paths(PathSelectors.any()) | ||
| 26 | + .build(); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 添加摘要信息 | ||
| 31 | + */ | ||
| 32 | + private ApiInfo apiInfo() | ||
| 33 | + { | ||
| 34 | + // 用ApiInfoBuilder进行定制 | ||
| 35 | + return new ApiInfoBuilder() | ||
| 36 | + // 设置标题 | ||
| 37 | + .title("标题:mqtt协议服务监听") | ||
| 38 | + // 描述 | ||
| 39 | + .description("描述:用于通过mqtt发送指令控制终端端操作") | ||
| 40 | + // 作者信息 | ||
| 41 | + .contact(new Contact("", null, null)) | ||
| 42 | + // 版本 | ||
| 43 | + .version("版本号:1.1.1" ) | ||
| 44 | + .build(); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | +} |
| 1 | +package com.zhonglai.luhui.mqtt.service.proxy.controller; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.alibaba.fastjson.util.IOUtils; | ||
| 5 | +import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; | ||
| 6 | +import com.zhonglai.luhui.device.analysis.dto.Message; | ||
| 7 | +import com.zhonglai.luhui.device.analysis.dto.MessageCode; | ||
| 8 | +import io.swagger.annotations.Api; | ||
| 9 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 10 | +import io.swagger.annotations.ApiImplicitParams; | ||
| 11 | +import io.swagger.annotations.ApiOperation; | ||
| 12 | +import org.springframework.stereotype.Controller; | ||
| 13 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 14 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 15 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
| 16 | + | ||
| 17 | +import javax.servlet.http.HttpServletResponse; | ||
| 18 | +import java.io.*; | ||
| 19 | +import java.util.Date; | ||
| 20 | +import java.util.zip.ZipEntry; | ||
| 21 | +import java.util.zip.ZipFile; | ||
| 22 | + | ||
| 23 | +@Api(tags = "设备操作") | ||
| 24 | +@Controller | ||
| 25 | +@RequestMapping("/log") | ||
| 26 | +public class LogController { | ||
| 27 | + @ApiOperation("获取一天的日志") | ||
| 28 | + @ApiImplicitParams({ | ||
| 29 | + @ApiImplicitParam(value = "时间(格式:20230114)",name = "time"), | ||
| 30 | + @ApiImplicitParam(value = "设备imei",name = "imei"), | ||
| 31 | + }) | ||
| 32 | + @RequestMapping(value = "getOneDateLog/{imei}/{time}",method = RequestMethod.GET) | ||
| 33 | + public void getOneDateLog(HttpServletResponse response, @PathVariable String imei, @PathVariable String time) throws IOException { | ||
| 34 | + response.setCharacterEncoding("UTF-8"); | ||
| 35 | + response.setHeader("Content-Type","text/html;charset=utf-8"); | ||
| 36 | + PrintWriter printWriter = response.getWriter(); | ||
| 37 | + String dateString = DateUtils.parseDateToStr("yyyyMMdd",new Date()); | ||
| 38 | + String fileName= imei+"_"+time+".log"; | ||
| 39 | + if(dateString.equals(time)) | ||
| 40 | + { | ||
| 41 | + File logsFile = new File("logs/"+fileName); | ||
| 42 | + if (!logsFile.exists()) | ||
| 43 | + { | ||
| 44 | + printWriter.println(JSON.toJSONString(new Message(MessageCode.DEFAULT_FAIL_CODE,"文件"+logsFile.getPath()+"不存在"))); | ||
| 45 | + } | ||
| 46 | + BufferedReader reader = null; | ||
| 47 | + try { | ||
| 48 | + reader = new BufferedReader(new FileReader(logsFile)); | ||
| 49 | + String line; | ||
| 50 | + while((line = reader.readLine()) != null){ | ||
| 51 | + printWriter.println(line); | ||
| 52 | + printWriter.println("<br/>"); | ||
| 53 | + } | ||
| 54 | + } catch (IOException e) { | ||
| 55 | + e.printStackTrace(); | ||
| 56 | + }finally { | ||
| 57 | + IOUtils.close(printWriter); | ||
| 58 | + IOUtils.close(reader); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + } | ||
| 62 | + File logsFile = new File("zip/"+time+".zip"); | ||
| 63 | + BufferedReader reader = null; | ||
| 64 | + try { | ||
| 65 | + ZipFile zipFile = new ZipFile(logsFile); | ||
| 66 | + reader = new BufferedReader(new InputStreamReader(zipFile.getInputStream(new ZipEntry(fileName)))); | ||
| 67 | + String line; | ||
| 68 | + while((line = reader.readLine()) != null) | ||
| 69 | + { | ||
| 70 | + printWriter.println(line); | ||
| 71 | + printWriter.println("<br/>"); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + } catch (IOException e) { | ||
| 75 | + printWriter.println(JSON.toJSONString(new Message(MessageCode.DEFAULT_FAIL_CODE,e.getMessage()))); | ||
| 76 | + }finally { | ||
| 77 | + IOUtils.close(printWriter); | ||
| 78 | + IOUtils.close(reader); | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | +} |
| 1 | +##服务器配置 | ||
| 2 | +server: | ||
| 3 | + tomcat: | ||
| 4 | + uri-encoding: UTF-8 | ||
| 5 | + port: 4885 | ||
| 6 | + servlet: | ||
| 7 | + context-path: / | ||
| 8 | + | ||
| 9 | +spring: | ||
| 10 | + messages: | ||
| 11 | + encoding: UTF-8 | ||
| 12 | + mvc: | ||
| 13 | + #出现错误时, 直接抛出异常 | ||
| 14 | + throw-exception-if-no-handler-found: true | ||
| 15 | + jackson: | ||
| 16 | + date-format: yyyy-MM-dd HH:mm:ss | ||
| 17 | + time-zone: GMT+8 | ||
| 18 | + default-property-inclusion: non_null | ||
| 19 | + | ||
| 20 | +mqtt: | ||
| 21 | + #链接地址 | ||
| 22 | + broker: tcp://175.24.61.68:1883 | ||
| 23 | + #唯一标识 | ||
| 24 | + clientId: ${random.uuid} | ||
| 25 | + topicconfig: "/{{roleid}}/{{username}}/{{clientid}}/{{payloadtype}}/{{topicType}}/{{messageid}}" | ||
| 26 | + username: sysuser | ||
| 27 | + password: "!@#1qaz" | ||
| 28 | + client: | ||
| 29 | + #客户端操作时间 | ||
| 30 | + operationTime: 10 |
| 1 | +log4j.rootLogger=INFO,indicator,FILE | ||
| 2 | + | ||
| 3 | +log4j.appender.indicator=org.apache.log4j.ConsoleAppender | ||
| 4 | +log4j.appender.indicator.layout=org.apache.log4j.PatternLayout | ||
| 5 | +log4j.appender.indicator.layout.ConversionPattern=%d{HH:mm:ss} [%p] %l -%m%n | ||
| 6 | + | ||
| 7 | +log4j.appender.FILE = org.apache.log4j.RollingFileAppender | ||
| 8 | +log4j.appender.FILE.File = logs/output.log | ||
| 9 | +log4j.appender.FILE.MaxFileSize = 2000KB | ||
| 10 | +log4j.appender.FILE.MaxBackupIndex = 5 | ||
| 11 | +log4j.appender.FILE.layout = org.apache.log4j.PatternLayout | ||
| 12 | +log4j.appender.FILE.layout.ConversionPattern = %d{HH:mm:ss} [%p] %l -%m%n | ||
| 13 | + | ||
| 14 | +log4j.logger.myDatalog= INFO, datalog | ||
| 15 | +log4j.additivity.myDatalog = false | ||
| 16 | +log4j.appender.datalog = org.apache.log4j.RollingFileAppender | ||
| 17 | +log4j.appender.datalog.File = datalog/output.log | ||
| 18 | +log4j.appender.datalog.MaxFileSize = 2000KB | ||
| 19 | +log4j.appender.datalog.MaxBackupIndex = 5 | ||
| 20 | +log4j.appender.datalog.layout = org.apache.log4j.PatternLayout | ||
| 21 | +log4j.appender.datalog.layout.ConversionPattern = %d{HH:mm:ss} [%p] %l -%m%n |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | + | ||
| 3 | +<assembly> | ||
| 4 | + <id>bin</id> | ||
| 5 | + <!-- 最终打包成一个用于发布的zip文件 --> | ||
| 6 | + <formats> | ||
| 7 | + <format>zip</format> | ||
| 8 | + </formats> | ||
| 9 | + | ||
| 10 | + <!-- Adds dependencies to zip package under lib directory --> | ||
| 11 | + <dependencySets> | ||
| 12 | + <dependencySet> | ||
| 13 | + <!-- | ||
| 14 | + 不使用项目的artifact,第三方jar不要解压,打包进zip文件的lib目录 | ||
| 15 | + --> | ||
| 16 | + <useProjectArtifact>false</useProjectArtifact> | ||
| 17 | + <outputDirectory>lib</outputDirectory> | ||
| 18 | + <unpack>false</unpack> | ||
| 19 | + </dependencySet> | ||
| 20 | + </dependencySets> | ||
| 21 | + | ||
| 22 | + <fileSets> | ||
| 23 | + <!-- 把项目相关的说明文件,打包进zip文件的根目录 --> | ||
| 24 | + <fileSet> | ||
| 25 | + <directory>${project.basedir}</directory> | ||
| 26 | + <outputDirectory>/</outputDirectory> | ||
| 27 | + <includes> | ||
| 28 | + <include>README*</include> | ||
| 29 | + <include>LICENSE*</include> | ||
| 30 | + <include>NOTICE*</include> | ||
| 31 | + </includes> | ||
| 32 | + </fileSet> | ||
| 33 | + | ||
| 34 | + <!-- 把项目的配置文件,打包进zip文件的config目录 --> | ||
| 35 | + <fileSet> | ||
| 36 | + <directory>${project.basedir}\src\main\resources\configs</directory> | ||
| 37 | + <outputDirectory>../configs</outputDirectory> | ||
| 38 | + <includes> | ||
| 39 | + <include>*.properties</include> | ||
| 40 | + </includes> | ||
| 41 | + </fileSet> | ||
| 42 | + | ||
| 43 | + <!-- 把项目的配置文件,提出来 --> | ||
| 44 | + <fileSet> | ||
| 45 | + <directory>${project.basedir}\src\main\resources</directory> | ||
| 46 | + <outputDirectory>/</outputDirectory> | ||
| 47 | + <includes> | ||
| 48 | + <include>*.properties</include> | ||
| 49 | + <include>*.yml</include> | ||
| 50 | + </includes> | ||
| 51 | + </fileSet> | ||
| 52 | + | ||
| 53 | + <!-- 把项目的脚本文件目录( src/main/scripts )中的启动脚本文件,打包进zip文件的跟目录 --> | ||
| 54 | + <fileSet> | ||
| 55 | + <directory>${project.basedir}\bin</directory> | ||
| 56 | + <outputDirectory></outputDirectory> | ||
| 57 | + <includes> | ||
| 58 | + <include>start.*</include> | ||
| 59 | + <include>stop.*</include> | ||
| 60 | + </includes> | ||
| 61 | + </fileSet> | ||
| 62 | + | ||
| 63 | + <!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 --> | ||
| 64 | + <fileSet> | ||
| 65 | + <directory>${project.build.directory}</directory> | ||
| 66 | + <outputDirectory></outputDirectory> | ||
| 67 | + <includes> | ||
| 68 | + <include>*.jar</include> | ||
| 69 | + </includes> | ||
| 70 | + </fileSet> | ||
| 71 | + </fileSets> | ||
| 72 | +</assembly> |
| 1 | package com.zhonglai.luhui.mqtt; | 1 | package com.zhonglai.luhui.mqtt; |
| 2 | 2 | ||
| 3 | -import com.ruoyi.common.utils.GsonConstructor; | ||
| 4 | -import com.zhonglai.luhui.device.analysis.comm.service.redis.RedisService; | ||
| 5 | -import com.zhonglai.luhui.mqtt.comm.service.TerminalService; | ||
| 6 | -import com.zhonglai.luhui.mqtt.service.ClienNoticeService; | 3 | +import com.zhonglai.luhui.redis.service.RedisService; |
| 7 | import org.slf4j.Logger; | 4 | import org.slf4j.Logger; |
| 8 | import org.slf4j.LoggerFactory; | 5 | import org.slf4j.LoggerFactory; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -12,10 +9,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | @@ -12,10 +9,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
| 12 | import org.springframework.boot.builder.SpringApplicationBuilder; | 9 | import org.springframework.boot.builder.SpringApplicationBuilder; |
| 13 | import org.springframework.context.annotation.ComponentScan; | 10 | import org.springframework.context.annotation.ComponentScan; |
| 14 | 11 | ||
| 15 | -import javax.annotation.PostConstruct; | ||
| 16 | -import java.util.HashMap; | ||
| 17 | -import java.util.Map; | ||
| 18 | - | ||
| 19 | 12 | ||
| 20 | @ComponentScan(basePackages = { | 13 | @ComponentScan(basePackages = { |
| 21 | "com.zhonglai.luhui.device.analysis", | 14 | "com.zhonglai.luhui.device.analysis", |
| @@ -28,8 +21,6 @@ import java.util.Map; | @@ -28,8 +21,6 @@ import java.util.Map; | ||
| 28 | @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) | 21 | @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) |
| 29 | public class MqttApplication { | 22 | public class MqttApplication { |
| 30 | private static Logger log = LoggerFactory.getLogger(MqttApplication.class); | 23 | private static Logger log = LoggerFactory.getLogger(MqttApplication.class); |
| 31 | - @Autowired | ||
| 32 | - private RedisService redisService ; | ||
| 33 | 24 | ||
| 34 | public static void main(String[] args) { | 25 | public static void main(String[] args) { |
| 35 | log.info("启动服务"); | 26 | log.info("启动服务"); |
| 1 | -package com.zhonglai.luhui.mqtt; | ||
| 2 | - | ||
| 3 | -import com.ruoyi.common.utils.GsonConstructor; | ||
| 4 | -import redis.clients.jedis.Jedis; | ||
| 5 | - | ||
| 6 | -import java.util.HashMap; | ||
| 7 | -import java.util.Map; | ||
| 8 | - | ||
| 9 | -public class Test { | ||
| 10 | - public static void main(String[] args) { | ||
| 11 | - Jedis jedis = new Jedis("47.112.163.61",9527); | ||
| 12 | - jedis.auth("Luhui586"); | ||
| 13 | - jedis.select(1); | ||
| 14 | - | ||
| 15 | - // 连接Redis并检查连接状态 | ||
| 16 | - String pingResponse = jedis.ping(); | ||
| 17 | - System.out.println("Ping Response: " + pingResponse); | ||
| 18 | - | ||
| 19 | - Map<String,String> map = new HashMap<>(); | ||
| 20 | - map.put("deviceName","SC-M8 号"); | ||
| 21 | - String key ="ly:x6:devices:866838067734877_1_1"; | ||
| 22 | - System.out.println(GsonConstructor.get().toJson(jedis.hmget(key,"deviceName")));; | ||
| 23 | - | ||
| 24 | - jedis.hmset(key,map); | ||
| 25 | -// // 更新Redis中的key-value数据 | ||
| 26 | -// jedis.set("key", "newValue"); | 1 | +//package com.zhonglai.luhui.mqtt; |
| 27 | // | 2 | // |
| 28 | -// // 获取并输出更新后的值 | ||
| 29 | -// String value = jedis.get("key"); | ||
| 30 | -// System.out.println("Updated Value: " + value); | ||
| 31 | - | ||
| 32 | - // 关闭连接 | ||
| 33 | - jedis.close(); | ||
| 34 | - } | ||
| 35 | -} | 3 | +//import com.ruoyi.common.utils.GsonConstructor; |
| 4 | +//import redis.clients.jedis.Jedis; | ||
| 5 | +// | ||
| 6 | +//import java.util.HashMap; | ||
| 7 | +//import java.util.Map; | ||
| 8 | +// | ||
| 9 | +//public class Test { | ||
| 10 | +// public static void main(String[] args) { | ||
| 11 | +// Jedis jedis = new Jedis("47.112.163.61",9527); | ||
| 12 | +// jedis.auth("Luhui586"); | ||
| 13 | +// jedis.select(1); | ||
| 14 | +// | ||
| 15 | +// // 连接Redis并检查连接状态 | ||
| 16 | +// String pingResponse = jedis.ping(); | ||
| 17 | +// System.out.println("Ping Response: " + pingResponse); | ||
| 18 | +// | ||
| 19 | +// Map<String,String> map = new HashMap<>(); | ||
| 20 | +// map.put("deviceName","SC-M8 号"); | ||
| 21 | +// String key ="ly:x6:devices:866838067734877_1_1"; | ||
| 22 | +// System.out.println(GsonConstructor.get().toJson(jedis.hmget(key,"deviceName")));; | ||
| 23 | +// | ||
| 24 | +// jedis.hmset(key,map); | ||
| 25 | +//// // 更新Redis中的key-value数据 | ||
| 26 | +//// jedis.set("key", "newValue"); | ||
| 27 | +//// | ||
| 28 | +//// // 获取并输出更新后的值 | ||
| 29 | +//// String value = jedis.get("key"); | ||
| 30 | +//// System.out.println("Updated Value: " + value); | ||
| 31 | +// | ||
| 32 | +// // 关闭连接 | ||
| 33 | +// jedis.close(); | ||
| 34 | +// } | ||
| 35 | +//} |
| 1 | package com.zhonglai.luhui.mqtt.comm.rocketMq; | 1 | package com.zhonglai.luhui.mqtt.comm.rocketMq; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | -import com.zhonglai.luhui.device.analysis.comm.db.DeviceService; | ||
| 5 | import com.zhonglai.luhui.mqtt.comm.service.DeviceCommandApi; | 4 | import com.zhonglai.luhui.mqtt.comm.service.DeviceCommandApi; |
| 6 | import com.zhonglai.luhui.device.analysis.dto.Message; | 5 | import com.zhonglai.luhui.device.analysis.dto.Message; |
| 7 | import com.zhonglai.luhui.device.analysis.dto.MessageCode; | 6 | import com.zhonglai.luhui.device.analysis.dto.MessageCode; |
| 8 | import com.zhonglai.luhui.mqtt.comm.service.MqttDeviceService; | 7 | import com.zhonglai.luhui.mqtt.comm.service.MqttDeviceService; |
| 9 | import org.apache.rocketmq.common.message.MessageExt; | 8 | import org.apache.rocketmq.common.message.MessageExt; |
| 9 | +import org.apache.rocketmq.spring.annotation.ConsumeMode; | ||
| 10 | import org.apache.rocketmq.spring.annotation.MessageModel; | 10 | import org.apache.rocketmq.spring.annotation.MessageModel; |
| 11 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; | 11 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; |
| 12 | import org.apache.rocketmq.spring.annotation.SelectorType; | 12 | import org.apache.rocketmq.spring.annotation.SelectorType; |
| @@ -18,7 +18,7 @@ import org.springframework.stereotype.Service; | @@ -18,7 +18,7 @@ import org.springframework.stereotype.Service; | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | @Service | 20 | @Service |
| 21 | -@RocketMQMessageListener(consumerGroup = "deviceCommand", topic = "${rocketmq.send-topic:}",selectorType = SelectorType.TAG,selectorExpression = "${rocketmq.send-tag:}",messageModel = MessageModel.BROADCASTING) | 21 | +@RocketMQMessageListener(consumerGroup = "deviceCommand3", topic = "${rocketmq.send-topic:}",selectorType = SelectorType.TAG,selectorExpression = "${rocketmq.send-tag:}",messageModel = MessageModel.BROADCASTING) |
| 22 | public class RocketMqService implements RocketMQReplyListener<MessageExt, Message> { | 22 | public class RocketMqService implements RocketMQReplyListener<MessageExt, Message> { |
| 23 | private static final Logger log = LoggerFactory.getLogger(RocketMqService.class); | 23 | private static final Logger log = LoggerFactory.getLogger(RocketMqService.class); |
| 24 | 24 | ||
| @@ -34,7 +34,9 @@ public class RocketMqService implements RocketMQReplyListener<MessageExt, Messag | @@ -34,7 +34,9 @@ public class RocketMqService implements RocketMQReplyListener<MessageExt, Messag | ||
| 34 | log.info("消息body{}",str); | 34 | log.info("消息body{}",str); |
| 35 | DeviceCommandApi deviceCommandApi = JSON.parseObject(str, DeviceCommandApi.class); | 35 | DeviceCommandApi deviceCommandApi = JSON.parseObject(str, DeviceCommandApi.class); |
| 36 | try { | 36 | try { |
| 37 | - return deviceCommandApi.invokeApi(deviceService); | 37 | + Message message = deviceCommandApi.invokeApi(deviceService); |
| 38 | + log.info("{} 指令执行完以后返回的结果{}",deviceCommandApi.getDeviceCommandApiParameter().getClient_id(),message); | ||
| 39 | + return message; | ||
| 38 | } catch (Exception e) { | 40 | } catch (Exception e) { |
| 39 | log.error("执行异常",e); | 41 | log.error("执行异常",e); |
| 40 | } | 42 | } |
| @@ -11,7 +11,7 @@ import com.zhonglai.luhui.device.domain.IotDevice; | @@ -11,7 +11,7 @@ import com.zhonglai.luhui.device.domain.IotDevice; | ||
| 11 | import com.zhonglai.luhui.device.analysis.comm.factory.BusinessAgreement; | 11 | import com.zhonglai.luhui.device.analysis.comm.factory.BusinessAgreement; |
| 12 | import com.zhonglai.luhui.device.analysis.comm.factory.BusinessAgreementFactory; | 12 | import com.zhonglai.luhui.device.analysis.comm.factory.BusinessAgreementFactory; |
| 13 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 13 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 14 | -import com.zhonglai.luhui.mqtt.comm.util.TopicUtil; | 14 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; |
| 15 | import com.zhonglai.luhui.device.analysis.comm.db.DeviceService; | 15 | import com.zhonglai.luhui.device.analysis.comm.db.DeviceService; |
| 16 | import lombok.SneakyThrows; | 16 | import lombok.SneakyThrows; |
| 17 | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; | 17 | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; |
lh-modules/lh-mqtt-service/src/main/java/com/zhonglai/luhui/mqtt/comm/service/MqttDeviceService.java
| @@ -2,6 +2,8 @@ package com.zhonglai.luhui.mqtt.comm.service; | @@ -2,6 +2,8 @@ package com.zhonglai.luhui.mqtt.comm.service; | ||
| 2 | 2 | ||
| 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.google.gson.JsonObject; | ||
| 6 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | import com.zhonglai.luhui.device.analysis.comm.db.DeviceService; | 7 | import com.zhonglai.luhui.device.analysis.comm.db.DeviceService; |
| 6 | import com.zhonglai.luhui.device.analysis.comm.db.mode.TerminalDataThingsModeService; | 8 | import com.zhonglai.luhui.device.analysis.comm.db.mode.TerminalDataThingsModeService; |
| 7 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | 9 | import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; |
| @@ -110,6 +112,9 @@ public class MqttDeviceService extends DeviceService{ | @@ -110,6 +112,9 @@ public class MqttDeviceService extends DeviceService{ | ||
| 110 | { | 112 | { |
| 111 | Object sendMap = map.get(key); | 113 | Object sendMap = map.get(key); |
| 112 | JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(sendMap)); | 114 | JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(sendMap)); |
| 115 | + | ||
| 116 | + JsonObject gsonobject = GsonConstructor.get().fromJson(JSONObject.toJSONString(sendMap),JsonObject.class); | ||
| 117 | + | ||
| 113 | for(String skey:jsonObject.keySet()) | 118 | for(String skey:jsonObject.keySet()) |
| 114 | { | 119 | { |
| 115 | IotThingsModel thingsModel = terminalDataThingsModeService.getIotThingsModel(topic.getUsername(),skey); | 120 | IotThingsModel thingsModel = terminalDataThingsModeService.getIotThingsModel(topic.getUsername(),skey); |
| @@ -128,18 +133,22 @@ public class MqttDeviceService extends DeviceService{ | @@ -128,18 +133,22 @@ public class MqttDeviceService extends DeviceService{ | ||
| 128 | thingsModel.setSpecs(spes.toString()); | 133 | thingsModel.setSpecs(spes.toString()); |
| 129 | } | 134 | } |
| 130 | String data_type = thingsModel.getData_type().toUpperCase(); | 135 | String data_type = thingsModel.getData_type().toUpperCase(); |
| 131 | - Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class,data_type).getaClass(); | ||
| 132 | - ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(),aClass); | ||
| 133 | - thingsModelBase.conversionThingsModel(thingsModel); | 136 | +// Class<ThingsModelBase> aClass = Enum.valueOf(ThingsModelDataTypeEnum.class,data_type).getaClass(); |
| 137 | +// ThingsModelBase thingsModelBase = JSON.parseObject(thingsModel.getSpecs(),aClass); | ||
| 138 | +// thingsModelBase.conversionThingsModel(thingsModel); | ||
| 134 | Object object = jsonObject.get(skey); | 139 | Object object = jsonObject.get(skey); |
| 135 | // Type clas = ((ParameterizedType)aClass.getGenericSuperclass()).getActualTypeArguments()[0]; | 140 | // Type clas = ((ParameterizedType)aClass.getGenericSuperclass()).getActualTypeArguments()[0]; |
| 136 | // if(null != object && object.getClass()!=clas) | 141 | // if(null != object && object.getClass()!=clas) |
| 137 | // { | 142 | // { |
| 138 | // return new Message(MessageCode.DEFAULT_FAIL_CODE,skey+" 参数数据类型和模型数据类型("+clas+")不一致"); | 143 | // return new Message(MessageCode.DEFAULT_FAIL_CODE,skey+" 参数数据类型和模型数据类型("+clas+")不一致"); |
| 139 | // } | 144 | // } |
| 140 | - ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase; | 145 | +// ThingsModelItemBase thingsModelItemBase = (ThingsModelItemBase) thingsModelBase; |
| 146 | + | ||
| 147 | + ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(Enum.valueOf(ThingsModelDataTypeEnum.class,data_type),thingsModel,gsonobject.get(skey)); | ||
| 148 | + | ||
| 141 | jsonObject.put(skey,thingsModelItemBase.getCmdView(object)); | 149 | jsonObject.put(skey,thingsModelItemBase.getCmdView(object)); |
| 142 | - thingsModelBase.addValue(thingsModelItemBase.getCmdView(object)); | 150 | + thingsModelItemBase.setValue(thingsModelItemBase.getCmdView(object)); |
| 151 | + | ||
| 143 | String id = clienid+"_"+key; | 152 | String id = clienid+"_"+key; |
| 144 | logDeviceOperationList.add(dviceLogService.newLogDeviceOperation(id,thingsModelItemBase.getSaveView(),null,"远程控制"+thingsModelItemBase.getName()+"为"+thingsModelItemBase.getView(),null)); | 153 | logDeviceOperationList.add(dviceLogService.newLogDeviceOperation(id,thingsModelItemBase.getSaveView(),null,"远程控制"+thingsModelItemBase.getName()+"为"+thingsModelItemBase.getView(),null)); |
| 145 | } | 154 | } |
| @@ -3,7 +3,7 @@ package com.zhonglai.luhui.mqtt.comm.service; | @@ -3,7 +3,7 @@ package com.zhonglai.luhui.mqtt.comm.service; | ||
| 3 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 3 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 4 | import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; | 4 | import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; |
| 5 | import com.zhonglai.luhui.device.analysis.comm.service.DataModeAnalysisService; | 5 | import com.zhonglai.luhui.device.analysis.comm.service.DataModeAnalysisService; |
| 6 | -import com.zhonglai.luhui.mqtt.comm.util.TopicUtil; | 6 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; |
| 7 | import org.apache.commons.lang3.StringUtils; | 7 | import org.apache.commons.lang3.StringUtils; |
| 8 | import org.eclipse.paho.client.mqttv3.MqttClient; | 8 | import org.eclipse.paho.client.mqttv3.MqttClient; |
| 9 | import org.eclipse.paho.client.mqttv3.MqttConnectOptions; | 9 | import org.eclipse.paho.client.mqttv3.MqttConnectOptions; |
| @@ -8,7 +8,7 @@ import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; | @@ -8,7 +8,7 @@ import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; | ||
| 8 | import com.zhonglai.luhui.device.analysis.dto.Message; | 8 | import com.zhonglai.luhui.device.analysis.dto.Message; |
| 9 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 9 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 10 | import com.zhonglai.luhui.mqtt.comm.service.TerminalService; | 10 | import com.zhonglai.luhui.mqtt.comm.service.TerminalService; |
| 11 | -import com.zhonglai.luhui.mqtt.comm.util.TopicUtil; | 11 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; |
| 12 | import net.jodah.expiringmap.ExpirationListener; | 12 | import net.jodah.expiringmap.ExpirationListener; |
| 13 | import net.jodah.expiringmap.ExpirationPolicy; | 13 | import net.jodah.expiringmap.ExpirationPolicy; |
| 14 | import net.jodah.expiringmap.ExpiringMap; | 14 | import net.jodah.expiringmap.ExpiringMap; |
| @@ -12,7 +12,7 @@ import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | @@ -12,7 +12,7 @@ import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 12 | import com.zhonglai.luhui.mqtt.service.ClienNoticeService; | 12 | import com.zhonglai.luhui.mqtt.service.ClienNoticeService; |
| 13 | import com.zhonglai.luhui.device.analysis.comm.util.StringUtils; | 13 | import com.zhonglai.luhui.device.analysis.comm.util.StringUtils; |
| 14 | import com.zhonglai.luhui.device.analysis.dto.topic.GetDto; | 14 | import com.zhonglai.luhui.device.analysis.dto.topic.GetDto; |
| 15 | -import com.zhonglai.luhui.mqtt.comm.util.TopicUtil; | 15 | +import com.zhonglai.luhui.device.analysis.util.TopicUtil; |
| 16 | import org.springframework.beans.BeanUtils; | 16 | import org.springframework.beans.BeanUtils; |
| 17 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 18 | import org.springframework.stereotype.Service; | 18 | import org.springframework.stereotype.Service; |
| @@ -28,6 +28,9 @@ | @@ -28,6 +28,9 @@ | ||
| 28 | <module>lh-http-service</module> | 28 | <module>lh-http-service</module> |
| 29 | <module>lh-data-file-service</module> | 29 | <module>lh-data-file-service</module> |
| 30 | <module>lh-lsy-plc-service</module> | 30 | <module>lh-lsy-plc-service</module> |
| 31 | + <module>lh-http-service-proxy</module> | ||
| 32 | + <module>lh-mqtt-service-listen</module> | ||
| 33 | + <module>lh-device-protocol-parser</module> | ||
| 31 | </modules> | 34 | </modules> |
| 32 | 35 | ||
| 33 | <properties> | 36 | <properties> |
| @@ -265,6 +265,13 @@ | @@ -265,6 +265,13 @@ | ||
| 265 | <version>${ruoyi.version}</version> | 265 | <version>${ruoyi.version}</version> |
| 266 | </dependency> | 266 | </dependency> |
| 267 | 267 | ||
| 268 | + <!-- dbcp实现的公用dao趁层 --> | ||
| 269 | + <dependency> | ||
| 270 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 271 | + <artifactId>lh-service-dao</artifactId> | ||
| 272 | + <version>${ruoyi.version}</version> | ||
| 273 | + </dependency> | ||
| 274 | + | ||
| 268 | <!-- 系统服务 --> | 275 | <!-- 系统服务 --> |
| 269 | <dependency> | 276 | <dependency> |
| 270 | <groupId>com.zhonglai.luhui</groupId> | 277 | <groupId>com.zhonglai.luhui</groupId> |
| @@ -348,6 +355,24 @@ | @@ -348,6 +355,24 @@ | ||
| 348 | </dependency> | 355 | </dependency> |
| 349 | 356 | ||
| 350 | <dependency> | 357 | <dependency> |
| 358 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 359 | + <artifactId>lh-device-protocol-factory</artifactId> | ||
| 360 | + <version>${ruoyi.version}</version> | ||
| 361 | + </dependency> | ||
| 362 | + | ||
| 363 | + <dependency> | ||
| 364 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 365 | + <artifactId>lh-device-xinjie</artifactId> | ||
| 366 | + <version>${ruoyi.version}</version> | ||
| 367 | + </dependency> | ||
| 368 | + | ||
| 369 | + <dependency> | ||
| 370 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 371 | + <artifactId>lh-device-http-public</artifactId> | ||
| 372 | + <version>${ruoyi.version}</version> | ||
| 373 | + </dependency> | ||
| 374 | + | ||
| 375 | + <dependency> | ||
| 351 | <groupId>com.zhonglai</groupId> | 376 | <groupId>com.zhonglai</groupId> |
| 352 | <artifactId>ServiceDao</artifactId> | 377 | <artifactId>ServiceDao</artifactId> |
| 353 | <version>1.4.3</version> | 378 | <version>1.4.3</version> |
| @@ -367,6 +392,12 @@ | @@ -367,6 +392,12 @@ | ||
| 367 | <version>${fastjson.version}</version> | 392 | <version>${fastjson.version}</version> |
| 368 | </dependency> | 393 | </dependency> |
| 369 | 394 | ||
| 395 | + <dependency> | ||
| 396 | + <groupId>redis.clients</groupId> | ||
| 397 | + <artifactId>jedis</artifactId> | ||
| 398 | + <version>3.6.3</version> | ||
| 399 | + </dependency> | ||
| 400 | + | ||
| 370 | <!-- 文档 --> | 401 | <!-- 文档 --> |
| 371 | <dependency> | 402 | <dependency> |
| 372 | <groupId>io.springfox</groupId> | 403 | <groupId>io.springfox</groupId> |
| @@ -461,12 +492,6 @@ | @@ -461,12 +492,6 @@ | ||
| 461 | </dependency> | 492 | </dependency> |
| 462 | 493 | ||
| 463 | <dependency> | 494 | <dependency> |
| 464 | - <groupId>redis.clients</groupId> | ||
| 465 | - <artifactId>jedis</artifactId> | ||
| 466 | - <version>3.6.3</version> | ||
| 467 | - </dependency> | ||
| 468 | - | ||
| 469 | - <dependency> | ||
| 470 | <groupId>org.apache.rocketmq</groupId> | 495 | <groupId>org.apache.rocketmq</groupId> |
| 471 | <artifactId>rocketmq-spring-boot-starter</artifactId> | 496 | <artifactId>rocketmq-spring-boot-starter</artifactId> |
| 472 | <version>2.1.1</version> | 497 | <version>2.1.1</version> |
| @@ -479,6 +504,11 @@ | @@ -479,6 +504,11 @@ | ||
| 479 | </dependency> | 504 | </dependency> |
| 480 | 505 | ||
| 481 | <dependency> | 506 | <dependency> |
| 507 | + <groupId>io.netty</groupId> | ||
| 508 | + <artifactId>netty-all</artifactId> | ||
| 509 | + <version>4.1.77.Final</version> | ||
| 510 | + </dependency> | ||
| 511 | + <dependency> | ||
| 482 | <groupId>cn.hutool</groupId> | 512 | <groupId>cn.hutool</groupId> |
| 483 | <artifactId>hutool-all</artifactId> | 513 | <artifactId>hutool-all</artifactId> |
| 484 | <version>5.8.14</version> | 514 | <version>5.8.14</version> |
| @@ -533,6 +563,12 @@ | @@ -533,6 +563,12 @@ | ||
| 533 | <artifactId>influxdb-client-java</artifactId> | 563 | <artifactId>influxdb-client-java</artifactId> |
| 534 | <version>6.12.0</version> | 564 | <version>6.12.0</version> |
| 535 | </dependency> | 565 | </dependency> |
| 566 | + | ||
| 567 | + <dependency> | ||
| 568 | + <groupId>com.aliyun</groupId> | ||
| 569 | + <artifactId>alibabacloud-dysmsapi20170525</artifactId> | ||
| 570 | + <version>2.0.24</version> | ||
| 571 | + </dependency> | ||
| 536 | </dependencies> | 572 | </dependencies> |
| 537 | 573 | ||
| 538 | 574 |
-
请 注册 或 登录 后发表评论