package group import ( "net/http" "time" "tmr-watch/http/handle/restful" "tmr-watch/models" "tmr-watch/pkg/app" "tmr-watch/pkg/e" "github.com/gin-gonic/gin" ) func DistributeFeedFormula(c *gin.Context) { appG := app.Gin{C: c} var req models.PastureBody if err := c.BindJSON(&req); err != nil { appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) return } if len(req.Body) <= 0 { appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil) } feedTemplateList := make([]*models.FeedTemplate, len(req.Body)) for i, b := range req.Body { feedTemplateList[i] = &models.FeedTemplate{ PastureId: req.PastureId, TCode: b.EncodeNumber, TName: b.Name, TColor: b.Colour, CCid: int64(b.CattleCategoryId), CCName: b.CattleCategoryName, FTType: "", Source: "", Remark: b.Remarks, Enable: 1, Weight: 0, DryWeight: 0, Version: b.Version, SaveTime: time.Now().Format("2006-01-02 15:04:05"), IsIssue: 0, IssueVersion: 0, IssueId: 0, } } if _, err := restful.Engine.Insert(feedTemplateList); err != nil { appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil) return } appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{ "success": true, }) }