fix: 修复材料半年均价计算错误的问题
This commit is contained in:
@@ -3,7 +3,6 @@ import datetime
|
||||
from sqlalchemy import func
|
||||
|
||||
from calculators import Helper
|
||||
from commons.models.fujian_survey import FujianSurvey
|
||||
from commons.models.price_publish import PricePublish
|
||||
from commons.models.price_result import PriceResult
|
||||
from commons.models.material import Material
|
||||
@@ -25,6 +24,7 @@ class Collector:
|
||||
def get_avg(self):
|
||||
query = PricePublish.get_query(material_id_in=self.material_codes)
|
||||
query = PricePublish.query_previous_month(query, start_date=datetime.date(self.year, self.month, 1), count=6)
|
||||
query = query.filter(PricePublish.type == '1')
|
||||
query = query.with_entities(
|
||||
PricePublish.material_id,
|
||||
PricePublish.name,
|
||||
|
@@ -1,7 +1,8 @@
|
||||
import datetime
|
||||
from operator import and_
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from sqlalchemy import Column, Integer, String, Numeric
|
||||
from sqlalchemy import Column, Integer, String, Numeric, or_
|
||||
|
||||
from commons.models.mixin.base import BaseModelMixin
|
||||
from commons.models.mixin.operation_track import OperationTrackMixin
|
||||
@@ -71,10 +72,10 @@ class PricePublish(db.Model, Model, OperationTrackMixin, BaseModelMixin):
|
||||
@classmethod
|
||||
def query_previous_month(cls, query, start_date: datetime.date, count=6):
|
||||
condition = False
|
||||
for i in range(count):
|
||||
for i in range(0, count):
|
||||
date = start_date - relativedelta(months=i)
|
||||
condition = condition or (cls.year == date.year and cls.month == date.month)
|
||||
query.filter(condition)
|
||||
condition = or_(condition, and_(cls.year == str(date.year), cls.month == str(date.month)))
|
||||
query = query.filter(condition)
|
||||
return query
|
||||
|
||||
@classmethod
|
||||
|
@@ -15,11 +15,11 @@ if __name__ == '__main__':
|
||||
from core.factory import ClientApp
|
||||
|
||||
with ClientApp().app_context():
|
||||
collect(2023, 3)
|
||||
# collect(2025, 4)
|
||||
|
||||
# for i in range(2, 12):
|
||||
# collect(2022, i + 1)
|
||||
# for i in range(0, 12):
|
||||
# collect(2023, i + 1)
|
||||
# for i in range(5, 10):
|
||||
# collect(2024, i + 1)
|
||||
# for i in range(4):
|
||||
# collect(2025, i + 1)
|
||||
for i in range(9,12):
|
||||
collect(2023, i + 1)
|
||||
for i in range(12):
|
||||
collect(2024, i + 1)
|
||||
|
Reference in New Issue
Block a user