Browse Source

添加和编辑人员接口

master
巴林闲侠 2 years ago
parent
commit
7bc2601620
  1. 75
      api/app/lib/controllers/member/index.js
  2. 5
      api/app/lib/index.js
  3. 21
      api/app/lib/models/member.js
  4. 10
      api/app/lib/routes/member/index.js
  5. 2
      api/sequelize-automate.config.js

75
api/app/lib/controllers/member/index.js

@ -1,10 +1,10 @@
'use strict'; 'use strict';
const moment = require('moment')
async function edit (ctx) { async function add (ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { const {
memberId,
pepUserId, idNumber, idPhoto, gender, birthday, nativePlace, marital, pepUserId, idNumber, idPhoto, gender, birthday, nativePlace, marital,
politicsStatus, phoneNumber, workPlace, graduatedFrom, educationBackground, specialty, graduationDate, hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory, vitae politicsStatus, phoneNumber, workPlace, graduatedFrom, educationBackground, specialty, graduationDate, hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory, vitae
} = ctx.request.body } = ctx.request.body
@ -15,18 +15,19 @@ async function edit (ctx) {
} }
}) })
if (existMemberRes && !memberId) { if (existMemberRes && !existMemberRes.del) {
throw '当前人员信息已存在' throw '当前人员信息已存在'
} }
let storageData = { let storageData = {
pepUserId, idNumber, idPhoto, gender, birthday, nativePlace, marital, pepUserId, idNumber, idPhoto, gender, birthday, nativePlace, marital,
politicsStatus, phoneNumber, workPlace, graduatedFrom, educationBackground, specialty, graduationDate, hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory, vitae politicsStatus, phoneNumber, workPlace, graduatedFrom, educationBackground, specialty, graduationDate, hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory, vitae,
del: false
} }
if (memberId) { if (existMemberRes && existMemberRes.del) {
await models.Member.update(storageData, { await models.Member.update(storageData, {
where: { where: {
id: memberId pepUserId,
} }
}) })
} else { } else {
@ -43,6 +44,46 @@ async function edit (ctx) {
} }
} }
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) { async function searchPepMember (ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
@ -109,7 +150,27 @@ async function searchPepMember (ctx) {
} }
} }
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 = { module.exports = {
add,
edit, edit,
searchPepMember searchPepMember,
list,
}; };

5
api/app/lib/index.js

@ -53,7 +53,10 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq
}); });
const { const {
Member, Vacate
} = dc.models; } = dc.models;
Vacate.belongsTo(Member, { foreignKey: 'pepUserId', targetKey: 'pepUserId' });
Member.hasMany(Vacate, { foreignKey: 'pepUserId', sourceKey: 'pepUserId' });
}; };

21
api/app/lib/models/member.js

@ -5,22 +5,12 @@ module.exports = dc => {
const DataTypes = dc.ORM; const DataTypes = dc.ORM;
const sequelize = dc.orm; const sequelize = dc.orm;
const Member = sequelize.define("member", { 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: { pepUserId: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
allowNull: false, allowNull: false,
defaultValue: null, defaultValue: null,
comment: "项企用户id", comment: "项企用户id",
primaryKey: false, primaryKey: true,
field: "pep_user_id", field: "pep_user_id",
autoIncrement: false, autoIncrement: false,
unique: "member_pep_user_id_uindex" unique: "member_pep_user_id_uindex"
@ -204,6 +194,15 @@ module.exports = dc => {
primaryKey: false, primaryKey: false,
field: "vitae", field: "vitae",
autoIncrement: false autoIncrement: false
},
del: {
type: DataTypes.BOOLEAN,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "del",
autoIncrement: false
} }
}, { }, {
tableName: "member", tableName: "member",

10
api/app/lib/routes/member/index.js

@ -3,9 +3,15 @@
const member = require('../../controllers/member'); const member = require('../../controllers/member');
module.exports = function (app, router, opts) { module.exports = function (app, router, opts) {
app.fs.api.logAttr['POST/member'] = { content: '添加/编辑人员信息', visible: true }; app.fs.api.logAttr['POST/member'] = { content: '添加人员信息', visible: true };
router.post('/member', member.edit); router.post('/member', member.add);
app.fs.api.logAttr['PUT/member'] = { content: '编辑人员信息', visible: true };
router.put('/member', member.edit);
app.fs.api.logAttr['GET/member/search'] = { content: '搜索项企用户', visible: true }; app.fs.api.logAttr['GET/member/search'] = { content: '搜索项企用户', visible: true };
router.get('/member/search', member.searchPepMember); router.get('/member/search', member.searchPepMember);
app.fs.api.logAttr['GET/member/list'] = { content: '查询人员列表', visible: true };
router.get('/member/list', member.list);
}; };

2
api/sequelize-automate.config.js

@ -26,7 +26,7 @@ module.exports = {
dir: './app/lib/models', // 指定输出 models 文件的目录 dir: './app/lib/models', // 指定输出 models 文件的目录
typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义 typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义
emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir` emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir`
tables: ['overtime'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 tables: ['member'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性
skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性 skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性
tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中 tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中
ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面 ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面

Loading…
Cancel
Save