export.js
1.56 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
60
61
62
const fs = require('fs');
const readline = require('readline');
const dayjs = require('dayjs');
const _ = require('lodash');
const date = process.argv[2];
const fileName = date ? date.match(/--d=(.*)/)[1] : dayjs().format('YYYY-MM-DD');
const yesFileName = date ? dayjs(date.match(/--d=(.*)/)[1]).subtract(1, 'day').format('YYYY-MM-DD') : dayjs().subtract(1, 'day').format('YYYY-MM-DD');
const fr = fs.createReadStream(`/Data/logs/node/prices/${fileName}.log`);
const yesfr = fs.createReadStream(`/Data/logs/node/prices/${yesFileName}.log`);
const rl = readline.createInterface({
input: fr
});
const yesrl = readline.createInterface({
input: yesfr
});
const allProducts = [];
const yesallProducts = [];
let product300 = [];
let yesProduct300 = [];
const diffDay = (products, yesAllProducts) => {
console.log('duid,sales,model,price');
products.forEach(findP => {
const yesFindP = yesAllProducts.find(p => p.productId === findP.productId);
if (findP && yesFindP) {
console.log(`${findP.productId},${findP.soldNum - yesFindP.soldNum},${findP.articleNumber},${parseInt(findP.price / 100, 10)}`);
}
});
};
rl.on('line', line => {
allProducts.push(JSON.parse(line));
});
rl.on('close', async() => {
product300 = _.take(_.orderBy(allProducts.filter(p => p.brandId !== 4981 && p.brandId !== 10065), 'soldNum', 'desc'), 300);
if (yesProduct300.length) {
diffDay(product300, yesProduct300);
}
});
yesrl.on('line', line => {
yesallProducts.push(JSON.parse(line));
});
yesrl.on('close', async() => {
diffDay(product300, yesallProducts);
});