Browse Source

no message

zhangchuanxing 1 month ago
parent
commit
1529a1661a

+ 1 - 0
models/article_history_record_all.go

@@ -134,6 +134,7 @@ func GetCygxArticleHistoryRecordAllListArticleIdCrm16_5() (items []*CygxArticleH
 func GetCygxArticleHistoryRecordAllListUserIdCrm16_5() (items []*CygxArticleHistoryRecordAll, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
+    		create_time,
     		article_id,
     		mobile,
 			user_id

+ 8 - 0
models/report_selection_subject_history.go

@@ -19,6 +19,7 @@ type CygxReportSelectionSubjectHistory struct {
 	IndustrialManagementId int       `description:"产业Id"`
 	RegisterPlatform       int       `description:"来源 1小程序,2:网页"`
 	ThirdId                int       `description:"类似产业、标的的三方ID"`
+	LableName              string    `description:"标签名称"`
 }
 
 type AddCygxReportSelectionSubjectHistoryReq struct {
@@ -42,3 +43,10 @@ func GetCygxReportSelectionSubjectHistory() (items []*CygxReportSelectionSubject
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+func UpdateCygxReportSelectionSubjectHistoryName(lableName string, id int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_report_selection_subject_history SET lable_name=? WHERE id = ? `
+	_, err = o.Raw(sql, lableName, id).Exec()
+	return
+}

+ 12 - 0
models/roadshow/rs_calendar.go

@@ -2,6 +2,7 @@ package roadshow
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_cygx/utils"
 	"time"
 )
 
@@ -39,3 +40,14 @@ func GetRsCalendarById(rsCalendarId int) (item *RsCalendar, err error) {
 	err = o.Raw(sql, rsCalendarId).QueryRow(&item)
 	return
 }
+
+// 列表
+func GetRsCalendarListInit(rsCalendarId []int) (items []*RsCalendar, err error) {
+	o := orm.NewOrmUsingDB("weekly_report")
+	sql := `SELECT
+    		*
+	FROM rs_calendar as  art 
+         WHERE 1=1  AND  rs_calendar_id IN  (` + utils.GetOrmInReplace(len(rsCalendarId)) + `)  `
+	_, err = o.Raw(sql, rsCalendarId).QueryRows(&items)
+	return
+}

+ 16 - 15
models/roadshow/rs_calendar_meeting_user.go

@@ -13,21 +13,22 @@ type RsCalendarMeetingUserResp struct {
 }
 
 type RsCalendarMeetingUser struct {
-	RsCalendarMeetingUserId int    `orm:"column(rs_calendar_meeting_user_id);pk" description:"主键ID"`
-	RsCalendarId            int    `description:"日程ID"`
-	UserId                  int    `description:"用户ID"`
-	Mobile                  string `description:"手机号"`
-	Email                   string `description:"邮箱"`
-	CompanyId               int    `description:"公司ID"`
-	CompanyName             string `description:"公司名称"`
-	RealName                string `description:"用户实际名称"`
-	Position                string `description:"职位"`
-	AdminId                 int    `description:"管理员ID"`
-	AdminName               string `description:"管理员姓名"`
-	StartDate               string `description:"开始日期"`
-	EndDate                 string `description:"结束日期"`
-	StartTime               string `description:"开始时间"`
-	EndTime                 string `description:"结束时间"`
+	RsCalendarMeetingUserId int       `orm:"column(rs_calendar_meeting_user_id);pk" description:"主键ID"`
+	RsCalendarId            int       `description:"日程ID"`
+	UserId                  int       `description:"用户ID"`
+	Mobile                  string    `description:"手机号"`
+	Email                   string    `description:"邮箱"`
+	CompanyId               int       `description:"公司ID"`
+	CompanyName             string    `description:"公司名称"`
+	RealName                string    `description:"用户实际名称"`
+	Position                string    `description:"职位"`
+	AdminId                 int       `description:"管理员ID"`
+	AdminName               string    `description:"管理员姓名"`
+	StartDate               string    `description:"开始日期"`
+	EndDate                 string    `description:"结束日期"`
+	StartTime               string    `description:"开始时间"`
+	EndTime                 string    `description:"结束时间"`
+	CreateTime              time.Time `description:"结束时间"`
 }
 
 // 列表

+ 37 - 0
models/wx_user_rai_label.go

@@ -191,6 +191,32 @@ func AddWxUserRaiLabelLogMultiInit(items []*WxUserRaiLabelLog) (err error) {
 	return
 }
 
+// 批量插入(脚本)
+func AddWxUserRaiLabelMultiInit(items []*WxUserRaiLabel) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+
+	//批量插入新的关联数据
+	if len(items) > 0 {
+		//批量添加流水信息
+		_, err = o.InsertMulti(len(items), items)
+		if err != nil {
+			return
+		}
+	}
+
+	return
+}
+
 // 文章标签表(业务用不到,跑数据使用,别删)
 type WxUserRaiArticleLabel struct {
 	Id         int       `orm:"column(id);pk"`
@@ -249,3 +275,14 @@ func GetWxUserRaiArticleLabelAllCrm16_5() (items []*WxUserRaiArticleLabel, err e
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+// 列表
+func GetWxUserRaiLabelLogAll() (items []*WxUserRaiLabelLog, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			*
+		FROM
+			wx_user_rai_label_log  `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 0 - 41
services/report_selection.go

@@ -102,44 +102,3 @@ func GetReportSelectionLabelName(req models.AddCygxReportSelectionSubjectHistory
 	ReportSelectionWxUserRaiLabelRedisAdd(req.ArticleId, userId, time.Now(), "cygx_report_selection", labelName)
 	return
 }
-
-// 记录用户在重点公司单独点了某一个标签
-//func UpdateReportSelectionLabelNameInit() {
-//	var err error
-//	defer func() {
-//		if err != nil {
-//			go utils.SendAlarmMsg("SendCygxReportSelectionLogApplyTemplateMsg Err"+err.Error(), 2)
-//		}
-//	}()
-//	var condition string
-//	var pars []interface{}
-//
-//	listhistory, err := models.GetCygxReportSelectionSubjectHistory()
-//	if err != nil {
-//		fmt.Println(err)
-//		return
-//	}
-//
-//	condition = ` AND article_id = ?  AND industrial_subject_id = ? AND  industrial_management_id = ? AND  third_id = ? `
-//	pars = append(pars, req.ArticleId, req.IndustrialSubjectId, req.IndustrialManagementId, req.ThirdId)
-//	listLog, e := models.GetCygxReportSelectionLog(condition, pars, 0, 9999)
-//	if e != nil {
-//		err = errors.New("GetCygxReportSelectionLog, Err: " + e.Error())
-//		return
-//	}
-//	var labelName string
-//	for _, v2 := range listLog {
-//		if v2.ThirdId > 0 {
-//			labelName = v2.ThirdName
-//		} else if v2.IndustrialSubjectId == 0 && v2.IndustrialManagementId != "" {
-//			labelName = v2.IndustrialManagementNames
-//		} else {
-//			labelName = v2.SubjectName
-//		}
-//	}
-//	if labelName == "" {
-//		return
-//	}
-//	ReportSelectionWxUserRaiLabelRedisAdd(req.ArticleId, userId, time.Now(), "cygx_report_selection", labelName)
-//	return
-//}

+ 535 - 120
services/wx_user_rai_label.go

@@ -425,56 +425,18 @@ func ArticleWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err er
 		err = errors.New("GetWxUserItemByUserId" + e.Error())
 		return
 	}
-	articleDetail, e := models.GetArticleDetailTestById(sourceId)
-	if e != nil {
-		err = errors.New("GetArticleDetailTestById" + e.Error())
-		return
-	}
-	articlePermission, e := models.GetArticlePermission(articleDetail.CategoryId)
-	if e != nil {
-		err = errors.New("GetArticlePermission" + e.Error())
-		return
-	}
-	if articlePermission == nil {
-		err = errors.New("报告权限不存在" + e.Error())
+	//articleDetail, e := models.GetArticleDetailTestById(sourceId)
+	//if e != nil {
+	//	err = errors.New("GetArticleDetailTestById" + e.Error())
+	//	return
+	//}
+
+	labelArr, sourceType := GetArticlelabelArrByArticleId(sourceId)
+	if len(labelArr) == 0 {
 		return
 	}
-	articlePermissionName := articlePermission.PermissionName
-	matchTypeName := articlePermission.MatchTypeName
-	matchTypeNameArr := []string{"季度策略", "科技前沿(周报)", "本周荟", "智造精粹"}
-
-	//1;四大行业汇总类报告:季度策略、科技前沿(周报)、本周荟、智造精粹以报告类型做标签
-	//2:策略、固收的所有报告,以报告类型做标签
-	if articlePermissionName == utils.CE_LUE_NAME || articlePermissionName == utils.GU_SHOU_NAME || utils.InArrayByStr(matchTypeNameArr, matchTypeName) { // 策略、固收的所有报告,以报告类型做标签
-		if matchTypeName == "季度策略" {
-			matchTypeName = articlePermissionName + matchTypeName //其中季度策略以:xx行业季度策略  呈现
-		}
-		item := new(models.WxUserRaiLabel)
-		item.UserId = wxUser.UserId
-		item.RealName = wxUser.RealName
-		item.Mobile = wxUser.Mobile
-		item.Email = wxUser.Email
-		item.CompanyId = wxUser.CompanyId
-		item.CompanyName = wxUser.CompanyName
-		item.Label = matchTypeName
-		item.SourceType = 8
-		item.SourceId = sourceId
-		item.CreateTime = log.CreateTime
-		item.ModifyTime = time.Now()
-		item.RegisterPlatform = log.RegisterPlatform
-		item.TableName = "cygx_article"
-		err = models.AddWxUserRaiLabel(item)
-		if e != nil {
-			err = errors.New("AddWxUserRaiLabel" + e.Error())
-			return
-		}
-	} else if articlePermissionName == utils.ZHOU_QI_NAME {
-		//周期的行业深度、调研纪要、产业跟踪这些系列的报告用领域做标签,其余的周期报告,都用报告类型(也就是ficc定义的类型)做标签
-		//其中周期的周度观点,以 周期周度观点 呈现
-		matchTypeNameArrZhouqi := []string{"行业深度", "调研纪要", "产业跟踪"}
-		if utils.InArrayByStr(matchTypeNameArrZhouqi, matchTypeName) {
-			matchTypeName = articleDetail.FieldName
-		}
+	var items []*models.WxUserRaiLabel
+	for _, v := range labelArr {
 		item := new(models.WxUserRaiLabel)
 		item.UserId = wxUser.UserId
 		item.RealName = wxUser.RealName
@@ -482,78 +444,147 @@ func ArticleWxUserRaiLabelRedisAddReduce(log models.WxUserRaiLabelRedis) (err er
 		item.Email = wxUser.Email
 		item.CompanyId = wxUser.CompanyId
 		item.CompanyName = wxUser.CompanyName
-		item.Label = matchTypeName
-		item.SourceType = 8
+		item.Label = v
+		item.SourceType = sourceType
 		item.SourceId = sourceId
 		item.CreateTime = log.CreateTime
 		item.ModifyTime = time.Now()
 		item.RegisterPlatform = log.RegisterPlatform
 		item.TableName = "cygx_article"
-		e = models.AddWxUserRaiLabel(item)
-		if e != nil {
-			err = errors.New("AddWxUserRaiLabel" + e.Error())
-			return
-		}
-	} else {
-		//正常的有产业报告
-		var labelArr []string
-		//建立首页资源表,与产业的关系
-		industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
-		if e != nil && e.Error() != utils.ErrNoRow() {
-			err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
-			return
-		}
-
-		var items []*models.WxUserRaiLabel
-		for _, v := range industrialList {
-			item := new(models.WxUserRaiLabel)
-			item.UserId = wxUser.UserId
-			item.RealName = wxUser.RealName
-			item.Mobile = wxUser.Mobile
-			item.Email = wxUser.Email
-			item.CompanyId = wxUser.CompanyId
-			item.CompanyName = wxUser.CompanyName
-			item.Label = v.IndustryName
-			item.SourceType = 7
-			item.SourceId = sourceId
-			item.CreateTime = log.CreateTime
-			item.ModifyTime = time.Now()
-			item.RegisterPlatform = log.RegisterPlatform
-			item.TableName = "cygx_article"
-			items = append(items, item)
-			labelArr = append(labelArr, v.IndustryName)
-		}
-
-		//建立首页资源表,与标的 的关系
-		subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
-		if e != nil && e.Error() != utils.ErrNoRow() {
-			err = errors.New("GetSubjectArticleGroupManagementListByArtcileId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
-			return
-		}
+		items = append(items, item)
+		//labelArr = append(labelArr, v.IndustryName)
+	}
+
+	//articlePermission, e := models.GetArticlePermission(articleDetail.CategoryId)
+	//if e != nil {
+	//	err = errors.New("GetArticlePermission" + e.Error())
+	//	return
+	//}
+	//if articlePermission == nil {
+	//	err = errors.New("报告权限不存在" + e.Error())
+	//	return
+	//}
+	//articlePermissionName := articlePermission.PermissionName
+	//matchTypeName := articlePermission.MatchTypeName
+	//matchTypeNameArr := []string{"季度策略", "科技前沿(周报)", "本周荟", "智造精粹"}
+	//
+	////1;四大行业汇总类报告:季度策略、科技前沿(周报)、本周荟、智造精粹以报告类型做标签
+	////2:策略、固收的所有报告,以报告类型做标签
+	//if articlePermissionName == utils.CE_LUE_NAME || articlePermissionName == utils.GU_SHOU_NAME || utils.InArrayByStr(matchTypeNameArr, matchTypeName) { // 策略、固收的所有报告,以报告类型做标签
+	//	if matchTypeName == "季度策略" {
+	//		matchTypeName = articlePermissionName + matchTypeName //其中季度策略以:xx行业季度策略  呈现
+	//	}
+	//	item := new(models.WxUserRaiLabel)
+	//	item.UserId = wxUser.UserId
+	//	item.RealName = wxUser.RealName
+	//	item.Mobile = wxUser.Mobile
+	//	item.Email = wxUser.Email
+	//	item.CompanyId = wxUser.CompanyId
+	//	item.CompanyName = wxUser.CompanyName
+	//	item.Label = matchTypeName
+	//	item.SourceType = 8
+	//	item.SourceId = sourceId
+	//	item.CreateTime = log.CreateTime
+	//	item.ModifyTime = time.Now()
+	//	item.RegisterPlatform = log.RegisterPlatform
+	//	item.TableName = "cygx_article"
+	//	err = models.AddWxUserRaiLabel(item)
+	//	if e != nil {
+	//		err = errors.New("AddWxUserRaiLabel" + e.Error())
+	//		return
+	//	}
+	//} else if articlePermissionName == utils.ZHOU_QI_NAME {
+	//	//周期的行业深度、调研纪要、产业跟踪这些系列的报告用领域做标签,其余的周期报告,都用报告类型(也就是ficc定义的类型)做标签
+	//	//其中周期的周度观点,以 周期周度观点 呈现
+	//	matchTypeNameArrZhouqi := []string{"行业深度", "调研纪要", "产业跟踪"}
+	//	if utils.InArrayByStr(matchTypeNameArrZhouqi, matchTypeName) {
+	//		matchTypeName = articleDetail.FieldName
+	//	}
+	//	item := new(models.WxUserRaiLabel)
+	//	item.UserId = wxUser.UserId
+	//	item.RealName = wxUser.RealName
+	//	item.Mobile = wxUser.Mobile
+	//	item.Email = wxUser.Email
+	//	item.CompanyId = wxUser.CompanyId
+	//	item.CompanyName = wxUser.CompanyName
+	//	item.Label = matchTypeName
+	//	item.SourceType = 8
+	//	item.SourceId = sourceId
+	//	item.CreateTime = log.CreateTime
+	//	item.ModifyTime = time.Now()
+	//	item.RegisterPlatform = log.RegisterPlatform
+	//	item.TableName = "cygx_article"
+	//	e = models.AddWxUserRaiLabel(item)
+	//	if e != nil {
+	//		err = errors.New("AddWxUserRaiLabel" + e.Error())
+	//		return
+	//	}
+	//} else {
+	//	//正常的有产业报告
+	//	var labelArr []string
+	//	//建立首页资源表,与产业的关系
+	//	industrialList, e := models.GetIndustrialArticleGroupManagementListByArticleId(sourceId)
+	//	if e != nil && e.Error() != utils.ErrNoRow() {
+	//		err = errors.New("GetIndustrialArticleGroupManagementListByArticleId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+	//		return
+	//	}
+	//
+	//	var items []*models.WxUserRaiLabel
+	//	for _, v := range industrialList {
+	//		item := new(models.WxUserRaiLabel)
+	//		item.UserId = wxUser.UserId
+	//		item.RealName = wxUser.RealName
+	//		item.Mobile = wxUser.Mobile
+	//		item.Email = wxUser.Email
+	//		item.CompanyId = wxUser.CompanyId
+	//		item.CompanyName = wxUser.CompanyName
+	//		item.Label = v.IndustryName
+	//		item.SourceType = 7
+	//		item.SourceId = sourceId
+	//		item.CreateTime = log.CreateTime
+	//		item.ModifyTime = time.Now()
+	//		item.RegisterPlatform = log.RegisterPlatform
+	//		item.TableName = "cygx_article"
+	//		items = append(items, item)
+	//		labelArr = append(labelArr, v.IndustryName)
+	//	}
+	//
+	//	//建立首页资源表,与标的 的关系
+	//	subjectList, e := models.GetSubjectArticleGroupManagementListByArtcileId(sourceId)
+	//	if e != nil && e.Error() != utils.ErrNoRow() {
+	//		err = errors.New("GetSubjectArticleGroupManagementListByArtcileId, Err: " + e.Error() + "sourceId:" + strconv.Itoa(sourceId))
+	//		return
+	//	}
+	//
+	//	for _, v := range subjectList {
+	//		item := new(models.WxUserRaiLabel)
+	//		item.UserId = wxUser.UserId
+	//		item.RealName = wxUser.RealName
+	//		item.Mobile = wxUser.Mobile
+	//		item.Email = wxUser.Email
+	//		item.CompanyId = wxUser.CompanyId
+	//		item.CompanyName = wxUser.CompanyName
+	//		item.Label = v.SubjectName
+	//		item.SourceType = 7
+	//		item.SourceId = sourceId
+	//		item.CreateTime = log.CreateTime
+	//		item.ModifyTime = time.Now()
+	//		item.RegisterPlatform = log.RegisterPlatform
+	//		item.TableName = "cygx_article"
+	//		items = append(items, item)
+	//		labelArr = append(labelArr, v.SubjectName)
+	//	}
+	//	e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
+	//	if e != nil {
+	//		err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
+	//		return
+	//	}
+	//}
 
-		for _, v := range subjectList {
-			item := new(models.WxUserRaiLabel)
-			item.UserId = wxUser.UserId
-			item.RealName = wxUser.RealName
-			item.Mobile = wxUser.Mobile
-			item.Email = wxUser.Email
-			item.CompanyId = wxUser.CompanyId
-			item.CompanyName = wxUser.CompanyName
-			item.Label = v.SubjectName
-			item.SourceType = 7
-			item.SourceId = sourceId
-			item.CreateTime = log.CreateTime
-			item.ModifyTime = time.Now()
-			item.RegisterPlatform = log.RegisterPlatform
-			item.TableName = "cygx_article"
-			items = append(items, item)
-			labelArr = append(labelArr, v.SubjectName)
-		}
-		e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
-		if e != nil {
-			err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
-			return
-		}
+	e = models.AddWxUserRaiLabelMulti(items, labelArr, userId)
+	if e != nil {
+		err = errors.New("AddWxUserRaiLabelMulti" + e.Error())
+		return
 	}
 
 	return
@@ -748,7 +779,7 @@ func initCrm16_5keyWord() {
 		for _, v := range items {
 			itemsAdd = append(itemsAdd, v)
 			if len(items)%2000 == 0 {
-				err = models.AddWxUserRaiLabelLogMultiInit(items)
+				err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
 				if err != nil {
 					return
 				}
@@ -816,6 +847,7 @@ func initCrm16_5Activity() {
 	}
 
 	sourceTypemap := make(map[int]int)
+	mapLabel := make(map[int]string)
 
 	for _, v := range activityDetailList {
 		if v.ActivityType == 1 {
@@ -823,6 +855,7 @@ func initCrm16_5Activity() {
 		} else {
 			sourceTypemap[v.ActivityId] = 2
 		}
+		mapLabel[v.ActivityId] = v.Label
 	}
 
 	//正常的有产业报告
@@ -846,11 +879,13 @@ func initCrm16_5Activity() {
 		if mapUser[v.Mobile] == nil || v.Mobile == "" {
 			continue
 		}
+		var haseName bool
 		wxUser := mapUser[v.Mobile]
 		for _, vI := range industrialList {
 			if vI.ActivityId != v.ActivityId {
 				continue
 			}
+			haseName = true
 			item := new(models.WxUserRaiLabelLog)
 			item.UserId = wxUser.UserId
 			item.RealName = wxUser.RealName
@@ -872,6 +907,7 @@ func initCrm16_5Activity() {
 			if vs.ActivityId != v.ActivityId {
 				continue
 			}
+			haseName = true
 			item := new(models.WxUserRaiLabelLog)
 			item.UserId = wxUser.UserId
 			item.RealName = wxUser.RealName
@@ -888,9 +924,28 @@ func initCrm16_5Activity() {
 			items = append(items, item)
 		}
 
-	}
-	fmt.Println(len(items))
+		//如果两个标签都没有,就添加临时标签
+		if !haseName {
+			item := new(models.WxUserRaiLabelLog)
+			item.UserId = wxUser.UserId
+			item.RealName = wxUser.RealName
+			item.Mobile = wxUser.Mobile
+			item.Email = wxUser.Email
+			item.CompanyId = wxUser.CompanyId
+			item.CompanyName = wxUser.CompanyName
+			item.Label = mapLabel[v.ActivityId]
+			item.SourceType = sourceTypemap[v.ActivityId]
+			item.SourceId = v.ActivityId
+			item.CreateTime = v.CreateTime
+			item.ModifyTime = time.Now()
+			//item.RegisterPlatform = v.RegisterPlatform
+			item.TableName = ""
+			items = append(items, item)
+		}
 
+	}
+	//fmt.Println("initCrm16_5Activity", len(items))
+	//return
 	var itemsAdd []*models.WxUserRaiLabelLog
 	if len(items) > 0 {
 		for _, v := range items {
@@ -919,7 +974,7 @@ func initCrm16_5Article() {
 	var pars []interface{}
 	condition += `  `
 	pars = append(pars)
-	//获取提交到会的人员信息
+
 	listArticleIds, err := models.GetCygxArticleHistoryRecordAllListArticleIdCrm16_5()
 	if err != nil {
 		fmt.Println(err)
@@ -1060,6 +1115,69 @@ func initCrm16_5Article2() {
 
 }
 
+////func init() {
+//	//initCrm16_5keyWord()
+//	//initCrm16_5Activity()
+//	//initCrm16_5Article2()
+//	//initCrm16_5ReportHistory()
+//	//initCrm16_5ReportHistory_2()
+//	//initCrm16_5Roadshow()
+//
+//	fmt.Println("end RO")
+//
+//	initCrm16_5wx_user_rai_label()
+//
+//	fmt.Println("end RO2")
+//}
+
+// 记录用户在重点公司单独点了某一个标签
+func initCrm16_5ReportHistory_0() {
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("SendCygxReportSelectionLogApplyTemplateMsg Err"+err.Error(), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+
+	listhistory, err := models.GetCygxReportSelectionSubjectHistory()
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	for kH, vH := range listhistory {
+		fmt.Println(kH)
+		pars = make([]interface{}, 0)
+		condition = ` AND article_id = ?  AND industrial_subject_id = ? AND  industrial_management_id = ? AND  third_id = ? `
+		pars = append(pars, vH.ArticleId, vH.IndustrialSubjectId, vH.IndustrialManagementId, vH.ThirdId)
+		listLog, e := models.GetCygxReportSelectionLog(condition, pars, 0, 9999)
+		if e != nil {
+			err = errors.New("GetCygxReportSelectionLog, Err: " + e.Error())
+			fmt.Println(err)
+			return
+		}
+		var labelName string
+		for _, v2 := range listLog {
+			if v2.ThirdId > 0 {
+				labelName = v2.ThirdName
+			} else if v2.IndustrialSubjectId == 0 && v2.IndustrialManagementId != "" {
+				labelName = v2.IndustrialManagementNames
+			} else {
+				labelName = v2.SubjectName
+			}
+		}
+		err = models.UpdateCygxReportSelectionSubjectHistoryName(labelName, vH.Id)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+	}
+	fmt.Println("end")
+
+	return
+}
+
 func initCrm16_5ReportHistory() {
 
 	listReportHistory, err := models.GetWxUserRaiCygxReportHistoryRecordCrm16_5()
@@ -1104,18 +1222,95 @@ func initCrm16_5ReportHistory() {
 		item.Email = wxUser.Email
 		item.CompanyId = wxUser.CompanyId
 		item.CompanyName = wxUser.CompanyName
-		if v.ReportType == "" {
+		if v.ReportType == "bgjx" {
 			item.Label = "重点推荐"
+			item.TableName = "cygx_report_selection"
 		} else {
 			item.Label = "本周研究汇总"
+			item.TableName = "cygx_research_summary"
 		}
+		item.SourceId = v.ArticleId
 		item.SourceType = 8
 		item.CreateTime = v.CreateTime
 		item.ModifyTime = time.Now()
 		item.RegisterPlatform = v.RegisterPlatform
 		items = append(items, item)
 	}
-	fmt.Println(len(items))
+	fmt.Println("items", len(items))
+
+	var itemsAdd []*models.WxUserRaiLabelLog
+	if len(items) > 0 {
+		for _, v := range items {
+			itemsAdd = append(itemsAdd, v)
+			if len(items)%2000 == 0 {
+				err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
+				if err != nil {
+					return
+				}
+				itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
+			}
+		}
+	}
+	if len(itemsAdd) > 0 {
+		err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
+		if err != nil {
+			return
+		}
+	}
+	fmt.Println("endAddWxUserRaiLabelLogMultiInit")
+}
+
+func initCrm16_5ReportHistory_2() {
+
+	listReportHistory, err := models.GetCygxReportSelectionSubjectHistory()
+
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	var mobiles []string
+	mapMobile := make(map[string]bool)
+	for _, v := range listReportHistory {
+		if mapMobile[v.Mobile] || v.Mobile == "" {
+			continue
+		}
+		mapMobile[v.Mobile] = true
+		mobiles = append(mobiles, v.Mobile)
+	}
+
+	listUser, err := models.GetWxUserListByMobileArr(mobiles)
+
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	mapUser := make(map[string]*models.WxUserItem)
+	for _, v := range listUser {
+		mapUser[v.Mobile] = v
+	}
+
+	var items []*models.WxUserRaiLabelLog
+	for _, v := range listReportHistory {
+		if mapUser[v.Mobile] == nil || v.Mobile == "" || v.LableName == "" {
+			continue
+		}
+		wxUser := mapUser[v.Mobile]
+		item := new(models.WxUserRaiLabelLog)
+		item.UserId = wxUser.UserId
+		item.RealName = wxUser.RealName
+		item.Mobile = wxUser.Mobile
+		item.Email = wxUser.Email
+		item.CompanyId = wxUser.CompanyId
+		item.CompanyName = wxUser.CompanyName
+		item.Label = v.LableName
+		item.SourceType = 8
+		item.CreateTime = v.CreateTime
+		item.ModifyTime = time.Now()
+		item.RegisterPlatform = v.RegisterPlatform
+		items = append(items, item)
+	}
+	fmt.Println("items", len(items))
 
 	var itemsAdd []*models.WxUserRaiLabelLog
 	if len(items) > 0 {
@@ -1139,3 +1334,223 @@ func initCrm16_5ReportHistory() {
 	}
 	fmt.Println("endAddWxUserRaiLabelLogMultiInit")
 }
+
+func initCrm16_5Roadshow() {
+	var condition string
+	var pars []interface{}
+	condition = " "
+	calendarMeetingUserList, e := roadshow.GetRsCalendarMeetingUserList(condition+"  ORDER BY rs.start_date ASC ", pars)
+	if e != nil {
+		fmt.Println(e)
+		return
+	}
+	var rsCalendarIds []int
+	for _, v := range calendarMeetingUserList {
+		rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
+	}
+
+	var mobiles []string
+	mapMobile := make(map[string]bool)
+	for _, v := range calendarMeetingUserList {
+		if mapMobile[v.Mobile] || v.Mobile == "" {
+			continue
+		}
+		mapMobile[v.Mobile] = true
+		mobiles = append(mobiles, v.Mobile)
+	}
+
+	RsCalendarListInit, e := roadshow.GetRsCalendarListInit(rsCalendarIds)
+	if e != nil {
+		fmt.Println(e)
+		return
+	}
+	mapRoadshowType := make(map[int]int)
+	for _, v := range RsCalendarListInit {
+		if v.RoadshowType == "线下" {
+			mapRoadshowType[v.RsCalendarId] = 3
+		} else {
+			mapRoadshowType[v.RsCalendarId] = 5
+		}
+	}
+
+	listUser, err := models.GetWxUserListByMobileArr(mobiles)
+
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	mapUser := make(map[string]*models.WxUserItem)
+
+	for _, v := range listUser {
+		mapUser[v.Mobile] = v
+	}
+
+	var items []*models.WxUserRaiLabelLog
+	for _, v := range calendarMeetingUserList {
+		if mapUser[v.Mobile] == nil || v.Mobile == "" {
+			continue
+		}
+		wxUser := mapUser[v.Mobile]
+		var sourceType int
+		sourceType = mapRoadshowType[v.RsCalendarId]
+
+		totalGroup, e := roadshow.GetRsCalendarMeetingLabelGroupByRsCalendarId(v.RsCalendarId)
+		if e != nil {
+			err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
+			return
+		}
+		//var lebelDetail []*cygx.RaiServeTagResp
+		var label string
+		var labelArr []string
+		if totalGroup > 0 {
+			listGroup, e := roadshow.GetRsCalendarMeetingLabelGroupListByRsCalendarId(v.RsCalendarId)
+			if e != nil {
+				err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
+				return
+			}
+			var industrialManagementIds []int
+			var industrialSubjectIds []int
+
+			mapindustrialManagementName := make(map[int]string)
+			mapindustrialSubjectName := make(map[int]string)
+			mapCelueName := make(map[int]string)
+			for _, vG := range listGroup {
+				switch vG.TagType {
+				case 1:
+					industrialManagementIds = append(industrialManagementIds, vG.TagId)
+				case 2:
+					industrialSubjectIds = append(industrialSubjectIds, vG.TagId)
+				case 3:
+					mapCelueName[vG.TagId] = "策略"
+				}
+			}
+
+			if len(industrialManagementIds) > 0 {
+				IndustryList, e := models.GetIndustryListByConditionByIds(industrialManagementIds)
+				if e != nil {
+					err = errors.New("GetRsCalendarMeetingLabelGroupByRsCalendarId" + e.Error())
+					return
+				}
+				for _, vI := range IndustryList {
+					mapindustrialManagementName[vI.IndustrialManagementId] = vI.IndustryName
+				}
+			}
+
+			if len(industrialSubjectIds) > 0 {
+				SubjectList, e := models.GetIndustrialSubjectDetailByIds(industrialSubjectIds)
+				if e != nil {
+					err = errors.New("GetIndustrialSubjectDetailByIds" + e.Error())
+					return
+				}
+				for _, vS := range SubjectList {
+					mapindustrialSubjectName[vS.IndustrialSubjectId] = vS.SubjectName
+				}
+			}
+
+			for _, vG := range listGroup {
+				switch vG.TagType {
+				case 1:
+					label = mapindustrialManagementName[vG.TagId]
+				case 2:
+					label = mapindustrialSubjectName[vG.TagId]
+				case 3:
+					label = mapCelueName[vG.TagId]
+				}
+				item := new(models.WxUserRaiLabelLog)
+				item.UserId = wxUser.UserId
+				item.RealName = wxUser.RealName
+				item.Mobile = wxUser.Mobile
+				item.Email = wxUser.Email
+				item.CompanyId = wxUser.CompanyId
+				item.CompanyName = wxUser.CompanyName
+				item.Label = label
+				item.SourceType = sourceType
+				item.SourceId = v.RsCalendarId
+				item.CreateTime = v.CreateTime
+				item.ModifyTime = time.Now()
+				//item.RegisterPlatform = log.RegisterPlatform
+				item.TableName = ""
+				items = append(items, item)
+				labelArr = append(labelArr, label)
+			}
+		}
+	}
+	fmt.Println("items", len(items))
+
+	var itemsAdd []*models.WxUserRaiLabelLog
+	if len(items) > 0 {
+		for _, v := range items {
+			itemsAdd = append(itemsAdd, v)
+			if len(items)%2000 == 0 {
+				err = models.AddWxUserRaiLabelLogMultiInit(items)
+				if err != nil {
+					return
+				}
+				itemsAdd = make([]*models.WxUserRaiLabelLog, 0)
+			}
+		}
+	}
+	if len(itemsAdd) > 0 {
+		err = models.AddWxUserRaiLabelLogMultiInit(itemsAdd)
+		if err != nil {
+			return
+		}
+	}
+	fmt.Println("endAddWxUserRaiLabelLogMultiInit")
+}
+
+func initCrm16_5wx_user_rai_label() {
+
+	listAll, err := models.GetWxUserRaiLabelLogAll()
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	mapMobileLabel := make(map[string]bool)
+	var items []*models.WxUserRaiLabel
+	for _, v := range listAll {
+		if mapMobileLabel[fmt.Sprint(v.Mobile, "__", v.Label)] {
+			continue
+		}
+		item := new(models.WxUserRaiLabel)
+		item.UserId = v.UserId
+		item.RealName = v.RealName
+		item.Mobile = v.Mobile
+		item.Email = v.Email
+		item.CompanyId = v.CompanyId
+		item.CompanyName = v.CompanyName
+		item.Label = v.Label
+		item.SourceId = v.SourceId
+		item.SourceType = v.SourceType
+		item.CreateTime = v.CreateTime
+		item.ModifyTime = v.ModifyTime
+		item.RegisterPlatform = v.RegisterPlatform
+		item.TableName = v.TableName
+		items = append(items, item)
+
+		mapMobileLabel[fmt.Sprint(v.Mobile, "__", v.Label)] = true
+	}
+
+	var itemsAdd []*models.WxUserRaiLabel
+	if len(items) > 0 {
+		for _, v := range items {
+			itemsAdd = append(itemsAdd, v)
+			if len(items)%2000 == 0 {
+				err = models.AddWxUserRaiLabelMultiInit(items)
+				if err != nil {
+					return
+				}
+				itemsAdd = make([]*models.WxUserRaiLabel, 0)
+			}
+		}
+	}
+	if len(itemsAdd) > 0 {
+		err = models.AddWxUserRaiLabelMultiInit(itemsAdd)
+		if err != nil {
+			return
+		}
+	}
+
+	fmt.Println("endAddWxUserRaiLabelLogMultiInit")
+}

+ 1 - 1
utils/constants.go

@@ -143,7 +143,7 @@ const (
 
 const (
 	SHANG_HAI_CRM_API_TOKEN = "SHANG_HAI_CRM_API_TOKEN"
-	WX_USER_RAI_LABEL_KEY   = "WX_USER_RAI_LABEL_KEY" //用户列表标签key
+	WX_USER_RAI_LABEL_KEY   = "CYGX_WX_USER_RAI_LABEL_KEY" //用户列表标签key
 )
 
 // 邀请机构标识