feed_formula.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. const (
  11. FeedCategoryDeleteKey = "feed_delete"
  12. CowCategoryDeleteKey = "cow_delete"
  13. )
  14. // DistributeFeedFormula 饲料配方下发
  15. func DistributeFeedFormula(c *gin.Context) {
  16. appG := app.Gin{C: c}
  17. var req models.PastureBodyRequest
  18. if err := c.BindJSON(&req); err != nil {
  19. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  20. return
  21. }
  22. if len(req.Body) <= 0 {
  23. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  24. return
  25. }
  26. if err := group.DistributeFeedFormulaService(&req); err != nil {
  27. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  28. return
  29. }
  30. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  31. "success": true,
  32. })
  33. }
  34. func FeedFormulaIsModify(c *gin.Context) {
  35. appG := app.Gin{C: c}
  36. var req models.PastureFeedFormulaIsModifyRequest
  37. if err := c.BindJSON(&req); err != nil {
  38. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  39. return
  40. }
  41. if req.PastureId <= 0 {
  42. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  43. return
  44. }
  45. if err := group.FeedFormulaIsModifyService(&req); err != nil {
  46. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  47. return
  48. }
  49. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  50. "success": true,
  51. })
  52. }
  53. // AnalysisAccuracy 准确性分析
  54. func AnalysisAccuracy(c *gin.Context) {
  55. appG := app.Gin{C: c}
  56. var req models.AnalysisAccuracyRequest
  57. if err := c.BindJSON(&req); err != nil {
  58. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  59. return
  60. }
  61. if res, err := group.AnalysisAccuracyService(&req); err != nil {
  62. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  63. "error": err,
  64. })
  65. } else {
  66. appG.Response(http.StatusOK, e.SUCCESS, res)
  67. }
  68. }
  69. // ProcessAnalysis 过程分析
  70. func ProcessAnalysis(c *gin.Context) {
  71. appG := app.Gin{C: c}
  72. var req models.AnalysisAccuracyRequest
  73. if err := c.BindJSON(&req); err != nil {
  74. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  75. return
  76. }
  77. if res, err := group.ProcessAnalysisService(&req); err != nil {
  78. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  79. "error": err,
  80. })
  81. } else {
  82. appG.Response(http.StatusOK, e.SUCCESS, res)
  83. }
  84. }
  85. // SprinkleStatistics 撒料统计
  86. func SprinkleStatistics(c *gin.Context) {
  87. appG := app.Gin{C: c}
  88. var req models.SprinkleStatisticsRequest
  89. if err := c.BindJSON(&req); err != nil {
  90. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  91. return
  92. }
  93. if res, err := group.SprinkleStatisticsService(&req); err != nil {
  94. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  95. "error": err,
  96. })
  97. } else {
  98. appG.Response(http.StatusOK, e.SUCCESS, res)
  99. }
  100. }
  101. // DistributeAccount 账号下发
  102. func DistributeAccount(c *gin.Context) {
  103. appG := app.Gin{C: c}
  104. var req models.AccountDistributionRequest
  105. if err := c.BindJSON(&req); err != nil {
  106. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  107. return
  108. }
  109. if err := group.AccountDistributionService(&req); err != nil {
  110. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  111. "error": err,
  112. })
  113. } else {
  114. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  115. "success": true,
  116. })
  117. }
  118. }
  119. // ForageCategoryDistribute 饲料分类下发
  120. func ForageCategoryDistribute(c *gin.Context) {
  121. appG := app.Gin{C: c}
  122. var req models.CategoryRequest
  123. if err := c.BindJSON(&req); err != nil {
  124. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  125. return
  126. }
  127. if err := group.ForageCategoryDistributeService(&req); err != nil {
  128. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  129. "error": err,
  130. })
  131. } else {
  132. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  133. "success": true,
  134. })
  135. }
  136. }
  137. func ForageCategoryDelete(c *gin.Context) {
  138. appG := app.Gin{C: c}
  139. var req models.CategoryDeleteRequest
  140. if err := c.BindJSON(&req); err != nil {
  141. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  142. return
  143. }
  144. if err := group.CategoryDeleteService(FeedCategoryDeleteKey, &req); err != nil {
  145. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  146. "error": err,
  147. })
  148. } else {
  149. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  150. "success": true,
  151. })
  152. }
  153. }
  154. func CowCategoryDistribute(c *gin.Context) {
  155. appG := app.Gin{C: c}
  156. var req models.CategoryRequest
  157. if err := c.BindJSON(&req); err != nil {
  158. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  159. return
  160. }
  161. if err := group.CattleCategoryDistributeService(&req); err != nil {
  162. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  163. "error": err,
  164. })
  165. } else {
  166. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  167. "success": true,
  168. })
  169. }
  170. }
  171. func CowCategoryDelete(c *gin.Context) {
  172. appG := app.Gin{C: c}
  173. var req models.CategoryDeleteRequest
  174. if err := c.BindJSON(&req); err != nil {
  175. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  176. return
  177. }
  178. if err := group.CategoryDeleteService(CowCategoryDeleteKey, &req); err != nil {
  179. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  180. "error": err,
  181. })
  182. } else {
  183. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  184. "success": true,
  185. })
  186. }
  187. }