feed_formula.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. return
  125. } else {
  126. appG.Response(http.StatusOK, e.SUCCESS, res)
  127. }
  128. }
  129. // DistributeAccount 账号下发
  130. func DistributeAccount(c *gin.Context) {
  131. appG := app.Gin{C: c}
  132. var req models.AccountDistributionRequest
  133. if err := c.BindJSON(&req); err != nil {
  134. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  135. return
  136. }
  137. if err := group.AccountDistributionService(&req); err != nil {
  138. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  139. "error": err,
  140. })
  141. } else {
  142. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  143. "success": true,
  144. })
  145. }
  146. }
  147. // ForageCategoryDistribute 饲料分类下发
  148. func ForageCategoryDistribute(c *gin.Context) {
  149. appG := app.Gin{C: c}
  150. var req models.CategoryRequest
  151. if err := c.BindJSON(&req); err != nil {
  152. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  153. return
  154. }
  155. if err := group.ForageCategoryDistributeService(&req); err != nil {
  156. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  157. "error": err,
  158. })
  159. } else {
  160. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  161. "success": true,
  162. })
  163. }
  164. }
  165. func ForageCategoryDelete(c *gin.Context) {
  166. appG := app.Gin{C: c}
  167. var req models.CategoryDeleteRequest
  168. if err := c.BindJSON(&req); err != nil {
  169. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  170. return
  171. }
  172. if err := group.CategoryDeleteService(FeedCategoryDeleteKey, &req); err != nil {
  173. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  174. "error": err,
  175. })
  176. } else {
  177. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  178. "success": true,
  179. })
  180. }
  181. }
  182. func CowCategoryDistribute(c *gin.Context) {
  183. appG := app.Gin{C: c}
  184. var req models.CategoryRequest
  185. if err := c.BindJSON(&req); err != nil {
  186. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  187. return
  188. }
  189. if err := group.CattleCategoryDistributeService(&req); err != nil {
  190. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  191. "error": err,
  192. })
  193. } else {
  194. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  195. "success": true,
  196. })
  197. }
  198. }
  199. func CowCategoryDelete(c *gin.Context) {
  200. appG := app.Gin{C: c}
  201. var req models.CategoryDeleteRequest
  202. if err := c.BindJSON(&req); err != nil {
  203. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  204. return
  205. }
  206. if err := group.CategoryDeleteService(CowCategoryDeleteKey, &req); err != nil {
  207. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  208. "error": err,
  209. })
  210. } else {
  211. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  212. "success": true,
  213. })
  214. }
  215. }
  216. // FeedUsage 配方使用概况
  217. func FeedUsage(c *gin.Context) {
  218. appG := app.Gin{C: c}
  219. var req models.FeedFormulaUsageRequest
  220. if err := c.BindJSON(&req); err != nil {
  221. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  222. return
  223. }
  224. if res, err := group.FeedUsageService(&req); err != nil {
  225. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  226. "error": err,
  227. })
  228. return
  229. } else {
  230. appG.Response(http.StatusOK, e.SUCCESS, res)
  231. }
  232. }