人力资源
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

50 lines
1.6 KiB

'use strict';
const { getDataRange } = require('../auth/index')
async function getPersonalTrainRecordList(ctx) {
try {
const { models } = ctx.fs.dc;
const { limit, page } = ctx.query;
const findObj = {
where: {},
order: [['id', 'ASC']]
};
let dataRange = await getDataRange(ctx);
if (dataRange.userNames) {
findObj.where.personalName = { $in: dataRange.userNames || [] }
}
if (Number(limit) > 0 && Number(page) >= 0) {
findObj.limit = Number(limit);
findObj.offset = Number(page) * Number(limit);
}
let personalTrainDetail = await models.PersonalTraining.findAndCountAll(findObj);
ctx.status = 200
ctx.body = personalTrainDetail;
} catch (error) {
ctx.fs.logger.error(`path:${ctx.path},error:${error}`)
ctx.status = 400;
ctx.body = { name: 'FindError', message: '查询个人培训记录数据失败' }
}
}
async function importPersonalTrainData(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.PersonalTraining.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;
}
}
module.exports = {
getPersonalTrainRecordList,
importPersonalTrainData
}