diff --git a/data/init/protocolComponent.json b/data/init/protocolComponent.json deleted file mode 100644 index 8d60bd7c..00000000 --- a/data/init/protocolComponent.json +++ /dev/null @@ -1,82 +0,0 @@ -[ - { - "id": "eabb131d-8fd1-43a8-88d9-a198abfd3d42", - "uid": "1", - "name": "MQTT标准协议组件", - "type": "device", - "protocol": "mqtt", - "jarFile": "iot-mqtt-component-0.4.5-SNAPSHOT.jar", - "config": "{\"port\":1883,\"ssl\":false,\"type\":\"server\"}", - "converter": "6260396d67aced2696184053", - "converType": "custom", - "state": "running", - "createAt": 1650473458084 - }, - { - "id": "6c095554-35e7-4e9d-a8d2-bb919e9479f4", - "uid": "1", - "name": "EMQX标准协议组件", - "type": "device", - "protocol": "mqtt", - "jarFile": "iot-emqx-component-0.4.5-SNAPSHOT.jar", - "config": "{\"port\":\"1884\",\"ssl\":false,\"type\":\"client\",\"subscribeTopics\":[\"/sys/+/+/s/#\",\"/sys/client/connected\",\"/sys/client/disconnected\",\"/sys/session/subscribed\",\"/sys/session/unsubscribed\"],\"authPort\":\"8088\",\"broker\":\"127.0.0.1\",\"clientId\":\"test\",\"username\":\"test\",\"password\":\"123\"}", - "converter": "6260396d67aced2696184053", - "converType": "custom", - "state": "stopped", - "createAt": 1653180468724 - }, - { - "id": "3ababc5e-15e9-45a7-8f38-2a6afd45c780", - "uid": "1", - "name": "小度音箱接入组件", - "type": "biz", - "protocol": "http", - "jarFile": "iot-http-biz-component-0.4.5-SNAPSHOT.jar", - "config": "{\"port\":\"8084\"}", - "converter": "", - "converType": "", - "state": "stopped", - "createAt": 1650685502665 - }, - { - "id": "2c089bb8-0412-449e-94f1-212d35a50219", - "uid": "1", - "name": "WEBSOCKET服务端", - "type": "device", - "protocol": "websocket", - "jarFile": "iot-websocket-component-0.4.5-SNAPSHOT.jar", - "config": "{\"port\":\"2454\",\"ssl\":false,\"type\":\"server\",\"ip\":\"\",\"url\":\"\",\"heartBeatTime\":10000,\"heartBeatData\":\"\",\"accessTokens\":[{\"id\":\"b4f02276-13d8-499d-89b3-8acd6330b310\",\"tokenName\":\"tokrn\",\"tokenStr\":\"NxW4nPt2SPnc87pdFXAQmCZY4Kb0nRsPDC6z4Qzpp1AtRWDJxg8iZMqFpcwZ2igi\"}]}", - "converter": "d7e84930-5460-4638-aa3f-e0c2015628f4", - "converType": "custom", - "state": "stopped", - "createAt": 1650685502665 - } -, - { - "id": "305a8b86-4566-4f2a-a57f-f84ca47471a1", - "uid": "1", - "name": "DLT645电表通讯组件", - "type": "device", - "protocol": "tcp", - "jarFile": "iot-DLT645-component-0.4.5-SNAPSHOT.jar", - "config": "{\"port\":2424,\"ssl\":false,\"type\":\"server\",\"parserType\":\"不处理\",\"parserConfiguration\":{\"delimited\":\"\",\"fix\":1,\"script\":\"\"},\"host\":\"127.0.0.1\"}", - "converType": "static", - "state": "stopped", - "createAt": 1650685502665 - }, - { - "id": "750da259-ff77-4869-a5a5-12a5433b0e4c", - "config": "{\"port\":\"11883\",\"type\":\"server\"}", - "converType": "custom", - "converter": "50b0fdd0-9bc8-448d-a7cf-d3b1b4df944c", - "createAt": 1689567633641, - "jarFile": "iot-nb-component-0.4.5-SNAPSHOT.jar", - "name": "铱塔智联-阿里透传组件", - "protocol": "mqtt", - "script": "!function (n) {\n \"use strict\";\n\n function d(n, t) {\n var r = (65535 & n) + (65535 & t);\n return (n >> 16) + (t >> 16) + (r >> 16) << 16 | 65535 & r\n }\n\n function f(n, t, r, e, o, u) {\n return d((u = d(d(t, n), d(e, u))) << o | u >>> 32 - o, r)\n }\n\n function l(n, t, r, e, o, u, c) {\n return f(t & r | ~t & e, n, t, o, u, c)\n }\n\n function g(n, t, r, e, o, u, c) {\n return f(t & e | r & ~e, n, t, o, u, c)\n }\n\n function v(n, t, r, e, o, u, c) {\n return f(t ^ r ^ e, n, t, o, u, c)\n }\n\n function m(n, t, r, e, o, u, c) {\n return f(r ^ (t | ~e), n, t, o, u, c)\n }\n\n function c(n, t) {\n var r, e, o, u;\n n[t >> 5] |= 128 << t % 32, n[14 + (t + 64 >>> 9 << 4)] = t;\n for (var c = 1732584193, f = -271733879, i = -1732584194, a = 271733878, h = 0; h < n.length; h += 16) c = l(r = c, e = f, o = i, u = a, n[h], 7, -680876936), a = l(a, c, f, i, n[h + 1], 12, -389564586), i = l(i, a, c, f, n[h + 2], 17, 606105819), f = l(f, i, a, c, n[h + 3], 22, -1044525330), c = l(c, f, i, a, n[h + 4], 7, -176418897), a = l(a, c, f, i, n[h + 5], 12, 1200080426), i = l(i, a, c, f, n[h + 6], 17, -1473231341), f = l(f, i, a, c, n[h + 7], 22, -45705983), c = l(c, f, i, a, n[h + 8], 7, 1770035416), a = l(a, c, f, i, n[h + 9], 12, -1958414417), i = l(i, a, c, f, n[h + 10], 17, -42063), f = l(f, i, a, c, n[h + 11], 22, -1990404162), c = l(c, f, i, a, n[h + 12], 7, 1804603682), a = l(a, c, f, i, n[h + 13], 12, -40341101), i = l(i, a, c, f, n[h + 14], 17, -1502002290), c = g(c, f = l(f, i, a, c, n[h + 15], 22, 1236535329), i, a, n[h + 1], 5, -165796510), a = g(a, c, f, i, n[h + 6], 9, -1069501632), i = g(i, a, c, f, n[h + 11], 14, 643717713), f = g(f, i, a, c, n[h], 20, -373897302), c = g(c, f, i, a, n[h + 5], 5, -701558691), a = g(a, c, f, i, n[h + 10], 9, 38016083), i = g(i, a, c, f, n[h + 15], 14, -660478335), f = g(f, i, a, c, n[h + 4], 20, -405537848), c = g(c, f, i, a, n[h + 9], 5, 568446438), a = g(a, c, f, i, n[h + 14], 9, -1019803690), i = g(i, a, c, f, n[h + 3], 14, -187363961), f = g(f, i, a, c, n[h + 8], 20, 1163531501), c = g(c, f, i, a, n[h + 13], 5, -1444681467), a = g(a, c, f, i, n[h + 2], 9, -51403784), i = g(i, a, c, f, n[h + 7], 14, 1735328473), c = v(c, f = g(f, i, a, c, n[h + 12], 20, -1926607734), i, a, n[h + 5], 4, -378558), a = v(a, c, f, i, n[h + 8], 11, -2022574463), i = v(i, a, c, f, n[h + 11], 16, 1839030562), f = v(f, i, a, c, n[h + 14], 23, -35309556), c = v(c, f, i, a, n[h + 1], 4, -1530992060), a = v(a, c, f, i, n[h + 4], 11, 1272893353), i = v(i, a, c, f, n[h + 7], 16, -155497632), f = v(f, i, a, c, n[h + 10], 23, -1094730640), c = v(c, f, i, a, n[h + 13], 4, 681279174), a = v(a, c, f, i, n[h], 11, -358537222), i = v(i, a, c, f, n[h + 3], 16, -722521979), f = v(f, i, a, c, n[h + 6], 23, 76029189), c = v(c, f, i, a, n[h + 9], 4, -640364487), a = v(a, c, f, i, n[h + 12], 11, -421815835), i = v(i, a, c, f, n[h + 15], 16, 530742520), c = m(c, f = v(f, i, a, c, n[h + 2], 23, -995338651), i, a, n[h], 6, -198630844), a = m(a, c, f, i, n[h + 7], 10, 1126891415), i = m(i, a, c, f, n[h + 14], 15, -1416354905), f = m(f, i, a, c, n[h + 5], 21, -57434055), c = m(c, f, i, a, n[h + 12], 6, 1700485571), a = m(a, c, f, i, n[h + 3], 10, -1894986606), i = m(i, a, c, f, n[h + 10], 15, -1051523), f = m(f, i, a, c, n[h + 1], 21, -2054922799), c = m(c, f, i, a, n[h + 8], 6, 1873313359), a = m(a, c, f, i, n[h + 15], 10, -30611744), i = m(i, a, c, f, n[h + 6], 15, -1560198380), f = m(f, i, a, c, n[h + 13], 21, 1309151649), c = m(c, f, i, a, n[h + 4], 6, -145523070), a = m(a, c, f, i, n[h + 11], 10, -1120210379), i = m(i, a, c, f, n[h + 2], 15, 718787259), f = m(f, i, a, c, n[h + 9], 21, -343485551), c = d(c, r), f = d(f, e), i = d(i, o), a = d(a, u);\n return [c, f, i, a]\n }\n\n function i(n) {\n for (var t = \"\", r = 32 * n.length, e = 0; e < r; e += 8) t += String.fromCharCode(n[e >> 5] >>> e % 32 & 255);\n return t\n }\n\n function a(n) {\n var t = [];\n for (t[(n.length >> 2) - 1] = void 0, e = 0; e < t.length; e += 1) t[e] = 0;\n for (var r = 8 * n.length, e = 0; e < r; e += 8) t[e >> 5] |= (255 & n.charCodeAt(e / 8)) << e % 32;\n return t\n }\n\n function e(n) {\n for (var t, r = \"0123456789abcdef\", e = \"\", o = 0; o < n.length; o += 1) t = n.charCodeAt(o), e += r.charAt(t >>> 4 & 15) + r.charAt(15 & t);\n return e\n }\n\n function r(n) {\n return unescape(encodeURIComponent(n))\n }\n\n function o(n) {\n return i(c(a(n = r(n)), 8 * n.length))\n }\n\n function u(n, t) {\n return function (n, t) {\n var r, e = a(n), o = [], u = [];\n for (o[15] = u[15] = void 0, 16 < e.length && (e = c(e, 8 * n.length)), r = 0; r < 16; r += 1) o[r] = 909522486 ^ e[r], u[r] = 1549556828 ^ e[r];\n return t = c(o.concat(a(t)), 512 + 8 * t.length), i(c(u.concat(t), 640))\n }(r(n), r(t))\n }\n\n function t(n, t, r) {\n return t ? r ? u(t, n) : e(u(t, n)) : r ? o(n) : e(o(n))\n }\n\n \"function\" == typeof define && define.amd ? define(function () {\n return t\n }) : \"object\" == typeof module && module.exports ? module.exports = t : n.md5 = t\n}(this);\nvar md5 = this.md5;\n/**\n 网关上线\n 订阅:/sys/hbtgIA0SuVw9lxjB/AA:BB:CC:DD:10/c/#\n\n 子设备注册:\n /sys/hbtgIA0SuVw9lxjB/AA:BB:CC:DD:10/s/register\n {\n \"id\": \"6\",\n \"params\":{\n \"productKey\":\"Rf4QSjbm65X45753\",\n \"deviceName\":\"ABC12400001\",\n \"model\":\"S1\"\n }\n }\n 子设备上线\n 订阅:/sys/Rf4QSjbm65X45753/ABC12400001/c/#\n\n 数据上报:\n /sys/Rf4QSjbm65X45753/ABC12400001/s/event/property/post\n {\n \"id\": \"6\",\n \"params\":{\n \"powerstate\": 1\n }\n }\n */\n\nvar registered = {};\n\nfunction getPkDn(clientId) {\n var arr = clientId.split(\"_\");\n return {\n pk: arr[0],\n dn: arr[1]\n };\n}\n\nfunction register(payload) {\n var auth = JSON.parse(payload);\n var arr = auth.clientid.split(\"_\");\n if (arr.length < 3) {\n throw new Error(\"incorrect clientid\");\n }\n\n var pk = arr[0];\n var dn = arr[1];\n var model = arr[2];\n\n var product = deviceBehaviour.getProductKey(pk)\n var pwd = md5(product.getProductSecret() + auth.clientid);\n\n if (pwd.toLocaleLowerCase() != auth.password.toLocaleLowerCase()) {\n throw new Error(\"incorrect password\" + \"pwd->\" + pwd + \" productSecret->\" + product.productSecret);\n }\n return {\n type: \"register\",\n data: {\n productKey: pk,\n deviceName: dn,\n model: model\n }\n };\n}\n\nfunction subRegister(topic, parent, payload) {\n var params = payload.params;\n var reply =\n {\n productKey: parent.productKey,\n deviceName: parent.deviceName,\n mid: \"0\",\n content: {\n topic: topic.replace(\"/s/\", \"/c/\") + \"_reply\",\n payload: JSON.stringify({\n id: \"0\",\n code: 0,\n data: {\n \"productKey\": params.productKey,\n \"deviceName\": params.deviceName\n }\n })\n }\n };\n\n return {\n type: \"register\",\n data: {\n productKey: parent.productKey,\n deviceName: parent.deviceName,\n subDevices: [{\n productKey: params.productKey,\n deviceName: params.deviceName,\n model: params.model\n }]\n },\n action: {\n type: \"ack\",\n content: JSON.stringify(reply)\n }\n };\n}\n\nfunction deviceStateChange(head, clientId, state) {\n var topic = head.topic;\n var device = getPkDn(clientId);\n\n var arr = topic.split('/');\n if (arr.length < 6) {\n throw new Error(\"incorrect topic\")\n }\n\n var pk = arr[2];\n var dn = arr[3];\n return {\n type: \"state\",\n data: {\n productKey: pk,\n deviceName: dn,\n state: state,\n parent: {\n productKey: device.pk,\n deviceName: device.dn,\n }\n }\n }\n}\n\nfunction disconnect(clientId) {\n var device = getPkDn(clientId);\n return {\n type: \"state\",\n data: {\n productKey: device.pk,\n deviceName: device.dn,\n state: \"offline\"\n }\n }\n}\n\nfunction ota(head, payload) {\n payload = JSON.parse(payload);\n var topic = head.topic;\n var arr = topic.split('/');\n if (arr.length < 6) {\n throw new Error(\"incorrect topic\")\n }\n\n var pk = arr[2];\n var dn = arr[3];\n return {\n type: \"ota\",\n data: {\n productKey: pk,\n deviceName: dn,\n mid: payload.id,\n content: {\n topic: topic,\n payload: payload\n }\n }\n }\n}\n\n//必须提供onReceive方法\nthis.onReceive = function (head, type, payload) {\n if (type == 'auth') {\n return register(payload);\n }\n\n if (type == 'subscribe') {\n return deviceStateChange(head, payload, 'online');\n }\n\n if (type == 'unsubscribe') {\n return deviceStateChange(head, payload, 'offline');\n }\n\n if (type == 'disconnect') {\n return disconnect(payload);\n }\n\n if (type == 'ota') {\n return ota(head, payload);\n }\n\n var topic = head['topic'];\n if (!topic) {\n throw new Error(\"topic is blank\")\n }\n\n var arr = topic.split('/');\n if (arr.length < 6) {\n throw new Error(\"incorrect topic\")\n }\n var pk = arr[2];\n var dn = arr[3];\n payload = JSON.parse(payload);\n\n //子设备注册\n if (topic.endsWith('/register')) {\n return subRegister(topic, {productKey: pk, deviceName: dn}, payload);\n }\n\n //数据上报\n var reply =\n {\n productKey: pk,\n deviceName: dn,\n mid: payload.id,\n content: {\n topic: topic.replace(\"/s/\", \"/c/\") + \"_reply\",\n payload: JSON.stringify({\n id: payload.id,\n method: payload.method + \"_reply\",\n code: 0,\n })\n }\n };\n\n var action = {};\n if (!topic.endsWith(\"_reply\")) {\n //需要回复的消息\n action = {\n type: \"ack\",\n content: JSON.stringify(reply)\n }\n }\n\n return {\n type: \"report\",\n data: {\n productKey: pk,\n deviceName: dn,\n mid: payload.id,\n content: {\n topic: topic,\n payload: payload\n }\n },\n action: action\n }\n}\n\nthis.onRegistered = function (regInfo, result) {\n}", - "scriptTyp": null, - "state": "stopped", - "type": "device", - "uid": "3" - } -] \ No newline at end of file diff --git a/data/init/protocolConverter.json b/data/init/protocolConverter.json deleted file mode 100755 index 465d1223..00000000 --- a/data/init/protocolConverter.json +++ /dev/null @@ -1,39 +0,0 @@ -[ - { - "id": "62995ba4dbf51a5ec41d5f7b", - "uid": "1", - "name": "自定义表计协议", - "desc": "用于燃气表的协议", - "createAt": 1654217636597 - }, - { - "id": "628ceb14addfdb2a3b4b5727", - "uid": "1", - "name": "奇特HTTP标准协议", - "desc": "奇特HTTP标准协议转换器", - "createAt": 1653402388275 - }, - { - "id": "6260396d67aced2696184053", - "uid": "1", - "name": "奇特MQTT标准协议", - "desc": "奇特MQTT标准协议转换器", - "createAt": 1650473325173 - }, - { - "id": "d7e84930-5460-4638-aa3f-e0c2015628f4", - "uid": "1", - "name": "WS标准协议", - "desc": "WS标准协议转换器", - "createAt": 1650473325173 - }, - { - "id": "50b0fdd0-9bc8-448d-a7cf-d3b1b4df944c", - "createAt": null, - "desc": null, - "name": "铱塔智联-NB透传单泵", - "script": "var mid = 1;\n\nfunction getMid() {\n mid++;\n if (mid > 10000) {\n mid = 1;\n }\n return mid + \"\";\n}\n//上行数据\nthis.decode = function (msg) {\n var content = msg.content;\n var topic = content.topic;\n var bytes = CRC.strToByte(content.payload);\n\n if (topic.endsWith(\"/thing/model/up_raw\")) {\n var byteData = ab2hex(bytes)\n var data = arrayGroup(byteData, 2);\n var params = {};\n var uint8Array = new Uint8Array(bytes.length);\n for (var i = 0; i < bytes.length; i++) {\n uint8Array[i] = bytes[i] & 0xff;\n }\n if (data[1] == '03') {\n if (byteData.length == 22 ) {\n params['Switch'] = Number(parseInt(data[3] + data[4], 16))\n params['HandMode'] = Number(parseInt(data[5] + data[6], 16))+1\n params['TempGear'] = Number(data[7].slice(1,2))+1\n params['RatioGear'] = Number(data[7].slice(0,1))+1\n params['PressureGear'] = data[8].slice(0,1) != 'f' ? Number(data[8].slice(0,1))+1 : 0\n params['SpeedGear'] = data[8].slice(1,2) != 'f' ? Number(data[8].slice(1,2))+1 : 0\n\n } else if (byteData.length == 126) {\n params['Pressure'] = Number((parseInt(data[3] + data[4], 16) / 100).toFixed(1))\n params['EmtyRunPressure'] = Number((parseInt(data[5] + data[6], 16) / 100).toFixed(1))\n params['StartPressure'] = Number((parseInt(data[7] + data[8], 16) / 100).toFixed(1))\n params['WorkMode'] = Number((parseInt(data[9] + data[10], 16)).toFixed(0))\n params['ClearIceEn'] = Number((parseInt(data[11] + data[12], 16)).toFixed(0))\n params['WaterT'] = Number((parseInt(data[13] + data[14], 16)).toFixed(0))\n params['WaterTReset'] = Number((parseInt(data[15] + data[16], 16)).toFixed(0))\n params['SensorMode'] = Number((parseInt(data[17] + data[18], 16)).toFixed(0))\n params['SensorGroup'] = Number((parseInt(data[19] + data[20], 16)).toFixed(0))\n params['ElectronicTMax'] = Number(parseInt(data[59], 16))\n params['ElectronicTMaxReset'] = Number(parseInt(data[60], 16))\n } else if (byteData.length == 26) {\n params['ActiveTime'] = String(parseInt(data[3], 16))+'-'+String(parseInt(data[4], 16))+'-'+String(parseInt(data[5], 16))\n }\telse if (byteData.length == 190) {\n params['Pressure'] = Number((parseInt(data[3] + data[4], 16) / 100).toFixed(1))\n params['EmtyRunPressure'] = Number((parseInt(data[5] + data[6], 16) / 100).toFixed(1))\n params['StartPressure'] = Number((parseInt(data[7] + data[8], 16) / 100).toFixed(1))\n params['WorkMode'] = Number((parseInt(data[9] + data[10], 16)).toFixed(0))\n params['ClearIceEn'] = Number((parseInt(data[11] + data[12], 16)).toFixed(0))\n params['WaterT'] = Number((parseInt(data[13] + data[14], 16)).toFixed(0))\n params['WaterTReset'] = Number((parseInt(data[15] + data[16], 16)).toFixed(0))\n params['SensorMode'] = Number((parseInt(data[17] + data[18], 16)).toFixed(0))\n params['SensorGroup'] = Number((parseInt(data[19] + data[20], 16)).toFixed(0))\n params['ElectronicTMax'] = Number(parseInt(data[59], 16))\n params['ElectronicTMaxReset'] = Number(parseInt(data[60], 16))\n params['SceneMode'] = Number((parseInt(data[63] + data[64], 16)).toFixed(0))\n params['EnergyModeTime'] = Number((parseInt(data[65] + data[66], 16)).toFixed(0))\n params['WaterTime'] = String(Number((parseInt(data[68].substring(0, 1), 16)).toFixed(0))) + ',' + String(Number((parseInt(data[68].substring(1), 16)).toFixed(0)))\n params['HotWaterTime'] = Number((parseInt(data[69] + data[70], 16)).toFixed(0))\n params['TempSet'] = String(Number((parseInt(data[71], 16)).toFixed(0)))+','+ String(Number((parseInt(data[72], 16)).toFixed(0)))\n params['TimeModeSet'] = parseInt(data[73] + data[74], 16)+'-'+parseInt(data[75] + data[76], 16)+','+ parseInt(data[77] + data[78], 16)+'-'+parseInt(data[79] + data[80], 16)+','+ parseInt(data[81] + data[82], 16)+'-'+parseInt(data[83] + data[84], 16)+','+ parseInt(data[85] + data[86], 16)+'-'+parseInt(data[87] + data[88], 16)+','+ parseInt(data[89] + data[90], 16)+'-'+parseInt(data[91] + data[92], 16)\n\n } else if (byteData.length == 94) {\n let timeStamp = parseInt(String(data[41])+String(data[42])+String(data[43])+String(data[44]),16)\n let time = timestampToTime(timeStamp)\n params['ActiveTime'] = String(parseInt(data[3], 16))+'-'+String(parseInt(data[4], 16))+'-'+String(parseInt(data[5], 16))\n params['Time'] = time + '-'+ timeStamp\n\n }\n } else if (data[1] == '04') {\n if (byteData.length == 54) {\n params['ErrorMsg'] = Number(parseInt(data[3]+data[4], 16))\n params['Voltage'] = Number(parseInt(data[5]+data[6], 16))\n params['Electric'] = Number(parseInt(data[7]+data[8], 16))/10\n params['Power'] = Number(parseInt(data[9]+data[10], 16))\n params['Speed'] = Number(parseInt(data[11]+data[12], 16))\n params['CurrentPressure1'] = data[13] != 'ff' ? Number((parseInt(data[13]+data[14], 16)/100).toFixed(1)) : 0\n params['CurrentPressure2'] = data[15] != 'ff' ? Number((parseInt(data[15]+data[16], 16)/100).toFixed(1)) : 0\n params['IpmTemperature'] = Number(parseInt(data[17]+data[18], 16))-55\n params['MotorTemperature'] = Number(parseInt(data[19]+data[20], 16))-55\n params['WaterTemperature'] = Number(parseInt(data[21]+data[22], 16))-55\n let warnArray = reverseStr(hex2bin(data[23] + data[24]))\n let warnInfo = \"\"\n for (let i = 0; i < warnArray.length; i++) {\n if (warnArray[i] === \"1\") {\n if (warnInfo === \"\") {\n warnInfo = DEVICE_ERROR[i]\n } else {\n warnInfo += `、${DEVICE_ERROR[i]}`\n }\n }\n }\n\n params['WarnInfo'] = warnInfo\n\n } else if (byteData.length == 18) {\n if (String(byteData) == '130404000800004847') {\n params['query'] = String(byteData)\n } else if (String(byteData).slice(9,10) == 3) {\n params['query'] = String(byteData)\n } else if (String(byteData).slice(9,10) == 4) {\n params['query'] = String(byteData)\n }\n } else if (byteData.length == 30) {\n params['McuVersion'] = String(Number(parseInt(data[3].slice(1,2), 16)))+'.'+String(Number(parseInt(data[4].slice(0,1), 16)))+'.'+String(Number(parseInt(data[4].slice(1,2), 16)))\n params['McuStatus'] = Number(parseInt(data[3].slice(0,1), 16))\n params['Scene'] = Number(parseInt(data[9]+data[10], 16))\n params['Model'] = String(Number(parseInt(data[11]+data[12], 16)))+'W'\n\n } else if (byteData.length == 66) {\n params['ErrorMsg'] = Number(parseInt(data[3]+data[4], 16))\n params['Voltage'] = Number(parseInt(data[5]+data[6], 16))\n params['Electric'] = Number(parseInt(data[7]+data[8], 16))/10\n params['Power'] = Number(parseInt(data[9]+data[10], 16))\n params['Speed'] = Number(parseInt(data[11]+data[12], 16))\n params['CurrentPressure1'] = data[13] != 'ff' ? Number((parseInt(data[13]+data[14], 16)/100).toFixed(1)) : 0\n params['CurrentPressure2'] = data[15] != 'ff' ? Number((parseInt(data[15]+data[16], 16)/100).toFixed(1)) : 0\n params['IpmTemperature'] = Number(parseInt(data[17]+data[18], 16))-55\n params['MotorTemperature'] = Number(parseInt(data[19]+data[20], 16))-55\n params['WaterTemperature'] = Number(parseInt(data[21]+data[22], 16))-55\n let warnArray = reverseStr(hex2bin(data[23] + data[24]))\n let warnInfo = \"\"\n for (let i = 0; i < warnArray.length; i++) {\n if (warnArray[i] === \"1\") {\n if (warnInfo === \"\") {\n warnInfo = DEVICE_ERROR[i]\n } else {\n warnInfo += `、${DEVICE_ERROR[i]}`\n }\n }\n }\n params['CountDown'] = Number(parseInt(data[25]+data[26], 16))\n params['WarnInfo'] = warnInfo\n params['Enabled'] = Number(parseInt(data[29]+data[30], 16))\n\n }\n }\n params['History'] = byteData\n //属性上报\n return {\n mid: msg.mid,\n productKey: msg.productKey,\n deviceName: msg.deviceName,\n type: \"property\",\n identifier: \"report\", //属性上报\n occur: new Date().getTime(), //时间戳,设备上的事件或数据产生的本地时间\n time: new Date().getTime(), //时间戳,消息上报时间\n data: params,\n };\n } else if (topic.indexOf(\"/event/\") > 0) {\n //事件上报\n } else if (topic.endsWith(\"/service/property/set_reply\")) {\n //属性设置回复\n } else if (topic.endsWith(\"/config/set_reply\")) {\n //设备配置设置回复\n } else if (topic.endsWith(\"/config/get\")) {\n //设备配置获取\n } else if (topic.endsWith(\"_reply\")) {\n //服务回复\n }\n return null;\n};\n\n//下行数据\nthis.encode = function (service, device) {\n var deviceMid = getMid();\n var method = \"thing.service.\";\n var topic = \"/sys/\" + service.productKey + \"/\" + service.deviceName + \"/thing/model/down_raw\";\n var params = {};\n\n var type = service.type;\n var identifier = service.identifier;\n if (type == \"property\" && identifier == \"get\") {\n var listParams = []\n for (var p in service.params) {\n listParams.push(service.params[p]);\n }\n return {\n productKey: service.productKey,\n deviceName: service.deviceName,\n mid: deviceMid,\n content: {\n topic: topic,\n payload: JSON.stringify({\n id: deviceMid,\n method: method += \"property.\" + identifier,\n params: listParams\n })\n }\n }\n } else if (type == \"property\" && identifier == \"set\") {\n for (var p in service.params) {\n params[p] = service.params[p];\n }\n //站地址\n if (paramsArr.includes('query')) {\n let queryHexData = arrayGroup(params['query'],2)\n let queryData = []\n queryHexData.map(function(value) {\n queryData.push(parseInt(value,16))\n })\n payloadArray = queryData\n } else {\n const stationAddress = \"49\";\n totalArray.push(stationAddress)\n //功能码\n var functionCode = \"\";\n // 寄存器数量\n var register = ''\n var baseVal = ''\n //起始地址\n var startAddressCode = '';\n if (paramsArr.length == 1) {\n functionCode = '06'\n totalArray.push(functionCode)\n } else {\n functionCode = '10'\n paramsArr = ['Pressure', 'EmtyRunPressure', 'StartPressure', 'WorkMode', 'ClearIceEn', 'WaterT', 'WaterTReset']\n totalArray.push(parseInt(Number(functionCode),16))\n }\n if (paramsArr.includes('Switch')) {\n startAddressCode = 300\n totalArray.push('01','44')\n } else if (paramsArr.includes('Pressure')) {\n startAddressCode = 400\n totalArray.push('01','144')\n register = '00' + add0(String(paramsArr.length),2) + add0(String((paramsArr.length*2).toString(16)),2)\n totalArray.push('00', add0(paramsArr.length,2), add0(String((paramsArr.length)*2),2))\n }\n if (functionCode == 6) {\n paramsArr.forEach(function(value){\n totalArray.push('00',params[value])\n itemArray = pad(params[value].toString(16),4)\n deviceArray.push(itemArray[0],itemArray[1])\n })\n } else if (functionCode == 10) {\n paramsArr.forEach(function(value, index){\n if (index < 3) {\n // if (params[value]*100 < 256) {\n // totalItemArray = ['00', String((params[value]*100).toFixed(0))]\n // itemArray = pad(String((params[value]*100).toString(16)),4)\n // totalItemArray = pad(String((params[value]*100).toFixed(0)),4)\n // } else {\n // outFFIndex = ((Number(params[value]*100))/256).toFixed(0)\n // totalItemArray = [outFFIndex, params[value]*100-outFFIndex*256]\n // }\n\n itemArray = pad(Number((params[value]*100).toFixed(0)).toString(16),4)\n totalItemArray = pad(String((params[value]*100).toFixed(0)),4)\n } else {\n itemArray = pad(String(params[value].toString(16)),4)\n totalItemArray = pad(String(params[value]),4)\n }\n // totalArray.push(params[value])\n // totalArray.push(totalItemArray[0],totalItemArray[1])\n totalArray.push(parseInt(itemArray[0],16),parseInt(itemArray[1],16))\n // deviceArray.push(parseInt(itemArray[0],16),parseInt(itemArray[1],16))\n deviceArray.push(itemArray[0],itemArray[1])\n\n })\n }\n\n var startAddressHex = pad(startAddressCode.toString(16), 4);\n baseVal = String(stationAddress) + String(functionCode) + String(startAddressHex[0]) + String(startAddressHex[1])\n if (functionCode != 6) {\n baseVal += register\n }\n deviceArray.forEach(function(item) {\n baseVal += item\n })\n // baseVal += '00070e0064000a00640001000100370037'\n var Crc = CRC.ToModbusCRC16(baseVal)\n var crcArray = arrayGroup(Crc,2)\n totalArray.push(parseInt(crcArray[0],16),parseInt(crcArray[1],16))\n payloadArray = totalArray;\n }\n // var params = json['params'];\n // var prop_float = params['prop_float'];\n // var prop_int16 = params['prop_int16'];\n // var prop_bool = params['prop_bool'];\n // //按照自定义协议格式拼接 rawData。\n // payloadArray = payloadArray.concat(buffer_uint8(COMMAND_SET)); //command字段。\n // payloadArray = payloadArray.concat(buffer_int32(parseInt(id))); //ALink JSON格式 'id'。\n // payloadArray = payloadArray.concat(buffer_int16(prop_int16)); //属性'prop_int16'的值。\n // payloadArray = payloadArray.concat(buffer_uint8(prop_bool)); //属性'prop_bool'的值。\n // payloadArray = payloadArray.concat(buffer_float32(prop_float)); //属性'prop_float'的值。\n\n }else if (method == 'thing.event.property.post') { //设备上报数据返回结果,如果不需要回复,可以去除该内容\n var code = json['code'];\n payloadArray = payloadArray.concat(buffer_uint8(COMMAND_REPORT_REPLY)); //command字段\n payloadArray = payloadArray.concat(buffer_int32(parseInt(id))); // ALink JSON格式 'id'\n payloadArray = payloadArray.concat(buffer_uint8(code));\n } else { //未知命令,对于有些命令不做处理\n var code = json['code'];\n payloadArray = payloadArray.concat(buffer_uint8(COMMAD_UNKOWN)); //command字段\n payloadArray = payloadArray.concat(buffer_int32(parseInt(id))); // ALink JSON格式 'id'\n payloadArray = payloadArray.concat(buffer_uint8(code));\n }\n return {\n productKey: service.productKey,\n deviceName: service.deviceName,\n mid: deviceMid,\n content: {\n topic: topic,\n payload: JSON.stringify({\n id: deviceMid,\n method: method += \"property.\" + identifier,\n params: payloadArray\n })\n }\n }\n};\n\n\nconst DEVICE_ERROR = [\n \"压力传感器故障\", //0\n \"高温限功率\", //1\n \"渗漏\", // 2\n \"电机温度传感器故障\", //3\n \"水温传感器故障\", //4\n \"保留\", //5\n \"保留\", //6\n \"保留\", //7\n \"保留\", //8\n \"保留\", //9\n \"保留\", //10\n \"保留\", //11\n \"保留\", //12\n \"保留\", //13\n \"保留\", //14\n \"保留\", // 15\n \"保留\", //16\n]\nfunction buffer_uint8(value) {\n var uint8Array = new Uint8Array(1);\n var dv = new DataView(uint8Array.buffer, 0);\n dv.setUint8(0, value);\n return [].slice.call(uint8Array);\n}\nfunction buffer_int16(value) {\n var uint8Array = new Uint8Array(2);\n var dv = new DataView(uint8Array.buffer, 0);\n dv.setInt16(0, value);\n return [].slice.call(uint8Array);\n}\nfunction buffer_int32(value) {\n var uint8Array = new Uint8Array(4);\n var dv = new DataView(uint8Array.buffer, 0);\n dv.setInt32(0, value);\n return [].slice.call(uint8Array);\n}\nfunction buffer_float32(value) {\n var uint8Array = new Uint8Array(4);\n var dv = new DataView(uint8Array.buffer, 0);\n dv.setFloat32(0, value);\n return [].slice.call(uint8Array);\n}\n\nfunction ab2hex(buffer) {\n var hexArr = Array.prototype.map.call(\n new Uint8Array(buffer),\n function (bit) {\n return ('00' + bit.toString(16)).slice(-2)\n }\n )\n return hexArr.join('');\n}\n\nfunction arrayGroup(ss, step) {\n var r = [];\n\n function doGroup(s) {\n if (!s) return;\n r.push(s.substr(0, step));\n s = s.substr(step);\n doGroup(s);\n }\n doGroup(ss);\n return r;\n}\n\nvar CRC = {};\n\nCRC._auchCRCHi = [\n 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,\n 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,\n 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,\n 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,\n 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,\n 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,\n 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,\n 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,\n 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,\n 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,\n 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,\n 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,\n 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,\n 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,\n 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,\n 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,\n 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,\n 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,\n 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,\n 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,\n 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,\n 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,\n 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,\n 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,\n 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,\n 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40\n];\nCRC._auchCRCLo = [\n 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06,\n 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD,\n 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,\n 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A,\n 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4,\n 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,\n 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3,\n 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,\n 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,\n 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29,\n 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED,\n 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,\n 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60,\n 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67,\n 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,\n 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,\n 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E,\n 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,\n 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71,\n 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92,\n 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,\n 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B,\n 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B,\n 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,\n 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42,\n 0x43, 0x83, 0x41, 0x81, 0x80, 0x40\n];\n\nCRC.CRC16 = function (buffer) {\n var hi = 0xff;\n var lo = 0xff;\n for (var i = 0; i < buffer.length; i++) {\n var idx = hi ^ buffer[i];\n hi = (lo ^ CRC._auchCRCHi[idx]);\n lo = CRC._auchCRCLo[idx];\n }\n return CRC.padLeft((hi << 8 | lo).toString(16).toUpperCase(), 4, '0');\n};\n\nCRC.isArray = function (arr) {\n return Object.prototype.toString.call(arr) === '[object Array]';\n};\n\nCRC.ToCRC16 = function (str) {\n return CRC.CRC16(CRC.isArray(str) ? str : CRC.strToByte(str));\n};\n\nCRC.ToModbusCRC16 = function (str) {\n return CRC.CRC16(CRC.isArray(str) ? str : CRC.strToHex(str));\n};\n\nCRC.strToByte = function (str) {\n var tmp = str.split(''),\n arr = [];\n for (var i = 0, c = tmp.length; i < c; i++) {\n var j = encodeURI(tmp[i]);\n if (j.length == 1) {\n arr.push(j.charCodeAt());\n } else {\n var b = j.split('%');\n for (var m = 1; m < b.length; m++) {\n arr.push(parseInt('0x' + b[m]));\n }\n }\n }\n return arr;\n};\n\nCRC.convertChinese = function (str) {\n var tmp = str.split(''),\n arr = [];\n for (var i = 0, c = tmp.length; i < c; i++) {\n var s = tmp[i].charCodeAt();\n if (s <= 0 || s >= 127) {\n arr.push(s.toString(16));\n } else {\n arr.push(tmp[i]);\n }\n }\n return arr;\n};\n\nCRC.filterChinese = function (str) {\n var tmp = str.split(''),\n arr = [];\n for (var i = 0, c = tmp.length; i < c; i++) {\n var s = tmp[i].charCodeAt();\n if (s > 0 && s < 127) {\n arr.push(tmp[i]);\n }\n }\n return arr;\n};\n\nCRC.strToHex = function (hex, isFilterChinese) {\n hex = isFilterChinese ? CRC.filterChinese(hex).join('') : CRC.convertChinese(hex).join('');\n\n //清除所有空格\n hex = hex.replace(/\\s/g, \"\");\n //若字符个数为奇数,补一个空格\n hex += hex.length % 2 != 0 ? \" \" : \"\";\n\n var c = hex.length / 2,\n arr = [];\n for (var i = 0; i < c; i++) {\n arr.push(parseInt(hex.substr(i * 2, 2), 16));\n }\n return arr;\n};\n\nCRC.padLeft = function (s, w, pc) {\n if (pc == undefined) {\n pc = '0';\n }\n for (var i = 0, c = w - s.length; i < c; i++) {\n s = pc + s;\n }\n return s;\n};\n\nfunction str2ab(str) {\n var buffer = new ArrayBuffer(str.length / 2); // 2 bytes for each char\n var dataView = new DataView(buffer);\n var str = str.split(\"\")\n var n = 0;\n for (var i = 0; i < str.length; i = i + 2) {\n dataView.setUint8(n, `0x${str[i]}${str[i+1]}`)\n n++;\n }\n return buffer;\n}\n\nfunction pad(num, n, flag = false) {\n var len = num.toString().length;\n while (len < n) {\n num = \"0\" + num;\n len++;\n }\n\n const arr = arrayGroup(num, 2)\n //高低位互换\n if (arr[1] == '00') {\n flag = true\n }\n return flag ? [arr[1], arr[0]] : [arr[0], arr[1]];\n}\n\nfunction add0(num,n) {\n let len = num.length\n while(len < n){\n num = '0'+num\n len++\n }\n if (len > n) {\n num = String(num).slice(1)\n }\n //console.log(num)\n return num\n}\n\nfunction hex2bin(hex, len) {\n var bin = parseInt(hex, 16).toString(2);\n var l = bin.length;\n for (var i = 0; i < len - l; i++) {\n bin = \"0\" + bin;\n }\n return bin;\n}\n\n//翻转字符串并切割成数组\nfunction reverseStr(str) {\n var arr = str.split(\"\");\n arr.reverse();\n return arr;\n}\n\nfunction timestampToTime(timestamp) {\n var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000\n var Y = date.getFullYear() + '-';\n var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';\n var D = date.getDate() + ' ';\n var h = date.getHours() + ':';\n var m = date.getMinutes() + ':';\n var s = date.getSeconds();\n return Y+M+D+h+m+s;\n}", - "typ": "js", - "uid": null - } -] \ No newline at end of file diff --git a/iot-common/iot-common-core/pom.xml b/iot-common/iot-common-core/pom.xml deleted file mode 100644 index 8c71d575..00000000 --- a/iot-common/iot-common-core/pom.xml +++ /dev/null @@ -1,128 +0,0 @@ - - - 4.0.0 - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - - iot-common-core - - - 此模块为通用业务逻辑或工具类 - - - - - commons-codec - commons-codec - - - - commons-io - commons-io - - - - org.bouncycastle - bcprov-jdk15on - - - - - com.fasterxml.jackson.core - jackson-core - - - - com.fasterxml.jackson.core - jackson-databind - - - - commons-beanutils - commons-beanutils - - - - - org.springframework - spring-context-support - - - - - org.apache.commons - commons-lang3 - - - - cn.hutool - hutool-core - - - - cn.hutool - hutool-http - - - - cn.hutool - hutool-extra - - - - cn.hutool - hutool-json - provided - - - - io.github.linpeilie - mapstruct-plus-spring-boot-starter - - - - jakarta.validation - jakarta.validation-api - - - - javax.validation - validation-api - - - - org.slf4j - slf4j-api - - - - org.lionsoul - ip2region - - - - org.projectlombok - lombok - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/BaseDto.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/BaseDto.java deleted file mode 100644 index 33925e1e..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/BaseDto.java +++ /dev/null @@ -1,45 +0,0 @@ -package cc.iotkit.common.api; - -import cc.iotkit.common.utils.MapstructUtils; -import lombok.Data; - -import java.util.Date; - -/** - * Entity基类 - * - * @author Lion Li - */ -@Data -public class BaseDto { - - /** - * 创建部门 - */ - - 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-common/iot-common-core/src/main/java/cc/iotkit/common/api/PageRequest.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/PageRequest.java deleted file mode 100644 index 266805b0..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/PageRequest.java +++ /dev/null @@ -1,92 +0,0 @@ -package cc.iotkit.common.api; - -import cc.iotkit.common.utils.MapstructUtils; -import cn.hutool.core.util.IdUtil; -import jakarta.validation.constraints.Max; -import jakarta.validation.constraints.Min; -import jakarta.validation.constraints.NotNull; - -import java.util.Map; - -import lombok.*; - -import java.io.Serializable; -import java.util.Objects; - -/** - * @author: Longjun.Tu - * @description: - * @date:created in 2023/5/10 23:15 - * @modificed by: - */ -@EqualsAndHashCode(callSuper = true) -@Data -@AllArgsConstructor -@NoArgsConstructor -@Builder -public class PageRequest extends Request implements Serializable { - - /** - * 分页大小 - */ - @Min(1) - @NotNull - private Integer pageSize; - - /** - * 当前页数 - */ - @Min(1) - @Max(100) - @NotNull - private Integer pageNum; - - /** - * 排序 key为排序字段名 value为排序方向方向desc或者asc - */ - private Map sortMap; - - /** - * 当前记录起始索引 默认值 - */ - public static final int DEFAULT_PAGE_NUM = 1; - - /** - * 每页显示记录数 默认值 - */ - public static final int DEFAULT_PAGE_SIZE = 20; - - - public static PageRequest of(T data) { - PageRequest pageRequest = new PageRequest<>(); - pageRequest.setPageSize(DEFAULT_PAGE_SIZE); - pageRequest.setPageNum(DEFAULT_PAGE_NUM); - pageRequest.setData(data); - pageRequest.setRequestId(IdUtil.simpleUUID()); - return pageRequest; - } - - public PageRequest to(Class dtoClass) { - PageRequest pageRequest = new PageRequest<>(); - if (Objects.nonNull(getData())) { - pageRequest.setData(MapstructUtils.convert(getData(), dtoClass)); - } - pageRequest.setPageNum(this.getPageNum()); - pageRequest.setPageSize(this.getPageSize()); - pageRequest.setRequestId(this.getRequestId()); - pageRequest.setSortMap(this.getSortMap()); - return pageRequest; - } - - public Integer getPageSize() { - return pageSize == null ? DEFAULT_PAGE_SIZE : pageSize; - } - - public Integer getPageNum() { - return pageNum == null ? DEFAULT_PAGE_NUM : pageNum; - } - - public Integer getOffset() { - return (getPageNum() - 1) * getPageSize(); - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/PageRequestEmpty.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/PageRequestEmpty.java deleted file mode 100644 index 44aaf6e4..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/PageRequestEmpty.java +++ /dev/null @@ -1,15 +0,0 @@ -package cc.iotkit.common.api; - -import lombok.Data; - -/** - * @author: Longjun.Tu - * @description: - * @date:created in 2023/5/10 23:16 - * @modificed by: - */ -@Data -public class PageRequestEmpty { - private Integer pageNum = 1; - private Integer pageSize = 20; -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Paging.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Paging.java deleted file mode 100644 index 77ca1bda..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Paging.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.api; - -import cc.iotkit.common.utils.MapstructUtils; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Paging { - - private long total; - - private List rows; - - public Paging to(Class voClass) { - return MapstructUtils.convert(this, voClass); - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Request.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Request.java deleted file mode 100644 index ee5c746e..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Request.java +++ /dev/null @@ -1,29 +0,0 @@ -package cc.iotkit.common.api; - -import cn.hutool.core.util.IdUtil; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -import java.io.Serializable; - -/** - * @author: Longjun.Tu - * @description: - * @date:created in 2023/5/10 23:14 - * @modificed by: - */ -@Data -public class Request extends RequestEmpty implements Serializable { - - @Valid - @NotNull - private T data; - - public static Request of(T data) { - Request request = new Request<>(); - request.setData(data); - request.setRequestId(IdUtil.simpleUUID()); - return request; - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/RequestEmpty.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/RequestEmpty.java deleted file mode 100644 index bd2891d0..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/RequestEmpty.java +++ /dev/null @@ -1,27 +0,0 @@ -package cc.iotkit.common.api; - -import cn.hutool.core.util.IdUtil; -import jakarta.validation.constraints.NotBlank; -import lombok.Data; - -import java.io.Serializable; - -/** - * @author: Longjun.Tu - * @description: - * @date:created in 2023/5/10 23:12 - * @modificed by: - */ -@Data -public class RequestEmpty implements Serializable { - - @NotBlank - private String requestId; - - public static RequestEmpty of() { - RequestEmpty request = new RequestEmpty(); - request.setRequestId(IdUtil.simpleUUID()); - return request; - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Response.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Response.java deleted file mode 100644 index b8b10585..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Response.java +++ /dev/null @@ -1,15 +0,0 @@ -package cc.iotkit.common.api; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Response { - private Integer code; - private String message; - private Object data; - private String requestId; -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/CacheConstants.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/CacheConstants.java deleted file mode 100644 index c6d8fea9..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/CacheConstants.java +++ /dev/null @@ -1,25 +0,0 @@ -package cc.iotkit.common.constant; - -/** - * 缓存的key 常量 - * - * @author Lion Li - */ -public interface CacheConstants { - - /** - * 在线用户 redis key - */ - String ONLINE_TOKEN_KEY = "online_tokens:"; - - /** - * 参数管理 cache key - */ - String SYS_CONFIG_KEY = "sys_config:"; - - /** - * 字典管理 cache key - */ - String SYS_DICT_KEY = "sys_dict:"; - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/CacheNames.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/CacheNames.java deleted file mode 100644 index de593f7d..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/CacheNames.java +++ /dev/null @@ -1,63 +0,0 @@ -package cc.iotkit.common.constant; - -/** - * 缓存组名称常量 - *

- * key 格式为 cacheNames#ttl#maxIdleTime#maxSize - *

- * ttl 过期时间 如果设置为0则不过期 默认为0 - * maxIdleTime 最大空闲时间 根据LRU算法清理空闲数据 如果设置为0则不检测 默认为0 - * maxSize 组最大长度 根据LRU算法清理溢出数据 如果设置为0则无限长 默认为0 - *

- * 例子: test#60s、test#0#60s、test#0#1m#1000、test#1h#0#500 - * - * @author Lion Li - */ -public interface CacheNames { - - /** - * 演示案例 - */ - String DEMO_CACHE = "demo:cache#60s#10m#20"; - - /** - * 系统配置 - */ - String SYS_CONFIG = "sys_config"; - - /** - * 数据字典 - */ - String SYS_DICT = "sys_dict"; - - /** - * 租户 - */ - String SYS_TENANT = GlobalConstants.GLOBAL_REDIS_KEY + "sys_tenant#30d"; - - /** - * 用户账户 - */ - String SYS_USER_NAME = "sys_user_name#30d"; - - /** - * 部门 - */ - String SYS_DEPT = "sys_dept#30d"; - - /** - * OSS内容 - */ - String SYS_OSS = "sys_oss#30d"; - - /** - * OSS配置 - */ - String SYS_OSS_CONFIG = "sys_oss_config"; - - /** - * 在线用户 - */ - String ONLINE_TOKEN = "online_tokens"; - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/Constants.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/Constants.java deleted file mode 100644 index 15a3a1ad..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/Constants.java +++ /dev/null @@ -1,282 +0,0 @@ -package cc.iotkit.common.constant; - -/** - * 通用常量信息 - * - * @author ruoyi - */ -public interface Constants { - - /** - * UTF-8 字符集 - */ - String UTF8 = "UTF-8"; - - /** - * GBK 字符集 - */ - String GBK = "GBK"; - - /** - * www主域 - */ - String WWW = "www."; - - /** - * http请求 - */ - String HTTP = "http://"; - - /** - * https请求 - */ - String HTTPS = "https://"; - - /** - * 通用成功标识 - */ - String SUCCESS = "0"; - - /** - * 通用失败标识 - */ - String FAIL = "1"; - - /** - * 登录成功 - */ - String LOGIN_SUCCESS = "Success"; - - /** - * 注销 - */ - String LOGOUT = "Logout"; - - /** - * 注册 - */ - String REGISTER = "Register"; - - /** - * 登录失败 - */ - String LOGIN_FAIL = "Error"; - - /** - * 验证码有效期(分钟) - */ - Integer CAPTCHA_EXPIRATION = 2; - - String ACCOUNT_SECRET = "3n1z33kzvpgz1foijpkepyd3e8tw84us"; - - String CACHE_PRODUCT = "product_cache"; - - String CACHE_DEVICE_INFO = "device_info_cache"; - - String CACHE_DEVICE_STATS = "device_stats_cache"; - - String CACHE_CATEGORY = "category_cache"; - - String CACHE_SPACE = "space_cache"; - - String CACHE_THING_MODEL = "thing_model_cache"; - - String CACHE_USER_INFO = "user_info_cache"; - - String CACHE_OAUTH_CLIENT = "oauth_client_cache"; - - String CACHE_PRODUCT_SCRIPT = "product_script_cache"; - - /** - * 管理员角色 - */ - String ROLE_ADMIN = "iot_admin"; - - /** - * 可写角色 - */ - String ROLE_WRITE = "iot_write"; - - /** - * 管理系统用户角色 - */ - String ROLE_SYSTEM = "iot_system"; - - /** - * C端用户角色 - */ - String ROLE_CLIENT = "iot_client"; - - /** - * C端用户默认密码 - */ - String PWD_CLIENT_USER = "c123456"; - - /** - * 系统用户默认密码 - */ - String PWD_SYSTEM_USER = "s123456"; - - /** - * 设备物模型消息的topic - */ - String THING_MODEL_MESSAGE_TOPIC = "device_thing"; - - /** - * 设备属性上报消息的topic - */ - String DEVICE_PROPERTY_REPORT_TOPIC = "device_property_report"; - - /** - * 设备配置消息topic - */ - String DEVICE_CONFIG_TOPIC = "device_config"; - - /** - * http消费设备信息的topic - */ - String HTTP_CONSUMER_DEVICE_INFO_TOPIC = "device_info:"; - - /** - * 写权限 - */ - String PERMISSION_WRITE = "write"; - - /** - * 设备属性缓存key - */ - String PROPERTY_CACHE_KEY = "str:iotkit:device:property:%s"; - - /** - * 三方平台类型 - */ - enum ThirdPlatform { - dueros("小度"), - aligenie("天猫精灵"), - miiot("小爱"); - - public String desc; - - ThirdPlatform(String desc) { - this.desc = desc; - } - } - - /** - * 三方平台openUid名称 - */ - enum ThirdOpenUid { - duerosOpenUid("小度OpenUid"), - aligenieOpenUid("天猫精灵OpenUid"), - miiotOpenUid("小爱OpenUid"); - - public String desc; - - ThirdOpenUid(String desc) { - this.desc = desc; - } - } - - interface API_DEVICE { - - /** - * 设备-基路径 - */ - String BASE = "/device"; - - /** - * 设备-设备列表 - */ - String LIST = "/list/{size}/{page}"; - - /** - * 设备-设备详情 - */ - String DETAIL = "/{deviceId}/detail"; - - /** - * 设备-属性设置 - */ - String SET_PROPERTIES = "/{deviceId}/service/property/set"; - - /** - * 设备-服务调用 - */ - String INVOKE_SERVICE = "/{deviceId}/service/{service}/invoke"; - /** - * 设备-属性获取 - */ - String INVOKE_SERVICE_PROPERTY_GET = "/service/property/get"; - - /** - * OTA升级 - */ - String OTA_UPGRADE_PACKAGE = "{deviceId}/ota/upgrade/package/"; - - /** - * OTA升级进度上报 - */ - String OTA_UPGRADE_INFORM = "{deviceId}/ota/upgrade/inform/"; - - } - - interface API_SPACE { - - /** - * 空间-基路径 - */ - String BASE = "/space"; - - /** - * 最近使用设备列表 - */ - String RECENT_DEVICES = "/myRecentDevices"; - - /** - * 获取用户当前收藏设备 - */ - String GET_COLLECT_DEVICES = "/getCollectDevices"; - - /** - * 我的空间设备列表 - */ - String SPACE_DEVICES = "/myDevices/{spaceId}"; - - /** - * 查找设备 - */ - String FIND_DEVICE = "/findDevice"; - - /** - * 空间添加设备 - */ - String ADD_DEVICE = "/addDevice"; - - /** - * 空间删除设备 - */ - String REMOVE_DEVICE = "/removeDevice"; - - /** - * 空间修改设备 - */ - String SAVE_DEVICE = "/saveDevice"; - - /** - * 收藏/取消收藏设备 - */ - String COLLECT_DEVICE = "/collectDevice"; - - /** - * 获取空间设备信息 - */ - String GET_DEVICE = "/device/{deviceId}"; - - /** - * 设置第三方平台openUid - */ - String SET_OPEN_UID = "/setOpenUid"; - } - -} - diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/GlobalConstants.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/GlobalConstants.java deleted file mode 100644 index d48c886a..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/GlobalConstants.java +++ /dev/null @@ -1,34 +0,0 @@ -package cc.iotkit.common.constant; - -/** - * 全局的key常量 (业务无关的key) - * - * @author Lion Li - */ -public interface GlobalConstants { - - /** - * 全局 redis key (业务无关的key) - */ - String GLOBAL_REDIS_KEY = "global:"; - - /** - * 验证码 redis key - */ - String CAPTCHA_CODE_KEY = GLOBAL_REDIS_KEY + "captcha_codes:"; - - /** - * 防重提交 redis key - */ - String REPEAT_SUBMIT_KEY = GLOBAL_REDIS_KEY + "repeat_submit:"; - - /** - * 限流 redis key - */ - String RATE_LIMIT_KEY = GLOBAL_REDIS_KEY + "rate_limit:"; - - /** - * 登录账户密码错误次数 redis key - */ - String PWD_ERR_CNT_KEY = GLOBAL_REDIS_KEY + "pwd_err_cnt:"; -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/HttpStatus.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/HttpStatus.java deleted file mode 100644 index 24cbcaba..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/HttpStatus.java +++ /dev/null @@ -1,93 +0,0 @@ -package cc.iotkit.common.constant; - -/** - * 返回状态码 - * - * @author Lion Li - */ -public interface HttpStatus { - /** - * 操作成功 - */ - int SUCCESS = 200; - - /** - * 对象创建成功 - */ - int CREATED = 201; - - /** - * 请求已经被接受 - */ - int ACCEPTED = 202; - - /** - * 操作已经执行成功,但是没有返回数据 - */ - int NO_CONTENT = 204; - - /** - * 资源已被移除 - */ - int MOVED_PERM = 301; - - /** - * 重定向 - */ - int SEE_OTHER = 303; - - /** - * 资源没有被修改 - */ - int NOT_MODIFIED = 304; - - /** - * 参数列表错误(缺少,格式不匹配) - */ - int BAD_REQUEST = 400; - - /** - * 未授权 - */ - int UNAUTHORIZED = 401; - - /** - * 访问受限,授权过期 - */ - int FORBIDDEN = 403; - - /** - * 资源,服务未找到 - */ - int NOT_FOUND = 404; - - /** - * 不允许的http方法 - */ - int BAD_METHOD = 405; - - /** - * 资源冲突,或者资源被锁 - */ - int CONFLICT = 409; - - /** - * 不支持的数据,媒体类型 - */ - int UNSUPPORTED_TYPE = 415; - - /** - * 系统内部错误 - */ - int ERROR = 500; - - /** - * 接口未实现 - */ - int NOT_IMPLEMENTED = 501; - - /** - * 系统警告消息 - */ - int WARN = 601; -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/TenantConstants.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/TenantConstants.java deleted file mode 100644 index f22fbf85..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/TenantConstants.java +++ /dev/null @@ -1,45 +0,0 @@ -package cc.iotkit.common.constant; - -/** - * 租户常量信息 - * - * @author Lion Li - */ -public interface TenantConstants { - - /** - * 租户正常状态 - */ - String NORMAL = "0"; - - /** - * 租户封禁状态 - */ - String DISABLE = "1"; - - /** - * 超级管理员ID - */ - Long SUPER_ADMIN_ID = 1L; - - /** - * 超级管理员角色 roleKey - */ - String SUPER_ADMIN_ROLE_KEY = "superadmin"; - - /** - * 租户管理员角色 roleKey - */ - String TENANT_ADMIN_ROLE_KEY = "admin"; - - /** - * 租户管理员角色名称 - */ - String TENANT_ADMIN_ROLE_NAME = "管理员"; - - /** - * 默认租户ID - */ - String DEFAULT_TENANT_ID = "000000"; - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/UserConstants.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/UserConstants.java deleted file mode 100644 index 699c09bd..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/constant/UserConstants.java +++ /dev/null @@ -1,132 +0,0 @@ -package cc.iotkit.common.constant; - -/** - * 用户常量信息 - * - * @author ruoyi - */ -public interface UserConstants { - - /** - * 平台内系统用户的唯一标志 - */ - String SYS_USER = "SYS_USER"; - - /** - * 正常状态 - */ - String NORMAL = "0"; - - /** - * 异常状态 - */ - String EXCEPTION = "1"; - - /** - * 用户正常状态 - */ - String USER_NORMAL = "0"; - - /** - * 用户封禁状态 - */ - String USER_DISABLE = "1"; - - /** - * 角色正常状态 - */ - String ROLE_NORMAL = "0"; - - /** - * 角色封禁状态 - */ - String ROLE_DISABLE = "1"; - - /** - * 部门正常状态 - */ - String DEPT_NORMAL = "0"; - - /** - * 部门停用状态 - */ - String DEPT_DISABLE = "1"; - - /** - * 字典正常状态 - */ - String DICT_NORMAL = "0"; - - /** - * 是否为系统默认(是) - */ - String YES = "Y"; - - /** - * 是否菜单外链(是) - */ - String YES_FRAME = "0"; - - /** - * 是否菜单外链(否) - */ - String NO_FRAME = "1"; - - /** - * 菜单正常状态 - */ - String MENU_NORMAL = "0"; - - /** - * 菜单停用状态 - */ - String MENU_DISABLE = "1"; - - /** - * 菜单类型(目录) - */ - String TYPE_DIR = "M"; - - /** - * 菜单类型(菜单) - */ - String TYPE_MENU = "C"; - - /** - * 菜单类型(按钮) - */ - String TYPE_BUTTON = "F"; - - /** - * Layout组件标识 - */ - String LAYOUT = "Layout"; - - /** - * ParentView组件标识 - */ - String PARENT_VIEW = "ParentView"; - - /** - * InnerLink组件标识 - */ - String INNER_LINK = "InnerLink"; - - /** - * 用户名长度限制 - */ - int USERNAME_MIN_LENGTH = 2; - int USERNAME_MAX_LENGTH = 20; - - /** - * 密码长度限制 - */ - int PASSWORD_MIN_LENGTH = 5; - int PASSWORD_MAX_LENGTH = 20; - - /** - * 超级管理员ID - */ - Long SUPER_ADMIN_ID = 1L; - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/DeviceType.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/DeviceType.java deleted file mode 100644 index 829175bc..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/DeviceType.java +++ /dev/null @@ -1,32 +0,0 @@ -package cc.iotkit.common.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 设备类型 - * 针对一套 用户体系 - * - * @author Lion Li - */ -@Getter -@AllArgsConstructor -public enum DeviceType { - - /** - * pc端 - */ - PC("pc"), - - /** - * app端 - */ - APP("app"), - - /** - * 小程序端 - */ - XCX("xcx"); - - private final String device; -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/ErrCode.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/ErrCode.java deleted file mode 100644 index 2934d794..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/ErrCode.java +++ /dev/null @@ -1,133 +0,0 @@ -package cc.iotkit.common.enums; - -/** - * @author :tfd - * 异常枚举类 - */ -public enum ErrCode implements IEnum { - /** - * 系统通用异常段 - */ - PARAMS_EXCEPTION(10000001, "参数异常"), - SYSTEM_EXCEPTION(10000002, "系统异常"), - UNKNOWN_EXCEPTION(10000003, "未知异常"), - SYSTEM_ERROR(10000004, "服务器内部错误"), - METHOD_NOT_ALLOWED(10000005, "请求方法不支持"), - NOT_FOUND(10000006, "请求资源不存在"), - FORBIDDEN(10000007, "请求被拒绝"), - UNAUTHORIZED_EXCEPTION(10000008, "未授权访问"), - UNSUPPORTED_OPERATION_EXCEPTION(10000009, "方法未实现"), - DATA_NOT_EXIST(10000010, "数据不存在"), - - /** - * openapi通用异常段 - */ - IDENTIFIER_ERROR(20000000, "签名验证失败"), - API_LOGIN_ERROR(20000000, "登录验证失败"), - - - /** - * 组件通用异常段 - */ - GET_COMPONENT_INSTANCE_ERROR(30000001, "获取通讯组件实例失败"), - GET_COMPONENT_SCRIPT_ERROR(30000002, "获取通讯组件脚本失败"), - GET_CONVERT_ERROR(30000003, "获取转换器失败"), - GET_SPI_COMPONENT_ERROR(30000004, "获取组件CLASS失败"), - GET_SPI_CONVERT_ERROR(30000005, "获取转换器CLASS失败"), - COMPONENT_NOT_FOUND(30000006, "通讯组件不存在"), - SEND_DESTINATION_NOT_FOUND(30000007, "发送目标不存在"), - MSG_CONVERT_ERROR(30000008, "消息转换失败"), - DEVICE_REGISTER_ERROR(30000009, "设备注册失败"), - COMPONENT_ID_BLANK(30000010, "通讯组件ID为空"), - COMPONENT_JAR_NOT_FOUND(30000011, "通讯组件JAR包为空"), - COMPONENT_ALREADY(30000012, "通讯组件已经存在"), - SAVE_COMPONENT_SCRIPT_ERROR(30000013, "保存通讯组件脚本失败"), - SAVE_CONVERT_SCRIPT_ERROR(30000014, "保存转换器脚本失败"), - ADD_COMPONENT_ERROR(30000015, "添加通讯组件失败"), - ADD_CONVERT_ERROR(30000016, "添加转换器失败"), - CONVERT_NOT_FOUND(30000017, "转换器不存在"), - DELETE_CONVERT_ERROR(30000018, "删除转换器失败"), - DELETE_COMPONENT_ERROR(30000019, "删除通讯组件失败"), - PRODUCT_SECRET_ERROR(30000020, "产品密钥错误"), - COMPONENT_START_ERROR(30000021, "通讯组件启动失败"), - INIT_PRODUCER_ERROR(30000022, "初始化MQ生产者失败"), - SEND_MSG_ERROR(30000023, "发送消息失败"), - PLUGIN_ROUTER_NOT_FOUND(30000100, "未找到插件路由"), - PLUGIN_INSTANCE_NOT_FOUND(30000101, "插件实例未找到"), - PLUGIN_SERVICE_NOT_FOUND(30000102, "插件设备服务未找到"), - PLUGIN_INSTALL_FAILED(30000103, "插件安装失败"), - DEVICE_ACTION_FAILED(30000200, "设备动作执行失败"), - - - /** - * 大屏通用异常段 - */ - RESOURCE_FILE_NOT_FOUND(40000000, "资源包为空"), - BIG_SCREEN_NOT_FOUND(40000001, "大屏不存在"), - BIG_SCREEN_ALREADY(40000002, "大屏已存在"), - ADD_BIG_SCREEN_ERROR(40000003, "保存大屏失败"), - DELETE_BIG_SCREEN_ERROR(40000004, "删除大屏资源失败"), - SCREEN_API_NOT_FOUND(40000005, "大屏接口不存在"), - ADD_SCREEN_API_ERROR(40000006, "添加大屏接口失败"), - SCREEN_PUBLISH_ERROR(40000007, "大屏发布失败"), - API_LIST_BLANK(40000008, "接口列表为空"), - - /** - * 业务通用异常段 - */ - ID_BLANK(50000001, "ID为空"), - TASK_NOT_SUPPORT_RENEW(50000002, "任务不支持续订"), - GROUP_ALREADY(50000003, "分组已经存在"), - GROUP_NOT_FOUND(50000004, "分组不存在"), - PRODUCT_NOT_FOUND(50000005, "产品不存在"), - DEVICE_NOT_FOUND(50000006, "设备不存在"), - DEVICE_OFFLINE(50000007, "设备已离线"), - DEVICE_ALREADY(50000008, "设备已存在"), - MODEL_DEVICE_ALREADY(50000009, "设备DN已存在"), - - DEVICE_HAS_ASSOCIATED(50000010, "设备已关联"), - MODEL_ALREADY(50000011, "型号已存在"), - MODEL_SCRIPT_NOT_FOUND(50000012, "产品型号脚本不存在"), - PRODUCT_MODEL_NOT_FOUND(50000013, "产品型号不存在"), - FILE_NOT_FOUND(50000014, "文件不存在"), - RULE_NOT_FOUND(50000015, "规则不存在"), - RULE_ALREADY_RUNNING(50000016, "规则已运行"), - SEND_REQUEST_ERROR(50000017, "发送请求失败"), - TASK_NOT_FOUND(50000018, "任务不存在"), - RENEW_TASK_ERROR(50000019, "重启任务失败"), - HOME_NOT_FOUND(50000020, "家庭不存在"), - CURRENT_HOME_NOT_FOUND(50000021, "当前家庭不存在"), - SPACE_NOT_FOUND(50000022, "空间不存在"), - SPACE_DEVICE_NOT_FOUND(50000023, "空间设备不存在"), - DATA_BLANK(50000024, "数据为空"), - DATA_LENGTH_ERROR(50000025, "数据长度错误"), - DATA_FORMAT_ERROR(50000026, "数据格式错误"), - USER_NOT_FOUND(50000027, "用户不存在"), - RESET_PWD_ERROR(50000028, "重置密码失败"), - UPDATE_PWD_ERROR(50000029, "修改密码失败"), - PWD_ERROR(50000030, "密码错误"), - STATE_ERROR(50000031, "状态错误"), - RECORD_NOT_FOUND(50000032, "记录不存在"), - ADD_PLATFORM_USER_ERROR(50000033, "添加平台用户失败"), - UPLOAD_FILE_ERROR(50000034, "上传文件失败"), - FILE_NAME_IS_NULL(50000035, "文件名为空,获取文件名失败"); - - - private int code; - private String message; - - ErrCode(int code, String message) { - this.code = code; - this.message = message; - } - - @Override - public Integer getKey() { - return this.code; - } - - @Override - public String getValue() { - return this.message; - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/IEnum.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/IEnum.java deleted file mode 100644 index 0b079e01..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/IEnum.java +++ /dev/null @@ -1,33 +0,0 @@ -package cc.iotkit.common.enums; - -public interface IEnum { - /** - * 获取枚举的key - */ - Integer getKey(); - - /** - * 获取枚举的下标 - */ - String getValue(); - - /** - * 将参数反序列化为枚举 - * - * @param param 当前值 - * @param clazz 枚举类型 - */ - static & IEnum> T parse(Integer param, Class clazz) { - if (param == null || clazz == null) { - return null; - } - T[] enums = clazz.getEnumConstants(); - for (T t : enums) { - Integer key = t.getKey(); - if (key.equals(param)) { - return t; - } - } - return null; - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/LoginType.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/LoginType.java deleted file mode 100644 index b566a64b..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/LoginType.java +++ /dev/null @@ -1,44 +0,0 @@ -package cc.iotkit.common.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 登录类型 - * - * @author Lion Li - */ -@Getter -@AllArgsConstructor -public enum LoginType { - - /** - * 密码登录 - */ - PASSWORD("user.password.retry.limit.exceed", "user.password.retry.limit.count"), - - /** - * 短信登录 - */ - SMS("sms.code.retry.limit.exceed", "sms.code.retry.limit.count"), - - /** - * 邮箱登录 - */ - EMAIL("email.code.retry.limit.exceed", "email.code.retry.limit.count"), - - /** - * 小程序登录 - */ - XCX("", ""); - - /** - * 登录重试超出限制提示 - */ - final String retryLimitExceed; - - /** - * 登录重试限制计数提示 - */ - final String retryLimitCount; -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/UserStatus.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/UserStatus.java deleted file mode 100644 index 61ae8299..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/UserStatus.java +++ /dev/null @@ -1,30 +0,0 @@ -package cc.iotkit.common.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 用户状态 - * - * @author ruoyi - */ -@Getter -@AllArgsConstructor -public enum UserStatus { - /** - * 正常 - */ - OK("0", "正常"), - /** - * 停用 - */ - DISABLE("1", "停用"), - /** - * 删除 - */ - DELETED("2", "删除"); - - private final String code; - private final String info; - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/UserType.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/UserType.java deleted file mode 100644 index ce4d00e0..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/enums/UserType.java +++ /dev/null @@ -1,43 +0,0 @@ -package cc.iotkit.common.enums; - -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.StringUtils; -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 设备类型 - * 针对多套 用户体系 - * - * @author Lion Li - */ -@Getter -@AllArgsConstructor -public enum UserType { - - /** - * pc端 - */ - SYS_USER("sys_user"), - - /** - * 第三方api - */ - API_USER("api_user"), - - /** - * app端 - */ - APP_USER("app_user"); - - private final String userType; - - public static UserType getUserType(String str) { - for (UserType value : values()) { - if (StringUtils.contains(str, value.getUserType())) { - return value; - } - } - throw new BizException("'UserType' not found By " + str); - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/BaseException.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/BaseException.java deleted file mode 100644 index b3f42cd4..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/BaseException.java +++ /dev/null @@ -1,80 +0,0 @@ -package cc.iotkit.common.exception; - - -import cc.iotkit.common.utils.MessageUtils; -import cc.iotkit.common.utils.StringUtils; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - - - -/** - * 基础异常 - * - * @author ruoyi - */ -@Data -@EqualsAndHashCode(callSuper = true) -@NoArgsConstructor -public class BaseException extends RuntimeException { - - - private static final long serialVersionUID = 1L; - - /** - * 所属模块 - */ - private String module; - - /** - * 错误码 - */ - private String code; - - /** - * 错误码对应的参数 - */ - private Object[] args; - - /** - * 错误消息 - */ - private String message; - - public BaseException(String module, String code, Object[] args, String message) { - this.module = module; - this.code = code; - this.args = args; - this.message = message; - } - - public BaseException(String module, String code, String message) { - this(module, code, null, message); - } - - public BaseException(String module, String message) { - this(module, null, null, message); - } - - public BaseException(String code, Object[] args) { - this(null, code, args, null); - } - - public BaseException(String message) { - this(null, null, null, message); - } - - @Override - public String getMessage() { - String message = null; - if (!StringUtils.isEmpty(code)) { - message = MessageUtils.message(code, args); - } - if (message == null) { - message = message; - } - return message; - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/BizException.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/BizException.java deleted file mode 100644 index 7fc08500..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/BizException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.exception; - -import cc.iotkit.common.enums.ErrCode; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -@EqualsAndHashCode(callSuper = true) -@Data -@NoArgsConstructor -@AllArgsConstructor -public class BizException extends RuntimeException { - - /** - * 所属模块 - */ - private String module; - - /** - * 错误码 - */ - private Integer code; - - /** - * 错误消息 - */ - private String message; - - public BizException(String message) { - super(message); - this.message = message; - this.code = ErrCode.SYSTEM_EXCEPTION.getKey(); - } - - /** - * 统一异常消息处理 - * - * @param errCode 异常枚举值 - */ - public BizException(ErrCode errCode) { - this.message = errCode.getValue(); - this.code = errCode.getKey(); - } - - public BizException(ErrCode errCode, Throwable cause) { - super(cause); - this.code = errCode.getKey(); - this.message = errCode.getValue(); - } - - public BizException(ErrCode errCode, String message) { - this.message = message; - this.code = errCode.getKey(); - } - - public BizException(String message, Throwable cause) { - super(message, cause); - } - - public BizException(Throwable cause) { - super(cause); - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/ViewException.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/ViewException.java deleted file mode 100644 index ffb1b2e1..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/ViewException.java +++ /dev/null @@ -1,41 +0,0 @@ -package cc.iotkit.common.exception; - - -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * 视图异常 - * - * @author sjg - */ -@EqualsAndHashCode(callSuper = true) -@Data -public class ViewException extends RuntimeException { - - public static final int CODE_FAILED = 500; - public static final int CODE_WARN = 601; - - private int code; - private String message; - private Object data; - - public ViewException() { - } - - public ViewException(String message) { - super(message); - this.message = message; - } - - public ViewException(int code, String message) { - this.code = code; - this.message = message; - } - - public ViewException(int code, String message, Object data) { - this.code = code; - this.message = message; - this.data = data; - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/user/UserException.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/user/UserException.java deleted file mode 100644 index 1af89aee..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/exception/user/UserException.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.exception.user; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -@EqualsAndHashCode(callSuper = true) -@Data -@NoArgsConstructor -@AllArgsConstructor -public class UserException extends BizException { - - /** - * 所属模块 - */ - private String module; - - /** - * 错误码 - */ - private Integer code; - - /** - * 错误消息 - */ - private String message; - - public UserException(String message) { - super( message); - this.code = ErrCode.SYSTEM_EXCEPTION.getKey(); - this.message = message; - - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/function/IfHandler.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/function/IfHandler.java deleted file mode 100644 index 320f6696..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/function/IfHandler.java +++ /dev/null @@ -1,11 +0,0 @@ -package cc.iotkit.common.function; - -/** - * @author huangwenl - * @date 2022-11-10 - */ -@FunctionalInterface -public interface IfHandler { - - void handler(Runnable tHandler, Runnable fHandler); -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/ConfigService.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/ConfigService.java deleted file mode 100644 index 910acc40..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/ConfigService.java +++ /dev/null @@ -1,18 +0,0 @@ -package cc.iotkit.common.service; - -/** - * 通用 参数配置服务 - * - * @author Lion Li - */ -public interface ConfigService { - - /** - * 根据参数 key 获取参数值 - * - * @param configKey 参数 key - * @return 参数值 - */ - String getConfigValue(String configKey); - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/DeptService.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/DeptService.java deleted file mode 100644 index 53e4993e..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/DeptService.java +++ /dev/null @@ -1,18 +0,0 @@ -package cc.iotkit.common.service; - -/** - * 通用 部门服务 - * - * @author Lion Li - */ -public interface DeptService { - - /** - * 通过部门ID查询部门名称 - * - * @param deptIds 部门ID串逗号分隔 - * @return 部门名称串逗号分隔 - */ - String selectDeptNameByIds(String deptIds); - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/DeviceService.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/DeviceService.java deleted file mode 100644 index 608cbd79..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/DeviceService.java +++ /dev/null @@ -1,19 +0,0 @@ -package cc.iotkit.common.service; - -import cc.iotkit.common.thing.ThingService; - -/** - * 通用设备服务 - * - * @author sjg - */ -public interface DeviceService { - - /** - * 调用设备服务 - * - * @param service 服务 - */ - void invoke(ThingService service); - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/DictService.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/DictService.java deleted file mode 100644 index 6ab10828..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/DictService.java +++ /dev/null @@ -1,57 +0,0 @@ -package cc.iotkit.common.service; - -/** - * 通用 字典服务 - * - * @author Lion Li - */ -public interface DictService { - - /** - * 分隔符 - */ - String SEPARATOR = ","; - - /** - * 根据字典类型和字典值获取字典标签 - * - * @param dictType 字典类型 - * @param dictValue 字典值 - * @return 字典标签 - */ - default String getDictLabel(String dictType, String dictValue) { - return getDictLabel(dictType, dictValue, SEPARATOR); - } - - /** - * 根据字典类型和字典标签获取字典值 - * - * @param dictType 字典类型 - * @param dictLabel 字典标签 - * @return 字典值 - */ - default String getDictValue(String dictType, String dictLabel) { - return getDictValue(dictType, dictLabel, SEPARATOR); - } - - /** - * 根据字典类型和字典值获取字典标签 - * - * @param dictType 字典类型 - * @param dictValue 字典值 - * @param separator 分隔符 - * @return 字典标签 - */ - String getDictLabel(String dictType, String dictValue, String separator); - - /** - * 根据字典类型和字典标签获取字典值 - * - * @param dictType 字典类型 - * @param dictLabel 字典标签 - * @param separator 分隔符 - * @return 字典值 - */ - String getDictValue(String dictType, String dictLabel, String separator); - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/OssService.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/OssService.java deleted file mode 100644 index 0ac5f8fb..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/OssService.java +++ /dev/null @@ -1,18 +0,0 @@ -package cc.iotkit.common.service; - -/** - * 通用 OSS服务 - * - * @author Lion Li - */ -public interface OssService { - - /** - * 通过ossId查询对应的url - * - * @param ossIds ossId串逗号分隔 - * @return url串逗号分隔 - */ - String selectUrlByIds(String ossIds); - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/UserService.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/UserService.java deleted file mode 100644 index 5b57e390..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/service/UserService.java +++ /dev/null @@ -1,18 +0,0 @@ -package cc.iotkit.common.service; - -/** - * 通用 用户服务 - * - * @author Lion Li - */ -public interface UserService { - - /** - * 通过用户ID查询用户账户 - * - * @param userId 用户ID - * @return 用户账户 - */ - String selectUserNameById(Long userId); - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/thing/ThingService.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/thing/ThingService.java deleted file mode 100644 index b443203b..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/thing/ThingService.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.thing; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author sjg - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class ThingService { - - public static final String TYPE_PROPERTY = "property"; - public static final String TYPE_SERVICE = "service"; - - public static final String TYPE_OTA = "ota"; - - private String mid; - - private String productKey; - - private String deviceName; - - private String type; - - private String identifier; - - private T params; - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/EmailLoginBody.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/EmailLoginBody.java deleted file mode 100644 index bbda62b0..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/EmailLoginBody.java +++ /dev/null @@ -1,35 +0,0 @@ -package cc.iotkit.common.undefined; - -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotBlank; -import lombok.Data; - -/** - * 短信登录对象 - * - * @author Lion Li - */ - -@Data -public class EmailLoginBody { - - /** - * 租户ID - */ - @NotBlank(message = "{tenant.number.not.blank}") - private String tenantId; - - /** - * 邮箱 - */ - @NotBlank(message = "{user.email.not.blank}") - @Email(message = "{user.email.not.valid}") - private String email; - - /** - * 邮箱code - */ - @NotBlank(message = "{email.code.not.blank}") - private String emailCode; - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/LoginBody.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/LoginBody.java deleted file mode 100644 index 3dff14a2..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/LoginBody.java +++ /dev/null @@ -1,43 +0,0 @@ -package cc.iotkit.common.undefined; - -import jakarta.validation.constraints.NotBlank; -import lombok.Data; - -/** - * 用户登录对象 - * - * @author Lion Li - */ - -@Data -public class LoginBody { - - /** - * 租户ID - */ - @NotBlank(message = "{tenant.number.not.blank}") - private String 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-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/LoginUser.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/LoginUser.java deleted file mode 100644 index d93e713d..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/LoginUser.java +++ /dev/null @@ -1,143 +0,0 @@ -package cc.iotkit.common.undefined; - -import cc.iotkit.common.utils.StringUtils; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; -import java.util.List; -import java.util.Set; - -/** - * 登录用户身份权限 - * - * @author Lion Li - */ - -@Data -@NoArgsConstructor -public class LoginUser implements Serializable { - - private static final long serialVersionUID = 1L; - - /** - * 租户ID - */ - private String tenantId; - - /** - * 用户ID - */ - private Long userId; - - /** - * 部门ID - */ - private Long deptId; - - /** - * 部门名 - */ - private String deptName; - - /** - * 用户唯一标识 - */ - private String token; - - /** - * 用户类型 - */ - private String userType; - - /** - * 登录时间 - */ - private Long loginTime; - - /** - * 过期时间 - */ - private Long expireTime; - - /** - * 登录IP地址 - */ - private String ipaddr; - - /** - * 登录地点 - */ - private String loginLocation; - - /** - * 浏览器类型 - */ - private String browser; - - /** - * 操作系统 - */ - private String os; - - /** - * 菜单权限 - */ - private Set menuPermission; - - /** - * 角色权限 - */ - private Set rolePermission; - - /** - * 用户名 - */ - private String username; - - /** - * 角色对象 - */ - private List roles; - - /** - * 数据权限 当前角色ID - */ - private Long roleId; - - /** - * 获取登录id - */ - public String getLoginId() { - if (userType == null) { - throw new IllegalArgumentException("用户类型不能为空"); - } - if (userId == null) { - throw new IllegalArgumentException("用户ID不能为空"); - } - return userType + ":" + userId; - } - - /** - * 根据loginId构造loginUser对象 - * - * @param loginId 登录id - * @return LoginUser - * @see LoginUser::getLoginId - */ - public static LoginUser from(String loginId) { - if (StringUtils.isBlank(loginId)) { - return null; - } - String[] split = loginId.split(":"); - if (split.length < 2) { - return null; - } - - LoginUser user = new LoginUser(); - user.setUserType(split[0]); - user.setUserId(Long.parseLong(split[1])); - return user; - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/RegisterBody.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/RegisterBody.java deleted file mode 100644 index 3e8a6cb5..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/RegisterBody.java +++ /dev/null @@ -1,17 +0,0 @@ -package cc.iotkit.common.undefined; - -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-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/RoleDTO.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/RoleDTO.java deleted file mode 100644 index 1198d8db..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/RoleDTO.java +++ /dev/null @@ -1,38 +0,0 @@ -package cc.iotkit.common.undefined; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; - -/** - * 角色 - * - * @author Lion Li - */ - -@Data -@NoArgsConstructor -public class RoleDTO implements Serializable { - - /** - * 角色ID - */ - private Long id; - - /** - * 角色名称 - */ - private String roleName; - - /** - * 角色权限 - */ - private String roleKey; - - /** - * 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限) - */ - private String dataScope; - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/SmsLoginBody.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/SmsLoginBody.java deleted file mode 100644 index b3ad99b6..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/SmsLoginBody.java +++ /dev/null @@ -1,33 +0,0 @@ -package cc.iotkit.common.undefined; - -import jakarta.validation.constraints.NotBlank; -import lombok.Data; - -/** - * 短信登录对象 - * - * @author Lion Li - */ - -@Data -public class SmsLoginBody { - - /** - * 租户ID - */ - @NotBlank(message = "{tenant.number.not.blank}") - private String tenantId; - - /** - * 手机号 - */ - @NotBlank(message = "{user.phonenumber.not.blank}") - private String phonenumber; - - /** - * 短信code - */ - @NotBlank(message = "{sms.code.not.blank}") - private String smsCode; - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/UserOnlineDTO.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/UserOnlineDTO.java deleted file mode 100644 index 4e27ac70..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/UserOnlineDTO.java +++ /dev/null @@ -1,60 +0,0 @@ -package cc.iotkit.common.undefined; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.Serializable; - -/** - * 当前在线会话 - * - * @author ruoyi - */ - -@Data -@NoArgsConstructor -public class UserOnlineDTO implements Serializable { - - private static final long serialVersionUID = 1L; - - /** - * 会话编号 - */ - 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-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/XcxLoginUser.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/XcxLoginUser.java deleted file mode 100644 index cd8963ae..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/undefined/XcxLoginUser.java +++ /dev/null @@ -1,26 +0,0 @@ -package cc.iotkit.common.undefined; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - - -/** - * 小程序登录用户身份权限 - * - * @author Lion Li - */ -@Data -@EqualsAndHashCode(callSuper = true) -@NoArgsConstructor -public class XcxLoginUser extends LoginUser { - - - private static final long serialVersionUID = 1L; - - /** - * openid - */ - private String openid; - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/CodecUtil.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/CodecUtil.java deleted file mode 100644 index bce9482f..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/CodecUtil.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.utils; - -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.lang3.StringUtils; - -import javax.crypto.Cipher; -import javax.crypto.KeyGenerator; -import javax.crypto.spec.SecretKeySpec; -import java.nio.charset.StandardCharsets; - -public class CodecUtil { - - private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding"; - - /** - * base 64 encode - * - * @param bytes 待编码的byte[] - * @return 编码后的base 64 code - */ - private static String base64Encode(byte[] bytes) { - return Base64.encodeBase64String(bytes); - } - - /** - * base 64 decode - * - * @param base64Code 待解码的base 64 code - * @return 解码后的byte[] - * @throws Exception 抛出异常 - */ - private static byte[] base64Decode(String base64Code) { - return StringUtils.isEmpty(base64Code) ? null : new Base64().decode(base64Code); - } - - - /** - * AES加密 - * - * @param content 待加密的内容 - * @param encryptKey 加密密钥 - * @return 加密后的byte[] - */ - private static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception { - KeyGenerator kgen = KeyGenerator.getInstance("AES"); - kgen.init(128); - Cipher cipher = Cipher.getInstance(ALGORITHMSTR); - cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(encryptKey.getBytes(), "AES")); - - return cipher.doFinal(content.getBytes(StandardCharsets.UTF_8)); - } - - - /** - * AES加密为base 64 code - * - * @param content 待加密的内容 - * @param encryptKey 加密密钥 - * @return 加密后的base 64 code - */ - public static String aesEncrypt(String content, String encryptKey) throws Exception { - String result = base64Encode(aesEncryptToBytes(content, encryptKey)); - return HexUtil.toHexString(result.getBytes()); - } - - /** - * AES解密 - * - * @param encryptBytes 待解密的byte[] - * @param decryptKey 解密密钥 - * @return 解密后的String - */ - private static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception { - KeyGenerator kgen = KeyGenerator.getInstance("AES"); - kgen.init(128); - - Cipher cipher = Cipher.getInstance(ALGORITHMSTR); - cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(), "AES")); - byte[] decryptBytes = cipher.doFinal(encryptBytes); - - return new String(decryptBytes); - } - - /** - * 将base 64 code AES解密 - * - * @param encryptStr 待解密的base 64 code - * @param decryptKey 解密密钥 - * @return 解密后的string - */ - public static String aesDecrypt(String encryptStr, String decryptKey) throws Exception { - encryptStr = new String(HexUtil.parseHex(encryptStr)); - return StringUtils.isEmpty(encryptStr) ? "" : aesDecryptByBytes(base64Decode(encryptStr), decryptKey); - } - - public static String aesDecryptHex(String encryptStr, String decryptKey) throws Exception { - encryptStr = new String(HexUtil.parseHex(encryptStr)); - return StringUtils.isEmpty(encryptStr) ? "" : aesDecryptByBytes(base64Decode(encryptStr), decryptKey); - } - - public static String md5Str(String content) { - return DigestUtils.md5Hex(content); - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ComponentClassLoader.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ComponentClassLoader.java deleted file mode 100644 index 4412b892..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ComponentClassLoader.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.utils; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - -public class ComponentClassLoader { - private static final Map classLoaders = new HashMap<>(); - - protected static Class findClass(String name, String clsName) throws ClassNotFoundException { - ClassLoader classLoader = classLoaders.get(name); - return (Class) classLoader.loadClass(clsName); - } - - private static String addUrl(String name, File jarPath) throws NoSuchMethodException, InvocationTargetException, - IllegalAccessException, IOException { - URLClassLoader classLoader = classLoaders.get(name); - if (classLoader != null) { - classLoader.close(); - } - - classLoader = URLClassLoader.newInstance(new URL[]{jarPath.toURI().toURL()}, - Thread.currentThread().getContextClassLoader()); - classLoaders.put(name, classLoader); - - Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); - if (!method.canAccess(classLoader)) { - method.setAccessible(true); - } - - URL url = jarPath.toURI().toURL(); - method.invoke(classLoader, url); - InputStream is = classLoader.getResourceAsStream("component.spi"); - if (is == null) { - return null; - } - - //多行只取第1行,并处理空格 - String[] lines = IOUtils.toString(is, StandardCharsets.UTF_8).split("\\s"); - if (lines.length == 0) { - return null; - } - return lines[0].trim(); - } - - public static T getComponent(String name, File jarFile) throws Exception { - String className = addUrl(name, jarFile); - if (StringUtils.isBlank(className)) { - throw new BizException(ErrCode.GET_SPI_COMPONENT_ERROR); - } - Class componentClass = findClass(name, className); - return componentClass.getDeclaredConstructor().newInstance(); - } - - public static T getConverter(String name) throws Exception { - URLClassLoader classLoader = classLoaders.get(name); - InputStream is = classLoader.getResourceAsStream("convert.spi"); - if (is == null) { - return null; - } - - //多行只取第1行,并处理空格 - String[] lines = IOUtils.toString(is, StandardCharsets.UTF_8).split("\\s"); - if (lines.length == 0) { - throw new BizException(ErrCode.GET_SPI_CONVERT_ERROR); - } - String className = lines[0].trim(); - Class converterClass = findClass(name, className); - return converterClass.getDeclaredConstructor().newInstance(); - } - - public static void closeClassLoader(String name) { - try { - URLClassLoader classLoader = classLoaders.get(name); - if (classLoader != null){ - classLoader.close(); - } - }catch (Exception e){ - e.printStackTrace(); - } - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/DateUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/DateUtils.java deleted file mode 100644 index 1a5835a5..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/DateUtils.java +++ /dev/null @@ -1,164 +0,0 @@ -package cc.iotkit.common.utils; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.apache.commons.lang3.time.DateFormatUtils; - -import java.lang.management.ManagementFactory; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.time.*; -import java.util.Date; - -/** - * 时间工具类 - * - * @author ruoyi - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class DateUtils extends org.apache.commons.lang3.time.DateUtils { - - public static final String YYYY = "yyyy"; - - public static final String YYYY_MM = "yyyy-MM"; - - public static final String YYYY_MM_DD = "yyyy-MM-dd"; - - public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; - - public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; - - private static final String[] PARSE_PATTERNS = { - "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", - "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", - "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"}; - - /** - * 获取当前Date型日期 - * - * @return Date() 当前日期 - */ - public static Date getNowDate() { - return new Date(); - } - - /** - * 获取当前日期, 默认格式为yyyy-MM-dd - * - * @return String - */ - public static String getDate() { - return dateTimeNow(YYYY_MM_DD); - } - - public static String getTime() { - return dateTimeNow(YYYY_MM_DD_HH_MM_SS); - } - - public static String dateTimeNow() { - return dateTimeNow(YYYYMMDDHHMMSS); - } - - public static String dateTimeNow(final String format) { - return parseDateToStr(format, new Date()); - } - - public static String dateTime(final Date date) { - return parseDateToStr(YYYY_MM_DD, date); - } - - public static String parseDateToStr(final String format, final Date date) { - return new SimpleDateFormat(format).format(date); - } - - public static Date dateTime(final String format, final String ts) { - try { - return new SimpleDateFormat(format).parse(ts); - } catch (ParseException e) { - throw new RuntimeException(e); - } - } - - /** - * 日期路径 即年/月/日 如2018/08/08 - */ - public static String datePath() { - Date now = new Date(); - return DateFormatUtils.format(now, "yyyy/MM/dd"); - } - - /** - * 日期路径 即年/月/日 如20180808 - */ - public static String dateTime() { - Date now = new Date(); - return DateFormatUtils.format(now, "yyyyMMdd"); - } - - /** - * 日期型字符串转化为日期 格式 - */ - public static Date parseDate(Object str) { - if (str == null) { - return null; - } - try { - return parseDate(str.toString(), PARSE_PATTERNS); - } catch (ParseException e) { - return null; - } - } - - /** - * 获取服务器启动时间 - */ - public static Date getServerStartDate() { - long time = ManagementFactory.getRuntimeMXBean().getStartTime(); - return new Date(time); - } - - /** - * 计算相差天数 - */ - public static int differentDaysByMillisecond(Date date1, Date date2) { - return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24))); - } - - /** - * 计算两个时间差 - */ - public static String getDatePoor(Date endDate, Date nowDate) { - long nd = 1000 * 24 * 60 * 60L; - long nh = 1000 * 60 * 60L; - long nm = 1000 * 60L; - // long ns = 1000; - // 获得两个时间的毫秒时间差异 - long diff = endDate.getTime() - nowDate.getTime(); - // 计算差多少天 - long day = diff / nd; - // 计算差多少小时 - long hour = diff % nd / nh; - // 计算差多少分钟 - long min = diff % nd % nh / nm; - // 计算差多少秒//输出结果 - // long sec = diff % nd % nh % nm / ns; - return day + "天" + hour + "小时" + min + "分钟"; - } - - /** - * 增加 LocalDateTime ==> Date - */ - public static Date toDate(LocalDateTime temporalAccessor) { - ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault()); - return Date.from(zdt.toInstant()); - } - - /** - * 增加 LocalDate ==> Date - */ - public static Date toDate(LocalDate temporalAccessor) { - LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0)); - ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault()); - return Date.from(zdt.toInstant()); - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/DeviceUtil.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/DeviceUtil.java deleted file mode 100644 index 0e33b8c0..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/DeviceUtil.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.utils; - -import org.apache.commons.lang3.RandomUtils; -import org.apache.commons.lang3.StringUtils; - -public class DeviceUtil { - - /** - * 1-13位 时间戳 - * 14-29位 deviceNae,去除非字母和数字,不足16位补0,超过16位的mac取后16位,共16位 - * 30-31位 mac长度,共2位 - * 32位 随机一个0-f字符 - */ - public static String newDeviceId(String deviceNae) { - int maxDnLen = 16; - String dn = deviceNae.replaceAll("[^0-9A-Za-z]", ""); - if (dn.length() > maxDnLen) { - dn = dn.substring(dn.length() - maxDnLen + 1); - } else { - dn = (dn + "00000000000000000000").substring(0, maxDnLen); - } - String len = StringUtils.leftPad(deviceNae.length() + "", 2, '0'); - String rnd = Integer.toHexString(RandomUtils.nextInt(0, 16)); - return (System.currentTimeMillis() + "0" + dn + len + rnd).toLowerCase(); - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/FIUtil.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/FIUtil.java deleted file mode 100644 index bee86309..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/FIUtil.java +++ /dev/null @@ -1,21 +0,0 @@ -package cc.iotkit.common.utils; - -import cc.iotkit.common.function.IfHandler; - -/** - * @author huangwenl - * @date 2022-11-10 - */ -public class FIUtil { - - - public static IfHandler isTotF(boolean param) { - return (tHandler, fHandler) -> { - if (param) { - tHandler.run(); - } else { - fHandler.run(); - } - }; - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/HexUtil.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/HexUtil.java deleted file mode 100644 index 576d593e..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/HexUtil.java +++ /dev/null @@ -1,328 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.utils; - - -import org.apache.commons.lang3.StringUtils; - -import java.nio.ByteBuffer; - -public class HexUtil { - - private static final char[] CHARS_TABLES = "0123456789ABCDEF".toCharArray(); - static final byte[] BYTES = new byte[128]; - - static { - for (int i = 0; i < 10; i++) { - BYTES['0' + i] = (byte) i; - BYTES['A' + i] = (byte) (10 + i); - BYTES['a' + i] = (byte) (10 + i); - } - } - - public static String toHexString(byte[] aBytes) { - return toHexString(aBytes, 0, aBytes.length); - } - - public static String toFormattedHexString(byte[] aBytes) { - return toFormattedHexString(aBytes, 0, aBytes.length); - } - - public static String toHexString(byte[] aBytes, int aLength) { - return toHexString(aBytes, 0, aLength); - } - - public static byte[] parseHex(String aHexString) { - char[] src = aHexString.replace("\n", "").replace(" ", "").toUpperCase().toCharArray(); - byte[] dst = new byte[src.length / 2]; - - for (int si = 0, di = 0; di < dst.length; di++) { - byte high = BYTES[src[si++] & 0x7f]; - byte low = BYTES[src[si++] & 0x7f]; - dst[di] = (byte) ((high << 4) + low); - } - - return dst; - } - - public static String toFormattedHexString(byte[] aBytes, int aOffset, int aLength) { - StringBuilder sb = new StringBuilder(); - sb.append("["); - sb.append(aLength); - sb.append("] :"); - for (int si = aOffset, di = 0; si < aOffset + aLength; si++, di++) { - byte b = aBytes[si]; - if (di % 4 == 0) { - sb.append(" "); - } else { - sb.append(' '); - } - sb.append(CHARS_TABLES[(b & 0xf0) >>> 4]); - sb.append(CHARS_TABLES[(b & 0x0f)]); - - } - - return sb.toString(); - - } - - public static String toHexString(byte[] aBytes, int aOffset, int aLength) { - char[] dst = new char[aLength * 2]; - - for (int si = aOffset, di = 0; si < aOffset + aLength; si++) { - byte b = aBytes[si]; - dst[di++] = CHARS_TABLES[(b & 0xf0) >>> 4]; - dst[di++] = CHARS_TABLES[(b & 0x0f)]; - } - - return new String(dst); - } - - public static String unwrapCharString(String charStr) { - byte[] bytes = parseHex(charStr); - StringBuilder rawStr = new StringBuilder(); - for (byte aByte : bytes) { - rawStr.append((char) aByte); - } - return rawStr.toString(); - } - - /** - * int转bytes - */ - public static byte[] intToBytes(int x) { - ByteBuffer buffer = ByteBuffer.allocate(4); - buffer.putInt(0, x); - return buffer.array(); - } - - /** - * bytes转int - */ - public static int bytesToInt(byte[] bytes) { - ByteBuffer buffer = ByteBuffer.wrap(bytes); - buffer.flip(); - return buffer.getInt(); - } - - public static int checkSum(ByteBuffer buffer) { - buffer.flip(); - byte sum = 0; - while (buffer.hasRemaining()) { - sum += buffer.get(); - } - buffer.limit(buffer.capacity()); - return sum % 256; - } - - public static byte[] toLowerBytes(byte[] bytes) { - int len = bytes.length; - byte[] r = new byte[len]; - for (int i = 0; i < len; i++) { - r[len - i - 1] = bytes[i]; - } - return r; - } - - public static int toLowerInt(byte[] bytes) { - int len = bytes.length; - byte[] r = new byte[len]; - for (int i = 0; i < len; i++) { - r[len - i - 1] = (byte) (bytes[i] - 0x33); - } - return ByteBuffer.wrap(r).getInt(); - } - - public static byte[] shortToBytes(short x) { - ByteBuffer buffer = ByteBuffer.allocate(2); - buffer.putShort(0, x); - return buffer.array(); - } - - public static String readString(ByteBuffer buffer, int len) { - byte[] dest = new byte[len]; - buffer.get(dest, 0, len); - return new String(dest); - } - -// public static int readLowerInt(ByteBuffer buffer, int len) { -// int r = 0; -// for (int i = 0; i < len; i++) { -// byte b = buffer.get(); -// r += (i == 0 ? b - 0x33 : ((b - 0x33) * Math.pow(10, i))); -// } -// return r; -// } - - public static String readHexIntString(ByteBuffer buffer) { - int b = buffer.get(); - String hex = Integer.toHexString(b - 0x33).replace("f", ""); - return StringUtils.leftPad(hex, 2, "0"); - } - - public static byte[] add33Bytes(byte[] bytes) { - for (int i = 0; i < bytes.length; i++) { - bytes[i] = (byte) (bytes[i] + 0x33); - } - return bytes; - } - - public static byte[] minus33Bytes(byte[] bytes) { - for (int i = 0; i < bytes.length; i++) { - bytes[i] = (byte) (bytes[i] - 0x33); - } - return bytes; - } - - public static byte[] readBytes(ByteBuffer buffer, int len) { - byte[] data = new byte[len]; - for (int i = 0; i < len; i++) { - data[i] = buffer.get(); - } - return data; - } - - public static byte[] readAndMinus33Bytes(ByteBuffer buffer, int len) { - byte[] data = new byte[len]; - for (int i = 0; i < len; i++) { - data[i] = (byte) (buffer.get() - 0x33); - } - return data; - } - - public static int bcdInt(String row) { - String bcd = bcdString(row); - bcd = bcd.replace("FF", "0"); - return Integer.parseInt(bcd); - } - - public static int bcdInt(ByteBuffer buffer, int len) { - byte[] bytes = readAndMinus33Bytes(buffer, len); - return bcdInt(HexUtil.toHexString(bytes)); - } - - public static String bcdString(String row) { - char[] chars = row.toCharArray(); - int len = chars.length; - char[] newChars = new char[len]; - - for (int i = 0; i < len; i += 2) { - newChars[i] = chars[len - i - 2]; - newChars[i + 1] = chars[len - i - 1]; - } - return String.valueOf(newChars); - } - - public static byte[] intBcdAdd33(int v, int len) { - String strV = String.valueOf(v); - strV = StringUtils.leftPad(strV, len * 2, '0'); - - return add33Bytes(HexUtil.parseHex(bcdString(strV))); - } - - /** - * 16进制表示的字符串转换为字节数组 - * - * @param s 16进制表示的字符串 - * @return byte[] 字节数组 - */ - public static byte[] hexStringToByteArray(String s) { - int len = s.length(); - byte[] b = new byte[len / 2]; - for (int i = 0; i < len; i += 2) { - // 两位一组,表示一个字节,把这样表示的16进制字符串,还原成一个字节 - b[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character - .digit(s.charAt(i + 1), 16)); - } - return b; - - } - /** - * 计算CRC16校验 - * - * @param data 需要计算的数组 - * @param offset 起始位置 - * @param len 长度 - * @return CRC16校验值 - */ - public static int calcCrc16(byte[] data, int offset, int len) { - byte[] crc16_tab_h = { - (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, - (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, - (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, - (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, - (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, - (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, - (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, - (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, - (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, - (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, - - (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, - (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, - (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, - (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, - (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, - (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, - (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, - (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, - (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, - (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, - - (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, - (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, - (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, - (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, - (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, - (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40 - }; - byte[] crc16_tab_l = { - (byte) 0x00, (byte) 0xC0, (byte) 0xC1, (byte) 0x01, (byte) 0xC3, (byte) 0x03, (byte) 0x02, (byte) 0xC2, (byte) 0xC6, (byte) 0x06, - (byte) 0x07, (byte) 0xC7, (byte) 0x05, (byte) 0xC5, (byte) 0xC4, (byte) 0x04, (byte) 0xCC, (byte) 0x0C, (byte) 0x0D, (byte) 0xCD, - (byte) 0x0F, (byte) 0xCF, (byte) 0xCE, (byte) 0x0E, (byte) 0x0A, (byte) 0xCA, (byte) 0xCB, (byte) 0x0B, (byte) 0xC9, (byte) 0x09, - (byte) 0x08, (byte) 0xC8, (byte) 0xD8, (byte) 0x18, (byte) 0x19, (byte) 0xD9, (byte) 0x1B, (byte) 0xDB, (byte) 0xDA, (byte) 0x1A, - (byte) 0x1E, (byte) 0xDE, (byte) 0xDF, (byte) 0x1F, (byte) 0xDD, (byte) 0x1D, (byte) 0x1C, (byte) 0xDC, (byte) 0x14, (byte) 0xD4, - (byte) 0xD5, (byte) 0x15, (byte) 0xD7, (byte) 0x17, (byte) 0x16, (byte) 0xD6, (byte) 0xD2, (byte) 0x12, (byte) 0x13, (byte) 0xD3, - (byte) 0x11, (byte) 0xD1, (byte) 0xD0, (byte) 0x10, (byte) 0xF0, (byte) 0x30, (byte) 0x31, (byte) 0xF1, (byte) 0x33, (byte) 0xF3, - (byte) 0xF2, (byte) 0x32, (byte) 0x36, (byte) 0xF6, (byte) 0xF7, (byte) 0x37, (byte) 0xF5, (byte) 0x35, (byte) 0x34, (byte) 0xF4, - (byte) 0x3C, (byte) 0xFC, (byte) 0xFD, (byte) 0x3D, (byte) 0xFF, (byte) 0x3F, (byte) 0x3E, (byte) 0xFE, (byte) 0xFA, (byte) 0x3A, - (byte) 0x3B, (byte) 0xFB, (byte) 0x39, (byte) 0xF9, (byte) 0xF8, (byte) 0x38, (byte) 0x28, (byte) 0xE8, (byte) 0xE9, (byte) 0x29, - - (byte) 0xEB, (byte) 0x2B, (byte) 0x2A, (byte) 0xEA, (byte) 0xEE, (byte) 0x2E, (byte) 0x2F, (byte) 0xEF, (byte) 0x2D, (byte) 0xED, - (byte) 0xEC, (byte) 0x2C, (byte) 0xE4, (byte) 0x24, (byte) 0x25, (byte) 0xE5, (byte) 0x27, (byte) 0xE7, (byte) 0xE6, (byte) 0x26, - (byte) 0x22, (byte) 0xE2, (byte) 0xE3, (byte) 0x23, (byte) 0xE1, (byte) 0x21, (byte) 0x20, (byte) 0xE0, (byte) 0xA0, (byte) 0x60, - (byte) 0x61, (byte) 0xA1, (byte) 0x63, (byte) 0xA3, (byte) 0xA2, (byte) 0x62, (byte) 0x66, (byte) 0xA6, (byte) 0xA7, (byte) 0x67, - (byte) 0xA5, (byte) 0x65, (byte) 0x64, (byte) 0xA4, (byte) 0x6C, (byte) 0xAC, (byte) 0xAD, (byte) 0x6D, (byte) 0xAF, (byte) 0x6F, - (byte) 0x6E, (byte) 0xAE, (byte) 0xAA, (byte) 0x6A, (byte) 0x6B, (byte) 0xAB, (byte) 0x69, (byte) 0xA9, (byte) 0xA8, (byte) 0x68, - (byte) 0x78, (byte) 0xB8, (byte) 0xB9, (byte) 0x79, (byte) 0xBB, (byte) 0x7B, (byte) 0x7A, (byte) 0xBA, (byte) 0xBE, (byte) 0x7E, - (byte) 0x7F, (byte) 0xBF, (byte) 0x7D, (byte) 0xBD, (byte) 0xBC, (byte) 0x7C, (byte) 0xB4, (byte) 0x74, (byte) 0x75, (byte) 0xB5, - (byte) 0x77, (byte) 0xB7, (byte) 0xB6, (byte) 0x76, (byte) 0x72, (byte) 0xB2, (byte) 0xB3, (byte) 0x73, (byte) 0xB1, (byte) 0x71, - (byte) 0x70, (byte) 0xB0, (byte) 0x50, (byte) 0x90, (byte) 0x91, (byte) 0x51, (byte) 0x93, (byte) 0x53, (byte) 0x52, (byte) 0x92, - - (byte) 0x96, (byte) 0x56, (byte) 0x57, (byte) 0x97, (byte) 0x55, (byte) 0x95, (byte) 0x94, (byte) 0x54, (byte) 0x9C, (byte) 0x5C, - (byte) 0x5D, (byte) 0x9D, (byte) 0x5F, (byte) 0x9F, (byte) 0x9E, (byte) 0x5E, (byte) 0x5A, (byte) 0x9A, (byte) 0x9B, (byte) 0x5B, - (byte) 0x99, (byte) 0x59, (byte) 0x58, (byte) 0x98, (byte) 0x88, (byte) 0x48, (byte) 0x49, (byte) 0x89, (byte) 0x4B, (byte) 0x8B, - (byte) 0x8A, (byte) 0x4A, (byte) 0x4E, (byte) 0x8E, (byte) 0x8F, (byte) 0x4F, (byte) 0x8D, (byte) 0x4D, (byte) 0x4C, (byte) 0x8C, - (byte) 0x44, (byte) 0x84, (byte) 0x85, (byte) 0x45, (byte) 0x87, (byte) 0x47, (byte) 0x46, (byte) 0x86, (byte) 0x82, (byte) 0x42, - - (byte) 0x43, (byte) 0x83, (byte) 0x41, (byte) 0x81, (byte) 0x80, (byte) 0x40 - }; - int pre = 0xffff; - int ucCRCHi = (pre & 0xff00) >> 8; - int ucCRCLo = pre & 0x00ff; - int iIndex; - for (int i = 0; i < len; ++i) { - iIndex = (ucCRCLo ^ data[offset + i]) & 0x00ff; - ucCRCLo = ucCRCHi ^ crc16_tab_h[iIndex]; - ucCRCHi = crc16_tab_l[iIndex]; - } - return ((ucCRCHi & 0x00ff) << 8) | (ucCRCLo & 0x00ff) & 0xffff; - } -} \ No newline at end of file diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/JsonUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/JsonUtils.java deleted file mode 100644 index fe102af2..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/JsonUtils.java +++ /dev/null @@ -1,129 +0,0 @@ -package cc.iotkit.common.utils; - -import cn.hutool.core.lang.Dict; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.PrimitiveArrayUtil; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.exc.MismatchedInputException; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -/** - * JSON 工具类 - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class JsonUtils { - - private static final ObjectMapper OBJECT_MAPPER = SpringUtils.getBean(ObjectMapper.class); - - public static ObjectMapper getObjectMapper() { - return OBJECT_MAPPER; - } - - public static String toJsonString(Object object) { - if (ObjectUtil.isNull(object)) { - return null; - } - try { - return OBJECT_MAPPER.writeValueAsString(object); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - - public static T parse(String json, Class cls) { - if (StringUtils.isBlank(json)) { - return null; - } - try { - return OBJECT_MAPPER.readValue(json, cls); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - - public static T parseObject(String text, Class clazz) { - if (StringUtils.isEmpty(text)) { - return null; - } - try { - return OBJECT_MAPPER.readValue(text, clazz); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static T parseObject(byte[] bytes, Class clazz) { - if (PrimitiveArrayUtil.isEmpty(bytes)) { - return null; - } - try { - return OBJECT_MAPPER.readValue(bytes, clazz); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static T parseObject(String text, TypeReference typeReference) { - if (StringUtils.isBlank(text)) { - return null; - } - try { - return OBJECT_MAPPER.readValue(text, typeReference); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static Dict parseMap(String text) { - if (StringUtils.isBlank(text)) { - return null; - } - try { - return OBJECT_MAPPER.readValue(text, OBJECT_MAPPER.getTypeFactory().constructType(Dict.class)); - } catch (MismatchedInputException e) { - // 类型不匹配说明不是json - return null; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static List parseArrayMap(String text) { - if (StringUtils.isBlank(text)) { - return Collections.emptyList(); - } - try { - return OBJECT_MAPPER.readValue(text, OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, Dict.class)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static List parseArray(String text, Class clazz) { - if (StringUtils.isEmpty(text)) { - return new ArrayList<>(); - } - try { - return OBJECT_MAPPER.readValue(text, OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, clazz)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static T objectToJavaBean(Object obj, Class clazz) { - if (Objects.isNull(obj)) { - return null; - } - return OBJECT_MAPPER.convertValue(obj, clazz); - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/MapstructUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/MapstructUtils.java deleted file mode 100644 index f9a31e74..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/MapstructUtils.java +++ /dev/null @@ -1,111 +0,0 @@ -package cc.iotkit.common.utils; - -import cc.iotkit.common.api.Paging; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.ObjectUtil; -import io.github.linpeilie.Converter; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.springframework.util.Assert; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * Mapstruct 工具类 - *

参考文档:mapstruct-plus

- * - * @author Michelle.Chung - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MapstructUtils { - - private final static Converter CONVERTER = SpringUtils.getBean(Converter.class); - - /** - * 将 T 类型对象,转换为 desc 类型的对象并返回 - * - * @param source 数据来源实体 - * @param desc 描述对象 转换后的对象 - * @return desc - */ - public static V convert(T source, Class desc) { - Assert.notNull(desc, "desc is null"); - if (source == null) { - return null; - } - return CONVERTER.convert(source, desc); - } - - /** - * 将 T 类型对象,按照配置的映射字段规则,给 desc 类型的对象赋值并返回 desc 对象 - * - * @param source 数据来源实体 - * @param desc 转换后的对象 - * @return desc - */ - public static V convert(T source, V desc) { - if (ObjectUtil.isNull(source)) { - return null; - } - if (ObjectUtil.isNull(desc)) { - return null; - } - return CONVERTER.convert(source, desc); - } - - /** - * 将 T 类型的集合,转换为 desc 类型的集合并返回 - * - * @param sourceList 数据来源实体列表 - * @param desc 描述对象 转换后的对象 - * @return desc - */ - public static List convert(List sourceList, Class desc) { - if (ObjectUtil.isNull(sourceList)) { - return Collections.emptyList(); - } - if (CollUtil.isEmpty(sourceList)) { - return CollUtil.newArrayList(); - } - return CONVERTER.convert(sourceList, desc); - } - - /** - * 将 Map 转换为 beanClass 类型的集合并返回 - * - * @param map 数据来源 - * @param beanClass bean类 - * @return bean对象 - */ - public static T convert(Map map, Class beanClass) { - if (MapUtil.isEmpty(map)) { - return null; - } - if (ObjectUtil.isNull(beanClass)) { - return null; - } - return CONVERTER.convert(map, beanClass); - } - - /** - * 转换分页对象 - * - * @param source 数据来源 - * @param desc 描述对象 转换后的对象 - * @return desc - */ - public static Paging convert(Paging source, Class desc) { - if (ObjectUtil.isNull(source)) { - return null; - } - if (CollUtil.isEmpty(source.getRows())) { - return new Paging<>(0, new ArrayList<>()); - } - return new Paging<>(source.getTotal(), CONVERTER.convert(source.getRows(), desc)); - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/MessageUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/MessageUtils.java deleted file mode 100644 index 32220169..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/MessageUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -package cc.iotkit.common.utils; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.springframework.context.MessageSource; -import org.springframework.context.i18n.LocaleContextHolder; - -/** - * 获取i18n资源文件 - * - * @author Lion Li - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class MessageUtils { - - private static final MessageSource MESSAGE_SOURCE = SpringUtils.getBean(MessageSource.class); - - /** - * 根据消息键和参数 获取消息 委托给spring messageSource - * - * @param code 消息键 - * @param args 参数 - * @return 获取国际化翻译值 - */ - public static String message(String code, Object... args) { -// TODO: 国际化 - try{ - return MESSAGE_SOURCE.getMessage(code, args, LocaleContextHolder.getLocale()); - } catch (Exception e) { - return code; - } - - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ReflectUtil.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ReflectUtil.java deleted file mode 100644 index 509d0840..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ReflectUtil.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.utils; - - -import lombok.SneakyThrows; -import org.apache.commons.beanutils.BeanMap; -import org.apache.commons.beanutils.BeanUtils; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ReflectUtil { - - @SneakyThrows - public static T copyNoNulls(T from, T to, String... fields) { - List fieldList = Arrays.asList(fields); - - Map map = new HashMap<>(); - new BeanMap(from).forEach((key, value) -> { - if (value == null) { - return; - } - String field = key.toString(); - if (fields.length == 0 || fieldList.contains(field)) { - map.put(field, value); - } - }); - BeanUtils.populate(to, map); - return to; - } - - public static Map toMap(Object bean) { - Map map = new HashMap<>(); - new BeanMap(bean).forEach((key, value) -> { - if (key.equals("class")) { - return; - } - String field = key.toString(); - map.put(field, value); - }); - return map; - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ReflectUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ReflectUtils.java deleted file mode 100644 index 44556111..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ReflectUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -package cc.iotkit.common.utils; - -import cn.hutool.core.util.ReflectUtil; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import java.lang.reflect.Method; - -/** - * 反射工具类. 提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class, 被AOP过的真实类等工具函数. - * - * @author Lion Li - */ -@SuppressWarnings("rawtypes") -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ReflectUtils extends ReflectUtil { - - private static final String SETTER_PREFIX = "set"; - - private static final String GETTER_PREFIX = "get"; - - /** - * 调用Getter方法. - * 支持多级,如:对象名.对象名.方法 - */ - @SuppressWarnings("unchecked") - public static E invokeGetter(Object obj, String propertyName) { - Object object = obj; - for (String name : StringUtils.split(propertyName, ".")) { - String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name); - object = invoke(object, getterMethodName); - } - return (E) object; - } - - /** - * 调用Setter方法, 仅匹配方法名。 - * 支持多级,如:对象名.对象名.方法 - */ - public static void invokeSetter(Object obj, String propertyName, E value) { - Object object = obj; - String[] names = StringUtils.split(propertyName, "."); - for (int i = 0; i < names.length; i++) { - if (i < names.length - 1) { - String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]); - object = invoke(object, getterMethodName); - } else { - String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]); - Method method = getMethodByName(object.getClass(), setterMethodName); - invoke(object, method, value); - } - } - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/SpringUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/SpringUtils.java deleted file mode 100644 index 80c10817..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/SpringUtils.java +++ /dev/null @@ -1,62 +0,0 @@ -package cc.iotkit.common.utils; - -import cn.hutool.extra.spring.SpringUtil; -import org.springframework.aop.framework.AopContext; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Component; - -/** - * spring工具类 - * - * @author Lion Li - */ -@Component -public final class SpringUtils extends SpringUtil { - - /** - * 如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true - */ - public static boolean containsBean(String name) { - return getBeanFactory().containsBean(name); - } - - /** - * 判断以给定名字注册的bean定义是一个singleton还是一个prototype。 - * 如果与给定名字相应的bean定义没有被找到,将会抛出一个异常(NoSuchBeanDefinitionException) - */ - public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException { - return getBeanFactory().isSingleton(name); - } - - /** - * @return Class 注册对象的类型 - */ - public static Class getType(String name) throws NoSuchBeanDefinitionException { - return getBeanFactory().getType(name); - } - - /** - * 如果给定的bean名字在bean定义中有别名,则返回这些别名 - */ - public static String[] getAliases(String name) throws NoSuchBeanDefinitionException { - return getBeanFactory().getAliases(name); - } - - /** - * 获取aop代理对象 - */ - @SuppressWarnings("unchecked") - public static T getAopProxy(T invoker) { - return (T) AopContext.currentProxy(); - } - - - /** - * 获取spring上下文 - */ - public static ApplicationContext context() { - return getApplicationContext(); - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/StreamUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/StreamUtils.java deleted file mode 100644 index eeab4e8c..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/StreamUtils.java +++ /dev/null @@ -1,254 +0,0 @@ -package cc.iotkit.common.utils; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.map.MapUtil; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.*; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -/** - * stream 流工具类 - * - * @author Lion Li - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class StreamUtils { - - /** - * 将collection过滤 - * - * @param collection 需要转化的集合 - * @param function 过滤方法 - * @return 过滤后的list - */ - public static List filter(Collection collection, Predicate function) { - if (CollUtil.isEmpty(collection)) { - return CollUtil.newArrayList(); - } - // 注意此处不要使用 .toList() 新语法 因为返回的是不可变List 会导致序列化问题 - return collection.stream().filter(function).collect(Collectors.toList()); - } - - /** - * 将collection拼接 - * - * @param collection 需要转化的集合 - * @param function 拼接方法 - * @return 拼接后的list - */ - public static String join(Collection collection, Function function) { - return join(collection, function, StringUtils.SEPARATOR); - } - - /** - * 将collection拼接 - * - * @param collection 需要转化的集合 - * @param function 拼接方法 - * @param delimiter 拼接符 - * @return 拼接后的list - */ - public static String join(Collection collection, Function function, CharSequence delimiter) { - if (CollUtil.isEmpty(collection)) { - return StringUtils.EMPTY; - } - return collection.stream().map(function).filter(Objects::nonNull).collect(Collectors.joining(delimiter)); - } - - /** - * 将collection排序 - * - * @param collection 需要转化的集合 - * @param comparing 排序方法 - * @return 排序后的list - */ - public static List sorted(Collection collection, Comparator comparing) { - if (CollUtil.isEmpty(collection)) { - return CollUtil.newArrayList(); - } - // 注意此处不要使用 .toList() 新语法 因为返回的是不可变List 会导致序列化问题 - return collection.stream().sorted(comparing).collect(Collectors.toList()); - } - - /** - * 将collection转化为类型不变的map
- * {@code Collection ----> Map} - * - * @param collection 需要转化的集合 - * @param key V类型转化为K类型的lambda方法 - * @param collection中的泛型 - * @param map中的key类型 - * @return 转化后的map - */ - public static Map toIdentityMap(Collection collection, Function key) { - if (CollUtil.isEmpty(collection)) { - return MapUtil.newHashMap(); - } - return collection.stream().collect(Collectors.toMap(key, Function.identity(), (l, r) -> l)); - } - - /** - * 将Collection转化为map(value类型与collection的泛型不同)
- * {@code Collection -----> Map } - * - * @param collection 需要转化的集合 - * @param key E类型转化为K类型的lambda方法 - * @param value E类型转化为V类型的lambda方法 - * @param collection中的泛型 - * @param map中的key类型 - * @param map中的value类型 - * @return 转化后的map - */ - public static Map toMap(Collection collection, Function key, Function value) { - if (CollUtil.isEmpty(collection)) { - return MapUtil.newHashMap(); - } - return collection.stream().collect(Collectors.toMap(key, value, (l, r) -> l)); - } - - /** - * 将collection按照规则(比如有相同的班级id)分类成map
- * {@code Collection -------> Map> } - * - * @param collection 需要分类的集合 - * @param key 分类的规则 - * @param collection中的泛型 - * @param map中的key类型 - * @return 分类后的map - */ - public static Map> groupByKey(Collection collection, Function key) { - if (CollUtil.isEmpty(collection)) { - return MapUtil.newHashMap(); - } - return collection - .stream() - .collect(Collectors.groupingBy(key, LinkedHashMap::new, Collectors.toList())); - } - - /** - * 将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map
- * {@code Collection ---> Map>> } - * - * @param collection 需要分类的集合 - * @param key1 第一个分类的规则 - * @param key2 第二个分类的规则 - * @param 集合元素类型 - * @param 第一个map中的key类型 - * @param 第二个map中的key类型 - * @return 分类后的map - */ - public static Map>> groupBy2Key(Collection collection, Function key1, Function key2) { - if (CollUtil.isEmpty(collection)) { - return MapUtil.newHashMap(); - } - return collection - .stream() - .collect(Collectors.groupingBy(key1, LinkedHashMap::new, Collectors.groupingBy(key2, LinkedHashMap::new, Collectors.toList()))); - } - - /** - * 将collection按照两个规则(比如有相同的年级id,班级id)分类成双层map
- * {@code Collection ---> Map> } - * - * @param collection 需要分类的集合 - * @param key1 第一个分类的规则 - * @param key2 第二个分类的规则 - * @param 第一个map中的key类型 - * @param 第二个map中的key类型 - * @param collection中的泛型 - * @return 分类后的map - */ - public static Map> group2Map(Collection collection, Function key1, Function key2) { - if (CollUtil.isEmpty(collection) || key1 == null || key2 == null) { - return MapUtil.newHashMap(); - } - return collection - .stream() - .collect(Collectors.groupingBy(key1, LinkedHashMap::new, Collectors.toMap(key2, Function.identity(), (l, r) -> l))); - } - - /** - * 将collection转化为List集合,但是两者的泛型不同
- * {@code Collection ------> List } - * - * @param collection 需要转化的集合 - * @param function collection中的泛型转化为list泛型的lambda表达式 - * @param collection中的泛型 - * @param List中的泛型 - * @return 转化后的list - */ - public static List toList(Collection collection, Function function) { - if (CollUtil.isEmpty(collection)) { - return CollUtil.newArrayList(); - } - return collection - .stream() - .map(function) - .filter(Objects::nonNull) - // 注意此处不要使用 .toList() 新语法 因为返回的是不可变List 会导致序列化问题 - .collect(Collectors.toList()); - } - - /** - * 将collection转化为Set集合,但是两者的泛型不同
- * {@code Collection ------> Set } - * - * @param collection 需要转化的集合 - * @param function collection中的泛型转化为set泛型的lambda表达式 - * @param collection中的泛型 - * @param Set中的泛型 - * @return 转化后的Set - */ - public static Set toSet(Collection collection, Function function) { - if (CollUtil.isEmpty(collection) || function == null) { - return CollUtil.newHashSet(); - } - return collection - .stream() - .map(function) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - } - - - /** - * 合并两个相同key类型的map - * - * @param map1 第一个需要合并的 map - * @param map2 第二个需要合并的 map - * @param merge 合并的lambda,将key value1 value2合并成最终的类型,注意value可能为空的情况 - * @param map中的key类型 - * @param 第一个 map的value类型 - * @param 第二个 map的value类型 - * @param 最终map的value类型 - * @return 合并后的map - */ - public static Map merge(Map map1, Map map2, BiFunction merge) { - if (MapUtil.isEmpty(map1) && MapUtil.isEmpty(map2)) { - return MapUtil.newHashMap(); - } else if (MapUtil.isEmpty(map1)) { - map1 = MapUtil.newHashMap(); - } else if (MapUtil.isEmpty(map2)) { - map2 = MapUtil.newHashMap(); - } - Set key = new HashSet<>(); - key.addAll(map1.keySet()); - key.addAll(map2.keySet()); - Map map = new HashMap<>(); - for (K t : key) { - X x = map1.get(t); - Y y = map2.get(t); - V z = merge.apply(x, y); - if (z != null) { - map.put(t, z); - } - } - return map; - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/StringUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/StringUtils.java deleted file mode 100644 index 96b4b5c3..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/StringUtils.java +++ /dev/null @@ -1,321 +0,0 @@ -package cc.iotkit.common.utils; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.convert.Convert; -import cn.hutool.core.lang.Validator; -import cn.hutool.core.util.StrUtil; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.springframework.util.AntPathMatcher; - -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * 字符串工具类 - * - * @author Lion Li - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class StringUtils extends org.apache.commons.lang3.StringUtils { - - public static final String SEPARATOR = ","; - - /** - * 获取参数不为空值 - * - * @param str defaultValue 要判断的value - * @return value 返回值 - */ - public static String blankToDefault(String str, String defaultValue) { - return StrUtil.blankToDefault(str, defaultValue); - } - - /** - * * 判断一个字符串是否为空串 - * - * @param str String - * @return true:为空 false:非空 - */ - public static boolean isEmpty(String str) { - return StrUtil.isEmpty(str); - } - - /** - * * 判断一个字符串是否为非空串 - * - * @param str String - * @return true:非空串 false:空串 - */ - public static boolean isNotEmpty(String str) { - return !isEmpty(str); - } - - /** - * 去空格 - */ - public static String trim(String str) { - return StrUtil.trim(str); - } - - /** - * 截取字符串 - * - * @param str 字符串 - * @param start 开始 - * @return 结果 - */ - public static String substring(final String str, int start) { - return substring(str, start, str.length()); - } - - /** - * 截取字符串 - * - * @param str 字符串 - * @param start 开始 - * @param end 结束 - * @return 结果 - */ - public static String substring(final String str, int start, int end) { - return StrUtil.sub(str, start, end); - } - - /** - * 格式化文本, {} 表示占位符
- * 此方法只是简单将占位符 {} 按照顺序替换为参数
- * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可
- * 例:
- * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b
- * 转义{}: format("this is \\{} for {}", "a", "b") -> this is {} for a
- * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b
- * - * @param template 文本模板,被替换的部分用 {} 表示 - * @param params 参数值 - * @return 格式化后的文本 - */ - public static String format(String template, Object... params) { - return StrUtil.format(template, params); - } - - /** - * 是否为http(s)://开头 - * - * @param link 链接 - * @return 结果 - */ - public static boolean ishttp(String link) { - return Validator.isUrl(link); - } - - /** - * 字符串转set - * - * @param str 字符串 - * @param sep 分隔符 - * @return set集合 - */ - public static Set str2Set(String str, String sep) { - return new HashSet<>(str2List(str, sep, true, false)); - } - - /** - * 字符串转list - * - * @param str 字符串 - * @param sep 分隔符 - * @param filterBlank 过滤纯空白 - * @param trim 去掉首尾空白 - * @return list集合 - */ - public static List str2List(String str, String sep, boolean filterBlank, boolean trim) { - List list = new ArrayList<>(); - if (isEmpty(str)) { - return list; - } - - // 过滤空白字符串 - if (filterBlank && isBlank(str)) { - return list; - } - String[] split = str.split(sep); - for (String string : split) { - if (filterBlank && isBlank(string)) { - continue; - } - if (trim) { - string = trim(string); - } - list.add(string); - } - - return list; - } - - /** - * 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写 - * - * @param cs 指定字符串 - * @param searchCharSequences 需要检查的字符串数组 - * @return 是否包含任意一个字符串 - */ - public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) { - return StrUtil.containsAnyIgnoreCase(cs, searchCharSequences); - } - - /** - * 驼峰转下划线命名 - */ - public static String toUnderScoreCase(String str) { - return StrUtil.toUnderlineCase(str); - } - - /** - * 是否包含字符串 - * - * @param str 验证字符串 - * @param strs 字符串组 - * @return 包含返回true - */ - public static boolean inStringIgnoreCase(String str, String... strs) { - return StrUtil.equalsAnyIgnoreCase(str, strs); - } - - /** - * 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld - * - * @param name 转换前的下划线大写方式命名的字符串 - * @return 转换后的驼峰式命名的字符串 - */ - public static String convertToCamelCase(String name) { - return StrUtil.upperFirst(StrUtil.toCamelCase(name)); - } - - /** - * 驼峰式命名法 例如:user_name->userName - */ - public static String toCamelCase(String s) { - return StrUtil.toCamelCase(s); - } - - /** - * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串 - * - * @param str 指定字符串 - * @param strs 需要检查的字符串数组 - * @return 是否匹配 - */ - public static boolean matches(String str, List strs) { - if (isEmpty(str) || CollUtil.isEmpty(strs)) { - return false; - } - for (String pattern : strs) { - if (isMatch(pattern, str)) { - return true; - } - } - return false; - } - - /** - * 判断url是否与规则配置: - * ? 表示单个字符; - * * 表示一层路径内的任意字符串,不可跨层级; - * ** 表示任意层路径; - * - * @param pattern 匹配规则 - * @param url 需要匹配的url - */ - public static boolean isMatch(String pattern, String url) { - AntPathMatcher matcher = new AntPathMatcher(); - return matcher.match(pattern, url); - } - - /** - * 数字左边补齐0,使之达到指定长度。注意,如果数字转换为字符串后,长度大于size,则只保留 最后size个字符。 - * - * @param num 数字对象 - * @param size 字符串指定长度 - * @return 返回数字的字符串格式,该字符串为指定长度。 - */ - public static String padl(final Number num, final int size) { - return padl(num.toString(), size, '0'); - } - - /** - * 字符串左补齐。如果原始字符串s长度大于size,则只保留最后size个字符。 - * - * @param s 原始字符串 - * @param size 字符串指定长度 - * @param c 用于补齐的字符 - * @return 返回指定长度的字符串,由原字符串左补齐或截取得到。 - */ - public static String padl(final String s, final int size, final char c) { - final StringBuilder sb = new StringBuilder(size); - if (s != null) { - final int len = s.length(); - if (s.length() <= size) { - sb.append(String.valueOf(c).repeat(size - len)); - sb.append(s); - } else { - return s.substring(len - size, len); - } - } else { - sb.append(String.valueOf(c).repeat(Math.max(0, size))); - } - return sb.toString(); - } - - /** - * 切分字符串(分隔符默认逗号) - * - * @param str 被切分的字符串 - * @return 分割后的数据列表 - */ - public static List splitList(String str) { - return splitTo(str, Convert::toStr); - } - - /** - * 切分字符串 - * - * @param str 被切分的字符串 - * @param separator 分隔符 - * @return 分割后的数据列表 - */ - public static List splitList(String str, String separator) { - return splitTo(str, separator, Convert::toStr); - } - - /** - * 切分字符串自定义转换(分隔符默认逗号) - * - * @param str 被切分的字符串 - * @param mapper 自定义转换 - * @return 分割后的数据列表 - */ - public static List splitTo(String str, Function mapper) { - return splitTo(str, SEPARATOR, mapper); - } - - /** - * 切分字符串自定义转换 - * - * @param str 被切分的字符串 - * @param separator 分隔符 - * @param mapper 自定义转换 - * @return 分割后的数据列表 - */ - public static List splitTo(String str, String separator, Function mapper) { - if (isBlank(str)) { - return new ArrayList<>(0); - } - return StrUtil.split(str, separator) - .stream() - .filter(Objects::nonNull) - .map(mapper) - .collect(Collectors.toList()); - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ThreadUtil.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ThreadUtil.java deleted file mode 100644 index 20ec1381..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ThreadUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.utils; - -import java.util.concurrent.ScheduledThreadPoolExecutor; - -public class ThreadUtil { - - public static ScheduledThreadPoolExecutor newScheduled(int poolSize, String threadName) { - return new ScheduledThreadPoolExecutor(poolSize, (Runnable r) -> { - SecurityManager s = System.getSecurityManager(); - ThreadGroup group = (s != null) ? s.getThreadGroup() : - Thread.currentThread().getThreadGroup(); - Thread t = new Thread(group, r, - threadName, - 0); - if (t.isDaemon()) { - t.setDaemon(false); - } - if (t.getPriority() != Thread.NORM_PRIORITY) { - t.setPriority(Thread.NORM_PRIORITY); - } - return t; - }); - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/TreeBuildUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/TreeBuildUtils.java deleted file mode 100644 index 3be2d5f1..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/TreeBuildUtils.java +++ /dev/null @@ -1,35 +0,0 @@ -package cc.iotkit.common.utils; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.lang.tree.Tree; -import cn.hutool.core.lang.tree.TreeNodeConfig; -import cn.hutool.core.lang.tree.TreeUtil; -import cn.hutool.core.lang.tree.parser.NodeParser; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Collections; -import java.util.List; - -/** - * 扩展 hutool TreeUtil 封装系统树构建 - * - * @author Lion Li - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TreeBuildUtils extends TreeUtil { - - /** - * 根据前端定制差异化字段 - */ - public static final TreeNodeConfig DEFAULT_CONFIG = TreeNodeConfig.DEFAULT_CONFIG.setNameKey("label"); - - public static List> build(List list, NodeParser nodeParser) { - if (CollUtil.isEmpty(list)) { - return Collections.emptyList(); - } - K k = ReflectUtils.invokeGetter(list.get(0), "parentId"); - return TreeUtil.build(list, k, DEFAULT_CONFIG, nodeParser); - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/UniqueIdUtil.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/UniqueIdUtil.java deleted file mode 100644 index 1668fb1e..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/UniqueIdUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.utils; - -import org.apache.commons.lang3.RandomUtils; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.concurrent.atomic.AtomicInteger; - -public final class UniqueIdUtil { - - private static final int MACHINE_ID = RandomUtils.nextInt(10, 99); - - private static final AtomicInteger SEQUENCE = new AtomicInteger(1000); - - public static String newRequestId() { - return newUniqueId("RID"); - } - - public static String newUniqueId(String prefix) { - int id = SEQUENCE.getAndIncrement(); - if (id >= 5000) { - SEQUENCE.set(1000); - } - - return prefix + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + id + MACHINE_ID; - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ValidatorUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ValidatorUtils.java deleted file mode 100644 index 2e7a370f..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ValidatorUtils.java +++ /dev/null @@ -1,28 +0,0 @@ -package cc.iotkit.common.utils; - -import jakarta.validation.ConstraintViolation; -import jakarta.validation.ConstraintViolationException; -import jakarta.validation.Validator; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Set; - -/** - * Validator 校验框架工具 - * - * @author Lion Li - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ValidatorUtils { - - private static final Validator VALID = SpringUtils.getBean(Validator.class); - - public static void validate(T object, Class... groups) { - Set> validate = VALID.validate(object, groups); - if (!validate.isEmpty()) { - throw new ConstraintViolationException("参数校验异常", validate); - } - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/WeChatUtil.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/WeChatUtil.java deleted file mode 100644 index 760af4dd..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/WeChatUtil.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.utils; - -import cn.hutool.core.codec.Base64; -import lombok.extern.slf4j.Slf4j; -import org.bouncycastle.jce.provider.BouncyCastleProvider; - -import javax.crypto.Cipher; -import javax.crypto.spec.IvParameterSpec; -import javax.crypto.spec.SecretKeySpec; -import javax.net.ssl.HttpsURLConnection; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.security.Key; -import java.security.Security; -import java.util.Arrays; - -/** - * 微信小程序工具类 - */ -@Slf4j -public class WeChatUtil { - - public static String httpRequest(String requestUrl, String requestMethod, String output) { - try { - URL url = new URL(requestUrl); - HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); - connection.setDoOutput(true); - connection.setDoInput(true); - connection.setUseCaches(false); - connection.setRequestMethod(requestMethod); - if (null != output) { - OutputStream outputStream = connection.getOutputStream(); - outputStream.write(output.getBytes(StandardCharsets.UTF_8)); - outputStream.close(); - } - // 从输入流读取返回内容 - InputStream inputStream = connection.getInputStream(); - InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); - BufferedReader bufferedReader = new BufferedReader(inputStreamReader); - String str; - StringBuilder buffer = new StringBuilder(); - while ((str = bufferedReader.readLine()) != null) { - buffer.append(str); - } - bufferedReader.close(); - inputStreamReader.close(); - inputStream.close(); - connection.disconnect(); - return buffer.toString(); - } catch (Exception e) { - e.printStackTrace(); - } - return ""; - } - - public static String decryptData(String encryptDataB64, String sessionKeyB64, String ivB64) { - return new String( - decryptOfDiyIv( - Base64.decode(encryptDataB64), - Base64.decode(sessionKeyB64), - Base64.decode(ivB64) - ) - ); - } - - private static final String KEY_ALGORITHM = "AES"; - private static final String ALGORITHM_STR = "AES/CBC/PKCS7Padding"; - private static Key key; - private static Cipher cipher; - - private static void init(byte[] keyBytes) { - // 如果密钥不足16位,那么就补足. 这个if 中的内容很重要 - int base = 16; - if (keyBytes.length % base != 0) { - int groups = keyBytes.length / base + 1; - byte[] temp = new byte[groups * base]; - Arrays.fill(temp, (byte) 0); - System.arraycopy(keyBytes, 0, temp, 0, keyBytes.length); - keyBytes = temp; - } - // 初始化 - Security.addProvider(new BouncyCastleProvider()); - // 转化成JAVA的密钥格式 - key = new SecretKeySpec(keyBytes, KEY_ALGORITHM); - try { - // 初始化cipher - cipher = Cipher.getInstance(ALGORITHM_STR, "BC"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * 解密方法 - * - * @param encryptedData 要解密的字符串 - * @param keyBytes 解密密钥 - * @param ivs 自定义对称解密算法初始向量 iv - * @return 解密后的字节数组 - */ - private static byte[] decryptOfDiyIv(byte[] encryptedData, byte[] keyBytes, byte[] ivs) { - byte[] encryptedText = null; - init(keyBytes); - try { - cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(ivs)); - encryptedText = cipher.doFinal(encryptedData); - } catch (Exception e) { - e.printStackTrace(); - } - return encryptedText; - } - -} \ No newline at end of file diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/file/FileUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/file/FileUtils.java deleted file mode 100644 index 025fb11b..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/file/FileUtils.java +++ /dev/null @@ -1,16 +0,0 @@ -package cc.iotkit.common.utils.file; - -import cn.hutool.core.io.FileUtil; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -/** - * 文件处理工具类 - * - * @author Lion Li - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class FileUtils extends FileUtil { - - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/file/MimeTypeUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/file/MimeTypeUtils.java deleted file mode 100644 index 2f24e720..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/file/MimeTypeUtils.java +++ /dev/null @@ -1,40 +0,0 @@ -package cc.iotkit.common.utils.file; - -/** - * 媒体类型工具类 - * - * @author ruoyi - */ -public class MimeTypeUtils { - public static final String IMAGE_PNG = "image/png"; - - public static final String IMAGE_JPG = "image/jpg"; - - public static final String IMAGE_JPEG = "image/jpeg"; - - public static final String IMAGE_BMP = "image/bmp"; - - public static final String IMAGE_GIF = "image/gif"; - - public static final String[] IMAGE_EXTENSION = {"bmp", "gif", "jpg", "jpeg", "png"}; - - public static final String[] FLASH_EXTENSION = {"swf", "flv"}; - - public static final String[] MEDIA_EXTENSION = {"swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg", - "asf", "rm", "rmvb"}; - - public static final String[] VIDEO_EXTENSION = {"mp4", "avi", "rmvb"}; - - public static final String[] DEFAULT_ALLOWED_EXTENSION = { - // 图片 - "bmp", "gif", "jpg", "jpeg", "png", - // word excel powerpoint - "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt", - // 压缩文件 - "rar", "zip", "gz", "bz2", - // 视频格式 - "mp4", "avi", "rmvb", - // pdf - "pdf"}; - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ip/AddressUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ip/AddressUtils.java deleted file mode 100644 index dd741dd4..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ip/AddressUtils.java +++ /dev/null @@ -1,33 +0,0 @@ -package cc.iotkit.common.utils.ip; - -import cc.iotkit.common.utils.StringUtils; -import cn.hutool.core.net.NetUtil; -import cn.hutool.http.HtmlUtil; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -/** - * 获取地址类 - * - * @author Lion Li - */ -@Slf4j -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class AddressUtils { - - // 未知地址 - public static final String UNKNOWN = "XX XX"; - - public static String getRealAddressByIP(String ip) { - if (StringUtils.isBlank(ip)) { - return UNKNOWN; - } - // 内网不查询 - ip = "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip); - if (NetUtil.isInnerIP(ip)) { - return "内网IP"; - } - return RegionUtils.getCityInfo(ip); - } -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ip/RegionUtils.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ip/RegionUtils.java deleted file mode 100644 index 32abcd25..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/utils/ip/RegionUtils.java +++ /dev/null @@ -1,67 +0,0 @@ -package cc.iotkit.common.utils.ip; - -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.file.FileUtils; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.io.resource.ClassPathResource; -import cn.hutool.core.util.ObjectUtil; -import lombok.extern.slf4j.Slf4j; -import org.lionsoul.ip2region.xdb.Searcher; - -import java.io.File; - -/** - * 根据ip地址定位工具类,离线方式 - * 参考地址:集成 ip2region 实现离线IP地址定位库 - * - * @author lishuyan - */ -@Slf4j -public class RegionUtils { - - private static final Searcher SEARCHER; - - static { - String fileName = "/ip2region.xdb"; - File existFile = FileUtils.file(FileUtil.getTmpDir() + FileUtil.FILE_SEPARATOR + fileName); - if (!FileUtils.exist(existFile)) { - ClassPathResource fileStream = new ClassPathResource(fileName); - if (ObjectUtil.isEmpty(fileStream.getStream())) { - throw new BizException("RegionUtils初始化失败,原因:IP地址库数据不存在!"); - } - FileUtils.writeFromStream(fileStream.getStream(), existFile); - } - - String dbPath = existFile.getPath(); - - // 1、从 dbPath 加载整个 xdb 到内存。 - byte[] cBuff; - try { - cBuff = Searcher.loadContentFromFile(dbPath); - } catch (Exception e) { - throw new BizException("RegionUtils初始化失败,原因:从ip2region.xdb文件加载内容失败!" + e.getMessage()); - } - // 2、使用上述的 cBuff 创建一个完全基于内存的查询对象。 - try { - SEARCHER = Searcher.newWithBuffer(cBuff); - } catch (Exception e) { - throw new BizException("RegionUtils初始化失败,原因:" + e.getMessage()); - } - } - - /** - * 根据IP地址离线获取城市 - */ - public static String getCityInfo(String ip) { - try { - ip = ip.trim(); - // 3、执行查询 - String region = SEARCHER.search(ip); - return region.replace("0|", "").replace("|0", ""); - } catch (Exception e) { - log.error("IP地址离线获取城市异常 {}", ip); - return "未知"; - } - } - -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/AddGroup.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/AddGroup.java deleted file mode 100644 index 1537625c..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/AddGroup.java +++ /dev/null @@ -1,9 +0,0 @@ -package cc.iotkit.common.validate; - -/** - * 校验分组 add - * - * @author Lion Li - */ -public interface AddGroup { -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/DeleteGroup.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/DeleteGroup.java deleted file mode 100644 index 9f4b9c45..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/DeleteGroup.java +++ /dev/null @@ -1,9 +0,0 @@ -package cc.iotkit.common.validate; - -/** - * 校验分组 delete - * - * @author Lion Li - */ -public interface DeleteGroup { -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/EditGroup.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/EditGroup.java deleted file mode 100644 index 8fe56f4f..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/EditGroup.java +++ /dev/null @@ -1,9 +0,0 @@ -package cc.iotkit.common.validate; - -/** - * 校验分组 edit - * - * @author Lion Li - */ -public interface EditGroup { -} diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/QueryGroup.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/QueryGroup.java deleted file mode 100644 index f3f1d091..00000000 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/validate/QueryGroup.java +++ /dev/null @@ -1,9 +0,0 @@ -package cc.iotkit.common.validate; - -/** - * 校验分组 query - * - * @author Lion Li - */ -public interface QueryGroup { -} diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/protocol/ProtocolComponent.java b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/protocol/ProtocolComponent.java deleted file mode 100644 index cad39e2c..00000000 --- a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/protocol/ProtocolComponent.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.model.protocol; - -import cc.iotkit.model.Owned; -import lombok.Data; - -@Data -public class ProtocolComponent implements Owned { - - public static final String STATE_STOPPED = "stopped"; - public static final String STATE_RUNNING = "running"; - public static final String TYPE_DEVICE = "device"; - public static final String TYPE_BIZ = "biz"; - /** - * 转换器类型:静态 - */ - public static final String CONVER_TYPE_STATIC = "static"; - /** - * 转换器类型:自定义 - */ - public static final String CONVER_TYPE_CUSTOM = "custom"; - - public static final String SCRIPT_FILE_NAME = "component.js"; - - private String id; - - /** - * 所属性用户id - */ - private String uid; - - private String name; - - private String type = TYPE_DEVICE; - - private String protocol; - - private String jarFile; - - private String config; - - private String converter; - - private String converType = CONVER_TYPE_CUSTOM; - - private String state; - - private Long createAt; - - private String scriptTyp; - - private String script; - -} diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/protocol/ProtocolConverter.java b/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/protocol/ProtocolConverter.java deleted file mode 100644 index 8e8c590f..00000000 --- a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/protocol/ProtocolConverter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.model.protocol; - -import cc.iotkit.model.Owned; -import lombok.Data; - -@Data -public class ProtocolConverter implements Owned { - - public static final String SCRIPT_FILE_NAME = "converter.js"; - - private String id; - - /** - * 所属性用户id - */ - private String uid; - - private String name; - - private String desc; - - private Long createAt; - - /** - * 脚本类型 - */ - private String typ; - - /** - * 脚本内容 - */ - private String script; -} diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProtocolComponentData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProtocolComponentData.java deleted file mode 100644 index 7f8d9789..00000000 --- a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProtocolComponentData.java +++ /dev/null @@ -1,14 +0,0 @@ -package cc.iotkit.data.manager; - -import cc.iotkit.data.IOwnedData; -import cc.iotkit.model.protocol.ProtocolComponent; - -import java.util.List; - -public interface IProtocolComponentData extends IOwnedData { - - List findByState(String state); - - List findByStateAndType(String state, String type); - -} diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProtocolConverterData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProtocolConverterData.java deleted file mode 100644 index d1c0ce8d..00000000 --- a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProtocolConverterData.java +++ /dev/null @@ -1,8 +0,0 @@ -package cc.iotkit.data.manager; - -import cc.iotkit.data.IOwnedData; -import cc.iotkit.model.protocol.ProtocolConverter; - -public interface IProtocolConverterData extends IOwnedData { - -} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProtocolComponentRepository.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProtocolComponentRepository.java deleted file mode 100644 index 8c309f18..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProtocolComponentRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.data.dao; - -import cc.iotkit.data.model.TbProtocolComponent; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.querydsl.QuerydslPredicateExecutor; - -import java.util.List; - -public interface ProtocolComponentRepository extends JpaRepository, QuerydslPredicateExecutor{ - - List findByState(String state); - - List findByStateAndType(String state, String type); - - List findByUid(String uid); - - Page findByUid(String uid, Pageable pageable); - - long countByUid(String uid); - -} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProtocolConverterRepository.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProtocolConverterRepository.java deleted file mode 100644 index b02dc54d..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProtocolConverterRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.data.dao; - -import cc.iotkit.data.model.TbProtocolConverter; -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 ProtocolConverterRepository extends JpaRepository { - - List findByUid(String uid); - - Page findByUid(String uid, Pageable pageable); - - long countByUid(String uid); - -} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProtocolComponent.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProtocolComponent.java deleted file mode 100644 index 61f5d23c..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProtocolComponent.java +++ /dev/null @@ -1,71 +0,0 @@ -package cc.iotkit.data.model; - -import cc.iotkit.model.protocol.ProtocolComponent; -import io.github.linpeilie.annotations.AutoMapper; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import org.hibernate.annotations.GenericGenerator; - -import javax.persistence.*; - -@Data -@Entity -@Table(name = "protocol_component") -@AutoMapper(target = ProtocolComponent.class) -public class TbProtocolComponent { - - @Id - @GeneratedValue(generator = "SnowflakeIdGenerator") - @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") - private String id; - - /** - * 所属性用户id - */ - @ApiModelProperty(value = "所属性用户id") - private String uid; - - @ApiModelProperty(value = "组件名称") - private String name; - - @ApiModelProperty(value = "组件类型") - - private String type; - - @ApiModelProperty(value = "通讯协议") - - private String protocol; - - @ApiModelProperty(value = "jar包") - - private String jarFile; - - @Column(columnDefinition = "text") - private String config; - - @ApiModelProperty(value = "转换脚本") - - private String converter; - - @ApiModelProperty(value = "转换器类型") - - private String converType; - - @ApiModelProperty(value = "运行状态") - - private String state; - - @ApiModelProperty(value = "创建时间") - - private Long createAt; - - @ApiModelProperty(value = "通讯脚本语言类型") - - private String scriptTyp; - - @ApiModelProperty(value = "脚本内容") - - @Column(columnDefinition = "text")//设置映射为text类型 - private String script; - -} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProtocolConverter.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProtocolConverter.java deleted file mode 100644 index a783fccd..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProtocolConverter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.data.model; - -import cc.iotkit.model.protocol.ProtocolConverter; -import io.github.linpeilie.annotations.AutoMapper; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import org.hibernate.annotations.GenericGenerator; - -import javax.persistence.*; - -@Data -@Entity -@Table(name = "protocol_converter") -@AutoMapper(target = ProtocolConverter.class) -public class TbProtocolConverter { - - @Id - @GeneratedValue(generator = "SnowflakeIdGenerator") - @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") - private String id; - - /** - * 所属性用户id - */ - @ApiModelProperty(value = "所属性用户id") - private String uid; - - @ApiModelProperty(value = "转换器名称") - private String name; - - @Column(name = "[desc]") - @ApiModelProperty(value = "描述") - private String desc; - - @ApiModelProperty(value = "创建时间") - private Long createAt; - - @ApiModelProperty(value = "转换脚本类型") - private String typ; - - // 脚本内容 - @Column(columnDefinition = "text")//设置映射为text类型 - @ApiModelProperty(value = "脚本内容") - private String script; - -} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProtocolComponentDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProtocolComponentDataImpl.java deleted file mode 100644 index 32171a09..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProtocolComponentDataImpl.java +++ /dev/null @@ -1,119 +0,0 @@ -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.ProtocolComponentRepository; -import cc.iotkit.data.manager.IProtocolComponentData; -import cc.iotkit.data.model.TbProtocolComponent; -import cc.iotkit.data.util.PageBuilder; -import cc.iotkit.data.util.PredicateBuilder; -import cc.iotkit.model.protocol.ProtocolComponent; -import com.querydsl.core.types.Predicate; -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.Collection; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -@Primary -@Service -public class ProtocolComponentDataImpl implements IProtocolComponentData, IJPACommData { - - @Autowired - private ProtocolComponentRepository protocolComponentRepository; - - @Override - public JpaRepository getBaseRepository() { - return protocolComponentRepository; - } - - @Override - public Class getJpaRepositoryClass() { - return TbProtocolComponent.class; - } - - @Override - public Class getTClass() { - return ProtocolComponent.class; - } - - @Override - public List findByState(String state) { - return MapstructUtils.convert(protocolComponentRepository.findByState(state), ProtocolComponent.class); - } - - @Override - public List findByStateAndType(String state, String type) { - return MapstructUtils.convert(protocolComponentRepository.findByStateAndType(state, type), ProtocolComponent.class); - } - - @Override - public List findByUid(String uid) { - return MapstructUtils.convert(protocolComponentRepository.findByUid(uid), ProtocolComponent.class); - } - - @Override - public Paging findByUid(String uid, int page, int size) { - Page paged = protocolComponentRepository.findByUid(uid, - Pageable.ofSize(size).withPage(page - 1)); - return new Paging<>(paged.getTotalElements(), - MapstructUtils.convert(paged.getContent(), ProtocolComponent.class)); - } - - @Override - public long countByUid(String uid) { - return protocolComponentRepository.countByUid(uid); - } - - @Override - public ProtocolComponent findById(String s) { - return MapstructUtils.convert(protocolComponentRepository.findById(s).orElse(null), ProtocolComponent.class); - } - - @Override - public List findByIds(Collection id) { - return Collections.emptyList(); - } - - @Override - public ProtocolComponent save(ProtocolComponent data) { - if (StringUtils.isBlank(data.getId())) { - data.setId(UUID.randomUUID().toString()); - data.setCreateAt(System.currentTimeMillis()); - } - protocolComponentRepository.save(MapstructUtils.convert(data, TbProtocolComponent.class)); - return data; - } - - @Override - public void deleteById(String s) { - protocolComponentRepository.deleteById(s); - } - - @Override - public List findAll() { - return MapstructUtils.convert(protocolComponentRepository.findAll(), ProtocolComponent.class); - } - - @Override - public Paging findAll(PageRequest pageRequest) { - - Predicate predicate = PredicateBuilder.instance() - .build(); - Page all = protocolComponentRepository.findAll(predicate, PageBuilder.toPageable(pageRequest)); - return new Paging<>(all.getTotalElements(), MapstructUtils.convert(all.getContent(), ProtocolComponent.class)); - } - - - - -} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProtocolConverterDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProtocolConverterDataImpl.java deleted file mode 100644 index c25ef3b6..00000000 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProtocolConverterDataImpl.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -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.ProtocolConverterRepository; -import cc.iotkit.data.manager.IProtocolConverterData; -import cc.iotkit.data.model.TbProtocolConverter; -import cc.iotkit.model.protocol.ProtocolConverter; -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.Collection; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -@Primary -@Service -public class ProtocolConverterDataImpl implements IProtocolConverterData, IJPACommData { - - @Autowired - private ProtocolConverterRepository protocolConverterRepository; - - @Override - public JpaRepository getBaseRepository() { - return protocolConverterRepository; - } - - @Override - public Class getJpaRepositoryClass() { - return TbProtocolConverter.class; - } - - @Override - public Class getTClass() { - return ProtocolConverter.class; - } - - @Override - public List findByUid(String uid) { - return MapstructUtils.convert(protocolConverterRepository.findByUid(uid), ProtocolConverter.class); - } - - @Override - public Paging findByUid(String uid, int page, int size) { - Page paged = protocolConverterRepository - .findByUid(uid, Pageable.ofSize(size).withPage(page - 1)); - return new Paging<>(paged.getTotalElements(), - MapstructUtils.convert(paged.getContent(), ProtocolConverter.class)); - } - - @Override - public long countByUid(String uid) { - return protocolConverterRepository.countByUid(uid); - } - - - - @Override - public ProtocolConverter findById(String s) { - return MapstructUtils.convert( - protocolConverterRepository.findById(s).orElse(null), ProtocolConverter.class); - } - - @Override - public List findByIds(Collection id) { - return Collections.emptyList(); - } - - @Override - public ProtocolConverter save(ProtocolConverter data) { - if (StringUtils.isBlank(data.getId())) { - data.setId(UUID.randomUUID().toString()); - data.setCreateAt(System.currentTimeMillis()); - } - protocolConverterRepository.save(MapstructUtils.convert(data, TbProtocolConverter.class)); - return data; - } - - -} diff --git a/iot-common/iot-common-doc/pom.xml b/iot-common/iot-common-doc/pom.xml deleted file mode 100644 index 28a69ea7..00000000 --- a/iot-common/iot-common-doc/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-common-doc - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.projectlombok - lombok - true - - - - - com.github.xiaoymin - knife4j-spring-boot-starter - - - org.mapstruct - mapstruct - - - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerAutoConfiguration.java b/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerAutoConfiguration.java deleted file mode 100644 index 418b6285..00000000 --- a/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerAutoConfiguration.java +++ /dev/null @@ -1,15 +0,0 @@ -package cc.iotkit.swagger.config; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -/** - * @Author: 石恒 - * @Date: 2023/5/6 22:03 - * @Description: - */ -@Configuration -@ComponentScan(basePackages = {"cc.iotkit.swagger"}) -public class SwaggerAutoConfiguration { - -} diff --git a/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerConfig.java b/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerConfig.java deleted file mode 100644 index ad57d232..00000000 --- a/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerConfig.java +++ /dev/null @@ -1,130 +0,0 @@ -package cc.iotkit.swagger.config; - -import io.swagger.annotations.ApiOperation; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.context.annotation.Bean; -import org.springframework.stereotype.Component; -import org.springframework.util.ReflectionUtils; -import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider; -import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; - -import java.lang.reflect.Field; -import java.util.List; - -/** - * @Author: 石恒 - * @Date: 2023/5/4 20:12 - * @Description: - */ -@Component -@EnableSwagger2WebMvc - -public class SwaggerConfig { - - @Value("${spring.application.name:Swagger API}") - private String applicationName; - - @Bean(value = "defaultApi2") - public Docket defaultApi2() { - return new Docket(DocumentationType.SWAGGER_2) - .groupName(applicationName) - .enable(true) - .apiInfo(apiInfo()) - .select() - .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) - .paths(PathSelectors.any()) - .build(); - } - - private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title(applicationName) - .description("Swagger API Doc") - .build(); - } - - // 解决springboot升级到2.6.x之后,knife4j报错 - @Bean - public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() { - return new BeanPostProcessor() { - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { -// if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) { - if (bean instanceof WebMvcRequestHandlerProvider ) { - customizeSpringfoxHandlerMappings(getHandlerMappings(bean)); - } - return bean; - } - - private void customizeSpringfoxHandlerMappings(List mappings) { - mappings.removeIf(mapping -> mapping.getPatternParser() != null); - } - - @SuppressWarnings("unchecked") - private List getHandlerMappings(Object bean) { - try { - Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings"); - field.setAccessible(true); - return (List) field.get(bean); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new IllegalStateException(e); - } - } - }; - } - -// /** -// * 解决springboot升级到2.6.x之后,knife4j报错 -// * -// * @param webEndpointsSupplier the web endpoints supplier -// * @param servletEndpointsSupplier the servlet endpoints supplier -// * @param controllerEndpointsSupplier the controller endpoints supplier -// * @param endpointMediaTypes the endpoint media types -// * @param corsProperties the cors properties -// * @param webEndpointProperties the web endpoint properties -// * @param environment the environment -// * @return the web mvc endpoint handler mapping -// */ -// @Bean -// public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping( -// WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, -// ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, -// CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, -// Environment environment) { -// List> allEndpoints = new ArrayList<>(); -// Collection webEndpoints = webEndpointsSupplier.getEndpoints(); -// allEndpoints.addAll(webEndpoints); -// allEndpoints.addAll(servletEndpointsSupplier.getEndpoints()); -// allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints()); -// String basePath = webEndpointProperties.getBasePath(); -// EndpointMapping endpointMapping = new EndpointMapping(basePath); -// boolean shouldRegisterLinksMapping = shouldRegisterLinksMapping(webEndpointProperties, -// environment, basePath); -// return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, -// corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), -// shouldRegisterLinksMapping, null); -// } -// -// /** -// * shouldRegisterLinksMapping -// * @param webEndpointProperties webEndpointProperties -// * @param environment environment -// * @param basePath / -// * @return boolean -// */ -// private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, -// Environment environment, String basePath) { -// return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) -// || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT)); -// } -} diff --git a/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerProperties.java b/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerProperties.java deleted file mode 100644 index 2430c994..00000000 --- a/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerProperties.java +++ /dev/null @@ -1,60 +0,0 @@ -package cc.iotkit.swagger.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * @Author: 石恒 - * @Date: 2023/5/6 22:26 - * @Description: - */ -@Data -@Component -@ConfigurationProperties(prefix = "swagger") -public class SwaggerProperties { - private Boolean enabled; - private String title; //标题 - private String group; //自定义组名 - private String description = "在线文档"; //描述 - private String version = "1.0"; //版本 - private Contact contact = new Contact(); //联系人 - private String basePackage = "com.example"; //swagger会解析的包路径 - private List basePath = new ArrayList<>(); //swagger会解析的url规则 - private List excludePath = new ArrayList<>();//在basePath基础上需要排除的url规则 - private Map docket = new LinkedHashMap<>(); //分组文档 - public String getGroup() { - if (group == null || "".equals(group)) { - return title; - } - return group; - } - @Data - public static class DocketInfo { - private String title = "在线文档"; //标题 - private String group = ""; //自定义组名 - private String description = "在线文档"; //描述 - private String version = "1.0"; //版本 - private Contact contact = new Contact(); //联系人 - private String basePackage = "com.example"; //swagger会解析的包路径 - private List basePath = new ArrayList<>(); //swagger会解析的url规则 - private List excludePath = new ArrayList<>();//在basePath基础上需要排除的url - public String getGroup() { - if (group == null || "".equals(group)) { - return title; - } - return group; - } - } - @Data - public static class Contact { - private String name = ""; //联系人 - private String url = ""; //联系人url - private String email = ""; //联系人email - } -} diff --git a/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerWebConfiguration.java b/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerWebConfiguration.java deleted file mode 100644 index a7d3e16b..00000000 --- a/iot-common/iot-common-doc/src/main/java/cc/iotkit/swagger/config/SwaggerWebConfiguration.java +++ /dev/null @@ -1,20 +0,0 @@ -package cc.iotkit.swagger.config; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -/** - * @Author: 石恒 - * @Date: 2023/5/6 22:03 - * @Description: - */ -@Configuration -public class SwaggerWebConfiguration implements WebMvcConfigurer { - - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("swagger-ui.html", "doc.html").addResourceLocations("classpath:/META-INF/resources/"); - registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); - } -} diff --git a/iot-common/iot-common-doc/src/main/resources/META-INF/spring.factories b/iot-common/iot-common-doc/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 7b54cfdb..00000000 --- a/iot-common/iot-common-doc/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - cc.iotkit.swagger.config.SwaggerAutoConfiguration,\ - cc.iotkit.swagger.config.SwaggerWebConfiguration \ No newline at end of file diff --git a/iot-common/iot-common-excel/pom.xml b/iot-common/iot-common-excel/pom.xml deleted file mode 100644 index dbd5e02c..00000000 --- a/iot-common/iot-common-excel/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-common-excel - - - - - cc.iotkit - iot-common-web - - - - cc.iotkit - iot-common-core - - - - - - com.alibaba - easyexcel - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/annotation/CellMerge.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/annotation/CellMerge.java deleted file mode 100644 index 91d6a47f..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/annotation/CellMerge.java +++ /dev/null @@ -1,25 +0,0 @@ -package cc.iotkit.common.excel.annotation; - - -import cc.iotkit.common.excel.core.CellMergeStrategy; - -import java.lang.annotation.*; - -/** - * excel 列单元格合并(合并列相同项) - * - * 需搭配 {@link CellMergeStrategy} 策略使用 - * - * @author Lion Li - */ -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -public @interface CellMerge { - - /** - * col index - */ - int index() default -1; - -} diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/annotation/ExcelDictFormat.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/annotation/ExcelDictFormat.java deleted file mode 100644 index 3c695511..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/annotation/ExcelDictFormat.java +++ /dev/null @@ -1,33 +0,0 @@ -package cc.iotkit.common.excel.annotation; - - -import cc.iotkit.common.utils.StringUtils; - -import java.lang.annotation.*; - -/** - * 字典格式化 - * - * @author Lion Li - */ -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -public @interface ExcelDictFormat { - - /** - * 如果是字典类型,请设置字典的type值 (如: sys_user_sex) - */ - String dictType() default ""; - - /** - * 读取内容转表达式 (如: 0=男,1=女,2=未知) - */ - String readConverterExp() default ""; - - /** - * 分隔符,读取字符串组内容 - */ - String separator() default StringUtils.SEPARATOR; - -} diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/annotation/ExcelEnumFormat.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/annotation/ExcelEnumFormat.java deleted file mode 100644 index 5a39c1a3..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/annotation/ExcelEnumFormat.java +++ /dev/null @@ -1,30 +0,0 @@ -package cc.iotkit.common.excel.annotation; - -import java.lang.annotation.*; - -/** - * 枚举格式化 - * - * @author Liang - */ -@Target({ElementType.FIELD}) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -public @interface ExcelEnumFormat { - - /** - * 字典枚举类型 - */ - Class> enumClass(); - - /** - * 字典枚举类中对应的code属性名称,默认为code - */ - String codeField() default "code"; - - /** - * 字典枚举类中对应的text属性名称,默认为text - */ - String textField() default "text"; - -} diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/convert/ExcelBigNumberConvert.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/convert/ExcelBigNumberConvert.java deleted file mode 100644 index 15d47dff..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/convert/ExcelBigNumberConvert.java +++ /dev/null @@ -1,52 +0,0 @@ -package cc.iotkit.common.excel.convert; - -import cn.hutool.core.convert.Convert; -import cn.hutool.core.util.ObjectUtil; -import com.alibaba.excel.converters.Converter; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.GlobalConfiguration; -import com.alibaba.excel.metadata.data.ReadCellData; -import com.alibaba.excel.metadata.data.WriteCellData; -import com.alibaba.excel.metadata.property.ExcelContentProperty; -import lombok.extern.slf4j.Slf4j; - -import java.math.BigDecimal; - -/** - * 大数值转换 - * Excel 数值长度位15位 大于15位的数值转换位字符串 - * - * @author Lion Li - */ -@Slf4j -public class ExcelBigNumberConvert implements Converter { - - @Override - public Class supportJavaTypeKey() { - return Long.class; - } - - @Override - public CellDataTypeEnum supportExcelTypeKey() { - return CellDataTypeEnum.STRING; - } - - @Override - public Long convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - return Convert.toLong(cellData.getData()); - } - - @Override - public WriteCellData convertToExcelData(Long object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - if (ObjectUtil.isNotNull(object)) { - String str = Convert.toStr(object); - if (str.length() > 15) { - return new WriteCellData<>(str); - } - } - WriteCellData cellData = new WriteCellData<>(new BigDecimal(object)); - cellData.setType(CellDataTypeEnum.NUMBER); - return cellData; - } - -} diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/convert/ExcelDictConvert.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/convert/ExcelDictConvert.java deleted file mode 100644 index 62e96730..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/convert/ExcelDictConvert.java +++ /dev/null @@ -1,73 +0,0 @@ -package cc.iotkit.common.excel.convert; - -import cc.iotkit.common.excel.annotation.ExcelDictFormat; -import cc.iotkit.common.excel.utils.ExcelUtil; -import cc.iotkit.common.service.DictService; -import cc.iotkit.common.utils.SpringUtils; -import cc.iotkit.common.utils.StringUtils; -import cn.hutool.core.annotation.AnnotationUtil; -import cn.hutool.core.convert.Convert; -import cn.hutool.core.util.ObjectUtil; -import com.alibaba.excel.converters.Converter; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.GlobalConfiguration; -import com.alibaba.excel.metadata.data.ReadCellData; -import com.alibaba.excel.metadata.data.WriteCellData; -import com.alibaba.excel.metadata.property.ExcelContentProperty; -import lombok.extern.slf4j.Slf4j; - -import java.lang.reflect.Field; - -/** - * 字典格式化转换处理 - * - * @author Lion Li - */ -@Slf4j -public class ExcelDictConvert implements Converter { - - @Override - public Class supportJavaTypeKey() { - return Object.class; - } - - @Override - public CellDataTypeEnum supportExcelTypeKey() { - return null; - } - - @Override - public Object convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - ExcelDictFormat anno = getAnnotation(contentProperty.getField()); - String type = anno.dictType(); - String label = cellData.getStringValue(); - String value; - if (StringUtils.isBlank(type)) { - value = ExcelUtil.reverseByExp(label, anno.readConverterExp(), anno.separator()); - } else { - value = SpringUtils.getBean(DictService.class).getDictValue(type, label, anno.separator()); - } - return Convert.convert(contentProperty.getField().getType(), value); - } - - @Override - public WriteCellData convertToExcelData(Object object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - if (ObjectUtil.isNull(object)) { - return new WriteCellData<>(""); - } - ExcelDictFormat anno = getAnnotation(contentProperty.getField()); - String type = anno.dictType(); - String value = Convert.toStr(object); - String label; - if (StringUtils.isBlank(type)) { - label = ExcelUtil.convertByExp(value, anno.readConverterExp(), anno.separator()); - } else { - label = SpringUtils.getBean(DictService.class).getDictLabel(type, value, anno.separator()); - } - return new WriteCellData<>(label); - } - - private ExcelDictFormat getAnnotation(Field field) { - return AnnotationUtil.getAnnotation(field, ExcelDictFormat.class); - } -} diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/convert/ExcelEnumConvert.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/convert/ExcelEnumConvert.java deleted file mode 100644 index 766320c6..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/convert/ExcelEnumConvert.java +++ /dev/null @@ -1,75 +0,0 @@ -package cc.iotkit.common.excel.convert; - -import cc.iotkit.common.excel.annotation.ExcelEnumFormat; -import cc.iotkit.common.utils.ReflectUtils; -import cn.hutool.core.annotation.AnnotationUtil; -import cn.hutool.core.convert.Convert; -import cn.hutool.core.util.ObjectUtil; -import com.alibaba.excel.converters.Converter; -import com.alibaba.excel.enums.CellDataTypeEnum; -import com.alibaba.excel.metadata.GlobalConfiguration; -import com.alibaba.excel.metadata.data.ReadCellData; -import com.alibaba.excel.metadata.data.WriteCellData; -import com.alibaba.excel.metadata.property.ExcelContentProperty; -import lombok.extern.slf4j.Slf4j; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - -/** - * 枚举格式化转换处理 - * - * @author Liang - */ -@Slf4j -public class ExcelEnumConvert implements Converter { - - @Override - public Class supportJavaTypeKey() { - return Object.class; - } - - @Override - public CellDataTypeEnum supportExcelTypeKey() { - return null; - } - - @Override - public Object convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - Object codeValue = cellData.getData(); - // 如果是空值 - if (ObjectUtil.isNull(codeValue)) { - return null; - } - Map enumValueMap = beforeConvert(contentProperty); - String textValue = enumValueMap.get(codeValue); - return Convert.convert(contentProperty.getField().getType(), textValue); - } - - @Override - public WriteCellData convertToExcelData(Object object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - if (ObjectUtil.isNull(object)) { - return new WriteCellData<>(""); - } - Map enumValueMap = beforeConvert(contentProperty); - String value = Convert.toStr(enumValueMap.get(object), ""); - return new WriteCellData<>(value); - } - - private Map beforeConvert(ExcelContentProperty contentProperty) { - ExcelEnumFormat anno = getAnnotation(contentProperty.getField()); - Map enumValueMap = new HashMap<>(); - Enum[] enumConstants = anno.enumClass().getEnumConstants(); - for (Enum enumConstant : enumConstants) { - Object codeValue = ReflectUtils.invokeGetter(enumConstant, anno.codeField()); - String textValue = ReflectUtils.invokeGetter(enumConstant, anno.textField()); - enumValueMap.put(codeValue, textValue); - } - return enumValueMap; - } - - private ExcelEnumFormat getAnnotation(Field field) { - return AnnotationUtil.getAnnotation(field, ExcelEnumFormat.class); - } -} diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/CellMergeStrategy.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/CellMergeStrategy.java deleted file mode 100644 index 392a9de2..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/CellMergeStrategy.java +++ /dev/null @@ -1,118 +0,0 @@ -package cc.iotkit.common.excel.core; - -import cc.iotkit.common.excel.annotation.CellMerge; -import cc.iotkit.common.utils.ReflectUtils; -import cn.hutool.core.collection.CollUtil; -import com.alibaba.excel.annotation.ExcelProperty; -import com.alibaba.excel.metadata.Head; -import com.alibaba.excel.write.merge.AbstractMergeStrategy; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.util.CellRangeAddress; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * 列值重复合并策略 - * - * @author Lion Li - */ -@Slf4j -public class CellMergeStrategy extends AbstractMergeStrategy { - - private final List list; - private final boolean hasTitle; - private int rowIndex; - - public CellMergeStrategy(List list, boolean hasTitle) { - this.list = list; - this.hasTitle = hasTitle; - // 行合并开始下标 - this.rowIndex = hasTitle ? 1 : 0; - } - - @Override - protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) { - List cellList = handle(list, hasTitle); - // the judge is necessary - if (CollUtil.isNotEmpty(cellList) && cell.getRowIndex() == rowIndex && cell.getColumnIndex() == 0) { - for (CellRangeAddress item : cellList) { - sheet.addMergedRegion(item); - } - } - } - - @SneakyThrows - private List handle(List list, boolean hasTitle) { - List cellList = new ArrayList<>(); - if (CollUtil.isEmpty(list)) { - return cellList; - } - Field[] fields = ReflectUtils.getFields(list.get(0).getClass(), field -> !"serialVersionUID".equals(field.getName())); - - // 有注解的字段 - List mergeFields = new ArrayList<>(); - List mergeFieldsIndex = new ArrayList<>(); - for (int i = 0; i < fields.length; i++) { - Field field = fields[i]; - if (field.isAnnotationPresent(CellMerge.class)) { - CellMerge cm = field.getAnnotation(CellMerge.class); - mergeFields.add(field); - mergeFieldsIndex.add(cm.index() == -1 ? i : cm.index()); - if (hasTitle) { - ExcelProperty property = field.getAnnotation(ExcelProperty.class); - rowIndex = Math.max(rowIndex, property.value().length); - } - } - } - - Map map = new HashMap<>(); - // 生成两两合并单元格 - for (int i = 0; i < list.size(); i++) { - for (int j = 0; j < mergeFields.size(); j++) { - Field field = mergeFields.get(j); - Object val = ReflectUtils.invokeGetter(list.get(i), field.getName()); - - int colNum = mergeFieldsIndex.get(j); - if (!map.containsKey(field)) { - map.put(field, new RepeatCell(val, i)); - } else { - RepeatCell repeatCell = map.get(field); - Object cellValue = repeatCell.getValue(); - if (cellValue == null || "".equals(cellValue)) { - // 空值跳过不合并 - continue; - } - if (!cellValue.equals(val)) { - if (i - repeatCell.getCurrent() > 1) { - cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex - 1, colNum, colNum)); - } - map.put(field, new RepeatCell(val, i)); - } else if ((i == list.size() - 1) && (i > repeatCell.getCurrent())) { - cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum)); - - } - } - } - } - return cellList; - } - - @Data - @AllArgsConstructor - static class RepeatCell { - - private Object value; - - private int current; - - } -} diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/DefaultExcelListener.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/DefaultExcelListener.java deleted file mode 100644 index 8c937288..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/DefaultExcelListener.java +++ /dev/null @@ -1,106 +0,0 @@ -package cc.iotkit.common.excel.core; - -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.common.utils.StreamUtils; -import cc.iotkit.common.utils.ValidatorUtils; -import cn.hutool.core.text.CharSequenceUtil; -import com.alibaba.excel.context.AnalysisContext; -import com.alibaba.excel.event.AnalysisEventListener; -import com.alibaba.excel.exception.ExcelAnalysisException; -import com.alibaba.excel.exception.ExcelDataConvertException; -import jakarta.validation.ConstraintViolation; -import jakarta.validation.ConstraintViolationException; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.util.Map; -import java.util.Set; - -/** - * Excel 导入监听 - * - * @author Yjoioooo - * @author Lion Li - */ -@Slf4j -@NoArgsConstructor -public class DefaultExcelListener extends AnalysisEventListener implements ExcelListener { - - /** - * 是否Validator检验,默认为是 - */ - private Boolean isValidate = Boolean.TRUE; - - /** - * excel 表头数据 - */ - private Map headMap; - - /** - * 导入回执 - */ - private ExcelResult excelResult; - - public DefaultExcelListener(boolean isValidate) { - this.excelResult = new DefaultExcelResult<>(); - this.isValidate = isValidate; - } - - /** - * 处理异常 - * - * @param exception ExcelDataConvertException - * @param context Excel 上下文 - */ - @Override - public void onException(Exception exception, AnalysisContext context) throws Exception { - String errMsg = null; - if (exception instanceof ExcelDataConvertException) { - ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException) exception; - // 如果是某一个单元格的转换异常 能获取到具体行号 - Integer rowIndex = excelDataConvertException.getRowIndex(); - Integer columnIndex = excelDataConvertException.getColumnIndex(); - errMsg = CharSequenceUtil.format("第{}行-第{}列-表头{}: 解析异常
", - rowIndex + 1, columnIndex + 1, headMap.get(columnIndex)); - if (log.isDebugEnabled()) { - log.error(errMsg); - } - } - if (exception instanceof ConstraintViolationException) { - ConstraintViolationException constraintViolationException = (ConstraintViolationException) exception; - Set> constraintViolations = constraintViolationException.getConstraintViolations(); - String constraintViolationsMsg = StreamUtils.join(constraintViolations, ConstraintViolation::getMessage, ", "); - errMsg = CharSequenceUtil.format("第{}行数据校验异常: {}", context.readRowHolder().getRowIndex() + 1, constraintViolationsMsg); - if (log.isDebugEnabled()) { - log.error(errMsg); - } - } - excelResult.getErrorList().add(errMsg); - throw new ExcelAnalysisException(errMsg); - } - - @Override - public void invokeHeadMap(Map headMap, AnalysisContext context) { - this.headMap = headMap; - log.debug("解析到一条表头数据: {}", JsonUtils.toJsonString(headMap)); - } - - @Override - public void invoke(T data, AnalysisContext context) { - if (Boolean.TRUE.equals(isValidate)) { - ValidatorUtils.validate(data); - } - excelResult.getList().add(data); - } - - @Override - public void doAfterAllAnalysed(AnalysisContext context) { - log.debug("所有数据解析完成!"); - } - - @Override - public ExcelResult getExcelResult() { - return excelResult; - } - -} diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/DefaultExcelResult.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/DefaultExcelResult.java deleted file mode 100644 index 571d3bac..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/DefaultExcelResult.java +++ /dev/null @@ -1,73 +0,0 @@ -package cc.iotkit.common.excel.core; - -import cn.hutool.core.text.CharSequenceUtil; -import lombok.Setter; - -import java.util.ArrayList; -import java.util.List; - -/** - * 默认excel返回对象 - * - * @author Yjoioooo - * @author Lion Li - */ -public class DefaultExcelResult implements ExcelResult { - - /** - * 数据对象list - */ - @Setter - private List list; - - /** - * 错误信息列表 - */ - @Setter - private List errorList; - - public DefaultExcelResult() { - this.list = new ArrayList<>(); - this.errorList = new ArrayList<>(); - } - - public DefaultExcelResult(List list, List errorList) { - this.list = list; - this.errorList = errorList; - } - - public DefaultExcelResult(ExcelResult excelResult) { - this.list = excelResult.getList(); - this.errorList = excelResult.getErrorList(); - } - - @Override - public List getList() { - return list; - } - - @Override - public List getErrorList() { - return errorList; - } - - /** - * 获取导入回执 - * - * @return 导入回执 - */ - @Override - public String getAnalysis() { - int successCount = list.size(); - int errorCount = errorList.size(); - if (successCount == 0) { - return "读取失败,未解析到数据"; - } else { - if (errorCount == 0) { - return CharSequenceUtil.format("恭喜您,全部读取成功!共{}条", successCount); - } else { - return ""; - } - } - } -} diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/ExcelListener.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/ExcelListener.java deleted file mode 100644 index cf12a666..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/ExcelListener.java +++ /dev/null @@ -1,14 +0,0 @@ -package cc.iotkit.common.excel.core; - -import com.alibaba.excel.read.listener.ReadListener; - -/** - * Excel 导入监听 - * - * @author Lion Li - */ -public interface ExcelListener extends ReadListener { - - ExcelResult getExcelResult(); - -} diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/ExcelResult.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/ExcelResult.java deleted file mode 100644 index fc4c7729..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/core/ExcelResult.java +++ /dev/null @@ -1,26 +0,0 @@ -package cc.iotkit.common.excel.core; - -import java.util.List; - -/** - * excel返回对象 - * - * @author Lion Li - */ -public interface ExcelResult { - - /** - * 对象列表 - */ - List getList(); - - /** - * 错误列表 - */ - List getErrorList(); - - /** - * 导入回执 - */ - String getAnalysis(); -} diff --git a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/utils/ExcelUtil.java b/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/utils/ExcelUtil.java deleted file mode 100644 index a77f06d5..00000000 --- a/iot-common/iot-common-excel/src/main/java/cc/iotkit/common/excel/utils/ExcelUtil.java +++ /dev/null @@ -1,327 +0,0 @@ -package cc.iotkit.common.excel.utils; - -import cc.iotkit.common.excel.convert.ExcelBigNumberConvert; -import cc.iotkit.common.excel.core.CellMergeStrategy; -import cc.iotkit.common.excel.core.DefaultExcelListener; -import cc.iotkit.common.excel.core.ExcelListener; -import cc.iotkit.common.excel.core.ExcelResult; -import cc.iotkit.common.utils.StringUtils; -import cc.iotkit.common.web.utils.ServletUtils; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.io.resource.ClassPathResource; -import cn.hutool.core.util.IdUtil; -import com.alibaba.excel.EasyExcel; -import com.alibaba.excel.ExcelWriter; -import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder; -import com.alibaba.excel.write.metadata.WriteSheet; -import com.alibaba.excel.write.metadata.fill.FillConfig; -import com.alibaba.excel.write.metadata.fill.FillWrapper; -import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -/** - * Excel相关处理 - * - * @author Lion Li - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ExcelUtil { - - /** - * 同步导入(适用于小数据量) - * - * @param is 输入流 - * @return 转换后集合 - */ - public static List importExcel(InputStream is, Class clazz) { - return EasyExcel.read(is).head(clazz).autoCloseStream(false).sheet().doReadSync(); - } - - - /** - * 使用校验监听器 异步导入 同步返回 - * - * @param is 输入流 - * @param clazz 对象类型 - * @param isValidate 是否 Validator 检验 默认为是 - * @return 转换后集合 - */ - public static ExcelResult importExcel(InputStream is, Class clazz, boolean isValidate) { - DefaultExcelListener listener = new DefaultExcelListener<>(isValidate); - EasyExcel.read(is, clazz, listener).sheet().doRead(); - return listener.getExcelResult(); - } - - /** - * 使用自定义监听器 异步导入 自定义返回 - * - * @param is 输入流 - * @param clazz 对象类型 - * @param listener 自定义监听器 - * @return 转换后集合 - */ - public static ExcelResult importExcel(InputStream is, Class clazz, ExcelListener listener) { - EasyExcel.read(is, clazz, listener).sheet().doRead(); - return listener.getExcelResult(); - } - - /** - * 导出excel - * - * @param list 导出数据集合 - * @param sheetName 工作表的名称 - * @param clazz 实体类 - * @param response 响应体 - */ - public static void exportExcel(List list, String sheetName, Class clazz, HttpServletResponse response) { - try { - resetResponse(sheetName, response); - ServletOutputStream os = response.getOutputStream(); - exportExcel(list, sheetName, clazz, false, os); - } catch (IOException e) { - throw new RuntimeException("导出Excel异常"); - } - } - - /** - * 导出excel - * - * @param list 导出数据集合 - * @param sheetName 工作表的名称 - * @param clazz 实体类 - * @param merge 是否合并单元格 - * @param response 响应体 - */ - public static void exportExcel(List list, String sheetName, Class clazz, boolean merge, HttpServletResponse response) { - try { - resetResponse(sheetName, response); - ServletOutputStream os = response.getOutputStream(); - exportExcel(list, sheetName, clazz, merge, os); - } catch (IOException e) { - throw new RuntimeException("导出Excel异常"); - } - } - - /** - * 导出excel - * - * @param list 导出数据集合 - * @param sheetName 工作表的名称 - * @param clazz 实体类 - * @param os 输出流 - */ - public static void exportExcel(List list, String sheetName, Class clazz, OutputStream os) { - exportExcel(list, sheetName, clazz, false, os); - } - - /** - * 导出excel - * - * @param list 导出数据集合 - * @param sheetName 工作表的名称 - * @param clazz 实体类 - * @param merge 是否合并单元格 - * @param os 输出流 - */ - public static void exportExcel(List list, String sheetName, Class clazz, boolean merge, OutputStream os) { - ExcelWriterSheetBuilder builder = EasyExcel.write(os, clazz) - .autoCloseStream(false) - // 自动适配 - .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) - // 大数值自动转换 防止失真 - .registerConverter(new ExcelBigNumberConvert()) - .sheet(sheetName); - if (merge) { - // 合并处理器 - builder.registerWriteHandler(new CellMergeStrategy(list, true)); - } - builder.doWrite(list); - } - - /** - * 单表多数据模板导出 模板格式为 {.属性} - * - * @param filename 文件名 - * @param templatePath 模板路径 resource 目录下的路径包括模板文件名 - * 例如: excel/temp.xlsx - * 重点: 模板文件必须放置到启动类对应的 resource 目录下 - * @param data 模板需要的数据 - * @param response 响应体 - */ - public static void exportTemplate(List data, String filename, String templatePath, HttpServletResponse response) { - try { - resetResponse(filename, response); - ServletOutputStream os = response.getOutputStream(); - exportTemplate(data, templatePath, os); - } catch (IOException e) { - throw new RuntimeException("导出Excel异常"); - } - } - - /** - * 单表多数据模板导出 模板格式为 {.属性} - * - * @param templatePath 模板路径 resource 目录下的路径包括模板文件名 - * 例如: excel/temp.xlsx - * 重点: 模板文件必须放置到启动类对应的 resource 目录下 - * @param data 模板需要的数据 - * @param os 输出流 - */ - public static void exportTemplate(List data, String templatePath, OutputStream os) { - ClassPathResource templateResource = new ClassPathResource(templatePath); - ExcelWriter excelWriter = EasyExcel.write(os) - .withTemplate(templateResource.getStream()) - .autoCloseStream(false) - // 大数值自动转换 防止失真 - .registerConverter(new ExcelBigNumberConvert()) - .build(); - WriteSheet writeSheet = EasyExcel.writerSheet().build(); - if (CollUtil.isEmpty(data)) { - throw new IllegalArgumentException("数据为空"); - } - // 单表多数据导出 模板格式为 {.属性} - for (Object d : data) { - excelWriter.fill(d, writeSheet); - } - excelWriter.finish(); - } - - /** - * 多表多数据模板导出 模板格式为 {key.属性} - * - * @param filename 文件名 - * @param templatePath 模板路径 resource 目录下的路径包括模板文件名 - * 例如: excel/temp.xlsx - * 重点: 模板文件必须放置到启动类对应的 resource 目录下 - * @param data 模板需要的数据 - * @param response 响应体 - */ - public static void exportTemplateMultiList(Map data, String filename, String templatePath, HttpServletResponse response) { - try { - resetResponse(filename, response); - ServletOutputStream os = response.getOutputStream(); - exportTemplateMultiList(data, templatePath, os); - } catch (IOException e) { - throw new RuntimeException("导出Excel异常"); - } - } - - /** - * 多表多数据模板导出 模板格式为 {key.属性} - * - * @param templatePath 模板路径 resource 目录下的路径包括模板文件名 - * 例如: excel/temp.xlsx - * 重点: 模板文件必须放置到启动类对应的 resource 目录下 - * @param data 模板需要的数据 - * @param os 输出流 - */ - public static void exportTemplateMultiList(Map data, String templatePath, OutputStream os) { - ClassPathResource templateResource = new ClassPathResource(templatePath); - ExcelWriter excelWriter = EasyExcel.write(os) - .withTemplate(templateResource.getStream()) - .autoCloseStream(false) - // 大数值自动转换 防止失真 - .registerConverter(new ExcelBigNumberConvert()) - .build(); - WriteSheet writeSheet = EasyExcel.writerSheet().build(); - if (CollUtil.isEmpty(data)) { - throw new IllegalArgumentException("数据为空"); - } - for (Map.Entry map : data.entrySet()) { - // 设置列表后续还有数据 - FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); - if (map.getValue() instanceof Collection) { - // 多表导出必须使用 FillWrapper - excelWriter.fill(new FillWrapper(map.getKey(), (Collection) map.getValue()), fillConfig, writeSheet); - } else { - excelWriter.fill(map.getValue(), writeSheet); - } - } - excelWriter.finish(); - } - - /** - * 重置响应体 - */ - private static void resetResponse(String sheetName, HttpServletResponse response) { - String filename = encodingFilename(sheetName); - ServletUtils.setAttachmentResponseHeader(response, filename); - response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8"); - } - - /** - * 解析导出值 0=男,1=女,2=未知 - * - * @param propertyValue 参数值 - * @param converterExp 翻译注解 - * @param separator 分隔符 - * @return 解析后值 - */ - public static String convertByExp(String propertyValue, String converterExp, String separator) { - StringBuilder propertyString = new StringBuilder(); - String[] convertSource = converterExp.split(StringUtils.SEPARATOR); - for (String item : convertSource) { - String[] itemArray = item.split("="); - if (StringUtils.containsAny(propertyValue, separator)) { - for (String value : propertyValue.split(separator)) { - if (itemArray[0].equals(value)) { - propertyString.append(itemArray[1]).append(separator); - break; - } - } - } else { - if (itemArray[0].equals(propertyValue)) { - return itemArray[1]; - } - } - } - return StringUtils.stripEnd(propertyString.toString(), separator); - } - - /** - * 反向解析值 男=0,女=1,未知=2 - * - * @param propertyValue 参数值 - * @param converterExp 翻译注解 - * @param separator 分隔符 - * @return 解析后值 - */ - public static String reverseByExp(String propertyValue, String converterExp, String separator) { - StringBuilder propertyString = new StringBuilder(); - String[] convertSource = converterExp.split(StringUtils.SEPARATOR); - for (String item : convertSource) { - String[] itemArray = item.split("="); - if (StringUtils.containsAny(propertyValue, separator)) { - for (String value : propertyValue.split(separator)) { - if (itemArray[1].equals(value)) { - propertyString.append(itemArray[0]).append(separator); - break; - } - } - } else { - if (itemArray[1].equals(propertyValue)) { - return itemArray[0]; - } - } - } - return StringUtils.stripEnd(propertyString.toString(), separator); - } - - /** - * 编码文件名 - */ - public static String encodingFilename(String filename) { - return IdUtil.fastSimpleUUID() + "_" + filename + ".xlsx"; - } - -} diff --git a/iot-common/iot-common-log/pom.xml b/iot-common/iot-common-log/pom.xml deleted file mode 100644 index 94f38100..00000000 --- a/iot-common/iot-common-log/pom.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-common-log - - - - - cc.iotkit - iot-common-core - - - - cc.iotkit - iot-common-web - - - - cc.iotkit - iot-common-satoken - - - - - - org.aspectj - aspectjweaver - - - - org.springframework.boot - spring-boot-autoconfigure - - - - com.alibaba - transmittable-thread-local - - - - org.projectlombok - lombok - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/annotation/Log.java b/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/annotation/Log.java deleted file mode 100644 index e2ea5819..00000000 --- a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/annotation/Log.java +++ /dev/null @@ -1,48 +0,0 @@ -package cc.iotkit.common.log.annotation; - -import cc.iotkit.common.log.enums.BusinessType; -import cc.iotkit.common.log.enums.OperatorType; - -import java.lang.annotation.*; - -/** - * 自定义操作日志记录注解 - * - * @author ruoyi - */ -@Target({ElementType.PARAMETER, ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface Log { - /** - * 模块 - */ - String title() default ""; - - /** - * 功能 - */ - BusinessType businessType() default BusinessType.OTHER; - - /** - * 操作人类别 - */ - OperatorType operatorType() default OperatorType.MANAGE; - - /** - * 是否保存请求的参数 - */ - boolean isSaveRequestData() default true; - - /** - * 是否保存响应的参数 - */ - boolean isSaveResponseData() default true; - - - /** - * 排除指定的请求参数 - */ - String[] excludeParamNames() default {}; - -} diff --git a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/aspect/LogAspect.java b/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/aspect/LogAspect.java deleted file mode 100644 index 378197eb..00000000 --- a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/aspect/LogAspect.java +++ /dev/null @@ -1,221 +0,0 @@ -package cc.iotkit.common.log.aspect; - -import cc.iotkit.common.log.annotation.Log; -import cc.iotkit.common.log.enums.BusinessStatus; -import cc.iotkit.common.log.event.OperLogEvent; -import cc.iotkit.common.satoken.utils.LoginHelper; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.common.utils.SpringUtils; -import cc.iotkit.common.utils.StringUtils; -import cc.iotkit.common.web.utils.ServletUtils; -import cn.hutool.core.lang.Dict; -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.ObjectUtil; -import com.alibaba.ttl.TransmittableThreadLocal; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.time.StopWatch; -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.AfterReturning; -import org.aspectj.lang.annotation.AfterThrowing; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.http.HttpMethod; -import org.springframework.validation.BindingResult; -import org.springframework.web.multipart.MultipartFile; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.Collection; -import java.util.Map; - -/** - * 操作日志记录处理 - * - * @author Lion Li - */ -@Slf4j -@Aspect -@AutoConfiguration -public class LogAspect { - - /** - * 排除敏感属性字段 - */ - public static final String[] EXCLUDE_PROPERTIES = {"password", "oldPassword", "newPassword", "confirmPassword"}; - - - /** - * 计算操作消耗时间 - */ - private static final ThreadLocal TIME_THREADLOCAL = new TransmittableThreadLocal<>(); - - /** - * 处理请求前执行 - */ - @Before(value = "@annotation(controllerLog)") - public void boBefore(JoinPoint joinPoint, Log controllerLog) { - StopWatch stopWatch = new StopWatch(); - TIME_THREADLOCAL.set(stopWatch); - stopWatch.start(); - } - - /** - * 处理完请求后执行 - * - * @param joinPoint 切点 - */ - @AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult") - public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult) { - handleLog(joinPoint, controllerLog, null, jsonResult); - } - - /** - * 拦截异常操作 - * - * @param joinPoint 切点 - * @param e 异常 - */ - @AfterThrowing(value = "@annotation(controllerLog)", throwing = "e") - public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e) { - handleLog(joinPoint, controllerLog, e, null); - } - - protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) { - try { - - // *========数据库日志=========*// - OperLogEvent operLog = new OperLogEvent(); - operLog.setTenantId(LoginHelper.getTenantId()); - operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); - // 请求的地址 - String ip = ServletUtils.getClientIP(); - operLog.setOperIp(ip); - operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255)); - operLog.setOperName(LoginHelper.getUsername()); - - if (e != null) { - operLog.setStatus(BusinessStatus.FAIL.ordinal()); - operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); - } - // 设置方法名称 - String className = joinPoint.getTarget().getClass().getName(); - String methodName = joinPoint.getSignature().getName(); - operLog.setMethod(className + "." + methodName + "()"); - // 设置请求方式 - operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); - // 处理设置注解上的参数 - getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); - // 设置消耗时间 - StopWatch stopWatch = TIME_THREADLOCAL.get(); - stopWatch.stop(); - operLog.setCostTime(stopWatch.getTime()); - // 发布事件保存数据库 - SpringUtils.context().publishEvent(operLog); - } catch (Exception exp) { - // 记录本地异常日志 - log.error("异常信息:{}", exp.getMessage()); - exp.printStackTrace(); - } finally { - TIME_THREADLOCAL.remove(); - } - } - - /** - * 获取注解中对方法的描述信息 用于Controller层注解 - * - * @param log 日志 - * @param operLog 操作日志 - * @throws Exception - */ - public void getControllerMethodDescription(JoinPoint joinPoint, Log log, OperLogEvent operLog, Object jsonResult) throws Exception { - // 设置action动作 - operLog.setBusinessType(log.businessType().ordinal()); - // 设置标题 - operLog.setTitle(log.title()); - // 设置操作人类别 - operLog.setOperatorType(log.operatorType().ordinal()); - // 是否需要保存request,参数和值 - if (log.isSaveRequestData()) { - // 获取参数的信息,传入到数据库中。 - setRequestValue(joinPoint, operLog, log.excludeParamNames()); - } - // 是否需要保存response,参数和值 - if (log.isSaveResponseData() && ObjectUtil.isNotNull(jsonResult)) { - operLog.setJsonResult(StringUtils.substring(JsonUtils.toJsonString(jsonResult), 0, 2000)); - } - } - - /** - * 获取请求的参数,放到log中 - * - * @param operLog 操作日志 - * @throws Exception 异常 - */ - private void setRequestValue(JoinPoint joinPoint, OperLogEvent operLog, String[] excludeParamNames) { - Map paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest()); - String requestMethod = operLog.getRequestMethod(); - if (MapUtil.isEmpty(paramsMap) - && HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) { - String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames); - operLog.setOperParam(StringUtils.substring(params, 0, 2000)); - } else { - MapUtil.removeAny(paramsMap, EXCLUDE_PROPERTIES); - MapUtil.removeAny(paramsMap, excludeParamNames); - operLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 2000)); - } - } - - /** - * 参数拼装 - */ - private String argsArrayToString(Object[] paramsArray, String[] excludeParamNames) { - StringBuilder params = new StringBuilder(); - if (paramsArray != null && paramsArray.length > 0) { - for (Object o : paramsArray) { - if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) { - try { - String str = JsonUtils.toJsonString(o); - Dict dict = JsonUtils.parseMap(str); - if (MapUtil.isNotEmpty(dict)) { - MapUtil.removeAny(dict, EXCLUDE_PROPERTIES); - MapUtil.removeAny(dict, excludeParamNames); - str = JsonUtils.toJsonString(dict); - } - params.append(str).append(" "); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - return params.toString().trim(); - } - - /** - * 判断是否需要过滤的对象。 - * - * @param o 对象信息。 - * @return 如果是需要过滤的对象,则返回true;否则返回false。 - */ - @SuppressWarnings("rawtypes") - public boolean isFilterObject(final Object o) { - Class clazz = o.getClass(); - if (clazz.isArray()) { - return clazz.getComponentType().isAssignableFrom(MultipartFile.class); - } else if (Collection.class.isAssignableFrom(clazz)) { - Collection collection = (Collection) o; - for (Object value : collection) { - return value instanceof MultipartFile; - } - } else if (Map.class.isAssignableFrom(clazz)) { - Map map = (Map) o; - for (Object value : map.entrySet()) { - Map.Entry entry = (Map.Entry) value; - return entry.getValue() instanceof MultipartFile; - } - } - return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse - || o instanceof BindingResult; - } -} diff --git a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/enums/BusinessStatus.java b/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/enums/BusinessStatus.java deleted file mode 100644 index 0c017a8c..00000000 --- a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/enums/BusinessStatus.java +++ /dev/null @@ -1,18 +0,0 @@ -package cc.iotkit.common.log.enums; - -/** - * 操作状态 - * - * @author ruoyi - */ -public enum BusinessStatus { - /** - * 成功 - */ - SUCCESS, - - /** - * 失败 - */ - FAIL, -} diff --git a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/enums/BusinessType.java b/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/enums/BusinessType.java deleted file mode 100644 index 7a88364c..00000000 --- a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/enums/BusinessType.java +++ /dev/null @@ -1,58 +0,0 @@ -package cc.iotkit.common.log.enums; - -/** - * 业务操作类型 - * - * @author ruoyi - */ -public enum BusinessType { - /** - * 其它 - */ - OTHER, - - /** - * 新增 - */ - INSERT, - - /** - * 修改 - */ - UPDATE, - - /** - * 删除 - */ - DELETE, - - /** - * 授权 - */ - GRANT, - - /** - * 导出 - */ - EXPORT, - - /** - * 导入 - */ - IMPORT, - - /** - * 强退 - */ - FORCE, - - /** - * 生成代码 - */ - GENCODE, - - /** - * 清空数据 - */ - CLEAN, -} diff --git a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/enums/OperatorType.java b/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/enums/OperatorType.java deleted file mode 100644 index d05e5fba..00000000 --- a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/enums/OperatorType.java +++ /dev/null @@ -1,23 +0,0 @@ -package cc.iotkit.common.log.enums; - -/** - * 操作人类别 - * - * @author ruoyi - */ -public enum OperatorType { - /** - * 其它 - */ - OTHER, - - /** - * 后台用户 - */ - MANAGE, - - /** - * 手机端用户 - */ - MOBILE -} diff --git a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/event/LogininforEvent.java b/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/event/LogininforEvent.java deleted file mode 100644 index dde592b3..00000000 --- a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/event/LogininforEvent.java +++ /dev/null @@ -1,58 +0,0 @@ -package cc.iotkit.common.log.event; - -import cn.hutool.http.useragent.UserAgent; -import lombok.Data; - -import javax.servlet.http.HttpServletRequest; -import java.io.Serializable; - -/** - * 登录事件 - * - * @author Lion Li - */ - -@Data -public class LogininforEvent implements Serializable { - private static final long serialVersionUID = 1L; - - /** - * 租户ID - */ - private String tenantId; - - /** - * 用户账号 - */ - private String username; - - /** - * 登录状态 0成功 1失败 - */ - private String status; - - /** - * 提示消息 - */ - private String message; - - /** - * ip - */ - private String ip; - - /** - * user-agent - */ - private UserAgent userAgent; - - /** - * 请求体 - */ - private HttpServletRequest request; - /** - * 其他参数 - */ - private Object[] args; - -} diff --git a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/event/OperLogEvent.java b/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/event/OperLogEvent.java deleted file mode 100644 index d50268b6..00000000 --- a/iot-common/iot-common-log/src/main/java/cc/iotkit/common/log/event/OperLogEvent.java +++ /dev/null @@ -1,112 +0,0 @@ -package cc.iotkit.common.log.event; - -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -/** - * 操作日志事件 - * - * @author Lion Li - */ - -@Data -public class OperLogEvent implements Serializable { - private static final long serialVersionUID = 1L; - - /** - * 日志主键 - */ - private Long id; - - /** - * 租户ID - */ - private String 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-common/iot-common-log/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/iot-common/iot-common-log/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 393b972c..00000000 --- a/iot-common/iot-common-log/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.common.log.aspect.LogAspect diff --git a/iot-common/iot-common-oss/pom.xml b/iot-common/iot-common-oss/pom.xml deleted file mode 100644 index fa1e801f..00000000 --- a/iot-common/iot-common-oss/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-common-oss - - - - cc.iotkit - iot-common-redis - - - - cc.iotkit - iot-common-core - - - - - - com.amazonaws - aws-java-sdk-s3 - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/constant/OssConstant.java b/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/constant/OssConstant.java deleted file mode 100644 index 1afba480..00000000 --- a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/constant/OssConstant.java +++ /dev/null @@ -1,38 +0,0 @@ -package cc.iotkit.common.oss.constant; - -import java.util.Arrays; -import java.util.List; - -/** - * 对象存储常量 - * - * @author Lion Li - */ -public interface OssConstant { - - /** - * 默认配置KEY - */ - String DEFAULT_CONFIG_KEY = "sys_oss:default_config"; - - /** - * 预览列表资源开关Key - */ - String PEREVIEW_LIST_RESOURCE_KEY = "sys.oss.previewListResource"; - - /** - * 系统数据ids - */ - List SYSTEM_DATA_IDS = Arrays.asList(1L, 2L, 3L, 4L); - - /** - * 云服务商 - */ - String[] CLOUD_SERVICE = new String[] {"aliyun", "qcloud", "qiniu", "obs"}; - - /** - * https 状态 - */ - String IS_HTTPS = "Y"; - -} diff --git a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/core/OssClient.java b/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/core/OssClient.java deleted file mode 100644 index fc22cb80..00000000 --- a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/core/OssClient.java +++ /dev/null @@ -1,260 +0,0 @@ -package cc.iotkit.common.oss.core; - -import cc.iotkit.common.oss.constant.OssConstant; -import cc.iotkit.common.oss.entity.UploadResult; -import cc.iotkit.common.oss.enumd.AccessPolicyType; -import cc.iotkit.common.oss.enumd.PolicyType; -import cc.iotkit.common.oss.exception.OssException; -import cc.iotkit.common.oss.properties.OssProperties; -import cc.iotkit.common.utils.DateUtils; -import cc.iotkit.common.utils.StringUtils; -import cn.hutool.core.io.IoUtil; -import cn.hutool.core.util.IdUtil; -import com.amazonaws.ClientConfiguration; -import com.amazonaws.HttpMethod; -import com.amazonaws.Protocol; -import com.amazonaws.auth.AWSCredentials; -import com.amazonaws.auth.AWSCredentialsProvider; -import com.amazonaws.auth.AWSStaticCredentialsProvider; -import com.amazonaws.auth.BasicAWSCredentials; -import com.amazonaws.client.builder.AwsClientBuilder; -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.AmazonS3Client; -import com.amazonaws.services.s3.AmazonS3ClientBuilder; -import com.amazonaws.services.s3.model.*; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.net.URL; -import java.util.Date; - -/** - * S3 存储协议 所有兼容S3协议的云厂商均支持 - * 阿里云 腾讯云 七牛云 minio - * - * @author Lion Li - */ -public class OssClient { - - private final String configKey; - - private final OssProperties properties; - - private final AmazonS3 client; - - public OssClient(String configKey, OssProperties ossProperties) { - this.configKey = configKey; - this.properties = ossProperties; - try { - AwsClientBuilder.EndpointConfiguration endpointConfig = - new AwsClientBuilder.EndpointConfiguration(properties.getEndpoint(), properties.getRegion()); - - AWSCredentials credentials = new BasicAWSCredentials(properties.getAccessKey(), properties.getSecretKey()); - AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); - ClientConfiguration clientConfig = new ClientConfiguration(); - if (OssConstant.IS_HTTPS.equals(properties.getIsHttps())) { - clientConfig.setProtocol(Protocol.HTTPS); - } else { - clientConfig.setProtocol(Protocol.HTTP); - } - AmazonS3ClientBuilder build = AmazonS3Client.builder() - .withEndpointConfiguration(endpointConfig) - .withClientConfiguration(clientConfig) - .withCredentials(credentialsProvider) - .disableChunkedEncoding(); - if (!StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE)) { - // minio 使用https限制使用域名访问 需要此配置 站点填域名 - build.enablePathStyleAccess(); - } - this.client = build.build(); - - createBucket(); - } catch (Exception e) { - if (e instanceof OssException) { - throw e; - } - throw new OssException("配置错误! 请检查系统配置:[" + e.getMessage() + "]"); - } - } - - public void createBucket() { - try { - String bucketName = properties.getBucketName(); - if (client.doesBucketExistV2(bucketName)) { - return; - } - CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName); - AccessPolicyType accessPolicy = getAccessPolicy(); - createBucketRequest.setCannedAcl(accessPolicy.getAcl()); - client.createBucket(createBucketRequest); - client.setBucketPolicy(bucketName, getPolicy(bucketName, accessPolicy.getPolicyType())); - } catch (Exception e) { - throw new OssException("创建Bucket失败, 请核对配置信息:[" + e.getMessage() + "]"); - } - } - - public UploadResult upload(byte[] data, String path, String contentType) { - return upload(new ByteArrayInputStream(data), path, contentType); - } - - public UploadResult upload(InputStream inputStream, String path, String contentType) { - if (!(inputStream instanceof ByteArrayInputStream)) { - inputStream = new ByteArrayInputStream(IoUtil.readBytes(inputStream)); - } - try { - ObjectMetadata metadata = new ObjectMetadata(); - metadata.setContentType(contentType); - metadata.setContentLength(inputStream.available()); - PutObjectRequest putObjectRequest = new PutObjectRequest(properties.getBucketName(), path, inputStream, metadata); - // 设置上传对象的 Acl 为公共读 - putObjectRequest.setCannedAcl(getAccessPolicy().getAcl()); - client.putObject(putObjectRequest); - } catch (Exception e) { - throw new OssException("上传文件失败,请检查配置信息:[" + e.getMessage() + "]"); - } - return UploadResult.builder().url(getUrl() + "/" + path).filename(path).build(); - } - - public void delete(String path) { - path = path.replace(getUrl() + "/", ""); - try { - client.deleteObject(properties.getBucketName(), path); - } catch (Exception e) { - throw new OssException("删除文件失败,请检查配置信息:[" + e.getMessage() + "]"); - } - } - - public UploadResult uploadSuffix(byte[] data, String suffix, String contentType) { - return upload(data, getPath(properties.getPrefix(), suffix), contentType); - } - - public UploadResult uploadSuffix(InputStream inputStream, String suffix, String contentType) { - return upload(inputStream, getPath(properties.getPrefix(), suffix), contentType); - } - - /** - * 获取文件元数据 - * - * @param path 完整文件路径 - */ - public ObjectMetadata getObjectMetadata(String path) { - path = path.replace(getUrl() + "/", ""); - S3Object object = client.getObject(properties.getBucketName(), path); - return object.getObjectMetadata(); - } - - public InputStream getObjectContent(String path) { - path = path.replace(getUrl() + "/", ""); - S3Object object = client.getObject(properties.getBucketName(), path); - return object.getObjectContent(); - } - - public String getUrl() { - String domain = properties.getDomain(); - String endpoint = properties.getEndpoint(); - String header = OssConstant.IS_HTTPS.equals(properties.getIsHttps()) ? "https://" : "http://"; - // 云服务商直接返回 - if (StringUtils.containsAny(endpoint, OssConstant.CLOUD_SERVICE)) { - if (StringUtils.isNotBlank(domain)) { - return header + domain; - } - return header + properties.getBucketName() + "." + endpoint; - } - // minio 单独处理 - if (StringUtils.isNotBlank(domain)) { - return header + domain + "/" + properties.getBucketName(); - } - return header + endpoint + "/" + properties.getBucketName(); - } - - public String getPath(String prefix, String suffix) { - // 生成uuid - String uuid = IdUtil.fastSimpleUUID(); - // 文件路径 - String path = DateUtils.datePath() + "/" + uuid; - if (StringUtils.isNotBlank(prefix)) { - path = prefix + "/" + path; - } - return path + suffix; - } - - - public String getConfigKey() { - return configKey; - } - - /** - * 获取私有URL链接 - * - * @param objectKey 对象KEY - * @param second 授权时间 - */ - public String getPrivateUrl(String objectKey, Integer second) { - GeneratePresignedUrlRequest generatePresignedUrlRequest = - new GeneratePresignedUrlRequest(properties.getBucketName(), objectKey) - .withMethod(HttpMethod.GET) - .withExpiration(new Date(System.currentTimeMillis() + 1000L * second)); - URL url = client.generatePresignedUrl(generatePresignedUrlRequest); - return url.toString(); - } - - /** - * 检查配置是否相同 - */ - public boolean checkPropertiesSame(OssProperties properties) { - return this.properties.equals(properties); - } - - /** - * 获取当前桶权限类型 - * - * @return 当前桶权限类型code - */ - public AccessPolicyType getAccessPolicy() { - return AccessPolicyType.getByType(properties.getAccessPolicy()); - } - - private static String getPolicy(String bucketName, PolicyType policyType) { - String location = ""; - switch (policyType) { - case WRITE: - location = "\"s3:GetBucketLocation\",\n\"s3:ListBucketMultipartUploads\"\n"; - break; - case READ_WRITE: - location = "\"s3:GetBucketLocation\",\n\"s3:ListBucket\",\n\"s3:ListBucketMultipartUploads\"\n"; - break; - default: - location = "\"s3:GetBucketLocation\"\n"; - } - - StringBuilder builder = new StringBuilder(); - builder.append("{\n\"Statement\": [\n{\n\"Action\": [\n"); - builder.append(location); - builder.append("],\n\"Effect\": \"Allow\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::"); - builder.append(bucketName); - builder.append("\"\n},\n"); - if (policyType == PolicyType.READ) { - builder.append("{\n\"Action\": [\n\"s3:ListBucket\"\n],\n\"Effect\": \"Deny\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::"); - builder.append(bucketName); - builder.append("\"\n},\n"); - } - String action = ""; - switch (policyType) { - case WRITE: - action = "[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n"; - break; - case READ_WRITE: - action = "[\n\"s3:AbortMultipartUpload\",\n\"s3:DeleteObject\",\n\"s3:GetObject\",\n\"s3:ListMultipartUploadParts\",\n\"s3:PutObject\"\n],\n"; - break; - default: - action = "\"s3:GetObject\",\n"; - } - builder.append("{\n\"Action\": "); - builder.append(action); - builder.append("\"Effect\": \"Allow\",\n\"Principal\": \"*\",\n\"Resource\": \"arn:aws:s3:::"); - builder.append(bucketName); - builder.append("/*\"\n}\n],\n\"Version\": \"2012-10-17\"\n}\n"); - return builder.toString(); - } - -} diff --git a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/entity/UploadResult.java b/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/entity/UploadResult.java deleted file mode 100644 index e486ec0e..00000000 --- a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/entity/UploadResult.java +++ /dev/null @@ -1,24 +0,0 @@ -package cc.iotkit.common.oss.entity; - -import lombok.Builder; -import lombok.Data; - -/** - * 上传返回体 - * - * @author Lion Li - */ -@Data -@Builder -public class UploadResult { - - /** - * 文件路径 - */ - private String url; - - /** - * 文件名 - */ - private String filename; -} diff --git a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/enumd/AccessPolicyType.java b/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/enumd/AccessPolicyType.java deleted file mode 100644 index b3c60182..00000000 --- a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/enumd/AccessPolicyType.java +++ /dev/null @@ -1,56 +0,0 @@ -package cc.iotkit.common.oss.enumd; - -import cc.iotkit.common.exception.BizException; -import com.amazonaws.services.s3.model.CannedAccessControlList; -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 桶访问策略配置 - * - * @author 陈賝 - */ -@Getter -@AllArgsConstructor -public enum AccessPolicyType { - - /** - * private - */ - PRIVATE("0", CannedAccessControlList.Private, PolicyType.WRITE), - - /** - * public - */ - PUBLIC("1", CannedAccessControlList.PublicRead, PolicyType.READ), - - /** - * custom - */ - CUSTOM("2",CannedAccessControlList.PublicRead, PolicyType.READ); - - /** - * 桶 权限类型 - */ - private final String type; - - /** - * 文件对象 权限类型 - */ - private final CannedAccessControlList acl; - - /** - * 桶策略类型 - */ - private final PolicyType policyType; - - public static AccessPolicyType getByType(String type) { - for (AccessPolicyType value : values()) { - if (value.getType().equals(type)) { - return value; - } - } - throw new BizException("'type' not found By " + type); - } - -} diff --git a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/enumd/PolicyType.java b/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/enumd/PolicyType.java deleted file mode 100644 index c838b050..00000000 --- a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/enumd/PolicyType.java +++ /dev/null @@ -1,35 +0,0 @@ -package cc.iotkit.common.oss.enumd; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * minio策略配置 - * - * @author Lion Li - */ -@Getter -@AllArgsConstructor -public enum PolicyType { - - /** - * 只读 - */ - READ("read-only"), - - /** - * 只写 - */ - WRITE("write-only"), - - /** - * 读写 - */ - READ_WRITE("read-write"); - - /** - * 类型 - */ - private final String type; - -} diff --git a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/exception/OssException.java b/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/exception/OssException.java deleted file mode 100644 index fd3fdc8a..00000000 --- a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/exception/OssException.java +++ /dev/null @@ -1,18 +0,0 @@ -package cc.iotkit.common.oss.exception; - - -/** - * OSS异常类 - * - * @author Lion Li - */ -public class OssException extends RuntimeException { - - - private static final long serialVersionUID = 1L; - - public OssException(String msg) { - super(msg); - } - -} diff --git a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/factory/OssFactory.java b/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/factory/OssFactory.java deleted file mode 100644 index bade134e..00000000 --- a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/factory/OssFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -package cc.iotkit.common.oss.factory; - - -import cc.iotkit.common.constant.CacheNames; -import cc.iotkit.common.oss.constant.OssConstant; -import cc.iotkit.common.oss.core.OssClient; -import cc.iotkit.common.oss.exception.OssException; -import cc.iotkit.common.oss.properties.OssProperties; -import cc.iotkit.common.redis.utils.CacheUtils; -import cc.iotkit.common.redis.utils.RedisUtils; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.common.utils.StringUtils; -import lombok.extern.slf4j.Slf4j; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * 文件上传Factory - * - * @author Lion Li - */ -@Slf4j -public class OssFactory { - - private static final Map CLIENT_CACHE = new ConcurrentHashMap<>(); - - /** - * 获取默认实例 - */ - public static OssClient instance() { - // 获取redis 默认类型 - String configKey = RedisUtils.getCacheObject(OssConstant.DEFAULT_CONFIG_KEY); - if (StringUtils.isEmpty(configKey)) { - throw new OssException("文件存储服务类型无法找到!"); - } - return instance(configKey); - } - - /** - * 根据类型获取实例 - */ - public static OssClient instance(String configKey) { - String json = CacheUtils.get(CacheNames.SYS_OSS_CONFIG, configKey); - if (json == null) { - throw new OssException("系统异常, '" + configKey + "'配置信息不存在!"); - } - OssProperties properties = JsonUtils.parseObject(json, OssProperties.class); - OssClient client = CLIENT_CACHE.get(configKey); - if (client == null) { - CLIENT_CACHE.put(configKey, new OssClient(configKey, properties)); - log.info("创建OSS实例 key => {}", configKey); - return CLIENT_CACHE.get(configKey); - } - // 配置不相同则重新构建 - if (!client.checkPropertiesSame(properties)) { - CLIENT_CACHE.put(configKey, new OssClient(configKey, properties)); - log.info("重载OSS实例 key => {}", configKey); - return CLIENT_CACHE.get(configKey); - } - return client; - } - -} diff --git a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/properties/OssProperties.java b/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/properties/OssProperties.java deleted file mode 100644 index ab372c93..00000000 --- a/iot-common/iot-common-oss/src/main/java/cc/iotkit/common/oss/properties/OssProperties.java +++ /dev/null @@ -1,58 +0,0 @@ -package cc.iotkit.common.oss.properties; - -import lombok.Data; - -/** - * OSS对象存储 配置属性 - * - * @author Lion Li - */ -@Data -public class OssProperties { - - /** - * 访问站点 - */ - private String endpoint; - - /** - * 自定义域名 - */ - private String domain; - - /** - * 前缀 - */ - private String prefix; - - /** - * ACCESS_KEY - */ - private String accessKey; - - /** - * SECRET_KEY - */ - private String secretKey; - - /** - * 存储空间名 - */ - private String bucketName; - - /** - * 存储区域 - */ - private String region; - - /** - * 是否https(Y=是,N=否) - */ - private String isHttps; - - /** - * 桶权限类型(0private 1public 2custom) - */ - private String accessPolicy; - -} diff --git a/iot-common/iot-common-redis/pom.xml b/iot-common/iot-common-redis/pom.xml deleted file mode 100644 index b1dafdac..00000000 --- a/iot-common/iot-common-redis/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-common-redis - - - - - cc.iotkit - iot-common-core - - - - - - - org.redisson - redisson-spring-boot-starter - - - - com.baomidou - lock4j-redisson-spring-boot-starter - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/config/RedisConfig.java b/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/config/RedisConfig.java deleted file mode 100644 index ea0bfd77..00000000 --- a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/config/RedisConfig.java +++ /dev/null @@ -1,130 +0,0 @@ -package cc.iotkit.common.redis.config; - -import cc.iotkit.common.redis.config.properties.RedissonProperties; -import cc.iotkit.common.redis.handler.KeyPrefixHandler; -import cc.iotkit.common.redis.manager.PlusSpringCacheManager; -import cn.hutool.core.util.ObjectUtil; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.slf4j.Slf4j; -import org.redisson.codec.JsonJacksonCodec; -import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cache.CacheManager; -import org.springframework.cache.annotation.EnableCaching; -import org.springframework.context.annotation.Bean; - -/** - * redis配置 - * - * @author Lion Li - */ -@Slf4j -@AutoConfiguration -@EnableCaching -@EnableConfigurationProperties(RedissonProperties.class) -public class RedisConfig { - - @Autowired - private RedissonProperties redissonProperties; - - @Autowired - private ObjectMapper objectMapper; - - @Bean - public RedissonAutoConfigurationCustomizer redissonCustomizer() { - return config -> { - config.setThreads(redissonProperties.getThreads()) - .setNettyThreads(redissonProperties.getNettyThreads()) - .setCodec(new JsonJacksonCodec(objectMapper)); - RedissonProperties.SingleServerConfig singleServerConfig = redissonProperties.getSingleServerConfig(); - if (ObjectUtil.isNotNull(singleServerConfig)) { - // 使用单机模式 - config.useSingleServer() - //设置redis key前缀 - .setNameMapper(new KeyPrefixHandler(redissonProperties.getKeyPrefix())) - .setTimeout(singleServerConfig.getTimeout()) - .setClientName(singleServerConfig.getClientName()) - .setIdleConnectionTimeout(singleServerConfig.getIdleConnectionTimeout()) - .setSubscriptionConnectionPoolSize(singleServerConfig.getSubscriptionConnectionPoolSize()) - .setConnectionMinimumIdleSize(singleServerConfig.getConnectionMinimumIdleSize()) - .setConnectionPoolSize(singleServerConfig.getConnectionPoolSize()); - } - // 集群配置方式 参考下方注释 - RedissonProperties.ClusterServersConfig clusterServersConfig = redissonProperties.getClusterServersConfig(); - if (ObjectUtil.isNotNull(clusterServersConfig)) { - config.useClusterServers() - //设置redis key前缀 - .setNameMapper(new KeyPrefixHandler(redissonProperties.getKeyPrefix())) - .setTimeout(clusterServersConfig.getTimeout()) - .setClientName(clusterServersConfig.getClientName()) - .setIdleConnectionTimeout(clusterServersConfig.getIdleConnectionTimeout()) - .setSubscriptionConnectionPoolSize(clusterServersConfig.getSubscriptionConnectionPoolSize()) - .setMasterConnectionMinimumIdleSize(clusterServersConfig.getMasterConnectionMinimumIdleSize()) - .setMasterConnectionPoolSize(clusterServersConfig.getMasterConnectionPoolSize()) - .setSlaveConnectionMinimumIdleSize(clusterServersConfig.getSlaveConnectionMinimumIdleSize()) - .setSlaveConnectionPoolSize(clusterServersConfig.getSlaveConnectionPoolSize()) - .setReadMode(clusterServersConfig.getReadMode()) - .setSubscriptionMode(clusterServersConfig.getSubscriptionMode()); - } - log.info("初始化 redis 配置"); - }; - } - - /** - * 自定义缓存管理器 整合spring-cache - */ - @Bean - public CacheManager cacheManager() { - return new PlusSpringCacheManager(); - } - - /** - * redis集群配置 yml - * - * --- # redis 集群配置(单机与集群只能开启一个另一个需要注释掉) - * spring: - * redis: - * cluster: - * nodes: - * - 192.168.0.100:6379 - * - 192.168.0.101:6379 - * - 192.168.0.102:6379 - * # 密码 - * password: - * # 连接超时时间 - * timeout: 10s - * # 是否开启ssl - * ssl: false - * - * redisson: - * # 线程池数量 - * threads: 16 - * # Netty线程池数量 - * nettyThreads: 32 - * # 集群配置 - * clusterServersConfig: - * # 客户端名称 - * clientName: ${ruoyi.name} - * # master最小空闲连接数 - * masterConnectionMinimumIdleSize: 32 - * # master连接池大小 - * masterConnectionPoolSize: 64 - * # slave最小空闲连接数 - * slaveConnectionMinimumIdleSize: 32 - * # slave连接池大小 - * slaveConnectionPoolSize: 64 - * # 连接空闲超时,单位:毫秒 - * idleConnectionTimeout: 10000 - * # 命令等待超时,单位:毫秒 - * timeout: 3000 - * # 发布和订阅连接池大小 - * subscriptionConnectionPoolSize: 50 - * # 读取模式 - * readMode: "SLAVE" - * # 订阅模式 - * subscriptionMode: "MASTER" - */ - -} diff --git a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/config/properties/RedissonProperties.java b/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/config/properties/RedissonProperties.java deleted file mode 100644 index af7a6067..00000000 --- a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/config/properties/RedissonProperties.java +++ /dev/null @@ -1,135 +0,0 @@ -package cc.iotkit.common.redis.config.properties; - -import lombok.Data; -import lombok.NoArgsConstructor; -import org.redisson.config.ReadMode; -import org.redisson.config.SubscriptionMode; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * Redisson 配置属性 - * - * @author Lion Li - */ -@Data -@ConfigurationProperties(prefix = "redisson") -public class RedissonProperties { - - /** - * redis缓存key前缀 - */ - private String keyPrefix; - - /** - * 线程池数量,默认值 = 当前处理核数量 * 2 - */ - private int threads; - - /** - * Netty线程池数量,默认值 = 当前处理核数量 * 2 - */ - private int nettyThreads; - - /** - * 单机服务配置 - */ - private SingleServerConfig singleServerConfig; - - /** - * 集群服务配置 - */ - private ClusterServersConfig clusterServersConfig; - - @Data - @NoArgsConstructor - public static class SingleServerConfig { - - /** - * 客户端名称 - */ - private String clientName; - - /** - * 最小空闲连接数 - */ - private int connectionMinimumIdleSize; - - /** - * 连接池大小 - */ - private int connectionPoolSize; - - /** - * 连接空闲超时,单位:毫秒 - */ - private int idleConnectionTimeout; - - /** - * 命令等待超时,单位:毫秒 - */ - private int timeout; - - /** - * 发布和订阅连接池大小 - */ - private int subscriptionConnectionPoolSize; - - } - - @Data - @NoArgsConstructor - public static class ClusterServersConfig { - - /** - * 客户端名称 - */ - private String clientName; - - /** - * master最小空闲连接数 - */ - private int masterConnectionMinimumIdleSize; - - /** - * master连接池大小 - */ - private int masterConnectionPoolSize; - - /** - * slave最小空闲连接数 - */ - private int slaveConnectionMinimumIdleSize; - - /** - * slave连接池大小 - */ - private int slaveConnectionPoolSize; - - /** - * 连接空闲超时,单位:毫秒 - */ - private int idleConnectionTimeout; - - /** - * 命令等待超时,单位:毫秒 - */ - private int timeout; - - /** - * 发布和订阅连接池大小 - */ - private int subscriptionConnectionPoolSize; - - /** - * 读取模式 - */ - private ReadMode readMode; - - /** - * 订阅模式 - */ - private SubscriptionMode subscriptionMode; - - } - -} diff --git a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/handler/KeyPrefixHandler.java b/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/handler/KeyPrefixHandler.java deleted file mode 100644 index b41eba00..00000000 --- a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/handler/KeyPrefixHandler.java +++ /dev/null @@ -1,50 +0,0 @@ -package cc.iotkit.common.redis.handler; - -import cc.iotkit.common.utils.StringUtils; -import org.redisson.api.NameMapper; - -/** - * redis缓存key前缀处理 - * - * @author ye - * @date 2022/7/14 17:44 - * @since 4.3.0 - */ -public class KeyPrefixHandler implements NameMapper { - - private final String keyPrefix; - - public KeyPrefixHandler(String keyPrefix) { - //前缀为空 则返回空前缀 - this.keyPrefix = StringUtils.isBlank(keyPrefix) ? "" : keyPrefix + ":"; - } - - /** - * 增加前缀 - */ - @Override - public String map(String name) { - if (StringUtils.isBlank(name)) { - return null; - } - if (StringUtils.isNotBlank(keyPrefix) && !name.startsWith(keyPrefix)) { - return keyPrefix + name; - } - return name; - } - - /** - * 去除前缀 - */ - @Override - public String unmap(String name) { - if (StringUtils.isBlank(name)) { - return null; - } - if (StringUtils.isNotBlank(keyPrefix) && name.startsWith(keyPrefix)) { - return name.substring(keyPrefix.length()); - } - return name; - } - -} diff --git a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/manager/PlusSpringCacheManager.java b/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/manager/PlusSpringCacheManager.java deleted file mode 100644 index 58040507..00000000 --- a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/manager/PlusSpringCacheManager.java +++ /dev/null @@ -1,191 +0,0 @@ -/** - * Copyright (c) 2013-2021 Nikita Koksharov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package cc.iotkit.common.redis.manager; - -import cc.iotkit.common.redis.utils.RedisUtils; -import org.redisson.api.RMap; -import org.redisson.api.RMapCache; -import org.redisson.spring.cache.CacheConfig; -import org.redisson.spring.cache.RedissonCache; -import org.springframework.boot.convert.DurationStyle; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; -import org.springframework.cache.transaction.TransactionAwareCacheDecorator; -import org.springframework.util.StringUtils; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -/** - * A {@link org.springframework.cache.CacheManager} implementation - * backed by Redisson instance. - *

- * 修改 RedissonSpringCacheManager 源码 - * 重写 cacheName 处理方法 支持多参数 - * - * @author Nikita Koksharov - * - */ -@SuppressWarnings("unchecked") -public class PlusSpringCacheManager implements CacheManager { - - private boolean dynamic = true; - - private boolean allowNullValues = true; - - private boolean transactionAware = true; - - Map configMap = new ConcurrentHashMap<>(); - ConcurrentMap instanceMap = new ConcurrentHashMap<>(); - - /** - * Creates CacheManager supplied by Redisson instance - */ - public PlusSpringCacheManager() { - } - - - /** - * Defines possibility of storing {@code null} values. - *

- * Default is true - * - * @param allowNullValues stores if true - */ - public void setAllowNullValues(boolean allowNullValues) { - this.allowNullValues = allowNullValues; - } - - /** - * Defines if cache aware of Spring-managed transactions. - * If {@code true} put/evict operations are executed only for successful transaction in after-commit phase. - *

- * Default is false - * - * @param transactionAware cache is transaction aware if true - */ - public void setTransactionAware(boolean transactionAware) { - this.transactionAware = transactionAware; - } - - /** - * Defines 'fixed' cache names. - * A new cache instance will not be created in dynamic for non-defined names. - *

- * `null` parameter setups dynamic mode - * - * @param names of caches - */ - public void setCacheNames(Collection names) { - if (names != null) { - for (String name : names) { - getCache(name); - } - dynamic = false; - } else { - dynamic = true; - } - } - - /** - * Set cache config mapped by cache name - * - * @param config object - */ - public void setConfig(Map config) { - this.configMap = (Map) config; - } - - protected CacheConfig createDefaultConfig() { - return new CacheConfig(); - } - - @Override - public Cache getCache(String name) { - Cache cache = instanceMap.get(name); - if (cache != null) { - return cache; - } - if (!dynamic) { - return cache; - } - - CacheConfig config = configMap.get(name); - if (config == null) { - config = createDefaultConfig(); - configMap.put(name, config); - } - - // 重写 cacheName 支持多参数 - String[] array = StringUtils.delimitedListToStringArray(name, "#"); - name = array[0]; - if (array.length > 1) { - config.setTTL(DurationStyle.detectAndParse(array[1]).toMillis()); - } - if (array.length > 2) { - config.setMaxIdleTime(DurationStyle.detectAndParse(array[2]).toMillis()); - } - if (array.length > 3) { - config.setMaxSize(Integer.parseInt(array[3])); - } - - if (config.getMaxIdleTime() == 0 && config.getTTL() == 0 && config.getMaxSize() == 0) { - return createMap(name, config); - } - - return createMapCache(name, config); - } - - private Cache createMap(String name, CacheConfig config) { - RMap map = RedisUtils.getClient().getMap(name); - - Cache cache = new RedissonCache(map, allowNullValues); - if (transactionAware) { - cache = new TransactionAwareCacheDecorator(cache); - } - Cache oldCache = instanceMap.putIfAbsent(name, cache); - if (oldCache != null) { - cache = oldCache; - } - return cache; - } - - private Cache createMapCache(String name, CacheConfig config) { - RMapCache map = RedisUtils.getClient().getMapCache(name); - - Cache cache = new RedissonCache(map, config, allowNullValues); - if (transactionAware) { - cache = new TransactionAwareCacheDecorator(cache); - } - Cache oldCache = instanceMap.putIfAbsent(name, cache); - if (oldCache != null) { - cache = oldCache; - } else { - map.setMaxSize(config.getMaxSize()); - } - return cache; - } - - @Override - public Collection getCacheNames() { - return Collections.unmodifiableSet(configMap.keySet()); - } - - -} diff --git a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/utils/CacheUtils.java b/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/utils/CacheUtils.java deleted file mode 100644 index 9141b760..00000000 --- a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/utils/CacheUtils.java +++ /dev/null @@ -1,75 +0,0 @@ -package cc.iotkit.common.redis.utils; - -import cc.iotkit.common.utils.SpringUtils; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.redisson.api.RMap; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; - -import java.util.Set; - -/** - * 缓存操作工具类 {@link } - * - * @author Michelle.Chung - * @date 2022/8/13 - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@SuppressWarnings(value = {"unchecked"}) -public class CacheUtils { - - private static final CacheManager CACHE_MANAGER = SpringUtils.getBean(CacheManager.class); - - /** - * 获取缓存组内所有的KEY - * - * @param cacheNames 缓存组名称 - */ - public static Set keys(String cacheNames) { - RMap rmap = (RMap) CACHE_MANAGER.getCache(cacheNames).getNativeCache(); - return rmap.keySet(); - } - - /** - * 获取缓存值 - * - * @param cacheNames 缓存组名称 - * @param key 缓存key - */ - public static T get(String cacheNames, Object key) { - Cache.ValueWrapper wrapper = CACHE_MANAGER.getCache(cacheNames).get(key); - return wrapper != null ? (T) wrapper.get() : null; - } - - /** - * 保存缓存值 - * - * @param cacheNames 缓存组名称 - * @param key 缓存key - * @param value 缓存值 - */ - public static void put(String cacheNames, Object key, Object value) { - CACHE_MANAGER.getCache(cacheNames).put(key, value); - } - - /** - * 删除缓存值 - * - * @param cacheNames 缓存组名称 - * @param key 缓存key - */ - public static void evict(String cacheNames, Object key) { - CACHE_MANAGER.getCache(cacheNames).evict(key); - } - - /** - * 清空缓存值 - * - * @param cacheNames 缓存组名称 - */ - public static void clear(String cacheNames) { - CACHE_MANAGER.getCache(cacheNames).clear(); - } - -} diff --git a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/utils/QueueUtils.java b/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/utils/QueueUtils.java deleted file mode 100644 index 3250a4be..00000000 --- a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/utils/QueueUtils.java +++ /dev/null @@ -1,180 +0,0 @@ -package cc.iotkit.common.redis.utils; - -import cc.iotkit.common.utils.SpringUtils; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.redisson.api.*; - -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; - -/** - * 分布式队列工具 - * 轻量级队列 重量级数据量 请使用 MQ - * 要求 redis 5.X 以上 - * - * @author Lion Li - * @version 3.6.0 新增 - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class QueueUtils { - - private static final RedissonClient CLIENT = SpringUtils.getBean(RedissonClient.class); - - - /** - * 获取客户端实例 - */ - public static RedissonClient getClient() { - return CLIENT; - } - - /** - * 添加普通队列数据 - * - * @param queueName 队列名 - * @param data 数据 - */ - public static boolean addQueueObject(String queueName, T data) { - RBlockingQueue queue = CLIENT.getBlockingQueue(queueName); - return queue.offer(data); - } - - /** - * 通用获取一个队列数据 没有数据返回 null(不支持延迟队列) - * - * @param queueName 队列名 - */ - public static T getQueueObject(String queueName) { - RBlockingQueue queue = CLIENT.getBlockingQueue(queueName); - return queue.poll(); - } - - /** - * 通用删除队列数据(不支持延迟队列) - */ - public static boolean removeQueueObject(String queueName, T data) { - RBlockingQueue queue = CLIENT.getBlockingQueue(queueName); - return queue.remove(data); - } - - /** - * 通用销毁队列 所有阻塞监听 报错(不支持延迟队列) - */ - public static boolean destroyQueue(String queueName) { - RBlockingQueue queue = CLIENT.getBlockingQueue(queueName); - return queue.delete(); - } - - /** - * 添加延迟队列数据 默认毫秒 - * - * @param queueName 队列名 - * @param data 数据 - * @param time 延迟时间 - */ - public static void addDelayedQueueObject(String queueName, T data, long time) { - addDelayedQueueObject(queueName, data, time, TimeUnit.MILLISECONDS); - } - - /** - * 添加延迟队列数据 - * - * @param queueName 队列名 - * @param data 数据 - * @param time 延迟时间 - * @param timeUnit 单位 - */ - public static void addDelayedQueueObject(String queueName, T data, long time, TimeUnit timeUnit) { - RBlockingQueue queue = CLIENT.getBlockingQueue(queueName); - RDelayedQueue delayedQueue = CLIENT.getDelayedQueue(queue); - delayedQueue.offer(data, time, timeUnit); - } - - /** - * 获取一个延迟队列数据 没有数据返回 null - * - * @param queueName 队列名 - */ - public static T getDelayedQueueObject(String queueName) { - RBlockingQueue queue = CLIENT.getBlockingQueue(queueName); - RDelayedQueue delayedQueue = CLIENT.getDelayedQueue(queue); - return delayedQueue.poll(); - } - - /** - * 删除延迟队列数据 - */ - public static boolean removeDelayedQueueObject(String queueName, T data) { - RBlockingQueue queue = CLIENT.getBlockingQueue(queueName); - RDelayedQueue delayedQueue = CLIENT.getDelayedQueue(queue); - return delayedQueue.remove(data); - } - - /** - * 销毁延迟队列 所有阻塞监听 报错 - */ - public static void destroyDelayedQueue(String queueName) { - RBlockingQueue queue = CLIENT.getBlockingQueue(queueName); - RDelayedQueue delayedQueue = CLIENT.getDelayedQueue(queue); - delayedQueue.destroy(); - } - - /** - * 添加优先队列数据 - * - * @param queueName 队列名 - * @param data 数据 - */ - public static boolean addPriorityQueueObject(String queueName, T data) { - RPriorityBlockingQueue priorityBlockingQueue = CLIENT.getPriorityBlockingQueue(queueName); - return priorityBlockingQueue.offer(data); - } - - /** - * 尝试设置 有界队列 容量 用于限制数量 - * - * @param queueName 队列名 - * @param capacity 容量 - */ - public static boolean trySetBoundedQueueCapacity(String queueName, int capacity) { - RBoundedBlockingQueue boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName); - return boundedBlockingQueue.trySetCapacity(capacity); - } - - /** - * 尝试设置 有界队列 容量 用于限制数量 - * - * @param queueName 队列名 - * @param capacity 容量 - * @param destroy 已存在是否销毁 - */ - public static boolean trySetBoundedQueueCapacity(String queueName, int capacity, boolean destroy) { - RBoundedBlockingQueue boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName); - if (boundedBlockingQueue.isExists() && destroy) { - destroyQueue(queueName); - } - return boundedBlockingQueue.trySetCapacity(capacity); - } - - /** - * 添加有界队列数据 - * - * @param queueName 队列名 - * @param data 数据 - * @return 添加成功 true 已达到界限 false - */ - public static boolean addBoundedQueueObject(String queueName, T data) { - RBoundedBlockingQueue boundedBlockingQueue = CLIENT.getBoundedBlockingQueue(queueName); - return boundedBlockingQueue.offer(data); - } - - /** - * 订阅阻塞队列(可订阅所有实现类 例如: 延迟 优先 有界 等) - */ - public static void subscribeBlockingQueue(String queueName, Consumer consumer) { - RBlockingQueue queue = CLIENT.getBlockingQueue(queueName); - queue.subscribeOnElements(consumer); - } - -} diff --git a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/utils/RedisUtils.java b/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/utils/RedisUtils.java deleted file mode 100644 index b6171c6a..00000000 --- a/iot-common/iot-common-redis/src/main/java/cc/iotkit/common/redis/utils/RedisUtils.java +++ /dev/null @@ -1,462 +0,0 @@ -package cc.iotkit.common.redis.utils; - -import cc.iotkit.common.utils.SpringUtils; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.redisson.api.*; - -import java.time.Duration; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * redis 工具类 - * - * @author Lion Li - * @version 3.1.0 新增 - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@SuppressWarnings(value = {"unchecked", "rawtypes"}) -public class RedisUtils { - - private static final RedissonClient CLIENT = SpringUtils.getBean(RedissonClient.class); - - /** - * 限流 - * - * @param key 限流key - * @param rateType 限流类型 - * @param rate 速率 - * @param rateInterval 速率间隔 - * @return -1 表示失败 - */ - public static long rateLimiter(String key, RateType rateType, int rate, int rateInterval) { - RRateLimiter rateLimiter = CLIENT.getRateLimiter(key); - rateLimiter.trySetRate(rateType, rate, rateInterval, RateIntervalUnit.SECONDS); - if (rateLimiter.tryAcquire()) { - return rateLimiter.availablePermits(); - } else { - return -1L; - } - } - - /** - * 获取客户端实例 - */ - public static RedissonClient getClient() { - return CLIENT; - } - - /** - * 发布通道消息 - * - * @param channelKey 通道key - * @param msg 发送数据 - * @param consumer 自定义处理 - */ - public static void publish(String channelKey, T msg, Consumer consumer) { - RTopic topic = CLIENT.getTopic(channelKey); - topic.publish(msg); - consumer.accept(msg); - } - - public static void publish(String channelKey, T msg) { - RTopic topic = CLIENT.getTopic(channelKey); - topic.publish(msg); - } - - /** - * 订阅通道接收消息 - * - * @param channelKey 通道key - * @param clazz 消息类型 - * @param consumer 自定义处理 - */ - public static void subscribe(String channelKey, Class clazz, Consumer consumer) { - RTopic topic = CLIENT.getTopic(channelKey); - topic.addListener(clazz, (channel, msg) -> consumer.accept(msg)); - } - - /** - * 缓存基本的对象,Integer、String、实体类等 - * - * @param key 缓存的键值 - * @param value 缓存的值 - */ - public static void setCacheObject(final String key, final T value) { - setCacheObject(key, value, false); - } - - /** - * 缓存基本的对象,保留当前对象 TTL 有效期 - * - * @param key 缓存的键值 - * @param value 缓存的值 - * @param isSaveTtl 是否保留TTL有效期(例如: set之前ttl剩余90 set之后还是为90) - * @since Redis 6.X 以上使用 setAndKeepTTL 兼容 5.X 方案 - */ - public static void setCacheObject(final String key, final T value, final boolean isSaveTtl) { - RBucket bucket = CLIENT.getBucket(key); - if (isSaveTtl) { - try { - bucket.setAndKeepTTL(value); - } catch (Exception e) { - long timeToLive = bucket.remainTimeToLive(); - setCacheObject(key, value, Duration.ofMillis(timeToLive)); - } - } else { - bucket.set(value); - } - } - - /** - * 缓存基本的对象,Integer、String、实体类等 - * - * @param key 缓存的键值 - * @param value 缓存的值 - * @param duration 时间 - */ - public static void setCacheObject(final String key, final T value, final Duration duration) { - RBatch batch = CLIENT.createBatch(); - RBucketAsync bucket = batch.getBucket(key); - bucket.setAsync(value); - bucket.expireAsync(duration); - batch.execute(); - } - - /** - * 注册对象监听器 - *

- * key 监听器需开启 `notify-keyspace-events` 等 redis 相关配置 - * - * @param key 缓存的键值 - * @param listener 监听器配置 - */ - public static void addObjectListener(final String key, final ObjectListener listener) { - RBucket result = CLIENT.getBucket(key); - result.addListener(listener); - } - - /** - * 设置有效时间 - * - * @param key Redis键 - * @param timeout 超时时间 - * @return true=设置成功;false=设置失败 - */ - public static boolean expire(final String key, final long timeout) { - return expire(key, Duration.ofSeconds(timeout)); - } - - /** - * 设置有效时间 - * - * @param key Redis键 - * @param duration 超时时间 - * @return true=设置成功;false=设置失败 - */ - public static boolean expire(final String key, final Duration duration) { - RBucket rBucket = CLIENT.getBucket(key); - return rBucket.expire(duration); - } - - /** - * 获得缓存的基本对象。 - * - * @param key 缓存键值 - * @return 缓存键值对应的数据 - */ - public static T getCacheObject(final String key) { - RBucket rBucket = CLIENT.getBucket(key); - return rBucket.get(); - } - - /** - * 获得key剩余存活时间 - * - * @param key 缓存键值 - * @return 剩余存活时间 - */ - public static long getTimeToLive(final String key) { - RBucket rBucket = CLIENT.getBucket(key); - return rBucket.remainTimeToLive(); - } - - /** - * 删除单个对象 - * - * @param key 缓存的键值 - */ - public static boolean deleteObject(final String key) { - return CLIENT.getBucket(key).delete(); - } - - /** - * 删除集合对象 - * - * @param collection 多个对象 - */ - public static void deleteObject(final Collection collection) { - RBatch batch = CLIENT.createBatch(); - collection.forEach(t -> { - batch.getBucket(t.toString()).deleteAsync(); - }); - batch.execute(); - } - - /** - * 检查缓存对象是否存在 - * - * @param key 缓存的键值 - */ - public static boolean isExistsObject(final String key) { - return CLIENT.getBucket(key).isExists(); - } - - /** - * 缓存List数据 - * - * @param key 缓存的键值 - * @param dataList 待缓存的List数据 - * @return 缓存的对象 - */ - public static boolean setCacheList(final String key, final List dataList) { - RList rList = CLIENT.getList(key); - return rList.addAll(dataList); - } - - /** - * 注册List监听器 - *

- * key 监听器需开启 `notify-keyspace-events` 等 redis 相关配置 - * - * @param key 缓存的键值 - * @param listener 监听器配置 - */ - public static void addListListener(final String key, final ObjectListener listener) { - RList rList = CLIENT.getList(key); - rList.addListener(listener); - } - - /** - * 获得缓存的list对象 - * - * @param key 缓存的键值 - * @return 缓存键值对应的数据 - */ - public static List getCacheList(final String key) { - RList rList = CLIENT.getList(key); - return rList.readAll(); - } - - /** - * 缓存Set - * - * @param key 缓存键值 - * @param dataSet 缓存的数据 - * @return 缓存数据的对象 - */ - public static boolean setCacheSet(final String key, final Set dataSet) { - RSet rSet = CLIENT.getSet(key); - return rSet.addAll(dataSet); - } - - /** - * 注册Set监听器 - *

- * key 监听器需开启 `notify-keyspace-events` 等 redis 相关配置 - * - * @param key 缓存的键值 - * @param listener 监听器配置 - */ - public static void addSetListener(final String key, final ObjectListener listener) { - RSet rSet = CLIENT.getSet(key); - rSet.addListener(listener); - } - - /** - * 获得缓存的set - * - * @param key 缓存的key - * @return set对象 - */ - public static Set getCacheSet(final String key) { - RSet rSet = CLIENT.getSet(key); - return rSet.readAll(); - } - - /** - * 缓存Map - * - * @param key 缓存的键值 - * @param dataMap 缓存的数据 - */ - public static void setCacheMap(final String key, final Map dataMap) { - if (dataMap != null) { - RMap rMap = CLIENT.getMap(key); - rMap.putAll(dataMap); - } - } - - /** - * 注册Map监听器 - *

- * key 监听器需开启 `notify-keyspace-events` 等 redis 相关配置 - * - * @param key 缓存的键值 - * @param listener 监听器配置 - */ - public static void addMapListener(final String key, final ObjectListener listener) { - RMap rMap = CLIENT.getMap(key); - rMap.addListener(listener); - } - - /** - * 获得缓存的Map - * - * @param key 缓存的键值 - * @return map对象 - */ - public static Map getCacheMap(final String key) { - RMap rMap = CLIENT.getMap(key); - return rMap.getAll(rMap.keySet()); - } - - /** - * 获得缓存Map的key列表 - * - * @param key 缓存的键值 - * @return key列表 - */ - public static Set getCacheMapKeySet(final String key) { - RMap rMap = CLIENT.getMap(key); - return rMap.keySet(); - } - - /** - * 往Hash中存入数据 - * - * @param key Redis键 - * @param hKey Hash键 - * @param value 值 - */ - public static void setCacheMapValue(final String key, final String hKey, final T value) { - RMap rMap = CLIENT.getMap(key); - rMap.put(hKey, value); - } - - /** - * 获取Hash中的数据 - * - * @param key Redis键 - * @param hKey Hash键 - * @return Hash中的对象 - */ - public static T getCacheMapValue(final String key, final String hKey) { - RMap rMap = CLIENT.getMap(key); - return rMap.get(hKey); - } - - /** - * 删除Hash中的数据 - * - * @param key Redis键 - * @param hKey Hash键 - * @return Hash中的对象 - */ - public static T delCacheMapValue(final String key, final String hKey) { - RMap rMap = CLIENT.getMap(key); - return rMap.remove(hKey); - } - - /** - * 获取多个Hash中的数据 - * - * @param key Redis键 - * @param hKeys Hash键集合 - * @return Hash对象集合 - */ - public static Map getMultiCacheMapValue(final String key, final Set hKeys) { - RMap rMap = CLIENT.getMap(key); - return rMap.getAll(hKeys); - } - - /** - * 设置原子值 - * - * @param key Redis键 - * @param value 值 - */ - public static void setAtomicValue(String key, long value) { - RAtomicLong atomic = CLIENT.getAtomicLong(key); - atomic.set(value); - } - - /** - * 获取原子值 - * - * @param key Redis键 - * @return 当前值 - */ - public static long getAtomicValue(String key) { - RAtomicLong atomic = CLIENT.getAtomicLong(key); - return atomic.get(); - } - - /** - * 递增原子值 - * - * @param key Redis键 - * @return 当前值 - */ - public static long incrAtomicValue(String key) { - RAtomicLong atomic = CLIENT.getAtomicLong(key); - return atomic.incrementAndGet(); - } - - /** - * 递减原子值 - * - * @param key Redis键 - * @return 当前值 - */ - public static long decrAtomicValue(String key) { - RAtomicLong atomic = CLIENT.getAtomicLong(key); - return atomic.decrementAndGet(); - } - - /** - * 获得缓存的基本对象列表 - * - * @param pattern 字符串前缀 - * @return 对象列表 - */ - public static Collection keys(final String pattern) { - Stream stream = CLIENT.getKeys().getKeysStreamByPattern(pattern); - return stream.collect(Collectors.toList()); - } - - /** - * 删除缓存的基本对象列表 - * - * @param pattern 字符串前缀 - */ - public static void deleteKeys(final String pattern) { - CLIENT.getKeys().deleteByPattern(pattern); - } - - /** - * 检查redis中是否存在key - * - * @param key 键 - */ - public static Boolean hasKey(String key) { - RKeys rKeys = CLIENT.getKeys(); - return rKeys.countExists(key) > 0; - } -} diff --git a/iot-common/iot-common-redis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/iot-common/iot-common-redis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index cdda9835..00000000 --- a/iot-common/iot-common-redis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.common.redis.config.RedisConfig diff --git a/iot-common/iot-common-satoken/pom.xml b/iot-common/iot-common-satoken/pom.xml deleted file mode 100644 index 41e9c1d9..00000000 --- a/iot-common/iot-common-satoken/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-common-satoken - - - - - cc.iotkit - iot-common-core - - - - cc.iotkit - iot-common-redis - - - - cc.iotkit - iot-common-web - - - - - - - cn.dev33 - sa-token-spring-boot-starter - - - - cn.dev33 - sa-token-dao-redis-jackson - - - - - cn.dev33 - sa-token-jwt - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/config/SaTokenConfig.java b/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/config/SaTokenConfig.java deleted file mode 100644 index 06471950..00000000 --- a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/config/SaTokenConfig.java +++ /dev/null @@ -1,61 +0,0 @@ -package cc.iotkit.common.satoken.config; - -import cc.iotkit.common.satoken.core.dao.PlusSaTokenDao; -import cc.iotkit.common.satoken.core.service.SaPermissionImpl; -import cn.dev33.satoken.dao.SaTokenDao; -import cn.dev33.satoken.interceptor.SaInterceptor; -import cn.dev33.satoken.stp.StpInterface; -import cn.dev33.satoken.stp.StpUtil; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -import java.util.ArrayList; -import java.util.List; - -/** - * sa-token 配置 - * - * @author Lion Li - */ -@Configuration -public class SaTokenConfig implements WebMvcConfigurer { - - /** - * 权限接口实现(使用bean注入方便用户替换) - */ - @Bean - public StpInterface stpInterface() { - return new SaPermissionImpl(); - } - - /** - * 自定义dao层存储 - */ - @Bean - public SaTokenDao saTokenDao() { - return new PlusSaTokenDao(); - } - - // 注册拦截器 - @Override - public void addInterceptors(InterceptorRegistry registry) { - // 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。 - - List swaggerUrls = List.of("/doc.html","/favicon.ico", "/webjars/**", "/resources/**" - , "/swagger-resources/**", "/swagger-ui.html/**"); - - List loginUrls = List.of("/code", "/auth/tenant/list", "/auth/login"); - List openApiUrls = List.of( "/openapi/v1/getToken"); - - List excludeUrls = new ArrayList<>(); - excludeUrls.addAll(loginUrls); - excludeUrls.addAll(swaggerUrls); - excludeUrls.addAll(openApiUrls); - - registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin())) - .addPathPatterns("/**") - .excludePathPatterns(excludeUrls); - } -} diff --git a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/core/dao/PlusSaTokenDao.java b/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/core/dao/PlusSaTokenDao.java deleted file mode 100644 index d35ce393..00000000 --- a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/core/dao/PlusSaTokenDao.java +++ /dev/null @@ -1,176 +0,0 @@ -package cc.iotkit.common.satoken.core.dao; - -import cc.iotkit.common.redis.utils.RedisUtils; -import cn.dev33.satoken.dao.SaTokenDao; -import cn.dev33.satoken.util.SaFoxUtil; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * Sa-Token持久层接口(使用框架自带RedisUtils实现 协议统一) - * - * @author Lion Li - */ -public class PlusSaTokenDao implements SaTokenDao { - - /** - * 获取Value,如无返空 - */ - @Override - public String get(String key) { - return RedisUtils.getCacheObject(key); - } - - /** - * 写入Value,并设定存活时间 (单位: 秒) - */ - @Override - public void set(String key, String value, long timeout) { - if (timeout == 0 || timeout <= NOT_VALUE_EXPIRE) { - return; - } - // 判断是否为永不过期 - if (timeout == NEVER_EXPIRE) { - RedisUtils.setCacheObject(key, value); - } else { - RedisUtils.setCacheObject(key, value, Duration.ofSeconds(timeout)); - } - } - - /** - * 修修改指定key-value键值对 (过期时间不变) - */ - @Override - public void update(String key, String value) { - long expire = getTimeout(key); - // -2 = 无此键 - if (expire == NOT_VALUE_EXPIRE) { - return; - } - this.set(key, value, expire); - } - - /** - * 删除Value - */ - @Override - public void delete(String key) { - RedisUtils.deleteObject(key); - } - - /** - * 获取Value的剩余存活时间 (单位: 秒) - */ - @Override - public long getTimeout(String key) { - long timeout = RedisUtils.getTimeToLive(key); - return timeout < 0 ? timeout : timeout / 1000; - } - - /** - * 修改Value的剩余存活时间 (单位: 秒) - */ - @Override - public void updateTimeout(String key, long timeout) { - // 判断是否想要设置为永久 - if (timeout == NEVER_EXPIRE) { - long expire = getTimeout(key); - if (expire == NEVER_EXPIRE) { - // 如果其已经被设置为永久,则不作任何处理 - } else { - // 如果尚未被设置为永久,那么再次set一次 - this.set(key, this.get(key), timeout); - } - return; - } - RedisUtils.expire(key, Duration.ofSeconds(timeout)); - } - - - /** - * 获取Object,如无返空 - */ - @Override - public Object getObject(String key) { - return RedisUtils.getCacheObject(key); - } - - /** - * 写入Object,并设定存活时间 (单位: 秒) - */ - @Override - public void setObject(String key, Object object, long timeout) { - if (timeout == 0 || timeout <= NOT_VALUE_EXPIRE) { - return; - } - // 判断是否为永不过期 - if (timeout == NEVER_EXPIRE) { - RedisUtils.setCacheObject(key, object); - } else { - RedisUtils.setCacheObject(key, object, Duration.ofSeconds(timeout)); - } - } - - /** - * 更新Object (过期时间不变) - */ - @Override - public void updateObject(String key, Object object) { - long expire = getObjectTimeout(key); - // -2 = 无此键 - if (expire == NOT_VALUE_EXPIRE) { - return; - } - this.setObject(key, object, expire); - } - - /** - * 删除Object - */ - @Override - public void deleteObject(String key) { - RedisUtils.deleteObject(key); - } - - /** - * 获取Object的剩余存活时间 (单位: 秒) - */ - @Override - public long getObjectTimeout(String key) { - long timeout = RedisUtils.getTimeToLive(key); - return timeout < 0 ? timeout : timeout / 1000; - } - - /** - * 修改Object的剩余存活时间 (单位: 秒) - */ - @Override - public void updateObjectTimeout(String key, long timeout) { - // 判断是否想要设置为永久 - if (timeout == NEVER_EXPIRE) { - long expire = getObjectTimeout(key); - if (expire == NEVER_EXPIRE) { - // 如果其已经被设置为永久,则不作任何处理 - } else { - // 如果尚未被设置为永久,那么再次set一次 - this.setObject(key, this.getObject(key), timeout); - } - return; - } - RedisUtils.expire(key, Duration.ofSeconds(timeout)); - } - - - /** - * 搜索数据 - */ - @Override - public List searchData(String prefix, String keyword, int start, int size, boolean sortType) { - Collection keys = RedisUtils.keys(prefix + "*" + keyword + "*"); - List list = new ArrayList<>(keys); - return SaFoxUtil.searchList(list, start, size, sortType); - } -} diff --git a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/core/service/SaPermissionImpl.java b/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/core/service/SaPermissionImpl.java deleted file mode 100644 index 544696fd..00000000 --- a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/core/service/SaPermissionImpl.java +++ /dev/null @@ -1,47 +0,0 @@ -package cc.iotkit.common.satoken.core.service; - -import cc.iotkit.common.enums.UserType; -import cc.iotkit.common.satoken.utils.LoginHelper; -import cc.iotkit.common.undefined.LoginUser; -import cn.dev33.satoken.stp.StpInterface; - -import java.util.ArrayList; -import java.util.List; - -/** - * sa-token 权限管理实现类 - * - * @author Lion Li - */ -public class SaPermissionImpl implements StpInterface { - - /** - * 获取菜单权限列表 - */ - @Override - public List getPermissionList(Object loginId, String loginType) { - LoginUser loginUser = LoginHelper.getLoginUser(); - UserType userType = UserType.getUserType(loginUser.getUserType()); - if (userType == UserType.SYS_USER) { - return new ArrayList<>(loginUser.getMenuPermission()); - } else if (userType == UserType.APP_USER) { - // 其他端 自行根据业务编写 - } - return new ArrayList<>(); - } - - /** - * 获取角色权限列表 - */ - @Override - public List getRoleList(Object loginId, String loginType) { - LoginUser loginUser = LoginHelper.getLoginUser(); - UserType userType = UserType.getUserType(loginUser.getUserType()); - if (userType == UserType.SYS_USER) { - return new ArrayList<>(loginUser.getRolePermission()); - } else if (userType == UserType.APP_USER) { - // 其他端 自行根据业务编写 - } - return new ArrayList<>(); - } -} diff --git a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/listener/UserActionListener.java b/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/listener/UserActionListener.java deleted file mode 100644 index 0b4e1a19..00000000 --- a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/listener/UserActionListener.java +++ /dev/null @@ -1,139 +0,0 @@ -package cc.iotkit.common.satoken.listener; - -import cc.iotkit.common.constant.CacheConstants; -import cc.iotkit.common.enums.UserType; -import cc.iotkit.common.redis.utils.RedisUtils; -import cc.iotkit.common.satoken.utils.LoginHelper; -import cc.iotkit.common.undefined.LoginUser; -import cc.iotkit.common.undefined.UserOnlineDTO; -import cc.iotkit.common.utils.ip.AddressUtils; -import cc.iotkit.common.web.utils.ServletUtils; -import cn.dev33.satoken.config.SaTokenConfig; -import cn.dev33.satoken.listener.SaTokenListener; -import cn.dev33.satoken.stp.SaLoginModel; -import cn.hutool.http.useragent.UserAgent; -import cn.hutool.http.useragent.UserAgentUtil; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -/** - * 用户行为 侦听器的实现 - * - * @author Lion Li - */ -@RequiredArgsConstructor -@Component -@Slf4j -public class UserActionListener implements SaTokenListener { - - private final SaTokenConfig tokenConfig; - - /** - * 每次登录时触发 - */ - @Override - public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginModel loginModel) { - UserType userType = UserType.getUserType(loginId.toString()); - if (userType == UserType.SYS_USER) { - UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent")); - String ip = ServletUtils.getClientIP(); - LoginUser user = LoginHelper.getLoginUser(); - UserOnlineDTO dto = new UserOnlineDTO(); - dto.setIpaddr(ip); - dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip)); - dto.setBrowser(userAgent.getBrowser().getName()); - dto.setOs(userAgent.getOs().getName()); - dto.setLoginTime(System.currentTimeMillis()); - dto.setTokenId(tokenValue); - dto.setUserName(user.getUsername()); - dto.setDeptName(user.getDeptName()); - if(tokenConfig.getTimeout() == -1) { - RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto); - } else { - RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto, Duration.ofSeconds(tokenConfig.getTimeout())); - } - log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue); - } else if (userType == UserType.APP_USER) { - // app端 自行根据业务编写 - } - } - - /** - * 每次注销时触发 - */ - @Override - public void doLogout(String loginType, Object loginId, String tokenValue) { - RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue); - log.info("user doLogout, userId:{}, token:{}", loginId, tokenValue); - } - - /** - * 每次被踢下线时触发 - */ - @Override - public void doKickout(String loginType, Object loginId, String tokenValue) { - RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue); - log.info("user doKickout, userId:{}, token:{}", loginId, tokenValue); - } - - /** - * 每次被顶下线时触发 - */ - @Override - public void doReplaced(String loginType, Object loginId, String tokenValue) { - RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue); - log.info("user doReplaced, userId:{}, token:{}", loginId, tokenValue); - } - - /** - * 每次被封禁时触发 - */ - @Override - public void doDisable(String loginType, Object loginId, String service, int level, long disableTime) { - } - - /** - * 每次被解封时触发 - */ - @Override - public void doUntieDisable(String loginType, Object loginId, String service) { - } - - /** - * 每次打开二级认证时触发 - */ - @Override - public void doOpenSafe(String loginType, String tokenValue, String service, long safeTime) { - } - - /** - * 每次创建Session时触发 - */ - @Override - public void doCloseSafe(String loginType, String tokenValue, String service) { - } - - /** - * 每次创建Session时触发 - */ - @Override - public void doCreateSession(String id) { - } - - /** - * 每次注销Session时触发 - */ - @Override - public void doLogoutSession(String id) { - } - - /** - * 每次Token续期时触发 - */ - @Override - public void doRenewTimeout(String tokenValue, Object loginId, long timeout) { - } -} diff --git a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/utils/AuthUtil.java b/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/utils/AuthUtil.java deleted file mode 100644 index 8fc59b4c..00000000 --- a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/utils/AuthUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.satoken.utils; - -import cc.iotkit.common.constant.Constants; -import cc.iotkit.common.utils.CodecUtil; -import cn.dev33.satoken.stp.StpUtil; -import org.apache.commons.lang3.RandomUtils; - -import java.util.List; - -public class AuthUtil { - - public static String getUserId() { - return String.valueOf(LoginHelper.getUserId()); - } - - public static List getUserRoles() { - return StpUtil.getRoleList(); - } - - public static boolean isAdmin() { - return LoginHelper.isSuperAdmin(); - } - - public static boolean isClientUser() { - return AuthUtil.getUserRoles().contains(Constants.ROLE_CLIENT); - } - - public static boolean hasWriteRole() { - return AuthUtil.getUserRoles().contains(Constants.ROLE_WRITE); - } - - public static String enCryptPwd(String pwd) throws Exception { - return CodecUtil.aesEncrypt(CodecUtil.md5Str(pwd) + ":" - + RandomUtils.nextInt(1000, 9999), Constants.ACCOUNT_SECRET); - } - - public static boolean checkPwd(String pwd, String secret) throws Exception { - String code = CodecUtil.aesDecrypt(secret, Constants.ACCOUNT_SECRET); - String[] arr = code.split(":"); - return arr.length > 0 && CodecUtil.md5Str(pwd).equals(arr[0]); - } -} diff --git a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/utils/LoginHelper.java b/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/utils/LoginHelper.java deleted file mode 100644 index 07a7fa34..00000000 --- a/iot-common/iot-common-satoken/src/main/java/cc/iotkit/common/satoken/utils/LoginHelper.java +++ /dev/null @@ -1,185 +0,0 @@ -package cc.iotkit.common.satoken.utils; - -import cc.iotkit.common.constant.TenantConstants; -import cc.iotkit.common.constant.UserConstants; -import cc.iotkit.common.enums.DeviceType; -import cc.iotkit.common.enums.UserType; -import cc.iotkit.common.undefined.LoginUser; -import cn.dev33.satoken.context.SaHolder; -import cn.dev33.satoken.context.model.SaStorage; -import cn.dev33.satoken.exception.InvalidContextException; -import cn.dev33.satoken.stp.SaLoginModel; -import cn.dev33.satoken.stp.StpUtil; -import cn.hutool.core.util.ObjectUtil; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.util.Objects; -import java.util.Set; - -/** - * 登录鉴权助手 - *

- * user_type 为 用户类型 同一个用户表 可以有多种用户类型 例如 pc,app - * deivce 为 设备类型 同一个用户类型 可以有 多种设备类型 例如 web,ios - * 可以组成 用户类型与设备类型多对多的 权限灵活控制 - *

- * 多用户体系 针对 多种用户类型 但权限控制不一致 - * 可以组成 多用户类型表与多设备类型 分别控制权限 - * - * @author Lion Li - */ -@Slf4j -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class LoginHelper { - - public static final String LOGIN_USER_KEY = "loginUser"; - public static final String TENANT_KEY = "tenantId"; - public static final String USER_KEY = "userId"; - - /** - * 登录系统 - * - * @param loginUser 登录用户信息 - */ - public static void login(LoginUser loginUser) { - loginByDevice(loginUser, null); - } - - /** - * 登录系统 基于 设备类型 - * 针对相同用户体系不同设备 - * - * @param loginUser 登录用户信息 - */ - public static void loginByDevice(LoginUser loginUser, DeviceType deviceType) { - SaStorage storage = SaHolder.getStorage(); - storage.set(LOGIN_USER_KEY, loginUser); - storage.set(TENANT_KEY, loginUser.getTenantId()); - storage.set(USER_KEY, loginUser.getUserId()); - SaLoginModel model = new SaLoginModel(); - if (ObjectUtil.isNotNull(deviceType)) { - model.setDevice(deviceType.getDevice()); - } - StpUtil.login(loginUser.getLoginId(), - model.setExtra(TENANT_KEY, loginUser.getTenantId()) - .setExtra(USER_KEY, loginUser.getUserId())); - StpUtil.getTokenSession().set(LOGIN_USER_KEY, loginUser); - } - - /** - * 获取用户(多级缓存) - */ - public static LoginUser getLoginUser() { - LoginUser loginUser = (LoginUser) SaHolder.getStorage().get(LOGIN_USER_KEY); - if (loginUser != null) { - return loginUser; - } - loginUser = (LoginUser) StpUtil.getTokenSession().get(LOGIN_USER_KEY); - SaHolder.getStorage().set(LOGIN_USER_KEY, loginUser); - return loginUser; - } - - /** - * 获取用户基于token - */ - public static LoginUser getLoginUser(String token) { - return (LoginUser) StpUtil.getTokenSessionByToken(token).get(LOGIN_USER_KEY); - } - - /** - * 获取用户id - */ - public static Long getUserId() { - try { - LoginUser user = LoginUser.from(StpUtil.getLoginIdAsString()); - if (user == null) { - return null; - } - return user.getUserId(); - } catch (Exception e) { - return null; - } - } - - /** - * 获取租户ID - */ - public static String getTenantId() { - try { - LoginUser loginUser = getLoginUser(); - if (loginUser == null) { - Object tenantId = SaHolder.getStorage().get(TENANT_KEY); - if (tenantId == null) { - return null; - } - return tenantId.toString(); - } - return loginUser.getTenantId(); - } catch (Exception e) { - //skip - } - return null; - } - - /** - * 设置租户ID - * - * @param tenantId 租户ID - */ - public static void setTenantId(String tenantId) { - SaHolder.getStorage().set(TENANT_KEY, tenantId); - } - - /** - * 获取部门ID - */ - public static Long getDeptId() { - return getLoginUser().getDeptId(); - } - - /** - * 获取用户账户 - */ - public static String getUsername() { - return getLoginUser().getUsername(); - } - - /** - * 获取用户类型 - */ - public static UserType getUserType() { - String loginId = StpUtil.getLoginIdAsString(); - return UserType.getUserType(loginId); - } - - /** - * 是否为超级管理员 - * - * @param userId 用户ID - * @return 结果 - */ - public static boolean isSuperAdmin(Long userId) { - return UserConstants.SUPER_ADMIN_ID.equals(userId); - } - - public static boolean isSuperAdmin() { - return isSuperAdmin(getUserId()); - } - - /** - * 是否为超级管理员 - * - * @param rolePermission 角色权限标识组 - * @return 结果 - */ - public static boolean isTenantAdmin(Set rolePermission) { - return rolePermission.contains(TenantConstants.TENANT_ADMIN_ROLE_KEY); - } - - public static boolean isTenantAdmin() { - return isTenantAdmin(getLoginUser().getRolePermission()); - } - -} diff --git a/iot-common/iot-common-tenant/pom.xml b/iot-common/iot-common-tenant/pom.xml deleted file mode 100644 index b5baef67..00000000 --- a/iot-common/iot-common-tenant/pom.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-common-tenant - - - - - cc.iotkit - iot-common-core - - - - cc.iotkit - iot-common-redis - - - - cc.iotkit - iot-common-satoken - - - - - - org.springframework.boot - spring-boot-starter-aop - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.aspectj - aspectjrt - - - org.aspectj - aspectjweaver - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - org.codehaus.mojo - aspectj-maven-plugin - 1.14.0 - - ${java.version} - ${java.version} - ${java.version} - true - true - ignore - UTF-8 - false - true - - - - org.hibernate - hibernate-core - - - - - - - - compile - - test-compile - - - - - - - - - \ No newline at end of file diff --git a/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/aspect/TenantFilterAspect.java b/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/aspect/TenantFilterAspect.java deleted file mode 100644 index 8bb0339b..00000000 --- a/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/aspect/TenantFilterAspect.java +++ /dev/null @@ -1,35 +0,0 @@ -package cc.iotkit.common.tenant.aspect; - - -import cc.iotkit.common.satoken.utils.LoginHelper; -import org.aspectj.lang.annotation.AfterReturning; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Pointcut; -import org.hibernate.Session; - -/** - * 类描述... - * - * @author Tiger Chen - * created on 2023/7/14 20:53 - */ - -@Aspect -public class TenantFilterAspect { - - @Pointcut("execution (* org.hibernate.internal.SessionFactoryImpl.SessionBuilderImpl.openSession(..))") - public void openSession() { - } - - @AfterReturning(pointcut = "openSession()", returning = "session") - public void afterOpenSession(Object session) { - if (session instanceof Session) { - String tenantId = LoginHelper.getTenantId(); - if (tenantId != null && !tenantId.equals("000000")) { - org.hibernate.Filter filter = ((Session) session).enableFilter("tenantFilter"); - filter.setParameter("tenantId", tenantId); - } - } - } - -} diff --git a/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/dao/TenantAware.java b/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/dao/TenantAware.java deleted file mode 100644 index 3c5d57c4..00000000 --- a/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/dao/TenantAware.java +++ /dev/null @@ -1,6 +0,0 @@ -package cc.iotkit.common.tenant.dao; - - -public interface TenantAware { - void setTenantId(String tenantId); -} diff --git a/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/entiry/BaseTenantEntity.java b/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/entiry/BaseTenantEntity.java deleted file mode 100644 index b6218a34..00000000 --- a/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/entiry/BaseTenantEntity.java +++ /dev/null @@ -1,82 +0,0 @@ -package cc.iotkit.common.tenant.entiry; - -import cc.iotkit.common.tenant.dao.TenantAware; -import cc.iotkit.common.tenant.listener.TenantListener; -import lombok.Data; -import org.hibernate.annotations.Filter; -import org.hibernate.annotations.FilterDef; -import org.hibernate.annotations.ParamDef; -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 javax.persistence.Column; -import javax.persistence.EntityListeners; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; -import javax.validation.constraints.Size; -import java.io.Serializable; -import java.util.Date; - -/** - * 类描述... - * - * @author Tiger Chen - * created on 2023/7/15 20:53 - */ - - -@MappedSuperclass -@Data -@FilterDef(name = "tenantFilter", parameters = {@ParamDef(name = "tenantId", type = "string")}) -@Filter(name = "tenantFilter", condition = "tenant_id = :tenantId") -@EntityListeners(TenantListener.class) -public abstract class BaseTenantEntity implements TenantAware, Serializable { - private static final long serialVersionUID = 1L; - - @Id - private Long id; - - @Size(max = 30) - @Column(name = "tenant_id") - private String tenantId; - - /** - * 创建部门 - */ - private Long createDept; - - /** - * 创建者 - */ - @CreatedBy - @Column(name = "create_by", updatable = false) - private Long createBy; - - /** - * 创建时间 - */ - @CreatedDate - @Column(name = "create_time", updatable = false) - private Date createTime; - - /** - * 更新者 - */ - @LastModifiedBy - @Column(name = "update_by") - private Long updateBy; - - /** - * 更新时间 - */ - @LastModifiedDate - @Column(name = "update_time") - private Date updateTime; - - public BaseTenantEntity(String tenantId) { - this.tenantId = tenantId; - } - -} \ No newline at end of file diff --git a/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/helper/TenantHelper.java b/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/helper/TenantHelper.java deleted file mode 100644 index 3e111476..00000000 --- a/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/helper/TenantHelper.java +++ /dev/null @@ -1,87 +0,0 @@ -package cc.iotkit.common.tenant.helper; - -import cc.iotkit.common.constant.GlobalConstants; -import cc.iotkit.common.redis.utils.RedisUtils; -import cc.iotkit.common.satoken.utils.LoginHelper; -import cc.iotkit.common.utils.SpringUtils; -import cc.iotkit.common.utils.StringUtils; -import cn.dev33.satoken.context.SaHolder; -import cn.dev33.satoken.spring.SpringMVCUtil; -import cn.hutool.core.convert.Convert; -import com.alibaba.ttl.TransmittableThreadLocal; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -/** - * 租户助手 - * - * @author Lion Li - */ -@Slf4j -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TenantHelper { - - private static final String DYNAMIC_TENANT_KEY = GlobalConstants.GLOBAL_REDIS_KEY + "dynamicTenant"; - - private static final ThreadLocal TEMP_DYNAMIC_TENANT = new TransmittableThreadLocal<>(); - - /** - * 设置动态租户(一直有效 需要手动清理) - *

- * 如果为非web环境 那么只在当前线程内生效 - */ - public static void setDynamic(String tenantId) { - if (!SpringMVCUtil.isWeb()) { - TEMP_DYNAMIC_TENANT.set(tenantId); - return; - } - String cacheKey = DYNAMIC_TENANT_KEY + ":" + LoginHelper.getUserId(); - RedisUtils.setCacheObject(cacheKey, tenantId); - SaHolder.getStorage().set(cacheKey, tenantId); - } - - /** - * 获取动态租户(一直有效 需要手动清理) - *

- * 如果为非web环境 那么只在当前线程内生效 - */ - public static String getDynamic() { - if (!SpringMVCUtil.isWeb()) { - return TEMP_DYNAMIC_TENANT.get(); - } - String cacheKey = DYNAMIC_TENANT_KEY + ":" + LoginHelper.getUserId(); - String tenantId = (String) SaHolder.getStorage().get(cacheKey); - if (StringUtils.isNotBlank(tenantId)) { - return tenantId; - } - tenantId = RedisUtils.getCacheObject(cacheKey); - SaHolder.getStorage().set(cacheKey, tenantId); - return tenantId; - } - - /** - * 清除动态租户 - */ - public static void clearDynamic() { - if (!SpringMVCUtil.isWeb()) { - TEMP_DYNAMIC_TENANT.remove(); - return; - } - String cacheKey = DYNAMIC_TENANT_KEY + ":" + LoginHelper.getUserId(); - RedisUtils.deleteObject(cacheKey); - SaHolder.getStorage().delete(cacheKey); - } - - /** - * 获取当前租户id(动态租户优先) - */ - public static String getTenantId() { - String tenantId = TenantHelper.getDynamic(); - if (StringUtils.isBlank(tenantId)) { - tenantId = LoginHelper.getTenantId(); - } - return tenantId; - } - -} diff --git a/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/listener/TenantListener.java b/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/listener/TenantListener.java deleted file mode 100644 index eb480987..00000000 --- a/iot-common/iot-common-tenant/src/main/java/cc/iotkit/common/tenant/listener/TenantListener.java +++ /dev/null @@ -1,31 +0,0 @@ -package cc.iotkit.common.tenant.listener; - - -import cc.iotkit.common.satoken.utils.LoginHelper; -import cc.iotkit.common.tenant.dao.TenantAware; -import lombok.extern.slf4j.Slf4j; - -import javax.persistence.PrePersist; -import javax.persistence.PreRemove; -import javax.persistence.PreUpdate; - -/** - * 类描述... - * - * @author Tiger Chen - * created on 2023/7/14 20:50 - */ - -@Slf4j -public class TenantListener { - - @PreUpdate - @PreRemove - @PrePersist - public void setTenant(TenantAware entity) { - final String tenantId = LoginHelper.getTenantId(); - if (!"000000".equals(tenantId) && tenantId != null) { - entity.setTenantId(tenantId); - } - } -} diff --git a/iot-common/iot-common-tenant/src/main/resources/META-INF/aop.xml b/iot-common/iot-common-tenant/src/main/resources/META-INF/aop.xml deleted file mode 100644 index 3c6a4419..00000000 --- a/iot-common/iot-common-tenant/src/main/resources/META-INF/aop.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/iot-common/iot-common-web/pom.xml b/iot-common/iot-common-web/pom.xml deleted file mode 100644 index 067caed6..00000000 --- a/iot-common/iot-common-web/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-common-web - - - - - cc.iotkit - iot-common-core - - - - - - - org.springframework.boot - spring-boot-starter-web - - - - cn.hutool - hutool-captcha - - - - com.alibaba - transmittable-thread-local - - - - cn.dev33 - sa-token-core - - - - org.projectlombok - lombok - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/BigNumberSerializer.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/BigNumberSerializer.java deleted file mode 100644 index 60f4360f..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/BigNumberSerializer.java +++ /dev/null @@ -1,42 +0,0 @@ -package cc.iotkit.common.web.config; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.ser.std.NumberSerializer; - -import java.io.IOException; - -/** - * 超出 JS 最大最小值 处理 - * - * @author Lion Li - */ -@JacksonStdImpl -public class BigNumberSerializer extends NumberSerializer { - - /** - * 根据 JS Number.MAX_SAFE_INTEGER 与 Number.MIN_SAFE_INTEGER 得来 - */ - private static final long MAX_SAFE_INTEGER = 9007199254740991L; - private static final long MIN_SAFE_INTEGER = -9007199254740991L; - - /** - * 提供实例 - */ - public static final BigNumberSerializer INSTANCE = new BigNumberSerializer(Number.class); - - public BigNumberSerializer(Class rawType) { - super(rawType); - } - - @Override - public void serialize(Number value, JsonGenerator gen, SerializerProvider provider) throws IOException { - // 超出范围 序列化位字符串 - if (value.longValue() > MIN_SAFE_INTEGER && value.longValue() < MAX_SAFE_INTEGER) { - super.serialize(value, gen, provider); - } else { - gen.writeString(value.toString()); - } - } -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/CaptchaConfig.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/CaptchaConfig.java deleted file mode 100644 index b37b7e8e..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/CaptchaConfig.java +++ /dev/null @@ -1,65 +0,0 @@ -package cc.iotkit.common.web.config; - -import cc.iotkit.common.web.config.properties.CaptchaProperties; -import cn.hutool.captcha.CaptchaUtil; -import cn.hutool.captcha.CircleCaptcha; -import cn.hutool.captcha.LineCaptcha; -import cn.hutool.captcha.ShearCaptcha; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Lazy; - -import java.awt.*; - -/** - * 验证码配置 - * - * @author Lion Li - */ -@AutoConfiguration -@EnableConfigurationProperties(CaptchaProperties.class) -public class CaptchaConfig { - - private static final int WIDTH = 160; - private static final int HEIGHT = 60; - private static final Color BACKGROUND = Color.PINK; - private static final Font FONT = new Font("Arial", Font.BOLD, 48); - - /** - * 圆圈干扰验证码 - */ - @Lazy - @Bean - public CircleCaptcha circleCaptcha() { - CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(WIDTH, HEIGHT); - captcha.setBackground(BACKGROUND); - captcha.setFont(FONT); - return captcha; - } - - /** - * 线段干扰的验证码 - */ - @Lazy - @Bean - public LineCaptcha lineCaptcha() { - LineCaptcha captcha = CaptchaUtil.createLineCaptcha(WIDTH, HEIGHT); - captcha.setBackground(BACKGROUND); - captcha.setFont(FONT); - return captcha; - } - - /** - * 扭曲干扰验证码 - */ - @Lazy - @Bean - public ShearCaptcha shearCaptcha() { - ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(WIDTH, HEIGHT); - captcha.setBackground(BACKGROUND); - captcha.setFont(FONT); - return captcha; - } - -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/CrossConfig.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/CrossConfig.java deleted file mode 100644 index 6ae6aa7a..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/CrossConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.web.config; - - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -public class CrossConfig implements WebMvcConfigurer { - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOriginPatterns("*") - .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") - .allowCredentials(true) - .maxAge(3600) - .allowedHeaders("*"); - } -} \ No newline at end of file diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/FilterConfig.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/FilterConfig.java deleted file mode 100644 index a8fe0ca3..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/FilterConfig.java +++ /dev/null @@ -1,53 +0,0 @@ -package cc.iotkit.common.web.config; - -import cc.iotkit.common.utils.StringUtils; -import cc.iotkit.common.web.config.properties.XssProperties; -import cc.iotkit.common.web.filter.RepeatableFilter; -import cc.iotkit.common.web.filter.XssFilter; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; - -import javax.servlet.DispatcherType; -import java.util.HashMap; -import java.util.Map; - -/** - * Filter配置 - * - * @author Lion Li - */ -@AutoConfiguration -@EnableConfigurationProperties(XssProperties.class) -public class FilterConfig { - - @SuppressWarnings({"rawtypes", "unchecked"}) - @Bean - @ConditionalOnProperty(value = "xss.enabled", havingValue = "true") - public FilterRegistrationBean xssFilterRegistration(XssProperties xssProperties) { - FilterRegistrationBean registration = new FilterRegistrationBean(); - registration.setDispatcherTypes(DispatcherType.REQUEST); - registration.setFilter(new XssFilter()); - registration.addUrlPatterns(StringUtils.split(xssProperties.getUrlPatterns(), StringUtils.SEPARATOR)); - registration.setName("xssFilter"); - registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE); - Map initParameters = new HashMap<>(); - initParameters.put("excludes", xssProperties.getExcludes()); - registration.setInitParameters(initParameters); - return registration; - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - @Bean - public FilterRegistrationBean someFilterRegistration() { - FilterRegistrationBean registration = new FilterRegistrationBean(); - registration.setFilter(new RepeatableFilter()); - registration.addUrlPatterns("/*"); - registration.setName("repeatableFilter"); - registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE); - return registration; - } - -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/JacksonConfig.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/JacksonConfig.java deleted file mode 100644 index c48530a3..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/JacksonConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package cc.iotkit.common.web.config; - -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.context.annotation.Bean; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.TimeZone; - -/** - * jackson 配置 - * - * @author Lion Li - */ -@Slf4j -@AutoConfiguration(before = JacksonAutoConfiguration.class) -public class JacksonConfig { - - @Bean - public Jackson2ObjectMapperBuilderCustomizer customizer() { - return builder -> { - // 全局配置序列化返回 JSON 处理 - JavaTimeModule javaTimeModule = new JavaTimeModule(); - javaTimeModule.addSerializer(Long.class, BigNumberSerializer.INSTANCE); - javaTimeModule.addSerializer(Long.TYPE, BigNumberSerializer.INSTANCE); - javaTimeModule.addSerializer(BigInteger.class, BigNumberSerializer.INSTANCE); - javaTimeModule.addSerializer(BigDecimal.class, ToStringSerializer.instance); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(formatter)); - javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(formatter)); - builder.modules(javaTimeModule); - builder.timeZone(TimeZone.getDefault()); - log.info("初始化 jackson 配置"); - }; - } - -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/ResourcesConfig.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/ResourcesConfig.java deleted file mode 100644 index fe34a808..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/ResourcesConfig.java +++ /dev/null @@ -1,52 +0,0 @@ -package cc.iotkit.common.web.config; - -import cc.iotkit.common.web.interceptor.PlusWebInvokeTimeInterceptor; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.springframework.web.filter.CorsFilter; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -/** - * 通用配置 - * - * @author Lion Li - */ -@AutoConfiguration -public class ResourcesConfig implements WebMvcConfigurer { - - @Override - public void addInterceptors(InterceptorRegistry registry) { - // 全局访问性能拦截 - registry.addInterceptor(new PlusWebInvokeTimeInterceptor()); - } - - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - } - - /** - * 跨域配置 - */ - @Bean - public CorsFilter corsFilter() { - CorsConfiguration config = new CorsConfiguration(); - config.setAllowCredentials(true); - // 设置访问源地址 - config.addAllowedOriginPattern("*"); - // 设置访问源请求头 - config.addAllowedHeader("*"); - // 设置访问源请求方法 - config.addAllowedMethod("*"); - // 有效期 1800秒 - config.setMaxAge(1800L); - // 添加映射路径,拦截一切请求 - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**", config); - // 返回新的CorsFilter - return new CorsFilter(source); - } -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/TenantConfig.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/TenantConfig.java deleted file mode 100644 index 16896708..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/TenantConfig.java +++ /dev/null @@ -1,22 +0,0 @@ -package cc.iotkit.common.web.config; - -import cc.iotkit.common.web.interceptor.TenantInterceptor; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -/** - * 注册租户ID拦截器. - * - * @author Tiger Chen - * created on 2023/7/15 14:48 - */ - -@Configuration -public class TenantConfig implements WebMvcConfigurer { - @Override - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new TenantInterceptor()); - } - -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/properties/CaptchaProperties.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/properties/CaptchaProperties.java deleted file mode 100644 index 6d0a131d..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/properties/CaptchaProperties.java +++ /dev/null @@ -1,40 +0,0 @@ -package cc.iotkit.common.web.config.properties; - -import cc.iotkit.common.web.enums.CaptchaCategory; -import cc.iotkit.common.web.enums.CaptchaType; -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -/** - * 验证码 配置属性 - * - * @author Lion Li - */ -@Data -@ConfigurationProperties(prefix = "captcha") -@Component -public class CaptchaProperties { - - private Boolean enable; - - /** - * 验证码类型 - */ - private CaptchaType type; - - /** - * 验证码类别 - */ - private CaptchaCategory category; - - /** - * 数字验证码位数 - */ - private Integer numberLength; - - /** - * 字符验证码长度 - */ - private Integer charLength; -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/properties/XssProperties.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/properties/XssProperties.java deleted file mode 100644 index 4f8e9a08..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/config/properties/XssProperties.java +++ /dev/null @@ -1,30 +0,0 @@ -package cc.iotkit.common.web.config.properties; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * xss过滤 配置属性 - * - * @author Lion Li - */ -@Data -@ConfigurationProperties(prefix = "xss") -public class XssProperties { - - /** - * 过滤开关 - */ - private String enabled; - - /** - * 排除链接(多个用逗号分隔) - */ - private String excludes; - - /** - * 匹配链接 - */ - private String urlPatterns; - -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/core/BaseController.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/core/BaseController.java deleted file mode 100644 index 43fd7dbf..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/core/BaseController.java +++ /dev/null @@ -1,56 +0,0 @@ -package cc.iotkit.common.web.core; - - -import cc.iotkit.common.exception.ViewException; -import cc.iotkit.common.utils.StringUtils; - -/** - * web层通用数据处理 - * - * @author Lion Li - */ -public class BaseController { - - public static void fail() { - throw new ViewException("操作失败"); - } - - public static void fail(String msg) { - throw new ViewException(ViewException.CODE_FAILED, msg); - } - - public static void fail(T data) { - throw new ViewException(ViewException.CODE_FAILED, "操作失败", data); - } - - public static void fail(String msg, T data) { - throw new ViewException(ViewException.CODE_FAILED, msg, data); - } - - /** - * 返回警告消息 - * - * @param msg 返回内容 - */ - public static void warn(String msg) { - throw new ViewException(ViewException.CODE_WARN, msg); - } - - /** - * 返回警告消息 - * - * @param msg 返回内容 - * @param data 数据对象 - */ - public static void warn(String msg, T data) { - throw new ViewException(ViewException.CODE_WARN, msg, data); - } - - /** - * 页面跳转 - */ - public String redirect(String url) { - return StringUtils.format("redirect:{}", url); - } - -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/enums/CaptchaCategory.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/enums/CaptchaCategory.java deleted file mode 100644 index ca5bddd3..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/enums/CaptchaCategory.java +++ /dev/null @@ -1,35 +0,0 @@ -package cc.iotkit.common.web.enums; - -import cn.hutool.captcha.AbstractCaptcha; -import cn.hutool.captcha.CircleCaptcha; -import cn.hutool.captcha.LineCaptcha; -import cn.hutool.captcha.ShearCaptcha; -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 验证码类别 - * - * @author Lion Li - */ -@Getter -@AllArgsConstructor -public enum CaptchaCategory { - - /** - * 线段干扰 - */ - LINE(LineCaptcha.class), - - /** - * 圆圈干扰 - */ - CIRCLE(CircleCaptcha.class), - - /** - * 扭曲干扰 - */ - SHEAR(ShearCaptcha.class); - - private final Class clazz; -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/enums/CaptchaType.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/enums/CaptchaType.java deleted file mode 100644 index 01590080..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/enums/CaptchaType.java +++ /dev/null @@ -1,29 +0,0 @@ -package cc.iotkit.common.web.enums; - -import cc.iotkit.common.web.utils.UnsignedMathGenerator; -import cn.hutool.captcha.generator.CodeGenerator; -import cn.hutool.captcha.generator.RandomGenerator; -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 验证码类型 - * - * @author Lion Li - */ -@Getter -@AllArgsConstructor -public enum CaptchaType { - - /** - * 数字 - */ - MATH(UnsignedMathGenerator.class), - - /** - * 字符 - */ - CHAR(RandomGenerator.class); - - private final Class clazz; -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/RepeatableFilter.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/RepeatableFilter.java deleted file mode 100644 index 03e538f2..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/RepeatableFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -package cc.iotkit.common.web.filter; - -import cc.iotkit.common.utils.StringUtils; -import org.springframework.http.MediaType; - -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; -import java.io.IOException; - -/** - * Repeatable 过滤器 - * - * @author ruoyi - */ -public class RepeatableFilter implements Filter { - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws IOException, ServletException { - ServletRequest requestWrapper = null; - if (request instanceof HttpServletRequest - && StringUtils.startsWithIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE)) { - requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response); - } - if (null == requestWrapper) { - chain.doFilter(request, response); - } else { - chain.doFilter(requestWrapper, response); - } - } - - @Override - public void destroy() { - - } -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/RepeatedlyRequestWrapper.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/RepeatedlyRequestWrapper.java deleted file mode 100644 index 00ca72c4..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/RepeatedlyRequestWrapper.java +++ /dev/null @@ -1,67 +0,0 @@ -package cc.iotkit.common.web.filter; - -import cc.iotkit.common.constant.Constants; -import cn.hutool.core.io.IoUtil; - -import javax.servlet.ReadListener; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStreamReader; - -/** - * 构建可重复读取inputStream的request - * - * @author ruoyi - */ -public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper { - private final byte[] body; - - public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException { - super(request); - request.setCharacterEncoding(Constants.UTF8); - response.setCharacterEncoding(Constants.UTF8); - - body = IoUtil.readBytes(request.getInputStream(), false); - } - - @Override - public BufferedReader getReader() throws IOException { - return new BufferedReader(new InputStreamReader(getInputStream())); - } - - @Override - public ServletInputStream getInputStream() throws IOException { - final ByteArrayInputStream bais = new ByteArrayInputStream(body); - return new ServletInputStream() { - @Override - public int read() throws IOException { - return bais.read(); - } - - @Override - public int available() throws IOException { - return body.length; - } - - @Override - public boolean isFinished() { - return false; - } - - @Override - public boolean isReady() { - return false; - } - - @Override - public void setReadListener(ReadListener readListener) { - - } - }; - } -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/XssFilter.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/XssFilter.java deleted file mode 100644 index 28e931a4..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/XssFilter.java +++ /dev/null @@ -1,61 +0,0 @@ -package cc.iotkit.common.web.filter; - -import cc.iotkit.common.utils.StringUtils; -import org.springframework.http.HttpMethod; - -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * 防止XSS攻击的过滤器 - * - * @author ruoyi - */ -public class XssFilter implements Filter { - /** - * 排除链接 - */ - public List excludes = new ArrayList<>(); - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - String tempExcludes = filterConfig.getInitParameter("excludes"); - if (StringUtils.isNotEmpty(tempExcludes)) { - String[] url = tempExcludes.split(StringUtils.SEPARATOR); - excludes.addAll(Arrays.asList(url)); - } - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws IOException, ServletException { - HttpServletRequest req = (HttpServletRequest) request; - HttpServletResponse resp = (HttpServletResponse) response; - if (handleExcludeURL(req, resp)) { - chain.doFilter(request, response); - return; - } - XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper((HttpServletRequest) request); - chain.doFilter(xssRequest, response); - } - - private boolean handleExcludeURL(HttpServletRequest request, HttpServletResponse response) { - String url = request.getServletPath(); - String method = request.getMethod(); - // GET DELETE 不过滤 - if (method == null || HttpMethod.GET.matches(method) || HttpMethod.DELETE.matches(method)) { - return true; - } - return StringUtils.matches(url, excludes); - } - - @Override - public void destroy() { - - } -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/XssHttpServletRequestWrapper.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/XssHttpServletRequestWrapper.java deleted file mode 100644 index 914b3831..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/filter/XssHttpServletRequestWrapper.java +++ /dev/null @@ -1,97 +0,0 @@ -package cc.iotkit.common.web.filter; - -import cc.iotkit.common.utils.StringUtils; -import cn.hutool.core.io.IoUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HtmlUtil; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; - -import javax.servlet.ReadListener; -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - -/** - * XSS过滤处理 - * - * @author ruoyi - */ -public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { - /** - * @param request - */ - public XssHttpServletRequestWrapper(HttpServletRequest request) { - super(request); - } - - @Override - public String[] getParameterValues(String name) { - String[] values = super.getParameterValues(name); - if (values != null) { - int length = values.length; - String[] escapseValues = new String[length]; - for (int i = 0; i < length; i++) { - // 防xss攻击和过滤前后空格 - escapseValues[i] = HtmlUtil.cleanHtmlTag(values[i]).trim(); - } - return escapseValues; - } - return super.getParameterValues(name); - } - - @Override - public ServletInputStream getInputStream() throws IOException { - // 非json类型,直接返回 - if (!isJsonRequest()) { - return super.getInputStream(); - } - - // 为空,直接返回 - String json = StrUtil.str(IoUtil.readBytes(super.getInputStream(), false), StandardCharsets.UTF_8); - if (StringUtils.isEmpty(json)) { - return super.getInputStream(); - } - - // xss过滤 - json = HtmlUtil.cleanHtmlTag(json).trim(); - byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8); - final ByteArrayInputStream bis = IoUtil.toStream(jsonBytes); - return new ServletInputStream() { - @Override - public boolean isFinished() { - return true; - } - - @Override - public boolean isReady() { - return true; - } - - @Override - public int available() throws IOException { - return jsonBytes.length; - } - - @Override - public void setReadListener(ReadListener readListener) { - } - - @Override - public int read() throws IOException { - return bis.read(); - } - }; - } - - /** - * 是否是Json请求 - */ - public boolean isJsonRequest() { - String header = super.getHeader(HttpHeaders.CONTENT_TYPE); - return StringUtils.startsWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE); - } -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/GlobalExceptionHandler.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/GlobalExceptionHandler.java deleted file mode 100644 index c830f115..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/GlobalExceptionHandler.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.web.handler; - -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.exception.ViewException; -import cn.dev33.satoken.exception.NotLoginException; -import cn.dev33.satoken.exception.NotPermissionException; -import cn.dev33.satoken.exception.NotRoleException; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.servlet.http.HttpServletResponse; - -@Slf4j -@ControllerAdvice -public class GlobalExceptionHandler { - - @ExceptionHandler(Exception.class) - @ResponseBody - public RequestResult handleException(Exception e, HttpServletResponse response) { - log.error("handler exception", e); - if (e instanceof NotLoginException) { - response.setStatus(401); - return new RequestResult(401, "未授权的请求"); - } - - if (e instanceof NotPermissionException || e instanceof NotRoleException) { - response.setStatus(403); - return new RequestResult(403, "没有权限"); - } - if (e instanceof BizException) { - BizException bizException = (BizException) e; - response.setStatus(200); - return new RequestResult(bizException.getCode(), bizException.getMessage()); - } - if (e instanceof ViewException) { - response.setStatus(200); - return new RequestResult(((ViewException) e).getCode(), e.getMessage()); - } - - if (e.getMessage().contains("Unauthorized")) { - response.setStatus(403); - return new RequestResult(403, "没有权限"); - } - response.setStatus(500); - return new RequestResult(500, e.getMessage()); - } - - @NoArgsConstructor - @AllArgsConstructor - @Data - public static class RequestResult { - private int code; - private String message; - } - -} - - diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/ResponseResultHandler.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/ResponseResultHandler.java deleted file mode 100644 index 63c5263b..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/ResponseResultHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.common.web.handler; - -import cc.iotkit.common.api.Response; -import cn.dev33.satoken.util.SaResult; -import cn.hutool.core.util.IdUtil; -import org.springframework.core.MethodParameter; -import org.springframework.http.MediaType; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.http.server.ServerHttpRequest; -import org.springframework.http.server.ServerHttpResponse; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; - -import java.util.Map; - -@ControllerAdvice(basePackages = {"cc.iotkit"}) -public class ResponseResultHandler implements ResponseBodyAdvice { - @Override - public boolean supports(MethodParameter returnType, Class> converterType) { - return !converterType.equals(StringHttpMessageConverter.class); - } - - @Override - public Object beforeBodyWrite(Object body, MethodParameter returnType, - MediaType selectedContentType, - Class> selectedConverterType, - ServerHttpRequest request, ServerHttpResponse response) { - if (body instanceof GlobalExceptionHandler.RequestResult) { - GlobalExceptionHandler.RequestResult requestResult = (GlobalExceptionHandler.RequestResult) body; - return new Response(requestResult.getCode(), requestResult.getMessage(), - "", IdUtil.simpleUUID()); - } else if (body instanceof SaResult) { - SaResult result = (SaResult) body; - return new Response(result.getCode(), result.getMsg(), result.getData(), IdUtil.simpleUUID()); - } else if (body instanceof Map) { - Map map = (Map) body; - //spring mvc内部异常 - if (map.containsKey("timestamp") && map.containsKey("status") && map.containsKey("error")) { - return new Response((Integer) map.get("status"), (String) map.get("error"), - "", IdUtil.simpleUUID()); - } - } else if (body instanceof Response) { - return body; - } - - return new Response(200, "", body, IdUtil.simpleUUID()); - } - -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/interceptor/PlusWebInvokeTimeInterceptor.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/interceptor/PlusWebInvokeTimeInterceptor.java deleted file mode 100644 index afe37d6f..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/interceptor/PlusWebInvokeTimeInterceptor.java +++ /dev/null @@ -1,106 +0,0 @@ -package cc.iotkit.common.web.interceptor; - -import cc.iotkit.common.api.Request; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.common.utils.SpringUtils; -import cc.iotkit.common.utils.StringUtils; -import cc.iotkit.common.web.filter.RepeatedlyRequestWrapper; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.io.IoUtil; -import cn.hutool.core.map.MapUtil; -import com.alibaba.ttl.TransmittableThreadLocal; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.time.StopWatch; -import org.slf4j.MDC; -import org.springframework.http.MediaType; -import org.springframework.web.servlet.HandlerInterceptor; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.BufferedReader; -import java.util.Map; -import java.util.Objects; - -/** - * web的调用时间统计拦截器 - * dev环境有效 - * - * @author Lion Li - * @since 3.3.0 - */ -@Slf4j -public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor { - - private final static String prodProfile = "prod"; - - private final TransmittableThreadLocal invokeTimeTL = new TransmittableThreadLocal<>(); - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - if (!prodProfile.equals(SpringUtils.getActiveProfile())) { - String url = request.getMethod() + " " + request.getRequestURI(); - log.info("request handler:{}, threadId:{}", url, Thread.currentThread().getId()); - - // 打印请求参数 - if (isJsonRequest(request)) { - String jsonParam = ""; - if (request instanceof RepeatedlyRequestWrapper) { - BufferedReader reader = request.getReader(); - jsonParam = IoUtil.read(reader); - Request req = JsonUtils.parseObject(jsonParam, Request.class); - MDC.put("requestId", req.getRequestId()); - } - log.debug("开始请求 => URL[{}],参数类型[json],参数:[{}]", url, jsonParam); - } else { - Map parameterMap = request.getParameterMap(); - if (MapUtil.isNotEmpty(parameterMap)) { - String parameters = JsonUtils.toJsonString(parameterMap); - String[] requestIds = parameterMap.get("requestId"); - if (Objects.nonNull(requestIds) && requestIds.length > 0) { - MDC.put("requestId", requestIds[0]); - } - log.debug("开始请求 => URL[{}],参数类型[param],参数:[{}]", url, parameters); - } else { - log.debug("开始请求 => URL[{}],无参数", url); - } - } - - StopWatch stopWatch = new StopWatch(); - invokeTimeTL.set(stopWatch); - stopWatch.start(); - } - return true; - } - - @Override - public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { - - } - - @Override - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { - if (!prodProfile.equals(SpringUtils.getActiveProfile())) { - StopWatch stopWatch = invokeTimeTL.get(); - stopWatch.stop(); - log.debug("结束请求 => URL[{}],耗时:[{}]毫秒", request.getMethod() + " " + request.getRequestURI(), stopWatch.getTime()); - invokeTimeTL.remove(); - MDC.clear(); - } - } - - /** - * 判断本次请求的数据类型是否为json - * - * @param request request - * @return boolean - */ - private boolean isJsonRequest(HttpServletRequest request) { - String contentType = request.getContentType(); - if (contentType != null) { - return StringUtils.startsWithIgnoreCase(contentType, MediaType.APPLICATION_JSON_VALUE); - } - return false; - } - -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/interceptor/TenantInterceptor.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/interceptor/TenantInterceptor.java deleted file mode 100644 index 5114b043..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/interceptor/TenantInterceptor.java +++ /dev/null @@ -1,38 +0,0 @@ -package cc.iotkit.common.web.interceptor; - -import cn.dev33.satoken.context.SaHolder; -import org.springframework.web.servlet.HandlerInterceptor; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * 新增租户拦截器,拦截请求头中的租户id - * - * @author Tiger Chen - * created on 2023/7/15 14:26 - */ - - -public class TenantInterceptor implements HandlerInterceptor { - - public static final String TENANT_ID = "Tenant-Id"; - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { - if (request.getHeader(TENANT_ID) != null) { - String tenantId = request.getHeader(TENANT_ID); - SaHolder.getStorage().set("tenantId", tenantId); - } - return true; - } - - @Override - public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { - } - - @Override - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { - } -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/utils/ServletUtils.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/utils/ServletUtils.java deleted file mode 100644 index 2ac44a11..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/utils/ServletUtils.java +++ /dev/null @@ -1,218 +0,0 @@ -package cc.iotkit.common.web.utils; - -import cc.iotkit.common.utils.StringUtils; -import cn.hutool.core.convert.Convert; -import cn.hutool.http.HttpStatus; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.springframework.http.MediaType; -import org.springframework.web.context.request.RequestAttributes; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import javax.servlet.ServletRequest; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import java.io.IOException; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - - -/** - * 客户端工具类 - * - * @author ruoyi - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ServletUtils { - - /** - * 获取String参数 - */ - public static String getParameter(String name) { - return getRequest().getParameter(name); - } - - /** - * 获取String参数 - */ - public static String getParameter(String name, String defaultValue) { - return Convert.toStr(getRequest().getParameter(name), defaultValue); - } - - /** - * 获取Integer参数 - */ - public static Integer getParameterToInt(String name) { - return Convert.toInt(getRequest().getParameter(name)); - } - - /** - * 获取Integer参数 - */ - public static Integer getParameterToInt(String name, Integer defaultValue) { - return Convert.toInt(getRequest().getParameter(name), defaultValue); - } - - /** - * 获取Boolean参数 - */ - public static Boolean getParameterToBool(String name) { - return Convert.toBool(getRequest().getParameter(name)); - } - - /** - * 获取Boolean参数 - */ - public static Boolean getParameterToBool(String name, Boolean defaultValue) { - return Convert.toBool(getRequest().getParameter(name), defaultValue); - } - - /** - * 获得所有请求参数 - * - * @param request 请求对象{@link ServletRequest} - * @return Map - */ - public static Map getParams(ServletRequest request) { - final Map map = request.getParameterMap(); - return Collections.unmodifiableMap(map); - } - - /** - * 获得所有请求参数 - * - * @param request 请求对象{@link ServletRequest} - * @return Map - */ - public static Map getParamMap(ServletRequest request) { - Map params = new HashMap<>(); - for (Map.Entry entry : getParams(request).entrySet()) { - params.put(entry.getKey(), StringUtils.join(entry.getValue(), StringUtils.SEPARATOR)); - } - return params; - } - - /** - * 获取request - */ - public static HttpServletRequest getRequest() { - return getRequestAttributes().getRequest(); - } - - /** - * 获取response - */ - public static HttpServletResponse getResponse() { - return getRequestAttributes().getResponse(); - } - - /** - * 获取session - */ - public static HttpSession getSession() { - return getRequest().getSession(); - } - - public static ServletRequestAttributes getRequestAttributes() { - RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); - return (ServletRequestAttributes) attributes; - } - - /** - * 将字符串渲染到客户端 - * - * @param response 渲染对象 - * @param string 待渲染的字符串 - */ - public static void renderString(HttpServletResponse response, String string) { - try { - response.setStatus(HttpStatus.HTTP_OK); - response.setContentType(MediaType.APPLICATION_JSON_VALUE); - response.setCharacterEncoding(StandardCharsets.UTF_8.toString()); - response.getWriter().print(string); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * 是否是Ajax异步请求 - * - * @param request - */ - public static boolean isAjaxRequest(HttpServletRequest request) { - - String accept = request.getHeader("accept"); - if (accept != null && accept.contains(MediaType.APPLICATION_JSON_VALUE)) { - return true; - } - - String xRequestedWith = request.getHeader("X-Requested-With"); - if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) { - return true; - } - - String uri = request.getRequestURI(); - if (StringUtils.equalsAnyIgnoreCase(uri, ".json", ".xml")) { - return true; - } - - String ajax = request.getParameter("__ajax"); - return StringUtils.equalsAnyIgnoreCase(ajax, "json", "xml"); - } - - public static String getClientIP() { - return getRequest().getRemoteAddr(); - } - - /** - * 内容编码 - * - * @param str 内容 - * @return 编码后的内容 - */ - public static String urlEncode(String str) { - return URLEncoder.encode(str, StandardCharsets.UTF_8); - } - - /** - * 内容解码 - * - * @param str 内容 - * @return 解码后的内容 - */ - public static String urlDecode(String str) { - return URLDecoder.decode(str, StandardCharsets.UTF_8); - } - - /** - * 百分号编码工具方法 - * - * @param s 需要百分号编码的字符串 - * @return 百分号编码后的字符串 - */ - public static String percentEncode(String s) { - String encode = URLEncoder.encode(s, StandardCharsets.UTF_8); - return encode.replaceAll("\\+", "%20"); - } - - /** - * 下载文件名重新编码 - * - * @param response 响应对象 - * @param realFileName 真实文件名 - */ - public static void setAttachmentResponseHeader(HttpServletResponse response, String realFileName) { - String percentEncodedFileName = percentEncode(realFileName); - String contentDispositionValue = String.format("attachment; filename=%s;filename*=utf-8''%s", percentEncodedFileName, percentEncodedFileName); - response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename"); - response.setHeader("Content-disposition", contentDispositionValue); - response.setHeader("download-filename", percentEncodedFileName); - } -} diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/utils/UnsignedMathGenerator.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/utils/UnsignedMathGenerator.java deleted file mode 100644 index abc810f2..00000000 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/utils/UnsignedMathGenerator.java +++ /dev/null @@ -1,84 +0,0 @@ -package cc.iotkit.common.web.utils; - -import cc.iotkit.common.utils.StringUtils; -import cn.hutool.captcha.generator.CodeGenerator; -import cn.hutool.core.math.Calculator; -import cn.hutool.core.text.CharPool; -import cn.hutool.core.util.RandomUtil; - -/** - * 无符号计算生成器 - * - * @author Lion Li - */ -public class UnsignedMathGenerator implements CodeGenerator { - private static final long serialVersionUID = -5514819971774091076L; - - private static final String OPERATORS = "+-*"; - - /** - * 参与计算数字最大长度 - */ - private final int numberLength; - - /** - * 构造 - */ - public UnsignedMathGenerator() { - this(2); - } - - /** - * 构造 - * - * @param numberLength 参与计算最大数字位数 - */ - public UnsignedMathGenerator(int numberLength) { - this.numberLength = numberLength; - } - - @Override - public String generate() { - final int limit = getLimit(); - int a = RandomUtil.randomInt(limit); - int b = RandomUtil.randomInt(limit); - String max = Integer.toString(Math.max(a,b)); - String min = Integer.toString(Math.min(a,b)); - max = StringUtils.rightPad(max, this.numberLength, CharPool.SPACE); - min = StringUtils.rightPad(min, this.numberLength, CharPool.SPACE); - - return max + RandomUtil.randomChar(OPERATORS) + min + '='; - } - - @Override - public boolean verify(String code, String userInputCode) { - int result; - try { - result = Integer.parseInt(userInputCode); - } catch (NumberFormatException e) { - // 用户输入非数字 - return false; - } - - final int calculateResult = (int) Calculator.conversion(code); - return result == calculateResult; - } - - /** - * 获取验证码长度 - * - * @return 验证码长度 - */ - public int getLength() { - return this.numberLength * 2 + 2; - } - - /** - * 根据长度获取参与计算数字最大值 - * - * @return 最大值 - */ - private int getLimit() { - return Integer.parseInt("1" + StringUtils.repeat('0', this.numberLength)); - } -} diff --git a/iot-common/iot-common-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/iot-common/iot-common-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 7c027df9..00000000 --- a/iot-common/iot-common-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1,4 +0,0 @@ -cc.iotkit.common.web.config.CaptchaConfig -cc.iotkit.common.web.config.FilterConfig -#cc.iotkit.common.web.config.I18nConfig -cc.iotkit.common.web.config.ResourcesConfig diff --git a/iot-common/iot-common-websocket/pom.xml b/iot-common/iot-common-websocket/pom.xml deleted file mode 100644 index b4e17363..00000000 --- a/iot-common/iot-common-websocket/pom.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-common-websocket - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-message-bus/iot-message-core/pom.xml b/iot-common/iot-message-bus/iot-message-core/pom.xml deleted file mode 100644 index e6a078fb..00000000 --- a/iot-common/iot-message-bus/iot-message-core/pom.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - iot-message-bus - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-message-core - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-message-bus/iot-message-core/src/main/java/cc/iotkit/mq/ConsumerHandler.java b/iot-common/iot-message-bus/iot-message-core/src/main/java/cc/iotkit/mq/ConsumerHandler.java deleted file mode 100644 index 55c329da..00000000 --- a/iot-common/iot-message-bus/iot-message-core/src/main/java/cc/iotkit/mq/ConsumerHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.mq; - -public interface ConsumerHandler { - - void handler(T msg); - -} diff --git a/iot-common/iot-message-bus/iot-message-core/src/main/java/cc/iotkit/mq/MqConsumer.java b/iot-common/iot-message-bus/iot-message-core/src/main/java/cc/iotkit/mq/MqConsumer.java deleted file mode 100644 index c3678d06..00000000 --- a/iot-common/iot-message-bus/iot-message-core/src/main/java/cc/iotkit/mq/MqConsumer.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.mq; - -public interface MqConsumer { - - void consume(String topic, ConsumerHandler handler); - -} diff --git a/iot-common/iot-message-bus/iot-message-core/src/main/java/cc/iotkit/mq/MqProducer.java b/iot-common/iot-message-bus/iot-message-core/src/main/java/cc/iotkit/mq/MqProducer.java deleted file mode 100644 index f1e8bf46..00000000 --- a/iot-common/iot-message-bus/iot-message-core/src/main/java/cc/iotkit/mq/MqProducer.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.mq; - -public interface MqProducer { - - void publish(String topic, T msg); - -} diff --git a/iot-common/iot-message-bus/iot-message-event-bus/pom.xml b/iot-common/iot-message-bus/iot-message-event-bus/pom.xml deleted file mode 100644 index cf07d02f..00000000 --- a/iot-common/iot-message-bus/iot-message-event-bus/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - iot-message-bus - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-message-event-bus - - - - - cc.iotkit - iot-message-core - - - - cc.iotkit - iot-common-model - - - - - - org.springframework.boot - spring-boot-autoconfigure - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/BeanCodec.java b/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/BeanCodec.java deleted file mode 100644 index d436c43a..00000000 --- a/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/BeanCodec.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.vertx; - -import cc.iotkit.common.utils.JsonUtils; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.eventbus.MessageCodec; -import io.vertx.core.json.Json; - -public class BeanCodec implements MessageCodec { - - private final Class beanType; - - public BeanCodec(Class cls) { - beanType = cls; - } - - @Override - public void encodeToWire(Buffer buffer, T o) { - String json = Json.encode(o); - Buffer encoded = Buffer.buffer(json); - buffer.appendInt(encoded.length()); - buffer.appendBuffer(encoded); - } - - @Override - public T decodeFromWire(int pos, Buffer buffer) { - int length = buffer.getInt(pos); - pos += 4; - return Json.decodeValue(buffer.slice(pos, pos + length), beanType); - } - - @Override - public T transform(T o) { - return JsonUtils.parseObject(JsonUtils.toJsonString(o), beanType); - } - - @Override - public String name() { - return beanType.getSimpleName(); - } - - @Override - public byte systemCodecID() { - return -1; - } -} diff --git a/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/VertxManager.java b/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/VertxManager.java deleted file mode 100644 index ef13aa1c..00000000 --- a/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/VertxManager.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.vertx; - -import io.vertx.core.Vertx; - -public class VertxManager { - - private static final Vertx INSTANCE = Vertx.vertx(); - - public static Vertx getVertx() { - return INSTANCE; - } -} diff --git a/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/VertxMqConsumer.java b/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/VertxMqConsumer.java deleted file mode 100644 index eea4a04e..00000000 --- a/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/VertxMqConsumer.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.vertx; - -import cc.iotkit.mq.ConsumerHandler; -import cc.iotkit.mq.MqConsumer; -import io.vertx.core.AbstractVerticle; -import io.vertx.core.Handler; -import io.vertx.core.eventbus.EventBus; -import io.vertx.core.eventbus.Message; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; - -import java.util.concurrent.CountDownLatch; - -@Slf4j -public class VertxMqConsumer implements MqConsumer { - - private final MqConsumerVerticle consumerVerticle; - - private final CountDownLatch countDownLatch = new CountDownLatch(1); - - @SneakyThrows - public VertxMqConsumer(Class cls) { - consumerVerticle = new MqConsumerVerticle<>(cls); - VertxManager.getVertx().deployVerticle(consumerVerticle, stringAsyncResult -> countDownLatch.countDown()); - //等待初始化穿完成 - countDownLatch.await(); - } - - @Override - public void consume(String topic, ConsumerHandler handler) { - consumerVerticle.consume(topic, handler); - } - - public static class MqConsumerVerticle extends AbstractVerticle { - - private final Class cls; - private EventBus eventBus; - - public MqConsumerVerticle(Class cls) { - this.cls = cls; - } - - @Override - public void start() { - eventBus = vertx.eventBus(); - eventBus.registerCodec(new BeanCodec<>(cls)); - } - - public void consume(String topic, ConsumerHandler handler) { - eventBus.consumer(topic, (Handler>) msg -> handler.handler(msg.body())); - } - } - -} diff --git a/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/VertxMqProducer.java b/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/VertxMqProducer.java deleted file mode 100644 index 60e78cf1..00000000 --- a/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/VertxMqProducer.java +++ /dev/null @@ -1,51 +0,0 @@ -package cc.iotkit.vertx; - -import cc.iotkit.mq.MqProducer; -import io.vertx.core.AbstractVerticle; -import io.vertx.core.eventbus.DeliveryOptions; -import io.vertx.core.eventbus.EventBus; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; - -import java.util.concurrent.CountDownLatch; - -@Slf4j -public class VertxMqProducer implements MqProducer { - - private final MqProducerVerticle producerVerticle; - - private final CountDownLatch countDownLatch = new CountDownLatch(1); - - @SneakyThrows - public VertxMqProducer(Class cls) { - producerVerticle = new MqProducerVerticle<>(cls); - VertxManager.getVertx().deployVerticle(producerVerticle, stringAsyncResult -> countDownLatch.countDown()); - //等待初始化完成 - countDownLatch.await(); - } - - @Override - public void publish(String topic, T msg) { - producerVerticle.publish(topic, msg); - } - - public static class MqProducerVerticle extends AbstractVerticle { - - private final Class cls; - private EventBus eventBus; - - public MqProducerVerticle(Class cls) { - this.cls = cls; - } - - @Override - public void start() { - eventBus = vertx.eventBus(); - eventBus.registerCodec(new BeanCodec<>(cls)); - } - - public void publish(String topic, T msg) { - eventBus.publish(topic, msg, new DeliveryOptions().setCodecName(cls.getSimpleName())); - } - } -} diff --git a/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/config/VertxConfig.java b/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/config/VertxConfig.java deleted file mode 100644 index d19ebd18..00000000 --- a/iot-common/iot-message-bus/iot-message-event-bus/src/main/java/cc/iotkit/vertx/config/VertxConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -package cc.iotkit.vertx.config; - -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.mq.MqConsumer; -import cc.iotkit.mq.MqProducer; -import cc.iotkit.vertx.VertxMqConsumer; -import cc.iotkit.vertx.VertxMqProducer; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class VertxConfig { - - @ConditionalOnMissingBean - @Bean - public MqProducer getThingModelMessageProducer() { - return new VertxMqProducer<>(ThingModelMessage.class); - } - - @ConditionalOnMissingBean - @Bean - public MqConsumer getThingModelMessageConsumer() { - return new VertxMqConsumer<>(ThingModelMessage.class); - } - -} diff --git a/iot-common/iot-message-bus/iot-message-event-bus/src/test/java/test/MsgPubConsumeTest.java b/iot-common/iot-message-bus/iot-message-event-bus/src/test/java/test/MsgPubConsumeTest.java deleted file mode 100644 index 5aa3ad29..00000000 --- a/iot-common/iot-message-bus/iot-message-event-bus/src/test/java/test/MsgPubConsumeTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package test; - -import cc.iotkit.mq.ConsumerHandler; -import cc.iotkit.vertx.VertxMqConsumer; -import cc.iotkit.vertx.VertxMqProducer; -import io.vertx.core.AsyncResult; -import io.vertx.core.Handler; -import io.vertx.core.Vertx; - -public class MsgPubConsumeTest { - - - public static void main(String[] args) { - - Vertx vertx = Vertx.vertx(); - VertxMqConsumer.MqConsumerVerticle consumerVerticle = new VertxMqConsumer.MqConsumerVerticle<>(Bean1.class); - vertx.deployVerticle(consumerVerticle, new Handler>() { - @Override - public void handle(AsyncResult stringAsyncResult) { - consumerVerticle.consume("aaa", new ConsumerHandler() { - @Override - public void handler(Bean1 msg) { - System.out.println("c1:" + msg.getName()); - } - }); - consumerVerticle.consume("aaa", new ConsumerHandler() { - @Override - public void handler(Bean1 msg) { - System.out.println("c2:" + msg.getName()); - } - }); - } - }); - - - VertxMqProducer.MqProducerVerticle producerVerticle = new VertxMqProducer.MqProducerVerticle<>(Bean1.class); - vertx.deployVerticle(producerVerticle, new Handler>() { - @Override - public void handle(AsyncResult stringAsyncResult) { - producerVerticle.publish("aaa", new Bean1("test", 1)); - System.out.println("publish"); - } - }); - } - - public static class Bean1 { - private String name; - private int age; - - public Bean1() { - } - - public Bean1(String name, int age) { - this.name = name; - this.age = age; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - } - -} diff --git a/iot-common/iot-message-bus/iot-message-rocketmq/pom.xml b/iot-common/iot-message-bus/iot-message-rocketmq/pom.xml deleted file mode 100644 index 3ec66b61..00000000 --- a/iot-common/iot-message-bus/iot-message-rocketmq/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - iot-message-bus - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-message-rocketmq - - - - - cc.iotkit - iot-common-model - - - - cc.iotkit - iot-message-core - - - - - - org.springframework.boot - spring-boot-autoconfigure - - - - org.apache.rocketmq - rocketmq-client - 4.9.4 - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-message-bus/iot-message-rocketmq/readme.md b/iot-common/iot-message-bus/iot-message-rocketmq/readme.md deleted file mode 100644 index 8af19e71..00000000 --- a/iot-common/iot-message-bus/iot-message-rocketmq/readme.md +++ /dev/null @@ -1,11 +0,0 @@ -### 支持rocketMq作为消息总线 - -版本:0.4.2 - -rocketMq版本:4.9.4 - -####开启方式: - -1、application.yml中打开注释支持rocketMq作为消息总线 - -2、pom.xml中打开注释使用rocketmq消息总线 diff --git a/iot-common/iot-message-bus/iot-message-rocketmq/src/main/java/cc/iotkit/rocketmq/RocketMqConsumer.java b/iot-common/iot-message-bus/iot-message-rocketmq/src/main/java/cc/iotkit/rocketmq/RocketMqConsumer.java deleted file mode 100644 index d95f685e..00000000 --- a/iot-common/iot-message-bus/iot-message-rocketmq/src/main/java/cc/iotkit/rocketmq/RocketMqConsumer.java +++ /dev/null @@ -1,46 +0,0 @@ -package cc.iotkit.rocketmq; - -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.mq.ConsumerHandler; -import cc.iotkit.mq.MqConsumer; -import lombok.extern.slf4j.Slf4j; -import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; -import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; -import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; -import org.apache.rocketmq.common.message.MessageExt; - -import java.nio.charset.StandardCharsets; - -@Slf4j -public class RocketMqConsumer implements MqConsumer { - - private String nameServer; - - private final Class msgType; - - public RocketMqConsumer(String nameServer, Class cls) { - this.nameServer = nameServer; - this.msgType = cls; - } - - @Override - public void consume(String topic, ConsumerHandler handler) { - try { - DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(handler.getClass() - .getName().replace(".", "")); - consumer.setNamesrvAddr(nameServer); - consumer.subscribe(topic, "*"); - consumer.registerMessageListener((MessageListenerConcurrently) (messages, context) -> { - for (MessageExt message : messages) { - T msg = JsonUtils.parseObject(new String(message.getBody(), StandardCharsets.UTF_8), msgType); - handler.handler(msg); - } - return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; - }); - consumer.start(); - } catch (Throwable e) { - log.error("consume error", e); - } - } - -} diff --git a/iot-common/iot-message-bus/iot-message-rocketmq/src/main/java/cc/iotkit/rocketmq/RocketMqProducer.java b/iot-common/iot-message-bus/iot-message-rocketmq/src/main/java/cc/iotkit/rocketmq/RocketMqProducer.java deleted file mode 100644 index d9a91174..00000000 --- a/iot-common/iot-message-bus/iot-message-rocketmq/src/main/java/cc/iotkit/rocketmq/RocketMqProducer.java +++ /dev/null @@ -1,36 +0,0 @@ -package cc.iotkit.rocketmq; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.mq.MqProducer; -import org.apache.rocketmq.client.producer.DefaultMQProducer; -import org.apache.rocketmq.common.message.Message; - -import java.nio.charset.StandardCharsets; - -public class RocketMqProducer implements MqProducer { - - private final DefaultMQProducer producer; - - public RocketMqProducer(String nameServer, String group) { - try { - producer = new DefaultMQProducer(group); - producer.setNamesrvAddr(nameServer); - producer.start(); - } catch (Throwable e) { - throw new BizException(ErrCode.INIT_PRODUCER_ERROR, e); - } - } - - @Override - public void publish(String topic, T msg) { - try { - producer.send(new Message(topic, - JsonUtils.toJsonString(msg).getBytes(StandardCharsets.UTF_8))); - } catch (Throwable e) { - throw new BizException(ErrCode.SEND_MSG_ERROR, e); - } - } - -} diff --git a/iot-common/iot-message-bus/iot-message-rocketmq/src/main/java/cc/iotkit/rocketmq/config/RocketMqConfig.java b/iot-common/iot-message-bus/iot-message-rocketmq/src/main/java/cc/iotkit/rocketmq/config/RocketMqConfig.java deleted file mode 100644 index 1386675c..00000000 --- a/iot-common/iot-message-bus/iot-message-rocketmq/src/main/java/cc/iotkit/rocketmq/config/RocketMqConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -package cc.iotkit.rocketmq.config; - -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.mq.MqConsumer; -import cc.iotkit.mq.MqProducer; -import cc.iotkit.rocketmq.RocketMqConsumer; -import cc.iotkit.rocketmq.RocketMqProducer; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class RocketMqConfig { - - @Value("${rocketmq.name-server}") - private String nameServer; - - @Value("${rocketmq.producer.group}") - private String group; - - @ConditionalOnMissingBean - @Bean - public MqProducer getThingModelMessageProducer() { - return new RocketMqProducer<>(nameServer, group); - } - - @ConditionalOnMissingBean - @Bean - public MqConsumer getThingModelMessageConsumer() { - return new RocketMqConsumer<>(nameServer, ThingModelMessage.class); - } - - -} diff --git a/iot-common/iot-message-bus/pom.xml b/iot-common/iot-message-bus/pom.xml deleted file mode 100644 index d6ed6c3b..00000000 --- a/iot-common/iot-message-bus/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - pom - - 消息队列适配模块,用于提供默认消息队列和适配不同消息队列接入 - - - iot-message-bus - - - iot-message-core - iot-message-event-bus - iot-message-rocketmq - - - - - - cc.iotkit - iot-common-core - - - - - - org.projectlombok - lombok - - - org.slf4j - slf4j-api - - - - io.vertx - vertx-core - - - - - diff --git a/iot-common/iot-script-engine/pom.xml b/iot-common/iot-script-engine/pom.xml deleted file mode 100644 index 635b6ddb..00000000 --- a/iot-common/iot-script-engine/pom.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - 4.0.0 - - iot-common - cc.iotkit - 0.5.0-SNAPSHOT - - - iot-script-engine - - - - 此模块为脚本引擎 - - - - - 11 - 11 - UTF-8 - - - - - - cc.iotkit - iot-common-core - - - - - - - org.graalvm.sdk - graal-sdk - - - - org.graalvm.js - js - - - - org.graalvm.js - js-scriptengine - - - - org.apache.commons - commons-lang3 - - - - org.slf4j - slf4j-api - - - - org.projectlombok - lombok - - - - commons-beanutils - commons-beanutils - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/IScriptEngine.java b/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/IScriptEngine.java deleted file mode 100644 index 5161bbe1..00000000 --- a/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/IScriptEngine.java +++ /dev/null @@ -1,15 +0,0 @@ -package cc.iotkit.script; - -import com.fasterxml.jackson.core.type.TypeReference; - -public interface IScriptEngine { - - void setScript(String key); - - void putScriptEnv(String key, Object val); - - void invokeMethod(String methodName, Object... args); - - T invokeMethod(TypeReference type, String methodName, Object... args); - -} diff --git a/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/JavaScriptEngine.java b/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/JavaScriptEngine.java deleted file mode 100644 index fb46365c..00000000 --- a/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/JavaScriptEngine.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.script; - - -import cc.iotkit.common.utils.JsonUtils; -import com.fasterxml.jackson.core.type.TypeReference; -import lombok.extern.slf4j.Slf4j; -import org.graalvm.polyglot.Context; -import org.graalvm.polyglot.HostAccess; -import org.graalvm.polyglot.Value; - -/** - * @author sjg - */ -@Slf4j -public class JavaScriptEngine implements IScriptEngine { - - private final Context context = Context.newBuilder("js").allowHostAccess(HostAccess.ALL).build(); - - private Value jsScript; - - @Override - public void setScript(String script) { - jsScript = context.eval("js", String.format( - "new (function () {\n%s; " + - " this.invoke=function(f,args){" + - " for(i in args){" + - " args[i]=JSON.parse(args[i]);" + - " }" + - " return JSON.stringify(this[f].apply(this,args));" + - " }; " + - "})()", script)); - } - - @Override - public void putScriptEnv(String key, Object value) { - context.getBindings("js").putMember(key, value); - } - - @Override - public void invokeMethod(String methodName, Object... args) { - invokeMethod(new TypeReference() { - }, methodName, args); - } - - @Override - public T invokeMethod(TypeReference type, String methodName, Object... args) { - Value member = jsScript.getMember("invoke"); - - StringBuilder sbArgs = new StringBuilder("["); - //将入参转成json - for (int i = 0; i < args.length; i++) { - args[i] = JsonUtils.toJsonString(args[i]); - sbArgs.append(i == args.length - 1 ? "," : "").append(args[i]); - } - sbArgs.append("]"); - - //通过调用invoke方法将目标方法返回结果转成json - Value rst = member.execute(methodName, args); - - String json = rst.asString(); - log.info("invoke script {},args:{}, result:{}", methodName, sbArgs, json); - - //没有返回值 - if (json == null || "null".equals(json)) { - return null; - } - - return JsonUtils.parseObject(json, type); - } - -} \ No newline at end of file diff --git a/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/ScriptEngineFactory.java b/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/ScriptEngineFactory.java deleted file mode 100644 index 0aa63751..00000000 --- a/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/ScriptEngineFactory.java +++ /dev/null @@ -1,46 +0,0 @@ -package cc.iotkit.script; - - -import com.fasterxml.jackson.core.type.TypeReference; - -/** - * @author sjg - */ -public class ScriptEngineFactory { - - public static IScriptEngine getScriptEngine(String type) { - if (type == null) { - type = "js"; - } - switch (type) { - case "python": - case "lua": - return new IScriptEngine() { - - @Override - public void setScript(String key) { - - } - - @Override - public void putScriptEnv(String key, Object val) { - - } - - @Override - public void invokeMethod(String methodName, Object... args) { - - } - - @Override - public T invokeMethod(TypeReference type, String methodName, Object... args) { - return null; - } - }; - case "js": - default: - return new JavaScriptEngine(); - } - } - -} diff --git a/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/ScriptException.java b/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/ScriptException.java deleted file mode 100644 index 86e17a69..00000000 --- a/iot-common/iot-script-engine/src/main/java/cc/iotkit/script/ScriptException.java +++ /dev/null @@ -1,7 +0,0 @@ -package cc.iotkit.script; - -public class ScriptException extends Exception{ - public ScriptException(String message) { - super(message); - } -} diff --git a/iot-common/pom.xml b/iot-common/pom.xml deleted file mode 100644 index 8caeac4b..00000000 --- a/iot-common/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - 4.0.0 - - iotkit-parent - cc.iotkit - 0.5.0-SNAPSHOT - - 0.5.0-SNAPSHOT - pom - - iot-common - - 技术组件,也分成两类: - 1. 框架组件:脚本引擎、通讯总线等等的拓展 - 2. 业务组件:物模型、鉴权、工具 - - - - iot-common-core - iot-common-dao - iot-script-engine - iot-message-bus - iot-common-doc - iot-common-excel - iot-common-log - iot-common-oss - iot-common-redis - iot-common-satoken - iot-common-tenant - iot-common-web - iot-common-websocket - - - - UTF-8 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-components/.DS_Store b/iot-components/.DS_Store deleted file mode 100755 index e86ca519..00000000 Binary files a/iot-components/.DS_Store and /dev/null differ diff --git a/iot-components/iot-DLT645-component/pom.xml b/iot-components/iot-DLT645-component/pom.xml deleted file mode 100644 index 39d57c17..00000000 --- a/iot-components/iot-DLT645-component/pom.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - iot-components - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-DLT645-component - - - - - cc.iotkit - iot-component-base - - - - cc.iotkit - iot-common-core - - - - - - org.projectlombok - lombok - - - - io.vertx - vertx-web-proxy - - - - cn.hutool - hutool-core - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - - io.vertx:vertx-web-proxy - io.vertx:vertx-web - io.vertx:vertx-bridge-common - io.vertx:vertx-http-proxy - io.vertx:vertx-core - io.netty:netty-codec-http2 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 11 - 11 - utf8 - - - - - - diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/DLT645Component.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/DLT645Component.java deleted file mode 100644 index d9045caf..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/DLT645Component.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.DLT645; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.AbstractDeviceComponent; -import cc.iotkit.comp.CompConfig; -import cc.iotkit.converter.DeviceMessage; -import io.vertx.core.Future; -import io.vertx.core.Vertx; -import lombok.Data; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; - -import java.util.UUID; -import java.util.concurrent.CountDownLatch; - -@Data -@Slf4j -public class DLT645Component extends AbstractDeviceComponent { - - private Vertx vertx; - - private CountDownLatch countDownLatch; - - private DLT645Verticle DLT645Verticle; - - private String deployedId; - - private String id; - - @Override - public void create(CompConfig config) { - super.create(config); - vertx = Vertx.vertx(); - this.id = UUID.randomUUID().toString(); - DLT645Config DLT645Config = JsonUtils.parseObject(config.getOther(), DLT645Config.class); - DLT645Verticle = new DLT645Verticle(DLT645Config); - } - - @Override - public void start() { - try { - DLT645Verticle.setExecutor(getHandler()); - countDownLatch = new CountDownLatch(1); - Future future = vertx.deployVerticle(DLT645Verticle); - future.onSuccess((s -> { - deployedId = s; - countDownLatch.countDown(); - })); - future.onFailure(e -> { - countDownLatch.countDown(); - log.error("start GLT645 component failed", e); - }); - countDownLatch.await(); - future.succeeded(); - } catch (Throwable e) { - throw new BizException(ErrCode.COMPONENT_START_ERROR, e); - } - } - - @Override - @SneakyThrows - public void stop() { - DLT645Verticle.stop(); - Future future = vertx.undeploy(deployedId); - future.onSuccess(unused -> log.info("stop GLT645 component success")); - } - - @Override - public void destroy() { - } - - - @Override - public DeviceMessage send(DeviceMessage message) { - DLT645Verticle.sendMsg(message); - return message; - } -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/DLT645Config.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/DLT645Config.java deleted file mode 100644 index 20c74e03..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/DLT645Config.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.DLT645; - -import lombok.Data; - -@Data -public class DLT645Config { - - private int port; - -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/DLT645Verticle.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/DLT645Verticle.java deleted file mode 100644 index 90f81dc2..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/DLT645Verticle.java +++ /dev/null @@ -1,184 +0,0 @@ -package cc.iotkit.comp.DLT645; - - -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.DLT645.analysis.*; -import cc.iotkit.comp.DLT645.utils.ByteUtils; -import cc.iotkit.comp.DLT645.utils.ContainerUtils; -import cc.iotkit.comp.IMessageHandler; -import cc.iotkit.comp.model.ReceiveResult; -import cc.iotkit.converter.DeviceMessage; -import io.vertx.core.AbstractVerticle; -import io.vertx.core.Future; -import io.vertx.core.net.NetServer; -import io.vertx.core.net.NetServerOptions; -import io.vertx.core.net.NetSocket; -import lombok.extern.slf4j.Slf4j; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicReference; - -/** - * @author tfd - * @date 2023-04-07 - */ -@Slf4j -public class DLT645Verticle extends AbstractVerticle { - - private IMessageHandler executor; - - private final DLT645Config config; - - private Map clientMap = new ConcurrentHashMap(); - - private NetServer netServer ; - - public DLT645Verticle(DLT645Config config) { - this.config = config; - } - - public void setExecutor(IMessageHandler executor) { - this.executor = executor; - } - - private List entityList; - - private Map dinMap; - - /** - * DL/T 645-1997 自定义协议-67开头,DLT645-68开头 - * 注册上行:67+动作标识2B(注册:7267、心跳:6862)+设备唯一值6B - * 注册下行:67+动作标识2B(注册:7267、心跳:6862)+状态码1B(00:成功、99:失败) - * 心跳上行:67+动作标识2B(注册:7267、心跳:6862) - * 心跳下行:67+动作标识2B(注册:7267、心跳:6862)+00 - */ - @Override - public void start() { - NetServerOptions options=new NetServerOptions().setPort(config.getPort()); - netServer=vertx.createNetServer(options); - netServer.connectHandler(socket -> { - log.info("TCP client connect address:{}", socket.remoteAddress()); - AtomicReference clientKey = new AtomicReference<>(); - Map dataMap= new HashMap<>(); - // 设置连接超时时间 - long timeoutId = vertx.setTimer(10000, id -> { - socket.close(); - }); - // 处理连接 - socket.handler(data -> { - String hexStr=ByteUtils.byteArrayToHexString(data.getBytes(),false); - log.info("Received message:{}", hexStr); - if(hexStr.startsWith("67")){//67打头为网关自定义协议 - String funCode=hexStr.substring(2,6); - log.info("收到自定义消息,行为码为:" + funCode + ",数据为:" + hexStr); - if("7267".equals(funCode)){ - String mac=hexStr.substring(6,18); - dataMap.put("mac",mac); - executor.onReceive(dataMap, "register", "",r ->{ - if(r!=null){ - //注册成功 - clientKey.set(getClientKey(r)); - if(!clientMap.containsKey(clientKey.get())){ - clientMap.put(clientKey.get(),socket); - } - vertx.cancelTimer(timeoutId); - executor.onReceive(dataMap, "online", ""); - socket.write(hexStr+"00"); - return; - } - socket.write(hexStr+"99"); - return; - }); - }else if("6862".equals(funCode)){//心跳 - socket.write(hexStr+"00"); - return; - } - }else{//其他为电表协议 - Map result = DLT645Analysis.unPackCmd2Map(ByteUtils.hexStringToByteArray(hexStr)); - //获取功能码 - Object func = result.get(DLT645Analysis.FUN); - DLT645FunCode funCode = DLT645FunCode.decodeEntity((byte) func); - if(funCode.isError()){ - log.error("message erroe:{}", hexStr); - return; - } - //获取设备地址 - byte[] adrrTmp = (byte[]) result.get(DLT645Analysis.ADR); - byte[] addr = new byte[6]; - ByteUtils.byteInvertedOrder(adrrTmp,addr); - //获取数据 - byte[] dat = (byte[]) result.get(DLT645Analysis.DAT); - DLT645V1997Data dataEntity = new DLT645V1997Data(); - dataEntity.decodeValue(dat, dinMap); - Map unPack = new HashMap<>(); - unPack.put("deviceAddress",ByteUtils.byteArrayToHexString(addr,false)); - unPack.put("funCode",funCode.getCode()); - unPack.put("identify",dataEntity.getKey());//数据标识 - unPack.put("data",dataEntity.getValue()+dataEntity.getUnit());//数据+单位 - executor.onReceive(new HashMap<>(), "dlt", JsonUtils.toJsonString(unPack)); - } - }); - socket.closeHandler(res->{ - log.warn("TCP connection closed!"); - if(clientMap.containsKey(clientKey.get())){ - executor.onReceive(dataMap, "offline", ""); - clientMap.remove(clientKey.get()); - } - }); - socket.exceptionHandler(res->{ - log.warn("TCP connection exception!"); - if(clientMap.containsKey(clientKey)){ - executor.onReceive(dataMap, "offline", ""); - clientMap.remove(clientKey.get()); - } - }); - }); - netServer.listen(res -> { - if (res.succeeded()) { - log.info("TCP server start success!"); - DLT645v1997CsvLoader template = new DLT645v1997CsvLoader(); - entityList = template.loadCsvFile(); - dinMap = ContainerUtils.buildMapByKey(entityList, DLT645V1997Data::getKey); - } else { - log.error("TCP server start fail: " + res.cause()); - } - }); - } - - @Override - public void stop() { - for (String clientKey : clientMap.keySet()) { - Map dataMap=new HashMap<>(); - dataMap.put("mac",clientKey.split("_")[1]); - executor.onReceive(dataMap, "offline", ""); - } - if (!entityList.isEmpty()) { - entityList.clear(); - } - if (!dinMap.isEmpty()) { - dinMap.clear(); - } - clientMap.clear(); - netServer.close(voidAsyncResult -> log.info("close tcp server...")); - } - - private String getClientKey(ReceiveResult result) { - return getClientKey(result.getProductKey(), result.getDeviceName()); - } - - private String getClientKey(String productKey, String deviceName) { - return String.format("%s_%s", productKey, deviceName); - } - - public DeviceMessage sendMsg(DeviceMessage msg) { - NetSocket client = clientMap.get(getClientKey(msg.getProductKey(),msg.getDeviceName())); - log.info("send msg payload:{}", msg.getContent().toString()); - Future result = client.write(msg.getContent().toString()); - result.onFailure(e -> log.error("DLT645 server send msg failed", e)); - return msg; - } - -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Analysis.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Analysis.java deleted file mode 100644 index c70db45e..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Analysis.java +++ /dev/null @@ -1,310 +0,0 @@ -package cc.iotkit.comp.DLT645.analysis; - -import cc.iotkit.comp.DLT645.utils.ByteRef; -import cc.iotkit.comp.DLT645.utils.BytesRef; -import cc.iotkit.comp.DLT645.utils.ContainerUtils; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * DL/T 645-1997 通讯规约通信规约 - * 帧起始符 地址域 帧起始符 控制码 数据长度域 数据域 校验码 结束符 - * 1 6 1 1 1 N 1 1 - */ -public class DLT645Analysis { - /** - * 静态实例 - */ - private static final DLT645Analysis DLT645Analysis = new DLT645Analysis(); - - public static DLT645Analysis inst() { - return DLT645Analysis; - } - /** - * 设备地址:4字节的byte[] - */ - public static final String ADR = "ADR"; - /** - * 功能码:1字节的byte - */ - public static final String FUN = "FUN"; - /** - * 数据报:不定长的byte[] - */ - public static final String DAT = "DAT"; - - /** - * 索引表 - */ - private Map name2entity; - private Map din2entity; - - - /** - * 验证码 - * - * @param arrCmd - * @param iOffSet - * @return - */ - private static int GetVfy(byte[] arrCmd, int iOffSet) { - int iSize = arrCmd.length - 2 - iOffSet; - if (iSize < 0) { - return 0; - } - - int bySum = 0x00; - - int index = iOffSet; - for (int i = 0; i < iSize; i++) { - bySum += arrCmd[index++]; - bySum &= 0xff; - } - - return bySum & 0xff; - } - - /** - * 打包 - * - * @param arrAddr 6字节的地址码 - * @param byCmd 命令字 - * @param arrData 数据段 - * @return 是否成功 - */ - public static byte[] packCmd(byte[] arrAddr, byte byCmd, byte[] arrData) { - // 检查:数据块的大小 - int iDataSize = arrData.length; - if (iDataSize > 255) { - return new byte[0]; - } - if (arrAddr.length != 6) { - return new byte[0]; - } - - // 初始化数组大小 - byte[] arrCmd = new byte[iDataSize + 13]; - - - int index = 0; - - - // 前导字符(在发送帧信息之前,先发送1个或多个字节FEH,以唤醒接收方) - arrCmd[index++] = (byte) 0xFE; - - // 帧起始符 - arrCmd[index++] = (byte) 0x68; - - // 地址码 - System.arraycopy(arrAddr, 0, arrCmd, index, arrAddr.length); - index += arrAddr.length; - - // 帧起始符 - arrCmd[index++] = (byte) 0x68; - - // 控制码 - arrCmd[index++] = byCmd; - - // 帧长度 - arrCmd[index++] = (byte) iDataSize; - - // 数据域 - System.arraycopy(arrData, 0, arrCmd, index, iDataSize); - // 每个字节加上0x33 - for (int i = 0; i < arrData.length; i++) { - arrCmd[index + i] = (byte) ((arrCmd[index + i] & 0xff) + 0x33); - } - index += iDataSize; - - - // 校验码 - arrCmd[index++] = (byte) GetVfy(arrCmd, 1); - - // 结束符 - arrCmd[index++] = 0x16; - - return arrCmd; - } - - /** - * 默认打包 - * - * @param byCmd - * @param arrData - * @return - */ - public static byte[] packCmd(byte byCmd, byte[] arrData) { - byte[] arrAddr = new byte[6]; - - arrAddr[0] = 0x01; - arrAddr[1] = 0x00; - arrAddr[2] = 0x00; - arrAddr[3] = 0x00; - arrAddr[4] = 0x00; - arrAddr[5] = 0x00; - - return packCmd(arrAddr, byCmd, arrData); - } - - /** - * 解包 - * - * @param arrCmd 报文,前面有不确定的唤醒字符 - * @param arrAddrRef 地址码 - * @param byCmd 命令字 - * @param arrDataRef 数据 - * @return 是否成功 - */ - private static boolean unPackCmd2Map(byte[] arrCmd, BytesRef arrAddrRef, ByteRef byCmd, BytesRef arrDataRef) { - int iSize = arrCmd.length; - - // 查找偏移量:DLT645电表前面会被塞入不定长的乱码数据,被用来激活电表,直到0x68字符出现 - int iOffSet = 0; - int index = 0; - for (iOffSet = 0; iOffSet < iSize; iOffSet++) { - if ((arrCmd[index++] & 0xff) == 0x68) { - break; - } - } - if (iOffSet == iSize) { - return false; - } - - // 检查:数据包大小 - if (iSize < 12 + iOffSet) { - return false; - } - -//============================================================================== -// 中国电力总局的DL/T 645-1997 多功能电能表通信规约 -// 引导码 起始符 地址码 起始符 功能码 帧长度 数据域 校验和 结束符 -// N 1 6 1 1 1 N 1 1 -//============================================================================== - - // 检查:起始符1 - if (arrCmd[iOffSet + 0] != 0x68) { - return false; - } - // 检查:起始符2 - if (arrCmd[iOffSet + 7] != 0x68) { - return false; - } - // 检查:结束符 - if (arrCmd[iSize - 1] != 0x16) { - return false; - } - - // 地址码 - byte[] arrAddr = new byte[6]; - System.arraycopy(arrCmd, iOffSet + 1, arrAddr, 0, 6); - arrAddrRef.setValue(arrAddr); - - - // 功能码 - byCmd.setValue(arrCmd[iOffSet + 8]); - - - // 检查:帧长度 - int iDataSize = arrCmd[iOffSet + 9]; - if ((iDataSize + 12 + iOffSet) != iSize) { - return false; - } - - // 数据域 - byte[] arrData = new byte[iDataSize]; - System.arraycopy(arrCmd, iOffSet + 10, arrData, 0, iDataSize); - // 每个字节先减去0x33 - for (int i = 0; i < arrData.length; i++) { - arrData[i] = (byte) ((arrData[i] & 0xff) - 0x33); - } - arrDataRef.setValue(arrData); - - - // 检查:校验码 - byte byVfyOK = (byte) (GetVfy(arrCmd, iOffSet) & 0xff); - return byVfyOK == arrCmd[iSize - 2]; - } - - public static boolean unPackCmd2Map(byte[] arrCmd, ByteRef byCmd, BytesRef arrData) { - BytesRef arrAddr = new BytesRef(); - return unPackCmd2Map(arrCmd, arrAddr, byCmd, arrData); - } - - /** - * 只有数据标识的DI0和DI1的请求命令 - * - * @param DI0 数据标识 - * @param DI1 数据标识 - * @return - */ - public static byte[] packCmdGetData(int DI0, int DI1) { - byte[] arrData = new byte[2]; - arrData[0] = (byte) DI0; - arrData[1] = (byte) DI1; - - return packCmd((byte) 0x01, arrData); - } - - public static boolean unPackCmdGetData(byte[] arrCmd, BytesRef arrData) { - ByteRef byCmd = new ByteRef(); - if (!unPackCmd2Map(arrCmd, byCmd, arrData)) { - return false; - } - - return byCmd.getValue() == 0x81; - } - - /** - * 包装成另一种格式 - * - * @param arrCmd - * @return - */ - public static Map unPackCmd2Map(byte[] arrCmd) { - ByteRef byFun = new ByteRef(); - BytesRef byAddr = new BytesRef(); - BytesRef arrData = new BytesRef(); - if (!unPackCmd2Map(arrCmd, byAddr, byFun, arrData)) { - return Collections.emptyMap(); - } - - Map value = new HashMap<>(); - value.put(ADR, byAddr.getValue()); - value.put(FUN, byFun.getValue()); - value.put(DAT, arrData.getValue()); - return value; - } - - /** - * 获得对象信息 - * - * @return 对象副本 - */ - public synchronized Map getTemplateByName() { - if (this.name2entity == null) { - DLT645v1997CsvLoader loader = new DLT645v1997CsvLoader(); - List entityList = loader.loadCsvFile(); - Map nameMap = ContainerUtils.buildMapByKey(entityList, DLT645V1997Data::getName); - this.name2entity = new ConcurrentHashMap<>(); - this.name2entity.putAll(nameMap); - } - - return this.name2entity; - } - - public synchronized Map getTemplateByDIn() { - if (this.din2entity == null) { - DLT645v1997CsvLoader loader = new DLT645v1997CsvLoader(); - List entityList = loader.loadCsvFile(); - Map keyMap = ContainerUtils.buildMapByKey(entityList, DLT645V1997Data::getKey); - this.din2entity = new ConcurrentHashMap<>(); - this.din2entity.putAll(keyMap); - } - - return this.din2entity; - } -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Converter.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Converter.java deleted file mode 100644 index 53fbba00..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Converter.java +++ /dev/null @@ -1,105 +0,0 @@ -package cc.iotkit.comp.DLT645.analysis; - -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.common.utils.UniqueIdUtil; -import cc.iotkit.comp.DLT645.utils.ByteUtils; -import cc.iotkit.converter.Device; -import cc.iotkit.converter.DeviceMessage; -import cc.iotkit.converter.IConverter; -import cc.iotkit.model.device.message.ThingModelMessage; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; - -import java.util.Map; - -@Slf4j -@Data -public class DLT645Converter implements IConverter { - @Override - public void setScript(String script) { - - } - - /** - * 编码 - * @param msg - * @return - */ - @Override - public ThingModelMessage decode(DeviceMessage msg) { - ThingModelMessage tmm = null; - ReportData rd=JsonUtils.parseObject(JsonUtils.toJsonString(msg.getContent()),ReportData.class); - if(ThingModelMessage.TYPE_PROPERTY.equals(rd.type)&&"report".equals(rd.getIdentifier())){ - tmm=ThingModelMessage.builder() - .mid(msg.getMid()) - .productKey(msg.getProductKey()) - .deviceName(msg.getDeviceName()) - .identifier(rd.getIdentifier()) - .occurred(rd.getOccur()) - .time(rd.getTime()) - .type(rd.getType()) - .data(rd.getData()) - .build(); - } - return tmm; - } - /** - * 解码 - * @param service,device - * @return - */ - @Override - public DeviceMessage encode(ThingService service, Device device) { - DeviceMessage deviceMsg=new DeviceMessage(); - deviceMsg.setProductKey(service.getProductKey()); - deviceMsg.setDeviceName(service.getDeviceName()); - deviceMsg.setMid(UniqueIdUtil.newRequestId()); - Map sd = (Map) service.getParams(); - String funCode=""; - if(ThingService.TYPE_SERVICE.equals(service.getType())){//服务相关 - if("readData".equals(service.getIdentifier())){//读数据 - funCode=DLT645FunCode.func_v97_00001; - }else if("writeData".equals(service.getIdentifier())){//写数据 - funCode=DLT645FunCode.func_v97_00100; - } - //...其他功能码 - } - deviceMsg.setContent(packData(sd.get("deviceAddr"),funCode,sd.get("dataIdentifier"))); - return deviceMsg; - } - - @Override - public void putScriptEnv(String key, Object value) { - - } - - private String packData(String deviceAddress,String funCode,String dataIdentifier){ - // 对设备地址进行编码 - byte[] tmp = ByteUtils.hexStringToByteArray(deviceAddress); - byte[] adrr = new byte[6]; - ByteUtils.byteInvertedOrder(tmp,adrr); - - // 根据对象名获取对象格式信息,这个格式信息,记录在CSV文件中 - DLT645Data dataEntity = DLT645Analysis.inst().getTemplateByDIn().get(dataIdentifier); - if (dataEntity == null) { - throw new BizException("CSV模板文件中未定义对象:" + dataIdentifier + " ,你需要在模板中添加该对象信息"); - } - byte byFun = Byte.decode(String.valueOf(DLT645FunCode.getCodev1997(funCode))); - - // 使用DLT645协议框架编码 - byte[] pack = DLT645Analysis.packCmd(adrr,byFun,dataEntity.getDIn()); - - // 将报文按要求的16进制格式的String对象返回 - return ByteUtils.byteArrayToHexString(pack,false); - } - @Data - public static class ReportData{ - private String type; - private String identifier; - private Long occur; - private Long time; - private Object data; - } -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Data.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Data.java deleted file mode 100644 index 6d2843ed..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645Data.java +++ /dev/null @@ -1,87 +0,0 @@ -package cc.iotkit.comp.DLT645.analysis; - -import cc.iotkit.common.exception.BizException; -import lombok.Data; - -import java.util.Map; - -@Data -public abstract class DLT645Data { - /** - * 名称 - */ - private String name; - /** - * 格式 - */ - private DLT645DataFormat format = new DLT645DataFormat(); - /** - * 长度 - */ - private int length; - /** - * 单位 - */ - private String unit; - /** - * 可读 - */ - private boolean read; - /** - * 可写 - */ - private boolean write; - /** - * 数值 - */ - private Object value = 0.0; - - /** - * 数值 - */ - private Object value2nd; - - public abstract String getKey(); - - public abstract byte[] getDIn(); - - public abstract void setDIn(byte[] value); - - public abstract int getDInLen(); - - public String toString() { - if (this.value2nd == null) { - return this.name + ":" + this.value + this.unit; - } - - return this.name + ":" + this.value + this.unit + " " + this.value2nd; - } - - public void decodeValue(byte[] data, Map dinMap) { - - // DI值 - this.setDIn(data); - - // 获取字典信息 - DLT645Data dict = dinMap.get(this.getKey()); - if (dict == null) { - throw new BizException("DIn info err,please configure:" + this.getKey()); - } - - this.format = dict.format; - this.name = dict.name; - this.read = dict.read; - this.write = dict.write; - this.length = dict.length; - this.unit = dict.unit; - - - // 基本值 - this.value = this.format.decodeValue(data, this.format.getFormat(), this.getDInLen(), this.format.getLength()); - - // 组合值 - if (this.format.getFormat2nd() != null && !this.format.getFormat2nd().isEmpty()) { - this.value2nd = this.format.decodeValue(data, this.format.getFormat2nd(), this.getDInLen() + this.format.getLength(), this.format.getLength2nd()); - } - } -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645DataFormat.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645DataFormat.java deleted file mode 100644 index 02df7cd0..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645DataFormat.java +++ /dev/null @@ -1,357 +0,0 @@ -package cc.iotkit.comp.DLT645.analysis; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.comp.DLT645.utils.ByteUtils; -import lombok.Data; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Data -public class DLT645DataFormat { - // 数值格式 - public static final String FORMAT_X = "X"; - public static final String FORMAT_N = "N"; - - // 时间格式 - public static final String FORMAT_YYMMDDWW = "YYMMDDWW"; - public static final String FORMAT_hhmmss = "hhmmss"; - public static final String FORMAT_YYMMDDhhmm = "YYMMDDhhmm"; - public static final String FORMAT_MMDDhhmm = "MMDDhhmm"; - public static final String FORMAT_DDhh = "DDhh"; - public static final String FORMAT_hhmm = "hhmm"; - public static final String FORMAT_mmmm = "mmmm"; - - // 编码格式 - public static final String FORMAT_NN___NN = "NN...NN"; - public static final String FORMAT_XX___XX = "XX...XX"; - - // 状态格式 - public static final String FORMAT_STATUS_WEEK = "周休日状态字"; - public static final String FORMAT_STATUS_METER = "电表运行状态字"; - public static final String FORMAT_STATUS_NETWORK = "电网状态字"; - - - /** - * 格式类型 - */ - private String format = ""; - /** - * 组合格式:第二个格式 - */ - private String format2nd = ""; - /** - * 长度 - */ - private int length = 0; - /** - * 组合格式:第二个长度 - */ - private int length2nd = 0; - /** - * 缩小比例 - */ - private double ratio = 1.0; - - public Object decodeValue(byte[] data, String format, int start, int length) throws RuntimeException { - // 前面4个字节是DI0~DI3 - if (data.length < length + start) { - throw new BizException(ErrCode.DATA_LENGTH_ERROR); - } - - // 各种XX.XX格式 - if (format.equals(FORMAT_X)) { - return this.getValue(data, start, length, this.ratio); - } - // 各种NN.NN格式 - if (format.equals(FORMAT_N)) { - return this.getValue(data, start, length, this.ratio); - } - if (format.equals(FORMAT_NN___NN)) { - return this.getString(data, start, length); - } - - // 时间格式 - if (format.equals(FORMAT_hhmm) || format.equals(FORMAT_DDhh) || format.equals(FORMAT_YYMMDDWW) || format.equals(FORMAT_hhmmss) || format.equals(FORMAT_YYMMDDhhmm) || format.equals(FORMAT_MMDDhhmm)) { - return this.getDataTime(data, format, start, length); - } - - - if (format.equals(FORMAT_XX___XX)) { - this.format = FORMAT_XX___XX; - this.ratio = 1.0; - return true; - } - - - return false; - } - - /** - * 解码格式:固定长度格式和可变长度格式 - * 固定长度格式:根据XX.XX它格式本身长度进行判定 - * - * @param format 格式名称 - * @param length 可变格式的长度 - * @return 是否成功 - */ - public boolean decodeFormat(String format, int length) { - // 统计字符种类的数量 - Map charCount = charCount(format); - - // 组合格式:XX.XXXX|YYMMDDhhmm - if (charCount.containsKey('|') && charCount.get('|').equals(1)) { - String format1 = format.substring(0, format.indexOf("|")); - String format2 = format.substring(format.indexOf("|") + 1); - this.decodeFormat(format2, -1); - this.format2nd = this.format; - this.length2nd = this.length; - this.decodeFormat(format1, -1); - return true; - } - - // 各种XX.XX格式 - if (charCount.containsKey('X') && charCount.containsKey('.') && charCount.get('.').equals(1)) { - this.format = FORMAT_X; - int point = format.length() - format.indexOf(".") - 1; - for (int i = 0; i < point; i++) { - this.ratio *= 10.0; - } - this.length = (format.length() - 1) / 2; - return true; - } - // XXXX格式 - if (charCount.containsKey('X') && charCount.size() == 1) { - this.format = FORMAT_X; - this.ratio = 1.0; - this.length = length; - return true; - } - // 各种NN.NN格式 - if (charCount.containsKey('N') && charCount.containsKey('.') && charCount.get('.').equals(1)) { - this.format = FORMAT_N; - int point = format.length() - format.indexOf(".") - 1; - for (int i = 0; i < point; i++) { - this.ratio *= 10.0; - } - this.length = (format.length() - 1) / 2; - return true; - } - // NNN格式 - if (charCount.containsKey('N') && charCount.size() == 1) { - this.format = FORMAT_N; - this.ratio = 1.0; - this.length = length; - return true; - } - - - // 固定长度 - if (this.isFixedLength(format)) { - this.format = format; - this.ratio = 1.0; - this.length = format.length() / 2; - return true; - } - - // 可变长度 - if (this.isVariableLength(format)) { - this.format = format; - this.ratio = 1.0; - this.length = length; - return true; - } - - return false; - } - - /** - * 是否为固定长度:它的长度是直接通过格式就能确定 - * - * @param format - * @return - */ - private boolean isFixedLength(String format) { - if (format.equalsIgnoreCase(FORMAT_hhmm)) { - return true; - } - if (format.equalsIgnoreCase(FORMAT_DDhh)) { - return true; - } - if (format.equalsIgnoreCase(FORMAT_MMDDhhmm)) { - return true; - } - if (format.equalsIgnoreCase(FORMAT_YYMMDDhhmm)) { - return true; - } - if (format.equalsIgnoreCase(FORMAT_hhmmss)) { - return true; - } - if (format.equalsIgnoreCase(FORMAT_mmmm)) { - return true; - } - - return format.equalsIgnoreCase(FORMAT_YYMMDDWW); - } - - /** - * 是否为可变长度:它的长度是通过用户在CSV文件中告知 - * - * @param format - * @return - */ - private boolean isVariableLength(String format) { - if (format.equalsIgnoreCase(FORMAT_NN___NN)) { - return true; - } - if (format.equalsIgnoreCase(FORMAT_XX___XX)) { - return true; - } - if (format.equalsIgnoreCase(FORMAT_STATUS_METER)) { - return true; - } - if (format.equalsIgnoreCase(FORMAT_STATUS_NETWORK)) { - return true; - } - - return format.equalsIgnoreCase(FORMAT_STATUS_WEEK); - } - - /** - * 统计字符数量,方面后面判定格式 - * - * @param format DLT645规约中定义的XXX.XXX之类的各种数据格式文本 - * @return 各字符数量 - */ - private Map charCount(String format) { - - Map charSet = new HashMap<>(); - for (int i = 0; i < format.length(); i++) { - Character ch = format.charAt(i); - Integer count = charSet.get(ch); - if (count == null) { - count = 0; - } - - count++; - charSet.put(ch, count); - } - - return charSet; - } - - /** - * 4字节长度的double型数值 - * - * @param data data数组 - * @param start 数据在数组中的起始位置 - * @param ratio 倍率,比如缩小100倍数,那么填0.01 - * @return 返回值 - */ - private Object getValue(byte[] data, int start, int length, double ratio) { - long sum = 0; - double rd = 1.0; - for (int i = 0; i < length; i++) { - long l = data[start + i] & 0x0f; - long h = (data[start + i] & 0xf0) >> 4; - - l = (long) (l * rd); - sum += l; - rd = rd * 10.0; - - - h = (long) (h * rd); - sum += h; - rd = rd * 10.0; - - } - - if (ratio < 1.1 && ratio > 0.0) { - // 如果ratio==1 - return sum; - } else { - return sum / ratio; - } - } - - /** - * 日期格式的解码 - * - * @param data data数组 - * @param format 日期格式 - * @param start 数据在数组中的起始位置 - * @param length 格式长度 - * @return 返回值 - */ - private String getDataTime(byte[] data, String format, int start, int length) { - // 拆解成个位数列表 - List list = new ArrayList<>(); - for (int i = 0; i < length; i++) { - int l = data[start + i] & 0x0f; - int h = (data[start + i] & 0xf0) >> 4; - - list.add(Integer.toString(l)); - list.add(Integer.toString(h)); - } - - // 格式1 - if (format.equals(FORMAT_YYMMDDhhmm)) { - String result = "20" + list.get(9) + list.get(8) + "年" + list.get(7) + list.get(6) + "月" + list.get(5) + list.get(4) + "日"; - result += " " + list.get(3) + list.get(2) + "点" + list.get(1) + list.get(0) + "分"; - return result; - } - - if (format.equals(FORMAT_YYMMDDWW)) { - String result = "20" + list.get(7) + list.get(6) + "年" + list.get(5) + list.get(4) + "月" + list.get(3) + list.get(2) + "日"; - result += " 星期:" + list.get(1) + list.get(0); - return result; - } - if (format.equals(FORMAT_hhmmss)) { - return list.get(5) + list.get(4) + "点" + list.get(3) + list.get(2) + "分" + list.get(1) + list.get(0) + "秒"; - } - if (format.equals(FORMAT_mmmm)) { - return list.get(3) + list.get(2) + list.get(1) + list.get(0) + "分"; - } - - - if (format.equals(FORMAT_MMDDhhmm)) { - String result = list.get(7) + list.get(6) + "月" + list.get(5) + list.get(4) + "日 "; - result += list.get(3) + list.get(2) + "点" + list.get(1) + list.get(0) + "分"; - return result; - } - if (format.equals(FORMAT_DDhh)) { - return list.get(3) + list.get(2) + "号 " + list.get(1) + list.get(0) + "点"; - } - if (format.equals(FORMAT_hhmm)) { - return list.get(3) + list.get(2) + "点 " + list.get(1) + list.get(0) + "分"; - } - - - return ""; - } - - private byte encodeBCD(byte a) { - return (byte) ((a / 10) * 16 + (a % 10)); - } - - private byte decodeBCD(byte a) { - return (byte) ((a / 16) * 10 + (a % 16)); - } - - private Object getString(byte[] data, int start, int length) { - byte[] tmp = new byte[length]; - - for (int i = 0; i < length; i++) { - tmp[i] = data[start + i]; - } - for (int i = 0; i < length / 2; i++) { - byte by = tmp[i]; - tmp[i] = tmp[length - i - 1]; - tmp[length - i - 1] = by; - } - return ByteUtils.byteArrayToHexString(tmp, true).replace(" ", ""); - } -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645FunCode.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645FunCode.java deleted file mode 100644 index f091c408..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645FunCode.java +++ /dev/null @@ -1,183 +0,0 @@ -package cc.iotkit.comp.DLT645.analysis; - -import lombok.Data; - -/** - * 功能码 - */ -@Data -public class DLT645FunCode { - - public static final String func_v97_00000 = "保留"; - public static final String func_v97_00001 = "读数据"; - public static final String func_v97_00010 = "读后续数据"; - public static final String func_v97_00011 = "重读数据"; - public static final String func_v97_00100 = "写数据"; - public static final String func_v97_01000 = "广播校时"; - public static final String func_v97_01010 = "写设备地址"; - public static final String func_v97_01100 = "更改通信速率"; - public static final String func_v97_01111 = "修改密码"; - public static final String func_v97_10000 = "最大需量清零"; - /** - * 方向:主站发出=false,从站应答=true - */ - private boolean direct = false; - /** - * 从站是否异常应答 - */ - private boolean error = false; - /** - * 功能代码 - */ - private byte code = 0; - /** - * 是否最后的尾部 - */ - private boolean next = false; - - public static DLT645FunCode decodeEntity(byte func) { - DLT645FunCode dlt645FunCode = new DLT645FunCode(); - dlt645FunCode.decode(func); - return dlt645FunCode; - } - - public static int getCodev1997(String text) { - if (func_v97_00000.equals(text)) {// - return 0b00000; - } - if (func_v97_00001.equals(text)) { - return 0b00001; - } - if (func_v97_00010.equals(text)) { - return 0b00010; - } - if (func_v97_00011.equals(text)) { - return 0b00011; - } - if (func_v97_00100.equals(text)) { - return 0b00100; - } - if (func_v97_01000.equals(text)) { - return 0b01000; - } - if (func_v97_01010.equals(text)) { - return 0b01010; - } - if (func_v97_01100.equals(text)) { - return 0b01100; - } - if (func_v97_01111.equals(text)) { - return 0b01111; - } - if (func_v97_10000.equals(text)) { - return 0b10000; - } - return 0b00000; - } - - /** - * 编码 - * - * @return 功能码 - */ - public byte encode() { - int func = 0; - if (this.direct) { - func |= 0x80; - } - if (this.error) { - func |= 0x40; - } - if (this.next) { - func |= 0x20; - } - func |= this.code & 0x1F; - - return (byte) func; - } - - /** - * 生成功能码 - * - * @param dlt645FunCode - * @return - */ - public byte encodeFunCode(DLT645FunCode dlt645FunCode) { - return dlt645FunCode.encode(); - } - - /** - * 解码 - * - * @param func - */ - public void decode(byte func) { - this.direct = (func & 0x80) > 0; - this.error = (func & 0x40) > 0; - this.next = (func & 0x20) > 0; - this.code = (byte) (func & 0x1F); - } - - public String getCodeTextV1997() { - if (this.code == 0b00000) { - return func_v97_00000; - } - if (this.code == 0b01000) { - return func_v97_01000; - } - if (this.code == 0b00001) { - return func_v97_00001; - } - if (this.code == 0b00010) { - return func_v97_00010; - } - if (this.code == 0b00100) { - return func_v97_00100; - } - if (this.code == 0b01010) { - return func_v97_01010; - } - if (this.code == 0b01100) { - return func_v97_01100; - } - if (this.code == 0b01111) { - return func_v97_01111; - } - if (this.code == 0b10000) { - return func_v97_10000; - } - - return ""; - } - - /** - * 获取文本描述 - * - * @return 文本描述 - */ - public String getMessage() { - String message = ""; - if (this.direct) { - message += "从站发出:"; - } else { - message += "主站发出:"; - } - - message += this.getCodeTextV1997(); - - if (this.error) { - message += ":异常"; - } else { - message += ":正常"; - } - - - if (this.next) { - message += ":还有后续帧"; - } else { - message += ":这是末尾帧"; - } - - return message; - } -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645V1997Data.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645V1997Data.java deleted file mode 100644 index 9204b615..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645V1997Data.java +++ /dev/null @@ -1,59 +0,0 @@ -package cc.iotkit.comp.DLT645.analysis; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import lombok.Getter; -import lombok.Setter; - -@Setter -@Getter -public class DLT645V1997Data extends DLT645Data { - /** - * DI1/DI0 - */ - private byte di0l = 0; - private byte di0h = 0; - private byte di1l = 0; - private byte di1h = 0; - - @Override - public String getKey() { - String key = ""; - key += Integer.toString(this.di1h, 16); - key += Integer.toString(this.di1l, 16); - key += Integer.toString(this.di0h, 16); - key += Integer.toString(this.di0l, 16); - return key.toUpperCase(); - } - - @Override - public byte[] getDIn() { - byte[] value = new byte[2]; - value[0] = (byte) (this.di0l + (this.di0h << 4)); - value[1] = (byte) (this.di1l + (this.di1h << 4)); - return value; - } - - @Override - public void setDIn(byte[] value) { - if (value.length < 2) { - throw new BizException(ErrCode.DATA_LENGTH_ERROR); - } - - // DI值 - this.di1h = (byte) ((value[1] & 0xf0) >> 4); - this.di1l = (byte) (value[1] & 0x0f); - this.di0h = (byte) ((value[0] & 0xf0) >> 4); - this.di0l = (byte) (value[0] & 0x0f); - } - - /** - * 1997版的DIn2字节 - * - * @return - */ - @Override - public int getDInLen() { - return 2; - } -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645v1997CsvLoader.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645v1997CsvLoader.java deleted file mode 100644 index 01a2b7b1..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/analysis/DLT645v1997CsvLoader.java +++ /dev/null @@ -1,87 +0,0 @@ -package cc.iotkit.comp.DLT645.analysis; - -import cn.hutool.core.text.csv.CsvReader; -import cn.hutool.core.text.csv.CsvUtil; -import cn.hutool.core.util.CharsetUtil; -import lombok.Data; - -import java.io.InputStreamReader; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * 数据实体的数据模板 - */ -public class DLT645v1997CsvLoader { - /** - * 从CSV文件中装载映射表 - * - */ - public List loadCsvFile() { - CsvReader csvReader = CsvUtil.getReader(); - InputStreamReader dataReader=new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("DLT645-1997.csv"),CharsetUtil.CHARSET_GBK); - List rows = csvReader.read(dataReader, JDecoderValueParam.class); - List list = new ArrayList<>(); - for (JDecoderValueParam jDecoderValueParam : rows) { - try { - DLT645V1997Data entity = new DLT645V1997Data(); - entity.setName(jDecoderValueParam.getName()); - entity.setDi1h((byte) Integer.parseInt(jDecoderValueParam.di1h, 16)); - entity.setDi1l((byte) Integer.parseInt(jDecoderValueParam.di1l, 16)); - entity.setDi0h((byte) Integer.parseInt(jDecoderValueParam.di0h, 16)); - entity.setDi0l((byte) Integer.parseInt(jDecoderValueParam.di0l, 16)); - entity.setLength(jDecoderValueParam.length); - entity.setUnit(jDecoderValueParam.unit); - entity.setRead(Boolean.parseBoolean(jDecoderValueParam.read)); - entity.setWrite(Boolean.parseBoolean(jDecoderValueParam.write)); - - DLT645DataFormat format = new DLT645DataFormat(); - if (format.decodeFormat(jDecoderValueParam.format, jDecoderValueParam.length)) { - entity.setFormat(format); - } else { - System.out.println("DLT645 CSV记录的格式错误:" + jDecoderValueParam.getName() + ":" + jDecoderValueParam.getFormat()); - continue; - } - list.add(entity); - } catch (Exception e) { - e.printStackTrace(); - } - } - return list; - } - - - @Data - public static class JDecoderValueParam implements Serializable { - private String di1h; - private String di1l; - private String di0h; - private String di0l; - /** - * 编码格式 - */ - private String format; - /** - * 长度 - */ - private Integer length; - /** - * 单位 - */ - private String unit; - - /** - * 是否可读 - */ - private String read; - /** - * 是否可写 - */ - private String write; - /** - * 名称 - */ - private String name; - } -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/ByteRef.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/ByteRef.java deleted file mode 100644 index 34959e0d..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/ByteRef.java +++ /dev/null @@ -1,11 +0,0 @@ -package cc.iotkit.comp.DLT645.utils; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Setter; - -@Getter(value = AccessLevel.PUBLIC) -@Setter(value = AccessLevel.PUBLIC) -public class ByteRef { - private byte value = 0; -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/ByteUtils.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/ByteUtils.java deleted file mode 100644 index 703ef25b..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/ByteUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -package cc.iotkit.comp.DLT645.utils; - -public class ByteUtils { - - /** - * 根据十六进制生成byte - * - * @param hex 16进制的字符串 比如"FF" - * @return byte数字比如-1 - */ - public static byte hex2byte(String hex) { - return Integer.valueOf(hex, 16).byteValue(); - } - - /** - * 16进制的字符串表示转成字节数组 - * - * @param hexString 16进制格式的字符串 - * @return 转换后的字节数组 - **/ - public static byte[] hexStringToByteArray(String hexString) { - String string = hexString.replaceAll(" ", ""); - final byte[] byteArray = new byte[string.length() / 2]; - int pos = 0; - for (int i = 0; i < byteArray.length; i++) { - // 因为是16进制,最多只会占用4位,转换成字节需要两个16进制的字符,高位在先 - byte high = (byte) (Character.digit(string.charAt(pos), 16) & 0xff); - byte low = (byte) (Character.digit(string.charAt(pos + 1), 16) & 0xff); - byteArray[i] = (byte) (high << 4 | low); - pos += 2; - } - - return byteArray; - } - - /** - * 字节数组转成16进制表示格式的字符串 - * - * @param byteArray 要转换的字节数组 - * @return 16进制表示格式的字符串 - **/ - public static String byteArrayToHexString(byte[] byteArray) { - return byteArrayToHexString(byteArray, true); - } - - public static String byteArrayToHexString(byte[] byteArray, boolean blankz) { - final StringBuilder hexString = new StringBuilder(); - for (int i = 0; i < byteArray.length; i++) { - if ((byteArray[i] & 0xff) < 0x10) { - // 0~F前面不零 - hexString.append("0"); - } - - hexString.append(Integer.toHexString(0xFF & byteArray[i])); - - if (blankz) { - hexString.append(" "); - } - } - return hexString.toString(); - } - - /** - * 字节逆序 - * - **/ - public static void byteInvertedOrder(byte[] tmp,byte[] retData) { - System.arraycopy(tmp, 0, retData, 0, Math.min(tmp.length, retData.length)); - for (int i = 0; i < retData.length / 2; i++) { - byte by = retData[i]; - retData[i] = retData[5 - i]; - retData[5 - i] = by; - } - } - -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/BytesRef.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/BytesRef.java deleted file mode 100644 index d2db4b7c..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/BytesRef.java +++ /dev/null @@ -1,11 +0,0 @@ -package cc.iotkit.comp.DLT645.utils; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.Setter; - -@Getter(value = AccessLevel.PUBLIC) -@Setter(value = AccessLevel.PUBLIC) -public class BytesRef { - private byte[] value = new byte[] {}; -} diff --git a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/ContainerUtils.java b/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/ContainerUtils.java deleted file mode 100644 index 6ec6c534..00000000 --- a/iot-components/iot-DLT645-component/src/main/java/cc/iotkit/comp/DLT645/utils/ContainerUtils.java +++ /dev/null @@ -1,422 +0,0 @@ -package cc.iotkit.comp.DLT645.utils; - -import java.io.Serializable; -import java.lang.invoke.SerializedLambda; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.*; -import java.util.function.Function; - -/** - * 集合操作的工具类 - */ -public class ContainerUtils { - public ContainerUtils() { - } - - /** - * 获取类函数的名称 - * 例如:getMethodName(Integer.toHexString),返回的就是toHexString - * - * @param function - * @param - * @param - * @return - * @throws NoSuchMethodException - * @throws SecurityException - * @throws IllegalAccessException - * @throws IllegalArgumentException - * @throws InvocationTargetException - */ - private static String getMethodName(SerializableFunction function) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Method method = function.getClass().getDeclaredMethod("writeReplace"); - method.setAccessible(Boolean.TRUE); - SerializedLambda serializedLambda = (SerializedLambda) method.invoke(function); - String implMethodName = serializedLambda.getImplMethodName(); - - return implMethodName; - } - - /** - * 获取类的函数 - * - * @param clazz - * @param function - * @param - * @param - * @param - * @return - * @throws NoSuchMethodException - * @throws SecurityException - * @throws IllegalAccessException - * @throws IllegalArgumentException - * @throws InvocationTargetException - */ - private static Method getMethod(Class clazz, SerializableFunction function) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - String methodName = ContainerUtils.getMethodName(function); - return clazz.getMethod(methodName); - } - - /** - * 根据对象列表中的对象的getXxxx()函数,取出成员 - * - * @param objList - * @param clazz - * @param method method是clazz的成员函数 - * @param - * @param - * @return - */ - private static List buildListByGetField(List objList, Class clazz, Method method) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - List keyList = new ArrayList(); - for (T obj : objList) { - // 接下来就该执行该方法了,第一个参数是具体调用该方法的对象, 第二个参数是执行该方法的具体参数 - Object keyObject = method.invoke(obj); - if (clazz.isInstance(keyObject)) { - K key = clazz.cast(keyObject); - keyList.add(key); - } - } - - return keyList; - } - - public static List buildKeyList(List objList, Method method) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - List keyList = new ArrayList(); - Class returnType = method.getReturnType(); - for (T obj : objList) { - // 接下来就该执行该方法了,第一个参数是具体调用该方法的对象, 第二个参数是执行该方法的具体参数 - Object keyObject = method.invoke(obj); - if (returnType.isInstance(keyObject)) { - keyList.add((K) returnType.cast(keyObject)); - } - } - - return keyList; - } - - /** - * 根据对象的getXxxx(),取出类型列表中的数据 - * - * @param objList AClass对象列表 - * @param clazz TClass AClass::getXxxx()中,TClass这样的成员 - * @param function AClass::getXxxx 这样的函数 - * @param - * @param - * @param - * @param - * @return - */ - public static List buildListByGetField(List objList, SerializableFunction function, Class clazz) { - if (objList.isEmpty()) { - return new ArrayList(); - } - - try { - // 取得函数对应的方法 - Method method = ContainerUtils.getMethod(objList.get(0).getClass(), function); - - // 使用方法返回对应的数组 - return ContainerUtils.buildListByGetField(objList, clazz, method); - } catch (NoSuchMethodException e) { - return new ArrayList(); - } catch (SecurityException e) { - return new ArrayList(); - } catch (IllegalAccessException e) { - return new ArrayList(); - } catch (IllegalArgumentException e) { - return new ArrayList(); - } catch (InvocationTargetException e) { - return new ArrayList(); - } - } - - /** - * 根据Key生成Map,该方法是是具体类的函数,(不具备多态能力,不是反射,速度很快) - * - * @param objList - * @param clazz - * @param method 使用obj.getClass().getMethod("getTnlKey", new Class[0])获取Method - * @return - */ - public static Map buildMapByKeyAndFinalMethod(List objList, Class clazz, Method method) { - try { - Map uid2deviceMap = new HashMap(); - for (T obj : objList) { - // 接下来就该执行该方法了,第一个参数是具体调用该方法的对象, 第二个参数是执行该方法的具体参数 - Object keyObject = method.invoke(obj); - if (clazz.isInstance(keyObject)) { - K key = clazz.cast(keyObject); - uid2deviceMap.put(key, obj); - } - } - - return uid2deviceMap; - } catch (IllegalAccessException e) { - return Collections.emptyMap(); - } catch (InvocationTargetException e) { - return Collections.emptyMap(); - } - } - - - public static Map buildMapByKey(List objList, SerializableFunction function) { - if (objList.isEmpty()) { - return new HashMap<>(); - } - - try { - // 取得函数对应的方法 - Method method = ContainerUtils.getMethod(objList.get(0).getClass(), function); - - // 使用方法返回对应的数组 - return ContainerUtils.buildMapByKey(objList, method); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | IllegalArgumentException | - SecurityException e) { - return new HashMap(); - } - } - - public static Map buildMapByKey(List objList, Method method) { - try { - Map uid2deviceMap = new HashMap(); - for (T obj : objList) { - // 接下来就该执行该方法了,第一个参数是具体调用该方法的对象, 第二个参数是执行该方法的具体参数 - Object keyObject = method.invoke(obj); - uid2deviceMap.put((K) keyObject, obj); - } - - return uid2deviceMap; - } catch (IllegalAccessException | InvocationTargetException e) { - return Collections.emptyMap(); - } - } - - /** - * 分类 - * - * @param objList - * @param clazz - * @param method - * @param - * @param - * @return - */ - public static Map> buildMapByTypeAndFinalMethod(List objList, Class clazz, Method method) { - try { - Map> uid2deviceMap = new HashMap<>(); - for (T obj : objList) { - // 接下来就该执行该方法了,第一个参数是具体调用该方法的对象, 第二个参数是执行该方法的具体参数 - Object keyObject = method.invoke(obj); - if (clazz.isInstance(keyObject)) { - K key = clazz.cast(keyObject); - List list = uid2deviceMap.computeIfAbsent(key, k -> new ArrayList<>()); - list.add(obj); - } - } - return uid2deviceMap; - } catch (IllegalAccessException | InvocationTargetException e) { - return Collections.emptyMap(); - } - } - - /** - * 根据Key生成Map,该方法是是具体类的函数,(不具备多态能力,不是反射,速度很快) - * - * @param objList 类型AClass的列表容器 - * @param function 类型AClass中的某个成员getxxxx() - * @param clazz 类型AClass中的某个成员BClass getxxxx()中的BClass - * @param - * @param - * @param - * @param - * @return - */ - public static Map buildMapByKeyAndFinalMethod(List objList, SerializableFunction function, Class clazz) { - if (objList.isEmpty()) { - return new HashMap<>(); - } - - try { - // 取得函数对应的方法 - Method method = ContainerUtils.getMethod(objList.get(0).getClass(), function); - - // 使用方法返回对应的数组 - return ContainerUtils.buildMapByKeyAndFinalMethod(objList, clazz, method); - } catch (NoSuchMethodException e) { - return new HashMap(); - } catch (SecurityException e) { - return new HashMap(); - } catch (IllegalAccessException e) { - return new HashMap(); - } catch (IllegalArgumentException e) { - return new HashMap(); - } catch (InvocationTargetException e) { - return new HashMap(); - } - } - - public static Map> buildMapByTypeAndFinalMethod(List objList, SerializableFunction function, Class clazz) { - if (objList.isEmpty()) { - return new HashMap<>(); - } - - try { - // 取得函数对应的方法 - Method method = ContainerUtils.getMethod(objList.get(0).getClass(), function); - - // 使用方法返回对应的数组 - return ContainerUtils.buildMapByTypeAndFinalMethod(objList, clazz, method); - } catch (NoSuchMethodException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | - SecurityException e) { - return new HashMap<>(); - } - } - - /** - * 根据map中的某个元素,将列表转换成以这个元素为key的map - * - * @param objList - * @param mapKey - * @param clazz - * @param - * @param - * @return - */ - public static Map> buildMapByMapAt(List> objList, String mapKey, Class clazz) { - if (objList.isEmpty()) { - return new HashMap<>(); - } - - Map> result = new HashMap<>(); - for (Map obj : objList) { - Object value = obj.get(mapKey); - if (!clazz.isInstance(value)) { - continue; - } - - result.put((K) value, obj); - } - - return result; - } - - /** - * 从列表中获取:某个字段等于某个值的对象 - * - * @param objList - * @param function - * @param key - * @param - * @param - * @param - * @param - * @return - */ - public static T getObjectByKey(List objList, SerializableFunction function, K key) { - try { - if (objList.isEmpty()) { - return null; - } - - Method method = ContainerUtils.getMethod(objList.get(0).getClass(), function); - - for (T obj : objList) { - // 先获取相应的method对象,getMethod第一个参数是方法名,第二个参数是该方法的参数类型, - // Method method = obj.getClass().getMethod(getKeyMathName, new Class[0]); - - // 接下来就该执行该方法了,第一个参数是具体调用该方法的对象, 第二个参数是执行该方法的具体参数 - Object keyObject = method.invoke(obj); - if (key.getClass().isInstance(keyObject)) { - if (keyObject.equals(key)) { - return obj; - } - } - } - - return null; - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - return null; - } - } - - /** - * 交换Key-Value - * - * @param key2value key2value - * @return value2key - */ - public static Map exchange(Map key2value) { - Map result = new HashMap<>(); - - for (Map.Entry entry : key2value.entrySet()) { - result.put(entry.getValue(), entry.getKey()); - } - - return result; - } - - public static Map> exchanges(Map key2value) { - Map> result = new HashMap<>(); - - for (Map.Entry entry : key2value.entrySet()) { - List list = result.get(entry.getValue()); - if (list == null) { - list = new ArrayList<>(); - result.put(entry.getValue(), list); - } - - list.add(entry.getKey()); - } - - return result; - } - - /** - * 根据Key提取出相关的值列表 - * - * @param key2value key2value - * @param keyList key列表 - * @return 跟key相关的values - */ - public static List buildValueListByKey(Map key2value, Collection keyList) { - List resultList = new ArrayList(); - for (K key : keyList) { - V value = key2value.get(key); - if (value != null) { - resultList.add(value); - } - } - - return resultList; - } - - /** - * 从A类型列表转换成B类型列表:A/B是派生类关系 - * - * @param aClazzList - * @param bClazz - * @return - */ - public static List buildClassList(List aClazzList, Class bClazz) { - List bInstanceList = new ArrayList(); - - for (A aInstance : aClazzList) { - if (bClazz.isInstance(aInstance)) { - bInstanceList.add(bClazz.cast(aInstance)); - } - } - - return bInstanceList; - } - - /** - * 定义一个函数接口 - * - * @param - * @param - */ - @FunctionalInterface - public interface SerializableFunction extends Function, Serializable { - } -} diff --git a/iot-components/iot-DLT645-component/src/main/resources/DLT645-1997.csv b/iot-components/iot-DLT645-component/src/main/resources/DLT645-1997.csv deleted file mode 100644 index bdc26858..00000000 --- a/iot-components/iot-DLT645-component/src/main/resources/DLT645-1997.csv +++ /dev/null @@ -1,143 +0,0 @@ -di1h,di1l,di0h,di0l,format,length,unit,read,write,name -9,0,1,0,XXXXXX.XX,4,kWh,TRUE,FALSE,(ǰ)йܵ -9,0,2,0,XXXXXX.XX,4,kWh,TRUE,FALSE,(ǰ)йܵ -9,1,1,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(ǰ)޹ܵ -9,1,2,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(ǰ)޹ܵ -9,1,3,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(ǰ)һ޹ܵ -9,1,4,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(ǰ)޹ܵ -9,1,5,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(ǰ)޹ܵ -9,1,6,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(ǰ)޹ܵ -9,4,1,0,XXXXXX.XX,4,kWh,TRUE,FALSE,()йܵ -9,4,2,0,XXXXXX.XX,4,kWh,TRUE,FALSE,()йܵ -9,5,1,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()޹ܵ -9,5,2,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()޹ܵ -9,5,3,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()һ޹ܵ -9,5,4,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()޹ܵ -9,5,5,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()޹ܵ -9,5,6,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()޹ܵ -9,8,1,0,XXXXXX.XX,4,kWh,TRUE,FALSE,()йܵ -9,8,2,0,XXXXXX.XX,4,kWh,TRUE,FALSE,()йܵ -9,9,1,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()޹ܵ -9,9,2,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()޹ܵ -9,9,3,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()һ޹ܵ -9,9,4,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()޹ܵ -9,9,5,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()޹ܵ -9,9,6,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,()޹ܵ -A,0,1,0,XX.XXXX,3,kW,TRUE,FALSE,(ǰ)й -A,0,2,0,XX.XXXX,3,kW,TRUE,FALSE,(ǰ)й -A,1,1,0,XX.XXXX,3,kvar,TRUE,FALSE,(ǰ)޹ -A,1,2,0,XX.XXXX,3,kvar,TRUE,FALSE,(ǰ)޹ -A,1,3,0,XX.XXXX,3,kvar,TRUE,FALSE,(ǰ)һ޹ -A,1,4,0,XX.XXXX,3,kvar,TRUE,FALSE,(ǰ)޹ -A,1,5,0,XX.XXXX,3,kvar,TRUE,FALSE,(ǰ)޹ -A,1,6,0,XX.XXXX,3,kvar,TRUE,FALSE,(ǰ)޹ -A,4,1,0,XX.XXXX,3,kW,TRUE,FALSE,()й -A,4,2,0,XX.XXXX,3,kW,TRUE,FALSE,()й -A,5,1,0,XX.XXXX,3,kvar,TRUE,FALSE,()޹ -A,5,2,0,XX.XXXX,3,kvar,TRUE,FALSE,()޹ -A,5,3,0,XX.XXXX,3,kvar,TRUE,FALSE,()һ޹ -A,5,4,0,XX.XXXX,3,kvar,TRUE,FALSE,()޹ -A,5,5,0,XX.XXXX,3,kvar,TRUE,FALSE,()޹ -A,5,6,0,XX.XXXX,3,kvar,TRUE,FALSE,()޹ -A,8,1,0,XX.XXXX,3,kvar,TRUE,FALSE,()й -A,8,2,0,XX.XXXX,3,kvar,TRUE,FALSE,()й -A,9,1,0,XX.XXXX,3,kvar,TRUE,FALSE,()޹ -A,9,2,0,XX.XXXX,3,kvar,TRUE,FALSE,()޹ -A,9,3,0,XX.XXXX,3,kvar,TRUE,FALSE,()һ޹ -A,9,4,0,XX.XXXX,3,kvar,TRUE,FALSE,()޹ -A,9,5,0,XX.XXXX,3,kvar,TRUE,FALSE,()޹ -A,9,6,0,XX.XXXX,3,kvar,TRUE,FALSE,()޹ -B,0,1,0,MMDDHHmm,4,,TRUE,FALSE,(ǰ)йʱ -B,0,2,0,MMDDHHmm,4,,TRUE,FALSE,(ǰ)йʱ -B,1,1,0,MMDDHHmm,4,,TRUE,FALSE,(ǰ)޹ʱ -B,1,2,0,MMDDHHmm,4,,TRUE,FALSE,(ǰ)޹ʱ -B,1,3,0,MMDDHHmm,4,,TRUE,FALSE,(ǰ)һ޹ʱ -B,1,4,0,MMDDHHmm,4,,TRUE,FALSE,(ǰ)޹ʱ -B,1,5,0,MMDDHHmm,4,,TRUE,FALSE,(ǰ)޹ʱ -B,1,6,0,MMDDHHmm,4,,TRUE,FALSE,(ǰ)޹ʱ -B,4,1,0,MMDDHHmm,4,,TRUE,FALSE,()йʱ -B,4,2,0,MMDDHHmm,4,,TRUE,FALSE,()йʱ -B,5,1,0,MMDDHHmm,4,,TRUE,FALSE,()޹ʱ -B,5,2,0,MMDDHHmm,4,,TRUE,FALSE,()޹ʱ -B,5,3,0,MMDDHHmm,4,,TRUE,FALSE,()һ޹ʱ -B,5,4,0,MMDDHHmm,4,,TRUE,FALSE,()޹ʱ -B,5,5,0,MMDDHHmm,4,,TRUE,FALSE,()޹ʱ -B,5,6,0,MMDDHHmm,4,,TRUE,FALSE,()޹ʱ -B,8,1,0,MMDDHHmm,4,,TRUE,FALSE,()йʱ -B,8,2,0,MMDDHHmm,4,,TRUE,FALSE,()йʱ -B,9,1,0,MMDDHHmm,4,,TRUE,FALSE,()޹ʱ -B,9,2,0,MMDDHHmm,4,,TRUE,FALSE,()޹ʱ -B,9,3,0,MMDDHHmm,4,,TRUE,FALSE,()һ޹ʱ -B,9,4,0,MMDDHHmm,4,,TRUE,FALSE,()޹ʱ -B,9,5,0,MMDDHHmm,4,,TRUE,FALSE,()޹ʱ -B,9,6,0,MMDDHHmm,4,,TRUE,FALSE,()޹ʱ -B,2,1,0,MMDDHHmm,4,,TRUE,FALSE,һαʱ -B,2,1,1,MMDDHHmm,4,,TRUE,FALSE,һʱ -B,2,1,2,NNNN,2,,TRUE,FALSE,̴ -B,2,1,3,NNNN,2,,TRUE,FALSE, -B,2,1,4,NNNNNN,3,min,TRUE,FALSE,عʱ -B,3,1,0,NNNN,2,,TRUE,FALSE,ܶ -B,3,1,1,NNNN,2,,TRUE,FALSE,A -B,3,1,2,NNNN,2,,TRUE,FALSE,B -B,3,1,3,NNNN,2,,TRUE,FALSE,C -B,3,2,0,NNNNNN,3,min,TRUE,FALSE,ʱۼֵ -B,3,2,1,NNNNNN,3,min,TRUE,FALSE,A ʱۼֵ -B,3,2,2,NNNNNN,3,min,TRUE,FALSE,B ʱۼֵ -B,3,2,3,NNNNNN,3,min,TRUE,FALSE,C ʱۼֵ -B,3,3,0,MMDDHHmm,4,,TRUE,FALSE,һζʼʱ -B,3,3,1,MMDDHHmm,4,,TRUE,FALSE,A ʼʱ -B,3,3,2,MMDDHHmm,4,,TRUE,FALSE,B ʼʱ -B,3,3,3,MMDDHHmm,4,,TRUE,FALSE,Cʼʱ -B,3,4,0,MMDDHHmm,4,,TRUE,FALSE,һζĽʱ -B,3,4,1,MMDDHHmm,4,,TRUE,FALSE,A һζĽʱ -B,3,4,2,MMDDHHmm,4,,TRUE,FALSE,B һζĽʱ -B,3,4,3,MMDDHHmm,4,,TRUE,FALSE,C һζĽʱ -B,6,1,1,XXX,2,V,TRUE,FALSE,Aѹ -B,6,1,2,XXX,2,V,TRUE,FALSE,Bѹ -B,6,1,3,XXX,2,V,TRUE,FALSE,Cѹ -B,6,2,1,XX.XX,2,A,TRUE,FALSE,A -B,6,2,2,XX.XX,2,A,TRUE,FALSE,B -B,6,2,3,XX.XX,2,A,TRUE,FALSE,C -B,6,3,0,XX.XXXX,3,kW,TRUE,FALSE,˲ʱй -B,6,3,1,XX.XXXX,3,kW,TRUE,FALSE,Aй -B,6,3,2,XX.XXXX,3,kW,TRUE,FALSE,Bй -B,6,3,3,XX.XXXX,3,kW,TRUE,FALSE,Cй -B,6,3,4,XX.XX,2,kW,TRUE,TRUE,йֵ -B,6,3,5,XX.XX,2,kW,TRUE,TRUE,йֵ -B,6,4,0,XX.XX,2,kvarh,TRUE,FALSE,˲ʱ޹ -B,6,4,1,XX.XX,2,kvarh,TRUE,FALSE,A޹ -B,6,4,2,XX.XX,2,kvarh,TRUE,FALSE,B޹ -B,6,4,3,XX.XX,2,kvarh,TRUE,FALSE,C޹ -B,6,5,0,XX.XX,2,kvarh,TRUE,FALSE,ܹ -B,6,5,1,XX.XX,3,kvarh,TRUE,FALSE,A ๦ -B,6,5,2,XX.XX,4,kvarh,TRUE,FALSE,B ๦ -B,6,5,3,XX.XX,5,kvarh,TRUE,FALSE,C ๦ -C,0,1,0,YYMMDDWW,4,,TRUE,TRUE,ڼܴ -C,0,1,1,hhmmss,3,,TRUE,TRUE,ʱ -C,0,2,0,״̬,1,,TRUE,TRUE,״̬ -C,0,2,1,״̬,1,,TRUE,TRUE,״̬ -C,0,2,2,״̬,1,,TRUE,TRUE,״̬ -C,0,3,0,NNNNNN,3,p/(kWh),TRUE,TRUE,(й) -C,0,3,1,NNNNNN,3,p/(kvarh),TRUE,TRUE,(޹) -C,0,3,2,NN...NN,6,,TRUE,TRUE, -C,0,3,3,NN...NN,6,,TRUE,TRUE,û -C,0,3,4,NN...NN,6,,TRUE,TRUE,豸 -C,1,1,1,XX,1,min,TRUE,TRUE, -C,1,1,2,XX,1,min,TRUE,TRUE,ʱ -C,1,1,3,XX,1,s,TRUE,TRUE,ѭʱ -C,1,1,4,XX,1,s,TRUE,TRUE,ͣʱ -C,1,1,5,NN,1,,TRUE,TRUE,ʾСλ -C,1,1,6,NN,1,,TRUE,TRUE,ʾ()Сλ -C,1,1,7,DDhh,2,,TRUE,TRUE,Զ -C,1,1,8,NN,1,,TRUE,TRUE,ɴ -C,1,1,9,NNNNNN.N,4,kWh,TRUE,TRUE,йʼ -C,1,1,A,NNNNNN.N,4,kvarh,TRUE,TRUE,޹ʼ -C,2,1,1,NNNN,2,ms,TRUE,TRUE, -C,2,1,2,NNNNNNNN,4,,FALSE,TRUE,Ȩ޼ -C,3,1,0,NN,1,,TRUE,TRUE,ʱ -C,3,1,1,NN,1,,TRUE,TRUE,ʱα -C,3,1,2,NN,1,,TRUE,TRUE,ʱ(ÿл)m10 -C,3,1,3,NN,1,,TRUE,TRUE, k14 -C,3,1,4,NN,1,,TRUE,TRUE, -C,5,1,0,MMDDhhmm,4,,TRUE,TRUE,ɼ¼ʼʱ -C,5,1,1,mmmm,2,min,TRUE,TRUE,ɼ¼ʱ diff --git a/iot-components/iot-DLT645-component/src/main/resources/component.js b/iot-components/iot-DLT645-component/src/main/resources/component.js deleted file mode 100644 index 103842e6..00000000 --- a/iot-components/iot-DLT645-component/src/main/resources/component.js +++ /dev/null @@ -1,74 +0,0 @@ -var mid=1; - -var gatewayPk="BRD3x4fkKxkaxXFt" -var smartMeterPk="PjmkANSTDt85bZPj" - -function getMid(){ - mid++; - if(mid>10000){ - mid=1; - } - return mid; -}; -function register(head){ - var mac= head.mac; - return { - type:"register", - data:{ - productKey:gatewayPk, - deviceName:mac, - model:"" - } - }; -} - -function deviceStateChange(head,type){ - var mac=head.mac; - return { - type:"state", - data:{ - productKey:gatewayPk, - deviceName:mac, - state:type - } - } -} - -function dltHandle(payload){ - var dltData= JSON.parse(payload); - var identify= dltData.identify; - var content={}; - content[identify]=dltData.data; - return { - type:"report", - data:{ - productKey:smartMeterPk, - deviceName:dltData.deviceAddress, - mid:getMid(), - content:{ - type:"property", - identifier: "report", //属性上报 - occur: new Date().getTime(), //时间戳,设备上的事件或数据产生的本地时间 - time: new Date().getTime(), //时间戳,消息上报时间 - data: content - } - }, - } -} - -//必须提供onReceive方法 -this.onReceive=function(head,type,payload){ - if("register"==type){ - return register(head); - }else if("online"==type){ - return deviceStateChange(head,type); - }else if("offline"==type){ - return deviceStateChange(head,type); - }else if("dlt"==type){ - return dltHandle(payload); - } -}; - -this.onRegistered=function (data,status) { - apiTool.log("onRegistered调用"); -} \ No newline at end of file diff --git a/iot-components/iot-DLT645-component/src/main/resources/component.spi b/iot-components/iot-DLT645-component/src/main/resources/component.spi deleted file mode 100644 index c7333bd5..00000000 --- a/iot-components/iot-DLT645-component/src/main/resources/component.spi +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.comp.DLT645.DLT645Component \ No newline at end of file diff --git a/iot-components/iot-DLT645-component/src/main/resources/convert.spi b/iot-components/iot-DLT645-component/src/main/resources/convert.spi deleted file mode 100644 index ab6801cd..00000000 --- a/iot-components/iot-DLT645-component/src/main/resources/convert.spi +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.comp.DLT645.analysis.DLT645Converter \ No newline at end of file diff --git a/iot-components/iot-component-base/.DS_Store b/iot-components/iot-component-base/.DS_Store deleted file mode 100755 index 5008ddfc..00000000 Binary files a/iot-components/iot-component-base/.DS_Store and /dev/null differ diff --git a/iot-components/iot-component-base/pom.xml b/iot-components/iot-component-base/pom.xml deleted file mode 100755 index 02008b56..00000000 --- a/iot-components/iot-component-base/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - iot-components - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-component-base - - - - - cc.iotkit - iot-component-converter - - - - - org.springframework - spring-context - - - - org.projectlombok - lombok - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/AbstractDeviceComponent.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/AbstractDeviceComponent.java deleted file mode 100755 index 07559f25..00000000 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/AbstractDeviceComponent.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp; - -import cc.iotkit.comp.model.AuthInfo; -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.comp.model.RegisterInfo; -import cc.iotkit.converter.IConverter; -import lombok.Data; - -import java.util.UUID; - -@Data -public abstract class AbstractDeviceComponent implements IDeviceComponent { - - protected IMessageHandler handler; - - protected IConverter converter; - - protected CompConfig config; - - protected String script; - - protected String id; - - @Override - public void create(CompConfig config) { - this.config = config; - this.id = UUID.randomUUID().toString(); - } - - @Override - public void onDeviceRegister(RegisterInfo info) { - } - - @Override - public void onDeviceAuth(AuthInfo authInfo) { - } - - @Override - public void onDeviceStateChange(DeviceState state) { - } - - @Override - public CompConfig getConfig() { - return config; - } - - @Override - public void putScriptEnv(String key, Object value) { - } -} diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/CompConfig.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/CompConfig.java deleted file mode 100755 index 449ab2c9..00000000 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/CompConfig.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class CompConfig { - - private long cmdTimeout; - - private String other; - -} diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IComponent.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IComponent.java deleted file mode 100755 index 5b0a4450..00000000 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IComponent.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp; - -public interface IComponent { - - String getId(); - - void create(CompConfig config); - - void start(); - - void stop(); - - void destroy(); - - CompConfig getConfig(); - - void setScript(String script); - - String getScript(); - - /** - * 添加脚本环境变量 - */ - void putScriptEnv(String key, Object value); -} diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IDeviceComponent.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IDeviceComponent.java deleted file mode 100755 index ca7c960f..00000000 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IDeviceComponent.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp; - -import cc.iotkit.comp.model.AuthInfo; -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.comp.model.RegisterInfo; -import cc.iotkit.converter.DeviceMessage; -import cc.iotkit.converter.IConverter; - -public interface IDeviceComponent extends IComponent { - - void onDeviceAuth(AuthInfo authInfo); - - void onDeviceRegister(RegisterInfo info); - - void onDeviceStateChange(DeviceState state); - - DeviceMessage send(DeviceMessage message); - - void setHandler(IMessageHandler handler); - - void setConverter(IConverter converter); - - IConverter getConverter(); - -} diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IMessageHandler.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IMessageHandler.java deleted file mode 100755 index 5e277e0d..00000000 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/IMessageHandler.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp; - -import cc.iotkit.comp.model.ReceiveResult; - -import java.util.Map; -import java.util.function.Consumer; - -public interface IMessageHandler { - - void onReceive(Map head, String type, String msg); - - void onReceive(Map head, String type, String msg, Consumer onResult); - - /** - * 添加脚本环境变量 - */ - void putScriptEnv(String key, Object value); -} diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/AuthInfo.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/AuthInfo.java deleted file mode 100755 index c5e8a947..00000000 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/AuthInfo.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.model; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.FieldNameConstants; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -@FieldNameConstants -public class AuthInfo { - - private String productKey; - - private String deviceName; - - private String productSecret; - - private String deviceSecret; - -} diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/DeviceState.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/DeviceState.java deleted file mode 100755 index 932c9d1f..00000000 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/DeviceState.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.model; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.FieldNameConstants; -import lombok.extern.slf4j.Slf4j; - -@Data -@Slf4j -@NoArgsConstructor -@AllArgsConstructor -@Builder -@FieldNameConstants -public class DeviceState { - - public static final String STATE_ONLINE = "online"; - public static final String STATE_OFFLINE = "offline"; - - private String productKey; - - private String deviceName; - - private String state; - - private Parent parent; - - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @FieldNameConstants - public static class Parent { - private String productKey; - private String deviceName; - } -} diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/ReceiveResult.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/ReceiveResult.java deleted file mode 100755 index c00b4fb8..00000000 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/ReceiveResult.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class ReceiveResult { - - private String productKey; - - private String deviceName; - - private Object data; - -} diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/RegisterInfo.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/RegisterInfo.java deleted file mode 100755 index c9618a01..00000000 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/model/RegisterInfo.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.model; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.FieldNameConstants; -import lombok.extern.slf4j.Slf4j; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * 注册信息 - */ -@Slf4j -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -@FieldNameConstants -public class RegisterInfo { - - private String productKey; - - private String deviceName; - - private String model; - - private Map tag; - - private List subDevices; - - public RegisterInfo(String productKey, String deviceName, String model) { - this.productKey = productKey; - this.deviceName = deviceName; - this.model = model; - } - - public RegisterInfo(String productKey, String deviceName, String subProductKey, String subDeviceName) { - this.productKey = productKey; - this.deviceName = deviceName; - if (subProductKey != null && subDeviceName != null) { - SubDevice subDevice = new SubDevice(subProductKey, subDeviceName, null, null); - subDevices = new ArrayList<>(); - subDevices.add(subDevice); - } - } - - @Data - @NoArgsConstructor - @AllArgsConstructor - @Builder - @FieldNameConstants - public static class SubDevice { - - private String productKey; - - private String deviceName; - - private String model; - - private Map tag; - } -} \ No newline at end of file diff --git a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/utils/SpringUtils.java b/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/utils/SpringUtils.java deleted file mode 100755 index 9cffd106..00000000 --- a/iot-components/iot-component-base/src/main/java/cc/iotkit/comp/utils/SpringUtils.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.utils; - -import org.springframework.aop.framework.AopContext; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; - -/** - * spring工具类 方便在非spring管理环境中获取bean - */ -//@Component -public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware -{ - /** Spring应用上下文环境 */ - private static ConfigurableListableBeanFactory beanFactory; - - private static ApplicationContext applicationContext; - - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException - { - SpringUtils.beanFactory = beanFactory; - } - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException - { - SpringUtils.applicationContext = applicationContext; - } - - /** - * 获取对象 - * - * @param name - * @return Object 一个以所给名字注册的bean的实例 - * @throws org.springframework.beans.BeansException - * - */ - @SuppressWarnings("unchecked") - public static T getBean(String name) throws BeansException - { - return (T) beanFactory.getBean(name); - } - - /** - * 获取类型为requiredType的对象 - * - * @param clz - * @return - * @throws org.springframework.beans.BeansException - * - */ - public static T getBean(Class clz) throws BeansException - { - return (T) beanFactory.getBean(clz); - } - - /** - * 如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true - * - * @param name - * @return boolean - */ - public static boolean containsBean(String name) - { - return beanFactory.containsBean(name); - } - - /** - * 判断以给定名字注册的bean定义是一个singleton还是一个prototype。 如果与给定名字相应的bean定义没有被找到,将会抛出一个异常(NoSuchBeanDefinitionException) - * - * @param name - * @return boolean - * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException - * - */ - public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException - { - return beanFactory.isSingleton(name); - } - - /** - * @param name - * @return Class 注册对象的类型 - * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException - * - */ - public static Class getType(String name) throws NoSuchBeanDefinitionException - { - return beanFactory.getType(name); - } - - /** - * 如果给定的bean名字在bean定义中有别名,则返回这些别名 - * - * @param name - * @return - * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException - * - */ - public static String[] getAliases(String name) throws NoSuchBeanDefinitionException - { - return beanFactory.getAliases(name); - } - - /** - * 获取aop代理对象 - * - * @param invoker - * @return - */ - @SuppressWarnings("unchecked") - public static T getAopProxy(T invoker) - { - return (T) AopContext.currentProxy(); - } - - /** - * 获取当前的环境配置,无配置返回null - * - * @return 当前的环境配置 - */ - public static String[] getActiveProfiles() - { - return applicationContext.getEnvironment().getActiveProfiles(); - } - -} diff --git a/iot-components/iot-component-converter/.DS_Store b/iot-components/iot-component-converter/.DS_Store deleted file mode 100755 index 5008ddfc..00000000 Binary files a/iot-components/iot-component-converter/.DS_Store and /dev/null differ diff --git a/iot-components/iot-component-converter/pom.xml b/iot-components/iot-component-converter/pom.xml deleted file mode 100755 index 34fbfe5d..00000000 --- a/iot-components/iot-component-converter/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - iot-components - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-component-converter - - - - - cc.iotkit - iot-common-model - - - - cc.iotkit - iot-script-engine - - - - - - org.slf4j - slf4j-api - - - - commons-beanutils - commons-beanutils - - - - org.projectlombok - lombok - - - - - org.graalvm.sdk - graal-sdk - - - - org.graalvm.js - js - - - org.graalvm.js - js-scriptengine - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/Device.java b/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/Device.java deleted file mode 100755 index 7f817cca..00000000 --- a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/Device.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.converter; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.HashMap; -import java.util.Map; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Device { - - private String deviceId; - - private String model; - - private Map property = new HashMap<>(); - - private Map tag = new HashMap<>(); - - /** - * 是否透传 - */ - private Boolean transparent; - -} diff --git a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/DeviceMessage.java b/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/DeviceMessage.java deleted file mode 100755 index 60da3e1d..00000000 --- a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/DeviceMessage.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.converter; - - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class DeviceMessage { - - private String productKey; - - private String deviceName; - - private String mid; - - private Object content; - -} diff --git a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/IConverter.java b/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/IConverter.java deleted file mode 100755 index dd6b4e1c..00000000 --- a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/IConverter.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.converter; - -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.model.device.message.ThingModelMessage; - -public interface IConverter { - - void setScript(String script); - - ThingModelMessage decode(DeviceMessage msg); - - DeviceMessage encode(ThingService service, Device device); - - void putScriptEnv(String key, Object value); -} diff --git a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/JavaScriptConverter.java b/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/JavaScriptConverter.java deleted file mode 100644 index 833e4de9..00000000 --- a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/JavaScriptConverter.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.converter; - -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.script.IScriptEngine; -import cc.iotkit.script.ScriptEngineFactory; -import com.fasterxml.jackson.core.type.TypeReference; -import lombok.Data; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Data -public class JavaScriptConverter implements IConverter { - - private IScriptEngine scriptEngine = ScriptEngineFactory.getScriptEngine("js"); - - @SneakyThrows - public void setScript(String script) { - scriptEngine.setScript(script); - } - - @SneakyThrows - public ThingModelMessage decode(DeviceMessage msg) { - return scriptEngine.invokeMethod(new TypeReference<>() { - }, "decode", msg); - } - - @SneakyThrows - @Override - public DeviceMessage encode(ThingService service, Device device) { - return scriptEngine.invokeMethod(new TypeReference<>() { - }, "encode", service, device); - } - - @Override - public void putScriptEnv(String key, Object value) { - scriptEngine.putScriptEnv(key, value); - } -} diff --git a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/ScriptConvertFactory.java b/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/ScriptConvertFactory.java deleted file mode 100644 index 8a2bc4c8..00000000 --- a/iot-components/iot-component-converter/src/main/java/cc/iotkit/converter/ScriptConvertFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -package cc.iotkit.converter; - -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.model.device.message.ThingModelMessage; - -public class ScriptConvertFactory { - - public static IConverter getCovert(String type) { - if (type == null) { - type = "js"; - } - switch (type) { - case "python": - case "lua": - return new IConverter() { - @Override - public void setScript(String script) { - - } - - @Override - public ThingModelMessage decode(DeviceMessage msg) { - return null; - } - - @Override - public DeviceMessage encode(ThingService service, Device device) { - return null; - } - - @Override - public void putScriptEnv(String key, Object value) { - - } - }; - case "js": - default: - return new JavaScriptConverter(); - } - } -} diff --git a/iot-components/iot-component-server/.DS_Store b/iot-components/iot-component-server/.DS_Store deleted file mode 100755 index 5008ddfc..00000000 Binary files a/iot-components/iot-component-server/.DS_Store and /dev/null differ diff --git a/iot-components/iot-component-server/pom.xml b/iot-components/iot-component-server/pom.xml deleted file mode 100755 index 1a529dec..00000000 --- a/iot-components/iot-component-server/pom.xml +++ /dev/null @@ -1,122 +0,0 @@ - - - - iot-components - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-component-server - - - - - cc.iotkit - iot-common-core - - - - cc.iotkit - iot-component-converter - - - - cc.iotkit - iot-common-model - - - - cc.iotkit - iot-component-base - - - - cc.iotkit - iot-message-core - - - - cc.iotkit - iot-data-service - - - - cc.iotkit - iot-temporal-service - - - - cc.iotkit - iot-data-serviceImpl-cache - - - - cc.iotkit - iot-script-engine - - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework - spring-context - - - - org.springframework.data - spring-data-redis - - - redis.clients - jedis - - - - org.slf4j - slf4j-api - - - - io.vertx - vertx-web-client - - - - commons-io - commons-io - - - - org.luaj - luaj-jse - - - - org.projectlombok - lombok - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - - - - - - \ No newline at end of file diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ApiTool.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ApiTool.java deleted file mode 100755 index 3fa128eb..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ApiTool.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comps; - -import cc.iotkit.common.constant.Constants; -import io.vertx.core.MultiMap; -import io.vertx.core.Vertx; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.http.HttpMethod; -import io.vertx.ext.web.client.HttpRequest; -import io.vertx.ext.web.client.HttpResponse; -import io.vertx.ext.web.client.WebClient; -import io.vertx.ext.web.client.WebClientOptions; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -/** - * 平台API调用工具类 - */ -@Slf4j -@Deprecated -public class ApiTool { - - private final Vertx vertx; - private final WebClient client; - - private String host; - private int port; - private int timeout; - - public ApiTool() { - if (Vertx.currentContext() == null) { - vertx = Vertx.vertx(); - } else { - vertx = Vertx.currentContext().owner(); - } - - WebClientOptions options = new WebClientOptions() - .setUserAgent("component-api-tool"); - options.setKeepAlive(false); - client = WebClient.create(vertx, options); - } - - public void config(String host, int port, int timeout) { - this.host = host; - this.port = port; - this.timeout = timeout; - } - - private String getDevicePath(String path) { - return Paths.get(Constants.API_DEVICE.BASE, path).toString(); - } - - private String getSpacePath(String path) { - return Paths.get(Constants.API_SPACE.BASE, path).toString(); - } - - /** - * 获取用户空间中设备列表 - */ - public ApiResponse getSpaceDevices(String token) { - HttpRequest request = client - .get(port, host, getSpacePath(Constants.API_SPACE.SPACE_DEVICES - .replace("{spaceId}", "all"))); - return send(token, HttpMethod.GET, request, new HashMap<>()); - } - - /** - * 获取空间设备详情 - */ - public ApiResponse getSpaceDeviceDetail(String token, String deviceId) { - HttpRequest request = client - .get(port, host, getSpacePath(Constants.API_SPACE.GET_DEVICE - .replace("{deviceId}", deviceId))); - return send(token, HttpMethod.GET, request, new HashMap<>()); - } - - /** - * 获取用户的设备列表 - */ - public ApiResponse getDevices(String token) { - HttpRequest request = client - .post(port, host, getDevicePath(Constants.API_DEVICE.LIST - .replace("{size}", "1000") - .replace("{page}", "1"))); - return send(token, HttpMethod.POST, request, new HashMap<>()); - } - - /** - * 设置第三方平台的openUid - */ - public ApiResponse setOpenUid(String token, String deviceId, String platform, String openUid) { - HttpRequest request = client - .post(port, host, getSpacePath(Constants.API_SPACE.SET_OPEN_UID)); - Map map = new HashMap<>(); - map.put("deviceId", deviceId); - map.put("platform", platform); - map.put("openUid", openUid); - return send(token, HttpMethod.POST, request, map, false); - } - - /** - * 获取设备详情 - */ - public ApiResponse getDeviceDetail(String token, String deviceId) { - HttpRequest request = client - .get(port, host, getDevicePath(Constants.API_DEVICE.DETAIL - .replace("{deviceId}", deviceId))); - return send(token, HttpMethod.GET, request, new HashMap<>()); - } - - /** - * 设置属性 - */ - public ApiResponse setProperties(String token, String deviceId, Map properties) { - HttpRequest request = client - .post(port, host, getDevicePath(Constants.API_DEVICE.SET_PROPERTIES - .replace("{deviceId}", deviceId))); - return send(token, HttpMethod.POST, request, properties); - } - - /** - * 调用服务 - */ - public ApiResponse invokeService(String token, String deviceId, String service, Map params) { - HttpRequest request = client - .post(port, host, getDevicePath(Constants.API_DEVICE.INVOKE_SERVICE - .replace("{deviceId}", deviceId) - .replace("{service}", service))); - return send(token, HttpMethod.POST, request, params); - } - - private ApiResponse send(String token, HttpMethod method, - HttpRequest request, - Map params) { - return send(token, method, request, params, true); - } - - private ApiResponse send(String token, HttpMethod method, - HttpRequest request, - Map params, - boolean isJson - ) { - request = request - .timeout(timeout) - .putHeader("wrap-response", "json") - .putHeader("token", token); - - AtomicReference apiResponse = new AtomicReference<>( - new ApiResponse(500, "", null, System.currentTimeMillis())); - try { - //转为同步模式便于提供给js调用 - CountDownLatch wait = new CountDownLatch(1); - - if (method == HttpMethod.POST && isJson) { - request.sendJson(params) - .onSuccess((response) -> onSendSuccess(apiResponse, wait, response)) - .onFailure((err) -> onSendFail(wait, err)); - } else if (method == HttpMethod.POST) { - //添加表单参数 - MultiMap multiMap = MultiMap.caseInsensitiveMultiMap(); - params.forEach((k, v) -> multiMap.add(k, v.toString())); - request.sendForm(multiMap) - .onSuccess((response) -> onSendSuccess(apiResponse, wait, response)) - .onFailure((err) -> onSendFail(wait, err)); - } else { - request.send() - .onSuccess((response) -> onSendSuccess(apiResponse, wait, response)) - .onFailure((err) -> onSendFail(wait, err)); - } - - if (wait.await(timeout, TimeUnit.MILLISECONDS)) { - return apiResponse.get(); - } else { - apiResponse.get().setStatus(500); - apiResponse.get().setMessage("request timeout"); - } - } catch (Throwable e) { - apiResponse.get().setStatus(500); - apiResponse.get().setMessage(e.getMessage()); - log.error("send error", e); - } - return apiResponse.get(); - } - - private void onSendFail(CountDownLatch wait, Throwable err) { - log.error("send failed", err); - wait.countDown(); - } - - private void onSendSuccess(AtomicReference apiResponse, CountDownLatch wait, HttpResponse response) { - log.info("send succeed,response:{}", response.bodyAsString()); - apiResponse.set(response.bodyAsJson(ApiResponse.class)); - wait.countDown(); - } - - public void log(String msg) { - log.info(msg); - } - - @Data - @NoArgsConstructor - @AllArgsConstructor - public static class ApiResponse { - private int status; - private String message; - private Object data; - private long timestamp; - } -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/BizComponentManager.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/BizComponentManager.java deleted file mode 100755 index 73be5465..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/BizComponentManager.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comps; - - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.ComponentClassLoader; -import cc.iotkit.comp.CompConfig; -import cc.iotkit.comp.IComponent; -import cc.iotkit.comps.config.ComponentConfig; -import cc.iotkit.comps.service.DeviceBehaviourService; -import cc.iotkit.data.manager.IProtocolComponentData; -import cc.iotkit.model.protocol.ProtocolComponent; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.FileUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Slf4j -@Component -public class BizComponentManager { - - private final Map components = new HashMap<>(); - private final Map states = new HashMap<>(); - - @Autowired - private ComponentConfig componentConfig; - @Autowired - private IProtocolComponentData protocolComponentData; - @Autowired - private DeviceBehaviourService deviceBehaviourService; - - @PostConstruct - public void init() { - try { - List componentList = protocolComponentData - .findByStateAndType(ProtocolComponent.STATE_RUNNING, ProtocolComponent.TYPE_BIZ); - for (ProtocolComponent component : componentList) { - register(component); - start(component.getId()); - } - } catch (Throwable e) { - log.error("init protocol components error", e); - } - } - - public void register(ProtocolComponent component) { - String id = component.getId(); - if (components.containsKey(id)) { - return; - } - - Path path = componentConfig.getComponentFilePath(id); - File file = path.resolve(component.getJarFile()).toAbsolutePath().toFile(); - if (!file.exists()) { - throw new BizException(ErrCode.FILE_NOT_FOUND); - } - - IComponent componentInstance; - try { - componentInstance = ComponentClassLoader.getComponent(component.getId(), file); - } catch (Throwable e) { - ComponentClassLoader.closeClassLoader(component.getId()); - throw new BizException(ErrCode.GET_COMPONENT_INSTANCE_ERROR,e); - } - try { - String componentScript = FileUtils.readFileToString(path. - resolve(ProtocolComponent.SCRIPT_FILE_NAME).toFile(), "UTF-8"); - componentInstance.setScript(componentScript); - componentInstance.putScriptEnv("deviceBehaviour", deviceBehaviourService); - componentInstance.putScriptEnv("apiTool", new ApiTool()); - } catch (IOException e) { - throw new BizException(ErrCode.GET_COMPONENT_SCRIPT_ERROR,e); - } - componentInstance.create(new CompConfig(300, component.getConfig())); - - register(id, componentInstance); - } - - public void register(String id, IComponent component) { - components.put(id, component); - states.put(id, false); - } - - public void deRegister(String id) { - IComponent component = components.remove(id); - states.remove(id); - if (component == null) { - return; - } - component.stop(); - component.destroy(); - } - - public void start(String id) { - IComponent component = components.get(id); - if (component == null) { - return; - } - component.start(); - states.put(id, true); - } - - public void stop(String id) { - IComponent component = components.get(id); - if (component == null) { - return; - } - component.stop(); - states.put(id, false); - } - - public boolean isRunning(String id) { - return states.containsKey(id) && states.get(id); - } - -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ComponentManager.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ComponentManager.java deleted file mode 100755 index 15f9f26f..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/ComponentManager.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comps; - - -import cc.iotkit.common.utils.ComponentClassLoader; -import cc.iotkit.model.protocol.ProtocolComponent; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Slf4j -@Component -public class ComponentManager { - - @Autowired - private BizComponentManager bizComponentManager; - - @Autowired - private DeviceComponentManager deviceComponentManager; - - - public void register(ProtocolComponent component) { - String type = component.getType(); - if (ProtocolComponent.TYPE_BIZ.equals(type)) { - bizComponentManager.register(component); - } else if (ProtocolComponent.TYPE_DEVICE.equals(type)) { - deviceComponentManager.register(component); - } - } - - public void deRegister(String id) { - bizComponentManager.deRegister(id); - deviceComponentManager.deRegister(id); - // 手动卸载jar应用,避免重新上传jar被占用 - ComponentClassLoader.closeClassLoader(id); - } - - public void start(String id) { - bizComponentManager.start(id); - deviceComponentManager.start(id); - } - - public void stop(String id) { - bizComponentManager.stop(id); - deviceComponentManager.stop(id); - } - - public boolean isRunning(String id) { - return bizComponentManager.isRunning(id) || deviceComponentManager.isRunning(id); - } - -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceComponentManager.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceComponentManager.java deleted file mode 100755 index 3a28099b..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceComponentManager.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comps; - - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.common.utils.ComponentClassLoader; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.CompConfig; -import cc.iotkit.comp.IComponent; -import cc.iotkit.comp.IDeviceComponent; -import cc.iotkit.comps.config.CacheKey; -import cc.iotkit.comps.config.ComponentConfig; -import cc.iotkit.comps.service.DeviceBehaviourService; -import cc.iotkit.converter.Device; -import cc.iotkit.converter.DeviceMessage; -import cc.iotkit.converter.IConverter; -import cc.iotkit.converter.ScriptConvertFactory; -import cc.iotkit.data.manager.IDeviceInfoData; -import cc.iotkit.data.manager.IProductData; -import cc.iotkit.data.manager.IProtocolComponentData; -import cc.iotkit.data.manager.IProtocolConverterData; -import cc.iotkit.model.device.DeviceInfo; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.model.product.Product; -import cc.iotkit.model.protocol.ProtocolComponent; -import cc.iotkit.model.protocol.ProtocolConverter; -import cc.iotkit.script.IScriptEngine; -import cc.iotkit.script.ScriptEngineFactory; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.FileUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.TimeUnit; - -@Slf4j -@Component -public class DeviceComponentManager { - - private final Map components = new HashMap<>(); - private final Map states = new HashMap<>(); - - @Autowired - private DeviceBehaviourService deviceBehaviourService; - @Autowired - private StringRedisTemplate redisTemplate; - @Autowired - private ComponentConfig componentConfig; - @Autowired - private IProtocolComponentData protocolComponentData; - @Autowired - @Qualifier("productDataCache") - IProductData productData; - @Autowired - @Qualifier("deviceInfoDataCache") - private IDeviceInfoData deviceInfoData; - @Autowired - private DeviceRouter deviceRouter; - - @Autowired - private IProtocolConverterData protocolConverterData; - - private IScriptEngine scriptEngine; - -// @PostConstruct - public void init() { - List componentList = protocolComponentData.findByStateAndType( - ProtocolComponent.STATE_RUNNING, ProtocolComponent.TYPE_DEVICE); - for (ProtocolComponent component : componentList) { - try { - register(component); - start(component.getId()); - } catch (Throwable e) { - log.error("init protocol components error", e); - } - } - } - - public void register(ProtocolComponent component) { - String id = component.getId(); - if (components.containsKey(id)) { - return; - } - - Path path = componentConfig.getComponentFilePath(id); - File file = path.resolve(component.getJarFile()).toAbsolutePath().toFile(); - IDeviceComponent componentInstance; - try { - componentInstance = ComponentClassLoader.getComponent(component.getId(), file); - } catch (Throwable e) { - throw new BizException(ErrCode.GET_COMPONENT_INSTANCE_ERROR, e); - } - componentInstance.create(new CompConfig(300, component.getConfig())); - - try { - if(ProtocolComponent.CONVER_TYPE_STATIC.equals(component.getConverType())){ - IConverter converterInstance; - try { - converterInstance=ComponentClassLoader.getConverter(component.getId()); - } catch (Throwable e) { - throw new BizException(ErrCode.GET_SPI_CONVERT_ERROR, e); - } - componentInstance.setConverter(converterInstance); - }else{ - setScriptConvert(component, componentInstance); - } - scriptEngine = ScriptEngineFactory.getScriptEngine(component.getScriptTyp()); - - String componentScript = FileUtils.readFileToString(path. - resolve(ProtocolComponent.SCRIPT_FILE_NAME).toFile(), StandardCharsets.UTF_8); - componentInstance.setScript(componentScript); - register(id, componentInstance); - } catch (IOException e) { - throw new BizException(ErrCode.GET_COMPONENT_SCRIPT_ERROR, e); - } - } - - private void setScriptConvert(ProtocolComponent component, IDeviceComponent componentInstance) throws IOException { - ProtocolConverter protocolConvert = protocolConverterData.findById(component.getConverter()); - - IConverter scriptConverter = ScriptConvertFactory.getCovert(protocolConvert.getTyp()); - // 从文件方式内容 - Path converterPath = componentConfig.getConverterFilePath(component.getConverter()); - String converterScript = FileUtils.readFileToString(converterPath. - resolve(ProtocolConverter.SCRIPT_FILE_NAME).toFile(), StandardCharsets.UTF_8); - -// scriptConverter.setScript(protocolConvert.getScript()); // 从数据库加载,以后可以加版本号 - scriptConverter.setScript(converterScript); - scriptConverter.putScriptEnv("component", componentInstance); - componentInstance.setConverter(scriptConverter); - } - - public void register(String id, IDeviceComponent component) { - components.put(id, component); - states.put(id, false); - } - - public void deRegister(String id) { - IDeviceComponent component = components.remove(id); - states.remove(id); - if (component == null) { - return; - } - component.stop(); - component.destroy(); - } - - public void start(String id) { - IDeviceComponent component = components.get(id); - if (component == null) { - return; - } - - DeviceMessageHandler messageHandler = new DeviceMessageHandler( - this, component, - scriptEngine, - component.getScript(), component.getConverter(), - deviceBehaviourService, deviceRouter); - messageHandler.putScriptEnv("apiTool", new ApiTool()); - messageHandler.putScriptEnv("deviceBehaviour", deviceBehaviourService); - messageHandler.putScriptEnv("component", component); - - component.setHandler(messageHandler); - component.start(); - states.put(id, true); - } - - public void stop(String id) { - IDeviceComponent component = components.get(id); - if (component == null) { - return; - } - component.stop(); - states.put(id, false); - } - - public boolean isRunning(String id) { - return states.containsKey(id) && states.get(id); - } - - public void send(ThingService service) { - log.info("start exec device service:{}", JsonUtils.toJsonString(service)); - if (components.size() == 0) { - throw new BizException(ErrCode.COMPONENT_NOT_FOUND); - } - - 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()); - linkPk = parent.getProductKey(); - linkDn = parent.getDeviceName(); - } - - IComponent component = deviceRouter.getRouter(linkPk, linkDn); - if (!(component instanceof IDeviceComponent)) { - throw new BizException(ErrCode.SEND_DESTINATION_NOT_FOUND); - } - IDeviceComponent deviceComponent = (IDeviceComponent) component; - - //构建必要的设备信息 - Map tag = new HashMap<>(); - Map tagMap = deviceInfo.getTag(); - if(Objects.nonNull(tagMap) && !tagMap.isEmpty()){ - tagMap.forEach((k, v) -> tag.put(k, v.getValue())); - } - - Device device = new Device(deviceInfo.getDeviceId(), - deviceInfo.getModel(), - deviceInfo.getProperty(), - tag, - product.isTransparent()); - - //对下发消息进行编码转换 - DeviceMessage message = deviceComponent.getConverter().encode(service, device); - if (message == null) { - throw new BizException(ErrCode.MSG_CONVERT_ERROR); - } - - String sendMid = message.getMid(); - long timeout = deviceComponent.getConfig().getCmdTimeout(); - - //保存设备端mid与平台mid对应关系 - saveMidMapping(message, timeout, service.getMid()); - //发送消息给设备 - message = deviceComponent.send(message); - - //mid发生改变 - if (!sendMid.equals(message.getMid())) { - //重新保存消息id映射 - saveMidMapping(message, timeout, service.getMid()); - } - - //产生下发消息 - ThingModelMessage thingModelMessage = ThingModelMessage.builder() - .mid(service.getMid()) - .productKey(service.getProductKey()) - .deviceName(service.getDeviceName()) - .identifier(service.getIdentifier()) - .type(service.getType()) - .data(service.getParams()) - .build(); - deviceBehaviourService.reportMessage(thingModelMessage); - } - - /** - * 保存设备端mid与平台mid对应关系 - */ - private void saveMidMapping(DeviceMessage message, long cmdTimeout, String serviceMid) { - redisTemplate.opsForValue().set( - CacheKey.getKeyCmdMid(message.getDeviceName(), message.getMid()), - serviceMid, cmdTimeout, TimeUnit.SECONDS); - } - - public String getPlatformMid(String deviceName, String mid) { - return redisTemplate.opsForValue().get(CacheKey.getKeyCmdMid(deviceName, mid)); - } - -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java deleted file mode 100755 index 3a1d9b2a..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceMessageHandler.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comps; - -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.common.utils.UniqueIdUtil; -import cc.iotkit.comp.IDeviceComponent; -import cc.iotkit.comp.IMessageHandler; -import cc.iotkit.comp.model.AuthInfo; -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.comp.model.ReceiveResult; -import cc.iotkit.comp.model.RegisterInfo; -import cc.iotkit.comps.service.DeviceBehaviourService; -import cc.iotkit.converter.DeviceMessage; -import cc.iotkit.converter.IConverter; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.script.IScriptEngine; -import com.fasterxml.jackson.core.type.TypeReference; -import lombok.Data; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; - -import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; - -@Slf4j -@Data -public class DeviceMessageHandler implements IMessageHandler { - - - private final IScriptEngine scriptEngine; - - private final IConverter converter; - - private final DeviceBehaviourService deviceBehaviourService; - - private final DeviceComponentManager deviceComponentManager; - - private final IDeviceComponent component; - - private final DeviceRouter deviceRouter; - - private final ExecutorService executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, - 60L, TimeUnit.SECONDS, - new LinkedBlockingQueue<>()); - - @SneakyThrows - public DeviceMessageHandler(DeviceComponentManager deviceComponentManager, - IDeviceComponent component, - IScriptEngine scriptEngine, - String script, IConverter converter, - DeviceBehaviourService deviceBehaviourService, - DeviceRouter deviceRouter - ) { - this.deviceComponentManager = deviceComponentManager; - this.component = component; - this.converter = converter; - this.deviceBehaviourService = deviceBehaviourService; - this.deviceRouter = deviceRouter; - this.scriptEngine = scriptEngine; - scriptEngine.putScriptEnv("component", component); - scriptEngine.setScript(script); - } - - @Override - public void onReceive(Map head, String type, String msg) { - onReceive(head, type, msg, (r) -> { - }); - } - - @Override - public void onReceive(Map head, String type, String msg, Consumer onResult) { - executorService.submit(() -> { - try { - Map rst = scriptEngine.invokeMethod(new TypeReference<>() { - }, "onReceive", head, type, msg); - Object objType = rst.get("type"); - if (objType == null) { - onResult.accept(null); - return; - } - //取脚本执行后返回的数据 - Object objData = rst.get("data"); - if (!(objData instanceof Map)) { - onResult.accept(null); - return; - } - Map data = (Map) objData; - - //获取动作数据 - Action action = MessageParser.parse(new Action(), rst.get("action")); - - switch (objType.toString()) { - case "register": - //注册数据 - RegisterInfo regInfo = MessageParser.parseRegisterInfo(data); - if (regInfo == null) { - onResult.accept(null); - return; - } - doRegister(regInfo); - doAction(action); - onResult.accept(new ReceiveResult(regInfo.getProductKey(), regInfo.getDeviceName(), regInfo)); - return; - case "auth": - //设备认证 - AuthInfo authInfo = MessageParser.parse(new AuthInfo(), data); - doAuth(authInfo); - doAction(action); - onResult.accept(new ReceiveResult(authInfo.getProductKey(), authInfo.getDeviceName(), authInfo)); - return; - case "state": - //设备状态变更 - DeviceState state = MessageParser.parseDeviceState(data); - doStateChange(state); - doAction(action); - onResult.accept(new ReceiveResult(state.getProductKey(), state.getDeviceName(), state)); - return; - case "report": - //上报数据 - DeviceMessage message = MessageParser.parse(new DeviceMessage(), data); - doReport(message); - doAction(action); - onResult.accept(new ReceiveResult(message.getProductKey(), message.getDeviceName(), message)); - return; - case "ota": - //上报数据 - DeviceMessage otaMessage = MessageParser.parse(new DeviceMessage(), data); - doOta(otaMessage); - doAction(action); - onResult.accept(new ReceiveResult(otaMessage.getProductKey(), otaMessage.getDeviceName(), otaMessage)); - return; - } - - } catch (Throwable e) { - log.error("receive component message error", e); - } - onResult.accept(null); - }); - } - - private void doRegister(RegisterInfo reg) { - try { - deviceBehaviourService.register(reg); - } catch (Throwable e) { - log.error("register error", e); - } finally { - scriptEngine.invokeMethod("onRegistered", reg, "false"); - } - } - - private void doAuth(AuthInfo auth) { - try { - deviceBehaviourService.deviceAuth(auth.getProductKey(), - auth.getDeviceName(), - auth.getProductSecret(), - auth.getDeviceSecret()); - } catch (Throwable e) { - log.error("device auth error", e); - } finally { - scriptEngine.invokeMethod("onAuthed", auth, "false"); - } - } - - private void doStateChange(DeviceState state) { - try { - String pk = state.getProductKey(); - String dn = state.getDeviceName(); - boolean isOnline = DeviceState.STATE_ONLINE.equals(state.getState()); - if (isOnline) { - deviceRouter.putRouter(pk, dn, component); - } else { - deviceRouter.removeRouter(pk, dn); - } - component.onDeviceStateChange(state); - deviceBehaviourService.deviceStateChange(pk, dn, isOnline); - } catch (Throwable e) { - log.error("device state change error", e); - } - } - - private void doOta(DeviceMessage message) { - ThingModelMessage thingModelMessage = converter.decode(message); - deviceBehaviourService.deviceOta(thingModelMessage); - } - - private void doReport(DeviceMessage message) { - ThingModelMessage thingModelMessage = converter.decode(message); - - //服务回复需要重新对应mid - if (thingModelMessage.getIdentifier().endsWith("_reply")) { - String platformMid = deviceComponentManager.getPlatformMid(thingModelMessage.getDeviceName(), message.getMid()); - if (platformMid == null) { - platformMid = UniqueIdUtil.newRequestId(); - } - thingModelMessage.setMid(platformMid); - } else { - //其它消息重新生成唯一MID - thingModelMessage.setMid(UniqueIdUtil.newRequestId()); - } - - deviceBehaviourService.reportMessage(thingModelMessage); - } - - private void doAction(Action action) { - if (action == null) { - return; - } - try { - if (Action.TYPE_ACK.equals(action.getType())) { - DeviceMessage deviceMessage = JsonUtils.parseObject(action.getContent(), DeviceMessage.class); - this.getComponent().send(deviceMessage); - } - } catch (Throwable e) { - log.error("do action error", e); - } - } - - @Override - public void putScriptEnv(String key, Object value) { - - scriptEngine.putScriptEnv(key, value); - } - - @Data - public static class Action { - public static final String TYPE_ACK = "ack"; - - private String type; - private String content; - } - -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceRouter.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceRouter.java deleted file mode 100755 index 2050443b..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceRouter.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comps; - -import cc.iotkit.comp.IComponent; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.stereotype.Component; - -import java.util.HashMap; -import java.util.Map; - -/** - * 设备路由 - */ -@Component -public class DeviceRouter { - - private static final String DEVICE_ROUTER = "str:device:router:%s:%s"; - - private static final Map components = new HashMap<>(); - - @Autowired - private StringRedisTemplate redisTemplate; - - private String getDeviceRouter(String productKey, String deviceName) { - return String.format(DEVICE_ROUTER, productKey, deviceName); - } - - public void putRouter(String productKey, String deviceName, IComponent component) { - String comId = component.getId(); - components.put(comId, component); - redisTemplate.opsForValue().set(getDeviceRouter(productKey, deviceName), component.getId()); - } - - public void removeRouter(String productKey, String deviceName) { - redisTemplate.delete(getDeviceRouter(productKey, deviceName)); - } - - public IComponent getRouter(String productKey, String deviceName) { - String comId = redisTemplate.opsForValue().get(getDeviceRouter(productKey, deviceName)); - if (StringUtils.isBlank(comId)) { - return null; - } - return components.get(comId); - } - -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/MessageInfo.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/MessageInfo.java deleted file mode 100644 index 8577605d..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/MessageInfo.java +++ /dev/null @@ -1,16 +0,0 @@ -package cc.iotkit.comps; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.Map; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class MessageInfo { - private Map head; - private String type; - private String msg; -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/MessageParser.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/MessageParser.java deleted file mode 100644 index 632a9815..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/MessageParser.java +++ /dev/null @@ -1,62 +0,0 @@ -package cc.iotkit.comps; - -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.comp.model.RegisterInfo; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.beanutils.BeanUtils; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -@Slf4j -public class MessageParser { - - public static RegisterInfo parseRegisterInfo(Map value) { - RegisterInfo registerInfo = new RegisterInfo(); - try { - List subDevices = new ArrayList<>(); - Object objSubDevices = value.get(RegisterInfo.Fields.subDevices); - if (objSubDevices instanceof List) { - for (Object item : (List) objSubDevices) { - subDevices.add(parse(new RegisterInfo.SubDevice(), item)); - } - } - registerInfo.setSubDevices(subDevices); - return RegisterInfo.builder() - .deviceName(Objects.toString(value.get(RegisterInfo.Fields.deviceName), "")) - .productKey(Objects.toString(value.get(RegisterInfo.Fields.productKey), "")) - .model(Objects.toString(value.get(RegisterInfo.Fields.model), "")) - .subDevices(subDevices) - .build(); - } catch (Throwable e) { - log.error("parse bean from Value error", e); - return null; - } - } - - @SneakyThrows - public static DeviceState parseDeviceState(Map value) { - return DeviceState.builder() - .deviceName(Objects.toString(value.get(DeviceState.Fields.deviceName), "")) - .productKey(Objects.toString(value.get(DeviceState.Fields.productKey), "")) - .state(Objects.toString(value.get(DeviceState.Fields.state), "")) - .parent( - parse(new DeviceState.Parent(), value.get(DeviceState.Fields.parent)) - ) - .build(); - } - - @SneakyThrows - public static T parse(T obj, Object map) { - if (!(map instanceof Map)) { - return null; - } - - BeanUtils.populate(obj, (Map) map); - return obj; - } - -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/config/CacheKey.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/config/CacheKey.java deleted file mode 100755 index 115cfe82..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/config/CacheKey.java +++ /dev/null @@ -1,11 +0,0 @@ -package cc.iotkit.comps.config; - -public class CacheKey { - - private static final String KEY_CMD_MID = "str:cmd:mid:%s:%s"; - - public static String getKeyCmdMid(String deviceName, String downMid) { - return String.format(KEY_CMD_MID, deviceName, downMid); - } - -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/config/ComponentConfig.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/config/ComponentConfig.java deleted file mode 100755 index bb8d5db4..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/config/ComponentConfig.java +++ /dev/null @@ -1,29 +0,0 @@ -package cc.iotkit.comps.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; - -@Configuration -@Data -public class ComponentConfig { - - @Value("${component.dir:./data/components}") - private String componentDir; - - @Value("${converter.dir:./data/converters}") - private String converterDir; - - public Path getComponentFilePath(String comId) { - return Paths.get(componentDir, comId) - .toAbsolutePath().normalize(); - } - - public Path getConverterFilePath(String conId) { - return Paths.get(converterDir, conId) - .toAbsolutePath().normalize(); - } -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java deleted file mode 100755 index 1164e968..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceBehaviourService.java +++ /dev/null @@ -1,303 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comps.service; - -import cc.iotkit.common.constant.Constants; -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.UniqueIdUtil; -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.comp.model.RegisterInfo; -import cc.iotkit.data.manager.IDeviceInfoData; -import cc.iotkit.data.manager.IDeviceOtaDetailData; -import cc.iotkit.data.manager.IProductData; -import cc.iotkit.data.manager.IProductModelData; -import cc.iotkit.model.device.DeviceInfo; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.model.ota.DeviceOtaDetail; -import cc.iotkit.model.product.Product; -import cc.iotkit.model.product.ProductModel; -import cc.iotkit.mq.MqProducer; -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 java.util.HashMap; -import java.util.List; -import java.util.Objects; -import java.util.UUID; - -@Slf4j -@Service -public class DeviceBehaviourService { - - @Autowired - private IProductModelData productModelData; - @Autowired - private IDeviceOtaDetailData deviceOtaDetailData; - - @Autowired - @Qualifier("deviceInfoDataCache") - private IDeviceInfoData deviceInfoData; - @Autowired - private MqProducer producer; - @Autowired - @Qualifier("productDataCache") - private IProductData productData; - - public void register(RegisterInfo info) { - try { - DeviceInfo deviceInfo = register(null, info); - //子设备注册 - List subDevices = info.getSubDevices(); - if (subDevices == null) { - return; - } - for (RegisterInfo.SubDevice subDevice : subDevices) { - register(deviceInfo.getDeviceId(), - new RegisterInfo(subDevice.getProductKey(), - subDevice.getDeviceName(), - subDevice.getModel(), - subDevice.getTag(), null)); - } - } catch (BizException e) { - log.error("register device error", e); - throw e; - } catch (Throwable e) { - log.error("register device error", e); - throw new BizException(ErrCode.DEVICE_REGISTER_ERROR, e); - } - } - - public DeviceInfo register(String parentId, RegisterInfo info) { - String pk = info.getProductKey(); - String dn = info.getDeviceName(); - String model = info.getModel(); - - //子设备注册处理 - if (parentId != null) { - //透传设备:pk为空、model不为空,使用model查询产品 - if (StringUtils.isBlank(pk) && StringUtils.isNotBlank(model)) { - ProductModel productModel = productModelData.findByModel(model); - if (productModel == null) { - throw new BizException(ErrCode.PRODUCT_MODEL_NOT_FOUND); - } - pk = productModel.getProductKey(); - } - } - - Product product = productData.findByProductKey(pk); - if (product == null) { - throw new BizException(ErrCode.PRODUCT_NOT_FOUND); - } - String uid = product.getUid(); - DeviceInfo device = deviceInfoData.findByDeviceName(info.getDeviceName()); - boolean reportMsg = false; - - if (device != null) { - log.info("device already registered"); - device.setModel(model); - } else { - //不存在,注册新设备 - device = new DeviceInfo(); - device.setId(DeviceUtil.newDeviceId(dn)); - device.setParentId(parentId); - device.setUid(uid); - device.setDeviceId(device.getId()); - device.setProductKey(pk); - device.setDeviceName(dn); - device.setModel(model); - //默认离线 - device.setState(new DeviceInfo.State(false, null, null)); - device.setCreateAt(System.currentTimeMillis()); - reportMsg = true; - - - //auth、acl - - } - - //透传设备,默认在线 - if (product.isTransparent()) { - device.setState(new DeviceInfo.State(true, System.currentTimeMillis(), null)); - } - - if (parentId != null) { - //子设备更换网关重新注册更新父级ID - device.setParentId(parentId); - reportMsg = true; - } - deviceInfoData.save(device); - - //新设备或更换网关需要产生注册消息 - if (reportMsg) { - log.info("device registered:{}", JsonUtils.toJsonString(device)); - //新注册设备注册消息 - ThingModelMessage modelMessage = new ThingModelMessage( - UUID.randomUUID().toString(), - UniqueIdUtil.newRequestId(), "", - pk, dn, uid, - ThingModelMessage.TYPE_LIFETIME, "register", - 0, new HashMap<>(), System.currentTimeMillis(), - System.currentTimeMillis() - ); - - reportMessage(modelMessage); - } - - return device; - } - - public void deviceAuth(String productKey, - String deviceName, - String productSecret, - String deviceSecret) { - DeviceInfo deviceInfo = deviceInfoData.findByDeviceName(deviceName); - if (deviceInfo == null) { - throw new BizException(ErrCode.DEVICE_NOT_FOUND); - } - Product product = getProductKey(productKey); - if (!product.getProductSecret().equals(productSecret)) { - throw new BizException(ErrCode.PRODUCT_SECRET_ERROR); - } - - //todo 按产品ProductSecret认证,子设备需要父设备认证后可通过验证 -// Optional optProduct = productRepository.findById(productKey); -// if (!optProduct.isPresent()) { -// throw new BizException("product does not exist"); -// } -// Product product = optProduct.get(); -// if (product.getNodeType()) { -// -// } - - } - - public boolean isOnline(String productKey, - String deviceName) { - DeviceInfo device = deviceInfoData.findByDeviceName(deviceName); - DeviceInfo deviceInfo = deviceInfoData.findByDeviceId(device.getDeviceId()); - return deviceInfo.getState().isOnline(); - } - - public void deviceStateChange(String productKey, - String deviceName, - boolean online) { - DeviceInfo device = deviceInfoData.findByDeviceName(deviceName); - if (device == null) { - log.warn("productKey: {},deviceName:{},online: {}", productKey, deviceName, online); - throw new BizException(ErrCode.DEVICE_NOT_FOUND); - } - deviceStateChange(device, online); - - //父设备ID不为空说明是子设备 - if (device.getParentId() != null) { - return; - } - - //否则为父设备,同步透传子设备状态 - 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 || !online) { - deviceStateChange(subDevice, online); - } - } - } - - private void deviceStateChange(DeviceInfo device, boolean online) { - if (online) { - device.getState().setOnline(true); - device.getState().setOnlineTime(System.currentTimeMillis()); - } else { - device.getState().setOnline(false); - device.getState().setOfflineTime(System.currentTimeMillis()); - } - deviceInfoData.save(device); - - //设备状态变更消息 - ThingModelMessage modelMessage = new ThingModelMessage( - UUID.randomUUID().toString(), - UniqueIdUtil.newRequestId(), "", - device.getProductKey(), device.getDeviceName(), device.getUid(), - ThingModelMessage.TYPE_STATE, - online ? DeviceState.STATE_ONLINE : DeviceState.STATE_OFFLINE, - 0, - new HashMap<>(), System.currentTimeMillis(), - System.currentTimeMillis() - ); - - reportMessage(modelMessage); - } - - public void reportMessage(ThingModelMessage message) { - try { - DeviceInfo device = deviceInfoData.findByDeviceName(message.getDeviceName()); - if (device == null) { - return; - } - message.setId(UUID.randomUUID().toString()); - if (message.getOccurred() == null) { - message.setOccurred(System.currentTimeMillis()); - } - if (message.getTime() == null) { - message.setTime(System.currentTimeMillis()); - } - message.setDeviceId(device.getDeviceId()); - - producer.publish(Constants.THING_MODEL_MESSAGE_TOPIC, message); - - } catch (Throwable e) { - log.error("send thing model message error", e); - } - } - - /** - * 提供给js调用的方法 - */ - public void reportMessage(String jsonMsg) { - ThingModelMessage message = JsonUtils.parseObject(jsonMsg, ThingModelMessage.class); - reportMessage(message); - } - - public void deviceOta(ThingModelMessage message) { - DeviceOtaDetail deviceOtaDetailTemp = JsonUtils.objectToJavaBean(message.getData(), DeviceOtaDetail.class); - if (Objects.isNull(deviceOtaDetailTemp)) { - log.debug("device ota upload data is null deviceId:{}", message.getDeviceId()); - return; - } - deviceOtaDetailTemp.setTaskId(message.getMid()); - deviceOtaDetailTemp.setDeviceId(message.getDeviceId()); - deviceOtaDetailTemp.setDeviceName(message.getDeviceName()); - deviceOtaDetailTemp.setProductKey(message.getProductKey()); - DeviceOtaDetail deviceOtaDetail = deviceOtaDetailData.findOneByCondition(DeviceOtaDetail.builder() - .taskId(message.getMid()) - .productKey(message.getProductKey()) - .deviceName(message.getDeviceName()) - .deviceId(message.getDeviceId()).build()); - if (Objects.nonNull(deviceOtaDetail)) { - deviceOtaDetail.setStep(deviceOtaDetailTemp.getStep()); - } else { - deviceOtaDetail = deviceOtaDetailTemp; - } - deviceOtaDetailData.save(deviceOtaDetail); - } - - public Product getProductKey(String productKey) { - return productData.findByProductKey(productKey); - } -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceConfigConsumer.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceConfigConsumer.java deleted file mode 100755 index d4a0d805..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceConfigConsumer.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comps.service; - -import cc.iotkit.common.constant.Constants; -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comps.DeviceComponentManager; -import cc.iotkit.data.manager.IDeviceConfigData; -import cc.iotkit.model.device.DeviceConfig; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.mq.ConsumerHandler; -import cc.iotkit.mq.MqConsumer; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import java.util.Map; - -/** - * 设备配置服务 - */ -@Slf4j -@Service -public class DeviceConfigConsumer implements ConsumerHandler { - - @Autowired - private MqConsumer configMessageConsumer; - - @Autowired - public DeviceComponentManager deviceComponentManager; - - @Autowired - private IDeviceConfigData deviceConfigData; - - @PostConstruct - public void init() { - configMessageConsumer.consume(Constants.DEVICE_CONFIG_TOPIC, this); - } - - @Override - public void handler(ThingModelMessage msg) { - try { - String identifier = msg.getIdentifier(); - if (ThingModelMessage.ID_CONFIG_GET.equals(identifier)) { - //收到设备获取配置消息,回复配置信息给设备 - 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(); - deviceComponentManager.send(service); - } - } catch (Throwable e) { - log.error("consumer device config msg error", e); - } - } -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceMessageConsumer.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceMessageConsumer.java deleted file mode 100755 index ceefd702..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DeviceMessageConsumer.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comps.service; - -import cc.iotkit.common.constant.Constants; -import cc.iotkit.data.manager.IDeviceInfoData; -import cc.iotkit.model.device.DeviceInfo; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.mq.ConsumerHandler; -import cc.iotkit.mq.MqConsumer; -import cc.iotkit.mq.MqProducer; -import cc.iotkit.temporal.IThingModelMessageData; -import lombok.extern.slf4j.Slf4j; -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 javax.annotation.PostConstruct; - -@Slf4j -@Service -public class DeviceMessageConsumer implements ConsumerHandler { - @Lazy - @Autowired - private IThingModelMessageData thingModelMessageData; - @Autowired - @Qualifier("deviceInfoDataCache") - private IDeviceInfoData deviceInfoData; - @Autowired - private MqConsumer thingModelMessageConsumer; - @Autowired - private MqProducer thingModelMessageMqProducer; - - @PostConstruct - public void init() { - thingModelMessageConsumer.consume(Constants.THING_MODEL_MESSAGE_TOPIC, this); - } - - @Override - public void handler(ThingModelMessage msg) { - try { - String type = msg.getType(); - //重新发布属性入库消息 - if (ThingModelMessage.TYPE_PROPERTY.equals(type) - && "report".equals(msg.getIdentifier())) { - thingModelMessageMqProducer.publish(Constants.DEVICE_PROPERTY_REPORT_TOPIC, msg); - } - if (ThingModelMessage.TYPE_CONFIG.equals(type)) { - //重新发布设备配置消息,用于设备配置下发 - thingModelMessageMqProducer.publish(Constants.DEVICE_CONFIG_TOPIC, msg); - } - - DeviceInfo device = deviceInfoData.findByDeviceId(msg.getDeviceId()); - if (device == null) { - return; - } - msg.setUid(device.getUid()); - - //设备消息入库 - thingModelMessageData.add(msg); - } catch (Throwable e) { - //不能重复消费 - log.error("device message consumer error", e); - } - } - -} diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DevicePropertyConsumer.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DevicePropertyConsumer.java deleted file mode 100755 index 90596012..00000000 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/service/DevicePropertyConsumer.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comps.service; - -import cc.iotkit.common.constant.Constants; -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.device.message.ThingModelMessage; -import cc.iotkit.model.product.ThingModel; -import cc.iotkit.mq.ConsumerHandler; -import cc.iotkit.mq.MqConsumer; -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.Service; - -import javax.annotation.PostConstruct; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * 设备属性消息消费入库 - */ -@Slf4j -@Service -public class DevicePropertyConsumer implements ConsumerHandler { - - @Autowired - private MqConsumer thingModelMessageMqConsumer; - @Autowired - private IDevicePropertyData devicePropertyData; - @Autowired - @Qualifier("deviceInfoDataCache") - private IDeviceInfoData deviceInfoData; - @Autowired - @Qualifier("thingModelDataCache") - private IThingModelData thingModelData; - - @PostConstruct - public void init() { - thingModelMessageMqConsumer.consume(Constants.DEVICE_PROPERTY_REPORT_TOPIC, this); - } - - @Override - public void handler(ThingModelMessage msg) { - 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(); - //删除非属性字段 - properties.forEach((key,val)->{ - if (thingModelProperties.containsKey(key)) { - DevicePropertyCache propertyCache = new DevicePropertyCache(); - propertyCache.setValue(val); - propertyCache.setOccurred(occurred); - addProperties.put(key,propertyCache); - handleLocate(deviceInfo,val,thingModelProperties.get(key)); - } - }); - - //更新设备当前属性 - updateDeviceCurrentProperties(deviceId, addProperties); - - //保存属性记录 - try { - devicePropertyData.addProperties(deviceId, addProperties, occurred); - } catch (Throwable e) { - log.warn("save property data error", e); - } - } - - - private void handleLocate(DeviceInfo deviceInfo,Object data,ThingModel.DataType dataType){ - if("position".equals(dataType.getType())){//如果是定位属性需要做一些处理 - Object specs = dataType.getSpecs(); - String locateType=""; - if (specs instanceof Map) { - Object objlocateType = ((Map) specs).get("locateType");//定位方式 - if (objlocateType != null) { - locateType = objlocateType.toString(); - } - if(StringUtils.isNotBlank(locateType)){ - 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-components/iot-component-tcp/pom.xml b/iot-components/iot-component-tcp/pom.xml deleted file mode 100644 index d23949ce..00000000 --- a/iot-components/iot-component-tcp/pom.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - - iot-components - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-component-tcp - - - - - cc.iotkit - iot-common-core - - - - cc.iotkit - iot-component-base - - - - cc.iotkit - iot-data-service - - - - cc.iotkit - iot-script-engine - - - - - - junit - junit - test - - - io.projectreactor - reactor-core - - - io.vertx - vertx-core - - - - org.projectlombok - lombok - - - - org.slf4j - slf4j-api - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - - io.vertx:vertx-core - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - true - false - utf8 - - - - - diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/TcpDeviceComponent.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/TcpDeviceComponent.java deleted file mode 100644 index 1ba36e3b..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/TcpDeviceComponent.java +++ /dev/null @@ -1,67 +0,0 @@ -package cc.iotkit.comp; - - -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.comp.tcp.cilent.TcpClientDeviceComponent; -import cc.iotkit.comp.tcp.server.TcpServerDeviceComponent; -import cc.iotkit.converter.DeviceMessage; -import lombok.extern.slf4j.Slf4j; - -import java.util.Map; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -@Slf4j -public class TcpDeviceComponent extends AbstractDeviceComponent { - - private AbstractDeviceComponent tcpVerticle; - - @Override - public void create(CompConfig config) { - Map maps = JsonUtils.parseObject(config.getOther(), Map.class); - String type = maps.get("type").toString(); - if ("server".equals(type)) { - tcpVerticle = new TcpServerDeviceComponent(); - } else { - tcpVerticle = new TcpClientDeviceComponent(); - } - tcpVerticle.create(config); - } - - @Override - public String getId() { - return tcpVerticle.getId(); - } - - @Override - public void start() { - tcpVerticle.setHandler(getHandler()); - tcpVerticle.start(); - } - - - @Override - public void stop() { - tcpVerticle.stop(); - } - - @Override - public void destroy() { - tcpVerticle.destroy(); - } - - @Override - public void onDeviceStateChange(DeviceState state) { - tcpVerticle.onDeviceStateChange(state); - } - - - - @Override - public DeviceMessage send(DeviceMessage message) { - return tcpVerticle.send(message); - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/TcpClientDeviceComponent.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/TcpClientDeviceComponent.java deleted file mode 100644 index af04651c..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/TcpClientDeviceComponent.java +++ /dev/null @@ -1,76 +0,0 @@ -package cc.iotkit.comp.tcp.cilent; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.AbstractDeviceComponent; -import cc.iotkit.comp.CompConfig; -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.converter.DeviceMessage; -import io.vertx.core.Future; -import io.vertx.core.Vertx; -import lombok.extern.slf4j.Slf4j; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -@Slf4j -public class TcpClientDeviceComponent extends AbstractDeviceComponent { - private Vertx vertx; - private TcpClientVerticle tcpClientVerticle; - private String deployedId; - - @Override - public void create(CompConfig config) { - super.create(config); - vertx = Vertx.vertx(); - TcpClinetConfig tcpClinetConfig = JsonUtils.parseObject(config.getOther(), TcpClinetConfig.class); - tcpClientVerticle = new TcpClientVerticle(tcpClinetConfig); - } - - @Override - public void start() { - try { - tcpClientVerticle.setExecutor(getHandler()); - Future future = vertx.deployVerticle(tcpClientVerticle); - future.onSuccess((s -> { - deployedId = s; - log.info("tcp client start success, deployId:{}", s); - })) - .onFailure((e -> { - log.error("tcp client start fail"); - e.printStackTrace(); - })); - future.succeeded(); - } catch (Throwable e) { - throw new BizException(ErrCode.COMPONENT_START_ERROR, e); - } - - } - - @Override - public void stop() { - tcpClientVerticle.stop(); - Future future = vertx.undeploy(deployedId); - future.onSuccess(unused -> log.info("stop tcpserver component success")); - } - - @Override - public void destroy() { - } - - @Override - public void onDeviceStateChange(DeviceState state) { - if (DeviceState.STATE_OFFLINE.equals(state.getState())) { - tcpClientVerticle.offlineDevice(state.getDeviceName()); - } - } - - - @Override - public DeviceMessage send(DeviceMessage message) { - tcpClientVerticle.sendMsg(message); - return message; - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/TcpClientVerticle.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/TcpClientVerticle.java deleted file mode 100644 index c770d0db..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/TcpClientVerticle.java +++ /dev/null @@ -1,157 +0,0 @@ -package cc.iotkit.comp.tcp.cilent; - -import cc.iotkit.comp.IMessageHandler; -import cc.iotkit.comp.tcp.parser.ParserStrategyBuilder; -import cc.iotkit.converter.DeviceMessage; -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 lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import java.time.Duration; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -/** - * @author huangwenlong - * @version 1.0 - * @date 2022/10/23 13:08 - */ -@Slf4j -public class TcpClientVerticle extends AbstractVerticle { - - private TcpClinetConfig config; - - private IMessageHandler executor; - - private VertxTcpClient tcpClient; - - private NetClient netClient; - - private Map deviceMap = new ConcurrentHashMap(); - - private boolean stopAction = false; - - public TcpClientVerticle(TcpClinetConfig config) { - this.config = config; - } - - public void setExecutor(IMessageHandler executor) { - this.executor = executor; - } - - @Override - public void start() { - tcpClient = new VertxTcpClient(UUID.randomUUID().toString(), false); - initConfig(); - initClient(); - } - - @Override - public void stop() { - if (null != tcpClient) { - stopAction = true; - tcpClient.shutdown(); - } - } - - public void sendMsg(DeviceMessage msg) { - if (tcpClient != null) { - tcpClient.sendMessage(Buffer.buffer(msg.getContent().toString())); - } - } - - public void offlineDevice(String deviceName) { - ClientDevice remove = deviceMap.remove(deviceName); - } - - /** - * 创建配置文件 - * 未链接成功就一直重连(每隔1分钟) - */ - public void initConfig() { - if (config.getOptions() == null) { - NetClientOptions options = new NetClientOptions(); - options.setReconnectAttempts(Integer.MAX_VALUE); - options.setReconnectInterval(20000L); - config.setOptions(options); - } - if (config.isSsl()) { - // 证书 - } - } - - private void initClient() { - netClient = vertx.createNetClient(config.getOptions()); - tcpClient.setKeepAliveTimeoutMs(Duration.ofMinutes(10).toMillis()); - tcpClient.onDisconnect(() -> { - // 所有设备都离线 - for (String deviceName : deviceMap.keySet()) { - // 发送离线消息 - executor.onReceive(null, "disconnect", deviceName); - } - }); - // 连接 - toConnection(); - // 设置收到消息处理 - tcpClient.setReceiveHandler(buffer -> { - try { - executor.onReceive(null, "", buffer.toString(), - result -> { - if (!deviceMap.containsKey(result.getDeviceName())) { - deviceMap.put(result.getDeviceName(), new ClientDevice(result.getDeviceName(), result.getProductKey())); - // 有些设备并没有连接时报文,所以模拟一次 online - HashMap map = new HashMap<>(); - map.put("deviceName", result.getDeviceName()); - executor.onReceive(map, "connect", buffer.toString()); - } - }); - } catch (Exception e) { - e.printStackTrace(); - } - }); - } - - public void toConnection() { - netClient.connect(config.getPort(), config.getHost(), result -> { - if (result.succeeded()) { - log.debug("connect tcp [{}:{}] success", config.getHost(), config.getPort()); - tcpClient.setRecordParser(ParserStrategyBuilder.build(config.getParserType(), config.getParserConfiguration())); - NetSocket socket = result.result(); - tcpClient.setSocket(socket); - socket.closeHandler((nil) -> { - tcpClient.shutdown(); - // 重连自动断开重连,收到停止组件不重连 - try { - if (!stopAction) { - Thread.sleep(5000L); - toConnection(); - }else{ - netClient.close(); - netClient = null; - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - }); - } else { - log.error("connect tcp [{}:{}] error", config.getHost(), config.getPort(), result.cause()); - } - }); - } - - @Data - @AllArgsConstructor - @NoArgsConstructor - class ClientDevice { - private String deviceName = ""; - private String productKey = ""; - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/TcpClinetConfig.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/TcpClinetConfig.java deleted file mode 100644 index e5a27971..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/TcpClinetConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -package cc.iotkit.comp.tcp.cilent; - -import io.vertx.core.net.NetClientOptions; -import lombok.Data; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -@Data -public class TcpClinetConfig { - - private String id; - - private NetClientOptions options; - - private String host; - - private int port; - - private boolean ssl; - - private String parserType; - - // 解析参数 - private Map parserConfiguration = new HashMap<>(); - - //服务实例数量(线程数) - private int instance = Runtime.getRuntime().availableProcessors(); - - -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/VertxTcpClient.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/VertxTcpClient.java deleted file mode 100644 index 4205a306..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/cilent/VertxTcpClient.java +++ /dev/null @@ -1,166 +0,0 @@ -package cc.iotkit.comp.tcp.cilent; - -import cc.iotkit.comp.IMessageHandler; -import cc.iotkit.comp.tcp.parser.PayloadParser; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.net.NetSocket; -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.binary.Hex; -import org.apache.commons.lang3.StringUtils; - -import java.time.Duration; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.function.Consumer; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -@Slf4j -public class VertxTcpClient { - @Getter - private String id; - @Getter - private String deviceName = ""; - @Setter - @Getter - private String parentName = ""; - @Getter - private String productKey = ""; - // 是否是服务端的连接客户端 - private final boolean serverClient; - volatile PayloadParser payloadParser; - public NetSocket socket; - private final List disconnectListener = new CopyOnWriteArrayList<>(); - private IMessageHandler executor; - private Consumer receiveHandler; - @Setter - private long keepAliveTimeoutMs = Duration.ofMinutes(10).toMillis(); - private volatile long lastKeepAliveTime = System.currentTimeMillis(); - - public VertxTcpClient(String id, boolean serverClient) { - this.id = id; - this.serverClient = serverClient; - } - - - public void keepAlive() { - lastKeepAliveTime = System.currentTimeMillis(); - } - - public boolean isOnline() { - return System.currentTimeMillis() - lastKeepAliveTime < keepAliveTimeoutMs; - } - - public void setDeviceInfo(String deviceName, String productKey) { - this.deviceName = deviceName; - this.productKey = productKey; - } - - public void setSocket(NetSocket socket) { - synchronized (this) { -// Objects.requireNonNull(payloadParser); - 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(); - payloadParser.handle(buffer); - if (this.socket != socket) { - log.warn("tcp client [{}] memory leak ", socket.remoteAddress()); - socket.close(); - } - }); - } - } - - /** - * 设置客户端消息解析器 - * - * @param payloadParser 消息解析器 - */ - public void setRecordParser(PayloadParser payloadParser) { - synchronized (this) { - if (null != this.payloadParser && this.payloadParser != payloadParser) { - this.payloadParser.close(); - } - this.payloadParser = payloadParser; - this.payloadParser - .handlePayload() - .onErrorContinue((err, res) -> { - log.error(err.getMessage(), err); - }) - .subscribe(buffer -> { - log.info(buffer.toString()); - receiveHandler.accept(buffer); - }); - } - } - - public void onDisconnect(Runnable disconnected) { - disconnectListener.add(disconnected); - } - - - /** - * 设置消息处理器 - */ - public void setReceiveHandler(Consumer receiveHandler) { - this.receiveHandler = receiveHandler; - } - - public void shutdown() { - log.debug("tcp client [{}] disconnect", getId()); - synchronized (this) { - if (null != socket) { - execute(socket::close); - this.socket = null; - } - // 粘包处理器 - if (null != payloadParser) { - execute(payloadParser::close); - payloadParser = null; - } - } - for (Runnable runnable : disconnectListener) { - execute(runnable); - } - disconnectListener.clear(); - } - - public void sendMessage(Buffer buffer) { - socket.write(buffer, r -> { - keepAlive(); - if (r.succeeded()) { - log.info("下行消息成功:{}", buffer.toString()); - } else { - log.error("下行消息失败", r.cause()); - } - }); - } - - private void execute(Runnable runnable) { - try { - runnable.run(); - } catch (Exception e) { - log.warn("close tcp client error", e); - } - } - - /** - * 是否有父设备 - */ - public boolean hasParent() { - return StringUtils.isNotEmpty(parentName); - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/DelimitedPayloadParser.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/DelimitedPayloadParser.java deleted file mode 100644 index 20a95ebd..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/DelimitedPayloadParser.java +++ /dev/null @@ -1,55 +0,0 @@ -package cc.iotkit.comp.tcp.parser; - -import io.vertx.core.buffer.Buffer; -import io.vertx.core.parsetools.RecordParser; -import org.apache.commons.lang3.StringEscapeUtils; -import reactor.core.publisher.EmitterProcessor; -import reactor.core.publisher.Flux; -import reactor.core.publisher.FluxSink; - -import java.util.function.Function; - -/** - * 分隔符 - * - * @author huangwenl - * @date 2022-10-13 - */ -public class DelimitedPayloadParser implements PayloadParser { - - private String delimited; - private final EmitterProcessor processor = EmitterProcessor.create(false); - private final FluxSink sink = processor.sink(FluxSink.OverflowStrategy.BUFFER); - - private RecordParser recordParser; - - - public PayloadParser init(Object delimited) { - this.delimited = StringEscapeUtils.unescapeJava(delimited.toString()); - this.reset(); - return this; - } - - - @Override - public void handle(Buffer buffer) { - recordParser.handle(buffer); - } - - @Override - public Flux handlePayload() { - return processor.map(Function.identity()); - } - - @Override - public void reset() { - this.recordParser = RecordParser.newDelimited(delimited); - // 塞入 skin pusher - this.recordParser.handler(sink::next); - } - - @Override - public void close() { - processor.onComplete(); - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/DirectPayloadParser.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/DirectPayloadParser.java deleted file mode 100644 index 0000bb56..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/DirectPayloadParser.java +++ /dev/null @@ -1,41 +0,0 @@ -package cc.iotkit.comp.tcp.parser; - -import io.vertx.core.buffer.Buffer; -import reactor.core.publisher.EmitterProcessor; -import reactor.core.publisher.Flux; - -import java.util.function.Function; - -/** - * 不处理 - * - * @author huangwenl - * @date 2022-10-13 - */ -public class DirectPayloadParser implements PayloadParser { - - - EmitterProcessor processor = EmitterProcessor.create(false); - - - @Override - public PayloadParser init(Object param) { - return this; - } - - @Override - public void handle(Buffer buffer) { - processor.onNext(buffer); - } - - @Override - public Flux handlePayload() { - return processor.map(Function.identity()); - } - - - @Override - public void close() { - processor.onComplete(); - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/FixPayloadParser.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/FixPayloadParser.java deleted file mode 100644 index 2dac056a..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/FixPayloadParser.java +++ /dev/null @@ -1,53 +0,0 @@ -package cc.iotkit.comp.tcp.parser; - -import io.vertx.core.buffer.Buffer; -import io.vertx.core.parsetools.RecordParser; -import reactor.core.publisher.EmitterProcessor; -import reactor.core.publisher.Flux; -import reactor.core.publisher.FluxSink; - -import java.util.function.Function; - -/** - * 固定长度 - * - * @author huangwenl - * @date 2022-10-13 - */ -public class FixPayloadParser implements PayloadParser { - - private int size; - private final EmitterProcessor processor = EmitterProcessor.create(false); - private final FluxSink sink = processor.sink(FluxSink.OverflowStrategy.BUFFER); - - private RecordParser recordParser; - - - public PayloadParser init(Object size) { - this.size = (int) size; - this.reset(); - return this; - } - - - @Override - public void handle(Buffer buffer) { - recordParser.handle(buffer); - } - - @Override - public Flux handlePayload() { - return processor.map(Function.identity()); - } - - @Override - public void reset() { - this.recordParser = RecordParser.newFixed(size); - this.recordParser.handler(sink::next); - } - - @Override - public void close() { - processor.onComplete(); - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/ParserStrategyBuilder.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/ParserStrategyBuilder.java deleted file mode 100644 index fa82d031..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/ParserStrategyBuilder.java +++ /dev/null @@ -1,35 +0,0 @@ -package cc.iotkit.comp.tcp.parser; - -import cc.iotkit.comp.tcp.parser.builder.DelimitedPayloadBuilder; -import cc.iotkit.comp.tcp.parser.builder.DirectPayloadBuilder; -import cc.iotkit.comp.tcp.parser.builder.FixPayloadBuilder; -import cc.iotkit.comp.tcp.parser.builder.ScriptPayloadBuilder; - -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -public class ParserStrategyBuilder { - private static Map strategyMap = new ConcurrentHashMap<>(); - - static { - register(new DelimitedPayloadBuilder()); - register(new DirectPayloadBuilder()); - register(new FixPayloadBuilder()); - register(new ScriptPayloadBuilder()); - } - - public static PayloadParser build(String type, Map configuration) { - return Optional.ofNullable(strategyMap.get(type)) - .map(builder -> builder.build(configuration)) - .orElseThrow(() -> new UnsupportedOperationException("unsupported parser:" + type)); - } - - private static void register(PayloadParserBuilderStrategy strategy) { - strategyMap.put(strategy.getType().getText(), strategy); - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/PayloadParser.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/PayloadParser.java deleted file mode 100644 index 2826d721..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/PayloadParser.java +++ /dev/null @@ -1,32 +0,0 @@ -package cc.iotkit.comp.tcp.parser; - -import io.vertx.core.buffer.Buffer; -import reactor.core.publisher.Flux; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -public interface PayloadParser { - - - PayloadParser init(Object param) throws Exception; - - void handle(Buffer buffer); - - /** - * 订阅完整的数据包流,每一个元素为一个完整的数据包 - * - * @return 完整数据包流 - */ - Flux handlePayload(); - - - /** - * 重置规则 - */ - default void reset() { - } - - void close(); -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/PayloadParserBuilderStrategy.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/PayloadParserBuilderStrategy.java deleted file mode 100644 index 416968a9..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/PayloadParserBuilderStrategy.java +++ /dev/null @@ -1,17 +0,0 @@ -package cc.iotkit.comp.tcp.parser; - - - -import cc.iotkit.comp.tcp.parser.enums.PayloadParserType; - -import java.util.Map; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -public interface PayloadParserBuilderStrategy { - PayloadParserType getType(); - - PayloadParser build(Map parserConfiguration); -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/ScriptPayloadParser.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/ScriptPayloadParser.java deleted file mode 100644 index 7a032f25..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/ScriptPayloadParser.java +++ /dev/null @@ -1,165 +0,0 @@ -package cc.iotkit.comp.tcp.parser; - -import cc.iotkit.script.IScriptEngine; -import cc.iotkit.script.ScriptEngineFactory; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.parsetools.RecordParser; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; -import reactor.core.publisher.EmitterProcessor; -import reactor.core.publisher.Flux; -import reactor.core.publisher.FluxSink; - -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; -import java.util.function.Function; - -@Slf4j -public class ScriptPayloadParser implements PayloadParser { - - private final IScriptEngine scriptEngine = ScriptEngineFactory.getScriptEngine("js"); - - @SneakyThrows - @Override - public PayloadParser init(Object param) { - String script = (String) param; - scriptEngine.setScript(script); - //执行转换脚本 - scriptEngine.invokeMethod("payloadParser", this); - return this; - } - - @Override - public synchronized void handle(Buffer buffer) { - if (recordParser == null && directMapper == null) { - log.error("record parser not init"); - return; - } - if (recordParser != null) { - recordParser.handle(buffer); - return; - } - Buffer buf = directMapper.apply(buffer); - if (null != buf) { - sink.next(buf); - } - } - - @Override - public Flux handlePayload() { - return processor.map(Function.identity()); - } - - @Override - public void reset() { - this.result.clear(); - complete(); - } - - @Override - public void close() { - processor.onComplete(); - currentPipe.set(0); - this.result.clear(); - } - - private final EmitterProcessor processor = EmitterProcessor.create(true); - - private final FluxSink sink = processor.sink(FluxSink.OverflowStrategy.BUFFER); - - private final List> pipe = new CopyOnWriteArrayList<>(); - - private final List result = new CopyOnWriteArrayList<>(); - - private volatile RecordParser recordParser; - - private Function directMapper; - - private Consumer firstInit; - - private final AtomicInteger currentPipe = new AtomicInteger(); - - public Buffer newBuffer() { - return Buffer.buffer(); - } - - public ScriptPayloadParser result(String buffer) { - return result(Buffer.buffer(buffer)); - } - - public ScriptPayloadParser result(byte[] buffer) { - return result(Buffer.buffer(buffer)); - } - - public ScriptPayloadParser handler(Consumer handler) { - pipe.add(handler); - return this; - } - - public ScriptPayloadParser delimited(String delimited) { - if (recordParser == null) { - setParser(RecordParser.newDelimited(delimited)); - firstInit = (parser -> parser.delimitedMode(delimited)); - return this; - } - recordParser.delimitedMode(delimited); - return this; - } - - public ScriptPayloadParser fixed(int size) { - if (size == 0) { - complete(); - return this; - } - if (recordParser == null) { - setParser(RecordParser.newFixed(size)); - firstInit = (parser -> parser.fixedSizeMode(size)); - return this; - } - recordParser.fixedSizeMode(size); - return this; - } - - public ScriptPayloadParser direct(Function mapper) { - this.directMapper = mapper; - return this; - } - - private Consumer getNextHandler() { - int i = currentPipe.getAndIncrement(); - if (i < pipe.size()) { - return pipe.get(i); - } - currentPipe.set(0); - return pipe.get(0); - } - - private void setParser(RecordParser parser) { - this.recordParser = parser; - this.recordParser.handler(buffer -> getNextHandler().accept(buffer)); - } - - public ScriptPayloadParser complete() { - currentPipe.set(0); - if (recordParser != null) { - firstInit.accept(recordParser); - } - if (!this.result.isEmpty()) { - Buffer buffer = Buffer.buffer(); - for (Buffer buf : this.result) { - buffer.appendBuffer(buf); - } - this.result.clear(); - sink.next(buffer); - } - return this; - - } - - public ScriptPayloadParser result(Buffer buffer) { - this.result.add(buffer); - return this; - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/DelimitedPayloadBuilder.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/DelimitedPayloadBuilder.java deleted file mode 100644 index 024c77d8..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/DelimitedPayloadBuilder.java +++ /dev/null @@ -1,24 +0,0 @@ -package cc.iotkit.comp.tcp.parser.builder; - -import cc.iotkit.comp.tcp.parser.DelimitedPayloadParser; -import cc.iotkit.comp.tcp.parser.PayloadParser; -import cc.iotkit.comp.tcp.parser.PayloadParserBuilderStrategy; -import cc.iotkit.comp.tcp.parser.enums.PayloadParserType; - -import java.util.Map; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -public class DelimitedPayloadBuilder implements PayloadParserBuilderStrategy { - @Override - public PayloadParserType getType() { - return PayloadParserType.DELIMITED; - } - - @Override - public PayloadParser build(Map parserConfiguration) { - return new DelimitedPayloadParser().init(parserConfiguration.get("delimited")); - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/DirectPayloadBuilder.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/DirectPayloadBuilder.java deleted file mode 100644 index 79f109cb..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/DirectPayloadBuilder.java +++ /dev/null @@ -1,24 +0,0 @@ -package cc.iotkit.comp.tcp.parser.builder; - -import cc.iotkit.comp.tcp.parser.DirectPayloadParser; -import cc.iotkit.comp.tcp.parser.PayloadParser; -import cc.iotkit.comp.tcp.parser.PayloadParserBuilderStrategy; -import cc.iotkit.comp.tcp.parser.enums.PayloadParserType; - -import java.util.Map; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -public class DirectPayloadBuilder implements PayloadParserBuilderStrategy { - @Override - public PayloadParserType getType() { - return PayloadParserType.DIRECT; - } - - @Override - public PayloadParser build(Map parserConfiguration) { - return new DirectPayloadParser().init(null); - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/FixPayloadBuilder.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/FixPayloadBuilder.java deleted file mode 100644 index e17b119e..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/FixPayloadBuilder.java +++ /dev/null @@ -1,24 +0,0 @@ -package cc.iotkit.comp.tcp.parser.builder; - -import cc.iotkit.comp.tcp.parser.FixPayloadParser; -import cc.iotkit.comp.tcp.parser.PayloadParser; -import cc.iotkit.comp.tcp.parser.PayloadParserBuilderStrategy; -import cc.iotkit.comp.tcp.parser.enums.PayloadParserType; - -import java.util.Map; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -public class FixPayloadBuilder implements PayloadParserBuilderStrategy { - @Override - public PayloadParserType getType() { - return PayloadParserType.FIXED_LENGTH; - } - - @Override - public PayloadParser build(Map parserConfiguration) { - return new FixPayloadParser().init(parserConfiguration.get("fix")); - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/ScriptPayloadBuilder.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/ScriptPayloadBuilder.java deleted file mode 100644 index c31f47a6..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/builder/ScriptPayloadBuilder.java +++ /dev/null @@ -1,24 +0,0 @@ -package cc.iotkit.comp.tcp.parser.builder; - -import cc.iotkit.comp.tcp.parser.PayloadParser; -import cc.iotkit.comp.tcp.parser.PayloadParserBuilderStrategy; -import cc.iotkit.comp.tcp.parser.ScriptPayloadParser; -import cc.iotkit.comp.tcp.parser.enums.PayloadParserType; - -import java.util.Map; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -public class ScriptPayloadBuilder implements PayloadParserBuilderStrategy { - @Override - public PayloadParserType getType() { - return PayloadParserType.SCRIPT; - } - - @Override - public PayloadParser build(Map parserConfiguration) { - return new ScriptPayloadParser().init(parserConfiguration.get("script")); - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/enums/PayloadParserType.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/enums/PayloadParserType.java deleted file mode 100644 index af34b7b6..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/parser/enums/PayloadParserType.java +++ /dev/null @@ -1,23 +0,0 @@ -package cc.iotkit.comp.tcp.parser.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -@Getter -@AllArgsConstructor -public enum PayloadParserType { - DIRECT("不处理"), - - FIXED_LENGTH("固定长度"), - - DELIMITED("分隔符"), - - SCRIPT("自定义脚本") - ; - - private String text; -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/TcpServerConfig.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/TcpServerConfig.java deleted file mode 100644 index fad4e210..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/TcpServerConfig.java +++ /dev/null @@ -1,43 +0,0 @@ -package cc.iotkit.comp.tcp.server; - -import io.vertx.core.net.NetServerOptions; -import io.vertx.core.net.SocketAddress; -import lombok.Data; -import org.apache.commons.lang3.StringUtils; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -@Data -public class TcpServerConfig { - - private String id; - - private NetServerOptions options; - - private String host; - - private int port; - - private boolean ssl; - - private String parserType; - - // 解析参数 - private Map parserConfiguration = new HashMap<>(); - - //服务实例数量(线程数) - private int instance = Runtime.getRuntime().availableProcessors(); - - public SocketAddress createSocketAddress() { - if (StringUtils.isEmpty(host)) { - host = "localhost"; - } - return SocketAddress.inetSocketAddress(port, host); - } - -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/TcpServerDeviceComponent.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/TcpServerDeviceComponent.java deleted file mode 100644 index bded0940..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/TcpServerDeviceComponent.java +++ /dev/null @@ -1,80 +0,0 @@ -package cc.iotkit.comp.tcp.server; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.AbstractDeviceComponent; -import cc.iotkit.comp.CompConfig; -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.converter.DeviceMessage; -import io.vertx.core.Future; -import io.vertx.core.Vertx; -import lombok.extern.slf4j.Slf4j; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -@Slf4j -public class TcpServerDeviceComponent extends AbstractDeviceComponent { - - private Vertx vertx; - private TcpServerVerticle tcpServerVerticle; - private String deployedId; - - @Override - public void create(CompConfig config) { - super.create(config); - vertx = Vertx.vertx(); - TcpServerConfig serverConfig = JsonUtils.parseObject(config.getOther(), TcpServerConfig.class); - tcpServerVerticle = new TcpServerVerticle(serverConfig); - } - - @Override - public void start() { - try { - tcpServerVerticle.setExecutor(getHandler()); - Future future = vertx.deployVerticle(tcpServerVerticle); - future.onSuccess((s -> { - deployedId = s; - log.info("tcp server start success, deployId:{}", s); - })) - .onFailure((e -> { - log.error("tcp server start fail"); - e.printStackTrace(); - })); - future.succeeded(); - }catch (Throwable e){ - throw new BizException(ErrCode.COMPONENT_START_ERROR, e); - } - - } - - @Override - public void stop() { - tcpServerVerticle.stop(); - Future future = vertx.undeploy(deployedId); - future.onSuccess(unused -> log.info("stop tcpserver component success")); - } - - @Override - public void destroy() { - } - - @Override - public void onDeviceStateChange(DeviceState state) { - if (DeviceState.STATE_OFFLINE.equals(state.getState())){ - tcpServerVerticle.offlineDevice(state.getDeviceName()); - }else if(DeviceState.STATE_ONLINE.equals(state.getState())){ - tcpServerVerticle.onlineDevice(state.getDeviceName(), - state.getParent() != null ? state.getParent().getDeviceName() : null); - } - } - - - @Override - public DeviceMessage send(DeviceMessage message) { - tcpServerVerticle.sendMsg(message); - return message; - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/TcpServerVerticle.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/TcpServerVerticle.java deleted file mode 100644 index 1ea21e36..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/TcpServerVerticle.java +++ /dev/null @@ -1,257 +0,0 @@ -package cc.iotkit.comp.tcp.server; - - -import cc.iotkit.comp.IMessageHandler; -import cc.iotkit.comp.tcp.cilent.VertxTcpClient; -import cc.iotkit.comp.tcp.parser.ParserStrategyBuilder; -import cc.iotkit.comp.tcp.parser.PayloadParser; -import cc.iotkit.converter.DeviceMessage; -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 lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; - -import java.time.Duration; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -/** - * @author huangwenl - * @date 2022-10-13 - */ -@Slf4j -public class TcpServerVerticle extends AbstractVerticle { - - @Getter - private TcpServerConfig config; - - private IMessageHandler executor; - - private VertxTcpServer tcpServer; - - private String id; - - private Map clientMap = new ConcurrentHashMap(); - - private ScheduledThreadPoolExecutor scheduledThreadPoolExecutor; - - @Setter - private long keepAliveTimeout = Duration.ofMinutes(10).toMillis(); - - private Collection tcpServers; - - public TcpServerVerticle(TcpServerConfig config) { - this.config = config; - } - - public void setExecutor(IMessageHandler executor) { - this.executor = executor; - } - - @Override - public void start() { - tcpServer = new VertxTcpServer(); - initConfig(); - initTcpServer(); - keepClientTask(); - } - - @Override - public void stop() { - tcpServer.shutdown(); - scheduledThreadPoolExecutor.shutdown(); - } - - /** - * 创建配置文件 - */ - public void initConfig() { - if (config.getOptions() == null) { - config.setOptions(new NetServerOptions()); - } - if (config.isSsl()) { - // 证书 - } - } - - - /** - * 初始TCP服务 - */ - private void initTcpServer() { - int instance = Math.max(2, config.getInstance()); - List instances = new ArrayList<>(instance); - for (int i = 0; i < instance; i++) { - instances.add(vertx.createNetServer(config.getOptions())); - } - // 根据解析类型配置数据解析器 - tcpServer.setParserSupplier(() -> ParserStrategyBuilder.build(config.getParserType(), config.getParserConfiguration())); - tcpServer.setServer(instances); - // 针对JVM做的多路复用优化 - // 多个server listen同一个端口,每个client连接的时候vertx会分配 - // 一个connection只能在一个server中处理 - for (NetServer netServer : instances) { - netServer.listen(config.createSocketAddress(), result -> { - if (result.succeeded()) { - log.info("tcp server startup on {}", result.result().actualPort()); - } else { - log.error("startup tcp server error", result.cause()); - } - }); - } - } - - public void offlineDevice(String deviceName) { - VertxTcpClient client = clientMap.get(deviceName); - if (client != null) { - client.shutdown(); - } - } - - public void onlineDevice(String deviceName, String parentName) { - VertxTcpClient client = clientMap.get(deviceName); - if (client != null) { - client.setParentName(parentName); - } - } - - public void sendMsg(DeviceMessage msg) { - VertxTcpClient tcpClient = clientMap.get(msg.getDeviceName()); - if (tcpClient != null) { - tcpClient.sendMessage(Buffer.buffer(msg.getContent().toString())); - } - } - - /** - * 保活定时任务 - */ - public void keepClientTask() { - scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(2); - - scheduledThreadPoolExecutor.scheduleAtFixedRate(() -> { - log.info("保活任务开始!"); - Set clients = new HashSet(clientMap.keySet()); - for (String key : clients) { - VertxTcpClient client = clientMap.get(key); - if (!client.isOnline()) { - client.shutdown(); - } - } - }, 1000, keepAliveTimeout, TimeUnit.MILLISECONDS); - } - - - class VertxTcpServer { - - private Supplier parserSupplier; - - /** - * 为每个NetServer添加connectHandler - * - * @param servers 创建的所有NetServer - */ - public void setServer(Collection servers) { - if (tcpServers != null && !tcpServers.isEmpty()) { - shutdown(); - } - tcpServers = servers; - for (NetServer tcpServer : tcpServers) { - tcpServer.connectHandler(this::acceptTcpConnection); - } - } - - /** - * TCP连接处理逻辑 - * - * @param socket socket - */ - protected void acceptTcpConnection(NetSocket socket) { - // 客户端连接处理 - String clientId = id + "_" + socket.remoteAddress(); - VertxTcpClient client = new VertxTcpClient(clientId, true); - client.setKeepAliveTimeoutMs(keepAliveTimeout); - try { - // TCP异常和关闭处理 - socket.exceptionHandler(err -> log.error("tcp server client [{}] error", socket.remoteAddress(), err)).closeHandler(nil -> { - log.debug("tcp server client [{}] closed", socket.remoteAddress()); - client.shutdown(); - }); - // 这个地方是在TCP服务初始化的时候设置的 parserSupplier - client.setKeepAliveTimeoutMs(keepAliveTimeout); - client.setRecordParser(parserSupplier.get()); - client.setSocket(socket); - client.onDisconnect(() -> clientDisconnect(client.getDeviceName())); - // 设置收到消息处理 - client.setReceiveHandler(buffer -> { - log.info(buffer.toString()); - try { - executor.onReceive(null, "", buffer.toString(), - result -> { - if (result != null && !clientMap.containsKey(result.getDeviceName())) { - client.setDeviceInfo(result.getDeviceName(), result.getProductKey()); - clientMap.put(result.getDeviceName(), client); - // 有些设备并没有连接时报文,所以模拟一次 online - HashMap map = new HashMap<>(); - map.put("deviceName", result.getDeviceName()); - executor.onReceive(map, "connect", buffer.toString()); - } - }); - } catch (Exception e) { - e.printStackTrace(); - } - - }); - log.debug("accept tcp client [{}] connection", socket.remoteAddress()); - } catch (Exception e) { - log.error("create tcp server client error", e); - client.shutdown(); - } - } - - public void setParserSupplier(Supplier parserSupplier) { - this.parserSupplier = parserSupplier; - } - - public void shutdown() { - if (null != tcpServers) { - for (NetServer tcpServer : tcpServers) { - execute(tcpServer::close); - } - tcpServers = null; - } - } - - private void execute(Runnable runnable) { - try { - runnable.run(); - } catch (Exception e) { - log.warn("close tcp server error", e); - } - } - - /** - * 断开连接,并移除子设备 - */ - private void clientDisconnect(String deviceName) { - VertxTcpClient remove = clientMap.remove(deviceName); - if (null != remove) { - // 发送离线消息 - executor.onReceive(null, "disconnect", deviceName); - // 移除子设备 - if (remove.hasParent()) { - List childClients = clientMap.values().stream().filter(cl -> cl.hasParent() && cl.getParentName() - .equals(remove.getParentName())).collect(Collectors.toList()); - childClients.forEach(child -> clientMap.remove(child.getDeviceName())); - } - } - } - } -} diff --git a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/VertxTcpServer.java b/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/VertxTcpServer.java deleted file mode 100644 index e0da38b7..00000000 --- a/iot-components/iot-component-tcp/src/main/java/cc/iotkit/comp/tcp/server/VertxTcpServer.java +++ /dev/null @@ -1,160 +0,0 @@ -package cc.iotkit.comp.tcp.server;//package cc.iotkit.comp.tcp.server; -// -//import cc.iotkit.comp.IMessageHandler; -//import cc.iotkit.comp.tcp.cilent.VertxTcpClient; -//import cc.iotkit.comp.tcp.parser.PayloadParser; -//import cc.iotkit.converter.DeviceMessage; -//import io.vertx.core.buffer.Buffer; -//import io.vertx.core.net.NetServer; -//import io.vertx.core.net.NetSocket; -//import lombok.Setter; -//import lombok.extern.slf4j.Slf4j; -// -//import java.time.Duration; -//import java.util.Collection; -//import java.util.HashMap; -//import java.util.List; -//import java.util.Map; -//import java.util.concurrent.ConcurrentHashMap; -//import java.util.function.Supplier; -//import java.util.stream.Collectors; -// -///** -// * @author huangwenl -// * @date 2022-10-13 -// */ -//@Slf4j -//public class VertxTcpServer { -// -// private String id; -// -// private Supplier parserSupplier; -// -// private Map clientMap = new ConcurrentHashMap(); -// private IMessageHandler executor; -// private Collection tcpServers; -// @Setter -// private long keepAliveTimeout = Duration.ofMinutes(10).toMillis(); -// -// public VertxTcpServer(String id) { -// this.id = id; -// } -// -// /** -// * 为每个NetServer添加connectHandler -// * -// * @param servers 创建的所有NetServer -// */ -// public void setServer(Collection servers) { -// if (this.tcpServers != null && !this.tcpServers.isEmpty()) { -// shutdown(); -// } -// this.tcpServers = servers; -// -// for (NetServer tcpServer : this.tcpServers) { -// tcpServer.connectHandler(this::acceptTcpConnection); -// } -// } -// -// /** -// * TCP连接处理逻辑 -// * -// * @param socket socket -// */ -// protected void acceptTcpConnection(NetSocket socket) { -// // 客户端连接处理 -// String clientId = id + "_" + socket.remoteAddress(); -// VertxTcpClient client = new VertxTcpClient(clientId, true); -// client.setKeepAliveTimeoutMs(keepAliveTimeout); -// try { -// // TCP异常和关闭处理 -// socket.exceptionHandler(err -> { -// log.error("tcp server client [{}] error", socket.remoteAddress(), err); -// }).closeHandler((nil) -> { -// log.debug("tcp server client [{}] closed", socket.remoteAddress()); -// client.shutdown(); -// }); -// // 这个地方是在TCP服务初始化的时候设置的 parserSupplier -// client.setRecordParser(parserSupplier.get()); -// client.setSocket(socket); -// client.onDisconnect(() -> { -// clientDisconnect(client.getDeviceName()); -// }); -// // 设置收到消息处理 -// client.setReceiveHandler(buffer -> { -// executor.onReceive(null, "", buffer.toString(), -// result -> { -// if (!clientMap.containsKey(result.getDeviceName())) { -// client.setDeviceInfo(result.getDeviceName(), result.getData().getParent().getDeviceName(), -// result.getProductKey()); -// clientMap.put(result.getDeviceName(), client); -// // 有些设备并没有连接时报文,所以模拟一次 online -// HashMap map = new HashMap<>(); -// map.put("deviceName", result.getDeviceName()); -// executor.onReceive(map, "online", ""); -// } -// }); -// }); -//// clientMap.put(clientId, client); -// log.debug("accept tcp client [{}] connection", socket.remoteAddress()); -// } catch (Exception e) { -// log.error("create tcp server client error", e); -// client.shutdown(); -// } -// } -// -// public void setParserSupplier(Supplier parserSupplier) { -// this.parserSupplier = parserSupplier; -// } -// -// public void shutdown() { -// if (null != tcpServers) { -// for (NetServer tcpServer : tcpServers) { -// execute(tcpServer::close); -// } -// tcpServers = null; -// } -// } -// -// private void execute(Runnable runnable) { -// try { -// runnable.run(); -// } catch (Exception e) { -// log.warn("close tcp server error", e); -// } -// } -// -// -// public void sendMsg(DeviceMessage message) { -// VertxTcpClient client = clientMap.get(message.getDeviceName()); -// if (client != null) { -// client.sendMessage(Buffer.buffer(message.getContent().toString())); -// } -// } -// -// /** -// * 递归断开连接 -// */ -// private void clientDisconnect(String deviceName) { -// VertxTcpClient remove = clientMap.remove(deviceName); -// if (null != remove) { -// executor.onReceive(null, "disconnect", deviceName); -// if (remove.hasParent()) { -// List childClients = clientMap.values().stream().filter(cl -> cl.hasParent() && cl.getParentName() -// .equals(remove.getParentName())).collect(Collectors.toList()); -// childClients.forEach(child -> clientDisconnect(child.getDeviceName())); -// } -// } -// } -// -// public void offlineDev(String deviceName) { -// VertxTcpClient remove = clientMap.remove(deviceName); -// if (null != remove) { -// if (remove.hasParent()) { -// List childClients = clientMap.values().stream().filter(cl -> cl.hasParent() && cl.getParentName() -// .equals(remove.getParentName())).collect(Collectors.toList()); -// childClients.forEach(child -> offlineDev(child.getDeviceName())); -// } -// } -// } -//} diff --git a/iot-components/iot-component-tcp/src/main/resources/component.spi b/iot-components/iot-component-tcp/src/main/resources/component.spi deleted file mode 100644 index 755eb05f..00000000 --- a/iot-components/iot-component-tcp/src/main/resources/component.spi +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.comp.TcpDeviceComponent \ No newline at end of file diff --git a/iot-components/iot-component-tcp/src/main/resources/scriptParser.js b/iot-components/iot-component-tcp/src/main/resources/scriptParser.js deleted file mode 100644 index b40625ef..00000000 --- a/iot-components/iot-component-tcp/src/main/resources/scriptParser.js +++ /dev/null @@ -1,6 +0,0 @@ -this.payloadParser = function (parser) { - parser.delimited("\r\n") - .handler(function(buffer){ - parser.result(buffer.toString("UTF-8")).complete(); - }); -} \ No newline at end of file diff --git a/iot-components/iot-ctwing-component/.DS_Store b/iot-components/iot-ctwing-component/.DS_Store deleted file mode 100755 index 5008ddfc..00000000 Binary files a/iot-components/iot-ctwing-component/.DS_Store and /dev/null differ diff --git a/iot-components/iot-ctwing-component/lib/ag-sdk-biz-84356.tar.gz-20220603.182201-SNAPSHOT.jar b/iot-components/iot-ctwing-component/lib/ag-sdk-biz-84356.tar.gz-20220603.182201-SNAPSHOT.jar deleted file mode 100644 index 2648a2b3..00000000 Binary files a/iot-components/iot-ctwing-component/lib/ag-sdk-biz-84356.tar.gz-20220603.182201-SNAPSHOT.jar and /dev/null differ diff --git a/iot-components/iot-ctwing-component/lib/ctg-ag-sdk-core-2.5.0-20220512.061430-51.jar b/iot-components/iot-ctwing-component/lib/ctg-ag-sdk-core-2.5.0-20220512.061430-51.jar deleted file mode 100644 index 2c9585be..00000000 Binary files a/iot-components/iot-ctwing-component/lib/ctg-ag-sdk-core-2.5.0-20220512.061430-51.jar and /dev/null differ diff --git a/iot-components/iot-ctwing-component/pom.xml b/iot-components/iot-ctwing-component/pom.xml deleted file mode 100644 index 0cefdd8c..00000000 --- a/iot-components/iot-ctwing-component/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - iot-components - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-ctwing-component - - - - - cc.iotkit - iot-component-base - - - - - - org.projectlombok - lombok - - - - io.vertx - vertx-web-proxy - - - - com.ctg.ag - ctg-ag-sdk-core - 2.5.0-SNAPSHOT - - - - com.ctg.ag - ag-sdk-biz-84356.tar.gz - 20220603.182201-SNAPSHOT - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - - io.vertx:vertx-web-proxy - io.vertx:vertx-web - io.vertx:vertx-bridge-common - io.vertx:vertx-http-proxy - io.vertx:vertx-core - io.netty:netty-codec-http2 - com.ctg.ag:ctg-ag-sdk-core - com.ctg.ag:ag-sdk-biz-84356.tar.gz - org.apache.httpcomponents:httpasyncclient - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 11 - 11 - - - - - - \ No newline at end of file diff --git a/iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingConfig.java b/iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingConfig.java deleted file mode 100644 index aca06a73..00000000 --- a/iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.http; - -import lombok.Data; - -@Data -public class CtwingConfig { - - private int port; - - /** - * ctwing推送消息加解密token - */ - private String encryptToken; - - /** - * ctwing应用的appKey - */ - private String appKey; - - /** - * ctwing应用的appSecret - */ - private String appSecret; - -} diff --git a/iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingDeviceComponent.java b/iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingDeviceComponent.java deleted file mode 100644 index 5d6372ca..00000000 --- a/iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/CtwingDeviceComponent.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.http; - -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.CodecUtil; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.AbstractDeviceComponent; -import cc.iotkit.comp.CompConfig; -import cc.iotkit.converter.DeviceMessage; -import com.ctg.ag.sdk.biz.AepDeviceCommandClient; -import com.ctg.ag.sdk.biz.aep_device_command.CreateCommandRequest; -import com.ctg.ag.sdk.biz.aep_device_command.CreateCommandResponse; -import io.vertx.core.Vertx; -import io.vertx.core.http.HttpServer; -import io.vertx.core.http.HttpServerRequest; -import io.vertx.ext.web.Router; -import io.vertx.ext.web.handler.BodyHandler; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.beanutils.BeanUtils; - -import java.util.List; -import java.util.Map; - -/** - * 电信天翼接入组件 - */ -@Slf4j -public class CtwingDeviceComponent extends AbstractDeviceComponent { - - private final Vertx vertx = Vertx.vertx(); - - private CtwingConfig ctwingConfig; - - private HttpServer backendServer; - - private AepDeviceCommandClient commandClient; - - @Override - public void create(CompConfig config) { - super.create(config); - this.ctwingConfig = JsonUtils.parseObject(config.getOther(), CtwingConfig.class); - commandClient = AepDeviceCommandClient.newClient() - .appKey(ctwingConfig.getAppKey()) - .appSecret(ctwingConfig.getAppSecret()) - .build(); - } - - @Override - public void start() { - backendServer = vertx.createHttpServer(); - Router backendRouter = Router.router(vertx); - - backendRouter.route().handler(BodyHandler.create()) - .handler(rc -> { - try { - Map httpHeader = ProtocolUtil.getData(rc.request().headers()); - log.info("request header:{}", JsonUtils.toJsonString(httpHeader)); - Map> httpParams = ProtocolUtil.getListData(rc.request().params()); - log.info("request params:{}", JsonUtils.toJsonString(httpParams)); - - HttpServerRequest httpRequest = rc.request(); - String contentType = httpRequest.headers().get("Content-Type"); - String requestBody = ""; - int responseCode = 500; - if ("application/json".equals(contentType)) { - requestBody = rc.getBody().toString(); - EncodedMessage msg = JsonUtils.parseObject(requestBody, EncodedMessage.class); - String content = CodecUtil.aesDecrypt(ctwingConfig.getEncryptToken(), msg.getEnc_msg()); - log.info("decrypt msg:{}", content); - getHandler().onReceive(httpHeader, "", content); - responseCode = 200; - } - log.info("request body:{}", requestBody); - - rc.response().setStatusCode(responseCode) - .end(); - } catch (Throwable e) { - log.error("handle request error", e); - rc.response().setStatusCode(500).end(); - } - }); - - backendServer.requestHandler(backendRouter) - .listen(ctwingConfig.getPort(), (http) -> { - if (http.succeeded()) { - log.info("http server create succeed,port:{}", ctwingConfig.getPort()); - } else { - log.error("http server create failed", http.cause()); - } - }); - } - - @Override - public DeviceMessage send(DeviceMessage message) { - Object obj = message.getContent(); - if (!(obj instanceof Map)) { - throw new BizException(ErrCode.DATA_FORMAT_ERROR); - } - SendContent msg = new SendContent(); - try { - BeanUtils.populate(msg, (Map) obj); - } catch (Throwable e) { - throw new BizException(ErrCode.DATA_FORMAT_ERROR); - } - - CreateCommandRequest request = new CreateCommandRequest(); - request.setParamMasterKey(msg.getMasterKey()); - request.setBody(("{\n" + - " \"content\":{\n" + - " \"dataType\":2,\n" + - " \"payload\":\"" + msg.getPayload() + "\"\n" + - " },\n" + - " \"deviceId\":\"" + message.getDeviceName() + "\",\n" + - " \"operator\":\"none\",\n" + - " \"productId\":" + msg.getProductId() + ",\n" + - " \"ttl\":0,\n" + - " \"level\":1\n" + - "}").getBytes()); - CreateCommandResponse response; - try { - response = commandClient.CreateCommand(request); - } catch (Exception e) { - throw new BizException("send cmd to ctwing error", e); - } - - String body = new String(response.getBody()); - log.info("send ctwing cmd result:{}", body); - if (response.getStatusCode() != 200) { - throw new BizException("send cmd to ctwing error:" + body); - } - - CtwingCmdRsp cmdRsp = JsonUtils.parseObject(body, CtwingCmdRsp.class); - if (cmdRsp.code != 0) { - throw new BizException("send cmd to ctwing failed:" + body); - } - - return message; - } - - @Override - public void stop() { - backendServer.close(); - } - - @Override - public void destroy() { - } - - /** - * 将数据编码成68H16H协议数据包,给js调用 - */ - public String encode68H16H(String devId, String cardNo, Object[] values) { - return ProtocolUtil.encode68H16H(devId, cardNo, values); - } - - /** - * 将68H16H协议的base64字符串消息解码为map数据,给js调用 - */ - public Map decode68H16H(String base64Str) { - return ProtocolUtil.decode68H16H(base64Str); - } - - @Data - public static class EncodedMessage { - private String msg_signature; - private String enc_msg; - } - - @Data - public static class SendContent { - private String masterKey; - private String productId; - private String payload; - } - - - @Data - public static class CtwingCmdRsp { - private int code; - protected String msg; - protected CmdResult result; - } - - @Data - public static class CmdResult { - private String commandId; - private String command; - private String commandStatus; - private int productId; - private String deviceId; - private String imei; - private String createBy; - private String createTime; - private int ttl; - } - -} diff --git a/iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/ProtocolUtil.java b/iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/ProtocolUtil.java deleted file mode 100644 index 248386f6..00000000 --- a/iot-components/iot-ctwing-component/src/main/java/cc/iotkit/comp/http/ProtocolUtil.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.http; - -import cc.iotkit.common.utils.HexUtil; -import io.vertx.core.MultiMap; - -import java.nio.ByteBuffer; -import java.util.*; - -public class ProtocolUtil { - - /** - * 将数据编码成68H16H协议数据包 - */ - public static String encode68H16H(String devId, String cardNo, Object[] values) { - //构建数据域 - ByteBuffer bufferData = ByteBuffer.allocate(7); - //模拟数据.. - bufferData.put((byte) 1); - bufferData.putShort((short) 4); - bufferData.putInt(100); - byte[] data = bufferData.array(); - - //起始符到卡号部分数据 - ByteBuffer buffer = ByteBuffer.allocate(1 + 2 + 5 + data.length + 4 + 7 + 2); - int len = 1 + 2 + 5 + data.length + 4 + 7 + 2; - buffer.put((byte) len); - buffer.put((byte) 0x68); - buffer.putShort((short) 0); - buffer.put(devId.getBytes()); - buffer.put(data); - buffer.putInt(0); - buffer.put(cardNo.getBytes()); - byte[] data1 = buffer.array(); - - //校验码 - int check = HexUtil.calcCrc16(data1, 0, data1.length); - //完整数据包 - buffer = ByteBuffer.allocate(1 + data1.length + 2 + 1); - buffer.put((byte) (data1.length + 2));//帧长度 - buffer.put(data1);//起始符到卡号部分数据 - buffer.putShort((short) check);//检验码 - buffer.put((byte) 0x16); - return HexUtil.toHexString(buffer.array()); - } - - /** - * 将68H16H协议的base64字符串消息解码为map数据 - */ - public static Map decode68H16H(String base64Str) { - byte[] bytes = Base64.getDecoder().decode(base64Str); - - Map decodeData = new HashMap<>(); - ByteBuffer buffer = ByteBuffer.wrap(bytes); - buffer.flip(); - byte len = buffer.get();//帧长度 - buffer.get();//帧起始符 - buffer.getShort();//预留2byte - byte[] devId = new byte[5];//设备ID - buffer.get(devId, 0, 5); - String strDevId = new String(devId); - decodeData.put("devId", strDevId); - - //数据域长度=帧长度-起始符-预留-设备ID-系统用-卡号-校验码 - int dataLen = len - 1 - 2 - 5 - 4 - 7 - 2; - //数据域 - byte[] data = new byte[dataLen]; - buffer.get(data, 0, dataLen); - Object[] values = ProtocolUtil.getTlvValues(data); - //模拟取1个值 - decodeData.put("flow", values[0]); - - buffer.getInt();//系统用 - //卡号 - byte[] card = new byte[7]; - buffer.get(card, 0, card.length); - String cardNo = new String(card); - decodeData.put("cardNo", cardNo); - - return decodeData; - } - - public static Object[] getTlvValues(byte[] data) { - List result = new ArrayList<>(); - - ByteBuffer dataBuff = ByteBuffer.wrap(data); - dataBuff.flip(); - //对数据域解码... - while (dataBuff.hasRemaining()) { - byte t = dataBuff.get(); - byte l = dataBuff.get(); - byte[] bytesV = new byte[l]; - dataBuff.get(bytesV, 0, bytesV.length); - if (t == 0) { - //int - result.add(HexUtil.bytesToInt(bytesV)); - } - //..其它类型 - } - return result.toArray(); - } - - public static Map> getListData(MultiMap multiMap) { - Map> listData = new HashMap<>(); - for (Map.Entry entry : multiMap.entries()) { - String key = entry.getKey(); - Object value = entry.getValue(); - listData.putIfAbsent(key, new ArrayList<>()); - listData.get(key).add(value); - } - return listData; - } - - public 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-components/iot-ctwing-component/src/main/resources/component.js b/iot-components/iot-ctwing-component/src/main/resources/component.js deleted file mode 100644 index 62112b41..00000000 --- a/iot-components/iot-ctwing-component/src/main/resources/component.js +++ /dev/null @@ -1,36 +0,0 @@ -//引用api工具类 -var apiTool = Java.type("cc.iotkit.comp.biz.ApiTool"); -//api配置 -apiTool.config("http://localhost",8086,3000); - -this.onReceive=function(method,path,header,params,body){ - //method:post、get、delete... - //path:请求路径 - //header:http请求头数据,结构:{xx:xx,yy:yy} - //params:请求参数,结构:{xx:[...],yy:[...]} - //body:请求体,当提交的数据为json格式时使用,结构:{xx:xx,yy:yy} - apiTool.log("onReceive method:"+method); - apiTool.log("onReceive path:"+path); - apiTool.log("onReceive header:"+header); - apiTool.log("onReceive params:"+params); - apiTool.log("onReceive body:"+body); - var duHeader=body.header; - var namespace=duHeader.namespace; - var requestName=duHeader.name; - var messageId=duHeader.messageId; - var duPayload=duHeader.payload; - var token=duHeader.accessToken; - - //设备发现 - if(namespace=="DuerOS.ConnectedHome.Discovery" && requestName=="DiscoverAppliancesRequest"){ - - } - - return { - url:"xx",//不指定直接作为响应返回 - header:{ - contentType:"xx" - }, - content:"xx" - } -} \ No newline at end of file diff --git a/iot-components/iot-ctwing-component/src/main/resources/component.spi b/iot-components/iot-ctwing-component/src/main/resources/component.spi deleted file mode 100644 index 51335f33..00000000 --- a/iot-components/iot-ctwing-component/src/main/resources/component.spi +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.comp.http.CtwingDeviceComponent \ No newline at end of file diff --git a/iot-components/iot-emqx-component/.DS_Store b/iot-components/iot-emqx-component/.DS_Store deleted file mode 100755 index 5008ddfc..00000000 Binary files a/iot-components/iot-emqx-component/.DS_Store and /dev/null differ diff --git a/iot-components/iot-emqx-component/emqx_rule_data.json b/iot-components/iot-emqx-component/emqx_rule_data.json deleted file mode 100644 index 9db7184b..00000000 --- a/iot-components/iot-emqx-component/emqx_rule_data.json +++ /dev/null @@ -1,185 +0,0 @@ -{ - "data":[ - { - "rawsql":"SELECT\n reason,\n clientid,\n username,\n peername,\n socketname\nFROM\n \"$events/client_connected\"", - "on_action_failed":"continue", - "metrics":[ - { - "speed_max":0, - "speed_last5m":0, - "speed":0, - "passed":0, - "node":"emqx@127.0.0.1", - "no_result":0, - "matched":0, - "failed":0, - "exception":0 - } - ], - "id":"rule:012980", - "for":[ - "$events/client_connected" - ], - "enabled":true, - "description":" 连接", - "actions":[ - { - "params":{ - "target_topic":"/sys/client/connected", - "target_qos":1, - "payload_tmpl":"{\"reason\":\"${reason}\",\"clientid\":\"${clientid}\",\"username\":\"${username}\",\"peername\":\"${peername}\",\"socketname\":\"${socketname}\"}" - }, - "name":"republish", - "metrics":[ - { - "taken":0, - "success":0, - "node":"emqx@127.0.0.1", - "failed":0 - } - ], - "id":"republish_16528854106752092", - "fallbacks":[ - - ] - } - ] - }, - { - "rawsql":"SELECT\n reason,\n clientid,\n username,\n peername,\n socketname\nFROM\n \"$events/client_disconnected\"", - "on_action_failed":"continue", - "metrics":[ - { - "speed_max":0, - "speed_last5m":0, - "speed":0, - "passed":0, - "node":"emqx@127.0.0.1", - "no_result":0, - "matched":0, - "failed":0, - "exception":0 - } - ], - "id":"rule:377397", - "for":[ - "$events/client_disconnected" - ], - "enabled":true, - "description":"断开连接", - "actions":[ - { - "params":{ - "target_topic":"/sys/client/disconnected", - "target_qos":0, - "payload_tmpl":"{\"reason\":\"${reason}\",\"clientid\":\"${clientid}\",\"username\":\"${username}\",\"peername\":\"${peername}\",\"socketname\":\"${socketname}\"}" - }, - "name":"republish", - "metrics":[ - { - "taken":0, - "success":0, - "node":"emqx@127.0.0.1", - "failed":0 - } - ], - "id":"republish_16528854190433372", - "fallbacks":[ - - ] - } - ] - }, - { - "rawsql":"SELECT\n clientid,\n username,\n topic,\n qos\nFROM\n \"$events/session_subscribed\"", - "on_action_failed":"continue", - "metrics":[ - { - "speed_max":0, - "speed_last5m":0, - "speed":0, - "passed":0, - "node":"emqx@127.0.0.1", - "no_result":0, - "matched":0, - "failed":0, - "exception":0 - } - ], - "id":"rule:758695", - "for":[ - "$events/session_subscribed" - ], - "enabled":true, - "description":"子设备注册成功后,订阅topic: /sys/{productKey}/{deviceName}/c/#", - "actions":[ - { - "params":{ - "target_topic":"/sys/session/subscribed", - "target_qos":1, - "payload_tmpl":"{\"username\":\"${username}\",\"topic\":\"${topic}\",\"qos\":\"${qos}\",\"clientid\":\"${clientid}\"}" - }, - "name":"republish", - "metrics":[ - { - "taken":0, - "success":0, - "node":"emqx@127.0.0.1", - "failed":0 - } - ], - "id":"republish_16530236276902029", - "fallbacks":[ - - ] - } - ] - }, - { - "rawsql":"SELECT\n clientid,\n username,\n topic,\n qos\nFROM\n \"$events/session_unsubscribed\"", - "on_action_failed":"continue", - "metrics":[ - { - "speed_max":0, - "speed_last5m":0, - "speed":0, - "passed":0, - "node":"emqx@127.0.0.1", - "no_result":0, - "matched":0, - "failed":0, - "exception":0 - } - ], - "id":"rule:514503", - "for":[ - "$events/session_unsubscribed" - ], - "enabled":true, - "description":"", - "actions":[ - { - "params":{ - "target_topic":"/sys/session/unsubscribed", - "target_qos":0, - "payload_tmpl":"{\"username\":\"${username}\",\"topic\":\"${topic}\",\"qos\":\"${qos}\",\"clientid\":\"${clientid}\"}" - }, - "name":"republish", - "metrics":[ - { - "taken":0, - "success":0, - "node":"emqx@127.0.0.1", - "failed":0 - } - ], - "id":"republish_16530237303922829", - "fallbacks":[ - - ] - } - ] - } - ], - "code":0 -} \ No newline at end of file diff --git a/iot-components/iot-emqx-component/pom.xml b/iot-components/iot-emqx-component/pom.xml deleted file mode 100755 index 1ee09205..00000000 --- a/iot-components/iot-emqx-component/pom.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - iot-components - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-emqx-component - - - - - cc.iotkit - iot-common-model - - - - cc.iotkit - iot-common-core - - - - cc.iotkit - iot-component-base - - - - cc.iotkit - iot-data-service - - - - cc.iotkit - iot-script-engine - - - - - io.vertx - vertx-core - - - - io.vertx - vertx-web-proxy - - - - io.vertx - vertx-mqtt - - - - org.luaj - luaj-jse - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - - - - - - io.vertx:vertx-core - io.vertx:vertx-web-proxy - io.vertx:vertx-mqtt - io.vertx:vertx-web - io.vertx:vertx-http-proxy - - org.luaj:luaj-jse - - io.netty:netty-common - io.netty:netty-transport - io.netty:netty-handler - io.netty:netty-resolver - io.netty:netty-buffer - io.netty:netty-handler - io.netty:netty-proxy - io.netty:netty-codec - io.netty:netty-codec-mqtt - io.netty:netty-codec-dns - io.netty:netty-resolver-dns - - io.netty:netty-tcnative-boringssl-static - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - true - false - utf8 - - - - - - diff --git a/iot-components/iot-emqx-component/readme.md b/iot-components/iot-emqx-component/readme.md deleted file mode 100644 index 1be0885d..00000000 --- a/iot-components/iot-emqx-component/readme.md +++ /dev/null @@ -1,6 +0,0 @@ -## EMQX配置 - -接入emqx需要在EMQX的规则引擎界面新增订阅、取消订阅、连接、断开连接的消息转发。 - -配置内容见:emqx_rule_data.json - diff --git a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/AuthVerticle.java b/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/AuthVerticle.java deleted file mode 100755 index eabfea65..00000000 --- a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/AuthVerticle.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.emqx; - -import cc.iotkit.comp.IMessageHandler; -import io.vertx.core.AbstractVerticle; -import io.vertx.core.http.HttpMethod; -import io.vertx.core.http.HttpServer; -import io.vertx.core.http.HttpServerResponse; -import io.vertx.ext.web.Router; -import io.vertx.ext.web.handler.BodyHandler; -import lombok.extern.slf4j.Slf4j; - -import java.util.HashMap; -import java.util.Map; - -@Slf4j -public class AuthVerticle extends AbstractVerticle { - - private HttpServer backendServer; - - private IMessageHandler executor; - - private final EmqxConfig config; - - public void setExecutor(IMessageHandler executor) { - this.executor = executor; - } - - public AuthVerticle(EmqxConfig config) { - this.config = config; - } - - @Override - public void start() { - backendServer = vertx.createHttpServer(); - - //第一步 声明Router&初始化Router - Router backendRouter = Router.router(vertx); - //获取body参数,得先添加这句 - backendRouter.route().handler(BodyHandler.create()); - - //第二步 配置Router解析url - backendRouter.route(HttpMethod.POST, "/mqtt/auth").handler(rc -> { - String json = rc.getBodyAsString(); - log.info("mqtt auth:{}", json); - try { - Map head = new HashMap<>(); - head.put("topic", "/mqtt/auth"); - executor.onReceive(head, "auth", json); - httpResult(rc.response(), 200); - } catch (Throwable e) { - httpResult(rc.response(), 500); - log.error("mqtt auth failed", e); - } - }); - backendRouter.route(HttpMethod.POST, "/mqtt/acl").handler(rc -> { - String json = rc.getBodyAsString(); - log.info("mqtt acl:{}", json); - try { - Map head = new HashMap<>(); - head.put("topic", "/mqtt/acl"); - executor.onReceive(head, "acl", json); - httpResult(rc.response(), 200); - } catch (Throwable e) { - httpResult(rc.response(), 500); - log.error("mqtt acl failed", e); - } - }); - - backendServer.requestHandler(backendRouter).listen(config.getAuthPort()); - } - - private void httpResult(HttpServerResponse response, int code) { - response.putHeader("Content-Type", "application/json"); - response - .setStatusCode(code); - response - .end("{\"result\": \"" + (code == 200 ? "allow" : "deny") + "\"}"); - } - - @Override - public void stop() throws Exception { - backendServer.close(voidAsyncResult -> log.info("close emqx auth server...")); - } -} diff --git a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/EmqxConfig.java b/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/EmqxConfig.java deleted file mode 100755 index 371be668..00000000 --- a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/EmqxConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.emqx; - -import lombok.Data; - -import java.util.List; - -@Data -public class EmqxConfig { - - private int authPort; - - private String broker; - - private int port; - - private boolean ssl; - - private String clientId; - - private String username; - - private String password; - - private List subscribeTopics; -} diff --git a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/EmqxDeviceComponent.java b/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/EmqxDeviceComponent.java deleted file mode 100755 index a872231b..00000000 --- a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/EmqxDeviceComponent.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.emqx; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.common.utils.SpringUtils; -import cc.iotkit.common.utils.ThreadUtil; -import cc.iotkit.comp.AbstractDeviceComponent; -import cc.iotkit.comp.CompConfig; -import cc.iotkit.comp.IMessageHandler; -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.converter.DeviceMessage; -import cc.iotkit.data.manager.IDeviceInfoData; -import cc.iotkit.model.device.DeviceInfo; -import cc.iotkit.model.device.message.ThingModelMessage; -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.*; -import org.apache.commons.beanutils.BeanUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.InvocationTargetException; -import java.nio.charset.Charset; -import java.util.*; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - - -public class EmqxDeviceComponent extends AbstractDeviceComponent implements Runnable { - - private static final Logger log = LoggerFactory.getLogger(EmqxDeviceComponent.class); - private Vertx vertx; - private AuthVerticle authVerticle; - private CountDownLatch countDownLatch; - private String deployedId; - private EmqxConfig mqttConfig; - private MqttClient client; - private boolean mqttConnected = false; - private final ScheduledThreadPoolExecutor emqxConnectTask = ThreadUtil.newScheduled(1, "emqx_connect"); - - /** - * 组件mqtt clientId,默认通过mqtt auth / acl验证。 - */ - private final Set compMqttClientIdList = new HashSet<>(); - - private final TransparentConverter transparentConverter = new TransparentConverter(); - - @Override - public void create(CompConfig config) { - super.create(config); - vertx = Vertx.vertx(); - mqttConfig = JsonUtils.parseObject(config.getOther(), EmqxConfig.class); - authVerticle = new AuthVerticle(mqttConfig); - } - - @Override - public void start() { - try { - compMqttClientIdList.add(mqttConfig.getClientId()); - authVerticle.setExecutor(getHandler()); - countDownLatch = new CountDownLatch(1); - Future future = vertx.deployVerticle(authVerticle); - future.onSuccess((s -> { - deployedId = s; - countDownLatch.countDown(); - log.info("start emqx auth component success"); - })); - future.onFailure(e -> { - countDownLatch.countDown(); - log.error("start emqx auth component failed", e); - }); - countDownLatch.await(); - - emqxConnectTask.scheduleWithFixedDelay(this, 0, 3, TimeUnit.SECONDS); - } catch (Throwable e) { - throw new BizException(ErrCode.COMPONENT_START_ERROR, e); - } - } - - @Override - public void run() { - try { - if (mqttConnected) { - return; - } - - MqttClientOptions options = new MqttClientOptions() - .setClientId(mqttConfig.getClientId()) - .setUsername(mqttConfig.getUsername()) - .setPassword(mqttConfig.getPassword()) - .setCleanSession(true) - .setKeepAliveInterval(60); - - - if (mqttConfig.isSsl()) { - options.setSsl(true) - .setTrustAll(true); - } - client = MqttClient.create(vertx, options); - - List topics = mqttConfig.getSubscribeTopics(); - Map subscribes = new HashMap<>(); - - for (String topic : topics) { - subscribes.put(topic, 1); - } - - client.publishHandler(p -> { - log.info("Client received message on [{}] payload [{}] with QoS [{}]", p.topicName(), p.payload().toString(Charset.defaultCharset()), p.qosLevel()); - - String topic = p.topicName(); - String payload = p.payload().toString(); - - try { - IMessageHandler messageHandler = getHandler(); - if (messageHandler != null) { - Map head = new HashMap<>(); - head.put("topic", topic); - messageHandler.onReceive(head, "", payload); - - } - } catch (Exception e) { - log.error("message is illegal.", e); - } - }); - - client.connect(mqttConfig.getPort(), mqttConfig.getBroker(), s -> { - if (s.succeeded()) { - log.info("client connect success."); - mqttConnected = true; - /* - * 订阅主题: - * /sys/+/+/s/# - * /sys/client/connected - * /sys/client/disconnected - * /sys/session/subscribed - * /sys/session/unsubscribed - */ - client.subscribe(subscribes, e -> { - if (e.succeeded()) { - log.info("===>subscribe success: {}", e.result()); - } else { - log.error("===>subscribe fail: ", e.cause()); - } - }); - - } else { - mqttConnected = false; - log.error("client connect fail: ", s.cause()); - } - }).exceptionHandler(event -> log.error("client fail", event)); - - } catch (Throwable e) { - throw new BizException(ErrCode.COMPONENT_START_ERROR, e); - } - } - - @SneakyThrows - @Override - public void stop() { - authVerticle.stop(); - Future future = vertx.undeploy(deployedId); - future.onSuccess(unused -> log.info("stop emqx auth component success")); - - client.disconnect() - .onSuccess(unused -> { - mqttConnected = false; - log.info("stop emqx component success"); - }) - .onFailure(unused -> log.info("stop emqx component failure")); - - emqxConnectTask.shutdown(); - } - - @Override - public void destroy() { - - } - - @Override - public void onDeviceStateChange(DeviceState state) { - DeviceState.Parent parent = state.getParent(); - if (parent == null) { - return; - } - IDeviceInfoData deviceInfoService = SpringUtils.getBean("deviceInfoDataCache"); - - DeviceInfo deviceInfo = deviceInfoService.findByDeviceName(state.getDeviceName()); - if (deviceInfo != null) { - boolean isOnline = DeviceState.STATE_ONLINE.equals(state.getState()); - deviceInfo.getState().setOnline(isOnline); - if (!isOnline) { - deviceInfo.getState().setOfflineTime(System.currentTimeMillis()); - } - if (isOnline) { - deviceInfo.getState().setOnlineTime(System.currentTimeMillis()); - } - deviceInfoService.save(deviceInfo); - } - } - - @Override - public DeviceMessage send(DeviceMessage message) { - Object obj = message.getContent(); - if (!(obj instanceof Map)) { - throw new BizException(ErrCode.DATA_FORMAT_ERROR); - } - Message msg = new Message(); - try { - //obj中的key,如果bean中有这个属性,就把这个key对应的value值赋给msg的属性 - BeanUtils.populate(msg, (Map) obj); - } catch (Throwable e) { - throw new BizException(ErrCode.DATA_FORMAT_ERROR); - } - - log.info("publish topic:{},payload:{}", msg.getTopic(), msg.getPayload()); - - client.publish(msg.getTopic(), - Buffer.buffer(msg.getPayload()), - MqttQoS.AT_LEAST_ONCE, - false, - false); - - return message; - } - - /** - * 透传解码 - */ - public ThingModelMessage transparentDecode(Map msg) throws InvocationTargetException, IllegalAccessException { - TransparentMsg transparentMsg = new TransparentMsg(); - BeanUtils.populate(transparentMsg, msg); - return transparentConverter.decode(transparentMsg); - } - - /** - * 透传编码 - */ - public DeviceMessage transparentEncode(ThingService service, cc.iotkit.converter.Device device) { - return transparentConverter.encode(service, device); - } - - /** - * 提供js调用 - */ - public Object getCompMqttClientIdList() { - String[] result = compMqttClientIdList.toArray(new String[0]); - return JsonUtils.toJsonString(result); - } - - @Data - public static class Message { - private String topic; - private String payload; - } - - @Data - @NoArgsConstructor - @AllArgsConstructor - @ToString - public static class Device { - private String productKey; - private String deviceName; - } -} diff --git a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/IScripter.java b/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/IScripter.java deleted file mode 100755 index cd8076df..00000000 --- a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/IScripter.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.emqx; - -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.model.device.message.ThingModelMessage; - -public interface IScripter { - - void setScript(String script); - - /** - * 透传解码 - */ - ThingModelMessage decode(TransparentMsg msg); - - /** - * 透传编码 - */ - TransparentMsg encode(ThingService service); -} diff --git a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/JsScripter.java b/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/JsScripter.java deleted file mode 100755 index 47238686..00000000 --- a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/JsScripter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.emqx; - -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.model.product.ProductModel; -import cc.iotkit.script.IScriptEngine; -import cc.iotkit.script.ScriptEngineFactory; -import com.fasterxml.jackson.core.type.TypeReference; -import lombok.Data; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Data -public class JsScripter implements IScripter { - - private ProductModel model; - - private Object scriptObj; - - private IScriptEngine scriptEngine = ScriptEngineFactory.getScriptEngine("js"); - - public JsScripter(ProductModel model) { - this.model = model; - } - - @SneakyThrows - @Override - public void setScript(String script) { - scriptEngine.setScript(script); - } - - @SneakyThrows - public ThingModelMessage decode(TransparentMsg msg) { - return scriptEngine.invokeMethod(new TypeReference<>() { - }, "decode", msg); - } - - @SneakyThrows - public TransparentMsg encode(ThingService service) { - return scriptEngine.invokeMethod(new TypeReference<>() { - }, "encode", service); - } -} diff --git a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/LuaScripter.java b/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/LuaScripter.java deleted file mode 100755 index 73472b09..00000000 --- a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/LuaScripter.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.emqx; - -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.model.product.ProductModel; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.beanutils.BeanUtils; -import org.luaj.vm2.LuaTable; -import org.luaj.vm2.LuaValue; -import org.luaj.vm2.script.LuaScriptEngine; - -import javax.script.Compilable; -import javax.script.CompiledScript; -import javax.script.ScriptEngineManager; -import javax.script.SimpleBindings; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Slf4j -@Data -public class LuaScripter implements IScripter { - - private ProductModel model; - - private final LuaScriptEngine engine = (LuaScriptEngine) ( - new ScriptEngineManager().getEngineByName("luaj")); - - private LuaValue decoder; - private LuaValue encoder; - - public LuaScripter(ProductModel model) { - this.model = model; - } - - @Override - public void setScript(String script) { - try { - CompiledScript compiledScript = ((Compilable) engine).compile(script); - SimpleBindings bindings = new SimpleBindings(); - compiledScript.eval(bindings); - decoder = (LuaValue) bindings.get("decode"); - encoder = (LuaValue) bindings.get("encode"); - } catch (Throwable e) { - log.error("compile script error", e); - } - } - - @Override - public ThingModelMessage decode(TransparentMsg msg) { - try { - LuaTable table = new LuaTable(); - table.set("model", msg.getModel()); - table.set("deviceName", msg.getDeviceName()); - table.set("data", msg.getData()); - Map result = (Map) parse(decoder.call(table)); - ThingModelMessage modelMessage = new ThingModelMessage(); - BeanUtils.populate(modelMessage, result); - - modelMessage.setProductKey(msg.getProductKey()); - modelMessage.setDeviceName(msg.getDeviceName()); - return modelMessage; - } catch (Throwable e) { - log.error("execute decode script error", e); - } - return null; - } - - @Override - public TransparentMsg encode(ThingService service) { - try { - LuaTable table = new LuaTable(); - table.set("identifier", service.getIdentifier()); - table.set("type", service.getType()); - table.set("productKey", service.getProductKey()); - table.set("deviceName", service.getDeviceName()); - table.set("mid", service.getMid()); - Object params = service.getParams(); - LuaTable tableParams = new LuaTable(); - if (params instanceof Map) { - ((Map) params).forEach((key, val) -> tableParams.set(key.toString(), parse(val))); - } - table.set("params", tableParams); - LuaValue result = encoder.call(table); - Map map = (Map) parse(result); - TransparentMsg message = new TransparentMsg(); - BeanUtils.populate(message, map); - message.setProductKey(model.getProductKey()); - message.setModel(model.getModel()); - message.setDeviceName(service.getDeviceName()); - return message; - } catch (Throwable e) { - log.error("execute encode script error", e); - } - return null; - } - - private Object parse(LuaValue value) { - String type = value.typename(); - switch (type) { - case "string": - return value.toString(); - case "number": - case "int": - return value.toint(); - case "table": - Map data = new HashMap<>(); - LuaTable table = (LuaTable) value; - int arrLen = table.rawlen(); - if (arrLen > 0) { - //数组转换 - List list = new ArrayList<>(); - for (LuaValue key : table.keys()) { - list.add(parse(table.get(key))); - } - return list; - } else { - //map转换 - for (LuaValue key : table.keys()) { - data.put(key.toString(), parse(table.get(key))); - } - } - return data; - } - return null; - } - - private LuaValue parse(Object value) { - if (value instanceof String) { - return LuaValue.valueOf(value.toString()); - } - if (value instanceof Integer) { - return LuaValue.valueOf((Integer) value); - } - return new LuaTable(); - } - -} diff --git a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentConverter.java b/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentConverter.java deleted file mode 100755 index a3dca0bb..00000000 --- a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentConverter.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.emqx; - - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.common.utils.SpringUtils; -import cc.iotkit.converter.Device; -import cc.iotkit.converter.DeviceMessage; -import cc.iotkit.data.manager.IDeviceInfoData; -import cc.iotkit.data.manager.IProductModelData; -import cc.iotkit.model.device.DeviceInfo; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.model.product.ProductModel; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -import java.util.HashMap; -import java.util.Map; - -@Slf4j -public class TransparentConverter { - - private final Map scripters = new HashMap<>(); - private final Map scripts = new HashMap<>(); - - private IDeviceInfoData deviceInfoData; - private IProductModelData productModelData; - - /** - * 透传解码 - */ - public ThingModelMessage decode(TransparentMsg msg) { - String productKey = msg.getProductKey(); - productKey = checkScriptUpdate(productKey, msg.getModel()); - msg.setProductKey(productKey); - ThingModelMessage decodeMsg = scripters.get(productKey).decode(msg); - decodeMsg.setProductKey(msg.getProductKey()); - decodeMsg.setDeviceName(msg.getDeviceName()); - return decodeMsg; - } - - /** - * 透传编码 - */ - public DeviceMessage encode(ThingService service, Device device) { - String productKey = service.getProductKey(); - checkScriptUpdate(productKey, device.getModel()); - TransparentMsg transparentMsg = scripters.get(productKey).encode(service); - //转换成网关消息 - String deviceName = service.getDeviceName(); - DeviceInfo gateway = getGatewayInfo(productKey, deviceName); - DeviceMessage message = new DeviceMessage(); - message.setProductKey(gateway.getProductKey()); - message.setDeviceName(gateway.getDeviceName()); - message.setMid(transparentMsg.getMid()); - //透传格式消息内容,mac、model、data - message.setContent(transparentMsg); - return message; - } - - private ProductModel getScript(String model) { - if (productModelData == null) { - productModelData = SpringUtils.getBean("productModelDataCache"); - } - - return productModelData.findByModel(model); - } - - private DeviceInfo getGatewayInfo(String subPk, String subDn) { - if (deviceInfoData == null) { - deviceInfoData = SpringUtils.getBean("deviceInfoDataCache"); - } - - String parentId = deviceInfoData.findByDeviceName(subDn).getParentId(); - return deviceInfoData.findByDeviceId(parentId); - } - - /** - * 检查产品脚本是否更新 - */ - private String checkScriptUpdate(String pk, String model) { - ProductModel productModel = null; - if (StringUtils.isNotBlank(model)) { - productModel = getScript(model); - } - //指定型号获取不到获取默认型号 - if (productModel == null && StringUtils.isNotBlank(pk)) { - productModel = getScript(ProductModel.getDefaultModel(pk)); - } - if (productModel == null) { - throw new BizException(ErrCode.MODEL_SCRIPT_NOT_FOUND); - } - - String productKey = productModel.getProductKey(); - String script = productModel.getScript(); - - String oldScript = scripts.get(productKey); - if (script.equals(oldScript)) { - return productKey; - } - - String type = productModel.getType(); - if (ProductModel.TYPE_LUA.equals(type)) { - scripters.putIfAbsent(productKey, new LuaScripter(productModel)); - } else if (ProductModel.TYPE_JS.equals(type)) { - scripters.putIfAbsent(productKey, new JsScripter(productModel)); - } - - //更新脚本 - IScripter scripter = scripters.get(productKey); - scripter.setScript(script); - scripts.put(productKey, script); - return productKey; - } - -} diff --git a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentMsg.java b/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentMsg.java deleted file mode 100755 index 840585a6..00000000 --- a/iot-components/iot-emqx-component/src/main/java/cc/iotkit/comp/emqx/TransparentMsg.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.emqx; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.FieldNameConstants; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -@FieldNameConstants -public class TransparentMsg { - - private String productKey; - - /** - * 生成给设备端的消息id - */ - private String mid; - - private String model; - - private String deviceName; - - private String data; - -} diff --git a/iot-components/iot-emqx-component/src/main/resources/component.js b/iot-components/iot-emqx-component/src/main/resources/component.js deleted file mode 100755 index 92b62ccb..00000000 --- a/iot-components/iot-emqx-component/src/main/resources/component.js +++ /dev/null @@ -1,381 +0,0 @@ -!function (n) { - "use strict"; - - function d(n, t) { - var r = (65535 & n) + (65535 & t); - return (n >> 16) + (t >> 16) + (r >> 16) << 16 | 65535 & r - } - - function f(n, t, r, e, o, u) { - return d((u = d(d(t, n), d(e, u))) << o | u >>> 32 - o, r) - } - - function l(n, t, r, e, o, u, c) { - return f(t & r | ~t & e, n, t, o, u, c) - } - - function g(n, t, r, e, o, u, c) { - return f(t & e | r & ~e, n, t, o, u, c) - } - - function v(n, t, r, e, o, u, c) { - return f(t ^ r ^ e, n, t, o, u, c) - } - - function m(n, t, r, e, o, u, c) { - return f(r ^ (t | ~e), n, t, o, u, c) - } - - function c(n, t) { - var r, e, o, u; - n[t >> 5] |= 128 << t % 32, n[14 + (t + 64 >>> 9 << 4)] = t; - for (var c = 1732584193, f = -271733879, i = -1732584194, a = 271733878, h = 0; h < n.length; h += 16) c = l(r = c, e = f, o = i, u = a, n[h], 7, -680876936), a = l(a, c, f, i, n[h + 1], 12, -389564586), i = l(i, a, c, f, n[h + 2], 17, 606105819), f = l(f, i, a, c, n[h + 3], 22, -1044525330), c = l(c, f, i, a, n[h + 4], 7, -176418897), a = l(a, c, f, i, n[h + 5], 12, 1200080426), i = l(i, a, c, f, n[h + 6], 17, -1473231341), f = l(f, i, a, c, n[h + 7], 22, -45705983), c = l(c, f, i, a, n[h + 8], 7, 1770035416), a = l(a, c, f, i, n[h + 9], 12, -1958414417), i = l(i, a, c, f, n[h + 10], 17, -42063), f = l(f, i, a, c, n[h + 11], 22, -1990404162), c = l(c, f, i, a, n[h + 12], 7, 1804603682), a = l(a, c, f, i, n[h + 13], 12, -40341101), i = l(i, a, c, f, n[h + 14], 17, -1502002290), c = g(c, f = l(f, i, a, c, n[h + 15], 22, 1236535329), i, a, n[h + 1], 5, -165796510), a = g(a, c, f, i, n[h + 6], 9, -1069501632), i = g(i, a, c, f, n[h + 11], 14, 643717713), f = g(f, i, a, c, n[h], 20, -373897302), c = g(c, f, i, a, n[h + 5], 5, -701558691), a = g(a, c, f, i, n[h + 10], 9, 38016083), i = g(i, a, c, f, n[h + 15], 14, -660478335), f = g(f, i, a, c, n[h + 4], 20, -405537848), c = g(c, f, i, a, n[h + 9], 5, 568446438), a = g(a, c, f, i, n[h + 14], 9, -1019803690), i = g(i, a, c, f, n[h + 3], 14, -187363961), f = g(f, i, a, c, n[h + 8], 20, 1163531501), c = g(c, f, i, a, n[h + 13], 5, -1444681467), a = g(a, c, f, i, n[h + 2], 9, -51403784), i = g(i, a, c, f, n[h + 7], 14, 1735328473), c = v(c, f = g(f, i, a, c, n[h + 12], 20, -1926607734), i, a, n[h + 5], 4, -378558), a = v(a, c, f, i, n[h + 8], 11, -2022574463), i = v(i, a, c, f, n[h + 11], 16, 1839030562), f = v(f, i, a, c, n[h + 14], 23, -35309556), c = v(c, f, i, a, n[h + 1], 4, -1530992060), a = v(a, c, f, i, n[h + 4], 11, 1272893353), i = v(i, a, c, f, n[h + 7], 16, -155497632), f = v(f, i, a, c, n[h + 10], 23, -1094730640), c = v(c, f, i, a, n[h + 13], 4, 681279174), a = v(a, c, f, i, n[h], 11, -358537222), i = v(i, a, c, f, n[h + 3], 16, -722521979), f = v(f, i, a, c, n[h + 6], 23, 76029189), c = v(c, f, i, a, n[h + 9], 4, -640364487), a = v(a, c, f, i, n[h + 12], 11, -421815835), i = v(i, a, c, f, n[h + 15], 16, 530742520), c = m(c, f = v(f, i, a, c, n[h + 2], 23, -995338651), i, a, n[h], 6, -198630844), a = m(a, c, f, i, n[h + 7], 10, 1126891415), i = m(i, a, c, f, n[h + 14], 15, -1416354905), f = m(f, i, a, c, n[h + 5], 21, -57434055), c = m(c, f, i, a, n[h + 12], 6, 1700485571), a = m(a, c, f, i, n[h + 3], 10, -1894986606), i = m(i, a, c, f, n[h + 10], 15, -1051523), f = m(f, i, a, c, n[h + 1], 21, -2054922799), c = m(c, f, i, a, n[h + 8], 6, 1873313359), a = m(a, c, f, i, n[h + 15], 10, -30611744), i = m(i, a, c, f, n[h + 6], 15, -1560198380), f = m(f, i, a, c, n[h + 13], 21, 1309151649), c = m(c, f, i, a, n[h + 4], 6, -145523070), a = m(a, c, f, i, n[h + 11], 10, -1120210379), i = m(i, a, c, f, n[h + 2], 15, 718787259), f = m(f, i, a, c, n[h + 9], 21, -343485551), c = d(c, r), f = d(f, e), i = d(i, o), a = d(a, u); - return [c, f, i, a] - } - - function i(n) { - for (var t = "", r = 32 * n.length, e = 0; e < r; e += 8) t += String.fromCharCode(n[e >> 5] >>> e % 32 & 255); - return t - } - - function a(n) { - var t = []; - for (t[(n.length >> 2) - 1] = void 0, e = 0; e < t.length; e += 1) t[e] = 0; - for (var r = 8 * n.length, e = 0; e < r; e += 8) t[e >> 5] |= (255 & n.charCodeAt(e / 8)) << e % 32; - return t - } - - function e(n) { - for (var t, r = "0123456789abcdef", e = "", o = 0; o < n.length; o += 1) t = n.charCodeAt(o), e += r.charAt(t >>> 4 & 15) + r.charAt(15 & t); - return e - } - - function r(n) { - return unescape(encodeURIComponent(n)) - } - - function o(n) { - return i(c(a(n = r(n)), 8 * n.length)) - } - - function u(n, t) { - return function (n, t) { - var r, e = a(n), o = [], u = []; - for (o[15] = u[15] = void 0, 16 < e.length && (e = c(e, 8 * n.length)), r = 0; r < 16; r += 1) o[r] = 909522486 ^ e[r], u[r] = 1549556828 ^ e[r]; - return t = c(o.concat(a(t)), 512 + 8 * t.length), i(c(u.concat(t), 640)) - }(r(n), r(t)) - } - - function t(n, t, r) { - return t ? r ? u(t, n) : e(u(t, n)) : r ? o(n) : e(o(n)) - } - - "function" == typeof define && define.amd ? define(function () { - return t - }) : "object" == typeof module && module.exports ? module.exports = t : n.md5 = t -}(this); -var md5 = this.md5; - -function isServerId(clientId) { - return JSON.parse(component.getCompMqttClientIdList()).indexOf(clientId) > -1 -} - -function getPkDn(clientId) { - var arr = clientId.split("_"); - return { - pk: arr[0], - dn: arr[1] - }; -} - -function auth(head, type, payload) { - if (isServerId(payload.clientid)) { - return { - type: "serverAuth", - data: { - productKey: "pd", - deviceName: "dn", - } - }; - } - - - var arr = payload.clientid.split("_"); - if (arr.length < 3) { - throw new Error("incorrect clientid:" + payload.clientid); - } - - var pk = arr[0]; - var dn = arr[1]; - var model = arr[2]; - - var product = deviceBehaviour.getProductKey(pk) - var pwd = md5(product.getProductSecret() + payload.clientid); - - if (pwd.toLocaleLowerCase() != payload.password.toLocaleLowerCase()) { - throw new Error("incorrect password"); - } - - - return { - type: "register", - data: { - productKey: pk, - deviceName: dn, - model: model - } - }; -} - -function acl(head, type, payload) { - var _topic = payload.topic; - - if (isServerId(payload.clientid)) { - return { - type: "acl", - data: { - productKey: "pd", - deviceName: "dn", - } - }; - } - - if (/^\/sys\/.+\/.+\/c\/#/i.test(_topic)) { - return subscribe(head, type, payload); - } - if (/^\/sys\/.+\/.+\/s\/.*/i.test(_topic)) { - return subscribe(head, type, payload); - } - -} - -function register(head, type, payload) { - var auth = payload; - var arr = auth.clientid.split("_"); - if (arr.length < 3) { - throw new Error("incorrect clientid:" + auth.clientid); - } - - var pk = arr[0]; - var dn = arr[1]; - var model = arr[2]; - - var product = deviceBehaviour.getProductKey(pk) - var pwd = md5(product.getProductSecret() + auth.clientid); - - if (pwd.toLocaleLowerCase() != auth.password.toLocaleLowerCase()) { - throw new Error("incorrect password"); - } - - return { - type: "register", - data: { - productKey: pk, - deviceName: dn, - model: model - } - }; -} - -function subRegister(topic, parent, payload) { - if (!topic) { - throw new Error("topic is blank") - } - - - var params = payload.params; - - var reply = - { - productKey: parent.productKey, - deviceName: parent.deviceName, - mid: "0", - content: { - topic: topic.replace("/s/", "/c/") + "_reply", - payload: JSON.stringify({ - id: payload.id, - code: 0, - data: { - "productKey": params.productKey, - "deviceName": params.deviceName - } - }) - } - }; - - return { - type: "register", - data: { - productKey: parent.productKey, - deviceName: parent.deviceName, - subDevices: [{ - productKey: params.productKey, - deviceName: params.deviceName, - model: params.model - }] - }, - action: { - type: "ack", - content: JSON.stringify(reply) - } - }; -} - -function disconnect(head, type, payload) { - var clientId = payload.clientid - var device = getPkDn(clientId); - return { - type: "state", - data: { - productKey: device.pk, - deviceName: device.dn, - state: "offline" - } - } -} - -function connect(head, type, payload) { - var clientId = payload.clientid - var device = getPkDn(clientId); - return { - type: "state", - data: { - productKey: device.pk, - deviceName: device.dn, - state: "online" - } - } -} - -function unsubscribe(head, type, payload) { - var topic = payload.topic; - - if (isServerId(payload.clientid)) { - return { - type: "acl", - data: { - productKey: "pd", - deviceName: "dn", - } - }; - } - - var arr = topic.split('/'); - if (arr.length < 6) { - throw new Error("incorrect topic: " + topic) - } - - var pk = arr[2]; - var dn = arr[3]; - - return { - type: "state", - data: { - productKey: pk, - deviceName: dn, - state: "offline" - } - } -} - -function subscribe(head, type, payload) { - var topic = payload.topic; - - if (isServerId(payload.clientid)) { - return { - type: "acl", - data: { - productKey: "pd", - deviceName: "dn", - } - }; - } - - var arr = topic.split('/'); - if (arr.length < 6) { - throw new Error("incorrect topic: " + topic) - } - var pk = arr[2]; - var dn = arr[3]; - - return { - type: "state", - data: { - productKey: pk, - deviceName: dn, - state: "online" - } - } -} - - -var messageHandler = { - "/sys/client/connected": connect, - "/sys/client/disconnected": disconnect, - "/mqtt/auth": auth, - "/mqtt/acl": acl, - "/sys/session/subscribed": subscribe, - "/sys/session/unsubscribed": unsubscribe -} - -//必须提供onReceive方法 -this.onReceive = function (head, type, payload) { - payload = JSON.parse(payload); - - print("======================================================================= "); - print("【message from】: " + (isServerId(payload.clientid) ? "Server" : "Device")); - print("onReceive head: " + JSON.stringify(head)); - print("onReceive type: " + JSON.stringify(type)); - print("onReceive payload: " + JSON.stringify(payload)); - //print("onReceive compMqttClientIdList: "+ component.getCompMqttClientIdList()); - - var result = {}; - var topic = head.topic; - if (!topic) { - - print("【result】: " + JSON.stringify(result)); - print("======================================================================= "); - return result; - } - - var fun = messageHandler[topic]; - - - if (fun) { - result = fun(head, type, payload) - } else { - var arr = topic.split('/'); - if (arr.length < 6) { - throw new Error("incorrect topic: " + topic) - } - var pk = arr[2]; - var dn = arr[3]; - - //子设备注册 - if (topic.endsWith('/register')) { - result = subRegister(topic, {productKey: pk, deviceName: dn}, payload); - } else { - //数据上报 - result = { - type: "report", - data: { - productKey: pk, - deviceName: dn, - mid: payload.id, - content: { - topic: topic, - payload: payload - } - } - } - } - - } - print("【result】: " + JSON.stringify(result)); - print("======================================================================= "); - return result; - -} - -this.onRegistered = function (regInfo, result) { -} \ No newline at end of file diff --git a/iot-components/iot-emqx-component/src/main/resources/component.spi b/iot-components/iot-emqx-component/src/main/resources/component.spi deleted file mode 100755 index 6a9c37a6..00000000 --- a/iot-components/iot-emqx-component/src/main/resources/component.spi +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.comp.emqx.EmqxDeviceComponent \ No newline at end of file diff --git a/iot-components/iot-http-biz-component/.DS_Store b/iot-components/iot-http-biz-component/.DS_Store deleted file mode 100755 index a3c148ab..00000000 Binary files a/iot-components/iot-http-biz-component/.DS_Store and /dev/null differ diff --git a/iot-components/iot-http-biz-component/pom.xml b/iot-components/iot-http-biz-component/pom.xml deleted file mode 100755 index 5faf58aa..00000000 --- a/iot-components/iot-http-biz-component/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - iot-components - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-http-biz-component - - - - - cc.iotkit - iot-component-base - - - - cc.iotkit - iot-script-engine - - - - - - org.projectlombok - lombok - - - - io.vertx - vertx-web-proxy - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - - io.vertx:vertx-web-proxy - io.vertx:vertx-web - io.vertx:vertx-bridge-common - io.vertx:vertx-http-proxy - io.vertx:vertx-core - io.netty:netty-codec-http2 - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - utf8 - - - - - - diff --git a/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpBizComponent.java b/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpBizComponent.java deleted file mode 100755 index 80958674..00000000 --- a/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpBizComponent.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.biz; - -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.CompConfig; -import cc.iotkit.comp.IComponent; -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.Vertx; -import io.vertx.core.http.HttpServer; -import io.vertx.core.http.HttpServerRequest; -import io.vertx.core.http.HttpServerResponse; -import io.vertx.ext.web.Router; -import io.vertx.ext.web.handler.BodyHandler; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; - -import java.util.*; - -@Data -@Slf4j -public class HttpBizComponent implements IComponent { - - private final Vertx vertx = Vertx.vertx(); - - private final IScriptEngine scriptEngine = ScriptEngineFactory.getScriptEngine("js"); - - private Object scriptObj; - - private CompConfig config; - - private HttpConfig httpConfig; - - private String script; - - private HttpServer backendServer; - - private String id; - - @Override - public void create(CompConfig config) { - this.id = UUID.randomUUID().toString(); - this.httpConfig = JsonUtils.parseObject(config.getOther(), HttpConfig.class); - scriptEngine.setScript(script); - } - - @Override - public void start() { - backendServer = vertx.createHttpServer(); - Router backendRouter = Router.router(vertx); - backendRouter.route().handler(BodyHandler.create()) - .handler(rc -> { - try { - Map httpHeader = getData(rc.request().headers()); - log.info("request header:{}", JsonUtils.toJsonString(httpHeader)); - Map> httpParams = getListData(rc.request().params()); - log.info("request params:{}", JsonUtils.toJsonString(httpParams)); - - HttpServerRequest httpRequest = rc.request(); - String contentType = httpRequest.headers().get("Content-Type"); - Map responseHeader = new HashMap<>(); - if ("application/json".equals(contentType)) { - String bodyStr = rc.getBody().toString(); - Map body = JsonUtils.parseObject(bodyStr, Map.class); - log.info("request body:{}", bodyStr); - - String response; - try { - HttpContent content = - scriptEngine.invokeMethod( - new TypeReference<>() { - }, - "onReceive", - httpRequest.method().name(), - httpRequest.path(), - httpHeader, - httpParams, - body); - responseHeader = content.getHeader(); - response = content.getContent(); - response = response == null ? "" : response; - } catch (Throwable e) { - log.error("invokeMethod onReceive error", e); - response = e.getMessage(); - } - - HttpServerResponse httpServerResponse = rc.response(); - //设置响应头 - responseHeader.forEach((key, value) -> { - //大写转换 - key = key.replaceAll("([A-Z])", "-$1").toLowerCase(); - httpServerResponse.putHeader(key, value.toString()); - }); - - log.info("response,header:{},content:{}", responseHeader, response); - //设置响应内容 - httpServerResponse - .end(response); - } else { - rc.response().end(""); - } - } catch (Throwable e) { - log.error("handle request error", e); - rc.response().end("server error:" + e.getMessage()); - } - }); - - backendServer.requestHandler(backendRouter) - .listen(httpConfig.getPort(), http -> { - if (http.succeeded()) { - log.info("http server create succeed,port:{}", httpConfig.getPort()); - } else { - log.error("http server create failed", http.cause()); - } - }); - } - - @Override - public void putScriptEnv(String key, Object value) { - scriptEngine.putScriptEnv(key, value); - } - - @Override - public void stop() { - backendServer.close(); - } - - @Override - public void destroy() { - } - - private static Map> getListData(MultiMap multiMap) { - Map> listData = new HashMap<>(); - for (Map.Entry entry : multiMap.entries()) { - String key = entry.getKey(); - Object value = entry.getValue(); - listData.putIfAbsent(key, new ArrayList<>()); - listData.get(key).add(value); - } - return listData; - } - - 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-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpConfig.java b/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpConfig.java deleted file mode 100755 index c4b3fa23..00000000 --- a/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpConfig.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.biz; - -import lombok.Data; - -@Data -public class HttpConfig { - - private int port; - -} diff --git a/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpContent.java b/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpContent.java deleted file mode 100644 index 5ca8d610..00000000 --- a/iot-components/iot-http-biz-component/src/main/java/cc/iotkit/comp/biz/HttpContent.java +++ /dev/null @@ -1,19 +0,0 @@ -package cc.iotkit.comp.biz; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.Map; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class HttpContent { - - private Map header; - - private String content; -} diff --git a/iot-components/iot-http-biz-component/src/main/resources/component.spi b/iot-components/iot-http-biz-component/src/main/resources/component.spi deleted file mode 100755 index 90ecd945..00000000 --- a/iot-components/iot-http-biz-component/src/main/resources/component.spi +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.comp.biz.HttpBizComponent \ No newline at end of file diff --git a/iot-components/iot-http-biz-component/src/main/resources/onenet接入脚本示例.js b/iot-components/iot-http-biz-component/src/main/resources/onenet接入脚本示例.js deleted file mode 100755 index 0e8c664f..00000000 --- a/iot-components/iot-http-biz-component/src/main/resources/onenet接入脚本示例.js +++ /dev/null @@ -1,74 +0,0 @@ -var pidPkMap={ - "H5Z31yKBmy":"3ptfx2dRescPAwTn", - "xOCy76jn6k":"jzC6eQGRse6hDZPB" -} - -this.onReceive=function(method,path,header,params,body){ - var type=header["Content-Type"]; - if(type=="application/json"){ - var msg=JSON.parse(body.msg); - var productId=msg.productId; - var deviceName=msg.deviceName; - var messageType=msg.messageType; - var data=msg.data; - var pk=pidPkMap[productId]; - if(!pk){ - return { - url:"", - header:{ - contentType:"application/json" - }, - content:"error" - } - } - - if(messageType=="lifeCycle"){ - //登录、登出 - var online=data.status=="online"; - deviceBehaviour.deviceStateChange(pk,deviceName,online); - }else if(messageType=="notify"){ - //设备消息 - //消息类型 - var notifyType=msg.notifyType; - if(notifyType=="property"){ - //属性上报 - var propertyData={}; - for(var p in data.params){ - propertyData[p]=data.params[p].value; - } - deviceBehaviour.reportMessage(JSON.stringify({ - mid:data.id, - productKey:pk, - deviceName:deviceName, - type:"property", - identifier:"report", - data:propertyData - })); - }else if(notifyType=="event"){ - //事件上报 - var identifier=""; - var paramData={}; - for(var p in data.params){ - identifier=p; - paramData=data.params[p]; - } - - deviceBehaviour.reportMessage(JSON.stringify({ - mid:data.id, - productKey:pk, - deviceName:deviceName, - type:"event", - identifier:identifier, - data:paramData.value - })); - } - } - } - return { - url:"", - header:{ - contentType:"application/json" - }, - content:JSON.stringify(params.msg) - } -}; \ No newline at end of file diff --git a/iot-components/iot-http-biz-component/src/main/resources/小度音箱接入脚本示例.js b/iot-components/iot-http-biz-component/src/main/resources/小度音箱接入脚本示例.js deleted file mode 100755 index ca368171..00000000 --- a/iot-components/iot-http-biz-component/src/main/resources/小度音箱接入脚本示例.js +++ /dev/null @@ -1,238 +0,0 @@ -//api配置 -apiTool.config("127.0.0.1",8085,3000); - -this.onReceive=function(method,path,header,params,body){ - //method:post、get、delete... - //path:请求路径 - //header:http请求头数据,结构:{xx:xx,yy:yy} - //params:请求参数,结构:{xx:[...],yy:[...]} - //body:请求体,当提交的数据为json格式时使用,结构:{xx:xx,yy:yy} - apiTool.log("onReceive body:"+body); - var duHeader=body.header; - var namespace=duHeader.namespace; - var requestName=duHeader.name; - var messageId=duHeader.messageId; - var duPayload=body.payload; - var token=duPayload.accessToken; - var openUid=duPayload.openUid; - - //设备发现 - if(namespace=="DuerOS.ConnectedHome.Discovery" && requestName=="DiscoverAppliancesRequest"){ - var deviceIds=[]; - var discoveredDevices=[]; - var content={ - header:{ - namespace:"DuerOS.ConnectedHome.Discovery", - name:"DiscoverAppliancesResponse", - messageId:messageId, - payloadVersion:1 - }, - payload:{ - discoveredAppliances:discoveredDevices, - discoveredGroups:[{ - groupName:"客厅", - applianceIds:deviceIds, - groupNotes:"客厅分组控制", - additionalGroupDetails:{} - }] - } - }; - var rst=apiTool.getSpaceDevices(token); - apiTool.log(JSON.stringify(rst)); - if(rst && rst.status==200 && rst.data){ - var devices=rst.data; - for(var i in devices){ - var device=devices[i]; - var did=device.deviceId; - var pk=device.productKey; - var dn=device.deviceName; - - //更新设备openUid - rst=apiTool.setOpenUid(token,did,"dueros",openUid); - if(!rst || rst.status!=200){ - continue; - } - - //插座 - if(pk=="cGCrkK7Ex4FESAwe"){ - var powerstate=device.property.powerstate; - discoveredDevices.push({ - actions:["turnOn","turnOff"], - applianceTypes:["SOCKET"], - additionalApplianceDetails:{}, - applianceId:device.deviceId, - friendlyDescription:"智能插座", - friendlyName:device.name, - isReachable:device.online, - manufacturerName:"海曼", - modelName:"S1", - version:"v1.0", - attributes:[ - { - name:"客厅的插座", - scale:"", - timestampOfSample:0, - uncertaintyInMilliseconds:10 - }, - { - name:"connectivity", - value:"REACHABLE", - scale:"", - timestampOfSample:0, - uncertaintyInMilliseconds:10 - }, - { - name:"turnOnState", - value:powerstate==1?"ON":"OFF", - scale:"", - timestampOfSample:0, - uncertaintyInMilliseconds:10, - legalValue:"(ON, OFF)" - } - ] - }); - }else if(pk=="Rf4QSjbm65X45753"){ - //开关 - var powerstate=device.property.powerstate; - discoveredDevices.push({ - actions:["turnOn","turnOff"], - applianceTypes:["SWITCH"], - additionalApplianceDetails:{}, - applianceId:device.deviceId, - friendlyDescription:"智能开关", - friendlyName:device.name, - isReachable:device.online, - manufacturerName:"海曼", - modelName:"S1", - version:"v1.0", - attributes:[ - { - name:"客厅的开关", - scale:"", - timestampOfSample:0, - uncertaintyInMilliseconds:10 - }, - { - name:"connectivity", - value:"REACHABLE", - scale:"", - timestampOfSample:0, - uncertaintyInMilliseconds:10 - }, - { - name:"turnOnState", - value:powerstate==1?"ON":"OFF", - scale:"", - timestampOfSample:0, - uncertaintyInMilliseconds:10, - legalValue:"(ON, OFF)" - } - ] - }); - - } - } - } - - return { - url:"",//不指定直接作为响应返回 - header:{ - contentType:"application/json" - }, - content:JSON.stringify(content) - } - }else if(namespace=="DuerOS.ConnectedHome.Control"){ - //设备控制 - var appliance=duPayload.appliance; - var deviceId=appliance.applianceId; - var confirmName="UnsupportedOperationError"; - var rst={status:500}; - - //开关 - if(requestName=="TurnOnRequest"){ - //开 - confirmName="TurnOnConfirmation"; - rst=apiTool.setProperties(token,deviceId,{powerstate:1}); - }else if(requestName=="TurnOffRequest"){ - //关 - confirmName="TurnOffConfirmation"; - rst=apiTool.setProperties(token,deviceId,{powerstate:0}); - } - - if(rst.status!=200){ - confirmName="UnsupportedOperationError"; - apiTool.log("device control failed:"+JSON.stringify(rst)); - } - - var content={ - header: { - namespace: "DuerOS.ConnectedHome.Control", - name: confirmName, - messageId: messageId, - payloadVersion: "1" - }, - payload: { - "attributes": [] - } - }; - - return { - url:"", - header:{ - contentType:"application/json" - }, - content:JSON.stringify(content) - } - }else if(namespace=="DuerOS.ConnectedHome.Query"){ - //属性查询 - if(requestName=="ReportStateRequest"){ - var appliance=duPayload.appliance; - var deviceId=appliance.applianceId; - var property=appliance.attributeName; - var propertyVal=""; - var success=false; - if(property=="turnOnState"){ - //开关状态查询 - var rst= apiTool.getSpaceDeviceDetail(token,deviceId); - if(rst && rst.status==200 && rst.data.property){ - propertyVal=rst.data.property.powerstate==1?"ON":"OFF"; - success=true; - } - } - var content=success?{ - "header": { - "namespace": "DuerOS.ConnectedHome.Query", - "name": "ReportStateResponse", - "messageId": new Date().getTime()+"", - "payloadVersion": "1" - }, - "payload": { - "attributes": [ - { - "name": property, - "value": propertyVal, - "scale": "", - "timestampOfSample": new Date().getTime()/1000, - "uncertaintyInMilliseconds": 0 - } - ] - } - }:{}; - - return { - url:"", - header:{ - contentType:"application/json" - }, - content:JSON.stringify(content) - } - } - } - return { - url:"",//不指定直接作为响应返回 - header:{ - contentType:"application/json" - }, - content:"" - } -} \ No newline at end of file diff --git a/iot-components/iot-mqtt-component/.DS_Store b/iot-components/iot-mqtt-component/.DS_Store deleted file mode 100755 index 827186b4..00000000 Binary files a/iot-components/iot-mqtt-component/.DS_Store and /dev/null differ diff --git a/iot-components/iot-mqtt-component/pom.xml b/iot-components/iot-mqtt-component/pom.xml deleted file mode 100755 index 47f37051..00000000 --- a/iot-components/iot-mqtt-component/pom.xml +++ /dev/null @@ -1,109 +0,0 @@ - - - - iot-components - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-mqtt-component - - - - - cc.iotkit - iot-common-core - - - - cc.iotkit - iot-component-base - - - - cc.iotkit - iot-data-service - - - - cc.iotkit - iot-script-engine - - - - - - io.vertx - vertx-core - - - - io.vertx - vertx-mqtt - - - - io.netty - netty-codec-mqtt - - - - org.projectlombok - lombok - - - - org.slf4j - slf4j-api - - - - org.luaj - luaj-jse - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - - io.vertx:vertx-core - io.vertx:vertx-mqtt - io.netty:netty-codec-mqtt - org.luaj:luaj-jse - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - true - false - utf8 - - - - - - diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/IScripter.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/IScripter.java deleted file mode 100755 index e37615c8..00000000 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/IScripter.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.mqtt; - -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.model.product.ProductModel; - -public interface IScripter { - - void setModel(ProductModel model); - - void setScript(String script); - - /** - * 透传解码 - */ - ThingModelMessage decode(TransparentMsg msg); - - /** - * 透传编码 - */ - TransparentMsg encode(ThingService service); -} diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/JsScripter.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/JsScripter.java deleted file mode 100755 index ba1d7c50..00000000 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/JsScripter.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.mqtt; - -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.model.product.ProductModel; -import cc.iotkit.script.IScriptEngine; -import cc.iotkit.script.ScriptEngineFactory; -import com.fasterxml.jackson.core.type.TypeReference; -import lombok.Data; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Data -public class JsScripter implements IScripter { - - private ProductModel model; - - private Object scriptObj; - - private IScriptEngine scriptEngine = ScriptEngineFactory.getScriptEngine("js"); - - public JsScripter(ProductModel model) { - this.model = model; - } - - @SneakyThrows - @Override - public void setScript(String script) { - scriptEngine.setScript(script); - } - - @SneakyThrows - public ThingModelMessage decode(TransparentMsg msg) { - return scriptEngine.invokeMethod(new TypeReference<>() { - }, "decode", msg); - - } - - @SneakyThrows - public TransparentMsg encode(ThingService service) { - return scriptEngine.invokeMethod(new TypeReference<>() { - }, "encode", service); - } -} diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/LuaScripter.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/LuaScripter.java deleted file mode 100755 index 597325fd..00000000 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/LuaScripter.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.mqtt; - -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.model.product.ProductModel; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.beanutils.BeanUtils; -import org.luaj.vm2.LuaTable; -import org.luaj.vm2.LuaValue; -import org.luaj.vm2.script.LuaScriptEngine; - -import javax.script.Compilable; -import javax.script.CompiledScript; -import javax.script.ScriptEngineManager; -import javax.script.SimpleBindings; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Slf4j -@Data -public class LuaScripter implements IScripter { - - private ProductModel model; - - private final LuaScriptEngine engine = (LuaScriptEngine) ( - new ScriptEngineManager().getEngineByName("luaj")); - - private LuaValue decoder; - private LuaValue encoder; - - public LuaScripter(ProductModel model) { - this.model = model; - } - - @Override - public void setScript(String script) { - try { - CompiledScript compiledScript = ((Compilable) engine).compile(script); - SimpleBindings bindings = new SimpleBindings(); - compiledScript.eval(bindings); - decoder = (LuaValue) bindings.get("decode"); - encoder = (LuaValue) bindings.get("encode"); - } catch (Throwable e) { - log.error("compile script error", e); - } - } - - public ThingModelMessage decode(TransparentMsg msg) { - try { - LuaTable table = new LuaTable(); - table.set("model", msg.getModel()); - table.set("deviceName", msg.getDeviceName()); - table.set("data", msg.getData()); - Map result = (Map) parse(decoder.call(table)); - ThingModelMessage modelMessage = new ThingModelMessage(); - BeanUtils.populate(modelMessage, result); - - modelMessage.setProductKey(msg.getProductKey()); - modelMessage.setDeviceName(msg.getDeviceName()); - return modelMessage; - } catch (Throwable e) { - log.error("execute decode script error", e); - } - return null; - } - - public TransparentMsg encode(ThingService service) { - try { - LuaTable table = new LuaTable(); - table.set("identifier", service.getIdentifier()); - table.set("type", service.getType()); - table.set("productKey", service.getProductKey()); - table.set("deviceName", service.getDeviceName()); - table.set("mid", service.getMid()); - Object params = service.getParams(); - LuaTable tableParams = new LuaTable(); - if (params instanceof Map) { - ((Map) params).forEach((key, val) -> tableParams.set(key.toString(), parse(val))); - } - table.set("params", tableParams); - LuaValue result = encoder.call(table); - Map map = (Map) parse(result); - TransparentMsg message = new TransparentMsg(); - BeanUtils.populate(message, map); - message.setProductKey(model.getProductKey()); - message.setModel(model.getModel()); - message.setDeviceName(service.getDeviceName()); - return message; - } catch (Throwable e) { - log.error("execute encode script error", e); - } - return null; - } - - private Object parse(LuaValue value) { - String type = value.typename(); - switch (type) { - case "string": - return value.toString(); - case "number": - case "int": - return value.toint(); - case "table": - Map data = new HashMap<>(); - LuaTable table = (LuaTable) value; - int arrLen = table.rawlen(); - if (arrLen > 0) { - //数组转换 - List list = new ArrayList<>(); - for (LuaValue key : table.keys()) { - list.add(parse(table.get(key))); - } - return list; - } else { - //map转换 - for (LuaValue key : table.keys()) { - data.put(key.toString(), parse(table.get(key))); - } - } - return data; - } - return null; - } - - private LuaValue parse(Object value) { - if (value instanceof String) { - return LuaValue.valueOf(value.toString()); - } - if (value instanceof Integer) { - return LuaValue.valueOf((Integer) value); - } - return new LuaTable(); - } - -} diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttConfig.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttConfig.java deleted file mode 100755 index 1c9069ab..00000000 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.mqtt; - -import lombok.Data; - -@Data -public class MqttConfig { - - private int port; - - private String sslKey; - - private String sslCert; - - private boolean ssl; - - private boolean useWebSocket; - -} diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttDeviceComponent.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttDeviceComponent.java deleted file mode 100755 index 2317ab7a..00000000 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttDeviceComponent.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.mqtt; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.AbstractDeviceComponent; -import cc.iotkit.comp.CompConfig; -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.converter.DeviceMessage; -import cc.iotkit.model.device.message.ThingModelMessage; -import io.vertx.core.Future; -import io.vertx.core.Vertx; -import lombok.*; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.beanutils.BeanUtils; - -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CountDownLatch; - -@Slf4j -public class MqttDeviceComponent extends AbstractDeviceComponent { - - private Vertx vertx; - private CountDownLatch countDownLatch; - private String deployedId; - private MqttVerticle mqttVerticle; - private final Map deviceChildToParent = new HashMap<>(); - private final TransparentConverter transparentConverter = new TransparentConverter(); - - @Override - public void create(CompConfig config) { - super.create(config); - vertx = Vertx.vertx(); - MqttConfig mqttConfig = JsonUtils.parseObject(config.getOther(), MqttConfig.class); - mqttVerticle = new MqttVerticle(mqttConfig); - } - - public void start() { - try { - mqttVerticle.setExecutor(getHandler()); - countDownLatch = new CountDownLatch(1); - Future future = vertx.deployVerticle(mqttVerticle); - future.onSuccess((s -> { - deployedId = s; - countDownLatch.countDown(); - })); - future.onFailure((e) -> { - countDownLatch.countDown(); - log.error("start mqtt component failed", e); - }); - countDownLatch.await(); - future.succeeded(); - } catch (Throwable e) { - throw new BizException(ErrCode.COMPONENT_START_ERROR, e); - } - } - - @SneakyThrows - public void stop() { - mqttVerticle.stop(); - Future future = vertx.undeploy(deployedId); - future.onSuccess(unused -> log.info("stop mqtt component success")); - } - - public void destroy() { - } - - @Override - public void onDeviceStateChange(DeviceState state) { - DeviceState.Parent parent = state.getParent(); - if (parent == null) { - return; - } - Device device = new Device(state.getProductKey(), state.getDeviceName()); - - if (DeviceState.STATE_ONLINE.equals(state.getState())) { - //保存子设备所属父设备 - deviceChildToParent.put(device.toString(), - new Device(parent.getProductKey(), parent.getDeviceName()) - ); - } else { - //删除关系 - deviceChildToParent.remove(device.toString()); - } - - } - - @Override - public DeviceMessage send(DeviceMessage message) { - Device child = new Device(message.getProductKey(), message.getDeviceName()); - //作为子设备查找父设备 - Device parent = deviceChildToParent.get(child.toString()); - if (parent == null) { - parent = child; - } - - Object obj = message.getContent(); - if (!(obj instanceof Map)) { - throw new BizException(ErrCode.DATA_FORMAT_ERROR); - } - Message msg = new Message(); - try { - BeanUtils.populate(msg, (Map) obj); - } catch (Throwable e) { - throw new BizException(ErrCode.DATA_FORMAT_ERROR); - } - log.info("publish topic:{},payload:{}", msg.getTopic(), msg.getPayload()); - mqttVerticle.publish(parent.getProductKey(), parent.getDeviceName(), - msg.getTopic(), msg.getPayload()); - - return message; - } - - @Override - public CompConfig getConfig() { - return config; - } - - /** - * 透传解码 - */ - public ThingModelMessage transparentDecode(Map msg) throws InvocationTargetException, IllegalAccessException { - TransparentMsg transparentMsg = new TransparentMsg(); - BeanUtils.populate(transparentMsg, msg); - return transparentConverter.decode(transparentMsg); - } - - /** - * 透传编码 - */ - public DeviceMessage transparentEncode(ThingService service, cc.iotkit.converter.Device device) { - return transparentConverter.encode(service, device); - } - - @Data - public static class Message { - private String topic; - private String payload; - } - - @Data - @NoArgsConstructor - @AllArgsConstructor - @ToString - public static class Device { - private String productKey; - private String deviceName; - } - -} diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttVerticle.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttVerticle.java deleted file mode 100755 index b1db2ded..00000000 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/MqttVerticle.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.mqtt; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.comp.IMessageHandler; -import cc.iotkit.comp.model.ReceiveResult; -import io.netty.handler.codec.mqtt.MqttConnectReturnCode; -import io.netty.handler.codec.mqtt.MqttProperties; -import io.netty.handler.codec.mqtt.MqttQoS; -import io.vertx.core.AbstractVerticle; -import io.vertx.core.Future; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.net.PemKeyCertOptions; -import io.vertx.mqtt.*; -import io.vertx.mqtt.messages.codes.MqttSubAckReasonCode; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -@Slf4j -public class MqttVerticle extends AbstractVerticle { - - private MqttServer mqttServer; - - private final MqttConfig config; - - private IMessageHandler executor; - - private final Map endpointMap = new HashMap<>(); - - // 增加一个客户端连接clientid-连接状态池,避免mqtt关闭的时候走异常断开和mqtt断开的handler,导致多次离线消息 - private static final Map mqttConnectPool = new ConcurrentHashMap<>(); - - public MqttVerticle(MqttConfig config) { - this.config = config; - } - - public void setExecutor(IMessageHandler executor) { - this.executor = executor; - } - - @Override - public void start() { - MqttServerOptions options = new MqttServerOptions() - .setPort(config.getPort()); - if (config.isSsl()) { - options = options.setSsl(true) - .setKeyCertOptions(new PemKeyCertOptions() - .setKeyPath(config.getSslKey()) - .setCertPath(config.getSslCert())); - } - options.setUseWebSocket(config.isUseWebSocket()); - - mqttServer = MqttServer.create(vertx, options); - mqttServer.endpointHandler(endpoint -> { - log.info("MQTT client:{} request to connect, clean session = {}", endpoint.clientIdentifier(), endpoint.isCleanSession()); - - MqttAuth auth = endpoint.auth(); - if (auth == null) { - return; - } - - String clientId = endpoint.clientIdentifier(); - String authJson = auth.toJson() - .put("clientid", clientId).toString(); - - log.info("MQTT client auth,clientId:{},username:{},password:{}", - clientId, auth.getUsername(), auth.getPassword()); - try { - executor.onReceive(new HashMap<>(), "auth", authJson, (r) -> { - if (r == null) { - //认证失败 - endpoint.reject(MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED); - return; - } - //保存设备与连接关系 - endpointMap.put(getEndpointKey(r), endpoint); - mqttConnectPool.put(clientId, true); - }); - } catch (Throwable e) { - log.error("auth failed", e); - endpoint.reject(MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED); - return; - } - - log.info("MQTT client keep alive timeout = {} ", endpoint.keepAliveTimeSeconds()); - - endpoint.accept(false); - endpoint.closeHandler((v) -> { - log.warn("client connection closed,clientId:{}", clientId); - if (Boolean.FALSE.equals(mqttConnectPool.get(clientId))) { - return; - } - executor.onReceive(new HashMap<>(), "disconnect", clientId, (r) -> { - //删除设备与连接关系 - endpointMap.remove(getEndpointKey(r)); - }); - }).disconnectMessageHandler(disconnectMessage -> { - log.info("Received disconnect from client, reason code = {}", disconnectMessage.code()); - executor.onReceive(new HashMap<>(), "disconnect", clientId, (r) -> { - //删除设备与连接关系 - endpointMap.remove(getEndpointKey(r)); - mqttConnectPool.put(clientId, false); - }); - }).subscribeHandler(subscribe -> { - List reasonCodes = new ArrayList<>(); - for (MqttTopicSubscription s : subscribe.topicSubscriptions()) { - log.info("Subscription for {},with QoS {}", s.topicName(), s.qualityOfService()); - try { - Map head = new HashMap<>(); - head.put("topic", s.topicName()); - executor.onReceive(head, "subscribe", clientId); - reasonCodes.add(MqttSubAckReasonCode.qosGranted(s.qualityOfService())); - } catch (Throwable e) { - log.error("subscribe failed,topic:" + s.topicName(), e); - reasonCodes.add(MqttSubAckReasonCode.NOT_AUTHORIZED); - } - } - // ack the subscriptions request - endpoint.subscribeAcknowledge(subscribe.messageId(), reasonCodes, MqttProperties.NO_PROPERTIES); - - }).unsubscribeHandler(unsubscribe -> { - for (String t : unsubscribe.topics()) { - log.info("Unsubscription for {}", t); - try { - Map head = new HashMap<>(); - head.put("topic", t); - executor.onReceive(head, "unsubscribe", clientId); - } catch (Throwable e) { - log.error("unsubscribe failed,topic:" + t, e); - } - } - // ack the subscriptions request - endpoint.unsubscribeAcknowledge(unsubscribe.messageId()); - }).publishHandler(message -> { - String payload = message.payload().toString(Charset.defaultCharset()); - log.info("Received message:{}, with QoS {}", payload, - message.qosLevel()); - if (StringUtils.isBlank(payload)) { - return; - } - - try { - Map head = new HashMap<>(); - String topic = message.topicName(); - head.put("topic", topic); - if (topic.toLowerCase().contains("ota")) { - executor.onReceive(head, "ota", payload); - } else { - executor.onReceive(head, "", payload); - } - if (message.qosLevel() == MqttQoS.AT_LEAST_ONCE) { - endpoint.publishAcknowledge(message.messageId()); - } else if (message.qosLevel() == MqttQoS.EXACTLY_ONCE) { - endpoint.publishReceived(message.messageId()); - } - } catch (Throwable e) { - log.error("handler message failed,topic:" + message.topicName(), e); - } - }).publishReleaseHandler(endpoint::publishComplete); - }).listen(ar -> { - if (ar.succeeded()) { - log.info("MQTT server is listening on port " + ar.result().actualPort()); - } else { - log.error("Error on starting the server", ar.cause()); - } - }); - } - - @Override - public void stop() throws Exception { - for (MqttEndpoint endpoint : endpointMap.values()) { - executor.onReceive(new HashMap<>(), "disconnect", endpoint.clientIdentifier()); - } - mqttServer.close(voidAsyncResult -> log.info("close mqtt server...")); - } - - private String getEndpointKey(ReceiveResult result) { - if (result == null) { - return null; - } - return getEndpointKey(result.getProductKey(), result.getDeviceName()); - } - - private String getEndpointKey(String productKey, String deviceName) { - return String.format("%s_%s", productKey, deviceName); - } - - public boolean exist(String productKey, String deviceName) { - return endpointMap.containsKey(getEndpointKey(productKey, deviceName)); - } - - public void publish(String productKey, String deviceName, String topic, String msg) { - MqttEndpoint endpoint = endpointMap.get(getEndpointKey(productKey, deviceName)); - if (endpoint == null) { - throw new BizException(ErrCode.SEND_DESTINATION_NOT_FOUND); - } - Future result = endpoint.publish(topic, Buffer.buffer(msg), - MqttQoS.AT_LEAST_ONCE, false, false); - result.onFailure(e -> log.error("public topic failed", e)); - result.onSuccess(integer -> log.info("publish success,topic:{},payload:{}", topic, msg)); - } -} diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentConverter.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentConverter.java deleted file mode 100755 index 5508b81d..00000000 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentConverter.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.mqtt; - - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.common.utils.SpringUtils; -import cc.iotkit.converter.Device; -import cc.iotkit.converter.DeviceMessage; -import cc.iotkit.data.manager.IDeviceInfoData; -import cc.iotkit.data.manager.IProductModelData; -import cc.iotkit.model.device.DeviceInfo; -import cc.iotkit.model.device.message.ThingModelMessage; -import cc.iotkit.model.product.ProductModel; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -import java.util.HashMap; -import java.util.Map; - -@Slf4j -public class TransparentConverter { - - private final Map scripters = new HashMap<>(); - private final Map scripts = new HashMap<>(); - - private IDeviceInfoData deviceInfoData; - private IProductModelData productModelData; - - /** - * 透传解码 - */ - public ThingModelMessage decode(TransparentMsg msg) { - String productKey = msg.getProductKey(); - productKey = checkScriptUpdate(productKey, msg.getModel()); - msg.setProductKey(productKey); - ThingModelMessage decodeMsg = scripters.get(productKey).decode(msg); - decodeMsg.setProductKey(msg.getProductKey()); - decodeMsg.setDeviceName(msg.getDeviceName()); - return decodeMsg; - } - - /** - * 透传编码 - */ - public DeviceMessage encode(ThingService service, Device device) { - String productKey = service.getProductKey(); - checkScriptUpdate(productKey, device.getModel()); - TransparentMsg transparentMsg = scripters.get(productKey).encode(service); - //转换成网关消息 - String deviceName = service.getDeviceName(); - DeviceInfo gateway = getGatewayInfo(deviceName); - DeviceMessage message = new DeviceMessage(); - message.setProductKey(gateway.getProductKey()); - message.setDeviceName(gateway.getDeviceName()); - message.setMid(transparentMsg.getMid()); - //透传格式消息内容,mac、model、data - message.setContent(transparentMsg); - return message; - } - - private ProductModel getScript(String model) { - if (productModelData == null) { - productModelData = SpringUtils.getBean("productModelDataCache"); - } - - return productModelData.findByModel(model); - } - - private DeviceInfo getGatewayInfo(String subDn) { - if (deviceInfoData == null) { - deviceInfoData = SpringUtils.getBean("deviceInfoDataCache"); - } - - String parentId = deviceInfoData.findByDeviceName(subDn).getParentId(); - return deviceInfoData.findByDeviceId(parentId); - } - - /** - * 检查产品脚本是否更新 - */ - private String checkScriptUpdate(String pk, String model) { - ProductModel productModel = null; - if (StringUtils.isNotBlank(model)) { - productModel = getScript(model); - } - //指定型号获取不到获取默认型号 - if (productModel == null && StringUtils.isNotBlank(pk)) { - productModel = getScript(ProductModel.getDefaultModel(pk)); - } - if (productModel == null) { - throw new BizException(ErrCode.MODEL_SCRIPT_NOT_FOUND); - } - - String productKey = productModel.getProductKey(); - String script = productModel.getScript(); - - String oldScript = scripts.get(productKey); - if (script.equals(oldScript)) { - return productKey; - } - - String type = productModel.getType(); - if (ProductModel.TYPE_LUA.equals(type)) { - scripters.putIfAbsent(productKey, new LuaScripter(productModel)); - } else if (ProductModel.TYPE_JS.equals(type)) { - scripters.putIfAbsent(productKey, new JsScripter(productModel)); - } - - //更新脚本 - IScripter scripter = scripters.get(productKey); - scripter.setScript(script); - scripts.put(productKey, script); - return productKey; - } - -} diff --git a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentMsg.java b/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentMsg.java deleted file mode 100755 index 05e04830..00000000 --- a/iot-components/iot-mqtt-component/src/main/java/cc/iotkit/comp/mqtt/TransparentMsg.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.mqtt; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.FieldNameConstants; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -@FieldNameConstants -public class TransparentMsg { - - private String productKey; - - /** - * 生成给设备端的消息id - */ - private String mid; - - private String model; - - private String deviceName; - - private String data; - -} diff --git a/iot-components/iot-mqtt-component/src/main/resources/ali-component.js b/iot-components/iot-mqtt-component/src/main/resources/ali-component.js deleted file mode 100644 index 9eb7301a..00000000 --- a/iot-components/iot-mqtt-component/src/main/resources/ali-component.js +++ /dev/null @@ -1,326 +0,0 @@ -!function (n) { - "use strict"; - - function d(n, t) { - var r = (65535 & n) + (65535 & t); - return (n >> 16) + (t >> 16) + (r >> 16) << 16 | 65535 & r - } - - function f(n, t, r, e, o, u) { - return d((u = d(d(t, n), d(e, u))) << o | u >>> 32 - o, r) - } - - function l(n, t, r, e, o, u, c) { - return f(t & r | ~t & e, n, t, o, u, c) - } - - function g(n, t, r, e, o, u, c) { - return f(t & e | r & ~e, n, t, o, u, c) - } - - function v(n, t, r, e, o, u, c) { - return f(t ^ r ^ e, n, t, o, u, c) - } - - function m(n, t, r, e, o, u, c) { - return f(r ^ (t | ~e), n, t, o, u, c) - } - - function c(n, t) { - var r, e, o, u; - n[t >> 5] |= 128 << t % 32, n[14 + (t + 64 >>> 9 << 4)] = t; - for (var c = 1732584193, f = -271733879, i = -1732584194, a = 271733878, h = 0; h < n.length; h += 16) c = l(r = c, e = f, o = i, u = a, n[h], 7, -680876936), a = l(a, c, f, i, n[h + 1], 12, -389564586), i = l(i, a, c, f, n[h + 2], 17, 606105819), f = l(f, i, a, c, n[h + 3], 22, -1044525330), c = l(c, f, i, a, n[h + 4], 7, -176418897), a = l(a, c, f, i, n[h + 5], 12, 1200080426), i = l(i, a, c, f, n[h + 6], 17, -1473231341), f = l(f, i, a, c, n[h + 7], 22, -45705983), c = l(c, f, i, a, n[h + 8], 7, 1770035416), a = l(a, c, f, i, n[h + 9], 12, -1958414417), i = l(i, a, c, f, n[h + 10], 17, -42063), f = l(f, i, a, c, n[h + 11], 22, -1990404162), c = l(c, f, i, a, n[h + 12], 7, 1804603682), a = l(a, c, f, i, n[h + 13], 12, -40341101), i = l(i, a, c, f, n[h + 14], 17, -1502002290), c = g(c, f = l(f, i, a, c, n[h + 15], 22, 1236535329), i, a, n[h + 1], 5, -165796510), a = g(a, c, f, i, n[h + 6], 9, -1069501632), i = g(i, a, c, f, n[h + 11], 14, 643717713), f = g(f, i, a, c, n[h], 20, -373897302), c = g(c, f, i, a, n[h + 5], 5, -701558691), a = g(a, c, f, i, n[h + 10], 9, 38016083), i = g(i, a, c, f, n[h + 15], 14, -660478335), f = g(f, i, a, c, n[h + 4], 20, -405537848), c = g(c, f, i, a, n[h + 9], 5, 568446438), a = g(a, c, f, i, n[h + 14], 9, -1019803690), i = g(i, a, c, f, n[h + 3], 14, -187363961), f = g(f, i, a, c, n[h + 8], 20, 1163531501), c = g(c, f, i, a, n[h + 13], 5, -1444681467), a = g(a, c, f, i, n[h + 2], 9, -51403784), i = g(i, a, c, f, n[h + 7], 14, 1735328473), c = v(c, f = g(f, i, a, c, n[h + 12], 20, -1926607734), i, a, n[h + 5], 4, -378558), a = v(a, c, f, i, n[h + 8], 11, -2022574463), i = v(i, a, c, f, n[h + 11], 16, 1839030562), f = v(f, i, a, c, n[h + 14], 23, -35309556), c = v(c, f, i, a, n[h + 1], 4, -1530992060), a = v(a, c, f, i, n[h + 4], 11, 1272893353), i = v(i, a, c, f, n[h + 7], 16, -155497632), f = v(f, i, a, c, n[h + 10], 23, -1094730640), c = v(c, f, i, a, n[h + 13], 4, 681279174), a = v(a, c, f, i, n[h], 11, -358537222), i = v(i, a, c, f, n[h + 3], 16, -722521979), f = v(f, i, a, c, n[h + 6], 23, 76029189), c = v(c, f, i, a, n[h + 9], 4, -640364487), a = v(a, c, f, i, n[h + 12], 11, -421815835), i = v(i, a, c, f, n[h + 15], 16, 530742520), c = m(c, f = v(f, i, a, c, n[h + 2], 23, -995338651), i, a, n[h], 6, -198630844), a = m(a, c, f, i, n[h + 7], 10, 1126891415), i = m(i, a, c, f, n[h + 14], 15, -1416354905), f = m(f, i, a, c, n[h + 5], 21, -57434055), c = m(c, f, i, a, n[h + 12], 6, 1700485571), a = m(a, c, f, i, n[h + 3], 10, -1894986606), i = m(i, a, c, f, n[h + 10], 15, -1051523), f = m(f, i, a, c, n[h + 1], 21, -2054922799), c = m(c, f, i, a, n[h + 8], 6, 1873313359), a = m(a, c, f, i, n[h + 15], 10, -30611744), i = m(i, a, c, f, n[h + 6], 15, -1560198380), f = m(f, i, a, c, n[h + 13], 21, 1309151649), c = m(c, f, i, a, n[h + 4], 6, -145523070), a = m(a, c, f, i, n[h + 11], 10, -1120210379), i = m(i, a, c, f, n[h + 2], 15, 718787259), f = m(f, i, a, c, n[h + 9], 21, -343485551), c = d(c, r), f = d(f, e), i = d(i, o), a = d(a, u); - return [c, f, i, a] - } - - function i(n) { - for (var t = "", r = 32 * n.length, e = 0; e < r; e += 8) t += String.fromCharCode(n[e >> 5] >>> e % 32 & 255); - return t - } - - function a(n) { - var t = []; - for (t[(n.length >> 2) - 1] = void 0, e = 0; e < t.length; e += 1) t[e] = 0; - for (var r = 8 * n.length, e = 0; e < r; e += 8) t[e >> 5] |= (255 & n.charCodeAt(e / 8)) << e % 32; - return t - } - - function e(n) { - for (var t, r = "0123456789abcdef", e = "", o = 0; o < n.length; o += 1) t = n.charCodeAt(o), e += r.charAt(t >>> 4 & 15) + r.charAt(15 & t); - return e - } - - function r(n) { - return unescape(encodeURIComponent(n)) - } - - function o(n) { - return i(c(a(n = r(n)), 8 * n.length)) - } - - function u(n, t) { - return function (n, t) { - var r, e = a(n), o = [], u = []; - for (o[15] = u[15] = void 0, 16 < e.length && (e = c(e, 8 * n.length)), r = 0; r < 16; r += 1) o[r] = 909522486 ^ e[r], u[r] = 1549556828 ^ e[r]; - return t = c(o.concat(a(t)), 512 + 8 * t.length), i(c(u.concat(t), 640)) - }(r(n), r(t)) - } - - function t(n, t, r) { - return t ? r ? u(t, n) : e(u(t, n)) : r ? o(n) : e(o(n)) - } - - "function" == typeof define && define.amd ? define(function () { - return t - }) : "object" == typeof module && module.exports ? module.exports = t : n.md5 = t -}(this); -var md5 = this.md5; -/** - 网关上线 - 订阅:/sys/hbtgIA0SuVw9lxjB/AA:BB:CC:DD:10/c/# - - 子设备注册: - /sys/hbtgIA0SuVw9lxjB/AA:BB:CC:DD:10/s/register - { - "id": "6", - "params":{ - "productKey":"Rf4QSjbm65X45753", - "deviceName":"ABC12400001", - "model":"S1" - } - } - 子设备上线 - 订阅:/sys/Rf4QSjbm65X45753/ABC12400001/c/# - - 数据上报: - /sys/Rf4QSjbm65X45753/ABC12400001/s/event/property/post - { - "id": "6", - "params":{ - "powerstate": 1 - } - } - */ - -var registered = {}; - -function getPkDn(clientId) { - var arr = clientId.split("|")[0].split("&"); - - if (arr.length < 2) { - throw new Error("incorrect clientid"); - } - var model = ""; - if (arr.length3 = 2) { - model = arr[2]; - } - return { - pk: arr[0], - dn: arr[1], - model: model - }; -} - -function register(payload) { - var auth = JSON.parse(payload); - // 兼容ali - var device = getPkDn(auth.clientid); - - var product = deviceBehaviour.getProductKey(pk) - var pwd = md5(product.getProductSecret() + auth.clientid); - - /*if (pwd.toLocaleLowerCase() != auth.password.toLocaleLowerCase()) { - throw new Error("incorrect password"); - }*/ - return { - type: "register", - data: { - productKey: device.pk, - deviceName: device.dn, - model: device.model - } - }; -} - -function subRegister(topic, parent, payload) { - var params = payload.params; - var reply = - { - productKey: parent.productKey, - deviceName: parent.deviceName, - mid: "0", - content: { - topic: topic.replace("/s/", "/c/") + "_reply", - payload: JSON.stringify({ - id: "0", - code: 0, - data: { - "productKey": params.productKey, - "deviceName": params.deviceName - } - }) - } - }; - - return { - type: "register", - data: { - productKey: parent.productKey, - deviceName: parent.deviceName, - subDevices: [{ - productKey: params.productKey, - deviceName: params.deviceName, - model: params.model - }] - }, - action: { - type: "ack", - content: JSON.stringify(reply) - } - }; -} - -function deviceStateChange(head, clientId, state) { - var topic = head.topic; - var device = getPkDn(clientId); - - var arr = topic.split('/'); - if (arr.length < 6) { - throw new Error("incorrect topic") - } - - var pk = arr[2]; - var dn = arr[3]; - return { - type: "state", - data: { - productKey: pk, - deviceName: dn, - state: state, - parent: { - productKey: device.pk, - deviceName: device.dn, - } - } - } -} - -function disconnect(clientId) { - var device = getPkDn(clientId); - return { - type: "state", - data: { - productKey: device.pk, - deviceName: device.dn, - state: "offline" - } - } -} - -function ignore() { - return {} -} - -function aliDeviceInfoUpdate(pk, dn, payload) { - return ignore(); - // return { - // type:"report", - // data:{ - // productKey:pk, - // deviceName:dn, - // mid:payload.id, - // content:{ - // topic:topic, - // payload:payload.params - // } - // }, - // action:{} - // }; -} - -//必须提供onReceive方法 -// todo: if else改成map -this.onReceive = function (head, type, payload) { - if (type == 'auth') { - return register(payload); - } - - if (type == 'subscribe') { - return deviceStateChange(head, payload, 'online'); - } - - if (type == 'unsubscribe') { - return deviceStateChange(head, payload, 'offline'); - } - - if (type == 'disconnect') { - return disconnect(payload); - } - - var topic = head['topic']; - if (!topic) { - throw new Error("topic is blank") - } - - var arr = topic.split('/'); - if (arr.length < 6) { - throw new Error("incorrect topic") - } - var pk = arr[2]; - var dn = arr[3]; - payload = JSON.parse(payload); - - //子设备注册 - if (topic.endsWith('/register')) { - return subRegister(topic, {productKey: pk, deviceName: dn}, payload); - } - - // 阿里设备信息上传 - // Received message:{"id": "1", "version": "1.0", "params": [{"domain": "SYSTEM", "attrKey": "SYS_SDK_LANGUAGE", "attrValue": "Python"}, {"domain": "SYSTEM", "attrKey": "SYS_LP_SDK_VERSION", "attrValue": "1.0.0"}, {"domain": "SYSTEM", "attrKey": "SYS_SDK_IF_INFO", "attrValue": "Eth|03ACDEFF0032|Eth|03ACDEFF0031"}], "method": "thing.deviceinfo.update"}, with QoS AT_MOST_ONCE - // topic":"/sys/JfGrfkfPXpBCEb6k/test_sc_001/thing/deviceinfo/update - if (topic.endsWith("/thing/deviceinfo/update")) { - return aliDeviceInfoUpdate(pk, dn, payload); - } - - //数据上报 - var reply = - { - productKey: pk, - deviceName: dn, - mid: payload.id, - content: { - topic: topic.replace("/s/", "/c/") + "_reply", - payload: JSON.stringify({ - id: payload.id, - method: payload.method + "_reply", - code: 0, - }) - } - }; - - var action = {}; - if (!topic.endsWith("_reply")) { - //需要回复的消息 - action = { - type: "ack", - content: JSON.stringify(reply) - } - } - - return { - type: "report", - data: { - productKey: pk, - deviceName: dn, - mid: payload.id, - content: { - topic: topic, - payload: payload.params - } - }, - action: action - } -} - -this.onRegistered = function (regInfo, result) { -} \ No newline at end of file diff --git a/iot-components/iot-mqtt-component/src/main/resources/component.js b/iot-components/iot-mqtt-component/src/main/resources/component.js deleted file mode 100755 index 7c97759a..00000000 --- a/iot-components/iot-mqtt-component/src/main/resources/component.js +++ /dev/null @@ -1,322 +0,0 @@ -!function (n) { - "use strict"; - - function d(n, t) { - var r = (65535 & n) + (65535 & t); - return (n >> 16) + (t >> 16) + (r >> 16) << 16 | 65535 & r - } - - function f(n, t, r, e, o, u) { - return d((u = d(d(t, n), d(e, u))) << o | u >>> 32 - o, r) - } - - function l(n, t, r, e, o, u, c) { - return f(t & r | ~t & e, n, t, o, u, c) - } - - function g(n, t, r, e, o, u, c) { - return f(t & e | r & ~e, n, t, o, u, c) - } - - function v(n, t, r, e, o, u, c) { - return f(t ^ r ^ e, n, t, o, u, c) - } - - function m(n, t, r, e, o, u, c) { - return f(r ^ (t | ~e), n, t, o, u, c) - } - - function c(n, t) { - var r, e, o, u; - n[t >> 5] |= 128 << t % 32, n[14 + (t + 64 >>> 9 << 4)] = t; - for (var c = 1732584193, f = -271733879, i = -1732584194, a = 271733878, h = 0; h < n.length; h += 16) c = l(r = c, e = f, o = i, u = a, n[h], 7, -680876936), a = l(a, c, f, i, n[h + 1], 12, -389564586), i = l(i, a, c, f, n[h + 2], 17, 606105819), f = l(f, i, a, c, n[h + 3], 22, -1044525330), c = l(c, f, i, a, n[h + 4], 7, -176418897), a = l(a, c, f, i, n[h + 5], 12, 1200080426), i = l(i, a, c, f, n[h + 6], 17, -1473231341), f = l(f, i, a, c, n[h + 7], 22, -45705983), c = l(c, f, i, a, n[h + 8], 7, 1770035416), a = l(a, c, f, i, n[h + 9], 12, -1958414417), i = l(i, a, c, f, n[h + 10], 17, -42063), f = l(f, i, a, c, n[h + 11], 22, -1990404162), c = l(c, f, i, a, n[h + 12], 7, 1804603682), a = l(a, c, f, i, n[h + 13], 12, -40341101), i = l(i, a, c, f, n[h + 14], 17, -1502002290), c = g(c, f = l(f, i, a, c, n[h + 15], 22, 1236535329), i, a, n[h + 1], 5, -165796510), a = g(a, c, f, i, n[h + 6], 9, -1069501632), i = g(i, a, c, f, n[h + 11], 14, 643717713), f = g(f, i, a, c, n[h], 20, -373897302), c = g(c, f, i, a, n[h + 5], 5, -701558691), a = g(a, c, f, i, n[h + 10], 9, 38016083), i = g(i, a, c, f, n[h + 15], 14, -660478335), f = g(f, i, a, c, n[h + 4], 20, -405537848), c = g(c, f, i, a, n[h + 9], 5, 568446438), a = g(a, c, f, i, n[h + 14], 9, -1019803690), i = g(i, a, c, f, n[h + 3], 14, -187363961), f = g(f, i, a, c, n[h + 8], 20, 1163531501), c = g(c, f, i, a, n[h + 13], 5, -1444681467), a = g(a, c, f, i, n[h + 2], 9, -51403784), i = g(i, a, c, f, n[h + 7], 14, 1735328473), c = v(c, f = g(f, i, a, c, n[h + 12], 20, -1926607734), i, a, n[h + 5], 4, -378558), a = v(a, c, f, i, n[h + 8], 11, -2022574463), i = v(i, a, c, f, n[h + 11], 16, 1839030562), f = v(f, i, a, c, n[h + 14], 23, -35309556), c = v(c, f, i, a, n[h + 1], 4, -1530992060), a = v(a, c, f, i, n[h + 4], 11, 1272893353), i = v(i, a, c, f, n[h + 7], 16, -155497632), f = v(f, i, a, c, n[h + 10], 23, -1094730640), c = v(c, f, i, a, n[h + 13], 4, 681279174), a = v(a, c, f, i, n[h], 11, -358537222), i = v(i, a, c, f, n[h + 3], 16, -722521979), f = v(f, i, a, c, n[h + 6], 23, 76029189), c = v(c, f, i, a, n[h + 9], 4, -640364487), a = v(a, c, f, i, n[h + 12], 11, -421815835), i = v(i, a, c, f, n[h + 15], 16, 530742520), c = m(c, f = v(f, i, a, c, n[h + 2], 23, -995338651), i, a, n[h], 6, -198630844), a = m(a, c, f, i, n[h + 7], 10, 1126891415), i = m(i, a, c, f, n[h + 14], 15, -1416354905), f = m(f, i, a, c, n[h + 5], 21, -57434055), c = m(c, f, i, a, n[h + 12], 6, 1700485571), a = m(a, c, f, i, n[h + 3], 10, -1894986606), i = m(i, a, c, f, n[h + 10], 15, -1051523), f = m(f, i, a, c, n[h + 1], 21, -2054922799), c = m(c, f, i, a, n[h + 8], 6, 1873313359), a = m(a, c, f, i, n[h + 15], 10, -30611744), i = m(i, a, c, f, n[h + 6], 15, -1560198380), f = m(f, i, a, c, n[h + 13], 21, 1309151649), c = m(c, f, i, a, n[h + 4], 6, -145523070), a = m(a, c, f, i, n[h + 11], 10, -1120210379), i = m(i, a, c, f, n[h + 2], 15, 718787259), f = m(f, i, a, c, n[h + 9], 21, -343485551), c = d(c, r), f = d(f, e), i = d(i, o), a = d(a, u); - return [c, f, i, a] - } - - function i(n) { - for (var t = "", r = 32 * n.length, e = 0; e < r; e += 8) t += String.fromCharCode(n[e >> 5] >>> e % 32 & 255); - return t - } - - function a(n) { - var t = []; - for (t[(n.length >> 2) - 1] = void 0, e = 0; e < t.length; e += 1) t[e] = 0; - for (var r = 8 * n.length, e = 0; e < r; e += 8) t[e >> 5] |= (255 & n.charCodeAt(e / 8)) << e % 32; - return t - } - - function e(n) { - for (var t, r = "0123456789abcdef", e = "", o = 0; o < n.length; o += 1) t = n.charCodeAt(o), e += r.charAt(t >>> 4 & 15) + r.charAt(15 & t); - return e - } - - function r(n) { - return unescape(encodeURIComponent(n)) - } - - function o(n) { - return i(c(a(n = r(n)), 8 * n.length)) - } - - function u(n, t) { - return function (n, t) { - var r, e = a(n), o = [], u = []; - for (o[15] = u[15] = void 0, 16 < e.length && (e = c(e, 8 * n.length)), r = 0; r < 16; r += 1) o[r] = 909522486 ^ e[r], u[r] = 1549556828 ^ e[r]; - return t = c(o.concat(a(t)), 512 + 8 * t.length), i(c(u.concat(t), 640)) - }(r(n), r(t)) - } - - function t(n, t, r) { - return t ? r ? u(t, n) : e(u(t, n)) : r ? o(n) : e(o(n)) - } - - "function" == typeof define && define.amd ? define(function () { - return t - }) : "object" == typeof module && module.exports ? module.exports = t : n.md5 = t -}(this); -var md5 = this.md5; -/** - 网关上线 - 订阅:/sys/hbtgIA0SuVw9lxjB/AA:BB:CC:DD:10/c/# - - 子设备注册: - /sys/hbtgIA0SuVw9lxjB/AA:BB:CC:DD:10/s/register - { - "id": "6", - "params":{ - "productKey":"Rf4QSjbm65X45753", - "deviceName":"ABC12400001", - "model":"S1" - } - } - 子设备上线 - 订阅:/sys/Rf4QSjbm65X45753/ABC12400001/c/# - - 数据上报: - /sys/Rf4QSjbm65X45753/ABC12400001/s/event/property/post - { - "id": "6", - "params":{ - "powerstate": 1 - } - } - */ - -var registered = {}; - -function getPkDn(clientId) { - var arr = clientId.split("_"); - return { - pk: arr[0], - dn: arr[1] - }; -} - -function register(payload) { - var auth = JSON.parse(payload); - var arr = auth.clientid.split("_"); - if (arr.length < 3) { - throw new Error("incorrect clientid"); - } - - var pk = arr[0]; - var dn = arr[1]; - var model = arr[2]; - - var product = deviceBehaviour.getProductKey(pk) - var pwd = md5(product.getProductSecret() + auth.clientid); - - if (pwd.toLocaleLowerCase() != auth.password.toLocaleLowerCase()) { - throw new Error("incorrect password" + "pwd->" + pwd + " productSecret->" + product.productSecret); - } - return { - type: "register", - data: { - productKey: pk, - deviceName: dn, - model: model - } - }; -} - -function subRegister(topic, parent, payload) { - var params = payload.params; - var reply = - { - productKey: parent.productKey, - deviceName: parent.deviceName, - mid: "0", - content: { - topic: topic.replace("/s/", "/c/") + "_reply", - payload: JSON.stringify({ - id: "0", - code: 0, - data: { - "productKey": params.productKey, - "deviceName": params.deviceName - } - }) - } - }; - - return { - type: "register", - data: { - productKey: parent.productKey, - deviceName: parent.deviceName, - subDevices: [{ - productKey: params.productKey, - deviceName: params.deviceName, - model: params.model - }] - }, - action: { - type: "ack", - content: JSON.stringify(reply) - } - }; -} - -function deviceStateChange(head, clientId, state) { - var topic = head.topic; - var device = getPkDn(clientId); - - var arr = topic.split('/'); - if (arr.length < 6) { - throw new Error("incorrect topic") - } - - var pk = arr[2]; - var dn = arr[3]; - return { - type: "state", - data: { - productKey: pk, - deviceName: dn, - state: state, - parent: { - productKey: device.pk, - deviceName: device.dn, - } - } - } -} - -function disconnect(clientId) { - var device = getPkDn(clientId); - return { - type: "state", - data: { - productKey: device.pk, - deviceName: device.dn, - state: "offline" - } - } -} - -function ota(head, payload) { - payload = JSON.parse(payload); - var topic = head.topic; - var arr = topic.split('/'); - if (arr.length < 6) { - throw new Error("incorrect topic") - } - - var pk = arr[2]; - var dn = arr[3]; - return { - type: "ota", - data: { - productKey: pk, - deviceName: dn, - mid: payload.id, - content: { - topic: topic, - payload: payload - } - } - } -} - -//必须提供onReceive方法 -this.onReceive = function (head, type, payload) { - if (type == 'auth') { - return register(payload); - } - - if (type == 'subscribe') { - return deviceStateChange(head, payload, 'online'); - } - - if (type == 'unsubscribe') { - return deviceStateChange(head, payload, 'offline'); - } - - if (type == 'disconnect') { - return disconnect(payload); - } - - if (type == 'ota') { - return ota(head, payload); - } - - var topic = head['topic']; - if (!topic) { - throw new Error("topic is blank") - } - - var arr = topic.split('/'); - if (arr.length < 6) { - throw new Error("incorrect topic") - } - var pk = arr[2]; - var dn = arr[3]; - payload = JSON.parse(payload); - - //子设备注册 - if (topic.endsWith('/register')) { - return subRegister(topic, {productKey: pk, deviceName: dn}, payload); - } - - //数据上报 - var reply = - { - productKey: pk, - deviceName: dn, - mid: payload.id, - content: { - topic: topic.replace("/s/", "/c/") + "_reply", - payload: JSON.stringify({ - id: payload.id, - method: payload.method + "_reply", - code: 0, - }) - } - }; - - var action = {}; - if (!topic.endsWith("_reply")) { - //需要回复的消息 - action = { - type: "ack", - content: JSON.stringify(reply) - } - } - - return { - type: "report", - data: { - productKey: pk, - deviceName: dn, - mid: payload.id, - content: { - topic: topic, - payload: payload - } - }, - action: action - } -} - -this.onRegistered = function (regInfo, result) { -} \ No newline at end of file diff --git a/iot-components/iot-mqtt-component/src/main/resources/component.spi b/iot-components/iot-mqtt-component/src/main/resources/component.spi deleted file mode 100755 index 954a8441..00000000 --- a/iot-components/iot-mqtt-component/src/main/resources/component.spi +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.comp.mqtt.MqttDeviceComponent \ No newline at end of file diff --git a/iot-components/iot-mqtt-component/src/main/resources/convert.js b/iot-components/iot-mqtt-component/src/main/resources/convert.js deleted file mode 100644 index 55d46c95..00000000 --- a/iot-components/iot-mqtt-component/src/main/resources/convert.js +++ /dev/null @@ -1,208 +0,0 @@ -var mid = 1; - -function getMid() { - mid++; - if (mid > 10000) { - mid = 1; - } - return mid + ""; -} - -this.decode = function (msg) { - //对msg进行解析,并返回物模型数据 - var content = msg.content; - var topic = content.topic; - var payload = content.payload; - var identifier = topic.substring(topic.lastIndexOf("/") + 1); - - //透传上报 - if (topic.endsWith("/event/rawReport")) { - var rst = component.transparentDecode(payload.params); - if (!rst) { - return null; - } - rst.occur = new Date().getTime(); - rst.time = new Date().getTime(); - return rst; - } - - if (topic.endsWith("/property/post")) { - //属性上报 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type: "property", - identifier: "report", //属性上报 - occur: new Date().getTime(), //时间戳,设备上的事件或数据产生的本地时间 - time: new Date().getTime(), //时间戳,消息上报时间 - data: payload.params, - }; - } else if (topic.indexOf("/ota/") >= 0) { - //事件上报 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type: "ota", - identifier: "ota", - occur: new Date().getTime(), - time: new Date().getTime(), - data: payload.params, - }; - } else if (topic.indexOf("/event/") > 0) { - //事件上报 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type: "event", - identifier: identifier, - occur: new Date().getTime(), - time: new Date().getTime(), - data: payload.params, - }; - } else if (topic.endsWith("/service/property/set_reply")) { - //属性设置回复 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type: "property", - identifier: identifier, - occur: new Date().getTime(), - time: new Date().getTime(), - code: payload.code - }; - } else if (topic.endsWith("/config/set_reply")) { - //设备配置设置回复 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type: "config", - identifier: "set_reply", - occur: new Date().getTime(), - time: new Date().getTime(), - code: payload.code - }; - } else if (topic.endsWith("/config/get")) { - //设备配置获取 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type: "config", - identifier: "get", - occur: new Date().getTime(), - time: new Date().getTime(), - data: {}, - }; - } else if (topic.endsWith("_reply")) { - //服务回复 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type: "service", - identifier: identifier, - occur: new Date().getTime(), - time: new Date().getTime(), - code: payload.code, - data: payload.data, - }; - } - return null; -}; - -this.encode = function (service, device) { - var deviceMid = getMid(); - var method = "thing.service."; - var topic = "/sys/" + service.productKey + "/" + service.deviceName + "/c/service/"; - var params = {}; - - //透传下发 - if (device.transparent) { - var rst = component.transparentEncode(service, device); - topic = "/sys/" + rst.productKey + "/" + rst.deviceName + "/c/service/rawSend"; - params.model = rst.content.model; - params.deviceName = rst.content.deviceName; - params.data = rst.content.data; - - return { - productKey: rst.productKey, - deviceName: rst.deviceName, - mid: rst.mid, - content: { - topic: topic, - payload: JSON.stringify({ - id: rst.mid, - method: method + "rawSend", - params: params - }) - } - } - - } - - var type = service.type; - var identifier = service.identifier; - - if (type == "property") { - method += "property." + identifier; - topic += "property/" + identifier; - } else if (type == "service") { - method += identifier; - topic += identifier; - } else if (type == "ota") { - method += identifier; - topic = "/ota/device/upgrade/" + service.productKey + "/" + service.deviceName; - } else if (type == "config") { - //设备配置下发 - method += identifier; - topic = "/sys/" + service.productKey + "/" + service.deviceName + "/c/config/" + identifier; - } else if (type = "lifetime") { - //子设备注销下发 - method += identifier; - topic = "/sys/" + service.productKey + "/" + service.deviceName + "/c/deregister"; - } - if (type == "property" && identifier == "get") { - var listParams = [] - for (var p in service.params) { - listParams.push(service.params[p]); - } - return { - productKey: service.productKey, - deviceName: service.deviceName, - mid: deviceMid, - content: { - topic: topic, - payload: JSON.stringify({ - id: deviceMid, - method: method, - params: listParams - }) - } - } - } else { - for (var p in service.params) { - params[p] = service.params[p]; - } - return { - productKey: service.productKey, - deviceName: service.deviceName, - mid: deviceMid, - content: { - topic: topic, - payload: JSON.stringify({ - id: deviceMid, - method: method, - params: params - }) - } - } - - } - - -}; diff --git a/iot-components/iot-mqtt-component/src/main/resources/graaljs-converter.js b/iot-components/iot-mqtt-component/src/main/resources/graaljs-converter.js deleted file mode 100644 index ec816c8f..00000000 --- a/iot-components/iot-mqtt-component/src/main/resources/graaljs-converter.js +++ /dev/null @@ -1,178 +0,0 @@ - -var mid=1; - -function getMid(){ - mid++; - if(mid>10000){ - mid=1; - } - return mid+""; -} - -this.decode = function (msg) { - - //对msg进行解析,并返回物模型数据 - console.log("msg", msg); - var content= msg.getContent(); - console.log("content",content); - var topic = content.topic; - console.log("topic",topic); - var payload = content.get("payload"); - console.log("payload",payload); - var identifier = topic.substring(topic.lastIndexOf("/") + 1); - - //透传上报 - if(topic.endsWith("/event/rawReport")){ - var rst= component.transparentDecode(payload.params); - if(!rst){ - return null; - } - rst.occured=new Date().getTime(); - rst.time=new Date().getTime(); - return rst; - } - - if (topic.endsWith("/property/post")) { - //属性上报 - return { - "mid": msg.getMid(), - "productKey": msg.getProductKey(), - "deviceName": msg.getDeviceName(), - "type":"property", - "identifier": "report", //属性上报 - "occured": new Date().getTime(), //时间戳,设备上的事件或数据产生的本地时间 - "time": new Date().getTime(), //时间戳,消息上报时间 - data: payload, - }; - } else if (topic.indexOf("/event/") > 0) { - //事件上报 - return { - mid: msg.getMid(), - productKey: msg.getProductKey(), - deviceName: msg.getDeviceName(), - type:"event", - identifier: identifier, - occured: new Date().getTime(), - time: new Date().getTime(), - data: payload.params, - }; - }else if(topic.endsWith("/service/property/set_reply")){ - //属性设置回复 - return { - mid: msg.getMid(), - productKey: msg.getProductKey(), - deviceName: msg.getDeviceName(), - type:"property", - identifier: identifier, - occured: new Date().getTime(), - time: new Date().getTime(), - code: payload.code - }; - }else if(topic.endsWith("/config/set_reply")){ - //设备配置设置回复 - return { - mid: msg.getMid(), - productKey: msg.getProductKey(), - deviceName: msg.getDeviceName(), - type:"config", - identifier: "set_reply", - occured: new Date().getTime(), - time: new Date().getTime(), - code: payload.code - }; - }else if(topic.endsWith("/config/get")){ - //设备配置获取 - return { - mid: msg.getMid(), - productKey: msg.getProductKey(), - deviceName: msg.getDeviceName(), - type:"config", - identifier: "get", - occured: new Date().getTime(), - time: new Date().getTime(), - data: {}, - }; - } else if (topic.endsWith("_reply")) { - //服务回复 - return { - mid: msg.getMid(), - productKey: msg.getProductKey(), - deviceName: msg.getDeviceName(), - type:"service", - identifier: identifier, - occured: new Date().getTime(), - time: new Date().getTime(), - code: payload.code, - data: payload.data, - }; - } - return null; -}; - -this.encode = function (service,device) { - var deviceMid=getMid(); - var method="thing.service."; - var topic="/sys/"+service.getProductKey()+"/"+service.getDeviceName()+"/c/service/"; - var params={}; - - //透传下发 - if(device.isTransparent()){ - var rst=component.transparentEncode(service,device); - topic="/sys/"+rst.productKey+"/"+rst.deviceName+"/c/service/rawSend"; - params.model=rst.content.model; - params.deviceName=rst.content.deviceName; - params.data=rst.content.data; - - return { - productKey:rst.productKey, - deviceName:rst.deviceName, - mid:rst.mid, - content:{ - topic:topic, - payload:JSON.stringify({ - id:rst.mid, - method:method+"rawSend", - params:params - }) - } - } - - } - - var type=service.getType(); - var identifier=service.getIdentifier(); - - if(type=="property"){ - method+="property."+identifier; - topic+="property/"+identifier; - }else if(type=="service"){ - method+=identifier; - topic+=identifier; - }else if(type=="config"){ - //设备配置下发 - method+=identifier; - topic="/sys/"+service.getProductKey()+"/"+service.getDeviceName()+"/c/config/"+identifier; - }else if(type="lifetime"){ - //子设备注销下发 - method+=identifier; - topic="/sys/"+service.getProductKey()+"/"+service.getDeviceName()+"/c/deregister"; - } - - for(var p in service.getParams()){ - params[p]=service.getParams()[p]; - } - - return { - productKey:service.getProductKey(), - deviceName:service.getDeviceName(), - mid:deviceMid, - content:{ - topic:topic, - payload:JSON.stringify({ - id:deviceMid, - method:method, - params:params - }) - } - } -}; \ No newline at end of file diff --git a/iot-components/iot-mqtt-component/src/main/resources/graaljsconverter.js b/iot-components/iot-mqtt-component/src/main/resources/graaljsconverter.js deleted file mode 100644 index 7182174a..00000000 --- a/iot-components/iot-mqtt-component/src/main/resources/graaljsconverter.js +++ /dev/null @@ -1,173 +0,0 @@ - -var mid=1; - -function getMid(){ - mid++; - if(mid>10000){ - mid=1; - } - return mid+""; -} - -this.decode = function (msg) { - //对msg进行解析,并返回物模型数据 - var content=msg.getContent(); - var topic = content.topic; - var payload = content.payload; - var identifier = topic.substring(topic.lastIndexOf("/") + 1); - - //透传上报 - if(topic.endsWith("/event/rawReport")){ - var rst= component.transparentDecode(payload.params); - if(!rst){ - return null; - } - rst.occur=new Date().getTime(); - rst.time=new Date().getTime(); - return rst; - } - - if (topic.endsWith("/property/post")) { - //属性上报 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type:"property", - identifier: "report", //属性上报 - occur: new Date().getTime(), //时间戳,设备上的事件或数据产生的本地时间 - time: new Date().getTime(), //时间戳,消息上报时间 - data: payload, - }; - } else if (topic.indexOf("/event/") > 0) { - //事件上报 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type:"event", - identifier: identifier, - occur: new Date().getTime(), - time: new Date().getTime(), - data: payload, - }; - }else if(topic.endsWith("/service/property/set_reply")){ - //属性设置回复 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type:"property", - identifier: identifier, - occur: new Date().getTime(), - time: new Date().getTime(), - code: payload.code - }; - }else if(topic.endsWith("/config/set_reply")){ - //设备配置设置回复 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type:"config", - identifier: "set_reply", - occur: new Date().getTime(), - time: new Date().getTime(), - code: payload.code - }; - }else if(topic.endsWith("/config/get")){ - //设备配置获取 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type:"config", - identifier: "get", - occur: new Date().getTime(), - time: new Date().getTime(), - data: {}, - }; - } else if (topic.endsWith("_reply")) { - //服务回复 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type:"service", - identifier: identifier, - occur: new Date().getTime(), - time: new Date().getTime(), - code: payload.code, - data: payload.data, - }; - } - return null; -}; - -this.encode = function (service,device) { - var deviceMid=getMid(); - var method="thing.service."; - var topic="/sys/"+service.productKey+"/"+service.deviceName+"/c/service/"; - var params={}; - - //透传下发 - if(device.transparent){ - var rst=component.transparentEncode(service,device); - topic="/sys/"+rst.productKey+"/"+rst.deviceName+"/c/service/rawSend"; - params.model=rst.content.model; - params.deviceName=rst.content.deviceName; - params.data=rst.content.data; - - return { - productKey:rst.productKey, - deviceName:rst.deviceName, - mid:rst.mid, - content:{ - topic:topic, - payload:JSON.stringify({ - id:rst.mid, - method:method+"rawSend", - params:params - }) - } - } - - } - - var type=service.type; - var identifier=service.identifier; - - if(type=="property"){ - method+="property."+identifier; - topic+="property/"+identifier; - }else if(type=="service"){ - method+=identifier; - topic+=identifier; - }else if(type=="config"){ - //设备配置下发 - method+=identifier; - topic="/sys/"+service.productKey+"/"+service.deviceName+"/c/config/"+identifier; - }else if(type="lifetime"){ - //子设备注销下发 - method+=identifier; - topic="/sys/"+service.productKey+"/"+service.deviceName+"/c/deregister"; - } - - for(var p in service.params){ - params[p]=service.params[p]; - } - - return { - productKey:service.productKey, - deviceName:service.deviceName, - mid:deviceMid, - content:{ - topic:topic, - payload:JSON.stringify({ - id:deviceMid, - method:method, - params:params - }) - } - } -}; \ No newline at end of file diff --git a/iot-components/iot-nb-component/pom.xml b/iot-components/iot-nb-component/pom.xml deleted file mode 100644 index 93075293..00000000 --- a/iot-components/iot-nb-component/pom.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - - cc.iotkit - iot-components - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-nb-component - - - - - cc.iotkit - iot-common-core - - - - cc.iotkit - iot-component-base - - - - cc.iotkit - iot-data-service - - - - cc.iotkit - iot-script-engine - - - - - - io.vertx - vertx-core - - - - io.vertx - vertx-mqtt - - - - io.netty - netty-codec-mqtt - - - - org.slf4j - slf4j-api - - - - org.projectlombok - lombok - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - - io.vertx:vertx-core - io.vertx:vertx-mqtt - io.netty:netty-codec-mqtt - org.luaj:luaj-jse - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - true - false - utf8 - - - - - - \ No newline at end of file diff --git a/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBConfig.java b/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBConfig.java deleted file mode 100644 index a7278f3b..00000000 --- a/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.nb; - -import lombok.Data; - -@Data -public class NBConfig { - - private int port; - - private String sslKey; - - private String sslCert; - - private boolean ssl; - - private boolean useWebSocket; - -} diff --git a/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBDeviceComponent.java b/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBDeviceComponent.java deleted file mode 100644 index 220e9bbc..00000000 --- a/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBDeviceComponent.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.nb; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.thing.ThingService; -import cc.iotkit.common.utils.HexUtil; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.AbstractDeviceComponent; -import cc.iotkit.comp.CompConfig; -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.converter.DeviceMessage; -import cc.iotkit.model.device.message.ThingModelMessage; -import io.vertx.core.Future; -import io.vertx.core.Vertx; -import io.vertx.core.buffer.Buffer; -import lombok.*; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.beanutils.BeanUtils; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CountDownLatch; - -@Slf4j -public class NBDeviceComponent extends AbstractDeviceComponent { - - private Vertx vertx; - private CountDownLatch countDownLatch; - private String deployedId; - private NBVerticle NBVerticle; - private final Map deviceChildToParent = new HashMap<>(); - - @Override - public void create(CompConfig config) { - super.create(config); - vertx = Vertx.vertx(); - NBConfig NBConfig = JsonUtils.parseObject(config.getOther(), NBConfig.class); - NBVerticle = new NBVerticle(NBConfig); - } - - public void start() { - try { - NBVerticle.setExecutor(getHandler()); - countDownLatch = new CountDownLatch(1); - Future future = vertx.deployVerticle(NBVerticle); - future.onSuccess((s -> { - deployedId = s; - countDownLatch.countDown(); - })); - future.onFailure((e) -> { - countDownLatch.countDown(); - log.error("start mqtt component failed", e); - }); - countDownLatch.await(); - future.succeeded(); - } catch (Throwable e) { - throw new BizException(ErrCode.COMPONENT_START_ERROR, e); - } - } - - @SneakyThrows - public void stop() { - NBVerticle.stop(); - Future future = vertx.undeploy(deployedId); - future.onSuccess(unused -> log.info("stop mqtt component success")); - } - - public void destroy() { - } - - @Override - public void onDeviceStateChange(DeviceState state) { - DeviceState.Parent parent = state.getParent(); - if (parent == null) { - return; - } - Device device = new Device(state.getProductKey(), state.getDeviceName()); - - if (DeviceState.STATE_ONLINE.equals(state.getState())) { - //保存子设备所属父设备 - deviceChildToParent.put(device.toString(), - new Device(parent.getProductKey(), parent.getDeviceName()) - ); - } else { - //删除关系 - deviceChildToParent.remove(device.toString()); - } - - } - - @Override - public DeviceMessage send(DeviceMessage message) { - Device child = new Device(message.getProductKey(), message.getDeviceName()); - //作为子设备查找父设备 - Device parent = deviceChildToParent.get(child.toString()); - if (parent == null) { - parent = child; - } - - Object obj = message.getContent(); - if (!(obj instanceof Map)) { - throw new BizException(ErrCode.DATA_FORMAT_ERROR); - } - Message msg = new Message(); - try { - BeanUtils.populate(msg, (Map) obj); - } catch (Throwable e) { - throw new BizException(ErrCode.DATA_FORMAT_ERROR); - } - Buffer content = null; - String topic = msg.getTopic(); - String payload = msg.getPayload(); - if (topic.endsWith("thing/model/down_raw")) { - content = Buffer.buffer(HexUtil.hexStringToByteArray(payload)); - }else { - content = Buffer.buffer(payload); - } - - log.info("publish topic:{},content:{}", topic, content); - NBVerticle.publish(parent.getProductKey(), parent.getDeviceName(), - topic, content); - - return message; - } - - @Override - public CompConfig getConfig() { - return config; - } - - @Data - public static class Message { - private String topic; - private String payload; - } - - @Data - @NoArgsConstructor - @AllArgsConstructor - @ToString - public static class Device { - private String productKey; - private String deviceName; - } - -} diff --git a/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBVerticle.java b/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBVerticle.java deleted file mode 100644 index 6f025c31..00000000 --- a/iot-components/iot-nb-component/src/main/java/cc/iotkit/comp/nb/NBVerticle.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.comp.nb; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.HexUtil; -import cc.iotkit.comp.IMessageHandler; -import cc.iotkit.comp.model.ReceiveResult; -import io.netty.handler.codec.mqtt.MqttConnectReturnCode; -import io.netty.handler.codec.mqtt.MqttProperties; -import io.netty.handler.codec.mqtt.MqttQoS; -import io.vertx.core.AbstractVerticle; -import io.vertx.core.Future; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.net.PemKeyCertOptions; -import io.vertx.mqtt.*; -import io.vertx.mqtt.messages.codes.MqttSubAckReasonCode; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.codec.binary.Hex; -import org.apache.commons.lang3.StringUtils; - -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -@Slf4j -public class NBVerticle extends AbstractVerticle { - - private MqttServer mqttServer; - - private final NBConfig config; - - private IMessageHandler executor; - - private final Map endpointMap = new HashMap<>(); - - // 增加一个客户端连接clientid-连接状态池,避免mqtt关闭的时候走异常断开和mqtt断开的handler,导致多次离线消息 - private static final Map mqttConnectPool = new ConcurrentHashMap<>(); - - public NBVerticle(NBConfig config) { - this.config = config; - } - - public void setExecutor(IMessageHandler executor) { - this.executor = executor; - } - - @Override - public void start() { - MqttServerOptions options = new MqttServerOptions() - .setPort(config.getPort()); - if (config.isSsl()) { - options = options.setSsl(true) - .setKeyCertOptions(new PemKeyCertOptions() - .setKeyPath(config.getSslKey()) - .setCertPath(config.getSslCert())); - } - options.setUseWebSocket(config.isUseWebSocket()); - - mqttServer = MqttServer.create(vertx, options); - mqttServer.endpointHandler(endpoint -> { - log.info("MQTT client:{} request to connect, clean session = {}", endpoint.clientIdentifier(), endpoint.isCleanSession()); - - MqttAuth auth = endpoint.auth(); - if (auth == null) { - return; - } - - String clientId = endpoint.clientIdentifier(); - String authJson = auth.toJson() - .put("clientid", clientId).toString(); - - log.info("MQTT client auth,clientId:{},username:{},password:{}", - clientId, auth.getUsername(), auth.getPassword()); - try { - executor.onReceive(new HashMap<>(), "auth", authJson, (r) -> { - if (r == null) { - //认证失败 - endpoint.reject(MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED); - return; - } - // 固定协议,不需要订阅,直接认为上线 - executor.onReceive(null, "online", clientId); - //保存设备与连接关系 - endpointMap.put(getEndpointKey(r), endpoint); - mqttConnectPool.put(clientId, true); - }); - } catch (Throwable e) { - log.error("auth failed", e); - endpoint.reject(MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED); - return; - } - - log.info("MQTT client keep alive timeout = {} ", endpoint.keepAliveTimeSeconds()); - - endpoint.accept(false); - endpoint.closeHandler((v) -> { - log.warn("client connection closed,clientId:{}", clientId); - if (Boolean.FALSE.equals(mqttConnectPool.get(clientId))) { - return; - } - executor.onReceive(new HashMap<>(), "disconnect", clientId, (r) -> { - //删除设备与连接关系 - endpointMap.remove(getEndpointKey(r)); - }); - }).disconnectMessageHandler(disconnectMessage -> { - log.info("Received disconnect from client, reason code = {}", disconnectMessage.code()); - executor.onReceive(new HashMap<>(), "disconnect", clientId, (r) -> { - //删除设备与连接关系 - endpointMap.remove(getEndpointKey(r)); - mqttConnectPool.put(clientId, false); - }); - }).subscribeHandler(subscribe -> { - List reasonCodes = new ArrayList<>(); - for (MqttTopicSubscription s : subscribe.topicSubscriptions()) { - log.info("Subscription for {},with QoS {}", s.topicName(), s.qualityOfService()); - try { - Map head = new HashMap<>(); - head.put("topic", s.topicName()); - executor.onReceive(head, "subscribe", clientId); - reasonCodes.add(MqttSubAckReasonCode.qosGranted(s.qualityOfService())); - } catch (Throwable e) { - log.error("subscribe failed,topic:" + s.topicName(), e); - reasonCodes.add(MqttSubAckReasonCode.NOT_AUTHORIZED); - } - } - // ack the subscriptions request - endpoint.subscribeAcknowledge(subscribe.messageId(), reasonCodes, MqttProperties.NO_PROPERTIES); - - }).unsubscribeHandler(unsubscribe -> { - for (String t : unsubscribe.topics()) { - log.info("Unsubscription for {}", t); - try { - Map head = new HashMap<>(); - head.put("topic", t); - executor.onReceive(head, "unsubscribe", clientId); - } catch (Throwable e) { - log.error("unsubscribe failed,topic:" + t, e); - } - } - // ack the subscriptions request - endpoint.unsubscribeAcknowledge(unsubscribe.messageId()); - }).publishHandler(message -> { - String payload = Hex.encodeHexString(message.payload().getBytes()); - log.info("Received message:{}, with QoS {}", payload, - message.qosLevel()); - if (StringUtils.isBlank(payload)) { - return; - } - - try { - Map head = new HashMap<>(); - String topic = message.topicName(); - head.put("topic", topic); - if (topic.toLowerCase().contains("ota")) { - executor.onReceive(head, "ota", payload); - } else { - executor.onReceive(head, "", payload); - } - if (message.qosLevel() == MqttQoS.AT_LEAST_ONCE) { - endpoint.publishAcknowledge(message.messageId()); - } else if (message.qosLevel() == MqttQoS.EXACTLY_ONCE) { - endpoint.publishReceived(message.messageId()); - } - } catch (Throwable e) { - log.error("handler message failed,topic:" + message.topicName(), e); - } - }).publishReleaseHandler(endpoint::publishComplete); - }).listen(ar -> { - if (ar.succeeded()) { - log.info("MQTT server is listening on port " + ar.result().actualPort()); - } else { - log.error("Error on starting the server", ar.cause()); - } - }); - } - - @Override - public void stop() throws Exception { - for (MqttEndpoint endpoint : endpointMap.values()) { - executor.onReceive(new HashMap<>(), "disconnect", endpoint.clientIdentifier()); - } - mqttServer.close(voidAsyncResult -> log.info("close mqtt server...")); - } - - private String getEndpointKey(ReceiveResult result) { - if (result == null) { - return null; - } - return getEndpointKey(result.getProductKey(), result.getDeviceName()); - } - - private String getEndpointKey(String productKey, String deviceName) { - return String.format("%s_%s", productKey, deviceName); - } - - public boolean exist(String productKey, String deviceName) { - return endpointMap.containsKey(getEndpointKey(productKey, deviceName)); - } - - public void publish(String productKey, String deviceName, String topic, Buffer msg) { - MqttEndpoint endpoint = endpointMap.get(getEndpointKey(productKey, deviceName)); - if (endpoint == null) { - throw new BizException(ErrCode.SEND_DESTINATION_NOT_FOUND); - } - Future result = endpoint.publish(topic, msg, - MqttQoS.AT_MOST_ONCE, false, false); - result.onFailure(e -> log.error("public topic failed", e)); - result.onSuccess(integer -> log.info("publish success,topic:{},payload:{}", topic, msg)); - } -} diff --git a/iot-components/iot-nb-component/src/main/resources/component.js b/iot-components/iot-nb-component/src/main/resources/component.js deleted file mode 100644 index 082f59fa..00000000 --- a/iot-components/iot-nb-component/src/main/resources/component.js +++ /dev/null @@ -1,339 +0,0 @@ -!function (n) { - "use strict"; - - function d(n, t) { - var r = (65535 & n) + (65535 & t); - return (n >> 16) + (t >> 16) + (r >> 16) << 16 | 65535 & r - } - - function f(n, t, r, e, o, u) { - return d((u = d(d(t, n), d(e, u))) << o | u >>> 32 - o, r) - } - - function l(n, t, r, e, o, u, c) { - return f(t & r | ~t & e, n, t, o, u, c) - } - - function g(n, t, r, e, o, u, c) { - return f(t & e | r & ~e, n, t, o, u, c) - } - - function v(n, t, r, e, o, u, c) { - return f(t ^ r ^ e, n, t, o, u, c) - } - - function m(n, t, r, e, o, u, c) { - return f(r ^ (t | ~e), n, t, o, u, c) - } - - function c(n, t) { - var r, e, o, u; - n[t >> 5] |= 128 << t % 32, n[14 + (t + 64 >>> 9 << 4)] = t; - for (var c = 1732584193, f = -271733879, i = -1732584194, a = 271733878, h = 0; h < n.length; h += 16) c = l(r = c, e = f, o = i, u = a, n[h], 7, -680876936), a = l(a, c, f, i, n[h + 1], 12, -389564586), i = l(i, a, c, f, n[h + 2], 17, 606105819), f = l(f, i, a, c, n[h + 3], 22, -1044525330), c = l(c, f, i, a, n[h + 4], 7, -176418897), a = l(a, c, f, i, n[h + 5], 12, 1200080426), i = l(i, a, c, f, n[h + 6], 17, -1473231341), f = l(f, i, a, c, n[h + 7], 22, -45705983), c = l(c, f, i, a, n[h + 8], 7, 1770035416), a = l(a, c, f, i, n[h + 9], 12, -1958414417), i = l(i, a, c, f, n[h + 10], 17, -42063), f = l(f, i, a, c, n[h + 11], 22, -1990404162), c = l(c, f, i, a, n[h + 12], 7, 1804603682), a = l(a, c, f, i, n[h + 13], 12, -40341101), i = l(i, a, c, f, n[h + 14], 17, -1502002290), c = g(c, f = l(f, i, a, c, n[h + 15], 22, 1236535329), i, a, n[h + 1], 5, -165796510), a = g(a, c, f, i, n[h + 6], 9, -1069501632), i = g(i, a, c, f, n[h + 11], 14, 643717713), f = g(f, i, a, c, n[h], 20, -373897302), c = g(c, f, i, a, n[h + 5], 5, -701558691), a = g(a, c, f, i, n[h + 10], 9, 38016083), i = g(i, a, c, f, n[h + 15], 14, -660478335), f = g(f, i, a, c, n[h + 4], 20, -405537848), c = g(c, f, i, a, n[h + 9], 5, 568446438), a = g(a, c, f, i, n[h + 14], 9, -1019803690), i = g(i, a, c, f, n[h + 3], 14, -187363961), f = g(f, i, a, c, n[h + 8], 20, 1163531501), c = g(c, f, i, a, n[h + 13], 5, -1444681467), a = g(a, c, f, i, n[h + 2], 9, -51403784), i = g(i, a, c, f, n[h + 7], 14, 1735328473), c = v(c, f = g(f, i, a, c, n[h + 12], 20, -1926607734), i, a, n[h + 5], 4, -378558), a = v(a, c, f, i, n[h + 8], 11, -2022574463), i = v(i, a, c, f, n[h + 11], 16, 1839030562), f = v(f, i, a, c, n[h + 14], 23, -35309556), c = v(c, f, i, a, n[h + 1], 4, -1530992060), a = v(a, c, f, i, n[h + 4], 11, 1272893353), i = v(i, a, c, f, n[h + 7], 16, -155497632), f = v(f, i, a, c, n[h + 10], 23, -1094730640), c = v(c, f, i, a, n[h + 13], 4, 681279174), a = v(a, c, f, i, n[h], 11, -358537222), i = v(i, a, c, f, n[h + 3], 16, -722521979), f = v(f, i, a, c, n[h + 6], 23, 76029189), c = v(c, f, i, a, n[h + 9], 4, -640364487), a = v(a, c, f, i, n[h + 12], 11, -421815835), i = v(i, a, c, f, n[h + 15], 16, 530742520), c = m(c, f = v(f, i, a, c, n[h + 2], 23, -995338651), i, a, n[h], 6, -198630844), a = m(a, c, f, i, n[h + 7], 10, 1126891415), i = m(i, a, c, f, n[h + 14], 15, -1416354905), f = m(f, i, a, c, n[h + 5], 21, -57434055), c = m(c, f, i, a, n[h + 12], 6, 1700485571), a = m(a, c, f, i, n[h + 3], 10, -1894986606), i = m(i, a, c, f, n[h + 10], 15, -1051523), f = m(f, i, a, c, n[h + 1], 21, -2054922799), c = m(c, f, i, a, n[h + 8], 6, 1873313359), a = m(a, c, f, i, n[h + 15], 10, -30611744), i = m(i, a, c, f, n[h + 6], 15, -1560198380), f = m(f, i, a, c, n[h + 13], 21, 1309151649), c = m(c, f, i, a, n[h + 4], 6, -145523070), a = m(a, c, f, i, n[h + 11], 10, -1120210379), i = m(i, a, c, f, n[h + 2], 15, 718787259), f = m(f, i, a, c, n[h + 9], 21, -343485551), c = d(c, r), f = d(f, e), i = d(i, o), a = d(a, u); - return [c, f, i, a] - } - - function i(n) { - for (var t = "", r = 32 * n.length, e = 0; e < r; e += 8) t += String.fromCharCode(n[e >> 5] >>> e % 32 & 255); - return t - } - - function a(n) { - var t = []; - for (t[(n.length >> 2) - 1] = void 0, e = 0; e < t.length; e += 1) t[e] = 0; - for (var r = 8 * n.length, e = 0; e < r; e += 8) t[e >> 5] |= (255 & n.charCodeAt(e / 8)) << e % 32; - return t - } - - function e(n) { - for (var t, r = "0123456789abcdef", e = "", o = 0; o < n.length; o += 1) t = n.charCodeAt(o), e += r.charAt(t >>> 4 & 15) + r.charAt(15 & t); - return e - } - - function r(n) { - return unescape(encodeURIComponent(n)) - } - - function o(n) { - return i(c(a(n = r(n)), 8 * n.length)) - } - - function u(n, t) { - return function (n, t) { - var r, e = a(n), o = [], u = []; - for (o[15] = u[15] = void 0, 16 < e.length && (e = c(e, 8 * n.length)), r = 0; r < 16; r += 1) o[r] = 909522486 ^ e[r], u[r] = 1549556828 ^ e[r]; - return t = c(o.concat(a(t)), 512 + 8 * t.length), i(c(u.concat(t), 640)) - }(r(n), r(t)) - } - - function t(n, t, r) { - return t ? r ? u(t, n) : e(u(t, n)) : r ? o(n) : e(o(n)) - } - - "function" == typeof define && define.amd ? define(function () { - return t - }) : "object" == typeof module && module.exports ? module.exports = t : n.md5 = t -}(this); -var md5 = this.md5; -/** - 网关上线 - 订阅:/sys/hbtgIA0SuVw9lxjB/AA:BB:CC:DD:10/c/# - - 子设备注册: - /sys/hbtgIA0SuVw9lxjB/AA:BB:CC:DD:10/s/register - { - "id": "6", - "params":{ - "productKey":"Rf4QSjbm65X45753", - "deviceName":"ABC12400001", - "model":"S1" - } - } - 子设备上线 - 订阅:/sys/Rf4QSjbm65X45753/ABC12400001/c/# - - 数据上报: - /sys/Rf4QSjbm65X45753/ABC12400001/s/event/property/post - { - "id": "6", - "params":{ - "powerstate": 1 - } - } - */ - -var registered = {}; - -function getPkDn(clientId) { - var arr = clientId.split("_"); - return { - pk: arr[0], - dn: arr[1] - }; -} - -function register(payload) { - var auth = JSON.parse(payload); - var arr = auth.clientid.split("_"); - if (arr.length < 3) { - throw new Error("incorrect clientid"); - } - - var pk = arr[0]; - var dn = arr[1]; - var model = arr[2]; - - var product = deviceBehaviour.getProductKey(pk) - var pwd = md5(product.getProductSecret() + auth.clientid); - - if (pwd.toLocaleLowerCase() != auth.password.toLocaleLowerCase()) { - throw new Error("incorrect password" + "pwd->" + pwd + " productSecret->" + product.getProductSecret()); - } - return { - type: "register", - data: { - productKey: pk, - deviceName: dn, - model: model - } - }; -} - -function subRegister(topic, parent, payload) { - var params = payload.params; - var reply = - { - productKey: parent.productKey, - deviceName: parent.deviceName, - mid: "0", - content: { - topic: topic.replace("/s/", "/c/") + "_reply", - payload: JSON.stringify({ - id: "0", - code: 0, - data: { - "productKey": params.productKey, - "deviceName": params.deviceName - } - }) - } - }; - - return { - type: "register", - data: { - productKey: parent.productKey, - deviceName: parent.deviceName, - subDevices: [{ - productKey: params.productKey, - deviceName: params.deviceName, - model: params.model - }] - }, - action: { - type: "ack", - content: JSON.stringify(reply) - } - }; -} - -function deviceStateChangeByClientId(head, clientId, state) { - - var device = getPkDn(clientId); - - return { - type: "state", - data: { - productKey: device.pk, - deviceName: device.dn, - state: state - } - } -} - -function deviceStateChange(head, clientId, state) { - var topic = head.topic; - var device = getPkDn(clientId); - - var arr = topic.split('/'); - if (arr.length < 6) { - throw new Error("incorrect topic") - } - - var pk = arr[2]; - var dn = arr[3]; - return { - type: "state", - data: { - productKey: pk, - deviceName: dn, - state: state, - parent: { - productKey: device.pk, - deviceName: device.dn, - } - } - } -} - -function disconnect(clientId) { - var device = getPkDn(clientId); - return { - type: "state", - data: { - productKey: device.pk, - deviceName: device.dn, - state: "offline" - } - } -} - -function ota(head, payload) { - payload = JSON.parse(payload); - var topic = head.topic; - var arr = topic.split('/'); - if (arr.length < 6) { - throw new Error("incorrect topic") - } - - var pk = arr[2]; - var dn = arr[3]; - return { - type: "ota", - data: { - productKey: pk, - deviceName: dn, - mid: payload.id, - content: { - topic: topic, - payload: payload - } - } - } -} - -//必须提供onReceive方法 -this.onReceive = function (head, type, payload) { - if (type == 'auth') { - return register(payload); - } - else if (type == 'online') { - return deviceStateChangeByClientId(head, payload, 'online'); - } - else if (type == 'subscribe') { - // 此产品无需通过订阅来确认是否上线 - return {}; - } - - else if (type == 'unsubscribe') { - // 此产品无需通过订阅来确认是否下线 - return {}; - } - - else if (type == 'disconnect') { - return disconnect(payload); - } - - else if (type == 'ota') { - return ota(head, payload); - } - - var topic = head['topic']; - if (!topic) { - throw new Error("topic is blank") - } - - var arr = topic.split('/'); - if (arr.length < 6) { - throw new Error("incorrect topic") - } - var pk = arr[2]; - var dn = arr[3]; - - //子设备注册 - if (topic.endsWith('/register')) { - return subRegister(topic, {productKey: pk, deviceName: dn}, payload); - } - - //数据上报 - var reply = - { - productKey: pk, - deviceName: dn, - // mid: payload.id, - content: { - topic: topic.replace("/s/", "/c/") + "_reply", - payload: JSON.stringify({ - // id: payload.id, - method: "thing.event.property.post", - code: 0, - }) - } - }; - - var action = {}; - if (!topic.endsWith("_reply")) { - //需要回复的消息 - action = { - type: "ack", - content: JSON.stringify(reply) - } - } - - return { - type: "report", - data: { - productKey: pk, - deviceName: dn, - mid: "3", - content: { - topic: topic, - payload: payload - } - }, - action: action - } -} - -this.onRegistered = function (regInfo, result) { -} \ No newline at end of file diff --git a/iot-components/iot-nb-component/src/main/resources/component.spi b/iot-components/iot-nb-component/src/main/resources/component.spi deleted file mode 100644 index 74979ba0..00000000 --- a/iot-components/iot-nb-component/src/main/resources/component.spi +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.comp.nb.NBDeviceComponent \ No newline at end of file diff --git a/iot-components/iot-nb-component/src/main/resources/convert.js b/iot-components/iot-nb-component/src/main/resources/convert.js deleted file mode 100644 index 33f27c4e..00000000 --- a/iot-components/iot-nb-component/src/main/resources/convert.js +++ /dev/null @@ -1,595 +0,0 @@ -var mid = 1; -var COMMAD_UNKOWN = 0xff; //未知的命令 -function getMid() { - mid++; - if (mid > 10000) { - mid = 1; - } - return mid + ""; -} -//上行数据 -this.decode = function (msg) { - var content = msg.content; - var topic = content.topic; - var bytes = arrayGroup(content.payload,2); - var byteData=content.payload; - if (topic.endsWith("/thing/model/up_raw")) { - var data = arrayGroup(byteData, 2); - var params = {}; - var uint8Array = new Uint8Array(bytes.length); - for (var i = 0; i < bytes.length; i++) { - uint8Array[i] = bytes[i] & 0xff; - } - if (data[1] == '03') { - if (byteData.length == 22 ) { - params['Switch'] = Number(parseInt(data[3] + data[4], 16)) - params['HandMode'] = Number(parseInt(data[5] + data[6], 16))+1 - params['TempGear'] = Number(data[7].slice(1,2))+1 - params['RatioGear'] = Number(data[7].slice(0,1))+1 - params['PressureGear'] = data[8].slice(0,1) != 'f' ? Number(data[8].slice(0,1))+1 : 0 - params['SpeedGear'] = data[8].slice(1,2) != 'f' ? Number(data[8].slice(1,2))+1 : 0 - - } else if (byteData.length == 126) { - params['Pressure'] = Number((parseInt(data[3] + data[4], 16) / 100).toFixed(1)) - params['EmtyRunPressure'] = Number((parseInt(data[5] + data[6], 16) / 100).toFixed(1)) - params['StartPressure'] = Number((parseInt(data[7] + data[8], 16) / 100).toFixed(1)) - params['WorkMode'] = Number((parseInt(data[9] + data[10], 16)).toFixed(0)) - params['ClearIceEn'] = Number((parseInt(data[11] + data[12], 16)).toFixed(0)) - params['WaterT'] = Number((parseInt(data[13] + data[14], 16)).toFixed(0)) - params['WaterTReset'] = Number((parseInt(data[15] + data[16], 16)).toFixed(0)) - params['SensorMode'] = Number((parseInt(data[17] + data[18], 16)).toFixed(0)) - params['SensorGroup'] = Number((parseInt(data[19] + data[20], 16)).toFixed(0)) - params['ElectronicTMax'] = Number(parseInt(data[59], 16)) - params['ElectronicTMaxReset'] = Number(parseInt(data[60], 16)) - } else if (byteData.length == 26) { - params['ActiveTime'] = String(parseInt(data[3], 16))+'-'+String(parseInt(data[4], 16))+'-'+String(parseInt(data[5], 16)) - } else if (byteData.length == 190) { - params['Pressure'] = Number((parseInt(data[3] + data[4], 16) / 100).toFixed(1)) - params['EmtyRunPressure'] = Number((parseInt(data[5] + data[6], 16) / 100).toFixed(1)) - params['StartPressure'] = Number((parseInt(data[7] + data[8], 16) / 100).toFixed(1)) - params['WorkMode'] = Number((parseInt(data[9] + data[10], 16)).toFixed(0)) - params['ClearIceEn'] = Number((parseInt(data[11] + data[12], 16)).toFixed(0)) - params['WaterT'] = Number((parseInt(data[13] + data[14], 16)).toFixed(0)) - params['WaterTReset'] = Number((parseInt(data[15] + data[16], 16)).toFixed(0)) - params['SensorMode'] = Number((parseInt(data[17] + data[18], 16)).toFixed(0)) - params['SensorGroup'] = Number((parseInt(data[19] + data[20], 16)).toFixed(0)) - params['ElectronicTMax'] = Number(parseInt(data[59], 16)) - params['ElectronicTMaxReset'] = Number(parseInt(data[60], 16)) - params['SceneMode'] = Number((parseInt(data[63] + data[64], 16)).toFixed(0)) - params['EnergyModeTime'] = Number((parseInt(data[65] + data[66], 16)).toFixed(0)) - params['WaterTime'] = String(Number((parseInt(data[68].substring(0, 1), 16)).toFixed(0))) + ',' + String(Number((parseInt(data[68].substring(1), 16)).toFixed(0))) - params['HotWaterTime'] = Number((parseInt(data[69] + data[70], 16)).toFixed(0)) - params['TempSet'] = String(Number((parseInt(data[71], 16)).toFixed(0)))+','+ String(Number((parseInt(data[72], 16)).toFixed(0))) - params['TimeModeSet'] = parseInt(data[73] + data[74], 16)+'-'+parseInt(data[75] + data[76], 16)+','+ parseInt(data[77] + data[78], 16)+'-'+parseInt(data[79] + data[80], 16)+','+ parseInt(data[81] + data[82], 16)+'-'+parseInt(data[83] + data[84], 16)+','+ parseInt(data[85] + data[86], 16)+'-'+parseInt(data[87] + data[88], 16)+','+ parseInt(data[89] + data[90], 16)+'-'+parseInt(data[91] + data[92], 16) - - } else if (byteData.length == 94) { - let timeStamp = parseInt(String(data[41])+String(data[42])+String(data[43])+String(data[44]),16) - let time = timestampToTime(timeStamp) - params['ActiveTime'] = String(parseInt(data[3], 16))+'-'+String(parseInt(data[4], 16))+'-'+String(parseInt(data[5], 16)) - params['Time'] = time + '-'+ timeStamp - - } - } else if (data[1] == '04') { - if (byteData.length == 54) { - params['ErrorMsg'] = Number(parseInt(data[3]+data[4], 16)) - params['Voltage'] = Number(parseInt(data[5]+data[6], 16)) - params['Electric'] = Number(parseInt(data[7]+data[8], 16))/10 - params['Power'] = Number(parseInt(data[9]+data[10], 16)) - params['Speed'] = Number(parseInt(data[11]+data[12], 16)) - params['CurrentPressure1'] = data[13] != 'ff' ? Number((parseInt(data[13]+data[14], 16)/100).toFixed(1)) : 0 - params['CurrentPressure2'] = data[15] != 'ff' ? Number((parseInt(data[15]+data[16], 16)/100).toFixed(1)) : 0 - params['IpmTemperature'] = Number(parseInt(data[17]+data[18], 16))-55 - params['MotorTemperature'] = Number(parseInt(data[19]+data[20], 16))-55 - params['WaterTemperature'] = Number(parseInt(data[21]+data[22], 16))-55 - let warnArray = reverseStr(hex2bin(data[23] + data[24])) - let warnInfo = "" - for (let i = 0; i < warnArray.length; i++) { - if (warnArray[i] === "1") { - if (warnInfo === "") { - warnInfo = DEVICE_ERROR[i] - } else { - warnInfo += `、${DEVICE_ERROR[i]}` - } - } - } - - params['WarnInfo'] = warnInfo - - } else if (byteData.length == 18) { - if (String(byteData) == '130404000800004847') { - params['query'] = String(byteData) - } else if (String(byteData).slice(9,10) == 3) { - params['query'] = String(byteData) - } else if (String(byteData).slice(9,10) == 4) { - params['query'] = String(byteData) - } - } else if (byteData.length == 30) { - params['McuVersion'] = String(Number(parseInt(data[3].slice(1,2), 16)))+'.'+String(Number(parseInt(data[4].slice(0,1), 16)))+'.'+String(Number(parseInt(data[4].slice(1,2), 16))) - params['McuStatus'] = Number(parseInt(data[3].slice(0,1), 16)) - params['Scene'] = Number(parseInt(data[9]+data[10], 16)) - params['Model'] = String(Number(parseInt(data[11]+data[12], 16)))+'W' - - } else if (byteData.length == 66) { - params['ErrorMsg'] = Number(parseInt(data[3]+data[4], 16)) - params['Voltage'] = Number(parseInt(data[5]+data[6], 16)) - params['Electric'] = Number(parseInt(data[7]+data[8], 16))/10 - params['Power'] = Number(parseInt(data[9]+data[10], 16)) - params['Speed'] = Number(parseInt(data[11]+data[12], 16)) - params['CurrentPressure1'] = data[13] != 'ff' ? Number((parseInt(data[13]+data[14], 16)/100).toFixed(1)) : 0 - params['CurrentPressure2'] = data[15] != 'ff' ? Number((parseInt(data[15]+data[16], 16)/100).toFixed(1)) : 0 - params['IpmTemperature'] = Number(parseInt(data[17]+data[18], 16))-55 - params['MotorTemperature'] = Number(parseInt(data[19]+data[20], 16))-55 - params['WaterTemperature'] = Number(parseInt(data[21]+data[22], 16))-55 - let warnArray = reverseStr(hex2bin(data[23] + data[24])) - let warnInfo = "" - for (let i = 0; i < warnArray.length; i++) { - if (warnArray[i] === "1") { - if (warnInfo === "") { - warnInfo = DEVICE_ERROR[i] - } else { - warnInfo += `、${DEVICE_ERROR[i]}` - } - } - } - params['CountDown'] = Number(parseInt(data[25]+data[26], 16)) - params['WarnInfo'] = warnInfo - params['Enabled'] = Number(parseInt(data[29]+data[30], 16)) - - } - } - params['History'] = byteData - //属性上报 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type: "property", - identifier: "report", //属性上报 - occur: new Date().getTime(), //时间戳,设备上的事件或数据产生的本地时间 - time: new Date().getTime(), //时间戳,消息上报时间 - data: params, - }; - } - return null; -}; - -//下行数据 -this.encode = function (service, device) { - var deviceMid = getMid(); - var method = "thing.service."; - var topic = "/sys/" + service.productKey + "/" + service.deviceName + "/thing/model/down_raw"; - var params = {}; - var payloadArray = []; - var deviceArray = [];; - var totalArray =[]; - var totalItemArray = []; - var itemArray = []; - var outFFIndex = '' - var type = service.type; - var identifier = service.identifier; - if (type == "property" && identifier == "get") { - var listParams = [] - for (var p in service.params) { - listParams.push(service.params[p]); - } - return { - productKey: service.productKey, - deviceName: service.deviceName, - mid: deviceMid, - content: { - topic: topic, - payload: JSON.stringify({ - id: deviceMid, - method: method += "property." + identifier, - params: listParams - }) - } - } - } else if (type == "property" && identifier == "set") { - for (var p in service.params) { - params[p] = service.params[p]; - } - var paramsArr = Object.keys(params) - //站地址 - if (paramsArr.includes('query')) { - let queryHexData = arrayGroup(params['query'],2) - let queryData = [] - queryHexData.map(function(value) { - queryData.push(parseInt(value,16)) - }) - payloadArray = queryData - } else { - const stationAddress = "49"; - totalArray.push(stationAddress) - //功能码 - var functionCode = ""; - // 寄存器数量 - var register = '' - var baseVal = '' - //起始地址 - var startAddressCode = ''; - if (paramsArr.length == 1) { - functionCode = '06' - totalArray.push(functionCode) - } else { - functionCode = '10' - paramsArr = ['Pressure', 'EmtyRunPressure', 'StartPressure', 'WorkMode', 'ClearIceEn', 'WaterT', 'WaterTReset'] - totalArray.push(parseInt(Number(functionCode),16)) - } - if (paramsArr.includes('Switch')) { - startAddressCode = 300 - totalArray.push('01','44') - } else if (paramsArr.includes('Pressure')) { - startAddressCode = 400 - totalArray.push('01','144') - register = '00' + add0(String(paramsArr.length),2) + add0(String((paramsArr.length*2).toString(16)),2) - totalArray.push('00', add0(paramsArr.length,2), add0(String((paramsArr.length)*2),2)) - } - if (functionCode == 6) { - paramsArr.forEach(function(value){ - totalArray.push('00',params[value]) - itemArray = pad(params[value].toString(16),4) - deviceArray.push(itemArray[0],itemArray[1]) - }) - } else if (functionCode == 10) { - paramsArr.forEach(function(value, index){ - if (index < 3) { - // if (params[value]*100 < 256) { - // totalItemArray = ['00', String((params[value]*100).toFixed(0))] - // itemArray = pad(String((params[value]*100).toString(16)),4) - // totalItemArray = pad(String((params[value]*100).toFixed(0)),4) - // } else { - // outFFIndex = ((Number(params[value]*100))/256).toFixed(0) - // totalItemArray = [outFFIndex, params[value]*100-outFFIndex*256] - // } - - itemArray = pad(Number((params[value]*100).toFixed(0)).toString(16),4) - totalItemArray = pad(String((params[value]*100).toFixed(0)),4) - } else { - itemArray = pad(String(params[value].toString(16)),4) - totalItemArray = pad(String(params[value]),4) - } - // totalArray.push(params[value]) - // totalArray.push(totalItemArray[0],totalItemArray[1]) - totalArray.push(parseInt(itemArray[0],16),parseInt(itemArray[1],16)) - // deviceArray.push(parseInt(itemArray[0],16),parseInt(itemArray[1],16)) - deviceArray.push(itemArray[0],itemArray[1]) - - }) - } - - var startAddressHex = pad(startAddressCode.toString(16), 4); - baseVal = String(stationAddress) + String(functionCode) + String(startAddressHex[0]) + String(startAddressHex[1]) - if (functionCode != 6) { - baseVal += register - } - deviceArray.forEach(function(item) { - baseVal += item - }) - // baseVal += '00070e0064000a00640001000100370037' - var Crc = CRC.ToModbusCRC16(baseVal) - var crcArray = arrayGroup(Crc,2) - totalArray.push(parseInt(crcArray[0],16),parseInt(crcArray[1],16)) - payloadArray = totalArray; - } - // var params = json['params']; - // var prop_float = params['prop_float']; - // var prop_int16 = params['prop_int16']; - // var prop_bool = params['prop_bool']; - // //按照自定义协议格式拼接 rawData。 - // payloadArray = payloadArray.concat(buffer_uint8(COMMAND_SET)); //command字段。 - // payloadArray = payloadArray.concat(buffer_int32(parseInt(id))); //ALink JSON格式 'id'。 - // payloadArray = payloadArray.concat(buffer_int16(prop_int16)); //属性'prop_int16'的值。 - // payloadArray = payloadArray.concat(buffer_uint8(prop_bool)); //属性'prop_bool'的值。 - // payloadArray = payloadArray.concat(buffer_float32(prop_float)); //属性'prop_float'的值。 - - }else if (method == 'thing.event.property.post') { //设备上报数据返回结果,如果不需要回复,可以去除该内容 - // var code = json['code']; - // payloadArray = payloadArray.concat(buffer_uint8(COMMAND_REPORT_REPLY)); //command字段 - // payloadArray = payloadArray.concat(buffer_int32(parseInt(id))); // ALink JSON格式 'id' - // payloadArray = payloadArray.concat(buffer_uint8(code)); - } else { //未知命令,对于有些命令不做处理 - var code = "FF"; - payloadArray = payloadArray.concat(buffer_uint8(COMMAD_UNKOWN)); //command字段 - payloadArray = payloadArray.concat(buffer_int32(parseInt(id))); // ALink JSON格式 'id' - payloadArray = payloadArray.concat(buffer_uint8(code)); - } - var hexstr = ab2hex(payloadArray); - console.log("hexstr:" + hexstr); - - return { - productKey: service.productKey, - deviceName: service.deviceName, - mid: deviceMid, - content: { - topic: topic, - payload: hexstr - } - } -}; - - -const DEVICE_ERROR = [ - "压力传感器故障", //0 - "高温限功率", //1 - "渗漏", // 2 - "电机温度传感器故障", //3 - "水温传感器故障", //4 - "保留", //5 - "保留", //6 - "保留", //7 - "保留", //8 - "保留", //9 - "保留", //10 - "保留", //11 - "保留", //12 - "保留", //13 - "保留", //14 - "保留", // 15 - "保留", //16 -] -function buffer_uint8(value) { - var uint8Array = new Uint8Array(1); - var dv = new DataView(uint8Array.buffer, 0); - dv.setUint8(0, value); - return [].slice.call(uint8Array); -} -function buffer_int16(value) { - var uint8Array = new Uint8Array(2); - var dv = new DataView(uint8Array.buffer, 0); - dv.setInt16(0, value); - return [].slice.call(uint8Array); -} -function buffer_int32(value) { - var uint8Array = new Uint8Array(4); - var dv = new DataView(uint8Array.buffer, 0); - dv.setInt32(0, value); - return [].slice.call(uint8Array); -} -function buffer_float32(value) { - var uint8Array = new Uint8Array(4); - var dv = new DataView(uint8Array.buffer, 0); - dv.setFloat32(0, value); - return [].slice.call(uint8Array); -} - -function ab2hex(buffer) { - var hexArr = Array.prototype.map.call( - new Uint8Array(buffer), - function (bit) { - return ('00' + bit.toString(16)).slice(-2) - } - ) - return hexArr.join(''); -} - -function arrayGroup(ss, step) { - var r = []; - - function doGroup(s) { - if (!s) return; - r.push(s.substr(0, step)); - s = s.substr(step); - doGroup(s); - } - doGroup(ss); - return r; -} - -var CRC = {}; - -CRC._auchCRCHi = [ - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, - 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, - 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, - 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 -]; -CRC._auchCRCLo = [ - 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, - 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, - 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, - 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, - 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, - 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, - 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, - 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, - 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, - 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, - 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, - 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, - 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, - 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, - 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, - 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, - 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, - 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, - 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, - 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, - 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, - 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, - 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, - 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, - 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, - 0x43, 0x83, 0x41, 0x81, 0x80, 0x40 -]; - -CRC.CRC16 = function (buffer) { - var hi = 0xff; - var lo = 0xff; - for (var i = 0; i < buffer.length; i++) { - var idx = hi ^ buffer[i]; - hi = (lo ^ CRC._auchCRCHi[idx]); - lo = CRC._auchCRCLo[idx]; - } - return CRC.padLeft((hi << 8 | lo).toString(16).toUpperCase(), 4, '0'); -}; - -CRC.isArray = function (arr) { - return Object.prototype.toString.call(arr) === '[object Array]'; -}; - -CRC.ToCRC16 = function (str) { - return CRC.CRC16(CRC.isArray(str) ? str : CRC.strToByte(str)); -}; - -CRC.ToModbusCRC16 = function (str) { - return CRC.CRC16(CRC.isArray(str) ? str : CRC.strToHex(str)); -}; - -CRC.strToByte = function (str) { - var tmp = str.split(""), - arr = []; - for (var i = 0, c = tmp.length; i < c; i++) { - var j = encodeURI(tmp[i]); - if (j.length == 1) { - arr.push(j.charCodeAt()); - } else { - var b = j.split("%"); - for (var m = 1; m < b.length; m++) { - arr.push(parseInt('0x' + b[m])); - } - } - } - return arr; -}; - -CRC.convertChinese = function (str) { - var tmp = str.split(""), - arr = []; - for (var i = 0, c = tmp.length; i < c; i++) { - var s = tmp[i].charCodeAt(); - if (s <= 0 || s >= 127) { - arr.push(s.toString(16)); - } else { - arr.push(tmp[i]); - } - } - return arr; -}; - -CRC.filterChinese = function (str) { - var tmp = str.split(""), - arr = []; - for (var i = 0, c = tmp.length; i < c; i++) { - var s = tmp[i].charCodeAt(); - if (s > 0 && s < 127) { - arr.push(tmp[i]); - } - } - return arr; -}; - -CRC.strToHex = function (hex, isFilterChinese) { - hex = isFilterChinese ? CRC.filterChinese(hex).join('') : CRC.convertChinese(hex).join(''); - - //清除所有空格 - hex = hex.replace(/\s/g, ""); - //若字符个数为奇数,补一个空格 - hex += hex.length % 2 != 0 ? " " : ""; - - var c = hex.length / 2, - arr = []; - for (var i = 0; i < c; i++) { - arr.push(parseInt(hex.substr(i * 2, 2), 16)); - } - return arr; -}; - -CRC.padLeft = function (s, w, pc) { - if (pc == undefined) { - pc = '0'; - } - for (var i = 0, c = w - s.length; i < c; i++) { - s = pc + s; - } - return s; -}; - -function str2ab(str) { - var buffer = new ArrayBuffer(str.length / 2); // 2 bytes for each char - var dataView = new DataView(buffer); - var str = str.split("") - var n = 0; - for (var i = 0; i < str.length; i = i + 2) { - dataView.setUint8(n, `0x${str[i]}${str[i+1]}`) - n++; - } - return buffer; -} - -function pad(num, n, flag = false) { - var len = num.toString().length; - while (len < n) { - num = "0" + num; - len++; - } - - const arr = arrayGroup(num, 2) - //高低位互换 - if (arr[1] == '00') { - flag = true - } - return flag ? [arr[1], arr[0]] : [arr[0], arr[1]]; -} - -function add0(num,n) { - let len = num.length - while(len < n){ - num = '0'+num - len++ - } - if (len > n) { - num = String(num).slice(1) - } - //console.log(num) - return num -} - -function hex2bin(hex, len) { - var bin = parseInt(hex, 16).toString(2); - var l = bin.length; - for (var i = 0; i < len - l; i++) { - bin = "0" + bin; - } - return bin; -} - -//翻转字符串并切割成数组 -function reverseStr(str) { - var arr = str.split(""); - arr.reverse(); - return arr; -} - -function timestampToTime(timestamp) { - var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000 - var Y = date.getFullYear() + '-'; - var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'; - var D = date.getDate() + ' '; - var h = date.getHours() + ':'; - var m = date.getMinutes() + ':'; - var s = date.getSeconds(); - return Y+M+D+h+m+s; -} \ No newline at end of file diff --git a/iot-components/iot-websocket-component/pom.xml b/iot-components/iot-websocket-component/pom.xml deleted file mode 100644 index 547afdff..00000000 --- a/iot-components/iot-websocket-component/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - iot-components - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-websocket-component - - - - - cc.iotkit - iot-common-core - - - - cc.iotkit - iot-component-base - - - - - - io.vertx - vertx-core - - - - org.projectlombok - lombok - - - - org.slf4j - slf4j-api - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - package - - shade - - - - - - - io.vertx:vertx-core - org.luaj:luaj-jse - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - true - false - utf8 - - - - - - diff --git a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/AbstractDeviceVerticle.java b/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/AbstractDeviceVerticle.java deleted file mode 100644 index e2d3c67e..00000000 --- a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/AbstractDeviceVerticle.java +++ /dev/null @@ -1,18 +0,0 @@ -package cc.iotkit.comp.websocket; - -import cc.iotkit.comp.IMessageHandler; -import cc.iotkit.converter.DeviceMessage; -import io.vertx.core.AbstractVerticle; -import lombok.Data; - -@Data -public abstract class AbstractDeviceVerticle extends AbstractVerticle { - - public static final String TYPE_SERVER = "server"; - public static final String TYPE_CLIENT = "client"; - - protected IMessageHandler executor; - - public abstract DeviceMessage send(DeviceMessage message); - -} diff --git a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/WebSocketDeviceComponent.java b/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/WebSocketDeviceComponent.java deleted file mode 100644 index be1a559a..00000000 --- a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/WebSocketDeviceComponent.java +++ /dev/null @@ -1,116 +0,0 @@ -package cc.iotkit.comp.websocket; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.AbstractDeviceComponent; -import cc.iotkit.comp.CompConfig; -import cc.iotkit.comp.model.DeviceState; -import cc.iotkit.comp.websocket.client.WebSocketClientVerticle; -import cc.iotkit.comp.websocket.server.WebSocketServerVerticle; -import cc.iotkit.converter.DeviceMessage; -import io.vertx.core.Future; -import io.vertx.core.Vertx; -import lombok.*; -import lombok.extern.slf4j.Slf4j; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CountDownLatch; - -@Slf4j -public class WebSocketDeviceComponent extends AbstractDeviceComponent { - - private Vertx vertx; - private CountDownLatch countDownLatch; - private String deployedId; - private AbstractDeviceVerticle webSocketVerticle; - private final Map deviceChildToParent = new HashMap<>(); - - @Override - public void create(CompConfig config) { - super.create(config); - vertx = Vertx.vertx(); - String type = JsonUtils.parseObject(config.getOther(), Map.class).get("type").toString(); - if(AbstractDeviceVerticle.TYPE_CLIENT.equals(type)){ - webSocketVerticle = new WebSocketClientVerticle(config.getOther()); - }else{ - webSocketVerticle = new WebSocketServerVerticle(config.getOther()); - } - } - - @Override - public void start() { - try { - webSocketVerticle.setExecutor(getHandler()); - countDownLatch = new CountDownLatch(1); - Future future = vertx.deployVerticle(webSocketVerticle); - future.onSuccess((s -> { - deployedId = s; - countDownLatch.countDown(); - })); - future.onFailure((e) -> { - countDownLatch.countDown(); - log.error("start websocket component failed", e); - }); - countDownLatch.await(); - future.succeeded(); - } catch (Throwable e) { - throw new BizException(ErrCode.COMPONENT_START_ERROR, e); - } - } - - @Override - @SneakyThrows - public void stop() { - webSocketVerticle.stop(); - Future future = vertx.undeploy(deployedId); - future.onSuccess(unused -> log.info("stop websocket component success")); - } - - @Override - public void destroy() { - } - - @Override - public void onDeviceStateChange(DeviceState state) { - DeviceState.Parent parent = state.getParent(); - if (parent == null) { - return; - } - Device device = new Device(state.getProductKey(), state.getDeviceName()); - - if (DeviceState.STATE_ONLINE.equals(state.getState())) { - //保存子设备所属父设备 - deviceChildToParent.put(device.toString(), - new Device(parent.getProductKey(), parent.getDeviceName()) - ); - } else { - //删除关系 - deviceChildToParent.remove(device.toString()); - } - - } - - @Override - public DeviceMessage send(DeviceMessage message) { - webSocketVerticle.send(message); - return message; - } - - @Override - public CompConfig getConfig() { - return config; - } - - - @Data - @NoArgsConstructor - @AllArgsConstructor - @ToString - public static class Device { - private String productKey; - private String deviceName; - } - -} diff --git a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/client/WebSocketClientConfig.java b/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/client/WebSocketClientConfig.java deleted file mode 100644 index 2867ca71..00000000 --- a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/client/WebSocketClientConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package cc.iotkit.comp.websocket.client; - -import lombok.Data; - -@Data -public class WebSocketClientConfig { - - private int port; - - private String ip; - - private String url; - - private long heartBeatTime; - - private String heartBeatData; - - private boolean ssl; - -} diff --git a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/client/WebSocketClientVerticle.java b/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/client/WebSocketClientVerticle.java deleted file mode 100644 index e5c50a9b..00000000 --- a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/client/WebSocketClientVerticle.java +++ /dev/null @@ -1,127 +0,0 @@ -package cc.iotkit.comp.websocket.client; - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.model.ReceiveResult; -import cc.iotkit.comp.model.RegisterInfo; -import cc.iotkit.comp.websocket.AbstractDeviceVerticle; -import cc.iotkit.converter.DeviceMessage; -import io.vertx.core.Future; -import io.vertx.core.http.HttpClient; -import io.vertx.core.http.WebSocket; -import io.vertx.core.http.WebSocketConnectOptions; -import lombok.*; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -@Slf4j -public class WebSocketClientVerticle extends AbstractDeviceVerticle { - - public static final String DISCONNECT = "disconnect"; - - private HttpClient httpClient; - - private WebSocket webSocketClient; - - private WebSocketClientConfig webSocketConfig; - - private long timerID; - - private final Map devices = new ConcurrentHashMap<>(); - - public void setWebSocketClient(WebSocket webSocketClient) { - this.webSocketClient = webSocketClient; - } - - public WebSocketClientVerticle(String config) { - this.webSocketConfig = JsonUtils.parseObject(config, WebSocketClientConfig.class); - } - - @Override - public void start() { - WebSocketConnectOptions options = new WebSocketConnectOptions().setPort(webSocketConfig.getPort()) - .setHost(webSocketConfig.getIp()).setURI(webSocketConfig.getUrl()).setSsl(webSocketConfig.isSsl()); - httpClient = vertx.createHttpClient(); - httpClient.webSocket(options).onSuccess(ws -> { - setWebSocketClient(ws); - log.info("webSocket client connect success!"); - ws.textMessageHandler(data -> { - log.info("webSocket client receive msg:" + data); - executor.onReceive(new HashMap<>(), null, data, ret -> { - if (ret != null && ret.getData() instanceof RegisterInfo) { - executor.onReceive(null, "connected", data, r -> { - if (!devices.containsKey(getDeviceKey(r))) { - devices.put(getDeviceKey(r), new Device(r.getDeviceName(), r.getProductKey())); - } - }); - } - }); - }); - ws.closeHandler(e -> { - for (String deviceKey : devices.keySet()) { - executor.onReceive(null, DISCONNECT, deviceKey); - } - log.warn("client connection closed!"); - }); - ws.exceptionHandler(e -> { - for (String deviceKey : devices.keySet()) { - executor.onReceive(null, DISCONNECT, deviceKey); - } - log.error("webSocket client connect exception!"); - }); - if (webSocketConfig.getHeartBeatTime() > 0 && StringUtils.isNotBlank(webSocketConfig.getHeartBeatData())) { - timerID = vertx.setPeriodic(webSocketConfig.getHeartBeatTime(), t -> { - if (webSocketClient.isClosed()) { - vertx.cancelTimer(timerID); - } - executor.onReceive(new HashMap<>(), "ping", JsonUtils.toJsonString(webSocketConfig)); - }); - } - }).onFailure(e -> log.info("webSocket client connect failed!")); - } - - @SneakyThrows - @Override - public void stop() { - vertx.cancelTimer(timerID); - for (String deviceKey : devices.keySet()) { - executor.onReceive(null, DISCONNECT, deviceKey); - } - httpClient.close(); - } - - @Override - public DeviceMessage send(DeviceMessage message) { - Object obj = message.getContent(); - if (!(obj instanceof Map)) { - throw new BizException(ErrCode.DATA_FORMAT_ERROR); - } - String msgStr = JsonUtils.toJsonString(obj); - log.info("send msg payload:{}", msgStr); - Future result = webSocketClient.writeTextMessage(msgStr); - result.onFailure(e -> log.error("webSocket client send msg failed", e)); - return message; - } - - private String getDeviceKey(ReceiveResult result) { - return getDeviceKey(result.getProductKey(), result.getDeviceName()); - } - - private String getDeviceKey(String productKey, String deviceName) { - return String.format("%s_%s", productKey, deviceName); - } - - @Data - @NoArgsConstructor - @AllArgsConstructor - @ToString - public static class Device { - private String productKey; - private String deviceName; - } -} diff --git a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/server/WebSocketServerConfig.java b/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/server/WebSocketServerConfig.java deleted file mode 100644 index e0fa0aa8..00000000 --- a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/server/WebSocketServerConfig.java +++ /dev/null @@ -1,25 +0,0 @@ -package cc.iotkit.comp.websocket.server; - -import lombok.Data; - -import java.util.List; - -@Data -public class WebSocketServerConfig { - - private int port; - - private String sslKey; - - private String sslCert; - - private boolean ssl; - - private List accessTokens; - - @Data - public static class AccessToken{ - private String tokenName; - private String tokenStr; - } -} diff --git a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/server/WebSocketServerVerticle.java b/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/server/WebSocketServerVerticle.java deleted file mode 100644 index 718814a6..00000000 --- a/iot-components/iot-websocket-component/src/main/java/cc/iotkit/comp/websocket/server/WebSocketServerVerticle.java +++ /dev/null @@ -1,166 +0,0 @@ -package cc.iotkit.comp.websocket.server; - - -import cc.iotkit.common.enums.ErrCode; -import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.JsonUtils; -import cc.iotkit.comp.websocket.AbstractDeviceVerticle; -import cc.iotkit.converter.DeviceMessage; -import io.vertx.core.Future; -import io.vertx.core.http.HttpServer; -import io.vertx.core.http.HttpServerOptions; -import io.vertx.core.http.ServerWebSocket; -import io.vertx.core.net.PemKeyCertOptions; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - - -@Slf4j -public class WebSocketServerVerticle extends AbstractDeviceVerticle { - - - private HttpServer httpServer; - - private WebSocketServerConfig webSocketConfig; - - private final Map wsClients = new ConcurrentHashMap<>(); - - public WebSocketServerVerticle(String config) { - this.webSocketConfig = JsonUtils.parseObject(config, WebSocketServerConfig.class); - } - - private Map tokens=new HashMap<>(); - - @Override - public void start() throws Exception { - HttpServerOptions options = new HttpServerOptions() - .setPort(webSocketConfig.getPort()); - if (webSocketConfig.isSsl()) { - options = options.setSsl(true) - .setKeyCertOptions(new PemKeyCertOptions() - .setKeyPath(webSocketConfig.getSslKey()) - .setCertPath(webSocketConfig.getSslCert())); - } - httpServer = vertx.createHttpServer(options).webSocketHandler(wsClient -> { - log.info("webSocket client connect sessionId:{},path={}", wsClient.textHandlerID(), wsClient.path()); - String deviceKey = wsClient.path().replace("/",""); - if(StringUtils.isBlank(deviceKey)||deviceKey.split("_").length!=2){ - log.warn("陌生连接,拒绝"); - wsClient.reject(); - return; - } - wsClient.writeTextMessage("connect succes! please auth!"); - Map deviceKeyObj=new HashMap<>(); - deviceKeyObj.put("deviceKey",deviceKey); - wsClient.textMessageHandler(message -> { - HashMap msg= JsonUtils.parseObject(message,HashMap.class); - if(wsClients.containsKey(deviceKey)){ - if("ping".equals(msg.get("type"))){ - msg.put("type","pong"); - wsClient.writeTextMessage(JsonUtils.toJsonString(msg)); - return; - } - if("register".equals(msg.get("type"))){ - executor.onReceive(new HashMap<>(), "", message,(r) -> { - if (r == null) { - //注册失败 - Map ret=new HashMap<>(); - ret.put("id",msg.get("id")); - ret.put("type",msg.get("type")); - ret.put("result","fail"); - wsClient.writeTextMessage(JsonUtils.toJsonString(ret)); - return; - }else{ - msg.put("type","online"); - executor.onReceive(new HashMap<>(), "", JsonUtils.toJsonString(msg)); - } - }); - } - }else if(msg!=null&&"auth".equals(msg.get("type"))){ - Set tokenKey=tokens.keySet(); - for(String key:tokenKey){ - if(StringUtils.isNotBlank(msg.get(key))&&tokens.get(key).equals(msg.get(key))){ - //保存设备与连接关系 - log.info("认证通过"); - wsClients.put(deviceKey, wsClient); - wsClient.writeTextMessage("auth succes"); - return; - } - } - log.warn("认证失败,拒绝"); - wsClient.writeTextMessage("auth fail"); - return; - }else{ - log.warn("认证失败,拒绝"); - wsClient.writeTextMessage("auth fail"); - return; - } - - }); - wsClient.closeHandler(c -> { - log.warn("client connection closed,deviceKey:{}", deviceKey); - if(wsClients.containsKey(deviceKey)){ - wsClients.remove(deviceKey); - deviceKeyObj.put("type","offline"); - executor.onReceive(new HashMap<>(), "", JsonUtils.toJsonString(deviceKeyObj), (r) -> { - }); - } - }); - wsClient.exceptionHandler(ex -> { - log.warn("webSocket client connection exception,deviceKey:{}", deviceKey); - if(wsClients.containsKey(deviceKey)){ - wsClients.remove(deviceKey); - deviceKeyObj.put("type","offline"); - executor.onReceive(new HashMap<>(), "", JsonUtils.toJsonString(deviceKeyObj), (r) -> { - }); - } - }); - }).listen(webSocketConfig.getPort(), server -> { - if (server.succeeded()) { - log.info("webSocket server is listening on port " + webSocketConfig.getPort()); - List tokenConfig= webSocketConfig.getAccessTokens(); - for (WebSocketServerConfig.AccessToken obj:tokenConfig) { - tokens.put(obj.getTokenName(),obj.getTokenStr()); - } - } else { - log.error("webSocket server on starting the server", server.cause()); - } - }); - } - - @Override - public void stop() throws Exception { - for (String deviceKey : wsClients.keySet()) { - Map deviceKeyObj=new HashMap<>(); - deviceKeyObj.put("deviceKey",deviceKey); - deviceKeyObj.put("type","offline"); - executor.onReceive(null, "", JsonUtils.toJsonString(deviceKeyObj)); - } - tokens.clear(); - httpServer.close(voidAsyncResult -> log.info("close webocket server...")); - } - - private String getDeviceKey(String productKey, String deviceName) { - return String.format("%s_%s", productKey, deviceName); - } - - @Override - public DeviceMessage send(DeviceMessage message) { - ServerWebSocket wsClient = wsClients.get(message.getDeviceName()); - Object obj = message.getContent(); - if (!(obj instanceof Map)) { - throw new BizException(ErrCode.DATA_FORMAT_ERROR); - } - String msgStr = JsonUtils.toJsonString(obj); - log.info("send msg payload:{}", msgStr); - Future result = wsClient.writeTextMessage(msgStr); - result.onFailure(e -> log.error("webSocket server send msg failed", e)); - return message; - } -} diff --git a/iot-components/iot-websocket-component/src/main/resources/component.js b/iot-components/iot-websocket-component/src/main/resources/component.js deleted file mode 100644 index b63e09ff..00000000 --- a/iot-components/iot-websocket-component/src/main/resources/component.js +++ /dev/null @@ -1,72 +0,0 @@ -var mid=1; - -var access_token=""; - -function getMid(){ - mid++; - if(mid>10000){ - mid=1; - } - return mid; -}; -function getPingData(data){ - var ping={ - productKey:"", - deviceName:"", - content:{ - id:getMid(), - type:data - } - }; - return { - type:"action", - data:{ - productKey:"", - deviceName:"", - state:"" - }, - action:{ - type:"ack", - content:JSON.stringify(ping) - } - } -}; -//必须提供onReceive方法 -this.onReceive=function(head,type,payload){ - var data=JSON.parse(payload) - if(data.type=="auth_required"){ - var auth={ - productKey:"", - deviceName:"", - content:{ - type:"auth", - access_token:access_token - } - }; - return { - type:"action", - data:{ - productKey:"", - deviceName:"", - state:"" - }, - action:{ - type:"ack", - content:JSON.stringify(auth) - } - } - }else if(data.type=="auth_ok"){ - return getPingData(data.heartBeatData); - }else if(data.type=="pong"){ - apiTool.log("receive pong!"); - }else if("ping"==type){ - return getPingData(data.heartBeatData); - } - return { - productKey:"", - deviceName:"", - mid:0, - content:{ - } - } -}; \ No newline at end of file diff --git a/iot-components/iot-websocket-component/src/main/resources/component.spi b/iot-components/iot-websocket-component/src/main/resources/component.spi deleted file mode 100644 index aa6c2a0f..00000000 --- a/iot-components/iot-websocket-component/src/main/resources/component.spi +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.comp.websocket.WebSocketDeviceComponent \ No newline at end of file diff --git a/iot-components/iot-websocket-component/src/main/resources/converter.js b/iot-components/iot-websocket-component/src/main/resources/converter.js deleted file mode 100644 index 0dafe522..00000000 --- a/iot-components/iot-websocket-component/src/main/resources/converter.js +++ /dev/null @@ -1,55 +0,0 @@ - -var mid=1; - -function getMid(){ - mid++; - if(mid>10000){ - mid=1; - } - return mid+""; -} - -this.decode = function (msg) { - //对msg进行解析,并返回物模型数据 - var content=msg.content; - var type = content.type; - - if (type=="report") { - //属性上报 - return { - mid: msg.mid, - productKey: msg.productKey, - deviceName: msg.deviceName, - type:"property", - identifier: "report", //属性上报 - occur: new Date().getTime(), //时间戳,设备上的事件或数据产生的本地时间 - time: new Date().getTime(), //时间戳,消息上报时间 - data: content.params, - }; - } - return null; -}; - -this.encode = function (service,device) { - var type=service.type; - var identifier=service.identifier; - var entityId=service.deviceName; - var deviceMid=getMid(); - var params={}; - var target={}; - if("property"==type&&"set"==identifier){ - var domain=entityId.split(".")[0]; - var powerstate=service.params.powerstate==1?"turn_on":"turn_off"; - params.type="call_service"; - params.domain=domain; - params.service=powerstate; - target.entity_id=entityId; - params.target=target; - } - return { - productKey:service.productKey, - deviceName:service.deviceName, - mid:deviceMid, - content:params - } -}; \ No newline at end of file diff --git a/iot-components/iot-websocket-component/src/main/resources/server-component.js b/iot-components/iot-websocket-component/src/main/resources/server-component.js deleted file mode 100644 index b5edd2e0..00000000 --- a/iot-components/iot-websocket-component/src/main/resources/server-component.js +++ /dev/null @@ -1,114 +0,0 @@ -var mid=1; - -function getMid(){ - mid++; - if(mid>10000){ - mid=1; - } - return mid; -}; -function getPkDn(deviceKey){ - var arr=deviceKey.split("_"); - return { - pk:arr[1], - dn:deviceKey - }; -} -function register(data){ - var device=getPkDn(data.data.deviceName) - var subDevicesList=data.data.subDevices - var subDevices=[] - if(subDevicesList!=undefined&&subDevicesList.length>0){ - apiTool.log("device:"+subDevicesList); - for (var i = 0; i < subDevicesList.length; i++) { - var deviceKey=subDevicesList[i] - var subDevice=getPkDn(deviceKey) - subDevices.push({ - productKey:subDevice.pk, - deviceName:subDevice.dn, - model:'' - }) - } - } - - var reply= - { - productKey:device.pk, - deviceName:device.dn, - mid:"0", - content:{ - id:data.id, - type:data.type, - result:'success' - } - }; - var data={ - productKey:device.pk, - deviceName:device.dn - } - if(subDevices.length>0){ - data['subDevices']=subDevices - } - apiTool.log("subDevices:"+JSON.stringify(data)); - return { - type:"register", - data:{ - productKey:device.pk, - deviceName:device.dn, - subDevices:subDevices - }, - action:{ - type:"ack", - content:JSON.stringify(reply) - } - }; -} - -function online(data){ - apiTool.log("data:"+JSON.stringify(data)); - var device=getPkDn(data.data.deviceName) - return { - type:"state", - data:{ - productKey:device.pk, - deviceName:device.dn, - state:data.type - } - }; -} - -function offline(data){ - var device=getPkDn(data.deviceKey) - return { - type:"state", - data:{ - productKey:device.pk, - deviceName:device.dn, - state:data.type - } - }; -} - -//必须提供onReceive方法 -this.onReceive=function(head,type,payload){ - var data=JSON.parse(payload) - if(data.type=="register"){ - apiTool.log("data:"+payload); - return register(data) - }else if(data.type=="online"){ - return online(data); - }else if(data.type=="offline"){ - return offline(data); - } - return { - productKey:"", - deviceName:"", - mid:0, - content:{ - } - } -}; - -this.onRegistered=function (data,status) { - apiTool.log("onRegistered调用"); -} \ No newline at end of file diff --git a/iot-components/pom.xml b/iot-components/pom.xml deleted file mode 100755 index 98b89642..00000000 --- a/iot-components/pom.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - iotkit-parent - cc.iotkit - 0.5.0-SNAPSHOT - - 4.0.0 - - iot-components - pom - - iot-component-server - iot-component-converter - iot-mqtt-component - iot-emqx-component - iot-component-base - iot-http-biz-component - iot-component-tcp - iot-DLT645-component - iot-websocket-component - iot-nb-component - - - - \ No newline at end of file diff --git a/iot-components/readme.txt b/iot-components/readme.txt deleted file mode 100755 index 12b6291c..00000000 --- a/iot-components/readme.txt +++ /dev/null @@ -1 +0,0 @@ -此模块为通讯组件模块,存放通讯组件接口、组件服务端和各通讯组件模块(如mqtt通讯组件) diff --git a/iot-common/iot-common-dao/iot-common-model/pom.xml b/iot-dao/iot-data-model/pom.xml similarity index 93% rename from iot-common/iot-common-dao/iot-common-model/pom.xml rename to iot-dao/iot-data-model/pom.xml index 3869c520..eba07622 100644 --- a/iot-common/iot-common-dao/iot-common-model/pom.xml +++ b/iot-dao/iot-data-model/pom.xml @@ -3,14 +3,14 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - iot-common-dao + iot-dao cc.iotkit 0.5.0-SNAPSHOT 0.5.0-SNAPSHOT 4.0.0 - iot-common-model + iot-data-model diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/BaseModel.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/BaseModel.java similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/BaseModel.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/BaseModel.java diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/Id.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/Id.java similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/Id.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/Id.java diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/InvokeResult.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/InvokeResult.java similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/InvokeResult.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/InvokeResult.java diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/OauthClient.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/OauthClient.java similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/OauthClient.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/OauthClient.java diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/Owned.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/Owned.java similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/Owned.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/Owned.java diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/TenantModel.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/TenantModel.java similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/TenantModel.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/TenantModel.java diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/UserInfo.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/UserInfo.java similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/UserInfo.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/UserInfo.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/alert/AlertConfig.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertConfig.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/alert/AlertRecord.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/alert/AlertRecord.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/device/DeviceConfig.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceConfig.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/device/DeviceGroup.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceGroup.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/device/DeviceInfo.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/DeviceInfo.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/device/VirtualDevice.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/VirtualDevice.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/device/VirtualDeviceLog.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/VirtualDeviceLog.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/device/message/DeviceProperty.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/message/DeviceProperty.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/device/message/DevicePropertyCache.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/message/DevicePropertyCache.java diff --git a/iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/device/message/ThingModelMessage.java b/iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/message/ThingModelMessage.java similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/device/message/ThingModelMessage.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/device/message/ThingModelMessage.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/notify/Channel.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/Channel.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/notify/ChannelConfig.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/ChannelConfig.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/notify/ChannelTemplate.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/ChannelTemplate.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/notify/NotifyMessage.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/notify/NotifyMessage.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/DeviceOta.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOta.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/DeviceOtaDetail.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOtaDetail.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/DeviceOtaInfo.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/DeviceOtaInfo.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaDevice.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaDevice.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaInfo.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaInfo.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/ota/OtaPackage.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/ota/OtaPackage.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/plugin/PluginInfo.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/plugin/PluginInfo.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/plugin/PluginInstance.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/plugin/PluginInstance.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/product/AppDesign.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/AppDesign.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/product/Category.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/Category.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/product/Product.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/Product.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/product/ProductModel.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/ProductModel.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/product/ThingModel.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/product/ThingModel.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/rule/FilterConfig.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/FilterConfig.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/rule/RuleAction.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleAction.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/rule/RuleInfo.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleInfo.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/rule/RuleLog.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/RuleLog.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/rule/TaskInfo.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/TaskInfo.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/rule/TaskLog.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/rule/TaskLog.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/screen/Screen.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/screen/Screen.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/screen/ScreenApi.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/screen/ScreenApi.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/space/Home.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/Home.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/space/Space.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/Space.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/space/SpaceDevice.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/space/SpaceDevice.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/stats/DataItem.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/DataItem.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/stats/TimeData.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/stats/TimeData.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysApp.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysApp.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysConfig.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysConfig.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysDept.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDept.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysDictData.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDictData.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysDictType.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysDictType.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysLoginInfo.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysLoginInfo.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysMenu.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysMenu.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysNotice.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysNotice.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysOperLog.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOperLog.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysOss.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOss.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysOssConfig.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysOssConfig.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysPost.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysPost.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysRole.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRole.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysRoleDept.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRoleDept.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysRoleMenu.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysRoleMenu.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysTenant.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysTenant.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysTenantPackage.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysTenantPackage.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysUser.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUser.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysUserPost.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUserPost.java diff --git a/iot-common/iot-common-dao/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-common-model/src/main/java/cc/iotkit/model/system/SysUserRole.java rename to iot-dao/iot-data-model/src/main/java/cc/iotkit/model/system/SysUserRole.java diff --git a/iot-common/iot-common-dao/iot-data-service/pom.xml b/iot-dao/iot-data-service/pom.xml similarity index 90% rename from iot-common/iot-common-dao/iot-data-service/pom.xml rename to iot-dao/iot-data-service/pom.xml index 4dcb9332..a48c2b8c 100644 --- a/iot-common/iot-common-dao/iot-data-service/pom.xml +++ b/iot-dao/iot-data-service/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - iot-common-dao + iot-dao cc.iotkit 0.5.0-SNAPSHOT @@ -15,7 +15,7 @@ cc.iotkit - iot-common-model + iot-data-model diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/ICommonData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/ICommonData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/IOwnedData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/IOwnedData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertConfigData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertConfigData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertRecordData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IAlertRecordData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ICategoryData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ICategoryData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelConfigData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelConfigData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelTemplateData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IChannelTemplateData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceConfigData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceConfigData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceGroupData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceGroupData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceInfoData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceInfoData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaDetailData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaDetailData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaInfoData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IDeviceOtaInfoData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IHomeData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IHomeData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/INotifyMessageData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/INotifyMessageData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOauthClientData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOauthClientData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaDeviceData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaDeviceData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaPackageData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IOtaPackageData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IPluginInfoData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IPluginInfoData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IPluginInstanceData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IPluginInstanceData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProductData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProductData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProductModelData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IProductModelData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IRuleInfoData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IRuleInfoData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IScreenApiData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IScreenApiData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IScreenData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IScreenData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ISpaceData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ISpaceData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ISpaceDeviceData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ISpaceDeviceData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ITaskInfoData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/ITaskInfoData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IThingModelData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IThingModelData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IUserInfoData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IUserInfoData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IVirtualDeviceData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/manager/IVirtualDeviceData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysAppData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysAppData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysConfigData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysConfigData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDeptData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDeptData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDictData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDictData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDictTypeData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDictTypeData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysLogininforData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysLogininforData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysMenuData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysMenuData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysNoticeData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysNoticeData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOperLogData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOperLogData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOssConfigData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOssConfigData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOssData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysOssData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysPostData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysPostData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleDeptData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleDeptData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleMenuData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysRoleMenuData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantPackageData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantPackageData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserPostData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserPostData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserRoleData.java rename to iot-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserRoleData.java diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-cache/pom.xml b/iot-dao/iot-data-serviceImpl-cache/pom.xml similarity index 94% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/pom.xml rename to iot-dao/iot-data-serviceImpl-cache/pom.xml index 43b2958e..79161757 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-cache/pom.xml +++ b/iot-dao/iot-data-serviceImpl-cache/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - iot-common-dao + iot-dao cc.iotkit 0.5.0-SNAPSHOT @@ -25,7 +25,7 @@ cc.iotkit - iot-common-model + iot-data-model diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/CategoryCacheEvict.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/CategoryCacheEvict.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCacheEvict.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCacheEvict.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCachePut.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/DeviceInfoCachePut.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/OauthClientCacheEvict.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/OauthClientCacheEvict.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ProductCacheEvict.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ProductCacheEvict.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ProductModelCacheEvict.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ProductModelCacheEvict.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/SpaceCacheEvict.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/SpaceCacheEvict.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ThingModelCacheEvict.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/ThingModelCacheEvict.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/UserInfoCacheEvict.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/cache/UserInfoCacheEvict.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/config/CacheConfig.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/config/CacheConfig.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/CategoryDataCache.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/CategoryDataCache.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoDataCache.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoPropertyDataCache.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/DeviceInfoPropertyDataCache.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/OauthClientDataCache.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/OauthClientDataCache.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ProductDataCache.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ProductDataCache.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ProductModelDataCache.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ProductModelDataCache.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/SpaceDataCache.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/SpaceDataCache.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ThingModelDataCache.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/ThingModelDataCache.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/UserInfoDataCache.java rename to iot-dao/iot-data-serviceImpl-cache/src/main/java/cc/iotkit/data/service/UserInfoDataCache.java diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/pom.xml b/iot-dao/iot-data-serviceImpl-rdb/pom.xml similarity index 95% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/pom.xml rename to iot-dao/iot-data-serviceImpl-rdb/pom.xml index 9dbbe0e1..4dbf0b2c 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/pom.xml +++ b/iot-dao/iot-data-serviceImpl-rdb/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - iot-common-dao + iot-dao cc.iotkit 0.5.0-SNAPSHOT @@ -64,11 +64,6 @@ - - commons-io - commons-io - - cn.hutool hutool-core @@ -79,22 +74,27 @@ mapstruct-plus-spring-boot-starter + + org.springframework.data + spring-data-commons + + + + javax.validation + validation-api + + + + io.swagger + swagger-annotations + + org.projectlombok lombok provided - - com.github.biyanwen - jpa-comment-spring-boot-starter - - - - org.springframework.data - spring-data-commons - - diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/AutoMapperConfig3.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/AutoMapperConfig3.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JdbcTemplateConfig.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JdbcTemplateConfig.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JpaConfig.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/JpaConfig.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertConfigRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertConfigRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertRecordRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/AlertRecordRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/CategoryRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/CategoryRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelConfigRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelConfigRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelTemplateRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ChannelTemplateRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceConfigRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceConfigRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceGroupMappingRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceGroupMappingRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceGroupRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceGroupRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceInfoRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceInfoRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaDetailRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaDetailRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaInfoRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceOtaInfoRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceSubUserRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceSubUserRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceTagRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/DeviceTagRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/HomeRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/HomeRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IJPACommData.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IJPACommData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaDeviceRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaDeviceRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaPackageRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IOtaPackageRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/NotifyMessageRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/NotifyMessageRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/OauthClientRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/OauthClientRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/PluginInfoRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/PluginInfoRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/PluginInstanceRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/PluginInstanceRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProductModelRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProductModelRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProductRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ProductRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/RuleInfoRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/RuleInfoRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ScreenApiRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ScreenApiRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ScreenRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ScreenRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SpaceDeviceRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SpaceDeviceRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SpaceRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SpaceRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysAppRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysAppRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysConfigRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysConfigRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDeptRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDeptRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDictDataRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDictDataRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDictTypeRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysDictTypeRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysLogininforRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysLogininforRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysMenuRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysMenuRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysNoticRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysNoticRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOperLogRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOperLogRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOssConfigRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOssConfigRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOssRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysOssRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysPostRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysPostRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleDeptRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleDeptRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleMenuRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleMenuRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysRoleRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysTenantPackageRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysTenantPackageRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysTenantRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysTenantRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserPostRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserPostRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRoleRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRoleRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/TaskInfoRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/TaskInfoRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ThingModelRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/ThingModelRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/UserInfoRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/UserInfoRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/VirtualDeviceMappingRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/VirtualDeviceMappingRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/VirtualDeviceRepository.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/VirtualDeviceRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/BaseEntity.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/BaseEntity.java diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/ChannelConfigMapper.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/ChannelConfigMapper.java similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/ChannelConfigMapper.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/ChannelConfigMapper.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/DeviceIdGroup.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/DeviceIdGroup.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertConfig.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertConfig.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertRecord.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbAlertRecord.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbCategory.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbCategory.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannel.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannel.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannelConfig.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannelConfig.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannelTemplate.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbChannelTemplate.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceConfig.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceConfig.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceGroup.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceGroup.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceGroupMapping.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceGroupMapping.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceInfo.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaDetail.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaDetail.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaInfo.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceOtaInfo.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceSubUser.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceSubUser.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceTag.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbDeviceTag.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbHome.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbHome.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbNotifyMessage.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbNotifyMessage.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOauthClient.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOauthClient.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaDevice.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaDevice.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaPackage.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbOtaPackage.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbPluginInfo.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbPluginInfo.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbPluginInstance.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbPluginInstance.java diff --git a/iot-common/iot-common-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 similarity index 98% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProduct.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProduct.java index e0d77bf8..26dce687 100644 --- a/iot-common/iot-common-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 @@ -15,6 +15,7 @@ import cc.iotkit.model.product.Product; import io.github.linpeilie.annotations.AutoMapper; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import jakarta.validation.constraints.Size; import lombok.Data; import org.hibernate.annotations.Filter; import org.hibernate.annotations.FilterDef; @@ -22,7 +23,6 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.ParamDef; import javax.persistence.*; -import javax.validation.constraints.Size; @Data @Entity diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProductModel.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbProductModel.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbRuleInfo.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbRuleInfo.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbScreen.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbScreen.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbScreenApi.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbScreenApi.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSpace.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSpace.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSpaceDevice.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSpaceDevice.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysApp.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysApp.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysConfig.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysConfig.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDept.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDept.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDictData.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDictData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDictType.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDictType.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysLogininfor.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysLogininfor.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysMenu.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysMenu.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysNotice.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysNotice.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOperLog.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOperLog.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOss.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOss.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOssConfig.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysOssConfig.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysPost.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysPost.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRole.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRole.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleDept.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleDept.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleMenu.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleMenu.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysTenant.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysTenant.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysTenantPackage.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysTenantPackage.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUser.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUser.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserPost.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserPost.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserRole.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserRole.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbTaskInfo.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbTaskInfo.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbThingModel.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbThingModel.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbUserInfo.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbVirtualDevice.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbVirtualDevice.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbVirtualDeviceMapping.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbVirtualDeviceMapping.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertConfigDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertConfigDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertRecordDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/AlertRecordDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/CategoryDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/CategoryDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelConfigDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelConfigDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelTemplateDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ChannelTemplateDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceConfigDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceConfigDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceGroupDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceGroupDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceInfoDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaDetailDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaDetailDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaInfoDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/DeviceOtaInfoDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/HomeDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/HomeDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaDeviceDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaDeviceDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaPackageDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/IOtaPackageDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/NotifyMessageDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/NotifyMessageDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/OauthClientDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/OauthClientDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/PluginInfoDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/PluginInfoDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/PluginInstanceDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/PluginInstanceDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProductDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProductDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProductModelDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ProductModelDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/RuleInfoDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/RuleInfoDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ScreenApiDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ScreenApiDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ScreenDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ScreenDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SpaceDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SpaceDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SpaceDeviceDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SpaceDeviceDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysAppDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysAppDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDictDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDictDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDictTypeDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDictTypeDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysLogininfoDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysLogininfoDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysNoticeDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysNoticeDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOperLogDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOperLogDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOssConfigDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOssConfigDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOssDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysOssDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysPostDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysPostDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDeptDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDeptDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleMenuDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleMenuDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantPackageDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantPackageDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserPostDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserPostDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserRoleDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserRoleDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/TaskInfoDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/TaskInfoDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ThingModelDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/ThingModelDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/UserInfoDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/UserInfoDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/VirtualDeviceDataImpl.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/VirtualDeviceDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/util/PageBuilder.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/util/PageBuilder.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/util/PredicateBuilder.java rename to iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/util/PredicateBuilder.java diff --git a/iot-common/iot-common-dao/iot-temporal-service/pom.xml b/iot-dao/iot-temporal-service/pom.xml similarity index 90% rename from iot-common/iot-common-dao/iot-temporal-service/pom.xml rename to iot-dao/iot-temporal-service/pom.xml index 777999d9..2a3c5827 100644 --- a/iot-common/iot-common-dao/iot-temporal-service/pom.xml +++ b/iot-dao/iot-temporal-service/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - iot-common-dao + iot-dao cc.iotkit 0.5.0-SNAPSHOT @@ -15,7 +15,7 @@ cc.iotkit - iot-common-model + iot-data-model diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IDbStructureData.java rename to iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IDbStructureData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IDevicePropertyData.java rename to iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IDevicePropertyData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IRuleLogData.java rename to iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IRuleLogData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/ITaskLogData.java rename to iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/ITaskLogData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IThingModelMessageData.java rename to iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IThingModelMessageData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IVirtualDeviceLogData.java rename to iot-dao/iot-temporal-service/src/main/java/cc/iotkit/temporal/IVirtualDeviceLogData.java diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/pom.xml b/iot-dao/iot-temporal-serviceImpl-es/pom.xml similarity index 98% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/pom.xml rename to iot-dao/iot-temporal-serviceImpl-es/pom.xml index 9f5d0b3b..6ffbc52c 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-es/pom.xml +++ b/iot-dao/iot-temporal-serviceImpl-es/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - iot-common-dao + iot-dao cc.iotkit 0.5.0-SNAPSHOT diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/config/ElasticsearchConfiguration.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/config/ElasticsearchConfiguration.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/RuleLogRepository.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/RuleLogRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/TaskLogRepository.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/TaskLogRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/ThingModelMessageRepository.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/ThingModelMessageRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/VirtualDeviceLogRepository.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/dao/VirtualDeviceLogRepository.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocDeviceProperty.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocDeviceProperty.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocRuleLog.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocRuleLog.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocTaskLog.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocTaskLog.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocThingModelMessage.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocThingModelMessage.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocVirtualDeviceLog.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/document/DocVirtualDeviceLog.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DbStructureDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DbStructureDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DevicePropertyDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/DevicePropertyDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/RuleLogDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/TaskLogDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/ThingModelMessageDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/VirtualDeviceLogDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-es/src/main/java/cc/iotkit/temporal/es/service/VirtualDeviceLogDataImpl.java diff --git a/iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/pom.xml b/iot-dao/iot-temporal-serviceImpl-ts/pom.xml similarity index 95% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/pom.xml rename to iot-dao/iot-temporal-serviceImpl-ts/pom.xml index 124ecbc8..9024b0dd 100644 --- a/iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/pom.xml +++ b/iot-dao/iot-temporal-serviceImpl-ts/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - iot-common-dao + iot-dao cc.iotkit 0.5.0-SNAPSHOT @@ -30,12 +30,12 @@ cc.iotkit - iot-common-model + iot-data-model cc.iotkit - iot-common-model + iot-data-model diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/config/Constants.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/config/Constants.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/config/TsDatasourceConfig.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/config/TsDatasourceConfig.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dao/TsTemplate.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dao/TsTemplate.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/DbField.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/DbField.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/FieldParser.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/FieldParser.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/TableManager.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/TableManager.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/TsField.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/dm/TsField.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsDeviceProperty.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsDeviceProperty.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsRuleLog.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsRuleLog.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsTaskLog.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsTaskLog.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsThingModelMessage.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsThingModelMessage.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsTimeData.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsTimeData.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsVirtualDeviceLog.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/model/TsVirtualDeviceLog.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/DbStructureDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/DbStructureDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/DevicePropertyDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/DevicePropertyDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/RuleLogDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/RuleLogDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/TaskLogDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/TaskLogDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/ThingModelMessageDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/ThingModelMessageDataImpl.java diff --git a/iot-common/iot-common-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 similarity index 100% rename from iot-common/iot-common-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/VirtualDeviceLogDataImpl.java rename to iot-dao/iot-temporal-serviceImpl-ts/src/main/java/cc/iotkit/temporal/ts/service/VirtualDeviceLogDataImpl.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/pom.xml b/iot-dao/iot-temproal-serviceImpl-td/pom.xml similarity index 97% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/pom.xml rename to iot-dao/iot-temproal-serviceImpl-td/pom.xml index 1f3d8bbf..6562a5ab 100644 --- a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/pom.xml +++ b/iot-dao/iot-temproal-serviceImpl-td/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - iot-common-dao + iot-dao cc.iotkit 0.5.0-SNAPSHOT diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/Constants.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/Constants.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/Constants.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/Constants.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/TdDatasourceConfig.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/TdDatasourceConfig.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/TdDatasourceConfig.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/config/TdDatasourceConfig.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dao/TdTemplate.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dao/TdTemplate.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dao/TdTemplate.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dao/TdTemplate.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/FieldParser.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/FieldParser.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/FieldParser.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/FieldParser.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TableManager.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TableManager.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TableManager.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TableManager.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdField.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdField.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdField.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdField.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdResponse.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdResponse.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdResponse.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdResponse.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdRestApi.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdRestApi.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdRestApi.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/dm/TdRestApi.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbDeviceProperty.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbDeviceProperty.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbDeviceProperty.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbDeviceProperty.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbRuleLog.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbRuleLog.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbRuleLog.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbRuleLog.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbTaskLog.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbTaskLog.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbTaskLog.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbTaskLog.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbThingModelMessage.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbThingModelMessage.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbThingModelMessage.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbThingModelMessage.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbVirtualDeviceLog.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbVirtualDeviceLog.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbVirtualDeviceLog.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/model/TbVirtualDeviceLog.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DbStructureDataImpl.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DbStructureDataImpl.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DbStructureDataImpl.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DbStructureDataImpl.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DevicePropertyDataImpl.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DevicePropertyDataImpl.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DevicePropertyDataImpl.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/DevicePropertyDataImpl.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/RuleLogDataImpl.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/RuleLogDataImpl.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/RuleLogDataImpl.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/RuleLogDataImpl.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/TaskLogDataImpl.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/TaskLogDataImpl.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/TaskLogDataImpl.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/TaskLogDataImpl.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/ThingModelMessageDataImpl.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/ThingModelMessageDataImpl.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/ThingModelMessageDataImpl.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/ThingModelMessageDataImpl.java diff --git a/iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/VirtualDeviceLogDataImpl.java b/iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/VirtualDeviceLogDataImpl.java similarity index 100% rename from iot-common/iot-common-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/VirtualDeviceLogDataImpl.java rename to iot-dao/iot-temproal-serviceImpl-td/src/main/java/cc/iotkit/temporal/td/service/VirtualDeviceLogDataImpl.java diff --git a/iot-common/iot-common-dao/pom.xml b/iot-dao/pom.xml similarity index 80% rename from iot-common/iot-common-dao/pom.xml rename to iot-dao/pom.xml index dee5ba44..f72b71b9 100644 --- a/iot-common/iot-common-dao/pom.xml +++ b/iot-dao/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - iot-common + iotkit-parent cc.iotkit 0.5.0-SNAPSHOT @@ -16,7 +16,7 @@ - iot-common-model + iot-data-model iot-data-service iot-data-serviceImpl-cache iot-data-serviceImpl-rdb @@ -25,14 +25,6 @@ iot-temproal-serviceImpl-td - iot-common-dao - - - - - - - - + iot-dao \ No newline at end of file diff --git a/iot-module/iot-baetyl/pom.xml b/iot-module/iot-baetyl/pom.xml deleted file mode 100644 index bc190ea7..00000000 --- a/iot-module/iot-baetyl/pom.xml +++ /dev/null @@ -1,121 +0,0 @@ - - - 4.0.0 - - iot-module - cc.iotkit - 0.5.0-SNAPSHOT - - - iot-baetyl - - - 此模块为边缘计算模块云端控制SDK - - - - - - cc.iotkit - iot-common-model - - - - cc.iotkit - iot-common-core - - - - 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-log - - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - - org.springframework.boot - spring-boot-starter-webflux - - - - joda-time - joda-time - - - - 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-baetyl/src/main/java/cc/iotkit/baetyl/IBaetylService.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/IBaetylService.java deleted file mode 100644 index 1effb46f..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/IBaetylService.java +++ /dev/null @@ -1,34 +0,0 @@ -package cc.iotkit.baetyl; - -import cc.iotkit.baetyl.dto.bo.*; -import cc.iotkit.baetyl.dto.vo.*; - -public interface IBaetylService { - GetNodeAppsByNameVo getNodeAppsByName(String name); - - UpdateCoreConfigByNameVo updateCoreConfigByName(UpdateCoreConfigByNameBo data); - - CreateNodeVo creatNode(CreateNodeBo data); - - Boolean deleteNodeByName(String data); - - GetNodesBatchVo getNodesBatch(String[] data); - - UpdateNodePropertiesVo updateNodeProperties(UpdateNodePropertiesBo data); - - GetNodeByNameVo getNodeByName(String data); - - UpdateNodeVo updateNode(UpdateNodeBo data); - - GetNodeStatsVo getNodeStats(String data); - - GetNodeCoreVersionVo getNodeCoreVersion(String data); - - GetNodesVo getNodes(GetNodesBo data); - - GetCoreConfigVo getCoreConfig(String data); - - String getInstallCommand(GetInstallCommandBo data); - - GetNodePropertiesVo getNodeProperties(String data); -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/config/BaetylProperties.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/config/BaetylProperties.java deleted file mode 100644 index 30b4cebd..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/config/BaetylProperties.java +++ /dev/null @@ -1,20 +0,0 @@ -package cc.iotkit.baetyl.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Data -@Configuration -@ConfigurationProperties(prefix = "baetyl") -public class BaetylProperties { - - /** - * 自定义baetyl服务地址 - */ - private String serviceUrl; - /** - * api请求封装类型 feign webclient - */ - private String apiType; -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/constant/BaetylConstant.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/constant/BaetylConstant.java deleted file mode 100644 index 879b6773..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/constant/BaetylConstant.java +++ /dev/null @@ -1,82 +0,0 @@ -package cc.iotkit.baetyl.constant; - -/*** - * 接口文档地址-https://baetyl.io/docs/cn/latest/_static/api.html - */ -public class BaetylConstant { - - - public class Url { - - /** - * 节点管理 - */ - public class NodeManagement { - /** - * 查询节点关联的应用 GET - */ - public static final String GetNodeAppsByName = "/v1/nodes/{name}/apps"; - /** - * 修改 core 配置(core 自升级) PUT - */ - public static final String UpdateCoreConfigByName = "/v1/nodes/{name}/core/configs"; - /** - * 创建节点 POST - */ - public static final String CreatNode = "/v1/nodes"; - /** - * 删除节点 DELETE - */ - public static final String DeleteNodeByName = "/v1/nodes/{name}"; - /** - * 批量查询节点 PUT - */ - public static final String GetNodesBatch = "/v1/nodes?batch"; - /** - * 更新节点属性 PUT - */ - public static final String UpdateNodeProperties = "/v1/nodes/{name}/properties"; - /** - * 查询节点 GET - */ - public static final String GetNodeByName = "/v1/nodes/{name}"; - /** - * 修改节点 PUT - */ - public static final String UpdateNode = "/v1/nodes/{name}"; - /** - * 查询节点状态信息 GET - */ - public static final String GetNodeStats = "/v1/nodes/{name}/stats"; - /** - * 罗列当前节点 core 版本号 GET - */ - public static final String GetNodeCoreVersion = "/v1/nodes/{name}/core/versions"; - /** - * 罗列节点 GET - */ - public static final String GetNodes = "/v1/nodes"; - /** - * 获取 core 配置 GET - */ - public static final String GetCoreConfig = "/v1/nodes/{name}/core/configs"; - /** - * 获取安装命令 GET - */ - public static final String GetInstallCommand = "/v1/nodes/:name/init"; - /** - * 获取节点属性 GET - */ - public static final String GetNodeProperties = "/v1/nodes/{name}/properties"; - - } - - - - - - } - - - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/controller/BartylNodeController.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/controller/BartylNodeController.java deleted file mode 100644 index 322a8bc0..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/controller/BartylNodeController.java +++ /dev/null @@ -1,118 +0,0 @@ -package cc.iotkit.baetyl.controller; - -import cc.iotkit.baetyl.IBaetylService; -import cc.iotkit.baetyl.dto.bo.*; -import cc.iotkit.baetyl.dto.vo.*; -import cc.iotkit.common.api.Request; -import cc.iotkit.common.web.core.BaseController; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -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; - -/** - * baetyl接口 - * - * @author longjun.tu - */ -@Validated -@RequiredArgsConstructor -@RestController -@RequestMapping("/baetyl/node") -@Api(tags = "边缘计算节点管理") -public class BartylNodeController extends BaseController { - - @Autowired - private IBaetylService configService; - - @ApiOperation("查询节点关联的应用") - @PostMapping("/getNodeAppsByName") - public GetNodeAppsByNameVo getNodeAppsByName(@Validated @RequestBody Request request) { - return configService.getNodeAppsByName(request.getData()); - } - - @ApiOperation("修改 core 配置(core 自升级)") - @PostMapping("/updateCoreConfigByName") - public UpdateCoreConfigByNameVo updateCoreConfigByName(@Validated @RequestBody Request request) { - return configService.updateCoreConfigByName(request.getData()); - } - - @ApiOperation("创建节点") - @PostMapping("/creatNode") - public CreateNodeVo creatNode(@Validated @RequestBody Request request) { - return configService.creatNode(request.getData()); - } - - @ApiOperation("删除节点") - @PostMapping("/deleteNodeByName") - public Boolean deleteNodeByName(@Validated @RequestBody Request request) { - return configService.deleteNodeByName(request.getData()); - } - - @ApiOperation("批量查询节点") - @PostMapping("/getNodesBatch") - public GetNodesBatchVo getNodesBatch(@Validated @RequestBody Request request) { - return configService.getNodesBatch(request.getData()); - } - - @ApiOperation("更新节点属性") - @PostMapping("/updateNodeProperties") - public UpdateNodePropertiesVo updateNodeProperties(@Validated @RequestBody Request request) { - return configService.updateNodeProperties(request.getData()); - } - - @ApiOperation("查询节点") - @PostMapping("/getNodeByName") - public GetNodeByNameVo getNodeByName(@Validated @RequestBody Request request) { - return configService.getNodeByName(request.getData()); - } - - @ApiOperation("修改节点") - @PostMapping("/updateNode") - public UpdateNodeVo updateNode(@Validated @RequestBody Request request) { - return configService.updateNode(request.getData()); - } - - @ApiOperation("查询节点状态信息") - @PostMapping("/getNodeStats") - public GetNodeStatsVo getNodeStats(@Validated @RequestBody Request request) { - return configService.getNodeStats(request.getData()); - } - - @ApiOperation("罗列当前节点 core 版本号") - @PostMapping("/getNodeCoreVersion") - public GetNodeCoreVersionVo getNodeCoreVersion(@Validated @RequestBody Request request) { - return configService.getNodeCoreVersion(request.getData()); - } - - @ApiOperation("罗列节点") - @PostMapping("/getNodes") - public GetNodesVo getNodes(@Validated @RequestBody Request request) { - return configService.getNodes(request.getData()); - } - - @ApiOperation("获取 core 配置") - @PostMapping("/getCoreConfig") - public GetCoreConfigVo getCoreConfig(@Validated @RequestBody Request request) { - return configService.getCoreConfig(request.getData()); - } - - @ApiOperation("获取安装命令") - @PostMapping("/getInstallCommand") - public String getInstallCommand(@Validated @RequestBody Request request) { - return configService.getInstallCommand(request.getData()); - } - - @ApiOperation("获取节点属性") - @PostMapping("/getNodeProperties") - public GetNodePropertiesVo getNodeProperties(@Validated @RequestBody Request request) { - return configService.getNodeProperties(request.getData()); - } - - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/CreateNodeBo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/CreateNodeBo.java deleted file mode 100644 index ab112cf7..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/CreateNodeBo.java +++ /dev/null @@ -1,36 +0,0 @@ -package cc.iotkit.baetyl.dto.bo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.Map; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/8 16:36 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class CreateNodeBo { - - @ApiModelProperty(value = "节点名称",required = true) - private String name; - @ApiModelProperty(value = "map[string]string类型,例如 {\"env\":\"test\"}") - private Map labels; - @ApiModelProperty(value = "map[string]string 用来保存品牌等属性信息") - private Map annotations; - @ApiModelProperty(value = "为空或NVIDIA GPU") - private String accelerator; - @ApiModelProperty(value = "是单机还是集群环境") - private Boolean cluster; - @ApiModelProperty(value = "可选官方应用,支持 baetyl-function、baetyl-rule") - private String[] sysApps; - @ApiModelProperty(value = "描述信息") - private String description; - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/GetInstallCommandBo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/GetInstallCommandBo.java deleted file mode 100644 index 447a21a9..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/GetInstallCommandBo.java +++ /dev/null @@ -1,26 +0,0 @@ -package cc.iotkit.baetyl.dto.bo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/18 16:22 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class GetInstallCommandBo { - - @ApiModelProperty(value = "节点名称") - private String name; - - @ApiModelProperty(value = "缺省或kube为kube安装命令") - private String mode; - - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/GetNodesBo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/GetNodesBo.java deleted file mode 100644 index f59db4f6..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/GetNodesBo.java +++ /dev/null @@ -1,34 +0,0 @@ -package cc.iotkit.baetyl.dto.bo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/11 18:49 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class GetNodesBo { - @ApiModelProperty(value = "标签查询") - private String selector; - @ApiModelProperty(value = "属性查询") - private String fieldSelector; - @ApiModelProperty(value = "分页限制") - private Integer limit; - @ApiModelProperty(value = "分页继续token,由上一次分页查询返回") - private String isContinue; - @ApiModelProperty(value = "查询页码") - private Integer pageNo; - @ApiModelProperty(value = "每页数据数") - private Integer pageSize; - @ApiModelProperty(value = "模糊匹配名称") - private String name; - @ApiModelProperty(value = "子节点标签过滤") - private String nodeSelector; -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateCoreConfigByNameBo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateCoreConfigByNameBo.java deleted file mode 100644 index 186729ee..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateCoreConfigByNameBo.java +++ /dev/null @@ -1,41 +0,0 @@ -package cc.iotkit.baetyl.dto.bo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/11 18:03 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class UpdateCoreConfigByNameBo { - - @ApiModelProperty(value = "节点名称",required = true) - private String name; - - @ApiModelProperty(value = "body内容") - private UpdateCoreConfigByNameBoBody body; - - @Data - @AllArgsConstructor - @NoArgsConstructor - public static class UpdateCoreConfigByNameBoBody { - @ApiModelProperty(value = "core版本号") - private String version; - - @ApiModelProperty(value = "core上报频率") - private Integer frequency; - - @ApiModelProperty(value = "core 边缘 API 端口") - private Integer apiport; - } - - - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodeBo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodeBo.java deleted file mode 100644 index 53832803..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodeBo.java +++ /dev/null @@ -1,43 +0,0 @@ -package cc.iotkit.baetyl.dto.bo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.Map; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/11 18:35 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class UpdateNodeBo { - - @ApiModelProperty(value = "节点名称",required = true) - private String name; - - @ApiModelProperty(value = "body内容",required = true) - private UpdateNodeBoBody body; - - @Data - @AllArgsConstructor - @NoArgsConstructor - public static class UpdateNodeBoBody { - @ApiModelProperty(value = "map[string]string类型,例如 {\"env\":\"test\"}") - private Map labels; - @ApiModelProperty(value = "map[string]string 用来保存品牌等属性信息") - private Map annotations; - @ApiModelProperty(value = "描述信息") - private String description; - @ApiModelProperty(value = "可选官方应用,支持 baetyl-function、baetyl-rule") - private String[] sysApps; - - - } - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodePropertiesBo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodePropertiesBo.java deleted file mode 100644 index e0a9b4fa..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodePropertiesBo.java +++ /dev/null @@ -1,33 +0,0 @@ -package cc.iotkit.baetyl.dto.bo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/11 17:58 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class UpdateNodePropertiesBo { - - @ApiModelProperty(value = "节点名称",required = true) - private String name; - - @ApiModelProperty(value = "map[string]string, value必须为 string") - private UpdateNodePropertiesBoBody state; - - @Data - @AllArgsConstructor - @NoArgsConstructor - public static class UpdateNodePropertiesBoBody { - @ApiModelProperty(value = "map[string]string, value必须为 string") - private String desire; - } - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/CreateNodeVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/CreateNodeVo.java deleted file mode 100644 index 8df626f9..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/CreateNodeVo.java +++ /dev/null @@ -1,39 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/8 16:36 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class CreateNodeVo { - - @ApiModelProperty(value = "节点名称") - private String name; - @ApiModelProperty(value = "命名空间") - private String namespace; - @ApiModelProperty(value = "描述信息") - private String description; - @ApiModelProperty(value = "为空或NVIDIA GPU") - private String accelerator; - @ApiModelProperty(value = "可选官方应用,支持 baetyl-function、baetyl-rule") - private String[] sysApps; - @ApiModelProperty(value = "节点是否已连接") - private Boolean ready; - @ApiModelProperty(value = "创建时间") - private String createTime; - @ApiModelProperty(value = "标签") - private Object labels; - @ApiModelProperty(value = "注解") - private Object annotations; - - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetCoreConfigVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetCoreConfigVo.java deleted file mode 100644 index 006dd868..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetCoreConfigVo.java +++ /dev/null @@ -1,27 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/18 15:58 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class GetCoreConfigVo { - - @ApiModelProperty(value = "core 版本") - private String version; - - @ApiModelProperty(value = "core 上报频率") - private Integer frequency; - - @ApiModelProperty(value = "core 边缘 API 端口") - private Integer apiport; -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeAppsByNameVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeAppsByNameVo.java deleted file mode 100644 index 0209aa8d..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeAppsByNameVo.java +++ /dev/null @@ -1,44 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/8 16:36 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class GetNodeAppsByNameVo { - - @ApiModelProperty(value = "应用总数") - private Integer total; - @ApiModelProperty(value = "列表选项") - private Object listOptions; - - @ApiModelProperty(value = "应用列表") - private List items; - - @Data - @AllArgsConstructor - @NoArgsConstructor - public static class AppInfoDetails{ - @ApiModelProperty(value = "应用名称",required = true) - private String name; - @ApiModelProperty(value = "标签选择器",required = true) - private String selector; - @ApiModelProperty(value = "命名空间",required = true) - private String namespace; - @ApiModelProperty(value = "创建时间",required = true) - private String createTime; - } - - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeByNameVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeByNameVo.java deleted file mode 100644 index 4e8fef2b..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeByNameVo.java +++ /dev/null @@ -1,14 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import lombok.Data; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/11 18:31 - * @modificed by: - */ -@Data -public class GetNodeByNameVo { - // TODO: 2023/6/11 -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeCoreVersionVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeCoreVersionVo.java deleted file mode 100644 index f9199e7f..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeCoreVersionVo.java +++ /dev/null @@ -1,20 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/11 18:46 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class GetNodeCoreVersionVo { - @ApiModelProperty(value = "当前节点 core 版本号列表") - private String[] versions; -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodePropertiesVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodePropertiesVo.java deleted file mode 100644 index 2d9a11f0..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodePropertiesVo.java +++ /dev/null @@ -1,45 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/18 18:08 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class GetNodePropertiesVo { - - @ApiModelProperty(value = "map[string]string, value必须为 string") - private GetNodePropertiesVoBodyState state; - - @ApiModelProperty(value = "map[string]string, value必须为 string") - private GetNodePropertiesVoBodyMetadata metadata; - - @Data - @AllArgsConstructor - @NoArgsConstructor - public static class GetNodePropertiesVoBodyState { - @ApiModelProperty(value = "map[string]string, value必须为 string") - private String report; - @ApiModelProperty(value = "map[string]string, value必须为 string") - private String desire; - } - - @Data - @AllArgsConstructor - @NoArgsConstructor - public static class GetNodePropertiesVoBodyMetadata { - - @ApiModelProperty(value = "map[string]string, value必须为 string") - private String report; - @ApiModelProperty(value = "map[string]string, value必须为 string") - private String desire; - } -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeStatsVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeStatsVo.java deleted file mode 100644 index f9616b8b..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeStatsVo.java +++ /dev/null @@ -1,14 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import lombok.Data; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/11 18:43 - * @modificed by: - */ -@Data -public class GetNodeStatsVo { - // TODO: 2023/6/11 -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesBatchVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesBatchVo.java deleted file mode 100644 index e37fb734..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesBatchVo.java +++ /dev/null @@ -1,40 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/8 16:36 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class GetNodesBatchVo { - - // TODO: 2023/6/11 待修改 - @ApiModelProperty(value = "节点名称") - private String name; - @ApiModelProperty(value = "命名空间") - private String namespace; - @ApiModelProperty(value = "描述信息") - private String description; - @ApiModelProperty(value = "为空或NVIDIA GPU") - private String accelerator; - @ApiModelProperty(value = "可选官方应用,支持 baetyl-function、baetyl-rule") - private String[] sysApps; - @ApiModelProperty(value = "节点是否已连接") - private Boolean ready; - @ApiModelProperty(value = "创建时间") - private String createTime; - @ApiModelProperty(value = "标签") - private Object labels; - @ApiModelProperty(value = "注解") - private Object annotations; - - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesVo.java deleted file mode 100644 index 1ea9f295..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesVo.java +++ /dev/null @@ -1,14 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import lombok.Data; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/11 18:49 - * @modificed by: - */ -@Data -public class GetNodesVo { - // TODO: 2023/6/11 -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateCoreConfigByNameVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateCoreConfigByNameVo.java deleted file mode 100644 index 4c349a68..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateCoreConfigByNameVo.java +++ /dev/null @@ -1,41 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/11 18:03 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class UpdateCoreConfigByNameVo { - - @ApiModelProperty(value = "节点名称") - private String name; - - @ApiModelProperty(value = "body内容") - private UpdateCoreConfigByNameBoBody body; - - @Data - @AllArgsConstructor - @NoArgsConstructor - public static class UpdateCoreConfigByNameBoBody { - @ApiModelProperty(value = "core版本号") - private String version; - - @ApiModelProperty(value = "core上报频率") - private Integer frequency; - - @ApiModelProperty(value = "core 边缘 API 端口") - private Integer apiport; - } - - - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodePropertiesVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodePropertiesVo.java deleted file mode 100644 index 3cbac0b3..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodePropertiesVo.java +++ /dev/null @@ -1,45 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/11 17:58 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class UpdateNodePropertiesVo { - - @ApiModelProperty(value = "map[string]string, value必须为 string") - private UpdateNodePropertiesVoBodyState state; - - @ApiModelProperty(value = "map[string]string, value必须为 string") - private UpdateNodePropertiesVoBodyMetadata metadata; - - @Data - @AllArgsConstructor - @NoArgsConstructor - public static class UpdateNodePropertiesVoBodyState { - @ApiModelProperty(value = "map[string]string, value必须为 string") - private String report; - @ApiModelProperty(value = "map[string]string, value必须为 string") - private String desire; - } - - @Data - @AllArgsConstructor - @NoArgsConstructor - public static class UpdateNodePropertiesVoBodyMetadata { - - @ApiModelProperty(value = "map[string]string, value必须为 string") - private String report; - @ApiModelProperty(value = "map[string]string, value必须为 string") - private String desire; - } -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodeVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodeVo.java deleted file mode 100644 index ce018c25..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodeVo.java +++ /dev/null @@ -1,36 +0,0 @@ -package cc.iotkit.baetyl.dto.vo; - -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author: regan - * @description: - * @date:created in 2023/6/11 18:35 - * @modificed by: - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class UpdateNodeVo { - - @ApiModelProperty(value = "节点名称") - private String name; - @ApiModelProperty(value = "命名空间") - private String namespace; - @ApiModelProperty(value = "描述信息") - private String description; - @ApiModelProperty(value = "可选官方应用,支持 baetyl-function、baetyl-rule") - private String[] sysApps; - @ApiModelProperty(value = "节点是否已连接") - private Boolean ready; - @ApiModelProperty(value = "创建时间") - private String createTime; - @ApiModelProperty(value = "标签") - private Object labels; - @ApiModelProperty(value = "注解") - private Object annotations; - -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/feign/BaetylServiceFeignClient.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/feign/BaetylServiceFeignClient.java deleted file mode 100644 index cd7977f1..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/feign/BaetylServiceFeignClient.java +++ /dev/null @@ -1,54 +0,0 @@ -package cc.iotkit.baetyl.feign; - -import cc.iotkit.baetyl.constant.BaetylConstant; -import cc.iotkit.baetyl.dto.bo.CreateNodeBo; -import cc.iotkit.baetyl.dto.bo.UpdateCoreConfigByNameBo; -import cc.iotkit.baetyl.dto.bo.UpdateNodeBo; -import cc.iotkit.baetyl.dto.bo.UpdateNodePropertiesBo; -import cc.iotkit.baetyl.dto.vo.*; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.*; - -@ConditionalOnClass(FeignClient.class) -@FeignClient(name = "baetylServiceFeignClient" , contextId = "baetylServiceFeignClient" ,url = "${baetyl.service-url:}") -public interface BaetylServiceFeignClient { - - @GetMapping(value = BaetylConstant.Url.NodeManagement.GetNodeAppsByName) - GetNodeAppsByNameVo getNodeAppsByName(@PathVariable(value = "name") String name); - - @PutMapping(value = BaetylConstant.Url.NodeManagement.UpdateCoreConfigByName) - UpdateCoreConfigByNameVo updateCoreConfigByName(@PathVariable(value = "name") String name, @RequestBody UpdateCoreConfigByNameBo.UpdateCoreConfigByNameBoBody data); - - @PostMapping(value = BaetylConstant.Url.NodeManagement.CreatNode) - CreateNodeVo creatNode(@RequestBody CreateNodeBo data); - - @DeleteMapping(value = BaetylConstant.Url.NodeManagement.DeleteNodeByName) - Boolean deleteNodeByName(@PathVariable(value = "name") String name); - - @PutMapping(value = BaetylConstant.Url.NodeManagement.GetNodesBatch) - GetNodesBatchVo getNodesBatch(@RequestBody String[] data); - - @PutMapping(value = BaetylConstant.Url.NodeManagement.UpdateNodeProperties) - UpdateNodePropertiesVo updateNodeProperties(@PathVariable(value = "name") String name, @RequestBody UpdateNodePropertiesBo.UpdateNodePropertiesBoBody state); - - @GetMapping(value = BaetylConstant.Url.NodeManagement.GetNodeByName) - GetNodeByNameVo getNodeByName(@PathVariable(value = "name") String name); - - @PutMapping(value = BaetylConstant.Url.NodeManagement.UpdateNode) - UpdateNodeVo updateNode(@PathVariable(value = "name") String name, @RequestBody UpdateNodeBo.UpdateNodeBoBody body); - @GetMapping(value = BaetylConstant.Url.NodeManagement.GetNodeStats) - GetNodeStatsVo getNodeStats(@PathVariable(value = "name") String name); - @GetMapping(value = BaetylConstant.Url.NodeManagement.GetNodeCoreVersion) - GetNodeCoreVersionVo getNodeCoreVersion(@PathVariable(value = "name") String name); - @GetMapping(value = BaetylConstant.Url.NodeManagement.GetNodes) - GetNodesVo getNodes(@RequestParam(value = "selector") String selector, @RequestParam(value = "fieldSelector") String fieldSelector, @RequestParam(value = "limit") Integer limit, - @RequestParam(value = "continue") String isContinue, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize, - @RequestParam(value = "name") String name, @RequestParam(value = "nodeSelector") String nodeSelector); - @GetMapping(value = BaetylConstant.Url.NodeManagement.GetCoreConfig) - GetCoreConfigVo getCoreConfig(@PathVariable(value = "name") String name); - @GetMapping(value = BaetylConstant.Url.NodeManagement.GetInstallCommand) - String getInstallCommand(@PathVariable(value = "name") String name, @RequestParam(value = "mode") String mode); - @GetMapping(value = BaetylConstant.Url.NodeManagement.GetNodeProperties) - GetNodePropertiesVo getNodeProperties(@PathVariable(value = "name") String data); -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceFeignImpl.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceFeignImpl.java deleted file mode 100644 index 33e249d5..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceFeignImpl.java +++ /dev/null @@ -1,92 +0,0 @@ -package cc.iotkit.baetyl.service; - -import cc.iotkit.baetyl.IBaetylService; -import cc.iotkit.baetyl.dto.bo.*; -import cc.iotkit.baetyl.dto.vo.*; -import cc.iotkit.baetyl.feign.BaetylServiceFeignClient; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Component; - -@Slf4j -@ConditionalOnProperty(value = "baetyl.api-type", havingValue = "feign") -@Component -public class BaetylServiceFeignImpl implements IBaetylService { - - @Lazy - @Autowired - private BaetylServiceFeignClient client; - - @Override - public GetNodeAppsByNameVo getNodeAppsByName(String name) { - return client.getNodeAppsByName(name); - } - - @Override - public UpdateCoreConfigByNameVo updateCoreConfigByName(UpdateCoreConfigByNameBo data) { - return client.updateCoreConfigByName(data.getName(),data.getBody()); - } - - @Override - public CreateNodeVo creatNode(CreateNodeBo data) { - return client.creatNode(data); - } - - @Override - public Boolean deleteNodeByName(String data) { - return client.deleteNodeByName(data); - } - - @Override - public GetNodesBatchVo getNodesBatch(String[] data) { - return client.getNodesBatch(data); - } - - @Override - public UpdateNodePropertiesVo updateNodeProperties(UpdateNodePropertiesBo data) { - return client.updateNodeProperties(data.getName(),data.getState()); - } - - @Override - public GetNodeByNameVo getNodeByName(String data) { - return client.getNodeByName(data); - } - - @Override - public UpdateNodeVo updateNode(UpdateNodeBo data) { - return client.updateNode(data.getName(),data.getBody()); - } - - @Override - public GetNodeStatsVo getNodeStats(String data) { - return client.getNodeStats(data); - } - - @Override - public GetNodeCoreVersionVo getNodeCoreVersion(String data) { - return client.getNodeCoreVersion(data); - } - - @Override - public GetNodesVo getNodes(GetNodesBo data) { - return client.getNodes(data.getSelector(),data.getFieldSelector(),data.getLimit(),data.getIsContinue(),data.getPageNo(),data.getPageSize(), - data.getName(),data.getNodeSelector()); - } - - @Override - public GetCoreConfigVo getCoreConfig(String data) { - return client.getCoreConfig(data); - } - - @Override - public String getInstallCommand(GetInstallCommandBo data) { - return client.getInstallCommand(data.getName(),data.getMode()); - } - - @Override - public GetNodePropertiesVo getNodeProperties(String data) { - return client.getNodeProperties(data); - } -} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceWebclientImpl.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceWebclientImpl.java deleted file mode 100644 index 111aab33..00000000 --- a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceWebclientImpl.java +++ /dev/null @@ -1,102 +0,0 @@ -package cc.iotkit.baetyl.service; - -import cc.iotkit.baetyl.IBaetylService; -import cc.iotkit.baetyl.constant.BaetylConstant; -import cc.iotkit.baetyl.dto.bo.*; -import cc.iotkit.baetyl.dto.vo.*; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.stereotype.Component; -import org.springframework.web.reactive.function.client.WebClient; - - -@Slf4j -@ConditionalOnProperty(value = "baetyl.api-type", havingValue = "webClient") -@Component -public class BaetylServiceWebclientImpl implements IBaetylService { - - - @Autowired - private WebClient webClient; - - - @Override - public GetNodeAppsByNameVo getNodeAppsByName(String name) { - ParameterizedTypeReference responseBodyType = new ParameterizedTypeReference<>() {}; - return webClient.get() - .uri(BaetylConstant.Url.NodeManagement.GetNodeAppsByName.replace("{name}",name)) - .retrieve() - .bodyToMono(responseBodyType) - .block(); - } - - // TODO: 2023/6/10 后续有需要则实现 - - - @Override - public UpdateCoreConfigByNameVo updateCoreConfigByName(UpdateCoreConfigByNameBo data) { - return null; - } - - @Override - public CreateNodeVo creatNode(CreateNodeBo data) { - return null; - } - - @Override - public Boolean deleteNodeByName(String data) { - return null; - } - - @Override - public GetNodesBatchVo getNodesBatch(String[] data) { - return null; - } - - @Override - public UpdateNodePropertiesVo updateNodeProperties(UpdateNodePropertiesBo data) { - return null; - } - - @Override - public GetNodeByNameVo getNodeByName(String data) { - return null; - } - - @Override - public UpdateNodeVo updateNode(UpdateNodeBo data) { - return null; - } - - @Override - public GetNodeStatsVo getNodeStats(String data) { - return null; - } - - @Override - public GetNodeCoreVersionVo getNodeCoreVersion(String data) { - return null; - } - - @Override - public GetNodesVo getNodes(GetNodesBo data) { - return null; - } - - @Override - public GetCoreConfigVo getCoreConfig(String data) { - return null; - } - - @Override - public String getInstallCommand(GetInstallCommandBo data) { - return null; - } - - @Override - public GetNodePropertiesVo getNodeProperties(String data) { - return null; - } -} diff --git a/iot-module/iot-contribution/pom.xml b/iot-module/iot-contribution/pom.xml deleted file mode 100644 index b6c320b3..00000000 --- a/iot-module/iot-contribution/pom.xml +++ /dev/null @@ -1,139 +0,0 @@ - - - 4.0.0 - - iot-module - cc.iotkit - 0.5.0-SNAPSHOT - - - - iot-contribution - - - 11 - 11 - UTF-8 - - - - - - cc.iotkit - iot-common-model - - - - cc.iotkit - iot-common-core - - - - 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-log - - - - cc.iotkit - iot-common-excel - - - - - - org.springframework.boot - spring-boot-starter-web - - - - joda-time - joda-time - - - - 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 - - - - - - - - - com.mysema.maven - apt-maven-plugin - 1.1.3 - - - generate-sources - - process - - - target/generated-sources/java - com.querydsl.apt.jpa.JPAAnnotationProcessor - - - - - - - - \ No newline at end of file diff --git a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/controller/IotContributorController.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/controller/IotContributorController.java deleted file mode 100644 index 67a90abb..00000000 --- a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/controller/IotContributorController.java +++ /dev/null @@ -1,106 +0,0 @@ -package cc.iotkit.contribution.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 cc.iotkit.contribution.dto.vo.IotContributorVo; -import cc.iotkit.contribution.dto.bo.IotContributorBo; -import cc.iotkit.contribution.service.IIotContributorService; - - -/** - * 贡献者 - * - * @author Lion Li - * @date 2023-07-09 - */ -@Validated -@RequiredArgsConstructor -@RestController -@RequestMapping("/contribution/contributor") -public class IotContributorController extends BaseController { - - private final IIotContributorService iotContributorService; - - /** - * 查询贡献者列表 - */ -// @SaCheckPermission("contribution:contributor:list") - @PostMapping("/list") - @ApiOperation("查询贡献者列表") - public Paging list( PageRequest pageQuery) { - return iotContributorService.queryPageList(pageQuery); - } - - /** - * 导出贡献者列表 - */ - @ApiOperation("导出贡献者列表") - @SaCheckPermission("contribution:contributor:export") - @Log(title = "贡献者", businessType = BusinessType.EXPORT) - @PostMapping("/export") - public void export(IotContributorBo bo, HttpServletResponse response) { - List list = iotContributorService.queryList(bo); - ExcelUtil.exportExcel(list, "贡献者", IotContributorVo.class, response); - } - - /** - * 获取贡献者详细信息 - * - */ -// @SaCheckPermission("contribution:contributor:query") - @PostMapping("/getDetail") - @ApiOperation("获取贡献者详细信息") - public IotContributorVo getDetail(@Validated @RequestBody Request request) { - return iotContributorService.queryById(request.getData()); - } - - /** - * 新增贡献者 - */ - @SaCheckPermission("contribution:contributor:add") - @Log(title = "贡献者", businessType = BusinessType.INSERT) - @PostMapping(value = "/add") - @ApiOperation("新增贡献者") - public Long add(@Validated(AddGroup.class) @RequestBody Request request) { - return iotContributorService.insertByBo(request.getData()); - } - - /** - * 修改贡献者 - */ - @SaCheckPermission("contribution:contributor:edit") - @Log(title = "贡献者", businessType = BusinessType.UPDATE) - @PostMapping("/edit") - @ApiOperation("修改贡献者") - public boolean edit(@Validated(EditGroup.class) @RequestBody Request request) { - return iotContributorService.updateByBo(request.getData()); - } - - /** - * 删除贡献者 - * - */ - @SaCheckPermission("contribution:contributor:remove") - @Log(title = "贡献者", businessType = BusinessType.DELETE) - @PostMapping("/delete") - @ApiOperation("删除贡献者") - public boolean remove(@Validated @RequestBody Request> query) { - return iotContributorService.deleteWithValidByIds(query.getData(), true); - } -} diff --git a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/data/IIotContributorData.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/data/IIotContributorData.java deleted file mode 100644 index 5f73aa01..00000000 --- a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/data/IIotContributorData.java +++ /dev/null @@ -1,16 +0,0 @@ -package cc.iotkit.contribution.data; - -import cc.iotkit.data.ICommonData; -import cc.iotkit.contribution.model.IotContributor; -import cc.iotkit.data.ICommonData; - -/** - * 数据接口 - * - * @author Lion Li - * @date 2023-07-09 - */ -public interface IIotContributorData extends ICommonData { - - -} diff --git a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/data/impl/IotContributorDataImpl.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/data/impl/IotContributorDataImpl.java deleted file mode 100644 index a8560c7c..00000000 --- a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/data/impl/IotContributorDataImpl.java +++ /dev/null @@ -1,115 +0,0 @@ -package cc.iotkit.contribution.data.impl; - -import cc.iotkit.contribution.repository.IotContributorRepository; -import cc.iotkit.contribution.data.IIotContributorData; -import cc.iotkit.contribution.data.model.TbIotContributor; -import cc.iotkit.contribution.model.IotContributor; - -import java.util.*; - -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 cc.iotkit.common.utils.MapstructUtils; -import cc.iotkit.data.util.PageBuilder; - - -import static cc.iotkit.contribution.data.model.QTbIotContributor.tbIotContributor; - -/** - * 数据实现接口 - * - * @author Lion Li - * @date 2023-07-09 - */ -@Primary -@Service -@RequiredArgsConstructor -public class IotContributorDataImpl implements IIotContributorData { - - private final IotContributorRepository baseRepository; - - private final JPAQueryFactory jpaQueryFactory; - - @Override - public Paging findAll(PageRequest pageRequest) { - return PageBuilder.toPaging(baseRepository.findAll(buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest))).to(IotContributor.class); - } - - private Predicate buildQueryCondition(IotContributor bo) { - PredicateBuilder builder = PredicateBuilder.instance(); - if (Objects.nonNull(bo)) { - - builder.and(StringUtils.isNotBlank(bo.getContributor()), () -> tbIotContributor.contributor.eq(bo.getContributor())); - builder.and(bo.getPost() != null, () -> tbIotContributor.post.eq(bo.getPost())); - } - return builder.build(); - } - - @Override - public List findByIds(Collection ids) { - List allById = baseRepository.findAllById(ids); - return MapstructUtils.convert(allById, IotContributor.class); - } - - @Override - public IotContributor save(IotContributor data) { - Object o = baseRepository.save(MapstructUtils.convert(data, TbIotContributor.class)); - return MapstructUtils.convert(o, IotContributor.class); - } - - @Override - public void batchSave(List data) { - baseRepository.saveAll(MapstructUtils.convert(data, TbIotContributor.class)); - } - - @Override - public void deleteById(Long id) { - baseRepository.deleteById(id); - } - - @Override - public void deleteByIds(Collection ids) { - baseRepository.deleteAllById(ids); - } - - @Override - public IotContributor findById(Long id) { - TbIotContributor ret = jpaQueryFactory.select(tbIotContributor).from(tbIotContributor).where(tbIotContributor.id.eq(id)).fetchOne(); - return MapstructUtils.convert(ret, IotContributor.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(Arrays.asList(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-contribution/src/main/java/cc/iotkit/contribution/data/model/TbIotContributor.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/data/model/TbIotContributor.java deleted file mode 100644 index 638691ad..00000000 --- a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/data/model/TbIotContributor.java +++ /dev/null @@ -1,104 +0,0 @@ -package cc.iotkit.contribution.data.model; - -import cc.iotkit.contribution.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; -import cc.iotkit.data.model.BaseEntity; -import lombok.Data; -import lombok.EqualsAndHashCode; -import javax.persistence.Table; -import javax.persistence.Entity; - -/** - * 贡献者对象 iot_contributor - * - * @author Lion Li - * @date 2023-07-09 - */ -@Data -@NoArgsConstructor -@EqualsAndHashCode(callSuper = true) -@Entity -@Table(name = "iot_contributor") -@AutoMapper(target = IotContributor.class) -public class TbIotContributor extends BaseEntity { - - - - /** - * - */ - @Id - @GeneratedValue(generator = "SnowflakeIdGenerator") - @GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator") - @ApiModelProperty(value = "") - private Long id; - - /** - * 贡献者名称 - */ - @ApiModelProperty(value = "贡献者名称") - private String contributor; - - /** - * 头像 - */ - @ApiModelProperty(value = "头像") - private String avatar; - - /** - * 岗位(1前端开发,2后端开发,3全栈开发,4测试,5ui设计师,6产品经理,7架构师) - */ - @ApiModelProperty(value = "岗位(1前端开发,2后端开发,3全栈开发,4测试,5ui设计师,6产品经理,7架构师)") - private Long post; - - /** - * 简介 - */ - @ApiModelProperty(value = "简介") - private String intro; - - /** - * tag列表(为了简单,逗号隔开) - */ - @ApiModelProperty(value = "tag列表(为了简单,逗号隔开)") - private String tags; - - /** - * 详情标题 - */ - @ApiModelProperty(value = "详情标题") - private String title; - - /** - * 详情 - */ - @ApiModelProperty(value = "详情") - private String context; - - /** - * 排序 - */ - @ApiModelProperty(value = "排序") - private Long score; - - /** - * 帐号状态(0正常 1停用) - */ - @ApiModelProperty(value = "帐号状态(0正常 1停用)") - private String status; - - /** - * 删除标志(0代表存在 2代表删除) - */ - @ApiModelProperty(value = "删除标志(0代表存在 2代表删除)") - private String delFlag; - - -} diff --git a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/dto/bo/IotContributorBo.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/dto/bo/IotContributorBo.java deleted file mode 100644 index f5d2a369..00000000 --- a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/dto/bo/IotContributorBo.java +++ /dev/null @@ -1,90 +0,0 @@ -package cc.iotkit.contribution.dto.bo; - -import cc.iotkit.contribution.model.IotContributor; -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 jakarta.validation.constraints.*; - -/** - * 贡献者业务对象 iot_contributor - * - * @author Lion Li - * @date 2023-07-09 - */ -@Data -@EqualsAndHashCode(callSuper = true) -@AutoMapper(target = IotContributor.class, reverseConvertGenerate = false) -public class IotContributorBo extends BaseDto { - - /** - * - */ - @NotNull(message = "不能为空", groups = { EditGroup.class }) - @ApiModelProperty(value = "", required = true) - private Long id; - - /** - * 贡献者名称 - */ - @NotBlank(message = "贡献者名称不能为空", groups = { AddGroup.class, EditGroup.class }) - @ApiModelProperty(value = "贡献者名称", required = true) - private String contributor; - - /** - * 头像 - */ - @ApiModelProperty(value = "头像", required = false) - private String avatar; - - /** - * 岗位(1前端开发,2后端开发,3全栈开发,4测试,5ui设计师,6产品经理,7架构师) - */ - @ApiModelProperty(value = "岗位(1前端开发,2后端开发,3全栈开发,4测试,5ui设计师,6产品经理,7架构师)", required = false) - private Long post; - - /** - * 简介 - */ - @ApiModelProperty(value = "简介", required = false) - private String intro; - - /** - * tag列表(为了简单,逗号隔开) - */ - @ApiModelProperty(value = "tag列表(为了简单,逗号隔开)", required = false) - private String tags; - - /** - * 详情标题 - */ - @ApiModelProperty(value = "详情标题", required = false) - private String title; - - /** - * 详情 - */ - @ApiModelProperty(value = "详情", required = false) - private String context; - - /** - * 排序 - */ - @NotNull(message = "排序不能为空", groups = { AddGroup.class, EditGroup.class }) - @ApiModelProperty(value = "排序", required = true) - private Long score; - - /** - * 帐号状态(0正常 1停用) - */ - @NotBlank(message = "帐号状态(0正常 1停用)不能为空", groups = { AddGroup.class, EditGroup.class }) - @ApiModelProperty(value = "帐号状态(0正常 1停用)", required = true) - private String status; - - -} diff --git a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/dto/vo/IotContributorVo.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/dto/vo/IotContributorVo.java deleted file mode 100644 index d361f220..00000000 --- a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/dto/vo/IotContributorVo.java +++ /dev/null @@ -1,104 +0,0 @@ -package cc.iotkit.contribution.dto.vo; - -import cc.iotkit.contribution.model.IotContributor; -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; - - - -/** - * 贡献者视图对象 iot_contributor - * - * @author Lion Li - * @date 2023-07-09 - */ -@Data -@ExcelIgnoreUnannotated -@AutoMapper(target = IotContributor.class) -public class IotContributorVo implements Serializable { - - - private static final long serialVersionUID = 1L; - - /** - * - */ - @ExcelProperty(value = "") - @ApiModelProperty(value = "") - private Long id; - - /** - * 贡献者名称 - */ - @ExcelProperty(value = "贡献者名称") - @ApiModelProperty(value = "贡献者名称") - private String contributor; - - /** - * 头像 - */ - @ExcelProperty(value = "头像") - @ApiModelProperty(value = "头像") - private String avatar; - - /** - * 岗位(1前端开发,2后端开发,3全栈开发,4测试,5ui设计师,6产品经理,7架构师) - */ - @ExcelProperty(value = "岗位(1前端开发,2后端开发,3全栈开发,4测试,5ui设计师,6产品经理,7架构师)") - @ApiModelProperty(value = "岗位(1前端开发,2后端开发,3全栈开发,4测试,5ui设计师,6产品经理,7架构师)") - private Long post; - - /** - * 简介 - */ - @ExcelProperty(value = "简介") - @ApiModelProperty(value = "简介") - private String intro; - - /** - * tag列表(为了简单,逗号隔开) - */ - @ExcelProperty(value = "tag列表(为了简单,逗号隔开)") - @ApiModelProperty(value = "tag列表(为了简单,逗号隔开)") - private String tags; - - /** - * 详情标题 - */ - @ExcelProperty(value = "详情标题") - @ApiModelProperty(value = "详情标题") - private String title; - - /** - * 详情 - */ - @ExcelProperty(value = "详情") - @ApiModelProperty(value = "详情") - private String context; - - /** - * 排序 - */ - @ExcelProperty(value = "排序") - @ApiModelProperty(value = "排序") - private Long score; - - /** - * 帐号状态(0正常 1停用) - */ - @ExcelProperty(value = "帐号状态", converter = ExcelDictConvert.class) - @ExcelDictFormat(readConverterExp = "0=正常,1=停用") - @ApiModelProperty(value = "帐号状态") - private String status; - - -} diff --git a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/model/IotContributor.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/model/IotContributor.java deleted file mode 100644 index c0c54472..00000000 --- a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/model/IotContributor.java +++ /dev/null @@ -1,79 +0,0 @@ -package cc.iotkit.contribution.model; - -import cc.iotkit.model.Id; -import cc.iotkit.model.BaseModel; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.io.Serializable; - - -/** - * 贡献者对象 iot_contributor - * - * @author Lion Li - * @date 2023-07-09 - */ -@Data -@EqualsAndHashCode(callSuper = true) -public class IotContributor extends BaseModel implements Id, Serializable{ - - private static final long serialVersionUID = 1L; - - /** - * - */ - private Long id; - - /** - * 贡献者名称 - */ - private String contributor; - - /** - * 头像 - */ - private String avatar; - - /** - * 岗位(1前端开发,2后端开发,3全栈开发,4测试,5ui设计师,6产品经理,7架构师) - */ - private Long post; - - /** - * 简介 - */ - private String intro; - - /** - * tag列表(为了简单,逗号隔开) - */ - private String tags; - - /** - * 详情标题 - */ - private String title; - - /** - * 详情 - */ - private String context; - - /** - * 排序 - */ - private Long score; - - /** - * 帐号状态(0正常 1停用) - */ - private String status; - - /** - * 删除标志(0代表存在 2代表删除) - */ - private String delFlag; - - -} diff --git a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/repository/IotContributorRepository.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/repository/IotContributorRepository.java deleted file mode 100644 index 16dab3fb..00000000 --- a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/repository/IotContributorRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package cc.iotkit.contribution.repository; - -import cc.iotkit.contribution.data.model.TbIotContributor; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.querydsl.QuerydslPredicateExecutor; - -/** - * 贡献者对象 iot_contributor - * - * @author Lion Li - * @date 2023-07-09 - */ -public interface IotContributorRepository extends JpaRepository, QuerydslPredicateExecutor { - -} diff --git a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/ContributorDataInit.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/ContributorDataInit.java deleted file mode 100644 index 1c0b1dfe..00000000 --- a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/ContributorDataInit.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * +---------------------------------------------------------------------- - * | Copyright (c) 奇特物联 2021-2022 All rights reserved. - * +---------------------------------------------------------------------- - * | Licensed 未经许可不能去掉「奇特物联」相关版权 - * +---------------------------------------------------------------------- - * | Author: xw2sy@163.com - * +---------------------------------------------------------------------- - */ -package cc.iotkit.contribution.service; - -import cc.iotkit.common.utils.JsonUtils; - -import cc.iotkit.contribution.data.IIotContributorData; -import cc.iotkit.contribution.data.impl.IotContributorDataImpl; -import cc.iotkit.contribution.model.IotContributor; -import cc.iotkit.data.ICommonData; -import cc.iotkit.model.Id; -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.Qualifier; -import org.springframework.stereotype.Service; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; - -@Slf4j -@Service -public class ContributorDataInit implements SmartInitializingSingleton { - - @Autowired - private IIotContributorData contributorData; - - @Override - public void afterSingletonsInstantiated() { - //等redis实例化后再执行 - Timer timer = new Timer(); - timer.schedule(new TimerTask() { - @Override - public void run() { - try { - - initSysData(); - - - - } catch ( - Throwable e) { - log.error("init error", e); - } - } - }, 100); - - } - - private void initSysData() throws IOException { - - initData("contributor", contributorData, new TypeReference>() { - }); - } - - private T initData(String name, ICommonData service, TypeReference type) throws IOException { - log.info("init {} data...", name); - if (service.count() > 0) { - return null; - } - String json = FileUtils.readFileToString(new File("./data/init/" + name + ".json"), StandardCharsets.UTF_8); - List list = (List) JsonUtils.parseObject(json, type); - for (Object obj : list) { - service.save((Id) obj); - } - return (T) list; - } - -} diff --git a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/IIotContributorService.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/IIotContributorService.java deleted file mode 100644 index e8ca7354..00000000 --- a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/IIotContributorService.java +++ /dev/null @@ -1,49 +0,0 @@ -package cc.iotkit.contribution.service; - -import cc.iotkit.contribution.dto.vo.IotContributorVo; -import cc.iotkit.contribution.dto.bo.IotContributorBo; - -import cc.iotkit.common.api.Paging; -import cc.iotkit.common.api.PageRequest; - -import java.util.Collection; -import java.util.List; - -/** - * 贡献者Service接口 - * - * @author Lion Li - * @date 2023-07-09 - */ -public interface IIotContributorService { - - /** - * 查询贡献者 - */ - IotContributorVo queryById(Long id); - - /** - * 查询贡献者列表 - */ - Paging queryPageList(PageRequest pageQuery); - - /** - * 查询贡献者列表 - */ - List queryList(IotContributorBo bo); - - /** - * 新增贡献者 - */ - Long insertByBo(IotContributorBo bo); - - /** - * 修改贡献者 - */ - Boolean updateByBo(IotContributorBo bo); - - /** - * 校验并批量删除贡献者信息 - */ - Boolean deleteWithValidByIds(Collection ids, Boolean isValid); -} diff --git a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/impl/IotContributorServiceImpl.java b/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/impl/IotContributorServiceImpl.java deleted file mode 100644 index 2f9c58ed..00000000 --- a/iot-module/iot-contribution/src/main/java/cc/iotkit/contribution/service/impl/IotContributorServiceImpl.java +++ /dev/null @@ -1,103 +0,0 @@ -package cc.iotkit.contribution.service.impl; - -import cc.iotkit.common.utils.MapstructUtils; -import cc.iotkit.common.utils.StringUtils; -import cc.iotkit.common.api.PageRequest; -import cc.iotkit.common.api.Paging; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import cc.iotkit.contribution.dto.bo.IotContributorBo; -import cc.iotkit.contribution.dto.vo.IotContributorVo; -import cc.iotkit.contribution.model.IotContributor; -import cc.iotkit.contribution.service.IIotContributorService; -import cc.iotkit.contribution.data.IIotContributorData; - -import java.util.List; -import java.util.Collection; -import cc.iotkit.common.exception.BizException; - - -/** - * 贡献者Service业务层处理 - * - * @author Lion Li - * @date 2023-07-09 - */ -@RequiredArgsConstructor -@Service -public class IotContributorServiceImpl implements IIotContributorService { - - private final IIotContributorData baseData; - - /** - * 查询贡献者 - */ - @Override - public IotContributorVo queryById(Long id){ - return MapstructUtils.convert(baseData.findById(id), IotContributorVo.class); - } - - /** - * 查询贡献者列表 - */ - @Override - public Paging queryPageList(PageRequest pageQuery) { - return baseData.findAll(pageQuery.to(IotContributor.class)).to(IotContributorVo.class); - } - - /** - * 查询贡献者列表 - */ - @Override - public List queryList(IotContributorBo bo) { - - return MapstructUtils.convert(baseData.findAllByCondition(bo.to(IotContributor.class)), IotContributorVo.class); - } - - /** - * 新增贡献者 - */ - @Override - public Long insertByBo(IotContributorBo bo) { - IotContributor add = MapstructUtils.convert(bo, IotContributor.class); - validEntityBeforeSave(add); - baseData.save(add); - if (add == null) { - throw new BizException("新增失败"); - } - return add.getId(); - } - - /** - * 修改贡献者 - */ - @Override - public Boolean updateByBo(IotContributorBo bo) { - IotContributor update = MapstructUtils.convert(bo, IotContributor.class); - validEntityBeforeSave(update); - IotContributor ret = baseData.save(update); - if(ret == null){ - return false; - } - return true; - } - - /** - * 保存前的数据校验 - */ - private void validEntityBeforeSave(IotContributor entity){ - //TODO 做一些数据校验,如唯一约束 - } - - /** - * 批量删除贡献者 - */ - @Override - public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { - if(isValid){ - //TODO 做一些业务上的校验,判断是否需要校验 - } - baseData.deleteByIds(ids); - return true; - } -} diff --git a/iot-module/iot-generator/pom.xml b/iot-module/iot-generator/pom.xml deleted file mode 100644 index 569a82ea..00000000 --- a/iot-module/iot-generator/pom.xml +++ /dev/null @@ -1,117 +0,0 @@ - - - - iot-module - cc.iotkit - 0.5.0-SNAPSHOT - - - 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-web - - - - 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} - - - - - - - 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 deleted file mode 100644 index e6c0103f..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/config/GenConfig.java +++ /dev/null @@ -1,73 +0,0 @@ -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 deleted file mode 100644 index c7e96a90..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/config/MybatisPlusConfig.java +++ /dev/null @@ -1,101 +0,0 @@ -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}") -//@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 deleted file mode 100644 index 7457336c..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/constant/GenConstants.java +++ /dev/null @@ -1,186 +0,0 @@ -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 deleted file mode 100644 index 984baf12..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/controller/GenController.java +++ /dev/null @@ -1,212 +0,0 @@ -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.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 -@RequiredArgsConstructor -@RestController -@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 deleted file mode 100644 index 8e2109c0..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/BaseEntity.java +++ /dev/null @@ -1,70 +0,0 @@ -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 deleted file mode 100644 index 378813e7..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/BaseMapperPlus.java +++ /dev/null @@ -1,198 +0,0 @@ -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 deleted file mode 100644 index 22243391..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseHelper.java +++ /dev/null @@ -1,76 +0,0 @@ -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 deleted file mode 100644 index 06168643..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DataBaseType.java +++ /dev/null @@ -1,51 +0,0 @@ -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 deleted file mode 100644 index f1c748e8..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/DbIdGenerator.java +++ /dev/null @@ -1,30 +0,0 @@ -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 deleted file mode 100644 index 0d5d7510..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/PageBuilder.java +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index efab0216..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/PageQuery.java +++ /dev/null @@ -1,113 +0,0 @@ -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 deleted file mode 100644 index c4fb2979..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/core/SqlUtil.java +++ /dev/null @@ -1,58 +0,0 @@ -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 deleted file mode 100644 index 16c1a903..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTable.java +++ /dev/null @@ -1,196 +0,0 @@ -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 jakarta.validation.Valid; -import jakarta.validation.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 deleted file mode 100644 index 6535f28f..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/domain/GenTableColumn.java +++ /dev/null @@ -1,222 +0,0 @@ -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 jakarta.validation.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 deleted file mode 100644 index 19544e38..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/dto/bo/ImportTableBo.java +++ /dev/null @@ -1,24 +0,0 @@ -package cc.iotkit.generator.dto.bo; - -import cc.iotkit.common.api.BaseDto; -import io.swagger.annotations.ApiModelProperty; -import jakarta.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 deleted file mode 100644 index cd5933b8..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/factory/YmlPropertySourceFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -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 deleted file mode 100644 index ad5a4a53..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/mapper/GenTableColumnMapper.java +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index 42f8f9bd..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/mapper/GenTableMapper.java +++ /dev/null @@ -1,63 +0,0 @@ -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 deleted file mode 100644 index 7887ca3e..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/GenTableServiceImpl.java +++ /dev/null @@ -1,463 +0,0 @@ -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 deleted file mode 100644 index 7b53f199..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/service/IGenTableService.java +++ /dev/null @@ -1,134 +0,0 @@ -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 deleted file mode 100644 index 4659c5e7..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/GenUtils.java +++ /dev/null @@ -1,233 +0,0 @@ -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 deleted file mode 100644 index a47b7595..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityInitializer.java +++ /dev/null @@ -1,35 +0,0 @@ -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 deleted file mode 100644 index 88b2768d..00000000 --- a/iot-module/iot-generator/src/main/java/cc/iotkit/generator/util/VelocityUtils.java +++ /dev/null @@ -1,354 +0,0 @@ -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 deleted file mode 100644 index 6919707b..00000000 --- a/iot-module/iot-generator/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -cc.iotkit.generator.config.MybatisPlusConfig \ 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 deleted file mode 100644 index f5dc6375..00000000 --- a/iot-module/iot-generator/src/main/resources/common-mybatis.yml +++ /dev/null @@ -1,33 +0,0 @@ -# 内置配置 不允许修改 如需修改请在 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 deleted file mode 100644 index 8b91add0..00000000 --- a/iot-module/iot-generator/src/main/resources/generator.yml +++ /dev/null @@ -1,10 +0,0 @@ -# 代码生成 -gen: - # 作者 - author: Lion Li - # 默认生成包路径 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 deleted file mode 100644 index 14f2d97b..00000000 --- a/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - - - - 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 deleted file mode 100644 index 57ff7958..00000000 --- a/iot-module/iot-generator/src/main/resources/mapper/generator/GenTableMapper.xml +++ /dev/null @@ -1,309 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 deleted file mode 100644 index c938b1e5..00000000 --- a/iot-module/iot-generator/src/main/resources/mapper/package-info.md +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index 400b821a..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/java/bo.java.vm +++ /dev/null @@ -1,52 +0,0 @@ -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 jakarta.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 deleted file mode 100644 index 566b9517..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/java/controller.java.vm +++ /dev/null @@ -1,113 +0,0 @@ -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 deleted file mode 100644 index 9dcec7e3..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/java/idata.java.vm +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index aa20bb48..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/java/idataimpl.java.vm +++ /dev/null @@ -1,135 +0,0 @@ -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 deleted file mode 100644 index a367317d..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/java/mapper.java.vm +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 6b75cdbb..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/java/model.java.vm +++ /dev/null @@ -1,50 +0,0 @@ -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 deleted file mode 100644 index e008721e..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/java/repository.java.vm +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index d789b777..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/java/service.java.vm +++ /dev/null @@ -1,53 +0,0 @@ -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 deleted file mode 100644 index 995d4b62..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/java/serviceImpl.java.vm +++ /dev/null @@ -1,109 +0,0 @@ -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 deleted file mode 100644 index 0f03e08f..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/java/tbmodel.java.vm +++ /dev/null @@ -1,71 +0,0 @@ -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 deleted file mode 100644 index 06da2d21..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/java/vo.java.vm +++ /dev/null @@ -1,61 +0,0 @@ -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 deleted file mode 100644 index 1df6ef37..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/js/api.js.vm +++ /dev/null @@ -1,47 +0,0 @@ -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 deleted file mode 100644 index f6638be5..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/sql/oracle/sql.vm +++ /dev/null @@ -1,19 +0,0 @@ --- 菜单 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 deleted file mode 100644 index 09233923..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/sql/postgres/sql.vm +++ /dev/null @@ -1,20 +0,0 @@ --- 菜单 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 deleted file mode 100644 index 01824c27..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/sql/sql.vm +++ /dev/null @@ -1,19 +0,0 @@ --- 菜单 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 deleted file mode 100644 index bdf166e5..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/sql/sqlserver/sql.vm +++ /dev/null @@ -1,19 +0,0 @@ --- 菜单 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 deleted file mode 100644 index ee309bc7..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/ts/api.ts.vm +++ /dev/null @@ -1,48 +0,0 @@ -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 deleted file mode 100644 index 99359e02..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/ts/types.ts.vm +++ /dev/null @@ -1,44 +0,0 @@ -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 deleted file mode 100644 index dbfa4b98..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/vue/index-tree.vue.vm +++ /dev/null @@ -1,501 +0,0 @@ - - - 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 deleted file mode 100644 index ace3446b..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/vue/index.vue.vm +++ /dev/null @@ -1,467 +0,0 @@ - - - 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 deleted file mode 100644 index 9fb48d99..00000000 --- a/iot-module/iot-generator/src/main/resources/vm/xml/mapper.xml.vm +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/iot-module/iot-manager/pom.xml b/iot-module/iot-manager/pom.xml index 719e9f3f..e5ceff32 100644 --- a/iot-module/iot-manager/pom.xml +++ b/iot-module/iot-manager/pom.xml @@ -15,7 +15,7 @@ cc.iotkit - iot-common-model + iot-data-model @@ -93,26 +93,11 @@ spring-boot-starter-web - - joda-time - joda-time - - io.github.linpeilie mapstruct-plus-spring-boot-starter - - com.aliyun.oss - aliyun-sdk-oss - - - - io.github.linpeilie - mapstruct-plus - - 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 index cadbbef5..9b1e1f1b 100644 --- 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 @@ -18,6 +18,7 @@ import cn.dev33.satoken.annotation.SaCheckPermission; import cn.hutool.core.util.ObjectUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import jakarta.validation.Valid; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; @@ -25,7 +26,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; -import javax.validation.Valid; /** * @Author: 石恒 diff --git a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/protocolcomponent/ProtocolComponentBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/protocolcomponent/ProtocolComponentBo.java deleted file mode 100644 index 8d61482b..00000000 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/protocolcomponent/ProtocolComponentBo.java +++ /dev/null @@ -1,70 +0,0 @@ -package cc.iotkit.manager.dto.bo.protocolcomponent; - -import cc.iotkit.common.api.BaseDto; -import cc.iotkit.model.protocol.ProtocolComponent; -import io.github.linpeilie.annotations.AutoMapper; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import jakarta.validation.constraints.Size; -import lombok.Data; -import lombok.EqualsAndHashCode; - - -@ApiModel(value = "ProtocolComponentBo") -@Data -@EqualsAndHashCode(callSuper = true) -@AutoMapper(target = ProtocolComponent.class, reverseConvertGenerate = false) -public class ProtocolComponentBo extends BaseDto { - private static final long serialVersionUID = -1L; - - @ApiModelProperty(value = "") - private String id; - - @ApiModelProperty(value = "") - @Size(max = 65535, message = "长度不正确") - private String config; - - @ApiModelProperty(value = "转换器类型") - @Size(max = 255, message = "转换器类型长度不正确") - private String converType; - - @ApiModelProperty(value = "转换脚本") - @Size(max = 255, message = "转换脚本长度不正确") - private String converter; - - @ApiModelProperty(value = "创建时间") - private Long createAt; - - @ApiModelProperty(value = "jar包") - @Size(max = 255, message = "jar包长度不正确") - private String jarFile; - - @ApiModelProperty(value = "组件名称") - @Size(max = 255, message = "组件名称长度不正确") - private String name; - - @ApiModelProperty(value = "通讯协议") - @Size(max = 255, message = "通讯协议长度不正确") - private String protocol; - - @ApiModelProperty(value = "脚本内容") - @Size(max = 65535, message = "脚本内容长度不正确") - private String script; - - @ApiModelProperty(value = "通讯脚本语言类型") - @Size(max = 255, message = "通讯脚本语言类型长度不正确") - private String scriptTyp; - - @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/protocolconverter/ProtocolConverterBo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/protocolconverter/ProtocolConverterBo.java deleted file mode 100644 index 73f4855b..00000000 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/bo/protocolconverter/ProtocolConverterBo.java +++ /dev/null @@ -1,52 +0,0 @@ -package cc.iotkit.manager.dto.bo.protocolconverter; - -import cc.iotkit.common.api.BaseDto; -import cc.iotkit.common.validate.AddGroup; -import cc.iotkit.common.validate.EditGroup; -import cc.iotkit.model.protocol.ProtocolConverter; -import io.github.linpeilie.annotations.AutoMapper; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; -import lombok.Data; -import lombok.EqualsAndHashCode; - - -@ApiModel(value = "ProtocolConverterBo") -@Data -@EqualsAndHashCode(callSuper = true) -@AutoMapper(target = ProtocolConverter.class, reverseConvertGenerate = false) -public class ProtocolConverterBo extends BaseDto { - - private static final long serialVersionUID = -1L; - - @ApiModelProperty(value = "id") - @NotBlank(message = "id不能为空", groups = {EditGroup.class}) - private String id; - - @ApiModelProperty(value = "创建时间") - private Long createAt; - - @ApiModelProperty(value = "描述") - @Size(max = 255, message = "描述长度不正确") - private String desc; - - @ApiModelProperty(value = "转换器名称") - @Size(max = 255, message = "转换器名称长度不正确") - @NotBlank(message = "转换器名称不能为空", groups = {AddGroup.class}) - private String name; - - @ApiModelProperty(value = "脚本内容") - @Size(max = 65535, message = "脚本内容长度不正确") - private String script; - - @ApiModelProperty(value = "转换脚本类型") - @Size(max = 255, message = "转换脚本类型长度不正确") - private String typ; - - @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/vo/protocolcomponent/ProtocolComponentVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/protocolcomponent/ProtocolComponentVo.java deleted file mode 100644 index 0292d131..00000000 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/protocolcomponent/ProtocolComponentVo.java +++ /dev/null @@ -1,77 +0,0 @@ -package cc.iotkit.manager.dto.vo.protocolcomponent; - -import cc.iotkit.model.protocol.ProtocolComponent; -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 = "ProtocolComponentVo") -@Data -@ExcelIgnoreUnannotated -@AutoMapper(target = ProtocolComponent.class) - -public class ProtocolComponentVo implements Serializable { - - private static final long serialVersionUID = -1L; - - @ApiModelProperty(value="") - @ExcelProperty(value = "") - private String id; - - @ApiModelProperty(value="") - @ExcelProperty(value = "") - private String config; - - @ApiModelProperty(value="转换器类型") - @ExcelProperty(value = "转换器类型") - private String converType; - - @ApiModelProperty(value="转换脚本") - @ExcelProperty(value = "转换脚本") - private String converter; - - @ApiModelProperty(value="创建时间") - @ExcelProperty(value = "创建时间") - private Long createAt; - - @ApiModelProperty(value="jar包") - @ExcelProperty(value = "jar包") - private String jarFile; - - @ApiModelProperty(value="组件名称") - @ExcelProperty(value = "组件名称") - private String name; - - @ApiModelProperty(value="通讯协议") - @ExcelProperty(value = "通讯协议") - private String protocol; - - @ApiModelProperty(value="脚本内容") - @ExcelProperty(value = "脚本内容") - private String script; - - @ApiModelProperty(value="通讯脚本语言类型") - @ExcelProperty(value = "通讯脚本语言类型") - private String scriptTyp; - - @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/protocolconverter/ProtocolConverterVo.java b/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/protocolconverter/ProtocolConverterVo.java deleted file mode 100644 index b1557dd5..00000000 --- a/iot-module/iot-manager/src/main/java/cc/iotkit/manager/dto/vo/protocolconverter/ProtocolConverterVo.java +++ /dev/null @@ -1,52 +0,0 @@ -package cc.iotkit.manager.dto.vo.protocolconverter; - -import cc.iotkit.model.protocol.ProtocolConverter; -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 = "ProtocolConverterVo") -@Data -@ExcelIgnoreUnannotated -@AutoMapper(target = ProtocolConverter.class) - -public class ProtocolConverterVo implements Serializable { - - private static final long serialVersionUID = -1L; - - @ApiModelProperty(value = "") - @ExcelProperty(value = "") - private String id; - - @ApiModelProperty(value = "创建时间") - @ExcelProperty(value = "创建时间") - private Long createAt; - - @ApiModelProperty(value = "描述") - @ExcelProperty(value = "描述") - private String desc; - - @ApiModelProperty(value = "转换器名称") - @ExcelProperty(value = "转换器名称") - private String name; - - @ApiModelProperty(value = "脚本内容") - @ExcelProperty(value = "脚本内容") - private String script; - - @ApiModelProperty(value = "转换脚本类型") - @ExcelProperty(value = "转换脚本类型") - private String typ; - - @ApiModelProperty(value = "所属性用户id") - @ExcelProperty(value = "所属性用户id") - private String uid; - - -} 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 index 4e45493f..41711656 100644 --- 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 @@ -27,8 +27,6 @@ import cc.iotkit.model.product.Category; import cc.iotkit.model.product.Product; import cc.iotkit.model.product.ProductModel; import cc.iotkit.model.product.ThingModel; -import cc.iotkit.model.protocol.ProtocolComponent; -import cc.iotkit.model.protocol.ProtocolConverter; import cc.iotkit.model.rule.RuleInfo; import cc.iotkit.model.rule.TaskInfo; import cc.iotkit.model.space.Home; @@ -39,7 +37,6 @@ import cc.iotkit.temporal.IDbStructureData; import com.fasterxml.jackson.core.type.TypeReference; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; -import org.hibernate.exception.DataException; import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -76,10 +73,6 @@ public class ExampleDataInit implements SmartInitializingSingleton { @Autowired private IProductModelData productModelData; @Autowired - private IProtocolComponentData protocolComponentData; - @Autowired - private IProtocolConverterData protocolConverterData; - @Autowired private IRuleInfoData ruleInfoData; @Autowired private ISpaceData spaceData; @@ -190,10 +183,6 @@ public class ExampleDataInit implements SmartInitializingSingleton { }); initData("productModel", productModelData, new TypeReference>() { }); - initData("protocolComponent", protocolComponentData, new TypeReference>() { - }); - initData("protocolConverter", protocolConverterData, new TypeReference>() { - }); initData("ruleInfo", ruleInfoData, new TypeReference>() { }); initData("space", spaceData, new TypeReference>() { 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 index fdb32411..be63053f 100644 --- 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 @@ -24,9 +24,6 @@ import cc.iotkit.model.product.ProductModel; import cc.iotkit.model.product.ThingModel; import cc.iotkit.temporal.IDbStructureData; import cn.hutool.core.lang.UUID; -import com.aliyun.oss.OSS; -import com.aliyun.oss.OSSClientBuilder; -import com.aliyun.oss.model.PutObjectResult; import com.github.yitter.idgen.YitIdHelper; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; @@ -76,8 +73,6 @@ public class ProductServiceImpl implements IProductService { @Autowired private IDeviceInfoData deviceInfoData; - private OSS ossClient; - @Override public ProductVo addEntity(ProductBo data) { Product product = data.to(Product.class); @@ -186,26 +181,8 @@ public class ProductServiceImpl implements IProductService { @Override @SneakyThrows - public String uploadImg(String productKey, MultipartFile file) { - String fileName = file.getOriginalFilename(); - if (StringUtils.isBlank(fileName)) { - throw new BizException(ErrCode.FILE_NAME_IS_NULL); - } - String end = fileName.substring(fileName.lastIndexOf(".")); - if (ossClient == null) { - // 创建OSSClient实例。 - ossClient = new OSSClientBuilder().build(aliyunConfig.getEndpoint(), - aliyunConfig.getAccessKeyId(), aliyunConfig.getAccessKeySecret()); - } - - fileName = "product/" + productKey + "/cover" + end; - String bucket = aliyunConfig.getBucketId(); - // 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。 - PutObjectResult result = ossClient.putObject(bucket, fileName, - file.getInputStream()); - return ossClient.generatePresignedUrl(bucket, fileName, - new Date(System.currentTimeMillis() + 3600L * 1000 * 24 * 365 * 10)).toString(); + return ""; } @Override diff --git a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenBaseController.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenAuthController.java similarity index 85% rename from iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenBaseController.java rename to iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenAuthController.java index a5401027..dd37868e 100644 --- a/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenBaseController.java +++ b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/controller/OpenAuthController.java @@ -4,7 +4,6 @@ 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 cc.iotkit.openapi.service.OpenDeviceService; import cn.dev33.satoken.annotation.SaIgnore; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -20,7 +19,7 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j @RestController @RequestMapping("/openapi") -public class OpenBaseController { +public class OpenAuthController { @Autowired private OpenBaseService openBaseService; @@ -28,7 +27,7 @@ public class OpenBaseController { @SaIgnore @ApiOperation(value = "token获取", notes = "token获取", httpMethod = "POST") @PostMapping("/v1/getToken") - public InvokeResult OpenApiGetToken(@RequestBody @Validated Request request) { + 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/dto/bo/TokenVerifyBo.java b/iot-module/iot-openapi/src/main/java/cc/iotkit/openapi/dto/bo/TokenVerifyBo.java index 24696550..cc7ed771 100644 --- 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 @@ -5,7 +5,7 @@ import io.swagger.annotations.ApiModelProperty; import jakarta.validation.constraints.NotBlank; import lombok.Data; -@ApiModel(value = "DeviceConsumerBo") +@ApiModel(value = "TokenVerifyBo") @Data public class TokenVerifyBo { private static final long serialVersionUID = -1L; @@ -14,9 +14,9 @@ public class TokenVerifyBo { @ApiModelProperty(value = "appid") private String appid; - @NotBlank(message = "timeStamp不能为空") + @NotBlank(message = "timestamp不能为空") @ApiModelProperty(value = "时间戳") - private String timeStamp; + private String timestamp; @NotBlank(message = "identifier不能为空") @ApiModelProperty(value = "标识符") @@ -26,5 +26,4 @@ public class TokenVerifyBo { @ApiModelProperty(value = "租户ID") private String tenantId; - } 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 index c5e2e4fc..20d7629c 100644 --- 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 @@ -5,7 +5,6 @@ import cc.iotkit.openapi.dto.bo.device.OpenapiDeviceBo; import cc.iotkit.openapi.dto.vo.OpenDeviceInfoVo; import cc.iotkit.openapi.dto.vo.OpenDevicePropertyVo; -import java.util.Map; /** * @Author: dsy 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 index 1038e1a4..ac82e5fa 100644 --- 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 @@ -3,7 +3,6 @@ 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.enums.LoginType; import cc.iotkit.common.exception.BizException; import cc.iotkit.common.log.event.LogininforEvent; import cc.iotkit.common.satoken.utils.LoginHelper; @@ -19,7 +18,6 @@ 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.secure.BCrypt; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; @@ -48,7 +46,7 @@ public class OpenBaseServiceImpl implements OpenBaseService { public String getToken(TokenVerifyBo bo) { String boAppid = bo.getAppid(); String boIdentifier = bo.getIdentifier(); - String boTimeStamp = bo.getTimeStamp(); + String boTimeStamp = bo.getTimestamp(); // 校验租户 checkTenant(bo.getTenantId()); 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 index 5deecd44..bb87a6b4 100644 --- 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 @@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** + * 插件接口调用入口 + * * @author sjg */ @Slf4j 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 index 788d9c27..34907ac4 100644 --- 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 @@ -15,7 +15,6 @@ import cc.iotkit.model.device.message.ThingModelMessage; import cc.iotkit.model.plugin.PluginInfo; import cc.iotkit.model.product.Product; import cc.iotkit.mq.MqProducer; -import cc.iotkit.plugin.core.IPluginConfig; import cc.iotkit.plugin.core.thing.IDevice; import cc.iotkit.plugin.core.thing.IThingService; import cc.iotkit.plugin.core.thing.actions.ActionResult; @@ -117,6 +116,7 @@ public class PluginMainImpl implements IPluginMain, DeviceService { 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); @@ -141,6 +141,7 @@ public class PluginMainImpl implements IPluginMain, DeviceService { .name(service.getIdentifier()) .params(params) .build(); + //调用插件设备服务接口 result = deviceService.serviceInvoke(action); publish(service, result.getCode()); } else if (ThingService.TYPE_PROPERTY.equals(type)) { @@ -152,6 +153,7 @@ public class PluginMainImpl implements IPluginMain, DeviceService { .deviceName(linkDn) .params(params) .build(); + //调用插件设备服务接口 result = deviceService.propertySet(action); publish(service, result.getCode()); } else if ("get".equals(identifier)) { @@ -162,6 +164,7 @@ public class PluginMainImpl implements IPluginMain, DeviceService { .deviceName(linkDn) .keys(new ArrayList<>(params.keySet())) .build(); + //调用插件设备服务接口 result = deviceService.propertyGet(action); publish(service, result.getCode()); } @@ -173,7 +176,7 @@ public class PluginMainImpl implements IPluginMain, DeviceService { } private void publish(ThingService service, int code) { - //产生下发消息 + //产生下发消息作为下行日志保存 ThingModelMessage message = ThingModelMessage.builder() .mid(service.getMid()) .productKey(service.getProductKey()) 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 index 14c1c1fb..dedc21b5 100644 --- 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 @@ -5,6 +5,7 @@ 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.StringUtils; import cc.iotkit.common.utils.UniqueIdUtil; import cc.iotkit.data.manager.IDeviceInfoData; import cc.iotkit.data.manager.IProductData; @@ -142,9 +143,13 @@ public class ThingServiceImpl implements IThingService { } private void registerDevice(DeviceInfo device, DeviceRegister register) { - Product product = getProduct(register.getProductKey()); - if (product == null) { - throw new BizException(ErrCode.PRODUCT_NOT_FOUND); + String productKey = register.getProductKey(); + //指定了pk需验证 + if (StringUtils.isNotBlank(productKey)) { + Product product = getProduct(productKey); + if (product == null) { + throw new BizException(ErrCode.PRODUCT_NOT_FOUND); + } } if (device != null) { @@ -155,10 +160,10 @@ public class ThingServiceImpl implements IThingService { device = new DeviceInfo(); device.setId(DeviceUtil.newDeviceId(register.getDeviceName())); device.setDeviceId(device.getId()); - device.setProductKey(register.getProductKey()); + device.setProductKey(productKey); device.setDeviceName(register.getDeviceName()); device.setModel(register.getModel()); - device.setSecret(RandomStringUtils.random(16)); + device.setSecret(RandomStringUtils.randomAlphabetic(16)); //默认离线 device.setState(new DeviceInfo.State(false, null, null)); device.setCreateAt(System.currentTimeMillis()); @@ -228,4 +233,5 @@ public class ThingServiceImpl implements IThingService { log.error("send thing model message error", e); } } + } diff --git a/iot-module/iot-rule-engine/pom.xml b/iot-module/iot-rule-engine/pom.xml index 086eb34a..a35105b9 100644 --- a/iot-module/iot-rule-engine/pom.xml +++ b/iot-module/iot-rule-engine/pom.xml @@ -18,7 +18,7 @@ cc.iotkit - iot-common-model + iot-data-model 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 index 1d372174..697c7198 100644 --- 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 @@ -11,15 +11,11 @@ package cc.iotkit.ruleengine.expression; import cc.iotkit.common.enums.ErrCode; import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.utils.JsonUtils; 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 org.graalvm.polyglot.Context; -import org.graalvm.polyglot.HostAccess; -import org.graalvm.polyglot.Value; import java.io.IOException; import java.nio.charset.Charset; 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 index a542fc55..9f8e2bb9 100644 --- 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 @@ -9,14 +9,11 @@ */ package cc.iotkit.ruleengine.handler.sys; -import cc.iotkit.data.manager.IDeviceInfoData; -import cc.iotkit.model.device.DeviceInfo; import cc.iotkit.model.device.message.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.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; @@ -29,18 +26,9 @@ public class DeviceMessageLogHandler implements DeviceMessageHandler { @Lazy @Autowired private IThingModelMessageData thingModelMessageData; - @Autowired - @Qualifier("deviceInfoDataCache") - private IDeviceInfoData deviceInfoData; @Override public void handle(ThingModelMessage msg) { - DeviceInfo device = deviceInfoData.findByDeviceId(msg.getDeviceId()); - if (device == null) { - return; - } - msg.setUid(device.getUid()); - //设备消息入库 thingModelMessageData.add(msg); } diff --git a/iot-module/iot-system/pom.xml b/iot-module/iot-system/pom.xml index c0bb7c28..e9918c9a 100644 --- a/iot-module/iot-system/pom.xml +++ b/iot-module/iot-system/pom.xml @@ -40,7 +40,7 @@ cc.iotkit - iot-common-model + iot-data-model @@ -70,6 +70,11 @@ mapstruct-plus-spring-boot-starter + + org.projectlombok + lombok + + diff --git a/iot-module/pom.xml b/iot-module/pom.xml index 15ef7656..4f6a096a 100644 --- a/iot-module/pom.xml +++ b/iot-module/pom.xml @@ -13,16 +13,12 @@ pom iot-system - iot-baetyl iot-manager iot-rule-engine iot-message-notify - iot-generator iot-screen - iot-contribution iot-openapi iot-plugin - \ No newline at end of file diff --git a/iot-starter/pom.xml b/iot-starter/pom.xml index 3a3d69d1..d1ef4377 100644 --- a/iot-starter/pom.xml +++ b/iot-starter/pom.xml @@ -45,21 +45,6 @@ iot-system - - cc.iotkit - iot-contribution - - - - cc.iotkit - iot-baetyl - - - - cc.iotkit - iot-generator - - cc.iotkit iot-openapi @@ -99,11 +84,6 @@ spring-boot-starter-web - - org.springframework.cloud - spring-cloud-starter-openfeign - - org.springframework.boot spring-boot-starter-logging diff --git a/iot-starter/src/main/java/cc/iotkit/Application.java b/iot-starter/src/main/java/cc/iotkit/Application.java index 480a98d4..87c9538e 100644 --- a/iot-starter/src/main/java/cc/iotkit/Application.java +++ b/iot-starter/src/main/java/cc/iotkit/Application.java @@ -17,7 +17,6 @@ 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.cloud.openfeign.EnableFeignClients; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -25,7 +24,6 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; @SpringBootApplication(scanBasePackages = {"cc.iotkit"}) @EnableTransactionManagement @EnableWebMvc -@EnableFeignClients(basePackages = {"cc.iotkit.baetyl.feign"}) public class Application implements SpringBootstrap { public static void main(String[] args) { 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 index 4da5bcf3..210b152f 100644 --- a/iot-starter/src/main/java/cc/iotkit/web/controller/AuthController.java +++ b/iot-starter/src/main/java/cc/iotkit/web/controller/AuthController.java @@ -2,7 +2,6 @@ package cc.iotkit.web.controller; import cc.iotkit.common.api.Request; import cc.iotkit.common.exception.BizException; -import cc.iotkit.common.tenant.helper.TenantHelper; import cc.iotkit.common.undefined.EmailLoginBody; import cc.iotkit.common.undefined.LoginBody; import cc.iotkit.common.undefined.RegisterBody; @@ -22,7 +21,6 @@ import cn.dev33.satoken.annotation.SaIgnore; import cn.hutool.core.collection.CollUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import jakarta.validation.constraints.NotBlank; import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; @@ -105,22 +103,6 @@ public class AuthController { return loginVo; } - /** - * 小程序登录(示例) - * - * @param xcxCode 小程序code - * @return 结果 - */ - @ApiOperation("小程序登录") - @PostMapping("/xcxLogin") - public LoginVo xcxLogin(@NotBlank(message = "{xcx.code.not.blank}") String xcxCode) { - LoginVo loginVo = new LoginVo(); - // 生成令牌 - String token = loginService.xcxLogin(xcxCode); - loginVo.setToken(token); - return loginVo; - } - /** * 退出登录 */ 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 index 3ce5db87..5eaa3893 100644 --- a/iot-starter/src/main/java/cc/iotkit/web/service/SysLoginService.java +++ b/iot-starter/src/main/java/cc/iotkit/web/service/SysLoginService.java @@ -5,7 +5,6 @@ import cc.iotkit.common.constant.GlobalConstants; import cc.iotkit.common.enums.DeviceType; import cc.iotkit.common.enums.LoginType; import cc.iotkit.common.enums.UserStatus; -import cc.iotkit.common.enums.UserType; import cc.iotkit.common.exception.BizException; import cc.iotkit.common.exception.user.UserException; import cc.iotkit.common.log.event.LogininforEvent; @@ -15,7 +14,6 @@ import cc.iotkit.common.satoken.utils.LoginHelper; import cc.iotkit.common.tenant.helper.TenantHelper; import cc.iotkit.common.undefined.LoginUser; import cc.iotkit.common.undefined.RoleDTO; -import cc.iotkit.common.undefined.XcxLoginUser; import cc.iotkit.common.utils.*; import cc.iotkit.common.web.config.properties.CaptchaProperties; import cc.iotkit.common.web.utils.ServletUtils; @@ -63,15 +61,6 @@ public class SysLoginService { @Value("${user.password.lockTime}") private Integer lockTime; - @Value("${weixin.appid}") - private String appid; - - @Value("${weixin.secret}") - private String secret; - - @Value("${weixin.authUrl}") - private String authUrl; - /** * 登录验证 * @@ -139,35 +128,6 @@ public class SysLoginService { return StpUtil.getTokenValue(); } - - public String xcxLogin(String xcxCode) { - // xcxCode 为 小程序调用 wx.login 授权后获取 - String url=authUrl+"?appid="+appid+"&secret="+secret+"&js_code="+xcxCode+"&grant_type=authorization_code"; - String ret=WeChatUtil.httpRequest(url,"GET",null); - String openid = JsonUtils.parseMap(ret).getStr("openid");; - UserInfo user = null; - try { - user = loadUserByOpenid(openid); - } catch (Exception e) { - e.printStackTrace(); - } - // 校验租户 -// checkTenant(user.getTenantId()); - - // 此处可根据登录用户的数据不同 自行创建 loginUser - XcxLoginUser loginUser = new XcxLoginUser(); - loginUser.setUserId(user.getId()); - loginUser.setUsername(user.getNickName()); - loginUser.setUserType(UserType.APP_USER.getUserType()); - loginUser.setOpenid(openid); - // 生成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(); - } - /** * 退出登录 */ diff --git a/iot-test-tool/iot-virtual-device/pom.xml b/iot-test-tool/iot-virtual-device/pom.xml index eff00986..b07f551b 100644 --- a/iot-test-tool/iot-virtual-device/pom.xml +++ b/iot-test-tool/iot-virtual-device/pom.xml @@ -17,7 +17,7 @@ cc.iotkit - iot-common-model + iot-data-model diff --git a/pom.xml b/pom.xml index d0c80c21..3542e7da 100755 --- a/pom.xml +++ b/pom.xml @@ -21,41 +21,22 @@ pom - iot-common - iot-components + iot-dao iot-module iot-starter iot-test-tool - 0.5.0-SNAPSHOT 11 + 1.0.0 2.7.11 - 2021.0.7 4.2.2 1.34.0 - 21.1.0 1.9.3 - 2.13.1 3.7 - 1.12.400 - 2.11.0 - 1.14 5.8.18 - 3.17.4 - 2.2.4 1.3.1 - 2.14.2 - 5.2.3 - 3.2.1 - 2.3 - 2.7.0 - 1.0.0 - 2.0.9 - 1.1.0.Final - 1.18.26 - 1.0.6 3.1.2 @@ -72,11 +53,9 @@ - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import + io.github.linpeilie + mapstruct-plus-spring-boot-starter + 1.3.1 @@ -84,46 +63,11 @@ commons-beanutils ${beanutils.version} + com.github.yitter yitter-idgenerator - ${yitter.version} - - - - com.fasterxml.jackson.core - jackson-core - ${jackson.version} - - - - org.apache.commons - commons-lang3 - ${lang3.version} - - - - com.amazonaws - aws-java-sdk-s3 - ${aws-java-sdk-s3.version} - - - - commons-io - commons-io - ${io.version} - - - - commons-codec - commons-codec - ${codec.version} - - - - com.alibaba - transmittable-thread-local - ${alibaba-ttl.version} + 1.0.6 @@ -135,13 +79,6 @@ import - - - org.redisson - redisson-spring-boot-starter - ${redisson.version} - - org.projectlombok lombok @@ -154,43 +91,6 @@ 1.8 - - org.bouncycastle - bcprov-jdk15on - 1.57 - - - - - cn.dev33 - sa-token-spring-boot-starter - ${satoken.version} - - - - cn.dev33 - sa-token-dao-redis-jackson - ${satoken.version} - - - - - cn.dev33 - sa-token-jwt - ${satoken.version} - - - cn.hutool - hutool-all - - - - - cn.dev33 - sa-token-core - ${satoken.version} - - jakarta.servlet jakarta.servlet-api @@ -221,36 +121,12 @@ 20.0 - - com.aliyun.oss - aliyun-sdk-oss - 3.10.2 - - co.elastic.clients elasticsearch-java 7.17.9 - - joda-time - joda-time - 2.10.10 - - - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - 1.2.5 - - - - org.luaj - luaj-jse - 3.0.1 - - it.ozimov embedded-redis @@ -269,7 +145,6 @@ 3.1.1 - io.vertx vertx-kafka-client @@ -300,63 +175,6 @@ ${vertx.version} - - - org.graalvm.sdk - graal-sdk - ${graalvm.version} - - - org.graalvm.js - js - ${graalvm.version} - runtime - - - org.graalvm.js - js-scriptengine - ${graalvm.version} - - - - io.github.linpeilie - mapstruct-plus - ${mapstruct-plus.version} - - - io.github.linpeilie - mapstruct-plus-spring-boot-starter - ${mapstruct-plus.version} - - - - com.baomidou - lock4j-redisson-spring-boot-starter - ${lock4j.version} - - - - org.apache.poi - poi - ${poi.version} - - - org.apache.poi - poi-ooxml - ${poi.version} - - - com.alibaba - easyexcel - ${easyexcel.version} - - - org.apache.poi - poi-ooxml-schemas - - - - com.gitee.starblues spring-brick @@ -369,94 +187,77 @@ ${spring-brick.version} - - - org.lionsoul - ip2region - ${ip2region.version} - - - - com.github.biyanwen - jpa-comment-spring-boot-starter - ${jap-comment.version} - com.github.xiaoymin knife4j-spring-boot-starter - ${knife4j.version} - - - javax.validation - validation-api - ${validateion.version} + 2.0.9 - + + io.swagger + swagger-annotations + 1.5.22 + + + cc.iotkit iot-common-core - ${project.version} - - - - cc.iotkit - iot-common-doc - ${project.version} + ${iot-iita-core.version} cc.iotkit iot-common-oss - ${project.version} - - - - cc.iotkit - iot-common-excel - ${project.version} - - - - cc.iotkit - iot-common-log - ${project.version} - - - - cc.iotkit - iot-common-redis - ${project.version} - - - - cc.iotkit - iot-common-satoken - ${project.version} - - - - cc.iotkit - iot-common-tenant - ${project.version} + ${iot-iita-core.version} cc.iotkit iot-common-web - ${project.version} + ${iot-iita-core.version} cc.iotkit - iot-common-websocket - ${project.version} + iot-common-doc + ${iot-iita-core.version} - cc.iotkit - iot-common-model + 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-data-model ${project.version} @@ -518,32 +319,7 @@ cc.iotkit iot-script-engine - ${project.version} - - - - - cc.iotkit - iot-component-base - ${project.version} - - - - cc.iotkit - iot-component-converter - ${project.version} - - - - cc.iotkit - iot-mqtt-component - ${project.version} - - - - cc.iotkit - iot-nb-component - ${project.version} + ${iot-iita-core.version} @@ -552,12 +328,6 @@ ${project.version} - - cc.iotkit - iot-contribution - ${project.version} - - cc.iotkit iot-message-notify @@ -594,17 +364,6 @@ ${project.version} - - cc.iotkit - iot-baetyl - ${project.version} - - - - cc.iotkit - iot-generator - ${project.version} - cc.iotkit iot-virtual-device @@ -623,13 +382,6 @@ ${project.version} - - - - org.apache.velocity - velocity-engine-core - ${velocity.version} -