@gingkoo/base-server 0.0.1-alpha.0 → 0.0.1-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/README.md +4 -0
  2. package/app.js +41 -40
  3. package/backend/common/entity.js +55 -0
  4. package/backend/common/enum.js +247 -0
  5. package/backend/common/fss/index.js +18 -0
  6. package/backend/common/fss/routers/attachment.js +45 -0
  7. package/backend/common/fss/routers/download.js +43 -0
  8. package/backend/common/fss/routers/import_export.js +113 -0
  9. package/backend/common/fss/routers/resources.js +149 -0
  10. package/backend/common/fss/routers/upload.js +81 -0
  11. package/backend/common/fss/services/import_export.js +159 -0
  12. package/backend/common/fss/services/index.js +92 -0
  13. package/backend/common/fss/utils.js +39 -0
  14. package/backend/common/ginfo/config.js +5 -0
  15. package/backend/common/ginfo/index.js +62 -0
  16. package/backend/common/index_template.html +28 -0
  17. package/backend/common/logger/index.js +96 -0
  18. package/backend/common/mapping.js +128 -0
  19. package/backend/common/middleware/auth.js +109 -0
  20. package/backend/common/middleware/cors.js +13 -0
  21. package/backend/common/middleware/response.js +25 -0
  22. package/backend/common/page_engine.js +487 -0
  23. package/backend/common/schedule.js +45 -0
  24. package/backend/common/services/dataCombine.js +67 -0
  25. package/backend/common/services/dept.js +37 -0
  26. package/backend/common/services/dict.js +488 -0
  27. package/backend/common/services/email.js +49 -0
  28. package/backend/common/services/generalConfig.js +137 -0
  29. package/backend/common/services/login.js +18 -0
  30. package/backend/common/services/notice.js +260 -0
  31. package/backend/common/services/permission.js +500 -0
  32. package/backend/common/services/roles.js +57 -0
  33. package/backend/common/services/send-notice.js +86 -0
  34. package/backend/common/services/task.js +259 -0
  35. package/backend/common/services/user.js +673 -0
  36. package/backend/common/socket.js +18 -0
  37. package/backend/common/sse/index.js +81 -0
  38. package/backend/common/sse/router.js +30 -0
  39. package/backend/common/task.js +75 -0
  40. package/backend/common/wechat/index.js +9 -0
  41. package/backend/common/wechat/routers/auth.js +238 -0
  42. package/{modules/user/frontend → backend/common/wechat/routers}/index.html +14 -7
  43. package/backend/common/wechat/services/auth.js +209 -0
  44. package/backend/common/wechat/services/notice.js +171 -0
  45. package/backend/config/index.js +61 -0
  46. package/backend/config/path.js +3 -0
  47. package/backend/router.js +100 -0
  48. package/backend/routers/app.js +222 -0
  49. package/backend/routers/automate.js +276 -0
  50. package/backend/routers/dict.js +370 -0
  51. package/backend/routers/email.js +85 -0
  52. package/backend/routers/generalConfig.js +276 -0
  53. package/backend/routers/idm.js +245 -0
  54. package/backend/routers/module.js +357 -0
  55. package/backend/routers/notice.js +138 -0
  56. package/backend/routers/pages.js +46 -0
  57. package/backend/routers/permission.js +985 -0
  58. package/backend/routers/setting.js +184 -0
  59. package/backend/routers/team/index.js +22 -0
  60. package/backend/routers/team/routers/mapping.js +29 -0
  61. package/backend/routers/team/routers/member.js +72 -0
  62. package/backend/routers/team/routers/membermanage.js +289 -0
  63. package/backend/routers/team/routers/pages.js +47 -0
  64. package/backend/routers/team/routers/roles.js +92 -0
  65. package/backend/routers/team/routers/teaminfo.js +27 -0
  66. package/backend/routers/team/routers/usergroup.js +213 -0
  67. package/backend/routers/team/services/mapping.js +101 -0
  68. package/backend/routers/team/services/member.js +206 -0
  69. package/backend/routers/team/services/roles.js +71 -0
  70. package/backend/routers/team/services/teaminfo.js +20 -0
  71. package/backend/routers/team/services/usergroup.js +128 -0
  72. package/backend/routers/user.js +436 -0
  73. package/backend/services/automate.js +60 -0
  74. package/backend/services/config.js +14 -0
  75. package/backend/services/module.js +298 -0
  76. package/backend/services/permission.js +192 -0
  77. package/backend/services/services.js +115 -0
  78. package/backend/services/setting.js +190 -0
  79. package/backend/services/token.js +42 -0
  80. package/backend/space.js +52 -0
  81. package/backend/space_mapping.js +22 -0
  82. package/backend/utils/avatar.js +48 -0
  83. package/backend/utils/color_gen_helper.js +20 -0
  84. package/backend/utils/date.js +66 -0
  85. package/backend/utils/excel.js +446 -0
  86. package/backend/utils/fs/doc.md +64 -0
  87. package/backend/utils/fs/index.js +127 -0
  88. package/backend/utils/jwt.js +54 -0
  89. package/backend/utils/modules/sequence.js +93 -0
  90. package/backend/utils/object.js +31 -0
  91. package/backend/utils/page-query-helper/index.js +61 -0
  92. package/backend/utils/path.js +123 -0
  93. package/backend/utils/run.js +25 -0
  94. package/backend/utils/tokenize.js +82 -0
  95. package/backend/utils/typeof.js +5 -0
  96. package/backend/utils/util.js +153 -0
  97. package/backend/views/api/index.js +32 -0
  98. package/backend/views/api/index.xml +49 -0
  99. package/backend/views/dict/index.js +80 -0
  100. package/backend/views/dict/index.xml +52 -0
  101. package/backend/views/index.js +32 -0
  102. package/backend/views/members_manage/index.js +68 -0
  103. package/backend/views/members_manage/index.xml +68 -0
  104. package/backend/views/roles/index.js +17 -0
  105. package/backend/views/roles/index.xml +47 -0
  106. package/backend/views/usergroup/index.js +68 -0
  107. package/backend/views/usergroup/index.xml +65 -0
  108. package/dist/base-assets/css/index-ffdb55a5.css +3 -0
  109. package/dist/base-assets/css/index-ffdb55a5.css.gz +0 -0
  110. package/dist/base-assets/js/index-b3998a47.js +762 -0
  111. package/dist/base-assets/js/index-b3998a47.js.gz +0 -0
  112. package/dist/base-assets/js/react-cropper.es-d5f06996.js +10 -0
  113. package/dist/base-assets/js/react-cropper.es-d5f06996.js.gz +0 -0
  114. package/dist/base-assets/png/u9-2348c304.png +0 -0
  115. package/dist/base-assets/woff2/materialicons-83be7b2f.woff2 +0 -0
  116. package/dist/index.html +162 -0
  117. package/package.json +62 -5
  118. package/common/router.js +0 -42
  119. package/modules/user/backend/index.js +0 -19
  120. package/modules/user/backend/routers/user.js +0 -11
  121. package/modules/user/frontend/index.js +0 -1
  122. package/serve.js +0 -9
