61 lines
3.1 KiB
Python
61 lines
3.1 KiB
Python
from sqlalchemy import Column, Integer, String, Numeric
|
|
|
|
from commons.models.mixin.base import BaseModelMixin
|
|
from commons.models.mixin.operation_track import OperationTrackMixin
|
|
from core.extensions import db
|
|
|
|
|
|
class PriceResult(db.Model, OperationTrackMixin, BaseModelMixin):
|
|
id = Column('ID', Integer, primary_key=True)
|
|
material_id = Column('MATERIAL_ID', String(128), default='', comment='编号')
|
|
name = Column('NAME', String(128), default='', comment='材料名称')
|
|
year = Column('YEAR', Integer, default='', comment='统计年份')
|
|
month = Column('MONTH', Integer, default='', comment='统计月份')
|
|
price_ftb = Column('PRICE_FTB', Numeric(16, 4), default=0, comment='福州交通局价格')
|
|
fluctuating_ftb = Column('FLUCTUATING_FTB', Numeric(16, 4), default=0, comment='福州交通局浮动')
|
|
price_ss = Column('PRICE_SS', Numeric(16, 4), default=0, comment='三明钢铁价格')
|
|
fluctuating_ss = Column('FLUCTUATING_SS', Numeric(16, 4), default=0, comment='三明钢铁浮动')
|
|
price_fhb = Column('PRICE_FHB', Numeric(16, 4), default=0, comment='福州公路局价格')
|
|
fluctuating_fhb = Column('FLUCTUATING_FHB', Numeric(16, 4), default=0, comment='福州公路局浮动')
|
|
price_network = Column('PRICE_NETWORK', Numeric(16, 4), default=0, comment='网络价格')
|
|
fluctuating_network = Column('FLUCTUATING_NETWORK', Numeric(16, 4), default=0, comment='网络浮动')
|
|
price_survey = Column('PRICE_SURVEY', Numeric(16, 4), default=0, comment='调查价格')
|
|
fluctuating_survey = Column('FLUCTUATING_SURVEY', Numeric(16, 4), default=0, comment='调查浮动')
|
|
price_last_month = Column('PRICE_LAST_MONTH', Numeric(16, 4), default=0, comment='上月发布价格')
|
|
price_calculate = Column('PRICE_CALCULATE', Numeric(16, 4), default=0, comment='计算价格')
|
|
price_recommend = Column('PRICE_RECOMMEND', Numeric(16, 4), default=0, comment='推荐价格')
|
|
fluctuating_recommend = Column('FLUCTUATING_RECOMMEND', Numeric(16, 4), default=0, comment='推荐浮动')
|
|
spec = Column('SPEC', String(128), default='', comment='规格')
|
|
unit = Column('UNIT', String(128), default='', comment='单位')
|
|
|
|
__tablename__ = 'PRICE_RESULT'
|
|
__table_args__ = (
|
|
{'comment': '计算结果'},
|
|
)
|
|
|
|
@classmethod
|
|
def get_by_key(cls, name, year, month):
|
|
query = cls.query
|
|
query = query.filter(cls.name == name).filter(cls.year == year).filter(cls.month == month)
|
|
return query.one_or_none()
|
|
|
|
def find_by_key(self):
|
|
cls = self.__class__
|
|
query = cls.query
|
|
query = query.filter(cls.year == self.year)
|
|
query = query.filter(cls.month == self.month)
|
|
query = query.filter(cls.name == self.name)
|
|
result = query.one_or_none()
|
|
return result
|
|
|
|
@classmethod
|
|
def get_query(cls, year, month, name_in=None, name=None):
|
|
query = cls.query
|
|
query = query.filter(cls.year == year)
|
|
query = query.filter(cls.month == month)
|
|
if name_in:
|
|
query = query.filter(cls.name.in_(name_in))
|
|
if name:
|
|
query = query.filter(cls.name == name)
|
|
return query
|