package api

import (
	"encoding/json"
	"fmt"
	"gadmin/config"
	"gadmin/internal/admin/forms"
	"gadmin/internal/admin/service"
	"gadmin/internal/gorm/query"
	"gadmin/package/gmdata"
	"gadmin/utility"
	"gadmin/utility/character"
	"gadmin/utility/player"
	"gadmin/utility/serializer"
	"github.com/gin-gonic/gin"
	"github.com/jinzhu/now"
	"github.com/spf13/cast"
	"sort"
	"sync"
	"time"
)

func DashboardAdvEcharts(ctx *gin.Context) {
	var params forms.QueryAdvEchartsReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}
	if params.EndDay == "" {
		params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
	}
	resp, err := service.Dash.QueryAdvEcharts(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}

func GetAllChaptersInfo(ctx *gin.Context) {
	data, _ := json.Marshal(gmdata.Chapters)
	ctx.JSON(200, gin.H{"code": 0, "data": string(data)})
}

func DashboadDict(ctx *gin.Context) {
	resp, err := service.Dash.QueryAllEventItems()
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, resp)
}

func Console(ctx *gin.Context) {
	type Models struct {
		TotalUser int64
		Today     int64
		Week      int64
		Moon      int64
	}
	t := time.Now()
	nt := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())

	var models Models

	for _, DB := range config.GDBGroup {
		var u = query.Use(DB).PlayerAttr
		totalUser, _ := u.Count()
		today, _ := u.Where(u.CreateTime.Gte(nt)).Count()
		week, _ := u.Where(u.CreateTime.Gte(nt.Add(-time.Second * 86400 * 7))).Count()
		moon, _ := u.Where(u.CreateTime.Gte(nt.Add(-time.Second * 86400 * 30))).Count()

		models.TotalUser += totalUser
		models.Today += today
		models.Week += week
		models.Moon += moon
	}

	ctx.JSON(200, serializer.Suc(models))
}

func DashboadLoginLog(ctx *gin.Context) {
	var params forms.LoginlogReq

	ctx.ShouldBind(&params)
	resp, err := service.Dash.QueryLoginLog(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data

	ctx.JSON(200, serializer.Suc(models))
}

func DashboadUserChaperLog(ctx *gin.Context) {
	var params forms.UserChapterLogReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	resp, err := service.Dash.QueryUserChapterLog(params.ServerId, params.Day, params.Days, params.ChapterId, params.Difficulty, params.ChannelId, params.Flag)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	if resp == nil {
		resp = make([]forms.UserChapterItem, 0)
	}

	var models forms.ListRes
	models.List = resp

	ctx.JSON(200, serializer.Suc(models))
}

//func DashboardDieLog(ctx *gin.Context) {
//	var params forms.DieDataReq
//	err := ctx.ShouldBindQuery(&params)
//	if err != nil {
//		ctx.JSON(http.StatusOK, ErrorResponse(err))
//		return
//	}
//
//	ctx.JSON(200, service.Dash.QueryUserDieLog(params))
//}

func DashboadConditionUsers(ctx *gin.Context) {
	var params forms.DieDataReq
	ctx.ShouldBind(&params)
	resp, err := service.Dash.QueryConditionUsers(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}

	var models forms.ListRes
	models.List = resp
	ctx.JSON(200, serializer.Suc(models))
}

// 今日基本数据 留存
func DashboardBasicInfo(ctx *gin.Context) {
	var params forms.DieDataReq
	ctx.ShouldBindQuery(&params)
	if params.ServerId <= 0 {
		ctx.JSON(200, gin.H{"code": 1, "msg": "请选择一个有效的服务器"})
		return
	}

	resp, err := service.Dash.QueryBasicInfo(params.ServerId, params.Day)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, forms.BasicRespData{
		Data: resp,
	})
}

// DashboardBasicRetention 基础留存率
func DashboardBasicRetention(ctx *gin.Context) {
	var params forms.QueryBasicRetentionReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}
	if params.EndDay == "" {
		params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
	}
	resp, err := service.Dash.QueryBasicRetention(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}

// 基本数据 爆表
func DashboardBasicReport(ctx *gin.Context) {
	var params forms.BasicReportReq
	ctx.ShouldBind(&params)

	resp, err := service.Dash.QueryBasicReport(ctx, params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}

	var models forms.ListRes
	models.List = resp.Data
	if resp.Total <= 0 {
		resp.Total = 1
	}
	models.Page = params.Page
	models.PerPage = params.PerPage
	models.PageCount = resp.Total / 10
	ctx.JSON(200, serializer.Suc(models))

}

