Browse Source

Merge branch 'master' of http://8.136.199.33:3000/hongze/hongze_cygx into cygx_10.5.3

xingzai 1 year ago
parent
commit
9d19a3be55

+ 18 - 0
controllers/activity_sign.go

@@ -139,6 +139,24 @@ func (this *ActivitySignCoAntroller) Detail() {
 
 		//线下调研活动扫码签到给对应销售发模版消息
 		services.SendActivitieSignTemplateMsg(user, activityInfo)
+
+		//处理用户标签
+		services.ActivityUserLabelLogAdd(activityId, []string{user.Mobile})
+
+		{
+			//用做后台联系人列表查询
+			itemD := new(models.CygxActivityAttendanceDetail)
+			itemD.ActivityId = activityId
+			itemD.RealName = user.RealName
+			itemD.Mobile = user.Mobile
+			itemD.CompanyName = user.CompanyName
+			itemD.IsMeetingStr = 1
+			itemD.CreateTime = time.Now()
+			var itemDs []*models.CygxActivityAttendanceDetail
+			itemDs = append(itemDs, itemD)
+			services.AddctivitySignupDetailByJmcjNew(itemDs, []int{activityId})
+		}
+
 	}
 	//1,没有签到记录不为潜在客户
 	//2,没有签到记录,手机号不为空,没有申请记录

+ 3 - 83
controllers/article.go

@@ -272,28 +272,7 @@ func (this *ArticleController) Detail() {
 			}
 			if hasPersion {
 				hasPermission = 1
-				historyRecord := new(models.CygxArticleHistoryRecord)
-				historyRecord.UserId = uid
-				historyRecord.ArticleId = articleId
-				historyRecord.CreateTime = time.Now()
-				historyRecord.Mobile = user.Mobile
-				historyRecord.Email = user.Email
-				historyRecord.CompanyId = user.CompanyId
-				historyRecord.CompanyName = user.CompanyName
-				recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
-				if recordCount == 0 {
-					go models.AddCygxArticleHistoryRecord(historyRecord)
-				} else {
-					detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
-					if err != nil {
-						br.Msg = "获取信息失败"
-						br.ErrMsg = "获取信息失败,Err:" + err.Error()
-						return
-					}
-					if detailNew.StopTime > 0 {
-						go models.AddCygxArticleHistoryRecord(historyRecord)
-					}
-				}
+				go services.ArticleHistory(articleId, user)
 				//30分钟之内阅读同一篇文章不错二次推送
 				key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
 				if !utils.Rc.IsExist(key) {
@@ -308,23 +287,6 @@ func (this *ArticleController) Detail() {
 					hasPermission = 3
 				}
 			}
-			if hasPermission == 1 {
-				key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
-				if !utils.Rc.IsExist(key) {
-					//新增浏览记录
-					record := new(models.CygxArticleViewRecord)
-					record.UserId = uid
-					record.ArticleId = articleId
-					record.CreateTime = time.Now()
-					record.Mobile = user.Mobile
-					record.Email = user.Email
-					record.CompanyId = user.CompanyId
-					record.CompanyName = user.CompanyName
-					go models.AddCygxArticleViewRecord(record)
-					utils.Rc.Put(key, 1, 5*time.Second)
-					models.ModifyReportLastViewTime(uid)
-				}
-			}
 		}
 
 		interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
@@ -533,6 +495,7 @@ func (this *ArticleController) ArticleCollect() {
 		resp.Status = 1
 		// 文章收藏消息发送
 		go services.ArticleUserRemind(user, detail, 2)
+		go services.ArticleHistoryUserLabelLogAdd(articleId, user.UserId)
 	} else {
 		err = models.RemoveArticleCollect(uid, articleId)
 		if err != nil {
@@ -937,50 +900,7 @@ func (this *ArticleController) AddStopTime() {
 				}
 			}
 			if hasPersion {
-				detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
-				if err == nil {
-					hasPermission = 1
-					historyRecord := new(models.AddStopTimeNewRep)
-					historyRecord.StopTime = detailNew.StopTime + stopTime
-					historyRecord.Id = detailNew.Id
-					historyRecord.OutType = outType
-					go models.UpdateArticleStopTime(historyRecord)
-				}
-
-				//不统计本公司的阅读记录、正常退出的不做时间差统计
-				if stopTime > 3 {
-					key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
-					record := new(models.CygxArticleHistoryRecordNewpv)
-					record.UserId = uid
-					record.ArticleId = articleId
-					record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
-					record.ModifyTime = time.Now()
-					record.Mobile = user.Mobile
-					record.Email = user.Email
-					record.CompanyId = user.CompanyId
-					record.CompanyName = user.CompanyName
-					record.StopTime = stopTime
-					record.OutType = outType
-					record.Source = source
-					if !utils.Rc.IsExist(key) || outType != 2 {
-						//新增浏览记录
-						go models.AddCygxArticleViewRecordNewpv(record)
-						recordRedis := new(services.ReportViewRecord)
-						recordRedis.UserId = user.UserId
-						recordRedis.ReportId = articleId
-						recordRedis.Mobile = user.Mobile
-						recordRedis.Email = user.Email
-						recordRedis.RealName = user.RealName
-						recordRedis.CompanyName = user.CompanyName
-						recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
-						go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
-					} else {
-						go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
-					}
-					utils.Rc.Put(key, 1, 10*time.Minute)
-				}
-
-				models.ModifyReportLastViewTime(uid)
+				go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
 			} else { //无该行业权限
 				hasPermission = 3
 			}

+ 33 - 18
controllers/report.go

@@ -62,6 +62,11 @@ func (this *ReportController) TradeList() {
 		categoryMap[v.CategoryId] = v.CategoryId
 		list = append(list, v)
 	}
+	//加了一个需求,现有数据结构不支持,手动添加  2023-06-12
+	//if ChartPermissionId == utils.KE_JI_ID {
+	//	list = append(list, &models.TradeReportMapping{MatchTypeName: "AI前沿", CategoryId: utils.ACTEGORY_ID_AI_QY})
+	//}
+
 	//var condition string
 	//var pars []interface{}
 	for k, v := range list {
@@ -70,24 +75,34 @@ func (this *ReportController) TradeList() {
 		//} else {
 		//	condition = ` AND a.category_id IN(` + strconv.Itoa(v.CategoryId) + `)`
 		//}
-		listArticle, _, err := models.GetReportAndproductIndustrylList(v.CategoryId, 0, 1)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			br.Msg = "获取信息失败"
-			br.Msg = "GetHomeList,Err:" + err.Error()
-			return
+		pageSize := 1
+		var listArticle []*models.ReportArticle
+		if v.CategoryId == utils.ACTEGORY_ID_AI_QY {
+			//加了一个需求,现有数据结构不支持,手动添加  2023-06-12
+			listArticle, _, err = services.GetAiQianYanArtilceList(0, pageSize)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				br.Msg = "获取信息失败"
+				br.Msg = "GetHomeList,Err:" + err.Error()
+				return
+			}
+			//for _, vAi := range listArticleAi {
+			//	listArticle = append(listArticle, &models.ReportArticle{
+			//		CategoryId:  vAi.CategoryId,
+			//		PublishDate: vAi.PublishDate,
+			//	})
+			//}
+		} else {
+			listArticle, _, err = models.GetReportAndproductIndustrylList(v.CategoryId, 0, pageSize)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				br.Msg = "获取信息失败"
+				br.Msg = "GetHomeList,Err:" + err.Error()
+				return
+			}
 		}
-		if len(listArticle) > 0 {
-			list[k].UpdateTime = utils.StrTimeToTime(listArticle[0].PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
+		//listArticle, _, err := models.GetReportAndproductIndustrylList(v.CategoryId, 0, 1)
 
-			//count, err := models.CheckThisCategoryNewArticleIsRead(uid, v.CategoryId)
-			//if err != nil {
-			//	br.Msg = "获取信息失败"
-			//	br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
-			//	return
-			//}
-			//if count == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.UpdateTime)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.UpdateTime)) {
-			//	list[k].IsRed = true
-			//}
+		if len(listArticle) > 0 {
+			list[k].UpdateTime = utils.StrTimeToTime(listArticle[0].PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式 }
 		}
 	}
 	resp := new(models.TradeReportMappingResp)
@@ -864,8 +879,8 @@ func (this *ReportController) Fllow() {
 		}
 	}
 
-	//处理是否关注全部赛道字段
-	go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
+	go services.IndustryFllowWithTrack(industrialManagementId, count, uid)       //处理是否关注全部赛道字段
+	go services.IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid) //处理用户标签
 	br.Msg = "操作成功"
 	br.Ret = 200
 	br.Success = true

+ 10 - 98
controllers/tactics.go

@@ -61,82 +61,14 @@ func (this *TacticsController) List() {
 	//var pars []interface{}
 	//var total int
 	resp := new(models.TacticsListResp)
-	//page := paging.GetPaging(currentIndex, pageSize, total)
-
-	//获取该产业下所对应的行业图片
-	//detail, errCategory := models.GetdetailByCategoryIdOneByHangye(categoryId)
-	//if errCategory != nil {
-	//	br.Msg = "获取信息失败"
-	//	br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
-	//	return
-	//}
-	//对应行业的图片
-	//detailChartPermissionUrl, err := models.GetConfigByCode("category_chart_permissionimg_url")
-	//if err != nil {
-	//	br.Msg = "获取数据失败"
-	//	br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
-	//	return
-	//}
-	//chartPermissionUrlList := strings.Split(detailChartPermissionUrl.ConfigValue, "{|}")
-	//mapChartPermission := make(map[string]string)
-	//var permissionName string
-	//var imgUrlChartPermission string
-	//for _, v := range chartPermissionUrlList {
-	//	vslice := strings.Split(v, "_")
-	//	permissionName = vslice[0]
-	//	imgUrlChartPermission = vslice[len(vslice)-1]
-	//	mapChartPermission[permissionName] = imgUrlChartPermission
-	//}
-
-	//对应分类的所图片
-	//detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
-	//if err != nil {
-	//	br.Msg = "获取数据失败"
-	//	br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
-	//	return
-	//}
-	//categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
-	//mapCategoryUrl := make(map[string]string)
-	//var categoryIdStr string
-	//var imgUrlChart string
-	//for _, v := range categoryUrlList {
-	//	vslice := strings.Split(v, "_")
-	//	categoryIdStr = vslice[0]
-	//	imgUrlChart = vslice[len(vslice)-1]
-	//	mapCategoryUrl[categoryIdStr] = imgUrlChart
-	//}
-
-	//if categoryId < 0 {
-	//	listTactics, err := models.GetReportMappingStrategyAll()
-	//	if err != nil && err.Error() != utils.ErrNoRow() {
-	//		br.Msg = "获取信息失败"
-	//		br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
-	//		return
-	//	}
-	//	for _, v := range listTactics {
-	//		listTacticsSrt = listTacticsSrt + strconv.Itoa(v.CategoryId) + `,`
-	//	}
-	//	listTacticsSrt = strings.TrimRight(listTacticsSrt, ",")
-	//	condition = ` AND category_id IN(` + listTacticsSrt + `)`
-	//} else {
-	//	if detail.CeLueFieldId != "" {
-	//		condition = ` AND ce_lue_field_id IN(` + detail.CeLueFieldId + `)`
-	//	} else if detail.PolymerizationId != "" {
-	//		condition = ` AND category_id IN(` + detail.PolymerizationId + `)`
-	//	} else {
-	//		condition = ` AND category_id IN(` + strconv.Itoa(categoryId) + `)`
-	//	}
-	//}
-	//total, err = models.GetHomeCount(condition, pars)
-	//if err != nil {
-	//	br.Msg = "获取信息失败"
-	//	br.Msg = "获取帖子总数失败,Err:" + err.Error()
-	//	return
-	//}
-
-	//list, err := models.GetReportTacticsList(condition, pars, uid, startSize, pageSize)
-
-	list, total, err := models.GetReportAndproductIndustrylList(categoryId, startSize, pageSize)
+	list := make([]*models.ReportArticle, 0)
+	var total int
+	var err error
+	if categoryId == utils.ACTEGORY_ID_AI_QY {
+		list, total, err = services.GetAiQianYanArtilceList(0, pageSize)
+	} else {
+		list, total, err = models.GetReportAndproductIndustrylList(categoryId, startSize, pageSize)
+	}
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.Msg = "获取帖子数据失败,Err:" + err.Error()
@@ -146,15 +78,12 @@ func (this *TacticsController) List() {
 	var productInteriorIs []int
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	for _, v := range list {
-		//if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
-		//	list[k].IsRed = true
-		//}
+
 		if v.Resource == 1 {
 			articleIds = append(articleIds, v.ArticleId)
 		} else {
 			productInteriorIs = append(productInteriorIs, v.ArticleId)
 		}
-		//list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
 	}
 	ArticleHistoryMap := services.GetArticleHistoryByUser(articleIds, user)
 	ProductInteriorHistoryMap := services.GetCygxProductInteriorHistoryListMap(articleIds, user)
@@ -184,24 +113,6 @@ func (this *TacticsController) List() {
 			v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
 		}
 	}
-	//lenList := len(list)
-	//for i := 0; i < lenList; i++ {
-	//	item := list[i]
-	//	list[i].Body, _ = services.GetReportContentTextSub(item.Body)
-	//	list[i].Abstract = html.UnescapeString(item.Abstract)
-	//	//list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
-	//	list[i].Annotation = strings.Replace(item.Annotation, "<br>", "", -1)
-	//	//行业比较研究、资金流向,显示报告的摘要
-	//	if resp.MatchTypeName == "行业比较研究" || resp.MatchTypeName == "资金流向" {
-	//		list[i].Annotation = list[i].Abstract
-	//	}
-	//	//if item.ArticleId == 6881 {
-	//	//	fmt.Println(list[i].Annotation)
-	//	//}
-	//	list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
-	//}
-	//
-	//resp.CategoryImgUrlPc = mapChartPermission[detail.ChartPermissionName]
 	resp.List = list
 	resp.Paging = page
 	br.Ret = 200
@@ -445,6 +356,7 @@ func (this *TacticsController) TacticsTimeLineList() {
 	}
 	for _, v := range list {
 		v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
+		v.Resource = 1
 	}
 	if len(list) == 0 {
 		list = make([]*models.CygxTacticsTimeLineResp, 0)

+ 9 - 5
controllers/user.go

@@ -1099,7 +1099,7 @@ func (this *UserController) ApplyTryOut() {
 					req.RealName = user.RealName
 					req.CompanyName = user.CompanyName
 				}
-				go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
+				//go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
 			}
 		}
 	} else {
@@ -1121,10 +1121,6 @@ func (this *UserController) ApplyTryOut() {
 			applyMethod = applyMethod + "," + title
 		}
 	}
