Browse Source

人员查询真分页

master
巴林闲侠 2 years ago
parent
commit
f0743ccc8e
  1. 9
      api/app/lib/controllers/member/index.js
  2. 54
      api/app/lib/utils/member.js

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

@ -209,7 +209,7 @@ async function list (ctx) {
const userRes = await memberList({ keywordTarget, keyword, limit, page, state })
let returnD = []
userRes.forEach(u => {
userRes.rows.forEach(u => {
let existUser = returnD.find(r => r.pepUserId == u.pepUserId)
if (existUser) {
if (u.depId && !existUser.departmrnt.some(d => d.id == u.depId)) {
@ -260,7 +260,10 @@ async function list (ctx) {
})
ctx.status = 200;
ctx.body = returnD
ctx.body = {
count: userRes.count,
rows: returnD
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
@ -413,7 +416,7 @@ async function exportData (ctx) {
let exportD = []
let pepUserIds = []
userRes.forEach(u => {
userRes.rows.forEach(u => {
let existUser = exportD.find(r => r.pepUserId == u.pepUserId)
if (existUser) {
if (u.depId && !existUser.departmrnt.some(d => d.id == u.depId)) {

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

@ -47,22 +47,8 @@ module.exports = function (app, opts) {
return []
}
}
const userRes = await clickHouse.hr.query(`
SELECT
hrMember."member.pep_user_id" AS pepUserId,
hrMember.*,
user.name AS userName,
role.name AS roleName,
role.id AS roleId,
department.name AS depName,
department.id AS depId
FROM (
SELECT
member.*,
hrVacate.vacateStartTime AS vacateStartTime,
hrVacate.vacateEndTime AS vacateEndTime,
hrOvertime.overtimeStartTime AS overtimeStartTime,
hrOvertime.overtimeEndTime AS overtimeEndTime
const innerSelectQuery = `
FROM member
INNER JOIN ${pepEmis}.user AS user
ON member.pep_user_id = user.id
@ -88,7 +74,7 @@ module.exports = function (app, opts) {
LEFT JOIN (
SELECT
pep_user_id,
any(toString(start_time)) AS overtimeStartTime,
any(start_time) AS overtimeStartTime,
any(end_time) AS overtimeEndTime
FROM overtime
WHERE
@ -118,9 +104,28 @@ module.exports = function (app, opts) {
AND department.name LIKE '%${keyword}%'
)
` : ''}
${state == 'dimission' ? `AND member.dimission_date IS NOT null` : ''}
${state == 'onJob' ? `AND member.dimission_date IS null` : ''}
${state == 'dimission' ? `AND member.dimission_date != '1970-01-01 00:00:00.000000'` : ''}
${state == 'onJob' ? `AND member.dimission_date = '1970-01-01 00:00:00.000000'` : ''}
${whereFromSelectOption.length ? `AND ${whereFromSelectOption.join('AND')}` : ''}
`
const userRes = await clickHouse.hr.query(`
SELECT
hrMember."member.pep_user_id" AS pepUserId,
hrMember.*,
user.name AS userName,
role.name AS roleName,
role.id AS roleId,
department.name AS depName,
department.id AS depId
FROM (
SELECT
member.*,
hrVacate.vacateStartTime AS vacateStartTime,
hrVacate.vacateEndTime AS vacateEndTime,
hrOvertime.overtimeStartTime AS overtimeStartTime,
hrOvertime.overtimeEndTime AS overtimeEndTime
${innerSelectQuery}
${limit ? `LIMIT ${limit}` : ''}
${limit && page ? 'OFFSET ' + parseInt(limit) * parseInt(page) : ''}
) AS hrMember
@ -138,9 +143,16 @@ module.exports = function (app, opts) {
${whereOption.length ? `WHERE ${whereOption.join(' AND ')}` : ''}
`).toPromise()
const countRes = await clickHouse.hr.query(`
SELECT
count(member.pep_user_id) AS count
${innerSelectQuery}
`).toPromise()
return userRes
return {
count: countRes[0].count,
rows: userRes
}
}
return {

Loading…
Cancel
Save