init
This commit is contained in:
35
web/commons/models/sanming_steel.py
Normal file
35
web/commons/models/sanming_steel.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import datetime
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from sqlalchemy import Column, Integer, String, Numeric, Date, UniqueConstraint
|
||||
|
||||
from core.extensions import db
|
||||
|
||||
|
||||
class SanmingSteel(db.Model):
|
||||
__tablename__ = 'SANMING_STEEL'
|
||||
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='材质')
|
||||
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, date, name='Idx_key'),
|
||||
{'comment': '三明钢铁'},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_query(cls, year, month, name, spec):
|
||||
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 == spec)
|
||||
return query
|
Reference in New Issue
Block a user