feed_formula.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package group
  2. import (
  3. "net/http"
  4. "tmr-watch/models"
  5. "tmr-watch/pkg/app"
  6. "tmr-watch/pkg/e"
  7. "tmr-watch/service/group"
  8. "github.com/gin-gonic/gin"
  9. )
  10. // DistributeFeedFormula 饲料配方下发
  11. func DistributeFeedFormula(c *gin.Context) {
  12. appG := app.Gin{C: c}
  13. var req models.PastureBodyRequest
  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. if err := group.DistributeFeedFormulaService(&req); err != nil {
  22. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  23. return
  24. }
  25. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  26. "success": true,
  27. })
  28. }
  29. func FeedFormulaIsModify(c *gin.Context) {
  30. appG := app.Gin{C: c}
  31. var req models.PastureFeedFormulaIsModifyRequest
  32. if err := c.BindJSON(&req); err != nil {
  33. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  34. return
  35. }
  36. if req.PastureId <= 0 {
  37. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  38. }
  39. if err := group.FeedFormulaIsModifyService(&req); err != nil {
  40. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  41. return
  42. }
  43. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  44. "success": true,
  45. })
  46. }
  47. // AnalysisAccuracy 准确性分析
  48. func AnalysisAccuracy(c *gin.Context) {
  49. appG := app.Gin{C: c}
  50. var req models.AnalysisAccuracyRequest
  51. if err := c.BindJSON(&req); err != nil {
  52. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  53. return
  54. }
  55. if res, err := group.AnalysisAccuracyService(&req); err != nil {
  56. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  57. "error": err,
  58. })
  59. } else {
  60. appG.Response(http.StatusOK, e.SUCCESS, res)
  61. }
  62. }
  63. // ProcessAnalysis 过程分析
  64. func ProcessAnalysis(c *gin.Context) {
  65. appG := app.Gin{C: c}
  66. var req models.AnalysisAccuracyRequest
  67. if err := c.BindJSON(&req); err != nil {
  68. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  69. return
  70. }
  71. if res, err := group.ProcessAnalysisService(&req); err != nil {
  72. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  73. "error": err,
  74. })
  75. } else {
  76. appG.Response(http.StatusOK, e.SUCCESS, res)
  77. }
  78. }
  79. // SprinkleStatistics 撒料统计
  80. func SprinkleStatistics(c *gin.Context) {
  81. appG := app.Gin{C: c}
  82. var req models.SprinkleStatisticsRequest
  83. if err := c.BindJSON(&req); err != nil {
  84. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  85. return
  86. }
  87. if res, err := group.SprinkleStatisticsService(&req); err != nil {
  88. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  89. "error": err,
  90. })
  91. } else {
  92. appG.Response(http.StatusOK, e.SUCCESS, res)
  93. }
  94. }
  95. // DistributeAccount 账号下发
  96. func DistributeAccount(c *gin.Context) {
  97. appG := app.Gin{C: c}
  98. var req models.AccountDistributionRequest
  99. if err := c.BindJSON(&req); err != nil {
  100. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  101. return
  102. }
  103. if err := group.AccountDistributionService(&req); err != nil {
  104. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  105. "error": err,
  106. })
  107. } else {
  108. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  109. "success": true,
  110. })
  111. }
  112. }