package cygx

import (
	"encoding/json"
	"fmt"
	"github.com/rdlucklib/rdluck_tools/paging"
	"github.com/tealeg/xlsx"
	"hongze/hz_crm_api/controllers"
	"hongze/hz_crm_api/models"
	"hongze/hz_crm_api/models/cygx"
	"hongze/hz_crm_api/utils"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"time"
)

// 活动
type ActivityVideoCoAntroller struct {
	controllers.BaseAuthController
}

// @Title 活动列表
// @Description 获取活动列表接口
// @Param   PageSize   query   int  true       "每页数据条数"
// @Param   CurrentIndex   query   int  true       "当前页页码，从1开始"
// @Param   ChartPermissionId   query   string  false     "行业id"
// @Param   ActivityTypeId   query   string  false     "活动类型id"
// @Param   StartDate   query   string  false       "开始时间 ，列如2021-03-06 "
// @Param   EndDate   query   string  false       "结束时间，列如2021-03-06 "
// @Param   KeyWord   query   string  false       "搜索关键词"
// @Param   SortType          query   string    false		"排序顺序：asc、desc"
// @Success 200 {object} cygx.CygxActivityVideoListRep
// @router /activityVideo/list [get]
func (this *ActivityVideoCoAntroller) ActivityVideoList() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()

	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		return
	}
	pageSize, _ := this.GetInt("PageSize")
	currentIndex, _ := this.GetInt("CurrentIndex")
	chartPermissionId, _ := this.GetInt("ChartPermissionId")
	ActivityTypeId, _ := this.GetInt("ActivityTypeId")
	startDate := this.GetString("StartDate")
	endDate := this.GetString("EndDate")
	keyWord := this.GetString("KeyWord")
	sortType := this.GetString("SortType")

	var startSize int
	if pageSize <= 0 {
		pageSize = utils.PageSize20
	}
	if currentIndex <= 0 {
		currentIndex = 1
	}
	startSize = utils.StartIndex(currentIndex, pageSize)
	var condition string
	var pars []interface{}
	if keyWord != "" {
		condition += ` AND (v.video_name LIKE '%` + keyWord + `%' )  `
	}
	//行业名称
	if chartPermissionId > 0 {
		condition += ` AND art.chart_permission_id  = ?  `
		pars = append(pars, chartPermissionId)
	}

	if startDate != "" {
		condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
	}
	if endDate != "" {
		condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
	}
	if ActivityTypeId > 0 {
		condition += ` AND art.activity_type_id  = ?  `
		pars = append(pars, ActivityTypeId)
	}
	total, err := cygx.GetActivityVideoCount(condition, pars)
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取失败，Err:" + err.Error()
		return
	}

	if sortType == "asc" || sortType == "desc" {
		condition += ` ORDER BY v.video_counts   ` + sortType
	} else {
		condition += ` 	ORDER BY art.activity_time DESC  `
	}

	list, errList := cygx.GetActivityVideoListAll(condition, pars, startSize, pageSize)
	if errList != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取失败，Err:" + errList.Error()
		return
	}
	var activityIds string
	for k, v := range list {
		if v.ChartPermissionNames != "" {
			list[k].ChartPermissionName = v.ChartPermissionNames
		}
		activityIds += strconv.Itoa(v.ActivityId) + ","
	}
	activityIds = strings.TrimRight(activityIds, ",")
	mapIndustrial := make(map[int]string)
	mapSubject := make(map[string]string)
	if activityIds != "" {
		industrialList, err := cygx.GetIndustrialActivityGroupListByactivityIds(activityIds)
		if err != nil {
			br.Msg = "获取失败"
			br.ErrMsg = "获取失败，GetIndustrialActivityGroupListByactivityIds Err:" + err.Error()
			return
		}
		subjectList, err := cygx.GetSubjectActivityGroupListByactivityIds(activityIds)
		if err != nil {
			br.Msg = "获取失败"
			br.ErrMsg = "获取失败，GetSubjectActivityGroupListByactivityIds Err:" + err.Error()
			return
		}
		//合并活动对应的多个标的
		for _, v := range subjectList {
			mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)] += v.SubjectName + "/"
		}
		//活动对应的产业
		for _, v := range industrialList {
			var labelSubject string
			labelSubject = mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)]
			if labelSubject != "" {
				mapIndustrial[v.ActivityId] += v.IndustryName + "--" + strings.TrimRight(labelSubject, "/") + "，"
			} else {
				mapIndustrial[v.ActivityId] += v.IndustryName + "，"
			}
		}
	}
	for k, v := range list {
		if mapIndustrial[v.ActivityId] != "" && v.TemporaryLabel == "" {
			list[k].Label = strings.TrimRight(mapIndustrial[v.ActivityId], "，")
		}
	}
	if len(list) == 0 {
		list = make([]*cygx.CygxActivityVideoListResp, 0)
	}
	page := paging.GetPaging(currentIndex, pageSize, total)
	resp := new(cygx.CygxActivityVideoListRep)
	resp.List = list
	resp.Paging = page
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 音频播放详情
// @Description 音频播放详情接口
// @Param   VideoId   query   int  true       "视频Id"
// @Success Ret=200 发布成功
// @router /activityVideo/deatil [get]
func (this *ActivityVideoCoAntroller) VideoDeatil() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	videoId, _ := this.GetInt("VideoId")
	if videoId <= 0 {
		br.Msg = "参数错误"
		return
	}
	var condition string
	var pars []interface{}
	condition += `AND v.video_id= ? `
	pars = append(pars, videoId)
	list, err := cygx.GetActivityVideoHistoryById(condition, pars)
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取数据失败，Err:" + err.Error()
		return
	}

	for _, v := range list {
		v.RegisterPlatform = utils.CYGX_REGISTER_PLATFORM_MAP[v.RegisterPlatform]
	}
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = list
}

