doomiwork 3.3.2 → 3.3.5
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/core/controller.js +8 -8
- package/core/database/daoBase.js +37 -88
- package/package.json +1 -1
package/core/controller.js
CHANGED
|
@@ -63,9 +63,9 @@ class controller {
|
|
|
63
63
|
* @param {*} req
|
|
64
64
|
* @param {*} res
|
|
65
65
|
*/
|
|
66
|
-
createCRUDRoute(actionType,url,datakey){
|
|
66
|
+
createCRUDRoute(actionType,url,datakey,middleware){
|
|
67
67
|
let instance = this;
|
|
68
|
-
instance.router[actionType.method](url,async (req,res)=>{
|
|
68
|
+
instance.router[actionType.method](url, middleware,async (req,res)=>{
|
|
69
69
|
////执行CRUD之前,可由继承的子类实现规则验证
|
|
70
70
|
////如果返回successed:false,则不再继续
|
|
71
71
|
let beforeResult = await instance.beforeCRUD(actionType,req,res)
|
|
@@ -91,14 +91,14 @@ class controller {
|
|
|
91
91
|
* @param {*} datakey 对应在dataconfig.json中的key,方便实体和传递的数据的映射以及SQL
|
|
92
92
|
* @param {*} action 操作的组合 CRUDS
|
|
93
93
|
*/
|
|
94
|
-
initializeCRUDRouter(url,datakey,action='SCRUD'){
|
|
94
|
+
initializeCRUDRouter(url, datakey, action = 'SCRUD', middleware){
|
|
95
95
|
if(!url || !datakey) return;
|
|
96
96
|
let urlWithId = stringHelper.endsWith(url,'/')?`${url}:id`:`${url}/:id`;
|
|
97
|
-
if(action.indexOf('C')>=0) this.createCRUDRoute(constEnum.CRUDAction.Create,url,datakey)
|
|
98
|
-
if(action.indexOf('S')>=0) this.createCRUDRoute(constEnum.CRUDAction.Single,urlWithId,datakey)
|
|
99
|
-
if(action.indexOf('R')>=0) this.createCRUDRoute(constEnum.CRUDAction.Retrieve,url,datakey)
|
|
100
|
-
if(action.indexOf('U')>=0) this.createCRUDRoute(constEnum.CRUDAction.Update,urlWithId,datakey)
|
|
101
|
-
if(action.indexOf('D')>=0) this.createCRUDRoute(constEnum.CRUDAction.Delete,urlWithId,datakey)
|
|
97
|
+
if (action.indexOf('C') >= 0) this.createCRUDRoute(constEnum.CRUDAction.Create, url, datakey, middleware)
|
|
98
|
+
if (action.indexOf('S') >= 0) this.createCRUDRoute(constEnum.CRUDAction.Single, urlWithId, datakey, middleware)
|
|
99
|
+
if (action.indexOf('R') >= 0) this.createCRUDRoute(constEnum.CRUDAction.Retrieve, url, datakey, middleware)
|
|
100
|
+
if (action.indexOf('U') >= 0) this.createCRUDRoute(constEnum.CRUDAction.Update, urlWithId, datakey, middleware)
|
|
101
|
+
if (action.indexOf('D') >= 0) this.createCRUDRoute(constEnum.CRUDAction.Delete, urlWithId, datakey, middleware)
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* CRUD真正进入数据库之前的处理,可由继承的类来处理
|
package/core/database/daoBase.js
CHANGED
|
@@ -246,84 +246,7 @@ class mysqlDao extends dao{
|
|
|
246
246
|
if (!this.hasPermissionControl || !permissionParam) {
|
|
247
247
|
return Promise.resolve({successed:true})
|
|
248
248
|
};
|
|
249
|
-
|
|
250
|
-
// replace into vmv3_data_permission(
|
|
251
|
-
// data_type,
|
|
252
|
-
// data_id,
|
|
253
|
-
// permission_type,
|
|
254
|
-
// data_department,
|
|
255
|
-
// data_department_text,
|
|
256
|
-
// data_role,
|
|
257
|
-
// data_role_text,
|
|
258
|
-
// data_level,
|
|
259
|
-
// data_level_text,
|
|
260
|
-
// data_user,
|
|
261
|
-
// data_user_text
|
|
262
|
-
// ) values
|
|
263
|
-
// `
|
|
264
|
-
// let subItem = [];
|
|
265
|
-
// if (permissionParam.managepermission){
|
|
266
|
-
// const mItem = permissionParam.managepermission;
|
|
267
|
-
// subItem.push(`(
|
|
268
|
-
// ${this.tableoption.permissiondatatype},
|
|
269
|
-
// '${id}',
|
|
270
|
-
// 1,
|
|
271
|
-
// '${mItem.department || ''}',
|
|
272
|
-
// '${mItem.departmenttext || ''}',
|
|
273
|
-
// '${mItem.role || ''}',
|
|
274
|
-
// '${mItem.roletext || ''}',
|
|
275
|
-
// '${mItem.level || ''}',
|
|
276
|
-
// '${mItem.leveltext || ''}',
|
|
277
|
-
// '${mItem.user || ''}',
|
|
278
|
-
// '${mItem.usertext || ''}'
|
|
279
|
-
// )`)
|
|
280
|
-
|
|
281
|
-
// }
|
|
282
|
-
|
|
283
|
-
// if (permissionParam.consumepermission) {
|
|
284
|
-
// const mItem = permissionParam.consumepermission;
|
|
285
|
-
// subItem.push(`(
|
|
286
|
-
// ${this.tableoption.permissiondatatype},
|
|
287
|
-
// '${id}',
|
|
288
|
-
// 2,
|
|
289
|
-
// '${mItem.department || ''}',
|
|
290
|
-
// '${mItem.departmenttext || ''}',
|
|
291
|
-
// '${mItem.role || ''}',
|
|
292
|
-
// '${mItem.roletext || ''}',
|
|
293
|
-
// '${mItem.level || ''}',
|
|
294
|
-
// '${mItem.leveltext || ''}',
|
|
295
|
-
// '${mItem.user || ''}',
|
|
296
|
-
// '${mItem.usertext || ''}'
|
|
297
|
-
// )`)
|
|
298
|
-
// }
|
|
299
|
-
//return this.executeSql(sqlCommand+subItem.join(','));
|
|
300
|
-
|
|
301
|
-
const sqlCommand = `
|
|
302
|
-
delete from framework_permission where data_id=? and data_type=?;
|
|
303
|
-
insert into framework_permission(
|
|
304
|
-
data_id,
|
|
305
|
-
data_type,
|
|
306
|
-
allow_type,
|
|
307
|
-
allow_id
|
|
308
|
-
) values ?;
|
|
309
|
-
|
|
310
|
-
update framework_permission op
|
|
311
|
-
inner join vm_org_department od on op.allow_id=od.department_id
|
|
312
|
-
set op.allow_name = od.department_name,
|
|
313
|
-
op.allow_path = od.parent_path
|
|
314
|
-
where data_id=? and data_type=? and allow_type=1;
|
|
315
|
-
|
|
316
|
-
update framework_permission op
|
|
317
|
-
inner join vm_org_role od on op.allow_id=od.role_id
|
|
318
|
-
set op.allow_name = od.role_name
|
|
319
|
-
where data_id=? and data_type=? and allow_type=2;
|
|
320
|
-
|
|
321
|
-
update framework_permission op
|
|
322
|
-
inner join vm_org_user od on op.allow_id=od.user_id
|
|
323
|
-
set op.allow_name = od.user_name
|
|
324
|
-
where data_id=? and data_type=? and allow_type=4;
|
|
325
|
-
|
|
326
|
-
`
|
|
249
|
+
let sqlCommand = `delete from framework_permission where data_id=? and data_type=?;`
|
|
327
250
|
let subItem = [];
|
|
328
251
|
|
|
329
252
|
|
|
@@ -342,16 +265,42 @@ class mysqlDao extends dao{
|
|
|
342
265
|
subItem.push([id, this.tableoption.permissiondatatype, 4, uid])
|
|
343
266
|
}
|
|
344
267
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
268
|
+
let sqlParam = [id, this.tableoption.permissiondatatype];
|
|
269
|
+
if (subItem.length){
|
|
270
|
+
sqlCommand = sqlCommand+`
|
|
271
|
+
insert into framework_permission(
|
|
272
|
+
data_id,
|
|
273
|
+
data_type,
|
|
274
|
+
allow_type,
|
|
275
|
+
allow_id
|
|
276
|
+
) values ?;
|
|
277
|
+
|
|
278
|
+
update framework_permission op
|
|
279
|
+
inner join vm_org_department od on op.allow_id=od.department_id
|
|
280
|
+
set op.allow_name = od.department_name,
|
|
281
|
+
op.allow_path = od.parent_path
|
|
282
|
+
where data_id=? and data_type=? and allow_type=1;
|
|
283
|
+
|
|
284
|
+
update framework_permission op
|
|
285
|
+
inner join vm_org_role od on op.allow_id=od.role_id
|
|
286
|
+
set op.allow_name = od.role_name
|
|
287
|
+
where data_id=? and data_type=? and allow_type=2;
|
|
288
|
+
|
|
289
|
+
update framework_permission op
|
|
290
|
+
inner join vm_org_user od on op.allow_id=od.user_id
|
|
291
|
+
set op.allow_name = od.user_name
|
|
292
|
+
where data_id=? and data_type=? and allow_type=4;
|
|
293
|
+
`
|
|
294
|
+
sqlParam.push(
|
|
295
|
+
subItem,
|
|
296
|
+
id,
|
|
297
|
+
this.tableoption.permissiondatatype,
|
|
298
|
+
id,
|
|
299
|
+
this.tableoption.permissiondatatype,
|
|
300
|
+
id,
|
|
301
|
+
this.tableoption.permissiondatatype);
|
|
302
|
+
}
|
|
303
|
+
return this.executeSql(sqlCommand, sqlParam);
|
|
355
304
|
}
|
|
356
305
|
/**
|
|
357
306
|
*
|