commit 514da053c4f7d0e9108e74b3933cb0d3a542c457 Author: 小鱼干 <1810377322@163.com> Date: Fri Jun 6 17:44:29 2025 +0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7006828 --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +# Compiled class file +*.class + +# Log file +log +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +.idea +target +*.iml +data/elasticsearch +.init +*.db +.flattened-pom.xml + +.DS_Store +dependency-reduced-pom.xml +/data/plugins +/data/dist +/data/iot-oss \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..11ddf4c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# 操作步骤: +# 1. 打包前端项目,复制dis到data目录 +# 2. 打包java项目 +# 3. docker build -t iot-iita . +# 4. docker tag iot-iita iotkits/iot-iita +# 5. docker push iotkits/iot-iita + +# 使用包含Java的基础镜像 +FROM eclipse-temurin:11-jre +# 设置工作目录 +WORKDIR /app + +# 复制后端Java应用的JAR文件 +COPY ./iot-starter/target/iot-starter-0.5.3.jar app.jar +COPY ./data/init/* data/init/ + +# 安装Nginx +RUN apt-get update && apt-get install -y nginx + +# 复制Nginx配置文件 +COPY ./data/nginx.conf /etc/nginx/nginx.conf + +# 复制静态资源 +COPY ./data/dist/ /usr/share/nginx/html + +# 暴露端口 +EXPOSE 8082 8086 1883 1884 +# 插件预留端口 +EXPOSE 8130-8140 + +# 设置容器启动命令 +CMD ["/bin/bash", "-c", "java -jar /app/app.jar & nginx -g 'daemon off;'"] + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f0e8d29 --- /dev/null +++ b/README.md @@ -0,0 +1,153 @@ + + + +

+logo +

+

+

+

+ + +

+ +#### 禹霖科技物联网平台开源项目 + +管理员账号密码:admin/admin123 + +#### 介绍 +此仓库为禹霖科技(openyl)物联网平台开源项目。 +禹霖科技开源平台是一个开源的物联网基础开发平台,提供了物联网及相关业务开发的常见基础功能, 能帮助你快速搭建自己的物联网相关业务平台。 + +系统包含了品类、物模型、消息转换、插件管理(mqtt插件、EMQX插件、http插件、tcp插件、modbus插件等)、设备管理、设备分组、规则引擎、第三方平台接入、数据流转(http/mqtt/kafka)、数据可视化、告警中心等模块。 +### 商业版本 +分布式协议商业版,支持协议组件水平扩展.对于设备数量多的用户可以考虑采购此版本 + +#### 低配服务器万级设备接入能力 + +服务器配置: 1台2核2G(阿里云突发性能实例)跑主程序、1台2核4G(阿里云突发性能实例)跑TDengine和RocketMq + +程序配置:使用内置H2数据库和内置mqtt + +设备接入情况:接入4千台网关+8千台子设备,其中4千台子设备每10秒上报一条数据 + +稳定运行后:设备在线并正常上报和下发、CPU占用未超过50%、界面操作没有卡顿 + +#### 低学习门槛 + +1、零配置一键运行,小白也会用 + +2、低环境要求,不需要额外安装软件 + +3、平民级代码,没有形式化的分层和过度封装,简单易懂 + + +#### 主流数据库支持 + +关系型数据库:理论上支持所有实现了标准SQL的数据库,如: DB2、H2、HSQLDB、MariaDB、Microsoft SQL Server、MySQL、Oracle、Postgres + +时序数据库:elasticsearch、TDEngine + +K-V数据库:redis + +#### 消息总线支持 + +Vertx event-bus(内置)、RocketMQ,通过扩展模块可接入其它任意消息中间件。 + + +#### 系统生态 + +**前端项目:** + +[![OPENIITA/iita-iot-web-admin](https://gitee.com/open-iita/iita-iot-web-admin/widgets/widget_card.svg?colors=393222,ebdfc1,fffae5,d8ca9f,393222,a28b40)](https://gitee.com/open-iita/iita-iot-web-admin) + + **演示地址:** [点击访问](https://open-iita.feishu.cn/wiki/Km67wBKNNiFMrMkldCJcxa6vnLe) + + +**系统截图** + +![输入图片说明](doc/screenshot.png) + + + +#### 软件架构 +软件架构说明 +本系统采用springboot、jpa、vertx、redis、H2、mysql、elasticsearch、TDEngine、RocketMq、sa-token等框架和第三方软件,中间件采用模块化无侵入集成非常容易扩展和替换。 + +默认使用内置的redis、h2数据库、es时序数据库、vertx消息总线和oss以减小启动难度,可实现 **零配置一键启动** ,程序在第一次启动的时候会使用data/init目录的示例数据进行初始化。 + + + +**注:** es版本为7.15.2,mysql版本为8.0+ + +##### H2数据库切换为mysql方法(其它数据库同理) +https://open-iita.feishu.cn/wiki/IhIGwZSnsiMaDdkT98Xcvtb4nGh + +##### es切换为TDengine(版本:3.x)方法 +https://open-iita.feishu.cn/wiki/IhIGwZSnsiMaDdkT98Xcvtb4nGh + +##### 消息总线切换为RocketMq方法 + +1、注释掉iot-starter/pom.xml中的 iot-message-event-bus,并打开iot-message-rocketmq的注释 + +2、application.xml中打开rocketmq配置 + +#### Docker运行 +docker 镜像版本里的比较旧了,请参考dockerfile自己构建 + +启动后访问 http://localhost:8082/ + +#### 源码运行步骤 +在线文档:[知识库](https://open-iita.feishu.cn/wiki/Km67wBKNNiFMrMkldCJcxa6vnLe) + +在配置好相应的jdk11环境后,推荐使用idea拉取代码,等待项目加载完成以后,先在Terminal里执行mvn clean install,然后在idea的maven操作框上点击下刷新 +![1](doc/image-20230702173737805.png) + +然后就点击启动,看到如下所示日志即表示启动成功: + +![image-20230702174747305](doc/image-20230702174747305.png) + +#### 后端常见问题以及处理方式 + +#### 1、数据初始化不成功 + +删除以下标红的几个文件以及文件夹后,重复下上面启动项目的操作: + +![image-20230702173852342](doc/image-20230702173852342.png) + +切换成外置中间件数据库时,也注意删除相关库以及数据。 + +##### 2、提示找不到QTbxxxxx类 + +在Terminal里执行mvn clean install,再刷新下,这个出现的原因是因为采用了querydsl插件,打包时会生成相关的类,有可能idea的扫描不及时,导致未识别到 + +![111](doc/image-20230702173737805.png) + +##### 3,启动提示xxMapperxxx类bean重复 + +处理办法同2一样,原因也类似,采用了mapstruct plus插件,打包时候会生成对应类的getset方法工具类,可能idea的扫描不及时,导致未识别到 + + +#### 服务器部署 + +执行maven打包在iot-starter模块中将打包后的iot-starter.xx.zip上传到服务器 +解压后先执行: java -jar lib/iot-start.xxx.jar,确认成功后续可使用 bin/start.sh或bin/start.bat启动。 + + + +#### 文档 + +https://open-iita.feishu.cn/wiki/Km67wBKNNiFMrMkldCJcxa6vnLe + + +# **商业版双节大优惠,惊喜价格!!!!** + +商务或技术交流请联系: + +![输入图片说明](doc/image.png) +![输入图片说明](doc/%E9%9B%86%E7%BE%A4.png) + +#### 捐助与支持 +如果您觉得我的开源软件对你有所帮助请关注、star、fork :kissing_heart: 。 + +如果我的开源软件应用到您的商业项目中,请务必通知到我,因为得到用户的认可是支撑开源的动力。 \ No newline at end of file diff --git a/data/init/category.json b/data/init/category.json new file mode 100644 index 0000000..76d5af1 --- /dev/null +++ b/data/init/category.json @@ -0,0 +1,49 @@ +[ { + "id" : "switch", + "name" : "开关", + "createAt" : 1647599367057 +}, { + "id" : "sensor", + "name" : "传感器", + "createAt" : 1649743382683 +}, { + "id" : "meter", + "name" : "表计", + "createAt" : 1654237582120 +}, { + "id" : "light", + "name" : "灯", + "createAt" : 1650174762755 +}, { + "id" : "gateway", + "name" : "网关", + "createAt" : 1646637047902 +}, { + "id" : "fan", + "name" : "风扇", + "createAt" : 1646630215889 +}, { + "id" : "door", + "name" : "门磁", + "createAt" : 1650173898298 +}, { + "id" : "SmartPlug", + "name" : "智能插座", + "createAt" : 1645409421118 +}, { + "id" : "FreshAir", + "name" : "新风", + "createAt" : 1681444312184 +}, { + "id" : "SmartMeter", + "name" : "智能电表", + "createAt" : 1681444312184 +}, { + "id" : "OpenIitaGateway", + "name" : "禹霖科技智能网关", + "createAt" : 1688969826383 +}, { + "id" : "OpenIitaPump", + "name" : "禹霖科技水泵", + "createAt" : 1688969826383 +} ] diff --git a/data/init/channel.json b/data/init/channel.json new file mode 100644 index 0000000..d84c84d --- /dev/null +++ b/data/init/channel.json @@ -0,0 +1,19 @@ +[ { + "id" : 1, + "code" : "DingTalk", + "title" : "钉钉", + "icon" : "http://www.baidu.com", + "createAt" : 1683816661690 +}, { + "id" : 2, + "code" : "QyWechat", + "title" : "企业微信", + "icon" : "http://www.baidu.com", + "createAt" : 1683816661690 +}, { + "id" : 3, + "code" : "Email", + "title" : "邮箱", + "icon" : "http://www.baidu.com", + "createAt" : 1683816661690 +} ] \ No newline at end of file diff --git a/data/init/channelConfig.json b/data/init/channelConfig.json new file mode 100644 index 0000000..14cedab --- /dev/null +++ b/data/init/channelConfig.json @@ -0,0 +1,19 @@ +[ { + "id" : 1312312, + "channelId" : 3, + "title" : "告警邮件配置", + "param" : "{\"userName\":\"xxx@163.com\",\"passWord\":\"xxx\",\"host\":\"smtp.163.com\",\"port\":465,\"mailSmtpAuth\":true,\"from\":\"xxxx@163.com\",\"to\":\"xxxx@163.com\"}\t", + "createAt" : 1683816661690 +}, { + "id" : 1313123, + "channelId" : 1, + "title" : "告警钉钉配置", + "param" : "{\"dingTalkWebhook\":\"xxxxxxxxxxxxxxxx\",\"dingTalkSecret\":\"xxxx\"}", + "createAt" : 1683816661690 +}, { + "id" : 32141342, + "channelId" : 2, + "title" : "告警企业微信配置", + "param" : "{\"qyWechatWebhook\":\"xxxxxxxxxxxxxxxx\"}", + "createAt" : 1683816661690 +} ] \ No newline at end of file diff --git a/data/init/channelTemplate.json b/data/init/channelTemplate.json new file mode 100644 index 0000000..548c9b8 --- /dev/null +++ b/data/init/channelTemplate.json @@ -0,0 +1,19 @@ +[ { + "id" : 12312312, + "channelConfigId" : 1312312, + "title" : "告警邮件模板", + "content" : "您的设备【${title}】温度过高", + "createAt" : 1683816661690 +}, { + "id" : 342353425, + "channelConfigId" : 1313123, + "title" : "告警钉钉模板", + "content" : "您的设备【${title}】温度过高", + "createAt" : 1683816661690 +}, { + "id" : 786778567, + "channelConfigId" : 32141342, + "title" : "告警企业微信模板", + "content" : "您的设备【${title}】温度过高", + "createAt" : 1683816661690 +} ] \ No newline at end of file diff --git a/data/init/deviceGroup.json b/data/init/deviceGroup.json new file mode 100644 index 0000000..0344641 --- /dev/null +++ b/data/init/deviceGroup.json @@ -0,0 +1,22 @@ +[ { + "id" : "g3", + "name" : "组3", + "uid" : "1", + "remark" : "2223333", + "deviceQty" : 7, + "createAt" : 0 +}, { + "id" : "g2", + "name" : "组2", + "uid" : "1", + "remark" : "222", + "deviceQty" : 12, + "createAt" : 0 +}, { + "id" : "g1", + "name" : "分组1", + "uid" : "1", + "remark" : "1111", + "deviceQty" : 10, + "createAt" : 0 +} ] \ No newline at end of file diff --git a/data/init/deviceInfo.json b/data/init/deviceInfo.json new file mode 100644 index 0000000..b3a7b25 --- /dev/null +++ b/data/init/deviceInfo.json @@ -0,0 +1,2045 @@ +[ + { + "tenantId" : 0, + "id": "16552595723210menci0001008000012f", + "deviceId": "16552595723210menci0001008000012f", + "productKey": "PN3EDmkBZDD8whDd", + "deviceName": "MENCI0001008", + "secret": "rMAweEJrE7cxbQWa", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655415536032 + }, + "property": { + "doorStatus": 0, + "power": 65, + "rssi": 106 + }, + "tag": {}, + "createAt": 1655259572321, + "group": { + "g1": { + "id": "g1", + "name": "分组1" + } + } + }, + { + "id": "16552595685220menci00010070000127", + "deviceId": "16552595685220menci00010070000127", + "productKey": "PN3EDmkBZDD8whDd", + "deviceName": "MENCI0001007", + "secret": "eN4PjDhH4yx4mrmi", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655415536130 + }, + "property": { + "doorStatus": 1, + "power": 34, + "rssi": 64 + }, + "tag": {}, + "createAt": 1655259568522, + "group": { + "g1": { + "id": "g1", + "name": "分组1" + } + } + }, + { + "id": "16552595656210menci0001006000012d", + "deviceId": "16552595656210menci0001006000012d", + "productKey": "PN3EDmkBZDD8whDd", + "deviceName": "MENCI0001006", + "secret": "ePSkE7bzGMsR6rTs", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655415536135 + }, + "property": { + "doorStatus": 1, + "power": 33, + "rssi": 40 + }, + "tag": {}, + "createAt": 1655259565621, + "group": { + "g1": { + "id": "g1", + "name": "分组1" + } + } + }, + { + "id": "16552594933210linght001007000012f", + "deviceId": "16552594933210linght001007000012f", + "productKey": "xpsYHExTKPFaQMS7", + "deviceName": "LINGHT001007", + "secret": "mkQiSDk4rF3EWKFM", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655416465031 + }, + "property": { + "brightness": 12, + "powerstate": 0 + }, + "tag": {}, + "createAt": 1655259493321, + "group": { + "g1": { + "id": "g1", + "name": "分组1" + }, + "g2": { + "id": "g2", + "name": "组2" + } + } + }, + { + "id": "16552594898210linght0010060000129", + "deviceId": "16552594898210linght0010060000129", + "productKey": "xpsYHExTKPFaQMS7", + "deviceName": "LINGHT001006", + "secret": "p72KAZyTA42zi8cJ", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655416465035 + }, + "property": { + "brightness": 86, + "powerstate": 1 + }, + "tag": {}, + "createAt": 1655259489821, + "group": { + "g1": { + "id": "g1", + "name": "分组1" + } + } + }, + { + "tenantId" : 0, + "id": "16552594863210linght001005000012c", + "deviceId": "16552594863210linght001005000012c", + "productKey": "xpsYHExTKPFaQMS7", + "deviceName": "LINGHT001005", + "secret": "xnKZZyPKj2rH6ee3", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655416465133 + }, + "property": { + "brightness": 16, + "powerstate": 1 + }, + "tag": {}, + "createAt": 1655259486321, + "group": { + "g1": { + "id": "g1", + "name": "分组1" + }, + "g2": { + "id": "g2", + "name": "组2" + } + } + }, + { + "id": "16552594812210linght001004000012d", + "deviceId": "16552594812210linght001004000012d", + "productKey": "xpsYHExTKPFaQMS7", + "deviceName": "LINGHT001004", + "secret": "PDkTxHPfw2H4WZjQ", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655416465231 + }, + "property": { + "brightness": 32, + "powerstate": 0 + }, + "tag": {}, + "createAt": 1655259481221, + "group": { + "g1": { + "id": "g1", + "name": "分组1" + } + } + }, + { + "tenantId" : 0, + "id": "16552594646210pulg0a0010160000122", + "deviceId": "16552594646210pulg0a0010160000122", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001016", + "secret": "3KdPNBKZEyDGaNYK", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655652738672 + }, + "property": { + "powerstate": 0, + "rssi": 66 + }, + "tag": {}, + "group": { + "g1": { + "id": "g1", + "name": "分组1" + } + }, + "createAt": 1655259464621 + }, + { + "tenantId" : 0, + "id": "16552594604220pulg0a0010150000127", + "deviceId": "16552594604220pulg0a0010150000127", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001015", + "secret": "TBwbHJdJBQCpGdHi", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655652738676 + }, + "property": { + "powerstate": 1, + "rssi": 67 + }, + "tag": {}, + "group": { + "g2": { + "id": "g2", + "name": "组2" + } + }, + "createAt": 1655259460422 + }, + { + "tenantId" : 0, + "id": "16552594572370pulg0a001014000012e", + "deviceId": "16552594572370pulg0a001014000012e", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001014", + "secret": "86pTYbQxxX3wd2FR", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655652738773 + }, + "property": { + "powerstate": 1, + "rssi": 42 + }, + "tag": {}, + "group": { + "g2": { + "id": "g2", + "name": "组2" + } + }, + "createAt": 1655259457237 + }, + { + "tenantId" : 0, + "id": "16552594542310pulg0a0010130000123", + "deviceId": "16552594542310pulg0a0010130000123", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001013", + "secret": "FtxYcTM5p6B5GyPk", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655652738872 + }, + "property": { + "powerstate": 1, + "rssi": 45 + }, + "tag": {}, + "group": { + "g2": { + "id": "g2", + "name": "组2" + } + }, + "createAt": 1655259454231 + }, + { + "tenantId" : 0, + "id": "16552594511210pulg0a001012000012c", + "deviceId": "16552594511210pulg0a001012000012c", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001012", + "secret": "5yHFHseBHDbCK3eZ", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655652738972 + }, + "property": { + "powerstate": 0, + "rssi": 60 + }, + "tag": {}, + "group": { + "g2": { + "id": "g2", + "name": "组2" + } + }, + "createAt": 1655259451121 + }, + { + "tenantId" : 0, + "id": "16552594475270pulg0a0010110000125", + "deviceId": "16552594475270pulg0a0010110000125", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001011", + "secret": "pGC4z4TrbjZhii2m", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655652739072 + }, + "property": { + "powerstate": 1, + "rssi": 27 + }, + "tag": {}, + "group": { + "g2": { + "id": "g2", + "name": "组2" + } + }, + "createAt": 1655259447528 + }, + { + "id": "16552594444210pulg0a0010100000128", + "deviceId": "16552594444210pulg0a0010100000128", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001010", + "secret": "HMxT2rQ55bzeRNJx", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655652739076 + }, + "property": { + "powerstate": 0, + "rssi": 117 + }, + "tag": {}, + "group": { + "g2": { + "id": "g2", + "name": "组2" + } + }, + "createAt": 1655259444422 + }, + { + "id": "16552594405220pulg0a0010090000124", + "deviceId": "16552594405220pulg0a0010090000124", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001009", + "secret": "Z6yMp6D6mHKMjFi7", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655652739174 + }, + "property": { + "powerstate": 1, + "rssi": 20 + }, + "tag": {}, + "group": { + "g2": { + "id": "g2", + "name": "组2" + } + }, + "createAt": 1655259440522 + }, + { + "tenantId" : 0, + "id": "16552594368340pulg0a0010080000126", + "deviceId": "16552594368340pulg0a0010080000126", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001008", + "secret": "Ek3ZjwPayCymDxhN", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655652739272 + }, + "property": { + "powerstate": 1, + "rssi": 77 + }, + "tag": {}, + "group": { + "g2": { + "id": "g2", + "name": "组2" + } + }, + "createAt": 1655259436834 + }, + { + "tenantId" : 0, + "id": "16552594320310pulg0a0010070000126", + "deviceId": "16552594320310pulg0a0010070000126", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001007", + "secret": "NnnHaibdHJXMxNbC", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655652739372 + }, + "property": { + "powerstate": 1, + "rssi": 75 + }, + "tag": {}, + "group": { + "g2": { + "id": "g2", + "name": "组2" + } + }, + "createAt": 1655259432067 + }, + { + "tenantId" : 0, + "id": "16542484163750d60ee9025d8430e327", + "deviceId": "16542484163750d60ee9025d8430e327", + "productKey": "Eit3kmGJtxSHfCKT", + "deviceName": "2475b491e72541f7ad60ee9025d8430e", + "secret": "bWkiEmY6wKM8WQP5", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false + }, + "property": { + "flow": "333", + "fee": "2121212" + }, + "tag": {}, + "createAt": 1654248416391 + }, + { + "tenantId" : 0, + "id": "16538390924670pulg0a001006000012a", + "deviceId": "16538390924670pulg0a001006000012a", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001006", + "secret": "FFSdNXDRJbnE8fm2", + "uid": "1", + "subUid": [ + "04c6722f-9a6d-40f3-ac9b-cd791b4c8933" + ], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839933067 + }, + "property": { + "powerstate": 1, + "rssi": 53, + "DeviceType": "222" + }, + "tag": { + "aligenie": { + "id": "aligenie", + "name": "天猫精灵", + "value": "是" + }, + "dueros": { + "id": "dueros", + "name": "小度", + "value": "是" + }, + "duerosOpenUid": { + "id": "duerosOpenUid", + "name": "小度OpenUid", + "value": "0cfd14fc6d1ec120fcd38885df09f33c" + } + }, + "createAt": 1653839092467 + }, + { + "tenantId" : 0, + "id": "16538390885690pulg0a0010050000126", + "deviceId": "16538390885690pulg0a0010050000126", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001005", + "secret": "CN8ZGpcAheAbsDn2", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839933167 + }, + "property": { + "powerstate": 0, + "rssi": 117 + }, + "tag": {}, + "createAt": 1653839088569 + }, + { + "id": "16538390853670pulg0a0010040000121", + "deviceId": "16538390853670pulg0a0010040000121", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001004", + "secret": "S4SDRKscRXAn43bc", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839933267 + }, + "property": { + "powerstate": 1, + "rssi": 45 + }, + "tag": {}, + "createAt": 1653839085367, + "group": { + "g3": { + "id": "g3", + "name": "组3" + } + } + }, + { + "tenantId" : 0, + "id": "16538390820760pulg0a0010030000127", + "deviceId": "16538390820760pulg0a0010030000127", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001003", + "secret": "7N4S6eYzMCjA7YfK", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839933367 + }, + "property": { + "powerstate": 1, + "rssi": 101 + }, + "tag": {}, + "createAt": 1653839082076 + }, + { + "tenantId" : 0, + "id": "16538390787670pulg0a0010020000124", + "deviceId": "16538390787670pulg0a0010020000124", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001002", + "secret": "Jm7ecfyXawiend8K", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839933376 + }, + "property": { + "powerstate": 1, + "rssi": 70 + }, + "tag": {}, + "createAt": 1653839078767, + "group": { + "g3": { + "id": "g3", + "name": "组3" + } + } + }, + { + "id": "16538390738670pulg0a0010010000125", + "deviceId": "16538390738670pulg0a0010010000125", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "PULG0A001001", + "secret": "rtsZbST3tiJHccbe", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839933474 + }, + "property": { + "powerstate": 1, + "rssi": 118 + }, + "tag": {}, + "createAt": 1653839073867, + "group": { + "g3": { + "id": "g3", + "name": "组3" + } + } + }, + { + "tenantId" : 0, + "id": "16538390097670switch0300100500143", + "deviceId": "16538390097670switch0300100500143", + "productKey": "eDhXKwEzwFybM5R7", + "deviceName": "SWITCH03001005", + "secret": "PXHwHXH4a8YJzZ3S", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839918667 + }, + "property": { + "powerstate_1": 0, + "powerstate_2": 0, + "powerstate_3": 1, + "rssi": 86 + }, + "tag": {}, + "createAt": 1653839009767, + "group": { + "g3": { + "id": "g3", + "name": "组3" + } + } + }, + { + "tenantId" : 0, + "id": "16538390048670switch0300100400141", + "deviceId": "16538390048670switch0300100400141", + "productKey": "eDhXKwEzwFybM5R7", + "deviceName": "SWITCH03001004", + "secret": "BQj5SZetsC3eGtfM", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839918676 + }, + "property": { + "powerstate_1": 0, + "powerstate_2": 0, + "powerstate_3": 0, + "rssi": 27 + }, + "tag": {}, + "createAt": 1653839004867, + "group": { + "g3": { + "id": "g3", + "name": "组3" + } + } + }, + { + "tenantId" : 0, + "id": "16538390008670switch0300100300145", + "deviceId": "16538390008670switch0300100300145", + "productKey": "eDhXKwEzwFybM5R7", + "deviceName": "SWITCH03001003", + "secret": "mbs4PsY4atEtzcA3", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839918771 + }, + "property": { + "powerstate_1": 0, + "powerstate_2": 0, + "powerstate_3": 0, + "rssi": 29 + }, + "tag": {}, + "createAt": 1653839000867, + "group": { + "g3": { + "id": "g3", + "name": "组3" + } + } + }, + { + "tenantId" : 0, + "id": "16538389971670switch0300100200140", + "deviceId": "16538389971670switch0300100200140", + "productKey": "eDhXKwEzwFybM5R7", + "deviceName": "SWITCH03001002", + "secret": "4nrNrjnFMSQZB562", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839918871 + }, + "property": { + "powerstate_1": 1, + "powerstate_2": 0, + "powerstate_3": 0, + "rssi": 12 + }, + "tag": {}, + "createAt": 1653838997167, + "group": { + "g3": { + "id": "g3", + "name": "组3" + } + } + }, + { + "tenantId" : 0, + "id": "16538389915670switch030010010014c", + "deviceId": "16538389915670switch030010010014c", + "productKey": "eDhXKwEzwFybM5R7", + "deviceName": "SWITCH03001001", + "secret": "Js66kBbXRjXmcpMB", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839918967 + }, + "property": { + "powerstate_1": 0, + "powerstate_2": 1, + "powerstate_3": 0, + "rssi": 18 + }, + "tag": {}, + "createAt": 1653838991567 + }, + { + "tenantId" : 0, + "id": "16538383943670wenshidu01008000139", + "deviceId": "16538383943670wenshidu01008000139", + "productKey": "6kYp6jszrDns2yh4", + "deviceName": "WENSHIDU01008", + "secret": "pGxKYrNJC7rDhsr8", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655416485331 + }, + "property": { + "humidity": 93, + "temperature": 330 + }, + "tag": {}, + "createAt": 1653838394367 + }, + { + "tenantId" : 0, + "id": "16538383910670wenshidu01007000136", + "deviceId": "16538383910670wenshidu01007000136", + "productKey": "6kYp6jszrDns2yh4", + "deviceName": "WENSHIDU01007", + "secret": "ZxDQeQ8jhMrfx8eE", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655416485335 + }, + "property": { + "humidity": 91, + "temperature": -29 + }, + "tag": {}, + "createAt": 1653838391067 + }, + { + "tenantId" : 0, + "id": "16538383880670wenshidu0100600013b", + "deviceId": "16538383880670wenshidu0100600013b", + "productKey": "6kYp6jszrDns2yh4", + "deviceName": "WENSHIDU01006", + "secret": "fEbdXEayedpBx6wk", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655416485433 + }, + "property": { + "humidity": 95, + "temperature": 394 + }, + "tag": {}, + "createAt": 1653838388067 + }, + { + "id": "16538383850710wenshidu01005000134", + "deviceId": "16538383850710wenshidu01005000134", + "productKey": "6kYp6jszrDns2yh4", + "deviceName": "WENSHIDU01005", + "secret": "Crm28CTD6iw7hYw5", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655416485531 + }, + "property": { + "humidity": 23, + "temperature": 425 + }, + "tag": {}, + "createAt": 1653838385071 + }, + { + "id": "16538383810690wenshidu01004000132", + "deviceId": "16538383810690wenshidu01004000132", + "productKey": "6kYp6jszrDns2yh4", + "deviceName": "WENSHIDU01004", + "secret": "FkCQGREXYCmjzxaZ", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655416485631 + }, + "property": { + "humidity": 96, + "temperature": 263 + }, + "tag": {}, + "createAt": 1653838381074 + }, + { + "id": "16537595658790linght0010030000128", + "deviceId": "16537595658790linght0010030000128", + "productKey": "xpsYHExTKPFaQMS7", + "deviceName": "LINGHT001003", + "secret": "JwKxnDWGrRcP8xAJ", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839919567 + }, + "property": { + "brightness": 9, + "powerstate": 0 + }, + "tag": {}, + "createAt": 1653759565879 + }, + { + "id": "16537595624750linght001002000012c", + "deviceId": "16537595624750linght001002000012c", + "productKey": "xpsYHExTKPFaQMS7", + "deviceName": "LINGHT001002", + "secret": "xrX2mrkQwf3YYaWc", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839919576 + }, + "property": { + "brightness": 83, + "powerstate": 1 + }, + "tag": {}, + "createAt": 1653759562475 + }, + { + "id": "16537595591780linght0010010000121", + "deviceId": "16537595591780linght0010010000121", + "productKey": "xpsYHExTKPFaQMS7", + "deviceName": "LINGHT001001", + "secret": "diRBkEREDt47MzWF", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839919673 + }, + "property": { + "brightness": 81, + "powerstate": 1 + }, + "tag": {}, + "createAt": 1653759559178 + }, + { + "id": "16537595308820fan000100300000010d", + "deviceId": "16537595308820fan000100300000010d", + "productKey": "hdX3PCMcFrCYpesJ", + "deviceName": "FAN0001003", + "secret": "fR3R3i8BYDKWAiDj", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false + }, + "property": {}, + "tag": {}, + "createAt": 1653759530882 + }, + { + "id": "16537595248720fan0001002000000101", + "deviceId": "16537595248720fan0001002000000101", + "productKey": "hdX3PCMcFrCYpesJ", + "deviceName": "FAN0001002", + "secret": "t3NYS5p7ExYaWKx4", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false + }, + "property": {}, + "tag": {}, + "createAt": 1653759524872 + }, + { + "id": "16537595195720fan0001001000000108", + "deviceId": "16537595195720fan0001001000000108", + "productKey": "hdX3PCMcFrCYpesJ", + "deviceName": "FAN0001001", + "secret": "KSpeRjXRP8H7tcAn", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false + }, + "property": {}, + "tag": {}, + "createAt": 1653759519572 + }, + { + "id": "16537594784840wenshidu0100300013a", + "deviceId": "16537594784840wenshidu0100300013a", + "productKey": "6kYp6jszrDns2yh4", + "deviceName": "WENSHIDU01003", + "secret": "DSBbhJW7cGXRWeZA", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839926671 + }, + "property": { + "humidity": 45, + "temperature": 123 + }, + "tag": {}, + "createAt": 1653759478484 + }, + { + "id": "16537594752710wenshidu0100200013d", + "deviceId": "16537594752710wenshidu0100200013d", + "productKey": "6kYp6jszrDns2yh4", + "deviceName": "WENSHIDU01002", + "secret": "5bm8pNYcdj7YPMXn", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839926777 + }, + "property": { + "humidity": 6, + "temperature": 28 + }, + "tag": {}, + "createAt": 1653759475271 + }, + { + "id": "16537594707840wenshidu0100100013c", + "deviceId": "16537594707840wenshidu0100100013c", + "productKey": "6kYp6jszrDns2yh4", + "deviceName": "WENSHIDU01001", + "secret": "neSfPnhsjCsQiCQx", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653839927067 + }, + "property": { + "humidity": 35, + "temperature": 392 + }, + "tag": {}, + "createAt": 1653759470784 + }, + { + "id": "16537591055800menci0001003000012e", + "deviceId": "16537591055800menci0001003000012e", + "productKey": "PN3EDmkBZDD8whDd", + "deviceName": "MENCI0001003", + "secret": "2D2k8mmHbi2AMh8G", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653785231385 + }, + "property": { + "doorStatus": 1, + "power": 70, + "rssi": 38 + }, + "tag": {}, + "createAt": 1653759105580 + }, + { + "id": "16537590838150menci00010020000128", + "deviceId": "16537590838150menci00010020000128", + "productKey": "PN3EDmkBZDD8whDd", + "deviceName": "MENCI0001002", + "secret": "AQHQJTQ2iXkncb3C", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653785231786 + }, + "property": { + "doorStatus": 1, + "power": 99, + "rssi": 48 + }, + "tag": {}, + "createAt": 1653759083815 + }, + { + "id": "16537590780810menci0001001000012b", + "deviceId": "16537590780810menci0001001000012b", + "productKey": "PN3EDmkBZDD8whDd", + "deviceName": "MENCI0001001", + "secret": "PwYEKSARBJjD4y6B", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653785232184 + }, + "property": { + "doorStatus": 1, + "power": 67, + "rssi": 54 + }, + "tag": {}, + "createAt": 1653759078092 + }, + { + "id": "16534030209640test001230100000118", + "deviceId": "16534030209640test001230100000118", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "TEST0012301", + "secret": "C8YxCycFFeQDPKX4", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653730979070 + }, + "property": { + "DeviceType": "", + "powerstate": 1, + "rssi": 15 + }, + "tag": {}, + "createAt": 1653403020971 + }, + { + "id": "16514657683280abe125000010000011f", + "deviceId": "16514657683280abe125000010000011f", + "productKey": "AWcJnf7ymGSkaz5M", + "deviceName": "ABE12500001", + "model": "M1", + "parentId": "16514626212240aabbccee01000000143", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653380321483 + }, + "property": { + "powerstate": "1", + "power": "1", + "rssi": "1", + "switch": "3232", + "current": "10000", + "electricty": "10" + }, + "tag": {}, + "createAt": 1651465768328 + }, + { + "id": "16514627991620aabbccdd1000000014f", + "deviceId": "16514627991620aabbccdd1000000014f", + "productKey": "hbtgIA0SuVw9lxjB", + "deviceName": "AA:BB:CC:DD:10", + "model": "GW01", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653185932725, + "offlineTime": 1653187754035 + }, + "property": {}, + "tag": {}, + "createAt": 1651462799162 + }, + { + "id": "16514626218250abe124000010000011a", + "deviceId": "16514626218250abe124000010000011a", + "productKey": "6kYp6jszrDns2yh4", + "deviceName": "ABE12400001", + "model": "S1", + "parentId": "16514626212240aabbccee01000000143", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653380322090, + "offlineTime": 1652593079579 + }, + "property": { + "humidity": 14, + "temperature": 447 + }, + "tag": {}, + "createAt": 1651462621825 + }, + { + "id": "16514626216250abe1230000200000114", + "deviceId": "16514626216250abe1230000200000114", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "ABE12300002", + "model": "S1", + "parentId": "16514626212240aabbccee01000000143", + "uid": "15620886-b30d-439d-9e5f-13a094c1f1f9", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653380319984, + "offlineTime": 1652593079484 + }, + "property": { + "powerstate": 0, + "rssi": 26 + }, + "tag": {}, + "createAt": 1651462621625 + }, + { + "id": "16514626214280abe1230000100000116", + "deviceId": "16514626214280abe1230000100000116", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "ABE12300001", + "model": "S1", + "parentId": "16514626212240aabbccee01000000143", + "uid": "15620886-b30d-439d-9e5f-13a094c1f1f9", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653380317469, + "offlineTime": 1652593079473 + }, + "property": { + "powerstate": 1, + "rssi": 48 + }, + "tag": {}, + "createAt": 1651462621428 + }, + { + "id": "16514626212240aabbccee01000000143", + "deviceId": "16514626212240aabbccee01000000143", + "productKey": "N523nWsCiG3CAn6X", + "deviceName": "AA:BB:CC:EE:01", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653380312358, + "offlineTime": 1652593079381 + }, + "property": { + "UnbindAndDelete": "1" + }, + "tag": {}, + "createAt": 1651462621224 + }, + { + "id": "16501898583770f4cce4feffbd1bec164", + "deviceId": "16501898583770f4cce4feffbd1bec164", + "productKey": "PN3EDmkBZDD8whDd", + "deviceName": "F4CCE4FEFFBD1BEC", + "model": "device", + "parentId": "165017126122400cefafcfee61000012b", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655415536433, + "offlineTime": 1652669743574 + }, + "property": { + "DeviceType": "TY0203@_TZ1800_ho6i0zk9", + "power": 12, + "doorStatus": 1, + "rssi": 42 + }, + "tag": { + "aligenie": { + "id": "aligenie", + "name": "天猫精灵接入", + "value": "是" + } + }, + "createAt": 1650189858377 + }, + { + "id": "16501806313260000833feffac33bc16c", + "deviceId": "16501806313260000833feffac33bc16c", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "000833FEFFAC33BC", + "model": "device", + "parentId": "165017126122400cefafcfee61000012b", + "uid": "15620886-b30d-439d-9e5f-13a094c1f1f9", + "subUid": [ + "04c6722f-9a6d-40f3-ac9b-cd791b4c8933" + ], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1652602130873, + "offlineTime": 1652669743479 + }, + "property": { + "DeviceType": "S2100-5102@_TZ2000_muw96vx2ppq6zh2k", + "powerstate": 1, + "rssi": -32 + }, + "tag": { + "aligenie": { + "id": "aligenie", + "name": "天猫精灵", + "value": "是" + }, + "dueros": { + "id": "dueros", + "name": "小度", + "value": "是" + }, + "duerosOpenUid": { + "id": "duerosOpenUid", + "name": "小度OpenUid", + "value": "0cfd14fc6d1ec120fcd38885df09f33c" + } + }, + "createAt": 1650180631326 + }, + { + "id": "165017126122400cefafcfee61000012b", + "deviceId": "165017126122400cefafcfee61000012b", + "productKey": "N523nWsCiG3CAn6X", + "deviceName": "0CEFAFCFEE61", + "subUid": [ + "04c6722f-9a6d-40f3-ac9b-cd791b4c8933" + ], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1652602115884, + "offlineTime": 1652669743471 + }, + "property": { + "DeviceType": "WIDORA-BIT5" + }, + "tag": { + "aligenie": { + "id": "aligenie", + "name": "天猫精灵", + "value": "是" + }, + "dueros": { + "id": "dueros", + "name": "小度", + "value": "是" + }, + "duerosOpenUid": { + "id": "duerosOpenUid", + "name": "小度OpenUid", + "value": "0cfd14fc6d1ec120fcd38885df09f33c" + } + }, + "createAt": 1650171261224 + }, + { + "id": "164785263238900cefafcfeeab0000125", + "deviceId": "164785263238900cefafcfeeab0000125", + "productKey": "N523nWsCiG3CAn6X", + "deviceName": "0CEFAFCFEEAB", + "subUid": [ + "629daa3de5a005209d182876" + ], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655581924548, + "offlineTime": 1655581807987 + }, + "property": { + "DeviceType": "WIDORA-BIT5" + }, + "tag": { + "dueros": { + "id": "dueros", + "name": "小度", + "value": "是" + }, + "duerosOpenUid": { + "id": "duerosOpenUid", + "name": "小度OpenUid", + "value": "b980663dfbcf35126bb5b85031c3413a" + } + }, + "group": {}, + "createAt": 1647852632389 + }, + { + "id": "16477632226720c2cc9f03008d1500166", + "deviceId": "16477632226720c2cc9f03008d1500166", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "C2CC9F03008D1500", + "model": "device", + "parentId": "164785263238900cefafcfeeab0000125", + "subUid": [ + "629daa3de5a005209d182876" + ], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655581925148, + "offlineTime": 1655581808150 + }, + "property": { + "DeviceType": "lumi.plug@LUMI", + "powerstate": 0, + "rssi": -77 + }, + "tag": { + "dueros": { + "id": "dueros", + "name": "小度", + "value": "是" + }, + "duerosOpenUid": { + "id": "duerosOpenUid", + "name": "小度OpenUid", + "value": "b980663dfbcf35126bb5b85031c3413a" + } + }, + "group": {}, + "createAt": 1647763222672 + }, + { + "id": "164776322227201472a803008d150016e", + "deviceId": "164776322227201472a803008d150016e", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "1472A803008D1500", + "model": "device", + "parentId": "164785263238900cefafcfeeab0000125", + "subUid": [ + "629daa3de5a005209d182876" + ], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655581925152, + "offlineTime": 1655581808148 + }, + "property": { + "DeviceType": "lumi.plug@LUMI", + "powerstate": 1, + "rssi": -77 + }, + "tag": { + "dueros": { + "id": "dueros", + "name": "小度", + "value": "是" + }, + "duerosOpenUid": { + "id": "duerosOpenUid", + "name": "小度OpenUid", + "value": "b980663dfbcf35126bb5b85031c3413a" + } + }, + "group": {}, + "createAt": 1647763222272 + }, + { + "id": "1647763221972019a89f03008d1500163", + "deviceId": "1647763221972019a89f03008d1500163", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "19A89F03008D1500", + "model": "device", + "parentId": "164785263238900cefafcfeeab0000125", + "subUid": [ + "629daa3de5a005209d182876" + ], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655581925157, + "offlineTime": 1655581808053 + }, + "property": { + "DeviceType": "lumi.plug@LUMI", + "powerstate": 1, + "rssi": -80 + }, + "tag": { + "dueros": { + "id": "dueros", + "name": "小度", + "value": "是" + }, + "duerosOpenUid": { + "id": "duerosOpenUid", + "name": "小度OpenUid", + "value": "b980663dfbcf35126bb5b85031c3413a" + } + }, + "group": {}, + "createAt": 1647763221972 + }, + { + "id": "16477632215720c11b1602008d1500160", + "deviceId": "16477632215720c11b1602008d1500160", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "C11B1602008D1500", + "model": "device", + "parentId": "164785263238900cefafcfeeab0000125", + "subUid": [ + "629daa3de5a005209d182876" + ], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655581925252, + "offlineTime": 1655581808052 + }, + "property": { + "DeviceType": "lumi.plug@LUMI", + "powerstate": 1, + "rssi": -78 + }, + "tag": { + "dueros": { + "id": "dueros", + "name": "小度", + "value": "是" + }, + "duerosOpenUid": { + "id": "duerosOpenUid", + "name": "小度OpenUid", + "value": "b980663dfbcf35126bb5b85031c3413a" + } + }, + "group": {}, + "createAt": 1647763221572 + }, + { + "id": "164776322117404acb9f03008d1500168", + "deviceId": "164776322117404acb9f03008d1500168", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "4ACB9F03008D1500", + "model": "device", + "parentId": "164785263238900cefafcfeeab0000125", + "subUid": [ + "629daa3de5a005209d182876" + ], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655581925255, + "offlineTime": 1655581808049 + }, + "property": { + "DeviceType": "lumi.plug@LUMI", + "powerstate": 1, + "rssi": -78 + }, + "tag": { + "dueros": { + "id": "dueros", + "name": "小度", + "value": "是" + }, + "duerosOpenUid": { + "id": "duerosOpenUid", + "name": "小度OpenUid", + "value": "b980663dfbcf35126bb5b85031c3413a" + } + }, + "group": {}, + "createAt": 1647763221174 + }, + { + "id": "1647690908735019dd9f03008d1500163", + "deviceId": "1647690908735019dd9f03008d1500163", + "productKey": "cGCrkK7Ex4FESAwe", + "deviceName": "19DD9F03008D1500", + "model": "device", + "parentId": "164785263238900cefafcfeeab0000125", + "subUid": [ + "629daa3de5a005209d182876" + ], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1655581925247, + "offlineTime": 1655581808009 + }, + "property": { + "powerstate": 1, + "DeviceType": "lumi.plug@LUMI", + "rssi": -78 + }, + "tag": { + "dueros": { + "id": "dueros", + "name": "小度", + "value": "是" + }, + "duerosOpenUid": { + "id": "duerosOpenUid", + "name": "小度OpenUid", + "value": "b980663dfbcf35126bb5b85031c3413a" + } + }, + "group": {}, + "createAt": 1647690908735 + }, + { + "id": "16465723457670abd123000020000011c", + "deviceId": "16465723457670abd123000020000011c", + "productKey": "hdX3PCMcFrCYpesJ", + "deviceName": "ABD12300002", + "model": "F01", + "parentId": "16465226744430aabbccdd22000000143", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653380311848, + "offlineTime": 1653380472842 + }, + "property": { + "windSpeed": "7", + "powerSwitch": "1", + "workMode": "5" + }, + "tag": {}, + "createAt": 1646572345767 + }, + { + "id": "16465723454670abd1230000100000117", + "deviceId": "16465723454670abd1230000100000117", + "productKey": "hdX3PCMcFrCYpesJ", + "deviceName": "ABD12300001", + "model": "F01", + "parentId": "16465226744430aabbccdd22000000143", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653380308883, + "offlineTime": 1653380472498 + }, + "property": { + "windSpeed": "68" + }, + "tag": {}, + "createAt": 1646572345467 + }, + { + "id": "16465723451670abc123000030000011a", + "deviceId": "16465723451670abc123000030000011a", + "productKey": "Rf4QSjbm65X45753", + "deviceName": "ABC12300003", + "model": "S01", + "parentId": "16465226744430aabbccdd22000000143", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653729780071, + "offlineTime": 1653380472221 + }, + "property": { + "powerstate": 0, + "volt": 81 + }, + "tag": {}, + "createAt": 1646572345167 + }, + { + "id": "16465723448670abc1230000200000115", + "deviceId": "16465723448670abc1230000200000115", + "productKey": "Rf4QSjbm65X45753", + "deviceName": "ABC12300002", + "model": "S01", + "parentId": "16465226744430aabbccdd22000000143", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653729780174, + "offlineTime": 1653380471930 + }, + "property": { + "powerstate": 1, + "volt": 69 + }, + "tag": {}, + "createAt": 1646572344867 + }, + { + "id": "16465226744430aabbccdd22000000143", + "deviceId": "16465226744430aabbccdd22000000143", + "productKey": "hbtgIA0SuVw9lxjB", + "deviceName": "AA:BB:CC:DD:22", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653380299997, + "offlineTime": 1653380471302 + }, + "property": {}, + "tag": {}, + "createAt": 1646522674443 + }, + { + "id": "168187356997901234567891230000120", + "deviceId": "168187356997901234567891230000120", + "productKey": "BRD3x4fkKxkaxXFt", + "deviceName": "123456789123", + "uid": "1", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653380299997, + "offlineTime": 1653380471302 + }, + "property": {}, + "tag": {}, + "createAt": 1646522674443 + }, + { + "id": "168191541600402017121609130000126", + "deviceId": "168191541600402017121609130000126", + "productKey": "PwMfpXmp4ZWkGahn", + "deviceName": "201712160913", + "uid": "1", + "parentId": "168187356997901234567891230000120", + "subUid": [], + "locate":{ + "longitude": "104.090377", + "latitude": "30.604218" + }, + "state": { + "online": false, + "onlineTime": 1653380299997, + "offlineTime": 1653380471302 + }, + "property": {}, + "tag": {}, + "createAt": 1646522674443 + }, + { + "id": "16891445583920testpump0100000010f", + "deviceId": "16891445583920testpump0100000010f", + "productKey": "openiitapump01", + "deviceName": "testpump01", + "model": null, + "secret": "8cB3W8NzjP3rFY6W", + "parentId": "16891443313530testgateway0100013d", + "uid": "1", + "subUid": null, + "locate": { + "longitude": null, + "latitude": null + }, + "state": { + "online": false, + "onlineTime": 0, + "offlineTime": 0 + }, + "property": null, + "tag": null, + "group": {}, + "createAt": 1689144558392 + }, + { + "id": "16891443313530testgateway0100013d", + "deviceId": "16891443313530testgateway0100013d", + "productKey": "openiitagateway01", + "deviceName": "testgateway01", + "model": null, + "secret": "bnw2Z6zNxxdBtm6N", + "parentId": null, + "uid": "1", + "subUid": null, + "locate": { + "longitude": "113.865453", + "latitude": "22.583686" + }, + "state": { + "online": false, + "onlineTime": 0, + "offlineTime": 0 + }, + "property": null, + "tag": null, + "group": {}, + "createAt": 1689144331356 + }, + { + "id": "16895701241450testnbpump010000125", + "deviceId": "16895701241450testnbpump010000125", + "productKey": "openiitanbpump01", + "deviceName": "testnbpump01", + "model": null, + "secret": "eY45WnZEWRryR2xt", + "parentId": null, + "uid": "1", + "subUid": null, + "locate": { + "longitude": "113.865453", + "latitude": "22.583686" + }, + "state": { + "online": false, + "onlineTime": 0, + "offlineTime": 0 + }, + "property": null, + "tag": null, + "group": {}, + "createAt": 1689570124148 + } +] \ No newline at end of file diff --git a/data/init/home.json b/data/init/home.json new file mode 100644 index 0000000..0070534 --- /dev/null +++ b/data/init/home.json @@ -0,0 +1,121 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320542, + "updateBy" : null, + "updateTime" : 1708254320542, + "tenantId" : 0, + "id" : 1, + "name" : "我的家庭", + "address" : "", + "userId" : 1, + "spaceNum" : 0, + "deviceNum" : 0, + "current" : true, + "spaces" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320593, + "updateBy" : null, + "updateTime" : 1708254320593, + "tenantId" : 0, + "id" : 2, + "name" : "我的家", + "address" : null, + "userId" : 3, + "spaceNum" : null, + "deviceNum" : null, + "current" : true, + "spaces" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320600, + "updateBy" : null, + "updateTime" : 1708254320600, + "tenantId" : 0, + "id" : 3, + "name" : "我深圳的家", + "address" : "广东省深圳市南山区西丽镇", + "userId" : 1, + "spaceNum" : null, + "deviceNum" : null, + "current" : true, + "spaces" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320605, + "updateBy" : null, + "updateTime" : 1708254320605, + "tenantId" : 0, + "id" : 4, + "name" : "我深圳的家", + "address" : "广东省深圳市南山区西丽镇", + "userId" : 1, + "spaceNum" : null, + "deviceNum" : null, + "current" : null, + "spaces" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320609, + "updateBy" : null, + "updateTime" : 1708254320609, + "tenantId" : 0, + "id" : 5, + "name" : "我深圳的家", + "address" : "广东省深圳市南山区西丽镇", + "userId" : 1, + "spaceNum" : null, + "deviceNum" : null, + "current" : null, + "spaces" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320613, + "updateBy" : null, + "updateTime" : 1708254320613, + "tenantId" : 0, + "id" : 6, + "name" : "我深圳的家", + "address" : "广东省深圳市南山区西丽镇", + "userId" : 1, + "spaceNum" : null, + "deviceNum" : null, + "current" : null, + "spaces" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320618, + "updateBy" : null, + "updateTime" : 1708254320618, + "tenantId" : 0, + "id" : 7, + "name" : "myhome", + "address" : "shengzhen nanshan", + "userId" : 1, + "spaceNum" : null, + "deviceNum" : null, + "current" : null, + "spaces" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320622, + "updateBy" : null, + "updateTime" : 1708254320622, + "tenantId" : 0, + "id" : 8, + "name" : "myhome", + "address" : "shengzhen nanshan", + "userId" : 1, + "spaceNum" : null, + "deviceNum" : null, + "current" : null, + "spaces" : null +} ] \ No newline at end of file diff --git a/data/init/icon.json b/data/init/icon.json new file mode 100644 index 0000000..5bb553b --- /dev/null +++ b/data/init/icon.json @@ -0,0 +1,814 @@ +[{ + "id": 541690159243333, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "行人道闸", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" +}, + { + "id": 541688704299077, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "信息", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541688627888197, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "指纹解锁", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541684987850821, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "出门", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541684915748933, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "车牌识别", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677836591173, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "门禁卡", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677777145925, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "电视", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677728616517, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "人脸识别", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677673070661, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "智能灯光", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677410635845, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "数字密码", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677357146181, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "语音对讲", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677302734917, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "信息", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677246382149, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "摄像枪", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677184880709, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "可视对讲机", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677128994885, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "门磁传感器", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677077753925, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "摄像头", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541677029232709, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "天气", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676952887365, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "降噪", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676899274821, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "时钟", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676816535621, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "手机", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676716355653, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "交换机", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676662272069, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "视频留言", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676613619781, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "燃气报警2", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676560719941, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "声光报警", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676497973317, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "火警", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676441411653, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "燃气报警器", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676382064709, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "门锁", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676324876357, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "静音", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676262502469, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "控制中心", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676185849925, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "红外传感器", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676067336261, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconName": "开锁", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541676000055365, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconName": "车道闸", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541673610784837, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0,"createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "安防", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541673324064837, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "电梯", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541670730166341, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541592097542213, + "iconName": "火灾报警", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541692991926341, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "粉尘监测", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541692883537989, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "柴油发电机", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541692800434245, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "报警主机", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541692587135045, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "智能插座", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541692406415429, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "物联网网关", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541692350357573, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "变压器温度", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541692266471493, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "中央空调", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541692181463109, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "故障", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541692105846853, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "红外探测器", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541692032311365, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "报警", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691913609285, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "火警", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691834851397, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "液位传感器", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691760943173, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "感温探测器", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691676672069, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "表面温度", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691618164805, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "液压传感器", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691548655685, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "消防水泵", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691497037893, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "排风机", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691433111621, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "温湿度", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691381289029, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "视频", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691293118533, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "电器火灾", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691126554693, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "消防用水", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541691056250949, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "无线火灾报警", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }, + { + "id": 541690984403013, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "iconTypeId": 541673667244101, + "iconName": "火灾报警", + "viewBox": "0 0 1024 1024", + "xmlns": "http://www.w3.org/2000/svg", + "version": "1.1", + "iconContent": "" + }] \ No newline at end of file diff --git a/data/init/iconType.json b/data/init/iconType.json new file mode 100644 index 0000000..dfe11ec --- /dev/null +++ b/data/init/iconType.json @@ -0,0 +1,19 @@ +[ { + "id" : 541592097542213, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "typeDescribe" : null, + "typeName" : "智能家居" +}, { + "id" : 541673667244101, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "typeDescribe" : null, + "typeName" : "工业物联网" +}] \ No newline at end of file diff --git a/data/init/notifyMessage.json b/data/init/notifyMessage.json new file mode 100644 index 0000000..d984df2 --- /dev/null +++ b/data/init/notifyMessage.json @@ -0,0 +1,85 @@ +[ { + "id" : 31, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : false, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +}, { + "id" : 5756, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : true, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +}, { + "id" : 9789, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : false, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +}, { + "id" : 56856, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : true, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +}, { + "id" : 67567, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : true, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +}, { + "id" : 90890, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : true, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +}, { + "id" : 151515, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : false, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +}, { + "id" : 1231312, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : true, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +}, { + "id" : 4324234, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : true, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +}, { + "id" : 4534346, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : false, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +}, { + "id" : 4534636, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : true, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +}, { + "id" : 64432342, + "content" : "你的设备【热水器】温度过高", + "messageType" : "alert", + "status" : true, + "createAt" : 1683816661690, + "updateAt" : 1683816661690 +} ] \ No newline at end of file diff --git a/data/init/oauthClient.json b/data/init/oauthClient.json new file mode 100644 index 0000000..64adb29 --- /dev/null +++ b/data/init/oauthClient.json @@ -0,0 +1,16 @@ +[ + { + "clientId": "iotkit", + "name": "奇特物联", + "clientSecret": "b86cb53d-c005-48a3-bb02-3c262151b68c", + "allowUrl": "*", + "createAt": 1652840868485 + }, + { + "clientId": "dueros", + "name": "小度音箱", + "clientSecret": "750c67c2-29cb-40c3-bf4d-c0b9bf3eed88", + "allowUrl": "*", + "createAt": 1652840868485 + } +] \ No newline at end of file diff --git a/data/init/pluginInfo.json b/data/init/pluginInfo.json new file mode 100644 index 0000000..ba67b32 --- /dev/null +++ b/data/init/pluginInfo.json @@ -0,0 +1,58 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : 1708317062484, + "updateBy" : null, + "updateTime" : 1708317122265, + "id" : 516835985375301, + "pluginId" : "http-plugin", + "name" : "http插件", + "description" : "http示例插件,配置参数:端口(port)默认9081-初次使用,请重新上传", + "deployType" : "upload", + "file" : "http-plugin-1.0.1-repackage.jar", + "version" : "1.0.1", + "type" : null, + "protocol" : null, + "state" : "stopped", + "configSchema" : "[\n {\n \"id\": \"port\",\n \"name\": \"端口\",\n \"type\": \"number\",\n \"value\": 9081,\n \"desc\": \"http端口,默认为9081\"\n },\n {\n \"id\": \"a\",\n \"name\": \"测试参数1\",\n \"type\": \"radio\",\n \"value\": 0,\n \"desc\": \"单选参数a\",\n \"options\": [\n {\n \"name\": \"值0\",\n \"value\": 0\n },\n {\n \"name\": \"值1\",\n \"value\": 11\n }\n ]\n }\n]", + "config" : null, + "script" : "" +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708317067797, + "updateBy" : null, + "updateTime" : 1708317171964, + "id" : 516836007116869, + "pluginId" : "mqtt-plugin", + "name" : "mqtt插件", + "description" : "mqtt示例插件-初次使用,请重新上传", + "deployType" : "upload", + "file" : "mqtt-plugin-1.0.1-repackage.jar", + "version" : "1.0.1", + "type" : null, + "protocol" : null, + "state" : "stopped", + "configSchema" : "[\n {\n \"id\": \"port\",\n \"name\": \"端口\",\n \"type\": \"number\",\n \"value\": 1883,\n \"desc\": \"mqtt端口,默认为1883\"\n }\n]", + "config" : null, + "script" : "" +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708317072837, + "updateBy" : null, + "updateTime" : 1708317204758, + "id" : 516836027760709, + "pluginId" : "tcp-plugin", + "name" : "tcp插件", + "description" : "tcp示例插件-初次使用,请重新上传", + "deployType" : "upload", + "file" : "tcp-plugin-1.0.4-repackage.jar", + "version" : "1.0.4", + "type" : null, + "protocol" : null, + "state" : "stopped", + "configSchema" : "[\n {\n \"id\": \"host\",\n \"name\": \"绑定ip\",\n \"type\": \"text\",\n \"value\": \"127.0.0.1\",\n \"desc\": \"tcp绑定ip,默认为127.0.0.1\"\n },\n {\n \"id\": \"port\",\n \"name\": \"端口\",\n \"type\": \"number\",\n \"value\": 6883,\n \"desc\": \"tcp端口,默认为6883\"\n }\n]", + "config" : null, + "script" : "function hexToByte(hexString) {\n if (hexString.length % 2 !== 0) {\n throw new Error('Invalid hex string. String must have an even number of characters.');\n }\n\n let byteArray = [];\n for (let i = 0; i < hexString.length; i += 4) {\n byteArray.push(parseInt(hexString.substr(i, 4), 16));\n }\n\n return byteArray;\n}\nfunction byteToHex(bytes) {\n for (var hex = [], i = 0; i < bytes.length; i++) {\n hex.push((bytes[i] >>> 4).toString(16));\n hex.push((bytes[i] & 0xF).toString(16));\n }\n return hex.join(\"\");\n}\n\nthis.decode=function(data){\n hex=data.payload;\n const bytes=hexToByte(hex);\n return {\n \"rssi\":bytes[0],\n \"powerstate\":bytes[1]\n };\n}\n\nthis.encode=function(params){\n const hex=byteToHex([params.powerstate]);\n return hex;\n}" +} ] \ No newline at end of file diff --git a/data/init/product.json b/data/init/product.json new file mode 100644 index 0000000..cd5ce92 --- /dev/null +++ b/data/init/product.json @@ -0,0 +1,373 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 1, + "productKey" : "openiitagateway01", + "productSecret" : "openiitasecret01", + "name" : "禹霖科技智能网关01", + "category" : "OpenIitaGateway", + "nodeType" : 0, + "uid" : "1", + "img" : null, + "iconId" : null, + "transparent" : false, + "isOpenLocate" : true, + "locateUpdateType" : "manual", + "createAt" : 1649653149339 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 2, + "productKey" : "openiitapump01", + "productSecret" : "openiitapump01", + "name" : "禹霖科技-单泵01", + "category" : "OpenIitaPump", + "nodeType" : 1, + "uid" : "1", + "img" : null, + "iconId" : null, + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : "manual", + "createAt" : 1649653149339 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 3, + "productKey" : "openiitanbpump01", + "productSecret" : "openiitanbpump01", + "name" : "NB透传水泵", + "category" : "OpenIitaPump", + "nodeType" : 2, + "uid" : "1", + "img" : null, + "iconId" : null, + "transparent" : false, + "isOpenLocate" : true, + "locateUpdateType" : "device", + "createAt" : 1649653149339 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994839621, + "productKey" : "xpsYHExTKPFaQMS7", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "调光灯", + "category" : "light", + "nodeType" : 1, + "uid" : "1", + "img" : null, + "iconId" : null, + "transparent" : false, + "isOpenLocate" : true, + "locateUpdateType" : "manual", + "createAt" : 1650174777304 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994847813, + "productKey" : "hdX3PCMcFrCYpesJ", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "智能风扇", + "category" : "fan", + "nodeType" : 1, + "uid" : "1", + "img" : null, + "iconId" : null, + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1646571291131 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994860101, + "productKey" : "hbtgIA0SuVw9lxjB", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "GW01网关", + "category" : "gateway", + "nodeType" : 0, + "uid" : "1", + "img" : "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/hbtgIA0SuVw9lxjB/cover.jpg?Expires=1967598154&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=2gh2jad14mVHGvWThwOd%2FykiB5g%3D", + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1652238155938 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994864197, + "productKey" : "eDhXKwEzwFybM5R7", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "三路开关", + "category" : "switch", + "nodeType" : 1, + "uid" : "1", + "img" : "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/eDhXKwEzwFybM5R7/cover.jpeg?Expires=1967598172&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=ZrFgANkomVEDQRV5JdmONL0S2sY%3D", + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1652238173536 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994876485, + "productKey" : "cGCrkK7Ex4FESAwe", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "插座", + "category" : "SmartPlug", + "nodeType" : 1, + "uid" : "1", + "img" : "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/cGCrkK7Ex4FESAwe/cover.jpeg?Expires=1967598137&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=vOjqav0pRZqQFgx8xBo99WhgWXk%3D", + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1652238138626 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994880581, + "productKey" : "Rf4QSjbm65X45753", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "一路开关", + "category" : "switch", + "nodeType" : 1, + "uid" : "1", + "img" : "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/Rf4QSjbm65X45753/cover.jpeg?Expires=1967598145&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=ksQhmEm5Rn7C7FFqY09o9l%2BZ%2BIQ%3D", + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1652238147123 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994884677, + "productKey" : "PN3EDmkBZDD8whDd", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "门磁", + "category" : "door", + "nodeType" : 1, + "uid" : "1", + "img" : "null", + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1650190400357 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994896965, + "productKey" : "N523nWsCiG3CAn6X", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "ZGW01", + "category" : "gateway", + "nodeType" : 0, + "uid" : "1", + "img" : "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/N523nWsCiG3CAn6X/cover.jpg?Expires=1967597641&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=%2BaGcHBT%2FHA3s%2BrZ687U50b4YE0A%3D", + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1652237643216 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994901061, + "productKey" : "Eit3kmGJtxSHfCKT", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "燃气表", + "category" : "meter", + "nodeType" : 2, + "uid" : "1", + "img" : null, + "iconId" : null, + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1654237604221 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994905157, + "productKey" : "DSGxxKk6E8mmDk6C", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "通断器", + "category" : "switch", + "nodeType" : 1, + "uid" : "1", + "img" : "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/DSGxxKk6E8mmDk6C/cover.jpeg?Expires=1967598201&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=k2PqHc%2BI14DfCwD8kQIflwoBAog%3D", + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1652238202310 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994909253, + "productKey" : "D8c5pXFmt2KJDxNm", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "四路场景面板", + "category" : "switch", + "nodeType" : 1, + "uid" : "1", + "img" : null, + "iconId" : null, + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1650187781637 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994913349, + "productKey" : "AWcJnf7ymGSkaz5M", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "smart pulg", + "category" : "SmartPlug", + "nodeType" : 1, + "uid" : "1", + "img" : "http://iotkit-img.oss-cn-shenzhen.aliyuncs.com/product/AWcJnf7ymGSkaz5M/cover.jpeg?Expires=1967598035&OSSAccessKeyId=LTAI5tGEHNoVu5tWHUWnosrs&Signature=tXzWH5%2B4JNcnuTFrJbvGwsbx97c%3D", + "transparent" : true, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1652279098100 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994925637, + "productKey" : "6kYp6jszrDns2yh4", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "温湿度传感器", + "category" : "sensor", + "nodeType" : 1, + "uid" : "1", + "img" : null, + "iconId" : null, + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1649653149339 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994933829, + "productKey" : "bGdZt8ffBETtsirm", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "新风", + "category" : "FreshAir", + "nodeType" : 1, + "uid" : "1", + "img" : null, + "iconId" : null, + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1649653149339 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994942021, + "productKey" : "BRD3x4fkKxkaxXFt", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "智能电表采集器", + "category" : "gateway", + "nodeType" : 0, + "uid" : "1", + "img" : null, + "iconId" : null, + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1649653149339 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "tenantId" : 0, + "id" : 516578994958405, + "productKey" : "PwMfpXmp4ZWkGahn", + "productSecret" : "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU", + "name" : "智能电表", + "category" : "SmartMeter", + "nodeType" : 1, + "uid" : "1", + "img" : null, + "iconId" : null, + "transparent" : false, + "isOpenLocate" : false, + "locateUpdateType" : null, + "createAt" : 1649653149339 +} ] diff --git a/data/init/productModel.json b/data/init/productModel.json new file mode 100644 index 0000000..2f705f1 --- /dev/null +++ b/data/init/productModel.json @@ -0,0 +1,10 @@ +[ { + "id" : "M1", + "model" : null, + "name" : "型号1", + "productKey" : "AWcJnf7ymGSkaz5M", + "type" : "LuaScript", + "script" : "\nfunction decode(msg)\n return {\n ['identifier'] = 'report',\n ['mid'] = '1',\n ['type'] = 'property',\n ['data'] ={\n ['power']=string.sub(msg.data,3,3)\n }\n }\nend\n\nfunction encode(service)\n return {\n\t['mid'] = 1,\n\t['model'] = 'M1',\n\t['mac'] = service.deviceName,\n\t['data'] = 'BB2'\n }\nend\n", + "state" : "publish", + "modifyAt" : 1708254320711 +} ] \ No newline at end of file diff --git a/data/init/ruleInfo.json b/data/init/ruleInfo.json new file mode 100644 index 0000000..5504692 --- /dev/null +++ b/data/init/ruleInfo.json @@ -0,0 +1,23 @@ +[ { + "id" : "2c10229b-dcb2-439e-b411-5425b49657a1", + "name" : "小度设备属性更新推送", + "type" : "flow", + "listeners" : [ ], + "filters" : [ ], + "actions" : [ ], + "uid" : "1", + "state" : "running", + "desc" : "开关插座开关状态推送", + "createAt" : 1652515471242 +}, { + "id" : "2820c218-660e-48ff-a234-c7b6793a5bb8", + "name" : "测试场景1", + "type" : "scene", + "listeners" : [ ], + "filters" : [ ], + "actions" : [ ], + "uid" : "1", + "state" : "stopped", + "desc" : "test", + "createAt" : 1649167998895 +} ] \ No newline at end of file diff --git a/data/init/space.json b/data/init/space.json new file mode 100644 index 0000000..a616a34 --- /dev/null +++ b/data/init/space.json @@ -0,0 +1,100 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320774, + "updateBy" : null, + "updateTime" : 1708254320774, + "tenantId" : 0, + "id" : 1, + "homeId" : 1, + "name" : "123", + "deviceNum" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320794, + "updateBy" : null, + "updateTime" : 1708254320794, + "tenantId" : 0, + "id" : 2, + "homeId" : 1, + "name" : "123", + "deviceNum" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320798, + "updateBy" : null, + "updateTime" : 1708254320798, + "tenantId" : 0, + "id" : 3, + "homeId" : 1, + "name" : "客厅", + "deviceNum" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320804, + "updateBy" : null, + "updateTime" : 1708254320804, + "tenantId" : 0, + "id" : 4, + "homeId" : 1, + "name" : "卧室", + "deviceNum" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320809, + "updateBy" : null, + "updateTime" : 1708254320809, + "tenantId" : 0, + "id" : 5, + "homeId" : 1, + "name" : "客厅", + "deviceNum" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320813, + "updateBy" : null, + "updateTime" : 1708254320813, + "tenantId" : 0, + "id" : 6, + "homeId" : 1, + "name" : "阳台", + "deviceNum" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320817, + "updateBy" : null, + "updateTime" : 1708254320817, + "tenantId" : 0, + "id" : 7, + "homeId" : 1, + "name" : "厨房", + "deviceNum" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320824, + "updateBy" : null, + "updateTime" : 1708254320824, + "tenantId" : 0, + "id" : 8, + "homeId" : 1, + "name" : "卧室", + "deviceNum" : null +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254320852, + "updateBy" : null, + "updateTime" : 1708254320852, + "tenantId" : 0, + "id" : 9, + "homeId" : 1, + "name" : "客厅", + "deviceNum" : null +} ] \ No newline at end of file diff --git a/data/init/spaceDevice.json b/data/init/spaceDevice.json new file mode 100644 index 0000000..d5f1029 --- /dev/null +++ b/data/init/spaceDevice.json @@ -0,0 +1,131 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321238, + "updateBy" : null, + "updateTime" : 1708254321238, + "tenantId" : 0, + "id" : 1, + "deviceId" : "164785263238900cefafcfeeab0000125", + "name" : "卧室的ZGW01", + "homeId" : 1, + "spaceId" : 1, + "collect" : true +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321248, + "updateBy" : null, + "updateTime" : 1708254321248, + "tenantId" : 0, + "id" : 2, + "deviceId" : "164776322117404acb9f03008d1500168", + "name" : "卧室的插座", + "homeId" : 1, + "spaceId" : 1, + "collect" : true +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321252, + "updateBy" : null, + "updateTime" : 1708254321252, + "tenantId" : 0, + "id" : 3, + "deviceId" : "1647763221972019a89f03008d1500163", + "name" : "卧室的插座", + "homeId" : 1, + "spaceId" : 1, + "collect" : false +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321255, + "updateBy" : null, + "updateTime" : 1708254321255, + "tenantId" : 0, + "id" : 4, + "deviceId" : "164776322227201472a803008d150016e", + "name" : "卧室的插座", + "homeId" : 1, + "spaceId" : 1, + "collect" : false +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321258, + "updateBy" : null, + "updateTime" : 1708254321258, + "tenantId" : 0, + "id" : 5, + "deviceId" : "16477632226720c2cc9f03008d1500166", + "name" : "卧室的插座", + "homeId" : 1, + "spaceId" : 1, + "collect" : false +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321261, + "updateBy" : null, + "updateTime" : 1708254321261, + "tenantId" : 0, + "id" : 6, + "deviceId" : "16477632215720c11b1602008d1500160", + "name" : "卧室的插座", + "homeId" : 1, + "spaceId" : 1, + "collect" : false +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321264, + "updateBy" : null, + "updateTime" : 1708254321264, + "tenantId" : 0, + "id" : 7, + "deviceId" : "1647690908735019dd9f03008d1500163", + "name" : "卧室的插座", + "homeId" : 1, + "spaceId" : 1, + "collect" : false +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321268, + "updateBy" : null, + "updateTime" : 1708254321268, + "tenantId" : 0, + "id" : 8, + "deviceId" : "16538390924670pulg0a001006000012a", + "name" : "阳台的插座", + "homeId" : 1, + "spaceId" : 1, + "collect" : false +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321271, + "updateBy" : null, + "updateTime" : 1708254321271, + "tenantId" : 0, + "id" : 9, + "deviceId" : "16501806313260000833feffac33bc16c", + "name" : "灯的插座", + "homeId" : 1, + "spaceId" : 1, + "collect" : false +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321275, + "updateBy" : null, + "updateTime" : 1708254321275, + "tenantId" : 0, + "id" : 10, + "deviceId" : "165017126122400cefafcfee61000012b", + "name" : "客厅网关", + "homeId" : 1, + "spaceId" : 1, + "collect" : false +} ] \ No newline at end of file diff --git a/data/init/sys_app.json b/data/init/sys_app.json new file mode 100644 index 0000000..8841127 --- /dev/null +++ b/data/init/sys_app.json @@ -0,0 +1,14 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254323547, + "updateBy" : null, + "updateTime" : 1708254323547, + "tenantId" : 0, + "id" : 453554819821637, + "appName" : "微信小程序", + "appId" : "xxx", + "appSecret" : "xxx", + "appType" : "1", + "remark" : "微信小程序" +} ] \ No newline at end of file diff --git a/data/init/sys_config.json b/data/init/sys_config.json new file mode 100644 index 0000000..c6461f5 --- /dev/null +++ b/data/init/sys_config.json @@ -0,0 +1,118 @@ +[ { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321796, + "updateBy" : null, + "updateTime" : 1708254321796, + "tenantId" : 0, + "id" : 1, + "configName" : "主框架页-默认皮肤样式名称", + "configKey" : "sys.index.skinName", + "configValue" : "skin-blue", + "configType" : "Y", + "remark" : "蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321808, + "updateBy" : null, + "updateTime" : 1708254321808, + "tenantId" : 0, + "id" : 2, + "configName" : "用户管理-账号初始密码", + "configKey" : "sys.user.initPassword", + "configValue" : "123456", + "configType" : "Y", + "remark" : "初始化密码 123456" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321811, + "updateBy" : null, + "updateTime" : 1708254321811, + "tenantId" : 0, + "id" : 3, + "configName" : "主框架页-侧边栏主题", + "configKey" : "sys.index.sideTheme", + "configValue" : "theme-dark", + "configType" : "Y", + "remark" : "深色主题theme-dark,浅色主题theme-light" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321814, + "updateBy" : null, + "updateTime" : 1708254321814, + "tenantId" : 0, + "id" : 5, + "configName" : "账号自助-是否开启用户注册功能", + "configKey" : "sys.account.registerUser", + "configValue" : "false", + "configType" : "Y", + "remark" : "是否开启注册用户功能(true开启,false关闭)" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321818, + "updateBy" : null, + "updateTime" : 1708254321818, + "tenantId" : 0, + "id" : 11, + "configName" : "OSS预览列表资源开关", + "configKey" : "sys.oss.previewListResource", + "configValue" : "true", + "configType" : "Y", + "remark" : "true:开启, false:关闭" +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321820, + "updateBy" : null, + "updateTime" : 1708254321820, + "tenantId" : 0, + "id" : 452767972696133, + "configName" : "主框架页-默认皮肤样式名称", + "configKey" : "sys.index.skinName", + "configValue" : "skin-blue", + "configType" : "Y", + "remark" : "蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow" +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321821, + "updateBy" : null, + "updateTime" : 1708254321821, + "tenantId" : "452748015218757", + "id" : 452767972700229, + "configName" : "用户管理-账号初始密码", + "configKey" : "sys.user.initPassword", + "configValue" : "123456", + "configType" : "Y", + "remark" : "初始化密码 123456" +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321823, + "updateBy" : null, + "updateTime" : 1708254321823, + "tenantId" : "452748015218757", + "id" : 452767972704325, + "configName" : "主框架页-侧边栏主题", + "configKey" : "sys.index.sideTheme", + "configValue" : "theme-dark", + "configType" : "Y", + "remark" : "深色主题theme-dark,浅色主题theme-light" +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321826, + "updateBy" : null, + "updateTime" : 1708254321826, + "tenantId" : "452748015218757", + "id" : 452767972708421, + "configName" : "账号自助-是否开启用户注册功能", + "configKey" : "sys.account.registerUser", + "configValue" : "false", + "configType" : "Y", + "remark" : "是否开启注册用户功能(true开启,false关闭)" +} ] diff --git a/data/init/sys_dept.json b/data/init/sys_dept.json new file mode 100644 index 0000000..04557b2 --- /dev/null +++ b/data/init/sys_dept.json @@ -0,0 +1,188 @@ +[ { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321849, + "updateBy" : null, + "updateTime" : 1708254321849, + "id" : 100, + "parentId" : 0, + "parentName" : null, + "ancestors" : "0", + "deptName" : "禹霖科技", + "orderNum" : 0, + "leader" : "openyl", + "phone" : "15888888888", + "email" : "xxx@qq.com", + "status" : "0", + "tenantId" : "000000" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321863, + "updateBy" : null, + "updateTime" : 1708254321863, + "id" : 101, + "parentId" : 100, + "parentName" : null, + "ancestors" : "0,100", + "deptName" : "深圳总公司", + "orderNum" : 1, + "leader" : "openyl", + "phone" : "15888888888", + "email" : "xxx@qq.com", + "status" : "0", + "tenantId" : "000000" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321868, + "updateBy" : null, + "updateTime" : 1708254321868, + "id" : 102, + "parentId" : 100, + "parentName" : null, + "ancestors" : "0,100", + "deptName" : "长沙分公司", + "orderNum" : 2, + "leader" : "openiita", + "phone" : "15888888888", + "email" : "xxx@qq.com", + "status" : "0", + "tenantId" : "000000" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321870, + "updateBy" : null, + "updateTime" : 1708254321870, + "id" : 103, + "parentId" : 101, + "parentName" : null, + "ancestors" : "0,100,101", + "deptName" : "研发部门", + "orderNum" : 1, + "leader" : "openiita", + "phone" : "15888888888", + "email" : "xxx@qq.com", + "status" : "0", + "tenantId" : "000000" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321874, + "updateBy" : null, + "updateTime" : 1708254321874, + "id" : 104, + "parentId" : 101, + "parentName" : null, + "ancestors" : "0,100,101", + "deptName" : "市场部门", + "orderNum" : 2, + "leader" : "openiita", + "phone" : "15888888888", + "email" : "xxx@qq.com", + "status" : "0", + "tenantId" : "000000" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321877, + "updateBy" : null, + "updateTime" : 1708254321877, + "id" : 105, + "parentId" : 101, + "parentName" : null, + "ancestors" : "0,100,101", + "deptName" : "测试部门", + "orderNum" : 3, + "leader" : "openiita", + "phone" : "15888888888", + "email" : "xxx@qq.com", + "status" : "0", + "tenantId" : "000000" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321880, + "updateBy" : null, + "updateTime" : 1708254321880, + "id" : 106, + "parentId" : 101, + "parentName" : null, + "ancestors" : "0,100,101", + "deptName" : "财务部门", + "orderNum" : 4, + "leader" : "openiita", + "phone" : "15888888888", + "email" : "xxx@qq.com", + "status" : "0", + "tenantId" : "000000" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321885, + "updateBy" : null, + "updateTime" : 1708254321885, + "id" : 107, + "parentId" : 101, + "parentName" : null, + "ancestors" : "0,100,101", + "deptName" : "运维部门", + "orderNum" : 5, + "leader" : "openiita", + "phone" : "15888888888", + "email" : "xxx@qq.com", + "status" : "0", + "tenantId" : "000000" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321889, + "updateBy" : null, + "updateTime" : 1708254321889, + "id" : 108, + "parentId" : 102, + "parentName" : null, + "ancestors" : "0,100,102", + "deptName" : "市场部门", + "orderNum" : 1, + "leader" : "openiita", + "phone" : "15888888888", + "email" : "xxx@qq.com", + "status" : "0", + "tenantId" : "000000" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321892, + "updateBy" : null, + "updateTime" : 1708254321892, + "id" : 109, + "parentId" : 102, + "parentName" : null, + "ancestors" : "0,100,102", + "deptName" : "财务部门", + "orderNum" : 2, + "leader" : "openiita", + "phone" : "15888888888", + "email" : "xxx@qq.com", + "status" : "0", + "tenantId" : "000000" +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321896, + "updateBy" : null, + "updateTime" : 1708254321896, + "id" : 452767971254341, + "parentId" : 0, + "parentName" : null, + "ancestors" : "0", + "deptName" : "测试租户有限公司", + "orderNum" : null, + "leader" : "test", + "phone" : "18888888888", + "email" : null, + "status" : "0", + "tenantId" : "452748015218757" +} ] diff --git a/data/init/sys_dict_data.json b/data/init/sys_dict_data.json new file mode 100644 index 0000000..3b5638b --- /dev/null +++ b/data/init/sys_dict_data.json @@ -0,0 +1,426 @@ +[ { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321935, + "updateBy" : null, + "updateTime" : 1708254321935, + "tenantId" : 0, + "id" : 1, + "dictSort" : 1, + "dictLabel" : "男", + "dictValue" : "0", + "dictType" : "sys_user_sex", + "cssClass" : "", + "listClass" : "", + "isDefault" : "Y", + "status" : "0", + "remark" : "性别男" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321951, + "updateBy" : null, + "updateTime" : 1708254321951, + "tenantId" : 0, + "id" : 2, + "dictSort" : 2, + "dictLabel" : "女", + "dictValue" : "1", + "dictType" : "sys_user_sex", + "cssClass" : "", + "listClass" : "", + "isDefault" : "N", + "status" : "0", + "remark" : "性别女" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321958, + "updateBy" : null, + "updateTime" : 1708254321958, + "tenantId" : 0, + "id" : 3, + "dictSort" : 3, + "dictLabel" : "未知", + "dictValue" : "2", + "dictType" : "sys_user_sex", + "cssClass" : "", + "listClass" : "", + "isDefault" : "N", + "status" : "0", + "remark" : "性别未知" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321962, + "updateBy" : null, + "updateTime" : 1708254321962, + "tenantId" : 0, + "id" : 4, + "dictSort" : 1, + "dictLabel" : "显示", + "dictValue" : "0", + "dictType" : "sys_show_hide", + "cssClass" : "", + "listClass" : "primary", + "isDefault" : "Y", + "status" : "0", + "remark" : "显示菜单" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321968, + "updateBy" : null, + "updateTime" : 1708254321968, + "tenantId" : 0, + "id" : 5, + "dictSort" : 2, + "dictLabel" : "隐藏", + "dictValue" : "1", + "dictType" : "sys_show_hide", + "cssClass" : "", + "listClass" : "danger", + "isDefault" : "N", + "status" : "0", + "remark" : "隐藏菜单" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321971, + "updateBy" : null, + "updateTime" : 1708254321971, + "tenantId" : 0, + "id" : 6, + "dictSort" : 1, + "dictLabel" : "正常", + "dictValue" : "0", + "dictType" : "sys_normal_disable", + "cssClass" : "", + "listClass" : "primary", + "isDefault" : "Y", + "status" : "0", + "remark" : "正常状态" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321976, + "updateBy" : null, + "updateTime" : 1708254321976, + "tenantId" : 0, + "id" : 7, + "dictSort" : 2, + "dictLabel" : "停用", + "dictValue" : "1", + "dictType" : "sys_normal_disable", + "cssClass" : "", + "listClass" : "danger", + "isDefault" : "N", + "status" : "0", + "remark" : "停用状态" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321981, + "updateBy" : null, + "updateTime" : 1708254321981, + "tenantId" : 0, + "id" : 12, + "dictSort" : 1, + "dictLabel" : "是", + "dictValue" : "Y", + "dictType" : "sys_yes_no", + "cssClass" : "", + "listClass" : "primary", + "isDefault" : "Y", + "status" : "0", + "remark" : "系统默认是" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321987, + "updateBy" : null, + "updateTime" : 1708254321987, + "tenantId" : 0, + "id" : 13, + "dictSort" : 2, + "dictLabel" : "否", + "dictValue" : "N", + "dictType" : "sys_yes_no", + "cssClass" : "", + "listClass" : "danger", + "isDefault" : "N", + "status" : "0", + "remark" : "系统默认否" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321991, + "updateBy" : null, + "updateTime" : 1708254321991, + "tenantId" : 0, + "id" : 14, + "dictSort" : 1, + "dictLabel" : "通知", + "dictValue" : "1", + "dictType" : "sys_notice_type", + "cssClass" : "", + "listClass" : "warning", + "isDefault" : "Y", + "status" : "0", + "remark" : "通知" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254321994, + "updateBy" : null, + "updateTime" : 1708254321994, + "tenantId" : 0, + "id" : 15, + "dictSort" : 2, + "dictLabel" : "公告", + "dictValue" : "2", + "dictType" : "sys_notice_type", + "cssClass" : "", + "listClass" : "success", + "isDefault" : "N", + "status" : "0", + "remark" : "公告" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322001, + "updateBy" : null, + "updateTime" : 1708254322001, + "tenantId" : 0, + "id" : 16, + "dictSort" : 1, + "dictLabel" : "正常", + "dictValue" : "0", + "dictType" : "sys_notice_status", + "cssClass" : "", + "listClass" : "primary", + "isDefault" : "Y", + "status" : "0", + "remark" : "正常状态" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322006, + "updateBy" : null, + "updateTime" : 1708254322006, + "tenantId" : 0, + "id" : 17, + "dictSort" : null, + "dictLabel" : "关闭", + "dictValue" : "1", + "dictType" : "sys_notice_status", + "cssClass" : "", + "listClass" : "danger", + "isDefault" : "N", + "status" : "0", + "remark" : "关闭状态" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322012, + "updateBy" : null, + "updateTime" : 1708254322012, + "tenantId" : 0, + "id" : 18, + "dictSort" : null, + "dictLabel" : "新增", + "dictValue" : "1", + "dictType" : "sys_oper_type", + "cssClass" : "", + "listClass" : "info", + "isDefault" : "N", + "status" : "0", + "remark" : "新增操作" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322018, + "updateBy" : null, + "updateTime" : 1708254322018, + "tenantId" : 0, + "id" : 19, + "dictSort" : null, + "dictLabel" : "修改", + "dictValue" : "2", + "dictType" : "sys_oper_type", + "cssClass" : "", + "listClass" : "info", + "isDefault" : "N", + "status" : "0", + "remark" : "修改操作" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322022, + "updateBy" : null, + "updateTime" : 1708254322022, + "tenantId" : 0, + "id" : 20, + "dictSort" : null, + "dictLabel" : "删除", + "dictValue" : "3", + "dictType" : "sys_oper_type", + "cssClass" : "", + "listClass" : "danger", + "isDefault" : "N", + "status" : "0", + "remark" : "删除操作" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322025, + "updateBy" : null, + "updateTime" : 1708254322025, + "tenantId" : 0, + "id" : 21, + "dictSort" : null, + "dictLabel" : "授权", + "dictValue" : "4", + "dictType" : "sys_oper_type", + "cssClass" : "", + "listClass" : "primary", + "isDefault" : "N", + "status" : "0", + "remark" : "授权操作" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322027, + "updateBy" : null, + "updateTime" : 1708254322027, + "tenantId" : 0, + "id" : 22, + "dictSort" : null, + "dictLabel" : "导出", + "dictValue" : "5", + "dictType" : "sys_oper_type", + "cssClass" : "", + "listClass" : "warning", + "isDefault" : "N", + "status" : "0", + "remark" : "导出操作" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322030, + "updateBy" : null, + "updateTime" : 1708254322030, + "tenantId" : 0, + "id" : 23, + "dictSort" : null, + "dictLabel" : "导入", + "dictValue" : "6", + "dictType" : "sys_oper_type", + "cssClass" : "", + "listClass" : "warning", + "isDefault" : "N", + "status" : "0", + "remark" : "导入操作" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322035, + "updateBy" : null, + "updateTime" : 1708254322035, + "tenantId" : 0, + "id" : 24, + "dictSort" : null, + "dictLabel" : "强退", + "dictValue" : "7", + "dictType" : "sys_oper_type", + "cssClass" : "", + "listClass" : "danger", + "isDefault" : "N", + "status" : "0", + "remark" : "强退操作" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322038, + "updateBy" : null, + "updateTime" : 1708254322038, + "tenantId" : 0, + "id" : 25, + "dictSort" : null, + "dictLabel" : "生成代码", + "dictValue" : "8", + "dictType" : "sys_oper_type", + "cssClass" : "", + "listClass" : "warning", + "isDefault" : "N", + "status" : "0", + "remark" : "生成操作" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322041, + "updateBy" : null, + "updateTime" : 1708254322041, + "tenantId" : 0, + "id" : 26, + "dictSort" : null, + "dictLabel" : "清空数据", + "dictValue" : "9", + "dictType" : "sys_oper_type", + "cssClass" : "", + "listClass" : "danger", + "isDefault" : "N", + "status" : "0", + "remark" : "清空操作" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322044, + "updateBy" : null, + "updateTime" : 1708254322044, + "tenantId" : 0, + "id" : 27, + "dictSort" : null, + "dictLabel" : "成功", + "dictValue" : "0", + "dictType" : "sys_common_status", + "cssClass" : "", + "listClass" : "primary", + "isDefault" : "N", + "status" : "0", + "remark" : "正常状态" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322046, + "updateBy" : null, + "updateTime" : 1708254322046, + "tenantId" : 0, + "id" : 28, + "dictSort" : null, + "dictLabel" : "失败", + "dictValue" : "1", + "dictType" : "sys_common_status", + "cssClass" : "", + "listClass" : "danger", + "isDefault" : "N", + "status" : "0", + "remark" : "停用状态" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322051, + "updateBy" : null, + "updateTime" : 1708254322051, + "tenantId" : 0, + "id" : 29, + "dictSort" : null, + "dictLabel" : "其他", + "dictValue" : "0", + "dictType" : "sys_oper_type", + "cssClass" : "", + "listClass" : "info", + "isDefault" : "N", + "status" : "0", + "remark" : "其他操作" +} ] \ No newline at end of file diff --git a/data/init/sys_dict_type.json b/data/init/sys_dict_type.json new file mode 100644 index 0000000..e87dc51 --- /dev/null +++ b/data/init/sys_dict_type.json @@ -0,0 +1,147 @@ +[ + { + "createDept": 103, + "createBy": 1, + "createTime": 1708254322074, + "updateBy": null, + "updateTime": 1708254322074, + "tenantId": 0, + "id": 1, + "dictName": "用户性别", + "dictType": "sys_user_sex", + "status": "0", + "remark": "用户性别列表" + }, + + { + "createDept": 103, + "createBy": 1, + "createTime": 1708254322088, + "updateBy": null, + "updateTime": 1708254322088, + "tenantId": 0, + "id": 3, + "dictName": "系统开关", + "dictType": "sys_normal_disable", + "status": "0", + "remark": "系统开关列表" + }, + { + "createDept": 103, + "createBy": 1, + "createTime": 1708254322091, + "updateBy": null, + "updateTime": 1708254322091, + "tenantId": 0, + "id": 6, + "dictName": "系统是否", + "dictType": "sys_yes_no", + "status": "0", + "remark": "系统是否列表" + }, + { + "createDept": 103, + "createBy": 1, + "createTime": 1708254322093, + "updateBy": null, + "updateTime": 1708254322093, + "tenantId": 0, + "id": 7, + "dictName": "通知类型", + "dictType": "sys_notice_type", + "status": "0", + "remark": "通知类型列表" + }, + { + "createDept": 103, + "createBy": 1, + "createTime": 1708254322097, + "updateBy": null, + "updateTime": 1708254322097, + "tenantId": 0, + "id": 8, + "dictName": "通知状态", + "dictType": "sys_notice_status", + "status": "0", + "remark": "通知状态列表" + }, + + { + "createDept": 103, + "createBy": 1, + "createTime": 1708254322103, + "updateBy": null, + "updateTime": 1708254322103, + "tenantId": 0, + "id": 10, + "dictName": "系统状态", + "dictType": "sys_common_status", + "status": "0", + "remark": "登录状态列表" + }, + + { + "createDept": null, + "createBy": null, + "createTime": 1708254322110, + "updateBy": null, + "updateTime": 1708254322110, + "tenantId": 0, + "id": 452767972298821, + "dictName": "菜单状态", + "dictType": "sys_show_hide", + "status": "0", + "remark": "菜单状态列表" + }, + + { + "createDept": null, + "createBy": null, + "createTime": 1708254322127, + "updateBy": null, + "updateTime": 1708254322127, + "tenantId": 0, + "id": 452767972302917, + "dictName": "操作类型", + "dictType": "sys_oper_type", + "status": "0", + "remark": "操作类型列表" + }, + + { + "id": 571709615026245, + "dictName": "设备协议", + "dictType": "sys_product_protocol", + "status": "0", + "remark": "", + "createBy": null, + "createTime": 1708254322133, + "updateBy": null, + "updateTime": 1708254322133, + "tenantId": 0 + }, + { + "id": 613245877620805, + "dictName": "短信渠道编码", + "dictType": "system_sms_channel_code", + "status": "0", + "remark": "", + "createBy": null, + "createTime": 1708254322133, + "updateBy": null, + "updateTime": 1708254322133, + "tenantId": 0 + }, + { + "id": 613246485446725, + "dictName": "短信类型", + "dictType": "system_sms_template_type", + "status": "0", + "remark": "", + "createBy": null, + "createTime": 1708254322133, + "updateBy": null, + "updateTime": 1708254322133, + "tenantId": 0 + } +] diff --git a/data/init/sys_logininfor.json b/data/init/sys_logininfor.json new file mode 100644 index 0000000..bb3f0a5 --- /dev/null +++ b/data/init/sys_logininfor.json @@ -0,0 +1,23 @@ +[ { + "id" : 516579924885573, + "tenantId" : 0, + "userName" : "admin", + "status" : "0", + "ipaddr" : "127.0.0.1", + "loginLocation" : "内网IP", + "browser" : "Chrome", + "os" : "OSX", + "msg" : "user.login.success", + "loginTime" : 1708254547722 +}, { + "id" : 1665628533390614529, + "tenantId" : 0, + "userName" : "admin", + "status" : "0", + "ipaddr" : "127.0.0.1", + "loginLocation" : "内网IP", + "browser" : "Chrome", + "os" : "Windows 10 or Windows Server 2016", + "msg" : "登录成功", + "loginTime" : null +} ] \ No newline at end of file diff --git a/data/init/sys_menu.json b/data/init/sys_menu.json new file mode 100644 index 0000000..3303670 --- /dev/null +++ b/data/init/sys_menu.json @@ -0,0 +1,3565 @@ +[ { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959951, + "updateBy" : null, + "updateTime" : 1708393959951, + "id" : 1, + "menuName" : "系统管理", + "parentId" : 0, + "orderNum" : 1, + "path" : "system", + "component" : null, + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "M", + "visible" : "0", + "status" : "0", + "perms" : "", + "icon" : "system", + "remark" : "系统管理目录", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959959, + "updateBy" : 1, + "updateTime" : 1708393959959, + "id" : 2, + "menuName" : "系统监控", + "parentId" : 0, + "orderNum" : 23, + "path" : "monitor", + "component" : null, + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "M", + "visible" : "0", + "status" : "0", + "perms" : "", + "icon" : "monitor", + "remark" : "系统监控目录", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959961, + "updateBy" : 1, + "updateTime" : 1708393959961, + "id" : 4, + "menuName" : "铱塔官网", + "parentId" : 0, + "orderNum" : 25, + "path" : "http://iotkit-open-source.gitee.io/document", + "component" : null, + "queryParam" : "", + "isFrame" : "0", + "isCache" : "0", + "menuType" : "M", + "visible" : "0", + "status" : "0", + "perms" : "", + "icon" : "guide", + "remark" : "铱塔官网", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959962, + "updateBy" : 1, + "updateTime" : 1708393959962, + "id" : 6, + "menuName" : "租户管理", + "parentId" : 0, + "orderNum" : 22, + "path" : "tenant", + "component" : null, + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "M", + "visible" : "0", + "status" : "0", + "perms" : "", + "icon" : "chart", + "remark" : "租户管理目录", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959963, + "updateBy" : null, + "updateTime" : 1708393959963, + "id" : 100, + "menuName" : "用户管理", + "parentId" : 1, + "orderNum" : 1, + "path" : "user", + "component" : "system/user/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:user:list", + "icon" : "user", + "remark" : "用户管理菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959966, + "updateBy" : null, + "updateTime" : 1708393959966, + "id" : 101, + "menuName" : "角色管理", + "parentId" : 1, + "orderNum" : 2, + "path" : "role", + "component" : "system/role/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:role:list", + "icon" : "peoples", + "remark" : "角色管理菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959968, + "updateBy" : null, + "updateTime" : 1708393959968, + "id" : 102, + "menuName" : "菜单管理", + "parentId" : 1, + "orderNum" : 3, + "path" : "menu", + "component" : "system/menu/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:menu:list", + "icon" : "tree-table", + "remark" : "菜单管理菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959969, + "updateBy" : null, + "updateTime" : 1708393959969, + "id" : 103, + "menuName" : "部门管理", + "parentId" : 1, + "orderNum" : 4, + "path" : "dept", + "component" : "system/dept/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:dept:list", + "icon" : "tree", + "remark" : "部门管理菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959970, + "updateBy" : null, + "updateTime" : 1708393959970, + "id" : 104, + "menuName" : "岗位管理", + "parentId" : 1, + "orderNum" : 5, + "path" : "post", + "component" : "system/post/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:post:list", + "icon" : "post", + "remark" : "岗位管理菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959971, + "updateBy" : null, + "updateTime" : 1708393959971, + "id" : 105, + "menuName" : "字典管理", + "parentId" : 1, + "orderNum" : 6, + "path" : "dict", + "component" : "system/dict/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:dict:list", + "icon" : "dict", + "remark" : "字典管理菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959972, + "updateBy" : null, + "updateTime" : 1708393959972, + "id" : 106, + "menuName" : "参数设置", + "parentId" : 1, + "orderNum" : 7, + "path" : "sysconfig", + "component" : "system/config/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:config:list", + "icon" : "edit", + "remark" : "参数设置菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959973, + "updateBy" : null, + "updateTime" : 1708393959973, + "id" : 107, + "menuName" : "通知公告", + "parentId" : 1, + "orderNum" : 8, + "path" : "notice", + "component" : "system/notice/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:notice:list", + "icon" : "message", + "remark" : "通知公告菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959974, + "updateBy" : null, + "updateTime" : 1708393959974, + "id" : 108, + "menuName" : "日志管理", + "parentId" : 1, + "orderNum" : 9, + "path" : "log", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "M", + "visible" : "0", + "status" : "0", + "perms" : "", + "icon" : "log", + "remark" : "日志管理菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959974, + "updateBy" : null, + "updateTime" : 1708393959974, + "id" : 109, + "menuName" : "在线用户", + "parentId" : 2, + "orderNum" : 1, + "path" : "online", + "component" : "monitor/online/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "monitor:online:list", + "icon" : "online", + "remark" : "在线用户菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959975, + "updateBy" : null, + "updateTime" : 1708393959975, + "id" : 118, + "menuName" : "文件管理", + "parentId" : 1, + "orderNum" : 10, + "path" : "oss", + "component" : "system/oss/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:oss:list", + "icon" : "upload", + "remark" : "文件管理菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959977, + "updateBy" : null, + "updateTime" : 1708393959977, + "id" : 121, + "menuName" : "租户管理", + "parentId" : 6, + "orderNum" : 1, + "path" : "tenant", + "component" : "system/tenant/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:tenant:list", + "icon" : "list", + "remark" : "租户管理菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959979, + "updateBy" : null, + "updateTime" : 1708393959979, + "id" : 122, + "menuName" : "租户套餐管理", + "parentId" : 6, + "orderNum" : 2, + "path" : "tenantPackage", + "component" : "system/tenantPackage/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:tenantPackage:list", + "icon" : "form", + "remark" : "租户套餐管理菜单", + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393959980, + "updateBy" : null, + "updateTime" : 1708393959980, + "id" : 423, + "menuName" : "应用修改", + "parentId" : 502, + "orderNum" : 4, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:app:edit", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959983, + "updateBy" : null, + "updateTime" : 1708393959983, + "id" : 500, + "menuName" : "操作日志", + "parentId" : 108, + "orderNum" : 1, + "path" : "operlog", + "component" : "monitor/operlog/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "monitor:operlog:list", + "icon" : "form", + "remark" : "操作日志菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959984, + "updateBy" : null, + "updateTime" : 1708393959984, + "id" : 501, + "menuName" : "登录日志", + "parentId" : 108, + "orderNum" : 2, + "path" : "logininfor", + "component" : "monitor/logininfor/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "monitor:logininfor:list", + "icon" : "logininfor", + "remark" : "登录日志菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959985, + "updateBy" : null, + "updateTime" : 1708393959985, + "id" : 502, + "menuName" : "应用管理", + "parentId" : 1, + "orderNum" : 11, + "path" : "app", + "component" : "system/app/index", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "system:app:list", + "icon" : "phone", + "remark" : "应用管理菜单", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959987, + "updateBy" : null, + "updateTime" : 1708393959987, + "id" : 1001, + "menuName" : "用户查询", + "parentId" : 100, + "orderNum" : 1, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:user:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959988, + "updateBy" : null, + "updateTime" : 1708393959988, + "id" : 1002, + "menuName" : "用户新增", + "parentId" : 100, + "orderNum" : 2, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:user:add", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959994, + "updateBy" : null, + "updateTime" : 1708393959994, + "id" : 1003, + "menuName" : "用户修改", + "parentId" : 100, + "orderNum" : 3, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:user:edit", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959996, + "updateBy" : null, + "updateTime" : 1708393959996, + "id" : 1004, + "menuName" : "用户删除", + "parentId" : 100, + "orderNum" : 4, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:user:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959997, + "updateBy" : null, + "updateTime" : 1708393959997, + "id" : 1005, + "menuName" : "用户导出", + "parentId" : 100, + "orderNum" : 5, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:user:export", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393959999, + "updateBy" : null, + "updateTime" : 1708393959999, + "id" : 1006, + "menuName" : "用户导入", + "parentId" : 100, + "orderNum" : 6, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:user:import", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960000, + "updateBy" : null, + "updateTime" : 1708393960000, + "id" : 1007, + "menuName" : "重置密码", + "parentId" : 100, + "orderNum" : 7, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:user:resetPwd", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960001, + "updateBy" : null, + "updateTime" : 1708393960001, + "id" : 1008, + "menuName" : "角色查询", + "parentId" : 101, + "orderNum" : 1, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:role:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960003, + "updateBy" : null, + "updateTime" : 1708393960003, + "id" : 1009, + "menuName" : "角色新增", + "parentId" : 101, + "orderNum" : 2, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:role:add", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960004, + "updateBy" : null, + "updateTime" : 1708393960004, + "id" : 1010, + "menuName" : "角色修改", + "parentId" : 101, + "orderNum" : 3, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:role:edit", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960005, + "updateBy" : null, + "updateTime" : 1708393960005, + "id" : 1011, + "menuName" : "角色删除", + "parentId" : 101, + "orderNum" : 4, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:role:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960007, + "updateBy" : null, + "updateTime" : 1708393960007, + "id" : 1012, + "menuName" : "角色导出", + "parentId" : 101, + "orderNum" : 5, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:role:export", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960008, + "updateBy" : null, + "updateTime" : 1708393960008, + "id" : 1013, + "menuName" : "菜单查询", + "parentId" : 102, + "orderNum" : 1, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:menu:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960008, + "updateBy" : null, + "updateTime" : 1708393960008, + "id" : 1014, + "menuName" : "菜单新增", + "parentId" : 102, + "orderNum" : 2, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:menu:add", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960009, + "updateBy" : null, + "updateTime" : 1708393960009, + "id" : 1015, + "menuName" : "菜单修改", + "parentId" : 102, + "orderNum" : 3, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:menu:edit", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960010, + "updateBy" : null, + "updateTime" : 1708393960010, + "id" : 1016, + "menuName" : "菜单删除", + "parentId" : 102, + "orderNum" : 4, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:menu:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960011, + "updateBy" : null, + "updateTime" : 1708393960011, + "id" : 1017, + "menuName" : "部门查询", + "parentId" : 103, + "orderNum" : 1, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:dept:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960012, + "updateBy" : null, + "updateTime" : 1708393960012, + "id" : 1018, + "menuName" : "部门新增", + "parentId" : 103, + "orderNum" : 2, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:dept:add", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960013, + "updateBy" : null, + "updateTime" : 1708393960013, + "id" : 1019, + "menuName" : "部门修改", + "parentId" : 103, + "orderNum" : 3, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:dept:edit", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960014, + "updateBy" : null, + "updateTime" : 1708393960014, + "id" : 1020, + "menuName" : "部门删除", + "parentId" : 103, + "orderNum" : 4, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:dept:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960015, + "updateBy" : null, + "updateTime" : 1708393960015, + "id" : 1021, + "menuName" : "岗位查询", + "parentId" : 104, + "orderNum" : 1, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:post:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960016, + "updateBy" : null, + "updateTime" : 1708393960016, + "id" : 1022, + "menuName" : "岗位新增", + "parentId" : 104, + "orderNum" : 2, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:post:add", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960016, + "updateBy" : null, + "updateTime" : 1708393960016, + "id" : 1023, + "menuName" : "岗位修改", + "parentId" : 104, + "orderNum" : 3, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:post:edit", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960017, + "updateBy" : null, + "updateTime" : 1708393960017, + "id" : 1024, + "menuName" : "岗位删除", + "parentId" : 104, + "orderNum" : 4, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:post:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960018, + "updateBy" : null, + "updateTime" : 1708393960018, + "id" : 1025, + "menuName" : "岗位导出", + "parentId" : 104, + "orderNum" : 5, + "path" : "", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:post:export", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960019, + "updateBy" : null, + "updateTime" : 1708393960019, + "id" : 1026, + "menuName" : "字典查询", + "parentId" : 105, + "orderNum" : 1, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:dict:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960020, + "updateBy" : null, + "updateTime" : 1708393960020, + "id" : 1027, + "menuName" : "字典新增", + "parentId" : 105, + "orderNum" : 2, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:dict:add", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960021, + "updateBy" : null, + "updateTime" : 1708393960021, + "id" : 1028, + "menuName" : "字典修改", + "parentId" : 105, + "orderNum" : 3, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:dict:edit", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960022, + "updateBy" : null, + "updateTime" : 1708393960022, + "id" : 1029, + "menuName" : "字典删除", + "parentId" : 105, + "orderNum" : 4, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:dict:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960023, + "updateBy" : null, + "updateTime" : 1708393960023, + "id" : 1030, + "menuName" : "字典导出", + "parentId" : 105, + "orderNum" : 5, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:dict:export", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960023, + "updateBy" : null, + "updateTime" : 1708393960023, + "id" : 1031, + "menuName" : "参数查询", + "parentId" : 106, + "orderNum" : 1, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:config:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960024, + "updateBy" : null, + "updateTime" : 1708393960024, + "id" : 1032, + "menuName" : "参数新增", + "parentId" : 106, + "orderNum" : 2, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:config:add", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960025, + "updateBy" : null, + "updateTime" : 1708393960025, + "id" : 1033, + "menuName" : "参数修改", + "parentId" : 106, + "orderNum" : 3, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:config:edit", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960026, + "updateBy" : null, + "updateTime" : 1708393960026, + "id" : 1034, + "menuName" : "参数删除", + "parentId" : 106, + "orderNum" : 4, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:config:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960027, + "updateBy" : null, + "updateTime" : 1708393960027, + "id" : 1035, + "menuName" : "参数导出", + "parentId" : 106, + "orderNum" : 5, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:config:export", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960028, + "updateBy" : null, + "updateTime" : 1708393960028, + "id" : 1036, + "menuName" : "公告查询", + "parentId" : 107, + "orderNum" : 1, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:notice:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960029, + "updateBy" : null, + "updateTime" : 1708393960029, + "id" : 1037, + "menuName" : "公告新增", + "parentId" : 107, + "orderNum" : 2, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:notice:add", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960030, + "updateBy" : null, + "updateTime" : 1708393960030, + "id" : 1038, + "menuName" : "公告修改", + "parentId" : 107, + "orderNum" : 3, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:notice:edit", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960030, + "updateBy" : null, + "updateTime" : 1708393960030, + "id" : 1039, + "menuName" : "公告删除", + "parentId" : 107, + "orderNum" : 4, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:notice:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960031, + "updateBy" : null, + "updateTime" : 1708393960031, + "id" : 1040, + "menuName" : "操作查询", + "parentId" : 500, + "orderNum" : 1, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "monitor:operlog:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960032, + "updateBy" : null, + "updateTime" : 1708393960032, + "id" : 1041, + "menuName" : "操作删除", + "parentId" : 500, + "orderNum" : 2, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "monitor:operlog:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960033, + "updateBy" : null, + "updateTime" : 1708393960033, + "id" : 1042, + "menuName" : "日志导出", + "parentId" : 500, + "orderNum" : 4, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "monitor:operlog:export", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960034, + "updateBy" : null, + "updateTime" : 1708393960034, + "id" : 1043, + "menuName" : "登录查询", + "parentId" : 501, + "orderNum" : 1, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "monitor:logininfor:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960035, + "updateBy" : null, + "updateTime" : 1708393960035, + "id" : 1044, + "menuName" : "登录删除", + "parentId" : 501, + "orderNum" : 2, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "monitor:logininfor:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960036, + "updateBy" : null, + "updateTime" : 1708393960036, + "id" : 1045, + "menuName" : "日志导出", + "parentId" : 501, + "orderNum" : 3, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "monitor:logininfor:export", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960037, + "updateBy" : null, + "updateTime" : 1708393960037, + "id" : 1046, + "menuName" : "在线查询", + "parentId" : 109, + "orderNum" : 1, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "monitor:online:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960039, + "updateBy" : null, + "updateTime" : 1708393960039, + "id" : 1047, + "menuName" : "批量强退", + "parentId" : 109, + "orderNum" : 2, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "monitor:online:batchLogout", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960040, + "updateBy" : null, + "updateTime" : 1708393960040, + "id" : 1048, + "menuName" : "单条强退", + "parentId" : 109, + "orderNum" : 3, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "monitor:online:forceLogout", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960041, + "updateBy" : null, + "updateTime" : 1708393960041, + "id" : 1050, + "menuName" : "账户解锁", + "parentId" : 501, + "orderNum" : 4, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "monitor:logininfor:unlock", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960042, + "updateBy" : null, + "updateTime" : 1708393960042, + "id" : 1600, + "menuName" : "文件查询", + "parentId" : 118, + "orderNum" : 1, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:oss:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960044, + "updateBy" : null, + "updateTime" : 1708393960044, + "id" : 1601, + "menuName" : "文件上传", + "parentId" : 118, + "orderNum" : 2, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:oss:upload", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960045, + "updateBy" : null, + "updateTime" : 1708393960045, + "id" : 1602, + "menuName" : "文件下载", + "parentId" : 118, + "orderNum" : 3, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:oss:download", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960046, + "updateBy" : null, + "updateTime" : 1708393960046, + "id" : 1603, + "menuName" : "文件删除", + "parentId" : 118, + "orderNum" : 4, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:oss:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960047, + "updateBy" : null, + "updateTime" : 1708393960047, + "id" : 1604, + "menuName" : "配置添加", + "parentId" : 118, + "orderNum" : 5, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:oss:add", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960048, + "updateBy" : null, + "updateTime" : 1708393960048, + "id" : 1605, + "menuName" : "配置编辑", + "parentId" : 118, + "orderNum" : 6, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:oss:edit", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960049, + "updateBy" : null, + "updateTime" : 1708393960049, + "id" : 1606, + "menuName" : "租户查询", + "parentId" : 121, + "orderNum" : 1, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:tenant:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960050, + "updateBy" : null, + "updateTime" : 1708393960050, + "id" : 1607, + "menuName" : "租户新增", + "parentId" : 121, + "orderNum" : 2, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:tenant:add", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960051, + "updateBy" : null, + "updateTime" : 1708393960051, + "id" : 1608, + "menuName" : "租户修改", + "parentId" : 121, + "orderNum" : 3, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:tenant:edit", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960052, + "updateBy" : null, + "updateTime" : 1708393960052, + "id" : 1609, + "menuName" : "租户删除", + "parentId" : 121, + "orderNum" : 4, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:tenant:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960054, + "updateBy" : null, + "updateTime" : 1708393960054, + "id" : 1610, + "menuName" : "租户导出", + "parentId" : 121, + "orderNum" : 5, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:tenant:export", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960055, + "updateBy" : null, + "updateTime" : 1708393960055, + "id" : 1611, + "menuName" : "租户套餐查询", + "parentId" : 122, + "orderNum" : 1, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:tenantPackage:query", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960055, + "updateBy" : null, + "updateTime" : 1708393960055, + "id" : 1612, + "menuName" : "租户套餐新增", + "parentId" : 122, + "orderNum" : 2, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:tenantPackage:add", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960056, + "updateBy" : null, + "updateTime" : 1708393960056, + "id" : 1613, + "menuName" : "租户套餐修改", + "parentId" : 122, + "orderNum" : 3, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:tenantPackage:edit", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960057, + "updateBy" : null, + "updateTime" : 1708393960057, + "id" : 1614, + "menuName" : "租户套餐删除", + "parentId" : 122, + "orderNum" : 4, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:tenantPackage:remove", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960058, + "updateBy" : null, + "updateTime" : 1708393960058, + "id" : 1615, + "menuName" : "租户套餐导出", + "parentId" : 122, + "orderNum" : 5, + "path" : "#", + "component" : "", + "queryParam" : "", + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:tenantPackage:export", + "icon" : "#", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960059, + "updateBy" : 1, + "updateTime" : 1708393960059, + "id" : 2200, + "menuName" : "设备接入", + "parentId" : 0, + "orderNum" : 1, + "path" : "/equipment", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "M", + "visible" : "0", + "status" : "0", + "perms" : null, + "icon" : "device", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960060, + "updateBy" : null, + "updateTime" : 1708393960060, + "id" : 2201, + "menuName" : "品类管理", + "parentId" : 2200, + "orderNum" : 1, + "path" : "categories", + "component" : "iot/equipment/categories/index", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "1", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:category:list", + "icon" : "education", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960060, + "updateBy" : null, + "updateTime" : 1708393960060, + "id" : 2205, + "menuName" : "产品管理", + "parentId" : 2200, + "orderNum" : 2, + "path" : "products", + "component" : "iot/equipment/products/index", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "1", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:product:list", + "icon" : "product-management", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960061, + "updateBy" : null, + "updateTime" : 1708393960061, + "id" : 2206, + "menuName" : "设备列表", + "parentId" : 2200, + "orderNum" : 3, + "path" : "devices", + "component" : "iot/equipment/devices/list", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "1", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:device:list", + "icon" : "device", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960062, + "updateBy" : null, + "updateTime" : 1708393960062, + "id" : 2207, + "menuName" : "虚拟设备", + "parentId" : 2200, + "orderNum" : 4, + "path" : "virtualDevices", + "component" : "iot/equipment/devices/virtualDevices", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "1", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:virtualDevice:list", + "icon" : "monitor", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960063, + "updateBy" : null, + "updateTime" : 1708393960063, + "id" : 2210, + "menuName" : "插件管理", + "parentId" : 2200, + "orderNum" : 4, + "path" : "plugins", + "component" : "iot/plugins/index", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "1", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:plugin:list", + "icon" : "component", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960064, + "updateBy" : 1, + "updateTime" : 1708393960064, + "id" : 2211, + "menuName" : "规则引擎", + "parentId" : 0, + "orderNum" : 3, + "path" : "ruleEngine", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "M", + "visible" : "0", + "status" : "0", + "perms" : null, + "icon" : "dashboard", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960065, + "updateBy" : null, + "updateTime" : 1708393960065, + "id" : 2212, + "menuName" : "规则管理", + "parentId" : 2211, + "orderNum" : 1, + "path" : "ruleSys", + "component" : "iot/ruleEngine/ruleSys/index", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:rule:list", + "icon" : "component", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960066, + "updateBy" : null, + "updateTime" : 1708393960066, + "id" : 2213, + "menuName" : "定时任务", + "parentId" : 2211, + "orderNum" : 1, + "path" : "scheduledTask", + "component" : "iot/ruleEngine/scheduledTask/index", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:task:list", + "icon" : "component", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960067, + "updateBy" : 1, + "updateTime" : 1708393960067, + "id" : 2214, + "menuName" : "设备详情", + "parentId" : 2200, + "orderNum" : 1, + "path" : "devicesDetail/:id", + "component" : "iot/equipment/devices/detail", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "1", + "status" : "0", + "perms" : null, + "icon" : "", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960068, + "updateBy" : 1, + "updateTime" : 1708393960068, + "id" : 2215, + "menuName" : "虚拟设备详情", + "parentId" : 2200, + "orderNum" : 16, + "path" : "virtualDeviceConfig/:id", + "component" : "iot/equipment/devices/virtualDeviceConfig", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "1", + "menuType" : "C", + "visible" : "1", + "status" : "0", + "perms" : null, + "icon" : "", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960069, + "updateBy" : 1, + "updateTime" : 1708393960069, + "id" : 2216, + "menuName" : "消息中心", + "parentId" : 0, + "orderNum" : 4, + "path" : "messageCenter", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "M", + "visible" : "0", + "status" : "0", + "perms" : null, + "icon" : "message", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960070, + "updateBy" : 1, + "updateTime" : 1708393960070, + "id" : 2217, + "menuName" : "消息列表", + "parentId" : 2216, + "orderNum" : 1, + "path" : "messageCenterList", + "component" : "iot/messageCenter/list", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : null, + "icon" : "message", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960071, + "updateBy" : 1, + "updateTime" : 1708393960071, + "id" : 2218, + "menuName" : "通道管理", + "parentId" : 0, + "orderNum" : 5, + "path" : "channel", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "M", + "visible" : "0", + "status" : "0", + "perms" : null, + "icon" : "cascader", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960073, + "updateBy" : null, + "updateTime" : 1708393960073, + "id" : 2219, + "menuName" : "通道配置", + "parentId" : 2218, + "orderNum" : 1, + "path" : "channelConfig", + "component" : "iot/channel/config", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:channel:list", + "icon" : "system", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960074, + "updateBy" : null, + "updateTime" : 1708393960074, + "id" : 2220, + "menuName" : "模板配置", + "parentId" : 2218, + "orderNum" : 2, + "path" : "template", + "component" : "iot/channel/template", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:channel:list", + "icon" : "system", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960075, + "updateBy" : 1, + "updateTime" : 1708393960075, + "id" : 2221, + "menuName" : "告警中心", + "parentId" : 0, + "orderNum" : 6, + "path" : "alarm", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "M", + "visible" : "0", + "status" : "0", + "perms" : null, + "icon" : "alart", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960076, + "updateBy" : null, + "updateTime" : 1708393960076, + "id" : 2222, + "menuName" : "告警列表", + "parentId" : 2221, + "orderNum" : 1, + "path" : "list", + "component" : "iot/alarm/list", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:alert:list", + "icon" : "message", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960077, + "updateBy" : null, + "updateTime" : 1708393960077, + "id" : 2223, + "menuName" : "告警配置", + "parentId" : 2221, + "orderNum" : 2, + "path" : "config", + "component" : "iot/alarm/config", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:alertConfig:list", + "icon" : "system", + "remark" : "", + "children" : [ ] +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708393960078, + "updateBy" : null, + "updateTime" : 1708393960078, + "id" : 2225, + "menuName" : "OTA", + "parentId" : 0, + "orderNum" : 1, + "path" : "upgradePack", + "component" : "iot/ota/upgradePack/index", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:ota:list", + "icon" : "upload", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960080, + "updateBy" : null, + "updateTime" : 1708393960080, + "id" : 442129, + "menuName" : "应用查询", + "parentId" : 502, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:app:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960081, + "updateBy" : null, + "updateTime" : 1708393960081, + "id" : 44212332, + "menuName" : "应用添加", + "parentId" : 502, + "orderNum" : 2, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:app:add", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960082, + "updateBy" : null, + "updateTime" : 1708393960082, + "id" : 4234553537, + "menuName" : "应用导出", + "parentId" : 502, + "orderNum" : 5, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:app:export", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960083, + "updateBy" : null, + "updateTime" : 1708393960083, + "id" : 442123323123, + "menuName" : "应用删除", + "parentId" : 502, + "orderNum" : 3, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "system:app:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960084, + "updateBy" : null, + "updateTime" : 1708393960084, + "id" : 441851175424069, + "menuName" : "品类查询", + "parentId" : 2201, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:category:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960085, + "updateBy" : null, + "updateTime" : 1708393960085, + "id" : 441851310268485, + "menuName" : "品类修改", + "parentId" : 2201, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:category:edit", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960086, + "updateBy" : null, + "updateTime" : 1708393960086, + "id" : 441851485323333, + "menuName" : "品类删除", + "parentId" : 2201, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:category:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960087, + "updateBy" : null, + "updateTime" : 1708393960087, + "id" : 441853056651333, + "menuName" : "产品查询", + "parentId" : 2205, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:product:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960088, + "updateBy" : null, + "updateTime" : 1708393960088, + "id" : 441853220675653, + "menuName" : "产品添加", + "parentId" : 2205, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:product:add", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960089, + "updateBy" : null, + "updateTime" : 1708393960089, + "id" : 441853285179461, + "menuName" : "产品修改", + "parentId" : 2205, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:product:edit", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960090, + "updateBy" : null, + "updateTime" : 1708393960090, + "id" : 441862726639685, + "menuName" : "产品删除", + "parentId" : 2205, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:product:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960092, + "updateBy" : null, + "updateTime" : 1708393960092, + "id" : 441862877970501, + "menuName" : "物模型查询", + "parentId" : 2205, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:thingModel:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960095, + "updateBy" : null, + "updateTime" : 1708393960095, + "id" : 441862978281541, + "menuName" : "物模型修改", + "parentId" : 2205, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:thingModel:edit", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960096, + "updateBy" : null, + "updateTime" : 1708393960096, + "id" : 441863058096197, + "menuName" : "物模型删除", + "parentId" : 2205, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:thingModel:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960098, + "updateBy" : null, + "updateTime" : 1708393960098, + "id" : 441869217525829, + "menuName" : "设备查询", + "parentId" : 2206, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:device:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960099, + "updateBy" : null, + "updateTime" : 1708393960099, + "id" : 441869327724613, + "menuName" : "设备添加", + "parentId" : 2206, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:device:add", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960100, + "updateBy" : null, + "updateTime" : 1708393960100, + "id" : 441869398310981, + "menuName" : "设备修改", + "parentId" : 2206, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:device:edit", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960101, + "updateBy" : null, + "updateTime" : 1708393960101, + "id" : 441869530075205, + "menuName" : "设备删除", + "parentId" : 2206, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:device:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960102, + "updateBy" : null, + "updateTime" : 1708393960102, + "id" : 441869649666117, + "menuName" : "设备控制", + "parentId" : 2206, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:device:ctrl", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960103, + "updateBy" : null, + "updateTime" : 1708393960103, + "id" : 441869802405957, + "menuName" : "设备日志查询", + "parentId" : 2206, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:deviceLog:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960104, + "updateBy" : null, + "updateTime" : 1708393960104, + "id" : 441870007808069, + "menuName" : "设备组查询", + "parentId" : 2206, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:deviceGroup:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960105, + "updateBy" : null, + "updateTime" : 1708393960105, + "id" : 441870091001925, + "menuName" : "设备组添加", + "parentId" : 2206, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:deviceGroup:add", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960107, + "updateBy" : null, + "updateTime" : 1708393960107, + "id" : 441870227968069, + "menuName" : "设备组修改", + "parentId" : 2206, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:deviceGroup:edit", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960110, + "updateBy" : null, + "updateTime" : 1708393960110, + "id" : 441870309814341, + "menuName" : "设备组删除", + "parentId" : 2206, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:deviceGroup:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960112, + "updateBy" : null, + "updateTime" : 1708393960112, + "id" : 441870607315013, + "menuName" : "虚拟设备查询", + "parentId" : 2207, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:virtualDevice:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960113, + "updateBy" : null, + "updateTime" : 1708393960113, + "id" : 441870717771845, + "menuName" : "虚拟设备添加", + "parentId" : 2207, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:virtualDevice:add", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960115, + "updateBy" : null, + "updateTime" : 1708393960115, + "id" : 441870780928069, + "menuName" : "虚拟设备修改", + "parentId" : 2207, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:virtualDevice:edit", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960116, + "updateBy" : null, + "updateTime" : 1708393960116, + "id" : 441870881378373, + "menuName" : "虚拟设备删除", + "parentId" : 2207, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:virtualDevice:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960117, + "updateBy" : null, + "updateTime" : 1708393960117, + "id" : 442127357415493, + "menuName" : "插件添加", + "parentId" : 2210, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:plugin:add", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960118, + "updateBy" : null, + "updateTime" : 1708393960118, + "id" : 442127532781637, + "menuName" : "插件修改", + "parentId" : 2210, + "orderNum" : 2, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:plugin:edit", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960119, + "updateBy" : null, + "updateTime" : 1708393960119, + "id" : 442127596064837, + "menuName" : "插件查询", + "parentId" : 2210, + "orderNum" : 4, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:plugin:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960120, + "updateBy" : null, + "updateTime" : 1708393960120, + "id" : 442127705182277, + "menuName" : "插件删除", + "parentId" : 2210, + "orderNum" : 3, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:plugin:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960121, + "updateBy" : null, + "updateTime" : 1708393960121, + "id" : 442128593006661, + "menuName" : "规则查询", + "parentId" : 2212, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:rule:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960122, + "updateBy" : null, + "updateTime" : 1708393960122, + "id" : 442128733950021, + "menuName" : "规则修改", + "parentId" : 2212, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:rule:eidt", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960123, + "updateBy" : null, + "updateTime" : 1708393960123, + "id" : 442128795189317, + "menuName" : "规则删除", + "parentId" : 2212, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:rule:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960124, + "updateBy" : null, + "updateTime" : 1708393960124, + "id" : 442129175347269, + "menuName" : "定时任务查询", + "parentId" : 2213, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:task:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960125, + "updateBy" : null, + "updateTime" : 1708393960125, + "id" : 442129320091717, + "menuName" : "定时任务修改", + "parentId" : 2213, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:task:edit", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960127, + "updateBy" : null, + "updateTime" : 1708393960127, + "id" : 442129388187717, + "menuName" : "定时任务删除", + "parentId" : 2213, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:task:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960128, + "updateBy" : null, + "updateTime" : 1708393960128, + "id" : 442130419388485, + "menuName" : "通道添加", + "parentId" : 2219, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:channel:add", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960130, + "updateBy" : null, + "updateTime" : 1708393960130, + "id" : 442130475098181, + "menuName" : "通道修改", + "parentId" : 2219, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:channel:edit", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960132, + "updateBy" : null, + "updateTime" : 1708393960132, + "id" : 442130534805573, + "menuName" : "通道删除", + "parentId" : 2219, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:channel:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960133, + "updateBy" : null, + "updateTime" : 1708393960133, + "id" : 442130860195909, + "menuName" : "告警配置查询", + "parentId" : 2223, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:alertConfig:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960134, + "updateBy" : null, + "updateTime" : 1708393960134, + "id" : 442130932109381, + "menuName" : "告警配置添加", + "parentId" : 2223, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:alertConfig:add", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960135, + "updateBy" : null, + "updateTime" : 1708393960135, + "id" : 442131029889093, + "menuName" : "告警配置修改", + "parentId" : 2223, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:alertConfig:edit", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960136, + "updateBy" : null, + "updateTime" : 1708393960136, + "id" : 442131115253829, + "menuName" : "告警配置删除", + "parentId" : 2223, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:alertConfig:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960137, + "updateBy" : null, + "updateTime" : 1708393960137, + "id" : 442131294584901, + "menuName" : "告警查询", + "parentId" : 2222, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:alert:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960139, + "updateBy" : null, + "updateTime" : 1708393960139, + "id" : 442143693541445, + "menuName" : "通道查询", + "parentId" : 2219, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:channel:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960140, + "updateBy" : null, + "updateTime" : 1708393960140, + "id" : 442149490409541, + "menuName" : "OTA查询", + "parentId" : 2225, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:ota:query", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960142, + "updateBy" : null, + "updateTime" : 1708393960142, + "id" : 442149580529733, + "menuName" : "OTA添加", + "parentId" : 2225, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:ota:add", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960144, + "updateBy" : null, + "updateTime" : 1708393960144, + "id" : 442149650423877, + "menuName" : "OTA删除", + "parentId" : 2225, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:ota:remove", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960145, + "updateBy" : null, + "updateTime" : 1708393960145, + "id" : 442149811572805, + "menuName" : "执行升级", + "parentId" : 2225, + "orderNum" : 1, + "path" : "", + "component" : null, + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "F", + "visible" : "0", + "status" : "0", + "perms" : "iot:ota:upgrade", + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708393960146, + "updateBy" : null, + "updateTime" : 1708393960146, + "id" : 461626374598725, + "menuName" : "插件详情", + "parentId" : 2200, + "orderNum" : 3, + "path" : "detail/:id", + "component" : "iot/plugins/detail", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "1", + "status" : "0", + "perms" : null, + "icon" : "", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1709354700431, + "updateBy" : null, + "updateTime" : 1709354955426, + "id" : 521086150434885, + "menuName" : "设备分组", + "parentId" : 2200, + "orderNum" : 2, + "path" : "deviceGroup", + "component" : "iot/equipment/devices/deviceGroup", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:deviceGroup:list", + "icon" : "device-grouping", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1709365727999, + "updateBy" : null, + "updateTime" : 1709365772669, + "id" : 521131319332933, + "menuName" : "设备分组详情", + "parentId" : 2200, + "orderNum" : 17, + "path" : "deviceGroupDetail/:id", + "component" : "iot/equipment/devices/deviceGroupDetail", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "1", + "menuType" : "C", + "visible" : "1", + "status" : "0", + "perms" : "iot:device:query", + "icon" : "", + "remark" : null, + "children" : [ ] +} , { + "createDept" : null, + "createBy" : null, + "createTime" : 1709365727999, + "updateBy" : null, + "updateTime" : 1709365772669, + "id" : 541767098171461, + "menuName" : "Modbus管理", + "parentId" : 0, + "orderNum" : 2, + "path" : "modbus", + "component" : "", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "M", + "visible" : "0", + "status" : "0", + "perms" : "", + "icon" : "build", + "remark" : null, + "children" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1709365727999, + "updateBy" : null, + "updateTime" : 1709365772669, + "id" : 541767327625285, + "menuName" : "产品点位", + "parentId" : 541767098171461, + "orderNum" : 17, + "path" : "modbusinfo", + "component" : "iot/modbus/info/index", + "queryParam" : null, + "isFrame" : "1", + "isCache" : "0", + "menuType" : "C", + "visible" : "0", + "status" : "0", + "perms" : "iot:modbus:list", + "icon" : "radio", + "remark" : null, + "children" : [ ] +}] \ No newline at end of file diff --git a/data/init/sys_notice.json b/data/init/sys_notice.json new file mode 100644 index 0000000..c4ff4be --- /dev/null +++ b/data/init/sys_notice.json @@ -0,0 +1,29 @@ +[ { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322623, + "updateBy" : null, + "updateTime" : 1708254322623, + "tenantId" : 0, + "id" : 1, + "noticeTitle" : "温馨提醒:2018-07-01 新版本发布啦", + "noticeType" : "2", + "noticeContent" : "5paw54mI5pys5YaF5a65", + "status" : "0", + "remark" : "管理员", + "createByName" : null +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322639, + "updateBy" : null, + "updateTime" : 1708254322639, + "tenantId" : 0, + "id" : 2, + "noticeTitle" : "维护通知:2018-07-01 系统凌晨维护", + "noticeType" : "1", + "noticeContent" : "57u05oqk5YaF5a65", + "status" : "0", + "remark" : "管理员", + "createByName" : null +} ] \ No newline at end of file diff --git a/data/init/sys_oper_log.json b/data/init/sys_oper_log.json new file mode 100644 index 0000000..d276a4d --- /dev/null +++ b/data/init/sys_oper_log.json @@ -0,0 +1,276 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516580177526853, + "tenantId" : 0, + "title" : "菜单管理", + "businessType" : 2, + "businessTypes" : null, + "method" : "cc.iotkit.system.controller.SysMenuController.edit()", + "requestMethod" : "POST", + "operatorType" : 1, + "operName" : "admin", + "deptName" : null, + "operUrl" : "/system/menu/edit", + "operIp" : "127.0.0.1", + "operLocation" : "内网IP", + "operParam" : "{\"requestId\":\"8ab12839-a039-4fad-8afe-bc5c0c98354f\",\"data\":{\"createDept\":null,\"createBy\":null,\"createTime\":\"2024-02-18T11:05:22.443+00:00\",\"updateBy\":null,\"updateTime\":null,\"id\":442127357415493,\"parentId\":2210,\"menuName\":\"插件添加\",\"orderNum\":1,\"path\":\"\",\"component\":null,\"queryParam\":null,\"isFrame\":\"1\",\"isCache\":\"0\",\"menuType\":\"F\",\"visible\":\"0\",\"status\":\"0\",\"perms\":\"iot: plugin:add\",\"icon\":\"\",\"remark\":null}}", + "jsonResult" : null, + "status" : 0, + "errorMsg" : null, + "operTime" : 1708254609402, + "costTime" : 32 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516580271538245, + "tenantId" : 0, + "title" : "菜单管理", + "businessType" : 2, + "businessTypes" : null, + "method" : "cc.iotkit.system.controller.SysMenuController.edit()", + "requestMethod" : "POST", + "operatorType" : 1, + "operName" : "admin", + "deptName" : null, + "operUrl" : "/system/menu/edit", + "operIp" : "127.0.0.1", + "operLocation" : "内网IP", + "operParam" : "{\"requestId\":\"f3bfc9df-cacc-4560-8c6f-8984d231675a\",\"data\":{\"createDept\":null,\"createBy\":null,\"createTime\":\"2024-02-18T11:05:22.444+00:00\",\"updateBy\":null,\"updateTime\":null,\"id\":442127532781637,\"parentId\":2210,\"menuName\":\"插件修改\",\"orderNum\":1,\"path\":\"\",\"component\":null,\"queryParam\":null,\"isFrame\":\"1\",\"isCache\":\"0\",\"menuType\":\"F\",\"visible\":\"0\",\"status\":\"0\",\"perms\":\"iot:plugin:edit\",\"icon\":\"\",\"remark\":null}}", + "jsonResult" : null, + "status" : 0, + "errorMsg" : null, + "operTime" : 1708254632356, + "costTime" : 6 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516580303495237, + "tenantId" : 0, + "title" : "菜单管理", + "businessType" : 2, + "businessTypes" : null, + "method" : "cc.iotkit.system.controller.SysMenuController.edit()", + "requestMethod" : "POST", + "operatorType" : 1, + "operName" : "admin", + "deptName" : null, + "operUrl" : "/system/menu/edit", + "operIp" : "127.0.0.1", + "operLocation" : "内网IP", + "operParam" : "{\"requestId\":\"e5e6b549-ae57-4265-9655-1f72768289bc\",\"data\":{\"createDept\":null,\"createBy\":null,\"createTime\":\"2024-02-18T11:05:22.443+00:00\",\"updateBy\":null,\"updateTime\":null,\"id\":442127357415493,\"parentId\":2210,\"menuName\":\"插件添加\",\"orderNum\":1,\"path\":\"\",\"component\":null,\"queryParam\":null,\"isFrame\":\"1\",\"isCache\":\"0\",\"menuType\":\"F\",\"visible\":\"0\",\"status\":\"0\",\"perms\":\"iot:plugin:add\",\"icon\":\"\",\"remark\":null}}", + "jsonResult" : null, + "status" : 0, + "errorMsg" : null, + "operTime" : 1708254640158, + "costTime" : 7 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516580369678405, + "tenantId" : 0, + "title" : "菜单管理", + "businessType" : 2, + "businessTypes" : null, + "method" : "cc.iotkit.system.controller.SysMenuController.edit()", + "requestMethod" : "POST", + "operatorType" : 1, + "operName" : "admin", + "deptName" : null, + "operUrl" : "/system/menu/edit", + "operIp" : "127.0.0.1", + "operLocation" : "内网IP", + "operParam" : "{\"requestId\":\"413f5711-9b51-4b53-9c07-4a18a5d369f3\",\"data\":{\"createDept\":null,\"createBy\":null,\"createTime\":\"2024-02-18T11:05:22.446+00:00\",\"updateBy\":null,\"updateTime\":null,\"id\":442127596064837,\"parentId\":2210,\"menuName\":\"插件查询\",\"orderNum\":1,\"path\":\"\",\"component\":null,\"queryParam\":null,\"isFrame\":\"1\",\"isCache\":\"0\",\"menuType\":\"F\",\"visible\":\"0\",\"status\":\"0\",\"perms\":\"iot:plugin:query\",\"icon\":\"\",\"remark\":null}}", + "jsonResult" : null, + "status" : 0, + "errorMsg" : null, + "operTime" : 1708254656316, + "costTime" : 5 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516580424007749, + "tenantId" : 0, + "title" : "菜单管理", + "businessType" : 2, + "businessTypes" : null, + "method" : "cc.iotkit.system.controller.SysMenuController.edit()", + "requestMethod" : "POST", + "operatorType" : 1, + "operName" : "admin", + "deptName" : null, + "operUrl" : "/system/menu/edit", + "operIp" : "127.0.0.1", + "operLocation" : "内网IP", + "operParam" : "{\"requestId\":\"564af98c-3af4-4b8b-8637-6a008d34fc6d\",\"data\":{\"createDept\":null,\"createBy\":null,\"createTime\":\"2024-02-18T11:05:22.447+00:00\",\"updateBy\":null,\"updateTime\":null,\"id\":442127705182277,\"parentId\":2210,\"menuName\":\"插件删除\",\"orderNum\":1,\"path\":\"\",\"component\":null,\"queryParam\":null,\"isFrame\":\"1\",\"isCache\":\"0\",\"menuType\":\"F\",\"visible\":\"0\",\"status\":\"0\",\"perms\":\"iot:plugin:remove\",\"icon\":\"\",\"remark\":null}}", + "jsonResult" : null, + "status" : 0, + "errorMsg" : null, + "operTime" : 1708254669580, + "costTime" : 6 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516580484644933, + "tenantId" : 0, + "title" : "菜单管理", + "businessType" : 2, + "businessTypes" : null, + "method" : "cc.iotkit.system.controller.SysMenuController.edit()", + "requestMethod" : "POST", + "operatorType" : 1, + "operName" : "admin", + "deptName" : null, + "operUrl" : "/system/menu/edit", + "operIp" : "127.0.0.1", + "operLocation" : "内网IP", + "operParam" : "{\"requestId\":\"38ff89ff-6243-4c54-aa0b-735e83377836\",\"data\":{\"createDept\":null,\"createBy\":null,\"createTime\":\"2024-02-18T11:05:22.444+00:00\",\"updateBy\":null,\"updateTime\":null,\"id\":442127532781637,\"parentId\":2210,\"menuName\":\"插件修改\",\"orderNum\":2,\"path\":\"\",\"component\":null,\"queryParam\":null,\"isFrame\":\"1\",\"isCache\":\"0\",\"menuType\":\"F\",\"visible\":\"0\",\"status\":\"0\",\"perms\":\"iot:plugin:edit\",\"icon\":\"\",\"remark\":null}}", + "jsonResult" : null, + "status" : 0, + "errorMsg" : null, + "operTime" : 1708254684384, + "costTime" : 5 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516580523356229, + "tenantId" : 0, + "title" : "菜单管理", + "businessType" : 2, + "businessTypes" : null, + "method" : "cc.iotkit.system.controller.SysMenuController.edit()", + "requestMethod" : "POST", + "operatorType" : 1, + "operName" : "admin", + "deptName" : null, + "operUrl" : "/system/menu/edit", + "operIp" : "127.0.0.1", + "operLocation" : "内网IP", + "operParam" : "{\"requestId\":\"19366ec6-55f5-49cd-8f82-e7b592cc0dd1\",\"data\":{\"createDept\":null,\"createBy\":null,\"createTime\":\"2024-02-18T11:05:22.447+00:00\",\"updateBy\":null,\"updateTime\":null,\"id\":442127705182277,\"parentId\":2210,\"menuName\":\"插件删除\",\"orderNum\":3,\"path\":\"\",\"component\":null,\"queryParam\":null,\"isFrame\":\"1\",\"isCache\":\"0\",\"menuType\":\"F\",\"visible\":\"0\",\"status\":\"0\",\"perms\":\"iot:plugin:remove\",\"icon\":\"\",\"remark\":null}}", + "jsonResult" : null, + "status" : 0, + "errorMsg" : null, + "operTime" : 1708254693835, + "costTime" : 6 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516580549386309, + "tenantId" : 0, + "title" : "菜单管理", + "businessType" : 2, + "businessTypes" : null, + "method" : "cc.iotkit.system.controller.SysMenuController.edit()", + "requestMethod" : "POST", + "operatorType" : 1, + "operName" : "admin", + "deptName" : null, + "operUrl" : "/system/menu/edit", + "operIp" : "127.0.0.1", + "operLocation" : "内网IP", + "operParam" : "{\"requestId\":\"4beb5d69-7e4e-4826-abe8-cc7d860fe814\",\"data\":{\"createDept\":null,\"createBy\":null,\"createTime\":\"2024-02-18T11:05:22.446+00:00\",\"updateBy\":null,\"updateTime\":null,\"id\":442127596064837,\"parentId\":2210,\"menuName\":\"插件查询\",\"orderNum\":4,\"path\":\"\",\"component\":null,\"queryParam\":null,\"isFrame\":\"1\",\"isCache\":\"0\",\"menuType\":\"F\",\"visible\":\"0\",\"status\":\"0\",\"perms\":\"iot:plugin:query\",\"icon\":\"\",\"remark\":null}}", + "jsonResult" : null, + "status" : 0, + "errorMsg" : null, + "operTime" : 1708254700190, + "costTime" : 5 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516580700786757, + "tenantId" : 0, + "title" : "用户管理", + "businessType" : 3, + "businessTypes" : null, + "method" : "cc.iotkit.system.controller.SysUserController.remove()", + "requestMethod" : "POST", + "operatorType" : 1, + "operName" : "admin", + "deptName" : null, + "operUrl" : "/system/user/delete", + "operIp" : "127.0.0.1", + "operLocation" : "内网IP", + "operParam" : "{\"requestId\":\"32db1317-b4ee-42c8-8b44-ad077b13468d\",\"data\":[3]}", + "jsonResult" : null, + "status" : 0, + "errorMsg" : null, + "operTime" : 1708254737152, + "costTime" : 29 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516580742733893, + "tenantId" : 0, + "title" : "用户管理", + "businessType" : 3, + "businessTypes" : null, + "method" : "cc.iotkit.system.controller.SysUserController.remove()", + "requestMethod" : "POST", + "operatorType" : 1, + "operName" : "admin", + "deptName" : null, + "operUrl" : "/system/user/delete", + "operIp" : "127.0.0.1", + "operLocation" : "内网IP", + "operParam" : "{\"requestId\":\"84a35cb9-b99f-4bdc-9977-a379fc964699\",\"data\":[2]}", + "jsonResult" : null, + "status" : 0, + "errorMsg" : null, + "operTime" : 1708254747394, + "costTime" : 8 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 1665641342438514690, + "tenantId" : 0, + "title" : "代码生成", + "businessType" : 6, + "businessTypes" : null, + "method" : "org.dromara.generator.controller.GenController.importTableSave()", + "requestMethod" : null, + "operatorType" : 1, + "operName" : "admin", + "deptName" : "", + "operUrl" : "/tool/gen/importTable", + "operIp" : "127.0.0.1", + "operLocation" : "内网IP", + "operParam" : "\"sys_role_dept,sys_role_menu,sysConfig,sysDictData,sysDictType,sysLogininfor,sysNotice,sys_operLog,sys_oss,sys_ossConfig\"", + "jsonResult" : null, + "status" : 0, + "errorMsg" : null, + "operTime" : null, + "costTime" : 199 +} ] \ No newline at end of file diff --git a/data/init/sys_oss.json b/data/init/sys_oss.json new file mode 100644 index 0000000..8878e54 --- /dev/null +++ b/data/init/sys_oss.json @@ -0,0 +1 @@ +[ ] \ No newline at end of file diff --git a/data/init/sys_oss_config.json b/data/init/sys_oss_config.json new file mode 100644 index 0000000..cb33ead --- /dev/null +++ b/data/init/sys_oss_config.json @@ -0,0 +1,89 @@ +[ { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322687, + "updateBy" : 1, + "updateTime" : 1708254322687, + "tenantId" : 0, + "id" : 1, + "configKey" : "oss-embed", + "accessKey" : "admin", + "secretKey" : "123", + "bucketName" : "iot", + "prefix" : "", + "endpoint" : "localhost:8086/iot-oss", + "outside": "localhost:8086/iot-oss", + "domain" : "", + "isHttps" : null, + "region" : "local", + "status" : "0", + "ext1" : "", + "remark" : null, + "accessPolicy" : "1" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322701, + "updateBy" : 1, + "updateTime" : 1708254322701, + "tenantId" : 0, + "id" : 2, + "configKey" : "qiniu", + "accessKey" : "XXXXXXXXXXXXXXX", + "secretKey" : "XXXXXXXXXXXXXXX", + "bucketName" : "ruoyi", + "prefix" : "", + "endpoint" : "s3-cn-north-1.qiniucs.com", + "outside": "s3-cn-north-1.qiniucs.com", + "domain" : "", + "isHttps" : null, + "region" : "", + "status" : "1", + "ext1" : "", + "remark" : null, + "accessPolicy" : "1" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322703, + "updateBy" : 1, + "updateTime" : 1708254322703, + "tenantId" : 0, + "id" : 3, + "configKey" : "aliyun", + "accessKey" : "XXXXXXXXXXXXXXX", + "secretKey" : "XXXXXXXXXXXXXXX", + "bucketName" : "ruoyi", + "prefix" : "", + "endpoint" : "oss-cn-beijing.aliyuncs.com", + "outside": "oss-cn-beijing.aliyuncs.com", + "domain" : "", + "isHttps" : null, + "region" : "", + "status" : "1", + "ext1" : "", + "remark" : null, + "accessPolicy" : "1" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322705, + "updateBy" : 1, + "updateTime" : 1708254322705, + "tenantId" : 0, + "id" : 4, + "configKey" : "qcloud", + "accessKey" : "XXXXXXXXXXXXXXX", + "secretKey" : "XXXXXXXXXXXXXXX", + "bucketName" : "ruoyi-1250000000", + "prefix" : "", + "endpoint" : "cos.ap-beijing.myqcloud.com", + "outside": "cos.ap-beijing.myqcloud.com", + "domain" : "", + "isHttps" : null, + "region" : "ap-beijing", + "status" : "1", + "ext1" : "", + "remark" : null, + "accessPolicy" : "1" +}] \ No newline at end of file diff --git a/data/init/sys_post.json b/data/init/sys_post.json new file mode 100644 index 0000000..458a1d2 --- /dev/null +++ b/data/init/sys_post.json @@ -0,0 +1,53 @@ +[ { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322729, + "updateBy" : null, + "updateTime" : 1708254322729, + "tenantId" : 0, + "id" : 1, + "postCode" : "ceo", + "postName" : "董事长", + "postSort" : 1, + "status" : "0", + "remark" : "" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322742, + "updateBy" : null, + "updateTime" : 1708254322742, + "tenantId" : 0, + "id" : 2, + "postCode" : "se", + "postName" : "项目经理", + "postSort" : 2, + "status" : "0", + "remark" : "" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322745, + "updateBy" : null, + "updateTime" : 1708254322745, + "tenantId" : 0, + "id" : 3, + "postCode" : "hr", + "postName" : "人力资源", + "postSort" : 3, + "status" : "0", + "remark" : "" +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322750, + "updateBy" : null, + "updateTime" : 1708254322750, + "tenantId" : 0, + "id" : 4, + "postCode" : "user", + "postName" : "普通员工", + "postSort" : 4, + "status" : "0", + "remark" : "" +} ] \ No newline at end of file diff --git a/data/init/sys_role.json b/data/init/sys_role.json new file mode 100644 index 0000000..a924c06 --- /dev/null +++ b/data/init/sys_role.json @@ -0,0 +1,37 @@ +[ { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322779, + "updateBy" : null, + "updateTime" : 1708254322779, + "tenantId" : 0, + "id" : 1, + "roleName" : "超级管理员", + "roleKey" : "superadmin", + "roleSort" : 1, + "dataScope" : null, + "menuCheckStrictly" : null, + "deptCheckStrictly" : null, + "status" : "0", + "remark" : "超级管理员", + "flag" : false, + "superAdmin" : true +}, { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254322799, + "updateBy" : null, + "updateTime" : 1708254322799, + "tenantId" : 0, + "id" : 2, + "roleName" : "普通角色", + "roleKey" : "common", + "roleSort" : 2, + "dataScope" : null, + "menuCheckStrictly" : null, + "deptCheckStrictly" : null, + "status" : "0", + "remark" : "普通角色", + "flag" : false, + "superAdmin" : false +} ] \ No newline at end of file diff --git a/data/init/sys_role_dept.json b/data/init/sys_role_dept.json new file mode 100644 index 0000000..8b6e1c7 --- /dev/null +++ b/data/init/sys_role_dept.json @@ -0,0 +1,37 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516579003666501, + "roleId" : 2, + "deptId" : 100 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516579003695173, + "roleId" : 2, + "deptId" : 101 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516579003699269, + "roleId" : 2, + "deptId" : 105 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 516579003707461, + "roleId" : 452767970971717, + "deptId" : 452767971254341 +} ] \ No newline at end of file diff --git a/data/init/sys_role_menu.json b/data/init/sys_role_menu.json new file mode 100644 index 0000000..fd9117b --- /dev/null +++ b/data/init/sys_role_menu.json @@ -0,0 +1,1198 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041742917, + "roleId" : 2, + "menuId" : 1 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041742918, + "roleId" : 2, + "menuId" : 100 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041742919, + "roleId" : 2, + "menuId" : 1001 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747013, + "roleId" : 2, + "menuId" : 1002 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747014, + "roleId" : 2, + "menuId" : 1003 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747015, + "roleId" : 2, + "menuId" : 1005 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747016, + "roleId" : 2, + "menuId" : 101 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747017, + "roleId" : 2, + "menuId" : 1008 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747018, + "roleId" : 2, + "menuId" : 1009 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747019, + "roleId" : 2, + "menuId" : 1010 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747020, + "roleId" : 2, + "menuId" : 1012 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747021, + "roleId" : 2, + "menuId" : 102 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747022, + "roleId" : 2, + "menuId" : 1013 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747023, + "roleId" : 2, + "menuId" : 1014 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747024, + "roleId" : 2, + "menuId" : 1015 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747025, + "roleId" : 2, + "menuId" : 103 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747026, + "roleId" : 2, + "menuId" : 1017 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747027, + "roleId" : 2, + "menuId" : 1018 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747028, + "roleId" : 2, + "menuId" : 1019 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041747029, + "roleId" : 2, + "menuId" : 104 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751109, + "roleId" : 2, + "menuId" : 1021 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751110, + "roleId" : 2, + "menuId" : 1022 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751111, + "roleId" : 2, + "menuId" : 1023 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751112, + "roleId" : 2, + "menuId" : 1025 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751113, + "roleId" : 2, + "menuId" : 105 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751114, + "roleId" : 2, + "menuId" : 1026 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751115, + "roleId" : 2, + "menuId" : 1027 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751116, + "roleId" : 2, + "menuId" : 1028 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751117, + "roleId" : 2, + "menuId" : 1030 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751118, + "roleId" : 2, + "menuId" : 106 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751119, + "roleId" : 2, + "menuId" : 1031 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751120, + "roleId" : 2, + "menuId" : 1032 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751121, + "roleId" : 2, + "menuId" : 1033 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751122, + "roleId" : 2, + "menuId" : 1035 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751123, + "roleId" : 2, + "menuId" : 107 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751124, + "roleId" : 2, + "menuId" : 1036 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751125, + "roleId" : 2, + "menuId" : 1037 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751126, + "roleId" : 2, + "menuId" : 1038 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751127, + "roleId" : 2, + "menuId" : 1039 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751128, + "roleId" : 2, + "menuId" : 108 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041751129, + "roleId" : 2, + "menuId" : 500 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755205, + "roleId" : 2, + "menuId" : 1040 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755206, + "roleId" : 2, + "menuId" : 1041 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755207, + "roleId" : 2, + "menuId" : 1042 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755208, + "roleId" : 2, + "menuId" : 501 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755209, + "roleId" : 2, + "menuId" : 1043 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755210, + "roleId" : 2, + "menuId" : 1044 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755211, + "roleId" : 2, + "menuId" : 1045 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755212, + "roleId" : 2, + "menuId" : 118 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755213, + "roleId" : 2, + "menuId" : 1600 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755214, + "roleId" : 2, + "menuId" : 1601 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755215, + "roleId" : 2, + "menuId" : 1602 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755216, + "roleId" : 2, + "menuId" : 1603 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755217, + "roleId" : 2, + "menuId" : 1604 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755218, + "roleId" : 2, + "menuId" : 1605 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755219, + "roleId" : 2, + "menuId" : 2200 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041755220, + "roleId" : 2, + "menuId" : 2201 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759301, + "roleId" : 2, + "menuId" : 441851175424069 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759302, + "roleId" : 2, + "menuId" : 441851310268485 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759303, + "roleId" : 2, + "menuId" : 2214 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759304, + "roleId" : 2, + "menuId" : 2205 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759305, + "roleId" : 2, + "menuId" : 441853056651333 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759306, + "roleId" : 2, + "menuId" : 441853220675653 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759307, + "roleId" : 2, + "menuId" : 441853285179461 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759308, + "roleId" : 2, + "menuId" : 441862877970501 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759309, + "roleId" : 2, + "menuId" : 441862978281541 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759310, + "roleId" : 2, + "menuId" : 2206 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759311, + "roleId" : 2, + "menuId" : 441869217525829 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041759312, + "roleId" : 2, + "menuId" : 441869327724613 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041763397, + "roleId" : 2, + "menuId" : 441869398310981 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041763398, + "roleId" : 2, + "menuId" : 441869649666117 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041763399, + "roleId" : 2, + "menuId" : 441869802405957 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041763400, + "roleId" : 2, + "menuId" : 441870007808069 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041763401, + "roleId" : 2, + "menuId" : 441870091001925 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041763402, + "roleId" : 2, + "menuId" : 441870227968069 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041763403, + "roleId" : 2, + "menuId" : 2207 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041763404, + "roleId" : 2, + "menuId" : 441870607315013 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041763405, + "roleId" : 2, + "menuId" : 441870717771845 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041763406, + "roleId" : 2, + "menuId" : 441870780928069 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041763407, + "roleId" : 2, + "menuId" : 2215 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041767493, + "roleId" : 2, + "menuId" : 2225 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041767494, + "roleId" : 2, + "menuId" : 442149490409541 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041767495, + "roleId" : 2, + "menuId" : 442149580529733 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041767496, + "roleId" : 2, + "menuId" : 442149811572805 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041767497, + "roleId" : 2, + "menuId" : 2208 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041767498, + "roleId" : 2, + "menuId" : 2209 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041771591, + "roleId" : 2, + "menuId" : 2210 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041771592, + "roleId" : 2, + "menuId" : 442127357415493 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041771593, + "roleId" : 2, + "menuId" : 442127532781637 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041771594, + "roleId" : 2, + "menuId" : 442127596064837 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041771595, + "roleId" : 2, + "menuId" : 2211 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041771596, + "roleId" : 2, + "menuId" : 2212 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041771597, + "roleId" : 2, + "menuId" : 442128593006661 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041771598, + "roleId" : 2, + "menuId" : 442128733950021 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041771599, + "roleId" : 2, + "menuId" : 2213 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041775685, + "roleId" : 2, + "menuId" : 442129175347269 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041775686, + "roleId" : 2, + "menuId" : 442129320091717 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041775687, + "roleId" : 2, + "menuId" : 2216 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041775688, + "roleId" : 2, + "menuId" : 2217 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041775689, + "roleId" : 2, + "menuId" : 2218 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041775690, + "roleId" : 2, + "menuId" : 2219 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041775691, + "roleId" : 2, + "menuId" : 442130419388485 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041775692, + "roleId" : 2, + "menuId" : 442130475098181 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041775693, + "roleId" : 2, + "menuId" : 442143693541445 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041775694, + "roleId" : 2, + "menuId" : 2220 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041775695, + "roleId" : 2, + "menuId" : 2221 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779781, + "roleId" : 2, + "menuId" : 2222 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779782, + "roleId" : 2, + "menuId" : 442131294584901 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779783, + "roleId" : 2, + "menuId" : 2223 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779784, + "roleId" : 2, + "menuId" : 442130860195909 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779785, + "roleId" : 2, + "menuId" : 442130932109381 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779786, + "roleId" : 2, + "menuId" : 442131029889093 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779787, + "roleId" : 2, + "menuId" : 6 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779788, + "roleId" : 2, + "menuId" : 121 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779789, + "roleId" : 2, + "menuId" : 1606 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779790, + "roleId" : 2, + "menuId" : 1607 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779791, + "roleId" : 2, + "menuId" : 1608 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779792, + "roleId" : 2, + "menuId" : 1610 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779793, + "roleId" : 2, + "menuId" : 1611 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779794, + "roleId" : 2, + "menuId" : 1612 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779795, + "roleId" : 2, + "menuId" : 1613 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779796, + "roleId" : 2, + "menuId" : 1615 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779797, + "roleId" : 2, + "menuId" : 2 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041779798, + "roleId" : 2, + "menuId" : 109 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041783877, + "roleId" : 2, + "menuId" : 1046 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041783879, + "roleId" : 2, + "menuId" : 115 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041783880, + "roleId" : 2, + "menuId" : 1055 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041783881, + "roleId" : 2, + "menuId" : 1056 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041783882, + "roleId" : 2, + "menuId" : 1058 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041783883, + "roleId" : 2, + "menuId" : 1057 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041783884, + "roleId" : 2, + "menuId" : 1059 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041783885, + "roleId" : 2, + "menuId" : 1060 +}, { + "createDept" : null, + "createBy" : null, + "createTime" : null, + "updateBy" : null, + "updateTime" : null, + "id" : 447227041783886, + "roleId" : 2, + "menuId" : 4 +} ] \ No newline at end of file diff --git a/data/init/sys_tenant.json b/data/init/sys_tenant.json new file mode 100644 index 0000000..1b159b0 --- /dev/null +++ b/data/init/sys_tenant.json @@ -0,0 +1,41 @@ +[ { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254323415, + "updateBy" : null, + "updateTime" : 1708254323415, + "id" : 1, + "tenantId" : 0, + "contactUserName" : "管理组", + "contactPhone" : "15888888888", + "companyName" : "XXX有限公司", + "licenseNumber" : null, + "address" : null, + "domain" : null, + "intro" : "多租户通用后台管理管理系统", + "remark" : null, + "packageId" : null, + "expireTime" : null, + "accountCount" : -1, + "status" : "0" +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254323430, + "updateBy" : null, + "updateTime" : 1708254323430, + "id" : 452748015235141, + "tenantId" : "452748015218757", + "contactUserName" : "测试人员", + "contactPhone" : "18888888888", + "companyName" : "测试租户有限公司", + "licenseNumber" : "12312312312", + "address" : "13123123", + "domain" : null, + "intro" : "测试租户有限公司管理系统", + "remark" : "租户管理员账密:test/test123", + "packageId" : 450389924483141, + "expireTime" : null, + "accountCount" : -1, + "status" : "0" +} ] \ No newline at end of file diff --git a/data/init/sys_tenant_package.json b/data/init/sys_tenant_package.json new file mode 100644 index 0000000..fad4184 --- /dev/null +++ b/data/init/sys_tenant_package.json @@ -0,0 +1,13 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254323450, + "updateBy" : null, + "updateTime" : 1708254323450, + "id" : 450389924483141, + "packageName" : "测试套餐", + "menuIds" : "1,100,1001,1002,1003,1004,1005,1006,1007,101,1008,1009,1010,1011,1012,102,1013,1014,1015,1016,103,1017,1018,1019,1020,104,1021,1022,1023,1024,1025,105,1026,1027,1028,1029,1030,106,1031,1032,1033,1034,1035,107,1036,1037,1038,1039,108,500,1040,1041,1042,501,1043,1044,1045,1050,118,1600,1601,1602,1603,1604,1605,502,442129,44212332,442123323123,423,4234553537,2200,2201,441851175424069,441851310268485,441851485323333,2214,2205,441853056651333,441853220675653,441853285179461,441862726639685,441862877970501,441862978281541,441863058096197,2206,441869217525829,441869327724613,441869398310981,441869530075205,441869649666117,441869802405957,441870007808069,441870091001925,441870227968069,441870309814341,2207,441870607315013,441870717771845,441870780928069,441870881378373,2215,2225,442149490409541,442149580529733,442149650423877,442149811572805,2208,2209,2210,442127357415493,442127532781637,442127596064837,442127705182277,2211,2212,442128593006661,442128733950021,442128795189317,2213,442129175347269,442129320091717,442129388187717,2216,2217,2218,2219,442130419388485,442130475098181,442130534805573,442143693541445,2220,2221,2222,442131294584901,2223,442130860195909,442130932109381,442131029889093,442131115253829", + "remark" : "测试套餐", + "menuCheckStrictly" : true, + "status" : "0" +} ] \ No newline at end of file diff --git a/data/init/sys_user.json b/data/init/sys_user.json new file mode 100644 index 0000000..bac64fb --- /dev/null +++ b/data/init/sys_user.json @@ -0,0 +1,27 @@ +[ { + "createDept" : 103, + "createBy" : 1, + "createTime" : 1708254323474, + "updateBy" : 1, + "updateTime" : 1708254547736, + "tenantId" : 0, + "id" : 1, + "deptId" : 103, + "userName" : "admin", + "nickName" : "admin", + "userType" : "sys_user", + "email" : "xw2sy@163.com", + "phonenumber" : "15888888888", + "sex" : "1", + "avatar" : null, + "password" : "$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2", + "status" : "0", + "loginIp" : "127.0.0.1", + "loginDate" : 1708254547731, + "remark" : "管理员", + "dept" : null, + "roles" : null, + "roleIds" : null, + "postIds" : null, + "roleId" : null +} ] \ No newline at end of file diff --git a/data/init/sys_user_post.json b/data/init/sys_user_post.json new file mode 100644 index 0000000..2abf047 --- /dev/null +++ b/data/init/sys_user_post.json @@ -0,0 +1,10 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254323498, + "updateBy" : null, + "updateTime" : 1708254323498, + "id" : 516579006476357, + "userId" : 1, + "postId" : 1 +} ] \ No newline at end of file diff --git a/data/init/sys_user_role.json b/data/init/sys_user_role.json new file mode 100644 index 0000000..578da5a --- /dev/null +++ b/data/init/sys_user_role.json @@ -0,0 +1,10 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254323519, + "updateBy" : null, + "updateTime" : 1708254323519, + "id" : 516579006554181, + "userId" : 1, + "roleId" : 1 +}] \ No newline at end of file diff --git a/data/init/taskInfo.json b/data/init/taskInfo.json new file mode 100644 index 0000000..a276e48 --- /dev/null +++ b/data/init/taskInfo.json @@ -0,0 +1,23 @@ +[ { + "id" : "97f79dde-bf3c-4d5b-bfd8-8102539002ad", + "name" : "测试111", + "type" : "timer", + "expression" : "*/25 * * * * ? *", + "desc" : "sss入网", + "actions" : null, + "state" : "stopped", + "uid" : "1", + "createAt" : 1645928016031, + "reason" : "stop by 1" +}, { + "id" : "667bbfa1-a7ed-4ce8-9ce0-cfa8cac90e6c", + "name" : "2222", + "type" : "delay", + "expression" : "22", + "desc" : "2222", + "actions" : null, + "state" : "stopped", + "uid" : null, + "createAt" : 1645871966035, + "reason" : "stop by 6286886077b91b031115e6a6" +} ] \ No newline at end of file diff --git a/data/init/thingModel.json b/data/init/thingModel.json new file mode 100644 index 0000000..7ae5810 --- /dev/null +++ b/data/init/thingModel.json @@ -0,0 +1,3291 @@ +[ + { + "id": 1, + "productKey": "xpsYHExTKPFaQMS7", + "model": { + "properties": [ + { + "identifier": "powerstate", + "dataType": { + "type": "enum", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "开关", + "accessMode": "rw" + }, + { + "identifier": "brightness", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "100" + } + }, + "name": "亮度", + "accessMode": "rw" + } + ], + "services": [], + "events": [] + } + }, + { + "id": 2, + "productKey": "hdX3PCMcFrCYpesJ", + "model": { + "properties": [ + { + "identifier": "windSpeed", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "10" + } + }, + "name": "风速", + "accessMode": "rw" + }, + { + "identifier": "powerSwitch", + "dataType": { + "type": "bool", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "电源开关", + "accessMode": "rw" + }, + { + "identifier": "workMode", + "dataType": { + "type": "enum", + "specs": { + "1": "正常风", + "2": "自然风", + "3": "睡眠风", + "4": "静音风" + } + }, + "name": "工作模式", + "accessMode": "rw" + } + ], + "services": [], + "events": [] + } + }, + { + "id": 3, + "productKey": "hbtgIA0SuVw9lxjB", + "model": { + "properties": [], + "services": [ + { + "identifier": "allowJoin", + "inputData": [], + "outputData": [], + "name": "开启入网" + }, + { + "identifier": "rawSend", + "inputData": [ + { + "identifier": "data", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "数据", + "required": false + }, + { + "identifier": "deviceName", + "dataType": { + "type": "text", + "specs": { + "length": "128" + } + }, + "name": "设备唯一码", + "required": false + }, + { + "identifier": "model", + "dataType": { + "type": "text", + "specs": { + "length": "128" + } + }, + "name": "设备型号", + "required": false + } + ], + "outputData": [], + "name": "透传下发" + } + ], + "events": [ + { + "identifier": "rawReport", + "outputData": [ + { + "identifier": "data", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "数据", + "required": false + }, + { + "identifier": "deviceName", + "dataType": { + "type": "text", + "specs": { + "length": "128" + } + }, + "name": "设备唯一码", + "required": false + }, + { + "identifier": "model", + "dataType": { + "type": "text", + "specs": { + "length": "128" + } + }, + "name": "设备型号", + "required": false + } + ], + "name": "透传上报" + } + ] + } + }, + { + "id": 4, + "productKey": "eDhXKwEzwFybM5R7", + "model": { + "properties": [ + { + "identifier": "powerstate", + "dataType": { + "type": "enum", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "全开关", + "accessMode": "rw" + }, + { + "identifier": "powerstate_1", + "dataType": { + "type": "enum", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "开关1", + "accessMode": "rw" + }, + { + "identifier": "powerstate_2", + "dataType": { + "type": "enum", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "开关2", + "accessMode": "rw" + }, + { + "identifier": "powerstate_3", + "dataType": { + "type": "enum", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "开关3", + "accessMode": "rw" + }, + { + "identifier": "DeviceType", + "dataType": { + "type": "text", + "specs": { + "length": "128" + } + }, + "name": "型号", + "accessMode": "r" + }, + { + "identifier": "rssi", + "dataType": { + "type": "int32", + "specs": { + "min": "-127", + "max": "127" + } + }, + "name": "信号强度", + "accessMode": "r" + } + ], + "services": [], + "events": [ + { + "identifier": "faultReportEvent", + "outputData": [ + { + "identifier": "code", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "错误代码" + } + ], + "name": "故障上报" + } + ] + } + }, + { + "id": 5, + "productKey": "cGCrkK7Ex4FESAwe", + "model": { + "properties": [ + { + "identifier": "rssi", + "dataType": { + "type": "int32", + "specs": { + "min": "-127", + "max": "127" + } + }, + "name": "信号强度", + "accessMode": "r" + }, + { + "identifier": "DeviceType", + "dataType": { + "type": "text", + "specs": { + "length": "128" + } + }, + "name": "设备型号", + "accessMode": "r" + }, + { + "identifier": "powerstate", + "dataType": { + "type": "bool", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "开关", + "accessMode": "rw" + } + ], + "services": [ + { + "identifier": "Toggle", + "inputData": [], + "outputData": [], + "name": "开关切换" + } + ], + "events": [ + { + "identifier": "faultReportEvent", + "outputData": [ + { + "identifier": "code", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "255" + } + }, + "name": "错误代码" + } + ], + "name": "故障上报" + } + ] + } + }, + { + "id": 6, + "productKey": "Rf4QSjbm65X45753", + "model": { + "properties": [ + { + "identifier": "powerstate", + "dataType": { + "type": "bool", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "开关状态", + "accessMode": "rw" + }, + { + "identifier": "volt", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电压", + "accessMode": "r" + } + ], + "services": [ + { + "identifier": "service1", + "inputData": [ + { + "identifier": "p1", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "100" + } + }, + "name": "参数1" + }, + { + "identifier": "p2", + "dataType": { + "type": "text", + "specs": { + "length": "90" + } + }, + "name": "参数2" + } + ], + "outputData": [], + "name": "服务1" + } + ], + "events": [ + { + "identifier": "event1", + "outputData": [ + { + "identifier": "p1", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "参数p1" + }, + { + "identifier": "p2", + "dataType": { + "type": "text", + "specs": { + "length": "100" + } + }, + "name": "参数p2" + } + ], + "name": "测试event1" + } + ] + }, + "_class": "cc.iotkit.model.ThingModel" + }, + { + "id": 7, + "productKey": "PN3EDmkBZDD8whDd", + "model": { + "properties": [ + { + "identifier": "power", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "电量", + "accessMode": "r" + }, + { + "identifier": "DeviceType", + "dataType": { + "type": "text", + "specs": { + "length": "128" + } + }, + "name": "设备型号", + "accessMode": "r" + }, + { + "identifier": "rssi", + "dataType": { + "type": "int32", + "specs": { + "min": "-127", + "max": "127" + } + }, + "name": "信号强度", + "accessMode": "r" + }, + { + "identifier": "doorStatus", + "dataType": { + "type": "enum", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "门状态", + "accessMode": "r" + } + ], + "services": [], + "events": [ + { + "identifier": "prylockEvent", + "outputData": [], + "name": "防撬报警事件" + } + ] + } + }, + { + "id": 8, + "productKey": "N523nWsCiG3CAn6X", + "model": { + "properties": [ + { + "identifier": "DeviceType", + "dataType": { + "type": "text", + "specs": { + "length": "128" + } + }, + "name": "设备型号", + "accessMode": "r" + }, + { + "identifier": "UnbindAndDelete", + "dataType": { + "type": "bool", + "specs": { + "0": "否", + "1": "是" + } + }, + "name": "解绑并删除设备", + "accessMode": "rw" + } + ], + "services": [ + { + "identifier": "Reboot", + "inputData": [], + "outputData": [], + "name": "重启" + }, + { + "identifier": "AllowJoin", + "inputData": [], + "outputData": [], + "name": "开启组网" + }, + { + "identifier": "OpenTrace", + "inputData": [ + { + "identifier": "enable", + "dataType": { + "type": "bool", + "specs": { + "0": "Close", + "1": "Open" + } + }, + "name": "值" + } + ], + "outputData": [], + "name": "打开调试" + }, + { + "identifier": "ShowDesc", + "inputData": [ + { + "identifier": "ieee", + "dataType": { + "type": "text", + "specs": { + "length": "32" + } + }, + "name": "设备地址" + } + ], + "outputData": [], + "name": "显示设备信息" + }, + { + "identifier": "rawSend", + "inputData": [ + { + "identifier": "model", + "dataType": { + "type": "text", + "specs": {} + }, + "name": "设备型号" + }, + { + "identifier": "mac", + "dataType": { + "type": "text", + "specs": {} + }, + "name": "设备mac" + }, + { + "identifier": "data", + "dataType": { + "type": "text", + "specs": {} + }, + "name": "数据" + } + ], + "outputData": [], + "name": "透传下发" + } + ], + "events": [ + { + "identifier": "faultReport", + "outputData": [ + { + "identifier": "code", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "255" + } + }, + "name": "错误码" + } + ], + "name": "故障上报" + }, + { + "identifier": "rawReport", + "outputData": [ + { + "identifier": "model", + "dataType": { + "type": "text", + "specs": { + "length": "128" + } + }, + "name": "设备型号" + }, + { + "identifier": "mac", + "dataType": { + "type": "text", + "specs": {} + }, + "name": "设备mac" + }, + { + "identifier": "data", + "dataType": { + "type": "text", + "specs": {} + }, + "name": "数据" + } + ], + "name": "透传上报" + } + ] + } + }, + { + "id": 9, + "productKey": "KdJYpTp5ywNhmrmC", + "model": { + "properties": [], + "services": [], + "events": [ + { + "identifier": "userDevicesChange", + "outputData": [ + { + "identifier": "uid", + "dataType": { + "type": "text", + "specs": { + "length": "100" + } + }, + "name": "用户Id" + } + ], + "name": "用户设备列表变更" + } + ] + } + }, + { + "id": 10, + "productKey": "Eit3kmGJtxSHfCKT", + "model": { + "properties": [ + { + "identifier": "flow", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100000" + } + }, + "name": "用量", + "accessMode": "r" + }, + { + "identifier": "fee", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100000" + } + }, + "name": "费用", + "accessMode": "rw" + } + ], + "services": [], + "events": [] + } + }, + { + "id": 11, + "productKey": "D8c5pXFmt2KJDxNm", + "model": { + "properties": [ + { + "identifier": "powerstate_1", + "dataType": { + "type": "enum", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "开关1", + "accessMode": "r" + }, + { + "identifier": "powerstate_2", + "dataType": { + "type": "enum", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "开关2", + "accessMode": "r" + }, + { + "identifier": "powerstate_3", + "dataType": { + "type": "enum", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "开关3", + "accessMode": "r" + }, + { + "identifier": "powerstate_4", + "dataType": { + "type": "enum", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "开关4", + "accessMode": "r" + }, + { + "identifier": "DeviceType", + "dataType": { + "type": "text", + "specs": { + "length": "128" + } + }, + "name": "型号", + "accessMode": "r" + }, + { + "identifier": "rssi", + "dataType": { + "type": "int32", + "specs": { + "min": "-127", + "max": "127" + } + }, + "name": "信号强度", + "accessMode": "r" + } + ], + "services": [], + "events": [ + { + "identifier": "faultReportEvent", + "outputData": [ + { + "identifier": "code", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "错误代码" + } + ], + "name": "故障上报" + } + ] + } + }, + { + "id": 12, + "productKey": "AWcJnf7ymGSkaz5M", + "model": { + "properties": [ + { + "identifier": "rssi", + "dataType": { + "type": "int32", + "specs": { + "min": "-128", + "max": "128" + } + }, + "name": "信号强度", + "accessMode": "r" + }, + { + "identifier": "switch", + "dataType": { + "type": "bool", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "开关", + "accessMode": "rw" + }, + { + "identifier": "voltage", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "1000" + } + }, + "name": "电压", + "accessMode": "r" + }, + { + "identifier": "current", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "1000" + } + }, + "name": "电流", + "accessMode": "r" + }, + { + "identifier": "power", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "1000000" + } + }, + "name": "功率", + "accessMode": "r" + }, + { + "identifier": "electricty", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "1000000000" + } + }, + "name": "电量", + "accessMode": "r" + }, + { + "identifier": "back_light", + "dataType": { + "type": "bool", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "背光灯", + "accessMode": "rw" + }, + { + "identifier": "start_onoff", + "dataType": { + "type": "enum", + "specs": { + "0": "off", + "1": "onoff with swithc", + "2": "on" + } + }, + "name": "上电启动配置", + "accessMode": "rw" + }, + { + "identifier": "cycle_timer", + "dataType": { + "type": "text", + "specs": { + "length": "64" + } + }, + "name": "循环定时", + "accessMode": "rw" + }, + { + "identifier": "countdown", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "1000000" + } + }, + "name": "倒计时", + "accessMode": "rw" + } + ], + "services": [], + "events": [] + } + }, + { + "id": 13, + "productKey": "6kYp6jszrDns2yh4", + "model": { + "properties": [ + { + "identifier": "humidity", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "湿度\t", + "accessMode": "r" + }, + { + "identifier": "temperature", + "dataType": { + "type": "int32", + "specs": { + "min": "-38", + "max": "656" + } + }, + "name": "温度\t", + "accessMode": "r" + } + ], + "services": [], + "events": [ + { + "identifier": "temperatureTooLowEvent", + "outputData": [], + "name": "温度过低事件" + } + ] + } + }, + { + "id": 14, + "productKey": "bGdZt8ffBETtsirm", + "model": { + "properties": [ + { + "identifier": "temp", + "dataType": { + "type": "int32", + "specs": { + "min": "17", + "max": "32" + } + }, + "name": "温度", + "accessMode": "rw", + "description": "温度", + "unit": "℃" + }, + { + "identifier": "swing_modes", + "dataType": { + "type": "enum", + "specs": { + "off": "关", + "on": "开" + } + }, + "name": "扫风开关", + "accessMode": "rw", + "description": "扫风开关" + }, + { + "identifier": "modes", + "dataType": { + "type": "enum", + "specs": { + "heat": "制热", + "off": "关闭", + "cool": "制冷", + "fan_only": "送风" + } + }, + "name": "模式", + "accessMode": "rw", + "description": "模式" + }, + { + "identifier": "fan_modes", + "dataType": { + "type": "enum", + "specs": { + "high": "高", + "medium": "中", + "low": "低" + } + }, + "name": "风模式", + "accessMode": "rw", + "description": "风模式" + }, + { + "identifier": "preset_modes", + "dataType": { + "type": "enum", + "specs": { + "eco": "节能", + "sleep": "睡眠", + "activity": "活动" + } + }, + "name": "预设模式", + "accessMode": "rw", + "description": "预设模式" + } + ], + "services": [ + ], + "events": [ + ] + } + }, + { + "id": 15, + "productKey": "BRD3x4fkKxkaxXFt", + "model": { + "properties": [], + "services": [ + { + "identifier": "readData", + "inputData": [ + { + "identifier": "deviceAddr", + "dataType": { + "type": "text", + "specs": { + "length": "12" + } + }, + "name": "设备地址", + "required": false + }, + { + "identifier": "dataIdentifier", + "dataType": { + "type": "text", + "specs": { + "length": "4" + } + }, + "name": "数据标识", + "required": false + } + ], + "outputData": [], + "name": "读数据" + }, + { + "identifier": "writeData", + "inputData": [ + { + "identifier": "deviceAddr", + "dataType": { + "type": "text", + "specs": { + "length": "12" + } + }, + "name": "设备地址", + "required": false + }, + { + "identifier": "dataIdentifier", + "dataType": { + "type": "text", + "specs": { + "length": "4" + } + }, + "name": "数据标识", + "required": false + } + ], + "outputData": [], + "name": "写数据" + } + ], + "events": [] + } + }, + { + "id": 16, + "productKey": "PwMfpXmp4ZWkGahn", + "model": { + "properties": [ + { + "identifier": "p9010", + "dataType": { + "type": "text", + "specs": { + "length": "20" + } + }, + "name": "(当前)正向有功总电能", + "accessMode": "r" + }, + { + "identifier": "p9410", + "dataType": { + "type": "text", + "specs": { + "length": "20" + } + }, + "name": "(上月)正向有功总电能", + "accessMode": "r" + } + ], + "services": [], + "events": [] + } + }, + { + "id": 17, + "productKey": "openiitapump01", + "model": { + "properties": [ + { + "identifier": "status", + "dataType": { + "type": "bool", + "specs": { + "0": "关", + "1": "开" + } + }, + "name": "状态", + "accessMode": "rw" + }, + { + "identifier": "pressure", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "压力", + "accessMode": "rw" + }, + { + "identifier": "model", + "dataType": { + "type": "enum", + "specs": { + "0": "自动模式", + "1": "手动模式", + "2": "定时模式", + "3": "防锈模式", + "4": "防冻模式" + } + }, + "name": "模式", + "accessMode": "rw" + }, + { + "identifier": "slave_id", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "255" + } + }, + "name": "连接配置-从机地址", + "accessMode": "rw" + }, + { + "identifier": "baud", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "连接配置-波特率", + "accessMode": "rw" + }, + { + "identifier": "verify", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "1" + } + }, + "name": "连接配置-奇偶校验", + "accessMode": "rw" + }, + { + "identifier": "retain", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "连接配置-保留位", + "accessMode": "rw" + }, + { + "identifier": "data_len", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "连接配置-数据位", + "accessMode": "rw" + }, + { + "identifier": "alarm", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "故障信息", + "accessMode": "r" + }, + { + "identifier": "vol", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "电压", + "accessMode": "r" + }, + { + "identifier": "elect", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "电流", + "accessMode": "r" + }, + { + "identifier": "power", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "功率", + "accessMode": "r" + }, + { + "identifier": "spd", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "转速", + "accessMode": "r" + }, + { + "identifier": "realPre", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "实时压力1", + "accessMode": "r" + }, + { + "identifier": "runStat", + "dataType": { + "type": "int32", + "specs": {} + }, + "name": "实时状态", + "accessMode": "r" + }, + { + "identifier": "mcuVersion", + "dataType": { + "type": "text", + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "MCU版本", + "accessMode": "r" + } + ], + "services": [], + "events": [] + } + }, + { + "id": 18, + "productKey": "openiitanbpump01", + "model": { + "properties": [ + { + "identifier": "WorkMode", + "dataType": { + "type": "enum", + "specs": { + "0": "自动", + "1": "手动", + "2": "自检1", + "3": "防锈", + "4": "防冻", + "5": "自检2", + "6": "温控" + } + }, + "name": "模式", + "accessMode": "rw" + }, + { + "identifier": "Pressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10", + "precision": "1" + } + }, + "name": "设置压力", + "accessMode": "rw" + }, + { + "identifier": "Switch", + "dataType": { + "type": "enum", + "specs": { + "85": "关闭", + "170": "开启" + } + }, + "name": "开关", + "accessMode": "rw" + }, + { + "identifier": "EmtyRunPressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10", + "precision": "1" + } + }, + "name": "缺水压力", + "accessMode": "rw" + }, + { + "identifier": "StartPressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10", + "precision": "1" + } + }, + "name": "开启压力", + "accessMode": "rw" + }, + { + "identifier": "WaterT", + "dataType": { + "type": "int32", + "specs": { + "min": "35", + "max": "100" + } + }, + "name": "水温保护", + "accessMode": "rw" + }, + { + "identifier": "WaterTReset", + "dataType": { + "type": "int32", + "specs": { + "min": "35", + "max": "100" + } + }, + "name": "水温复位", + "accessMode": "rw" + }, + { + "identifier": "ClearIceEn", + "dataType": { + "type": "enum", + "specs": { + "0": "关闭", + "1": "开启" + } + }, + "name": "防冻", + "accessMode": "rw" + }, + { + "identifier": "ErrorMsg", + "dataType": { + "type": "enum", + "specs": { + "0": "无", + "1": "过压", + "2": "欠压", + "3": "过流", + "4": "电机高温", + "5": "IPM高温", + "6": "堵转", + "7": "温升保护", + "8": "启动失败", + "9": "缺相", + "10": "无-", + "11": "软件过流", + "12": "缺水", + "13": "未激活", + "14": "传感器故障", + "15": "通信故障" + } + }, + "name": "故障信息", + "accessMode": "r" + }, + { + "identifier": "Voltage", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "300" + } + }, + "name": "电压", + "accessMode": "r" + }, + { + "identifier": "Electric", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "100", + "precision": "" + } + }, + "name": "电流", + "accessMode": "r" + }, + { + "identifier": "Power", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "5000" + } + }, + "name": "功率", + "accessMode": "r" + }, + { + "identifier": "Speed", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "10000" + } + }, + "name": "转速", + "accessMode": "r" + }, + { + "identifier": "CurrentPressure1", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10" + } + }, + "name": "实时压力1", + "accessMode": "r" + }, + { + "identifier": "CurrentPressure2", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10" + } + }, + "name": "实时压力2", + "accessMode": "r" + }, + { + "identifier": "IpmTemperature", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "IPM温度", + "accessMode": "r" + }, + { + "identifier": "MotorTemperature", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电机温度", + "accessMode": "r" + }, + { + "identifier": "WaterTemperature", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "水温度", + "accessMode": "r" + }, + { + "identifier": "McuStatus", + "dataType": { + "type": "enum", + "specs": { + "0": "APP", + "8": "BootLoader" + } + }, + "name": "MCU状态", + "accessMode": "r" + }, + { + "identifier": "Scene", + "dataType": { + "type": "enum", + "specs": { + "0": "增压泵", + "1": "回水器", + "2": "循环泵" + } + }, + "name": "设备场景", + "accessMode": "r" + }, + { + "identifier": "WarnInfo", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "警告信息", + "accessMode": "r" + }, + { + "identifier": "ActiveTime", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "激活时间", + "accessMode": "rw" + }, + { + "identifier": "SensorMode", + "dataType": { + "type": "enum", + "specs": { + "0": "自动", + "1": "手动" + } + }, + "name": "传感器组合模式", + "accessMode": "rw" + }, + { + "identifier": "SensorGroup", + "dataType": { + "type": "enum", + "specs": { + "0": "无传感器", + "1": "水流开关-压力", + "2": "单水流开关", + "3": "单压力", + "4": "双压力" + } + }, + "name": "传感器组合", + "accessMode": "rw" + }, + { + "identifier": "ElectronicTMax", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电机保护温度", + "accessMode": "rw" + }, + { + "identifier": "ElectronicTMaxReset", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电机复位温度", + "accessMode": "rw" + }, + { + "identifier": "History", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "历史上报", + "accessMode": "r" + }, + { + "identifier": "Model", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "设备型号", + "accessMode": "r" + }, + { + "identifier": "HandMode", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "手动模式挡位", + "accessMode": "rw" + }, + { + "identifier": "TempGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "温控挡位", + "accessMode": "rw" + }, + { + "identifier": "RatioGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "比例挡位", + "accessMode": "rw" + }, + { + "identifier": "SpeedGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "速度挡位", + "accessMode": "rw" + }, + { + "identifier": "PressureGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "压力挡位", + "accessMode": "rw" + }, + { + "identifier": "SceneMode", + "dataType": { + "type": "enum", + "specs": { + "0": "节能模式-自动挡", + "1": "温控模式-温控模式", + "2": "一键热水-恒速模式", + "3": "定时模式-恒压模式", + "4": "比例模式" + } + }, + "name": "回水器/循环泵-设置模式", + "accessMode": "rw" + }, + { + "identifier": "EnergyModeTime", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "节能模式运行时间", + "accessMode": "rw" + }, + { + "identifier": "WaterTime", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "水流开关设置", + "accessMode": "rw" + }, + { + "identifier": "HotWaterTime", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "一键热水运行时间", + "accessMode": "rw" + }, + { + "identifier": "TempSet", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "温控上下限设置", + "accessMode": "rw" + }, + { + "identifier": "CountDown", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "回水器倒计时", + "accessMode": "rw" + }, + { + "identifier": "Enabled", + "dataType": { + "type": "enum", + "specs": { + "0": "停止", + "1": "开启" + } + }, + "name": "实时运行状态", + "accessMode": "rw" + }, + { + "identifier": "TimeModeSet", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "定时模式时间设置", + "accessMode": "rw" + }, + { + "identifier": "McuVersion", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "Mcu版本号", + "accessMode": "rw" + } + ], + "services": [ + { + "identifier": "set", + "inputData": [ + { + "identifier": "WorkMode", + "dataType": { + "type": "enum", + "specs": { + "0": "自动", + "1": "手动", + "2": "自检1", + "3": "防锈", + "4": "防冻", + "5": "自检2", + "6": "温控" + } + }, + "name": "模式", + "required": false + }, + { + "identifier": "Pressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10", + "precision": "1" + } + }, + "name": "设置压力", + "required": false + }, + { + "identifier": "Switch", + "dataType": { + "type": "enum", + "specs": { + "85": "关闭", + "170": "开启" + } + }, + "name": "开关", + "required": false + }, + { + "identifier": "EmtyRunPressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10", + "precision": "1" + } + }, + "name": "缺水压力", + "required": false + }, + { + "identifier": "StartPressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10" + } + }, + "name": "开启压力", + "required": false + }, + { + "identifier": "WaterT", + "dataType": { + "type": "int32", + "specs": { + "min": "35", + "max": "100" + } + }, + "name": "水温保护", + "required": false + }, + { + "identifier": "WaterTReset", + "dataType": { + "type": "int32", + "specs": { + "min": "35", + "max": "100" + } + }, + "name": "水温复位", + "required": false + }, + { + "identifier": "ClearIceEn", + "dataType": { + "type": "enum", + "specs": { + "0": "关闭", + "1": "开启" + } + }, + "name": "防冻", + "required": false + }, + { + "identifier": "ActiveTime", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "激活时间", + "required": false + }, + { + "identifier": "SensorMode", + "dataType": { + "type": "enum", + "specs": { + "0": "自动", + "1": "手动" + } + }, + "name": "传感器组合模式", + "required": false + }, + { + "identifier": "SensorGroup", + "dataType": { + "type": "enum", + "specs": { + "0": "无传感器", + "1": "水流开关-压力", + "2": "单水流开关", + "3": "单压力", + "4": "双压力" + } + }, + "name": "传感器组合", + "required": false + }, + { + "identifier": "ElectronicTMax", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电机保护温度", + "required": false + }, + { + "identifier": "ElectronicTMaxReset", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电机复位温度", + "required": false + }, + { + "identifier": "HandMode", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "手动模式挡位", + "required": false + }, + { + "identifier": "TempGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "温控挡位", + "required": false + }, + { + "identifier": "RatioGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "比例挡位", + "required": false + }, + { + "identifier": "SpeedGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "速度挡位", + "required": false + }, + { + "identifier": "PressureGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "压力挡位", + "required": false + }, + { + "identifier": "SceneMode", + "dataType": { + "type": "enum", + "specs": { + "0": "节能模式-自动挡", + "1": "温控模式-温控模式", + "2": "一键热水-恒速模式", + "3": "定时模式-恒压模式", + "4": "比例模式" + } + }, + "name": "回水器/循环泵-设置模式", + "required": false + }, + { + "identifier": "EnergyModeTime", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "节能模式运行时间", + "required": false + }, + { + "identifier": "WaterTime", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "水流开关设置", + "required": false + }, + { + "identifier": "HotWaterTime", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "一键热水运行时间", + "required": false + }, + { + "identifier": "TempSet", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "温控上下限设置", + "required": false + }, + { + "identifier": "CountDown", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "回水器倒计时", + "required": false + }, + { + "identifier": "Enabled", + "dataType": { + "type": "enum", + "specs": { + "0": "停止", + "1": "开启" + } + }, + "name": "实时运行状态", + "required": false + }, + { + "identifier": "TimeModeSet", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "定时模式时间设置", + "required": false + }, + { + "identifier": "McuVersion", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "Mcu版本号", + "required": false + } + ], + "outputData": [], + "name": "属性设置" + }, + { + "identifier": "get", + "inputData": [ + { + "identifier": "propertyName", + "dataType": { + "type": "text", + "specs": { + "length": "500" + } + }, + "name": "属性名", + "required": false + } + ], + "outputData": [ + { + "identifier": "WorkMode", + "dataType": { + "type": "enum", + "specs": { + "0": "自动", + "1": "手动", + "2": "自检1", + "3": "防锈", + "4": "防冻", + "5": "自检2", + "6": "温控" + } + }, + "name": "模式", + "required": false + }, + { + "identifier": "Pressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10", + "precision": "1" + } + }, + "name": "设置压力", + "required": false + }, + { + "identifier": "Switch", + "dataType": { + "type": "enum", + "specs": { + "85": "关闭", + "170": "开启" + } + }, + "name": "开关", + "required": false + }, + { + "identifier": "EmtyRunPressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10", + "precision": "1" + } + }, + "name": "缺水压力", + "required": false + }, + { + "identifier": "StartPressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10" + } + }, + "name": "开启压力", + "required": false + }, + { + "identifier": "WaterT", + "dataType": { + "type": "int32", + "specs": { + "min": "35", + "max": "100" + } + }, + "name": "水温保护", + "required": false + }, + { + "identifier": "WaterTReset", + "dataType": { + "type": "int32", + "specs": { + "min": "35", + "max": "100" + } + }, + "name": "水温复位", + "required": false + }, + { + "identifier": "ClearIceEn", + "dataType": { + "type": "enum", + "specs": { + "0": "关闭", + "1": "开启" + } + }, + "name": "防冻", + "required": false + }, + { + "identifier": "ErrorMsg", + "dataType": { + "type": "enum", + "specs": { + "0": "无", + "1": "过压", + "2": "欠压", + "3": "过流", + "4": "电机高温", + "5": "IPM高温", + "6": "堵转", + "7": "温升保护", + "8": "启动失败", + "9": "缺相", + "10": "无-", + "11": "软件过流", + "12": "缺水", + "13": "未激活", + "14": "传感器故障", + "15": "通信故障" + } + }, + "name": "故障信息", + "required": false + }, + { + "identifier": "Voltage", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "300" + } + }, + "name": "电压", + "required": false + }, + { + "identifier": "Electric", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电流", + "required": false + }, + { + "identifier": "Power", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "5000" + } + }, + "name": "功率", + "required": false + }, + { + "identifier": "Speed", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "10000" + } + }, + "name": "转速", + "required": false + }, + { + "identifier": "CurrentPressure1", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10" + } + }, + "name": "实时压力1", + "required": false + }, + { + "identifier": "CurrentPressure2", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10" + } + }, + "name": "实时压力2", + "required": false + }, + { + "identifier": "IpmTemperature", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "IPM温度", + "required": false + }, + { + "identifier": "MotorTemperature", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电机温度", + "required": false + }, + { + "identifier": "WaterTemperature", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "水温度", + "required": false + }, + { + "identifier": "McuStatus", + "dataType": { + "type": "enum", + "specs": { + "0": "APP", + "8": "BootLoader" + } + }, + "name": "MCU状态", + "required": false + }, + { + "identifier": "Scene", + "dataType": { + "type": "enum", + "specs": { + "0": "增压泵", + "1": "回水器", + "2": "循环泵" + } + }, + "name": "设备场景", + "required": false + }, + { + "identifier": "WarnInfo", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "警告信息", + "required": false + }, + { + "identifier": "ActiveTime", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "激活时间", + "required": false + }, + { + "identifier": "SensorMode", + "dataType": { + "type": "enum", + "specs": { + "0": "自动", + "1": "手动" + } + }, + "name": "传感器组合模式", + "required": false + }, + { + "identifier": "SensorGroup", + "dataType": { + "type": "enum", + "specs": { + "0": "无传感器", + "1": "水流开关-压力", + "2": "单水流开关", + "3": "单压力", + "4": "双压力" + } + }, + "name": "传感器组合", + "required": false + }, + { + "identifier": "ElectronicTMax", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电机保护温度", + "required": false + }, + { + "identifier": "ElectronicTMaxReset", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电机复位温度", + "required": false + }, + { + "identifier": "History", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "历史上报", + "required": false + }, + { + "identifier": "Model", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "设备型号", + "required": false + }, + { + "identifier": "HandMode", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "手动模式挡位", + "required": false + }, + { + "identifier": "TempGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "温控挡位", + "required": false + }, + { + "identifier": "RatioGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "比例挡位", + "required": false + }, + { + "identifier": "SpeedGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "速度挡位", + "required": false + }, + { + "identifier": "PressureGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "压力挡位", + "required": false + }, + { + "identifier": "SceneMode", + "dataType": { + "type": "enum", + "specs": { + "0": "节能模式-自动挡", + "1": "温控模式-温控模式", + "2": "一键热水-恒速模式", + "3": "定时模式-恒压模式", + "4": "比例模式" + } + }, + "name": "回水器/循环泵-设置模式", + "required": false + }, + { + "identifier": "EnergyModeTime", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "节能模式运行时间", + "required": false + }, + { + "identifier": "WaterTime", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "水流开关设置", + "required": false + }, + { + "identifier": "HotWaterTime", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "一键热水运行时间", + "required": false + }, + { + "identifier": "TempSet", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "温控上下限设置", + "required": false + }, + { + "identifier": "CountDown", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "回水器倒计时", + "required": false + }, + { + "identifier": "Enabled", + "dataType": { + "type": "enum", + "specs": { + "0": "停止", + "1": "开启" + } + }, + "name": "实时运行状态", + "required": false + }, + { + "identifier": "TimeModeSet", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "定时模式时间设置", + "required": false + }, + { + "identifier": "McuVersion", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "Mcu版本号", + "required": false + } + ], + "name": "属性获取" + } + ], + "events": [ + { + "identifier": "post", + "inputData": [], + "outputData": [ + { + "identifier": "WorkMode", + "dataType": { + "type": "enum", + "specs": { + "0": "自动", + "1": "手动", + "2": "自检1", + "3": "防锈", + "4": "防冻", + "5": "自检2", + "6": "温控" + } + }, + "name": "模式", + "required": false + }, + { + "identifier": "Pressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10", + "precision": "1" + } + }, + "name": "设置压力", + "required": false + }, + { + "identifier": "Switch", + "dataType": { + "type": "enum", + "specs": { + "85": "关闭", + "170": "开启" + } + }, + "name": "开关", + "required": false + }, + { + "identifier": "EmtyRunPressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10", + "precision": "1" + } + }, + "name": "缺水压力", + "required": false + }, + { + "identifier": "StartPressure", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10" + } + }, + "name": "开启压力", + "required": false + }, + { + "identifier": "WaterT", + "dataType": { + "type": "int32", + "specs": { + "min": "35", + "max": "100" + } + }, + "name": "水温保护", + "required": false + }, + { + "identifier": "WaterTReset", + "dataType": { + "type": "int32", + "specs": { + "min": "35", + "max": "100" + } + }, + "name": "水温复位", + "required": false + }, + { + "identifier": "ClearIceEn", + "dataType": { + "type": "enum", + "specs": { + "0": "关闭", + "1": "开启" + } + }, + "name": "防冻", + "required": false + }, + { + "identifier": "ErrorMsg", + "dataType": { + "type": "enum", + "specs": { + "0": "无", + "1": "过压", + "2": "欠压", + "3": "过流", + "4": "电机高温", + "5": "IPM高温", + "6": "堵转", + "7": "温升保护", + "8": "启动失败", + "9": "缺相", + "10": "无-", + "11": "软件过流", + "12": "缺水", + "13": "未激活", + "14": "传感器故障", + "15": "通信故障" + } + }, + "name": "故障信息", + "required": false + }, + { + "identifier": "Voltage", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "300" + } + }, + "name": "电压", + "required": false + }, + { + "identifier": "Electric", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电流", + "required": false + }, + { + "identifier": "Power", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "5000" + } + }, + "name": "功率", + "required": false + }, + { + "identifier": "Speed", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "10000" + } + }, + "name": "转速", + "required": false + }, + { + "identifier": "CurrentPressure1", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10" + } + }, + "name": "实时压力1", + "required": false + }, + { + "identifier": "CurrentPressure2", + "dataType": { + "type": "float", + "specs": { + "min": "0", + "max": "10" + } + }, + "name": "实时压力2", + "required": false + }, + { + "identifier": "IpmTemperature", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "IPM温度", + "required": false + }, + { + "identifier": "MotorTemperature", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电机温度", + "required": false + }, + { + "identifier": "WaterTemperature", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "水温度", + "required": false + }, + { + "identifier": "McuStatus", + "dataType": { + "type": "enum", + "specs": { + "0": "APP", + "8": "BootLoader" + } + }, + "name": "MCU状态", + "required": false + }, + { + "identifier": "Scene", + "dataType": { + "type": "enum", + "specs": { + "0": "增压泵", + "1": "回水器", + "2": "循环泵" + } + }, + "name": "设备场景", + "required": false + }, + { + "identifier": "WarnInfo", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "警告信息", + "required": false + }, + { + "identifier": "ActiveTime", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "激活时间", + "required": false + }, + { + "identifier": "SensorMode", + "dataType": { + "type": "enum", + "specs": { + "0": "自动", + "1": "手动" + } + }, + "name": "传感器组合模式", + "required": false + }, + { + "identifier": "SensorGroup", + "dataType": { + "type": "enum", + "specs": { + "0": "无传感器", + "1": "水流开关-压力", + "2": "单水流开关", + "3": "单压力", + "4": "双压力" + } + }, + "name": "传感器组合", + "required": false + }, + { + "identifier": "ElectronicTMax", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电机保护温度", + "required": false + }, + { + "identifier": "ElectronicTMaxReset", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "100" + } + }, + "name": "电机复位温度", + "required": false + }, + { + "identifier": "History", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "历史上报", + "required": false + }, + { + "identifier": "Model", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "设备型号", + "required": false + }, + { + "identifier": "HandMode", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "手动模式挡位", + "required": false + }, + { + "identifier": "TempGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "温控挡位", + "required": false + }, + { + "identifier": "RatioGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "比例挡位", + "required": false + }, + { + "identifier": "SpeedGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "速度挡位", + "required": false + }, + { + "identifier": "PressureGear", + "dataType": { + "type": "int32", + "specs": { + "min": "1", + "max": "5" + } + }, + "name": "压力挡位", + "required": false + }, + { + "identifier": "SceneMode", + "dataType": { + "type": "enum", + "specs": { + "0": "节能模式-自动挡", + "1": "温控模式-温控模式", + "2": "一键热水-恒速模式", + "3": "定时模式-恒压模式", + "4": "比例模式" + } + }, + "name": "回水器/循环泵-设置模式", + "required": false + }, + { + "identifier": "EnergyModeTime", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "节能模式运行时间", + "required": false + }, + { + "identifier": "WaterTime", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "水流开关设置", + "required": false + }, + { + "identifier": "HotWaterTime", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "一键热水运行时间", + "required": false + }, + { + "identifier": "TempSet", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "温控上下限设置", + "required": false + }, + { + "identifier": "CountDown", + "dataType": { + "type": "int32", + "specs": { + "min": "0", + "max": "65532" + } + }, + "name": "回水器倒计时", + "required": false + }, + { + "identifier": "Enabled", + "dataType": { + "type": "enum", + "specs": { + "0": "停止", + "1": "开启" + } + }, + "name": "实时运行状态", + "required": false + }, + { + "identifier": "TimeModeSet", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "定时模式时间设置", + "required": false + }, + { + "identifier": "McuVersion", + "dataType": { + "type": "text", + "specs": { + "length": "255" + } + }, + "name": "Mcu版本号", + "required": false + } + ], + "name": "属性上报" + } + ] + } + } +] \ No newline at end of file diff --git a/data/init/userInfo.json b/data/init/userInfo.json new file mode 100644 index 0000000..dad63bd --- /dev/null +++ b/data/init/userInfo.json @@ -0,0 +1,161 @@ +[ { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321471, + "updateBy" : null, + "updateTime" : 1708254321471, + "tenantId" : 0, + "id" : 432323, + "uid" : "18126045687", + "secret" : "483752384B473759556E685768796B6F644E48634F76486C51646A41576B545A2B396C34474244414F334F517674507547437A72627A7154302B724441734C5A", + "nickName" : "song", + "gender" : null, + "avatarUrl" : null, + "email" : null, + "address" : null, + "currHomeId" : null, + "type" : 1, + "roles" : [ ], + "permissions" : [ ], + "usePlatforms" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321468, + "updateBy" : null, + "updateTime" : 1708254321468, + "tenantId" : 0, + "id" : 3454543, + "uid" : "tm1", + "secret" : null, + "nickName" : "天猫精灵1", + "gender" : null, + "avatarUrl" : null, + "email" : null, + "address" : null, + "currHomeId" : null, + "type" : 1, + "roles" : [ ], + "permissions" : [ ], + "usePlatforms" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321451, + "updateBy" : null, + "updateTime" : 1708254321451, + "tenantId" : 0, + "id" : 13123123, + "uid" : "iotkit", + "secret" : "6E49354D37437030564370666E48486150524B3134743258735059354D75324F6532594478654C47767535614C6C6E767139625170774E576477785A34513369", + "nickName" : "管理员", + "gender" : null, + "avatarUrl" : null, + "email" : null, + "address" : null, + "currHomeId" : null, + "type" : 0, + "roles" : [ ], + "permissions" : [ ], + "usePlatforms" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321458, + "updateBy" : null, + "updateTime" : 1708254321458, + "tenantId" : 0, + "id" : 23423423, + "uid" : "tm3", + "secret" : null, + "nickName" : "天猫精灵test3", + "gender" : null, + "avatarUrl" : null, + "email" : null, + "address" : null, + "currHomeId" : null, + "type" : 1, + "roles" : [ ], + "permissions" : [ ], + "usePlatforms" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321463, + "updateBy" : null, + "updateTime" : 1708254321463, + "tenantId" : 0, + "id" : 45234345, + "uid" : "du1", + "secret" : "483752384B473759556E685768796B6F644E48634F76486C51646A41576B545A2B396C34474244414F334F517674507547437A72627A7154302B724441734C5A", + "nickName" : "小度接入1", + "gender" : null, + "avatarUrl" : null, + "email" : null, + "address" : null, + "currHomeId" : null, + "type" : 1, + "roles" : [ ], + "permissions" : [ ], + "usePlatforms" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321454, + "updateBy" : null, + "updateTime" : 1708254321454, + "tenantId" : 0, + "id" : 12312312312, + "uid" : "du2", + "secret" : null, + "nickName" : "小度接入2", + "gender" : null, + "avatarUrl" : null, + "email" : null, + "address" : null, + "currHomeId" : null, + "type" : 1, + "roles" : [ ], + "permissions" : [ ], + "usePlatforms" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321446, + "updateBy" : null, + "updateTime" : 1708254321446, + "tenantId" : 0, + "id" : 141231312312, + "uid" : "guest1", + "secret" : "48774861346645676F51324A4D6E6639306E6474437741634C4333746C4575666C316F76503455542B5836763065315A2F676244695056557356704D49513569", + "nickName" : "演示账户", + "gender" : null, + "avatarUrl" : null, + "email" : null, + "address" : null, + "currHomeId" : null, + "type" : 0, + "roles" : [ ], + "permissions" : [ ], + "usePlatforms" : [ ] +}, { + "createDept" : null, + "createBy" : null, + "createTime" : 1708254321434, + "updateBy" : null, + "updateTime" : 1708254321434, + "tenantId" : 0, + "id" : 13123123123213, + "uid" : "13480802157", + "secret" : "483752384B473759556E685768796B6F644E48634F76486C51646A41576B545A2B396C34474244414F334F78574F4778613764564338594E666770595A376177", + "nickName" : "song2", + "gender" : null, + "avatarUrl" : null, + "email" : null, + "address" : null, + "currHomeId" : null, + "type" : 1, + "roles" : [ ], + "permissions" : [ ], + "usePlatforms" : [ ] +} ] \ No newline at end of file diff --git a/data/init/virtualDevice.json b/data/init/virtualDevice.json new file mode 100644 index 0000000..99d638f --- /dev/null +++ b/data/init/virtualDevice.json @@ -0,0 +1,73 @@ +[ { + "id" : "6293953092084e2df303ba3e", + "uid" : "1", + "name" : "三路开关", + "productKey" : "eDhXKwEzwFybM5R7", + "devices" : [ ], + "type" : "thingModel", + "script" : "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n return [];\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n\t \"rssi\":127-parseInt(Math.random()*127),\n\t \"powerstate_1\":Math.random()>0.5?1:0,\n\t \"powerstate_2\":Math.random()>0.5?1:0,\n\t \"powerstate_3\":Math.random()>0.5?1:0\n }\n }\n}", + "trigger" : "random", + "triggerExpression" : "second", + "state" : "running", + "createAt" : 1653839152090 +}, { + "id" : "629391ae92084e2df303ba3d", + "uid" : "1", + "name" : "温湿度传感器", + "productKey" : "6kYp6jszrDns2yh4", + "devices" : [ ], + "type" : "thingModel", + "script" : "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n return [];\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n \"humidity\":parseInt(Math.random()*100),\n\t \"temperature\":parseInt(Math.random()*500)-38\n }\n }\n}", + "trigger" : "random", + "triggerExpression" : "second", + "state" : "running", + "createAt" : 1653838254989 +}, { + "id" : "629390f492084e2df303ba3c", + "uid" : "1", + "name" : "调光灯", + "productKey" : "xpsYHExTKPFaQMS7", + "devices" : [ ], + "type" : "thingModel", + "script" : "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n return [];\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n \"brightness\":parseInt(Math.random()*100),\n\t \"powerstate\":Math.random()>0.5?1:0\n }\n }\n}", + "trigger" : "random", + "triggerExpression" : "second", + "state" : "running", + "createAt" : 1653838068860 +}, { + "id" : "62925cb72002b44c15caeb1c", + "uid" : "1", + "name" : "虚拟门磁1", + "productKey" : "PN3EDmkBZDD8whDd", + "devices" : [ ], + "type" : "thingModel", + "script" : "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n return [];\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n \"rssi\":127-parseInt(Math.random()*127),\n \"power\":parseInt(Math.random()*100),\n\t \"doorStatus\":Math.random()>0.5?1:0\n }\n }\n}", + "trigger" : "random", + "triggerExpression" : "minute", + "state" : "running", + "createAt" : 1653759159567 +}, { + "id" : "628fd800fba69e633a972e12", + "uid" : "1", + "name" : "开关1", + "productKey" : "Rf4QSjbm65X45753", + "devices" : [ ], + "type" : "thingModel", + "script" : "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n return [{\n \"productKey\":service.productKey,\n \"deviceName\":service.deviceName,\n \"mid\":service.mid,\n \"type\":\"service\",\n \"identifier\":\"reboot_reply\",\n \"data\":{},\n \"code\":0\n },{\n \"mid\":getRequestId(),\n \"productKey\":service.productKey, \n \"deviceName\":service.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\n \"time\":new Date().getTime(),\n \"data\":{\n \"volt\":parseInt(Math.random()*100),\n\t \"powerstate\":Math.random()>0.5?1:0\n }\n }]\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n \"volt\":parseInt(Math.random()*100)\n }\n }\n}", + "trigger" : "cron", + "triggerExpression" : "0 * * * * ? ", + "state" : "running", + "createAt" : 1653594112764 +}, { + "id" : "628fa6bc1b735b73cb260042", + "uid" : "1", + "name" : "虚拟插座12", + "productKey" : "cGCrkK7Ex4FESAwe", + "devices" : [ ], + "type" : "thingModel", + "script" : "\nvar mid=1000;\n\nfunction getMid(){\n mid++;\n if(mid>9999){\n\tmid=1;\n }\n return mid+\"\";\n}\n\nfunction getRequestId(){\n return \"RID\"+new Date().getTime()+getMid();\n}\n\n\nthis.receive=function(service,device){\n var identifier=service.identifier;\n var result= [{\n \"productKey\":service.productKey,\n \"deviceName\":service.deviceName,\n \"mid\":service.mid,\n \"type\":\"service\",\n \"identifier\":identifier+\"_reply\",\n \"data\":{},\n \"code\":0\n }]\n \n if(service.type==\"property\" && (identifier==\"get\" || identifier==\"set\")){\n\tresult.push({\n\t \"mid\":getRequestId(),\n\t \"productKey\":device.productKey, \n\t \"deviceName\":device.deviceName,\n\t \"type\":\"property\",\n\t \"identifier\":\"report\",\n\t \"occurred\":new Date().getTime(),\n\t \"time\":new Date().getTime(),\n\t \"data\":service.params\n\t});\n }\n \n return result;\n}\n\nthis.report=function(device){\n return {\n \"mid\":getRequestId(),\n \"productKey\":device.productKey, \n \"deviceName\":device.deviceName,\n \"type\":\"property\",\n \"identifier\":\"report\",\n \"occurred\":new Date().getTime(),\t//时间戳,设备上的事件或数据产生的本地时间\n \"time\":new Date().getTime(),\t\t//时间戳,消息上报时间\n \"data\":{\n \"rssi\":127-parseInt(Math.random()*127),\n\t \"powerstate\":Math.random()>0.5?1:0\n }\n }\n}", + "trigger" : "random", + "triggerExpression" : "second", + "state" : "running", + "createAt" : 1653581500076 +} ] \ No newline at end of file diff --git a/data/nginx.conf b/data/nginx.conf new file mode 100644 index 0000000..7b8b908 --- /dev/null +++ b/data/nginx.conf @@ -0,0 +1,50 @@ +user root; +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /run/nginx.pid; + +# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. +include /usr/share/nginx/modules/*.conf; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 4096; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server + { + listen 8082; + server_name localhost; + client_max_body_size 100m; + index index.html; + root /usr/share/nginx/html; + + location /prod-api/ + { + rewrite /api(.*) $1 break; + proxy_pass http://127.0.0.1:8086/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header REMOTE-HOST $remote_addr; + proxy_http_version 1.1; + } + } + +} + diff --git a/doc/.keep b/doc/.keep new file mode 100644 index 0000000..e69de29 diff --git a/doc/WechatIMG539.png b/doc/WechatIMG539.png new file mode 100644 index 0000000..6164fa3 Binary files /dev/null and b/doc/WechatIMG539.png differ diff --git a/doc/image-20230702173737805.png b/doc/image-20230702173737805.png new file mode 100644 index 0000000..9698059 Binary files /dev/null and b/doc/image-20230702173737805.png differ diff --git a/doc/image-20230702173852342.png b/doc/image-20230702173852342.png new file mode 100644 index 0000000..c93dde2 Binary files /dev/null and b/doc/image-20230702173852342.png differ diff --git a/doc/image-20230702174747305.png b/doc/image-20230702174747305.png new file mode 100644 index 0000000..5dd4a82 Binary files /dev/null and b/doc/image-20230702174747305.png differ diff --git a/doc/image.png b/doc/image.png new file mode 100644 index 0000000..d05e11e Binary files /dev/null and b/doc/image.png differ diff --git a/doc/ma.png b/doc/ma.png new file mode 100644 index 0000000..6a4ea8e Binary files /dev/null and b/doc/ma.png differ diff --git a/doc/ma2.png b/doc/ma2.png new file mode 100644 index 0000000..4fce765 Binary files /dev/null and b/doc/ma2.png differ diff --git a/doc/screenshot.jpg b/doc/screenshot.jpg new file mode 100644 index 0000000..de02089 Binary files /dev/null and b/doc/screenshot.jpg differ diff --git a/doc/screenshot.png b/doc/screenshot.png new file mode 100644 index 0000000..241224b Binary files /dev/null and b/doc/screenshot.png differ diff --git a/doc/集群.png b/doc/集群.png new file mode 100644 index 0000000..39dd516 Binary files /dev/null and b/doc/集群.png differ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0e9e77e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,72 @@ +version: "3.4" + +services: + mysql: + container_name: iot-mysql + image: mysql:8 + restart: unless-stopped + tty: true + ports: + - "3306:3306" + environment: + MYSQL_DATABASE: ${MYSQL_DATABASE:-iotkit} + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-123456} + volumes: + - mysql:/var/lib/mysql/ + + redis: + container_name: iot-redis + image: redis:6-alpine + restart: unless-stopped + ports: + - "6379:6379" + volumes: + - redis:/data + + td-engine: + container_name: iot-td-engine + image: taosdata/tdengine:latest + restart: unless-stopped + volumes: + - iot-td-engine:/var/lib/tdengine/ + + server: + container_name: iot-server + build: + context: . + image: iot-server + restart: unless-stopped + ports: + - "8089:8086" + - "8088:8082" + environment: + # https://github.com/polovyivan/docker-pass-configs-to-container + SPRING_PROFILES_ACTIVE: mysql + SPRING_DATASOURCE_URL: ${MASTER_DATASOURCE_URL:-jdbc:mysql://iot-mysql:3306/iotkit?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true} + SPRING_DATASOURCE_USERNAME: ${MASTER_DATASOURCE_USERNAME:-root} + SPRING_DATASOURCE_PASSWORD: ${MASTER_DATASOURCE_PASSWORD:-123456} + SPRING_REDIS_HOST: ${REDIS_HOST:-iot-redis} + SPRING_REDIS_PORT: 6379 + SPRING_TD_DATASOURCE_URL: jdbc:TAOS-RS://iot-td-engine:6041/iotkit?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8 + SPRING_TD_DATASOURCE_USERNAME: root + SPRING_TD_DATASOURCE_PASSWORD: taosdata + JAVA_OPTS: + ${JAVA_OPTS:- + -Xms512m + -Xmx512m + -Djava.security.egd=file:/dev/./urandom + } + volumes: + - ./data/dist:/usr/share/nginx/html + depends_on: + - redis + - mysql + - td-engine + +volumes: + mysql: + driver: local + redis: + driver: local + iot-td-engine: + driver: local diff --git a/docker.env b/docker.env new file mode 100644 index 0000000..521e860 --- /dev/null +++ b/docker.env @@ -0,0 +1,19 @@ +## mysql +MYSQL_DATABASE=iotkit +MYSQL_ROOT_PASSWORD=123456 + +## server +JAVA_OPTS=-Xms512m -Xmx512m -Djava.security.egd=file:/dev/./urandom -DdisabledEmbeddedRedis=true + +MASTER_DATASOURCE_URL=jdbc:mysql://iot-mysql:3306/${MYSQL_DATABASE}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true +MASTER_DATASOURCE_USERNAME=root +MASTER_DATASOURCE_PASSWORD=${MYSQL_ROOT_PASSWORD} +SLAVE_DATASOURCE_URL=${MASTER_DATASOURCE_URL} +SLAVE_DATASOURCE_USERNAME=${MASTER_DATASOURCE_USERNAME} +SLAVE_DATASOURCE_PASSWORD=${MASTER_DATASOURCE_PASSWORD} +REDIS_HOST=iot-redis + +## admin +NODE_ENV=production +PUBLIC_PATH=/ +VUE_APP_TITLE=iot管理系统 diff --git a/git规范.md b/git规范.md new file mode 100644 index 0000000..0bab21e --- /dev/null +++ b/git规范.md @@ -0,0 +1,77 @@ +# **提交规范** + +## **例子** + +``` +feat(miniprogram):新增自开奖页面 + +新增活动页面,但是产品还有需求遗漏,待完善 +- 新增内容1 +- 新增内容2 +``` + +``` +fix(miniprogram):活动页面设置渠道后,自动添加渠道文字类型判断错误 +``` + + + +## **Commit message 格式** + +为了方便使用,我们避免了过于复杂的规定,格式较为简单且不限制中英文: + + + +``` +(): +// 空一行 + +// 空一行 + +// 注意冒号 : 后有空格 +// 如 feat(miniprogram): 增加了小程序模板消息相关功能 +``` + +大致分为两个个部分: + +1. 标题行: 包括` (): ` +2. 主题内容: 描述了为什么修改,做了什么修改,以及开发思路等 + +| | 说明 | 必填 | +| ------- | ---------------------- | ------ | +| type | 修改类型 | 必填 | +| scope | 作用范围 | 非必填 | +| subject | 对commit的简单描述 | 必填 | +| body | 本次 commit 的详细描述 | 非必填 | + +### **1.type** + +``` +feat:新功能(feature) +fix:修补bug +docs:文档(documentation) +style: 格式(不影响代码运行的变动) +refactor:重构(即不是新增功能,也不是修改bug的代码变动) +test:增加测试 +chore:构建过程或辅助工具的变动 +``` + +如果type为feat和fix,则该 commit 将肯定出现在 Change log 之中。其他情况(docs、chore、style、refactor、test)由你决定,要不要放入 Change log,建议是不要。 + +### **2.scope** + +scope用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,视项目不同而不同。 + +### **3. subject** + +subject是 commit 目的的简短描述,不超过50个字符。 + +``` +以动词开头,使用第一人称现在时,比如change,而不是changed或changes +第一个字母小写 +结尾不加句号(.) +``` + +### **4. body** + +Body 部分是对本次 commit 的详细描述,可以分成多行。描述为什么修改, 做了什么样的修改, 以及开发的思路等等 \ No newline at end of file diff --git a/iot-dao/iot-data-model/pom.xml b/iot-dao/iot-data-model/pom.xml new file mode 100644 index 0000000..27f0544 --- /dev/null +++ b/iot-dao/iot-data-model/pom.xml @@ -0,0 +1,56 @@ + + + + iot-dao + cc.iotkit + 0.5.3 + + 0.5.3 + 4.0.0 + + iot-data-model + + + + + cc.iotkit + iot-common-core + + + + + + org.projectlombok + lombok + provided + + + + com.fasterxml.jackson.core + jackson-annotations + + + + org.hibernate + hibernate-core + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + + + \ No newline at end of file diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/BaseModel.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/BaseModel.java new file mode 100644 index 0000000..0ee51da --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/BaseModel.java @@ -0,0 +1,70 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model; + +import cc.iotkit.common.utils.MapstructUtils; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * Entity基类 + * + * @author Lion Li + */ + +@Data +public class BaseModel implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 创建部门 + */ + private Long createDept; + + /** + * 创建者 + */ + private Long createBy; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新者 + */ + private Long updateBy; + + /** + * 更新时间 + */ + private Date updateTime; + + public T to(Class tClass) { + return MapstructUtils.convert(this, tClass); + } +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/FeedBackEvaluation/FeedBackEvaluationDO.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/FeedBackEvaluation/FeedBackEvaluationDO.java new file mode 100644 index 0000000..e4ba057 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/FeedBackEvaluation/FeedBackEvaluationDO.java @@ -0,0 +1,73 @@ +package cc.iotkit.model.FeedBackEvaluation; + + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import com.sun.xml.bind.v2.TODO; +import lombok.*; + +import java.lang.annotation.Annotation; + +// 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@EqualsAndHashCode(callSuper = true) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class FeedBackEvaluationDO extends TenantModel implements Id { + private static final long serialVersionUID = 1L; + /** + * ID + */ + + private Long id; + /** + * 内容 + */ + private String content; + /** + * 问题截图 + */ + private String problemScreenshot; + /** + * 消息 + */ + private String message; + /** + * 客户姓名 + */ + private String customerName; + /** + * 评价类型1意见反馈,2用户评价,3师傅评价 + * + * 枚举 {@link TODO evaluation_type 对应的类} + */ + private String evaluationType; + /** + * 服务满意度 + */ + private String serviceSatisfaction; + /** + * 设备ID + */ + private String deviceId; + /** + * 工单ID + */ + private String worderId; + /** + * 问题是否解决1解决2未解决 + * + * 枚举 {@link TODO is_solve 对应的类} + */ + private String isSolve; + /** + * 客户电话 + */ + private String customerPhone; + /** + *租户id + */ + private Long tenantId; + +} \ No newline at end of file diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/Id.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/Id.java new file mode 100644 index 0000000..8665212 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/Id.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model; + +public interface Id { + + T getId(); + + void setId(T id); + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/InvokeResult.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/InvokeResult.java new file mode 100644 index 0000000..07b170e --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/InvokeResult.java @@ -0,0 +1,42 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class InvokeResult { + + private String requestId; + + private long time; + + public InvokeResult(String requestId) { + this.requestId = requestId; + this.time = System.currentTimeMillis(); + } +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/OauthClient.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/OauthClient.java new file mode 100644 index 0000000..3169379 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/OauthClient.java @@ -0,0 +1,46 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model; + +import lombok.Data; + +/** + * oauth2的client + */ +@Data +public class OauthClient implements Id { + + private String id; + + private String clientId; + + private String name; + + private String clientSecret; + + private String allowUrl; + + private Long createAt; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/Owned.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/Owned.java new file mode 100644 index 0000000..baa9ae1 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/Owned.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model; + +public interface Owned extends Id { + + String getUid(); + + void setUid(String uid); + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/TenantModel.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/TenantModel.java new file mode 100644 index 0000000..b2b82ee --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/TenantModel.java @@ -0,0 +1,43 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 租户基类 + * + * @author Michelle.Chung + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class TenantModel extends BaseModel { + + /** + * 租户编号 + */ + private Long tenantId; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/UserInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/UserInfo.java new file mode 100644 index 0000000..8e1ef86 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/UserInfo.java @@ -0,0 +1,108 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class UserInfo extends TenantModel implements Id, Serializable { + + public static final int USER_TYPE_PLATFORM = 0; + public static final int USER_TYPE_CLIENT = 1; + + private Long id; + + /** + * 用户账号 + */ + private String uid; + + /** + * 密钥(密码加密后的内容) + */ + private String secret; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 性别 0-未知 1-male,2-female + */ + private Integer gender; + + /** + * 头像地址 + */ + private String avatarUrl; + + private String email; + + private String address; + private String site; + + /** + * 当前家庭Id + */ + private String currHomeId; + + /** + * 用户类型 + * 0:平台用户 + * 1:终端用户 + */ + private Integer type; + /** + * 设备数量 + */ + private Long deviceCount; + /** + * 角色 + */ + private List roles = new ArrayList<>(); + + /** + * 权限 + */ + private List permissions = new ArrayList<>(); + + /** + * 用户使用的平台 + * 见:Constants.THIRD_PLATFORM + */ + private List usePlatforms = new ArrayList<>(); + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertConfig.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertConfig.java new file mode 100644 index 0000000..b8b0ad7 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertConfig.java @@ -0,0 +1,83 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.alert; + +import cc.iotkit.model.Owned; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 告警配置 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AlertConfig extends TenantModel implements Owned { + + private Long id; + + /** + * 配置所属用户 + */ + private String uid; + + /** + * 告警名称 + */ + private String name; + + /** + * 告警严重度 + */ + private String level; + + /** + * 关联规则引擎ID + */ + private String ruleInfoId; + + /** + * 关联消息转发模板ID + */ + private Long messageTemplateId; + + /** + * 描述 + */ + private String description; + + /** + * 是否启用 + */ + private Boolean enable; + + /** + * 创建时间 + */ + private Long createAt; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertRecord.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertRecord.java new file mode 100644 index 0000000..420b9e0 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertRecord.java @@ -0,0 +1,85 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.alert; + +import cc.iotkit.model.Owned; +import cc.iotkit.model.TenantModel; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; +import java.util.Date; +import java.util.Map; + +/** + * 告警配置 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AlertRecord extends TenantModel implements Owned { + + private Long id; + private Map params; + /** + * 配置所属用户 + */ + private String uid; + + /** + * 告警名称 + */ + private String name; + + /** + * 告警严重度(1-5) + */ + private String level; + + /** + * 告警时间 + */ + /* @JsonFormat(timezone = "Asia/Shanghai",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")*/ + private Long alertTime; + private String alertTimeStats; + /** + * 告警详情 + */ + private String details; + + /** + * 是否已读 + */ + private Boolean readFlg; + /* @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + public Date getAlertTime() { + return new Date(this.alertTime); + }*/ + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceConfig.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceConfig.java new file mode 100644 index 0000000..d4e87bf --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceConfig.java @@ -0,0 +1,58 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.device; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 设备配置 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DeviceConfig extends TenantModel implements Id { + + private String id; + + private String deviceId; + + /** + * 产品key + */ + private String productKey; + + private String deviceName; + + /** + * 设备配置json内容 + */ + private String config; + + private Long createAt; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceGroup.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceGroup.java new file mode 100644 index 0000000..96b97ac --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceGroup.java @@ -0,0 +1,65 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.device; + +import cc.iotkit.model.Owned; +import cc.iotkit.model.TenantModel; +import lombok.Data; + +/** + * 设备分组 + */ +@Data +public class DeviceGroup extends TenantModel implements Owned { + + /** + * 分组id + */ + private String id; + + /** + * 分组名称 + */ + private String name; + + /** + * 所属用户 + */ + private String uid; + + /** + * 分组说明 + */ + private String remark; + + /** + * 设备数量 + */ + private int deviceQty; + + /** + * 创建时间 + */ + private long createAt; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceInfo.java new file mode 100644 index 0000000..81f7d33 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceInfo.java @@ -0,0 +1,151 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.device; + +import cc.iotkit.model.Owned; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DeviceInfo extends TenantModel implements Owned { + + private String id; + + private String deviceId; + + private Long deptAreaId; + + /** + * 产品key + */ + private String productKey; + + private String deviceName; + + /** + * 设备型号 + */ + private String model; + + /** + * 设备密钥 + */ + private String secret; + + private String parentId; + + /** + * 所属平台用户ID + */ + private String uid; + + /** + * 关联子用户ID列表 + */ + private List subUid = new ArrayList<>(); + + /** + * 设备定位对象 + */ + private Locate locate = new Locate(); + + /** + * 设备在离线状态 + */ + private State state = new State(); + + /** + * 设备属性 + */ + private Map property = new HashMap<>(); + + /** + * 设备标签 + */ + private Map tag = new HashMap<>(); + + /** + * 设备所属分组 + */ + private Map group = new HashMap<>(); + + private Long createAt; + + public boolean isOnline() { + return state != null && state.isOnline(); + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class Locate { + + private String longitude; + + private String latitude; + + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + @Builder + public static class State { + + private boolean online; + + private Long onlineTime; + + private Long offlineTime; + + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class Tag { + private String id; + private String name; + private String value; + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class Group { + private String id; + private String name; + } + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/VirtualDevice.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/VirtualDevice.java new file mode 100644 index 0000000..250dba8 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/VirtualDevice.java @@ -0,0 +1,121 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.device; + +import cc.iotkit.model.Owned; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +/** + * 虚拟设备 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class VirtualDevice extends TenantModel implements Owned { + + public static final String STATE_STOPPED = "stopped"; + public static final String STATE_RUNNING = "running"; + + /** + * 虚拟类型-基于物模型模拟 + */ + public static final String TYPE_THING_MODEL = "thingModel"; + /** + * 虚拟类型-基于设备协议模拟 + */ + public static final String TYPE_PROTOCOL = "protocol"; + + /** + * 触发执行-无(手动) + */ + public static final String TRIGGER_NONE = "none"; + /** + * 触发执行-定时执行 + */ + public static final String TRIGGER_CRON = "cron"; + /** + * 触发执行-随机执行 + */ + public static final String TRIGGER_RANDOM = "random"; + + private String id; + + /** + * 所属用户 + */ + private String uid; + + /** + * 虚拟设备名称 + */ + private String name; + + /** + * 产品key + */ + private String productKey; + + /** + * 虚拟的目标设备列表 + */ + private List devices = new ArrayList<>(); + + /** + * 虚拟类型 + */ + private String type; + + /** + * 设备行为脚本 + */ + private String script; + + /** + * 触发方式执行方式 + */ + private String trigger; + + /** + * 触发表达式 + */ + private String triggerExpression; + + /** + * 运行状态 + */ + private String state; + + /** + * 创建时间 + */ + private Long createAt; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/VirtualDeviceLog.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/VirtualDeviceLog.java new file mode 100644 index 0000000..56a56c2 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/VirtualDeviceLog.java @@ -0,0 +1,66 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.device; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + + +/** + * 虚拟设备日志 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class VirtualDeviceLog { + + private String id; + + /** + * 虚拟设备id + */ + private String virtualDeviceId; + + /** + * 虚拟设备名称 + */ + private String virtualDeviceName; + + /** + * 关联设备数量 + */ + private int deviceTotal; + + /** + * 虚拟设备执行结果 + */ + private String result; + + /** + * 创建时间 + */ + private Long logAt = System.currentTimeMillis(); +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/message/DeviceProperty.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/message/DeviceProperty.java new file mode 100644 index 0000000..2b6e5d5 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/message/DeviceProperty.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.device.message; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class DeviceProperty { + + private String id; + + private String deviceId; + + private String name; + + private Object value; + + private Long time; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/message/DevicePropertyCache.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/message/DevicePropertyCache.java new file mode 100644 index 0000000..5ea88d6 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/message/DevicePropertyCache.java @@ -0,0 +1,52 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.device.message; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class DevicePropertyCache { + + + /** + * 属性值 + */ + private Object value; + + /** + * 属性值时间: 设备上报时间 + */ + private Long occurred; + + + public Map toMap() { + return Map.of("value", value, "occurred", occurred); + } + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/iccid/DIccidRecordDO.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/iccid/DIccidRecordDO.java new file mode 100644 index 0000000..5fd89e7 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/iccid/DIccidRecordDO.java @@ -0,0 +1,84 @@ +package cc.iotkit.model.iccid; + + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.TenantModel; +import cc.iotkit.model.notify.Channel; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.*; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.*; +import java.io.Serializable; +import java.time.LocalDateTime; + +// 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@EqualsAndHashCode(callSuper = true) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DIccidRecordDO extends TenantModel implements cc.iotkit.model.Id, Serializable { + private static final long serialVersionUID = 1L; + /** + * 主键 + */ + //@TableId(type = IdType.AUTO) + + private Long id; + /** + * 厂商编号|合作商编号 + */ + private String userCode; + /** + * 物联网卡号 + */ + private String iccid; + /** + * 物联网卡运营商 + */ + private Integer simType; + /** + * 发货日期 + */ + private String dateline; + /** + * 状态(0,已授权,1未授权,2未支付) + */ + private Integer state; + /** + * 订单id + */ + private String orderId; + /** + * 授权码 + */ + private String authorizationCode; + /** + * 物联网卡来源0-其他 1-官方 + */ + private Integer source; + /** + * 厂商名称|合作商名称 + */ + private String user; + /** + * imei + */ + private String imei; + + private Integer validDays; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private LocalDateTime expirationTime; + /** + *租户id + */ + private Long tenantId; + +} \ No newline at end of file diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/modbus/ModbusInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/modbus/ModbusInfo.java new file mode 100644 index 0000000..21ec208 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/modbus/ModbusInfo.java @@ -0,0 +1,63 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.model.modbus; + +import cc.iotkit.model.Owned; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @Description: modbus信息 + * @Author: ZOUZDC + * @Date: 2024/4/28 22:49 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ModbusInfo extends TenantModel implements Owned, Serializable { + + private Long id; + + /** + * 配置所属用户 + */ + private String uid; + + /** + * 产品名称 + */ + private String name; + + private String productKey; + + /** + * 说明 + */ + private String remark; + + /** + * 创建时间 + */ + private Long createAt; + + /** + * 更新时间 + */ + private Long updateAt; + + + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/modbus/ModbusThingModel.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/modbus/ModbusThingModel.java new file mode 100644 index 0000000..3dcfd60 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/modbus/ModbusThingModel.java @@ -0,0 +1,186 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.model.modbus; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import cc.iotkit.model.product.ThingModel; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.*; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @Description: modbus点表物模型 + * @Author: ZOUZDC + * @Date: 2024/4/28 22:52 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ModbusThingModel extends TenantModel implements Id, Serializable { + private static final long serialVersionUID = 1L; + + private Long id; + + private String productKey; + + private ModbusThingModel.Model model; + + private Long updateAt; + + public ModbusThingModel(String productKey) { + this.productKey = productKey; + } + + @Data + public static class Model { + private List properties; + private List services; + private List events; + + public Map serviceMap() { + if (services == null) { + return new HashMap<>(); + } + return services.stream().collect(Collectors.toMap(ModbusThingModel.Service::getIdentifier, s -> s)); + } + } + + @Data + @JsonIgnoreProperties(ignoreUnknown = true) + public static class Property { + private String name; + private String identifier; + // 描述 + private String description; + /** + * 寄存器类型 + * [{value:'01',label:'线圈状态(RW)',}, + * {value:'02',label:'离散输入(RO)',}, + * {value:'03',label:'保持寄存器(RW)',}, + * {value:'04',label:'输入寄存器(RO)',},] + */ + private String regType; + //寄存器地址 + private Integer regAddr; + //寄存器数量 + private Integer regNum; + // * 处理公式 + private String processor; + //数据顺序 + /** + + * [ + * { value: 'AB', }, + * { value: 'BA', }, + * { value: 'AB CD', }, + * { value: 'CD AB', }, + * { value: 'DC BA', }, + * { value: 'BA DC', }, + * ] + */ + private String sort; + + private ModbusThingModel.DataType dataType; + + private String accessMode = "rw"; + + // 单位 + private String unit; + } + + + @Data + public static class ProData { + /** + * 寄存器类型 + * [{value:'01',label:'线圈状态(RW)',}, + * {value:'02',label:'离散输入(RO)',}, + * {value:'03',label:'保持寄存器(RW)',}, + * {value:'04',label:'输入寄存器(RO)',},] + */ + private String regType; + //寄存器地址 + private Integer regAddr; + //寄存器数量 + private Integer regNum; + // * 处理公式 + private String processor; + //数据顺序 + /** + + * [ + * { value: 'AB', }, + * { value: 'BA', }, + * { value: 'AB CD', }, + * { value: 'CD AB', }, + * { value: 'DC BA', }, + * { value: 'BA DC', }, + * ] + */ + private String sort; + } + + @Data + @JsonIgnoreProperties(ignoreUnknown = true) + public static class Parameter { + private String identifier; + private ThingModel.DataType dataType; + private String name; + private Boolean required = false; + } + + @Data + public static class Service { + private String identifier; + private List inputData; + private List outputData; + private String name; + } + + @Data + public static class Event { + private String identifier; + private List outputData; + private String name; + } + + @Data + public static class DataType { + private String type; + private Object specs; + + public Object parse(T value) { + if (value == null) { + return null; + } + + String val = value.toString(); + type = type.toLowerCase(); + switch (type) { + case "bool": + case "enum": + return val; + case "int": + return Integer.parseInt(val); + default: + return val; + } + + } + } +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/Channel.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/Channel.java new file mode 100644 index 0000000..d2431d8 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/Channel.java @@ -0,0 +1,54 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.notify; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * author: 石恒 + * date: 2023-05-11 16:30 + * description: + **/ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Channel extends TenantModel implements Id { + + private Long id; + + private String code; + + private String title; + + private String icon; + + private Long createAt; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/ChannelConfig.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/ChannelConfig.java new file mode 100644 index 0000000..2d8e18a --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/ChannelConfig.java @@ -0,0 +1,54 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.notify; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * author: 石恒 + * date: 2023-05-11 16:30 + * description: + **/ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ChannelConfig extends TenantModel implements Id { + + private Long id; + + private Long channelId; + + private String title; + + private String param; + + private Long createAt; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/ChannelTemplate.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/ChannelTemplate.java new file mode 100644 index 0000000..1fb5855 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/ChannelTemplate.java @@ -0,0 +1,53 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.notify; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * author: 石恒 + * date: 2023-05-11 16:30 + * description: + **/ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ChannelTemplate extends TenantModel implements Id { + + private Long id; + + private Long channelConfigId; + + private String title; + + private String content; + + private Long createAt; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/NotifyMessage.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/NotifyMessage.java new file mode 100644 index 0000000..fe3a812 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/NotifyMessage.java @@ -0,0 +1,55 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.notify; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author: 石恒 + * @Date: 2023/5/13 15:22 + * @Description: + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class NotifyMessage extends TenantModel implements Id { + + private Long id; + + private String content; + + private String messageType; + + private Boolean status; + + private Long createAt; + + private Long updateAt; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOta.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOta.java new file mode 100644 index 0000000..cb4c76d --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOta.java @@ -0,0 +1,38 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.ota; + +import cc.iotkit.model.TenantModel; +import lombok.Data; + +/** + * @Author: 石恒 + * @Date: 2023/6/10 14:36 + * @Description: + */ +@Data +public class DeviceOta extends TenantModel { + private String currentVersion; + private String deviceId; +} \ No newline at end of file diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOtaDetail.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOtaDetail.java new file mode 100644 index 0000000..26d30d8 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOtaDetail.java @@ -0,0 +1,64 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.ota; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:00 + * @Description: + */ + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DeviceOtaDetail extends TenantModel implements Id { + + private Long id; + + private Integer step; + + private String taskId; + + private String desc; + + private String version; + + private String module; + + private String deviceId; + + private String productKey; + + private String deviceName; + + private Long otaInfoId; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOtaInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOtaInfo.java new file mode 100644 index 0000000..49ac307 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOtaInfo.java @@ -0,0 +1,62 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.ota; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.*; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:00 + * @Description: + */ + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DeviceOtaInfo extends TenantModel implements Id { + + private Long id; + + private Long packageId; + + private String desc; + + private String version; + + private String module; + + private Integer total; + + private Integer success; + + private Integer fail; + + private String productKey; + + private Long createAt; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaDevice.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaDevice.java new file mode 100644 index 0000000..28c3276 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaDevice.java @@ -0,0 +1,56 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.ota; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author: 石恒 + * @Date: 2023/6/10 14:36 + * @Description: + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class OtaDevice extends TenantModel implements Id { + + private Long id; + + private String deviceName; + + private String deviceId; + + private String version; + + private Integer status; + + private Long createAt; +} + diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaInfo.java new file mode 100644 index 0000000..a4b51f9 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaInfo.java @@ -0,0 +1,39 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.ota; + +import cc.iotkit.model.TenantModel; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:54 + * @Description: + */ +@Data +public class OtaInfo extends TenantModel implements Serializable { + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaPackage.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaPackage.java new file mode 100644 index 0000000..d39af4e --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaPackage.java @@ -0,0 +1,112 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.ota; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +/** + * @Author: 石恒 + * @Date: 2023/6/10 14:35 + * @Description: + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class OtaPackage extends TenantModel implements Id { + + private Long id; + + /** + * 文件包大小 + */ + private Long size; + + /** + * 签名 + */ + private String sign; + + /** + * 是否差分升级 + */ + private Boolean isDiff; + + /** + * 文件MD5后的值 + */ + private String md5; + + /** + * 包名 + */ + private String name; + + /** + * 描述 + */ + private String desc; + + /** + * 版本 + */ + private String version; + + /** + * 升级包地址 + */ + private String url; + + /** + * 签名方式 + */ + private String signMethod; + + /** + * 模块 + */ + private String module; + + /** + * 扩展数据 + */ + private String extData; + + /** + * 创建时间 + */ + private Long createAt; + + /** + * 产品key + */ + private String productKey; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/plugin/PluginInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/plugin/PluginInfo.java new file mode 100644 index 0000000..8b9445a --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/plugin/PluginInfo.java @@ -0,0 +1,135 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.plugin; + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * 插件信息 + * + * @author sjg + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class PluginInfo extends TenantModel implements Id, Serializable { + + /** + * 插件状态-停止 + */ + public static final String STATE_STOPPED = "stopped"; + /** + * 插件状态-运行中 + */ + public static final String STATE_RUNNING = "running"; + + /** + * 插件类型-普通插件 + */ + public static final String TYPE_NORMAL = "normal"; + /** + * 插件类型-设备插件 + */ + public static final String TYPE_DEVICE = "device"; + + /** + * 部署方式-上传jar + */ + public static final String DEPLOY_UPLOAD = "upload"; + /** + * 部署方式-独立运行 + */ + public static final String DEPLOY_ALONE = "alone"; + + /** + * id + */ + private Long id; + + /** + * 插件包id + */ + private String pluginId; + + /** + * 插件名称 + */ + private String name; + + /** + * 描述 + */ + private String description; + + /** + * 部署方式 + */ + private String deployType; + + /** + * 插件包文件名 + */ + private String file; + + /** + * 插件版本 + */ + private String version; + + /** + * 插件类型 + */ + private String type; + + /** + * 设备插件协议类型 + */ + private String protocol; + + /** + * 状态 + */ + private String state; + + /** + * 插件配置项描述信息 + */ + private String configSchema; + + /** + * 插件配置信息 + */ + private String config; + + /** + * 插件脚本 + */ + private String script; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/plugin/PluginInstance.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/plugin/PluginInstance.java new file mode 100644 index 0000000..4a15b13 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/plugin/PluginInstance.java @@ -0,0 +1,73 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.plugin; + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.*; + +import java.io.Serializable; + +/** + * 插件实例 + * + * @author sjg + */ +@EqualsAndHashCode(callSuper = true) +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PluginInstance extends TenantModel implements Id, Serializable { + + private Long id; + + /** + * 插件主程序id + */ + private String mainId; + + /** + * 插件id + */ + private Long pluginId; + + /** + * 插件主程序所在ip + */ + private String ip; + + /** + * 插件主程序端口 + */ + private int port; + + /** + * 心跳时间 + * 心路时间超过30秒需要剔除 + */ + private Long heartbeatAt; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/AppDesign.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/AppDesign.java new file mode 100644 index 0000000..23bc0ac --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/AppDesign.java @@ -0,0 +1,50 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.product; + +import cc.iotkit.model.Owned; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AppDesign extends TenantModel implements Owned { + + private String id; + + private String productKey; + + private String template; + + private String uid; + + private Boolean state; + + private Long modifyAt; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/Category.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/Category.java new file mode 100644 index 0000000..df5033c --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/Category.java @@ -0,0 +1,38 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.product; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; + +@Data +public class Category extends TenantModel implements Id { + + private String id; + + private String name; + + private Long createAt; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/Icon.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/Icon.java new file mode 100644 index 0000000..7913613 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/Icon.java @@ -0,0 +1,56 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.product; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.*; + +import java.io.Serializable; + +/** + * @Author: tfd + * @Date: 2024/4/25 14:32 + * @Description: + */ +@EqualsAndHashCode(callSuper = true) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Icon extends TenantModel implements Id, Serializable { + + private Long id; + + private Long iconTypeId; + + private String iconName; + + private String viewBox; + + private String xmlns; + + private String version; + + private String iconContent; +} \ No newline at end of file diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/IconType.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/IconType.java new file mode 100644 index 0000000..b8b94ce --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/IconType.java @@ -0,0 +1,48 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.product; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.*; + +import java.io.Serializable; + +/** + * @Author: tfd + * @Date: 2024/4/25 14:32 + * @Description: + */ +@EqualsAndHashCode(callSuper = true) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class IconType extends TenantModel implements Id, Serializable { + + private Long id; + + private String typeName; + + private String typeDescribe; +} \ No newline at end of file diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/Product.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/Product.java new file mode 100644 index 0000000..5d9841d --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/Product.java @@ -0,0 +1,89 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.product; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.*; + +import java.io.Serializable; + +@EqualsAndHashCode(callSuper = true) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Product extends TenantModel implements Id, Serializable { + + //定位更新方式,手动/设备上报 + public static final String LOCATE_MANUAL = "manual"; + public static final String LOCATE_DEVICE = "device"; + + private Long id; + + private String productKey; + + private String productSecret; + + private String name; + + private String category; + + private Integer nodeType; + + /** + * 所属平台用户ID + */ + private String uid; + + private String img; + + private Long iconId; + + /** + * 是否透传 + */ + private Boolean transparent; + + /** + * 是否开启定位 + */ + private Boolean isOpenLocate; + + /** + * 定位更新方式 + */ + private String locateUpdateType; + + /** + * 保活时长(秒) + */ + private Long keepAliveTime; + + private Long createAt; + + private Integer productType; + public boolean isTransparent() { + return transparent != null && transparent; + } +} \ No newline at end of file diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/ProductModel.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/ProductModel.java new file mode 100644 index 0000000..3ac53cb --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/ProductModel.java @@ -0,0 +1,70 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.product; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ProductModel extends TenantModel implements Id { + + public static final String TYPE_JS = "JavaScript"; + public static final String TYPE_LUA = "LuaScript"; + + public static final String STATE_DEV = "dev"; + public static final String STATE_PUBLISH = "publish"; + + private String id; + + /** + * 型号在所有产品中唯一 + */ + private String model; + + private String name; + + private String productKey; + + private String type; + + private String script; + + /** + * 脚本状态,只有发布状态才生效 + */ + private String state; + + private Long modifyAt; + + public static String getDefaultModel(String pk) { + return pk + "_default"; + } + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/ThingModel.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/ThingModel.java new file mode 100644 index 0000000..58698b3 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/ThingModel.java @@ -0,0 +1,139 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.product; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.*; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author sjg + */ +@EqualsAndHashCode(callSuper = true) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ThingModel extends TenantModel implements Id, Serializable { + private static final long serialVersionUID = 1L; + + private Long id; + + private String productKey; + + private Model model; + + public ThingModel(String productKey) { + this.productKey = productKey; + } + + @Data + public static class Model { + private List properties; + private List services; + private List events; + + public Map serviceMap() { + if (services == null) { + return new HashMap<>(); + } + return services.stream().collect(Collectors.toMap(Service::getIdentifier, s -> s)); + } + } + + @Data + @JsonIgnoreProperties(ignoreUnknown = true) + public static class Property { + private String identifier; + private DataType dataType; + private String name; + private String accessMode = "rw"; + + // 描述 + private String description; + + // 单位 + private String unit; + // 图标id + private Long iconId; + // 图标信息 + private Icon icon; + private String proData; + } + + @Data + @JsonIgnoreProperties(ignoreUnknown = true) + public static class Parameter { + private String identifier; + private DataType dataType; + private String name; + private Boolean required = false; + } + + @Data + public static class Service { + private String identifier; + private List inputData; + private List outputData; + private String name; + } + + @Data + public static class Event { + private String identifier; + private List outputData; + private String name; + } + + @Data + public static class DataType { + private String type; + private Object specs; + + public Object parse(T value) { + if (value == null) { + return null; + } + + String val = value.toString(); + type = type.toLowerCase(); + switch (type) { + case "bool": + case "enum": + return val; + case "int": + return Integer.parseInt(val); + default: + return val; + } + + } + } +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/FilterConfig.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/FilterConfig.java new file mode 100644 index 0000000..4d2caf0 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/FilterConfig.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.rule; + +import lombok.Data; + +/** + * 监听器和过滤器的过滤条件配置 + * + * @author sjg + */ +@Data +public class FilterConfig { + /** + * 条件类型 + */ + private String type; + + /** + * 条件配置 + */ + protected String config; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleAction.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleAction.java new file mode 100644 index 0000000..d539c6c --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleAction.java @@ -0,0 +1,83 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.rule; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 规则引擎输出动作 + * + * @author sjg + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class RuleAction { + /** + * 设备控制 + */ + public static final String TYPE_DEVICE = "device"; + + /** + * 告警消息 + */ + public static final String TYPE_ALARM = "alarm"; + + /** + * 场景控制 + */ + public static final String TYPE_SCENE = "scene"; + + /** + * http推送 + */ + public static final String TYPE_HTTP = "http"; + + /** + * mqtt推送 + */ + public static final String TYPE_MQTT = "mqtt"; + + /** + * kafka推送 + */ + public static final String TYPE_KAFKA = "kafka"; + + /** + * tcp推送 + */ + public static final String TYPE_TCP = "tcp"; + + /** + * 动作类型 + */ + protected String type; + + /** + * 动作配置 + */ + protected String config; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleInfo.java new file mode 100644 index 0000000..a207e17 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleInfo.java @@ -0,0 +1,75 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.rule; + +import cc.iotkit.model.Owned; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class RuleInfo implements Owned { + + public static final String STATE_STOPPED = "stopped"; + public static final String STATE_RUNNING = "running"; + + public static final String TYPE_SCENE = "scene"; + public static final String TYPE_FLOW = "flow"; + + private String id; + + private String name; + + private String type; + + private List listeners; + + private List filters; + + private List actions; + + private String uid; + + private String state; + + private String desc; + + private Long createAt; + + public List getListeners() { + return listeners == null ? new ArrayList<>() : listeners; + } + + public List getFilters() { + return filters == null ? new ArrayList<>() : filters; + } + + public List getActions() { + return actions == null ? new ArrayList<>() : actions; + } +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleLog.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleLog.java new file mode 100644 index 0000000..194b0fc --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleLog.java @@ -0,0 +1,50 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.rule; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class RuleLog { + + public static final String STATE_MATCHED_LISTENER = "matched_listener"; + public static final String STATE_MATCHED_FILTER = "matched_filter"; + public static final String STATE_UNMATCHED_FILTER = "unmatched_filter"; + public static final String STATE_EXECUTED_ACTION = "executed_action"; + + private String id; + + private String ruleId; + + private String state; + + private String content; + + private Boolean success; + + private Long logAt; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/TaskInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/TaskInfo.java new file mode 100644 index 0000000..2fb2d44 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/TaskInfo.java @@ -0,0 +1,100 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.rule; + +import cc.iotkit.model.Owned; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data + +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TaskInfo implements Owned { + + public static String TYPE_TIMER = "timer"; + public static String TYPE_DELAY = "delay"; + + public static String STATE_STOP = "stopped"; + public static String STATE_RUNNING = "running"; + public static String STATE_INVALID = "invalid"; + public static String STATE_FINISHED = "finished"; + + private String id; + + private String name; + + /** + * 任务类型 + */ + private String type; + + /** + * 表达式 + * 定时器使用cron表达式 + * 延时器使用延时时长(秒) + */ + private String expression; + + /** + * 描述 + */ + private String desc; + + /** + * 任务输出 + */ + private List actions; + + /** + * 任务状态 + */ + private String state; + + /** + * 创建者 + */ + private String uid; + + private Long createAt; + + /** + * 操作备注 + */ + private String reason; + + public Long delayTime() { + if (!TYPE_DELAY.equals(type)) { + return null; + } + if (expression == null) { + return null; + } + return Long.parseLong(expression); + } +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/TaskLog.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/TaskLog.java new file mode 100644 index 0000000..7bfff5f --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/TaskLog.java @@ -0,0 +1,45 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.rule; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TaskLog { + + private String id; + + private String taskId; + + private String content; + + private Boolean success; + + private Long logAt; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/screen/Screen.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/screen/Screen.java new file mode 100644 index 0000000..f92a2c1 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/screen/Screen.java @@ -0,0 +1,70 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.screen; + +import cc.iotkit.model.Owned; +import lombok.Data; + +/** + * @Author:tfd + * @Date:2023/6/25 15:04 + */ +@Data +public class Screen implements Owned { + + public static final String STATE_STOPPED = "stopped"; + public static final String STATE_RUNNING = "running"; + + private Long id; + private String uid; + /** + * 大屏名称 + */ + private String name; + + /** + * 资源文件 + */ + private String resourceFile; + + /** + * 端口 + */ + private Integer port; + + /** + * 发布状态 + */ + private String state; + + /** + * 创建时间 + */ + private Long createAt; + + /** + * 是否为默认大屏 + */ + private Boolean isDefault; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/screen/ScreenApi.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/screen/ScreenApi.java new file mode 100644 index 0000000..972d09e --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/screen/ScreenApi.java @@ -0,0 +1,72 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.screen; + +import cc.iotkit.model.Owned; +import lombok.Data; + +/** + * @Author:tfd + * @Date:2023/6/25 15:04 + */ +@Data +public class ScreenApi implements Owned { + + private Long id; + private String uid; + /** + * 大屏id + */ + private Long screenId; + + /** + * 接口路径 + */ + private String apiPath; + + /** + * 接口参数 + */ + private String apiParams; + + /** + * 请求方法 + */ + private String httpMethod; + + /** + * 数据源 + */ + private String dataSource; + + /** + * 创建时间 + */ + private Long createAt; + + /** + * 转换脚本 + */ + private String script; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/Home.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/Home.java new file mode 100644 index 0000000..5ca13e9 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/Home.java @@ -0,0 +1,77 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.space; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Home extends TenantModel implements Id, Serializable { + + private Long id; + + /** + * 家庭名称 + */ + private String name; + + /** + * 家庭地址 + */ + private String address; + + /** + * 关联用户id + */ + private Long userId; + + /** + * 空间数量 + */ + private Integer spaceNum; + + /** + * 设备数量 + */ + private Integer deviceNum; + + /** + * 是否为用户当前使用的家庭 + */ + private Boolean current; + + /** + * 空间对象 + */ + private List spaces; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/Space.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/Space.java new file mode 100644 index 0000000..9ab110e --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/Space.java @@ -0,0 +1,56 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.space; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Space extends TenantModel implements Id, Serializable { + + private Long id; + + /** + * 关联家庭id + */ + private Long homeId; + + /** + * 空间名称 + */ + private String name; + + /** + * 设备数量 + */ + private Integer deviceNum; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/SpaceDevice.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/SpaceDevice.java new file mode 100644 index 0000000..16fb078 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/SpaceDevice.java @@ -0,0 +1,67 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.space; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SpaceDevice extends TenantModel implements Id, Serializable { + + private Long id; + + /** + * 空间中的设备id + */ + private String deviceId; + + /** + * 空间中的设备名称 + */ + private String name; + + /** + * 所属家庭Id + */ + private Long homeId; + + /** + * 空间id + */ + private Long spaceId; + + /** + * 是否收藏 + */ + private Boolean collect; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/AlertStatDTO.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/AlertStatDTO.java new file mode 100644 index 0000000..92f694e --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/AlertStatDTO.java @@ -0,0 +1,14 @@ +package cc.iotkit.model.stats; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.Date; + +@AllArgsConstructor +@Data +public class AlertStatDTO { + private String axis; // 日期格式:YYYY-MM-DD + private String name; // 告警等级1-5 + private Integer data; // 该等级当天的告警数量 +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/DataItem.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/DataItem.java new file mode 100644 index 0000000..a8f63b0 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/DataItem.java @@ -0,0 +1,47 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.stats; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 统计的数据项 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class DataItem { + + /** + * 数据项名 + */ + private String name; + + /** + * 数据项值 + */ + private Object value; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/DeviceProduckDTO.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/DeviceProduckDTO.java new file mode 100644 index 0000000..4a08313 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/DeviceProduckDTO.java @@ -0,0 +1,12 @@ +package cc.iotkit.model.stats; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@AllArgsConstructor +@Data +public class DeviceProduckDTO { + private String productKey; // 日期格式:YYYY-MM-DD + private String name; // 告警等级1-5 + private Integer state; // 该等级当天的告警数量 +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/ProductKeyCountDTO.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/ProductKeyCountDTO.java new file mode 100644 index 0000000..c4b1467 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/ProductKeyCountDTO.java @@ -0,0 +1,20 @@ +package cc.iotkit.model.stats; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class ProductKeyCountDTO { + + private String productKey; + private String name; + private Long value; + + public ProductKeyCountDTO(String productKey, Long value, String name) { + this.productKey = productKey; + this.value = value; + this.name = name; + } + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/TimeData.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/TimeData.java new file mode 100644 index 0000000..ccfa901 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/TimeData.java @@ -0,0 +1,47 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.model.stats; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 统计的时间数据 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TimeData { + + /** + * 时间 + */ + private long time; + + /** + * 数据值 + */ + private Object data; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysApp.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysApp.java new file mode 100644 index 0000000..ba1fb36 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysApp.java @@ -0,0 +1,77 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + + +/** + * 对象 SYS_APP + * + * @author tfd + * @date 2023-08-10 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class SysApp extends TenantModel implements Id, Serializable{ + + private static final long serialVersionUID = 1L; + + /** + * id + */ + private Long id; + + /** + * 应用名称 + */ + private String appName; + + /** + * appId + */ + private String appId; + + /** + * appSecret + */ + private String appSecret; + + /** + * 应用类型 + */ + private String appType; + + /** + * 备注 + */ + private String remark; + + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysConfig.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysConfig.java new file mode 100644 index 0000000..a0ee6b8 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysConfig.java @@ -0,0 +1,80 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 参数配置视图对象 sys_config + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysConfig extends TenantModel implements Id, Serializable { + private static final long serialVersionUID = 1L; + + /** + * 参数主键 + */ + private Long id; + + /** + * 参数名称 + */ + private String configName; + + /** + * 参数键名 + */ + private String configKey; + + /** + * 参数键值 + */ + private String configValue; + + /** + * 系统内置(Y是 N否) + */ + private String configType; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间 + */ + private Date createTime; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDept.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDept.java new file mode 100644 index 0000000..51993f5 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDept.java @@ -0,0 +1,108 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.Id; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + +/** + * 部门视图对象 sys_dept + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysDept extends BaseModel implements Id, Serializable { + private static final long serialVersionUID = 1L; + + /** + * 部门id + */ + private Long id; + + /** + * 父部门id + */ + private Long parentId; + + /** + * 父部门名称 + */ + private String parentName; + + /** + * 祖级列表 + */ + private String ancestors; + + /** + * 部门名称 + */ + private String deptName; + + /** + * 显示顺序 + */ + private Integer orderNum; + + /** + * 负责人 + */ + private String leader; + + /** + * 联系电话 + */ + private String phone; + + /** + * 邮箱 + */ + private String email; + + /** + * 部门状态(0正常 1停用) + */ + private String status; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 租户编号 + */ + private Long tenantId; + + /** + * 部门与区域(默认0是部门,1是区域) + */ + private Integer areaType; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDictData.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDictData.java new file mode 100644 index 0000000..7dc5de6 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDictData.java @@ -0,0 +1,100 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 字典数据视图对象 sys_dict_data + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysDictData extends TenantModel implements Id,Serializable { + private static final long serialVersionUID = 1L; + + /** + * 字典编码 + */ + private Long id; + + /** + * 字典排序 + */ + private Integer dictSort; + + /** + * 字典标签 + */ + private String dictLabel; + + /** + * 字典键值 + */ + private String dictValue; + + /** + * 字典类型 + */ + private String dictType; + + /** + * 样式属性(其他样式扩展) + */ + private String cssClass; + + /** + * 表格回显样式 + */ + private String listClass; + + /** + * 是否默认(Y是 N否) + */ + private String isDefault; + + /** + * 状态(0正常 1停用) + */ + private String status; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间 + */ + private Date createTime; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDictType.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDictType.java new file mode 100644 index 0000000..36f47db --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDictType.java @@ -0,0 +1,75 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 字典类型视图对象 sys_dict_type + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysDictType extends TenantModel implements Id,Serializable { + private static final long serialVersionUID = 1L; + + /** + * 字典主键 + */ + private Long id; + + /** + * 字典名称 + */ + private String dictName; + + /** + * 字典类型 + */ + private String dictType; + + /** + * 状态(0正常 1停用) + */ + private String status; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间 + */ + private Date createTime; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysLoginInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysLoginInfo.java new file mode 100644 index 0000000..8d742a5 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysLoginInfo.java @@ -0,0 +1,95 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import java.io.Serializable; +import java.util.Date; + + +/** + * 系统访问记录视图对象 sys_logininfor + * + * @author Michelle.Chung + * @date 2023-02-07 + */ +@Data +public class SysLoginInfo extends TenantModel implements Id,Serializable { + private static final long serialVersionUID = 1L; + + /** + * 访问ID + */ + private Long id; + + /** + * 租户编号 + */ + private Long tenantId; + + /** + * 用户账号 + */ + private String userName; + + /** + * 登录状态(0成功 1失败) + */ + private String status; + + /** + * 登录IP地址 + */ + private String ipaddr; + + /** + * 登录地点 + */ + private String loginLocation; + + /** + * 浏览器类型 + */ + private String browser; + + /** + * 操作系统 + */ + private String os; + + + /** + * 提示消息 + */ + private String msg; + + /** + * 访问时间 + */ + private Date loginTime; + + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysMenu.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysMenu.java new file mode 100644 index 0000000..0a80fe7 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysMenu.java @@ -0,0 +1,132 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.Id; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + +/** + * 菜单权限视图对象 sys_menu + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysMenu extends BaseModel implements Id,Serializable { + private static final long serialVersionUID = 1L; + + /** + * 菜单ID + */ + private Long id; + + /** + * 菜单名称 + */ + private String menuName; + + /** + * 父菜单ID + */ + private Long parentId; + + /** + * 显示顺序 + */ + private Integer orderNum; + + /** + * 路由地址 + */ + private String path; + + /** + * 组件路径 + */ + private String component; + + /** + * 路由参数 + */ + private String queryParam; + + /** + * 是否为外链(0是 1否) + */ + private String isFrame; + + /** + * 是否缓存(0缓存 1不缓存) + */ + private String isCache; + + /** + * 菜单类型(M目录 C菜单 F按钮) + */ + private String menuType; + + /** + * 显示状态(0显示 1隐藏) + */ + private String visible; + + /** + * 菜单状态(0正常 1停用) + */ + private String status; + + /** + * 权限标识 + */ + private String perms; + + /** + * 菜单图标 + */ + private String icon; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 子菜单 + */ + private List children = new ArrayList<>(); + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysNotice.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysNotice.java new file mode 100644 index 0000000..6b60185 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysNotice.java @@ -0,0 +1,90 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 通知公告视图对象 sys_notice + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysNotice extends TenantModel implements Id, Serializable { + private static final long serialVersionUID = 1L; + + /** + * 公告ID + */ + private Long id; + + /** + * 公告标题 + */ + private String noticeTitle; + + /** + * 公告类型(1通知 2公告) + */ + private String noticeType; + + /** + * 公告内容 + */ + private String noticeContent; + + /** + * 公告状态(0正常 1关闭) + */ + private String status; + + /** + * 备注 + */ + private String remark; + + /** + * 创建者 + */ + private Long createBy; + + /** + * 创建人名称 + */ + private String createByName; + + /** + * 创建时间 + */ + private Date createTime; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOperLog.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOperLog.java new file mode 100644 index 0000000..84500d2 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOperLog.java @@ -0,0 +1,140 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.Id; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 操作日志记录视图对象 sys_oper_log + * + * @author Michelle.Chung + * @date 2023-02-07 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysOperLog extends BaseModel implements Id, Serializable { + private static final long serialVersionUID = 1L; + + /** + * 日志主键 + */ + private Long id; + + /** + * 租户编号 + */ + private Long tenantId; + + /** + * 模块标题 + */ + private String title; + + /** + * 业务类型(0其它 1新增 2修改 3删除) + */ + private Integer businessType; + + /** + * 业务类型数组 + */ + private Integer[] businessTypes; + + /** + * 方法名称 + */ + private String method; + + /** + * 请求方式 + */ + private String requestMethod; + + /** + * 操作类别(0其它 1后台用户 2手机端用户) + */ + private Integer operatorType; + + /** + * 操作人员 + */ + private String operName; + + /** + * 部门名称 + */ + private String deptName; + + /** + * 请求URL + */ + private String operUrl; + + /** + * 主机地址 + */ + private String operIp; + + /** + * 操作地点 + */ + private String operLocation; + + /** + * 请求参数 + */ + private String operParam; + + /** + * 返回参数 + */ + private String jsonResult; + + /** + * 操作状态(0正常 1异常) + */ + private Integer status; + + /** + * 错误消息 + */ + private String errorMsg; + + /** + * 操作时间 + */ + private Date operTime; + + /** + * 消耗时间 + */ + private Long costTime; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOss.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOss.java new file mode 100644 index 0000000..fe70d93 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOss.java @@ -0,0 +1,90 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + +/** + * OSS对象存储视图对象 sys_oss + * + * @author Lion Li + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysOss extends TenantModel implements Id,Serializable { + private static final long serialVersionUID = 1L; + + /** + * 对象存储主键 + */ + private Long id; + + /** + * 文件名 + */ + private String fileName; + + /** + * 原名 + */ + private String originalName; + + /** + * 文件后缀名 + */ + private String fileSuffix; + + /** + * URL地址 + */ + private String url; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 上传人 + */ + private Long createBy; + + /** + * 上传人名称 + */ + private String createByName; + + /** + * 服务商 + */ + private String service; + + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOssConfig.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOssConfig.java new file mode 100644 index 0000000..d5772c6 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOssConfig.java @@ -0,0 +1,116 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + + +/** + * 对象存储配置视图对象 sys_oss_config + * + * @author Lion Li + * @author 孤舟烟雨 + * @date 2021-08-13 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysOssConfig extends TenantModel implements Id, Serializable { + private static final long serialVersionUID = 1L; + + /** + * 主建 + */ + private Long id; + + /** + * 配置key + */ + private String configKey; + + /** + * accessKey + */ + private String accessKey; + + /** + * 秘钥 + */ + private String secretKey; + + /** + * 桶名称 + */ + private String bucketName; + + /** + * 前缀 + */ + private String prefix; + + /** + * 访问站点 + */ + private String endpoint; + + /** + * 自定义域名 + */ + private String domain; + + /** + * 是否https(Y=是,N=否) + */ + private String isHttps; + + /** + * 域 + */ + private String region; + + /** + * 是否默认(0=是,1=否) + */ + private String status; + + /** + * 扩展字段 + */ + private String ext1; + + /** + * 备注 + */ + private String remark; + + /** + * 桶权限类型(0private 1public 2custom) + */ + private String accessPolicy; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysPost.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysPost.java new file mode 100644 index 0000000..9537a20 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysPost.java @@ -0,0 +1,80 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 岗位信息视图对象 sys_post + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysPost extends TenantModel implements Id,Serializable { + private static final long serialVersionUID = 1L; + + /** + * 岗位ID + */ + private Long id; + + /** + * 岗位编码 + */ + private String postCode; + + /** + * 岗位名称 + */ + private String postName; + + /** + * 显示顺序 + */ + private Integer postSort; + + /** + * 状态(0正常 1停用) + */ + private String status; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间 + */ + private Date createTime; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRole.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRole.java new file mode 100644 index 0000000..cfaa605 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRole.java @@ -0,0 +1,104 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + +/** + * 角色信息视图对象 sys_role + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysRole extends TenantModel implements Id,Serializable { + private static final long serialVersionUID = 1L; + + /** + * 角色ID + */ + private Long id; + + /** + * 角色名称 + */ + private String roleName; + + /** + * 角色权限字符串 + */ + private String roleKey; + + /** + * 显示顺序 + */ + private Integer roleSort; + + /** + * 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限) + */ + private String dataScope; + + /** + * 菜单树选择项是否关联显示 + */ + private Boolean menuCheckStrictly; + + /** + * 部门树选择项是否关联显示 + */ + private Boolean deptCheckStrictly; + + /** + * 角色状态(0正常 1停用) + */ + private String status; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 用户是否存在此角色标识 默认不存在 + */ + private boolean flag = false; + + public boolean isSuperAdmin() { + return UserConstants.SUPER_ADMIN_ID.equals(this.id); + } + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRoleDept.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRoleDept.java new file mode 100644 index 0000000..e992468 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRoleDept.java @@ -0,0 +1,53 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * author: 石恒 + * date: 2023-05-30 16:16 + * description: + **/ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysRoleDept extends TenantModel implements Id, Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + + private Long roleId; + + /** + * 部门ID + */ + private Long deptId; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRoleMenu.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRoleMenu.java new file mode 100644 index 0000000..1b2147c --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRoleMenu.java @@ -0,0 +1,57 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * author: 石恒 + * date: 2023-05-30 10:57 + * description: + **/ + +@EqualsAndHashCode(callSuper = true) +@Data +public class SysRoleMenu extends TenantModel implements Id, Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + + /** + * 角色ID + */ + private Long roleId; + + /** + * 菜单ID + */ + private Long menuId; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysTenant.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysTenant.java new file mode 100644 index 0000000..89be7f7 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysTenant.java @@ -0,0 +1,115 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.Id; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 租户视图对象 sys_tenant + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysTenant extends BaseModel implements Id,Serializable { + private static final long serialVersionUID = 1L; + + /** + * id + */ + private Long id; + + /** + * 租户编号 + */ + private Long tenantId; + + /** + * 联系人 + */ + private String contactUserName; + + /** + * 联系电话 + */ + private String contactPhone; + + /** + * 企业名称 + */ + private String companyName; + + /** + * 统一社会信用代码 + */ + private String licenseNumber; + + /** + * 地址 + */ + private String address; + + /** + * 域名 + */ + private String domain; + + /** + * 企业简介 + */ + private String intro; + + /** + * 备注 + */ + private String remark; + + /** + * 租户套餐编号 + */ + private Long packageId; + + /** + * 过期时间 + */ + private Date expireTime; + + /** + * 用户数量(-1不限制) + */ + private Long accountCount; + + /** + * 租户状态(0正常 1停用) + */ + private String status; + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysTenantPackage.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysTenantPackage.java new file mode 100644 index 0000000..24761f0 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysTenantPackage.java @@ -0,0 +1,75 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.Id; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + + +/** + * 租户套餐视图对象 sys_tenant_package + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysTenantPackage extends BaseModel implements Id, Serializable { + private static final long serialVersionUID = 1L; + + /** + * 租户套餐id + */ + private Long id; + + /** + * 套餐名称 + */ + private String packageName; + + /** + * 关联菜单id + */ + private String menuIds; + + /** + * 备注 + */ + private String remark; + + /** + * 菜单树选择项是否关联显示 + */ + private Boolean menuCheckStrictly; + + /** + * 状态(0正常 1停用) + */ + private String status; + + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUser.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUser.java new file mode 100644 index 0000000..7f7b9be --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUser.java @@ -0,0 +1,151 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import java.util.Map; + + +/** + * 用户信息视图对象 sys_user + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysUser extends TenantModel implements Id, Serializable { + private static final long serialVersionUID = 1L; + + /** + * 用户ID + */ + private Long id; + private Map params; + /** + * 部门ID + */ + private Long deptId; + + /** + * 用户账号 + */ + private String userName; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 用户类型(sys_user系统用户) + */ + private String userType; + + /** + * 用户邮箱 + */ + private String email; + + /** + * 手机号码 + */ + private String phonenumber; + + /** + * 用户性别(0男 1女 2未知) + */ + private String sex; + + /** + * 头像地址 + */ + private Long avatar; + + /** + * 密码 + */ + private String password; + + /** + * 帐号状态(0正常 1停用) + */ + private String status; + + /** + * 最后登录IP + */ + private String loginIp; + + /** + * 最后登录时间 + */ + private Date loginDate; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 部门对象 + */ + private SysDept dept; + /** + * 部门对象 + */ + private SysDept areaDept; + /** + * 角色对象 + */ + private List roles; + + /** + * 角色组 + */ + private Long[] roleIds; + + /** + * 岗位组 + */ + private Long[] postIds; + + /** + * 数据权限 当前角色ID + */ + private Long roleId; + + private Long deptAreaId; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUserArea.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUserArea.java new file mode 100644 index 0000000..ff9fdb8 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUserArea.java @@ -0,0 +1,81 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + + +import cc.iotkit.model.BaseModel; +import io.github.linpeilie.annotations.AutoMapper; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; +import java.io.Serializable; + +/** + * 用户对象 sys_user + * + * @author Lion Li + */ + +@EqualsAndHashCode(callSuper = true) +@Data +public class SysUserArea extends BaseModel implements cc.iotkit.model.Id, Serializable { + private static final long serialVersionUID = 1L; + /** + * 用户ID + */ + + + private Long id; + + /** + * 租户编号 + */ + // @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 部门ID + */ + // @ApiModelProperty(value = "部门区域ID") + private Long sysDeptId; + + /** + * 用户账号 + */ + //@ApiModelProperty(value = "用户id") + private Long sysUserId; + + + public SysUserArea(Long id) { + this.id = id; + } + +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUserPost.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUserPost.java new file mode 100644 index 0000000..7a64f27 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUserPost.java @@ -0,0 +1,56 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.Id; +import java.io.Serializable; + +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +/** + * 用户和岗位关联 sys_user_post + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysUserPost extends TenantModel implements Id, Serializable { + private static final long serialVersionUID = 1L; + + private Long id; + + /** + * 用户ID + */ + private Long userId; + + /** + * 岗位ID + */ + private Long postId; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUserRole.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUserRole.java new file mode 100644 index 0000000..ad09682 --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUserRole.java @@ -0,0 +1,56 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.model.system; + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.Id; +import java.io.Serializable; + +import cc.iotkit.model.TenantModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +/** + * 用户和角色关联 sys_user_role + * + * @author Michelle.Chung + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysUserRole extends TenantModel implements Id, Serializable { + private static final long serialVersionUID = 1L; + + private Long id; + + /** + * 用户ID + */ + private Long userId; + + /** + * 角色ID + */ + private Long roleId; +} diff --git a/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/worder/WorderDO.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/worder/WorderDO.java new file mode 100644 index 0000000..d77609d --- /dev/null +++ b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/worder/WorderDO.java @@ -0,0 +1,162 @@ +package cc.iotkit.model.worder; + + +import cc.iotkit.model.TenantModel; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.sun.xml.bind.v2.TODO; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.*; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * 工单 DO + * + * @author zhp + */ +// 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@EqualsAndHashCode(callSuper = true) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class WorderDO extends TenantModel implements cc.iotkit.model.Id, Serializable { + private static final long serialVersionUID = 1L; + /** + * ID + */ + + private Long id; + + /** + * 工单编号 + */ + private String worderNum; + /** + * 工单内容 + */ + private String worderContent; + /** + * 上报时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date reportTime; + /** + * 指派人id + */ + private Long assignUserid; + /** + * 指派人姓名 + */ + private String assignName; + /** + * 指派时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date assignTime; + /** + * 问题截图 + */ + private String problemScreenshot; + /** + * 消息 + */ + private String message; + /** + * 预约时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private String reservationTime; + /** + * 客户id + */ + private Long customerId; + /** + * 客户姓名 + */ + private String customerName; + /** + * 联系方式 + */ + private String customerPhone; + /** + * 客户服务地址编码 + */ + private Integer customerAreaId; + /** + * 服务地址(客户详细地址) + */ + private String customerAddress; + /** + * 退单时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date worderBackTime; + /** + * 退单原因 + */ + private String worderBackReason; + /** + * 工单完成时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date finishTime; + /** + * 完成后图片 + */ + private String finishPicture; + /** + * 反馈信息 + */ + private String feedback; + + /** + * 工单类型 + *

+ * 枚举 {@link TODO worder_type 对应的类} + */ + private Integer worderType; + /** + * 订单id + */ + private String orderId; + /** + * 设备id + */ + private String productId; + /** + * 订单状态 + *

+ * 枚举 {@link TODO is_state 对应的类} + */ + private Integer orderStatus; + /** + * 工单状态 + *

+ * 枚举 {@link TODO worder_status 对应的类} + */ + private Integer worderStatus; + + /** + * fwid + */ + private Long fwId; + + /** + * 指派人电话 + */ + private String assignPhone; + private Long tenantId; +} \ No newline at end of file diff --git a/iot-dao/iot-data-service/pom.xml b/iot-dao/iot-data-service/pom.xml new file mode 100644 index 0000000..29b44ed --- /dev/null +++ b/iot-dao/iot-data-service/pom.xml @@ -0,0 +1,37 @@ + + + + iot-dao + cc.iotkit + 0.5.3 + + 4.0.0 + 0.5.3 + iot-data-service + + + + + cc.iotkit + iot-data-model + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + + + \ No newline at end of file diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/ICommonData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/ICommonData.java new file mode 100644 index 0000000..303792d --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/ICommonData.java @@ -0,0 +1,89 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.Id; + +import java.util.Collection; +import java.util.List; + +/** + * 数据基础服务接口 + */ +public interface ICommonData, ID> { + + /** + * 通过ID取数据 + */ + T findById(ID id); + + /** + * 通过ID取数据 + */ + List findByIds(Collection id); + + + /** + * 保存数据,id不为空更新,否则添加 + */ + T save(T data) ; + + + /** + * 批量保存数据 + */ + void batchSave(List data) ; + /** + * 按id删除 + */ + void deleteById(ID id) ; + /** + * 按id批量删除 + */ + void deleteByIds(Collection ids) ; + /** + * 总数统计 + */ + long count(); + /** + * 取所有数据 + */ + List findAll() ; + + /** + * 分页获取所有信息 + */ + Paging findAll(PageRequest pageRequest) ; + + /** + * 按条件查询多个结果 + */ + List findAllByCondition(T data); + + /** + * 按条件查询单个结果 + */ + T findOneByCondition(T data); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/IOwnedData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/IOwnedData.java new file mode 100644 index 0000000..f0dc58b --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/IOwnedData.java @@ -0,0 +1,57 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.Owned; + +import java.util.Collections; +import java.util.List; + +/** + * 数据基础服务接口 + */ +public interface IOwnedData, ID> extends ICommonData { + + /** + * 按所属用户取数据 + * @return + */ + default List findByUid(String uid) { + return Collections.emptyList(); + + } + + default Paging findByUid(String uid, int page, int size) { + return null; + } + + /** + * 按所属用户统计总数 + */ + default long countByUid(String uid) { + return 0L; + + } + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertConfigData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertConfigData.java new file mode 100644 index 0000000..571e2d0 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertConfigData.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.alert.AlertConfig; + + +public interface IAlertConfigData extends ICommonData { + + + Paging selectAlertConfigPage(PageRequest request); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertRecordData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertRecordData.java new file mode 100644 index 0000000..343569c --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertRecordData.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.alert.AlertRecord; +import cc.iotkit.model.stats.AlertStatDTO; + +import java.util.List; + + +public interface IAlertRecordData extends ICommonData { + + + Paging selectAlertConfigPage(PageRequest request); + + + List getAlertRecord(); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ICategoryData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ICategoryData.java new file mode 100644 index 0000000..d7f203f --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ICategoryData.java @@ -0,0 +1,29 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.product.Category; + +public interface ICategoryData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelConfigData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelConfigData.java new file mode 100644 index 0000000..4de9b79 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelConfigData.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.notify.ChannelConfig; + +/** + * author: 石恒 + * date: 2023-05-11 17:15 + * description: + **/ +public interface IChannelConfigData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelData.java new file mode 100644 index 0000000..ba4b8bf --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelData.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.notify.Channel; + +/** + * author: 石恒 + * date: 2023-05-11 17:15 + * description: + **/ +public interface IChannelData extends ICommonData { + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelTemplateData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelTemplateData.java new file mode 100644 index 0000000..2bdd9fb --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelTemplateData.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.notify.ChannelTemplate; + +/** + * author: 石恒 + * date: 2023-05-11 17:15 + * description: + **/ +public interface IChannelTemplateData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDIccidRecordData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDIccidRecordData.java new file mode 100644 index 0000000..be4925a --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDIccidRecordData.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.iccid.DIccidRecordDO; +import cc.iotkit.model.space.Home; + +import java.util.List; + + +public interface IDIccidRecordData extends ICommonData { + + + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceConfigData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceConfigData.java new file mode 100644 index 0000000..d7e78d5 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceConfigData.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.device.DeviceConfig; + +public interface IDeviceConfigData extends ICommonData { + + DeviceConfig findByDeviceName(String deviceName); + + DeviceConfig findByDeviceId(String deviceId); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceGroupData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceGroupData.java new file mode 100644 index 0000000..3433518 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceGroupData.java @@ -0,0 +1,33 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.device.DeviceGroup; + +public interface IDeviceGroupData extends ICommonData { + + Paging findByNameLike(String name, int page, int size); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceInfoData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceInfoData.java new file mode 100644 index 0000000..9eb781a --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceInfoData.java @@ -0,0 +1,190 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.IOwnedData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DevicePropertyCache; +import cc.iotkit.model.stats.AlertStatDTO; +import cc.iotkit.model.stats.DataItem; +import cc.iotkit.model.stats.ProductKeyCountDTO; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +public interface IDeviceInfoData extends IOwnedData { + + /** + * 保存设备属性 + * + * @param deviceId 设备id + * @param properties 设备属性map + */ + void saveProperties(String deviceId, Map properties); + + /** + * 获取设备属性map + * + * @param deviceId 设备id + */ + Map getProperties(String deviceId); + + /** + * 获取设备属性更新时间 + * + * @param deviceId 设备id + * @return timestamp + */ + long getPropertyUpdateTime(String deviceId); + + /** + * 获取设备最新通讯时间 + * + * @param deviceId 设备id + * @return timestamp + */ + long getLastTime(String deviceId); + /** + * 设置设备最新通讯时间 + * + * @param deviceId 设备id + * @return timestamp + */ + void setLastTime(String deviceId, long lastTime); + + /** + * 根据设备ID取设备信息 + * + * @param deviceId 设备ID + */ + DeviceInfo findByDeviceId(String deviceId); + + /** + * 根据父设备ID取子设备列表 + * + * @param parentId 父设备ID + */ + List findByParentId(String parentId); + public List findByConditionsList(String productKey); + /** + * 根据父设备ID取子设备ID列表 + * + * @param parentId 父设备ID + */ + List findSubDeviceIds(String parentId); + + /** + * 根据deviceName查找设备 + */ + DeviceInfo findByDeviceName(String deviceName); + + /** + * 按条件搜索设备 + * + * @param uid 所属账号id + * @param subUid 子账号id + * @param productKey 产品key + * @param groupId 设备分组 + * @param online 是否在线:true在线,false离线 + * @param keyword 关键字 + * @param page 页码 + * @param size 分页大小 + */ + Paging findByConditions(String uid, String subUid, String productKey, + String groupId, Boolean online, String keyword, + int page, int size,Long areaDepeId); + + /** + * 更新设备标签 + * + * @param deviceId 设备ID + * @param tag 标签 + */ + void updateTag(String deviceId, DeviceInfo.Tag tag); + + /** + * 获取按品类统计的用户设备数 + */ + List getDeviceStatsByCategory(String uid); + List getProductDevice(Long deptAreaId, String startDate, String endDate); + /** + * 按分组id统计设备数量 + */ + long countByGroupId(String groupId); + + /** + * 将设备添加到分组 + * + * @param deviceId 设备ID + * @param group 设备分组 + */ + void addToGroup(String deviceId, DeviceInfo.Group group); + + /** + * 按组id更新设备分组 + * + * @param groupId 分组ID + * @param group 设备分组信息 + */ + void updateGroup(String groupId, DeviceInfo.Group group); + + /** + * 移除指定设备信息中的分组 + * + * @param deviceId 设备ID + * @param groupId 分组ID + */ + void removeGroup(String deviceId, String groupId); + + /** + * 移除设备信息中的分组 + * + * @param groupId 分组ID + */ + void removeGroup(String groupId); + + /** + * 获取所有网关类型设备 + * + * @return + */ + List findByProductNodeType(String uid); + + /** + * 是否存在product类型的设备 + * + * @param productKey + * @return + */ + boolean existByProductKey(String productKey); + + /** + * 查找待激活设备 + * @return + */ + List findNeverUsedDevices(); + + List getDeviceRecord(); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaDetailData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaDetailData.java new file mode 100644 index 0000000..b7f4bc5 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaDetailData.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.ota.DeviceOtaDetail; +import cc.iotkit.model.ota.DeviceOtaInfo; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:14 + * @Description: + */ +public interface IDeviceOtaDetailData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaInfoData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaInfoData.java new file mode 100644 index 0000000..5475b43 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaInfoData.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.ota.DeviceOtaInfo; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:14 + * @Description: + */ +public interface IDeviceOtaInfoData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IFeedBackEvaluationData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IFeedBackEvaluationData.java new file mode 100644 index 0000000..e610370 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IFeedBackEvaluationData.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; + + + +public interface IFeedBackEvaluationData extends ICommonData { + + + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IHomeData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IHomeData.java new file mode 100644 index 0000000..588e7f9 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IHomeData.java @@ -0,0 +1,39 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.space.Home; + +import java.util.List; + + +public interface IHomeData extends ICommonData { + + Home findByUserIdAndCurrent(Long userId, boolean current); + + List findByUserId(Long userId); + + boolean checkHomeNameUnique(Home home); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IIconData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IIconData.java new file mode 100644 index 0000000..b078484 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IIconData.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.product.Icon; + +/** + * @Author: tfd + * @Date: 2024/4/25 14:32 + * @Description: + */ +public interface IIconData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IIconTypeData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IIconTypeData.java new file mode 100644 index 0000000..10527ea --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IIconTypeData.java @@ -0,0 +1,33 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.product.IconType; +/** + * @Author: tfd + * @Date: 2024/4/25 14:32 + * @Description: + */ +public interface IIconTypeData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/INotifyMessageData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/INotifyMessageData.java new file mode 100644 index 0000000..e902ebb --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/INotifyMessageData.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.notify.NotifyMessage; + +/** + * @Author: 石恒 + * @Date: 2023/5/13 18:32 + * @Description: + */ +public interface INotifyMessageData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOauthClientData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOauthClientData.java new file mode 100644 index 0000000..854eb34 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOauthClientData.java @@ -0,0 +1,32 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.OauthClient; + +public interface IOauthClientData extends ICommonData { + + OauthClient findByClientId(String clientId); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaDeviceData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaDeviceData.java new file mode 100644 index 0000000..07b9739 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaDeviceData.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.ota.OtaDevice; + +/** + * @Author: 石恒 + * @Date: 2023/5/25 23:40 + * @Description: + */ +public interface IOtaDeviceData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaPackageData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaPackageData.java new file mode 100644 index 0000000..0ac25cb --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaPackageData.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.ota.OtaPackage; + +/** + * @Author: 石恒 + * @Date: 2023/5/19 21:46 + * @Description: + */ +public interface IOtaPackageData extends ICommonData { + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IPluginInfoData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IPluginInfoData.java new file mode 100644 index 0000000..75d07ef --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IPluginInfoData.java @@ -0,0 +1,43 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.plugin.PluginInfo; + +/** + * 插件信息接口 + * + * @author sjg + */ +public interface IPluginInfoData extends ICommonData { + + /** + * 按插件包id取插件信息 + * + * @param pluginId 插件包id + * @return 插件信息 + */ + PluginInfo findByPluginId(String pluginId); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IPluginInstanceData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IPluginInstanceData.java new file mode 100644 index 0000000..85195f8 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IPluginInstanceData.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.plugin.PluginInstance; + +/** + * 插件实例接口 + * + * @author sjg + */ +public interface IPluginInstanceData extends ICommonData { + + /** + * 获取插件实例 + * + * @param mainId 主程序id + * @param pluginId 插件包id + * @return 插件实例 + */ + PluginInstance findInstance(String mainId, String pluginId); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProductData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProductData.java new file mode 100644 index 0000000..fddb591 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProductData.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.product.Product; + +import java.util.List; + +/** + * 产品接口 + */ +public interface IProductData extends ICommonData { + + /** + * 按品类取产品列表 + */ + List findByCategory(String category); + + + Product findByProductKey(String productKey); + + void delByProductKey(String productKey); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProductModelData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProductModelData.java new file mode 100644 index 0000000..e5ba428 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProductModelData.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.product.ProductModel; + +import java.util.List; + +public interface IProductModelData extends ICommonData { + + ProductModel findByModel(String model); + + List findByProductKey(String productKey); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IRuleInfoData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IRuleInfoData.java new file mode 100644 index 0000000..f7d3f61 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IRuleInfoData.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.IOwnedData; +import cc.iotkit.model.rule.RuleInfo; + +import java.util.List; + +public interface IRuleInfoData extends IOwnedData { + + List findByUidAndType(String uid, String type); + + Paging findByUidAndType(String uid, String type, int page, int size); + + Paging findByType(String type, int page, int size); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IScreenApiData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IScreenApiData.java new file mode 100644 index 0000000..af45923 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IScreenApiData.java @@ -0,0 +1,39 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.IOwnedData; +import cc.iotkit.model.screen.ScreenApi; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/6/25 15:34 + */ +public interface IScreenApiData extends IOwnedData { + List findByScreenId(Long id); + + void deleteByScreenId(Long id); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IScreenData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IScreenData.java new file mode 100644 index 0000000..d131f2b --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IScreenData.java @@ -0,0 +1,39 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.IOwnedData; +import cc.iotkit.model.screen.Screen; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/6/25 15:34 + */ +public interface IScreenData extends IOwnedData { + Screen findByIsDefault(boolean isDefault); + + List findByState(String state); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ISpaceData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ISpaceData.java new file mode 100644 index 0000000..c784952 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ISpaceData.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.space.Space; + +import java.util.List; + +public interface ISpaceData extends ICommonData { + + List findByHomeId(Long homeId); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ISpaceDeviceData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ISpaceDeviceData.java new file mode 100644 index 0000000..4488dc0 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ISpaceDeviceData.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.space.SpaceDevice; + +import java.util.List; + +public interface ISpaceDeviceData extends ICommonData { + + List findByHomeIdAndCollect(Long homeId,boolean collect); + + List findByHomeId(Long homeId); + + List findBySpaceId(Long spaceId); + + SpaceDevice findByDeviceId(String deviceId); + + void deleteAllBySpaceId(Long spaceId); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ITaskInfoData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ITaskInfoData.java new file mode 100644 index 0000000..2f2ac6f --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ITaskInfoData.java @@ -0,0 +1,30 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.IOwnedData; +import cc.iotkit.model.rule.TaskInfo; + +public interface ITaskInfoData extends IOwnedData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IThingModelData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IThingModelData.java new file mode 100644 index 0000000..858b764 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IThingModelData.java @@ -0,0 +1,32 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.product.ThingModel; + +public interface IThingModelData extends ICommonData { + + ThingModel findByProductKey(String productKey); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IUserInfoData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IUserInfoData.java new file mode 100644 index 0000000..af26b82 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IUserInfoData.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.UserInfo; + +import java.util.List; + +public interface IUserInfoData extends ICommonData { + + UserInfo findByUid(String uid); + + List findByType(int type); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IVirtualDeviceData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IVirtualDeviceData.java new file mode 100644 index 0000000..7f501f8 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IVirtualDeviceData.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.IOwnedData; +import cc.iotkit.model.alert.AlertConfig; +import cc.iotkit.model.device.VirtualDevice; + +import java.util.List; + +public interface IVirtualDeviceData extends IOwnedData { + + Paging findByUid(String uid, int size, int page); + + List findByUidAndState(String uid, String state); + + List findByTriggerAndState(String trigger, String state); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IWorderData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IWorderData.java new file mode 100644 index 0000000..5b82c8d --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IWorderData.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.manager; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import cc.iotkit.model.worder.WorderDO; + + +public interface IWorderData extends ICommonData { + + + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysAppData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysAppData.java new file mode 100644 index 0000000..a06fa6a --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysAppData.java @@ -0,0 +1,39 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysApp; + +/** + * 数据接口 + * + * @author Lion Li + * @date 2023-08-10 + */ +public interface ISysAppData extends ICommonData { + + SysApp findByAppId(String appId); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysConfigData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysConfigData.java new file mode 100644 index 0000000..546f8b3 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysConfigData.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysConfig; + +/** + * 系统配置数据接口 + * + * @author sjg + */ +public interface ISysConfigData extends ICommonData { + + SysConfig findByConfigKey(String configKey); + + Paging findAllByConditions(PageRequest pageRequest); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDeptData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDeptData.java new file mode 100644 index 0000000..6774ea6 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDeptData.java @@ -0,0 +1,78 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysDept; + +import java.util.List; + +/** + * 部门数据接口 + * + * @author sjg + */ +public interface ISysDeptData extends ICommonData { + + + + + /** + * 复合备件查询 + * + * @param dept dept + * @return list + */ + List findDepts(SysDept dept); + + /** + * 根据角色ID查询部门树信息 + * + * @param roleId 角色ID + * @return 选中部门列表 + */ + List findByRoleId(Long roleId); + + /** + * 根据ID查询所有子部门数(正常状态) + * + * @param parentId 部门ID + * @return 子部门数 + */ + long countByParentId(Long parentId); + + /** + * 根据ID查询所有子部门数(所有状态) + * + * @param deptId 部门ID + * @return 部门列表 + */ + List findByDeptId(Long deptId); + + + boolean checkDeptNameUnique(String deptName, Long parentId, Long deptId); + + long selectNormalChildrenDeptById(Long deptId); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDictData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDictData.java new file mode 100644 index 0000000..bef250e --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDictData.java @@ -0,0 +1,70 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysDictData; + +import java.util.List; + +/** + * 字典数据接口 + * + * @author sjg + */ +public interface ISysDictData extends ICommonData { + + /** + * 按条件查询 + */ + List findByConditions(SysDictData query); + + + + /** + * 根据字典类型和字典键值查询字典数据信息 + * + * @param dictType 字典类型 + * @param dictValue 字典键值 + * @return 字典标签 + */ + SysDictData findByDictTypeAndDictValue(String dictType, String dictValue); + + /** + * 根据字典类型查询字典数据 + * + * @param dictType 字典类型 + * @return 字典数据集合信息 + */ + List findByDicType(String dictType); + + /** + * 根据字典类型查询字典数据数量 + * + * @param dictType 字典类型 + * @return 字典数据集合信息 + */ + long countByDicType(String dictType); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDictTypeData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDictTypeData.java new file mode 100644 index 0000000..4f2b5ea --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDictTypeData.java @@ -0,0 +1,66 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysDictType; + +import java.util.List; + +/** + * 字典类型数据接口 + * + * @author sjg + */ +public interface ISysDictTypeData extends ICommonData { + + /** + * 按条件查询 + */ + List findByConditions(SysDictType cond); + + /** + * 按条件分页查询 + */ + Paging findByConditions(SysDictType cond, int page, int size); + + /** + * 根据字典类型查询信息 + * + * @param dictType 字典类型 + * @return 字典类型 + */ + SysDictType findByDicType(String dictType); + + /** + * 修改字典类型 + * + * @param dictType 类型 + * @param newType 新类型 + */ + void updateDicType(String dictType, String newType); + + boolean checkDictTypeUnique(SysDictType dictType); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysLogininforData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysLogininforData.java new file mode 100644 index 0000000..ddc19d7 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysLogininforData.java @@ -0,0 +1,60 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.system.SysLoginInfo; + +import java.util.List; + +/** + * 登录记录数据接口 + * + * @author sjg + */ +public interface ISysLogininforData extends ICommonData { + + /** + * 按条件查询 + */ + List findByConditions(SysLoginInfo cond); + + /** + * 按条件分页查询 + */ + Paging findByConditions(SysLoginInfo cond, int page, int size); + + /** + * 按租户清除登录日志 + * + * @param tenantId 租户id + */ + void deleteByTenantId(Long tenantId); + + /** + * 清除所有 + */ + void deleteAll(); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysMenuData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysMenuData.java new file mode 100644 index 0000000..d6278e4 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysMenuData.java @@ -0,0 +1,73 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysMenu; + +import java.util.List; + +/** + * 菜单数据接口 + * + * @author sjg + */ +public interface ISysMenuData extends ICommonData { + + /** + * 根据用户查询系统菜单列表 + * + * @param userId 用户ID + * @return 菜单列表 + */ + List selectMenuList(SysMenu menu, Long userId, boolean isSuperAdmin); + + List selectMenuPermsByUserId(Long userId); + + List selectMenuPermsByRoleId(Long roleId); + + /** + * 根据用户ID查询菜单 + * + * @return 菜单列表 + */ + List selectMenuTreeAll(); + + /** + * 根据用户ID查询菜单 + * + * @param userId 用户ID + * @return 菜单列表 + */ + List selectMenuTreeByUserId(Long userId); + + boolean hasChildByMenuId(Long menuId); + + boolean checkMenuNameUnique(SysMenu menu); + + + List selectParentIdByMenuIds(List menuIds); + + List findByMenuIdListAndNotParentIdList(List menuIds, List parentIds); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysNoticeData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysNoticeData.java new file mode 100644 index 0000000..d0eba8e --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysNoticeData.java @@ -0,0 +1,43 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.data.ICommonData; +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.system.SysNotice; + +/** + * 通知数据接口 + * + * @author sjg + */ +public interface ISysNoticeData extends ICommonData { + + /** + * 按条件分页查询 + */ + Paging findByConditions(PageRequest pageRequest); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOperLogData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOperLogData.java new file mode 100644 index 0000000..30d3b18 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOperLogData.java @@ -0,0 +1,51 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysOperLog; + +/** + * 操作日志数据接口 + * + * @author sjg + */ +public interface ISysOperLogData extends ICommonData { + + /** + * 按条件分页查询 + */ + Paging findByConditions(Long tenantId, String title, Integer businessType, + Integer status, int page, int size); + + /** + * 按租户清除日志 + * + * @param tenantId 租户id + */ + void deleteByTenantId(Long tenantId); + + void deleteAll(); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOssConfigData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOssConfigData.java new file mode 100644 index 0000000..0d60b61 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOssConfigData.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysOssConfig; + +/** + * 操作日志数据接口 + * + * @author sjg + */ +public interface ISysOssConfigData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOssData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOssData.java new file mode 100644 index 0000000..89bc728 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOssData.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysOss; + +/** + * 操作日志数据接口 + * + * @author sjg + */ +public interface ISysOssData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysPostData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysPostData.java new file mode 100644 index 0000000..488de7e --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysPostData.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysPost; + +import java.util.List; + +/** + * 操作日志数据接口 + * + * @author sjg + */ +public interface ISysPostData extends ICommonData { + List selectPostListByUserId(Long userId); + + List selectPostList(SysPost post); + + boolean checkPostNameUnique(SysPost post); + + boolean checkPostCodeUnique(SysPost post); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleData.java new file mode 100644 index 0000000..02591e2 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleData.java @@ -0,0 +1,88 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysRole; + +import java.util.List; + +/** + * 操作日志数据接口 + * + * @author sjg + */ +public interface ISysRoleData extends ICommonData { + + /** + * 根据角色ID查询菜单树信息 + * + * @param roleId 角色ID + * @return 选中菜单列表 + */ + List selectMenuListByRoleId(Long roleId, boolean menuCheckStrictly); + + /** + * 根据用户ID查询角色 + * + * @param userId 用户ID + * @return 角色列表 + */ + List selectRolePermissionByUserId(Long userId); + + /** + * 根据用户ID获取角色选择框列表 + * + * @param userId 用户ID + * @return 选中角色ID列表 + */ + List selectRoleListByUserId(Long userId); + + /** + * 校验角色名称是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + boolean checkRoleNameUnique(SysRole role); + + /** + * 校验角色权限是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + boolean checkRoleKeyUnique(SysRole role); + /** + * 修改角色状态 + * + * @param role 角色信息 + * @return 结果 + */ + int updateById(SysRole role); + + List selectRoleList(SysRole role); + + List findByUserId(Long id); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleDeptData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleDeptData.java new file mode 100644 index 0000000..35c05e9 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleDeptData.java @@ -0,0 +1,43 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysRoleDept; + +import java.util.Collection; +import java.util.List; + +/** + * 操作日志数据接口 + * + * @author sjg + */ +public interface ISysRoleDeptData extends ICommonData { + + void deleteByRoleId(Collection roleIds); + + long insertBatch(List list); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleMenuData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleMenuData.java new file mode 100644 index 0000000..d75426b --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleMenuData.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysRoleMenu; + +import java.util.Collection; +import java.util.List; + +/** + * 操作日志数据接口 + * + * @author sjg + */ +public interface ISysRoleMenuData extends ICommonData { + boolean checkMenuExistRole(Long menuId); + + long insertBatch(List list); + + long deleteByRoleId(Collection ids); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantData.java new file mode 100644 index 0000000..cc06967 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantData.java @@ -0,0 +1,38 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysTenant; + +/** + * 租户数据接口 + * + * @author tfd + */ +public interface ISysTenantData extends ICommonData { + + boolean checkCompanyNameUnique(SysTenant to); + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantPackageData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantPackageData.java new file mode 100644 index 0000000..893363f --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantPackageData.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysTenantPackage; + +/** + * 操作日志数据接口 + * + * @author sjg + */ +public interface ISysTenantPackageData extends ICommonData { +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserAreaData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserAreaData.java new file mode 100644 index 0000000..560e75b --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserAreaData.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysUser; +import cc.iotkit.model.system.SysUserArea; + +/** + * 用户数据接口 + * + * @author sjg + */ +public interface ISysUserAreaData extends ICommonData { + + +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserData.java new file mode 100644 index 0000000..eda7b73 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserData.java @@ -0,0 +1,77 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysUser; + +/** + * 用户数据接口 + * + * @author sjg + */ +public interface ISysUserData extends ICommonData { + + /** + * 按部门统计数量 + * + * @param deptId 部门id + * @return 数量 + */ + long countByDeptId(Long deptId); + + + boolean checkUserNameUnique(SysUser to); + + boolean checkPhoneUnique(SysUser to); + + boolean checkEmailUnique(SysUser to); + + SysUser selectByPhonenumber(String phonenumber); + + SysUser selectTenantUserByPhonenumber(String phonenumber, Long tenantId); + + SysUser selectTenantUserByEmail(String email, Long tenantId); + + SysUser selectUserByEmail(String email); + + SysUser selectTenantUserByUserName(String username, Long tenantId); + + SysUser selectUserByUserName(String username); + + + Paging selectAllocatedList(PageRequest to); + + String selectUserPostGroup(String userName); + + String selectUserRoleGroup(String userName); + + + + Paging selectUnallocatedList(PageRequest to); + + SysUser findByPhonenumber(String phonenumber); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserPostData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserPostData.java new file mode 100644 index 0000000..e823803 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserPostData.java @@ -0,0 +1,43 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysUserPost; + +/** + * 用户岗位数据接口 + * + * @author sjg + */ +public interface ISysUserPostData extends ICommonData { + + /** + * 按用户id删除数据 + * + * @param userId 用户id + * @return 数量 + */ + int deleteByUserId(Long userId); +} diff --git a/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserRoleData.java b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserRoleData.java new file mode 100644 index 0000000..d80fe74 --- /dev/null +++ b/iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserRoleData.java @@ -0,0 +1,56 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.system; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.system.SysUserRole; + +import java.util.List; + +/** + * 用户角色数据接口 + * + * @author sjg + */ +public interface ISysUserRoleData extends ICommonData { + /** + * 按用户id删除数据 + * + * @param userId 用户id + * @return 数量 + */ + int deleteByUserId(Long userId); + + /** + * 通过角色ID查询角色使用数量 + * + * @param roleId 角色ID + * @return 结果 + */ + long countUserRoleByRoleId(Long roleId); + + long delete(Long roleId, List userIds); + + long insertBatch(List list); +} diff --git a/iot-dao/iot-data-serviceImpl-cache/pom.xml b/iot-dao/iot-data-serviceImpl-cache/pom.xml new file mode 100644 index 0000000..b8c54c2 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/pom.xml @@ -0,0 +1,64 @@ + + + + iot-dao + cc.iotkit + 0.5.3 + + 4.0.0 + 0.5.3 + iot-data-serviceImpl-cache + + + + + cc.iotkit + iot-common-core + + + + cc.iotkit + iot-common-redis + + + + cc.iotkit + iot-data-model + + + + cc.iotkit + iot-data-service + + + + + + org.springframework + spring-context + + + + org.springframework.boot + spring-boot-starter-cache + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + + + \ No newline at end of file diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/CategoryCacheEvict.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/CategoryCacheEvict.java new file mode 100644 index 0000000..ae19b6a --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/CategoryCacheEvict.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.cache; + +import cc.iotkit.common.constant.Constants; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.stereotype.Component; + +@Component +public class CategoryCacheEvict { + + @CacheEvict(value = Constants.CACHE_CATEGORY, key = "#root.method.name+#s") + public void findById(String s) { + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCacheEvict.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCacheEvict.java new file mode 100644 index 0000000..69852b6 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCacheEvict.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.cache; + +import cc.iotkit.common.constant.Constants; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.stereotype.Component; + +@Component +public class DeviceInfoCacheEvict { + + @CacheEvict(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#deviceId") + public void findByDeviceId(String deviceId) { + } + + @CacheEvict(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#deviceName") + public void findByDeviceName(String deviceName) { + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCachePut.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCachePut.java new file mode 100644 index 0000000..f8f8e31 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCachePut.java @@ -0,0 +1,50 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.cache; + +import cc.iotkit.common.constant.Constants; +import cc.iotkit.model.device.DeviceInfo; +import org.springframework.cache.annotation.CachePut; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class DeviceInfoCachePut { + + @CachePut(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#deviceId") + public DeviceInfo findByDeviceId(String deviceId, DeviceInfo deviceInfo) { + return deviceInfo; + } + + @CachePut(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#deviceName") + public DeviceInfo findByDeviceName(String deviceName, DeviceInfo deviceInfo) { + return deviceInfo; + } + + @CachePut(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#parentId") + public List findSubDeviceIds(String parentId, List subDeviceIds) { + return subDeviceIds; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/OauthClientCacheEvict.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/OauthClientCacheEvict.java new file mode 100644 index 0000000..cbf9bf9 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/OauthClientCacheEvict.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.cache; + +import cc.iotkit.common.constant.Constants; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.stereotype.Component; + +@Component +public class OauthClientCacheEvict { + + @CacheEvict(value = Constants.CACHE_OAUTH_CLIENT, key = "#root.method.name+#clientId") + public void findByClientId(String clientId) { + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ProductCacheEvict.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ProductCacheEvict.java new file mode 100644 index 0000000..4c7b672 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ProductCacheEvict.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.cache; + +import cc.iotkit.common.constant.Constants; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.stereotype.Component; + +@Component +public class ProductCacheEvict { + + @CacheEvict(value = Constants.CACHE_PRODUCT, key = "#root.method.name+#id") + public void findById(Long id) { + } + + @CacheEvict(value = Constants.CACHE_PRODUCT, key = "#root.method.name+#productKey") + public void findByProductKey(String productKey) { + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ProductModelCacheEvict.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ProductModelCacheEvict.java new file mode 100644 index 0000000..6952e70 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ProductModelCacheEvict.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.cache; + +import cc.iotkit.common.constant.Constants; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.stereotype.Component; + +@Component +public class ProductModelCacheEvict { + + @CacheEvict(value = Constants.CACHE_PRODUCT_SCRIPT, key = "#root.method.name+#model") + public void findByModel(String model) { + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/SpaceCacheEvict.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/SpaceCacheEvict.java new file mode 100644 index 0000000..822a1d4 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/SpaceCacheEvict.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.cache; + +import cc.iotkit.common.constant.Constants; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.stereotype.Component; + +@Component +public class SpaceCacheEvict { + + @CacheEvict(value = Constants.CACHE_SPACE, key = "#root.method.name+#s") + public void findById(Long s) { + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ThingModelCacheEvict.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ThingModelCacheEvict.java new file mode 100644 index 0000000..d52153c --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ThingModelCacheEvict.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.cache; + +import cc.iotkit.common.constant.Constants; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.stereotype.Component; + +@Component +public class ThingModelCacheEvict { + + @CacheEvict(value = Constants.CACHE_THING_MODEL, key = "#root.method.name+#s") + public void findById(Long s) { + } + + @CacheEvict(value = Constants.CACHE_THING_MODEL, key = "#root.method.name+#productKey") + public void findByProductKey(String productKey){ + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/UserInfoCacheEvict.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/UserInfoCacheEvict.java new file mode 100644 index 0000000..fa18214 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/UserInfoCacheEvict.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.cache; + +import cc.iotkit.common.constant.Constants; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.stereotype.Component; + +@Component +public class UserInfoCacheEvict { + + @CacheEvict(value = Constants.CACHE_USER_INFO, key = "#root.method.name+#uid") + public void findByUid(String uid) { + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/config/CacheConfig.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/config/CacheConfig.java new file mode 100644 index 0000000..9928179 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/config/CacheConfig.java @@ -0,0 +1,61 @@ +///* +// * +---------------------------------------------------------------------- +// * | Copyright (c) 奇特物联 2021-2022 All rights reserved. +// * +---------------------------------------------------------------------- +// * | Licensed 未经许可不能去掉「奇特物联」相关版权 +// * +---------------------------------------------------------------------- +// * | Author: xw2sy@163.com +// * +---------------------------------------------------------------------- +// */ +//package cc.iotkit.data.config; +// +//import cc.iotkit.common.constant.Constants; +//import cc.iotkit.common.redis.manager.PlusSpringCacheManager; +//import org.springframework.cache.CacheManager; +//import org.springframework.cache.annotation.EnableCaching; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.data.redis.cache.RedisCacheConfiguration; +//import org.springframework.data.redis.cache.RedisCacheManager; +//import org.springframework.data.redis.connection.RedisConnectionFactory; +//import org.springframework.data.redis.serializer.RedisSerializationContext; +//import org.springframework.data.redis.serializer.RedisSerializer; +// +//import java.time.Duration; +//import java.util.Map; +//import java.util.Set; +// +//@Configuration +//@EnableCaching +//public class CacheConfig { +// +// @Bean +// public RedisCacheConfiguration getRedisCacheConfiguration() { +// RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig(); +// cacheConfiguration = cacheConfiguration.serializeValuesWith(RedisSerializationContext +// .SerializationPair.fromSerializer(RedisSerializer.json())); +// return cacheConfiguration; +// } +// +// @Bean +// public CacheManager cacheManager(RedisConnectionFactory factory, RedisCacheConfiguration config) { +// Set cacheNames = Set.of(Constants.CACHE_DEVICE_INFO, Constants.CACHE_DEVICE_STATS); +// Map cacheConfigs = Map.of( +// Constants.CACHE_DEVICE_INFO, config, +// Constants.CACHE_PRODUCT, config, +// Constants.CACHE_OAUTH_CLIENT, config, +// Constants.CACHE_CATEGORY, config, +// Constants.CACHE_THING_MODEL, config, +// Constants.CACHE_SPACE, config, +// Constants.CACHE_PRODUCT_SCRIPT, config, +// //统计缓存5分钟 +// Constants.CACHE_DEVICE_STATS, config.entryTtl(Duration.ofMinutes(5)) +// ); +// +// return RedisCacheManager.builder(factory) +// .initialCacheNames(cacheNames) +// .withInitialCacheConfigurations(cacheConfigs) +// .build(); +// } +// +//} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/CategoryDataCache.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/CategoryDataCache.java new file mode 100644 index 0000000..754d446 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/CategoryDataCache.java @@ -0,0 +1,108 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.data.cache.CategoryCacheEvict; +import cc.iotkit.data.manager.ICategoryData; +import cc.iotkit.model.product.Category; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +@Service +@Qualifier("categoryDataCache") +public class CategoryDataCache implements ICategoryData { + + @Autowired + private ICategoryData categoryData; + @Autowired + private CategoryCacheEvict categoryCacheEvict; + + @Override + @Cacheable(value = Constants.CACHE_CATEGORY, key = "#root.method.name+#s", unless = "#result == null") + public Category findById(String s) { + return categoryData.findById(s); + } + + @Override + public List findByIds(Collection id) { + return Collections.emptyList(); + } + + @Override + public Category save(Category data) { + data = categoryData.save(data); + categoryCacheEvict.findById(data.getId()); + return data; + } + + @Override + public void batchSave(List data) { + + } + + @Override + public void deleteById(String s) { + categoryData.deleteById(s); + } + + @Override + public void deleteByIds(Collection strings) { + + } + + @Override + public long count() { + return categoryData.count(); + } + + @Override + public List findAll() { + return categoryData.findAll(); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return categoryData.findAll(pageRequest); + } + + @Override + public List findAllByCondition(Category data) { + return Collections.emptyList(); + } + + @Override + public Category findOneByCondition(Category data) { + return null; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java new file mode 100644 index 0000000..251c3c8 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java @@ -0,0 +1,384 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.data.cache.DeviceInfoCacheEvict; +import cc.iotkit.data.cache.DeviceInfoCachePut; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DevicePropertyCache; +import cc.iotkit.model.stats.AlertStatDTO; +import cc.iotkit.model.stats.DataItem; +import cc.iotkit.model.stats.ProductKeyCountDTO; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.SmartInitializingSingleton; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; + +import java.util.*; + +@Service +@Qualifier("deviceInfoDataCache") +public class DeviceInfoDataCache implements IDeviceInfoData, SmartInitializingSingleton { + + @Autowired + private StringRedisTemplate redisTemplate; + + @Autowired + private DeviceInfoCachePut deviceInfoCachePut; + @Autowired + private DeviceInfoCacheEvict deviceInfoCacheEvict; + + @Autowired + private IDeviceInfoData deviceInfoData; + + + @Override + public void afterSingletonsInstantiated() { + if ("true".equals(System.getProperty("disabledEmbeddedRedis"))) { + return; + } + + //需要等待缓存初始化 + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + //内嵌redis每次启动需要重新装载缓存 + int page = 1; + Paging paged; + List parentIds = new ArrayList<>(); + PageRequest pageRequest = new PageRequest<>(); + pageRequest.setPageSize(1000); + pageRequest.setPageNum(page); + + while (!(paged = deviceInfoData.findAll(pageRequest)).getRows().isEmpty()) { + pageRequest.setPageNum(page++); + List devices = paged.getRows(); + for (DeviceInfo device : devices) { + //装载设备信息缓存 + deviceInfoCachePut.findByDeviceId(device.getDeviceId(), device); + deviceInfoCachePut.findByDeviceName(device.getDeviceName(), device); + String parentId = device.getParentId(); + if (StringUtils.isBlank(parentId)) { + parentIds.add(parentId); + } + } + } + //装载子设备id列表缓存 + for (String parentId : parentIds) { + putSubDeviceIds(parentId); + } + } + }, 100); + } + + private String getPropertyCacheKey(String deviceId) { + return String.format(Constants.PROPERTY_CACHE_KEY, deviceId); + } + + private String getLastTimeCacheKey(String deviceId) { + return String.format(Constants.LAST_TIME_CACHE_KEY, deviceId); + } + + + @Override + public void saveProperties(String deviceId, Map properties) { + Map old = getProperties(deviceId); + old.putAll(properties); + long updateTime = System.currentTimeMillis(); + redisTemplate.opsForValue().set(getPropertyCacheKey(deviceId), + JsonUtils.toJsonString(new PropertyCacheInfo(updateTime, old)) + ); + } + @Override + public List getDeviceRecord() { + return deviceInfoData.getDeviceRecord(); + } + /** + * 清除设备属性缓存 + */ + private void clearProperties(String deviceId) { + redisTemplate.delete(getPropertyCacheKey(deviceId)); + } + + @Override + public Map getProperties(String deviceId) { + return getPropertyCacheInfo(deviceId).getProperties(); + } + @Override + public List getProductDevice(Long deptAreaId,String startDate, String endDate){ + + return deviceInfoData.getProductDevice(deptAreaId,startDate,endDate); + } + private PropertyCacheInfo getPropertyCacheInfo(String deviceId) { + String json = redisTemplate.opsForValue().get(getPropertyCacheKey(deviceId)); + if (StringUtils.isBlank(json)) { + return new PropertyCacheInfo(0, new HashMap<>()); + } + return JsonUtils.parseObject(json, new TypeReference<>() { + }); + } + + @Override + public long getPropertyUpdateTime(String deviceId) { + return getPropertyCacheInfo(deviceId).getUpdateTime(); + } + + @Override + public long getLastTime(String deviceId) { + String last = redisTemplate.opsForValue().get( getLastTimeCacheKey(deviceId)); + if(StringUtils.isBlank(last)){ + return 0L; + } + return Long.valueOf(last); + } + + @Override + public void setLastTime(String deviceId, long lastTime) { + redisTemplate.opsForValue().set(getLastTimeCacheKey(deviceId), String.valueOf(lastTime)); + } + + @Override + @Cacheable(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#deviceId", unless = "#result == null") + public DeviceInfo findByDeviceId(String deviceId) { + return deviceInfoData.findByDeviceId(deviceId); + } + + @Override + @Cacheable(value = Constants.CACHE_DEVICE_INFO, key = "#root.method.name+#deviceName", unless = "#result == null") + public DeviceInfo findByDeviceName(String deviceName) { + return deviceInfoData.findByDeviceName(deviceName); + } + + @Override + public List findByParentId(String parentId) { + return deviceInfoData.findByParentId(parentId); + } + + @Override + public List findByConditionsList(String productKey) { + return deviceInfoData.findByConditionsList(productKey); + } + + @Override + public List findByProductNodeType(String uid) { + return deviceInfoData.findByProductNodeType(uid); + } + + @Override + public boolean existByProductKey(String productKey) { + return deviceInfoData.existByProductKey(productKey); + } + + @Override + public List findNeverUsedDevices() { + return deviceInfoData.findNeverUsedDevices(); + } + + @Override + public List findSubDeviceIds(String parentId) { + return deviceInfoData.findSubDeviceIds(parentId); + } + + @Override + public Paging findByConditions(String uid, String subUid, String productKey, + String groupId, Boolean state, String keyword, int page, int size,Long deptAreaId) { + return deviceInfoData.findByConditions(uid, subUid, productKey, groupId, state, keyword, page, size,deptAreaId); + } + + @Override + public void updateTag(String deviceId, DeviceInfo.Tag tag) { + deviceInfoData.updateTag(deviceId, tag); + DeviceInfo data = deviceInfoData.findByDeviceId(deviceId); + putDeviceInfo(data); + } + + @Override + @Cacheable(value = Constants.CACHE_DEVICE_STATS, key = "#root.method.name+#uid", unless = "#result == null") + public List getDeviceStatsByCategory(String uid) { + return deviceInfoData.getDeviceStatsByCategory(uid); + } + + @Override + public long countByGroupId(String groupId) { + return deviceInfoData.countByGroupId(groupId); + } + + @Override + public void addToGroup(String deviceId, DeviceInfo.Group group) { + deviceInfoData.addToGroup(deviceId, group); + DeviceInfo data = deviceInfoData.findByDeviceId(deviceId); + putDeviceInfo(data); + } + + @Override + public void updateGroup(String groupId, DeviceInfo.Group group) { + deviceInfoData.updateGroup(groupId, group); + } + + @Override + public void removeGroup(String deviceId, String groupId) { + deviceInfoData.removeGroup(deviceId, groupId); + DeviceInfo data = deviceInfoData.findByDeviceId(deviceId); + putDeviceInfo(data); + } + + @Override + public void removeGroup(String groupId) { + deviceInfoData.removeGroup(groupId); + } + + @Override + public List findByUid(String uid) { + return deviceInfoData.findByUid(uid); + } + + @Override + public Paging findByUid(String uid, int page, int size) { + return deviceInfoData.findByUid(uid, page, size); + } + + @Override + public long countByUid(String uid) { + return deviceInfoData.countByUid(uid); + } + + @Override + public DeviceInfo findById(String s) { + return deviceInfoData.findById(s); + } + + @Override + public List findByIds(Collection ids) { + return deviceInfoData.findByIds(ids); + } + + @Override + public DeviceInfo save(DeviceInfo data) { + DeviceInfo r = deviceInfoData.save(data); + //更新设备信息缓存 + putDeviceInfo(data); + //更新子设备列表缓存 + putSubDeviceIds(data.getParentId()); + return r; + } + + @Override + public void batchSave(List data) { + + } + + @Override + public void deleteById(String s) { + DeviceInfo device = deviceInfoData.findById(s); + deviceInfoData.deleteById(s); + //清除缓存 + deviceInfoCacheEvict.findByDeviceId(device.getDeviceId()); + deviceInfoCacheEvict.findByDeviceName(device.getDeviceName()); + //清除属性缓存 + clearProperties(device.getDeviceId()); + //更新子设备列表缓存 + putSubDeviceIds(device.getParentId()); + } + + @Override + public void deleteByIds(Collection ids) { + List deviceInfos = deviceInfoData.findByIds(ids); + deviceInfos.forEach(device -> { + deviceInfoCacheEvict.findByDeviceId(device.getDeviceId()); + deviceInfoCacheEvict.findByDeviceName(device.getDeviceName()); + //清除属性缓存 + clearProperties(device.getDeviceId()); + //更新子设备列表缓存 + putSubDeviceIds(device.getParentId()); + }); + deviceInfoData.deleteByIds(ids); + } + + @Override + public long count() { + return deviceInfoData.count(); + } + + @Override + public List findAll() { + return deviceInfoData.findAll(); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return deviceInfoData.findAll(pageRequest); + } + + @Override + public List findAllByCondition(DeviceInfo data) { + return deviceInfoData.findAllByCondition(data); + } + + @Override + public DeviceInfo findOneByCondition(DeviceInfo data) { + return null; + } + + /** + * 更新缓存 + */ + private void putDeviceInfo(DeviceInfo data) { + deviceInfoCachePut.findByDeviceId(data.getDeviceId(), data); + deviceInfoCachePut.findByDeviceName(data.getDeviceName(), data); + } + + /** + * 更新子设备id列表 + */ + private void putSubDeviceIds(String parentId) { + if (StringUtils.isBlank(parentId)) { + return; + } + List subDeviceIds = deviceInfoData.findSubDeviceIds(parentId); + deviceInfoCachePut.findSubDeviceIds(parentId, subDeviceIds); + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + private static class PropertyCacheInfo { + + private long updateTime; + + private Map properties; + + } +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoPropertyDataCache.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoPropertyDataCache.java new file mode 100644 index 0000000..89c5515 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoPropertyDataCache.java @@ -0,0 +1,239 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DevicePropertyCache; +import cc.iotkit.model.stats.AlertStatDTO; +import cc.iotkit.model.stats.DataItem; +import cc.iotkit.model.stats.ProductKeyCountDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * 包含设备属性的设备信息缓存服务 + */ +@Service +@Qualifier("deviceInfoPropertyDataCache") +public class DeviceInfoPropertyDataCache implements IDeviceInfoData { + + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + + + @Override + public DeviceInfo findById(String s) { + return deviceInfoData.findById(s); + } + public List findByConditionsList(String productKey){ + return deviceInfoData.findByConditionsList(productKey); + } + @Override + public List findByIds(Collection id) { + return null; + } + + @Override + public DeviceInfo save(DeviceInfo data) { + return deviceInfoData.save(data); + } + + @Override + public void batchSave(List data) { + + } + + @Override + public void deleteById(String s) { + deviceInfoData.deleteById(s); + } + + @Override + public void deleteByIds(Collection ids) { + deviceInfoData.deleteByIds(ids); + } + + @Override + public long count() { + return deviceInfoData.count(); + } + + @Override + public List findAll() { + return deviceInfoData.findAll(); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return deviceInfoData.findAll(pageRequest); + } + + @Override + public List findAllByCondition(DeviceInfo data) { + return null; + } + + @Override + public DeviceInfo findOneByCondition(DeviceInfo data) { + return null; + } + + @Override + public void saveProperties(String deviceId, Map properties) { + deviceInfoData.saveProperties(deviceId, properties); + } + + @Override + public Map getProperties(String deviceId) { + return deviceInfoData.getProperties(deviceId); + } + + @Override + public long getPropertyUpdateTime(String deviceId) { + return deviceInfoData.getPropertyUpdateTime(deviceId); + } + + @Override + public long getLastTime(String deviceId) { + return deviceInfoData.getLastTime(deviceId); + } + + @Override + public void setLastTime(String deviceId, long lastTime) { + deviceInfoData.setLastTime(deviceId, lastTime); + } + + @Override + public DeviceInfo findByDeviceId(String deviceId) { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + deviceInfo.setProperty(getProperties(deviceId)); + return deviceInfo; + } + + @Override + public DeviceInfo findByDeviceName(String deviceName) { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceName(deviceName); + if (deviceInfo == null) { + return null; + } + deviceInfo.setProperty(getProperties(deviceInfo.getDeviceId())); + return deviceInfo; + } + @Override + public List getDeviceRecord() { + return deviceInfoData.getDeviceRecord(); + } + @Override + public List findByParentId(String parentId) { + return deviceInfoData.findByParentId(parentId); + } + + @Override + public List findSubDeviceIds(String parentId) { + return deviceInfoData.findSubDeviceIds(parentId); + } + + @Override + public Paging findByConditions(String uid, String subUid, String productKey, String groupId, Boolean online, String keyword, int page, int size,Long deptAreaId) { + return deviceInfoData.findByConditions(uid, subUid, productKey, groupId, online, keyword, page, size,deptAreaId); + } + + @Override + public void updateTag(String deviceId, DeviceInfo.Tag tag) { + deviceInfoData.updateTag(deviceId, tag); + } + + @Override + public List getDeviceStatsByCategory(String uid) { + return deviceInfoData.getDeviceStatsByCategory(uid); + } + + @Override + public long countByGroupId(String groupId) { + return deviceInfoData.countByGroupId(groupId); + } + + @Override + public void addToGroup(String deviceId, DeviceInfo.Group group) { + deviceInfoData.addToGroup(deviceId, group); + } + + @Override + public void updateGroup(String groupId, DeviceInfo.Group group) { + deviceInfoData.updateGroup(groupId, group); + } + + @Override + public void removeGroup(String deviceId, String groupId) { + deviceInfoData.removeGroup(deviceId, groupId); + } + + @Override + public void removeGroup(String groupId) { + deviceInfoData.removeGroup(groupId); + } + + @Override + public List findByProductNodeType(String uid) { + return deviceInfoData.findByProductNodeType(uid); + } + + @Override + public boolean existByProductKey(String productKey) { + return deviceInfoData.existByProductKey(productKey); + } + + @Override + public List findNeverUsedDevices() { + return deviceInfoData.findNeverUsedDevices(); + } + + @Override + public List findByUid(String uid) { + return deviceInfoData.findByUid(uid); + } + + @Override + public Paging findByUid(String uid, int page, int size) { + return deviceInfoData.findByUid(uid, page, size); + } + @Override + public List getProductDevice(Long deptAreaId, String startDate, String endDate){ + + return deviceInfoData.getProductDevice(deptAreaId,startDate,endDate); + } + @Override + public long countByUid(String uid) { + return deviceInfoData.countByUid(uid); + } +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/OauthClientDataCache.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/OauthClientDataCache.java new file mode 100644 index 0000000..0c8b012 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/OauthClientDataCache.java @@ -0,0 +1,113 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.data.cache.OauthClientCacheEvict; +import cc.iotkit.data.manager.IOauthClientData; +import cc.iotkit.model.OauthClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +@Service +@Qualifier("oauthClientDataCache") +public class OauthClientDataCache implements IOauthClientData { + + @Autowired + private IOauthClientData oauthClientData; + @Autowired + private OauthClientCacheEvict oauthClientCacheEvict; + + @Override + @Cacheable(value = Constants.CACHE_OAUTH_CLIENT, key = "#root.method.name+#clientId", unless = "#result == null") + public OauthClient findByClientId(String clientId) { + return oauthClientData.findByClientId(clientId); + } + + @Override + public OauthClient findById(String s) { + return oauthClientData.findById(s); + } + + @Override + public List findByIds(Collection id) { + return Collections.emptyList(); + } + + @Override + public OauthClient save(OauthClient data) { + OauthClient oauthClient = oauthClientData.save(data); + //清除缓存 + oauthClientCacheEvict.findByClientId(data.getClientId()); + return oauthClient; + } + + @Override + public void batchSave(List data) { + + } + + @Override + public void deleteById(String s) { + oauthClientData.deleteById(s); + } + + @Override + public void deleteByIds(Collection strings) { + + } + + @Override + public long count() { + return oauthClientData.count(); + } + + @Override + public List findAll() { + return oauthClientData.findAll(); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return oauthClientData.findAll(pageRequest); + } + + @Override + public List findAllByCondition(OauthClient data) { + return Collections.emptyList(); + } + + @Override + public OauthClient findOneByCondition(OauthClient data) { + return null; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ProductDataCache.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ProductDataCache.java new file mode 100644 index 0000000..5846d0e --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ProductDataCache.java @@ -0,0 +1,145 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.data.cache.ProductCacheEvict; +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.product.Product; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; + +@Service +@Qualifier("productDataCache") +public class ProductDataCache implements IProductData { + + @Autowired + private IProductData productData; + @Autowired + private ProductCacheEvict productCacheEvict; + + @Override + public List findByCategory(String category) { + return productData.findByCategory(category); + } + + @Override + @Cacheable(value = Constants.CACHE_PRODUCT, key = "#root.method.name+#productKey", unless = "#result == null") + public Product findByProductKey(String productKey) { + return productData.findByProductKey(productKey); + } + + @Override + @Cacheable(value = Constants.CACHE_PRODUCT, key = "#root.method.name+#productKey", unless = "#result == null") + public void delByProductKey(String productKey) { + + } + +// @Override +// public List findByUid(String uid) { +// return productData.findByUid(uid); +// } + +// @Override +// public Paging findByUid(String uid, int page, int size) { +// return productData.findByUid(uid, page, size); +// } + +// @Override +// public long countByUid(String uid) { +// return productData.countByUid(uid); +// } + + @Override + @Cacheable(value = Constants.CACHE_PRODUCT, key = "#root.method.name+#s", unless = "#result == null") + @Deprecated + public Product findById(Long s) { + return productData.findById(s); + } + + @Override + public List findByIds(Collection id) { + return null; + } + + @Override + public Product save(Product data) { + Product p = productData.save(data); + //清除缓存 + productCacheEvict.findById(p.getId()); + productCacheEvict.findByProductKey(p.getProductKey()); + return p; + } + + @Override + public void batchSave(List data) { + + } + + @Override + public void deleteById(Long s) { + Product product = findById(s); + delByProductKey(product.getProductKey()); + productData.deleteById(s); + //清除缓存 + productCacheEvict.findById(s); + } + + @Override + public void deleteByIds(Collection ids) { + + } + + @Override + public long count() { + return productData.count(); + } + + @Override + public List findAll() { + return productData.findAll(); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return productData.findAll(pageRequest); + } + + @Override + public List findAllByCondition(Product data) { + return null; + } + + @Override + public Product findOneByCondition(Product data) { + return null; + } +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ProductModelDataCache.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ProductModelDataCache.java new file mode 100644 index 0000000..fb47fea --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ProductModelDataCache.java @@ -0,0 +1,117 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.data.manager.IProductModelData; +import cc.iotkit.data.cache.ProductModelCacheEvict; +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.product.ProductModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; + +@Service +@Qualifier("productModelDataCache") +public class ProductModelDataCache implements IProductModelData { + + @Autowired + private IProductModelData productModelData; + @Autowired + private ProductModelCacheEvict productModelCacheEvict; + + @Override + @Cacheable(value = Constants.CACHE_PRODUCT_SCRIPT, key = "#root.method.name+#model", unless = "#result == null") + public ProductModel findByModel(String model) { + return productModelData.findByModel(model); + } + + @Override + public List findByProductKey(String productKey) { + return productModelData.findByProductKey(productKey); + } + + @Override + public ProductModel findById(String s) { + return productModelData.findById(s); + } + + @Override + public List findByIds(Collection id) { + return null; + } + + @Override + public ProductModel save(ProductModel data) { + ProductModel productModel = productModelData.save(data); + productModelCacheEvict.findByModel(data.getModel()); + return productModel; + } + + @Override + public void batchSave(List data) { + + } + + @Override + public void deleteById(String s) { + productModelData.deleteById(s); + } + + @Override + public void deleteByIds(Collection strings) { + + } + + @Override + public long count() { + return productModelData.count(); + } + + @Override + public List findAll() { + return productModelData.findAll(); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return productModelData.findAll(pageRequest); + } + + @Override + public List findAllByCondition(ProductModel data) { + return null; + } + + @Override + public ProductModel findOneByCondition(ProductModel data) { + return null; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/SpaceDataCache.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/SpaceDataCache.java new file mode 100644 index 0000000..e464279 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/SpaceDataCache.java @@ -0,0 +1,112 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.data.cache.SpaceCacheEvict; +import cc.iotkit.data.manager.ISpaceData; +import cc.iotkit.model.space.Space; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; + +@Service +@Qualifier("spaceDataCache") +public class SpaceDataCache implements ISpaceData { + + @Autowired + private ISpaceData spaceData; + @Autowired + private SpaceCacheEvict spaceCacheEvict; + + @Override + public List findByHomeId(Long homeId) { + return spaceData.findByHomeId(homeId); + } + + @Override + @Cacheable(value = Constants.CACHE_SPACE, key = "#root.method.name+#s", unless = "#result == null") + public Space findById(Long s) { + return spaceData.findById(s); + } + + @Override + public List findByIds(Collection id) { + return null; + } + + @Override + public Space save(Space data) { + data = spaceData.save(data); + spaceCacheEvict.findById(data.getId()); + return data; + } + + @Override + public void batchSave(List data) { + + } + + @Override + public void deleteById(Long s) { + spaceData.deleteById(s); + } + + @Override + public void deleteByIds(Collection strings) { + + } + + @Override + public long count() { + return spaceData.count(); + } + + @Override + public List findAll() { + return spaceData.findAll(); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return spaceData.findAll(pageRequest); + } + + @Override + public List findAllByCondition(Space data) { + return null; + } + + @Override + public Space findOneByCondition(Space data) { + return null; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ThingModelDataCache.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ThingModelDataCache.java new file mode 100644 index 0000000..6a7ed59 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ThingModelDataCache.java @@ -0,0 +1,114 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.data.manager.IThingModelData; +import cc.iotkit.data.cache.ThingModelCacheEvict; +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.product.ThingModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; + +@Service +@Qualifier("thingModelDataCache") +public class ThingModelDataCache implements IThingModelData { + + @Autowired + private IThingModelData thingModelData; + @Autowired + private ThingModelCacheEvict thingModelCacheEvict; + + @Override + @Cacheable(value = Constants.CACHE_THING_MODEL, key = "#root.method.name+#s", unless = "#result == null") + public ThingModel findById(Long s) { + return thingModelData.findById(s); + } + + @Override + public List findByIds(Collection id) { + return null; + } + + @Override + public ThingModel save(ThingModel data) { + data = thingModelData.save(data); + thingModelCacheEvict.findById(data.getId()); + thingModelCacheEvict.findByProductKey(data.getProductKey()); + return data; + } + + @Override + public void batchSave(List data) { + + } + + @Override + public void deleteById(Long s) { + thingModelData.deleteById(s); + thingModelCacheEvict.findById(s); + } + + @Override + public void deleteByIds(Collection ids) { + + } + + @Override + public long count() { + return thingModelData.count(); + } + + @Override + public List findAll() { + return thingModelData.findAll(); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return thingModelData.findAll(pageRequest); + } + + @Override + public List findAllByCondition(ThingModel data) { + return null; + } + + @Override + public ThingModel findOneByCondition(ThingModel data) { + return null; + } + + @Override + @Cacheable(value = Constants.CACHE_THING_MODEL, key = "#root.method.name+#productKey", unless = "#result == null") + public ThingModel findByProductKey(String productKey) { + return thingModelData.findByProductKey(productKey); + } +} diff --git a/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/UserInfoDataCache.java b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/UserInfoDataCache.java new file mode 100644 index 0000000..e4a86d5 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/UserInfoDataCache.java @@ -0,0 +1,118 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.data.cache.UserInfoCacheEvict; +import cc.iotkit.data.manager.IUserInfoData; +import cc.iotkit.model.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; + +@Service +@Qualifier("userInfoDataCache") +public class UserInfoDataCache implements IUserInfoData { + + @Autowired + private IUserInfoData userInfoData; + @Autowired + private UserInfoCacheEvict userInfoCacheEvict; + + @Override + @Cacheable(value = Constants.CACHE_USER_INFO, key = "#root.method.name+#uid", unless = "#result == null") + public UserInfo findByUid(String uid) { + return userInfoData.findByUid(uid); + } + + @Override + public List findByType(int type) { + return userInfoData.findByType(type); + } + + @Override + public UserInfo findById(Long s) { + return userInfoData.findById(s); + } + + @Override + public List findByIds(Collection id) { + return null; + } + + @Override + public UserInfo save(UserInfo data) { + UserInfo userInfo = userInfoData.save(data); + //清除缓存 + userInfoCacheEvict.findByUid(data.getUid()); + return userInfo; + } + + @Override + public void batchSave(List data) { + + } + + @Override + public void deleteById(Long s) { + userInfoData.deleteById(s); + } + + @Override + public void deleteByIds(Collection longs) { + + } + + @Override + public long count() { + return userInfoData.count(); + } + + @Override + public List findAll() { + return userInfoData.findAll(); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return userInfoData.findAll(pageRequest); + } + + @Override + public List findAllByCondition(UserInfo data) { + return null; + } + + @Override + public UserInfo findOneByCondition(UserInfo data) { + return null; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/pom.xml b/iot-dao/iot-data-serviceImpl-rdb/pom.xml new file mode 100644 index 0000000..fc6c916 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/pom.xml @@ -0,0 +1,171 @@ + + + + iot-dao + cc.iotkit + 0.5.3 + + 0.5.3 + 4.0.0 + iot-data-serviceImpl-rdb + + 关系型数据库的数据服务实现模块 + 如:h2、mysql,由jpa兼容不同数据库 + + + + + + cc.iotkit + iot-common-core + + + + cc.iotkit + iot-data-service + + + + cc.iotkit + iot-common-tenant + + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + + com.querydsl + querydsl-apt + + + com.querydsl + querydsl-jpa + + + com.github.yitter + yitter-idgenerator + + + + com.h2database + h2 + + + + mysql + mysql-connector-java + 8.0.32 + + + + + + + + + + cn.hutool + hutool-core + + + + io.github.linpeilie + mapstruct-plus-spring-boot-starter + + + + org.springframework.data + spring-data-commons + + + + + com.github.biyanwen + jpa-comment-spring-boot-starter + + + + org.projectlombok + lombok + provided + + + cc.iotkit + iot-common-satoken + + + org.apache.poi + poi + 5.2.3 + compile + + + org.apache.poi + poi + 5.2.3 + compile + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + org.projectlombok + lombok + ${lombok.version} + + + io.github.linpeilie + mapstruct-plus-processor + ${mapstruct-plus.version} + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + + + + + + + + com.mysema.maven + apt-maven-plugin + 1.1.3 + + + generate-sources + + process + + + target/generated-sources/java + com.querydsl.apt.jpa.JPAAnnotationProcessor + + + + + + + + + diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/AutoMapperConfig3.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/AutoMapperConfig3.java new file mode 100644 index 0000000..e076b54 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/AutoMapperConfig3.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.config; + +import io.github.linpeilie.annotations.MapperConfig; + +/** + * @Author: jay + * @Date: 2023/6/4 14:21 + * @Version: V1.0 + * @Description: mapperstruct 配置 + */ +@MapperConfig(adapterClassName = "dataAdapter") + +public class AutoMapperConfig3 { +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/DataFilter.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/DataFilter.java new file mode 100644 index 0000000..460cee8 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/DataFilter.java @@ -0,0 +1,9 @@ +package cc.iotkit.data.config; + +import java.lang.annotation.*; + +@Target({ElementType.PARAMETER, ElementType.METHOD})//注解放置的目标位置,METHOD是可注解在方法级别上 +@Retention(RetentionPolicy.RUNTIME) //注解在哪个阶段执行 +@Documented +public @interface DataFilter { +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JdbcTemplateConfig.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JdbcTemplateConfig.java new file mode 100644 index 0000000..dff15e7 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JdbcTemplateConfig.java @@ -0,0 +1,53 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.config; + + +import org.springframework.boot.autoconfigure.jdbc.JdbcProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.jdbc.core.JdbcTemplate; + +import javax.sql.DataSource; + +@Configuration( + proxyBeanMethods = false +) +class JdbcTemplateConfig { + + @Bean + @Primary + JdbcTemplate jdbcTemplate(DataSource dataSource, JdbcProperties properties) { + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + JdbcProperties.Template template = properties.getTemplate(); + jdbcTemplate.setFetchSize(template.getFetchSize()); + jdbcTemplate.setMaxRows(template.getMaxRows()); + if (template.getQueryTimeout() != null) { + jdbcTemplate.setQueryTimeout((int) template.getQueryTimeout().getSeconds()); + } + + return jdbcTemplate; + } +} \ No newline at end of file diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JpaConfig.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JpaConfig.java new file mode 100644 index 0000000..6bae73d --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JpaConfig.java @@ -0,0 +1,119 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.config; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.hibernate5.support.OpenSessionInViewFilter; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.JpaVendorAdapter; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * @Author: 石恒 + * @Date: 2023/5/28 16:58 + * @Description: + */ +@Configuration +@EnableTransactionManagement +public class JpaConfig { + + @Bean + public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) { + /* entityManager.unwrap(Session.class) + .enableFilter("tenantFilter") + .setParameter("tenantId", getCurrentTenantId());*/ + // entityManager.unwrap(Session.class).enableFilter("tenantFilter").setParameter("tenantId", getCurrentTenantId()); + return new JPAQueryFactory(entityManager); + } + + /* @Bean + public PlatformTransactionManager transactionManager(EntityManagerFactory emf) { + JpaTransactionManager txManager = new JpaTransactionManager(emf); + txManager.setEntityManagerInitializer(em -> { + em.unwrap(Session.class) + .enableFilter("tenantFilter") + .setParameter("tenantId", getCurrentTenantId()); + }); + return txManager; + }*/ + + /* @Bean + public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) { + // 启用租户过滤器 + entityManager.unwrap(Session.class) + .enableFilter("tenantFilter") + .setParameter("tenantId", getCurrentTenantId()); + return new JPAQueryFactory(entityManager); + }*/ + + + private Long getCurrentTenantId() { + // 实现获取当前租户 ID 的逻辑 + return 0L; // 示例,实际应从上下文中获取 + } + + /* @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { + LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(dataSource); + em.setPackagesToScan("cc.iotkit.data.model"); // 替换为您的实体类包名 + em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); + em.setJpaProperties(hibernateProperties()); + return em; + } + + private Properties hibernateProperties() { + Properties props = new Properties(); + props.put("hibernate.hbm2ddl.auto", "update"); + props.put("hibernate.show_sql", "true"); + return props; + } + + + private Long getCurrentTenantId() { + // 获取当前租户 ID 的逻辑 + return 0L; // 示例,实际应从上下文中获取 + }*/ +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/TenantAspect.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/TenantAspect.java new file mode 100644 index 0000000..cc09881 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/TenantAspect.java @@ -0,0 +1,105 @@ +package cc.iotkit.data.config; + +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.StringUtils; +import com.querydsl.core.types.Predicate; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.hibernate.Filter; +import org.hibernate.Session; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ObjectUtils; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; + +import static cn.dev33.satoken.SaManager.log; + +@Aspect +@Component +public class TenantAspect { + @PersistenceContext + private EntityManager entityManager; + /** + * 转换request 请求参数 + * + * @param paramMap request获取的参数数组 + */ + public Map converMap(Map paramMap) { + Map rtnMap = new HashMap(); + for (String key : paramMap.keySet()) { + rtnMap.put(key, paramMap.get(key)[0]); + } + return rtnMap; + } + + /*@Around("@annotation(dataFilter)") + @Transactional + public Object doProcess(ProceedingJoinPoint joinPoint, DataFilter dataFilter) throws Throwable { + System.out.println("进入切面了~~~~~~~~~~~"); + // 从获取RequestAttributes中获取HttpServletRequest的信息 + *//* HttpServletRequest request= (HttpServletRequest) RequestContextHolder.getRequestAttributes().resolveReference(RequestAttributes.REFERENCE_REQUEST); + Map rtnMap = converMap(request.getParameterMap()); + String tenantId = rtnMap.get("tenantId");*//* + + try { + Long tenantId = 111L; + Session session = entityManager.unwrap(Session.class); + //!自定义的属性名属性值名,设置值,该值可以是集合类型,可以是基本类型,这里是集合类型 + session.enableFilter("tenantId").setParameter("tenantFilter", tenantId); + return joinPoint.proceed(); + } catch (Throwable ex) { + System.out.println("出错了::"); + ex.printStackTrace(); + throw ex; + } finally { + System.out.println("最终关闭过滤器"); + entityManager.unwrap(Session.class).disableFilter("tenantId"); + + } + }*/ + + @Around("execution(* org.springframework.data.jpa.repository.JpaRepository+.*(..)) || " + + "execution(* org.springframework.data.repository.query.QueryByExampleExecutor+.*(..))") + public Object applyTenantFilter(ProceedingJoinPoint pjp) throws Throwable { + // System.out.println("111111111111Thread" + TenantContext.isFilterDisabled()); + if(LoginHelper.isSuperAdmin()){ + return pjp.proceed(); // 跳过租户过滤 + // TenantContext.disableTenantFilter(); + } + if(TenantContext.isFilterDisabled()) { + return pjp.proceed(); // 跳过租户过滤 + } + //放开租户 + Long tenantId= LoginHelper.getTenantId(); + // Long tenantId = 0L; // 实现租户ID获取逻辑 + if(ObjectUtils.isEmpty(tenantId)){ + tenantId = 0L; + } + try { + entityManager.unwrap(Session.class) + .enableFilter("tenantFilter") + .setParameter("tenantId", tenantId); + return pjp.proceed(); + } finally { + entityManager.unwrap(Session.class).disableFilter("tenantFilter"); + } + } + + /* @AfterReturning("execution(* org.springframework.data.jpa.repository.JpaRepository+.*(..)) || " + + "execution(* org.springframework.data.repository.query.QueryByExampleExecutor+.*(..))") + public void cleanup() { + TenantContext.enableTenantFilter(); // 确保状态重置 + }*/ + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/TenantAspectFilter.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/TenantAspectFilter.java new file mode 100644 index 0000000..bbcf9ee --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/TenantAspectFilter.java @@ -0,0 +1,26 @@ +package cc.iotkit.data.config; +import javax.servlet.*; +import java.io.IOException; + +public class TenantAspectFilter implements Filter{ + @Override + public void init(FilterConfig filterConfig) throws ServletException { + // 初始化逻辑(可选) + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + try { + // TenantContext.disableTenantFilter(); + chain.doFilter(request, response); + } finally { + TenantContext.enableTenantFilter(); + } + } + + @Override + public void destroy() { + // 清理资源(可选) + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/TenantContext.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/TenantContext.java new file mode 100644 index 0000000..315f22a --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/TenantContext.java @@ -0,0 +1,26 @@ +package cc.iotkit.data.config; + +import com.alibaba.ttl.TransmittableThreadLocal; + +public class TenantContext { + + // private static final ThreadLocal TENANT_FILTER_DISABLED = ThreadLocal.withInitial(() -> false); + private static final ThreadLocal TENANT_FILTER_DISABLED = + new TransmittableThreadLocal<>(){ + @Override + protected Boolean initialValue() { + return false; // 默认启用租户过滤 + } + }; // 替换原实现 + public static void disableTenantFilter() { + TENANT_FILTER_DISABLED.set(true); + } + + public static void enableTenantFilter() { + TENANT_FILTER_DISABLED.set(false); + } + + public static boolean isFilterDisabled() { + return TENANT_FILTER_DISABLED.get(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/UserIDAuditorConfig.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/UserIDAuditorConfig.java new file mode 100644 index 0000000..0be61dd --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/UserIDAuditorConfig.java @@ -0,0 +1,43 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.config; + +import cc.iotkit.common.satoken.utils.LoginHelper; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.domain.AuditorAware; + +import java.util.Optional; + +/** + * @Author:tfd + * @Date:2024/1/12 15:06 + */ +@Configuration +public class UserIDAuditorConfig implements AuditorAware { + @Override + public Optional getCurrentAuditor() { + Long userId = LoginHelper.getUserId(); + return Optional.of(userId == null ? 1 : userId); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java new file mode 100644 index 0000000..f0573c1 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java @@ -0,0 +1,69 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.config.id; + +import com.github.yitter.contract.IdGeneratorOptions; +import com.github.yitter.idgen.YitIdHelper; +import org.hibernate.HibernateException; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.id.IdentifierGenerator; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.io.Serializable; +import java.lang.reflect.Field; +import java.util.Objects; + +/** + * @author: Longjun.Tu + * @description: + * @date:created in 2023/5/18 10:20 + * @modificed by: + */ +@Component +public class SnowflakeIdGenerator implements IdentifierGenerator { + + @PostConstruct + public void snowflakeIdGenerator() { + // TODO: 2023/6/12 从配置文件中读取 + IdGeneratorOptions options = new IdGeneratorOptions((short) 1); + YitIdHelper.setIdGenerator(options); + } + + @Override + public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException { + Field id = null; + try { + id = o.getClass().getDeclaredField("id"); + id.setAccessible(true); + Object val = id.get(o); + if (Objects.nonNull(val)){ + return (Serializable) val; + } + } catch (NoSuchFieldException | IllegalAccessException e) { + + } + return YitIdHelper.nextId(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertConfigRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertConfigRepository.java new file mode 100644 index 0000000..afa6030 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertConfigRepository.java @@ -0,0 +1,30 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbAlertConfig; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AlertConfigRepository extends JpaRepository { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertRecordRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertRecordRepository.java new file mode 100644 index 0000000..31bf1a6 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertRecordRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbAlertRecord; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface AlertRecordRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/CategoryRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/CategoryRepository.java new file mode 100644 index 0000000..5b515f7 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/CategoryRepository.java @@ -0,0 +1,30 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbCategory; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CategoryRepository extends JpaRepository { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelConfigRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelConfigRepository.java new file mode 100644 index 0000000..62e0786 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelConfigRepository.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbChannelConfig; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @Author: 石恒 + * @Date: 2023/5/11 21:00 + * @Description: + */ +public interface ChannelConfigRepository extends JpaRepository { +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelRepository.java new file mode 100644 index 0000000..227ec64 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelRepository.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbChannel; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * author: 石恒 + * date: 2023-05-11 17:51 + * description: + **/ +public interface ChannelRepository extends JpaRepository { +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelTemplateRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelTemplateRepository.java new file mode 100644 index 0000000..8b68a77 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelTemplateRepository.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbChannelTemplate; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @Author: 石恒 + * @Date: 2023/5/11 21:00 + * @Description: + */ +public interface ChannelTemplateRepository extends JpaRepository { +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceConfigRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceConfigRepository.java new file mode 100644 index 0000000..40cd772 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceConfigRepository.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbDeviceConfig; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface DeviceConfigRepository extends JpaRepository { + + TbDeviceConfig findByDeviceName(String deviceName); + + TbDeviceConfig findByDeviceId(String deviceId); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceGroupMappingRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceGroupMappingRepository.java new file mode 100644 index 0000000..af2c294 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceGroupMappingRepository.java @@ -0,0 +1,39 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbDeviceGroupMapping; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface DeviceGroupMappingRepository extends JpaRepository { + + List findByDeviceId(String deviceId); + + TbDeviceGroupMapping findByDeviceIdAndGroupId(String deviceId, String groupId); + + long countByGroupId(String groupId); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceGroupRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceGroupRepository.java new file mode 100644 index 0000000..a725aa1 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceGroupRepository.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbDeviceGroup; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface DeviceGroupRepository extends JpaRepository { + + Page findByNameLike(String name, Pageable pageable); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceInfoRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceInfoRepository.java new file mode 100644 index 0000000..14d1205 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceInfoRepository.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbDeviceInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +import java.util.List; + +public interface DeviceInfoRepository extends JpaRepository, QuerydslPredicateExecutor { + + TbDeviceInfo findByDeviceId(String deviceId); + + List findByParentId(String parentId); + + TbDeviceInfo findByDeviceName(String deviceName); + long countByUid(String uid); +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaDetailRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaDetailRepository.java new file mode 100644 index 0000000..9ceaed9 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaDetailRepository.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbDeviceOtaInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:21 + * @Description: + */ +public interface DeviceOtaDetailRepository extends JpaRepository, QuerydslPredicateExecutor { +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaInfoRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaInfoRepository.java new file mode 100644 index 0000000..953e8ac --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaInfoRepository.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbDeviceOtaInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:21 + * @Description: + */ +public interface DeviceOtaInfoRepository extends JpaRepository, QuerydslPredicateExecutor { +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceSubUserRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceSubUserRepository.java new file mode 100644 index 0000000..9ce97cc --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceSubUserRepository.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbDeviceSubUser; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface DeviceSubUserRepository extends JpaRepository { + + List findByDeviceId(String deviceId); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceTagRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceTagRepository.java new file mode 100644 index 0000000..0a16fe4 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceTagRepository.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbDeviceTag; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface DeviceTagRepository extends JpaRepository { + + List findByDeviceId(String deviceId); + + TbDeviceTag findByDeviceIdAndCode(String deviceId, String code); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DiccidRecordRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DiccidRecordRepository.java new file mode 100644 index 0000000..23938e5 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DiccidRecordRepository.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbDIccidRecordDO; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface DiccidRecordRepository extends JpaRepository { + + + + void deleteById(Long s); + + long count(); + + List findAll(); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/FeedBackEvaluationRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/FeedBackEvaluationRepository.java new file mode 100644 index 0000000..563961c --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/FeedBackEvaluationRepository.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbFeedBackEvaluation; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface FeedBackEvaluationRepository extends JpaRepository { + + + + void deleteById(Long s); + + long count(); + + List findAll(); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/HomeRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/HomeRepository.java new file mode 100644 index 0000000..e54e4fa --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/HomeRepository.java @@ -0,0 +1,48 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbHome; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface HomeRepository extends JpaRepository { + + TbHome findByUserIdAndCurrent(Long userId, boolean current); + + List findByUserId(Long userId); + + Page findByUserId(Long userId, Pageable pageable); + + long countByUserId(Long userId); + + void deleteById(Long s); + + long count(); + + List findAll(); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IJPACommData.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IJPACommData.java new file mode 100644 index 0000000..3489ac6 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IJPACommData.java @@ -0,0 +1,180 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.helper.TenantHelper; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.ICommonData; +import cc.iotkit.data.model.BaseEntity; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.model.Id; +import cc.iotkit.model.TenantModel; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.bean.copier.CopyOptions; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; +import org.springframework.data.domain.Page; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +/** + * @Author: jay + * @Date: 2023/6/1 9:27 + * @Version: V1.0 + * @Description: 基础数据操作接口 + */ +public interface IJPACommData, ID> extends ICommonData { + + + JpaRepository getBaseRepository(); + + Class getJpaRepositoryClass(); + + Class getTClass(); + + @Override + default T findById(ID id) { + return (T) MapstructUtils.convert(getBaseRepository().findById(id).orElse(null), getTClass()); + } + + @Override + default List findByIds(Collection id) { + List allById = getBaseRepository().findAllById(id); + return MapstructUtils.convert(allById, getTClass()); + } + + @Override + default T save(T data) { + ID id = data.getId(); + Object tbData = MapstructUtils.convert(data, getJpaRepositoryClass()); + Optional byId = id == null ? Optional.empty() : getBaseRepository().findById(id); + if (byId.isPresent()) { + Object dbObj = byId.get(); + //只更新不为空的字段 + BeanUtil.copyProperties(tbData, dbObj, CopyOptions.create().ignoreNullValue()); + tbData = dbObj; + } + if (tbData instanceof TenantAware) { + Long sourceTid = null; + if (data instanceof TenantModel) { + sourceTid = ((TenantModel) data).getTenantId(); + } + Long tenantId = TenantHelper.getTenantId(); + //未指定租户id,使用当前用户所属租户id + if (Objects.isNull(sourceTid) && tenantId != null) { + ((TenantAware) tbData).setTenantId(tenantId); + } + } + + Object o = getBaseRepository().save(tbData); + return (T) MapstructUtils.convert(o, getTClass()); + } + + @Override + default void batchSave(List data) { + getBaseRepository().saveAll(MapstructUtils.convert(data, getJpaRepositoryClass())); + } + + @Override + default void deleteById(ID id) { + getBaseRepository().deleteById(id); + } + + @Override + default void deleteByIds(Collection ids) { + getBaseRepository().deleteAllById(ids); + } + + @Override + default long count() { + return getBaseRepository().count(); + } + + @Override + default List findAll() { + return MapstructUtils.convert(getBaseRepository().findAll(), getTClass()); + } + + @Override + default Paging findAll(PageRequest pageRequest) { + Example example = genExample(pageRequest.getData()); + Page all = null; + if (Objects.isNull(example)) { + all = getBaseRepository().findAll(PageBuilder.toPageable(pageRequest)); + } else { + all = getBaseRepository().findAll(example, PageBuilder.toPageable(pageRequest)); + } + return PageBuilder.toPaging(all, getTClass()); + } + + /** + * 按条件查询多个结果 + */ + @Override + default List findAllByCondition(T data) { + Example example = genExample(data); + List all = null; + if (Objects.isNull(example)) { + all = getBaseRepository().findAll(); + + } else { + all = getBaseRepository().findAll(example); + + } + return MapstructUtils.convert(all, getTClass()); + } + + /** + * 按条件查询单个结果 + */ + @Override + default T findOneByCondition(T data) { + Example example = genExample(data); + + Optional one = getBaseRepository().findOne(example); + if (one.isPresent()) { + return (T) MapstructUtils.convert(one.get(), getTClass()); + } + return null; + } + + default Example genExample(T data) { + if (Objects.isNull(data)) { + return null; + } + return Example.of(MapstructUtils.convert(data, getJpaRepositoryClass()), + ExampleMatcher.matching().withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING) + ); + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaDeviceRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaDeviceRepository.java new file mode 100644 index 0000000..a41432a --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaDeviceRepository.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbOtaDevice; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @Author: 石恒 + * @Date: 2023/5/25 23:43 + * @Description: + */ +public interface IOtaDeviceRepository extends JpaRepository { +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaPackageRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaPackageRepository.java new file mode 100644 index 0000000..aa9683b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaPackageRepository.java @@ -0,0 +1,39 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbOtaPackage; +import cc.iotkit.model.ota.OtaPackage; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +/** + * @Author: 石恒 + * @Date: 2023/5/19 21:54 + * @Description: + */ +public interface IOtaPackageRepository extends JpaRepository { + List findByVersionGreaterThan(String version); +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IconRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IconRepository.java new file mode 100644 index 0000000..54af266 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IconRepository.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbIcon; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @Author:tfd + * @Date:2024/4/28 16:41 + */ +public interface IconRepository extends JpaRepository { +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IconTypeRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IconTypeRepository.java new file mode 100644 index 0000000..ebd4842 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IconTypeRepository.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbIconType; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @Author:tfd + * @Date:2024/4/28 16:41 + */ +public interface IconTypeRepository extends JpaRepository { +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/NotifyMessageRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/NotifyMessageRepository.java new file mode 100644 index 0000000..90c8ef0 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/NotifyMessageRepository.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbNotifyMessage; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @Author: 石恒 + * @Date: 2023/5/13 18:36 + * @Description: + */ +public interface NotifyMessageRepository extends JpaRepository { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/OauthClientRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/OauthClientRepository.java new file mode 100644 index 0000000..a89739d --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/OauthClientRepository.java @@ -0,0 +1,32 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbOauthClient; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface OauthClientRepository extends JpaRepository { + + TbOauthClient findByClientId(String clientId); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/PluginInfoRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/PluginInfoRepository.java new file mode 100644 index 0000000..efe59a7 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/PluginInfoRepository.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbPluginInfo; +import cc.iotkit.data.model.TbSysOperLog; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +/** + * @author sjg + */ +public interface PluginInfoRepository extends JpaRepository, QuerydslPredicateExecutor { + + TbPluginInfo findByPluginId(String pluginId); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/PluginInstanceRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/PluginInstanceRepository.java new file mode 100644 index 0000000..40b0fb9 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/PluginInstanceRepository.java @@ -0,0 +1,43 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbPluginInfo; +import cc.iotkit.data.model.TbPluginInstance; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @author sjg + */ +public interface PluginInstanceRepository extends JpaRepository { + + /** + * 按主程序id和插件id获取插件实例 + * + * @param mainId 主程序id + * @param pluginId 插件id + * @return 插件实例 + */ + TbPluginInfo findByMainIdAndPluginId(String mainId, String pluginId); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProductModelRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProductModelRepository.java new file mode 100644 index 0000000..97425bb --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProductModelRepository.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbProductModel; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface ProductModelRepository extends JpaRepository { + + TbProductModel findByModel(String model); + + List findByProductKey(String productKey); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProductRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProductRepository.java new file mode 100644 index 0000000..6eaf502 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProductRepository.java @@ -0,0 +1,43 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbProduct; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface ProductRepository extends JpaRepository { + + List findByCategory(String category); + + List findByUid(String uid); + + Page findByUid(String uid, Pageable pageable); + + long countByUid(String uid); + + TbProduct findByProductKey(String productKey); +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/RuleInfoRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/RuleInfoRepository.java new file mode 100644 index 0000000..038a141 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/RuleInfoRepository.java @@ -0,0 +1,46 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbRuleInfo; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface RuleInfoRepository extends JpaRepository { + + List findByUid(String uid); + + List findByUidAndType(String uid, String type); + + Page findByUidAndType(String uid, String type, Pageable pageable); + + Page findByUid(String uid, Pageable pageable); + + Page findByType(String type, Pageable pageable); + + long countByUid(String uid); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ScreenApiRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ScreenApiRepository.java new file mode 100644 index 0000000..aaf79ad --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ScreenApiRepository.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbScreenApi; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/6/25 15:23 + */ +public interface ScreenApiRepository extends JpaRepository, QuerydslPredicateExecutor { + + List findByScreenId(Long screenId); + + void deleteByScreenId(Long screenId); +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ScreenRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ScreenRepository.java new file mode 100644 index 0000000..988cee1 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ScreenRepository.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbScreen; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/6/25 15:23 + */ +public interface ScreenRepository extends JpaRepository, QuerydslPredicateExecutor { + + TbScreen findByIsDefault(boolean isDefault); + + List findByState(String state); +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SpaceDeviceRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SpaceDeviceRepository.java new file mode 100644 index 0000000..93ffaa2 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SpaceDeviceRepository.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSpaceDevice; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface SpaceDeviceRepository extends JpaRepository { + + List findByHomeIdAndCollect(Long homeId,boolean collect); + + TbSpaceDevice findByDeviceId(String deviceId); + + List findByHomeId(Long homeId); + + List findBySpaceId(Long spaceId); + + void deleteAllBySpaceId(Long spaceId); +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SpaceRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SpaceRepository.java new file mode 100644 index 0000000..f1999c4 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SpaceRepository.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSpace; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface SpaceRepository extends JpaRepository { + + List findByHomeId(Long homeId); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysAppRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysAppRepository.java new file mode 100644 index 0000000..5e5b1bc --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysAppRepository.java @@ -0,0 +1,38 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysApp; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +/** + * 应用信息对象 SYS_APP + * + * @author tfd + * @date 2023-08-10 + */ +public interface SysAppRepository extends JpaRepository, QuerydslPredicateExecutor { + TbSysApp findByAppId(String appId); +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysConfigRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysConfigRepository.java new file mode 100644 index 0000000..915f87c --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysConfigRepository.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysConfig; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +import java.util.Optional; + +public interface SysConfigRepository extends JpaRepository, QuerydslPredicateExecutor { + + Optional findByConfigKey(String configKey); +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDeptRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDeptRepository.java new file mode 100644 index 0000000..ff01a10 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDeptRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysDept; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysDeptRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDictDataRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDictDataRepository.java new file mode 100644 index 0000000..1af60e3 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDictDataRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysDictData; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysDictDataRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDictTypeRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDictTypeRepository.java new file mode 100644 index 0000000..485842e --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDictTypeRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysDictType; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysDictTypeRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysLogininforRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysLogininforRepository.java new file mode 100644 index 0000000..813072a --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysLogininforRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysLogininfor; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysLogininforRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysMenuRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysMenuRepository.java new file mode 100644 index 0000000..3523595 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysMenuRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysMenu; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysMenuRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysNoticRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysNoticRepository.java new file mode 100644 index 0000000..c287cbf --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysNoticRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysNotice; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysNoticRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOperLogRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOperLogRepository.java new file mode 100644 index 0000000..c0cdd3c --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOperLogRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysOperLog; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysOperLogRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOssConfigRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOssConfigRepository.java new file mode 100644 index 0000000..1c8c025 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOssConfigRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysOssConfig; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysOssConfigRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOssRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOssRepository.java new file mode 100644 index 0000000..08e2ad5 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOssRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysOss; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysOssRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysPostRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysPostRepository.java new file mode 100644 index 0000000..37b82ee --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysPostRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysPost; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysPostRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleDeptRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleDeptRepository.java new file mode 100644 index 0000000..433a59b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleDeptRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysRoleDept; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysRoleDeptRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleMenuRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleMenuRepository.java new file mode 100644 index 0000000..8041b91 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleMenuRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysRoleMenu; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysRoleMenuRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleRepository.java new file mode 100644 index 0000000..184445c --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysRole; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysRoleRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysTenantPackageRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysTenantPackageRepository.java new file mode 100644 index 0000000..f56bf0d --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysTenantPackageRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysTenantPackage; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysTenantPackageRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysTenantRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysTenantRepository.java new file mode 100644 index 0000000..9e4ef23 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysTenantRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysTenant; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysTenantRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserAreaRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserAreaRepository.java new file mode 100644 index 0000000..e9a3f52 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserAreaRepository.java @@ -0,0 +1,32 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysUser; +import cc.iotkit.data.model.TbSysUserArea; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysUserAreaRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserPostRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserPostRepository.java new file mode 100644 index 0000000..952716c --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserPostRepository.java @@ -0,0 +1,32 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysUserPost; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysUserPostRepository extends JpaRepository, QuerydslPredicateExecutor { + + int deleteAllByUserId(Long userId); +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRepository.java new file mode 100644 index 0000000..88981da --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysUser; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysUserRepository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRoleRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRoleRepository.java new file mode 100644 index 0000000..31f4349 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRoleRepository.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbSysUserRole; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +public interface SysUserRoleRepository extends JpaRepository, QuerydslPredicateExecutor { + int deleteAllByUserId(Long userId); +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/TaskInfoRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/TaskInfoRepository.java new file mode 100644 index 0000000..aff18cc --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/TaskInfoRepository.java @@ -0,0 +1,38 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbTaskInfo; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface TaskInfoRepository extends JpaRepository { + + List findByUid(String uid); + + Page findByUid(String uid, Pageable pageable); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ThingModelRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ThingModelRepository.java new file mode 100644 index 0000000..bc43153 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ThingModelRepository.java @@ -0,0 +1,33 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbThingModel; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface ThingModelRepository extends JpaRepository { + + Optional findByProductKey(String productKey); +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/UserInfoRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/UserInfoRepository.java new file mode 100644 index 0000000..76d335d --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/UserInfoRepository.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbUserInfo; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface UserInfoRepository extends JpaRepository { + + TbUserInfo findByUid(String uid); + + List findByType(int type); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/VirtualDeviceMappingRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/VirtualDeviceMappingRepository.java new file mode 100644 index 0000000..520b2c8 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/VirtualDeviceMappingRepository.java @@ -0,0 +1,38 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbVirtualDeviceMapping; +import org.springframework.data.jpa.repository.JpaRepository; + +import javax.transaction.Transactional; +import java.util.List; + +public interface VirtualDeviceMappingRepository extends JpaRepository { + + List findByVirtualId(String virtualId); + + @Transactional + void deleteByVirtualId(String virtualId); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/VirtualDeviceRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/VirtualDeviceRepository.java new file mode 100644 index 0000000..5362c9c --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/VirtualDeviceRepository.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbVirtualDevice; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface VirtualDeviceRepository extends JpaRepository { + + List findByUid(String uid); + + Page findByUid(String uid, Pageable pageable); + + List findByTriggerAndState(String trigger, String state); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/WorderRepository.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/WorderRepository.java new file mode 100644 index 0000000..c4230da --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/WorderRepository.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.dao; + +import cc.iotkit.data.model.TbWorderDO; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface WorderRepository extends JpaRepository { + + + + void deleteById(Long s); + + long count(); + + List findAll(); + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/BaseEntity.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/BaseEntity.java new file mode 100644 index 0000000..7a54961 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/BaseEntity.java @@ -0,0 +1,87 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.data.annotation.CreatedBy; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedBy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.Column; +import javax.persistence.EntityListeners; +import javax.persistence.MappedSuperclass; +import java.util.Date; + +/** + * Entity基类 + * + * @author Lion Li + */ +@Data +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public class BaseEntity { + + /** + * 创建部门 + */ + @ApiModelProperty(value = "创建部门") + private Long createDept; + + /** + * 创建者 + */ + @CreatedBy + @Column(name = "create_by", updatable = false) + @ApiModelProperty(value = "创建者") + private Long createBy; + + /** + * 创建时间 + */ + @CreatedDate + @Column(name = "create_time", updatable = false) + @ApiModelProperty(value = "创建时间") + private Date createTime; + + /** + * 更新者 + */ + @LastModifiedBy + @Column(name = "update_by") + @ApiModelProperty(value = "更新者") + private Long updateBy; + + /** + * 更新时间 + */ + @LastModifiedDate + @Column(name = "update_time") + @ApiModelProperty(value = "更新时间") + private Date updateTime; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/DeviceIdGroup.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/DeviceIdGroup.java new file mode 100644 index 0000000..fc5752a --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/DeviceIdGroup.java @@ -0,0 +1,55 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.EntityListeners; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class DeviceIdGroup extends BaseEntity implements TenantAware { + + @ApiModelProperty(value = "设备组id") + private Long id; + @ApiModelProperty(value = "设备id") + private String deviceId; + @ApiModelProperty(value = "组名称") + private String name; + + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertConfig.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertConfig.java new file mode 100644 index 0000000..4279b75 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertConfig.java @@ -0,0 +1,105 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import javax.persistence.*; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.alert.AlertConfig; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +@Data +@Entity +@Table(name = "alert_config") +@AutoMapper(target = AlertConfig.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbAlertConfig extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "告警配置id") + private Long id; + + /** + * 配置所属用户 + */ + @ApiModelProperty(value = "配置所属用户") + private String uid; + + /** + * 告警名称 + */ + @ApiModelProperty(value = "告警名称") + private String name; + + /** + * 告警严重度 + */ + @ApiModelProperty(value = "告警严重度") + private String level; + + /** + * 关联规则引擎ID + */ + @ApiModelProperty(value = "关联规则引擎ID") + private String ruleInfoId; + + /** + * 关联消息转发模板ID + */ + @ApiModelProperty(value = "关联消息转发模板ID") + private String messageTemplateId; + + /** + * 描述 + */ + @ApiModelProperty(value = "描述") + private String description; + + /** + * 是否启用 + */ + @ApiModelProperty(value = "是否启用") + private Boolean enable; + + /** + * 创建时间 + */ + @ApiModelProperty(value = "创建时间") + private Long createAt; + + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertRecord.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertRecord.java new file mode 100644 index 0000000..1e82868 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertRecord.java @@ -0,0 +1,92 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.alert.AlertRecord; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "alert_record") +@AutoMapper(target = AlertRecord.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbAlertRecord extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "告警记录id") + private Long id; + + /** + * 配置所属用户 + */ + @ApiModelProperty(value = "配置所属用户") + private String uid; + + /** + * 告警名称 + */ + @ApiModelProperty(value = "告警名称") + private String name; + + /** + * 告警严重度(1-5) + */ + @ApiModelProperty(value = "告警严重度(1-5)") + private String level; + + /** + * 告警时间 + */ + @ApiModelProperty(value = "告警时间") + private Long alertTime; + + /** + * 告警详情 + */ + @ApiModelProperty(value = "告警详情") + private String details; + + /** + * 是否已读 + */ + @ApiModelProperty(value = "是否已读") + private Boolean readFlg; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbCategory.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbCategory.java new file mode 100644 index 0000000..7f26dd7 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbCategory.java @@ -0,0 +1,61 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.product.Category; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "category") +@AutoMapper(target = Category.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbCategory extends BaseEntity implements TenantAware { + + @ApiModelProperty(value = "分类id") + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private String id; + + @ApiModelProperty(value = "分类名称") + private String name; + + @ApiModelProperty(value = "分类描述") + private Long createAt; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannel.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannel.java new file mode 100644 index 0000000..831c0f9 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannel.java @@ -0,0 +1,72 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.notify.Channel; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * author: 石恒 + * date: 2023-05-11 17:53 + * description: + **/ +@Data +@Entity +@Table(name = "channel") +@AutoMapper(target= Channel.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbChannel extends BaseEntity implements TenantAware { + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "通道id") + private Long id; + + @ApiModelProperty(value = "通道名称") + private String code; + + @ApiModelProperty(value = "标题") + private String title; + + @ApiModelProperty(value = "图标") + private String icon; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannelConfig.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannelConfig.java new file mode 100644 index 0000000..0a5bab3 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannelConfig.java @@ -0,0 +1,75 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.notify.ChannelConfig; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * @Author: 石恒 + * @Date: 2023/5/11 20:58 + * @Description: + */ +@Data +@Entity +@Table(name = "channel_config") +@ApiModel(value = "通道配置") +@AutoMapper(target = ChannelConfig.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbChannelConfig extends BaseEntity implements TenantAware { + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "通道配置id") + private Long id; + + @ApiModelProperty(value = "通道id") + private Long channelId; + + @ApiModelProperty(value = "通道配置名称") + private String title; + + @ApiModelProperty(value = "通道配置参数") + @Column(columnDefinition = "TEXT") + private String param; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannelTemplate.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannelTemplate.java new file mode 100644 index 0000000..a406e0a --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannelTemplate.java @@ -0,0 +1,74 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.notify.ChannelTemplate; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * @Author: 石恒 + * @Date: 2023/5/11 20:59 + * @Description: + */ +@Data +@Entity +@Table(name = "channel_template") +@ApiModel(value = "通道模板") +@AutoMapper(target= ChannelTemplate.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbChannelTemplate extends BaseEntity implements TenantAware { + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "通道模板id") + private Long id; + + @ApiModelProperty(value = "通道配置id") + private Long channelConfigId; + + @ApiModelProperty(value = "通道模板名称") + private String title; + + @ApiModelProperty(value = "通道模板内容") + private String content; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDIccidRecordDO.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDIccidRecordDO.java new file mode 100644 index 0000000..2471b52 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDIccidRecordDO.java @@ -0,0 +1,81 @@ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.*; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; +import java.time.LocalDateTime; + +// 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@Entity +@Table(name = "t_d_iccid_record") +@AutoMapper(target= cc.iotkit.model.iccid.DIccidRecordDO.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbDIccidRecordDO extends BaseEntity implements TenantAware { + + /** + * 主键 + */ + //@TableId(type = IdType.AUTO) + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + /** + * 厂商编号|合作商编号 + */ + private String userCode; + /** + * 物联网卡号 + */ + private String iccid; + /** + * 物联网卡运营商 + */ + private Integer simType; + /** + * 发货日期 + */ + private String dateline; + /** + * 状态(0,已授权,1未授权,2未支付) + */ + private Integer state; + /** + * 订单id + */ + private String orderId; + /** + * 授权码 + */ + private String authorizationCode; + /** + * 物联网卡来源0-其他 1-官方 + */ + private Integer source; + /** + * 厂商名称|合作商名称 + */ + private String user; + /** + * imei + */ + private String imei; + + private Integer validDays; + private LocalDateTime expirationTime; + /** + *租户id + */ + private Long tenantId; + +} \ No newline at end of file diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceConfig.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceConfig.java new file mode 100644 index 0000000..7fe8103 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceConfig.java @@ -0,0 +1,82 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.device.DeviceConfig; +import io.github.linpeilie.annotations.AutoMapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@ApiModel(value = "设备配置") +@Table(name = "device_config") +@AutoMapper(target = DeviceConfig.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbDeviceConfig extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "设备配置id") + private String id; + + @ApiModelProperty(value = "设备id") + private String deviceId; + + /** + * 产品key + */ + @ApiModelProperty(value = "产品key") + private String productKey; + + @ApiModelProperty(value = "设备名称") + private String deviceName; + + /** + * 设备配置json内容 + */ + @Column(columnDefinition = "text") + @ApiModelProperty(value = "设备配置json内容") + private String config; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceGroup.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceGroup.java new file mode 100644 index 0000000..de5ebd5 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceGroup.java @@ -0,0 +1,84 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.device.DeviceGroup; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "device_group") +@ApiModel(value = "设备组") +@AutoMapper(target = DeviceGroup.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbDeviceGroup extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "设备组id") + private String id; + + @ApiModelProperty(value = "设备组名称") + private String name; + + /** + * 所属用户 + */ + @ApiModelProperty(value = "所属用户") + private String uid; + + /** + * 分组说明 + */ + @ApiModelProperty(value = "分组说明") + private String remark; + + /** + * 设备数量 + */ + @ApiModelProperty(value = "设备数量") + private int deviceQty; + + /** + * 创建时间 + */ + @ApiModelProperty(value = "创建时间") + private long createAt; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceGroupMapping.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceGroupMapping.java new file mode 100644 index 0000000..cda1bee --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceGroupMapping.java @@ -0,0 +1,63 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Entity +@Table(name = "device_group_mapping") +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbDeviceGroupMapping extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "设备组映射id") + private String id; + + @ApiModelProperty(value = "设备id") + private String deviceId; + + @ApiModelProperty(value = "设备组id") + private String groupId; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java new file mode 100644 index 0000000..b81dd09 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java @@ -0,0 +1,105 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.device.DeviceInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "device_info") +@ApiModel(value = "设备信息") +@AutoMapper(target = DeviceInfo.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbDeviceInfo extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private String id; + + @ApiModelProperty(value = "设备id") + private String deviceId; + + @ApiModelProperty(value = "产品key") + private String productKey; + + @ApiModelProperty(value = "设备名称") + private String deviceName; + + @ApiModelProperty(value = "设备类型") + private String model; + + @ApiModelProperty(value = "设备密钥") + private String secret; + + @ApiModelProperty(value = "父级id") + private String parentId; + + @ApiModelProperty(value = "经度") + private String longitude; + + @ApiModelProperty(value = "纬度") + private String latitude; + + @ApiModelProperty(value = "用户id") + private String uid; + + @ApiModelProperty(value = "设备状态") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String state; + + @ApiModelProperty(value = "设备在线时间") + private Long onlineTime; + + @ApiModelProperty(value = "设备离线时间") + private Long offlineTime; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + @ApiModelProperty(value = "区域id") + private Long deptAreaId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaDetail.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaDetail.java new file mode 100644 index 0000000..013270a --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaDetail.java @@ -0,0 +1,80 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.ota.DeviceOtaDetail; +import cc.iotkit.model.ota.DeviceOtaInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:22 + * @Description: + */ +@Data +@Entity +@Table(name = "device_ota_detail") +@ApiModel(value = "设备升级明细") +@AutoMapper(target = DeviceOtaDetail.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbDeviceOtaDetail extends BaseEntity implements TenantAware { + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + + private Integer step; + + private String taskId; + + @Column(name = "[desc]") + private String desc; + + private String version; + + private String module; + + private String deviceId; + + private String productKey; + + private String deviceName; + + private Long otaInfoId; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaInfo.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaInfo.java new file mode 100644 index 0000000..bb8eac1 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaInfo.java @@ -0,0 +1,80 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.ota.DeviceOtaInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:22 + * @Description: + */ +@Data +@Entity +@Table(name = "device_ota_info") +@ApiModel(value = "设备信息") +@AutoMapper(target = DeviceOtaInfo.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbDeviceOtaInfo extends BaseEntity implements TenantAware { + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + + private Long packageId; + + @Column(name = "[desc]") + private String desc; + + private String version; + + private String module; + + private Integer total; + + private Integer success; + + private Integer fail; + + private String productKey; + + private Long createAt; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceSubUser.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceSubUser.java new file mode 100644 index 0000000..73b638c --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceSubUser.java @@ -0,0 +1,61 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "device_sub_user") +@ApiModel(value = "设备用户映射") +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbDeviceSubUser extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "id") + private String id; + + @ApiModelProperty(value = "设备id") + private String deviceId; + + @ApiModelProperty(value = "设备用户id") + private String uid; + + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceTag.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceTag.java new file mode 100644 index 0000000..f69cdcc --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceTag.java @@ -0,0 +1,82 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Entity +@Table(name = "device_tag") +@ApiModel(value = "设备标签") +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbDeviceTag extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "id") + private String id; + + @ApiModelProperty(value = "设备id") + private String deviceId; + + /** + * 标签码 + */ + @ApiModelProperty(value = "标签码") + private String code; + + /** + * 标签名称 + */ + @ApiModelProperty(value = "标签名称") + private String name; + + /** + * 标签值 + */ + @ApiModelProperty(value = "标签值") + @Column(name = "[value]") + private String value; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbFeedBackEvaluation.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbFeedBackEvaluation.java new file mode 100644 index 0000000..2475282 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbFeedBackEvaluation.java @@ -0,0 +1,88 @@ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; + +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import com.sun.xml.bind.v2.TODO; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.*; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 意见反馈评价 DO + * + * @author zhp + */ +// 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@Entity +@Table(name = "t_d_feedback_evaluation") +@AutoMapper(target= FeedBackEvaluationDO.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbFeedBackEvaluation extends BaseEntity implements TenantAware { + + /** + * ID + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + /** + * 内容 + */ + private String content; + /** + * 问题截图 + */ + private String problemScreenshot; + /** + * 消息 + */ + private String message; + /** + * 客户姓名 + */ + private String customerName; + /** + * 评价类型1意见反馈,2用户评价,3师傅评价 + * + * 枚举 {@link TODO evaluation_type 对应的类} + */ + private String evaluationType; + /** + * 服务满意度 + */ + private String serviceSatisfaction; + /** + * 设备ID + */ + private String deviceId; + /** + * 工单ID + */ + private String worderId; + /** + * 问题是否解决1解决2未解决 + * + * 枚举 {@link TODO is_solve 对应的类} + */ + private String isSolve; + /** + * 客户电话 + */ + private String customerPhone; + /** + *租户id + */ + private Long tenantId; + +} \ No newline at end of file diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbHome.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbHome.java new file mode 100644 index 0000000..6de274a --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbHome.java @@ -0,0 +1,100 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.space.Home; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@NoArgsConstructor +@Table(name = "home") +@ApiModel(value = "家庭信息") +@AutoMapper(target = Home.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbHome extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "家庭id") + private Long id; + + /** + * 家庭名称 + */ + @ApiModelProperty(value = "家庭名称") + private String name; + + /** + * 家庭地址 + */ + @ApiModelProperty(value = "家庭地址") + private String address; + + /** + * 关联用户id + */ + @ApiModelProperty(value = "关联用户id") + private Long userId; + + /** + * 空间数量 + */ + @ApiModelProperty(value = "空间数量") + private Integer spaceNum; + + /** + * 设备数量 + */ + @ApiModelProperty(value = "设备数量") + private Integer deviceNum; + + /** + * 是否为用户当前使用的家庭 + */ + @ApiModelProperty(value = "是否为用户当前使用的家庭") + private Boolean current; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbIcon.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbIcon.java new file mode 100644 index 0000000..cb12c49 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbIcon.java @@ -0,0 +1,80 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.product.Icon; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@ApiModel(value = "图标") +@Table(name = "icon") +@AutoMapper(target = Icon.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbIcon extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "iconId") + private Long id; + + + @Column(name = "tenant_id") + private Long tenantId; + + @ApiModelProperty(value = "图标分类id") + private Long iconTypeId; + + @ApiModelProperty(value = "图标名称") + private String iconName; + + @ApiModelProperty(value = "视窗缩放") + private String viewBox; + + @ApiModelProperty(value = "命名空间") + private String xmlns; + + @ApiModelProperty(value = "版本") + private String version; + + @Column(columnDefinition = "text") + @ApiModelProperty(value = "图标内容") + private String iconContent; + +} \ No newline at end of file diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbIconType.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbIconType.java new file mode 100644 index 0000000..1ea6355 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbIconType.java @@ -0,0 +1,66 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.product.IconType; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@ApiModel(value = "图标分类") +@Table(name = "icon_type") +@AutoMapper(target = IconType.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbIconType extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "主键id") + private Long id; + + + @Column(name = "tenant_id") + private Long tenantId; + + @ApiModelProperty(value = "分类名称") + private String typeName; + + @ApiModelProperty(value = "分类描述") + private String typeDescribe; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbNotifyMessage.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbNotifyMessage.java new file mode 100644 index 0000000..88fa2ba --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbNotifyMessage.java @@ -0,0 +1,72 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.notify.NotifyMessage; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * @Author: 石恒 + * @Date: 2023/5/13 18:33 + * @Description: + */ +@Data +@Entity +@ApiModel(value = "通知消息") +@Table(name = "notify_message") +@AutoMapper(target= NotifyMessage.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbNotifyMessage extends BaseEntity implements TenantAware { + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "通知消息id") + private Long id; + + private String content; + + private String messageType; + + private Boolean status; + + private Long createAt; + + private Long updateAt; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOauthClient.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOauthClient.java new file mode 100644 index 0000000..ae37025 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOauthClient.java @@ -0,0 +1,71 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.OauthClient; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "oauth_client") +@AutoMapper(target = OauthClient.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbOauthClient extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "id") + private String id; + + @ApiModelProperty(value = "客户端id") + private String clientId; + + @ApiModelProperty(value = "客户端名称") + private String name; + + @ApiModelProperty(value = "客户端密钥") + private String clientSecret; + + @ApiModelProperty(value = "允许访问的url") + private String allowUrl; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + private Long tenantId; + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaDevice.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaDevice.java new file mode 100644 index 0000000..67914b6 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaDevice.java @@ -0,0 +1,66 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * @Author: 石恒 + * @Date: 2023/5/25 23:26 + * @Description: + */ +@Data +@Entity +@Table(name = "ota_device") +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbOtaDevice extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + + private String deviceName; + + private String deviceId; + + private String version; + + private Integer status; + + private Long createAt; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaPackage.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaPackage.java new file mode 100644 index 0000000..a0efd30 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaPackage.java @@ -0,0 +1,86 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.ota.OtaPackage; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * @Author: 石恒 + * @Date: 2023/5/19 21:25 + * @Description: + */ +@Data +@Entity +@Table(name = "ota_package") +@AutoMapper(target = OtaPackage.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbOtaPackage extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + + private Long size; + + private String sign; + + private Boolean isDiff; + + private String md5; + + private String name; + + @Column(name = "[desc]") + private String desc; + + private String version; + + private String url; + + private String signMethod; + + private String module; + + private String productKey; + + private String extData; + + private Long createAt; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbPluginInfo.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbPluginInfo.java new file mode 100644 index 0000000..8375b87 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbPluginInfo.java @@ -0,0 +1,145 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.plugin.PluginInfo; +import cc.iotkit.model.product.Product; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.*; + +import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.Table; + +/** + * @author sjg + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@ApiModel(value = "插件信息") +@Table(name = "plugin_info") +@DynamicUpdate +@AutoMapper(target = PluginInfo.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbPluginInfo extends BaseEntity implements TenantAware { + + /** + * id + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "id") + private Long id; + + /** + * 插件包id + */ + @ApiModelProperty(value = "插件包id") + private String pluginId; + + /** + * 插件名称 + */ + @ApiModelProperty(value = "插件名称") + private String name; + + /** + * 描述 + */ + @ApiModelProperty(value = "描述") + private String description; + + /** + * 部署方式 + */ + @ApiModelProperty(value = "部署方式") + private String deployType; + + /** + * 插件包地址 + */ + @ApiModelProperty(value = "插件包地址") + private String file; + + /** + * 插件版本 + */ + @ApiModelProperty(value = "插件版本") + private String version; + + /** + * 插件类型 + */ + @ApiModelProperty(value = "插件类型") + private String type; + + /** + * 设备插件协议类型 + */ + @ApiModelProperty(value = "设备插件协议类型") + private String protocol; + + /** + * 状态 + */ + @ApiModelProperty(value = "状态") + private String state; + + /** + * 插件配置项描述信息 + */ + @ApiModelProperty(value = "插件配置项描述信息") + @Column(columnDefinition = "text") + private String configSchema; + + /** + * 插件配置信息 + */ + @ApiModelProperty(value = "插件配置信息") + @Column(columnDefinition = "text") + private String config; + + /** + * 插件脚本 + */ + @ApiModelProperty(value = "插件脚本") + @Column(columnDefinition = "text") + private String script; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbPluginInstance.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbPluginInstance.java new file mode 100644 index 0000000..d81edac --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbPluginInstance.java @@ -0,0 +1,92 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.plugin.PluginInstance; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@ApiModel(value = "插件实例") +@Table(name = "plugin_instance") +@AutoMapper(target = PluginInstance.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbPluginInstance extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "id") + private Long id; + + /** + * 插件主程序id + */ + @ApiModelProperty(value = "插件主程序id") + private String mainId; + + /** + * 插件id + */ + @ApiModelProperty(value = "插件id") + private Long pluginId; + + /** + * 插件主程序所在ip + */ + @ApiModelProperty(value = "插件主程序所在ip") + private String ip; + + /** + * 插件主程序端口 + */ + @ApiModelProperty(value = "插件主程序端口") + private int port; + + /** + * 心跳时间 + * 心路时间超过30秒需要剔除 + */ + @ApiModelProperty(value = "心跳时间") + private Long heartbeatAt; + + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProduct.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProduct.java new file mode 100644 index 0000000..f048e3e --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProduct.java @@ -0,0 +1,103 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.product.Product; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@ApiModel(value = "产品") +@Table(name = "product") +@AutoMapper(target = Product.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbProduct extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "产品id") + private Long id; + + + @Column(name = "tenant_id") + private Long tenantId; + + @ApiModelProperty(value = "产品key") + private String productKey; + + @ApiModelProperty(value = "产品密钥") + private String productSecret; + + @ApiModelProperty(value = "产品名称") + private String name; + + @ApiModelProperty(value = "品类") + private String category; + + @ApiModelProperty(value = "节点类型") + private Integer nodeType; + + /** + * 所属平台用户ID + */ + @ApiModelProperty(value = "用户ID") + private String uid; + + @ApiModelProperty(value = "图片") + private String img; + + @ApiModelProperty(value = "产品图标ID") + private Long iconId; + + @ApiModelProperty(value = "是否透传,true/false") + private Boolean transparent; + + @ApiModelProperty(value = "是否开启设备定位,true/false") + private Boolean isOpenLocate; + + @ApiModelProperty(value = "定位更新方式") + private String locateUpdateType; + + @ApiModelProperty(value = "保活时长(秒)") + private Long keepAliveTime; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + @ApiModelProperty(value = "0是报警器1是其它") + private Integer productType; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProductModel.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProductModel.java new file mode 100644 index 0000000..3cb1c4a --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProductModel.java @@ -0,0 +1,89 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.product.ProductModel; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@ApiModel(value = "产品型号") +@Table(name = "product_model") +@AutoMapper(target = ProductModel.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbProductModel extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "型号id") + private String id; + + /** + * 型号在所有产品中唯一 + */ + @ApiModelProperty(value = "型号") + private String model; + + @ApiModelProperty(value = "名称") + + private String name; + + @ApiModelProperty(value = "产品Key") + + private String productKey; + + @ApiModelProperty(value = "脚本类型") + private String type; + + @Column(columnDefinition = "text") + @ApiModelProperty(value = "脚本内容") + + private String script; + + /** + * 脚本状态,只有发布状态才生效 + */ + @ApiModelProperty(value = "脚本状态") + + private String state; + @ApiModelProperty(value = "修改时间") + private Long modifyAt; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbRuleInfo.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbRuleInfo.java new file mode 100644 index 0000000..f213c7b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbRuleInfo.java @@ -0,0 +1,96 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.rule.RuleInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "rule_info") +@ApiModel(value = "规则") +@AutoMapper(target = RuleInfo.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbRuleInfo extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "规则id") + private String id; + + @ApiModelProperty(value = "规则名称") + private String name; + + @ApiModelProperty(value = "规则类型") + private String type; + + @Column(columnDefinition = "text") + @ApiModelProperty(value = "监听器") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String listeners; + + @Column(columnDefinition = "text") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + @ApiModelProperty(value = "过滤器") + private String filters; + + @Column(columnDefinition = "text") + @ApiModelProperty(value = "动作") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String actions; + + @ApiModelProperty(value = "用户id") + private String uid; + + @ApiModelProperty(value = "状态") + private String state; + + @Column(name = "[desc]") + @ApiModelProperty(value = "描述") + private String desc; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbScreen.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbScreen.java new file mode 100644 index 0000000..3ec1c2d --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbScreen.java @@ -0,0 +1,83 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.screen.Screen; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * @Author:tfd + * @Date:2023/6/25 15:02 + */ +@Data +@Entity +@Table(name = "screen") +@AutoMapper(target = Screen.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbScreen { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + /** + * 大屏名称 + */ + private String name; + + /** + * 资源文件 + */ + private String resourceFile; + + /** + * 端口 + */ + private Integer port; + + /** + * 发布状态 + */ + private String state; + + /** + * 创建时间 + */ + private Long createAt; + + /** + * 是否为默认大屏 + */ + private Boolean isDefault; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbScreenApi.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbScreenApi.java new file mode 100644 index 0000000..62f12a8 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbScreenApi.java @@ -0,0 +1,89 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.screen.ScreenApi; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * @Author:tfd + * @Date:2023/6/25 15:02 + */ +@Data +@Entity +@Table(name = "screen_api") +@AutoMapper(target = ScreenApi.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbScreenApi { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + /** + * 大屏id + */ + private Long screenId; + + /** + * 接口路径 + */ + private String apiPath; + + /** + * 接口参数 + */ + private String apiParams; + + /** + * 请求方法 + */ + private String httpMethod; + + /** + * 数据源 + */ + private String dataSource; + + /** + * 创建时间 + */ + private Long createAt; + + /** + * 转换脚本 + */ + @Column(columnDefinition = "text") + private String script; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSpace.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSpace.java new file mode 100644 index 0000000..3fdbefe --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSpace.java @@ -0,0 +1,81 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.space.Space; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@NoArgsConstructor +@ApiModel(value = "空间") +@Table(name = "space") +@AutoMapper(target = Space.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSpace extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "空间id") + private Long id; + + /** + * 关联家庭id + */ + @ApiModelProperty(value = "关联家庭id") + private Long homeId; + + /** + * 空间名称 + */ + @ApiModelProperty(value = "空间名称") + private String name; + + /** + * 设备数量 + */ + @ApiModelProperty(value = "设备数量") + private Integer deviceNum; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSpaceDevice.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSpaceDevice.java new file mode 100644 index 0000000..98c27f6 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSpaceDevice.java @@ -0,0 +1,90 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.space.SpaceDevice; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "space_device") +@ApiModel(value = "空间设备") +@AutoMapper(target = SpaceDevice.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSpaceDevice extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + + /** + * 空间中的设备id + */ + @ApiModelProperty(value = "空间中的设备id") + private String deviceId; + + /** + * 空间中的设备名称 + */ + @ApiModelProperty(value = "空间中的设备名称") + private String name; + + /** + * 所属家庭Id + */ + @ApiModelProperty(value = "所属家庭Id") + private Long homeId; + + /** + * 空间id + */ + @ApiModelProperty(value = "空间id") + private Long spaceId; + + /** + * 是否收藏 + */ + @ApiModelProperty(value = "是否收藏") + private Boolean collect; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysApp.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysApp.java new file mode 100644 index 0000000..0314a6b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysApp.java @@ -0,0 +1,106 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysApp; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 应用信息表对象 SYS_APP + * + * @author tfd + * @date 2023-08-10 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@NoArgsConstructor +@Table(name = "SYS_APP") +@AutoMapper(target = SysApp.class) +@ApiModel(value = "应用信息表") +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysApp extends BaseEntity implements TenantAware { + + /** + * 主键id + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "主键id") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 应用名称 + */ + @ApiModelProperty(value = "应用名称") + private String appName; + + /** + * appId + */ + @ApiModelProperty(value = "appId") + private String appId; + + /** + * appSecret + */ + @ApiModelProperty(value = "appSecret") + private String appSecret; + + /** + * 应用类型,0:app,1:小程序 + */ + @ApiModelProperty(value = "应用类型") + private String appType; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysConfig.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysConfig.java new file mode 100644 index 0000000..e3d4851 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysConfig.java @@ -0,0 +1,101 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysConfig; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 参数配置表 sys_config + * + * @author Lion Li + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_config") +@AutoMapper(target = SysConfig.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysConfig extends BaseEntity implements TenantAware { + + /** + * 参数主键 + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "参数主键") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 参数名称 + */ + @ApiModelProperty(value = "参数名称") + private String configName; + + /** + * 参数键名 + */ + @ApiModelProperty(value = "参数键名") + private String configKey; + + /** + * 参数键值 + */ + @ApiModelProperty(value = "参数键值") + private String configValue; + + /** + * 系统内置(Y是 N否) + */ + @ApiModelProperty(value = "系统内置(Y是 N否)") + private String configType; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDept.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDept.java new file mode 100644 index 0000000..57645b0 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDept.java @@ -0,0 +1,132 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysDept; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 部门表 sys_dept + * + * @author Lion Li + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_dept") +@AutoMapper(target = SysDept.class) +@ApiModel(value = "部门表") +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysDept extends BaseEntity implements TenantAware { + private static final long serialVersionUID = 1L; + + /** + * 部门ID + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "部门ID") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户ID") + @Column(name = "tenant_id") + private Long tenantId; + + /** + * 父部门ID + */ + @ApiModelProperty(value = "父部门ID") + private Long parentId; + + /** + * 部门名称 + */ + @ApiModelProperty(value = "部门名称") + private String deptName; + + /** + * 显示顺序 + */ + @ApiModelProperty(value = "显示顺序") + private Integer orderNum; + + /** + * 负责人 + */ + @ApiModelProperty(value = "负责人") + private String leader; + + /** + * 联系电话 + */ + @ApiModelProperty(value = "联系电话") + private String phone; + + /** + * 邮箱 + */ + @ApiModelProperty(value = "邮箱") + private String email; + + /** + * 部门状态:0正常,1停用 + */ + @ApiModelProperty(value = "部门状态:0正常,1停用") + private String status; + + /** + * 删除标志(0代表存在 2代表删除) + */ + @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") + private String delFlag= UserConstants.NORMAL; + + /** + * 祖级列表 + */ + @ApiModelProperty(value = "祖级列表") + private String ancestors; + @ApiModelProperty(value = "0部门1区域") + private Integer areaType; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDictData.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDictData.java new file mode 100644 index 0000000..1acfe02 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDictData.java @@ -0,0 +1,127 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysDictData; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 字典数据表 sys_dict_data + * + * @author Lion Li + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_dict_data") +@AutoMapper(target = SysDictData.class) +@ApiModel(value = "字典数据表") +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysDictData extends BaseEntity implements TenantAware { + + + /** + * 字典编码 + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "字典编码") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 字典排序 + */ + @ApiModelProperty(value = "字典排序") + private Integer dictSort; + + /** + * 字典标签 + */ + @ApiModelProperty(value = "字典标签") + private String dictLabel; + + /** + * 字典键值 + */ + @ApiModelProperty(value = "字典键值") + private String dictValue; + + /** + * 字典类型 + */ + @ApiModelProperty(value = "字典类型") + private String dictType; + + /** + * 样式属性(其他样式扩展) + */ + @ApiModelProperty(value = "样式属性(其他样式扩展)") + private String cssClass; + + /** + * 表格字典样式 + */ + @ApiModelProperty(value = "表格字典样式") + private String listClass; + + /** + * 是否默认(Y是 N否) + */ + @ApiModelProperty(value = "是否默认(Y是 N否)") + private String isDefault; + + /** + * 状态(0正常 1停用) + */ + @ApiModelProperty(value = "状态(0正常 1停用)") + private String status; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDictType.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDictType.java new file mode 100644 index 0000000..9120383 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDictType.java @@ -0,0 +1,97 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysDictType; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 字典类型表 sys_dict_type + * + * @author Lion Li + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_dict_type") +@AutoMapper(target = SysDictType.class) +@ApiModel(value = "字典类型表") +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysDictType extends BaseEntity implements TenantAware { + + /** + * 字典主键 + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "字典主键") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 字典名称 + */ + @ApiModelProperty(value = "字典名称") + private String dictName; + + /** + * 字典类型 + */ + @ApiModelProperty(value = "字典类型") + private String dictType; + + /** + * 状态(0正常 1停用) + */ + @ApiModelProperty(value = "状态(0正常 1停用)") + private String status; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysLogininfor.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysLogininfor.java new file mode 100644 index 0000000..5a8e735 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysLogininfor.java @@ -0,0 +1,117 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysLoginInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; +import java.util.Date; + +/** + * 系统访问记录表 sys_logininfor + * + * @author Lion Li + */ + +@Data +@Entity +@Table(name = "sys_logininfor") +@AutoMapper(target = SysLoginInfo.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysLogininfor extends BaseEntity implements TenantAware { + /** + * ID + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "ID") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 用户账号 + */ + @ApiModelProperty(value = "用户账号") + private String userName; + + /** + * 登录状态 0成功 1失败 + */ + @ApiModelProperty(value = "登录状态 0成功 1失败") + private String status; + + /** + * 登录IP地址 + */ + @ApiModelProperty(value = "登录IP地址") + private String ipaddr; + + /** + * 登录地点 + */ + @ApiModelProperty(value = "登录地点") + private String loginLocation; + + /** + * 浏览器类型 + */ + @ApiModelProperty(value = "浏览器类型") + private String browser; + + /** + * 操作系统 + */ + @ApiModelProperty(value = "操作系统") + private String os; + + /** + * 提示消息 + */ + @ApiModelProperty(value = "提示消息") + private String msg; + + /** + * 访问时间 + */ + @ApiModelProperty(value = "访问时间") + private Date loginTime; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysMenu.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysMenu.java new file mode 100644 index 0000000..204d498 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysMenu.java @@ -0,0 +1,146 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.model.system.SysMenu; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.GenericGenerator; + +import javax.persistence.*; + +/** + * 菜单权限表 sys_menu + * + * @author Lion Li + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_menu") +@AutoMapper(target = SysMenu.class) +@ApiModel(value = "菜单权限表") +public class TbSysMenu extends BaseEntity { + + /** + * 菜单ID + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @Column(name = "menu_id") + @ApiModelProperty(value = "菜单ID") + private Long id; + + /** + * 父菜单ID + */ + @ApiModelProperty(value = "父菜单ID") + @Column(name = "parent_id") + private Long parentId; + + /** + * 菜单名称 + */ + @ApiModelProperty(value = "菜单名称") + @Column(name = "menu_name") + private String menuName; + + /** + * 显示顺序 + */ + @ApiModelProperty(value = "显示顺序") + private Integer orderNum; + + /** + * 路由地址 + */ + @ApiModelProperty(value = "路由地址") + private String path; + + /** + * 组件路径 + */ + @ApiModelProperty(value = "组件路径") + private String component; + + /** + * 路由参数 + */ + @ApiModelProperty(value = "路由参数") + private String queryParam; + + /** + * 是否为外链(0是 1否) + */ + @ApiModelProperty(value = "是否为外链(0是 1否)") + private String isFrame; + + /** + * 是否缓存(0缓存 1不缓存) + */ + @ApiModelProperty(value = "是否缓存(0缓存 1不缓存)") + private String isCache; + + /** + * 类型(M目录 C菜单 F按钮) + */ + @ApiModelProperty(value = "类型(M目录 C菜单 F按钮)") + private String menuType; + + /** + * 显示状态(0显示 1隐藏) + */ + @ApiModelProperty(value = "显示状态(0显示 1隐藏)") + private String visible; + + /** + * 菜单状态(0正常 1停用) + */ + @ApiModelProperty(value = "菜单状态(0正常 1停用)") + private String status; + + /** + * 权限字符串 + */ + @ApiModelProperty(value = "权限字符串") + private String perms; + + /** + * 菜单图标 + */ + @ApiModelProperty(value = "菜单图标") + private String icon; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysNotice.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysNotice.java new file mode 100644 index 0000000..0eed95c --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysNotice.java @@ -0,0 +1,102 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysNotice; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 通知公告表 sys_notice + * + * @author Lion Li + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_notice") +@AutoMapper(target = SysNotice.class) +@ApiModel(value = "通知公告表") +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysNotice extends BaseEntity implements TenantAware { + + /** + * 公告ID + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "公告ID") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 公告标题 + */ + @ApiModelProperty(value = "公告标题") + private String noticeTitle; + + /** + * 公告类型(1通知 2公告) + */ + @ApiModelProperty(value = "公告类型(1通知 2公告)") + private String noticeType; + + /** + * 公告内容 + */ + @ApiModelProperty(value = "公告内容") + private String noticeContent; + + /** + * 公告状态(0正常 1关闭) + */ + @ApiModelProperty(value = "公告状态(0正常 1关闭)") + private String status; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOperLog.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOperLog.java new file mode 100644 index 0000000..8eb92c2 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOperLog.java @@ -0,0 +1,164 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.model.system.SysOperLog; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.GenericGenerator; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * 操作日志记录表 oper_log + * + * @author Lion Li + */ +@Data +@Entity +@Table(name = "oper_log") +@AutoMapper(target = SysOperLog.class) +@ApiModel(value = "操作日志记录表") +public class TbSysOperLog implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 日志主键 + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "日志主键") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 操作模块 + */ + @ApiModelProperty(value = "操作模块") + private String title; + + /** + * 业务类型(0其它 1新增 2修改 3删除) + */ + @ApiModelProperty(value = "业务类型(0其它 1新增 2修改 3删除)") + private Integer businessType; + + /** + * 请求方法 + */ + @ApiModelProperty(value = "请求方法") + private String method; + + /** + * 请求方式 + */ + @ApiModelProperty(value = "请求方式") + private String requestMethod; + + /** + * 操作类别(0其它 1后台用户 2手机端用户) + */ + @ApiModelProperty(value = "操作类别(0其它 1后台用户 2手机端用户)") + private Integer operatorType; + + /** + * 操作人员 + */ + @ApiModelProperty(value = "操作人员") + private String operName; + + /** + * 部门名称 + */ + @ApiModelProperty(value = "部门名称") + private String deptName; + + /** + * 请求url + */ + @ApiModelProperty(value = "请求url") + private String operUrl; + + /** + * 操作地址 + */ + @ApiModelProperty(value = "操作地址") + private String operIp; + + /** + * 操作地点 + */ + @ApiModelProperty(value = "操作地点") + private String operLocation; + + /** + * 请求参数 + */ + @ApiModelProperty(value = "请求参数") + @Column(length = 2000) + private String operParam; + + /** + * 返回参数 + */ + @ApiModelProperty(value = "返回参数") + @Column(length = 2000) + private String jsonResult; + + /** + * 操作状态(0正常 1异常) + */ + @ApiModelProperty(value = "操作状态(0正常 1异常)") + private Integer status; + + /** + * 错误消息 + */ + @ApiModelProperty(value = "错误消息") + @Column(length = 2000) + private String errorMsg; + + /** + * 操作时间 + */ + @ApiModelProperty(value = "操作时间") + private Date operTime; + + /** + * 消耗时间 + */ + @ApiModelProperty(value = "消耗时间") + private Long costTime; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOss.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOss.java new file mode 100644 index 0000000..17c3e9d --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOss.java @@ -0,0 +1,103 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysOss; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * OSS对象存储对象 + * + * @author Lion Li + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_oss") +@ApiModel(value = "OSS对象存储对象") +@AutoMapper(target = SysOss.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysOss extends BaseEntity implements TenantAware { + + /** + * 对象存储主键 + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "对象存储主键") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 文件名 + */ + @ApiModelProperty(value = "文件名") + private String fileName; + + /** + * 原名 + */ + @ApiModelProperty(value = "原名") + private String originalName; + + /** + * 文件后缀名 + */ + @ApiModelProperty(value = "文件后缀名") + private String fileSuffix; + + /** + * URL地址 + */ + @ApiModelProperty(value = "URL地址") + private String url; + + /** + * 服务商 + */ + @ApiModelProperty(value = "服务商") + private String service; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOssConfig.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOssConfig.java new file mode 100644 index 0000000..5428ce2 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOssConfig.java @@ -0,0 +1,149 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysOssConfig; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 对象存储配置对象 sys_oss_config + * + * @author Lion Li + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_oss_config") +@ApiModel(value = "对象存储配置对象") +@AutoMapper(target = SysOssConfig.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysOssConfig extends BaseEntity implements TenantAware { + + /** + * 主建 + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "主建") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 配置key + */ + @ApiModelProperty(value = "配置key") + private String configKey; + + /** + * accessKey + */ + @ApiModelProperty(value = "accessKey") + private String accessKey; + + /** + * 秘钥 + */ + @ApiModelProperty(value = "秘钥") + private String secretKey; + + /** + * 桶名称 + */ + @ApiModelProperty(value = "桶名称") + private String bucketName; + + /** + * 前缀 + */ + @ApiModelProperty(value = "前缀") + private String prefix; + + /** + * 访问站点 + */ + @ApiModelProperty(value = "访问站点") + private String endpoint; + + /** + * 自定义域名 + */ + @ApiModelProperty(value = "自定义域名") + private String domain; + + /** + * 是否https(0否 1是) + */ + @ApiModelProperty(value = "是否https(0否 1是)") + private String isHttps; + + /** + * 域 + */ + @ApiModelProperty(value = "域") + private String region; + + /** + * 是否默认(0=是,1=否) + */ + @ApiModelProperty(value = "是否默认(0=是,1=否)") + private String status; + + /** + * 扩展字段 + */ + @ApiModelProperty(value = "扩展字段") + private String ext1; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + + /** + * 桶权限类型(0private 1public 2custom) + */ + @ApiModelProperty(value = "桶权限类型(0private 1public 2custom)") + private String accessPolicy; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysPost.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysPost.java new file mode 100644 index 0000000..0ea5560 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysPost.java @@ -0,0 +1,101 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysPost; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 岗位表 sys_post + * + * @author Lion Li + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_post") +@AutoMapper(target = SysPost.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysPost extends BaseEntity implements TenantAware { + + /** + * 岗位序号 + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "岗位序号") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 岗位编码 + */ + @ApiModelProperty(value = "岗位编码") + private String postCode; + + /** + * 岗位名称 + */ + @ApiModelProperty(value = "岗位名称") + private String postName; + + /** + * 岗位排序 + */ + @ApiModelProperty(value = "岗位排序") + private Integer postSort; + + /** + * 状态(0正常 1停用) + */ + @ApiModelProperty(value = "状态(0正常 1停用)") + private String status; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRole.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRole.java new file mode 100644 index 0000000..9176a32 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRole.java @@ -0,0 +1,132 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysRole; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 角色表 sys_role + * + * @author Lion Li + */ + +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_role") +@AutoMapper(target = SysRole.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysRole extends BaseEntity implements TenantAware { + + /** + * 角色ID + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "角色ID") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 角色名称 + */ + @ApiModelProperty(value = "角色名称") + private String roleName; + + /** + * 角色权限 + */ + @ApiModelProperty(value = "角色权限") + private String roleKey; + + /** + * 角色排序 + */ + @ApiModelProperty(value = "角色排序") + private Integer roleSort; + + /** + * 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限) + */ + @ApiModelProperty(value = "数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限)") + private String dataScope; + + /** + * 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) + */ + @ApiModelProperty(value = "菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示)") + private Boolean menuCheckStrictly; + + /** + * 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) + */ + @ApiModelProperty(value = "部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 )") + private Boolean deptCheckStrictly; + + /** + * 角色状态(0正常 1停用) + */ + @ApiModelProperty(value = "角色状态(0正常 1停用)") + private String status; + + /** + * 删除标志(0代表存在 2代表删除) + */ + @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") + private String delFlag= UserConstants.NORMAL; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + + public TbSysRole(Long id) { + this.id = id; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleDept.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleDept.java new file mode 100644 index 0000000..5750c26 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleDept.java @@ -0,0 +1,75 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysRoleDept; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 角色和部门关联 sys_role_dept + * + * @author Lion Li + */ + +@Data +@Entity +@Table(name = "sys_role_dept") +@AutoMapper(target = SysRoleDept.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysRoleDept extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "主键") + private Long id; + + /** + * 角色ID + */ + @ApiModelProperty(value = "角色ID") + private Long roleId; + + /** + * 部门ID + */ + @ApiModelProperty(value = "部门ID") + private Long deptId; + + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleMenu.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleMenu.java new file mode 100644 index 0000000..61b350e --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleMenu.java @@ -0,0 +1,75 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysRoleMenu; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 角色和菜单关联 sys_role_menu + * + * @author Lion Li + */ + +@Data +@Entity +@Table(name = "sys_role_menu") +@AutoMapper(target = SysRoleMenu.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysRoleMenu extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "主键") + private Long id; + + /** + * 角色ID + */ + @ApiModelProperty(value = "角色ID") + private Long roleId; + + /** + * 菜单ID + */ + @ApiModelProperty(value = "菜单ID") + private Long menuId; + + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysTenant.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysTenant.java new file mode 100644 index 0000000..8580534 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysTenant.java @@ -0,0 +1,146 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.model.system.SysTenant; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.GenericGenerator; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Date; + +/** + * 租户对象 sys_tenant + * + * @author Michelle.Chung + */ +@Data +@Entity +@Table(name = "sys_tenant") +@AutoMapper(target = SysTenant.class) +public class TbSysTenant extends BaseEntity implements TenantAware { + private static final long serialVersionUID = 1L; + + /** + * id + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "id") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 联系人 + */ + @ApiModelProperty(value = "联系人") + private String contactUserName; + + /** + * 联系电话 + */ + @ApiModelProperty(value = "联系电话") + private String contactPhone; + + /** + * 企业名称 + */ + @ApiModelProperty(value = "企业名称") + private String companyName; + + /** + * 统一社会信用代码 + */ + @ApiModelProperty(value = "统一社会信用代码") + private String licenseNumber; + + /** + * 地址 + */ + @ApiModelProperty(value = "地址") + private String address; + + /** + * 域名 + */ + @ApiModelProperty(value = "域名") + private String domain; + + /** + * 企业简介 + */ + @ApiModelProperty(value = "企业简介") + private String intro; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + + /** + * 租户套餐编号 + */ + @ApiModelProperty(value = "租户套餐编号") + private Long packageId; + + /** + * 过期时间 + */ + @ApiModelProperty(value = "过期时间") + private Date expireTime; + + /** + * 用户数量(-1不限制) + */ + @ApiModelProperty(value = "用户数量(-1不限制)") + private Long accountCount; + + /** + * 租户状态(0正常 1停用) + */ + @ApiModelProperty(value = "租户状态(0正常 1停用)") + private String status=UserConstants.DICT_ABNORMAL; + + /** + * 删除标志(0代表存在 2代表删除) + */ + @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") + private String delFlag= UserConstants.NORMAL; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysTenantPackage.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysTenantPackage.java new file mode 100644 index 0000000..6566b09 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysTenantPackage.java @@ -0,0 +1,89 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.model.system.SysTenantPackage; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.hibernate.annotations.GenericGenerator; + +import javax.persistence.*; + +/** + * 租户套餐对象 sys_tenant_package + * + * @author Michelle.Chung + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_tenant_package") +@AutoMapper(target = SysTenantPackage.class) +public class TbSysTenantPackage extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 租户套餐id + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "租户套餐id") + private Long id; + /** + * 套餐名称 + */ + @ApiModelProperty(value = "套餐名称") + private String packageName; + /** + * 关联菜单id + */ + @Column(columnDefinition = "text") + @ApiModelProperty(value = "关联菜单id") + private String menuIds; + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + /** + * 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) + */ + @ApiModelProperty(value = "菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示)") + private Boolean menuCheckStrictly; + /** + * 状态(0正常 1停用) + */ + @ApiModelProperty(value = "状态(0正常 1停用)") + private String status; + /** + * 删除标志(0代表存在 2代表删除) + */ + @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") + private String delFlag= UserConstants.NORMAL; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUser.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUser.java new file mode 100644 index 0000000..918003c --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUser.java @@ -0,0 +1,165 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysUser; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; +import java.util.Date; + +/** + * 用户对象 sys_user + * + * @author Lion Li + */ + +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_user") +@AutoMapper(target = SysUser.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysUser extends BaseEntity implements TenantAware { + + /** + * 用户ID + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "用户ID") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 部门ID + */ + @ApiModelProperty(value = "部门ID") + private Long deptId; + + /** + * 用户账号 + */ + @ApiModelProperty(value = "用户账号") + private String userName; + + /** + * 用户昵称 + */ + @ApiModelProperty(value = "用户昵称") + private String nickName; + + /** + * 用户类型(sys_user系统用户) + */ + @ApiModelProperty(value = "用户类型(sys_user系统用户)") + private String userType; + + /** + * 用户邮箱 + */ + @ApiModelProperty(value = "用户邮箱") + private String email; + + /** + * 手机号码 + */ + @ApiModelProperty(value = "手机号码") + private String phonenumber; + + /** + * 用户性别 + */ + @ApiModelProperty(value = "用户性别") + private String sex; + + /** + * 用户头像 + */ + @ApiModelProperty(value = "用户头像") + private Long avatar; + + /** + * 密码 + */ + @ApiModelProperty(value = "密码") + private String password; + + /** + * 帐号状态(0正常 1停用) + */ + @ApiModelProperty(value = "帐号状态(0正常 1停用)") + private String status; + + /** + * 删除标志(0代表存在 2代表删除) + */ + @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") + private String delFlag=UserConstants.NORMAL; + + /** + * 最后登录IP + */ + @ApiModelProperty(value = "最后登录IP") + private String loginIp; + + /** + * 最后登录时间 + */ + @ApiModelProperty(value = "最后登录时间") + private Date loginDate; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + @ApiModelProperty(value="部门表-区域id") + private Long deptAreaId; + + public TbSysUser(Long id) { + this.id = id; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserArea.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserArea.java new file mode 100644 index 0000000..d4dbc74 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserArea.java @@ -0,0 +1,93 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.system.SysUser; +import cc.iotkit.model.system.SysUserArea; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; +import java.util.Date; + +/** + * 用户对象 sys_user + * + * @author Lion Li + */ + +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "sys_user_area") +@AutoMapper(target = SysUserArea.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysUserArea extends BaseEntity implements TenantAware { + + /** + * 用户ID + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "ID") + private Long id; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 部门ID + */ + @ApiModelProperty(value = "部门区域ID") + private Long sysDeptId; + + /** + * 用户账号 + */ + @ApiModelProperty(value = "用户id") + private Long sysUserId; + + + public TbSysUserArea(Long id) { + this.id = id; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserPost.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserPost.java new file mode 100644 index 0000000..9ce9caa --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserPost.java @@ -0,0 +1,73 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 用户和岗位关联 sys_user_post + * + * @author Lion Li + */ + +@Data +@Entity +@Table(name = "sys_user_post") +@AutoMapper(target = cc.iotkit.model.system.SysUserPost.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysUserPost extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + + /** + * 用户ID + */ + @ApiModelProperty(value = "用户ID") + private Long userId; + + /** + * 岗位ID + */ + @ApiModelProperty(value = "岗位ID") + private Long postId; + + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserRole.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserRole.java new file mode 100644 index 0000000..40af0bf --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserRole.java @@ -0,0 +1,72 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * 用户和角色关联 sys_user_role + * + * @author Lion Li + */ + +@Data +@Entity +@Table(name = "sys_user_role") +@AutoMapper(target = cc.iotkit.model.system.SysUserRole.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbSysUserRole extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + + /** + * 用户ID + */ + @ApiModelProperty(value = "用户ID") + private Long userId; + + /** + * 角色ID + */ + @ApiModelProperty(value = "角色ID") + private Long roleId; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbTaskInfo.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbTaskInfo.java new file mode 100644 index 0000000..11db4c2 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbTaskInfo.java @@ -0,0 +1,112 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.rule.TaskInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "task_info") +@AutoMapper(target = TaskInfo.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbTaskInfo extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "主键") + private String id; + + @ApiModelProperty(value = "任务名称") + private String name; + + /** + * 任务类型 + */ + @ApiModelProperty(value = "任务类型") + private String type; + + /** + * 表达式 + * 定时器使用cron表达式 + * 延时器使用延时时长(秒) + */ + @ApiModelProperty(value = "表达式") + private String expression; + + /** + * 描述 + */ + @Column(name = "[desc]") + @ApiModelProperty(value = "描述") + private String desc; + + /** + * 任务输出 + */ + @Column(columnDefinition = "text") + @ApiModelProperty(value = "任务输出") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String actions; + + /** + * 任务状态 + */ + @ApiModelProperty(value = "任务状态") + private String state; + + /** + * 创建者 + */ + @ApiModelProperty(value = "创建者") + private String uid; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + /** + * 操作备注 + */ + @ApiModelProperty(value = "操作备注") + private String reason; + + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbThingModel.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbThingModel.java new file mode 100644 index 0000000..4e839e5 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbThingModel.java @@ -0,0 +1,66 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.product.ThingModel; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "thing_model") +@AutoMapper(target = ThingModel.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbThingModel extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "主键") + private Long id; + + @ApiModelProperty(value = "产品key") + private String productKey; + + @ApiModelProperty(value = "模型内容") + @Column(columnDefinition = "text") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String model; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java new file mode 100644 index 0000000..99f382b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java @@ -0,0 +1,148 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.UserInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@EqualsAndHashCode(callSuper = true) +@Entity +@NoArgsConstructor +@Table(name = "user_info") +@AutoMapper(target = UserInfo.class) +@ApiModel(value = "用户信息表") +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbUserInfo extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + + /** + * 用户账号 + */ + @ApiModelProperty(value = "用户账号") + private String uid; + + /** + * 租户编号 + */ + @ApiModelProperty(value = "租户编号") + private Long tenantId; + + /** + * 密钥(密码加密后的内容) + */ + @ApiModelProperty(value = "密钥(密码加密后的内容)") + private String secret; + + /** + * 用户昵称 + */ + @ApiModelProperty(value = "用户昵称") + private String nickName; + + /** + * 性别 0-未知 1-male,2-female + */ + @ApiModelProperty(value="性别 0-未知 1-male,2-female") + private Integer gender; + + /** + * 头像地址 + */ + @ApiModelProperty(value="头像地址") + private String avatarUrl; + + @ApiModelProperty(value="email") + private String email; + + @ApiModelProperty(value="地址") + private String address; + + /** + * 当前家庭Id + */ + @ApiModelProperty(value="当前家庭Id") + private String currHomeId; + + /** + * 用户类型 + * 0:平台用户 + * 1:终端用户 + */ + @ApiModelProperty(value="用户类型 0:平台用户 1:终端用户") + private Integer type; + @ApiModelProperty(value="详细地址") + private String site; + @ApiModelProperty(value="部门表-区域id") + private Long deptAreaId; + + + /** + * 角色 + */ + @ApiModelProperty(value="角色") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String roles; + + /** + * 权限 + */ + @ApiModelProperty(value="权限") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + + private String permissions; + + /** + * 用户使用的平台 + * 见:Constants.THIRD_PLATFORM + */ + @ApiModelProperty(value="用户使用的平台") + @ReverseAutoMapping(ignore = true) + @AutoMapping(ignore = true) + private String usePlatforms; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbVirtualDevice.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbVirtualDevice.java new file mode 100644 index 0000000..6c751f1 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbVirtualDevice.java @@ -0,0 +1,111 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.device.VirtualDevice; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "virtual_device") +@AutoMapper(target = VirtualDevice.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbVirtualDevice extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private String id; + + /** + * 所属用户 + */ + @ApiModelProperty(value = "所属用户") + private String uid; + + /** + * 虚拟设备名称 + */ + @ApiModelProperty(value = "虚拟设备名称") + private String name; + + /** + * 产品key + */ + @ApiModelProperty(value = "产品key") + private String productKey; + + /** + * 虚拟类型 + */ + @ApiModelProperty(value = "虚拟类型") + private String type; + + /** + * 设备行为脚本 + */ + @ApiModelProperty(value = "设备行为脚本") + @Column(columnDefinition = "text") + private String script; + + /** + * 触发方式执行方式 + */ + @ApiModelProperty(value = "触发方式执行方式") + @Column(name = "[trigger]") + private String trigger; + + /** + * 触发表达式 + */ + @ApiModelProperty(value = "触发表达式") + private String triggerExpression; + + /** + * 运行状态 + */ + @ApiModelProperty(value = "运行状态") + private String state; + + /** + * 创建时间 + */ + @ApiModelProperty(value = "创建时间") + private Long createAt; + + private Long tenantId; + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbVirtualDeviceMapping.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbVirtualDeviceMapping.java new file mode 100644 index 0000000..9700b25 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbVirtualDeviceMapping.java @@ -0,0 +1,61 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.entiry.BaseTenantEntity; +import cc.iotkit.common.tenant.listener.TenantListener; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Entity +@Table(name = "virtual_device_mapping") +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbVirtualDeviceMapping extends BaseEntity implements TenantAware { + + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private String id; + + @ApiModelProperty(value = "虚拟设备ID") + private String virtualId; + + @ApiModelProperty(value = "设备ID") + private String deviceId; + + private Long tenantId; +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbWorderDO.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbWorderDO.java new file mode 100644 index 0000000..ae44b8d --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbWorderDO.java @@ -0,0 +1,170 @@ +package cc.iotkit.data.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.sun.xml.bind.v2.TODO; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.*; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.*; +import java.util.Date; + +/** + * 工单 DO + * + * @author zhp + */ +// 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@Entity +@Table(name = "t_d_worder") +@AutoMapper(target= cc.iotkit.model.worder.WorderDO.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +@EntityListeners(TenantListener.class) +public class TbWorderDO extends BaseEntity implements TenantAware { + + /** + * ID + */ + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + private Long id; + + /** + * 工单编号 + */ + private String worderNum; + /** + * 工单内容 + */ + private String worderContent; + /** + * 上报时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date reportTime; + /** + * 指派人id + */ + private Long assignUserid; + /** + * 指派人姓名 + */ + private String assignName; + + /** + * 指派人电话 + */ + private String assignPhone; + + /** + * 指派时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date assignTime; + /** + * 问题截图 + */ + private String problemScreenshot; + /** + * 消息 + */ + private String message; + /** + * 预约时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private String reservationTime; + /** + * 客户id + */ + private Long customerId; + /** + * 客户姓名 + */ + private String customerName; + /** + * 联系方式 + */ + private String customerPhone; + /** + * 客户服务地址编码 + */ + private Integer customerAreaId; + /** + * 服务地址(客户详细地址) + */ + private String customerAddress; + /** + * 退单时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date worderBackTime; + /** + * 退单原因 + */ + private String worderBackReason; + /** + * 工单完成时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date finishTime; + /** + * 完成后图片 + */ + private String finishPicture; + /** + * 反馈信息 + */ + private String feedback; + + /** + * 工单类型 + *

+ * 枚举 {@link TODO worder_type 对应的类} + */ + private Integer worderType; + /** + * 订单id + */ + private String orderId; + /** + * 设备id + */ + private String productId; + /** + * 订单状态 + *

+ * 枚举 {@link TODO is_state 对应的类} + */ + private Integer orderStatus; + /** + * 工单状态 + *

+ * 枚举 {@link TODO worder_status 对应的类} + */ + private Integer worderStatus; + + /** + * 滤芯名称 + */ + private Long fwId; + + + + private Long tenantId; +} \ No newline at end of file diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertConfigDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertConfigDataImpl.java new file mode 100644 index 0000000..28fdf3b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertConfigDataImpl.java @@ -0,0 +1,70 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.AlertConfigRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IAlertConfigData; +import cc.iotkit.data.model.TbAlertConfig; +import cc.iotkit.model.alert.AlertConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +@Primary +@Service +public class AlertConfigDataImpl implements IAlertConfigData, IJPACommData { + + @Autowired + private AlertConfigRepository alertConfigRepository; + + + @Override + public JpaRepository getBaseRepository() { + return alertConfigRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbAlertConfig.class; + } + + @Override + public Class getTClass() { + return AlertConfig.class; + } + + + @Override + public Paging selectAlertConfigPage(PageRequest request) { + Page alertConfigPage = alertConfigRepository.findAll(Pageable.ofSize(request.getPageSize()).withPage(request.getPageNum() - 1)); + return new Paging<>(alertConfigPage.getTotalElements(), MapstructUtils.convert(alertConfigPage.getContent(), AlertConfig.class)); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertRecordDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertRecordDataImpl.java new file mode 100644 index 0000000..3fbf351 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertRecordDataImpl.java @@ -0,0 +1,170 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.AlertRecordRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IAlertRecordData; +import cc.iotkit.data.model.QTbAlertRecord; +import cc.iotkit.data.model.TbAlertRecord; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.alert.AlertRecord; +import cc.iotkit.model.stats.AlertStatDTO; +import cc.iotkit.model.system.SysLoginInfo; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.core.QueryResults; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static cc.iotkit.data.model.QTbAlertRecord.tbAlertRecord; + +@Primary +@Service +public class AlertRecordDataImpl implements IAlertRecordData, IJPACommData { + + @Autowired + private AlertRecordRepository alertRecordRepository; + + @Autowired + private JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return alertRecordRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbAlertRecord.class; + } + + @Override + public Class getTClass() { + return AlertRecord.class; + } + + private static Predicate genPredicate(AlertRecord data) { + boolean flag = false; + if(ObjectUtils.isNotEmpty(data.getParams()) && !"".equals(data.getParams().get("endTime"))){ + flag = true; + } + if(ObjectUtils.isNotEmpty(data)) { + return PredicateBuilder.instance() + .and(StringUtils.isNotBlank(data.getName()), () -> tbAlertRecord.name.like(data.getName())) + .and(StringUtils.isNotBlank(data.getLevel()), () -> tbAlertRecord.level.eq(data.getLevel())) + .and(flag, () -> (BooleanExpression) genTimePredicate(data.getParams())) + .build(); + }else{ + return PredicateBuilder.instance() + //.and(data != null && StringUtils.isNotBlank(data.getLevel()), () -> tbAlertRecord.level.eq(data.getLevel())) + .build(); + } + } + + @Override + public Paging selectAlertConfigPage(PageRequest request) { + + QueryResults results = jpaQueryFactory.selectFrom(tbAlertRecord) + .where(genPredicate(request.getData())) + // .where(genTimePredicate(request.getData().getParams())) // 添加时间条件 + .orderBy(tbAlertRecord.id.desc()) + .limit(request.getPageSize()) + .offset(request.getOffset()).fetchResults(); + // 将alertTime乘以1000 + List convertedResults = results.getResults().stream() + .peek(record -> record.setAlertTime(record.getAlertTime() * 1000)) + .collect(Collectors.toList()); + + return new Paging<>(results.getTotal(), convertedResults).to(AlertRecord.class); + + } + private static Predicate genTimePredicate(Map params) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate beginDate = LocalDate.parse(params.get("beginTime").toString(), formatter); + LocalDate endDate = LocalDate.parse(params.get("endTime").toString(), formatter); + + long beginSec = beginDate.atStartOfDay(ZoneId.systemDefault()) + .toEpochSecond(); + long endSec = endDate.atTime(23, 59, 59) + .atZone(ZoneId.systemDefault()) + .toEpochSecond(); + /*return PredicateBuilder.instance() + .and(tbAlertRecord.alertTime.between(beginSec, endSec));*/ + return tbAlertRecord.alertTime.between(beginSec, endSec); + } + + @Override + public List getAlertRecord() { + + /* QueryResults results = jpaQueryFactory.selectFrom(tbAlertRecord).where(genPredicate(request.getData())) + .orderBy(tbAlertRecord.id.desc()) + .limit(request.getPageSize()) + .offset(request.getOffset()).fetchResults();*/ + long currentTime = Instant.now().getEpochSecond(); + long sevenDaysAgo = currentTime - (7 * 24 * 60 * 60); + QTbAlertRecord record = QTbAlertRecord.tbAlertRecord; + return jpaQueryFactory + .select(Projections.constructor( + AlertStatDTO.class, + Expressions.stringTemplate("DATE_FORMAT(FROM_UNIXTIME({0}), '%Y-%m-%d')", record.alertTime).as("axis"), + record.level.as("name"), + record.count().as("data") + )) + .from(record) + .where(record.alertTime.between(sevenDaysAgo, currentTime)) + .groupBy( + Expressions.stringTemplate("DATE_FORMAT(FROM_UNIXTIME({0}), '%Y-%m-%d')", record.alertTime), + record.level + ) + .orderBy( + Expressions.stringTemplate("DATE_FORMAT(FROM_UNIXTIME({0}), '%Y-%m-%d')", record.alertTime).asc(), + record.level.asc() + ) + .fetch(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/CategoryDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/CategoryDataImpl.java new file mode 100644 index 0000000..be53ac0 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/CategoryDataImpl.java @@ -0,0 +1,98 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.CategoryRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.ICategoryData; +import cc.iotkit.data.model.TbCategory; +import cc.iotkit.model.product.Category; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +@Primary +@Service +public class CategoryDataImpl implements ICategoryData, IJPACommData { + + @Autowired + private CategoryRepository categoryRepository; + + @Override + public JpaRepository getBaseRepository() { + return categoryRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbCategory.class; + } + + @Override + public Class getTClass() { + return Category.class; + } + + @Override + public Category findById(String s) { + return MapstructUtils.convert(categoryRepository.findById(s).orElse(null), Category.class); + } + + @Override + public List findByIds(Collection id) { + return Collections.emptyList(); + } + + @Override + public Category save(Category data) { + TbCategory tb = categoryRepository.save(MapstructUtils.convert(data, TbCategory.class)); + data.setId(tb.getId()); + return data; + } + + + + + + @Override + public long count() { + return categoryRepository.count(); + } + + @Override + public List findAll() { + return categoryRepository.findAll().stream() + .map(c -> MapstructUtils.convert(c, Category.class)) + .collect(Collectors.toList()); + } + + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelConfigDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelConfigDataImpl.java new file mode 100644 index 0000000..e513098 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelConfigDataImpl.java @@ -0,0 +1,76 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.dao.ChannelConfigRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IChannelConfigData; +import cc.iotkit.data.model.TbChannelConfig; +import cc.iotkit.model.notify.ChannelConfig; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * author: 石恒 + * date: 2023-05-11 17:43 + * description: + **/ +@Primary +@Service +public class ChannelConfigDataImpl implements IChannelConfigData, IJPACommData { + + @Resource + private ChannelConfigRepository channelConfigRepository; + + @Override + public JpaRepository getBaseRepository() { + return channelConfigRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbChannelConfig.class; + } + + @Override + public Class getTClass() { + return ChannelConfig.class; + } + + @Override + public Paging findAll(PageRequest pageRequest) { + Page tbChannelConfigs = channelConfigRepository.findAll(Pageable.ofSize(pageRequest.getPageSize()).withPage(pageRequest.getPageNum() - 1)); + return new Paging<>( + tbChannelConfigs.getTotalElements(), + tbChannelConfigs.getContent() + ).to(ChannelConfig.class); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelDataImpl.java new file mode 100644 index 0000000..bd03426 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelDataImpl.java @@ -0,0 +1,66 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.ChannelRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IChannelData; +import cc.iotkit.data.model.TbChannel; +import cc.iotkit.model.notify.Channel; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * author: 石恒 + * date: 2023-05-11 17:44 + * description: + **/ +@Primary +@Service +public class ChannelDataImpl implements IChannelData, IJPACommData { + + @Resource + private ChannelRepository channelRepository; + + @Override + public JpaRepository getBaseRepository() { + return channelRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbChannel.class; + } + + @Override + public Class getTClass() { + return Channel.class; + } + + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelTemplateDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelTemplateDataImpl.java new file mode 100644 index 0000000..9684814 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelTemplateDataImpl.java @@ -0,0 +1,97 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.ChannelTemplateRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IChannelTemplateData; +import cc.iotkit.data.model.TbChannelTemplate; +import cc.iotkit.model.notify.ChannelTemplate; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * author: 石恒 + * date: 2023-05-11 17:45 + * description: + **/ +@Primary +@Service +public class ChannelTemplateDataImpl implements IChannelTemplateData, IJPACommData { + + @Resource + private ChannelTemplateRepository channelTemplateRepository; + + @Override + public JpaRepository getBaseRepository() { + return channelTemplateRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbChannelTemplate.class; + } + + @Override + public Class getTClass() { + return ChannelTemplate.class; + } + + + @Override + public void batchSave(List data) { + + } + + @Override + public long count() { + return channelTemplateRepository.count(); + } + + @Override + public List findAll() { + return channelTemplateRepository.findAll().stream() + .map(c -> MapstructUtils.convert(c, ChannelTemplate.class)) + .collect(Collectors.toList()); + } + + @Override + public List findAllByCondition(ChannelTemplate data) { + return Collections.emptyList(); + } + + @Override + public ChannelTemplate findOneByCondition(ChannelTemplate data) { + return null; + } + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DIccidRecordDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DIccidRecordDataImpl.java new file mode 100644 index 0000000..1fe6767 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DIccidRecordDataImpl.java @@ -0,0 +1,78 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.DiccidRecordRepository; +import cc.iotkit.data.dao.HomeRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IDIccidRecordData; +import cc.iotkit.data.manager.IHomeData; +import cc.iotkit.data.model.TbDIccidRecordDO; +import cc.iotkit.data.model.TbHome; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.iccid.DIccidRecordDO; +import cc.iotkit.model.space.Home; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; + +import static cc.iotkit.data.model.QTbHome.tbHome; + +@Primary +@Service +@RequiredArgsConstructor +public class DIccidRecordDataImpl implements IDIccidRecordData, IJPACommData { + + @Autowired + private DiccidRecordRepository homeRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return homeRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbDIccidRecordDO.class; + } + + @Override + public Class getTClass() { + return DIccidRecordDO.class; + } + + + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceConfigDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceConfigDataImpl.java new file mode 100644 index 0000000..06e15ab --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceConfigDataImpl.java @@ -0,0 +1,86 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.DeviceConfigRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IDeviceConfigData; +import cc.iotkit.data.model.TbDeviceConfig; +import cc.iotkit.model.device.DeviceConfig; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +@Primary +@Service +public class DeviceConfigDataImpl implements IDeviceConfigData, IJPACommData { + + @Autowired + private DeviceConfigRepository deviceConfigRepository; + + @Override + public DeviceConfig findByDeviceName(String deviceName) { + return MapstructUtils.convert(deviceConfigRepository.findByDeviceName(deviceName), DeviceConfig.class); + } + + @Override + public DeviceConfig findByDeviceId(String deviceId) { + return MapstructUtils.convert(deviceConfigRepository.findByDeviceId(deviceId), DeviceConfig.class); + } + + @Override + public JpaRepository getBaseRepository() { + return deviceConfigRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbDeviceConfig.class; + } + + @Override + public Class getTClass() { + return DeviceConfig.class; + } + + + @Override + public DeviceConfig save(DeviceConfig data) { + if (StringUtils.isBlank(data.getId())) { + data.setId(UUID.randomUUID().toString()); + } + deviceConfigRepository.save(MapstructUtils.convert(data, TbDeviceConfig.class)); + return data; + } + + + + + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceGroupDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceGroupDataImpl.java new file mode 100644 index 0000000..40b08eb --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceGroupDataImpl.java @@ -0,0 +1,96 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.DeviceGroupRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IDeviceGroupData; +import cc.iotkit.data.model.TbDeviceGroup; +import cc.iotkit.model.device.DeviceGroup; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.UUID; + +@Primary +@Service +public class DeviceGroupDataImpl implements IDeviceGroupData, IJPACommData { + + @Autowired + private DeviceGroupRepository deviceGroupRepository; + + @Override + public JpaRepository getBaseRepository() { + return deviceGroupRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbDeviceGroup.class; + } + + @Override + public Class getTClass() { + return DeviceGroup.class; + } + + @Override + public Paging findByNameLike(String name, int page, int size) { + Page groups = deviceGroupRepository.findByNameLike("%" + name.trim() + "%", + Pageable.ofSize(size).withPage(page - 1)); + return new Paging<>(groups.getTotalElements(), + MapstructUtils.convert(groups.getContent(), DeviceGroup.class)); + } + + + @Override + public DeviceGroup findById(String s) { + return MapstructUtils.convert(deviceGroupRepository.findById(s).orElse(null), DeviceGroup.class); + } + + @Override + public DeviceGroup save(DeviceGroup data) { + if (StringUtils.isBlank(data.getId())) { + data.setId(UUID.randomUUID().toString()); + } + deviceGroupRepository.save(MapstructUtils.convert(data, TbDeviceGroup.class)); + return data; + } + + + @Override + public List findAll() { + return MapstructUtils.convert(deviceGroupRepository.findAll(), DeviceGroup.class); + } + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java new file mode 100644 index 0000000..5413c6b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java @@ -0,0 +1,734 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.ReflectUtil; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.data.dao.*; +import cc.iotkit.data.manager.ICategoryData; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.data.model.*; +import cc.iotkit.data.system.ISysDeptData; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.alert.AlertRecord; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DevicePropertyCache; +import cc.iotkit.model.product.Category; +import cc.iotkit.model.product.Product; +import cc.iotkit.model.stats.AlertStatDTO; +import cc.iotkit.model.stats.DataItem; +import cc.iotkit.model.stats.DeviceProduckDTO; +import cc.iotkit.model.stats.ProductKeyCountDTO; +import cc.iotkit.model.system.SysDept; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +import static cc.iotkit.data.model.QTbAlertRecord.tbAlertRecord; +import static cc.iotkit.data.model.QTbDeviceGroupMapping.tbDeviceGroupMapping; +import static cc.iotkit.data.model.QTbDeviceInfo.tbDeviceInfo; +import static cc.iotkit.data.model.QTbDeviceSubUser.tbDeviceSubUser; +import static cc.iotkit.data.model.QTbProduct.tbProduct; +import static cc.iotkit.data.model.QTbSysUser.tbSysUser; + +@Primary +@Service +@RequiredArgsConstructor +public class DeviceInfoDataImpl implements IDeviceInfoData, IJPACommData { + + private final ISysDeptData sysDeptData; + private final DeviceInfoRepository deviceInfoRepository; + + private final DeviceSubUserRepository deviceSubUserRepository; + + private final DeviceGroupMappingRepository deviceGroupMappingRepository; + + private final DeviceGroupRepository deviceGroupRepository; + + private final DeviceTagRepository deviceTagRepository; + + @Qualifier("productDataCache") + private final IProductData productData; + + @Qualifier("categoryDataCache") + private final ICategoryData categoryData; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return deviceInfoRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbDeviceInfo.class; + } + + @Override + public Class getTClass() { + return DeviceInfo.class; + } + + @Override + public void saveProperties(String deviceId, Map properties) { + } + + @Override + public Map getProperties(String deviceId) { + return new HashMap<>(); + } + + @Override + public long getPropertyUpdateTime(String deviceId) { + return 0; + } + + @Override + public long getLastTime(String deviceId) { + return 0; + } + + @Override + public void setLastTime(String deviceId, long lastTime) { + + } + + @Override + public DeviceInfo findByDeviceId(String deviceId) { + TbDeviceInfo tbDeviceInfo = deviceInfoRepository.findByDeviceId(deviceId); + + DeviceInfo dto = MapstructUtils.convert(tbDeviceInfo, DeviceInfo.class); + fillDeviceInfo(deviceId, tbDeviceInfo, dto); + return dto; + } + + /** + * 填充设备其它信息 + */ + + private DeviceInfo fillDeviceInfo(String deviceId, TbDeviceInfo vo, DeviceInfo dto) { + if (vo == null || dto == null) { + return null; + } + //取子关联用户 + dto.setSubUid(deviceSubUserRepository.findByDeviceId(deviceId).stream() + .map(TbDeviceSubUser::getUid).collect(Collectors.toList())); + + //取设备所属分组 + List groupMappings = deviceGroupMappingRepository.findByDeviceId(deviceId); + Map groups = new HashMap<>(); + for (TbDeviceGroupMapping mapping : groupMappings) { + TbDeviceGroup deviceGroup = deviceGroupRepository.findById(mapping.getGroupId()).orElse(null); + if (deviceGroup == null) { + continue; + } + groups.put(deviceGroup.getId(), new DeviceInfo.Group(deviceGroup.getId(), deviceGroup.getName())); + } + dto.setGroup(groups); + + //取设备标签 + List deviceTags = deviceTagRepository.findByDeviceId(deviceId); + Map tagMap = new HashMap<>(); + for (TbDeviceTag tag : deviceTags) { + tagMap.put(tag.getCode(), new DeviceInfo.Tag(tag.getCode(), tag.getName(), tag.getValue())); + } + dto.setTag(tagMap); + + //将设备状态从vo转为dto的 + parseStateToDto(vo, dto); + return dto; + } + + /** + * 将设备状态从vo转为dto的 + */ + private void parseStateToDto(TbDeviceInfo vo, DeviceInfo dto) { + dto.setState(new DeviceInfo.State("online".equals(vo.getState()), + vo.getOnlineTime(), vo.getOfflineTime())); + dto.setLocate(new DeviceInfo.Locate(vo.getLongitude(), vo.getLatitude())); + } + + /** + * 将设备状态从dto转vo + */ + private void parseStateToVo(DeviceInfo dto, TbDeviceInfo vo) { + DeviceInfo.State state = dto.getState(); + vo.setState(state != null && state.isOnline() ? "online" : "offline"); + vo.setOfflineTime(state != null ? state.getOfflineTime() : null); + vo.setOnlineTime(state != null ? state.getOnlineTime() : null); + DeviceInfo.Locate locate = dto.getLocate(); + vo.setLongitude(locate.getLongitude()); + vo.setLatitude(locate.getLatitude()); + } + + /** + * 将数据库中查出来的vo转为dto + */ + private DeviceInfo parseVoToDto(TbDeviceInfo vo) { + if (vo == null) { + return null; + } + DeviceInfo dto = MapstructUtils.convert(vo, DeviceInfo.class); + + fillDeviceInfo(vo.getDeviceId(), vo, dto); + return dto; + } + + /** + * 将数据库中查出来的vo列表转为dto列表 + */ + private List parseVoToDto(List vos) { + return vos.stream().map(d -> { + + DeviceInfo dto = MapstructUtils.convert(d, DeviceInfo.class); + + fillDeviceInfo(d.getDeviceId(), d, dto); + return dto; + }).collect(Collectors.toList()); + } + + @Override + public DeviceInfo findByDeviceName(String deviceName) { + return parseVoToDto(deviceInfoRepository.findByDeviceName(deviceName)); + } + + @Override + public List findByParentId(String parentId) { + return parseVoToDto(deviceInfoRepository.findByParentId(parentId)); + } + + @Override + public List findSubDeviceIds(String parentId) { + return jpaQueryFactory.select(tbDeviceInfo.deviceId).from(tbDeviceInfo) + .where(tbDeviceInfo.parentId.eq(parentId)).fetch(); + } + + @Override + public List findByProductNodeType(String uid) { + List devices = jpaQueryFactory.select(tbDeviceInfo).from(tbDeviceInfo) + .join(tbProduct).on(tbProduct.nodeType.eq(0).and(tbDeviceInfo.productKey.eq(tbProduct.productKey))).fetch(); + return MapstructUtils.convert(devices, DeviceInfo.class); + } + + @Override + public boolean existByProductKey(String productKey) { + return Optional.ofNullable(jpaQueryFactory.selectOne().from(tbDeviceInfo).where(tbDeviceInfo.productKey.eq(productKey)).fetchOne()).orElse(0) > 0; + } + + @Override + public List findNeverUsedDevices() { + JPAQuery query = jpaQueryFactory.selectFrom(tbDeviceInfo); + query.where(tbDeviceInfo.onlineTime.isNull()); + List devices = query.fetch(); + return MapstructUtils.convert(devices, DeviceInfo.class); + } + @Override + public List getDeviceRecord() { + QTbDeviceInfo device = QTbDeviceInfo.tbDeviceInfo; + QTbProduct product = QTbProduct.tbProduct; + // 在线设备统计 + List onlineStats = jpaQueryFactory + .select(Projections.constructor( + DeviceProduckDTO.class, + product.productKey, + product.name, + // Expressions.constant("在线"), + device.state.when("online").then(1).otherwise(0).sum().as("state") + )) + .from(product) + .leftJoin(device).on(product.productKey.eq(device.productKey)) + .groupBy(product.productKey) + .fetch(); + + // 离线设备统计 + List offlineStats = jpaQueryFactory + .select(Projections.constructor( + DeviceProduckDTO.class, + product.productKey, + product.name, + // Expressions.constant("离线"), + device.state.when("offline").then(1).otherwise(0).sum().as("state") + )) + .from(product) + .leftJoin(device).on(product.productKey.eq(device.productKey)) + .groupBy(product.productKey) + .fetch(); + List result = new ArrayList<>(); + + // 转换在线统计数据 + for (DeviceProduckDTO dto : onlineStats) { + result.add(new AlertStatDTO( + dto.getName(), // 作为axis字段 + "在线", // 作为name字段 + dto.getState() // 作为data字段 + )); + } + + // 转换离线统计数据 + for (DeviceProduckDTO dto : offlineStats) { + result.add(new AlertStatDTO( + dto.getName(), // 作为axis字段 + "离线", // 作为name字段 + dto.getState() // 作为data字段 + )); + } + + return result; + + + } + + @Override + public Paging findByConditions(String uid, String subUid, + String productKey, String groupId, + Boolean online, String keyword, + int page, int size, Long deptAreaId) { + JPAQuery query = jpaQueryFactory.selectFrom(tbDeviceInfo); + + // 根据groupId, 如果groupId存在,则关联查询TbDeviceGroupMapping, 根据groupId,查询对应的devices + if (StringUtils.isNotBlank(groupId)) { + query.join(tbDeviceGroupMapping).on(tbDeviceGroupMapping.deviceId.eq(tbDeviceInfo.deviceId)); + query.where(tbDeviceGroupMapping.groupId.eq(groupId)); + } + + if (StringUtils.isNotBlank(uid)) { + query.where(tbDeviceInfo.uid.eq(uid)); + } + if (ObjectUtil.isNotNull(LoginHelper.getTenantId()) && !LoginHelper.isSuperAdmin()) { + query.where(tbDeviceInfo.tenantId.eq(LoginHelper.getTenantId())); + } + if (ObjectUtil.isNotNull(deptAreaId)) { + List areaIds; + // if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) { + Long areaId = deptAreaId; + List depts = sysDeptData.findByDeptId(areaId); + areaIds = StreamUtils.toList(depts, SysDept::getId); + areaIds.add(areaId); + if (ObjectUtil.isNotEmpty(areaIds)) { + query.where(tbDeviceInfo.deptAreaId.in(areaIds)); + } + } + if (StringUtils.isNotBlank(subUid)) { + query.join(tbDeviceSubUser).on(tbDeviceSubUser.deviceId.eq(tbDeviceInfo.deviceId)); + query.where(tbDeviceSubUser.uid.eq(subUid)); + } + + if (StringUtils.isNotBlank(productKey)) { + query.where(tbDeviceInfo.productKey.eq(productKey)); + } + + if (online != null) { + query.where(tbDeviceInfo.state.eq(online ? "online" : "offline")); + } + + if (StringUtils.isNotBlank(keyword)) { + query.where(tbDeviceInfo.deviceId.like("%" + keyword + "%") + .or(tbDeviceInfo.deviceName.like("%" + keyword + "%"))); + } + + query.orderBy(tbDeviceInfo.createAt.desc()); + query.offset((page - 1) * size).limit(size); + + List tbDeviceInfos = query.fetch(); + long total = query.fetchCount(); + List deviceInfos = new ArrayList<>(tbDeviceInfos.size()); + for (TbDeviceInfo tbDeviceInfo : tbDeviceInfos) { + DeviceInfo deviceInfo = MapstructUtils.convert(tbDeviceInfo, DeviceInfo.class); + fillDeviceInfo(tbDeviceInfo.getDeviceId(), tbDeviceInfo, deviceInfo); + deviceInfos.add(deviceInfo); + } + return new Paging<>(total, deviceInfos); + } + + @Override + public List findByConditionsList(String productKey) { + JPAQuery query = jpaQueryFactory.selectFrom(tbDeviceInfo); + + // 根据groupId, 如果groupId存在,则关联查询TbDeviceGroupMapping, 根据groupId,查询对应的devices + /* if (StringUtils.isNotBlank(groupId)) { + query.join(tbDeviceGroupMapping).on(tbDeviceGroupMapping.deviceId.eq(tbDeviceInfo.deviceId)); + query.where(tbDeviceGroupMapping.groupId.eq(groupId)); + } + + if (StringUtils.isNotBlank(uid)) { + query.where(tbDeviceInfo.uid.eq(uid)); + } + + if (StringUtils.isNotBlank(subUid)) { + query.join(tbDeviceSubUser).on(tbDeviceSubUser.deviceId.eq(tbDeviceInfo.deviceId)); + query.where(tbDeviceSubUser.uid.eq(subUid)); + } + + if (StringUtils.isNotBlank(productKey)) { + query.where(tbDeviceInfo.productKey.eq(productKey)); + } + + if (online != null) { + query.where(tbDeviceInfo.state.eq(online ? "online" : "offline")); + } + + if (StringUtils.isNotBlank(keyword)) { + query.where(tbDeviceInfo.deviceId.like("%" + keyword + "%") + .or(tbDeviceInfo.deviceName.like("%" + keyword + "%"))); + } +*/ + if (StringUtils.isNotBlank(productKey)) { + query.where(tbDeviceInfo.productKey.eq(productKey)); + } + query.orderBy(tbDeviceInfo.createAt.desc()); + // query.offset((page - 1) * size).limit(size); + + List tbDeviceInfos = query.fetch(); + long total = query.fetchCount(); + List deviceInfos = new ArrayList<>(tbDeviceInfos.size()); + for (TbDeviceInfo tbDeviceInfo : tbDeviceInfos) { + DeviceInfo deviceInfo = MapstructUtils.convert(tbDeviceInfo, DeviceInfo.class); + fillDeviceInfo(tbDeviceInfo.getDeviceId(), tbDeviceInfo, deviceInfo); + deviceInfos.add(deviceInfo); + } + return deviceInfos; + } + + @Override + public void updateTag(String deviceId, DeviceInfo.Tag tag) { + TbDeviceTag deviceTag = deviceTagRepository.findByDeviceIdAndCode(deviceId, tag.getId()); + if (deviceTag != null) { + deviceTag.setName(tag.getName()); + deviceTag.setValue(tag.getValue()); + deviceTagRepository.save(deviceTag); + } else { + deviceTagRepository.save( + TbDeviceTag.builder() + .id(UUID.randomUUID().toString()) + .code(tag.getId()) + .deviceId(deviceId) + .name(tag.getName()) + .value(tag.getValue()) + .build() + ); + } + } + + @Override + public List getDeviceStatsByCategory(String uid) { + //先按产品统计设备数量 + JPAQuery query = jpaQueryFactory.select(Projections.bean(DataItem.class, + tbDeviceInfo.productKey.as("name"), + tbDeviceInfo.productKey.count().as("value"))) + .from(tbDeviceInfo) + .groupBy(tbDeviceInfo.productKey); + + if (StringUtils.isNotBlank(uid)) { + query.where(tbDeviceInfo.uid.eq(uid)); + } + + List stats = new ArrayList<>(); + + List rst = query.fetch(); + for (DataItem item : rst) { + //找到产品对应的品类取出品类名 + Product product = productData.findByProductKey(item.getName()); + String cateId = product.getCategory(); + Category category = categoryData.findById(cateId); + if (category == null) { + continue; + } + //将数据替换成按品类的数据 + item.setName(category.getName()); + } + + //按品类分组求合 + rst.stream().collect(Collectors.groupingBy(DataItem::getName, + Collectors.summarizingLong(item -> (long) item.getValue()))) + .forEach((key, sum) -> stats.add(new DataItem(key, sum.getSum()))); + + return stats; + } + + @Override + public long countByGroupId(String groupId) { + return deviceGroupMappingRepository.countByGroupId(groupId); + } + private static Predicate genPredicate(List deptAreaId,String startDate, String endDate) { + boolean hasValidConditions = false; + PredicateBuilder builder = PredicateBuilder.instance(); + if (ObjectUtil.isNotEmpty(deptAreaId)) { + hasValidConditions = true; + builder.and(ObjectUtil.isNotEmpty(deptAreaId), () -> tbDeviceInfo.deptAreaId.in(deptAreaId)); + } + if (ObjectUtil.isNotNull(endDate)) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + Date beginDate = Date.from(LocalDate.parse(startDate).atStartOfDay(ZoneId.systemDefault()).toInstant()); + + + Date endDate1 = Date.from(LocalDate.parse(endDate).atStartOfDay(ZoneId.systemDefault()).toInstant()); + + // LocalDate beginDate = LocalDate.parse(startDate, formatter); + // LocalDate endDate1 = LocalDate.parse(endDate, formatter); + builder.and(ObjectUtil.isNotNull(endDate), () -> tbDeviceInfo.createTime.between(beginDate, endDate1)); + hasValidConditions = true; + } + if(hasValidConditions) { + Predicate predicate = builder.build(); + return predicate; + }else{ + return PredicateBuilder.instance().build(); + } +// 手动覆盖空条件 + +/* + return PredicateBuilder.instance() + .and(Expressions.asBoolean(true).isTrue()) + .and(ObjectUtil.isNotNull(deptAreaId), () -> tbDeviceInfo.deptAreaId.in(deptAreaId)) + .and(ObjectUtil.isNotNull(endDate), () -> tbDeviceInfo.createTime.between(startDate, endDate)) + .build();*/ + + } + @Override + public List getProductDevice(Long deptAreaId,String startDate, String endDate) { + QTbDeviceInfo record = QTbDeviceInfo.tbDeviceInfo; + QTbProduct product = QTbProduct.tbProduct; + List areaIds = new ArrayList<>(); + if (ObjectUtil.isNotNull(deptAreaId)) { + // if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) { + Long areaId = deptAreaId; + List depts = sysDeptData.findByDeptId(areaId); + areaIds = StreamUtils.toList(depts, SysDept::getId); + areaIds.add(areaId); + /* if (ObjectUtil.isNotEmpty(areaIds)) { + query.where(tbDeviceInfo.deptAreaId.in(areaIds)); + }*/ + } + + return jpaQueryFactory + .select(Projections.constructor( + ProductKeyCountDTO.class, + record.productKey, + record.count().as("value"), + product.name + )) + .from(record) + .join(product).on(record.productKey.eq(product.productKey)) + .where(genPredicate(areaIds,startDate, endDate)) + .groupBy(record.productKey) + .fetch(); + } + + + @Override + @Transactional + public void addToGroup(String deviceId, DeviceInfo.Group group) { + String groupId = UUID.randomUUID().toString(); + deviceGroupMappingRepository.save(new TbDeviceGroupMapping(groupId, deviceId, group.getId(), LoginHelper.getTenantId())); + + //更新设备数量 + updateGroupDeviceCount(groupId); + } + + private void updateGroupDeviceCount(String groupId) { + //更新设备数量 + TbDeviceGroup deviceGroup = deviceGroupRepository.findById(groupId).orElse(null); + if (deviceGroup != null) { + deviceGroup.setDeviceQty((int) countByGroupId(groupId)); + deviceGroupRepository.save(deviceGroup); + } + } + + @Override + public void updateGroup(String groupId, DeviceInfo.Group group) { + //更新设备信息中的分组信息,关系数据库中不需要实现 + } + + @Override + @Transactional + public void removeGroup(String deviceId, String groupId) { + jpaQueryFactory.delete(tbDeviceGroupMapping) + .where(tbDeviceGroupMapping.deviceId.eq(deviceId) + .and(tbDeviceGroupMapping.groupId.eq(groupId))) + .execute(); + //更新设备数量 + updateGroupDeviceCount(groupId); + } + + @Override + @Transactional + public void removeGroup(String groupId) { + jpaQueryFactory.delete(tbDeviceGroupMapping) + .where(tbDeviceGroupMapping.groupId.eq(groupId)) + .execute(); + //更新设备数量 + updateGroupDeviceCount(groupId); + } + + @Override + public List findByUid(String uid) { + return new ArrayList<>(); + } + + @Override + public Paging findByUid(String uid, int page, int size) { + return new Paging<>(); + } + + @Override + public long countByUid(String uid) { + + return deviceInfoRepository.countByUid(uid); + } + + + @Override + public DeviceInfo findById(String s) { + return MapstructUtils.convert( + deviceInfoRepository.findById(s).orElse(null), DeviceInfo.class); + } + + @Override + public List findByIds(Collection ids) { + return MapstructUtils.convert(deviceInfoRepository.findAllById(ids), DeviceInfo.class); + } + + @Override + @Transactional + public DeviceInfo save(DeviceInfo data) { + TbDeviceInfo vo = deviceInfoRepository.findByDeviceId(data.getDeviceId()); + if (StringUtils.isBlank(data.getId())) { + data.setId(UUID.randomUUID().toString()); + } + if (vo == null) { + vo = new TbDeviceInfo(); + } + + ReflectUtil.copyNoNulls(data, vo); + //状态转换 + parseStateToVo(data, vo); + //保存设备信息 + deviceInfoRepository.save(vo); + + //设备分组转换 + Map groupMap = data.getGroup(); + groupMap.forEach((id, group) -> { + TbDeviceGroupMapping mapping = deviceGroupMappingRepository.findByDeviceIdAndGroupId(data.getDeviceId(), id); + if (mapping == null) { + //保存设备分组与设备对应关系 + deviceGroupMappingRepository.save(new TbDeviceGroupMapping( + UUID.randomUUID().toString(), + data.getDeviceId(), + id, + LoginHelper.getTenantId() + )); + } + }); + + return data; + } + + @Override + public void batchSave(List data) { + + } + + @Override + public void deleteById(String s) { + deviceInfoRepository.deleteById(s); + } + + @Override + public void deleteByIds(Collection ids) { + deviceInfoRepository.deleteAllById(ids); + } + + + @Override + public long count() { + return deviceInfoRepository.count(); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + Page ret = deviceInfoRepository.findAll(PageBuilder.toPageable(pageRequest)); + List list = new ArrayList<>(); + for (TbDeviceInfo deviceInfo : ret.getContent()) { + list.add(fillDeviceInfo(deviceInfo.getDeviceId(), deviceInfo, MapstructUtils.convert(deviceInfo, DeviceInfo.class))); + } + return new Paging<>(ret.getTotalElements(), list); + } + + @Override + public DeviceInfo findOneByCondition(DeviceInfo data) { + return null; + } + + @Override + public List findAllByCondition(DeviceInfo data) { + return buildQuery(buildQueryCondition(data)); + } + + private List buildQuery(Predicate predicate) { + List devices = jpaQueryFactory.select(Projections.bean(TbDeviceInfo.class, tbDeviceInfo.uid, + tbDeviceInfo.deviceId, tbDeviceInfo.productKey, tbDeviceInfo.deviceName, tbDeviceInfo.state, tbDeviceInfo.createAt, + tbDeviceInfo.id, tbDeviceInfo.onlineTime, tbDeviceInfo.parentId, tbDeviceInfo.latitude, tbDeviceInfo.longitude, tbDeviceInfo.model, + tbDeviceInfo.offlineTime, tbDeviceInfo.secret)) + .from(tbDeviceInfo) + .where(predicate).fetch(); + return MapstructUtils.convert(devices, DeviceInfo.class); + } + + private Predicate buildQueryCondition(DeviceInfo device) { + return PredicateBuilder.instance() + .and(ObjectUtil.isNotNull(device.getId()), () -> tbDeviceInfo.id.eq(device.getId())) + .and(ObjectUtil.isNotNull(device.getDeviceName()), () -> tbDeviceInfo.deviceName.eq(device.getDeviceName())) + .and(ObjectUtil.isNotNull(device.getState()), () -> tbDeviceInfo.state.eq(device.getState().isOnline() ? "online" : "offline")) + .build(); + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaDetailDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaDetailDataImpl.java new file mode 100644 index 0000000..dcaefd7 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaDetailDataImpl.java @@ -0,0 +1,69 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.DeviceOtaDetailRepository; +import cc.iotkit.data.dao.DeviceOtaInfoRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IDeviceOtaDetailData; +import cc.iotkit.data.manager.IDeviceOtaInfoData; +import cc.iotkit.data.model.TbDeviceOtaDetail; +import cc.iotkit.data.model.TbDeviceOtaInfo; +import cc.iotkit.model.ota.DeviceOtaDetail; +import cc.iotkit.model.ota.DeviceOtaInfo; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:19 + * @Description: + */ +@Primary +@Service +@RequiredArgsConstructor +public class DeviceOtaDetailDataImpl implements IDeviceOtaDetailData, IJPACommData { + + private final DeviceOtaDetailRepository deviceOtaDetailRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return deviceOtaDetailRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbDeviceOtaDetail.class; + } + + @Override + public Class getTClass() { + return DeviceOtaDetail.class; + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaInfoDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaInfoDataImpl.java new file mode 100644 index 0000000..b154e83 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaInfoDataImpl.java @@ -0,0 +1,65 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.DeviceOtaInfoRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IDeviceOtaInfoData; +import cc.iotkit.data.model.TbDeviceOtaInfo; +import cc.iotkit.model.ota.DeviceOtaInfo; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @Author: 石恒 + * @Date: 2023/6/15 22:19 + * @Description: + */ +@Primary +@Service +@RequiredArgsConstructor +public class DeviceOtaInfoDataImpl implements IDeviceOtaInfoData, IJPACommData { + + private final DeviceOtaInfoRepository deviceOtaInfoRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return deviceOtaInfoRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbDeviceOtaInfo.class; + } + + @Override + public Class getTClass() { + return DeviceOtaInfo.class; + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/FeedBackEvaluationImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/FeedBackEvaluationImpl.java new file mode 100644 index 0000000..edb6e94 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/FeedBackEvaluationImpl.java @@ -0,0 +1,66 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.FeedBackEvaluationRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IFeedBackEvaluationData; +import cc.iotkit.data.model.TbFeedBackEvaluation; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +@Primary +@Service +@RequiredArgsConstructor +public class FeedBackEvaluationImpl implements IFeedBackEvaluationData, IJPACommData { + + @Autowired + private FeedBackEvaluationRepository homeRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return homeRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbFeedBackEvaluation.class; + } + + @Override + public Class getTClass() { + return FeedBackEvaluationDO.class; + } + + + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/HomeDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/HomeDataImpl.java new file mode 100644 index 0000000..a5c3c41 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/HomeDataImpl.java @@ -0,0 +1,92 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.HomeRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IHomeData; +import cc.iotkit.data.model.TbHome; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.space.Home; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; + +import static cc.iotkit.data.model.QTbHome.tbHome; + +@Primary +@Service +@RequiredArgsConstructor +public class HomeDataImpl implements IHomeData, IJPACommData { + + @Autowired + private HomeRepository homeRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return homeRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbHome.class; + } + + @Override + public Class getTClass() { + return Home.class; + } + + @Override + public Home findByUserIdAndCurrent(Long userId, boolean current) { + return MapstructUtils.convert(homeRepository.findByUserIdAndCurrent(userId, current), Home.class); + } + + @Override + public List findByUserId(Long userId) { + return MapstructUtils.convert(homeRepository.findByUserId(userId), Home.class); + } + + @Override + public boolean checkHomeNameUnique(Home home) { + final TbHome ret = jpaQueryFactory.select(tbHome).from(tbHome) + .where(PredicateBuilder.instance() + .and(tbHome.name.eq(home.getName())) + .and(tbHome.userId.eq(LoginHelper.getUserId())) + .build()).fetchOne(); + return Objects.isNull(ret); + } + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaDeviceDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaDeviceDataImpl.java new file mode 100644 index 0000000..9cef0e9 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaDeviceDataImpl.java @@ -0,0 +1,63 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.IOtaDeviceRepository; +import cc.iotkit.data.manager.IOtaDeviceData; +import cc.iotkit.data.model.TbOtaDevice; +import cc.iotkit.model.ota.OtaDevice; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * @Author: 石恒 + * @Date: 2023/5/25 23:41 + * @Description: + */ +@Primary +@Service +public class IOtaDeviceDataImpl implements IOtaDeviceData, IJPACommData { + + @Resource + private IOtaDeviceRepository iOtaDeviceRepository; + + @Override + public JpaRepository getBaseRepository() { + return iOtaDeviceRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbOtaDevice.class; + } + + @Override + public Class getTClass() { + return OtaDevice.class; + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaPackageDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaPackageDataImpl.java new file mode 100644 index 0000000..6407c01 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaPackageDataImpl.java @@ -0,0 +1,81 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.IOtaPackageRepository; +import cc.iotkit.data.manager.IOtaPackageData; +import cc.iotkit.data.model.TbOtaPackage; +import cc.iotkit.model.ota.OtaPackage; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Author: 石恒 + * @Date: 2023/5/19 21:53 + * @Description: + */ +@Primary +@Service +@RequiredArgsConstructor +public class IOtaPackageDataImpl implements IOtaPackageData, IJPACommData { + + private final IOtaPackageRepository iOtaPackageRepository; + + @Override + public JpaRepository getBaseRepository() { + return iOtaPackageRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbOtaPackage.class; + } + + @Override + public Class getTClass() { + return OtaPackage.class; + } + + @Override + public List findAll() { + return iOtaPackageRepository.findAll().stream().map(e -> MapstructUtils.convert(e, OtaPackage.class)).collect(Collectors.toList()); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + Page tbOtaPackages = iOtaPackageRepository.findAll(Pageable.ofSize(pageRequest.getPageSize()).withPage(pageRequest.getPageNum() - 1)); + return new Paging<>(tbOtaPackages.getTotalElements(), tbOtaPackages.getContent().stream().map(e -> MapstructUtils.convert(e, OtaPackage.class)).collect(Collectors.toList())); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IconDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IconDataImpl.java new file mode 100644 index 0000000..33ea611 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IconDataImpl.java @@ -0,0 +1,61 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.IconRepository; +import cc.iotkit.data.manager.IIconData; +import cc.iotkit.data.model.TbIcon; +import cc.iotkit.model.product.Icon; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @Author:tfd + * @Date:2024/4/28 16:42 + */ +@Primary +@Service +public class IconDataImpl implements IIconData, IJPACommData { + + @Autowired + private IconRepository iconRepository; + + @Override + public JpaRepository getBaseRepository() { + return iconRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbIcon.class; + } + + @Override + public Class getTClass() { + return Icon.class; + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IconTypeDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IconTypeDataImpl.java new file mode 100644 index 0000000..6860c88 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IconTypeDataImpl.java @@ -0,0 +1,61 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.IconTypeRepository; +import cc.iotkit.data.manager.IIconTypeData; +import cc.iotkit.data.model.TbIconType; +import cc.iotkit.model.product.IconType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @Author:tfd + * @Date:2024/4/28 16:42 + */ +@Primary +@Service +public class IconTypeDataImpl implements IIconTypeData, IJPACommData { + + @Autowired + private IconTypeRepository iconTypeRepository; + + @Override + public JpaRepository getBaseRepository() { + return iconTypeRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbIconType.class; + } + + @Override + public Class getTClass() { + return IconType.class; + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/NotifyMessageDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/NotifyMessageDataImpl.java new file mode 100644 index 0000000..3944346 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/NotifyMessageDataImpl.java @@ -0,0 +1,65 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.NotifyMessageRepository; +import cc.iotkit.data.manager.INotifyMessageData; +import cc.iotkit.data.model.TbNotifyMessage; +import cc.iotkit.model.notify.NotifyMessage; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * @Author: 石恒 + * @Date: 2023/5/13 18:35 + * @Description: + */ +@Primary +@Service +public class NotifyMessageDataImpl implements INotifyMessageData, IJPACommData { + + @Resource + private NotifyMessageRepository notifyMessageRepository; + + + @Override + public JpaRepository getBaseRepository() { + return notifyMessageRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbNotifyMessage.class; + } + + @Override + public Class getTClass() { + return NotifyMessage.class; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/OauthClientDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/OauthClientDataImpl.java new file mode 100644 index 0000000..9aff2fe --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/OauthClientDataImpl.java @@ -0,0 +1,86 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.OauthClientRepository; +import cc.iotkit.data.manager.IOauthClientData; +import cc.iotkit.data.model.TbOauthClient; +import cc.iotkit.model.OauthClient; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +@Primary +@Service +public class OauthClientDataImpl implements IOauthClientData, IJPACommData { + + @Autowired + private OauthClientRepository oauthClientRepository; + + @Override + public OauthClient findByClientId(String clientId) { + return MapstructUtils.convert(oauthClientRepository.findByClientId(clientId), OauthClient.class); + } + + @Override + public JpaRepository getBaseRepository() { + return oauthClientRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbOauthClient.class; + } + + @Override + public Class getTClass() { + return OauthClient.class; + } + + @Override + public OauthClient findById(String s) { + return MapstructUtils.convert(oauthClientRepository.findById(s).orElse(null), OauthClient.class); + } + + + @Override + public OauthClient save(OauthClient data) { + if (StringUtils.isBlank(data.getId())) { + data.setId(UUID.randomUUID().toString()); + data.setCreateAt(System.currentTimeMillis()); + } + oauthClientRepository.save(MapstructUtils.convert(data, TbOauthClient.class)); + return data; + } + + + + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/PluginInfoDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/PluginInfoDataImpl.java new file mode 100644 index 0000000..1041b27 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/PluginInfoDataImpl.java @@ -0,0 +1,94 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.PluginInfoRepository; +import cc.iotkit.data.manager.IPluginInfoData; +import cc.iotkit.data.model.TbPluginInfo; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.plugin.PluginInfo; +import com.querydsl.core.types.Predicate; +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import static cc.iotkit.data.model.QTbPluginInfo.tbPluginInfo; + + +/** + * @author sjg + */ +@Primary +@Service +public class PluginInfoDataImpl implements IPluginInfoData, IJPACommData { + + @Autowired + private PluginInfoRepository pluginInfoRepository; + + @Autowired + private JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return pluginInfoRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbPluginInfo.class; + } + + @Override + public Class getTClass() { + return PluginInfo.class; + } + + @Override + public PluginInfo findByPluginId(String pluginId) { + return MapstructUtils.convert(pluginInfoRepository.findByPluginId(pluginId), PluginInfo.class); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return PageBuilder.toPaging(pluginInfoRepository.findAll( + buildQueryCondition(pageRequest.getData()), + PageBuilder.toPageable(pageRequest) + )).to(PluginInfo.class); + } + + private Predicate buildQueryCondition(PluginInfo data) { + return PredicateBuilder.instance() + .and(StringUtils.isNotBlank(data.getType()), () -> tbPluginInfo.type.eq(data.getType())) + .and(data.getState() != null, () -> tbPluginInfo.state.eq(data.getState())) + .build(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/PluginInstanceDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/PluginInstanceDataImpl.java new file mode 100644 index 0000000..6891110 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/PluginInstanceDataImpl.java @@ -0,0 +1,70 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.PluginInstanceRepository; +import cc.iotkit.data.manager.IPluginInstanceData; +import cc.iotkit.data.model.TbPluginInstance; +import cc.iotkit.model.plugin.PluginInstance; +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @author sjg + */ +@Primary +@Service +public class PluginInstanceDataImpl implements IPluginInstanceData, IJPACommData { + + @Autowired + private PluginInstanceRepository pluginInstanceRepository; + + @Autowired + private JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return pluginInstanceRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbPluginInstance.class; + } + + @Override + public Class getTClass() { + return PluginInstance.class; + } + + @Override + public PluginInstance findInstance(String mainId, String pluginId) { + return MapstructUtils.convert(pluginInstanceRepository.findByMainIdAndPluginId(mainId, pluginId), PluginInstance.class); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProductDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProductDataImpl.java new file mode 100644 index 0000000..8a5aac0 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProductDataImpl.java @@ -0,0 +1,105 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.ProductRepository; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.data.model.TbProduct; +import cc.iotkit.model.product.Product; +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +import static cc.iotkit.data.model.QTbProduct.tbProduct; + +@Primary +@Service +public class ProductDataImpl implements IProductData, IJPACommData { + + @Autowired + private ProductRepository productRepository; + @Autowired + private JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return productRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbProduct.class; + } + + @Override + public Class getTClass() { + return Product.class; + } + + @Override + public List findByCategory(String category) { + return MapstructUtils.convert(productRepository.findByCategory(category), Product.class); + } + + @Override + public Product findByProductKey(String productKey) { + return MapstructUtils.convert(productRepository.findByProductKey(productKey), Product.class); + } + + @Override + public void delByProductKey(String productKey) { + jpaQueryFactory.delete(tbProduct).where(tbProduct.productKey.eq(productKey)).execute(); + } + + public List findByUid(String uid) { + return MapstructUtils.convert(productRepository.findByUid(uid), Product.class); + } + + public Paging findByUid(String uid, int page, int size) { + Page productPage = productRepository.findByUid(uid, + Pageable.ofSize(size).withPage(page - 1)); + return new Paging<>(productPage.getTotalElements(), + MapstructUtils.convert(productPage.getContent(), Product.class)); + } + + public long countByUid(String uid) { + return productRepository.countByUid(uid); + } + + @Override + public Product save(Product data) { + productRepository.save(MapstructUtils.convert(data, TbProduct.class)); + return data; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProductModelDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProductModelDataImpl.java new file mode 100644 index 0000000..ace695e --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProductModelDataImpl.java @@ -0,0 +1,98 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.ProductModelRepository; +import cc.iotkit.data.manager.IProductModelData; +import cc.iotkit.data.model.TbProductModel; +import cc.iotkit.model.product.ProductModel; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +@Primary +@Service +public class ProductModelDataImpl implements IProductModelData, IJPACommData { + + @Autowired + private ProductModelRepository productModelRepository; + + + @Override + public JpaRepository getBaseRepository() { + return productModelRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbProductModel.class; + } + + @Override + public Class getTClass() { + return ProductModel.class; + } + + @Override + public ProductModel findByModel(String model) { + return MapstructUtils.convert(productModelRepository.findByModel(model), ProductModel.class); + } + + @Override + public List findByProductKey(String productKey) { + return MapstructUtils.convert(productModelRepository.findByProductKey(productKey), ProductModel.class); + } + + @Override + public ProductModel findById(String s) { + return MapstructUtils.convert(productModelRepository.findById(s).orElse(null), ProductModel.class); + } + + @Override + public List findByIds(Collection id) { + return Collections.emptyList(); + } + + @Override + public ProductModel save(ProductModel data) { + if (StringUtils.isBlank(data.getId())) { + data.setId(UUID.randomUUID().toString()); + } + data.setModifyAt(System.currentTimeMillis()); + productModelRepository.save(MapstructUtils.convert(data, TbProductModel.class)); + return null; + } + + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/RuleInfoDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/RuleInfoDataImpl.java new file mode 100644 index 0000000..e5df003 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/RuleInfoDataImpl.java @@ -0,0 +1,171 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IRuleInfoData; +import cc.iotkit.data.dao.RuleInfoRepository; +import cc.iotkit.data.model.TbRuleInfo; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.model.TbTaskInfo; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.model.rule.FilterConfig; +import cc.iotkit.model.rule.RuleAction; +import cc.iotkit.model.rule.RuleInfo; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +@Primary +@Service +public class RuleInfoDataImpl implements IRuleInfoData, IJPACommData { + + @Autowired + private RuleInfoRepository ruleInfoRepository; + + @Override + public JpaRepository getBaseRepository() { + return ruleInfoRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbRuleInfo.class; + } + + @Override + public Class getTClass() { + return RuleInfo.class; + } + + @Override + public List findByUidAndType(String uid, String type) { + return fromTb(ruleInfoRepository.findByUidAndType(uid, type)); + } + + @Override + public Paging findByUidAndType(String uid, String type, int page, int size) { + Page paged = ruleInfoRepository.findByUidAndType(uid, type, + Pageable.ofSize(size).withPage(page - 1)); + + return new Paging<>(paged.getTotalElements(), + fromTb(paged.getContent())); + } + + @Override + public Paging findByType(String type, int page, int size) { + Page paged = ruleInfoRepository.findByType(type, + Pageable.ofSize(size).withPage(page - 1)); + return new Paging<>(paged.getTotalElements(), + fromTb(paged.getContent())); + } + + @Override + public List findByUid(String uid) { + return fromTb(ruleInfoRepository.findByUid(uid)); + } + + @Override + public Paging findByUid(String uid, int page, int size) { + Page paged = ruleInfoRepository.findByUid(uid, + Pageable.ofSize(size).withPage(page - 1)); + return new Paging<>(paged.getTotalElements(), fromTb(paged.getContent())); + } + + @Override + public long countByUid(String uid) { + return ruleInfoRepository.countByUid(uid); + } + + + @Override + public RuleInfo findById(String s) { + return from(ruleInfoRepository.findById(s).orElse(null)); + } + + @Override + public List findByIds(Collection id) { + return null; + } + + @Override + public Paging findAll(PageRequest pageRequest) { + Page ret = ruleInfoRepository.findAll(PageBuilder.toPageable(pageRequest)); + return new Paging<>(ret.getTotalElements(), fromTb(ret.getContent())); + } + + @Override + public RuleInfo save(RuleInfo data) { + if (StringUtils.isBlank(data.getId())) { + data.setId(UUID.randomUUID().toString()); + data.setCreateAt(System.currentTimeMillis()); + } + ruleInfoRepository.save(from(data)); + return data; + } + + private static RuleInfo from(TbRuleInfo tb) { + RuleInfo convert = MapstructUtils.convert(tb, RuleInfo.class); + assert convert != null; + convert.setActions(JsonUtils.parseArray(tb.getActions(), RuleAction.class)); + convert.setFilters(JsonUtils.parseArray(tb.getFilters(), FilterConfig.class)); + convert.setListeners(JsonUtils.parseArray(tb.getListeners(), FilterConfig.class)); + return convert; + } + + private static TbRuleInfo from(RuleInfo rule) { + TbRuleInfo convert = MapstructUtils.convert(rule, TbRuleInfo.class); + assert convert != null; + convert.setActions(JsonUtils.toJsonString(rule.getActions())); + convert.setFilters(JsonUtils.toJsonString(rule.getFilters())); + convert.setListeners(JsonUtils.toJsonString(rule.getListeners())); + return convert; + } + + private static List fromTb(List list) { + if (list == null) { + return new ArrayList<>(); + } + return list.stream().map(RuleInfoDataImpl::from).collect(Collectors.toList()); + } + + private static List fromBo(List list) { + if (list == null) { + return new ArrayList<>(); + } + return list.stream().map(RuleInfoDataImpl::from).collect(Collectors.toList()); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ScreenApiDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ScreenApiDataImpl.java new file mode 100644 index 0000000..77706d5 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ScreenApiDataImpl.java @@ -0,0 +1,74 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.ScreenApiRepository; +import cc.iotkit.data.manager.IScreenApiData; +import cc.iotkit.data.model.TbScreenApi; +import cc.iotkit.model.screen.ScreenApi; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/6/25 15:21 + */ +@Primary +@Service +public class ScreenApiDataImpl implements IScreenApiData,IJPACommData { + + @Autowired + private ScreenApiRepository screenApiRepository; + + @Override + public JpaRepository getBaseRepository() { + return screenApiRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbScreenApi.class; + } + + @Override + public Class getTClass() { + return ScreenApi.class; + } + + @Override + public List findByScreenId(Long id) { + return MapstructUtils.convert(screenApiRepository.findByScreenId(id),ScreenApi.class); + } + + @Override + public void deleteByScreenId(Long id) { + screenApiRepository.deleteByScreenId(id); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ScreenDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ScreenDataImpl.java new file mode 100644 index 0000000..0ede76b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ScreenDataImpl.java @@ -0,0 +1,79 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.ScreenRepository; +import cc.iotkit.data.manager.IScreenData; +import cc.iotkit.data.model.TbScreen; +import cc.iotkit.model.screen.Screen; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/6/25 15:21 + */ +@Primary +@Service +@RequiredArgsConstructor +public class ScreenDataImpl implements IScreenData,IJPACommData { + + @Autowired + private ScreenRepository screenRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return screenRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbScreen.class; + } + + @Override + public Class getTClass() { + return Screen.class; + } + + @Override + public Screen findByIsDefault(boolean isDefault) { + return MapstructUtils.convert(screenRepository.findByIsDefault(isDefault),Screen.class); + } + + @Override + public List findByState(String state) { + return MapstructUtils.convert(screenRepository.findByState(state),Screen.class); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SpaceDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SpaceDataImpl.java new file mode 100644 index 0000000..f0f825c --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SpaceDataImpl.java @@ -0,0 +1,66 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SpaceRepository; +import cc.iotkit.data.manager.ISpaceData; +import cc.iotkit.data.model.TbSpace; +import cc.iotkit.model.space.Space; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Primary +@Service +public class SpaceDataImpl implements ISpaceData, IJPACommData { + + @Autowired + private SpaceRepository spaceRepository; + + + @Override + public JpaRepository getBaseRepository() { + return spaceRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSpace.class; + } + + @Override + public Class getTClass() { + return Space.class; + } + + @Override + public List findByHomeId(Long homeId) { + return MapstructUtils.convert(spaceRepository.findByHomeId(homeId), Space.class); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SpaceDeviceDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SpaceDeviceDataImpl.java new file mode 100644 index 0000000..da5b214 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SpaceDeviceDataImpl.java @@ -0,0 +1,87 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SpaceDeviceRepository; +import cc.iotkit.data.manager.ISpaceDeviceData; +import cc.iotkit.data.model.TbSpaceDevice; +import cc.iotkit.model.space.SpaceDevice; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Primary +@Service +public class SpaceDeviceDataImpl implements ISpaceDeviceData, IJPACommData { + + @Autowired + private SpaceDeviceRepository spaceDeviceRepository; + + + @Override + public JpaRepository getBaseRepository() { + return spaceDeviceRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSpaceDevice.class; + } + + @Override + public Class getTClass() { + return SpaceDevice.class; + } + + + @Override + public List findByHomeIdAndCollect(Long homeId, boolean collect) { + return MapstructUtils.convert(spaceDeviceRepository.findByHomeIdAndCollect(homeId, collect), SpaceDevice.class); + } + + @Override + public List findByHomeId(Long homeId) { + return MapstructUtils.convert(spaceDeviceRepository.findByHomeId(homeId), SpaceDevice.class); + } + + @Override + public List findBySpaceId(Long spaceId) { + return MapstructUtils.convert(spaceDeviceRepository.findBySpaceId(spaceId), SpaceDevice.class); + } + + @Override + public SpaceDevice findByDeviceId(String deviceId) { + return MapstructUtils.convert(spaceDeviceRepository.findByDeviceId(deviceId), SpaceDevice.class); + } + + @Override + public void deleteAllBySpaceId(Long spaceId) { + spaceDeviceRepository.deleteAllBySpaceId(spaceId); + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysAppDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysAppDataImpl.java new file mode 100644 index 0000000..bbd9cec --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysAppDataImpl.java @@ -0,0 +1,97 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysAppRepository; +import cc.iotkit.data.model.TbSysApp; +import cc.iotkit.data.system.ISysAppData; +import cc.iotkit.model.system.SysApp; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * 数据实现接口 + * + * @author Lion Li + * @date 2023-08-10 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysAppDataImpl implements ISysAppData, IJPACommData { + + private final SysAppRepository baseRepository; + + private final JPAQueryFactory jpaQueryFactory; + +// @Override +// public Paging findAll(PageRequest pageRequest) { +// return PageBuilder.toPaging(baseRepository.findAll(buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest))).to(SysApp.class); +// } + +// private Predicate buildQueryCondition(SysApp bo) { +// PredicateBuilder builder = PredicateBuilder.instance(); +// if(Objects.nonNull(bo)) { +// +// builder.and(StringUtils.isNotBlank(bo.getId()), () -> tbSysApp.ID.eq(bo.getId())); +// builder.and(StringUtils.isNotBlank(bo.getTenantId()), () -> tbSysApp.tenantId.eq(bo.getTenantId())); +// builder.and(StringUtils.isNotBlank(bo.getAppId()), () -> tbSysApp.appId.eq(bo.getAppId())); +// builder.and(StringUtils.isNotBlank(bo.getAppSecret()), () -> tbSysApp.appSecret.eq(bo.getAppSecret())); +// builder.and(StringUtils.isNotBlank(bo.getAppType()), () -> tbSysApp.appType.eq(bo.getAppType())); +// builder.and(StringUtils.isNotBlank(bo.getRemark()), () -> tbSysApp.REMARK.eq(bo.getRemark())); +// } +// return builder.build(); +// } + + @Override + public JpaRepository getBaseRepository() { + return baseRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysApp.class; + } + + @Override + public Class getTClass() { + return SysApp.class; + } + + @Override + public SysApp findByAppId(String appId) { + TbSysApp ret=baseRepository.findByAppId(appId); + if(ObjectUtil.isNotNull(ret)){ + return MapstructUtils.convert(ret,SysApp.class); + }else{ + return null; + } + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java new file mode 100644 index 0000000..e1cdf56 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java @@ -0,0 +1,166 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysConfigRepository; +import cc.iotkit.data.model.TbSysConfig; +import cc.iotkit.data.system.ISysConfigData; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysConfig; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.core.QueryResults; +import com.querydsl.core.types.Predicate; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.apache.commons.collections.IteratorUtils; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; + +import static cc.iotkit.data.model.QTbSysConfig.tbSysConfig; + +@Primary +@Service +@RequiredArgsConstructor +public class SysConfigDataImpl implements ISysConfigData, IJPACommData { + + private final SysConfigRepository baseRepository; + + + private final JPAQueryFactory jpaQueryFactory; + + + @Override + public JpaRepository getBaseRepository() { + return baseRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysConfig.class; + } + + @Override + public Class getTClass() { + return SysConfig.class; + } + + @Override + public SysConfig findById(Long id) { + TbSysConfig tbSysConfig = baseRepository.findById(id).orElseThrow(() -> + new BizException(ErrCode.DATA_NOT_EXIST)); + return MapstructUtils.convert(tbSysConfig, SysConfig.class); + } + + @Override + public SysConfig save(SysConfig data) { + baseRepository.save(MapstructUtils.convert(data, TbSysConfig.class)); + return data; + } + + @Override + public List findByIds(Collection id) { + Iterable allById = baseRepository.findAllById(id); + Iterator iterator = allById.iterator(); + return MapstructUtils.convert(IteratorUtils.toList(iterator), SysConfig.class); + } + + + + @Override + public Paging findAll(PageRequest pageRequest) { + SysConfig query = pageRequest.getData(); + Predicate predicate = PredicateBuilder.instance() + .and(StringUtils.isNotEmpty(query.getConfigName()), () -> tbSysConfig.configName.like(query.getConfigName())) + .and(StringUtils.isNotEmpty(query.getConfigType()), () -> tbSysConfig.configType.eq(query.getConfigType())) + .and(StringUtils.isNotEmpty(query.getConfigKey()), () -> tbSysConfig.configKey.like(query.getConfigKey())) + .build(); + Page all = baseRepository.findAll(predicate, PageBuilder.toPageable(pageRequest)); + return PageBuilder.toPaging(all, SysConfig.class); + } + + + @Override + public List findAllByCondition(SysConfig data) { + Predicate predicate = PredicateBuilder.instance() + .and(StringUtils.isNotEmpty(data.getConfigKey()), () -> tbSysConfig.configKey.eq(data.getConfigKey())) + .and(ObjectUtil.isNotNull(data.getTenantId()), () -> tbSysConfig.tenantId.eq(data.getTenantId())) + .build(); + Iterator iterator = baseRepository.findAll(predicate).iterator(); + return MapstructUtils.convert(IteratorUtils.toList(iterator), SysConfig.class); + } + + @Override + public SysConfig findOneByCondition(SysConfig data) { + Predicate predicate = PredicateBuilder.instance() + .and(StringUtils.isNotBlank(data.getConfigKey()), () -> tbSysConfig.configKey.eq(data.getConfigKey())) + .build(); + TbSysConfig tbSysConfig = baseRepository.findOne(predicate).orElse(null); + if(Objects.isNull(tbSysConfig)){ + return null; + } + return MapstructUtils.convert(tbSysConfig, SysConfig.class); + } + + @Override + public SysConfig findByConfigKey(String configKey) { + TbSysConfig tbSysConfig = baseRepository.findByConfigKey(configKey).orElse(null); + if(Objects.isNull(tbSysConfig)){ + return null; + } + return MapstructUtils.convert(tbSysConfig, SysConfig.class); + } + + @Override + public Paging findAllByConditions(PageRequest pageRequest) { + SysConfig data = pageRequest.getData(); + Predicate predicate = buildPredicate(data); + QueryResults tbSysConfigQueryResults = jpaQueryFactory.select(tbSysConfig).from(tbSysConfig).where(predicate).limit(pageRequest.getPageSize()).offset(pageRequest.getOffset()).fetchResults(); + return PageBuilder.queryResults2Page(tbSysConfigQueryResults, SysConfig.class); + + } + + private Predicate buildPredicate(SysConfig data) { + return PredicateBuilder.instance() + .and(StringUtils.isNotEmpty(data.getConfigKey()), () -> tbSysConfig.configKey.eq(data.getConfigKey())) + .and(StringUtils.isNotEmpty(data.getConfigName()), () -> tbSysConfig.configName.like(data.getConfigName())) + .and(StringUtils.isNotEmpty(data.getConfigType()), () -> tbSysConfig.configType.eq(data.getConfigType())) + .build(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java new file mode 100644 index 0000000..bbdb687 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java @@ -0,0 +1,139 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysDeptRepository; +import cc.iotkit.data.model.TbSysDept; +import cc.iotkit.data.system.ISysDeptData; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysDept; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import static cc.iotkit.data.model.QTbSysDept.tbSysDept; +import static cc.iotkit.data.model.QTbSysRoleDept.tbSysRoleDept; + +/** + * @Author:tfd + * @Date:2023/5/30 13:43 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysDeptDataImpl implements ISysDeptData, IJPACommData { + + @Autowired + private SysDeptRepository deptRepository; + + private final JPAQueryFactory jpaQueryFactory; + + + @Override + public JpaRepository getBaseRepository() { + return deptRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysDept.class; + } + + @Override + public Class getTClass() { + return SysDept.class; + } + + + @Override + public List findDepts(SysDept dept) { + PredicateBuilder predicateBuilder = PredicateBuilder.instance() + .and(ObjectUtil.isNotNull(dept.getId()), () -> tbSysDept.id.eq(dept.getId())) + .and(StringUtils.isNotEmpty(dept.getDeptName()), () -> tbSysDept.deptName.like(dept.getDeptName())) + .and(ObjectUtil.isNotNull(dept.getParentId()), () -> tbSysDept.parentId.eq(dept.getParentId())) + .and(StringUtils.isNotEmpty(dept.getStatus()), () -> tbSysDept.status.eq(dept.getStatus())); + if(ObjectUtil.isNotNull(dept.getAreaType()) && dept.getAreaType() == 1){ + //查询区域(需要查询parentId为0的顶级部门) + predicateBuilder.and(ObjectUtil.isNotNull(dept.getAreaType()), () -> tbSysDept.areaType.eq(dept.getAreaType()).or(tbSysDept.parentId.eq(0L))); + }else if(ObjectUtil.isNotNull(dept.getAreaType()) && dept.getAreaType() == 0){ + //查询部门 + predicateBuilder.and(ObjectUtil.isNotNull(dept.getAreaType()), () -> tbSysDept.areaType.eq(dept.getAreaType())); + } + return MapstructUtils.convert(StreamSupport.stream(deptRepository.findAll(predicateBuilder.build()).spliterator(), false).collect(Collectors.toList()), SysDept.class); + } + + @Override + public List findByRoleId(Long roleId) { + List list = jpaQueryFactory.select(tbSysDept).from(tbSysDept).leftJoin(tbSysRoleDept).on(tbSysDept.id.eq(tbSysRoleDept.deptId)) + .where(tbSysRoleDept.roleId.eq(roleId)).orderBy(tbSysDept.parentId.desc(), tbSysDept.orderNum.desc()).fetch(); + return MapstructUtils.convert(list, SysDept.class); + + } + + @Override + public long countByParentId(Long parentId) { + return jpaQueryFactory.select(tbSysDept.id.count()).from(tbSysDept).where(tbSysDept.parentId.eq(parentId)).fetchOne(); + } + + @Override + public List findByDeptId(Long deptId) { + return MapstructUtils.convert(deptRepository.findAll().stream().filter(o -> o.getAncestors() != null && o.getAncestors().contains(deptId.toString())) + .collect(Collectors.toList()), SysDept.class); + } + + @Override + public boolean checkDeptNameUnique(String deptName, Long parentId, Long deptId) { + PredicateBuilder predicateBuilder = PredicateBuilder.instance().and(tbSysDept.deptName.eq(deptName)) + .and(tbSysDept.parentId.eq(parentId)); + if (ObjectUtil.isNotNull(deptId)) { + predicateBuilder.and(tbSysDept.id.ne(deptId)); + } + Long count = jpaQueryFactory.select(tbSysDept.id.count()) + .from(tbSysDept) + .where(predicateBuilder.build()) + .fetchOne(); + return count == 0; + } + + @Override + public long selectNormalChildrenDeptById(Long deptId) { + + PredicateBuilder predicateBuilder = PredicateBuilder.instance().and(tbSysDept.status.eq(UserConstants.DEPT_NORMAL)); + return jpaQueryFactory.select(tbSysDept.ancestors).where(predicateBuilder.build()).fetch().stream().filter(o -> o.indexOf(deptId.toString()) != -1).count(); + + + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDictDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDictDataImpl.java new file mode 100644 index 0000000..7b182c7 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDictDataImpl.java @@ -0,0 +1,124 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysDictDataRepository; +import cc.iotkit.data.model.TbSysDictData; +import cc.iotkit.data.system.ISysDictData; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysDictData; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.core.types.Predicate; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +import static cc.iotkit.data.model.QTbSysDictData.tbSysDictData; + +/** + * @Author:tfd + * @Date:2023/5/30 13:43 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysDictDataImpl implements ISysDictData, IJPACommData { + + @Autowired + private SysDictDataRepository baseRepository; + + private final JPAQueryFactory jpaQueryFactory; + + + @Override + public JpaRepository getBaseRepository() { + return baseRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysDictData.class; + } + + @Override + public Class getTClass() { + return SysDictData.class; + } + + + @Override + public List findByConditions(SysDictData query) { + List rets=jpaQueryFactory.select(tbSysDictData).from(tbSysDictData) + .where(buildQueryCondition(query)).orderBy(tbSysDictData.dictSort.asc()) + .fetch(); + return MapstructUtils.convert(rets,SysDictData.class); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return PageBuilder.toPaging(baseRepository.findAll(buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest))).to(SysDictData.class); + } + + @Override + public SysDictData findByDictTypeAndDictValue(String dictType, String dictValue) { + return null; + } + + @Override + public List findByDicType(String dictType) { + List rets=jpaQueryFactory.select(tbSysDictData).from(tbSysDictData) + .where(PredicateBuilder.instance() + .and(tbSysDictData.status.eq(UserConstants.DICT_NORMAL)) + .and(tbSysDictData.dictType.eq(dictType)) + .build()).orderBy(tbSysDictData.dictSort.asc()) + .fetch(); + return MapstructUtils.convert(rets,SysDictData.class); + } + + @Override + public long countByDicType(String dictType) { + return 0; + } + + private Predicate buildQueryCondition(SysDictData dictData) { + return PredicateBuilder.instance() + .and(dictData.getDictSort() != null, () -> tbSysDictData.dictSort.eq(dictData.getDictSort())) + .and(StringUtils.isNotEmpty(dictData.getDictLabel()), () -> tbSysDictData.dictLabel.like(dictData.getDictLabel())) + .and(StringUtils.isNotEmpty(dictData.getDictType()), () -> tbSysDictData.dictType.eq(dictData.getDictType())) + .and(StringUtils.isNotEmpty(dictData.getStatus()), () -> tbSysDictData.status.eq(dictData.getStatus())) + .and(ObjectUtil.isNotNull(dictData.getTenantId()), () -> tbSysDictData.tenantId.eq(dictData.getTenantId())).build(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDictTypeDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDictTypeDataImpl.java new file mode 100644 index 0000000..6206369 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDictTypeDataImpl.java @@ -0,0 +1,129 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysDictTypeRepository; +import cc.iotkit.data.model.TbSysDictType; +import cc.iotkit.data.system.ISysDictTypeData; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysDictType; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.core.types.Predicate; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; + +import static cc.iotkit.data.model.QTbSysDictType.tbSysDictType; + +/** + * @Author:tfd + * @Date:2023/5/30 13:43 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysDictTypeDataImpl implements ISysDictTypeData, IJPACommData { + + @Autowired + private SysDictTypeRepository baseRepository; + + private final JPAQueryFactory jpaQueryFactory; + + + @Override + public Paging findAll(PageRequest pageRequest) { + return PageBuilder.toPaging(baseRepository.findAll(buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest))).to(SysDictType.class); + } + + @Override + public JpaRepository getBaseRepository() { + return baseRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysDictType.class; + } + + @Override + public Class getTClass() { + return SysDictType.class; + } + + + @Override + public List findByConditions(SysDictType query) { + List rets=jpaQueryFactory.select(tbSysDictType).from(tbSysDictType) + .where(buildQueryCondition(query)) + .fetch(); + return MapstructUtils.convert(rets, SysDictType.class); + } + + @Override + public Paging findByConditions(SysDictType query, int page, int size) { + return null; + } + + @Override + public SysDictType findByDicType(String dictType) { + return null; + } + + @Override + public void updateDicType(String dictType, String newType) { + + } + + @Override + public boolean checkDictTypeUnique(SysDictType dictType) { + final TbSysDictType ret = jpaQueryFactory.select(tbSysDictType).from(tbSysDictType) + .where(PredicateBuilder.instance() + .and(tbSysDictType.dictType.eq(dictType.getDictType())) + .and(Objects.nonNull(dictType.getId()), () -> tbSysDictType.id.ne(dictType.getId())) + .build()).fetchOne(); + return Objects.nonNull(ret); + } + + private Predicate buildQueryCondition(SysDictType dictType) { + return PredicateBuilder.instance() + .and(StringUtils.isNotEmpty(dictType.getDictName()), () -> tbSysDictType.dictName.like(dictType.getDictName())) + .and(StringUtils.isNotEmpty(dictType.getDictType()), () -> tbSysDictType.dictType.like(dictType.getDictType())) + .and(StringUtils.isNotEmpty(dictType.getStatus()), () -> tbSysDictType.status.eq(dictType.getStatus())) + .and(ObjectUtil.isNotNull(dictType.getTenantId()), () -> tbSysDictType.tenantId.eq(dictType.getTenantId())).build(); + } + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysLogininfoDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysLogininfoDataImpl.java new file mode 100644 index 0000000..67c40ee --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysLogininfoDataImpl.java @@ -0,0 +1,115 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysLogininforRepository; +import cc.iotkit.data.model.TbSysLogininfor; +import cc.iotkit.data.system.ISysLogininforData; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysLoginInfo; +import com.querydsl.core.types.Predicate; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +import static cc.iotkit.data.model.QTbSysLogininfor.tbSysLogininfor; + +/** + * @Author:tfd + * @Date:2023/5/31 15:58 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysLogininfoDataImpl implements ISysLogininforData, IJPACommData { + + private final SysLogininforRepository logininfoRepository; + + + private final JPAQueryFactory jpaQueryFactory; + + + @Override + public JpaRepository getBaseRepository() { + return logininfoRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysLogininfor.class; + } + + @Override + public Class getTClass() { + return SysLoginInfo.class; + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return PageBuilder.toPaging(logininfoRepository.findAll(genPredicate(pageRequest.getData()), PageBuilder.toPageable(pageRequest))).to(SysLoginInfo.class); + } + + @Override + public List findByConditions(SysLoginInfo data) { + List ret=jpaQueryFactory.selectFrom(tbSysLogininfor).where(genPredicate(data)) + .orderBy(tbSysLogininfor.id.desc()).fetch(); + return MapstructUtils.convert(ret, SysLoginInfo.class); + } + + private static Predicate genPredicate(SysLoginInfo data) { + return PredicateBuilder.instance() + .and(StringUtils.isNotBlank(data.getIpaddr()), () -> tbSysLogininfor.ipaddr.like(data.getIpaddr())) + .and(StringUtils.isNotBlank(data.getStatus()), () -> tbSysLogininfor.status.eq(data.getStatus())) + .and(StringUtils.isNotBlank(data.getUserName()), () -> tbSysLogininfor.userName.like(data.getUserName())) + .build(); + } + + @Override + public Paging findByConditions(SysLoginInfo cond, int page, int size) { + Page all = logininfoRepository.findAll(genPredicate(cond), PageBuilder.buildPageable(page, size)); + return PageBuilder.toPaging(all, SysLoginInfo.class); + } + + @Override + public void deleteByTenantId(Long tenantId) { + + } + + @Override + public void deleteAll() { + logininfoRepository.deleteAll(); + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java new file mode 100644 index 0000000..d4fcfdb --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java @@ -0,0 +1,249 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysMenuRepository; +import cc.iotkit.data.model.QTbSysMenu; +import cc.iotkit.data.model.TbSysMenu; +import cc.iotkit.data.system.ISysMenuData; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysMenu; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import static cc.iotkit.data.model.QTbSysMenu.tbSysMenu; +import static cc.iotkit.data.model.QTbSysRole.tbSysRole; +import static cc.iotkit.data.model.QTbSysRoleMenu.tbSysRoleMenu; +import static cc.iotkit.data.model.QTbSysUser.tbSysUser; +import static cc.iotkit.data.model.QTbSysUserRole.tbSysUserRole; + + +/** + * @Author: 石恒 + * @Date: 2023/5/28 15:43 + * @Description: + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysMenuDataImpl implements ISysMenuData, IJPACommData { + + private final SysMenuRepository sysMenuRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return sysMenuRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysMenu.class; + } + + @Override + public Class getTClass() { + return SysMenu.class; + } + + @Override + public SysMenu findById(Long id) { + TbSysMenu tbSysMenu = sysMenuRepository.findById(id).orElseThrow(() -> + new BizException(ErrCode.DATA_NOT_EXIST)); + return MapstructUtils.convert(tbSysMenu, SysMenu.class); + } + + @Override + public List findByIds(Collection ids) { + List list = sysMenuRepository.findAllById(ids); + return MapstructUtils.convert(list, SysMenu.class); + } + + @Override + public SysMenu save(SysMenu data) { + sysMenuRepository.save(MapstructUtils.convert(data, TbSysMenu.class)); + return data; + } + + @Override + public void batchSave(List data) { + List tbSysMenus = data.stream().map(e -> MapstructUtils.convert(e, TbSysMenu.class)).collect(Collectors.toList()); + sysMenuRepository.saveAll(tbSysMenus); + } + + @Override + public void deleteById(Long id) { + sysMenuRepository.deleteById(id); + } + + @Override + public void deleteByIds(Collection ids) { + sysMenuRepository.deleteAllByIdInBatch(ids); + } + + @Override + public List selectMenuList(SysMenu menu, Long userId, boolean isSuperAdmin) { + + PredicateBuilder predicateBuilder = PredicateBuilder.instance() + .and(StringUtils.isNotBlank(menu.getMenuName()), () -> tbSysMenu.menuName.like(menu.getMenuName())) + .and(StringUtils.isNotBlank(menu.getVisible()), () -> tbSysMenu.visible.eq(menu.getVisible())) + .and(StringUtils.isNotBlank(menu.getStatus()), () -> tbSysMenu.status.eq(menu.getStatus())); + + // 管理员显示所有菜单信息 + List tbSysMenuList; + if (isSuperAdmin) { + tbSysMenuList = jpaQueryFactory.select(tbSysMenu) + .from(tbSysMenu) + .where(predicateBuilder.build()) + .orderBy(tbSysMenu.parentId.asc(), tbSysMenu.orderNum.asc()).fetch(); + } else { + tbSysMenuList = jpaQueryFactory.select(Projections.bean(TbSysMenu.class, tbSysMenu.id, + tbSysMenu.parentId, tbSysMenu.menuName, tbSysMenu.path, tbSysMenu.component, tbSysMenu.queryParam, + tbSysMenu.visible, tbSysMenu.status, tbSysMenu.perms, tbSysMenu.isFrame, tbSysMenu.isCache, tbSysMenu.menuType, + tbSysMenu.icon, tbSysMenu.orderNum, tbSysMenu.createTime)) + .from(tbSysMenu) + .leftJoin(tbSysRoleMenu).on(tbSysMenu.id.eq(tbSysRoleMenu.menuId)) + .leftJoin(tbSysUserRole).on(tbSysRoleMenu.roleId.eq(tbSysUserRole.roleId)) + .leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id)) + .where(predicateBuilder + .and(tbSysUserRole.userId.eq(userId)) + .build()) + .orderBy(tbSysMenu.parentId.asc(), tbSysMenu.orderNum.asc()).fetch(); + + } + return MapstructUtils.convert(tbSysMenuList, SysMenu.class); + + } + + @Override + public List selectMenuPermsByUserId(Long userId) { + return jpaQueryFactory.select(tbSysMenu.perms) + .from(tbSysMenu) + .leftJoin(tbSysRoleMenu).on(tbSysMenu.id.eq(tbSysRoleMenu.menuId)) + .leftJoin(tbSysUserRole).on(tbSysRoleMenu.roleId.eq(tbSysUserRole.roleId)) + .leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id)) + .where(PredicateBuilder.instance() + .and(tbSysMenu.status.eq("0")) + .and(tbSysRole.status.eq("0")) + .and(tbSysUserRole.userId.eq(userId)) + .build()).fetch(); + } + + @Override + public List selectMenuPermsByRoleId(Long roleId) { + return jpaQueryFactory.select(Projections.bean(String.class, tbSysMenu.perms.countDistinct())) + .from(tbSysMenu) + .leftJoin(tbSysRoleMenu).on(tbSysMenu.id.eq(tbSysRoleMenu.menuId)) + .where(PredicateBuilder.instance() + .and(tbSysMenu.status.eq("0")) + .and(tbSysRoleMenu.roleId.eq(roleId)) + .build()).fetch(); + } + + @Override + public List selectMenuTreeAll() { + List rets= jpaQueryFactory.select(tbSysMenu) + .from(tbSysMenu) + .where(PredicateBuilder.instance() + .and(tbSysMenu.menuType.in(UserConstants.TYPE_DIR, UserConstants.TYPE_MENU)) + .and(tbSysMenu.status.eq(UserConstants.MENU_NORMAL)) + .build()) + .orderBy(tbSysMenu.parentId.asc(), tbSysMenu.orderNum.asc()).fetch(); + return MapstructUtils.convert(rets,SysMenu.class); + } + + @Override + public List selectMenuTreeByUserId(Long userId) { + return jpaQueryFactory.select(Projections.bean(SysMenu.class, tbSysMenu.id.as(tbSysMenu.id), + tbSysMenu.parentId, tbSysMenu.menuName, tbSysMenu.path, tbSysMenu.component, tbSysMenu.queryParam, + tbSysMenu.visible, tbSysMenu.status, tbSysMenu.perms, tbSysMenu.isFrame, tbSysMenu.isCache, tbSysMenu.menuType, + tbSysMenu.icon, tbSysMenu.orderNum, tbSysMenu.createTime)) + .distinct() + .from(tbSysMenu) + .leftJoin(tbSysRoleMenu).on(tbSysMenu.id.eq(tbSysRoleMenu.menuId)) + .leftJoin(tbSysUserRole).on(tbSysRoleMenu.roleId.eq(tbSysUserRole.roleId)) + .leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id)) + .leftJoin(tbSysUser).on(tbSysUserRole.userId.eq(tbSysUser.id)) + .where(PredicateBuilder.instance() + .and(tbSysUser.id.eq(userId)) + .and(tbSysMenu.menuType.in("M", "C")) + .and(tbSysMenu.status.eq("0")) + .and(tbSysRole.status.eq("0")) + .build()) + .orderBy(tbSysMenu.parentId.asc(), tbSysMenu.orderNum.asc()).fetch(); + } + + @Override + public boolean hasChildByMenuId(Long menuId) { + TbSysMenu tbSysMenu = jpaQueryFactory.select(QTbSysMenu.tbSysMenu).from(QTbSysMenu.tbSysMenu) + .where(QTbSysMenu.tbSysMenu.parentId.eq(menuId)).limit(1).fetchOne(); + return Objects.nonNull(tbSysMenu); + } + + @Override + public boolean checkMenuNameUnique(SysMenu menu) { + TbSysMenu tbSysMenu = jpaQueryFactory.select(QTbSysMenu.tbSysMenu).from(QTbSysMenu.tbSysMenu) + .where( + PredicateBuilder.instance() + .and(QTbSysMenu.tbSysMenu.menuName.eq(menu.getMenuName())) + .and(QTbSysMenu.tbSysMenu.parentId.eq(menu.getParentId())) + .and(ObjectUtil.isNotNull(menu.getId()), () -> QTbSysMenu.tbSysMenu.id.ne(menu.getId())) + .build()).fetchOne(); + return Objects.isNull(tbSysMenu); + } + + @Override + public List selectParentIdByMenuIds(List menuIds) { + return jpaQueryFactory.select(tbSysMenu.parentId).from(tbSysMenu).where(tbSysMenu.id.in(menuIds)).fetch(); + + } + + @Override + public List findByMenuIdListAndNotParentIdList(List menuIds, List parentIds) { + Predicate build = PredicateBuilder.instance() + .and(tbSysMenu.id.in(menuIds)) + .and(CollectionUtil.isNotEmpty(parentIds), () -> tbSysMenu.id.notIn(parentIds)).build(); + return jpaQueryFactory.select(tbSysMenu.id).from(tbSysMenu).where(build).fetch(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysNoticeDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysNoticeDataImpl.java new file mode 100644 index 0000000..4ef3ebc --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysNoticeDataImpl.java @@ -0,0 +1,97 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysNoticRepository; +import cc.iotkit.data.model.TbSysNotice; +import cc.iotkit.data.system.ISysNoticeData; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysNotice; +import com.querydsl.core.QueryResults; +import com.querydsl.core.types.Predicate; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import static cc.iotkit.data.model.QTbSysNotice.tbSysNotice; + +/** + * @Author:tfd + * @Date:2023/5/30 13:43 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysNoticeDataImpl implements ISysNoticeData, IJPACommData { + + @Autowired + private SysNoticRepository baseRepository; + + private final JPAQueryFactory jpaQueryFactory; + + + @Override + public JpaRepository getBaseRepository() { + return baseRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysNotice.class; + } + + @Override + public Class getTClass() { + return SysNotice.class; + } + + + @Override + public Paging findByConditions(PageRequest pageRequest) { + SysNotice data = pageRequest.getData(); + Predicate predicate = buildQueryCondition(data); + QueryResults tbSysNoticeQueryResults = jpaQueryFactory.select(tbSysNotice).from(tbSysNotice).where(predicate).offset(pageRequest.getOffset()).limit(pageRequest.getPageSize()).fetchResults(); + return new Paging<>(tbSysNoticeQueryResults.getTotal(), MapstructUtils.convert(tbSysNoticeQueryResults.getResults(), SysNotice.class)); + } + + private Predicate buildQueryCondition(SysNotice query) { + return PredicateBuilder.instance().and(StringUtils.isNotBlank(query.getNoticeTitle()), ()-> + tbSysNotice.noticeTitle.like(query.getNoticeTitle())) + .and(StringUtils.isNotBlank(query.getNoticeType()), ()-> + tbSysNotice.noticeType.eq(query.getNoticeType())) + .and(StringUtils.isNotBlank(query.getStatus()), ()-> + tbSysNotice.status.eq(query.getStatus())) + .and(StringUtils.isNotBlank(query.getCreateByName()), ()->( + tbSysNotice.createBy.like(query.getCreateByName()))) + .build(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOperLogDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOperLogDataImpl.java new file mode 100644 index 0000000..7c4ebdf --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOperLogDataImpl.java @@ -0,0 +1,120 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysOperLogRepository; +import cc.iotkit.data.model.TbSysOperLog; +import cc.iotkit.data.system.ISysOperLogData; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysOperLog; +import cn.hutool.core.util.ArrayUtil; +import com.querydsl.core.types.Predicate; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.List; + +import static cc.iotkit.data.model.QTbSysOperLog.tbSysOperLog; + +/** + * @Author:tfd + * @Date:2023/5/31 15:24 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysOperLogDataImpl implements ISysOperLogData, IJPACommData { + + private final SysOperLogRepository operLogRepository; + + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return operLogRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysOperLog.class; + } + + @Override + public Class getTClass() { + return SysOperLog.class; + } + + @Override + public Paging findByConditions(Long tenantId, String title, Integer businessType, Integer status, int page, int size) { + return null; + } + + @Override + public void deleteByTenantId(Long tenantId) { + + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return PageBuilder.toPaging( + operLogRepository.findAll( + buildQueryCondition(pageRequest.getData()), + PageBuilder.toPageable(pageRequest)) + , SysOperLog.class + ); + } + + @Override + public void deleteAll() { + operLogRepository.deleteAll(); + } + + @Override + public List findAllByCondition(SysOperLog data) { + List ret = jpaQueryFactory.selectFrom(tbSysOperLog).where(buildQueryCondition(data)) + .orderBy(tbSysOperLog.id.desc()).fetch(); + return MapstructUtils.convert(ret, SysOperLog.class); + } + + private Predicate buildQueryCondition(SysOperLog data) { + return PredicateBuilder.instance() + .and(StringUtils.isNotBlank(data.getTitle()), () -> tbSysOperLog.title.like(data.getTitle())) + .and(data.getBusinessType() != null && data.getBusinessType() > 0, () -> tbSysOperLog.businessType.eq(data.getBusinessType())) + .and(ArrayUtil.isNotEmpty(data.getBusinessTypes()), () -> tbSysOperLog.businessType.in(Arrays.asList(data.getBusinessTypes()))) + .and(data.getStatus() != null && data.getStatus() > 0, () -> tbSysOperLog.status.eq(data.getStatus())) + .and(StringUtils.isNotBlank(data.getOperName()), () -> tbSysOperLog.operName.like(data.getOperName())) + .build(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOssConfigDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOssConfigDataImpl.java new file mode 100644 index 0000000..357571b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOssConfigDataImpl.java @@ -0,0 +1,67 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysOssConfigRepository; +import cc.iotkit.data.model.TbSysOssConfig; +import cc.iotkit.data.system.ISysOssConfigData; +import cc.iotkit.model.system.SysOssConfig; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @Author:tfd + * @Date:2023/5/31 15:24 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysOssConfigDataImpl implements ISysOssConfigData, IJPACommData { + + private final SysOssConfigRepository operLogRepository; + + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return operLogRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysOssConfig.class; + } + + @Override + public Class getTClass() { + return SysOssConfig.class; + } + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOssDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOssDataImpl.java new file mode 100644 index 0000000..0c10791 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOssDataImpl.java @@ -0,0 +1,69 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysOssRepository; +import cc.iotkit.data.model.TbSysOss; +import cc.iotkit.data.system.ISysOssData; +import cc.iotkit.model.system.SysOss; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @Author:tfd + * @Date:2023/5/30 13:43 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysOssDataImpl implements ISysOssData, IJPACommData { + + @Autowired + private SysOssRepository baseRepository; + + private final JPAQueryFactory jpaQueryFactory; + + + @Override + public JpaRepository getBaseRepository() { + return baseRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysOss.class; + } + + @Override + public Class getTClass() { + return SysOss.class; + } + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysPostDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysPostDataImpl.java new file mode 100644 index 0000000..3325b2b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysPostDataImpl.java @@ -0,0 +1,133 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysPostRepository; +import cc.iotkit.data.model.TbSysPost; +import cc.iotkit.data.system.ISysPostData; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysPost; +import com.querydsl.core.types.Predicate; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; + +import static cc.iotkit.data.model.QTbSysPost.tbSysPost; +import static cc.iotkit.data.model.QTbSysUser.tbSysUser; +import static cc.iotkit.data.model.QTbSysUserPost.tbSysUserPost; + +/** + * @Author:tfd + * @Date:2023/5/30 18:20 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysPostDataImpl implements ISysPostData, IJPACommData { + + private final SysPostRepository postRepository; + + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return postRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysPost.class; + } + + @Override + public Class getTClass() { + return SysPost.class; + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return PageBuilder.toPaging( + postRepository.findAll( + buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest)) + , SysPost.class + ); + } + + @Override + public List selectPostListByUserId(Long userId) { + return jpaQueryFactory.select(tbSysPost.id) + .from(tbSysPost) + .leftJoin(tbSysUserPost).on(tbSysUserPost.postId.eq(tbSysPost.id)) + .leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserPost.userId)) + .where(PredicateBuilder.instance() + .and(tbSysUser.id.eq(userId)) + .build()).fetch(); + } + + @Override + public List selectPostList(SysPost post) { + List ret = jpaQueryFactory.selectFrom(tbSysPost).where(buildQueryCondition(post)) + .orderBy(tbSysPost.postSort.asc()).fetch(); + return MapstructUtils.convert(ret, SysPost.class); + } + + @Override + public boolean checkPostNameUnique(SysPost post) { + final TbSysPost ret = jpaQueryFactory.selectFrom(tbSysPost) + .where(PredicateBuilder.instance() + .and(tbSysPost.postName.eq(post.getPostName())) + .and(Objects.nonNull(post.getId()), () -> tbSysPost.id.eq(post.getId())) + .build()).fetchOne(); + return Objects.isNull(ret); + } + + @Override + public boolean checkPostCodeUnique(SysPost post) { + final TbSysPost ret = jpaQueryFactory.selectFrom(tbSysPost) + .where(PredicateBuilder.instance() + .and(tbSysPost.postCode.eq(post.getPostCode())) + .and(Objects.nonNull(post.getId()), () -> tbSysPost.id.eq(post.getId())) + .build()).fetchOne(); + return Objects.isNull(ret); + } + + private Predicate buildQueryCondition(SysPost post) { + return PredicateBuilder.instance() + .and(StringUtils.isNotBlank(post.getPostCode()), () -> tbSysPost.postCode.like(post.getPostCode())) + .and(StringUtils.isNotBlank(post.getPostName()), () -> tbSysPost.postName.like(post.getPostName())) + .and(StringUtils.isNotBlank(post.getStatus()), () -> tbSysPost.status.eq(post.getStatus())).build(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDataImpl.java new file mode 100644 index 0000000..d795c6b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDataImpl.java @@ -0,0 +1,218 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysRoleRepository; +import cc.iotkit.data.model.TbSysRole; +import cc.iotkit.data.system.ISysRoleData; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysRole; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; + +import static cc.iotkit.data.model.QTbSysDept.tbSysDept; +import static cc.iotkit.data.model.QTbSysMenu.tbSysMenu; +import static cc.iotkit.data.model.QTbSysRole.tbSysRole; +import static cc.iotkit.data.model.QTbSysRoleMenu.tbSysRoleMenu; +import static cc.iotkit.data.model.QTbSysUser.tbSysUser; +import static cc.iotkit.data.model.QTbSysUserRole.tbSysUserRole; + +/** + * author: 石恒 + * date: 2023-05-29 16:23 + * description: + **/ +@Primary +@Service +@RequiredArgsConstructor +public class SysRoleDataImpl implements ISysRoleData, IJPACommData { + + private final SysRoleRepository sysRoleRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return sysRoleRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysRole.class; + } + + @Override + public Class getTClass() { + return SysRole.class; + } + + @Override + public SysRole findById(Long id) { + return MapstructUtils.convert(sysRoleRepository.findById(id).orElse(null), SysRole.class); + } + + @Override + public List selectMenuListByRoleId(Long roleId, boolean menuCheckStrictly) { + + + PredicateBuilder predicateBuilder = PredicateBuilder.instance() + .and(tbSysRoleMenu.roleId.eq(roleId)); + + if (menuCheckStrictly) { + List roleIds = jpaQueryFactory.select(tbSysMenu.parentId) + .from(tbSysMenu) + .innerJoin(tbSysRoleMenu).on(tbSysMenu.id.eq(tbSysRoleMenu.menuId).and(tbSysRoleMenu.roleId.eq(roleId))) + .fetch(); + predicateBuilder.and(tbSysMenu.id.notIn(roleIds)); + } + + return jpaQueryFactory.select( tbSysMenu.id) + .from(tbSysMenu) + .leftJoin(tbSysRoleMenu).on(tbSysMenu.id.eq(tbSysRoleMenu.menuId)) + .where(predicateBuilder.build()) + .orderBy(tbSysMenu.parentId.asc(), tbSysMenu.orderNum.asc()).fetch(); + } + + @Override + public List selectRolePermissionByUserId(Long userId) { + return buildQueryTitle(PredicateBuilder.instance() + .and(tbSysRole.delFlag.eq(UserConstants.NORMAL)) + .and(tbSysUserRole.userId.eq(userId)) + .build()); + } + + @Override + public List selectRoleListByUserId(Long userId) { + return jpaQueryFactory.select(tbSysRole.id).from(tbSysRole) + .leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.id)) + .leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserRole.userId)) + .where(PredicateBuilder.instance().and(tbSysUser.id.eq(userId)).build()).fetch(); + + } + + @Override + public boolean checkRoleNameUnique(SysRole role) { + final TbSysRole tbSysRoleRes = jpaQueryFactory.select(tbSysRole).from(tbSysRole) + .where(PredicateBuilder.instance() + .and(tbSysRole.roleName.eq(role.getRoleName())) + .and(Objects.nonNull(role.getId()), () -> tbSysRole.id.ne(role.getId())) + .build()).fetchOne(); + return Objects.isNull(tbSysRoleRes); + } + + @Override + public boolean checkRoleKeyUnique(SysRole role) { + final TbSysRole tbSysRoleRes = jpaQueryFactory.select(tbSysRole).from(tbSysRole) + .where(PredicateBuilder.instance() + .and(tbSysRole.roleKey.eq(role.getRoleKey())) + .and(Objects.nonNull(role.getId()), () -> tbSysRole.id.ne(role.getId())) + .build()).fetchOne(); + return Objects.isNull(tbSysRoleRes); + } + + @Override + public int updateById(SysRole role) { + long execute = jpaQueryFactory.update(tbSysRole) + .set(tbSysRole.roleName, role.getRoleName()) + .set(tbSysRole.roleKey, role.getRoleKey()) + .set(tbSysRole.roleSort, role.getRoleSort()) + .set(tbSysRole.dataScope, role.getDataScope()) + .set(tbSysRole.status, role.getStatus()) + .set(tbSysRole.menuCheckStrictly, role.getMenuCheckStrictly()) + .set(tbSysRole.deptCheckStrictly, role.getDeptCheckStrictly()) + .set(tbSysRole.remark, role.getRemark()) + .where(PredicateBuilder.instance().and(tbSysRole.id.eq(role.getId())).build()).execute(); + return Integer.parseInt(execute + ""); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return PageBuilder.toPaging( + sysRoleRepository.findAll( + buildQueryWrapper(pageRequest.getData()), + PageBuilder.toPageable(pageRequest)) + , SysRole.class + ); + } + + @Override + public List selectRoleList(SysRole role) { + return buildQueryTitle(buildQueryWrapper(role)); + } + + @Override + public List findByUserId(Long id) { + return jpaQueryFactory.select(Projections.bean(SysRole.class, tbSysRole.id, tbSysRole.roleName, tbSysRole.roleKey, tbSysRole.roleSort, tbSysRole.dataScope, tbSysRole.status, tbSysRole.delFlag, tbSysRole.createTime, tbSysRole.remark)) + .from(tbSysRole) + .leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.id)) + .where(tbSysUserRole.userId.eq(id)) + .fetch(); + } + + private List buildQueryTitle(Predicate predicate) { + return jpaQueryFactory.selectDistinct(tbSysRole.id) + .select(Projections.fields(SysRole.class, tbSysRole.id, tbSysRole.roleName, + tbSysRole.roleKey, tbSysRole.roleSort, tbSysRole.menuCheckStrictly, tbSysRole.deptCheckStrictly, + tbSysRole.status, tbSysRole.delFlag, tbSysRole.createTime, tbSysRole.remark)) + .from(tbSysRole) + .leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.id)) + .leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserRole.userId)) + .leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.id)) + .where(predicate) + .orderBy(tbSysRole.roleSort.asc(), tbSysRole.createTime.asc()).fetch(); + } + + private Predicate buildQueryWrapper(SysRole role) { + return PredicateBuilder.instance() + .and(tbSysRole.delFlag.eq(UserConstants.ROLE_NORMAL)) + .and(Objects.nonNull(role.getId()), () -> tbSysRole.id.eq(role.getId())) + .and(StringUtils.isNotBlank(role.getRoleName()), () -> tbSysRole.roleName.like(role.getRoleName())) + .and(StringUtils.isNotBlank(role.getStatus()), () -> tbSysRole.roleName.eq(role.getStatus())) + .and(StringUtils.isNotBlank(role.getRoleKey()), () -> tbSysRole.roleKey.like(role.getRoleKey())) + .and(ObjectUtil.isNotNull(role.getTenantId()), () -> tbSysRole.tenantId.eq(role.getTenantId())) + .build(); + + } + + @Override + public void deleteById(Long id) { + jpaQueryFactory.delete(tbSysRole).where(tbSysRole.id.eq(id)).execute(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDeptDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDeptDataImpl.java new file mode 100644 index 0000000..ae00ff8 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDeptDataImpl.java @@ -0,0 +1,82 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysRoleDeptRepository; +import cc.iotkit.data.model.TbSysRoleDept; +import cc.iotkit.data.system.ISysRoleDeptData; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysRoleDept; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; + +import static cc.iotkit.data.model.QTbSysRoleDept.tbSysRoleDept; + +/** + * author: 石恒 + * date: 2023-05-30 16:20 + * description: + **/ +@Primary +@Service +@RequiredArgsConstructor +public class SysRoleDeptDataImpl implements ISysRoleDeptData, IJPACommData { + + + private final SysRoleDeptRepository sysRoleDeptRepository; + private final JPAQueryFactory jpaQueryFactory; + + @Override + public void deleteByRoleId(Collection roleIds) { + jpaQueryFactory.delete(tbSysRoleDept).where(PredicateBuilder.instance().and(tbSysRoleDept.roleId.in(roleIds)).build()).execute(); + } + + @Override + public long insertBatch(List list) { + return sysRoleDeptRepository.saveAll(MapstructUtils.convert(list,TbSysRoleDept.class)).size(); + } + + @Override + public JpaRepository getBaseRepository() { + return sysRoleDeptRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysRoleDept.class; + } + + @Override + public Class getTClass() { + return SysRoleDept.class; + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleMenuDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleMenuDataImpl.java new file mode 100644 index 0000000..8ab4217 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleMenuDataImpl.java @@ -0,0 +1,97 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysRoleMenuRepository; +import cc.iotkit.data.model.QTbSysRoleMenu; +import cc.iotkit.data.model.TbSysRoleMenu; +import cc.iotkit.data.system.ISysRoleMenuData; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysRoleMenu; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; +import java.util.Objects; + +import static cc.iotkit.data.model.QTbSysRoleMenu.tbSysRoleMenu; + +/** + * author: 石恒 + * date: 2023-05-30 11:00 + * description: + **/ +@Primary +@Service +@RequiredArgsConstructor +public class SysRoleMenuDataImpl implements ISysRoleMenuData, IJPACommData { + + + private final SysRoleMenuRepository sysRoleMenuRepository; + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return sysRoleMenuRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysRoleMenu.class; + } + + @Override + public Class getTClass() { + return SysRoleMenu.class; + } + + @Override + public boolean checkMenuExistRole(Long menuId) { + return jpaQueryFactory + .select(QTbSysRoleMenu.tbSysRoleMenu.count()) + .from(QTbSysRoleMenu.tbSysRoleMenu) + .where(PredicateBuilder.instance() + .and(QTbSysRoleMenu.tbSysRoleMenu.menuId.eq(menuId)) + .build()).fetchOne() > 0; + } + + @Override + public long insertBatch(List list) { + List tbSysRoleMenus = Objects.requireNonNull(MapstructUtils.convert(list, TbSysRoleMenu.class)); + return sysRoleMenuRepository.saveAll(tbSysRoleMenus).size(); + } + + @Override + public long deleteByRoleId(Collection ids) { + return jpaQueryFactory.delete(tbSysRoleMenu).where(tbSysRoleMenu.roleId.in(ids)).execute(); + } + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantDataImpl.java new file mode 100644 index 0000000..7322218 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantDataImpl.java @@ -0,0 +1,125 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.helper.TenantHelper; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysTenantRepository; +import cc.iotkit.data.model.TbSysTenant; +import cc.iotkit.data.system.ISysTenantData; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.TenantModel; +import cc.iotkit.model.system.SysTenant; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.bean.copier.CopyOptions; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +import static cc.iotkit.data.model.QTbSysTenant.tbSysTenant; + +/** + * @Author:tfd + * @Date:2023/5/31 9:45 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysTenantDataImpl implements ISysTenantData, IJPACommData { + + private final SysTenantRepository sysTenantRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return sysTenantRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysTenant.class; + } + + @Override + public Class getTClass() { + return SysTenant.class; + } + + + @Override + public List findAllByCondition(SysTenant data) { + List ret=jpaQueryFactory.selectFrom(tbSysTenant).where(PredicateBuilder.instance() + + .and(StringUtils.isNotBlank(data.getContactUserName()),()->tbSysTenant.contactUserName.like(data.getContactUserName())) + .and(StringUtils.isNotBlank(data.getContactPhone()),()->tbSysTenant.contactPhone.eq(data.getContactPhone())) + .and(StringUtils.isNotBlank(data.getCompanyName()),()->tbSysTenant.companyName.like(data.getCompanyName())) + .and(StringUtils.isNotBlank(data.getLicenseNumber()),()->tbSysTenant.licenseNumber.eq(data.getLicenseNumber())) + .and(StringUtils.isNotBlank(data.getAddress()),()->tbSysTenant.address.eq(data.getAddress())) + .and(StringUtils.isNotBlank(data.getIntro()),()->tbSysTenant.intro.eq(data.getIntro())) + .and(StringUtils.isNotBlank(data.getDomain()),()->tbSysTenant.domain.like(data.getDomain())) + .and(data.getPackageId() != null,()->tbSysTenant.packageId.eq(data.getPackageId())) + .and(data.getExpireTime() != null,()->tbSysTenant.expireTime.eq(data.getExpireTime())) + .and(data.getAccountCount() != null,()->tbSysTenant.accountCount.eq(data.getAccountCount())) + .and(StringUtils.isNotBlank(data.getStatus()),()->tbSysTenant.status.eq(data.getStatus())) + .build()).fetch(); + return MapstructUtils.convert(ret, SysTenant.class); + } + + @Override + public boolean checkCompanyNameUnique(SysTenant tenant) { + final TbSysTenant ret = jpaQueryFactory.select(tbSysTenant).from(tbSysTenant) + .where(PredicateBuilder.instance() + .and(tbSysTenant.companyName.eq(tenant.getCompanyName())) + .and(Objects.nonNull(tenant.getId()), () -> tbSysTenant.id.ne(tenant.getId())) + .build()).fetchOne(); + return Objects.isNull(ret); + } + @Override + public SysTenant save(SysTenant data) { + Long id = data.getId(); + Object tbData = MapstructUtils.convert(data, getJpaRepositoryClass()); + Optional byId = id == null ? Optional.empty() : getBaseRepository().findById(id); + if (byId.isPresent()) { + Object dbObj = byId.get(); + //只更新不为空的字段 + BeanUtil.copyProperties(tbData, dbObj, CopyOptions.create().ignoreNullValue()); + tbData = dbObj; + } + + Object o = getBaseRepository().save(tbData); + return (SysTenant) MapstructUtils.convert(o, getTClass()); + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantPackageDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantPackageDataImpl.java new file mode 100644 index 0000000..11f4c49 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantPackageDataImpl.java @@ -0,0 +1,69 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysTenantPackageRepository; +import cc.iotkit.data.model.TbSysTenantPackage; +import cc.iotkit.data.system.ISysTenantPackageData; +import cc.iotkit.model.system.SysTenantPackage; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @Author:tfd + * @Date:2023/5/30 13:43 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysTenantPackageDataImpl implements ISysTenantPackageData, IJPACommData { + + @Autowired + private SysTenantPackageRepository baseRepository; + + private final JPAQueryFactory jpaQueryFactory; + + + @Override + public JpaRepository getBaseRepository() { + return baseRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysTenantPackage.class; + } + + @Override + public Class getTClass() { + return SysTenantPackage.class; + } + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserAreaDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserAreaDataImpl.java new file mode 100644 index 0000000..3f84fa5 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserAreaDataImpl.java @@ -0,0 +1,107 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.tenant.helper.TenantHelper; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysUserAreaRepository; +import cc.iotkit.data.dao.SysUserRepository; +import cc.iotkit.data.model.TbSysPost; +import cc.iotkit.data.model.TbSysRole; +import cc.iotkit.data.model.TbSysUser; +import cc.iotkit.data.model.TbSysUserArea; +import cc.iotkit.data.system.ISysDeptData; +import cc.iotkit.data.system.ISysRoleData; +import cc.iotkit.data.system.ISysUserAreaData; +import cc.iotkit.data.system.ISysUserData; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysDept; +import cc.iotkit.model.system.SysRole; +import cc.iotkit.model.system.SysUser; +import cc.iotkit.model.system.SysUserArea; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.core.QueryResults; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +import static cc.iotkit.data.model.QTbSysDept.tbSysDept; +import static cc.iotkit.data.model.QTbSysPost.tbSysPost; +import static cc.iotkit.data.model.QTbSysRole.tbSysRole; +import static cc.iotkit.data.model.QTbSysUser.tbSysUser; +import static cc.iotkit.data.model.QTbSysUserPost.tbSysUserPost; +import static cc.iotkit.data.model.QTbSysUserRole.tbSysUserRole; + + +/** + * @Author:tfd + * @Date:2023/5/29 16:00 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysUserAreaDataImpl implements ISysUserAreaData, IJPACommData { + + private final SysUserAreaRepository userAreaRepository; + + private final ISysDeptData sysDeptData; + + private final ISysRoleData sysRoleData; + + private final JPAQueryFactory jpaQueryFactory; + + + @Override + public JpaRepository getBaseRepository() { + return userAreaRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysUserArea.class; + } + + @Override + public Class getTClass() { + return SysUserArea.class; + } + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java new file mode 100644 index 0000000..146a7c8 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java @@ -0,0 +1,376 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.tenant.helper.TenantHelper; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysUserRepository; +import cc.iotkit.data.model.TbSysPost; +import cc.iotkit.data.model.TbSysRole; +import cc.iotkit.data.model.TbSysUser; +import cc.iotkit.data.system.ISysDeptData; +import cc.iotkit.data.system.ISysRoleData; +import cc.iotkit.data.system.ISysUserData; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysDept; +import cc.iotkit.model.system.SysRole; +import cc.iotkit.model.system.SysUser; +import cn.hutool.core.util.ObjectUtil; +import com.querydsl.core.QueryResults; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +import static cc.iotkit.data.model.QTbSysDept.tbSysDept; +import static cc.iotkit.data.model.QTbSysPost.tbSysPost; +import static cc.iotkit.data.model.QTbSysRole.tbSysRole; +import static cc.iotkit.data.model.QTbSysUser.tbSysUser; +import static cc.iotkit.data.model.QTbSysUserPost.tbSysUserPost; +import static cc.iotkit.data.model.QTbSysUserRole.tbSysUserRole; + + +/** + * @Author:tfd + * @Date:2023/5/29 16:00 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysUserDataImpl implements ISysUserData, IJPACommData { + + private final SysUserRepository userRepository; + + private final ISysDeptData sysDeptData; + + private final ISysRoleData sysRoleData; + + private final JPAQueryFactory jpaQueryFactory; + + + @Override + public JpaRepository getBaseRepository() { + return userRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysUser.class; + } + + @Override + public Class getTClass() { + return SysUser.class; + } + + @Override + public long countByDeptId(Long aLong) { + return 0; + } + + @Override + public boolean checkUserNameUnique(SysUser user) { + final TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser) + .where(PredicateBuilder.instance() + .and(tbSysUser.userName.eq(user.getUserName())) + .and(Objects.nonNull(user.getId()), () -> tbSysUser.id.ne(user.getId())) + .build()).fetchOne(); + return Objects.isNull(ret); + } + + @Override + public boolean checkPhoneUnique(SysUser user) { + final TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser) + .where(PredicateBuilder.instance() + .and(tbSysUser.phonenumber.eq(user.getPhonenumber())) + .and(Objects.nonNull(user.getId()), () -> tbSysUser.id.ne(user.getId())) + .build()).fetchOne(); + return Objects.isNull(ret); + } + + @Override + public SysUser findById(Long id) { + Optional optUser = userRepository.findById(id); + if (optUser.isEmpty()) { + return null; + } + + SysUser convert = MapstructUtils.convert(optUser.get(), SysUser.class); + List sysRoles = sysRoleData.findByUserId(id); + convert.setRoles(sysRoles); + + Long deptId = convert.getDeptId(); + if (deptId == null) { + return convert; + } + + SysDept dept = sysDeptData.findById(deptId); + if (ObjectUtil.isNotNull(dept)) { + convert.setDept(dept); + } + + Long areaDeptId = convert.getDeptAreaId(); + if (areaDeptId == null) { + return convert; + } + + SysDept areaDept = sysDeptData.findById(areaDeptId); + if (ObjectUtil.isNotNull(areaDept)) { + convert.setAreaDept(areaDept); + } + return convert; + } + + @Override + public boolean checkEmailUnique(SysUser user) { + final TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser) + .where(PredicateBuilder.instance() + .and(tbSysUser.email.eq(user.getEmail())) + .and(Objects.nonNull(user.getId()), () -> tbSysUser.id.ne(user.getId())) + .build()).fetchOne(); + return Objects.isNull(ret); + } + + @Override + public SysUser selectByPhonenumber(String phonenumber) { + TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser) + .where(PredicateBuilder.instance() + .and(tbSysUser.phonenumber.eq(phonenumber)) + .build()).fetchOne(); + return MapstructUtils.convert(ret, SysUser.class); + } + + @Override + public SysUser selectTenantUserByPhonenumber(String phonenumber, Long tenantId) { + TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser) + .where(PredicateBuilder.instance() + .and(tbSysUser.phonenumber.eq(phonenumber)) + .and(tbSysUser.tenantId.eq(tenantId)) + .build()).fetchOne(); + return MapstructUtils.convert(ret, SysUser.class); + } + + @Override + public SysUser selectTenantUserByEmail(String email, Long tenantId) { + TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser) + .where(PredicateBuilder.instance() + .and(tbSysUser.email.eq(email)) + .and(tbSysUser.tenantId.eq(tenantId)) + .build()).fetchOne(); + return MapstructUtils.convert(ret, SysUser.class); + } + + @Override + public SysUser selectUserByEmail(String email) { + TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser) + .where(PredicateBuilder.instance() + .and(tbSysUser.email.eq(email)) + .build()).fetchOne(); + return MapstructUtils.convert(ret, SysUser.class); + } + + @Override + public SysUser selectTenantUserByUserName(String username, Long tenantId) { + TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser) + .where(PredicateBuilder.instance() + .and(tbSysUser.userName.eq(username)) + .and(TenantHelper.isEnable(), () -> tbSysUser.tenantId.eq(tenantId)) + .build()).fetchOne(); + if (Objects.nonNull(ret)) { + SysUser convert = MapstructUtils.convert(ret, SysUser.class); + Long deptId = ret.getDeptId(); + if (Objects.nonNull(deptId)) { + // 获取部门信息 + SysDept sysDept = sysDeptData.findById(deptId); + convert.setDept(sysDept); + // 获取角色信息 + List sysRoles = sysRoleData.findByUserId(ret.getId()); + + convert.setRoles(sysRoles); + } + return MapstructUtils.convert(ret, SysUser.class); + } else { + return null; + } + + } + + @Override + public SysUser selectUserByUserName(String username) { + TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser) + .where(PredicateBuilder.instance() + .and(tbSysUser.userName.eq(username)) + .build()).fetchOne(); + SysUser convert = MapstructUtils.convert(ret, SysUser.class); + Long deptId = ret.getDeptId(); + if (Objects.nonNull(deptId)) { + // 获取部门信息 + SysDept sysDept = sysDeptData.findById(deptId); + convert.setDept(sysDept); + // 获取角色信息 + List sysRoles = sysRoleData.findByUserId(ret.getId()); + + convert.setRoles(sysRoles); + } + return convert; + } + + @Override + public Paging selectAllocatedList(PageRequest to) { + SysUser data = to.getData(); + + PredicateBuilder builder = PredicateBuilder.instance() + .and(StringUtils.isNotBlank(data.getPhonenumber()), () -> tbSysUser.phonenumber.like(data.getPhonenumber())) + .and(StringUtils.isNotBlank(data.getUserName()), () -> tbSysUser.userName.like(data.getUserName())) + .and(StringUtils.isNotBlank(data.getStatus()), () -> tbSysUser.status.eq(data.getStatus())) + .and(Objects.nonNull(data.getDeptId()), () -> tbSysUser.deptId.eq(data.getDeptId())) + .and(tbSysUser.delFlag.eq(UserConstants.ROLE_NORMAL)) + .and(Objects.nonNull(data.getRoleId()), () -> tbSysRole.id.eq(data.getRoleId())); + + QueryResults tbSysUserQueryResults = jpaQueryFactory.select(Projections.bean(TbSysUser.class, tbSysUser.id, tbSysUser.deptId, tbSysUser.userName, + tbSysUser.nickName, tbSysUser.email, tbSysUser.phonenumber, tbSysUser.createTime)).from(tbSysUser) + .leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.id)) + .leftJoin(tbSysUserRole).on(tbSysUser.id.eq(tbSysUserRole.userId)) + .leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id)) + .where(builder.build()).offset(to.getOffset()).limit(to.getPageSize()).fetchResults(); + return new Paging<>(tbSysUserQueryResults.getTotal(), MapstructUtils.convert(tbSysUserQueryResults.getResults(), SysUser.class)); + + } + + @Override + public String selectUserPostGroup(String userName) { + List fetch = jpaQueryFactory.select(Projections.bean(TbSysPost.class, tbSysPost.id, tbSysPost.postName, tbSysPost.postCode)).from(tbSysPost) + .leftJoin(tbSysUserPost).on(tbSysPost.id.eq(tbSysUserPost.postId)) + .leftJoin(tbSysUser).on(tbSysUserPost.userId.eq(tbSysUser.id)) + .where(tbSysUser.userName.eq(userName)) + .orderBy(tbSysPost.postSort.asc()).fetch(); + return fetch.stream().map(TbSysPost::getPostName).collect(Collectors.joining(",")); + } + + @Override + public String selectUserRoleGroup(String userName) { + List fetch = jpaQueryFactory.select(tbSysRole).from(tbSysRole) + .leftJoin(tbSysUserRole).on(tbSysRole.id.eq(tbSysUserRole.roleId)) + .leftJoin(tbSysUser).on(tbSysUserRole.userId.eq(tbSysUser.id)) + .where(tbSysUser.userName.eq(userName)) + .orderBy(tbSysRole.roleSort.asc()).fetch(); + return fetch.stream().map(TbSysRole::getRoleName).collect(Collectors.joining(",")); + } + + + @Override + public Paging selectUnallocatedList(PageRequest to) { + SysUser data = to.getData(); + PredicateBuilder builder = PredicateBuilder.instance(); + if (Objects.nonNull(data)) { + builder.and(StringUtils.isNotBlank(data.getPhonenumber()), () -> tbSysUser.phonenumber.like(data.getPhonenumber())) + .and(StringUtils.isNotBlank(data.getUserName()), () -> tbSysUser.userName.like(data.getUserName())) + .and(StringUtils.isNotBlank(data.getStatus()), () -> tbSysUser.status.eq(data.getStatus())) + .and(Objects.nonNull(data.getDeptId()), () -> tbSysUser.deptId.eq(data.getDeptId())) + .and(tbSysUser.delFlag.eq(UserConstants.ROLE_NORMAL)); + } + + QueryResults sysUserQueryResults = jpaQueryFactory.select(Projections.bean(SysUser.class, tbSysUser.id, tbSysUser.deptId, tbSysUser.userName, + tbSysUser.nickName, tbSysUser.email, tbSysUser.phonenumber, tbSysUser.createTime)).from(tbSysUser) + .leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.id)) + .leftJoin(tbSysUserRole).on(tbSysUser.id.eq(tbSysUserRole.userId)) + .leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id)) + .where(builder.build()).offset(to.getOffset()).limit(to.getPageSize()).fetchResults(); + return new Paging<>(sysUserQueryResults.getTotal(), sysUserQueryResults.getResults()); + } + + @Override + public SysUser findByPhonenumber(String phonenumber) { + TbSysUser user = jpaQueryFactory.select(tbSysUser).from(tbSysUser) + .where(PredicateBuilder.instance() + .and(tbSysUser.phonenumber.eq(phonenumber)) + .build()).fetchOne(); + return MapstructUtils.convert(user, SysUser.class); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return PageBuilder.toPaging(userRepository.findAll(buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest))).to(SysUser.class); + } + + @Override + public List findAllByCondition(SysUser user) { + return buildQuery(buildQueryCondition(user)); + } + + private List buildQuery(Predicate predicate) { + List users = jpaQueryFactory.select(Projections.bean(TbSysUser.class, tbSysUser.id, tbSysUser.deptId, + tbSysUser.nickName, tbSysUser.userName, tbSysUser.email, tbSysUser.avatar, tbSysUser.phonenumber, tbSysUser.sex, + tbSysUser.status, tbSysUser.delFlag, tbSysUser.loginIp, tbSysUser.loginDate, tbSysUser.createBy, tbSysUser.createTime, + tbSysUser.remark, tbSysDept.deptName, tbSysDept.leader)) + .from(tbSysUser) + .leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.id)) + .where(predicate).fetch(); + return MapstructUtils.convert(users, SysUser.class); + } + + private Predicate buildQueryCondition(SysUser user) { + List ids; + if (Objects.nonNull(user) && Objects.nonNull(user.getDeptId())) { + Long deptId = user.getDeptId(); + List depts = sysDeptData.findByDeptId(deptId); + ids = StreamUtils.toList(depts, SysDept::getId); + ids.add(deptId); + } else { + ids = null; + } + List areaIds; + if (Objects.nonNull(user) && Objects.nonNull(user.getDeptAreaId())) { + Long deptId = user.getDeptAreaId(); + List depts = sysDeptData.findByDeptId(deptId); + areaIds = StreamUtils.toList(depts, SysDept::getId); + areaIds.add(deptId); + } else { + areaIds = null; + } + return PredicateBuilder.instance() + .and(ObjectUtil.isNotNull(user.getId()), () -> tbSysUser.id.eq(user.getId())) + .and(StringUtils.isNotEmpty(user.getUserName()), () -> tbSysUser.userName.like("%" + user.getUserName() + "%")) + .and(StringUtils.isNotEmpty(user.getStatus()), () -> tbSysUser.status.eq(user.getStatus())) + .and(ObjectUtil.isNotEmpty(user.getParams()), () -> tbSysUser.createTime.between(java.sql.Date.valueOf(user.getParams().get("beginTime").toString()), java.sql.Date.valueOf(user.getParams().get("endTime").toString()))) + .and(StringUtils.isNotEmpty(user.getPhonenumber()), () -> tbSysUser.phonenumber.like("%" + user.getPhonenumber() + "%")) + .and(ObjectUtil.isNotEmpty(ids), () -> tbSysUser.deptId.in(ids)) + .and(ObjectUtil.isNotEmpty(areaIds), () -> tbSysUser.deptAreaId.in(areaIds)).build(); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserPostDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserPostDataImpl.java new file mode 100644 index 0000000..dd5780a --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserPostDataImpl.java @@ -0,0 +1,76 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysUserPostRepository; +import cc.iotkit.data.model.TbSysUserPost; +import cc.iotkit.data.system.ISysUserPostData; +import cc.iotkit.model.system.SysUserPost; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/5/30 17:04 + */ + +@Primary +@Service +@RequiredArgsConstructor +public class SysUserPostDataImpl implements ISysUserPostData, IJPACommData { + + + private final SysUserPostRepository sysUserPostRepository; + + @Override + public int deleteByUserId(Long userId) { + return sysUserPostRepository.deleteAllByUserId(userId); + } + + @Override + public JpaRepository getBaseRepository() { + return sysUserPostRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysUserPost.class; + } + + @Override + public Class getTClass() { + return SysUserPost.class; + } + + @Override + public void batchSave(List data) { + sysUserPostRepository.saveAll(MapstructUtils.convert(data, TbSysUserPost.class)); + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserRoleDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserRoleDataImpl.java new file mode 100644 index 0000000..ede0dc5 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserRoleDataImpl.java @@ -0,0 +1,93 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.SysUserRoleRepository; +import cc.iotkit.data.model.TbSysUserRole; +import cc.iotkit.data.system.ISysUserRoleData; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysUserRole; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +import static cc.iotkit.data.model.QTbSysUserRole.tbSysUserRole; + +/** + * @Author:tfd + * @Date:2023/5/30 16:36 + */ +@Primary +@Service +@RequiredArgsConstructor +public class SysUserRoleDataImpl implements ISysUserRoleData, IJPACommData { + + private final SysUserRoleRepository sysUserRoleRepository; + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return sysUserRoleRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbSysUserRole.class; + } + + @Override + public Class getTClass() { + return SysUserRole.class; + } + + @Override + public int deleteByUserId(Long userId) { + return sysUserRoleRepository.deleteAllByUserId(userId); + } + + @Override + public long countUserRoleByRoleId(Long roleId) { + return sysUserRoleRepository.count(tbSysUserRole.roleId.eq(roleId)); + } + + @Override + public long insertBatch(List list) { + return sysUserRoleRepository.saveAll(MapstructUtils.convert(list,TbSysUserRole.class)).size(); + } + + @Override + public long delete(Long roleId, List userIds) { + return jpaQueryFactory.delete(tbSysUserRole).where(PredicateBuilder.instance() + .and(tbSysUserRole.roleId.eq(roleId)) + .and(tbSysUserRole.userId.in(userIds)) + .build()).execute(); + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/TaskInfoDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/TaskInfoDataImpl.java new file mode 100644 index 0000000..3fee6b1 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/TaskInfoDataImpl.java @@ -0,0 +1,131 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.TaskInfoRepository; +import cc.iotkit.data.manager.ITaskInfoData; +import cc.iotkit.data.model.TbTaskInfo; +import cc.iotkit.data.util.PageBuilder; +import cc.iotkit.model.rule.RuleAction; +import cc.iotkit.model.rule.TaskInfo; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +@Primary +@Service +@RequiredArgsConstructor +public class TaskInfoDataImpl implements ITaskInfoData, IJPACommData { + + @Autowired + private TaskInfoRepository taskInfoRepository; + + @Override + public List findByUid(String uid) { + return taskInfoRepository.findByUid(uid).stream().map(this::to) + .collect(Collectors.toList()); + } + + @Override + public Paging findByUid(String uid, int page, int size) { + Page paged = taskInfoRepository.findByUid(uid, + Pageable.ofSize(size).withPage(page - 1)); + return new Paging<>(paged.getTotalElements(), + paged.getContent().stream().map(this::to) + .collect(Collectors.toList()) + ); + } + + @Override + public long countByUid(String uid) { + return 0; + } + + @Override + public JpaRepository getBaseRepository() { + return taskInfoRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbTaskInfo.class; + } + + @Override + public Class getTClass() { + return TaskInfo.class; + } + + @Override + public TaskInfo findById(String s) { + return to(taskInfoRepository.findById(s).orElse(null)); + } + + @Override + public Paging findAll(PageRequest pageRequest) { + Page ret = taskInfoRepository.findAll(PageBuilder.toPageable(pageRequest)); + return new Paging<>(ret.getTotalElements(), + ret.getContent().stream().map(this::to) + .collect(Collectors.toList()) + ); + } + + @Override + public TaskInfo save(TaskInfo data) { + if (StringUtils.isBlank(data.getId())) { + data.setId(UUID.randomUUID().toString()); + data.setCreateAt(System.currentTimeMillis()); + } + taskInfoRepository.save(to(data)); + return data; + } + + private TaskInfo to(TbTaskInfo tb) { + TaskInfo convert = MapstructUtils.convert(tb, TaskInfo.class); + assert convert != null; + convert.setActions(JsonUtils.parseArray(tb.getActions(), RuleAction.class)); + return convert; + } + + private TbTaskInfo to(TaskInfo t) { + TbTaskInfo convert = MapstructUtils.convert(t, TbTaskInfo.class); + assert convert != null; + convert.setActions(JsonUtils.toJsonString(t.getActions())); + return convert; + } + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ThingModelDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ThingModelDataImpl.java new file mode 100644 index 0000000..781d158 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ThingModelDataImpl.java @@ -0,0 +1,96 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.ThingModelRepository; +import cc.iotkit.data.manager.IThingModelData; +import cc.iotkit.data.model.TbThingModel; +import cc.iotkit.model.product.ThingModel; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @author sjg + */ +@Primary +@Service +@RequiredArgsConstructor +public class ThingModelDataImpl implements IThingModelData, IJPACommData { + + @Autowired + private ThingModelRepository thingModelRepository; + + @Override + public JpaRepository getBaseRepository() { + return thingModelRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbThingModel.class; + } + + @Override + public Class getTClass() { + return ThingModel.class; + } + + @Override + public ThingModel findById(Long id) { + TbThingModel tbThingModel = thingModelRepository.findById(id).orElse(null); + ThingModel convert = MapstructUtils.convert(tbThingModel, ThingModel.class); + if (tbThingModel != null && convert != null) { + convert.setModel(JsonUtils.parseObject(tbThingModel.getModel(), ThingModel.Model.class)); + } + return convert; + } + + @Override + public ThingModel save(ThingModel data) { + TbThingModel to = data.to(TbThingModel.class); + to.setModel(JsonUtils.toJsonString(data.getModel())); + thingModelRepository.save(to); + return data; + } + + @Override + public void deleteById(Long id) { + thingModelRepository.deleteById(id); + } + + @Override + public ThingModel findByProductKey(String productKey) { + TbThingModel tbThingModel = thingModelRepository.findByProductKey(productKey).orElse(null); + ThingModel convert = MapstructUtils.convert(tbThingModel, ThingModel.class); + if (tbThingModel != null && convert != null) { + convert.setModel(JsonUtils.parseObject(tbThingModel.getModel(), ThingModel.Model.class)); + } + return convert; + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/UserInfoDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/UserInfoDataImpl.java new file mode 100644 index 0000000..5ff8798 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/UserInfoDataImpl.java @@ -0,0 +1,73 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.UserInfoRepository; +import cc.iotkit.data.manager.IUserInfoData; +import cc.iotkit.data.model.TbUserInfo; +import cc.iotkit.model.UserInfo; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Primary +@Service +@RequiredArgsConstructor +public class UserInfoDataImpl implements IUserInfoData, IJPACommData { + + @Autowired + private UserInfoRepository userInfoRepository; + + @Override + public UserInfo findByUid(String uid) { + return MapstructUtils.convert(userInfoRepository.findByUid(uid), UserInfo.class); + } + + @Override + public List findByType(int type) { + return MapstructUtils.convert(userInfoRepository.findByType(type), UserInfo.class); + } + + @Override + public JpaRepository getBaseRepository() { + return userInfoRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbUserInfo.class; + } + + @Override + public Class getTClass() { + return UserInfo.class; + } + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/VirtualDeviceDataImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/VirtualDeviceDataImpl.java new file mode 100644 index 0000000..501075b --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/VirtualDeviceDataImpl.java @@ -0,0 +1,155 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.data.service; + +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.manager.IVirtualDeviceData; +import cc.iotkit.data.dao.VirtualDeviceMappingRepository; +import cc.iotkit.data.dao.VirtualDeviceRepository; +import cc.iotkit.data.model.TbVirtualDevice; +import cc.iotkit.data.model.TbVirtualDeviceMapping; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.device.VirtualDevice; +import cn.hutool.core.util.IdUtil; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +@Primary +@Service +@RequiredArgsConstructor +public class VirtualDeviceDataImpl implements IVirtualDeviceData, IJPACommData { + + private final VirtualDeviceRepository virtualDeviceRepository; + + private final VirtualDeviceMappingRepository virtualDeviceMappingRepository; + + @Override + public JpaRepository getBaseRepository() { + return virtualDeviceRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbVirtualDevice.class; + } + + @Override + public Class getTClass() { + return VirtualDevice.class; + } + + @Override + public List findByUid(String uid) { + return MapstructUtils.convert(virtualDeviceRepository.findByUid(uid), VirtualDevice.class); + } + + @Override + public Paging findByUid(String uid, int size, int page) { + Page paged = virtualDeviceRepository.findByUid(uid, + Pageable.ofSize(size).withPage(page - 1)); + return new Paging<>(paged.getTotalElements(), + MapstructUtils.convert(paged.getContent(), VirtualDevice.class)); + } + + @Override + public long countByUid(String uid) { + return 0; + } + + @Override + public List findByUidAndState(String uid, String state) { + return null; + } + + @Override + public List findByTriggerAndState(String trigger, String state) { + List list = MapstructUtils.convert(virtualDeviceRepository + .findByTriggerAndState(trigger, state), VirtualDevice.class); + for (VirtualDevice virtualDevice : list) { + virtualDevice.setDevices(getVirtualDeviceIds(virtualDevice.getId())); + } + return list; + } + + @Override + public VirtualDevice findById(String s) { + VirtualDevice dto = MapstructUtils.convert(virtualDeviceRepository.findById(s).orElse(null), VirtualDevice.class); + dto.setDevices(getVirtualDeviceIds(s)); + return dto; + } + + + private List getVirtualDeviceIds(String virtualId) { + List deviceMappings = virtualDeviceMappingRepository.findByVirtualId(virtualId); + return deviceMappings.stream().map(TbVirtualDeviceMapping::getDeviceId).collect(Collectors.toList()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public VirtualDevice save(VirtualDevice data) { + if (StringUtils.isBlank(data.getId())) { + data.setId(IdUtil.simpleUUID()); + data.setState(VirtualDevice.STATE_STOPPED); + data.setCreateAt(System.currentTimeMillis()); + } + virtualDeviceRepository.save(MapstructUtils.convert(data, TbVirtualDevice.class)); + + //删除旧的添加新的关联设备记录 + virtualDeviceMappingRepository.deleteByVirtualId(data.getId()); + virtualDeviceMappingRepository.saveAllAndFlush( + data.getDevices().stream().map(d -> new TbVirtualDeviceMapping( + IdUtil.simpleUUID(), + data.getId(), + d, LoginHelper.getTenantId() + )).collect(Collectors.toList()) + ); + return data; + } + + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteById(String s) { + virtualDeviceRepository.deleteById(s); + virtualDeviceMappingRepository.deleteByVirtualId(s); + } + + + @Override + public List findAll() { + return MapstructUtils.convert(virtualDeviceRepository.findAll(), VirtualDevice.class); + } + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/WorderImpl.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/WorderImpl.java new file mode 100644 index 0000000..6b4bac2 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/WorderImpl.java @@ -0,0 +1,69 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.service; + +import cc.iotkit.data.dao.FeedBackEvaluationRepository; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.data.dao.WorderRepository; +import cc.iotkit.data.manager.IFeedBackEvaluationData; +import cc.iotkit.data.manager.IWorderData; +import cc.iotkit.data.model.TbWorderDO; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import cc.iotkit.model.worder.WorderDO; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +@Primary +@Service +@RequiredArgsConstructor +public class WorderImpl implements IWorderData, IJPACommData { + + @Autowired + private WorderRepository homeRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public JpaRepository getBaseRepository() { + return homeRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbWorderDO.class; + } + + @Override + public Class getTClass() { + return WorderDO.class; + } + + + + +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/util/PageBuilder.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/util/PageBuilder.java new file mode 100644 index 0000000..8ac7221 --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/util/PageBuilder.java @@ -0,0 +1,103 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.util; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.PageRequestEmpty; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cn.hutool.core.collection.CollUtil; +import com.querydsl.core.QueryResults; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; +import org.springframework.data.domain.Sort.Order; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author: Longjun.Tu + * @description: + * @date:created in 2023/5/26 17:14 + * @modificed by: + */ +public class PageBuilder { + + public static Pageable toPageable(PageRequest request, Sort.Direction direction, String... properties) { + return (Pageable)(request.getPageSize() <= 0 ? Pageable.unpaged() : org.springframework.data.domain.PageRequest.of(request.getPageNum() - 1, request.getPageSize(), direction, properties)); + } + + public static Pageable toPageable(PageRequest request) { + List orders = getOrders(request); + if(CollUtil.isNotEmpty(orders)){ + return toPageable(request, Sort.by(orders)); + } + return (Pageable)(request.getPageSize() <= 0 ? Pageable.unpaged() : org.springframework.data.domain.PageRequest.of(request.getPageNum() - 1, request.getPageSize())); + + } + + public static Pageable toPageable(PageRequestEmpty request) { + return (Pageable)(request.getPageNum() <= 0 ? Pageable.unpaged() : org.springframework.data.domain.PageRequest.of(request.getPageNum() - 1, request.getPageSize())); + } + + public static Pageable toPageable(PageRequestEmpty request, Sort.Direction direction, String... properties) { + return (Pageable)(request.getPageNum() <= 0 ? Pageable.unpaged() : org.springframework.data.domain.PageRequest.of(request.getPageNum() - 1, request.getPageSize(), direction, properties)); + } + + public static Pageable toPageable(PageRequest request, Sort sort) { + return (Pageable)(request.getPageSize() <= 0 ? Pageable.unpaged() : org.springframework.data.domain.PageRequest.of(request.getPageNum() - 1, request.getPageSize(), sort)); + } + + private static List getOrders(PageRequest pageRequest) { + List orders = new ArrayList<>(); + Map sortMap = pageRequest.getSortMap(); + if (CollUtil.isNotEmpty(sortMap)){ + sortMap.forEach((k,v) -> { + orders.add(new Order(Direction.fromString("desc"), k)); + }); + } + return orders; + } + + public static Paging toPaging(Page all, Class clz) { + return new Paging<>(all.getTotalElements(), + MapstructUtils.convert(all.getContent(), clz)); + } + + public static Paging toPaging(Page all) { + return new Paging<>(all.getTotalElements(), all.getContent()); + } + + public static Pageable buildPageable(int page, int size) { + return org.springframework.data.domain.PageRequest.of(page, size); + } + + public static Paging queryResults2Page(QueryResults queryResults, Class clz) { + return new Paging<>(queryResults.getTotal(), MapstructUtils.convert(queryResults.getResults(), clz)); + + } +} diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/util/PredicateBuilder.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/util/PredicateBuilder.java new file mode 100644 index 0000000..483585d --- /dev/null +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/util/PredicateBuilder.java @@ -0,0 +1,139 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.data.util; + +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.Expressions; +import java.util.function.Supplier; + +/** + * @author: Longjun.Tu + * @description: + * @date:created in 2023/5/26 17:02 + * @modificed by: + */ +public class PredicateBuilder { + /** + * 1 = 1, 永远为真. + */ + private static final BooleanExpression ALWAYS_TRUE = Expressions.ONE.eq(Expressions.ONE); + + private BooleanExpression expression; + + public PredicateBuilder(BooleanExpression expression) { + this.expression = expression; + } + + /** + * 获取{@link PredicateBuilder}实例. + * + * @return PredicateBuilder + */ + public static PredicateBuilder instance() { + return instance(null); + } + + /** + * 获取{@link PredicateBuilder}实例. + * + * @param init 初始条件 + * @return PredicateBuilder + */ + public static PredicateBuilder instance(BooleanExpression init) { + return new PredicateBuilder(init); + } + + /** + * 使用 'and' 对条件进行拼接 + * + * @param expr Boolean expressions + * @return PredicateBuilder + */ + public PredicateBuilder and(BooleanExpression expr) { + return and(true, () -> expr); + } + + /** + * 如果条件为true, 则使用 'and' 对条件进行拼接 + * + * @param condition 执行条件, 如果为false, 则不会拼接该条件. + * @param exprSupplier expression supplier. + * @return PredicateBuilder + */ + public PredicateBuilder and(boolean condition, Supplier exprSupplier) { + if (condition) { + if (exprIsNull()) { + expression = exprSupplier.get(); + return this; + } + expression = expression.and(exprSupplier.get()); + } + return this; + } + + /** + * 使用 'or' 对条件进行拼接 + * + * @param expr Boolean expressions + * @return PredicateBuilder + */ + public PredicateBuilder or(BooleanExpression expr) { + return or(true, () -> expr); + } + + /** + * 如果条件为true, 则使用 'or' 对条件进行拼接 + * + * @param condition 执行条件, 如果为false, 则不会拼接该条件. + * @param exprSupplier expression supplier. + * @return PredicateBuilder + */ + public PredicateBuilder or(boolean condition, Supplier exprSupplier) { + if (condition) { + if (exprIsNull()) { + expression = exprSupplier.get(); + return this; + } + expression = expression.or(exprSupplier.get()); + } + return this; + } + + /** + * 获取最终的{@link BooleanExpression}表达式 + * + * @return Predicate, 如果没有拼接条件, 则默认返回 1 = 1的表达式. + */ + public Predicate build() { + if (exprIsNull()) { + return ALWAYS_TRUE; + } + return expression; + } + + private boolean exprIsNull() { + return null == expression; + } +} diff --git a/iot-dao/iot-temporal-service/pom.xml b/iot-dao/iot-temporal-service/pom.xml new file mode 100644 index 0000000..af0da22 --- /dev/null +++ b/iot-dao/iot-temporal-service/pom.xml @@ -0,0 +1,42 @@ + + + + iot-dao + cc.iotkit + 0.5.3 + + 4.0.0 + 0.5.3 + iot-temporal-service + + + + + cc.iotkit + iot-common-thing + + + + cc.iotkit + iot-data-model + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + + + \ No newline at end of file diff --git a/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IDbStructureData.java b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IDbStructureData.java new file mode 100644 index 0000000..375fd37 --- /dev/null +++ b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IDbStructureData.java @@ -0,0 +1,48 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.temporal; + +import cc.iotkit.model.product.ThingModel; + +/** + * 数据结构接口 + */ +public interface IDbStructureData { + + /** + * 定义物模型,根据物模型定义表 + */ + void defineThingModel(ThingModel thingModel); + + /** + * 更新物模型定义 + */ + void updateThingModel(ThingModel thingModel); + + /** + * 初始化数据库结构 + */ + void initDbStructure(); + +} diff --git a/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IDevicePropertyData.java b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IDevicePropertyData.java new file mode 100644 index 0000000..6a69404 --- /dev/null +++ b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IDevicePropertyData.java @@ -0,0 +1,57 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal; + + +import cc.iotkit.model.device.message.DeviceProperty; +import cc.iotkit.model.device.message.DevicePropertyCache; + +import java.util.List; +import java.util.Map; + +/** + * 设备属性时序数据接口 + */ +public interface IDevicePropertyData { + + /** + * 按时间范围取设备指定属性的历史数据 + * + * @param deviceId 设备id + * @param name 属性名称 + * @param start 开始时间戳 + * @param end 结束时间戳 + * @param size 取时间范围内的数量 + */ + List findDevicePropertyHistory(String deviceId, String name, long start, long end, int size); + + /** + * 添加多个属性 + * + * @param deviceId 设备ID + * @param properties 属性 + * @param time 属性上报时间 + */ + void addProperties(String deviceId, Map properties, long time); + +} diff --git a/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IRuleLogData.java b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IRuleLogData.java new file mode 100644 index 0000000..262fee3 --- /dev/null +++ b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IRuleLogData.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.temporal; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.rule.RuleLog; + +public interface IRuleLogData { + + void deleteByRuleId(String ruleId); + + Paging findByRuleId(String ruleId, int page, int size); + + void add(RuleLog log); + +} diff --git a/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/ITaskLogData.java b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/ITaskLogData.java new file mode 100644 index 0000000..82530a9 --- /dev/null +++ b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/ITaskLogData.java @@ -0,0 +1,35 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.temporal; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.rule.TaskLog; + +public interface ITaskLogData { + void deleteByTaskId(String taskId); + + Paging findByTaskId(String taskId, int page, int size); + + void add(TaskLog log); +} diff --git a/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IThingModelMessageData.java b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IThingModelMessageData.java new file mode 100644 index 0000000..79b377f --- /dev/null +++ b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IThingModelMessageData.java @@ -0,0 +1,86 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.model.stats.TimeData; + +import java.util.List; + +public interface IThingModelMessageData { + + /** + * 按消息类型和标识符取设备消息 + * + * @param deviceId 设备id + * @param type 消息类型 + * @param identifier 标识符 + * @param page 页码 + * @param size 页大小 + */ + Paging findByTypeAndIdentifier(String deviceId, String type, + String identifier, int page, int size); + + /** + * 按用户统计时间段内每小时上报次数 + * + * @param uid 用户id + * @param start 开始时间戳 + * @param end 结束时间戳 + */ + List getDeviceMessageStatsWithUid(String uid, long start, long end); + + /** + * 按用户统计时间段内上行消息 + * @param uid 用户id + * @param start 开始时间戳 + * @param end 结束时间戳 + */ + List getDeviceUpMessageStatsWithUid(String uid, Long start, Long end); + + /** + * 按用户统计时间段内下行 + * @param uid 用户id + * @param start 开始时间戳 + * @param end 结束时间戳 + */ + List getDeviceDownMessageStatsWithUid(String uid, Long start, Long end); + + + /** + * 查询指定设备集类型并按时间倒序 + * + * @param deviceIds 设备ids + * @param type 消息类型 + * @param identifier 标识符 + * @param page 页码 + * @param size 页大小 + */ + Paging findByTypeAndDeviceIds(List deviceIds, String type, + String identifier, int page, int size); + + void add(ThingModelMessage msg); + + long count(); +} diff --git a/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IVirtualDeviceLogData.java b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IVirtualDeviceLogData.java new file mode 100644 index 0000000..9d61634 --- /dev/null +++ b/iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IVirtualDeviceLogData.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.temporal; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.device.VirtualDeviceLog; + +public interface IVirtualDeviceLogData { + + Paging findByVirtualDeviceId(String virtualDeviceId, int page, int size); + + void add(VirtualDeviceLog log); +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/pom.xml b/iot-dao/iot-temporal-serviceImpl-es/pom.xml new file mode 100644 index 0000000..5f1d3dc --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/pom.xml @@ -0,0 +1,84 @@ + + + + iot-dao + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-temporal-serviceImpl-es + + + + + + cc.iotkit + iot-temporal-service + + + + cc.iotkit + iot-data-serviceImpl-cache + + + + + + org.projectlombok + lombok + provided + + + + org.springframework.data + spring-data-elasticsearch + + + + com.fasterxml.jackson.core + jackson-annotations + + + + io.github.linpeilie + mapstruct-plus-spring-boot-starter + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + org.projectlombok + lombok + ${lombok.version} + + + io.github.linpeilie + mapstruct-plus-processor + ${mapstruct-plus.version} + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + + + + + + + \ No newline at end of file diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/config/ElasticsearchConfiguration.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/config/ElasticsearchConfiguration.java new file mode 100644 index 0000000..c16f64e --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/config/ElasticsearchConfiguration.java @@ -0,0 +1,39 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.temporal.es.config; + + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.Lazy; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; +import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; + +@Lazy +@Configuration +@EnableElasticsearchRepositories(basePackages = "cc.iotkit.temporal.es.dao", includeFilters = +@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchRepository.class)) +public class ElasticsearchConfiguration { +} \ No newline at end of file diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/RuleLogRepository.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/RuleLogRepository.java new file mode 100644 index 0000000..6585aa3 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/RuleLogRepository.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.dao; + +import cc.iotkit.temporal.es.document.DocRuleLog; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +public interface RuleLogRepository extends ElasticsearchRepository { + + void deleteByRuleId(String ruleId); + + Page findByRuleIdOrderByLogAtDesc(String ruleId, Pageable pageable); + +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/TaskLogRepository.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/TaskLogRepository.java new file mode 100644 index 0000000..cbf642a --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/TaskLogRepository.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.dao; + +import cc.iotkit.temporal.es.document.DocTaskLog; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +public interface TaskLogRepository extends ElasticsearchRepository { + + void deleteByTaskId(String taskId); + + Page findByTaskIdOrderByLogAtDesc(String taskId, Pageable pageable); + +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/ThingModelMessageRepository.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/ThingModelMessageRepository.java new file mode 100644 index 0000000..1d87394 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/ThingModelMessageRepository.java @@ -0,0 +1,29 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.dao; + +import cc.iotkit.temporal.es.document.DocThingModelMessage; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +public interface ThingModelMessageRepository extends ElasticsearchRepository { +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/VirtualDeviceLogRepository.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/VirtualDeviceLogRepository.java new file mode 100644 index 0000000..ed2e152 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/VirtualDeviceLogRepository.java @@ -0,0 +1,34 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.dao; + +import cc.iotkit.temporal.es.document.DocVirtualDeviceLog; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +public interface VirtualDeviceLogRepository extends ElasticsearchRepository { + + Page findByVirtualDeviceId(String virtualDeviceId, Pageable pageable); + +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocDeviceProperty.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocDeviceProperty.java new file mode 100644 index 0000000..20b9df3 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocDeviceProperty.java @@ -0,0 +1,56 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.document; + +import cc.iotkit.model.device.message.DeviceProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldType; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Document(indexName = "device_property") +@AutoMapper(target = DeviceProperty.class) +public class DocDeviceProperty { + + @Id + private String id; + + private String deviceId; + + private String name; + + private Object value; + + @Field(type = FieldType.Date) + private Long time; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocRuleLog.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocRuleLog.java new file mode 100644 index 0000000..455a49b --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocRuleLog.java @@ -0,0 +1,56 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.document; + +import cc.iotkit.model.rule.RuleLog; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldType; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Document(indexName = "rule_log") +@AutoMapper(target = RuleLog.class) +public class DocRuleLog { + @Id + private String id; + + private String ruleId; + + private String state; + + private String content; + + private Boolean success; + + @Field(type = FieldType.Date) + private Long logAt; +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocTaskLog.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocTaskLog.java new file mode 100644 index 0000000..2911b25 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocTaskLog.java @@ -0,0 +1,55 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.document; + +import cc.iotkit.model.rule.TaskLog; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldType; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Document(indexName = "task_log") +@AutoMapper(target = TaskLog.class) +public class DocTaskLog { + + @Id + private String id; + + private String taskId; + + private String content; + + private Boolean success; + + @Field(type = FieldType.Date) + private Long logAt; +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocThingModelMessage.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocThingModelMessage.java new file mode 100644 index 0000000..139fc6d --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocThingModelMessage.java @@ -0,0 +1,69 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.document; + +import cc.iotkit.common.thing.ThingModelMessage; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldType; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Document(indexName = "thing_model_message") +@AutoMapper(target = ThingModelMessage.class) +public class DocThingModelMessage { + + @Id + private String id; + + private String mid; + + private String deviceId; + + private String productKey; + + private String deviceName; + + private String type; + + private String identifier; + + private int code; + + private Object data; + + @Field(type = FieldType.Date) + private Long occurred; + + @Field(type = FieldType.Date) + private Long time; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocVirtualDeviceLog.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocVirtualDeviceLog.java new file mode 100644 index 0000000..a9b9b3a --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocVirtualDeviceLog.java @@ -0,0 +1,72 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.document; + +import cc.iotkit.model.device.VirtualDeviceLog; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldType; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@AutoMapper(target= VirtualDeviceLog.class) +@Document(indexName = "virtual_device_log") +public class DocVirtualDeviceLog { + + @Id + private String id; + + /** + * 虚拟设备id + */ + private String virtualDeviceId; + + /** + * 虚拟设备名称 + */ + private String virtualDeviceName; + + /** + * 关联设备数量 + */ + private int deviceTotal; + + /** + * 虚拟设备执行结果 + */ + private String result; + + /** + * 创建时间 + */ + @Field(type = FieldType.Date) + private Long logAt = System.currentTimeMillis(); +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DbStructureDataImpl.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DbStructureDataImpl.java new file mode 100644 index 0000000..d7b7144 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DbStructureDataImpl.java @@ -0,0 +1,46 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.temporal.es.service; + +import cc.iotkit.model.product.ThingModel; +import cc.iotkit.temporal.IDbStructureData; +import org.springframework.stereotype.Service; + +@Service +public class DbStructureDataImpl implements IDbStructureData { + @Override + public void defineThingModel(ThingModel thingModel) { + + } + + @Override + public void updateThingModel(ThingModel thingModel) { + + } + + @Override + public void initDbStructure() { + + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DevicePropertyDataImpl.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DevicePropertyDataImpl.java new file mode 100644 index 0000000..c61cd8f --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DevicePropertyDataImpl.java @@ -0,0 +1,112 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.service; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DeviceProperty; +import cc.iotkit.model.device.message.DevicePropertyCache; +import cc.iotkit.temporal.IDevicePropertyData; +import cc.iotkit.temporal.es.document.DocDeviceProperty; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.sort.FieldSortBuilder; +import org.elasticsearch.search.sort.SortOrder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; +import org.springframework.data.elasticsearch.core.SearchHits; +import org.springframework.data.elasticsearch.core.document.Document; +import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; +import org.springframework.data.elasticsearch.core.query.NativeSearchQuery; +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +@Service +public class DevicePropertyDataImpl implements IDevicePropertyData { + + @Autowired + private ElasticsearchRestTemplate template; + + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + + private final Set indexSet = new HashSet<>(); + + @Override + public List findDevicePropertyHistory(String deviceId, String name, long start, long end, int size) { + String index = getIndex(deviceId, name); + NativeSearchQuery query = new NativeSearchQueryBuilder() + .withQuery( + QueryBuilders.boolQuery() + .must(QueryBuilders.termQuery("deviceId", deviceId)) + .must(QueryBuilders.rangeQuery("time") + .from(start, true).to(end, true)) + ) + .withSorts(new FieldSortBuilder("time").order(SortOrder.ASC)) + .build(); + SearchHits result = template.search(query, DocDeviceProperty.class, IndexCoordinates.of(index)); + return result.getSearchHits().stream() + .map(h -> MapstructUtils.convert(h.getContent(), DeviceProperty.class)) + .collect(Collectors.toList()); + } + + @Override + public void addProperties(String deviceId, Map properties, long time) { + properties.forEach((key, val) -> { + DevicePropertyCache propertyCache = (DevicePropertyCache) val; + String index = getIndex(deviceId, key); + long occurred = Objects.nonNull(propertyCache.getOccurred()) ? propertyCache.getOccurred() : time; + template.save( + new DocDeviceProperty(UUID.randomUUID().toString(), deviceId, key, propertyCache.getValue(), occurred), + IndexCoordinates.of(index) + ); + }); + } + + private String getIndex(String deviceId, String name) { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + if (deviceInfo == null) { + return null; + } + String pk = deviceInfo.getProductKey(); + String index = String.format("device_property_%s_%s", pk, name).toLowerCase(); + if (!indexSet.contains(index)) { + IndexCoordinates indexCoordinates = IndexCoordinates.of(index); + if (!template.indexOps(indexCoordinates).exists()) { + // 根据索引实体,获取mapping字段 + Document mapping = template.indexOps(indexCoordinates).createMapping(DocDeviceProperty.class); + template.indexOps(indexCoordinates).create(); + // 创建索引mapping + template.indexOps(indexCoordinates).putMapping(mapping); + } + indexSet.add(index); + } + return index; + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java new file mode 100644 index 0000000..503ed69 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java @@ -0,0 +1,61 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.model.rule.RuleLog; +import cc.iotkit.temporal.IRuleLogData; +import cc.iotkit.temporal.es.dao.RuleLogRepository; +import cc.iotkit.temporal.es.document.DocRuleLog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.stream.Collectors; + +@Service +public class RuleLogDataImpl implements IRuleLogData { + + @Autowired + private RuleLogRepository ruleLogRepository; + + @Override + public void deleteByRuleId(String ruleId) { + ruleLogRepository.deleteByRuleId(ruleId); + } + + @Override + public Paging findByRuleId(String ruleId, int page, int size) { + Page paged = ruleLogRepository.findByRuleIdOrderByLogAtDesc(ruleId, Pageable.ofSize(size).withPage(page - 1)); + return new Paging<>(paged.getTotalElements(), + paged.getContent().stream().map(o -> MapstructUtils.convert(o, RuleLog.class)) + .collect(Collectors.toList())); + } + + @Override + public void add(RuleLog log) { + ruleLogRepository.save(MapstructUtils.convert(log, DocRuleLog.class)); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java new file mode 100644 index 0000000..545d760 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java @@ -0,0 +1,61 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.model.rule.TaskLog; +import cc.iotkit.temporal.ITaskLogData; +import cc.iotkit.temporal.es.dao.TaskLogRepository; +import cc.iotkit.temporal.es.document.DocTaskLog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.stream.Collectors; + +@Service +public class TaskLogDataImpl implements ITaskLogData { + + @Autowired + private TaskLogRepository taskLogRepository; + + @Override + public void deleteByTaskId(String taskId) { + taskLogRepository.deleteByTaskId(taskId); + } + + @Override + public Paging findByTaskId(String taskId, int page, int size) { + Page paged = taskLogRepository.findByTaskIdOrderByLogAtDesc(taskId, Pageable.ofSize(size).withPage(page - 1)); + return new Paging<>(paged.getTotalElements(), + paged.getContent().stream().map(o -> MapstructUtils.convert(o, TaskLog.class)) + .collect(Collectors.toList())); + } + + @Override + public void add(TaskLog log) { + taskLogRepository.save(MapstructUtils.convert(log, DocTaskLog.class)); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java new file mode 100644 index 0000000..a2fe81a --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java @@ -0,0 +1,234 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.model.stats.TimeData; +import cc.iotkit.temporal.IThingModelMessageData; +import cc.iotkit.temporal.es.dao.ThingModelMessageRepository; +import cc.iotkit.temporal.es.document.DocThingModelMessage; +import cn.hutool.core.util.ObjectUtil; +import org.apache.commons.lang3.StringUtils; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; +import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; +import org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.data.elasticsearch.core.ElasticsearchAggregations; +import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; +import org.springframework.data.elasticsearch.core.SearchHit; +import org.springframework.data.elasticsearch.core.SearchHits; +import org.springframework.data.elasticsearch.core.query.NativeSearchQuery; +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; +import org.springframework.stereotype.Service; + +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class ThingModelMessageDataImpl implements IThingModelMessageData { + + @Autowired + private ElasticsearchRestTemplate template; + @Autowired + private ThingModelMessageRepository thingModelMessageRepository; + + @Override + public Paging findByTypeAndIdentifier(String deviceId, String type, + String identifier, + int page, int size) { + BoolQueryBuilder builder = QueryBuilders.boolQuery(); + builder.must(QueryBuilders.termQuery("deviceId", deviceId)); + if (StringUtils.isNotBlank(type)) { + builder.must(QueryBuilders.termQuery("type", type)); + } + if (StringUtils.isNotBlank(identifier)) { + builder.must(QueryBuilders.matchPhraseQuery("identifier", identifier)); + } + NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(builder) + .withPageable(PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("time")))) + .build(); + SearchHits result = template.search(query, DocThingModelMessage.class); + return new Paging<>(result.getTotalHits(), result.getSearchHits().stream() + .map(m -> MapstructUtils.convert(m.getContent(), ThingModelMessage.class)) + .collect(Collectors.toList())); + } + + @Override + public Paging findByTypeAndDeviceIds(List deviceIds, String type, + String identifier, + int page, int size) { + BoolQueryBuilder builder = QueryBuilders.boolQuery(); + builder.must(QueryBuilders.termQuery("type", type)); + if (deviceIds.size()>0) { + builder.must(QueryBuilders.termsQuery("deviceId", deviceIds)); + } + if (StringUtils.isNotBlank(identifier)) { + builder.must(QueryBuilders.matchPhraseQuery("identifier", identifier)); + } + NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(builder) + .withPageable(PageRequest.of(page - 1, size, Sort.by(Sort.Order.desc("time")))) + .build(); + SearchHits result = template.search(query, DocThingModelMessage.class); + return new Paging<>(result.getTotalHits(), result.getSearchHits().stream() + .map(m -> MapstructUtils.convert(m.getContent(), ThingModelMessage.class)) + .collect(Collectors.toList())); + } + + @Override + public List getDeviceMessageStatsWithUid(String uid, long start, long end) { + BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery() + .must(QueryBuilders.rangeQuery("time") + .from(start, true).to(end, true)); + if (uid != null) { + queryBuilder = + queryBuilder.must(QueryBuilders.termQuery("uid", uid)); + } + + //按小时统计消息数量 + NativeSearchQuery query = new NativeSearchQueryBuilder() + .withQuery(queryBuilder) + .withAggregations(AggregationBuilders.dateHistogram("agg") + .field("time") + .calendarInterval(DateHistogramInterval.HOUR) + .calendarInterval(DateHistogramInterval.hours(1)) + ) + .build(); + + ElasticsearchAggregations result = (ElasticsearchAggregations) template + .search(query, DocThingModelMessage.class).getAggregations(); + ParsedDateHistogram histogram = result.aggregations().get("agg"); + + List data = new ArrayList<>(); + for (Histogram.Bucket bucket : histogram.getBuckets()) { + long seconds = ((ZonedDateTime) bucket.getKey()).toInstant().getEpochSecond(); + data.add(new TimeData(seconds * 1000, bucket.getDocCount())); + } + + return data; + } + + @Override + public List getDeviceUpMessageStatsWithUid(String uid, Long start, Long end) { + BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery(); + if (ObjectUtil.isNotEmpty(start) && ObjectUtil.isNotEmpty(end)) { + queryBuilder.must(QueryBuilders.rangeQuery("time") + .from(start, true).to(end, true)); + } + + if ( ObjectUtil.isNotEmpty(uid) ) { + queryBuilder = + queryBuilder.must(QueryBuilders.termQuery("uid", uid)); + } + + // 查询字段type='property' and identifier='report', 或者 type='event' 的数据 + queryBuilder = queryBuilder.must(QueryBuilders.boolQuery() + .should(QueryBuilders.boolQuery() + .must(QueryBuilders.termQuery("type", "property")) + .must(QueryBuilders.termQuery("identifier", "report"))) + .should(QueryBuilders.termQuery("type", "event"))); + + NativeSearchQuery query = new NativeSearchQueryBuilder() + .withQuery(queryBuilder) + .withAggregations(AggregationBuilders.dateHistogram("agg") + .field("time") + .calendarInterval(DateHistogramInterval.HOUR) + .calendarInterval(DateHistogramInterval.hours(1)) + ) + .build(); + + ElasticsearchAggregations result = (ElasticsearchAggregations) template + .search(query, DocThingModelMessage.class).getAggregations(); + ParsedDateHistogram histogram = result.aggregations().get("agg"); + + List data = new ArrayList<>(); + for (Histogram.Bucket bucket : histogram.getBuckets()) { + long seconds = ((ZonedDateTime) bucket.getKey()).toInstant().getEpochSecond(); + data.add(new TimeData(seconds * 1000, bucket.getDocCount())); + } + + return data; + } + + @Override + public List getDeviceDownMessageStatsWithUid(String uid, Long start, Long end) { + BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery(); + if (ObjectUtil.isNotEmpty(start) && ObjectUtil.isNotEmpty(end)) { + queryBuilder.must(QueryBuilders.rangeQuery("time") + .from(start, true).to(end, true)); + } + + if ( ObjectUtil.isNotEmpty(uid) ) { + queryBuilder = + queryBuilder.must(QueryBuilders.termQuery("uid", uid)); + } + + // 查询字段type='property' and identifie!='report', 或者 type='service' 或者 type= 'config' + queryBuilder = queryBuilder.must(QueryBuilders.boolQuery() + .should(QueryBuilders.boolQuery() + .must(QueryBuilders.termQuery("type", "property")) + .must(QueryBuilders.boolQuery() + .mustNot(QueryBuilders.termQuery("identifier", "report")))) + .should(QueryBuilders.termQuery("type", "service")) + .should(QueryBuilders.termQuery("type", "config"))); + + NativeSearchQuery query = new NativeSearchQueryBuilder() + .withQuery(queryBuilder) + .withAggregations(AggregationBuilders.dateHistogram("agg") + .field("time") + .calendarInterval(DateHistogramInterval.HOUR) + .calendarInterval(DateHistogramInterval.hours(1)) + ) + .build(); + + ElasticsearchAggregations result = (ElasticsearchAggregations) template + .search(query, DocThingModelMessage.class).getAggregations(); + ParsedDateHistogram histogram = result.aggregations().get("agg"); + + List data = new ArrayList<>(); + for (Histogram.Bucket bucket : histogram.getBuckets()) { + long seconds = ((ZonedDateTime) bucket.getKey()).toInstant().getEpochSecond(); + data.add(new TimeData(seconds * 1000, bucket.getDocCount())); + } + + return data; + } + + @Override + public void add(ThingModelMessage msg) { + thingModelMessageRepository.save(MapstructUtils.convert(msg, DocThingModelMessage.class)); + } + + @Override + public long count() { + return thingModelMessageRepository.count(); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/VirtualDeviceLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/VirtualDeviceLogDataImpl.java new file mode 100644 index 0000000..f573ed9 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/VirtualDeviceLogDataImpl.java @@ -0,0 +1,58 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.es.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.model.device.VirtualDeviceLog; +import cc.iotkit.temporal.IVirtualDeviceLogData; +import cc.iotkit.temporal.es.dao.VirtualDeviceLogRepository; +import cc.iotkit.temporal.es.document.DocVirtualDeviceLog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.stream.Collectors; + +@Service +public class VirtualDeviceLogDataImpl implements IVirtualDeviceLogData { + + @Autowired + private VirtualDeviceLogRepository virtualDeviceLogRepository; + + @Override + public Paging findByVirtualDeviceId(String virtualDeviceId, int page, int size) { + Page paged = virtualDeviceLogRepository + .findByVirtualDeviceId(virtualDeviceId, + Pageable.ofSize(size).withPage(page - 1)); + return new Paging<>(paged.getTotalElements(), paged.getContent().stream() + .map(o -> MapstructUtils.convert(o, VirtualDeviceLog.class)) + .collect(Collectors.toList())); + } + + @Override + public void add(VirtualDeviceLog log) { + virtualDeviceLogRepository.save(MapstructUtils.convert(log, DocVirtualDeviceLog.class)); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-iotdb/pom.xml b/iot-dao/iot-temporal-serviceImpl-iotdb/pom.xml new file mode 100644 index 0000000..1787057 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-iotdb/pom.xml @@ -0,0 +1,57 @@ + + + + iot-dao + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-temporal-serviceImpl-iotdb + + + + + cc.iotkit + iot-temporal-service + + + + cc.iotkit + iot-data-serviceImpl-cache + + + + + + org.apache.iotdb + iotdb-session + 1.2.2 + + + + org.springframework + spring-context + + + + org.projectlombok + lombok + provided + + + + com.fasterxml.jackson.core + jackson-annotations + + + + io.github.linpeilie + mapstruct-plus-spring-boot-starter + + + + + \ No newline at end of file diff --git a/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/config/IotDbConf.java b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/config/IotDbConf.java new file mode 100644 index 0000000..e78ac01 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/config/IotDbConf.java @@ -0,0 +1,61 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.temporal.iotdb.config; + + +import org.apache.iotdb.session.pool.SessionPool; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * iotdb数据库配置 + * + * @author sjg + */ +@Configuration +public class IotDbConf { + + @Value("${spring.iotdb-datasource.host}") + private String host; + + @Value("${spring.iotdb-datasource.port}") + private int port; + + @Value("${spring.iotdb-datasource.username}") + private String username; + + @Value("${spring.iotdb-datasource.password}") + private String password; + + @Bean + public SessionPool getSession() { + return new SessionPool.Builder() + .host(host) + .port(port) + .user(username) + .password(password) + .build(); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/dao/IotDbTemplate.java b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/dao/IotDbTemplate.java new file mode 100644 index 0000000..0ff1186 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/dao/IotDbTemplate.java @@ -0,0 +1,97 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.temporal.iotdb.dao; + +import lombok.Data; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.apache.iotdb.isession.pool.SessionDataSetWrapper; +import org.apache.iotdb.session.pool.SessionPool; +import org.apache.iotdb.tsfile.read.common.Field; +import org.apache.iotdb.tsfile.read.common.RowRecord; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author sjg + */ +@Slf4j +@Component +@Data +public class IotDbTemplate { + + @Autowired + private SessionPool sessionPool; + + private static String group = "root.iotkit"; + + private String getPath(String productKey, String deviceId) { + return group + "." + productKey + "." + deviceId; + } + + /** + * 对齐插入时序序列 + * @param productKey 产品key + * @param deviceId 设备id + * @param time 数据时间 + * @param data 数据键值对 + */ + @SneakyThrows + public void insert(String productKey, String deviceId, long time, Map data) { + String path = getPath(productKey, deviceId); + List measurements = new ArrayList<>(); + // 需要服务器做类型判断 + List values = new ArrayList<>(); + for (String key : data.keySet()) { + measurements.add(key); + values.add(String.valueOf(data.get(key))); + } + //对齐插入,使用PREVIOUS填充查询 + sessionPool.insertAlignedRecord(path, time, measurements, values); + } + + @SneakyThrows + public List> query(String productKey, String deviceId,long startTime,long endTime) { + List> list = new ArrayList<>(); + SessionDataSetWrapper dataSetWrapper = sessionPool.executeRawDataQuery( + List.of(getPath(productKey,deviceId)),startTime,endTime,5000); + while (dataSetWrapper.hasNext()) { + RowRecord record = dataSetWrapper.next(); + Map data = new HashMap<>(record.getFields().size() + 1); + long time = record.getTimestamp(); + data.put("time", time); + for (Field field : record.getFields()) { + field.getObjectValue(field.getDataType()); + } + list.add(data); + } + return list; + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/model/Record.java b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/model/Record.java new file mode 100644 index 0000000..4ce188a --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/model/Record.java @@ -0,0 +1,46 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.temporal.iotdb.model; + + +/** + * @author sjg + */ +public interface Record { + + /** + * 设备Id + * + * @return string + */ + String getDeviceId(); + + /** + * 时间 + * + * @return long + */ + Long getTime(); + +} diff --git a/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/DbStructureDataImpl.java b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/DbStructureDataImpl.java new file mode 100644 index 0000000..f99a289 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/DbStructureDataImpl.java @@ -0,0 +1,59 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.iotdb.service; + +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.model.product.ThingModel; +import cc.iotkit.temporal.IDbStructureData; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; + +@Slf4j +@Service +public class DbStructureDataImpl implements IDbStructureData { + + @SneakyThrows + @Override + public void defineThingModel(ThingModel thingModel) { + //无须处理,自动创建 + } + + @Override + public void updateThingModel(ThingModel thingModel) { + throw new BizException(ErrCode.UNSUPPORTED_OPERATION_EXCEPTION); + } + + /** + * 初始化其它数据结构 + */ + @Override + @PostConstruct + public void initDbStructure() { + + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/DevicePropertyDataImpl.java b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/DevicePropertyDataImpl.java new file mode 100644 index 0000000..42dffed --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/DevicePropertyDataImpl.java @@ -0,0 +1,85 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.iotdb.service; + +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DeviceProperty; +import cc.iotkit.model.device.message.DevicePropertyCache; +import cc.iotkit.temporal.IDevicePropertyData; +import cc.iotkit.temporal.iotdb.dao.IotDbTemplate; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +@Service +public class DevicePropertyDataImpl implements IDevicePropertyData { + + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + + @Autowired + private IotDbTemplate dbTemplate; + + @Override + public List findDevicePropertyHistory(String deviceId, String name, long start, long end, int size) { + DeviceInfo device = deviceInfoData.findByDeviceId(deviceId); + if (device == null) { + return new ArrayList<>(); + } + List list=new ArrayList<>(); + List> records = dbTemplate.query(device.getProductKey(), deviceId, start, end); + int i=0; + for (Map record : records) { + Object val = record.get(name); + list.add(new DeviceProperty(String.valueOf(++i),deviceId,name,val, (Long) record.get("time"))); + } + + return list; + } + + @Override + public void addProperties(String deviceId, Map properties, long time) { + DeviceInfo device = deviceInfoData.findByDeviceId(deviceId); + if (device == null) { + return; + } + //获取设备旧属性 + Map oldProperties = deviceInfoData.getProperties(deviceId); + //用新属性覆盖 + oldProperties.putAll(properties); + Map data = new HashMap<>(oldProperties.size()); + oldProperties.forEach((k, v) -> data.put(k, v.getValue())); + //添加对齐序列 + dbTemplate.insert(device.getProductKey(), deviceId, System.currentTimeMillis(), data); + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/RuleLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/RuleLogDataImpl.java new file mode 100644 index 0000000..5998d9f --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/RuleLogDataImpl.java @@ -0,0 +1,45 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.iotdb.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.rule.RuleLog; +import cc.iotkit.temporal.IRuleLogData; +import org.springframework.stereotype.Service; + +@Service +public class RuleLogDataImpl implements IRuleLogData { + + @Override + public void deleteByRuleId(String ruleId) { + } + + @Override + public Paging findByRuleId(String ruleId, int page, int size) { + return new Paging<>(); + } + + @Override + public void add(RuleLog log) { + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/TaskLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/TaskLogDataImpl.java new file mode 100644 index 0000000..386cc9f --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/TaskLogDataImpl.java @@ -0,0 +1,45 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.iotdb.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.rule.TaskLog; +import cc.iotkit.temporal.ITaskLogData; +import org.springframework.stereotype.Service; + +@Service +public class TaskLogDataImpl implements ITaskLogData { + + @Override + public void deleteByTaskId(String taskId) { + } + + @Override + public Paging findByTaskId(String taskId, int page, int size) { + return new Paging<>(); + } + + @Override + public void add(TaskLog log) { + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/ThingModelMessageDataImpl.java b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/ThingModelMessageDataImpl.java new file mode 100644 index 0000000..2ffb4f0 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/ThingModelMessageDataImpl.java @@ -0,0 +1,72 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.iotdb.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.model.stats.TimeData; +import cc.iotkit.temporal.IThingModelMessageData; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class ThingModelMessageDataImpl implements IThingModelMessageData { + + @Override + public Paging findByTypeAndIdentifier(String deviceId, String type, + String identifier, + int page, int size) { + return new Paging<>(); + } + + @Override + public List getDeviceMessageStatsWithUid(String uid, long start, long end) { + return new ArrayList<>(); + } + + @Override + public List getDeviceUpMessageStatsWithUid(String uid, Long start, Long end) { + return null; + } + + @Override + public List getDeviceDownMessageStatsWithUid(String uid, Long start, Long end) { + return null; + } + + @Override + public Paging findByTypeAndDeviceIds(List deviceIds, String type, String identifier, int page, int size) { + return new Paging<>(); + } + + @Override + public void add(ThingModelMessage msg) { + } + + @Override + public long count() { + return 0L; + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/VirtualDeviceLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/VirtualDeviceLogDataImpl.java new file mode 100644 index 0000000..d4835cd --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-iotdb/src/main/java/cc/iotkit/temporal/iotdb/service/VirtualDeviceLogDataImpl.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.iotdb.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.device.VirtualDeviceLog; +import cc.iotkit.temporal.IVirtualDeviceLogData; +import org.springframework.stereotype.Service; + +@Service +public class VirtualDeviceLogDataImpl implements IVirtualDeviceLogData { + + @Override + public Paging findByVirtualDeviceId(String virtualDeviceId, int page, int size) { + return new Paging<>(); + } + + @Override + public void add(VirtualDeviceLog log) { + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/pom.xml b/iot-dao/iot-temporal-serviceImpl-td/pom.xml new file mode 100644 index 0000000..7737d28 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/pom.xml @@ -0,0 +1,86 @@ + + + + iot-dao + cc.iotkit + 0.5.3 + + 4.0.0 + 0.5.3 + iot-temporal-serviceImpl-td + + + 时序数据库服务接口的TDengine实现 + TDengine版本:3.x + + + + + + cc.iotkit + iot-temporal-service + + + + cc.iotkit + iot-data-serviceImpl-cache + + + + + + org.springframework + spring-context + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + com.taosdata.jdbc + taos-jdbcdriver + 3.2.4 + + + + org.projectlombok + lombok + provided + + + + com.fasterxml.jackson.core + jackson-annotations + + + + io.github.linpeilie + mapstruct-plus-spring-boot-starter + + + + cn.hutool + hutool-http + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + + + \ No newline at end of file diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/Constants.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/Constants.java new file mode 100644 index 0000000..5e5639a --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/Constants.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.config; + +public interface Constants { + + /** + * 根据产品key获取产品属性超级表名 + */ + static String getProductPropertySTableName(String productKey) { + return String.format("product_property_%s", productKey.toLowerCase()); + } + + /** + * 根据deviceId获取设备属性表名 + */ + static String getDevicePropertyTableName(String deviceId) { + return String.format("device_property_%s", deviceId.toLowerCase()); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/TdDatasourceConfig.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/TdDatasourceConfig.java new file mode 100644 index 0000000..6483e3b --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/TdDatasourceConfig.java @@ -0,0 +1,58 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.config; + +import cc.iotkit.temporal.td.dao.TdTemplate; +import com.zaxxer.hikari.HikariDataSource; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration +public class TdDatasourceConfig { + + @Value("${spring.td-datasource.url}") + private String url; + + @Value("${spring.td-datasource.driverClassName}") + private String driverClassName; + + @Value("${spring.td-datasource.username}") + private String username; + + @Value("${spring.td-datasource.password}") + private String password; + + @Bean("tdJdbcTemplate") + @Primary + public TdTemplate tdJdbcTemplate() { + HikariDataSource dataSource = new HikariDataSource(); + dataSource.setJdbcUrl(url); + dataSource.setUsername(username); + dataSource.setPassword(password); + dataSource.setDriverClassName(driverClassName); + return new TdTemplate(dataSource); + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dao/TdTemplate.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dao/TdTemplate.java new file mode 100644 index 0000000..7fded5b --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dao/TdTemplate.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.dao; + +import org.springframework.jdbc.core.JdbcTemplate; + +import javax.sql.DataSource; + +public class TdTemplate extends JdbcTemplate { + + public TdTemplate() { + } + + public TdTemplate(DataSource dataSource) { + super(dataSource); + } + + public TdTemplate(DataSource dataSource, boolean lazyInit) { + super(dataSource, lazyInit); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/FieldParser.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/FieldParser.java new file mode 100644 index 0000000..d541c10 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/FieldParser.java @@ -0,0 +1,106 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.dm; + +import cc.iotkit.common.exception.BizException; +import cc.iotkit.model.product.ThingModel; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class FieldParser { + + /** + * 物模型到td数据类型映射 + */ + private static final Map TYPE_MAPPING = Map.of( + "int32", "INT", + "float", "FLOAT", + "bool", "TINYINT", + "enum", "TINYINT", + "text", "NCHAR", + "date", "NCHAR", + "position", "NCHAR" + ); + + /** + * 将物模型字段转换为td字段 + */ + public static TdField parse(ThingModel.Property property) { + String filedName = property.getIdentifier().toLowerCase(); + ThingModel.DataType dataType = property.getDataType(); + String type = dataType.getType(); + + //将物模型字段类型映射为td字段类型 + String fType = TYPE_MAPPING.get(type); + Object specs = dataType.getSpecs(); + int len = -1; + if (specs instanceof Map) { + Object objLen = ((Map) specs).get("length"); + if (objLen != null) { + try{ + len = Integer.parseInt(objLen.toString()); + }catch (Exception e){ + throw new BizException(filedName+" 长度错误"); + } + if("NCHAR".equals(fType) && len <1){ + throw new BizException(filedName+" 长度错误"); + } + } + } + + return new TdField(filedName, fType, len); + } + + /** + * 获取物模型中的字段列表 + */ + public static List parse(ThingModel thingModel) { + return thingModel.getModel().getProperties().stream().map(FieldParser::parse).collect(Collectors.toList()); + } + + /** + * 将从库中查出来的字段信息转换为td字段对象 + */ + public static List parse(List rows) { + return (List) rows.stream().map((r) -> { + List row = (List) r; + String type = row.get(1).toString().toUpperCase(); + return new TdField( + row.get(0).toString(), + type, + type.equals("NCHAR") ? Integer.parseInt(row.get(2).toString()) : -1); + }).collect(Collectors.toList()); + } + + /** + * 获取字段字义 + */ + public static String getFieldDefine(TdField field) { + return field.getName() + " " + (field.getLength() > 0 ? + String.format("%s(%d)", field.getType(), field.getLength()) + : field.getType()); + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TableManager.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TableManager.java new file mode 100644 index 0000000..9bcf3a1 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TableManager.java @@ -0,0 +1,148 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.dm; + +import java.util.List; + +public class TableManager { + + /** + * 创建超级表模板(含存在判断) + */ + private static final String CREATE_STABLE_INE_TPL = "CREATE STABLE IF NOT EXISTS %s (%s) TAGS (%s);"; + + /** + * 删除超级表 + */ + private static final String DROP_STABLE_TPL = "DROP STABLE IF EXISTS %s;"; + + /** + * 获取表的结构信息 + */ + private static final String DESC_TB_TPL = "DESCRIBE %s;"; + + /** + * 超级表增加列 + */ + private static final String ALTER_STABLE_ADD_COL_TPL = "ALTER STABLE %s ADD COLUMN %s;"; + + /** + * 超级表修改列 + */ + private static final String ALTER_STABLE_MODIFY_COL_TPL = "ALTER STABLE %s MODIFY COLUMN %s;"; + + /** + * 超级表删除列 + */ + private static final String ALTER_STABLE_DROP_COL_TPL = "ALTER STABLE %s DROP COLUMN %s;"; + + /** + * 获取创建表sql + */ + public static String getCreateSTableSql(String tbName, List fields, TdField... tags) { + if (fields.isEmpty()) { + return null; + } + + //生成字段片段 + StringBuilder sbField = new StringBuilder("time timestamp,"); + + for (TdField field : fields) { + sbField.append(FieldParser.getFieldDefine(field)); + sbField.append(","); + } + sbField.deleteCharAt(sbField.length() - 1); + + String fieldFrag = sbField.toString(); + + //生成tag + StringBuilder sbTag = new StringBuilder(); + for (TdField tag : tags) { + sbTag.append(FieldParser.getFieldDefine(tag)) + .append(","); + } + sbTag.deleteCharAt(sbTag.length() - 1); + + return String.format(CREATE_STABLE_INE_TPL, tbName, fieldFrag, sbTag.toString()); + + } + + /** + * 取正确的表名 + * + * @param name 表象 + */ + public static String rightTbName(String name) { + return name.toLowerCase().replace("-", "_"); + } + + /** + * 获取表详情的sql + */ + public static String getDescTableSql(String tbName) { + return String.format(DESC_TB_TPL, tbName); + } + + /** + * 获取添加字段sql + */ + public static String getAddSTableColumnSql(String tbName, List fields) { + StringBuilder sbAdd = new StringBuilder(); + for (TdField field : fields) { + sbAdd.append(String.format(ALTER_STABLE_ADD_COL_TPL, + tbName, + FieldParser.getFieldDefine(field) + )); + } + return sbAdd.toString(); + } + + /** + * 获取修改字段sql + */ + public static String getModifySTableColumnSql(String tbName, List fields) { + StringBuilder sbModify = new StringBuilder(); + for (TdField field : fields) { + sbModify.append(String.format(ALTER_STABLE_MODIFY_COL_TPL, + tbName, + FieldParser.getFieldDefine(field) + )); + } + return sbModify.toString(); + } + + /** + * 获取删除字段sql + */ + public static String getDropSTableColumnSql(String tbName, List fields) { + StringBuilder sbDrop = new StringBuilder(); + for (TdField field : fields) { + sbDrop.append(String.format(ALTER_STABLE_DROP_COL_TPL, + tbName, + field.getName() + )); + } + return sbDrop.toString(); + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdField.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdField.java new file mode 100644 index 0000000..3ff4e68 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdField.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.dm; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TdField { + private String name; + private String type; + private int length; +} \ No newline at end of file diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdResponse.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdResponse.java new file mode 100644 index 0000000..956b934 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdResponse.java @@ -0,0 +1,48 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.dm; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TdResponse { + + public static final int CODE_SUCCESS = 0; + public static final int CODE_TB_NOT_EXIST = 9731; + + private String status; + + private int code; + + private String desc; + + //[["time","TIMESTAMP",8,""],["powerstate","TINYINT",1,""],["brightness","INT",4,""],["deviceid","NCHAR",32,"TAG"]] + private List data; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdRestApi.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdRestApi.java new file mode 100644 index 0000000..c843f3b --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdRestApi.java @@ -0,0 +1,77 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.dm; + +import cc.iotkit.common.utils.JsonUtils; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class TdRestApi { + + @Value("${spring.td-datasource.url}") + private String url; + + @Value("${spring.td-datasource.username}") + private String username; + + @Value("${spring.td-datasource.password}") + private String password; + + private String getRestApiUrl() { + //jdbc:TAOS-RS://127.0.0.1:6041/iotkit?xxxx + String restUrl = url.replace("jdbc:TAOS-RS://", "") + .replaceAll("\\?.*", ""); + // /rest/sql/iotkit + int idx = restUrl.lastIndexOf("/"); + //127.0.0.1:6041/rest/sql/iotkit + return String.format("%s/rest/sql/%s", restUrl.substring(0, idx), restUrl.substring(idx + 1)); + } + + + /** + * 新建td api请求对象 + */ + public HttpRequest newApiRequest(String sql) { + return HttpRequest + .post(getRestApiUrl()) + .body(sql) + .basicAuth(username, password); + } + + /** + * 执行sql + */ + public TdResponse execSql(String sql) { + log.info("exec td sql:{}", sql); + HttpRequest request = newApiRequest(sql); + HttpResponse response = request.execute(); + return JsonUtils.parseObject(response.body(), TdResponse.class); + } + + +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbDeviceProperty.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbDeviceProperty.java new file mode 100644 index 0000000..a9d01e9 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbDeviceProperty.java @@ -0,0 +1,42 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TbDeviceProperty { + + private Long time; + + private String deviceId; + + private String name; + + private Object value; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbRuleLog.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbRuleLog.java new file mode 100644 index 0000000..fbacc4e --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbRuleLog.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TbRuleLog { + + private Long time; + + private String ruleId; + + private String state1; + + private String content; + + private Boolean success; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbTaskLog.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbTaskLog.java new file mode 100644 index 0000000..27d45fc --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbTaskLog.java @@ -0,0 +1,42 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TbTaskLog { + + private Long time; + + private String taskId; + + private String content; + + private Boolean success; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbThingModelMessage.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbThingModelMessage.java new file mode 100644 index 0000000..3638a72 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbThingModelMessage.java @@ -0,0 +1,56 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TbThingModelMessage { + + private Long time; + + private String mid; + + private String deviceId; + + private String productKey; + + private String deviceName; + + private String uid; + + private String type; + + private String identifier; + + private int code; + + private String data; + + private Long reportTime; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbVirtualDeviceLog.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbVirtualDeviceLog.java new file mode 100644 index 0000000..e431e18 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbVirtualDeviceLog.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TbVirtualDeviceLog { + + private Long time; + + private String virtualDeviceId; + + private String virtualDeviceName; + + private int deviceTotal; + + private String result; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DbStructureDataImpl.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DbStructureDataImpl.java new file mode 100644 index 0000000..f941dd9 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DbStructureDataImpl.java @@ -0,0 +1,206 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.service; + +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.model.product.ThingModel; +import cc.iotkit.temporal.IDbStructureData; +import cc.iotkit.temporal.td.config.Constants; +import cc.iotkit.temporal.td.dm.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import java.util.List; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class DbStructureDataImpl implements IDbStructureData { + + @Autowired + private TdRestApi tdRestApi; + + @Value("${spring.td-datasource.db:iotkit}") + private String dbName; + + /** + * 根据物模型创建超级表 + */ + @Override + public void defineThingModel(ThingModel thingModel) { + //获取物模型中的属性定义 + List fields = FieldParser.parse(thingModel); + String tbName = Constants.getProductPropertySTableName(thingModel.getProductKey()); + //生成sql + String sql = TableManager.getCreateSTableSql(tbName, + fields, + new TdField("device_id", "NCHAR", 50)); + if (sql == null) { + return; + } + log.info("executing sql:{}", sql); + + //执行sql + TdResponse response = tdRestApi.execSql(sql); + if (TdResponse.CODE_SUCCESS != response.getCode()) { + throw new BizException(String.format( + "create td stable failed,code:%s,desc:%s" + , response.getCode(), response.getDesc())); + } + } + + /** + * 根据物模型更新超级表结构 + */ + @Override + public void updateThingModel(ThingModel thingModel) { + try { + //获取旧字段信息 + String tbName = Constants.getProductPropertySTableName(thingModel.getProductKey()); + String sql = TableManager.getDescTableSql(tbName); + TdResponse response = tdRestApi.execSql(sql); + int code = response.getCode(); + if (code != TdResponse.CODE_SUCCESS) { + if (TdResponse.CODE_TB_NOT_EXIST == code) { + defineThingModel(thingModel); + return; + } + + throw new BizException("get des table error:" + JsonUtils.toJsonString(response)); + } + + List oldFields = FieldParser.parse(response.getData()); + List newFields = FieldParser.parse(thingModel); + //对比差异 + + //找出新增的字段 + List addFields = newFields.stream().filter((f) -> oldFields.stream() + .noneMatch(old -> old.getName().equals(f.getName()))) + .collect(Collectors.toList()); + if (!addFields.isEmpty()) { + sql = TableManager.getAddSTableColumnSql(tbName, addFields); + response = tdRestApi.execSql(sql); + if (response.getCode() != TdResponse.CODE_SUCCESS) { + throw new BizException("add table column error:" + JsonUtils.toJsonString(response)); + } + } + + //找出修改的字段 + List modifyFields = newFields.stream().filter((f) -> oldFields.stream() + .anyMatch(old -> + old.getName().equals(f.getName()) //字段名相同 + //字段类型或长度不同 + && (!old.getType().equals(f.getType()) || old.getLength() != f.getLength()) + )) + .collect(Collectors.toList()); + + if (!modifyFields.isEmpty()) { + sql = TableManager.getModifySTableColumnSql(tbName, modifyFields); + response = tdRestApi.execSql(sql); + if (response.getCode() != TdResponse.CODE_SUCCESS) { + throw new BizException("modify table column error:" + JsonUtils.toJsonString(response)); + } + } + + //找出删除的字段 + List dropFields = oldFields.stream().filter((f) -> + !"time".equals(f.getName()) && + !"device_id".equals(f.getName()) && newFields.stream() + //字段名不是time且没有相同字段名的 + .noneMatch(n -> n.getName().equals(f.getName()))) + .collect(Collectors.toList()); + if (!dropFields.isEmpty()) { + sql = TableManager.getDropSTableColumnSql(tbName, dropFields); + response = tdRestApi.execSql(sql); + if (response.getCode() != TdResponse.CODE_SUCCESS) { + throw new BizException("drop table column error:" + JsonUtils.toJsonString(response)); + } + } + } catch (Throwable e) { + throw e; + } + } + + /** + * 初始化其它数据结构 + */ + @Override + @PostConstruct + public void initDbStructure() { + tdRestApi.execSql(String.format("CREATE DATABASE IF NOT EXISTS %s KEEP 365 DURATION 10 BUFFER 16 WAL_LEVEL 1;", dbName)); + + //创建规则日志超级表 + String sql = TableManager.getCreateSTableSql("rule_log", List.of( + new TdField("state1", "NCHAR", 32), + new TdField("content", "NCHAR", 1024), + new TdField("success", "BOOL", -1) + ), new TdField("rule_id", "NCHAR", 50)); + TdResponse response = tdRestApi.execSql(sql); + if (response.getCode() != TdResponse.CODE_SUCCESS) { + throw new BizException("create stable rule_log error:" + JsonUtils.toJsonString(response)); + } + + //创建规则日志超级表 + sql = TableManager.getCreateSTableSql("task_log", List.of( + new TdField("content", "NCHAR", 1024), + new TdField("success", "BOOL", -1) + ), new TdField("task_id", "NCHAR", 50)); + response = tdRestApi.execSql(sql); + if (response.getCode() != TdResponse.CODE_SUCCESS) { + throw new BizException("create stable task_log error:" + JsonUtils.toJsonString(response)); + } + + //创建物模型消息超级表 + sql = TableManager.getCreateSTableSql("thing_model_message", List.of( + new TdField("mid", "NCHAR", 50), + new TdField("product_key", "NCHAR", 50), + new TdField("device_name", "NCHAR", 50), + new TdField("uid", "NCHAR", 50), + new TdField("type", "NCHAR", 20), + new TdField("identifier", "NCHAR", 50), + new TdField("code", "INT", -1), + new TdField("data", "NCHAR", 1024), + new TdField("report_time", "BIGINT", -1) + ), new TdField("device_id", "NCHAR", 50)); + response = tdRestApi.execSql(sql); + if (response.getCode() != TdResponse.CODE_SUCCESS) { + throw new BizException("create stable thing_model_message error:" + JsonUtils.toJsonString(response)); + } + + //创建虚拟设备日志超级表 + sql = TableManager.getCreateSTableSql("virtual_device_log", List.of( + new TdField("virtual_device_name", "NCHAR", 50), + new TdField("device_total", "INT", -1), + new TdField("result", "NCHAR", 1024) + ), new TdField("virtual_device_id", "NCHAR", 50)); + response = tdRestApi.execSql(sql); + if (response.getCode() != TdResponse.CODE_SUCCESS) { + throw new BizException("create stable virtual_device_log error:" + JsonUtils.toJsonString(response)); + } + + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DevicePropertyDataImpl.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DevicePropertyDataImpl.java new file mode 100644 index 0000000..4ffeea4 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DevicePropertyDataImpl.java @@ -0,0 +1,112 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.service; + +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DeviceProperty; +import cc.iotkit.model.device.message.DevicePropertyCache; +import cc.iotkit.temporal.IDevicePropertyData; +import cc.iotkit.temporal.td.config.Constants; +import cc.iotkit.temporal.td.dao.TdTemplate; +import cc.iotkit.temporal.td.model.TbDeviceProperty; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class DevicePropertyDataImpl implements IDevicePropertyData { + + @Autowired + private TdTemplate tdTemplate; + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + + @Override + public List findDevicePropertyHistory(String deviceId, String name, long start, long end, int size) { + DeviceInfo device = deviceInfoData.findByDeviceId(deviceId); + if (device == null) { + return new ArrayList<>(); + } + + String tbName = Constants.getProductPropertySTableName(device.getProductKey()); + List deviceProperties = tdTemplate.query(String.format( + "select time,%s as `value`,device_id from %s where device_id=? and time>=? and time<=? " + + "order by time asc limit 0," + size, + name.toLowerCase(), tbName), + new BeanPropertyRowMapper<>(TbDeviceProperty.class), + deviceId, start, end + ); + return deviceProperties.stream().map(p -> new DeviceProperty( + p.getTime().toString(), + p.getDeviceId(), + name, + p.getValue(), + p.getTime())) + .collect(Collectors.toList()); + } + + @Override + public void addProperties(String deviceId, Map properties, long time) { + DeviceInfo device = deviceInfoData.findByDeviceId(deviceId); + if (device == null) { + return; + } + //获取设备旧属性 + Map oldProperties = deviceInfoData.getProperties(deviceId); + //用新属性覆盖 + oldProperties.putAll(properties); + + StringBuilder sbFieldNames = new StringBuilder(); + StringBuilder sbFieldPlaces = new StringBuilder(); + List args = new ArrayList<>(); + args.add(time); + + //组织sql + oldProperties.forEach((key, val) -> { + sbFieldNames.append(key) + .append(","); + sbFieldPlaces.append("?,"); + args.add(val.getValue()); + }); + sbFieldNames.deleteCharAt(sbFieldNames.length() - 1); + sbFieldPlaces.deleteCharAt(sbFieldPlaces.length() - 1); + + String sql = String.format("INSERT INTO %s (time,%s) USING %s TAGS ('%s') VALUES (?,%s);", + Constants.getDevicePropertyTableName(deviceId), + sbFieldNames.toString(), + Constants.getProductPropertySTableName(device.getProductKey()), + deviceId, + sbFieldPlaces.toString()); + + tdTemplate.update(sql, args.toArray()); + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/RuleLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/RuleLogDataImpl.java new file mode 100644 index 0000000..1923a12 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/RuleLogDataImpl.java @@ -0,0 +1,77 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.rule.RuleLog; +import cc.iotkit.temporal.IRuleLogData; +import cc.iotkit.temporal.td.dao.TdTemplate; +import cc.iotkit.temporal.td.dm.TableManager; +import cc.iotkit.temporal.td.model.TbRuleLog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class RuleLogDataImpl implements IRuleLogData { + + @Autowired + private TdTemplate tdTemplate; + + @Override + public void deleteByRuleId(String ruleId) { + tdTemplate.update("delete from rule_log where rule_id=? and time<=NOW()", ruleId); + } + + @Override + public Paging findByRuleId(String ruleId, int page, int size) { + String sql = "select time,state1,content,success,rule_id from rule_log where rule_id=? " + + "order by time desc limit %d offset %d"; + sql = String.format(sql, size, (page - 1) * size); + List ruleLogs = tdTemplate.query(sql, new BeanPropertyRowMapper<>(TbRuleLog.class), ruleId); + + sql = "select count(*) from rule_log where rule_id=?"; + List counts = tdTemplate.queryForList(sql, Long.class, ruleId); + + return new Paging<>(!counts.isEmpty() ? counts.get(0) : 0, ruleLogs.stream().map(r -> + new RuleLog(r.getTime().toString(), ruleId, r.getState1(), + r.getContent(), r.getSuccess(), r.getTime())) + .collect(Collectors.toList())); + } + + @Override + public void add(RuleLog log) { + //使用ruleId作表名 + String sql = String.format("INSERT INTO %s (%s) USING %s TAGS ('%s') VALUES (%s);", + "rule_log_" + TableManager.rightTbName(log.getRuleId()), + "time,state1,content,success", + "rule_log", + log.getRuleId(), + "?,?,?,?" + ); + tdTemplate.update(sql, System.currentTimeMillis(), log.getState(), log.getContent(), log.getSuccess()); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/TaskLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/TaskLogDataImpl.java new file mode 100644 index 0000000..d60af84 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/TaskLogDataImpl.java @@ -0,0 +1,76 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.rule.TaskLog; +import cc.iotkit.temporal.ITaskLogData; +import cc.iotkit.temporal.td.dao.TdTemplate; +import cc.iotkit.temporal.td.dm.TableManager; +import cc.iotkit.temporal.td.model.TbTaskLog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class TaskLogDataImpl implements ITaskLogData { + + @Autowired + private TdTemplate tdTemplate; + + @Override + public void deleteByTaskId(String taskId) { + tdTemplate.update("delete from task_log where task_id=? and time<=NOW()", taskId); + } + + @Override + public Paging findByTaskId(String taskId, int page, int size) { + String sql = "select time,content,success,task_id from task_log where task_id=? order by time desc limit %d offset %d"; + sql = String.format(sql, size, (page - 1) * size); + List taskLogs = tdTemplate.query(sql, new BeanPropertyRowMapper<>(TbTaskLog.class), taskId); + + sql = "select count(*) from task_log where task_id=?"; + List counts = tdTemplate.queryForList(sql, Long.class, taskId); + + return new Paging<>(!counts.isEmpty() ? counts.get(0) : 0, taskLogs.stream().map(r -> + new TaskLog(r.getTime().toString(), taskId, + r.getContent(), r.getSuccess(), r.getTime())) + .collect(Collectors.toList())); + } + + @Override + public void add(TaskLog log) { + //使用taskId作表名 + String sql = String.format("INSERT INTO %s (%s) USING %s TAGS ('%s') VALUES (%s);", + "task_log_" + TableManager.rightTbName(log.getTaskId()), + "time,content,success", + "task_log", + log.getTaskId(), + "?,?,?" + ); + tdTemplate.update(sql, System.currentTimeMillis(), log.getContent(), log.getSuccess()); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/ThingModelMessageDataImpl.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/ThingModelMessageDataImpl.java new file mode 100644 index 0000000..a7485e4 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/ThingModelMessageDataImpl.java @@ -0,0 +1,219 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.model.stats.TimeData; +import cc.iotkit.temporal.IThingModelMessageData; +import cc.iotkit.temporal.td.dao.TdTemplate; +import cc.iotkit.temporal.td.model.TbThingModelMessage; +import cn.hutool.core.util.ObjectUtil; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +public class ThingModelMessageDataImpl implements IThingModelMessageData { + + @Autowired + private TdTemplate tdTemplate; + + @Override + public Paging findByTypeAndIdentifier(String deviceId, String type, + String identifier, + int page, int size) { + String sql = "select time,mid,product_key,device_name,type,identifier,code,data,report_time " + + "from thing_model_message where device_id=? %s order by time desc limit %d offset %d"; + + //构建动态条件 + List args = new ArrayList<>(); + args.add(deviceId); + StringBuilder sbCond = new StringBuilder(); + if (StringUtils.isNotBlank(type)) { + sbCond.append(" and type=? "); + args.add(type); + } + if (StringUtils.isNotBlank(identifier)) { + sbCond.append("and identifier=? "); + args.add(identifier); + } + + sql = String.format(sql, sbCond.toString(), size, (page - 1) * size); + List ruleLogs = tdTemplate.query(sql, + new BeanPropertyRowMapper<>(TbThingModelMessage.class), + args.toArray() + ); + + sql = String.format("select count(*) from thing_model_message where device_id=? %s", + sbCond.toString()); + List counts = tdTemplate.queryForList(sql, Long.class, args.toArray()); + long count = !counts.isEmpty() ? counts.get(0) : 0; + + return new Paging<>(count, ruleLogs.stream().map(r -> + new ThingModelMessage(r.getTime().toString(), r.getMid(), + deviceId, r.getProductKey(), r.getDeviceName(), + r.getUid(), r.getType(), r.getIdentifier(), r.getCode(), + JsonUtils.parseObject(r.getData(), Map.class), + r.getTime(), r.getReportTime())) + .collect(Collectors.toList())); + } + + @Override + public Paging findByTypeAndDeviceIds(List deviceIds, String type, + String identifier, + int page, int size) { + String sql = "select time,mid,product_key,device_name,type,identifier,code,data,report_time " + + "from thing_model_message where type=? %s order by time desc limit %d offset %d"; + + //构建动态条件 + List args = new ArrayList<>(); + args.add(type); + StringBuilder sbCond = new StringBuilder(); + if (deviceIds.size()>0) { + sbCond.append(" and deviceIds in (?) "); + args.add(String.join(",",deviceIds)); + } + if (StringUtils.isNotBlank(identifier)) { + sbCond.append("and identifier=? "); + args.add(identifier); + } + + sql = String.format(sql, sbCond.toString(), size, (page - 1) * size); + List ruleLogs = tdTemplate.query(sql, + new BeanPropertyRowMapper<>(TbThingModelMessage.class), + args.toArray() + ); + + sql = String.format("select count(*) from thing_model_message where type=? %s", + sbCond.toString()); + List counts = tdTemplate.queryForList(sql, Long.class, args.toArray()); + long count = !counts.isEmpty() ? counts.get(0) : 0; + + return new Paging<>(count, ruleLogs.stream().map(r -> + new ThingModelMessage(r.getTime().toString(), r.getMid(), + r.getDeviceId(), r.getProductKey(), r.getDeviceName(), + r.getUid(), r.getType(), r.getIdentifier(), r.getCode(), + JsonUtils.parseObject(r.getData(), Map.class), + r.getTime(), r.getReportTime())) + .collect(Collectors.toList())); + } + + @Override + public List getDeviceMessageStatsWithUid(String uid, long start, long end) { + String sql = "select time,count(*) as data from(" + + "select TIMETRUNCATE(time,1h) as time from thing_model_message " + + "where time>=? and time<=? " + (uid != null ? "and uid=?" : "") + + ") a group by time order by time asc"; + + List args = new ArrayList<>(); + args.add(start); + args.add(end); + if (uid != null) { + args.add(uid); + } + + return tdTemplate.query(sql, new BeanPropertyRowMapper<>(TimeData.class), args.toArray()); + } + + @Override + public List getDeviceUpMessageStatsWithUid(String uid, Long start, Long end) { + String sql = "select time,count(*) as data from(" + + "select TIMETRUNCATE(time,1h) as time from thing_model_message " + + "where (type='property' and identifier='report') or type='event' "; + StringBuilder sqlBuffer = new StringBuilder(); + sqlBuffer.append(sql); + + List args = new ArrayList<>(); + if (ObjectUtil.isNotEmpty(uid)) { + sqlBuffer.append(" and uid=?"); + args.add(uid); + } + + if (ObjectUtil.isNotEmpty(start) && ObjectUtil.isNotEmpty(end)) { + sqlBuffer.append(" and time>=? and time<=?"); + args.add(start); + args.add(end); + } + + sqlBuffer.append(") a group by time order by time asc"); + + return tdTemplate.query(sqlBuffer.toString(), new BeanPropertyRowMapper<>(TimeData.class), args.toArray()); + } + + @Override + public List getDeviceDownMessageStatsWithUid(String uid, Long start, Long end) { + String sql = "select time,count(*) as data from(" + + "select TIMETRUNCATE(time,1h) as time from thing_model_message " + + "where (type='property' and identifier!='report') or type='service' or type= 'config' "; + StringBuilder sqlBuffer = new StringBuilder(); + sqlBuffer.append(sql); + + List args = new ArrayList<>(); + if (ObjectUtil.isNotEmpty(uid)) { + sqlBuffer.append(" and uid=?"); + args.add(uid); + } + + if (ObjectUtil.isNotEmpty(start) && ObjectUtil.isNotEmpty(end)) { + sqlBuffer.append(" and time>=? and time<=?"); + args.add(start); + args.add(end); + } + + sqlBuffer.append(") a group by time order by time asc"); + + return tdTemplate.query(sqlBuffer.toString(), new BeanPropertyRowMapper<>(TimeData.class), args.toArray()); + } + + @Override + public void add(ThingModelMessage msg) { + //使用deviceId作表名 + String sql = String.format("INSERT INTO %s (%s) USING %s TAGS ('%s') VALUES (%s);", + "thing_model_message_" + msg.getDeviceId().toLowerCase(), + "time,mid,product_key,device_name,uid,type,identifier,code,data,report_time", + "thing_model_message", + msg.getDeviceId(), + "?,?,?,?,?,?,?,?,?,?" + ); + tdTemplate.update(sql, msg.getOccurred(), msg.getMid(), + msg.getProductKey(), msg.getDeviceName(), + msg.getUid(), msg.getType(), + msg.getIdentifier(), msg.getCode(), + msg.getData() == null ? "{}" : JsonUtils.toJsonString(msg.getData()), + msg.getTime()); + } + + @Override + public long count() { + List counts = tdTemplate.queryForList("select count(*) from thing_model_message", Long.class); + return !counts.isEmpty() ? counts.get(0) : 0; + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/VirtualDeviceLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/VirtualDeviceLogDataImpl.java new file mode 100644 index 0000000..f64dd91 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/VirtualDeviceLogDataImpl.java @@ -0,0 +1,73 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.temporal.td.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.device.VirtualDeviceLog; +import cc.iotkit.temporal.IVirtualDeviceLogData; +import cc.iotkit.temporal.td.dao.TdTemplate; +import cc.iotkit.temporal.td.model.TbVirtualDeviceLog; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class VirtualDeviceLogDataImpl implements IVirtualDeviceLogData { + + @Autowired + private TdTemplate tdTemplate; + + @Override + public Paging findByVirtualDeviceId(String virtualDeviceId, int page, int size) { + String sql = "select time,virtual_device_id,virtual_device_name,device_total,result from virtual_device_log_%s order by time desc limit %d offset %d"; + sql = String.format(sql, virtualDeviceId.toLowerCase(), size, (page - 1) * size); + List logs = tdTemplate.query(sql, new BeanPropertyRowMapper<>(TbVirtualDeviceLog.class)); + + sql = "select count(*) from virtual_device_log_" + virtualDeviceId.toLowerCase(); + List counts = tdTemplate.queryForList(sql, Long.class); + + return new Paging<>(!counts.isEmpty() ? counts.get(0) : 0, logs.stream().map(r -> + new VirtualDeviceLog(r.getTime().toString(), virtualDeviceId, + r.getVirtualDeviceName(), + r.getDeviceTotal(), r.getResult(), + r.getTime())) + .collect(Collectors.toList())); + } + + @Override + public void add(VirtualDeviceLog log) { + //使用virtualDeviceId作表名 + String sql = String.format("INSERT INTO %s (%s) USING %s TAGS ('%s') VALUES (%s);", + "virtual_device_log_" + log.getVirtualDeviceId().toLowerCase(), + "time,virtual_device_name,device_total,result", + "virtual_device_log", + log.getVirtualDeviceId(), + "?,?,?,?" + ); + tdTemplate.update(sql, System.currentTimeMillis(), log.getVirtualDeviceName(), + log.getDeviceTotal(), log.getResult()); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/pom.xml b/iot-dao/iot-temporal-serviceImpl-ts/pom.xml new file mode 100644 index 0000000..9df0aa0 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/pom.xml @@ -0,0 +1,111 @@ + + + 4.0.0 + + iot-dao + cc.iotkit + 0.5.3 + + 0.5.3 + iot-temporal-serviceImpl-ts + + + 时序数据库服务接口的TimescaleDB实现 + postgrep 14 + + + + 11 + 11 + UTF-8 + + + + + cc.iotkit + iot-data-serviceImpl-cache + + + + cc.iotkit + iot-data-model + + + + cc.iotkit + iot-data-model + + + + cc.iotkit + iot-temporal-service + + + + + + org.springframework + spring-context + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + org.projectlombok + lombok + + + + com.fasterxml.jackson.core + jackson-annotations + + + + cn.hutool + hutool-http + + + + org.jooq + jooq-meta + 3.14.15 + + + + org.jooq + jooq + 3.14.15 + + + + org.postgresql + postgresql + 42.5.4 + + + org.springframework + spring-jdbc + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + + + \ No newline at end of file diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/config/Constants.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/config/Constants.java new file mode 100644 index 0000000..5a6bb3f --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/config/Constants.java @@ -0,0 +1,27 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.config; + +public interface Constants { + + /** + * 根据产品key获取产品属性超级表名 + */ + static String getProductPropertySTableName(String productKey) { + return String.format("product_property_%s", productKey.toLowerCase()); + } + + /** + * 根据deviceId获取设备属性表名 + */ + static String getDevicePropertyTableName(String deviceId) { + return String.format("device_property_%s", deviceId.toLowerCase()); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/config/TsDatasourceConfig.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/config/TsDatasourceConfig.java new file mode 100644 index 0000000..a7dca33 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/config/TsDatasourceConfig.java @@ -0,0 +1,44 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.config; + +import cc.iotkit.temporal.ts.dao.TsTemplate; +import com.zaxxer.hikari.HikariDataSource; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class TsDatasourceConfig { + + @Value("${spring.ts-datasource.url}") + private String url; + + @Value("${spring.ts-datasource.driverClassName}") + private String driverClassName; + + @Value("${spring.ts-datasource.username}") + private String username; + + @Value("${spring.ts-datasource.password}") + private String password; + + @Bean("tsJdbcTemplate") + @Primary + public TsTemplate tdJdbcTemplate() { + HikariDataSource dataSource = new HikariDataSource(); + dataSource.setJdbcUrl(url); + dataSource.setUsername(username); + dataSource.setPassword(password); + dataSource.setDriverClassName(driverClassName); + return new TsTemplate(dataSource); + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dao/TsTemplate.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dao/TsTemplate.java new file mode 100644 index 0000000..bb9c316 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dao/TsTemplate.java @@ -0,0 +1,19 @@ +package cc.iotkit.temporal.ts.dao; + +import org.springframework.jdbc.core.JdbcTemplate; + +import javax.sql.DataSource; + +public class TsTemplate extends JdbcTemplate { + + public TsTemplate() { + } + + public TsTemplate(DataSource dataSource) { + super(dataSource); + } + + public TsTemplate(DataSource dataSource, boolean lazyInit) { + super(dataSource, lazyInit); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/DbField.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/DbField.java new file mode 100644 index 0000000..c9d7443 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/DbField.java @@ -0,0 +1,15 @@ +package cc.iotkit.temporal.ts.dm; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class DbField { + private String name; + private String type; + + private int length; +} \ No newline at end of file diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/FieldParser.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/FieldParser.java new file mode 100644 index 0000000..60223f4 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/FieldParser.java @@ -0,0 +1,119 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.dm; + + +import cc.iotkit.model.product.ThingModel; +import org.jooq.DataType; +import org.jooq.Field; +import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +public class FieldParser { + + /** + * 物模型到td数据类型映射 + */ + private static final Map TYPE_MAPPING = Map.of( + "int32", SQLDataType.INTEGER, + "float", SQLDataType.FLOAT, + "bool", SQLDataType.INTEGER, + "enum", SQLDataType.INTEGER, + "text", SQLDataType.NVARCHAR, + "date", SQLDataType.DATE, + "position", SQLDataType.NVARCHAR + ); + + /** + * td数据类型到物模型映射 + */ + + private static final Map DB2TYPE_MAPPING = Map.of( + "int",SQLDataType.INTEGER, + "float", SQLDataType.FLOAT, + "bool", SQLDataType.INTEGER, + "char",SQLDataType.NVARCHAR, + "date", SQLDataType.DATE, + "timestamptz", SQLDataType.TIMESTAMPWITHTIMEZONE + ); + + + private static DataType getFieldType(final String type) { + Set keys = DB2TYPE_MAPPING.keySet(); + String lowerCase = type.toLowerCase(); + for(String key:keys){ + if(lowerCase.contains(key)){ + return DB2TYPE_MAPPING.get(key); + } + } + return null; + } + + /** + * 将物模型字段转换为td字段 + */ + public static TsField parse(ThingModel.Property property) { + String filedName = property.getIdentifier().toLowerCase(); + ThingModel.DataType dataType = property.getDataType(); + String type = dataType.getType(); + + //将物模型字段类型映射为td字段类型 + DataType fType = TYPE_MAPPING.get(type); + Object specs = dataType.getSpecs(); + int len = -1; + if (specs instanceof Map) { + Object objLen = ((Map) specs).get("length"); + if (objLen != null) { + len = Integer.parseInt(objLen.toString()); + } + } + + return new TsField(filedName, fType, len); + } + + /** + * 获取物模型中的字段列表 + */ + public static List parse(ThingModel thingModel) { + return thingModel.getModel().getProperties().stream().map(FieldParser::parse).collect(Collectors.toList()); + } + + /** + * 将从库中查出来的字段信息转换为td字段对象 + */ + public static List parse(List rows) { + return (List) rows.stream().map((r) -> { + + return new TsField( + r.getName(), + getFieldType(r.getType()).length(r.getLength()),r.getLength()); + }).collect(Collectors.toList()); + } + + /** + * 获取字段字义 + */ + public static Field getFieldDefine(TsField field) { + int length = field.getLength(); + DataType type = field.getType(); + + if(length>0){ + type.length(length); + } + return DSL.field(field.getName(),type); + + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/TableManager.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/TableManager.java new file mode 100644 index 0000000..0cb13a3 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/TableManager.java @@ -0,0 +1,161 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.dm; + +import org.jooq.*; +import org.jooq.conf.ParamType; +import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; +import org.jooq.tools.StringUtils; + +import java.util.List; + +import static org.jooq.impl.DSL.*; + +public class TableManager { + + private static final DSLContext sqlBuilder = DSL.using(SQLDialect.POSTGRES); + + public static DSLContext getSqlBuilder() { + return sqlBuilder; + } + + /** + * 获取创建表sql + */ + public static String getCreateSTableSql(String tbName, List fields) { + if (fields.size() == 0) { + return null; + } + + CreateTableColumnStep tableColumnStep = sqlBuilder.createTable(tbName) + .column("time", SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false)) + .column(field("device_id", SQLDataType.NCHAR.length(50).nullable(false))); + + //生成字段片段 + + for (TsField field : fields) { + tableColumnStep.column(FieldParser.getFieldDefine(field)); + + } + + + return tableColumnStep.getSQL(ParamType.INLINED); + + } + + public static String getCreateSTableIndexSql(String tbName, String partitionCol) { + //根据时间和设备纬度分区 + String sql = null; + if(StringUtils.isBlank(partitionCol)){ + // 只根据时间分区 + sql= String.format(" SELECT create_hypertable('%s', 'time') ;", tbName); + }else{ + sql= String.format(" SELECT * FROM create_hypertable('%s', 'time'," + + " partitioning_column => '%s'," + + " number_partitions => 4" + + ") ;", tbName, partitionCol ); + + } + + return sql; + + } + + public static String getCreateTableIndexSql(String tbName) { + + CreateIndexIncludeStep step = sqlBuilder.createIndexIfNotExists(tbName + "_index").on( + table(name(tbName)), + field(name("device_id")), + field(name("time")).desc()); + + return step.getSQL(ParamType.INLINED); + + } + + /** + * 取正确的表名 + * + * @param name 表象 + */ + public static String rightTbName(String name) { + return name.toLowerCase().replace("-", "_"); + } + + /** + * 获取表详情的sql + */ + public static String getDescTableSql(String tbName) { + + + String sql =String.format( " select a.attname as name," + + " t.typname as type, " + + "a.attlen as length," + + " case when a.attnotnull='t' then '1' else '0' end as nullable," + + " case when b.pk='t' then '1' else '0' end as isPk " + + "from pg_class e, pg_attribute a left join pg_type t on a.atttypid = t.oid " + + "left join (select pg_constraint.conname,pg_constraint.contype,pg_attribute.attname as pk " + + "from pg_constraint " + + " inner join pg_class on pg_constraint.conrelid = pg_class.oid" + + " inner join pg_attribute on pg_attribute.attrelid = pg_class.oid " + + " and pg_attribute.attnum = any(pg_constraint.conkey) where contype='p')" + + " b on a.attname=b.pk where e.relname = '%s'" + + " and a.attnum > 0 and a.attrelid = e.oid and t.typname is not null ;",tbName); + + return sql; + + + + } + + /** + * 获取添加字段sql + */ + public static String getAddSTableColumnSql(String tbName, List fields) { + + AlterTableStep alterTableStep = sqlBuilder.alterTable(tbName); + + AlterTableFinalStep addStep = null; + for (TsField o : fields) { + addStep = alterTableStep.add(FieldParser.getFieldDefine(o)); + } + return addStep.getSQL(); + } + + /** + * 获取修改字段sql + */ + public static String getModifySTableColumnSql(String tbName, List fields) { + AlterTableStep alterTableStep = sqlBuilder.alterTable(tbName); + AlterTableFinalStep step = null; + for (TsField o : fields) { + Field fieldDefine = FieldParser.getFieldDefine(o); + step = alterTableStep.alterColumn(o.getName()).set(fieldDefine.getDataType()); + } + return step.getSQL(); + } + + /** + * 获取删除字段sql + */ + public static String getDropSTableColumnSql(String tbName, List fields) { + + AlterTableStep alterTableStep = sqlBuilder.alterTable(tbName); + + + AlterTableFinalStep step = null; + for (TsField o : fields) { + step = alterTableStep.dropColumnIfExists(FieldParser.getFieldDefine(o)); + } + + return step.getSQL(); + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/TsField.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/TsField.java new file mode 100644 index 0000000..72734d8 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/TsField.java @@ -0,0 +1,24 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.dm; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.jooq.DataType; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TsField { + private String name; + private DataType type; + private int length; +} \ No newline at end of file diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsDeviceProperty.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsDeviceProperty.java new file mode 100644 index 0000000..ebc9f32 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsDeviceProperty.java @@ -0,0 +1,31 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TsDeviceProperty { + + private Date time; + + private String deviceId; + + private String name; + + private Object value; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsRuleLog.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsRuleLog.java new file mode 100644 index 0000000..59d5f2d --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsRuleLog.java @@ -0,0 +1,33 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TsRuleLog { + + private Date time; + + private String ruleId; + + private String state1; + + private String content; + + private Boolean success; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsTaskLog.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsTaskLog.java new file mode 100644 index 0000000..a254665 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsTaskLog.java @@ -0,0 +1,29 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TsTaskLog { + + private Long time; + + private String taskId; + + private String content; + + private Boolean success; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsThingModelMessage.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsThingModelMessage.java new file mode 100644 index 0000000..fe6b6c7 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsThingModelMessage.java @@ -0,0 +1,45 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TsThingModelMessage { + + private Date time; + + private String mid; + + private String deviceId; + + private String productKey; + + private String deviceName; + + private String uid; + + private String type; + + private String identifier; + + private int code; + + private String data; + + private Long reportTime; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsTimeData.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsTimeData.java new file mode 100644 index 0000000..c98b409 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsTimeData.java @@ -0,0 +1,36 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * 统计的时间数据 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TsTimeData { + + /** + * 时间 + */ + private Date time; + + /** + * 数据值 + */ + private Object data; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsVirtualDeviceLog.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsVirtualDeviceLog.java new file mode 100644 index 0000000..f1488b6 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsVirtualDeviceLog.java @@ -0,0 +1,33 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TsVirtualDeviceLog { + + private Date time; + + private String virtualDeviceId; + + private String virtualDeviceName; + + private int deviceTotal; + + private String result; + +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/DbStructureDataImpl.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/DbStructureDataImpl.java new file mode 100644 index 0000000..b11cea7 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/DbStructureDataImpl.java @@ -0,0 +1,207 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.service; + +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.model.product.ThingModel; +import cc.iotkit.temporal.IDbStructureData; +import cc.iotkit.temporal.ts.config.Constants; +import cc.iotkit.temporal.ts.dao.TsTemplate; +import cc.iotkit.temporal.ts.dm.DbField; +import cc.iotkit.temporal.ts.dm.FieldParser; +import cc.iotkit.temporal.ts.dm.TableManager; +import cc.iotkit.temporal.ts.dm.TsField; +import lombok.extern.slf4j.Slf4j; +import org.jooq.CreateTableColumnStep; +import org.jooq.DSLContext; +import org.jooq.SQLDialect; +import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import java.util.List; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class DbStructureDataImpl implements IDbStructureData { + + @Autowired + private TsTemplate tsTemplate; + + /** + * 根据物模型创建超级表 + */ + @Override + public void defineThingModel(ThingModel thingModel) { + //获取物模型中的属性定义 + List fields = FieldParser.parse(thingModel); + String tbName = Constants.getProductPropertySTableName(thingModel.getProductKey()); + String sql = TableManager.getCreateSTableSql(tbName, + fields); + if (sql == null) { + return; + } + System.out.println(sql); + tsTemplate.execute(sql); + + createHypertable(tbName, "device_id"); + + } + + private void createHypertable(String tbName, String partitionCol) { + String createSTableIndexSql = TableManager.getCreateSTableIndexSql(tbName, partitionCol); + try { + System.out.println(createSTableIndexSql); + + tsTemplate.execute(createSTableIndexSql); + } catch (Exception e) { + log.info("createHypertable error:{}", e.getMessage()); + } + + } + + /** + * 根据物模型更新超级表结构 + */ + @Override + public void updateThingModel(ThingModel thingModel) { + //获取旧字段信息 + String tbName = Constants.getProductPropertySTableName(thingModel.getProductKey()); + String sql = TableManager.getDescTableSql(tbName); + if (sql == null) { + return; + } + + tsTemplate.execute(sql); + + List fieldsInDb = tsTemplate.query(sql, new BeanPropertyRowMapper(DbField.class)); + + List newFields = FieldParser.parse(thingModel); + List oldFields = FieldParser.parse(fieldsInDb); + + //对比差异 + + //找出修改的字段 + List modifyFields = newFields.stream().filter((f) -> oldFields.stream() + .anyMatch(old -> + old.getName().equals(f.getName()) //字段名相同 + //字段类型或长度不同 + && (!old.getType().equals(f.getType()) || old.getLength() != f.getLength()) + )) + .collect(Collectors.toList()); + if (modifyFields.size() > 0) { + sql = TableManager.getModifySTableColumnSql(tbName, modifyFields); + log.info("modify column:{}", sql); + + tsTemplate.execute(sql); + + } + + //找出新增的字段 + List addFields = newFields.stream().filter((f) -> oldFields.stream() + .noneMatch(old -> old.getName().equals(f.getName()))) + .collect(Collectors.toList()); + if (addFields.size() > 0) { + sql = TableManager.getAddSTableColumnSql(tbName, addFields); + log.info("add column:{}", sql); + + tsTemplate.execute(sql); + } + + + //找出删除的字段 + List dropFields = oldFields.stream().filter((f) -> + !"time".equals(f.getName()) && + !"device_id".equals(f.getName()) && newFields.stream() + //字段名不是time且没有相同字段名的 + .noneMatch(n -> n.getName().equals(f.getName()))) + .collect(Collectors.toList()); + if (dropFields.size() > 0) { + + sql = TableManager.getDropSTableColumnSql(tbName, dropFields); + log.info("drop column:{}", sql); + tsTemplate.execute(sql); + + } + } + + /** + * 初始化其它数据结构 + */ + @Override + @PostConstruct + public void initDbStructure() { + //创建规则日志表 + DSLContext dslBuilder = DSL.using(SQLDialect.POSTGRES); + + CreateTableColumnStep ruleLogStep = dslBuilder.createTableIfNotExists("rule_log") + .column("time", SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false)) + .column("state1", SQLDataType.VARCHAR(50)) + .column("content", SQLDataType.VARCHAR(1024)) + .column("success", SQLDataType.BOOLEAN) + .column("rule_id", SQLDataType.VARCHAR(50).nullable(false)); + String sql = ruleLogStep.getSQL(); + System.out.println(sql); + tsTemplate.execute(sql); + // 按时间和rule_id分区 + createHypertable("rule_log", "rule_id"); + + + CreateTableColumnStep taskLogStep = dslBuilder.createTableIfNotExists("task_log") + .column("time", SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false)) + .column("content", SQLDataType.VARCHAR(1024)) + .column("success", SQLDataType.BOOLEAN) + .column("task_id", SQLDataType.VARCHAR(50).nullable(false)); + String taskLogsql = taskLogStep.getSQL(); + + System.out.println(taskLogsql); + tsTemplate.execute(taskLogsql); + // 按时间和task_id分区 + createHypertable("task_log", "task_id"); + + CreateTableColumnStep thingModelStep = dslBuilder.createTableIfNotExists("thing_model_message") + .column("time", SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false)) + .column("mid", SQLDataType.NVARCHAR(50)) + .column("product_key", SQLDataType.NVARCHAR(50)) + .column("device_name", SQLDataType.NVARCHAR(50)) + .column("uid", SQLDataType.NVARCHAR(50)) + .column("type", SQLDataType.NVARCHAR(20)) + .column("identifier", SQLDataType.NVARCHAR(50)) + .column("code", SQLDataType.INTEGER) + .column("data", SQLDataType.NVARCHAR(1024)) + .column("report_time", SQLDataType.NVARCHAR(1024)) + .column("device_id", SQLDataType.NVARCHAR(50)); + + String thingModelsql = thingModelStep.getSQL(); + + System.out.println(thingModelsql); + tsTemplate.execute(thingModelsql); + createHypertable("thing_model_message", "device_id"); + + //创建虚拟设备日志表 + CreateTableColumnStep virtualStep = dslBuilder.createTableIfNotExists("virtual_device_log") + .column("time", SQLDataType.TIMESTAMPWITHTIMEZONE.nullable(false)) + .column("virtual_device_name", SQLDataType.NVARCHAR(50)) + .column("device_total", SQLDataType.INTEGER) + .column("result", SQLDataType.NVARCHAR(1024)) + .column("virtual_device_id", SQLDataType.NVARCHAR(50)); + + String virtualsql = virtualStep.getSQL(); + System.out.println(virtualsql); + + tsTemplate.execute(virtualsql); + createHypertable("virtual_device_log", "virtual_device_id"); + + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/DevicePropertyDataImpl.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/DevicePropertyDataImpl.java new file mode 100644 index 0000000..84bb1b9 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/DevicePropertyDataImpl.java @@ -0,0 +1,105 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.service; + +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DeviceProperty; +import cc.iotkit.temporal.IDevicePropertyData; +import cc.iotkit.temporal.ts.config.Constants; +import cc.iotkit.temporal.ts.dao.TsTemplate; +import cc.iotkit.temporal.ts.model.TsDeviceProperty; +import lombok.extern.slf4j.Slf4j; +import org.jooq.Condition; +import org.jooq.Field; +import org.jooq.InsertValuesStepN; +import org.jooq.Record; +import org.jooq.conf.ParamType; +import org.jooq.impl.DSL; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +import static org.jooq.impl.DSL.field; + +@Slf4j +@Service +public class DevicePropertyDataImpl implements IDevicePropertyData { + + @Autowired + private TsTemplate tsTemplate; + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + + @Override + public List findDevicePropertyHistory(String deviceId, String name, long start, long end) { + DeviceInfo device = deviceInfoData.findByDeviceId(deviceId); + + String tbName = Constants.getProductPropertySTableName(device.getProductKey()); + Condition con = field("time").greaterOrEqual(new Date(start)).and(field("time").lessOrEqual(new Date(end))) + .and(DSL.field("device_id").eq(deviceId)); + String sql = DSL.select(DSL.field("time"), DSL.field("device_id"), DSL.field(name.toLowerCase()).as("value")) + .from(tbName).where(con) + .getSQL(ParamType.INLINED); + + + List list = tsTemplate.query(sql, new BeanPropertyRowMapper<>(TsDeviceProperty.class)); + + + return list.stream().map( + o->{ + DeviceProperty deviceProperty = new DeviceProperty(); + BeanUtils.copyProperties(o,deviceProperty); + deviceProperty.setTime(o.getTime().getTime()); + return deviceProperty; + } + ).collect(Collectors.toList()); + + } + + @Override + public void addProperties(String deviceId, Map properties, long time) { + DeviceInfo device = deviceInfoData.findByDeviceId(deviceId); + if (device == null) { + return; + } + //获取设备旧属性 + Map oldProperties = deviceInfoData.getProperties(deviceId); + //用新属性覆盖 + oldProperties.putAll(properties); + + List> fields = new ArrayList<>(); + List values = new ArrayList<>(); + + fields.add(DSL.field("time")); + fields.add(DSL.field("device_id")); + values.add(new Date(time)); + values.add(deviceId); + //组织sql + oldProperties.forEach((key, val) -> { + fields.add(DSL.field(key)); + values.add(val); + }); + String tbName = Constants.getProductPropertySTableName(device.getProductKey()); + + //组织sql + InsertValuesStepN step = DSL.insertInto(DSL.table(tbName), (Collection>) fields).values(values); + String sql = step.getSQL(ParamType.INLINED); + tsTemplate.batchUpdate(sql); + + } + +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/RuleLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/RuleLogDataImpl.java new file mode 100644 index 0000000..84969f5 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/RuleLogDataImpl.java @@ -0,0 +1,82 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.rule.RuleLog; +import cc.iotkit.temporal.IRuleLogData; +import cc.iotkit.temporal.ts.dao.TsTemplate; +import cc.iotkit.temporal.ts.dm.TableManager; +import cc.iotkit.temporal.ts.model.TsRuleLog; +import org.jooq.*; +import org.jooq.conf.ParamType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; + +//import cc.iotkit.temporal.ts.dm.TableManager; + +@Service +public class RuleLogDataImpl implements IRuleLogData { + + + @Autowired + private TsTemplate tsTemplate; + + @Override + public void deleteByRuleId(String ruleId) { + + tsTemplate.update("delete from rule_log where rule_id=? and time<=NOW()", ruleId); + } + + @Override + public Paging findByRuleId(String ruleId, int page, int size) { + + SelectForUpdateStep> sqlStep = TableManager.getSqlBuilder() + .select(field("time"), field("state1"), field("content"), field("success"), + field("rule_id")) + .from(table("rule_log")) + .where(field("rule_id").eq(ruleId)) + .orderBy(field("time").desc()) + .limit(size) + .offset((page - 1) * size); + List ruleLogs = tsTemplate.query(sqlStep.getSQL(ParamType.INLINED), new BeanPropertyRowMapper<>(TsRuleLog.class), ruleId); + + SelectConditionStep> where = TableManager.getSqlBuilder().selectCount().from(table("rule_log")) + .where(field("rule_id").eq(ruleId)); + Long count = tsTemplate.queryForObject(where.getSQL(ParamType.INLINED), Long.class); + + return new Paging<>(count, ruleLogs.stream().map(r -> + new RuleLog(r.getTime().toString(), ruleId, r.getState1(), + r.getContent(), r.getSuccess(), r.getTime().getTime())) + .collect(Collectors.toList())); + } + + @Override + public void add(RuleLog log) { + //使用 + + InsertValuesStep5 sqlStep = TableManager.getSqlBuilder().insertInto(table("rule_log"), + field("time"), + field("rule_id"), + field("state1"), + field("content"), field("success")).values(new Date(), + log.getRuleId(), log.getState(), log.getContent(), log.getSuccess()); + + tsTemplate.update(sqlStep.getSQL(ParamType.INLINED)); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/TaskLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/TaskLogDataImpl.java new file mode 100644 index 0000000..b81f7ea --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/TaskLogDataImpl.java @@ -0,0 +1,83 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.rule.TaskLog; +import cc.iotkit.temporal.ITaskLogData; +import cc.iotkit.temporal.ts.dao.TsTemplate; +import cc.iotkit.temporal.ts.dm.TableManager; +import cc.iotkit.temporal.ts.model.TsTaskLog; +import org.jooq.InsertValuesStep4; +import org.jooq.Record; +import org.jooq.Record4; +import org.jooq.SelectForUpdateStep; +import org.jooq.conf.ParamType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; + +@Service +public class TaskLogDataImpl implements ITaskLogData { + + @Autowired + private TsTemplate tsTemplate; + + @Override + public void deleteByTaskId(String taskId) { + tsTemplate.update("delete from task_log where task_id=? and time<=NOW()", taskId); + } + + @Override + public Paging findByTaskId(String taskId, int page, int size) { + SelectForUpdateStep> sqlStep = TableManager.getSqlBuilder() + .select(field("time"), field("content"), field("success"), field("task_id")) + .from(table("task_log")) + .where(field("task_id").eq(taskId)) + .orderBy(field("time").desc()) + .limit(size) + .offset((page - 1) * size); + + // Get the SQL string from the query + String sql = sqlStep.getSQL(ParamType.INLINED); + List taskLogs = tsTemplate.query(sql, new BeanPropertyRowMapper<>(TsTaskLog.class)); + + String whereSql = TableManager.getSqlBuilder().selectCount().from(table("task_log")) + .where(field("task_id").eq(taskId)).getSQL(ParamType.INLINED); + Long count = tsTemplate.queryForObject(whereSql, new BeanPropertyRowMapper<>(Long.class)); + + return new Paging<>(count, taskLogs.stream().map(r -> + new TaskLog(r.getTime().toString(), taskId, + r.getContent(), r.getSuccess(), r.getTime())) + .collect(Collectors.toList())); + } + + @Override + public void add(TaskLog log) { + + InsertValuesStep4 sqlStep + = TableManager.getSqlBuilder().insertInto(table("tag_log"), + field("time"), + field("task_id"), + field("content"), field("success")).values( + new Date(), + log.getTaskId(), + log.getContent(), log.getSuccess()); + + tsTemplate.update(sqlStep.getSQL(ParamType.INLINED)); + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/ThingModelMessageDataImpl.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/ThingModelMessageDataImpl.java new file mode 100644 index 0000000..45814f1 --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/ThingModelMessageDataImpl.java @@ -0,0 +1,131 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.model.stats.TimeData; +import cc.iotkit.temporal.IThingModelMessageData; +import cc.iotkit.temporal.ts.dao.TsTemplate; +import cc.iotkit.temporal.ts.dm.TableManager; +import cc.iotkit.temporal.ts.model.TsThingModelMessage; +import cc.iotkit.temporal.ts.model.TsTimeData; +import org.apache.commons.lang3.StringUtils; +import org.jooq.*; +import org.jooq.conf.ParamType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; + +@Service +public class ThingModelMessageDataImpl implements IThingModelMessageData { + + @Autowired + private TsTemplate tsTemplate; + + public Paging findByTypeAndIdentifier(String deviceId, String type, + String identifier, + int page, int size) { + + + Table table = table("thing_model_message"); + Condition whereConditions = field("device_id").eq(deviceId); + SelectJoinStep> step = TableManager.getSqlBuilder().select(field("time"), field("mid"), + field("product_key"), field("device_name"), field("type"), + field("identifier"), field("code"), field("data"), + field("report_time")).from(table); + + + if (StringUtils.isNotBlank(type)) { + whereConditions.and(field("type").eq(type)); + } + if (StringUtils.isNotBlank(identifier)) { + whereConditions.and(field("identifier").eq(identifier)); + } + + String sql = step.where(whereConditions).orderBy(field("time").desc()).limit(size).offset((page - 1) * size).getSQL(ParamType.INLINED); + + List ruleLogs = tsTemplate.query(sql, + new BeanPropertyRowMapper<>(TsThingModelMessage.class) + ); + + String countSql = TableManager.getSqlBuilder().selectCount().from(table).where(whereConditions).getSQL(ParamType.INLINED); + Long count = tsTemplate.queryForObject(countSql, Long.class); + + return new Paging<>(count, ruleLogs.stream().map(r -> + new ThingModelMessage(r.getTime().toString(), r.getMid(), + deviceId, r.getProductKey(), r.getDeviceName(), + r.getUid(), r.getType(), r.getIdentifier(), r.getCode(), + r.getData(), + r.getTime().getTime(), r.getReportTime())) + .collect(Collectors.toList())); + } + + @Override + public List getDeviceMessageStatsWithUid(String uid, long start, long end) { + + Table table = table("thing_model_message"); + + Condition con = field("time").greaterOrEqual(new Date(start)).and(field("time").lessOrEqual(new Date(end))); + if (StringUtils.isNotBlank(uid)) { + con.and(field("uid").eq(uid)); + } + + String sql = TableManager.getSqlBuilder().select(field("date_trunc('hour', \"time\")").as("time"), field("count(*)").as("data")) + .from(table).where(con).groupBy(field("date_trunc('hour', \"time\")")).orderBy(field("time").asc()).getSQL(ParamType.INLINED); + + + List query = tsTemplate.query(sql, new BeanPropertyRowMapper<>(TsTimeData.class)); + return query.stream().map(o -> { + TimeData timeData = new TimeData(); + timeData.setData(o.getData()); + timeData.setTime(o.getTime().getTime()); + return timeData; + + }).collect(Collectors.toList()); + } + + @Override + public void add(ThingModelMessage msg) { + Table table = table("thing_model_message"); + + String sql = TableManager.getSqlBuilder().insertInto(table, + field("time"), + field("device_id"), + field("mid"), + field("product_key"), + field("device_name"), + field("uid"), + field("type"), + field("identifier"), + field("code"), + field("data"), field("report_time")) + .values(new Date(msg.getOccurred()), msg.getDeviceId(), msg.getMid(), + msg.getProductKey(), msg.getDeviceName(), + msg.getUid(), msg.getType(), + msg.getIdentifier(), msg.getCode(), + msg.getData() == null ? "{}" : JsonUtils.toJsonString(msg.getData()), + msg.getTime()).getSQL(ParamType.INLINED); + tsTemplate.update(sql); + } + + @Override + public long count() { + List counts = tsTemplate.queryForList("select count(*) from thing_model_message", Long.class); + return counts.size() > 0 ? counts.get(0) : 0; + } +} diff --git a/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/VirtualDeviceLogDataImpl.java b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/VirtualDeviceLogDataImpl.java new file mode 100644 index 0000000..e6caf3e --- /dev/null +++ b/iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/VirtualDeviceLogDataImpl.java @@ -0,0 +1,77 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.temporal.ts.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.device.VirtualDeviceLog; +import cc.iotkit.temporal.IVirtualDeviceLogData; +import cc.iotkit.temporal.ts.dao.TsTemplate; +import cc.iotkit.temporal.ts.dm.TableManager; +import cc.iotkit.temporal.ts.model.TsVirtualDeviceLog; +import org.jooq.Condition; +import org.jooq.DSLContext; +import org.jooq.Record; +import org.jooq.Table; +import org.jooq.conf.ParamType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +import static org.jooq.impl.DSL.field; +import static org.jooq.impl.DSL.table; + +@Service +public class VirtualDeviceLogDataImpl implements IVirtualDeviceLogData { + + @Autowired + private TsTemplate tsTemplate; + + @Override + public Paging findByVirtualDeviceId(String virtualDeviceId, int page, int size) { + + Table table = table("virtual_device_log"); + + Condition whereConditions = field("virtual_device_id").eq(virtualDeviceId.toLowerCase()); + DSLContext sqlBuilder = TableManager.getSqlBuilder(); + String sql = sqlBuilder.select(field("time"), field("virtual_device_id"), + field("virtual_device_name"), field("device_total"), field("result")).from(table).where(whereConditions) + .orderBy(field("time").desc()).limit(size).offset((page - 1) * size).getSQL(ParamType.INLINED); + + List logs = tsTemplate.query(sql, new BeanPropertyRowMapper<>(TsVirtualDeviceLog.class)); + + String countSql = sqlBuilder.selectCount().from(table).where(whereConditions).getSQL(ParamType.INLINED); + + Long count = tsTemplate.queryForObject(countSql, Long.class); + + return new Paging<>(count, logs.stream().map(r -> + new VirtualDeviceLog(r.getTime().toString(), virtualDeviceId, + r.getVirtualDeviceName(), + r.getDeviceTotal(), r.getResult(), + r.getTime().getTime())) + .collect(Collectors.toList())); + } + + @Override + public void add(VirtualDeviceLog log) { + Table table = table("virtual_device_log"); + + String sql = TableManager.getSqlBuilder().insertInto(table, field("time"), field("virtual_device_id"), + field("virtual_device_name"), + field("device_total"), field("result")) + .values(new Date(), log.getVirtualDeviceId(), log.getVirtualDeviceName(), + log.getDeviceTotal(), log.getResult()).getSQL(ParamType.INLINED); + + tsTemplate.update(sql); + } +} diff --git a/iot-dao/pom.xml b/iot-dao/pom.xml new file mode 100644 index 0000000..e0105c2 --- /dev/null +++ b/iot-dao/pom.xml @@ -0,0 +1,31 @@ + + + + iotkit-parent + cc.iotkit + 0.5.3 + + 4.0.0 + pom + + + 与数据存取相关内容的模块 + 包含:数据接口定义、数据实体类定义、关系型数据库接口实现、NoSQL数据库接口实现、数据缓存服务 + + + + iot-data-model + iot-data-service + iot-data-serviceImpl-cache + iot-data-serviceImpl-rdb + iot-temporal-service + iot-temporal-serviceImpl-td + iot-temporal-serviceImpl-es + iot-temporal-serviceImpl-iotdb + + + iot-dao + + \ No newline at end of file diff --git a/iot-module/iot-generator/pom.xml b/iot-module/iot-generator/pom.xml new file mode 100644 index 0000000..8af739c --- /dev/null +++ b/iot-module/iot-generator/pom.xml @@ -0,0 +1,119 @@ + + + + iot-module + cc.iotkit + 0.5.3 + + + 4.0.0 + + iot-generator + + + + generator 代码生成 + + + + 3.5.1 + 0.2.0 + 3.5.3.1 + + + + + + + + cc.iotkit + iot-common-core + + + + cc.iotkit + iot-common-doc + + + + + + cc.iotkit + iot-common-log + + + + + + + com.github.yitter + yitter-idgenerator + + + + + org.apache.velocity + velocity-engine-core + + + + + com.baomidou + dynamic-datasource-spring-boot-starter + ${dynamic-ds.version} + + + + com.baomidou + mybatis-plus-boot-starter + ${mybatis-plus.version} + + + + com.baomidou + mybatis-plus-annotation + ${mybatis-plus.version} + + + cc.iotkit + iot-common-web + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + utf8 + + + org.projectlombok + lombok + ${lombok.version} + + + io.github.linpeilie + mapstruct-plus-processor + ${mapstruct-plus.version} + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + + + + + + + + diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/config/GenConfig.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/config/GenConfig.java new file mode 100644 index 0000000..e6c0103 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/config/GenConfig.java @@ -0,0 +1,73 @@ +package cc.iotkit.generator.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Component; + +/** + * 读取代码生成相关配置 + * + * @author ruoyi + */ +@Component +@ConfigurationProperties(prefix = "gen") +@PropertySource(value = {"classpath:generator.yml"}, encoding = "UTF-8") +public class GenConfig { + + /** + * 作者 + */ + public static String author; + + /** + * 生成包路径 + */ + public static String packageName; + + /** + * 自动去除表前缀,默认是false + */ + public static boolean autoRemovePre; + + /** + * 表前缀(类名不会包含表前缀) + */ + public static String tablePrefix; + + public static String getAuthor() { + return author; + } + + @Value("${author}") + public void setAuthor(String author) { + GenConfig.author = author; + } + + public static String getPackageName() { + return packageName; + } + + @Value("${packageName}") + public void setPackageName(String packageName) { + GenConfig.packageName = packageName; + } + + public static boolean getAutoRemovePre() { + return autoRemovePre; + } + + @Value("${autoRemovePre}") + public void setAutoRemovePre(boolean autoRemovePre) { + GenConfig.autoRemovePre = autoRemovePre; + } + + public static String getTablePrefix() { + return tablePrefix; + } + + @Value("${tablePrefix}") + public void setTablePrefix(String tablePrefix) { + GenConfig.tablePrefix = tablePrefix; + } +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/config/MybatisPlusConfig.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/config/MybatisPlusConfig.java new file mode 100644 index 0000000..67e0bbe --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/config/MybatisPlusConfig.java @@ -0,0 +1,102 @@ +package cc.iotkit.generator.config; + +import cc.iotkit.generator.core.DbIdGenerator; +import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +/** + * mybatis-plus配置类(下方注释有插件介绍) + * + * @author Lion Li + */ +@EnableTransactionManagement(proxyTargetClass = true) +@AutoConfiguration +//@MapperScan("${mybatis-plus.mapperPackage}") +@MapperScan("cc.iotkit.**.mapper") +//@PropertySource(value = "classpath:common-mybatis.yml", factory = YmlPropertySourceFactory.class) +public class MybatisPlusConfig { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + // 数据权限处理 +// interceptor.addInnerInterceptor(dataPermissionInterceptor()); + // 分页插件 + interceptor.addInnerInterceptor(paginationInnerInterceptor()); + // 乐观锁插件 + interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor()); + return interceptor; + } + + /** + * 数据权限拦截器 + */ +// public PlusDataPermissionInterceptor dataPermissionInterceptor() { +// return new PlusDataPermissionInterceptor(); +// } + + /** + * 分页插件,自动识别数据库类型 + */ + public PaginationInnerInterceptor paginationInnerInterceptor() { + PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); + // 设置最大单页限制数量,默认 500 条,-1 不受限制 + paginationInnerInterceptor.setMaxLimit(-1L); + // 分页合理化 + paginationInnerInterceptor.setOverflow(true); + return paginationInnerInterceptor; + } + + /** + * 乐观锁插件 + */ + public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() { + return new OptimisticLockerInnerInterceptor(); + } + + /** + * 元对象字段填充控制器 + */ +// @Bean +// public MetaObjectHandler metaObjectHandler() { +// return new InjectionMetaObjectHandler(); +// } + + /** + * 使用网卡信息绑定雪花生成器 + * 防止集群雪花ID重复 + */ + @Bean + public IdentifierGenerator idGenerator() { +// String hostAddress = NetUtil.getLocalhost().getHostAddress(); + // TODO: 采用配置文件里的 + return new DbIdGenerator((short) 1); + } + + /** + * PaginationInnerInterceptor 分页插件,自动识别数据库类型 + * https://baomidou.com/pages/97710a/ + * OptimisticLockerInnerInterceptor 乐观锁插件 + * https://baomidou.com/pages/0d93c0/ + * MetaObjectHandler 元对象字段填充控制器 + * https://baomidou.com/pages/4c6bcf/ + * ISqlInjector sql注入器 + * https://baomidou.com/pages/42ea4a/ + * BlockAttackInnerInterceptor 如果是对全表的删除或更新操作,就会终止该操作 + * https://baomidou.com/pages/f9a237/ + * IllegalSQLInnerInterceptor sql性能规范插件(垃圾SQL拦截) + * IdentifierGenerator 自定义主键策略 + * https://baomidou.com/pages/568eb2/ + * TenantLineInnerInterceptor 多租户插件 + * https://baomidou.com/pages/aef2f2/ + * DynamicTableNameInnerInterceptor 动态表名插件 + * https://baomidou.com/pages/2a45ff/ + */ + +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/constant/GenConstants.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/constant/GenConstants.java new file mode 100644 index 0000000..7457336 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/constant/GenConstants.java @@ -0,0 +1,186 @@ +package cc.iotkit.generator.constant; + +/** + * 代码生成通用常量 + * + * @author ruoyi + */ +public interface GenConstants { + /** + * 单表(增删改查) + */ + String TPL_CRUD = "crud"; + + /** + * 树表(增删改查) + */ + String TPL_TREE = "tree"; + + /** + * 树编码字段 + */ + String TREE_CODE = "treeCode"; + + /** + * 树父编码字段 + */ + String TREE_PARENT_CODE = "treeParentCode"; + + /** + * 树名称字段 + */ + String TREE_NAME = "treeName"; + + /** + * 上级菜单ID字段 + */ + String PARENT_MENU_ID = "parentMenuId"; + + /** + * 上级菜单名称字段 + */ + String PARENT_MENU_NAME = "parentMenuName"; + + /** + * 数据库字符串类型 + */ + String[] COLUMNTYPE_STR = {"char", "varchar", "enum", "set", "nchar", "nvarchar", "varchar2", "nvarchar2"}; + + /** + * 数据库文本类型 + */ + String[] COLUMNTYPE_TEXT = {"tinytext", "text", "mediumtext", "longtext", "binary", "varbinary", "blob", + "ntext", "image", "bytea"}; + + /** + * 数据库时间类型 + */ + String[] COLUMNTYPE_TIME = {"datetime", "time", "date", "timestamp", "year", "interval", + "smalldatetime", "datetime2", "datetimeoffset"}; + + /** + * 数据库数字类型 + */ + String[] COLUMNTYPE_NUMBER = {"tinyint", "smallint", "mediumint", "int", "number", "integer", + "bit", "bigint", "float", "double", "decimal", "numeric", "real", "double precision", + "smallserial", "serial", "bigserial", "money", "smallmoney"}; + + /** + * BO对象 不需要添加字段 + */ + String[] COLUMNNAME_NOT_ADD = {"create_dept", "create_by", "create_time", "del_flag", "update_by", + "update_time", "version", "tenant_id"}; + + /** + * BO对象 不需要编辑字段 + */ + String[] COLUMNNAME_NOT_EDIT = {"create_dept", "create_by", "create_time", "del_flag", "update_by", + "update_time", "version", "tenant_id"}; + + /** + * VO对象 不需要返回字段 + */ + String[] COLUMNNAME_NOT_LIST = {"create_dept", "create_by", "create_time", "del_flag", "update_by", + "update_time", "version", "tenant_id"}; + + /** + * BO对象 不需要查询字段 + */ + String[] COLUMNNAME_NOT_QUERY = {"id", "create_dept", "create_by", "create_time", "del_flag", "update_by", + "update_time", "remark", "version", "tenant_id"}; + + /** + * Entity基类字段 + */ + String[] BASE_ENTITY = {"createDept", "createBy", "createTime", "updateBy", "updateTime", "tenantId"}; + + /** + * 文本框 + */ + String HTML_INPUT = "input"; + + /** + * 文本域 + */ + String HTML_TEXTAREA = "textarea"; + + /** + * 下拉框 + */ + String HTML_SELECT = "select"; + + /** + * 单选框 + */ + String HTML_RADIO = "radio"; + + /** + * 复选框 + */ + String HTML_CHECKBOX = "checkbox"; + + /** + * 日期控件 + */ + String HTML_DATETIME = "datetime"; + + /** + * 图片上传控件 + */ + String HTML_IMAGE_UPLOAD = "imageUpload"; + + /** + * 文件上传控件 + */ + String HTML_FILE_UPLOAD = "fileUpload"; + + /** + * 富文本控件 + */ + String HTML_EDITOR = "editor"; + + /** + * 字符串类型 + */ + String TYPE_STRING = "String"; + + /** + * 整型 + */ + String TYPE_INTEGER = "Integer"; + + /** + * 长整型 + */ + String TYPE_LONG = "Long"; + + /** + * 浮点型 + */ + String TYPE_DOUBLE = "Double"; + + /** + * 高精度计算类型 + */ + String TYPE_BIGDECIMAL = "BigDecimal"; + + /** + * 时间类型 + */ + String TYPE_DATE = "Date"; + + /** + * 模糊查询 + */ + String QUERY_LIKE = "LIKE"; + + /** + * 相等查询 + */ + String QUERY_EQ = "EQ"; + + /** + * 需要 + */ + String REQUIRE = "1"; +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/controller/GenController.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/controller/GenController.java new file mode 100644 index 0000000..314407c --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/controller/GenController.java @@ -0,0 +1,214 @@ +package cc.iotkit.generator.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.generator.domain.GenTable; +import cc.iotkit.generator.domain.GenTableColumn; +import cc.iotkit.generator.dto.bo.ImportTableBo; +import cc.iotkit.generator.service.IGenTableService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.io.IoUtil; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 代码生成 操作处理 + * + * @author Lion Li + */ +@Validated +@RestController +@RequiredArgsConstructor + +@RequestMapping("/tool/gen") +public class GenController extends BaseController { + + private final IGenTableService genTableService; + + /** + * 查询代码生成列表 + */ + // @SaCheckPermission("tool:gen:list") + @ApiOperation(value = "查询代码生成列表", notes = "查询代码生成列表,根据查询条件分页") + @PostMapping("/list") + public Paging genList(@RequestBody @Validated PageRequest query) { + return genTableService.selectPageGenTableList(query ); + } + + /** + * 修改代码生成业务 + * + */ +// @SaCheckPermission("tool:gen:query") + @ApiOperation(value = "修改代码生成业务", notes = "修改代码生成业务详情") + @PostMapping(value = "/getDetail") + public Map getInfo(@Validated @RequestBody Request bo) { + Long tableId = bo.getData(); + GenTable table = genTableService.selectGenTableById(tableId); + List tables = genTableService.selectGenTableAll(); + List list = genTableService.selectGenTableColumnListByTableId(tableId); + Map map = new HashMap<>(); + map.put("info", table); + map.put("rows", list); + map.put("tables", tables); + return map; + } + + /** + * 查询数据库列表 + */ +// @SaCheckPermission("tool:gen:list") + @ApiOperation(value = "查询数据库列表", notes = "查询数据库列表") + @PostMapping("/db/list") + public Paging dataList(@RequestBody @Validated PageRequest pageQuery) { + return genTableService.selectPageDbTableList( pageQuery); + } + + /** + * 查询数据表字段列表 + * + * @param tableId 表ID + */ +// @SaCheckPermission("tool:gen:list") + @ApiOperation(value = "查询数据表字段列表", notes = "查询数据表字段列表") + @PostMapping(value = "/column/{tableId}") + public Paging columnList(Long tableId) { + + List list = genTableService.selectGenTableColumnListByTableId(tableId); + + return new Paging<>(); + } + + /** + * 导入表结构(保存) + * + */ +// @SaCheckPermission("tool:gen:import") + @Log(title = "代码生成", businessType = BusinessType.IMPORT) + @PostMapping("/importTable") + @ApiOperation(value = "导入表结构(保存)", notes = "导入表结构(保存)") + public void importTableSave(@Validated @RequestBody Request bo) { + List tables = bo.getData().getTables(); + + // 查询表信息 + List tableList = genTableService.selectDbTableListByNames(tables); + genTableService.importGenTable(tableList); + } + + /** + * 修改保存代码生成业务 + */ +// @SaCheckPermission("tool:gen:edit") + @ApiOperation(value = "修改保存代码生成业务", notes = "修改保存代码生成业务") + @Log(title = "代码生成", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + public void editSave(@Validated @RequestBody Request bo) { + GenTable genTable = bo.getData(); + genTableService.validateEdit(genTable); + genTableService.updateGenTable(genTable); + } + + /** + * 删除代码生成 + * + + */ +// @SaCheckPermission("tool:gen:remove") + @Log(title = "代码生成", businessType = BusinessType.DELETE) + @PostMapping("/delete") + @ApiOperation(value = "删除代码生成", notes = "删除代码生成") + public void remove(@Validated @RequestBody Request> bo) { + genTableService.deleteGenTableByIds(bo.getData()); + } + + /** + * 预览代码 + * + */ +// @SaCheckPermission("tool:gen:preview") + @ApiOperation(value = "预览代码", notes = "预览代码") + @PostMapping("/preview") + public Map preview(@Validated @RequestBody Request bo) throws IOException { + Map dataMap = genTableService.previewCode(bo.getData()); + return dataMap; + } + + /** + * 生成代码(下载方式) + * + * @param tableName 表名 + */ +// @SaCheckPermission("tool:gen:code") + @Log(title = "代码生成", businessType = BusinessType.GENCODE) + @PostMapping("/download/{tableName}") + public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException { + byte[] data = genTableService.downloadCode(tableName); + genCode(response, data); + } + + /** + * 生成代码(自定义路径) + * + * @param tableName 表名 + */ +// @SaCheckPermission("tool:gen:code") + @Log(title = "代码生成", businessType = BusinessType.GENCODE) + @ApiOperation(value = "生成代码(自定义路径)", notes = "生成代码(自定义路径)") + @PostMapping("/genCode/{tableName}") + public void genCode(@PathVariable("tableName") String tableName) { + genTableService.generatorCode(tableName); + } + + /** + * 同步数据库 + * + */ +// @SaCheckPermission("tool:gen:edit") + @Log(title = "代码生成", businessType = BusinessType.UPDATE) + @ApiOperation(value = "同步数据库", notes = "同步数据库") + @PostMapping("/synchDb") + public void synchDb(@Validated @RequestBody Request bo) { + genTableService.synchDb(bo.getData()); + } + + /** + * 批量生成代码 + * + * @param tables 表名串 + */ +// @SaCheckPermission("tool:gen:code") + @Log(title = "代码生成", businessType = BusinessType.GENCODE) + @ApiOperation(value = "批量生成代码", notes = "批量生成代码") + @PostMapping("/batchGenCode") + public void batchGenCode(HttpServletResponse response, String tables) throws IOException { + String[] tableNames = Convert.toStrArray(tables); + byte[] data = genTableService.downloadCode(tableNames); + genCode(response, data); + } + + /** + * 生成zip文件 + */ + private void genCode(HttpServletResponse response, byte[] data) throws IOException { + response.reset(); + response.addHeader("Access-Control-Allow-Origin", "*"); + response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); + response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); + response.addHeader("Content-Length", "" + data.length); + response.setContentType("application/octet-stream; charset=UTF-8"); + IoUtil.write(response.getOutputStream(), false, data); + } +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/BaseEntity.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/BaseEntity.java new file mode 100644 index 0000000..8e2109c --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/BaseEntity.java @@ -0,0 +1,70 @@ +package cc.iotkit.generator.core; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * Entity基类 + * + * @author Lion Li + */ + +@Data +public class BaseEntity implements Serializable { + + + private static final long serialVersionUID = 1L; + + /** + * 搜索值 + */ + @JsonIgnore + @TableField(exist = false) + private String searchValue; + + /** + * 创建部门 + */ + @TableField(fill = FieldFill.INSERT) + private Long createDept; + + /** + * 创建者 + */ + @TableField(fill = FieldFill.INSERT) + private Long createBy; + + /** + * 创建时间 + */ + @TableField(fill = FieldFill.INSERT) + private Date createTime; + + /** + * 更新者 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Long updateBy; + + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateTime; + + /** + * 请求参数 + */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @TableField(exist = false) + private Map params = new HashMap<>(); + +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/BaseMapperPlus.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/BaseMapperPlus.java new file mode 100644 index 0000000..378813e --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/BaseMapperPlus.java @@ -0,0 +1,198 @@ +package cc.iotkit.generator.core; + +import cc.iotkit.common.utils.MapstructUtils; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.ReflectionKit; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.toolkit.Db; +import org.apache.ibatis.logging.Log; +import org.apache.ibatis.logging.LogFactory; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * 自定义 Mapper 接口, 实现 自定义扩展 + * + * @param table 泛型 + * @param vo 泛型 + * @author Lion Li + * @since 2021-05-13 + */ +@SuppressWarnings("unchecked") +public interface BaseMapperPlus extends BaseMapper { + + Log log = LogFactory.getLog(BaseMapperPlus.class); + + default Class currentVoClass() { + return (Class) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseMapperPlus.class, 1); + } + + default Class currentModelClass() { + return (Class) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseMapperPlus.class, 0); + } + + default List selectList() { + return this.selectList(new QueryWrapper<>()); + } + + /** + * 批量插入 + */ + default boolean insertBatch(Collection entityList) { + return Db.saveBatch(entityList); + } + + /** + * 批量更新 + */ + default boolean updateBatchById(Collection entityList) { + return Db.updateBatchById(entityList); + } + + /** + * 批量插入或更新 + */ + default boolean insertOrUpdateBatch(Collection entityList) { + return Db.saveOrUpdateBatch(entityList); + } + + /** + * 批量插入(包含限制条数) + */ + default boolean insertBatch(Collection entityList, int batchSize) { + return Db.saveBatch(entityList, batchSize); + } + + /** + * 批量更新(包含限制条数) + */ + default boolean updateBatchById(Collection entityList, int batchSize) { + return Db.updateBatchById(entityList, batchSize); + } + + /** + * 批量插入或更新(包含限制条数) + */ + default boolean insertOrUpdateBatch(Collection entityList, int batchSize) { + return Db.saveOrUpdateBatch(entityList, batchSize); + } + + /** + * 插入或更新(包含限制条数) + */ + default boolean insertOrUpdate(T entity) { + return Db.saveOrUpdate(entity); + } + + default V selectVoById(Serializable id) { + return selectVoById(id, this.currentVoClass()); + } + + /** + * 根据 ID 查询 + */ + default C selectVoById(Serializable id, Class voClass) { + T obj = this.selectById(id); + if (ObjectUtil.isNull(obj)) { + return null; + } + return MapstructUtils.convert(obj, voClass); + } + + default List selectVoBatchIds(Collection idList) { + return selectVoBatchIds(idList, this.currentVoClass()); + } + + /** + * 查询(根据ID 批量查询) + */ + default List selectVoBatchIds(Collection idList, Class voClass) { + List list = this.selectBatchIds(idList); + if (CollUtil.isEmpty(list)) { + return CollUtil.newArrayList(); + } + return MapstructUtils.convert(list, voClass); + } + + default List selectVoByMap(Map map) { + return selectVoByMap(map, this.currentVoClass()); + } + + /** + * 查询(根据 columnMap 条件) + */ + default List selectVoByMap(Map map, Class voClass) { + List list = this.selectByMap(map); + if (CollUtil.isEmpty(list)) { + return CollUtil.newArrayList(); + } + return MapstructUtils.convert(list, voClass); + } + + default V selectVoOne(Wrapper wrapper) { + return selectVoOne(wrapper, this.currentVoClass()); + } + + /** + * 根据 entity 条件,查询一条记录 + */ + default C selectVoOne(Wrapper wrapper, Class voClass) { + T obj = this.selectOne(wrapper); + if (ObjectUtil.isNull(obj)) { + return null; + } + return MapstructUtils.convert(obj, voClass); + } + + default List selectVoList() { + return selectVoList(new QueryWrapper<>(), this.currentVoClass()); + } + + default List selectVoList(Wrapper wrapper) { + return selectVoList(wrapper, this.currentVoClass()); + } + + /** + * 根据 entity 条件,查询全部记录 + */ + default List selectVoList(Wrapper wrapper, Class voClass) { + List list = this.selectList(wrapper); + if (CollUtil.isEmpty(list)) { + return CollUtil.newArrayList(); + } + return MapstructUtils.convert(list, voClass); + } + + default

> P selectVoPage(IPage page, Wrapper wrapper) { + return selectVoPage(page, wrapper, this.currentVoClass()); + } + + /** + * 分页查询VO + */ + default > P selectVoPage(IPage page, Wrapper wrapper, Class voClass) { + IPage pageData = this.selectPage(page, wrapper); + IPage voPage = new Page<>(pageData.getCurrent(), pageData.getSize(), pageData.getTotal()); + if (CollUtil.isEmpty(pageData.getRecords())) { + return (P) voPage; + } + voPage.setRecords(MapstructUtils.convert(pageData.getRecords(), voClass)); + return (P) voPage; + } + + default List selectObjs(Wrapper wrapper, Function mapper) { + return this.selectObjs(wrapper).stream().filter(Objects::nonNull).map(mapper).collect(Collectors.toList()); + } + +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseHelper.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseHelper.java new file mode 100644 index 0000000..2224339 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseHelper.java @@ -0,0 +1,76 @@ +package cc.iotkit.generator.core; + +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.SpringUtils; +import cn.hutool.core.convert.Convert; +import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; + +/** + * 数据库助手 + * + * @author Lion Li + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class DataBaseHelper { + + private static final DynamicRoutingDataSource DS = SpringUtils.getBean(DynamicRoutingDataSource.class); + + /** + * 获取当前数据库类型 + */ + public static DataBaseType getDataBaseType() { + DataSource dataSource = DS.determineDataSource(); + try (Connection conn = dataSource.getConnection()) { + DatabaseMetaData metaData = conn.getMetaData(); + String databaseProductName = metaData.getDatabaseProductName(); + return DataBaseType.find(databaseProductName); + } catch (SQLException e) { + throw new BizException(e.getMessage()); + } + } + + public static boolean isMySql() { + return DataBaseType.MY_SQL == getDataBaseType(); + } + + public static boolean isH2() { + return DataBaseType.H2 == getDataBaseType(); + } + + + public static boolean isOracle() { + return DataBaseType.ORACLE == getDataBaseType(); + } + + public static boolean isPostgerSql() { + return DataBaseType.POSTGRE_SQL == getDataBaseType(); + } + + public static boolean isSqlServer() { + return DataBaseType.SQL_SERVER == getDataBaseType(); + } + + public static String findInSet(Object var1, String var2) { + DataBaseType dataBasyType = getDataBaseType(); + String var = Convert.toStr(var1); + if (dataBasyType == DataBaseType.SQL_SERVER) { + // charindex(',100,' , ',0,100,101,') <> 0 + return String.format("charindex(',%s,' , ','+%s+',') <> 0",var, var2 ); + } else if (dataBasyType == DataBaseType.POSTGRE_SQL) { + // (select position(',100,' in ',0,100,101,')) <> 0 + return String.format("(select position(',%s,' in ','||%s||',')) <> 0", var, var2); + } else if (dataBasyType == DataBaseType.ORACLE) { + // instr(',0,100,101,' , ',100,') <> 0 + return String.format("instr(','||%s||',' , ',%s,') <> 0",var2, var ); + } + // find_in_set(100 , '0,100,101') + return String.format("find_in_set('%s' , %s) <> 0", var, var2); + } +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseType.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseType.java new file mode 100644 index 0000000..0616864 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseType.java @@ -0,0 +1,51 @@ +package cc.iotkit.generator.core; + +import cc.iotkit.common.utils.StringUtils; +import lombok.AllArgsConstructor; +import lombok.Getter; + + +/** + * 数据库类型 + * + * @author Lion Li + */ +@Getter +@AllArgsConstructor +public enum DataBaseType { + + /** + * MySQL + */ + MY_SQL("MySQL"), + + H2("H2"), + /** + * Oracle + */ + ORACLE("Oracle"), + + /** + * PostgreSQL + */ + POSTGRE_SQL("PostgreSQL"), + + /** + * SQL Server + */ + SQL_SERVER("Microsoft SQL Server"); + + private final String type; + + public static DataBaseType find(String databaseProductName) { + if (StringUtils.isBlank(databaseProductName)) { + return null; + } + for (DataBaseType type : values()) { + if (type.getType().equals(databaseProductName)) { + return type; + } + } + return null; + } +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DbIdGenerator.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DbIdGenerator.java new file mode 100644 index 0000000..f1c748e --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DbIdGenerator.java @@ -0,0 +1,30 @@ +package cc.iotkit.generator.core; + +import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator; +import com.github.yitter.contract.IdGeneratorOptions; +import com.github.yitter.idgen.YitIdHelper; + +/** + * @author: Jay + * @description: + * @date:created in 2023/5/18 10:20 + * @modificed by: + */ +public class DbIdGenerator implements IdentifierGenerator { + + + public DbIdGenerator(Short workerId) { +// 使用网卡信息绑定雪花生成器 +// 防止集群雪花ID重复 + + IdGeneratorOptions options = new IdGeneratorOptions(workerId); + YitIdHelper.setIdGenerator(options); + } + + + + @Override + public Number nextId(Object entity) { + return YitIdHelper.nextId(); + } +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/PageBuilder.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/PageBuilder.java new file mode 100644 index 0000000..0d5d751 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/PageBuilder.java @@ -0,0 +1,25 @@ +package cc.iotkit.generator.core; + +import cc.iotkit.common.api.PageRequest; +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +import java.io.Serializable; + +/** + * 分页查询实体类 + * + * @author Lion Li + */ + + +public class PageBuilder implements Serializable { + + + public static Page build(PageRequest pageRequest) { + Integer pageNum = ObjectUtil.defaultIfNull(pageRequest.getPageNum(), PageQuery.DEFAULT_PAGE_NUM); + Integer pageSize = ObjectUtil.defaultIfNull(pageRequest.getPageSize(), PageQuery.DEFAULT_PAGE_SIZE); + return new Page(pageNum, pageSize); + } + +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/PageQuery.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/PageQuery.java new file mode 100644 index 0000000..efab021 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/PageQuery.java @@ -0,0 +1,113 @@ +package cc.iotkit.generator.core; + +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.StringUtils; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * 分页查询实体类 + * + * @author Lion Li + */ + +@Data +public class PageQuery implements Serializable { + + + private static final long serialVersionUID = 1L; + + /** + * 分页大小 + */ + private Integer pageSize; + + /** + * 当前页数 + */ + private Integer pageNum; + + /** + * 排序列 + */ + private String orderByColumn; + + /** + * 排序的方向desc或者asc + */ + private String isAsc; + + /** + * 当前记录起始索引 默认值 + */ + public static final int DEFAULT_PAGE_NUM = 1; + + /** + * 每页显示记录数 默认值 默认查全部 + */ + public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE; + + public Page build() { + Integer pageNum = ObjectUtil.defaultIfNull(getPageNum(), DEFAULT_PAGE_NUM); + Integer pageSize = ObjectUtil.defaultIfNull(getPageSize(), DEFAULT_PAGE_SIZE); + if (pageNum <= 0) { + pageNum = DEFAULT_PAGE_NUM; + } + Page page = new Page<>(pageNum, pageSize); + List orderItems = buildOrderItem(); + if (CollUtil.isNotEmpty(orderItems)) { + page.addOrder(orderItems); + } + return page; + } + + /** + * 构建排序 + * + * 支持的用法如下: + * {isAsc:"asc",orderByColumn:"id"} order by id asc + * {isAsc:"asc",orderByColumn:"id,createTime"} order by id asc,create_time asc + * {isAsc:"desc",orderByColumn:"id,createTime"} order by id desc,create_time desc + * {isAsc:"asc,desc",orderByColumn:"id,createTime"} order by id asc,create_time desc + */ + private List buildOrderItem() { + if (StringUtils.isBlank(orderByColumn) || StringUtils.isBlank(isAsc)) { + return Collections.emptyList(); + } + String orderBy = SqlUtil.escapeOrderBySql(orderByColumn); + orderBy = StringUtils.toUnderScoreCase(orderBy); + + // 兼容前端排序类型 + isAsc = StringUtils.replaceEach(isAsc, new String[]{"ascending", "descending"}, new String[]{"asc", "desc"}); + + String[] orderByArr = orderBy.split(StringUtils.SEPARATOR); + String[] isAscArr = isAsc.split(StringUtils.SEPARATOR); + if (isAscArr.length != 1 && isAscArr.length != orderByArr.length) { + throw new BizException("排序参数有误"); + } + + List list = new ArrayList<>(); + // 每个字段各自排序 + for (int i = 0; i < orderByArr.length; i++) { + String orderByStr = orderByArr[i]; + String isAscStr = isAscArr.length == 1 ? isAscArr[0] : isAscArr[i]; + if ("asc".equals(isAscStr)) { + list.add(OrderItem.asc(orderByStr)); + } else if ("desc".equals(isAscStr)) { + list.add(OrderItem.desc(orderByStr)); + } else { + throw new BizException("排序参数有误"); + } + } + return list; + } + +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/SqlUtil.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/SqlUtil.java new file mode 100644 index 0000000..c4fb297 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/SqlUtil.java @@ -0,0 +1,58 @@ +package cc.iotkit.generator.core; + +import cc.iotkit.common.utils.StringUtils; +import cn.hutool.core.exceptions.UtilException; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + + +/** + * sql操作工具类 + * + * @author ruoyi + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class SqlUtil { + + /** + * 定义常用的 sql关键字 + */ + public static final String SQL_REGEX = "select |insert |delete |update |drop |count |exec |chr |mid |master |truncate |char |and |declare "; + + /** + * 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序) + */ + public static final String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,\\.]+"; + + /** + * 检查字符,防止注入绕过 + */ + public static String escapeOrderBySql(String value) { + if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value)) { + throw new UtilException("参数不符合规范,不能进行查询"); + } + return value; + } + + /** + * 验证 order by 语法是否符合规范 + */ + public static boolean isValidOrderBySql(String value) { + return value.matches(SQL_PATTERN); + } + + /** + * SQL关键字检查 + */ + public static void filterKeyword(String value) { + if (StringUtils.isEmpty(value)) { + return; + } + String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|"); + for (String sqlKeyword : sqlKeywords) { + if (StringUtils.indexOfIgnoreCase(value, sqlKeyword) > -1) { + throw new UtilException("参数存在SQL注入风险"); + } + } + } +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTable.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTable.java new file mode 100644 index 0000000..59aa8d3 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTable.java @@ -0,0 +1,196 @@ +package cc.iotkit.generator.domain; + +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.generator.constant.GenConstants; +import cc.iotkit.generator.core.BaseEntity; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import javax.validation.Valid; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * 业务表 gen_table + * + * @author Lion Li + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("gen_table") +public class GenTable extends BaseEntity { + + /** + * 编号 + */ + @TableId(value = "table_id") + private Long tableId; + + /** + * 数据源名称 + */ + // @NotBlank(message = "数据源名称不能为空") + private String dataName; + + /** + * 表名称 + */ + // @NotBlank(message = "表名称不能为空") + private String tableName; + + /** + * 表描述 + */ + // @NotBlank(message = "表描述不能为空") + private String tableComment; + + /** + * 关联父表的表名 + */ + private String subTableName; + + /** + * 本表关联父表的外键名 + */ + private String subTableFkName; + + /** + * 实体类名称(首字母大写) + */ + // @NotBlank(message = "实体类名称不能为空") + private String className; + + /** + * 使用的模板(crud单表操作 tree树表操作 sub主子表操作) + */ + private String tplCategory; + + /** + * 生成包路径 + */ + // @NotBlank(message = "生成包路径不能为空") + private String packageName; + + /** + * 生成模块名 + */ + // @NotBlank(message = "生成模块名不能为空") + private String moduleName; + + /** + * 生成业务名 + */ + // @NotBlank(message = "生成业务名不能为空") + private String businessName; + + /** + * 生成功能名 + */ + //@NotBlank(message = "生成功能名不能为空") + private String functionName; + + /** + * 生成作者 + */ + //@NotBlank(message = "作者不能为空") + private String functionAuthor; + + /** + * 生成代码方式(0zip压缩包 1自定义路径) + */ + private String genType; + + /** + * 生成路径(不填默认项目路径) + */ + @TableField(updateStrategy = FieldStrategy.NOT_EMPTY) + private String genPath; + + /** + * 主键信息 + */ + @TableField(exist = false) + private GenTableColumn pkColumn; + + /** + * 表列信息 + */ + @Valid + @TableField(exist = false) + private List columns; + + /** + * 其它生成选项 + */ + private String options; + + /** + * 备注 + */ + private String remark; + + /** + * 树编码字段 + */ + @TableField(exist = false) + private String treeCode; + + /** + * 树父编码字段 + */ + @TableField(exist = false) + private String treeParentCode; + + /** + * 树名称字段 + */ + @TableField(exist = false) + private String treeName; + + /* + * 菜单id列表 + */ + @TableField(exist = false) + private List menuIds; + + /** + * 上级菜单ID字段 + */ + @TableField(exist = false) + private String parentMenuId; + + /** + * 上级菜单名称字段 + */ + @TableField(exist = false) + private String parentMenuName; + + public boolean isTree() { + return isTree(this.tplCategory); + } + + public static boolean isTree(String tplCategory) { + return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory); + } + + public boolean isCrud() { + return isCrud(this.tplCategory); + } + + public static boolean isCrud(String tplCategory) { + return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory); + } + + public boolean isSuperColumn(String javaField) { + return isSuperColumn(this.tplCategory, javaField); + } + + public static boolean isSuperColumn(String tplCategory, String javaField) { + return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); + } +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTableColumn.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTableColumn.java new file mode 100644 index 0000000..83ee8c5 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTableColumn.java @@ -0,0 +1,222 @@ +package cc.iotkit.generator.domain; + +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.generator.core.BaseEntity; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.apache.ibatis.type.JdbcType; + +/** + * 代码生成业务字段表 gen_table_column + * + * @author Lion Li + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("gen_table_column") +public class GenTableColumn extends BaseEntity { + + /** + * 编号 + */ + @TableId(value = "column_id") + private Long columnId; + + /** + * 归属表编号 + */ + private Long tableId; + + /** + * 列名称 + */ + private String columnName; + + /** + * 列描述 + */ + @TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR) + private String columnComment; + + /** + * 列类型 + */ + private String columnType; + + /** + * JAVA类型 + */ + private String javaType; + + /** + * JAVA字段名 + */ + @NotBlank(message = "Java属性不能为空") + private String javaField; + + /** + * 是否主键(1是) + */ + @TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR) + private String isPk; + + /** + * 是否自增(1是) + */ + @TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR) + private String isIncrement; + + /** + * 是否必填(1是) + */ + @TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR) + private String isRequired; + + /** + * 是否为插入字段(1是) + */ + @TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR) + private String isInsert; + + /** + * 是否编辑字段(1是) + */ + @TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR) + private String isEdit; + + /** + * 是否列表字段(1是) + */ + @TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR) + private String isList; + + /** + * 是否查询字段(1是) + */ + @TableField(updateStrategy = FieldStrategy.IGNORED, jdbcType = JdbcType.VARCHAR) + private String isQuery; + + /** + * 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) + */ + private String queryType; + + /** + * 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件) + */ + private String htmlType; + + /** + * 字典类型 + */ + private String dictType; + + /** + * 排序 + */ + private Integer sort; + + public String getCapJavaField() { + return StringUtils.capitalize(javaField); + } + + public boolean isPk() { + return isPk(this.isPk); + } + + public boolean isPk(String isPk) { + return isPk != null && StringUtils.equals("1", isPk); + } + + public boolean isIncrement() { + return isIncrement(this.isIncrement); + } + + public boolean isIncrement(String isIncrement) { + return isIncrement != null && StringUtils.equals("1", isIncrement); + } + + public boolean isRequired() { + return isRequired(this.isRequired); + } + + public boolean isRequired(String isRequired) { + return isRequired != null && StringUtils.equals("1", isRequired); + } + + public boolean isInsert() { + return isInsert(this.isInsert); + } + + public boolean isInsert(String isInsert) { + return isInsert != null && StringUtils.equals("1", isInsert); + } + + public boolean isEdit() { + return isInsert(this.isEdit); + } + + public boolean isEdit(String isEdit) { + return isEdit != null && StringUtils.equals("1", isEdit); + } + + public boolean isList() { + return isList(this.isList); + } + + public boolean isList(String isList) { + return isList != null && StringUtils.equals("1", isList); + } + + public boolean isQuery() { + return isQuery(this.isQuery); + } + + public boolean isQuery(String isQuery) { + return isQuery != null && StringUtils.equals("1", isQuery); + } + + public boolean isSuperColumn() { + return isSuperColumn(this.javaField); + } + + public static boolean isSuperColumn(String javaField) { + return StringUtils.equalsAnyIgnoreCase(javaField, + // BaseEntity + "createBy", "createTime", "updateBy", "updateTime", + // TreeEntity + "parentName", "parentId"); + } + + public boolean isUsableColumn() { + return isUsableColumn(javaField); + } + + public static boolean isUsableColumn(String javaField) { + // isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单 + return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); + } + + public String readConverterExp() { + String remarks = StringUtils.substringBetween(this.columnComment, "(", ")"); + StringBuffer sb = new StringBuffer(); + if (StringUtils.isNotEmpty(remarks)) { + for (String value : remarks.split(" ")) { + if (StringUtils.isNotEmpty(value)) { + Object startStr = value.subSequence(0, 1); + String endStr = value.substring(1); + sb.append(StringUtils.EMPTY).append(startStr).append("=").append(endStr).append(StringUtils.SEPARATOR); + } + } + return sb.deleteCharAt(sb.length() - 1).toString(); + } else { + return this.columnComment; + } + } +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/dto/bo/ImportTableBo.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/dto/bo/ImportTableBo.java new file mode 100644 index 0000000..daa156f --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/dto/bo/ImportTableBo.java @@ -0,0 +1,24 @@ +package cc.iotkit.generator.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotEmpty; +import lombok.Data; + +import java.util.List; + +/** + * @Author: jay + * @Date: 2023/6/24 16:47 + * @Version: V1.0 + * @Description: 导入表Bo + */ +@Data +public class ImportTableBo extends BaseDto { + + @ApiModelProperty(value = "表名列表", notes = "表名列表") + @NotEmpty(message = "表名列表不能为空") + private List tables; + + +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/factory/YmlPropertySourceFactory.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/factory/YmlPropertySourceFactory.java new file mode 100644 index 0000000..cd5933b --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/factory/YmlPropertySourceFactory.java @@ -0,0 +1,32 @@ +package cc.iotkit.generator.factory; + + +import cc.iotkit.common.utils.StringUtils; +import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; +import org.springframework.core.env.PropertiesPropertySource; +import org.springframework.core.env.PropertySource; +import org.springframework.core.io.support.DefaultPropertySourceFactory; +import org.springframework.core.io.support.EncodedResource; + +import java.io.IOException; + +/** + * yml 配置源工厂 + * + * @author Lion Li + */ +public class YmlPropertySourceFactory extends DefaultPropertySourceFactory { + + @Override + public PropertySource createPropertySource(String name, EncodedResource resource) throws IOException { + String sourceName = resource.getResource().getFilename(); + if (StringUtils.isNotBlank(sourceName) && StringUtils.endsWithAny(sourceName, ".yml", ".yaml")) { + YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); + factory.setResources(resource.getResource()); + factory.afterPropertiesSet(); + return new PropertiesPropertySource(sourceName, factory.getObject()); + } + return super.createPropertySource(name, resource); + } + +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/mapper/GenTableColumnMapper.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/mapper/GenTableColumnMapper.java new file mode 100644 index 0000000..ad5a4a5 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/mapper/GenTableColumnMapper.java @@ -0,0 +1,24 @@ +package cc.iotkit.generator.mapper; + +import cc.iotkit.generator.core.BaseMapperPlus; +import cc.iotkit.generator.domain.GenTableColumn; +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; + +import java.util.List; + +/** + * 业务字段 数据层 + * + * @author Lion Li + */ +@InterceptorIgnore(dataPermission = "true", tenantLine = "true") +public interface GenTableColumnMapper extends BaseMapperPlus { + /** + * 根据表名称查询列信息 + * + * @param tableName 表名称 + * @return 列信息 + */ + List selectDbTableColumnsByName(String tableName); + +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/mapper/GenTableMapper.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/mapper/GenTableMapper.java new file mode 100644 index 0000000..42f8f9b --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/mapper/GenTableMapper.java @@ -0,0 +1,63 @@ +package cc.iotkit.generator.mapper; + +import cc.iotkit.generator.core.BaseMapperPlus; +import cc.iotkit.generator.domain.GenTable; +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.ibatis.annotations.Param; + +import java.util.Collection; +import java.util.List; + +/** + * 业务 数据层 + * + * @author Lion Li + */ +@InterceptorIgnore( tenantLine = "true") +public interface GenTableMapper extends BaseMapperPlus { + + /** + * 查询据库列表 + * + * @param genTable 查询条件 + * @return 数据库表集合 + */ + @InterceptorIgnore( tenantLine = "true") + Page selectPageDbTableList(@Param("page") Page page, @Param("genTable") GenTable genTable); + + /** + * 查询据库列表 + * + * @param tableNames 表名称组 + * @return 数据库表集合 + */ + List selectDbTableListByNames(Collection tableNames); + + /** + * 查询所有表信息 + * + * @return 表信息集合 + */ + List selectGenTableAll(); + + /** + * 查询表ID业务信息 + * + * @param id 业务ID + * @return 业务信息 + */ + GenTable selectGenTableById(Long id); + + /** + * 查询表名称业务信息 + * + * @param tableName 表名称 + * @return 业务信息 + */ + GenTable selectGenTableByName(String tableName); + + List selectTableNameList(String dataName); + + +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/GenTableServiceImpl.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/GenTableServiceImpl.java new file mode 100644 index 0000000..7887ca3 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/GenTableServiceImpl.java @@ -0,0 +1,463 @@ +package cc.iotkit.generator.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.utils.file.FileUtils; +import cc.iotkit.generator.constant.GenConstants; +import cc.iotkit.generator.core.DbIdGenerator; +import cc.iotkit.generator.core.PageBuilder; +import cc.iotkit.generator.domain.GenTable; +import cc.iotkit.generator.domain.GenTableColumn; +import cc.iotkit.generator.mapper.GenTableColumnMapper; +import cc.iotkit.generator.mapper.GenTableMapper; +import cc.iotkit.generator.util.GenUtils; +import cc.iotkit.generator.util.VelocityInitializer; +import cc.iotkit.generator.util.VelocityUtils; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.lang.Dict; +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +/** + * 业务 服务层实现 + * + * @author Lion Li + */ +@DS("#header.datasource") +@Slf4j +@RequiredArgsConstructor +@Service +public class GenTableServiceImpl implements IGenTableService { + + private final GenTableMapper baseMapper; + private final GenTableColumnMapper genTableColumnMapper; + private final DbIdGenerator identifierGenerator; + + /** + * 查询业务字段列表 + * + * @param tableId 业务字段编号 + * @return 业务字段集合 + */ + @Override + public List selectGenTableColumnListByTableId(Long tableId) { + return genTableColumnMapper.selectList(new LambdaQueryWrapper() + .eq(GenTableColumn::getTableId, tableId) + .orderByAsc(GenTableColumn::getSort)); + } + + /** + * 查询业务信息 + * + * @param id 业务ID + * @return 业务信息 + */ + @Override + public GenTable selectGenTableById(Long id) { + GenTable genTable = baseMapper.selectGenTableById(id); + setTableFromOptions(genTable); + return genTable; + } + + @Override + public Paging selectPageGenTableList( PageRequest pageQuery) { + Page page = baseMapper.selectPage(PageBuilder.build(pageQuery), this.buildGenTableQueryWrapper(pageQuery.getData())); + return new Paging<>(page.getTotal(), page.getRecords()); + } + + private QueryWrapper buildGenTableQueryWrapper(GenTable genTable) { + Map params = genTable.getParams(); + QueryWrapper wrapper = Wrappers.query(); + wrapper.like(StringUtils.isNotBlank(genTable.getTableName()), "lower(table_name)", StringUtils.lowerCase(genTable.getTableName())) + .like(StringUtils.isNotBlank(genTable.getTableComment()), "lower(table_comment)", StringUtils.lowerCase(genTable.getTableComment())) + .between(StringUtils.isNotBlank((CharSequence) params.get("beginTime")) && StringUtils.isNotBlank((CharSequence) params.get("endTime")), + "create_time", params.get("beginTime"), params.get("endTime")); + return wrapper; + } + + + @Override + public Paging selectPageDbTableList(PageRequest pageQuery) { + GenTable genTable = pageQuery.getData(); + genTable.getParams().put("genTableNames",baseMapper.selectTableNameList(genTable.getDataName())); + + Page page = baseMapper.selectPageDbTableList(PageBuilder.build(pageQuery), genTable); + return new Paging<>(page.getTotal(), page.getRecords()); + } + + /** + * 查询据库列表 + * + * @param tableNames 表名称组 + * @return 数据库表集合 + */ + @Override + public List selectDbTableListByNames(Collection tableNames) { + return baseMapper.selectDbTableListByNames(tableNames); + } + + /** + * 查询所有表信息 + * + * @return 表信息集合 + */ + @Override + public List selectGenTableAll() { + return baseMapper.selectGenTableAll(); + } + + /** + * 修改业务 + * + * @param genTable 业务信息 + * @return 结果 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void updateGenTable(GenTable genTable) { + String options = JsonUtils.toJsonString(genTable.getParams()); + genTable.setOptions(options); + int row = baseMapper.updateById(genTable); + if (row > 0) { + for (GenTableColumn cenTableColumn : genTable.getColumns()) { + genTableColumnMapper.updateById(cenTableColumn); + } + } + } + + /** + * 删除业务对象 + * + * @param tableIds 需要删除的数据ID + * @return 结果 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void deleteGenTableByIds(Collection tableIds) { + + baseMapper.deleteBatchIds(tableIds); + genTableColumnMapper.delete(new LambdaQueryWrapper().in(GenTableColumn::getTableId, tableIds)); + } + + /** + * 导入表结构 + * + * @param tableList 导入表列表 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void importGenTable(List tableList) { + String operName = LoginHelper.getUsername(); + try { + for (GenTable table : tableList) { + String tableName = table.getTableName(); + GenUtils.initTable(table, operName); + int row = baseMapper.insert(table); + if (row > 0) { + // 保存列信息 + List genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); + List saveColumns = new ArrayList<>(); + for (GenTableColumn column : genTableColumns) { + GenUtils.initColumnField(column, table); + saveColumns.add(column); + } + if (CollUtil.isNotEmpty(saveColumns)) { + genTableColumnMapper.insertBatch(saveColumns); + } + } + } + } catch (Exception e) { + throw new BizException("导入失败:" + e.getMessage()); + } + } + + /** + * 预览代码 + * + * @param tableId 表编号 + * @return 预览数据列表 + */ + @Override + public Map previewCode(Long tableId) { + Map dataMap = new LinkedHashMap<>(); + // 查询表信息 + GenTable table = baseMapper.selectGenTableById(tableId); + List menuIds = new ArrayList<>(); + for (int i = 0; i < 6; i++) { + menuIds.add((Long) identifierGenerator.nextId(null)); + } + table.setMenuIds(menuIds); + // 设置主键列信息 + setPkColumn(table); + VelocityInitializer.initVelocity(); + + VelocityContext context = VelocityUtils.prepareContext(table); + + // 获取模板列表 + List templates = VelocityUtils.getTemplateList(table.getTplCategory()); + for (String template : templates) { + // 渲染模板 + StringWriter sw = new StringWriter(); + Template tpl = Velocity.getTemplate(template, Constants.UTF8); + tpl.merge(context, sw); + dataMap.put(template, sw.toString()); + } + return dataMap; + } + + /** + * 生成代码(下载方式) + * + * @param tableName 表名称 + * @return 数据 + */ + @Override + public byte[] downloadCode(String tableName) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ZipOutputStream zip = new ZipOutputStream(outputStream); + generatorCode(tableName, zip); + IoUtil.close(zip); + return outputStream.toByteArray(); + } + + /** + * 生成代码(自定义路径) + * + * @param tableName 表名称 + */ + @Override + public void generatorCode(String tableName) { + // 查询表信息 + GenTable table = baseMapper.selectGenTableByName(tableName); + // 设置主键列信息 + setPkColumn(table); + + VelocityInitializer.initVelocity(); + + VelocityContext context = VelocityUtils.prepareContext(table); + + // 获取模板列表 + List templates = VelocityUtils.getTemplateList(table.getTplCategory()); + for (String template : templates) { + if (!StringUtils.containsAny(template, "sql.vm", "api.ts.vm", "types.ts.vm", "index.vue.vm", "index-tree.vue.vm")) { + // 渲染模板 + StringWriter sw = new StringWriter(); + Template tpl = Velocity.getTemplate(template, Constants.UTF8); + tpl.merge(context, sw); + try { + String path = getGenPath(table, template); + FileUtils.writeUtf8String(sw.toString(), path); + } catch (Exception e) { + throw new BizException("渲染模板失败,表名:" + table.getTableName()); + } + } + } + } + + /** + * 同步数据库 + * + * @param tableName 表名称 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void synchDb(String tableName) { + GenTable table = baseMapper.selectGenTableByName(tableName); + List tableColumns = table.getColumns(); + Map tableColumnMap = StreamUtils.toIdentityMap(tableColumns, GenTableColumn::getColumnName); + + List dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); + if (CollUtil.isEmpty(dbTableColumns)) { + throw new BizException("同步数据失败,原表结构不存在"); + } + List dbTableColumnNames = StreamUtils.toList(dbTableColumns, GenTableColumn::getColumnName); + + List saveColumns = new ArrayList<>(); + dbTableColumns.forEach(column -> { + GenUtils.initColumnField(column, table); + if (tableColumnMap.containsKey(column.getColumnName())) { + GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName()); + column.setColumnId(prevColumn.getColumnId()); + if (column.isList()) { + // 如果是列表,继续保留查询方式/字典类型选项 + column.setDictType(prevColumn.getDictType()); + column.setQueryType(prevColumn.getQueryType()); + } + if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk() + && (column.isInsert() || column.isEdit()) + && ((column.isUsableColumn()) || (!column.isSuperColumn()))) { + // 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项 + column.setIsRequired(prevColumn.getIsRequired()); + column.setHtmlType(prevColumn.getHtmlType()); + } + } + saveColumns.add(column); + }); + if (CollUtil.isNotEmpty(saveColumns)) { + genTableColumnMapper.insertOrUpdateBatch(saveColumns); + } + List delColumns = StreamUtils.filter(tableColumns, column -> !dbTableColumnNames.contains(column.getColumnName())); + if (CollUtil.isNotEmpty(delColumns)) { + List ids = StreamUtils.toList(delColumns, GenTableColumn::getColumnId); + genTableColumnMapper.deleteBatchIds(ids); + } + } + + /** + * 批量生成代码(下载方式) + * + * @param tableNames 表数组 + * @return 数据 + */ + @Override + public byte[] downloadCode(String[] tableNames) { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ZipOutputStream zip = new ZipOutputStream(outputStream); + for (String tableName : tableNames) { + generatorCode(tableName, zip); + } + IoUtil.close(zip); + return outputStream.toByteArray(); + } + + /** + * 查询表信息并生成代码 + */ + private void generatorCode(String tableName, ZipOutputStream zip) { + // 查询表信息 + GenTable table = baseMapper.selectGenTableByName(tableName); + List menuIds = new ArrayList<>(); + for (int i = 0; i < 6; i++) { + menuIds.add((Long) identifierGenerator.nextId(null)); + } + table.setMenuIds(menuIds); + // 设置主键列信息 + setPkColumn(table); + + VelocityInitializer.initVelocity(); + + VelocityContext context = VelocityUtils.prepareContext(table); + + // 获取模板列表 + List templates = VelocityUtils.getTemplateList(table.getTplCategory()); + for (String template : templates) { + // 渲染模板 + StringWriter sw = new StringWriter(); + Template tpl = Velocity.getTemplate(template, Constants.UTF8); + tpl.merge(context, sw); + try { + // 添加到zip + zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); + IoUtil.write(zip, StandardCharsets.UTF_8, false, sw.toString()); + IoUtil.close(sw); + zip.flush(); + zip.closeEntry(); + } catch (IOException e) { + log.error("渲染模板失败,表名:" + table.getTableName(), e); + } + } + } + + /** + * 修改保存参数校验 + * + * @param genTable 业务信息 + */ + @Override + public void validateEdit(GenTable genTable) { + if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { + String options = JsonUtils.toJsonString(genTable.getParams()); + Dict paramsObj = JsonUtils.parseMap(options); + if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_CODE))) { + throw new BizException("树编码字段不能为空"); + } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_PARENT_CODE))) { + throw new BizException("树父编码字段不能为空"); + } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_NAME))) { + throw new BizException("树名称字段不能为空"); + } + } + } + + /** + * 设置主键列信息 + * + * @param table 业务表信息 + */ + public void setPkColumn(GenTable table) { + for (GenTableColumn column : table.getColumns()) { + if (column.isPk()) { + table.setPkColumn(column); + break; + } + } + if (ObjectUtil.isNull(table.getPkColumn())) { + table.setPkColumn(table.getColumns().get(0)); + } + + } + + /** + * 设置代码生成其他选项值 + * + * @param genTable 设置后的生成对象 + */ + public void setTableFromOptions(GenTable genTable) { + Dict paramsObj = JsonUtils.parseMap(genTable.getOptions()); + if (ObjectUtil.isNotNull(paramsObj)) { + String treeCode = paramsObj.getStr(GenConstants.TREE_CODE); + String treeParentCode = paramsObj.getStr(GenConstants.TREE_PARENT_CODE); + String treeName = paramsObj.getStr(GenConstants.TREE_NAME); + String parentMenuId = paramsObj.getStr(GenConstants.PARENT_MENU_ID); + String parentMenuName = paramsObj.getStr(GenConstants.PARENT_MENU_NAME); + + genTable.setTreeCode(treeCode); + genTable.setTreeParentCode(treeParentCode); + genTable.setTreeName(treeName); + genTable.setParentMenuId(parentMenuId); + genTable.setParentMenuName(parentMenuName); + } + } + + /** + * 获取代码生成地址 + * + * @param table 业务表信息 + * @param template 模板文件路径 + * @return 生成地址 + */ + public static String getGenPath(GenTable table, String template) { + String genPath = table.getGenPath(); + if (StringUtils.equals(genPath, "/")) { + return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); + } + return genPath + File.separator + VelocityUtils.getFileName(template, table); + } +} + diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/IGenTableService.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/IGenTableService.java new file mode 100644 index 0000000..7b53f19 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/IGenTableService.java @@ -0,0 +1,134 @@ +package cc.iotkit.generator.service; + + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.generator.domain.GenTable; +import cc.iotkit.generator.domain.GenTableColumn; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + * 业务 服务层 + * + * @author Lion Li + */ +public interface IGenTableService { + + /** + * 查询业务字段列表 + * + * @param tableId 业务字段编号 + * @return 业务字段集合 + */ + List selectGenTableColumnListByTableId(Long tableId); + + /** + * 查询业务列表 + * + * + * @return 业务集合 + */ + Paging selectPageGenTableList(PageRequest pageQuery); + + /** + * 查询据库列表 + * + * @return 数据库表集合 + */ + Paging selectPageDbTableList(PageRequest pageQuery); + + /** + * 查询据库列表 + * + * @param tableNames 表名称组 + * @return 数据库表集合 + */ + List selectDbTableListByNames(Collection tableNames); + + /** + * 查询所有表信息 + * + * @return 表信息集合 + */ + List selectGenTableAll(); + + /** + * 查询业务信息 + * + * @param id 业务ID + * @return 业务信息 + */ + GenTable selectGenTableById(Long id); + + /** + * 修改业务 + * + * @param genTable 业务信息 + * @return 结果 + */ + void updateGenTable(GenTable genTable); + + /** + * 删除业务信息 + * + * @param tableIds 需要删除的表数据ID + * @return 结果 + */ + void deleteGenTableByIds(Collection tableIds); + + /** + * 导入表结构 + * + * @param tableList 导入表列表 + */ + void importGenTable(List tableList); + + /** + * 预览代码 + * + * @param tableId 表编号 + * @return 预览数据列表 + */ + Map previewCode(Long tableId); + + /** + * 生成代码(下载方式) + * + * @param tableName 表名称 + * @return 数据 + */ + byte[] downloadCode(String tableName); + + /** + * 生成代码(自定义路径) + * + * @param tableName 表名称 + * @return 数据 + */ + void generatorCode(String tableName); + + /** + * 同步数据库 + * + * @param tableName 表名称 + */ + void synchDb(String tableName); + + /** + * 批量生成代码(下载方式) + * + * @param tableNames 表数组 + * @return 数据 + */ + byte[] downloadCode(String[] tableNames); + + /** + * 修改保存参数校验 + * + * @param genTable 业务信息 + */ + void validateEdit(GenTable genTable); +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/GenUtils.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/GenUtils.java new file mode 100644 index 0000000..4659c5e --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/GenUtils.java @@ -0,0 +1,233 @@ +package cc.iotkit.generator.util; + +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.generator.config.GenConfig; +import cc.iotkit.generator.constant.GenConstants; +import cc.iotkit.generator.domain.GenTable; +import cc.iotkit.generator.domain.GenTableColumn; +import cn.hutool.core.util.ReUtil; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Arrays; + +/** + * 代码生成器 工具类 + * + * @author ruoyi + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class GenUtils { + + /** + * 初始化表信息 + */ + public static void initTable(GenTable genTable, String operName) { + genTable.setClassName(convertClassName(genTable.getTableName())); + genTable.setPackageName(GenConfig.getPackageName()); + genTable.setModuleName(getModuleName(GenConfig.getPackageName())); + genTable.setBusinessName(getBusinessName(genTable.getTableName())); + genTable.setFunctionName(replaceText(genTable.getTableComment())); + genTable.setFunctionAuthor(GenConfig.getAuthor()); + genTable.setCreateBy(LoginHelper.getUserId()); + } + + /** + * 初始化列属性字段 + */ + public static void initColumnField(GenTableColumn column, GenTable table) { + String dataType = getDbType(column.getColumnType()); + String columnName = column.getColumnName(); + column.setTableId(table.getTableId()); + column.setCreateBy(table.getCreateBy()); + // 设置java字段名 + column.setJavaField(StringUtils.toCamelCase(columnName)); + // 设置默认类型 + column.setJavaType(GenConstants.TYPE_STRING); + column.setQueryType(GenConstants.QUERY_EQ); + + if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) { + // 字符串长度超过500设置为文本域 + Integer columnLength = getColumnLength(column.getColumnType()); + String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; + column.setHtmlType(htmlType); + } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) { + column.setJavaType(GenConstants.TYPE_DATE); + column.setHtmlType(GenConstants.HTML_DATETIME); + } else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) { + column.setHtmlType(GenConstants.HTML_INPUT); + + // 如果是浮点型 统一用BigDecimal + String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), StringUtils.SEPARATOR); + if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) { + column.setJavaType(GenConstants.TYPE_BIGDECIMAL); + } + // 如果是整形 + else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) { + column.setJavaType(GenConstants.TYPE_INTEGER); + } + // 长整形 + else { + column.setJavaType(GenConstants.TYPE_LONG); + } + } + + // BO对象 默认插入勾选 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_ADD, columnName) && !column.isPk()) { + column.setIsInsert(GenConstants.REQUIRE); + } + // BO对象 默认编辑勾选 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName)) { + column.setIsEdit(GenConstants.REQUIRE); + } + // BO对象 默认是否必填勾选 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName)) { + column.setIsRequired(GenConstants.REQUIRE); + } + // VO对象 默认返回勾选 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName)) { + column.setIsList(GenConstants.REQUIRE); + } + // BO对象 默认查询勾选 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) { + column.setIsQuery(GenConstants.REQUIRE); + } + + // 查询字段类型 + if (StringUtils.endsWithIgnoreCase(columnName, "name")) { + column.setQueryType(GenConstants.QUERY_LIKE); + } + // 状态字段设置单选框 + if (StringUtils.endsWithIgnoreCase(columnName, "status")) { + column.setHtmlType(GenConstants.HTML_RADIO); + } + // 类型&性别字段设置下拉框 + else if (StringUtils.endsWithIgnoreCase(columnName, "type") + || StringUtils.endsWithIgnoreCase(columnName, "sex")) { + column.setHtmlType(GenConstants.HTML_SELECT); + } + // 图片字段设置图片上传控件 + else if (StringUtils.endsWithIgnoreCase(columnName, "image")) { + column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD); + } + // 文件字段设置文件上传控件 + else if (StringUtils.endsWithIgnoreCase(columnName, "file")) { + column.setHtmlType(GenConstants.HTML_FILE_UPLOAD); + } + // 内容字段设置富文本控件 + else if (StringUtils.endsWithIgnoreCase(columnName, "content")) { + column.setHtmlType(GenConstants.HTML_EDITOR); + } + } + + /** + * 校验数组是否包含指定值 + * + * @param arr 数组 + * @param targetValue 值 + * @return 是否包含 + */ + public static boolean arraysContains(String[] arr, String targetValue) { + return Arrays.asList(arr).contains(targetValue); + } + + /** + * 获取模块名 + * + * @param packageName 包名 + * @return 模块名 + */ + public static String getModuleName(String packageName) { + int lastIndex = packageName.lastIndexOf("."); + int nameLength = packageName.length(); + return StringUtils.substring(packageName, lastIndex + 1, nameLength); + } + + /** + * 获取业务名 + * + * @param tableName 表名 + * @return 业务名 + */ + public static String getBusinessName(String tableName) { + int firstIndex = tableName.indexOf("_"); + int nameLength = tableName.length(); + String businessName = StringUtils.substring(tableName, firstIndex + 1, nameLength); + businessName = StringUtils.toCamelCase(businessName); + return businessName; + } + + /** + * 表名转换成Java类名 + * + * @param tableName 表名称 + * @return 类名 + */ + public static String convertClassName(String tableName) { + boolean autoRemovePre = GenConfig.getAutoRemovePre(); + String tablePrefix = GenConfig.getTablePrefix(); + if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) { + String[] searchList = StringUtils.split(tablePrefix, StringUtils.SEPARATOR); + tableName = replaceFirst(tableName, searchList); + } + return StringUtils.convertToCamelCase(tableName); + } + + /** + * 批量替换前缀 + * + * @param replacementm 替换值 + * @param searchList 替换列表 + * @return + */ + public static String replaceFirst(String replacementm, String[] searchList) { + String text = replacementm; + for (String searchString : searchList) { + if (replacementm.startsWith(searchString)) { + text = replacementm.replaceFirst(searchString, ""); + break; + } + } + return text; + } + + /** + * 关键字替换 + * + * @param text 需要被替换的名字 + * @return 替换后的名字 + */ + public static String replaceText(String text) { + return ReUtil.replaceAll(text, "(?:表|若依)", ""); + } + + /** + * 获取数据库类型字段 + * + * @param columnType 列类型 + * @return 截取后的列类型 + */ + public static String getDbType(String columnType) { + if (StringUtils.indexOf(columnType, '(') > 0) { + return StringUtils.substringBefore(columnType, "("); + } else { + return columnType; + } + } + + /** + * 获取字段长度 + * + * @param columnType 列类型 + * @return 截取后的列类型 + */ + public static Integer getColumnLength(String columnType) { + if (StringUtils.indexOf(columnType, '(') > 0) { + String length = StringUtils.substringBetween(columnType, "(", ")"); + return Integer.valueOf(length); + } else { + return 0; + } + } +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityInitializer.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityInitializer.java new file mode 100644 index 0000000..a47b759 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityInitializer.java @@ -0,0 +1,35 @@ +package cc.iotkit.generator.util; + +import cc.iotkit.common.constant.Constants; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.apache.velocity.app.Velocity; + +import java.util.Properties; + +/** + * VelocityEngine工厂 + * + * @author ruoyi + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class VelocityInitializer { + + /** + * 初始化vm方法 + */ + public static void initVelocity() { + Properties p = new Properties(); + try { + // 加载classpath目录下的vm文件 + p.setProperty("resource.loader.file.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); + // 定义字符集 + p.setProperty(Velocity.INPUT_ENCODING, Constants.UTF8); + // 初始化Velocity引擎,指定配置Properties + Velocity.init(p); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +} diff --git a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityUtils.java b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityUtils.java new file mode 100644 index 0000000..88b2768 --- /dev/null +++ b/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityUtils.java @@ -0,0 +1,354 @@ +package cc.iotkit.generator.util; + +import cc.iotkit.common.utils.DateUtils; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.generator.constant.GenConstants; +import cc.iotkit.generator.core.DataBaseHelper; +import cc.iotkit.generator.domain.GenTable; +import cc.iotkit.generator.domain.GenTableColumn; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.lang.Dict; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.apache.velocity.VelocityContext; + +import java.util.*; + +/** + * 模板处理工具类 + * + * @author ruoyi + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class VelocityUtils { + + /** + * 项目空间路径 + */ + private static final String PROJECT_PATH = "main/java"; + + /** + * mybatis空间路径 + */ + private static final String MYBATIS_PATH = "main/resources/mapper"; + + /** + * 默认上级菜单,系统工具 + */ + private static final String DEFAULT_PARENT_MENU_ID = "3"; + + /** + * 设置模板变量信息 + * + * @return 模板列表 + */ + public static VelocityContext prepareContext(GenTable genTable) { + String moduleName = genTable.getModuleName(); + String businessName = genTable.getBusinessName(); + String packageName = genTable.getPackageName(); + String tplCategory = genTable.getTplCategory(); + String functionName = genTable.getFunctionName(); + + VelocityContext velocityContext = new VelocityContext(); + velocityContext.put("tplCategory", genTable.getTplCategory()); + velocityContext.put("tableName", genTable.getTableName()); + velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】"); + velocityContext.put("ClassName", genTable.getClassName()); + velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); + velocityContext.put("moduleName", genTable.getModuleName()); + velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); + velocityContext.put("businessName", genTable.getBusinessName()); + velocityContext.put("basePackage", getPackagePrefix(packageName)); + velocityContext.put("packageName", packageName); + velocityContext.put("author", genTable.getFunctionAuthor()); + velocityContext.put("datetime", DateUtils.getDate()); + velocityContext.put("pkColumn", genTable.getPkColumn()); + velocityContext.put("importList", getImportList(genTable)); + velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); + velocityContext.put("columns", genTable.getColumns()); + velocityContext.put("table", genTable); + velocityContext.put("dicts", getDicts(genTable)); + setMenuVelocityContext(velocityContext, genTable); + if (GenConstants.TPL_TREE.equals(tplCategory)) { + setTreeVelocityContext(velocityContext, genTable); + } + return velocityContext; + } + + public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { + String options = genTable.getOptions(); + Dict paramsObj = JsonUtils.parseMap(options); + String parentMenuId = getParentMenuId(paramsObj); + context.put("parentMenuId", parentMenuId); + } + + public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) { + String options = genTable.getOptions(); + Dict paramsObj = JsonUtils.parseMap(options); + String treeCode = getTreecode(paramsObj); + String treeParentCode = getTreeParentCode(paramsObj); + String treeName = getTreeName(paramsObj); + + context.put("treeCode", treeCode); + context.put("treeParentCode", treeParentCode); + context.put("treeName", treeName); + context.put("expandColumn", getExpandColumn(genTable)); + if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { + context.put("tree_parent_code", paramsObj.get(GenConstants.TREE_PARENT_CODE)); + } + if (paramsObj.containsKey(GenConstants.TREE_NAME)) { + context.put("tree_name", paramsObj.get(GenConstants.TREE_NAME)); + } + } + + /** + * 获取模板信息 + * + * @return 模板列表 + */ + public static List getTemplateList(String tplCategory) { + List templates = new ArrayList(); + templates.add("vm/java/model.java.vm"); + templates.add("vm/java/vo.java.vm"); + templates.add("vm/java/bo.java.vm"); +// templates.add("vm/java/mapper.java.vm"); + templates.add("vm/java/service.java.vm"); + templates.add("vm/java/serviceImpl.java.vm"); + templates.add("vm/java/controller.java.vm"); + templates.add("vm/java/idata.java.vm"); + templates.add("vm/java/idataimpl.java.vm"); + templates.add("vm/java/tbmodel.java.vm"); + templates.add("vm/java/repository.java.vm"); + if (DataBaseHelper.isOracle()) { + templates.add("vm/sql/oracle/sql.vm"); + } else if (DataBaseHelper.isPostgerSql()) { + templates.add("vm/sql/postgres/sql.vm"); + } else if (DataBaseHelper.isSqlServer()) { + templates.add("vm/sql/sqlserver/sql.vm"); + } else { + templates.add("vm/sql/sql.vm"); + } + templates.add("vm/ts/api.ts.vm"); + templates.add("vm/ts/types.ts.vm"); + if (GenConstants.TPL_CRUD.equals(tplCategory)) { + templates.add("vm/vue/index.vue.vm"); + } else if (GenConstants.TPL_TREE.equals(tplCategory)) { + templates.add("vm/vue/index-tree.vue.vm"); + } + return templates; + } + + /** + * 获取文件名 + */ + public static String getFileName(String template, GenTable genTable) { + // 文件名称 + String fileName = ""; + // 包路径 + String packageName = genTable.getPackageName(); + // 模块名 + String moduleName = genTable.getModuleName(); + // 大写类名 + String className = genTable.getClassName(); + // 业务名称 + String businessName = genTable.getBusinessName(); + + String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); + String mybatisPath = MYBATIS_PATH + "/" + moduleName; + String vuePath = "vue"; + + if (template.contains("domain.java.vm")) { + fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); + } + if (template.endsWith("tbmodel.java.vm")) { + fileName = StringUtils.format("{}/data/model/Tb{}.java", javaPath, className); + } else if (template.endsWith("model.java.vm")) { + fileName = StringUtils.format("{}/model/{}.java", javaPath, className); + } + if (template.endsWith("repository.java.vm")) { + fileName = StringUtils.format("{}/repository/{}Repository.java", javaPath, className); + } + if (template.endsWith("idata.java.vm")) { + fileName = StringUtils.format("{}/data/I{}Data.java", javaPath, className); + } else if (template.endsWith("idataimpl.java.vm")) { + fileName = StringUtils.format("{}/data/impl/{}DataImpl.java", javaPath, className); + } + if (template.contains("vo.java.vm")) { + fileName = StringUtils.format("{}/dto/vo/{}Vo.java", javaPath, className); + } + if (template.contains("bo.java.vm")) { + fileName = StringUtils.format("{}/dto/bo/{}Bo.java", javaPath, className); + } + if (template.contains("mapper.java.vm")) { + fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); + } else if (template.contains("service.java.vm")) { + fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); + } else if (template.contains("serviceImpl.java.vm")) { + fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); + } else if (template.contains("controller.java.vm")) { + fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); + } else if (template.contains("mapper.xml.vm")) { + fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); + } else if (template.contains("sql.vm")) { + fileName = businessName + "Menu.sql"; + } else if (template.contains("api.ts.vm")) { + fileName = StringUtils.format("{}/api/{}/{}/index.ts", vuePath, moduleName, businessName); + } else if (template.contains("types.ts.vm")) { + fileName = StringUtils.format("{}/api/{}/{}/types.ts", vuePath, moduleName, businessName); + } else if (template.contains("index.vue.vm")) { + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); + } else if (template.contains("index-tree.vue.vm")) { + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); + } + return fileName; + } + + /** + * 获取包前缀 + * + * @param packageName 包名称 + * @return 包前缀名称 + */ + public static String getPackagePrefix(String packageName) { + int lastIndex = packageName.lastIndexOf("."); + return StringUtils.substring(packageName, 0, lastIndex); + } + + /** + * 根据列类型获取导入包 + * + * @param genTable 业务表对象 + * @return 返回需要导入的包列表 + */ + public static HashSet getImportList(GenTable genTable) { + List columns = genTable.getColumns(); + HashSet importList = new HashSet<>(); + for (GenTableColumn column : columns) { + if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) { + importList.add("java.util.Date"); + importList.add("com.fasterxml.jackson.annotation.JsonFormat"); + } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) { + importList.add("java.math.BigDecimal"); + } + } + return importList; + } + + /** + * 根据列类型获取字典组 + * + * @param genTable 业务表对象 + * @return 返回字典组 + */ + public static String getDicts(GenTable genTable) { + List columns = genTable.getColumns(); + Set dicts = new HashSet<>(); + addDicts(dicts, columns); + return StringUtils.join(dicts, ", "); + } + + /** + * 添加字典列表 + * + * @param dicts 字典列表 + * @param columns 列集合 + */ + public static void addDicts(Set dicts, List columns) { + for (GenTableColumn column : columns) { + if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny( + column.getHtmlType(), + new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX })) { + dicts.add("'" + column.getDictType() + "'"); + } + } + } + + /** + * 获取权限前缀 + * + * @param moduleName 模块名称 + * @param businessName 业务名称 + * @return 返回权限前缀 + */ + public static String getPermissionPrefix(String moduleName, String businessName) { + return StringUtils.format("{}:{}", moduleName, businessName); + } + + /** + * 获取上级菜单ID字段 + * + * @param paramsObj 生成其他选项 + * @return 上级菜单ID字段 + */ + public static String getParentMenuId(Dict paramsObj) { + if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID) + && StringUtils.isNotEmpty(paramsObj.getStr(GenConstants.PARENT_MENU_ID))) { + return paramsObj.getStr(GenConstants.PARENT_MENU_ID); + } + return DEFAULT_PARENT_MENU_ID; + } + + /** + * 获取树编码 + * + * @param paramsObj 生成其他选项 + * @return 树编码 + */ + public static String getTreecode(Map paramsObj) { + if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_CODE)) { + return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_CODE))); + } + return StringUtils.EMPTY; + } + + /** + * 获取树父编码 + * + * @param paramsObj 生成其他选项 + * @return 树父编码 + */ + public static String getTreeParentCode(Dict paramsObj) { + if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { + return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_PARENT_CODE)); + } + return StringUtils.EMPTY; + } + + /** + * 获取树名称 + * + * @param paramsObj 生成其他选项 + * @return 树名称 + */ + public static String getTreeName(Dict paramsObj) { + if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) { + return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_NAME)); + } + return StringUtils.EMPTY; + } + + /** + * 获取需要在哪一列上面显示展开按钮 + * + * @param genTable 业务表对象 + * @return 展开按钮列序号 + */ + public static int getExpandColumn(GenTable genTable) { + String options = genTable.getOptions(); + Dict paramsObj = JsonUtils.parseMap(options); + String treeName = paramsObj.getStr(GenConstants.TREE_NAME); + int num = 0; + for (GenTableColumn column : genTable.getColumns()) { + if (column.isList()) { + num++; + String columnName = column.getColumnName(); + if (columnName.equals(treeName)) { + break; + } + } + } + return num; + } +} diff --git a/iot-module/iot-generator/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/iot-module/iot-generator/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..6919707 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +cc.iotkit.generator.config.MybatisPlusConfig \ No newline at end of file diff --git a/iot-module/iot-generator/src/main/resources/application-generator.yml b/iot-module/iot-generator/src/main/resources/application-generator.yml new file mode 100644 index 0000000..5939408 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/application-generator.yml @@ -0,0 +1,45 @@ +spring: + + + jpa: + show-sql: true + hibernate: + ddl-auto: update + properties: + hibernate: + format_sql: true + + sql: + init: + # mysql 初始化 + schema-locations: classpath:sql/schema.sql + # postgrep 初始化 + #schema-locations: classpath:sql/schema-postgre.sql + mode: ALWAYS + + datasource: + # 动态数据源文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/content + dynamic: + primary: master #设置默认的数据源或者数据源组,默认值即为master + strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源 + datasource: + # 主库数据源 + master: + type: ${spring.datasource.type} + driverClassName: ${spring.datasource.driverClassName} + # jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562 + # rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题) + url: ${spring.datasource.url} + username: ${spring.datasource.username} + password: ${spring.datasource.password} + + # 从库数据源 + # slave: + # lazy: true + # type: ${spring.datasource.type} + #driverClassName: ${spring.datasource.driverClassName} + # jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562 + # rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题) + #url: ${spring.datasource.url} + #username: ${spring.datasource.username} + #password: ${spring.datasource.password} \ No newline at end of file diff --git a/iot-module/iot-generator/src/main/resources/common-mybatis.yml b/iot-module/iot-generator/src/main/resources/common-mybatis.yml new file mode 100644 index 0000000..f5dc637 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/common-mybatis.yml @@ -0,0 +1,33 @@ +# 内置配置 不允许修改 如需修改请在 nacos 上写相同配置覆盖 +# MyBatisPlus配置 +# https://baomidou.com/config/ +mybatis-plus: + # 启动时是否检查 MyBatis XML 文件的存在,默认不检查 + checkConfigLocation: false + configuration: + # 自动驼峰命名规则(camel case)映射 + mapUnderscoreToCamelCase: true + # MyBatis 自动映射策略 + # NONE:不启用 PARTIAL:只对非嵌套 resultMap 自动映射 FULL:对所有 resultMap 自动映射 + autoMappingBehavior: FULL + # MyBatis 自动映射时未知列或未知属性处理策 + # NONE:不做处理 WARNING:打印相关警告 FAILING:抛出异常和详细信息 + autoMappingUnknownColumnBehavior: NONE + # 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl + # 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl + # 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl + logImpl: org.apache.ibatis.logging.nologging.NoLoggingImpl + global-config: + # 是否打印 Logo banner + banner: true + dbConfig: + # 主键类型 + # AUTO 自增 NONE 空 INPUT 用户输入 ASSIGN_ID 雪花 ASSIGN_UUID 唯一 UUID + idType: ASSIGN_ID + # 逻辑已删除值(框架表均使用此值 禁止随意修改) + logicDeleteValue: 2 + # 逻辑未删除值 + logicNotDeleteValue: 0 + insertStrategy: NOT_NULL + updateStrategy: NOT_NULL + whereStrategy: NOT_NULL diff --git a/iot-module/iot-generator/src/main/resources/generator.yml b/iot-module/iot-generator/src/main/resources/generator.yml new file mode 100644 index 0000000..aa8b9de --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/generator.yml @@ -0,0 +1,10 @@ +# 代码生成 +gen: + # 作者 + author: iita + # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool + packageName: cc.iotkit.system + # 自动去除表前缀,默认是false + autoRemovePre: false + # 表前缀(生成类名不会包含表前缀,多个用逗号分隔) + tablePrefix: sys_ diff --git a/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml new file mode 100644 index 0000000..14f2d97 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml @@ -0,0 +1,105 @@ + + + + + + + + + + diff --git a/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableMapper.xml b/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableMapper.xml new file mode 100644 index 0000000..57ff795 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableMapper.xml @@ -0,0 +1,309 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iot-module/iot-generator/src/main/resources/mapper/package-info.md b/iot-module/iot-generator/src/main/resources/mapper/package-info.md new file mode 100644 index 0000000..c938b1e --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/mapper/package-info.md @@ -0,0 +1,3 @@ +java包使用 `.` 分割 resource 目录使用 `/` 分割 +
+此文件目的 防止文件夹粘连找不到 `xml` 文件 \ No newline at end of file diff --git a/iot-module/iot-generator/src/main/resources/vm/java/bo.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/bo.java.vm new file mode 100644 index 0000000..291858c --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/bo.java.vm @@ -0,0 +1,52 @@ +package ${packageName}.dto.bo; + +import ${packageName}.model.${ClassName}; +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import javax.validation.constraints.*; +#foreach ($import in $importList) +import ${import}; +#end + +/** + * ${functionName}业务对象 ${tableName} + * + * @author ${author} + * @date ${datetime} + */ +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = ${ClassName}.class, reverseConvertGenerate = false) +public class ${ClassName}Bo extends BaseDto { + +#foreach ($column in $columns) +#if(!$table.isSuperColumn($column.javaField) && ($column.query || $column.insert || $column.edit)) + /** + * $column.columnComment + */ +#if($column.insert && $column.edit) +#set($Group="AddGroup.class, EditGroup.class") +#elseif($column.insert) +#set($Group="AddGroup.class") +#elseif($column.edit) +#set($Group="EditGroup.class") +#end +#if($column.required) +#if($column.javaType == 'String') + @NotBlank(message = "$column.columnComment不能为空", groups = { $Group }) +#else + @NotNull(message = "$column.columnComment不能为空", groups = { $Group }) +#end +#end + @ApiModelProperty(value = "$column.columnComment", required = ${column.required}) + private $column.javaType $column.javaField; + +#end +#end + +} diff --git a/iot-module/iot-generator/src/main/resources/vm/java/controller.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/controller.java.vm new file mode 100644 index 0000000..566b951 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/controller.java.vm @@ -0,0 +1,113 @@ +package ${packageName}.controller; + +import java.util.List; + + +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import javax.servlet.http.HttpServletResponse; +import cn.dev33.satoken.annotation.SaCheckPermission; +import org.springframework.web.bind.annotation.*; +import org.springframework.validation.annotation.Validated; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.excel.utils.ExcelUtil; +import ${packageName}.dto.vo.${ClassName}Vo; +import ${packageName}.dto.bo.${ClassName}Bo; +import ${packageName}.service.I${ClassName}Service; + + +/** + * ${functionName} + * + * @author ${author} + * @date ${datetime} + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/${moduleName}/${businessName}") +public class ${ClassName}Controller extends BaseController { + + private final I${ClassName}Service ${className}Service; + + /** + * 查询${functionName}列表 + */ + @SaCheckPermission("${permissionPrefix}:list") + @PostMapping("/list") + @ApiOperation("查询${functionName}列表") +#if($table.crud || $table.sub) + public Paging<${ClassName}Vo> list( PageRequest<${ClassName}Bo> pageQuery) { + return ${className}Service.queryPageList(pageQuery); + } +#elseif($table.tree) + public List<${ClassName}Vo> list(@RequestBody Request<${ClassName}Bo> query) { + List<${ClassName}Vo> list = ${className}Service.queryList(query.getData()); + return list; + } +#end + + /** + * 导出${functionName}列表 + */ + @ApiOperation("导出${functionName}列表") + @SaCheckPermission("${permissionPrefix}:export") + @Log(title = "${functionName}", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(${ClassName}Bo bo, HttpServletResponse response) { + List<${ClassName}Vo> list = ${className}Service.queryList(bo); + ExcelUtil.exportExcel(list, "${functionName}", ${ClassName}Vo.class, response); + } + + /** + * 获取${functionName}详细信息 + * + */ + @SaCheckPermission("${permissionPrefix}:query") + @PostMapping("/getDetail") + @ApiOperation("获取${functionName}详细信息") + public ${ClassName}Vo getDetail(@Validated @RequestBody Request request) { + return ${className}Service.queryById(request.getData()); + } + + /** + * 新增${functionName} + */ + @SaCheckPermission("${permissionPrefix}:add") + @Log(title = "${functionName}", businessType = BusinessType.INSERT) + @PostMapping(value = "/add") + @ApiOperation("新增${functionName}") + public Long add(@Validated(AddGroup.class) @RequestBody Request<${ClassName}Bo> request) { + return ${className}Service.insertByBo(request.getData()); + } + + /** + * 修改${functionName} + */ + @SaCheckPermission("${permissionPrefix}:edit") + @Log(title = "${functionName}", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + @ApiOperation("修改${functionName}") + public boolean edit(@Validated(EditGroup.class) @RequestBody Request<${ClassName}Bo> request) { + return ${className}Service.updateByBo(request.getData()); + } + + /** + * 删除${functionName} + * + */ + @SaCheckPermission("${permissionPrefix}:remove") + @Log(title = "${functionName}", businessType = BusinessType.DELETE) + @PostMapping("/delete") + @ApiOperation("删除${functionName}") + public boolean remove(@Validated @RequestBody Request> query) { + return ${className}Service.deleteWithValidByIds(query.getData(), true); + } +} diff --git a/iot-module/iot-generator/src/main/resources/vm/java/idata.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/idata.java.vm new file mode 100644 index 0000000..9dcec7e --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/idata.java.vm @@ -0,0 +1,16 @@ +package ${packageName}.data; + +import cc.iotkit.data.ICommonData; +import ${packageName}.model.${ClassName}; +import java.util.List; + +/** + * 数据接口 + * + * @author ${author} + * @date ${datetime} + */ +public interface I${ClassName}Data extends ICommonData<${ClassName}, Long> { + + +} diff --git a/iot-module/iot-generator/src/main/resources/vm/java/idataimpl.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/idataimpl.java.vm new file mode 100644 index 0000000..aa20bb4 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/idataimpl.java.vm @@ -0,0 +1,135 @@ +package ${packageName}.data; + +import ${packageName}.repository.${ClassName}Repository; +import ${packageName}.data.I${ClassName}Data; +import ${packageName}.data.model.Tb${ClassName}; +import ${packageName}.model.${ClassName}; +import java.util.List; +import com.querydsl.core.types.Predicate; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; +import cc.iotkit.data.util.PredicateBuilder; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.StringUtils; +import java.util.Collection; +import java.util.Objects; +import java.util.Optional; +import com.google.common.collect.Lists; + + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.util.PageBuilder; + + +import static ${packageName}.data.model.QTb${ClassName}.tb${ClassName}; +/** + * 数据实现接口 + * + * @author ${author} + * @date ${datetime} + */ +@Primary +@Service +@RequiredArgsConstructor +public class ${ClassName}DataImpl implements I${ClassName}Data { + + private final ${ClassName}Repository baseRepository; + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public Paging<${ClassName}> findAll(PageRequest<${ClassName}> pageRequest) { + return PageBuilder.toPaging(baseRepository.findAll(buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest))).to(${ClassName}.class); + } + + private Predicate buildQueryCondition(${ClassName} bo) { + PredicateBuilder builder = PredicateBuilder.instance(); + if(Objects.nonNull(bo)) { + + #foreach($column in $columns) + #if($column.query) + #set($queryType=$column.queryType) + #set($javaField=$column.javaField) + #set($javaType=$column.javaType) + #set($columnName=$column.columnName) + #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) + #if($queryType != 'BETWEEN') + #if($javaType == 'String') + #set($condition='StringUtils.isNotBlank(bo.get'+$AttrName+'())') + #else + #set($condition='bo.get'+$AttrName+'() != null') + #end + builder.and($condition, () -> tb${ClassName}.${javaField}.eq(bo.get${AttrName}())); + #else + builder.and(params.get("begin$AttrName") != null && params.get("end$AttrName") != null, + () -> tb${ClassName}.${javaField}.bettwen(params.get("begin$AttrName"), params.get("end$AttrName"))); + #end + #end + #end + } + return builder.build(); + } + + @Override + public List<${ClassName}> findByIds(Collection ids) { + List allById = baseRepository.findAllById(ids); + return MapstructUtils.convert(allById, ${ClassName}.class); + } + + @Override + public ${ClassName} save(${ClassName} data) { + Object o = baseRepository.save(MapstructUtils.convert(data, Tb${ClassName}.class)); + return MapstructUtils.convert(o, ${ClassName}.class); + } + + @Override + public void batchSave(List<${ClassName}> data) { + baseRepository.saveAll(MapstructUtils.convert(data, Tb${ClassName}.class)); + } + + @Override + public void deleteById(Long id) { + baseRepository.deleteById(id); + } + + @Override + public void deleteByIds(Collection ids) { + baseRepository.deleteAllById(ids); + } + + @Override + public ${ClassName} findById(Long id) { + Tb${ClassName} ret = jpaQueryFactory.select(tb${ClassName}).from(tb${ClassName}).where(tb${ClassName}.id.eq(id)).fetchOne(); + return MapstructUtils.convert(ret, ${ClassName}.class); + } + + @Override + public long count() { + return baseRepository.count(); + } + + @Override + public List findAll() { + return MapstructUtils.convert(baseRepository.findAll(), IotContributor.class); + } + + @Override + public List findAllByCondition(IotContributor data) { + Iterable all = baseRepository.findAll(buildQueryCondition(data)); + return MapstructUtils.convert(Lists.newArrayList(all), IotContributor.class); + } + + @Override + public IotContributor findOneByCondition(IotContributor data) { + Optional one = baseRepository.findOne(buildQueryCondition(data)); + + if(one.isPresent()){ + return MapstructUtils.convert(one.get(), IotContributor.class); + } + return null; + } +} diff --git a/iot-module/iot-generator/src/main/resources/vm/java/mapper.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/mapper.java.vm new file mode 100644 index 0000000..a367317 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/mapper.java.vm @@ -0,0 +1,15 @@ +package ${packageName}.mapper; + +import ${packageName}.domain.${ClassName}; +import ${packageName}.domain.vo.${ClassName}Vo; +import cc.iotkit.common.mybatis.core.mapper.BaseMapperPlus; + +/** + * ${functionName}Mapper接口 + * + * @author ${author} + * @date ${datetime} + */ +public interface ${ClassName}Mapper extends BaseMapperPlus<${ClassName}, ${ClassName}Vo> { + +} diff --git a/iot-module/iot-generator/src/main/resources/vm/java/model.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/model.java.vm new file mode 100644 index 0000000..6b75cdb --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/model.java.vm @@ -0,0 +1,50 @@ +package ${packageName}.model; + +import cc.iotkit.model.Id; +#foreach ($column in $columns) +#if($column.javaField=='tenantId') +#set($IsTenant=1) +#end +#end +#if($IsTenant==1) +import cc.iotkit.model.TenantModel; +#else +import cc.iotkit.model.BaseModel; +#end +import lombok.Data; +import lombok.EqualsAndHashCode; +#foreach ($import in $importList) +import ${import}; +#end + +import java.io.Serializable; + + +/** + * ${functionName}对象 ${tableName} + * + * @author ${author} + * @date ${datetime} + */ +#if($IsTenant==1) +#set($Entity="TenantModel") +#else +#set($Entity="BaseModel") +#end +@Data +@EqualsAndHashCode(callSuper = true) +public class ${ClassName} extends ${Entity} implements Id, Serializable{ + + private static final long serialVersionUID = 1L; + +#foreach ($column in $columns) +#if(!$table.isSuperColumn($column.javaField)) + /** + * $column.columnComment + */ + private $column.javaType $column.javaField; + +#end +#end + +} diff --git a/iot-module/iot-generator/src/main/resources/vm/java/repository.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/repository.java.vm new file mode 100644 index 0000000..e008721 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/repository.java.vm @@ -0,0 +1,15 @@ +package ${packageName}.data.dao; + +import ${packageName}.data.model.Tb${ClassName}; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; + +/** + * ${functionName}对象 ${tableName} + * + * @author ${author} + * @date ${datetime} + */ +public interface ${ClassName}Repository extends JpaRepository, QuerydslPredicateExecutor { + +} diff --git a/iot-module/iot-generator/src/main/resources/vm/java/service.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/service.java.vm new file mode 100644 index 0000000..d789b77 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/service.java.vm @@ -0,0 +1,53 @@ +package ${packageName}.service; + +import ${packageName}.dto.vo.${ClassName}Vo; +import ${packageName}.dto.bo.${ClassName}Bo; +#if($table.crud || $table.sub) + +#end +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.PageRequest; + +import java.util.Collection; +import java.util.List; + +/** + * ${functionName}Service接口 + * + * @author ${author} + * @date ${datetime} + */ +public interface I${ClassName}Service { + + /** + * 查询${functionName} + */ + ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}); + +#if($table.crud || $table.sub) + /** + * 查询${functionName}列表 + */ + Paging<${ClassName}Vo> queryPageList(PageRequest<${ClassName}Bo> pageQuery); +#end + + /** + * 查询${functionName}列表 + */ + List<${ClassName}Vo> queryList(${ClassName}Bo bo); + + /** + * 新增${functionName} + */ + Long insertByBo(${ClassName}Bo bo); + + /** + * 修改${functionName} + */ + Boolean updateByBo(${ClassName}Bo bo); + + /** + * 校验并批量删除${functionName}信息 + */ + Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid); +} diff --git a/iot-module/iot-generator/src/main/resources/vm/java/serviceImpl.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/serviceImpl.java.vm new file mode 100644 index 0000000..995d4b6 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/serviceImpl.java.vm @@ -0,0 +1,109 @@ +package ${packageName}.service.impl; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +#if($table.crud || $table.sub) +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +#end +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import ${packageName}.dto.bo.${ClassName}Bo; +import ${packageName}.dto.vo.${ClassName}Vo; +import ${packageName}.model.${ClassName}; +import ${packageName}.service.I${ClassName}Service; +import ${packageName}.data.I${ClassName}Data; + +import java.util.List; +import java.util.Collection; +import cc.iotkit.common.exception.BizException; + + +/** + * ${functionName}Service业务层处理 + * + * @author ${author} + * @date ${datetime} + */ +@RequiredArgsConstructor +@Service +public class ${ClassName}ServiceImpl implements I${ClassName}Service { + + private final I${ClassName}Data baseData; + + /** + * 查询${functionName} + */ + @Override + public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}){ + return MapstructUtils.convert(baseData.findById(${pkColumn.javaField}), ${ClassName}Vo.class); + } + +#if($table.crud || $table.sub) + /** + * 查询${functionName}列表 + */ + @Override + public Paging<${ClassName}Vo> queryPageList(PageRequest<${ClassName}Bo> pageQuery) { + Paging<${ClassName}Vo> result = baseData.findAll(pageQuery.to(${ClassName}.class)).to(${ClassName}Vo.class); + return result; + } +#end + + /** + * 查询${functionName}列表 + */ + @Override + public List<${ClassName}Vo> queryList(${ClassName}Bo bo) { + + return MapstructUtils.convert(baseData.findAllByCondition(bo.to(${ClassName}.class)), ${ClassName}Vo.class); + } + + /** + * 新增${functionName} + */ + @Override + public Long insertByBo(${ClassName}Bo bo) { + ${ClassName} add = MapstructUtils.convert(bo, ${ClassName}.class); + validEntityBeforeSave(add); + baseData.save(add); + if (add == null) { + throw new BizException("新增失败"); + } + #set($pk=$pkColumn.javaField.substring(0,1).toUpperCase() + ${pkColumn.javaField.substring(1)}) + return add.get$pk(); + } + + /** + * 修改${functionName} + */ + @Override + public Boolean updateByBo(${ClassName}Bo bo) { + ${ClassName} update = MapstructUtils.convert(bo, ${ClassName}.class); + validEntityBeforeSave(update); + ${ClassName} ret = baseData.save(update); + if(ret == null){ + return false; + } + return true; + } + + /** + * 保存前的数据校验 + */ + private void validEntityBeforeSave(${ClassName} entity){ + //TODO 做一些数据校验,如唯一约束 + } + + /** + * 批量删除${functionName} + */ + @Override + public Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid) { + if(isValid){ + //TODO 做一些业务上的校验,判断是否需要校验 + } + baseData.deleteByIds(ids); + return true; + } +} diff --git a/iot-module/iot-generator/src/main/resources/vm/java/tbmodel.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/tbmodel.java.vm new file mode 100644 index 0000000..0f03e08 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/tbmodel.java.vm @@ -0,0 +1,71 @@ +package ${packageName}.data.model; + +import ${packageName}.model.IotContributor; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.GenericGenerator; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +#foreach ($column in $columns) +#if($column.javaField=='tenantId') +#set($IsTenant=1) +#end +#end +#if($IsTenant==1) +import cc.iotkit.model.TenantModel; +#else +import cc.iotkit.data.model.BaseEntity; +#end +import lombok.Data; +import lombok.EqualsAndHashCode; +#foreach ($import in $importList) +import ${import}; +#end +import javax.persistence.Table; +import javax.persistence.Entity; + +/** + * ${functionName}对象 ${tableName} + * + * @author ${author} + * @date ${datetime} + */ +#if($IsTenant==1) +#set($Entity="TenantEntity") +#else +#set($Entity="BaseEntity") +#end +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "${tableName}") +@AutoMapper(target = ${ClassName}.class) +public class Tb${ClassName} extends ${Entity} { + + + +#foreach ($column in $columns) +#if(!$table.isSuperColumn($column.javaField)) + /** + * $column.columnComment + */ +#if($column.javaField=='delFlag') +#end +#if($column.javaField=='version') +#end +#if($column.isPk==1) + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") +#end + @ApiModelProperty(value = "$column.columnComment") + private $column.javaType $column.javaField; + +#end +#end + +} diff --git a/iot-module/iot-generator/src/main/resources/vm/java/vo.java.vm b/iot-module/iot-generator/src/main/resources/vm/java/vo.java.vm new file mode 100644 index 0000000..06da2d2 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/java/vo.java.vm @@ -0,0 +1,61 @@ +package ${packageName}.dto.vo; + +#foreach ($import in $importList) +import ${import}; +#end +import ${packageName}.model.${ClassName}; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import io.swagger.annotations.ApiModelProperty; + + +import java.io.Serializable; +import java.util.Date; + + + +/** + * ${functionName}视图对象 ${tableName} + * + * @author ${author} + * @date ${datetime} + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = ${ClassName}.class) +public class ${ClassName}Vo implements Serializable { + + + private static final long serialVersionUID = 1L; + +#foreach ($column in $columns) +#if($column.list) + /** + * $column.columnComment + */ +#set($parentheseIndex=$column.columnComment.indexOf("(")) +#if($parentheseIndex != -1) +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) +#else +#set($comment=$column.columnComment) +#end +#if(${column.dictType} && ${column.dictType} != '') + @ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "${column.dictType}") +#elseif($parentheseIndex != -1) + @ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class) + @ExcelDictFormat(readConverterExp = "$column.readConverterExp()") +#else + @ExcelProperty(value = "${comment}") +#end + @ApiModelProperty(value = "${comment}") + private $column.javaType $column.javaField; + +#end +#end + +} diff --git a/iot-module/iot-generator/src/main/resources/vm/js/api.js.vm b/iot-module/iot-generator/src/main/resources/vm/js/api.js.vm new file mode 100644 index 0000000..1df6ef3 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/js/api.js.vm @@ -0,0 +1,47 @@ +import request from '@/utils/request' +import { ${BusinessName}Form, ${BusinessName}Query, ${BusinessName}VO } from './types' + +// 查询${functionName}列表 +export function list${BusinessName}(query: ${BusinessName}Query): AxiosPromise<${BusinessName}VO[]> { + return request({ + url: '/${moduleName}/${businessName}/list', + method: 'post', + params: query + }) +} + +// 查询${functionName}详细 +export function get${BusinessName}(${pkColumn.javaField}: string | number) : AxiosPromise<${BusinessName}VO> { + return request({ + url: '/${moduleName}/${businessName}/getDetail', + method: 'post', + data: ${pkColumn.javaField} + }) +} + +// 新增${functionName} +export function add${BusinessName}(data: ${BusinessName}Form) { + return request({ + url: '/${moduleName}/${businessName}/add', + method: 'post', + data, + }) +} + +// 修改${functionName} +export function update${BusinessName}(data: ${BusinessName}Form) { + return request({ + url: '/${moduleName}/${businessName}/edit', + method: 'post', + data, + }) +} + +// 删除${functionName} +export function del${BusinessName}(${pkColumn.javaField}: Array) { + return request({ + url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, + method: 'post', + data: ${pkColumn.javaField} + }) +} diff --git a/iot-module/iot-generator/src/main/resources/vm/sql/oracle/sql.vm b/iot-module/iot-generator/src/main/resources/vm/sql/oracle/sql.vm new file mode 100644 index 0000000..f6638be --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/sql/oracle/sql.vm @@ -0,0 +1,19 @@ +-- 菜单 SQL +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[0]}, '${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 103, 1, sysdate, null, null, '${functionName}菜单'); + +-- 按钮 SQL +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[1]}, '${functionName}查询', ${table.menuIds[0]}, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 103, 1, sysdate, null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[2]}, '${functionName}新增', ${table.menuIds[0]}, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 103, 1, sysdate, null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[3]}, '${functionName}修改', ${table.menuIds[0]}, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 103, 1, sysdate, null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[4]}, '${functionName}删除', ${table.menuIds[0]}, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 103, 1, sysdate, null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[5]}, '${functionName}导出', ${table.menuIds[0]}, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 103, 1, sysdate, null, null, ''); diff --git a/iot-module/iot-generator/src/main/resources/vm/sql/postgres/sql.vm b/iot-module/iot-generator/src/main/resources/vm/sql/postgres/sql.vm new file mode 100644 index 0000000..0923392 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/sql/postgres/sql.vm @@ -0,0 +1,20 @@ +-- 菜单 SQL +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[0]}, '${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 103, 1, now(), null, null, '${functionName}菜单'); + +-- 按钮 SQL +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[1]}, '${functionName}查询', ${table.menuIds[0]}, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 103, 1, now(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[2]}, '${functionName}新增', ${table.menuIds[0]}, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 103, 1, now(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[3]}, '${functionName}修改', ${table.menuIds[0]}, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 103, 1, now(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[4]}, '${functionName}删除', ${table.menuIds[0]}, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 103, 1, now(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[5]}, '${functionName}导出', ${table.menuIds[0]}, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 103, 1, now(), null, null, ''); + diff --git a/iot-module/iot-generator/src/main/resources/vm/sql/sql.vm b/iot-module/iot-generator/src/main/resources/vm/sql/sql.vm new file mode 100644 index 0000000..01824c2 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/sql/sql.vm @@ -0,0 +1,19 @@ +-- 菜单 SQL +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[0]}, '${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 103, 1, sysdate(), null, null, '${functionName}菜单'); + +-- 按钮 SQL +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[1]}, '${functionName}查询', ${table.menuIds[0]}, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 103, 1, sysdate(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[2]}, '${functionName}新增', ${table.menuIds[0]}, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 103, 1, sysdate(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[3]}, '${functionName}修改', ${table.menuIds[0]}, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 103, 1, sysdate(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[4]}, '${functionName}删除', ${table.menuIds[0]}, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 103, 1, sysdate(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[5]}, '${functionName}导出', ${table.menuIds[0]}, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 103, 1, sysdate(), null, null, ''); diff --git a/iot-module/iot-generator/src/main/resources/vm/sql/sqlserver/sql.vm b/iot-module/iot-generator/src/main/resources/vm/sql/sqlserver/sql.vm new file mode 100644 index 0000000..bdf166e --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/sql/sqlserver/sql.vm @@ -0,0 +1,19 @@ +-- 菜单 SQL +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[0]}, '${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 103, 1, getdate(), null, null, '${functionName}菜单'); + +-- 按钮 SQL +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[1]}, '${functionName}查询', ${table.menuIds[0]}, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 103, 1, getdate(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[2]}, '${functionName}新增', ${table.menuIds[0]}, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 103, 1, getdate(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[3]}, '${functionName}修改', ${table.menuIds[0]}, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 103, 1, getdate(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[4]}, '${functionName}删除', ${table.menuIds[0]}, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 103, 1, getdate(), null, null, ''); + +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values(${table.menuIds[5]}, '${functionName}导出', ${table.menuIds[0]}, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 103, 1, getdate(), null, null, ''); diff --git a/iot-module/iot-generator/src/main/resources/vm/ts/api.ts.vm b/iot-module/iot-generator/src/main/resources/vm/ts/api.ts.vm new file mode 100644 index 0000000..ee309bc --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/ts/api.ts.vm @@ -0,0 +1,48 @@ +import request from '@/utils/request'; +import {AxiosPromise} from 'axios'; +import {${BusinessName}Form, ${BusinessName}Query, ${BusinessName}VO} from './types'; + +// 查询${functionName}列表 +export const list${BusinessName}(query: ${BusinessName}Query): AxiosPromise<${BusinessName}VO[]> { + return request({ + url: '/${moduleName}/${businessName}/list', + method: 'post', + params: query + }) +} + +// 查询${functionName}详细 +export const get${BusinessName}(${pkColumn.javaField}: string | number): AxiosPromise<${BusinessName}VO> { + return request({ + url: '/${moduleName}/${businessName}/getDetail', + method: 'post', + data: ${pkColumn.javaField} + }) +} + +// 新增${functionName} +export const add${BusinessName}(data: ${BusinessName}Form) { + return request({ + url: '/${moduleName}/${businessName}/add', + method: 'post', + data + }) +} + +// 修改${functionName} +export const update${BusinessName}(data: ${BusinessName}Form) { + return request({ + url: '/${moduleName}/${businessName}/edit', + method: 'post', + data: data + }) +} + +// 删除${functionName} +export const del${BusinessName}(${pkColumn.javaField}: Array) { + return request({ + url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, + method: 'post', + data: ${pkColumn.javaField} + }) +} diff --git a/iot-module/iot-generator/src/main/resources/vm/ts/types.ts.vm b/iot-module/iot-generator/src/main/resources/vm/ts/types.ts.vm new file mode 100644 index 0000000..99359e0 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/ts/types.ts.vm @@ -0,0 +1,44 @@ +export interface ${BusinessName}VO { +#foreach ($column in $columns) +#if($column.insert || $column.edit) + /** + * $column.columnComment + */ + $column.javaField:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number; + #elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number; + #elseif($column.javaType == 'Boolean') boolean; + #else string; + #end +#end +#end +} + +export interface ${BusinessName}Form extends BaseEntity { +#foreach ($column in $columns) +#if($column.insert || $column.edit) + /** + * $column.columnComment + */ + $column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number; + #elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number; + #elseif($column.javaType == 'Boolean') boolean; + #else string; + #end +#end +#end +} + +export interface ${BusinessName}Query #if(!${treeCode})extends PageQuery #end{ +#foreach ($column in $columns) +#if($column.query) + /** + * $column.columnComment + */ + $column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number; + #elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number; + #elseif($column.javaType == 'Boolean') boolean; + #else string; + #end +#end +#end +} diff --git a/iot-module/iot-generator/src/main/resources/vm/vue/index-tree.vue.vm b/iot-module/iot-generator/src/main/resources/vm/vue/index-tree.vue.vm new file mode 100644 index 0000000..dbfa4b9 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/vue/index-tree.vue.vm @@ -0,0 +1,501 @@ + + + diff --git a/iot-module/iot-generator/src/main/resources/vm/vue/index.vue.vm b/iot-module/iot-generator/src/main/resources/vm/vue/index.vue.vm new file mode 100644 index 0000000..ace3446 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/vue/index.vue.vm @@ -0,0 +1,467 @@ + + + diff --git a/iot-module/iot-generator/src/main/resources/vm/xml/mapper.xml.vm b/iot-module/iot-generator/src/main/resources/vm/xml/mapper.xml.vm new file mode 100644 index 0000000..9fb48d9 --- /dev/null +++ b/iot-module/iot-generator/src/main/resources/vm/xml/mapper.xml.vm @@ -0,0 +1,7 @@ + + + + + diff --git a/iot-module/iot-manager/pom.xml b/iot-module/iot-manager/pom.xml new file mode 100644 index 0000000..f50cc9c --- /dev/null +++ b/iot-module/iot-manager/pom.xml @@ -0,0 +1,142 @@ + + + + iot-module + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-manager + + + + + + cc.iotkit + iot-data-model + + + + cc.iotkit + iot-common-core + + + + cc.iotkit + iot-rule-engine + + + + + + + + + cc.iotkit + iot-virtual-device + + + + cc.iotkit + iot-message-core + + + + cc.iotkit + iot-common-oss + + + + cc.iotkit + iot-common-websocket + + + + cc.iotkit + iot-temporal-service + + + + cc.iotkit + iot-data-serviceImpl-rdb + + + + cc.iotkit + iot-data-serviceImpl-cache + + + + cc.iotkit + iot-common-web + + + + cc.iotkit + iot-common-doc + + + cc.iotkit + iot-common-satoken + + + + cc.iotkit + iot-common-excel + + + cc.iotkit + iot-common-log + + + + + + org.springframework.boot + spring-boot-starter-web + + + + io.github.linpeilie + mapstruct-plus-spring-boot-starter + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + utf8 + + + org.projectlombok + lombok + ${lombok.version} + + + io.github.linpeilie + mapstruct-plus-processor + ${mapstruct-plus.version} + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + + + + + + + diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/AliyunConfig.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/AliyunConfig.java new file mode 100644 index 0000000..9d6129a --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/AliyunConfig.java @@ -0,0 +1,42 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.config; + + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "aliyun") +@Data +public class AliyunConfig { + + private String bucketId; + + private String endpoint; + + private String accessKeyId; + + private String accessKeySecret; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/AutoMapperConfig2.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/AutoMapperConfig2.java new file mode 100644 index 0000000..2d6c955 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/AutoMapperConfig2.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.config; + +import io.github.linpeilie.annotations.MapperConfig; + +/** + * @Author: jay + * @Date: 2023/6/4 14:21 + * @Version: V1.0 + * @Description: mapperstruct 配置 + */ +@MapperConfig( adapterClassName = "managerAdapter") +public class AutoMapperConfig2 { +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/BeanUtils.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/BeanUtils.java new file mode 100644 index 0000000..8deec2e --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/BeanUtils.java @@ -0,0 +1,52 @@ +package cc.iotkit.manager.config; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.db.PageResult; + +import java.util.List; +import java.util.function.Consumer; + +public class BeanUtils { + + public static T toBean(Object source, Class targetClass) { + return BeanUtil.toBean(source, targetClass); + } + + public static T toBean(Object source, Class targetClass, Consumer peek) { + T target = toBean(source, targetClass); + if (target != null) { + peek.accept(target); + } + return target; + } + + public static List toBean(List source, Class targetType) { + if (source == null) { + return null; + } + return CollectionUtils.convertList(source, s -> toBean(s, targetType)); + } + + public static List toBean(List source, Class targetType, Consumer peek) { + List list = toBean(source, targetType); + if (list != null) { + list.forEach(peek); + } + return list; + } + + /* public static PageResult toBean(PageResult source, Class targetType) { + return toBean(source, targetType, null); + } + + public static PageResult toBean(PageResult source, Class targetType, Consumer peek) { + if (source == null) { + return null; + } + List list = toBean(source.getList(), targetType); + if (peek != null) { + list.forEach(peek); + } + return new PageResult<>(list, source.getTotal()); + }*/ +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/CollectionUtils.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/CollectionUtils.java new file mode 100644 index 0000000..cdf4117 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/CollectionUtils.java @@ -0,0 +1,315 @@ +package cc.iotkit.manager.config; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ArrayUtil; + +import java.util.*; +import java.util.function.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static java.util.Arrays.asList; + +public class CollectionUtils { + public static boolean containsAny(Object source, Object... targets) { + return asList(targets).contains(source); + } + + public static boolean isAnyEmpty(Collection... collections) { + return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty); + } + + public static boolean anyMatch(Collection from, Predicate predicate) { + return from.stream().anyMatch(predicate); + } + + public static List filterList(Collection from, Predicate predicate) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return from.stream().filter(predicate).collect(Collectors.toList()); + } + + public static List distinct(Collection from, Function keyMapper) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return distinct(from, keyMapper, (t1, t2) -> t1); + } + + public static List distinct(Collection from, Function keyMapper, BinaryOperator cover) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return new ArrayList<>(convertMap(from, keyMapper, Function.identity(), cover).values()); + } + + public static List convertList(T[] from, Function func) { + if (ArrayUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return convertList(Arrays.asList(from), func); + } + + public static List convertList(Collection from, Function func) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return from.stream().map(func).filter(Objects::nonNull).collect(Collectors.toList()); + } + + public static List convertList(Collection from, Function func, Predicate filter) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return from.stream().filter(filter).map(func).filter(Objects::nonNull).collect(Collectors.toList()); + } + + public static List convertListByFlatMap(Collection from, + Function> func) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return from.stream().filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toList()); + } + + public static List convertListByFlatMap(Collection from, + Function mapper, + Function> func) { + if (CollUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return from.stream().map(mapper).filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toList()); + } + + public static List mergeValuesFromMap(Map> map) { + return map.values() + .stream() + .flatMap(List::stream) + .collect(Collectors.toList()); + } + + public static Set convertSet(Collection from) { + return convertSet(from, v -> v); + } + + public static Set convertSet(Collection from, Function func) { + if (CollUtil.isEmpty(from)) { + return new HashSet<>(); + } + return from.stream().map(func).filter(Objects::nonNull).collect(Collectors.toSet()); + } + + public static Set convertSet(Collection from, Function func, Predicate filter) { + if (CollUtil.isEmpty(from)) { + return new HashSet<>(); + } + return from.stream().filter(filter).map(func).filter(Objects::nonNull).collect(Collectors.toSet()); + } + + public static Map convertMapByFilter(Collection from, Predicate filter, Function keyFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return from.stream().filter(filter).collect(Collectors.toMap(keyFunc, v -> v)); + } + + public static Set convertSetByFlatMap(Collection from, + Function> func) { + if (CollUtil.isEmpty(from)) { + return new HashSet<>(); + } + return from.stream().filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet()); + } + + public static Set convertSetByFlatMap(Collection from, + Function mapper, + Function> func) { + if (CollUtil.isEmpty(from)) { + return new HashSet<>(); + } + return from.stream().map(mapper).filter(Objects::nonNull).flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet()); + } + + public static Map convertMap(Collection from, Function keyFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return convertMap(from, keyFunc, Function.identity()); + } + + public static Map convertMap(Collection from, Function keyFunc, Supplier> supplier) { + if (CollUtil.isEmpty(from)) { + return supplier.get(); + } + return convertMap(from, keyFunc, Function.identity(), supplier); + } + + public static Map convertMap(Collection from, Function keyFunc, Function valueFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return convertMap(from, keyFunc, valueFunc, (v1, v2) -> v1); + } + + public static Map convertMap(Collection from, Function keyFunc, Function valueFunc, BinaryOperator mergeFunction) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return convertMap(from, keyFunc, valueFunc, mergeFunction, HashMap::new); + } + + public static Map convertMap(Collection from, Function keyFunc, Function valueFunc, Supplier> supplier) { + if (CollUtil.isEmpty(from)) { + return supplier.get(); + } + return convertMap(from, keyFunc, valueFunc, (v1, v2) -> v1, supplier); + } + + public static Map convertMap(Collection from, Function keyFunc, Function valueFunc, BinaryOperator mergeFunction, Supplier> supplier) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return from.stream().collect(Collectors.toMap(keyFunc, valueFunc, mergeFunction, supplier)); + } + + public static Map> convertMultiMap(Collection from, Function keyFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return from.stream().collect(Collectors.groupingBy(keyFunc, Collectors.mapping(t -> t, Collectors.toList()))); + } + + public static Map> convertMultiMap(Collection from, Function keyFunc, Function valueFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return from.stream() + .collect(Collectors.groupingBy(keyFunc, Collectors.mapping(valueFunc, Collectors.toList()))); + } + + // 暂时没想好名字,先以 2 结尾噶 + public static Map> convertMultiMap2(Collection from, Function keyFunc, Function valueFunc) { + if (CollUtil.isEmpty(from)) { + return new HashMap<>(); + } + return from.stream().collect(Collectors.groupingBy(keyFunc, Collectors.mapping(valueFunc, Collectors.toSet()))); + } + + /* public static Map convertImmutableMap(Collection from, Function keyFunc) { + if (CollUtil.isEmpty(from)) { + return Collections.emptyMap(); + } + ImmutableMap.Builder builder = ImmutableMap.builder(); + from.forEach(item -> builder.put(keyFunc.apply(item), item)); + return builder.build(); + }*/ + + /** + * 对比老、新两个列表,找出新增、修改、删除的数据 + * + * @param oldList 老列表 + * @param newList 新列表 + * @param sameFunc 对比函数,返回 true 表示相同,返回 false 表示不同 + * 注意,same 是通过每个元素的“标识”,判断它们是不是同一个数据 + * @return [新增列表、修改列表、删除列表] + */ + public static List> diffList(Collection oldList, Collection newList, + BiFunction sameFunc) { + List createList = new LinkedList<>(newList); // 默认都认为是新增的,后续会进行移除 + List updateList = new ArrayList<>(); + List deleteList = new ArrayList<>(); + + // 通过以 oldList 为主遍历,找出 updateList 和 deleteList + for (T oldObj : oldList) { + // 1. 寻找是否有匹配的 + T foundObj = null; + for (Iterator iterator = createList.iterator(); iterator.hasNext(); ) { + T newObj = iterator.next(); + // 1.1 不匹配,则直接跳过 + if (!sameFunc.apply(oldObj, newObj)) { + continue; + } + // 1.2 匹配,则移除,并结束寻找 + iterator.remove(); + foundObj = newObj; + break; + } + // 2. 匹配添加到 updateList;不匹配则添加到 deleteList 中 + if (foundObj != null) { + updateList.add(foundObj); + } else { + deleteList.add(oldObj); + } + } + return asList(createList, updateList, deleteList); + } + + public static boolean containsAny(Collection source, Collection candidates) { + return org.springframework.util.CollectionUtils.containsAny(source, candidates); + } + + public static T getFirst(List from) { + return !CollectionUtil.isEmpty(from) ? from.get(0) : null; + } + + public static T findFirst(Collection from, Predicate predicate) { + return findFirst(from, predicate, Function.identity()); + } + + public static U findFirst(Collection from, Predicate predicate, Function func) { + if (CollUtil.isEmpty(from)) { + return null; + } + return from.stream().filter(predicate).findFirst().map(func).orElse(null); + } + + public static > V getMaxValue(Collection from, Function valueFunc) { + if (CollUtil.isEmpty(from)) { + return null; + } + assert !from.isEmpty(); // 断言,避免告警 + T t = from.stream().max(Comparator.comparing(valueFunc)).get(); + return valueFunc.apply(t); + } + + public static > V getMinValue(List from, Function valueFunc) { + if (CollUtil.isEmpty(from)) { + return null; + } + assert from.size() > 0; // 断言,避免告警 + T t = from.stream().min(Comparator.comparing(valueFunc)).get(); + return valueFunc.apply(t); + } + + public static > V getSumValue(List from, Function valueFunc, + BinaryOperator accumulator) { + return getSumValue(from, valueFunc, accumulator, null); + } + + public static > V getSumValue(Collection from, Function valueFunc, + BinaryOperator accumulator, V defaultValue) { + if (CollUtil.isEmpty(from)) { + return defaultValue; + } + assert !from.isEmpty(); // 断言,避免告警 + return from.stream().map(valueFunc).filter(Objects::nonNull).reduce(accumulator).orElse(defaultValue); + } + + public static void addIfNotNull(Collection coll, T item) { + if (item == null) { + return; + } + coll.add(item); + } + + public static Collection singleton(T obj) { + return obj == null ? Collections.emptyList() : Collections.singleton(obj); + } + + public static List newArrayList(List> list) { + return list.stream().flatMap(Collection::stream).collect(Collectors.toList()); + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/TimestampIdentifierGenerator.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/TimestampIdentifierGenerator.java new file mode 100644 index 0000000..98bb4f6 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/config/TimestampIdentifierGenerator.java @@ -0,0 +1,44 @@ +package cc.iotkit.manager.config; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.extra.spring.SpringUtil; +import org.springframework.data.redis.core.RedisTemplate; + +public class TimestampIdentifierGenerator { + + /** + * 生成一个8位的数字标识符,基于当前时间戳。 + * 注意:这种方法并不能保证绝对的唯一性,特别是在高并发的情况下。 + * + * @return 一个8位的数字标识符。 + */ + public static String generateIdentifier(String key) { + //利用redis进行自增ID + RedisTemplate redisTemplate = SpringUtil.getBean("stringRedisTemplate"); + if (ObjectUtil.isEmpty(redisTemplate.opsForValue().get(key))) { + // 获取当前日期并格式化为 yyyyMMdd + // String formattedDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); + // 定义增量值 + long currentSeconds = System.currentTimeMillis() / 1000; + + long incrementValue = 10000000; + // 拼接字符串 + String resultString = currentSeconds + String.format("%07d", incrementValue); // 确保增量值是7位数,前面补零 + // 将拼接后的字符串转换为 long 类型 + long result = Long.parseLong(resultString); + + // LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); + redisTemplate.opsForValue().increment(key, result); + return redisTemplate.opsForValue().get(key).toString(); + } else { + redisTemplate.opsForValue().increment(key); + return redisTemplate.opsForValue().get(key).toString(); + } + + } + + public static String getIdCreateWorderNum() { + return generateIdentifier("getIdCreateWorderNum"); + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/AlertController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/AlertController.java new file mode 100644 index 0000000..a6cf26d --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/AlertController.java @@ -0,0 +1,90 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.manager.service.AlertService; +import cc.iotkit.model.alert.AlertConfig; +import cc.iotkit.model.alert.AlertRecord; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@Api(tags = {"告警中心"}) +@Slf4j +@RestController +@RequestMapping("/alert") +public class AlertController { + + @Autowired + private AlertService alertService; + + + @ApiOperation("新增告警中心配置") + @SaCheckPermission("iot:alertConfig:add") + @PostMapping("/createAlertConfig") + public AlertConfig createAlertConfig(@RequestBody @Validated Request request) { + return alertService.createAlertConfig(request.getData()); + } + + @ApiOperation("编辑告警中心配置") + @SaCheckPermission("iot:alertConfig:edit") + @PostMapping("/updateAlertConfig") + public AlertConfig updateAlertConfig(@RequestBody @Validated Request request) { + return alertService.updateAlertConfig(request.getData()); + } + + @ApiOperation("删除告警中心配置") + @SaCheckPermission("iot:alertConfig:remove") + @PostMapping("/deleteAlertConfigById") + public void deleteAlertConfigById(@RequestBody @Validated Request request) { + alertService.deleteAlertConfigById(request.getData()); + } + + @ApiOperation("查询告警中心配置分页") + @SaCheckPermission("iot:alertConfig:query") + @PostMapping("/selectAlertConfigPage") + public Paging selectAlertConfigPage(@RequestBody @Validated PageRequest request) { + return alertService.selectAlertConfigPage(request); + } + + + @ApiOperation("查询告警消息分页") + @SaCheckPermission("iot:alert:query") + @PostMapping("/selectAlertRecordPage") + public Paging selectAlertRecordPage(@RequestBody @Validated PageRequest request) { + return alertService.selectAlertRecordPage(request); + } + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/DeviceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/DeviceController.java new file mode 100644 index 0000000..9369c86 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/DeviceController.java @@ -0,0 +1,381 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.api.Response; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.manager.dto.bo.device.*; +import cc.iotkit.manager.dto.bo.deviceconfig.DeviceConfigAddBo; +import cc.iotkit.manager.dto.bo.devicegroup.DeviceAddGroupBo; +import cc.iotkit.manager.dto.bo.devicegroup.DeviceGroupBo; +import cc.iotkit.manager.dto.bo.thingmodel.ThingModelMessageBo; +import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo; +import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupImportVo; +import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo; +import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoImportVo; +import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo; +import cc.iotkit.manager.dto.vo.deviceinfo.ParentDeviceVo; +import cc.iotkit.manager.dto.vo.thingmodel.ThingModelVo; +import cc.iotkit.manager.service.DeviceCtrlService; +import cc.iotkit.manager.service.IDeviceManagerService; +import cc.iotkit.manager.service.IProductService; +import cc.iotkit.model.InvokeResult; +import cc.iotkit.model.device.DeviceConfig; +import cc.iotkit.model.device.DeviceGroup; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DeviceProperty; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.util.IdUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.async.DeferredResult; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.List; + +@Api(tags = {"设备"}) +@Slf4j +@RestController +@RequestMapping("/device") +public class DeviceController { + + + @Autowired + IProductService productService; + + @Autowired + private DeviceCtrlService deviceCtrlService; + @Autowired + private IDeviceManagerService deviceServiceImpl; + + + @ApiOperation(value = "服务调用", notes = "服务调用", httpMethod = "POST") + @SaCheckPermission("iot:device:ctrl") + @PostMapping("/service/invoke") + public InvokeResult invokeService(@RequestBody @Validated Request request) { + return new InvokeResult(deviceCtrlService.invokeService(request.getData().getDeviceId(), request.getData().getService(), request.getData().getArgs())); + } + + @ApiOperation(value = "属性获取", notes = "属性获取", httpMethod = "POST") + @SaCheckPermission("iot:device:ctrl") + @PostMapping("/service/property/get") + public InvokeResult invokeServicePropertySet(@RequestBody @Validated Request request) { + return new InvokeResult(deviceCtrlService.getProperty(request.getData().getDeviceId(), request.getData().getPropertyNames(), true)); + } + + @ApiOperation(value = "属性设置", notes = "属性设置", httpMethod = "POST") + @SaCheckPermission("iot:device:ctrl") + @PostMapping("/service/property/set") + public InvokeResult setProperty(@RequestBody @Validated Request request) { + return new InvokeResult(deviceCtrlService.setProperty(request.getData().getDeviceId(), request.getData().getArgs())); + } + + @ApiOperation(value = "设备列表", notes = "设备列表", httpMethod = "POST") + @SaCheckPermission("iot:device:query") + @PostMapping("/list") + public Paging getDevices(@Validated @RequestBody PageRequest pageRequest) { + return deviceServiceImpl.getDevices(pageRequest); + } + + @ApiOperation(value = "创建设备") + @SaCheckPermission("iot:device:add") + @PostMapping("/add") + public boolean createDevice(@RequestBody @Validated Request bo) { + return deviceServiceImpl.addDevice(bo.getData()); + } + + @ApiOperation(value = "保存设备") + @SaCheckPermission("iot:device:edit") + @PostMapping("/save") + public boolean saveDevice(@RequestBody @Validated Request bo) { + return deviceServiceImpl.saveDevice(bo.getData()); + } + + @ApiOperation(value = "获取子设备", notes = "获取子设备") + @SaCheckPermission("iot:device:query") + @PostMapping("/children/list") + public List getChildren(@Validated @RequestBody PageRequest request) { + String deviceId = request.getData(); + return deviceServiceImpl.selectChildrenPageList(deviceId); + } + + @ApiOperation("获取网关设备") + @SaCheckPermission("iot:device:query") + @PostMapping("/getParentDevices") + public List getParentDevices() { + return deviceServiceImpl.getParentDevices(); + } + + @ApiOperation("获取设备详情") + @SaCheckPermission("iot:device:query") + @PostMapping("/detail") + public DeviceInfo getDetail(@RequestBody @Validated Request request) { + return deviceServiceImpl.getDetail(request.getData()); + } + + @ApiOperation("获取设备详情") + @SaCheckPermission("iot:device:query") + @PostMapping("/getByPkDn") + public DeviceInfo getByPkDn(@Validated @RequestBody Request query) { + return deviceServiceImpl.getByPkDn(query.getData().getPk(), query.getData().getDn()); + } + + @ApiOperation("删除设备") + @SaCheckPermission("iot:device:remove") + @PostMapping("/delete") + public boolean deleteDevice(@Validated @RequestBody Request request) { + return deviceServiceImpl.deleteDevice(request.getData()); + } + + @ApiOperation("批量删除设备") + @SaCheckPermission("iot:device:remove") + @PostMapping("/batchDelete") + public boolean batchDelete(@Validated @RequestBody Request> request) { + return deviceServiceImpl.batchDeleteDevice(request.getData()); + } + + + /** + * 导入设备-批量添加设备 + */ + @ApiOperation(value = "导入设备") + @SaCheckPermission("iot:device:add") + @PostMapping("/importData") + public Response importDevice(@RequestPart("file") MultipartFile file, @RequestParam("requestId") String requestId) { + return new Response(200, deviceServiceImpl.importDevice(file), null, requestId); + } + + /** + * 获取导入设备模板 + */ + @ApiOperation("下载设备模板") + @PostMapping("/exportData") + public void exportDeviceTemplate(HttpServletResponse response) { + ExcelUtil.exportExcel(new ArrayList<>(), "设备分组", DeviceInfoImportVo.class, response); + } + + @ApiOperation("设备物模型日志") + @SaCheckPermission("iot:deviceLog:query") + @PostMapping("/deviceLogs/list") + public Paging logs(@Validated(QueryGroup.class) @RequestBody PageRequest request) { + return deviceServiceImpl.logs(request); + } + + @ApiOperation("获取设备属性历史数据") + @SaCheckPermission("iot:deviceLog:query") + @PostMapping("/deviceProperty/log/list") + public List getPropertyHistory(@Validated @RequestBody + Request query) { + DevicePropertyLogQueryBo data = query.getData(); + String deviceId = data.getDeviceId(); + String name = data.getName(); + long start = data.getStart(); + long end = data.getEnd(); + return deviceServiceImpl.getPropertyHistory(deviceId, name, start, end, 10000); + } + + @ApiOperation("设备解绑") + @SaCheckPermission("iot:device:edit") + @PostMapping("/unbind") + public boolean unbindDevice(@Validated @RequestBody Request request) { + return deviceServiceImpl.unbindDevice(request.getData()); + } + + @ApiOperation("获取设备物模型") + @SaCheckPermission("iot:thingModel:query") + @PostMapping("/getThingModel") + public ThingModelVo getThingModel(@Validated @RequestBody Request request) { + String deviceId = request.getData(); + DeviceInfo deviceInfo = deviceServiceImpl.getDetail(deviceId); + return productService.getThingModelByProductKey(deviceInfo.getProductKey()); + } + + @ApiOperation("添加标签") + @SaCheckPermission("iot:device:edit") + @PostMapping("/tag/add") + public boolean addTag(@Validated @RequestBody Request bo) { + return deviceServiceImpl.addTag(bo.getData()); + } + + @ApiOperation("模拟设备上报") + @SaCheckPermission("iot:device:query") + @PostMapping("/simulateSend") + public boolean simulateSend( + @Validated @RequestBody Request bo) { + ThingModelMessage message = bo.getData().to(ThingModelMessage.class); + return deviceServiceImpl.simulateSend(message); + } + + /** + * 消费设备信息消息(实时推送设备信息) + */ + @ApiOperation("消费设备信息消息(实时推送设备信息)") + @SaCheckPermission("iot:device:query") + @PostMapping("/consumer") + public DeferredResult consumerDeviceInfo( + @Validated @RequestBody Request bo + ) { + DeviceConsumerBo data = bo.getData(); + return deviceServiceImpl.addConsumer(data.getDeviceId(), data.getClientId()); + } + + /** + * 获取分组列表 + */ + @ApiOperation(value = "获取分组列表") + @SaCheckPermission("iot:deviceGroup:query") + @PostMapping("/groups/list") + public Paging getDeviceGroups( + @Validated @RequestBody PageRequest pageRequest) { + return deviceServiceImpl.selectGroupPageList(pageRequest); + } + + /** + * 添加设备分组 + */ + @ApiOperation(value = "添加设备分组") + @SaCheckPermission("iot:deviceGroup:add") + @PostMapping("/group/add") + public boolean addGroup(@Validated @RequestBody Request group) { + return deviceServiceImpl.addGroup(group.getData().to(DeviceGroup.class)); + } + + + /** + * 导入设备分组-批量添加设备分组 + */ + @ApiOperation(value = "导入设备分组") + @SaCheckPermission("iot:deviceGroup:add") + @PostMapping("/group/importData") + public Response importGroup(@RequestPart("file") MultipartFile file, @RequestParam("requestId") String requestId) { + return new Response(200, deviceServiceImpl.importGroup(file), null, requestId); + } + + /** + * 获取导入模板 + */ + @ApiOperation("下载设备分组模板") + @PostMapping("/group/exportData") + public void exportGroupTemplate(HttpServletResponse response) { + ExcelUtil.exportExcel(new ArrayList<>(), "设备分组", DeviceGroupImportVo.class, response); + } + + /** + * 修改设备分组 + */ + @ApiOperation(value = "修改设备分组") + @SaCheckPermission("iot:deviceGroup:edit") + @PostMapping("/group/edit") + public boolean editGroup(@RequestBody @Validated Request bo) { + return deviceServiceImpl.updateGroup(bo.getData()); + + } + + /** + * 删除分组 + */ + @ApiOperation(value = "删除分组") + @SaCheckPermission("iot:deviceGroup:remove") + @PostMapping("/group/delete") + public boolean deleteGroup(@Validated @RequestBody Request request) { + String id = request.getData(); + return deviceServiceImpl.deleteGroup(id); + } + + /** + * 清空组下所有设备 + */ + @ApiOperation(value = "清空组下所有设备") + @SaCheckPermission("iot:deviceGroup:remove") + @PostMapping("/group/clear") + public boolean clearGroup(@Validated @RequestBody Request request) { + String id = request.getData(); + return deviceServiceImpl.clearGroup(id); + } + + /** + * 添加设备到组 + */ + @ApiOperation(value = "添加设备到组") + @SaCheckPermission("iot:deviceGroup:edit") + @PostMapping("/group/addDevices") + public boolean addToGroup(@Validated @RequestBody Request bo) { + return deviceServiceImpl.addDevice2Group(bo.getData()); + } + + /** + * 将设备从组中移除 + */ + @ApiOperation(value = "将设备从组中移除") + @SaCheckPermission("iot:deviceGroup:edit") + @PostMapping("/group/removeDevices") + public boolean removeDevices(@Validated @RequestBody Request bo) { + DeviceAddGroupBo data = bo.getData(); + return deviceServiceImpl.removeDevices(data.getGroup(), data.getDevices()); + } + + /** + * 保存设备配置 + */ + @ApiOperation(value = "保存设备配置") + @SaCheckPermission("iot:device:edit") + @PostMapping("/config/save") + public boolean saveConfig(@Validated @RequestBody Request request) { + DeviceConfig data = request.getData().to(DeviceConfig.class); + return deviceServiceImpl.saveConfig(data); + } + + /** + * 获取设备配置 + */ + @ApiOperation(value = "获取设备配置") + @SaCheckPermission("iot:device:query") + @PostMapping("/config/get") + public DeviceConfigVo getConfig(@Validated @RequestBody Request request) { + String deviceId = request.getData(); + return deviceServiceImpl.getConfig(deviceId); + } + + /** + * 设备配置下发 + */ + @ApiOperation(value = "设备配置下发") + @SaCheckPermission("iot:device:ctrl") + @PostMapping("/config/send") + public InvokeResult sendConfig(@Validated @RequestBody Request bo) { + String deviceId = bo.getData(); + return new InvokeResult(deviceCtrlService.sendConfig(deviceId)); + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/FeedBackEvaluationController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/FeedBackEvaluationController.java new file mode 100644 index 0000000..8aebd9b --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/FeedBackEvaluationController.java @@ -0,0 +1,102 @@ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.api.Response; +import cc.iotkit.manager.config.BeanUtils; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationPageReqVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationRespVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationSaveReqVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationVO; +import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordListSaveReqVO; +import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordPageReqVO; +import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordRespVO; +import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordSaveReqVO; +import cc.iotkit.manager.service.DIccidRecordService; +import cc.iotkit.manager.service.FeedBackEvaluationService; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import cc.iotkit.model.iccid.DIccidRecordDO; +import cn.hutool.db.PageResult; +import io.swagger.annotations.Api; +import lombok.extern.slf4j.Slf4j; +import org.hibernate.annotations.Parameter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.List; + +import static cc.iotkit.common.api.Response.success; + +@Api(tags = {"反馈意见"}) +@Slf4j +@RestController +@RequestMapping("/dFeedbackEvaluation") +public class FeedBackEvaluationController { + + + @Autowired + private FeedBackEvaluationService feedBackEvaluationService; + + @PostMapping("/add") + //@Operation(summary = "创建意见反馈评价") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:create')") + public Long createFeedBackEvaluation(@Valid @RequestBody Request createReqVO) { + return feedBackEvaluationService.createFeedBackEvaluation(createReqVO.getData()); + } + + @PostMapping("/edit") + //@Operation(summary = "更新意见反馈评价") + // @PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:update')") + public Boolean updateFeedBackEvaluation(@Valid @RequestBody Request updateReqVO) { + feedBackEvaluationService.updateFeedBackEvaluation(updateReqVO.getData()); + return true; + } + + @PostMapping("/delete") + //@Operation(summary = "删除意见反馈评价") + //@Parameter(name = "id", description = "编号", required = true) + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:delete')") + public boolean deleteFeedBackEvaluation(@Validated @RequestBody Request request) { + feedBackEvaluationService.deleteFeedBackEvaluation(request.getData()); + return true; + } + + @PostMapping("/getDetail") + //@Operation(summary = "获得意见反馈评价") + //@Parameter(name = "id", description = "编号", required = true, example = "1024") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')") + public FeedBackEvaluationDO getFeedBackEvaluation(@Validated @RequestBody Request request) { + FeedBackEvaluationDO feedBackEvaluation = feedBackEvaluationService.getFeedBackEvaluation(request.getData()); + return feedBackEvaluation; + } + + @PostMapping("/list") + //@Operation(summary = "获得意见反馈评价分页") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')") + public Paging getFeedBackEvaluationPage(@RequestBody @Validated PageRequest pageReqVO) { + Paging pageResult = feedBackEvaluationService.getFeedBackEvaluationPage(pageReqVO); + return pageResult; + } + + /* @GetMapping("/export-excel") + @Operation(summary = "导出意见反馈评价 Excel") + @PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportFeedBdackEvaluationExcel(@Valid FeedBackEvaluationPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = feedBackEvaluationService.getFeedBackEvaluationPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "意见反馈评价.xls", "数据", FeedBackEvaluationRespVO.class, + BeanUtils.toBean(list, FeedBackEvaluationRespVO.class)); + }*/ + + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/IccidRecordController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/IccidRecordController.java new file mode 100644 index 0000000..913649a --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/IccidRecordController.java @@ -0,0 +1,91 @@ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.manager.config.BeanUtils; + +import cc.iotkit.manager.dto.bo.device.DeviceInfoBo; +import cc.iotkit.manager.dto.bo.taskinfo.TaskInfoBo; +import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordListSaveReqVO; +import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordPageReqVO; +import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordRespVO; +import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordSaveReqVO; +import cc.iotkit.manager.service.DIccidRecordService; +import cc.iotkit.model.iccid.DIccidRecordDO; +import cn.hutool.db.PageResult; +import io.swagger.annotations.Api; +import lombok.extern.slf4j.Slf4j; +import org.hibernate.annotations.Parameter; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import java.util.List; + +import static cc.iotkit.common.api.Response.success; + +@Api(tags = {"物联网iccid管理"}) +@Slf4j +@RestController +@RequestMapping("/dIccidRecord") +public class IccidRecordController { + + + @Resource + private DIccidRecordService dIccidRecordService; + + @PostMapping("/add") + // @Operation(summary = "录入物联网卡") + // @PreAuthorize("@ss.hasPermission('dIccidrecord:D-iccid-record:create')") + public String createDIccidRecord(@Valid @RequestBody Request createReqVO) { + return dIccidRecordService.createDIccidRecord(createReqVO.getData()); + } + @PostMapping("/createList") + // @Operation(summary = "批量录入物联网卡") + // @PreAuthorize("@ss.hasPermission('dIccidrecord:D-iccid-record:create')") + public String createList(@Valid @RequestBody Request createReqVO + ) { + Integer num =createReqVO.getData().getEndIccid()-createReqVO.getData().getStartIccid(); + return dIccidRecordService.createList(createReqVO.getData(),num); + } + + @PostMapping("/edit") + // @Operation(summary = "更新物联网卡") + // @PreAuthorize("@ss.hasPermission('dIccidrecord:D-iccid-record:update')") + public Boolean updateDIccidRecord(@Valid @RequestBody Request updateReqVO) { + dIccidRecordService.updateDIccidRecord(updateReqVO.getData()); + return true; + } + + @PostMapping("/delete") + // @Operation(summary = "删除物联网卡") + // @Parameter(name = "id", description = "编号", required = true) + // @PreAuthorize("@ss.hasPermission('dIccidrecord:D-iccid-record:delete')") + public Boolean deleteDIccidRecord(@Validated @RequestBody Request request) { + dIccidRecordService.deleteDIccidRecord(request.getData()); + return true; + } + + @PostMapping("/getDetail") + // @Operation(summary = "获得物联网卡") + // @Parameter(name = "id", description = "编号", required = true, example = "1024") + // @PreAuthorize("@ss.hasPermission('dIccidrecord:D-iccid-record:query')") + public DIccidRecordDO getDIccidRecord(@Validated @RequestBody Request request) { + DIccidRecordDO dIccidRecord = dIccidRecordService.getDIccidRecord(request.getData()); + return dIccidRecord; + } + + @PostMapping("/list") + // @Operation(summary = "获得物联网卡分页") + public Paging getDIccidRecordPage( @Validated @RequestBody PageRequest pageReqVO) { + Paging pageResult = dIccidRecordService.getDIccidRecordPage(pageReqVO); + + return pageResult; + } + + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/NotifyController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/NotifyController.java new file mode 100644 index 0000000..d68ae5b --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/NotifyController.java @@ -0,0 +1,158 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.manager.dto.bo.channel.ChannelConfigBo; +import cc.iotkit.manager.dto.bo.channel.ChannelTemplateBo; +import cc.iotkit.manager.dto.vo.channel.ChannelConfigVo; +import cc.iotkit.manager.dto.vo.channel.ChannelTemplateVo; +import cc.iotkit.manager.service.NotifyService; +import cc.iotkit.model.notify.Channel; +import cc.iotkit.model.notify.ChannelConfig; +import cc.iotkit.model.notify.ChannelTemplate; +import cc.iotkit.model.notify.NotifyMessage; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +/** + * author: 石恒 + * date: 2023-05-11 15:17 + * description: + **/ +@Api(tags = {"消息通知"}) +@Slf4j +@RestController +@RequestMapping("/notify") +public class NotifyController { + + @Resource + private NotifyService notifyService; + + @ApiOperation("获取通道类型列表") + @SaCheckPermission("iot:channel:query") + @PostMapping("/channel/getList") + public List getChannelList() { + return notifyService.getChannelList(); + } + + @ApiOperation("获取通道配置分页列表") + @SaCheckPermission("iot:channel:query") + @PostMapping("/channel/config/getList") + public Paging getChannelConfigList(@RequestBody @Validated(QueryGroup.class) PageRequest request) { + return notifyService.getChannelConfigList(request); + } + + @ApiOperation("获取通道配置列表") + @SaCheckPermission("iot:channel:query") + @PostMapping("/channel/config/getAll") + public List getChannelConfigAll() { + return notifyService.getChannelConfigAll(); + } + + @ApiOperation("新增通道配置") + @SaCheckPermission("iot:channel:add") + @PostMapping("/channel/config/add") + public ChannelConfig addChannelConfig(@RequestBody @Validated(EditGroup.class) Request request) { + return notifyService.addChannelConfig(request.getData()); + } + + @ApiOperation("根据ID获取通道配置") + @SaCheckPermission("iot:channel:query") + @PostMapping("/channel/config/getById") + public ChannelConfig getChannelConfigById(@RequestBody @Validated(QueryGroup.class) Request request) { + return notifyService.getChannelConfigById(request.getData()); + } + + @ApiOperation("修改通道配置") + @SaCheckPermission("iot:channel:edit") + @PostMapping("/channel/config/updateById") + public ChannelConfig updateChannelConfigById(@RequestBody @Validated Request request) { + return notifyService.updateChannelConfigById(request.getData()); + } + + @ApiOperation("删除通道配置") + @SaCheckPermission("iot:channel:remove") + @PostMapping("/channel/config/delById") + public Boolean delChannelConfigById(@RequestBody @Validated Request request) { + return notifyService.delChannelConfigById(request.getData()); + } + + @ApiOperation("获取通道模板列表") + @SaCheckPermission("iot:channel:query") + @PostMapping("/channel/template/getList") + public Paging getChannelTemplateList(@RequestBody @Validated(QueryGroup.class) PageRequest request) { + return notifyService.getChannelTemplateList(request); + } + + @ApiOperation("新增通道模板") + @SaCheckPermission("iot:channel:add") + @PostMapping("/channel/template/add") + public ChannelTemplate addChannelTemplate(@RequestBody @Validated(EditGroup.class) Request request) { + return notifyService.addChannelTemplate(request.getData()); + } + + @ApiOperation("根据ID获取通道模板") + @SaCheckPermission("iot:channel:query") + @PostMapping("/channel/template/getById") + public ChannelTemplate getChannelTemplateById(@RequestBody @Validated Request request) { + return notifyService.getChannelTemplateById(request.getData()); + } + + @ApiOperation("修改通道模板") + @SaCheckPermission("iot:channel:edit") + @PostMapping("/channel/template/updateById") + public ChannelTemplate updateChannelTemplateById(@RequestBody @Validated Request request) { + return notifyService.updateChannelTemplateById(request.getData()); + } + + @ApiOperation("删除通道模板") + @SaCheckPermission("iot:channel:remove") + @PostMapping("/channel/template/delById") + public Boolean delChannelTemplateById(@RequestBody @Validated(EditGroup.class) Request request) { + return notifyService.delChannelTemplateById(request.getData()); + } + + @ApiOperation("消息列表") + @SaCheckPermission("iot:channelMsg:query") + @PostMapping("/message/getList") + public Paging messageList(@RequestBody @Validated(QueryGroup.class) PageRequest request) { + return notifyService.getNotifyMessageList(request); + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/OtaController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/OtaController.java new file mode 100644 index 0000000..e389331 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/OtaController.java @@ -0,0 +1,126 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.manager.dto.bo.ota.DeviceOtaDetailBo; +import cc.iotkit.manager.dto.bo.ota.DeviceOtaInfoBo; +import cc.iotkit.manager.dto.bo.ota.DeviceUpgradeBo; +import cc.iotkit.manager.dto.bo.ota.OtaPackageBo; +import cc.iotkit.manager.dto.vo.ota.DeviceOtaDetailVo; +import cc.iotkit.manager.dto.vo.ota.DeviceOtaInfoVo; +import cc.iotkit.manager.dto.vo.ota.DeviceUpgradeVo; +import cc.iotkit.manager.dto.vo.ota.OtaPackageUploadVo; +import cc.iotkit.manager.service.OtaService; +import cc.iotkit.model.ota.OtaPackage; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import javax.validation.Valid; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; + +/** + * @Author: 石恒 + * @Date: 2023/5/19 20:42 + * @Description: + */ +@Api(tags = {"ota升级管理"}) +@Slf4j +@RestController +@RequestMapping("/ota") +public class OtaController extends BaseController { + + @Resource + private OtaService otaService; + + @ApiOperation("升级包上传") + @SaCheckPermission("iot:ota:add") + @PostMapping(value = "/package/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public OtaPackageUploadVo packageUpload(@RequestPart("file") MultipartFile file, @RequestParam("requestId") String requestId) throws Exception { + if (ObjectUtil.isNull(file)) { + fail("上传文件不能为空"); + } + return otaService.uploadFile(file); + } + + @ApiOperation("新增升级包") + @SaCheckPermission("iot:ota:add") + @PostMapping("/package/add") + public OtaPackage packageAdd(@RequestBody @Valid Request request) { + return otaService.addOtaPackage(request.getData()); + } + + @ApiOperation("删除升级包") + @SaCheckPermission("iot:ota:remove") + @PostMapping("/package/delById") + public Boolean delPackageById(@RequestBody @Valid Request request) { + return otaService.delOtaPackageById(request.getData()); + } + + @ApiOperation("升级包列表") + @SaCheckPermission("iot:ota:query") + @PostMapping("/package/getList") + public Paging packageList(@RequestBody @Validated PageRequest request) { + return otaService.getOtaPackagePageList(request); + } + + @ApiOperation("OTA升级") + @SaCheckPermission("iot:ota:upgrade") + @PostMapping("/device/upgrade") + public DeviceUpgradeVo deviceUpgrade(@RequestBody Request request) { + String result = otaService.startUpgrade(request.getData().getOtaId(), request.getData().getDeviceIds()); + return DeviceUpgradeVo.builder().result(result).build(); + } + + @ApiOperation("设备升级结果查询") + @SaCheckPermission("iot:ota:query") + @PostMapping("/device/detail") + public Paging otaDeviceDetail(@RequestBody PageRequest request) { + return otaService.otaDeviceDetail(request); + } + + @ApiOperation("设备升级批次查询") + @SaCheckPermission("iot:ota:query") + @PostMapping("/device/info") + public Paging otaDeviceInfo(@RequestBody PageRequest request) { + return otaService.otaDeviceInfo(request); + } + + @ApiOperation("ota升级测试") + @PostMapping("/testStartUpgrade") + public void testStartUpgrade(@RequestBody Request request) { + otaService.testStartUpgrade(); + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/PluginController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/PluginController.java new file mode 100644 index 0000000..01ba1aa --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/PluginController.java @@ -0,0 +1,112 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.manager.dto.bo.plugin.PluginInfoBo; +import cc.iotkit.manager.dto.vo.plugin.PluginInfoVo; +import cc.iotkit.manager.service.IPluginService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +/** + * @author sjg + */ +@Api(tags = {"插件管理"}) +@Slf4j +@RestController +@RequestMapping("/plugin") +public class PluginController { + + @Autowired + private IPluginService pluginService; + + @ApiOperation("上传Jar包") + // @SaCheckPermission("iot:plugin:add") + @PostMapping("/uploadJar") + public void uploadJar( + @RequestParam("id") Long id, + @RequestPart("file") MultipartFile file) { + pluginService.upload(file, id); + } + + @ApiOperation("添加插件") + @SaCheckPermission("iot:plugin:add") + @PostMapping(value = "/add") + @Log(title = "插件", businessType = BusinessType.INSERT) + public void add(@Validated(AddGroup.class) @RequestBody Request request) { + pluginService.addPlugin(request.getData()); + } + + @ApiOperation(value = "修改插件") + @SaCheckPermission("iot:plugin:edit") + @PostMapping("/edit") + @Log(title = "插件", businessType = BusinessType.UPDATE) + public void edit(@Validated(EditGroup.class) @RequestBody Request request) { + pluginService.modifyPlugin(request.getData()); + } + + @ApiOperation(value = "插件详情") + @SaCheckPermission("iot:plugin:list") + @PostMapping("/detail") + public PluginInfoVo detail(@RequestBody Request request) { + return pluginService.getPlugin(request.getData()); + } + + @ApiOperation(value = "删除插件") + @SaCheckPermission("iot:plugin:delete") + @PostMapping("/delete") + @Log(title = "插件", businessType = BusinessType.DELETE) + public void delete(@Validated(EditGroup.class) @RequestBody Request request) { + pluginService.deletePlugin(request.getData()); + } + + @ApiOperation("获取插件列表") + @SaCheckPermission("monitor:plugin:list") + @PostMapping("/list") + public Paging list(@RequestBody @Validated(QueryGroup.class) PageRequest query) { + return pluginService.findPagePluginList(query); + } + + @ApiOperation("修改插件状态") + @SaCheckPermission("monitor:plugin:edit") + @PostMapping("/changeState") + public void changeState(@RequestBody Request request) { + pluginService.changeState(request.getData()); + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProductController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProductController.java new file mode 100644 index 0000000..47acf22 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ProductController.java @@ -0,0 +1,226 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.manager.dto.bo.category.CategoryBo; +import cc.iotkit.manager.dto.bo.product.IconBo; +import cc.iotkit.manager.dto.bo.product.IconTypeBo; +import cc.iotkit.manager.dto.bo.product.ProductBo; +import cc.iotkit.manager.dto.bo.productmodel.ProductModelBo; +import cc.iotkit.manager.dto.bo.thingmodel.ThingModelBo; +import cc.iotkit.manager.dto.vo.category.CategoryVo; +import cc.iotkit.manager.dto.vo.product.IconTypeVo; +import cc.iotkit.manager.dto.vo.product.IconVo; +import cc.iotkit.manager.dto.vo.product.ProductVo; +import cc.iotkit.manager.dto.vo.productmodel.ProductModelVo; +import cc.iotkit.manager.dto.vo.thingmodel.ThingModelVo; +import cc.iotkit.manager.service.IProductService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +@Api(tags = {"产品"}) +@Slf4j +@RestController +@RequestMapping("/product") +public class ProductController { + + + @Autowired + private IProductService productService; + + @ApiOperation("列表") + @SaCheckPermission("iot:product:query") + @PostMapping("/list") + public Paging getProducts(@Validated(QueryGroup.class) @RequestBody + PageRequest request) { + return productService.selectPageList(request); + } + + @ApiOperation("新建") + @SaCheckPermission("iot:product:add") + @PostMapping(value = "/add") + @Log(title = "产品", businessType = BusinessType.INSERT) + public ProductVo create(@Validated(AddGroup.class) @RequestBody Request request) { + return productService.addEntity(request.getData()); + } + + @ApiOperation(value = "编辑产品") + @SaCheckPermission("iot:product:edit") + @PostMapping("/edit") + @Log(title = "产品", businessType = BusinessType.UPDATE) + public boolean edit(@Validated(EditGroup.class) @RequestBody Request request) { + return productService.updateEntity(request.getData()); + } + + @ApiOperation("保存图标分类") + @SaCheckPermission("iot:iconType:edit") + @PostMapping("/icon/saveIconType") + public boolean saveIconType(@Validated @RequestBody Request request) { + return productService.saveIconType(request.getData()); + } + + @ApiOperation("删除图标分类") + @SaCheckPermission("iot:iconType:remove") + @PostMapping("/icon/deleteIconType") + public boolean deleteIconType(@Validated @RequestBody Request request) { + return productService.deleteIconType(request.getData()); + } + + @ApiOperation("图标分类列表") + @SaCheckPermission("iot:iconType:query") + @PostMapping("/icon/getAllIconType") + public List getAllIconType() { + return productService.selectIconTypeList(); + } + + @ApiOperation("保存图标") + @SaCheckPermission("iot:icon:edit") + @PostMapping("/icon/saveIcon") + public boolean saveIcon(@Validated @RequestBody Request request) { + return productService.saveIcon(request.getData()); + } + + @ApiOperation("删除图标") + @SaCheckPermission("iot:icon:remove") + @PostMapping("/icon/deleteIcon") + public boolean deleteIcon(@Validated @RequestBody Request request) { + return productService.deleteIcon(request.getData()); + } + + @ApiOperation("图标分页展示") + @SaCheckPermission("iot:icon:query") + @PostMapping("/icon/getAllIcon") + public Paging getAllIcon(@Validated @RequestBody PageRequest request) { + return productService.selectIconPageList(request); + } + + @ApiOperation("查看详情") + @SaCheckPermission("iot:product:query") + @PostMapping(value = "/getDetail") + public ProductVo getDetail(@RequestBody @Validated Request request) { + return productService.getDetail(request.getData()); + } + + @ApiOperation("删除产品") + @SaCheckPermission("iot:product:remove") + @PostMapping(value = "/deleteProduct") + public boolean deleteProduct(@RequestBody @Validated Request request) { + return productService.deleteProduct(request.getData()); + } + + @ApiOperation("查看物模型") + @SaCheckPermission("iot:thingModel:query") + @PostMapping("/getThingModelByProductKey") + public ThingModelVo getThingModelByProductKey(@RequestBody @Validated Request request) { + return productService.getThingModelByProductKey(request.getData()); + } + + @ApiOperation("保存物模型") + @SaCheckPermission("iot:thingModel:edit") + @PostMapping("/thingModel/save") + public boolean saveThingModel(@Validated @RequestBody Request request) { + return productService.saveThingModel(request.getData()); + } + + @ApiOperation("删除物模型") + @SaCheckPermission("iot:thingModel:remove") + @PostMapping("/thingModel/delete") + @Log(title = "物模型", businessType = BusinessType.DELETE) + public boolean deleteThingModel(@Validated @RequestBody Request id) { + return productService.deleteThingModel(id.getData()); + } + + @ApiOperation("产品品类分页展示") + @SaCheckPermission("iot:category:query") + @PostMapping("/category/list") + public Paging getCategories(@Validated @RequestBody PageRequest request) { + return productService.selectCategoryPageList(request); + } + + @ApiOperation("产品品类展示") + @SaCheckPermission("iot:category:query") + @PostMapping("/category/getAll") + public List getCategorieList() { + return productService.selectCategoryList(); + } + + @ApiOperation("品类编辑") + @SaCheckPermission("iot:category:edit") + @PostMapping("/category/edit") + public boolean saveCategory(@Validated @RequestBody Request req) { + return productService.editCategory(req.getData()); + } + + @ApiOperation("删除品类") + @SaCheckPermission("iot:category:remove") + @PostMapping("/category/delete") + public boolean delCategory(@Validated @RequestBody Request req) { + return productService.deleteCategory(req.getData()); + } + + @ApiOperation("上传产品图片") + @SaCheckPermission("iot:product:edit") + @PostMapping("/uploadImg/{productKey}") + public String uploadImg(@PathVariable("productKey") String productKey, + @RequestParam("file") MultipartFile file) { + return productService.uploadImg(productKey, file); + } + + @ApiModelProperty("获取产品型号") + @SaCheckPermission("iot:product:query") + @PostMapping("/getModelsByProductKey") + public List getModels(@Validated @RequestBody Request bo) { + return productService.getModels(bo.getData()); + } + + @ApiOperation("编辑产品型号") + @SaCheckPermission("iot:product:edit") + @PostMapping("/productModel/edit") + public boolean saveProductModel(@Validated @RequestBody Request bo) { + return productService.editProductModel(bo.getData()); + } + + @ApiOperation("删除产品型号") + @SaCheckPermission("iot:product:remove") + @PostMapping("/productModel/delete") + public boolean deleteProductModel(@Validated @RequestBody Request id) { + return productService.deleteProductModel(id.getData()); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java new file mode 100644 index 0000000..39ecac0 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/RuleEngineController.java @@ -0,0 +1,179 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.manager.dto.bo.ruleinfo.RuleInfoBo; +import cc.iotkit.manager.dto.bo.ruleinfo.RuleLogBo; +import cc.iotkit.manager.dto.bo.taskinfo.TaskInfoBo; +import cc.iotkit.manager.dto.bo.taskinfo.TaskLogBo; +import cc.iotkit.manager.dto.vo.ruleinfo.RuleInfoVo; +import cc.iotkit.manager.dto.vo.ruleinfo.RuleLogVo; +import cc.iotkit.manager.dto.vo.taskinfo.TaskInfoVo; +import cc.iotkit.manager.dto.vo.taskinfo.TaskLogVo; +import cc.iotkit.manager.service.IRuleEngineService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = {"规则引擎"}) +@Slf4j +@RestController +@RequestMapping("/rule_engine") +public class RuleEngineController { + + @Autowired + IRuleEngineService ruleEngineService; + + @ApiOperation("规则列表") + @SaCheckPermission("iot:rule:query") + @PostMapping("/list") + public Paging rules( + @Validated @RequestBody + PageRequest request + ) { + return ruleEngineService.selectPageList(request); + } + + @ApiOperation("保存规则") + @SaCheckPermission("iot:rule:eidt") + @PostMapping("/edit") + public boolean saveRule(@RequestBody @Validated Request ruleInfoBo) { + return ruleEngineService.saveRule(ruleInfoBo.getData()); + } + + @ApiOperation("暂停规则") + @SaCheckPermission("iot:rule:edit") + @PostMapping("/pause") + public boolean pauseRule(@Validated @RequestBody Request request) { + String ruleId = request.getData(); + return ruleEngineService.pauseRule(ruleId); + } + + @ApiOperation("恢复规则") + @SaCheckPermission("iot:rule:edit") + @PostMapping("/resume") + public boolean resumeRule(@Validated @RequestBody Request request) { + String ruleId = request.getData(); + return ruleEngineService.resumeRule(ruleId); + } + + @ApiOperation("删除规则") + @SaCheckPermission("iot:rule:remove") + @PostMapping("/delete") + public boolean deleteRule(@Validated @RequestBody Request request) { + String ruleId = request.getData(); + return ruleEngineService.deleteRule(ruleId); + } + + @ApiOperation("规则日志") + @SaCheckPermission("iot:rule:query") + @PostMapping("/ruleLog/list") + public Paging getRuleLogs( + @Validated @RequestBody PageRequest request + ) { + return ruleEngineService.selectRuleLogPageList(request); + } + + @ApiOperation("清理日志") + @SaCheckPermission("iot:rule:remove") + @PostMapping("/ruleLog/clear") + public boolean clearRuleLogs(@Validated @RequestBody Request request) { + String ruleId = request.getData(); + return ruleEngineService.clearRuleLogs(ruleId); + + } + + @ApiOperation("定时任务列表") + @SaCheckPermission("iot:task:query") + @PostMapping("/tasks/list") + public Paging tasks(@Validated @RequestBody PageRequest request) { + return ruleEngineService.selectTaskPageList(request); + } + + @ApiOperation("保存定时任务") + @SaCheckPermission("iot:task:edit") + @PostMapping("/task/save") + public boolean saveTask(@Validated @RequestBody Request taskInfo) { + return ruleEngineService.saveTask(taskInfo.getData()); + } + + @ApiOperation("停止定时任务") + @SaCheckPermission("iot:task:edit") + @PostMapping("/task/pause") + public boolean pauseTask(@Validated @RequestBody Request request) { + String taskId = request.getData(); + return ruleEngineService.pauseTask(taskId); + } + + @ApiOperation("恢复定时任务") + @SaCheckPermission("iot:task:edit") + @PostMapping("/task/resume") + public boolean resumeTask(@Validated @RequestBody Request request) { + return ruleEngineService.resumeTask(request.getData()); + } + + @ApiOperation("更新定时任务") + @SaCheckPermission("iot:task:edit") + @PostMapping("/task/renew") + public boolean renewTask(@Validated @RequestBody Request request) { + String taskId = request.getData(); + return ruleEngineService.renewTask(taskId); + + } + + @ApiOperation("删除定时任务") + @SaCheckPermission("iot:task:remove") + @PostMapping("/task/delete") + public boolean deleteTask(@Validated @RequestBody Request request) { + String taskId = request.getData(); + return ruleEngineService.deleteTask(taskId); + + } + + @ApiOperation("定时任务日志list") + @SaCheckPermission("iot:task:query") + @PostMapping("/taskLogs/list") + public Paging getTaskLogs( + @Validated @RequestBody PageRequest request + ) { + return ruleEngineService.selectTaskLogPageList(request); + } + + @ApiOperation("清除定时任务日志") + @SaCheckPermission("iot:task:remove") + @PostMapping("/taskLogs/clear") + public boolean clearTaskLogs(@Validated @RequestBody Request request) { + return ruleEngineService.clearTaskLogs(request.getData()); + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ScreenController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ScreenController.java new file mode 100644 index 0000000..fc06026 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/ScreenController.java @@ -0,0 +1,174 @@ +///* +// * +// * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 +// * * +---------------------------------------------------------------------- +// * * | Author: xw2sy@163.com +// * * +---------------------------------------------------------------------- +// * +// * Copyright [2024] [OPENIITA] +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// * / +// */ +// +//package cc.iotkit.manager.controller; +// +//import cc.iotkit.common.api.PageRequest; +//import cc.iotkit.common.api.Paging; +//import cc.iotkit.common.api.Request; +//import cc.iotkit.common.enums.ErrCode; +//import cc.iotkit.common.exception.BizException; +//import cc.iotkit.manager.dto.bo.screen.DebugChangeBo; +//import cc.iotkit.manager.dto.bo.screen.PublishChangeBo; +//import cc.iotkit.manager.service.IScreenService; +//import cc.iotkit.model.screen.Screen; +//import cc.iotkit.model.screen.ScreenApi; +//import cn.dev33.satoken.annotation.SaCheckPermission; +//import cn.hutool.core.util.ObjectUtil; +//import io.swagger.annotations.Api; +//import io.swagger.annotations.ApiOperation; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.validation.annotation.Validated; +//import org.springframework.web.bind.annotation.*; +//import org.springframework.web.multipart.MultipartFile; +// +//import java.util.List; +// +///** +// * @Author:tfd +// * @Date:2023/6/25 14:56 +// */ +//@Api(tags = {"大屏接口"}) +//@Slf4j +//@RestController +//@RequestMapping("/screen") +//public class ScreenController { +// +// @Autowired +// private IScreenService screenService; +// +// @ApiOperation(value = "获取大屏列表", httpMethod = "POST") +// @SaCheckPermission("iot:screen:list") +// @PostMapping("/getScreens") +// public Paging getBigScreens(@Validated @RequestBody PageRequest request) { +// return screenService.getBigScreens(request); +// } +// +// @ApiOperation(value = "上传大屏资源包") +// @SaCheckPermission("iot:screen:add") +// @PostMapping("/uploadResourceFile") +// public Long uploadResourceFile(@RequestParam("file") MultipartFile file, +// @RequestBody @Validated Request id){ +// if (file == null) { +// throw new BizException(ErrCode.PARAMS_EXCEPTION); +// } +// log.info("saving upload resource file:{}", file.getName()); +// return screenService.uploadResourceFile(file,id.getData()); +// } +// +// @ApiOperation(value = "获取大屏接口") +// @SaCheckPermission("iot:screen:list") +// @PostMapping("/getScreenApis") +// public List getScreenApis(@RequestBody @Validated Request id) { +// if (ObjectUtil.isEmpty(id.getData())) { +// throw new BizException(ErrCode.ID_BLANK); +// } +// return screenService.findByScreenId(id.getData()); +// } +// +// @ApiOperation(value = "获取默认大屏") +// @SaCheckPermission("iot:screen:query") +// @PostMapping("/getDefaultScreen") +// public Screen getDefaultScreen() { +// return screenService.getDefaultScreen(); +// } +// +// @ApiOperation(value = "同步资源包接口") +// @SaCheckPermission("iot:screen:query") +// @PostMapping("/syncResourceApis") +// public List syncResourceApis(@RequestBody @Validated Request id) { +// if (ObjectUtil.isEmpty(id.getData())) { +// throw new BizException(ErrCode.ID_BLANK); +// } +// return screenService.syncResourceApis(id.getData()); +// } +// +// @ApiOperation(value = "预览接口") +// @SaCheckPermission("iot:screen:query") +// @PostMapping("/previewApis") +// public void previewApis(@RequestBody @Validated Request> screenApis) { +// if (ObjectUtil.isNull(screenApis.getData()) || screenApis.getData().isEmpty()) { +// throw new BizException(ErrCode.API_LIST_BLANK); +// } +// screenService.previewApis(screenApis.getData()); +// } +// +// @ApiOperation(value = "保存大屏接口") +// @SaCheckPermission("iot:screen:edit") +// @PostMapping("/saveScreenApis") +// public void saveScreenApis(@RequestBody @Validated Request> screenApis) { +// if (ObjectUtil.isNull(screenApis.getData()) || screenApis.getData().isEmpty()) { +// throw new BizException(ErrCode.API_LIST_BLANK); +// } +// screenService.saveScreenApis(screenApis.getData()); +// } +// +// @ApiOperation(value = "调试模式转换") +// @SaCheckPermission("iot:screen:edit") +// @PostMapping("/debugModeChange") +// public void debugMode(@RequestBody @Validated Request debugChange) { +// screenService.debugModeChange(debugChange.getData()); +// } +// +// @ApiOperation(value = "添加大屏") +// @SaCheckPermission("iot:screen:add") +// @PostMapping("/addScreen") +// public void addScreen(@RequestBody @Validated Request screen) { +// screenService.addBigScreen(screen.getData()); +// } +// +// @ApiOperation(value = "保存大屏") +// @SaCheckPermission("iot:screen:edit") +// @PostMapping("/saveScreen") +// public void saveScreen(@RequestBody @Validated Request screen) { +// screenService.saveBigScreen(screen.getData()); +// } +// +// @ApiOperation(value = "发布状态改变") +// @SaCheckPermission("iot:screen:edit") +// @PostMapping("/publishStatusChange") +// public void publishStatusChange(@RequestBody @Validated Request req) { +// screenService.publishStatusChange(req.getData()); +// } +// +// @ApiOperation(value = "设置默认大屏") +// @SaCheckPermission("iot:screen:edit") +// @PostMapping("/setDefaultScreen") +// public void setDefaultScreen(@RequestBody @Validated Request id) { +// if (ObjectUtil.isEmpty(id.getData())) { +// throw new BizException(ErrCode.ID_BLANK); +// } +// screenService.setDefaultScreen(id.getData()); +// } +// +// @ApiOperation(value = "删除大屏", httpMethod = "POST") +// @SaCheckPermission("iot:screen:remove") +// @PostMapping("/deleteScreen") +// public void deleteScreen(@RequestBody @Validated Request id) { +// if (ObjectUtil.isEmpty(id.getData())) { +// throw new BizException(ErrCode.ID_BLANK); +// } +// screenService.deleteScreen(id.getData()); +// } +//} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceController.java new file mode 100644 index 0000000..6ccb54e --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceController.java @@ -0,0 +1,181 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.Request; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.manager.dto.bo.space.HomeBo; +import cc.iotkit.manager.service.DataOwnerService; +import cc.iotkit.manager.service.IHomeService; +import cc.iotkit.manager.service.ISpaceService; +import cc.iotkit.model.space.Home; +import cc.iotkit.model.space.Space; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Api(tags = {"空间"}) +@RestController +@RequestMapping("/space") +public class SpaceController { + + @Autowired + private ISpaceService spaceService; + @Autowired + private IHomeService homeService; + @Autowired + private DataOwnerService dataOwnerService; + + /** + * 取用户当前家庭 + */ + @PostMapping("/currentHome") + public Home getCurrentHome() { + return homeService.findByUserIdAndCurrent(LoginHelper.getUserId(), true); + } + + /** + * 取用户所有家庭 + */ + @PostMapping("/getUserHomes") + public List getUserHomes() { + return homeService.findByUserId(LoginHelper.getUserId()); + } + + /** + * 切换用户当前家庭 + */ + @PostMapping("/changCurrentHome") + public void changCurrentHome(@RequestBody @Validated Request request) { + HomeBo home=request.getData(); + checkHomeExist(home.getId()); + homeService.changCurrentHome(home); + } + + /** + * 添加家庭信息 + */ + @PostMapping("/addHome") + public void addHome(@RequestBody @Validated Request request) { + HomeBo home = request.getData(); + if (!homeService.checkHomeNameUnique(home)) { + throw new BizException("家庭'" + home.getName() + "'已存在"); + } + home.setSpaceNum(3); + home.setUserId(LoginHelper.getUserId()); + Home dbHome = homeService.save(home); + //添加默认房间 + for (String name : new String[]{"客厅", "卧室", "厨房"}) { + spaceService.save(Space.builder() + .homeId(dbHome.getId()) + .name(name) + .deviceNum(0) + .build()); + } + } + + /** + * 保存家庭信息 + */ + @PostMapping("/saveHome") + public void saveHome(@RequestBody @Validated Request request) { + HomeBo home=request.getData(); + checkHomeExist(home.getId()); + homeService.save(home); + } + + /** + * 删除家庭信息 + */ + @PostMapping("/delHome") + public void delHome(@RequestBody @Validated Request request) { + Long id=request.getData(); + checkHomeExist(id); + homeService.deleteById(id); + } + + /** + * 我的空间列表 + */ + @PostMapping("/getSpaces") + public List getSpaces(@RequestBody @Validated Request request) { + return spaceService.findByHomeId(request.getData()); + } + + /** + * 在当前家庭中添加空间 + */ + @PostMapping("/addSpace") + public void addSpace(@RequestBody @Validated Request request) { + Long userId=LoginHelper.getUserId(); + Home currHome = homeService.findByUserIdAndCurrent(userId, true); + if (currHome == null) { + throw new BizException(ErrCode.CURRENT_HOME_NOT_FOUND); + } + spaceService.save(Space.builder() + .homeId(currHome.getId()) + .name(request.getData().getName()) + .deviceNum(0) + .build()); + } + + @PostMapping("/delSpace") + public void delSpace(@RequestBody @Validated Request request) { + Long spaceId=request.getData(); + checkExist(spaceId); + spaceService.deleteById(spaceId); + } + + @PostMapping("/saveSpace") + public void saveSpace(@RequestBody @Validated Request request) { + Space space=request.getData(); + Space oldSpace = checkExist(space.getId()); + oldSpace.setName(space.getName()); + spaceService.save(oldSpace); + } + + private Space checkExist(Long id) { + Space space = spaceService.findById(id); + if (space == null) { + throw new BizException(ErrCode.SPACE_NOT_FOUND); + } + return space; + } + + private Home checkHomeExist(Long id) { + Home home = homeService.findById(id); + if (home == null) { + throw new BizException(ErrCode.HOME_NOT_FOUND); + } + return home; + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java new file mode 100644 index 0000000..bbcb766 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/SpaceDeviceController.java @@ -0,0 +1,380 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.data.manager.ICategoryData; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IUserInfoData; +import cc.iotkit.manager.dto.bo.device.DeviceLogQueryBo; +import cc.iotkit.manager.dto.vo.product.ProductVo; +import cc.iotkit.manager.dto.vo.thingmodel.ThingModelVo; +import cc.iotkit.manager.model.vo.FindDeviceVo; +import cc.iotkit.manager.model.vo.SpaceDeviceVo; +import cc.iotkit.manager.service.IHomeService; +import cc.iotkit.manager.service.IProductService; +import cc.iotkit.manager.service.ISpaceDeviceService; +import cc.iotkit.manager.service.ISpaceService; +import cc.iotkit.model.UserInfo; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.product.Category; +import cc.iotkit.model.space.Home; +import cc.iotkit.model.space.Space; +import cc.iotkit.model.space.SpaceDevice; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + + +@Api(tags = {"空间设备"}) +@RestController +@RequestMapping("/space") +public class SpaceDeviceController { + + @Autowired + private ISpaceDeviceService spaceDeviceService; + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + @Autowired + private IProductService productService; + @Autowired + @Qualifier("categoryDataCache") + private ICategoryData categoryData; + @Autowired + private ISpaceService spaceService; + @Autowired + private IHomeService homeService; + @Autowired + private IUserInfoData userInfoData; + + /** + * 我最近使用的设备列表 + */ + @PostMapping(Constants.API_SPACE.RECENT_DEVICES) + public List getMyRecentDevices() {//TODO 老接口 +// List spaceDevices = spaceDeviceService.findByUserIdAndCollect(LoginHelper.getUserId(),true); +// return spaceDevices.stream().map((this::parseSpaceDevice)).collect(Collectors.toList()); + return null; + } + + @ApiOperation("设备日志") + @PostMapping("/deviceLogs") + public Paging logs(@Validated @RequestBody PageRequest request) { + Home home = homeService.findByUserIdAndCurrent(LoginHelper.getUserId(), true); + List spaceDevices = spaceDeviceService.findByHomeId(home.getId()); + List devIds=spaceDevices.stream().map((spaceDevice->spaceDevice.getDeviceId())).collect(Collectors.toList()); + return spaceDeviceService.findByTypeAndDeviceIds(devIds,request.getData().getType(),"",request.getPageNum(),request.getPageSize()); + } + + /** + * 获取用户收藏设备列表 + */ + @PostMapping(Constants.API_SPACE.GET_COLLECT_DEVICES) + public List getCollectDevices() { + Home home = homeService.findByUserIdAndCurrent(LoginHelper.getUserId(), true); + List spaceDevices = spaceDeviceService.findByHomeIdAndCollect(home.getId(), true); + return spaceDevices.stream().map((this::parseSpaceDevice)).collect(Collectors.toList()); + } + + + + /** + * 收藏/取消收藏设备 + */ + @PostMapping(Constants.API_SPACE.COLLECT_DEVICE) + public void collectDevice(@RequestBody @Validated Request request) { + SpaceDevice spaceDevice = request.getData(); + SpaceDevice oldSpaceDevice = spaceDeviceService.findByDeviceId(spaceDevice.getDeviceId()); + oldSpaceDevice.setCollect(spaceDevice.getCollect()); + spaceDeviceService.save(oldSpaceDevice); + } + + /** + * 我的空间设备列表-按空间获取 + * + * @param request + */ + @PostMapping("/getSpaceDevices") + public List getMyDevices(@RequestBody @Validated Request request) { + List spaceDevices; + Long spaceId = request.getData(); + if ("all".equals(spaceId)) { + //全部设备 + Home home = homeService.findByUserIdAndCurrent(LoginHelper.getUserId(), true); + spaceDevices = spaceDeviceService.findByHomeId(home.getId()); + } else { + //按空间获取 + spaceDevices = spaceDeviceService.findBySpaceId(spaceId); + } + return spaceDevices.stream().map((this::parseSpaceDevice)).collect(Collectors.toList()); + } + + private SpaceDeviceVo parseSpaceDevice(SpaceDevice sd) { + DeviceInfo device = deviceInfoData.findByDeviceId(sd.getDeviceId()); + Space space = spaceService.findById(sd.getSpaceId()); + ProductVo product = productService.findByProductKey(device.getProductKey()); + ThingModelVo tm = productService.getThingModelByProductKey(device.getProductKey()); + Map property = new HashMap<>(); + if (tm != null) { + tm.getModel().setEvents(null); + property = JsonUtils.parseObject(JsonUtils.toJsonString(tm.getModel()), Map.class); + } + Category category = categoryData.findById(product.getCategory()); + DeviceInfo.State state = device.getState(); + + return SpaceDeviceVo.builder() + .id(sd.getId()) + .deviceId(sd.getDeviceId()) + .deviceName(device.getDeviceName()) + .name(sd.getName()) + .createTime(sd.getCreateTime()) + .spaceId(sd.getSpaceId()) + .spaceName(space.getName()) + .productKey(device.getProductKey()) + .productName(product.getName()) + .category(product.getCategory()) + .categoryName(category.getName()) + .picUrl(product.getImg()) + .online(state != null && state.isOnline()) + .property(property) + .collect(sd.getCollect()) + .build(); + } + + /** + * 获取用户所有设备列表 + */ + @PostMapping("/{userId}/devices") + public List getDevices(@PathVariable("userId") Long userId) { + Home curHome = homeService.findByUserIdAndCurrent(userId, true); + List spaceDevices = spaceDeviceService.findByHomeId(curHome.getId()); + return spaceDevices.stream().map((this::parseSpaceDevice)).collect(Collectors.toList()); + } + + /** + * 搜索未添加过的设备 + */ + @PostMapping(Constants.API_SPACE.FIND_DEVICE) + public List findDevice(@RequestBody @Validated Request request) { + String mac = request.getData(); + if (StringUtils.isBlank(mac)) { + throw new BizException(ErrCode.DATA_BLANK); + } + + if (mac.trim().length() < 3) { + throw new BizException(ErrCode.DATA_LENGTH_ERROR); + } + + List findDeviceVos = new ArrayList<>(); + DeviceInfo query=new DeviceInfo(); + query.setDeviceName(mac); + query.setState(null); + List devices = deviceInfoData.findAllByCondition(query); + if(devices == null){ + return findDeviceVos; + } + //查找网关下子设备 +// List subDevices = new ArrayList<>(); +// if (findDevice.getParentId() == null) {//如果是网关设备 +// subDevices = deviceInfoData.findByParentId(findDevice.getDeviceId()); +// } +// List devices = new ArrayList<>(subDevices); + + //查找空间设备 + for (DeviceInfo device : devices) { + SpaceDevice spaceDevice = spaceDeviceService.findByDeviceId(device.getDeviceId()); + if (spaceDevice == null) { + //没有被其它人占用 + findDeviceVos.add(getFindDeviceVo(device)); + } + } + return findDeviceVos; + } + + private FindDeviceVo getFindDeviceVo(DeviceInfo device) { + FindDeviceVo findDeviceVo = FindDeviceVo.builder() + .deviceId(device.getDeviceId()) + .deviceName(device.getDeviceName()) + .productKey(device.getProductKey()) + .build(); + + ProductVo product = productService.findByProductKey(device.getProductKey()); + Category category = categoryData.findById(product.getCategory()); + findDeviceVo.setProductName(product.getName()); + findDeviceVo.setProductImg(product.getImg()); + findDeviceVo.setCategoryName(category.getName()); + return findDeviceVo; + } + + /** + * REMOVE_DEVICE + * 往指定房间中添加设备 + */ + @PostMapping(Constants.API_SPACE.ADD_DEVICE) + public void addDevice(@RequestBody @Validated Request request) { + SpaceDevice device = request.getData(); + String deviceId = device.getDeviceId(); + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + if (deviceInfo == null) { + throw new BizException(ErrCode.DEVICE_NOT_FOUND); + } + Long spaceId = device.getSpaceId(); + Space space = spaceService.findById(spaceId); + if (space == null) { + throw new BizException(ErrCode.SPACE_NOT_FOUND); + } + + SpaceDevice oldSpaceDevice = spaceDeviceService.findByDeviceId(deviceId); + if (oldSpaceDevice != null) { + throw new BizException(ErrCode.DEVICE_ALREADY); + } + + SpaceDevice spaceDevice = SpaceDevice.builder() + .deviceId(deviceId) + .spaceId(spaceId) + .deviceId(deviceId) + .name(device.getName()) + .homeId(space.getHomeId()) + .collect(false) + .build(); + spaceDeviceService.save(spaceDevice); + + //更新设备子用户列表 + List subUid = deviceInfo.getSubUid(); + if (subUid == null) { + subUid = new ArrayList<>(); + deviceInfo.setSubUid(subUid); + } + + String uid = AuthUtil.getUserId(); + UserInfo userInfo = userInfoData.findById(Long.valueOf(uid)); + if (userInfo == null) { + throw new BizException(ErrCode.USER_NOT_FOUND); + } + if (!subUid.contains(uid)) { + subUid.add(uid); + } + + //更新设备标签,标识设备是用的哪个第三方平台 + List platforms = userInfo.getUsePlatforms(); + Map tags = deviceInfo.getTag(); + for (String platform : platforms) { + Constants.ThirdPlatform thirdPlatform = Constants.ThirdPlatform.valueOf(platform); + tags.put(platform, new DeviceInfo.Tag(platform, thirdPlatform.desc, "是")); + } + + deviceInfoData.save(deviceInfo); + } + + /** + * 移除房间中的设备 + */ + @PostMapping(Constants.API_SPACE.REMOVE_DEVICE) + public void removeDevice(@RequestBody @Validated Request request) { + SpaceDevice spaceDevice = spaceDeviceService.findByDeviceId(request.getData()); + if (spaceDevice == null) { + throw new BizException(ErrCode.SPACE_DEVICE_NOT_FOUND); + } + + spaceDeviceService.deleteById(spaceDevice.getId()); + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(request.getData()); + UserInfo userInfo = userInfoData.findById(LoginHelper.getUserId()); + if (userInfo == null) { + throw new BizException(ErrCode.USER_NOT_FOUND); + } + + List platforms = userInfo.getUsePlatforms(); + List subUid = deviceInfo.getSubUid(); + subUid.remove(LoginHelper.getUserId() + ""); + //删除设备标签 + for (String platform : platforms) { + deviceInfo.getTag().remove(platform); + } + + deviceInfoData.save(deviceInfo); + } + + /** + * 保存房间设备信息 + */ + @PostMapping(Constants.API_SPACE.SAVE_DEVICE) + public void saveDevice(SpaceDevice spaceDevice) { + SpaceDevice oldData = spaceDeviceService.findById(spaceDevice.getId()); + if (oldData == null) { + throw new BizException(ErrCode.SPACE_DEVICE_NOT_FOUND); + } + oldData.setName(spaceDevice.getName()); + oldData.setSpaceId(spaceDevice.getSpaceId()); + spaceDeviceService.save(oldData); + } + + /** + * 获取房间中指定设备信息 + */ + @PostMapping(Constants.API_SPACE.GET_DEVICE) + public SpaceDeviceVo getSpaceDevice(@PathVariable("deviceId") String deviceId) { + SpaceDevice spaceDevice = spaceDeviceService.findByDeviceId(deviceId); + return parseSpaceDevice(spaceDevice); + } + + /** + * 设置设备的第三方平台openUid + * 如:小度接入使用的openUid + */ + @PostMapping(Constants.API_SPACE.SET_OPEN_UID) + public void setOpenUid(String deviceId, String platform, String openUid) { + SpaceDevice spaceDevice = spaceDeviceService.findByDeviceId(deviceId); + if (spaceDevice == null) { + throw new BizException(ErrCode.SPACE_DEVICE_NOT_FOUND); + } + + //找到设备 + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + Map tags = deviceInfo.getTag(); + String openUidName = platform + "OpenUid"; + //给设备添加对应平台openUid的设备标签 + Constants.ThirdOpenUid thirdOpenUid = Constants.ThirdOpenUid.valueOf(openUidName); + tags.put(openUidName, new DeviceInfo.Tag(openUidName, thirdOpenUid.desc, openUid)); + deviceInfoData.save(deviceInfo); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/StatsController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/StatsController.java new file mode 100644 index 0000000..6dfa2b7 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/StatsController.java @@ -0,0 +1,256 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.data.config.TenantContext; +import cc.iotkit.data.manager.IAlertRecordData; +import cc.iotkit.data.manager.ICategoryData; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.manager.dto.bo.device.DeviceQueryBo; +import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo; +import cc.iotkit.manager.model.stats.MainStats; +import cc.iotkit.manager.service.AlertService; +import cc.iotkit.manager.service.IDeviceManagerService; +import cc.iotkit.model.alert.AlertRecord; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.stats.AlertStatDTO; +import cc.iotkit.temporal.IThingModelMessageData; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.map.MapUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.time.*; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Api(tags = {"状态"}) +@Slf4j +@RestController +@RequestMapping("/stats") +public class StatsController { + + @Autowired + private ICategoryData ICategoryData; + @Autowired + @Qualifier("productDataCache") + private IProductData productData; + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + @Autowired + private IThingModelMessageData thingModelMessageData; + @Autowired + private IAlertRecordData iAlertRecordData; + @Autowired + private AlertService alertService; + @Autowired + private IDeviceManagerService deviceServiceImpl; + @PostMapping("/main") + public MainStats getMainStats() { + MainStats mainStats = new MainStats(); + String uid = AuthUtil.getUserId(); + log.info("Thread {} - TenantFilter disabled: {}", + Thread.currentThread().getId(), + TenantContext.isFilterDisabled()); + long now = System.currentTimeMillis(); + if (AuthUtil.isAdmin()) { + mainStats.setCategoryTotal(ICategoryData.count()); + mainStats.setProductTotal(productData.count()); + mainStats.setDeviceTotal(deviceInfoData.count()); + + DeviceInfo condition = new DeviceInfo(); + DeviceInfo.State state = new DeviceInfo.State(); + state.setOnline(true); + condition.setState(state); + mainStats.setOnlineTotal(deviceInfoData.findAllByCondition(condition).size()); + + state.setOnline(false); + condition.setState(state); + mainStats.setOfflineTotal(deviceInfoData.findAllByCondition(condition).size()); + + // 待激活设备 + mainStats.setNeverOnlineTotal(deviceInfoData.findNeverUsedDevices().size()); + + mainStats.setReportTotal(thingModelMessageData.count()); + //上行数据统计 + mainStats.setDeviceUpMessageStats(thingModelMessageData.getDeviceUpMessageStatsWithUid(null, null, null)); + // 下行数据统计 + mainStats.setDeviceDownMessageStats(thingModelMessageData.getDeviceDownMessageStatsWithUid(null, null, null)); + //产品数量统计 + mainStats.setDeviceStatsOfCategory(deviceInfoData.getDeviceStatsByCategory("")); + } else { + mainStats.setCategoryTotal(ICategoryData.count()); +// mainStats.setProductTotal(productData.countByUid(uid)); + mainStats.setDeviceTotal(deviceInfoData.countByUid(uid)); +// mainStats.setReportTotal(deviceReportRepository.countByUid(uid)); + //上报数据统计 + mainStats.setReportDataStats(thingModelMessageData.getDeviceMessageStatsWithUid(uid, now - 48 * 3600 * 1000, now)); + //产品数量统计 + mainStats.setDeviceStatsOfCategory(deviceInfoData.getDeviceStatsByCategory(uid)); + } + + return mainStats; + } + + + @PostMapping("/mainAlertRecord") + public String getAlertRecord() { + List list = iAlertRecordData.getAlertRecord(); + // jpaQueryFactory + // iAlertRecordData.findAll(); + return JSONUtil.toJsonPrettyStr(list); + // return list; + } + @PostMapping("/deviceRecord") + public String getDeviceRecord() { + List list = deviceInfoData.getDeviceRecord(); + // jpaQueryFactory + // iAlertRecordData.findAll(); + return JSONUtil.toJsonPrettyStr(list); + // return list; + } + @PostMapping("/mainTop") + public String getMainTop() { + //过滤租户开启 + + TenantContext.disableTenantFilter(); + log.info("Thread {} - TenantFilter disabled: {}", + Thread.currentThread().getId(), + TenantContext.isFilterDisabled()); + + MainStats mainStats = new MainStats(); + String uid = AuthUtil.getUserId(); + mainStats.setCategoryTotal(ICategoryData.count()); + mainStats.setProductTotal(productData.count()); + mainStats.setDeviceTotal(deviceInfoData.count()); + + DeviceInfo condition = new DeviceInfo(); + DeviceInfo.State state = new DeviceInfo.State(); + state.setOnline(true); + condition.setState(state); + mainStats.setOnlineTotal(deviceInfoData.findAllByCondition(condition).size()); + + state.setOnline(false); + condition.setState(state); + mainStats.setOfflineTotal(deviceInfoData.findAllByCondition(condition).size()); + + // 待激活设备 + mainStats.setNeverOnlineTotal(deviceInfoData.findNeverUsedDevices().size()); + + mainStats.setReportTotal(thingModelMessageData.count()); + //上行数据统计 + mainStats.setDeviceUpMessageStats(thingModelMessageData.getDeviceUpMessageStatsWithUid(null, null, null)); + // 下行数据统计 + mainStats.setDeviceDownMessageStats(thingModelMessageData.getDeviceDownMessageStatsWithUid(null, null, null)); + //产品数量统计 + mainStats.setDeviceStatsOfCategory(deviceInfoData.getDeviceStatsByCategory("")); + + //告警总数 + mainStats.setAlertCount(iAlertRecordData.count()); + mainStats.setProductKeyCount(deviceInfoData.getProductDevice(null,null,null)); + // jpaQueryFactory + // iAlertRecordData.findAll(); + //过滤租户关 + //TenantContext.enableTenantFilter(); + return JSONUtil.toJsonPrettyStr(mainStats); + } + @PostMapping("/mainListProduct") + public String mainListProduct(Long deptAreaId,String startDate, String endDate) { + //过滤租户开启 + + TenantContext.disableTenantFilter(); + log.info("Thread {} - TenantFilter disabled: {}", + Thread.currentThread().getId(), + TenantContext.isFilterDisabled()); + + MainStats mainStats = new MainStats(); + + mainStats.setProductKeyCount(deviceInfoData.getProductDevice(deptAreaId,startDate,endDate)); + // jpaQueryFactory + // iAlertRecordData.findAll(); + //过滤租户关 + //TenantContext.enableTenantFilter(); + return JSONUtil.toJsonPrettyStr(mainStats.getProductKeyCount()); + } + + @ApiOperation(value = "设备列表", notes = "设备列表", httpMethod = "POST") + //@SaCheckPermission("iot:device:query") + @PostMapping("/list") + public String getDevices(String productKey,Integer type) { + List list = new ArrayList<>(); + List list1 = new ArrayList<>(); + if(ObjectUtils.isNotEmpty(type) && type==0) { + PageRequest pageRequest = new PageRequest<>(20, 1, null); + pageRequest.setData(new DeviceQueryBo()); + pageRequest.getData().setProductKey(productKey); + list1 = deviceServiceImpl.getDevices(pageRequest).getRows(); + for (DeviceInfoVo deviceInfoVo : list1) { + deviceInfoVo.setOnlineStatus(deviceInfoVo.getOnline()?"在线":"离线"); + deviceInfoVo.setProductName(ObjectUtils.isNotEmpty(deviceInfoVo.getProduct().getName()) ? deviceInfoVo.getProduct().getName():""); + } + return JSONUtil.toJsonPrettyStr(list1); + } + /* for (DeviceInfo deviceInfo : list) { + deviceInfo.setOnlineStatus(deviceInfo.getOnline()?"在线":"离线"); + }*/ + return JSONUtil.toJsonPrettyStr(deviceInfoData.findByConditionsList(productKey)); + } + @ApiOperation("查询告警消息分页") + // @SaCheckPermission("iot:alert:query") + @PostMapping("/mainListAlert") + public String selectAlertRecordList() { + PageRequest request = new PageRequest<>(20, 1, null); + request.setData(new AlertRecord()); + /* DateTimeFormatter formatter = + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.of("Asia/Shanghai")); +*/ + List list = alertService.selectAlertRecordPage(request).getRows(); + for (AlertRecord record : list) { + String formattedTime = Instant.ofEpochMilli(record.getAlertTime()).atZone(ZoneId.of("Asia/Shanghai")) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + //String formattedTime = zonedDateTime.format(formatter); + record.setAlertTimeStats(formattedTime + ); + } + return JSONUtil.toJsonPrettyStr(list); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/UserInfoController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/UserInfoController.java new file mode 100644 index 0000000..2498e4c --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/UserInfoController.java @@ -0,0 +1,219 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.ReflectUtil; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IHomeData; +import cc.iotkit.data.manager.ISpaceData; +import cc.iotkit.data.manager.IUserInfoData; +import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordPageReqVO; +import cc.iotkit.manager.dto.vo.product.ProductVo; +import cc.iotkit.manager.dto.vo.userInfo.UserInfoPageReqVO; +import cc.iotkit.manager.service.DataOwnerService; +import cc.iotkit.model.UserInfo; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.space.Home; +import cc.iotkit.model.space.Space; +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.Collections; +import java.util.List; + +@Api(tags = {"用户"}) +@RestController +@RequestMapping("/user") +public class UserInfoController { + + @Autowired + private IUserInfoData userInfoData; + @Autowired + private IDeviceInfoData ideviceInfoData; + @Autowired + private DataOwnerService ownerService; + @Autowired + private IHomeData homeData; + @Autowired + private ISpaceData spaceData; + + /** + * 平台用户列表 + */ + /* @PostMapping("/platform/users") + public List getPlatformUsers() { + return userInfoData.findByType(UserInfo.USER_TYPE_PLATFORM); + } + + *//** + * 添加平台用户 + *//* + @PostMapping("/platform/user/add") + public void addPlatformUser(@RequestBody UserInfo user) { + try { + user.setType(UserInfo.USER_TYPE_PLATFORM); + user.setRoles(Collections.singletonList(Constants.ROLE_SYSTEM)); + user.setPermissions(Collections.singletonList(Constants.PERMISSION_WRITE)); + user.setSecret(AuthUtil.enCryptPwd(Constants.PWD_SYSTEM_USER)); + userInfoData.save(user); + } catch (Throwable e) { + throw new BizException(ErrCode.ADD_PLATFORM_USER_ERROR, e); + } + } + + *//** + * 重置平台用户密码 + *//* + @PostMapping("/platform/user/{uid}/resetPwd") + public void resetPlatformUserPwd(@PathVariable("uid") String uid) { + try { + UserInfo user = userInfoData.findByUid(uid); + if (user == null) { + throw new BizException(ErrCode.USER_NOT_FOUND); + } + user.setSecret(AuthUtil.enCryptPwd(Constants.PWD_SYSTEM_USER)); + userInfoData.save(user); + } catch (Throwable e) { + throw new BizException(ErrCode.RESET_PWD_ERROR, e); + } + }*/ + + /** + * 客户端用户列表 + */ + @PostMapping("/client/users/list") + public List clientUsers() { + + return userInfoData.findByType(UserInfo.USER_TYPE_CLIENT); + } + /** + * c端用户分页,并查出客户绑定的设备数量 + * */ + @PostMapping("/client/users/page") + public Paging clientUsersList( @Validated @RequestBody PageRequest pageReqVO) { + pageReqVO.getData().setType(UserInfo.USER_TYPE_CLIENT); + + + Paging Paging = userInfoData.findAll(pageReqVO.to(UserInfo.class)); + + for (UserInfo row : Paging.getRows()) { + if(ObjectUtil.isNotNull(row.getId())){ + row.setDeviceCount(ideviceInfoData.countByUid(row.getId().toString())); + } + } + return Paging; + } + /** + * 添加C端用户 + */ + @PostMapping("/client/user/add") + public void addClientUser(@RequestBody Request user) throws Exception { + user.getData().setType(UserInfo.USER_TYPE_CLIENT); + user.getData().setRoles(Collections.singletonList(Constants.ROLE_CLIENT)); + user.getData().setSecret(AuthUtil.enCryptPwd(Constants.PWD_CLIENT_USER)); + userInfoData.save(user.getData()); + + //添加默认家庭 + Home home = homeData.save(Home.builder() + .name("我的家庭") + .address("") + .deviceNum(0) + .spaceNum(0) + .current(true) + .build()); + + //添加默认房间 + for (String name : new String[]{"客厅", "卧室", "厨房"}) { + spaceData.save(Space.builder() + .homeId(home.getId()) + .name(name) + .build()); + } + } + + @PostMapping("/client/user/{id}/delete") + public void deleteClientUser(@PathVariable("id") Long id) { + UserInfo user = userInfoData.findById(id); + if (user == null) { + throw new BizException(ErrCode.USER_NOT_FOUND); + } + userInfoData.deleteById(id); + } + + @PostMapping("/getUserInfo") + public UserInfo getUserInfo() { + return userInfoData.findById(LoginHelper.getUserId()); + } + @PostMapping("/client/user/getDetail") + public UserInfo getDetail(@Validated @RequestBody Request request) { + return userInfoData.findById(request.getData()); + } + @PostMapping("/client/user/save") + public void saveClientUser(@RequestBody UserInfo user) { + UserInfo oldUser = userInfoData.findById(user.getId()); + if (oldUser == null) { + return; + } + ReflectUtil.copyNoNulls(user, oldUser); + userInfoData.save(oldUser); + } + + /** + * 修改密码 + */ + @PostMapping("/{uid}/modifyPwd") + public void modifyPwd(@PathVariable("uid") String uid, String oldPwd, String newPwd) { + UserInfo user = userInfoData.findByUid(uid); + if (user == null) { + throw new BizException(ErrCode.USER_NOT_FOUND); + } + if (!AuthUtil.getUserId().equals(user.getId())) { + throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION); + } + + try { + if (!AuthUtil.checkPwd(oldPwd, user.getSecret())) { + throw new BizException(ErrCode.PWD_ERROR); + } + + user.setSecret(AuthUtil.enCryptPwd(newPwd)); + userInfoData.save(user); + } catch (BizException e) { + throw e; + } catch (Throwable e) { + throw new BizException(ErrCode.UPDATE_PWD_ERROR, e); + } + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/VirtualDeviceController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/VirtualDeviceController.java new file mode 100644 index 0000000..ac7a866 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/VirtualDeviceController.java @@ -0,0 +1,226 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.ReflectUtil; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.data.manager.IVirtualDeviceData; +import cc.iotkit.manager.dto.bo.ChangeStateBo; +import cc.iotkit.manager.dto.bo.device.DeviceLogQueryBo; +import cc.iotkit.manager.dto.bo.device.DeviceSaveScriptBo; +import cc.iotkit.manager.dto.bo.virtualdevice.VirtualSaveDevicesBo; +import cc.iotkit.manager.service.DataOwnerService; +import cc.iotkit.model.device.VirtualDevice; +import cc.iotkit.model.device.VirtualDeviceLog; +import cc.iotkit.temporal.IVirtualDeviceLogData; +import cc.iotkit.virtualdevice.VirtualManager; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Api(tags = {"虚拟设备"}) +@Slf4j +@RestController +@RequestMapping("/virtual_device") +public class VirtualDeviceController { + + @Autowired + private DataOwnerService dataOwnerService; + @Autowired + private IVirtualDeviceData virtualDeviceData; + @Autowired + private VirtualManager virtualManager; + @Autowired + private IVirtualDeviceLogData virtualDeviceLogData; + + @ApiOperation("获取虚拟设备列表") + @SaCheckPermission("iot:virtualDevice:query") + @PostMapping("/list") + public Paging getDevices(@Validated(QueryGroup.class)@RequestBody PageRequest pageRequest) { + return virtualDeviceData.findAll(pageRequest); + } + + /** + * 添加虚拟设备 + */ + @ApiOperation("添加虚拟设备") + @SaCheckPermission("iot:virtualDevice:add") + @PostMapping("/add") + public void add(@Validated @RequestBody Request bo) { + virtualDeviceData.save(bo.getData()); + } + + /** + * 修改虚拟设备 + */ + @ApiOperation("修改虚拟设备") + @SaCheckPermission("iot:virtualDevice:edit") + @PostMapping("/modify") + public void modify(@Validated @RequestBody Request bo) { + VirtualDevice virtualDevice = bo.getData(); + VirtualDevice oldData = checkOwner(virtualDevice.getId()); + ReflectUtil.copyNoNulls(virtualDevice, oldData, + "name", "productKey", "type", "trigger", "triggerExpression"); + if (VirtualDevice.STATE_RUNNING.equals(virtualDevice.getState())) { + virtualManager.remove(oldData); + } + virtualDevice.setState(VirtualDevice.STATE_STOPPED); + virtualDeviceData.save(virtualDevice); + } + + /** + * 获取虚拟设备详情 + */ + @ApiOperation("获取虚拟设备详情") + @SaCheckPermission("iot:virtualDevice:query") + @PostMapping("/getDetail") + public VirtualDevice detail(@Validated @RequestBody Request bo) { + return checkOwner(bo.getData()); + } + + /** + * 设置虚拟设备状态 + */ + @ApiOperation("设置虚拟设备状态") + @SaCheckPermission("iot:virtualDevice:edit") + @PostMapping("/setState") + public void setState(@Validated @RequestBody Request bo) { + ChangeStateBo data = bo.getData(); + String id = data.getId(); + String state = data.getState(); + VirtualDevice oldData = checkOwner(id); + if (!VirtualDevice.STATE_RUNNING.equals(state) + && !VirtualDevice.STATE_STOPPED.equals(state)) { + throw new BizException(ErrCode.STATE_ERROR); + } + oldData.setState(state); + if (VirtualDevice.STATE_RUNNING.equals(state)) { + virtualManager.add(oldData); + } else { + virtualManager.remove(oldData); + } + virtualDeviceData.save(oldData); + } + + /** + * 删除 + */ + @ApiOperation("删除虚拟设备") + @SaCheckPermission("iot:virtualDevice:remove") + @PostMapping("/delete") + public void delete(@Validated @RequestBody Request bo) { + String id = bo.getData(); + checkOwner(id); + virtualDeviceData.deleteById(id); + } + + /** + * 删除 + */ + @ApiOperation("批量删除虚拟设备") + @SaCheckPermission("iot:virtualDevice:remove") + @PostMapping("/batchDelete") + public void batchDelete(@Validated @RequestBody Request> ids) { + virtualDeviceData.deleteByIds(ids.getData()); + } + + /** + * 保存脚本 + */ + @ApiOperation("保存脚本") + @SaCheckPermission("iot:virtualDevice:edit") + @PostMapping("/saveScript") + public void saveScript(@Validated @RequestBody Request bo) { + DeviceSaveScriptBo data = bo.getData(); + String id = data.getId(); + String script = data.getScript(); + VirtualDevice old = checkOwner(id); + old.setScript(script); + virtualDeviceData.save(old); + } + + /** + * 保存关联设备 + */ + @ApiOperation("保存关联设备") + @SaCheckPermission("iot:virtualDevice:edit") + @PostMapping("/saveDevices") + public void saveDevices(@Validated @RequestBody Request bo) { + VirtualSaveDevicesBo data = bo.getData(); + List devices = data.getDevices(); + String id = data.getId(); + VirtualDevice old = checkOwner(id); + old.setDevices(devices); + virtualDeviceData.save(old); + } + + /** + * 手动执行虚拟设备 + */ + @ApiOperation("手动执行虚拟设备") + @SaCheckPermission("iot:virtualDevice:query") + @PostMapping("/run") + public void run(@Validated @RequestBody Request bo) { + String id = bo.getData(); + VirtualDevice virtualDevice = checkOwner(id); + virtualManager.run(virtualDevice); + } + + /** + * 取虚拟设备执行日志 + */ + @ApiOperation("取虚拟设备执行日志") + @SaCheckPermission("iot:virtualDevice:query") + @PostMapping("/logs/list") + public Paging getLogs( + @Validated @RequestBody PageRequest bo) { + DeviceLogQueryBo data = bo.getData(); + + return virtualDeviceLogData.findByVirtualDeviceId(data.getDeviceId(), bo.getPageNum(), bo.getPageSize()); + } + + private VirtualDevice checkOwner(String id) { + VirtualDevice oldData = virtualDeviceData.findById(id); + if (oldData == null) { + throw new BizException(ErrCode.RECORD_NOT_FOUND); + } + + dataOwnerService.checkOwner(oldData); + return oldData; + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/WorderController.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/WorderController.java new file mode 100644 index 0000000..925896e --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/controller/WorderController.java @@ -0,0 +1,82 @@ +package cc.iotkit.manager.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.api.Response; +import cc.iotkit.manager.config.BeanUtils; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationPageReqVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationRespVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationSaveReqVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationVO; +import cc.iotkit.manager.dto.vo.worder.WorderPageReqVO; +import cc.iotkit.manager.dto.vo.worder.WorderRespVO; +import cc.iotkit.manager.dto.vo.worder.WorderSaveReqVO; +import cc.iotkit.manager.service.FeedBackEvaluationService; +import cc.iotkit.manager.service.IWorderService; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import cc.iotkit.model.worder.WorderDO; +import cn.hutool.db.PageResult; +import io.swagger.annotations.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cc.iotkit.common.api.Response.success; + +@Api(tags = {"工单"}) +@Slf4j +@RestController +@RequestMapping("/dWorder") +public class WorderController { + + + @Resource + private IWorderService worderService; + + @PostMapping("/add") + //@Operation(summary = "创建工单") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:create')") + public Long createWorder(@Valid @RequestBody Request createReqVO) { + return worderService.createWorder(createReqVO.getData()); + } + + @PostMapping("/edit") + //@Operation(summary = "更新工单") + // @PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:update')") + public Boolean updateFeedBackEvaluation(@Valid @RequestBody Request updateReqVO) { + worderService.updateWorder(updateReqVO.getData()); + return true; + } + + @PostMapping("/delete") + //@Operation(summary = "删除工单") + //@Parameter(name = "id", description = "编号", required = true) + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:delete')") + public Boolean deleteFeedBackEvaluation(@Validated @RequestBody Request request) { + worderService.deleteWorder(request.getData()); + return true; + } + + @PostMapping("/getDetail") + //@Operation(summary = "获得工单") + //@Parameter(name = "id", description = "编号", required = true, example = "1024") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')") + public WorderDO getFeedBackEvaluation(@Validated @RequestBody Request request) { + WorderDO worderDO = worderService.getWorder(request.getData()); + return worderDO; + } + + @PostMapping("/list") + //@Operation(summary = "获得工单分页") + //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')") + public Paging getFeedBackEvaluationPage(@Validated @RequestBody PageRequest pageReqVO) { + Paging pageResult = worderService.getWorderPage(pageReqVO); + return pageResult; + } + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ChangeStateBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ChangeStateBo.java new file mode 100644 index 0000000..2b28667 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ChangeStateBo.java @@ -0,0 +1,52 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "ChangeStateBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class ChangeStateBo extends BaseDto { + private static final long serialVersionUID = -1L; + + @NotBlank(message = "id不能为空") + @ApiModelProperty(value = "") + private String id; + + + @NotBlank(message = "state不能为空") + @ApiModelProperty(value = "运行状态") + @Size(max = 255, message = "运行状态长度不正确") + private String state; + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/category/CategoryBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/category/CategoryBo.java new file mode 100644 index 0000000..edaf893 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/category/CategoryBo.java @@ -0,0 +1,55 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.category; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.product.Category; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "CategoryBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = Category.class, reverseConvertGenerate = false) +public class CategoryBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + + @ApiModelProperty(value="id") + private String id; + + @ApiModelProperty(value="分类描述") + private Long createAt; + + @ApiModelProperty(value="分类名称") + @Size(max = 255, message = "分类名称长度不正确") + private String name; + + } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/channel/ChannelConfigBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/channel/ChannelConfigBo.java new file mode 100644 index 0000000..ade8206 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/channel/ChannelConfigBo.java @@ -0,0 +1,58 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.channel; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.notify.ChannelConfig; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "ChannelConfigBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = ChannelConfig.class) +public class ChannelConfigBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value="id") + private Long id; + + @ApiModelProperty(value="通道id") + private Long channelId; + + @ApiModelProperty(value="通道配置名称") + private String title; + + @ApiModelProperty(value="通道配置参数") + private String param; + + @ApiModelProperty(value="创建时间") + private Long createAt; + + } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/channel/ChannelTemplateBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/channel/ChannelTemplateBo.java new file mode 100644 index 0000000..ec894b0 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/channel/ChannelTemplateBo.java @@ -0,0 +1,62 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.channel; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.notify.ChannelTemplate; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel(value = "ChannelTemplateVo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = ChannelTemplate.class, reverseConvertGenerate = false) +public class ChannelTemplateBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value="通道模板id") + @ExcelProperty(value = "通道模板id") + private Long id; + + @ApiModelProperty(value="通道配置id") + @ExcelProperty(value = "通道配置id") + private Long channelConfigId; + + @ApiModelProperty(value="通道模板名称") + @ExcelProperty(value = "通道模板名称") + private String title; + + @ApiModelProperty(value="通道模板内容") + @ExcelProperty(value = "通道模板内容") + private String content; + + @ApiModelProperty(value="创建时间") + @ExcelProperty(value = "创建时间") + private Long createAt; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceConsumerBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceConsumerBo.java new file mode 100644 index 0000000..fd41d91 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceConsumerBo.java @@ -0,0 +1,49 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.device; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "DeviceConsumerBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class DeviceConsumerBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @NotBlank(message = "deviceId不能为空") + @ApiModelProperty(value = "设备id") + private String deviceId; + + @NotBlank(message = "clientId不能为空") + @ApiModelProperty(value = "clientId") + private String clientId; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceInfoBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceInfoBo.java new file mode 100644 index 0000000..672ae28 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceInfoBo.java @@ -0,0 +1,94 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.device; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.device.DeviceInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "DeviceInfoBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DeviceInfo.class, reverseConvertGenerate = false) +public class DeviceInfoBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + private String id; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "设备id") + @Size(max = 255, message = "设备id长度不正确") + private String deviceId; + + @ApiModelProperty(value = "设备名称") + @Size(max = 255, message = "设备名称长度不正确") + private String deviceName; + + @ApiModelProperty(value = "设备类型") + @Size(max = 255, message = "设备类型长度不正确") + private String model; + + @ApiModelProperty(value = "设备离线时间") + private Long offlineTime; + + @ApiModelProperty(value = "设备在线时间") + private Long onlineTime; + + @ApiModelProperty(value = "父级id") + @Size(max = 255, message = "父级id长度不正确") + private String parentId; + + @ApiModelProperty(value = "产品key") + @Size(max = 255, message = "产品key长度不正确") + @NotBlank(message = "产品Key不能为空") + private String productKey; + + @ApiModelProperty(value = "设备描述") + @Size(max = 255, message = "设备描述长度不正确") + private String secret; + + @ApiModelProperty(value = "经度") + private String longitude; + + @ApiModelProperty(value = "纬度") + private String latitude; + @ApiModelProperty(value="部门表-区域id") + private Long deptAreaId; + @ApiModelProperty(value = "用户id") + @Size(max = 255, message = "用户id长度不正确") + private String uid; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceLogQueryBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceLogQueryBo.java new file mode 100644 index 0000000..a903cc8 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceLogQueryBo.java @@ -0,0 +1,47 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.dto.bo.device; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.manager.model.vo.DeviceLog; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel(value = "DeviceLogQueryBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DeviceLog.class, reverseConvertGenerate = false) +public class DeviceLogQueryBo extends BaseDto { + + @ApiModelProperty(value="设备id") + private String deviceId; + + @ApiModelProperty(value="类型") + private String type; + + @ApiModelProperty(value="属性名") + private String identifier; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DevicePropertyLogQueryBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DevicePropertyLogQueryBo.java new file mode 100644 index 0000000..b6c7904 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DevicePropertyLogQueryBo.java @@ -0,0 +1,45 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.dto.bo.device; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel(value = "DevicePropertiesLogQueryBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class DevicePropertyLogQueryBo extends BaseDto { + + + @ApiModelProperty(value="设备id") + private String deviceId; + @ApiModelProperty(value="属性名称") + private String name; + @ApiModelProperty(value="开始时间") + private long start; + @ApiModelProperty(value="结束时间") + private long end; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryBo.java new file mode 100644 index 0000000..20dab1d --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryBo.java @@ -0,0 +1,80 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.dto.bo.device; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.device.DeviceInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel(value = "DeviceQueryBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class DeviceQueryBo extends BaseDto { + + + @ApiModelProperty(value="关键字") + private String keyword; + + @ApiModelProperty(value="分组") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String group; + + @ApiModelProperty(value="设备id") + @Size(max = 255, message = "设备id长度不正确") + private String deviceId; + + @ApiModelProperty(value="设备名称") + @Size(max = 255, message = "设备名称长度不正确") + private String deviceName; + + @ApiModelProperty(value="设备类型") + @Size(max = 255, message = "设备类型长度不正确") + private String model; + + @ApiModelProperty(value="父级id") + @Size(max = 255, message = "父级id长度不正确") + private String parentId; + + @ApiModelProperty(value="产品key") + @Size(max = 255, message = "产品key长度不正确") + private String productKey; + + + @ApiModelProperty(value="设备状态") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private Boolean online; + + @ApiModelProperty(value="用户id") + @Size(max = 255, message = "用户id长度不正确") + private String uid; + private Long deptAreaId; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryByPkDnBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryByPkDnBo.java new file mode 100644 index 0000000..88a4034 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceQueryByPkDnBo.java @@ -0,0 +1,49 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.device; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "DeviceQueryByPkDnBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class DeviceQueryByPkDnBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @NotBlank(message = "产品key不能为空") + @ApiModelProperty(value = "产品key") + private String pk; + + @NotBlank(message = "设备不能为空") + @ApiModelProperty(value = "设备") + private String dn; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceSaveScriptBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceSaveScriptBo.java new file mode 100644 index 0000000..ced0ada --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceSaveScriptBo.java @@ -0,0 +1,49 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.device; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "DeviceSaveScriptBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class DeviceSaveScriptBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @NotBlank(message = "id不能为空") + @ApiModelProperty(value = "id") + private String id; + + + @ApiModelProperty(value = "脚本") + private String script; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceTagAddBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceTagAddBo.java new file mode 100644 index 0000000..108fd02 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/DeviceTagAddBo.java @@ -0,0 +1,53 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.dto.bo.device; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.device.DeviceInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel(value = "DeviceTagAddBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DeviceInfo.Tag.class, reverseConvertGenerate = false) +public class DeviceTagAddBo extends BaseDto { + + + @ApiModelProperty(value="设备") + private String deviceId; + + + @ApiModelProperty(value="tag id") + + private String id; + @ApiModelProperty(value="tag名称") + + private String name; + @ApiModelProperty(value="tag值") + + private String value; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/GetDeviceServicePorpertyBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/GetDeviceServicePorpertyBo.java new file mode 100644 index 0000000..daf1f35 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/GetDeviceServicePorpertyBo.java @@ -0,0 +1,49 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.device; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; + +import java.util.List; + +/** + * @author: regan + * @description: + * @date:created in 2023/6/17 12:17 + * @modificed by: + */ +@ApiModel(value = "GetDeviceServicePorpertyBo") +@Data +public class GetDeviceServicePorpertyBo { + @ApiModelProperty(value="设备id",required = true) + @NotBlank + private String deviceId; + + @ApiModelProperty(value="属性列表") + private List propertyNames; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/ServiceInvokeBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/ServiceInvokeBo.java new file mode 100644 index 0000000..a4b3317 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/ServiceInvokeBo.java @@ -0,0 +1,51 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.device; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; + +import java.util.Map; + +/** + * @author: regan + * @description: + * @date:created in 2023/6/17 12:17 + * @modificed by: + */ +@ApiModel(value = "ServiceInvokeBo") +@Data +public class ServiceInvokeBo { + @ApiModelProperty(value="设备id",required = true) + @NotBlank + private String deviceId; + @ApiModelProperty(value="服务",required = true) + @NotBlank + private String service; + @ApiModelProperty(value="参数") + private Map args; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/SetDeviceServicePorpertyBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/SetDeviceServicePorpertyBo.java new file mode 100644 index 0000000..bedb727 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/device/SetDeviceServicePorpertyBo.java @@ -0,0 +1,48 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.device; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; + +import java.util.Map; + +/** + * @author: regan + * @description: + * @date:created in 2023/6/17 12:17 + * @modificed by: + */ +@ApiModel(value = "SetDeviceServicePorpertyBo") +@Data +public class SetDeviceServicePorpertyBo { + @ApiModelProperty(value="设备id",required = true) + @NotBlank + private String deviceId; + @ApiModelProperty(value="参数") + private Map args; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/deviceconfig/DeviceConfigAddBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/deviceconfig/DeviceConfigAddBo.java new file mode 100644 index 0000000..3bfce3d --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/deviceconfig/DeviceConfigAddBo.java @@ -0,0 +1,54 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.deviceconfig; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.device.DeviceConfig; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "DeviceConfigAddBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DeviceConfig.class, reverseConvertGenerate = false) +public class DeviceConfigAddBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "设备配置json内容") + @Size(max = 65535, message = "设备配置json内容长度不正确") + private String config; + + + @ApiModelProperty(value = "设备id") + @Size(max = 255, message = "设备id长度不正确") + private String deviceId; + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/deviceconfig/DeviceConfigBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/deviceconfig/DeviceConfigBo.java new file mode 100644 index 0000000..5bc25a4 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/deviceconfig/DeviceConfigBo.java @@ -0,0 +1,63 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.deviceconfig; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.device.DeviceConfig; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "DeviceConfigBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DeviceConfig.class, reverseConvertGenerate = false) +public class DeviceConfigBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "设备配置json内容") + @Size(max = 65535, message = "设备配置json内容长度不正确") + private String config; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "设备id") + @Size(max = 255, message = "设备id长度不正确") + private String deviceId; + + @ApiModelProperty(value = "设备名称") + @Size(max = 255, message = "设备名称长度不正确") + private String deviceName; + + @ApiModelProperty(value = "产品key") + @Size(max = 255, message = "产品key长度不正确") + private String productKey; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/devicegroup/DeviceAddGroupBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/devicegroup/DeviceAddGroupBo.java new file mode 100644 index 0000000..644d519 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/devicegroup/DeviceAddGroupBo.java @@ -0,0 +1,47 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.devicegroup; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + + +@ApiModel(value = "DeviceAddGroupBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class DeviceAddGroupBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty("组id") + private String group; + @ApiModelProperty("设备列表") + private List devices; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/devicegroup/DeviceGroupBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/devicegroup/DeviceGroupBo.java new file mode 100644 index 0000000..99278a2 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/devicegroup/DeviceGroupBo.java @@ -0,0 +1,66 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.devicegroup; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.device.DeviceGroup; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "DeviceGroupBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DeviceGroup.class, reverseConvertGenerate = false) +public class DeviceGroupBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "分组id") + private String id; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "设备数量") + private Integer deviceQty; + + @ApiModelProperty(value = "设备组名称") + @Size(max = 255, message = "设备组名称长度不正确") + private String name; + + @ApiModelProperty(value = "分组说明") + @Size(max = 255, message = "分组说明长度不正确") + private String remark; + + @ApiModelProperty(value = "所属用户") + @Size(max = 255, message = "所属用户长度不正确") + private String uid; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/DeviceOtaDetailBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/DeviceOtaDetailBo.java new file mode 100644 index 0000000..ef65659 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/DeviceOtaDetailBo.java @@ -0,0 +1,54 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.ota; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.ota.DeviceOtaDetail; +import cc.iotkit.model.ota.DeviceOtaInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @Author: 石恒 + * @Date: 2023/6/17 20:45 + * @Description: + */ +@Data +@ApiModel(value = "DeviceOtaDetailBo") +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DeviceOtaDetail.class, reverseConvertGenerate = false) +public class DeviceOtaDetailBo extends BaseDto { + + private Long otaInfoId; + + private String version; + + private String deviceId; + + private String productKey; + + private String deviceName; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/DeviceOtaInfoBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/DeviceOtaInfoBo.java new file mode 100644 index 0000000..b678378 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/DeviceOtaInfoBo.java @@ -0,0 +1,57 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.ota; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.ota.DeviceOtaInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @Author: 石恒 + * @Date: 2023/6/17 20:45 + * @Description: + */ +@Data +@ApiModel(value = "DeviceOtaInfoBo") +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DeviceOtaInfo.class, reverseConvertGenerate = false) +public class DeviceOtaInfoBo extends BaseDto { + + private Long id; + + private Long packageId; + + private String taskId; + + private String version; + + private String deviceId; + + private String productKey; + + private String deviceName; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/DeviceUpgradeBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/DeviceUpgradeBo.java new file mode 100644 index 0000000..c12a65e --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/DeviceUpgradeBo.java @@ -0,0 +1,45 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.ota; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +/** + * @Author: 石恒 + * @Date: 2023/6/16 21:13 + * @Description: + */ +@ApiModel(value = "DeviceUpgradeBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class DeviceUpgradeBo extends BaseDto { + private static final long serialVersionUID = -1L; + private List deviceIds; + private Long otaId; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/OtaPackageBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/OtaPackageBo.java new file mode 100644 index 0000000..6d93510 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ota/OtaPackageBo.java @@ -0,0 +1,102 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.ota; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.ota.OtaPackage; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @Author: 石恒 + * @Date: 2023/6/27 22:09 + * @Description: + */ +@ApiModel(value = "OtaPackageBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = OtaPackage.class, reverseConvertGenerate = false) +public class OtaPackageBo extends BaseDto { + + /** + * 文件包大小 + */ + private Long size; + + /** + * 签名 + */ + private String sign; + + /** + * 是否差分升级 + */ + private Boolean isDiff; + + /** + * 文件MD5后的值 + */ + private String md5; + + /** + * 包名 + */ + private String name; + + /** + * 描述 + */ + private String desc; + + /** + * 版本 + */ + private String version; + + /** + * 升级包地址 + */ + private String url; + + /** + * 签名方式 + */ + private String signMethod; + + /** + * 模块 + */ + private String module; + + /** + * 扩展数据 + */ + private String extData; + /** + * 产品key + */ + private String productKey; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/plugin/PluginInfoBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/plugin/PluginInfoBo.java new file mode 100644 index 0000000..5083382 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/plugin/PluginInfoBo.java @@ -0,0 +1,88 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.plugin; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.plugin.PluginInfo; +import io.github.linpeilie.annotations.AutoMapper; +import javax.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 插件业务对象 + * + * @author sjg + */ +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = PluginInfo.class, reverseConvertGenerate = false) +public class PluginInfoBo extends BaseDto { + + /** + * id + */ + @NotNull(message = "插件id不能为空", groups = {EditGroup.class}) + private Long id; + + /** + * 插件名称 + */ + @NotNull(message = "插件名称不能为空", groups = {AddGroup.class, EditGroup.class}) + private String name; + + /** + * 部署方式 + */ + @NotNull(message = "部署方式不能为空", groups = {AddGroup.class, EditGroup.class}) + private String deployType; + + /** + * 插件类型 + */ + private String type; + + /** + * 设备插件协议类型 + */ + private String protocol; + + /** + * 状态 + */ + private String state; + + /** + * 插件配置信息 + */ + private String config; + + /** + * 插件脚本 + */ + private String script; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/IconBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/IconBo.java new file mode 100644 index 0000000..b03d0f9 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/IconBo.java @@ -0,0 +1,66 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.product; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.product.Icon; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "IconBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = Icon.class, reverseConvertGenerate = false) +public class IconBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "id") + private Long id; + + @ApiModelProperty(value = "图标分类id") + private Long iconTypeId; + + @ApiModelProperty(value = "图标名称") + private String iconName; + + @ApiModelProperty(value = "视窗缩放") + private String viewBox; + + @ApiModelProperty(value = "命名空间") + private String xmlns; + + @ApiModelProperty(value = "版本") + private String version; + + @Size(max = 65535, message = "图标内容长度不正确") + @ApiModelProperty(value = "图标内容") + private String iconContent; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/IconTypeBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/IconTypeBo.java new file mode 100644 index 0000000..18c23fc --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/IconTypeBo.java @@ -0,0 +1,52 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.product; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.product.IconType; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "IconTypeBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = IconType.class, reverseConvertGenerate = false) +public class IconTypeBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "id") + private Long id; + + @ApiModelProperty(value = "分类名称") + private String typeName; + + @ApiModelProperty(value = "分类描述") + private String typeDescribe; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/ProductBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/ProductBo.java new file mode 100644 index 0000000..a5db850 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/ProductBo.java @@ -0,0 +1,99 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.product; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.product.Product; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Min; +import org.hibernate.validator.constraints.NotBlank; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "ProductBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = Product.class, reverseConvertGenerate = false) +public class ProductBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "id") + private Long id; + @ApiModelProperty(value = "productKey") + private String productKey; + + @ApiModelProperty(value = "品类") + @Size(max = 255, message = "品类长度不正确") + private String category; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "图片") + @Size(max = 255, message = "图片长度不正确") + private String img; + + @ApiModelProperty(value = "产品图标ID") + private Long iconId; + + @ApiModelProperty(value = "产品名称") + @Size(max = 255, message = "产品名称长度不正确") + private String name; + + @ApiModelProperty(value = "节点类型") + private Integer nodeType; + + @ApiModelProperty(value = "是否透传,true/false") + private Boolean transparent; + + @ApiModelProperty(value = "是否开启设备定位,true/false") + private Boolean isOpenLocate; + + @ApiModelProperty(value = "定位更新方式") + private String locateUpdateType; + + @ApiModelProperty(value = "用户ID") + @Size(max = 255, message = "用户ID长度不正确") + private String uid; + + @ApiModelProperty(value = "产品密钥") + @Size(max = 255, message = "产品密钥长度不正确") + private String productSecret; + + @ApiModelProperty(value = "保活时长") + @NotNull(message = "保活时长不能为空",groups = { AddGroup.class, EditGroup.class }) + private Long keepAliveTime; + @ApiModelProperty(value = "0是报警器1是其它") + // @NotNull(message = "保活时长不能为空",groups = { AddGroup.class, EditGroup.class }) + private Integer productType; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/ProductListReqBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/ProductListReqBo.java new file mode 100644 index 0000000..975fd46 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/product/ProductListReqBo.java @@ -0,0 +1,52 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.product; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.product.Product; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.Size; + + +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = ProductBo.class, reverseConvertGenerate = false) +public class ProductListReqBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + + @ApiModelProperty(value = "productKey") + private String productKey; + + @ApiModelProperty(value = "产品名称") + @Size(max = 255, message = "产品名称长度不正确") + private String name; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/productmodel/ProductModelBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/productmodel/ProductModelBo.java new file mode 100644 index 0000000..e9ef843 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/productmodel/ProductModelBo.java @@ -0,0 +1,74 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.productmodel; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.product.ProductModel; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "ProductModelBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = ProductModel.class, reverseConvertGenerate = false) +public class ProductModelBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value="id") + private String id; + + @ApiModelProperty(value="型号") + @Size(max = 255, message = "型号长度不正确") + private String model; + + @ApiModelProperty(value="修改时间") + private Long modifyAt; + + @ApiModelProperty(value="名称") + @Size(max = 255, message = "名称长度不正确") + private String name; + + @ApiModelProperty(value="产品Key") + @Size(max = 255, message = "产品Key长度不正确") + private String productKey; + + @ApiModelProperty(value="脚本内容") + @Size(max = 65535, message = "脚本内容长度不正确") + private String script; + + @ApiModelProperty(value="脚本状态") + @Size(max = 255, message = "脚本状态长度不正确") + private String state; + + @ApiModelProperty(value="脚本类型") + @Size(max = 255, message = "脚本类型长度不正确") + private String type; + + } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ruleinfo/RuleInfoBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ruleinfo/RuleInfoBo.java new file mode 100644 index 0000000..f347029 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ruleinfo/RuleInfoBo.java @@ -0,0 +1,82 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.ruleinfo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.rule.FilterConfig; +import cc.iotkit.model.rule.RuleAction; +import cc.iotkit.model.rule.RuleInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +@ApiModel(value = "RuleInfoBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = RuleInfo.class, reverseConvertGenerate = false) +public class RuleInfoBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "id") + private String id; + + @ApiModelProperty(value = "动作") + private List actions; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "描述") + @Size(max = 255, message = "描述长度不正确") + private String desc; + + @ApiModelProperty(value = "过滤器") + private List filters; + + @ApiModelProperty(value = "监听器") + private List listeners; + + @ApiModelProperty(value = "规则名称") + @Size(max = 255, message = "规则名称长度不正确") + private String name; + + @ApiModelProperty(value = "状态") + @Size(max = 255, message = "状态长度不正确") + private String state; + + @ApiModelProperty(value = "规则类型") + @Size(max = 255, message = "规则类型长度不正确") + private String type; + + @ApiModelProperty(value = "用户id") + @Size(max = 255, message = "用户id长度不正确") + private String uid; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ruleinfo/RuleLogBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ruleinfo/RuleLogBo.java new file mode 100644 index 0000000..19b9dd1 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/ruleinfo/RuleLogBo.java @@ -0,0 +1,57 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.ruleinfo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.rule.RuleLog; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel(value = "RuleLogBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = RuleLog.class, reverseConvertGenerate = false) +public class RuleLogBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value="时间") + private Long time; + + @ApiModelProperty(value="规则id") + private String ruleId; + + @ApiModelProperty(value="状态") + private String state1; + + @ApiModelProperty(value="内容") + private String content; + + @ApiModelProperty(value="是否成功") + private Boolean success; + + } diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/screen/DebugChangeBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/screen/DebugChangeBo.java new file mode 100644 index 0000000..d7d0d7c --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/screen/DebugChangeBo.java @@ -0,0 +1,46 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.screen; + +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; + +/** + * @Author:tfd + * @Date:2023/6/26 11:23 + */ +@Data +public class DebugChangeBo { + + private static final long serialVersionUID = -1L; + + @NotBlank(message = "id不能为空") + @ApiModelProperty(value = "id") + private Long id; + + @NotBlank(message = "转换状态不能为空") + @ApiModelProperty(value = "转换状态") + private Boolean state; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/screen/PublishChangeBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/screen/PublishChangeBo.java new file mode 100644 index 0000000..66cf70f --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/screen/PublishChangeBo.java @@ -0,0 +1,52 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.screen; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "ChangeStateBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class PublishChangeBo extends BaseDto { + private static final long serialVersionUID = -1L; + + @NotBlank(message = "id不能为空") + @ApiModelProperty(value = "") + private Long id; + + + @NotBlank(message = "state不能为空") + @ApiModelProperty(value = "运行状态") + @Size(max = 255, message = "运行状态长度不正确") + private String state; + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/space/HomeBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/space/HomeBo.java new file mode 100644 index 0000000..1044f4a --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/space/HomeBo.java @@ -0,0 +1,77 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.dto.bo.space; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.space.Home; +import cc.iotkit.model.space.Space; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.*; + +import java.util.List; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = Home.class, reverseConvertGenerate = false) +public class HomeBo extends BaseDto { + + private Long id; + + /** + * 家庭名称 + */ + private String name; + + /** + * 家庭地址 + */ + private String address; + + /** + * 关联用户id + */ + private Long userId; + + /** + * 空间数量 + */ + private Integer spaceNum; + + /** + * 设备数量 + */ + private Integer deviceNum; + + /** + * 是否为用户当前使用的家庭 + */ + private Boolean current; + + /** + * 空间对象 + */ + private List spaces; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/taskinfo/TaskInfoBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/taskinfo/TaskInfoBo.java new file mode 100644 index 0000000..8a8addb --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/taskinfo/TaskInfoBo.java @@ -0,0 +1,91 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.taskinfo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.rule.RuleAction; +import cc.iotkit.model.rule.TaskInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + + +@ApiModel(value = "TaskInfoBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = TaskInfo.class, reverseConvertGenerate = false) +public class TaskInfoBo extends BaseDto { + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "id") + private String id; + + @ApiModelProperty(value = "任务输出") + private List actions; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "描述") + @Size(max = 255, message = "描述长度不正确") + private String desc; + + @ApiModelProperty(value = "表达式") + @Size(max = 255, message = "表达式长度不正确") + private String expression; + + @ApiModelProperty(value = "任务名称") + @Size(max = 255, message = "任务名称长度不正确") + private String name; + + @ApiModelProperty(value = "操作备注") + @Size(max = 255, message = "操作备注长度不正确") + private String reason; + + @ApiModelProperty(value = "任务状态") + @Size(max = 255, message = "任务状态长度不正确") + private String state; + + @ApiModelProperty(value = "任务类型") + @Size(max = 255, message = "任务类型长度不正确") + private String type; + + @ApiModelProperty(value = "延时时长秒") + private Integer seconds; + + @ApiModelProperty(value = "创建者") + @Size(max = 255, message = "创建者长度不正确") + private String uid; + + public void setSeconds(Integer seconds) { + if (TaskInfo.TYPE_DELAY.equals(getType())) { + setExpression("" + seconds); + } + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/taskinfo/TaskLogBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/taskinfo/TaskLogBo.java new file mode 100644 index 0000000..299fb7f --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/taskinfo/TaskLogBo.java @@ -0,0 +1,47 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.dto.bo.taskinfo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.rule.TaskLog; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel(value = "TaskLogBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = TaskLog.class, reverseConvertGenerate = false) +public class TaskLogBo extends BaseDto { + + private String id; + + private String taskId; + + private String content; + + private Boolean success; + + private Long logAt; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/thingmodel/ThingModelBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/thingmodel/ThingModelBo.java new file mode 100644 index 0000000..951e939 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/thingmodel/ThingModelBo.java @@ -0,0 +1,57 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.thingmodel; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.product.ThingModel; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "ThingModelBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = ThingModel.class, reverseConvertGenerate = false) +public class ThingModelBo extends BaseDto { + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "模型内容") + @Size(max = 65535, message = "模型内容长度不正确") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String model; + + @ApiModelProperty(value = "产品key") + @NotBlank(message = "产品Key不许为空") + private String productKey; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/thingmodel/ThingModelMessageBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/thingmodel/ThingModelMessageBo.java new file mode 100644 index 0000000..05df09e --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/thingmodel/ThingModelMessageBo.java @@ -0,0 +1,100 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.dto.bo.thingmodel; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.thing.ThingModelMessage; +import io.github.linpeilie.annotations.AutoMapper; +import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.HashMap; +import java.util.Map; + +/** + * 物模型消息 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@AutoMapper(target = ThingModelMessage.class, reverseConvertGenerate = false) + +public class ThingModelMessageBo extends BaseDto { + + + private String id; + + private String mid; + @NotNull(message = "设备ID不能为空") + private String deviceId; + + private String productKey; + + private String deviceName; + + /** + * 所属用户ID + */ + private String uid; + + /** + * 消息类型 + * lifetime:生命周期 + * state:状态 + * property:属性 + * event:事件 + * service:服务 + */ + private String type; + + private String identifier; + + /** + * 消息状态码 + */ + private int code; + + private Object data; + + /** + * 时间戳,设备上的事件或数据产生的本地时间 + */ + private Long occurred; + + /** + * 消息上报时间 + */ + private Long time; + + public Map dataToMap() { + Map mapData = new HashMap<>(); + if (data instanceof Map) { + ((Map) data).forEach((key, value) -> mapData.put(key.toString(), value)); + } + return mapData; + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/virtualdevice/VirtualSaveDevicesBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/virtualdevice/VirtualSaveDevicesBo.java new file mode 100644 index 0000000..076abaf --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/virtualdevice/VirtualSaveDevicesBo.java @@ -0,0 +1,51 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.bo.virtualdevice; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + + +@ApiModel(value = "VirtualSaveDevicesBo") +@Data +@EqualsAndHashCode(callSuper = true) +public class VirtualSaveDevicesBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + @NotBlank(message = "id不能为空") + @ApiModelProperty(value = "id") + private String id; + + + @ApiModelProperty(value = "设备id列表") + private List devices; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationPageReqVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationPageReqVO.java new file mode 100644 index 0000000..f351d50 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationPageReqVO.java @@ -0,0 +1,80 @@ +package cc.iotkit.manager.dto.vo.FeedBackEvaluation; + + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import cc.iotkit.model.iccid.DIccidRecordDO; +import com.alibaba.excel.annotation.ExcelProperty; +import com.sun.xml.bind.v2.TODO; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.io.Serializable; +import java.time.LocalDateTime; + + +//@Schema(description = "管理后台 - 物联网卡分页 Request VO") +@ApiModel(value = "FeedBackEvaluationPageReqVO") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = FeedBackEvaluationDO.class, reverseConvertGenerate = false) +//@ToString(callSuper = true) +public class FeedBackEvaluationPageReqVO extends BaseDto{ + private static final long serialVersionUID = -1L; + /** + * ID + */ + + private Long id; + /** + * 内容 + */ + private String content; + /** + * 问题截图 + */ + private String problemScreenshot; + /** + * 消息 + */ + private String message; + /** + * 客户姓名 + */ + private String customerName; + /** + * 评价类型1意见反馈,2用户评价,3师傅评价 + * + * 枚举 {@link TODO evaluation_type 对应的类} + */ + private String evaluationType; + /** + * 服务满意度 + */ + private String serviceSatisfaction; + /** + * 设备ID + */ + private String deviceId; + /** + * 工单ID + */ + private String worderId; + /** + * 问题是否解决1解决2未解决 + * + * 枚举 {@link TODO is_solve 对应的类} + */ + private String isSolve; + /** + * 客户电话 + */ + private String customerPhone; + /** + *租户id + */ + private Long tenantId; +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationRespVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationRespVO.java new file mode 100644 index 0000000..ca14453 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationRespVO.java @@ -0,0 +1,67 @@ +package cc.iotkit.manager.dto.vo.FeedBackEvaluation; + + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import com.fasterxml.jackson.annotation.JsonFormat; + +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +//@Schema(description = "管理后台 - 意见反馈评价 Response VO") +@Data +@ExcelIgnoreUnannotated +public class FeedBackEvaluationRespVO { + + + @ExcelProperty("ID") + private Long id; + + + @ExcelProperty("内容") + private String content; + + @ExcelProperty("问题截图") + private String problemScreenshot; + + @ExcelProperty("消息") + private String message; + + @ExcelProperty("客户姓名") + private String customerName; + + + @ExcelProperty(value = "评价类型1意见反馈,2用户评价,3师傅评价 ") + + private String evaluationType; + + + @ExcelProperty("服务满意度") + private String serviceSatisfaction; + + + @ExcelProperty("设备ID") + private String deviceId; + + + @ExcelProperty("工单ID") + private String worderId; + + + @ExcelProperty(value = "问题是否解决1解决2未解决") + + private String isSolve; + + + @ExcelProperty("客户电话") + private String customerPhone; + + + @ExcelProperty("创建时间") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationSaveReqVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationSaveReqVO.java new file mode 100644 index 0000000..dd69e08 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationSaveReqVO.java @@ -0,0 +1,47 @@ +package cc.iotkit.manager.dto.vo.FeedBackEvaluation; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +//@Schema(description = "管理后台 - 意见反馈评价新增/修改 Request VO") +@Data +@NoArgsConstructor +@AllArgsConstructor +public class FeedBackEvaluationSaveReqVO { + + // @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED) + private Long id; + + // @Schema(description = "内容") + private String content; + + // @Schema(description = "问题截图") + private String problemScreenshot; + + // @Schema(description = "消息") + private String message; + + // @Schema(description = "客户姓名") + private String customerName; + + // @Schema(description = "评价类型1意见反馈,2用户评价,3师傅评价 ") + private String evaluationType; + + // @Schema(description = "服务满意度") + private String serviceSatisfaction; + + // @Schema(description = "设备ID") + private String deviceId; + + // @Schema(description = "工单ID") + private String worderId; + + // @Schema(description = "问题是否解决1解决2未解决") + private String isSolve; + + // @Schema(description = "客户电话") + private String customerPhone; + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationVO.java new file mode 100644 index 0000000..cae0474 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/FeedBackEvaluation/FeedBackEvaluationVO.java @@ -0,0 +1,80 @@ +package cc.iotkit.manager.dto.vo.FeedBackEvaluation; + + +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import cc.iotkit.model.iccid.DIccidRecordDO; +import cc.iotkit.model.plugin.PluginInfo; +import cc.iotkit.model.product.Product; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.sun.xml.bind.v2.TODO; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.*; + +import java.io.Serializable; + +// 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 + + +@ApiModel(value = "FeedBackEvaluationVO") +@Data +@AutoMapper(target = FeedBackEvaluationDO.class) +public class FeedBackEvaluationVO implements Serializable { + + private static final long serialVersionUID = -1L; + /** + * ID + */ + + private Long id; + /** + * 内容 + */ + private String content; + /** + * 问题截图 + */ + private String problemScreenshot; + /** + * 消息 + */ + private String message; + /** + * 客户姓名 + */ + private String customerName; + /** + * 评价类型1意见反馈,2用户评价,3师傅评价 + * + * 枚举 {@link TODO evaluation_type 对应的类} + */ + private String evaluationType; + /** + * 服务满意度 + */ + private String serviceSatisfaction; + /** + * 设备ID + */ + private String deviceId; + /** + * 工单ID + */ + private String worderId; + /** + * 问题是否解决1解决2未解决 + * + * 枚举 {@link TODO is_solve 对应的类} + */ + private String isSolve; + /** + * 客户电话 + */ + private String customerPhone; + /** + *租户id + */ + private Long tenantId; + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/CategoryVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/CategoryVo.java new file mode 100644 index 0000000..3013bec --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/CategoryVo.java @@ -0,0 +1,60 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.category; + +import cc.iotkit.model.product.Category; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + + +@ApiModel(value = "CategoryVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = Category.class) + +public class CategoryVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value="分类id") + @ExcelProperty(value = "分类id") + private String id; + + @ApiModelProperty(value="分类描述") + @ExcelProperty(value = "分类描述") + private Long createAt; + + @ApiModelProperty(value="分类名称") + @ExcelProperty(value = "分类名称") + private String name; + + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordListSaveReqVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordListSaveReqVO.java new file mode 100644 index 0000000..075ed6d --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordListSaveReqVO.java @@ -0,0 +1,74 @@ +package cc.iotkit.manager.dto.vo.category.vo; + +import cc.iotkit.model.iccid.DIccidRecordDO; +import com.alibaba.excel.annotation.ExcelProperty; + +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Builder; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.time.LocalDateTime; + + +//@Schema(description = "管理后台 - 物联网卡新增/修改 Request VO") +@ApiModel(value = "DIccidRecordListSaveReqVO") +@Data +@Builder +//@AutoMapper(target = TbDIccidRecordDO.class) +public class DIccidRecordListSaveReqVO implements Serializable { + private static final long serialVersionUID = -1L; + // @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "23580") + private Long id; + + // @Schema(description = "厂商编号|合作商编号", example = "张三") + @NotNull(message = "厂商编号不能为空") + private String userCode; + + // @Schema(description = "物联网卡号", example = "6236") + @NotNull(message = "厂商物联网卡iccid不能为空") + private String iccid; + + // @Schema(description = "物联网卡运营商", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "物联网卡运营商不能为空") + private Integer simType; + + // @Schema(description = "发货日期") + private String dateline; + + // @Schema(description = "状态(0,已授权,1未授权,2未支付)") + private Integer state; + + // @Schema(description = "订单id", example = "7866") + private String orderId; + + // @Schema(description = "授权码") + private String authorizationCode; + + // @Schema(description = "物联网卡来源0-其他 1-官方") + private Integer source; + + // @Schema(description = "厂商名称|合作商名称") + private String user; + + // @Schema(description = "imei") + private String imei; + // @Schema(description = "逻辑删除;0:未删除(默认);1:已删除") + private Integer deleted; + // @Schema(description = "有效天数") + @ExcelProperty("有效天数") + private Integer validDays; + + //@Schema(description = "到期时间") + // @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime expirationTime; + + @NotNull(message = "物联网卡运营商不能为空") + private Integer startIccid; + @NotNull(message = "起始后缀ICCID") + private Integer endIccid; + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordPageReqVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordPageReqVO.java new file mode 100644 index 0000000..607d92e --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordPageReqVO.java @@ -0,0 +1,74 @@ +package cc.iotkit.manager.dto.vo.category.vo; + + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.iccid.DIccidRecordDO; +import cc.iotkit.model.rule.TaskInfo; +import com.alibaba.excel.annotation.ExcelProperty; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.time.LocalDateTime; + + +//@Schema(description = "管理后台 - 物联网卡分页 Request VO") +@ApiModel(value = "DIccidRecordPageReqVO") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = DIccidRecordDO.class, reverseConvertGenerate = false) +@ToString(callSuper = true) +public class DIccidRecordPageReqVO extends BaseDto implements Serializable { + private static final long serialVersionUID = -1L; + + //@Schema(description = "厂商编号|合作商编号", example = "张三") + private String userCode; + + // @Schema(description = "物联网卡号", example = "6236") + private String iccid; + + //@Schema(description = "物联网卡运营商", example = "1") + private Integer simType; + + // @Schema(description = "发货日期") + private String dateline; + + // @Schema(description = "状态(0,已授权,1未授权,2未支付)") + private Integer state; + + //@Schema(description = "订单id", example = "7866") + private String orderId; + + // @Schema(description = "授权码") + private String authorizationCode; + + // @Schema(description = "物联网卡来源0-其他 1-官方") + private Integer source; + + // @Schema(description = "厂商名称|合作商名称") + private String user; + + // @Schema(description = "imei") + private String imei; + + // @Schema(description = "创建时间") + // @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + // private LocalDateTime[] createTime; + // @Schema(description = "逻辑删除;0:未删除(默认);1:已删除") + private Integer deleted; + // @Schema(description = "有效天数") + @ExcelProperty("有效天数") + private Integer validDays; + + // @Schema(description = "到期时间") + // @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private LocalDateTime expirationTime; +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordRespTemplateVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordRespTemplateVO.java new file mode 100644 index 0000000..07e16f7 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordRespTemplateVO.java @@ -0,0 +1,43 @@ +package cc.iotkit.manager.dto.vo.category.vo; + +import cc.iotkit.model.iccid.DIccidRecordDO; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; + +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.io.Serializable; + + + +@Data +@Builder +public class DIccidRecordRespTemplateVO implements Serializable { + private static final long serialVersionUID = -1L; + + + + @ExcelProperty("iccid") + private String iccid; + + @ExcelProperty("运营商(1移动,2联通)") + private Integer simType; + + //@Schema(description = "厂商编码", example = "张三") + @ExcelProperty("厂商编码") + private String userCode; + + @ExcelProperty("imei") + private String imei; + + + @ExcelProperty("有效天数") + private Integer validDays; + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordRespVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordRespVO.java new file mode 100644 index 0000000..82c322b --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordRespVO.java @@ -0,0 +1,79 @@ +package cc.iotkit.manager.dto.vo.category.vo; + +import cc.iotkit.model.iccid.DIccidRecordDO; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Builder; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.time.LocalDateTime; + +//@Schema(description = "管理后台 - 物联网卡 Response VO") +@ApiModel(value = "DIccidRecordRespVO") +@Data +@AutoMapper(target = DIccidRecordDO.class) +public class DIccidRecordRespVO implements Serializable { + private static final long serialVersionUID = -1L; + + // @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "23580") + @ExcelProperty("主键") + private Long id; + + //@Schema(description = "厂商编号|合作商编号", example = "张三") + @ExcelProperty("厂商编号|合作商编号") + private String userCode; + + //@Schema(description = "物联网卡号", example = "6236") + @ExcelProperty("物联网卡号") + private String iccid; + + // @Schema(description = "物联网卡运营商", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty("物联网卡运营商") + private Integer simType; + + //@Schema(description = "发货日期") + @ExcelProperty("发货日期") + private String dateline; + + //@Schema(description = "状态(0,已授权,1未授权,2未支付)") + @ExcelProperty("状态") + private Integer state; + + //@Schema(description = "订单id", example = "7866") + @ExcelProperty("订单id") + private String orderId; + + // @Schema(description = "授权码") + @ExcelProperty("授权码") + private String authorizationCode; + + // @Schema(description = "物联网卡来源0-其他 1-官方") + @ExcelProperty("物联网卡来源0-其他 1-官方") + private Integer source; + + //@Schema(description = "厂商名称|合作商名称") + @ExcelProperty("厂商名称|合作商名称") + private String user; + + // @Schema(description = "imei") + @ExcelProperty("imei") + private String imei; + + // @Schema(description = "创建时间") + // @ExcelProperty("创建时间") + // private LocalDateTime createTime; + // @Schema(description = "逻辑删除;0:未删除(默认);1:已删除") + private Integer deleted; + // @Schema(description = "有效天数") + @ExcelProperty("有效天数") + private Integer validDays; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private LocalDateTime expirationTime; +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordSaveReqVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordSaveReqVO.java new file mode 100644 index 0000000..c952202 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DIccidRecordSaveReqVO.java @@ -0,0 +1,83 @@ +package cc.iotkit.manager.dto.vo.category.vo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.iccid.DIccidRecordDO; +import cc.iotkit.model.product.Product; +import com.alibaba.excel.annotation.ExcelProperty; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.*; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.time.LocalDateTime; + + +//@Schema(description = "管理后台 - 物联网卡新增/修改 Request VO") +@ApiModel(value = "DIccidRecordSaveReqVO") +@Data +@EqualsAndHashCode(callSuper = true) +//@AutoMapper(target = DIccidRecordDO.class, reverseConvertGenerate = false) +@NoArgsConstructor +@AllArgsConstructor +//@AutoMapper(target = TbDIccidRecordDO.class) +public class DIccidRecordSaveReqVO extends BaseDto { + + private static final long serialVersionUID = -1L; + + // @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "23580") + private Long id; + + //@Schema(description = "厂商编号|合作商编号", example = "张三") + // @NotNull(message = "厂商编号不能为空") + private String userCode; + + // @Schema(description = "物联网卡号", example = "6236") + // @NotNull(message = "厂商物联网卡iccid不能为空") + private String iccid; + + //@Schema(description = "物联网卡运营商", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + // @NotNull(message = "物联网卡运营商不能为空") + private Integer simType; + + // @Schema(description = "发货日期") + private String dateline; + + //@Schema(description = "状态(0,已授权,1未授权,2未支付)") + private Integer state; + + //@Schema(description = "订单id", example = "7866") + private String orderId; + + // @Schema(description = "授权码") + private String authorizationCode; + + // @Schema(description = "物联网卡来源0-其他 1-官方") + private Integer source; + + // @Schema(description = "厂商名称|合作商名称") + private String user; + + // @Schema(description = "imei") + private String imei; + //@Schema(description = "逻辑删除;0:未删除(默认);1:已删除") + private Integer deleted; + // @Schema(description = "有效天数") + // @ExcelProperty("有效天数") + private Integer validDays; + + // @Schema(description = "到期时间") + //@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private LocalDateTime expirationTime; + + // @NotNull(message = "物联网卡运营商不能为空") + private Integer startIccid; + //@NotNull(message = "起始后缀ICCID") + private Integer endIccid; + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DiccidRecordImportRespVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DiccidRecordImportRespVO.java new file mode 100644 index 0000000..992d459 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/category/vo/DiccidRecordImportRespVO.java @@ -0,0 +1,29 @@ +package cc.iotkit.manager.dto.vo.category.vo; + + +import cc.iotkit.model.iccid.DIccidRecordDO; +import cc.iotkit.model.rule.TaskLog; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +//@Schema(description = "管理后台 - 物联卡 Response VO") +@ApiModel(value = "DiccidRecordImportRespVO") +@Data +@Builder +//@AutoMapper(target = TbDIccidRecordDO.class) +public class DiccidRecordImportRespVO implements Serializable { + private static final long serialVersionUID = -1L; + + //@Schema(description = "创建成功物联卡名数组", requiredMode = Schema.RequiredMode.REQUIRED) + private List createUsernames; + + //@Schema(description = "导入失败的用户集合,key 为iccid,value 为失败原因", requiredMode = Schema.RequiredMode.REQUIRED) + private Map failureUsernames; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/channel/ChannelConfigVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/channel/ChannelConfigVo.java new file mode 100644 index 0000000..ad268dc --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/channel/ChannelConfigVo.java @@ -0,0 +1,63 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.channel; + +import cc.iotkit.model.notify.ChannelConfig; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +@ApiModel(value = "ChannelConfigVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = ChannelConfig.class) +public class ChannelConfigVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value="通道配置id") + @ExcelProperty(value = "通道配置id") + private Long id; + + @ApiModelProperty(value="通道id") + @ExcelProperty(value = "通道id") + private String channelId; + + @ApiModelProperty(value="通道配置名称") + @ExcelProperty(value = "通道配置名称") + private String title; + + @ApiModelProperty(value="通道配置参数") + @ExcelProperty(value = "通道配置参数") + private String param; + + @ApiModelProperty(value="创建时间") + @ExcelProperty(value = "创建时间") + private Long createAt; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/channel/ChannelTemplateVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/channel/ChannelTemplateVo.java new file mode 100644 index 0000000..04d422a --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/channel/ChannelTemplateVo.java @@ -0,0 +1,63 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.channel; + +import cc.iotkit.model.notify.ChannelTemplate; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +@ApiModel(value = "ChannelTemplateVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = ChannelTemplate.class) +public class ChannelTemplateVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value="通道模板id") + @ExcelProperty(value = "通道模板id") + private Long id; + + @ApiModelProperty(value="通道配置id") + @ExcelProperty(value = "通道配置id") + private Long channelConfigId; + + @ApiModelProperty(value="通道模板名称") + @ExcelProperty(value = "通道模板名称") + private String title; + + @ApiModelProperty(value="通道模板内容") + @ExcelProperty(value = "通道模板内容") + private String content; + + @ApiModelProperty(value="创建时间") + @ExcelProperty(value = "创建时间") + private Long createAt; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceconfig/DeviceConfigVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceconfig/DeviceConfigVo.java new file mode 100644 index 0000000..d78d678 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceconfig/DeviceConfigVo.java @@ -0,0 +1,71 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.deviceconfig; + +import cc.iotkit.model.device.DeviceConfig; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + + +@ApiModel(value = "DeviceConfigVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = DeviceConfig.class) + +public class DeviceConfigVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "设备配置id") + @ExcelProperty(value = "设备配置id") + private String id; + + @ApiModelProperty(value = "设备配置json内容") + @ExcelProperty(value = "设备配置json内容") + private String config; + + @ApiModelProperty(value = "创建时间") + @ExcelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "设备id") + @ExcelProperty(value = "设备id") + private String deviceId; + + @ApiModelProperty(value = "设备名称") + @ExcelProperty(value = "设备名称") + private String deviceName; + + @ApiModelProperty(value = "产品key") + @ExcelProperty(value = "产品key") + private String productKey; + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/devicegroup/DeviceGroupImportVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/devicegroup/DeviceGroupImportVo.java new file mode 100644 index 0000000..95dc4f9 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/devicegroup/DeviceGroupImportVo.java @@ -0,0 +1,50 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.devicegroup; + +import cc.iotkit.model.device.DeviceGroup; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + + +@Data +@NoArgsConstructor +@AutoMapper(target = DeviceGroup.class, reverseConvertGenerate = false) +public class DeviceGroupImportVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ExcelProperty(value = "设备组id") + private String id; + + @ExcelProperty(value = "设备组名称") + private String name; + + @ExcelProperty(value = "分组说明") + private String remark; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/devicegroup/DeviceGroupVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/devicegroup/DeviceGroupVo.java new file mode 100644 index 0000000..816df22 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/devicegroup/DeviceGroupVo.java @@ -0,0 +1,71 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.devicegroup; + +import cc.iotkit.model.device.DeviceGroup; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + + +@ApiModel(value = "DeviceGroupVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = DeviceGroup.class) + +public class DeviceGroupVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "设备组id") + @ExcelProperty(value = "设备组id") + private String id; + + @ApiModelProperty(value = "创建时间") + @ExcelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "设备数量") + @ExcelProperty(value = "设备数量") + private Integer deviceQty; + + @ApiModelProperty(value = "设备组名称") + @ExcelProperty(value = "设备组名称") + private String name; + + @ApiModelProperty(value = "分组说明") + @ExcelProperty(value = "分组说明") + private String remark; + + @ApiModelProperty(value = "所属用户") + @ExcelProperty(value = "所属用户") + private String uid; + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/DeviceInfoImportVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/DeviceInfoImportVo.java new file mode 100644 index 0000000..893744d --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/DeviceInfoImportVo.java @@ -0,0 +1,55 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.deviceinfo; + +import cc.iotkit.model.device.DeviceInfo; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; + + +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = DeviceInfo.class,convertGenerate = false) +public class DeviceInfoImportVo implements Serializable { + private static final long serialVersionUID = -1L; + + @ExcelProperty(value = "设备名称") + private String deviceName; + + @ExcelProperty(value = "设备型号") + private String model; + + @ExcelProperty(value = "父级id") + private String parentId; + + @ExcelProperty(value = "产品key") + private String productKey; + + @ExcelProperty(value = "设备分组") + private String deviceGroup; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/DeviceInfoVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/DeviceInfoVo.java new file mode 100644 index 0000000..a2bc5d4 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/DeviceInfoVo.java @@ -0,0 +1,112 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.deviceinfo; + +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.product.Product; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Map; + + +@ApiModel(value = "DeviceInfoVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = DeviceInfo.class,convertGenerate = false) +public class DeviceInfoVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "") + @ExcelProperty(value = "") + private String id; + + @ApiModelProperty(value = "创建时间") + @ExcelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "设备id") + @ExcelProperty(value = "设备id") + private String deviceId; + + @ApiModelProperty(value = "设备名称") + @ExcelProperty(value = "设备名称") + private String deviceName; + + @ApiModelProperty(value = "设备类型") + @ExcelProperty(value = "设备类型") + private String model; + + @ApiModelProperty(value = "设备离线时间") + @ExcelProperty(value = "设备离线时间") + @ReverseAutoMapping(source = "state.offlineTime", target = "offlineTime") + @AutoMapping(ignore = true) + private Long offlineTime; + + @ApiModelProperty(value = "设备在线时间") + @ExcelProperty(value = "设备在线时间") + @ReverseAutoMapping(source = "state.onlineTime", target = "onlineTime") + @AutoMapping(ignore = true) + private Long onlineTime; + + @ApiModelProperty(value = "父级id") + @ExcelProperty(value = "父级id") + private String parentId; + + @ApiModelProperty(value = "产品key") + @ExcelProperty(value = "产品key") + private String productKey; + + @ApiModelProperty(value = "设备描述") + @ExcelProperty(value = "设备描述") + private String secret; + + @ApiModelProperty(value = "设备状态") + @ExcelProperty(value = "设备状态") + @ReverseAutoMapping(source = "state.online", target = "online") + @AutoMapping(ignore = true) + private Boolean online; + + @ApiModelProperty(value = "所属产品信息") + private Product product; + + @ApiModelProperty(value = "所属分组") + private Map group; + + @ApiModelProperty(value = "位置信息") + private DeviceInfo.Locate locate; + //@AutoMapping(ignore = true) + private String onlineStatus; + @ApiModelProperty(value="部门表-区域id") + private Long deptAreaId; + private String productName; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/ParentDeviceVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/ParentDeviceVo.java new file mode 100644 index 0000000..eac5c75 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/deviceinfo/ParentDeviceVo.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.deviceinfo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author:tfd + * @Date:2023/6/29 14:30 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ParentDeviceVo { + + private String id; + + private String deviceName; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/DeviceOtaDetailVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/DeviceOtaDetailVo.java new file mode 100644 index 0000000..5c4e976 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/DeviceOtaDetailVo.java @@ -0,0 +1,63 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.ota; + +import cc.iotkit.model.ota.DeviceOtaDetail; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: 石恒 + * @Date: 2023/6/17 20:49 + * @Description: + */ +@Data +@ExcelIgnoreUnannotated +@ApiModel(value = "DeviceOtaDetailVo") +@AutoMapper(target = DeviceOtaDetail.class) +public class DeviceOtaDetailVo implements Serializable { + private Long id; + + private Integer step; + + private String taskId; + + private String desc; + + private String version; + + private String module; + + private String deviceId; + + private String productKey; + + private String deviceName; + + private Long otaInfoId; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/DeviceOtaInfoVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/DeviceOtaInfoVo.java new file mode 100644 index 0000000..8d2d18c --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/DeviceOtaInfoVo.java @@ -0,0 +1,64 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.ota; + +import cc.iotkit.model.ota.DeviceOtaInfo; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: 石恒 + * @Date: 2023/6/17 20:49 + * @Description: + */ +@Data +@ExcelIgnoreUnannotated +@ApiModel(value = "DeviceOtaInfoVo") +@AutoMapper(target = DeviceOtaInfo.class) +public class DeviceOtaInfoVo implements Serializable { + + private Long id; + + private Long packageId; + + private String desc; + + private String version; + + private String module; + + private Integer total; + + private Integer success; + + private Integer fail; + + private String productKey; + + private Long createAt; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/DeviceUpgradeVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/DeviceUpgradeVo.java new file mode 100644 index 0000000..866e088 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/DeviceUpgradeVo.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.ota; + +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: 石恒 + * @Date: 2023/7/18 21:48 + * @Description: + */ +@Data +@Builder +public class DeviceUpgradeVo implements Serializable { + private String result; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/OtaPackageUploadVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/OtaPackageUploadVo.java new file mode 100644 index 0000000..a958d3e --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ota/OtaPackageUploadVo.java @@ -0,0 +1,46 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.ota; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: 石恒 + * @Date: 2023/6/27 22:35 + * @Description: + */ +@Data +@ExcelIgnoreUnannotated +@ApiModel(value = "OtaPackageUploadVo") +public class OtaPackageUploadVo implements Serializable { + private String url; + private Long size; + private String md5; + private Long ossId; + private String originalName; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/plugin/PluginInfoVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/plugin/PluginInfoVo.java new file mode 100644 index 0000000..5274cbd --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/plugin/PluginInfoVo.java @@ -0,0 +1,106 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.plugin; + +import cc.iotkit.model.plugin.PluginInfo; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.util.Date; + +@Data +@AutoMapper(target = PluginInfo.class) +public class PluginInfoVo { + + /** + * id + */ + private Long id; + + /** + * 插件包id + */ + private String pluginId; + + /** + * 插件名称 + */ + private String name; + + /** + * 部署方式 + */ + private String deployType; + + /** + * 插件包文件名 + */ + private String file; + + /** + * 插件版本 + */ + private String version; + + /** + * 插件类型 + */ + private String type; + + /** + * 设备插件协议类型 + */ + private String protocol; + + /** + * 状态 + */ + private String state; + + /** + * 描述 + */ + private String description; + + /** + * 插件配置项描述 + */ + private String configSchema; + + /** + * 插件配置信息 + */ + private String config; + + /** + * 插件脚本 + */ + private String script; + + /** + * 创建时间 + */ + private Date createTime; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/product/IconTypeVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/product/IconTypeVo.java new file mode 100644 index 0000000..ff5272b --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/product/IconTypeVo.java @@ -0,0 +1,51 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.product; + +import cc.iotkit.model.product.IconType; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + + +@ApiModel(value = "IconTypeVo") +@Data +@AutoMapper(target = IconType.class) +public class IconTypeVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "id") + private Long id; + + @ApiModelProperty(value = "分类名称") + private String typeName; + + @ApiModelProperty(value = "分类描述") + private String typeDescribe; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/product/IconVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/product/IconVo.java new file mode 100644 index 0000000..8f6fc75 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/product/IconVo.java @@ -0,0 +1,67 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.product; + +import cc.iotkit.model.product.Icon; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + + +@ApiModel(value = "IconVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = Icon.class) +public class IconVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "id") + @ExcelProperty(value = "id") + private Long id; + + @ApiModelProperty(value = "图标分类id") + private Long iconTypeId; + + @ApiModelProperty(value = "图标名称") + private String iconName; + + @ApiModelProperty(value = "视窗缩放") + private String viewBox; + + @ApiModelProperty(value = "命名空间") + private String xmlns; + + @ApiModelProperty(value = "版本") + private String version; + + @ApiModelProperty(value = "图标内容") + private String iconContent; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/product/ProductVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/product/ProductVo.java new file mode 100644 index 0000000..93ac445 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/product/ProductVo.java @@ -0,0 +1,107 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.product; + +import cc.iotkit.model.product.Icon; +import cc.iotkit.model.product.Product; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + + +@ApiModel(value = "ProductVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = Product.class) +public class ProductVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "产品id") + @ExcelProperty(value = "产品id") + private Long id; + + @ApiModelProperty(value = "产品id") + @ExcelProperty(value = "产品id") + private String productKey; + + @ApiModelProperty(value = "产品密钥") + @ExcelProperty(value = "产品密钥") + private String productSecret; + + @ApiModelProperty(value = "品类") + @ExcelProperty(value = "品类") + private String category; + + @ApiModelProperty(value = "创建时间") + @ExcelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "图片") + @ExcelProperty(value = "图片") + private String img; + + @ApiModelProperty(value = "产品图标ID") + @ExcelProperty(value = "图片") + private Long iconId; + + @ApiModelProperty(value = "产品图标信息") + private Icon icon; + + @ApiModelProperty(value = "产品名称") + @ExcelProperty(value = "产品名称") + private String name; + + @ApiModelProperty(value = "节点类型") + @ExcelProperty(value = "节点类型") + private Integer nodeType; + + @ApiModelProperty(value = "是否透传,true/false") + @ExcelProperty(value = "是否透传,true/false") + private Boolean transparent; + + @ApiModelProperty(value = "是否开启设备定位,true/false") + @ExcelProperty(value = "是否开启设备定位,true/false") + private Boolean isOpenLocate; + + @ApiModelProperty(value = "定位更新方式") + @ExcelProperty(value = "定位更新方式") + private String locateUpdateType; + + @ApiModelProperty(value = "用户ID") + @ExcelProperty(value = "用户ID") + private String uid; + + @ApiModelProperty(value = "保活时长(秒)") + @ExcelProperty(value = "保活时长(秒)") + private Long keepAliveTime; + @ApiModelProperty(value = "0是报警器1是其它") + // @NotNull(message = "保活时长不能为空",groups = { AddGroup.class, EditGroup.class }) + private Integer productType; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/productmodel/ProductModelVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/productmodel/ProductModelVo.java new file mode 100644 index 0000000..c743c8c --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/productmodel/ProductModelVo.java @@ -0,0 +1,80 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.productmodel; + +import cc.iotkit.model.product.ProductModel; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + + +@ApiModel(value = "ProductModelVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = ProductModel.class) + +public class ProductModelVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value="型号id") + @ExcelProperty(value = "型号id") + private String id; + + @ApiModelProperty(value="型号") + @ExcelProperty(value = "型号") + private String model; + + @ApiModelProperty(value="修改时间") + @ExcelProperty(value = "修改时间") + private Long modifyAt; + + @ApiModelProperty(value="名称") + @ExcelProperty(value = "名称") + private String name; + + @ApiModelProperty(value="产品Key") + @ExcelProperty(value = "产品Key") + private String productKey; + + @ApiModelProperty(value="脚本内容") + @ExcelProperty(value = "脚本内容") + private String script; + + @ApiModelProperty(value="脚本状态") + @ExcelProperty(value = "脚本状态") + private String state; + + @ApiModelProperty(value="脚本类型") + @ExcelProperty(value = "脚本类型") + private String type; + + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ruleinfo/RuleInfoVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ruleinfo/RuleInfoVo.java new file mode 100644 index 0000000..cbdfccd --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ruleinfo/RuleInfoVo.java @@ -0,0 +1,90 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.ruleinfo; + +import cc.iotkit.model.rule.FilterConfig; +import cc.iotkit.model.rule.RuleAction; +import cc.iotkit.model.rule.RuleInfo; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + + +@ApiModel(value = "RuleInfoVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = RuleInfo.class) + +public class RuleInfoVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "规则id") + @ExcelProperty(value = "规则id") + private String id; + + @ApiModelProperty(value = "动作") + @ExcelProperty(value = "动作") + private List actions; + + @ApiModelProperty(value = "创建时间") + @ExcelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "描述") + @ExcelProperty(value = "描述") + private String desc; + + @ApiModelProperty(value = "过滤器") + @ExcelProperty(value = "过滤器") + private List filters; + + @ApiModelProperty(value = "监听器") + @ExcelProperty(value = "监听器") + private List listeners; + + @ApiModelProperty(value = "规则名称") + @ExcelProperty(value = "规则名称") + private String name; + + @ApiModelProperty(value = "状态") + @ExcelProperty(value = "状态") + private String state; + + @ApiModelProperty(value = "规则类型") + @ExcelProperty(value = "规则类型") + private String type; + + @ApiModelProperty(value = "用户id") + @ExcelProperty(value = "用户id") + private String uid; + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ruleinfo/RuleLogVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ruleinfo/RuleLogVo.java new file mode 100644 index 0000000..c0b2524 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/ruleinfo/RuleLogVo.java @@ -0,0 +1,55 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.ruleinfo; + +import cc.iotkit.model.rule.RuleLog; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +@ApiModel(value = "RuleLogVo") +@Data +@AutoMapper(target = RuleLog.class) +public class RuleLogVo implements Serializable { + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "时间") + private Long logAt; + + @ApiModelProperty(value = "规则id") + private String ruleId; + + @ApiModelProperty(value = "状态") + private String state; + + @ApiModelProperty(value = "内容") + private String content; + + @ApiModelProperty(value = "是否成功") + private Boolean success; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/taskinfo/TaskInfoVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/taskinfo/TaskInfoVo.java new file mode 100644 index 0000000..7a882ce --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/taskinfo/TaskInfoVo.java @@ -0,0 +1,94 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.taskinfo; + +import cc.iotkit.model.rule.RuleAction; +import cc.iotkit.model.rule.TaskInfo; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + + +@ApiModel(value = "TaskInfoVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = TaskInfo.class) +public class TaskInfoVo implements Serializable { + + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "主键") + @ExcelProperty(value = "主键") + private String id; + + @ApiModelProperty(value = "任务输出") + @ExcelProperty(value = "任务输出") + private List actions; + + @ApiModelProperty(value = "创建时间") + @ExcelProperty(value = "创建时间") + private Long createAt; + + @ApiModelProperty(value = "描述") + @ExcelProperty(value = "描述") + private String desc; + + @ApiModelProperty(value = "表达式") + @ExcelProperty(value = "表达式") + private String expression; + + @ApiModelProperty(value = "任务名称") + @ExcelProperty(value = "任务名称") + private String name; + + @ApiModelProperty(value = "操作备注") + @ExcelProperty(value = "操作备注") + private String reason; + + @ApiModelProperty(value = "任务状态") + @ExcelProperty(value = "任务状态") + private String state; + + @ApiModelProperty(value = "任务类型") + @ExcelProperty(value = "任务类型") + private String type; + + @ApiModelProperty(value = "创建者") + @ExcelProperty(value = "创建者") + private String uid; + + public Integer getSeconds() { + if (TaskInfo.TYPE_DELAY.equals(getType())) { + return Integer.parseInt(getExpression()); + } + return null; + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/taskinfo/TaskLogVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/taskinfo/TaskLogVo.java new file mode 100644 index 0000000..568c4c7 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/taskinfo/TaskLogVo.java @@ -0,0 +1,48 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.dto.vo.taskinfo; + +import cc.iotkit.model.rule.TaskLog; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.*; + +import java.io.Serializable; + + +@ApiModel(value = "TaskLogVo") +@Data +@AutoMapper(target = TaskLog.class) +public class TaskLogVo implements Serializable { + private static final long serialVersionUID = -1L; + + private String id; + + private String taskId; + + private String content; + + private Boolean success; + + private Long logAt; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/thingmodel/ThingModelVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/thingmodel/ThingModelVo.java new file mode 100644 index 0000000..47556b9 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/thingmodel/ThingModelVo.java @@ -0,0 +1,50 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.dto.vo.thingmodel; + +import cc.iotkit.model.product.ThingModel; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + + +@ApiModel(value = "ThingModelVo") +@Data +@AutoMapper(target = ThingModel.class) +public class ThingModelVo implements Serializable { + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "主键") + private String id; + + @ApiModelProperty(value = "模型内容") + private ThingModel.Model model; + + @ApiModelProperty(value = "产品key") + private String productKey; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/userInfo/UserInfoPageReqVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/userInfo/UserInfoPageReqVO.java new file mode 100644 index 0000000..f0fcbff --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/userInfo/UserInfoPageReqVO.java @@ -0,0 +1,68 @@ +package cc.iotkit.manager.dto.vo.userInfo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.data.model.TbUserInfo; +import cc.iotkit.model.UserInfo; +import cc.iotkit.model.iccid.DIccidRecordDO; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.io.Serializable; + +@ApiModel(value = "UserInfoPageReqVO") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = UserInfo.class, reverseConvertGenerate = false) +@ToString(callSuper = true) +public class UserInfoPageReqVO extends BaseDto implements Serializable { + private static final long serialVersionUID = -1L; + public static final int USER_TYPE_PLATFORM = 0; + public static final int USER_TYPE_CLIENT = 1; + + private Long id; + + /** + * 用户账号 + */ + private String uid; + + /** + * 密钥(密码加密后的内容) + */ + private String secret; + private String site; + /** + * 用户昵称 + */ + private String nickName; + + /** + * 性别 0-未知 1-male,2-female + */ + private Integer gender; + + /** + * 头像地址 + */ + private String avatarUrl; + + private String email; + + private String address; + + /** + * 当前家庭Id + */ + private String currHomeId; + + /** + * 用户类型 + * 0:平台用户 + * 1:终端用户 + */ + private Integer type; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderNumRespVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderNumRespVO.java new file mode 100644 index 0000000..2ffab28 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderNumRespVO.java @@ -0,0 +1,20 @@ +package cc.iotkit.manager.dto.vo.worder; + +import lombok.Data; + +@Data +public class WorderNumRespVO { + /** + * 已完成工单数 + */ + private String finish; + /** + * 未完成工单数 + */ + private String noFinish; + /** + * 工单总量 + */ + private String totalWorder; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderPageReqVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderPageReqVO.java new file mode 100644 index 0000000..72a8c18 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderPageReqVO.java @@ -0,0 +1,134 @@ +package cc.iotkit.manager.dto.vo.worder; + + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import cc.iotkit.model.worder.WorderDO; +import com.fasterxml.jackson.annotation.JsonFormat; + +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.Date; +import java.util.List; + +//@Schema(description = "管理后台 - 工单分页 Request VO") +@ApiModel(value = "WorderPageReqVO") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = WorderDO.class, reverseConvertGenerate = false) +@ToString(callSuper = true) +public class WorderPageReqVO extends BaseDto implements Serializable { + private static final long serialVersionUID = -1L; + //@Schema(description = "工单id") + private String id; + // @Schema(description = "工单编号") + private String worderNum; + + // @Schema(description = "工单内容") + private String worderContent; + + //@Schema(description = "上报时间") + /* @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date[] reportTime;*/ + + // @Schema(description = "指派人id") + private Long assignUserid; + + // @Schema(description = "指派人姓名") + private String assignName; + + // @Schema(description = "指派时间") +/* @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date[] assignTime;*/ + + //@Schema(description = "问题截图") + private String problemScreenshot; + + // @Schema(description = "消息") + private String message; + + //@Schema(description = "预约时间") + private String reservationTime; + + // @Schema(description = "客户id") + private Long customerId; + + // @Schema(description = "客户姓名") + private String customerName; + + // @Schema(description = "联系方式") + private String customerPhone; + + // @Schema(description = "客户服务地址编码") + private Integer customerAreaId; + + // @Schema(description = "服务地址(客户详细地址)") + private String customerAddress; + + // @Schema(description = "退单时间") +/* @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date[] worderBackTime;*/ + + // @Schema(description = "退单原因") + private String worderBackReason; + + // @Schema(description = "工单完成时间") + /* @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date[] finishTime;*/ + + // @Schema(description = "完成后图片") + private String finishPicture; + + // @Schema(description = "反馈信息") + private String feedback; + + // @Schema(description = "创建时间") +/* @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date[] createTime;*/ + + //@Schema(description = "工单类型") + private Integer worderType; + + // @Schema(description = "设备id") + private String productId; + + ///@Schema(description = "订单id") + private String orderId; + + // @Schema(description = "订单状态") + private Integer orderStatus; + + //@Schema(description = "工单状态") + private Integer worderStatus; + + // @Schema(description = "滤芯名称") + private String filterName; + + // @Schema(description = "服务ID") + private String fwId; + + // @Schema(description = "服务IDS") + // private List fwIds; + + // @Schema(description = "类型 (只在经销商端工单列表中作为查询参数 1-全部工单,2-待派单,3-已派单,4-已完成)") + private Integer type; + + // @Schema(description = "部门id (临时字段)") + private Long deptId; + /** + * 指派人电话 + */ + private String assignPhone; +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderRespVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderRespVO.java new file mode 100644 index 0000000..39c9830 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderRespVO.java @@ -0,0 +1,147 @@ +package cc.iotkit.manager.dto.vo.worder; + + +import cc.iotkit.model.iccid.DIccidRecordDO; +import cc.iotkit.model.worder.WorderDO; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; + +import com.fasterxml.jackson.annotation.JsonFormat; + +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +//@Schema(description = "管理后台 - 工单 Response VO") +@Data +@AutoMapper(target = WorderDO.class) +public class WorderRespVO { + + // @Schema(description = "工单编号") + @ExcelProperty("工单编号") + private String worderNum; + + // @Schema(description = "工单内容") + @ExcelProperty("工单内容") + private String worderContent; + + // @Schema(description = "上报时间") + @ExcelProperty("上报时间") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date reportTime; + + //@Schema(description = "指派人id") + @ExcelProperty("指派人id") + private Long assignUserid; + + //@Schema(description = "指派人姓名") + @ExcelProperty("指派人姓名") + private String assignName; + + // @Schema(description = "指派时间") + @ExcelProperty("指派时间") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date assignTime; + + // @Schema(description = "问题截图") + @ExcelProperty("问题截图") + private String problemScreenshot; + + //@Schema(description = "消息") + @ExcelProperty("消息") + private String message; + + // @Schema(description = "预约时间") + @ExcelProperty("预约时间") + private String reservationTime; + + // @Schema(description = "客户id") + @ExcelProperty("客户id") + private Long customerId; + + // @Schema(description = "客户姓名") + @ExcelProperty("客户姓名") + private String customerName; + + // @Schema(description = "联系方式") + @ExcelProperty("联系方式") + private String customerPhone; + + // @Schema(description = "客户服务地址编码") + private Integer customerAreaId; + + //@Schema(description = "服务地址(客户详细地址)") + @ExcelProperty("服务地址") + private String customerAddress; + + // @Schema(description = "退单时间") + @ExcelProperty("退单时间") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date worderBackTime; + + // @Schema(description = "退单原因") + @ExcelProperty("退单原因") + private String worderBackReason; + + // @Schema(description = "工单完成时间") + @ExcelProperty("工单完成时间") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date finishTime; + + // @Schema(description = "完成后图片") + @ExcelProperty("完成后图片") + private String finishPicture; + + // @Schema(description = "反馈信息") + @ExcelProperty("反馈信息") + private String feedback; + + //@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + + //@Schema(description = "工单id", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("工单id") + private Long id; + + //@Schema(description = "工单类型") + // @ExcelProperty(value = "工单类型", converter = DictConvert.class) + // @DictFormat(DictTypeConstants.WORDER_TYPE) + private Integer worderType; + + // @Schema(description = "设备id") + private String productId; + + + + + // @Schema(description = "订单id") + @ExcelProperty("订单id") + private String orderId; + + // @Schema(description = "订单状态") + // @ExcelProperty(value = "订单状态", converter = DictConvert.class) + // @DictFormat(DictTypeConstants.IS_STATE) + private Integer orderStatus; + + //@Schema(description = "工单状态") + // @ExcelProperty(value = "工单状态", converter = DictConvert.class) + // @DictFormat(DictTypeConstants.WORDER_STATUS) + private Integer worderStatus; + // @Schema(description = "服务商id") + private Long fwId; + + private Long tenantId; + /** + * 指派人电话 + */ + private String assignPhone; +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderSaveReqVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderSaveReqVO.java new file mode 100644 index 0000000..ad6c5cb --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderSaveReqVO.java @@ -0,0 +1,114 @@ +package cc.iotkit.manager.dto.vo.worder; + +import com.fasterxml.jackson.annotation.JsonFormat; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +//@Schema(description = "管理后台 - 工单新增/修改 Request VO") +@Data +@NoArgsConstructor +@AllArgsConstructor +public class WorderSaveReqVO { + + // @Schema(description = "工单编号") + private String worderNum; + + // @Schema(description = "工单内容") + private String worderContent; + + //@Schema(description = "上报时间") + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date reportTime; + + // @Schema(description = "指派人id") + private Long assignUserid; + + // @Schema(description = "指派人姓名") + private String assignName; + + // @Schema(description = "指派时间") + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date assignTime; + + // @Schema(description = "问题截图") + private String problemScreenshot; + + // @Schema(description = "消息") + private String message; + + // @Schema(description = "预约时间") + private String reservationTime; + + // @Schema(description = "客户id") + private Long customerId; + + // @Schema(description = "客户姓名") + private String customerName; + + // @Schema(description = "联系方式") + private String customerPhone; + + // @Schema(description = "客户服务地址编码") + private Integer customerAreaId; + + // @Schema(description = "客户服务地址名称") + private String customerAreaName; + + //@Schema(description = "服务地址(客户详细地址)") + private String customerAddress; + + // @Schema(description = "退单时间") + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date worderBackTime; + + // @Schema(description = "退单原因") + private String worderBackReason; + + // @Schema(description = "工单完成时间") + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + private Date finishTime; + + // @Schema(description = "完成后图片") + private String finishPicture; + + // @Schema(description = "反馈信息") + private String feedback; + + // @Schema(description = "工单id", requiredMode = Schema.RequiredMode.REQUIRED) + private Long id; + + // @Schema(description = "工单类型") + private Integer worderType; + + // @Schema(description = "设备id") + private String productId; + + // @Schema(description = "滤芯名称") + private String filterName; + + // @Schema(description = "订单id") + private String orderId; + + //@Schema(description = "订单状态") + private Integer orderStatus; + + // @Schema(description = "工单状态") + private Integer worderStatus; + + // @Schema(description = "问题类型") + private Integer problemType; + /** + * 指派人电话 + */ + private String assignPhone; + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderSubscribeSaveReqVO.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderSubscribeSaveReqVO.java new file mode 100644 index 0000000..36c545d --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/worder/WorderSubscribeSaveReqVO.java @@ -0,0 +1,44 @@ +package cc.iotkit.manager.dto.vo.worder; + +import com.fasterxml.jackson.annotation.JsonFormat; + +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotNull; +import java.util.Date; + +//@Schema(description = "管理后台 - 工单新增/修改 Request VO") +@Data +public class WorderSubscribeSaveReqVO { + + //@Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + //@NotNull(message = "订单编号不能为空") + private Long id; + + // @Schema(description = "预约时间" ) + //@NotNull(message = "预约时间不能为空") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + private Date[] deliveryTime; + + // @Schema(description = "客户id") + private Long customerId; + + // @Schema(description = "客户姓名") + private String customerName; + + // @Schema(description = "联系方式") + private String customerPhone; + + // @Schema(description = "客户服务地址编码") + private Integer customerAreaId; + + //@Schema(description = "客户服务地址名称") + private String customerAreaName; + + //@Schema(description = "服务地址(客户详细地址)") + private String customerAddress; + + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/listener/DeviceGroupImportListener.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/listener/DeviceGroupImportListener.java new file mode 100644 index 0000000..6764ec5 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/listener/DeviceGroupImportListener.java @@ -0,0 +1,126 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.listener; + +import cc.iotkit.common.excel.core.ExcelListener; +import cc.iotkit.common.excel.core.ExcelResult; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.SpringUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.manager.dto.bo.devicegroup.DeviceGroupBo; +import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupImportVo; +import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo; +import cc.iotkit.manager.service.IDeviceManagerService; +import cc.iotkit.model.device.DeviceGroup; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import lombok.extern.slf4j.Slf4j; + +import java.util.Collections; +import java.util.List; + +@Slf4j +public class DeviceGroupImportListener extends AnalysisEventListener implements ExcelListener { + + private final Boolean isUpdateSupport; + + private int successNum = 0; + private int failureNum = 0; + + private final String userId; + + private IDeviceManagerService deviceManagerService; + + private final StringBuilder successMsg = new StringBuilder(); + private final StringBuilder failureMsg = new StringBuilder(); + + public DeviceGroupImportListener(Boolean isUpdateSupport) { + this.isUpdateSupport = isUpdateSupport; + this.userId = String.valueOf(LoginHelper.getUserId()); + this.deviceManagerService = SpringUtils.getBean(IDeviceManagerService.class); + } + + @Override + public ExcelResult getExcelResult() { + + return new ExcelResult<>() { + @Override + public String getAnalysis() { + if (failureNum > 0) { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new BizException(failureMsg.toString()); + } else { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条"); + } + return successMsg.toString(); + } + + @Override + public List getList() { + return Collections.emptyList(); + } + + @Override + public List getErrorList() { + return Collections.emptyList(); + } + }; + } + + @Override + public void invoke(DeviceGroupImportVo deviceGroupImportVo, AnalysisContext analysisContext) { + if ( StringUtils.isEmpty(deviceGroupImportVo.getId()) || StringUtils.isEmpty(deviceGroupImportVo.getName()) ) { + failureNum++; + failureMsg.append("
第").append(analysisContext.getCurrentRowNum()).append("行,设备分组ID或名称不能为空"); + return; + } + + DeviceGroupVo deviceGroupVo = this.deviceManagerService.getDeviceGroup(deviceGroupImportVo.getId()); + try { + if (ObjectUtil.isNull(deviceGroupVo)) { + // 新增 + DeviceGroup deviceGroup = BeanUtil.toBean(deviceGroupImportVo, DeviceGroup.class); + deviceGroup.setUid(this.userId); + this.deviceManagerService.addGroup(deviceGroup); + } else if (Boolean.TRUE.equals(isUpdateSupport)) { + // 修改 + DeviceGroupBo deviceGroupBo = BeanUtil.toBean(deviceGroupImportVo, DeviceGroupBo.class); + deviceGroupBo.setUid(this.userId); + this.deviceManagerService.updateGroup(deviceGroupBo); + } + successNum++; + } catch (Exception e) { + failureNum++; + failureMsg.append("
第").append(analysisContext.getCurrentRowNum()).append("行,导入失败:").append(e.getMessage()); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/listener/DeviceInfoImportListener.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/listener/DeviceInfoImportListener.java new file mode 100644 index 0000000..cd844aa --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/listener/DeviceInfoImportListener.java @@ -0,0 +1,140 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.listener; + +import cc.iotkit.common.excel.core.ExcelListener; +import cc.iotkit.common.excel.core.ExcelResult; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.SpringUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.manager.dto.bo.device.DeviceInfoBo; +import cc.iotkit.manager.dto.bo.devicegroup.DeviceAddGroupBo; +import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoImportVo; +import cc.iotkit.manager.service.IDeviceManagerService; +import cc.iotkit.model.device.DeviceInfo; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class DeviceInfoImportListener extends AnalysisEventListener implements ExcelListener { + + private Boolean isUpdateSupport; + + private int successNum = 0; + private int failureNum = 0; + + private final String userId; + + private IDeviceManagerService deviceManagerService; + + private final StringBuilder successMsg = new StringBuilder(); + private final StringBuilder failureMsg = new StringBuilder(); + + public DeviceInfoImportListener(Boolean isUpdateSupport) { + this.isUpdateSupport = isUpdateSupport; + this.userId = String.valueOf(LoginHelper.getUserId()); + this.deviceManagerService = SpringUtils.getBean(IDeviceManagerService.class); + } + + @Override + public ExcelResult getExcelResult() { + return new ExcelResult<>() { + @Override + public String getAnalysis() { + if (failureNum > 0) { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new BizException(failureMsg.toString()); + } else { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条"); + } + return successMsg.toString(); + } + + @Override + public List getList() { + return Collections.emptyList(); + } + + @Override + public List getErrorList() { + return Collections.emptyList(); + } + }; + } + + @Override + public void invoke(DeviceInfoImportVo deviceInfoImportVo, AnalysisContext analysisContext) { + if (StringUtils.isBlank(deviceInfoImportVo.getProductKey())) { + failureMsg.append("
第").append(analysisContext.getCurrentRowNum()).append("行,产品key不能为空!"); + failureNum++; + } + if (StringUtils.isBlank(deviceInfoImportVo.getDeviceName())) { + failureMsg.append("
第").append(analysisContext.getCurrentRowNum()).append("行,设备名称不能为空!"); + failureNum++; + } + DeviceInfo deviceInfo = this.deviceManagerService.getByPkDn(deviceInfoImportVo.getProductKey(), deviceInfoImportVo.getDeviceName()); + try { + // todo 处理groups + if(ObjectUtil.isNull(deviceInfo)) { + // 新增 + DeviceInfoBo deviceInfoBo = BeanUtil.toBean(deviceInfoImportVo, DeviceInfoBo.class); + this.deviceManagerService.addDevice(deviceInfoBo); + // 新增后重新获取deviceInfo, 此操作冗余,是建立在不修改源码基础上的处理方式,可优化 + deviceInfo = this.deviceManagerService.getByPkDn(deviceInfoImportVo.getProductKey(), deviceInfoImportVo.getDeviceName()); + } else if (Boolean.TRUE.equals(isUpdateSupport)) { + // 修改 + DeviceInfoBo deviceInfoBo = BeanUtil.toBean(deviceInfo, DeviceInfoBo.class); + this.deviceManagerService.saveDevice(deviceInfoBo); + } + + // 设备分组处理 + String group = deviceInfoImportVo.getDeviceGroup(); + if (StringUtils.isNotBlank(group)) { + DeviceAddGroupBo deviceAddGroupBo = new DeviceAddGroupBo(); + deviceAddGroupBo.setGroup(group); + String deviceId = deviceInfo.getDeviceId(); + ArrayList devices = new ArrayList<>(); + devices.add(deviceId); + deviceAddGroupBo.setDevices(devices); + this.deviceManagerService.addDevice2Group(deviceAddGroupBo); + } + + successNum++; + } catch (Exception e) { + failureNum++; + failureMsg.append("
第").append(analysisContext.getCurrentRowNum()).append("行,导入失败:").append(e.getMessage()); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/query/DeviceQuery.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/query/DeviceQuery.java new file mode 100644 index 0000000..0400ce6 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/query/DeviceQuery.java @@ -0,0 +1,38 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.model.query; + +import lombok.Data; + +@Data +public class DeviceQuery { + + private String productKey; + + private String keyword; + + private String group; + + private String state; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/stats/MainStats.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/stats/MainStats.java new file mode 100644 index 0000000..70075aa --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/stats/MainStats.java @@ -0,0 +1,103 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.model.stats; + +import cc.iotkit.model.stats.DataItem; +import cc.iotkit.model.stats.ProductKeyCountDTO; +import cc.iotkit.model.stats.TimeData; +import lombok.Data; + +import java.util.List; + +/** + * 首页数据统计 + */ +@Data +public class MainStats { + + /** + * 品类数量 + */ + private long categoryTotal; + + /** + * 产品数量 + */ + private long productTotal; + + /** + * 设备数量 + */ + private long deviceTotal; + + /** + * 上报数量 + */ + private long reportTotal; + + /** + * 在线数量 + */ + private long onlineTotal; + + /** + * 离线数量 + */ + private long offlineTotal; + + /** + * 待激活设备 + */ + private long neverOnlineTotal; + + /** + * 上报数据数量统计 + */ + private List reportDataStats; + + + /** + * 上行数据数量统计 + */ + private List deviceUpMessageStats; + + /** + * 下行数据数量统计 + */ + private List deviceDownMessageStats; + + + /** + * 按品类统计的设备数量 + */ + private List deviceStatsOfCategory; + + /** + * 报警总数 + */ + private long alertCount; + /** + * 产品分类对应的设备总数 + */ + List productKeyCount; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/AppDesignVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/AppDesignVo.java new file mode 100644 index 0000000..b60ef76 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/AppDesignVo.java @@ -0,0 +1,50 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AppDesignVo { + + private String id; + + private String productKey; + + private String html; + + private Boolean state; + + private Long modifyAt; + + private String productName; + + private String cateName; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/AppPageNode.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/AppPageNode.java new file mode 100644 index 0000000..2c8a4a9 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/AppPageNode.java @@ -0,0 +1,52 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class AppPageNode { + + private String id; + + private String name; + + private String parent; + + Map props; + + Map appearance; + + Map binds; + + Map action; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/DeviceLog.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/DeviceLog.java new file mode 100644 index 0000000..0ecfe50 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/DeviceLog.java @@ -0,0 +1,31 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.model.vo; + +import lombok.Data; + +@Data +public class DeviceLog { + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/FindDeviceVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/FindDeviceVo.java new file mode 100644 index 0000000..5d8e463 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/FindDeviceVo.java @@ -0,0 +1,49 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class FindDeviceVo { + + private String deviceId; + + private String productKey; + + private String deviceName; + + private String productName; + + private String categoryName; + + private String productImg; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/LoginResult.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/LoginResult.java new file mode 100644 index 0000000..472109a --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/LoginResult.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class LoginResult { + + private String token; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/MessageVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/MessageVo.java new file mode 100644 index 0000000..88c5543 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/MessageVo.java @@ -0,0 +1,39 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MessageVo { + + private String content; + + private String time; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/SpaceDeviceVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/SpaceDeviceVo.java new file mode 100644 index 0000000..2f1a428 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/SpaceDeviceVo.java @@ -0,0 +1,111 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SpaceDeviceVo { + + private Long id; + + /** + * 空间中的设备id + */ + private String deviceId; + + /** + * 空间中的设备名称 + */ + private String name; + + /** + * 设备DN + */ + private String deviceName; + + /** + * 设备图片 + */ + private String picUrl; + + /** + * 空间ID + */ + private Long spaceId; + + /** + * 空间名称 + */ + private String spaceName; + + /** + * 设备状态 + */ + private Boolean online; + + /** + * 设备属性 + */ + private Map property = new HashMap<>(); + + /** + * 产品key + */ + private String productKey; + + /** + * 产品名 + */ + private String productName; + + /** + * 品类 + */ + private String category; + + /** + * 品类名 + */ + private String categoryName; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 是否收藏 + */ + private Boolean collect; +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/SpaceInfo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/SpaceInfo.java new file mode 100644 index 0000000..df29e4f --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/model/vo/SpaceInfo.java @@ -0,0 +1,38 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class SpaceInfo { + + private String address; + + private String userId; + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/AlertMessageEventListener.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/AlertMessageEventListener.java new file mode 100644 index 0000000..25bb851 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/AlertMessageEventListener.java @@ -0,0 +1,56 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service; + +import cc.iotkit.data.manager.IAlertConfigData; +import cc.iotkit.message.event.MessageEvent; +import cc.iotkit.message.listener.MessageEventListener; +import cc.iotkit.message.model.Message; +import cc.iotkit.model.alert.AlertConfig; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +/** + * @author sjg + */ +@Slf4j +@Component +public class AlertMessageEventListener implements MessageEventListener { + + @Autowired + private IAlertConfigData alertConfigData; + + @Autowired + private AlertService alertService; + + @Override + @EventListener(classes = MessageEvent.class) + public void doEvent(MessageEvent event) { + Message message = event.getMessage(); + AlertConfig alertConfig = alertConfigData.findById(message.getAlertConfigId()); + alertService.addAlert(alertConfig, message.getFormatContent()); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/AlertService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/AlertService.java new file mode 100644 index 0000000..1a34bb1 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/AlertService.java @@ -0,0 +1,74 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.data.manager.IAlertConfigData; +import cc.iotkit.data.manager.IAlertRecordData; +import cc.iotkit.model.alert.AlertConfig; +import cc.iotkit.model.alert.AlertRecord; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class AlertService { + + @Autowired + private IAlertConfigData alertConfigData; + @Autowired + private IAlertRecordData alertRecordData; + + public AlertConfig createAlertConfig(AlertConfig alertConfig) { + return alertConfigData.save(alertConfig); + } + + public AlertConfig updateAlertConfig(AlertConfig alertConfig) { + return alertConfigData.save(alertConfig); + } + + public void deleteAlertConfigById(Long id) { + alertConfigData.deleteById(id); + } + + public Paging selectAlertConfigPage(PageRequest request) { + return alertConfigData.selectAlertConfigPage(request); + } + + public Paging selectAlertRecordPage(PageRequest request) { + return alertRecordData.selectAlertConfigPage(request); + } + + public void addAlert(AlertConfig config, String content) { + alertRecordData.save(AlertRecord.builder() + .level(config.getLevel()) + .name(config.getName()) + .readFlg(false) + .alertTime(System.currentTimeMillis()) + .details(content) + .build()); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DIccidRecordService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DIccidRecordService.java new file mode 100644 index 0000000..e0ff4cc --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DIccidRecordService.java @@ -0,0 +1,60 @@ +package cc.iotkit.manager.service; + + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.manager.dto.vo.category.vo.*; +import cc.iotkit.model.iccid.DIccidRecordDO; +import cn.hutool.db.PageResult; + +import javax.validation.Valid; +import java.util.List; + +/** + * 物联网卡 Service 接口 + * + * @author 芋道源码 + */ +public interface DIccidRecordService { + + /** + * 创建物联网卡 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + String createDIccidRecord(@Valid DIccidRecordSaveReqVO createReqVO); + + /** + * 更新物联网卡 + * + * @param updateReqVO 更新信息 + */ + void updateDIccidRecord(@Valid DIccidRecordSaveReqVO updateReqVO); + + /** + * 删除物联网卡 + * + * @param id 编号 + */ + void deleteDIccidRecord(Long id); + + /** + * 获得物联网卡 + * + * @param id 编号 + * @return 物联网卡 + */ + DIccidRecordDO getDIccidRecord(Long id); + + /** + * 获得物联网卡分页 + * + * @param pageReqVO 分页查询 + * @return 物联网卡分页 + */ + Paging getDIccidRecordPage(PageRequest pageReqVO); + + String createList(DIccidRecordListSaveReqVO createReqVO, Integer num); + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DataOwnerService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DataOwnerService.java new file mode 100644 index 0000000..64f41d1 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DataOwnerService.java @@ -0,0 +1,127 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.service; + +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.Owned; +import cc.iotkit.model.device.DeviceInfo; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class DataOwnerService { + + public > T wrapExample(T data) { + if (AuthUtil.isAdmin()) { + return data; + } + data.setUid(AuthUtil.getUserId()); + return data; + } + + /** + * 检查数据中的uid与当前登录用户是否一致 + */ + public T checkOwner(T data) { + //管理员不限制 + if (AuthUtil.isAdmin()) { + return data; + } + + if (data == null) { + return null; + } + if (StringUtils.isBlank(data.getUid())) { + return data; + } + + String uid = AuthUtil.getUserId(); + if (uid.equals(data.getUid())) { + return data; + } + + if (data instanceof DeviceInfo) { + DeviceInfo device = (DeviceInfo) data; + //设备子用户验证 + List subUid = device.getSubUid(); + if (subUid != null && subUid.contains(uid)) { + return data; + } + } + +// throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION);暂时先注释,重新设计 + return data; + } + + /** + * 从库中取对应数据Id的数据中的uid是否与当前登录用户一致 + */ + public void checkOwner(ICommonData service, Object id) { + //管理员不限制 + if (AuthUtil.isAdmin()) { + return; + } + + //数据id为空的新数据 + if (StringUtils.isBlank(id.toString())) { + return; + } + + Owned old = (Owned) service.findById(id); + //新数据 + if (old == null) { + return; + } + + String currUid = AuthUtil.getUserId(); + if (currUid.equals(old.getUid())) { + return; + } + +// throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION);暂时先注释,重新设计 + return; + } + + /** + * 从库中取对应数据Id的数据中的uid是否与当前登录用户一致,并把当前用户id设置到数据中 + */ + public void checkOwnerSave(ICommonData service, Owned data) { +// checkOwner(service, data.getId()); + data.setUid(AuthUtil.getUserId()); + } + + public void checkWriteRole() { + if (AuthUtil.isAdmin()) { + return; + } + + if (!AuthUtil.hasWriteRole()) { + throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION); + } + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeferredDataConsumer.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeferredDataConsumer.java new file mode 100644 index 0000000..5b72687 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeferredDataConsumer.java @@ -0,0 +1,207 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.service; + +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.websocket.holder.WebSocketSessionHolder; +import cc.iotkit.common.websocket.utils.WebSocketUtils; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.space.SpaceDevice; +import cc.iotkit.mq.ConsumerHandler; +import cc.iotkit.mq.MqConsumer; +import cn.hutool.core.util.ObjectUtil; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.async.DeferredResult; + +import javax.annotation.PostConstruct; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.*; + +/** + * 长连接推送消息消费 + */ +@Slf4j +@Component +public class DeferredDataConsumer implements ConsumerHandler, Runnable { + + private final Map> topicConsumers = new ConcurrentHashMap<>(); + private final Map consumerDeferred = new ConcurrentHashMap<>(); + private final DelayQueue delayedPushes = new DelayQueue<>(); + + @Autowired + private ISpaceDeviceService deviceServiceImpl; + + @Autowired + private MqConsumer thingModelMessageConsumer; + + @PostConstruct + public void init() { + thingModelMessageConsumer.consume(Constants.THING_MODEL_MESSAGE_TOPIC, this); + Executors.newCachedThreadPool().submit(this); + } + + public DeferredResult newConsumer(String consumerId, String topic) { + topicConsumers.putIfAbsent(topic, new HashSet<>()); + Set consumers = topicConsumers.get(topic); + consumers.add(consumerId); + + String consumerKey = getConsumerKey(consumerId, topic); + DeferredResult result = new DeferredResult<>(10000L, new DeviceInfo()); + DeferredResultInfo resultInfo = new DeferredResultInfo(result, false); + result.onCompletion(() -> resultInfo.setCompleted(true)); + result.onTimeout(() -> resultInfo.setCompleted(true)); + + consumerDeferred.put(consumerKey, resultInfo); + return result; + } + + public void publish(String topic, T msg, boolean republish) { + Set consumers = topicConsumers.get(topic); + if (consumers == null) { + return; + } + for (String consumer : consumers) { + String consumerKey = getConsumerKey(consumer, topic); + DeferredResultInfo result = consumerDeferred.get(consumerKey); + if (result == null) { + continue; + } + + //如果已经推送完成了,等待1秒再尝试发送,让客户端有时间重连 + if (!republish && result.isCompleted() && !result.isExpired()) { + delayedPushes.offer(new DelayedPush<>(topic, System.currentTimeMillis(), msg), + 3, TimeUnit.SECONDS); + } else { + log.info("push {} to {},msg:{}", topic, consumer, JsonUtils.toJsonString(msg)); + result.getDeferredResult().setResult(msg); + } + } + } + + public void publish(String topic, T msg) { + publish(topic, msg, false); + } + + private String getConsumerKey(String consumerId, String topic) { + return consumerId + topic; + } + + @Override + public void handler(ThingModelMessage msg) { + String type = msg.getType(); + String identifier = msg.getIdentifier(); + //属性上报和上下线消息 + if ((ThingModelMessage.TYPE_PROPERTY.equals(type) && "report".equals(identifier)) || + ThingModelMessage.TYPE_STATE.equals(type)) { + publish(Constants.HTTP_CONSUMER_DEVICE_INFO_TOPIC + msg.getDeviceId(), + msg); + sendWebSocket(msg); + } + } + + public void sendWebSocket(ThingModelMessage msg){ + SpaceDevice deviceInfo=deviceServiceImpl.findByDeviceId(msg.getDeviceId()); + if(ObjectUtil.isNotNull(deviceInfo)&&ObjectUtil.isNotNull(deviceInfo.getCreateBy())&&WebSocketSessionHolder.existSession(deviceInfo.getCreateBy())){ + WebSocketUtils.sendMessage(deviceInfo.getCreateBy(),JsonUtils.toJsonString(msg)); + } + + } + + @Override + public void run() { + while (true) { + try { + DelayedPush delayedPush = delayedPushes.take(); + ThingModelMessage modelMessage = delayedPush.getMsg(); + publish(delayedPush.getTopic(), modelMessage, true); + } catch (Throwable e) { + log.error("delayed push error", e); + } + } + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class DeferredResultInfo { + private DeferredResult deferredResult; + private boolean completed; + private long completedTime; + + public DeferredResultInfo(DeferredResult deferredResult, boolean completed) { + this.deferredResult = deferredResult; + this.completed = completed; + this.completedTime = System.currentTimeMillis(); + } + + public void setCompleted(boolean completed) { + this.completed = completed; + this.completedTime = System.currentTimeMillis(); + } + + public boolean isExpired() { + //完成超过3后视为过期,客户端可能已断开 + return completed && System.currentTimeMillis() - completedTime > 3 * 1000L; + } + } + + @Data + public static class DelayedPush implements Delayed { + + private String topic; + + private T msg; + + private long addTime; + + public DelayedPush(String topic, long addTime, T message) { + this.topic = topic; + this.addTime = addTime; + this.msg = message; + } + + @Override + public long getDelay(TimeUnit unit) { + return unit.convert(addTime - System.nanoTime(), TimeUnit.NANOSECONDS); + } + + @Override + public int compareTo(Delayed o) { + long diff = o.getDelay(TimeUnit.NANOSECONDS) - getDelay(TimeUnit.NANOSECONDS); + if (diff == 0) { + return 0; + } + return diff > 0 ? 1 : -1; + } + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeviceCtrlService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeviceCtrlService.java new file mode 100644 index 0000000..7ae0ec8 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeviceCtrlService.java @@ -0,0 +1,218 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.service; + +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.thing.DeviceService; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.thing.ThingService; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.UniqueIdUtil; +import cc.iotkit.data.manager.IDeviceConfigData; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.model.device.DeviceConfig; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.temporal.IThingModelMessageData; +import cc.iotkit.virtualdevice.VirtualManager; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +import static cc.iotkit.common.enums.ErrCode.DEVICE_NOT_FOUND; +import static cc.iotkit.common.enums.ErrCode.DEVICE_OFFLINE; + +@Slf4j +@Service +public class DeviceCtrlService { + + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + @Autowired + private DataOwnerService dataOwnerService; + @Autowired + private ThingModelService thingModelService; + @Autowired + private IThingModelMessageData thingModelMessageData; + @Autowired + private VirtualManager virtualManager; + @Autowired + private IDeviceConfigData deviceConfigData; + @Autowired + private DeviceService deviceService; + + /** + * 设备服务调用 + */ + public String invokeService(String deviceId, String service, + Map args) { + return invokeService(deviceId, service, args, true); + } + + /** + * 设备服务调用 + */ + public String invokeService(String deviceId, String service, + Map args, boolean checkOwner) { + DeviceInfo device = getAndCheckDevice(deviceId, checkOwner); + + return send(deviceId, device.getProductKey(), device.getDeviceName(), + args, ThingModelMessage.TYPE_SERVICE, service); + } + + public String otaUpgrade(String deviceId, boolean checkOwner, Object data) { + DeviceInfo device = getAndCheckDevice(deviceId, checkOwner); + return send(deviceId, device.getProductKey(), device.getDeviceName(), + data, ThingModelMessage.TYPE_OTA, "ota"); + } + + /** + * 设备属性获取 + */ + public String getProperty(String deviceId, List properties, + boolean checkOwner) { + DeviceInfo device = getAndCheckDevice(deviceId, checkOwner); + + return send(deviceId, device.getProductKey(), device.getDeviceName(), properties, + ThingModelMessage.TYPE_PROPERTY, ThingModelMessage.ID_PROPERTY_GET); + } + + /** + * 设备属性设置 + */ + public String setProperty(String deviceId, Map properties) { + return setProperty(deviceId, properties, true); + } + + /** + * 设备属性设置 + */ + public String setProperty(String deviceId, Map properties, + boolean checkOwner) { + DeviceInfo device = getAndCheckDevice(deviceId, checkOwner); + + return send(deviceId, device.getProductKey(), device.getDeviceName(), properties, + ThingModelMessage.TYPE_PROPERTY, ThingModelMessage.ID_PROPERTY_SET); + } + + /** + * 设备配置下发 + */ + public String sendConfig(String deviceId, boolean checkOwner) { + DeviceInfo device = getAndCheckDevice(deviceId, checkOwner); + + DeviceConfig config = deviceConfigData.findByDeviceId(deviceId); + Map data = JsonUtils.parseObject(config.getConfig(), Map.class); + + return send(deviceId, device.getProductKey(), device.getDeviceName(), data, + ThingModelMessage.TYPE_CONFIG, ThingModelMessage.ID_CONFIG_SET); + } + + /** + * 设备配置下发 + */ + public String sendConfig(String deviceId) { + return sendConfig(deviceId, true); + } + + /** + * 检查设备操作权限和状态 + */ + private DeviceInfo getAndCheckDevice(String deviceId, boolean checkOwner) { + DeviceInfo device = deviceInfoData.findByDeviceId(deviceId); + if (device == null) { + throw new BizException(DEVICE_NOT_FOUND); + } + + if (checkOwner) { + dataOwnerService.checkOwner(device); + } + + if (!device.getState().isOnline()) { + throw new BizException(DEVICE_OFFLINE); + } + return device; + } + + /** + * 解绑子设备 + * + * @param deviceId 子设备id + */ + public void unbindDevice(String deviceId) { + DeviceInfo device = deviceInfoData.findByDeviceId(deviceId); + DeviceInfo parent = deviceInfoData.findByDeviceId(device.getParentId()); + + try { + //下发子设备注销给网关 + send(parent.getDeviceId(), parent.getProductKey(), parent.getDeviceName(), + Map.of( + "productKey", device.getProductKey(), + "deviceName", device.getDeviceName() + ), + ThingModelMessage.TYPE_LIFETIME, ThingModelMessage.ID_DEREGISTER); + } catch (Throwable e) { + log.error("send {} message error", ThingModelMessage.ID_DEREGISTER, e); + } + + //清除设备的父级id,不管是否发送成功都需要清除父级id + device.setParentId(""); + deviceInfoData.save(device); + } + + /** + * 数据下发 + */ + private String send(String deviceId, String pk, String dn, + Object data, String type, String identifier) { + ThingService thingService = ThingService.builder() + .mid(UniqueIdUtil.newRequestId()) + .productKey(pk) + .deviceName(dn) + .type(type) + .identifier(identifier) + .params(data) + .build(); + if (!ThingModelMessage.TYPE_CONFIG.equals(type) + && !ThingModelMessage.TYPE_LIFETIME.equals(type) + && !ThingModelMessage.TYPE_OTA.equals(type) + ) { + //非配置非OTA且非生命周期下发需要做物模型转换 + thingModelService.parseParams(thingService); + } + + if (virtualManager.isVirtual(deviceId)) { + //虚拟设备指令下发 + virtualManager.send(thingService); + } else { + //设备指令下发 + deviceService.invoke(thingService); + } + return thingService.getMid(); + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeviceStateCheckTask.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeviceStateCheckTask.java new file mode 100644 index 0000000..6253eb1 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/DeviceStateCheckTask.java @@ -0,0 +1,103 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.UniqueIdUtil; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.product.Product; +import cc.iotkit.plugin.core.thing.IThingService; +import cc.iotkit.plugin.core.thing.actions.DeviceState; +import cc.iotkit.plugin.core.thing.actions.up.DeviceStateChange; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +/** + * 设备状态检查定时任务 + */ +@Slf4j +@Component +public class DeviceStateCheckTask { + + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + + @Autowired + @Qualifier("productDataCache") + private IProductData productData; + + @Autowired + private IThingService thingService; + + @Scheduled(fixedDelay = 10, initialDelay = 20, timeUnit = TimeUnit.SECONDS) + public void syncState() { + int pn = 1; + Paging all; + while (true) { + //取出数据库中所有在线设备 + all = deviceInfoData.findByConditions("","","","",true,"",pn,1000,null); + //判断属性更新时间是否大于产品定义保活时长 + for (DeviceInfo device : all.getRows()) { + Product product = productData.findByProductKey(device.getProductKey()); + Long keepAliveTime = product.getKeepAliveTime(); + if (keepAliveTime == null || keepAliveTime <= 0) { + continue; + } + String deviceId = device.getDeviceId(); + long lastTime = deviceInfoData.getLastTime(deviceId); + //最后更新时间超时保活时长1.1倍认为设备离线了 + if (System.currentTimeMillis() - lastTime > keepAliveTime * 1000 * 1.1) { + DeviceInfo realTimeDevice = deviceInfoData.findByDeviceId(deviceId); + if (!realTimeDevice.isOnline()) { + continue; + } + log.info("device state check offline,{}", deviceId); + + // 发送设备离线物模型消息 + thingService.post("NONE", DeviceStateChange.builder() + .id(UniqueIdUtil.newRequestId()) + .productKey(realTimeDevice.getProductKey()) + .deviceName(realTimeDevice.getDeviceName()) + .state(DeviceState.OFFLINE) + .time(System.currentTimeMillis()) + .build()); + } + } + + if (all.getRows().size() < 1000) { + break; + } + pn++; + } + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ExampleDataInit.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ExampleDataInit.java new file mode 100644 index 0000000..4b51182 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ExampleDataInit.java @@ -0,0 +1,242 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.service; + +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.SpringUtils; +import cc.iotkit.data.ICommonData; +import cc.iotkit.data.manager.*; +import cc.iotkit.data.system.*; +import cc.iotkit.model.Id; +import cc.iotkit.model.OauthClient; +import cc.iotkit.model.UserInfo; +import cc.iotkit.model.device.DeviceGroup; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.VirtualDevice; +import cc.iotkit.model.notify.Channel; +import cc.iotkit.model.notify.ChannelConfig; +import cc.iotkit.model.notify.ChannelTemplate; +import cc.iotkit.model.notify.NotifyMessage; +import cc.iotkit.model.plugin.PluginInfo; +import cc.iotkit.model.product.*; +import cc.iotkit.model.rule.RuleInfo; +import cc.iotkit.model.rule.TaskInfo; +import cc.iotkit.model.space.Home; +import cc.iotkit.model.space.Space; +import cc.iotkit.model.space.SpaceDevice; +import cc.iotkit.model.system.*; +import cc.iotkit.temporal.IDbStructureData; +import cn.hutool.core.collection.CollectionUtil; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; +import org.springframework.beans.factory.SmartInitializingSingleton; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Paths; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +@Slf4j +@Service +public class ExampleDataInit implements SmartInitializingSingleton { + + @Value("${init.data.flag:true}") + private boolean initDataFlg; + + @Value("${init.data.path:.}") + private String initDataPath; + + @Autowired + private IDbStructureData dbStructureData; + + @Override + public void afterSingletonsInstantiated() { + //等redis实例化后再执行 + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + try { + File initFile = new File(".init"); + if (initFile.exists()) { + return; + } + + if (!initDataFlg) { + return; + } + initData("category", SpringUtils.getBean(ICategoryData.class), new TypeReference>() { + }); + initData("deviceGroup", SpringUtils.getBean(IDeviceGroupData.class), new TypeReference>() { + }); + initData("deviceInfo", SpringUtils.getBean(IDeviceInfoData.class), new TypeReference>() { + }); + initData("home", SpringUtils.getBean(IHomeData.class), new TypeReference>() { + }); +// initData("oauthClient", SpringUtils.getBean(IOauthClientData.class), new TypeReference>() { +// }); + initData("product", SpringUtils.getBean(IProductData.class), new TypeReference>() { + }); + initData("productModel", SpringUtils.getBean(IProductModelData.class), new TypeReference>() { + }); + initData("ruleInfo", SpringUtils.getBean(IRuleInfoData.class), new TypeReference>() { + }); + initData("space", SpringUtils.getBean(ISpaceData.class), new TypeReference>() { + }); + initData("spaceDevice", SpringUtils.getBean(ISpaceDeviceData.class), new TypeReference>() { + }); + initData("taskInfo", SpringUtils.getBean(ITaskInfoData.class), new TypeReference>() { + }); + List thingModels = initData("thingModel", SpringUtils.getBean(IThingModelData.class), new TypeReference<>() { + }); + //初始化物模型时序数据结构 + if(CollectionUtil.isNotEmpty(thingModels)) { + for (ThingModel thingModel : thingModels) { + dbStructureData.defineThingModel(thingModel); + } + } + + initData("userInfo", SpringUtils.getBean(IUserInfoData.class), new TypeReference>() { + }); + initData("virtualDevice", SpringUtils.getBean(IVirtualDeviceData.class), new TypeReference>() { + }); + initData("channel", SpringUtils.getBean(IChannelData.class), new TypeReference>() { + }); + initData("channelConfig", SpringUtils.getBean(IChannelConfigData.class), new TypeReference>() { + }); + initData("channelTemplate", SpringUtils.getBean(IChannelTemplateData.class), new TypeReference>() { + }); + initData("notifyMessage", SpringUtils.getBean(INotifyMessageData.class), new TypeReference>() { + }); + initData("pluginInfo", SpringUtils.getBean(IPluginInfoData.class), new TypeReference>() { + }); + initData("iconType", SpringUtils.getBean(IIconTypeData.class), new TypeReference>() { + }); + initData("icon", SpringUtils.getBean(IIconData.class), new TypeReference>() { + }); + + initSysData(); + + log.info("init data finished."); + + FileUtils.write(initFile, "", StandardCharsets.UTF_8); + } catch ( + Exception e) { + log.error("init error", e); + } + } + }, 100); + + } + + private void initSysData() throws IOException { + initData("sys_config", SpringUtils.getBean(ISysConfigData.class), new TypeReference>() { + }); + + initData("sys_dept", SpringUtils.getBean(ISysDeptData.class), new TypeReference>() { + }); + + initData("sys_dict_data", SpringUtils.getBean(ISysDictData.class), new TypeReference>() { + }); + + initData("sys_dict_type", SpringUtils.getBean(ISysDictTypeData.class), new TypeReference>() { + }); + + initData("sys_logininfor", SpringUtils.getBean(ISysLogininforData.class), new TypeReference>() { + }); + initData("sys_menu", SpringUtils.getBean(ISysMenuData.class), new TypeReference>() { + }); + + initData("sys_notice", SpringUtils.getBean(ISysNoticeData.class), new TypeReference>() { + }); + + initData("sys_oper_log", SpringUtils.getBean(ISysOperLogData.class), new TypeReference>() { + }); + + initData("sys_oss", SpringUtils.getBean(ISysOssData.class), new TypeReference>() { + }); + + initData("sys_oss_config", SpringUtils.getBean(ISysOssConfigData.class), new TypeReference>() { + }); + + initData("sys_post", SpringUtils.getBean(ISysPostData.class), new TypeReference>() { + }); + initData("sys_role", SpringUtils.getBean(ISysRoleData.class), new TypeReference>() { + }); + + initData("sys_role_dept", SpringUtils.getBean(ISysRoleDeptData.class), new TypeReference>() { + }); + + initData("sys_role_menu", SpringUtils.getBean(ISysRoleMenuData.class), new TypeReference>() { + }); + + initData("sys_tenant", SpringUtils.getBean(ISysTenantData.class), new TypeReference>() { + }); + + initData("sys_tenant_package", SpringUtils.getBean(ISysTenantPackageData.class), new TypeReference>() { + }); + + initData("sys_user", SpringUtils.getBean(ISysUserData.class), new TypeReference>() { + }); + + initData("sys_user_post", SpringUtils.getBean(ISysUserPostData.class), new TypeReference>() { + }); + + initData("sys_user_role", SpringUtils.getBean(ISysUserRoleData.class), new TypeReference>() { + }); + + initData("sys_app", SpringUtils.getBean(ISysAppData.class), new TypeReference>() { + }); + } + + private T initData(String name, ICommonData service, TypeReference type) { + try { + log.info("init {} data...", name); + if (service.count() > 0) { + log.error("原数据库已存在" + name + "的旧数据,请清除后再重新初始化!系统正在退出。。。"); + System.exit(0); + } + String path = initDataPath; + if (initDataPath.equals(".")) { + path = "./data/init"; + } + String json = FileUtils.readFileToString(Paths.get(path, name + ".json").toFile(), StandardCharsets.UTF_8); + List list = (List) JsonUtils.parseObject(json, type); + for (Object obj : list) { + service.save((Id) obj); + } + return (T) list; + } catch (Exception e) { + log.error("initData error", e); + return null; + } + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/FeedBackEvaluationService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/FeedBackEvaluationService.java new file mode 100644 index 0000000..4dd0573 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/FeedBackEvaluationService.java @@ -0,0 +1,59 @@ +package cc.iotkit.manager.service; + + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationPageReqVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationSaveReqVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationVO; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import cn.hutool.db.PageResult; + +import javax.validation.Valid; + +/** + * 意见反馈评价 Service 接口 + * + * @author zhp + */ +public interface FeedBackEvaluationService { + + /** + * 创建意见反馈评价 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createFeedBackEvaluation(@Valid FeedBackEvaluationSaveReqVO createReqVO); + + /** + * 更新意见反馈评价 + * + * @param updateReqVO 更新信息 + */ + void updateFeedBackEvaluation(@Valid FeedBackEvaluationSaveReqVO updateReqVO); + + /** + * 删除意见反馈评价 + * + * @param id 编号 + */ + void deleteFeedBackEvaluation(Long id); + + /** + * 获得意见反馈评价 + * + * @param id 编号 + * @return 意见反馈评价 + */ + FeedBackEvaluationDO getFeedBackEvaluation(Long id); + + /** + * 获得意见反馈评价分页 + * + * @param pageReqVO 分页查询 + * @return 意见反馈评价分页 + */ + Paging getFeedBackEvaluationPage(PageRequest pageReqVO); + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IDeviceManagerService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IDeviceManagerService.java new file mode 100644 index 0000000..429d653 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IDeviceManagerService.java @@ -0,0 +1,108 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.manager.dto.bo.device.DeviceInfoBo; +import cc.iotkit.manager.dto.bo.device.DeviceLogQueryBo; +import cc.iotkit.manager.dto.bo.device.DeviceQueryBo; +import cc.iotkit.manager.dto.bo.device.DeviceTagAddBo; +import cc.iotkit.manager.dto.bo.devicegroup.DeviceAddGroupBo; +import cc.iotkit.manager.dto.bo.devicegroup.DeviceGroupBo; +import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo; +import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo; +import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo; +import cc.iotkit.manager.dto.vo.deviceinfo.ParentDeviceVo; +import cc.iotkit.model.device.DeviceConfig; +import cc.iotkit.model.device.DeviceGroup; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DeviceProperty; +import org.springframework.web.context.request.async.DeferredResult; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +/** + * @Author: jay + * @Date: 2023/5/31 11:05 + * @Version: V1.0 + * @Description: 设备服务接口 + */ +public interface IDeviceManagerService { + Paging getDevices(PageRequest pageRequest); + + boolean addDevice(DeviceInfoBo data); + + List selectChildrenPageList(String deviceId); + + List getParentDevices(); + + DeviceInfo getDetail(String deviceId); + + DeviceInfo getByPkDn(String pk, String dn); + + boolean deleteDevice(String data); + + boolean batchDeleteDevice(List ids); + + Paging logs(PageRequest request); + + List getPropertyHistory(String deviceId, String name, long start, long end,int size); + + boolean unbindDevice(String data); + + boolean addTag(DeviceTagAddBo bo); + + boolean simulateSend(ThingModelMessage message); + + DeferredResult addConsumer(String deviceId, String clientId); + + Paging selectGroupPageList(PageRequest pageRequest); + + boolean addGroup(DeviceGroup group); + + boolean updateGroup(DeviceGroupBo data); + + boolean deleteGroup(String id); + + boolean clearGroup(String id); + + boolean addDevice2Group(DeviceAddGroupBo data); + + boolean removeDevices(String group, List devices); + + boolean saveConfig(DeviceConfig data); + + DeviceConfigVo getConfig(String deviceId); + + boolean saveDevice(DeviceInfoBo data); + + String importGroup(MultipartFile file); + + DeviceGroupVo getDeviceGroup(String id); + + String importDevice(MultipartFile file); +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IHomeService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IHomeService.java new file mode 100644 index 0000000..8bb2ed2 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IHomeService.java @@ -0,0 +1,50 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service; + +import cc.iotkit.manager.dto.bo.space.HomeBo; +import cc.iotkit.model.space.Home; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/8/25 10:21 + */ +public interface IHomeService { + + Home save(HomeBo home); + + Home findByUserIdAndCurrent(Long userId, boolean current); + + List findByUserId(Long userId); + + Home findById(Long id); + + boolean checkHomeNameUnique(HomeBo user); + + void deleteById(Long id); + + void changCurrentHome(HomeBo home); +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IPluginService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IPluginService.java new file mode 100644 index 0000000..0b727ea --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IPluginService.java @@ -0,0 +1,87 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.manager.dto.bo.plugin.PluginInfoBo; +import cc.iotkit.manager.dto.vo.plugin.PluginInfoVo; +import org.springframework.web.multipart.MultipartFile; + +/** + * @author sjg + */ +public interface IPluginService { + + /** + * 上传jar包 + * + * @param file 文件 + * @param id 插件id + */ + void upload(MultipartFile file, Long id); + + /** + * 添加插件 + * + * @param plugin 插件信息 + */ + void addPlugin(PluginInfoBo plugin); + + /** + * 修改插件信息 + * + * @param plugin 插件信息 + */ + void modifyPlugin(PluginInfoBo plugin); + + /** + * 获取插件信息 + * + * @param id 插件id + * @return 插件信息 + */ + PluginInfoVo getPlugin(Long id); + + /** + * 删除插件 + * + * @param id 插件id + */ + void deletePlugin(Long id); + + /** + * 分页查询 + * + * @param query 查询条件 + */ + Paging findPagePluginList(PageRequest query); + + /** + * 修改插件状态 + * + * @param plugin 插件信息 + */ + void changeState(PluginInfoBo plugin); +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IProductService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IProductService.java new file mode 100644 index 0000000..48b5244 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IProductService.java @@ -0,0 +1,96 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.manager.dto.bo.category.CategoryBo; +import cc.iotkit.manager.dto.bo.product.IconBo; +import cc.iotkit.manager.dto.bo.product.IconTypeBo; +import cc.iotkit.manager.dto.bo.product.ProductBo; +import cc.iotkit.manager.dto.bo.productmodel.ProductModelBo; +import cc.iotkit.manager.dto.bo.thingmodel.ThingModelBo; +import cc.iotkit.manager.dto.vo.category.CategoryVo; +import cc.iotkit.manager.dto.vo.product.IconTypeVo; +import cc.iotkit.manager.dto.vo.product.IconVo; +import cc.iotkit.manager.dto.vo.product.ProductVo; +import cc.iotkit.manager.dto.vo.productmodel.ProductModelVo; +import cc.iotkit.manager.dto.vo.thingmodel.ThingModelVo; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +/** + * @Author: jay + * @Date: 2023/5/30 16:23 + * @Version: V1.0 + * @Description: 产品服务接口 + */ +public interface IProductService { + ProductVo addEntity(ProductBo data); + + boolean updateEntity(ProductBo productBo); + + ProductVo getDetail(String data); + + boolean deleteProduct(String productKey); + + ThingModelVo getThingModelByProductKey(String data); + + boolean saveThingModel(ThingModelBo data); + + boolean deleteThingModel(Long id); + + boolean deleteCategory(String data); + + boolean editCategory(CategoryBo req); + + String uploadImg(String productKey, MultipartFile file); + + Paging selectPageList(PageRequest request); + + Paging selectCategoryPageList(PageRequest request); + + List selectCategoryList(); + + List getModels(String productKey); + + boolean editProductModel(ProductModelBo productModel); + + boolean deleteProductModel(String id); + + ProductVo findByProductKey(String productKey); + + boolean saveIconType(IconTypeBo data); + + boolean deleteIconType(Long data); + + boolean saveIcon(IconBo data); + + boolean deleteIcon(Long data); + + List selectIconTypeList(); + + Paging selectIconPageList(PageRequest request); +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IRuleEngineService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IRuleEngineService.java new file mode 100644 index 0000000..e333b1f --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IRuleEngineService.java @@ -0,0 +1,73 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.manager.dto.bo.ruleinfo.RuleInfoBo; +import cc.iotkit.manager.dto.bo.ruleinfo.RuleLogBo; +import cc.iotkit.manager.dto.bo.taskinfo.TaskInfoBo; +import cc.iotkit.manager.dto.bo.taskinfo.TaskLogBo; +import cc.iotkit.manager.dto.vo.ruleinfo.RuleInfoVo; +import cc.iotkit.manager.dto.vo.ruleinfo.RuleLogVo; +import cc.iotkit.manager.dto.vo.taskinfo.TaskInfoVo; +import cc.iotkit.manager.dto.vo.taskinfo.TaskLogVo; + +/** + * @Author: jay + * @Date: 2023/5/30 18:14 + * @Version: V1.0 + * @Description: 规则引擎服务接口 + */ +public interface IRuleEngineService { + Paging selectPageList(PageRequest request); + + boolean saveRule(RuleInfoBo ruleInfoBo); + + boolean pauseRule(String ruleId); + + boolean resumeRule(String ruleId); + + boolean deleteRule(String ruleId); + + Paging selectRuleLogPageList(PageRequest request); + + boolean clearRuleLogs(String ruleId); + + Paging selectTaskPageList(PageRequest request); + + boolean saveTask(TaskInfoBo taskInfo); + + boolean pauseTask(String taskId); + + boolean resumeTask(String data); + + boolean renewTask(String taskId); + + boolean deleteTask(String taskId); + + Paging selectTaskLogPageList(PageRequest request); + + boolean clearTaskLogs(String taskId); +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IScreenService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IScreenService.java new file mode 100644 index 0000000..aa81d04 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IScreenService.java @@ -0,0 +1,66 @@ +///* +// * +// * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 +// * * +---------------------------------------------------------------------- +// * * | Author: xw2sy@163.com +// * * +---------------------------------------------------------------------- +// * +// * Copyright [2024] [OPENIITA] +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// * / +// */ +// +//package cc.iotkit.manager.service; +// +//import cc.iotkit.common.api.PageRequest; +//import cc.iotkit.common.api.Paging; +//import cc.iotkit.manager.dto.bo.screen.DebugChangeBo; +//import cc.iotkit.manager.dto.bo.screen.PublishChangeBo; +//import cc.iotkit.model.screen.Screen; +//import cc.iotkit.model.screen.ScreenApi; +//import org.springframework.web.multipart.MultipartFile; +// +//import java.util.List; +// +///** +// * @Author:tfd +// * @Date:2023/6/25 15:14 +// */ +//public interface IScreenService { +// Long uploadResourceFile(MultipartFile file, Long id); +// +// List findByScreenId(Long id); +// +// Screen getDefaultScreen(); +// +// List syncResourceApis(Long id); +// +// void previewApis(List screenApis); +// +// void saveScreenApis(List screenApis); +// +// void debugModeChange(DebugChangeBo debugChange); +// +// void addBigScreen(Screen screen); +// +// void saveBigScreen(Screen screen); +// +// void publishStatusChange(PublishChangeBo data); +// +// void setDefaultScreen(Long id); +// +// void deleteScreen(Long id); +// +// Paging getBigScreens(PageRequest request); +//} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ISpaceDeviceService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ISpaceDeviceService.java new file mode 100644 index 0000000..1eb2d49 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ISpaceDeviceService.java @@ -0,0 +1,55 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.model.space.SpaceDevice; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/8/25 14:46 + */ +public interface ISpaceDeviceService { + + List findByHomeIdAndCollect(Long homeId,boolean collect); + + SpaceDevice findByDeviceId(String deviceId); + + SpaceDevice save(SpaceDevice spaceDevice); + + List findByHomeId(Long homeId); + + List findBySpaceId(Long spaceId); + + void deleteById (Long id); + + SpaceDevice findById (Long id); + + Paging findByTypeAndDeviceIds(List deviceIds, String type, + String identifier, + int page, int size); +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ISpaceService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ISpaceService.java new file mode 100644 index 0000000..33cc1aa --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ISpaceService.java @@ -0,0 +1,43 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service; + +import cc.iotkit.model.space.Space; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/8/25 10:22 + */ +public interface ISpaceService { + + Space save(Space space); + + List findByHomeId(Long homeId); + + Space findById(Long id); + + void deleteById(Long id); +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IWorderService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IWorderService.java new file mode 100644 index 0000000..b65ecdd --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/IWorderService.java @@ -0,0 +1,65 @@ +package cc.iotkit.manager.service; + + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationPageReqVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationSaveReqVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationVO; +import cc.iotkit.manager.dto.vo.worder.WorderPageReqVO; +import cc.iotkit.manager.dto.vo.worder.WorderRespVO; +import cc.iotkit.manager.dto.vo.worder.WorderSaveReqVO; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import cc.iotkit.model.worder.WorderDO; +import cn.hutool.db.PageResult; + +import javax.validation.Valid; + +/** + * 意见反馈评价 Service 接口 + * + * @author zhp + */ +public interface IWorderService { + + /** + * 创建工单 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createWorder(@Valid WorderSaveReqVO createReqVO); + + /** + * 更新工单 + * + * @param updateReqVO 更新信息 + */ + void updateWorder(@Valid WorderSaveReqVO updateReqVO); + + /** + * 删除工单 + * + * @param id 编号 + */ + void deleteWorder(Long id); + + /** + * 获得工单 + * + * @param id 编号 + * @return 工单 + */ + WorderDO getWorder(Long id); + + + // Boolean tenantOvermanagedCheck(); + + /** + * 获得工单分页 + * + * @param pageReqVO 分页查询 + * @return 工单分页 + */ + Paging getWorderPage(PageRequest pageReqVO); +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/NotifyService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/NotifyService.java new file mode 100644 index 0000000..d72a789 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/NotifyService.java @@ -0,0 +1,121 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.manager.IChannelConfigData; +import cc.iotkit.data.manager.IChannelData; +import cc.iotkit.data.manager.IChannelTemplateData; +import cc.iotkit.data.manager.INotifyMessageData; +import cc.iotkit.manager.dto.bo.channel.ChannelConfigBo; +import cc.iotkit.manager.dto.bo.channel.ChannelTemplateBo; +import cc.iotkit.manager.dto.vo.channel.ChannelConfigVo; +import cc.iotkit.manager.dto.vo.channel.ChannelTemplateVo; +import cc.iotkit.model.notify.Channel; +import cc.iotkit.model.notify.ChannelConfig; +import cc.iotkit.model.notify.ChannelTemplate; +import cc.iotkit.model.notify.NotifyMessage; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * author: 石恒 + * date: 2023-05-11 15:21 + * description: + **/ +@Slf4j +@Service +public class NotifyService { + + @Resource + private IChannelData iChannelData; + + @Resource + private IChannelConfigData iChannelConfigData; + + @Resource + private IChannelTemplateData iChannelTemplateData; + + @Resource + private INotifyMessageData iNotifyMessageData; + + public List getChannelList() { + return iChannelData.findAll(); + } + + public Paging getChannelConfigList(PageRequest request) { + return iChannelConfigData.findAll(request.to(ChannelConfig.class)).to(ChannelConfigVo.class); + } + + public List getChannelConfigAll() { + return MapstructUtils.convert(iChannelConfigData.findAll(),ChannelConfigVo.class); + } + + public ChannelConfig addChannelConfig(ChannelConfig channelConfig) { + return iChannelConfigData.save(channelConfig); + } + + public ChannelConfig getChannelConfigById(Long id) { + return iChannelConfigData.findById(id); + } + + public ChannelConfig updateChannelConfigById(ChannelConfig channelConfig) { + return iChannelConfigData.save(channelConfig); + } + + public Boolean delChannelConfigById(Long id) { + iChannelConfigData.deleteById(id); + return Boolean.TRUE; + } + + public Paging getChannelTemplateList(PageRequest request) { + return iChannelTemplateData.findAll(request.to(ChannelTemplate.class)).to(ChannelTemplateVo.class); + } + + public ChannelTemplate addChannelTemplate(ChannelTemplateBo channelTemplate) { + return iChannelTemplateData.save(channelTemplate.to(ChannelTemplate.class)); + } + + public ChannelTemplate getChannelTemplateById(Long id) { + return iChannelTemplateData.findById(id); + } + + public ChannelTemplate updateChannelTemplateById(ChannelTemplate channelTemplate) { + return iChannelTemplateData.save(channelTemplate); + } + + public Boolean delChannelTemplateById(Long id) { + iChannelTemplateData.deleteById(id); + return Boolean.TRUE; + } + + public Paging getNotifyMessageList(PageRequest request) { + return iNotifyMessageData.findAll(request); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/OtaService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/OtaService.java new file mode 100644 index 0000000..c2138b2 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/OtaService.java @@ -0,0 +1,233 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.oss.core.OssClient; +import cc.iotkit.common.oss.factory.OssFactory; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IDeviceOtaDetailData; +import cc.iotkit.data.manager.IDeviceOtaInfoData; +import cc.iotkit.data.manager.IOtaPackageData; +import cc.iotkit.data.system.ISysOssData; +import cc.iotkit.manager.dto.bo.ota.DeviceOtaDetailBo; +import cc.iotkit.manager.dto.bo.ota.DeviceOtaInfoBo; +import cc.iotkit.manager.dto.bo.ota.OtaPackageBo; +import cc.iotkit.manager.dto.vo.ota.DeviceOtaDetailVo; +import cc.iotkit.manager.dto.vo.ota.DeviceOtaInfoVo; +import cc.iotkit.manager.dto.vo.ota.OtaPackageUploadVo; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.ota.DeviceOtaDetail; +import cc.iotkit.model.ota.DeviceOtaInfo; +import cc.iotkit.model.ota.OtaPackage; +import cc.iotkit.model.system.SysOss; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.io.FileUtils; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import cc.iotkit.common.oss.entity.UploadResult; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; + +/** + * @Author: 石恒 + * @Date: 2023/5/19 20:49 + * @Description: + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class OtaService { + + private final IOtaPackageData iOtaPackageData; + private final DeviceCtrlService deviceCtrlService; + + private final IDeviceOtaInfoData deviceOtaInfoData; + @Qualifier("deviceInfoDataCache") + private final IDeviceInfoData deviceInfoData; + private final IDeviceOtaDetailData deviceOtaDetailData; + private final ISysOssData sysOssData; + + public OtaPackageUploadVo uploadFile(MultipartFile file) throws Exception { + String originalFileName = file.getOriginalFilename(); + if (originalFileName == null) { + throw new BizException("文件名为空,获取失败"); + } + String suffix = StringUtils.substring(originalFileName, originalFileName.lastIndexOf("."), originalFileName.length()); + OssClient storage = OssFactory.instance(); + UploadResult uploadResult; + try { + uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType()); + } catch (IOException e) { + throw new BizException(e.getMessage()); + } + // 保存文件信息 + SysOss oss = new SysOss(); + oss.setUrl(uploadResult.getUrl()); + oss.setFileSuffix(suffix); + oss.setFileName(uploadResult.getFilename()); + oss.setOriginalName(originalFileName); + oss.setService(storage.getConfigKey()); + oss = sysOssData.save(oss); + + String md5 = md5OfFile(file); + OtaPackageUploadVo otaPackageUploadVo = new OtaPackageUploadVo(); + otaPackageUploadVo.setUrl(uploadResult.getUrl()); + otaPackageUploadVo.setSize(file.getSize()); + otaPackageUploadVo.setMd5(md5); + otaPackageUploadVo.setOriginalName(originalFileName); + otaPackageUploadVo.setOssId(oss.getId()); + return otaPackageUploadVo; + } + + public static String md5OfFile(MultipartFile multipartFile) throws Exception { + File file = null; + if (multipartFile.isEmpty()) { + return ""; + } + try { + //本质上还是在项目根路径创建文件 + file = new File(multipartFile.getOriginalFilename()); + //将MultipartFile的byte[]写入到file中 + FileUtils.writeByteArrayToFile(file, multipartFile.getBytes()); + byte[] bytes = DigestUtils.md5(multipartFile.getInputStream()); + } catch (IOException e) { + e.printStackTrace(); + } + MessageDigest md = MessageDigest.getInstance("MD5"); + FileInputStream fs = new FileInputStream(file); + BufferedInputStream bs = new BufferedInputStream(fs); + byte[] buffer = new byte[1024]; + int bytesRead; + + while ((bytesRead = bs.read(buffer, 0, buffer.length)) != -1) { + md.update(buffer, 0, bytesRead); + } + byte[] digest = md.digest(); + + StringBuilder sb = new StringBuilder(); + for (byte bite : digest) { + sb.append(String.format("%02x", bite & 0xff)); + } + return sb.toString(); + } + + public OtaPackage addOtaPackage(OtaPackageBo otaPackage) { + return iOtaPackageData.save(otaPackage.to(OtaPackage.class)); + } + + public Boolean delOtaPackageById(Long id) { + iOtaPackageData.deleteById(id); + return Boolean.TRUE; + } + + public Paging getOtaPackagePageList(PageRequest request) { + return iOtaPackageData.findAll(request); + } + + /** + * 开始升级 + */ + public String startUpgrade(Long otaPackageId, List deviceIds) { + OtaPackage otaPackage = iOtaPackageData.findById(otaPackageId); + if (Objects.isNull(otaPackage)) { + throw new BizException(ErrCode.DATA_NOT_EXIST); + } + DeviceOtaInfo deviceOtaInfo = deviceOtaInfoData.save(DeviceOtaInfo.builder() + .total(deviceIds.size()) + .packageId(otaPackageId) + .productKey(otaPackage.getProductKey()) + .module(otaPackage.getModule()) + .desc(otaPackage.getDesc()) + .version(otaPackage.getVersion()) + .createAt(System.currentTimeMillis()) + .build()); + + List deviceOtaDetails = new ArrayList<>(); + AtomicReference success = new AtomicReference<>(0); + AtomicReference fail = new AtomicReference<>(0); + deviceIds.forEach(deviceId -> { + try { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + String taskId = deviceCtrlService.otaUpgrade(deviceId, true, otaPackage); + deviceOtaDetails.add(DeviceOtaDetail.builder() + .taskId(taskId) + .deviceName(deviceInfo.getDeviceName()) + .otaInfoId(deviceOtaInfo.getId()) + .module(otaPackage.getModule()) + .version(otaPackage.getVersion()) + .step(0) + .deviceId(deviceId) + .build()); + success.getAndSet(success.get() + 1); + } catch (Exception ex) { + log.error("add device upgrade error deviceId:{} ", deviceId, ex); + fail.getAndSet(fail.get() + 1); + } + }); + deviceOtaDetailData.batchSave(deviceOtaDetails); + deviceOtaInfo.setSuccess(success.get()); + deviceOtaInfo.setFail(fail.get()); + deviceOtaInfoData.save(deviceOtaInfo); + return "发起升级【" + success.get() + "】条,失败【" + fail.get() + "】条"; + } + + public Paging otaDeviceDetail(PageRequest request) { + return deviceOtaDetailData.findAll(request.to(DeviceOtaDetail.class)).to(DeviceOtaDetailVo.class); + } + + public Paging otaDeviceInfo(PageRequest request) { + return deviceOtaInfoData.findAll(request.to(DeviceOtaInfo.class)).to(DeviceOtaInfoVo.class); + } + + public void testStartUpgrade() { + String deviceId = "16885697173790test100001230000123"; + OtaPackage otaPackage = OtaPackage.builder() + .createAt(System.currentTimeMillis()) + .desc("升级测试") + .md5("AAAABCC") + .sign("AAAAAAAA") + .isDiff(false) + .size(1024L) + .url("http://www.baidu.com/resource/test.jpg") + .version("1.2.1") + .build(); + deviceCtrlService.otaUpgrade(deviceId, true, otaPackage); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/SpaceDeviceService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/SpaceDeviceService.java new file mode 100644 index 0000000..cdc8f9b --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/SpaceDeviceService.java @@ -0,0 +1,78 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.service; + +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.data.manager.ISpaceDeviceData; +import cc.iotkit.manager.model.vo.SpaceDeviceVo; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.product.Product; +import cc.iotkit.model.space.SpaceDevice; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class SpaceDeviceService { + @Autowired + private ISpaceDeviceData spaceDeviceData; + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + @Autowired + @Qualifier("productDataCache") + private IProductData productData; +//TODO 没看到使用 +// public List getUserDevices(String uid, String spaceId) { +// SpaceDevice device = new SpaceDevice(); +// device.setUid(uid); +// List spaceDevices; +// if (StringUtils.isNotBlank(spaceId)) { +// device.setSpaceId(spaceId); +// spaceDevices = spaceDeviceData.findByUidAndSpaceIdOrderByAddAtDesc(uid, spaceId); +// } else { +// spaceDevices = spaceDeviceData.findBySpaceIdOrderByAddAtDesc(spaceId); +// } +// +// List spaceDeviceVos = new ArrayList<>(); +// spaceDevices.forEach(sd -> { +// DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(sd.getDeviceId()); +// Product product = productData.findByProductKey(deviceInfo.getProductKey()); +// spaceDeviceVos.add(SpaceDeviceVo.builder() +// .uid(sd.getUid()) +// .deviceId(sd.getDeviceId()) +// .name(sd.getName()) +// .picUrl(product.getImg()) +// .online(deviceInfo.getState().isOnline()) +// .property(deviceInfo.getProperty()) +// .productKey(deviceInfo.getProductKey()) +// .build()); +// }); +// return spaceDeviceVos; +// } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ThingModelService.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ThingModelService.java new file mode 100644 index 0000000..29f5939 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/ThingModelService.java @@ -0,0 +1,96 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.manager.service; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.thing.ThingService; +import cc.iotkit.data.manager.IThingModelData; +import cc.iotkit.model.product.ThingModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Component +public class ThingModelService { + @Autowired + private IThingModelData thingModelData; + + public void parseParams(ThingService service) { + ThingModel thingModel = thingModelData.findByProductKey(service.getProductKey()); + ThingModel.Model model = thingModel.getModel(); + + String type = service.getType(); + String identifier = service.getIdentifier(); + Object params = null; + //属性设置 + if (ThingService.TYPE_PROPERTY.equals(type)) { + List properties = model.getProperties(); + if (properties == null) { + return; + } + if(identifier.equals(ThingModelMessage.ID_PROPERTY_GET)){ + params = service.getParams(); + } + else { + params = parseProperties(properties, (Map) service.getParams()); + } + } else if (ThingService.TYPE_SERVICE.equals(type)) { + //服务调用 + Map services = model.serviceMap(); + ThingModel.Service s = services.get(identifier); + if (s == null) { + return; + } + params = parseParams(s.getInputData(), (Map) service.getParams()); + } + service.setParams(params); + } + + private Map parseParams(List parameters, Map params) { + Map parsed = new HashMap<>(); + parameters.forEach((p -> parseField(p.getIdentifier(), p.getDataType(), params, parsed))); + return parsed; + } + + private Map parseProperties(List properties, Map params) { + Map parsed = new HashMap<>(); + properties.forEach((p -> parseField(p.getIdentifier(), p.getDataType(), params, parsed))); + return parsed; + } + + private void parseField(String identifier, ThingModel.DataType dataType, Map params, Map parsed) { + Object val = params.get(identifier); + if (val == null) { + return; + } + Object result = dataType.parse(val); + if (result == null) { + return; + } + parsed.put(identifier, result); + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/DIccidRecordServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/DIccidRecordServiceImpl.java new file mode 100644 index 0000000..ed5fc3b --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/DIccidRecordServiceImpl.java @@ -0,0 +1,157 @@ +package cc.iotkit.manager.service.impl; + + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.manager.IDIccidRecordData; + +import cc.iotkit.manager.config.BeanUtils; +import cc.iotkit.manager.dto.vo.category.vo.*; +import cc.iotkit.manager.dto.vo.taskinfo.TaskInfoVo; +import cc.iotkit.manager.service.DIccidRecordService; +import cc.iotkit.model.iccid.DIccidRecordDO; +import cc.iotkit.model.rule.TaskInfo; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; + +import cn.hutool.db.PageResult; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.formula.functions.T; +import org.hibernate.service.spi.ServiceException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.*; +import java.util.stream.Collectors; + + + +/** + * 物联网卡 Service 实现类 + * + * @author 芋道源码 + */ +@Slf4j +@Service +public class DIccidRecordServiceImpl implements DIccidRecordService { + + @Autowired + private IDIccidRecordData idIccidRecordData; + + + + @Override + @Transactional(rollbackFor = {Exception.class, RuntimeException.class, ServiceException.class}) + public String createDIccidRecord(DIccidRecordSaveReqVO createReqVO) { + // TenantContextHolder.setIgnore(true); + // 插入 + DIccidRecordDO dIccidRecord = BeanUtils.toBean(createReqVO, DIccidRecordDO.class); + DIccidRecordDO dIccidRecordDO = idIccidRecordData.findOneByCondition(dIccidRecord); + Assert.isNull(dIccidRecordDO, "厂商物联网卡iccid已经存在"); + // dIccidRecord.setState(0); + // dIccidRecord.setOrderId(String.valueOf(IdUtil.getSnowflake(1, 1).nextId())); + //修改厂商物联网数量 + // TenantContextHolder.setIgnore(true); + // TenantDO tenantDO = tenantMapper.selectOne(new QueryWrapper().lambda().eq(TenantDO::getId, dIccidRecord.getUserCode())); + + // Assert.isTrue(tenantDO.getAccountCount() > 0, "剩余授权数量不足"); + // dIccidRecord.setExpirationTime(DateUtil.offsetDay(new Date(), dIccidRecord.getValidDays()).toLocalDateTime()); + // dIccidRecord.setUser(tenantDO.getName()); + //dIccidRecord.setTenantId(tenantDO.getId()); + // 返回 + // tenantMapper.update(new UpdateWrapper().lambda().eq(TenantDO::getId, tenantDO.getId()).set(TenantDO::getAccountCount, tenantDO.getAccountCount() - 1)); + + idIccidRecordData.save(dIccidRecord); + return null; + } + + @Override + @Transactional(rollbackFor = {Exception.class, RuntimeException.class, ServiceException.class}) + public void updateDIccidRecord(DIccidRecordSaveReqVO updateReqVO) { + // TenantContextHolder.setIgnore(true); + // 校验存在 + validateDIccidRecordExists(updateReqVO.getId()); + //TenantDO tenantDO = tenantMapper.selectOne(new QueryWrapper().lambda().eq(TenantDO::getId, updateReqVO.getUserCode())); + // 更新 + DIccidRecordDO updateObj = BeanUtils.toBean(updateReqVO, DIccidRecordDO.class); + // updateObj.setTenantId(tenantDO.getId()); + idIccidRecordData.save(updateObj); + } + + @Override + @Transactional(rollbackFor = {Exception.class, RuntimeException.class, ServiceException.class}) + public void deleteDIccidRecord(Long id) { + // 校验存在 + validateDIccidRecordExists(id); + idIccidRecordData.deleteById(id); + // 删除 + /* List list = Arrays.asList(id.split(",")); + List dIccidRecordDOS = dIccidRecordMapper.selectList(new QueryWrapper().lambda().in(TbDIccidRecordDO::getId, list)); + List collected = dIccidRecordDOS.stream().map(TbDIccidRecordDO::getIccid).collect(Collectors.toList()); + List tdProductDOS = tdProductMapper.selectList(new QueryWrapper().lambda().in(TdProductDO::getIccid, collected)); + if (ObjectUtil.isNotEmpty(tdProductDOS)) { + List collect = tdProductDOS.stream().map(TdProductDO::getId).collect(Collectors.toList()); + tdProductMapper.delete(new QueryWrapper().lambda().in(TdProductDO::getId, collect)); + tdProductDeptMapper.delete(new QueryWrapper().lambda().in(TdProductDeptDO::getProductId)); + } + dIccidRecordMapper.deleteBatchIds(list);*/ + } + + private void validateDIccidRecordExists(Long id) { + if (idIccidRecordData.findById(id) == null) { + throw new RuntimeException("物联网卡iccid不存在"); + } + } + + @Override + public DIccidRecordDO getDIccidRecord(Long id) { + return idIccidRecordData.findById(id); + } + + + + @Override + @Transactional(rollbackFor = {Exception.class, RuntimeException.class, ServiceException.class}) + public String createList(DIccidRecordListSaveReqVO createReqVO, Integer num) { + //修改厂商物联网数量 + // TenantContextHolder.setIgnore(true); + // TenantDO tenantDO = tenantMapper.selectOne(new QueryWrapper().lambda().eq(TenantDO::getId, createReqVO.getUserCode())); + DIccidRecordDO dIccidRecord = BeanUtils.toBean(createReqVO, DIccidRecordDO.class); + // DeptDO deptDO = deptMapper.selectOne(new QueryWrapper().lambda().eq(DeptDO::getId, createReqVO.getUserCode())); + // Assert.isTrue(tenantDO.getAccountCount() - num > 0, "剩余授权数量不足"); + List dIccidRecordDOS = new ArrayList<>(); + List dIccidRecordDOS1 = idIccidRecordData.findAllByCondition(dIccidRecord); + Map collect = dIccidRecordDOS1.stream().collect(Collectors.toMap(DIccidRecordDO::getIccid, DIccidRecordDO::getId)); + for (int i = createReqVO.getStartIccid(); i <= createReqVO.getEndIccid(); i++) { + DIccidRecordDO dIccidRecord1 = BeanUtils.toBean(createReqVO, DIccidRecordDO.class); + Long s1 = collect.get(dIccidRecord.getIccid() + i); + if (ObjectUtil.isEmpty(s1)) { + dIccidRecord1.setIccid(dIccidRecord.getIccid() + i); + dIccidRecord1.setState(0); + //dIccidRecord1.setUser(tenantDO.getName()); + // dIccidRecord.setTenantId(tenantDO.getId()); + dIccidRecord1.setExpirationTime(DateUtil.offsetDay(new Date(), dIccidRecord.getValidDays()).toLocalDateTime()); + dIccidRecord1.setOrderId(String.valueOf(IdUtil.getSnowflake(1, 1).nextId())); + dIccidRecordDOS.add(dIccidRecord1); + } + } + // 插入 + // tenantMapper.update(new UpdateWrapper().lambda().eq(TenantDO::getId, tenantDO.getId()).set(TenantDO::getAccountCount, tenantDO.getAccountCount() - num)); + idIccidRecordData.batchSave(dIccidRecordDOS); + return "录入成功"; + } + + @Override + public Paging getDIccidRecordPage(PageRequest pageReqVO) { + + return idIccidRecordData.findAll(pageReqVO.to(DIccidRecordDO.class)).to(DIccidRecordRespVO.class); + + } + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/DeviceManagerServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/DeviceManagerServiceImpl.java new file mode 100644 index 0000000..353f5fd --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/DeviceManagerServiceImpl.java @@ -0,0 +1,481 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.excel.core.ExcelResult; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.*; +import cc.iotkit.data.manager.IDeviceConfigData; +import cc.iotkit.data.manager.IDeviceGroupData; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.manager.dto.bo.device.DeviceInfoBo; +import cc.iotkit.manager.dto.bo.device.DeviceLogQueryBo; +import cc.iotkit.manager.dto.bo.device.DeviceQueryBo; +import cc.iotkit.manager.dto.bo.device.DeviceTagAddBo; +import cc.iotkit.manager.dto.bo.devicegroup.DeviceAddGroupBo; +import cc.iotkit.manager.dto.bo.devicegroup.DeviceGroupBo; +import cc.iotkit.manager.dto.vo.deviceconfig.DeviceConfigVo; +import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupImportVo; +import cc.iotkit.manager.dto.vo.devicegroup.DeviceGroupVo; +import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoImportVo; +import cc.iotkit.manager.dto.vo.deviceinfo.DeviceInfoVo; +import cc.iotkit.manager.dto.vo.deviceinfo.ParentDeviceVo; +import cc.iotkit.manager.listener.DeviceGroupImportListener; +import cc.iotkit.manager.listener.DeviceInfoImportListener; +import cc.iotkit.manager.service.DataOwnerService; +import cc.iotkit.manager.service.DeferredDataConsumer; +import cc.iotkit.manager.service.DeviceCtrlService; +import cc.iotkit.manager.service.IDeviceManagerService; +import cc.iotkit.model.device.DeviceConfig; +import cc.iotkit.model.device.DeviceGroup; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DeviceProperty; +import cc.iotkit.model.product.Product; +import cc.iotkit.mq.MqProducer; +import cc.iotkit.temporal.IDevicePropertyData; +import cc.iotkit.temporal.IThingModelMessageData; +import lombok.SneakyThrows; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; +import org.springframework.web.context.request.async.DeferredResult; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Author: jay + * @Date: 2023/5/31 11:06 + * @Version: V1.0 + * @Description: 设备服务实现 + */ + +@Service +public class DeviceManagerServiceImpl implements IDeviceManagerService { + + @Autowired + private DeviceCtrlService deviceCtrlService; + + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + @Autowired + @Qualifier("productDataCache") + private IProductData productData; + @Autowired + private DataOwnerService dataOwnerService; + + @Lazy + @Autowired + private IThingModelMessageData thingModelMessageData; + @Lazy + @Autowired + private IDevicePropertyData devicePropertyData; + @Autowired + DeferredDataConsumer deferredDataConsumer; + @Autowired + private IDeviceGroupData deviceGroupData; + @Autowired + private IDeviceConfigData deviceConfigData; + + @Autowired + private MqProducer producer; + + @Override + public Paging getDevices(PageRequest pageRequest) { + DeviceQueryBo query = pageRequest.getData(); + + String uid = ""; + String subUid = ""; + + String pk = query.getProductKey(); + //关键字查询 + String keyword = query.getKeyword(); + String group = query.getGroup(); + Boolean online = query.getOnline(); + Long areaDepeId = query.getDeptAreaId(); + Paging result = MapstructUtils.convert(deviceInfoData.findByConditions(uid, subUid, pk, group, + online, keyword, pageRequest.getPageNum(), pageRequest.getPageSize(), areaDepeId), DeviceInfoVo.class); + for (DeviceInfoVo row : result.getRows()) { + row.setProduct(productData.findByProductKey(row.getProductKey())); + } + return result; + } + + @Override + public boolean addDevice(DeviceInfoBo deviceInfo) { + + String productKey = deviceInfo.getProductKey(); + String deviceName = deviceInfo.getDeviceName(); + String parentId = deviceInfo.getParentId(); + + Product product = productData.findByProductKey(productKey); + if (product == null) { + throw new BizException(ErrCode.PRODUCT_NOT_FOUND); + } + //同产品不可重复设备名 + DeviceInfo deviceRepetition = deviceInfoData.findByDeviceName(deviceName); + if (deviceRepetition != null) { + throw new BizException(ErrCode.MODEL_DEVICE_ALREADY); + } + //生成设备密钥 + String chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"; + int maxPos = chars.length(); + StringBuilder secret = new StringBuilder(); + for (var i = 0; i < 16; i++) { + secret.append(chars.charAt((int) Math.floor(Math.random() * maxPos))); + } + + DeviceInfo device = new DeviceInfo(); + device.setId(DeviceUtil.newDeviceId(deviceName)); + device.setUid(product.getUid()); + device.setDeviceId(device.getId()); + device.setProductKey(productKey); + device.setDeviceName(deviceName); + device.setSecret(secret.toString()); + device.setState(new DeviceInfo.State(false, null, null)); + device.setLocate(new DeviceInfo.Locate(deviceInfo.getLongitude(), deviceInfo.getLatitude())); + device.setCreateAt(System.currentTimeMillis()); + if (StringUtils.isNotBlank(parentId)) { + device.setParentId(parentId); + } + deviceInfoData.save(device); + return true; + } + + @Override + public List selectChildrenPageList(String deviceId) { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + if (deviceInfo == null) { + throw new BizException(ErrCode.DEVICE_NOT_FOUND); + } + + dataOwnerService.checkOwner(deviceInfo); + List list = MapstructUtils.convert(deviceInfoData.findByParentId(deviceId), DeviceInfoVo.class); + for (DeviceInfoVo row : list) { + row.setProduct(productData.findByProductKey(row.getProductKey())); + } + return list; + } + + @Override + public List getParentDevices() { + String uid = ""; + List pdv = null; + if (!AuthUtil.isAdmin()) { + uid = AuthUtil.getUserId(); + } + List ret = deviceInfoData.findByProductNodeType(uid); + if (!ret.isEmpty()) { + pdv = ret.stream().map(r -> ParentDeviceVo.builder().id(r.getId()).deviceName(r.getDeviceName()).build()).collect(Collectors.toList()); + } + return pdv; + } + + @Override + public DeviceInfo getDetail(String deviceId) { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); +// dataOwnerService.checkOwner(deviceInfo); + deviceInfo.setProperty(deviceInfoData.getProperties(deviceId)); + return deviceInfo; + } + + @Override + public DeviceInfo getByPkDn(String pk, String dn) { + return dataOwnerService.checkOwner( + deviceInfoData.findByDeviceName(dn)); + } + + @Override + public boolean deleteDevice(String deviceId) { + + deviceId = getDetail(deviceId).getDeviceId(); + deviceInfoData.deleteById(deviceId); + return true; + } + + @Override + public boolean batchDeleteDevice(List ids) { + deviceInfoData.deleteByIds(ids); + return true; + } + + @Override + public Paging logs(PageRequest request) { + DeviceLogQueryBo data = request.getData(); + return thingModelMessageData.findByTypeAndIdentifier(data.getDeviceId(), data.getType(), data.getIdentifier(), request.getPageNum(), request.getPageSize()); + + } + + @Override + public List getPropertyHistory(String deviceId, String name, long start, long end, int size) { + return devicePropertyData.findDevicePropertyHistory(deviceId, name, start, end, size); + } + + @Override + public boolean unbindDevice(String deviceId) { + + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + dataOwnerService.checkOwner(deviceInfo); + deviceCtrlService.unbindDevice(deviceId); + return true; + } + + @Override + public boolean addTag(DeviceTagAddBo bo) { + String deviceId = bo.getDeviceId(); + DeviceInfo device = deviceInfoData.findByDeviceId(deviceId); + dataOwnerService.checkOwner(device); + deviceInfoData.updateTag(deviceId, bo.to(DeviceInfo.Tag.class)); + return true; + } + + @Override + public boolean simulateSend(ThingModelMessage message) { + DeviceInfo device = deviceInfoData.findByDeviceId(message.getDeviceId()); + dataOwnerService.checkOwner(device); + + message.setMid(UniqueIdUtil.newRequestId()); + message.setOccurred(System.currentTimeMillis()); + message.setTime(System.currentTimeMillis()); + producer.publish(Constants.THING_MODEL_MESSAGE_TOPIC, message); + return true; + } + + @Override + public DeferredResult addConsumer(String deviceId, String clientId) { + //修改为通过websocket下发给app + DeferredResult result = new DeferredResult<>(0L); + String uid = AuthUtil.getUserId(); + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + dataOwnerService.checkOwner(deviceInfo); + +// 按用户+客户端ID订阅 + return deferredDataConsumer.newConsumer(uid + clientId, + Constants.HTTP_CONSUMER_DEVICE_INFO_TOPIC + deviceId); + } + + @Override + public Paging selectGroupPageList(PageRequest pageRequest) { + DeviceGroupBo data = pageRequest.getData(); + return deviceGroupData.findByNameLike(data.getName(), pageRequest.getPageNum(), pageRequest.getPageSize()).to(DeviceGroupVo.class); + } + + @Override + public boolean addGroup(DeviceGroup group) { + group.setUid(AuthUtil.getUserId()); + if (deviceGroupData.findById(group.getId()) != null) { + throw new BizException(ErrCode.GROUP_ALREADY); + } + deviceGroupData.save(group); + return true; + } + + @Override + public boolean updateGroup(DeviceGroupBo bo) { + DeviceGroup group = bo.to(DeviceGroup.class); + DeviceGroup dbGroup = deviceGroupData.findById(group.getId()); + if (dbGroup == null) { + // 如果不存在,则添加分组 + return addGroup(group); +// throw new BizException(ErrCode.GROUP_NOT_FOUND); + } + dataOwnerService.checkOwner(dbGroup); + ReflectUtil.copyNoNulls(group, dbGroup); + + deviceGroupData.save(dbGroup); + //更新设备中的组信息 + deviceInfoData.updateGroup(dbGroup.getId(), new DeviceInfo.Group(dbGroup.getId(), dbGroup.getName())); + return true; + } + + @Override + public boolean deleteGroup(String id) { + DeviceGroup group = deviceGroupData.findById(id); + if (group == null) { + throw new BizException(ErrCode.GROUP_NOT_FOUND); + } + dataOwnerService.checkOwner(group); + //删除分组 + deviceGroupData.deleteById(id); + + //移除设备信息中的分组 + deviceInfoData.removeGroup(group.getId()); + return true; + } + + @Override + public boolean clearGroup(String id) { + DeviceGroup group = deviceGroupData.findById(id); + if (group == null) { + throw new BizException(ErrCode.GROUP_NOT_FOUND); + } + dataOwnerService.checkOwner(group); + + //设备数量清零 + group.setDeviceQty(0); + deviceGroupData.save(group); + + //移除设备信息中的分组 + deviceInfoData.removeGroup(group.getId()); + return true; + } + + @Override + public boolean addDevice2Group(DeviceAddGroupBo data) { + + String group = data.getGroup(); + List devices = data.getDevices(); + DeviceGroup deviceGroup = deviceGroupData.findById(group); + if (deviceGroup == null) { + throw new BizException(ErrCode.GROUP_NOT_FOUND); + } + dataOwnerService.checkOwner(deviceGroup); + + for (String device : devices) { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(device); + if (deviceInfo == null) { + continue; + } + + dataOwnerService.checkOwner(deviceInfo); + //添加设备到组 + deviceInfoData.addToGroup(device, new DeviceInfo.Group(group, deviceGroup.getName())); + } + //统计组下设备数量 + long qty = deviceInfoData.countByGroupId(group); + //更新组信息 + deviceGroup.setDeviceQty((int) qty); + deviceGroupData.save(deviceGroup); + return true; + } + + @Override + public boolean removeDevices(String group, List devices) { + + DeviceGroup deviceGroup = deviceGroupData.findById(group); + if (deviceGroup == null) { + throw new BizException(ErrCode.GROUP_NOT_FOUND); + } + dataOwnerService.checkOwner(deviceGroup); + + for (String device : devices) { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(device); + if (deviceInfo == null) { + continue; + } + + dataOwnerService.checkOwner(deviceInfo); + //删除设备所在组 + deviceInfoData.removeGroup(device, group); + } + //统计组下设备数量 + long qty = deviceInfoData.countByGroupId(group); + //更新组信息 + deviceGroup.setDeviceQty((int) qty); + deviceGroupData.save(deviceGroup); + return true; + } + + @Override + public boolean saveConfig(DeviceConfig data) { + String deviceId = data.getDeviceId(); + String config = data.getConfig(); + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + dataOwnerService.checkOwner(deviceInfo); + + DeviceConfig deviceConfig = deviceConfigData.findByDeviceId(deviceId); + if (deviceConfig == null) { + deviceConfig = DeviceConfig.builder() + .deviceId(deviceId) + .deviceName(deviceInfo.getDeviceName()) + .productKey(deviceInfo.getProductKey()) + .config(config) + .createAt(System.currentTimeMillis()) + .build(); + } else { + deviceConfig.setConfig(config); + } + + deviceConfigData.save(deviceConfig); + return true; + } + + @Override + public DeviceConfigVo getConfig(String deviceId) { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + dataOwnerService.checkOwner(deviceInfo); + return MapstructUtils.convert(deviceConfigData.findByDeviceId(deviceId), DeviceConfigVo.class); + + } + + @Override + public boolean saveDevice(DeviceInfoBo data) { + DeviceInfo di = data.to(DeviceInfo.class); + di.setLocate(new DeviceInfo.Locate(data.getLongitude(), data.getLatitude())); + if (StringUtils.isBlank(data.getSecret())) { + data.setSecret(RandomStringUtils.random(16)); + } + //deviceName不可重复 + DeviceInfo deviceRepetition = deviceInfoData.findByDeviceName(data.getDeviceName()); + if (deviceRepetition != null && !deviceRepetition.getDeviceId().equals(di.getDeviceId())) { + throw new BizException(ErrCode.MODEL_DEVICE_ALREADY); + } + return deviceInfoData.save(di) != null; + } + + + @SneakyThrows + @Override + public String importGroup(MultipartFile file) { + ExcelResult result = ExcelUtil.importExcel(file.getInputStream(), DeviceGroupImportVo.class, new DeviceGroupImportListener(true)); + return result.getAnalysis(); + } + + @Override + public DeviceGroupVo getDeviceGroup(String id) { + DeviceGroup deviceGroup = deviceGroupData.findById(id); + return MapstructUtils.convert(deviceGroup, DeviceGroupVo.class); + } + + @SneakyThrows + @Override + public String importDevice(MultipartFile file) { + ExcelResult result = ExcelUtil.importExcel(file.getInputStream(), DeviceInfoImportVo.class, new DeviceInfoImportListener(true)); + return result.getAnalysis(); + } + + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/FeedBackEvaluationServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/FeedBackEvaluationServiceImpl.java new file mode 100644 index 0000000..b6d99ff --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/FeedBackEvaluationServiceImpl.java @@ -0,0 +1,114 @@ +package cc.iotkit.manager.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.manager.IDIccidRecordData; +import cc.iotkit.data.manager.IFeedBackEvaluationData; +import cc.iotkit.manager.config.BeanUtils; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationPageReqVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationSaveReqVO; +import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationVO; +import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordPageReqVO; +import cc.iotkit.manager.dto.vo.category.vo.DIccidRecordRespVO; +import cc.iotkit.manager.service.FeedBackEvaluationService; +import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO; +import cc.iotkit.model.iccid.DIccidRecordDO; +import cn.hutool.core.util.ObjectUtil; + +import cn.hutool.db.PageResult; +import lombok.extern.slf4j.Slf4j; +import org.hibernate.service.spi.ServiceException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; + +import static io.micrometer.core.instrument.binder.http.HttpRequestTags.exception; + + +/** + * 意见反馈评价 Service 实现类 + * + * @author zhp + */ +@Service +@Slf4j +public class FeedBackEvaluationServiceImpl implements FeedBackEvaluationService { + + @Autowired + private IFeedBackEvaluationData iFeedBackEvaluationData; + + @Override + @Transactional(rollbackFor = {Exception.class, RuntimeException.class}) + public Long createFeedBackEvaluation(FeedBackEvaluationSaveReqVO createReqVO) { + // String id = TimestampIdentifierGenerator.getIdCreateFeedBackEvaluation(); + + // createReqVO.setId(id); + // 插入 + FeedBackEvaluationDO feedBackEvaluation = BeanUtils.toBean(createReqVO, FeedBackEvaluationDO.class); + //查询工单号 + /* if(ObjectUtil.isNotEmpty(feedBackEvaluation.getWorderId())){ + String worderId = feedBackEvaluation.getWorderId(); + TbWorderDO worderDO = worderMapper.selectById(worderId); + + feedBackEvaluation.setCustomerPhone(worderDO.getCustomerPhone()); + feedBackEvaluation.setCustomerName(worderDO.getCustomerName()); + feedBackEvaluation.setDeviceId(worderDO.getProductId()); + }*/ + + + iFeedBackEvaluationData.save(feedBackEvaluation); + // 返回 + return null; + } + + @Override + @Transactional(rollbackFor = {Exception.class, RuntimeException.class, ServiceException.class}) + public void updateFeedBackEvaluation(FeedBackEvaluationSaveReqVO updateReqVO) { + // 校验存在 + validateFeedBackEvaluationExists(updateReqVO.getId()); + // 更新 + FeedBackEvaluationDO updateObj = BeanUtils.toBean(updateReqVO, FeedBackEvaluationDO.class); + iFeedBackEvaluationData.save(updateObj); + } + + @Override + @Transactional(rollbackFor = {Exception.class, RuntimeException.class, ServiceException.class}) + public void deleteFeedBackEvaluation(Long id) { + // 校验存在 + validateFeedBackEvaluationExists(id); + // 删除 + iFeedBackEvaluationData.deleteById(id); + } + + private void validateFeedBackEvaluationExists(Long id) { + if (iFeedBackEvaluationData.findById(id) == null) { + throw new RuntimeException("不存在"); + } + } + + @Override + public FeedBackEvaluationDO getFeedBackEvaluation(Long id) { + return iFeedBackEvaluationData.findById(id); + } + + @Override + public Paging getFeedBackEvaluationPage(PageRequest pageReqVO) { + + + // 参数校验 + if(pageReqVO == null) { + pageReqVO = new PageRequest<>(); + } + PageRequest feedBackEvaluationDO = pageReqVO.to(FeedBackEvaluationDO.class); + if (feedBackEvaluationDO == null) { + throw new IllegalArgumentException("Conversion to TbFeedBackEvaluation resulted in null"); + } + // Paging a= iFeedBackEvaluationData.findAll(feedBackEvaluationDO); + + return iFeedBackEvaluationData.findAll(feedBackEvaluationDO).to(FeedBackEvaluationVO.class); + } + +} \ No newline at end of file diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/HomeServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/HomeServiceImpl.java new file mode 100644 index 0000000..de617ad --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/HomeServiceImpl.java @@ -0,0 +1,99 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service.impl; + +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.data.manager.IHomeData; +import cc.iotkit.data.manager.ISpaceData; +import cc.iotkit.data.manager.ISpaceDeviceData; +import cc.iotkit.manager.dto.bo.space.HomeBo; +import cc.iotkit.manager.service.IHomeService; +import cc.iotkit.model.space.Home; +import cc.iotkit.model.space.Space; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/8/25 10:21 + */ +@Service +public class HomeServiceImpl implements IHomeService { + @Autowired + private IHomeData homeData; + + @Autowired + private ISpaceData spaceData; + + @Autowired + private ISpaceDeviceData spaceDeviceData; + + @Override + public Home save(HomeBo home) { + return homeData.save(home.to(Home.class)); + } + + @Override + public Home findByUserIdAndCurrent(Long userId, boolean current) { + return homeData.findByUserIdAndCurrent(userId,current); + } + + @Override + public List findByUserId(Long userId) { + return homeData.findByUserId(userId); + } + + @Override + public Home findById(Long id) { + return homeData.findById(id); + } + + @Override + public boolean checkHomeNameUnique(HomeBo home) { + return homeData.checkHomeNameUnique(home.to(Home.class)); + } + + @Override + public void deleteById(Long id) { + //先删除空间设备,再删除空间,再删除家庭 + List spaces=spaceData.findByHomeId(id); + for(Space space:spaces){ + spaceDeviceData.deleteAllBySpaceId(space.getId()); + spaceData.deleteById(space.getId()); + } + homeData.deleteById(id); + } + + @Override + public void changCurrentHome(HomeBo home) { + Home oldHome=homeData.findByUserIdAndCurrent(LoginHelper.getUserId(), true); + oldHome.setCurrent(false); + homeData.save(oldHome); + Home newHome=homeData.findById(home.getId()); + newHome.setCurrent(true); + homeData.save(newHome); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/PluginServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/PluginServiceImpl.java new file mode 100644 index 0000000..52e26a6 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/PluginServiceImpl.java @@ -0,0 +1,252 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.manager.IPluginInfoData; +import cc.iotkit.manager.dto.bo.plugin.PluginInfoBo; +import cc.iotkit.manager.dto.vo.plugin.PluginInfoVo; +import cc.iotkit.manager.service.IPluginService; +import cc.iotkit.model.plugin.PluginInfo; +import cn.hutool.core.io.IoUtil; +import com.gitee.starblues.core.PluginState; +import com.gitee.starblues.core.descriptor.PluginDescriptor; +import com.gitee.starblues.integration.AutoIntegrationConfiguration; +import com.gitee.starblues.integration.operator.PluginOperator; +import com.gitee.starblues.integration.operator.upload.UploadParam; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.PostConstruct; +import java.nio.charset.Charset; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +/** + * @author sjg + */ +@Slf4j +@Service +public class PluginServiceImpl implements IPluginService { + + @Autowired + private AutoIntegrationConfiguration autoIntegrationConfiguration; + + @Autowired + private IPluginInfoData pluginInfoData; + + @Autowired + private PluginOperator pluginOperator; + + @Override + public void upload(MultipartFile file, Long id) { + try { + PluginInfo plugin = pluginInfoData.findById(id); + if (file == null || plugin == null) { + throw new BizException(ErrCode.DATA_NOT_EXIST); + } + String pluginId = plugin.getPluginId(); + + if (pluginId != null && !file.getOriginalFilename().contains(pluginId)) { + throw new BizException(ErrCode.PLUGIN_INSTALL_FAILED, "文件名与原插件id不匹配"); + } + + if (StringUtils.isNotBlank(pluginId)) { + //停止卸载旧的插件 + com.gitee.starblues.core.PluginInfo pluginInfo = pluginOperator.getPluginInfo(pluginId); + if (pluginInfo != null) { + if (pluginInfo.getPluginState() == PluginState.STARTED) { + pluginOperator.stop(pluginId); + } + pluginOperator.uninstall(pluginId, true, false); + } + } + + UploadParam uploadParam = UploadParam.byMultipartFile(file) + .setBackOldPlugin(false) + .setStartPlugin(false) + .setUnpackPlugin(false); + com.gitee.starblues.core.PluginInfo pluginInfo = pluginOperator.uploadPlugin(uploadParam); + if (pluginInfo == null) { + throw new BizException(ErrCode.PLUGIN_INSTALL_FAILED); + } + + String configJson = ""; + String script = ""; + try (JarFile jarFile = new JarFile(pluginInfo.getPluginPath())) { + // 获取config文件在jar包中的路径 + String configFile = "classes/config.json"; + JarEntry configEntry = jarFile.getJarEntry(configFile); + + if (configEntry != null) { + //读取配置文件 + configJson = IoUtil.read(jarFile.getInputStream(configEntry), Charset.defaultCharset()); + log.info("configJson:{}", configJson); + } + + //读取script.js脚本 + String scriptFile = "classes/script.js"; + JarEntry scriptEntity = jarFile.getJarEntry(scriptFile); + if (scriptEntity != null) { + //读取脚本文件 + script = IoUtil.read(jarFile.getInputStream(scriptEntity), Charset.defaultCharset()); + log.info("script:{}", script); + } + } + + PluginState pluginState = pluginInfo.getPluginState(); + if (pluginState == PluginState.STARTED) { + plugin.setState(PluginInfo.STATE_RUNNING); + } + plugin.setPluginId(pluginInfo.getPluginId()); + plugin.setFile(file.getOriginalFilename()); + plugin.setConfigSchema(configJson); + plugin.setScript(script); + + PluginDescriptor pluginDescriptor = pluginInfo.getPluginDescriptor(); + plugin.setVersion(pluginDescriptor.getPluginVersion()); + plugin.setDescription(pluginDescriptor.getDescription()); + pluginInfoData.save(plugin); + } catch (BizException e) { + throw e; + } catch (Exception e) { + throw new BizException(ErrCode.PLUGIN_INSTALL_FAILED, e); + } + } + + @Override + public void addPlugin(PluginInfoBo plugin) { + plugin.setState(PluginInfo.STATE_STOPPED); + pluginInfoData.save(MapstructUtils.convert(plugin, PluginInfo.class)); + } + + @Override + public void modifyPlugin(PluginInfoBo plugin) { + pluginInfoData.save(plugin.to(PluginInfo.class)); + } + + @Override + public PluginInfoVo getPlugin(Long id) { + return pluginInfoData.findById(id).to(PluginInfoVo.class); + } + + @Override + public void deletePlugin(Long id) { + PluginInfo byId = pluginInfoData.findById(id); + if (byId == null || !PluginInfo.STATE_STOPPED.equals(byId.getState())) { + throw new BizException(ErrCode.PARAMS_EXCEPTION, "请先停止插件"); + } + String pluginId = byId.getPluginId(); + //停止卸载旧的 + com.gitee.starblues.core.PluginInfo pluginInfo = pluginOperator.getPluginInfo(pluginId); + if (pluginInfo != null) { + if (pluginInfo.getPluginState() == PluginState.STARTED) { + pluginOperator.stop(pluginId); + } + pluginOperator.uninstall(pluginId, true, false); + } + + pluginInfoData.deleteById(id); + } + + @Override + public Paging findPagePluginList(PageRequest query) { + return pluginInfoData.findAll(query.to(PluginInfo.class)).to(PluginInfoVo.class); + } + + @Override + public void changeState(PluginInfoBo plugin) { + String state = plugin.getState(); + if (!PluginInfo.STATE_RUNNING.equals(state) && !PluginInfo.STATE_STOPPED.equals(state)) { + throw new BizException(ErrCode.PARAMS_EXCEPTION, "插件状态错误"); + } + + PluginInfo old = pluginInfoData.findById(plugin.getId()); + if (old == null) { + throw new BizException(ErrCode.DATA_NOT_EXIST); + } + if (StringUtils.isBlank(old.getFile())) { + throw new BizException(ErrCode.DATA_BLANK, "插件包为空"); + } + + String pluginId = old.getPluginId(); + com.gitee.starblues.core.PluginInfo pluginInfo = pluginOperator.getPluginInfo(pluginId); + if (pluginInfo != null) { + if (state.equals(PluginInfo.STATE_RUNNING) && pluginInfo.getPluginState() != PluginState.STARTED) { + //启动插件 + pluginOperator.start(pluginId); + } else if (state.equals(PluginInfo.STATE_STOPPED) && pluginInfo.getPluginState() == PluginState.STARTED) { + //停止插件 + pluginOperator.stop(pluginId); + } + } else { + //已经停止,未获取到插件 + if (PluginInfo.STATE_RUNNING.equals(state)) { + throw new BizException(ErrCode.PLUGIN_INSTALL_FAILED, "插件启动失败"); + } + } + + old.setState(state); + pluginInfoData.save(old); + + } + + @PostConstruct + public void init() { + Executors.newSingleThreadScheduledExecutor().schedule(this::startPlugins, 3, TimeUnit.SECONDS); + } + + @SneakyThrows + private void startPlugins() { + while (!pluginOperator.inited()) { + Thread.sleep(1000L); + } + + for (PluginInfo pluginInfo : pluginInfoData.findAll()) { + if (!PluginInfo.STATE_RUNNING.equals(pluginInfo.getState())) { + continue; + } + log.info("start plugin:{}", pluginInfo.getPluginId()); + try { + com.gitee.starblues.core.PluginInfo plugin = pluginOperator.getPluginInfo(pluginInfo.getPluginId()); + if (plugin != null) { + pluginOperator.start(plugin.getPluginId()); + } + } catch (Exception e) { + log.error("start plugin error", e); + } + } + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/ProductServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/ProductServiceImpl.java new file mode 100644 index 0000000..eb710ab --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/ProductServiceImpl.java @@ -0,0 +1,357 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.oss.entity.UploadResult; +import cc.iotkit.common.oss.factory.OssFactory; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.manager.*; +import cc.iotkit.manager.config.AliyunConfig; +import cc.iotkit.manager.dto.bo.category.CategoryBo; +import cc.iotkit.manager.dto.bo.product.IconBo; +import cc.iotkit.manager.dto.bo.product.IconTypeBo; +import cc.iotkit.manager.dto.bo.product.ProductBo; +import cc.iotkit.manager.dto.bo.productmodel.ProductModelBo; +import cc.iotkit.manager.dto.bo.thingmodel.ThingModelBo; +import cc.iotkit.manager.dto.vo.category.CategoryVo; +import cc.iotkit.manager.dto.vo.product.IconTypeVo; +import cc.iotkit.manager.dto.vo.product.IconVo; +import cc.iotkit.manager.dto.vo.product.ProductVo; +import cc.iotkit.manager.dto.vo.productmodel.ProductModelVo; +import cc.iotkit.manager.dto.vo.thingmodel.ThingModelVo; +import cc.iotkit.manager.service.DataOwnerService; +import cc.iotkit.manager.service.IProductService; +import cc.iotkit.model.product.*; +import cc.iotkit.temporal.IDbStructureData; +import cn.hutool.core.lang.UUID; +import cn.hutool.core.util.ObjectUtil; +import com.github.yitter.idgen.YitIdHelper; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * @Author: jay + * @Date: 2023/5/30 17:00 + * @Version: V1.0 + * @Description: 产品服务实现类 + */ + +@Slf4j +@RequiredArgsConstructor +@Service +public class ProductServiceImpl implements IProductService { + + @Autowired + @Qualifier("productDataCache") + private IProductData productData; + @Autowired + @Qualifier("thingModelDataCache") + private IThingModelData thingModelData; + @Autowired + @Qualifier("categoryDataCache") + private ICategoryData categoryData; + + @Autowired + private DataOwnerService dataOwnerService; + @Autowired + private AliyunConfig aliyunConfig; + @Autowired + @Qualifier("productModelDataCache") + private IProductModelData productModelData; + @Autowired + private IDbStructureData dbStructureData; + + @Autowired + private IDeviceInfoData deviceInfoData; + + @Autowired + private IIconTypeData iconTypeData; + + @Autowired + private IIconData iconData; + + @Override + public ProductVo addEntity(ProductBo data) { + Product product = data.to(Product.class); + if (product.getCreateAt() == null) { + product.setCreateAt(System.currentTimeMillis()); + } + + String secret = UUID.randomUUID().toString(true); + product.setProductSecret(secret); + String productKey = data.getProductKey(); + Product oldProduct = productData.findByProductKey(productKey); + if (oldProduct != null) { + throw new BizException(ErrCode.PRODUCT_KEY_EXIST); + } + + productData.save(product); + return MapstructUtils.convert(product, ProductVo.class); + } + + @Override + public boolean updateEntity(ProductBo productBo) { + Product product = productBo.to(Product.class); + + if (product.getCreateAt() == null) { + product.setCreateAt(System.currentTimeMillis()); + } + productData.save(product); + return true; + } + + @Override + public ProductVo getDetail(String productKey) { + return MapstructUtils.convert(productData.findByProductKey(productKey), ProductVo.class); + } + + @Override + public boolean deleteProduct(String productKey) { + Product product = productData.findByProductKey(productKey); + if (Objects.isNull(product)) { + throw new BizException(ErrCode.PRODUCT_NOT_FOUND); + } + boolean exist = deviceInfoData.existByProductKey(productKey); + if (exist) { + throw new BizException(ErrCode.DEVICE_HAS_ASSOCIATED); + } + productData.deleteById(product.getId()); + return true; + } + + @Override + public ThingModelVo getThingModelByProductKey(String productKey) { + ThingModel thingModel = thingModelData.findByProductKey(productKey); + if(ObjectUtil.isNotNull(thingModel)&&ObjectUtil.isNotNull(thingModel.getModel())&& + thingModel.getModel().getProperties().size()>0){ + for (ThingModel.Property pro:thingModel.getModel().getProperties()){ + if(ObjectUtil.isNotNull(pro.getIconId())){ + pro.setIcon(iconData.findById(pro.getIconId())); + } + } + } + return MapstructUtils.convert(thingModel, ThingModelVo.class); + } + + @Override + public boolean saveThingModel(ThingModelBo data) { + String productKey = data.getProductKey(); + String model = data.getModel(); + ThingModel oldData = thingModelData.findByProductKey(productKey); + ThingModel thingModel = new ThingModel(YitIdHelper.nextId(), productKey, JsonUtils.parseObject(model, ThingModel.Model.class)); + + //验证物模型合法性 + List properties = thingModel.getModel().getProperties(); + for (ThingModel.Property property : properties) { + //属性标识符合法性校验 + String identifier = property.getIdentifier(); + if (StringUtils.isBlank(identifier)) { + throw new BizException("属性标识符不能为空"); + } + if (!identifier.matches("^[a-zA-Z].*")) { + throw new BizException("属性标识符【" + identifier + "】不合法"); + } + } + + if (oldData == null) { + //定义时序数据库物模型数据结构 + dbStructureData.defineThingModel(thingModel); + } else { + thingModel.setId(oldData.getId()); + //更新时序数据库物模型数据结构 + dbStructureData.updateThingModel(thingModel); + } + thingModelData.save(thingModel); + return true; + } + + @Override + public boolean deleteThingModel(Long id) { + ThingModel thingModel = thingModelData.findById(id); + //删除时序数据库物模型数据结构 + dbStructureData.defineThingModel(thingModel); + thingModelData.deleteById(id); + return true; + } + + + @Override + public boolean deleteCategory(String id) { + categoryData.deleteById(id); + return true; + } + + @Override + public boolean editCategory(CategoryBo req) { + Category cate = req.to(Category.class); + cate.setCreateAt(System.currentTimeMillis()); + categoryData.save(cate); + return true; + } + + @Override + @SneakyThrows + public String uploadImg(String productKey, MultipartFile file) { + String originalFilename = file.getOriginalFilename(); + if (originalFilename == null) { + throw new BizException(ErrCode.PARAMS_EXCEPTION); + } + String contentType = file.getContentType(); + if (contentType == null || !contentType.contains("image/")) { + throw new BizException(ErrCode.PARAMS_EXCEPTION, "上传的文件不是图片"); + } + + UploadResult upload = OssFactory.instance().upload(file.getInputStream(), + String.format("/product/%s%s", productKey, originalFilename.substring(originalFilename.lastIndexOf("."))), + contentType); + return upload.getUrl(); + } + + @Override + public Paging selectPageList(PageRequest request) { + Paging result =productData.findAll(request.to(Product.class)).to(ProductVo.class); + for (ProductVo row : result.getRows()) { + if(ObjectUtil.isNotNull(row.getIconId())){ + row.setIcon(iconData.findById(row.getIconId())); + } + } + return result; + } + + @Override + public Paging selectCategoryPageList(PageRequest request) { + return MapstructUtils.convert(categoryData.findAll(request.to(Category.class)), CategoryVo.class); + + } + + @Override + public List selectCategoryList() { + return MapstructUtils.convert(categoryData.findAll(), CategoryVo.class); + + } + + @Override + public List getModels(String productKey) { +// dataOwnerService.checkOwner(productData, productKey); + return MapstructUtils.convert(productModelData.findByProductKey(productKey), ProductModelVo.class); + + } + + @Override + public boolean deleteProductModel(String id) { + productModelData.deleteById(id); + return true; + } + + @Override + public ProductVo findByProductKey(String productKey) { + return productData.findByProductKey(productKey).to(ProductVo.class); + } + + @Override + public boolean saveIconType(IconTypeBo data) { + IconType iconType = data.to(IconType.class); + iconTypeData.save(iconType); + return true; + } + + @Override + public boolean deleteIconType(Long data) { + iconTypeData.deleteById(data); + return true; + } + + @Override + public boolean saveIcon(IconBo data) { + Icon icon = data.to(Icon.class); + iconData.save(icon); + return true; + } + + @Override + public boolean deleteIcon(Long data) { + iconData.deleteById(data); + return true; + } + + @Override + public List selectIconTypeList() { + return MapstructUtils.convert(iconTypeData.findAll(), IconTypeVo.class); + } + + @Override + public Paging selectIconPageList(PageRequest request) { + Map sortMap = new HashMap<>(); + sortMap.put("updateTime","desc"); + request.setSortMap(sortMap); + return iconData.findAll(request.to(Icon.class)).to(IconVo.class); + } + + @Override + public boolean editProductModel(ProductModelBo productModelBo) { + ProductModel productModel = productModelBo.to(ProductModel.class); + String model = productModel.getModel(); + String productKey = productModel.getProductKey(); + Product product = productData.findByProductKey(productKey); + if (product == null) { + throw new BizException(ErrCode.PRODUCT_NOT_FOUND); + } + + ProductModel oldScript = productModelData.findByModel(model); + if (oldScript != null && !oldScript.getProductKey().equals(productKey)) { + throw new BizException(ErrCode.MODEL_ALREADY); + } + + productModel.setModifyAt(System.currentTimeMillis()); + productModelData.save(productModel); + return true; + } + + private Product getProduct(String productKey) { + return productData.findByProductKey(productKey); + } + + + /***********/ + private void checkProductOwner(String productKey) { +// dataOwnerService.checkOwner(productData.findByProductKey(productKey)); + } + +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/RuleEngineServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/RuleEngineServiceImpl.java new file mode 100644 index 0000000..db2fe28 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/RuleEngineServiceImpl.java @@ -0,0 +1,293 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.ReflectUtil; +import cc.iotkit.data.manager.IRuleInfoData; +import cc.iotkit.data.manager.ITaskInfoData; +import cc.iotkit.manager.dto.bo.ruleinfo.RuleInfoBo; +import cc.iotkit.manager.dto.bo.ruleinfo.RuleLogBo; +import cc.iotkit.manager.dto.bo.taskinfo.TaskInfoBo; +import cc.iotkit.manager.dto.bo.taskinfo.TaskLogBo; +import cc.iotkit.manager.dto.vo.ruleinfo.RuleInfoVo; +import cc.iotkit.manager.dto.vo.ruleinfo.RuleLogVo; +import cc.iotkit.manager.dto.vo.taskinfo.TaskInfoVo; +import cc.iotkit.manager.dto.vo.taskinfo.TaskLogVo; +import cc.iotkit.manager.service.DataOwnerService; +import cc.iotkit.manager.service.IRuleEngineService; +import cc.iotkit.model.rule.RuleInfo; +import cc.iotkit.model.rule.RuleLog; +import cc.iotkit.model.rule.TaskInfo; +import cc.iotkit.model.rule.TaskLog; +import cc.iotkit.ruleengine.rule.RuleManager; +import cc.iotkit.ruleengine.task.TaskManager; +import cc.iotkit.temporal.IRuleLogData; +import cc.iotkit.temporal.ITaskLogData; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.quartz.SchedulerException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.UUID; + +/** + * @Author: jay + * @Date: 2023/5/30 18:15 + * @Version: V1.0 + * @Description: 规则引擎服务实现 + */ + +@Slf4j +@RequiredArgsConstructor +@Service +public class RuleEngineServiceImpl implements IRuleEngineService { + @Autowired + private ITaskInfoData taskInfoData; + + @Autowired + private IRuleInfoData ruleInfoData; + + @Autowired + private IRuleLogData ruleLogData; + + @Autowired + private DataOwnerService dataOwnerService; + + @Autowired + private TaskManager taskManager; + + @Autowired + private RuleManager ruleManager; + + @Autowired + private ITaskLogData taskLogData; + + @Override + public Paging selectPageList(PageRequest request) { + RuleInfoBo data = request.getData(); + String type = data.getType(); + Integer page = request.getPageNum(); + Integer size = request.getPageSize(); + if (AuthUtil.isAdmin()) { + return MapstructUtils.convert(ruleInfoData.findByType(type, page, size), RuleInfoVo.class); + } else { + return MapstructUtils.convert(ruleInfoData.findByUidAndType(AuthUtil.getUserId(), type, page, size), RuleInfoVo.class); + } + } + + @Override + public boolean saveRule(RuleInfoBo ruleInfoBo) { + RuleInfo rule = ruleInfoBo.to(RuleInfo.class); + if (StringUtils.isBlank(rule.getId())) { + rule.setId(UUID.randomUUID().toString()); + rule.setState(RuleInfo.STATE_STOPPED); + rule.setCreateAt(System.currentTimeMillis()); + rule.setUid(AuthUtil.getUserId()); + ruleInfoData.save(rule); + ruleManager.add(rule); + } else { + RuleInfo ruleInfo = ruleInfoData.findById(rule.getId()); + if (ruleInfo == null) { + throw new BizException(ErrCode.RULE_NOT_FOUND); + } + if (RuleInfo.STATE_RUNNING.equals(ruleInfo.getState())) { + throw new BizException(ErrCode.RULE_ALREADY_RUNNING); + } + + dataOwnerService.checkOwner(ruleInfo); + + ruleInfo.setListeners(rule.getListeners()); + ruleInfo.setFilters(rule.getFilters()); + ruleInfo.setActions(rule.getActions()); + ruleInfo.setName(rule.getName()); + ruleInfo.setDesc(rule.getDesc()); + + ruleInfoData.save(ruleInfo); + } + return true; + } + + @Override + public boolean pauseRule(String ruleId) { + RuleInfo ruleInfo = ruleInfoData.findById(ruleId); + if (ruleInfo == null) { + throw new BizException(ErrCode.RULE_NOT_FOUND); + } + dataOwnerService.checkOwner(ruleInfo); + ruleInfo.setState(RuleInfo.STATE_STOPPED); + ruleInfoData.save(ruleInfo); + ruleManager.pause(ruleInfo.getId()); + return true; + } + + @Override + public boolean resumeRule(String ruleId) { + RuleInfo ruleInfo = ruleInfoData.findById(ruleId); + if (ruleInfo == null) { + throw new BizException(ErrCode.RULE_NOT_FOUND); + } + dataOwnerService.checkOwner(ruleInfo); + ruleInfo.setState(RuleInfo.STATE_RUNNING); + ruleInfoData.save(ruleInfo); + ruleManager.resume(ruleInfo); + return true; + } + + @Override + public boolean deleteRule(String ruleId) { + RuleInfo ruleInfo = ruleInfoData.findById(ruleId); + if (ruleInfo == null) { + throw new BizException(ErrCode.RULE_NOT_FOUND); + } + dataOwnerService.checkOwner(ruleInfo); + try { + ruleInfoData.deleteById(ruleInfo.getId()); + ruleManager.remove(ruleInfo.getId()); + ruleLogData.deleteByRuleId(ruleId); + } catch (Throwable e) { + log.warn("删除失败", e); + } + return true; + } + + @Override + public Paging selectRuleLogPageList(PageRequest request) { + RuleLog ruleLog = request.getData().to(RuleLog.class); + + return ruleLogData.findByRuleId(ruleLog.getRuleId(), request.getPageNum(), request.getPageSize()).to(RuleLogVo.class); + } + + @Override + public boolean clearRuleLogs(String ruleId) { + ruleLogData.deleteByRuleId(ruleId); + return true; + } + + @Override + public Paging selectTaskPageList(PageRequest request) { + if (AuthUtil.isAdmin()) { + return taskInfoData.findAll(request.to(TaskInfo.class)).to(TaskInfoVo.class); + } + return taskInfoData.findByUid(AuthUtil.getUserId(), request.getPageNum(), request.getPageSize()).to(TaskInfoVo.class); + } + + @Override + public boolean saveTask(TaskInfoBo bo) { + TaskInfo taskInfo = bo.to(TaskInfo.class); + if (StringUtils.isBlank(taskInfo.getId())) { + taskInfo.setId(UUID.randomUUID().toString()); + taskInfo.setUid(AuthUtil.getUserId()); + taskInfo.setCreateAt(System.currentTimeMillis()); + taskInfo.setState(TaskInfo.STATE_STOP); + } else { + TaskInfo oldTask = taskInfoData.findById(taskInfo.getId()); + if (oldTask == null) { + throw new BizException(ErrCode.TASK_NOT_FOUND); + } + taskInfo = ReflectUtil.copyNoNulls(taskInfo, oldTask); + dataOwnerService.checkOwner(taskInfo); + } + + taskInfoData.save(taskInfo); + return true; + } + + @Override + public boolean pauseTask(String taskId) { + TaskInfo taskInfo = taskInfoData.findById(taskId); + if (taskInfo == null) { + throw new BizException(ErrCode.TASK_NOT_FOUND); + } + dataOwnerService.checkOwner(taskInfo); + taskManager.pauseTask(taskId, "stop by " + AuthUtil.getUserId()); + return true; + } + + @Override + public boolean resumeTask(String taskId) { + TaskInfo taskInfo = taskInfoData.findById(taskId); + if (taskInfo == null) { + throw new BizException(ErrCode.TASK_NOT_FOUND); + } + dataOwnerService.checkOwner(taskInfo); + taskManager.resumeTask(taskId, "resume by " + AuthUtil.getUserId()); + return true; + } + + @Override + public boolean renewTask(String taskId) { + TaskInfo taskInfo = taskInfoData.findById(taskId); + if (taskInfo == null) { + throw new BizException(ErrCode.TASK_NOT_FOUND); + } + dataOwnerService.checkOwner(taskInfo); + try { + taskManager.renewTask(taskInfo); + taskManager.updateTaskState(taskId, TaskInfo.STATE_RUNNING, "renew by " + AuthUtil.getUserId()); + } catch (SchedulerException e) { + log.error("renew task error", e); + throw new BizException(ErrCode.RENEW_TASK_ERROR); + } + return true; + } + + @Override + public boolean deleteTask(String taskId) { + TaskInfo taskInfo = taskInfoData.findById(taskId); + if (taskInfo == null) { + throw new BizException(ErrCode.TASK_NOT_FOUND); + } + + dataOwnerService.checkOwner(taskInfo); + taskManager.deleteTask(taskId, "delete by " + AuthUtil.getUserId()); + taskInfoData.deleteById(taskId); + try { + taskLogData.deleteByTaskId(taskId); + } catch (Throwable e) { + log.error("delete task logs failed", e); + } + return true; + } + + @Override + public Paging selectTaskLogPageList(PageRequest request) { + TaskLog taskLog = request.getData().to(TaskLog.class); + Paging byTaskId = taskLogData.findByTaskId(taskLog.getTaskId(), request.getPageNum(), request.getPageSize()); + return byTaskId.to(TaskLogVo.class); + } + + @Override + public boolean clearTaskLogs(String taskId) { + taskLogData.deleteByTaskId(taskId); + return true; + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/ScreenServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/ScreenServiceImpl.java new file mode 100644 index 0000000..aa8a421 --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/ScreenServiceImpl.java @@ -0,0 +1,237 @@ +///* +// * +// * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 +// * * +---------------------------------------------------------------------- +// * * | Author: xw2sy@163.com +// * * +---------------------------------------------------------------------- +// * +// * Copyright [2024] [OPENIITA] +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// * / +// */ +// +//package cc.iotkit.manager.service.impl; +// +//import cc.iotkit.common.api.PageRequest; +//import cc.iotkit.common.api.Paging; +//import cc.iotkit.common.enums.ErrCode; +//import cc.iotkit.common.exception.BizException; +//import cc.iotkit.common.utils.ReflectUtil; +//import cc.iotkit.data.manager.IScreenApiData; +//import cc.iotkit.data.manager.IScreenData; +//import cc.iotkit.manager.dto.bo.screen.DebugChangeBo; +//import cc.iotkit.manager.dto.bo.screen.PublishChangeBo; +//import cc.iotkit.manager.service.DataOwnerService; +//import cc.iotkit.manager.service.IScreenService; +//import cc.iotkit.model.screen.Screen; +//import cc.iotkit.model.screen.ScreenApi; +//import cc.iotkit.screen.ScreenManager; +//import cc.iotkit.screen.config.ScreenConfig; +//import cn.hutool.core.util.ObjectUtil; +//import cn.hutool.core.util.ZipUtil; +//import com.github.yitter.idgen.YitIdHelper; +//import lombok.extern.slf4j.Slf4j; +//import org.apache.commons.io.FileUtils; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.stereotype.Service; +//import org.springframework.util.StringUtils; +//import org.springframework.web.multipart.MultipartFile; +// +//import java.io.File; +//import java.io.IOException; +//import java.nio.file.*; +//import java.util.List; +//import java.util.Objects; +// +///** +// * @Author:tfd +// * @Date:2023/6/25 15:15 +// */ +//@Service +//@Slf4j +//public class ScreenServiceImpl implements IScreenService { +// @Autowired +// private IScreenData screenData; +// @Autowired +// private IScreenApiData screenApiData; +// @Autowired +// private DataOwnerService dataOwnerService; +// @Autowired +// private ScreenConfig screenConfig; +// @Autowired +// private ScreenManager screenManager; +// +// @Override +// public Long uploadResourceFile(MultipartFile file, Long id) { +// String fileName = StringUtils.cleanPath(Objects.requireNonNull(file.getOriginalFilename())); +// try { +// if (ObjectUtil.isNotNull(id)) { +// getAndCheckBigScreen(id); +// } else { +// id = YitIdHelper.nextId(); +// } +// Path filePath = screenConfig.getBigScreenFilePath(String.valueOf(id)); +// Files.createDirectories(filePath); +// Path targetLocation = filePath.resolve(fileName); +// Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING); +// ZipUtil.unzip(filePath.toString()+"/"+fileName); +// return id; +// } catch (IOException ex) { +// throw new BizException(ErrCode.UPLOAD_FILE_ERROR, ex); +// } +// } +// +// @Override +// public List findByScreenId(Long id) { +// return screenApiData.findByScreenId(id); +// } +// +// @Override +// public Screen getDefaultScreen() { +// return screenData.findByIsDefault(true); +// } +// +// @Override +// public List syncResourceApis(Long id) { +// Screen screen = getAndCheckBigScreen(id); +// return screenManager.getScreenApis(screen); +// } +// +// @Override +// public void previewApis(List screenApis) { +// Screen screen = getAndCheckBigScreen(screenApis.get(0).getScreenId()); +// screenManager.previewApis(screen,screenApis); +// } +// +// @Override +// public void saveScreenApis(List screenApis) { +// Screen screen = getAndCheckBigScreen(screenApis.get(0).getScreenId()); +// screenApiData.deleteByScreenId(screen.getId()); +// screenApiData.batchSave(screenApis); +// } +// +// @Override +// public void debugModeChange(DebugChangeBo debugChange) { +// Screen screen = getAndCheckBigScreen(debugChange.getId()); +// screenManager.debugMode(screen,debugChange.getState()); +// } +// +// @Override +// public void addBigScreen(Screen screen) { +// String id = String.valueOf(screen.getId()); +// if (!StringUtils.hasLength(id)) { +// throw new BizException(ErrCode.ID_BLANK); +// } +// Path resPath = screenConfig.getBigScreenFilePath(id); +// if (!resPath.resolve(screen.getResourceFile()).toFile().exists()) { +// throw new BizException(ErrCode.RESOURCE_FILE_NOT_FOUND); +// } +// Screen s = screenData.findById(screen.getId()); +// if (s != null) { +// throw new BizException(ErrCode.BIG_SCREEN_ALREADY); +// } +// try { +// screen.setCreateAt(System.currentTimeMillis()); +// screen.setIsDefault(false); +// screenData.save(screen); +// } catch (Throwable e) { +// throw new BizException(ErrCode.ADD_BIG_SCREEN_ERROR, e); +// } +// } +// +// @Override +// public void saveBigScreen(Screen screen) { +// String id = String.valueOf(screen.getId()); +// if (!StringUtils.hasLength(id)) { +// throw new BizException(ErrCode.ID_BLANK); +// } +// Path jarPath = screenConfig.getBigScreenFilePath(id); +// if (!jarPath.resolve(screen.getResourceFile()).toFile().exists()) { +// throw new BizException(ErrCode.RESOURCE_FILE_NOT_FOUND); +// } +// Screen oldScreen = getAndCheckBigScreen(screen.getId()); +// screen = ReflectUtil.copyNoNulls(screen, oldScreen); +// try { +// screenData.save(screen); +// } catch (Throwable e) { +// throw new BizException(ErrCode.ADD_BIG_SCREEN_ERROR, e); +// } +// } +// +// @Override +// public void publishStatusChange(PublishChangeBo data) { +// Screen screen = getAndCheckBigScreen(data.getId()); +// if (Screen.STATE_RUNNING.equals(data.getState())) {//发布状态 +// List screenApis=screenApiData.findByScreenId(screen.getId()); +// if(screenApis==null||screenApis.size()==0){ +// throw new BizException(ErrCode.API_LIST_BLANK); +// } +// screen.setState(Screen.STATE_RUNNING); +// screenManager.register(screen); +// screenManager.publish(screen); +// } else {//取消发布 +// screen.setState(Screen.STATE_STOPPED); +// screenManager.unPublish(screen); +// } +// screenData.save(screen); +// } +// +// @Override +// public void setDefaultScreen(Long id) { +// Screen screen = getAndCheckBigScreen(id); +// Screen oldScreen=screenData.findByIsDefault(true); +// if(oldScreen!=null){ +// oldScreen.setIsDefault(false); +// } +// screenData.save(oldScreen); +// screen.setIsDefault(true); +// screenData.save(screen); +// } +// +// @Override +// public void deleteScreen(Long id) { +// Screen screen = getAndCheckBigScreen(id); +// try { +// Path path = Paths.get(String.format("%s/%s", screenConfig.getScreenDir(), id)) +// .toAbsolutePath().normalize(); +// File file = path.toFile(); +// try { +// if (file.isDirectory()) { +// FileUtils.deleteDirectory(file); +// } else { +// FileUtils.delete(file); +// } +// } catch (NoSuchFileException e) { +// log.warn("delete big screen resource error", e); +// } +// screenData.deleteById(screen.getId()); +// } catch (Throwable e) { +// throw new BizException(ErrCode.DELETE_BIG_SCREEN_ERROR, e); +// } +// } +// +// @Override +// public Paging getBigScreens(PageRequest request) { +// return screenData.findAll(request); +// } +// +// private Screen getAndCheckBigScreen(Long id) { +// Screen oldBigScreen = screenData.findById(id); +// if (oldBigScreen == null) { +// throw new BizException(ErrCode.BIG_SCREEN_NOT_FOUND); +// } +// dataOwnerService.checkOwner(oldBigScreen); +// return oldBigScreen; +// } +//} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/SpaceDeviceServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/SpaceDeviceServiceImpl.java new file mode 100644 index 0000000..fc14b5b --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/SpaceDeviceServiceImpl.java @@ -0,0 +1,95 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service.impl; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.manager.ISpaceDeviceData; +import cc.iotkit.manager.service.ISpaceDeviceService; +import cc.iotkit.model.space.SpaceDevice; +import cc.iotkit.temporal.IThingModelMessageData; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/8/25 14:46 + */ +@Service +public class SpaceDeviceServiceImpl implements ISpaceDeviceService { + + @Autowired + private ISpaceDeviceData spaceDeviceData; + + @Autowired + private IThingModelMessageData thingModelMessageData; + + @Override + public List findByHomeIdAndCollect(Long homeId, boolean collect) { + return spaceDeviceData.findByHomeIdAndCollect(homeId,collect); + } + + @Override + public SpaceDevice findByDeviceId(String deviceId) { + return spaceDeviceData.findByDeviceId(deviceId); + } + + @Override + public SpaceDevice save(SpaceDevice spaceDevice) { + return spaceDeviceData.save(spaceDevice); + } + + @Override + public List findByHomeId(Long homeId) { + return spaceDeviceData.findByHomeId(homeId); + } + + @Override + public List findBySpaceId(Long spaceId) { + return spaceDeviceData.findBySpaceId(spaceId); + } + + @Override + public void deleteById(Long id) { + spaceDeviceData.deleteById(id); + } + + @Override + public SpaceDevice findById(Long id) { + return spaceDeviceData.findById(id); + } + + @Override + public Paging findByTypeAndDeviceIds(List deviceIds, String type, String identifier, int page, int size) { + if(StringUtils.isEmpty(type)){ + throw new BizException(ErrCode.PARAMS_EXCEPTION); + } + return thingModelMessageData.findByTypeAndDeviceIds(deviceIds,type,identifier,page,size); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/SpaceServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/SpaceServiceImpl.java new file mode 100644 index 0000000..6d021be --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/SpaceServiceImpl.java @@ -0,0 +1,62 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.manager.service.impl; + +import cc.iotkit.data.manager.ISpaceData; +import cc.iotkit.manager.service.ISpaceService; +import cc.iotkit.model.space.Space; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/8/25 10:23 + */ +@Service +public class SpaceServiceImpl implements ISpaceService { + @Autowired + private ISpaceData spaceData; + + @Override + public Space save(Space space) { + return spaceData.save(space); + } + + @Override + public List findByHomeId(Long homeId) { + return spaceData.findByHomeId(homeId); + } + + @Override + public Space findById(Long id) { + return spaceData.findById(id); + } + + @Override + public void deleteById(Long id) { + spaceData.deleteById(id); + } +} diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/WorderServiceImpl.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/WorderServiceImpl.java new file mode 100644 index 0000000..c01b44f --- /dev/null +++ b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/service/impl/WorderServiceImpl.java @@ -0,0 +1,119 @@ +package cc.iotkit.manager.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.data.manager.IWorderData; +import cc.iotkit.manager.config.BeanUtils; +import cc.iotkit.manager.config.TimestampIdentifierGenerator; +import cc.iotkit.manager.dto.vo.worder.WorderPageReqVO; +import cc.iotkit.manager.dto.vo.worder.WorderRespVO; +import cc.iotkit.manager.dto.vo.worder.WorderSaveReqVO; +import cc.iotkit.manager.service.IWorderService; +import cc.iotkit.model.worder.WorderDO; +import cn.hutool.core.util.ObjectUtil; +import lombok.extern.slf4j.Slf4j; +import org.hibernate.service.spi.ServiceException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ObjectUtils; + +import java.util.Date; + +import static cc.iotkit.common.satoken.utils.LoginHelper.getLoginUser; + + +/** + * 意见反馈评价 Service 实现类 + * + * @author zhp + */ +@Service +@Slf4j +public class WorderServiceImpl implements IWorderService { + + @Autowired + private IWorderData iWorderData; + @Override + @Transactional(rollbackFor = {Exception.class, RuntimeException.class, ServiceException.class}) + public Long createWorder(WorderSaveReqVO createReqVO) { + // 插入 + // String id = TimestampIdentifierGenerator.getIdCreateWorder(); + // createReqVO.setId(id); + // 生成工单编号 + /*StringBuilder sb = new StringBuilder("FW"); + String timeStap = DateUtil.format(new Date(), "yyyyMMddHHmmssSSS"); + sb.append(timeStap); + int sequence = counter.get().getAndIncrement(); + // 如果需要,可以在这里添加逻辑来处理同一秒内超过999个工单的情况 保证三位数,不足前面补0 + String sequencePart = String.format("%03d", sequence); + sb.append(sequencePart);*/ + createReqVO.setWorderNum(TimestampIdentifierGenerator.getIdCreateWorderNum()); + // TdProductDO tdProductDO = tdProductMapper.selectById(createReqVO.getProductId()); + WorderDO worder = BeanUtils.toBean(createReqVO, WorderDO.class); + if(worder != null && ObjectUtils.isEmpty(worder.getCustomerId())){ + worder.setCustomerId(getLoginUser().getUserId()); + } + /* if (ObjectUtil.isNotEmpty(tdProductDO)) { + worder.setCustomerAreaId(tdProductDO.getAreaId()); + worder.setCustomerAddress(tdProductDO.getAreaAddress()); + AppScanReturnDataProduct bean = JSONUtil.toBean(tdProductDO.getAppBindingDevice(), AppScanReturnDataProduct.class); + String cityProvinceRegion = bean.getCityProvinceRegion(); + String detailedAddress = bean.getDetailedAddress(); + worder.setCustomerAddress(cityProvinceRegion + detailedAddress); + }*/ + + + worder.setReportTime(new Date()); + iWorderData.save(worder); + //assignSpByTid(worder.getId()); + // 返回 + return null; + } + + @Override + @Transactional(rollbackFor = {Exception.class, RuntimeException.class, ServiceException.class}) + public void updateWorder(WorderSaveReqVO updateReqVO) { + // 校验存在 + validateWorderExists(updateReqVO.getId()); + // 更新 + WorderDO worderDO1 = iWorderData.findById(updateReqVO.getId()); + if(ObjectUtil.isNotEmpty(updateReqVO.getWorderStatus())) { + if (updateReqVO.getWorderStatus().equals(worderDO1.getWorderStatus())) { + throw new RuntimeException("状态不能一样"); + } + } + WorderDO updateObj = BeanUtils.toBean(updateReqVO, WorderDO.class); + iWorderData.save(updateObj); + } + + @Override + @Transactional(rollbackFor = {Exception.class, RuntimeException.class, ServiceException.class}) + public void deleteWorder(Long id) { + // 校验存在 + validateWorderExists(id); + // 删除 + iWorderData.deleteById(id); + } + + private void validateWorderExists(Long id) { + if (iWorderData.findById(id) == null) { + throw new RuntimeException("不存在"); + } + } + + @Override + public WorderDO getWorder(Long id) { + WorderDO worderDO = iWorderData.findById(id); + // whetherEncapsulationCommented(worderDO); + return worderDO; + } + @Override + public Paging getWorderPage(PageRequest pageReqVO) { + // Paging +//PageRequest pageReqVO + Paging ddd= iWorderData.findAll(pageReqVO.to(WorderDO.class)).to(WorderRespVO.class); + return iWorderData.findAll(pageReqVO.to(WorderDO.class)).to(WorderRespVO.class); + } + +} \ No newline at end of file diff --git a/iot-module/iot-message-notify/pom.xml b/iot-module/iot-message-notify/pom.xml new file mode 100644 index 0000000..34af4dc --- /dev/null +++ b/iot-module/iot-message-notify/pom.xml @@ -0,0 +1,61 @@ + + + + iot-module + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-message-notify + + + + + cc.iotkit + iot-common-core + + + + io.vertx + vertx-web-client + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-mail + + + + org.projectlombok + lombok + + + + org.springframework.boot + spring-boot-autoconfigure + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + utf8 + + + + + + diff --git a/iot-module/iot-message-notify/readme.md b/iot-module/iot-message-notify/readme.md new file mode 100644 index 0000000..8af19e7 --- /dev/null +++ b/iot-module/iot-message-notify/readme.md @@ -0,0 +1,11 @@ +### 支持rocketMq作为消息总线 + +版本:0.4.2 + +rocketMq版本:4.9.4 + +####开启方式: + +1、application.yml中打开注释支持rocketMq作为消息总线 + +2、pom.xml中打开注释使用rocketmq消息总线 diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/config/VertxManager.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/config/VertxManager.java new file mode 100644 index 0000000..db49709 --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/config/VertxManager.java @@ -0,0 +1,32 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.message.config; + +import io.vertx.core.Vertx; + +public enum VertxManager { + INSTANCE; + public Vertx getVertx() { + return Vertx.vertx(); + } +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/enums/ChannelEnum.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/enums/ChannelEnum.java new file mode 100644 index 0000000..ac3f726 --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/enums/ChannelEnum.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.enums; + +/** + * author: 石恒 + * date: 2023-05-11 15:01 + * description: + **/ +public enum ChannelEnum { + DingTalk, + QyWechat, + Email, + Phone; +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/event/MessageEvent.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/event/MessageEvent.java new file mode 100644 index 0000000..efa898b --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/event/MessageEvent.java @@ -0,0 +1,50 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.event; + +import cc.iotkit.message.model.Message; +import org.springframework.context.ApplicationEvent; + +/** + * author: 石恒 + * date: 2023-05-11 14:14 + * description: + **/ + +public class MessageEvent extends ApplicationEvent { + private Message message; + + public MessageEvent(Message message) { + super(message); + this.message = message; + } + + public Message getMessage() { + return message; + } + + public void setMessage(Message message) { + this.message = message; + } +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/DingTalkEventListener.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/DingTalkEventListener.java new file mode 100644 index 0000000..c6d7c12 --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/DingTalkEventListener.java @@ -0,0 +1,64 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.listener; + +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.message.config.VertxManager; +import cc.iotkit.message.event.MessageEvent; +import cc.iotkit.message.model.DingTalkConfig; +import cc.iotkit.message.model.DingTalkMessage; +import cc.iotkit.message.model.Message; +import io.vertx.ext.web.client.WebClient; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +/** + * author: 石恒 + * date: 2023-05-08 15:09 + * description: + **/ +@Slf4j +@Component +public class DingTalkEventListener implements MessageEventListener { + WebClient client = WebClient.create(VertxManager.INSTANCE.getVertx()); + + @Override + @EventListener(classes = MessageEvent.class, condition = "#event.message.channel=='DingTalk'") + public void doEvent(MessageEvent event) { + Message message = event.getMessage(); + String channelConfig = message.getChannelConfig(); + DingTalkConfig dingTalkConfig = JsonUtils.parse(channelConfig, DingTalkConfig.class); + + DingTalkMessage qyWechatMessage = DingTalkMessage.builder() + .msgtype("text") + .text(DingTalkMessage.MessageContent.builder().content(message.getFormatContent()).build()) + .build(); + + client.postAbs(dingTalkConfig.getDingTalkWebhook()).sendJson(qyWechatMessage) + .onSuccess(response -> log.info("Received response with status code" + response.statusCode())) + .onFailure(err -> log.error("Something went wrong " + err.getMessage())); + } + +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/EmailEventListener.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/EmailEventListener.java new file mode 100644 index 0000000..173794c --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/EmailEventListener.java @@ -0,0 +1,81 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.listener; + +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.message.event.MessageEvent; +import cc.iotkit.message.model.EmailConfig; +import cc.iotkit.message.model.Message; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.mail.javamail.JavaMailSenderImpl; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.stereotype.Component; + +import javax.mail.internet.MimeMessage; +import java.util.Properties; + +/** + * author: 石恒 + * date: 2023-05-08 15:09 + * description: + **/ +@Slf4j +@Component +public class EmailEventListener implements MessageEventListener { + + @Override + @EventListener(classes = MessageEvent.class, condition = "#event.message.channel=='Email'") + public void doEvent(MessageEvent event) { + Message message = event.getMessage(); + String channelConfig = message.getChannelConfig(); + EmailConfig emailConfig = JsonUtils.parse(channelConfig, EmailConfig.class); + + JavaMailSenderImpl jms = new JavaMailSenderImpl(); + jms.setHost(emailConfig.getHost()); + jms.setUsername(emailConfig.getUserName()); + jms.setPassword(emailConfig.getPassWord()); + jms.setDefaultEncoding("utf-8"); + Properties p = new Properties(); + p.setProperty("mail.smtp.auth", String.valueOf(null == emailConfig.getSmtpAuth() || emailConfig.getSmtpAuth())); + jms.setJavaMailProperties(p); + MimeMessage mimeMessage = jms.createMimeMessage(); + try { + String content = message.getFormatContent(); + MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true); + //收件人 + String[] split = emailConfig.getTo().split(","); + messageHelper.setTo(split); + //标题 + messageHelper.setSubject(content.substring(0, Math.min(20, content.length()))); + //内容 + messageHelper.setText(content, true); + //发件人 + messageHelper.setFrom(emailConfig.getFrom()); + jms.send(mimeMessage); + } catch (Exception e) { + log.error("发送邮件失败.", e); + } + } +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/MessageEventListener.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/MessageEventListener.java new file mode 100644 index 0000000..86d9a47 --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/MessageEventListener.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.listener; + +import cc.iotkit.message.event.MessageEvent; + +/** + * author: 石恒 + * date: 2023-05-08 15:08 + * description: + **/ +public interface MessageEventListener { + + void doEvent(MessageEvent event); + +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/QyWechatEventListener.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/QyWechatEventListener.java new file mode 100644 index 0000000..1d57c20 --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/listener/QyWechatEventListener.java @@ -0,0 +1,63 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.listener; + +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.message.config.VertxManager; +import cc.iotkit.message.event.MessageEvent; +import cc.iotkit.message.model.Message; +import cc.iotkit.message.model.QyWechatConfig; +import cc.iotkit.message.model.QyWechatMessage; +import io.vertx.ext.web.client.WebClient; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +/** + * author: 石恒 + * date: 2023-05-08 15:09 + * description: + **/ +@Slf4j +@Component +public class QyWechatEventListener implements MessageEventListener { + WebClient client = WebClient.create(VertxManager.INSTANCE.getVertx()); + + @Override + @EventListener(classes = MessageEvent.class, condition = "#event.message.channel=='QyWechat'") + public void doEvent(MessageEvent event) { + Message message = event.getMessage(); + String channelConfig = message.getChannelConfig(); + QyWechatConfig qyWechatConfig = JsonUtils.parse(channelConfig, QyWechatConfig.class); + + QyWechatMessage qyWechatMessage = QyWechatMessage.builder() + .msgtype("text") + .text(QyWechatMessage.MessageContent.builder().content(message.getFormatContent()).build()) + .build(); + + client.postAbs(qyWechatConfig.getQyWechatWebhook()).sendJson(qyWechatMessage) + .onSuccess(response -> log.info("Received response with status code" + response.statusCode())) + .onFailure(err -> log.error("Something went wrong " + err.getMessage())); + } +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkConfig.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkConfig.java new file mode 100644 index 0000000..54a6d7b --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkConfig.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.model; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author sjg + */ +@Data +public class DingTalkConfig implements Serializable { + private String dingTalkWebhook; +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java new file mode 100644 index 0000000..2736f7c --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java @@ -0,0 +1,60 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.model; + +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * author: 石恒 + * date: 2023-05-08 15:58 + * description: + **/ +@Data +@Builder +public class DingTalkMessage implements Serializable { + + /** + * 消息文本类型 目前只支持文本 + */ + private String msgtype; + + /** + * 文本消息 + */ + private MessageContent text; + + @Data + @Builder + public static class MessageContent { + + /** + * 文本内容 + */ + private String content; + + } +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailConfig.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailConfig.java new file mode 100644 index 0000000..3658c3e --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailConfig.java @@ -0,0 +1,45 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.model; + +import lombok.Data; + +import java.io.Serializable; + +/** + * author: 石恒 + * date: 2023-05-08 15:58 + * description: + **/ +@Data +public class EmailConfig implements Serializable { + private String host; + private String userName; + private String passWord; + private String from; + private String to; + private String title; + private String content; + private Boolean smtpAuth; +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailMessage.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailMessage.java new file mode 100644 index 0000000..6fddf67 --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailMessage.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.model; + +import lombok.Data; + +import java.io.Serializable; + +/** + * author: 石恒 + * date: 2023-05-08 15:58 + * description: + **/ +@Data +public class EmailMessage implements Serializable { +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java new file mode 100644 index 0000000..8b42dc4 --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java @@ -0,0 +1,58 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Map; + +/** + * author: 石恒 + * date: 2023-05-08 15:15 + * description: + **/ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Message { + private String content; + private Map param; + private Long channelId; + private String channel; + private String channelConfig; + private Long alertConfigId; + + public String getFormatContent() { + String fmt = content; + for (String key : param.keySet()) { + Object val = param.get(key); + fmt = fmt.replace("${" + key + "}", val == null ? "" : val.toString()); + } + return fmt; + } +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatConfig.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatConfig.java new file mode 100644 index 0000000..c06239f --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatConfig.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.model; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author sjg + */ +@Data +public class QyWechatConfig implements Serializable { + private String qyWechatWebhook; +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java new file mode 100644 index 0000000..9a61d19 --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java @@ -0,0 +1,49 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.model; + +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * author: 石恒 + * date: 2023-05-08 15:58 + * description: + **/ +@Data +@Builder +public class QyWechatMessage implements Serializable { + + private String msgtype; + + private MessageContent text; + + @Data + @Builder + public static class MessageContent{ + private String content; + } +} diff --git a/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java new file mode 100644 index 0000000..f56bc52 --- /dev/null +++ b/iot-module/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java @@ -0,0 +1,47 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.message.service; + +import cc.iotkit.message.event.MessageEvent; +import cc.iotkit.message.model.Message; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * author: 石恒 + * date: 2023-05-08 16:02 + * description: + **/ +@Service +public class MessageService { + @Resource + private ApplicationEventPublisher applicationEventPublisher; + + public void sendMessage(Message message) { + applicationEventPublisher.publishEvent(new MessageEvent(message)); + } + +} diff --git a/iot-module/iot-message-notify/消息中心文档.md b/iot-module/iot-message-notify/消息中心文档.md new file mode 100644 index 0000000..09b1f2f --- /dev/null +++ b/iot-module/iot-message-notify/消息中心文档.md @@ -0,0 +1,60 @@ +# 消息中心 + + +## 用户通道配置 +1. 用户通过接口获取系统已经支持的通道列表 +2. 选择某个通道配置对应的参数 + 1. 企业微信:先添加消息机器人 再获取token + 2. 飞书:先添加消息机器人 再获取token + 3. 邮箱:配置host 发件人 收件人 +3. 保存通道配置 +4. 通过接口启用通道 + 1. 修改已经保存的通道的状态为启用 + 2. 订阅已经启用的通道 +## 设备发送消息 +1. 消息中心接收消息 +2. 根据设备deviceId获取设备归属人userId +3. 根据归属人userId获取已经订阅的通道 +## SQL +~~~mysql +CREATE TABLE channel_type +( + id bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID', + title varchar(128) NOT NULL COMMENT '标题', + createTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + updateTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间' +) COMMENT '通道类型'; + +INSERT INTO channel_type(title, createTime, updateTime) +VALUES ('邮箱', current_timestamp(), current_timestamp()); +INSERT INTO channel_type(title, createTime, updateTime) +VALUES ('飞书', current_timestamp(), current_timestamp()); +INSERT INTO channel_type(title, createTime, updateTime) +VALUES ('短信', current_timestamp(), current_timestamp()); +INSERT INTO channel_type(title, createTime, updateTime) +VALUES ('钉钉', current_timestamp(), current_timestamp()); +INSERT INTO channel_type(title, createTime, updateTime) +VALUES ('企业微信', current_timestamp(), current_timestamp()); + +CREATE TABLE channel +( + id bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID', + title varchar(128) COMMENT '标题', + channelType bigint NOT NULL COMMENT '渠道类型', + configParam text NOT NULL COMMENT '配置参数', + userId bigint COMMENT '配置归属', + createTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + updateTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间' +) COMMENT '通道'; + + +CREATE TABLE message +( + id bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID', + mac varchar(128) COMMENT '设备MAC', + deviceId varchar(128) COMMENT '设备ID', + content text NOT NULL COMMENT '消息内容', + createTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + updateTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间' +) COMMENT '消息'; +~~~ diff --git a/iot-module/iot-modbus/pom.xml b/iot-module/iot-modbus/pom.xml new file mode 100644 index 0000000..4f16913 --- /dev/null +++ b/iot-module/iot-modbus/pom.xml @@ -0,0 +1,114 @@ + + + + iot-module + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-modbus + + + + + cc.iotkit + iot-common-core + + + + cc.iotkit + iot-common-web + + + + cc.iotkit + iot-common-log + + + + cc.iotkit + iot-common-excel + + + + cc.iotkit + iot-common-tenant + + + + cc.iotkit + iot-data-model + + + + + cc.iotkit + iot-common-doc + + + + + cc.iotkit + iot-data-serviceImpl-rdb + + + + cc.iotkit + iot-common-satoken + + + + + + io.github.linpeilie + mapstruct-plus-spring-boot-starter + + + + org.projectlombok + lombok + + + cc.iotkit + iot-manager + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + utf8 + + + org.projectlombok + lombok + ${lombok.version} + + + io.github.linpeilie + mapstruct-plus-processor + ${mapstruct-plus.version} + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + + + + + + + diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/controller/ModbusController.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/controller/ModbusController.java new file mode 100644 index 0000000..37bb4f0 --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/controller/ModbusController.java @@ -0,0 +1,140 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.modbus.controller; + + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.modbus.dto.bo.modbus.ModbusInfoBo; +import cc.iotkit.modbus.dto.bo.modbus.ModbusThingModelBo; +import cc.iotkit.modbus.dto.vo.modbus.ModbusInfoVo; +import cc.iotkit.modbus.dto.vo.modbus.ModbusThingModelImportVo; +import cc.iotkit.modbus.dto.vo.modbus.ModbusThingModelVo; +import cc.iotkit.modbus.service.IModbusInfoService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.util.StrUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; + +/** + * @Description: Modbus模版管理 + * @Author: ZOUZDC + * @Date: 2024/4/28 23:10 + */ +@Api(tags = {"modbus"}) +@Slf4j +@RestController +@RequestMapping("/modbus") +public class ModbusController { + + @Autowired + private IModbusInfoService modbusInfoService; + + + @ApiOperation(value = "ModbusInfo模版列表", notes = "设备列表", httpMethod = "POST") + @SaCheckPermission("iot:modbus:list") + @PostMapping("/list") + public Paging getDevices(@Validated @RequestBody PageRequest request) { + return modbusInfoService.selectPageList(request); + } + + + @ApiOperation("新建ModbusInfo") + @SaCheckPermission("iot:modbus:add") + @PostMapping(value = "/add") + @Log(title = "modbusInfo", businessType = BusinessType.INSERT) + public ModbusInfoVo create(@Validated(AddGroup.class) @RequestBody Request request) { + return modbusInfoService.addEntity(request.getData()); + } + + @ApiOperation(value = "编辑ModbusInfo") + @SaCheckPermission("iot:modbus:edit") + @PostMapping("/edit") + @Log(title = "modbusInfo", businessType = BusinessType.UPDATE) + public boolean edit(@Validated(EditGroup.class) @RequestBody Request request) { + return modbusInfoService.updateEntity(request.getData()); + } + + @ApiOperation("查看ModbusInfo详情") + @SaCheckPermission("iot:modbus:query") + @PostMapping(value = "/getDetail") + public ModbusInfoVo getDetail(@RequestBody @Validated Request request) { + return modbusInfoService.getDetail(request.getData()); + } + + @ApiOperation("删除ModbusInfo") + @SaCheckPermission("iot:modbus:remove") + @PostMapping(value = "/deleteModbus") + public boolean deleteProduct(@RequestBody @Validated Request request) { + return modbusInfoService.deleteModbus(request.getData()); + } + + /** + * 导入点位模型 + */ + @ApiOperation(value = "导入点位模型") + @SaCheckPermission("iot:modbus:add") + @PostMapping("/importData") + public String importData(@RequestPart("file") MultipartFile file, @RequestParam("productKey") String productKey) { + if(StrUtil.isBlank(productKey)){ + throw new BizException("缺少productKey"); + } + + return modbusInfoService.importData(file,productKey); + } + @ApiOperation("下载点位模版") + @SaCheckPermission("iot:modbus:query") + @PostMapping("/exportData") + public void exportDeviceTemplate(HttpServletResponse response) { + ExcelUtil.exportExcel(new ArrayList<>(), "点位模版", ModbusThingModelImportVo.class, response); + } + + + @ApiOperation("查看点位物模型") + @SaCheckPermission("iot:modbus:query") + @PostMapping("/getThingModelByProductKey") + public ModbusThingModelVo getThingModelByProductKey(@RequestBody @Validated Request request) { + return modbusInfoService.getThingModelByProductKey(request.getData()); + } + + @ApiOperation("保存点位物模型") + @SaCheckPermission("iot:modbus:edit") + @PostMapping("/thingModel/save") + public boolean saveThingModel(@Validated @RequestBody Request request) { + return modbusInfoService.saveThingModel(request.getData()); + } + + + @ApiOperation("同步点位物模型到产品") + @SaCheckPermission("iot:modbus:edit") + @PostMapping("/syncToProduct") + public boolean syncToProduct(@Validated @RequestBody Request request) { + return modbusInfoService.syncToProduct(request.getData()); + } + + + +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dao/ModbusInfoRepository.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dao/ModbusInfoRepository.java new file mode 100644 index 0000000..2fccf67 --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dao/ModbusInfoRepository.java @@ -0,0 +1,15 @@ +package cc.iotkit.modbus.dao; + +import cc.iotkit.modbus.model.TbModbusInfo; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @Description: ModbusInfoRepository + * @Author: ZOUZDC + * @Date: 2024/4/29 0:11 + */ +public interface ModbusInfoRepository extends JpaRepository { + + + TbModbusInfo findByProductKey(String productKey); +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dao/ModbusThingModelRepository.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dao/ModbusThingModelRepository.java new file mode 100644 index 0000000..b6e938a --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dao/ModbusThingModelRepository.java @@ -0,0 +1,14 @@ +package cc.iotkit.modbus.dao; + +import cc.iotkit.modbus.model.TbModbusThingModel; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @Description: ModbusInfoRepository + * @Author: ZOUZDC + * @Date: 2024/4/29 0:11 + */ +public interface ModbusThingModelRepository extends JpaRepository { + + TbModbusThingModel findByProductKey(String productKey); +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/IModbusInfoData.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/IModbusInfoData.java new file mode 100644 index 0000000..c76d4bb --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/IModbusInfoData.java @@ -0,0 +1,14 @@ +package cc.iotkit.modbus.data; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.modbus.ModbusInfo; + + +/** + * @Description: ModbusInfo数据接口 + * @Author: ZOUZDC + * @Date: 2024/4/29 0:10 + */ +public interface IModbusInfoData extends ICommonData { + ModbusInfo findByProductKey(String productKey); +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/IModbusThingModelData.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/IModbusThingModelData.java new file mode 100644 index 0000000..74be98f --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/IModbusThingModelData.java @@ -0,0 +1,17 @@ +package cc.iotkit.modbus.data; + +import cc.iotkit.data.ICommonData; +import cc.iotkit.model.modbus.ModbusThingModel; + + +/** + * @Description: ModbusThingModel数据接口 + * @Author: ZOUZDC + * @Date: 2024/5/9 23:36 + */ +public interface IModbusThingModelData extends ICommonData { + + ModbusThingModel findByProductKey(String productKey); + + ModbusThingModel save(ModbusThingModel thingModel); +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/Impl/ModbusInfoDataImpl.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/Impl/ModbusInfoDataImpl.java new file mode 100644 index 0000000..1dfe1c3 --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/Impl/ModbusInfoDataImpl.java @@ -0,0 +1,47 @@ +package cc.iotkit.modbus.data.Impl; + +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.modbus.dao.ModbusInfoRepository; +import cc.iotkit.modbus.data.IModbusInfoData; +import cc.iotkit.modbus.model.TbModbusInfo; +import cc.iotkit.model.modbus.ModbusInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @Description: ModbusInfoDataImpl + * @Author: ZOUZDC + * @Date: 2024/4/29 0:11 + */ +@Primary +@Service +public class ModbusInfoDataImpl implements IModbusInfoData, IJPACommData { + + @Autowired + private ModbusInfoRepository modbusInfoRepository; + + + @Override + public JpaRepository getBaseRepository() { + return modbusInfoRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbModbusInfo.class; + } + + @Override + public Class getTClass() { + return ModbusInfo.class; + } + + + @Override + public ModbusInfo findByProductKey(String productKey) { + return MapstructUtils.convert(modbusInfoRepository.findByProductKey(productKey), ModbusInfo.class); + } +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/Impl/ModbusThingModelDataImpl.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/Impl/ModbusThingModelDataImpl.java new file mode 100644 index 0000000..1c08867 --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/data/Impl/ModbusThingModelDataImpl.java @@ -0,0 +1,62 @@ +package cc.iotkit.modbus.data.Impl; + +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.dao.IJPACommData; +import cc.iotkit.modbus.dao.ModbusThingModelRepository; +import cc.iotkit.modbus.data.IModbusThingModelData; +import cc.iotkit.modbus.model.TbModbusThingModel; +import cc.iotkit.model.modbus.ModbusThingModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Service; + +/** + * @Description: ModbusInfoDataImpl + * @Author: ZOUZDC + * @Date: 2024/5/9 23:36 + */ +@Primary +@Service +public class ModbusThingModelDataImpl implements IModbusThingModelData, IJPACommData { + + @Autowired + private ModbusThingModelRepository modbusThingModelRepository; + + + @Override + public JpaRepository getBaseRepository() { + return modbusThingModelRepository; + } + + @Override + public Class getJpaRepositoryClass() { + return TbModbusThingModel.class; + } + + @Override + public Class getTClass() { + return ModbusThingModel.class; + } + + + @Override + public ModbusThingModel findByProductKey(String productKey) { + TbModbusThingModel tbThingModel = modbusThingModelRepository.findByProductKey(productKey); + ModbusThingModel convert = MapstructUtils.convert(tbThingModel, ModbusThingModel.class); + if (tbThingModel != null && convert != null) { + convert.setModel(JsonUtils.parseObject(tbThingModel.getModel(), ModbusThingModel.Model.class)); + } + return convert; + + } + + @Override + public ModbusThingModel save(ModbusThingModel data) { + TbModbusThingModel to = data.to(TbModbusThingModel.class); + to.setModel(JsonUtils.toJsonString(data.getModel())); + modbusThingModelRepository.save(to); + return data; + } +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/bo/modbus/ModbusInfoBo.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/bo/modbus/ModbusInfoBo.java new file mode 100644 index 0000000..591a043 --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/bo/modbus/ModbusInfoBo.java @@ -0,0 +1,34 @@ +package cc.iotkit.modbus.dto.bo.modbus; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.modbus.ModbusInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "ModbusInfoBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = ModbusInfo.class, reverseConvertGenerate = false) +public class ModbusInfoBo extends BaseDto { + + private static final long serialVersionUID = -1L; + + + @ApiModelProperty(value="id") + private Long id; + + @ApiModelProperty(value="产品名称") + private String name; + + @ApiModelProperty(value="产品Key") + private String productKey; + + @ApiModelProperty(value="说明") + private String remark; + + + } diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/bo/modbus/ModbusThingModelBo.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/bo/modbus/ModbusThingModelBo.java new file mode 100644 index 0000000..2e9c1d1 --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/bo/modbus/ModbusThingModelBo.java @@ -0,0 +1,34 @@ +package cc.iotkit.modbus.dto.bo.modbus; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.modbus.ModbusThingModel; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + + +@ApiModel(value = "ModbusThingModelBo") +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = ModbusThingModel.class, reverseConvertGenerate = false) +public class ModbusThingModelBo extends BaseDto { + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "模型内容") + @Size(max = 65535, message = "模型内容长度不正确") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String model; + + @NotBlank(message="产品Key不能为空") + @ApiModelProperty(value = "产品key") + @Size(min = 16, max = 16, message = "产品key长度不正确") + private String productKey; + +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/vo/modbus/ModbusInfoVo.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/vo/modbus/ModbusInfoVo.java new file mode 100644 index 0000000..e3c3d92 --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/vo/modbus/ModbusInfoVo.java @@ -0,0 +1,49 @@ +package cc.iotkit.modbus.dto.vo.modbus; + +import cc.iotkit.model.modbus.ModbusInfo; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + + +@ApiModel(value = "ModbusInfoVo") +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = ModbusInfo.class) +public class ModbusInfoVo implements Serializable { + + private static final long serialVersionUID = -1L; + + + @ApiModelProperty(value="id") + private Long id; + + + @ApiModelProperty(value="产品名称") + @ExcelProperty(value = "产品名称") + private String name; + + + @ApiModelProperty(value="产品Key") + @ExcelProperty(value = "产品Key") + private String productKey; + + + @ApiModelProperty(value="说明") + @ExcelProperty(value = "说明") + private String remark; + + @ApiModelProperty(value="创建时间") + @ExcelProperty(value = "创建时间") + private Long createAt; + + + @ApiModelProperty(value="修改时间") + @ExcelProperty(value = "修改时间") + private Long updateAt; +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/vo/modbus/ModbusThingModelImportVo.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/vo/modbus/ModbusThingModelImportVo.java new file mode 100644 index 0000000..bd020ff --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/vo/modbus/ModbusThingModelImportVo.java @@ -0,0 +1,60 @@ +package cc.iotkit.modbus.dto.vo.modbus; + +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.io.Serializable; + + +@ApiModel(value = "ModbusThingModel.Property") +@Data +public class ModbusThingModelImportVo implements Serializable { + private static final long serialVersionUID = -1L; + + @ExcelProperty(value = "名称") + private String name; + + @ExcelProperty(value = "标识符") + private String identifier; + + @ExcelProperty(value = "描述") + private String description; + + @ExcelProperty(value = "寄存器类型") + private String regType; + //寄存器地址 + @ExcelProperty(value = "寄存器地址") + private Integer regAddr; + //寄存器数量 + @ExcelProperty(value = "寄存器数量") + private Integer regNum; + /** + * 处理公式 + * [ + * { value: 'AB', }, + * { value: 'BA', }, + * { value: 'AB CD', }, + * { value: 'CD AB', }, + * { value: 'DC BA', }, + * { value: 'BA DC', }, + * ] + */ + @ExcelProperty(value = "处理公式") + private String processor; + + + @ExcelProperty(value = "数据类型") + private String dataType; + + @ExcelProperty(value = "读写模式") + private String accessMode = "rw"; + + @ExcelProperty(value = "单位") + private String unit; + //数据顺序 + @ExcelProperty(value = "数据顺序") + private String sort; + + +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/vo/modbus/ModbusThingModelVo.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/vo/modbus/ModbusThingModelVo.java new file mode 100644 index 0000000..d9321c1 --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/dto/vo/modbus/ModbusThingModelVo.java @@ -0,0 +1,29 @@ +package cc.iotkit.modbus.dto.vo.modbus; + +import cc.iotkit.model.modbus.ModbusThingModel; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + + +@ApiModel(value = "ModbusThingModelVo") +@Data +@AutoMapper(target = ModbusThingModel.class) +public class ModbusThingModelVo implements Serializable { + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "主键") + private String id; + + @ApiModelProperty(value = "模型内容") + private ModbusThingModel.Model model; + + @ApiModelProperty(value = "产品key") + private String productKey; + + @ApiModelProperty(value = "更新时间") + private Long updateAt; +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/model/TbModbusInfo.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/model/TbModbusInfo.java new file mode 100644 index 0000000..c0d2d39 --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/model/TbModbusInfo.java @@ -0,0 +1,71 @@ +package cc.iotkit.modbus.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.modbus.ModbusInfo; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * @Description: modbus点表信息 + * @Author: ZOUZDC + * @Date: 2024/4/29 0:11 + */ +@Data +@Entity +@Table(name = "modbus_info") +@ApiModel(value = "modbus点表信息") +@AutoMapper(target = ModbusInfo.class) +@EntityListeners(TenantListener.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +public class TbModbusInfo implements TenantAware { + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "id") + private Long id; + + /** + * 配置所属用户 + */ + @ApiModelProperty(value = "配置所属用户") + private String uid; + + /** + * 产品名称 + */ + @ApiModelProperty(value = "产品名称") + private String name; + + @ApiModelProperty(value = "productKey") + private String productKey; + + /** + * 说明 + */ + @ApiModelProperty(value = "说明") + private String remark; + + @ApiModelProperty(value = "创建时间") + private Long createAt; + + /** + * 更新时间 + */ + @ApiModelProperty(value = "创建时间") + private Long updateAt; + + + @Column(name = "tenant_id") + private Long tenantId; +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/model/TbModbusThingModel.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/model/TbModbusThingModel.java new file mode 100644 index 0000000..da864d3 --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/model/TbModbusThingModel.java @@ -0,0 +1,63 @@ +/* + * +---------------------------------------------------------------------- + * | Copyright (c) 奇特物联 2021-2022 All rights reserved. + * +---------------------------------------------------------------------- + * | Licensed 未经许可不能去掉「奇特物联」相关版权 + * +---------------------------------------------------------------------- + * | Author: xw2sy@163.com + * +---------------------------------------------------------------------- + */ +package cc.iotkit.modbus.model; + +import cc.iotkit.common.tenant.dao.TenantAware; +import cc.iotkit.common.tenant.listener.TenantListener; +import cc.iotkit.model.modbus.ModbusThingModel; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.Size; +import lombok.Data; +import org.hibernate.annotations.Filter; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.ParamDef; + +import javax.persistence.*; + +/** + * @Description: modbus点表物模型 + * @Author: ZOUZDC + * @Date: 2024/4/28 22:52 + */ +@Data +@Entity +@Table(name = "modbus_thing_model") +@ApiModel(value = "modbus物模型") +@AutoMapper(target = ModbusThingModel.class) +@EntityListeners(TenantListener.class) +@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "long")}) +@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") +public class TbModbusThingModel implements TenantAware { + @Id + @GeneratedValue(generator = "SnowflakeIdGenerator") + @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") + @ApiModelProperty(value = "主键") + private Long id; + + @ApiModelProperty(value = "产品key") + private String productKey; + + @ApiModelProperty(value = "模型内容") + @Column(columnDefinition = "text") + @AutoMapping(ignore = true) + @ReverseAutoMapping(ignore = true) + private String model; + + @ApiModelProperty(value = "更新时间") + private Long updateAt; + + @Column(name = "tenant_id") + private Long tenantId; +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/service/IModbusInfoService.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/service/IModbusInfoService.java new file mode 100644 index 0000000..f43b04f --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/service/IModbusInfoService.java @@ -0,0 +1,34 @@ +package cc.iotkit.modbus.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.modbus.dto.bo.modbus.ModbusInfoBo; +import cc.iotkit.modbus.dto.bo.modbus.ModbusThingModelBo; +import cc.iotkit.modbus.dto.vo.modbus.ModbusInfoVo; +import cc.iotkit.modbus.dto.vo.modbus.ModbusThingModelVo; +import org.springframework.web.multipart.MultipartFile; + +/** + * @Description: Modbus模版管理 + * @Author: ZOUZDC + * @Date: 2024/4/29 0:11 + */ +public interface IModbusInfoService { + Paging selectPageList(PageRequest request); + + ModbusInfoVo addEntity(ModbusInfoBo data); + + boolean updateEntity(ModbusInfoBo data); + + ModbusInfoVo getDetail(Long data); + + boolean deleteModbus(Long data); + + ModbusThingModelVo getThingModelByProductKey(String data); + + boolean saveThingModel(ModbusThingModelBo data); + + boolean syncToProduct(ModbusThingModelBo data); + + String importData(MultipartFile file, String productKey); +} diff --git a/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/service/impl/ModbusInfoServiceImpl.java b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/service/impl/ModbusInfoServiceImpl.java new file mode 100644 index 0000000..6242721 --- /dev/null +++ b/iot-module/iot-modbus/src/main/java/cc/iotkit/modbus/service/impl/ModbusInfoServiceImpl.java @@ -0,0 +1,261 @@ +package cc.iotkit.modbus.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.manager.dto.bo.product.ProductBo; +import cc.iotkit.manager.dto.bo.thingmodel.ThingModelBo; +import cc.iotkit.manager.service.IProductService; +import cc.iotkit.modbus.data.IModbusInfoData; +import cc.iotkit.modbus.data.IModbusThingModelData; +import cc.iotkit.modbus.dto.bo.modbus.ModbusInfoBo; +import cc.iotkit.modbus.dto.bo.modbus.ModbusThingModelBo; +import cc.iotkit.modbus.dto.vo.modbus.ModbusInfoVo; +import cc.iotkit.modbus.dto.vo.modbus.ModbusThingModelImportVo; +import cc.iotkit.modbus.dto.vo.modbus.ModbusThingModelVo; +import cc.iotkit.modbus.service.IModbusInfoService; +import cc.iotkit.model.modbus.ModbusInfo; +import cc.iotkit.model.modbus.ModbusThingModel; +import cc.iotkit.model.product.Product; +import cc.iotkit.model.product.ThingModel; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.json.JSONUtil; +import com.alibaba.excel.EasyExcel; +import com.github.yitter.idgen.YitIdHelper; +import lombok.SneakyThrows; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * @Description: Modbus模版管理 + * @Author: ZOUZDC + * @Date: 2024/4/29 0:12 + */ +@Service +public class ModbusInfoServiceImpl implements IModbusInfoService { + + + @Autowired + private IModbusInfoData modbusInfoData; + @Autowired + private IModbusThingModelData modbusThingModelData; + + /** + * 如果需要可以直接复写方法,不依赖iot-manager + */ + @Autowired + private IProductService productService; + + @Autowired + @Qualifier("productDataCache") + private IProductData productData; + @Override + public Paging selectPageList(PageRequest request) { + return modbusInfoData.findAll(request.to(ModbusInfo.class)).to(ModbusInfoVo.class); + } + + @Override + @Transactional + public ModbusInfoVo addEntity(ModbusInfoBo data) { + ModbusInfo modbusInfo = data.to(ModbusInfo.class); + + ModbusInfo condition = new ModbusInfo(); + condition.setName(data.getName()); + //模板名称不可重复 + ModbusInfo old = modbusInfoData.findOneByCondition(condition); + if (old != null) { + throw new BizException(ErrCode.TEMPLATE_NAME_ALREADY); + } + //productKey在产品中不可重复 + Product oldProduct = productData.findByProductKey(data.getProductKey()); + if (oldProduct != null) { + throw new BizException(ErrCode.PRODUCT_KEY_EXIST); + } + //productKey在物模型中不可重复 + old = modbusInfoData.findByProductKey(data.getProductKey()); + if (old != null) { + throw new BizException(ErrCode.PRODUCT_KEY_EXIST); + } + + modbusInfo.setCreateAt(System.currentTimeMillis()); + modbusInfo.setUpdateAt(modbusInfo.getCreateAt()); + modbusInfo.setUid(AuthUtil.getUserId()); + + modbusInfoData.save(modbusInfo); + + + //生成对应的product + ProductBo productBo = new ProductBo(); + productBo.setProductKey(data.getProductKey()); + productBo.setName(data.getName()); + /** + * [{value:0,label:'网关设备',},{value:1,label:'网关子设备',},{value:2,label:'直连设备'},] + */ + productBo.setNodeType(1); + productBo.setTransparent(true); + productBo.setKeepAliveTime(0L); + productBo.setIsOpenLocate(false); + productService.addEntity(productBo); + + return MapstructUtils.convert(modbusInfo, ModbusInfoVo.class); + } + + @Override + public boolean updateEntity(ModbusInfoBo data) { + ModbusInfo modbusInfo = data.to(ModbusInfo.class); + + ModbusInfo condition = new ModbusInfo(); + condition.setName(data.getName()); + //模板名称不可重复 + ModbusInfo old = modbusInfoData.findOneByCondition(condition); + if (old != null && !Objects.equals(data.getId(), old.getId())) { + throw new BizException(ErrCode.TEMPLATE_NAME_ALREADY); + } + + modbusInfo.setUpdateAt(System.currentTimeMillis()); + + modbusInfoData.save(modbusInfo); + return true; + } + + @Override + public ModbusInfoVo getDetail(Long id) { + return MapstructUtils.convert(modbusInfoData.findById(id), ModbusInfoVo.class); + } + + @Override + public boolean deleteModbus(Long id) { + + ModbusInfo info = modbusInfoData.findById(id); + + Product oldProduct = productData.findByProductKey(info.getProductKey()); + if (oldProduct != null) { + //存在关联产品 + throw new BizException(ErrCode.RELATED_PRODUCTS_EXIST); + } + + modbusInfoData.deleteById(id); + return true; + } + + @Override + public ModbusThingModelVo getThingModelByProductKey(String productKey) { + ModbusThingModel thingModel = modbusThingModelData.findByProductKey(productKey); + return MapstructUtils.convert(thingModel, ModbusThingModelVo.class); + } + + @Override + @Transactional + public boolean saveThingModel(ModbusThingModelBo data) { + String productKey = data.getProductKey(); + + ModbusThingModel thingModel = new ModbusThingModel(YitIdHelper.nextId(), productKey, JsonUtils.parseObject(data.getModel(), ModbusThingModel.Model.class),System.currentTimeMillis()); + return saveThingModel(productKey,thingModel); + } + public boolean saveThingModel(String productKey, ModbusThingModel thingModel) { + + ModbusThingModel oldTm = modbusThingModelData.findByProductKey(productKey); + + //验证物模型合法性 + List properties = thingModel.getModel().getProperties(); + for (ModbusThingModel.Property property : properties) { + //属性标识符合法性校验 + String identifier = property.getIdentifier(); + if (StringUtils.isBlank(identifier)) { + throw new BizException("属性标识符不能为空"); + } + if (!identifier.matches("^[a-zA-Z].*")) { + throw new BizException("属性标识符【" + identifier + "】不合法"); + } + } + if(oldTm!=null){ + thingModel.setId(oldTm.getId()); + } + modbusThingModelData.save(thingModel); + return true; + } + + @Override + public boolean syncToProduct(ModbusThingModelBo data) { + String productKey = data.getProductKey(); + + Product product = productData.findByProductKey(productKey); + if (product == null) { + throw new BizException(ErrCode.PRODUCT_NOT_FOUND); + } + + ModbusThingModel modbusThingModel = modbusThingModelData.findByProductKey(productKey); + + + ThingModel.Model model = new ThingModel.Model(); + + //将Property私有属性封装到proData中 + List properties=new ArrayList<>(); + + if(CollectionUtil.isNotEmpty(modbusThingModel.getModel().getProperties())){ + properties = modbusThingModel.getModel().getProperties().stream().map(p -> { + ThingModel.Property property = BeanUtil.copyProperties(p, ThingModel.Property.class); + property.setProData(JSONUtil.toJsonStr(BeanUtil.copyProperties(p, ModbusThingModel.ProData.class))); + return property; + }).collect(Collectors.toList()); + } + model.setProperties(properties); + + //services events 数据封装 + + + + ThingModelBo tbspModel = new ThingModelBo(); + tbspModel.setProductKey(productKey); + tbspModel.setModel(JSONUtil.toJsonStr(model)); + + + productService.saveThingModel(tbspModel); + + + return true; + } + + @SneakyThrows + @Override + public String importData(MultipartFile file, String productKey) { + + List objects = EasyExcel.read(file.getInputStream()).head(ModbusThingModelImportVo.class).sheet().doReadSync(); + if(CollectionUtil.isEmpty(objects)){ + throw new BizException(ErrCode.DATA_NOT_EXIST); + } + List modbusThingModelArrayList = new ArrayList<>(); + for (ModbusThingModelImportVo vo : objects) { + ModbusThingModel.Property convert = MapstructUtils.convert(vo, ModbusThingModel.Property.class); + modbusThingModelArrayList.add(convert); + } + + ModbusThingModel.Model model = new ModbusThingModel.Model(); + model.setProperties(modbusThingModelArrayList); + + ModbusThingModel modbusThingModel = new ModbusThingModel(); + modbusThingModel.setModel(model ); + + + return this.saveThingModel(productKey, modbusThingModel)?"导入成功":"导入失败"; + + + } + + +} diff --git a/iot-module/iot-openapi/pom.xml b/iot-module/iot-openapi/pom.xml new file mode 100644 index 0000000..87d01e8 --- /dev/null +++ b/iot-module/iot-openapi/pom.xml @@ -0,0 +1,66 @@ + + + + iot-module + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-openapi + + + + + cc.iotkit + iot-system + + + + cc.iotkit + iot-manager + + + + + + 11 + 11 + 1.3.4 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + utf8 + + + org.projectlombok + lombok + ${lombok.version} + + + io.github.linpeilie + mapstruct-plus-processor + ${mapstruct-plus.version} + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + + + + + + \ No newline at end of file diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenAuthController.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenAuthController.java new file mode 100644 index 0000000..eb84fc3 --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenAuthController.java @@ -0,0 +1,58 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.controller; + +import cc.iotkit.common.api.Request; +import cc.iotkit.model.InvokeResult; +import cc.iotkit.openapi.dto.bo.TokenVerifyBo; +import cc.iotkit.openapi.service.OpenBaseService; +import cn.dev33.satoken.annotation.SaIgnore; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = {"openapi-基础"}) +@Slf4j +@RestController +@RequestMapping("/openapi") +public class OpenAuthController { + + @Autowired + private OpenBaseService openBaseService; + + @SaIgnore + @ApiOperation(value = "token获取", notes = "token获取", httpMethod = "POST") + @PostMapping("/v1/getToken") + public InvokeResult getToken(@RequestBody @Validated Request request) { + return new InvokeResult(openBaseService.getToken(request.getData())); + } + + +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenDeviceController.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenDeviceController.java new file mode 100644 index 0000000..d97a000 --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenDeviceController.java @@ -0,0 +1,87 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.controller; + +import cc.iotkit.common.api.Request; +import cc.iotkit.model.InvokeResult; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.openapi.dto.bo.device.OpenapiDeviceBo; +import cc.iotkit.openapi.dto.bo.device.OpenapiSetDeviceServicePropertyBo; +import cc.iotkit.openapi.dto.vo.OpenDeviceInfoVo; +import cc.iotkit.openapi.dto.vo.OpenDevicePropertyVo; +import cc.iotkit.openapi.service.OpenBaseService; +import cc.iotkit.openapi.service.OpenDeviceService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@Api(tags = {"openapi-设备"}) +@Slf4j +@RestController +@RequestMapping("/openapi/device") +public class OpenDeviceController { + + @Autowired + private OpenBaseService openBaseService; + + @Autowired + private OpenDeviceService openDeviceService; + + @ApiOperation("查询单个设备详情") + @PostMapping("/v1/detail") + public DeviceInfo getDetail(@RequestBody @Validated Request bo) { + return openDeviceService.getDetail(bo.getData()); + } + + @ApiOperation(value = "单个设备注册") + @PostMapping("/v1/registerDevice") + public OpenDeviceInfoVo createDevice(@RequestBody @Validated Request bo) { + return openDeviceService.addDevice(bo.getData()); + } + + @ApiOperation("单个设备删除") + @PostMapping("/v1/deleteDevice") + public boolean deleteDevice(@Validated @RequestBody Request bo) { + return openDeviceService.deleteDevice(bo.getData()); + } + + @ApiOperation(value = "设置设备的属性", notes = "设置设备的属性", httpMethod = "POST") + @PostMapping("/v1/setDeviceProperty") + public InvokeResult setProperty(@RequestBody @Validated Request request) { + return new InvokeResult(openDeviceService.setProperty(request.getData().getProductKey(), request.getData().getDeviceName(), request.getData().getArgs())); + } + + @ApiOperation("查询指定设备的属性快照") + @PostMapping("/v1/queryDevicePropertyStatus") + public OpenDevicePropertyVo getDevicePropertyStatus(@RequestBody @Validated Request bo) { + return openDeviceService.getDevicePropertyStatus(bo.getData()); + } +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/TokenVerifyBo.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/TokenVerifyBo.java new file mode 100644 index 0000000..2f16c56 --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/TokenVerifyBo.java @@ -0,0 +1,54 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.dto.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@ApiModel(value = "TokenVerifyBo") +@Data +public class TokenVerifyBo { + private static final long serialVersionUID = -1L; + + @NotBlank(message = "appid不能为空") + @ApiModelProperty(value = "appid") + private String appid; + + @NotBlank(message = "timestamp不能为空") + @ApiModelProperty(value = "时间戳") + private String timestamp; + + @NotBlank(message = "identifier不能为空") + @ApiModelProperty(value = "标识符") + private String identifier; + + @NotNull(message = "{tenant.number.not.blank}") + @ApiModelProperty(value = "租户ID") + private Long tenantId; + +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/device/OpenapiDeviceBo.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/device/OpenapiDeviceBo.java new file mode 100644 index 0000000..a11031c --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/device/OpenapiDeviceBo.java @@ -0,0 +1,46 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.dto.bo.device; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; + +@ApiModel(value = "OpenapiDeviceBo") +@Data +public class OpenapiDeviceBo { + private static final long serialVersionUID = -1L; + + @ApiModelProperty(value = "父级ID") + private String parentId; + + @NotBlank(message = "deviceName不能为空") + @ApiModelProperty(value = "产品名称") + private String deviceName; + + @NotBlank(message = "productKey不能为空") + @ApiModelProperty(value = "产品key") + private String productKey; +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/device/OpenapiSetDeviceServicePropertyBo.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/device/OpenapiSetDeviceServicePropertyBo.java new file mode 100644 index 0000000..86066a1 --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/device/OpenapiSetDeviceServicePropertyBo.java @@ -0,0 +1,56 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.dto.bo.device; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; + +import java.util.Map; +/** + * @author: dsy + * @description: + * @date:created in 2023/7/25 14:17 + * @modificed by: + */ +@ApiModel(value = "OpenapiSetDeviceServicePropertyBo") +@Data +public class OpenapiSetDeviceServicePropertyBo { + + /*@ApiModelProperty(value="设备id",required = true) + @NotBlank + private String deviceId;*/ + + @NotBlank(message = "deviceName不能为空") + @ApiModelProperty(value = "产品名称") + private String deviceName; + + @NotBlank(message = "productKey不能为空") + @ApiModelProperty(value = "产品key") + private String productKey; + + @ApiModelProperty(value="参数") + private String args; +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenDeviceInfoVo.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenDeviceInfoVo.java new file mode 100644 index 0000000..9e6b1b0 --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenDeviceInfoVo.java @@ -0,0 +1,66 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.dto.vo; + +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.product.ThingModel; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import lombok.Data; + + +@ApiModel(value = "OpenDeviceInfoVo") +@Data +@AutoMapper(target = DeviceInfo.class) +public class OpenDeviceInfoVo { + private String id; + + private String deviceId; + + /** + * 产品key + */ + private String productKey; + + private String deviceName; + + /** + * 设备型号 + */ + private String model; + + /** + * 设备密钥 + */ + private String secret; + + private String parentId; + + /** + * 所属平台用户ID + */ + private String uid; + + private Long createAt; +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenDevicePropertyVo.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenDevicePropertyVo.java new file mode 100644 index 0000000..43e459d --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenDevicePropertyVo.java @@ -0,0 +1,51 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.dto.vo; + +import cc.iotkit.model.product.ThingModel; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + + +@ApiModel(value = "OpenDevicePropertyVo") +@Data +@AutoMapper(target = ThingModel.class) +public class OpenDevicePropertyVo { + + @ApiModelProperty(value="设备属性") + private List property; + + @ApiModelProperty(value = "主键") + private String id; + + @ApiModelProperty(value = "模型内容") + private ThingModel.Model model; + + @ApiModelProperty(value = "产品key") + private String productKey; +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenPropertyVo.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenPropertyVo.java new file mode 100644 index 0000000..e75ebc3 --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/vo/OpenPropertyVo.java @@ -0,0 +1,60 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.dto.vo; + +import cc.iotkit.model.product.ThingModel; +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Data; + +@ApiModel(value = "OpenPropertyVo") +@Data +public class OpenPropertyVo { + private String identifier; + private ThingModel.DataType dataType; + private String name; + private String accessMode = "rw"; + + // 描述 + private String description; + + // 单位 + private String unit; + + private String time; + + private String value; + + public OpenPropertyVo() { + } + + public OpenPropertyVo(String identifier, ThingModel.DataType dataType, String name, String accessMode, String description, String unit) { + this.identifier = identifier; + this.dataType = dataType; + this.name = name; + this.accessMode = accessMode; + this.description = description; + this.unit = unit; + } +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/OpenBaseService.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/OpenBaseService.java new file mode 100644 index 0000000..8ff7cd0 --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/OpenBaseService.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.service; + +import cc.iotkit.openapi.dto.bo.TokenVerifyBo; + +/** + * @Author: dsy + * @Date: 2023/7/24 11:30 + * @Version: V1.0 + * @Description: openapi基础服务接口 + */ +public interface OpenBaseService { + + String getToken(TokenVerifyBo bo); +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/OpenDeviceService.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/OpenDeviceService.java new file mode 100644 index 0000000..451681e --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/OpenDeviceService.java @@ -0,0 +1,51 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.service; + +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.openapi.dto.bo.device.OpenapiDeviceBo; +import cc.iotkit.openapi.dto.vo.OpenDeviceInfoVo; +import cc.iotkit.openapi.dto.vo.OpenDevicePropertyVo; + + +/** + * @Author: dsy + * @Date: 2023/7/24 11:05 + * @Version: V1.0 + * @Description: openapi设备服务接口 + */ +public interface OpenDeviceService { + DeviceInfo getDetail(OpenapiDeviceBo bo); + + OpenDeviceInfoVo addDevice(OpenapiDeviceBo bo); + + boolean deleteDevice(OpenapiDeviceBo bo); + + /** + * 设备属性设置 + */ + String setProperty(String productKey, String deviceName, String properties); + + OpenDevicePropertyVo getDevicePropertyStatus(OpenapiDeviceBo data); +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/impl/OpenBaseServiceImpl.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/impl/OpenBaseServiceImpl.java new file mode 100644 index 0000000..7fb9af0 --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/impl/OpenBaseServiceImpl.java @@ -0,0 +1,145 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.service.impl; + +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.enums.DeviceType; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.log.event.LogininforEvent; +import cc.iotkit.common.model.LoginUser; +import cc.iotkit.common.model.RoleDTO; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.CodecUtil; +import cc.iotkit.common.utils.DateUtils; +import cc.iotkit.common.utils.MessageUtils; +import cc.iotkit.common.utils.SpringUtils; +import cc.iotkit.common.web.utils.ServletUtils; +import cc.iotkit.data.system.ISysUserData; +import cc.iotkit.model.system.SysUser; +import cc.iotkit.openapi.dto.bo.TokenVerifyBo; +import cc.iotkit.openapi.service.OpenBaseService; +import cc.iotkit.system.service.ISysPermissionService; +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class OpenBaseServiceImpl implements OpenBaseService { + + @Value("${openapi.appid}") + private String appid; + + @Value("${openapi.password}") + private String password; + + @Autowired + private ISysUserData userData; + + @Autowired + private ISysPermissionService permissionService; + + @Override + public String getToken(TokenVerifyBo bo) { + String boAppid = bo.getAppid(); + String boIdentifier = bo.getIdentifier(); + String boTimeStamp = bo.getTimestamp(); + + // 校验租户 + checkTenant(bo.getTenantId()); + if (!CodecUtil.md5Str(boAppid + password + boTimeStamp).equals(boIdentifier)){ + throw new BizException(ErrCode.IDENTIFIER_ERROR); + } + if (!boAppid.equals(appid)){ + throw new BizException(ErrCode.API_LOGIN_ERROR); + } + SysUser sysUser = userData.selectUserByUserName(appid); + if (sysUser == null){ + //用户不存在是否新建? + } + LoginUser loginUser = buildLoginUser(sysUser); + // 生成token + LoginHelper.loginByDevice(loginUser, DeviceType.PC); + + recordLoginInfo(loginUser.getTenantId(), bo.getAppid(), Constants.LOGIN_SUCCESS, MessageUtils.message("openapi.login.success")); + recordLoginInfo(sysUser.getId()); + return StpUtil.getTokenValue(); + } + + private void checkTenant(Long tenantId) { + + } + /** + * 构建登录用户 + */ + private LoginUser buildLoginUser(SysUser user) { + LoginUser loginUser = new LoginUser(); + loginUser.setTenantId(user.getTenantId()); + loginUser.setUserId(user.getId()); + loginUser.setDeptId(user.getDeptId()); + loginUser.setUsername(user.getUserName()); + loginUser.setUserType(user.getUserType()); + loginUser.setMenuPermission(permissionService.getMenuPermission(user.getId())); + loginUser.setRolePermission(permissionService.getRolePermission(user.getId())); + loginUser.setDeptName(ObjectUtil.isNull(user.getDept()) ? "" : user.getDept().getDeptName()); + List roles = BeanUtil.copyToList(user.getRoles(), RoleDTO.class); + loginUser.setRoles(roles); + return loginUser; + } + + /** + * 记录登录信息 + * + * @param tenantId 租户ID + * @param username 用户名 + * @param status 状态 + * @param message 消息内容 + */ + private void recordLoginInfo(Long tenantId, String username, String status, String message) { + LogininforEvent logininforEvent = new LogininforEvent(); + logininforEvent.setTenantId(tenantId); + logininforEvent.setUsername(username); + logininforEvent.setStatus(status); + logininforEvent.setMessage(message); + logininforEvent.setRequest(ServletUtils.getRequest()); + SpringUtils.context().publishEvent(logininforEvent); + } + /** + * 记录登录信息 + * + * @param userId 用户ID + */ + public void recordLoginInfo(Long userId) { + SysUser sysUser = userData.findById(userId); + sysUser.setLoginIp(ServletUtils.getClientIP()); + sysUser.setLoginDate(DateUtils.getNowDate()); + sysUser.setUpdateBy(userId); + userData.save(sysUser); + } +} diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/impl/OpenDeviceServiceImpl.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/impl/OpenDeviceServiceImpl.java new file mode 100644 index 0000000..4970eb9 --- /dev/null +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/service/impl/OpenDeviceServiceImpl.java @@ -0,0 +1,160 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.openapi.service.impl; + +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.DeviceUtil; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.data.manager.IThingModelData; +import cc.iotkit.manager.service.DeviceCtrlService; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.product.Product; +import cc.iotkit.model.product.ThingModel; +import cc.iotkit.openapi.dto.bo.device.OpenapiDeviceBo; +import cc.iotkit.openapi.dto.vo.OpenDeviceInfoVo; +import cc.iotkit.openapi.dto.vo.OpenDevicePropertyVo; +import cc.iotkit.openapi.dto.vo.OpenPropertyVo; +import cc.iotkit.openapi.service.OpenDeviceService; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + + +@Service +public class OpenDeviceServiceImpl implements OpenDeviceService { + + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + + @Autowired + @Qualifier("productDataCache") + private IProductData productData; + + @Autowired + @Qualifier("thingModelDataCache") + private IThingModelData thingModelData; + + @Autowired + private DeviceCtrlService deviceCtrlService; + + @Override + public DeviceInfo getDetail(OpenapiDeviceBo data) { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceName(data.getDeviceName()); + deviceInfo.setProperty(deviceInfoData.getProperties(deviceInfo.getDeviceId())); + return deviceInfo; + } + + @Override + public OpenDeviceInfoVo addDevice(OpenapiDeviceBo bo) { + String productKey = bo.getProductKey(); + String deviceName = bo.getDeviceName(); + String parentId = bo.getParentId(); + + Product product = productData.findByProductKey(productKey); + if (product == null) { + throw new BizException(ErrCode.PRODUCT_NOT_FOUND); + } + //同产品不可重复设备名 + DeviceInfo deviceRepetition = deviceInfoData.findByDeviceName(deviceName); + if (deviceRepetition != null) { + throw new BizException(ErrCode.MODEL_DEVICE_ALREADY); + } + //生成设备密钥 + String chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"; + int maxPos = chars.length(); + StringBuilder secret = new StringBuilder(); + for (var i = 0; i < 16; i++) { + secret.append(chars.charAt((int) Math.floor(Math.random() * maxPos))); + } + + DeviceInfo device = new DeviceInfo(); + device.setId(DeviceUtil.newDeviceId(deviceName)); + device.setUid(product.getUid()); + device.setDeviceId(device.getId()); + device.setProductKey(productKey); + device.setDeviceName(deviceName); + device.setSecret(secret.toString()); + device.setState(new DeviceInfo.State(false, null, null)); +// device.setLocate(new DeviceInfo.Locate(deviceInfo.getLongitude(),deviceInfo.getLatitude())); + device.setCreateAt(System.currentTimeMillis()); + if (StringUtils.isNotBlank(parentId)) { + device.setParentId(parentId); + } + deviceInfoData.save(device); + return MapstructUtils.convert(device, OpenDeviceInfoVo.class); + } + + @Override + public boolean deleteDevice(OpenapiDeviceBo bo) { + DeviceInfo deviceRepetition = deviceInfoData.findByDeviceName(bo.getDeviceName()); + if (deviceRepetition == null){ + throw new BizException(ErrCode.DEVICE_NOT_FOUND); + } + deviceInfoData.deleteById(deviceRepetition.getDeviceId()); + return true; + } + + @Override + public String setProperty(String productKey, String deviceName, String args) { + DeviceInfo deviceRepetition = deviceInfoData.findByDeviceName(deviceName); + if (deviceRepetition == null){ + throw new BizException(ErrCode.DEVICE_NOT_FOUND); + } + return deviceCtrlService.setProperty(deviceRepetition.getDeviceId(), JsonUtils.parseObject(args,Map.class), true); + } + + @Override + public OpenDevicePropertyVo getDevicePropertyStatus(OpenapiDeviceBo bo) { + ThingModel thingModel = thingModelData.findByProductKey(bo.getProductKey()); + OpenDevicePropertyVo propertyVo = MapstructUtils.convert(thingModel, OpenDevicePropertyVo.class); + DeviceInfo deviceInfo = deviceInfoData.findByDeviceName(bo.getDeviceName()); + List openPropertyVos = new ArrayList<>(); + if (propertyVo != null){ + Map properties = deviceInfoData.getProperties(deviceInfo.getDeviceId()); + for (ThingModel.Property property : propertyVo.getModel().getProperties()) { + OpenPropertyVo openPropertyVo = new OpenPropertyVo(property.getIdentifier(), property.getDataType(), property.getName(), property.getAccessMode(), property.getDescription(), property.getUnit()); + Map map = (Map) properties.get(openPropertyVo.getIdentifier()); + if (map != null){ + openPropertyVo.setTime(String.valueOf(map.get("occurred"))); + openPropertyVo.setValue(String.valueOf(map.get("value"))); + } + openPropertyVos.add(openPropertyVo); + } + propertyVo.setProperty(openPropertyVos); + } + return propertyVo; + } + +} diff --git a/iot-module/iot-plugin/iot-plugin-main/pom.xml b/iot-module/iot-plugin/iot-plugin-main/pom.xml new file mode 100644 index 0000000..01cdec8 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/pom.xml @@ -0,0 +1,45 @@ + + + + iot-plugin + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-plugin-main + + + + + cc.iotkit + iot-plugin-core + + + + cc.iotkit + iot-common-redis + + + + cc.iotkit + iot-data-service + + + + cc.iotkit + iot-temporal-service + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + \ No newline at end of file diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/DeviceRouter.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/DeviceRouter.java new file mode 100644 index 0000000..481d0ca --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/DeviceRouter.java @@ -0,0 +1,54 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.plugin.main; + +import cc.iotkit.common.redis.utils.RedisUtils; +import org.springframework.stereotype.Component; + +/** + * 设备路由 + * + * @author sjg + */ +@Component +public class DeviceRouter { + + private static final String DEVICE_ROUTER = "str:device:router:%s"; + + private String getDeviceRouter(String deviceName) { + return String.format(DEVICE_ROUTER, deviceName); + } + + public void putRouter(String deviceName, PluginRouter pluginRouter) { + RedisUtils.setCacheObject(getDeviceRouter(deviceName), pluginRouter); + } + + public void removeRouter(String deviceName) { + RedisUtils.deleteObject(getDeviceRouter(deviceName)); + } + + public PluginRouter getRouter(String deviceName) { + return RedisUtils.getCacheObject(getDeviceRouter(deviceName)); + } + +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/IPluginMain.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/IPluginMain.java new file mode 100644 index 0000000..27be9cd --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/IPluginMain.java @@ -0,0 +1,58 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main; + +import cc.iotkit.common.thing.ThingService; +import cc.iotkit.plugin.core.IPluginConfig; +import cc.iotkit.plugin.core.IPluginScript; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.UUID; + +/** + * 主程序接口 + * + * @author sjg + */ +@RestController +@RequestMapping("/plugin") +public interface IPluginMain extends IPluginScript, IPluginConfig { + + /** + * 主程序id + */ + String MAIN_ID = UUID.randomUUID().toString(); + + /** + * 调用设备服务 + * + * @param service 设备服务 + */ + @PostMapping("/invoke") + void invoke(@RequestBody ThingService service); + +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginHost.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginHost.java new file mode 100644 index 0000000..e1d166e --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginHost.java @@ -0,0 +1,70 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main; + +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.thing.ThingService; +import cc.iotkit.data.manager.IPluginInstanceData; +import cc.iotkit.model.plugin.PluginInstance; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * 插件接口调用入口 + * + * @author sjg + */ +@Slf4j +@Service +public class PluginHost { + + @Autowired + private IPluginInstanceData pluginInstanceData; + + @Autowired + private DeviceRouter deviceRouter; + + @Autowired + private IPluginMain pluginMain; + + public void invoke(ThingService service) { + log.info("start exec device service:{}", service); + //根据设备获取插件路由 + PluginRouter router = deviceRouter.getRouter(service.getDeviceName()); + if (router == null) { + throw new BizException(ErrCode.PLUGIN_ROUTER_NOT_FOUND); + } + + //根据插件路由找到要调用的主程序 + PluginInstance instance = pluginInstanceData.findInstance(router.getMainId(), router.getPluginId()); + if (instance == null) { + throw new BizException(ErrCode.PLUGIN_INSTANCE_NOT_FOUND); + } + + //调用插件主程序接口 + pluginMain.invoke(service); + } +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginInitListener.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginInitListener.java new file mode 100644 index 0000000..3876e54 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginInitListener.java @@ -0,0 +1,118 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main; + +import cc.iotkit.data.manager.IPluginInfoData; +import cc.iotkit.data.manager.IPluginInstanceData; +import cc.iotkit.model.plugin.PluginInstance; +import com.gitee.starblues.core.PluginInfo; +import com.gitee.starblues.integration.listener.PluginInitializerListener; +import com.gitee.starblues.integration.operator.PluginOperator; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * @author starBlues + * @version 1.0 + */ +@Component +@Slf4j +public class PluginInitListener implements PluginInitializerListener { + private boolean isCompleted = false; + + /** + * 插件主程序运行ip + */ + @Value("${plugin.ip:127.0.0.1}") + private String mainIp; + + /** + * 插件主程序web端口 + */ + @Value("${server.port:8087}") + private int port; + + @Autowired + private PluginOperator pluginOperator; + + @Autowired + private IPluginInfoData pluginInfoData; + + @Autowired + private IPluginInstanceData pluginInstanceData; + + @Override + public void before() { + log.info("before plugin init"); + } + + @Override + public void complete() { + log.info("plugin init finished"); + this.isCompleted = true; + } + + @Override + public void failure(Throwable e) { + log.info("plugin init failed", e); + } + + /** + * 插件注册,保活 + */ + @Scheduled(fixedRate = 30, timeUnit = TimeUnit.SECONDS) + private void keepAlive() { + if (!isCompleted) { + return; + } + //获取插件列表 + List plugins = pluginOperator.getPluginInfo(); + for (PluginInfo plugin : plugins) { + cc.iotkit.model.plugin.PluginInfo pluginInfo = pluginInfoData.findByPluginId(plugin.getPluginId()); + if (pluginInfo == null) { + continue; + } + + PluginInstance instance = pluginInstanceData.findInstance(IPluginMain.MAIN_ID, plugin.getPluginId()); + if (instance == null) { + instance = PluginInstance.builder() + .mainId(IPluginMain.MAIN_ID) + .pluginId(pluginInfo.getId()) + .ip(mainIp) + .port(port) + .build(); + } + //更新心跳时间 + instance.setHeartbeatAt(System.currentTimeMillis()); + pluginInstanceData.save(instance); + } + + } +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginMainImpl.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginMainImpl.java new file mode 100644 index 0000000..0220a53 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginMainImpl.java @@ -0,0 +1,240 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main; + +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.thing.DeviceService; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.thing.ThingService; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IPluginInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.plugin.PluginInfo; +import cc.iotkit.model.product.Product; +import cc.iotkit.mq.MqProducer; +import cc.iotkit.plugin.core.thing.IDevice; +import cc.iotkit.plugin.core.thing.IThingService; +import cc.iotkit.plugin.core.thing.actions.ActionResult; +import cc.iotkit.plugin.core.thing.actions.down.DeviceConfig; +import cc.iotkit.plugin.core.thing.actions.down.PropertyGet; +import cc.iotkit.plugin.core.thing.actions.down.PropertySet; +import cc.iotkit.plugin.core.thing.actions.down.ServiceInvoke; +import cc.iotkit.plugin.main.script.PluginScriptServer; +import cc.iotkit.script.IScriptEngine; +import com.gitee.starblues.integration.user.PluginUser; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * 插件主程序接口服务 + * + * @author sjg + */ +@Slf4j +@Service +public class PluginMainImpl implements IPluginMain, DeviceService { + + @Autowired + private IPluginInfoData pluginInfoData; + + @Autowired + @Qualifier("productDataCache") + IProductData productData; + + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + + @Autowired + private DeviceRouter deviceRouter; + + @Autowired + private PluginUser pluginUser; + + @Autowired + private IThingService thingService; + + @Autowired + private MqProducer producer; + + @Autowired + private PluginScriptServer pluginScriptServer; + + @Override + public IScriptEngine getScriptEngine(String pluginId) { + return pluginScriptServer.getScriptEngine(pluginId); + } + + @Override + public void reloadScript(String pluginId) { + } + + @Override + public void invoke(@RequestBody ThingService service) { + log.info("start exec device service:{}", service); + DeviceInfo deviceInfo = deviceInfoData.findByDeviceName(service.getDeviceName()); + Product product = productData.findByProductKey(service.getProductKey()); + String linkPk = service.getProductKey(); + String linkDn = service.getDeviceName(); + + if (product.isTransparent()) { + //如果是透传设备,取父级设备进行链路查找 + DeviceInfo parent = deviceInfoData.findByDeviceId(deviceInfo.getParentId()); + if(parent==null){ + throw new BizException(ErrCode.DEVICE_NOT_FOUND,"未找到父级设备"); + } + linkPk = parent.getProductKey(); + linkDn = parent.getDeviceName(); + } + + PluginRouter router = deviceRouter.getRouter(service.getDeviceName()); + if (router == null) { + throw new BizException(ErrCode.PLUGIN_ROUTER_NOT_FOUND); + } + + //获取插件中的设备服务接口 + List deviceServices = pluginUser.getBeanByInterface(router.getPluginId(), IDevice.class); + if (deviceServices.isEmpty()) { + throw new BizException(ErrCode.PLUGIN_SERVICE_NOT_FOUND); + } + + IDevice deviceService = deviceServices.get(0); + String type = service.getType(); + String identifier = service.getIdentifier(); + ActionResult result = null; + Map params = null; + switch (type){ + case ThingService.TYPE_SERVICE: + if (!(service.getParams() instanceof Map)) { + throw new BizException(ErrCode.PARAMS_EXCEPTION); + } + params = (Map) service.getParams(); + //服务调用 + ServiceInvoke action = ServiceInvoke.builder() + .id(service.getMid()) + .productKey(linkPk) + .deviceName(linkDn) + .name(service.getIdentifier()) + .params(params) + .build(); + //调用插件设备服务接口 + result = deviceService.serviceInvoke(action); + publish(service, deviceInfo.getDeviceId(), result.getCode()); + break; + case ThingService.TYPE_PROPERTY: + if ("set".equals(identifier)) { + if (!(service.getParams() instanceof Map)) { + throw new BizException(ErrCode.PARAMS_EXCEPTION); + } + params = (Map) service.getParams(); + //属性设置 + PropertySet actionSet = PropertySet.builder() + .id(service.getMid()) + .productKey(linkPk) + .deviceName(linkDn) + .params(params) + .build(); + //调用插件设备服务接口 + result = deviceService.propertySet(actionSet); + publish(service, deviceInfo.getDeviceId(), result.getCode()); + } else if ("get".equals(identifier)) { + //属性获取 + PropertyGet actionGet = PropertyGet.builder() + .id(service.getMid()) + .productKey(linkPk) + .deviceName(linkDn) + .keys((List) service.getParams()) + .build(); + //调用插件设备服务接口 + result = deviceService.propertyGet(actionGet); + publish(service, deviceInfo.getDeviceId(), result.getCode()); + } + break; + case ThingService.TYPE_OTA: + + break; + case ThingService.TYPE_CONFIG: + // 下发配置: + DeviceConfig actionConfigSet = DeviceConfig.builder() + .id(service.getMid()) + .productKey(linkPk) + .deviceName(linkDn) + .config((Map) service.getParams()) + .build(); + //调用插件设备服务接口 + result = deviceService.config(actionConfigSet); + publish(service, deviceInfo.getDeviceId(), result.getCode()); + break; + default: + break; + + } + + + if (result == null || result.getCode() != 0) { + throw new BizException(ErrCode.DEVICE_ACTION_FAILED, result == null ? "" : result.getReason()); + } + } + + private void publish(ThingService service, String deviceId, int code) { + //产生下发消息作为下行日志保存 + ThingModelMessage message = ThingModelMessage.builder() + .id(UUID.randomUUID().toString()) + .deviceId(deviceId) + .mid(service.getMid()) + .productKey(service.getProductKey()) + .deviceName(service.getDeviceName()) + .identifier(service.getIdentifier()) + .type(service.getType()) + .data(service.getParams()) + .code(code) + .occurred(System.currentTimeMillis()) + .time(System.currentTimeMillis()) + .build(); + + producer.publish(Constants.THING_MODEL_MESSAGE_TOPIC, message); + } + + @Override + public Map getConfig(String pluginId) { + //获取系统插件配置项 + PluginInfo plugin = pluginInfoData.findByPluginId(pluginId); + if (plugin == null) { + return new HashMap<>(0); + } + return JsonUtils.parseObject(plugin.getConfig(), Map.class); + } +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginRouter.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginRouter.java new file mode 100644 index 0000000..4a26a14 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/PluginRouter.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 插件路由 + * + * @author sjg + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PluginRouter { + + private String mainId; + + private String pluginId; + +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/ThingServiceImpl.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/ThingServiceImpl.java new file mode 100644 index 0000000..bcef38a --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/ThingServiceImpl.java @@ -0,0 +1,375 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main; + +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.DeviceUtil; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.utils.UniqueIdUtil; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IProductData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.product.Product; +import cc.iotkit.mq.MqProducer; +import cc.iotkit.plugin.core.thing.IThingService; +import cc.iotkit.plugin.core.thing.actions.*; +import cc.iotkit.plugin.core.thing.actions.up.*; +import cc.iotkit.plugin.core.thing.model.ThingDevice; +import cc.iotkit.plugin.core.thing.model.ThingProduct; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +import java.util.*; + +/** + * @author sjg + */ +@Slf4j +@Service +public class ThingServiceImpl implements IThingService { + + @Autowired + @Qualifier("productDataCache") + private IProductData productData; + + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + + @Autowired + private MqProducer producer; + + @Autowired + private DeviceRouter deviceRouter; + + @Override + public ActionResult post(String pluginId, IDeviceAction action) { + try { + log.info("receive plugin:{}, action:{}", pluginId, action); + String deviceName = action.getDeviceName(); + + if(!"NONE".equals(pluginId)){ + //添加设备路由 + deviceRouter.putRouter(deviceName, new PluginRouter(IPluginMain.MAIN_ID, pluginId)); + } + long lastTime = System.currentTimeMillis(); + DeviceInfo device = getDeviceInfo(deviceName); + if (Objects.isNull(device)) { + log.warn("device:{} is not found.", deviceName); + }else { + deviceUpdateLastTime(device, lastTime); + } + + ActionType type = action.getType(); + switch (type) { + case REGISTER: + //设备注册 + String deviceId = registerDevice(device, (DeviceRegister) action, null); + deviceUpdateLastTime(deviceId, lastTime); + + break; + case PING: + // 设备心跳 + break; + case SUB_REGISTER: + //子设备注册 + subRegisterDevice(pluginId, device, (SubDeviceRegister) action); + break; + case STATE_CHANGE: + deviceStateChange(device, (DeviceStateChange) action); + //父设备ID不为空说明是子设备 + if (Objects.isNull(device.getParentId())) { + //否则为父设备,同步透传子设备状态 + List subDeviceIds = deviceInfoData.findSubDeviceIds(device.getDeviceId()); + for (String subDeviceId : subDeviceIds) { + DeviceInfo subDevice = deviceInfoData.findByDeviceId(subDeviceId); + Product product = productData.findByProductKey(subDevice.getProductKey()); + Boolean transparent = product.getTransparent(); + //透传设备父设备上线,子设备也上线。非透传设备父设备离线,子设备才离线 + if (transparent != null && transparent || ((DeviceStateChange) action).getState() != DeviceState.ONLINE) { + deviceStateChange(subDevice, (DeviceStateChange)action); + } + } + } + break; + case EVENT_REPORT: + EventReport eventReport = (EventReport) action; + publishMsg( + device, action, + ThingModelMessage.builder() + .type(ThingModelMessage.TYPE_EVENT) + .identifier(eventReport.getName()) + .data(eventReport.getParams()) + .time(eventReport.getTime()) + .build() + ); + break; + case PROPERTY_REPORT: + PropertyReport propertyReport = (PropertyReport) action; + publishMsg( + device, action, + ThingModelMessage.builder() + .type(ThingModelMessage.TYPE_PROPERTY) + .identifier(ThingModelMessage.ID_PROPERTY_REPORT) + .data(propertyReport.getParams()) + .time(propertyReport.getTime()) + .occurred(propertyReport.getTime()) + .build() + ); + break; + case SERVICE_REPLY: + ServiceReply serviceReply = (ServiceReply) action; + publishMsg( + device, action, + ThingModelMessage.builder() + .type(ThingModelMessage.TYPE_SERVICE) + .identifier(serviceReply.getName() + "_reply") + .mid(serviceReply.getReplyId()) + .code(serviceReply.getCode()) + .data(serviceReply.getParams()) + .time(serviceReply.getTime()) + .build() + ); + break; + + case TOPOLOGY: + deviceTopologyUpdate(device, (DeviceTopology) action); + break; + default: + return ActionResult.builder().code(ErrCode.PARAMS_EXCEPTION.getKey()).build(); + } + + return new ActionResult(); + } catch (Throwable e) { + log.error("action process error", e); + return ActionResult.builder().code(1).reason(e.getMessage()).build(); + } + } + + private void deviceUpdateLastTime(DeviceInfo device, long lastTime) { + deviceUpdateLastTime(device.getDeviceId(),lastTime); + } + + private void deviceUpdateLastTime(String deviceId, long lastTime) { + deviceInfoData.setLastTime(deviceId,lastTime); + } + + @Override + public ThingProduct getProduct(String pk) { + try { + Product product = productData.findByProductKey(pk); + if (product == null) { + return null; + } + return ThingProduct.builder() + .category(product.getCategory()) + .productKey(product.getProductKey()) + .name(product.getName()) + .nodeType(product.getNodeType()) + .productSecret(product.getProductSecret()) + .build(); + } catch (Throwable e) { + log.error("get product error", e); + return null; + } + } + + public DeviceInfo getDeviceInfo(String dn) { + try { + return deviceInfoData.findByDeviceName(dn); + } catch (Throwable e) { + log.error("get device error", e); + return null; + } + } + + @Override + public ThingDevice getDevice(String dn) { + DeviceInfo deviceInfo = getDeviceInfo(dn); + if (deviceInfo == null) { + return null; + } + return ThingDevice.builder() + .deviceId(deviceInfo.getDeviceId()) + .deviceName(deviceInfo.getDeviceName()) + .model(deviceInfo.getModel()) + .productKey(deviceInfo.getProductKey()) + .secret(deviceInfo.getSecret()) + .build(); + } + + @Override + public Map getProperty(String deviceName) { + DeviceInfo device = getDeviceInfo(deviceName); + if (device == null) { + return new HashMap<>(0); + } + return device.getProperty(); + } + + + private void deviceStateChange(DeviceInfo device, DeviceStateChange action) { + DeviceState state = action.getState(); + if ( (device.getState().isOnline() && state == DeviceState.ONLINE) || + (!device.getState().isOnline() && state == DeviceState.OFFLINE) ) { + return; + } + + if (state == DeviceState.ONLINE) { + device.getState().setOnline(true); + device.getState().setOnlineTime(System.currentTimeMillis()); + } else { + device.getState().setOnline(false); + device.getState().setOfflineTime(System.currentTimeMillis()); + } + deviceInfoData.save(device); + + publishMsg( + device, action, + ThingModelMessage.builder() + .type(ThingModelMessage.TYPE_STATE) + .identifier(action.getState().getState()) + .time(System.currentTimeMillis()) + .build() + ); + } + + + private String registerDevice(DeviceInfo device, DeviceRegister register, String parentId) { + String productKey = register.getProductKey(); + //指定了pk需验证 + if (StringUtils.isNotBlank(productKey)) { + ThingProduct product = getProduct(productKey); + if (product == null) { + throw new BizException(ErrCode.PRODUCT_NOT_FOUND); + } + } + + if (device != null) { + log.info("device already registered"); + if (parentId != null) { + device.setParentId(parentId); + deviceInfoData.save(device); + } + return device.getDeviceId(); + } else { + //不存在,注册新设备 + DeviceInfo deviceInfo = new DeviceInfo(); + deviceInfo.setId(DeviceUtil.newDeviceId(register.getDeviceName())); + deviceInfo.setDeviceId(deviceInfo.getId()); + deviceInfo.setProductKey(productKey); + deviceInfo.setDeviceName(register.getDeviceName()); + deviceInfo.setModel(register.getModel()); + deviceInfo.setParentId(parentId); + deviceInfo.setSecret(RandomStringUtils.randomAlphabetic(16)); + //默认离线 + deviceInfo.setState(new DeviceInfo.State(false, null, null)); + deviceInfo.setCreateAt(System.currentTimeMillis()); + deviceInfoData.save(deviceInfo); + + log.info("device registered:{}", JsonUtils.toJsonString(device)); + publishMsg( + deviceInfo, + register, + ThingModelMessage.builder() + .type(ThingModelMessage.TYPE_LIFETIME) + .identifier("register") + .time(System.currentTimeMillis()) + .build() + ); + return deviceInfo.getDeviceId(); + } + } + + private void subRegisterDevice(String pluginId, DeviceInfo parent, SubDeviceRegister register) { + //先注册父设备 + String parentId = registerDevice(parent, + DeviceRegister.builder() + .productKey(register.getProductKey()) + .deviceName(register.getDeviceName()) + .model(register.getModel()) + .version(register.getVersion()) + .build(), null); + + for (DeviceRegister sub : register.getSubs()) { + String productKey = sub.getProductKey(); + String deviceName = sub.getDeviceName(); + DeviceInfo subDevice = getDeviceInfo(sub.getDeviceName()); + //添加设备路由 + deviceRouter.putRouter(deviceName, new PluginRouter(IPluginMain.MAIN_ID, pluginId)); + //注册子设备 + registerDevice(subDevice, + DeviceRegister.builder() + .productKey(productKey) + .deviceName(deviceName) + .model(sub.getModel()) + .version(sub.getVersion()) + .build() + , parentId + ); + } + } + + private void deviceTopologyUpdate(DeviceInfo device, DeviceTopology topology) { + //设备拓扑关系更新 + for (String deviceName : topology.getSubDevices()) { + DeviceInfo subDevice = getDeviceInfo(deviceName); + subDevice.setParentId(device.getDeviceId()); + deviceInfoData.save(subDevice); + } + } + + private void publishMsg(DeviceInfo device, IDeviceAction action, ThingModelMessage message) { + try { + message.setId(UUID.randomUUID().toString()); + message.setMid(UniqueIdUtil.newRequestId()); + message.setDeviceId(device.getDeviceId()); + message.setProductKey(device.getProductKey()); + message.setDeviceName(device.getDeviceName()); + message.setUid(device.getUid()); + if (message.getOccurred() == null) { + message.setOccurred(action.getTime()); + } + if (message.getTime() == null) { + message.setTime(System.currentTimeMillis()); + } + if (message.getData() == null) { + message.setData(new HashMap<>(0)); + } + + log.info("publish thingModel msg:{}", message); + producer.publish(Constants.THING_MODEL_MESSAGE_TOPIC, message); + } catch (Throwable e) { + log.error("send thing model message error", e); + } + } + +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/Chan.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/Chan.java new file mode 100644 index 0000000..7a25b5d --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/Chan.java @@ -0,0 +1,65 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main.script; + +import lombok.extern.slf4j.Slf4j; + +import java.util.concurrent.locks.LockSupport; + +@Slf4j +public class Chan { + + private static final long THREAD_WAIT_TIME = 1000_000L * 10_000; + + private volatile T data; + + private volatile Thread t; + + private Chan() { + + } + + public static Chan getInstance() { + return ChanSingleton.INSTANCE; + } + + public T get(Object blocker) { + this.t = Thread.currentThread(); + LockSupport.parkNanos(blocker, THREAD_WAIT_TIME); + this.t = null; + return data; + } + + public void put(T data) { + this.data = data; + if (t == null) { + return; + } + LockSupport.unpark(t); + } + + private static class ChanSingleton { + private static final Chan INSTANCE = new Chan<>(); + } +} \ No newline at end of file diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataDecoder.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataDecoder.java new file mode 100644 index 0000000..efc1bd5 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataDecoder.java @@ -0,0 +1,69 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main.script; + +import io.vertx.core.buffer.Buffer; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + +/** + * 数据解码 + * + * @author sjg + */ +@Slf4j +public class DataDecoder { + + public static DataPackage decode(Buffer buffer) { + DataPackage data = new DataPackage(); + ReadField rf = new ReadField(0, buffer); + + data.setMid(rf.read()); + data.setPluginId(rf.read()); + data.setMethod(rf.read()); + data.setArgs(rf.read()); + data.setResult(rf.read()); + return data; + } + + + @Data + @AllArgsConstructor + private static class ReadField { + + private int idx = 0; + + private Buffer buffer; + + private String read() { + int len = buffer.getInt(idx); + idx += 4; + String s = new String(buffer.getBytes(idx, idx + len)); + idx += len; + return s; + } + + } +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataEncoder.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataEncoder.java new file mode 100644 index 0000000..8a8b897 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataEncoder.java @@ -0,0 +1,65 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main.script; + +import io.vertx.core.buffer.Buffer; +import lombok.extern.slf4j.Slf4j; + +/** + * 数据编码 + * + * @author sjg + */ +@Slf4j +public class DataEncoder { + + public static Buffer encode(DataPackage data) { + + Buffer body = Buffer.buffer(); + + append(data.getMid(), body); + + append(data.getPluginId(), body); + + append(data.getMethod(), body); + + append(data.getArgs(), body); + + append(data.getResult(), body); + + Buffer buffer = Buffer.buffer(); + + byte[] bytes = body.getBytes(); + buffer.appendInt(bytes.length); + buffer.appendBytes(bytes); + + return buffer; + } + + private static void append(String s, Buffer buffer) { + byte[] bytes = s == null ? new byte[]{} : s.getBytes(); + buffer.appendInt(bytes.length); + buffer.appendBytes(bytes); + } +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataPackage.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataPackage.java new file mode 100644 index 0000000..f959694 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataPackage.java @@ -0,0 +1,68 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main.script; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + + +/** + * 数据包 + * + * @author sjg + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class DataPackage { + + /** + * 消息id + */ + private String mid; + + /** + * 插件id + */ + private String pluginId; + + /** + * 调用方法 + */ + private String method; + + /** + * 方法参数 + */ + private String args; + + /** + * 执行结果 + */ + private String result; + +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataReader.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataReader.java new file mode 100644 index 0000000..3296f74 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/DataReader.java @@ -0,0 +1,68 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main.script; + + +import io.vertx.core.Handler; +import io.vertx.core.buffer.Buffer; +import io.vertx.core.parsetools.RecordParser; + +import java.util.function.Consumer; + +/** + * 数据包读取器 + * + * @author sjg + */ +public class DataReader { + + public static RecordParser getParser(Consumer receiveHandler) { + RecordParser parser = RecordParser.newFixed(4); + // 设置处理器 + parser.setOutput(new Handler<>() { + // 表示当前数据长度 + int size = -1; + + @Override + public void handle(Buffer buffer) { + //-1表示当前还没有长度信息,需要从收到的数据中取出长度 + if (-1 == size) { + //取出长度 + size = buffer.getInt(0); + //动态修改长度 + parser.fixedSizeMode(size); + } else { + //如果size != -1, 说明已经接受到长度信息了,接下来的数据就是protobuf可识别的字节数组 + byte[] buf = buffer.getBytes(); + receiveHandler.accept(Buffer.buffer(buf)); + //处理完后要将长度改回 + parser.fixedSizeMode(4); + //重置size变量 + size = -1; + } + } + }); + return parser; + } +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/PluginScriptEngine.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/PluginScriptEngine.java new file mode 100644 index 0000000..66d6a91 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/PluginScriptEngine.java @@ -0,0 +1,100 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main.script; + +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.script.IScriptEngine; +import cc.iotkit.script.JavaScriptEngine; +import cn.hutool.core.util.IdUtil; +import com.fasterxml.jackson.core.type.TypeReference; +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + +import java.util.ArrayList; +import java.util.List; + +/** + * 用于插件的脚本引擎,为了规避graalvm js加载问题,不直接调用使用tcp通讯交互 + * + * @author sjg + */ +@Slf4j +@Data +public class PluginScriptEngine implements IScriptEngine { + + private String pluginId; + + private ScriptClientVerticle scriptClientVerticle = new ScriptClientVerticle(); + + public PluginScriptEngine(String pluginId) { + this.pluginId = pluginId; + Vertx vertx = Vertx.vertx(); + Future future = vertx.deployVerticle(scriptClientVerticle); + future.onSuccess((s -> { + log.info("tcp client started success"); + })); + future.onFailure((e) -> { + log.error("tcp client startup failed", e); + }); + } + + @Override + public void setScript(String s) { + + } + + @Override + public void putScriptEnv(String s, Object o) { + + } + + @Override + public void invokeMethod(String s, Object... args) { + throw new UnsupportedOperationException(); + } + + @Override + public T invokeMethod(TypeReference type, String method, Object... args) { + List argJson = new ArrayList<>(); + for (Object arg : args) { + argJson.add(JsonUtils.toJsonString(arg)); + } + + String json = scriptClientVerticle.send(DataPackage.builder() + .pluginId(pluginId) + .mid(IdUtil.getSnowflakeNextIdStr()) + .method(method) + .args(JsonUtils.toJsonString(argJson)) + .build()); + return json == null ? null : JsonUtils.parseObject(json, type); + } + + @Override + public String invokeMethod(String s, String s1) { + throw new UnsupportedOperationException(); + } + +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/PluginScriptServer.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/PluginScriptServer.java new file mode 100644 index 0000000..36738b4 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/PluginScriptServer.java @@ -0,0 +1,71 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main.script; + +import cc.iotkit.data.manager.IPluginInfoData; +import cc.iotkit.script.IScriptEngine; +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.Map; + +/** + * 用于插件的脚本引擎,为了规避graalvm js加载问题,不直接调用使用tcp通讯交互 + * + * @author sjg + */ +@Slf4j +@Service +public class PluginScriptServer { + @Autowired + private IPluginInfoData pluginInfoData; + + @Autowired + private ScriptVerticle scriptVerticle; + + private static final Map PLUGIN_SCRIPT_ENGINES = new HashMap<>(); + + @PostConstruct + public void init() { + Vertx vertx = Vertx.vertx(); + Future future = vertx.deployVerticle(scriptVerticle); + future.onSuccess((s -> { + log.info("plugin script server started success"); + })); + future.onFailure(Throwable::printStackTrace); + } + + public IScriptEngine getScriptEngine(String pluginId) { + if (!PLUGIN_SCRIPT_ENGINES.containsKey(pluginId)) { + PLUGIN_SCRIPT_ENGINES.put(pluginId,new PluginScriptEngine(pluginId)); + } + return PLUGIN_SCRIPT_ENGINES.get(pluginId); + } + +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptClientVerticle.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptClientVerticle.java new file mode 100644 index 0000000..a6adbfd --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptClientVerticle.java @@ -0,0 +1,104 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main.script; + +import cn.hutool.core.util.HexUtil; +import io.vertx.core.AbstractVerticle; +import io.vertx.core.buffer.Buffer; +import io.vertx.core.net.NetClient; +import io.vertx.core.net.NetClientOptions; +import io.vertx.core.net.NetSocket; +import io.vertx.core.parsetools.RecordParser; +import lombok.extern.slf4j.Slf4j; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author sjg + */ +@Slf4j +public class ScriptClientVerticle extends AbstractVerticle { + + private NetClient netClient; + + private NetSocket socket; + + private AtomicInteger atMid = new AtomicInteger(0); + + @Override + public void start() { + initClient(); + } + + @Override + public void stop() { + if (null != netClient) { + netClient.close(); + } + } + + private void initClient() { + NetClientOptions options = new NetClientOptions(); + options.setReconnectAttempts(Integer.MAX_VALUE); + options.setReconnectInterval(20000L); + netClient = vertx.createNetClient(options); + RecordParser parser = DataReader.getParser(this::handle); + + netClient.connect(new ScriptServerConfig().getPort(), "127.0.0.1", result -> { + if (result.succeeded()) { + log.debug("connect tcp success"); + socket = result.result(); + socket.handler(parser); + } else { + log.error("connect tcp error", result.cause()); + } + }); + } + + private short getMid() { + atMid.compareAndSet(254, 0); + return (short) atMid.getAndIncrement(); + } + + public String send(DataPackage data) { + Buffer buffer = DataEncoder.encode(data); + socket.write(buffer); + Chan chan = Chan.getInstance(); + DataPackage receiver = chan.get(data.getMid()); + if (receiver == null) { + return null; + } + if (receiver.getMid().equals(data.getMid())) { + return receiver.getResult(); + } + return null; + } + + public void handle(Buffer buffer) { + DataPackage data = DataDecoder.decode(buffer); + Chan chan = Chan.getInstance(); + chan.put(data); + } + +} \ No newline at end of file diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptServerConfig.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptServerConfig.java new file mode 100644 index 0000000..cf7a725 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptServerConfig.java @@ -0,0 +1,53 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main.script; + +import cn.hutool.core.util.RandomUtil; +import io.vertx.core.net.SocketAddress; +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +/** + * @author sjg + */ +public class ScriptServerConfig { + private static int _port; + + static { + _port = RandomUtil.randomInt(41024, 42024); + } + + @Getter + private String host = "localhost"; + + @Getter + private int port = _port; + + public SocketAddress createSocketAddress() { + if (StringUtils.isEmpty(host)) { + host = "localhost"; + } + return SocketAddress.inetSocketAddress(port, host); + } +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptVerticle.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptVerticle.java new file mode 100644 index 0000000..baed4ee --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/ScriptVerticle.java @@ -0,0 +1,199 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main.script; + +import cc.iotkit.common.utils.CodecUtil; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.manager.IPluginInfoData; +import cc.iotkit.model.plugin.PluginInfo; +import cc.iotkit.script.IScriptEngine; +import cc.iotkit.script.ScriptEngineFactory; +import cn.hutool.core.util.IdUtil; +import io.vertx.core.AbstractVerticle; +import io.vertx.core.buffer.Buffer; +import io.vertx.core.net.NetServer; +import io.vertx.core.net.NetServerOptions; +import io.vertx.core.net.NetSocket; +import io.vertx.core.parsetools.RecordParser; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.time.Duration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; + +@Slf4j +@Component +public class ScriptVerticle extends AbstractVerticle { + + private final Map clientMap = new ConcurrentHashMap<>(); + + private static final Map PLUGIN_SCRIPT_ENGINES = new HashMap<>(); + + private final Map pluginScripts = new HashMap<>(); + + @Setter + private long keepAliveTimeout = Duration.ofSeconds(30).toMillis(); + + @Autowired + private IPluginInfoData pluginInfoData; + + public IScriptEngine initScriptEngine(String pluginId) { + PluginInfo pluginInfo = pluginInfoData.findByPluginId(pluginId); + if (pluginInfo == null) { + return null; + } + String script = pluginInfo.getScript(); + if (StringUtils.isBlank(script)) { + return null; + } + + //缓存脚本md5,用于判断是否需要更新脚本 + pluginScripts.put(pluginId, CodecUtil.md5Str(script)); + + IScriptEngine jsEngine = ScriptEngineFactory.getJsEngine(script); + PLUGIN_SCRIPT_ENGINES.put(pluginId, ScriptEngineFactory.getJsEngine(script)); + return jsEngine; + } + + public IScriptEngine getScriptEngine(String pluginId) { + if (!PLUGIN_SCRIPT_ENGINES.containsKey(pluginId)) { + return initScriptEngine(pluginId); + } + return PLUGIN_SCRIPT_ENGINES.get(pluginId); + } + + @Scheduled(fixedDelay = 5, timeUnit = TimeUnit.SECONDS) + public void checkScriptUpdate() { + //定时检查脚本是否需要更新 + List plugins = pluginInfoData.findAll(); + for (PluginInfo plugin : plugins) { + String pluginId = plugin.getPluginId(); + String oldMd5 = pluginScripts.get(pluginId); + String script = plugin.getScript(); + if (script == null) { + continue; + } + String md5 = CodecUtil.md5Str(script); + if (oldMd5 != null && oldMd5.equals(md5)) { + continue; + } + + IScriptEngine scriptEngine = PLUGIN_SCRIPT_ENGINES.get(pluginId); + if (scriptEngine == null) { + continue; + } + log.info("plugin script has changed"); + pluginScripts.put(pluginId, md5); + scriptEngine.setScript(script); + } + } + + @Override + public void start() { + initTcpServer(); + } + + @Override + public void stop() { + log.info("tcp server stopped"); + } + + /** + * 初始TCP服务 + */ + private void initTcpServer() { + ScriptServerConfig config = new ScriptServerConfig(); + NetServer netServer = vertx.createNetServer( + new NetServerOptions().setHost("127.0.0.1") + .setPort(config.getPort())); + netServer.connectHandler(this::acceptTcpConnection); + netServer.listen(config.createSocketAddress(), result -> { + if (result.succeeded()) { + log.info("tcp server startup on {}", result.result().actualPort()); + } else { + result.cause().printStackTrace(); + } + }); + } + + /** + * TCP连接处理逻辑 + * + * @param socket socket + */ + protected void acceptTcpConnection(NetSocket socket) { + // 客户端连接处理 + String clientId = IdUtil.simpleUUID() + "_" + socket.remoteAddress(); + VertxTcpClient client = new VertxTcpClient(clientId); + client.setKeepAliveTimeoutMs(keepAliveTimeout); + try { + // TCP异常和关闭处理 + socket.exceptionHandler(Throwable::printStackTrace).closeHandler(nil -> { + log.debug("tcp server client [{}] closed", socket.remoteAddress()); + client.shutdown(); + }); + // 这个地方是在TCP服务初始化的时候设置的 parserSupplier + client.setKeepAliveTimeoutMs(keepAliveTimeout); + client.setSocket(socket); + RecordParser parser = DataReader.getParser(buffer -> { + try { + DataPackage data = DataDecoder.decode(buffer); + String pluginId = data.getPluginId(); + clientMap.put(pluginId, client); + IScriptEngine scriptEngine = getScriptEngine(pluginId); + if (scriptEngine == null) { + data.setResult(""); + } else { + //调用执行脚本方法返回结果 + String result = scriptEngine.invokeMethod(data.getMethod(), data.getArgs()); + data.setResult(result); + } + sendMsg(pluginId, DataEncoder.encode(data)); + } catch (Exception e) { + log.error("decode error", e); + } + }); + client.setParser(parser); + log.debug("accept tcp client [{}] connection", socket.remoteAddress()); + } catch (Exception e) { + log.error("acceptTcpConnection error", e); + client.shutdown(); + } + } + + public void sendMsg(String pluginId, Buffer msg) { + VertxTcpClient tcpClient = clientMap.get(pluginId); + if (tcpClient != null) { + tcpClient.sendMessage(msg); + } + } + +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/VertxTcpClient.java b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/VertxTcpClient.java new file mode 100644 index 0000000..4bfc819 --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/java/cc/iotkit/plugin/main/script/VertxTcpClient.java @@ -0,0 +1,114 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.plugin.main.script; + +import io.vertx.core.buffer.Buffer; +import io.vertx.core.net.NetSocket; +import io.vertx.core.parsetools.RecordParser; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.binary.Hex; + +import java.time.Duration; + +/** + * @author sjg + */ +@Slf4j +public class VertxTcpClient { + @Getter + private String id; + public NetSocket socket; + @Setter + private long keepAliveTimeoutMs = Duration.ofSeconds(30).toMillis(); + private volatile long lastKeepAliveTime = System.currentTimeMillis(); + + @Setter + private RecordParser parser; + + public VertxTcpClient(String id) { + this.id = id; + } + + public void keepAlive() { + lastKeepAliveTime = System.currentTimeMillis(); + } + + public boolean isOnline() { + return System.currentTimeMillis() - lastKeepAliveTime < keepAliveTimeoutMs; + } + + public void setSocket(NetSocket socket) { + synchronized (this) { + if (this.socket != null && this.socket != socket) { + this.socket.close(); + } + + this.socket = socket + .closeHandler(v -> shutdown()) + .handler(buffer -> { + if (log.isDebugEnabled()) { + log.debug("handle tcp client[{}] payload:[{}]", + socket.remoteAddress(), + Hex.encodeHexString(buffer.getBytes())); + } + keepAlive(); + parser.handle(buffer); + if (this.socket != socket) { + log.warn("tcp client [{}] memory leak ", socket.remoteAddress()); + socket.close(); + } + }); + } + } + + public void shutdown() { + log.debug("tcp client [{}] disconnect", getId()); + synchronized (this) { + if (null != socket) { + execute(socket::close); + this.socket = null; + } + } + } + + public void sendMessage(Buffer buffer) { + socket.write(buffer, r -> { + keepAlive(); + if (!r.succeeded()) { + log.error("client msg send failed", r.cause()); + } + }); + } + + private void execute(Runnable runnable) { + try { + runnable.run(); + } catch (Exception e) { + log.warn("close tcp client error", e); + } + } + +} diff --git a/iot-module/iot-plugin/iot-plugin-main/src/main/resources/application.yml b/iot-module/iot-plugin/iot-plugin-main/src/main/resources/application.yml new file mode 100644 index 0000000..e242bfa --- /dev/null +++ b/iot-module/iot-plugin/iot-plugin-main/src/main/resources/application.yml @@ -0,0 +1,10 @@ +# 插件配置 +plugin: + # 独立部署模式 + standalone: false + ip: localhost + runMode: prod + mainPackage: cc.iotkit + # 如果配置是 windows 下路径, mac、linux 自行修改 + pluginPath: + - ./data/plugins \ No newline at end of file diff --git a/iot-module/iot-plugin/pom.xml b/iot-module/iot-plugin/pom.xml new file mode 100644 index 0000000..7f42dd6 --- /dev/null +++ b/iot-module/iot-plugin/pom.xml @@ -0,0 +1,19 @@ + + + + iot-module + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-plugin + pom + + + iot-plugin-main + + + \ No newline at end of file diff --git a/iot-module/iot-rule-engine/pom.xml b/iot-module/iot-rule-engine/pom.xml new file mode 100644 index 0000000..28406fc --- /dev/null +++ b/iot-module/iot-rule-engine/pom.xml @@ -0,0 +1,133 @@ + + + + iot-module + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-rule-engine + + 规则引擎模块,包含场景引擎、数据流转等 + + + + + + cc.iotkit + iot-data-model + + + + cc.iotkit + iot-common-core + + + + cc.iotkit + iot-data-service + + + + cc.iotkit + iot-temporal-service + + + + cc.iotkit + iot-message-core + + + + cc.iotkit + iot-script-engine + + + + cc.iotkit + iot-message-notify + + + + + + org.springframework + spring-context-support + + + + org.quartz-scheduler + quartz + + + com.zaxxer + HikariCP-java7 + + + + + org.springframework.boot + spring-boot + + + + org.springframework + spring-tx + + + + org.springframework.boot + spring-boot-starter-integration + + + org.springframework.integration + spring-integration-mqtt + + + + com.squareup.okhttp3 + okhttp + + + + org.projectlombok + lombok + + + + + io.vertx + vertx-mqtt + + + + + io.vertx + vertx-kafka-client + + + cc.iotkit + iot-plugin-core + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + utf8 + + + + + + diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/Application.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/Application.java new file mode 100644 index 0000000..68c61b2 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/Application.java @@ -0,0 +1,39 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Slf4j +@SpringBootApplication(scanBasePackages = {"cc.iotkit"}) +@EnableTransactionManagement +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + log.info("server start success!"); + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/Action.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/Action.java new file mode 100644 index 0000000..06e1b12 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/Action.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.action; + + +import cc.iotkit.common.thing.ThingModelMessage; + +import java.util.List; + +public interface Action { + + String getType(); + + List getServices(); + + /** + * 执行动作返回执行动作内容 + */ + List execute(ThingModelMessage msg); +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/ScriptService.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/ScriptService.java new file mode 100644 index 0000000..7dc433e --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/ScriptService.java @@ -0,0 +1,62 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.action; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.script.IScriptEngine; +import cc.iotkit.script.ScriptEngineFactory; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + + +@Slf4j +@Data +public class ScriptService { + + private IScriptEngine scriptEngine = ScriptEngineFactory.getScriptEngine("js"); + + private String script; + + private IDeviceInfoData deviceInfoData; + + public void setScript(String script) { + this.script=script; + scriptEngine.setScript(script); + } + + public T execScript(TypeReference type, ThingModelMessage msg) { + try { + //取设备信息 + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(msg.getDeviceId()); + + //执行转换脚本 + return scriptEngine.invokeMethod(type, "translate", msg, deviceInfo); + } catch (Throwable e) { + log.error("run script error", e); + return null; + } + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertAction.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertAction.java new file mode 100644 index 0000000..d4520d7 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertAction.java @@ -0,0 +1,62 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.action.alert; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.ruleengine.action.Action; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author sjg + */ +@NoArgsConstructor +@AllArgsConstructor +@Data +public class AlertAction implements Action { + + public static final String TYPE = "alert"; + + private String type; + + private List services; + + @Override + public String getType() { + return TYPE; + } + + @Override + public List execute(ThingModelMessage msg) { + List results = new ArrayList<>(); + for (AlertService service : services) { + results.add(service.execute(msg)); + } + return results; + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertService.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertService.java new file mode 100644 index 0000000..a530c0f --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/alert/AlertService.java @@ -0,0 +1,62 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.action.alert; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.message.model.Message; +import cc.iotkit.message.service.MessageService; +import cc.iotkit.ruleengine.action.ScriptService; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; + +import java.util.Map; + +/** + * @author sjg + */ +@EqualsAndHashCode(callSuper = true) +@Slf4j +@Data +public class AlertService extends ScriptService { + + private Message message; + + private MessageService messageService; + + @SneakyThrows + public String execute(ThingModelMessage msg) { + //执行转换脚本 + Map result = execScript(new TypeReference<>() { + }, msg); + if (result == null) { + log.warn("execScript result is null"); + return "execScript result is null"; + } + message.setParam(result); + messageService.sendMessage(message); + return "ok"; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/device/DeviceAction.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/device/DeviceAction.java new file mode 100644 index 0000000..58488cb --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/device/DeviceAction.java @@ -0,0 +1,64 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.action.device; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.ruleengine.action.Action; +import cc.iotkit.ruleengine.action.device.DeviceActionService.Service; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@NoArgsConstructor +@AllArgsConstructor +@Data +public class DeviceAction implements Action { + + public static final String TYPE = "device"; + + private String type; + + private List services; + + private DeviceActionService deviceActionService; + + @Override + public String getType() { + return TYPE; + } + + @Override + public List execute(ThingModelMessage msg) { + List results = new ArrayList<>(); + for (DeviceActionService.Service service : services) { + deviceActionService.invoke(service); + results.add(JsonUtils.toJsonString(service)); + } + return results; + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/device/DeviceActionService.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/device/DeviceActionService.java new file mode 100644 index 0000000..2cdc104 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/device/DeviceActionService.java @@ -0,0 +1,91 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.action.device; + +import cc.iotkit.common.thing.DeviceService; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.thing.ThingService; +import cc.iotkit.common.utils.UniqueIdUtil; +import lombok.Data; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Component +public class DeviceActionService { + + @Autowired + private DeviceService deviceService; + + public String invoke(Service service) { + String[] pkDn = service.getDevice().split("/"); + ThingService> thingService = new ThingService<>(); + thingService.setMid(UniqueIdUtil.newRequestId()); + thingService.setProductKey(pkDn[0]); + thingService.setDeviceName(pkDn[1]); + thingService.setType(service.getType()); + thingService.setIdentifier(service.getIdentifier()); + thingService.setParams(service.parseInputData()); + deviceService.invoke(thingService); + return thingService.getMid(); + } + + @Data + public static class Service { + + private String device; + + private String identifier; + + private String type; + + public String getType() { + //identifier为set固定为属性设置,其它为服务调用 + if (ThingModelMessage.ID_PROPERTY_SET.equals(identifier) || + ThingModelMessage.ID_PROPERTY_GET.equals(identifier)) { + return ThingModelMessage.TYPE_PROPERTY; + } + return ThingModelMessage.TYPE_SERVICE; + } + + private List inputData; + + public Map parseInputData() { + Map data = new HashMap<>(); + for (Parameter p : inputData) { + data.put(p.getIdentifier(), p.getValue()); + } + return data; + } + + @Data + public static class Parameter { + private String identifier; + private Object value; + } + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/http/HttpAction.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/http/HttpAction.java new file mode 100644 index 0000000..5e3612c --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/http/HttpAction.java @@ -0,0 +1,59 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.action.http; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.ruleengine.action.Action; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@NoArgsConstructor +@AllArgsConstructor +@Data +public class HttpAction implements Action { + + public static final String TYPE = "http"; + + private String type; + + private List services; + + @Override + public String getType() { + return TYPE; + } + + @Override + public List execute(ThingModelMessage msg) { + List results = new ArrayList<>(); + for (HttpService service : services) { + results.add(service.execute(msg)); + } + return results; + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/http/HttpService.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/http/HttpService.java new file mode 100644 index 0000000..c75061f --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/http/HttpService.java @@ -0,0 +1,108 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.action.http; + +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.ruleengine.action.ScriptService; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import okhttp3.*; +import org.apache.commons.beanutils.BeanUtils; + +import java.io.IOException; +import java.util.Map; + +@EqualsAndHashCode(callSuper = true) +@Slf4j +@Data +public class HttpService extends ScriptService { + private String url; + + private final OkHttpClient httpClient = new OkHttpClient(); + + @SneakyThrows + public String execute(ThingModelMessage msg) { + //执行转换脚本 + HttpData httpData = execScript(new TypeReference<>() { + }, msg); + if (httpData == null) { + log.warn("execScript result is null"); + return "execScript result is null"; + } + + //组装http请求 + String url = this.url + httpData.getPath(); + Request.Builder builder = new Request.Builder(); + Map headers = httpData.getHeader(); + if (headers != null) { + headers.forEach((key, val) -> builder.header(key, val.toString())); + } + HttpHeader httpHeader = new HttpHeader(); + BeanUtils.populate(httpHeader, headers); + + builder.url(url); + RequestBody requestBody; + requestBody = RequestBody.create(MediaType.get(httpHeader.getContentType()), + httpData.getBody().toString()); + + Request request = builder.method(httpData.getMethod().toUpperCase(), requestBody).build(); + String requestDataStr = JsonUtils.toJsonString(httpData); + log.info("send http request:{} ,{}", url, requestDataStr); + + String responseBody = ""; + int responseCode; + //发送请求 + try (Response response = httpClient.newCall(request).execute()) { + ResponseBody body = response.body(); + responseCode = response.code(); + responseBody = body == null ? "" : body.string(); + log.info("send result,code:{},response:{}", responseCode, responseBody); + } catch (IOException e) { + throw new BizException(ErrCode.SEND_REQUEST_ERROR, e); + } + + return String.format("send request,url:%s,method:%s,receive response,code:%s,body:%s", + url, requestDataStr, responseCode, responseBody); + + } + + @Data + public static class HttpData { + private String path; + private String method; + private Map header; + private Object body; + } + + @Data + public static class HttpHeader { + private String contentType; + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/kafka/KafkaAction.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/kafka/KafkaAction.java new file mode 100644 index 0000000..218d9a4 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/kafka/KafkaAction.java @@ -0,0 +1,63 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.action.kafka; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.ruleengine.action.Action; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author huangwenl + * @date 2022-11-11 + */ +@NoArgsConstructor +@AllArgsConstructor +@Data +public class KafkaAction implements Action { + + public static final String TYPE = "kafka"; + + + private List services; + + @Override + public String getType() { + return TYPE; + } + + + @Override + public List execute(ThingModelMessage msg) { + List results = new ArrayList<>(); + for (KafkaService service : services) { + results.add(service.execute(msg)); + } + return results; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/kafka/KafkaService.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/kafka/KafkaService.java new file mode 100644 index 0000000..cb81fbc --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/kafka/KafkaService.java @@ -0,0 +1,89 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.action.kafka; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.FIUtil; +import cc.iotkit.ruleengine.action.ScriptService; +import cc.iotkit.ruleengine.link.LinkFactory; +import cc.iotkit.ruleengine.link.LinkService; +import cc.iotkit.ruleengine.link.impl.KafkaLink; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.extern.slf4j.Slf4j; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +/** + * @author huangwenl + * @date 2022-11-11 + */ +@EqualsAndHashCode(callSuper = true) +@Slf4j +@Data +public class KafkaService extends ScriptService implements LinkService { + + private String services; + private String ack; + + public String execute(ThingModelMessage msg) { + //执行转换脚本 + Map result = execScript(new TypeReference<>() { + }, msg); + if (result == null) { + log.warn("execScript result is null"); + return "execScript result is null"; + } + boolean initResult = LinkFactory.initLink(getKey(), KafkaLink.LINK_TYPE, getLinkConf()); + + AtomicReference data = new AtomicReference<>(""); + FIUtil.isTotF(initResult).handler( + () -> LinkFactory.sendMsg(getKey(), result, data::set), + () -> data.set("创建连接失败!") + ); + + return data.get(); + } + + @Override + public String getKey() { + return String.format("kafka_%s", services); + } + + @Override + public String getLinkType() { + return KafkaLink.LINK_TYPE; + } + + @Override + public Map getLinkConf() { + Map config = new HashMap<>(); + config.put(KafkaLink.SERVERS, services); + config.put(KafkaLink.ACK, ack); + return config; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/mqtt/MqttAction.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/mqtt/MqttAction.java new file mode 100644 index 0000000..c3f5eb0 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/mqtt/MqttAction.java @@ -0,0 +1,62 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.action.mqtt; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.ruleengine.action.Action; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author huangwenl + * @date 2022-11-10 + */ +@NoArgsConstructor +@AllArgsConstructor +@Data +public class MqttAction implements Action { + public static final String TYPE = "mqtt"; + + + private List services; + + @Override + public String getType() { + return TYPE; + } + + + @Override + public List execute(ThingModelMessage msg) { + List results = new ArrayList<>(); + for (MqttService service : services) { + results.add(service.execute(msg)); + } + return results; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/mqtt/MqttService.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/mqtt/MqttService.java new file mode 100644 index 0000000..f06d484 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/mqtt/MqttService.java @@ -0,0 +1,93 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.action.mqtt; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.FIUtil; +import cc.iotkit.ruleengine.action.ScriptService; +import cc.iotkit.ruleengine.link.LinkFactory; +import cc.iotkit.ruleengine.link.LinkService; +import cc.iotkit.ruleengine.link.impl.MqttClientLink; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.extern.slf4j.Slf4j; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +/** + * @author huangwenl + * @date 2022-11-09 + */ + +@EqualsAndHashCode(callSuper = true) +@Slf4j +@Data +public class MqttService extends ScriptService implements LinkService { + + private String username; + private String password; + private String host; + private int port; + + public String execute(ThingModelMessage msg) { + //执行转换脚本 + Map result = execScript(new TypeReference<>() { + }, msg); + if (result == null) { + log.warn("execScript result is null"); + return "execScript result is null"; + } + boolean initResult = LinkFactory.initLink(getKey(), MqttClientLink.LINK_TYPE, getLinkConf()); + + AtomicReference data = new AtomicReference<>(""); + FIUtil.isTotF(initResult).handler( + () -> LinkFactory.sendMsg(getKey(), result, data::set), + () -> data.set("创建连接失败!") + ); + return data.get(); + } + + @Override + public String getKey() { + return String.format("mqtt_%s_%d", host, port); + } + + @Override + public String getLinkType() { + return MqttClientLink.LINK_TYPE; + } + + @Override + public Map getLinkConf() { + Map config = new HashMap<>(); + config.put(MqttClientLink.HOST, host); + config.put(MqttClientLink.PORT, port); + config.put(MqttClientLink.USERNAME, username); + config.put(MqttClientLink.PASSWORD, password); + return config; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/tcp/TcpAction.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/tcp/TcpAction.java new file mode 100644 index 0000000..b234938 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/tcp/TcpAction.java @@ -0,0 +1,62 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.action.tcp; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.ruleengine.action.Action; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author huangwenl + * @date 2022-12-14 + */ +@NoArgsConstructor +@AllArgsConstructor +@Data +public class TcpAction implements Action { + public static final String TYPE = "tcp"; + + + private List services; + + @Override + public String getType() { + return TYPE; + } + + + @Override + public List execute(ThingModelMessage msg) { + List results = new ArrayList<>(); + for (TcpService service : services) { + results.add(service.execute(msg)); + } + return results; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/tcp/TcpService.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/tcp/TcpService.java new file mode 100644 index 0000000..786ea74 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/action/tcp/TcpService.java @@ -0,0 +1,87 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.action.tcp; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.FIUtil; +import cc.iotkit.ruleengine.action.ScriptService; +import cc.iotkit.ruleengine.link.LinkFactory; +import cc.iotkit.ruleengine.link.LinkService; +import cc.iotkit.ruleengine.link.impl.TcpClientLink; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.extern.slf4j.Slf4j; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +/** + * @author huangwenl + * @date 2022-12-14 + */ +@EqualsAndHashCode(callSuper = true) +@Slf4j +@Data +public class TcpService extends ScriptService implements LinkService { + private String host; + private int port; + + public String execute(ThingModelMessage msg) { + //执行转换脚本 + Map result = execScript(new TypeReference<>() { + },msg); + if (result == null) { + log.warn("execScript result is null"); + return "execScript result is null"; + } + boolean initResult = LinkFactory.initLink(getKey(), TcpClientLink.LINK_TYPE, getLinkConf()); + + AtomicReference data = new AtomicReference<>(""); + FIUtil.isTotF(initResult).handler( + () -> LinkFactory.sendMsg(getKey(), result, data::set), + () -> data.set("创建连接失败!") + ); + return data.get(); + } + + @Override + public String getKey() { + return String.format("tcp_%s_%d", host, port); + } + + @Override + public String getLinkType() { + return TcpClientLink.LINK_TYPE; + } + + @Override + public Map getLinkConf() { + Map config = new HashMap<>(); + config.put(TcpClientLink.HOST, host); + config.put(TcpClientLink.PORT, port); + return config; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/alert/Alerter.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/alert/Alerter.java new file mode 100644 index 0000000..160bc9f --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/alert/Alerter.java @@ -0,0 +1,38 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.alert; + +import java.util.Map; + +/** + * 报警器 + */ +public interface Alerter { + + void setConfig(String config); + + void setTemplate(String template); + + String send(Map data); + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/alert/DingdRobotAlerter.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/alert/DingdRobotAlerter.java new file mode 100644 index 0000000..df9cc56 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/alert/DingdRobotAlerter.java @@ -0,0 +1,45 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.alert; + +import java.util.Map; + +/** + * 钉钉机器人告警器 + */ +public class DingdRobotAlerter implements Alerter { + @Override + public void setConfig(String config) { + + } + + @Override + public void setTemplate(String template) { + + } + + @Override + public String send(Map data) { + return "send dingding robot msg"; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/alert/EmailAlerter.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/alert/EmailAlerter.java new file mode 100644 index 0000000..a541041 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/alert/EmailAlerter.java @@ -0,0 +1,50 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.alert; + +import lombok.Data; + +import java.util.Map; + +/** + * 邮件告警器 + */ +@Data +public class EmailAlerter implements Alerter { + + + @Override + public void setConfig(String config) { + + } + + @Override + public void setTemplate(String template) { + + } + + @Override + public String send(Map data) { + return "send email"; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/config/JobFactory.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/config/JobFactory.java new file mode 100644 index 0000000..f377bb5 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/config/JobFactory.java @@ -0,0 +1,61 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.config; + +import cc.iotkit.model.rule.TaskInfo; +import cc.iotkit.ruleengine.task.ActionExecutorManager; +import cc.iotkit.ruleengine.task.CommonJob; +import cc.iotkit.ruleengine.task.TaskManager; +import org.quartz.JobDetail; +import org.quartz.spi.TriggerFiredBundle; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; +import org.springframework.scheduling.quartz.AdaptableJobFactory; +import org.springframework.stereotype.Component; + +@Component +public class JobFactory extends AdaptableJobFactory { + @Autowired + private AutowireCapableBeanFactory capableBeanFactory; + @Autowired + private ActionExecutorManager actionExecutorManager; + @Autowired + private TaskManager taskManager; + + @Override + protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { + JobDetail jobDetail = bundle.getJobDetail(); + Object objTask = jobDetail.getJobDataMap().get("taskInfo"); + + Class clz = jobDetail.getJobClass(); + Object jobInstance; + if (clz == CommonJob.class && objTask instanceof TaskInfo) { + jobInstance = new CommonJob(actionExecutorManager, taskManager, (TaskInfo) objTask); + } else { + jobInstance = super.createJobInstance(bundle); + } + //进行注入 + capableBeanFactory.autowireBean(jobInstance); + return jobInstance; + } +} \ No newline at end of file diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/config/QuartzConfiguration.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/config/QuartzConfiguration.java new file mode 100644 index 0000000..f959115 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/config/QuartzConfiguration.java @@ -0,0 +1,54 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.config; + +import org.quartz.Scheduler; +import org.quartz.spi.JobFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.quartz.SchedulerFactoryBean; + +@Configuration +public class QuartzConfiguration { + + @Autowired + private JobFactory jobFactory; + + @Bean + public SchedulerFactoryBean schedulerFactoryBean() { + SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); + try { + schedulerFactoryBean.setOverwriteExistingJobs(true); + schedulerFactoryBean.setJobFactory(jobFactory); + } catch (Exception e) { + e.printStackTrace(); + } + return schedulerFactoryBean; + } + + @Bean(name = "scheduler") + public Scheduler scheduler() { + return schedulerFactoryBean().getScheduler(); + } +} \ No newline at end of file diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/config/RuleConfiguration.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/config/RuleConfiguration.java new file mode 100644 index 0000000..e844921 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/config/RuleConfiguration.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.config; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.mq.MqConsumer; +import cc.iotkit.ruleengine.handler.RuleDeviceConsumer; +import cc.iotkit.ruleengine.task.TaskManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class RuleConfiguration { + + @Bean + public RuleDeviceConsumer getConsumer(MqConsumer consumer) { + return new RuleDeviceConsumer(consumer); + } + + @Bean + public TaskManager getTaskManager() { + return new TaskManager(); + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/expression/Expression.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/expression/Expression.java new file mode 100644 index 0000000..2264d59 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/expression/Expression.java @@ -0,0 +1,73 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.expression; + +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.script.IScriptEngine; +import cc.iotkit.script.ScriptEngineFactory; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.IOUtils; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; + +/** + * @author sjg + */ +@Slf4j +public class Expression { + + private static final Map COMPARATOR_MAP = new HashMap<>(); + + private static IScriptEngine engine = ScriptEngineFactory.getScriptEngine("js"); + + static { + COMPARATOR_MAP.put(">", "gt"); + COMPARATOR_MAP.put(">=", "ge"); + COMPARATOR_MAP.put("==", "eq"); + COMPARATOR_MAP.put("<", "lt"); + COMPARATOR_MAP.put("<=", "le"); + COMPARATOR_MAP.put("!=", "neq"); + try { + String script = IOUtils.resourceToString("script.js", Charset.defaultCharset(), Expression.class.getClassLoader()); + engine.setScript(script); + } catch (IOException e) { + log.error("read script.js error", e); + } + } + + public static boolean eval(String comparator, Object... args) { + String name = COMPARATOR_MAP.get(comparator); + if (name == null) { + throw new BizException(ErrCode.DATA_BLANK); + } + + return engine.invokeMethod(new TypeReference<>() { + }, name, args); + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/DeviceCondition.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/DeviceCondition.java new file mode 100644 index 0000000..75835eb --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/DeviceCondition.java @@ -0,0 +1,94 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.filter; + +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DevicePropertyCache; +import cc.iotkit.ruleengine.expression.Expression; +import lombok.Data; + +import java.util.Map; + +@Data +public class DeviceCondition { + + private String device; + + private String type; + + private String identifier; + + private Object value; + + private String comparator; + + private IDeviceInfoData deviceInfoData; + + @Override + public DeviceCondition clone() { + DeviceCondition con = new DeviceCondition(); + con.setDevice(device); + con.setType(type); + con.setIdentifier(identifier); + con.setValue(value); + con.setComparator(comparator); + con.setDeviceInfoData(deviceInfoData); + return con; + } + + public boolean matches() { + DeviceInfo deviceInfo; + String[] pkDn = device.split("/"); + if (pkDn.length < 2) { + //用deviceId取 + deviceInfo = deviceInfoData.findByDeviceId(device); + } else { + //用pk/dn取 + deviceInfo = deviceInfoData.findByDeviceName(pkDn[1]); + } + Object left = null; + if ("property".equals(type)) { + Map properties = deviceInfo.getProperty(); + DevicePropertyCache propertyCache = (DevicePropertyCache) properties.get(identifier); + if (propertyCache == null) { + return false; + } + left = propertyCache.getValue(); + } else if ("state".equals(type)) { + DeviceInfo.State state = deviceInfo.getState(); + left = state != null && state.isOnline(); + } else if ("tag".equals(type)) { + //取设备标签判断 + Map tags = deviceInfo.getTag(); + if (tags != null) { + DeviceInfo.Tag tag = tags.get(identifier); + if (tag != null) { + //设备标签值 + left = tag.getValue(); + } + } + } + return Expression.eval(comparator, left, value); + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/DeviceFilter.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/DeviceFilter.java new file mode 100644 index 0000000..6c54b69 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/DeviceFilter.java @@ -0,0 +1,73 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.filter; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.data.manager.IDeviceInfoData; +import lombok.Data; +import org.apache.commons.lang3.StringUtils; + +import java.util.List; + +@Data +public class DeviceFilter implements Filter { + + public static String TYPE = "device"; + + private String type; + + private String pk; + + private String dn; + + private List conditions; + + private IDeviceInfoData deviceInfoData; + + @Override + public String getType() { + return TYPE; + } + + @Override + public void init() { + } + + @Override + public boolean execute(ThingModelMessage msg) { + for (DeviceCondition condition : getConditions()) { + DeviceCondition con = condition.clone(); + //未指定device,使用消息中的deviceId + if (StringUtils.isBlank(con.getDevice())) { + con.setDevice(msg.getDeviceId()); + } + + con.setDeviceInfoData(deviceInfoData); + if (!con.matches()) { + return false; + } + } + return true; + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/Filter.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/Filter.java new file mode 100644 index 0000000..4429138 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/filter/Filter.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.filter; + +import cc.iotkit.common.thing.ThingModelMessage; + +import java.util.List; + +/** + * 场景过滤器 + */ +public interface Filter { + + String getType(); + + List getConditions(); + + void init(); + + boolean execute(ThingModelMessage msg); +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/DeviceMessageHandler.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/DeviceMessageHandler.java new file mode 100644 index 0000000..b87f95f --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/DeviceMessageHandler.java @@ -0,0 +1,33 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.handler; + + +import cc.iotkit.common.thing.ThingModelMessage; + +public interface DeviceMessageHandler { + + void handle(ThingModelMessage message); + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/RuleDeviceConsumer.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/RuleDeviceConsumer.java new file mode 100644 index 0000000..e76b53c --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/RuleDeviceConsumer.java @@ -0,0 +1,84 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.handler; + + +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.ThreadUtil; +import cc.iotkit.mq.ConsumerHandler; +import cc.iotkit.mq.MqConsumer; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ScheduledThreadPoolExecutor; + +@Slf4j +public class RuleDeviceConsumer implements ConsumerHandler, ApplicationContextAware { + + private final List handlers = new ArrayList<>(); + private ScheduledThreadPoolExecutor messageHandlerPool; + + @SneakyThrows + public RuleDeviceConsumer(MqConsumer consumer) { + consumer.consume(Constants.THING_MODEL_MESSAGE_TOPIC, this); + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + Map handlerMap = applicationContext.getBeansOfType(DeviceMessageHandler.class); + messageHandlerPool = ThreadUtil.newScheduled(handlerMap.size() * 2, "messageHandler"); + this.handlers.addAll(handlerMap.values()); + } + + @SneakyThrows + @Override + public void handler(ThingModelMessage msg) { + log.info("received thing model message:{}", msg); + try { + for (DeviceMessageHandler handler : this.handlers) { + messageHandlerPool.submit(() -> { + try { + if (!(msg.getData() instanceof Map)) { + msg.setData(new HashMap<>()); + } + handler.handle(msg); + } catch (Throwable e) { + log.error("handler message error", e); + } + }); + } + } catch (Throwable e) { + log.error("rule device message process error", e); + } + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DeviceConfigHandler.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DeviceConfigHandler.java new file mode 100644 index 0000000..38a4d05 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DeviceConfigHandler.java @@ -0,0 +1,70 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.handler.sys; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.thing.ThingService; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.data.manager.IDeviceConfigData; +import cc.iotkit.model.device.DeviceConfig; +import cc.iotkit.ruleengine.handler.DeviceMessageHandler; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Map; + +/** + * 设备配置服务 + */ +@Slf4j +@Service +public class DeviceConfigHandler implements DeviceMessageHandler { + + @Autowired + private IDeviceConfigData deviceConfigData; + + @Override + public void handle(ThingModelMessage msg) { + String identifier = msg.getIdentifier(); + if (!ThingModelMessage.ID_CONFIG_GET.equals(identifier)) { + return; + } + //收到设备获取配置消息,回复配置信息给设备 + DeviceConfig deviceConfig = deviceConfigData.findByDeviceId(msg.getDeviceId()); + if (deviceConfig == null) { + return; + } + + Map config = JsonUtils.parseObject(deviceConfig.getConfig(), Map.class); + ThingService service = ThingService.builder() + .productKey(msg.getProductKey()) + .deviceName(msg.getDeviceName()) + .identifier(ThingModelMessage.ID_CONFIG_GET + "_reply") + .type(ThingModelMessage.TYPE_CONFIG) + .mid(msg.getMid()) + .params(config) + .build(); + //todo 下发 + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DeviceMessageLogHandler.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DeviceMessageLogHandler.java new file mode 100644 index 0000000..0cf63ea --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DeviceMessageLogHandler.java @@ -0,0 +1,49 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.handler.sys; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.ruleengine.handler.DeviceMessageHandler; +import cc.iotkit.temporal.IThingModelMessageData; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +/** + * @author sjg + */ +@Slf4j +@Component +public class DeviceMessageLogHandler implements DeviceMessageHandler { + @Lazy + @Autowired + private IThingModelMessageData thingModelMessageData; + + @Override + public void handle(ThingModelMessage msg) { + //设备消息入库 + thingModelMessageData.add(msg); + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DevicePropertyHandler.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DevicePropertyHandler.java new file mode 100644 index 0000000..10efbac --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DevicePropertyHandler.java @@ -0,0 +1,158 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.handler.sys; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IThingModelData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.message.DevicePropertyCache; +import cc.iotkit.model.product.ThingModel; +import cc.iotkit.ruleengine.handler.DeviceMessageHandler; +import cc.iotkit.temporal.IDevicePropertyData; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 设备属性消息消费入库 + */ +@Slf4j +@Component +public class DevicePropertyHandler implements DeviceMessageHandler { + + @Autowired + private IDevicePropertyData devicePropertyData; + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + @Autowired + @Qualifier("thingModelDataCache") + private IThingModelData thingModelData; + + @Override + public void handle(ThingModelMessage msg) { + if (!ThingModelMessage.TYPE_PROPERTY.equals(msg.getType())) { + return; + } + if (!ThingModelMessage.ID_PROPERTY_REPORT.equals(msg.getIdentifier())) { + return; + } + + if (!(msg.getData() instanceof Map)) { + return; + } + + Map properties = (Map) msg.getData(); + String deviceId = msg.getDeviceId(); + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(deviceId); + if (deviceInfo == null) { + return; + } + + //物模型校验,过滤非物模型属性 + ThingModel thingModel = thingModelData.findByProductKey(deviceInfo.getProductKey()); + if (thingModel == null) { + return; + } + + //物模型属性 + Map thingModelProperties = thingModel.getModel(). + getProperties().stream().collect(Collectors.toMap( + ThingModel.Property::getIdentifier, ThingModel.Property::getDataType)); + + Map addProperties = new HashMap<>(); + Long occurred = msg.getOccurred(); + if (occurred == null) { + occurred = System.currentTimeMillis(); + } + + //删除非属性字段 + Long finalOccurred = occurred; + properties.forEach((key, val) -> { + if (thingModelProperties.containsKey(key)) { + DevicePropertyCache propertyCache = new DevicePropertyCache(); + propertyCache.setValue(val); + propertyCache.setOccurred(finalOccurred); + addProperties.put(key, propertyCache); + handleLocate(deviceInfo, val, thingModelProperties.get(key)); + } + }); + + //更新设备当前属性 + updateDeviceCurrentProperties(deviceId, addProperties); + + //保存属性记录 + devicePropertyData.addProperties(deviceId, addProperties, occurred); + } + + + private void handleLocate(DeviceInfo deviceInfo, Object data, ThingModel.DataType dataType) { + if (!"position".equals(dataType.getType())) { + return; + } + //如果是定位属性需要做一些处理 + Object specs = dataType.getSpecs(); + String locateType = ""; + if (specs instanceof Map) { + Object objlocateType = ((Map) specs).get("locateType"); + //定位方式 + if (objlocateType != null) { + locateType = objlocateType.toString(); + } + if (StringUtils.isBlank(locateType)) { + return; + } + if ("lonLat".equals(locateType)) { + //经纬度定位格式:经度,纬度 + String[] lonLats = data.toString().split(","); + deviceInfo.getLocate().setLongitude(lonLats[0]); + deviceInfo.getLocate().setLatitude(lonLats[1]); + deviceInfoData.save(deviceInfo); + } else if ("basestation".equals(locateType)) { + //基站定位 + } else if ("ipinfo".equals(locateType)) { + //ip定位 + } + } + } + + /** + * 更新设备当前属性 + */ + private void updateDeviceCurrentProperties(String deviceId, Map properties) { + try { + log.info("save device property,deviceId:{},property:{}", deviceId, JsonUtils.toJsonString(properties)); + deviceInfoData.saveProperties(deviceId, properties); + } catch (Throwable e) { + log.error("save device current properties error", e); + } + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DeviceStateCheckHandler.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DeviceStateCheckHandler.java new file mode 100644 index 0000000..4eb1aef --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/handler/sys/DeviceStateCheckHandler.java @@ -0,0 +1,100 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.handler.sys; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.UniqueIdUtil; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.plugin.core.thing.actions.DeviceState; +import cc.iotkit.plugin.core.thing.actions.up.DeviceStateChange; +import cc.iotkit.ruleengine.handler.DeviceMessageHandler; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; +import cc.iotkit.plugin.core.thing.IThingService; + +/** + * 设备状态检查 + */ +@Slf4j +@Component +public class DeviceStateCheckHandler implements DeviceMessageHandler { + + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + + @Autowired + private IThingService thingService; + + @Override + public void handle(ThingModelMessage msg) { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(msg.getDeviceId()); + if (deviceInfo == null) { + return; + } + + String identifier = msg.getIdentifier(); + String type = msg.getType(); + + //过滤下行消息 + if (ThingModelMessage.TYPE_PROPERTY.equals(type)) { + if (ThingModelMessage.ID_PROPERTY_SET.equals(identifier) + || ThingModelMessage.ID_PROPERTY_GET.equals(identifier) + ) { + return; + } + } + + //过滤服务下发消息 + if (ThingModelMessage.TYPE_SERVICE.equals(type) && !identifier.endsWith("_reply")) { + return; + } + + //过滤oat消息 + if (ThingModelMessage.TYPE_CONFIG.equals(type) || + ThingModelMessage.TYPE_OTA.equals(type) || + ThingModelMessage.TYPE_LIFETIME.equals(type) || + ThingModelMessage.TYPE_STATE.equals(type) + ) { + return; + } + + // 如果在线,则不处理 + if( deviceInfo.getState().isOnline() ) { + return; + } + + // 其他消息, 发送设备在线物模型消息 + thingService.post("NONE", DeviceStateChange.builder() + .id(UniqueIdUtil.newRequestId()) + .productKey(deviceInfo.getProductKey()) + .deviceName(deviceInfo.getDeviceName()) + .state(DeviceState.ONLINE) + .time(System.currentTimeMillis()) + .build()); + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/BaseSinkLink.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/BaseSinkLink.java new file mode 100644 index 0000000..08f9f35 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/BaseSinkLink.java @@ -0,0 +1,58 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.link; + +import java.util.Map; +import java.util.function.Consumer; + +/** + * @author huangwenl + * @date 2022-11-10 + */ +public interface BaseSinkLink { + + /** + * 建立连接 + * @param config 连接配置信息 + */ + boolean open(Map config); + + /** + * 发送消息 + * @param msg 消息内容 + * @param consumer 发送回调 + */ + void send(Map msg, Consumer consumer); + + /** + * 关闭连接 + */ + void close(); + + /** + * 连接监听 + * @param closeHandler + */ + void closeHandler(Consumer closeHandler); +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/LinkFactory.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/LinkFactory.java new file mode 100644 index 0000000..d5d2974 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/LinkFactory.java @@ -0,0 +1,173 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.link; + +import cc.iotkit.common.utils.FIUtil; +import cc.iotkit.ruleengine.link.impl.KafkaLink; +import cc.iotkit.ruleengine.link.impl.MqttClientLink; +import cc.iotkit.ruleengine.link.impl.TcpClientLink; +import lombok.extern.slf4j.Slf4j; + +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; + +/** + * @author huangwenl + * @date 2022-11-10 + */ +@Slf4j +public class LinkFactory { + + private static final Map linkMap = new ConcurrentHashMap<>(); + private static final Map> ruleLink = new ConcurrentHashMap<>(); + + /** + * 发送消息前,初始化连接 + * + * @param key 连接标识 + * @param type 连接类型 + * @param config 连接配置 + * @return + */ + public static boolean initLink(String key, String type, Map config) { + AtomicBoolean exist = new AtomicBoolean(false); + FIUtil.isTotF(linkMap.containsKey(key)).handler( + () -> exist.set(true), + () -> exist.set(buildLink(key, type, config)) + ); + return exist.get(); + } + + /** + * 启动规则时,初始化连接 + * + * @param ruleId + * @param ruleId 规则ID + * @param key 连接标识 + * @param type 连接类型 + * @param config 连接配置 + * @return + */ + public static boolean initLink(String ruleId, String key, String type, Map config) { + boolean result = initLink(key, type, config); + if (result) { + Set linkKeys = Optional.ofNullable(ruleLink.get(ruleId)).orElse(new HashSet<>()); + linkKeys.add(key); + ruleLink.put(ruleId, linkKeys); + } + return result; + } + + /** + * 注册连接 + * + * @param key 连接标识 + * @param link 连接 + */ + public static void register(String key, BaseSinkLink link) { + log.info("连接器{}注册连接", key); + linkMap.put(key, link); + + link.closeHandler(Void -> { + linkMap.remove(key); + log.info("连接器{}断开连接", key); + }); + } + + /** + * 发送消息 + * + * @param key 连接标识 + * @param msg 消息 + * @param consumer 发送回调 + */ + public static void sendMsg(String key, Map msg, Consumer consumer) { + try { + BaseSinkLink sinkLink = linkMap.get(key); + FIUtil.isTotF(sinkLink != null).handler(() -> sinkLink.send(msg, consumer), + () -> consumer.accept(String.format("key:%s, 没有连接!", key))); + } catch (Exception e) { + e.printStackTrace(); + consumer.accept(String.format("key:%s,发送异常:%s", key, e.getMessage())); + } + + } + + /** + * 停用规则 + * + * @param ruleId + */ + public static void ruleClose(String ruleId) { + Set linkKeys = ruleLink.remove(ruleId); + // 排除其他规则也在用这个 link的 + if (linkKeys != null && !linkKeys.isEmpty()) { + Set existKey = new HashSet<>(); + ruleLink.forEach((key, value) -> existKey.addAll(value)); + linkKeys.removeAll(existKey); + linkKeys.forEach(LinkFactory::close); + } + } + + /** + * 关闭连接 + * + * @param key + */ + public static void close(String key) { + BaseSinkLink link = linkMap.get(key); + if (link != null) { + link.close(); + } + } + + private static boolean buildLink(String key, String type, Map conf) { + boolean success = false; + BaseSinkLink link = null; + switch (type) { + case MqttClientLink.LINK_TYPE: + link = new MqttClientLink(); + break; + case KafkaLink.LINK_TYPE: + link = new KafkaLink(); + break; + case TcpClientLink.LINK_TYPE: + link = new TcpClientLink(); + break; + } + if (link != null) { + success = link.open(conf); + } + if (success) { + register(key, link); + } + return success; + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/LinkService.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/LinkService.java new file mode 100644 index 0000000..0710eb5 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/LinkService.java @@ -0,0 +1,43 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.link; + +import java.util.Map; + +/** + * @author huangwenl + * @date 2022-11-11 + */ +public interface LinkService { + + default boolean initLink(String ruleId) { + return LinkFactory.initLink(ruleId, getKey(), getLinkType(), getLinkConf()); + } + + String getKey(); + + String getLinkType(); + + Map getLinkConf(); +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/impl/KafkaLink.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/impl/KafkaLink.java new file mode 100644 index 0000000..8e63430 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/impl/KafkaLink.java @@ -0,0 +1,120 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.link.impl; + +import cc.iotkit.common.utils.FIUtil; +import cc.iotkit.ruleengine.link.BaseSinkLink; +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import io.vertx.kafka.client.producer.KafkaProducer; +import io.vertx.kafka.client.producer.KafkaProducerRecord; +import lombok.extern.slf4j.Slf4j; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.common.serialization.StringSerializer; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; + +/** + * kafka 连接器 + * 支持自定义topic 和 分区, ack + * k-v 只支持String + * + * @author huangwenl + * @date 2022-11-11 + */ +@Slf4j +public class KafkaLink implements BaseSinkLink { + public static final String LINK_TYPE = "kafka"; + public static final String TOPIC = "topic"; + public static final String PAYLOAD = "payload"; + public static final String PARTITION = "partition"; + + public static final String SERVERS = "servers"; + public static final String ACK = "ack"; + + private KafkaProducer producer; + private Consumer closeHandler; + + @Override + public boolean open(Map config) { + try { + AtomicReference vertx = new AtomicReference<>(); + FIUtil.isTotF(Vertx.currentContext() == null).handler( + () -> vertx.set(Vertx.vertx()), + () -> vertx.set(Vertx.currentContext().owner()) + ); + Map kafkaConfig = new HashMap<>(); + kafkaConfig.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, (String) config.get(SERVERS)); + kafkaConfig.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); + kafkaConfig.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); + kafkaConfig.put(ProducerConfig.ACKS_CONFIG, (String) config.get(ACK)); + producer = KafkaProducer.create(vertx.get(), kafkaConfig); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + @Override + public void send(Map msg, Consumer consumer) { + AtomicReference> record = new AtomicReference<>(); + FIUtil.isTotF(msg.containsKey(PARTITION)).handler( + () -> record.set(KafkaProducerRecord.create((String) msg.get(TOPIC), "", msg.get(PAYLOAD).toString(), (Integer) msg.get(PARTITION))), + () -> record.set(KafkaProducerRecord.create((String) msg.get(TOPIC), msg.get(PAYLOAD).toString()))); + // 同步等待结果 + try { + Future write = producer.write(record.get()); + write.toCompletionStage().toCompletableFuture().get(); + FIUtil.isTotF(write.succeeded()).handler( + () -> consumer.accept(String.format("kafka,topic[%s],发送成功:%s", msg.get(TOPIC), msg.get(PAYLOAD).toString())), + () -> consumer.accept(String.format("kafka,topic[%s],发送失败:%s", msg.get(TOPIC), msg.get(PAYLOAD).toString())) + ); + } catch (Exception e) { + e.printStackTrace(); + log.error("kafka,topic[{}],发送异常:{}", msg.get(TOPIC), msg.get(PAYLOAD).toString(), e); + consumer.accept(String.format("kafka,topic[%s],发送异常:%s", msg.get(TOPIC), msg.get(PAYLOAD).toString())); + } + + } + + @Override + public void close() { + try { + producer.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + closeHandler.accept(null); + } + } + + @Override + public void closeHandler(Consumer consumer) { + this.closeHandler = consumer; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/impl/MqttClientLink.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/impl/MqttClientLink.java new file mode 100644 index 0000000..40e6540 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/impl/MqttClientLink.java @@ -0,0 +1,136 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.link.impl; + +import cc.iotkit.common.utils.FIUtil; +import cc.iotkit.ruleengine.link.BaseSinkLink; +import io.netty.handler.codec.mqtt.MqttQoS; +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import io.vertx.core.buffer.Buffer; +import io.vertx.mqtt.MqttClient; +import io.vertx.mqtt.MqttClientOptions; +import lombok.extern.slf4j.Slf4j; + +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; + +/** + * @author huangwenl + * @date 2022-11-10 + */ +@Slf4j +public class MqttClientLink implements BaseSinkLink { + public static final String LINK_TYPE = "mqtt"; + public static final String TOPIC = "topic"; + public static final String PASSWORD = "password"; + public static final String USERNAME = "username"; + public static final String HOST = "host"; + public static final String PORT = "port"; + public static final String PAYLOAD = "payload"; + + private MqttClient mqttClient; + private Consumer closeHandler; + private MqttClientOptions clientOptions; + private String host; + private int port; + private boolean connecting; + + + @Override + public boolean open(Map config) { + try { + AtomicReference vertx = new AtomicReference<>(); + FIUtil.isTotF(Vertx.currentContext() == null).handler( + () -> vertx.set(Vertx.vertx()), + () -> vertx.set(Vertx.currentContext().owner()) + ); + clientOptions = new MqttClientOptions(); + clientOptions.setUsername((String) config.get(USERNAME)); + clientOptions.setPassword((String) config.get(PASSWORD)); + mqttClient = MqttClient.create(vertx.get(), clientOptions); + host = (String) config.get(HOST); + port = (int) config.get(PORT); + mqttClient = MqttClient.create(vertx.get(), clientOptions); + connecting = true; + mqttClient.connect(port, host, + s -> { + connecting = false; + if (!s.succeeded()) { + closeHandler.accept(null); + } + }); + } catch (Exception e) { + e.printStackTrace(); + connecting = false; + return false; + } + return true; + } + + @Override + public void send(Map msg, Consumer consumer) { + FIUtil.isTotF(mqttClient.isConnected()).handler( + () -> { + Future publish = mqttClient.publish((String) msg.get(TOPIC), + Buffer.buffer(msg.get(PAYLOAD).toString()), + MqttQoS.AT_MOST_ONCE, false, false); + try { + publish.toCompletionStage().toCompletableFuture().get(); + FIUtil.isTotF(publish.succeeded()).handler( + () -> consumer.accept(String.format("mqtt,topic[%s],发送成功:%s", msg.get(TOPIC), msg.get(PAYLOAD).toString())), + () -> consumer.accept(String.format("mqtt,topic[%s],发送失败:%s", msg.get(TOPIC), msg.get(PAYLOAD).toString())) + ); + } catch (Exception e) { + e.printStackTrace(); + consumer.accept(String.format("mqtt,topic[%s],发送异常:%s", msg.get(TOPIC), msg.get(PAYLOAD).toString())); + } + }, + () -> { + consumer.accept("mqtt,连接断开,发送失败"); + if (!connecting) { + log.info("mqtt重连!"); + connecting = true; + mqttClient.connect(port, host, s -> connecting = false); + } + }); + } + + @Override + public void close() { + try { + mqttClient.disconnect(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + closeHandler.accept(null); + } + } + + @Override + public void closeHandler(Consumer consumer) { + this.closeHandler = consumer; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/impl/TcpClientLink.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/impl/TcpClientLink.java new file mode 100644 index 0000000..c83cb77 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/link/impl/TcpClientLink.java @@ -0,0 +1,142 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.ruleengine.link.impl; + +import cc.iotkit.common.utils.FIUtil; +import cc.iotkit.ruleengine.link.BaseSinkLink; +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import io.vertx.core.buffer.Buffer; +import io.vertx.core.net.NetClient; +import io.vertx.core.net.NetClientOptions; +import io.vertx.core.net.NetSocket; +import lombok.extern.slf4j.Slf4j; + +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; + +/** + * @author huangwenl + * @date 2022-12-14 + */ +@Slf4j +public class TcpClientLink implements BaseSinkLink { + public static final String LINK_TYPE = "tcp"; + public static final String HOST = "host"; + public static final String PORT = "port"; + public static final String PAYLOAD = "payload"; + + private Consumer closeHandler; + private NetClient client; + private NetSocket socket; + private String host; + private int port; + private boolean connecting; + private boolean normal; + + @Override + public boolean open(Map config) { + try { + AtomicReference vertx = new AtomicReference<>(); + FIUtil.isTotF(Vertx.currentContext() == null).handler( + () -> vertx.set(Vertx.vertx()), + () -> vertx.set(Vertx.currentContext().owner()) + ); + NetClientOptions options = new NetClientOptions().setConnectTimeout(10000); + client = vertx.get().createNetClient(options); + port = (int) config.get(PORT); + host = (String) config.get(HOST); + connecting = true; + client.connect(port, host, res -> { + connecting = false; + if (res.succeeded()) { + log.info("连接成功:{}, {}", port,host); + socket = res.result(); + normal = true; + socket.closeHandler(Void -> normal = false); + } else { + closeHandler.accept(null); + log.info("连接失败:{}, {}", port,host); + } + }); + } catch (Exception e) { + e.printStackTrace(); + connecting = false; + return false; + } + return true; + } + + @Override + public void send(Map msg, Consumer consumer) { + FIUtil.isTotF(normal).handler( + () -> { + Future publish = socket.write(Buffer.buffer(msg.get(PAYLOAD).toString())); + try { + publish.toCompletionStage().toCompletableFuture().get(300L, TimeUnit.MILLISECONDS); + FIUtil.isTotF(publish.succeeded()).handler( + () -> consumer.accept(String.format("tcp,发送成功:%s", msg.get(PAYLOAD).toString())), + () -> consumer.accept(String.format("tcp,发送失败:%s", msg.get(PAYLOAD).toString())) + ); + } catch (Exception e) { + e.printStackTrace(); + consumer.accept(String.format("tcp,发送异常:%s", msg.get(PAYLOAD).toString())); + } + }, + () -> { + consumer.accept("tcp,连接断开,发送失败"); + if (!connecting) { + log.info("tcp重连!"); + connecting = true; + client.connect(port, host, res -> { + connecting = false; + if (res.succeeded()) { + log.info("连接成功:{}, {}", port,host); + socket = res.result(); + normal = true; + socket.closeHandler(Void -> normal = false); + } + }); + } + }); + } + + @Override + public void close() { + try { + socket.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + closeHandler.accept(null); + } + } + + @Override + public void closeHandler(Consumer consumer) { + this.closeHandler = consumer; + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java new file mode 100644 index 0000000..c85361c --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceCondition.java @@ -0,0 +1,87 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.listener; + +import cc.iotkit.ruleengine.expression.Expression; +import lombok.Data; +import org.apache.commons.lang3.StringUtils; + +import java.util.List; +import java.util.Map; + +@Data +public class DeviceCondition { + + private String type; + + private String device; + + private String identifier; + + private List parameters; + + public boolean matches(String type, String identifier, Map parameter) { + if (!this.type.equals(type)) { + return false; + } + //通配规则,不需要判断其它条件 + if (this.identifier.endsWith(":*")) { + return true; + } + if (!this.identifier.equals(identifier)) { + return false; + } + for (Parameter p : this.parameters) { + if (!p.matches(parameter)) { + return false; + } + } + return true; + } + + @Data + public static class Parameter { + private String identifier; + private Object value; + private String comparator; + + public boolean matches(Map parameter) { + //任意匹配 + if ("*".equals(identifier)) { + return true; + } + + //存在参数或无参数条件,值任意匹配 + if ((StringUtils.isBlank(identifier) || parameter.containsKey(identifier)) + && "*".equals(comparator)) { + return true; + } + + Object left = parameter.get(identifier); + if (left == null) { + return false; + } + return Expression.eval(comparator, left, value); + } + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceListener.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceListener.java new file mode 100644 index 0000000..7a54a40 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/DeviceListener.java @@ -0,0 +1,79 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.listener; + +import cc.iotkit.common.thing.ThingModelMessage; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; +import java.util.Map; + +@Slf4j +@Data +public class DeviceListener implements Listener { + + public static final String TYPE = "device"; + + private String type; + + private String pk; + + private String dn; + + private List conditions; + + @Override + public String getType() { + return TYPE; + } + + @Override + public boolean execute(ThingModelMessage message) { + String identifier = message.getIdentifier(); + Map mapData = message.dataToMap(); + String pk = message.getProductKey(); + String dn = message.getDeviceName(); + for (DeviceCondition condition : this.conditions) { + String condPkDn = condition.getDevice(); + String[] pkAndDn = condPkDn.split("/"); + String condPk = pkAndDn[0]; + String condDn = pkAndDn[1]; + //判断产品是否匹配 + if (!pk.equals(condPk)) { + continue; + } + //判断设备是否匹配 + if (!"#".equals(condDn) && !dn.equals(condDn)) { + continue; + } + + if (condition.matches(message.getType(), identifier, mapData)) { + return true; + } + } + + return false; + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/Listener.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/Listener.java new file mode 100644 index 0000000..9e4d511 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/listener/Listener.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.listener; + +import cc.iotkit.common.thing.ThingModelMessage; + +import java.util.List; + +public interface Listener { + + String getType(); + + List getConditions(); + + boolean execute(ThingModelMessage msg); +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/Rule.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/Rule.java new file mode 100644 index 0000000..1044320 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/Rule.java @@ -0,0 +1,49 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.rule; + +import cc.iotkit.ruleengine.action.Action; +import cc.iotkit.ruleengine.filter.Filter; +import cc.iotkit.ruleengine.listener.Listener; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Rule { + + private String id; + + private String name; + + private List> listeners; + + private List> filters; + + private List> actions; + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleExecutor.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleExecutor.java new file mode 100644 index 0000000..a89fb5e --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleExecutor.java @@ -0,0 +1,119 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.rule; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.model.rule.RuleLog; +import cc.iotkit.ruleengine.action.Action; +import cc.iotkit.ruleengine.filter.Filter; +import cc.iotkit.ruleengine.listener.Listener; +import cc.iotkit.temporal.IRuleLogData; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * 规则执行器 + */ +@Component +@Slf4j +public class RuleExecutor { + + @Lazy + @Autowired + private IRuleLogData ruleLogData; + + public void execute(ThingModelMessage message, Rule rule) { + if (!doListeners(message, rule)) { + log.info("The listener did not match the appropriate content,rule:{},{}", rule.getId(), rule.getName()); + return; + } + log.info("Start execute rule {},id:{}", rule.getName(), rule.getId()); + + RuleLog ruleLog = new RuleLog(); + ruleLog.setId(UUID.randomUUID().toString()); + ruleLog.setRuleId(rule.getId()); + ruleLog.setState(RuleLog.STATE_MATCHED_LISTENER); + + try { + if (!doFilters(rule, message)) { + ruleLog.setState(RuleLog.STATE_UNMATCHED_FILTER); + log.info("The filter did not match the appropriate content,rule:{},{}", rule.getId(), rule.getName()); + return; + } + ruleLog.setState(RuleLog.STATE_MATCHED_FILTER); + + //执行动作返回执行内容 + List results = doActions(rule, message); + //保存动作内容和状态 + ruleLog.setContent(JsonUtils.toJsonString(results)); + ruleLog.setState(RuleLog.STATE_EXECUTED_ACTION); + ruleLog.setSuccess(true); + log.info("rule execution completed,id:{}", rule.getId()); + } catch (Throwable e) { + log.error("rule execution error,id:" + rule.getId(), e); + ruleLog.setSuccess(false); + ruleLog.setContent(e.toString()); + } finally { + ruleLog.setLogAt(System.currentTimeMillis()); + ruleLogData.add(ruleLog); + } + } + + private boolean doListeners(ThingModelMessage message, Rule rule) { + List> listeners = rule.getListeners(); + for (Listener listener : listeners) { + if (listener.execute(message)) { + //只要有一个监听器匹配到数据即可 + return true; + } + } + return false; + } + + private boolean doFilters(Rule rule, ThingModelMessage msg) { + List> filters = rule.getFilters(); + for (Filter filter : filters) { + //只要有一个过滤器未通过都不算通过 + if (!filter.execute(msg)) { + return false; + } + } + return true; + } + + private List doActions(Rule rule, ThingModelMessage msg) { + List results = new ArrayList<>(); + for (Action action : rule.getActions()) { + results.addAll(action.execute(msg)); + } + return results; + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java new file mode 100644 index 0000000..c6022a5 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleManager.java @@ -0,0 +1,304 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.rule; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.manager.*; +import cc.iotkit.message.model.Message; +import cc.iotkit.message.service.MessageService; +import cc.iotkit.model.alert.AlertConfig; +import cc.iotkit.model.notify.Channel; +import cc.iotkit.model.notify.ChannelConfig; +import cc.iotkit.model.notify.ChannelTemplate; +import cc.iotkit.model.rule.FilterConfig; +import cc.iotkit.model.rule.RuleAction; +import cc.iotkit.model.rule.RuleInfo; +import cc.iotkit.ruleengine.action.Action; +import cc.iotkit.ruleengine.action.alert.AlertAction; +import cc.iotkit.ruleengine.action.alert.AlertService; +import cc.iotkit.ruleengine.action.device.DeviceAction; +import cc.iotkit.ruleengine.action.device.DeviceActionService; +import cc.iotkit.ruleengine.action.http.HttpAction; +import cc.iotkit.ruleengine.action.http.HttpService; +import cc.iotkit.ruleengine.action.kafka.KafkaAction; +import cc.iotkit.ruleengine.action.kafka.KafkaService; +import cc.iotkit.ruleengine.action.mqtt.MqttAction; +import cc.iotkit.ruleengine.action.mqtt.MqttService; +import cc.iotkit.ruleengine.action.tcp.TcpAction; +import cc.iotkit.ruleengine.action.tcp.TcpService; +import cc.iotkit.ruleengine.config.RuleConfiguration; +import cc.iotkit.ruleengine.filter.DeviceFilter; +import cc.iotkit.ruleengine.filter.Filter; +import cc.iotkit.ruleengine.link.LinkFactory; +import cc.iotkit.ruleengine.listener.DeviceCondition; +import cc.iotkit.ruleengine.listener.DeviceListener; +import cc.iotkit.ruleengine.listener.Listener; +import cn.hutool.core.collection.CollectionUtil; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +@Component +@Slf4j +public class RuleManager { + + @Autowired + private RuleConfiguration ruleConfiguration; + + @Autowired + private RuleMessageHandler ruleMessageHandler; + + @Autowired + private IRuleInfoData ruleInfoData; + + @Autowired + @Qualifier("deviceInfoPropertyDataCache") + private IDeviceInfoData deviceInfoData; + + @Autowired + private DeviceActionService deviceActionService; + + @Autowired + private IAlertConfigData alertConfigData; + + @Autowired + private IChannelTemplateData channelTemplateData; + + @Autowired + private IChannelConfigData channelConfigData; + + @Autowired + private IChannelData channelData; + + @Autowired + private MessageService messageService; + + public RuleManager() { + ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); + executorService.schedule(this::initRules, 1, TimeUnit.SECONDS); + } + + @SneakyThrows + public void initRules() { + int idx = 1; + while (true) { + PageRequest pageRequest = new PageRequest<>(); + pageRequest.setPageNum(idx); + pageRequest.setPageSize(100); + Paging all = ruleInfoData.findAll(pageRequest); + List rules = all.getRows(); + if (CollectionUtil.isEmpty(rules)) { + return; + } + rules.forEach(rule -> { + try { + //不添加停止的规则 + if (RuleInfo.STATE_STOPPED.equals(rule.getState())) { + return; + } + log.info("got rule {} to init", rule.getId()); + add(rule); + } catch (Throwable e) { + log.error("add rule error", e); + } + }); + idx++; + } + } + + public void add(RuleInfo ruleInfo) { + if(RuleInfo.STATE_STOPPED.equals(ruleInfo.getState())){ + return; + } + Rule rule = parseRule(ruleInfo); + ruleMessageHandler.putRule(rule); + } + + public void remove(String ruleId) { + ruleMessageHandler.removeRule(ruleId); + // 移出link连接 + LinkFactory.ruleClose(ruleId); + } + + public void pause(String ruleId) { + remove(ruleId); + } + + public void resume(RuleInfo ruleInfo) { + add(ruleInfo); + } + + private Rule parseRule(RuleInfo ruleInfo) { + List> listeners = new ArrayList<>(); + for (FilterConfig listener : ruleInfo.getListeners()) { + if (StringUtils.isBlank(listener.getConfig())) { + continue; + } + listeners.add(parseListener(listener.getType(), listener.getConfig())); + } + + List> filters = new ArrayList<>(); + for (FilterConfig filter : ruleInfo.getFilters()) { + if (StringUtils.isBlank(filter.getConfig())) { + continue; + } + filters.add(parseFilter(filter.getType(), filter.getConfig())); + } + + List> actions = new ArrayList<>(); + for (RuleAction action : ruleInfo.getActions()) { + if (StringUtils.isBlank(action.getConfig())) { + continue; + } + actions.add(parseAction(ruleInfo.getId(), action.getType(), action.getConfig())); + } + + return new Rule(ruleInfo.getId(), ruleInfo.getName(), listeners, filters, actions); + } + + private Listener parseListener(String type, String config) { + if (DeviceListener.TYPE.equals(type)) { + DeviceListener listener = parse(config, DeviceListener.class); + for (DeviceCondition condition : listener.getConditions()) { + String dn = "#"; + if (StringUtils.isNotBlank(listener.getDn())) { + dn = listener.getDn(); + } + condition.setDevice(listener.getPk() + "/" + dn); + } + return listener; + } + return null; + } + + private Filter parseFilter(String type, String config) { + if (DeviceFilter.TYPE.equals(type)) { + DeviceFilter filter = parse(config, DeviceFilter.class); + for (cc.iotkit.ruleengine.filter.DeviceCondition condition : filter.getConditions()) { + String dn = "#"; + if (StringUtils.isNotBlank(filter.getDn())) { + dn = filter.getDn(); + } + condition.setDevice(filter.getPk() + "/" + dn); + } + filter.setDeviceInfoData(deviceInfoData); + return filter; + } + return null; + } + + private Action parseAction(String ruleId, String type, String config) { + if (DeviceAction.TYPE.equals(type)) { + DeviceAction action = parse(config, DeviceAction.class); + action.setDeviceActionService(deviceActionService); + return action; + } else if (HttpAction.TYPE.equals(type)) { + HttpAction httpAction = parse(config, HttpAction.class); + for (HttpService service : httpAction.getServices()) { + service.setDeviceInfoData(deviceInfoData); + } + return httpAction; + } else if (MqttAction.TYPE.equals(type)) { + MqttAction mqttAction = parse(config, MqttAction.class); + for (MqttService service : mqttAction.getServices()) { + service.setDeviceInfoData(deviceInfoData); + service.initLink(ruleId); + } + return mqttAction; + } else if (KafkaAction.TYPE.equals(type)) { + KafkaAction kafkaAction = parse(config, KafkaAction.class); + for (KafkaService service : kafkaAction.getServices()) { + service.setDeviceInfoData(deviceInfoData); + service.initLink(ruleId); + } + return kafkaAction; + } else if (TcpAction.TYPE.equals(type)) { + TcpAction tcpAction = parse(config, TcpAction.class); + for (TcpService service : tcpAction.getServices()) { + service.setDeviceInfoData(deviceInfoData); + service.initLink(ruleId); + } + return tcpAction; + } else if (AlertAction.TYPE.equals(type)) { + List alertConfigs = alertConfigData.findAllByCondition(AlertConfig.builder() + .ruleInfoId(ruleId) + .build()); + + AlertAction alertAction = parse(config, AlertAction.class); + String script = alertAction.getServices().get(0).getScript(); + + List alertServices = new ArrayList<>(); + for (AlertConfig alertConfig : alertConfigs) { + if (alertConfig.getEnable() != null && !alertConfig.getEnable()) { + continue; + } + + AlertService service = new AlertService(); + service.setScript(script); + service.setDeviceInfoData(deviceInfoData); + service.setMessageService(messageService); + + ChannelTemplate channelTemplate = channelTemplateData.findById(alertConfig.getMessageTemplateId()); + Long channelConfigId = channelTemplate.getChannelConfigId(); + + Message message = Message.builder() + .content(channelTemplate.getContent()) + .alertConfigId(alertConfig.getId()) + .build(); + + if (channelConfigId != null) { + ChannelConfig channelConfig = channelConfigData.findById(channelTemplate.getChannelConfigId()); + Channel channel = channelData.findById(channelConfig.getChannelId()); + message.setChannel(channel.getCode()); + message.setChannelId(channel.getId()); + message.setChannelConfig(channelConfig.getParam()); + } + + service.setMessage(message); + alertServices.add(service); + } + alertAction.setServices(alertServices); + return alertAction; + } + return null; + } + + private T parse(String config, Class cls) { + return JsonUtils.parseObject(config, cls); + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleMessageHandler.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleMessageHandler.java new file mode 100644 index 0000000..027c081 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/rule/RuleMessageHandler.java @@ -0,0 +1,96 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.rule; + +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.ruleengine.handler.DeviceMessageHandler; +import cc.iotkit.ruleengine.listener.DeviceCondition; +import cc.iotkit.ruleengine.listener.Listener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component +public class RuleMessageHandler implements DeviceMessageHandler { + + private final Map> deviceRuleMap = new HashMap<>(); + + @Autowired + private RuleExecutor ruleExecutor; + + public synchronized void putRule(Rule rule) { + //先删除已经存在的规则 + removeRule(rule.getId()); + + //将同一个规则中不同device拆开存储 + for (Listener listener : rule.getListeners()) { + for (Object condition : listener.getConditions()) { + if (!(condition instanceof DeviceCondition)) { + continue; + } + String device = ((DeviceCondition) condition).getDevice(); + deviceRuleMap.putIfAbsent(device, new ArrayList<>()); + List rules = deviceRuleMap.get(device); + rules.add(rule); + } + } + } + + public synchronized void removeRule(String ruleId) { + Iterator>> iterator = deviceRuleMap.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry> entry = iterator.next(); + String device = entry.getKey(); + //找出相同场景ID的规则删除 + entry.getValue().removeIf(s -> s != null && s.getId().equals(ruleId)); + //删除空的规则列表 + if (entry.getValue().isEmpty()) { + iterator.remove(); + deviceRuleMap.remove(device); + } + } + } + + @Override + public void handle(ThingModelMessage message) { + String pk = message.getProductKey(); + String dn = message.getDeviceName(); + List rules = new ArrayList<>(); + //仅用PK匹配 + List foundRules = deviceRuleMap.get(pk + "/#"); + if (foundRules != null) { + rules.addAll(foundRules); + } + //用PK和DN匹配 + foundRules = deviceRuleMap.get(pk + "/" + dn); + if (foundRules != null) { + rules.addAll(foundRules); + } + //执行规则 + for (Rule rule : rules) { + ruleExecutor.execute(message, rule); + } + } + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/ActionExecutor.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/ActionExecutor.java new file mode 100644 index 0000000..9660d66 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/ActionExecutor.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.task; + +/** + * 动作执行器接口 + */ +public interface ActionExecutor { + + /** + * 动作名 + */ + String getName(); + + /** + * 执行动作 + */ + void execute(String data); + +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/ActionExecutorManager.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/ActionExecutorManager.java new file mode 100644 index 0000000..1851d1a --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/ActionExecutorManager.java @@ -0,0 +1,59 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.task; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +@Slf4j +@Service +public class ActionExecutorManager implements ApplicationContextAware { + + private static Map EXECUTORS = new HashMap<>(); + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + Map beans = applicationContext.getBeansOfType(ActionExecutor.class); + beans.forEach((name, bean) -> EXECUTORS.put(bean.getName(), bean)); + } + + public ActionExecutor getExecutor(String name) { + return EXECUTORS.get(name); + } + + public void execute(String name, String data) { + ActionExecutor executor = getExecutor(name); + if (executor == null) { + log.error("action executor not found by name:{}", name); + return; + } + + executor.execute(data); + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/CommonJob.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/CommonJob.java new file mode 100644 index 0000000..0b27837 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/CommonJob.java @@ -0,0 +1,69 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.task; + +import cc.iotkit.model.rule.RuleAction; +import cc.iotkit.model.rule.TaskInfo; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.quartz.Job; +import org.quartz.JobExecutionContext; + +import java.util.List; + +@Slf4j +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CommonJob implements Job { + + private ActionExecutorManager actionExecutorManager; + + private TaskManager taskManager; + + private TaskInfo taskInfo; + + @Override + public void execute(JobExecutionContext context) { + String result = ""; + boolean success = true; + try { + List actions = taskInfo.getActions(); + log.info("start execute job,task:{}", taskInfo.getId()); + for (RuleAction action : actions) { + actionExecutorManager.execute(action.getType(), action.getConfig()); + } + } catch (Throwable e) { + log.error("execute job failed", e); + result = e.getMessage(); + success = false; + } + if (TaskInfo.TYPE_DELAY.equals(taskInfo.getType())) { + taskManager.finishTask(taskInfo.getId()); + } + taskManager.addLog(taskInfo.getId(), success, result); + } + +} \ No newline at end of file diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/DeviceActionExecutor.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/DeviceActionExecutor.java new file mode 100644 index 0000000..f8c6f5a --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/DeviceActionExecutor.java @@ -0,0 +1,68 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.task; + +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.ruleengine.action.device.DeviceAction; +import cc.iotkit.ruleengine.action.device.DeviceActionService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 设备输出器 + */ +@Slf4j +@Component +public class DeviceActionExecutor implements ActionExecutor { + + @Autowired + private DeviceActionService deviceActionService; + + private Map actionMap = new ConcurrentHashMap<>(); + + @Override + public String getName() { + return "device"; + } + + @Override + public void execute(String config) { + if (StringUtils.isBlank(config)) { + log.error("device executor's config is blank"); + return; + } + //将执行的数据转换为动作配置 + Integer code = config.hashCode(); + DeviceAction action = actionMap.computeIfAbsent(code, k -> JsonUtils.parseObject(config, DeviceAction.class)); + + log.info("start device service invoke,{}", JsonUtils.toJsonString(action)); + for (DeviceActionService.Service service : action.getServices()) { + deviceActionService.invoke(service); + } + } +} diff --git a/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java new file mode 100644 index 0000000..357b787 --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/java/cc/iotkit/ruleengine/task/TaskManager.java @@ -0,0 +1,250 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.ruleengine.task; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.data.manager.ITaskInfoData; +import cc.iotkit.model.rule.TaskInfo; +import cc.iotkit.model.rule.TaskLog; +import cc.iotkit.temporal.ITaskLogData; +import cn.hutool.core.collection.CollectionUtil; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.quartz.*; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Lazy; + +import java.util.Date; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +@Slf4j +public class TaskManager implements ApplicationContextAware { + + private ApplicationContext applicationContext; + + @Autowired + private ITaskInfoData taskInfoData; + + @Lazy + @Autowired + private ITaskLogData taskLogData; + + public TaskManager() { + ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); + executorService.schedule(this::initTask, 1, TimeUnit.SECONDS); + } + + public void initTask() { + int idx = 1; + while (true) { + PageRequest pageRequest = new PageRequest<>(); + pageRequest.setPageNum(idx); + pageRequest.setPageSize(100); + Paging all = taskInfoData.findAll(pageRequest); + List tasks = all.getRows(); + // 如果记录为空,直接跳出循环 + if (CollectionUtil.isEmpty(tasks)) { + break; + } + tasks.forEach(task -> { + try { + if (!TaskInfo.STATE_RUNNING.equals(task.getState())) { + return; + } + log.info("got task {} to init", task.getId()); + addTask(task); + } catch (Throwable e) { + log.error("add task error", e); + } + }); + idx++; + } + } + + private void addTask(TaskInfo task) throws SchedulerException { + // 指明job的名称,所在组的名称,以及绑定job类 + JobDataMap jobData = new JobDataMap(); + jobData.put("taskInfo", task); + JobDetail jobDetail = JobBuilder.newJob(CommonJob.class) + .withIdentity(task.getId(), task.getUid()) + .usingJobData(jobData) + .build(); + + ScheduleBuilder scheduleBuilder = getScheduleBuilder(task); + if (scheduleBuilder == null) { + log.error("get task builder failed"); + return; + } + + // 定义调度触发规则 + Trigger trigger = TriggerBuilder.newTrigger().withIdentity(task.getId(), task.getUid())// 触发器key + .startAt(DateBuilder.futureDate(1, DateBuilder.IntervalUnit.SECOND)) + .withSchedule(scheduleBuilder) + .startNow().build(); + + // 把作业和触发器注册到任务调度中 + Scheduler scheduler = getScheduler(); + scheduler.scheduleJob(jobDetail, trigger); + + // 启动 + if (!scheduler.isShutdown()) { + scheduler.start(); + } + } + + private ScheduleBuilder getScheduleBuilder(TaskInfo task) { + if (TaskInfo.TYPE_TIMER.equals(task.getType())) { + return CronScheduleBuilder.cronSchedule(task.getExpression()); + } + if (TaskInfo.TYPE_DELAY.equals(task.getType())) { + Long delayTime = task.delayTime(); + if (delayTime == null) { + return null; + } + delayTime = System.currentTimeMillis() + delayTime * 1000; + + return DailyTimeIntervalScheduleBuilder + .dailyTimeIntervalSchedule() + .startingDailyAt(TimeOfDay.hourAndMinuteAndSecondFromDate(new Date(delayTime))) + .endingDailyAt(TimeOfDay.hourAndMinuteAndSecondFromDate(new Date(delayTime + 1000))) + .withRepeatCount(1) + ; + } + return null; + } + + public void saveTask(TaskInfo task) throws SchedulerException { + TriggerKey triggerKey = new TriggerKey(task.getId(), task.getUid()); + Trigger oldTrigger = getScheduler().getTrigger(triggerKey); + if (oldTrigger == null) { + log.warn("saveTask:trigger does not exist"); + addTask(task); + return; + } + Scheduler scheduler = getScheduler(); + scheduler.pauseTrigger(triggerKey); + scheduler.unscheduleJob(triggerKey); + scheduler.deleteJob(JobKey.jobKey(task.getId(), task.getUid())); + + addTask(task); + } + + public void renewTask(TaskInfo task) throws SchedulerException { + saveTask(task); + } + + public TaskInfo updateTaskState(String taskId, String state, String reason) { + TaskInfo taskInfo = taskInfoData.findById(taskId); + if (taskInfo == null) { + return null; + } + taskInfo.setState(state); + taskInfo.setReason(reason); + taskInfoData.save(taskInfo); + return taskInfo; + } + + public void finishTask(String taskId) { + TaskInfo taskInfo = taskInfoData.findById(taskId); + if (taskInfo == null) { + return; + } + taskInfo.setState(TaskInfo.STATE_FINISHED); + taskInfoData.save(taskInfo); + } + + @SneakyThrows + public void pauseTask(String taskId, String reason) { + TaskInfo taskInfo = updateTaskState(taskId, TaskInfo.STATE_STOP, reason); + if (taskInfo == null) { + return; + } + Scheduler scheduler = getScheduler(); + TriggerKey triggerKey = new TriggerKey(taskInfo.getId(), taskInfo.getUid()); + if (!scheduler.checkExists(triggerKey)) { + return; + } + + scheduler.pauseTrigger(triggerKey); + scheduler.pauseJob(JobKey.jobKey(taskInfo.getId(), taskInfo.getUid())); + } + + @SneakyThrows + public void deleteTask(String taskId, String reason) { + TaskInfo taskInfo = updateTaskState(taskId, TaskInfo.STATE_STOP, reason); + if (taskInfo == null) { + return; + } + Scheduler scheduler = getScheduler(); + TriggerKey triggerKey = new TriggerKey(taskInfo.getId(), taskInfo.getUid()); + if (!scheduler.checkExists(triggerKey)) { + return; + } + scheduler.deleteJob(JobKey.jobKey(taskInfo.getId(), taskInfo.getUid())); + } + + @SneakyThrows + public void resumeTask(String taskId, String reason) { + TaskInfo taskInfo = updateTaskState(taskId, TaskInfo.STATE_RUNNING, reason); + if (taskInfo == null) { + return; + } + Scheduler scheduler = getScheduler(); + TriggerKey triggerKey = new TriggerKey(taskInfo.getId(), taskInfo.getUid()); + if (!scheduler.checkExists(triggerKey)) { + addTask(taskInfo); + } + + scheduler.resumeTrigger(triggerKey); + scheduler.resumeJob(JobKey.jobKey(taskInfo.getId(), taskInfo.getUid())); + } + + public void addLog(String taskId, boolean success, String content) { + taskLogData.add(TaskLog.builder() + .id(UUID.randomUUID().toString()) + .taskId(taskId) + .success(success) + .content(content) + .logAt(System.currentTimeMillis()) + .build()); + } + + public Scheduler getScheduler() { + return this.applicationContext.getBean("scheduler", Scheduler.class); + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } +} diff --git a/iot-module/iot-rule-engine/src/main/resources/script.js b/iot-module/iot-rule-engine/src/main/resources/script.js new file mode 100644 index 0000000..0ee994b --- /dev/null +++ b/iot-module/iot-rule-engine/src/main/resources/script.js @@ -0,0 +1,23 @@ +this.gt=function(a,b){ + return a>b; +} + +this.ge=function(a,b){ + return a>=b; +} + +this.eq=function(a,b){ + return a==b; +} + +this.lt=function(a,b){ + return a + + + iot-module + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-screen + + 数据大屏模块 + + + + + + cc.iotkit + iot-common-core + + + + cc.iotkit + iot-script-engine + + + + cc.iotkit + iot-data-service + + + + + + org.springframework + spring-context-support + + + + org.projectlombok + lombok + + + + io.vertx + vertx-core + + + + io.vertx + vertx-web-proxy + + + + org.springframework + spring-context + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + utf8 + + + + + + \ No newline at end of file diff --git a/iot-module/iot-screen/src/main/java/cc/iotkit/screen/ScreenManager.java b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/ScreenManager.java new file mode 100644 index 0000000..c5b91bb --- /dev/null +++ b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/ScreenManager.java @@ -0,0 +1,141 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.screen; + +import cc.iotkit.data.manager.IScreenApiData; +import cc.iotkit.data.manager.IScreenData; +import cc.iotkit.model.screen.Screen; +import cc.iotkit.model.screen.ScreenApi; +import cc.iotkit.screen.api.ScreenApiHandle; +import cc.iotkit.screen.config.ScreenConfig; +import cc.iotkit.screen.staticres.ScreenComponent; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author:tfd + * @Date:2023/6/25 17:03 + */ +@Slf4j +@Component +public class ScreenManager { + + @Autowired + private IScreenApiData screenApiData; + + @Autowired + private IScreenData screenData; + + @Autowired + private ScreenConfig screenConfig; + + private final Map screens = new HashMap<>(); + private final Map states = new HashMap<>(); + + @PostConstruct + public void init() { + List screenList = screenData.findByState( + Screen.STATE_RUNNING); + for (Screen screen : screenList) { + try { + register(screen); + publish(screen); + } catch (Throwable e) { + log.error("init screen error", e); + } + } + } + + public void register(Screen screen) { + Long id = screen.getId(); + if (screens.containsKey(id)) { + return; + } + ScreenComponent screenComponent=new ScreenComponent(); + String[] pathNames=screen.getResourceFile().split("\\."); + screenComponent.create(screen.getPort(),pathNames.length>1?pathNames[0]:"",screenConfig); + screens.put(id,screenComponent); + } + + public void publish(Screen screen) { + Long id = screen.getId(); + ScreenComponent screenComponent = screens.get(id); + if (screenComponent == null) { + return; + } + ScreenApiHandle screenApiHandle=new ScreenApiHandle(id,screenApiData.findByScreenId(id)); + screenComponent.setApiHandle(screenApiHandle); + screenComponent.publish(); + states.put(id, true); + } + + public void unPublish(Screen screen) { + Long id = screen.getId(); + ScreenComponent screenComponent = screens.get(id); + if (screenComponent == null) { + return; + } + screens.remove(id); + states.remove(id); + screenComponent.unPublish(); + } + + public void previewApis(Screen screen,List screenApis) { + Long id = screen.getId(); + ScreenComponent screenComponent = screens.get(id); + if (screenComponent == null) { + return; + } + screenComponent.previewApis(screenApis); + } + + public List getScreenApis(Screen screen) { + Long id = screen.getId(); + ScreenComponent screenComponent = screens.get(id); + if (screenComponent == null) { + return Collections.emptyList(); + } + return screenComponent.getScreenApis(); + } + + public void debugMode(Screen screen,boolean state) { + Long id = screen.getId(); + ScreenComponent screenComponent = screens.get(id); + if (screenComponent == null) { + return; + } + screenComponent.debugMode(state); + } + + public boolean isRunning(String id) { + return states.containsKey(id) && states.get(id); + } +} diff --git a/iot-module/iot-screen/src/main/java/cc/iotkit/screen/api/HttpContent.java b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/api/HttpContent.java new file mode 100644 index 0000000..81e0d36 --- /dev/null +++ b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/api/HttpContent.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.screen.api; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author:tfd + * @Date:2023/6/25 15:57 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class HttpContent { + private String content; +} diff --git a/iot-module/iot-screen/src/main/java/cc/iotkit/screen/api/ScreenApiHandle.java b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/api/ScreenApiHandle.java new file mode 100644 index 0000000..60457d2 --- /dev/null +++ b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/api/ScreenApiHandle.java @@ -0,0 +1,161 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.screen.api; + +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.model.screen.ScreenApi; +import cc.iotkit.script.IScriptEngine; +import cc.iotkit.script.ScriptEngineFactory; +import com.fasterxml.jackson.core.type.TypeReference; +import io.vertx.core.MultiMap; +import io.vertx.core.http.HttpMethod; +import io.vertx.core.http.HttpServerRequest; +import io.vertx.core.http.HttpServerResponse; +import io.vertx.core.json.JsonObject; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @Author:tfd + * @Date:2023/6/25 15:54 + */ +@Slf4j +@Data +public class ScreenApiHandle { + private final Long screenId; + + public List screenApis; + + public boolean debugMode=false; + + private final IScriptEngine scriptEngine = ScriptEngineFactory.getScriptEngine("js"); + + public ScreenApiHandle(Long screenId, List screenApis) { + this.screenId = screenId; + this.screenApis = screenApis; + } + + public void putScriptEnv(String key, Object value) { + this.scriptEngine.putScriptEnv(key, value); + } + + /** + * 每个请求的处理方法要执行对应的请求脚本然后将结果返回给http服务器 + * + */ + public String httpReq(HttpServerRequest req, HttpServerResponse res) { + String response=""; + try { + Map httpHeader = getData(req.headers()); + log.info("request header:{}", JsonUtils.toJsonString(httpHeader)); + String path=req.path(); + String params=""; + log.info("接收到请求:"+path); + if(HttpMethod.GET.name().equals(req.method().name())){ + String[] getParams=req.absoluteURI().split("\\?"); + if(getParams.length>1){ + params=getParams[1]; + } + }else if(HttpMethod.POST.name().equals(req.method().name())){ + MultiMap postParams=req.params(); + JsonObject jsonObject = new JsonObject(); + if(!postParams.isEmpty()){ + for (String paramName : postParams.names()) { + jsonObject.put(paramName, postParams.get(paramName)); + } + params=jsonObject.encode(); + } + } + log.info("参数:"+params); + if(debugMode){ + if(screenApis.stream().anyMatch(m -> m.getApiPath().equals(path))){ + String finalParams = params; + screenApis.stream().map(s -> { + s.setApiPath(path); + s.setApiParams(finalParams); + s.setHttpMethod(req.method().name()); + return s; + }).collect(Collectors.toList()); + }else{ + ScreenApi sai=new ScreenApi(); + sai.setApiPath(path); + sai.setApiParams(params); + sai.setHttpMethod(req.method().name()); + screenApis.add(sai); + } + response="PREVIEW API"; + }else{ + for (ScreenApi screenApi:screenApis) { + if(screenApi.getApiPath().equals(path)){ + String script=screenApi.getScript(); + if(StringUtils.isBlank(script)){ + response="转换脚本为空"; + return response; + } + scriptEngine.setScript(script); + try { + HttpContent content = + scriptEngine.invokeMethod( + new TypeReference<>() { + }, + "messageConver", + httpHeader, + params); + response = content.getContent(); + response = response == null ? "" : response; + } catch (Throwable e) { + log.error("invokeMethod messageConver error", e); + response = e.getMessage(); + return response; + } + log.info("response,content:{}", response); + }else if("/favicon.ico".equals(path)){ + response="NOT FOUND"; + }else{ + response="NOT FOUND"; + } + } + } + } catch (Throwable e) { + log.error("handle request error", e); + response="server error:" + e.getMessage(); + return response; + } + return response; + } + + private static Map getData(MultiMap multiMap) { + Map data = new HashMap<>(); + for (Map.Entry entry : multiMap.entries()) { + data.put(entry.getKey(), entry.getValue()); + } + return data; + } +} diff --git a/iot-module/iot-screen/src/main/java/cc/iotkit/screen/config/ScreenConfig.java b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/config/ScreenConfig.java new file mode 100644 index 0000000..0d761a4 --- /dev/null +++ b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/config/ScreenConfig.java @@ -0,0 +1,50 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.screen.config; + +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * @Author:tfd + * @Date:2023/6/25 16:04 + */ +@Configuration +@Data +public class ScreenConfig { + + @Value("${bigScreen.dir:./data/screens}") + private String screenDir; + @Value("${bigScreen.admin:/iotkit/screen}") + public String screenAdmin; + + public Path getBigScreenFilePath(String screenId) { + return Paths.get(screenDir, screenId) + .toAbsolutePath().normalize(); + } +} diff --git a/iot-module/iot-screen/src/main/java/cc/iotkit/screen/staticres/ScreenComponent.java b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/staticres/ScreenComponent.java new file mode 100644 index 0000000..8c3c718 --- /dev/null +++ b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/staticres/ScreenComponent.java @@ -0,0 +1,99 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.screen.staticres; + +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.model.screen.ScreenApi; +import cc.iotkit.screen.api.ScreenApiHandle; +import cc.iotkit.screen.config.ScreenConfig; +import io.vertx.core.Future; +import io.vertx.core.Vertx; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; +import java.util.concurrent.CountDownLatch; + +/** + * @Author:tfd + * @Date:2023/6/25 16:01 + */ +@Slf4j +public class ScreenComponent { + + private Vertx vertx; + private CountDownLatch countDownLatch; + private String deployedId; + private ScreenApiHandle apiHandle; + private ScreenVerticle screenVerticle; + + public List getScreenApis() { + return apiHandle.screenApis; + } + + public void debugMode(boolean state) { + apiHandle.debugMode = state; + } + + public void create(int port, String packageName, ScreenConfig screenConfig) { + vertx = Vertx.vertx(); + screenVerticle = new ScreenVerticle(port, packageName, screenConfig); + } + + public void setApiHandle(ScreenApiHandle screenApiHandle) { + this.apiHandle = screenApiHandle; + } + + public void previewApis(List screenApis) { + this.apiHandle.setScreenApis(screenApis); + } + + public void publish() { + try { + screenVerticle.setApiHandler(apiHandle); + countDownLatch = new CountDownLatch(1); + Future future = vertx.deployVerticle(screenVerticle); + future.onSuccess((s -> { + deployedId = s; + countDownLatch.countDown(); + })); + future.onFailure(e -> { + countDownLatch.countDown(); + log.error("publish screen failed", e); + }); + countDownLatch.await(); + future.succeeded(); + } catch (Throwable e) { + throw new BizException(ErrCode.SCREEN_PUBLISH_ERROR, e); + } + } + + @SneakyThrows + public void unPublish() { + screenVerticle.stop(); + Future future = vertx.undeploy(deployedId); + future.onSuccess(unused -> log.info("unPublish screen success")); + } +} diff --git a/iot-module/iot-screen/src/main/java/cc/iotkit/screen/staticres/ScreenVerticle.java b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/staticres/ScreenVerticle.java new file mode 100644 index 0000000..0aa094d --- /dev/null +++ b/iot-module/iot-screen/src/main/java/cc/iotkit/screen/staticres/ScreenVerticle.java @@ -0,0 +1,91 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.screen.staticres; + +import cc.iotkit.screen.api.ScreenApiHandle; +import cc.iotkit.screen.config.ScreenConfig; +import io.vertx.core.AbstractVerticle; +import io.vertx.core.http.HttpServer; +import io.vertx.ext.web.Router; +import io.vertx.ext.web.handler.BodyHandler; +import io.vertx.ext.web.handler.StaticHandler; +import lombok.extern.slf4j.Slf4j; + +/** + * @Author:tfd + * @Date:2023/6/25 16:03 + */ +@Slf4j +public class ScreenVerticle extends AbstractVerticle { + + private HttpServer httpServer; + + private int port; + + private String packageName; + + private ScreenApiHandle apiHandler; + + private ScreenConfig screenConfig; + + public ScreenVerticle(int port,String packageName,ScreenConfig screenConfig) { + this.port = port; + this.packageName = packageName; + this.screenConfig = screenConfig; + } + + public void setApiHandler(ScreenApiHandle apiHandler) { + this.apiHandler = apiHandler; + } + + @Override + public void start() { + httpServer = vertx.createHttpServer(); + Router router = Router.router(vertx); + router.route(screenConfig.screenAdmin + "/*").handler(StaticHandler.create(screenConfig.getScreenDir() + "/" + apiHandler.getScreenId() + "/" + packageName)); + router.get(screenConfig.screenAdmin).handler(ctx -> { + ctx.response().sendFile(screenConfig.getScreenDir() + "/" + apiHandler.getScreenId() + "/" + packageName + "/index.html"); + }); + router.get("/*").handler(ctx -> { + String res = apiHandler.httpReq(ctx.request(), ctx.response()); + ctx.response().end(res); + }); + router.post("/*").handler(BodyHandler.create()).handler(ctx -> { + String res = apiHandler.httpReq(ctx.request(), ctx.response()); + ctx.response().end(res); + }); + httpServer.requestHandler(router).listen(port, (http) -> { + if (http.succeeded()) { + log.info("screen server create succeed,port:{}", port); + } else { + log.error("screen server create failed", http.cause()); + } + }); + } + + @Override + public void stop() { + httpServer.close(voidAsyncResult -> log.info("close screen server...")); + } +} diff --git a/iot-module/iot-system/pom.xml b/iot-module/iot-system/pom.xml new file mode 100644 index 0000000..ab3f397 --- /dev/null +++ b/iot-module/iot-system/pom.xml @@ -0,0 +1,134 @@ + + + + iot-module + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-system + + + + + cc.iotkit + iot-common-core + + + + cc.iotkit + iot-common-web + + + + cc.iotkit + iot-common-log + + + + cc.iotkit + iot-common-excel + + + + cc.iotkit + iot-common-tenant + + + + cc.iotkit + iot-data-model + + + + cc.iotkit + iot-data-serviceImpl-rdb + + + + cc.iotkit + iot-common-doc + + + + cc.iotkit + iot-common-oss + + + + cc.iotkit + iot-common-satoken + + + + + + io.github.linpeilie + mapstruct-plus-spring-boot-starter + + + + org.projectlombok + lombok + + + + com.github.yitter + yitter-idgenerator + 1.0.6 + + + io.minio + minio + 8.2.2 + + + com.squareup.okhttp3 + okhttp + + + + + com.squareup.okhttp3 + okhttp + 3.12.0 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + utf8 + + + org.projectlombok + lombok + ${lombok.version} + + + io.github.linpeilie + mapstruct-plus-processor + ${mapstruct-plus.version} + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + + + + + + + diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/config/AutoMapperConfig.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/config/AutoMapperConfig.java new file mode 100644 index 0000000..6113dcb --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/config/AutoMapperConfig.java @@ -0,0 +1,36 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.config; + +import io.github.linpeilie.annotations.MapperConfig; + +/** + * @Author: jay + * @Date: 2023/6/4 14:21 + * @Version: V1.0 + * @Description: mapperstruct 配置 + */ +@MapperConfig( adapterClassName="SysAdapter") +public class AutoMapperConfig { +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/config/MinIoClientConfig.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/config/MinIoClientConfig.java new file mode 100644 index 0000000..364000e --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/config/MinIoClientConfig.java @@ -0,0 +1,40 @@ +package cc.iotkit.system.config; + +import io.minio.MinioClient; +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +@Data +@Component +@ConfigurationProperties(prefix = "minio") +public class MinIoClientConfig { + @Value("${minio.server}") + private String server; + @Value("${minio.port}") + private int port; + @Value("${minio.endpoint}") + private String endpoint; + @Value("${minio.access-key}") + private String accessKey; + @Value("${minio.secret-key}") + private String secretKey; + @Value("${minio.bucket}") + private String bucket; + + /** + * 创建minio连接对象 + * + * @return + */ + @Bean + public MinioClient minioClient() { + + return MinioClient.builder() + .endpoint(server, port,false) + .credentials(accessKey, secretKey) + .build(); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/config/MinioUtil.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/config/MinioUtil.java new file mode 100644 index 0000000..d9232a0 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/config/MinioUtil.java @@ -0,0 +1,264 @@ +package cc.iotkit.system.config; + +import cn.hutool.core.util.ObjectUtil; +import io.minio.*; +import io.minio.http.Method; +import io.minio.messages.Bucket; +import io.minio.messages.DeleteError; +import io.minio.messages.DeleteObject; +import io.minio.messages.Item; +import lombok.SneakyThrows; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +@Component +public class MinioUtil { + + @Autowired + @Lazy + private MinioClient minioClient; + @Value("${minio.bucket}") + // @Lazy + private String bucket; + + @Value("${minio.endpoint}") + // @Lazy + private String endpoint; + + /** + * description: 判断bucket是否存在,不存在则创建 + */ + @SneakyThrows + public boolean existBucket(String name) { + boolean exists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(name).build()); + if (!exists) { + minioClient.makeBucket(MakeBucketArgs.builder().bucket(name).build()); + } + return exists; + } + + /** + * 创建存储bucket + * + * @param bucketName 存储bucket名称 + * @return Boolean + */ + @SneakyThrows + public Boolean makeBucket(String bucketName) { + boolean exist = existBucket(bucketName); + if (!exist) { + minioClient.makeBucket(MakeBucketArgs.builder() + .bucket(bucketName) + .build()); + return true; + } + return false; + } + + /** + * 删除存储bucket + * + * @param bucketName 存储bucket名称 + * @return Boolean + */ + @SneakyThrows + public Boolean removeBucket(String bucketName) { + boolean exist = existBucket(bucketName); + if (!exist) return false; + + Iterable> results = + minioClient.listObjects(ListObjectsArgs.builder().bucket(bucketName).build()); + for (Result result : results) { + Item item = result.get(); + // 桶不为空不允许删除 + if (item.size() > 0) { + return false; + } + } + minioClient.removeBucket(RemoveBucketArgs.builder() + .bucket(bucketName) + .build()); + return true; + } + + /** + * 列出所有存储桶 + */ + @SneakyThrows + public List listBuckets() { + return minioClient.listBuckets(); + } + + /** + * 列出所有存储桶名称 + */ + public List listBucketNames() { + List bucketList = listBuckets(); + if (ObjectUtil.isEmpty(bucketList)) + return null; + List bucketListName = new ArrayList<>(); + for (Bucket bucket : bucketList) { + bucketListName.add(bucket.name()); + } + return bucketListName; + } + + /** + * 列出存储桶中的所有对象名称 + * + * @param bucketName 存储桶名称 + */ + @SneakyThrows + public List listObjectNames(String bucketName) { + boolean exist = existBucket(bucketName); + if (!exist) return null; + + List listObjectNames = new ArrayList<>(); + Iterable> results = + minioClient.listObjects(ListObjectsArgs.builder().bucket(bucketName).build()); + for (Result result : results) { + Item item = result.get(); + listObjectNames.add(item.objectName()); + } + return listObjectNames; + } + + /** + * 查看文件对象 + * + * @param bucketName 存储bucket名称 + * @return 存储bucket内文件对象信息 + */ + public Map listObjects(String bucketName) { + boolean exist = existBucket(bucketName); + if (!exist) return null; + + Iterable> results = + minioClient.listObjects(ListObjectsArgs.builder().bucket(bucketName).build()); + Map map = new HashMap<>(); + try { + for (Result result : results) { + Item item = result.get(); + map.put(item.objectName(), item); + } + } catch (Exception e) { + e.printStackTrace(); + return null; + } + return map; + } + + /** + * 文件访问路径 + * + * @param bucketName 存储桶名称 + * @param objectName 存储桶里的对象名称 + */ + @SneakyThrows + public String getObjectUrl(String bucketName, String objectName) { + boolean exist = existBucket(bucketName); + if (!exist) return null; + + return minioClient.getPresignedObjectUrl( + GetPresignedObjectUrlArgs.builder() + .method(Method.GET) + .bucket(bucketName) + .object(objectName) + .expiry(2, TimeUnit.MINUTES) + .build()); + } + + /** + * 删除一个对象 + * + * @param bucketName 存储桶名称 + * @param objectName 存储桶里的对象名称 + */ + @SneakyThrows + public boolean removeObject(String bucketName, String objectName) { + boolean exist = existBucket(bucketName); + if (!exist) return false; + + minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build()); + return true; + } + + /** + * 删除指定桶的多个文件对象 + * + * @param bucketName 存储桶名称 + * @param objectNames 含有要删除的多个object名称的迭代器对象 + */ + @SneakyThrows + public boolean removeObject(String bucketName, List objectNames) { + boolean exist = existBucket(bucketName); + if (!exist) return false; + + List objects = new LinkedList<>(); + for (String objectName : objectNames) { + objects.add(new DeleteObject(objectName)); + } + minioClient.removeObjects(RemoveObjectsArgs.builder().bucket(bucketName).objects(objects).build()); + return true; + } + + /** + * 批量删除文件对象 + * + * @param bucketName 存储bucket名称 + * @param objects 对象名称集合 + */ + public Iterable> removeObjects(String bucketName, List objects) { + List dos = objects.stream().map(DeleteObject::new).collect(Collectors.toList()); + return minioClient.removeObjects(RemoveObjectsArgs.builder().bucket(bucketName).objects(dos).build()); + } + + /** + * 文件上传 + */ + public String upload(MultipartFile multipartFile) { + String fileName = multipartFile.getOriginalFilename(); + // 注意,这里需要加上 \\ 将 特殊字符 . 转意 \\. ,否则异常 + assert fileName != null; + String[] fileArray = fileName.split("\\."); + + // 获取当前日期 + Date now = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + String format = sdf.format(now); + + fileName = format + "/" + fileArray[0] + System.currentTimeMillis() + "." + fileArray[1]; + + try (InputStream inputStream = multipartFile.getInputStream()) { + minioClient.putObject( + PutObjectArgs.builder() + .bucket(bucket) + .object(fileName) + .stream(inputStream, -1L, 10485760L) + .contentType(multipartFile.getContentType()) + .build() + ); + } catch (Exception e) { + throw new RuntimeException("文件上传失败: " + e.getMessage()); + } + // 返回地址 + return endpoint+bucket+"/"+fileName; + } + + /** + * 文件下载 + * + * @param fileName 文件名 + * @param delete 是否删除 + */ +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysAppController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysAppController.java new file mode 100644 index 0000000..1a0e40a --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysAppController.java @@ -0,0 +1,134 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.bo.SysAppBo; +import cc.iotkit.system.dto.vo.SysAppVo; +import cc.iotkit.system.service.ISysAppService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + + +/** + * 应用信息 + * + * @author tfd + * @date 2023-08-10 + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/app") +public class SysAppController extends BaseController { + + private final ISysAppService sysAppService; + + /** + * 查询应用信息列表 + */ + @SaCheckPermission("system:app:list") + @PostMapping("/list") + @ApiOperation("查询应用信息列表") + public Paging list( PageRequest pageQuery) { + return sysAppService.queryPageList(pageQuery); + } + + /** + * 导出应用信息列表 + */ + @ApiOperation("导出应用信息列表") + @SaCheckPermission("system:app:export") + @Log(title = "应用信息", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(SysAppBo bo, HttpServletResponse response) { + List list = sysAppService.queryList(bo); + ExcelUtil.exportExcel(list, "应用信息", SysAppVo.class, response); + } + + /** + * 获取应用信息详细信息 + * + */ + @SaCheckPermission("system:app:query") + @PostMapping("/getDetail") + @ApiOperation("获取应用信息详细信息") + public SysAppVo getDetail(@Validated @RequestBody Request request) { + return sysAppService.queryById(request.getData()); + } + + /** + * 新增应用信息 + */ + @SaCheckPermission("system:app:add") + @Log(title = "应用信息", businessType = BusinessType.INSERT) + @PostMapping(value = "/add") + @ApiOperation("新增应用信息") + public Long add(@Validated(AddGroup.class) @RequestBody Request request) { + if (sysAppService.checkAppIdUnique(request.getData().getAppId())) { + fail("新增应用'" + request.getData().getAppName() + "'失败,APPID已存在"); + } + return sysAppService.insertByBo(request.getData()); + } + + /** + * 修改应用信息 + */ + @SaCheckPermission("system:app:edit") + @Log(title = "应用信息", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + @ApiOperation("修改应用信息") + public boolean edit(@Validated(EditGroup.class) @RequestBody Request request) { + return sysAppService.updateByBo(request.getData()); + } + + /** + * 删除应用信息 + * + */ + @SaCheckPermission("system:app:remove") + @Log(title = "应用信息", businessType = BusinessType.DELETE) + @PostMapping("/delete") + @ApiOperation("删除应用信息") + public boolean remove(@Validated @RequestBody Request query) { + return sysAppService.deleteById(query.getData()); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysConfigController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysConfigController.java new file mode 100644 index 0000000..452847e --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysConfigController.java @@ -0,0 +1,162 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.data.manager.ICategoryData; +import cc.iotkit.model.product.Category; +import cc.iotkit.system.dto.bo.SysConfigBo; +import cc.iotkit.system.dto.vo.SysConfigVo; +import cc.iotkit.system.service.ISysConfigService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.io.FileUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.util.List; + +/** + * 参数配置 信息操作处理 + * + * @author Lion Li + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/config") +@Api(tags = "参数配置 信息操作处理") +public class SysConfigController extends BaseController { + + private final ISysConfigService configService; + + private final ICategoryData categoryData; + + + @ApiOperation("获取参数配置列表") + @SaCheckPermission("system:config:list") + @PostMapping("/list") + public Paging list(@RequestBody @Validated(QueryGroup.class) PageRequest query) { + return configService.selectPageConfigList(query); + } + + @ApiOperation("导出参数配置列表") + @Log(title = "参数管理", businessType = BusinessType.EXPORT) + @SaCheckPermission("system:config:export") + @PostMapping("/export") + public void export(@Validated(QueryGroup.class) SysConfigBo config, + HttpServletResponse response) { + List list = configService.selectConfigList(config); + ExcelUtil.exportExcel(list, "参数数据", SysConfigVo.class, response); + } + + + @ApiOperation("根据参数编号获取详细信息") + @SaCheckPermission("system:config:query") + @PostMapping(value = "/getDetail") + public SysConfigVo getInfo(@RequestBody @Validated Request request) { + return configService.selectConfigById(request.getData()); + } + + + @ApiOperation("根据参数键名查询参数值") + @PostMapping(value = "/getConfigKey") + public String getConfigKey(@RequestBody @Validated Request request) { + return configService.selectConfigByKey(request.getData()); + } + + + @ApiOperation("新增参数配置") + @SaCheckPermission("system:config:add") + @Log(title = "参数管理", businessType = BusinessType.INSERT) + @PostMapping(value = "/add") + public void add(@RequestBody @Validated(AddGroup.class) Request request) { + if (!configService.checkConfigKeyUnique(request.getData())) { + fail("新增参数'" + request.getData().getConfigName() + "'失败,参数键名已存在"); + } + configService.insertConfig(request.getData()); + } + + @ApiOperation("修改参数配置") + @SaCheckPermission("system:config:edit") + @Log(title = "参数管理", businessType = BusinessType.UPDATE) + @PostMapping(value = "/edit") + public void edit(@RequestBody @Validated(EditGroup.class) Request request) { + if (!configService.checkConfigKeyUnique(request.getData())) { + fail("修改参数'" + request.getData().getConfigName() + "'失败,参数键名已存在"); + } + configService.updateConfig(request.getData()); + } + + @ApiOperation("根据参数键名修改参数配置") + @SaCheckPermission("system:config:edit") + @Log(title = "参数管理", businessType = BusinessType.UPDATE) + @PostMapping("/updateByKey") + public void updateByKey(@RequestBody @Validated(EditGroup.class) Request request) { + configService.updateConfig(request.getData()); + } + + @ApiOperation("删除参数配置") + @SaCheckPermission("system:config:remove") + @Log(title = "参数管理", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@RequestBody @Validated Request> request) { + configService.deleteConfigByIds(request.getData()); + } + + @ApiOperation("刷新参数缓存") + @SaCheckPermission("system:config:remove") + @Log(title = "参数管理", businessType = BusinessType.CLEAN) + @PostMapping("/refreshCache") + public void refreshCache() { + configService.resetConfigCache(); + } + + @SneakyThrows + @ApiOperation("导出系统数据") + @Log(title = "导出系统数据", businessType = BusinessType.EXPORT) + @SaCheckPermission("system:config:exportSysData") + @PostMapping("/exportSysData") + public void exportSysData() { + configService.backupSysData(); + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDeptController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDeptController.java new file mode 100644 index 0000000..28ad4e4 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDeptController.java @@ -0,0 +1,155 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.data.config.TenantContext; +import cc.iotkit.system.dto.bo.SysDeptBo; +import cc.iotkit.system.dto.vo.SysDeptVo; +import cc.iotkit.system.service.ISysDeptService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.convert.Convert; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 部门信息 + * + * @author Lion Li + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/dept") +public class SysDeptController extends BaseController { + + private final ISysDeptService deptService; + + /** + * 获取部门列表 + */ + @SaCheckPermission("system:dept:list") + @ApiOperation("获取部门列表") + @PostMapping("/list") + public List list(@RequestBody @Validated(QueryGroup.class) PageRequest dept) { + + return deptService.selectDeptList(dept.getData()); + } + + /** + * 查询部门列表(排除节点) + */ + @ApiOperation("查询部门列表(排除节点)") + @SaCheckPermission("system:dept:list") + @PostMapping("/list/exclude") + public List excludeChild(@Validated @RequestBody Request request) { + + Long deptId = request.getData(); + List depts = deptService.selectDeptList(new SysDeptBo()); + depts.removeIf(d -> d.getId().equals(deptId) + || StringUtils.splitList(d.getAncestors()).contains(Convert.toStr(deptId))); + return depts; + } + + /** + * 根据部门编号获取详细信息 + */ + @SaCheckPermission("system:dept:query") + @ApiOperation("根据部门编号获取详细信息") + @PostMapping(value = "/getInfo") + public SysDeptVo getInfo(@Validated @RequestBody Request bo) { + Long deptId = bo.getData(); + deptService.checkDeptDataScope(deptId); + return deptService.selectDeptById(deptId); + } + + /** + * 新增部门 + */ + @SaCheckPermission("system:dept:add") + @ApiOperation("新增部门") + @Log(title = "部门管理", businessType = BusinessType.INSERT) + @PostMapping("/add") + public void add(@Validated @RequestBody Request bo) { + SysDeptBo dept = bo.getData(); + if (!deptService.checkDeptNameUnique(dept)) { + fail("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); + } + deptService.insertDept(dept); + } + + /** + * 修改部门 + */ + @ApiOperation("修改部门") + @SaCheckPermission("system:dept:edit") + @Log(title = "部门管理", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + public void edit(@Validated @RequestBody Request bo) { + SysDeptBo dept = bo.getData(); + Long deptId = dept.getId(); + deptService.checkDeptDataScope(deptId); + if (dept.getParentId().equals(deptId)) { + fail("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); + } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) + && deptService.selectNormalChildrenDeptById(deptId) > 0) { + fail("该部门包含未停用的子部门!"); + } + deptService.updateDept(dept); + } + + /** + * 删除部门 + */ + @SaCheckPermission("system:dept:remove") + @ApiOperation("删除部门") + @Log(title = "部门管理", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@Validated @RequestBody Request bo) { + Long deptId = bo.getData(); + if (deptService.hasChildByDeptId(deptId)) { + warn("存在下级部门,不允许删除"); + } + if (deptService.checkDeptExistUser(deptId)) { + warn("部门存在用户,不允许删除"); + } + deptService.checkDeptDataScope(deptId); + deptService.deleteDeptById(deptId); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDictDataController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDictDataController.java new file mode 100644 index 0000000..8fc38fa --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDictDataController.java @@ -0,0 +1,144 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.system.dto.bo.SysDictDataBo; +import cc.iotkit.system.dto.vo.SysDictDataVo; +import cc.iotkit.system.service.ISysDictDataService; +import cc.iotkit.system.service.ISysDictTypeService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.List; + +/** + * 数据字典信息 + * + * @author Lion Li + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/dict/data") +public class SysDictDataController { + + private final ISysDictDataService dictDataService; + private final ISysDictTypeService dictTypeService; + + /** + * 查询字典数据列表 + */ + @SaCheckPermission("system:dict:list") + @ApiOperation(value = "查询字典数据列表", notes = "查询字典数据列表") + @PostMapping("/list") + public Paging list(@Validated @RequestBody PageRequest query) { + return dictDataService.selectPageDictDataList( query); + } + + /** + * 导出字典数据列表 + */ + @Log(title = "字典数据", businessType = BusinessType.EXPORT) + @SaCheckPermission("system:dict:export") + @ApiOperation(value = "导出字典数据列表", notes = "导出字典数据列表") + @PostMapping("/export") + public void export(SysDictDataBo bo, HttpServletResponse response) { + List list = dictDataService.selectDictDataList(bo); + ExcelUtil.exportExcel(list, "字典数据", SysDictDataVo.class, response); + } + + /** + * 查询字典数据详细 + * + + */ + @SaCheckPermission("system:dict:query") + @ApiOperation(value = "查询字典数据详细", notes = "查询字典数据详细") + @PostMapping(value = "/getDetail") + public SysDictDataVo getInfo(@Validated @RequestBody Request bo) { + return dictDataService.selectDictDataById(bo.getData()); + } + + /** + * 根据字典类型查询字典数据信息 + * + + */ + @ApiOperation(value = "根据字典类型查询字典数据信息", notes = "根据字典类型查询字典数据信息") + @PostMapping(value = "/type") + public List dictType(@Validated @RequestBody Request bo) { + String dictType = bo.getData(); + List data = dictTypeService.selectDictDataByType(dictType); + if (ObjectUtil.isNull(data)) { + data = new ArrayList<>(); + } + return data; + } + + /** + * 新增字典类型 + */ + @ApiOperation(value = "新增字典类型", notes = "新增字典类型") + @SaCheckPermission("system:dict:add") + @Log(title = "字典数据", businessType = BusinessType.INSERT) + @PostMapping("/add") + public void add(@Validated @RequestBody Request bo) { + dictDataService.insertDictData(bo.getData()); + } + + /** + * 修改保存字典类型 + */ + @ApiOperation(value = "修改保存字典类型", notes = "修改保存字典类型") + @SaCheckPermission("system:dict:edit") + @Log(title = "字典数据", businessType = BusinessType.UPDATE) + @PutMapping("/edit") + public void edit(@Validated @RequestBody Request bo) { + dictDataService.updateDictData(bo.getData()); + } + + /** + * 删除字典类型 + * + */ + @ApiOperation(value = "删除字典类型", notes = "删除字典类型") + @SaCheckPermission("system:dict:remove") + @Log(title = "字典类型", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@Validated @RequestBody Request bo) { + dictDataService.deleteDictDataByIds(bo.getData()); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDictTypeController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDictTypeController.java new file mode 100644 index 0000000..b9bb1ff --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDictTypeController.java @@ -0,0 +1,158 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.bo.SysDictTypeBo; +import cc.iotkit.system.dto.vo.SysDictTypeVo; +import cc.iotkit.system.service.ISysDictTypeService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 数据字典信息 + * + * @author Lion Li + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/dict/type") +public class SysDictTypeController extends BaseController { + + private final ISysDictTypeService dictTypeService; + + /** + * 查询字典类型列表 + */ + @ApiOperation(value = "查询字典类型列表", notes = "查询字典类型列表") + @SaCheckPermission("system:dict:list") + @PostMapping("/list") + public Paging list(@RequestBody @Validated(QueryGroup.class) PageRequest query) { + return dictTypeService.selectPageDictTypeList(query); + } + + /** + * 导出字典类型列表 + */ + @ApiOperation(value = "导出字典类型列表", notes = "导出字典类型列表") + @Log(title = "字典类型", businessType = BusinessType.EXPORT) + @SaCheckPermission("system:dict:export") + @PostMapping("/export") + public void export(@Validated(QueryGroup.class) SysDictTypeBo dictType, HttpServletResponse response) { + + List list = dictTypeService.selectDictTypeList(dictType); + ExcelUtil.exportExcel(list, "字典类型", SysDictTypeVo.class, response); + } + + /** + * 查询字典类型详细 + */ + @ApiOperation(value = "查询字典类型详细", notes = "查询字典类型详细") + @SaCheckPermission("system:dict:query") + @PostMapping(value = "/getById") + public SysDictTypeVo getInfo(@Validated(QueryGroup.class) @RequestBody Request bo) { + Long dictTypeId = bo.getData().getId(); + return dictTypeService.selectDictTypeById(dictTypeId); + } + + /** + * 新增字典类型 + */ + @ApiOperation(value = "新增字典类型", notes = "新增字典类型") + @SaCheckPermission("system:dict:add") + @Log(title = "字典类型", businessType = BusinessType.INSERT) + @PostMapping("/add") + public void add(@Validated(AddGroup.class) @RequestBody Request dict) { + if (!dictTypeService.checkDictTypeUnique(dict.getData())) { + fail("新增字典'" + dict.getData().getDictName() + "'失败,字典类型已存在"); + } + dictTypeService.insertDictType(dict.getData()); + } + + /** + * 修改字典类型 + */ + @ApiOperation(value = "修改字典类型", notes = "修改字典类型") + @SaCheckPermission("system:dict:edit") + @Log(title = "字典类型", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + public void edit(@Validated(EditGroup.class) @RequestBody Request dict) { + if (!dictTypeService.checkDictTypeUnique(dict.getData())) { + fail("修改字典'" + dict.getData().getDictName() + "'失败,字典类型已存在"); + } + dictTypeService.updateDictType(dict.getData()); + } + + /** + * 删除字典类型 + * + * @param dictIds 字典ID串 + */ + @ApiOperation(value = "删除字典类型", notes = "删除字典类型") + @SaCheckPermission("system:dict:remove") + @Log(title = "字典类型", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@RequestBody @Validated Request> dictIds) { + dictTypeService.deleteDictTypeByIds(dictIds.getData()); + } + + /** + * 刷新字典缓存 + */ + @ApiOperation(value = "刷新字典缓存", notes = "刷新字典缓存") + @SaCheckPermission("system:dict:remove") + @Log(title = "字典类型", businessType = BusinessType.CLEAN) + @PostMapping("/refreshCache") + public void refreshCache() { + dictTypeService.resetDictCache(); + } + + /** + * 获取字典选择框列表 + */ + @ApiOperation(value = "获取字典选择框列表", notes = "获取字典选择框列表") + @PostMapping("/optionselect") + public List optionselect() { + return dictTypeService.selectDictTypeAll(); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysLogininforController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysLogininforController.java new file mode 100644 index 0000000..214965b --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysLogininforController.java @@ -0,0 +1,121 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.constant.GlobalConstants; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.redis.utils.RedisUtils; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.bo.SysLoginInfoBo; +import cc.iotkit.system.dto.vo.SysLogininforVo; +import cc.iotkit.system.service.ISysLogininforService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/5/31 15:53 + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/monitor/logininfor") +@Api(tags = "系统访问记录") +public class SysLogininforController extends BaseController { + + private final ISysLogininforService logininforService; + + /** + * 获取系统访问记录列表 + */ + + @ApiOperation("获取系统访问记录列表") + @SaCheckPermission("monitor:logininfor:list") + @PostMapping("/list") + public Paging list(@RequestBody @Validated(QueryGroup.class) PageRequest query) { + return logininforService.findAll(query); + } + + /** + * 导出系统访问记录列表 + */ + @ApiOperation("获取系统访问记录列表") + @Log(title = "登录日志", businessType = BusinessType.EXPORT) + @SaCheckPermission("monitor:logininfor:export") + @PostMapping("/export") + public void export(SysLoginInfoBo logininfor, HttpServletResponse response) { + List list = logininforService.selectLogininforList(logininfor); + ExcelUtil.exportExcel(list, "登录日志", SysLogininforVo.class, response); + } + + /** + * 批量删除登录日志 + + */ + @ApiOperation("批量删除登录日志") + @SaCheckPermission("monitor:logininfor:remove") + @Log(title = "登录日志", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@RequestBody @Validated Request> bo) { + logininforService.deleteLogininforByIds(bo.getData()); + } + + /** + * 清理系统访问记录 + */ + @ApiOperation("清理系统访问记录") + @SaCheckPermission("monitor:logininfor:remove") + @Log(title = "登录日志", businessType = BusinessType.CLEAN) + @PostMapping("/clean") + public void clean() { + logininforService.cleanLogininfor(); + } + + @ApiOperation("账户解锁") + @SaCheckPermission("monitor:logininfor:unlock") + @Log(title = "账户解锁", businessType = BusinessType.OTHER) + @PostMapping("/unlockByUserName") + public void unlock(@Validated @RequestBody Request bo) { + String loginName = GlobalConstants.PWD_ERR_CNT_KEY + bo.getData(); + if (Boolean.TRUE.equals(RedisUtils.hasKey(loginName))) { + RedisUtils.deleteObject(loginName); + } + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysMenuController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysMenuController.java new file mode 100644 index 0000000..83c94d7 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysMenuController.java @@ -0,0 +1,215 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.Request; +import cc.iotkit.common.constant.TenantConstants; +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.model.system.SysMenu; +import cc.iotkit.system.dto.bo.SysMenuBo; +import cc.iotkit.system.dto.vo.MenuTreeSelectVo; +import cc.iotkit.system.dto.vo.RouterVo; +import cc.iotkit.system.dto.vo.SysMenuVo; +import cc.iotkit.system.service.ISysMenuService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.dev33.satoken.annotation.SaCheckRole; +import cn.dev33.satoken.annotation.SaMode; +import cn.hutool.core.lang.tree.Tree; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 菜单信息 + * + * @author Lion Li + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/menu") +public class SysMenuController extends BaseController { + + private final ISysMenuService menuService; + + /** + * 获取路由信息 + * + * @return 路由信息 + */ + @ApiOperation("获取路由信息") + @PostMapping("/getRouters") + public List getRouters() { + List menus = menuService.selectMenuTreeByUserId(LoginHelper.getUserId()); + return menuService.buildMenus(menus); + } + + /** + * 获取菜单列表 + */ + @ApiOperation("获取菜单列表") + @SaCheckRole(value = { + TenantConstants.SUPER_ADMIN_ROLE_KEY, + TenantConstants.TENANT_ADMIN_ROLE_KEY + }, mode = SaMode.OR) + @SaCheckPermission("system:menu:list") + @PostMapping("/list") + public List list(@RequestBody Request bo) { + return menuService.selectMenuList(bo.getData(), LoginHelper.getUserId()); + } + + /** + * 根据菜单编号获取详细信息 + * + * @param menuId 菜单ID + */ + @SaCheckRole(value = { + TenantConstants.SUPER_ADMIN_ROLE_KEY, + TenantConstants.TENANT_ADMIN_ROLE_KEY + }, mode = SaMode.OR) + @SaCheckPermission("system:menu:query") + @PostMapping(value = "/getInfo") + public SysMenuVo getInfo(@RequestBody Request menuId) { + return menuService.selectMenuById(menuId.getData()); + } + + /** + * 获取菜单下拉树列表 + */ + @ApiOperation("获取菜单下拉树列表") + @SaCheckRole(value = { + TenantConstants.SUPER_ADMIN_ROLE_KEY, + TenantConstants.TENANT_ADMIN_ROLE_KEY + }, mode = SaMode.OR) + @SaCheckPermission("system:menu:query") + @PostMapping("/treeselect") + public List> treeSelect(@Validated @RequestBody Request menu) { + List menus = menuService.selectMenuList(menu.getData(), LoginHelper.getUserId()); + return menuService.buildMenuTreeSelect(menus); + } + + /** + * 加载对应角色菜单列表树 + * + */ + @ApiOperation("加载对应角色菜单列表树") + @SaCheckRole(value = { + TenantConstants.SUPER_ADMIN_ROLE_KEY, + TenantConstants.TENANT_ADMIN_ROLE_KEY + }, mode = SaMode.OR) + @SaCheckPermission("system:menu:query") + @PostMapping(value = "/roleMenuTreeselectByRoleId") + public MenuTreeSelectVo roleMenuTreeSelect(@Validated @RequestBody Request bo) { + List menus = menuService.selectMenuList(LoginHelper.getUserId()); + MenuTreeSelectVo selectVo = new MenuTreeSelectVo(); + selectVo.setCheckedKeys(menuService.selectMenuListByRoleId(bo.getData())); + selectVo.setMenus(menuService.buildMenuTreeSelect(menus)); + return selectVo; + } + + /** + * 新增菜单 + */ + @ApiOperation("新增菜单") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:menu:add") + @Log(title = "菜单管理", businessType = BusinessType.INSERT) + @PostMapping("/add") + public void add(@Validated @RequestBody Request bo) { + SysMenuBo menu = bo.getData(); + if (!menuService.checkMenuNameUnique(menu)) { + fail("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在"); + } else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) { + fail("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头"); + } + menuService.insertMenu(menu); + } + + /** + * 修改菜单 + */ + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:menu:edit") + @Log(title = "菜单管理", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + public void edit(@Validated @RequestBody Request bo) { + SysMenuBo menu = bo.getData(); + if (!menuService.checkMenuNameUnique(menu)) { + fail("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在"); + } else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) { + fail("修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头"); + } else if (menu.getId().equals(menu.getParentId())) { + fail("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己"); + } + menuService.updateMenu(menu); + } + + + /** + * 加载对应租户套餐菜单列表树 + * + * @param packageId 租户套餐ID + */ + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:menu:query") + @PostMapping(value = "/tenantPackageMenuTreeselect") + public MenuTreeSelectVo tenantPackageMenuTreeselect(@Validated @RequestBody Request bo) { + List menus = menuService.selectMenuList(LoginHelper.getUserId()); + MenuTreeSelectVo selectVo = new MenuTreeSelectVo(); + selectVo.setCheckedKeys(menuService.selectMenuListByPackageId(bo.getData())); + selectVo.setMenus(menuService.buildMenuTreeSelect(menus)); + return selectVo; + } + /** + * 删除菜单 + * + */ + @ApiOperation("删除菜单") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:menu:remove") + @Log(title = "菜单管理", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@Validated @RequestBody Request bo) { + Long menuId = bo.getData(); + if (menuService.hasChildByMenuId(menuId)) { + warn("存在子菜单,不允许删除"); + } + if (menuService.checkMenuExistRole(menuId)) { + warn("菜单已分配,不允许删除"); + } + menuService.deleteMenuById(menuId); + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysNoticeController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysNoticeController.java new file mode 100644 index 0000000..e326614 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysNoticeController.java @@ -0,0 +1,112 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.bo.SysNoticeBo; +import cc.iotkit.system.dto.vo.SysNoticeVo; +import cc.iotkit.system.service.ISysNoticeService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 公告 信息操作处理 + * + * @author Lion Li + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/notice") +public class SysNoticeController extends BaseController { + + private final ISysNoticeService noticeService; + + /** + * 获取通知公告列表 + */ + @SaCheckPermission("system:notice:list") + @ApiOperation(value = "获取通知公告列表", notes = "获取通知公告列表") + @PostMapping("/list") + public Paging list(@Validated @RequestBody PageRequest query) { + return noticeService.selectPageNoticeList( query); + } + + /** + * 根据通知公告编号获取详细信息 + * + */ + @ApiOperation(value = "根据通知公告编号获取详细信息", notes = "根据通知公告编号获取详细信息") + @SaCheckPermission("system:notice:query") + @PostMapping(value = "/getDetail") + public SysNoticeVo getInfo(@Validated @RequestBody Request bo) { + return noticeService.selectNoticeById(bo.getData()); + } + + /** + * 新增通知公告 + */ + @ApiOperation(value = "新增通知公告", notes = "新增通知公告") + @SaCheckPermission("system:notice:add") + @Log(title = "通知公告", businessType = BusinessType.INSERT) + @PostMapping("/add") + public void add(@Validated @RequestBody Request bo) { + noticeService.insertNotice(bo.getData()); + } + + /** + * 修改通知公告 + */ + @SaCheckPermission("system:notice:edit") + @Log(title = "通知公告", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + public void edit(@Validated @RequestBody Request bo) { + noticeService.updateNotice(bo.getData()); + } + + /** + * 删除通知公告 + * + */ + @ApiOperation(value = "删除通知公告", notes = "删除通知公告") + @SaCheckPermission("system:notice:remove") + @Log(title = "通知公告", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@Validated @RequestBody Request> bo) { + noticeService.deleteNoticeByIds(bo.getData()); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOperlogController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOperlogController.java new file mode 100644 index 0000000..2f32cda --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOperlogController.java @@ -0,0 +1,107 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.bo.SysOperLogBo; +import cc.iotkit.system.dto.vo.SysOperLogVo; +import cc.iotkit.system.service.ISysOperLogService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/5/31 15:08 + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/monitor/operlog") +@Api(tags = "操作日志记录") +public class SysOperlogController extends BaseController { + + private final ISysOperLogService operLogService; + + /** + * 获取操作日志记录列表 + */ + @ApiOperation("获取操作日志记录列表") + @SaCheckPermission("monitor:operlog:list") + @PostMapping("/list") + public Paging list(@RequestBody @Validated(QueryGroup.class) PageRequest query) { + return operLogService.selectPageOperLogList(query); + } + + /** + * 导出操作日志记录列表 + */ + @ApiOperation("导出操作日志记录列表") + @Log(title = "操作日志", businessType = BusinessType.EXPORT) + @SaCheckPermission("monitor:operlog:export") + @PostMapping("/export") + public void export(SysOperLogBo operLog, HttpServletResponse response) { + List list = operLogService.selectOperLogList(operLog); + ExcelUtil.exportExcel(list, "操作日志", SysOperLogVo.class, response); + } + + /** + * 批量删除操作日志记录 + */ + @ApiOperation("批量删除操作日志记录") + @Log(title = "操作日志", businessType = BusinessType.DELETE) + @SaCheckPermission("monitor:operlog:remove") + @PostMapping("/delete") + public void remove(@Validated @RequestBody Request> bo) { + List operIds = bo.getData(); + operLogService.deleteOperLogByIds(operIds); + } + + /** + * 清理操作日志记录 + */ + @ApiOperation("清理操作日志记录") + @Log(title = "操作日志", businessType = BusinessType.CLEAN) + @SaCheckPermission("monitor:operlog:remove") + @PostMapping("/clean") + public void clean() { + operLogService.cleanOperLog(); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOssConfigController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOssConfigController.java new file mode 100644 index 0000000..99bb073 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOssConfigController.java @@ -0,0 +1,128 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.bo.SysOssConfigBo; +import cc.iotkit.system.dto.vo.SysOssConfigVo; +import cc.iotkit.system.service.ISysOssConfigService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 对象存储配置 + * + * @author Lion Li + * @author 孤舟烟雨 + * @date 2021-08-13 + */ +@Validated +@RequiredArgsConstructor +@RestController +@Controller +@ResponseBody +@RequestMapping("/resource/oss/config") +public class SysOssConfigController extends BaseController { + + private final ISysOssConfigService ossConfigService; + + /** + * 查询对象存储配置列表 + */ + @ApiOperation(value = "查询对象存储配置列表", notes = "查询对象存储配置列表") + @SaCheckPermission("system:oss:list") + @PostMapping("/list") + public Paging list(@Validated @RequestBody PageRequest query) { + return ossConfigService.queryPageList(query); + } + + /** + * 获取对象存储配置详细信息 + * + */ + @ApiOperation(value = "获取对象存储配置详细信息", notes = "获取对象存储配置详细信息") + @SaCheckPermission("system:oss:query") + @PostMapping("/getDetail") + public SysOssConfigVo getInfo(@Validated @RequestBody Request bo) { + return ossConfigService.queryById(bo.getData()); + } + + /** + * 新增对象存储配置 + */ + @ApiOperation(value = "新增对象存储配置", notes = "新增对象存储配置") + @SaCheckPermission("system:oss:add") + @Log(title = "对象存储配置", businessType = BusinessType.INSERT) + @PostMapping("/add") + public void add(@Validated(AddGroup.class) @RequestBody Request bo) { + ossConfigService.insertByBo(bo.getData()); + } + + /** + * 修改对象存储配置 + */ + @ApiOperation(value = "修改对象存储配置", notes = "修改对象存储配置") + @SaCheckPermission("system:oss:edit") + @Log(title = "对象存储配置", businessType = BusinessType.UPDATE) + @PostMapping() + public void edit(@Validated(EditGroup.class) @RequestBody Request bo) { + ossConfigService.updateByBo(bo.getData()); + } + + /** + * 删除对象存储配置 + * + */ + @ApiOperation(value = "删除对象存储配置", notes = "删除对象存储配置") + @SaCheckPermission("system:oss:remove") + @Log(title = "对象存储配置", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@Validated @RequestBody Request> bo) { + ossConfigService.deleteWithValidByIds(bo.getData(), true); + } + + /** + * 状态修改 + */ + @ApiOperation(value = "状态修改", notes = "状态修改") + @SaCheckPermission("system:oss:edit") + @Log(title = "对象存储状态修改", businessType = BusinessType.UPDATE) + @PostMapping("/changeStatus") + public void changeStatus(@RequestBody Request bo) { + ossConfigService.updateOssConfigStatus(bo.getData()); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOssController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOssController.java new file mode 100644 index 0000000..b69d860 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysOssController.java @@ -0,0 +1,145 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.oss.core.OssClient; +import cc.iotkit.common.oss.factory.OssFactory; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.bo.SysOssBo; +import cc.iotkit.system.dto.vo.SysOssUploadVo; +import cc.iotkit.system.dto.vo.SysOssVo; +import cc.iotkit.system.service.ISysOssService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.ObjectUtil; +import com.amazonaws.services.s3.model.ObjectMetadata; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.List; + +/** + * 文件上传 控制层 + * + * @author Lion Li + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/resource/oss") +public class SysOssController extends BaseController { + + private final ISysOssService ossService; + + /** + * 查询OSS对象存储列表 + */ + @SaCheckPermission("system:oss:list") + @ApiOperation(value = "查询OSS对象存储列表", notes = "查询OSS对象存储列表") + @PostMapping("/list") + public Paging list(@Validated(QueryGroup.class) @RequestBody PageRequest query) { + return ossService.queryPageList(query); + } + + /** + * 查询OSS对象基于id串 + */ + @ApiOperation(value = "查询OSS对象基于id串", notes = "查询OSS对象基于id串") + // @SaCheckPermission("system:oss:list") + @PostMapping("/listByIds") + public List listByIds(@Validated @RequestBody Request> bo) { + return ossService.listByIds(bo.getData()); + } + + /** + * 上传OSS对象存储 + * + * @param file 文件 + */ + @ApiOperation(value = "上传OSS对象存储", notes = "上传OSS对象存储") + // @SaCheckPermission("system:oss:upload") + @Log(title = "OSS对象存储", businessType = BusinessType.INSERT) + @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public SysOssUploadVo upload(@RequestPart("file") MultipartFile file, @RequestParam("requestId") String requestId) { + if (ObjectUtil.isNull(file)) { + fail("上传文件不能为空"); + } + SysOssVo oss = ossService.upload(file); + SysOssUploadVo uploadVo = new SysOssUploadVo(); + uploadVo.setUrl(oss.getUrl()); + uploadVo.setFileName(oss.getOriginalName()); + uploadVo.setOssId(oss.getId().toString()); + return uploadVo; + } + + /** + * 下载OSS对象 + */ + @SaCheckPermission("system:oss:download") + @PostMapping("/downloadById") + @ApiOperation(value = "下载OSS对象", notes = "下载OSS对象") + public ResponseEntity download(@RequestBody @Validated Request bo) throws IOException { + SysOssVo ossVo = ossService.getById(bo.getData()); + OssClient storage = OssFactory.instance(); + ObjectMetadata objectMetadata = storage.getObjectMetadata(ossVo.getUrl()); + InputStream objectContent = storage.getObjectContent(ossVo.getUrl()); + return ResponseEntity + .ok() + .header(HttpHeaders.ACCEPT_RANGES, "bytes") + .header("download-filename", ossVo.getFileName()) + .contentLength(objectMetadata.getContentLength()) + .contentType(MediaType.APPLICATION_OCTET_STREAM) + .body(out -> IoUtil.copy(objectContent, out)); + } + + /** + * 删除OSS对象存储 + */ + @ApiOperation(value = "删除OSS对象存储", notes = "删除OSS对象存储") + @SaCheckPermission("system:oss:remove") + @Log(title = "OSS对象存储", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@Validated @RequestBody Request> bo) { + ossService.deleteWithValidByIds(bo.getData(), true); + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysPostController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysPostController.java new file mode 100644 index 0000000..0a13776 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysPostController.java @@ -0,0 +1,148 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.bo.SysPostBo; +import cc.iotkit.system.dto.vo.SysPostVo; +import cc.iotkit.system.service.ISysPostService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 岗位信息操作处理 + * + * @author Lion Li + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/post") +@Api(tags = "岗位信息") +public class SysPostController extends BaseController { + + private final ISysPostService postService; + + /** + * 获取岗位列表 + */ + @ApiOperation("获取岗位列表") + @SaCheckPermission("system:post:list") + @PostMapping("/list") + public Paging list(@RequestBody @Validated(QueryGroup.class) PageRequest query) { + return postService.selectPagePostList(query); + } + + /** + * 导出岗位列表 + */ + @ApiOperation("导出岗位列表") + @Log(title = "岗位管理", businessType = BusinessType.EXPORT) + @SaCheckPermission("system:post:export") + @PostMapping("/export") + public void export(@Validated(QueryGroup.class) SysPostBo post, HttpServletResponse response) { + List list = postService.selectPostList(post); + ExcelUtil.exportExcel(list, "岗位数据", SysPostVo.class, response); + } + + /** + * 根据岗位编号获取详细信息 + * + * @param postId 岗位ID + */ + @ApiOperation("根据岗位编号获取详细信息") + @SaCheckPermission("system:post:query") + @PostMapping(value = "/getInfo") + public SysPostVo getInfo(@RequestBody @Validated Request postId) { + return postService.selectPostById(postId.getData()); + } + + /** + * 新增岗位 + */ + @ApiOperation("新增岗位") + @SaCheckPermission("system:post:add") + @Log(title = "岗位管理", businessType = BusinessType.INSERT) + @PostMapping("/add") + public void add(@RequestBody @Validated(AddGroup.class) Request post) { + if (!postService.checkPostNameUnique(post.getData())) { + fail("新增岗位'" + post.getData().getPostName() + "'失败,岗位名称已存在"); + } else if (!postService.checkPostCodeUnique(post.getData())) { + fail("新增岗位'" + post.getData().getPostName() + "'失败,岗位编码已存在"); + } + postService.insertPost(post.getData()); + } + + /** + * 修改岗位 + */ + @ApiOperation("修改岗位") + @SaCheckPermission("system:post:edit") + @Log(title = "岗位管理", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + public void edit(@RequestBody @Validated(EditGroup.class) Request post) { + postService.updatePost(post.getData()); + } + + /** + * 删除岗位 + * + * @param postIds 岗位ID串 + */ + @ApiOperation("删除岗位") + @SaCheckPermission("system:post:remove") + @Log(title = "岗位管理", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@RequestBody @Validated Request> postIds) { + postService.deletePostByIds(postIds.getData()); + } + + /** + * 获取岗位选择框列表 + */ + @ApiOperation("获取岗位选择框列表") + @PostMapping("/optionselect") + public List optionselect() { + return postService.selectPostAll(); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysProfileController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysProfileController.java new file mode 100644 index 0000000..b959179 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysProfileController.java @@ -0,0 +1,157 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.Request; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.utils.file.MimeTypeUtils; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.bo.SysChangePwdBo; +import cc.iotkit.system.dto.bo.SysUserBo; +import cc.iotkit.system.dto.bo.SysUserProfileBo; +import cc.iotkit.system.dto.vo.AvatarVo; +import cc.iotkit.system.dto.vo.ProfileVo; +import cc.iotkit.system.dto.vo.SysOssVo; +import cc.iotkit.system.dto.vo.SysUserVo; +import cc.iotkit.system.service.ISysOssService; +import cc.iotkit.system.service.ISysUserService; +import cn.dev33.satoken.secure.BCrypt; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.io.FileUtil; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.util.Arrays; + +/** + * 个人信息 业务处理 + * + * @author Lion Li + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/user/profile") +public class SysProfileController extends BaseController { + + private final ISysUserService userService; + private final ISysOssService ossService; + + /** + * 个人信息 + */ + + @ApiOperation(value = "个人信息", notes = "个人信息") + @PostMapping("/getDetail") + public ProfileVo profile() { + SysUserVo user = userService.selectUserById(LoginHelper.getUserId()); + ProfileVo profileVo = new ProfileVo(); + profileVo.setUser(user); + profileVo.setRoleGroup(userService.selectUserRoleGroup(user.getUserName())); + profileVo.setPostGroup(userService.selectUserPostGroup(user.getUserName())); + return profileVo; + } + + /** + * 修改用户 + */ + @ApiOperation(value = "修改用户", notes = "修改用户") + @Log(title = "个人信息", businessType = BusinessType.UPDATE) + @PostMapping("/updateProfile") + public void updateProfile(@RequestBody Request bo) { + SysUserProfileBo profile = bo.getData(); + SysUserBo user = BeanUtil.toBean(profile, SysUserBo.class); + if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { + fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); + } + if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { + fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); + } + user.setId(LoginHelper.getUserId()); + if (userService.updateUserProfile(user) > 0) { + return; + } + fail("修改个人信息异常,请联系管理员"); + } + + /** + * 重置密码 + * + */ + @ApiOperation(value = "重置密码", notes = "重置密码") + @Log(title = "个人信息", businessType = BusinessType.UPDATE) + @PostMapping("/updatePwd") + public void updatePwd(@RequestBody @Validated Request bo) { + SysChangePwdBo data = bo.getData(); + String newPassword = data.getNewPassword(); + String oldPassword = data.getOldPassword(); + SysUserVo user = userService.selectUserById(LoginHelper.getUserId()); + String password = user.getPassword(); + if (!BCrypt.checkpw(oldPassword, password)) { + fail("修改密码失败,旧密码错误"); + } + if (BCrypt.checkpw(newPassword, password)) { + fail("新密码不能与旧密码相同"); + } + + if (userService.resetUserPwd(user.getId(), BCrypt.hashpw(newPassword)) > 0) { + return; + } + fail("修改密码异常,请联系管理员"); + } + + /** + * 头像上传 + * + * @param avatarfile 用户头像 + */ + @ApiOperation(value = "头像上传", notes = "头像上传") + @Log(title = "用户头像", businessType = BusinessType.UPDATE) + @PostMapping(value = "/avatar", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public AvatarVo avatar(@RequestPart("avatarfile") MultipartFile avatarfile, + @RequestParam("requestId") String requestId) { + if (!avatarfile.isEmpty()) { + String extension = FileUtil.extName(avatarfile.getOriginalFilename()); + if (!StringUtils.equalsAnyIgnoreCase(extension, MimeTypeUtils.IMAGE_EXTENSION)) { + fail("文件格式不正确,请上传" + Arrays.toString(MimeTypeUtils.IMAGE_EXTENSION) + "格式"); + } + SysOssVo oss = ossService.upload(avatarfile); + String avatar = oss.getUrl(); + if (userService.updateUserAvatar(LoginHelper.getUserId(), oss.getId())) { + AvatarVo avatarVo = new AvatarVo(); + avatarVo.setImgUrl(avatar); + return avatarVo; + } + } + fail("上传图片异常,请联系管理员"); + return null; + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysRoleController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysRoleController.java new file mode 100644 index 0000000..8816239 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysRoleController.java @@ -0,0 +1,274 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.model.system.SysUserRole; +import cc.iotkit.system.dto.bo.SysDeptBo; +import cc.iotkit.system.dto.bo.SysRoleAuthBo; +import cc.iotkit.system.dto.bo.SysRoleBo; +import cc.iotkit.system.dto.bo.SysUserBo; +import cc.iotkit.system.dto.vo.DeptTreeSelectVo; +import cc.iotkit.system.dto.vo.SysRoleVo; +import cc.iotkit.system.dto.vo.SysUserVo; +import cc.iotkit.system.service.ISysDeptService; +import cc.iotkit.system.service.ISysRoleService; +import cc.iotkit.system.service.ISysUserService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 角色信息 + * + * @author Lion Li + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/role") +public class SysRoleController extends BaseController { + + private final ISysRoleService roleService; + private final ISysUserService userService; + private final ISysDeptService deptService; + + /** + * 获取角色信息列表 + */ + @ApiOperation(value = "获取角色信息列表", notes = "获取角色信息列表,根据查询条件分页") + @SaCheckPermission("system:role:list") + @PostMapping("/list") + public Paging list(@RequestBody @Validated PageRequest query) { + return roleService.selectPageRoleList(query); + } + + /** + * 导出角色信息列表 + */ + @Log(title = "角色管理", businessType = BusinessType.EXPORT) + @ApiOperation(value = "导出角色信息列表", notes = "导出角色信息列表") + @SaCheckPermission("system:role:export") + @PostMapping("/export") + public void export(@Validated SysRoleBo role, HttpServletResponse response) { + List list = roleService.selectRoleList(role); + ExcelUtil.exportExcel(list, "角色数据", SysRoleVo.class, response); + } + + /** + * 根据角色编号获取详细信息 + */ + @ApiOperation(value = "根据角色编号获取详细信息", notes = "根据角色编号获取详细信息") + @SaCheckPermission("system:role:query") + @PostMapping(value = "/getInfo") + public SysRoleVo getInfo(@Validated @RequestBody Request bo) { + Long roleId = bo.getData(); + roleService.checkRoleDataScope(roleId); + return roleService.selectRoleById(roleId); + } + + /** + * 新增角色 + */ + @ApiOperation(value = "新增角色", notes = "新增角色") + @SaCheckPermission("system:role:add") + @Log(title = "角色管理", businessType = BusinessType.INSERT) + @PostMapping("/add") + public void add(@Validated @RequestBody Request bo) { + SysRoleBo role = bo.getData(); + + if (!roleService.checkRoleNameUnique(role)) { + fail("新增角色'" + role.getRoleName() + "'失败,角色名称已存在"); + } else if (!roleService.checkRoleKeyUnique(role)) { + fail("新增角色'" + role.getRoleName() + "'失败,角色权限已存在"); + } + roleService.insertRole(role); + + } + + /** + * 修改保存角色 + */ + @ApiOperation(value = "修改保存角色", notes = "修改保存角色") + @SaCheckPermission("system:role:edit") + @Log(title = "角色管理", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + public void edit(@Validated @RequestBody Request bo) { + SysRoleBo role = bo.getData(); + + roleService.checkRoleAllowed(role.getId()); + roleService.checkRoleDataScope(role.getId()); + if (!roleService.checkRoleNameUnique(role)) { + fail("修改角色'" + role.getRoleName() + "'失败,角色名称已存在"); + } else if (!roleService.checkRoleKeyUnique(role)) { + fail("修改角色'" + role.getRoleName() + "'失败,角色权限已存在"); + } + + if (roleService.updateRole(role) > 0) { + roleService.cleanOnlineUserByRole(role.getId()); + return; + } + fail("修改角色'" + role.getRoleName() + "'失败,请联系管理员"); + } + + /** + * 修改保存数据权限 + */ + @ApiOperation(value = "修改保存数据权限", notes = "修改保存数据权限") + @SaCheckPermission("system:role:edit") + @Log(title = "角色管理", businessType = BusinessType.UPDATE) + @PostMapping("/dataScope") + public void dataScope(@RequestBody Request bo) { + SysRoleBo role = bo.getData(); + roleService.checkRoleAllowed(role.getId()); + roleService.checkRoleDataScope(role.getId()); + roleService.authDataScope(role); + } + + /** + * 状态修改 + */ + @ApiOperation(value = "状态修改", notes = "状态修改") + @SaCheckPermission("system:role:edit") + @Log(title = "角色管理", businessType = BusinessType.UPDATE) + @PostMapping("/changeStatus") + public void changeStatus(@RequestBody Request bo) { + SysRoleBo role = bo.getData(); + roleService.checkRoleAllowed(role.getId()); + roleService.checkRoleDataScope(role.getId()); + roleService.updateRoleStatus(role.getId(), role.getStatus()); + } + + /** + * 删除角色 + */ + @ApiOperation(value = "删除角色", notes = "删除角色") + @SaCheckPermission("system:role:remove") + @Log(title = "角色管理", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@Validated @RequestBody Request> bo) { + roleService.deleteRoleByIds(bo.getData()); + } + + /** + * 获取角色选择框列表 + */ + @ApiOperation(value = "获取角色选择框列表", notes = "获取角色选择框列表") + @SaCheckPermission("system:role:query") + @PostMapping("/optionselect") + public List optionselect() { + return roleService.selectRoleAll(); + } + + /** + * 查询已分配用户角色列表 + */ + @ApiOperation(value = "查询已分配用户角色列表", notes = "查询已分配用户角色列表") + @SaCheckPermission("system:role:list") + @PostMapping("/authUser/allocatedList") + public Paging allocatedList(@RequestBody @Validated PageRequest query) { + return userService.selectAllocatedList(query); + } + + /** + * 查询未分配用户角色列表 + */ + @ApiOperation(value = "查询未分配用户角色列表", notes = "查询未分配用户角色列表") + @SaCheckPermission("system:role:list") + @PostMapping("/authUser/unallocatedList") + public Paging unallocatedList(PageRequest query) { + return userService.selectUnallocatedList(query); + } + + /** + * 取消授权用户 + */ + @ApiOperation(value = "取消授权用户", notes = "取消授权用户") + @SaCheckPermission("system:role:edit") + @Log(title = "角色管理", businessType = BusinessType.GRANT) + @PostMapping("/authUser/cancel") + public void cancelAuthUser(@RequestBody Request bo) { + roleService.deleteAuthUser(bo.getData()); + } + + /** + * 批量取消授权用户 + * + */ + @ApiOperation(value = "批量取消授权用户", notes = "批量取消授权用户") + @SaCheckPermission("system:role:edit") + @Log(title = "角色管理", businessType = BusinessType.GRANT) + @PostMapping("/authUser/cancelAll") + public void cancelAuthUserAll(@Validated @RequestBody Request bo) { + SysRoleAuthBo data = bo.getData(); + Long roleId = data.getRoleId(); + Long[] userIds = data.getUserIds(); + roleService.deleteAuthUsers(roleId, userIds); + } + + /** + * 批量选择用户授权 + * + */ + @ApiOperation(value = "批量选择用户授权", notes = "批量选择用户授权") + @SaCheckPermission("system:role:edit") + @Log(title = "角色管理", businessType = BusinessType.GRANT) + @PostMapping("/authUser/selectAll") + public void selectAuthUserAll(@Validated @RequestBody Request bo) { + SysRoleAuthBo data = bo.getData(); + Long roleId = data.getRoleId(); + Long[] userIds = data.getUserIds(); + roleService.checkRoleDataScope(roleId); + roleService.insertAuthUsers(roleId, userIds); + } + + /** + * 获取对应角色部门树列表 + * + */ + @ApiOperation(value = "获取对应角色部门树列表", notes = "获取对应角色部门树列表") + @SaCheckPermission("system:role:list") + @PostMapping(value = "/deptTreeByRoleId") + public DeptTreeSelectVo roleDeptTreeselect(@Validated @RequestBody Request bo) { + Long roleId = bo.getData(); + DeptTreeSelectVo selectVo = new DeptTreeSelectVo(); + selectVo.setCheckedKeys(deptService.selectDeptListByRoleId(roleId)); + selectVo.setDepts(deptService.selectDeptTreeList(new SysDeptBo())); + return selectVo; + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysTenantController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysTenantController.java new file mode 100644 index 0000000..1be2492 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysTenantController.java @@ -0,0 +1,198 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.constant.TenantConstants; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.tenant.helper.TenantHelper; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.bo.SysTenantBo; +import cc.iotkit.system.dto.vo.SysTenantVo; +import cc.iotkit.system.service.ISysTenantService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.dev33.satoken.annotation.SaCheckRole; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.hibernate.validator.constraints.NotBlank; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 租户管理 + * + * @author Michelle.Chung + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/tenant") +@Api(tags = "租户管理") +public class SysTenantController extends BaseController { + + private final ISysTenantService tenantService; + + /** + * 查询租户列表 + */ + @ApiOperation("查询租户列表") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenant:list") + @PostMapping("/list") + public Paging list(@Validated @RequestBody PageRequest query) { + return tenantService.queryPageList(query); + } + + /** + * 导出租户列表 + */ + @ApiOperation("导出租户列表") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenant:export") + @Log(title = "租户", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(SysTenantBo bo, HttpServletResponse response) { + List list = tenantService.queryList(bo); + ExcelUtil.exportExcel(list, "租户", SysTenantVo.class, response); + } + + /** + * 获取租户详细信息 + */ + @ApiOperation("获取租户详细信息") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenant:query") + @PostMapping("/getDetail") + public SysTenantVo getInfo(@Validated @RequestBody Request bo) { + return tenantService.queryById(bo.getData()); + } + + /** + * 新增租户 + */ + @ApiOperation("新增租户") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenant:add") + @Log(title = "租户", businessType = BusinessType.INSERT) + @PostMapping("/add") + public void add(@Validated(AddGroup.class) @RequestBody Request bo) { + SysTenantBo data = bo.getData(); + if (!tenantService.checkCompanyNameUnique(data)) { + fail("新增租户'" + data.getCompanyName() + "'失败,企业名称已存在"); + } + TenantHelper.ignore(()->tenantService.insertByBo(data)); + } + + /** + * 修改租户 + */ + @ApiOperation("修改租户") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenant:edit") + @Log(title = "租户", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + public void edit(@Validated(EditGroup.class) @RequestBody Request bo) { + SysTenantBo data = bo.getData(); + tenantService.checkTenantAllowed(data.getTenantId()); + if (!tenantService.checkCompanyNameUnique(data)) { + fail("修改租户'" + data.getCompanyName() + "'失败,公司名称已存在"); + } + TenantHelper.ignore(()->tenantService.updateByBo(data)); ; + } + + /** + * 状态修改 + */ + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenant:edit") + @Log(title = "租户", businessType = BusinessType.UPDATE) + @PostMapping("/changeStatus") + public void changeStatus(@RequestBody Request bo) { + SysTenantBo data = bo.getData(); + tenantService.checkTenantAllowed(data.getTenantId()); + tenantService.updateTenantStatus(data); + } + + /** + * 删除租户 + */ + @ApiOperation("删除租户") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenant:remove") + @Log(title = "租户", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@Validated @RequestBody Request bo) { + tenantService.deleteById(bo.getData()); + } + + /** + * 动态切换租户 + */ + @ApiOperation("动态切换租户") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @PostMapping("/dynamic") + public void dynamicTenant(@Validated @RequestBody Request bo) { + TenantHelper.setDynamic(bo.getData()); + } + + /** + * 清除动态租户 + */ + @ApiOperation("清除动态租户") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @PostMapping("/dynamic/clear") + public void dynamicClear() { + TenantHelper.clearDynamic(); + } + + + /** + * 同步租户套餐 + * + * @param tenantId 租户id + * @param packageId 套餐id + */ + @ApiOperation("同步租户套餐") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenant:edit") + @Log(title = "租户", businessType = BusinessType.UPDATE) + @PostMapping("/syncTenantPackage") + public void syncTenantPackage(@NotBlank(message = "租户ID不能为空") Long tenantId, @NotBlank(message = "套餐ID不能为空") String packageId) { + //TenantHelper.ignore(() -> tenantService.syncTenantPackage(tenantId, packageId)); + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysTenantPackageController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysTenantPackageController.java new file mode 100644 index 0000000..4d78a1f --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysTenantPackageController.java @@ -0,0 +1,160 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.constant.TenantConstants; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.bo.SysTenantPackageBo; +import cc.iotkit.system.dto.vo.SysTenantPackageVo; +import cc.iotkit.system.service.ISysTenantPackageService; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.dev33.satoken.annotation.SaCheckRole; +import io.swagger.annotations.ApiOperation; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 租户套餐管理 + * + * @author Michelle.Chung + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/tenant/package") +public class SysTenantPackageController extends BaseController { + + private final ISysTenantPackageService tenantPackageService; + + /** + * 查询租户套餐列表 + */ + @ApiOperation("查询租户套餐列表") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenantPackage:list") + @PostMapping("/list") + public Paging list( PageRequest query) { + return tenantPackageService.queryPageList( query); + } + + /** + * 查询租户套餐下拉选列表 + */ + @ApiOperation("查询租户套餐下拉选列表") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenantPackage:list") + @PostMapping("/selectList") + public List selectList() { + return tenantPackageService.selectList(); + } + + /** + * 导出租户套餐列表 + */ + @ApiOperation("导出租户套餐列表") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenantPackage:export") + @Log(title = "租户套餐", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(SysTenantPackageBo bo, HttpServletResponse response) { + List list = tenantPackageService.queryList(bo); + ExcelUtil.exportExcel(list, "租户套餐", SysTenantPackageVo.class, response); + } + + /** + * 获取租户套餐详细信息 + * + * @param 主键 + */ + @ApiOperation("获取租户套餐详细信息") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenantPackage:query") + @PostMapping("/getInfo") + public SysTenantPackageVo getInfo(@RequestBody @Validated Request bo) { + return tenantPackageService.queryById(bo.getData()); + } + + /** + * 新增租户套餐 + */ + @ApiOperation("新增租户套餐") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenantPackage:add") + @Log(title = "租户套餐", businessType = BusinessType.INSERT) + @PostMapping("/add") + public void add(@Validated(AddGroup.class) @RequestBody Request bo) { + tenantPackageService.insertByBo(bo.getData()); + } + + /** + * 修改租户套餐 + */ + @ApiOperation("修改租户套餐") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenantPackage:edit") + @Log(title = "租户套餐", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + public void edit(@Validated(EditGroup.class) @RequestBody Request bo) { + tenantPackageService.updateByBo(bo.getData()); + } + + /** + * 状态修改 + */ + @ApiOperation("状态修改") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenantPackage:edit") + @Log(title = "租户套餐", businessType = BusinessType.UPDATE) + @PostMapping("/changeStatus") + public void changeStatus(@RequestBody Request bo) { + tenantPackageService.updatePackageStatus(bo.getData()); + } + + /** + * 删除租户套餐 + * + */ + @ApiOperation("删除租户套餐") + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenantPackage:remove") + @Log(title = "租户套餐", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@RequestBody Request> bo) { + tenantPackageService.deleteWithValidByIds(bo.getData(), true); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserController.java new file mode 100644 index 0000000..ee2e438 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserController.java @@ -0,0 +1,305 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.excel.core.ExcelResult; +import cc.iotkit.common.excel.utils.ExcelUtil; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.model.LoginUser; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.tenant.helper.TenantHelper; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.common.validate.QueryGroup; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.data.config.TenantContext; +import cc.iotkit.system.dto.bo.SysDeptBo; +import cc.iotkit.system.dto.bo.SysUserBo; +import cc.iotkit.system.dto.bo.SysUserRolesBo; +import cc.iotkit.system.dto.vo.*; +import cc.iotkit.system.listener.SysUserImportListener; +import cc.iotkit.system.service.*; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.dev33.satoken.secure.BCrypt; +import cn.hutool.core.lang.tree.Tree; +import cn.hutool.core.util.ObjectUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.List; + +/** + * 用户信息 + * + * @author Lion Li + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/system/user") +@Api(tags = "用户信息") +public class SysUserController extends BaseController { + + private final ISysUserService userService; + private final ISysRoleService roleService; + private final ISysPostService postService; + private final ISysDeptService deptService; + private final ISysTenantService tenantService; + + @ApiOperation("获取用户列表") + @SaCheckPermission("system:user:list") + @PostMapping("/list") + public Paging list(@RequestBody @Validated(QueryGroup.class) PageRequest query) { + /* if(LoginHelper.isSuperAdmin()){ + TenantContext.disableTenantFilter();} + //放开租户*/ + return userService.selectPageUserList(query); + } + + @ApiOperation("导出用户列表") + @Log(title = "用户管理", businessType = BusinessType.EXPORT) + @SaCheckPermission("system:user:export") + @PostMapping("/export") + public void export(@Validated(QueryGroup.class) SysUserBo user, + HttpServletResponse response) { + List list = userService.selectUserList(user); + List listVo = MapstructUtils.convert(list, SysUserExportVo.class); + ExcelUtil.exportExcel(listVo, "用户数据", SysUserExportVo.class, response); + } + + /** + * 导入数据 + * + * @param file 导入文件 + * @param updateSupport 是否更新已存在数据 + */ + @ApiOperation("导入数据") + @Log(title = "用户管理", businessType = BusinessType.IMPORT) + @SaCheckPermission("system:user:import") + @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public void importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception { + ExcelResult result = ExcelUtil.importExcel(file.getInputStream(), SysUserImportVo.class, new SysUserImportListener(updateSupport)); + result.getAnalysis(); + } + + /** + * 获取导入模板 + */ + @ApiOperation("获取导入模板") + @PostMapping("/importTemplate") + public void importTemplate(HttpServletResponse response) { + ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", SysUserImportVo.class, response); + } + + /** + * 获取用户信息 + * + * @return 用户信息 + */ + @ApiOperation("获取用户信息") + @PostMapping("/getInfo") + public UserInfoVo getInfo() { + UserInfoVo userInfoVo = new UserInfoVo(); + LoginUser loginUser = LoginHelper.getLoginUser(); + if (LoginHelper.isSuperAdmin()) { + // 超级管理员 如果重新加载用户信息需清除动态租户 + TenantHelper.clearDynamic(); + } + SysUserVo user = userService.selectUserById(loginUser.getUserId()); + userInfoVo.setUser(user); + userInfoVo.setPermissions(loginUser.getMenuPermission()); + userInfoVo.setRoles(loginUser.getRolePermission()); + return userInfoVo; + } + + /** + * 根据用户编号获取详细信息 + * 用户ID + */ + @ApiOperation("根据用户编号获取详细信息") + @SaCheckPermission("system:user:query") + @PostMapping(value = {"/getDetail"}) + public SysUserInfoVo getInfo(@Validated @RequestBody Request req) { + Long userId = req.getData(); + userService.checkUserDataScope(userId); + SysUserInfoVo userInfoVo = new SysUserInfoVo(); + List roles = roleService.selectRoleAll(); + userInfoVo.setRoles(LoginHelper.isSuperAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isSuperAdmin())); + userInfoVo.setPosts(postService.selectPostAll()); + if (ObjectUtil.isNotNull(userId)) { + SysUserVo sysUser = userService.selectUserById(userId); + userInfoVo.setUser(sysUser); + userInfoVo.setRoleIds(StreamUtils.toList(sysUser.getRoles(), SysRoleVo::getId)); + userInfoVo.setPostIds(postService.selectPostListByUserId(userId)); + } + return userInfoVo; + } + + /** + * 新增用户 + */ + @ApiOperation("新增用户") + @SaCheckPermission("system:user:add") + @Log(title = "用户管理", businessType = BusinessType.INSERT) + @PostMapping("/add") + public void add(@Validated(AddGroup.class) @RequestBody Request reqUser) { + SysUserBo user = reqUser.getData(); + if (!userService.checkUserNameUnique(user)) { + fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); + } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { + fail("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); + } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { + fail("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); + } + if (!tenantService.checkAccountBalance(TenantHelper.getTenantId())) { + fail("当前租户下用户名额不足,请联系管理员"); + } + user.setPassword(BCrypt.hashpw(user.getPassword())); + user.setUserType("sys_user"); + userService.insertUser(user); + } + + /** + * 修改用户 + */ + @ApiOperation("修改用户") + @SaCheckPermission("system:user:edit") + @Log(title = "用户管理", businessType = BusinessType.UPDATE) + @PostMapping("/edit") + public void edit(@Validated(EditGroup.class) @RequestBody Request reqUser) { + SysUserBo user = reqUser.getData(); + userService.checkUserAllowed(user); + userService.checkUserDataScope(user.getId()); + if (!userService.checkUserNameUnique(user)) { + fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); + } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { + fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); + } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { + fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在"); + } + userService.updateUser(user); + } + + /** + * 删除用户 + */ + @ApiOperation("删除用户") + @SaCheckPermission("system:user:remove") + @Log(title = "用户管理", businessType = BusinessType.DELETE) + @PostMapping("/delete") + public void remove(@Validated @RequestBody Request> bo) { + List userIds = bo.getData(); + if (userIds.contains(LoginHelper.getUserId())) { + fail("当前用户不能删除"); + } + userService.deleteUserByIds(userIds); + } + + /** + * 重置密码 + */ + @ApiOperation("重置密码") + @SaCheckPermission("system:user:resetPwd") + @Log(title = "用户管理", businessType = BusinessType.UPDATE) + @PostMapping("/resetPwd") + public void resetPwd(@RequestBody @Validated(EditGroup.class) Request reqUser) { + SysUserBo user = reqUser.getData(); + userService.checkUserAllowed(user); + userService.checkUserDataScope(user.getId()); + user.setPassword(BCrypt.hashpw(user.getPassword())); + userService.resetUserPwd(user.getId(), user.getPassword()); + } + + /** + * 状态修改 + */ + @ApiOperation("状态修改") + @SaCheckPermission("system:user:edit") + @Log(title = "用户管理", businessType = BusinessType.UPDATE) + @PostMapping("/changeStatus") + public void changeStatus(@RequestBody @Validated(EditGroup.class) Request reqUser) { + SysUserBo user = reqUser.getData(); + userService.checkUserAllowed(user); + userService.checkUserDataScope(user.getId()); + userService.updateUserStatus(user.getId(), user.getStatus()); + } + + /** + * 根据用户编号获取授权角色 + */ + @ApiOperation("根据用户编号获取授权角色") + @SaCheckPermission("system:user:query") + @PostMapping("/authRoleByUserId") + public SysUserInfoVo authRole(@Validated @RequestBody Request bo) { + Long userId = bo.getData(); + SysUserVo user = userService.selectUserById(userId); + List roles = roleService.selectRolesByUserId(userId); + SysUserInfoVo userInfoVo = new SysUserInfoVo(); + userInfoVo.setUser(user); + userInfoVo.setRoles(LoginHelper.isSuperAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isSuperAdmin())); + return userInfoVo; + } + + /** + * 用户授权角色 + * + * @param userRole 用户角色 + */ + @ApiOperation("用户授权角色") + @SaCheckPermission("system:user:edit") + @Log(title = "用户管理", businessType = BusinessType.GRANT) + @PostMapping("/authRole") + public void insertAuthRole(@RequestBody @Validated Request userRole) { + SysUserRolesBo data = userRole.getData(); + Long userId = data.getUserId(); + userService.checkUserDataScope(userId); + userService.insertUserAuth(userId, data.getRoleIds()); + } + + /** + * 获取部门树列表 + */ + @ApiOperation("获取部门树列表") + @SaCheckPermission("system:user:list") + @PostMapping("/deptTree") + public List> deptTree(@RequestBody @Validated(QueryGroup.class) Request reqDept) { + + return deptService.selectDeptTreeList(reqDept.getData()); + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserOnlineController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserOnlineController.java new file mode 100644 index 0000000..8f98f9b --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserOnlineController.java @@ -0,0 +1,114 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.controller; + +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.api.Request; +import cc.iotkit.common.constant.CacheConstants; +import cc.iotkit.common.log.annotation.Log; +import cc.iotkit.common.log.enums.BusinessType; +import cc.iotkit.common.model.UserOnlineDTO; +import cc.iotkit.common.redis.utils.RedisUtils; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.web.core.BaseController; +import cc.iotkit.system.dto.SysUserOnline; +import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @Author:tfd + * @Date:2023/5/31 16:08 + */ +@RequiredArgsConstructor +@RestController +@RequestMapping("/monitor/online") +@Api(tags = "用户在线监控") +public class SysUserOnlineController extends BaseController { + + /** + * 获取在线用户监控列表 + */ + @ApiOperation("获取在线用户监控列表") + @SaCheckPermission("monitor:online:list") + @PostMapping("/list") + public Paging list(@RequestBody @Validated Request request) { + SysUserOnline data = request.getData(); + String ipaddr = data.getIpaddr(); + String userName = data.getUserName(); + // 获取所有未过期的 token + List keys = StpUtil.searchTokenValue("", 0, -1, false); + List userOnlineDTOList = new ArrayList<>(); + for (String key : keys) { + String token = StringUtils.substringAfterLast(key, ":"); + // 如果已经过期则跳过 + if (StpUtil.stpLogic.getTokenActivityTimeoutByToken(token) < -1) { + continue; + } + userOnlineDTOList.add(RedisUtils.getCacheObject(CacheConstants.ONLINE_TOKEN_KEY + token)); + } + if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) { + userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline -> + StringUtils.equals(ipaddr, userOnline.getIpaddr()) && + StringUtils.equals(userName, userOnline.getUserName()) + ); + } else if (StringUtils.isNotEmpty(ipaddr)) { + userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline -> + StringUtils.equals(ipaddr, userOnline.getIpaddr()) + ); + } else if (StringUtils.isNotEmpty(userName)) { + userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline -> + StringUtils.equals(userName, userOnline.getUserName()) + ); + } + Collections.reverse(userOnlineDTOList); + userOnlineDTOList.removeAll(Collections.singleton(null)); + List userOnlineList = BeanUtil.copyToList(userOnlineDTOList, SysUserOnline.class); + return new Paging<>(userOnlineList.size(), userOnlineList); + } + + /** + * 强退用户 + */ + @ApiOperation("强退用户") + @SaCheckPermission("monitor:online:forceLogout") + @Log(title = "在线用户", businessType = BusinessType.FORCE) + @PostMapping("/kickoutByTokenValue") + public void forceLogout(@RequestBody @Validated Request bo) { + StpUtil.kickoutByTokenValue(bo.getData()); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/LoginBody.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/LoginBody.java new file mode 100644 index 0000000..8b9e670 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/LoginBody.java @@ -0,0 +1,68 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto; + +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 用户登录对象 + * + * @author Lion Li + */ + +@Data +public class LoginBody { + + /** + * 租户ID + */ + @NotNull(message = "{tenant.number.not.blank}") + private Long tenantId; + + /** + * 用户名 + */ + @NotBlank(message = "{user.username.not.blank}") + private String username; + + /** + * 用户密码 + */ + @NotBlank(message = "{user.password.not.blank}") + private String password; + + /** + * 验证码 + */ + private String code; + + /** + * 唯一标识 + */ + private String uuid; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/RegisterBody.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/RegisterBody.java new file mode 100644 index 0000000..9af16d0 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/RegisterBody.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 用户注册对象 + * + * @author Lion Li + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class RegisterBody extends LoginBody { + + private String userType; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysCache.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysCache.java new file mode 100644 index 0000000..fd6de48 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysCache.java @@ -0,0 +1,70 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto; + +import cc.iotkit.common.utils.StringUtils; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 缓存信息 + * + * @author Lion Li + */ +@Data +@NoArgsConstructor +public class SysCache { + + /** + * 缓存名称 + */ + private String cacheName = ""; + + /** + * 缓存键名 + */ + private String cacheKey = ""; + + /** + * 缓存内容 + */ + private String cacheValue = ""; + + /** + * 备注 + */ + private String remark = ""; + + public SysCache(String cacheName, String remark) { + this.cacheName = cacheName; + this.remark = remark; + } + + public SysCache(String cacheName, String cacheKey, String cacheValue) { + this.cacheName = StringUtils.replace(cacheName, ":", ""); + this.cacheKey = StringUtils.replace(cacheKey, cacheName, ""); + this.cacheValue = cacheValue; + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysRoleMenu.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysRoleMenu.java new file mode 100644 index 0000000..a0cd44c --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysRoleMenu.java @@ -0,0 +1,47 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto; + +import lombok.Data; + +/** + * 角色和菜单关联 + * + * @author Lion Li + */ + +@Data +public class SysRoleMenu { + + /** + * 角色ID + */ + private Long roleId; + + /** + * 菜单ID + */ + private Long menuId; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysUserOnline.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysUserOnline.java new file mode 100644 index 0000000..e1c905d --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysUserOnline.java @@ -0,0 +1,77 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto; + +import lombok.Data; + +/** + * 当前在线会话 + * + * @author Lion Li + */ + +@Data +public class SysUserOnline { + + /** + * 会话编号 + */ + private String tokenId; + + /** + * 部门名称 + */ + private String deptName; + + /** + * 用户名称 + */ + private String userName; + + /** + * 登录IP地址 + */ + private String ipaddr; + + /** + * 登录地址 + */ + private String loginLocation; + + /** + * 浏览器类型 + */ + private String browser; + + /** + * 操作系统 + */ + private String os; + + /** + * 登录时间 + */ + private Long loginTime; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysUserPost.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysUserPost.java new file mode 100644 index 0000000..124cdff --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/SysUserPost.java @@ -0,0 +1,47 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto; + +import lombok.Data; + +/** + * 用户和岗位关联 + * + * @author Lion Li + */ + +@Data +public class SysUserPost { + + /** + * 用户ID + */ + private Long userId; + + /** + * 岗位ID + */ + private Long postId; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysAppBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysAppBo.java new file mode 100644 index 0000000..56c6737 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysAppBo.java @@ -0,0 +1,88 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysApp; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotNull; + +/** + * 应用信息业务对象 SYS_APP + * + * @author tfd + * @date 2023-08-10 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysApp.class, reverseConvertGenerate = false) +public class SysAppBo extends BaseDto { + + + @NotNull(message = "id不能为空", groups = { EditGroup.class }) + @ApiModelProperty(value = "id", required = true) + private Long id; + + /** + * 应用名称 + */ + @ApiModelProperty(value = "应用名称", required = true) + private String appName; + + /** + * appId + */ + @NotBlank(message = "appId不能为空", groups = { AddGroup.class, EditGroup.class }) + @ApiModelProperty(value = "appId", required = true) + private String appId; + + /** + * appSecret + */ + @NotBlank(message = "appSecret不能为空", groups = { AddGroup.class, EditGroup.class }) + @ApiModelProperty(value = "appSecret", required = true) + private String appSecret; + + /** + * 应用类型 + */ + @NotBlank(message = "应用类型不能为空", groups = { AddGroup.class, EditGroup.class }) + @ApiModelProperty(value = "应用类型", required = true) + private String appType; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注", required = true) + private String remark; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysChangePwdBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysChangePwdBo.java new file mode 100644 index 0000000..672e728 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysChangePwdBo.java @@ -0,0 +1,47 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * 个人信息业务处理 + * + * @author Michelle.Chung + */ + +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class SysChangePwdBo extends BaseDto { + + @ApiModelProperty(value = "旧密码") + private String oldPassword; + @ApiModelProperty(value = "新密码") + private String newPassword; +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysConfigBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysConfigBo.java new file mode 100644 index 0000000..4f62151 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysConfigBo.java @@ -0,0 +1,86 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysConfig; +import io.github.linpeilie.annotations.AutoMapper; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 参数配置业务对象 sys_config + * + * @author Michelle.Chung + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysConfig.class, reverseConvertGenerate = false) +public class SysConfigBo extends BaseDto { + + /** + * 参数主键 + */ + @NotNull(message = "参数主键不能为空", groups = {EditGroup.class}) + private Long id; + + /** + * 参数名称 + */ + @NotBlank(message = "参数名称不能为空", groups = {AddGroup.class, EditGroup.class}) + @Size(min = 0, max = 100, message = "参数名称不能超过{max}个字符") + private String configName; + + /** + * 参数键名 + */ + @NotBlank(message = "参数键名不能为空", groups = {AddGroup.class, EditGroup.class}) + @Size(min = 0, max = 100, message = "参数键名长度不能超过{max}个字符") + private String configKey; + + /** + * 参数键值 + */ + @NotBlank(message = "参数键值不能为空", groups = {AddGroup.class, EditGroup.class}) + @Size(min = 0, max = 500, message = "参数键值长度不能超过{max}个字符") + private String configValue; + + /** + * 系统内置(Y是 N否) + */ + private String configType; + + /** + * 备注 + */ + private String remark; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysDeptBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysDeptBo.java new file mode 100644 index 0000000..ee7d771 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysDeptBo.java @@ -0,0 +1,99 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysDept; +import io.github.linpeilie.annotations.AutoMapper; +import javax.validation.constraints.Email; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 部门业务对象 sys_dept + * + * @author Michelle.Chung + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysDept.class, reverseConvertGenerate = false) +public class SysDeptBo extends BaseDto { + + /** + * 部门id + */ + @NotNull(message = "部门id不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 父部门ID + */ + private Long parentId; + + /** + * 部门名称 + */ + @NotBlank(message = "部门名称不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 30, message = "部门名称长度不能超过{max}个字符") + private String deptName; + + /** + * 显示顺序 + */ + @NotNull(message = "显示顺序不能为空", groups = { AddGroup.class, EditGroup.class }) + private Integer orderNum; + + /** + * 负责人 + */ + private String leader; + + /** + * 联系电话 + */ + @Size(min = 0, max = 11, message = "联系电话长度不能超过{max}个字符") + private String phone; + + /** + * 邮箱 + */ + // @Email(message = "邮箱格式不正确") + @Size(min = 0, max = 50, message = "邮箱长度不能超过{max}个字符") + private String email; + + /** + * 部门状态(0正常 1停用) + */ + private String status; + /** + * 部门与区域(默认0是部门,1是区域) + */ + private Integer areaType; +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysDictDataBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysDictDataBo.java new file mode 100644 index 0000000..b13f20e --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysDictDataBo.java @@ -0,0 +1,111 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysDictData; +import io.github.linpeilie.annotations.AutoMapper; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 字典数据业务对象 sys_dict_data + * + * @author Michelle.Chung + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysDictData.class, reverseConvertGenerate = false) +public class SysDictDataBo extends BaseDto { + + /** + * 字典编码 + */ + @NotNull(message = "字典编码不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 字典排序 + */ + private Integer dictSort; + + /** + * 字典标签 + */ + @NotBlank(message = "字典标签不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 100, message = "字典标签长度不能超过{max}个字符") + private String dictLabel; + + /** + * 字典键值 + */ + @NotBlank(message = "字典键值不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 100, message = "字典键值长度不能超过{max}个字符") + private String dictValue; + + /** + * 字典类型 + */ + @NotBlank(message = "字典类型不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 100, message = "字典类型长度不能超过{max}个字符") + private String dictType; + + /** + * 样式属性(其他样式扩展) + */ + @Size(min = 0, max = 100, message = "样式属性长度不能超过{max}个字符") + private String cssClass; + + /** + * 表格回显样式 + */ + private String listClass; + + /** + * 是否默认(Y是 N否) + */ + private String isDefault; + + /** + * 状态(0正常 1停用) + */ + private String status; + + /** + * 创建部门 + */ + private Long createDept; + + /** + * 备注 + */ + private String remark; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysDictTypeBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysDictTypeBo.java new file mode 100644 index 0000000..587b523 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysDictTypeBo.java @@ -0,0 +1,81 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysDictType; +import io.github.linpeilie.annotations.AutoMapper; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 字典类型业务对象 sys_dict_type + * + * @author Michelle.Chung + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysDictType.class, reverseConvertGenerate = false) +public class SysDictTypeBo extends BaseDto { + + /** + * 字典主键 + */ + @NotNull(message = "字典主键不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 字典名称 + */ + @NotBlank(message = "字典名称不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 100, message = "字典类型名称长度不能超过{max}个字符") + private String dictName; + + /** + * 字典类型 + */ + @NotBlank(message = "字典类型不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 100, message = "字典类型类型长度不能超过{max}个字符") + @Pattern(regexp = "^[a-z][a-z0-9_]*$", message = "字典类型必须以字母开头,且只能为(小写字母,数字,下滑线)") + private String dictType; + + /** + * 状态(0正常 1停用) + */ + private String status; + + /** + * 备注 + */ + private String remark; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysLoginInfoBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysLoginInfoBo.java new file mode 100644 index 0000000..c1567c0 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysLoginInfoBo.java @@ -0,0 +1,100 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.model.system.SysLoginInfo; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 系统访问记录业务对象 sys_logininfor + * + * @author Michelle.Chung + */ + +@Data +@AutoMapper(target = SysLoginInfo.class, reverseConvertGenerate = false) +public class SysLoginInfoBo { + + /** + * 访问ID + */ + private Long id; + + /** + * 租户编号 + */ + private Long tenantId; + + /** + * 用户账号 + */ + private String userName; + + /** + * 登录IP地址 + */ + private String ipaddr; + + /** + * 登录地点 + */ + private String loginLocation; + + /** + * 浏览器类型 + */ + private String browser; + + /** + * 操作系统 + */ + private String os; + + /** + * 登录状态(0成功 1失败) + */ + private String status; + + /** + * 提示消息 + */ + private String msg; + + /** + * 访问时间 + */ + private Date loginTime; + + /** + * 请求参数 + */ + private Map params = new HashMap<>(); + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysMenuBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysMenuBo.java new file mode 100644 index 0000000..6781c28 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysMenuBo.java @@ -0,0 +1,134 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysMenu; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.github.linpeilie.annotations.AutoMapper; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 菜单权限业务对象 sys_menu + * + * @author Michelle.Chung + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysMenu.class, reverseConvertGenerate = false) +public class SysMenuBo extends BaseDto { + + /** + * 菜单ID + */ + @NotNull(message = "菜单ID不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 父菜单ID + */ + private Long parentId; + + /** + * 菜单名称 + */ + @NotBlank(message = "菜单名称不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 50, message = "菜单名称长度不能超过{max}个字符") + private String menuName; + + /** + * 显示顺序 + */ + @NotNull(message = "显示顺序不能为空", groups = { AddGroup.class, EditGroup.class }) + private Integer orderNum; + + /** + * 路由地址 + */ + @Size(min = 0, max = 200, message = "路由地址不能超过{max}个字符") + private String path; + + /** + * 组件路径 + */ + @Size(min = 0, max = 200, message = "组件路径不能超过{max}个字符") + private String component; + + /** + * 路由参数 + */ + private String queryParam; + + /** + * 是否为外链(0是 1否) + */ + private String isFrame; + + /** + * 是否缓存(0缓存 1不缓存) + */ + private String isCache; + + /** + * 菜单类型(M目录 C菜单 F按钮) + */ + @NotBlank(message = "菜单类型不能为空", groups = { AddGroup.class, EditGroup.class }) + private String menuType; + + /** + * 显示状态(0显示 1隐藏) + */ + private String visible; + + /** + * 菜单状态(0正常 1停用) + */ + private String status; + + /** + * 权限标识 + */ + @JsonInclude(JsonInclude.Include.NON_NULL) + @Size(min = 0, max = 100, message = "权限标识长度不能超过{max}个字符") + private String perms; + + /** + * 菜单图标 + */ + private String icon; + + /** + * 备注 + */ + private String remark; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysNoticeBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysNoticeBo.java new file mode 100644 index 0000000..42d2c8b --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysNoticeBo.java @@ -0,0 +1,86 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysNotice; +import io.github.linpeilie.annotations.AutoMapper; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 通知公告业务对象 sys_notice + * + * @author Michelle.Chung + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysNotice.class, reverseConvertGenerate = false) +public class SysNoticeBo extends BaseDto { + + /** + * 公告ID + */ + @NotNull(message = "公告ID不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 公告标题 + */ + @NotBlank(message = "公告标题不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 50, message = "公告标题不能超过{max}个字符") + private String noticeTitle; + + /** + * 公告类型(1通知 2公告) + */ + private String noticeType; + + /** + * 公告内容 + */ + private String noticeContent; + + /** + * 公告状态(0正常 1关闭) + */ + private String status; + + /** + * 备注 + */ + private String remark; + + /** + * 创建人名称 + */ + private String createByName; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysOperLogBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysOperLogBo.java new file mode 100644 index 0000000..f13bff7 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysOperLogBo.java @@ -0,0 +1,151 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.log.event.OperLogEvent; +import cc.iotkit.model.system.SysOperLog; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMappers; +import lombok.Data; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 操作日志记录业务对象 sys_oper_log + * + * @author Michelle.Chung + * @date 2023-02-07 + */ + +@Data +@AutoMappers({ + @AutoMapper(target = SysOperLog.class, reverseConvertGenerate = false), + @AutoMapper(target = OperLogEvent.class) +}) +public class SysOperLogBo extends BaseDto { + + /** + * 日志主键 + */ + private Long id; + + /** + * 租户编号 + */ + private Long tenantId; + + /** + * 模块标题 + */ + private String title; + + /** + * 业务类型(0其它 1新增 2修改 3删除) + */ + private Integer businessType; + + /** + * 业务类型数组 + */ + private Integer[] businessTypes; + + /** + * 方法名称 + */ + private String method; + + /** + * 请求方式 + */ + private String requestMethod; + + /** + * 操作类别(0其它 1后台用户 2手机端用户) + */ + private Integer operatorType; + + /** + * 操作人员 + */ + private String operName; + + /** + * 部门名称 + */ + private String deptName; + + /** + * 请求URL + */ + private String operUrl; + + /** + * 主机地址 + */ + private String operIp; + + /** + * 操作地点 + */ + private String operLocation; + + /** + * 请求参数 + */ + private String operParam; + + /** + * 返回参数 + */ + private String jsonResult; + + /** + * 操作状态(0正常 1异常) + */ + private Integer status; + + /** + * 错误消息 + */ + private String errorMsg; + + /** + * 操作时间 + */ + private Date operTime; + + /** + * 消耗时间 + */ + private Long costTime; + + /** + * 请求参数 + */ + private Map params = new HashMap<>(); + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysOssBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysOssBo.java new file mode 100644 index 0000000..681df79 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysOssBo.java @@ -0,0 +1,72 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.model.system.SysOss; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * OSS对象存储分页查询对象 sys_oss + * + * @author Lion Li + */ +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysOss.class, reverseConvertGenerate = false) +public class SysOssBo extends BaseDto { + + /** + * ossId + */ + private Long id; + + /** + * 文件名 + */ + private String fileName; + + /** + * 原名 + */ + private String originalName; + + /** + * 文件后缀名 + */ + private String fileSuffix; + + /** + * URL地址 + */ + private String url; + + /** + * 服务商 + */ + private String service; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysOssConfigBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysOssConfigBo.java new file mode 100644 index 0000000..c070ffe --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysOssConfigBo.java @@ -0,0 +1,132 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysOssConfig; +import io.github.linpeilie.annotations.AutoMapper; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 对象存储配置业务对象 sys_oss_config + * + * @author Lion Li + * @author 孤舟烟雨 + * @date 2021-08-13 + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysOssConfig.class, reverseConvertGenerate = false) +public class SysOssConfigBo extends BaseDto { + + /** + * 主建 + */ + @NotNull(message = "主建不能为空", groups = {EditGroup.class}) + private Long id; + + /** + * 配置key + */ + @NotBlank(message = "配置key不能为空", groups = {AddGroup.class, EditGroup.class}) + @Size(min = 2, max = 100, message = "configKey长度必须介于{min}和{max} 之间") + private String configKey; + + /** + * accessKey + */ + @NotBlank(message = "accessKey不能为空", groups = {AddGroup.class, EditGroup.class}) + @Size(min = 2, max = 100, message = "accessKey长度必须介于{min}和{max} 之间") + private String accessKey; + + /** + * 秘钥 + */ + @NotBlank(message = "secretKey不能为空", groups = {AddGroup.class, EditGroup.class}) + @Size(min = 2, max = 100, message = "secretKey长度必须介于{min}和{max} 之间") + private String secretKey; + + /** + * 桶名称 + */ + @NotBlank(message = "桶名称不能为空", groups = {AddGroup.class, EditGroup.class}) + @Size(min = 2, max = 100, message = "bucketName长度必须介于{min}和{max}之间") + private String bucketName; + + /** + * 前缀 + */ + private String prefix; + + /** + * 访问站点 + */ + @NotBlank(message = "访问站点不能为空", groups = {AddGroup.class, EditGroup.class}) + @Size(min = 2, max = 100, message = "endpoint长度必须介于{min}和{max}之间") + private String endpoint; + + /** + * 自定义域名 + */ + private String domain; + + /** + * 是否https(Y=是,N=否) + */ + private String isHttps; + + /** + * 是否默认(0=是,1=否) + */ + private String status; + + /** + * 域 + */ + private String region; + + /** + * 扩展字段 + */ + private String ext1; + + /** + * 备注 + */ + private String remark; + + /** + * 桶权限类型(0private 1public 2custom) + */ + @NotBlank(message = "桶权限类型不能为空", groups = {AddGroup.class, EditGroup.class}) + private String accessPolicy; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysPostBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysPostBo.java new file mode 100644 index 0000000..d61837a --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysPostBo.java @@ -0,0 +1,85 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysPost; +import io.github.linpeilie.annotations.AutoMapper; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 岗位信息业务对象 sys_post + * + * @author Michelle.Chung + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysPost.class, reverseConvertGenerate = false) +public class SysPostBo extends BaseDto { + + /** + * 岗位ID + */ + @NotNull(message = "岗位ID不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 岗位编码 + */ + @NotBlank(message = "岗位编码不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 64, message = "岗位编码长度不能超过{max}个字符") + private String postCode; + + /** + * 岗位名称 + */ + @NotBlank(message = "岗位名称不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 50, message = "岗位名称长度不能超过{max}个字符") + private String postName; + + /** + * 显示顺序 + */ + @NotNull(message = "显示顺序不能为空", groups = { AddGroup.class, EditGroup.class }) + private Integer postSort; + + /** + * 状态(0正常 1停用) + */ + private String status; + + /** + * 备注 + */ + private String remark; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysRoleAuthBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysRoleAuthBo.java new file mode 100644 index 0000000..65eb283 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysRoleAuthBo.java @@ -0,0 +1,55 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModelProperty; +import javax.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * 角色信息业务对象 sys_role + * + * @author Michelle.Chung + */ + +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class SysRoleAuthBo extends BaseDto { + + + @ApiModelProperty(value = "角色ID") + @NotNull(message = "角色ID不能为空") + private Long roleId; + + + @ApiModelProperty(value = "用户ID列表") + private Long[] userIds; + + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysRoleBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysRoleBo.java new file mode 100644 index 0000000..f65bc13 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysRoleBo.java @@ -0,0 +1,120 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysRole; +import io.github.linpeilie.annotations.AutoMapper; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * 角色信息业务对象 sys_role + * + * @author Michelle.Chung + */ + +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysRole.class, reverseConvertGenerate = false) +public class SysRoleBo extends BaseDto { + + /** + * 角色ID + */ + @NotNull(message = "角色ID不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 角色名称 + */ + @NotBlank(message = "角色名称不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 30, message = "角色名称长度不能超过{max}个字符") + private String roleName; + + /** + * 角色权限字符串 + */ + @NotBlank(message = "角色权限字符串不能为空", groups = { AddGroup.class, EditGroup.class }) + @Size(min = 0, max = 100, message = "权限字符长度不能超过{max}个字符") + private String roleKey; + + /** + * 显示顺序 + */ + @NotNull(message = "显示顺序不能为空", groups = { AddGroup.class, EditGroup.class }) + private Integer roleSort; + + /** + * 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限) + */ + private String dataScope; + + /** + * 菜单树选择项是否关联显示 + */ + private Boolean menuCheckStrictly; + + /** + * 部门树选择项是否关联显示 + */ + private Boolean deptCheckStrictly; + + /** + * 角色状态(0正常 1停用) + */ + private String status; + + /** + * 备注 + */ + private String remark; + + /** + * 菜单组 + */ + private Long[] menuIds; + + /** + * 部门组(数据权限) + */ + private Long[] deptIds; + + public SysRoleBo(Long roleId) { + this.id = roleId; + } + + public boolean isSuperAdmin() { + return UserConstants.SUPER_ADMIN_ID.equals(this.id); + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysTenantBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysTenantBo.java new file mode 100644 index 0000000..78e58be --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysTenantBo.java @@ -0,0 +1,140 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.utils.DateUtils; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysTenant; +import io.github.linpeilie.annotations.AutoMapper; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; +import java.util.Date; + +/** + * 租户业务对象 sys_tenant + * + * @author Michelle.Chung + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysTenant.class, reverseConvertGenerate = false) +public class SysTenantBo extends BaseDto { + + /** + * id + */ + private Long id; + + /** + * 租户编号 + */ + private Long tenantId; + + /** + * 联系人 + */ + @NotBlank(message = "联系人不能为空", groups = { AddGroup.class, EditGroup.class }) + private String contactUserName; + + /** + * 联系电话 + */ + @NotBlank(message = "联系电话不能为空", groups = { AddGroup.class, EditGroup.class }) + private String contactPhone; + + /** + * 企业名称 + */ + @NotBlank(message = "企业名称不能为空", groups = { AddGroup.class, EditGroup.class }) + private String companyName; + + /** + * 用户名(创建系统用户) + */ + @NotBlank(message = "用户名不能为空", groups = { AddGroup.class }) + private String username; + + /** + * 密码(创建系统用户) + */ + @NotBlank(message = "密码不能为空", groups = { AddGroup.class }) + private String password; + + /** + * 统一社会信用代码 + */ + private String licenseNumber; + + /** + * 地址 + */ + private String address; + + /** + * 域名 + */ + private String domain; + + /** + * 企业简介 + */ + private String intro; + + /** + * 备注 + */ + private String remark; + + /** + * 租户套餐编号 + */ + @NotNull(message = "租户套餐不能为空", groups = { AddGroup.class }) + private Long packageId; + + /** + * 过期时间 + */ + @DateTimeFormat(pattern = DateUtils.YYYY_MM_DD_HH_MM_SS) + private Date expireTime; + + /** + * 用户数量(-1不限制) + */ + private Long accountCount; + + /** + * 租户状态(0正常 1停用) + */ + private String status; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysTenantPackageBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysTenantPackageBo.java new file mode 100644 index 0000000..1d63ee8 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysTenantPackageBo.java @@ -0,0 +1,82 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysTenantPackage; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.AutoMapping; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 租户套餐业务对象 sys_tenant_package + * + * @author Michelle.Chung + */ + +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysTenantPackage.class, reverseConvertGenerate = false) +public class SysTenantPackageBo extends BaseDto { + + /** + * 租户套餐id + */ + @NotNull(message = "租户套餐id不能为空", groups = {EditGroup.class}) + private Long packageId; + + /** + * 套餐名称 + */ + @NotBlank(message = "套餐名称不能为空", groups = {AddGroup.class, EditGroup.class}) + private String packageName; + + /** + * 关联菜单id + */ + @AutoMapping(target = "menuIds", expression = "java(cc.iotkit.common.utils.StringUtils.join(source.getMenuIds(), \",\"))") + private Long[] menuIds; + + /** + * 备注 + */ + private String remark; + + /** + * 菜单树选择项是否关联显示 + */ + private Boolean menuCheckStrictly; + + /** + * 状态(0正常 1停用) + */ + private String status; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserBo.java new file mode 100644 index 0000000..88dfeda --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserBo.java @@ -0,0 +1,144 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.validate.EditGroup; +import cc.iotkit.model.system.SysUser; +import io.github.linpeilie.annotations.AutoMapper; +import javax.validation.constraints.Email; + +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +/** + * 用户信息业务对象 sys_user + * + * @author Michelle.Chung + */ + +@Data +@NoArgsConstructor + +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = SysUser.class, reverseConvertGenerate = false) +public class SysUserBo extends BaseDto { + + /** + * 用户ID + */ + @NotNull(message = "用户ID不能为空", groups = {EditGroup.class}) + private Long id; + + /** + * 部门ID + */ + private Long deptId; + + /** + * 用户账号 + */ + @NotBlank(message = "用户账号不能为空") + @Size(min = 0, max = 30, message = "用户账号长度不能超过{max}个字符") + private String userName; + //@Size(min = 0, max = 30, message = "用户账号长度不能超过{max}个字符") + private Map params; + /** + * 用户昵称 + */ + @Size(min = 0, max = 30, message = "用户昵称长度不能超过{max}个字符") + private String nickName; + + /** + * 用户类型(sys_user系统用户) + */ + private String userType; + + /** + * 用户邮箱 + */ + // @Email(message = "邮箱格式不正确") + @Size(min = 0, max = 50, message = "邮箱长度不能超过{max}个字符") + private String email; + + /** + * 手机号码 + */ + private String phonenumber; + + /** + * 用户性别(0男 1女 2未知) + */ + private String sex; + + /** + * 密码 + */ + private String password; + + /** + * 帐号状态(0正常 1停用) + */ + private String status; + + /** + * 备注 + */ + private String remark; + + /** + * 角色组 + */ + @Size(min = 1, message = "用户角色不能为空") + private List roleIds; + // @ApiModelProperty(value="部门表-区域id") + private Long deptAreaId; + /** + * 岗位组 + */ + private List postIds; + + /** + * 数据权限 当前角色ID + */ + private Long roleId; + + public SysUserBo(Long id) { + this.id = id; + } + + public boolean isSuperAdmin() { + return UserConstants.SUPER_ADMIN_ID.equals(this.id); + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserProfileBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserProfileBo.java new file mode 100644 index 0000000..bf3376b --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserProfileBo.java @@ -0,0 +1,75 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import javax.validation.constraints.Email; +import javax.validation.constraints.Size; + +import cc.iotkit.common.validate.AddGroup; +import cc.iotkit.common.validate.EditGroup; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * 个人信息业务处理 + * + * @author Michelle.Chung + */ + +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class SysUserProfileBo extends BaseDto { + + /** + * 用户ID + */ + private Long id; + + /** + * 用户昵称 + */ + @Size(min = 0, max = 30, message = "用户昵称长度不能超过{max}个字符") + private String nickName; + + /** + * 用户邮箱 + */ + // @Email(message = "邮箱格式不正确") + @Size(min = 0, max = 50, message = "邮箱长度不能超过{max}个字符") + private String email; + + /** + * 手机号码 + */ + private String phonenumber; + + /** + * 用户性别(0男 1女 2未知) + */ + private String sex; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserRolesBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserRolesBo.java new file mode 100644 index 0000000..c75245f --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserRolesBo.java @@ -0,0 +1,58 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * 用户权限设置 + * + * @author sjg + */ + +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class SysUserRolesBo extends BaseDto { + + /** + * 用户ID + */ + @NotNull(message = "用户ID不能为空") + private Long userId; + + /** + * 角色组 + */ + @Size(min = 1, message = "用户角色不能为空") + private List roleIds; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/UserOnlineBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/UserOnlineBo.java new file mode 100644 index 0000000..bd17124 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/UserOnlineBo.java @@ -0,0 +1,60 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.api.BaseDto; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * 用户信息业务对象 sys_user + * + * @author Michelle.Chung + */ + +@Data +@NoArgsConstructor + +@EqualsAndHashCode(callSuper = true) +public class UserOnlineBo extends BaseDto { + + + /** + * 用户账号 + */ + + @ApiModelProperty(value = "用户账号") + private String ipaddr; + + /** + * 用户昵称 + */ + + @ApiModelProperty("用户昵称") + private String userName; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/XcxLoginBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/XcxLoginBo.java new file mode 100644 index 0000000..b9d7f4b --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/XcxLoginBo.java @@ -0,0 +1,53 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.validator.constraints.NotBlank; +import lombok.Data; + +/** + * 小程序登录对象 + * + * @author tfd + */ + +@Data +public class XcxLoginBo { + + /** + * appId + */ + @ApiModelProperty("appId") + @NotBlank(message = "appId不能为空") + private String appId; + + /** + * 授权码 + */ + @ApiModelProperty("授权码") + @NotBlank(message = "code不能为空") + private String code; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/XcxLoginUserBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/XcxLoginUserBo.java new file mode 100644 index 0000000..2c0bc04 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/XcxLoginUserBo.java @@ -0,0 +1,50 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.bo; + +import cc.iotkit.common.model.LoginUser; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + + +/** + * 小程序登录用户身份权限 + * + * @author Lion Li + */ +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +public class XcxLoginUserBo extends LoginUser { + + + private static final long serialVersionUID = 1L; + + /** + * openid + */ + private String openid; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/AvatarVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/AvatarVo.java new file mode 100644 index 0000000..1403842 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/AvatarVo.java @@ -0,0 +1,41 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import lombok.Data; + +/** + * 用户头像信息 + * + * @author Michelle.Chung + */ +@Data +public class AvatarVo { + + /** + * 头像地址 + */ + private String imgUrl; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/CacheListInfoVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/CacheListInfoVo.java new file mode 100644 index 0000000..f24e149 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/CacheListInfoVo.java @@ -0,0 +1,46 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import lombok.Data; + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +/** + * 缓存监控列表信息 + * + * @author Michelle.Chung + */ +@Data +public class CacheListInfoVo { + + private Properties info; + + private Long dbSize; + + private List> commandStats; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/DeptTreeSelectVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/DeptTreeSelectVo.java new file mode 100644 index 0000000..91650df --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/DeptTreeSelectVo.java @@ -0,0 +1,49 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cn.hutool.core.lang.tree.Tree; +import lombok.Data; + +import java.util.List; + +/** + * 角色部门列表树信息 + * + * @author Michelle.Chung + */ +@Data +public class DeptTreeSelectVo { + + /** + * 选中部门列表 + */ + private List checkedKeys; + + /** + * 下拉树结构列表 + */ + private List> depts; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/MenuTreeSelectVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/MenuTreeSelectVo.java new file mode 100644 index 0000000..b07cce1 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/MenuTreeSelectVo.java @@ -0,0 +1,49 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cn.hutool.core.lang.tree.Tree; +import lombok.Data; + +import java.util.List; + +/** + * 角色菜单列表树信息 + * + * @author Michelle.Chung + */ +@Data +public class MenuTreeSelectVo { + + /** + * 选中菜单列表 + */ + private List checkedKeys; + + /** + * 菜单下拉树结构列表 + */ + private List> menus; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/MetaVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/MetaVo.java new file mode 100644 index 0000000..99cea2a --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/MetaVo.java @@ -0,0 +1,84 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.utils.StringUtils; +import lombok.Data; + +/** + * 路由显示信息 + * + * @author ruoyi + */ + +@Data +public class MetaVo { + + /** + * 设置该路由在侧边栏和面包屑中展示的名字 + */ + private String title; + + /** + * 设置该路由的图标,对应路径src/assets/icons/svg + */ + private String icon; + + /** + * 设置为true,则不会被 缓存 + */ + private boolean noCache; + + /** + * 内链地址(http(s)://开头) + */ + private String link; + + public MetaVo(String title, String icon) { + this.title = title; + this.icon = icon; + } + + public MetaVo(String title, String icon, boolean noCache) { + this.title = title; + this.icon = icon; + this.noCache = noCache; + } + + public MetaVo(String title, String icon, String link) { + this.title = title; + this.icon = icon; + this.link = link; + } + + public MetaVo(String title, String icon, boolean noCache, String link) { + this.title = title; + this.icon = icon; + this.noCache = noCache; + if (StringUtils.ishttp(link)) { + this.link = link; + } + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/ProfileVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/ProfileVo.java new file mode 100644 index 0000000..e11b7c1 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/ProfileVo.java @@ -0,0 +1,52 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import lombok.Data; + +/** + * 用户个人信息 + * + * @author Michelle.Chung + */ +@Data +public class ProfileVo { + + /** + * 用户信息 + */ + private SysUserVo user; + + /** + * 用户所属角色组 + */ + private String roleGroup; + + /** + * 用户所属岗位组 + */ + private String postGroup; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/RouterVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/RouterVo.java new file mode 100644 index 0000000..f7d9d11 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/RouterVo.java @@ -0,0 +1,85 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.util.List; + +/** + * 路由配置信息 + * + * @author Lion Li + */ +@Data +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class RouterVo { + + /** + * 路由名字 + */ + private String name; + + /** + * 路由地址 + */ + private String path; + + /** + * 是否隐藏路由,当设置 true 的时候该路由不会再侧边栏出现 + */ + private boolean hidden; + + /** + * 重定向地址,当设置 noRedirect 的时候该路由在面包屑导航中不可被点击 + */ + private String redirect; + + /** + * 组件地址 + */ + private String component; + + /** + * 路由参数:如 {"id": 1, "name": "ry"} + */ + private String query; + + /** + * 当你一个路由下面的 children 声明的路由大于1个时,自动会变成嵌套的模式--如组件页面 + */ + private Boolean alwaysShow; + + /** + * 其他元素 + */ + private MetaVo meta; + + /** + * 子路由 + */ + private List children; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysAppVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysAppVo.java new file mode 100644 index 0000000..88e4b99 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysAppVo.java @@ -0,0 +1,93 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.model.system.SysApp; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + + + +/** + * 应用信息视图对象 SYS_APP + * + * @author tfd + * @date 2023-08-10 + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysApp.class) +public class SysAppVo implements Serializable { + + + private static final long serialVersionUID = 1L; + + /** + * id + */ + @ApiModelProperty(value = "id") + private Long id; + + /** + * 租户id + */ + @ApiModelProperty(value = "租户id") + private Long tenantId; + + /** + * 应用名称 + */ + @ApiModelProperty(value = "应用名称") + private String appName; + + /** + * appId + */ + @ApiModelProperty(value = "appId") + private String appId; + + /** + * appSecret + */ + @ApiModelProperty(value = "appSecret") + private String appSecret; + + /** + * 应用类型 + */ + @ApiModelProperty(value = "应用类型") + private String appType; + + /** + * 备注 + */ + @ApiModelProperty(value = "备注") + private String remark; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysConfigVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysConfigVo.java new file mode 100644 index 0000000..54e0c2d --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysConfigVo.java @@ -0,0 +1,92 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import cc.iotkit.model.system.SysConfig; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 参数配置视图对象 sys_config + * + * @author Michelle.Chung + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysConfig.class) +public class SysConfigVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 参数主键 + */ + @ExcelProperty(value = "参数主键") + private Long id; + + /** + * 参数名称 + */ + @ExcelProperty(value = "参数名称") + private String configName; + + /** + * 参数键名 + */ + @ExcelProperty(value = "参数键名") + private String configKey; + + /** + * 参数键值 + */ + @ExcelProperty(value = "参数键值") + private String configValue; + + /** + * 系统内置(Y是 N否) + */ + @ExcelProperty(value = "系统内置", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_yes_no") + private String configType; + + /** + * 备注 + */ + @ExcelProperty(value = "备注") + private String remark; + + /** + * 创建时间 + */ + @ExcelProperty(value = "创建时间") + private Date createTime; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDeptVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDeptVo.java new file mode 100644 index 0000000..1da7cc0 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDeptVo.java @@ -0,0 +1,114 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import cc.iotkit.model.system.SysDept; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 部门视图对象 sys_dept + * + * @author Michelle.Chung + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysDept.class) +public class SysDeptVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 部门id + */ + @ExcelProperty(value = "部门id") + private Long id; + + /** + * 父部门id + */ + private Long parentId; + + /** + * 父部门名称 + */ + private String parentName; + + /** + * 祖级列表 + */ + private String ancestors; + + /** + * 部门名称 + */ + @ExcelProperty(value = "部门名称") + private String deptName; + + /** + * 显示顺序 + */ + private Integer orderNum; + + /** + * 负责人 + */ + @ExcelProperty(value = "负责人") + private String leader; + + /** + * 联系电话 + */ + @ExcelProperty(value = "联系电话") + private String phone; + + /** + * 邮箱 + */ + @ExcelProperty(value = "邮箱") + private String email; + + /** + * 部门状态(0正常 1停用) + */ + @ExcelProperty(value = "部门状态", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_normal_disable") + private String status; + + /** + * 创建时间 + */ + @ExcelProperty(value = "创建时间") + private Date createTime; + /** + * 部门与区域(默认0是部门,1是区域) + */ + private Integer areaType; +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDictDataVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDictDataVo.java new file mode 100644 index 0000000..e893deb --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDictDataVo.java @@ -0,0 +1,115 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import cc.iotkit.model.system.SysDictData; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 字典数据视图对象 sys_dict_data + * + * @author Michelle.Chung + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysDictData.class) +public class SysDictDataVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 字典编码 + */ + @ExcelProperty(value = "字典编码") + private Long id; + + /** + * 字典排序 + */ + @ExcelProperty(value = "字典排序") + private Integer dictSort; + + /** + * 字典标签 + */ + @ExcelProperty(value = "字典标签") + private String dictLabel; + + /** + * 字典键值 + */ + @ExcelProperty(value = "字典键值") + private String dictValue; + + /** + * 字典类型 + */ + @ExcelProperty(value = "字典类型") + private String dictType; + + /** + * 样式属性(其他样式扩展) + */ + private String cssClass; + + /** + * 表格回显样式 + */ + private String listClass; + + /** + * 是否默认(Y是 N否) + */ + @ExcelProperty(value = "是否默认", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_yes_no") + private String isDefault; + + /** + * 状态(0正常 1停用) + */ + @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_normal_disable") + private String status; + + /** + * 备注 + */ + @ExcelProperty(value = "备注") + private String remark; + + /** + * 创建时间 + */ + @ExcelProperty(value = "创建时间") + private Date createTime; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDictTypeVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDictTypeVo.java new file mode 100644 index 0000000..2f1d5c4 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDictTypeVo.java @@ -0,0 +1,86 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import cc.iotkit.model.system.SysDictType; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 字典类型视图对象 sys_dict_type + * + * @author Michelle.Chung + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysDictType.class) +public class SysDictTypeVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 字典主键 + */ + @ExcelProperty(value = "字典主键") + private Long id; + + /** + * 字典名称 + */ + @ExcelProperty(value = "字典名称") + private String dictName; + + /** + * 字典类型 + */ + @ExcelProperty(value = "字典类型") + private String dictType; + + /** + * 状态(0正常 1停用) + */ + @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_normal_disable") + private String status; + + /** + * 备注 + */ + @ExcelProperty(value = "备注") + private String remark; + + /** + * 创建时间 + */ + @ExcelProperty(value = "创建时间") + private Date createTime; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysLogininforVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysLogininforVo.java new file mode 100644 index 0000000..c264e5b --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysLogininforVo.java @@ -0,0 +1,113 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import cc.iotkit.model.system.SysLoginInfo; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + + +/** + * 系统访问记录视图对象 sys_logininfor + * + * @author Michelle.Chung + * @date 2023-02-07 + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysLoginInfo.class) +public class SysLogininforVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 访问ID + */ + @ExcelProperty(value = "序号") + private Long id; + + /** + * 租户编号 + */ + private Long tenantId; + + /** + * 用户账号 + */ + @ExcelProperty(value = "用户账号") + private String userName; + + /** + * 登录状态(0成功 1失败) + */ + @ExcelProperty(value = "登录状态", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_common_status") + private String status; + + /** + * 登录IP地址 + */ + @ExcelProperty(value = "登录地址") + private String ipaddr; + + /** + * 登录地点 + */ + @ExcelProperty(value = "登录地点") + private String loginLocation; + + /** + * 浏览器类型 + */ + @ExcelProperty(value = "浏览器") + private String browser; + + /** + * 操作系统 + */ + @ExcelProperty(value = "操作系统") + private String os; + + + /** + * 提示消息 + */ + @ExcelProperty(value = "提示消息") + private String msg; + + /** + * 访问时间 + */ + @ExcelProperty(value = "访问时间") + private Date loginTime; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysMenuVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysMenuVo.java new file mode 100644 index 0000000..be8b549 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysMenuVo.java @@ -0,0 +1,136 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.model.system.SysMenu; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + +/** + * 菜单权限视图对象 sys_menu + * + * @author Michelle.Chung + */ +@Data +@AutoMapper(target = SysMenu.class) +public class SysMenuVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 菜单ID + */ + private Long id; + + /** + * 菜单名称 + */ + private String menuName; + + /** + * 父菜单ID + */ + private Long parentId; + + /** + * 显示顺序 + */ + private Integer orderNum; + + /** + * 路由地址 + */ + private String path; + + /** + * 组件路径 + */ + private String component; + + /** + * 路由参数 + */ + private String queryParam; + + /** + * 是否为外链(0是 1否) + */ + private String isFrame; + + /** + * 是否缓存(0缓存 1不缓存) + */ + private String isCache; + + /** + * 菜单类型(M目录 C菜单 F按钮) + */ + private String menuType; + + /** + * 显示状态(0显示 1隐藏) + */ + private String visible; + + /** + * 菜单状态(0正常 1停用) + */ + private String status; + + /** + * 权限标识 + */ + private String perms; + + /** + * 菜单图标 + */ + private String icon; + + /** + * 创建部门 + */ + private Long createDept; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 子菜单 + */ + private List children = new ArrayList<>(); + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysNoticeVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysNoticeVo.java new file mode 100644 index 0000000..cda931e --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysNoticeVo.java @@ -0,0 +1,90 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.model.system.SysNotice; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + + +/** + * 通知公告视图对象 sys_notice + * + * @author Michelle.Chung + */ +@Data +@AutoMapper(target = SysNotice.class) +public class SysNoticeVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 公告ID + */ + private Long id; + + /** + * 公告标题 + */ + private String noticeTitle; + + /** + * 公告类型(1通知 2公告) + */ + private String noticeType; + + /** + * 公告内容 + */ + private String noticeContent; + + /** + * 公告状态(0正常 1关闭) + */ + private String status; + + /** + * 备注 + */ + private String remark; + + /** + * 创建者 + */ + private Long createBy; + + /** + * 创建人名称 + */ + private String createByName; + + /** + * 创建时间 + */ + private Date createTime; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOperLogVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOperLogVo.java new file mode 100644 index 0000000..553a2cc --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOperLogVo.java @@ -0,0 +1,165 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.api.BaseDto; +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import cc.iotkit.model.system.SysOperLog; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 操作日志记录视图对象 sys_oper_log + * + * @author Michelle.Chung + * @date 2023-02-07 + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysOperLog.class) +public class SysOperLogVo extends BaseDto implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 日志主键 + */ + @ExcelProperty(value = "日志主键") + private Long id; + + /** + * 租户编号 + */ + private Long tenantId; + + /** + * 模块标题 + */ + @ExcelProperty(value = "操作模块") + private String title; + + /** + * 业务类型(0其它 1新增 2修改 3删除) + */ + @ExcelProperty(value = "业务类型", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_oper_type") + private Integer businessType; + + /** + * 业务类型数组 + */ + private Integer[] businessTypes; + + /** + * 方法名称 + */ + @ExcelProperty(value = "请求方法") + private String method; + + /** + * 请求方式 + */ + @ExcelProperty(value = "请求方式") + private String requestMethod; + + /** + * 操作类别(0其它 1后台用户 2手机端用户) + */ + @ExcelProperty(value = "操作类别", converter = ExcelDictConvert.class) + @ExcelDictFormat(readConverterExp = "0=其它,1=后台用户,2=手机端用户") + private Integer operatorType; + + /** + * 操作人员 + */ + @ExcelProperty(value = "操作人员") + private String operName; + + /** + * 部门名称 + */ + @ExcelProperty(value = "部门名称") + private String deptName; + + /** + * 请求URL + */ + @ExcelProperty(value = "请求地址") + private String operUrl; + + /** + * 主机地址 + */ + @ExcelProperty(value = "操作地址") + private String operIp; + + /** + * 操作地点 + */ + @ExcelProperty(value = "操作地点") + private String operLocation; + + /** + * 请求参数 + */ + @ExcelProperty(value = "请求参数") + private String operParam; + + /** + * 返回参数 + */ + @ExcelProperty(value = "返回参数") + private String jsonResult; + + /** + * 操作状态(0正常 1异常) + */ + @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_common_status") + private Integer status; + + /** + * 错误消息 + */ + @ExcelProperty(value = "错误消息") + private String errorMsg; + + /** + * 操作时间 + */ + @ExcelProperty(value = "操作时间") + private Date operTime; + + /** + * 消耗时间 + */ + @ExcelProperty(value = "消耗时间") + private Long costTime; +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOssConfigVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOssConfigVo.java new file mode 100644 index 0000000..9d185b4 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOssConfigVo.java @@ -0,0 +1,117 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.model.system.SysOssConfig; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; + + +/** + * 对象存储配置视图对象 sys_oss_config + * + * @author Lion Li + * @author 孤舟烟雨 + * @date 2021-08-13 + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysOssConfig.class) +public class SysOssConfigVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 主建 + */ + private Long id; + + /** + * 配置key + */ + private String configKey; + + /** + * accessKey + */ + private String accessKey; + + /** + * 秘钥 + */ + private String secretKey; + + /** + * 桶名称 + */ + private String bucketName; + + /** + * 前缀 + */ + private String prefix; + + /** + * 访问站点 + */ + private String endpoint; + + /** + * 自定义域名 + */ + private String domain; + + /** + * 是否https(Y=是,N=否) + */ + private String isHttps; + + /** + * 域 + */ + private String region; + + /** + * 是否默认(0=是,1=否) + */ + private String status; + + /** + * 扩展字段 + */ + private String ext1; + + /** + * 备注 + */ + private String remark; + + /** + * 桶权限类型(0private 1public 2custom) + */ + private String accessPolicy; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOssUploadVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOssUploadVo.java new file mode 100644 index 0000000..08f9dbb --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOssUploadVo.java @@ -0,0 +1,51 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import lombok.Data; + +/** + * 上传对象信息 + * + * @author Michelle.Chung + */ +@Data +public class SysOssUploadVo { + + /** + * URL地址 + */ + private String url; + + /** + * 文件名 + */ + private String fileName; + + /** + * 对象存储主键 + */ + private String ossId; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOssVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOssVo.java new file mode 100644 index 0000000..7982904 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysOssVo.java @@ -0,0 +1,89 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.model.system.SysOss; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * OSS对象存储视图对象 sys_oss + * + * @author Lion Li + */ +@Data +@AutoMapper(target = SysOss.class) +public class SysOssVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 对象存储主键 + */ + private Long id; + + /** + * 文件名 + */ + private String fileName; + + /** + * 原名 + */ + private String originalName; + + /** + * 文件后缀名 + */ + private String fileSuffix; + + /** + * URL地址 + */ + private String url; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 上传人 + */ + private Long createBy; + + /** + * 上传人名称 + */ + private String createByName; + + /** + * 服务商 + */ + private String service; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysPostVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysPostVo.java new file mode 100644 index 0000000..c17e1f6 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysPostVo.java @@ -0,0 +1,93 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import cc.iotkit.model.system.SysPost; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + + +/** + * 岗位信息视图对象 sys_post + * + * @author Michelle.Chung + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysPost.class) +public class SysPostVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 岗位ID + */ + @ExcelProperty(value = "岗位序号") + private Long id; + + /** + * 岗位编码 + */ + @ExcelProperty(value = "岗位编码") + private String postCode; + + /** + * 岗位名称 + */ + @ExcelProperty(value = "岗位名称") + private String postName; + + /** + * 显示顺序 + */ + @ExcelProperty(value = "岗位排序") + private Integer postSort; + + /** + * 状态(0正常 1停用) + */ + @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_normal_disable") + private String status; + + /** + * 备注 + */ + @ExcelProperty(value = "备注") + private String remark; + + /** + * 创建时间 + */ + @ExcelProperty(value = "创建时间") + private Date createTime; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysRoleVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysRoleVo.java new file mode 100644 index 0000000..271ef29 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysRoleVo.java @@ -0,0 +1,120 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import cc.iotkit.model.system.SysRole; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 角色信息视图对象 sys_role + * + * @author Michelle.Chung + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysRole.class) +public class SysRoleVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 角色ID + */ + @ExcelProperty(value = "角色序号") + private Long id; + + /** + * 角色名称 + */ + @ExcelProperty(value = "角色名称") + private String roleName; + + /** + * 角色权限字符串 + */ + @ExcelProperty(value = "角色权限") + private String roleKey; + + /** + * 显示顺序 + */ + @ExcelProperty(value = "角色排序") + private Integer roleSort; + + /** + * 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限) + */ + @ExcelProperty(value = "数据范围", converter = ExcelDictConvert.class) + @ExcelDictFormat(readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限,5=仅本人数据权限") + private String dataScope; + + /** + * 菜单树选择项是否关联显示 + */ + @ExcelProperty(value = "菜单树选择项是否关联显示") + private Boolean menuCheckStrictly; + + /** + * 部门树选择项是否关联显示 + */ + @ExcelProperty(value = "部门树选择项是否关联显示") + private Boolean deptCheckStrictly; + + /** + * 角色状态(0正常 1停用) + */ + @ExcelProperty(value = "角色状态", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_normal_disable") + private String status; + + /** + * 备注 + */ + @ExcelProperty(value = "备注") + private String remark; + + /** + * 创建时间 + */ + @ExcelProperty(value = "创建时间") + private Date createTime; + + /** + * 用户是否存在此角色标识 默认不存在 + */ + private boolean flag = false; + + public boolean isSuperAdmin() { + return UserConstants.SUPER_ADMIN_ID.equals(this.id); + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysTenantPackageVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysTenantPackageVo.java new file mode 100644 index 0000000..42d704f --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysTenantPackageVo.java @@ -0,0 +1,86 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import cc.iotkit.model.system.SysTenantPackage; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; + + +/** + * 租户套餐视图对象 sys_tenant_package + * + * @author Michelle.Chung + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysTenantPackage.class) +public class SysTenantPackageVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 租户套餐id + */ + @ExcelProperty(value = "租户套餐id") + private Long id; + + /** + * 套餐名称 + */ + @ExcelProperty(value = "套餐名称") + private String packageName; + + /** + * 关联菜单id + */ + @ExcelProperty(value = "关联菜单id") + private String menuIds; + + /** + * 备注 + */ + @ExcelProperty(value = "备注") + private String remark; + + /** + * 菜单树选择项是否关联显示 + */ + @ExcelProperty(value = "菜单树选择项是否关联显示") + private Boolean menuCheckStrictly; + + /** + * 状态(0正常 1停用) + */ + @ExcelProperty(value = "状态", converter = ExcelDictConvert.class) + @ExcelDictFormat(readConverterExp = "0=正常,1=停用") + private String status; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysTenantVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysTenantVo.java new file mode 100644 index 0000000..8161e17 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysTenantVo.java @@ -0,0 +1,136 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import cc.iotkit.model.BaseModel; +import cc.iotkit.model.system.SysTenant; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 租户视图对象 sys_tenant + * + * @author Michelle.Chung + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = SysTenant.class) +public class SysTenantVo extends BaseModel implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * id + */ + @ExcelProperty(value = "id") + private Long id; + + /** + * 租户编号 + */ + @ExcelProperty(value = "租户编号") + private Long tenantId; + + /** + * 联系人 + */ + @ExcelProperty(value = "联系人") + private String contactUserName; + + /** + * 联系电话 + */ + @ExcelProperty(value = "联系电话") + private String contactPhone; + + /** + * 企业名称 + */ + @ExcelProperty(value = "企业名称") + private String companyName; + + /** + * 统一社会信用代码 + */ + @ExcelProperty(value = "统一社会信用代码") + private String licenseNumber; + + /** + * 地址 + */ + @ExcelProperty(value = "地址") + private String address; + + /** + * 域名 + */ + @ExcelProperty(value = "域名") + private String domain; + + /** + * 企业简介 + */ + @ExcelProperty(value = "企业简介") + private String intro; + + /** + * 备注 + */ + @ExcelProperty(value = "备注") + private String remark; + + /** + * 租户套餐编号 + */ + @ExcelProperty(value = "租户套餐编号") + private Long packageId; + + /** + * 过期时间 + */ + @ExcelProperty(value = "过期时间") + private Date expireTime; + + /** + * 用户数量(-1不限制) + */ + @ExcelProperty(value = "用户数量") + private Long accountCount; + + /** + * 租户状态(0正常 1停用) + */ + @ExcelProperty(value = "租户状态", converter = ExcelDictConvert.class) + @ExcelDictFormat(readConverterExp = "0=正常,1=停用") + private String status; + + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserExportVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserExportVo.java new file mode 100644 index 0000000..8bff85f --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserExportVo.java @@ -0,0 +1,119 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import com.alibaba.excel.annotation.ExcelProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.github.linpeilie.annotations.ReverseAutoMapping; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.Date; + +/** + * 用户对象导出VO + * + * @author Lion Li + */ + +@Data +@NoArgsConstructor +@AutoMapper(target = SysUserVo.class, convertGenerate = false) +public class SysUserExportVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 用户ID + */ + @ExcelProperty(value = "用户序号") + private Long userId; + + /** + * 用户账号 + */ + @ExcelProperty(value = "登录名称") + private String userName; + + /** + * 用户昵称 + */ + @ExcelProperty(value = "用户名称") + private String nickName; + + /** + * 用户邮箱 + */ + @ExcelProperty(value = "用户邮箱") + private String email; + + /** + * 手机号码 + */ + @ExcelProperty(value = "手机号码") + private String phonenumber; + + /** + * 用户性别 + */ + @ExcelProperty(value = "用户性别", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_user_sex") + private String sex; + + /** + * 帐号状态(0正常 1停用) + */ + @ExcelProperty(value = "帐号状态", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_normal_disable") + private String status; + + /** + * 最后登录IP + */ + @ExcelProperty(value = "最后登录IP") + private String loginIp; + + /** + * 最后登录时间 + */ + @ExcelProperty(value = "最后登录时间") + private Date loginDate; + + /** + * 部门名称 + */ + @ReverseAutoMapping(target = "deptName", source = "dept.deptName") + @ExcelProperty(value = "部门名称") + private String deptName; + + /** + * 负责人 + */ + @ReverseAutoMapping(target = "leader", source = "dept.leader") + @ExcelProperty(value = "部门负责人") + private String leader; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserImportVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserImportVo.java new file mode 100644 index 0000000..ad99a08 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserImportVo.java @@ -0,0 +1,96 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.common.excel.annotation.ExcelDictFormat; +import cc.iotkit.common.excel.convert.ExcelDictConvert; +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 用户对象导入VO + * + * @author Lion Li + */ + +@Data +@NoArgsConstructor +// @Accessors(chain = true) // 导入不允许使用 会找不到set方法 +public class SysUserImportVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 用户ID + */ + @ExcelProperty(value = "用户序号") + private Long userId; + + /** + * 部门ID + */ + @ExcelProperty(value = "部门编号") + private Long deptId; + + /** + * 用户账号 + */ + @ExcelProperty(value = "登录名称") + private String userName; + + /** + * 用户昵称 + */ + @ExcelProperty(value = "用户名称") + private String nickName; + + /** + * 用户邮箱 + */ + @ExcelProperty(value = "用户邮箱") + private String email; + + /** + * 手机号码 + */ + @ExcelProperty(value = "手机号码") + private String phonenumber; + + /** + * 用户性别 + */ + @ExcelProperty(value = "用户性别", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_user_sex") + private String sex; + + /** + * 帐号状态(0正常 1停用) + */ + @ExcelProperty(value = "帐号状态", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_normal_disable") + private String status; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserInfoVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserInfoVo.java new file mode 100644 index 0000000..384c54c --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserInfoVo.java @@ -0,0 +1,63 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import lombok.Data; + +import java.util.List; + +/** + * 用户信息 + * + * @author Michelle.Chung + */ +@Data +public class SysUserInfoVo { + + /** + * 用户信息 + */ + private SysUserVo user; + + /** + * 角色ID列表 + */ + private List roleIds; + + /** + * 角色列表 + */ + private List roles; + + /** + * 岗位ID列表 + */ + private List postIds; + + /** + * 岗位列表 + */ + private List posts; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserVo.java new file mode 100644 index 0000000..5d3683f --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserVo.java @@ -0,0 +1,156 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import cc.iotkit.model.system.SysUser; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.github.linpeilie.annotations.AutoMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + + +/** + * 用户信息视图对象 sys_user + * + * @author Michelle.Chung + */ +@Data +@AutoMapper(target = SysUser.class) +public class SysUserVo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 用户ID + */ + private Long id; + + /** + * 租户ID + */ + private Long tenantId; + + /** + * 部门ID + */ + private Long deptId; + + /** + * 用户账号 + */ + private String userName; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 用户类型(sys_user系统用户) + */ + private String userType; + + /** + * 用户邮箱 + */ + private String email; + + /** + * 手机号码 + */ + private String phonenumber; + + /** + * 用户性别(0男 1女 2未知) + */ + private String sex; + + /** + * 头像地址 + */ + private Long avatar; + + /** + * 密码 + */ + @JsonIgnore + @JsonProperty + private String password; + + /** + * 帐号状态(0正常 1停用) + */ + private String status; + + /** + * 最后登录IP + */ + private String loginIp; + + /** + * 最后登录时间 + */ + private Date loginDate; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 部门对象 + */ + private SysDeptVo dept; + + /** + * 角色对象 + */ + private List roles; + + /** + * 角色组 + */ + private Long[] roleIds; + + /** + * 岗位组 + */ + private Long[] postIds; + + /** + * 数据权限 当前角色ID + */ + private Long roleId; + // @ApiModelProperty(value="部门表-区域id") + private Long deptAreaId; +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/UserInfoVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/UserInfoVo.java new file mode 100644 index 0000000..dc17c8a --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/UserInfoVo.java @@ -0,0 +1,53 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.dto.vo; + +import lombok.Data; + +import java.util.Set; + +/** + * 登录用户信息 + * + * @author Michelle.Chung + */ +@Data +public class UserInfoVo { + + /** + * 用户基本信息 + */ + private SysUserVo user; + + /** + * 菜单权限 + */ + private Set permissions; + + /** + * 角色权限 + */ + private Set roles; + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/listener/SysUserImportListener.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/listener/SysUserImportListener.java new file mode 100644 index 0000000..f6a074d --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/listener/SysUserImportListener.java @@ -0,0 +1,143 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.listener; + +import cc.iotkit.common.excel.core.ExcelListener; +import cc.iotkit.common.excel.core.ExcelResult; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.SpringUtils; +import cc.iotkit.common.utils.ValidatorUtils; +import cc.iotkit.system.dto.bo.SysUserBo; +import cc.iotkit.system.dto.vo.SysUserImportVo; +import cc.iotkit.system.dto.vo.SysUserVo; +import cc.iotkit.system.service.ISysConfigService; +import cc.iotkit.system.service.ISysUserService; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.crypto.digest.BCrypt; +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import lombok.extern.slf4j.Slf4j; + +import java.util.Collections; +import java.util.List; + +/** + * 系统用户自定义导入 + * + * @author Lion Li + */ +@Slf4j +public class SysUserImportListener extends AnalysisEventListener implements ExcelListener { + + private final ISysUserService userService; + + private final String password; + + private final Boolean isUpdateSupport; + + private final Long operUserId; + + private int successNum = 0; + private int failureNum = 0; + private final StringBuilder successMsg = new StringBuilder(); + private final StringBuilder failureMsg = new StringBuilder(); + + public SysUserImportListener(Boolean isUpdateSupport) { + String initPassword = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.user.initPassword"); + this.userService = SpringUtils.getBean(ISysUserService.class); + this.password = BCrypt.hashpw(initPassword); + this.isUpdateSupport = isUpdateSupport; + this.operUserId = LoginHelper.getUserId(); + } + + @Override + public void invoke(SysUserImportVo userVo, AnalysisContext context) { + SysUserVo sysUser = this.userService.selectUserByUserName(userVo.getUserName()); + try { + // 验证是否存在这个用户 + if (ObjectUtil.isNull(sysUser)) { + SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class); + ValidatorUtils.validate(user); + user.setPassword(password); + user.setCreateBy(operUserId); + userService.insertUser(user); + successNum++; + successMsg.append("
").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功"); + } else if (Boolean.TRUE.equals(isUpdateSupport)) { + Long userId = sysUser.getId(); + SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class); + user.setId(userId); + ValidatorUtils.validate(user); + userService.checkUserAllowed(user); + userService.checkUserDataScope(user.getId()); + user.setUpdateBy(operUserId); + userService.updateUser(user); + successNum++; + successMsg.append("
").append(successNum).append("、账号 ").append(user.getUserName()).append(" 更新成功"); + } else { + failureNum++; + failureMsg.append("
").append(failureNum).append("、账号 ").append(sysUser.getUserName()).append(" 已存在"); + } + } catch (Exception e) { + failureNum++; + String msg = "
" + failureNum + "、账号 " + sysUser.getUserName() + " 导入失败:"; + failureMsg.append(msg).append(e.getMessage()); + log.error(msg, e); + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + + } + + @Override + public ExcelResult getExcelResult() { + return new ExcelResult<>() { + + @Override + public String getAnalysis() { + if (failureNum > 0) { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new BizException(failureMsg.toString()); + } else { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } + + @Override + public List getList() { + return Collections.emptyList(); + } + + @Override + public List getErrorList() { + return Collections.emptyList(); + } + }; + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysAppService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysAppService.java new file mode 100644 index 0000000..36609f5 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysAppService.java @@ -0,0 +1,80 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysAppBo; +import cc.iotkit.system.dto.vo.SysAppVo; + +import java.util.List; + +/** + * 应用信息Service接口 + * + * @author tfd + * @date 2023-08-10 + */ +public interface ISysAppService { + + /** + * 查询应用信息 + */ + SysAppVo queryById(Long id); + + /** + * 根据appid查询应用信息 + */ + SysAppVo queryByAppId(String appId); + + /** + * 根据appid查询应用信息是否存在 + */ + boolean checkAppIdUnique(String appId); + + /** + * 查询应用信息列表 + */ + Paging queryPageList(PageRequest pageQuery); + + /** + * 查询应用信息列表 + */ + List queryList(SysAppBo bo); + + /** + * 新增应用信息 + */ + Long insertByBo(SysAppBo bo); + + /** + * 修改应用信息 + */ + Boolean updateByBo(SysAppBo bo); + + /** + * 删除应用信息信息 + */ + Boolean deleteById(Long id); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysConfigService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysConfigService.java new file mode 100644 index 0000000..b7ea740 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysConfigService.java @@ -0,0 +1,116 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysConfigBo; +import cc.iotkit.system.dto.vo.SysConfigVo; + +import java.io.File; +import java.util.List; + +/** + * 参数配置 服务层 + * + * @author Lion Li + */ +public interface ISysConfigService { + + + Paging selectPageConfigList(PageRequest query); + + /** + * 查询参数配置信息 + * + * @param configId 参数配置ID + * @return 参数配置信息 + */ + SysConfigVo selectConfigById(Long configId); + + /** + * 根据键名查询参数配置信息 + * + * @param configKey 参数键名 + * @return 参数键值 + */ + String selectConfigByKey(String configKey); + + /** + * 获取注册开关 + * @param tenantId 租户id + * @return true开启,false关闭 + */ + boolean selectRegisterEnabled(Long tenantId); + + /** + * 查询参数配置列表 + * + * @param config 参数配置信息 + * @return 参数配置集合 + */ + List selectConfigList(SysConfigBo config); + + /** + * 新增参数配置 + * + * @param bo 参数配置信息 + * @return 结果 + */ + String insertConfig(SysConfigBo bo); + + /** + * 修改参数配置 + * + * @param bo 参数配置信息 + * @return 结果 + */ + String updateConfig(SysConfigBo bo); + + /** + * 批量删除参数信息 + * + * @param configIds 需要删除的参数ID + */ + void deleteConfigByIds(List configIds); + + /** + * 重置参数缓存数据 + */ + void resetConfigCache(); + + /** + * 校验参数键名是否唯一 + * + * @param config 参数信息 + * @return 结果 + */ + boolean checkConfigKeyUnique(SysConfigBo config); + + /** + * 将系统数据备份到文件中 + * @return zip备份文件 + */ + File backupSysData(); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysDeptService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysDeptService.java new file mode 100644 index 0000000..e14c572 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysDeptService.java @@ -0,0 +1,138 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.model.system.SysDept; +import cc.iotkit.system.dto.bo.SysDeptBo; +import cc.iotkit.system.dto.vo.SysDeptVo; +import cn.hutool.core.lang.tree.Tree; + +import java.util.List; + +/** + * 部门管理 服务层 + * + * @author Lion Li + */ +public interface ISysDeptService { + /** + * 查询部门管理数据 + * + * @param dept 部门信息 + * @return 部门信息集合 + */ + List selectDeptList(SysDeptBo dept); + + /** + * 查询部门树结构信息 + * + * @param dept 部门信息 + * @return 部门树信息集合 + */ + List> selectDeptTreeList(SysDeptBo dept); + + /** + * 构建前端所需要下拉树结构 + * + * @param depts 部门列表 + * @return 下拉树结构列表 + */ + List> buildDeptTreeSelect(List depts); + + /** + * 根据角色ID查询部门树信息 + * + * @param roleId 角色ID + * @return 选中部门列表 + */ + List selectDeptListByRoleId(Long roleId); + + /** + * 根据部门ID查询信息 + * + * @param deptId 部门ID + * @return 部门信息 + */ + SysDeptVo selectDeptById(Long deptId); + + /** + * 根据ID查询所有子部门数(正常状态) + * + * @param deptId 部门ID + * @return 子部门数 + */ + long selectNormalChildrenDeptById(Long deptId); + + /** + * 是否存在部门子节点 + * + * @param deptId 部门ID + * @return 结果 + */ + boolean hasChildByDeptId(Long deptId); + + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 true 存在 false 不存在 + */ + boolean checkDeptExistUser(Long deptId); + + /** + * 校验部门名称是否唯一 + * + * @param dept 部门信息 + * @return 结果 + */ + boolean checkDeptNameUnique(SysDeptBo dept); + + /** + * 校验部门是否有数据权限 + * + * @param deptId 部门id + */ + void checkDeptDataScope(Long deptId); + + /** + * 新增保存部门信息 + * + * @param bo 部门信息 + */ + void insertDept(SysDeptBo bo); + + /** + * 修改保存部门信息 + * + * @param bo 部门信息 + */ + void updateDept(SysDeptBo bo); + + /** + * 删除部门管理信息 + * + * @param deptId 部门ID + */ + void deleteDeptById(Long deptId); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysDictDataService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysDictDataService.java new file mode 100644 index 0000000..192f5ce --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysDictDataService.java @@ -0,0 +1,90 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysDictDataBo; +import cc.iotkit.system.dto.vo.SysDictDataVo; + +import java.util.List; + +/** + * 字典 业务层 + * + * @author Lion Li + */ +public interface ISysDictDataService { + + + Paging selectPageDictDataList(PageRequest query); + + /** + * 根据条件分页查询字典数据 + * + * @param dictData 字典数据信息 + * @return 字典数据集合信息 + */ + List selectDictDataList(SysDictDataBo dictData); + + /** + * 根据字典类型和字典键值查询字典数据信息 + * + * @param dictType 字典类型 + * @param dictValue 字典键值 + * @return 字典标签 + */ + String selectDictLabel(String dictType, String dictValue); + + /** + * 根据字典数据ID查询信息 + * + * @param dictCode 字典数据ID + * @return 字典数据 + */ + SysDictDataVo selectDictDataById(Long dictCode); + + /** + * 批量删除字典数据信息 + * + * @param dictCodes 需要删除的字典数据ID + */ + void deleteDictDataByIds(Long[] dictCodes); + + /** + * 新增保存字典数据信息 + * + * @param bo 字典数据信息 + * @return 结果 + */ + List insertDictData(SysDictDataBo bo); + + /** + * 修改保存字典数据信息 + * + * @param bo 字典数据信息 + * @return 结果 + */ + List updateDictData(SysDictDataBo bo); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysDictTypeService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysDictTypeService.java new file mode 100644 index 0000000..22e54f0 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysDictTypeService.java @@ -0,0 +1,119 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysDictTypeBo; +import cc.iotkit.system.dto.vo.SysDictDataVo; +import cc.iotkit.system.dto.vo.SysDictTypeVo; + +import java.util.Collection; +import java.util.List; + +/** + * 字典 业务层 + * + * @author Lion Li + */ +public interface ISysDictTypeService { + + + Paging selectPageDictTypeList( PageRequest query); + + /** + * 根据条件分页查询字典类型 + * + * @param dictType 字典类型信息 + * @return 字典类型集合信息 + */ + List selectDictTypeList(SysDictTypeBo dictType); + + /** + * 根据所有字典类型 + * + * @return 字典类型集合信息 + */ + List selectDictTypeAll(); + + /** + * 根据字典类型查询字典数据 + * + * @param dictType 字典类型 + * @return 字典数据集合信息 + */ + List selectDictDataByType(String dictType); + + /** + * 根据字典类型ID查询信息 + * + * @param dictId 字典类型ID + * @return 字典类型 + */ + SysDictTypeVo selectDictTypeById(Long dictId); + + /** + * 根据字典类型查询信息 + * + * @param dictType 字典类型 + * @return 字典类型 + */ + SysDictTypeVo selectDictTypeByType(String dictType); + + /** + * 批量删除字典信息 + * + * @param dictIds 需要删除的字典ID + */ + void deleteDictTypeByIds(Collection dictIds); + + /** + * 重置字典缓存数据 + */ + void resetDictCache(); + + /** + * 新增保存字典类型信息 + * + * @param bo 字典类型信息 + * @return 结果 + */ + List insertDictType(SysDictTypeBo bo); + + /** + * 修改保存字典类型信息 + * + * @param bo 字典类型信息 + * @return 结果 + */ + List updateDictType(SysDictTypeBo bo); + + /** + * 校验字典类型称是否唯一 + * + * @param dictType 字典类型 + * @return 结果 + */ + boolean checkDictTypeUnique(SysDictTypeBo dictType); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysLogininforService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysLogininforService.java new file mode 100644 index 0000000..f28bc4d --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysLogininforService.java @@ -0,0 +1,72 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysLoginInfoBo; +import cc.iotkit.system.dto.vo.SysLogininforVo; + +import java.util.Collection; +import java.util.List; + +/** + * 系统访问日志情况信息 服务层 + * + * @author Lion Li + */ +public interface ISysLogininforService { + + + + /** + * 新增系统登录日志 + * + * @param bo 访问日志对象 + */ + void insertLogininfor(SysLoginInfoBo bo); + + /** + * 查询系统登录日志集合 + * + * @param logininfor 访问日志对象 + * @return 登录记录集合 + */ + List selectLogininforList(SysLoginInfoBo logininfor); + + /** + * 批量删除系统登录日志 + * + * @param infoIds 需要删除的登录日志ID + * @return 结果 + */ + void deleteLogininforByIds(Collection infoIds); + + /** + * 清空系统登录日志 + */ + void cleanLogininfor(); + + Paging findAll(PageRequest query); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysMenuService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysMenuService.java new file mode 100644 index 0000000..c60a899 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysMenuService.java @@ -0,0 +1,164 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.model.system.SysMenu; +import cc.iotkit.system.dto.bo.SysMenuBo; +import cc.iotkit.system.dto.vo.RouterVo; +import cc.iotkit.system.dto.vo.SysMenuVo; +import cn.hutool.core.lang.tree.Tree; + +import java.util.List; +import java.util.Set; + +/** + * 菜单 业务层 + * + * @author Lion Li + */ +public interface ISysMenuService { + + /** + * 根据用户查询系统菜单列表 + * + * @param userId 用户ID + * @return 菜单列表 + */ + List selectMenuList(Long userId); + + /** + * 根据用户查询系统菜单列表 + * + * @param menu 菜单信息 + * @param userId 用户ID + * @return 菜单列表 + */ + List selectMenuList(SysMenuBo menu, Long userId); + + /** + * 根据用户ID查询权限 + * + * @param userId 用户ID + * @return 权限列表 + */ + Set selectMenuPermsByUserId(Long userId); + + /** + * 根据角色ID查询权限 + * + * @param roleId 角色ID + * @return 权限列表 + */ + Set selectMenuPermsByRoleId(Long roleId); + + /** + * 根据用户ID查询菜单树信息 + * + * @param userId 用户ID + * @return 菜单列表 + */ + List selectMenuTreeByUserId(Long userId); + + /** + * 根据角色ID查询菜单树信息 + * + * @param roleId 角色ID + * @return 选中菜单列表 + */ + List selectMenuListByRoleId(Long roleId); + + /** + * 构建前端路由所需要的菜单 + * + * @param menus 菜单列表 + * @return 路由列表 + */ + List buildMenus(List menus); + + /** + * 构建前端所需要下拉树结构 + * + * @param menus 菜单列表 + * @return 下拉树结构列表 + */ + List> buildMenuTreeSelect(List menus); + + /** + * 根据菜单ID查询信息 + * + * @param menuId 菜单ID + * @return 菜单信息 + */ + SysMenuVo selectMenuById(Long menuId); + + /** + * 是否存在菜单子节点 + * + * @param menuId 菜单ID + * @return 结果 true 存在 false 不存在 + */ + boolean hasChildByMenuId(Long menuId); + + /** + * 查询菜单是否存在角色 + * + * @param menuId 菜单ID + * @return 结果 true 存在 false 不存在 + */ + boolean checkMenuExistRole(Long menuId); + + /** + * 新增保存菜单信息 + * + * @param bo 菜单信息 + * @return 结果 + */ + void insertMenu(SysMenuBo bo); + + /** + * 修改保存菜单信息 + * + * @param bo 菜单信息 + * @return 结果 + */ + void updateMenu(SysMenuBo bo); + + /** + * 删除菜单管理信息 + * + * @param menuId 菜单ID + * @return 结果 + */ + void deleteMenuById(Long menuId); + + /** + * 校验菜单名称是否唯一 + * + * @param menu 菜单信息 + * @return 结果 + */ + boolean checkMenuNameUnique(SysMenuBo menu); + + List selectMenuListByPackageId(Long data); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysNoticeService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysNoticeService.java new file mode 100644 index 0000000..63a05c3 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysNoticeService.java @@ -0,0 +1,91 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysNoticeBo; +import cc.iotkit.system.dto.vo.SysNoticeVo; + +import java.util.Collection; +import java.util.List; + +/** + * 公告 服务层 + * + * @author Lion Li + */ +public interface ISysNoticeService { + + + Paging selectPageNoticeList( PageRequest query); + + /** + * 查询公告信息 + * + * @param noticeId 公告ID + * @return 公告信息 + */ + SysNoticeVo selectNoticeById(Long noticeId); + + /** + * 查询公告列表 + * + * @param notice 公告信息 + * @return 公告集合 + */ + List selectNoticeList(SysNoticeBo notice); + + /** + * 新增公告 + * + * @param bo 公告信息 + * @return 结果 + */ + Long insertNotice(SysNoticeBo bo); + + /** + * 修改公告 + * + * @param bo 公告信息 + * @return 结果 + */ + void updateNotice(SysNoticeBo bo); + + /** + * 删除公告信息 + * + * @param noticeId 公告ID + * @return 结果 + */ + void deleteNoticeById(Long noticeId); + + /** + * 批量删除公告信息 + * + * @param noticeIds 需要删除的公告ID + * @return 结果 + */ + void deleteNoticeByIds(Collection noticeIds); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysOperLogService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysOperLogService.java new file mode 100644 index 0000000..f977b7d --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysOperLogService.java @@ -0,0 +1,78 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysOperLogBo; +import cc.iotkit.system.dto.vo.SysOperLogVo; + +import java.util.Collection; +import java.util.List; + +/** + * 操作日志 服务层 + * + * @author Lion Li + */ +public interface ISysOperLogService { + + Paging selectPageOperLogList(PageRequest query); + + /** + * 新增操作日志 + * + * @param bo 操作日志对象 + */ + void insertOperlog(SysOperLogBo bo); + + /** + * 查询系统操作日志集合 + * + * @param operLog 操作日志对象 + * @return 操作日志集合 + */ + List selectOperLogList(SysOperLogBo operLog); + + /** + * 批量删除系统操作日志 + * + * @param operIds 需要删除的操作日志ID + * @return 结果 + */ + void deleteOperLogByIds(Collection operIds); + + /** + * 查询操作日志详细 + * + * @param operId 操作ID + * @return 操作日志对象 + */ + SysOperLogVo selectOperLogById(Long operId); + + /** + * 清空操作日志 + */ + void cleanOperLog(); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysOssConfigService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysOssConfigService.java new file mode 100644 index 0000000..de75250 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysOssConfigService.java @@ -0,0 +1,88 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysOssConfigBo; +import cc.iotkit.system.dto.vo.SysOssConfigVo; + +import java.util.Collection; + +/** + * 对象存储配置Service接口 + * + * @author Lion Li + * @author 孤舟烟雨 + * @date 2021-08-13 + */ +public interface ISysOssConfigService { + + /** + * 初始化OSS配置 + */ + void init(); + + /** + * 查询单个 + */ + SysOssConfigVo queryById(Long ossConfigId); + + /** + * 查询列表 + */ + Paging queryPageList(PageRequest query); + + + /** + * 根据新增业务对象插入对象存储配置 + * + * @param bo 对象存储配置新增业务对象 + * @return + */ + Boolean insertByBo(SysOssConfigBo bo); + + /** + * 根据编辑业务对象修改对象存储配置 + * + * @param bo 对象存储配置编辑业务对象 + * @return + */ + Boolean updateByBo(SysOssConfigBo bo); + + /** + * 校验并删除数据 + * + * @param ids 主键集合 + * @param isValid 是否校验,true-删除前校验,false-不校验 + * @return + */ + Boolean deleteWithValidByIds(Collection ids, Boolean isValid); + + /** + * 启用停用状态 + */ + int updateOssConfigStatus(SysOssConfigBo bo); + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysOssService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysOssService.java new file mode 100644 index 0000000..a2e87ea --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysOssService.java @@ -0,0 +1,55 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysOssBo; +import cc.iotkit.system.dto.vo.SysOssVo; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.Collection; +import java.util.List; + +/** + * 文件上传 服务层 + * + * @author Lion Li + */ +public interface ISysOssService { + + Paging queryPageList(PageRequest query); + + List listByIds(Collection ossIds); + + SysOssVo getById(Long ossId); + + SysOssVo upload(MultipartFile file); + + void download(Long ossId) throws IOException; + + void deleteWithValidByIds(Collection ids, Boolean isValid); + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysPermissionService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysPermissionService.java new file mode 100644 index 0000000..c221caf --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysPermissionService.java @@ -0,0 +1,51 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import java.util.Set; + +/** + * 用户权限处理 + * + * @author Lion Li + */ +public interface ISysPermissionService { + + /** + * 获取角色数据权限 + * + * @param userId 用户id + * @return 角色权限信息 + */ + Set getRolePermission(Long userId); + + /** + * 获取菜单数据权限 + * + * @param userId 用户id + * @return 菜单权限信息 + */ + Set getMenuPermission(Long userId); + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysPostService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysPostService.java new file mode 100644 index 0000000..cc68f24 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysPostService.java @@ -0,0 +1,130 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysPostBo; +import cc.iotkit.system.dto.vo.SysPostVo; + +import java.util.Collection; +import java.util.List; + +/** + * 岗位信息 服务层 + * + * @author Lion Li + */ +public interface ISysPostService { + + + Paging selectPagePostList(PageRequest query); + + /** + * 查询岗位信息集合 + * + * @param post 岗位信息 + * @return 岗位列表 + */ + List selectPostList(SysPostBo post); + + /** + * 查询所有岗位 + * + * @return 岗位列表 + */ + List selectPostAll(); + + /** + * 通过岗位ID查询岗位信息 + * + * @param postId 岗位ID + * @return 角色对象信息 + */ + SysPostVo selectPostById(Long postId); + + /** + * 根据用户ID获取岗位选择框列表 + * + * @param userId 用户ID + * @return 选中岗位ID列表 + */ + List selectPostListByUserId(Long userId); + + /** + * 校验岗位名称 + * + * @param post 岗位信息 + * @return 结果 + */ + boolean checkPostNameUnique(SysPostBo post); + + /** + * 校验岗位编码 + * + * @param post 岗位信息 + * @return 结果 + */ + boolean checkPostCodeUnique(SysPostBo post); + + /** + * 通过岗位ID查询岗位使用数量 + * + * @param postId 岗位ID + * @return 结果 + */ + long countUserPostById(Long postId); + + /** + * 删除岗位信息 + * + * @param postId 岗位ID + * @return 结果 + */ + void deletePostById(Long postId); + + /** + * 批量删除岗位信息 + * + * @param postIds 需要删除的岗位ID + * @return 结果 + */ + void deletePostByIds(Collection postIds); + + /** + * 新增保存岗位信息 + * + * @param bo 岗位信息 + * @return 结果 + */ + void insertPost(SysPostBo bo); + + /** + * 修改保存岗位信息 + * + * @param bo 岗位信息 + * @return 结果 + */ + void updatePost(SysPostBo bo); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysRoleService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysRoleService.java new file mode 100644 index 0000000..4e7af65 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysRoleService.java @@ -0,0 +1,207 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.model.system.SysUserRole; +import cc.iotkit.system.dto.bo.SysRoleBo; +import cc.iotkit.system.dto.vo.SysRoleVo; + +import java.util.Collection; +import java.util.List; +import java.util.Set; + +/** + * 角色业务层 + * + * @author Lion Li + */ +public interface ISysRoleService { + + + Paging selectPageRoleList(PageRequest query); + + /** + * 根据条件分页查询角色数据 + * + * @param role 角色信息 + * @return 角色数据集合信息 + */ + List selectRoleList(SysRoleBo role); + + /** + * 根据用户ID查询角色列表 + * + * @param userId 用户ID + * @return 角色列表 + */ + List selectRolesByUserId(Long userId); + + /** + * 根据用户ID查询角色权限 + * + * @param userId 用户ID + * @return 权限列表 + */ + Set selectRolePermissionByUserId(Long userId); + + /** + * 查询所有角色 + * + * @return 角色列表 + */ + List selectRoleAll(); + + /** + * 根据用户ID获取角色选择框列表 + * + * @param userId 用户ID + * @return 选中角色ID列表 + */ + List selectRoleListByUserId(Long userId); + + /** + * 通过角色ID查询角色 + * + * @param roleId 角色ID + * @return 角色对象信息 + */ + SysRoleVo selectRoleById(Long roleId); + + /** + * 校验角色名称是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + boolean checkRoleNameUnique(SysRoleBo role); + + /** + * 校验角色权限是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + boolean checkRoleKeyUnique(SysRoleBo role); + + /** + * 校验角色是否允许操作 + * + * @param roleId 角色ID + */ + void checkRoleAllowed(Long roleId); + + /** + * 校验角色是否有数据权限 + * + * @param roleId 角色id + */ + void checkRoleDataScope(Long roleId); + + /** + * 通过角色ID查询角色使用数量 + * + * @param roleId 角色ID + * @return 结果 + */ + long countUserRoleByRoleId(Long roleId); + + /** + * 新增保存角色信息 + * + * @param bo 角色信息 + * @return 结果 + */ + int insertRole(SysRoleBo bo); + + /** + * 修改保存角色信息 + * + * @param bo 角色信息 + * @return 结果 + */ + int updateRole(SysRoleBo bo); + + /** + * 修改角色状态 + * + * @param roleId 角色ID + * @param status 角色状态 + * @return 结果 + */ + void updateRoleStatus(Long roleId, String status); + + /** + * 修改数据权限信息 + * + * @param bo 角色信息 + * @return 结果 + */ + int authDataScope(SysRoleBo bo); + + /** + * 通过角色ID删除角色 + * + * @param roleId 角色ID + * @return 结果 + */ + void deleteRoleById(Long roleId); + + /** + * 批量删除角色信息 + * + * @param roleIds 需要删除的角色ID + * @return 结果 + */ + void deleteRoleByIds(Collection roleIds); + + /** + * 取消授权用户角色 + * + * @param userRole 用户和角色关联信息 + * @return 结果 + */ + void deleteAuthUser(SysUserRole userRole); + + /** + * 批量取消授权用户角色 + * + * @param roleId 角色ID + * @param userIds 需要取消授权的用户数据ID + * @return 结果 + */ + void deleteAuthUsers(Long roleId, Long[] userIds); + + /** + * 批量选择授权用户角色 + * + * @param roleId 角色ID + * @param userIds 需要删除的用户数据ID + * @return 结果 + */ + void insertAuthUsers(Long roleId, Long[] userIds); + + void cleanOnlineUserByRole(Long roleId); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysTenantPackageService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysTenantPackageService.java new file mode 100644 index 0000000..db23012 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysTenantPackageService.java @@ -0,0 +1,80 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysTenantPackageBo; +import cc.iotkit.system.dto.vo.SysTenantPackageVo; + +import java.util.Collection; +import java.util.List; + +/** + * 租户套餐Service接口 + * + * @author Michelle.Chung + */ +public interface ISysTenantPackageService { + + /** + * 查询租户套餐 + */ + SysTenantPackageVo queryById(Long packageId); + + /** + * 查询租户套餐列表 + */ + Paging queryPageList( PageRequest query); + + /** + * 查询租户套餐已启用列表 + */ + List selectList(); + + /** + * 查询租户套餐列表 + */ + List queryList(SysTenantPackageBo bo); + + /** + * 新增租户套餐 + */ + Boolean insertByBo(SysTenantPackageBo bo); + + /** + * 修改租户套餐 + */ + Boolean updateByBo(SysTenantPackageBo bo); + + /** + * 修改套餐状态 + */ + void updatePackageStatus(SysTenantPackageBo bo); + + /** + * 校验并批量删除租户套餐信息 + */ + Boolean deleteWithValidByIds(Collection ids, Boolean isValid); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysTenantService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysTenantService.java new file mode 100644 index 0000000..2d9481d --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysTenantService.java @@ -0,0 +1,104 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysTenantBo; +import cc.iotkit.system.dto.vo.SysTenantVo; + +import java.util.List; + +/** + * 租户Service接口 + * + * @author Michelle.Chung + */ +public interface ISysTenantService { + + /** + * 查询租户 + */ + SysTenantVo queryById(Long id); + + /** + * 基于租户ID查询租户 + */ + SysTenantVo queryByTenantId(Long tenantId); + + /** + * 查询租户列表 + */ + Paging queryPageList( PageRequest query); + + /** + * 查询租户列表 + */ + List queryList(SysTenantBo bo); + + /** + * 新增租户 + */ + void insertByBo(SysTenantBo bo); + + /** + * 修改租户 + */ + void updateByBo(SysTenantBo bo); + + /** + * 修改租户状态 + */ + int updateTenantStatus(SysTenantBo bo); + + /** + * 校验租户是否允许操作 + */ + void checkTenantAllowed(Long tenantId); + + /** + * 删除租户信息 + */ + void deleteById(Long id); + + /** + * 校验企业名称是否唯一 + */ + boolean checkCompanyNameUnique(SysTenantBo bo); + + /** + * 校验账号余额 + */ + boolean checkAccountBalance(Long tenantId); + + /** + * 校验有效期 + */ + boolean checkExpireTime(Long tenantId); + + /** + * 同步租户套餐 + */ + Boolean syncTenantPackage(Long tenantId, String packageId); +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysUserService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysUserService.java new file mode 100644 index 0000000..59beeda --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysUserService.java @@ -0,0 +1,227 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.system.dto.bo.SysUserBo; +import cc.iotkit.system.dto.vo.SysUserVo; + +import java.util.Collection; +import java.util.List; + +/** + * 用户 业务层 + * + * @author Lion Li + */ +public interface ISysUserService { + + + Paging selectPageUserList(PageRequest query); + + /** + * 根据条件分页查询用户列表 + * + * @param user 用户信息 + * @return 用户信息集合信息 + */ + List selectUserList(SysUserBo user); + + /** + * 根据条件分页查询已分配用户角色列表 + * + * @return 用户信息集合信息 + */ + Paging selectAllocatedList( PageRequest query); + + /** + * 根据条件分页查询未分配用户角色列表 + * + * @return 用户信息集合信息 + */ + Paging selectUnallocatedList( PageRequest query); + + /** + * 通过用户名查询用户 + * + * @param userName 用户名 + * @return 用户对象信息 + */ + SysUserVo selectUserByUserName(String userName); + + /** + * 通过手机号查询用户 + * + * @param phonenumber 手机号 + * @return 用户对象信息 + */ + SysUserVo selectUserByPhonenumber(String phonenumber); + + /** + * 通过用户ID查询用户 + * + * @param userId 用户ID + * @return 用户对象信息 + */ + SysUserVo selectUserById(Long userId); + + /** + * 根据用户ID查询用户所属角色组 + * + * @param userName 用户名 + * @return 结果 + */ + String selectUserRoleGroup(String userName); + + /** + * 根据用户ID查询用户所属岗位组 + * + * @param userName 用户名 + * @return 结果 + */ + String selectUserPostGroup(String userName); + + /** + * 校验用户名称是否唯一 + * + * @param user 用户信息 + * @return 结果 + */ + boolean checkUserNameUnique(SysUserBo user); + + /** + * 校验手机号码是否唯一 + * + * @param user 用户信息 + * @return 结果 + */ + boolean checkPhoneUnique(SysUserBo user); + + /** + * 校验email是否唯一 + * + * @param user 用户信息 + * @return 结果 + */ + boolean checkEmailUnique(SysUserBo user); + + /** + * 校验用户是否允许操作 + * + * @param user 用户信息 + */ + void checkUserAllowed(SysUserBo user); + + /** + * 校验用户是否有数据权限 + * + * @param userId 用户id + */ + void checkUserDataScope(Long userId); + + /** + * 新增用户信息 + * + * @param user 用户信息 + * @return 结果 + */ + int insertUser(SysUserBo user); + + /** + * 注册用户信息 + * + * @param user 用户信息 + * @return 结果 + */ + boolean registerUser(SysUserBo user, Long tenantId); + + /** + * 修改用户信息 + * + * @param user 用户信息 + * @return 结果 + */ + int updateUser(SysUserBo user); + + /** + * 用户授权角色 + * + * @param userId 用户ID + * @param roleIds 角色组 + */ + void insertUserAuth(Long userId, List roleIds); + + /** + * 修改用户状态 + * + * @param userId 用户ID + * @param status 帐号状态 + * @return 结果 + */ + int updateUserStatus(Long userId, String status); + + /** + * 修改用户基本信息 + * + * @param user 用户信息 + * @return 结果 + */ + int updateUserProfile(SysUserBo user); + + /** + * 修改用户头像 + * + * @param userId 用户ID + * @param avatar 头像地址 + * @return 结果 + */ + boolean updateUserAvatar(Long userId, Long avatar); + + /** + * 重置用户密码 + * + * @param userId 用户ID + * @param password 密码 + * @return 结果 + */ + int resetUserPwd(Long userId, String password); + + /** + * 通过用户ID删除用户 + * + * @param userId 用户ID + * @return 结果 + */ + int deleteUserById(Long userId); + + /** + * 批量删除用户信息 + * + * @param userIds 需要删除的用户ID + * @return 结果 + */ + void deleteUserByIds(Collection userIds); + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysAppServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysAppServiceImpl.java new file mode 100644 index 0000000..3645e95 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysAppServiceImpl.java @@ -0,0 +1,131 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.system.ISysAppData; +import cc.iotkit.model.system.SysApp; +import cc.iotkit.system.dto.bo.SysAppBo; +import cc.iotkit.system.dto.vo.SysAppVo; +import cc.iotkit.system.service.ISysAppService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + + +/** + * 应用信息Service业务层处理 + * + * @author tfd + * @date 2023-08-10 + */ +@RequiredArgsConstructor +@Service +public class SysAppServiceImpl implements ISysAppService { + + private final ISysAppData baseData; + + /** + * 查询应用信息 + */ + @Override + public SysAppVo queryById(Long id){ + return MapstructUtils.convert(baseData.findById(id), SysAppVo.class); + } + + @Override + public SysAppVo queryByAppId(String appId) { + SysApp ret=baseData.findByAppId(appId); + return ret!=null?MapstructUtils.convert(ret,SysAppVo.class):null; + } + + @Override + public boolean checkAppIdUnique(String appId) { + return baseData.findByAppId(appId)!=null; + } + + /** + * 查询应用信息列表 + */ + @Override + public Paging queryPageList(PageRequest pageQuery) { + Paging result = baseData.findAll(pageQuery.to(SysApp.class)).to(SysAppVo.class); + return result; + } + + /** + * 查询应用信息列表 + */ + @Override + public List queryList(SysAppBo bo) { + + return MapstructUtils.convert(baseData.findAllByCondition(bo.to(SysApp.class)), SysAppVo.class); + } + + /** + * 新增应用信息 + */ + @Override + public Long insertByBo(SysAppBo bo) { + SysApp add = MapstructUtils.convert(bo, SysApp.class); + baseData.save(add); + if (add == null) { + throw new BizException("新增失败"); + } + return add.getId(); + } + + /** + * 修改应用信息 + */ + @Override + public Boolean updateByBo(SysAppBo bo) { + SysApp update = MapstructUtils.convert(bo, SysApp.class); + validEntityBeforeSave(update); + SysApp ret = baseData.save(update); + if(ret == null){ + return false; + } + return true; + } + + /** + * 保存前的数据校验 + */ + private void validEntityBeforeSave(SysApp entity){ + } + + /** + * 批量删除应用信息 + */ + @Override + public Boolean deleteById(Long id) { + baseData.deleteById(id); + return true; + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysConfigServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysConfigServiceImpl.java new file mode 100644 index 0000000..ab937bf --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysConfigServiceImpl.java @@ -0,0 +1,273 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.CacheNames; +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.redis.utils.CacheUtils; +import cc.iotkit.common.service.ConfigService; +import cc.iotkit.common.utils.*; +import cc.iotkit.data.ICommonData; +import cc.iotkit.data.manager.*; +import cc.iotkit.data.system.*; +import cc.iotkit.model.system.SysConfig; +import cc.iotkit.system.dto.bo.SysConfigBo; +import cc.iotkit.system.dto.vo.SysConfigVo; +import cc.iotkit.system.service.ISysConfigService; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ZipUtil; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +/** + * 参数配置 服务层实现 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Service +public class SysConfigServiceImpl implements ISysConfigService, ConfigService { + + @Autowired + private ISysConfigData sysConfigData; + + @Override + public Paging selectPageConfigList(PageRequest query) { + return sysConfigData.findAllByConditions(query.to(SysConfig.class)).to(SysConfigVo.class); + } + + /** + * 查询参数配置信息 + * + * @param configId 参数配置ID + * @return 参数配置信息 + */ + @Override + public SysConfigVo selectConfigById(Long configId) { + return sysConfigData.findById(configId).to(SysConfigVo.class); + } + + /** + * 根据键名查询参数配置信息 + * + * @param configKey 参数key + * @return 参数键值 + */ + @Override + public String selectConfigByKey(String configKey) { + SysConfig sysConfig = sysConfigData.findByConfigKey(configKey); + if (ObjectUtil.isNotNull(sysConfig)) { + return sysConfig.getConfigValue(); + } + return StringUtils.EMPTY; + } + + /** + * 获取注册开关 + * + * @param tenantId 租户id + * @return true开启,false关闭 + */ + @Override + public boolean selectRegisterEnabled(Long tenantId) { + SysConfig query = new SysConfig(); + query.setConfigKey("sys.account.registerUser"); + SysConfig retConfig = sysConfigData.findOneByCondition(query); + + if (ObjectUtil.isNull(retConfig)) { + return false; + } + return Convert.toBool(retConfig.getConfigValue()); + } + + /** + * 查询参数配置列表 + * + * @param config 参数配置信息 + * @return 参数配置集合 + */ + @Override + public List selectConfigList(SysConfigBo config) { + + List allByCondition = sysConfigData.findAllByCondition(MapstructUtils.convert(config, SysConfig.class)); + return MapstructUtils.convert(allByCondition, SysConfigVo.class); + } + + /** + * 新增参数配置 + * + * @param bo 参数配置信息 + * @return 结果 + */ + @Override + public String insertConfig(SysConfigBo bo) { + SysConfig to = bo.to(SysConfig.class); + sysConfigData.save(to); + return String.valueOf(to.getId()); + } + + /** + * 修改参数配置 + * + * @param bo 参数配置信息 + * @return 结果 + */ +// @CachePut(cacheNames = CacheNames.SYS_CONFIG, key = "#bo.configKey") + @Override + public String updateConfig(SysConfigBo bo) { + SysConfig config = MapstructUtils.convert(bo, SysConfig.class); + if (config.getId() == null) { + SysConfig old = sysConfigData.findByConfigKey(config.getConfigKey()); + if (old == null) { + throw new BizException("操作失败,key不存在"); + } + config.setId(old.getId()); + } + + sysConfigData.save(config); + return config.getConfigValue(); + } + + /** + * 批量删除参数信息 + * + * @param configIds 需要删除的参数ID + */ + @Override + public void deleteConfigByIds(List configIds) { + for (Long configId : configIds) { + SysConfig old = sysConfigData.findById(configId); + if (StringUtils.equals(UserConstants.YES, old.getConfigType())) { + throw new BizException(String.format("内置参数【%1$s】不能删除 ", old.getConfigKey())); + } + CacheUtils.evict(CacheNames.SYS_CONFIG, old.getConfigKey()); + } + sysConfigData.deleteByIds(configIds); + } + + /** + * 重置参数缓存数据 + */ + @Override + public void resetConfigCache() { + CacheUtils.clear(CacheNames.SYS_CONFIG); + } + + /** + * 校验参数键名是否唯一 + * + * @param config 参数配置信息 + * @return 结果 + */ + @Override + public boolean checkConfigKeyUnique(SysConfigBo config) { + long configId = ObjectUtil.isNull(config.getId()) ? -1L : config.getId(); + SysConfig old = sysConfigData.findByConfigKey(config.getConfigKey()); + return !ObjectUtil.isNotNull(old) || old.getId() == configId; + } + + /** + * 根据参数 key 获取参数值 + * + * @param configKey 参数 key + * @return 参数值 + */ + @Override + public String getConfigValue(String configKey) { + return SpringUtils.getAopProxy(this).selectConfigByKey(configKey); + } + + @Override + public File backupSysData() { + File fileDir = new File("./data/backup/" + DateUtils.dateTimeNow()); + if (!fileDir.exists()) { + FileUtil.mkdir(fileDir); + } + writeData(fileDir, "category", SpringUtils.getBean(ICategoryData.class)); + writeData(fileDir, "channel", SpringUtils.getBean(IChannelData.class)); + writeData(fileDir, "channelConfig", SpringUtils.getBean(IChannelConfigData.class)); + writeData(fileDir, "channelTemplate", SpringUtils.getBean(IChannelTemplateData.class)); + writeData(fileDir, "deviceGroup", SpringUtils.getBean(IDeviceGroupData.class)); + writeData(fileDir, "deviceInfo", SpringUtils.getBean(IDeviceInfoData.class)); + writeData(fileDir, "home", SpringUtils.getBean(IHomeData.class)); + writeData(fileDir, "notifyMessage", SpringUtils.getBean(INotifyMessageData.class)); + writeData(fileDir, "product", SpringUtils.getBean(IProductData.class)); + writeData(fileDir, "productModel", SpringUtils.getBean(IProductModelData.class)); + writeData(fileDir, "ruleInfo", SpringUtils.getBean(IRuleInfoData.class)); + writeData(fileDir, "space", SpringUtils.getBean(ISpaceData.class)); + writeData(fileDir, "spaceDevice", SpringUtils.getBean(ISpaceDeviceData.class)); + writeData(fileDir, "sys_app", SpringUtils.getBean(ISysAppData.class)); + writeData(fileDir, "sys_config", SpringUtils.getBean(ISysConfigData.class)); + writeData(fileDir, "sys_dept", SpringUtils.getBean(ISysDeptData.class)); + writeData(fileDir, "sys_dict_data", SpringUtils.getBean(ISysDictData.class)); + writeData(fileDir, "sys_dict_type", SpringUtils.getBean(ISysDictTypeData.class)); + writeData(fileDir, "sys_logininfor", SpringUtils.getBean(ISysLogininforData.class)); + writeData(fileDir, "sys_menu", SpringUtils.getBean(ISysMenuData.class)); + writeData(fileDir, "sys_notice", SpringUtils.getBean(ISysNoticeData.class)); + writeData(fileDir, "sys_oper_log", SpringUtils.getBean(ISysOperLogData.class)); + writeData(fileDir, "sys_oss", SpringUtils.getBean(ISysOssData.class)); + writeData(fileDir, "sys_oss_config", SpringUtils.getBean(ISysOssConfigData.class)); + writeData(fileDir, "sys_post", SpringUtils.getBean(ISysPostData.class)); + writeData(fileDir, "sys_role", SpringUtils.getBean(ISysRoleData.class)); + writeData(fileDir, "sys_role_dept", SpringUtils.getBean(ISysRoleDeptData.class)); + writeData(fileDir, "sys_role_menu", SpringUtils.getBean(ISysRoleMenuData.class)); + writeData(fileDir, "sys_tenant", SpringUtils.getBean(ISysTenantData.class)); + writeData(fileDir, "sys_tenant_package", SpringUtils.getBean(ISysTenantPackageData.class)); + writeData(fileDir, "sys_user", SpringUtils.getBean(ISysUserData.class)); + writeData(fileDir, "sys_user_post", SpringUtils.getBean(ISysUserPostData.class)); + writeData(fileDir, "sys_user_role", SpringUtils.getBean(ISysUserRoleData.class)); + writeData(fileDir, "taskInfo", SpringUtils.getBean(ITaskInfoData.class)); + writeData(fileDir, "thingModel", SpringUtils.getBean(IThingModelData.class)); + writeData(fileDir, "userInfo", SpringUtils.getBean(IUserInfoData.class)); + writeData(fileDir, "virtualDevice", SpringUtils.getBean(IVirtualDeviceData.class)); + writeData(fileDir, "pluginInfo", SpringUtils.getBean(IPluginInfoData.class)); + String zipPath = fileDir.getAbsolutePath() + ".zip"; + ZipUtil.zip(fileDir.getAbsolutePath(), zipPath); + return new File(zipPath); + } + + @SneakyThrows + private void writeData(File dir, String name, ICommonData data) { + Path path = Paths.get(dir.getAbsolutePath(), name + ".json"); + ObjectMapper mapper=new ObjectMapper(); + mapper.enable(SerializationFeature.INDENT_OUTPUT); + String formattedJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(data.findAll()); + FileUtil.writeString(formattedJson, path.toFile(), StandardCharsets.UTF_8); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDataScopeServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDataScopeServiceImpl.java new file mode 100644 index 0000000..22da328 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDataScopeServiceImpl.java @@ -0,0 +1,72 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * 数据权限 实现 + *

+ * 注意: 此Service内不允许调用标注`数据权限`注解的方法 + * 例如: deptMapper.selectList 此 selectList 方法标注了`数据权限`注解 会出现循环解析的问题 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Service("sdss") +public class SysDataScopeServiceImpl { +// +// private final SysRoleDeptMapper roleDeptMapper; +// private final SysDeptMapper deptMapper; +// +// @Override +// public String getRoleCustom(Long roleId) { +// List list = roleDeptMapper.selectList( +// new LambdaQueryWrapper() +// .select(SysRoleDept::getDeptId) +// .eq(SysRoleDept::getRoleId, roleId)); +// if (CollUtil.isNotEmpty(list)) { +// return StreamUtils.join(list, rd -> Convert.toStr(rd.getDeptId())); +// } +// return null; +// } +// +// @Override +// public String getDeptAndChild(Long deptId) { +// List deptList = deptMapper.selectList(new LambdaQueryWrapper() +// .select(SysDept::getDeptId) +// .apply(DataBaseHelper.findInSet(deptId, "ancestors"))); +// List ids = StreamUtils.toList(deptList, SysDept::getDeptId); +// ids.add(deptId); +// List list = deptMapper.selectList(new LambdaQueryWrapper() +// .select(SysDept::getDeptId) +// .in(SysDept::getDeptId, ids)); +// if (CollUtil.isNotEmpty(list)) { +// return StreamUtils.join(list, d -> Convert.toStr(d.getDeptId())); +// } +// return null; +// } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDeptServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDeptServiceImpl.java new file mode 100644 index 0000000..2195463 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDeptServiceImpl.java @@ -0,0 +1,326 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.service.DeptService; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.SpringUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.utils.TreeBuildUtils; +import cc.iotkit.data.system.ISysDeptData; +import cc.iotkit.data.system.ISysRoleData; +import cc.iotkit.data.system.ISysUserData; +import cc.iotkit.model.system.SysDept; +import cc.iotkit.system.dto.bo.SysDeptBo; +import cc.iotkit.system.dto.vo.SysDeptVo; +import cc.iotkit.system.service.ISysDeptService; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.lang.tree.Tree; +import cn.hutool.core.util.ObjectUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 部门管理 服务实现 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Service +public class SysDeptServiceImpl implements ISysDeptService, DeptService { + + private final ISysDeptData sysDeptData; + + private final ISysRoleData sysRoleData; + + private final ISysUserData sysUserData; + + /** + * 查询部门管理数据 + * + * @param dept 部门信息 + * @return 部门信息集合 + */ + @Override + public List selectDeptList(SysDeptBo dept) { + return MapstructUtils.convert( + sysDeptData.findDepts(dept.to(SysDept.class)) + , SysDeptVo.class); + } + + /** + * 查询部门树结构信息 + * + * @param bo 部门信息 + * @return 部门树信息集合 + */ + @Override + @Transactional + public List> selectDeptTreeList(SysDeptBo bo) { + List depts = sysDeptData.findDepts(bo.to(SysDept.class)); + return buildDeptTreeSelect(depts); + } + + /** + * 构建前端所需要下拉树结构 + * + * @param depts 部门列表 + * @return 下拉树结构列表 + */ + @Override + public List> buildDeptTreeSelect(List depts) { + if (CollUtil.isEmpty(depts)) { + return CollUtil.newArrayList(); + } + return TreeBuildUtils.build(depts, (dept, tree) -> + tree.setId(dept.getId()) + .setParentId(dept.getParentId()) + .setName(dept.getDeptName()) + .setWeight(dept.getOrderNum())); + } + + /** + * 根据角色ID查询部门树信息 + * + * @param roleId 角色ID + * @return 选中部门列表 + */ + @Override + public List selectDeptListByRoleId(Long roleId) { + return sysDeptData.findByRoleId(roleId).stream() + .map(SysDept::getId).collect(Collectors.toList()); + } + + /** + * 根据部门ID查询信息 + * + * @param deptId 部门ID + * @return 部门信息 + */ +// @Cacheable(cacheNames = CacheNames.SYS_DEPT, key = "#deptId") + @Override + public SysDeptVo selectDeptById(Long deptId) { + SysDept dept = sysDeptData.findById(deptId); + if (ObjectUtil.isNull(dept)) { + return null; + } + + SysDept parentDept = sysDeptData.findById(dept.getParentId()); + dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null); + return MapstructUtils.convert(dept, SysDeptVo.class); + } + + /** + * 通过部门ID查询部门名称 + * + * @param deptIds 部门ID串逗号分隔 + * @return 部门名称串逗号分隔 + */ + @Override + public String selectDeptNameByIds(String deptIds) { + List list = new ArrayList<>(); + for (Long id : StringUtils.splitTo(deptIds, Convert::toLong)) { + SysDeptVo vo = SpringUtils.getAopProxy(this).selectDeptById(id); + if (ObjectUtil.isNotNull(vo)) { + list.add(vo.getDeptName()); + } + } + return String.join(StringUtils.SEPARATOR, list); + } + + /** + * 根据ID查询所有子部门数(正常状态) + * + * @param deptId 部门ID + * @return 子部门数 + */ + @Override + public long selectNormalChildrenDeptById(Long deptId) { + return sysDeptData.selectNormalChildrenDeptById(deptId); + } + + /** + * 是否存在子节点 + * + * @param deptId 部门ID + * @return 结果 + */ + @Override + public boolean hasChildByDeptId(Long deptId) { + return sysDeptData.countByParentId(deptId) > 0; + } + + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 true 存在 false 不存在 + */ + @Override + public boolean checkDeptExistUser(Long deptId) { + return sysUserData.countByDeptId(deptId) > 0; + } + + /** + * 校验部门名称是否唯一 + * + * @param dept 部门信息 + * @return 结果 + */ + @Override + public boolean checkDeptNameUnique(SysDeptBo dept) { + return sysDeptData.checkDeptNameUnique(dept.getDeptName(), dept.getParentId(), dept.getId()); + } + + /** + * 校验部门是否有数据权限 + * + * @param deptId 部门id + */ + @Override + public void checkDeptDataScope(Long deptId) { + if (ObjectUtil.isNull(deptId)) { + return; + } + if (LoginHelper.isSuperAdmin()) { + return; + } + SysDept dept = sysDeptData.findById(deptId); + if (ObjectUtil.isNull(dept)) { + throw new BizException("没有权限访问部门数据!"); + } + } + + /** + * 新增保存部门信息 + * + * @param bo 部门信息 + */ + @Override + public void insertDept(SysDeptBo bo) { + SysDept parent = sysDeptData.findById(bo.getParentId()); + // 如果父节点不为正常状态,则不允许新增子节点 + if (!UserConstants.DEPT_NORMAL.equals(parent.getStatus())) { + throw new BizException("部门停用,不允许新增"); + } + SysDept dept = MapstructUtils.convert(bo, SysDept.class); + dept.setAncestors(parent.getAncestors() + StringUtils.SEPARATOR + dept.getParentId()); + sysDeptData.save(dept); + } + + /** + * 修改保存部门信息 + * + * @param bo 部门信息 + * @return 结果 + */ +// @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId") + @Override + public void updateDept(SysDeptBo bo) { + SysDept dept = MapstructUtils.convert(bo, SysDept.class); + SysDept oldDept = sysDeptData.findById(bo.getId()); + if (oldDept == null) { + throw new BizException(ErrCode.DATA_NOT_EXIST); + } + + if (!oldDept.getParentId().equals(dept.getParentId())) { + // 如果是新父部门 则校验是否具有新父部门权限 避免越权 + this.checkDeptDataScope(dept.getParentId()); + SysDept newParentDept = sysDeptData.findById(dept.getParentId()); + if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(oldDept)) { + String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getId(); + String oldAncestors = oldDept.getAncestors(); + dept.setAncestors(newAncestors); + updateDeptChildren(dept.getId(), newAncestors, oldAncestors); + } + } + + sysDeptData.save(dept); + if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) + && !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) { + // 如果该部门是启用状态,则启用该部门的所有上级部门 + updateParentDeptStatusNormal(dept); + } + } + + /** + * 修改该部门的父级部门状态 + * + * @param dept 当前部门 + */ + private void updateParentDeptStatusNormal(SysDept dept) { +// String ancestors = dept.getAncestors(); +// Long[] deptIds = Convert.toLongArray(ancestors); +// baseMapper.update(null, new LambdaUpdateWrapper() +// .set(SysDept::getStatus, UserConstants.DEPT_NORMAL) +// .in(SysDept::getDeptId, Arrays.asList(deptIds))); + } + + /** + * 修改子元素关系 + * + * @param deptId 被修改的部门ID + * @param newAncestors 新的父ID集合 + * @param oldAncestors 旧的父ID集合 + */ + private void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) { +// List children = baseMapper.selectList(new LambdaQueryWrapper() +// .apply(DataBaseHelper.findInSet(deptId, "ancestors"))); +// List list = new ArrayList<>(); +// for (SysDept child : children) { +// SysDept dept = new SysDept(); +// dept.setDeptId(child.getDeptId()); +// dept.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); +// list.add(dept); +// } +// if (CollUtil.isNotEmpty(list)) { +// if (baseMapper.updateBatchById(list)) { +// list.forEach(dept -> CacheUtils.evict(CacheNames.SYS_DEPT, dept.getDeptId())); +// } +// } + } + + /** + * 删除部门管理信息 + * + * @param deptId 部门ID + * @return 结果 + */ +// @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId") + @Override + public void deleteDeptById(Long deptId) { + sysDeptData.deleteById(deptId); + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDictDataServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDictDataServiceImpl.java new file mode 100644 index 0000000..eef399c --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDictDataServiceImpl.java @@ -0,0 +1,136 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.CacheNames; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.system.ISysDictData; +import cc.iotkit.model.system.SysDictData; +import cc.iotkit.system.dto.bo.SysDictDataBo; +import cc.iotkit.system.dto.vo.SysDictDataVo; +import cc.iotkit.system.service.ISysDictDataService; +import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CachePut; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 字典 业务层处理 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Service +public class SysDictDataServiceImpl implements ISysDictDataService { + + private final ISysDictData sysDictData; + + @Override + public Paging selectPageDictDataList( PageRequest query) { + return sysDictData.findAll(query.to(SysDictData.class) ).to(SysDictDataVo.class); + } + + /** + * 根据条件分页查询字典数据 + * + * @param dictData 字典数据信息 + * @return 字典数据集合信息 + */ + @Override + public List selectDictDataList(SysDictDataBo dictData) { + return MapstructUtils.convert( + sysDictData.findByConditions( + MapstructUtils.convert(dictData, SysDictData.class) + ), SysDictDataVo.class); + } + + /** + * 根据字典类型和字典键值查询字典数据信息 + * + * @param dictType 字典类型 + * @param dictValue 字典键值 + * @return 字典标签 + */ + @Override + public String selectDictLabel(String dictType, String dictValue) { + return sysDictData.findByDictTypeAndDictValue(dictType, dictValue).getDictLabel(); + } + + /** + * 根据字典数据ID查询信息 + * + * @param dictCode 字典数据ID + * @return 字典数据 + */ + @Override + public SysDictDataVo selectDictDataById(Long dictCode) { + return MapstructUtils.convert(sysDictData.findById(dictCode), SysDictDataVo.class); + } + + /** + * 批量删除字典数据信息 + * + * @param dictCodes 需要删除的字典数据ID + */ + @Override + public void deleteDictDataByIds(Long[] dictCodes) { + for (Long dictCode : dictCodes) { + SysDictData data = sysDictData.findById(dictCode); + sysDictData.deleteById(dictCode); +// CacheUtils.evict(CacheNames.SYS_DICT, data.getDictType()); + } + } + + /** + * 新增保存字典数据信息 + * + * @param bo 字典数据信息 + * @return 结果 + */ + @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#bo.dictType") + @Override + public List insertDictData(SysDictDataBo bo) { + SysDictData data = MapstructUtils.convert(bo, SysDictData.class); + sysDictData.save(data); + return MapstructUtils.convert(sysDictData.findByDicType(data.getDictType()), SysDictDataVo.class); + } + + /** + * 修改保存字典数据信息 + * + * @param bo 字典数据信息 + * @return 结果 + */ +// @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#bo.dictType") + @Override + public List updateDictData(SysDictDataBo bo) { + SysDictData data = MapstructUtils.convert(bo, SysDictData.class); + sysDictData.save(data); + return MapstructUtils.convert(sysDictData.findByDicType(data.getDictType()), SysDictDataVo.class); + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDictTypeServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDictTypeServiceImpl.java new file mode 100644 index 0000000..7e766db --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysDictTypeServiceImpl.java @@ -0,0 +1,256 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.CacheConstants; +import cc.iotkit.common.constant.CacheNames; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.redis.utils.CacheUtils; +import cc.iotkit.common.service.DictService; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.SpringUtils; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.system.ISysDictData; +import cc.iotkit.data.system.ISysDictTypeData; +import cc.iotkit.model.system.SysDictData; +import cc.iotkit.model.system.SysDictType; +import cc.iotkit.system.dto.bo.SysDictTypeBo; +import cc.iotkit.system.dto.vo.SysDictDataVo; +import cc.iotkit.system.dto.vo.SysDictTypeVo; +import cc.iotkit.system.service.ISysDictTypeService; +import cn.dev33.satoken.context.SaHolder; +import cn.hutool.core.util.ObjectUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * 字典 业务层处理 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Service +public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService { + + private final ISysDictTypeData sysDictTypeData; + private final ISysDictData sysDictData; + + @Override + public Paging selectPageDictTypeList(PageRequest query) { + return sysDictTypeData.findAll(query.to(SysDictType.class)).to(SysDictTypeVo.class); + } + + /** + * 根据条件分页查询字典类型 + * + * @param dictType 字典类型信息 + * @return 字典类型集合信息 + */ + @Override + public List selectDictTypeList(SysDictTypeBo dictType) { + return MapstructUtils.convert( + sysDictTypeData.findByConditions( + dictType.to(SysDictType.class)), + SysDictTypeVo.class); + } + + /** + * 根据所有字典类型 + * + * @return 字典类型集合信息 + */ + @Override + public List selectDictTypeAll() { + return MapstructUtils.convert(sysDictTypeData.findAll(), SysDictTypeVo.class); + } + + /** + * 根据字典类型查询字典数据 + * + * @param dictType 字典类型 + * @return 字典数据集合信息 + */ +// @Cacheable(cacheNames = CacheNames.SYS_DICT, key = "#dictType") + @Override + public List selectDictDataByType(String dictType) { + return MapstructUtils.convert(sysDictData.findByDicType(dictType), SysDictDataVo.class); + } + + /** + * 根据字典类型ID查询信息 + * + * @param dictId 字典类型ID + * @return 字典类型 + */ + @Override + public SysDictTypeVo selectDictTypeById(Long dictId) { + return MapstructUtils.convert(sysDictTypeData.findById(dictId), SysDictTypeVo.class); + } + + /** + * 根据字典类型查询信息 + * + * @param dictType 字典类型 + * @return 字典类型 + */ +// @Cacheable(cacheNames = CacheNames.SYS_DICT, key = "#dictType") + @Override + public SysDictTypeVo selectDictTypeByType(String dictType) { + return MapstructUtils.convert(sysDictTypeData.findByDicType(dictType), SysDictTypeVo.class); + } + + /** + * 批量删除字典类型信息 + * + * @param dictIds 需要删除的字典ID + */ + @Override + public void deleteDictTypeByIds(Collection dictIds) { + for (Long dictId : dictIds) { + SysDictType dictType = sysDictTypeData.findById(dictId); + if (sysDictData.countByDicType(dictType.getDictType()) > 0) { + throw new BizException(String.format("%1$s已分配,不能删除", dictType.getDictName())); + } + CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType()); + } + sysDictTypeData.deleteByIds(dictIds); + } + + /** + * 重置字典缓存数据 + */ + @Override + public void resetDictCache() { + CacheUtils.clear(CacheNames.SYS_DICT); + } + + /** + * 新增保存字典类型信息 + * + * @param bo 字典类型信息 + * @return 结果 + */ +// @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#bo.dictType") + @Override + public List insertDictType(SysDictTypeBo bo) { + SysDictType dict = MapstructUtils.convert(bo, SysDictType.class); + sysDictTypeData.save(dict); + return new ArrayList<>(); + } + + /** + * 修改保存字典类型信息 + * + * @param bo 字典类型信息 + * @return 结果 + */ +// @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#bo.dictType") + @Override + public List updateDictType(SysDictTypeBo bo) { + SysDictType oldDict = sysDictTypeData.findById(bo.getId()); + List olds = sysDictData.findByDicType(oldDict.getDictType()); + for (SysDictData sd : olds) { + sd.setDictType(bo.getDictType()); + sysDictData.save(sd); + } + sysDictTypeData.save(bo.to(SysDictType.class)); +// CacheUtils.evict(CacheNames.SYS_DICT, oldDict.getDictType()); + return MapstructUtils.convert(sysDictData.findByDicType(bo.getDictType()), SysDictDataVo.class); + } + + /** + * 校验字典类型称是否唯一 + * + * @param dictType 字典类型 + * @return 结果 + */ + @Override + public boolean checkDictTypeUnique(SysDictTypeBo dictType) { + boolean exist = sysDictTypeData.checkDictTypeUnique(dictType.to(SysDictType.class)); + return !exist; + } + + /** + * 根据字典类型和字典值获取字典标签 + * + * @param dictType 字典类型 + * @param dictValue 字典值 + * @param separator 分隔符 + * @return 字典标签 + */ + @SuppressWarnings("unchecked cast") + @Override + public String getDictLabel(String dictType, String dictValue, String separator) { + // 优先从本地缓存获取 + List datas = (List) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType); + if (ObjectUtil.isNull(datas)) { + datas = selectDictDataByType(dictType); + SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas); + } + + Map map = StreamUtils.toMap(datas, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel); + if (StringUtils.containsAny(dictValue, separator)) { + return Arrays.stream(dictValue.split(separator)) + .map(v -> map.getOrDefault(v, StringUtils.EMPTY)) + .collect(Collectors.joining(separator)); + } else { + return map.getOrDefault(dictValue, StringUtils.EMPTY); + } + } + + /** + * 根据字典类型和字典标签获取字典值 + * + * @param dictType 字典类型 + * @param dictLabel 字典标签 + * @param separator 分隔符 + * @return 字典值 + */ + @SuppressWarnings("unchecked cast") + @Override + public String getDictValue(String dictType, String dictLabel, String separator) { + // 优先从本地缓存获取 + List datas = (List) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType); + if (ObjectUtil.isNull(datas)) { + datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); + SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas); + } + + Map map = StreamUtils.toMap(datas, SysDictDataVo::getDictLabel, SysDictDataVo::getDictValue); + if (StringUtils.containsAny(dictLabel, separator)) { + return Arrays.stream(dictLabel.split(separator)) + .map(l -> map.getOrDefault(l, StringUtils.EMPTY)) + .collect(Collectors.joining(separator)); + } else { + return map.getOrDefault(dictLabel, StringUtils.EMPTY); + } + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysLogininforServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysLogininforServiceImpl.java new file mode 100644 index 0000000..06716f1 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysLogininforServiceImpl.java @@ -0,0 +1,167 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.log.event.LogininforEvent; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.utils.ip.AddressUtils; +import cc.iotkit.common.web.utils.ServletUtils; +import cc.iotkit.data.system.ISysLogininforData; +import cc.iotkit.model.system.SysLoginInfo; +import cc.iotkit.system.dto.bo.SysLoginInfoBo; +import cc.iotkit.system.dto.vo.SysLogininforVo; +import cc.iotkit.system.service.ISysLogininforService; +import cn.hutool.http.useragent.UserAgent; +import cn.hutool.http.useragent.UserAgentUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.util.Collection; +import java.util.Date; +import java.util.List; + +/** + * 系统访问日志情况信息 服务层处理 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Slf4j +@Service +public class SysLogininforServiceImpl implements ISysLogininforService { + + private final ISysLogininforData sysLogininforData; + + /** + * 记录登录信息 + * + * @param logininforEvent 登录事件 + */ + @Async + @EventListener + public void recordLogininfor(LogininforEvent logininforEvent) { + HttpServletRequest request = logininforEvent.getRequest(); + final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent")); + final String ip = ServletUtils.getClientIP(); + + String address = AddressUtils.getRealAddressByIP(ip); + StringBuilder s = new StringBuilder(); + s.append(getBlock(ip)); + s.append(address); + s.append(getBlock(logininforEvent.getUsername())); + s.append(getBlock(logininforEvent.getStatus())); + s.append(getBlock(logininforEvent.getMessage())); + // 打印信息到日志 + log.info(s.toString(), logininforEvent.getArgs()); + // 获取客户端操作系统 + String os = userAgent.getOs().getName(); + // 获取客户端浏览器 + String browser = userAgent.getBrowser().getName(); + // 封装对象 + SysLoginInfoBo logininfor = new SysLoginInfoBo(); + logininfor.setTenantId(logininforEvent.getTenantId()); + logininfor.setUserName(logininforEvent.getUsername()); + logininfor.setIpaddr(ip); + logininfor.setLoginLocation(address); + logininfor.setBrowser(browser); + logininfor.setOs(os); + logininfor.setMsg(logininforEvent.getMessage()); + // 日志状态 + if (StringUtils.equalsAny(logininforEvent.getStatus(), Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER)) { + logininfor.setStatus(Constants.SUCCESS); + } else if (Constants.LOGIN_FAIL.equals(logininforEvent.getStatus())) { + logininfor.setStatus(Constants.FAIL); + } + // 插入数据 + insertLogininfor(logininfor); + } + + private String getBlock(Object msg) { + if (msg == null) { + msg = ""; + } + return "[" + msg.toString() + "]"; + } + + + + /** + * 新增系统登录日志 + * + * @param bo 访问日志对象 + */ + @Override + public void insertLogininfor(SysLoginInfoBo bo) { + SysLoginInfo logininfor = MapstructUtils.convert(bo, SysLoginInfo.class); + logininfor.setLoginTime(new Date()); + sysLogininforData.save(logininfor); + } + + /** + * 查询系统登录日志集合 + * + * @param logininfor 访问日志对象 + * @return 登录记录集合 + */ + @Override + public List selectLogininforList(SysLoginInfoBo logininfor) { + return MapstructUtils.convert( + sysLogininforData.findByConditions( + MapstructUtils.convert(logininfor, SysLoginInfo.class) + ), SysLogininforVo.class + ); + } + + /** + * 批量删除系统登录日志 + * + * @param infoIds 需要删除的登录日志ID + * @return 结果 + */ + @Override + public void deleteLogininforByIds(Collection infoIds) { + sysLogininforData.deleteByIds(infoIds); + } + + /** + * 清空系统登录日志 + */ + @Override + public void cleanLogininfor() { + sysLogininforData.deleteAll(); + } + + @Override + public Paging findAll(PageRequest query) { + return sysLogininforData.findAll(query.to(SysLoginInfo.class)).to(SysLogininforVo.class); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysMenuServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysMenuServiceImpl.java new file mode 100644 index 0000000..6a14811 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysMenuServiceImpl.java @@ -0,0 +1,459 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.utils.TreeBuildUtils; +import cc.iotkit.data.dao.SysTenantPackageRepository; +import cc.iotkit.data.system.ISysMenuData; +import cc.iotkit.data.system.ISysRoleData; +import cc.iotkit.data.system.ISysRoleMenuData; +import cc.iotkit.data.system.ISysTenantPackageData; +import cc.iotkit.data.util.PredicateBuilder; +import cc.iotkit.model.system.SysMenu; +import cc.iotkit.model.system.SysRole; +import cc.iotkit.model.system.SysTenantPackage; +import cc.iotkit.system.dto.bo.SysMenuBo; +import cc.iotkit.system.dto.vo.MetaVo; +import cc.iotkit.system.dto.vo.RouterVo; +import cc.iotkit.system.dto.vo.SysMenuVo; +import cc.iotkit.system.service.ISysMenuService; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.lang.tree.Tree; +import com.querydsl.core.types.Predicate; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; + +import static cc.iotkit.data.model.QTbSysConfig.tbSysConfig; +import static cc.iotkit.data.model.QTbSysMenu.tbSysMenu; + +/** + * 菜单 业务层处理 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Service +public class SysMenuServiceImpl implements ISysMenuService { + + private final ISysMenuData sysMenuData; + private final ISysRoleData sysRoleData; + private final ISysRoleMenuData iSysRoleMenuData; + + + private final ISysTenantPackageData iSysTenantPackageData; + + /** + * 根据用户查询系统菜单列表 + * + * @param userId 用户ID + * @return 菜单列表 + */ + @Override + public List selectMenuList(Long userId) { + return selectMenuList(new SysMenuBo(), userId); + } + + /** + * 查询系统菜单列表 + * + * @param bo 菜单信息 + * @param userId 用户信息 + * @return 菜单列表 + */ + @Override + public List selectMenuList(SysMenuBo bo, Long userId) { + boolean superAdmin = LoginHelper.isSuperAdmin(userId); + SysMenu sysMenu = MapstructUtils.convert(bo, SysMenu.class); + List sysMenuList = sysMenuData.selectMenuList(sysMenu, userId, superAdmin); + return MapstructUtils.convert(sysMenuList, SysMenuVo.class); + } + + /** + * 根据用户ID查询权限 + * + * @param userId 用户ID + * @return 权限列表 + */ + @Override + public Set selectMenuPermsByUserId(Long userId) { + List perms = sysMenuData.selectMenuPermsByUserId(userId); + Set permsSet = new HashSet<>(); + for (String perm : perms) { + if (StringUtils.isNotEmpty(perm)) { + permsSet.addAll(StringUtils.splitList(perm.trim())); + } + } + return permsSet; + } + + /** + * 根据角色ID查询权限 + * + * @param roleId 角色ID + * @return 权限列表 + */ + @Override + public Set selectMenuPermsByRoleId(Long roleId) { + List perms = sysMenuData.selectMenuPermsByRoleId(roleId); + Set permsSet = new HashSet<>(); + for (String perm : perms) { + if (StringUtils.isNotEmpty(perm)) { + permsSet.addAll(StringUtils.splitList(perm.trim())); + } + } + return permsSet; + } + + /** + * 根据用户ID查询菜单 + * + * @param userId 用户名称 + * @return 菜单列表 + */ + @Override + public List selectMenuTreeByUserId(Long userId) { + List menus = null; + if (LoginHelper.isSuperAdmin(userId)) { + menus = sysMenuData.selectMenuTreeAll(); + } else { + menus = sysMenuData.selectMenuTreeByUserId(userId); + } + return getChildPerms(menus, 0); + } + + /** + * 根据角色ID查询菜单树信息 + * + * @param roleId 角色ID + * @return 选中菜单列表 + */ + @Override + public List selectMenuListByRoleId(Long roleId) { + SysRole role = sysRoleData.findById(roleId); + Boolean flag = role.getMenuCheckStrictly(); + return sysRoleData.selectMenuListByRoleId(roleId, flag != null && flag); + } + + /** + * 构建前端路由所需要的菜单 + * + * @param menus 菜单列表 + * @return 路由列表 + */ + @Override + public List buildMenus(List menus) { + List routers = new LinkedList<>(); + for (SysMenu menu : menus) { + RouterVo router = new RouterVo(); + router.setHidden("1".equals(menu.getVisible())); + router.setName(getRouteName(menu)); + router.setPath(getRouterPath(menu)); + router.setComponent(getComponent(menu)); + router.setQuery(menu.getQueryParam()); + router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); + List cMenus = menu.getChildren(); + if (CollUtil.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType())) { + router.setAlwaysShow(true); + router.setRedirect("noRedirect"); + router.setChildren(buildMenus(cMenus)); + } else if (isMenuFrame(menu)) { + router.setMeta(null); + List childrenList = new ArrayList<>(); + RouterVo children = new RouterVo(); + children.setPath(menu.getPath()); + children.setComponent(menu.getComponent()); + children.setName(StringUtils.capitalize(menu.getPath())); + children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); + children.setQuery(menu.getQueryParam()); + childrenList.add(children); + router.setChildren(childrenList); + } else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) { + router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); + router.setPath("/"); + List childrenList = new ArrayList<>(); + RouterVo children = new RouterVo(); + String routerPath = innerLinkReplaceEach(menu.getPath()); + children.setPath(routerPath); + children.setComponent(UserConstants.INNER_LINK); + children.setName(StringUtils.capitalize(routerPath)); + children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath())); + childrenList.add(children); + router.setChildren(childrenList); + } + routers.add(router); + } + return routers; + } + + /** + * 获取路由名称 + * + * @param menu 菜单信息 + * @return 路由名称 + */ + public String getRouteName(SysMenu menu) { + String routerName = StringUtils.capitalize(menu.getPath()); + // 非外链并且是一级目录(类型为目录) + if (isMenuFrame(menu)) { + routerName = StringUtils.EMPTY; + } + return routerName; + } + + /** + * 是否为菜单内部跳转 + * + * @param menu 菜单信息 + * @return 结果 + */ + public boolean isMenuFrame(SysMenu menu) { + return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType()) + && menu.getIsFrame().equals(UserConstants.NO_FRAME); + } + + /** + * 获取路由地址 + * + * @param menu 菜单信息 + * @return 路由地址 + */ + public String getRouterPath(SysMenu menu) { + String routerPath = menu.getPath(); + // 内链打开外网方式 + if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) { + routerPath = innerLinkReplaceEach(routerPath); + } + // 非外链并且是一级目录(类型为目录) + if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType()) + && UserConstants.NO_FRAME.equals(menu.getIsFrame())) { + routerPath = "/" + menu.getPath(); + } + // 非外链并且是一级目录(类型为菜单) + else if (isMenuFrame(menu)) { + routerPath = "/"; + } + return routerPath; + } + + /** + * 获取组件信息 + * + * @param menu 菜单信息 + * @return 组件信息 + */ + public String getComponent(SysMenu menu) { + String component = UserConstants.LAYOUT; + if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) { + component = menu.getComponent(); + } else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) { + component = UserConstants.INNER_LINK; + } else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) { + component = UserConstants.PARENT_VIEW; + } + return component; + } + + /** + * 构建前端所需要下拉树结构 + * + * @param menus 菜单列表 + * @return 下拉树结构列表 + */ + @Override + public List> buildMenuTreeSelect(List menus) { + if (CollUtil.isEmpty(menus)) { + return CollUtil.newArrayList(); + } + return TreeBuildUtils.build(menus, (menu, tree) -> + tree.setId(menu.getId()) + .setParentId(menu.getParentId()) + .setName(menu.getMenuName()) + .setWeight(menu.getOrderNum())); + } + + /** + * 根据菜单ID查询信息 + * + * @param menuId 菜单ID + * @return 菜单信息 + */ + @Override + public SysMenuVo selectMenuById(Long menuId) { + return sysMenuData.findById(menuId).to(SysMenuVo.class); + } + + /** + * 是否存在菜单子节点 + * + * @param menuId 菜单ID + * @return 结果 + */ + @Override + public boolean hasChildByMenuId(Long menuId) { + return sysMenuData.hasChildByMenuId(menuId); + } + + /** + * 是否为内链组件 + * + * @param menu 菜单信息 + * @return 结果 + */ + public boolean isInnerLink(SysMenu menu) { + return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.ishttp(menu.getPath()); + } + + /** + * 是否为parent_view组件 + * + * @param menu 菜单信息 + * @return 结果 + */ + public boolean isParentView(SysMenu menu) { + return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType()); + } + + /** + * 查询菜单使用数量 + * + * @param menuId 菜单ID + * @return 结果 + */ + @Override + public boolean checkMenuExistRole(Long menuId) { + return iSysRoleMenuData.checkMenuExistRole(menuId); + } + + /** + * 新增保存菜单信息 + * + * @param bo 菜单信息 + */ + @Override + public void insertMenu(SysMenuBo bo) { + sysMenuData.save(bo.to(SysMenu.class)); + } + + /** + * 修改保存菜单信息 + * + * @param bo 菜单信息 + */ + @Override + public void updateMenu(SysMenuBo bo) { + sysMenuData.save(bo.to(SysMenu.class)); + } + + /** + * 删除菜单管理信息 + * + * @param menuId 菜单ID + */ + @Override + public void deleteMenuById(Long menuId) { + sysMenuData.deleteById(menuId); + } + + /** + * 校验菜单名称是否唯一 + * + * @param bo 菜单信息 + * @return 结果 + */ + @Override + public boolean checkMenuNameUnique(SysMenuBo bo) { + return sysMenuData.checkMenuNameUnique(bo.to(SysMenu.class)); + } + + @Override + public List selectMenuListByPackageId(Long packageId) { + SysTenantPackage tenantPackage = iSysTenantPackageData.findById(packageId); + List menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong); + if (CollUtil.isEmpty(menuIds)) { + return List.of(); + } + List parentIds; + if (Objects.equals(tenantPackage.getMenuCheckStrictly(),true)) { + parentIds = sysMenuData.selectParentIdByMenuIds(menuIds); + } else { + parentIds = null; + } + + return sysMenuData.findByMenuIdListAndNotParentIdList(menuIds, parentIds); + } + + /** + * 根据父节点的ID获取所有子节点 + * + * @param list 分类表 + * @param parentId 传入的父节点ID + * @return String + */ + private List getChildPerms(List list, int parentId) { + List returnList = new ArrayList<>(); + for (SysMenu t : list) { + // 一、根据传入的某个父节点ID,遍历该父节点的所有子节点 + if (t.getParentId() == parentId) { + recursionFn(list, t); + returnList.add(t); + } + } + return returnList; + } + + /** + * 递归列表 + */ + private void recursionFn(List list, SysMenu t) { + // 得到子节点列表 + List childList = StreamUtils.filter(list, n -> n.getParentId().equals(t.getId())); + t.setChildren(childList); + for (SysMenu tChild : childList) { + // 判断是否有子节点 + if (list.stream().anyMatch(n -> n.getParentId().equals(tChild.getId()))) { + recursionFn(list, tChild); + } + } + } + + /** + * 内链域名特殊字符替换 + */ + public String innerLinkReplaceEach(String path) { + return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."}, + new String[]{"", "", "", "/"}); + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysNoticeServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysNoticeServiceImpl.java new file mode 100644 index 0000000..ab7ed86 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysNoticeServiceImpl.java @@ -0,0 +1,122 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.system.ISysNoticeData; +import cc.iotkit.model.system.SysNotice; +import cc.iotkit.system.dto.bo.SysNoticeBo; +import cc.iotkit.system.dto.vo.SysNoticeVo; +import cc.iotkit.system.service.ISysNoticeService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; + +/** + * 公告 服务层实现 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Service +public class SysNoticeServiceImpl implements ISysNoticeService { + + private final ISysNoticeData sysNoticeData; + + @Override + public Paging selectPageNoticeList( PageRequest query) { + return sysNoticeData.findByConditions(query.to(SysNotice.class)).to(SysNoticeVo.class); + } + + /** + * 查询公告信息 + * + * @param noticeId 公告ID + * @return 公告信息 + */ + @Override + public SysNoticeVo selectNoticeById(Long noticeId) { + return sysNoticeData.findById(noticeId).to(SysNoticeVo.class); + } + + /** + * 查询公告列表 + * + * @param notice 公告信息 + * @return 公告集合 + */ + @Override + public List selectNoticeList(SysNoticeBo notice) { + List allByCondition = sysNoticeData.findAllByCondition(notice.to(SysNotice.class)); + return MapstructUtils.convert(allByCondition, SysNoticeVo.class); + } + + /** + * 新增公告 + * + * @param bo 公告信息 + * @return 结果 + */ + @Override + public Long insertNotice(SysNoticeBo bo) { + return sysNoticeData.save(bo.to(SysNotice.class)).getId(); + } + + /** + * 修改公告 + * + * @param bo 公告信息 + * @return 结果 + */ + @Override + public void updateNotice(SysNoticeBo bo) { + sysNoticeData.save(bo.to(SysNotice.class)); + } + + /** + * 删除公告对象 + * + * @param noticeId 公告ID + * @return 结果 + */ + @Override + public void deleteNoticeById(Long noticeId) { + sysNoticeData.deleteById(noticeId); + } + + /** + * 批量删除公告信息 + * + * @param noticeIds 需要删除的公告ID + * @return 结果 + */ + @Override + public void deleteNoticeByIds(Collection noticeIds) { + sysNoticeData.deleteByIds(noticeIds); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOperLogServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOperLogServiceImpl.java new file mode 100644 index 0000000..172a791 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOperLogServiceImpl.java @@ -0,0 +1,126 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.log.event.OperLogEvent; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.ip.AddressUtils; +import cc.iotkit.data.system.ISysOperLogData; +import cc.iotkit.model.system.SysOperLog; +import cc.iotkit.system.dto.bo.SysOperLogBo; +import cc.iotkit.system.dto.vo.SysOperLogVo; +import cc.iotkit.system.service.ISysOperLogService; +import lombok.RequiredArgsConstructor; +import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.Date; +import java.util.List; + +/** + * 操作日志 服务层处理 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Service +public class SysOperLogServiceImpl implements ISysOperLogService { + + private final ISysOperLogData sysOperLogData; + + /** + * 操作日志记录 + * + * @param operLogEvent 操作日志事件 + */ + @Async + @EventListener + public void recordOper(OperLogEvent operLogEvent) { + SysOperLogBo operLog = MapstructUtils.convert(operLogEvent, SysOperLogBo.class); + // 远程查询操作地点 + operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp())); + insertOperlog(operLog); + } + + @Override + public Paging selectPageOperLogList(PageRequest query) { + return sysOperLogData.findAll(query.to(SysOperLog.class)).to(SysOperLogVo.class); + } + + /** + * 新增操作日志 + * + * @param bo 操作日志对象 + */ + @Override + public void insertOperlog(SysOperLogBo bo) { + bo.setOperTime(new Date()); + sysOperLogData.save(bo.to(SysOperLog.class)); + } + + /** + * 查询系统操作日志集合 + * + * @param operLog 操作日志对象 + * @return 操作日志集合 + */ + @Override + public List selectOperLogList(SysOperLogBo operLog) { + return MapstructUtils.convert(sysOperLogData.findAllByCondition(operLog.to(SysOperLog.class)),SysOperLogVo.class); + } + + /** + * 批量删除系统操作日志 + * + * @param operIds 需要删除的操作日志ID + * @return 结果 + */ + @Override + public void deleteOperLogByIds(Collection operIds) { + sysOperLogData.deleteByIds(operIds); + } + + /** + * 查询操作日志详细 + * + * @param operId 操作ID + * @return 操作日志对象 + */ + @Override + public SysOperLogVo selectOperLogById(Long operId) { + return sysOperLogData.findById(operId).to(SysOperLogVo.class); + } + + /** + * 清空操作日志 + */ + @Override + public void cleanOperLog() { + sysOperLogData.deleteAll(); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssConfigServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssConfigServiceImpl.java new file mode 100644 index 0000000..8367581 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssConfigServiceImpl.java @@ -0,0 +1,183 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.CacheNames; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.oss.constant.OssConstant; +import cc.iotkit.common.redis.utils.CacheUtils; +import cc.iotkit.common.redis.utils.RedisUtils; +import cc.iotkit.common.tenant.helper.TenantHelper; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.system.ISysOssConfigData; +import cc.iotkit.model.system.SysOssConfig; +import cc.iotkit.system.dto.bo.SysOssConfigBo; +import cc.iotkit.system.dto.vo.SysOssConfigVo; +import cc.iotkit.system.service.ISysOssConfigService; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * 对象存储配置Service业务层处理 + * + * @author Lion Li + * @author 孤舟烟雨 + * @date 2021-08-13 + */ +@Slf4j +@RequiredArgsConstructor +@Service +public class SysOssConfigServiceImpl implements ISysOssConfigService { + + private final ISysOssConfigData baseData; + + @Scheduled(fixedRate = 10, timeUnit = TimeUnit.SECONDS) + private void checkOssConfig() { + String configKey = RedisUtils.getCacheObject(OssConstant.DEFAULT_CONFIG_KEY); + if(configKey==null){ + init(); + } + } + + /** + * 项目启动时,初始化参数到缓存,加载配置类 + */ + @Override + public void init() { + List list = baseData.findAll(); + List notEmptyTenantIdList = list.stream().filter(item -> ObjectUtil.isNotNull(item.getTenantId())).collect(Collectors.toList()); + Map> map = StreamUtils.groupByKey(notEmptyTenantIdList, SysOssConfig::getTenantId); + try { + for (Map.Entry> stringListEntry : map.entrySet()) { + TenantHelper.setDynamic(stringListEntry.getKey()); + for (SysOssConfig config : stringListEntry.getValue()) { + String configKey = config.getConfigKey(); + if ("0".equals(config.getStatus())) { + RedisUtils.setCacheObject(OssConstant.DEFAULT_CONFIG_KEY, configKey); + } + CacheUtils.put(CacheNames.SYS_OSS_CONFIG, config.getConfigKey(), JsonUtils.toJsonString(config)); + } + } + } finally { + TenantHelper.clearDynamic(); + } + } + + @Override + public SysOssConfigVo queryById(Long ossConfigId) { + return MapstructUtils.convert(baseData.findById(ossConfigId), SysOssConfigVo.class); + } + + @Override + public Paging queryPageList(PageRequest query) { + return baseData.findAll(query.to(SysOssConfig.class)).to(SysOssConfigVo.class); + } + + + @Override + public Boolean insertByBo(SysOssConfigBo bo) { + SysOssConfig config = MapstructUtils.convert(bo, SysOssConfig.class); + validEntityBeforeSave(config); + SysOssConfig save = baseData.save(config); + if (ObjectUtil.isNotNull(save)) { + CacheUtils.put(CacheNames.SYS_OSS_CONFIG, config.getConfigKey(), JsonUtils.toJsonString(config)); + } + return true; + } + + @Override + public Boolean updateByBo(SysOssConfigBo bo) { + SysOssConfig config = MapstructUtils.convert(bo, SysOssConfig.class); + validEntityBeforeSave(config); + SysOssConfig save = baseData.save(config); + return true; + } + + /** + * 保存前的数据校验 + */ + private void validEntityBeforeSave(SysOssConfig entity) { + if (StringUtils.isNotEmpty(entity.getConfigKey()) + && !checkConfigKeyUnique(entity)) { + throw new BizException("操作配置'" + entity.getConfigKey() + "'失败, 配置key已存在!"); + } + } + + @Override + public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { + if (Objects.equals(Boolean.TRUE, isValid) && CollUtil.containsAny(ids, OssConstant.SYSTEM_DATA_IDS)) { + throw new BizException("系统内置, 不可删除!"); + } + List list = CollUtil.newArrayList(); + for (Long configId : ids) { + SysOssConfig config = baseData.findById(configId); + list.add(config); + } + // TODO: 2021/8/13 删除数据校验 + baseData.deleteByIds(ids); + list.forEach(sysOssConfig -> + CacheUtils.evict(CacheNames.SYS_OSS_CONFIG, sysOssConfig.getConfigKey())); + return true; + } + + /** + * 判断configKey是否唯一 + */ + private boolean checkConfigKeyUnique(SysOssConfig sysOssConfig) { + long ossConfigId = ObjectUtil.isNull(sysOssConfig.getId()) ? -1L : sysOssConfig.getId(); + SysOssConfig q = new SysOssConfig(); + q.setConfigKey(sysOssConfig.getConfigKey()); + SysOssConfig info = baseData.findOneByCondition(q); + return !ObjectUtil.isNotNull(info) || info.getId() == ossConfigId; + } + + /** + * 启用禁用状态 + */ + @Override + public int updateOssConfigStatus(SysOssConfigBo bo) { + SysOssConfig old = baseData.findById(bo.getId()); + old.setStatus(bo.getStatus()); + baseData.save(old); + RedisUtils.deleteObject(OssConstant.DEFAULT_CONFIG_KEY); + return 0; + } + +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssServiceImpl.java new file mode 100644 index 0000000..954333a --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssServiceImpl.java @@ -0,0 +1,197 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.CacheNames; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.oss.core.OssClient; +import cc.iotkit.common.oss.entity.UploadResult; +import cc.iotkit.common.oss.enumd.AccessPolicyType; +import cc.iotkit.common.oss.exception.OssException; +import cc.iotkit.common.oss.factory.OssFactory; +import cc.iotkit.common.service.OssService; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.SpringUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.system.ISysOssData; +import cc.iotkit.model.system.SysOss; +import cc.iotkit.system.config.MinioUtil; +import cc.iotkit.system.dto.bo.SysOssBo; +import cc.iotkit.system.dto.vo.SysOssVo; +import cc.iotkit.system.service.ISysOssService; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.ObjectUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * 文件上传 服务层实现 + * + * @author Lion Li + */ +@Slf4j +@RequiredArgsConstructor +@Service +public class SysOssServiceImpl implements ISysOssService, OssService { + + private final ISysOssData sysOssData; + @Autowired + private MinioUtil minioUtil; + @Override + public Paging queryPageList(PageRequest query) { + return sysOssData.findAll(query.to(SysOss.class)).to(SysOssVo.class); + } + + @Override + public List listByIds(Collection ossIds) { + List list = new ArrayList<>(); + for (Long id : ossIds) { + SysOss oss = sysOssData.findById(id); + if (ObjectUtil.isNotNull(oss)) { + SysOssVo vo = MapstructUtils.convert(oss, SysOssVo.class); + list.add(this.matchingUrl(vo)); + } + } + return list; + } + + @Override + public String selectUrlByIds(String ossIds) { + List list = new ArrayList<>(); + for (Long id : StringUtils.splitTo(ossIds, Convert::toLong)) { + SysOssVo vo = SpringUtils.getAopProxy(this).getById(id); + if (ObjectUtil.isNotNull(vo)) { + list.add(this.matchingUrl(vo).getUrl()); + } + } + return String.join(StringUtils.SEPARATOR, list); + } + + @Cacheable(cacheNames = CacheNames.SYS_OSS, key = "#ossId") + @Override + public SysOssVo getById(Long ossId) { + return sysOssData.findById(ossId).to(SysOssVo.class); + } + + @Override + public void download(Long ossId) { + } + + /* @Override + public SysOssVo upload(MultipartFile file) { + String originalFileName = file.getOriginalFilename(); + if (originalFileName == null) { + throw new BizException("文件名为空,获取失败"); + } + String suffix = StringUtils.substring(originalFileName, originalFileName.lastIndexOf("."), originalFileName.length()); + OssClient storage = OssFactory.instance(); + UploadResult uploadResult; + try { + uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType()); + } catch (IOException e) { + throw new BizException(e.getMessage()); + } + // 保存文件信息 + SysOss oss = new SysOss(); + oss.setUrl(uploadResult.getUrl()); + oss.setFileSuffix(suffix); + oss.setFileName(uploadResult.getFilename()); + oss.setOriginalName(originalFileName); + oss.setService(storage.getConfigKey()); + oss = sysOssData.save(oss); + SysOssVo sysOssVo = MapstructUtils.convert(oss, SysOssVo.class); + return this.matchingUrl(sysOssVo); + }*/ + @Override + public SysOssVo upload(MultipartFile file) { + String originalFileName = file.getOriginalFilename(); + // minioUtil = new MinioUtil(); + if (originalFileName == null) { + throw new BizException("文件名为空,获取失败"); + } + String url = minioUtil.upload(file); + String suffix = StringUtils.substring(originalFileName, originalFileName.lastIndexOf("."), originalFileName.length()); + /* OssClient storage = OssFactory.instance(); + UploadResult uploadResult; + try { + uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType()); + } catch (IOException e) { + throw new BizException(e.getMessage()); + }*/ + // 保存文件信息 + SysOss oss = new SysOss(); + oss.setUrl(url); + oss.setFileSuffix(suffix); + oss.setFileName(file.getName()); + oss.setOriginalName(originalFileName); + oss.setService("oss-embed"); + oss = sysOssData.save(oss); + SysOssVo sysOssVo = MapstructUtils.convert(oss, SysOssVo.class); + return sysOssVo; + } + @Override + public void deleteWithValidByIds(Collection ids, Boolean isValid) { + if (Boolean.TRUE.equals(isValid)) { + // 做一些业务上的校验,判断是否需要校验 + } + List list = sysOssData.findByIds(ids); + for (SysOss sysOss : list) { + OssClient storage = OssFactory.instance(sysOss.getService()); + storage.delete(sysOss.getUrl()); + } + sysOssData.deleteByIds(ids); + } + + /** + * 匹配Url + * + * @param oss OSS对象 + * @return oss 匹配Url的OSS对象 + */ + private SysOssVo matchingUrl(SysOssVo oss) { + try { + OssClient storage = OssFactory.instance(oss.getService()); + // 仅修改桶类型为 private 的URL,临时URL时长为120s + if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) { + oss.setUrl(storage.getPrivateUrl(oss.getFileName(), 120)); + } + return oss; + } catch (OssException e) { + log.error("matchingUrl error", e); + return new SysOssVo(); + } + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysPermissionServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysPermissionServiceImpl.java new file mode 100644 index 0000000..6aea4e4 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysPermissionServiceImpl.java @@ -0,0 +1,84 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.constant.TenantConstants; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.system.service.ISysMenuService; +import cc.iotkit.system.service.ISysPermissionService; +import cc.iotkit.system.service.ISysRoleService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.HashSet; +import java.util.Set; + +/** + * 用户权限处理 + * + * @author ruoyi + */ +@RequiredArgsConstructor +@Service +public class SysPermissionServiceImpl implements ISysPermissionService { + + private final ISysRoleService roleService; + private final ISysMenuService menuService; + + /** + * 获取角色数据权限 + * + * @param userId 用户id + * @return 角色权限信息 + */ + @Override + public Set getRolePermission(Long userId) { + Set roles = new HashSet<>(); + // 管理员拥有所有权限 + if (LoginHelper.isSuperAdmin(userId)) { + roles.add(TenantConstants.SUPER_ADMIN_ROLE_KEY); + } else { + roles.addAll(roleService.selectRolePermissionByUserId(userId)); + } + return roles; + } + + /** + * 获取菜单数据权限 + * + * @param userId 用户id + * @return 菜单权限信息 + */ + @Override + public Set getMenuPermission(Long userId) { + Set perms = new HashSet<>(); + // 管理员拥有所有权限 + if (LoginHelper.isSuperAdmin(userId)) { + perms.add("*:*:*"); + } else { + perms.addAll(menuService.selectMenuPermsByUserId(userId)); + } + return perms; + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysPostServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysPostServiceImpl.java new file mode 100644 index 0000000..4842c43 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysPostServiceImpl.java @@ -0,0 +1,175 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.system.ISysPostData; +import cc.iotkit.model.system.SysPost; +import cc.iotkit.system.dto.bo.SysPostBo; +import cc.iotkit.system.dto.vo.SysPostVo; +import cc.iotkit.system.service.ISysPostService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; + +/** + * 岗位信息 服务层处理 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Service +public class SysPostServiceImpl implements ISysPostService { + + private final ISysPostData sysPostData; + + @Override + public Paging selectPagePostList(PageRequest query) { + return sysPostData.findAll(query.to(SysPost.class)).to(SysPostVo.class); + } + + /** + * 查询岗位信息集合 + * + * @param post 岗位信息 + * @return 岗位信息集合 + */ + @Override + public List selectPostList(SysPostBo post) { + return MapstructUtils.convert(sysPostData.selectPostList(post.to(SysPost.class)),SysPostVo.class); + } + + /** + * 查询所有岗位 + * + * @return 岗位列表 + */ + @Override + public List selectPostAll() { + return MapstructUtils.convert(sysPostData.findAll(), SysPostVo.class); + } + + /** + * 通过岗位ID查询岗位信息 + * + * @param postId 岗位ID + * @return 角色对象信息 + */ + @Override + public SysPostVo selectPostById(Long postId) { + return sysPostData.findById(postId).to(SysPostVo.class); + } + + /** + * 根据用户ID获取岗位选择框列表 + * + * @param userId 用户ID + * @return 选中岗位ID列表 + */ + @Override + public List selectPostListByUserId(Long userId) { + return sysPostData.selectPostListByUserId(userId); + } + + /** + * 校验岗位名称是否唯一 + * + * @param post 岗位信息 + * @return 结果 + */ + @Override + public boolean checkPostNameUnique(SysPostBo post) { + return sysPostData.checkPostNameUnique(post.to(SysPost.class)); + } + + /** + * 校验岗位编码是否唯一 + * + * @param post 岗位信息 + * @return 结果 + */ + @Override + public boolean checkPostCodeUnique(SysPostBo post) { + return sysPostData.checkPostCodeUnique(post.to(SysPost.class)); + } + + /** + * 通过岗位ID查询岗位使用数量 + * + * @param postId 岗位ID + * @return 结果 + */ + @Override + public long countUserPostById(Long postId) { + return 0; + } + + /** + * 删除岗位信息 + * + * @param postId 岗位ID + * @return 结果 + */ + @Override + public void deletePostById(Long postId) { + sysPostData.deleteById(postId); + } + + /** + * 批量删除岗位信息 + * + * @param postIds 需要删除的岗位ID + * @return 结果 + */ + @Override + public void deletePostByIds(Collection postIds) { + sysPostData.deleteByIds(postIds); + } + + /** + * 新增保存岗位信息 + * + * @param bo 岗位信息 + * @return 结果 + */ + @Override + public void insertPost(SysPostBo bo) { + sysPostData.save(bo.to(SysPost.class)); + } + + /** + * 修改保存岗位信息 + * + * @param bo 岗位信息 + * @return 结果 + */ + @Override + public void updatePost(SysPostBo bo) { + sysPostData.save(bo.to(SysPost.class)); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysRoleServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysRoleServiceImpl.java new file mode 100644 index 0000000..161ab1a --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysRoleServiceImpl.java @@ -0,0 +1,447 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.model.LoginUser; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.system.ISysRoleData; +import cc.iotkit.data.system.ISysRoleDeptData; +import cc.iotkit.data.system.ISysRoleMenuData; +import cc.iotkit.data.system.ISysUserRoleData; +import cc.iotkit.model.system.*; +import cc.iotkit.system.dto.bo.SysRoleBo; +import cc.iotkit.system.dto.vo.SysRoleVo; +import cc.iotkit.system.service.ISysRoleService; +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +/** + * 角色 业务层处理 + * + * @author Lion Li + */ +@Service +@RequiredArgsConstructor +public class SysRoleServiceImpl implements ISysRoleService { + + private final ISysRoleData iSysRoleData; + private final ISysRoleMenuData iSysRoleMenuData; + private final ISysUserRoleData iSysUserRoleData; + private final ISysRoleDeptData iSysRoleDeptData; + + @Override + public Paging selectPageRoleList(PageRequest query) { + return iSysRoleData.findAll(query.to(SysRole.class)).to(SysRoleVo.class); + } + + /** + * 根据条件分页查询角色数据 + * + * @param role 角色信息 + * @return 角色数据集合信息 + */ + @Override + public List selectRoleList(SysRoleBo role) { + List sysRoles = getSysRoles(role); + return MapstructUtils.convert(sysRoles, SysRoleVo.class); + } + + private List getSysRoles(SysRoleBo role) { + return iSysRoleData.selectRoleList(MapstructUtils.convert(role, SysRole.class)); + } + + + /** + * 根据用户ID查询角色 + * + * @param userId 用户ID + * @return 角色列表 + */ + @Override + public List selectRolesByUserId(Long userId) { + List sysRoles = iSysRoleData.selectRolePermissionByUserId(userId); + List roles = getSysRoles(new SysRoleBo()); + for (SysRole role : roles) { + for (SysRole sysRole : sysRoles) { + if (role.getId().longValue() == sysRole.getId().longValue()) { + role.setFlag(true); + break; + } + } + } + return MapstructUtils.convert(roles, SysRoleVo.class); + } + + /** + * 根据用户ID查询权限 + * + * @param userId 用户ID + * @return 权限列表 + */ + @Override + public Set selectRolePermissionByUserId(Long userId) { + List perms = iSysRoleData.selectRolePermissionByUserId(userId); + Set permsSet = new HashSet<>(); + for (SysRole perm : perms) { + if (ObjectUtil.isNotNull(perm)) { + permsSet.addAll(StringUtils.splitList(perm.getRoleKey().trim())); + } + } + return permsSet; + } + + /** + * 查询所有角色 + * + * @return 角色列表 + */ + @Override + public List selectRoleAll() { + return this.selectRoleList(new SysRoleBo()); + } + + /** + * 根据用户ID获取角色选择框列表 + * + * @param userId 用户ID + * @return 选中角色ID列表 + */ + @Override + public List selectRoleListByUserId(Long userId) { + return iSysRoleData.selectRoleListByUserId(userId); + } + + /** + * 通过角色ID查询角色 + * + * @param roleId 角色ID + * @return 角色对象信息 + */ + @Override + public SysRoleVo selectRoleById(Long roleId) { + return iSysRoleData.findById(roleId).to(SysRoleVo.class); + } + + /** + * 校验角色名称是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + @Override + public boolean checkRoleNameUnique(SysRoleBo role) { + return iSysRoleData.checkRoleNameUnique(MapstructUtils.convert(role, SysRole.class)); + } + + /** + * 校验角色权限是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + @Override + public boolean checkRoleKeyUnique(SysRoleBo role) { + return iSysRoleData.checkRoleKeyUnique(MapstructUtils.convert(role, SysRole.class)); + } + + /** + * 校验角色是否允许操作 + * + * @param roleId 角色ID + */ + @Override + public void checkRoleAllowed(Long roleId) { + if (ObjectUtil.isNotNull(roleId) && LoginHelper.isSuperAdmin(roleId)) { + throw new BizException("不允许操作超级管理员角色"); + } + } + + /** + * 校验角色是否有数据权限 + * + * @param roleId 角色id + */ + @Override + public void checkRoleDataScope(Long roleId) { + if (ObjectUtil.isNull(roleId)) { + return; + } + if (LoginHelper.isSuperAdmin()) { + return; + } + List roles = this.selectRoleList(new SysRoleBo(roleId)); + if (CollUtil.isEmpty(roles)) { + throw new BizException("没有权限访问角色数据!"); + } + + } + + /** + * 通过角色ID查询角色使用数量 + * + * @param roleId 角色ID + * @return 结果 + */ + @Override + public long countUserRoleByRoleId(Long roleId) { + return iSysUserRoleData.countUserRoleByRoleId(roleId); + } + + /** + * 新增保存角色信息 + * + * @param bo 角色信息 + * @return 结果 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public int insertRole(SysRoleBo bo) { + SysRole role = iSysRoleData.save(bo.to(SysRole.class)); + //TODO 后面再晚上插入菜单的,目前不知道逻辑 + //return insertRoleMenu(bo); + + return 1; + } + + /** + * 修改保存角色信息 + * + * @param bo 角色信息 + * @return 结果 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public int updateRole(SysRoleBo bo) { + // 修改角色信息 + iSysRoleData.updateById(bo.to(SysRole.class)); + // 删除角色与菜单关联 + iSysRoleMenuData.deleteByRoleId(List.of(bo.getId())); + return insertRoleMenu(bo); + } + + /** + * 修改角色状态 + * + * @param roleId 角色ID + * @param status 角色状态 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void updateRoleStatus(Long roleId, String status) { + SysRole sysRole = iSysRoleData.findById(roleId); + sysRole.setStatus(status); + iSysRoleData.updateById(sysRole); + } + + /** + * 修改数据权限信息 + * + * @param bo 角色信息 + * @return 结果 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public int authDataScope(SysRoleBo bo) { + // 修改角色信息 + iSysRoleData.updateById(MapstructUtils.convert(bo, SysRole.class)); + // 删除角色与部门关联 + iSysRoleDeptData.deleteByRoleId(List.of(bo.getId())); + // 新增角色和部门信息(数据权限) + return insertRoleDept(bo); + + } + + /** + * 新增角色菜单信息 + * + * @param role 角色对象 + */ + private int insertRoleMenu(SysRoleBo role) { + long rows = 1; + // 新增用户与角色管理 + List list = new ArrayList<>(); + for (Long menuId : role.getMenuIds()) { + SysRoleMenu rm = new SysRoleMenu(); + rm.setRoleId(role.getId()); + rm.setMenuId(menuId); + list.add(rm); + } + if (!list.isEmpty()) { + rows = iSysRoleMenuData.insertBatch(list); + } + return Integer.parseInt(rows + ""); + } + + /** + * 新增角色部门信息(数据权限) + * + * @param role 角色对象 + */ + private int insertRoleDept(SysRoleBo role) { + long rows = 1; + // 新增角色与部门(数据权限)管理 + List list = new ArrayList<>(); + for (Long deptId : role.getDeptIds()) { + SysRoleDept rd = new SysRoleDept(); + rd.setRoleId(role.getId()); + rd.setDeptId(deptId); + list.add(rd); + } + if (!list.isEmpty()) { + rows = iSysRoleDeptData.insertBatch(list); + } + return Integer.parseInt(rows + ""); + } + + /** + * 通过角色ID删除角色 + * + * @param roleId 角色ID + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteRoleById(Long roleId) { + // 删除角色与菜单关联 + iSysRoleMenuData.deleteByRoleId(List.of(roleId)); + // 删除角色与部门关联 + iSysRoleDeptData.deleteByRoleId(List.of(roleId)); + iSysRoleData.deleteById(roleId); + } + + /** + * 批量删除角色信息 + * + * @param roleIds 需要删除的角色ID + * @return 结果 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteRoleByIds(Collection roleIds) { + for (Long roleId : roleIds) { + checkRoleAllowed(roleId); + checkRoleDataScope(roleId); + SysRole role = iSysRoleData.findById(roleId); + if (countUserRoleByRoleId(roleId) > 0) { + throw new BizException(String.format("%1$s已分配,不能删除", role.getRoleName())); + } + } + + // 删除角色与菜单关联 + iSysRoleMenuData.deleteByRoleId(roleIds); + // 删除角色与部门关联 + iSysRoleDeptData.deleteByRoleId(roleIds); + iSysRoleData.deleteByIds(roleIds); + } + + /** + * 取消授权用户角色 + * + * @param userRole 用户和角色关联信息 + * @return 结果 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAuthUser(SysUserRole userRole) { + long rows = iSysUserRoleData.delete(userRole.getRoleId(), List.of(userRole.getUserId())); + if (rows > 0) { + cleanOnlineUserByRole(userRole.getRoleId()); + } + } + + /** + * 批量取消授权用户角色 + * + * @param roleId 角色ID + * @param userIds 需要取消授权的用户数据ID + * @return 结果 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAuthUsers(Long roleId, Long[] userIds) { + long rows = iSysUserRoleData.delete(roleId, Arrays.asList(userIds)); + if (rows > 0) { + cleanOnlineUserByRole(roleId); + } + } + + /** + * 批量选择授权用户角色 + * + * @param roleId 角色ID + * @param userIds 需要授权的用户数据ID + * @return 结果 + */ + @Override + public void insertAuthUsers(Long roleId, Long[] userIds) { + // 新增用户与角色管理 + long rows = 1; + List list = StreamUtils.toList(List.of(userIds), userId -> { + SysUserRole ur = new SysUserRole(); + ur.setUserId(userId); + ur.setRoleId(roleId); + return ur; + }); + if (CollUtil.isNotEmpty(list)) { + rows = iSysUserRoleData.insertBatch(list); + } + if (rows > 0) { + cleanOnlineUserByRole(roleId); + } + } + + @Override + public void cleanOnlineUserByRole(Long roleId) { + List keys = StpUtil.searchTokenValue("", 0, -1, false); + if (CollUtil.isEmpty(keys)) { + return; + } + // 角色关联的在线用户量过大会导致redis阻塞卡顿 谨慎操作 + keys.parallelStream().forEach(key -> { + String token = StringUtils.substringAfterLast(key, ":"); + // 如果已经过期则跳过 + if (StpUtil.stpLogic.getTokenActivityTimeoutByToken(token) < -1) { + return; + } + LoginUser loginUser = LoginHelper.getLoginUser(token); + if(Objects.isNull(loginUser)||CollUtil.isEmpty(loginUser.getRoles())){ + return; + } + if (loginUser.getRoles().stream().anyMatch(r -> r.getId().equals(roleId))) { + StpUtil.logoutByTokenValue(token); + } + }); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysTenantPackageServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysTenantPackageServiceImpl.java new file mode 100644 index 0000000..158cf17 --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysTenantPackageServiceImpl.java @@ -0,0 +1,123 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.data.system.ISysTenantPackageData; +import cc.iotkit.model.system.SysTenantPackage; +import cc.iotkit.system.dto.bo.SysTenantPackageBo; +import cc.iotkit.system.dto.vo.SysTenantPackageVo; +import cc.iotkit.system.service.ISysTenantPackageService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Collection; +import java.util.List; + +/** + * 租户套餐Service业务层处理 + * + * @author Michelle.Chung + */ +@RequiredArgsConstructor +@Service +public class SysTenantPackageServiceImpl implements ISysTenantPackageService { + + private final ISysTenantPackageData sysTenantPackageData; + + /** + * 查询租户套餐 + */ + @Override + public SysTenantPackageVo queryById(Long packageId) { + return sysTenantPackageData.findById(packageId).to(SysTenantPackageVo.class); + } + + /** + * 查询租户套餐列表 + */ + @Override + public Paging queryPageList( PageRequest query) { + return sysTenantPackageData.findAll(query.to(SysTenantPackage.class)).to(SysTenantPackageVo.class); + } + + @Override + public List selectList() { + List all = sysTenantPackageData.findAll(); + return MapstructUtils.convert(all,SysTenantPackageVo.class); + } + + /** + * 查询租户套餐列表 + */ + @Override + public List queryList(SysTenantPackageBo bo) { + List all = sysTenantPackageData.findAllByCondition(bo.to(SysTenantPackage.class)); + return MapstructUtils.convert(all,SysTenantPackageVo.class); + } + + /** + * 新增租户套餐 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean insertByBo(SysTenantPackageBo bo) { + sysTenantPackageData.save(bo.to(SysTenantPackage.class)); + return true; + } + + /** + * 修改租户套餐 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean updateByBo(SysTenantPackageBo bo) { + sysTenantPackageData.save(bo.to(SysTenantPackage.class)); + return true; + } + + /** + * 修改套餐状态 + * + * @param bo 套餐信息 + * @return 结果 + */ + @Override + public void updatePackageStatus(SysTenantPackageBo bo) { + sysTenantPackageData.save(bo.to(SysTenantPackage.class)); + } + + /** + * 批量删除租户套餐 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { + sysTenantPackageData.deleteByIds(ids); + return true; + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysTenantServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysTenantServiceImpl.java new file mode 100644 index 0000000..0c7edbc --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysTenantServiceImpl.java @@ -0,0 +1,294 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.CacheNames; +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.constant.TenantConstants; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.enums.UserType; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.data.system.*; +import cc.iotkit.model.system.*; +import cc.iotkit.system.dto.bo.SysTenantBo; +import cc.iotkit.system.dto.vo.SysTenantVo; +import cc.iotkit.system.service.ISysTenantService; +import cn.dev33.satoken.secure.BCrypt; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.ObjectUtil; +import com.github.yitter.idgen.YitIdHelper; +import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 租户Service业务层处理 + * + * @author Michelle.Chung + */ +@RequiredArgsConstructor +@Service +public class SysTenantServiceImpl implements ISysTenantService { + + private final ISysTenantData sysTenantData; + + private final ISysTenantPackageData sysTenantPackageData; + + private final ISysUserData sysUserData; + + private final ISysRoleData sysRoleData; + + private final ISysRoleMenuData sysRoleMenuData; + + private final ISysDeptData sysDeptData; + + private final ISysRoleDeptData sysRoleDeptData; + + private final ISysUserRoleData sysUserRoleData; + + private final ISysDictTypeData sysDictTypeData; + + private final ISysDictData sysDictData; + + private final ISysConfigData sysConfigData; + + @Override + public SysTenantVo queryById(Long id) { + return sysTenantData.findById(id).to(SysTenantVo.class); + } + + /** + * 基于租户ID查询租户 + */ + @Cacheable(cacheNames = CacheNames.SYS_TENANT, key = "#tenantId") + @Override + public SysTenantVo queryByTenantId(Long tenantId) { + SysTenant sysTenant = new SysTenant(); + sysTenant.setTenantId(tenantId); + SysTenant tenant = sysTenantData.findOneByCondition(sysTenant); + return MapstructUtils.convert(tenant,SysTenantVo.class); + } + + @Override + public Paging queryPageList(PageRequest query) { + return sysTenantData.findAll(query.to(SysTenant.class)).to(SysTenantVo.class); + } + + @Override + public List queryList(SysTenantBo bo) { + return MapstructUtils.convert(sysTenantData.findAllByCondition(bo.to(SysTenant.class)),SysTenantVo.class); + } + + @Override + public void insertByBo(SysTenantBo bo) { + long tenantId = YitIdHelper.nextId(); + bo.setId(tenantId); + bo.setTenantId(tenantId); + SysTenant sysTenant=sysTenantData.save(bo.to(SysTenant.class)); + // 根据套餐创建角色 + Long roleId = createTenantRole(sysTenant.getTenantId(), bo.getPackageId()); + + // 创建部门: 公司名是部门名称 + SysDept dept = new SysDept(); + dept.setTenantId(sysTenant.getTenantId()); + dept.setDeptName(bo.getCompanyName()); + dept.setParentId(0L); + dept.setAncestors("0"); + dept.setPhone(bo.getContactPhone()); + dept.setStatus(TenantConstants.NORMAL); + SysDept retDept =sysDeptData.save(dept); + Long deptId = retDept.getId(); + + // 角色和部门关联表 + SysRoleDept roleDept = new SysRoleDept(); + roleDept.setRoleId(roleId); + roleDept.setDeptId(deptId); + roleDept.setTenantId(tenantId); + sysRoleDeptData.save(roleDept); + + // 创建系统用户 + SysUser user = new SysUser(); + user.setTenantId(sysTenant.getTenantId()); + user.setUserName(bo.getUsername()); + user.setNickName(bo.getUsername()); + user.setPassword(BCrypt.hashpw(bo.getPassword())); + user.setDeptId(deptId); + user.setUserType(UserType.SYS_USER.getUserType()); + user.setStatus(TenantConstants.NORMAL); + user.setRemark(TenantConstants.TENANT_ADMIN_ROLE_NAME); + user.setPhonenumber(bo.getContactPhone()); + SysUser retUser=sysUserData.save(user); + + //新增系统用户后,默认当前用户为部门的负责人 + SysDept updateDept =sysDeptData.findById(retDept.getId()); + updateDept.setLeader(retUser.getUserName()); + sysDeptData.save(updateDept); + + // 用户和角色关联表 + SysUserRole userRole = new SysUserRole(); + userRole.setUserId(retUser.getId()); + userRole.setRoleId(roleId); + userRole.setTenantId(tenantId); + sysUserRoleData.save(userRole); + + Long defaultTenantId = TenantConstants.DEFAULT_TENANT_ID; + SysDictType querySysDictType=new SysDictType(); + querySysDictType.setTenantId(defaultTenantId); + List dictTypeList = sysDictTypeData.findByConditions(querySysDictType); + SysDictData querySysDictData=new SysDictData(); + querySysDictData.setTenantId(defaultTenantId); + List dictDataList = sysDictData.findByConditions(querySysDictData); + for (SysDictType dictType : dictTypeList) { + dictType.setId(null); + dictType.setTenantId(sysTenant.getTenantId()); + } + for (SysDictData dictData : dictDataList) { + dictData.setId(null); + dictData.setTenantId(sysTenant.getTenantId()); + } + + sysDictTypeData.batchSave(dictTypeList); + sysDictData.batchSave(dictDataList); + SysConfig querySysConfig=new SysConfig(); + querySysConfig.setTenantId(defaultTenantId); + List sysConfigList = sysConfigData.findAllByCondition(querySysConfig); + + for (SysConfig config : sysConfigList) { + config.setId(null); + config.setTenantId(sysTenant.getTenantId()); + } + sysConfigData.batchSave(sysConfigList); + } + + /** + * 根据租户菜单创建租户角色 + * + * @param tenantId 租户编号 + * @param packageId 租户套餐id + * @return 角色id + */ + private Long createTenantRole(Long tenantId, Long packageId) { + // 获取租户套餐 + SysTenantPackage tenantPackage = sysTenantPackageData.findById(packageId); + if (ObjectUtil.isNull(tenantPackage)) { + throw new BizException(ErrCode.PACKAGE_NOT_FOUND); + } + // 获取套餐菜单id + List menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong); + + // 创建角色 + SysRole role = new SysRole(); + role.setTenantId(tenantId); + role.setRoleName(TenantConstants.TENANT_ADMIN_ROLE_NAME); + role.setRoleKey(TenantConstants.TENANT_ADMIN_ROLE_KEY); + role.setRoleSort(1); + role.setRemark(TenantConstants.TENANT_ADMIN_ROLE_NAME); + role.setStatus(TenantConstants.NORMAL); + SysRole retRole=sysRoleData.save(role); + Long roleId = retRole.getId(); + + // 创建角色菜单 + List roleMenus = new ArrayList<>(menuIds.size()); + menuIds.forEach(menuId -> { + SysRoleMenu roleMenu = new SysRoleMenu(); + roleMenu.setRoleId(roleId); + roleMenu.setMenuId(menuId); + roleMenus.add(roleMenu); + }); + sysRoleMenuData.insertBatch(roleMenus); + return roleId; + } + + @Override + public void updateByBo(SysTenantBo bo) { + sysTenantData.save(bo.to(SysTenant.class)); + } + + @Override + public int updateTenantStatus(SysTenantBo bo) { + SysTenant tenantDataById = sysTenantData.findById(bo.getId()); + tenantDataById.setStatus(bo.getStatus()); + sysTenantData.save(tenantDataById); + return 0; + } + + @Override + public void checkTenantAllowed(Long tenantId) { + if (ObjectUtil.isNotNull(tenantId) && TenantConstants.DEFAULT_TENANT_ID.equals(tenantId)) { + throw new BizException(ErrCode.UNAUTHORIZED_TENANT); + } + } + + @Override + public void deleteById(Long id) { + Long tenantId=LoginHelper.getTenantId(); + //删除角色 + SysRole querySysRole=new SysRole(); + querySysRole.setTenantId(tenantId); + List roles =sysRoleData.selectRoleList(querySysRole); + sysRoleData.deleteByIds(roles.stream().map(SysRole::getId).collect(Collectors.toList())); + //删除部门 + //删除系统用户 + //删除字典类型 + //删除字典数据 + //删除系统配置 + sysTenantData.deleteById(id); + } + + @Override + public boolean checkCompanyNameUnique(SysTenantBo bo) { + return sysTenantData.checkCompanyNameUnique(bo.to(SysTenant.class)); + } + + @Override + public boolean checkAccountBalance(Long tenantId) { + SysTenantVo tenant = this.queryByTenantId(tenantId); + // 如果余额为-1代表不限制 + if (tenant.getAccountCount() == -1) { + return true; + } + Long userNumber = sysUserData.count(); + // 如果余额大于0代表还有可用名额 + return tenant.getAccountCount() - userNumber > 0; + } + + @Override + public boolean checkExpireTime(Long tenantId) { + return false; + } + + @Override + public Boolean syncTenantPackage(Long tenantId, String packageId) { + return false; + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysUserServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysUserServiceImpl.java new file mode 100644 index 0000000..5a01c4d --- /dev/null +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysUserServiceImpl.java @@ -0,0 +1,327 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.system.service.impl; + +import cc.iotkit.common.api.PageRequest; +import cc.iotkit.common.api.Paging; +import cc.iotkit.common.constant.UserConstants; +import cc.iotkit.common.enums.ErrCode; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.service.UserService; +import cc.iotkit.common.utils.MapstructUtils; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.data.system.*; +import cc.iotkit.model.system.SysRole; +import cc.iotkit.model.system.SysUser; +import cc.iotkit.model.system.SysUserPost; +import cc.iotkit.model.system.SysUserRole; +import cc.iotkit.system.dto.bo.SysUserBo; +import cc.iotkit.system.dto.vo.SysUserVo; +import cc.iotkit.system.service.ISysUserService; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ObjectUtil; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Collection; +import java.util.List; + +/** + * 用户 业务层处理 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Service +public class SysUserServiceImpl implements ISysUserService, UserService { + + @Autowired + private ISysUserData sysUserData; + + @Autowired + private ISysDeptData sysDeptData; + + @Autowired + private ISysRoleData sysRoleData; + + @Autowired + private ISysPostData sysPostData; + + @Autowired + private ISysUserRoleData sysUserRoleData; + + @Autowired + private ISysUserPostData sysUserPostData; + // @Autowired + // private ISysUserAreaData iSysUserAreaData; + + @Override + public String selectUserNameById(Long userId) { + return null; + } + + @Override + public Paging selectPageUserList(PageRequest query) { + PageRequest condition = query.to(SysUser.class); + if(ObjectUtil.isNotNull(query.getData().getParams()) && !"".equals(query.getData().getParams().get("endTime"))) { + condition.getData().setParams(query.getData().getParams()); + }// 手动补全Map字段 + return sysUserData.findAll(condition).to(SysUserVo.class); + } + + @Override + public List selectUserList(SysUserBo user) { + return MapstructUtils.convert(sysUserData.findAllByCondition(user.to(SysUser.class)), SysUserVo.class); + } + + @Override + public Paging selectAllocatedList(PageRequest query) { + return sysUserData.selectAllocatedList(query.to(SysUser.class)).to(SysUserVo.class); + } + + @Override + public Paging selectUnallocatedList(PageRequest query) { + return sysUserData.selectUnallocatedList(query.to(SysUser.class)).to(SysUserVo.class); + } + + @Override + public SysUserVo selectUserByUserName(String userName) { + return MapstructUtils.convert(sysUserData.selectUserByUserName(userName), SysUserVo.class); + } + + @Override + public SysUserVo selectUserByPhonenumber(String phonenumber) { + return MapstructUtils.convert(sysUserData.findByPhonenumber(phonenumber), SysUserVo.class); + + } + + @Override + public SysUserVo selectUserById(Long userId) { + return MapstructUtils.convert(sysUserData.findById(userId), SysUserVo.class); + } + + @Override + public String selectUserRoleGroup(String userName) { + return sysUserData.selectUserRoleGroup(userName); + } + + @Override + public String selectUserPostGroup(String userName) { + return sysUserData.selectUserPostGroup(userName); + } + + @Override + public boolean checkUserNameUnique(SysUserBo user) { + return sysUserData.checkUserNameUnique(user.to(SysUser.class)); + } + + @Override + public boolean checkPhoneUnique(SysUserBo user) { + return sysUserData.checkPhoneUnique(user.to(SysUser.class)); + } + + @Override + public boolean checkEmailUnique(SysUserBo user) { + return sysUserData.checkEmailUnique(user.to(SysUser.class)); + } + + @Override + public void checkUserAllowed(SysUserBo user) { + if (ObjectUtil.isNotNull(user.getId()) && user.isSuperAdmin()) { + throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION); + } + } + + @Override + public void checkUserDataScope(Long userId) { + if (ObjectUtil.isNull(userId)) { + return; + } + if (LoginHelper.isSuperAdmin()) { + return; + } + if (ObjectUtil.isNull(sysUserData.findById(userId))) { + throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION); + } + } + + @Override + public int insertUser(SysUserBo user) { + // 新增用户信息 + SysUser newUser = sysUserData.save(user.to(SysUser.class)); + user.setId(newUser.getId()); + // 新增用户岗位关联 + insertUserPost(user, false); + // 新增用户与角色管理 + insertUserRole(user, false); + return newUser != null ? 1 : 0; + } + + /** + * 新增用户角色信息 + * + * @param user 用户对象 + * @param clear 清除已存在的关联数据 + */ + private void insertUserRole(SysUserBo user, boolean clear) { + this.insertUserRole(user.getId(), user.getRoleIds(), clear); + } + + /** + * 新增用户岗位信息 + * + * @param user 用户对象 + * @param clear 清除已存在的关联数据 + */ + private void insertUserPost(SysUserBo user, boolean clear) { + List posts = user.getPostIds(); + if (CollectionUtil.isNotEmpty(posts)) { + if (clear) { + // 删除用户与岗位关联 + sysUserPostData.deleteByUserId(user.getId()); + } + // 新增用户与岗位管理 + List list = StreamUtils.toList(posts, postId -> { + SysUserPost up = new SysUserPost(); + up.setUserId(user.getId()); + up.setPostId(postId); + return up; + }); + sysUserPostData.batchSave(list); + } + } + + /** + * 新增用户角色信息 + * + * @param userId 用户ID + * @param roleIds 角色组 + * @param clear 清除已存在的关联数据 + */ + private void insertUserRole(Long userId, List roleIds, boolean clear) { + if (CollectionUtil.isNotEmpty(roleIds)) { + // 判断是否具有此角色的操作权限 + List roles = sysRoleData.selectRoleList(new SysRole()); + if (CollUtil.isEmpty(roles)) { + throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION); + } + List roleList = StreamUtils.toList(roles, SysRole::getId); + if (!LoginHelper.isSuperAdmin(userId)) { + roleList.remove(UserConstants.SUPER_ADMIN_ID); + } + List canDoRoleList = StreamUtils.filter(roleIds, roleList::contains); + if (CollUtil.isEmpty(canDoRoleList)) { + throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION); + } + if (clear) { + // 删除用户与角色关联 + sysUserRoleData.deleteByUserId(userId); + } + // 新增用户与角色管理 + List list = StreamUtils.toList(canDoRoleList, roleId -> { + SysUserRole ur = new SysUserRole(); + ur.setUserId(userId); + ur.setRoleId(roleId); + return ur; + }); + sysUserRoleData.batchSave(list); + } + } + + @Override + public boolean registerUser(SysUserBo user, Long tenantId) { + return false; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public int updateUser(SysUserBo user) { + // 新增用户与角色管理 + insertUserRole(user, true); + // 新增用户与岗位管理 + insertUserPost(user, true); + SysUser sysUser = MapstructUtils.convert(user, SysUser.class); + // 防止错误更新后导致的数据误删除 + SysUser ret = sysUserData.save(sysUser); + if (ret == null) { + throw new BizException("修改用户" + user.getUserName() + "信息失败"); + } + return 0; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void insertUserAuth(Long userId, List roleIds) { + insertUserRole(userId, roleIds, true); + } + + @Override + public int updateUserStatus(Long userId, String status) { + SysUser user = sysUserData.findById(userId); + user.setStatus(status); + return sysUserData.save(user) != null ? 1 : 0; + } + + @Override + public int updateUserProfile(SysUserBo user) { + SysUser oldUser = sysUserData.findById(user.getId()); + if (ObjectUtil.isNotNull(user.getNickName())) { + oldUser.setNickName(user.getNickName()); + } + oldUser.setPhonenumber(user.getPhonenumber()); + oldUser.setEmail(user.getEmail()); + oldUser.setSex(user.getSex()); + return sysUserData.save(oldUser) != null ? 1 : 0; + } + + @Override + public boolean updateUserAvatar(Long userId, Long avatar) { + SysUser oldUser = sysUserData.findById(userId); + oldUser.setAvatar(avatar); + sysUserData.save(oldUser); + return Boolean.TRUE; + } + + @Override + public int resetUserPwd(Long userId, String password) { + SysUser user = sysUserData.findById(userId); + user.setPassword(password); + return sysUserData.save(user) != null ? 1 : 0; + } + + @Override + public int deleteUserById(Long userId) { + return 0; + } + + @Override + public void deleteUserByIds(Collection userIds) { + sysUserData.deleteByIds(userIds); + } +} diff --git a/iot-module/pom.xml b/iot-module/pom.xml new file mode 100644 index 0000000..d1cc351 --- /dev/null +++ b/iot-module/pom.xml @@ -0,0 +1,26 @@ + + + + iotkit-parent + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-module + pom + + iot-system + iot-rule-engine + iot-message-notify + + iot-openapi + iot-plugin + iot-manager + iot-modbus + iot-generator + + + diff --git a/iot-starter/pom.xml b/iot-starter/pom.xml new file mode 100644 index 0000000..4eca99a --- /dev/null +++ b/iot-starter/pom.xml @@ -0,0 +1,233 @@ + + + + iotkit-parent + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-starter + jar + + + + io.vertx + vertx-core + + + + io.vertx + vertx-web-client + + + + jakarta.xml.bind + jakarta.xml.bind-api + 4.0.1 + + + + cc.iotkit + iot-common-tenant + + + + cc.iotkit + iot-rule-engine + + + + + cc.iotkit + iot-message-event-bus + + + + + + + + + + cc.iotkit + iot-plugin-main + + + + cc.iotkit + iot-manager + + + + cc.iotkit + iot-system + + + + cc.iotkit + iot-openapi + + + + cc.iotkit + iot-data-serviceImpl-rdb + + + + cc.iotkit + iot-modbus + + + + + cc.iotkit + iot-temporal-serviceImpl-es + + + + + cc.iotkit + iot-generator + + + + + + + + + + + + + + + + + cc.iotkit + iot-oss-embed + + + + + + org.springframework.boot + spring-boot-starter-web + + + com.mysql + mysql-connector-j + 8.0.33 + + + org.springframework.boot + spring-boot-starter-logging + + + org.apache.logging.log4j + log4j-to-slf4j + + + + + + com.gitee.starblues + spring-brick + + + + org.apache.logging.log4j + log4j-core + + + + org.projectlombok + lombok + true + + + + it.ozimov + embedded-redis + + + slf4j-simple + org.slf4j + + + + + + org.elasticsearch + elasticsearch + + + + org.elasticsearch.plugin + transport-netty4-client + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + ${java.version} + ${java.version} + UTF-8 + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + repackage + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + false + + + cc.iotkit.Application + + + + + ${project.parent.basedir}/iot-starter/src/main/resources/assemblies/standalone-package.xml + + + + + + make-assembly + package + + single + + + + + + + + + diff --git a/iot-starter/readme.md b/iot-starter/readme.md new file mode 100644 index 0000000..634ddf7 --- /dev/null +++ b/iot-starter/readme.md @@ -0,0 +1,5 @@ +程序入口模块,引用集成了其它所有模块的功能,并提供web api接口和实现。 + +### 2023-05-05 添加swagger支持 + 访问地址:http://localhost:8086/swagger-ui/index.html + 访问地址:http://localhost:8086/doc.html \ No newline at end of file diff --git a/iot-starter/src/main/bin/clear_data.sh b/iot-starter/src/main/bin/clear_data.sh new file mode 100644 index 0000000..20a579e --- /dev/null +++ b/iot-starter/src/main/bin/clear_data.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# linux系统 清除数据脚本 + +# bin目录绝对路径 +BIN_DIR=`pwd` + +# 返回到上一级项目根目录路径 +cd .. +# 打印项目根目录绝对路径 + +# `pwd` 执行系统命令并获得结果 +DEPLOY_DIR=`pwd` + +# 清除.init文件,清除es数据库,h2数据库 +# 清除后,项目启动时数控库会重新初始化 + +rm -rf .init $DEPLOY_DIR/data/elasticsearch $DEPLOY_DIR/data/iotkit.mv.db + + +# TODO:根据数据库类型,清除数据库 +# mysql \ No newline at end of file diff --git a/iot-starter/src/main/bin/start.bat b/iot-starter/src/main/bin/start.bat new file mode 100644 index 0000000..922f335 --- /dev/null +++ b/iot-starter/src/main/bin/start.bat @@ -0,0 +1,38 @@ +echo off + +set APP_NAME=${project.build.finalName}.jar +set LOG_IMPL_FILE=log4j2.xml +set LOGGING_CONFIG= +if exist ../config/%LOG_IMPL_FILE% ( + set LOGGING_CONFIG=-Dlogging.config=../config/%LOGGING_CONFIG% +) +set CONFIG= -Dlogging.path=../log %LOGGING_CONFIG% -Dspring.config.location=../config/ + +set DEBUG_OPTS= +if ""%1"" == ""debug"" ( + set DEBUG_OPTS= -Xloggc:../log/gc.log -verbose:gc -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../log + goto debug +) + +set JMX_OPTS= +if ""%1"" == ""jmx"" ( + set JMX_OPTS= -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9888 -Dcom.sun.management.jmxremote.ssl=FALSE -Dcom.sun.management.jmxremote.authenticate=FALSE + goto jmx +) + +echo "Starting the %APP_NAME%" +java -Xms512m -Xmx512m -server %DEBUG_OPTS% %JMX_OPTS% %CONFIG% -jar ../lib/%APP_NAME% +echo "java -Xms512m -Xmx512m -server %DEBUG_OPTS% %JMX_OPTS% %CONFIG% -jar ../lib/%APP_NAME%" +goto end + +:debug +echo "debug" +java -Xms512m -Xmx512m -server %DEBUG_OPTS% %CONFIG% -jar ../lib/%APP_NAME% +goto end + +:jmx +java -Xms512m -Xmx512m -server %JMX_OPTS% %CONFIG% -jar ../lib/%APP_NAME% +goto end + +:end +pause \ No newline at end of file diff --git a/iot-starter/src/main/bin/start.sh b/iot-starter/src/main/bin/start.sh new file mode 100644 index 0000000..297ef11 --- /dev/null +++ b/iot-starter/src/main/bin/start.sh @@ -0,0 +1,133 @@ +#!/bin/bash + +# 项目名称 +SERVER_NAME="${project.artifactId}" + +# jar名称 +JAR_NAME="${project.build.finalName}.jar" + +# 进入bin目录 +cd `dirname $0` +# bin目录绝对路径 +BIN_DIR=`pwd` +# 返回到上一级项目根目录路径 +cd .. +# 打印项目根目录绝对路径 +# `pwd` 执行系统命令并获得结果 +DEPLOY_DIR=`pwd` + +# 如果没有指定外部配置文件,则使用默认的配置文件 +while getopts ":c:j:" opt +do + case $opt in + j) + # 如果没有指定外部配置文件,则使用默认的配置文件 + echo "java命令行参数:$OPTARG" + JAVA_OPTS=$OPTARG + ;; + c) + echo "配置文件路径$OPTARG" + USER_ASSIGN_CONFIG=$OPTARG + ;; + ?) + echo "未知参数" + exit 1;; + esac +done + + +# 如果指定的是目录,spring则会读取目录中的所有配置文件 +if [ -n "$USER_ASSIGN_CONFIG" ]; then + CONF_DIR=$USER_ASSIGN_CONFIG +else + CONF_DIR=$DEPLOY_DIR/config +fi + +# SERVER_PORT=`sed '/server.port/!d;s/.*=//' config/application.properties | tr -d '\r'` +# 获取应用的端口号 +SERVER_PORT=`sed -nr '/port: [0-9]+/ s/.*port: +([0-9]+).*/\1/p' $CONF_DIR/application.yml|head -1` + +PIDS=`ps -f | grep java | grep "$CONF_DIR" |awk '{print $2}'` +if [ "$1" = "status" ]; then + if [ -n "$PIDS" ]; then + echo "The $SERVER_NAME is running...!" + echo "PID: $PIDS" + exit 0 + else + echo "The $SERVER_NAME is stopped" + exit 0 + fi +fi + +if [ -n "$PIDS" ]; then + echo "ERROR: The $SERVER_NAME already started!" + echo "PID: $PIDS" + exit 1 +fi + +if [ -n "$SERVER_PORT" ]; then + SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l` + if [ $SERVER_PORT_COUNT -gt 0 ]; then + echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!" + exit 1 + fi +fi + +# 项目日志输出绝对路径 +LOGS_DIR=$DEPLOY_DIR/log +# 如果logs文件夹不存在,则创建文件夹 +if [ ! -d $LOGS_DIR ]; then + mkdir $LOGS_DIR +fi +STDOUT_FILE=$LOGS_DIR/catalina.log + +# JVM Configuration +JAVA_OPTS+=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true " +JAVA_DEBUG_OPTS="" +if [ "$1" = "debug" ]; then + JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n " +fi + +JAVA_JMX_OPTS="" +if [ "$1" = "jmx" ]; then + JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false " +fi + +JAVA_MEM_OPTS="" +BITS=`java -version 2>&1 | grep -i 64-bit` +if [ -n "$BITS" ]; then + JAVA_MEM_OPTS=" -server -Xmx512m -Xms512m -Xmn256m -Xss256k" +else + JAVA_MEM_OPTS=" -server -Xms512m -Xmx512m" +fi + +# 加载外部log4j2文件的配置 +LOG_IMPL_FILE=log4j2.xml +LOGGING_CONFIG="" +if [ -f "$CONF_DIR/$LOG_IMPL_FILE" ] +then + LOGGING_CONFIG="-Dlogging.config=$CONF_DIR/$LOG_IMPL_FILE" +fi +CONFIG_FILES=" -Dlogging.path=$LOGS_DIR $LOGGING_CONFIG -Dspring.config.location=$CONF_DIR/ " +echo -e "Starting the $SERVER_NAME ..." +nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS $CONFIG_FILES -jar $DEPLOY_DIR/lib/$JAR_NAME > $STDOUT_FILE 2>&1 & + +COUNT=0 +while [ $COUNT -lt 1 ]; do + echo -e ".\c" + sleep 1 + if [ -n "$SERVER_PORT" ]; then + COUNT=`netstat -an | grep $SERVER_PORT | wc -l` + else + COUNT=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l` + fi + if [ $COUNT -gt 0 ]; then + break + fi +done + + +echo "OK!" +PIDS=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}'` +echo "PID: $PIDS" +echo "STDOUT: $STDOUT_FILE" \ No newline at end of file diff --git a/iot-starter/src/main/bin/stop.sh b/iot-starter/src/main/bin/stop.sh new file mode 100644 index 0000000..28a5e2e --- /dev/null +++ b/iot-starter/src/main/bin/stop.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# 项目名称 +APPLICATION="${project.artifactId}" + +# 项目启动jar包名称 +APPLICATION_JAR="${project.build.finalName}.jar" + +# 通过项目名称查找到PI,然后kill -9 pid +PID=$(ps -ef | grep "${APPLICATION_JAR}" | grep -v grep | awk '{ print $2 }') +if [[ -z "$PID" ]] +then + echo ${APPLICATION} is already stopped +else + echo kill ${PID} + kill -9 ${PID} + echo ${APPLICATION} stopped successfully +fi \ No newline at end of file diff --git a/iot-starter/src/main/java/cc/iotkit/Application.java b/iot-starter/src/main/java/cc/iotkit/Application.java new file mode 100644 index 0000000..791906c --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/Application.java @@ -0,0 +1,63 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit; + +import com.gitee.starblues.loader.DevelopmentMode; +import com.gitee.starblues.loader.launcher.SpringBootstrap; +import com.gitee.starblues.loader.launcher.SpringMainBootstrap; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +@Slf4j +@SpringBootApplication +@ComponentScan(excludeFilters = { + @ComponentScan.Filter(type = FilterType.REGEX, pattern = ".*s3mock.*Controller") +}) +@EnableTransactionManagement +@EnableWebMvc +@EnableJpaAuditing +@EnableScheduling +public class Application implements SpringBootstrap { + + public static void main(String[] args) { + SpringMainBootstrap.launch(Application.class, args); + log.info("server start success!"); + } + + @Override + public void run(String[] args) { + SpringApplication.run(Application.class, args); + } + + @Override + public String developmentMode() { + return DevelopmentMode.ISOLATION; + } +} diff --git a/iot-starter/src/main/java/cc/iotkit/config/EmbeddedElasticSearchConfig.java b/iot-starter/src/main/java/cc/iotkit/config/EmbeddedElasticSearchConfig.java new file mode 100644 index 0000000..a5bb452 --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/config/EmbeddedElasticSearchConfig.java @@ -0,0 +1,91 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.config; + +import lombok.SneakyThrows; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.node.InternalSettingsPreparer; +import org.elasticsearch.node.Node; +import org.elasticsearch.transport.Netty4Plugin; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.Collections; + +@Component +public class EmbeddedElasticSearchConfig { + + @Value("${spring.elasticsearch.embedded.enabled:false}") + private boolean embeddedElasticsearchEnabled; + + @Value("${spring.elasticsearch.embedded.port:9200}") + private Integer esPort; + + @PostConstruct + private void start(){ + if (embeddedElasticsearchEnabled) { + startEmbeddedElasticSearch(esPort); + } + + } + + @SneakyThrows + public void startEmbeddedElasticSearch(Integer port) { + EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(new ConfigProperty(), port); + embeddedElasticSearch.start(); + } + + public class ConfigProperty { + + public Settings.Builder applySetting(Settings.Builder settings) { + String dataPath = "./data/elasticsearch"; + String homePath = "./"; + int port = esPort; + String host = "0.0.0.0"; + return settings.put("network.host", host) + .put("http.port", port) + .put("path.data", dataPath) + .put("path.home", homePath); + } + + } + + public static class EmbeddedElasticSearch extends Node { + + @SneakyThrows + public EmbeddedElasticSearch(ConfigProperty properties, Integer port) { + super(InternalSettingsPreparer.prepareEnvironment( + properties.applySetting( + Settings.builder() + .put("node.name", "test") + .put("discovery.type", "single-node") + .put("transport.type", Netty4Plugin.NETTY_TRANSPORT_NAME) + .put("http.type", Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME) + .put("network.host", "0.0.0.0") + .put("http.port", port) + ).build(), Collections.emptyMap(), null, () -> "default"), + Collections.singleton(Netty4Plugin.class), false); + } + } +} diff --git a/iot-starter/src/main/java/cc/iotkit/config/EmbeddedRedisConfig.java b/iot-starter/src/main/java/cc/iotkit/config/EmbeddedRedisConfig.java new file mode 100644 index 0000000..417b342 --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/config/EmbeddedRedisConfig.java @@ -0,0 +1,72 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import redis.embedded.RedisServer; + +import javax.annotation.PostConstruct; + +@Slf4j +@Component +public class EmbeddedRedisConfig { + + @Value("${spring.redis.embedded.enabled:false}") + private boolean embeddedRedisEnabled; + @Value("${spring.redis.port:6378}") + private Integer redisPort; + + @PostConstruct + private void start(){ + if (embeddedRedisEnabled) { + startEmbeddedRedisServer(redisPort); + } + + } + public static void startEmbeddedRedisServer(Integer port) { + RedisServer redisServer; + String os = System.getProperty("os.name").toLowerCase(); + if (os.contains("windows")) { + redisServer = RedisServer.builder().setting("maxheap 200m") + .port(port) + .setting("bind localhost") + .build(); + } else { + redisServer = RedisServer.builder() + .port(port) + .setting("bind localhost") + .build(); + } + try { + redisServer.start(); + } catch (Exception e) { + if (e.getMessage().contains("Address already in use")) { + throw new RuntimeException("redis端口被占用,请先停止本地的redis服务"); + } + log.error("start redis server failed", e); + } + } + +} diff --git a/iot-starter/src/main/java/cc/iotkit/config/SchedulerConfig.java b/iot-starter/src/main/java/cc/iotkit/config/SchedulerConfig.java new file mode 100644 index 0000000..812a1d0 --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/config/SchedulerConfig.java @@ -0,0 +1,44 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.config; + + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; + +@Configuration +@EnableScheduling +public class SchedulerConfig { + + @Bean + public ThreadPoolTaskScheduler threadPoolTaskScheduler() { + ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); + scheduler.setPoolSize(10); // 设置线程池大小 + scheduler.setThreadNamePrefix("spring-scheduled-"); // 设置线程名前缀 + scheduler.initialize(); + return scheduler; + } + +} \ No newline at end of file diff --git a/iot-starter/src/main/java/cc/iotkit/web/controller/AuthController.java b/iot-starter/src/main/java/cc/iotkit/web/controller/AuthController.java new file mode 100644 index 0000000..6a9de56 --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/web/controller/AuthController.java @@ -0,0 +1,161 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.web.controller; + +import cc.iotkit.common.api.Request; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.StreamUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.system.dto.LoginBody; +import cc.iotkit.system.dto.RegisterBody; +import cc.iotkit.system.dto.bo.SysTenantBo; +import cc.iotkit.system.dto.bo.XcxLoginBo; +import cc.iotkit.system.dto.vo.SysTenantVo; +import cc.iotkit.system.service.ISysConfigService; +import cc.iotkit.system.service.ISysTenantService; +import cc.iotkit.web.domain.vo.LoginTenantVo; +import cc.iotkit.web.domain.vo.LoginVo; +import cc.iotkit.web.domain.vo.TenantListVo; +import cc.iotkit.web.service.SysLoginService; +import cc.iotkit.web.service.SysRegisterService; +import cn.dev33.satoken.annotation.SaIgnore; +import cn.hutool.core.collection.CollUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.net.URL; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 认证 + * + * @author Lion Li + */ +@Api(tags = "认证") +@SaIgnore +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/auth") +public class AuthController { + + private final SysLoginService loginService; + private final SysRegisterService registerService; + private final ISysConfigService configService; + private final ISysTenantService tenantService; + + /** + * 登录方法 + * + * @param body 登录信息 + * @return 结果 + */ + @ApiOperation("登录") + @PostMapping("/login") + public LoginVo login(@Validated @RequestBody Request body) { + LoginBody loginBody = body.getData(); + LoginVo loginVo = new LoginVo(); + // 生成令牌 + String token = loginService.login( + loginBody.getTenantId(), + loginBody.getUsername(), loginBody.getPassword(), + loginBody.getCode(), loginBody.getUuid()); + loginVo.setToken(token); + return loginVo; + } + + /** + * 小程序登录(示例) + * + * @param body 小程序appid,code + * @return 结果 + */ + @ApiOperation("小程序登录") + @PostMapping("/xcxLogin") + public LoginVo xcxLogin(@Validated @RequestBody Request body) { + LoginVo loginVo = new LoginVo(); + XcxLoginBo data = body.getData(); + // 生成令牌 + String token = loginService.xcxLogin(data.getAppId(), data.getCode()); + loginVo.setToken(token); + return loginVo; + } + + + /** + * 退出登录 + */ + @ApiOperation("退出登录") + @PostMapping("/logout") + public void logout() { + loginService.logout(); + + } + + /** + * 用户注册 + */ + @ApiOperation("用户注册") + @PostMapping("/register") + public void register(@Validated @RequestBody RegisterBody user) { + if (!configService.selectRegisterEnabled(user.getTenantId())) { + throw new BizException("当前租户不允许注册"); + } + registerService.register(user); + } + + /** + * 登录页面租户下拉框 + * + * @return 租户列表 + */ + @ApiOperation("登录页面租户下拉框") + @PostMapping("/tenant/list") + public LoginTenantVo tenantList(HttpServletRequest request) throws Exception { + List tenantList = tenantService.queryList(new SysTenantBo()); + List voList = tenantList.stream().map(t -> TenantListVo.builder() + .tenantId(t.getTenantId()) + .companyName(t.getCompanyName()) + .domain(t.getDomain()) + .build()).collect(Collectors.toList()); + // 获取域名 + String host = new URL(request.getRequestURL().toString()).getHost(); + // 根据域名进行筛选 + List list = StreamUtils.filter(voList, vo -> StringUtils.equals(vo.getDomain(), host)); + // 返回对象 + LoginTenantVo vo = new LoginTenantVo(); + vo.setVoList(CollUtil.isNotEmpty(list) ? list : voList); + vo.setTenantEnabled(true); + return vo; + } + +} diff --git a/iot-starter/src/main/java/cc/iotkit/web/controller/CaptchaController.java b/iot-starter/src/main/java/cc/iotkit/web/controller/CaptchaController.java new file mode 100644 index 0000000..464ec14 --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/web/controller/CaptchaController.java @@ -0,0 +1,102 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.web.controller; + +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.constant.GlobalConstants; +import cc.iotkit.common.redis.utils.RedisUtils; +import cc.iotkit.common.utils.ReflectUtils; +import cc.iotkit.common.utils.SpringUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.web.config.properties.CaptchaProperties; +import cc.iotkit.common.web.enums.CaptchaType; +import cc.iotkit.web.domain.vo.CaptchaVo; +import cn.dev33.satoken.annotation.SaIgnore; +import cn.hutool.captcha.AbstractCaptcha; +import cn.hutool.captcha.generator.CodeGenerator; +import cn.hutool.core.util.IdUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.expression.Expression; +import org.springframework.expression.ExpressionParser; +import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.Duration; + +/** + * 验证码操作处理 + * + * @author Lion Li + */ +@SaIgnore +@Slf4j +@Validated +@RequiredArgsConstructor +@RestController +@Api(tags = "验证码") +public class CaptchaController { + + private final CaptchaProperties captchaProperties; + + /** + * 生成验证码 + */ + @ApiOperation(value = "生成验证码") + @PostMapping("/code") + public CaptchaVo getCode() { + CaptchaVo captchaVo = new CaptchaVo(); + boolean captchaEnabled = captchaProperties.getEnable(); + if (!captchaEnabled) { + captchaVo.setCaptchaEnabled(false); + return captchaVo; + } + // 保存验证码信息 + String uuid = IdUtil.simpleUUID(); + String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + uuid; + // 生成验证码 + CaptchaType captchaType = captchaProperties.getType(); + boolean isMath = CaptchaType.MATH == captchaType; + Integer length = isMath ? captchaProperties.getNumberLength() : captchaProperties.getCharLength(); + CodeGenerator codeGenerator = ReflectUtils.newInstance(captchaType.getClazz(), length); + AbstractCaptcha captcha = SpringUtils.getBean(captchaProperties.getCategory().getClazz()); + captcha.setGenerator(codeGenerator); + captcha.createCode(); + String code = captcha.getCode(); + if (isMath) { + ExpressionParser parser = new SpelExpressionParser(); + Expression exp = parser.parseExpression(StringUtils.remove(code, "=")); + code = exp.getValue(String.class); + } + RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION)); + captchaVo.setUuid(uuid); + captchaVo.setImg(captcha.getImageBase64()); + return captchaVo; + } + +} diff --git a/iot-starter/src/main/java/cc/iotkit/web/domain/vo/CaptchaVo.java b/iot-starter/src/main/java/cc/iotkit/web/domain/vo/CaptchaVo.java new file mode 100644 index 0000000..1061a27 --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/web/domain/vo/CaptchaVo.java @@ -0,0 +1,48 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.web.domain.vo; + +import lombok.Data; + +/** + * 验证码信息 + * + * @author Michelle.Chung + */ +@Data +public class CaptchaVo { + + /** + * 是否开启验证码 + */ + private Boolean captchaEnabled = true; + + private String uuid; + + /** + * 验证码图片 + */ + private String img; + +} diff --git a/iot-starter/src/main/java/cc/iotkit/web/domain/vo/LoginTenantVo.java b/iot-starter/src/main/java/cc/iotkit/web/domain/vo/LoginTenantVo.java new file mode 100644 index 0000000..4f72372 --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/web/domain/vo/LoginTenantVo.java @@ -0,0 +1,48 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.web.domain.vo; + +import lombok.Data; + +import java.util.List; + +/** + * 登录租户对象 + * + * @author Michelle.Chung + */ +@Data +public class LoginTenantVo { + + /** + * 租户开关 + */ + private Boolean tenantEnabled; + + /** + * 租户对象列表 + */ + private List voList; + +} diff --git a/iot-starter/src/main/java/cc/iotkit/web/domain/vo/LoginVo.java b/iot-starter/src/main/java/cc/iotkit/web/domain/vo/LoginVo.java new file mode 100644 index 0000000..a0bd645 --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/web/domain/vo/LoginVo.java @@ -0,0 +1,38 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.web.domain.vo; + +import lombok.Data; + +/** + * 登录验证信息 + * + * @author Michelle.Chung + */ +@Data +public class LoginVo { + + private String token; + +} diff --git a/iot-starter/src/main/java/cc/iotkit/web/domain/vo/TenantListVo.java b/iot-starter/src/main/java/cc/iotkit/web/domain/vo/TenantListVo.java new file mode 100644 index 0000000..4b4ba19 --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/web/domain/vo/TenantListVo.java @@ -0,0 +1,52 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.web.domain.vo; + +import cc.iotkit.system.dto.vo.SysTenantVo; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + + +/** + * 租户列表 + * + * @author Lion Li + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@AutoMapper(target = SysTenantVo.class) +public class TenantListVo { + + private Long tenantId; + + private String companyName; + + private String domain; + +} diff --git a/iot-starter/src/main/java/cc/iotkit/web/service/SysLoginService.java b/iot-starter/src/main/java/cc/iotkit/web/service/SysLoginService.java new file mode 100644 index 0000000..9e6d8de --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/web/service/SysLoginService.java @@ -0,0 +1,458 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.web.service; + +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.constant.GlobalConstants; +import cc.iotkit.common.constant.TenantConstants; +import cc.iotkit.common.enums.*; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.exception.user.UserException; +import cc.iotkit.common.log.event.LogininforEvent; +import cc.iotkit.common.model.LoginUser; +import cc.iotkit.common.model.RoleDTO; +import cc.iotkit.common.redis.utils.RedisUtils; +import cc.iotkit.common.satoken.utils.AuthUtil; +import cc.iotkit.common.satoken.utils.LoginHelper; +import cc.iotkit.common.tenant.helper.TenantHelper; +import cc.iotkit.common.utils.*; +import cc.iotkit.common.web.config.properties.CaptchaProperties; +import cc.iotkit.common.web.utils.ServletUtils; +import cc.iotkit.data.manager.IUserInfoData; +import cc.iotkit.data.system.ISysUserData; +import cc.iotkit.manager.dto.bo.space.HomeBo; +import cc.iotkit.manager.service.IHomeService; +import cc.iotkit.manager.service.ISpaceService; +import cc.iotkit.model.UserInfo; +import cc.iotkit.model.space.Home; +import cc.iotkit.model.space.Space; +import cc.iotkit.model.system.SysUser; +import cc.iotkit.system.dto.bo.XcxLoginUserBo; +import cc.iotkit.system.dto.vo.SysAppVo; +import cc.iotkit.system.dto.vo.SysTenantVo; +import cc.iotkit.system.dto.vo.SysUserVo; +import cc.iotkit.system.service.ISysAppService; +import cc.iotkit.system.service.ISysPermissionService; +import cc.iotkit.system.service.ISysTenantService; +import cn.dev33.satoken.exception.NotLoginException; +import cn.dev33.satoken.secure.BCrypt; +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.time.Duration; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.function.Supplier; + +/** + * 登录校验方法 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Slf4j +@Service +public class SysLoginService { + + private final ISysUserData userData; + private final IUserInfoData userInfoData; + private final CaptchaProperties captchaProperties; + private final ISysPermissionService permissionService; + private final ISysTenantService tenantService; + private final ISysAppService appService; + private final ISpaceService spaceService; + private final IHomeService homeService; + + @Value("${user.password.maxRetryCount}") + private Integer maxRetryCount; + + @Value("${user.password.lockTime}") + private Integer lockTime; + + private String authUrl="https://api.weixin.qq.com/sns/jscode2session"; + + /** + * 登录验证 + * + * @param username 用户名 + * @param password 密码 + * @param code 验证码 + * @param uuid 唯一标识 + * @return 结果 + */ + public String login(Long tenantId, String username, String password, String code, String uuid) { + boolean captchaEnabled = captchaProperties.getEnable(); + // 验证码开关 + if (captchaEnabled) { + validateCaptcha(tenantId, username, code, uuid); + } + // 校验租户 + checkTenant(tenantId); + + //未登录前临时设置租户id + LoginHelper.setTenantId(tenantId); + SysUserVo user = loadUserByUsername(tenantId, username); + user.setTenantId(tenantId); + checkLogin(LoginType.PASSWORD, tenantId, username, () -> !BCrypt.checkpw(password, user.getPassword())); + // 此处可根据登录用户的数据不同 自行创建 loginUser + LoginUser loginUser = buildLoginUser(user); + // 生成token + LoginHelper.loginByDevice(loginUser, DeviceType.PC); + + recordLoginInfo(loginUser.getTenantId(), username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); + recordLoginInfo(user.getId()); + return StpUtil.getTokenValue(); + } + + public String smsLogin(Long tenantId, String phonenumber, String smsCode) { + // 校验租户 + checkTenant(tenantId); + // 通过手机号查找用户 + SysUserVo user = loadUserByPhonenumber(tenantId, phonenumber); + + checkLogin(LoginType.SMS, tenantId, user.getUserName(), () -> !validateSmsCode(tenantId, phonenumber, smsCode)); + // 此处可根据登录用户的数据不同 自行创建 loginUser + LoginUser loginUser = buildLoginUser(user); + // 生成token + LoginHelper.loginByDevice(loginUser, DeviceType.APP); + + recordLoginInfo(loginUser.getTenantId(), user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); + recordLoginInfo(user.getId()); + return StpUtil.getTokenValue(); + } + + public String emailLogin(Long tenantId, String email, String emailCode) { + // 校验租户 + checkTenant(tenantId); + // 通过手机号查找用户 + SysUserVo user = loadUserByEmail(tenantId, email); + + checkLogin(LoginType.EMAIL, tenantId, user.getUserName(), () -> !validateEmailCode(tenantId, email, emailCode)); + // 此处可根据登录用户的数据不同 自行创建 loginUser + LoginUser loginUser = buildLoginUser(user); + // 生成token + LoginHelper.loginByDevice(loginUser, DeviceType.APP); + + recordLoginInfo(loginUser.getTenantId(), user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); + recordLoginInfo(user.getId()); + return StpUtil.getTokenValue(); + } + + + public String xcxLogin(String appId,String xcxCode) { + // xcxCode 为 小程序调用 wx.login 授权后获取 + SysAppVo sysApp=appService.queryByAppId(appId); + if(sysApp==null){ + throw new BizException("该应用未授权注册"); + } + String openid = WeChatUtil.getOpenId(appId,sysApp.getAppSecret(),xcxCode); + UserInfo user = null; + LoginHelper.setTenantId(sysApp.getTenantId()); + try { + user = loadUserByOpenid(openid,sysApp.getTenantId()); + } catch (Exception e) { + e.printStackTrace(); + } + // 校验租户 +// checkTenant(user.getTenantId()); + + // 此处可根据登录用户的数据不同 自行创建 loginUser + XcxLoginUserBo loginUser = new XcxLoginUserBo(); + loginUser.setUserId(user.getId()); + loginUser.setUsername(user.getNickName()); + loginUser.setUserType(UserType.APP_USER.getUserType()); + loginUser.setOpenid(openid); + loginUser.setTenantId(sysApp.getTenantId()); + // 生成token + LoginHelper.loginByDevice(loginUser, DeviceType.XCX); + + recordLoginInfo(loginUser.getTenantId(), user.getNickName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); +// recordLoginInfo(user.getId()); + return StpUtil.getTokenValue(); + } + + /** + * 退出登录 + */ + public void logout() { + try { + LoginUser loginUser = LoginHelper.getLoginUser(); + if(loginUser==null){ + return; + } + if (LoginHelper.isSuperAdmin()) { + // 超级管理员 登出清除动态租户 + TenantHelper.clearDynamic(); + } + StpUtil.logout(); + recordLoginInfo(loginUser.getTenantId(), loginUser.getUsername(), Constants.LOGOUT, MessageUtils.message("user.logout.success")); + } catch (NotLoginException ignored) { + } + } + + /** + * 记录登录信息 + * + * @param tenantId 租户ID + * @param username 用户名 + * @param status 状态 + * @param message 消息内容 + */ + private void recordLoginInfo(Long tenantId, String username, String status, String message) { + LogininforEvent logininforEvent = new LogininforEvent(); + logininforEvent.setTenantId(tenantId); + logininforEvent.setUsername(username); + logininforEvent.setStatus(status); + logininforEvent.setMessage(message); + logininforEvent.setRequest(ServletUtils.getRequest()); + SpringUtils.context().publishEvent(logininforEvent); + } + + /** + * 校验短信验证码 + */ + private boolean validateSmsCode(Long tenantId, String phonenumber, String smsCode) { + String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + phonenumber); + if (StringUtils.isBlank(code)) { + recordLoginInfo(tenantId, phonenumber, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")); + throw new BizException(MessageUtils.message("user.jcaptcha.expire")); + } + return code.equals(smsCode); + } + + /** + * 校验邮箱验证码 + */ + private boolean validateEmailCode(Long tenantId, String email, String emailCode) { + String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + email); + if (StringUtils.isBlank(code)) { + recordLoginInfo(tenantId, email, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")); + throw new BizException("验证码过期"); + } + return code.equals(emailCode); + } + + /** + * 校验验证码 + * + * @param username 用户名 + * @param code 验证码 + * @param uuid 唯一标识 + */ + public void validateCaptcha(Long tenantId, String username, String code, String uuid) { + String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, ""); + String captcha = RedisUtils.getCacheObject(verifyKey); + RedisUtils.deleteObject(verifyKey); + if (captcha == null) { + recordLoginInfo(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")); + throw new BizException("验证码过期"); + } + if (!code.equalsIgnoreCase(captcha)) { + recordLoginInfo(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")); + throw new BizException("验证码错误"); + } + } + + private SysUserVo loadUserByUsername(Long tenantId, String username) { + SysUser user = userData.selectTenantUserByUserName(username,tenantId); + + if (ObjectUtil.isNull(user)) { + log.info("登录用户:{} 不存在.", username); + throw new UserException("登录用户不存在"); + } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { + log.info("登录用户:{} 已被停用.", username); + throw new UserException("用户被停用"); + } + if (TenantHelper.isEnable()) { + return user.to(SysUserVo.class); + } + SysUser sysUser = userData.selectUserByUserName(username); + return MapstructUtils.convert(sysUser, SysUserVo.class); + } + + private SysUserVo loadUserByPhonenumber(Long tenantId, String phonenumber) { + SysUser query = new SysUser(); + query.setPhonenumber(phonenumber); + + SysUser user = userData.findOneByCondition(query); + if (ObjectUtil.isNull(user)) { + log.info("登录用户:{} 不存在.", phonenumber); + throw new UserException("登录用户不存在"); + } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { + log.info("登录用户:{} 已被停用.", phonenumber); + throw new UserException("用户被停用"); + } + + SysUser sysUser = userData.selectTenantUserByPhonenumber(phonenumber, tenantId); + return MapstructUtils.convert(sysUser, SysUserVo.class); + } + + private SysUserVo loadUserByEmail(Long tenantId, String email) { + SysUser query = new SysUser(); + query.setEmail(email); + SysUser user = userData.findOneByCondition(query); + + if (ObjectUtil.isNull(user)) { + log.info("登录用户:{} 不存在.", email); + throw new UserException("用户不存在"); + } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { + log.info("登录用户:{} 已被停用.", email); + throw new UserException("用户被停用"); + } + SysUser sysUser = userData.selectUserByEmail(email); + return MapstructUtils.convert(sysUser, SysUserVo.class); + + } + + private UserInfo loadUserByOpenid(String openid,Long tenantId) throws Exception { + // 使用 openid 查询绑定用户 如未绑定用户 则根据业务自行处理 例如 创建默认用户 + UserInfo user=userInfoData.findByUid(openid); + if (ObjectUtil.isNull(user)) { + log.info("小程序用户:{} 不存在,开始初始化", openid); + user=new UserInfo(); + user.setType(UserInfo.USER_TYPE_CLIENT); + user.setUid(openid); + user.setRoles(Collections.singletonList(Constants.ROLE_CLIENT)); + user.setNickName("微信用户"); + user.setSecret(AuthUtil.enCryptPwd(Constants.PWD_CLIENT_USER)); + user.setTenantId(tenantId); + user = userInfoData.save(user); + //添加默认家庭 + Home home = homeService.save(HomeBo.builder() + .name("我的家庭") + .userId(user.getId()) + .address("") + .deviceNum(0) + .spaceNum(3) + .current(true) + .build()); + + //添加默认房间 + for (String name : new String[]{"客厅", "卧室", "厨房"}) { + spaceService.save(Space.builder() + .homeId(home.getId()) + .name(name) + .deviceNum(0) + .build()); + } + } + return user; + } + + /** + * 构建登录用户 + */ + private LoginUser buildLoginUser(SysUserVo user) { + LoginUser loginUser = new LoginUser(); + loginUser.setTenantId(user.getTenantId()); + loginUser.setUserId(user.getId()); + loginUser.setDeptId(user.getDeptId()); + loginUser.setUsername(user.getUserName()); + loginUser.setUserType(user.getUserType()); + loginUser.setMenuPermission(permissionService.getMenuPermission(user.getId())); + loginUser.setRolePermission(permissionService.getRolePermission(user.getId())); + loginUser.setDeptName(ObjectUtil.isNull(user.getDept()) ? "" : user.getDept().getDeptName()); + List roles = BeanUtil.copyToList(user.getRoles(), RoleDTO.class); + loginUser.setRoles(roles); + return loginUser; + } + + /** + * 记录登录信息 + * + * @param userId 用户ID + */ + public void recordLoginInfo(Long userId) { + SysUser sysUser = userData.findById(userId); + sysUser.setLoginIp(ServletUtils.getClientIP()); + sysUser.setLoginDate(DateUtils.getNowDate()); + sysUser.setUpdateBy(userId); + userData.save(sysUser); + } + + /** + * 登录校验 + */ + private void checkLogin(LoginType loginType, Long tenantId, String username, Supplier supplier) { + String errorKey = GlobalConstants.PWD_ERR_CNT_KEY + username; + String loginFail = Constants.LOGIN_FAIL; + + // 获取用户登录错误次数(可自定义限制策略 例如: key + username + ip) + Integer errorNumber = RedisUtils.getCacheObject(errorKey); + // 锁定时间内登录 则踢出 + if (ObjectUtil.isNotNull(errorNumber) && errorNumber.equals(maxRetryCount)) { + recordLoginInfo(tenantId, username, loginFail, MessageUtils.message(loginType.getRetryLimitExceed(), maxRetryCount, lockTime)); + throw new UserException("重试达到最大限制"); + } + + if (supplier.get()) { + // 是否第一次 + errorNumber = ObjectUtil.isNull(errorNumber) ? 1 : errorNumber + 1; + // 达到规定错误次数 则锁定登录 + if (errorNumber.equals(maxRetryCount)) { + RedisUtils.setCacheObject(errorKey, errorNumber, Duration.ofMinutes(lockTime)); + recordLoginInfo(tenantId, username, loginFail, MessageUtils.message(loginType.getRetryLimitExceed(), maxRetryCount, lockTime)); + throw new UserException("重试达到最大限制"); + + } else { + // 未达到规定错误次数 则递增 + RedisUtils.setCacheObject(errorKey, errorNumber); + recordLoginInfo(tenantId, username, loginFail, MessageUtils.message(loginType.getRetryLimitCount(), errorNumber)); + throw new UserException(String.format("错误次数:%s", errorNumber)); + + } + } + + // 登录成功 清空错误次数 + RedisUtils.deleteObject(errorKey); + } + + private void checkTenant(Long tenantId) { + if (!TenantHelper.isEnable()) { + return; + } + if (TenantConstants.DEFAULT_TENANT_ID.equals(tenantId)) { + return; + } + SysTenantVo tenant = tenantService.queryByTenantId(tenantId); + if (ObjectUtil.isNull(tenant)) { + log.info("登录租户:{} 不存在.", tenantId); + throw new BizException(ErrCode.TENANT_NOT_FOUND); + } else if (TenantConstants.DISABLE.equals(tenant.getStatus())) { + log.info("登录租户:{} 已被停用.", tenantId); + throw new BizException(ErrCode.TENANT_DISABLE); + } else if (ObjectUtil.isNotNull(tenant.getExpireTime()) + && new Date().after(tenant.getExpireTime())) { + log.info("登录租户:{} 已超过有效期.", tenantId); + throw new BizException(ErrCode.TENANT_EXPIRE); + } + } + +} diff --git a/iot-starter/src/main/java/cc/iotkit/web/service/SysRegisterService.java b/iot-starter/src/main/java/cc/iotkit/web/service/SysRegisterService.java new file mode 100644 index 0000000..e309702 --- /dev/null +++ b/iot-starter/src/main/java/cc/iotkit/web/service/SysRegisterService.java @@ -0,0 +1,126 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ + +package cc.iotkit.web.service; + +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.constant.GlobalConstants; +import cc.iotkit.common.enums.UserType; +import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.exception.user.UserException; +import cc.iotkit.common.redis.utils.RedisUtils; +import cc.iotkit.common.utils.MessageUtils; +import cc.iotkit.common.utils.StringUtils; +import cc.iotkit.common.web.config.properties.CaptchaProperties; +import cc.iotkit.system.dto.RegisterBody; +import cc.iotkit.system.dto.bo.SysUserBo; +import cc.iotkit.system.service.ISysUserService; +import cn.dev33.satoken.secure.BCrypt; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * 注册校验方法 + * + * @author Lion Li + */ +@RequiredArgsConstructor +@Service +public class SysRegisterService { + + private final ISysUserService userService; + private final CaptchaProperties captchaProperties; + + /** + * 注册 + */ + public void register(RegisterBody registerBody) { + Long tenantId = registerBody.getTenantId(); + String username = registerBody.getUsername(); + String password = registerBody.getPassword(); + // 校验用户类型是否存在 + String userType = UserType.getUserType(registerBody.getUserType()).getUserType(); + + boolean captchaEnabled = captchaProperties.getEnable(); + // 验证码开关 + if (captchaEnabled) { + validateCaptcha(tenantId, username, registerBody.getCode(), registerBody.getUuid()); + } + SysUserBo sysUser = new SysUserBo(); + sysUser.setUserName(username); + sysUser.setNickName(username); + sysUser.setPassword(BCrypt.hashpw(password)); + sysUser.setUserType(userType); + + if (!userService.checkUserNameUnique(sysUser)) { + throw new UserException( username); + } + boolean regFlag = userService.registerUser(sysUser, tenantId); + if (!regFlag) { + throw new UserException( "注册失败" ); + } + recordLoginInfo(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success")); + } + + /** + * 校验验证码 + * + * @param username 用户名 + * @param code 验证码 + * @param uuid 唯一标识 + */ + public void validateCaptcha(Long tenantId, String username, String code, String uuid) { + String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, ""); + String captcha = RedisUtils.getCacheObject(verifyKey); + RedisUtils.deleteObject(verifyKey); + if (captcha == null) { + recordLoginInfo(tenantId, username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.expire")); + throw new BizException("验证码过期"); + + } + if (!code.equalsIgnoreCase(captcha)) { + recordLoginInfo(tenantId, username, Constants.REGISTER, MessageUtils.message("user.jcaptcha.error")); + throw new BizException("验证码错误"); + } + } + + /** + * 记录登录信息 + * + * @param tenantId 租户ID + * @param username 用户名 + * @param status 状态 + * @param message 消息内容 + * @return + */ + private void recordLoginInfo(Long tenantId, String username, String status, String message) { +// LogininforEvent logininforEvent = new LogininforEvent(); +// logininforEvent.setTenantId(tenantId); +// logininforEvent.setUsername(username); +// logininforEvent.setStatus(status); +// logininforEvent.setMessage(message); +// logininforEvent.setRequest(ServletUtils.getRequest()); +// SpringUtils.context().publishEvent(logininforEvent); + } + +} diff --git a/iot-starter/src/main/resources/application-dev.yml b/iot-starter/src/main/resources/application-dev.yml new file mode 100644 index 0000000..1b0e8aa --- /dev/null +++ b/iot-starter/src/main/resources/application-dev.yml @@ -0,0 +1,199 @@ + +server: + port: 8086 + address: 0.0.0.0 # 新增此行 +spring: + servlet: + multipart: + enabled: true + max-file-size: 200MB + max-request-size: 200MB + + #注: 切换数据库时需要将项目根目录中的.init文件删除再重启 + # <<=======内置H2数据库连接设置开始========== +# jpa: +# show-sql: false +# hibernate: +# ddl-auto: update +# properties: +# hibernate: +# format_sql: true +# datasource: +# type: com.zaxxer.hikari.HikariDataSource +# driverClassName: org.h2.Driver +# url: jdbc:h2:./data/iotkit;MODE=MySQL +# username: sa +# password: 123456 +# hikari: +# connection-timeout: 10000 +# idle-timeout: 60000 # 经过idle-timeout时间如果连接还处于空闲状态, 该连接会被回收 +# min-idle: 5 # 池中维护的最小空闲连接数, 默认为 10 个 +# max-pool-size: 16 # 池中最大连接数, 包括闲置和使用中的连接, 默认为 10 个 +# max-lifetime: 120000 # 如果一个连接超过了时长,且没有被使用, 连接会被回收 +# is-auto-commit: true +# # 内置h2 web console设置 +# platform: h2 +# h2: +# console: +# enabled: true +# path: /h2 +# settings: +# web-allow-others: true + #=======内置H2数据库连接设置结束==========>> + + # <<==========mysql配置开始============== + jpa: + database: MySQL + database-platform: org.hibernate.dialect.MySQL5InnoDBDialect + show-sql: true + hibernate: + ddl-auto: update + properties: + hibernate: + format_sql: true + use_sql_comments: true # 输出SQL注释 + session_factory: + # statement_inspector: com.example.TenantSQLInterceptor + # dialect: org.hibernate.dialect.MySQL5Dialect + datasource: + type: com.zaxxer.hikari.HikariDataSource + driverClassName: com.mysql.cj.jdbc.Driver + # jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562 + url: jdbc:mysql://192.168.10.29:3306/hma_iot?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false + username: root + password: CGKhbMfrdz6w3icX + hikari: + connection-timeout: 10000 + idle-timeout: 60000 # 经过idle-timeout时间如果连接还处于空闲状态, 该连接会被回收 + min-idle: 5 # 池中维护的最小空闲连接数, 默认为 10 个 + max-pool-size: 16 # 池中最大连接数, 包括闲置和使用中的连接, 默认为 10 个 + max-lifetime: 120000 # 如果一个连接超过了时长,且没有被使用, 连接会被回收 + is-auto-commit: true + # ============mysql配置结束============>> + + #<<================es时序数据配置开始=============== + elasticsearch: + embedded: + # 是否启用内部es + enabled: false + port: 9301 + rest: + #使用内置es的配置 + #uris: http://elasticsearch:9200 + uris: http://192.168.10.14:9301 + username: + password: + connection-timeout: 10s + #================es时序数据配置结束===============>> + + #<<===========tdengine时序数据库配置开始============ +# td-datasource: +# url: jdbc:TAOS-RS://172.17.60.206:6041/iotkit?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8 +# username: root +# password: taosdata +# driverClassName: com.taosdata.jdbc.rs.RestfulDriver + #===========tdengine时序数据库配置开始============>> + + + #<<===========iotdb时序数据库配置开始============ +# iotdb-datasource: +# host: 127.0.0.1 +# port: 6667 +# username: root +# password: root + #===========tdengine时序数据库配置开始============>> + + redis: + #使用内置redis的配置 + embedded: + enabled: false + #host: redis + host: 192.168.10.14 + port: 6379 + database: 11 + password: HMkj@2023 + + mvc: + pathmatch: + matching-strategy: path_pattern_parser +# profiles: +# active: mysql + +#application.yml中打开注释支持rocketMq作为消息总线,pom.xml中打开注释使用rocketmq消息总线 +#rocketmq: +# name-server: 172.16.1.113:9876 +# producer: +# group: iotkit + +#图片存储用的是阿里云oss,如果需要上传产品图片才需要配置 +aliyun: + bucketId: + endpoint: + accessKeyId: + accessKeySecret: + +sa-token: + # token名称 (同时也是cookie名称) + token-name: token + # token有效期,单位s 默认30天, -1代表永不过期 + timeout: 2592000 + # token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒 + activity-timeout: -1 + # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) + is-concurrent: true + # 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token) + is-share: false + # token风格 + token-style: uuid + # 是否输出操作日志 + is-log: false + +captcha: + enable: true + # 页面 <参数设置> 可开启关闭 验证码校验 + # 验证码类型 math 数组计算 char 字符验证 + type: MATH + # line 线段干扰 circle 圆圈干扰 shear 扭曲干扰 + category: CIRCLE + # 数字验证码位数 + numberLength: 1 + # 字符验证码长度 + charLength: 4 + +# 用户配置 +user: + password: + # 密码最大错误次数 + maxRetryCount: 5 + # 密码锁定时间(默认10分钟) + lockTime: 10 + +# openapi配置 +openapi: + appid: 123456789 + password: 123456 + +oss: + region: xxxxx + endpoint: xxxxx + accessKey: xxxxx + secretKey: xxxxx + buckName: xxxx + +#微信小程序配置 +weixin: + appid: xx + secret: xx + authUrl: xx + +websocket: + enabled: true + path: /websocket + allowedOrigins: '*' + +# 插件配置 +plugin: + runMode: prod + mainPackage: cc.iotkit + pluginPath: + - ./data/plugins diff --git a/iot-starter/src/main/resources/application.yml b/iot-starter/src/main/resources/application.yml new file mode 100644 index 0000000..2c9e3fc --- /dev/null +++ b/iot-starter/src/main/resources/application.yml @@ -0,0 +1,16 @@ +spring: + profiles: +# active: dev,generator # 使用application-dev.yml和代码生成器模块application-generator.yml配置 + active: dev,generator # 使用application-dev.yml 配置 +# active: prd # 使用application-prd.yml 配置 +# active: test # 使用application-test.yml 配置 +# active: mysql # 使用application-mysql.yml 配置 +minio: + server: http://221.176.140.236 + port: 9200 + endpoint: http://mini.huamar.com/ + access-key: ruoyi + secret-key: ruoyi123 + bucket: feijialuo + + diff --git a/iot-starter/src/main/resources/assemblies/standalone-package.xml b/iot-starter/src/main/resources/assemblies/standalone-package.xml new file mode 100644 index 0000000..4e0e585 --- /dev/null +++ b/iot-starter/src/main/resources/assemblies/standalone-package.xml @@ -0,0 +1,71 @@ + + standalone-package + + zip + + + false + + + + + + ${project.parent.basedir}/iot-starter/src/main/bin + ${project.name}/bin + + **/*.bat + **/*.sh + + 0755 + + unix + true + + + + + ${project.parent.basedir}/iot-starter/src/main/resources + ${project.name}/config + + **/*.xml + **/*.properties + **/*.yml + + true + + + + + target + ${project.name}/lib + + *.jar + + + + + + ${project.parent.basedir} + ${project.name}/docs + + *.md + + 0644 + + + + + ${project.parent.basedir}/data/init + ${project.name}/data/init + + **/* + + + + + \ No newline at end of file diff --git a/iot-starter/src/main/resources/ip2region.xdb b/iot-starter/src/main/resources/ip2region.xdb new file mode 100644 index 0000000..31f96a1 Binary files /dev/null and b/iot-starter/src/main/resources/ip2region.xdb differ diff --git a/iot-starter/src/main/resources/logback.xml b/iot-starter/src/main/resources/logback.xml new file mode 100644 index 0000000..a4a1702 --- /dev/null +++ b/iot-starter/src/main/resources/logback.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + DEBUG + + + ${CONSOLE_LOG_PATTERN} + utf8 + + + + + + ${LOG_FILE}/info.log + + ${LOG_FILE}/info.%d{yyyy-MM-dd}.%i.gz + + 5 + + 20GB + + + 1GB + + + + ${CONSOLE_LOG_PATTERN} + utf8 + + + + + + ${LOG_FILE}/error.log + + ${LOG_FILE}/error.%d{yyyy-MM-dd}.%i.gz + + 5 + + 5GB + + + 1GB + + + + ${CONSOLE_LOG_PATTERN} + utf8 + + + ERROR + ACCEPT + DENY + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/iot-starter/src/main/resources/sql/schema-postgre.sql b/iot-starter/src/main/resources/sql/schema-postgre.sql new file mode 100644 index 0000000..c593d65 --- /dev/null +++ b/iot-starter/src/main/resources/sql/schema-postgre.sql @@ -0,0 +1,112 @@ + +-- ---------------------------- +-- 18、代码生成业务表 +-- ---------------------------- +drop table if exists gen_table; +create table if not exists gen_table +( + table_id int8, + data_name varchar(200) default ''::varchar, + table_name varchar(200) default ''::varchar, + table_comment varchar(500) default ''::varchar, + sub_table_name varchar(64) default ''::varchar, + sub_table_fk_name varchar(64) default ''::varchar, + class_name varchar(100) default ''::varchar, + tpl_category varchar(200) default 'crud'::varchar, + package_name varchar(100) default null::varchar, + module_name varchar(30) default null::varchar, + business_name varchar(30) default null::varchar, + function_name varchar(50) default null::varchar, + function_author varchar(50) default null::varchar, + gen_type char default '0'::bpchar not null, + gen_path varchar(200) default '/'::varchar, + options varchar(1000) default null::varchar, + create_dept int8, + create_by int8, + create_time timestamp, + update_by int8, + update_time timestamp, + remark varchar(500) default null::varchar, + constraint gen_table_pk primary key (table_id) + ); + +comment on table gen_table is '代码生成业务表'; +comment on column gen_table.table_id is '编号'; +comment on column gen_table.data_name is '数据源名称'; +comment on column gen_table.table_name is '表名称'; +comment on column gen_table.table_comment is '表描述'; +comment on column gen_table.sub_table_name is '关联子表的表名'; +comment on column gen_table.sub_table_fk_name is '子表关联的外键名'; +comment on column gen_table.class_name is '实体类名称'; +comment on column gen_table.tpl_category is '使用的模板(CRUD单表操作 TREE树表操作)'; +comment on column gen_table.package_name is '生成包路径'; +comment on column gen_table.module_name is '生成模块名'; +comment on column gen_table.business_name is '生成业务名'; +comment on column gen_table.function_name is '生成功能名'; +comment on column gen_table.function_author is '生成功能作者'; +comment on column gen_table.gen_type is '生成代码方式(0zip压缩包 1自定义路径)'; +comment on column gen_table.gen_path is '生成路径(不填默认项目路径)'; +comment on column gen_table.options is '其它生成选项'; +comment on column gen_table.create_dept is '创建部门'; +comment on column gen_table.create_by is '创建者'; +comment on column gen_table.create_time is '创建时间'; +comment on column gen_table.update_by is '更新者'; +comment on column gen_table.update_time is '更新时间'; +comment on column gen_table.remark is '备注'; + +-- ---------------------------- +-- 19、代码生成业务表字段 +-- ---------------------------- +drop table if exists gen_table_column; +create table if not exists gen_table_column +( + column_id int8, + table_id int8, + column_name varchar(200) default null::varchar, + column_comment varchar(500) default null::varchar, + column_type varchar(100) default null::varchar, + java_type varchar(500) default null::varchar, + java_field varchar(200) default null::varchar, + is_pk char default null::bpchar, + is_increment char default null::bpchar, + is_required char default null::bpchar, + is_insert char default null::bpchar, + is_edit char default null::bpchar, + is_list char default null::bpchar, + is_query char default null::bpchar, + query_type varchar(200) default 'EQ'::varchar, + html_type varchar(200) default null::varchar, + dict_type varchar(200) default ''::varchar, + sort int4, + create_dept int8, + create_by int8, + create_time timestamp, + update_by int8, + update_time timestamp, + constraint gen_table_column_pk primary key (column_id) + ); + +comment on table gen_table_column is '代码生成业务表字段'; +comment on column gen_table_column.column_id is '编号'; +comment on column gen_table_column.table_id is '归属表编号'; +comment on column gen_table_column.column_name is '列名称'; +comment on column gen_table_column.column_comment is '列描述'; +comment on column gen_table_column.column_type is '列类型'; +comment on column gen_table_column.java_type is 'JAVA类型'; +comment on column gen_table_column.java_field is 'JAVA字段名'; +comment on column gen_table_column.is_pk is '是否主键(1是)'; +comment on column gen_table_column.is_increment is '是否自增(1是)'; +comment on column gen_table_column.is_required is '是否必填(1是)'; +comment on column gen_table_column.is_insert is '是否为插入字段(1是)'; +comment on column gen_table_column.is_edit is '是否编辑字段(1是)'; +comment on column gen_table_column.is_list is '是否列表字段(1是)'; +comment on column gen_table_column.is_query is '是否查询字段(1是)'; +comment on column gen_table_column.query_type is '查询方式(等于、不等于、大于、小于、范围)'; +comment on column gen_table_column.html_type is '显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)'; +comment on column gen_table_column.dict_type is '字典类型'; +comment on column gen_table_column.sort is '排序'; +comment on column gen_table_column.create_dept is '创建部门'; +comment on column gen_table_column.create_by is '创建者'; +comment on column gen_table_column.create_time is '创建时间'; +comment on column gen_table_column.update_by is '更新者'; +comment on column gen_table_column.update_time is '更新时间'; diff --git a/iot-starter/src/main/resources/sql/schema.sql b/iot-starter/src/main/resources/sql/schema.sql new file mode 100644 index 0000000..b9ea000 --- /dev/null +++ b/iot-starter/src/main/resources/sql/schema.sql @@ -0,0 +1,60 @@ +-- ---------------------------- +-- 18、代码生成业务表 +-- ---------------------------- +create table if not exists gen_table ( + table_id bigint(20) not null comment '编号', + data_name varchar(200) default '' comment '数据源名称', + table_name varchar(200) default '' comment '表名称', + table_comment varchar(500) default '' comment '表描述', + sub_table_name varchar(64) default null comment '关联子表的表名', + sub_table_fk_name varchar(64) default null comment '子表关联的外键名', + class_name varchar(100) default '' comment '实体类名称', + tpl_category varchar(200) default 'crud' comment '使用的模板(crud单表操作 tree树表操作)', + package_name varchar(100) comment '生成包路径', + module_name varchar(30) comment '生成模块名', + business_name varchar(30) comment '生成业务名', + function_name varchar(50) comment '生成功能名', + function_author varchar(50) comment '生成功能作者', + gen_type char(1) default '0' comment '生成代码方式(0zip压缩包 1自定义路径)', + gen_path varchar(200) default '/' comment '生成路径(不填默认项目路径)', + options varchar(1000) comment '其它生成选项', + create_dept bigint(20) default null comment '创建部门', + create_by bigint(20) default null comment '创建者', + create_time datetime comment '创建时间', + update_by bigint(20) default null comment '更新者', + update_time datetime comment '更新时间', + remark varchar(500) default null comment '备注', + primary key (table_id) +) engine=innodb comment = '代码生成业务表'; + + +-- ---------------------------- +-- 19、代码生成业务表字段 +-- ---------------------------- + +create table if not exists gen_table_column ( + column_id bigint(20) not null comment '编号', + table_id bigint(20) comment '归属表编号', + column_name varchar(200) comment '列名称', + column_comment varchar(500) comment '列描述', + column_type varchar(100) comment '列类型', + java_type varchar(500) comment 'JAVA类型', + java_field varchar(200) comment 'JAVA字段名', + is_pk char(1) comment '是否主键(1是)', + is_increment char(1) comment '是否自增(1是)', + is_required char(1) comment '是否必填(1是)', + is_insert char(1) comment '是否为插入字段(1是)', + is_edit char(1) comment '是否编辑字段(1是)', + is_list char(1) comment '是否列表字段(1是)', + is_query char(1) comment '是否查询字段(1是)', + query_type varchar(200) default 'EQ' comment '查询方式(等于、不等于、大于、小于、范围)', + html_type varchar(200) comment '显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)', + dict_type varchar(200) default '' comment '字典类型', + sort int comment '排序', + create_dept bigint(20) default null comment '创建部门', + create_by bigint(20) default null comment '创建者', + create_time datetime comment '创建时间', + update_by bigint(20) default null comment '更新者', + update_time datetime comment '更新时间', + primary key (column_id) +) engine=innodb comment = '代码生成业务表字段'; \ No newline at end of file diff --git a/iot-test-tool/iot-virtual-device/pom.xml b/iot-test-tool/iot-virtual-device/pom.xml new file mode 100644 index 0000000..c5121b5 --- /dev/null +++ b/iot-test-tool/iot-virtual-device/pom.xml @@ -0,0 +1,67 @@ + + + + iot-test-tool + cc.iotkit + 0.5.3 + + 4.0.0 + + iot-virtual-device + + 虚拟设备模块,用于虚拟真实设备数据上报 + + + + + cc.iotkit + iot-data-model + + + + cc.iotkit + iot-script-engine + + + + cc.iotkit + iot-data-service + + + + cc.iotkit + iot-plugin-main + + + + + + org.springframework.boot + spring-boot-starter + + + + org.quartz-scheduler + quartz + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + utf8 + + + + + + diff --git a/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualExecutor.java b/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualExecutor.java new file mode 100644 index 0000000..eee9809 --- /dev/null +++ b/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualExecutor.java @@ -0,0 +1,74 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.virtualdevice; + +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.VirtualDevice; +import cc.iotkit.model.device.VirtualDeviceLog; +import lombok.extern.slf4j.Slf4j; +import org.quartz.Job; +import org.quartz.JobDetail; +import org.quartz.JobExecutionContext; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +@Slf4j +public class VirtualExecutor implements Job { + + @Override + public void execute(JobExecutionContext context) { + Map data = context.getMergedJobDataMap(); + VirtualManager virtualManager = (VirtualManager) data.get("virtualManager"); + VirtualDevice virtualDevice = (VirtualDevice) data.get("virtualDevice"); + List devices = (List) data.get("devices"); + devices = devices == null ? new ArrayList<>() : devices; + JobDetail jobDetail = context.getJobDetail(); + String jobKey = jobDetail.getKey().toString(); + + VirtualDeviceLog virtualDeviceLog = VirtualDeviceLog.builder() + .id(UUID.randomUUID().toString()) + .virtualDeviceId(virtualDevice.getId()) + .virtualDeviceName(virtualDevice.getName()) + .deviceTotal(devices.size()) + .result("success") + .logAt(System.currentTimeMillis()) + .build(); + + try { + for (DeviceInfo device : devices) { + if (device == null) { + continue; + } + log.info("invoke virtual device report,jobKey:{},deviceId:{}", jobKey, device.getDeviceId()); + virtualManager.invokeReport(device, virtualDevice.getId()); + } + } catch (Throwable e) { + virtualDeviceLog.setResult(e.getMessage()); + log.error("execute job error", e); + } + virtualManager.saveLog(virtualDeviceLog); + } +} diff --git a/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualManager.java b/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualManager.java new file mode 100644 index 0000000..1ca40e5 --- /dev/null +++ b/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/VirtualManager.java @@ -0,0 +1,321 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.virtualdevice; + +import cc.iotkit.common.constant.Constants; +import cc.iotkit.common.thing.ThingModelMessage; +import cc.iotkit.common.thing.ThingService; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.common.utils.UniqueIdUtil; +import cc.iotkit.data.manager.IDeviceInfoData; +import cc.iotkit.data.manager.IVirtualDeviceData; +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.device.VirtualDevice; +import cc.iotkit.model.device.VirtualDeviceLog; +import cc.iotkit.mq.MqProducer; +import cc.iotkit.plugin.core.thing.IThingService; +import cc.iotkit.plugin.core.thing.actions.DeviceState; +import cc.iotkit.plugin.core.thing.actions.up.DeviceStateChange; +import cc.iotkit.script.IScriptEngine; +import cc.iotkit.script.ScriptEngineFactory; +import cc.iotkit.temporal.IVirtualDeviceLogData; +import cc.iotkit.virtualdevice.trigger.RandomScheduleBuilder; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.quartz.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + +import java.util.*; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +@Slf4j +public class VirtualManager { + private final Map virtualScripts = new HashMap<>(); + private final Map> deviceIdToVirtualId = new HashMap<>(); + + @Autowired + private IVirtualDeviceData virtualDeviceData; + @Autowired + @Qualifier("deviceInfoDataCache") + private IDeviceInfoData deviceInfoData; + @Autowired + private Scheduler scheduler; + @Autowired + private IVirtualDeviceLogData virtualDeviceLogData; + @Autowired + private IThingService thingService; + @Autowired + private MqProducer producer; + + public VirtualManager(){ + ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); + executorService.schedule(this::init, 8, TimeUnit.SECONDS); + } + + public void init() { + List virtualDevices = getAllVirtualDevices(); + for (VirtualDevice virtualDevice : virtualDevices) { + addTask(virtualDevice); + } + } + + /** + * 判断设备是否应用了虚拟设备 + */ + public boolean isVirtual(String deviceId) { + return deviceIdToVirtualId.containsKey(deviceId); + } + + /** + * 调用虚拟设备下发 + */ + @SneakyThrows + public void send(ThingService service) { + DeviceInfo deviceInfo = deviceInfoData.findByDeviceName(service.getDeviceName()); + String deviceId = deviceInfo.getDeviceId(); + + //根据设备Id取虚拟设备列表 + Set virtualIds = deviceIdToVirtualId.get(deviceId); + for (String virtualId : virtualIds) { + IScriptEngine scriptEngine = virtualScripts.get(virtualId); + //多条虚拟设备消息 + List result = scriptEngine.invokeMethod( + new TypeReference<>() { + }, + "receive", service); + for (ThingModelMessage msg : result) { + processReport(msg); + } + log.info("virtual device send result:{}", JsonUtils.toJsonString(result)); + } + } + + /** + * 添加虚拟设备 + */ + public void add(VirtualDevice virtualDevice) { + addTask(virtualDevice); + } + + /** + * 删除虚拟设备 + */ + public void remove(VirtualDevice virtualDevice) { + deleteTask(virtualDevice); + } + + /** + * 立即执行一次虚拟设备上报 + */ + public void run(VirtualDevice virtualDevice) { + List devices = virtualDevice.getDevices(); + VirtualDeviceLog virtualDeviceLog = VirtualDeviceLog.builder() + .id(UUID.randomUUID().toString()) + .virtualDeviceId(virtualDevice.getId()) + .virtualDeviceName(virtualDevice.getName()) + .deviceTotal(devices.size()) + .result("success") + .logAt(System.currentTimeMillis()) + .build(); + try { + IScriptEngine scriptEngine = virtualScripts.get(virtualDevice.getId()); + if ( null == scriptEngine ) { + //添加新的脚本对象 + scriptEngine = ScriptEngineFactory.getScriptEngine("js"); + scriptEngine.setScript(virtualDevice.getScript()); + virtualScripts.put(virtualDevice.getId(), scriptEngine); + } + for (String deviceId : devices) { + DeviceInfo device = deviceInfoData.findByDeviceId(deviceId); + processReport(scriptEngine.invokeMethod(new TypeReference<>() { + }, "report", device)); + } + } catch (Throwable e) { + virtualDeviceLog.setResult(e.getMessage()); + log.error("run VirtualDevice error", e); + } + virtualDeviceLogData.add(virtualDeviceLog); + } + + /** + * 更新虚拟设备 + */ + public void update(VirtualDevice virtualDevice) { + remove(virtualDevice); + add(virtualDevice); + } + + /** + * 获取所有虚拟设备 + */ + private List getAllVirtualDevices() { + List randomVirtualDevices = virtualDeviceData + .findByTriggerAndState(VirtualDevice.TRIGGER_RANDOM, VirtualDevice.STATE_RUNNING); + List cronVirtualDevices = virtualDeviceData + .findByTriggerAndState(VirtualDevice.TRIGGER_CRON, VirtualDevice.STATE_RUNNING); + cronVirtualDevices.addAll(randomVirtualDevices); + return cronVirtualDevices; + } + + private void addTask(VirtualDevice virtualDevice) { + try { + String id = virtualDevice.getId(); + String name = virtualDevice.getName(); + String script = virtualDevice.getScript(); + log.info("adding virtual device job,id:{},name:{}", id, name); + + //添加新的脚本对象 + IScriptEngine scriptEngine = ScriptEngineFactory.getScriptEngine("js"); + scriptEngine.setScript(script); + virtualScripts.put(id, scriptEngine); + List devices = new ArrayList<>(); + for (String deviceId : virtualDevice.getDevices()) { + devices.add(deviceInfoData.findByDeviceId(deviceId)); + //更新deviceId的虚拟设备Id对应关系 + Set virtualIds = deviceIdToVirtualId.getOrDefault(deviceId, new HashSet<>()); + virtualIds.add(id); + //一个真实设备可能会被多个虚拟设备使用 + deviceIdToVirtualId.put(deviceId, virtualIds); + } + + JobDataMap jobDataMap = new JobDataMap(); + jobDataMap.put("virtualManager", this); + jobDataMap.put("virtualDevice", virtualDevice); + jobDataMap.put("devices", devices); + + JobDetail jobDetail = JobBuilder.newJob(VirtualExecutor.class) + .withIdentity(id, name) + .usingJobData(jobDataMap) + .build(); + + Trigger trigger = TriggerBuilder + .newTrigger() + .withIdentity("trigger_" + id, "triggerGroup_" + name) + .startNow() + .withSchedule( + getTriggerBuilder(virtualDevice) + ).build(); + + scheduler.scheduleJob(jobDetail, trigger); + if (!scheduler.isShutdown()) { + scheduler.start(); + } + } catch (Throwable e) { + log.error("create job failed", e); + } + } + + private ScheduleBuilder getTriggerBuilder(VirtualDevice virtualDevice) { + String type = virtualDevice.getTrigger(); + if ("random".equals(type)) { + return new RandomScheduleBuilder(virtualDevice.getTriggerExpression()); + } + if ("cron".equals(type)) { + return CronScheduleBuilder.cronSchedule(virtualDevice.getTriggerExpression()); + } + return null; + } + + @SneakyThrows + public void deleteTask(VirtualDevice virtualDevice) { + String id = virtualDevice.getId(); + String name = virtualDevice.getName(); + + //删除脚本对象 + virtualScripts.remove(id); + + //更新deviceId的虚拟设备Id对应关系 + Iterator keyIterator = deviceIdToVirtualId.keySet().iterator(); + while (keyIterator.hasNext()) { + String deviceId = keyIterator.next(); + Set virtualIds = deviceIdToVirtualId.get(deviceId); + virtualIds.remove(id); + if (virtualIds.size() == 0) { + keyIterator.remove(); + } + } + + //删除job + TriggerKey triggerKey = new TriggerKey("trigger_" + id, "triggerGroup_" + name); + if (!scheduler.checkExists(triggerKey)) { + return; + } + scheduler.deleteJob(JobKey.jobKey(id, name)); + } + + /** + * 处理js上报方法返回结果 + */ + private void processReport(ThingModelMessage message) { + try { + producer.publish(Constants.THING_MODEL_MESSAGE_TOPIC, message); + } catch (Throwable e) { + log.error("process js data error", e); + } + } + + /** + * 调用脚本中上报方法 + */ + @SneakyThrows + public void invokeReport(DeviceInfo device, String virtualId) { + //设备上线 + deviceOnline(device); + + IScriptEngine scriptEngine = virtualScripts.get(virtualId); + if (scriptEngine == null) { + return; + } + processReport(scriptEngine.invokeMethod(new TypeReference<>() { + }, "report", device)); + } + + /** + * 设备上线 + */ + private void deviceOnline(DeviceInfo device) { + DeviceInfo.State state = device.getState(); + if (state == null || !state.isOnline()) { + //设备离线,产生上线消息 + thingService.post("NONE", DeviceStateChange.builder() + .id(UniqueIdUtil.newRequestId()) + .productKey(device.getProductKey()) + .deviceName(device.getDeviceName()) + .state(DeviceState.ONLINE) + .time(System.currentTimeMillis()) + .build()); + } + } + + /** + * 保存虚拟设备日志 + */ + public void saveLog(VirtualDeviceLog log) { + virtualDeviceLogData.add(log); + } + +} diff --git a/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/config/VirtualConfig.java b/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/config/VirtualConfig.java new file mode 100644 index 0000000..368f1a2 --- /dev/null +++ b/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/config/VirtualConfig.java @@ -0,0 +1,37 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.virtualdevice.config; + +import cc.iotkit.virtualdevice.VirtualManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class VirtualConfig { + + @Bean + public VirtualManager getVirtualManager() { + return new VirtualManager(); + } + +} diff --git a/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/trigger/RandomScheduleBuilder.java b/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/trigger/RandomScheduleBuilder.java new file mode 100644 index 0000000..64a5775 --- /dev/null +++ b/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/trigger/RandomScheduleBuilder.java @@ -0,0 +1,40 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.virtualdevice.trigger; + +import org.quartz.ScheduleBuilder; +import org.quartz.spi.MutableTrigger; + +public class RandomScheduleBuilder extends ScheduleBuilder { + + private final String unit; + + public RandomScheduleBuilder(String unit) { + this.unit = unit; + } + + public MutableTrigger build() { + return new RandomTrigger(unit); + } + +} diff --git a/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/trigger/RandomTrigger.java b/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/trigger/RandomTrigger.java new file mode 100644 index 0000000..74060f5 --- /dev/null +++ b/iot-test-tool/iot-virtual-device/src/main/java/cc/iotkit/virtualdevice/trigger/RandomTrigger.java @@ -0,0 +1,69 @@ +/* + * + * * | Licensed 未经许可不能去掉「OPENIITA」相关版权 + * * +---------------------------------------------------------------------- + * * | Author: xw2sy@163.com + * * +---------------------------------------------------------------------- + * + * Copyright [2024] [OPENIITA] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * / + */ +package cc.iotkit.virtualdevice.trigger; + +import org.apache.commons.lang3.RandomUtils; +import org.quartz.Calendar; +import org.quartz.impl.triggers.SimpleTriggerImpl; + +import java.util.Date; + +public class RandomTrigger extends SimpleTriggerImpl { + + private String unit; + private Date nextFireTime; + + public RandomTrigger(String unit) { + this.unit = unit; + } + + @Override + public void triggered(Calendar calendar) { + super.triggered(calendar); + nextFireTime = randomTime(); + } + + @Override + public Date getNextFireTime() { + if (nextFireTime == null) { + nextFireTime = randomTime(); + } + return nextFireTime; + } + + private Date randomTime() { + Date previousTime = getPreviousFireTime(); + if (previousTime == null) { + previousTime = new Date(); + } + long time = previousTime.getTime(); + if ("second".equals(unit)) { + time = time + RandomUtils.nextInt(0, 60) * 1000; + } else if ("minute".equals(unit)) { + time = time + RandomUtils.nextInt(0, 60) * 1000 * 60; + } else if ("hour".equals(unit)) { + time = time + RandomUtils.nextInt(0, 60) * 1000 * 60 * 60; + } + return new Date(time); + } +} diff --git a/iot-test-tool/iot-virtual-device/src/main/resources/spring.factories b/iot-test-tool/iot-virtual-device/src/main/resources/spring.factories new file mode 100644 index 0000000..68e7ceb --- /dev/null +++ b/iot-test-tool/iot-virtual-device/src/main/resources/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=cc.iotkit.virtualdevice.config.VirtualConfig diff --git a/iot-test-tool/pom.xml b/iot-test-tool/pom.xml new file mode 100644 index 0000000..ec47bfd --- /dev/null +++ b/iot-test-tool/pom.xml @@ -0,0 +1,22 @@ + + + + iotkit-parent + cc.iotkit + 0.5.3 + + 4.0.0 + pom + + 提供用于测试的相关工具的模块 + + + + iot-virtual-device + + + iot-test-tool + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a97a27c --- /dev/null +++ b/pom.xml @@ -0,0 +1,434 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.7.11 + + + + cc.iotkit + iotkit-parent + 0.5.3 + ${project.artifactId} + 奇特物联是一个开源的物联网基础开发平台,提供了物联网及相关业务开发的常见基础功能, + 能帮助你快速搭建自己的物联网相关业务平台。 + + https://gitee.com/iotkit-open-source/iotkit-parent + pom + + + iot-dao + iot-module + iot-starter + iot-test-tool + + + + 11 + 1.0.5 + 2.7.11 + 4.2.2 + 1.34.0 + 1.9.3 + 3.7 + 5.8.18 + 1.3.1 + 3.1.4 + 1.0.6 + 2.3 + + + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + io.github.linpeilie + mapstruct-plus-spring-boot-starter + 1.3.1 + + + + commons-beanutils + commons-beanutils + ${beanutils.version} + + + + + cn.hutool + hutool-bom + ${hutool.version} + pom + import + + + + org.projectlombok + lombok + ${lombok.version} + + + + jakarta.servlet + jakarta.servlet-api + 6.0.0 + + + + org.quartz-scheduler + quartz + 2.3.2 + + + + javax.ws.rs + javax.ws.rs-api + 2.1.1 + + + + com.google.guava + guava + 20.0 + + + + co.elastic.clients + elasticsearch-java + 7.17.9 + + + + it.ozimov + embedded-redis + 0.7.3 + + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.17.1 + + + + com.ejlchina + okhttps + 3.1.1 + + + + io.vertx + vertx-kafka-client + ${vertx.version} + + + + io.vertx + vertx-core + ${vertx.version} + + + + io.vertx + vertx-mqtt + ${vertx.version} + + + + io.vertx + vertx-web-proxy + ${vertx.version} + + + + io.vertx + vertx-web-client + ${vertx.version} + + + + com.gitee.starblues + spring-brick + ${spring-brick.version} + + + + com.gitee.starblues + spring-brick-bootstrap + ${spring-brick.version} + + + + com.github.biyanwen + jpa-comment-spring-boot-starter + 1.0.0 + + + + com.github.xiaoymin + knife4j-spring-boot-starter + 2.0.9 + + + + io.swagger + swagger-annotations + 1.5.22 + + + + + cc.iotkit + iot-common-core + ${iot-iita-core.version} + + + + cc.iotkit + iot-common-thing + ${iot-iita-core.version} + + + + cc.iotkit + iot-common-oss + ${iot-iita-core.version} + + + + cc.iotkit + iot-common-websocket + ${iot-iita-core.version} + + + + cc.iotkit + iot-common-web + ${iot-iita-core.version} + + + + cc.iotkit + iot-common-doc + ${iot-iita-core.version} + + + + cc.iotkit + iot-common-satoken + ${iot-iita-core.version} + + + + cc.iotkit + iot-common-excel + ${iot-iita-core.version} + + + + cc.iotkit + iot-common-tenant + ${iot-iita-core.version} + + + + cc.iotkit + iot-common-redis + ${iot-iita-core.version} + + + + cc.iotkit + iot-common-log + ${iot-iita-core.version} + + + + + cc.iotkit + iot-message-core + ${iot-iita-core.version} + + + + cc.iotkit + iot-message-event-bus + ${iot-iita-core.version} + + + + cc.iotkit + iot-message-rocketmq + ${iot-iita-core.version} + + + + cc.iotkit + iot-script-engine + ${iot-iita-core.version} + + + + + cc.iotkit + iot-data-model + ${project.version} + + + + cc.iotkit + iot-data-service + ${project.version} + + + + cc.iotkit + iot-data-serviceImpl-cache + ${project.version} + + + + cc.iotkit + iot-data-serviceImpl-rdb + ${project.version} + + + + cc.iotkit + iot-temporal-service + ${project.version} + + + + cc.iotkit + iot-temporal-serviceImpl-es + ${project.version} + + + + cc.iotkit + iot-temporal-serviceImpl-td + ${project.version} + + + + cc.iotkit + iot-manager + ${project.version} + + + + cc.iotkit + iot-generator + ${project.version} + + + + cc.iotkit + iot-message-notify + ${project.version} + + + + cc.iotkit + iot-rule-engine + ${project.version} + + + + + + + + + + cc.iotkit + iot-system + ${project.version} + + + + cc.iotkit + iot-message-bus + ${iot-iita-core.version} + + + + cc.iotkit + iot-modbus + ${project.version} + + + + cc.iotkit + iot-openapi + ${project.version} + + + + cc.iotkit + iot-virtual-device + ${project.version} + + + + cc.iotkit + iot-plugin-core + ${iot-iita-core.version} + + + + cc.iotkit + iot-plugin-main + ${project.version} + + + + cc.iotkit + iot-oss-embed + ${iot-iita-core.version} + + + + com.github.yitter + yitter-idgenerator + ${yitter.version} + + + + org.apache.velocity + velocity-engine-core + ${velocity.version} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + UTF-8 + ${java.version} + ${java.version} + + + + + + diff --git a/待优化项.md b/待优化项.md new file mode 100644 index 0000000..7b9e6ce --- /dev/null +++ b/待优化项.md @@ -0,0 +1,88 @@ +# 1.**后端待优化项** +## ** 插件优化 !!!! ** +目前插件代码太重,需要优化 +插件删除存在bug,很多情况下无法删除 +插件启用时,不一定启用最新的版本插件,可能和删除有关 + +## ** 缓存优化 ** +缓存的信息优化 + +## **sonerlint扫描** +sonerlint扫描,按建议修改相关不规范的代码 + +## **接口路径** +尽量不用路径参数、且路径直接放在接口上,不放在常量里 + +## **冗余方法、类** +删除掉不用的冗余方法、类 + +## **日志** +sql 日志打印的话加个拦截器,简化sql +增加requestid 基于MDC--已完成 + +## **数据权限** +将原有的checkOwner做成通用的、文档 + +## **规则引擎-定时任务** +延时执行添加指定具体某一天时间 + +## **产品** +产品分类 +修改产品图片未生效 + +## **消息中心** +模板内容中把标题拆出来,也支持模板替换 + +## **消费消息 设备** +单条插入变批量插入 设置限制、超时 + +## **告警中心** +告警频次 + +## **[iot-manager](iot-module%2Fiot-manager)** +统一service接口层 接口+impl + +## **[iot-component-oss](iot-components%2Fiot-component-oss)** +新增本地文件存储方式 + +## **[iot-components](iot-components)** +抽离仓库 + +## **项目规范完善** + +## **文件上传的 requesid字段添加** + +## **初始化公用SystemApplicationRunner SysOssConfigServiceImpl統一** + +## **緩存注解統一** + +## **首頁缺少接口** + +## **产品导出接口** + +## **数据库字段名称** +统一创建时间、更新时间、创建人、更新人、删除标识、删除时间、删除人 + +## **通讯组件** +统一上传接口,组件jar上传requestId封装,本地上传实现,文件上传类型配置修改 + +## **代码生成器** +前端代码生成器完善 + +## **多租户** +目前只是几个表增加了租户支持 +MQ、redis之类的也需要多租户支持 + +## **modbus** +modbus云端轮询实现 + + + + +# 2.待开发 + +| 功能 | 模块 | 说明 | +|---------| --- |----------| +| 视频流管理 | | | +| 智能边缘端管理 | | | + diff --git a/项目规范.md b/项目规范.md new file mode 100644 index 0000000..12c7029 --- /dev/null +++ b/项目规范.md @@ -0,0 +1,13 @@ +# **项目规范** + +## **接口** +请求类型统一为POST,路径大致为模块归类/动作+资源,请求参数所有均封装下Request,超过一个参数必须封装成Bo对象 + +## **数据库** + + +## **service** + + +## **前端** +esLint 安装 \ No newline at end of file