123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package controllers
- import (
- "rtzh_elec_temperature/rtelec_app_public_lib/service"
- "strings"
- "time"
- )
- //联动管理相关服务
- type LinkeventController struct {
- BaseController
- }
- //联动详情
- // @router /link_list [get]
- func (c *LinkeventController) LinkList() {
- source_address := c.GetString("source_address")
- targ_address := c.GetString("targe_address")
- deviceName := c.GetString("devicename")
- pageIndex, _ := c.GetInt("pageindex", 1)
- pageSize, _ := c.GetInt("pagesize", 20)
- starttime := c.GetString("starttime")
- var startDate, endDate = 0, 0
- if starttime != "" {
- starttime = strings.TrimLeft(starttime, " ")
- starttime = strings.TrimRight(starttime, " ")
- if strings.Index(starttime, " ") == -1 {
- starttime += " 00:00:00"
- }
- start_date, parseErr := time.ParseInLocation("2006-01-02 15:04:05", starttime, time.Local)
- if parseErr == nil {
- startDate = int(start_date.Unix())
- }
- }
- endtime := c.GetString("endtime")
- if endtime != "" {
- endtime = strings.TrimLeft(endtime, " ")
- endtime = strings.TrimRight(endtime, " ")
- if strings.Index(endtime, " ") == -1 {
- endtime += " 00:00:00"
- }
- end_date, parseErr := time.ParseInLocation("2006-01-02 15:04:05", endtime, time.Local)
- if parseErr == nil {
- endDate = int(end_date.Unix())
- }
- }
- obj := new(service.LinkEventService)
- list, err := obj.LinkDataList(startDate, endDate, source_address, targ_address, deviceName, pageIndex, pageSize)
- if err == nil {
- c.Data["json"] = c.ApiOK(list)
- } else {
- c.Data["json"] = c.ApiError(err.Error())
- }
- c.ServeJSON()
- }
- //联动详情
- // @router /now [get]
- func (c *LinkeventController) LinkNow() {
- pageIndex, _ := c.GetInt("pageindex", 1)
- pageSize, _ := c.GetInt("pagesize", 20)
- curDate := time.Now().Local().Format("2006-01-02") + " 00:00:00"
- formatTime, _ := time.ParseInLocation("2006-01-02 15:04:05", curDate, time.Local)
- var startDate = int(formatTime.Unix())
- list, err := new(service.LinkEventService).LinkDataList(startDate, 0, "", "", "", pageIndex, pageSize)
- if err == nil {
- c.Data["json"] = c.ApiOK(list)
- } else {
- c.Data["json"] = c.ApiError(err.Error())
- }
- c.ServeJSON()
- }
|