feed_formula.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. func FeedFormulaList(c *gin.Context) {
  57. appG := app.Gin{C: c}
  58. var req models.FeedFormulaListRequest
  59. if err := c.BindJSON(&req); err != nil {
  60. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  61. return
  62. }
  63. if req.PastureId <= 0 {
  64. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  65. return
  66. }
  67. if req.Page <= 0 {
  68. req.Page = 1
  69. }
  70. if req.PageSize <= 0 {
  71. req.PageSize = 50
  72. }
  73. data, err := group.FeedFormulaList(&req)
  74. if err != nil {
  75. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  76. return
  77. }
  78. appG.Response(http.StatusOK, e.SUCCESS, data)
  79. }
  80. // AnalysisAccuracy 准确性分析
  81. func AnalysisAccuracy(c *gin.Context) {
  82. appG := app.Gin{C: c}
  83. var req models.AnalysisAccuracyRequest
  84. if err := c.BindJSON(&req); err != nil {
  85. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  86. return
  87. }
  88. if res, err := group.AnalysisAccuracyService(&req); err != nil {
  89. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  90. "error": err,
  91. })
  92. } else {
  93. appG.Response(http.StatusOK, e.SUCCESS, res)
  94. }
  95. }
  96. // ProcessAnalysis 过程分析
  97. func ProcessAnalysis(c *gin.Context) {
  98. appG := app.Gin{C: c}
  99. var req models.AnalysisAccuracyRequest
  100. if err := c.BindJSON(&req); err != nil {
  101. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  102. return
  103. }
  104. if res, err := group.ProcessAnalysisService(&req); err != nil {
  105. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  106. "error": err,
  107. })
  108. } else {
  109. appG.Response(http.StatusOK, e.SUCCESS, res)
  110. }
  111. }
  112. // SprinkleStatistics 撒料统计
  113. func SprinkleStatistics(c *gin.Context) {
  114. appG := app.Gin{C: c}
  115. var req models.SprinkleStatisticsRequest
  116. if err := c.BindJSON(&req); err != nil {
  117. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  118. return
  119. }
  120. if res, err := group.SprinkleStatisticsService(&req); err != nil {
  121. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  122. "error": err,
  123. })
  124. } else {
  125. appG.Response(http.StatusOK, e.SUCCESS, res)
  126. }
  127. }
  128. // DistributeAccount 账号下发
  129. func DistributeAccount(c *gin.Context) {
  130. appG := app.Gin{C: c}
  131. var req models.AccountDistributionRequest
  132. if err := c.BindJSON(&req); err != nil {
  133. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  134. return
  135. }
  136. if err := group.AccountDistributionService(&req); err != nil {
  137. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  138. "error": err,
  139. })
  140. } else {
  141. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  142. "success": true,
  143. })
  144. }
  145. }
  146. // ForageCategoryDistribute 饲料分类下发
  147. func ForageCategoryDistribute(c *gin.Context) {
  148. appG := app.Gin{C: c}
  149. var req models.CategoryRequest
  150. if err := c.BindJSON(&req); err != nil {
  151. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  152. return
  153. }
  154. if err := group.ForageCategoryDistributeService(&req); err != nil {
  155. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  156. "error": err,
  157. })
  158. } else {
  159. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  160. "success": true,
  161. })
  162. }
  163. }
  164. func ForageCategoryDelete(c *gin.Context) {
  165. appG := app.Gin{C: c}
  166. var req models.CategoryDeleteRequest
  167. if err := c.BindJSON(&req); err != nil {
  168. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  169. return
  170. }
  171. if err := group.CategoryDeleteService(FeedCategoryDeleteKey, &req); err != nil {
  172. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  173. "error": err,
  174. })
  175. } else {
  176. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  177. "success": true,
  178. })
  179. }
  180. }
  181. func CowCategoryDistribute(c *gin.Context) {
  182. appG := app.Gin{C: c}
  183. var req models.CategoryRequest
  184. if err := c.BindJSON(&req); err != nil {
  185. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  186. return
  187. }
  188. if err := group.CattleCategoryDistributeService(&req); err != nil {
  189. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  190. "error": err,
  191. })
  192. } else {
  193. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  194. "success": true,
  195. })
  196. }
  197. }
  198. func CowCategoryDelete(c *gin.Context) {
  199. appG := app.Gin{C: c}
  200. var req models.CategoryDeleteRequest
  201. if err := c.BindJSON(&req); err != nil {
  202. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  203. return
  204. }
  205. if err := group.CategoryDeleteService(CowCategoryDeleteKey, &req); err != nil {
  206. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  207. "error": err,
  208. })
  209. } else {
  210. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  211. "success": true,
  212. })
  213. }
  214. }