Browse Source

人员id模糊查询

master
巴林闲侠 2 years ago
parent
commit
4e0b12031e
  1. 59
      api/app/lib/controllers/member/index.js
  2. 1
      api/app/lib/index.js
  3. 418
      api/app/lib/models/member.js
  4. 2
      api/app/lib/utils/member.js
  5. 6
      api/config.js

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

@ -221,7 +221,7 @@ async function list (ctx) {
) )
.replace(/_/g, '') .replace(/_/g, '')
} }
obj[nextKey] = u[k] obj[nextKey] = u[k] == '1970-01-01 00:00:00.000000' ? null : u[k]
} }
returnD.push({ returnD.push({
...obj, ...obj,
@ -234,7 +234,7 @@ async function list (ctx) {
name: u.roleName name: u.roleName
}] : [], }] : [],
del: undefined, del: undefined,
pepuserid: undefined pepuserid: undefined,
}) })
} }
}) })
@ -382,6 +382,7 @@ async function vacateStatistics (ctx) {
async function exportData (ctx) { async function exportData (ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { clickHouse, opts: { qiniu } } = ctx.app.fs
const { simpleExcelDown, memberList } = ctx.app.fs.utils const { simpleExcelDown, memberList } = ctx.app.fs.utils
const { keywordTarget, keyword, limit, page, state, keys = '' } = ctx.query const { keywordTarget, keyword, limit, page, state, keys = '' } = ctx.query
@ -391,6 +392,7 @@ async function exportData (ctx) {
const optionKeys = keys.split(',') const optionKeys = keys.split(',')
let exportD = [] let exportD = []
let pepUserIds = []
userRes.forEach(u => { userRes.forEach(u => {
let existUser = exportD.find(r => r.pepUserId == u.pepUserId) let existUser = exportD.find(r => r.pepUserId == u.pepUserId)
if (existUser) { if (existUser) {
@ -419,8 +421,9 @@ async function exportData (ctx) {
) )
.replace(/_/g, '') .replace(/_/g, '')
} }
obj[nextKey] = u[k] obj[nextKey] = u[k] == '1970-01-01 00:00:00.000000' ? null : u[k]
} }
pepUserIds.push(u.pepUserId)
exportD.push({ exportD.push({
...obj, ...obj,
departmrnt: u.depId ? [{ departmrnt: u.depId ? [{
@ -456,6 +459,56 @@ async function exportData (ctx) {
}) })
} }
} }
header = header.concat([{
title: '累计加班次数',
key: 'overTimeCount',
}, {
title: '累计加班总时长 / h',
key: 'overTimeDuration',
}, {
title: '累计请假次数',
key: 'vacateCount',
}, {
title: '累计请假总时长 / h',
key: 'vacateDuration',
},])
// 查询累计加班次数及总时长
const statisticOvertimeRes = await clickHouse.hr.query(`
SELECT
pep_user_id AS pepUserId,
count(id) AS count,
sum(duration) AS duration
FROM
overtime
WHERE pep_user_id IN (${pepUserIds.join(',')})
GROUP BY pep_user_id
`).toPromise()
const statisticVacateRes = await clickHouse.hr.query(`
SELECT
pep_user_id AS pepUserId,
count(id) AS count,
sum(duration) AS duration
FROM
vacate
WHERE pep_user_id IN (${pepUserIds.join(',')})
GROUP BY pep_user_id
`).toPromise()
exportD.forEach(d => {
d.departmrnt = d.departmrnt.map(dep => dep.name).join('、')
d.role = d.role.map(r => r.name).join('、')
d.idPhoto ? d.idPhoto = qiniu.domain + d.idPhoto : ''
d.vitae ? d.vitae = qiniu.domain + d.vitae : ''
const corOverTime = statisticOvertimeRes.find(so => so.pepUserId == d.pepUserId)
d.overTimeCount = corOverTime ? corOverTime.count : 0
d.overTimeDuration = corOverTime ? (corOverTime.duration / 3600).toFixed(1) : 0
const corVacate = statisticVacateRes.find(so => so.pepUserId == d.pepUserId)
d.vacateCount = corVacate ? corVacate.count : 0
d.vacateDuration = corVacate ? (corVacate.duration / 3600).toFixed(1) : 0
})
const fileName = `人员信息_${moment().format('YYYYMMDDHHmmss')}` + '.csv' const fileName = `人员信息_${moment().format('YYYYMMDDHHmmss')}` + '.csv'
const filePath = await simpleExcelDown({ data: exportD, header, fileName: fileName }) const filePath = await simpleExcelDown({ data: exportD, header, fileName: fileName })

1
api/app/lib/index.js

@ -16,6 +16,7 @@ module.exports.entry = function (app, router, opts) {
app.fs.logger.log('info', '[FS-AUTH]', 'Inject auth and api mv into router.'); app.fs.logger.log('info', '[FS-AUTH]', 'Inject auth and api mv into router.');
app.fs.api = app.fs.api || {}; app.fs.api = app.fs.api || {};
app.fs.opts = opts || {};
app.fs.utils = app.fs.utils || {}; app.fs.utils = app.fs.utils || {};
app.fs.api.authAttr = app.fs.api.authAttr || {}; app.fs.api.authAttr = app.fs.api.authAttr || {};
app.fs.api.logAttr = app.fs.api.logAttr || {}; app.fs.api.logAttr = app.fs.api.logAttr || {};

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

@ -2,213 +2,213 @@
'use strict'; 'use strict';
module.exports = dc => { 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", {
pepUserId: { pepUserId: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
allowNull: false, allowNull: false,
defaultValue: null, defaultValue: null,
comment: "项企用户id", comment: "项企用户id",
primaryKey: true, 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"
}, },
idNumber: { idNumber: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "证件号", comment: "证件号",
primaryKey: false, primaryKey: false,
field: "id_number", field: "id_number",
autoIncrement: false autoIncrement: false
}, },
idPhoto: { idPhoto: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "证件照", comment: "证件照",
primaryKey: false, primaryKey: false,
field: "id_photo", field: "id_photo",
autoIncrement: false autoIncrement: false
}, },
gender: { gender: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "性别", comment: "性别",
primaryKey: false, primaryKey: false,
field: "gender", field: "gender",
autoIncrement: false autoIncrement: false
}, },
birthday: { birthday: {
type: DataTypes.DATEONLY, type: DataTypes.DATEONLY,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "出生年月", comment: "出生年月",
primaryKey: false, primaryKey: false,
field: "birthday", field: "birthday",
autoIncrement: false autoIncrement: false
}, },
nativePlace: { nativePlace: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "籍贯", comment: "籍贯",
primaryKey: false, primaryKey: false,
field: "native_place", field: "native_place",
autoIncrement: false autoIncrement: false
}, },
marital: { marital: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "婚育状态", comment: "婚育状态",
primaryKey: false, primaryKey: false,
field: "marital", field: "marital",
autoIncrement: false autoIncrement: false
}, },
politicsStatus: { politicsStatus: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "整治面貌", comment: "整治面貌",
primaryKey: false, primaryKey: false,
field: "politics_status", field: "politics_status",
autoIncrement: false autoIncrement: false
}, },
phoneNumber: { phoneNumber: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: null, comment: '手机号码',
primaryKey: false, primaryKey: false,
field: "phone_number", field: "phone_number",
autoIncrement: false autoIncrement: false
}, },
workPlace: { workPlace: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "工作地点", comment: "工作地点",
primaryKey: false, primaryKey: false,
field: "work_place", field: "work_place",
autoIncrement: false autoIncrement: false
}, },
graduatedFrom: { graduatedFrom: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "毕业院校", comment: "毕业院校",
primaryKey: false, primaryKey: false,
field: "graduated_from", field: "graduated_from",
autoIncrement: false autoIncrement: false
}, },
educationBackground: { educationBackground: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "学历", comment: "学历",
primaryKey: false, primaryKey: false,
field: "education_background", field: "education_background",
autoIncrement: false autoIncrement: false
}, },
specialty: { specialty: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "专业", comment: "专业",
primaryKey: false, primaryKey: false,
field: "specialty", field: "specialty",
autoIncrement: false autoIncrement: false
}, },
graduationDate: { graduationDate: {
type: DataTypes.DATEONLY, type: DataTypes.DATEONLY,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "毕业时间", comment: "毕业时间",
primaryKey: false, primaryKey: false,
field: "graduation_date", field: "graduation_date",
autoIncrement: false autoIncrement: false
}, },
hiredate: { hiredate: {
type: DataTypes.DATEONLY, type: DataTypes.DATEONLY,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "入职时间", comment: "入职时间",
primaryKey: false, primaryKey: false,
field: "hiredate", field: "hiredate",
autoIncrement: false autoIncrement: false
}, },
turnProbationPeriod: { turnProbationPeriod: {
type: DataTypes.DATEONLY, type: DataTypes.DATEONLY,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "转试用期时间", comment: "转试用期时间",
primaryKey: false, primaryKey: false,
field: "turn_probation_period", field: "turn_probation_period",
autoIncrement: false autoIncrement: false
}, },
regularDate: { regularDate: {
type: DataTypes.DATEONLY, type: DataTypes.DATEONLY,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "转正时间", comment: "转正时间",
primaryKey: false, primaryKey: false,
field: "regular_date", field: "regular_date",
autoIncrement: false autoIncrement: false
}, },
dimissionDate: { dimissionDate: {
type: DataTypes.DATEONLY, type: DataTypes.DATEONLY,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "离职时间", comment: "离职时间",
primaryKey: false, primaryKey: false,
field: "dimission_date", field: "dimission_date",
autoIncrement: false autoIncrement: false
}, },
experienceYear: { experienceYear: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "工作经验/年", comment: "工作经验/年",
primaryKey: false, primaryKey: false,
field: "experience_year", field: "experience_year",
autoIncrement: false autoIncrement: false
}, },
occupationalHistory: { occupationalHistory: {
type: DataTypes.TEXT, type: DataTypes.TEXT,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "工作经历", comment: "工作经历",
primaryKey: false, primaryKey: false,
field: "occupational_history", field: "occupational_history",
autoIncrement: false autoIncrement: false
}, },
vitae: { vitae: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: "简历", comment: "简历",
primaryKey: false, primaryKey: false,
field: "vitae", field: "vitae",
autoIncrement: false autoIncrement: false
}, },
del: { del: {
type: DataTypes.BOOLEAN, type: DataTypes.BOOLEAN,
allowNull: true, allowNull: true,
defaultValue: null, defaultValue: null,
comment: null, comment: null,
primaryKey: false, primaryKey: false,
field: "del", field: "del",
autoIncrement: false autoIncrement: false
} }
}, { }, {
tableName: "member", tableName: "member",
comment: "", comment: "",
indexes: [] indexes: []
}); });
dc.models.Member = Member; dc.models.Member = Member;
return Member; return Member;
}; };

