#!/usr/bin/env python # -*- encoding: utf-8 -*- ''' @Date:2022/07/19 13:54:49 ''' from sqlalchemy import or_, desc from db_logic.db_base import Repository from models.warning_models import EntityWarning #预警信息业务逻辑类 class BllWarning(Repository): def __init__(self, entityType=EntityWarning): return super().__init__(entityType) #获取预警列表 def getWarningList(self,customerId,pageParam,keyWord=''): keyWord='%'+keyWord+'%' orm_query= self.findList().filter( EntityWarning.customer_id==customerId ).filter( or_(EntityWarning.object_name.like(keyWord), EntityWarning.warning_user_name.like(keyWord)) ).order_by(desc(EntityWarning.warning_date)) return self.queryPage(orm_query,pageParam) #获取预警类型数量 def getWarningCount(self): recordList=self.findList().all() # 过期预警列表 gqList = [record for record in recordList if record.object_type == '2'] # 余量预警列表 ylList = [record for record in recordList if record.object_type == '3'] return (len(recordList),len(gqList),len(ylList))