From fc5a9a83a3ba24cbe42e55c9544f0e216352db72 Mon Sep 17 00:00:00 2001 From: wuaho Date: Wed, 8 Sep 2021 16:23:56 +0800 Subject: [PATCH] 1 --- api/api_v1/endpoints/query.py | 2 +- api/api_v1/endpoints/user.py | 7 +++++-- core/config.py | 7 +++++-- models/behavior_analysis.py | 18 +++++++++++++++++- schemas/user.py | 1 + 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/api/api_v1/endpoints/query.py b/api/api_v1/endpoints/query.py index 0b3bb03..cb933a1 100644 --- a/api/api_v1/endpoints/query.py +++ b/api/api_v1/endpoints/query.py @@ -45,7 +45,7 @@ async def event_model_sql( ) -> schemas.Msg: """ 事件分析模型 sql""" - await analysis.init() + await analysis.init(data_where=current_user.data_where) data = analysis.event_model_sql() return schemas.Msg(code=0, msg='ok', data=data) diff --git a/api/api_v1/endpoints/user.py b/api/api_v1/endpoints/user.py index 3621904..72f55f5 100644 --- a/api/api_v1/endpoints/user.py +++ b/api/api_v1/endpoints/user.py @@ -39,10 +39,13 @@ async def login( 'nickname': user.nickname, 'email': user.email, 'tel': user.tel, + + 'token': security.create_access_token( expires_delta=access_token_expires, _id=str(user.id), email=user.email, nickname=user.nickname, - is_superuser=user.is_superuser, name=user.name + is_superuser=user.is_superuser, name=user.name, + data_where=user.data_where, ), "token_type": "bearer", @@ -50,7 +53,7 @@ async def login( 'access_token': security.create_access_token( expires_delta=access_token_expires, _id=str(user.id), email=user.email, nickname=user.nickname, - is_superuser=user.is_superuser, name=user.name + is_superuser=user.is_superuser, name=user.name,data_where= user.data_where ), "token_type": "bearer", diff --git a/core/config.py b/core/config.py index 2b44459..9f02224 100644 --- a/core/config.py +++ b/core/config.py @@ -33,8 +33,8 @@ class Settings(BaseSettings): CK_CONFIG = {'host': '139.159.159.3', 'port': 9654, - 'user':'legu', - 'password':'gncPASUwpYrc' + 'user': 'legu', + 'password': 'gncPASUwpYrc' } CK_TYPE_DICT = {"DateTime('UTC')": 'datetime', @@ -191,6 +191,9 @@ class Settings(BaseSettings): }, { 'id': 'is null', 'title': '无值' + }, { + 'id': 'in', + 'title': '在列表里' }, # { # 'id': 'regex', diff --git a/models/behavior_analysis.py b/models/behavior_analysis.py index 5b5c95a..b8681ec 100644 --- a/models/behavior_analysis.py +++ b/models/behavior_analysis.py @@ -101,7 +101,8 @@ class BehaviorAnalysis: self.unit_num = None self.report_name = None - async def init(self): + async def init(self, *args, **kwargs): + if self.data_in.report_id: db = get_database() report = await crud.report.get(db, id=self.data_in.report_id) @@ -132,6 +133,10 @@ class BehaviorAnalysis: self.groupby = self._get_group_by() self.unit_num = self._get_unit_num() + # 用户自带过滤 + if 'data_where' in kwargs: + self.global_filters.extend(kwargs['data_where'].get(self.game, [])) + def _get_time_particle_size(self): return self.event_view.get('timeParticleSize') or 'P1D' @@ -218,6 +223,17 @@ class BehaviorAnalysis: elif comparator == 'is null': where.append(col.is_(None)) + elif comparator == 'like': + where.append(col.like(f'%{ftv[0]}%')) + + elif comparator == 'not like': + where.append(col.notlike(f'%{ftv[0]}%')) + + elif comparator == 'in': + where.append(col.in_(ftv)) + + + elif comparator == '!=': where.append(col != ftv[0]) diff --git a/schemas/user.py b/schemas/user.py index 4b2880b..f8af986 100644 --- a/schemas/user.py +++ b/schemas/user.py @@ -61,6 +61,7 @@ class UserDB(DBBase): nickname: str = '' tel: Any = '' last_login_ts: str = '尚未登录' + data_where: dict = dict() class UserDBRW(UserDB):