dept.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package system
  2. import (
  3. "kpt-pasture/http/middleware"
  4. "net/http"
  5. "strconv"
  6. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  7. "gitee.com/xuyiping_admin/pkg/valid"
  8. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  9. "gitee.com/xuyiping_admin/pkg/apierr"
  10. "gitee.com/xuyiping_admin/pkg/ginutil"
  11. "github.com/gin-gonic/gin"
  12. )
  13. func DeptList(c *gin.Context) {
  14. var req pasturePb.SearchDeptRequest
  15. if err := ginutil.BindProto(c, &req); err != nil {
  16. apierr.AbortBadRequest(c, http.StatusOK, err)
  17. return
  18. }
  19. pagination := &pasturePb.PaginationModel{
  20. Page: int32(c.GetInt(middleware.Page)),
  21. PageSize: int32(c.GetInt(middleware.PageSize)),
  22. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  23. }
  24. res, err := middleware.Dependency(c).StoreEventHub.OpsService.SearchSystemDeptList(c, &req, pagination)
  25. if err != nil {
  26. apierr.ClassifiedAbort(c, err)
  27. return
  28. }
  29. ginutil.JSONResp(c, res)
  30. }
  31. func DepIsShow(c *gin.Context) {
  32. IDStr := c.Param("id")
  33. Id, _ := strconv.Atoi(IDStr)
  34. if err := valid.Validate(Id, valid.Required, valid.Min(1)); err != nil {
  35. apierr.ClassifiedAbort(c, err)
  36. return
  37. }
  38. if err := middleware.Dependency(c).StoreEventHub.OpsService.SystemDepDelete(c, int64(Id)); err != nil {
  39. apierr.ClassifiedAbort(c, err)
  40. return
  41. }
  42. ginutil.JSONResp(c, &operationPb.CommonOK{
  43. Code: http.StatusOK,
  44. Msg: "ok",
  45. Data: &operationPb.Success{Success: true},
  46. })
  47. }
  48. func DepCreateOrUpdate(c *gin.Context) {
  49. var req pasturePb.SearchDeptRequest
  50. if err := ginutil.BindProto(c, &req); err != nil {
  51. apierr.AbortBadRequest(c, http.StatusOK, err)
  52. return
  53. }
  54. if err := middleware.Dependency(c).StoreEventHub.OpsService.SystemDeptCreateOrUpdate(c, &req); err != nil {
  55. apierr.ClassifiedAbort(c, err)
  56. return
  57. }
  58. ginutil.JSONResp(c, &operationPb.CommonOK{
  59. Code: http.StatusOK,
  60. Msg: "ok",
  61. Data: &operationPb.Success{Success: true},
  62. })
  63. }