From 6492daac6bc8c47fa391fa1303d4d4e8121f224a Mon Sep 17 00:00:00 2001 From: zhouxin Date: Sat, 17 Dec 2022 15:37:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=B9=E8=AE=AD=E8=B5=84=E6=96=99=E5=BA=93?= =?UTF-8?q?=EF=BC=9A=E5=B7=A6=E4=BE=A7=E5=88=86=E7=B1=BB=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/resourceRepository/index.js | 105 ++++++++++++++++++ .../lib/models/training_information_level.js | 6 +- .../lib/routes/resourceRepository/index.js | 9 ++ 3 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 api/app/lib/controllers/resourceRepository/index.js create mode 100644 api/app/lib/routes/resourceRepository/index.js diff --git a/api/app/lib/controllers/resourceRepository/index.js b/api/app/lib/controllers/resourceRepository/index.js new file mode 100644 index 0000000..f50c666 --- /dev/null +++ b/api/app/lib/controllers/resourceRepository/index.js @@ -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 +} \ No newline at end of file diff --git a/api/app/lib/models/training_information_level.js b/api/app/lib/models/training_information_level.js index ff753c2..888f6fc 100644 --- a/api/app/lib/models/training_information_level.js +++ b/api/app/lib/models/training_information_level.js @@ -28,16 +28,16 @@ module.exports = dc => { type: DataTypes.STRING, allowNull: false, defaultValue: null, - comment: null, + comment: '部门(2级目录)', primaryKey: false, field: "departmentname", autoIncrement: false }, traindate: { type: DataTypes.DATE, - allowNull: false, + allowNull: true, defaultValue: null, - comment: null, + comment: '培训时间(3级目录)', primaryKey: false, field: "traindate", autoIncrement: false diff --git a/api/app/lib/routes/resourceRepository/index.js b/api/app/lib/routes/resourceRepository/index.js new file mode 100644 index 0000000..0e5c58d --- /dev/null +++ b/api/app/lib/routes/resourceRepository/index.js @@ -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); +}; \ No newline at end of file