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 ApiWeChatScannerLedger struct {
}

func (s *ApiWeChatScannerLedger) GetWeChatScannerLedgerList(c *gin.Context) {
	var paramsInfo request.WeChatScannerLedgerRequest
	_ = c.ShouldBindJSON(&paramsInfo)
	/*if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}*/
	list, total, err := ServiceWeChatScannerLedger.WeChatScannerLedgerList(c, paramsInfo.WeChatScannerLedger, 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 (e *ApiWeChatScannerLedger) ExportLedgerListExcel(c *gin.Context) {
	var excelInfo request.ExcelLedgerInfo
	_ = c.ShouldBindJSON(&excelInfo)
	paramsInfo := excelInfo.InfoList
	paramsInfo.PageSize = 300
	paramsInfo.Page = 1
	list, _, err := ServiceWeChatScannerLedger.WeChatScannerLedgerList(c, paramsInfo.WeChatScannerLedger, 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 = ServiceWeChatScannerLedger.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)
}
