ww664853070 1 year ago
parent
commit
8678a0e5c5
  1. 50
      api/app/lib/controllers/attendance/index.js
  2. 18
      api/app/lib/controllers/departmentTrain/index.js
  3. 32
      api/app/lib/controllers/employeeCommunicate/index.js
  4. 17
      api/app/lib/controllers/personalTrain/index.js
  5. 49
      api/app/lib/controllers/userRole/index.js
  6. 8
      api/app/lib/models/role_resource.js
  7. 3
      api/app/lib/routes/userRole/index.js

50
api/app/lib/controllers/attendance/index.js

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const moment = require('moment') const moment = require('moment')
const fs = require('fs'); const fs = require('fs');
const { getDataRange } = require('../auth/index')
async function overtimeStatistic(ctx) { async function overtimeStatistic(ctx) {
try { try {
@ -12,6 +13,14 @@ async function overtimeStatistic(ctx) {
startDate, endDate, startDate, endDate,
} = ctx.query } = ctx.query
let dataRange = await getDataRange(ctx);
if (dataRange.userIds && dataRange.userIds.length === 0) {
ctx.status = 200;
ctx.body = {
count: 0,
rows: []
}
} else {
const userRes = await memberList({ const userRes = await memberList({
keywordTarget, keyword, limit, page, keywordTarget, keyword, limit, page,
orderBy, orderDirection, orderBy, orderDirection,
@ -20,6 +29,7 @@ async function overtimeStatistic(ctx) {
overtimeCountStatistic: true, overtimeCountStatistic: true,
overtimeCountStatisticStartDate: startDate, overtimeCountStatisticStartDate: startDate,
overtimeCountStatisticendDate: endDate, overtimeCountStatisticendDate: endDate,
userIds: dataRange.userIds
}) })
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) let { packageUser: returnD, pepUserIds } = await packageUserData(userRes)
@ -38,6 +48,7 @@ async function overtimeStatistic(ctx) {
count: userRes.count, count: userRes.count,
rows: returnD rows: returnD
} }
}
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
@ -56,7 +67,11 @@ async function exportOvertimeStatistic(ctx) {
keywordTarget, keyword, limit, page, orderBy, orderDirection, keywordTarget, keyword, limit, page, orderBy, orderDirection,
startDate, endDate, startDate, endDate,
} = ctx.query } = ctx.query
let returnD = null;
let dataRange = await getDataRange(ctx);
if (dataRange.userIds && dataRange.userIds.length === 0) {
returnD = [];
} else {
const userRes = await memberList({ const userRes = await memberList({
keywordTarget, keyword, limit, page, keywordTarget, keyword, limit, page,
orderBy, orderDirection, orderBy, orderDirection,
@ -65,10 +80,11 @@ async function exportOvertimeStatistic(ctx) {
overtimeCountStatistic: true, overtimeCountStatistic: true,
overtimeCountStatisticStartDate: startDate, overtimeCountStatisticStartDate: startDate,
overtimeCountStatisticendDate: endDate, overtimeCountStatisticendDate: endDate,
userIds: dataRange.userIds
}) })
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) let { packageUser, pepUserIds } = await packageUserData(userRes)
returnD = packageUser;
const sumRes = await overtimeStatisticListDayType({ const sumRes = await overtimeStatisticListDayType({
startDate, endDate, pepUserIds startDate, endDate, pepUserIds
}) })
@ -89,7 +105,7 @@ async function exportOvertimeStatistic(ctx) {
} }
} }
for (let overtimeTypeKey in overtimeType) { for (let overtimeTypeKey in overtimeType) {
d['sum' + overtimeTypeKey] = overtimeStatistic.reduce((sum, o) => { d['sum' + overtimeTypeKey] = overtimeStatistic((sum, o) => {
if (o.compensate == overtimeTypeKey) { if (o.compensate == overtimeTypeKey) {
sum += o.duration / 3600 sum += o.duration / 3600
// totalDuration += o.duration / 3600 // totalDuration += o.duration / 3600
@ -99,7 +115,7 @@ async function exportOvertimeStatistic(ctx) {
} }
d.totalDuration = totalDuration d.totalDuration = totalDuration
}) })
}
let overtimeTypeHeader = [] let overtimeTypeHeader = []
let sumOvertimeTypeHeader = [] let sumOvertimeTypeHeader = []
for (let overtimeTypeKey in overtimeType) { for (let overtimeTypeKey in overtimeType) {
@ -149,6 +165,7 @@ async function exportOvertimeStatistic(ctx) {
ctx.set('Content-Type', 'application/x-xls'); ctx.set('Content-Type', 'application/x-xls');
ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName)); ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName));
ctx.body = fileData; ctx.body = fileData;
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400; ctx.status = 400;
@ -188,6 +205,14 @@ async function vacateStatistic(ctx) {
startDate, endDate, startDate, endDate,
} = ctx.query } = ctx.query
let dataRange = await getDataRange(ctx);
if (dataRange.userIds && dataRange.userIds.length === 0) {
ctx.status = 200;
ctx.body = {
count: 0,
rows: []
}
} else {
const userRes = await memberList({ const userRes = await memberList({
keywordTarget, keyword, limit, page, keywordTarget, keyword, limit, page,
orderBy, orderDirection, orderBy, orderDirection,
@ -197,6 +222,7 @@ async function vacateStatistic(ctx) {
vacateCountStatistic: true, vacateCountStatistic: true,
vacateCountStatisticStartDate: startDate, vacateCountStatisticStartDate: startDate,
vacateCountStatisticendDate: endDate, vacateCountStatisticendDate: endDate,
userIds: dataRange.userIds
}) })
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) let { packageUser: returnD, pepUserIds } = await packageUserData(userRes)
@ -219,6 +245,7 @@ async function vacateStatistic(ctx) {
count: userRes.count, count: userRes.count,
rows: returnD rows: returnD
} }
}
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
@ -241,7 +268,11 @@ async function exportVacateStatistic(ctx) {
const vacateTypeRes = await clickHouse.hr.query(` const vacateTypeRes = await clickHouse.hr.query(`
SELECT type FROM vacate GROUP BY type ORDER BY type DESC SELECT type FROM vacate GROUP BY type ORDER BY type DESC
`).toPromise() `).toPromise()
let returnD = null;
let dataRange = await getDataRange(ctx);
if (dataRange.userIds && dataRange.userIds.length === 0) {
returnD = [];
} else {
const userRes = await memberList({ const userRes = await memberList({
keywordTarget, keyword, limit, page, keywordTarget, keyword, limit, page,
orderBy, orderDirection, orderBy, orderDirection,
@ -251,10 +282,11 @@ async function exportVacateStatistic(ctx) {
vacateCountStatistic: true, vacateCountStatistic: true,
vacateCountStatisticStartDate: startDate, vacateCountStatisticStartDate: startDate,
vacateCountStatisticendDate: endDate, vacateCountStatisticendDate: endDate,
userIds: dataRange.userIds
}) })
let { packageUser: returnD, pepUserIds } = await packageUserData(userRes) let { packageUser, pepUserIds } = await packageUserData(userRes)
returnD = packageUser;
const sumRes = await vacateStatisticListDayType({ const sumRes = await vacateStatisticListDayType({
startDate, endDate, pepUserIds startDate, endDate, pepUserIds
}) })
@ -279,7 +311,7 @@ async function exportVacateStatistic(ctx) {
let remarkData = remarkList.filter(e => e.pepUserId == u.pepUserId) let remarkData = remarkList.filter(e => e.pepUserId == u.pepUserId)
u.remark = remarkData.length ? (remarkData[0].remark == '' ? '无' : remarkData[0].remark) : '无' u.remark = remarkData.length ? (remarkData[0].remark == '' ? '无' : remarkData[0].remark) : '无'
}) })
}
const header = [{ const header = [{
title: '员工编号', title: '员工编号',
key: 'userCode', key: 'userCode',

18
api/app/lib/controllers/departmentTrain/index.js

@ -1,17 +1,25 @@
'use strict'; 'use strict';
const moment = require("moment/moment"); const moment = require("moment");
const { getDataRange } = require('../auth/index')
async function get(ctx) { async function get(ctx) {
try { try {
const { limit, page } = ctx.query; const { limit, page } = ctx.query;
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
let res = await models.DeptTraining.findAndCountAll({ const findObj = {
where: {}, where: {},
offset: Number(page) * Number(limit),
limit: Number(limit),
order: [['id', 'ASC']] order: [['id', 'ASC']]
}) };
let dataRange = await getDataRange(ctx);
if (dataRange.departmentNames) {
findObj.where.departmentName = { $in: dataRange.departmentNames || [] }
}
if (Number(limit) > 0 && Number(page) >= 0) {
findObj.limit = Number(limit);
findObj.offset = Number(page) * Number(limit);
}
let res = await models.DeptTraining.findAndCountAll(findObj)
ctx.status = 200; ctx.status = 200;
ctx.body = res; ctx.body = res;
} catch (error) { } catch (error) {

32
api/app/lib/controllers/employeeCommunicate/index.js

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const fs = require('fs'); const fs = require('fs');
const moment = require('moment'); const moment = require('moment');
const { getDataRange } = require('../auth/index')
/** /**
* 查询员工沟通统计数据 * 查询员工沟通统计数据
* @param {*} ctx ctx ctx.query:{keywordTarget-关键字项keyword-关键字内容timeRange-沟通时间limit-页宽, page-页码} * @param {*} ctx ctx ctx.query:{keywordTarget-关键字项keyword-关键字内容timeRange-沟通时间limit-页宽, page-页码}
@ -9,19 +10,26 @@ async function get(ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { keywordTarget, keyword, timeRange, limit, page } = ctx.query; const { keywordTarget, keyword, timeRange, limit, page } = ctx.query;
const where = {}; const findObj = {
where: {},
order: [['id', 'ASC']]
};
if (keywordTarget && keyword) { if (keywordTarget && keyword) {
where[keywordTarget] = { $iLike: `%${keyword}%` }; findObj.where[keywordTarget] = { $iLike: `%${keyword}%` };
} }
if (timeRange) { if (timeRange) {
where.communicateDate = { $between: timeRange.split(',') }; findObj.where.communicateDate = { $between: timeRange.split(',') };
} }
let employeeCommunicate = await models.EmployeeCommunicate.findAndCountAll({ let dataRange = await getDataRange(ctx);
where: where, //相较于用户所属部门,用户名称更少改动
offset: Number(page) * Number(limit), if (dataRange.userNames) {
limit: Number(limit), findObj.where.personalName = { $in: dataRange.userNames || [] }
order: [['id', 'ASC']] }
}); if (Number(limit) > 0 && Number(page) >= 0) {
findObj.limit = Number(limit);
findObj.offset = Number(page) * Number(limit);
}
let employeeCommunicate = await models.EmployeeCommunicate.findAndCountAll(findObj);
ctx.status = 200 ctx.status = 200
ctx.body = employeeCommunicate; ctx.body = employeeCommunicate;
} catch (error) { } catch (error) {
@ -55,7 +63,13 @@ async function exportData(ctx) {
header.push({ title: columnKeys[key], key: key }); header.push({ title: columnKeys[key], key: key });
attributes.push(key); attributes.push(key);
}) })
const where = {};
let dataRange = await getDataRange(ctx);
if (dataRange.userNames) {
where.personalName = { $in: dataRange.userNames || [] }
}
let exportData = await models.EmployeeCommunicate.findAll({ let exportData = await models.EmployeeCommunicate.findAll({
where: where,
attributes: attributes, attributes: attributes,
order: [['id', 'ASC']] order: [['id', 'ASC']]
}); });

17
api/app/lib/controllers/personalTrain/index.js

@ -1,14 +1,23 @@
'use strict'; 'use strict';
const { getDataRange } = require('../auth/index')
async function getPersonalTrainRecordList(ctx) { async function getPersonalTrainRecordList(ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { limit, page } = ctx.query; const { limit, page } = ctx.query;
let personalTrainDetail = await models.PersonalTraining.findAndCountAll({ const findObj = {
offset: Number(page) * Number(limit), where: {},
limit: Number(limit),
order: [['id', 'ASC']] order: [['id', 'ASC']]
}); };
let dataRange = await getDataRange(ctx);
if (dataRange.userNames) {
findObj.where.personalName = { $in: dataRange.userNames || [] }
}
if (Number(limit) > 0 && Number(page) >= 0) {
findObj.limit = Number(limit);
findObj.offset = Number(page) * Number(limit);
}
let personalTrainDetail = await models.PersonalTraining.findAndCountAll(findObj);
ctx.status = 200 ctx.status = 200
ctx.body = personalTrainDetail; ctx.body = personalTrainDetail;
} catch (error) { } catch (error) {

49
api/app/lib/controllers/userRole/index.js

@ -90,10 +90,59 @@ async function del(ctx) {
} }
} }
async function getUserResources(ctx) {
try {
const { adminHr } = ctx.fs.api.userInfo;
const { models } = ctx.fs.dc;
const { userId } = ctx.params;
let codes = [];
//人资管理员-所有权限
if (adminHr.some(admin => admin.id == userId)) {
const resource = await models.Resource.findAll({
attributes: ['code'],
order: [['id', 'asc']]
})
codes = resource.map(r => r.code);
} else {
const userResources = await models.RoleResource.findAll({
attributes: ['id', 'resId'],
include: [{
required: true,
model: models.Role,
attributes: [],
include: [{
model: models.UserRole,
attributes: [],
where: { userId: userId }
}],
}, {
required: true,
model: models.Resource,
attributes: ['id', 'name', 'code'],
}],
order: [['id', 'asc']]
});
let rslt = [];
userResources && userResources.map(ur => {
if (!rslt.some(r => r.id === ur.resId)) {
rslt.push(ur.resource);
codes.push(ur.resource.code);
}
})
}
ctx.status = 200;
ctx.body = codes;
} catch (error) {
ctx.fs.logger.error(`path:${ctx.path},error:${error}`)
ctx.status = 400;
ctx.body = { name: 'FindError', message: '获取用户角色资源失败' }
}
}
module.exports = { module.exports = {
get, get,
add, add,
edit, edit,
del, del,
getUserResources
} }

8
api/app/lib/models/role_resource.js

@ -39,5 +39,13 @@ module.exports = dc => {
indexes: [] indexes: []
}); });
dc.models.RoleResource = RoleResource; dc.models.RoleResource = RoleResource;
const Role = dc.models.Role;
RoleResource.belongsTo(Role, { foreignKey: 'roleId', targetKey: 'id' });
Role.hasMany(RoleResource, { foreignKey: 'roleId', sourceKey: 'id' });
const Resource = dc.models.Resource;
RoleResource.belongsTo(Resource, { foreignKey: 'resId', targetKey: 'id' });
Resource.hasMany(RoleResource, { foreignKey: 'resId', sourceKey: 'id' });
return RoleResource; return RoleResource;
}; };

3
api/app/lib/routes/userRole/index.js

@ -10,5 +10,8 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['POST/roleUser/add'] = { content: '角色添加用户成功', visible: true }; app.fs.api.logAttr['POST/roleUser/add'] = { content: '角色添加用户成功', visible: true };
router.post('/roleUser/add', userRole.add); router.post('/roleUser/add', userRole.add);
app.fs.api.logAttr['GET/user/:userId/role/resources'] = { content: '获取用户角色资源', visible: true };
router.get('/user/:userId/role/resources', userRole.getUserResources);
}; };
Loading…
Cancel
Save