13 Commits

Author SHA1 Message Date
insistence
c415dfa8e1 !16 RuoYi-Vue3-FastAPI v1.3.2
Merge pull request !16 from insistence/develop
2024-08-08 01:38:22 +00:00
insistence
5765e967ae docs: 更新README文档 2024-08-08 09:28:33 +08:00
insistence
1ba4d959ce chore: 升级版本至1.3.2 2024-08-08 09:27:51 +08:00
insistence
df8ab6bc55 chore: 调整.gitignore策略 2024-08-08 09:24:09 +08:00
insistence
ca6668331f style: 优化添加中间件函数注释 2024-08-08 09:20:57 +08:00
insistence
d49d05b776 feat: 新增gzip压缩中间件 2024-08-08 09:18:07 +08:00
insistence
d8e3f7dca1 fix: 修复定时任务监听函数中事件没有job_id报错的问题 2024-08-07 14:41:57 +08:00
insistence
5ee1a64587 fix: 修复分页函数计算has_next错误的问题 #10 2024-08-02 10:27:06 +08:00
insistence
9a31c21943 !15 RuoYi-Vue3-FastAPI v1.3.1
Merge pull request !15 from insistence/develop
2024-07-31 03:24:06 +00:00
insistence
e52f0f42cb docs: 更新README文档 2024-07-31 11:14:38 +08:00
insistence
1f51525dfa chore: 升级版本至1.3.1 2024-07-31 11:13:57 +08:00
insistence
a1c77829cd perf: 补充定时任务违规字符串 2024-07-31 10:59:01 +08:00
insistence
07771c180d fix: 修复1.3.0版本采用新的异常处理机制后日志装饰器无法记录异常日志的问题 2024-07-27 16:31:01 +08:00
12 changed files with 126 additions and 53 deletions

1
.gitignore vendored
View File

@@ -18,6 +18,7 @@ lib64/
parts/
sdist/
var/
vf_admin/
wheels/
share/python-wheels/
*.egg-info/

View File

@@ -1,22 +1,17 @@
<p align="center">
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png">
</p>
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi-Vue3-FastAPI v1.3.0</h1>
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi-Vue3-FastAPI v1.3.2</h1>
<h4 align="center">基于RuoYi-Vue3+FastAPI前后端分离的快速开发框架</h4>
<p align="center">
<a href="https://gitee.com/insistence2022/RuoYi-Vue3-FastAPI/stargazers"><img src="https://gitee.com/insistence2022/RuoYi-Vue3-FastAPI/badge/star.svg?theme=dark"></a>
<a href="https://github.com/insistence/RuoYi-Vue3-FastAPI"><img src="https://img.shields.io/github/stars/insistence/RuoYi-Vue3-FastAPI?style=social"></a>
<a href="https://gitee.com/insistence2022/RuoYi-Vue3-FastAPI"><img src="https://img.shields.io/badge/RuoYiVue3FastAPI-v1.3.0-brightgreen.svg"></a>
<a href="https://gitee.com/insistence2022/RuoYi-Vue3-FastAPI"><img src="https://img.shields.io/badge/RuoYiVue3FastAPI-v1.3.2-brightgreen.svg"></a>
<a href="https://gitee.com/insistence2022/RuoYi-Vue3-FastAPI/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
<img src="https://img.shields.io/badge/python-≥3.8-blue">
<img src="https://img.shields.io/badge/python-≥3.9-blue">
<img src="https://img.shields.io/badge/MySQL-≥5.7-blue">
</p>
## 平台简介
RuoYi-Vue3-FastAPI是一套全部开源的快速开发平台毫无保留给个人及企业免费使用。

View File

@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
# 应用端口
APP_PORT = 9099
# 应用版本
APP_VERSION= '1.3.0'
APP_VERSION= '1.3.2'
# 应用是否开启热重载
APP_RELOAD = true
# 应用是否开启IP归属区域查询

View File

@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
# 应用端口
APP_PORT = 9099
# 应用版本
APP_VERSION= '1.3.0'
APP_VERSION= '1.3.2'
# 应用是否开启热重载
APP_RELOAD = false
# 应用是否开启IP归属区域查询

View File

@@ -76,7 +76,7 @@ class JobConstant:
"""
定时任务常量
JOB_ERROR_LIST: 定时任务禁止调用模块列表
JOB_ERROR_LIST: 定时任务禁止调用模块及违规字符串列表
JOB_WHITE_LIST: 定时任务允许调用模块列表
"""
@@ -84,11 +84,46 @@ class JobConstant:
'app',
'config',
'exceptions',
'import ',
'middlewares',
'module_admin',
'open(',
'os.',
'server',
'sub_applications',
'subprocess.',
'sys.',
'utils',
'while ',
'__import__',
'"',
"'",
',',
'?',
':',
';',
'/',
'|',
'+',
'-',
'=',
'~',
'!',
'#',
'$',
'%',
'^',
'&',
'*',
'<',
'>',
'(',
')',
'[',
']',
'{',
'}',
' ',
]
JOB_WHITE_LIST = ['module_task']

View File

