feed_formula.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package group
  2. import (
  3. "net/http"
  4. "time"
  5. "tmr-watch/http/handle/restful"
  6. "tmr-watch/models"
  7. "tmr-watch/pkg/app"
  8. "tmr-watch/pkg/e"
  9. "github.com/gin-gonic/gin"
  10. )
  11. func DistributeFeedFormula(c *gin.Context) {
  12. appG := app.Gin{C: c}
  13. var req models.PastureBody
  14. if err := c.BindJSON(&req); err != nil {
  15. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  16. return
  17. }
  18. if len(req.Body) <= 0 {
  19. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  20. }
  21. feedTemplateList := make([]*models.FeedTemplate, len(req.Body))
  22. for i, b := range req.Body {
  23. feedTemplateList[i] = &models.FeedTemplate{
  24. PastureId: req.PastureId,
  25. TCode: b.EncodeNumber,
  26. TName: b.Name,
  27. TColor: b.Colour,
  28. CCid: int64(b.CattleCategoryId),
  29. CCName: b.CattleCategoryName,
  30. FTType: "",
  31. Source: "",
  32. Remark: b.Remarks,
  33. Enable: 1,
  34. Weight: 0,
  35. DryWeight: 0,
  36. Version: b.Version,
  37. SaveTime: time.Now().Format("2006-01-02 15:04:05"),
  38. IsIssue: 0,
  39. IssueVersion: 0,
  40. IssueId: 0,
  41. }
  42. }
  43. if _, err := restful.Engine.Insert(feedTemplateList); err != nil {
  44. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  45. return
  46. }
  47. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  48. "success": true,
  49. })
  50. }