// @Title 留言详情excel表格下载
// @Description 留言详情excel表格下载接口
// @Param   VideoId   query   int  true       "视频ID"
// @Success 200 导出成功
// @router /activityVideo/commnetListExport [get]
func (this *ActivityVideoCoAntroller) CommentListExport() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		return
	}
	videoId, _ := this.GetInt("VideoId")
	videoInfo, _ := cygx.GetCygxActivityVideoReqDetailByVideoId(videoId)
	if videoInfo == nil {
		br.Msg = "操作失败"
		br.ErrMsg = "报告ID错误"
		return
	}

	var condition string
	var pars []interface{}
	condition += `  AND activity_id =  ? AND video_id = ?  `
	pars = append(pars, videoInfo.ActivityId, videoInfo.VideoId)
	list, err := cygx.GetArticleCommentListSearch(condition, pars)
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取失败，Err:" + err.Error()
		return
	}
	//创建excel
	dir, err := os.Executable()
	exPath := filepath.Dir(dir)
	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
	xlsxFile := xlsx.NewFile()
	if err != nil {
		br.Msg = "生成文件失败"
		br.ErrMsg = "生成文件失败"
		return
	}
	style := xlsx.NewStyle()
	alignment := xlsx.Alignment{
		Horizontal: "center",
		Vertical:   "center",
		WrapText:   true,
	}
	style.Alignment = alignment
	style.ApplyAlignment = true
	sheet, err := xlsxFile.AddSheet("名单")
	if err != nil {
		br.Msg = "新增Sheet失败"
		br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
		return
	}
	//标头
	rowTitle := sheet.AddRow()
	cellA := rowTitle.AddCell()
	cellA.Value = "姓名"
	cellB := rowTitle.AddCell()
	cellB.Value = "公司名称"
	cellC := rowTitle.AddCell()
	cellC.Value = "留言"
	cellD := rowTitle.AddCell()
	cellD.Value = "提交时间"

	for _, item := range list {
		row := sheet.AddRow()
		cellA := row.AddCell()
		cellA.Value = item.RealName
		cellB := row.AddCell()
		cellB.Value = item.CompanyName
		cellC := row.AddCell()
		cellC.Value = item.Content
		cellD := row.AddCell()
		cellD.Value = item.CreateTime
	}
	err = xlsxFile.Save(downLoadnFilePath)
	if err != nil {
		br.Msg = "保存文件失败"
		br.ErrMsg = "保存文件失败"
		return
	}
	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
	downloadFileName := "留言列表" + randStr + ".xlsx"
	this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
	defer func() {
		os.Remove(downLoadnFilePath)
	}()
	br.Success = true
	br.Ret = 200
	br.Msg = "导出成功"
}

