controller.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. from typing import Annotated, Optional
  2. from fastapi import APIRouter, Depends, Path, Query
  3. from fastapi.responses import JSONResponse
  4. from app.api.v1.module_system.auth.schema import AuthSchema
  5. from app.common.response import ResponseSchema, SuccessResponse
  6. from app.core.dependencies import AuthPermission, get_current_user
  7. from app.core.logger import log
  8. from app.core.router_class import OperationLogRoute
  9. from .schema import (
  10. EmployeeCreateOrUpdateSchema,
  11. EmployeeListOutSchema,
  12. EmployeeOperationOutSchema,
  13. EmployeeInviteQuerySchema,
  14. EmployeeInviteQueryOutSchema,
  15. )
  16. from .service import EmployeeService
  17. EmployeeRouter = APIRouter(
  18. route_class=OperationLogRoute,
  19. prefix="/employee",
  20. tags=["员工管理"],
  21. )
  22. @EmployeeRouter.get(
  23. "/info",
  24. summary="查询员工详情",
  25. description="查询员工详情",
  26. )
  27. async def info_employee_controller(
  28. enterprise_id: Annotated[str, Query(description="企业ID")],
  29. auth: Annotated[AuthSchema, Depends(get_current_user)],
  30. employee_id: Annotated[Optional[str], Query(description="员工ID")] = None,
  31. employee_email: Annotated[Optional[str], Query(description="员工邮箱")] = None,
  32. employee_mobile: Annotated[Optional[str], Query(description="员工手机号")] = None,
  33. ) -> JSONResponse:
  34. """查询员工详情"""
  35. result = await EmployeeService.info_service(
  36. auth=auth,
  37. employee_id=employee_id,
  38. employee_email=employee_email,
  39. employee_mobile=employee_mobile,
  40. enterprise_id=enterprise_id
  41. )
  42. return SuccessResponse(data=result, msg="查询员工详情成功")
  43. @EmployeeRouter.post(
  44. "",
  45. summary="添加员工",
  46. description="添加员工 (alipay.commerce.ec.employee.add)",
  47. response_model=ResponseSchema[EmployeeOperationOutSchema],
  48. )
  49. async def add_employee_controller(
  50. data: EmployeeCreateOrUpdateSchema,
  51. auth: Annotated[AuthSchema, Depends(AuthPermission(["module_payment:employee:create"]))],
  52. ) -> JSONResponse:
  53. """添加员工"""
  54. result = await EmployeeService.add_employee_service(auth=auth, data=data)
  55. log.info(f"添加员工成功: {data.employee_name}, employee_id={result.employee_id}")
  56. return SuccessResponse(data=result, msg="添加员工成功")
  57. @EmployeeRouter.get(
  58. "",
  59. summary="查询员工列表",
  60. description="分页查询员工列表",
  61. response_model=ResponseSchema[EmployeeListOutSchema],
  62. )
  63. async def list_employee_controller(
  64. auth: Annotated[AuthSchema, Depends(AuthPermission(["module_payment:employee:list"]))],
  65. page_no: Annotated[int, Query(description="页码")] = 1,
  66. page_size: Annotated[int, Query(description="每页数量")] = 20,
  67. enterprise_id: Annotated[str | None, Query(description="企业ID")] = None,
  68. employee_name: Annotated[str | None, Query(description="员工姓名")] = None,
  69. employee_no: Annotated[str | None, Query(description="员工工号")] = None,
  70. status: Annotated[str | None, Query(description="状态")] = None,
  71. ) -> JSONResponse:
  72. """查询员工列表"""
  73. search = {}
  74. if enterprise_id:
  75. search["enterprise_id"] = enterprise_id
  76. if employee_name:
  77. search["employee_name"] = employee_name
  78. if employee_no:
  79. search["employee_no"] = employee_no
  80. if status:
  81. search["status"] = status
  82. result = await EmployeeService.list_service(
  83. auth=auth, page_no=page_no, page_size=page_size, search=search
  84. )
  85. return SuccessResponse(data=result, msg="查询员工列表成功")
  86. @EmployeeRouter.get(
  87. "/detail",
  88. summary="查询员工详情",
  89. description="根据 employee_id 查询员工详情",
  90. )
  91. async def get_detail_controller(
  92. enterprise_id: Annotated[str, Query(description="企业ID")],
  93. auth: Annotated[AuthSchema, Depends(AuthPermission(["module_payment:employee:detail"]))],
  94. employee_id: Annotated[Optional[str], Query(description="员工ID")] = None,
  95. employee_email: Annotated[Optional[str], Query(description="员工邮箱")] = None,
  96. employee_mobile: Annotated[Optional[str], Query(description="员工手机号")] = None,
  97. ) -> JSONResponse:
  98. """查询员工详情"""
  99. result = await EmployeeService.detail_service(auth=auth, employee_id=employee_id, employee_email=employee_email, employee_mobile=employee_mobile, enterprise_id=enterprise_id)
  100. log.info(f"查询员工详情成功: {employee_id}, enterprise_id={enterprise_id}")
  101. return SuccessResponse(data=result, msg="查询员工详情成功")
  102. @EmployeeRouter.delete(
  103. "/{employee_id}",
  104. summary="删除员工",
  105. description="删除员工 (alipay.commerce.ec.employee.delete)",
  106. response_model=ResponseSchema[EmployeeOperationOutSchema],
  107. )
  108. async def delete_employee_controller(
  109. employee_id: Annotated[str, Path(description="员工ID")],
  110. enterprise_id: Annotated[str, Query(description="企业ID")],
  111. auth: Annotated[AuthSchema, Depends(AuthPermission(["module_payment:employee:delete"]))],
  112. ) -> JSONResponse:
  113. """删除员工"""
  114. result = await EmployeeService.delete_employee_service(
  115. auth=auth, employee_id=employee_id, enterprise_id=enterprise_id
  116. )
  117. log.info(f"删除员工成功: {employee_id}, enterprise_id={enterprise_id}")
  118. return SuccessResponse(data=result, msg="删除员工成功")
  119. @EmployeeRouter.post(
  120. "/invite/query",
  121. summary="获取员工签约激活链接",
  122. description="获取员工签约激活链接 (alipay.commerce.ec.employee.invite.query)",
  123. response_model=ResponseSchema[EmployeeInviteQueryOutSchema],
  124. )
  125. async def invite_query_controller(
  126. data: EmployeeInviteQuerySchema,
  127. auth: Annotated[AuthSchema, Depends(AuthPermission(["module_payment:employee:invite"]))],
  128. ) -> JSONResponse:
  129. """获取员工签约激活链接"""
  130. result = await EmployeeService.invite_query_service(auth=auth, data=data)
  131. log.info(f"获取员工签约激活链接成功: enterprise_id={data.enterprise_id}")
  132. return SuccessResponse(data=result, msg="获取员工签约激活链接成功")