Browse Source

Merge branch 'cygx_fix_bug_08-02' of http://8.136.199.33:3000/hongze/hz_crm_api

xingzai 1 year ago
parent
commit
1c3402510d

+ 43 - 8
controllers/cygx/user.go

@@ -622,7 +622,7 @@ func (this *UserController) TableList() {
 		{PermissionName: "音视频播放", Source: 9, TotalNum: countDetail.RoadshowVideoNum + countDetail.ActivityVideoNum + countDetail.ActivityVoiceNum},
 		{PermissionName: "首页标签点击", Source: 10, TotalNum: countDetail.TagNum}}
 
-resp := new(cygx.CygxUserTableListRep)
+	resp := new(cygx.CygxUserTableListRep)
 	resp.List = List
 	resp.UserName = wxUser.RealName
 	resp.Mobile = wxUser.Mobile
@@ -730,31 +730,67 @@ func (this *UserController) TableDetail() {
 			endDate += " 23:59:59"
 			condition += ` AND r.create_time <= '` + endDate + `' `
 		}
+		if wxUser.Mobile == "" {
+			wxUser.Mobile = wxUser.Email
+		}
 		total, err = cygx.GetCygxArticleHistoryCount(wxUser.Mobile, wxUser.Email, condition)
 		if err != nil {
 			br.Msg = "获取信息失败"
 			br.ErrMsg = "获取用户阅读记录总数失败,Err:" + err.Error()
 			return
 		}
-		list, err = cygx.GetCygxArticleHistoryRecordByUser(wxUser.Mobile, wxUser.Email, condition, startSize, pageSize)
+		list, err = cygx.GetCygxArticleHistoryRecordByUserNew(wxUser.Mobile, wxUser.Email, condition, startSize, pageSize)
 		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "获取信息失败"
 			br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
 			return
 		}
+		var articleIds string
+		var articleIdArr []int
 		if len(list) > 0 {
+			articleIds = ""
+			mapAricleId := make(map[int]int)
+			mapAricleIndustrialSubjectName := make(map[int]*cygx.ArticleIndustrialSubjectNameResp)
 			for k, v := range list {
-				list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
 				if v.ArticleId >= utils.SummaryArticleId {
 					list[k].ArticleType = 1
 				} else {
 					list[k].ArticleType = 2
 				}
-				if list[k].PermissionName == "" {
-					list[k].PermissionName = v.CategoryName
+				if mapAricleId[v.ArticleId] == 0 {
+					articleIds += strconv.Itoa(v.ArticleId) + ","
+					mapAricleId[v.ArticleId] = v.ArticleId
 				}
+				list[k].RegisterPlatform = cygxService.GetArticleSourcePlatform(v.SourcePlatform)
+				articleIdArr = append(articleIdArr, v.ArticleId)
+			}
+			articleIds = strings.TrimRight(articleIds, ",")
+
+			listArticleIndustrialSubjectList, err := cygx.GetCygxArticleIndustrialSubjectName(articleIds)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取用户阅读记录,Err:" + err.Error()
+				return
+			}
+			if len(listArticleIndustrialSubjectList) > 0 {
+				for _, v := range listArticleIndustrialSubjectList {
+					mapAricleIndustrialSubjectName[v.ArticleId] = v
+				}
+				for k, v := range list {
+					if mapAricleIndustrialSubjectName[v.ArticleId] != nil {
+						list[k].IndustryName = mapAricleIndustrialSubjectName[v.ArticleId].IndustryName     // 产业
+						list[k].SubjectNameStr = mapAricleIndustrialSubjectName[v.ArticleId].SubjectNameStr // 标的
+					}
+				}
+			}
+
+			//行业
+			mapPerssionName := cygxService.GetCygxArticlePerssionNameListMap(articleIdArr)
+			for k, v := range list {
+				list[k].PermissionName = mapPerssionName[v.ArticleId]
 			}
 		}
