123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- package controllers
- import (
- "rtzh_elec_temperature/rtelec_app_public_lib/service"
- "strings"
- )
- //数据统计报表相关服务
- type StatReportController struct {
- BaseController
- }
- // 多测点对比数据查询 godoc
- // @Summary 多测点对比数据查询
- // @Description 多测点对比数据查询
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param mplist query string true "对比的测点列表。测点格式为:设备ID.测点属性名(如123.tem1)。多个测点之间使用逗号分隔。"
- // @Param startdate query int true "数据查询开始日期"
- // @Param enddate query int true "数据查询结束日期"
- // @Success 200 {object} ApiOK|ApiError 服务访问成功
- // @Failure 401 status 认证未通过,一般是未指定token或token已失效
- // @Failure 500 status 服务器|后台发生错误
- // @router /mutil_mp/comp [get]
- func (c *StatReportController) MutilMpCompData() {
- obj := new(service.StatReportService)
- mplist := c.GetString("mplist")
- if mplist == "" {
- c.Data["json"] = c.ApiError("对比的测点不能为空")
- c.ServeJSON()
- return
- }
- mps := map[string][]string{}
- tmpAry := strings.Split(mplist, ",")
- for _, v := range tmpAry {
- v1 := strings.Split(v, ".")
- if len(v1) != 2 {
- c.Data["json"] = c.ApiError("对比的测点格式不正确。参考:123.tem1")
- c.ServeJSON()
- return
- }
- if t1, h := mps[v1[0]]; h {
- t1 = append(t1, v1[1])
- mps[v1[0]] = t1
- } else {
- mps[v1[0]] = []string{v1[1]}
- }
- }
- //logger.Logger.Debug(fmt.Sprintf("对比分析的测点列表:%+v", mps))
- obj.UserInfo = c.GetCurrentUserInfo_rt()
- startdate := c.GetString("startdate")
- enddate := c.GetString("enddate")
- r, err := obj.MpComp(startdate, enddate, mps)
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- } else {
- c.Data["json"] = c.ApiOK(r)
- }
- c.ServeJSON()
- }
- // 多测点对比Echarts Line数据查询 godoc
- // @Summary 多测点对比Echarts Line数据查询。按Echarts Line要格式要求返回数据。
- // @Description 多测点对比Echarts Line数据查询按Echarts Line要格式要求返回数据。
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param mplist query string true "对比的测点列表。测点格式为:设备ID.测点属性名(如123.tem1)。多个测点之间使用逗号分隔。"
- // @Param startdate query int true "数据查询开始日期"
- // @Param enddate query int true "数据查询结束日期"
- // @Success 200 {object} ApiOK|ApiError 服务访问成功
- // @Failure 401 status 认证未通过,一般是未指定token或token已失效
- // @Failure 500 status 服务器|后台发生错误
- // @router /mutil_mp/echarts_data [get]
- func (c *StatReportController) MutilMpCompEchartsLineData() {
- obj := new(service.StatReportService)
- mplist := c.GetString("mplist")
- if mplist == "" {
- c.Data["json"] = c.ApiError("对比的测点不能为空")
- c.ServeJSON()
- return
- }
- mps := map[string][]string{}
- tmpAry := strings.Split(mplist, ",")
- for _, v := range tmpAry {
- v1 := strings.Split(v, ".")
- if len(v1) != 2 {
- c.Data["json"] = c.ApiError("对比的测点格式不正确。参考:123.tem1")
- c.ServeJSON()
- return
- }
- if t1, h := mps[v1[0]]; h {
- t1 = append(t1, v1[1])
- mps[v1[0]] = t1
- } else {
- mps[v1[0]] = []string{v1[1]}
- }
- }
- obj.UserInfo = c.GetCurrentUserInfo_rt()
- startdate := c.GetString("startdate")
- enddate := c.GetString("enddate")
- r, err := obj.MpCompEchartsLine(startdate, enddate, mps)
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- } else {
- c.Data["json"] = c.ApiOK(r)
- }
- c.ServeJSON()
- }
- // 获取报表数据 godoc
- // @Summary 获取报表数据
- // @Description 获取报表数据
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param deviceid query int true "设备ID"
- // @Param reportid query int true "查询条件:报表ID"
- // @Param reporttype query int true "查询条件:报表类型。支持以下:1 年报 2 月报 3 周报 4 日报"
- // @Success 200 {object} ApiOK|ApiError 服务访问成功
- // @Failure 401 status 认证未通过,一般是未指定token或token已失效
- // @Failure 500 status 服务器|后台发生错误
- // @router /data/list [get]
- func (c *StatReportController) GetReportData() {
- obj := new(service.StatReportService)
- deviceid, _ := c.GetInt32("deviceid")
- if deviceid == 0 {
- c.Data["json"] = c.ApiError("设备ID不能为空")
- c.ServeJSON()
- return
- }
- obj.UserInfo = c.GetCurrentUserInfo_rt()
- rtid, _ := c.GetInt64("reportid")
- typeid := c.GetString("reporttype")
- r, err := obj.DataQuery(deviceid, rtid, typeid)
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- } else {
- c.Data["json"] = c.ApiOK(r)
- }
- c.ServeJSON()
- }
- // 获取年报表列表 godoc
- // @Summary 获取年报表列表
- // @Description 获取年报表列表。不指定年份时,获取所有的年报表。
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param deviceid query int true "设备ID"
- // @Param year query int false "查询条件:年份"
- // @Success 200 {object} ApiOK|ApiError 服务访问成功
- // @Failure 401 status 认证未通过,一般是未指定token或token已失效
- // @Failure 500 status 服务器|后台发生错误
- // @router /year/list [get]
- func (c *StatReportController) GetYearReportList() {
- obj := new(service.StatReportService)
- deviceid, _ := c.GetInt32("deviceid")
- if deviceid == 0 {
- c.Data["json"] = c.ApiError("设备ID不能为空")
- c.ServeJSON()
- return
- }
- obj.UserInfo = c.GetCurrentUserInfo_rt()
- year := c.GetString("year")
- r, n, err := obj.QueryYearReportList(deviceid, year)
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- } else {
- c.Data["json"] = c.ApiOK(map[string]interface{}{"total": n, "list": r})
- }
- c.ServeJSON()
- }
- // 获取月报表列表 godoc
- // @Summary 获取月报表列表
- // @Description 获取月报表列表。不指定月份时,获取指定年内所有的月报表。
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param deviceid query int true "设备ID"
- // @Param year query int true "查询条件:年份"
- // @Param month query int false "查询条件:月份"
- // @Success 200 {object} ApiOK|ApiError 服务访问成功
- // @Failure 401 status 认证未通过,一般是未指定token或token已失效
- // @Failure 500 status 服务器|后台发生错误
- // @router /month/list [get]
- func (c *StatReportController) GetMonthReportList() {
- obj := new(service.StatReportService)
- deviceid, _ := c.GetInt32("deviceid")
- if deviceid == 0 {
- c.Data["json"] = c.ApiError("设备ID不能为空")
- c.ServeJSON()
- return
- }
- obj.UserInfo = c.GetCurrentUserInfo_rt()
- year := c.GetString("year")
- if year == "" {
- c.Data["json"] = c.ApiError("年份不能为空")
- c.ServeJSON()
- return
- }
- month := c.GetString("month")
- r, n, err := obj.QueryMonthReportList(deviceid, year, month)
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- } else {
- c.Data["json"] = c.ApiOK(map[string]interface{}{"total": n, "list": r})
- }
- c.ServeJSON()
- }
- // 获取周报表列表 godoc
- // @Summary 获取周报表列表
- // @Description 获取周报表列表。不指定周时,获取指定年内所有的周报表。
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param deviceid query int true "设备ID"
- // @Param year query int true "查询条件:年份"
- // @Param week query int false "查询条件:周"
- // @Param pageindex query int false "查询条件:当前页码。默认为1"
- // @Param pagesize query int false "查询条件:每页记录数。默认为20"
- // @Success 200 {object} ApiOK|ApiError 服务访问成功
- // @Failure 401 status 认证未通过,一般是未指定token或token已失效
- // @Failure 500 status 服务器|后台发生错误
- // @router /week/list [get]
- func (c *StatReportController) GetWeekReportList() {
- obj := new(service.StatReportService)
- deviceid, _ := c.GetInt32("deviceid")
- if deviceid == 0 {
- c.Data["json"] = c.ApiError("设备ID不能为空")
- c.ServeJSON()
- return
- }
- obj.UserInfo = c.GetCurrentUserInfo_rt()
- year := c.GetString("year")
- if year == "" {
- c.Data["json"] = c.ApiError("年份不能为空")
- c.ServeJSON()
- return
- }
- week := c.GetString("week")
- pagei, _ := c.GetInt("pageindex", 1)
- pagen, _ := c.GetInt("pagesize", 20)
- r, n, err := obj.QueryWeekReportList(deviceid, year, week, pagei, pagen)
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- } else {
- c.Data["json"] = c.ApiOK(map[string]interface{}{"total": n, "list": r})
- }
- c.ServeJSON()
- }
- // 获取日报表列表 godoc
- // @Summary 获取日报表列表
- // @Description 获取日报表列表。不指定月时,获取指定年内所有的日报表。
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param deviceid query int true "设备ID"
- // @Param year query int true "查询条件:年份"
- // @Param month query int false "查询条件:月份"
- // @Param pageindex query int false "查询条件:当前页码。默认为1"
- // @Param pagesize query int false "查询条件:每页记录数。默认为20"
- // @Success 200 {object} ApiOK|ApiError 服务访问成功
- // @Failure 401 status 认证未通过,一般是未指定token或token已失效
- // @Failure 500 status 服务器|后台发生错误
- // @router /day/list [get]
- func (c *StatReportController) GetDayReportList() {
- obj := new(service.StatReportService)
- deviceid, _ := c.GetInt32("deviceid")
- if deviceid == 0 {
- c.Data["json"] = c.ApiError("设备ID不能为空")
- c.ServeJSON()
- return
- }
- obj.UserInfo = c.GetCurrentUserInfo_rt()
- year := c.GetString("year")
- if year == "" {
- c.Data["json"] = c.ApiError("年份不能为空")
- c.ServeJSON()
- return
- }
- month := c.GetString("month")
- pagei, _ := c.GetInt("pageindex", 1)
- pagen, _ := c.GetInt("pagesize", 20)
- r, n, err := obj.QueryDayReportList(deviceid, year, month, pagei, pagen)
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- } else {
- c.Data["json"] = c.ApiOK(map[string]interface{}{"total": n, "list": r})
- }
- c.ServeJSON()
- }
- // 获取自定义周期内的日报表列表 godoc
- // @Summary 获取自定义周期内的日报表列表
- // @Description 获取自定义周期内的日报表列表。建议开始和结束日期范围不超过3个月!
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param deviceid query int true "设备ID"
- // @Param s1 query string true "查询条件:开始日期"
- // @Param s2 query string false "查询条件:结束日期"
- // @Param pageindex query int false "查询条件:当前页码。默认为1"
- // @Param pagesize query int false "查询条件:每页记录数。默认为20"
- // @Success 200 {object} ApiOK|ApiError 服务访问成功
- // @Failure 401 status 认证未通过,一般是未指定token或token已失效
- // @Failure 500 status 服务器|后台发生错误
- // @router /custmer/list [get]
- func (c *StatReportController) GetAnyDayReportList() {
- obj := new(service.StatReportService)
- deviceid, _ := c.GetInt32("deviceid")
- if deviceid == 0 {
- c.Data["json"] = c.ApiError("设备ID不能为空")
- c.ServeJSON()
- return
- }
- obj.UserInfo = c.GetCurrentUserInfo_rt()
- s1 := c.GetString("s1")
- s2 := c.GetString("s2")
- if s1 == "" || s2 == "" {
- c.Data["json"] = c.ApiError("查询的开始和结束日期不能为空")
- c.ServeJSON()
- return
- }
- pagei, _ := c.GetInt("pageindex", 1)
- pagen, _ := c.GetInt("pagesize", 20)
- r, n, err := obj.QueryDayReportListByAnyDate(deviceid, s1, s2, pagei, pagen)
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- } else {
- c.Data["json"] = c.ApiOK(map[string]interface{}{"total": n, "list": r})
- }
- c.ServeJSON()
- }
- // 获取最高数据(温度、湿度、电压等)统计信息
- // @Summary 获取最高数据(温度、湿度、电压等)统计信息
- // @Description 获取最高数据(温度、湿度、电压等)统计信息。包括:tem(温度、时间、设备名称)对象,hum(湿度、时间、设备名称)对象,vol(电压、时间、设备名称)对象.以上信息后台会通过主题/rtelec/runtime/today/maxdata进行发布。前端可订阅该主题。
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Success 200 {object} ApiOK|ApiError 服务访问成功
- // @Failure 401 status 认证未通过,一般是未指定token或token已失效
- // @Failure 500 status 服务器|后台发生错误
- // @router /maxdata [get]
- func (c *StatReportController) GetMaxDataInfo() {
- var hisotryObject = new(service.HistoryService)
- list, err := hisotryObject.GetMaxDataInfo()
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- } else {
- c.Data["json"] = c.ApiOK(list)
- }
- c.ServeJSON()
- }
- // 获取设备数量统计信息
- // @Summary 获取设备数量统计信息
- // @Description 获取设备数量统计信息。包括:总设备数、在线数、离线数、告警数。以上信息每分钟后台会通过主题/rtelec/runtime/device/total进行发布。前端可订阅该主题。
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Success 200 {object} ApiOK|ApiError 服务访问成功
- // @Failure 401 status 认证未通过,一般是未指定token或token已失效
- // @Failure 500 status 服务器|后台发生错误
- // @router /device/total [get]
- func (c *StatReportController) GetTotalDataInfo() {
- var obj = new(service.StatReportService)
- obj.UserInfo = c.GetCurrentUserInfo_rt()
- list, err := obj.DeviceTotalStat()
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- } else {
- c.Data["json"] = c.ApiOK(list)
- }
- c.ServeJSON()
- }
|