feat: ship OA drafts/badges, role dual-track, and test-env deploy tooling.
Add approval instance drafts with menu badges, dual-track user/role read model and role bound names, form-designer outline docs, and bare-metal test deploy scripts. Ignore local test-server credential file. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7af53fc344
commit
de22678c87
56 files changed
+11861
-6082
No files matched your search
+18
-24
@@ -26,8 +26,11 @@ from app.crud import menu as menu_svc
|
||||
from app.crud import role as role_svc
|
||||
from app.crud import user as user_svc
|
||||
from app.crud.collection_protocol import _lookup_attachment_by_url
|
||||
from app.models.models import BizAttachment, SysDept, SysRole, SysUser, SysUserRole
|
||||
from app.services.web_auth_roles import _map_role_name_to_web
|
||||
from app.models.models import BizAttachment, SysDept, SysRole, SysUser
|
||||
from app.services.web_auth_roles import (
|
||||
_map_role_name_to_web,
|
||||
list_user_ids_with_effective_role_name,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/web/admin", tags=["运营端管理"])
|
||||
|
||||
@@ -77,7 +80,7 @@ async def list_users_for_select(
|
||||
):
|
||||
"""返回用户下拉选项(label=昵称,value=用户ID),供流程设计器审批人选择使用。
|
||||
|
||||
可选 roleName:按 sys_role.role_name 精确过滤拥有该角色的用户。
|
||||
可选 roleName:按有效角色(直接绑定 ∪ 职位继承)精确过滤。
|
||||
"""
|
||||
tenant_no = _user.get("tenant_no", "")
|
||||
q = db.query(SysUser).filter(SysUser.del_flag == 0, SysUser.status == "1")
|
||||
@@ -85,18 +88,12 @@ async def list_users_for_select(
|
||||
q = q.filter(SysUser.tenant_no == tenant_no)
|
||||
rn = (roleName or "").strip()
|
||||
if rn:
|
||||
q = (
|
||||
q.join(SysUserRole, SysUserRole.user_id == SysUser.id)
|
||||
.join(SysRole, SysRole.id == SysUserRole.role_id)
|
||||
.filter(
|
||||
SysUserRole.del_flag == 0,
|
||||
SysRole.del_flag == 0,
|
||||
SysRole.status == "1",
|
||||
SysRole.role_name == rn,
|
||||
)
|
||||
matched_ids = list_user_ids_with_effective_role_name(
|
||||
db, tenant_no=tenant_no or settings.DEFAULT_TENANT_NO, role_name=rn
|
||||
)
|
||||
if tenant_no:
|
||||
q = q.filter(SysUserRole.tenant_no == tenant_no, SysRole.tenant_no == tenant_no)
|
||||
if not matched_ids:
|
||||
return success_response([])
|
||||
q = q.filter(SysUser.id.in_(matched_ids))
|
||||
rows = q.order_by(SysUser.create_time.desc()).distinct().all()
|
||||
out = [{"label": (r.nick_name or r.user_no or ""), "value": r.id} for r in rows]
|
||||
return success_response(out)
|
||||
@@ -317,17 +314,14 @@ async def list_users(
|
||||
query = query.filter(SysUser.status == status)
|
||||
rn = (roleName or "").strip()
|
||||
if rn:
|
||||
query = (
|
||||
query.join(SysUserRole, SysUserRole.user_id == SysUser.id)
|
||||
.join(SysRole, SysRole.id == SysUserRole.role_id)
|
||||
.filter(
|
||||
SysUserRole.del_flag == 0,
|
||||
SysRole.del_flag == 0,
|
||||
SysRole.status == "1",
|
||||
SysRole.role_name == rn,
|
||||
)
|
||||
matched_ids = list_user_ids_with_effective_role_name(
|
||||
db, tenant_no=tenant_no, role_name=rn
|
||||
)
|
||||
query = query.filter(SysUserRole.tenant_no == tenant_no, SysRole.tenant_no == tenant_no)
|
||||
if not matched_ids:
|
||||
return success_response(
|
||||
{"list": [], "total": 0, "page": page, "pageSize": pageSize, "totalPages": 0}
|
||||
)
|
||||
query = query.filter(SysUser.id.in_(matched_ids))
|
||||
query = apply_data_scope(query, SysUser, user, db, tenant_no)
|
||||
total = query.distinct().count()
|
||||
items = (
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"""OA 审批管理接口(钉钉交互)"""
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
@@ -8,7 +9,9 @@ from sqlalchemy.orm import Session
|
||||
from app.core.database import get_db
|
||||
from app.core.menu_guard import require_admin_or_super_admin
|
||||
from app.core.response import error_response, success_response
|
||||
from app.core.utils import parse_datetime
|
||||
from app.crud import oa_approval as oa_crud
|
||||
from app.crud import oa_instance_draft as oid_crud
|
||||
from app.crud import oa_receive_account as ora_crud
|
||||
from app.models.models import SysUser
|
||||
from app.services.oa_receive_account import normalize_account_fields
|
||||
@@ -164,6 +167,258 @@ async def delete_receive_account(
|
||||
return success_response(None, message="删除成功")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 发起审批草稿箱(oa_instance_draft)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class OaInstanceDraftBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
app_id: str = Field(..., alias="appId")
|
||||
form_data: Optional[Dict[str, Any]] = Field(None, alias="formData")
|
||||
title: Optional[str] = None
|
||||
initiator_dept_id: Optional[str] = Field(None, alias="initiatorDeptId")
|
||||
initiator_select_by_node: Optional[Dict[str, List[str]]] = Field(
|
||||
None, alias="initiatorSelectByNode"
|
||||
)
|
||||
|
||||
|
||||
class OaInstanceDraftUpdateBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
form_data: Optional[Dict[str, Any]] = Field(None, alias="formData")
|
||||
title: Optional[str] = None
|
||||
initiator_dept_id: Optional[str] = Field(None, alias="initiatorDeptId")
|
||||
initiator_select_by_node: Optional[Dict[str, List[str]]] = Field(
|
||||
None, alias="initiatorSelectByNode"
|
||||
)
|
||||
|
||||
|
||||
class OaInstanceDraftBatchDeleteBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
ids: List[str] = Field(default_factory=list)
|
||||
|
||||
|
||||
class OaInstanceDraftSubmitBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
form_data: Optional[Dict[str, Any]] = Field(None, alias="formData")
|
||||
title: Optional[str] = None
|
||||
initiator_dept_id: Optional[str] = Field(None, alias="initiatorDeptId")
|
||||
initiator_select_by_node: Optional[Dict[str, List[str]]] = Field(
|
||||
None, alias="initiatorSelectByNode"
|
||||
)
|
||||
|
||||
|
||||
def _parse_draft_range_end(raw: Optional[str]) -> Optional[datetime]:
|
||||
"""截止日期:仅日期时扩到当天 23:59:59。"""
|
||||
if not raw or not str(raw).strip():
|
||||
return None
|
||||
s = str(raw).strip()
|
||||
dt = parse_datetime(s)
|
||||
if dt is None and len(s) == 10:
|
||||
try:
|
||||
dt = datetime.strptime(s, "%Y-%m-%d")
|
||||
except ValueError:
|
||||
return None
|
||||
if dt is None:
|
||||
return None
|
||||
if len(s) <= 10:
|
||||
return dt.replace(hour=23, minute=59, second=59)
|
||||
return dt
|
||||
|
||||
|
||||
def _parse_draft_range_start(raw: Optional[str]) -> Optional[datetime]:
|
||||
if not raw or not str(raw).strip():
|
||||
return None
|
||||
s = str(raw).strip()
|
||||
dt = parse_datetime(s)
|
||||
if dt is None and len(s) == 10:
|
||||
try:
|
||||
return datetime.strptime(s, "%Y-%m-%d")
|
||||
except ValueError:
|
||||
return None
|
||||
return dt
|
||||
|
||||
|
||||
@router.get("/drafts/count")
|
||||
async def oa_instance_draft_count(
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
n = oid_crud.count_drafts(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
owner_user_id=user.get("user_id") or "",
|
||||
)
|
||||
return success_response({"count": int(n)})
|
||||
|
||||
|
||||
@router.get("/drafts")
|
||||
async def list_oa_instance_drafts(
|
||||
page: int = Query(1, ge=1),
|
||||
pageSize: int = Query(20, ge=1, le=100),
|
||||
keyword: Optional[str] = None,
|
||||
groupId: Optional[str] = None,
|
||||
updateTimeFrom: Optional[str] = None,
|
||||
updateTimeTo: Optional[str] = None,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
items, total = oid_crud.list_drafts(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
owner_user_id=user.get("user_id") or "",
|
||||
keyword=keyword,
|
||||
group_id=groupId,
|
||||
update_time_from=_parse_draft_range_start(updateTimeFrom),
|
||||
update_time_to=_parse_draft_range_end(updateTimeTo),
|
||||
page=page,
|
||||
page_size=pageSize,
|
||||
)
|
||||
return success_response({"list": items, "total": total})
|
||||
|
||||
|
||||
@router.post("/drafts")
|
||||
async def create_oa_instance_draft(
|
||||
body: OaInstanceDraftBody,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
data = oid_crud.create_draft(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
owner_user_id=user.get("user_id") or "",
|
||||
app_id=body.app_id,
|
||||
form_data=body.form_data,
|
||||
initiator_select_by_node=body.initiator_select_by_node,
|
||||
initiator_dept_id=body.initiator_dept_id,
|
||||
title=body.title,
|
||||
create_dept_id=user.get("dept_id") or "",
|
||||
)
|
||||
return success_response(data, message="已存入草稿箱")
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.post("/drafts/batch-delete")
|
||||
async def batch_delete_oa_instance_drafts(
|
||||
body: OaInstanceDraftBatchDeleteBody,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
n = oid_crud.batch_soft_delete_drafts(
|
||||
db,
|
||||
body.ids,
|
||||
tenant_no=tenant_no,
|
||||
owner_user_id=user.get("user_id") or "",
|
||||
)
|
||||
return success_response({"deleted": n}, message="删除成功")
|
||||
except oid_crud.DraftAccessError as e:
|
||||
return error_response(403, str(e))
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.get("/drafts/{draft_id}")
|
||||
async def get_oa_instance_draft(
|
||||
draft_id: str,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
data = oid_crud.get_draft_detail(
|
||||
db,
|
||||
draft_id,
|
||||
tenant_no=tenant_no,
|
||||
owner_user_id=user.get("user_id") or "",
|
||||
)
|
||||
return success_response(data)
|
||||
except oid_crud.DraftAccessError as e:
|
||||
return error_response(404, str(e))
|
||||
|
||||
|
||||
@router.put("/drafts/{draft_id}")
|
||||
async def update_oa_instance_draft(
|
||||
draft_id: str,
|
||||
body: OaInstanceDraftUpdateBody,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
data = oid_crud.update_draft(
|
||||
db,
|
||||
draft_id,
|
||||
tenant_no=tenant_no,
|
||||
owner_user_id=user.get("user_id") or "",
|
||||
form_data=body.form_data,
|
||||
initiator_select_by_node=body.initiator_select_by_node,
|
||||
initiator_dept_id=body.initiator_dept_id,
|
||||
title=body.title,
|
||||
)
|
||||
return success_response(data, message="草稿已保存")
|
||||
except oid_crud.DraftAccessError as e:
|
||||
return error_response(404, str(e))
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.delete("/drafts/{draft_id}")
|
||||
async def delete_oa_instance_draft(
|
||||
draft_id: str,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
oid_crud.soft_delete_draft(
|
||||
db,
|
||||
draft_id,
|
||||
tenant_no=tenant_no,
|
||||
owner_user_id=user.get("user_id") or "",
|
||||
)
|
||||
return success_response(None, message="删除成功")
|
||||
except oid_crud.DraftAccessError as e:
|
||||
return error_response(404, str(e))
|
||||
|
||||
|
||||
@router.post("/drafts/{draft_id}/submit")
|
||||
async def submit_oa_instance_draft(
|
||||
draft_id: str,
|
||||
body: Optional[OaInstanceDraftSubmitBody] = None,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
from app.services.oa_engine import OaEngineError
|
||||
|
||||
payload = body or OaInstanceDraftSubmitBody()
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
data = oid_crud.submit_draft(
|
||||
db,
|
||||
draft_id,
|
||||
tenant_no=tenant_no,
|
||||
owner_user_id=user.get("user_id") or "",
|
||||
form_data=payload.form_data,
|
||||
initiator_select_by_node=payload.initiator_select_by_node,
|
||||
initiator_dept_id=payload.initiator_dept_id,
|
||||
title=payload.title,
|
||||
)
|
||||
return success_response(data, message="发起成功")
|
||||
except oid_crud.DraftAccessError as e:
|
||||
return error_response(404, str(e))
|
||||
except OaEngineError as e:
|
||||
return error_response(400, str(e))
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 分组
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -700,6 +955,23 @@ async def get_related_summaries(
|
||||
return success_response({"list": items})
|
||||
|
||||
|
||||
@router.get("/tasks/pending/count")
|
||||
async def oa_pending_task_count(
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
from app.services.oa_engine import OaEngineError, count_pending_tasks
|
||||
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
n = count_pending_tasks(
|
||||
db, tenant_no=tenant_no, user_id=user.get("user_id") or ""
|
||||
)
|
||||
return success_response({"count": int(n)})
|
||||
except OaEngineError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.get("/tasks/cc/unread-count")
|
||||
async def oa_cc_unread_count(
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
|
||||
Reference in new issue
Block a user