From 7bc2601620fd7048ba88b6a1444eb96aac86662c Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Fri, 14 Oct 2022 15:54:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=92=8C=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E4=BA=BA=E5=91=98=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/member/index.js | 75 ++++++++++++++++++++++--- api/app/lib/index.js | 5 +- api/app/lib/models/member.js | 21 ++++--- api/app/lib/routes/member/index.js | 10 +++- api/sequelize-automate.config.js | 2 +- 5 files changed, 91 insertions(+), 22 deletions(-) diff --git a/api/app/lib/controllers/member/index.js b/api/app/lib/controllers/member/index.js index 4e6f61d..3be89ba 100644 --- a/api/app/lib/controllers/member/index.js +++ b/api/app/lib/controllers/member/index.js @@ -1,10 +1,10 @@ 'use strict'; +const moment = require('moment') -async function edit (ctx) { +async function add (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 @@ -15,18 +15,19 @@ async function edit (ctx) { } }) - if (existMemberRes && !memberId) { + 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 + 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, { where: { - id: memberId + pepUserId, } }) } 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) { try { 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 = { + add, edit, - searchPepMember + searchPepMember, + list, }; \ No newline at end of file diff --git a/api/app/lib/index.js b/api/app/lib/index.js index 87abdb9..231b570 100644 --- a/api/app/lib/index.js +++ b/api/app/lib/index.js @@ -53,7 +53,10 @@ module.exports.models = function (dc) { // dc = { orm: Sequelize对象, ORM: Seq }); const { - + Member, Vacate } = dc.models; + Vacate.belongsTo(Member, { foreignKey: 'pepUserId', targetKey: 'pepUserId' }); + Member.hasMany(Vacate, { foreignKey: 'pepUserId', sourceKey: 'pepUserId' }); + }; diff --git a/api/app/lib/models/member.js b/api/app/lib/models/member.js index fd124f5..a3d4df6 100644 --- a/api/app/lib/models/member.js +++ b/api/app/lib/models/member.js @@ -5,22 +5,12 @@ 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, + primaryKey: true, field: "pep_user_id", autoIncrement: false, unique: "member_pep_user_id_uindex" @@ -204,6 +194,15 @@ module.exports = dc => { primaryKey: false, field: "vitae", autoIncrement: false + }, + del: { + type: DataTypes.BOOLEAN, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "del", + autoIncrement: false } }, { tableName: "member", diff --git a/api/app/lib/routes/member/index.js b/api/app/lib/routes/member/index.js index 0a6eaf0..489ef61 100644 --- a/api/app/lib/routes/member/index.js +++ b/api/app/lib/routes/member/index.js @@ -3,9 +3,15 @@ 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['POST/member'] = { content: '添加人员信息', visible: true }; + 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 }; router.get('/member/search', member.searchPepMember); + + app.fs.api.logAttr['GET/member/list'] = { content: '查询人员列表', visible: true }; + router.get('/member/list', member.list); }; \ No newline at end of file diff --git a/api/sequelize-automate.config.js b/api/sequelize-automate.config.js index e3207cc..3c6744b 100644 --- a/api/sequelize-automate.config.js +++ b/api/sequelize-automate.config.js @@ -26,7 +26,7 @@ module.exports = { dir: './app/lib/models', // 指定输出 models 文件的目录 typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义 emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir` - tables: ['overtime'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 + tables: ['member'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性 skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性 tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中 ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面