From f7ebed19c50a20e107f13afc1f780e56540fb046 Mon Sep 17 00:00:00 2001 From: zhouxin Date: Tue, 20 Dec 2022 13:53:14 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E5=9F=B9=E8=AE=AD=E8=B5=84=E6=96=99?= =?UTF-8?q?=E5=BA=93=E4=BC=98=E5=8C=96=E5=B7=A6=E4=BE=A7=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E9=80=89=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/resourceRepository/index.js | 58 ++++++++++++++----- api/app/lib/models/training_information.js | 2 +- .../containers/resourceRepository.jsx | 1 + 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/api/app/lib/controllers/resourceRepository/index.js b/api/app/lib/controllers/resourceRepository/index.js index 40eee44..d5ec279 100644 --- a/api/app/lib/controllers/resourceRepository/index.js +++ b/api/app/lib/controllers/resourceRepository/index.js @@ -8,6 +8,7 @@ async function getResourceClassify(ctx) { rlst = [{ label: "公司培训资料", value: "company", key: "公司培训资料", operation: true, children: [] }, { label: "部门培训资料", value: 'dept', key: '部门培训资料', operation: false, children: [] }]; + const findObj = { order: [["departmentName", "asc"]] } const filterData = (arrayData, arrIndex, operation) => { if (arrayData.length) { for (let level of arrayData) { @@ -15,17 +16,18 @@ async function getResourceClassify(ctx) { /** departmentName:2级,trainDate:3级 */ if (departmentName) { if (trainDate) { + const trainDateLabel = 'object' == typeof trainDate ? moment(trainDate).format('YYYY-MM') : trainDate; const depKey = rlst[arrIndex].label + '/' + departmentName //区分2级是否记录 if (rlst[arrIndex].children) { 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'); + const dateKey = rlst[arrIndex].label + '/' + rlst[arrIndex].children[depIndex].label + '/' + trainDateLabel; if (rlst[arrIndex].children[depIndex].children) { 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'), + label: trainDateLabel, value: dateKey, key: dateKey, operation @@ -33,7 +35,7 @@ async function getResourceClassify(ctx) { } } else { rlst[arrIndex].children[depIndex].children = [{ - label: moment(trainDate).format('YYYY-MM'), + label: trainDateLabel, value: dateKey, key: dateKey, operation @@ -46,9 +48,9 @@ async function getResourceClassify(ctx) { key: depKey, operation, children: [{ - label: moment(trainDate).format('YYYY-MM'), - value: depKey + '/' + moment(trainDate).format('YYYY-MM'), - key: depKey + '/' + moment(trainDate).format('YYYY-MM'), + label: trainDateLabel, + value: depKey + '/' + trainDateLabel, + key: depKey + '/' + trainDateLabel, operation }] }); @@ -60,9 +62,9 @@ async function getResourceClassify(ctx) { key: depKey, operation, children: [{ - label: moment(trainDate).format('YYYY-MM'), - value: depKey + '/' + moment(trainDate).format('YYYY-MM'), - key: depKey + '/' + moment(trainDate).format('YYYY-MM'), + label: trainDateLabel, + value: depKey + '/' + trainDateLabel, + key: depKey + '/' + trainDateLabel, operation }] }] @@ -94,11 +96,11 @@ async function getResourceClassify(ctx) { } } - const deptTraining = await models.DeptTraining.findAll({}); + const deptTraining = await models.DeptTraining.findAll(findObj); if (deptTraining.length) { filterData(deptTraining, 1, false); } - const trainingInformation = await models.TrainingInformation.findAll({}); + const trainingInformation = await models.TrainingInformation.findAll(findObj); if (trainingInformation.length) { filterData(trainingInformation, 0, true); } @@ -113,7 +115,13 @@ async function getResourceClassify(ctx) { } } } - +/**查询培训资源储备库文件列表 + * query + * limit、offset + * type : 文件分类,必填,{公司培训资料/部门培训资料} + * departmentName:二级目录 + * trainDate:三级目录 + */ async function getResourceFileList(ctx, next) { try { const { models } = ctx.fs.dc; @@ -122,6 +130,7 @@ async function getResourceFileList(ctx, next) { if (["公司培训资料", "部门培训资料"].includes(type)) { const findObj = { attributes: ["id", "fileType", "fileName", "fileSize", "updateDate", "attachPath"], + order: [["departmentName", "desc"]] }; if (Number(limit) > 0 && Number(offset) >= 0) { findObj.limit = Number(limit); @@ -153,8 +162,31 @@ async function getResourceFileList(ctx, next) { ctx.body = { message: err.message || '查询培训资源储备库文件列表失败' } } } +async function postResourceClassify(ctx) { + try { + const { models } = ctx.fs.dc; + const { departmentName, trainDate } = ctx.request.body; + if (departmentName && '' != departmentName) { + const where = { + departmentName: departmentName + }; + if (trainDate && '' != trainDate) { + where.trainDate = trainDate; + } + const oldData = await models.TrainingInformation.findOne(where); + + } + + ctx.status = 204; + } catch (err) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { message: err.message || '查询培训资源储备库文件列表失败' } + } +} module.exports = { getResourceClassify, - getResourceFileList + getResourceFileList, + postResourceClassify } \ No newline at end of file diff --git a/api/app/lib/models/training_information.js b/api/app/lib/models/training_information.js index a48434f..4d9c61f 100644 --- a/api/app/lib/models/training_information.js +++ b/api/app/lib/models/training_information.js @@ -25,7 +25,7 @@ module.exports = dc => { autoIncrement: false }, trainDate: { - type: DataTypes.DATE, + type: DataTypes.STRING, allowNull: true, defaultValue: null, comment: null, diff --git a/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx b/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx index b1b108d..5fa3ef8 100644 --- a/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx +++ b/web/client/src/sections/humanAffairs/containers/resourceRepository.jsx @@ -113,6 +113,7 @@ const ResourceRepository = (props) => { defaultExpandAll={true} treeData={treeData} style={style} + value={currentSelect} expandedKeys={defaultExpandedKey} filterTreeNode={true} searchRender={false}