人力资源
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.

115 lines
3.2 KiB

'use strict';
async function edit (ctx) {
try {
const { models } = ctx.fs.dc;
const {
memberId,
pepUserId, idNumber, idPhoto, gender, birthday, nativePlace, marital,
politicsStatus, phoneNumber, workPlace, graduatedFrom, educationBackground, specialty, graduationDate, hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory, vitae
} = ctx.request.body
const existMemberRes = await models.Member.findOne({
where: {
pepUserId
}
})
if (existMemberRes && !memberId) {
throw '当前人员信息已存在'
}
let storageData = {
pepUserId, idNumber, idPhoto, gender, birthday, nativePlace, marital,
politicsStatus, phoneNumber, workPlace, graduatedFrom, educationBackground, specialty, graduationDate, hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory, vitae
}
if (memberId) {
await models.Member.update(storageData, {
where: {
id: memberId
}
})
} else {
await models.create(storageData)
}
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function searchPepMember (ctx) {
try {
const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs
const { keyword } = ctx.query
let whereOption = []
if (keyword) {
whereOption.push(`user.id = ${keyword}`)
whereOption.push(`user.name LIKE '${keyword}'`)
}
const userRes = await clickHouse.pepEmis.query(`
SELECT
user.id AS pepUserId,
user.name AS userName,
role.name AS roleName,
department.name AS depName
FROM
user
LEFT JOIN user_role
ON user_role.user = user.id
LEFT JOIN role
ON role.id = user_role.role
LEFT JOIN department_user
ON department_user.user = user.id
LEFT JOIN department
ON department.id = department_user.department
${whereOption.length ? `WHERE ${whereOption.join(' OR ')}` : ''}
`).toPromise()
let returnD = []
userRes.forEach(u => {
let existUser = returnD.find(r => r.pepUserId == u.pepUserId)
if (existUser) {
existUser.departmrnt.push({
name: u.depName
})
existUser.role.push({
name: u.roleName
})
} else {
returnD.push({
pepUserId: u.pepUserId,
name: u.userName,
departmrnt: [{
name: u.depName
}],
role: [{
name: u.roleName
}]
})
}
})
ctx.status = 200;
ctx.body = returnD
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
edit,
searchPepMember
};