feed_formula.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. // EditRecodeFeedFormula 饲料配方修改记录
  58. func EditRecodeFeedFormula(c *gin.Context) {
  59. appG := app.Gin{C: c}
  60. var req models.CancelDistributeFeedFormulaRequest
  61. if err := c.BindJSON(&req); err != nil {
  62. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  63. return
  64. }
  65. if len(req.PastureDataId) <= 0 {
  66. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  67. return
  68. }
  69. if err := group.CancelDistributeFeedFormulaService(&req); err != nil {
  70. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  71. return
  72. }
  73. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  74. "success": true,
  75. })
  76. }
  77. func FeedFormulaIsModify(c *gin.Context) {
  78. appG := app.Gin{C: c}
  79. var req models.PastureFeedFormulaIsModifyRequest
  80. if err := c.BindJSON(&req); err != nil {
  81. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  82. return
  83. }
  84. if req.PastureId <= 0 {
  85. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  86. return
  87. }
  88. if err := group.FeedFormulaIsModifyService(&req); err != nil {
  89. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  90. return
  91. }
  92. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  93. "success": true,
  94. })
  95. }
  96. // FeedFormulaAsyncList 获取配方列表
  97. func FeedFormulaAsyncList(c *gin.Context) {
  98. appG := app.Gin{C: c}
  99. var req models.FeedListRequest
  100. if err := c.BindJSON(&req); err != nil {
  101. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  102. return
  103. }
  104. if req.PastureId <= 0 {
  105. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  106. return
  107. }
  108. if req.Page <= 0 {
  109. req.Page = 1
  110. }
  111. if req.PageSize <= 0 {
  112. req.PageSize = 50
  113. }
  114. data, err := group.FeedFormulaList(&req)
  115. if err != nil {
  116. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  117. return
  118. }
  119. appG.Response(http.StatusOK, e.SUCCESS, data)
  120. }
  121. // FeedAsyncList 获取饲料
  122. func FeedAsyncList(c *gin.Context) {
  123. appG := app.Gin{C: c}
  124. var req models.FeedListRequest
  125. if err := c.BindJSON(&req); err != nil {
  126. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  127. return
  128. }
  129. if req.PastureId <= 0 {
  130. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  131. return
  132. }
  133. if req.Page <= 0 {
  134. req.Page = 1
  135. }
  136. if req.PageSize <= 0 {
  137. req.PageSize = 50
  138. }
  139. data, err := group.FeedList(&req)
  140. if err != nil {
  141. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  142. return
  143. }
  144. appG.Response(http.StatusOK, e.SUCCESS, data)
  145. }
  146. // AnalysisAccuracy 准确性分析
  147. func AnalysisAccuracy(c *gin.Context) {
  148. appG := app.Gin{C: c}
  149. var req models.AnalysisAccuracyRequest
  150. if err := c.BindJSON(&req); err != nil {
  151. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  152. return
  153. }
  154. if res, err := group.AnalysisAccuracyService(&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, res)
  160. }
  161. }
  162. // ProcessAnalysis 过程分析
  163. func ProcessAnalysis(c *gin.Context) {
  164. appG := app.Gin{C: c}
  165. var req models.AnalysisAccuracyRequest
  166. if err := c.BindJSON(&req); err != nil {
  167. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  168. return
  169. }
  170. if res, err := group.ProcessAnalysisService(&req); err != nil {
  171. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  172. "error": err,
  173. })
  174. } else {
  175. appG.Response(http.StatusOK, e.SUCCESS, res)
  176. }
  177. }
  178. // SprinkleStatistics 撒料统计
  179. func SprinkleStatistics(c *gin.Context) {
  180. appG := app.Gin{C: c}
  181. var req models.SprinkleStatisticsRequest
  182. if err := c.BindJSON(&req); err != nil {
  183. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  184. return
  185. }
  186. if res, err := group.SprinkleStatisticsService(&req); err != nil {
  187. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  188. "error": err,
  189. })
  190. return
  191. } else {
  192. appG.Response(http.StatusOK, e.SUCCESS, res)
  193. }
  194. }
  195. // DistributeAccount 账号下发
  196. func DistributeAccount(c *gin.Context) {
  197. appG := app.Gin{C: c}
  198. var req models.AccountDistributionRequest
  199. if err := c.BindJSON(&req); err != nil {
  200. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  201. return
  202. }
  203. if err := group.AccountDistributionService(&req); err != nil {
  204. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  205. "error": err,
  206. })
  207. } else {
  208. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  209. "success": true,
  210. })
  211. }
  212. }
  213. // ForageCategoryDistribute 饲料分类下发
  214. func ForageCategoryDistribute(c *gin.Context) {
  215. appG := app.Gin{C: c}
  216. var req models.CategoryRequest
  217. if err := c.BindJSON(&req); err != nil {
  218. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  219. return
  220. }
  221. if err := group.ForageCategoryDistributeService(&req); err != nil {
  222. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  223. "error": err,
  224. })
  225. } else {
  226. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  227. "success": true,
  228. })
  229. }
  230. }
  231. func ForageCategoryDelete(c *gin.Context) {
  232. appG := app.Gin{C: c}
  233. var req models.CategoryDeleteRequest
  234. if err := c.BindJSON(&req); err != nil {
  235. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  236. return
  237. }
  238. if err := group.CategoryDeleteService(FeedCategoryDeleteKey, &req); err != nil {
  239. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  240. "error": err,
  241. })
  242. } else {
  243. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  244. "success": true,
  245. })
  246. }
  247. }
  248. func CowCategoryDistribute(c *gin.Context) {
  249. appG := app.Gin{C: c}
  250. var req models.CategoryRequest
  251. if err := c.BindJSON(&req); err != nil {
  252. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  253. return
  254. }
  255. if err := group.CattleCategoryDistributeService(&req); err != nil {
  256. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  257. "error": err,
  258. })
  259. } else {
  260. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  261. "success": true,
  262. })
  263. }
  264. }
  265. func CowCategoryDelete(c *gin.Context) {
  266. appG := app.Gin{C: c}
  267. var req models.CategoryDeleteRequest
  268. if err := c.BindJSON(&req); err != nil {
  269. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  270. return
  271. }
  272. if err := group.CategoryDeleteService(CowCategoryDeleteKey, &req); err != nil {
  273. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  274. "error": err,
  275. })
  276. } else {
  277. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  278. "success": true,
  279. })
  280. }
  281. }
  282. // FeedUsage 配方使用概况
  283. func FeedUsage(c *gin.Context) {
  284. appG := app.Gin{C: c}
  285. var req models.FeedFormulaUsageRequest
  286. if err := c.BindJSON(&req); err != nil {
  287. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  288. return
  289. }
  290. if res, err := group.FeedUsageService(&req); err != nil {
  291. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  292. "error": err,
  293. })
  294. return
  295. } else {
  296. appG.Response(http.StatusOK, e.SUCCESS, res)
  297. }
  298. }