读取常量表
This commit is contained in:
1 parent
bab9515e0b
commit
0bc4b4202e
2 files changed
+42
No files matched your search
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
// ========================================常用 require start===========================================
|
||||
const Service = require('egg').Service;
|
||||
const _ = require('lodash');
|
||||
// ========================================常用 require end=============================================
|
||||
|
||||
|
||||
class ConstantService extends Service {
|
||||
|
||||
async getConstantObj() {
|
||||
const { jianghuKnex } = this.app;
|
||||
const constantList = await jianghuKnex('_constant').select();
|
||||
constantList.forEach(constant => {
|
||||
try {
|
||||
constant.constantValue = JSON.parse(constant.constantValue);
|
||||
} catch (e) {
|
||||
console.error('parse constantValue error', constant.constantKey)
|
||||
}
|
||||
});
|
||||
const constantObj = _.mapValues(_.keyBy(constantList, 'constantKey'), 'constantValue');
|
||||
|
||||
return constantObj;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConstantService;
|
||||
Reference in new issue
Block a user