Browse Source

no message

zhangchuanxing 1 week ago
parent
commit
16a6e8745e
2 changed files with 98 additions and 35 deletions
  1. 97 34
      controllers/cygx/rai_serve.go
  2. 1 1
      models/cygx/rai_serve_company.go

+ 97 - 34
controllers/cygx/rai_serve.go

@@ -357,7 +357,7 @@ func (this *RaiServeCoAntroller) List() {
 	isExport, _ := this.GetBool("IsExport")
 	resp := new(cygx.CygxRaiServeCompanyListResp)
 	if isExport {
-		pageSize = 999
+		pageSize = 9999
 	}
 	var startSize int
 	if pageSize <= 0 {
@@ -441,11 +441,13 @@ func (this *RaiServeCoAntroller) List() {
 		companyIds = append(companyIds, v.CompanyId)
 	}
 
-	mapWeekAmount := make(map[string]float64) //周度服务量
+	mapWeekAmount := make(map[string]float64)  //周度服务量
+	mapMonthAmount := make(map[string]float64) //月度服务量
 	weeks := 4
 	months := 3
 	if isExport {
 		weeks = 12 // 下载获取近12周的数据
+		months = 6
 	}
 	lencompanyIds := len(companyIds)
 	if lencompanyIds > 0 {
@@ -476,7 +478,6 @@ func (this *RaiServeCoAntroller) List() {
 		}
 
 		now := time.Now()
-
 		for _, v := range listBill {
 			for i := 0; i < weeks; i++ {
 				// 计算当前周的周一
@@ -488,10 +489,10 @@ func (this *RaiServeCoAntroller) List() {
 			}
 			for i := 0; i < months; i++ {
 				// 计算当前月的第一天
-				monthday := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, i, 0)
+				monthday := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, -i, 0)
 				monthFirstDay := monthday.Format(utils.FormatDate)
 				if v.MonthStartDate == monthFirstDay {
-					mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", i)] += v.ServeCount
+					mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", i)] += v.ServeCount
 				}
 			}
 		}
@@ -535,7 +536,7 @@ func (this *RaiServeCoAntroller) List() {
 
 	//导出excel
 	if isExport {
-		RaiServeListExport(this, resp, mapWeekAmount, br)
+		RaiServeListExport(this, resp, mapWeekAmount, mapMonthAmount, br)
 		return
 	}
 	page := paging.GetPaging(currentIndex, pageSize, total)
@@ -547,10 +548,13 @@ func (this *RaiServeCoAntroller) List() {
 }
 
 // EnterScoreScoreListExport 导出Excel
-func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompanyListResp, mapWeekAmount map[string]float64, br *models.BaseResponse) {
+func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompanyListResp, mapWeekAmount map[string]float64, mapMonthAmount map[string]float64, br *models.BaseResponse) {
 	weeks := 12 // 下载获取近12周的数据
+	months := 6 // 下载获取近6个月的数据
 	mapWeekFormat := make(map[int]string)
+	mapMonthFormat := 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)
@@ -559,7 +563,11 @@ func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompan
 		weeksunday := sunday.Format(utils.FormatMonthDayUnSpace2)
 		mapWeekFormat[i] = weekmonday + "~" + weeksunday
 	}
-
+	for i := 0; i < months; i++ {
+		// 处理月份
+		monthday := now.AddDate(0, -i, 0)
+		mapMonthFormat[i] = fmt.Sprint(int(monthday.Month()), "月")
+	}
 	dir, err := os.Executable()
 	exPath := filepath.Dir(dir)
 	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
@@ -657,50 +665,102 @@ func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompan
 		cellWei.SetValue(mapWeekFormat[i])
 	}
 
