refactor: add log

This commit is contained in:
wangjiahao
2025-12-30 17:39:55 +08:00
parent e5fd7d297a
commit 95b058a2ad
10 changed files with 38 additions and 25 deletions
+8 -2
View File
@@ -167,6 +167,11 @@ async def start_chat(session: SessionDep, current_user: CurrentUser, create_chat
@router.post("/assistant/start", response_model=ChatInfo, summary=f"{PLACEHOLDER_PREFIX}assistant_start_chat")
@system_log(LogConfig(
operation_type=OperationType.CREATE,
module=OperationModules.CHAT,
result_id_expr="id"
))
async def start_chat(session: SessionDep, current_user: CurrentUser):
try:
return create_chat(session, current_user, CreateChat(origin=2), False)
@@ -436,8 +441,9 @@ async def analysis_or_predict(session: SessionDep, current_user: CurrentUser, ch
)
@router.get("/record/{chat_record_id}/excel/export", summary=f"{PLACEHOLDER_PREFIX}export_chart_data")
async def export_excel(session: SessionDep, current_user: CurrentUser, chat_record_id: int, trans: Trans):
@router.get("/record/{chat_record_id}/excel/export/{chat_id}", summary=f"{PLACEHOLDER_PREFIX}export_chart_data")
@system_log(LogConfig(operation_type=OperationType.EXPORT,module=OperationModules.CHAT,resource_id_expr="chat_id",))
async def export_excel(session: SessionDep, current_user: CurrentUser, chat_record_id: int,chat_id: int, trans: Trans):
chat_record = session.get(ChatRecord, chat_record_id)
if not chat_record:
raise HTTPException(
@@ -8,12 +8,14 @@ from apps.datasource.models.datasource import CoreDatasource
from apps.swagger.i18n import PLACEHOLDER_PREFIX
from apps.system.schemas.permission import SqlbotPermission, require_permissions
from common.core.deps import SessionDep
from common.audit.models.log_model import OperationType, OperationModules
from common.audit.schemas.logger_decorator import LogConfig, system_log
router = APIRouter(tags=["Table Relation"], prefix="/table_relation")
@router.post("/save/{ds_id}", response_model=None, summary=f"{PLACEHOLDER_PREFIX}tr_save")
@require_permissions(permission=SqlbotPermission(role=['ws_admin'], keyExpression="ds_id", type='ds'))
@system_log(LogConfig(operation_type=OperationType.UPDATE_TABLE_RELATION,module=OperationModules.DATASOURCE,resource_id_expr="ds_id"))
async def save_relation(session: SessionDep, relation: List[dict],
ds_id: int = Path(..., description=f"{PLACEHOLDER_PREFIX}ds_id")):
ds = session.get(CoreDatasource, ds_id)
+2
View File
@@ -108,6 +108,7 @@ async def picture(file_id: str = Path(description="file_id")):
@router.patch('/ui', summary=f"{PLACEHOLDER_PREFIX}assistant_ui_api", description=f"{PLACEHOLDER_PREFIX}assistant_ui_api")
@system_log(LogConfig(operation_type=OperationType.UPDATE, module=OperationModules.APPLICATION, result_id_expr="id"))
async def ui(session: SessionDep, data: str = Form(), files: List[UploadFile] = []):
json_data = json.loads(data)
uiSchema = AssistantUiSchema(**json_data)
@@ -155,6 +156,7 @@ async def ui(session: SessionDep, data: str = Form(), files: List[UploadFile] =
session.add(db_model)
session.commit()
await clear_ui_cache(db_model.id)
return db_model
@clear_cache(namespace=CacheNamespace.EMBEDDED_INFO, cacheName=CacheName.ASSISTANT_INFO, keyExpression="id")
+3 -15
View File
@@ -272,11 +272,7 @@ async def langChange(session: SessionDep, current_user: CurrentUser, trans: Tran
@router.patch("/pwd/{id}", summary=f"{PLACEHOLDER_PREFIX}reset_pwd", description=f"{PLACEHOLDER_PREFIX}reset_pwd")
@require_permissions(permission=SqlbotPermission(role=['admin']))
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="id")
@system_log(LogConfig(
operation_type=OperationType.UPDATE,
module=OperationModules.USER,
resource_id_expr="id"
))
@system_log(LogConfig(operation_type=OperationType.RESET_PWD,module=OperationModules.USER,resource_id_expr="id"))
async def pwdReset(session: SessionDep, current_user: CurrentUser, trans: Trans, id: int = Path(description=f"{PLACEHOLDER_PREFIX}uid")):
if not current_user.isAdmin:
raise Exception(trans('i18n_permission.no_permission', url = " patch[/user/pwd/id],", msg = trans('i18n_permission.only_admin')))
@@ -286,11 +282,7 @@ async def pwdReset(session: SessionDep, current_user: CurrentUser, trans: Trans,
@router.put("/pwd", summary=f"{PLACEHOLDER_PREFIX}update_pwd", description=f"{PLACEHOLDER_PREFIX}update_pwd")
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="current_user.id")
@system_log(LogConfig(
operation_type=OperationType.UPDATE,
module=OperationModules.USER,
result_id_expr="id"
))
@system_log(LogConfig(operation_type=OperationType.UPDATE_PWD,module=OperationModules.USER,result_id_expr="id"))
async def pwdUpdate(session: SessionDep, current_user: CurrentUser, trans: Trans, editor: PwdEditor):
new_pwd = editor.new_pwd
if not check_pwd_format(new_pwd):
@@ -306,11 +298,7 @@ async def pwdUpdate(session: SessionDep, current_user: CurrentUser, trans: Trans
@router.patch("/status", summary=f"{PLACEHOLDER_PREFIX}update_status", description=f"{PLACEHOLDER_PREFIX}update_status")
@require_permissions(permission=SqlbotPermission(role=['admin']))
@clear_cache(namespace=CacheNamespace.AUTH_INFO, cacheName=CacheName.USER_INFO, keyExpression="statusDto.id")
@system_log(LogConfig(
operation_type=OperationType.UPDATE,
module=OperationModules.USER,
resource_id_expr="statusDto.id"
))
@system_log(LogConfig(operation_type=OperationType.UPDATE_STATUS,module=OperationModules.USER, resource_id_expr="statusDto.id"))
async def statusChange(session: SessionDep, current_user: CurrentUser, trans: Trans, statusDto: UserStatus):
if not current_user.isAdmin:
raise Exception(trans('i18n_permission.no_permission', url = ", ", msg = trans('i18n_permission.only_admin')))
+4
View File
@@ -34,6 +34,10 @@ class OperationType(str, Enum):
CREATE = "create"
DELETE = "delete"
UPDATE = "update"
RESET_PWD = "reset_pwd"
UPDATE_PWD = "update_pwd"
UPDATE_STATUS = "update_status"
UPDATE_TABLE_RELATION = "update_table_relation"
EDIT = "edit"
LOGIN = "login"
VIEW = "view"
+5 -1
View File
@@ -178,7 +178,11 @@
"system_management": "System Management",
"opt_log": "Operation Log",
"prediction": "Data prediction",
"analysis": "Data analysis"
"analysis": "Data analysis",
"reset_pwd": "Reset Password",
"update_pwd": "Update Password",
"update_status": "Update Status",
"update_table_relation": "Change Table Relation"
},
"i18n_table_not_exist": "Table not exist"
}
+5 -1
View File
@@ -178,7 +178,11 @@
"system_management": "시스템 관리",
"opt_log": "작업 로그",
"prediction": "데이터 예측",
"analysis": "데이터 분석"
"analysis": "데이터 분석",
"reset_pwd": "비밀번호 재설정",
"update_pwd": "비밀번호 업데이트",
"update_status": "상태 업데이트",
"update_table_relation": "테이블 관계 변경"
},
"i18n_table_not_exist": "현재 테이블이 존재하지 않습니다"
}
+5 -2
View File
@@ -178,8 +178,11 @@
"system_management": "系统管理",
"opt_log": "操作日志",
"prediction": "数据预测",
"analysis": "数据分析"
"analysis": "数据分析",
"reset_pwd": "重置密码",
"update_pwd": "更新密码",
"update_status": "更新状态",
"update_table_relation": "变更表关系"
},
"i18n_table_not_exist": "当前表不存在"
}
+2 -2
View File
@@ -356,8 +356,8 @@ export const chatApi = {
return request.get(`/chat/recent_questions/${datasource_id}`)
},
checkLLMModel: () => request.get('/system/aimodel/default', { requestOptions: { silent: true } }),
export2Excel: (record_id: number | undefined) =>
request.get(`/chat/record/${record_id}/excel/export`, {
export2Excel: (record_id: number | undefined, chat_id: any) =>
request.get(`/chat/record/${record_id}/excel/export/${chat_id}`, {
responseType: 'blob',
requestOptions: { customError: true },
}),
@@ -247,7 +247,7 @@ function exportToExcel() {
if (chartRef.value && props.recordId) {
loading.value = true
chatApi
.export2Excel(props.recordId)
.export2Excel(props.recordId, props.message?.record?.chat_id || 0)
.then((res) => {
const blob = new Blob([res], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',