// 基本数据 爆表
func DashboardEventReport(ctx *gin.Context) {
	var params forms.ConditionReportReq
	ctx.ShouldBind(&params)

	resp, err := service.Dash.QueryConditionReport(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data
	if resp.Total <= 0 {
		resp.Total = 1
	}
	models.Page = params.Page
	models.PerPage = params.PerPage
	models.PageCount = resp.Total / 10
	ctx.JSON(200, serializer.Suc(models))
}

// 广告位
func DashboardAdvReport(ctx *gin.Context) {
	var params forms.AdvReportReq
	ctx.ShouldBindQuery(&params)
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}

	params.PerPage = 1000

	resp, err := service.Dash.QueryAdvReport(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data
	models.Page = 100
	models.PerPage = 1
	models.PageCount = 1

	ctx.JSON(200, serializer.Suc(models))
}

func DashboardFirstAdv(ctx *gin.Context) {
	var params forms.FirstAdvReq
	ctx.ShouldBindQuery(&params)

	resp, err := service.Dash.QueryFirstAdv(ctx, params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data
	if resp.Total <= 0 {
		resp.Total = 1
	}
	models.Page = params.Page
	models.PerPage = params.PerPage
	models.PageCount = resp.Total / params.PerPage

	ctx.JSON(200, serializer.Suc(models))
}

func DashboardFirstAdvStat(ctx *gin.Context) {
	var params forms.FirstAdvReq
	ctx.ShouldBindQuery(&params)

	resp, err := service.Dash.QueryFirstAdvStat(ctx, params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}

	ctx.JSON(200, serializer.Suc(resp))
}

func DashboardAdvSumm(ctx *gin.Context) {
	var params forms.AdvSummReq
	ctx.ShouldBindQuery(&params)

	resp, err := service.Dash.QueryAdvSumm(ctx, params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data
	if resp.Total <= 0 {
		resp.Total = 1
	}
	models.Page = params.Page
	models.PerPage = params.PerPage
	models.PageCount = resp.Total / params.PerPage

	ctx.JSON(200, serializer.Suc(models))
}

func DashboardAdvDetails(ctx *gin.Context) {
	var params forms.AdvDetailsReq
	ctx.ShouldBindQuery(&params)
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}

	resp, err := service.Dash.QueryAdvDetailsReq(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data
	models.Page = 100
	models.PerPage = 100
	models.PageCount = 1
	ctx.JSON(200, serializer.Suc(models))
}

func DashboardAdvUserDetails(ctx *gin.Context) {
	var params forms.AdvUserDetailsReq
	ctx.ShouldBindQuery(&params)

	err := params.Check()
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
	}

	resp, err := service.Dash.QueryAdvUserDetails(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}

	var models forms.ListRes
	models.List = resp.Data
	models.Page = 100
	models.PerPage = 100
	models.PageCount = 1
	ctx.JSON(200, serializer.Suc(models))
}

// 商品展示位
func DashboardGoodsReport(ctx *gin.Context) {
	var params forms.GoodsReportReq
	ctx.ShouldBindQuery(&params)
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}

	resp, err := service.Dash.QueryGoodsReport(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data
	ctx.JSON(200, serializer.Suc(models))
}

// 商品展示位
func DashboardChapterPassLog(ctx *gin.Context) {
	var params forms.GoodsReportReq
	ctx.ShouldBindQuery(&params)
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}

	var models forms.ListRes
	resp, err := service.Dash.QueryChapterPassLog(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}

	models.List = resp
	ctx.JSON(200, serializer.Suc(models))
}

type ChapterItem struct {
	ID       int64 `json:"id"`
	Diff     int   `json:"diff"`
	Nums     int   `json:"nums"`
	PassNums int   `json:"passNums"`
}

var (
	GradeLock sync.RWMutex
	GradeMap  = make(map[string]forms.ListRes)
)

func GradeDistribution(ctx *gin.Context) {
	var params forms.GradeDistributionReq
	ctx.ShouldBindQuery(&params)

	if service.Channel.IsMasterChannel(params.ChannelId) {
		ctx.JSON(200, gin.H{"code": 1, "msg": "当前数据仅支持筛选全部渠道或指定子渠道！"})
		return
	}

	if params.ServerId <= 0 {
		ctx.JSON(200, gin.H{"code": 1, "msg": "请选择一个有效的服务器"})
		return
	}

	DB, err := player.GetDBByServerID(params.ServerId)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}

	marshal, err := json.Marshal(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err})
		return
	}

	key := character.Md5Content(marshal)
	if val, ok := GradeMap[key]; ok {
		ctx.JSON(200, serializer.Suc(val))
		return
	}

	GradeLock.RLock()
	defer GradeLock.RUnlock()

	lists := make([]map[string]interface{}, 0)

	var (
		q               = query.Use(config.GDBGroup[DB]).PlayerAttr
		count     int64 = 0
		levels          = []int32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
		intervals       = [][]int32{{11, 15}, {16, 20}, {21, 40}, {41, 60}, {61, 80}, {81, 90}, {91, 110}, {111, 130}, {131, 160}}
		models    forms.ListRes
	)

	day := now.MustParse(params.Day)
	endDay := now.MustParse(params.EndDay)

	wg := new(sync.WaitGroup)
	for _, v := range levels {
		wg.Add(1)
		go func(v int32, wg *sync.WaitGroup) {
			m := q.WithContext(ctx).Where(q.CreateTime.Between(day, endDay))
			if params.ChannelId != "" {
				tmpIds := service.PlayerChannel.PlayerIds(ctx, params.ChannelId)
				pIds := utility.SpiltInt64BySizeFromInt64(tmpIds, 5000)
				var tmpCount int64
				for _, ids := range pIds {
					count, _ = m.Where(q.Playerid.In(ids...), q.Level.Eq(v)).Count()
					tmpCount += count
				}
				lists = append(lists, map[string]interface{}{"level": cast.ToString(v) + "级", "sum": tmpCount, "index": v})
			} else {
				count, _ = m.Where(q.Level.Eq(v)).Count()
				lists = append(lists, map[string]interface{}{"level": cast.ToString(v) + "级", "sum": count, "index": v})
			}

			wg.Done()
		}(v, wg)
	}

	for _, v := range intervals {
		wg.Add(1)
		go func(v []int32, wg *sync.WaitGroup) {
			m := q.WithContext(ctx).Where(q.CreateTime.Between(day, endDay))

			if params.ChannelId != "" {
				tmpIds := service.PlayerChannel.PlayerIds(ctx, params.ChannelId)
				pIds := utility.SpiltInt64BySizeFromInt64(tmpIds, 5000)
				var tmpCount int64
				for _, ids := range pIds {
					count, _ = m.Where(q.Playerid.In(ids...), q.Level.Between(v[0], v[1])).Count()
					tmpCount += count
				}
				lists = append(lists, map[string]interface{}{"level": fmt.Sprintf("%d~%d级", v[0], v[1]), "sum": tmpCount, "index": v[0] + v[1]})
			} else {
				count, _ = m.Where(q.Level.Between(v[0], v[1])).Count()
				lists = append(lists, map[string]interface{}{"level": fmt.Sprintf("%d~%d级", v[0], v[1]), "sum": count, "index": v[0] + v[1]})
			}

			wg.Done()
		}(v, wg)
	}

	//wg.Add(1)
	//go func(wg *sync.WaitGroup) {
	//	m := q.WithContext(ctx).Where(q.CreateTime.Between(day, endDay))
	//
	//	if params.ChannelId != "" {
	//		tmpIds := service.PlayerChannel.PlayerIds(ctx, params.ChannelId)
	//		pIds := utility.SpiltInt64BySize(tmpIds, 10000)
	//		var tmpCount int64
	//		for _, ids := range pIds {
	//			count, _ = m.Where(q.Playerid.In(ids...), q.Level.Between(141, 1000)).Count()
	//			tmpCount += count
	//		}
	//		lists = append(lists, map[string]interface{}{"level": "140级以上", "sum": tmpCount, "index": 1000})
	//	} else {
	//		count, _ = m.Where(q.Level.Between(141, 1000)).Count()
	//		lists = append(lists, map[string]interface{}{"level": "140级以上", "sum": count, "index": 1000})
	//	}
	//
	//	wg.Done()
	//}(wg)

	wg.Wait()

	type lev struct {
		Level string `json:"level"`
		Sum   int32  `json:"sum"`
		Index int32  `json:"index"`
	}

	var lst []lev
	for _, v := range lists {
		lst = append(lst, lev{v["level"].(string), cast.ToInt32(v["sum"]), cast.ToInt32(v["index"])})
	}

	sort.Slice(lst, func(i, j int) bool {
		return lst[i].Index < lst[j].Index // 升序
	})

	models.List = lst

	GradeMap[key] = models
	ctx.JSON(200, serializer.Suc(models))
}

