feed_formula.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. return
  21. }
  22. if err := group.DistributeFeedFormulaService(&req); err != nil {
  23. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  24. return
  25. }
  26. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  27. "success": true,
  28. })
  29. }
  30. func FeedFormulaIsModify(c *gin.Context) {
  31. appG := app.Gin{C: c}
  32. var req models.PastureFeedFormulaIsModifyRequest
  33. if err := c.BindJSON(&req); err != nil {
  34. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  35. return
  36. }
  37. if req.PastureId <= 0 {
  38. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  39. return
  40. }
  41. if err := group.FeedFormulaIsModifyService(&req); err != nil {
  42. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  43. return
  44. }
  45. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  46. "success": true,
  47. })
  48. }
  49. // AnalysisAccuracy 准确性分析
  50. func AnalysisAccuracy(c *gin.Context) {
  51. appG := app.Gin{C: c}
  52. var req models.AnalysisAccuracyRequest
  53. if err := c.BindJSON(&req); err != nil {
  54. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  55. return
  56. }
  57. if res, err := group.AnalysisAccuracyService(&req); err != nil {
  58. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  59. "error": err,
  60. })
  61. } else {
  62. appG.Response(http.StatusOK, e.SUCCESS, res)
  63. }
  64. }
  65. // ProcessAnalysis 过程分析
  66. func ProcessAnalysis(c *gin.Context) {
  67. appG := app.Gin{C: c}
  68. var req models.AnalysisAccuracyRequest
  69. if err := c.BindJSON(&req); err != nil {
  70. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  71. return
  72. }
  73. if res, err := group.ProcessAnalysisService(&req); err != nil {
  74. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  75. "error": err,
  76. })
  77. } else {
  78. appG.Response(http.StatusOK, e.SUCCESS, res)
  79. }
  80. }
  81. // SprinkleStatistics 撒料统计
  82. func SprinkleStatistics(c *gin.Context) {
  83. appG := app.Gin{C: c}
  84. var req models.SprinkleStatisticsRequest
  85. if err := c.BindJSON(&req); err != nil {
  86. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  87. return
  88. }
  89. if res, err := group.SprinkleStatisticsService(&req); err != nil {
  90. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  91. "error": err,
  92. })
  93. } else {
  94. appG.Response(http.StatusOK, e.SUCCESS, res)
  95. }
  96. }
  97. // DistributeAccount 账号下发
  98. func DistributeAccount(c *gin.Context) {
  99. appG := app.Gin{C: c}
  100. var req models.AccountDistributionRequest
  101. if err := c.BindJSON(&req); err != nil {
  102. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  103. return
  104. }
  105. if err := group.AccountDistributionService(&req); err != nil {
  106. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  107. "error": err,
  108. })
  109. } else {
  110. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  111. "success": true,
  112. })
  113. }
  114. }
  115. // ForageCategoryDistribute 饲料分类下发
  116. func ForageCategoryDistribute(c *gin.Context) {
  117. appG := app.Gin{C: c}
  118. var req models.CategoryRequest
  119. if err := c.BindJSON(&req); err != nil {
  120. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  121. return
  122. }
  123. if err := group.ForageCategoryDistributeService(&req); err != nil {
  124. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  125. "error": err,
  126. })
  127. } else {
  128. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  129. "success": true,
  130. })
  131. }
  132. }
  133. func CattleCategoryDistribute(c *gin.Context) {
  134. appG := app.Gin{C: c}
  135. var req models.CategoryRequest
  136. if err := c.BindJSON(&req); err != nil {
  137. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  138. return
  139. }
  140. if err := group.CattleCategoryDistributeService(&req); err != nil {
  141. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  142. "error": err,
  143. })
  144. } else {
  145. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  146. "success": true,
  147. })
  148. }
  149. }