Selaa lähdekoodia

用户列表增加多条件模糊查询

zhangnaiwen 2 vuotta sitten
vanhempi
commit
55bb96b12d
2 muutettua tiedostoa jossa 5 lisäystä ja 5 poistoa
  1. 3 3
      src/app/api/users.py
  2. 2 2
      src/app/modle/users.py

+ 3 - 3
src/app/api/users.py

@@ -4,7 +4,7 @@ from io import BytesIO
 
 from flask import request, jsonify, Response, current_app
 from flask_restx import Resource, Namespace, reqparse
-from sqlalchemy import insert, select, update, delete, func
+from sqlalchemy import insert, select, update, delete, func, or_
 from sqlalchemy.orm import Session
 from werkzeug.datastructures import FileStorage
 
@@ -18,7 +18,7 @@ ns = Namespace('users', description='用户管理接口')
 
 get_users = reqparse.RequestParser(bundle_errors=True)
 get_users.add_argument(name='status', type=int, required=False, location='args', help='用户状态 0为正常,1为禁用')
-get_users.add_argument(name='name', type=str, required=False, location='args', help='过滤用户名')
+get_users.add_argument(name='filter', type=str, required=False, location='args', help='过滤值')
 get_users.add_argument(name='page_size', type=int, location='args', required=False, help='每页记录数量,默认:20')
 get_users.add_argument(name='page', type=int, location='args', required=False, help='第几页')
 
@@ -46,7 +46,7 @@ class GetUserListApi(Resource):
                 stmt = select(User).where(User.account_status == status)
 
                 if name:
-                    stmt = stmt.where(User.user_name.like("%{}%".format(name)))
+                    stmt = stmt.where(or_(User.user_name.like("%{}%".format(name)),User.phone.like("%{}%".format(name)), User.company.like("%{}%".format(name))))
 
                 stmt = stmt.offset(page_size * (page - 1)).limit(page_size)
 

+ 2 - 2
src/app/modle/users.py

@@ -1,4 +1,4 @@
-from sqlalchemy import String, Column, Integer
+from sqlalchemy import String, Column, Integer, INT
 from werkzeug.security import check_password_hash, generate_password_hash
 
 from app.modle import Base
@@ -14,7 +14,7 @@ class User(Base):
     password = Column(String, nullable=False, unique=False, index=False, doc='密码')
     photograph = Column(String, nullable=True, unique=False, index=False, doc='照片')
     name = Column(String, nullable=True, unique=False, index=False, doc='姓名')
-    phone = Column(Integer, nullable=True, unique=False, index=False, doc='电话')
+    phone = Column(String, nullable=True, unique=False, index=False, doc='电话')
     email = Column(String, nullable=True, unique=False, index=False, doc='邮箱')
     company = Column(String, nullable=True, unique=False, index=False, doc='公司')
     department = Column(String, nullable=True, unique=False, index=False, doc='部门')