func DashboardGudongLog(ctx *gin.Context) {
	var params forms.GoodsReportReq
	ctx.ShouldBindQuery(&params)
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}

	resp, err := service.Dash.QueryGudongLog(params)
	// resp = []ChapterItem{{ID: 1, Diff: 0}}
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}

func DashboardUserRolesMap(ctx *gin.Context) {
	var params forms.GoodsReportReq
	ctx.ShouldBindQuery(&params)
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}

	if params.ServerId <= 0 {
		ctx.JSON(200, gin.H{"code": 1, "msg": "请选择一个有效的服务器"})
		return
	}

	resp, err := service.Dash.QueryUserRolesMap(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}

// DashboardExpeditionLog 远征报表
func DashboardExpeditionLog(ctx *gin.Context) {
	var params forms.ExpeditionReportReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}
	if params.EndDay == "" {
		params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
	}
	resp, err := service.Dash.QueryExpeditionLog(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}

// DashboardExpeditionFloor 远征关卡未通关信息
func DashboardExpeditionFloor(ctx *gin.Context) {
	var params forms.ExpeditionFloorReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}
	resp, err := service.Dash.QueryExpeditionFloor(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}

// DashboardDuelLog 远征报表
func DashboardDuelLog(ctx *gin.Context) {
	var params forms.DuelReportReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}
	if params.EndDay == "" {
		params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
	}
	resp, err := service.Dash.QueryDuelLog(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}

