|
|
|
'use strict';
|
|
|
|
const moment = require('moment')
|
|
|
|
|
|
|
|
async function add (ctx) {
|
|
|
|
try {
|
|
|
|
const { models } = ctx.fs.dc;
|
|
|
|
const {
|
|
|
|
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 && !existMemberRes.del) {
|
|
|
|
throw '当前人员信息已存在'
|
|
|
|
}
|
|
|
|
|
|
|
|
let storageData = {
|
|
|
|
pepUserId, idNumber, idPhoto, gender, birthday, nativePlace, marital,
|
|
|
|
politicsStatus, phoneNumber, workPlace, graduatedFrom, educationBackground, specialty, graduationDate, hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory, vitae,
|
|
|
|
del: false
|
|
|
|
}
|
|
|
|
if (existMemberRes && existMemberRes.del) {
|
|
|
|
await models.Member.update(storageData, {
|
|
|
|
where: {
|
|
|
|
pepUserId,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} 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 edit (ctx) {
|
|
|
|
try {
|
|
|
|
const { models } = ctx.fs.dc;
|
|
|
|
const {
|
|
|
|
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) {
|
|
|
|
throw '当前人员信息不存在'
|
|
|
|
}
|
|
|
|
|
|
|
|
let storageData = {
|
|
|
|
pepUserId, idNumber, idPhoto, gender, birthday, nativePlace, marital,
|
|
|
|
politicsStatus, phoneNumber, workPlace, graduatedFrom, educationBackground, specialty, graduationDate, hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory, vitae,
|
|
|
|
del: false
|
|
|
|
}
|
|
|
|
|
|
|
|
await models.Member.update(storageData, {
|
|
|
|
where: {
|
|
|
|
pepUserId: pepUserId
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function list (ctx) {
|
|
|
|
try {
|
|
|
|
const { models } = ctx.fs.dc;
|
|
|
|
const { clickHouse } = ctx.app.fs
|
|
|
|
const { keywordTarget, keyword, limit, page } = ctx.query
|
|
|
|
|
|
|
|
|
|
|
|
ctx.status = 200;
|
|
|
|
ctx.body = []
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = {
|
|
|
|
message: typeof error == 'string' ? error : undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
add,
|
|
|
|
edit,
|
|
|
|
searchPepMember,
|
|
|
|
list,
|
|
|
|
};
|