|
|
@@ -9,7 +9,9 @@ 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.crud import oa_approval as oa_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
|
|
|
|
|
|
router = APIRouter(prefix="/web/admin/oa-approval", tags=["OA审批"])
|
|
|
|
|
|
@@ -176,6 +178,142 @@ async def replace_oa_role_users(
|
|
|
return error_response(400, str(e))
|
|
|
|
|
|
|
|
|
+# ---------------------------------------------------------------------------
|
|
|
+# 收款账户
|
|
|
+# ---------------------------------------------------------------------------
|
|
|
+
|
|
|
+
|
|
|
+class OaReceiveAccountBody(BaseModel):
|
|
|
+ model_config = ConfigDict(populate_by_name=True)
|
|
|
+ account_type: str = Field(..., alias="accountType")
|
|
|
+ account_name: str = Field(..., alias="accountName")
|
|
|
+ account_no: str = Field(..., alias="accountNo")
|
|
|
+ bank_name: Optional[str] = Field(None, alias="bankName")
|
|
|
+ bank_province: Optional[str] = Field(None, alias="bankProvince")
|
|
|
+ bank_city: Optional[str] = Field(None, alias="bankCity")
|
|
|
+ bank_branch: Optional[str] = Field(None, alias="bankBranch")
|
|
|
+ order_num: Optional[int] = Field(None, alias="orderNum")
|
|
|
+ remark: Optional[str] = None
|
|
|
+
|
|
|
+
|
|
|
+class OaReceiveAccountBatchDeleteBody(BaseModel):
|
|
|
+ model_config = ConfigDict(populate_by_name=True)
|
|
|
+ ids: List[str] = Field(default_factory=list)
|
|
|
+
|
|
|
+
|
|
|
+@router.get("/receive-accounts")
|
|
|
+async def list_receive_accounts(
|
|
|
+ page: int = Query(1, ge=1),
|
|
|
+ pageSize: int = Query(10, ge=1, le=100),
|
|
|
+ keyword: Optional[str] = None,
|
|
|
+ accountType: 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 = ora_crud.list_accounts(
|
|
|
+ db,
|
|
|
+ tenant_no=tenant_no,
|
|
|
+ keyword=keyword,
|
|
|
+ account_type=accountType,
|
|
|
+ page=page,
|
|
|
+ page_size=pageSize,
|
|
|
+ )
|
|
|
+ return success_response({"list": items, "total": total})
|
|
|
+
|
|
|
+
|
|
|
+@router.get("/receive-accounts/options")
|
|
|
+async def list_receive_account_options(
|
|
|
+ user: dict = Depends(require_admin_or_super_admin),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+):
|
|
|
+ tenant_no = _get_tenant_no(db, user)
|
|
|
+ return success_response({"list": ora_crud.list_options(db, tenant_no=tenant_no)})
|
|
|
+
|
|
|
+
|
|
|
+@router.post("/receive-accounts/batch-delete")
|
|
|
+async def batch_delete_receive_accounts(
|
|
|
+ body: OaReceiveAccountBatchDeleteBody,
|
|
|
+ user: dict = Depends(require_admin_or_super_admin),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+):
|
|
|
+ tenant_no = _get_tenant_no(db, user)
|
|
|
+ count = ora_crud.soft_delete_accounts(
|
|
|
+ db, body.ids, tenant_no=tenant_no, user_id=user.get("user_id")
|
|
|
+ )
|
|
|
+ return success_response({"deletedCount": count}, message="删除成功")
|
|
|
+
|
|
|
+
|
|
|
+@router.post("/receive-accounts")
|
|
|
+async def create_receive_account(
|
|
|
+ body: OaReceiveAccountBody,
|
|
|
+ user: dict = Depends(require_admin_or_super_admin),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+):
|
|
|
+ ok, err, fields = normalize_account_fields(body.model_dump(by_alias=True))
|
|
|
+ if not ok:
|
|
|
+ return error_response(400, err or "参数无效")
|
|
|
+ tenant_no = _get_tenant_no(db, user)
|
|
|
+ obj = ora_crud.create_account(
|
|
|
+ db,
|
|
|
+ tenant_no=tenant_no,
|
|
|
+ user_id=user.get("user_id"),
|
|
|
+ dept_id=user.get("dept_id") or "",
|
|
|
+ fields=fields,
|
|
|
+ )
|
|
|
+ return success_response(obj, message="创建成功")
|
|
|
+
|
|
|
+
|
|
|
+@router.get("/receive-accounts/{account_id}")
|
|
|
+async def get_receive_account(
|
|
|
+ account_id: str,
|
|
|
+ user: dict = Depends(require_admin_or_super_admin),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+):
|
|
|
+ tenant_no = _get_tenant_no(db, user)
|
|
|
+ obj = ora_crud.get_account(db, account_id, tenant_no)
|
|
|
+ if not obj:
|
|
|
+ return error_response(404, "收款账户不存在")
|
|
|
+ return success_response(obj)
|
|
|
+
|
|
|
+
|
|
|
+@router.put("/receive-accounts/{account_id}")
|
|
|
+async def update_receive_account(
|
|
|
+ account_id: str,
|
|
|
+ body: OaReceiveAccountBody,
|
|
|
+ user: dict = Depends(require_admin_or_super_admin),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+):
|
|
|
+ ok, err, fields = normalize_account_fields(body.model_dump(by_alias=True))
|
|
|
+ if not ok:
|
|
|
+ return error_response(400, err or "参数无效")
|
|
|
+ tenant_no = _get_tenant_no(db, user)
|
|
|
+ obj = ora_crud.update_account(
|
|
|
+ db,
|
|
|
+ account_id,
|
|
|
+ tenant_no=tenant_no,
|
|
|
+ user_id=user.get("user_id"),
|
|
|
+ fields=fields,
|
|
|
+ )
|
|
|
+ if not obj:
|
|
|
+ return error_response(404, "收款账户不存在")
|
|
|
+ return success_response(obj, message="更新成功")
|
|
|
+
|
|
|
+
|
|
|
+@router.delete("/receive-accounts/{account_id}")
|
|
|
+async def delete_receive_account(
|
|
|
+ account_id: str,
|
|
|
+ user: dict = Depends(require_admin_or_super_admin),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+):
|
|
|
+ tenant_no = _get_tenant_no(db, user)
|
|
|
+ if not ora_crud.soft_delete_account(
|
|
|
+ db, account_id, tenant_no=tenant_no, user_id=user.get("user_id")
|
|
|
+ ):
|
|
|
+ return error_response(404, "收款账户不存在")
|
|
|
+ return success_response(None, message="删除成功")
|
|
|
+
|
|
|
+
|
|
|
# ---------------------------------------------------------------------------
|
|
|
# 分组
|
|
|
# ---------------------------------------------------------------------------
|