@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.
- package/README.md +4 -0
- package/app.js +41 -40
- package/backend/common/entity.js +55 -0
- package/backend/common/enum.js +247 -0
- package/backend/common/fss/index.js +18 -0
- package/backend/common/fss/routers/attachment.js +45 -0
- package/backend/common/fss/routers/download.js +43 -0
- package/backend/common/fss/routers/import_export.js +113 -0
- package/backend/common/fss/routers/resources.js +149 -0
- package/backend/common/fss/routers/upload.js +81 -0
- package/backend/common/fss/services/import_export.js +159 -0
- package/backend/common/fss/services/index.js +92 -0
- package/backend/common/fss/utils.js +39 -0
- package/backend/common/ginfo/config.js +5 -0
- package/backend/common/ginfo/index.js +62 -0
- package/backend/common/index_template.html +28 -0
- package/backend/common/logger/index.js +96 -0
- package/backend/common/mapping.js +128 -0
- package/backend/common/middleware/auth.js +109 -0
- package/backend/common/middleware/cors.js +13 -0
- package/backend/common/middleware/response.js +25 -0
- package/backend/common/page_engine.js +487 -0
- package/backend/common/schedule.js +45 -0
- package/backend/common/services/dataCombine.js +67 -0
- package/backend/common/services/dept.js +37 -0
- package/backend/common/services/dict.js +488 -0
- package/backend/common/services/email.js +49 -0
- package/backend/common/services/generalConfig.js +137 -0
- package/backend/common/services/login.js +18 -0
- package/backend/common/services/notice.js +260 -0
- package/backend/common/services/permission.js +500 -0
- package/backend/common/services/roles.js +57 -0
- package/backend/common/services/send-notice.js +86 -0
- package/backend/common/services/task.js +259 -0
- package/backend/common/services/user.js +673 -0
- package/backend/common/socket.js +18 -0
- package/backend/common/sse/index.js +81 -0
- package/backend/common/sse/router.js +30 -0
- package/backend/common/task.js +75 -0
- package/backend/common/wechat/index.js +9 -0
- package/backend/common/wechat/routers/auth.js +238 -0
- package/{modules/user/frontend → backend/common/wechat/routers}/index.html +14 -7
- package/backend/common/wechat/services/auth.js +209 -0
- package/backend/common/wechat/services/notice.js +171 -0
- package/backend/config/index.js +61 -0
- package/backend/config/path.js +3 -0
- package/backend/router.js +100 -0
- package/backend/routers/app.js +222 -0
- package/backend/routers/automate.js +276 -0
- package/backend/routers/dict.js +370 -0
- package/backend/routers/email.js +85 -0
- package/backend/routers/generalConfig.js +276 -0
- package/backend/routers/idm.js +245 -0
- package/backend/routers/module.js +357 -0
- package/backend/routers/notice.js +138 -0
- package/backend/routers/pages.js +46 -0
- package/backend/routers/permission.js +985 -0
- package/backend/routers/setting.js +184 -0
- package/backend/routers/team/index.js +22 -0
- package/backend/routers/team/routers/mapping.js +29 -0
- package/backend/routers/team/routers/member.js +72 -0
- package/backend/routers/team/routers/membermanage.js +289 -0
- package/backend/routers/team/routers/pages.js +47 -0
- package/backend/routers/team/routers/roles.js +92 -0
- package/backend/routers/team/routers/teaminfo.js +27 -0
- package/backend/routers/team/routers/usergroup.js +213 -0
- package/backend/routers/team/services/mapping.js +101 -0
- package/backend/routers/team/services/member.js +206 -0
- package/backend/routers/team/services/roles.js +71 -0
- package/backend/routers/team/services/teaminfo.js +20 -0
- package/backend/routers/team/services/usergroup.js +128 -0
- package/backend/routers/user.js +436 -0
- package/backend/services/automate.js +60 -0
- package/backend/services/config.js +14 -0
- package/backend/services/module.js +298 -0
- package/backend/services/permission.js +192 -0
- package/backend/services/services.js +115 -0
- package/backend/services/setting.js +190 -0
- package/backend/services/token.js +42 -0
- package/backend/space.js +52 -0
- package/backend/space_mapping.js +22 -0
- package/backend/utils/avatar.js +48 -0
- package/backend/utils/color_gen_helper.js +20 -0
- package/backend/utils/date.js +66 -0
- package/backend/utils/excel.js +446 -0
- package/backend/utils/fs/doc.md +64 -0
- package/backend/utils/fs/index.js +127 -0
- package/backend/utils/jwt.js +54 -0
- package/backend/utils/modules/sequence.js +93 -0
- package/backend/utils/object.js +31 -0
- package/backend/utils/page-query-helper/index.js +61 -0
- package/backend/utils/path.js +123 -0
- package/backend/utils/run.js +25 -0
- package/backend/utils/tokenize.js +82 -0
- package/backend/utils/typeof.js +5 -0
- package/backend/utils/util.js +153 -0
- package/backend/views/api/index.js +32 -0
- package/backend/views/api/index.xml +49 -0
- package/backend/views/dict/index.js +80 -0
- package/backend/views/dict/index.xml +52 -0
- package/backend/views/index.js +32 -0
- package/backend/views/members_manage/index.js +68 -0
- package/backend/views/members_manage/index.xml +68 -0
- package/backend/views/roles/index.js +17 -0
- package/backend/views/roles/index.xml +47 -0
- package/backend/views/usergroup/index.js +68 -0
- package/backend/views/usergroup/index.xml +65 -0
- package/dist/base-assets/css/index-ffdb55a5.css +3 -0
- package/dist/base-assets/css/index-ffdb55a5.css.gz +0 -0
- package/dist/base-assets/js/index-b3998a47.js +762 -0
- package/dist/base-assets/js/index-b3998a47.js.gz +0 -0
- package/dist/base-assets/js/react-cropper.es-d5f06996.js +10 -0
- package/dist/base-assets/js/react-cropper.es-d5f06996.js.gz +0 -0
- package/dist/base-assets/png/u9-2348c304.png +0 -0
- package/dist/base-assets/woff2/materialicons-83be7b2f.woff2 +0 -0
- package/dist/index.html +162 -0
- package/package.json +62 -5
- package/common/router.js +0 -42
- package/modules/user/backend/index.js +0 -19
- package/modules/user/backend/routers/user.js +0 -11
- package/modules/user/frontend/index.js +0 -1
- 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
|
+
};
|