mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
Merge branch 'main' of https://github.com/dataease/SQLBot
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from typing import Optional
|
||||
from fastapi import APIRouter, Query
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from sqlmodel import exists, or_, select
|
||||
from apps.system.models.system_model import UserWsModel, WorkspaceBase, WorkspaceEditor, WorkspaceModel
|
||||
from apps.system.models.user import UserModel
|
||||
@@ -105,11 +105,14 @@ async def pager(
|
||||
|
||||
|
||||
@router.post("/uws")
|
||||
async def create(session: SessionDep, creator: UserWsDTO):
|
||||
async def create(session: SessionDep, current_user: CurrentUser, creator: UserWsDTO):
|
||||
if not current_user.isAdmin and current_user.weight == 0:
|
||||
raise HTTPException("no permission to execute")
|
||||
oid: int = creator.oid if current_user.isAdmin else current_user.oid
|
||||
# 判断uid_list以及oid合法性
|
||||
db_model_list = [
|
||||
UserWsModel.model_validate({
|
||||
"oid": creator.oid,
|
||||
"oid": oid,
|
||||
"uid": uid,
|
||||
"weight": creator.weight
|
||||
})
|
||||
@@ -133,10 +136,13 @@ async def edit(session: SessionDep, editor: UserWsEditor):
|
||||
session.commit()
|
||||
|
||||
@router.delete("/uws")
|
||||
async def delete(session: SessionDep, dto: UserWsBase):
|
||||
db_model_list: list[UserWsModel] = session.exec(select(UserWsModel).where(UserWsModel.uid.in_(dto.uid_list), UserWsModel.oid == dto.oid)).all()
|
||||
async def delete(session: SessionDep, current_user: CurrentUser, dto: UserWsBase):
|
||||
if not current_user.isAdmin and current_user.weight == 0:
|
||||
raise HTTPException("no permission to execute")
|
||||
oid: int = dto.oid if current_user.isAdmin else current_user.oid
|
||||
db_model_list: list[UserWsModel] = session.exec(select(UserWsModel).where(UserWsModel.uid.in_(dto.uid_list), UserWsModel.oid == oid)).all()
|
||||
if not db_model_list:
|
||||
raise ValueError(f"UserWsModel not found")
|
||||
raise HTTPException(f"UserWsModel not found")
|
||||
for db_model in db_model_list:
|
||||
session.delete(db_model)
|
||||
session.commit()
|
||||
|
||||
@@ -48,7 +48,7 @@ class PwdEditor(BaseModel):
|
||||
|
||||
class UserWsBase(BaseModel):
|
||||
uid_list: list[int]
|
||||
oid: int
|
||||
oid: Optional[int] = None
|
||||
class UserWsDTO(UserWsBase):
|
||||
weight: int = 0
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ template:
|
||||
根据表结构和问题生成符合{engine}数据库引擎规范的sql语句,以及sql中所用到的表名(不要包含schema和database,用数组返回)。
|
||||
你必须遵守以下规则:
|
||||
- 生成的SQL必须符合{engine}的规范。
|
||||
- 根据表结构生成SQL语句。
|
||||
- 根据表结构生成SQL语句,需给每个表名生成一个别名(不要加AS)。
|
||||
- SQL查询中不能使用星号(*),必须明确指定字段名.
|
||||
- SQL查询的字段名不要自动翻译,别名必须为英文。
|
||||
- 计算占比,百分比类型字段,保留两位小数,以%结尾。
|
||||
@@ -174,6 +174,7 @@ template:
|
||||
- 生成的SQL必须符合{engine}的规范。
|
||||
- 不要替换原来SQL中的过滤条件,将新过滤条件添加到SQL中,生成一个新的sql。
|
||||
- 如果存在冗余的过滤条件则进行去重后再生成新SQL。
|
||||
- 给过滤条件中的字段前加上表别名(如果没有表别名则加表名),如:table.field。
|
||||
- 生成SQL时,必须避免关键字冲突:
|
||||
- 如数据库引擎是 PostgreSQL、Oracle,则在schema、表名、字段名、别名外层加双引号;
|
||||
- 如数据库引擎是 MySQL,则在表名、字段名、别名外层加反引号;
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
/>
|
||||
</el-popover>
|
||||
<el-tooltip effect="dark" :content="t('qa.new_chat')" placement="bottom">
|
||||
<el-button link type="primary" class="icon-btn" @click="createNewChat">
|
||||
<el-button link type="primary" class="icon-btn" @click="createNewChatSimple">
|
||||
<el-icon>
|
||||
<icon_new_chat_outlined />
|
||||
</el-icon>
|
||||
@@ -73,7 +73,7 @@
|
||||
size="large"
|
||||
type="primary"
|
||||
class="greeting-btn"
|
||||
@click="createNewChat"
|
||||
@click="createNewChatSimple"
|
||||
>
|
||||
<span class="inner-icon">
|
||||
<el-icon>
|
||||
@@ -299,6 +299,12 @@ const goEmpty = () => {
|
||||
inputMessage.value = ''
|
||||
}
|
||||
|
||||
const createNewChatSimple = async () => {
|
||||
currentChat.value = new ChatInfo()
|
||||
currentChatId.value = undefined
|
||||
await createNewChat()
|
||||
}
|
||||
|
||||
const createNewChat = async () => {
|
||||
goEmpty()
|
||||
if (isAssistant.value) {
|
||||
@@ -760,9 +766,7 @@ defineExpose({
|
||||
align-items: center;
|
||||
|
||||
.welcome-content {
|
||||
padding: 12px;
|
||||
|
||||
width: fit-content;
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
|
||||
Reference in New Issue
Block a user