package routers import ( "fmt" "github.com/Anderson-Lu/gofasion/gofasion" "github.com/gin-gonic/gin" "io/ioutil" "kpt.xdmy/apiserver/service" "kpt.xdmy/pkg/app" "kpt.xdmy/pkg/e" "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() eqClassPIdStr := fsion.Get("eqClassPIdStr").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, eqClassPIdStr) 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"}) } func GetEnsiling(c *gin.Context) { appG := app.Gin{C: c} pastureId := c.Query("pastureId") ensilingList, err := svc.GetEnsiling(pastureId) if err != nil { appG.Response(500, e.ERROR, err) return } appG.Response(200, e.SUCCESS, ensilingList) }