-	//如果对应销售不存在就给王芳,汪洋推模版消息
-	if sellerItem == nil {
-		go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
-	}
 
 	item := new(models.CygxApplyRecord)
 	item.UserId = user.UserId
@@ -1148,6 +1144,14 @@ func (this *UserController) ApplyTryOut() {
 		br.ErrMsg = "申请失败,Err:" + err.Error()
 		return
 	}
+	if sellerItem == nil {
+		go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
+	} else {
+		openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
+		if openIpItem != nil && openIpItem.OpenId != "" {
+			go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
+		}
+	}
 	//添加成功后,设置5分钟缓存,不允许重复添加
 	//utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
 

+ 12 - 0
models/activity.go

@@ -1217,6 +1217,18 @@ func GetActivityLabelListAllNoLimit(condition, sortTime string, pars []interface
 	return
 }
 
+// 列表
+func GetCygxActivityList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivity, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_activity as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
 // 批量修改弘则活动与进门财经的一个活动关联
 func UpdateJmcjActivityIdGroup(items map[int]string) (err error) {
 	o := orm.NewOrm()

+ 1 - 1
models/activity_attendance_detail.go

@@ -101,7 +101,7 @@ func AddAttendancDetail(items []*CygxActivityAttendanceDetail, activityId int, m
 	if err != nil {
 		return
 	}
-	sql = `UPDATE cygx_activity_signup SET  is_meeting=1   WHERE  activity_id=? AND outbound_mobile IN (` + mobileStr + `)`
+	sql = `UPDATE cygx_activity_signup SET  is_meeting=1   WHERE  activity_id=? AND ( outbound_mobile IN (` + mobileStr + `)  OR mobile IN (` + mobileStr + `) )`
 	_, err = o.Raw(sql, activityId).Exec()
 	if err != nil {
 		return

+ 10 - 0
models/activity_special_trip.go

@@ -51,6 +51,16 @@ func GetCygxActivitySpecialTripList(condition string, pars []interface{}) (item
 	return
 }
 
+func GetCygxActivitySpecialmeetingDetailList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_activity_special_meeting_detail  
+			WHERE 1 = 1 ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
 // 获取某一用户的报名的数量
 func GetUserActivitySpecialTripCount(uid, activityId int) (count int, err error) {
 	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip  WHERE  user_id=?  AND   activity_id =? `

+ 25 - 0
models/article.go

@@ -47,6 +47,7 @@ type CygxArticle struct {
 	TypeName         string `description:"策略平台报告类型"`
 	ModifyTimeByCl   string `description:"策略平台报告更新时间"`
 	CeLueFieldId     int    `description:"策略平台领域ID"`
+	Cover            string `description:"封面图片"`
 }
 
 type CygxArticleEs struct {
@@ -112,6 +113,7 @@ type HomeArticle struct {
 	IsReport            int                  `description:"是否属于报告,1是,0否"`
 	ArticleResponse     int                  `description:"报告类型 0:啥也不是,1研选报告,2:研选纪要,3:研选沙龙,4;研选观点"`
 	Readnum             int                  `description:"阅读数量"`
+	Cover               string               `description:"封面图片"`
 	List                []*IndustrialManagementIdInt
 }
 
@@ -728,3 +730,26 @@ func GetArticleStock() (items []*SummaryArticleStock, err error) {
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+// 列表
+func GetCygxCygxArticleList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxArticle, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+// 获取数量
+func GetCygxArticleCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_article as art WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}

+ 0 - 13
models/article_category_mapping.go

@@ -30,19 +30,6 @@ func AddCygxArticleCategoryMapping(item *CygxArticleCategoryMapping) (lastId int
 	return
 }
 
-type CygxReportMappingCygx struct {
-	Id                  int    `orm:"column(id);pk" description:"id"`
-	ChartPermissionId   int    `description:"行业ID"`
-	ChartPermissionName string `description:"行业名称"`
-	MatchTypeName       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客观"`
-}
-
 type CygxReportMappingGroup struct {
 	Id              int       `orm:"column(id);pk" description:"id"`
 	IdCygx          int       `description:"分类ID"`

+ 1 - 1
models/article_history_record_newpv.go

@@ -295,7 +295,7 @@ func GetCygxArticleHistoryAllTop(pars []interface{}, condition string) (items []
 // 列表
 func GetCygxArticleHistoryRecordNewpvList(condition string, pars []interface{}) (items []*CygxArticleHistoryRecordNewpv, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_article_history_record_newpv as art WHERE 1= 1 `
+	sql := `SELECT * FROM cygx_article_history_record_newpv as art WHERE 1= 1  `
 	if condition != "" {
 		sql += condition
 	}

+ 4 - 0
models/db.go

@@ -147,6 +147,10 @@ func init() {
 		new(CygxActivitySignupBreak),
 		new(CygxBannerHistory),
 		new(CygxReportHistoryRecordLog),
+		new(CygxUserLabel),
+		new(CygxUserLabelActivity),
+		new(CygxUserLabelArticle),
+		new(CygxUserLabelActivitySpecial),
 		new(CygxInviteCompany),
 	)
 	// 记录ORM查询日志

+ 28 - 2
models/industrial_activity_group_management.go

@@ -29,7 +29,7 @@ type CygxIndustrialSubject struct {
 	Source                 int       `description:"来源,1正常添加,2:通过文章添加,3通过活动添加(默认为1)"`
 }
 
-//获取标的列表
+// 获取标的列表
 func GetCygxIndustrialSubjectList(subjectName string) (items []*CygxIndustrialSubject, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
@@ -82,4 +82,30 @@ func GetActivityIndustryRelationList(condition string, pars []interface{}) (list
 	}
 	_, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
 	return
-}
+}
+
+// 获取数量
+func GetCygxIndustrialActivityGroupManagementCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_industrial_activity_group_management as art WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// CygxIndustrialActivityGroupManagement 获取活动与产业关联列表
+func GetCygxIndustrialActivityGroupManagementList(condition string, pars []interface{}) (list []*CygxIndustrialActivityGroupManagement, err error) {
+	sql := `SELECT
+			*
+			FROM
+			cygx_industrial_activity_group_management
+			WHERE
+				1 = 1 `
+	if condition != `` {
+		sql += condition
+	}
+	_, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
+	return
+}

+ 12 - 0
models/industry_fllow.go

@@ -203,3 +203,15 @@ func GetTopIndustryFollowData(startSize, pageSize int, condition string, pars []
 	_, err = orm.NewOrm().Raw(sql, pars, startSize, pageSize).QueryRows(&list)
 	return
 }
+
+// 列表
+func GetCygxIndustryFllowListByCon(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxIndustryFllow, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_industry_fllow as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	//sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 21 - 0
models/report_mapping.go

@@ -374,3 +374,24 @@ func GetReportMapping() (items []*CygxReportMapping, err error) {
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+// 通过分类ID对应的系列名称
+func GetdetailByCategoryIdLabel(categoryId int) (item *CygxReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			c.id,c.match_type_name
+			FROM
+			cygx_report_mapping_group as g
+			INNER JOIN cygx_report_mapping_cygx as c ON c.id = g.id_cygx
+			WHERE
+			category_id_celue = ? LIMIT 1`
+	err = o.Raw(sql, categoryId).QueryRow(&item)
+	return
+}
+
+func GetCygxReportMappingById(id int) (items *CygxReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping_cygx WHERE id = ?`
+	err = o.Raw(sql, id).QueryRow(&items)
+	return
+}

+ 31 - 0
models/report_mapping_cygx.go

@@ -0,0 +1,31 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	//"time"
+)
+
+type CygxReportMappingCygx struct {
+	Id                  int    `orm:"column(id);pk" description:"id"`
+	ChartPermissionId   int    `description:"行业ID"`
+	ChartPermissionName string `description:"行业名称"`
+	MatchTypeName       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客观"`
+}
+
+// 列表
+func GetCygxReportMappingCygxByCon(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxReportMappingCygx, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping_cygx as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	//sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 1 - 0
models/tactics.go

@@ -84,6 +84,7 @@ type Tactics2 struct {
 	TypeName        string    `description:"策略平台报告类型"`
 	UpdateDate      string    `description:"策略平台报告更新时间"`
 	CeLueFieldId    int       `description:"策略平台领域ID"`
+	Cover           string    `description:"封面图片"`
 }
 
 func GetTacticsList2(endDate string) (list []*Tactics2, err error) {

+ 1 - 0
models/tactics_time_line.go

@@ -43,6 +43,7 @@ type CygxTacticsTimeLineResp struct {
 	ArticleId   int    `description:"文章ID"`
 	ChartId     int    `description:"图表ID"`
 	Link        string `description:"文章或图表链接"`
+	Resource    int    `description:"来源类型,1:文章、2:产品内测、3:晨报点评"`
 }
 
 // 获取数量

+ 115 - 0
models/user_label.go

@@ -0,0 +1,115 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserLabelLogRedis struct {
+	UserId     int       `description:"用户ID"`
+	SourceId   int       `description:"资源ID"`
+	SourceType int       `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
+	IsFllow    int       `description:"1关注、0取消关注"`
+	CreateTime time.Time `description:"创建时间"`
+}
+
+type CygxUserLabel struct {
+	Id         int       `orm:"column(id);pk"`
+	UserId     int       `description:"用户ID"`
+	CompanyId  int       `description:"公司id"`
+	RealName   string    `description:"用户实际名称"`
+	Mobile     string    `description:"手机号"`
+	Email      string    `description:"邮箱"`
+	Label      string    `description:"标签内容"`
+	Weight     int       `description:"权重"`
+	SourceId   int       `description:"来源ID(产业ID,系列ID)"`
+	Source     int       `description:"来源1:产业、2:系列"`
+	IsFollow   int       `description:"是否关注,1是,0否"`
+	CreateTime time.Time `description:"创建时间"`
+	ModifyTime time.Time `description:"更新时间"`
+}
+
+// 获取数量
+func GetCygxUserLabelCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_user_label as art WHERE 1= 1   AND modify_time > DATE_SUB(CURDATE(), INTERVAL 3 MONTH)  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// 添加
+func AddCygxUserLabel(item *CygxUserLabel) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// 批量添加
+func CygxUserLabelMulti(items []*CygxUserLabel) (err error) {
+	o := orm.NewOrm()
+	if len(items) > 0 {
+		//批量添加新的记录
+		_, err = o.InsertMulti(len(items), items)
+	}
+	return
+}
+
+// 修改是否关注
+func UpdateCygxUserLabelIsFollow(isFollow, sourceId, source, userId int, label string) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_user_label SET is_follow=?,label = ? , modify_time=NOW()  WHERE source_id=? AND source = ? AND user_id = ? `
+	_, err = o.Raw(sql, isFollow, label, sourceId, source, userId).Exec()
+	return
+}
+
+// 修改对应标签权重+1
+func UpdateCygxUserLabelWeight(sourceId, source, userId int, label string) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_user_label SET weight = weight +1 ,label = ? , modify_time=NOW()  WHERE source_id=? AND source = ? AND  user_id = ? `
+	_, err = o.Raw(sql, label, sourceId, source, userId).Exec()
+	return
+}
+
+// 把所有用户标签权重设置为0
+func UpdateCygxUserLabelWeightAll() (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_user_label SET weight = 0 `
+	_, err = o.Raw(sql).Exec()
+	return
+}
+
+// 列表
+func GetCygxUserLabelList(condition string, pars []interface{}) (items []*CygxUserLabel, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_user_label as art WHERE 1= 1   	`
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// UpdateCygxUserLabelMulti 批量修改用户标签权重
+func UpdateCygxUserLabelMulti(items []*CygxUserLabel) (err error) {
+	o := orm.NewOrm()
+	p, err := o.Raw(` UPDATE cygx_user_label SET weight = ? WHERE user_id = ? AND label = ? `).Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close() // 别忘记关闭 statement
+	}()
+	for _, v := range items {
+		_, err = p.Exec(
+			v.Weight,
+			v.UserId,
+			v.Label)
+		if err != nil {
+			return
+		}
+	}
+	return
+}

+ 42 - 0
models/user_label_activity.go

@@ -0,0 +1,42 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserLabelActivity struct {
+	Id                     int       `orm:"column(id);pk"`
+	UserId                 int       `description:"用户ID"`
+	CompanyId              int       `description:"公司id"`
+	RealName               string    `description:"用户实际名称"`
+	Mobile                 string    `description:"手机号"`
+	Email                  string    `description:"邮箱"`
+	Label                  string    `description:"标签内容"`
+	ActivityId             int       `description:"活动ID"`
+	IndustrialManagementId int       `description:"cygx_industrial_management表的主键ID"`
+	CreateTime             time.Time `description:"创建时间"`
+	ModifyTime             time.Time `description:"更新时间"`
+}
+
+// 列表
+func GetCygxUserLabelActivity(condition string, pars []interface{}) (items []*CygxUserLabelActivity, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_user_label_activity as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// 批量添加
+func AddCygxUserLabelActivityList(items []*CygxUserLabelActivity) (lastId int64, err error) {
+	lenitems := len(items)
+	if lenitems == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(1, items)
+	return
+}

+ 43 - 0
models/user_label_activity_special.go

@@ -0,0 +1,43 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserLabelActivitySpecial struct {
+	Id                     int       `orm:"column(id);pk"`
+	UserId                 int       `description:"用户ID"`
+	CompanyId              int       `description:"公司id"`
+	RealName               string    `description:"用户实际名称"`
+	Mobile                 string    `description:"手机号"`
+	Email                  string    `description:"邮箱"`
+	Label                  string    `description:"标签内容"`
+	ActivityId             int       `description:"活动ID"`
+	IndustrialManagementId int       `description:"cygx_industrial_management表的主键ID"`
+	CreateTime             time.Time `description:"创建时间"`
+	ModifyTime             time.Time `description:"更新时间"`
+}
+
+// 列表
+func GetCygxUserLabelActivitySpecial(condition string, pars []interface{}) (items []*CygxUserLabelActivitySpecial, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_user_label_activity_special as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// 批量添加
+func AddCygxUserLabelActivitySpecialList(items []*CygxUserLabelActivitySpecial) (lastId int64, err error) {
+	lenitems := len(items)
+	if lenitems == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(1, items)
+	return
+}

+ 50 - 0
models/user_label_article.go

@@ -0,0 +1,50 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserLabelArticle struct {
+	Id         int       `orm:"column(id);pk"`
+	UserId     int       `description:"用户ID"`
+	CompanyId  int       `description:"公司id"`
+	RealName   string    `description:"用户实际名称"`
+	Mobile     string    `description:"手机号"`
+	Email      string    `description:"邮箱"`
+	Label      string    `description:"标签内容"`
+	ArticleId  int       `description:"文章ID"`
+	SourceId   int       `description:"来源ID(产业ID,系列ID)"`
+	Source     int       `description:"来源1:产业、2:系列"`
+	CreateTime time.Time `description:"创建时间"`
+	ModifyTime time.Time `description:"更新时间"`
+}
+
+// 添加
+func AddCygxUserLabelArticle(item *CygxUserLabelArticle) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// 批量添加
+func AddCygxUserLabelArticleList(items []*CygxUserLabelArticle) (lastId int64, err error) {
+	lenitems := len(items)
+	if lenitems == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(1, items)
+	return
+}
+
+// 列表
+func GetCygxUserLabelArticleList(condition string, pars []interface{}) (items []*CygxUserLabelArticle, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_user_label_article as art WHERE 1= 1   	`
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 12 - 0
models/wx_user.go

@@ -585,6 +585,18 @@ func GetWxUserByMobiles(mobiles []string) (items []*WxUser, err error) {
 	return
 }
 
+// GetWxUserByMobiles 根据用户手机号获取用户详情
+func GetWxUserByOutboundMobiles(mobiles []string) (items []*WxUser, err error) {
+	lenmobiles := len(mobiles)
+	if lenmobiles == 0 {
+		return
+	}
+	sql := `SELECT* FROM wx_user  WHERE outbound_mobile in (` + utils.GetOrmInReplace(lenmobiles) + `)  `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, mobiles).QueryRows(&items)
+	return
+}
+
 func UserSubscribe(subscribeTime string, userId int) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE wx_user SET cygx_subscribe=1,cygx_subscribe_time=? WHERE user_id = ? `

+ 12 - 0
models/xzs_choose_category.go

@@ -27,6 +27,18 @@ func GetCygxXzsChooseCategoryList(mobile string) (items []*CygxXzsChooseCategory
 	return
 }
 
+// 列表
+func GetCygxXzsChooseCategoryListByCon(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxXzsChooseCategory, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_xzs_choose_category as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	//sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
 // 添加
 func AddCygxCategoryFllow(item *CygxXzsChooseCategory) (lastId int64, err error) {
 	o := orm.NewOrm()

+ 29 - 17
services/activity.go

@@ -557,6 +557,25 @@ func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.Ac
 		havePower = true
 		return
 	}
+	//医药消费,科技,智造四大行业,验证主客观。如果主客观校验不通过,那么直接返回
+	if strings.Contains(utils.YI_YAO_NAME+utils.XIAO_FEI_NAME+utils.KE_JI_NAME+utils.ZHI_ZAO_NAME, activityInfo.ChartPermissionName) {
+		if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
+			if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
+				havePower = true
+			} else {
+				havePower = false
+			}
+		} else {
+			if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
+				havePower = true
+			} else {
+				havePower = false
+			}
+		}
+		if !havePower {
+			return
+		}
+	}
 	if activityInfo.LimitPeopleNum > 0 {
 		mapUserType, e := GetActivityCcustomerTypeList()
 		if e != nil {
@@ -640,23 +659,6 @@ func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.Ac
 			}
 		}
 	}
-	if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 {
-		if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") {
-			havePower = true
-		} else {
-			havePower = false
-		}
-	} else {
-		if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") {
-			havePower = true
-		} else {
-			havePower = false
-		}
-	}
-	//如果主客观校验不通过,那么直接返回
-	if !havePower {
-		return
-	}
 
 	permissionShengji, errs := models.GetCompanyPermissionByUserTrip(user.CompanyId)
 	if errs != nil {
@@ -1377,6 +1379,7 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 				var isPlayback bool // 是否包含回放
 				needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
 				var mobileStr string
+				var mobileArr []string
 				if len(list) > 0 {
 					fmt.Println("原来的", vAct.RoadshowTitle)
 					fmt.Println("处理的", activityName)
@@ -1409,6 +1412,7 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 							item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
 							item.CreateTime = time.Now()
 							mobileStr += "'" + v.UserPhone + "'" + ","
+							mobileArr = append(mobileArr, v.UserPhone)
 							needAddAttendanc = append(needAddAttendanc, item)
 						}
 					}
@@ -1450,7 +1454,10 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 						return err
 					}
 
+					go ActivityUserLabelLogAdd(activityDetail.ActivityId, mobileArr)
+
 					AddctivitySignupDetailByJmcj(needAddAttendanc, activityDetail.ActivityId)
+
 				}
 			}
 		}
@@ -1486,6 +1493,7 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 				var isPlayback bool // 是否包含回放
 				needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
 				var mobileStr string
+				var mobileArr []string
 				if len(list) > 0 {
 					fmt.Println("原来的1", vAct.ActivityName)
 					fmt.Println("处理的2", activityName)
@@ -1518,6 +1526,7 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 							item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId
 							item.CreateTime = time.Now()
 							mobileStr += "'" + v.UserPhone + "'" + ","
+							mobileArr = append(mobileArr, v.UserPhone)
 							needAddAttendanc = append(needAddAttendanc, item)
 						}
 					}
@@ -1558,7 +1567,10 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 						return err
 					}
 					activityIds += strconv.Itoa(vAct.ActivityId) + ","
+
+					go ActivityUserLabelLogAdd(vAct.ActivityId, mobileArr)
 					AddctivitySignupDetailByJmcj(needAddAttendanc, vAct.ActivityId)
+
 				}
 			}
 		}

+ 5 - 12
services/activity_special.go

@@ -1039,6 +1039,7 @@ func SendWxMsgActivitySpecial10(activityInfo *models.CygxActivitySpecialDetail)
 
 // SendWxMsgActivitySpecialTwoDays  活动开始前两天08:00,提醒报名客户 \提醒报名客户的对口销售
 func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
+	//func SendWxMsgActivitySpecialTwoDays() (err error) {
 	var msg string
 	defer func() {
 		if err != nil {
@@ -1053,7 +1054,7 @@ func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
 	endTime := twoDayTime.Format(utils.FormatDate) + " 23:59:59"
 	var condition string
 	var pars []interface{}
-	condition = ` AND  days >0  AND activity_time BETWEEN ? AND  ? `
+	condition = ` AND  days >0  AND activity_time BETWEEN ? AND  ?  `
 	pars = append(pars, startTime, endTime)
 	listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
 	if e != nil {
@@ -1093,11 +1094,8 @@ func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
 		first := ""
 		keyword1 := "专项调研【" + v.ResearchTheme + "】"
 		keyword2 := "将在两天后进行,如不能参加,请及时取消报名"
-		keyword3 := v.ActivityTimeTextByDay
-		keyword4 := "线上"
-		if v.SpecialType == 2 {
-			keyword4 = v.City
-		}
+		keyword3 := ""
+		keyword4 := ""
 		remark := "点击查看活动详情"
 		SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
 
@@ -1118,10 +1116,6 @@ func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
 			if len(listSeller) == 0 {
 				continue
 			}
-			type SllerData struct {
-				Openid  string `description:"Openid"`
-				Keyword string `description:"Keyword "`
-			}
 			mapSller := make(map[string]string)
 			mapSllerOpenid := make(map[string]string)
 			for _, vS := range listSeller {
@@ -1133,8 +1127,7 @@ func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
 				}
 			}
 			for k, _ := range mapSller {
-				keyword1 = "将在两天后进行,请及时提醒您的报名客户"
-				//keyword2 = vM
+				keyword2 = "将在两天后进行,请及时提醒您的报名客户"
 				openIdList = make([]*models.OpenIdList, 0)
 				openIdList = append(openIdList, &models.OpenIdList{OpenId: mapSllerOpenid[k]})
 				SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)

+ 103 - 8
services/article.go

@@ -675,15 +675,15 @@ func GetArticleListByApi(cont context.Context) (err error) {
 }
 
 //func init() {
-// allList, err := models.GetArticleAll()
+//	// allList, err := models.GetArticleAll()
+//	//
+//	// fmt.Println(err)
+//	//
+//	//	for _, v := range allList {
+//	//		HandleArticleListByApi(v.ArticleId)
+//	//	}
+//	HandleArticleListByApi(8785)
 //
-// fmt.Println(err)
-//
-//	for _, v := range allList {
-//		HandleArticleListByApi(v.ArticleId)
-//	}
-//HandleArticleListByApi(8112)
-
 //}
 
 // 处理同步过来的文章
@@ -755,6 +755,14 @@ func HandleArticleListByApi(artcleId int) (err error) {
 		return
 	}
 
+	var cover string
+	if articleResult.Series.Name == "图解市场" {
+		cover = GetArticleCoverByChartFirst(articleResult.Content.Body)
+	} else if articleResult.Series.Name == "行业深度" {
+		cover = articleResult.Cover
+	}
+	fmt.Println(cover)
+	//return
 	//状态等于 2 跟 4 的进行同步 IsActive 为false 软删除的也不同步
 	if exitMap[articleResult.SeriesId] > 0 && (articleResult.PublishStatus == 2 || articleResult.PublishStatus == 4) && articleResult.IsActive {
 		articleResult.PublishDate = time.Date(articleResult.PublishDate.Year(), articleResult.PublishDate.Month(), articleResult.PublishDate.Day(), articleResult.PublishDate.Hour(), articleResult.PublishDate.Minute(), articleResult.PublishDate.Second(), articleResult.PublishDate.Nanosecond(), time.Local)
@@ -792,6 +800,7 @@ func HandleArticleListByApi(artcleId int) (err error) {
 		item.CategoryId = exitMap[articleResult.SeriesId]
 		item.CategoryIdTwo = exitMap[articleResult.SeriesId]
 		item.SubCategoryName = articleResult.Series.Name
+		item.Cover = cover
 		if len(articleResult.Stock) > 0 {
 			var stock string
 			for _, vS := range articleResult.Stock {
@@ -991,6 +1000,7 @@ func HandleArticleListByApi(artcleId int) (err error) {
 			updateParams["TypeName"] = v.TypeName
 			updateParams["ModifyTimeByCl"] = v.UpdateDate
 			updateParams["CeLueFieldId"] = v.CeLueFieldId
+			updateParams["Cover"] = v.Cover
 			whereParam := map[string]interface{}{"article_id": v.ArticleId}
 			err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
 			if err != nil {
@@ -1034,6 +1044,7 @@ func HandleArticleListByApi(artcleId int) (err error) {
 			item.TypeName = v.TypeName
 			item.ModifyTimeByCl = v.UpdateDate
 			item.CeLueFieldId = v.CeLueFieldId
+			item.Cover = v.Cover
 			newId, err := models.AddCygxArticles(item)
 			if err != nil {
 				fmt.Println("AddCygxArticle Err:", err.Error())
@@ -2043,3 +2054,87 @@ func GetArticleStockMap() (mapResp map[string]int, err error) {
 	}
 	return
 }
+
+// GetAiQianYanArtilceList 获取AI前沿几篇文章
+func GetAiQianYanArtilceList(startSize, pageSize int) (items []*models.ReportArticle, total int, err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("获取AI前沿几篇文章失败"+err.Error(), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition += ` AND title LIKE '%AI前沿%' AND publish_status = 1  ORDER BY publish_date DESC   `
+	articleList, e := models.GetCygxCygxArticleList(condition, pars, startSize, pageSize)
+	if e != nil {
+		err = errors.New("GetCygxCygxArticleList, Err: " + e.Error())
+		return
+	}
+	total, e = models.GetCygxArticleCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxArticleCount, Err: " + e.Error())
+		return
+	}
+
+	for _, v := range articleList {
+		item := new(models.ReportArticle)
+		item.ArticleId = v.ArticleId
+		item.Title = v.Title
+		item.Abstract = v.Abstract
+		item.Annotation = v.Annotation
+		item.PublishDate = v.PublishDate
+		item.Resource = 1
+		item.CategoryId = strconv.Itoa(v.CategoryId)
+		item.Body = v.Body
+		items = append(items, item)
+	}
+	return
+}
+
+// 获取文章内部图表的第一张封面图
+func GetArticleCoverByChartFirst(body string) (cover string) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("获取文章内部图表的第一张封面图失败,Err:"+err.Error()+body, 3)
+		}
+	}()
+	var chartUrl string
+	var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
+	match := hrefRegexp.FindAllString(body, -1)
+	if match != nil {
+		for _, v := range match {
+			if strings.Contains(v, "charts/display") {
+				chartUrl = v
+				break
+			}
+		}
+	}
+	if chartUrl != "" {
+		urlSlice := strings.Split(chartUrl, "/")
+		lenurlSlice := len(urlSlice)
+		sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
+		if sourceId == 0 {
+			sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
+		}
+		if sourceId == 0 {
+			err = errors.New("新的图标链接无法解析" + chartUrl)
+			return
+		}
+		chartUrlApi := utils.ApiUrl + "charts/" + strconv.Itoa(sourceId)
+		authorization := utils.ApiAuthorization
+		body, e := PublicGetDate(chartUrlApi, authorization)
+		if e != nil {
+			err = errors.New("PublicGetDate" + err.Error())
+			return
+		}
+		var resultDate models.ChartResultDetailApi
+		e = json.Unmarshal(body, &resultDate)
+		if e != nil {
+			err = errors.New(" json.Unmarshal" + err.Error())
+		}
+		cover = resultDate.Data.Cover
+	}
+	return
+}

+ 85 - 0
services/article_history.go

@@ -1,9 +1,12 @@
 package services
 
 import (
+	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
+	"strconv"
+	"time"
 )
 
 func GetArticleHistoryByUser(articleIds []int, user *models.WxUserItem) (mapResp map[int]int) {
@@ -32,3 +35,85 @@ func GetArticleHistoryByUser(articleIds []int, user *models.WxUserItem) (mapResp
 	}
 	return
 }
+
+// 记录用户文章浏览记录
+func ArticleHistory(articleId int, user *models.WxUserItem) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("记录用户文章浏览记录,失败"+err.Error(), 2)
+		}
+	}()
+	recordRedis := new(ReportViewRecord)
+	recordRedis.UserId = user.UserId
+	recordRedis.ReportId = articleId
+	recordRedis.Mobile = user.Mobile
+	recordRedis.Email = user.Email
+	recordRedis.RealName = user.RealName
+	recordRedis.CompanyName = user.CompanyName
+	recordRedis.CreateTime = time.Now()
+	go PushViewRecordNewRedisData(recordRedis, user.CompanyId)
+	uid := user.UserId
+	key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
+	if !utils.Rc.IsExist(key) {
+		//新增浏览记录
+		//这个表貌似没怎么用了,暂时保留记录
+		record := new(models.CygxArticleViewRecord)
+		record.UserId = uid
+		record.ArticleId = articleId
+		record.CreateTime = time.Now()
+		record.Mobile = user.Mobile
+		record.Email = user.Email
+		record.CompanyId = user.CompanyId
+		record.CompanyName = user.CompanyName
+		_, e := models.AddCygxArticleViewRecord(record)
+		if e != nil {
+			err = errors.New("AddCygxArticleViewRecord, Err: " + e.Error())
+			return
+		}
+
+		e = models.ModifyReportLastViewTime(uid)
+		if e != nil {
+			err = errors.New("ModifyReportLastViewTime, Err: " + e.Error())
+			return
+		}
+		utils.Rc.Put(key, 1, 2*time.Second)
+	}
+	return
+}
+
+// 记录用户文章浏览记录带时长
+func ArticleHistoryStopTime(articleId, stopTime, outType int, user *models.WxUserItem) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("记录用户文章浏览记录带时长,失败"+err.Error(), 2)
+		}
+	}()
+	if stopTime < 3 {
+		return
+	}
+	uid := user.UserId
+
+	key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
+	if !utils.Rc.IsExist(key) {
+		record := new(models.CygxArticleHistoryRecordNewpv)
+		record.UserId = uid
+		record.ArticleId = articleId
+		record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
+		record.ModifyTime = time.Now()
+		record.Mobile = user.Mobile
+		record.Email = user.Email
+		record.CompanyId = user.CompanyId
+		record.CompanyName = user.CompanyName
+		record.StopTime = stopTime
+		record.OutType = outType
+		record.Source = "WEB"
+		_, e := models.AddCygxArticleViewRecordNewpv(record)
+		if e != nil {
+			err = errors.New("AddCygxArticleViewRecordNewpv, Err: " + e.Error())
+			return
+		}
+		utils.Rc.Put(key, 1, 2*time.Second)
+	}
+	go ArticleHistoryUserLabelLogAdd(articleId, uid)
+	return
+}

+ 5 - 0
services/industrial_management.go

@@ -299,6 +299,11 @@ func IndustryFllowWithTrack(industrialManagementId, count, uid int) (err error)
 	return err
 }
 
+func init() {
+	//IndustryFllowUserLabel(136, 16, 5660)
+	//UserLabelLogReduce()
+}
+
 // GetIndustryNewLabelMap 获取产业【新】标签Map
 func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error) {
 	labelMap = make(map[int]bool, 0)

+ 1 - 1
services/init_10.3.go

@@ -7,7 +7,7 @@ import (
 
 //10.3版本上线需要更新的数据
 
-func init1111() {
+func init51111() {
 	var condition string
 	var pars []interface{}
 	var err error

+ 457 - 0
services/init_10.5.1.go

@@ -0,0 +1,457 @@
+package services
+
+import (
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"time"
+)
+
+//10.5.1版本上线需要更新的数据
+
+func init1111() {
+	var condition string
+	var pars []interface{}
+	var err error
+	fmt.Print()
+
+	var topCond string
+	var topPars []interface{}
+	toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+	if err != nil {
+		return
+	}
+
+	mapIndustryName := make(map[int]string)
+	for _, v := range toplist {
+		mapIndustryName[v.IndustrialManagementId] = v.IndustryName
+	}
+	fmt.Println(mapIndustryName)
+	//处理上周纪要汇总
+	condition = ` AND  type = 1  `
+	list, err := models.GetCygxIndustryFllowListByCon(condition, pars, 0, 100000)
+	if err != nil {
+		fmt.Println(err)
+	}
+	var items []*models.CygxUserLabel
+	for _, user := range list {
+		item := new(models.CygxUserLabel)
+		item.UserId = user.UserId
+		item.CompanyId = user.CompanyId
+		item.RealName = user.RealName
+		item.Mobile = user.Mobile
+		item.Email = user.Email
+		item.Label = mapIndustryName[user.IndustrialManagementId]
+		item.SourceId = user.IndustrialManagementId
+		item.Source = 1
+		item.IsFollow = 1
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		items = append(items, item)
+		if len(items)%5000 == 0 {
+			err = models.CygxUserLabelMulti(items)
+			fmt.Println(err)
+			items = make([]*models.CygxUserLabel, 0)
+		}
+	}
+	if len(items) > 0 {
+		err = models.CygxUserLabelMulti(items)
+		fmt.Println(err, "555")
+	}
+}
+
+func init123() {
+	var condition string
+	var pars []interface{}
+	var err error
+	fmt.Print()
+
+	var topCond string
+	var topPars []interface{}
+	toplist, err := models.GetCygxReportMappingCygxByCon(topCond, topPars, 0, 0)
+	if err != nil {
+		return
+	}
+
+	mapIndustryName := make(map[int]string)
+	for _, v := range toplist {
+		mapIndustryName[v.Id] = v.MatchTypeName
+	}
+	fmt.Println(mapIndustryName)
+
+	condition = ` `
+	list, err := models.GetCygxXzsChooseCategoryListByCon(condition, pars, 0, 100000)
+	if err != nil {
+		fmt.Println(err)
+	}
+	var items []*models.CygxUserLabel
+	for _, user := range list {
+		if user.IdCygx == 0 {
+			continue
+		}
+		item := new(models.CygxUserLabel)
+		item.UserId = user.UserId
+		item.CompanyId = user.CompanyId
+		item.RealName = user.RealName
+		item.Mobile = user.Mobile
+		item.Email = user.Email
+		item.Label = mapIndustryName[user.IdCygx]
+		item.SourceId = user.IdCygx
+		item.Source = 2
+		item.IsFollow = 1
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		fmt.Println(item.SourceId)
+		items = append(items, item)
+		if len(items)%5000 == 0 {
+			err = models.CygxUserLabelMulti(items)
+			fmt.Println(err)
+			items = make([]*models.CygxUserLabel, 0)
+		}
+	}
+	if len(items) > 0 {
+		err = models.CygxUserLabelMulti(items)
+		fmt.Println(err, "555")
+	}
+}
+
+func init5333() {
+	var condition string
+	var pars []interface{}
+	var err error
+	fmt.Print()
+
+	var topCond string
+	var topPars []interface{}
+	toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+	if err != nil {
+		return
+	}
+
+	mapIndustryName := make(map[int]string)
+	for _, v := range toplist {
+		mapIndustryName[v.IndustrialManagementId] = v.IndustryName
+	}
+	fmt.Println(mapIndustryName)
+	condition = ` AND activity_time > '2022-11-25 00:00:00' AND publish_status = 1    `
+	listAct, err := models.GetCygxActivityList(condition, pars, 0, 100000)
+	if err != nil {
+		fmt.Println(err)
+	}
+	var items []*models.CygxUserLabelActivity
+	for _, v := range listAct {
+		fmt.Println(v.ActivityTime)
+		var condition1 string
+		var pars1 []interface{}
+		condition1 = ` AND activity_id = ?  `
+		pars1 = append(pars1, v.ActivityId)
+		total, e := models.GetCygxIndustrialActivityGroupManagementCount(condition1+"  AND  source = 1 ", pars1)
+		if e != nil {
+			fmt.Println(e)
+			return
+		}
+		if total == 0 {
+			continue
+		}
+		industrialList, e := models.GetCygxIndustrialActivityGroupManagementList(condition1+"  AND  source = 1 ", pars1)
+		if e != nil {
+			fmt.Println(e)
+			return
+		}
+
+		pars = make([]interface{}, 0)
+		condition = ` AND activity_id  = ? AND is_meeting = 1  `
+		pars = append(pars, v.ActivityId)
+		signUpList, err := models.GetSignupDetailBySignup(condition, pars)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			return
+		}
+		for _, vi := range industrialList {
+			for _, user := range signUpList {
+				item := new(models.CygxUserLabelActivity)
+				item.UserId = user.UserId
+				item.CompanyId = user.CompanyId
+				item.RealName = user.RealName
+				item.Mobile = user.Mobile
+				item.Email = user.Email
+				item.ActivityId = v.ActivityId
+				item.IndustrialManagementId = vi.IndustrialManagementId
+				item.Label = mapIndustryName[vi.IndustrialManagementId]
+				item.CreateTime = utils.StrTimeToTime(v.ActivityTime)
+				item.ModifyTime = time.Now()
+				items = append(items, item)
+				if len(items)%5000 == 0 {
+					_, err = models.AddCygxUserLabelActivityList(items)
+					fmt.Println(err)
+					items = make([]*models.CygxUserLabelActivity, 0)
+				}
+			}
+		}
+	}
+	fmt.Println(len(items))
+	if len(items) > 0 {
+		_, err = models.AddCygxUserLabelActivityList(items)
+		fmt.Println(err, "555")
+	}
+}
+
+func init5444() {
+	var condition string
+	var pars []interface{}
+	var err error
+	fmt.Print()
+
+	var topCond string
+	var topPars []interface{}
+	toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+	if err != nil {
+		return
+	}
+
+	mapIndustryName := make(map[int]string)
+	for _, v := range toplist {
+		mapIndustryName[v.IndustrialManagementId] = v.IndustryName
+	}
+	fmt.Println(mapIndustryName)
+	condition = ` AND is_meeting = 1  `
+	listAct, err := models.GetCygxActivitySpecialmeetingDetailList(condition, pars)
+	if err != nil {
+		fmt.Println(err)
+	}
+	var items []*models.CygxUserLabelActivitySpecial
+	for _, user := range listAct {
+		var condition1 string
+		var pars1 []interface{}
+		condition1 = ` AND activity_id = ?  `
+		pars1 = append(pars1, user.ActivityId)
+		total, e := models.GetCygxIndustrialActivityGroupManagementCount(condition1+"  AND  source = 2 ", pars1)
+		if e != nil {
+			fmt.Println(e)
+			return
+		}
+		if total == 0 {
+			continue
+		}
+		industrialList, e := models.GetCygxIndustrialActivityGroupManagementList(condition1+"  AND  source = 2 ", pars1)
+		if e != nil {
+			fmt.Println(e)
+			return
+		}
+		for _, vi := range industrialList {
+			item := new(models.CygxUserLabelActivitySpecial)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.ActivityId = user.ActivityId
+			item.IndustrialManagementId = vi.IndustrialManagementId
+			item.Label = mapIndustryName[vi.IndustrialManagementId]
+			item.CreateTime = utils.StrTimeToTime(user.CreateTime)
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+			if len(items)%5000 == 0 {
+				_, err = models.AddCygxUserLabelActivitySpecialList(items)
+				fmt.Println(err)
+				items = make([]*models.CygxUserLabelActivitySpecial, 0)
+			}
+		}
+	}
+	fmt.Println(len(items))
+	if len(items) > 0 {
+		_, err = models.AddCygxUserLabelActivitySpecialList(items)
+		fmt.Println(err, "555")
+	}
+}
+
+func init5555() {
+	var condition string
+	var pars []interface{}
+	var err error
+	fmt.Print()
+
+	var topCond string
+	var topPars []interface{}
+	toplist, err := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+	if err != nil {
+		return
+	}
+
+	mapIndustryName := make(map[int]string)
+	for _, v := range toplist {
+		mapIndustryName[v.IndustrialManagementId] = v.IndustryName
+	}
+	//fmt.Println(mapIndustryName)
+	condition = ` AND   stop_time > 3  AND create_time > '2022-11-25 00:00:00' GROUP BY article_id  `
+	//condition = `   AND   stop_time > 4   AND create_time > '2023-04-25 00:00:00' GROUP BY article_id  `
+	listArtGroup, err := models.GetCygxArticleHistoryRecordNewpvList(condition, pars)
+	if err != nil {
+		fmt.Println(err)
+	}
+	fmt.Println(len(listArtGroup))
+	var source int
+
+	itemsMap := make(map[int][]*models.CygxUserLabel)
+	for _, v := range listArtGroup {
+
+		fmt.Println(v.ArticleId)
+		var items []*models.CygxUserLabel
+		articleId := v.ArticleId
+		var condition string
+		var pars []interface{}
+		condition = ` AND article_id = ? `
+		pars = append(pars, v.ArticleId)
+		industrialList, e := models.GetIndustrialArticleGroupManagementList(condition, pars)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			fmt.Println(e)
+			continue
+			//return
+		}
+		if len(industrialList) == 0 {
+			//如果没有行产业归类就按照行业报告处理
+			source = 2
+			detailArticle, e := models.GetArticleDetailById(articleId)
+			if e != nil {
+				fmt.Println(e)
+				continue
+				//return
+			}
+
+			labelDetail, e := models.GetdetailByCategoryIdLabel(detailArticle.CategoryId)
+			if e != nil {
+				fmt.Println(e)
+				continue
+				//return
+			}
+			label := labelDetail.MatchTypeName
+			industrialManagementId := labelDetail.Id
+			item := new(models.CygxUserLabel)
+
+			item.Label = label
+			item.SourceId = industrialManagementId
+			item.Source = source
+			item.Weight = 1
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+		} else {
+			//如果有行产业归类就按照产业报告处理
+			var topCond string
+			var topPars []interface{}
+			var industrialManagementIds []int
+
+			for _, v := range industrialList {
+				industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
+			}
+			idsLen := len(industrialManagementIds)
+			if idsLen > 0 {
+				topCond = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(idsLen) + `)`
+				topPars = append(topPars, industrialManagementIds)
+			} else {
+				continue
+			}
+			industrNamelist, e := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+			if e != nil {
+				fmt.Println(e)
+				continue
+			}
+			source = 1
+			for _, v := range industrNamelist {
+				label := v.IndustryName
+				industrialManagementId := v.IndustrialManagementId
+
+				item := new(models.CygxUserLabel)
+				item.Label = label
+				item.SourceId = industrialManagementId
+				item.Source = source
+				item.Weight = 1
+				item.CreateTime = time.Now()
+				item.ModifyTime = time.Now()
+				items = append(items, item)
+
+			}
+
+			//for _, vi := range industrialList {
+			//	for _, user := range signUpList {
+			//		item := new(models.CygxUserLabelActivity)
+			//		item.UserId = user.UserId
+			//		item.CompanyId = user.CompanyId
+			//		item.RealName = user.RealName
+			//		item.Mobile = user.Mobile
+			//		item.Email = user.Email
+			//		item.ActivityId = v.ActivityId
+			//		item.IndustrialManagementId = vi.IndustrialManagementId
+			//		item.Label = mapIndustryName[vi.IndustrialManagementId]
+			//		item.CreateTime = utils.StrTimeToTime(v.ActivityTime)
+			//		item.ModifyTime = time.Now()
+			//		items = append(items, item)
+			//		if len(items)%50 == 0 {
+			//			_, err = models.AddCygxUserLabelActivityList(items)
+			//			fmt.Println(err)
+			//			items = make([]*models.CygxUserLabelActivity, 0)
+			//		}
+			//	}
+			//}
+			itemsMap[articleId] = items
+		}
+	}
+	condition = `   AND   stop_time > 3   AND create_time > '2022-11-25 00:00:00'   `
+	//condition = `  AND   stop_time > 4    AND create_time > '2023-4-25 00:00:00'   `
+	listArt, err := models.GetCygxArticleHistoryRecordNewpvList(condition, pars)
+	if err != nil {
+		fmt.Println(err)
+	}
+	var items []*models.CygxUserLabelArticle
+
+	fmt.Println(len(listArt))
+
+	for _, user := range listArt {
+		if len(itemsMap[user.ArticleId]) > 0 {
+			for k2, vlsit := range itemsMap {
+				if k2 != user.ArticleId {
+					continue
+				}
+				for _, vm := range vlsit {
+
+					//if user.ArticleId == 8365 {
+					//	fmt.Println("k", k, "_k2:", k2, "_k3:", k3)
+					//	fmt.Println(vm.Label)
+					//}
+					item := new(models.CygxUserLabelArticle)
+					item.UserId = user.UserId
+					item.ArticleId = user.ArticleId
+					item.CompanyId = user.CompanyId
+					//item.RealName = user.R
+					item.Mobile = user.Mobile
+					item.Email = user.Email
+					item.Label = vm.Label
+					item.SourceId = vm.SourceId
+					item.Source = vm.Source
+					item.CreateTime = user.CreateTime
+					item.ModifyTime = time.Now()
+					items = append(items, item)
+					if len(items)%5000 == 0 {
+						_, err = models.AddCygxUserLabelArticleList(items)
+						fmt.Println(err)
+						items = make([]*models.CygxUserLabelArticle, 0)
+					}
+				}
+			}
+		}
+	}
+	//for k, vlsit := range itemsMap[8365] {
+	//	fmt.Println(k)
+	//	fmt.Println(vlsit)
+	//	//for _, vm := range vlsit {
+	//	//	fmt.Println(vm)
+	//	//}
+	//}
+	fmt.Println(len(items))
+	fmt.Println(len(itemsMap))
+	fmt.Println((itemsMap))
+	fmt.Println(len(items))
+	if len(items) > 0 {
+		_, err = models.AddCygxUserLabelArticleList(items)
+		fmt.Println(err, "555")
+	}
+}

+ 2 - 0
services/task.go

@@ -125,6 +125,8 @@ func Task() {
 		getArticleListByApi := task.NewTask("getArticleListByApi", "0 */60 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章
 		task.AddTask("getArticleListByApi", getArticleListByApi)
 	}
+
+	go UserLabelLogReduce() // 处理用户标签的队列消息
 	//GetCygxActivityAttendanceDetail()
 	//CreateIndexNameArticleHistory()
 	//AddAllArticleHistory()

+ 1001 - 0
services/user_label.go

@@ -0,0 +1,1001 @@
+package services
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"strconv"
+	"strings"
+	"time"
+)
+
+func init() {
+
+	//ArticleHistoryUserLabelLogAdd(8350, 53095)
+	//UserLabelLogReduce()
+	//var mobileArr []string
+	//mobileArr = append(mobileArr, "15557270714")
+	//ActivityUserLabelLogAdd(2239, mobileArr)
+
+	//UserLabelLogReduce()
+}
+
+// 添加用户阅读标签到Redis
+func ArticleHistoryUserLabelLogAdd(articleId, uid int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			msg := fmt.Sprint("articleId:", articleId, "userId:", uid)
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
+		}
+	}()
+	// SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。
+	log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: articleId, SourceType: 1, CreateTime: time.Now()}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
+		if err != nil {
+			fmt.Println("CygxUserLabelLogRedis LPush Err:" + err.Error())
+		}
+	}
+	return
+}
+
+// 添加用户2产业关注标签到Redis
+func IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
+	var isFllow int
+	if count == 0 {
+		isFllow = 1
+	} else {
+		isFllow = 0
+	}
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
+		}
+	}()
+	log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 2, IsFllow: isFllow, CreateTime: time.Now()}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
+		if err != nil {
+			fmt.Println("RecordNewLogs LPush Err:" + err.Error())
+		}
+	}
+	return
+}
+
+// 添加用户活动到会标签到Redis
+func ActivityUserLabelLogAdd(activityId int, mobileArr []string) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			msg := fmt.Sprint("activityId:", activityId, "mobile:", mobileArr)
+			go utils.SendAlarmMsg("添加用户活动到会标签到Redis,写入Redis队列消息失败:"+err.Error()+msg, 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition = ` AND activity_id = ?  `
+	pars = append(pars, activityId)
+	total, e := models.GetCygxIndustrialActivityGroupManagementCount(condition+"  AND  source = 1 ", pars)
+	if e != nil {
+		err = errors.New("GetCygxIndustrialActivityGroupManagementCount" + e.Error())
+		return
+	}
+	if total == 0 {
+		//没有关联产业的活动不做标签处理
+		return
+	}
+
+	industrialList, e := models.GetCygxIndustrialActivityGroupManagementList(condition+"  AND  source = 1 ", pars)
+	if e != nil {
+		err = errors.New("GetCygxIndustrialActivityGroupManagementList, Err: " + e.Error())
+		return
+	}
+
+	//如果有行产业归类就按照产业报告处理
+	var topCond string
+	var topPars []interface{}
+	var industrialManagementIds []int
+
+	for _, v := range industrialList {
+		industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
+	}
+	idsLen := len(industrialManagementIds)
+	if idsLen > 0 {
+		topCond = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(idsLen) + `)`
+		topPars = append(topPars, industrialManagementIds)
+	} else {
+		return
+	}
+	industrNamelist, e := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+	if e != nil {
+		err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
+		return
+	}
+
+	userList, e := models.GetWxUserByOutboundMobiles(mobileArr)
+	if e != nil {
+		err = errors.New("GetWxUserByOutboundMobiles" + e.Error())
+		return
+	}
+	listActivityHistory, e := models.GetCygxUserLabelActivity(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxUserLabelActivity" + e.Error())
+		return
+	}
+	activityHistoryMap := make(map[int]bool)
+	for _, v := range listActivityHistory {
+		activityHistoryMap[v.UserId] = true
+	}
+	var items []*models.CygxUserLabelActivity
+	for _, user := range userList {
+		//已经提交到会的活动写入标签的不做二次添加处理
+		if activityHistoryMap[user.UserId] {
+			continue
+		}
+		// SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。
+		log := &models.CygxUserLabelLogRedis{UserId: user.UserId, SourceId: activityId, SourceType: 3, CreateTime: time.Now()}
+		if utils.Re == nil {
+			err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
+			if err != nil {
+				fmt.Println("CygxUserLabelLogRedis LPush Err:" + err.Error())
+			}
+		}
+		for _, industr := range industrNamelist {
+			item := new(models.CygxUserLabelActivity)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.ActivityId = activityId
+			item.IndustrialManagementId = industr.IndustrialManagementId
+			item.Label = industr.IndustryName
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+		}
+	}
+	if len(items) > 0 {
+		_, err = models.AddCygxUserLabelActivityList(items)
+	}
+	return
+}
+
+func UserLabelLogReduce() (err error) {
+	for {
+		//SourceType int       `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
+		utils.Rc.Brpop(utils.CYGX_USER_KEY_LABEL, func(b []byte) {
+			var log models.CygxUserLabelLogRedis
+			if err := json.Unmarshal(b, &log); err != nil {
+				fmt.Println("json unmarshal wrong!")
+				go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+err.Error()+string(b), 2)
+			}
+			switch log.SourceType {
+			case 1:
+				go ArticleHistoryUserLabelLogReduce(log)
+				fmt.Println("文章阅读")
+				break
+			case 2:
+				go IndustryFllowUserLabelLogReduce(log)
+				fmt.Println("2产业关注")
+				break
+			case 3:
+				go ActivityUserLabelLogReduce(log)
+				fmt.Println("活动到会")
+				break
+			case 4:
+				go CategoryFllowUserLabelLogReduce(log)
+				fmt.Println("4系列关注")
+				break
+			case 5:
+				go ActivitySpecialUserLabelLogReduce(log)
+				fmt.Println("5专项调研活动到会")
+				break
+			default:
+				fmt.Println(string(b))
+				go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+string(b), 2)
+			}
+		})
+	}
+}
+
+// 1:文章阅读
+func ArticleHistoryUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("用户文章阅读更新相关标签,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("articleId", log.SourceId, "userId", log.UserId), 2)
+		}
+	}()
+
+	articleId := log.SourceId
+	userId := log.UserId
+	var source int
+	user, e := models.GetWxUserItemByUserId(userId)
+	if e != nil {
+		err = errors.New("GetWxUserItemByUserId" + e.Error())
+		return
+	}
+	var condition string
+	var pars []interface{}
+	condition = ` AND article_id = ? `
+	pars = append(pars, articleId)
+	industrialList, e := models.GetIndustrialArticleGroupManagementList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetIndustrialArticleGroupManagementList, Err: " + e.Error())
+		return
+	}
+	var items []*models.CygxUserLabel
+	if len(industrialList) == 0 {
+		//如果没有行产业归类就按照行业报告处理
+		source = 2
+		detailArticle, e := models.GetArticleDetailById(articleId)
+		if e != nil {
+			err = errors.New("GetArticleDetailById, Err: " + e.Error())
+			return
+		}
+
+		labelDetail, e := models.GetdetailByCategoryIdLabel(detailArticle.CategoryId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("GetdetailByCategoryIdLabel, Err: " + e.Error())
+			return
+		}
+		if labelDetail == nil {
+			return
+		}
+		label := labelDetail.MatchTypeName
+		industrialManagementId := labelDetail.Id
+		var condition string
+		var pars []interface{}
+		condition += ` AND source_id=? AND source = ?  AND  user_id = ?  `
+		pars = append(pars, industrialManagementId, source, userId)
+		total, e := models.GetCygxUserLabelCount(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxProductInteriorCount" + e.Error())
+			return
+		}
+		item := new(models.CygxUserLabel)
+		item.UserId = user.UserId
+		item.CompanyId = user.CompanyId
+		item.RealName = user.RealName
+		item.Mobile = user.Mobile
+		item.Email = user.Email
+		item.Label = label
+		item.SourceId = industrialManagementId
+		item.Source = source
+		item.Weight = 1
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		items = append(items, item)
+		if total == 0 {
+			_, e = models.AddCygxUserLabel(item)
+			if e != nil {
+				err = errors.New("AddCygxUserLabel" + e.Error())
+				return
+			}
+		} else {
+			//source 来源1:产业、2:系列
+			e = models.UpdateCygxUserLabelWeight(industrialManagementId, source, userId, label)
+			if e != nil {
+				err = errors.New("UpdateCygxUserLabelWeight" + e.Error())
+				return
+			}
+		}
+	} else {
+		//如果有行产业归类就按照产业报告处理
+		var topCond string
+		var topPars []interface{}
+		var industrialManagementIds []int
+
+		for _, v := range industrialList {
+			industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
+		}
+		idsLen := len(industrialManagementIds)
+		if idsLen > 0 {
+			topCond = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(idsLen) + `)`
+			topPars = append(topPars, industrialManagementIds)
+		} else {
+			return
+		}
+		industrNamelist, e := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+		if e != nil {
+			err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
+			return
+		}
+		source = 1
+		for _, v := range industrNamelist {
+			label := v.IndustryName
+			industrialManagementId := v.IndustrialManagementId
+			var condition string
+			var pars []interface{}
+			condition += ` AND source_id=? AND source = ?  AND  user_id = ?  `
+			pars = append(pars, v.IndustrialManagementId, source, userId)
+			total, e := models.GetCygxUserLabelCount(condition, pars)
+			if e != nil {
+				err = errors.New("GetCygxProductInteriorCount" + e.Error())
+				return
+			}
+			item := new(models.CygxUserLabel)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.Label = label
+			item.SourceId = industrialManagementId
+			item.Source = source
+			item.Weight = 1
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+			if total == 0 {
+				_, e = models.AddCygxUserLabel(item)
+				if e != nil {
+					err = errors.New("AddCygxUserLabel" + e.Error())
+					return
+				}
+			} else {
+				//source 来源1:产业、2:系列
+				e = models.UpdateCygxUserLabelWeight(industrialManagementId, source, userId, label)
+				if e != nil {
+					err = errors.New("UpdateCygxUserLabelWeight" + e.Error())
+					return
+				}
+			}
+		}
+	}
+	if len(items) > 0 {
+		go AddArticleHistoryUserLabelLog(items, articleId)
+	}
+	updateUserLabelByUserId(userId)
+	return
+}
+
+// 添加文章阅读记录日志,处理文章阅读三个月之内标签权重有效逻辑
+func AddArticleHistoryUserLabelLog(items []*models.CygxUserLabel, articleId int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("添加文章阅读记录日志,处理文章阅读三个月之内标签权重有效逻辑失败:"+err.Error(), 2)
+		}
+	}()
+	if len(items) == 0 {
+		return
+	}
+	for _, v := range items {
+		item := new(models.CygxUserLabelArticle)
+		item.UserId = v.UserId
+		item.CompanyId = v.CompanyId
+		item.RealName = v.RealName
+		item.Mobile = v.Mobile
+		item.Email = v.Email
+		item.Label = v.Label
+		item.SourceId = v.SourceId
+		item.Source = v.Source
+		item.ArticleId = articleId
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		_, e := models.AddCygxUserLabelArticle(item)
+		if e != nil {
+			err = errors.New("AddCygxUserLabelArticle" + e.Error())
+			return
+		}
+	}
+	return
+}
+
+// 2:产业关注
+func IndustryFllowUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,处理Redis队列消息失败:"+err.Error(), 2)
+		}
+	}()
+	isFllow := log.IsFllow
+	industrialManagementId := log.SourceId
+	userId := log.UserId
+	source := 1
+	detailIndustrial, e := models.GetIndustrialManagementDetail(industrialManagementId)
+	if e != nil {
+		err = errors.New("GetIndustrialManagementDetail" + e.Error())
+		return
+	}
+	label := detailIndustrial.IndustryName
+	if isFllow == 0 {
+		e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, source, userId, label)
+		if e != nil {
+			err = errors.New("UpdateCygxUserLabelIsFollow" + e.Error())
+			return
+		}
+	} else {
+		var condition string
+		var pars []interface{}
+		condition += ` AND source_id=? AND source = ?   AND user_id = ?`
+		pars = append(pars, industrialManagementId, source, userId)
+		total, e := models.GetCygxUserLabelCount(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxProductInteriorCount" + e.Error())
+			return
+		}
+		if total == 0 {
+			user, e := models.GetWxUserItemByUserId(userId)
+			if e != nil {
+				err = errors.New("GetWxUserItemByUserId" + e.Error())
+				return
+			}
+			item := new(models.CygxUserLabel)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.Label = label
+			item.SourceId = industrialManagementId
+			item.Source = source
+			item.IsFollow = isFllow
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			_, e = models.AddCygxUserLabel(item)
+			if e != nil {
+				err = errors.New("AddCygxUserLabel" + e.Error())
+				return
+			}
+		} else {
+			//source 来源1:产业、2:系列
+			e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, source, userId, label)
+			if e != nil {
+				err = errors.New("UpdateCygxUserLabelIsFollow" + e.Error())
+				return
+			}
+		}
+	}
+	updateUserLabelByUserId(userId)
+	return
+}
+
+// 3:活动到会
+func ActivityUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("用户活动到会更新相关标签,处理Redis队列消息失败:"+err.Error(), 2)
+		}
+	}()
+
+	activityId := log.SourceId
+	userId := log.UserId
+	var source int
+	user, e := models.GetWxUserItemByUserId(userId)
+	if e != nil {
+		err = errors.New("GetWxUserItemByUserId" + e.Error())
+		return
+	}
+	var condition string
+	var pars []interface{}
+	condition = ` AND activity_id = ?  `
+	pars = append(pars, activityId)
+	industrialList, e := models.GetCygxIndustrialActivityGroupManagementList(condition+"  AND  source = 1 ", pars)
+	if e != nil {
+		err = errors.New("GetCygxIndustrialActivityGroupManagementList, Err: " + e.Error())
+		return
+	}
+
+	//如果有行产业归类就按照产业报告处理
+	var topCond string
+	var topPars []interface{}
+	var industrialManagementIds []int
+
+	for _, v := range industrialList {
+		industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
+	}
+	idsLen := len(industrialManagementIds)
+	if idsLen > 0 {
+		topCond = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(idsLen) + `)`
+		topPars = append(topPars, industrialManagementIds)
+	} else {
+		return
+	}
+	industrNamelist, e := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+	if e != nil {
+		err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
+		return
+	}
+
+	source = 1
+	for _, v := range industrNamelist {
+		label := v.IndustryName
+		industrialManagementId := v.IndustrialManagementId
+		var condition string
+		var pars []interface{}
+		condition += ` AND source_id=? AND source = ?  AND  user_id = ?  `
+		pars = append(pars, v.IndustrialManagementId, source, userId)
+		total, e := models.GetCygxUserLabelCount(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxProductInteriorCount" + e.Error())
+			return
+		}
+		if total == 0 {
+			item := new(models.CygxUserLabel)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.Label = label
+			item.SourceId = industrialManagementId
+			item.Source = source
+			item.Weight = 1
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			_, e = models.AddCygxUserLabel(item)
+			if e != nil {
+				err = errors.New("AddCygxUserLabel" + e.Error())
+				return
+			}
+		} else {
+			//source 来源1:产业、2:系列
+			e = models.UpdateCygxUserLabelWeight(industrialManagementId, source, userId, label)
+			if e != nil {
+				err = errors.New("UpdateCygxUserLabelWeight" + e.Error())
+				return
+			}
+		}
+	}
+	updateUserLabelByUserId(userId)
+	return
+}
+
+// 4:系列关注
+func CategoryFllowUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("用户关注系列更新相关标签,处理Redis队列消息失败:"+err.Error(), 2)
+		}
+	}()
+	isFllow := log.IsFllow
+	industrialManagementId := log.SourceId
+	userId := log.UserId
+	source := 2
+	detailIndustrial, e := models.GetCygxReportMappingById(industrialManagementId)
+	if e != nil {
+		err = errors.New("GetCygxReportMappingById" + e.Error())
+		return
+	}
+	label := detailIndustrial.MatchTypeName
+	if isFllow == 0 {
+		e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, source, userId, label)
+		if e != nil {
+			err = errors.New("UpdateCygxUserLabelIsFollow" + e.Error())
+			return
+		}
+	} else {
+		var condition string
+		var pars []interface{}
+		condition += ` AND source_id=? AND source = ?   AND user_id = ?`
+		pars = append(pars, industrialManagementId, source, userId)
+		total, e := models.GetCygxUserLabelCount(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxProductInteriorCount" + e.Error())
+			return
+		}
+		if total == 0 {
+			user, e := models.GetWxUserItemByUserId(userId)
+			if e != nil {
+				err = errors.New("GetWxUserItemByUserId" + e.Error())
+				return
+			}
+			item := new(models.CygxUserLabel)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.Label = label
+			item.SourceId = industrialManagementId
+			item.Source = source
+			item.IsFollow = isFllow
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			_, e = models.AddCygxUserLabel(item)
+			if e != nil {
+				err = errors.New("AddCygxUserLabel" + e.Error())
+				return
+			}
+		} else {
+			//source 来源1:产业、2:系列
+			e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, source, userId, label)
+			if e != nil {
+				err = errors.New("UpdateCygxUserLabelIsFollow" + e.Error())
+				return
+			}
+		}
+	}
+	updateUserLabelByUserId(userId)
+	return
+}
+
+// 5:专项调研活动到会
+func ActivitySpecialUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("用户活动到会更新相关标签,处理Redis队列消息失败:"+err.Error(), 2)
+		}
+	}()
+
+	activityId := log.SourceId
+	userId := log.UserId
+	var source int
+	user, e := models.GetWxUserItemByUserId(userId)
+	if e != nil {
+		err = errors.New("GetWxUserItemByUserId" + e.Error())
+		return
+	}
+	var condition string
+	var pars []interface{}
+	condition = ` AND activity_id = ?  `
+	pars = append(pars, activityId)
+	industrialList, e := models.GetCygxIndustrialActivityGroupManagementList(condition+"  AND  source = 2 ", pars)
+	if e != nil {
+		err = errors.New("GetCygxIndustrialActivityGroupManagementList, Err: " + e.Error())
+		return
+	}
+
+	//如果有行产业归类就按照产业报告处理
+	var topCond string
+	var topPars []interface{}
+	var industrialManagementIds []int
+
+	for _, v := range industrialList {
+		industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
+	}
+	idsLen := len(industrialManagementIds)
+	if idsLen > 0 {
+		topCond = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(idsLen) + `)`
+		topPars = append(topPars, industrialManagementIds)
+	} else {
+		return
+	}
+	industrNamelist, e := models.GetTopOneMonthArtReadNumIndustryAll(topCond, topPars)
+	if e != nil {
+		err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
+		return
+	}
+
+	source = 1
+	for _, v := range industrNamelist {
+		label := v.IndustryName
+		industrialManagementId := v.IndustrialManagementId
+		var condition string
+		var pars []interface{}
+		condition += ` AND source_id=? AND source = ?  AND  user_id = ?  `
+		pars = append(pars, v.IndustrialManagementId, source, userId)
+		total, e := models.GetCygxUserLabelCount(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxProductInteriorCount" + e.Error())
+			return
+		}
+		if total == 0 {
+			item := new(models.CygxUserLabel)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.Label = label
+			item.SourceId = industrialManagementId
+			item.Source = source
+			item.Weight = 1
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			_, e = models.AddCygxUserLabel(item)
+			if e != nil {
+				err = errors.New("AddCygxUserLabel" + e.Error())
+				return
+			}
+		} else {
+			//source 来源1:产业、2:系列
+			e = models.UpdateCygxUserLabelWeight(industrialManagementId, source, userId, label)
+			if e != nil {
+				err = errors.New("UpdateCygxUserLabelWeight" + e.Error())
+				return
+			}
+		}
+	}
+	updateUserLabelByUserId(userId)
+	return
+}
+
+//func init() {
+//	var condition string
+//	var pars []interface{}
+//	pars = make([]interface{}, 0)
+//	condition = ` GROUP BY user_id`
+//	listUser, _ := models.GetCygxUserLabelList(condition, pars)
+//	for k, v := range listUser {
+//		fmt.Println(k)
+//		updateUserLabelByUserId(v.UserId)
+//	}
+//	//updateUserLabelByUserId(13269)
+//}
+
+// 更新用户标签
+func updateUserLabelByUserId(userId int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			utils.FileLog.Info("更新用户标签,Err:%s", err.Error(), userId)
+			go utils.SendAlarmMsg("更新用户标签失败:"+err.Error()+"userId:"+strconv.Itoa(userId), 2)
+		}
+	}()
+	time.Sleep(1 * time.Second)
+	var condition string
+	var pars []interface{}
+	condition = ` AND is_follow=1  AND  user_id = ?  `
+	pars = append(pars, userId)
+	totalSource1, e := models.GetCygxUserLabelCount(condition+" AND source = 1 ", pars)
+	if e != nil {
+		err = errors.New("GetCygxProductInteriorCount" + e.Error())
+		return
+	}
+
+	totalSource2, e := models.GetCygxUserLabelCount(condition+" AND source = 2 ", pars)
+	if e != nil {
+		err = errors.New("GetCygxProductInteriorCount" + e.Error())
+		return
+	}
+	condition = `   AND  user_id = ?  `
+	var list []*models.CygxUserLabel
+	//当产业关注数量不超过10 ,系列关注数量不超过5
+	if totalSource1 <= 10 && totalSource2 <= 5 {
+		condition += `  	AND ( is_follow > 0 OR weight > 0 )  ORDER BY is_follow DESC, weight DESC  `
+		list, e = models.GetCygxUserLabelList(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxUserLabelList当产业关注数量不超过10 ,系列关注数量不超过5" + e.Error())
+			return
+		}
+	}
+
+	//当产业关注数量超过10 ,系列关注数量超过5
+	if totalSource1 > 10 && totalSource2 > 5 {
+		condition += `  AND  weight > 0 ORDER BY  weight DESC  `
+		list, e = models.GetCygxUserLabelList(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxUserLabelList 当产业关注数量超过10 ,系列关注数量超过5" + e.Error())
+			return
+		}
+	}
+	//当产业关注数量不超过10 ,系列关注数量超过5
+	if totalSource1 <= 10 && totalSource2 > 5 {
+		condition += `  AND  source = 1  AND is_follow = 1 ORDER BY  weight DESC  `
+		listfollow, e := models.GetCygxUserLabelList(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxUserLabelList" + e.Error())
+			return
+		}
+		idMap := make(map[int]bool)
+		for _, v := range listfollow {
+			idMap[v.Id] = true
+			list = append(list, v)
+		}
+		pars = make([]interface{}, 0)
+		condition = `  AND  user_id = ?  `
+		pars = append(pars, userId)
+		condition += ` 	AND  weight > 0   ORDER BY  weight DESC  `
+		listother, e := models.GetCygxUserLabelList(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxUserLabelList 当产业关注数量不超过10 ,系列关注数量超过5" + e.Error())
+			return
+		}
+		for _, v := range listother {
+			if idMap[v.Id] {
+				continue
+			}
+			list = append(list, v)
+		}
+	}
+
+	//当产业关注数量超过10 ,系列关注数量不超过5
+	if totalSource1 > 10 && totalSource2 <= 5 {
+		condition += `  AND  source = 2  AND is_follow = 1 ORDER BY  weight DESC  `
+		listfollow, e := models.GetCygxUserLabelList(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxUserLabelList 当产业关注数量超过10 ,系列关注数量不超过5" + e.Error())
+			return
+		}
+		idMap := make(map[int]bool)
+		for _, v := range listfollow {
+			idMap[v.Id] = true
+			list = append(list, v)
+		}
+		pars = make([]interface{}, 0)
+		condition = `  AND  user_id = ?  `
+		pars = append(pars, userId)
+		condition += ` 	AND  weight > 0   ORDER BY  weight DESC  `
+		listother, e := models.GetCygxUserLabelList(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxUserLabelList 当产业关注数量超过10 ,系列关注数量不超过5" + e.Error())
+			return
+		}
+		for _, v := range listother {
+			if idMap[v.Id] {
+				continue
+			}
+			list = append(list, v)
+		}
+	}
+
+	var labelUser string
+	for _, v := range list {
+		labelUser += v.Label + ","
+	}
+	labelUser = strings.TrimRight(labelUser, ",")
+	e = models.UpdateUserLabel(labelUser, userId)
+	if e != nil {
+		err = errors.New("UpdateUserLabel" + e.Error())
+		return err
+	}
+	return
+}
+
+//func init() {
+//	UpdateUserLabelWeight()
+//}
+
+// 更新用户标签权重
+func UpdateUserLabelWeight() (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("更新用户标签权重失败:"+err.Error(), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	list, e := models.GetCygxUserLabelList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxUserLabelList" + e.Error())
+		return
+	}
+	updateTime := time.Now().AddDate(0, -3, 0)
+	condition = ` AND create_time > ?`
+	pars = append(pars, updateTime)
+
+	listArticle, e := models.GetCygxUserLabelArticleList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxUserLabelArticleList" + e.Error())
+		return
+	}
+
+	listActivity, e := models.GetCygxUserLabelActivity(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxUserLabelActivity" + e.Error())
+		return
+	}
+
+	listActivitySpecial, e := models.GetCygxUserLabelActivitySpecial(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxUserLabelActivitySpecial" + e.Error())
+		return
+	}
+	userLabel := make(map[string]bool)
+	userLabelWeight := make(map[string]int)
+	for _, v := range list {
+		userLabel[fmt.Sprint("user_id{|}", v.UserId, "{|}source_id{|}", v.SourceId, "{|}source{|}", v.Source)] = true
+	}
+	fmt.Println(userLabel)
+	//处理文章标签
+	var items []*models.CygxUserLabel
+	for _, user := range listArticle {
+		if !userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.SourceId, "{|}source{|}", user.Source)] {
+			item := new(models.CygxUserLabel)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.Label = user.Label
+			item.SourceId = user.SourceId
+			item.Source = user.Source
+			item.CreateTime = user.CreateTime
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+			userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.SourceId, "{|}source{|}", user.Source)] = true
+		}
+		userLabelWeight[fmt.Sprint("user_id{|}", user.UserId, "{|}label{|}", user.Label)]++
+	}
+
+	//处理活动标签
+	for _, user := range listActivity {
+		if !userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.IndustrialManagementId, "{|}source{|}", 1)] {
+			item := new(models.CygxUserLabel)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.Label = user.Label
+			item.SourceId = user.IndustrialManagementId
+			item.Source = 1
+			item.CreateTime = user.CreateTime
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+			userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.IndustrialManagementId, "{|}source{|}", 1)] = true
+		}
+		userLabelWeight[fmt.Sprint("user_id{|}", user.UserId, "{|}label{|}", user.Label)]++
+	}
+
+	//处理专项调研活动标签
+	for _, user := range listActivitySpecial {
+		if !userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.IndustrialManagementId, "{|}source{|}", 1)] {
+			item := new(models.CygxUserLabel)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.Label = user.Label
+			item.SourceId = user.IndustrialManagementId
+			item.Source = 1
+			item.CreateTime = user.CreateTime
+			item.ModifyTime = time.Now()
+			items = append(items, item)
+			userLabel[fmt.Sprint("user_id{|}", user.UserId, "{|}source_id{|}", user.IndustrialManagementId, "{|}source{|}", 1)] = true
+		}
+		userLabelWeight[fmt.Sprint("user_id{|}", user.UserId, "{|}label{|}", user.Label)]++
+	}
+	var itemLimt []*models.CygxUserLabel
+	fmt.Println(len(items))
+	if len(items) > 0 {
+		for _, v := range items {
+			itemLimt = append(itemLimt, v)
+			if len(itemLimt)%5000 == 0 {
+				err = models.CygxUserLabelMulti(itemLimt)
+				fmt.Println(err)
+				itemLimt = make([]*models.CygxUserLabel, 0)
+			}
+		}
+	}
+	if len(itemLimt) > 0 {
+		err = models.CygxUserLabelMulti(itemLimt)
+		fmt.Println(err)
+	}
+	var itemsUpdate []*models.CygxUserLabel
+	for k, v := range userLabelWeight {
+		sliceUser := strings.Split(k, "{|}")
+		userid, _ := strconv.Atoi(sliceUser[1])
+		label := sliceUser[len(sliceUser)-1]
+		item := new(models.CygxUserLabel)
+		item.UserId = userid
+		item.Label = label
+		item.Weight = v
+		itemsUpdate = append(itemsUpdate, item)
+	}
+
+	e = models.UpdateCygxUserLabelWeightAll()
+	if e != nil {
+		err = errors.New("UpdateCygxUserLabelWeightAll" + e.Error())
+		return
+	}
+	fmt.Println(len(itemsUpdate))
+	e = models.UpdateCygxUserLabelMulti(itemsUpdate)
+	if e != nil {
+		err = errors.New("UpdateCygxUserLabelMulti" + e.Error())
+		return
+	}
+
+	pars = make([]interface{}, 0)
+	condition = ` GROUP BY user_id`
+	listUser, e := models.GetCygxUserLabelList(condition, pars)
+	for _, v := range listUser {
+		go updateUserLabelByUserId(v.UserId)
+	}
+	return
+}

