feed_formula.go 5.4 KB

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