classes.py 867 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # File : classes.py
  4. # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
  5. # Date : 2022/9/6
  6. from base.database import db
  7. from utils.log import logger
  8. from models.ruleclass import RuleClass
  9. def getClasses():
  10. if not db:
  11. msg = '未提供数据库连接'
  12. logger.info(msg)
  13. return []
  14. res = db.session.query(RuleClass).all()
  15. return [rc.name for rc in res]
  16. def getClassInfo(cls):
  17. if not db:
  18. msg = f'未提供数据库连接,获取{cls}详情失败'
  19. logger.info(msg)
  20. return None
  21. logger.info(f'开始查询{cls}的分类详情')
  22. res = db.session.query(RuleClass).filter(RuleClass.name == cls).first()
  23. if res:
  24. logger.info(str(res))
  25. return str(res)
  26. else:
  27. return f'数据库不存在{cls}的分类缓存'