|
@@ -7,16 +7,15 @@ const xlsx = require('xlsx'); |
|
@@ -7,16 +7,15 @@ const xlsx = require('xlsx'); |
7
|
const mail = require('nodemailer');
|
7
|
const mail = require('nodemailer');
|
8
|
const moment = require('moment');
|
8
|
const moment = require('moment');
|
9
|
const smtpTransport = require('nodemailer-smtp-transport');
|
9
|
const smtpTransport = require('nodemailer-smtp-transport');
|
10
|
-const depart_names = ['创意', '活动', '技术', '零售', '媒体', '品牌', '上游资源', '市场会员', '运维', '战略发展'];
|
10
|
+const depart_names = ['活动', '技术', '零售', '媒体', '品牌', '上游资源', '市场会员', '运维', '战略发展'];
|
11
|
const ActivityModel = require('../../admin/models/activity');
|
11
|
const ActivityModel = require('../../admin/models/activity');
|
12
|
|
12
|
|
13
|
-let results = [[], [], [], [], [], [], [], [], [], []];
|
13
|
+let results = [[], [], [], [], [], [], [], [], []];
|
14
|
|
14
|
|
15
|
let loadExcel = function(path) {
|
15
|
let loadExcel = function(path) {
|
16
|
let workbook = xlsx.readFile(path);
|
16
|
let workbook = xlsx.readFile(path);
|
17
|
const sheetNames = workbook.SheetNames;
|
17
|
const sheetNames = workbook.SheetNames;
|
18
|
const worksheet = workbook.Sheets[sheetNames[0]];
|
18
|
const worksheet = workbook.Sheets[sheetNames[0]];
|
19
|
-
|
|
|
20
|
return Promise.resolve(xlsx.utils.sheet_to_json(worksheet));
|
19
|
return Promise.resolve(xlsx.utils.sheet_to_json(worksheet));
|
21
|
};
|
20
|
};
|
22
|
|
21
|
|
|
@@ -76,9 +75,9 @@ const excelLoader = { |
|
@@ -76,9 +75,9 @@ const excelLoader = { |
76
|
* @returns {Promise.<T>|*}
|
75
|
* @returns {Promise.<T>|*}
|
77
|
*/
|
76
|
*/
|
78
|
excelToXml(req, res, next) {
|
77
|
excelToXml(req, res, next) {
|
79
|
- return loadExcel('public/docs/user.xlsx').then(ret => {
|
78
|
+ return loadExcel('public/docs/users2019.xlsx').then(ret => {
|
80
|
_.each(ret, item => {
|
79
|
_.each(ret, item => {
|
81
|
- let depart_1 = item.depart_1; // 第一级部门
|
80
|
+ let depart_1 = item.block; // 第一级部门
|
82
|
|
81
|
|
83
|
for (let i = 0; i < depart_names.length; i++) { // 按部门归入相应的数组
|
82
|
for (let i = 0; i < depart_names.length; i++) { // 按部门归入相应的数组
|
84
|
if (depart_1.indexOf(depart_names[i]) >= 0) {
|
83
|
if (depart_1.indexOf(depart_names[i]) >= 0) {
|
|
@@ -92,7 +91,8 @@ const excelLoader = { |
|
@@ -92,7 +91,8 @@ const excelLoader = { |
92
|
'\t<data>\n';
|
91
|
'\t<data>\n';
|
93
|
|
92
|
|
94
|
_.each(results, item_arr => {
|
93
|
_.each(results, item_arr => {
|
95
|
- let xml_dep_f = '\t\t<department depid="0" name="' + item_arr[0].depart_1 +
|
94
|
+ console.log(item_arr.length);
|
|
|
95
|
+ let xml_dep_f = '\t\t<department depid="0" name="' + item_arr[0].block +
|
96
|
'" total="' + item_arr.length + '" prizes="0">\n';
|
96
|
'" total="' + item_arr.length + '" prizes="0">\n';
|
97
|
let xml_person = '';
|
97
|
let xml_person = '';
|
98
|
|
98
|
|
|
@@ -101,14 +101,14 @@ const excelLoader = { |
|
@@ -101,14 +101,14 @@ const excelLoader = { |
101
|
let xml_person_e = '\t\t\t</person>\n';
|
101
|
let xml_person_e = '\t\t\t</person>\n';
|
102
|
let depart_arr = [];
|
102
|
let depart_arr = [];
|
103
|
|
103
|
|
104
|
- if (item.depart_1) {
|
|
|
105
|
- depart_arr.push(item.depart_1);
|
104
|
+ if (item.block) {
|
|
|
105
|
+ depart_arr.push(item.block);
|
106
|
}
|
106
|
}
|
107
|
- if (item.depart_2) {
|
|
|
108
|
- depart_arr.push(item.depart_2);
|
107
|
+ if (item.center) {
|
|
|
108
|
+ depart_arr.push(item.center);
|
109
|
}
|
109
|
}
|
110
|
- if (item.depart_3) {
|
|
|
111
|
- depart_arr.push(item.depart_3);
|
110
|
+ if (item.depart) {
|
|
|
111
|
+ depart_arr.push(item.depart.replace(/\d/g, ''));
|
112
|
}
|
112
|
}
|
113
|
if (item.depart_4) {
|
113
|
if (item.depart_4) {
|
114
|
depart_arr.push(item.depart_4);
|
114
|
depart_arr.push(item.depart_4);
|
|
@@ -125,7 +125,6 @@ const excelLoader = { |
|
@@ -125,7 +125,6 @@ const excelLoader = { |
125
|
'\t\t\t\t<level>0</level>\n';
|
125
|
'\t\t\t\t<level>0</level>\n';
|
126
|
|
126
|
|
127
|
xml_person += xml_person_f + xml_person_content + xml_person_e;
|
127
|
xml_person += xml_person_f + xml_person_content + xml_person_e;
|
128
|
-
|
|
|
129
|
});
|
128
|
});
|
130
|
|
129
|
|
131
|
let xml_dep_e = '\t\t</department>\n';
|
130
|
let xml_dep_e = '\t\t</department>\n';
|
|
@@ -140,7 +139,7 @@ const excelLoader = { |
|
@@ -140,7 +139,7 @@ const excelLoader = { |
140
|
},
|
139
|
},
|
141
|
getExcelData(req, res) {
|
140
|
getExcelData(req, res) {
|
142
|
console.log(req);
|
141
|
console.log(req);
|
143
|
- return loadExcel('public/docs/user.xlsx').then(ret => {
|
142
|
+ return loadExcel('public/docs/users2019.xlsx').then(ret => {
|
144
|
res.json(ret);
|
143
|
res.json(ret);
|
145
|
});
|
144
|
});
|
146
|
},
|
145
|
},
|