post.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # -*- coding: utf-8 -*-
  2. # @Author : YY
  3. from typing import List
  4. from pydantic import BeforeValidator
  5. from typing_extensions import Annotated
  6. from ruoyi_common.base.transformer import ids_to_list
  7. from ruoyi_common.base.model import AjaxResponse, TableResponse
  8. from ruoyi_common.domain.enum import BusinessType
  9. from ruoyi_common.descriptor.serializer import BaseSerializer, JsonSerializer
  10. from ruoyi_common.descriptor.validator import BodyValidator, QueryValidator, PathValidator
  11. from ruoyi_common.utils import security_util as SecurityUtil
  12. from ruoyi_framework.descriptor.log import Log
  13. from ruoyi_framework.descriptor.permission import HasPerm, PreAuthorize
  14. from ruoyi_system.domain.entity import SysPost
  15. from ruoyi_system.service import SysPostService
  16. from ... import reg
  17. @reg.api.route("/system/post/list", methods=["GET"])
  18. @QueryValidator(is_page=True)
  19. @PreAuthorize(HasPerm("system:post:list"))
  20. @JsonSerializer()
  21. def system_post_list(dto:SysPost):
  22. '''
  23. 获取岗位信息列表
  24. '''
  25. rows = SysPostService.select_post_list(dto)
  26. table_response = TableResponse(rows=rows)
  27. return table_response
  28. @reg.api.route("/system/post/export", methods=["POST"])
  29. @BodyValidator()
  30. @PreAuthorize(HasPerm("system:post:export"))
  31. @Log(title = "岗位管理", business_type = BusinessType.EXPORT)
  32. @BaseSerializer()
  33. def system_post_export(dto:SysPost):
  34. '''
  35. # todo
  36. 导出岗位信息列表
  37. '''
  38. rows = SysPostService.select_post_list(dto)
  39. table_response = TableResponse(rows=rows)
  40. return table_response
  41. @reg.api.route("/system/post/<int:id>", methods=["GET"])
  42. @PathValidator()
  43. @PreAuthorize(HasPerm("system:post:query"))
  44. @JsonSerializer()
  45. def system_post_get(id:int):
  46. '''
  47. 根据id,获取岗位信息
  48. '''
  49. eo = SysPostService.select_post_by_id(id)
  50. return AjaxResponse.from_success(data=eo) \
  51. if eo else AjaxResponse.from_error()
  52. @reg.api.route("/system/post", methods=["POST"])
  53. @BodyValidator()
  54. @PreAuthorize(HasPerm("system:post:add"))
  55. @Log(title = "岗位管理", business_type = BusinessType.INSERT)
  56. @JsonSerializer()
  57. def system_post_add(dto:SysPost):
  58. '''
  59. 添加岗位信息
  60. '''
  61. dto.create_by_user(SecurityUtil.get_username())
  62. SysPostService.insert_post(dto)
  63. ajax_response = AjaxResponse.from_success()
  64. return ajax_response
  65. @reg.api.route("/system/post", methods=["PUT"])
  66. @BodyValidator()
  67. @PreAuthorize(HasPerm("system:post:edit"))
  68. @Log(title = "岗位管理", business_type = BusinessType.UPDATE)
  69. @JsonSerializer()
  70. def system_post_update(dto:SysPost):
  71. '''
  72. 修改岗位信息
  73. '''
  74. dto.update_by_user(SecurityUtil.get_username())
  75. flag = SysPostService.update_post(dto)
  76. return AjaxResponse.from_success() if flag else AjaxResponse.from_error()
  77. @reg.api.route("/system/post/<ids>", methods=["DELETE"])
  78. @PathValidator()
  79. @PreAuthorize(HasPerm("system:post:remove"))
  80. @Log(title = "岗位管理", business_type = BusinessType.DELETE)
  81. @JsonSerializer()
  82. def system_post_delete(
  83. ids: Annotated[List[int],BeforeValidator(ids_to_list)]
  84. ):
  85. '''
  86. 删除岗位信息
  87. '''
  88. flag = SysPostService.delete_post_by_ids(ids)
  89. return AjaxResponse.from_success() if flag else AjaxResponse.from_error()