// DashboardIdiomLog 金榜题名报表
func DashboardIdiomLog(ctx *gin.Context) {
	var params forms.IdiomReportReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}
	if params.EndDay == "" {
		params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
	}
	resp, err := service.Dash.QueryIdiomLog(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}

// DashboardBossLog 暗影突袭报表
func DashboardBossLog(ctx *gin.Context) {
	var params forms.BossReportReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}

	if params.ServerId <= 0 {
		ctx.JSON(200, gin.H{"code": 1, "msg": "请选择一个有效的服务器"})
		return
	}

	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}
	if params.EndDay == "" {
		params.EndDay = utility.Format(time.Now().AddDate(0, 0, 0))
	}
	resp, err := service.Dash.QueryBossLog(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}

// HeroLevelDistribution 英雄等级分布
func HeroLevelDistribution(ctx *gin.Context) {
	var params forms.HeroLevelDistributedReq
	err := ctx.ShouldBindQuery(&params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	if params.Day == "" {
		params.Day = utility.Format(time.Now().AddDate(0, 0, -1))
	}

	if params.ServerId <= 0 {
		ctx.JSON(200, gin.H{"code": 1, "msg": "请选择一个有效的服务器"})
		return
	}

	resp, err := service.Dash.QueryRolesLog(params)
	ctx.JSON(200, gin.H{"data": resp, "code": 0})
}

// DashboardSevenBasic 七日任务基础信息
func DashboardSevenBasic(ctx *gin.Context) {
	var params forms.SevenBasicReq
	ctx.ShouldBindQuery(&params)
	resp, err := service.Dash.QuerySevenBasic(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data
	if resp.Total <= 0 {
		resp.Total = 1
	}
	models.Page = params.Page
	models.PerPage = params.PerPage
	models.PageCount = (resp.Total + params.PerPage - 1) / params.PerPage
	ctx.JSON(200, serializer.Suc(models))

}

// DashboardSevenTask 七日任务任务统计
func DashboardSevenTask(ctx *gin.Context) {
	var params forms.SevenTaskReq
	ctx.ShouldBindQuery(&params)
	resp, err := service.Dash.QuerySevenTask(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data
	if resp.Total <= 0 {
		resp.Total = 1
	}
	models.Page = params.Page
	models.PerPage = params.PerPage
	models.PageCount = resp.Total / 10
	ctx.JSON(200, serializer.Suc(models))
}

// DashboardSevenAward 七日任务奖励统计
func DashboardSevenAward(ctx *gin.Context) {
	var params forms.SevenAwardReq
	ctx.ShouldBindQuery(&params)
	resp, err := service.Dash.QuerySevenAward(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data
	if resp.Total <= 0 {
		resp.Total = 1
	}
	models.Page = params.Page
	models.PerPage = params.PerPage
	models.PageCount = resp.Total / 10
	ctx.JSON(200, serializer.Suc(models))
}

// DashboardDisconnectList 断线重连统计列表
func DashboardDisconnectList(ctx *gin.Context) {
	var params forms.DisconnectListReq
	ctx.ShouldBindQuery(&params)
	resp, err := service.Dash.QueryDisconnectList(params)
	if err != nil {
		ctx.JSON(200, gin.H{"code": 1, "msg": err.Error()})
		return
	}
	var models forms.ListRes
	models.List = resp.Data
	if resp.Total <= 0 {
		resp.Total = 1
	}
	models.Page = params.Page
	models.PerPage = params.PerPage
	models.PageCount = resp.Total / 10
	ctx.JSON(200, serializer.Suc(models))
}
