|
@@ -4,12 +4,15 @@ import (
|
|
|
"errors"
|
|
|
"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/models/roadshow"
|
|
|
cygxService "hongze/hz_crm_api/services/cygx"
|
|
|
"hongze/hz_crm_api/utils"
|
|
|
+ "os"
|
|
|
+ "path/filepath"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -76,13 +79,6 @@ func (this *RaiServeCoAntroller) SearchTag() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- //keyWordSlice := strings.Split(keyWord, ",")
|
|
|
- //var conditionindustrial string
|
|
|
- //var conditionsubject string
|
|
|
- //for _, v := range keyWordSlice {
|
|
|
- // conditionindustrial += ` OR i.industry_name LIKE '%` + v + `%' `
|
|
|
- // conditionsubject += ` OR s.subject_name LIKE '%` + v + `%' `
|
|
|
- //}
|
|
|
resp := new(cygx.RaiServeTagListResp)
|
|
|
list, err := cygx.GetRaiServeSearchTagRespList(keyWord)
|
|
|
if err != nil {
|
|
@@ -380,7 +376,10 @@ func (this *RaiServeCoAntroller) List() {
|
|
|
}
|
|
|
|
|
|
mapWeekAmount := make(map[string]float64) //周度服务量
|
|
|
-
|
|
|
+ weeks := 4
|
|
|
+ if isExport {
|
|
|
+ weeks = 12 // 下载获取近12周的数据
|
|
|
+ }
|
|
|
lencompanyIds := len(companyIds)
|
|
|
if lencompanyIds > 0 {
|
|
|
var conditionBill string
|
|
@@ -409,7 +408,7 @@ func (this *RaiServeCoAntroller) List() {
|
|
|
}
|
|
|
|
|
|
now := time.Now()
|
|
|
- weeks := 4
|
|
|
+
|
|
|
for _, v := range listBill {
|
|
|
for i := 0; i < weeks; i++ {
|
|
|
// 计算当前周的周一
|
|
@@ -422,10 +421,6 @@ func (this *RaiServeCoAntroller) List() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if isExport {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
for _, v := range listRaiServeCompany {
|
|
|
item := new(cygx.CygxRaiServeCompanyResp)
|
|
|
item.CompanyId = v.CompanyId
|
|
@@ -448,8 +443,12 @@ func (this *RaiServeCoAntroller) List() {
|
|
|
resp.List = append(resp.List, item)
|
|
|
}
|
|
|
|
|
|
+ //导出excel
|
|
|
+ if isExport {
|
|
|
+ RaiServeListExport(this, resp, mapWeekAmount, br)
|
|
|
+ return
|
|
|
+ }
|
|
|
page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
-
|
|
|
resp.Paging = page
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
@@ -457,6 +456,162 @@ func (this *RaiServeCoAntroller) List() {
|
|
|
br.Data = resp
|
|
|
}
|
|
|
|
|
|
+// EnterScoreScoreListExport 导出Excel
|
|
|
+func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompanyListResp, mapWeekAmount map[string]float64, br *models.BaseResponse) {
|
|
|
+ weeks := 12 // 下载获取近12周的数据
|
|
|
+ mapWeekFormat := make(map[int]string)
|
|
|
+ now := time.Now()
|
|
|
+ for i := 0; i < weeks; i++ {
|
|
|
+ // 计算当前周的周一
|
|
|
+ monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
|
|
|
+ sunday := monday.AddDate(0, 0, 6)
|
|
|
+ weekmonday := monday.Format(utils.FormatMonthDayUnSpace2)
|
|
|
+ weeksunday := sunday.Format(utils.FormatMonthDayUnSpace2)
|
|
|
+ mapWeekFormat[i] = weekmonday + "~" + weeksunday
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|
|
|
+
|
|
|
+ sheel, err := xlsxFile.AddSheet("权益服务统计")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "新增Sheet失败"
|
|
|
+ br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sheel.SetColWidth(0, 0, 30)
|
|
|
+ sheel.SetColWidth(1, 1, 15)
|
|
|
+ sheel.SetColWidth(2, 2, 15)
|
|
|
+ sheel.SetColWidth(3, 3, 18)
|
|
|
+
|
|
|
+ titleRow := sheel.AddRow()
|
|
|
+
|
|
|
+ cellA := titleRow.AddCell()
|
|
|
+ cellA.SetStyle(style)
|
|
|
+ cellA.SetValue("客户名称")
|
|
|
+
|
|
|
+ cellB := titleRow.AddCell()
|
|
|
+ cellB.SetStyle(style)
|
|
|
+ cellB.SetValue("当前状态")
|
|
|
+
|
|
|
+ cellC := titleRow.AddCell()
|
|
|
+ cellC.SetStyle(style)
|
|
|
+ cellC.SetValue("所属销售")
|
|
|
+
|
|
|
+ cellD := titleRow.AddCell()
|
|
|
+ cellD.SetStyle(style)
|
|
|
+ cellD.SetValue("咨询销售")
|
|
|
+
|
|
|
+ cellE := titleRow.AddCell()
|
|
|
+ cellE.SetStyle(style)
|
|
|
+ cellE.SetValue("合同期限")
|
|
|
+
|
|
|
+ cellF := titleRow.AddCell()
|
|
|
+ cellF.SetStyle(style)
|
|
|
+ cellF.SetValue("合同金额")
|
|
|
+
|
|
|
+ cellG := titleRow.AddCell()
|
|
|
+ cellG.SetStyle(style)
|
|
|
+ cellG.SetValue("签约套餐")
|
|
|
+
|
|
|
+ cellWe1 := titleRow.AddCell()
|
|
|
+ cellWe1.SetStyle(style)
|
|
|
+ cellWe1.SetValue("本周服务量(" + mapWeekFormat[0] + ")")
|
|
|
+
|
|
|
+ cellWe2 := titleRow.AddCell()
|
|
|
+ cellWe2.SetStyle(style)
|
|
|
+ cellWe2.SetValue("上周服务量(" + mapWeekFormat[1] + ")")
|
|
|
+
|
|
|
+ cellWe3 := titleRow.AddCell()
|
|
|
+ cellWe3.SetStyle(style)
|
|
|
+ cellWe3.SetValue("上上周服务量(" + mapWeekFormat[2] + ")")
|
|
|
+
|
|
|
+ cellWe4 := titleRow.AddCell()
|
|
|
+ cellWe4.SetStyle(style)
|
|
|
+ cellWe4.SetValue("上三周服务量(" + mapWeekFormat[3] + ")")
|
|
|
+
|
|
|
+ for i := 0; i < weeks; i++ {
|
|
|
+ if i < 4 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 计算当前周的周一
|
|
|
+ cellWei := titleRow.AddCell()
|
|
|
+ cellWei.SetStyle(style)
|
|
|
+ cellWei.SetValue(mapWeekFormat[i])
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range resp.List {
|
|
|
+ dataRow := sheel.AddRow()
|
|
|
+ dataRow.SetHeight(20)
|
|
|
+
|
|
|
+ cellA := dataRow.AddCell()
|
|
|
+ cellA.SetStyle(style)
|
|
|
+ cellA.SetValue(v.CompanyName)
|
|
|
+
|
|
|
+ cellB := dataRow.AddCell()
|
|
|
+ cellB.SetStyle(style)
|
|
|
+ cellB.SetValue(v.Status)
|
|
|
+
|
|
|
+ cellC := dataRow.AddCell()
|
|
|
+ cellC.SetStyle(style)
|
|
|
+ cellC.SetValue(v.SellerName)
|
|
|
+
|
|
|
+ cellD := dataRow.AddCell()
|
|
|
+ cellD.SetStyle(style)
|
|
|
+ cellD.SetValue(v.ShareSeller)
|
|
|
+
|
|
|
+ cellE := dataRow.AddCell()
|
|
|
+ cellE.SetStyle(style)
|
|
|
+ cellE.SetValue(v.StartDate + "~" + v.EndDate)
|
|
|
+
|
|
|
+ cellF := dataRow.AddCell()
|
|
|
+ cellF.SetStyle(style)
|
|
|
+ cellF.SetValue(v.Money)
|
|
|
+
|
|
|
+ cellG := dataRow.AddCell()
|
|
|
+ cellG.SetStyle(style)
|
|
|
+ cellG.SetValue(v.PermissionName)
|
|
|
+
|
|
|
+ for i := 0; i < weeks; i++ {
|
|
|
+ cellWei := dataRow.AddCell()
|
|
|
+ cellWei.SetStyle(style)
|
|
|
+ cellWei.SetValue(mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", i)])
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ 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.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "导出成功"
|
|
|
+}
|
|
|
+
|
|
|
// 标签搜索语句筛选
|
|
|
func getServeBillTag(tagType, tagId int) (conditionBill string, parsBill []interface{}, err error) {
|
|
|
var activityIds []int
|
|
@@ -602,7 +757,6 @@ func (this *RaiServeCoAntroller) CoverageRate() {
|
|
|
for k, v := range listWeekBill {
|
|
|
mapWeek[k] = v.CoverageRate
|
|
|
}
|
|
|
-
|
|
|
resp := new(cygx.RaiServeCoverageRateResp)
|
|
|
resp.ThisWeekAmount = mapWeek[0] + "%"
|
|
|
resp.LastWeekAmount = mapWeek[1] + "%"
|
|
@@ -742,12 +896,15 @@ func (this *RaiServeCoAntroller) BillList() {
|
|
|
for _, v := range list {
|
|
|
switch v.Source {
|
|
|
case utils.CYGX_OBJ_ARTICLE:
|
|
|
- v.Tag = strings.Join(maparticleIndustrialLabel[v.SourceId], ",")
|
|
|
- if len(maparticleSubjectLabel[v.SourceId]) > 0 {
|
|
|
- v.Tag += "," + strings.Join(maparticleSubjectLabel[v.SourceId], ",")
|
|
|
+ if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
|
|
|
+ v.Tag = v.ChartPermissionName
|
|
|
+ } else {
|
|
|
+ v.Tag = strings.Join(maparticleIndustrialLabel[v.SourceId], ",")
|
|
|
+ if len(maparticleSubjectLabel[v.SourceId]) > 0 {
|
|
|
+ v.Tag += "," + strings.Join(maparticleSubjectLabel[v.SourceId], ",")
|
|
|
+ }
|
|
|
}
|
|
|
case utils.CYGX_OBJ_ACTIVITY:
|
|
|
-
|
|
|
v.Tag = strings.Join(mapActivityIndustrialLabel[v.SourceId], ",")
|
|
|
if len(mapActivitySubjectLabel[v.SourceId]) > 0 {
|
|
|
v.Tag += "," + strings.Join(mapActivitySubjectLabel[v.SourceId], ",")
|
|
@@ -758,7 +915,11 @@ func (this *RaiServeCoAntroller) BillList() {
|
|
|
v.Tag += "," + strings.Join(mapActivitySpeicalSubjectLabel[v.SourceId], ",")
|
|
|
}
|
|
|
case utils.CYGX_OBJ_RS_CALENDAR:
|
|
|
- v.Tag = strings.Join(mapRsCalendarLabel[v.SourceId], ",")
|
|
|
+ if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
|
|
|
+ v.Tag = v.ChartPermissionName
|
|
|
+ } else {
|
|
|
+ v.Tag = strings.Join(mapRsCalendarLabel[v.SourceId], ",")
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
resp.List = list
|