seme_time.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package pasture
  2. import (
  3. "kpt-pasture/http/middleware"
  4. "net/http"
  5. "strconv"
  6. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  7. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  8. "gitee.com/xuyiping_admin/pkg/apierr"
  9. "gitee.com/xuyiping_admin/pkg/ginutil"
  10. "gitee.com/xuyiping_admin/pkg/valid"
  11. "github.com/gin-gonic/gin"
  12. )
  13. // SemeTimeCreated 同期策略添加
  14. func SemeTimeCreated(c *gin.Context) {
  15. var req pasturePb.SemeTimeRequest
  16. if err := ginutil.BindProto(c, &req); err != nil {
  17. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  18. return
  19. }
  20. if err := valid.ValidateStruct(&req,
  21. valid.Field(&req.Form, valid.Required, valid.By(func(value interface{}) error {
  22. form := value.(*pasturePb.SemeTimeFormData)
  23. if err := valid.ValidateStruct(form,
  24. valid.Field(&form.Name, valid.Required),
  25. valid.Field(&form.CowType, valid.Required),
  26. valid.Field(&form.WeekType, valid.Required),
  27. valid.Field(&form.PostpartumDays, valid.Required),
  28. ); err != nil {
  29. return err
  30. }
  31. return nil
  32. })),
  33. valid.Field(&req.Graph, valid.Required),
  34. ); err != nil {
  35. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  36. return
  37. }
  38. if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateSemeTime(c, &req); 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. // SemeTimeList 同步策略列表
  49. func SemeTimeList(c *gin.Context) {
  50. var req pasturePb.SearchNameRequest
  51. if err := ginutil.BindProto(c, &req); err != nil {
  52. apierr.AbortBadRequest(c, http.StatusBadRequest, err)
  53. return
  54. }
  55. pagination := &pasturePb.PaginationModel{
  56. Page: int32(c.GetInt(middleware.Page)),
  57. PageSize: int32(c.GetInt(middleware.PageSize)),
  58. PageOffset: int32(c.GetInt(middleware.PageOffset)),
  59. }
  60. res, err := middleware.BackendOperation(c).OpsService.SearchSemeTimeList(c, &req, pagination)
  61. if err != nil {
  62. apierr.ClassifiedAbort(c, err)
  63. return
  64. }
  65. ginutil.JSONResp(c, res)
  66. }
  67. // SemeTimeDetail 同步策略详情
  68. func SemeTimeDetail(c *gin.Context) {
  69. semeTimeIdStr := c.Param("semeTimeId")
  70. semeTimeId, _ := strconv.Atoi(semeTimeIdStr)
  71. if err := valid.Validate(semeTimeId, valid.Required, valid.Min(1)); err != nil {
  72. apierr.ClassifiedAbort(c, err)
  73. return
  74. }
  75. res, err := middleware.BackendOperation(c).OpsService.SemeTimeDetail(c, int64(semeTimeId))
  76. if err != nil {
  77. apierr.ClassifiedAbort(c, err)
  78. return
  79. }
  80. ginutil.JSONResp(c, res)
  81. }