// @Title 留言列表详情
// @Description 获取留言列表详情接口
// @Param    VideoId   query   int  true       "视频ID"
// @Success 200 {object} cygx.ArticleCommentListResp
// @router /activityVideo/commentList [get]
func (this *ActivityVideoCoAntroller) CommentList() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		return
	}
	videoId, _ := this.GetInt("VideoId")
	videoInfo, _ := cygx.GetCygxActivityVideoReqDetailByVideoId(videoId)
	if videoInfo == nil {
		br.Msg = "操作失败"
		br.ErrMsg = "报告ID错误"
		return
	}

	var condition string
	var pars []interface{}
	condition += `  AND activity_id =  ? AND video_id = ?  `
	pars = append(pars, videoInfo.ActivityId, videoInfo.VideoId)
	list, err := cygx.GetArticleCommentListSearch(condition, pars)
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取失败，Err:" + err.Error()
		return
	}
	//list, err := cygx.GetArticleCommentListByActivityVideoId(videoId)
	//if err != nil {
	//	br.Msg = "获取失败"
	//	br.ErrMsg = "获取失败，Err:" + err.Error()
	//	return
	//}
	resp := new(cygx.ArticleCommentListResp)
	resp.List = list
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 获取音视频上传之后的封面图
// @Description 获取音视频上传之后的封面图
// @Param   ActivityId   query   int  true       "活动ID"
// @Param   FileType   query   int  true       "音视频文件类型 。1：音频。2：视频"
// @Param   ChartPermissionId     query   int  true       "行业ID"
// @Success 200 {object} cygx.ChartPermissionRepMoreList
// @router /activityVideo/video_and_voice/img [get]
func (this *ActivityVideoCoAntroller) VideoAndVoice() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	AdminUser := this.SysUser
	if AdminUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，用户信息为空"
		br.Ret = 408
		return
	}
	conf, err := cygx.GetCygxConfigDetailByCode("activity_video_default_img")
	if err != nil {
		br.Msg = "获取微路演默认图配置失败" + err.Error()
		return
	}
	list := new(cygx.ActivityVideoDefaultImgList)
	if err = json.Unmarshal([]byte(conf.ConfigValue), &list); err != nil {
		br.Msg = "微路演默认图配置配置值解析失败" + err.Error()
		return
	}
	resp := new(cygx.ActivityVideoDefaultImgListResp)
	chartPermissionId, _ := this.GetInt("ChartPermissionId")
	activityId, _ := this.GetInt("ActivityId")
	fileType, _ := this.GetInt("FileType")

	if chartPermissionId > 0 {
		for _, v := range list.Audio {
			if v.ChartPermissionId == chartPermissionId {
				resp.List = v.List
			}
		}
	} else {
		if activityId < 1 {
			br.Msg = "请输入活动ID"
			return
		}
		activityInfo, err := cygx.GetAddActivityInfoById(activityId)
		if err != nil {
			br.Msg = "活动不存在"
			br.ErrMsg = "活动ID错误，Err:" + err.Error() + "activityId：" + strconv.Itoa(activityId)
			return
		}

		if activityInfo.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN { // 研选的音视频看全部行业
			if fileType == 1 {
				for _, v := range list.Audio {
					for _, vFile := range v.List {
						resp.List = append(resp.List, vFile)
					}
				}
			} else {
				for _, v := range list.Video {
					for _, vFile := range v.List {
						resp.List = append(resp.List, vFile)
					}
				}
			}
		} else {
			if fileType == 1 {
				for _, v := range list.Audio {
					if v.ChartPermissionId == activityInfo.ChartPermissionId {
						resp.List = v.List
					}
				}
			} else {
				for _, v := range list.Video {
					if v.ChartPermissionId == activityInfo.ChartPermissionId {
						resp.List = v.List
					}
				}
			}
		}
		//key := utils.MicroRoadshowDefaultImgKey
	}

	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 路演反馈、调研反馈列表
