package dataStatistics

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"log-server/global"
	"log-server/model/dataStatistics/request"
	"log-server/model/log/response"
)

type ApiOldDataShow struct {
}

func (s *ApiOldDataShow) GetOldDataList(c *gin.Context) {
	var paramsInfo request.OldDataShowRequest
	_ = c.ShouldBindJSON(&paramsInfo)
	/*if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}*/
	list, total, err := ServiceOldDataShow.OldDataShowList(c, paramsInfo.OldDataShow2, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
	if err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     paramsInfo.Page,
			PageSize: paramsInfo.PageSize,
		}, "获取成功", c)
	}
}

func (s *ApiOldDataShow) ExportSyDataListExcel(c *gin.Context) {
	var excelInfo request.ExcelOldDataInfo
	_ = c.ShouldBindJSON(&excelInfo)
	paramsInfo := excelInfo.InfoList
	paramsInfo.PageSize = 1000
	paramsInfo.Page = 1
	list, _, err := ServiceOldDataShow.OldDataShowList(c, paramsInfo.OldDataShow2, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc)
	if err != nil {
		global.GVA_LOG.Error("获取数据失败!", zap.Error(err))
		response.FailWithMessage("获取数据失败", c)
		return
	}
	filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
	err = ServiceOldDataShow.ParseInfoList2Excel(list, filePath)
	if err != nil {
		global.GVA_LOG.Error("转换Excel失败!", zap.Error(err))
		response.FailWithMessage("转换Excel失败", c)
		return
	}
	c.Writer.Header().Add("success", "true")
	c.File(filePath)
}
