From 205efcdaf41c243d06f9e68765db2cb0ed10fd71 Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Mon, 19 Dec 2022 14:45:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?(*)=E9=83=A8=E9=97=A8=E5=9F=B9=E8=AE=AD?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=9F=A5=E8=AF=A2=E3=80=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E3=80=81=E5=AF=BC=E5=85=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/departmentTrain/index.js | 50 +++++++++++++++++-- api/app/lib/routes/departmentTrain/index.js | 8 ++- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/api/app/lib/controllers/departmentTrain/index.js b/api/app/lib/controllers/departmentTrain/index.js index 8750087..02f14b8 100644 --- a/api/app/lib/controllers/departmentTrain/index.js +++ b/api/app/lib/controllers/departmentTrain/index.js @@ -1,8 +1,16 @@ 'use strict'; -async function getDepartmentTrainRecordList(ctx) { +async function get(ctx) { try { + const { limit, page } = ctx.query; + const models = ctx.fs.dc.models; + let res = await models.DeptTraining.findAndCountAll({ + where: {}, + offset: Number(page) * Number(limit), + limit: Number(limit), + order: [['id', 'ASC']] + }) ctx.status = 200; - ctx.body = {}; + ctx.body = res; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; @@ -10,9 +18,45 @@ async function getDepartmentTrainRecordList(ctx) { message: '查询部门培训记录列表失败' } } +} +async function importData(ctx) { + let errorMsg = { message: '导入部门培训记录信息失败' }; + const transaction = await ctx.fs.dc.orm.transaction(); + try { + const models = ctx.fs.dc.models; + const data = ctx.request.body; + await models.DeptTraining.bulkCreate(data, { transaction }); + await transaction.commit(); + ctx.status = 204; + } catch (error) { + await transaction.rollback(); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = errorMsg; + } } +async function modify(ctx) { + try { + const { models } = ctx.fs.dc; + const { id, ...rest } = ctx.request.body; + const existRes = await models.DeptTraining.findOne({ where: { id } }); + if (!existRes) { + throw '当前部门培训记录信息不存在'; + } + await models.DeptTraining.update({ ...rest }, { where: { id: id } }); + ctx.status = 204; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: '修改部门培训记录失败' + } + } +} module.exports = { - getDepartmentTrainRecordList + get, + importData, + modify } diff --git a/api/app/lib/routes/departmentTrain/index.js b/api/app/lib/routes/departmentTrain/index.js index d8458e5..d7635b2 100644 --- a/api/app/lib/routes/departmentTrain/index.js +++ b/api/app/lib/routes/departmentTrain/index.js @@ -5,5 +5,11 @@ const departmentTrain = require('../../controllers/departmentTrain'); module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/department/train/record/list'] = { content: '查询部门培训记录列表', visible: true }; - router.get('/department/train/record/list', departmentTrain.getDepartmentTrainRecordList); + router.get('/department/train/record/list', departmentTrain.get); + + app.fs.api.logAttr['POST/department/train/record/bulk'] = { content: '导入部门培训记录信息', visible: true }; + router.post('/department/train/record/bulk', departmentTrain.importData); + + app.fs.api.logAttr['PUT/department/train/record/modify'] = { content: '编辑部门培训记录信息', visible: true }; + router.put('/department/train/record/modify', departmentTrain.modify); }; \ No newline at end of file From 7a0b880e4153217b3a2926412429674669d4271c Mon Sep 17 00:00:00 2001 From: zhouxin Date: Mon, 19 Dec 2022 15:11:13 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=9F=B9=E8=AE=AD=E8=B5=84=E6=96=99?= =?UTF-8?q?=E5=BA=93=EF=BC=9A=E9=BB=98=E8=AE=A4=E4=B8=A4=E4=B8=AA=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/resourceRepository/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/app/lib/controllers/resourceRepository/index.js b/api/app/lib/controllers/resourceRepository/index.js index a9bd824..e3f9d95 100644 --- a/api/app/lib/controllers/resourceRepository/index.js +++ b/api/app/lib/controllers/resourceRepository/index.js @@ -11,11 +11,12 @@ async function getResourceClassify(ctx) { 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) { - rlst = [{ - label: "公司培训资料", value: "company", key: "company", operation: true, - }, { label: "部门培训资料", value: 'dept', key: 'dept', operation: false }]; + for (let level of trainingInformationLevel) { const { id, type, departmentname, traindate, origin } = level; @@ -96,6 +97,7 @@ async function getResourceClassify(ctx) { } } } + ctx.status = 200; ctx.body = rlst; } catch (error) { From f9a18592e9b21c3ea8164722fb58a688008bdf28 Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Mon, 19 Dec 2022 16:54:57 +0800 Subject: [PATCH 3/3] =?UTF-8?q?(*)=E9=83=A8=E9=97=A8=E5=9F=B9=E8=AE=AD?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E8=A1=A8=E7=BB=93=E6=9E=84=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/models/dept_training.js | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/api/app/lib/models/dept_training.js b/api/app/lib/models/dept_training.js index 302b399..f1e50e2 100644 --- a/api/app/lib/models/dept_training.js +++ b/api/app/lib/models/dept_training.js @@ -113,6 +113,42 @@ module.exports = dc => { primaryKey: false, field: "origin", autoIncrement: false + }, + fileSize: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "filesize", + autoIncrement: false + }, + fileName: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "filename", + autoIncrement: false + }, + fileType: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "filetype", + autoIncrement: false + }, + updateDate: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "updatedate", + autoIncrement: false } }, { tableName: "dept_training",