doomiwork 4.1.10 → 4.2.1
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/dist/index.esm.js +1 -0
- package/dist/index.js +1 -0
- package/package.json +22 -7
- package/configuration/appsetting.js +0 -42
- package/configuration/dataconfig.js +0 -55
- package/configuration/routerconfig.js +0 -144
- package/core/actionresult.js +0 -30
- package/core/controller.js +0 -380
- package/core/database/daoBase.js +0 -352
- package/core/database/mysqlbase.js +0 -173
- package/core/database/poolmanager.js +0 -15
- package/core/doomiwork.js +0 -76
- package/core/enumconst.js +0 -52
- package/index.js +0 -13
- package/utilities/excelutility.js +0 -202
- package/utilities/keywordparse.js +0 -115
- package/utilities/requestparser-bak.js +0 -163
- package/utilities/requestparser.js +0 -250
- package/utilities/tokenutility.js +0 -45
- package/utilities/transferutility.js +0 -105
package/core/database/daoBase.js
DELETED
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 封装了数据访问层的基础访问
|
|
3
|
-
* Author : Stephen.Shen
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const dao = require('./mysqlbase');
|
|
7
|
-
const Moment = require('moment')
|
|
8
|
-
class mysqlDao extends dao{
|
|
9
|
-
/**
|
|
10
|
-
* 构造函数,确定使用的数据库链接
|
|
11
|
-
* @param {{
|
|
12
|
-
* database
|
|
13
|
-
* permissiondatatype
|
|
14
|
-
* permission
|
|
15
|
-
* tableName:string
|
|
16
|
-
* primaryKey:string
|
|
17
|
-
* forcefilter:string
|
|
18
|
-
* logicDelete:boolean
|
|
19
|
-
* logicDeleteField:string
|
|
20
|
-
* business:{
|
|
21
|
-
* code: string
|
|
22
|
-
* name: string
|
|
23
|
-
* }
|
|
24
|
-
* }} tableoption
|
|
25
|
-
* {
|
|
26
|
-
* permission:数据的权限 0:无需权限控制 1:控制权限
|
|
27
|
-
* permissiondatatype:权限控制的业务数据类型
|
|
28
|
-
* tableName:操作的数据表名称
|
|
29
|
-
* primaryKey: 表的主键名称
|
|
30
|
-
* logicDelete:表记录是否逻辑删除,默认逻辑删除
|
|
31
|
-
* logicDeleteField:代表逻辑删除的字段名称
|
|
32
|
-
* forcefilter:强制添加的sql附加语法,会添加在根据主键获取、修改、删除的尾部,加强操作的安全性验证
|
|
33
|
-
* }
|
|
34
|
-
*/
|
|
35
|
-
constructor(tableoption){
|
|
36
|
-
//super(appsetting.getConnection('dev'));
|
|
37
|
-
super(tableoption ? (tableoption.database || 'dev') : 'dev');
|
|
38
|
-
if (tableoption){
|
|
39
|
-
tableoption.forcefilter=tableoption.forcefilter || '';
|
|
40
|
-
this.tableoption = tableoption;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 数据对象是否存在权限因子控制
|
|
45
|
-
*/
|
|
46
|
-
get hasPermissionControl(){
|
|
47
|
-
if (!this.tableoption) return false;
|
|
48
|
-
return this.tableoption.permission && !isNaN(this.tableoption.permissiondatatype);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* 获取列表的权限控制Sql条件
|
|
52
|
-
*/
|
|
53
|
-
get permissionSql(){
|
|
54
|
-
if (this.hasPermissionControl){
|
|
55
|
-
const leftjoin = `left join vmv3_data_permission vp on vp.data_type = ${this.tableoption.permissiondatatype}
|
|
56
|
-
and ${this.tableoption.primaryKey} = vp.data_id
|
|
57
|
-
and vp.permission_type = 2`
|
|
58
|
-
return `
|
|
59
|
-
if (ifnull(vp.data_department, '') = '', ' and 1 = 1 ', ' and find_in_set('@user.department@',vp.data_department)')
|
|
60
|
-
if (ifnull(vp.data_role, '') = '', ' and 1 = 1 ', ' and find_in_set('@user.role@',vp.data_role)')
|
|
61
|
-
if (ifnull(vp.data_department, '') = '', ' and 1 = 1 ', ' and find_in_set('@user.id @',vp.data_user)')
|
|
62
|
-
`
|
|
63
|
-
}
|
|
64
|
-
return '';
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* 返回本数据实体对应的业务名称
|
|
68
|
-
*/
|
|
69
|
-
getBusiness(){
|
|
70
|
-
if (this.tableoption) return this.tableoption.business;
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* 通过sql获取数据
|
|
75
|
-
* @param {*} sqlString
|
|
76
|
-
* @param {*} parameters
|
|
77
|
-
*/
|
|
78
|
-
async loadData(sqlString, parameters){
|
|
79
|
-
return this.executeSql(sqlString, parameters);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
*
|
|
83
|
-
* @returns {string}
|
|
84
|
-
* @summary 根据主键获取数据
|
|
85
|
-
*/
|
|
86
|
-
getByIdSql(){
|
|
87
|
-
return `select * from ${this.tableoption.tableName} where ${this.tableoption.primaryKey}=? ${this.tableoption.forcefilter}`;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* 更改记录
|
|
91
|
-
*/
|
|
92
|
-
updateSql(id) {
|
|
93
|
-
return `update ${this.tableoption.tableName} set ? where ${this.tableoption.primaryKey}=? ${this.tableoption.forcefilter}`;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* 新增记录
|
|
97
|
-
*/
|
|
98
|
-
insertSql() {
|
|
99
|
-
return `insert into ${this.tableoption.tableName} set ?`;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 删除记录
|
|
103
|
-
*/
|
|
104
|
-
deleteSql() {
|
|
105
|
-
// const ids = (id + '').trim().split(',').map(x => '\'' + x + '\'');
|
|
106
|
-
////如果是逻辑删除,则只将记录的删除状态设置为1
|
|
107
|
-
if(this.tableoption.logicDelete) {
|
|
108
|
-
|
|
109
|
-
let sqlDelete = `update ${this.tableoption.tableName} set #DELETEBY# #DELETEDATE# ${this.tableoption.logicDeleteField || 'rec_isdeleted'} =1 where ${this.tableoption.primaryKey} =? ${this.tableoption.forcefilter}`;
|
|
110
|
-
sqlDelete = sqlDelete.replace('#DELETEBY#', this.tableoption.logDeleteBy?`${this.tableoption.logDeleteBy}=?,`:'')
|
|
111
|
-
sqlDelete = sqlDelete.replace('#DELETEDATE#', this.tableoption.logDeleteDate ? `${this.tableoption.logDeleteDate}=now(),` : '');
|
|
112
|
-
return sqlDelete;
|
|
113
|
-
}
|
|
114
|
-
return `delete from ${this.tableoption.tableName} where ${this.tableoption.primaryKey} =? ${this.tableoption.forcefilter}`;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* 批量操作Sql
|
|
119
|
-
*/
|
|
120
|
-
BatchSql() {
|
|
121
|
-
return `update ${this.tableoption.tableName} set ? where find_in_set(${this.tableoption.primaryKey},?) ${this.tableoption.forcefilter}`;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
///根据主键获取一条记录
|
|
125
|
-
async getBykey(Sql, id) {return this.executeSql(Sql, id);}
|
|
126
|
-
///插入记录
|
|
127
|
-
async create(Sql, model) {return this.executeSql(Sql, model);}
|
|
128
|
-
///更新记录
|
|
129
|
-
async update(Sql, model, id) {return this.executeSql(Sql, [model, id]);}
|
|
130
|
-
///删除记录
|
|
131
|
-
async delete(Sql, id,userid) {
|
|
132
|
-
const ids = (id + '').trim().split(',').map(x => '\'' + x + '\'');
|
|
133
|
-
if (this.tableoption.logicDelete && this.tableoption.logDeleteBy){
|
|
134
|
-
return this.executeSql(Sql, [userid, id]); //ids.join(',')]);
|
|
135
|
-
}
|
|
136
|
-
return this.executeSql(Sql, id); //ids.join(','));
|
|
137
|
-
///
|
|
138
|
-
//return this.executeSql(Sql, id);
|
|
139
|
-
/*if (result.successed && this.tableoption.logicDelete && userid && (this.tableoption.logDeleteBy || this.tableoption.logDeleteDate)){
|
|
140
|
-
let sqlLog = `update ${this.tableoption.tableName} set ? where ${this.tableoption.primaryKey}=? ${this.tableoption.forcefilter}`;
|
|
141
|
-
let model = {};
|
|
142
|
-
if (this.tableoption.logDeleteBy){
|
|
143
|
-
model[this.tableoption.logDeleteBy] = userid;
|
|
144
|
-
}
|
|
145
|
-
if (this.tableoption.logDeleteDate){
|
|
146
|
-
model[this.tableoption.logDeleteDate] = Moment().format('YYYY-MM-DD HH:mm:ss');
|
|
147
|
-
}
|
|
148
|
-
if (Object.keys(model).length>0) this.executeSql(sqlLog, [model, id]);
|
|
149
|
-
}
|
|
150
|
-
return result;
|
|
151
|
-
*/
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* 获取对应数据的权限设置
|
|
155
|
-
* @param {*} id
|
|
156
|
-
*/
|
|
157
|
-
async getDataPermissionSetting(id,busSql){
|
|
158
|
-
///没有权限控制,则无需获取单条数据的权限因子
|
|
159
|
-
if (!this.hasPermissionControl){
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
// const sqlCommand = `select
|
|
163
|
-
// data_type as datatype,
|
|
164
|
-
// data_id as id,
|
|
165
|
-
// permission_type as permissiontype,
|
|
166
|
-
// data_department as department,
|
|
167
|
-
// data_department_text as departmenttext,
|
|
168
|
-
// data_role as role,
|
|
169
|
-
// data_role_text as roletext,
|
|
170
|
-
// data_level as level,
|
|
171
|
-
// data_level_text as leveltext,
|
|
172
|
-
// data_user as user,
|
|
173
|
-
// data_user_text as usertext
|
|
174
|
-
// from vmv3_data_permission
|
|
175
|
-
// where data_type=?
|
|
176
|
-
// and data_id=?
|
|
177
|
-
// `
|
|
178
|
-
// return this.executeSql(sqlCommand, [this.tableoption.permissiondatatype,id])
|
|
179
|
-
// .then(result=>{
|
|
180
|
-
// let retValue = {
|
|
181
|
-
// successed:true,
|
|
182
|
-
// managepermission: {
|
|
183
|
-
// datatype:this.tableoption.permissiondatatype,
|
|
184
|
-
// id,
|
|
185
|
-
// permissiontype:1,
|
|
186
|
-
// department:'',
|
|
187
|
-
// departmenttext:'',
|
|
188
|
-
// role:'',
|
|
189
|
-
// roletext:'',
|
|
190
|
-
// level:'',
|
|
191
|
-
// leveltext:'',
|
|
192
|
-
// user:'',
|
|
193
|
-
// usertext:''
|
|
194
|
-
// },
|
|
195
|
-
// consumepermission: {
|
|
196
|
-
// datatype: this.tableoption.permissiondatatype,
|
|
197
|
-
// id,
|
|
198
|
-
// permissiontype: 2,
|
|
199
|
-
// department: '',
|
|
200
|
-
// departmenttext: '',
|
|
201
|
-
// role: '',
|
|
202
|
-
// roletext: '',
|
|
203
|
-
// level: '',
|
|
204
|
-
// leveltext: '',
|
|
205
|
-
// user: '',
|
|
206
|
-
// usertext: ''
|
|
207
|
-
// }
|
|
208
|
-
// };
|
|
209
|
-
// result.rows.forEach(element => {
|
|
210
|
-
// if (element.permissiontype === 1) {////管理权限
|
|
211
|
-
// retValue.managepermission = element;
|
|
212
|
-
// } else if (element.permissiontype === 2) {////消费权限
|
|
213
|
-
// retValue.consumepermission = element;
|
|
214
|
-
// }
|
|
215
|
-
// });
|
|
216
|
-
// return retValue;
|
|
217
|
-
// })
|
|
218
|
-
const sqlCommand = `select
|
|
219
|
-
data_id as id,
|
|
220
|
-
data_type as datatype,
|
|
221
|
-
allow_type as allowtype,
|
|
222
|
-
allow_id as allowid,
|
|
223
|
-
allow_name as allowname
|
|
224
|
-
from framework_permission
|
|
225
|
-
where
|
|
226
|
-
data_id=?
|
|
227
|
-
and data_type=?
|
|
228
|
-
${busSql}
|
|
229
|
-
order by allow_type,allow_id
|
|
230
|
-
`
|
|
231
|
-
return this.executeSql(sqlCommand, [id,this.tableoption.permissiondatatype])
|
|
232
|
-
.then(result=>{
|
|
233
|
-
let retValue = {
|
|
234
|
-
successed:true,
|
|
235
|
-
managepermission: {},
|
|
236
|
-
consumepermission: {
|
|
237
|
-
datatype: this.tableoption.permissiondatatype,
|
|
238
|
-
id,
|
|
239
|
-
permissiontype: 2,
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
let pObject = {deptid:[],depttext:[],roleid:[],roletext:[],userid:[],usernames:[]}
|
|
243
|
-
for (const element of result.rows){
|
|
244
|
-
switch (element.allowtype){
|
|
245
|
-
case 1: ///部门
|
|
246
|
-
pObject.deptid.push(element.allowid)
|
|
247
|
-
pObject.depttext.push(element.allowname)
|
|
248
|
-
break;
|
|
249
|
-
case 2: ///角色
|
|
250
|
-
pObject.roleid.push(element.allowid)
|
|
251
|
-
pObject.roletext.push(element.allowname)
|
|
252
|
-
break;
|
|
253
|
-
case 4: ///用户
|
|
254
|
-
pObject.userid.push(element.allowid)
|
|
255
|
-
pObject.usernames.push(element.allowname)
|
|
256
|
-
break;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
retValue.consumepermission.department = pObject.deptid.join(',')
|
|
260
|
-
retValue.consumepermission.departmenttext = pObject.depttext.join(',') ;//+ ((pObject.deptid.length > pObject.depttext.length) ? `等${pObject.deptid.length}个部门`:'');
|
|
261
|
-
|
|
262
|
-
retValue.consumepermission.role = pObject.roleid.join(',')
|
|
263
|
-
retValue.consumepermission.roletext = pObject.roletext.join(',');// + ((pObject.roleid.length > pObject.roletext.length) ? `等${pObject.roleid.length}个角色` : '');
|
|
264
|
-
|
|
265
|
-
retValue.consumepermission.user = pObject.userid.join(',')
|
|
266
|
-
retValue.consumepermission.usertext = pObject.usernames.join(',');// + ((pObject.userid.length > pObject.usernames.length) ? `等${pObject.userid.length}个用户` : '');
|
|
267
|
-
|
|
268
|
-
// console.log('retValue==>', retValue)
|
|
269
|
-
return retValue;
|
|
270
|
-
})
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
async saveDataPermissionSetting(id,permissionParam){
|
|
274
|
-
if (!this.hasPermissionControl || !permissionParam) {
|
|
275
|
-
return Promise.resolve({successed:true})
|
|
276
|
-
};
|
|
277
|
-
let sqlCommand = `delete from framework_permission where data_id=? and data_type=?;`
|
|
278
|
-
let subItem = [];
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (permissionParam.consumepermission) {
|
|
282
|
-
const mItem = permissionParam.consumepermission;
|
|
283
|
-
const deptids = mItem.department?mItem.department.split(','):[]
|
|
284
|
-
for (const deptid of deptids){
|
|
285
|
-
subItem.push([id, this.tableoption.permissiondatatype, 1, deptid])
|
|
286
|
-
}
|
|
287
|
-
const roleids = mItem.role ? mItem.role.split(',') : []
|
|
288
|
-
for (const rid of roleids) {
|
|
289
|
-
subItem.push([id, this.tableoption.permissiondatatype, 2, rid])
|
|
290
|
-
}
|
|
291
|
-
const userids = mItem.user ? mItem.user.split(',') : []
|
|
292
|
-
for (const uid of userids) {
|
|
293
|
-
subItem.push([id, this.tableoption.permissiondatatype, 4, uid])
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
let sqlParam = [id, this.tableoption.permissiondatatype];
|
|
297
|
-
if (subItem.length){
|
|
298
|
-
sqlCommand = sqlCommand+`
|
|
299
|
-
insert into framework_permission(
|
|
300
|
-
data_id,
|
|
301
|
-
data_type,
|
|
302
|
-
allow_type,
|
|
303
|
-
allow_id
|
|
304
|
-
) values ?;
|
|
305
|
-
|
|
306
|
-
update framework_permission op
|
|
307
|
-
inner join vm_org_department od on op.allow_id=od.department_id
|
|
308
|
-
set op.allow_name = od.department_name,
|
|
309
|
-
op.allow_path = od.parent_path
|
|
310
|
-
where data_id=? and data_type=? and allow_type=1;
|
|
311
|
-
|
|
312
|
-
update framework_permission op
|
|
313
|
-
inner join vm_org_position od on op.allow_id=od.position_id
|
|
314
|
-
set op.allow_name = od.position_namecn
|
|
315
|
-
where data_id=? and data_type=? and allow_type=2;
|
|
316
|
-
|
|
317
|
-
update framework_permission op
|
|
318
|
-
inner join vm_org_user od on op.allow_id=od.user_id
|
|
319
|
-
set op.allow_name = od.user_name
|
|
320
|
-
where data_id=? and data_type=? and allow_type=4;
|
|
321
|
-
`
|
|
322
|
-
sqlParam.push(
|
|
323
|
-
subItem,
|
|
324
|
-
id,
|
|
325
|
-
this.tableoption.permissiondatatype,
|
|
326
|
-
id,
|
|
327
|
-
this.tableoption.permissiondatatype,
|
|
328
|
-
id,
|
|
329
|
-
this.tableoption.permissiondatatype);
|
|
330
|
-
}
|
|
331
|
-
return this.executeSql(sqlCommand, sqlParam);
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
*
|
|
335
|
-
* @param {*} model 需要改变的属性键值对
|
|
336
|
-
* @param {*} id 批量操作的id集合,逗号分开
|
|
337
|
-
*/
|
|
338
|
-
async batchUpdate(Sql,model,id,userid){
|
|
339
|
-
////记录批量删除的人
|
|
340
|
-
if (this.tableoption.logicDelete && this.tableoption.logDeleteBy && model[this.tableoption.logicDeleteField || 'rec_isdeleted']!=null ) {
|
|
341
|
-
model[this.tableoption.logDeleteBy] = userid;
|
|
342
|
-
if (this.tableoption.logDeleteDate){
|
|
343
|
-
model[this.tableoption.logDeleteDate] = Moment().format('YYYY-MM-DD HH:mm:ss');
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return this.executeSql(Sql, [model, id])
|
|
347
|
-
.then(result=>{
|
|
348
|
-
return {successed:true,count:result.rows.affectedRows }
|
|
349
|
-
})
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
exports=module.exports = mysqlDao;
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MySql 封装 (简单,应该尚未完善)
|
|
3
|
-
*/
|
|
4
|
-
const mysql = require('mysql');
|
|
5
|
-
const apiResult = require('../actionresult');
|
|
6
|
-
// const logHelper = require('doomi-helper').logHelper;
|
|
7
|
-
const { createDatabasePool } = require('./poolmanager')
|
|
8
|
-
const executeSqlWithConnection = Symbol("executeSqlWithConnection");
|
|
9
|
-
class Database {
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* @param {*} connectionstring
|
|
13
|
-
*/
|
|
14
|
-
constructor(connectionstring) {
|
|
15
|
-
this.pool = createDatabasePool(connectionstring);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @param {{ trace: (arg0: string, arg1: any, arg2: string, arg3: any) => void; error: (arg0: string, arg1: any) => void; }} logUtility
|
|
20
|
-
*/
|
|
21
|
-
// set logger(logUtility){
|
|
22
|
-
// console.log('logUtility',logUtility)
|
|
23
|
-
// this.logger = logUtility;//logHelper.getInstance().getLogger("framework");
|
|
24
|
-
// }
|
|
25
|
-
/**
|
|
26
|
-
* 防Sql注入进行编码
|
|
27
|
-
* @param {*} value
|
|
28
|
-
*/
|
|
29
|
-
escape(value) {
|
|
30
|
-
return mysql.escape(value);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 给字段名添加``
|
|
34
|
-
* @param {*} value
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
escapeId(value){
|
|
38
|
-
return mysql.escapeId(value)
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* 记录错误日志
|
|
42
|
-
*/
|
|
43
|
-
logError(scene, error, user = null) {
|
|
44
|
-
///不需要记录错误日志
|
|
45
|
-
if (this.ingoreErrorLog === true || !this.actionLogger || typeof (this.actionLogger.logError) !== 'function') {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
///如果没有传场景,则记录数据库的业务值
|
|
49
|
-
if (!scene) scene = this.constructor.name;
|
|
50
|
-
this.actionLogger.logError({ scene, error, user })
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* 检查是否存在数据
|
|
54
|
-
* @param {*} sqlCommand
|
|
55
|
-
* @param {*} parameters
|
|
56
|
-
*/
|
|
57
|
-
async existedSqlData(sqlCommand, parameters, conn, autoclose = true) {
|
|
58
|
-
let sqlExecute = await this.executeSql(sqlCommand, parameters, conn, autoclose);
|
|
59
|
-
if (!sqlExecute.successed) return { successed: false }
|
|
60
|
-
if (!sqlExecute.rows || sqlExecute.rows.length == 0) return { successed: true, existed: false }
|
|
61
|
-
return { successed: true, existed: true, ...sqlExecute.rows[0] }
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* 获取到第一行记录的所有字段的值
|
|
65
|
-
* @param {*} sqlCommand
|
|
66
|
-
* @param {*} parameters
|
|
67
|
-
* @returns
|
|
68
|
-
*/
|
|
69
|
-
async getComputedRowValue(sqlCommand, parameters, conn, autoclose = true) {
|
|
70
|
-
let sqlExecute = await this.executeSql(sqlCommand, parameters, conn, autoclose);
|
|
71
|
-
if (!sqlExecute.successed || sqlExecute.rows.length == 0) return { successed: false, errcode: -1, errmsg: '没有任何记录' }
|
|
72
|
-
return { successed: true, ...sqlExecute.rows[0] }
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* 单独获得一个连接串
|
|
77
|
-
* @returns
|
|
78
|
-
*/
|
|
79
|
-
getConnection() {
|
|
80
|
-
return new Promise((success) => {
|
|
81
|
-
if (!this.pool) {
|
|
82
|
-
return success(null);
|
|
83
|
-
}
|
|
84
|
-
this.pool.getConnection(function (err, connection) {
|
|
85
|
-
if (err) return success(null);;
|
|
86
|
-
return success(connection)
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* 不事务执行SQL命令
|
|
92
|
-
* @param {*} sqlCommand
|
|
93
|
-
* @param {*} parameters 参数
|
|
94
|
-
*/
|
|
95
|
-
executeSql(sqlCommand, parameters, conn, autoclose = true) {
|
|
96
|
-
// let logger = this.logger;
|
|
97
|
-
// let that = this;
|
|
98
|
-
if (conn) {
|
|
99
|
-
return this[executeSqlWithConnection](sqlCommand, parameters, conn, autoclose)
|
|
100
|
-
}
|
|
101
|
-
return new Promise((success, failed) => {
|
|
102
|
-
if (!this.pool) {
|
|
103
|
-
return success(apiResult.DB_CONNECTED_FAILED);
|
|
104
|
-
}
|
|
105
|
-
///创建出数据库连接,准备执行
|
|
106
|
-
this.pool.getConnection(async (err, connection) => {
|
|
107
|
-
if (err) {
|
|
108
|
-
// if (logger) logger.error("Database Connected Failed :" + err);
|
|
109
|
-
return success(apiResult.DB_CONNECTED_FAILED);
|
|
110
|
-
}
|
|
111
|
-
let sqlResult = await this[executeSqlWithConnection](sqlCommand, parameters, connection, autoclose)
|
|
112
|
-
return success(sqlResult)
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* 使用一个已存在的链接Query Sql
|
|
118
|
-
* @param {*} sqlCommand
|
|
119
|
-
* @param {*} parameters
|
|
120
|
-
* @param {*} conn
|
|
121
|
-
* @param {*} closeAfterQuery 执行完毕后是否关闭
|
|
122
|
-
*/
|
|
123
|
-
[executeSqlWithConnection](sqlCommand, parameters, conn, autoclose = true) {
|
|
124
|
-
if (!conn) return Promise.resolve(apiResult.DB_CONNECTED_FAILED);
|
|
125
|
-
return new Promise((success) => {
|
|
126
|
-
// this.logger.trace("SqlCommand:", sqlCommand, "Parameters:", parameters);
|
|
127
|
-
return conn.query(sqlCommand, parameters, (err, rows) => {
|
|
128
|
-
if (autoclose) conn.release();
|
|
129
|
-
if (err) {
|
|
130
|
-
// this.logger.error("Database Query Error :" + err, sqlCommand);
|
|
131
|
-
console.log('数据库操作错误', err, sqlCommand)
|
|
132
|
-
this.logError(null, '数据库操作错误:' + err + sqlCommand)
|
|
133
|
-
return success(Object.assign(apiResult.DB_EXECUTE_FAILED, { errmessage:'数据库操作错误'}));// err.message }));
|
|
134
|
-
}
|
|
135
|
-
return success({ successed: true, rows: rows });//,fields:fields});
|
|
136
|
-
});
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* 启动事务进行保护性操作
|
|
141
|
-
* @param {*} conn
|
|
142
|
-
* @param {*} func
|
|
143
|
-
*/
|
|
144
|
-
async executeSqlWithTransaction(conn, func) {
|
|
145
|
-
if (!conn) {
|
|
146
|
-
conn = await this.getConnection();
|
|
147
|
-
}
|
|
148
|
-
if (!conn) return Promise.resolve({ successed: false });
|
|
149
|
-
return new Promise(success => {
|
|
150
|
-
conn.beginTransaction(async err => {
|
|
151
|
-
if (err) return success({ successed: false, errcode: -1, errmessage: '【事务启动错误】' + err.message });
|
|
152
|
-
let result = { successed: true }
|
|
153
|
-
if (func && typeof (func) === 'function') result = await func(conn);
|
|
154
|
-
if (result.successed) {
|
|
155
|
-
conn.commit(commiterror => {
|
|
156
|
-
if (commiterror) {
|
|
157
|
-
console.log('事务提交失败 :', commiterror);
|
|
158
|
-
return success(Object.assign(apiResult.DB_EXECUTE_FAILED, { errmessage: commiterror.message }));
|
|
159
|
-
}
|
|
160
|
-
conn.release();
|
|
161
|
-
return success(result);
|
|
162
|
-
})
|
|
163
|
-
} else {
|
|
164
|
-
conn.rollback(() => {
|
|
165
|
-
conn.release();
|
|
166
|
-
return success(Object.assign(apiResult.DB_EXECUTE_FAILED, { errmessage: '撤回操作' }));
|
|
167
|
-
})
|
|
168
|
-
}
|
|
169
|
-
})
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
module.exports = Database;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const mysql = require('mysql');
|
|
2
|
-
const appsetting = require('../../configuration/appsetting').getCurrentApp();
|
|
3
|
-
/**
|
|
4
|
-
* 创建和管理数据库链接池
|
|
5
|
-
* @param {*} connect
|
|
6
|
-
*/
|
|
7
|
-
let PoolManager = {};
|
|
8
|
-
module.exports.createDatabasePool=(connect)=>{
|
|
9
|
-
if (PoolManager[connect]!=null){
|
|
10
|
-
return PoolManager[connect];
|
|
11
|
-
}
|
|
12
|
-
const pool = mysql.createPool(appsetting.getConnection(connect || 'dev'));
|
|
13
|
-
PoolManager[connect] = pool;
|
|
14
|
-
return pool;
|
|
15
|
-
}
|
package/core/doomiwork.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Doomisoft框架入口类
|
|
3
|
-
自动加载配置与routerConfig中的路由配置
|
|
4
|
-
*/
|
|
5
|
-
const { loadController } = require('../configuration/routerconfig')
|
|
6
|
-
const config = require('../configuration/appsetting').getCurrentApp();
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const path = require('path')
|
|
9
|
-
// const {redisHelper,logHelper} = require('doomi-helper');
|
|
10
|
-
class Doomiwork {
|
|
11
|
-
static startWork(application,option) {
|
|
12
|
-
// const startupRoot = process.cwd();
|
|
13
|
-
///将configuration对象放置于app对象中.所有的controller都可以使用
|
|
14
|
-
application.config = config;
|
|
15
|
-
///启动redis进行缓存
|
|
16
|
-
////为每个controller注入同一个redis实例
|
|
17
|
-
if (config.getSetting("redis", false) === true && option.redis){
|
|
18
|
-
application.redis = option.redis;// redisHelper.getInstance();
|
|
19
|
-
}
|
|
20
|
-
////记录用户行为的日志记录器
|
|
21
|
-
// const logHandler = config.getSetting("logaction", null)
|
|
22
|
-
// if (logHandler){
|
|
23
|
-
// let actionLogger = path.join(startupRoot, logHandler);
|
|
24
|
-
// if (actionLogger && fs.existsSync(actionLogger)) {
|
|
25
|
-
// const logInstance = require(actionLogger);
|
|
26
|
-
// application.actionLogger = new logInstance();
|
|
27
|
-
// }
|
|
28
|
-
// }
|
|
29
|
-
///用户操作日志记录
|
|
30
|
-
if(config.getSetting("logaction", false)===true && option.logaction){
|
|
31
|
-
application.actionLogger = option.logaction;
|
|
32
|
-
}
|
|
33
|
-
///日志记录器
|
|
34
|
-
if (config.getSetting("logger", false) === true && option.logger) {
|
|
35
|
-
application.logger = option.logger;// redisHelper.getInstance();
|
|
36
|
-
}
|
|
37
|
-
//application.logger = logHelper.getInstance().getLogger("framework");
|
|
38
|
-
/**全局所有请求拦截器 */
|
|
39
|
-
application.use('/',(req,res,next)=>{
|
|
40
|
-
req.user = req.headers;
|
|
41
|
-
return next();
|
|
42
|
-
});
|
|
43
|
-
/** 加载所有的控制器 */
|
|
44
|
-
if (!option.routes){
|
|
45
|
-
const roterfile = path.join(process.cwd(), 'routerconfig.json');
|
|
46
|
-
///将配置中的所有需要加载的controller文件都加载出来
|
|
47
|
-
if (fs.existsSync(roterfile)){
|
|
48
|
-
option.routes = require(roterfile)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
loadController(application, option.routes)
|
|
52
|
-
Doomiwork.app = application;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* 注册url请求拦截函数
|
|
56
|
-
* @param {*} baseUrl
|
|
57
|
-
* @param {*} intrupFilter
|
|
58
|
-
*/
|
|
59
|
-
static registerUrlInterceptor(app,baseUrl,intrupFilter){
|
|
60
|
-
if (intrupFilter){
|
|
61
|
-
app.use(baseUrl,intrupFilter);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* 注册一组同组的请求路径的拦截器
|
|
66
|
-
* @param {*} baseUrl
|
|
67
|
-
* @param {*} intrupFilter
|
|
68
|
-
*/
|
|
69
|
-
static registerGroupInterceptor(app,groupName,intrupFilter){
|
|
70
|
-
if (groupName && intrupFilter){
|
|
71
|
-
if (!app.Interceptor) app.Interceptor = {};
|
|
72
|
-
app.Interceptor[groupName] = intrupFilter;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports = module.exports = Doomiwork;
|
package/core/enumconst.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* 常用的API返回错误枚举
|
|
3
|
-
*/
|
|
4
|
-
///数据库级别的错误 : FROM 10001 ~ 10100
|
|
5
|
-
module.exports.DATABASE_ERROR = {
|
|
6
|
-
DATABASE_CONNECTED_ERROR: 10001,
|
|
7
|
-
DATABASE_EXECUTE_ERROR: 10002,
|
|
8
|
-
NO_RECORD_EFFECTED: 10003,
|
|
9
|
-
NO_RECORD_FOUND: 10004
|
|
10
|
-
}
|
|
11
|
-
///通用错误 : From 9000~10000
|
|
12
|
-
module.exports.COMMON_ERROR = {
|
|
13
|
-
TRANSMIT_TO_VIEW_ERROR: 9000,
|
|
14
|
-
TRANSMIT_TO_DATA_ERROR: 9001,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
VISIT_TO_INDEX: 9002, //访问跟域名,返回到首页
|
|
18
|
-
API_PARAMETERS_ERROR: 9003, //API方法调用错误
|
|
19
|
-
VERIFY_CODE_ERROR: 9004, //验证码错误
|
|
20
|
-
/////权限操作类错误
|
|
21
|
-
NO_ACCESS_RIGHT: 9100, //没有访问权限
|
|
22
|
-
TOKEN_IS_MISSING: 9997,
|
|
23
|
-
TOKEN_EXPIRED: 9998, //
|
|
24
|
-
TOKEN_IS_INVALID: 9999, //密匙无效
|
|
25
|
-
UNAUTHORIZATION_ERROR: 10000 //未认证
|
|
26
|
-
}
|
|
27
|
-
///用户登录错误码
|
|
28
|
-
module.exports.LOGIN_ERROR = {
|
|
29
|
-
SUCCESSED: 0,
|
|
30
|
-
USER_NOT_FOUND: 1,
|
|
31
|
-
USER_PASSWORD_ERROR: 2,
|
|
32
|
-
SERIAL_CODE_ERROR: 3, ///校验码无效
|
|
33
|
-
UNKNOW_ERROR: 4,
|
|
34
|
-
DATABASE_ERROR: 100
|
|
35
|
-
};
|
|
36
|
-
///获取用户属性错误码
|
|
37
|
-
module.exports.GET_USERINFO_ERROR = {
|
|
38
|
-
SUCCESSED: 0,
|
|
39
|
-
USER_NOT_FOUND: 1,
|
|
40
|
-
UNKNOW_ERROR: 2,
|
|
41
|
-
DATABASE_ERROR: 100
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* CRUD操作所对应的web method以及框架对应的调用方法
|
|
45
|
-
*/
|
|
46
|
-
module.exports.CRUDAction = {
|
|
47
|
-
Create:{method:'post',name:'create',func:'create'},
|
|
48
|
-
Retrieve:{method:'get',name:'list',func:'getListData'},
|
|
49
|
-
Single:{method:'get',name:'single',func:'getDataById'},
|
|
50
|
-
Update:{method:'put',name:'update',func:'update'},
|
|
51
|
-
Delete:{method:'delete',name:'delete',func:'delete'}
|
|
52
|
-
}
|
package/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
exports = module.exports = {
|
|
2
|
-
doomiwork:require('./core/doomiwork'),
|
|
3
|
-
controller: require('./core/controller'),
|
|
4
|
-
model: require('./core/database/daoBase'),
|
|
5
|
-
appsetting:require('./configuration/appsetting'),
|
|
6
|
-
actionresult:require('./core/actionresult'),
|
|
7
|
-
excelutility:require('./utilities/excelutility'),
|
|
8
|
-
tokenHelper:require('./utilities/tokenutility'),
|
|
9
|
-
constants:require('./core/enumconst'),
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
///last version 3.7.12
|