// @Description 路演反馈、调研反馈列表接口
// @Param   PageSize   query   int  true       "每页数据条数"
// @Param   CurrentIndex   query   int  true       "当前页页码，从1开始"
// @Param   ChartPermissionId   query   string  false     "行业id"
// @Param   ActivityTypeId   query   string  false     "活动类型id"
// @Param   StartDate   query   string  false       "开始时间 ，列如2021-03-06 "
// @Param   EndDate   query   string  false       "结束时间，列如2021-03-06 "
// @Param   KeyWord   query   string  false       "搜索关键词"
// @Param   SortType          query   string    false		"排序顺序：asc、desc"
// @Param   SearchType          query   int    false		"类型 1 路演回放 ，2：调研反馈"
// @Param   IsResearch   query   bool  true       "是否为研选"
// @Success 200 {object} cygx.CygxActivityVideoListRep
// @router /activity_voice_and_video/list [get]
func (this *ActivityVideoCoAntroller) ActivityVoiceAndVideoList() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()

	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		return
	}
	pageSize, _ := this.GetInt("PageSize")
	currentIndex, _ := this.GetInt("CurrentIndex")
	chartPermissionId, _ := this.GetInt("ChartPermissionId")
	ActivityTypeId, _ := this.GetInt("ActivityTypeId")
	searchType, _ := this.GetInt("SearchType", 1)
	startDate := this.GetString("StartDate")
	endDate := this.GetString("EndDate")
	keyWord := this.GetString("KeyWord")
	sortType := this.GetString("SortType")
	isResearch, _ := this.GetBool("IsResearch")

	var startSize int
	if pageSize <= 0 {
		pageSize = utils.PageSize20
	}
	if currentIndex <= 0 {
		currentIndex = 1
	}
	startSize = utils.StartIndex(currentIndex, pageSize)
	var condition string
	var conditionVideo string
	var conditionVoice string
	var pars []interface{}
	if keyWord != "" {
		conditionVideo += ` AND (v.video_name LIKE '%` + keyWord + `%' )  `
		conditionVoice += ` AND (v.voice_name LIKE '%` + keyWord + `%' )  `
	}

	if isResearch {
		chartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN //如果是研选添加一个研选行业的筛选
		searchType = 0
	} else {
		condition += ` AND art.chart_permission_id  != ?  `
		pars = append(pars, utils.CHART_PERMISSION_ID_YANXUAN)
	}
	//行业名称
	if chartPermissionId > 0 {
		condition += ` AND art.chart_permission_id  = ?  `
		pars = append(pars, chartPermissionId)
	}

	if startDate != "" {
		condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
	}
	if endDate != "" {
		condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
	}
	if ActivityTypeId > 0 {
		condition += ` AND art.activity_type_id  = ?  `
		pars = append(pars, ActivityTypeId)
	}
	//类型 1 路演反馈 ，2：调研反馈
	if searchType == 1 {
		condition += ` AND v.file_type = 1 `
	} else if searchType == 2 {
		condition += ` AND v.file_type = 2   `
	}

	var conditionOrder string
	if sortType == "asc" || sortType == "desc" {
		conditionOrder += ` ORDER BY video_counts   ` + sortType
	} else {
		conditionOrder += ` 	ORDER BY activity_time DESC  `
	}

	list, total, err := cygx.GetActivityVoiceAndVideoList(condition, conditionVoice, conditionVideo, conditionOrder, pars, startSize, pageSize)
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取失败，Err:" + err.Error()
		return
	}

	var activityIds string
	for k, v := range list {
		if v.ChartPermissionNames != "" {
			list[k].ChartPermissionName = v.ChartPermissionNames
		}
		activityIds += strconv.Itoa(v.ActivityId) + ","
	}
	activityIds = strings.TrimRight(activityIds, ",")
	mapIndustrial := make(map[int]string)
	mapSubject := make(map[string]string)
	if activityIds != "" {
		industrialList, err := cygx.GetIndustrialActivityGroupListByactivityIds(activityIds)
		if err != nil {
			br.Msg = "获取失败"
			br.ErrMsg = "获取失败，GetIndustrialActivityGroupListByactivityIds Err:" + err.Error()
			return
		}
		subjectList, err := cygx.GetSubjectActivityGroupListByactivityIds(activityIds)
		if err != nil {
			br.Msg = "获取失败"
			br.ErrMsg = "获取失败，GetSubjectActivityGroupListByactivityIds Err:" + err.Error()
			return
		}
		//合并活动对应的多个标的
		for _, v := range subjectList {
			mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)] += v.SubjectName + "/"
		}
		//活动对应的产业
		for _, v := range industrialList {
			var labelSubject string
			labelSubject = mapSubject[fmt.Sprint(v.ActivityId, "_", v.IndustrialManagementId)]
			if labelSubject != "" {
				mapIndustrial[v.ActivityId] += v.IndustryName + "--" + strings.TrimRight(labelSubject, "/") + "，"
			} else {
				mapIndustrial[v.ActivityId] += v.IndustryName + "，"
			}
		}

		//处理音视文件标识
		mapVoice := make(map[int]bool)
		//var conditionVoice string
		var parsVoice []interface{}
		conditionVoice = " AND activity_id IN (" + activityIds + ")  "
		listVoice, err := cygx.GetActivityVoiceList(conditionVoice, parsVoice)
		if err != nil && err.Error() != utils.ErrNoRow() {
			br.Msg = "获取失败"
			br.ErrMsg = "获取数据失败，Err:" + err.Error()
			return
		}
		if len(listVoice) > 0 {
			for _, v := range listVoice {
				mapVoice[v.ActivityId] = true
			}
		}
		for k, v := range list {
			if mapIndustrial[v.ActivityId] != "" && v.TemporaryLabel == "" {
				list[k].Label = strings.TrimRight(mapIndustrial[v.ActivityId], "，")
			}
			if mapVoice[v.ActivityId] {
				v.FileName = "音频"
			} else {
				v.FileName = "视频"
			}
		}
		if len(list) == 0 {
			list = make([]*cygx.CygxActivityVideoListResp, 0)
		}
	}

	page := paging.GetPaging(currentIndex, pageSize, total)
	resp := new(cygx.CygxActivityVideoListRep)
	resp.List = list
	resp.Paging = page
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// @Title 留言列表详情
// @Description 获取留言列表详情接口
// @Param   ActivityId   query   int  true     "活动ID"
// @Param   IsExport   query   bool  false       "是否导出excel，默认是false"
// @Success 200 {object} cygx.ArticleCommentListResp
// @router /activity_voice_and_video/commentList [get]
func (this *ActivityVideoCoAntroller) VoiceAndVideoCommentList() {
	br := new(models.BaseResponse).Init()
	defer func() {
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		return
	}
	activityId, _ := this.GetInt("ActivityId")
	//是否导出报表
	isExport, _ := this.GetBool("IsExport")
	var condition string
	var pars []interface{}

	videoInfo, _ := cygx.GetCygxActivityVideoReqDetail(activityId)
	if videoInfo != nil {
		condition += `  AND activity_id =  ? AND video_id = ?  `
		pars = append(pars, videoInfo.ActivityId, videoInfo.VideoId)
	} else {
		videoInfo, _ := cygx.GetMicroRoadshowVoiceById(activityId)
		if videoInfo == nil {
			br.Msg = "操作失败"
			br.ErrMsg = "音频ID错误"
			return
		}
		condition += `  AND activity_voice_id = ? `
		pars = append(pars, videoInfo.ActivityVoiceId)
	}
	list, err := cygx.GetArticleCommentListSearch(condition, pars)
	if err != nil {
		br.Msg = "获取失败"
		br.ErrMsg = "获取失败，Err:" + err.Error()
		return
	}

	resp := new(cygx.ArticleCommentListResp)
	resp.List = list
	//导出excel
	if isExport {
		VoiceAndVideoCommentListExport(this, resp, br)
		return
	}
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = resp
}

