3 changed files with 117 additions and 3 deletions
@ -0,0 +1,105 @@ |
|||||
|
'use strict'; |
||||
|
const moment = require('moment') |
||||
|
|
||||
|
async function getResourceClassify(ctx) { |
||||
|
try { |
||||
|
const { models } = ctx.fs.dc; |
||||
|
const { limit, offset } = ctx.query; |
||||
|
let rlst = []; |
||||
|
const findObj = { plain: false, group: ["type", "id"] } |
||||
|
if (Number(limit) > 0 && Number(offset) >= 0) { |
||||
|
findObj.limit = Number(limit); |
||||
|
findObj.offset = Number(offset); |
||||
|
} |
||||
|
const trainingInformationLevel = await models.TrainingInformationLevel.findAll(findObj); |
||||
|
if (trainingInformationLevel.length) { |
||||
|
rlst = [{ |
||||
|
label: "公司培训资料", value: "company", operation: true, |
||||
|
}, { label: "部门培训资料", value: 'dept', operation: false }]; |
||||
|
|
||||
|
for (let level of trainingInformationLevel) { |
||||
|
const { id, type, departmentname, traindate } = level; |
||||
|
/**type:1级, departmentname:2级,traindate:3级 */ |
||||
|
const arrIndex = rlst.findIndex(item => item.label == type) |
||||
|
if (arrIndex > -1) {//一级分类名称正确
|
||||
|
if (departmentname) { |
||||
|
if (traindate) { |
||||
|
//区分2级是否记录
|
||||
|
if (rlst[arrIndex].children) { |
||||
|
const depIndex = rlst[arrIndex].children.findIndex(r => r.label == departmentname); |
||||
|
if (depIndex > -1) { |
||||
|
if (rlst[arrIndex].children[depIndex].children) { |
||||
|
rlst[arrIndex].children[depIndex].children.push({ |
||||
|
label: moment(traindate).format('YYYY-MM'), |
||||
|
value: id, |
||||
|
key: id, |
||||
|
}) |
||||
|
} else { |
||||
|
rlst[arrIndex].children[depIndex].children = [{ |
||||
|
label: moment(traindate).format('YYYY-MM'), |
||||
|
value: id, |
||||
|
key: id |
||||
|
}] |
||||
|
} |
||||
|
} else { |
||||
|
rlst[arrIndex].children.push({ |
||||
|
label: departmentname, |
||||
|
children: { |
||||
|
label: moment(traindate).format('YYYY-MM'), |
||||
|
value: id, |
||||
|
key: id |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} else { |
||||
|
rlst[arrIndex].children = [{ |
||||
|
label: departmentname, |
||||
|
children: [{ |
||||
|
label: moment(traindate).format('YYYY-MM'), |
||||
|
value: id, |
||||
|
key: id, |
||||
|
}] |
||||
|
}] |
||||
|
} |
||||
|
} else { |
||||
|
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; |
||||
|
} |
||||
|
} else { |
||||
|
rlst[arrIndex].children.push({ |
||||
|
label: departmentname, |
||||
|
value: id, |
||||
|
key: id |
||||
|
}) |
||||
|
} |
||||
|
} else { |
||||
|
rlst[arrIndex].children = [{ |
||||
|
label: departmentname, |
||||
|
value: id, |
||||
|
key: id |
||||
|
}] |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
ctx.status = 200; |
||||
|
ctx.body = rlst; |
||||
|
} catch (error) { |
||||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
||||
|
ctx.status = 400; |
||||
|
ctx.body = { |
||||
|
message: '查询培训资源储备库分类目录失败' |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
module.exports = { |
||||
|
getResourceClassify |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
'use strict'; |
||||
|
/**培训资料库 */ |
||||
|
const resourceRepository = require('../../controllers/resourceRepository'); |
||||
|
|
||||
|
module.exports = function (app, router, opts) { |
||||
|
|
||||
|
app.fs.api.logAttr['GET/train/trainFiles/resourceRepository/classify'] = { content: '查询培训资源储备库分类目录', visible: false }; |
||||
|
router.get('/train/trainFiles/resourceRepository/classify', resourceRepository.getResourceClassify); |
||||
|
}; |
Loading…
Reference in new issue