|
@@ -3,12 +3,15 @@ package cygx
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"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"
|
|
|
cygxService "hongze/hz_crm_api/services/cygx"
|
|
|
"hongze/hz_crm_api/services/elastic"
|
|
|
"hongze/hz_crm_api/utils"
|
|
|
+ "os"
|
|
|
+ "path/filepath"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -292,6 +295,7 @@ func (this *AskserieVideoController) HistoryList() {
|
|
|
// @Title 留言记录详情
|
|
|
// @Description 留言记录详情接口
|
|
|
// @Param AskserieVideoId query int true "ID"
|
|
|
+// @Param IsExport query bool false "是否导出excel,默认是false"
|
|
|
// @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
|
|
|
// @router /askserie_video/collection_list [get]
|
|
|
func (this *AskserieVideoController) CollectionList() {
|
|
@@ -313,6 +317,8 @@ func (this *AskserieVideoController) CollectionList() {
|
|
|
br.Msg = "请输入详情ID"
|
|
|
return
|
|
|
}
|
|
|
+ //是否导出报表
|
|
|
+ isExport, _ := this.GetBool("IsExport")
|
|
|
_, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
|
|
|
if err != nil {
|
|
|
br.Msg = "详情不存在"
|
|
@@ -330,12 +336,81 @@ func (this *AskserieVideoController) CollectionList() {
|
|
|
return
|
|
|
}
|
|
|
resp.List = list
|
|
|
+ //导出excel
|
|
|
+ if isExport {
|
|
|
+ CollectionListExport(this, resp, br)
|
|
|
+ return
|
|
|
+ }
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|
|
|
br.Data = resp
|
|
|
}
|
|
|
|
|
|
+// VoiceAndVideoCommentListExport 导出Excel
|
|
|
+func CollectionListExport(this *AskserieVideoController, resp *cygx.CygxAskserieVideoCollectionListResp, 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 = "导出成功"
|
|
|
+}
|
|
|
+
|
|
|
// @Title 发布/取消发布
|
|
|
// @Description 发布/取消发布接口
|
|
|
// @Param request body cygx.ProductInteriorIdReq true "type json string"
|