@@ -0,0 +1,260 @@
1
+ 'use strict';
2
+
3
+ const { v4: uuidv4 } = require('uuid');
4
+ const moment = require('dayjs');
5
+
6
+ const {
7
+ sqlExecutor,
8
+ queryParamsBuilder,
9
+ insertSqlBuilder,
10
+ updateSqlBuilder,
11
+ } = require('@gingkoo/node-tools');
12
+ const entity = require('../entity');
13
+ const { message: messageConstant } = require('../enum');
14
+ const { logger } = require('../logger');
15
+
16
+ module.exports = {
17
+ //用户通知权限
18
+ /**
19
+ * @param {*} filters 查询条件
20
+ * @returns
21
+ */
22
+ getUserPermission: async function (filters) {
23
+ if (!filters) return;
24
+ let sql = `select * FROM ${entity.NOTICE_USER_PERMISSION} WHERE `;
25
+ let params = queryParamsBuilder(filters);
26
+ let { error, results } = await sqlExecutor(sql + params.sql, params.params);
27
+ if (error) {
28
+ return null;
29
+ }
30
+ return results;
31
+ },
32
+
33
+ //创建通知权限
34
+ postUserPermission: async function (prosp) {
35
+ let DATA_ID = uuidv4().replaceAll('-', '');
36
+ let params = {
37
+ ...prosp,
38
+ ORG_ID: global.orgid,
39
+ DATA_ID,
40
+ STATUS: '00', //默认正常订阅
41
+ };
42
+ let sqlResult = insertSqlBuilder(entity.NOTICE_USER_PERMISSION, params);
43
+ let { error, results } = await sqlExecutor(sqlResult.sql, sqlResult.params);
44
+ if (error) {
45
+ return null;
46
+ }
47
+ return results;
48
+ },
49
+
50
+ /***
51
+ * @param {*} props 修改内容
52
+ * @param {*} filters 过滤条件
53
+ */
54
+ putUserPermission: async function (props, filters) {
55
+ let sqlResult = updateSqlBuilder(entity.NOTICE_USER_PERMISSION, props, filters);
56
+
57
+ let { error, results } = await sqlExecutor(sqlResult.sql, sqlResult.params);
58
+ if (error) {
59
+ return null;
60
+ }
61
+ return results;
62
+ },
63
+
64
+ /**
65
+ * @param {string[]} dictList? 指定码表查询
66
+ *
67
+ */
68
+ async getNoticeDict(dictList) {
69
+ dictList = Array.isArray(dictList) ? dictList : [];
70
+ let dictids = `'${dictList.join("','")}'`;
71
+ let { error, results } = await sqlExecutor(
72
+ `select * from ${entity.BASE_DICT_ITEMS} where ORG_ID=? ${
73
+ dictList.length ? `and DICT_ID in (${dictids})` : ''
74
+ } order by ORD_NO asc`,
75
+ [global.orgid],
76
+ );
77
+ if (error) {
78
+ logger.error(error);
79
+ return null;
80
+ }
81
+ let data = {};
82
+ results.forEach((element) => {
83
+ if (!data.hasOwnProperty(element.DICT_ID)) {
84
+ data[element.DICT_ID] = [];
85
+ }
86
+ data[element.DICT_ID].push({
87
+ value: element.ITEM_ID,
88
+ label: element.ITEM_VALUE,
89
+ icon: element.ITEM_ICON || '',
90
+ style: element.ITEM_STYLE || '',
91
+ color: element.ITEM_COLOR || '',
92
+ desc: element.ITEM_DESC || '',
93
+ parent: element.ITEM_PARENT || '',
94
+ });
95
+ });
96
+ return data;
97
+ },
98
+
99
+ // 获取用户通知数据
100
+ getNotices: async function (userid) {
101
+ let dbResult = await sqlExecutor(
102
+ `select n.*, i.AVATAR, i.USER_NAME from ${entity.NOTICE_LOG} n join idm_users i on n.NOT_USER_ID=i.USER_ID where n.ORG_ID=? and n.STATUS=? and n.RECEIVE_USER=? order by n.DATA_CRT_TIME+0 desc`,
103
+ [global.orgid, messageConstant.NOT_STATUS.normal, userid],
104
+ );
105
+ if (dbResult.error) {
106
+ console.log(dbResult.error);
107
+ return null;
108
+ }
109
+ return dbResult.results;
110
+ },
111
+ /**
112
+ * 修改通知数据
113
+ * @param {*} params 修改内容
114
+ * @param {*} filters 修改条件
115
+ * @returns
116
+ */
117
+ updateNotice: async function (params, filters) {
118
+ if (!Object.keys(filters)?.length) {
119
+ return null;
120
+ }
121
+ let sqlResult = updateSqlBuilder(entity.NOTICE_LOG, params, filters);
122
+ let dbResult = await sqlExecutor(sqlResult.sql, sqlResult.params);
123
+ if (dbResult.error) {
124
+ console.log(dbResult.error);
125
+ return null;
126
+ }
127
+ return true;
128
+ },
129
+
130
+ // 删除通知数据
131
+ deleteNotice: async function (filters) {
132
+ if (!Object.keys(filters)?.length) {
133
+ return null;
134
+ }
135
+ let sqlResult = updateSqlBuilder(
136
+ entity.NOTICE_LOG,
137
+ { STATUS: messageConstant.NOT_STATUS.notdel },
138
+ filters,
139
+ );
140
+ let dbResult = await sqlExecutor(sqlResult.sql, sqlResult.params);
141
+ if (dbResult.error) {
142
+ console.log(dbResult.error);
143
+ return null;
144
+ }
145
+ return true;
146
+ },
147
+ /**
148
+ * 添加通知数据
149
+ */
150
+ createNotice: async function (userid, props) {
151
+ let NOT_ID = uuidv4().replaceAll('-', '');
152
+ let params = {
153
+ ...props,
154
+ NOT_ID,
155
+ ORG_ID: global.orgid,
156
+ RECEIVE_USER: userid,
157
+ SEND_DATE: moment().format('YYYYMMDDHHmmss'),
158
+ STATUS: messageConstant.NOT_STATUS.normal, //默认正常订阅
159
+ IS_READ: messageConstant.NOT_IS_READ.unread, //默认未读
160
+ };
161
+ let sqlResult = insertSqlBuilder(entity.NOTICE_LOG, params);
162
+ let dbResult = await sqlExecutor(sqlResult.sql, sqlResult.params);
163
+ if (dbResult.error) {
164
+ console.log(dbResult.error);
165
+ return null;
166
+ }
167
+ return NOT_ID;
168
+ },
169
+
170
+ // 企业微信通知
171
+
172
+ // 任务消息通知
173
+
174
+ /**
175
+ * @param {Array<string>} toUsers 要通知的角色
176
+ * @param {string} content 通知内容
177
+ * @param {string} link 跳转链接
178
+ * @param {string} type 通知类型
179
+ * @param {string} title 通知标题
180
+ * @param {string} sender 发送人
181
+ *
182
+ */
183
+ notice: async function ({ toUsers, content, link, title, sender, type }) {
184
+ if (!Array.isArray(toUsers) || !content) return;
185
+ // let web = new WebSocket();
186
+ Promise.all(
187
+ toUsers.map(async (v) => {
188
+ await this.createNotice(v, {
189
+ NOT_TITLE: title,
190
+ NOT_LINK: link,
191
+ NOT_TYPE: type || 'issue_update',
192
+ NOT_CONTENT: content,
193
+ NOT_USER_ID: sender,
194
+ });
195
+ }),
196
+ );
197
+ },
198
+
199
+ /**
200
+ * 通知权限 渠道 权限
201
+ * @param {obj} map 通知内容
202
+ * 例:obj={
203
+ * [数据字典<通知内容>]: 用户ID,用户ID,用户ID
204
+ * }
205
+ * @returns {
206
+ * error:string|null
207
+ * qywx:Array<string>
208
+ * email:Array<string>
209
+ * taems:Array<string>
210
+ * }
211
+ */
212
+ noticeChannel: async function (obj, userid) {
213
+ if (!typeof obj == 'object') return { error: '参数错误' };
214
+ const { CHANNEL } = await this.getNoticeDict(['CHANNEL']);
215
+ if (!Array.isArray(CHANNEL)) return { error: '字典查询错误' };
216
+ let channel = {};
217
+
218
+ //获取渠道mapping
219
+ CHANNEL.map((v) => {
220
+ if (v.value) channel[v.value] = [];
221
+ });
222
+
223
+ //获取通知内容 查看是否通知
224
+ await Promise.all(
225
+ Object.keys(obj).map(async (type) => {
226
+ if (!typeof obj[type] == 'string') return;
227
+ let users = obj[type].split(',');
228
+ //查看 哪些渠道不通知
229
+
230
+ await Promise.all(
231
+ users.map(async (user) => {
232
+ if (user == userid) return;
233
+ //在那渠道 的内容不通知
234
+ let data = await this.getUserPermission({
235
+ IS_NOTICE: '01',
236
+ USER_ID: user,
237
+ NOT_TYPE: type,
238
+ });
239
+
240
+ //在那渠道 的内容不通知
241
+ if (Array.isArray(data)) {
242
+ let not = data.map((v) => {
243
+ return v.CHANNEL;
244
+ });
245
+ Object.keys(channel).map((key) => {
246
+ if (!channel[key]) return;
247
+ if (not.includes(key) || channel[key].includes(user)) return;
248
+ channel[key].push(user);
249
+ });
250
+ }
251
+ }),
252
+ );
253
+ }),
254
+ );
255
+ return {
256
+ error: null,
257
+ ...channel,
258
+ };
259
+ },
260
+ };