2
api/app/lib/utils/member.js

@ -67,7 +67,7 @@ module.exports = function (app, opts) {
INNER JOIN ${pepEmis}.user AS user INNER JOIN ${pepEmis}.user AS user
ON member.pep_user_id = user.id ON member.pep_user_id = user.id
${keywordTarget == 'number' && keyword ? ` ${keywordTarget == 'number' && keyword ? `
AND user.id LIKE '%${keyword}%' AND toString(user.id) LIKE '%${keyword}%'
`: ''} `: ''}
${keywordTarget == 'name' && keyword ? ` ${keywordTarget == 'name' && keyword ? `
AND user.name LIKE '%${keyword}%' AND user.name LIKE '%${keyword}%'

6
api/config.js

@ -107,6 +107,12 @@ const product = {
'INTERNALLY_TERMINATED' //流程异常结束 'INTERNALLY_TERMINATED' //流程异常结束
] ]
}, },
qiniu: {
domain: QINIU_DOMAIN_QNDMN_RESOURCE,
bucket: QINIU_BUCKET_RESOURCE,
accessKey: QINIU_AK,
secretKey: QINIU_SK
},
redis: { redis: {
host: IOTA_REDIS_SERVER_HOST, host: IOTA_REDIS_SERVER_HOST,
port: IOTA_REDIS_SERVER_PORT, port: IOTA_REDIS_SERVER_PORT,

Loading…
Cancel
Save