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/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) { 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", 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