init
This commit is contained in:
44
web/commons/models/steel_rebar.py
Normal file
44
web/commons/models/steel_rebar.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import datetime
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Numeric, Date, UniqueConstraint, func
|
||||
|
||||
from calculators import Helper
|
||||
from commons.models.mixin.steel import SteelMixin
|
||||
from core.extensions import db
|
||||
|
||||
|
||||
class SteelRebar(db.Model, SteelMixin):
|
||||
__tablename__ = 'STEEL_REBAR'
|
||||
id = Column('ID', Integer, primary_key=True)
|
||||
name = Column('NAME', String(128), default='', comment='名称')
|
||||
spec = Column('SPEC', String(128), default='', comment='规格')
|
||||
material = Column('MATERIAL', String(64), default='', comment='材质')
|
||||
source = Column('SOURCE', String(64), default='', comment='产地')
|
||||
price = Column('PRICE', Numeric(16, 4), default=0, comment='价格')
|
||||
fluctuating = Column('FLUCTUATING', Numeric(16, 4), default=0, comment='浮动')
|
||||
date = Column('DATE', Date, comment='日期')
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint(name, spec, material, source, date, name='Idx_key'),
|
||||
{'comment': '钢筋'},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def query_by_month(cls, query, year, month):
|
||||
last_month_year, last_month = Helper.get_last_month(year, month)
|
||||
query = query.filter(cls.date >= datetime.date(last_month_year, last_month, 26))
|
||||
query = query.filter(cls.date <= datetime.date(year, month, 25))
|
||||
return query
|
||||
|
||||
@classmethod
|
||||
def get_items(cls, year, month, material, source='三钢闽光', name_in=('高线', '螺纹钢')):
|
||||
query = cls.query
|
||||
query = cls.query_by_month(query, year, month)
|
||||
query = query.filter(cls.material == material)
|
||||
query = query.filter(cls.source == source)
|
||||
query = query.filter(cls.name.in_(name_in))
|
||||
query = query.with_entities(cls.spec, cls.material, func.avg(cls.price))
|
||||
query = query.group_by(cls.spec, cls.material)
|
||||
result = query.all()
|
||||
|
||||
return result
|
Reference in New Issue
Block a user