...
|
...
|
@@ -78,6 +78,8 @@ const task = async({productId, productCode, third}) => { |
|
|
if (sizeRelation[size]) {
|
|
|
const price = calcPrice(skusGroups[size]);
|
|
|
|
|
|
logger.info(`[price-day-task] skusGroups: ${JSON.stringify(skusGroups[size])}, price: ${price}`);
|
|
|
|
|
|
if (price > 0) {
|
|
|
return {
|
|
|
size,
|
...
|
...
|
@@ -90,11 +92,11 @@ const task = async({productId, productCode, third}) => { |
|
|
|
|
|
return {
|
|
|
productId,
|
|
|
price: Math.round(_.sumBy(_.filter(skus, s => s.price > 0), 'price') / skus.length) || 0,
|
|
|
price: Math.round(_.sumBy(skus, 'price') / skus.length) || 0,
|
|
|
skus,
|
|
|
};
|
|
|
} catch (error) {
|
|
|
logger.error(`[price-line-task], ${error}`);
|
|
|
logger.error(`[price-day-task] dayTask, ${error}`);
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -110,15 +112,25 @@ const report = (product, time) => { |
|
|
|
|
|
|
|
|
if (result) {
|
|
|
logger.info(`[price-line-task] insert success productId: ${product.productId}, sizeId: ${sku.sizeId}, price: ${sku.price}, sknPrice: ${product.price}, time: ${time}`);
|
|
|
logger.info(`[price-day-task] dayTask, insert success productId: ${product.productId}, sizeId: ${sku.sizeId}, price: ${sku.price}, sknPrice: ${product.price}, time: ${time}`);
|
|
|
} else {
|
|
|
logger.error(`[price-line-task] insert fail productId: ${product.productId}, sizeId: ${sku.sizeId}, price: ${sku.price}, sknPrice: ${product.price}, time: ${time}`);
|
|
|
logger.error(`[price-day-task] dayTask, insert fail productId: ${product.productId}, sizeId: ${sku.sizeId}, price: ${sku.price}, sknPrice: ${product.price}, time: ${time}`);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
module.exports = async() => {
|
|
|
const now = dayjs().startOf('hour').unix();
|
|
|
|
|
|
const resultExists = await mysqlPool.query('SELECT COUNT(*) AS Num FROM `price_trend_day` WHERE `create_time` = :createTime', {
|
|
|
createTime: now
|
|
|
});
|
|
|
|
|
|
if (_.first(resultExists).Num > 0) {
|
|
|
logger.info(`[price-day-task] dayTask, exists createtime price: ${now}`);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
const lockTask = lockup(task);
|
|
|
const products = await ProductRelationModel.findAll();
|
|
|
|
...
|
...
|
@@ -128,4 +140,3 @@ module.exports = async() => { |
|
|
report(result, now);
|
|
|
});
|
|
|
}; |
|
|
module.exports(); |
|
|
\ No newline at end of file |
...
|
...
|
|