package pasture import ( "kpt-pasture/http/middleware" "net/http" "strconv" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation" "gitee.com/xuyiping_admin/pkg/apierr" "gitee.com/xuyiping_admin/pkg/ginutil" "gitee.com/xuyiping_admin/pkg/valid" "github.com/gin-gonic/gin" ) // SemeTimeCreated 同期策略添加 func SemeTimeCreated(c *gin.Context) { var req pasturePb.SemeTimeRequest if err := ginutil.BindProto(c, &req); err != nil { apierr.AbortBadRequest(c, http.StatusBadRequest, err) return } if err := valid.ValidateStruct(&req, valid.Field(&req.Form, valid.Required, valid.By(func(value interface{}) error { form := value.(*pasturePb.SemeTimeFormData) if err := valid.ValidateStruct(form, valid.Field(&form.Name, valid.Required), valid.Field(&form.CowType, valid.Required), valid.Field(&form.WeekType, valid.Required), valid.Field(&form.PostpartumDays, valid.Required), ); err != nil { return err } return nil })), valid.Field(&req.Graph, valid.Required), ); err != nil { apierr.AbortBadRequest(c, http.StatusBadRequest, err) return } if err := middleware.BackendOperation(c).OpsService.CreateOrUpdateSemeTime(c, &req); err != nil { apierr.ClassifiedAbort(c, err) return } ginutil.JSONResp(c, &operationPb.CommonOK{ Code: http.StatusOK, Msg: "ok", Data: &operationPb.Success{Success: true}, }) } // SemeTimeList 同步策略列表 func SemeTimeList(c *gin.Context) { var req pasturePb.SearchNameRequest if err := ginutil.BindProto(c, &req); err != nil { apierr.AbortBadRequest(c, http.StatusBadRequest, err) return } pagination := &pasturePb.PaginationModel{ Page: int32(c.GetInt(middleware.Page)), PageSize: int32(c.GetInt(middleware.PageSize)), PageOffset: int32(c.GetInt(middleware.PageOffset)), } res, err := middleware.BackendOperation(c).OpsService.SearchSemeTimeList(c, &req, pagination) if err != nil { apierr.ClassifiedAbort(c, err) return } ginutil.JSONResp(c, res) } // SemeTimeDetail 同步策略详情 func SemeTimeDetail(c *gin.Context) { semeTimeIdStr := c.Param("semeTimeId") semeTimeId, _ := strconv.Atoi(semeTimeIdStr) if err := valid.Validate(semeTimeId, valid.Required, valid.Min(1)); err != nil { apierr.ClassifiedAbort(c, err) return } res, err := middleware.BackendOperation(c).OpsService.SemeTimeDetail(c, int64(semeTimeId)) if err != nil { apierr.ClassifiedAbort(c, err) return } ginutil.JSONResp(c, res) }