report.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package routers
  2. import (
  3. "fmt"
  4. "github.com/Anderson-Lu/gofasion/gofasion"
  5. "github.com/gin-gonic/gin"
  6. "io/ioutil"
  7. "kpt.xdmy/apiserver/service"
  8. "kpt.xdmy/pkg/app"
  9. "kpt.xdmy/pkg/e"
  10. "time"
  11. )
  12. func MaintainList(c *gin.Context) {
  13. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  14. fsion := gofasion.NewFasion(string(dataByte))
  15. pastureName := fsion.Get("pastureName").ValueStr()
  16. eqClassId := fsion.Get("eqClassId").ValueStr()
  17. start := fsion.Get("startTime").ValueStr()
  18. end := fsion.Get("endTime").ValueStr()
  19. level := fsion.Get("level").ValueStr()
  20. eqName := fsion.Get("eqName").ValueStr()
  21. eqClassPIdStr := fsion.Get("eqClassPIdStr").ValueStr()
  22. offset := fsion.Get("offset").ValueInt()
  23. pagecount := fsion.Get("pagecount").ValueDefaultInt(99999999)
  24. startTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", start), time.Local)
  25. if err != nil {
  26. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  27. return
  28. }
  29. endTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 23:59:59", end), time.Local)
  30. if err != nil {
  31. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  32. return
  33. }
  34. if level == "1" {
  35. total, resp, err := service.MaintainListPid(pastureName, eqClassId, startTime, endTime, offset, pagecount)
  36. if err != nil {
  37. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  38. return
  39. }
  40. c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok", "total": total, "pageNum": offset, "pageSize": pagecount})
  41. } else if level == "2" {
  42. total, resp, err := service.MaintainList(pastureName, eqClassId, startTime, endTime, offset, pagecount, eqClassPIdStr)
  43. if err != nil {
  44. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail", "total": total, "pageNum": offset, "pageSize": pagecount})
  45. return
  46. }
  47. c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok", "total": total, "pageNum": offset, "pageSize": pagecount})
  48. } else {
  49. total, resp, err := service.MaintainListEquipment(pastureName, eqClassId, startTime, endTime, offset, pagecount, eqName)
  50. if err != nil {
  51. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  52. return
  53. }
  54. c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok", "total": total, "pageNum": offset, "pageSize": pagecount})
  55. }
  56. }
  57. func MaintainListPid(c *gin.Context) {
  58. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  59. fsion := gofasion.NewFasion(string(dataByte))
  60. pastureName := fsion.Get("pastureName").ValueStr()
  61. eqClassId := fsion.Get("eqClassId").ValueStr()
  62. start := fsion.Get("startTime").ValueStr()
  63. end := fsion.Get("endTime").ValueStr()
  64. startTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", start), time.Local)
  65. if err != nil {
  66. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  67. return
  68. }
  69. endTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 23:59:59", end), time.Local)
  70. if err != nil {
  71. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  72. return
  73. }
  74. _, resp, err := service.MaintainListPid(pastureName, eqClassId, startTime, endTime, 0, 0)
  75. if err != nil {
  76. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  77. return
  78. }
  79. c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok"})
  80. }
  81. func MaintainListEquipment(c *gin.Context) {
  82. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  83. fsion := gofasion.NewFasion(string(dataByte))
  84. pastureName := fsion.Get("pastureName").ValueStr()
  85. eqClassId := fsion.Get("eqClassId").ValueStr()
  86. start := fsion.Get("startTime").ValueStr()
  87. end := fsion.Get("endTime").ValueStr()
  88. startTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", start), time.Local)
  89. if err != nil {
  90. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  91. return
  92. }
  93. endTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 23:59:59", end), time.Local)
  94. if err != nil {
  95. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  96. return
  97. }
  98. total, resp, err := service.MaintainListEquipment(pastureName, eqClassId, startTime, endTime, 0, 0, "")
  99. if err != nil {
  100. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  101. return
  102. }
  103. c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok", "total": total})
  104. }
  105. func GetOversee(c *gin.Context) {
  106. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  107. fsion := gofasion.NewFasion(string(dataByte))
  108. pastureName := fsion.Get("pastureId").ValueStr()
  109. eqClassId := fsion.Get("eqClassId").ValueStr()
  110. empname := fsion.Get("empname").ValueStr()
  111. offset := fsion.Get("offset").ValueDefaultInt(0)
  112. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  113. resp, err := service.GetOversee(pastureName, eqClassId, empname, offset, pagecount)
  114. if err != nil {
  115. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  116. return
  117. }
  118. c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok"})
  119. }
  120. func StartStopRecord(c *gin.Context) {
  121. dataByte, _ := ioutil.ReadAll(c.Request.Body)
  122. fsion := gofasion.NewFasion(string(dataByte))
  123. pastureId := fsion.Get("pastureId").ValueStr()
  124. eqName := fsion.Get("eqName").ValueStr()
  125. start := fsion.Get("startTime").ValueStr()
  126. end := fsion.Get("endTime").ValueStr()
  127. offset := fsion.Get("offset").ValueDefaultInt(0)
  128. pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
  129. startTime, err := time.ParseInLocation("2006-01-02", start, time.Local)
  130. if err != nil {
  131. c.JSON(500, map[string]interface{}{"code": 500, "data": "请选择日期", "msg": "fail"})
  132. return
  133. }
  134. endTime, err := time.ParseInLocation("2006-01-02", end, time.Local)
  135. if err != nil {
  136. c.JSON(500, map[string]interface{}{"code": 500, "data": "请选择日期", "msg": "fail"})
  137. return
  138. }
  139. resp, err := service.StartStopRecord(pastureId, eqName, startTime, endTime, offset, pagecount)
  140. if err != nil {
  141. c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
  142. return
  143. }
  144. c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok"})
  145. }
  146. func GetEnsiling(c *gin.Context) {
  147. appG := app.Gin{C: c}
  148. pastureId := c.Query("pastureId")
  149. ensilingList, err := svc.GetEnsiling(pastureId)
  150. if err != nil {
  151. appG.Response(500, e.ERROR, err)
  152. return
  153. }
  154. appG.Response(200, e.SUCCESS, ensilingList)
  155. }