feat: 更新国产沥青计算
This commit is contained in:
56
web/commons/models/data_network.py
Normal file
56
web/commons/models/data_network.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import datetime
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from sqlalchemy import Column, Integer, String, Date, UniqueConstraint, Numeric, Text
|
||||
|
||||
from commons.models.mixin.base import BaseModelMixin
|
||||
from commons.models.model import Model
|
||||
from core.extensions import db
|
||||
|
||||
|
||||
class DataNetwork(db.Model, Model, BaseModelMixin):
|
||||
__tablename__ = 'DATA_NETWORK'
|
||||
|
||||
id = Column('ID', Integer, primary_key=True)
|
||||
material_id = Column('MATERIAL_ID', String(128), comment='')
|
||||
spec = Column('SPEC', String(128), comment='')
|
||||
unit = Column('UNIT', String(128), comment='')
|
||||
brand = Column('BRAND', String(128), comment='')
|
||||
name = Column('NAME', String(128), comment='')
|
||||
price = Column('PRICE', Numeric(16, 4), comment='')
|
||||
source = Column('SOURCE', String(128), comment='')
|
||||
remark = Column('REMARK', Text, comment='')
|
||||
date = Column('DATE', Date, comment='')
|
||||
region = Column('REGION', String(64), comment='')
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint(name, spec, region, date, name='Idx_key'),
|
||||
{'comment': '网络数据'},
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def find_by_key(self):
|
||||
query = DataNetwork.query
|
||||
query = query.filter(DataNetwork.name == self.name)
|
||||
query = query.filter(DataNetwork.spec == self.spec)
|
||||
query = query.filter(DataNetwork.region == self.region)
|
||||
query = query.filter(DataNetwork.date == self.date)
|
||||
result = query.one_or_none()
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def get_query(cls, year, month, name, spec, region="福州"):
|
||||
start_date = datetime.date(year, month, 1)
|
||||
end_date = start_date + relativedelta(months=1)
|
||||
query = cls.query
|
||||
query = query.filter(cls.date >= start_date)
|
||||
query = query.filter(cls.date < end_date)
|
||||
if name:
|
||||
query = query.filter(cls.name == name)
|
||||
if spec:
|
||||
query = query.filter(cls.spec.like(f'%{spec}%'))
|
||||
if region:
|
||||
query = query.filter(cls.region.like(f'%{region}%'))
|
||||
return query
|
Reference in New Issue
Block a user