|
|
@ -4,92 +4,94 @@ const moment = require('moment') |
|
|
|
async function getResourceClassify(ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { limit, offset } = ctx.query; |
|
|
|
// const { limit, offset } = ctx.query;
|
|
|
|
let rlst = []; |
|
|
|
const findObj = {} |
|
|
|
if (Number(limit) > 0 && Number(offset) >= 0) { |
|
|
|
findObj.limit = Number(limit); |
|
|
|
findObj.offset = Number(offset); |
|
|
|
} |
|
|
|
// const findObj = {}
|
|
|
|
// if (Number(limit) > 0 && Number(offset) >= 0) {
|
|
|
|
// findObj.limit = Number(limit);
|
|
|
|
// findObj.offset = Number(offset);
|
|
|
|
// }
|
|
|
|
rlst = [{ |
|
|
|
label: "公司培训资料", value: "company", key: "company", operation: true, children: [] |
|
|
|
}, { label: "部门培训资料", value: 'dept', key: 'dept', operation: false, children: [] }]; |
|
|
|
const trainingInformationLevel = await models.TrainingInformationLevel.findAll(findObj); |
|
|
|
if (trainingInformationLevel.length) { |
|
|
|
|
|
|
|
|
|
|
|
for (let level of trainingInformationLevel) { |
|
|
|
const { id, type, departmentname, traindate, origin } = level; |
|
|
|
/**type:1级, departmentname:2级,traindate:3级 */ |
|
|
|
const arrIndex = rlst.findIndex(item => item.label == type) |
|
|
|
if (arrIndex > -1) {//一级分类名称正确
|
|
|
|
const operation = "import" == origin ? true : false; |
|
|
|
if (departmentname) { |
|
|
|
if (traindate) { |
|
|
|
label: "公司培训资料", value: "company", key: "公司培训资料", operation: true, children: [] |
|
|
|
}, { label: "部门培训资料", value: 'dept', key: '部门培训资料', operation: false, children: [] }]; |
|
|
|
const filterData = (arrayData, arrIndex, operation) => { |
|
|
|
if (arrayData.length) { |
|
|
|
for (let level of arrayData) { |
|
|
|
const { departmentName, trainDate } = level.dataValues; |
|
|
|
/** departmentName:2级,trainDate:3级 */ |
|
|
|
if (departmentName) { |
|
|
|
if (trainDate) { |
|
|
|
const depKey = rlst[arrIndex].label + '/' + departmentName |
|
|
|
//区分2级是否记录
|
|
|
|
if (rlst[arrIndex].children) { |
|
|
|
const depIndex = rlst[arrIndex].children.findIndex(r => r.label == departmentname); |
|
|
|
const depIndex = rlst[arrIndex].children.findIndex(r => r.key == depKey); |
|
|
|
if (depIndex > -1) { |
|
|
|
const dateKey = rlst[arrIndex].label + '/' + rlst[arrIndex].children[depIndex].label + '/' + moment(trainDate).format('YYYY-MM'); |
|
|
|
if (rlst[arrIndex].children[depIndex].children) { |
|
|
|
rlst[arrIndex].children[depIndex].children.push({ |
|
|
|
label: moment(traindate).format('YYYY-MM'), |
|
|
|
value: id, |
|
|
|
key: id, |
|
|
|
operation |
|
|
|
}) |
|
|
|
const dateIndex = rlst[arrIndex].children[depIndex].children.findIndex(r => r.key == dateKey); |
|
|
|
if (dateIndex == -1) { |
|
|
|
rlst[arrIndex].children[depIndex].children.push({ |
|
|
|
label: moment(trainDate).format('YYYY-MM'), |
|
|
|
value: dateKey, |
|
|
|
key: dateKey, |
|
|
|
operation |
|
|
|
}); |
|
|
|
} |
|
|
|
} else { |
|
|
|
rlst[arrIndex].children[depIndex].children = [{ |
|
|
|
label: moment(traindate).format('YYYY-MM'), |
|
|
|
value: id, |
|
|
|
key: id, |
|
|
|
label: moment(trainDate).format('YYYY-MM'), |
|
|
|
value: dateKey, |
|
|
|
key: dateKey, |
|
|
|
operation |
|
|
|
}] |
|
|
|
} |
|
|
|
} else { |
|
|
|
rlst[arrIndex].children.push({ |
|
|
|
label: departmentname, |
|
|
|
label: departmentName, |
|
|
|
value: depKey, |
|
|
|
key: depKey, |
|
|
|
operation, |
|
|
|
children: [{ |
|
|
|
label: moment(traindate).format('YYYY-MM'), |
|
|
|
value: id, |
|
|
|
key: id, |
|
|
|
label: moment(trainDate).format('YYYY-MM'), |
|
|
|
value: depKey + '/' + moment(trainDate).format('YYYY-MM'), |
|
|
|
key: depKey + '/' + moment(trainDate).format('YYYY-MM'), |
|
|
|
operation |
|
|
|
}] |
|
|
|
}); |
|
|
|
} |
|
|
|
} else { |
|
|
|
rlst[arrIndex].children = [{ |
|
|
|
label: departmentname, |
|
|
|
label: departmentName, |
|
|
|
value: depKey, |
|
|
|
key: depKey, |
|
|
|
operation, |
|
|
|
children: [{ |
|
|
|
label: moment(traindate).format('YYYY-MM'), |
|
|
|
value: id, |
|
|
|
key: id, |
|
|
|
label: moment(trainDate).format('YYYY-MM'), |
|
|
|
value: depKey + '/' + moment(trainDate).format('YYYY-MM'), |
|
|
|
key: depKey + '/' + moment(trainDate).format('YYYY-MM'), |
|
|
|
operation |
|
|
|
}] |
|
|
|
}] |
|
|
|
} |
|
|
|
} else { |
|
|
|
//只有2级目录的情况
|
|
|
|
if (rlst[arrIndex].children) { |
|
|
|
const depIndex = rlst[arrIndex].children.findIndex(r => r.label == departmentname); |
|
|
|
if (depIndex > -1) { |
|
|
|
if (!rlst[arrIndex].children[depIndex].value) { |
|
|
|
rlst[arrIndex].children[depIndex].value = id; |
|
|
|
rlst[arrIndex].children[depIndex].key = id; |
|
|
|
rlst[arrIndex].children[depIndex].operation = operation; |
|
|
|
} |
|
|
|
} else { |
|
|
|
const depIndex = rlst[arrIndex].children.findIndex(r => r.key == rlst[arrIndex].label + '/' + departmentName); |
|
|
|
if (depIndex == -1) { |
|
|
|
rlst[arrIndex].children.push({ |
|
|
|
label: departmentname, |
|
|
|
value: id, |
|
|
|
key: id, |
|
|
|
operation |
|
|
|
label: departmentName, |
|
|
|
value: rlst[arrIndex].label + '/' + departmentName, |
|
|
|
key: rlst[arrIndex].label + '/' + departmentName, |
|
|
|
operation, |
|
|
|
children: [] |
|
|
|
}) |
|
|
|
} |
|
|
|
} else { |
|
|
|
rlst[arrIndex].children = [{ |
|
|
|
label: departmentname, |
|
|
|
value: id, |
|
|
|
key: id, |
|
|
|
operation |
|
|
|
value: rlst[arrIndex].label + '/' + departmentName, |
|
|
|
key: rlst[arrIndex].label + '/' + departmentName, |
|
|
|
operation, |
|
|
|
children: [] |
|
|
|
}] |
|
|
|
} |
|
|
|
} |
|
|
@ -97,6 +99,16 @@ async function getResourceClassify(ctx) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const deptTraining = await models.DeptTraining.findAll({}); |
|
|
|
if (deptTraining.length) { |
|
|
|
filterData(deptTraining, 1, false); |
|
|
|
} |
|
|
|
|
|
|
|
const trainingInformation = await models.TrainingInformation.findAll({}); |
|
|
|
if (trainingInformation.length) { |
|
|
|
filterData(trainingInformation, 0, true); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = rlst; |
|
|
|