@@ -221,39 +221,40 @@ class SchedulerUtil:
if event_type == 'JobExecutionEvent' and event.exception:
exception_info = str(event.exception)
status = '1'
job_id = event.job_id
query_job = cls.get_scheduler_job(job_id=job_id)
if query_job:
query_job_info = query_job.__getstate__()
# 获取任务名称
job_name = query_job_info.get('name')
# 获取任务组名
job_group = query_job._jobstore_alias
# 获取任务执行器
job_executor = query_job_info.get('executor')
# 获取调用目标字符串
invoke_target = query_job_info.get('func')
# 获取调用函数位置参数
job_args = ','.join(query_job_info.get('args'))
# 获取调用函数关键字参数
job_kwargs = json.dumps(query_job_info.get('kwargs'))
# 获取任务触发器
job_trigger = str(query_job_info.get('trigger'))
# 构造日志消息
job_message = f"事件类型: {event_type}, 任务ID: {job_id}, 任务名称: {job_name}, 执行于{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
job_log = JobLogModel(
jobName=job_name,
jobGroup=job_group,
jobExecutor=job_executor,
invokeTarget=invoke_target,
jobArgs=job_args,
jobKwargs=job_kwargs,
jobTrigger=job_trigger,
jobMessage=job_message,
status=status,
exceptionInfo=exception_info,
createTime=datetime.now(),
)
session = SessionLocal()
JobLogService.add_job_log_services(session, job_log)
session.close()
if hasattr(event, 'job_id'):
job_id = event.job_id
query_job = cls.get_scheduler_job(job_id=job_id)
if query_job:
query_job_info = query_job.__getstate__()
# 获取任务名称
job_name = query_job_info.get('name')
# 获取任务组名
job_group = query_job._jobstore_alias
# 获取任务执行器
job_executor = query_job_info.get('executor')
# 获取调用目标字符串
invoke_target = query_job_info.get('func')
# 获取调用函数位置参数
job_args = ','.join(query_job_info.get('args'))
# 获取调用函数关键字参数
job_kwargs = json.dumps(query_job_info.get('kwargs'))
# 获取任务触发器
job_trigger = str(query_job_info.get('trigger'))
# 构造日志消息
job_message = f"事件类型: {event_type}, 任务ID: {job_id}, 任务名称: {job_name}, 执行于{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
job_log = JobLogModel(
jobName=job_name,
jobGroup=job_group,
jobExecutor=job_executor,
invokeTarget=invoke_target,
jobArgs=job_args,
jobKwargs=job_kwargs,
jobTrigger=job_trigger,
jobMessage=job_message,
status=status,
exceptionInfo=exception_info,
createTime=datetime.now(),
)
session = SessionLocal()
JobLogService.add_job_log_services(session, job_log)
session.close()

View File

@@ -3,6 +3,12 @@ from fastapi.middleware.cors import CORSMiddleware
def add_cors_middleware(app: FastAPI):
"""
添加跨域中间件
:param app: FastAPI对象
:return:
"""
# 前端页面url
origins = [
'http://localhost:80',

View File

@@ -0,0 +1,12 @@
from fastapi import FastAPI
from starlette.middleware.gzip import GZipMiddleware
def add_gzip_middleware(app: FastAPI):
"""
添加gzip压缩中间件
:param app: FastAPI对象
:return:
"""
app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=9)

View File

@@ -1,5 +1,6 @@
from fastapi import FastAPI
from middlewares.cors_middleware import add_cors_middleware
from middlewares.gzip_middleware import add_gzip_middleware
def handle_middleware(app: FastAPI):
@@ -8,3 +9,5 @@ def handle_middleware(app: FastAPI):
"""
# 加载跨域中间件
add_cors_middleware(app)
# 加载gzip压缩中间件
add_gzip_middleware(app)

View File

@@ -15,6 +15,8 @@ from module_admin.service.log_service import LoginLogService, OperationLogServic
from module_admin.service.login_service import LoginService
from config.enums import BusinessType
from config.env import AppConfig
from exceptions.exception import LoginException, ServiceException, ServiceWarning
from utils.response_util import ResponseUtil
class Log:
@@ -111,8 +113,17 @@ class Log:
loginTime=oper_time.strftime('%Y-%m-%d %H:%M:%S'),
)
kwargs['form_data'].login_info = login_log
# 调用原始函数
result = await func(*args, **kwargs)
try:
# 调用原始函数
result = await func(*args, **kwargs)
except LoginException as e:
result = ResponseUtil.failure(data=e.data, msg=e.message)
except ServiceException as e:
result = ResponseUtil.error(data=e.data, msg=e.message)
except ServiceWarning as e:
result = ResponseUtil.failure(data=e.data, msg=e.message)
except Exception as e:
result = ResponseUtil.error(msg=str(e))
# 获取请求耗时
cost_time = float(time.time() - start_time) * 100
# 判断请求是否来自api文档
@@ -281,8 +292,17 @@ def log_decorator(
loginTime=oper_time.strftime('%Y-%m-%d %H:%M:%S'),
)
kwargs['form_data'].login_info = login_log
# 调用原始函数
result = await func(*args, **kwargs)
try:
# 调用原始函数
result = await func(*args, **kwargs)
except LoginException as e:
result = ResponseUtil.failure(data=e.data, msg=e.message)
except ServiceException as e:
result = ResponseUtil.error(data=e.data, msg=e.message)
except ServiceWarning as e:
result = ResponseUtil.failure(data=e.data, msg=e.message)
except Exception as e:
result = ResponseUtil.error(msg=str(e))
# 获取请求耗时
cost_time = float(time.time() - start_time) * 100
# 判断请求是否来自api文档

View File

@@ -71,7 +71,7 @@ class PageUtil:
paginated_data.append(row[0])
else:
paginated_data.append(row)
has_next = True if math.ceil(len(paginated_data) / page_size) > page_num else False
has_next = math.ceil(total / page_size) > page_num
result = PageResponseModel(
rows=CamelCaseUtil.transform_result(paginated_data),
pageNum=page_num,

View File

@@ -1,6 +1,6 @@
{
"name": "vfadmin",
"version": "1.3.0",
"version": "1.3.2",
"description": "vfadmin管理系统",
"author": "insistence",
"license": "MIT",