diff --git a/zlt-business/user-center/src/main/java/com/central/user/mapper/SysTenantMapper.java b/zlt-business/user-center/src/main/java/com/central/user/mapper/SysTenantMapper.java new file mode 100644 index 00000000..de3d92ac --- /dev/null +++ b/zlt-business/user-center/src/main/java/com/central/user/mapper/SysTenantMapper.java @@ -0,0 +1,10 @@ +import com.central.db.mapper.SuperMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Map; + +@Mapper +public interface SysTenantMapper extends SuperMapper { + List findList(Page page, @Param("t") Map params); +} diff --git a/zlt-business/user-center/src/main/java/com/central/user/model/SysTenant.java b/zlt-business/user-center/src/main/java/com/central/user/model/SysTenant.java new file mode 100644 index 00000000..035e1087 --- /dev/null +++ b/zlt-business/user-center/src/main/java/com/central/user/model/SysTenant.java @@ -0,0 +1,56 @@ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sys_tenant") +public class SysTenant extends SuperEntity { + private static final long serialVersionUID = 1L; + + /** + * 租户名称 + */ + private String name; + + /** + * 租户编码 + */ + private String code; + + /** + * 租户状态:0-禁用,1-正常 + */ + private Integer status; + + /** + * 租户类型:1-免费版,2-标准版,3-企业版 + */ + private Integer type; + + /** + * 开始时间 + */ + private Date startTime; + + /** + * 结束时间 + */ + private Date endTime; + + /** + * 联系人 + */ + private String contactName; + + /** + * 联系电话 + */ + private String contactPhone; + + /** + * 联系邮箱 + */ + private String contactEmail; + + /** + * 备注 + */ + private String remark; +} diff --git a/zlt-commons/zlt-iot-spring-boot-starter/pom.xml b/zlt-commons/zlt-iot-spring-boot-starter/pom.xml deleted file mode 100644 index 3324b470..00000000 --- a/zlt-commons/zlt-iot-spring-boot-starter/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - com.zlt - zlt-commons - 6.0.0 - - 4.0.0 - jar - zlt-iot-spring-boot-starter - iot通用组件 - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.java-websocket - Java-WebSocket - 1.5.7 - - - cn.hutool - hutool-all - - - com.alibaba - fastjson - 2.0.51 - - - - diff --git a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTConfiguration.java b/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTConfiguration.java deleted file mode 100644 index 58207525..00000000 --- a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTConfiguration.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.central.common.iot; - -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * iot 自动配置 - * - * @author wangpeijie - * @date 2024/11/19 - */ -@Configuration -class IoTConfiguration { - - /** - * iot v1版本配置 - * - * @return - */ - @Bean("iotProperties") - @ConditionalOnProperty(name = "jetlinks.version", havingValue = "1.0") - @ConfigurationProperties(prefix = "jetlinks.server.v1") - public IoTProperties iotPropertiesV1() { - return new IoTProperties(); - } - - /** - * iot v2版本配置 - * - * @return - */ - @Bean("iotProperties") - @ConditionalOnProperty(name = "jetlinks.version", havingValue = "2.0") - @ConfigurationProperties(prefix = "jetlinks.server.v2") - public IoTProperties iotPropertiesV2() { - return new IoTProperties(); - } - - /** - * iot 模板 - * - * @param iotProperties - * @return - */ - @Bean - public IoTTemplate iotTemplate(@Qualifier("iotProperties") IoTProperties iotProperties) { - return new IoTTemplate(iotProperties); - } - -} diff --git a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTException.java b/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTException.java deleted file mode 100644 index d605cb7c..00000000 --- a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTException.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.central.common.iot; - -/** - * iot 异常 - * - * @author wangpeijie - * @date 2024/11/28 - */ -public class IoTException extends RuntimeException { - - public IoTException(String message) { - super(message); - } -} diff --git a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTProperties.java b/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTProperties.java deleted file mode 100644 index 89916e2d..00000000 --- a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTProperties.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.central.common.iot; - -import lombok.Setter; -import org.springframework.beans.factory.annotation.Value; - -/** - * iot 配置 - * - * @author wangpeijie - * @date 2024/11/19 - */ -@Setter -public class IoTProperties { - - @Value("${jetlinks.version}") - private String version; - - @Value("${jetlinks.clientId}") - private String clientId; - - @Value("${jetlinks.secureKey}") - private String secureKey; - - @Value("${jetlinks.dockProductIds:}") - private String dockProductIds; - - @Value("${jetlinks.droneProductIds:}") - private String droneProductIds; - - private String deviceInfoQueryUrl = "/device-instance/_query"; - - private String url; - - private String ws; - - private String mqtt; - - /** - * 获取iot平台token - */ - private String queryToken; - - /** - * hushi->iot执行任务指令 - */ - private String execMissionUrl; - - /** - * mgnt -> iot 添加设备 - */ - private String saveDeviceUrl; - - /** - * mgnt -> iot 激活设备 - */ - private String activeDeviceUrl; - - /** - * hushi查询产品 - */ - private String productQueryUrl; - - /** - * hushi查询固件历史 - */ - private String upgradeHistoryUrl; - - /** - * 查询固件 - */ - private String firmwareQueryUrl; - - /** - * 固件升级任务 - */ - private String firmwareUpgradeTaskStartUrl; - - /** - * 查询设备日志 - */ - private String deviceLogUrl; - - /** - * 查询设备所有属性 - */ - private String propertiesQueryUrl; - - /** - * 查询设备所有属性 - */ - private String propertyQueryUrl; - - /** - * 查询单个设备最新的全部属性 - */ - private String propertyLatest; - - public String getDockProductIds() { - return dockProductIds; - } - - public String getDroneProductIds() { - return droneProductIds; - } - - public String getVersion() { - return this.version; - } - - public String getClientId() { - return this.clientId; - } - - public String getSecureKey() { - return this.secureKey; - } - - public String getUrl() { - return this.url; - } - - public String getWsUrl() { - return this.ws; - } - - public String getMqttUrl() { - return this.mqtt; - } - - public String getQueryTokenUrl() { - return this.url + this.queryToken; - } - - public String getExecMissionUrl() { - return this.url + this.execMissionUrl; - } - - public String getSaveDeviceUrl() { - return this.url + this.saveDeviceUrl; - } - - public String getActiveDeviceUrl() { - return this.url + this.activeDeviceUrl; - } - - public String getProductQueryUrl() { - return this.url + this.productQueryUrl; - } - - public String getUpgradeHistoryUrl() { - return this.url + this.upgradeHistoryUrl; - } - - public String getFirmwareQueryUrl() { - return this.url + this.firmwareQueryUrl; - } - - public String getFirmwareUpgradeTaskStartUrl() { - return this.url + this.firmwareUpgradeTaskStartUrl; - } - - public String getDeviceLogUrl() { - return this.url + this.deviceLogUrl; - } - - public String getPropertiesQueryUrl() { - return this.url + this.propertiesQueryUrl; - } - - public String getPropertyQueryUrl() { - return this.url + this.propertyQueryUrl; - } - - public String getPropertyLatestUrl() { - return this.url + this.propertyLatest; - } - - public String getDeviceInfoQueryUrl() { - return this.url + this.deviceInfoQueryUrl; - } -} diff --git a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTTemplate.java b/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTTemplate.java deleted file mode 100644 index eba35d94..00000000 --- a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTTemplate.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.central.common.iot; - -import cn.hutool.core.util.HexUtil; -import cn.hutool.crypto.digest.DigestAlgorithm; -import cn.hutool.crypto.digest.DigestUtil; -import cn.hutool.http.HttpRequest; -import cn.hutool.http.HttpResponse; -import cn.hutool.http.HttpUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.util.*; - -/** - * IoT Template - * - * @author wangpeijie - * @date 2024/11/20 - */ -@Slf4j -@RequiredArgsConstructor -public class IoTTemplate { - - private final IoTProperties iotProperties; - - /** - * 查询token - * - * @return - */ - public String queryToken() { - String queryTokenUrl = iotProperties.getQueryTokenUrl(); - Map param = new HashMap<>(2); - param.put("expires", 7200 * 24); - return this.execute(queryTokenUrl, param); - } - - /** - * 返回报文结构 - * { - * "total": 865, - * "data": [ - * { - * "formatValue": "DNS1MINIPT23160061", - * "propertyName": "设备ID", - * "createTime": 1735095082942, - * "property": "deviceId", - * "id": "eZP7ud--Szm9VElG6y3BvT76MNySv3ZC", - * "type": "string", - * "deviceId": "DNS1MINIPT23160061", - * "value": "DNS1MINIPT23160061", - * "originValue": "DNS1MINIPT23160061", - * "timestamp": 1735095082940 - * } - * ], - * "pageIndex": 0, - * "pageSize": 1 - * } - * 单个属性查询 - * - * @param deviceSn 设备SN - * @param property 属性 - * @return - */ - public String queryProperty(String deviceSn, String property) { - String url = iotProperties.getPropertyQueryUrl(); - url = url.replace("{deviceId}", deviceSn).replace("{property}", property); - Map params = new HashMap<>(5); - params.put("pageSize", 1); - params.put("pageIndex", 0); - List> list = new ArrayList<>(); - Map termParam = new HashMap<>(5); - termParam.put("column", "property"); - termParam.put("value", property); - list.add(termParam); - params.put("terms", list); - return this.execute(url, params); - } - - /** - * 单个属性值查询 - * - * @param deviceSn 设备SN - * @param property 属性 - * @return - */ - public String queryPropertyValue(String deviceSn, String property) { - String result = this.queryProperty(deviceSn, property); - JSONObject resultObject = JSON.parseObject(result); - JSONArray dataArray = resultObject.getJSONArray("data"); - if (dataArray != null && !dataArray.isEmpty()) { - JSONObject jsonObject = dataArray.getJSONObject(0); - return jsonObject.getString("value"); - } - return null; - } - - /** - * iot 核心请求方法,JSON报文体 - * - * @param url 请求地址 - * @param param 报文参数 - * @return - */ - public String execute(String url, Map param) { - String body = JSON.toJSONString(param); - return this.execute(url, body); - } - - /** - * iot 核心请求方法,字符串报文体 - * - * @param url 请求地址 - * @param body 报文体 - * @return - */ - public String execute(String url, String body) { - //时间戳 - String xTimestamp = String.valueOf(System.currentTimeMillis()); - //param+X-Timestamp+SecureKey通过MD5加密 - MessageDigest digest = DigestUtil.digester(DigestAlgorithm.MD5).getDigest(); - digest.update(body.getBytes()); - digest.update(xTimestamp.getBytes()); - digest.update(iotProperties.getSecureKey().getBytes()); - - Map headers = new HashMap<>(5); - headers.put("X-Sign", HexUtil.encodeHexStr(digest.digest())); - headers.put("X-Client-Id", iotProperties.getClientId()); - headers.put("X-Timestamp", xTimestamp); - - HttpRequest httpRequest = HttpUtil.createPost(url); - httpRequest.addHeaders(headers); - httpRequest.body(body); - String result = null; - try (HttpResponse httpResponse = httpRequest.execute()) { - result = new String(httpResponse.bodyBytes(), StandardCharsets.UTF_8); - log.info("IoTTemplate请求地址:{},请求头:{}, 请求参数:{},响应结果:{}", url, headers, body, result); - } catch (Exception e) { - log.error("IoTTemplate请求地址:{},请求头:{}, 请求参数:{}", url, headers, body, e); - } - JSONObject jsonObject = JSON.parseObject(result); - if (jsonObject != null && Objects.equals(jsonObject.getInteger("status"), 200)) { - return jsonObject.getString("result"); - } - throw new IoTException(StringUtils.defaultIfBlank(jsonObject.getString("message"), "IoTTemplate请求异常")); - } - -} diff --git a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTWebSocketClient.java b/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTWebSocketClient.java deleted file mode 100644 index 40fad2ff..00000000 --- a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTWebSocketClient.java +++ /dev/null @@ -1,248 +0,0 @@ -package com.central.common.iot; - -import cn.hutool.core.thread.ThreadUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.java_websocket.client.WebSocketClient; -import org.java_websocket.handshake.ServerHandshake; -import org.springframework.beans.factory.BeanNameAware; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; - -import java.net.URI; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * iot websocket 客户端 - * - * @author wangpeijie - * @date 2024/11/20 - */ -@Slf4j -public class IoTWebSocketClient implements BeanNameAware, InitializingBean, DisposableBean { - - private String beanName; - - /** - * 尝试重连标识 - */ - private final AtomicBoolean tryReconnect = new AtomicBoolean(false); - - /** - * 需要ping标识 - */ - private final AtomicBoolean needPing = new AtomicBoolean(true); - - /** - * 连接结束标识 - */ - private final AtomicBoolean end = new AtomicBoolean(false); - - /** - * 重连次数 - */ - private AtomicInteger reConnectTimes = new AtomicInteger(0); - - /** - * iot 消息处理器 - */ - private final IoTWebSocketHandler iotWebSocketHandler; - - private WebSocketClient webSocketClient; - - @Autowired - private IoTProperties iotProperties; - - @Autowired - private IoTTemplate iotTemplate; - - public IoTWebSocketClient(IoTWebSocketHandler iotWebSocketHandler) { - this.iotWebSocketHandler = iotWebSocketHandler; - } - - /** - * 设置bean名称 - * - * @param beanName - */ - @Override - public void setBeanName(String beanName) { - this.beanName = beanName; - } - - /** - * 初始化 - * - * @throws Exception - */ - @Override - public void afterPropertiesSet() throws Exception { - connect(); - circlePing(); - } - - /** - * 连接 - */ - private void connect() throws Exception { - String token = null; - for (int i = 0; i < 3; i++) { - token = iotTemplate.queryToken(); - if (StrUtil.isNotBlank(token)) { - break; - } - } - if (StringUtils.isBlank(token)) { - log.warn("iot token 获取失败..."); - return; - } - String url = iotProperties.getWsUrl() + token; - webSocketClient = new WebSocketClient(new URI(url)) { - @Override - public void onOpen(ServerHandshake serverHandshake) { - log.info("[{}]IoTWebSocketClient [onOpen]连接成功{}", beanName, getRemoteSocketAddress()); - tryReconnect.set(false); - } - - @Override - public void onMessage(String message) { - if (StringUtils.isEmpty(message)) { - return; - } - if (message.contains("{\"type\":\"pong\"}")) { - return; - } - if (log.isDebugEnabled()) { - log.debug("[{}]IoTWebSocketClient [onMessage]接收到消息{}", beanName, message); - } - JSONObject jsonObject = JSON.parseObject(message); - if (jsonObject == null || StringUtils.isBlank(jsonObject.getString("topic"))) { - return; - } - JSONObject payload = jsonObject.getJSONObject("payload"); - try { - iotWebSocketHandler.onMessage(payload); - } catch (Exception e) { - log.error("[{}]IoTWebSocketClient [onMessage]处理消息异常", beanName, e); - } - } - - @Override - public void onClose(int code, String reason, boolean remote) { - log.info("[{}]IoTWebSocketClient [onClose]关闭,code={},reason={},remote={}", beanName, code, reason, remote); - if (StrUtil.hasBlank(reason) || reason.contains("https")) { - if (end.get()) { - return; - } - try { - IoTWebSocketClient.this.reconnect(); - } catch (Exception e) { - log.error("[{}]IoTWebSocketClient [onClose]重连失败", beanName, e); - } - } - } - - @Override - public void onError(Exception e) { - log.info("[{}]IoTWebSocketClient [onError]异常", beanName, e); - try { - IoTWebSocketClient.this.reconnect(); - } catch (Exception exception) { - log.info("[{}]IoTWebSocketClient [onError]重连失败", beanName, exception); - } - } - }; - webSocketClient.connectBlocking(10, TimeUnit.SECONDS); - iotWebSocketHandler.onConnect(this); - } - - /** - * 重连 - */ - private void reconnect() throws Exception { - ThreadUtil.sleep(10, TimeUnit.SECONDS); - int cul = reConnectTimes.incrementAndGet(); - if (end.get()) { - log.info("已确认关闭连接"); - return; - } - log.warn("[{}]第[{}]次断开重连", beanName, cul); - if (tryReconnect.get()) { - log.error("[{}]第[{}]次断开重连结果 -> 连接正在重连,本次重连请求放弃", beanName, cul); - return; - } - try { - tryReconnect.set(true); - if (webSocketClient.isOpen()) { - log.warn("[{}]第[{}]次断开重连,关闭旧连接", beanName, cul); - webSocketClient.closeConnection(2, "reconnect stop"); - } - webSocketClient = null; - connect(); - reConnectTimes = new AtomicInteger(0); - } catch (Exception e) { - log.error("[{}]第[{}]次断开重连结果 -> 连接正在重连", beanName, cul, e); - reconnect(); - } finally { - tryReconnect.set(false); - } - } - - /** - * 心跳 - */ - public void circlePing() { - new Thread( - () -> { - while (needPing.get()) { - if (webSocketClient.isOpen()) { - String ping = "{\"type\":\"ping\"}"; - webSocketClient.send(ping); - } - ThreadUtil.sleep(5, TimeUnit.SECONDS); - } - log.warn("[{}]Ping循环关闭", beanName); - }) - .start(); - } - - /** - * 销毁 - */ - @Override - public void destroy() throws Exception { - needPing.set(false); - end.set(true); - if (webSocketClient != null) { - try { - webSocketClient.closeConnection(3, "real stop"); - } catch (Exception e) { - log.error("[{}]IoTWebSocketClient 关闭失败", beanName, e); - } - try { - webSocketClient.close(); - } catch (Exception e) { - log.error("[{}]IoTWebSocketClient 关闭失败", beanName, e); - } - reConnectTimes = new AtomicInteger(0); - webSocketClient = null; - } - } - - /** - * 发送消息 - * - * @param message - */ - public void send(String message) { - if (webSocketClient.isOpen()) { - webSocketClient.send(message); - } - } -} diff --git a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTWebSocketHandler.java b/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTWebSocketHandler.java deleted file mode 100644 index 474f6228..00000000 --- a/zlt-commons/zlt-iot-spring-boot-starter/src/main/java/com/central/common/iot/IoTWebSocketHandler.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.central.common.iot; - -import com.alibaba.fastjson.JSONObject; - -/** - * IoT WebSocket 处理器 - * - * @author wangpeijie - * @date 2024/11/20 - */ -public interface IoTWebSocketHandler { - - /** - * 连接成功 - * - * @param webSocketClient - */ - default void onConnect(IoTWebSocketClient webSocketClient) { - - } - - /** - * 处理消息 - * - * @param message - */ - void onMessage(JSONObject message); - -} diff --git a/zlt-commons/zlt-iot-spring-boot-starter/src/main/resources/META-INF/spring.factories b/zlt-commons/zlt-iot-spring-boot-starter/src/main/resources/META-INF/spring.factories deleted file mode 100644 index d084a2e2..00000000 --- a/zlt-commons/zlt-iot-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -com.central.common.iot.IoTConfiguration \ No newline at end of file