feed_formula.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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.FeedFormula) <= 0 {
  26. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  27. return
  28. }
  29. if len(req.FeedFormulaDetail) <= 0 {
  30. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  31. return
  32. }
  33. if err := group.DistributeFeedFormulaService(&req); err != nil {
  34. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  35. return
  36. }
  37. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  38. "success": true,
  39. })
  40. }
  41. // CancelDistributeFeedFormula 饲料取消配方下发
  42. func CancelDistributeFeedFormula(c *gin.Context) {
  43. appG := app.Gin{C: c}
  44. var req models.CancelDistributeFeedFormulaRequest
  45. if err := c.BindJSON(&req); err != nil {
  46. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  47. return
  48. }
  49. if len(req.PastureDataId) <= 0 {
  50. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  51. return
  52. }
  53. if err := group.CancelDistributeFeedFormulaService(&req); err != nil {
  54. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  55. return
  56. }
  57. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  58. "success": true,
  59. })
  60. }
  61. // EditRecodeFeedFormula 饲料配方修改记录
  62. func EditRecodeFeedFormula(c *gin.Context) {
  63. appG := app.Gin{C: c}
  64. var req models.CancelDistributeFeedFormulaRequest
  65. if err := c.BindJSON(&req); err != nil {
  66. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  67. return
  68. }
  69. if len(req.PastureDataId) <= 0 {
  70. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  71. return
  72. }
  73. if err := group.CancelDistributeFeedFormulaService(&req); err != nil {
  74. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  75. return
  76. }
  77. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  78. "success": true,
  79. })
  80. }
  81. func FeedFormulaIsModify(c *gin.Context) {
  82. appG := app.Gin{C: c}
  83. var req models.PastureFeedFormulaIsModifyRequest
  84. if err := c.BindJSON(&req); err != nil {
  85. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  86. return
  87. }
  88. if req.PastureId <= 0 {
  89. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  90. return
  91. }
  92. if err := group.FeedFormulaIsModifyService(&req); err != nil {
  93. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  94. return
  95. }
  96. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  97. "success": true,
  98. })
  99. }
  100. // FeedFormulaAsyncList 获取配方列表
  101. func FeedFormulaAsyncList(c *gin.Context) {
  102. appG := app.Gin{C: c}
  103. var req models.FeedListRequest
  104. if err := c.BindJSON(&req); err != nil {
  105. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  106. return
  107. }
  108. if req.PastureId <= 0 {
  109. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  110. return
  111. }
  112. if req.Page <= 0 {
  113. req.Page = 1
  114. }
  115. if req.PageSize <= 0 {
  116. req.PageSize = 50
  117. }
  118. data, err := group.FeedFormulaList(&req)
  119. if err != nil {
  120. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  121. return
  122. }
  123. appG.Response(http.StatusOK, e.SUCCESS, data)
  124. }
  125. // FeedAsyncList 获取饲料
  126. func FeedAsyncList(c *gin.Context) {
  127. appG := app.Gin{C: c}
  128. var req models.FeedListRequest
  129. if err := c.BindJSON(&req); err != nil {
  130. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  131. return
  132. }
  133. if req.PastureId <= 0 {
  134. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  135. return
  136. }
  137. if req.Page <= 0 {
  138. req.Page = 1
  139. }
  140. if req.PageSize <= 0 {
  141. req.PageSize = 50
  142. }
  143. data, err := group.FeedList(&req)
  144. if err != nil {
  145. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  146. return
  147. }
  148. appG.Response(http.StatusOK, e.SUCCESS, data)
  149. }
  150. // FeedFormulaDetailList 饲料配方详情
  151. func FeedFormulaDetailList(c *gin.Context) {
  152. appG := app.Gin{C: c}
  153. var req models.FeedListRequest
  154. if err := c.BindJSON(&req); err != nil {
  155. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  156. return
  157. }
  158. if req.PastureId <= 0 {
  159. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  160. return
  161. }
  162. if req.Page <= 0 {
  163. req.Page = 1
  164. }
  165. if req.PageSize <= 0 {
  166. req.PageSize = 50
  167. }
  168. data, err := group.FeedTemplateDetailList(&req)
  169. if err != nil {
  170. appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
  171. return
  172. }
  173. appG.Response(http.StatusOK, e.SUCCESS, data)
  174. }
  175. // AnalysisAccuracy 准确性分析
  176. func AnalysisAccuracy(c *gin.Context) {
  177. appG := app.Gin{C: c}
  178. var req models.AnalysisAccuracyRequest
  179. if err := c.BindJSON(&req); err != nil {
  180. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  181. return
  182. }
  183. if res, err := group.AnalysisAccuracyService(&req); err != nil {
  184. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  185. "error": err,
  186. })
  187. } else {
  188. appG.Response(http.StatusOK, e.SUCCESS, res)
  189. }
  190. }
  191. // ProcessAnalysis 过程分析
  192. func ProcessAnalysis(c *gin.Context) {
  193. appG := app.Gin{C: c}
  194. var req models.AnalysisAccuracyRequest
  195. if err := c.BindJSON(&req); err != nil {
  196. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  197. return
  198. }
  199. if res, err := group.ProcessAnalysisService(&req); err != nil {
  200. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  201. "error": err,
  202. })
  203. } else {
  204. appG.Response(http.StatusOK, e.SUCCESS, res)
  205. }
  206. }
  207. // SprinkleStatistics 撒料统计
  208. func SprinkleStatistics(c *gin.Context) {
  209. appG := app.Gin{C: c}
  210. var req models.SprinkleStatisticsRequest
  211. if err := c.BindJSON(&req); err != nil {
  212. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  213. return
  214. }
  215. if res, err := group.SprinkleStatisticsService(&req); err != nil {
  216. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  217. "error": err,
  218. })
  219. return
  220. } else {
  221. appG.Response(http.StatusOK, e.SUCCESS, res)
  222. }
  223. }
  224. // DistributeAccount 账号下发
  225. func DistributeAccount(c *gin.Context) {
  226. appG := app.Gin{C: c}
  227. var req models.AccountDistributionRequest
  228. if err := c.BindJSON(&req); err != nil {
  229. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  230. return
  231. }
  232. if err := group.AccountDistributionService(&req); err != nil {
  233. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  234. "error": err,
  235. })
  236. } else {
  237. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  238. "success": true,
  239. })
  240. }
  241. }
  242. // ForageCategoryDistribute 饲料分类下发
  243. func ForageCategoryDistribute(c *gin.Context) {
  244. appG := app.Gin{C: c}
  245. var req models.CategoryRequest
  246. if err := c.BindJSON(&req); err != nil {
  247. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  248. return
  249. }
  250. if err := group.ForageCategoryDistributeService(&req); err != nil {
  251. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  252. "error": err,
  253. })
  254. } else {
  255. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  256. "success": true,
  257. })
  258. }
  259. }
  260. func ForageCategoryDelete(c *gin.Context) {
  261. appG := app.Gin{C: c}
  262. var req models.CategoryDeleteRequest
  263. if err := c.BindJSON(&req); err != nil {
  264. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  265. return
  266. }
  267. if err := group.CategoryDeleteService(FeedCategoryDeleteKey, &req); err != nil {
  268. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  269. "error": err,
  270. })
  271. } else {
  272. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  273. "success": true,
  274. })
  275. }
  276. }
  277. func CowCategoryDistribute(c *gin.Context) {
  278. appG := app.Gin{C: c}
  279. var req models.CategoryRequest
  280. if err := c.BindJSON(&req); err != nil {
  281. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  282. return
  283. }
  284. if err := group.CattleCategoryDistributeService(&req); err != nil {
  285. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  286. "error": err,
  287. })
  288. } else {
  289. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  290. "success": true,
  291. })
  292. }
  293. }
  294. func CowCategoryDelete(c *gin.Context) {
  295. appG := app.Gin{C: c}
  296. var req models.CategoryDeleteRequest
  297. if err := c.BindJSON(&req); err != nil {
  298. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  299. return
  300. }
  301. if err := group.CategoryDeleteService(CowCategoryDeleteKey, &req); err != nil {
  302. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  303. "error": err,
  304. })
  305. } else {
  306. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
  307. "success": true,
  308. })
  309. }
  310. }
  311. // FeedUsage 配方使用概况
  312. func FeedUsage(c *gin.Context) {
  313. appG := app.Gin{C: c}
  314. var req models.FeedFormulaUsageRequest
  315. if err := c.BindJSON(&req); err != nil {
  316. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  317. return
  318. }
  319. if res, err := group.FeedUsageService(&req); err != nil {
  320. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  321. "error": err,
  322. })
  323. return
  324. } else {
  325. appG.Response(http.StatusOK, e.SUCCESS, res)
  326. }
  327. }
  328. // FeedFormulaVersion 集团端配方信息更新同步
  329. func FeedFormulaVersion(c *gin.Context) {
  330. appG := app.Gin{C: c}
  331. var req models.FeedFormulaUpdateVersionRequest
  332. if err := c.BindJSON(&req); err != nil {
  333. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  334. return
  335. }
  336. if err := group.FeedFormulaVersionService(&req); err != nil {
  337. appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
  338. "error": err,
  339. })
  340. return
  341. }
  342. appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{"success": true})
  343. }