+	cellMonth1 := titleRow.AddCell()
+	cellMonth1.SetStyle(style)
+	cellMonth1.SetValue("本月服务量")
+
+	cellMonthQoQ := titleRow.AddCell()
+	cellMonthQoQ.SetStyle(style)
+	cellMonthQoQ.SetValue("上月环比")
+
+	cellMonth2 := titleRow.AddCell()
+	cellMonth2.SetStyle(style)
+	cellMonth2.SetValue("上月服务量")
+
+	cellMonth3 := titleRow.AddCell()
+	cellMonth3.SetStyle(style)
+	cellMonth3.SetValue("上上月服务量")
+
+	for i := 0; i < months; i++ {
+		if i < 3 {
+			continue
+		}
+		// 计算当前周的周一
+		cellMonthi := titleRow.AddCell()
+		cellMonthi.SetStyle(style)
+		cellMonthi.SetValue(mapMonthFormat[i])
+	}
+
 	for _, v := range resp.List {
 		dataRow := sheel.AddRow()
 		dataRow.SetHeight(20)
 
-		cellA := dataRow.AddCell()
+		cellAData := dataRow.AddCell()
 		if v.IsUserMaker == -1 {
-			cellA.SetStyle(redStyle)
+			cellAData.SetStyle(redStyle)
 		} else {
-			cellA.SetStyle(style)
+			cellAData.SetStyle(style)
 		}
-		cellA.SetValue(v.CompanyName)
+		cellAData.SetValue(v.CompanyName)
 
 		cellWeekData := dataRow.AddCell()
 		cellWeekData.SetStyle(style)
 		cellWeekData.SetValue(v.ServeCoverageRate)
 
-		cellB := dataRow.AddCell()
-		cellB.SetStyle(style)
-		cellB.SetValue(v.Status)
+		cellBData := dataRow.AddCell()
+		cellBData.SetStyle(style)
+		cellBData.SetValue(v.Status)
 
-		cellC := dataRow.AddCell()
-		cellC.SetStyle(style)
-		cellC.SetValue(v.SellerName)
+		cellCData := dataRow.AddCell()
+		cellCData.SetStyle(style)
+		cellCData.SetValue(v.SellerName)
 
-		cellD := dataRow.AddCell()
-		cellD.SetStyle(style)
-		cellD.SetValue(v.ShareSeller)
+		cellDData := dataRow.AddCell()
+		cellDData.SetStyle(style)
+		cellDData.SetValue(v.ShareSeller)
 
-		cellE := dataRow.AddCell()
-		cellE.SetStyle(style)
-		cellE.SetValue(v.StartDate + "~" + v.EndDate)
+		cellEData := dataRow.AddCell()
+		cellEData.SetStyle(style)
+		cellEData.SetValue(v.StartDate + "~" + v.EndDate)
 
-		cellF := dataRow.AddCell()
-		cellF.SetStyle(style)
-		cellF.SetValue(v.Money)
+		cellFData := dataRow.AddCell()
+		cellFData.SetStyle(style)
+		cellFData.SetValue(v.Money)
 
-		cellG := dataRow.AddCell()
-		cellG.SetStyle(style)
-		cellG.SetValue(v.PermissionName)
+		cellGData := dataRow.AddCell()
+		cellGData.SetStyle(style)
+		cellGData.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)])
+			cellWeiData := dataRow.AddCell()
+			cellWeiData.SetStyle(style)
+			cellWeiData.SetValue(mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", i)])
+		}
+
+		cellMonth1Data := dataRow.AddCell()
+		cellMonth1Data.SetStyle(style)
+		cellMonth1Data.SetValue(mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 0)])
+
+		cellMonthQoQData := dataRow.AddCell()
+		var cellMonthQoQStr string
+		if mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]-mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)] == 0 || mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)] == 0 {
+			cellMonthQoQStr = "0%"
+		} else {
+			cellMonthQoQStr = fmt.Sprint(utils.SubFloatToString((mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]-mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)])/mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)]*100, 2)) + "%"
+			if (mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]-mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)])/mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)] <= 0.2 {
+				cellMonthQoQData.SetStyle(redStyle) //小于0.2做标红处理
+			} else {
+				cellMonthQoQData.SetStyle(style)
+			}
+		}
+		cellMonthQoQData.SetValue(cellMonthQoQStr)
+		for i := 0; i < months; i++ {
+			if i == 0 {
+				continue
+			}
+			cellMonthData := dataRow.AddCell()
+			cellMonthData.SetStyle(style)
+			cellMonthData.SetValue(mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", i)])
 		}
 
 	}
@@ -970,7 +1030,7 @@ func (this *RaiServeCoAntroller) BillList() {
 	if whatMonth > 0 {
 		now := time.Now()
 		// 计算所选月份的第一天
-		monthday := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, whatWeek, 0)
+		monthday := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, -whatMonth+1, 0)
 		condition += " AND  month_start_date = ? "
 		pars = append(pars, monthday.Format(utils.FormatDate))
 	}
@@ -1016,6 +1076,9 @@ func (this *RaiServeCoAntroller) BillList() {
 			case utils.CYGX_OBJ_RS_CALENDAR:
 				rsCalendarIds = append(rsCalendarIds, v.SourceId)
 			}
+			if v.ServeTypeName == "阅读uv" {
+				v.ServeTypeName = "报告阅读uv" //服务类型名称做一下,映射修改
+			}
 		}
 
 		maparticleIndustrialLabel := make(map[int][]string) //文章产业标签

+ 1 - 1
models/cygx/rai_serve_company.go

@@ -45,7 +45,7 @@ type CygxRaiServeCompanyResp struct {
 	ThisMonthAmount   float64 `comment:"本月互动量"`
 	LastMonthAmount   float64 `comment:"上月互动量"`
 	LastMonthQoq      string  `comment:"上月环比"`
-	LastMonthQoqIsRed bool    `comment:"上月环比"`
+	LastMonthQoqIsRed bool    `comment:"上月环比是否标红"`
 	TwoMonthAmount    float64 `comment:"上上月互动量"`
 }