feed_formula.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. // CancelDistributeFeedFormula 饲料取消配方下发
  38. func CancelDistributeFeedFormula(c *gin.Context) {
  39. appG := app.Gin{C: c}
  40. var req models.CancelDistributeFeedFormulaRequest
  41. if err := c.BindJSON(&req); err != nil {
  42. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  43. return
  44. }
  45. if len(req.PastureDataId) <= 0 {
  46. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  47. return
  48. }
  49. if err := group.CancelDistributeFeedFormulaService(&req); err != nil {
  50. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  51. return
  52. }
  53. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  54. "success": true,
  55. })
  56. }
  57. func FeedFormulaIsModify(c *gin.Context) {
  58. appG := app.Gin{C: c}
  59. var req models.PastureFeedFormulaIsModifyRequest
  60. if err := c.BindJSON(&req); err != nil {
  61. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  62. return
  63. }
  64. if req.PastureId <= 0 {
  65. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  66. return
  67. }
  68. if err := group.FeedFormulaIsModifyService(&req); err != nil {
  69. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  70. return
  71. }
  72. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  73. "success": true,
  74. })
  75. }
  76. func FeedFormulaList(c *gin.Context) {
  77. appG := app.Gin{C: c}
  78. var req models.FeedFormulaListRequest
  79. if err := c.BindJSON(&req); err != nil {
  80. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  81. return
  82. }
  83. if req.PastureId <= 0 {
  84. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  85. return
  86. }
  87. if req.Page <= 0 {
  88. req.Page = 1
  89. }
  90. if req.PageSize <= 0 {
  91. req.PageSize = 50
  92. }
  93. data, err := group.FeedFormulaList(&req)
  94. if err != nil {
  95. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  96. return
  97. }
  98. appG.Response(http.StatusOK, e.SUCCESS, data)
  99. }
  100. // AnalysisAccuracy 准确性分析
  101. func AnalysisAccuracy(c *gin.Context) {
  102. appG := app.Gin{C: c}
  103. var req models.AnalysisAccuracyRequest
  104. if err := c.BindJSON(&req); err != nil {
  105. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  106. return
  107. }
  108. if res, err := group.AnalysisAccuracyService(&req); err != nil {
  109. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  110. "error": err,
  111. })
  112. } else {
  113. appG.Response(http.StatusOK, e.SUCCESS, res)
  114. }
  115. }
  116. // ProcessAnalysis 过程分析
  117. func ProcessAnalysis(c *gin.Context) {
  118. appG := app.Gin{C: c}
  119. var req models.AnalysisAccuracyRequest
  120. if err := c.BindJSON(&req); err != nil {
  121. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  122. return
  123. }
  124. if res, err := group.ProcessAnalysisService(&req); err != nil {
  125. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  126. "error": err,
  127. })
  128. } else {
  129. appG.Response(http.StatusOK, e.SUCCESS, res)
  130. }
  131. }
  132. // SprinkleStatistics 撒料统计
  133. func SprinkleStatistics(c *gin.Context) {
  134. appG := app.Gin{C: c}
  135. var req models.SprinkleStatisticsRequest
  136. if err := c.BindJSON(&req); err != nil {
  137. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  138. return
  139. }
  140. if res, err := group.SprinkleStatisticsService(&req); err != nil {
  141. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  142. "error": err,
  143. })
  144. return
  145. } else {
  146. appG.Response(http.StatusOK, e.SUCCESS, res)
  147. }
  148. }
  149. // DistributeAccount 账号下发
  150. func DistributeAccount(c *gin.Context) {
  151. appG := app.Gin{C: c}
  152. var req models.AccountDistributionRequest
  153. if err := c.BindJSON(&req); err != nil {
  154. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  155. return
  156. }
  157. if err := group.AccountDistributionService(&req); err != nil {
  158. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  159. "error": err,
  160. })
  161. } else {
  162. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  163. "success": true,
  164. })
  165. }
  166. }
  167. // ForageCategoryDistribute 饲料分类下发
  168. func ForageCategoryDistribute(c *gin.Context) {
  169. appG := app.Gin{C: c}
  170. var req models.CategoryRequest
  171. if err := c.BindJSON(&req); err != nil {
  172. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  173. return
  174. }
  175. if err := group.ForageCategoryDistributeService(&req); err != nil {
  176. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  177. "error": err,
  178. })
  179. } else {
  180. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  181. "success": true,
  182. })
  183. }
  184. }
  185. func ForageCategoryDelete(c *gin.Context) {
  186. appG := app.Gin{C: c}
  187. var req models.CategoryDeleteRequest
  188. if err := c.BindJSON(&req); err != nil {
  189. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  190. return
  191. }
  192. if err := group.CategoryDeleteService(FeedCategoryDeleteKey, &req); err != nil {
  193. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  194. "error": err,
  195. })
  196. } else {
  197. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  198. "success": true,
  199. })
  200. }
  201. }
  202. func CowCategoryDistribute(c *gin.Context) {
  203. appG := app.Gin{C: c}
  204. var req models.CategoryRequest
  205. if err := c.BindJSON(&req); err != nil {
  206. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  207. return
  208. }
  209. if err := group.CattleCategoryDistributeService(&req); err != nil {
  210. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  211. "error": err,
  212. })
  213. } else {
  214. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  215. "success": true,
  216. })
  217. }
  218. }
  219. func CowCategoryDelete(c *gin.Context) {
  220. appG := app.Gin{C: c}
  221. var req models.CategoryDeleteRequest
  222. if err := c.BindJSON(&req); err != nil {
  223. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  224. return
  225. }
  226. if err := group.CategoryDeleteService(CowCategoryDeleteKey, &req); err != nil {
  227. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  228. "error": err,
  229. })
  230. } else {
  231. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  232. "success": true,
  233. })
  234. }
  235. }
  236. // FeedUsage 配方使用概况
  237. func FeedUsage(c *gin.Context) {
  238. appG := app.Gin{C: c}
  239. var req models.FeedFormulaUsageRequest
  240. if err := c.BindJSON(&req); err != nil {
  241. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  242. return
  243. }
  244. if res, err := group.FeedUsageService(&req); err != nil {
  245. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  246. "error": err,
  247. })
  248. return
  249. } else {
  250. appG.Response(http.StatusOK, e.SUCCESS, res)
  251. }
  252. }