+ 2 - 7
services/wechat_send_msg.go

@@ -105,17 +105,12 @@ func SendInterviewApplyCancelTemplateMsg(realName, companyName, mobile, articleT
 
 // 权限申请
 func SendPermissionApplyTemplateMsg(realName, companyName, mobile, applyMethod string, itemOpenid *models.OpenIdList) (err error) {
-	var msg string
+
 	defer func() {
 		if err != nil {
-			go utils.SendEmail("发送模版消息失败"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
-			go utils.SendAlarmMsg(fmt.Sprint("权限申请模板消息推送消息失败,手机号", mobile, "公司:", companyName, "手机号:", mobile), 2)
-		}
-		if msg != "" {
-			utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
+			go utils.SendAlarmMsg(fmt.Sprint("权限申请模板消息推送消息失败,手机号", mobile, "公司:", companyName, "手机号:", mobile, ";Err:"+err.Error()), 2)
 		}
 	}()
-
 	var first string
 	var keyword1 string
 	var keyword2 string

+ 11 - 42
services/wx_template_msg.go

@@ -45,7 +45,8 @@ func SendWxMsgWithFrequency(keyword2, activityName, reserveResults, activityTime
 }
 
 // 专项调研活动预开始消息通知
-func SendWxMsgWithFrequencySpecial(first, activityName, reserveResults, activityTime, activityAddress, remark string, openIdList []*models.OpenIdList, activityId int) (err error) {
+// func SendWxMsgWithFrequencySpecial(first, activityName, reserveResults, activityTime, activityAddress, remark string, openIdList []*models.OpenIdList, activityId int) (err error) {
+func SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark string, openIdList []*models.OpenIdList, activityId int) (err error) {
 	var msg string
 	defer func() {
 		if err != nil {
@@ -53,38 +54,6 @@ func SendWxMsgWithFrequencySpecial(first, activityName, reserveResults, activity
 			utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
 		}
 	}()
-	//accessToken, err := models.GetWxAccessTokenByXzs()
-	//if err != nil {
-	//	msg = "GetWxAccessToken Err:" + err.Error()
-	//	return
-	//}
-	//if accessToken == "" {
-	//	msg = "accessToken is empty"
-	//	return
-	//}
-	//
-	//sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
-	//templateId := utils.WxMsgTemplateIdActivityApplyXzs
-	//sendMap := make(map[string]interface{})
-	//sendData := make(map[string]interface{})
-	//sendMap["template_id"] = templateId
-	//sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxAppId, "pagepath": utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)}
-	//sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
-	//sendData["keyword1"] = map[string]interface{}{"value": activityName, "color": "#173177"}
-	//sendData["keyword2"] = map[string]interface{}{"value": activityTime, "color": "#173177"}
-	//sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
-	//sendMap["data"] = sendData
-	//WxSendTemplateMsg(sendUrl, sendMap, openIdList, strconv.Itoa(activityId), utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD)
-
-	//var first string
-	var keyword1 string
-	var keyword2 string
-	var keyword3 string
-	var keyword4 string
-
-	first = ""
-	keyword1 = activityName
-	keyword3 = activityTime
 	openIdArr := make([]string, 0)
 	for _, v := range openIdList {
 		openIdArr = append(openIdArr, v.OpenId)
@@ -104,7 +73,6 @@ func SendWxMsgWithFrequencySpecial(first, activityName, reserveResults, activity
 	sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
 	sendInfo.OpenIdArr = openIdArr
 	err = PublicSendTemplateMsg(sendInfo)
-
 	return
 }
 
@@ -425,7 +393,14 @@ func SendActivityAskApplyTemplateMsgV2(keyword1, keyword2, keyword3, keyword4, r
 
 	activityId := itemAct.ActivityId
 	var redirectUrl string
-	redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
+	//redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(activityId)
+	//mapSource留言跳转类型,1:文章、2:活动、3:微路演视频、4:活动视频、5:活动音频
+	//if utils.RunMode != "release" {
+	//
+	//} else {
+	//
+	//}
+	redirectUrl = utils.WX_MSG_PATH_TEMPLATE_MSG + "SourceId=" + strconv.Itoa(msgId) + "&SourceType=2"
 	openIdArr := make([]string, 0)
 	openIdArr = append(openIdArr, itemOpenid.OpenId)
 	sendInfo := new(SendWxTemplate)
@@ -433,19 +408,13 @@ func SendActivityAskApplyTemplateMsgV2(keyword1, keyword2, keyword3, keyword4, r
 	sendInfo.Keyword2 = keyword2
 	sendInfo.Keyword3 = keyword3
 	sendInfo.Keyword4 = keyword4
+	sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
 	sendInfo.Remark = remark
 	sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
 	sendInfo.RedirectUrl = redirectUrl
 	sendInfo.RedirectTarget = 3
 	sendInfo.Resource = strconv.Itoa(activityId)
 
-	//mapSource留言跳转类型,1:文章、2:活动、3:微路演视频、4:活动视频、5:活动音频
-	if utils.RunMode != "release" {
-		sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD
-	} else {
-		redirectUrl = utils.WX_MSG_PATH_TEMPLATE_MSG + "SourceId=" + strconv.Itoa(msgId) + "&SourceType=2"
-	}
-
 	sendInfo.OpenIdArr = openIdArr
 	err = PublicSendTemplateMsg(sendInfo)
 	return

+ 167 - 168
services/wx_user.go

@@ -5,7 +5,6 @@ import (
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
-	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -15,8 +14,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 	defer func() {
 		if err != nil {
 			go utils.SendAlarmMsg("更新用户标签失败;Err:"+err.Error(), 2)
-			go utils.SendEmail("更新用户标签失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), ";Err:"+err.Error(), utils.EmailSendToUsers)
-			utils.FileLog.Info("更新用户标签失败,Err:%s", err.Error())
 		}
 	}()
 	//获取需要处理的权益客户
@@ -25,7 +22,6 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 		fmt.Println("GetUserRegisterList Err", err)
 		return err
 	}
-
 	mapChartCollect := make(map[string]int)
 	//获取已经处理记录的用户并记录切片
 	listChartCollectL, err := models.GetCygxChartCollectList()
@@ -336,170 +332,170 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 	}
 
 	//处理用户标签
-	for _, vUser := range listUser {
-		labels, err := models.GetCygxCompanyUserListSplit(strconv.Itoa(vUser.UserId))
-		if err != nil {
-			fmt.Println("GetCygxCompanyUserListSplit Err", err)
-			return err
-		}
-		mapLabels := make(map[string]string)
-		var labelsListStr []*models.UserLabel
-		mapActivityLabels := make(map[string]string)
-		labelsList := strings.Split(labels, ",")
-		for _, vL := range labelsList {
-			if mapLabels[vL] == "" && vL != "" {
-				mapLabels[vL] = vL
-				item := new(models.UserLabel)
-				item.Label = vL
-				labelsListStr = append(labelsListStr, item)
-			}
-		}
-		dateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
-		listArticlePv, err := models.GetArticlePvCount(vUser.Mobile, vUser.Email, dateTime)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			fmt.Println("GetArticlePvCount Err", err)
-			return err
-		}
-		var articleIds string
-		mapArticleIdLabelTotal := make(map[string]int)
-		mapArticleIdPv := make(map[int]int)
-		if len(listArticlePv) > 0 {
-			for _, v := range listArticlePv {
-				articleIds += strconv.Itoa(v.ArticleId) + ","
-				mapArticleIdPv[v.ArticleId] = v.Pv
-			}
-			articleIds = strings.TrimRight(articleIds, ",")
-			//产业、标的标签
-			listLabelName, err := models.GetArticleGroupyIndustryName(articleIds)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				fmt.Println("GetArticleGroupyIndustryName Err", err)
-				return err
-			}
-			if len(listLabelName) > 0 {
-				for _, v := range listLabelName {
-					labelsIndustryList := strings.Split(v.IndustryName, "/")
-					labelsSubjectList := strings.Split(v.SubjectName, "/")
-					//添加产业统计
-					if len(labelsIndustryList) > 0 {
-						for _, vIn := range labelsIndustryList {
-							if mapActivityLabels[vIn] != "" {
-								mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
-							} else {
-								mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
-								mapActivityLabels[vIn] = vIn
-							}
-						}
-					}
-					if len(labelsSubjectList) > 0 {
-						//添加标的统计
-						for _, vIn := range labelsSubjectList {
-							if mapActivityLabels[vIn] != "" {
-								mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
-							} else {
-								mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
-								mapActivityLabels[vIn] = vIn
-							}
-						}
-					}
-				}
-			}
-		}
-		articleIds, err = models.GetCygxArticleCollectId(vUser.UserId, dateTime)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			fmt.Println("GetCygxArticleCollectId Err", err)
-			return err
-		}
-		if articleIds != "" {
-			//产业、标的标签
-			listLabelName, err := models.GetArticleGroupyIndustryName(articleIds)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				fmt.Println("GetArticleGroupyIndustryName Err", err)
-				return err
-			}
-			if len(listLabelName) > 0 {
-				for _, v := range listLabelName {
-					labelsIndustryList := strings.Split(v.IndustryName, "/")
-					labelsSubjectList := strings.Split(v.SubjectName, "/")
-					//添加产业统计
-					if len(labelsIndustryList) > 0 {
-						for _, vIn := range labelsIndustryList {
-							if mapActivityLabels[vIn] != "" {
-								mapArticleIdLabelTotal[vIn] += 1
-							} else {
-								mapArticleIdLabelTotal[vIn] = 1
-								mapActivityLabels[vIn] = vIn
-							}
-						}
-					}
-					if len(labelsSubjectList) > 0 {
-						//添加标的统计
-						for _, vIn := range labelsSubjectList {
-							if mapActivityLabels[vIn] != "" {
-								mapArticleIdLabelTotal[vIn] += 1
-							} else {
-								mapArticleIdLabelTotal[vIn] = 1
-								mapActivityLabels[vIn] = vIn
-							}
-						}
-					}
-				}
-			}
-		}
-		//活动标签计算
-		listActivityPv, err := models.GetActivitySignCount(vUser.Mobile, dateTime)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			fmt.Println("GetActivitySignCount Err", err)
-			return err
-		}
-		if len(listActivityPv) > 0 {
-			for _, v := range listActivityPv {
-				labelsList := strings.Split(v.Label, "-")
-				for _, v2 := range labelsList {
-					labelsListSon := strings.Split(v2, "/")
-					for _, v3 := range labelsListSon {
-						if mapActivityLabels[v3] != "" {
-							mapArticleIdLabelTotal[v3] += 1
-						} else {
-							mapArticleIdLabelTotal[v3] = 1
-							mapActivityLabels[v3] = v3
-						}
-					}
-				}
-			}
-		}
-		//对标签数量进行排序
-		type KvPair struct {
-			Key string
-			Val int
-		}
-		tmpList := make([]KvPair, 0)
-		for k, v := range mapArticleIdLabelTotal {
-			tmpList = append(tmpList, KvPair{Key: k, Val: v})
-		}
-		sort.Slice(tmpList, func(i, j int) bool {
-			return tmpList[i].Val > tmpList[j].Val // 降序
-		})
-		for _, v := range tmpList {
-			if v.Key != "" {
-				mapLabels[v.Key] = v.Key
-				item := new(models.UserLabel)
-				item.Label = v.Key
-				labelsListStr = append(labelsListStr, item)
-			}
-		}
-		var labelNew string
-		for _, v := range labelsListStr {
-			labelNew += v.Label + ","
-		}
-		labelNew = strings.TrimRight(labelNew, ",")
-		if labelNew != "" {
-			err = models.UpdateUserLabel(labelNew, vUser.UserId)
-			if err != nil {
-				fmt.Println("UpdateUserLabel Err", err)
-				return err
-			}
-		}
-	}
+	//for _, vUser := range listUser {
+	//	labels, err := models.GetCygxCompanyUserListSplit(strconv.Itoa(vUser.UserId))
+	//	if err != nil {
+	//		fmt.Println("GetCygxCompanyUserListSplit Err", err)
+	//		return err
+	//	}
+	//	mapLabels := make(map[string]string)
+	//	var labelsListStr []*models.UserLabel
+	//	mapActivityLabels := make(map[string]string)
+	//	labelsList := strings.Split(labels, ",")
+	//	for _, vL := range labelsList {
+	//		if mapLabels[vL] == "" && vL != "" {
+	//			mapLabels[vL] = vL
+	//			item := new(models.UserLabel)
+	//			item.Label = vL
+	//			labelsListStr = append(labelsListStr, item)
+	//		}
+	//	}
+	//	dateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
+	//	listArticlePv, err := models.GetArticlePvCount(vUser.Mobile, vUser.Email, dateTime)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		fmt.Println("GetArticlePvCount Err", err)
+	//		return err
+	//	}
+	//	var articleIds string
+	//	mapArticleIdLabelTotal := make(map[string]int)
+	//	mapArticleIdPv := make(map[int]int)
+	//	if len(listArticlePv) > 0 {
+	//		for _, v := range listArticlePv {
+	//			articleIds += strconv.Itoa(v.ArticleId) + ","
+	//			mapArticleIdPv[v.ArticleId] = v.Pv
+	//		}
+	//		articleIds = strings.TrimRight(articleIds, ",")
+	//		//产业、标的标签
+	//		listLabelName, err := models.GetArticleGroupyIndustryName(articleIds)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			fmt.Println("GetArticleGroupyIndustryName Err", err)
+	//			return err
+	//		}
+	//		if len(listLabelName) > 0 {
+	//			for _, v := range listLabelName {
+	//				labelsIndustryList := strings.Split(v.IndustryName, "/")
+	//				labelsSubjectList := strings.Split(v.SubjectName, "/")
+	//				//添加产业统计
+	//				if len(labelsIndustryList) > 0 {
+	//					for _, vIn := range labelsIndustryList {
+	//						if mapActivityLabels[vIn] != "" {
+	//							mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
+	//						} else {
+	//							mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
+	//							mapActivityLabels[vIn] = vIn
+	//						}
+	//					}
+	//				}
+	//				if len(labelsSubjectList) > 0 {
+	//					//添加标的统计
+	//					for _, vIn := range labelsSubjectList {
+	//						if mapActivityLabels[vIn] != "" {
+	//							mapArticleIdLabelTotal[vIn] += mapArticleIdPv[v.ArticleId]
+	//						} else {
+	//							mapArticleIdLabelTotal[vIn] = mapArticleIdPv[v.ArticleId]
+	//							mapActivityLabels[vIn] = vIn
+	//						}
+	//					}
+	//				}
+	//			}
+	//		}
+	//	}
+	//	articleIds, err = models.GetCygxArticleCollectId(vUser.UserId, dateTime)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		fmt.Println("GetCygxArticleCollectId Err", err)
+	//		return err
+	//	}
+	//	if articleIds != "" {
+	//		//产业、标的标签
+	//		listLabelName, err := models.GetArticleGroupyIndustryName(articleIds)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			fmt.Println("GetArticleGroupyIndustryName Err", err)
+	//			return err
+	//		}
+	//		if len(listLabelName) > 0 {
+	//			for _, v := range listLabelName {
+	//				labelsIndustryList := strings.Split(v.IndustryName, "/")
+	//				labelsSubjectList := strings.Split(v.SubjectName, "/")
+	//				//添加产业统计
+	//				if len(labelsIndustryList) > 0 {
+	//					for _, vIn := range labelsIndustryList {
+	//						if mapActivityLabels[vIn] != "" {
+	//							mapArticleIdLabelTotal[vIn] += 1
+	//						} else {
+	//							mapArticleIdLabelTotal[vIn] = 1
+	//							mapActivityLabels[vIn] = vIn
+	//						}
+	//					}
+	//				}
+	//				if len(labelsSubjectList) > 0 {
+	//					//添加标的统计
+	//					for _, vIn := range labelsSubjectList {
+	//						if mapActivityLabels[vIn] != "" {
+	//							mapArticleIdLabelTotal[vIn] += 1
+	//						} else {
+	//							mapArticleIdLabelTotal[vIn] = 1
+	//							mapActivityLabels[vIn] = vIn
+	//						}
+	//					}
+	//				}
+	//			}
+	//		}
+	//	}
+	//	//活动标签计算
+	//	listActivityPv, err := models.GetActivitySignCount(vUser.Mobile, dateTime)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		fmt.Println("GetActivitySignCount Err", err)
+	//		return err
+	//	}
+	//	if len(listActivityPv) > 0 {
+	//		for _, v := range listActivityPv {
+	//			labelsList := strings.Split(v.Label, "-")
+	//			for _, v2 := range labelsList {
+	//				labelsListSon := strings.Split(v2, "/")
+	//				for _, v3 := range labelsListSon {
+	//					if mapActivityLabels[v3] != "" {
+	//						mapArticleIdLabelTotal[v3] += 1
+	//					} else {
+	//						mapArticleIdLabelTotal[v3] = 1
+	//						mapActivityLabels[v3] = v3
+	//					}
+	//				}
+	//			}
+	//		}
+	//	}
+	//	//对标签数量进行排序
+	//	type KvPair struct {
+	//		Key string
+	//		Val int
+	//	}
+	//	tmpList := make([]KvPair, 0)
+	//	for k, v := range mapArticleIdLabelTotal {
+	//		tmpList = append(tmpList, KvPair{Key: k, Val: v})
+	//	}
+	//	sort.Slice(tmpList, func(i, j int) bool {
+	//		return tmpList[i].Val > tmpList[j].Val // 降序
+	//	})
+	//	for _, v := range tmpList {
+	//		if v.Key != "" {
+	//			mapLabels[v.Key] = v.Key
+	//			item := new(models.UserLabel)
+	//			item.Label = v.Key
+	//			labelsListStr = append(labelsListStr, item)
+	//		}
+	//	}
+	//	var labelNew string
+	//	for _, v := range labelsListStr {
+	//		labelNew += v.Label + ","
+	//	}
+	//	labelNew = strings.TrimRight(labelNew, ",")
+	//	if labelNew != "" {
+	//		err = models.UpdateUserLabel(labelNew, vUser.UserId)
+	//		if err != nil {
+	//			fmt.Println("UpdateUserLabel Err", err)
+	//			return err
+	//		}
+	//	}
+	//}
 
 	//处理用户、机构互动量数据
 	{
@@ -754,5 +750,8 @@ func UpdateWxUserLabel(cont context.Context) (err error) {
 			}
 		}
 	}
+
+	//更新用户标签以及权重
+	go UpdateUserLabelWeight()
 	return
 }

+ 2 - 0
utils/constants.go

@@ -108,6 +108,7 @@ const (
 	CYGX_TACTICS_TIME_LINE_STATUS    string = "cygx_tactics_time_line_status" // 策略时间线是否对外开放
 	TIME_LINE_ID                     int    = 99999                           // 策略时间线的值
 	TIME_LINE_NAME                   string = "时间线"                           // 策略时间线的名称
+	ACTEGORY_ID_AI_QY                int    = 61                              // AI前沿自定义ID
 )
 
 const (
@@ -121,6 +122,7 @@ const (
 
 const (
 	YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY = "YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY" //易董证通云的token,存Redis使用
+	CYGX_USER_KEY_LABEL              = "CYGX_USER_KEY_LABEL"              //查研观向用户标签
 )
 
 const (