From 1e4c6658702e605c6ed3edfb15a102a03bc4053e Mon Sep 17 00:00:00 2001 From: han0 Date: Wed, 19 Mar 2025 14:37:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=90=8E=E6=9C=AA=E7=A7=BB=E9=99=A4=E5=A4=9A=E4=BD=99=E6=9D=90?= =?UTF-8?q?=E6=96=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/commons/models/price_publish.py | 4 ++++ web/commons/models/price_result.py | 4 ++++ web/tasks/once/calculate.py | 5 ++++- web/tasks/once/collect.py | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/web/commons/models/price_publish.py b/web/commons/models/price_publish.py index d773816..79a43f2 100644 --- a/web/commons/models/price_publish.py +++ b/web/commons/models/price_publish.py @@ -39,6 +39,10 @@ class PricePublish(db.Model, Model, OperationTrackMixin, BaseModelMixin): {'comment': '发布价格'}, ) + @classmethod + def clean(cls, year, month): + cls.query.filter(cls.year == year, cls.month == month).delete() + @classmethod def get_by_key(cls, name, year, month, type): query = cls.query diff --git a/web/commons/models/price_result.py b/web/commons/models/price_result.py index 6dd8ef3..b387fb0 100644 --- a/web/commons/models/price_result.py +++ b/web/commons/models/price_result.py @@ -43,6 +43,10 @@ class PriceResult(db.Model, Model, OperationTrackMixin, BaseModelMixin): {'comment': '计算结果'}, ) + @classmethod + def clean(cls, year, month): + cls.query.filter(cls.year == year, cls.month == month).delete() + @classmethod def get_by_key(cls, material_id, year, month): query = cls.query diff --git a/web/tasks/once/calculate.py b/web/tasks/once/calculate.py index c6384d0..92b5f21 100644 --- a/web/tasks/once/calculate.py +++ b/web/tasks/once/calculate.py @@ -1,5 +1,6 @@ from calculators import RoundMethod from commons.models.material import Material +from commons.models.price_result import PriceResult def calculate(year=2023, month=8): @@ -8,6 +9,8 @@ def calculate(year=2023, month=8): """ from calculators import Calculator + # 清空当月数据 + PriceResult.clean(year, month) # 从材料表获取趋势表所需的材料信息 for material in Material.query.all(): calculator = Calculator(year=year, month=month) @@ -36,7 +39,7 @@ if __name__ == '__main__': from core.factory import ClientApp with ClientApp().app_context(): - calculate(2024, 8) + calculate(2024, 7) # for i in range(2, 12): # calculate(2022, i+1) diff --git a/web/tasks/once/collect.py b/web/tasks/once/collect.py index ef954a8..c508eae 100644 --- a/web/tasks/once/collect.py +++ b/web/tasks/once/collect.py @@ -1,10 +1,12 @@ from collectors import Collector +from commons.models.price_publish import PricePublish def collect(year=2023, month=11): """ 整理发布价格 """ + PricePublish.clean(year, month) # 清空当月数据 collector = Collector(year, month) collector.run()