123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package routers
- import (
- "fmt"
- "github.com/Anderson-Lu/gofasion/gofasion"
- "github.com/gin-gonic/gin"
- "io/ioutil"
- "kpt.xdmy/apiserver/service"
- "time"
- )
- func MaintainList(c *gin.Context) {
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- pastureName := fsion.Get("pastureName").ValueStr()
- eqClassId := fsion.Get("eqClassId").ValueStr()
- start := fsion.Get("startTime").ValueStr()
- end := fsion.Get("endTime").ValueStr()
- level := fsion.Get("level").ValueStr()
- eqName := fsion.Get("eqName").ValueStr()
- offset := fsion.Get("offset").ValueInt()
- pagecount := fsion.Get("pagecount").ValueDefaultInt(99999999)
- startTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", start), time.Local)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- endTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 23:59:59", end), time.Local)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- if level == "1" {
- total, resp, err := service.MaintainListPid(pastureName, eqClassId, startTime, endTime, offset, pagecount)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok", "total": total, "pageNum": offset, "pageSize": pagecount})
- } else if level == "2" {
- total, resp, err := service.MaintainList(pastureName, eqClassId, startTime, endTime, offset, pagecount)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail", "total": total, "pageNum": offset, "pageSize": pagecount})
- return
- }
- c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok", "total": total, "pageNum": offset, "pageSize": pagecount})
- } else {
- total, resp, err := service.MaintainListEquipment(pastureName, eqClassId, startTime, endTime, offset, pagecount, eqName)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok", "total": total, "pageNum": offset, "pageSize": pagecount})
- }
- }
- func MaintainListPid(c *gin.Context) {
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- pastureName := fsion.Get("pastureName").ValueStr()
- eqClassId := fsion.Get("eqClassId").ValueStr()
- start := fsion.Get("startTime").ValueStr()
- end := fsion.Get("endTime").ValueStr()
- startTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", start), time.Local)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- endTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 23:59:59", end), time.Local)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- _, resp, err := service.MaintainListPid(pastureName, eqClassId, startTime, endTime, 0, 0)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok"})
- }
- func MaintainListEquipment(c *gin.Context) {
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- pastureName := fsion.Get("pastureName").ValueStr()
- eqClassId := fsion.Get("eqClassId").ValueStr()
- start := fsion.Get("startTime").ValueStr()
- end := fsion.Get("endTime").ValueStr()
- startTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 00:00:00", start), time.Local)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- endTime, err := time.ParseInLocation("2006-01-02 15:04:05", fmt.Sprintf("%s 23:59:59", end), time.Local)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- total, resp, err := service.MaintainListEquipment(pastureName, eqClassId, startTime, endTime, 0, 0, "")
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok", "total": total})
- }
- func GetOversee(c *gin.Context) {
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- pastureName := fsion.Get("pastureId").ValueStr()
- eqClassId := fsion.Get("eqClassId").ValueStr()
- empname := fsion.Get("empname").ValueStr()
- offset := fsion.Get("offset").ValueDefaultInt(0)
- pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
- resp, err := service.GetOversee(pastureName, eqClassId, empname, offset, pagecount)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok"})
- }
- func StartStopRecord(c *gin.Context) {
- dataByte, _ := ioutil.ReadAll(c.Request.Body)
- fsion := gofasion.NewFasion(string(dataByte))
- pastureId := fsion.Get("pastureId").ValueStr()
- eqName := fsion.Get("eqName").ValueStr()
- start := fsion.Get("startTime").ValueStr()
- end := fsion.Get("endTime").ValueStr()
- offset := fsion.Get("offset").ValueDefaultInt(0)
- pagecount := fsion.Get("pagecount").ValueDefaultInt(0)
- startTime, err := time.ParseInLocation("2006-01-02", start, time.Local)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": "请选择日期", "msg": "fail"})
- return
- }
- endTime, err := time.ParseInLocation("2006-01-02", end, time.Local)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": "请选择日期", "msg": "fail"})
- return
- }
- resp, err := service.StartStopRecord(pastureId, eqName, startTime, endTime, offset, pagecount)
- if err != nil {
- c.JSON(500, map[string]interface{}{"code": 500, "data": err.Error(), "msg": "fail"})
- return
- }
- c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok"})
- }
|