From a3f815c3a4d21b9a96cb6dfacbc19e8327dab917 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Sun, 4 Feb 2024 16:28:46 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=E6=97=A5=E5=BF=97=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=A8=A1=E5=9D=97=E6=96=B0=E5=A2=9E=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module_admin/dao/log_dao.py | 17 +++++++++++++++-- .../module_admin/entity/vo/log_vo.py | 4 ++++ .../callbacks/monitor_c/logininfor_c.py | 11 ++++++++--- .../callbacks/monitor_c/operlog_c.py | 11 ++++++++--- .../views/monitor/logininfor/__init__.py | 4 ++++ .../views/monitor/operlog/__init__.py | 4 ++++ 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/dash-fastapi-backend/module_admin/dao/log_dao.py b/dash-fastapi-backend/module_admin/dao/log_dao.py index 92d347d..c5ee91b 100644 --- a/dash-fastapi-backend/module_admin/dao/log_dao.py +++ b/dash-fastapi-backend/module_admin/dao/log_dao.py @@ -1,3 +1,4 @@ +from sqlalchemy import asc, desc from sqlalchemy.orm import Session from module_admin.entity.do.log_do import SysOperLog, SysLogininfor from module_admin.entity.vo.log_vo import OperLogModel, LogininforModel, OperLogQueryModel, LoginLogQueryModel @@ -32,6 +33,12 @@ class OperationLogDao: :param query_object: 查询参数对象 :return: 操作日志列表信息对象 """ + if query_object.is_asc == 'ascend': + order_by_column = asc(getattr(SysOperLog, query_object.order_by_column, None)) + elif query_object.is_asc == 'descend': + order_by_column = desc(getattr(SysOperLog, query_object.order_by_column, None)) + else: + order_by_column = asc(SysOperLog.oper_time) operation_log_list = db.query(SysOperLog) \ .filter(SysOperLog.title.like(f'%{query_object.title}%') if query_object.title else True, SysOperLog.oper_name.like(f'%{query_object.oper_name}%') if query_object.oper_name else True, @@ -42,7 +49,7 @@ class OperationLogDao: datetime.combine(datetime.strptime(query_object.oper_time_end, '%Y-%m-%d'), time(23, 59, 59))) if query_object.oper_time_start and query_object.oper_time_end else True )\ - .distinct().all() + .distinct().order_by(order_by_column).all() return list_format_datetime(operation_log_list) @@ -96,6 +103,12 @@ class LoginLogDao: :param query_object: 查询参数对象 :return: 登录日志列表信息对象 """ + if query_object.is_asc == 'ascend': + order_by_column = asc(getattr(SysLogininfor, query_object.order_by_column, None)) + elif query_object.is_asc == 'descend': + order_by_column = desc(getattr(SysLogininfor, query_object.order_by_column, None)) + else: + order_by_column = asc(SysLogininfor.login_time) login_log_list = db.query(SysLogininfor) \ .filter(SysLogininfor.ipaddr.like(f'%{query_object.ipaddr}%') if query_object.ipaddr else True, SysLogininfor.user_name.like(f'%{query_object.user_name}%') if query_object.user_name else True, @@ -105,7 +118,7 @@ class LoginLogDao: datetime.combine(datetime.strptime(query_object.login_time_end, '%Y-%m-%d'), time(23, 59, 59))) if query_object.login_time_start and query_object.login_time_end else True )\ - .distinct().all() + .distinct().order_by(order_by_column).all() return list_format_datetime(login_log_list) diff --git a/dash-fastapi-backend/module_admin/entity/vo/log_vo.py b/dash-fastapi-backend/module_admin/entity/vo/log_vo.py index 64a999e..a8486e2 100644 --- a/dash-fastapi-backend/module_admin/entity/vo/log_vo.py +++ b/dash-fastapi-backend/module_admin/entity/vo/log_vo.py @@ -50,6 +50,8 @@ class OperLogQueryModel(OperLogModel): """ 操作日志管理不分页查询模型 """ + order_by_column: Optional[str] + is_asc: Optional[str] oper_time_start: Optional[str] oper_time_end: Optional[str] @@ -91,6 +93,8 @@ class LoginLogQueryModel(LogininforModel): """ 登录日志管理不分页查询模型 """ + order_by_column: Optional[str] + is_asc: Optional[str] login_time_start: Optional[str] login_time_end: Optional[str] diff --git a/dash-fastapi-frontend/callbacks/monitor_c/logininfor_c.py b/dash-fastapi-frontend/callbacks/monitor_c/logininfor_c.py index 1971c5b..4cec7c0 100644 --- a/dash-fastapi-frontend/callbacks/monitor_c/logininfor_c.py +++ b/dash-fastapi-frontend/callbacks/monitor_c/logininfor_c.py @@ -21,6 +21,7 @@ from api.log import get_login_log_list_api, delete_login_log_api, clear_login_lo inputs=dict( search_click=Input('login_log-search', 'nClicks'), refresh_click=Input('login_log-refresh', 'nClicks'), + sorter=Input('login_log-list-table', 'sorter'), pagination=Input('login_log-list-table', 'pagination'), operations=Input('login_log-operations-store', 'data') ), @@ -33,7 +34,7 @@ from api.log import get_login_log_list_api, delete_login_log_api, clear_login_lo ), prevent_initial_call=True ) -def get_login_log_table_data(search_click, refresh_click, pagination, operations, ipaddr, user_name, status_select, login_time_range, button_perms): +def get_login_log_table_data(search_click, refresh_click, sorter, pagination, operations, ipaddr, user_name, status_select, login_time_range, button_perms): """ 获取登录日志表格数据回调(进行表格相关增删查改操作后均会触发此回调) """ @@ -49,17 +50,21 @@ def get_login_log_table_data(search_click, refresh_click, pagination, operations status=status_select, login_time_start=login_time_start, login_time_end=login_time_end, + order_by_column=sorter.get('columns')[0] if sorter else None, + is_asc=sorter.get('orders')[0] if sorter else None, page_num=1, page_size=10 ) - triggered_id = dash.ctx.triggered_id - if triggered_id == 'login_log-list-table': + triggered_prop = dash.ctx.triggered[0].get('prop_id') + if triggered_prop == 'login_log-list-table.pagination': query_params = dict( ipaddr=ipaddr, user_name=user_name, status=status_select, login_time_start=login_time_start, login_time_end=login_time_end, + order_by_column=sorter.get('columns')[0] if sorter else None, + is_asc=sorter.get('orders')[0] if sorter else None, page_num=pagination['current'], page_size=pagination['pageSize'] ) diff --git a/dash-fastapi-frontend/callbacks/monitor_c/operlog_c.py b/dash-fastapi-frontend/callbacks/monitor_c/operlog_c.py index 4bd6aa3..b1e6252 100644 --- a/dash-fastapi-frontend/callbacks/monitor_c/operlog_c.py +++ b/dash-fastapi-frontend/callbacks/monitor_c/operlog_c.py @@ -23,6 +23,7 @@ from api.dict import query_dict_data_list_api inputs=dict( search_click=Input('operation_log-search', 'nClicks'), refresh_click=Input('operation_log-refresh', 'nClicks'), + sorter=Input('operation_log-list-table', 'sorter'), pagination=Input('operation_log-list-table', 'pagination'), operations=Input('operation_log-operations-store', 'data') ), @@ -36,7 +37,7 @@ from api.dict import query_dict_data_list_api ), prevent_initial_call=True ) -def get_operation_log_table_data(search_click, refresh_click, pagination, operations, title, oper_name, business_type, status_select, oper_time_range, button_perms): +def get_operation_log_table_data(search_click, refresh_click, sorter, pagination, operations, title, oper_name, business_type, status_select, oper_time_range, button_perms): """ 获取操作日志表格数据回调(进行表格相关增删查改操作后均会触发此回调) """ @@ -53,11 +54,13 @@ def get_operation_log_table_data(search_click, refresh_click, pagination, operat status=status_select, oper_time_start=oper_time_start, oper_time_end=oper_time_end, + order_by_column=sorter.get('columns')[0] if sorter else None, + is_asc=sorter.get('orders')[0] if sorter else None, page_num=1, page_size=10 ) - triggered_id = dash.ctx.triggered_id - if triggered_id == 'operation_log-list-table': + triggered_prop = dash.ctx.triggered[0].get('prop_id') + if triggered_prop == 'operation_log-list-table.pagination': query_params = dict( title=title, oper_name=oper_name, @@ -65,6 +68,8 @@ def get_operation_log_table_data(search_click, refresh_click, pagination, operat status=status_select, oper_time_start=oper_time_start, oper_time_end=oper_time_end, + order_by_column=sorter.get('columns')[0] if sorter else None, + is_asc=sorter.get('orders')[0] if sorter else None, page_num=pagination['current'], page_size=pagination['pageSize'] ) diff --git a/dash-fastapi-frontend/views/monitor/logininfor/__init__.py b/dash-fastapi-frontend/views/monitor/logininfor/__init__.py index bff7d37..55c9b37 100644 --- a/dash-fastapi-frontend/views/monitor/logininfor/__init__.py +++ b/dash-fastapi-frontend/views/monitor/logininfor/__init__.py @@ -331,6 +331,10 @@ def render(button_perms): rowSelectionType='checkbox', rowSelectionWidth=50, bordered=True, + sortOptions={ + 'sortDataIndexes': ['user_name', 'login_time'], + 'multiple': False + }, pagination={ 'pageSize': page_size, 'current': page_num, diff --git a/dash-fastapi-frontend/views/monitor/operlog/__init__.py b/dash-fastapi-frontend/views/monitor/operlog/__init__.py index 1ee38e0..8c1f3a7 100644 --- a/dash-fastapi-frontend/views/monitor/operlog/__init__.py +++ b/dash-fastapi-frontend/views/monitor/operlog/__init__.py @@ -361,6 +361,10 @@ def render(button_perms): rowSelectionType='checkbox', rowSelectionWidth=50, bordered=True, + sortOptions={ + 'sortDataIndexes': ['oper_name', 'oper_time'], + 'multiple': False + }, pagination={ 'pageSize': page_size, 'current': page_num, -- Gitee From 3bb3a6b4627aac55b93ea0105f69e732dec91dda Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Sun, 4 Feb 2024 16:35:16 +0800 Subject: [PATCH 2/5] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1cron=E8=A1=A8=E8=BE=BE=E5=BC=8F?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=A0=87=E5=87=86cron=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=86=99?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dash-fastapi-backend/config/get_scheduler.py | 46 ++++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/dash-fastapi-backend/config/get_scheduler.py b/dash-fastapi-backend/config/get_scheduler.py index 8ecad29..af1c633 100644 --- a/dash-fastapi-backend/config/get_scheduler.py +++ b/dash-fastapi-backend/config/get_scheduler.py @@ -20,11 +20,49 @@ class MyCronTrigger(CronTrigger): @classmethod def from_crontab(cls, expr, timezone=None): values = expr.split() - if len(values) != 7: - raise ValueError('Wrong number of fields; got {}, expected 7'.format(len(values))) + if len(values) != 6 and len(values) != 7: + raise ValueError('Wrong number of fields; got {}, expected 6 or 7'.format(len(values))) - return cls(second=values[0], minute=values[1], hour=values[2], day=values[3], month=values[4], - day_of_week=values[5], year=values[6], timezone=timezone) + second = values[0] + minute = values[1] + hour = values[2] + if '?' in values[3]: + day = None + elif 'L' in values[5]: + day = f"last {values[5].replace('L', '')}" + elif 'W' in values[3]: + day = cls.__find_recent_workday(int(values[3].split('W')[0])) + else: + day = values[3].replace('L', 'last') + month = values[4] + if '?' in values[5] or 'L' in values[5]: + week = None + elif '#' in values[5]: + week = int(values[5].split('#')[1]) + else: + week = values[5] + if '#' in values[5]: + day_of_week = int(values[5].split('#')[0]) - 1 + else: + day_of_week = None + year = values[6] if len(values) == 7 else None + return cls(second=second, minute=minute, hour=hour, day=day, month=month, week=week, + day_of_week=day_of_week, year=year, timezone=timezone) + + @classmethod + def __find_recent_workday(cls, day): + now = datetime.now() + date = datetime(now.year, now.month, day) + if date.weekday() < 5: + return date.day + else: + diff = 1 + while True: + previous_day = date - timedelta(days=diff) + if previous_day.weekday() < 5: + return previous_day.day + else: + diff += 1 job_stores = { -- Gitee From 6c9893de215ba70a950580adffdeadd482694f66 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Sun, 4 Feb 2024 16:36:27 +0800 Subject: [PATCH 3/5] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4sql=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1cron?= =?UTF-8?q?=E8=A1=A8=E8=BE=BE=E5=BC=8F=E6=8F=92=E5=85=A5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dash-fastapi-backend/sql/dash-fastapi.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dash-fastapi-backend/sql/dash-fastapi.sql b/dash-fastapi-backend/sql/dash-fastapi.sql index 2699e7e..8514d9d 100644 --- a/dash-fastapi-backend/sql/dash-fastapi.sql +++ b/dash-fastapi-backend/sql/dash-fastapi.sql @@ -260,9 +260,9 @@ CREATE TABLE `sys_job` ( -- ---------------------------- -- Records of sys_job -- ---------------------------- -INSERT INTO `sys_job` VALUES (1, '系统默认(无参)', 'default', 'default', 'module_task.scheduler_test.job', 'test', NULL, '0/10 * * * * * *', '2', '0', '1', 'admin', '2023-05-23 16:13:34', 'admin', '2023-05-23 16:13:34', ''); -INSERT INTO `sys_job` VALUES (2, '系统默认(有参)', 'sqlalchemy', 'default', 'module_task.scheduler_test.job', 'new', '{\"test\": 111}', '0/15 * * * * * *', '1', '1', '1', 'admin', '2023-05-23 16:13:34', 'admin', '2023-05-23 16:13:34', ''); -INSERT INTO `sys_job` VALUES (3, '系统默认(多参)', 'redis', 'default', 'module_task.scheduler_test.job', NULL, NULL, '0/20 * * * * * *', '3', '1', '1', 'admin', '2023-05-23 16:13:34', '', NULL, ''); +INSERT INTO `sys_job` VALUES (1, '系统默认(无参)', 'default', 'default', 'module_task.scheduler_test.job', 'test', NULL, '0/10 * * * * ?', '2', '0', '1', 'admin', '2023-05-23 16:13:34', 'admin', '2023-05-23 16:13:34', ''); +INSERT INTO `sys_job` VALUES (2, '系统默认(有参)', 'sqlalchemy', 'default', 'module_task.scheduler_test.job', 'new', '{\"test\": 111}', '0/15 * * * * ?', '1', '1', '1', 'admin', '2023-05-23 16:13:34', 'admin', '2023-05-23 16:13:34', ''); +INSERT INTO `sys_job` VALUES (3, '系统默认(多参)', 'redis', 'default', 'module_task.scheduler_test.job', NULL, NULL, '0/20 * * * * ?', '3', '1', '1', 'admin', '2023-05-23 16:13:34', '', NULL, ''); -- ---------------------------- -- Table structure for sys_job_log -- Gitee From af5b89e2b0ddfd39444ac5d25224bb0d8d758a0b Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Sun, 4 Feb 2024 16:42:59 +0800 Subject: [PATCH 4/5] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0requests?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=B8=BA2.31.0=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=AE=89=E5=85=A8=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 41f8638..dfbeb62 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,7 +17,7 @@ psutil==5.9.5 PyMySQL==1.0.3 python-jose[cryptography]==3.3.0 redis==5.0.1 -requests==2.30.0 +requests==2.31.0 SQLAlchemy==1.4.48 user-agents==2.2.0 waitress==2.1.2 -- Gitee From 402ad067194b457d83d507fa95485e02e5b7f105 Mon Sep 17 00:00:00 2001 From: insistence <3055204202@qq.com> Date: Sun, 4 Feb 2024 16:43:08 +0800 Subject: [PATCH 5/5] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0README=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bf347a4..5aa73da 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,18 @@