This commit is contained in:
aozhiwei 2022-04-16 16:42:27 +08:00
parent 8fd77fd8dc
commit ddba7238ac
2 changed files with 58 additions and 41 deletions

View File

@ -25,50 +25,56 @@ function registerMetaClass(fileName, primKey, wrapClass, aliseName = '') {
}
}
function load() {
metaClassList.forEach((metaClass) => {
const json = utils.readJsonFromFile(metaClass['fileName']);
if (!json) {
throw new Error('读取配置' + metaClass['fileName'] + '失败');
}
if (Array.isArray(json)) {
metaClass['rawList'] = json;
} else {
metaClass['rawList'].push(json);
}
let idx = 0;
metaClass['rawList'].forEach(function (item) {
const wrapOjb = new metaClass['wrapClass'](item, metaClass);
const wrapProxy = new Proxy(wrapOjb, wrapOjb._getHandler());
metaClass['wrapList'].push(wrapProxy);
if (metaClass['primKey'] == '') {
metaClass['rawHash'][idx] = item;
metaClass['wrapHash'][idx] = wrapProxy;
} else {
metaClass['rawHash'][item[metaClass['primKey']]] = item;
metaClass['wrapHash'][item[metaClass['primKey']]] = wrapProxy;
}
++idx;
});
//log.debug(utils.jsonEncode(metaClass));
});
{
for (let i = 0; i < 3; ++i) {
metaClassList.forEach((metaClass) => {
metaClass['wrapList'].forEach((item) => {
if (item['_init' + i]) {
item['_init' + i](exports);
}
});
});
}
metaClassList.forEach((metaClass) => {
function onAllLoadPost(classList) {
for (let i = 0; i < 3; ++i) {
classList.forEach((metaClass) => {
metaClass['wrapList'].forEach((item) => {
item.lock();
if (item['_init' + i]) {
item['_init' + i](exports);
}
});
});
}
classList.forEach((metaClass) => {
metaClass['wrapList'].forEach((item) => {
item.lock();
});
});
}
function loadMeta(metaClass) {
const json = utils.readJsonFromFile(metaClass['fileName']);
if (!json) {
throw new Error('读取配置' + metaClass['fileName'] + '失败');
}
if (Array.isArray(json)) {
metaClass['rawList'] = json;
} else {
metaClass['rawList'].push(json);
}
let idx = 0;
metaClass['rawList'].forEach(function (item) {
const wrapOjb = new metaClass['wrapClass'](item, metaClass);
const wrapProxy = new Proxy(wrapOjb, wrapOjb._getHandler());
metaClass['wrapList'].push(wrapProxy);
if (metaClass['primKey'] == '') {
metaClass['rawHash'][idx] = item;
metaClass['wrapHash'][idx] = wrapProxy;
} else {
metaClass['rawHash'][item[metaClass['primKey']]] = item;
metaClass['wrapHash'][item[metaClass['primKey']]] = wrapProxy;
}
++idx;
});
}
function load() {
metaClassList.forEach((metaClass) => {
loadMeta(metaClass);
//log.debug(utils.jsonEncode(metaClass));
});
onAllLoadPost(metaClassList);
}
function init() {
@ -115,13 +121,18 @@ function init() {
load();
{
const classList = [];
getMetaByKey('PresentList', '0')['list'].forEach((item) => {
registerMetaClass(resDir + item + '@present.json',
'id',
'Present',
'Present' + item
);
const metaClass = getMetaClass('Present' + item);
loadMeta(metaClass);
classList.push(metaClass);
});
onAllLoadPost(classList);
}
{
traverseMetaList('MarketDb', (dbConf, idx) => {

View File

@ -1,9 +1,15 @@
const BaseService = require('./baseservice');
const metaFactory = require('../metadata/factory');
class Present extends BaseService {
async init() {
const presentList = metaFactory.getMetaByKey('PresentList', '0')['list'];
for (let i in presentList) {
const name = presentList[i];
metaFactory.traverseMetaList('Present' + name, (item) => {
});
}
}
}