// VoiceAndVideoCommentListExport 导出Excel
func VoiceAndVideoCommentListExport(this *ActivityVideoCoAntroller, resp *cygx.ArticleCommentListResp, br *models.BaseResponse) {
	//创建excel
	dir, err := os.Executable()
	exPath := filepath.Dir(dir)
	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
	xlsxFile := xlsx.NewFile()
	if err != nil {
		br.Msg = "生成文件失败"
		br.ErrMsg = "生成文件失败"
		return
	}
	style := xlsx.NewStyle()
	alignment := xlsx.Alignment{
		Horizontal: "center",
		Vertical:   "center",
		WrapText:   true,
	}
	style.Alignment = alignment
	style.ApplyAlignment = true
	sheet, err := xlsxFile.AddSheet("阅读明细")
	if err != nil {
		br.Msg = "新增Sheet失败"
		br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
		return
	}
	//标头
	rowTitle := sheet.AddRow()
	cellA := rowTitle.AddCell()
	cellA.Value = "姓名"
	cellB := rowTitle.AddCell()
	cellB.Value = "公司名称"
	cellC := rowTitle.AddCell()
	cellC.Value = "留言"
	cellD := rowTitle.AddCell()
	cellD.Value = "提交时间"

	for _, item := range resp.List {
		row := sheet.AddRow()
		cellA := row.AddCell()
		cellA.Value = item.RealName
		cellB := row.AddCell()
		cellB.Value = item.CompanyName
		cellC := row.AddCell()
		cellC.Value = item.Content
		cellD := row.AddCell()
		cellD.Value = item.CreateTime
	}
	err = xlsxFile.Save(downLoadnFilePath)
	if err != nil {
		br.Msg = "保存文件失败"
		br.ErrMsg = "保存文件失败"
		return
	}
	downloadFileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
	this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
	defer func() {
		os.Remove(downLoadnFilePath)
	}()
	br.Ret = 200
	br.Success = true
	br.Msg = "导出成功"
}
