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()