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. 2
      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, '')
}
obj[nextKey] = u[k]
obj[nextKey] = u[k] == '1970-01-01 00:00:00.000000' ? null : u[k]
}
returnD.push({
...obj,
@ -234,7 +234,7 @@ async function list (ctx) {
name: u.roleName
}] : [],
del: undefined,
pepuserid: undefined
pepuserid: undefined,
})
}
})
@ -382,6 +382,7 @@ async function vacateStatistics (ctx) {
async function exportData (ctx) {
try {
const { models } = ctx.fs.dc;
const { clickHouse, opts: { qiniu } } = ctx.app.fs
const { simpleExcelDown, memberList } = ctx.app.fs.utils
const { keywordTarget, keyword, limit, page, state, keys = '' } = ctx.query
@ -391,6 +392,7 @@ async function exportData (ctx) {
const optionKeys = keys.split(',')
let exportD = []
let pepUserIds = []
userRes.forEach(u => {
let existUser = exportD.find(r => r.pepUserId == u.pepUserId)
if (existUser) {
@ -419,8 +421,9 @@ async function exportData (ctx) {
)
.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({
...obj,
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 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.api = app.fs.api || {};
app.fs.opts = opts || {};
app.fs.utils = app.fs.utils || {};
app.fs.api.authAttr = app.fs.api.authAttr || {};
app.fs.api.logAttr = app.fs.api.logAttr || {};

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

@ -82,7 +82,7 @@ module.exports = dc => {
type: DataTypes.STRING,
allowNull: true,
defaultValue: null,
comment: null,
comment: '手机号码',
primaryKey: false,
field: "phone_number",
autoIncrement: false

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

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

6
api/config.js

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

Loading…
Cancel
Save