zhangchuanxing 3 ماه پیش
والد
کامیت
0aa932224b
2فایلهای تغییر یافته به همراه403 افزوده شده و 1 حذف شده
  1. 387 1
      controllers/cygx/report_article.go
  2. 16 0
      models/cygx/summary_manage.go

+ 387 - 1
controllers/cygx/report_article.go

@@ -4323,7 +4323,7 @@ func initQuanyi() {
 }
 
 func init() {
-	initQuanyiXiaoShou()
+	initart121_1()
 }
 
 func initBeizhu() {
@@ -4862,3 +4862,389 @@ func initQuanyiXiaoShou() {
 	fmt.Println("end")
 
 }
+
+func initart121() {
+	//行业
+	var condition string
+	var pars []interface{}
+	condition += ` AND re.chart_permission_id  = 22   AND art.publish_date > '2024-12-20' AND art.publish_date < '2025-01-21'  `
+	//报告匹配类型
+	//9.5 13:52
+	condition += `	GROUP BY art.article_id  ORDER BY art.publish_date DESC `
+	listart, err := cygx.GetReportArticleList(condition, pars, 0, 2000, 1)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	fmt.Println("listart", len(listart))
+	//创建excel
+	dir, err := os.Executable()
+	exPath := filepath.Dir(dir)
+	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	xlsxFile := xlsx.NewFile()
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	style := xlsx.NewStyle()
+	alignment := xlsx.Alignment{
+		Horizontal: "center",
+		Vertical:   "center",
+		WrapText:   true,
+	}
+	style.Alignment = alignment
+	style.ApplyAlignment = true
+
+	redStyle := xlsx.NewStyle()
+	redStyle.Alignment = alignment
+	redStyle.ApplyAlignment = true
+	redStyle.Font.Color = "ff0000"
+	//定义底色需要标黄的 单元格颜色
+	redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
+	redStyle.Fill = redFill
+	//redStyle.Border = *border
+
+	var sheetName string
+	sheetName = "PV"
+	sheet, err := xlsxFile.AddSheet(sheetName)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	//标头
+	rowTitle := sheet.AddRow()
+	cellAt := rowTitle.AddCell()
+	cellAt.Value = "标题"
+
+	cellXl := rowTitle.AddCell()
+	cellXl.Value = "系列"
+
+	cellPd := rowTitle.AddCell()
+	cellPd.Value = "发布时间"
+	cellA := rowTitle.AddCell()
+	cellA.Value = "姓名"
+	cellB := rowTitle.AddCell()
+	cellB.Value = "手机号"
+	cellC := rowTitle.AddCell()
+	cellC.Value = "公司名称"
+	cellD := rowTitle.AddCell()
+	cellD.Value = "分类"
+
+	cellDCreatedTime := rowTitle.AddCell()
+	cellDCreatedTime.Value = "阅读时间"
+
+	cellE := rowTitle.AddCell()
+	cellE.Value = "停留时长"
+
+	cellF := rowTitle.AddCell()
+	cellF.Value = "阅读来源"
+
+	for k, v := range listart {
+		fmt.Println("kkkk", k)
+		articleId := v.ArticleId
+		condition = ` AND h.mobile!= '' AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) // 过滤弘则
+		listPv, err := cygx.GetArticleHistoryList121(articleId, condition)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+
+		//var listDate []*cygx.ArticleHistoryRep
+
+		var mobileArr []string
+		var companyIds []int
+		companyIdsMap := make(map[int]bool)
+		mapMobileUser := make(map[string]string)
+		for _, vuser := range listPv {
+			mobileArr = append(mobileArr, vuser.Mobile)
+			if companyIdsMap[vuser.CompanyId] {
+				continue
+			}
+			companyIds = append(companyIds, vuser.CompanyId)
+			companyIdsMap[vuser.CompanyId] = true
+		}
+
+		listUser, err := models.GetWxUserListByUserMobileHaveCompany(mobileArr)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		for _, vu := range listUser {
+			mapMobileUser[vu.Mobile] = vu.RealName
+		}
+
+		//合并合同所对应的权限
+		listCompany, err := company.GetCompanyProductsByCompanyIdsAndProductIdinit(companyIds)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		mapIndustryName := make(map[int]string)
+		for _, vC := range listCompany {
+			mapIndustryName[vC.CompanyId] = vC.IndustryName
+		}
+
+		//rowtitle := sheet.AddRow()
+		//cellADatatitle := rowtitle.AddCell()
+		//cellADatatitle.Value = v.Title
+
+		for _, item := range listPv {
+			//if  mapIndustryName[item.CompanyId] ==""{
+			//	continue
+			//}
+			row := sheet.AddRow()
+
+			cellADatatitle := row.AddCell()
+			cellADatatitle.Value = v.Title
+
+			cellXlData := row.AddCell()
+			cellXlData.Value = v.SubCategoryName
+
+			cellADataPd := row.AddCell()
+			cellADataPd.Value = v.PublishDate
+
+			cellAData := row.AddCell()
+			if item.RealName == "" {
+				cellAData.Value = mapMobileUser[item.Mobile]
+			} else {
+				cellAData.Value = item.RealName
+			}
+
+			cellBData := row.AddCell()
+			cellBData.Value = item.Mobile
+
+			cellCData := row.AddCell()
+			cellCData.Value = item.CompanyName
+
+			cellDData := row.AddCell()
+			cellDData.Value = mapIndustryName[item.CompanyId]
+
+			cellEData := row.AddCell()
+			cellEData.Value = item.CreateTime
+
+			cellFData := row.AddCell()
+			cellFData.Value = item.StopTime
+
+			//fmt.Println(item.Source)
+			cellLyData := row.AddCell()
+
+			switch item.Source {
+			case "MOBILE":
+				cellLyData.Value = "小程序"
+			case "WEB":
+				cellLyData.Value = "网页版"
+			case "CELUE":
+				cellLyData.Value = "vmp"
+			case "PC":
+				cellLyData.Value = "小程序"
+			}
+
+		}
+
+		err = xlsxFile.Save(downLoadnFilePath)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+	}
+}
+
+func initart121_1() {
+	//行业
+	var condition string
+	var pars []interface{}
+	condition += ` AND re.chart_permission_id  = 22   AND art.publish_date > '2023-01-01' AND art.publish_date < '2025-01-01'  `
+	//报告匹配类型
+	//9.5 13:52
+	condition += `	GROUP BY art.article_id  ORDER BY art.publish_date DESC `
+	listart, err := cygx.GetReportArticleList(condition, pars, 0, 2000, 1)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	fmt.Println("listart", len(listart))
+	//创建excel
+	dir, err := os.Executable()
+	exPath := filepath.Dir(dir)
+	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	xlsxFile := xlsx.NewFile()
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	style := xlsx.NewStyle()
+	alignment := xlsx.Alignment{
+		Horizontal: "center",
+		Vertical:   "center",
+		WrapText:   true,
+	}
+	style.Alignment = alignment
+	style.ApplyAlignment = true
+
+	redStyle := xlsx.NewStyle()
+	redStyle.Alignment = alignment
+	redStyle.ApplyAlignment = true
+	redStyle.Font.Color = "ff0000"
+	//定义底色需要标黄的 单元格颜色
+	redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
+	redStyle.Fill = redFill
+	//redStyle.Border = *border
+
+	var sheetName string
+	sheetName = "PV"
+	sheet, err := xlsxFile.AddSheet(sheetName)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	//标头
+	rowTitle := sheet.AddRow()
+	cellAt := rowTitle.AddCell()
+	cellAt.Value = "标题"
+
+	cellXl := rowTitle.AddCell()
+	cellXl.Value = "系列"
+
+	cellPd := rowTitle.AddCell()
+	cellPd.Value = "发布时间"
+	cellA := rowTitle.AddCell()
+	cellA.Value = "姓名"
+	cellB := rowTitle.AddCell()
+	cellB.Value = "手机号"
+	cellC := rowTitle.AddCell()
+	cellC.Value = "公司名称"
+	cellD := rowTitle.AddCell()
+	cellD.Value = "分类"
+
+	cellDCreatedTime := rowTitle.AddCell()
+	cellDCreatedTime.Value = "阅读时间"
+
+	cellE := rowTitle.AddCell()
+	cellE.Value = "停留时长"
+
+	cellF := rowTitle.AddCell()
+	cellF.Value = "阅读来源"
+
+	for k, v := range listart {
+		fmt.Println("kkkk", k)
+		articleId := v.ArticleId
+		condition = ` AND h.mobile!= '' AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) // 过滤弘则
+		listPv, err := cygx.GetArticleHistoryList121(articleId, condition)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+
+		mapStopTime := make(map[string]int)
+
+		for _, vP := range listPv {
+			StopTime, _ := strconv.Atoi(vP.StopTime)
+			mapStopTime[vP.Mobile] += StopTime
+		}
+		haveMobile := make(map[string]bool)
+		//var listDate []*cygx.ArticleHistoryRep
+
+		var mobileArr []string
+		var companyIds []int
+		companyIdsMap := make(map[int]bool)
+		mapMobileUser := make(map[string]string)
+		for _, vuser := range listPv {
+			mobileArr = append(mobileArr, vuser.Mobile)
+			if companyIdsMap[vuser.CompanyId] {
+				continue
+			}
+			companyIds = append(companyIds, vuser.CompanyId)
+			companyIdsMap[vuser.CompanyId] = true
+		}
+
+		listUser, err := models.GetWxUserListByUserMobileHaveCompany(mobileArr)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		for _, vu := range listUser {
+			mapMobileUser[vu.Mobile] = vu.RealName
+		}
+
+		//合并合同所对应的权限
+		listCompany, err := company.GetCompanyProductsByCompanyIdsAndProductIdinit(companyIds)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		mapIndustryName := make(map[int]string)
+		for _, vC := range listCompany {
+			mapIndustryName[vC.CompanyId] = vC.IndustryName
+		}
+
+		//rowtitle := sheet.AddRow()
+		//cellADatatitle := rowtitle.AddCell()
+		//cellADatatitle.Value = v.Title
+
+		for _, item := range listPv {
+			//if  mapIndustryName[item.CompanyId] ==""{
+			//	continue
+			//}
+
+			if haveMobile[item.Mobile] {
+				continue
+			}
+			haveMobile[item.Mobile] = true
+			row := sheet.AddRow()
+
+			cellADatatitle := row.AddCell()
+			cellADatatitle.Value = v.Title
+
+			cellXlData := row.AddCell()
+			cellXlData.Value = v.SubCategoryName
+
+			cellADataPd := row.AddCell()
+			cellADataPd.Value = v.PublishDate
+
+			cellAData := row.AddCell()
+			if item.RealName == "" {
+				cellAData.Value = mapMobileUser[item.Mobile]
+			} else {
+				cellAData.Value = item.RealName
+			}
+
+			cellBData := row.AddCell()
+			cellBData.Value = item.Mobile
+
+			cellCData := row.AddCell()
+			cellCData.Value = item.CompanyName
+
+			cellDData := row.AddCell()
+			cellDData.Value = mapIndustryName[item.CompanyId]
+
+			cellEData := row.AddCell()
+			cellEData.Value = item.CreateTime
+
+			cellFData := row.AddCell()
+			cellFData.Value = strconv.Itoa(mapStopTime[item.Mobile])
+
+			//fmt.Println(item.Source)
+			cellLyData := row.AddCell()
+
+			switch item.Source {
+			case "MOBILE":
+				cellLyData.Value = "小程序"
+			case "WEB":
+				cellLyData.Value = "网页版"
+			case "CELUE":
+				cellLyData.Value = "vmp"
+			case "PC":
+				cellLyData.Value = "小程序"
+			}
+
+		}
+
+		err = xlsxFile.Save(downLoadnFilePath)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+	}
+}

+ 16 - 0
models/cygx/summary_manage.go

@@ -566,6 +566,22 @@ func GetArticleHistoryList(articleId int, condition string) (items []*ArticleHis
 	return
 }
 
+// 列表
+func GetArticleHistoryList121(articleId int, condition string) (items []*ArticleHistoryRep, err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	sql := `SELECT
+			h.*
+			FROM
+				cygx_article_history_record_all AS h
+			WHERE
+				h.article_id = ?  AND h.is_del = 0   `
+	if condition != "" {
+		sql = sql + condition
+	}
+	_, err = o.Raw(sql, articleId).QueryRows(&items)
+	return
+}
+
 // 列表
 func GetArticleHistoryList_H(articleId int, condition string) (items []*ArticleHistoryRep, err error) {
 	o := orm.NewOrmUsingDB("hz_cygx")