feed_formula.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. // FeedFormulaDetailList 饲料配方详情
  147. func FeedFormulaDetailList(c *gin.Context) {
  148. appG := app.Gin{C: c}
  149. var req models.FeedListRequest
  150. if err := c.BindJSON(&req); err != nil {
  151. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  152. return
  153. }
  154. if req.PastureId <= 0 {
  155. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  156. return
  157. }
  158. if req.Page <= 0 {
  159. req.Page = 1
  160. }
  161. if req.PageSize <= 0 {
  162. req.PageSize = 50
  163. }
  164. data, err := group.FeedTemplateDetailList(&req)
  165. if err != nil {
  166. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  167. return
  168. }
  169. appG.Response(http.StatusOK, e.SUCCESS, data)
  170. }
  171. // AnalysisAccuracy 准确性分析
  172. func AnalysisAccuracy(c *gin.Context) {
  173. appG := app.Gin{C: c}
  174. var req models.AnalysisAccuracyRequest
  175. if err := c.BindJSON(&req); err != nil {
  176. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  177. return
  178. }
  179. if res, err := group.AnalysisAccuracyService(&req); err != nil {
  180. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  181. "error": err,
  182. })
  183. } else {
  184. appG.Response(http.StatusOK, e.SUCCESS, res)
  185. }
  186. }
  187. // ProcessAnalysis 过程分析
  188. func ProcessAnalysis(c *gin.Context) {
  189. appG := app.Gin{C: c}
  190. var req models.AnalysisAccuracyRequest
  191. if err := c.BindJSON(&req); err != nil {
  192. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  193. return
  194. }
  195. if res, err := group.ProcessAnalysisService(&req); err != nil {
  196. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  197. "error": err,
  198. })
  199. } else {
  200. appG.Response(http.StatusOK, e.SUCCESS, res)
  201. }
  202. }
  203. // SprinkleStatistics 撒料统计
  204. func SprinkleStatistics(c *gin.Context) {
  205. appG := app.Gin{C: c}
  206. var req models.SprinkleStatisticsRequest
  207. if err := c.BindJSON(&req); err != nil {
  208. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  209. return
  210. }
  211. if res, err := group.SprinkleStatisticsService(&req); err != nil {
  212. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  213. "error": err,
  214. })
  215. return
  216. } else {
  217. appG.Response(http.StatusOK, e.SUCCESS, res)
  218. }
  219. }
  220. // DistributeAccount 账号下发
  221. func DistributeAccount(c *gin.Context) {
  222. appG := app.Gin{C: c}
  223. var req models.AccountDistributionRequest
  224. if err := c.BindJSON(&req); err != nil {
  225. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  226. return
  227. }
  228. if err := group.AccountDistributionService(&req); err != nil {
  229. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  230. "error": err,
  231. })
  232. } else {
  233. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  234. "success": true,
  235. })
  236. }
  237. }
  238. // ForageCategoryDistribute 饲料分类下发
  239. func ForageCategoryDistribute(c *gin.Context) {
  240. appG := app.Gin{C: c}
  241. var req models.CategoryRequest
  242. if err := c.BindJSON(&req); err != nil {
  243. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  244. return
  245. }
  246. if err := group.ForageCategoryDistributeService(&req); err != nil {
  247. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  248. "error": err,
  249. })
  250. } else {
  251. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  252. "success": true,
  253. })
  254. }
  255. }
  256. func ForageCategoryDelete(c *gin.Context) {
  257. appG := app.Gin{C: c}
  258. var req models.CategoryDeleteRequest
  259. if err := c.BindJSON(&req); err != nil {
  260. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  261. return
  262. }
  263. if err := group.CategoryDeleteService(FeedCategoryDeleteKey, &req); err != nil {
  264. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  265. "error": err,
  266. })
  267. } else {
  268. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  269. "success": true,
  270. })
  271. }
  272. }
  273. func CowCategoryDistribute(c *gin.Context) {
  274. appG := app.Gin{C: c}
  275. var req models.CategoryRequest
  276. if err := c.BindJSON(&req); err != nil {
  277. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  278. return
  279. }
  280. if err := group.CattleCategoryDistributeService(&req); err != nil {
  281. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  282. "error": err,
  283. })
  284. } else {
  285. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  286. "success": true,
  287. })
  288. }
  289. }
  290. func CowCategoryDelete(c *gin.Context) {
  291. appG := app.Gin{C: c}
  292. var req models.CategoryDeleteRequest
  293. if err := c.BindJSON(&req); err != nil {
  294. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  295. return
  296. }
  297. if err := group.CategoryDeleteService(CowCategoryDeleteKey, &req); err != nil {
  298. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  299. "error": err,
  300. })
  301. } else {
  302. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  303. "success": true,
  304. })
  305. }
  306. }
  307. // FeedUsage 配方使用概况
  308. func FeedUsage(c *gin.Context) {
  309. appG := app.Gin{C: c}
  310. var req models.FeedFormulaUsageRequest
  311. if err := c.BindJSON(&req); err != nil {
  312. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  313. return
  314. }
  315. if res, err := group.FeedUsageService(&req); err != nil {
  316. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  317. "error": err,
  318. })
  319. return
  320. } else {
  321. appG.Response(http.StatusOK, e.SUCCESS, res)
  322. }
  323. }