report.go 6.1 KB

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