diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 56205c3..c723e45 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -28,9 +28,9 @@ // "--qndmn http://resources.anxinyun.cn", "--qndmn http://rjkwed13l.hn-bkt.clouddn.com", // click 开发 - // "--clickHouseUrl http://10.8.30.71", + "--clickHouseUrl http://10.8.30.71", // click 测试 - "--clickHouseUrl http://10.8.30.161", + // "--clickHouseUrl http://10.8.30.161", // "--clickHouseUrl https://clickhouse01.anxinyun.cn/play", "--clickHousePort 30123", @@ -38,9 +38,15 @@ // "--clickHouseUser ", // "--clickHousePassword ", - // 测试 - "--clickHousePepEmis pepca8", + // 开发 + "--clickHousePepEmis pepca10", "--clickHouseCamworkflow camworkflow", + "--clickHouseHr hr_dev", + + // 测试 + // "--clickHousePepEmis pepca8", + // "--clickHouseCamworkflow camworkflow", + // "--clickHouseHr hr_dev", ] }, { diff --git a/api/app/lib/controllers/member/index.js b/api/app/lib/controllers/member/index.js index 3be89ba..6b381f7 100644 --- a/api/app/lib/controllers/member/index.js +++ b/api/app/lib/controllers/member/index.js @@ -150,15 +150,123 @@ async function searchPepMember (ctx) { } } +async function del (ctx) { + try { + const { models } = ctx.fs.dc; + const { pepUserId } = ctx.query + + await models.Member.update({ + del: true, + }, { + where: { + pepUserId, + } + }) + + 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 list (ctx) { try { const { models } = ctx.fs.dc; const { clickHouse } = ctx.app.fs - const { keywordTarget, keyword, limit, page } = ctx.query + const { database: pepEmis } = clickHouse.pepEmis.opts.config + const { keywordTarget, keyword, limit, page, state } = ctx.query + + let whereOption = [] + if (state == 'dimission') { + whereOption.push(`member.dimission_date IS NOT null`) + } + const userRes = await clickHouse.hr.query(` + SELECT + member.pep_user_id AS pepUserId, + member.*, + user.name AS userName, + role.name AS roleName, + role.id AS roleId, + department.name AS depName, + department.id AS depId + FROM member + LEFT JOIN ${pepEmis}.user AS user + ON member.pep_user_id = user.id + LEFT JOIN ${pepEmis}.user_role AS user_role + ON ${pepEmis}.user_role.user = user.id + LEFT JOIN ${pepEmis}.role AS role + ON ${pepEmis}.role.id = user_role.role + LEFT JOIN ${pepEmis}.department_user AS department_user + ON department_user.user = user.id + LEFT JOIN ${pepEmis}.department AS department + ON department.id = department_user.department + ${state == 'vacate' ? 'INNER' : 'LEFT'} JOIN vacate + ON vacate.pep_user_id = member.pep_user_id + AND vacate.start_time <= '${moment().format('YYYY-MM-DD HH:mm:ss')}' + AND vacate.end_time > '${moment().format('YYYY-MM-DD HH:mm:ss')}' + ${whereOption.length ? `WHERE ${whereOption.join(' AND ')}` : ''} + ${limit ? `LIMIT ${limit}` : ''} + ${limit && page ? 'OFFSET ' + parseInt(limit) * parseInt(page) : ''} + `).toPromise() + let returnD = [] + userRes.forEach(u => { + if (u.overtimeId) { + let a = 1 + } + let existUser = returnD.find(r => r.pepUserId == u.pepUserId) + if (existUser) { + if (u.depId && !existUser.departmrnt.some(d => d.id == u.depId)) { + existUser.departmrnt.push({ + id: u.depId, + name: u.depName + }) + } + if (u.roleId && !existUser.role.some(r => r.id == u.roleId)) { + existUser.role.push({ + id: u.roleId, + name: u.roleName + }) + } + } else { + let obj = {} + for (let k in u) { + if (k.indexOf('member.') >= 0) { + obj[ + k.replace('member.', '') + // 变为小驼峰 + .toLowerCase() + .replace( + /(_)[a-z]/g, + (L) => L.toUpperCase() + ) + .replace(/_/g, '') + ] = u[k] + } else { + obj[k] = u[k] + } + } + returnD.push({ + ...obj, + departmrnt: u.depId ? [{ + id: u.depId, + name: u.depName + }] : [], + role: u.roleId ? [{ + id: u.roleId, + name: u.roleName + }] : [], + del: undefined, + }) + } + }) ctx.status = 200; - ctx.body = [] + ctx.body = returnD } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.status = 400; @@ -171,6 +279,7 @@ async function list (ctx) { module.exports = { add, edit, + del, searchPepMember, list, }; \ No newline at end of file diff --git a/api/app/lib/routes/member/index.js b/api/app/lib/routes/member/index.js index 489ef61..a3f5d12 100644 --- a/api/app/lib/routes/member/index.js +++ b/api/app/lib/routes/member/index.js @@ -9,6 +9,9 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['PUT/member'] = { content: '编辑人员信息', visible: true }; router.put('/member', member.edit); + app.fs.api.logAttr['DEL/member'] = { content: '删除人员信息', visible: true }; + router.del('/member', member.del); + app.fs.api.logAttr['GET/member/search'] = { content: '搜索项企用户', visible: true }; router.get('/member/search', member.searchPepMember); diff --git a/api/config.js b/api/config.js index 7f5b2c5..ef18ba1 100644 --- a/api/config.js +++ b/api/config.js @@ -29,6 +29,7 @@ args.option('clickHouseUrl', 'clickHouse Url'); args.option('clickHousePort', 'clickHouse Port'); args.option('clickHousePepEmis', 'clickHouse 项企数据库名称'); args.option('clickHouseCamworkflow', 'clickHouse 工作流数据库名称'); +args.option('clickHouseHr', 'clickHouse 人资数据库名称'); const flags = args.parse(process.argv); @@ -56,6 +57,7 @@ const CLICKHOUST_USER = process.env.CLICKHOUST_USER || flags.clickHouseUser const CLICKHOUST_PASSWORD = process.env.CLICKHOUST_PASSWORD || flags.clickHousePassword const CLICKHOUST_PEP_EMIS = process.env.CLICKHOUST_PEP_EMIS || flags.clickHousePepEmis const CLICKHOUST_CAM_WORKFLOW = process.env.CLICKHOUST_CAM_WORKFLOW || flags.clickHouseCamworkflow +const CLICKHOUST_HR = process.env.CLICKHOUST_HR || flags.clickHouseHr // timor 节假日查询 const API_TIMOR_URL = 'http://timor.tech/api/' @@ -66,7 +68,7 @@ if ( || !API_EMIS_URL || !QINIU_DOMAIN_QNDMN_RESOURCE || !QINIU_BUCKET_RESOURCE || !QINIU_AK || !QINIU_SK || !CLICKHOUST_URL || !CLICKHOUST_PORT - || !CLICKHOUST_PEP_EMIS || !CLICKHOUST_CAM_WORKFLOW + || !CLICKHOUST_PEP_EMIS || !CLICKHOUST_CAM_WORKFLOW || !CLICKHOUST_HR ) { console.log('缺少启动参数,异常退出'); args.showHelp(); @@ -143,6 +145,10 @@ const product = { { name: 'camWorkflow', db: CLICKHOUST_CAM_WORKFLOW + }, + { + name: 'hr', + db: CLICKHOUST_HR } ] } diff --git a/web/client/src/utils/webapi.js b/web/client/src/utils/webapi.js index e49acad..760d4fb 100644 --- a/web/client/src/utils/webapi.js +++ b/web/client/src/utils/webapi.js @@ -5,7 +5,7 @@ export const AxyRequest = new ProxyRequest("_axy"); export const EmisRequest = new ProxyRequest("_emis") export const webUtils = new customWebUtils({ - userKey: 'pomsUser' + userKey: 'hrUser' }); const { basicAction, RouteRequest } = webUtils export {