123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- package api
- import (
- "net/http"
- "strconv"
- "tmr-watch/middleware"
- "tmr-watch/service/group"
- "tmr-watch/service/sheep"
- operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
- feedPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/pasture"
- "gitee.com/xuyiping_admin/pkg/apierr"
- "gitee.com/xuyiping_admin/pkg/ginutil"
- "gitee.com/xuyiping_admin/pkg/valid"
- "github.com/gin-gonic/gin"
- )
- // SearchFeetTemplateList 配方列表
- func SearchFeetTemplateList(c *gin.Context) {
- var req feedPb.SearchFeedTemplateRequest
- if err := ginutil.BindProto(c, &req); err != nil {
- apierr.AbortBadRequest(c, http.StatusBadRequest, err)
- return
- }
- req.Pagination = &feedPb.PaginationModel{
- Page: int32(c.GetInt(middleware.Page)),
- PageSize: int32(c.GetInt(middleware.PageSize)),
- PageOffset: int32(c.GetInt(middleware.PageOffset)),
- }
- list, err := group.SearchFeedTemplateList(c, &req)
- if err != nil {
- apierr.ClassifiedAbort(c, err)
- return
- }
- ginutil.JSONResp(c, list)
- }
- // GetFeetTemplateVersion 获取配方最新版本详情
- func GetFeetTemplateVersion(c *gin.Context) {
- var req feedPb.FeetTemplateVersionRequest
- if err := ginutil.BindProto(c, &req); err != nil {
- apierr.AbortBadRequest(c, http.StatusBadRequest, err)
- return
- }
- if err := valid.ValidateStruct(&req,
- valid.Field(&req.FeetTemplateId, valid.Required, valid.Length(1, 100)),
- valid.Field(&req.PastureId, valid.Required, valid.Min(1)),
- ); err != nil {
- apierr.ClassifiedAbort(c, err)
- return
- }
- feetTemplateId, _ := strconv.Atoi(req.GetFeetTemplateId())
- list, err := group.GetFeetTemplateVersion(c, int(req.GetPastureId()), feetTemplateId)
- if err != nil {
- apierr.ClassifiedAbort(c, err)
- return
- }
- ginutil.JSONResp(c, list)
- }
- // FeetTemplateUpgradeNewVersion 配方更新至最新版本
- func FeetTemplateUpgradeNewVersion(c *gin.Context) {
- var req feedPb.FeetTemplateVersionRequest
- if err := ginutil.BindProto(c, &req); err != nil {
- apierr.AbortBadRequest(c, http.StatusBadRequest, err)
- return
- }
- if err := valid.ValidateStruct(&req,
- valid.Field(&req.FeetTemplateId, valid.Required, valid.Length(1, 100)),
- valid.Field(&req.PastureId, valid.Required, valid.Min(1)),
- ); err != nil {
- apierr.ClassifiedAbort(c, err)
- return
- }
- feetTemplateId, _ := strconv.Atoi(req.GetFeetTemplateId())
- if err := group.FeetTemplateUpgradeNewVersion(c, int(req.GetPastureId()), feetTemplateId); err != nil {
- apierr.ClassifiedAbort(c, err)
- return
- }
- ginutil.JSONResp(c, &operationPb.CommonOK{
- Code: http.StatusOK,
- Msg: "ok",
- Data: &operationPb.Success{Success: true},
- })
- }
- // UpdateTmrGear 更新tmr_gear表数据
- func UpdateTmrGear(c *gin.Context) {
- var req operationPb.UpdateOrCreateTmrGearRequest
- if err := ginutil.BindProto(c, &req); err != nil {
- apierr.AbortBadRequest(c, http.StatusBadRequest, err)
- return
- }
- if err := valid.ValidateStruct(&req,
- valid.Field(&req.TmrId, valid.Required),
- valid.Field(&req.Params, valid.Required),
- ); err != nil {
- apierr.ClassifiedAbort(c, err)
- return
- }
- if err := sheep.UpdateOrCreateTmrGear(c, &req); err != nil {
- apierr.ClassifiedAbort(c, err)
- return
- }
- ginutil.JSONResp(c, &operationPb.CommonOK{
- Code: http.StatusOK,
- Msg: "ok",
- Data: &operationPb.Success{Success: true},
- })
- }
- func UseGear(c *gin.Context) {
- var req operationPb.UseGearRequest
- if err := ginutil.BindProto(c, &req); err != nil {
- apierr.AbortBadRequest(c, http.StatusBadRequest, err)
- return
- }
- if err := valid.ValidateStruct(&req,
- valid.Field(&req.TmrId, valid.Required),
- valid.Field(&req.Id, valid.Required),
- valid.Field(&req.TmrId, valid.Required),
- ); err != nil {
- apierr.ClassifiedAbort(c, err)
- return
- }
- data, err := sheep.UseGear(c, &req)
- if err != nil {
- apierr.ClassifiedAbort(c, err)
- return
- }
- ginutil.JSONResp(c, data)
- }
|