Browse Source

(*)假勤管理相关,员工沟通,个人培训记录模块数据范围控制

master
zmh 2 years ago
parent
commit
14b24a1034
  1. 50
      api/app/lib/controllers/attendance/index.js
  2. 32
      api/app/lib/controllers/employeeCommunicate/index.js
  3. 17
      api/app/lib/controllers/personalTrain/index.js

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

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

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

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

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

@ -1,14 +1,23 @@
'use strict';
const { getDataRange } = require('../auth/index')
async function getPersonalTrainRecordList(ctx) {
try {
const { models } = ctx.fs.dc;
const { limit, page } = ctx.query;
let personalTrainDetail = await models.PersonalTraining.findAndCountAll({
offset: Number(page) * Number(limit),
limit: Number(limit),
const findObj = {
where: {},
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.body = personalTrainDetail;
} catch (error) {

Loading…
Cancel
Save