Browse Source

人员添加接口

master
巴林闲侠 2 years ago
parent
commit
a68231c788
  1. 6
      api/.vscode/launch.json
  2. 114
      api/app/lib/controllers/member/index.js
  3. 215
      api/app/lib/models/member.js
  4. 115
      api/app/lib/models/user.js
  5. 11
      api/app/lib/routes/member/index.js
  6. 9
      api/app/lib/service/socket.js
  7. 6
      api/sequelize-automate.config.js
  8. 2
      web/package.json

6
api/.vscode/launch.json

@ -16,7 +16,7 @@
"-p 4700",
"-f http://localhost:4700",
//
"-g postgres://postgres:123@10.8.30.32:5432/orational_service",
"-g postgres://postgres:123@10.8.30.166:5432/hr-dev",
"--redisHost 10.8.30.112",
"--redisPort 6379",
// "--apiEmisUrl http://10.8.30.112:14000",
@ -24,9 +24,9 @@
"--apiEmisUrl http://10.8.30.161:1111",
"--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5",
"--qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa",
"--qnbkt dev-operational-service",
"--qnbkt dev-hr",
// "--qndmn http://resources.anxinyun.cn",
"--qndmn http://rhvqdivo5.hn-bkt.clouddn.com",
"--qndmn http://rjkwed13l.hn-bkt.clouddn.com",
// click
// "--clickHouseUrl http://10.8.30.71",
// click

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

@ -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
};

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

@ -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;
};

115
api/app/lib/models/user.js

@ -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;
};

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

@ -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);
};

9
api/app/lib/service/socket.js

@ -10,15 +10,6 @@ module.exports = async function factory (app, opts) {
const connectSeconds = moment().diff(moment(socket.handshake.time), 'seconds')
console.info('WEB_SOCKET token:' + socket.handshake.query.token + ' 已断开连接:' + reason + ' 连接时长:' + connectSeconds + 's');
const { models } = app.fs.dc
await models.User.increment({
onlineDuration: connectSeconds
}, {
where: {
id: socket.handshake.query.pomsUserId
}
})
})
})

6
api/sequelize-automate.config.js

@ -1,11 +1,11 @@
module.exports = {
// 数据库配置 与 sequelize 相同
dbOptions: {
database: 'orational_service',
database: 'hr-dev',
username: 'postgres',
password: '123',
dialect: 'postgres',
host: '10.8.30.32',
host: '10.8.30.166',
port: 5432,
define: {
underscored: false,
@ -26,7 +26,7 @@ module.exports = {
dir: './app/lib/models', // 指定输出 models 文件的目录
typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义
emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir`
tables: ['quick_link'], // 指定生成哪些表的 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_',] ,长度较长的 前缀放前面

2
web/package.json

@ -7,7 +7,7 @@
"test": "mocha",
"start-vite": "cross-env NODE_ENV=developmentVite npm run start-params",
"start": "cross-env NODE_ENV=development npm run start-params",
"start-params": "node server -p 5700 -u http://localhost:4700 --apiHrUrl http://localhost:4700 --qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5 --qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa --qnbkt dev-highways4good --qndmn http://rhvqdivo5.hn-bkt.clouddn.com",
"start-params": "node server -p 5700 -u http://localhost:4700 --apiHrUrl http://localhost:4700 --qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5 --qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa --qnbkt dev-hr --qndmn http://rjkwed13l.hn-bkt.clouddn.com",
"deploy": "export NODE_ENV=production&& npm run build && node server",
"build-dev": "cross-env NODE_ENV=development&&webpack --config webpack.config.js",
"build": "cross-env NODE_ENV=production&&webpack --config webpack.config.prod.js"

Loading…
Cancel
Save