巴林闲侠
2 years ago
8 changed files with 347 additions and 131 deletions
@ -0,0 +1,114 @@ |
|||||
|
'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 |
||||
|
}; |
@ -0,0 +1,215 @@ |
|||||
|
/* eslint-disable*/ |
||||
|
'use strict'; |
||||
|
|
||||
|
module.exports = dc => { |
||||
|
const DataTypes = dc.ORM; |
||||
|
const sequelize = dc.orm; |
||||
|
const Member = sequelize.define("member", { |
||||
|
id: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: true, |
||||
|
field: "id", |
||||
|
autoIncrement: true, |
||||
|
unique: "member_id_uindex" |
||||
|
}, |
||||
|
pepUserId: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: false, |
||||
|
defaultValue: null, |
||||
|
comment: "项企用户id", |
||||
|
primaryKey: false, |
||||
|
field: "pep_user_id", |
||||
|
autoIncrement: false, |
||||
|
unique: "member_pep_user_id_uindex" |
||||
|
}, |
||||
|
idNumber: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "证件号", |
||||
|
primaryKey: false, |
||||
|
field: "id_number", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
idPhoto: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "证件照", |
||||
|
primaryKey: false, |
||||
|
field: "id_photo", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
gender: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "性别", |
||||
|
primaryKey: false, |
||||
|
field: "gender", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
birthday: { |
||||
|
type: DataTypes.DATEONLY, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "出生年月", |
||||
|
primaryKey: false, |
||||
|
field: "birthday", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
nativePlace: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "籍贯", |
||||
|
primaryKey: false, |
||||
|
field: "native_place", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
marital: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "婚育状态", |
||||
|
primaryKey: false, |
||||
|
field: "marital", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
politicsStatus: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "整治面貌", |
||||
|
primaryKey: false, |
||||
|
field: "politics_status", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
phoneNumber: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: null, |
||||
|
primaryKey: false, |
||||
|
field: "phone_number", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
workPlace: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "工作地点", |
||||
|
primaryKey: false, |
||||
|
field: "work_place", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
graduatedFrom: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "毕业院校", |
||||
|
primaryKey: false, |
||||
|
field: "graduated_from", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
educationBackground: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "学历", |
||||
|
primaryKey: false, |
||||
|
field: "education_background", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
specialty: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "专业", |
||||
|
primaryKey: false, |
||||
|
field: "specialty", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
graduationDate: { |
||||
|
type: DataTypes.DATEONLY, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "毕业时间", |
||||
|
primaryKey: false, |
||||
|
field: "graduation_date", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
hiredate: { |
||||
|
type: DataTypes.DATEONLY, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "入职时间", |
||||
|
primaryKey: false, |
||||
|
field: "hiredate", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
turnProbationPeriod: { |
||||
|
type: DataTypes.DATEONLY, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "转试用期时间", |
||||
|
primaryKey: false, |
||||
|
field: "turn_probation_period", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
regularDate: { |
||||
|
type: DataTypes.DATEONLY, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "转正时间", |
||||
|
primaryKey: false, |
||||
|
field: "regular_date", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
dimissionDate: { |
||||
|
type: DataTypes.DATEONLY, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "离职时间", |
||||
|
primaryKey: false, |
||||
|
field: "dimission_date", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
experienceYear: { |
||||
|
type: DataTypes.INTEGER, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "工作经验/年", |
||||
|
primaryKey: false, |
||||
|
field: "experience_year", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
occupationalHistory: { |
||||
|
type: DataTypes.TEXT, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "工作经历", |
||||
|
primaryKey: false, |
||||
|
field: "occupational_history", |
||||
|
autoIncrement: false |
||||
|
}, |
||||
|
vitae: { |
||||
|
type: DataTypes.STRING, |
||||
|
allowNull: true, |
||||
|
defaultValue: null, |
||||
|
comment: "简历", |
||||
|
primaryKey: false, |
||||
|
field: "vitae", |
||||
|
autoIncrement: false |
||||
|
} |
||||
|
}, { |
||||
|
tableName: "member", |
||||
|
comment: "", |
||||
|
indexes: [] |
||||
|
}); |
||||
|
dc.models.Member = Member; |
||||
|
return Member; |
||||
|
}; |
@ -1,115 +0,0 @@ |
|||||
/* eslint-disable*/ |
|
||||
'use strict'; |
|
||||
|
|
||||
module.exports = dc => { |
|
||||
const DataTypes = dc.ORM; |
|
||||
const sequelize = dc.orm; |
|
||||
const User = sequelize.define("user", { |
|
||||
id: { |
|
||||
type: DataTypes.INTEGER, |
|
||||
allowNull: false, |
|
||||
defaultValue: null, |
|
||||
comment: null, |
|
||||
primaryKey: true, |
|
||||
field: "id", |
|
||||
autoIncrement: true, |
|
||||
unique: "user_id_uindex" |
|
||||
}, |
|
||||
pepUserId: { |
|
||||
type: DataTypes.INTEGER, |
|
||||
allowNull: false, |
|
||||
defaultValue: null, |
|
||||
comment: "项企对应用户id", |
|
||||
primaryKey: false, |
|
||||
field: "pep_user_id", |
|
||||
autoIncrement: false |
|
||||
}, |
|
||||
role: { |
|
||||
type: DataTypes.ARRAY(DataTypes.STRING), |
|
||||
allowNull: true, |
|
||||
defaultValue: null, |
|
||||
comment: "角色 也对应权限 admin 管理员 / all 全部角色 / data_analyst 数据分析 / after_sale 售后运维 / resource_manage 资源管理 / customer_service 客户服务", |
|
||||
primaryKey: false, |
|
||||
field: "role", |
|
||||
autoIncrement: false |
|
||||
}, |
|
||||
correlationProject: { |
|
||||
type: DataTypes.ARRAY(DataTypes.INTEGER), |
|
||||
allowNull: true, |
|
||||
defaultValue: null, |
|
||||
comment: "关联的poms的项目id", |
|
||||
primaryKey: false, |
|
||||
field: "correlation_project", |
|
||||
autoIncrement: false |
|
||||
}, |
|
||||
lastInTime: { |
|
||||
type: DataTypes.DATE, |
|
||||
allowNull: true, |
|
||||
defaultValue: null, |
|
||||
comment: null, |
|
||||
primaryKey: false, |
|
||||
field: "last_in_time", |
|
||||
autoIncrement: false |
|
||||
}, |
|
||||
inTimes: { |
|
||||
type: DataTypes.INTEGER, |
|
||||
allowNull: false, |
|
||||
defaultValue: "0", |
|
||||
comment: null, |
|
||||
primaryKey: false, |
|
||||
field: "in_times", |
|
||||
autoIncrement: false |
|
||||
}, |
|
||||
onlineDuration: { |
|
||||
type: DataTypes.INTEGER, |
|
||||
allowNull: true, |
|
||||
defaultValue: "0", |
|
||||
comment: "在线时长 单位 s", |
|
||||
primaryKey: false, |
|
||||
field: "online_duration", |
|
||||
autoIncrement: false |
|
||||
}, |
|
||||
lastInAddress: { |
|
||||
type: DataTypes.STRING, |
|
||||
allowNull: true, |
|
||||
defaultValue: null, |
|
||||
comment: "上次登录地点", |
|
||||
primaryKey: false, |
|
||||
field: "last_in_address", |
|
||||
autoIncrement: false |
|
||||
}, |
|
||||
disabled: { |
|
||||
type: DataTypes.BOOLEAN, |
|
||||
allowNull: false, |
|
||||
defaultValue: false, |
|
||||
comment: null, |
|
||||
primaryKey: false, |
|
||||
field: "disabled", |
|
||||
autoIncrement: false |
|
||||
}, |
|
||||
deleted: { |
|
||||
type: DataTypes.BOOLEAN, |
|
||||
allowNull: false, |
|
||||
defaultValue: false, |
|
||||
comment: null, |
|
||||
primaryKey: false, |
|
||||
field: "deleted", |
|
||||
autoIncrement: false |
|
||||
}, |
|
||||
updateTime: { |
|
||||
type: DataTypes.DATE, |
|
||||
allowNull: true, |
|
||||
defaultValue: sequelize.fn('now'), |
|
||||
comment: null, |
|
||||
primaryKey: false, |
|
||||
field: "update_time", |
|
||||
autoIncrement: false |
|
||||
} |
|
||||
}, { |
|
||||
tableName: "user", |
|
||||
comment: "", |
|
||||
indexes: [] |
|
||||
}); |
|
||||
dc.models.User = User; |
|
||||
return User; |
|
||||
}; |
|
@ -0,0 +1,11 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const member = require('../../controllers/member'); |
||||
|
|
||||
|
module.exports = function (app, router, opts) { |
||||
|
app.fs.api.logAttr['POST/member'] = { content: '添加/编辑人员信息', visible: true }; |
||||
|
router.post('/member', member.edit); |
||||
|
|
||||
|
app.fs.api.logAttr['GET/member/search'] = { content: '搜索项企用户', visible: true }; |
||||
|
router.get('/member/search', member.searchPepMember); |
||||
|
}; |
Loading…
Reference in new issue