Browse Source

(*)员工沟通统计导出接口优化

master
zmh 2 years ago
parent
commit
41e4788ac9
  1. 11
      api/app/lib/controllers/employeeCommunicate/index.js
  2. 2
      api/app/lib/utils/xlsxDownload.js

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

@ -38,11 +38,6 @@ async function exportData(ctx) {
try {
const { models } = ctx.fs.dc;
const { simpleExcelDown } = ctx.app.fs.utils;
let exportData = await models.EmployeeCommunicate.findAll({
attributes: ['id', 'personalName', 'job', 'departmentName', 'communicateDate', 'communicateContent',
'communicateResult', 'valuation', 'communicateCondition', 'nextPlan'],
order: [['id', 'ASC']]
});
const columnKeys = {
personalName: '被沟通人',
job: '岗位',
@ -55,9 +50,15 @@ async function exportData(ctx) {
nextPlan: '下一步工作计划或提升方向'
}
let header = [];
let attributes = ['id'];
Object.keys(columnKeys).map(key => {
header.push({ title: columnKeys[key], key: key });
attributes.push(key);
})
let exportData = await models.EmployeeCommunicate.findAll({
attributes: attributes,
order: [['id', 'ASC']]
});
const fileName = `员工沟通统计_${moment().format('YYYYMMDDHHmmss')}` + '.xlsx'
const filePath = await simpleExcelDown({ data: exportData, header, fileName: fileName, format: 'YYYY-MM-DD', formatKey: 'communicateDate' })
const fileData = fs.readFileSync(filePath);

2
api/app/lib/utils/xlsxDownload.js

@ -60,7 +60,7 @@ module.exports = function (app, opts) {
for (let h of header) {
const cell = row.addCell();
if (format && formatKey && formatKey === h.key && data[i][h.key]) {
cell.value = moment(data[i][h.key]).format(format)
cell.value = moment(data[i][h.key]).format(format);
} else
cell.value = data[i][h.key] || h.defaultValue || '-';
cell.style = style

Loading…
Cancel
Save