+
 	} else if source == 2 {
 		if mobile != "" {
 			condition = ` AND s.mobile = '` + mobile + `' `
@@ -1919,7 +1955,7 @@ func (this *UserController) CompanyTableList() {
 		br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
 		return
 	}
-	tagNum, err := cygx.GetCygxTagHistoryCountByCompanyId(companyId,"")
+	tagNum, err := cygx.GetCygxTagHistoryCountByCompanyId(companyId, "")
 	if err != nil {
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		br.Msg = "获取搜索记录失败"
@@ -4163,7 +4199,7 @@ func (this *UserController) TableCompanyList() {
 		br.ErrMsg = "获取搜索记录失败,Err:" + err.Error()
 		return
 	}
-	tagNum, err := cygx.GetCygxTagHistoryCountByCompanyIds(companyCondition,"")
+	tagNum, err := cygx.GetCygxTagHistoryCountByCompanyIds(companyCondition, "")
 	if err != nil {
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		br.Msg = "获取搜索记录失败"
@@ -4319,4 +4355,3 @@ func (this *UserController) UserRemind() {
 	br.Success = true
 	br.Data = resp
 }
-

+ 27 - 3
models/cygx/cygx_user.go

@@ -332,7 +332,6 @@ type UserInteraction struct {
 	SubjectNames          string `orm:"column(subject_names);NOT NULL"`  // 标的
 }
 
-
 // 查研观向图表
 type CygxChartResp struct {
 	Title       string `description:"标题"`
@@ -354,8 +353,8 @@ type CygxChartResp struct {
 // 获取阅读记录数量
 func GetCygxArticleHistoryCount(mobile, email, condition string) (count int, err error) {
 	o := orm.NewOrm()
-	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_article_history_record_all as r  INNER JOIN cygx_article  as art  ON  art.article_id = r.article_id  WHERE   r.mobile  = ?  AND is_del = 0 ` + condition + `  OR ( email = ? AND email <> ''  AND is_del = 0  ` + condition + `) `
-	err = o.Raw(sqlCount, mobile, email).QueryRow(&count)
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_article_history_record_all as r  INNER JOIN cygx_article  as art  ON  art.article_id = r.article_id  WHERE   r.mobile  = '` + mobile + `'  AND is_del = 0 ` + condition
+	err = o.Raw(sqlCount).QueryRow(&count)
 	return
 }
 
@@ -404,6 +403,31 @@ func GetCygxArticleHistoryRecordByUser(mobile, email, condition string, startSiz
 	return
 }
 
+// 用户阅读记录列表 2023-08-02 优化拆分
+func GetCygxArticleHistoryRecordByUserNew(mobile, email, condition string, startSize, pageSize int) (items []*UserInteraction, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT
+			art.title,
+			art.article_id,
+			art.article_id_md5,
+			art.publish_date,
+			art.category_name,
+			r.create_time,
+			r.stop_time,
+			r.source as source_platform
+		FROM
+			cygx_article_history_record_all AS r
+			INNER JOIN cygx_article AS art ON art.article_id = r.article_id
+		WHERE
+			 r.mobile  = ?  AND is_del = 0 ` + condition + `  OR ( email = ? AND email <>''  AND is_del = 0 ` + condition + `  )
+			 ORDER BY  r.create_time DESC   `
+	if startSize > 0 || pageSize > 0 {
+		sql += ` LIMIT ` + strconv.Itoa(startSize) + "," + strconv.Itoa(pageSize)
+	}
+	_, err = o.Raw(sql, mobile, email).QueryRows(&items)
+	return
+}
+
 // 收藏列表数量
 func GetCygxArticleCollectCount(uid int) (count int, err error) {
 	o := orm.NewOrm()

+ 0 - 18
models/cygx/report_article.go

@@ -1270,24 +1270,6 @@ type CygxCelueArticleHistoryRecord struct {
 	RealName       string    `description:"用户姓名"`
 }
 
-func GetArticleHistoryRecordMobile(articleIds string) (mobiles string, err error) {
-	sql := `SELECT  GROUP_CONCAT( DISTINCT mobile SEPARATOR ',' ) as mobiles   FROM cygx_article_history_record_newpv WHERE article_id IN (` + articleIds + `) AND mobile!= ''`
-	o := orm.NewOrm()
-	err = o.Raw(sql).QueryRow(&mobiles)
-	return
-}
-
-func GetCygxCelueArticleHistoryRecordPv(articleIds, mobiles string) (item []*ArticleHistoryRep, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_celue_article_history_record WHERE article_id IN ( ` + articleIds + ` ) AND  `
-	if mobiles != "" {
-		sql += `	AND mobile NOT IN ( ` + mobiles + `)`
-	}
-	sql += ` ORDER BY create_time DESC  `
-	_, err = o.Raw(sql).QueryRows(&item)
-	return
-}
-
 func GetCygxCelueArticleHistoryRecordPvAll(articleIds string) (item []*ArticleHistoryRep, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM cygx_article_history_record_all as  h WHERE article_id IN ( ` + articleIds + ` )  AND   h.is_del = 0   AND h.platfor = 2 `

+ 38 - 0
models/cygx/report_mapping_celue.go

@@ -21,6 +21,22 @@ type CygxReportMappingCelue struct {
 	ModifyTime          time.Time `description:"更新时间"`
 }
 
+type CygxReportMappingCelueResp struct {
+	Id                  int       `orm:"column(id);pk" description:"id"`
+	ChartPermissionId   int       `description:"行业ID"`
+	CategoryId          int       `description:"分类ID"`
+	ChartPermissionName string    `description:"行业名称"`
+	SubCategoryName     string    `description:"主题"`
+	ReportType          int       `description:"报告类型,2产业报告,1行业报告"`
+	Sort                int       `description:"排序"`
+	IsCustom            int       `description:"是否属于自定义的匹配类型 ,1是,0否"`
+	IsSummary           int       `description:"是否是纪要库,1是,0否"`
+	IsReport            int       `description:"是否是报告,1是,0否"`
+	PermissionType      int       `description:"1主观,2客观"`
+	CreateTime          time.Time `description:"创建时间"`
+	ModifyTime          time.Time `description:"更新时间"`
+}
+
 // 获取category_id 最大的值,进行累加
 func GetCygxReportMappingCelueMaxDetail() (item *CygxReportMappingCelue, err error) {
 	o := orm.NewOrm()
@@ -28,3 +44,25 @@ func GetCygxReportMappingCelueMaxDetail() (item *CygxReportMappingCelue, err err
 	err = o.Raw(sql).QueryRow(&item)
 	return
 }
+
+// 列表
+func GetCygxReportMappingList(condition string, pars []interface{}) (items []*CygxReportMappingCelueResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping   WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// 列表
+func GetCygxReportMappingCelueList(condition string, pars []interface{}) (items []*CygxReportMappingCelueResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping_celue   WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 46 - 0
services/cygx/report_mapping.go

@@ -1,9 +1,11 @@
 package cygx
 
 import (
+	"errors"
 	"fmt"
 	"hongze/hz_crm_api/models/cygx"
 	"hongze/hz_crm_api/services/alarm_msg"
+	"hongze/hz_crm_api/utils"
 )
 
 // 报告匹配类型映射
@@ -27,3 +29,47 @@ func GetCygxReportMappingCygxListMap() (mapResp map[int]string) {
 	}
 	return
 }
+
+// 根据文章ID获取文章行业分类
+func GetCygxArticlePerssionNameListMap(articleIdArr []int) (mapResp map[int]string) {
+	lenArr := len(articleIdArr)
+	if lenArr == 0 {
+		return
+	}
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg("根据文章ID获取文章行业分类,信息失败,GetCygxArticlePerssionNameListMap Err:"+err.Error(), 3)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	//获取分类名称
+	perssionNameList, e := cygx.GetCygxReportMappingList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxReportMappingCelueList, Err: " + e.Error())
+		return
+	}
+	mapName := make(map[int]string)
+	for _, v := range perssionNameList {
+		mapName[v.CategoryId] = v.ChartPermissionName
+	}
+	pars = make([]interface{}, 0)
+	condition = ` AND  article_id IN (` + utils.GetOrmInReplace(lenArr) + `)`
+	pars = append(pars, articleIdArr)
+	listArticle, e := cygx.GetArticlList(condition, pars, 0, 999)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetArticlList, Err: " + e.Error())
+		return
+	}
+	mapResp = make(map[int]string, 0)
+	for _, v := range listArticle {
+		if v.CategoryId == 0 {
+			mapResp[v.ArticleId] = utils.CHART_PERMISSION_NAME_MF_YANXUAN
+		} else {
+			mapResp[v.ArticleId] = mapName[v.CategoryId]
+		}
+	}
+	return
+}