xlsx-service.js
1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Created by TaoHuang on 2017/5/17.
*/
const Context = require('../framework/context');
const xlsx2json = require('xlsx2json');
const Api = require('../common/api');
const _ = require('lodash');
const xlsxRead = (fileName) => {
return xlsx2json(fileName, {
dataStartingRow: 2,
mapping: {
productSkn: 'A',
productSku: 'B',
number: 'c'
}
});
};
class XlsxService extends Context {
constructor() {
super();
this.api = this.instance(Api);
}
handle(fileName) {
return xlsxRead(fileName).then((jsonArray) => {
let data = _.first(jsonArray);
if (!data) {
return {code: 500, message: '数据为空'};
}
if (data.length > 1000) {
return {code: 500, message: '数据超出限制'};
}
data = data.filter(d => d.productSkn && d.productSku && d.number);
return this.postJitStore(data);
});
}
postJitStore(params) {
let data = {
body: {
brandAuthData: null,
authLevel: true,
storageType: 3,
virtualInventoryBos: params
},
path: '/erp/importJitStorage'
};
return Promise.resolve(data);
}
}
module.exports = XlsxService;