|
|
@ -47,6 +47,68 @@ module.exports = function (app, opts) { |
|
|
|
return [] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const innerSelectQuery = ` |
|
|
|
FROM member |
|
|
|
INNER JOIN ${pepEmis}.user AS user |
|
|
|
ON member.pep_user_id = user.id |
|
|
|
${keywordTarget == 'number' && keyword ? ` |
|
|
|
AND toString(user.id) LIKE '%${keyword}%' |
|
|
|
`: ''}
|
|
|
|
${keywordTarget == 'name' && keyword ? ` |
|
|
|
AND user.name LIKE '%${keyword}%' |
|
|
|
`: ''}
|
|
|
|
${state == 'vacate' ? 'INNER' : 'LEFT'} JOIN ( |
|
|
|
SELECT |
|
|
|
pep_user_id, |
|
|
|
any(start_time) AS vacateStartTime, |
|
|
|
any(end_time) AS vacateEndTime |
|
|
|
FROM vacate |
|
|
|
WHERE |
|
|
|
start_time <= '${nowTime.format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
AND end_time > '${nowTime.format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
GROUP BY pep_user_id |
|
|
|
) AS hrVacate |
|
|
|
ON hrVacate.pep_user_id = member.pep_user_id |
|
|
|
|
|
|
|
LEFT JOIN ( |
|
|
|
SELECT |
|
|
|
pep_user_id, |
|
|
|
any(start_time) AS overtimeStartTime, |
|
|
|
any(end_time) AS overtimeEndTime |
|
|
|
FROM overtime |
|
|
|
WHERE |
|
|
|
start_time <= '${nowTime.format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
AND end_time > '${nowTime.format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
GROUP BY pep_user_id |
|
|
|
) AS hrOvertime |
|
|
|
ON hrOvertime.pep_user_id = member.pep_user_id |
|
|
|
|
|
|
|
WHERE |
|
|
|
member.del = 0 |
|
|
|
${keywordTarget == 'role' && keyword ? ` |
|
|
|
AND user.id IN ( |
|
|
|
SELECT user_role.user |
|
|
|
FROM ${pepEmis}.user_role AS user_role |
|
|
|
INNER JOIN ${pepEmis}.role AS role |
|
|
|
ON role.id = user_role.role |
|
|
|
AND role.name LIKE '%${keyword}%' |
|
|
|
) |
|
|
|
` : ''}
|
|
|
|
${keywordTarget == 'dep' && keyword ? ` |
|
|
|
AND user.id IN ( |
|
|
|
SELECT department_user.user |
|
|
|
FROM ${pepEmis}.department_user AS department_user |
|
|
|
INNER JOIN ${pepEmis}.department AS department |
|
|
|
ON department.id = department_user.department |
|
|
|
AND department.name LIKE '%${keyword}%' |
|
|
|
) |
|
|
|
` : ''}
|
|
|
|
${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, |
|
|
@ -63,64 +125,7 @@ module.exports = function (app, opts) { |
|
|
|
hrVacate.vacateEndTime AS vacateEndTime, |
|
|
|
hrOvertime.overtimeStartTime AS overtimeStartTime, |
|
|
|
hrOvertime.overtimeEndTime AS overtimeEndTime |
|
|
|
FROM member |
|
|
|
INNER JOIN ${pepEmis}.user AS user |
|
|
|
ON member.pep_user_id = user.id |
|
|
|
${keywordTarget == 'number' && keyword ? ` |
|
|
|
AND toString(user.id) LIKE '%${keyword}%' |
|
|
|
`: ''}
|
|
|
|
${keywordTarget == 'name' && keyword ? ` |
|
|
|
AND user.name LIKE '%${keyword}%' |
|
|
|
`: ''}
|
|
|
|
${state == 'vacate' ? 'INNER' : 'LEFT'} JOIN ( |
|
|
|
SELECT |
|
|
|
pep_user_id, |
|
|
|
any(start_time) AS vacateStartTime, |
|
|
|
any(end_time) AS vacateEndTime |
|
|
|
FROM vacate |
|
|
|
WHERE |
|
|
|
start_time <= '${nowTime.format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
AND end_time > '${nowTime.format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
GROUP BY pep_user_id |
|
|
|
) AS hrVacate |
|
|
|
ON hrVacate.pep_user_id = member.pep_user_id |
|
|
|
|
|
|
|
LEFT JOIN ( |
|
|
|
SELECT |
|
|
|
pep_user_id, |
|
|
|
any(toString(start_time)) AS overtimeStartTime, |
|
|
|
any(end_time) AS overtimeEndTime |
|
|
|
FROM overtime |
|
|
|
WHERE |
|
|
|
start_time <= '${nowTime.format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
AND end_time > '${nowTime.format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
GROUP BY pep_user_id |
|
|
|
) AS hrOvertime |
|
|
|
ON hrOvertime.pep_user_id = member.pep_user_id |
|
|
|
|
|
|
|
WHERE |
|
|
|
member.del = 0 |
|
|
|
${keywordTarget == 'role' && keyword ? ` |
|
|
|
AND user.id IN ( |
|
|
|
SELECT user_role.user |
|
|
|
FROM ${pepEmis}.user_role AS user_role |
|
|
|
INNER JOIN ${pepEmis}.role AS role |
|
|
|
ON role.id = user_role.role |
|
|
|
AND role.name LIKE '%${keyword}%' |
|
|
|
) |
|
|
|
` : ''}
|
|
|
|
${keywordTarget == 'dep' && keyword ? ` |
|
|
|
AND user.id IN ( |
|
|
|
SELECT department_user.user |
|
|
|
FROM ${pepEmis}.department_user AS department_user |
|
|
|
INNER JOIN ${pepEmis}.department AS department |
|
|
|
ON department.id = department_user.department |
|
|
|
AND department.name LIKE '%${keyword}%' |
|
|
|
) |
|
|
|
` : ''}
|
|
|
|
${state == 'dimission' ? `AND member.dimission_date IS NOT null` : ''} |
|
|
|
${state == 'onJob' ? `AND member.dimission_date IS null` : ''} |
|
|
|
${whereFromSelectOption.length ? `AND ${whereFromSelectOption.join('AND')}` : ''} |
|
|
|
${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 { |
|
|
|