controller.py 5.9 KB

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