package services

import (
	"context"
	"errors"
	"fmt"
	"hongze/hongze_cygx/models"
	"hongze/hongze_cygx/models/company"
	"hongze/hongze_cygx/models/wx_user"
	"hongze/hongze_cygx/utils"
	"strconv"
	"strings"
	"time"
)

func UpdateWxUserLabelOLd(cont context.Context) (err error) {
	defer func() {
		if err != nil {
			go utils.SendAlarmMsg("更新用户标签失败;Err:"+err.Error(), 2)
		}
	}()
	//获取需要处理的权益客户
	listUser, err := models.GetUserRegisterList()
	if err != nil {
		fmt.Println("GetUserRegisterList Err", err)
		return err
	}
	mapChartCollect := make(map[string]int)
	//获取已经处理记录的用户并记录切片
	listChartCollectL, err := models.GetCygxChartCollectList()
	if err != nil && err.Error() != utils.ErrNoRow() {
		fmt.Println("GetCygxUserInteractionNumList Err", err)
		return err
	}
	for _, v := range listChartCollectL {
		mapChartCollect[fmt.Sprint("m:", v.Mobile, "u:", v.ChartId)] = v.UserId
	}

	var interactionNum int //  互动量
	mapComapnyInteractionNum := make(map[int]int)

	//拉取策略平台用户同步的图表信息

	{
		var chartMobile string
		var chartItems []*models.CygxChartCollect

		if utils.RunMode == "release" {
			for k, vUser := range listUser {
				if vUser.Mobile != "" {
					mobile := vUser.Mobile
					fmt.Println(vUser.Mobile, "_", k)
					chartMobile += mobile + ","
					listChart, _, _ := GetChartCollectionByApi(mobile, 9999, 0)
					if len(listChart) > 0 {
						for _, vChart := range listChart {
							if mapChartCollect[fmt.Sprint("m:", mobile, "u:", vChart.ChartId)] == 0 {
								item := new(models.CygxChartCollect)
								item.ChartId = vChart.ChartId
								t1, _ := time.Parse("2006-01-02T15:04:05Z", vChart.CreateDate)
								item.CreateTime = t1
								item.Mobile = mobile
								chartItems = append(chartItems, item)
							}
						}
					}
				}
			}
		}
		//如果有数据就添加
		if len(chartItems) > 0 {
			_, err = models.AddCygxChartCollectList(chartItems)
			if err != nil {
				fmt.Println(" RemoveChartCollectByMobile Err", err)
			}
		}

		//处理图表关注后的用户
		{
			if utils.RunMode == "release" {
				listChartCollect, err := models.GetCygxChartCollectByMobileList()
				if err != nil {
					fmt.Println("GetCygxChartCollectByMobileList ，Err" + err.Error())
				}
				for k, v := range listChartCollect {
					if v.Mobile != "" {
						user, err := models.GetWxUserItemByMobile(v.Mobile)
						if err != nil && err.Error() != utils.ErrNoRow() {
							fmt.Println("GetWxUserItemByUserId ，Err" + err.Error())
						}
						if user != nil {
							fmt.Println(user.RealName, k)
							err = models.UpdateCygxChartCollect(user)
							if err != nil {
								fmt.Println("UpdateCygxChartCollect ，Err" + err.Error())
							}
						}
					}
				}
			}
		}
	}

	//处理 前一天移动之后的用户的公司记录信息

	//{
	//	startDate := time.Now().AddDate(0, 0, -1).Format(utils.FormatDate)
	//	endDate := time.Now().Format(utils.FormatDate)
	//	listUpdateUser, err := models.GetWxUserOpLogList(startDate, endDate)
	//	if err != nil && err.Error() != utils.ErrNoRow() {
	//		return err
	//	}
	//	var userIds string
	//	var mobiles string
	//	if len(listUpdateUser) > 0 {
	//		for _, v := range listUpdateUser {
	//			userIds += strconv.Itoa(v.UserId) + ","
	//			mobiles += "'" + v.Mobile + "',"
	//		}
	//	}
	//	userIds = strings.TrimRight(userIds, ",")
	//	mobiles = strings.TrimRight(mobiles, ",")
	//
	//	//如果用户ID不为空那么就处理这些用户的记录信息
	//	if userIds != "" {
	//		var condition string
	//		//condition = ` AND user_id IN (` + userIds + `)`
	//		condition = ` AND mobile IN (` + mobiles + `)`
	//		//处理用户的文章收藏
	//		listCollect, err := models.GetCygxArticleCollectList(condition)
	//		if err != nil && err.Error() != utils.ErrNoRow() {
	//			fmt.Println("GetAddCygxArticleCollectList ，Err" + err.Error())
	//		}
	//		if len(listCollect) > 0 {
	//			for _, v := range listCollect {
	//				user, err := models.GetWxUserItemByUserId(v.UserId)
	//				if err != nil && err.Error() != utils.ErrNoRow() {
	//					fmt.Println("GetWxUserItemByUserId ，Err" + err.Error())
	//				}
	//				if user != nil {
	//					fmt.Println(user.RealName)
	//					err = models.UpdateCygxArticleCollect(user)
	//					if err != nil {
	//						fmt.Println("UpdateCygxArticleCollect ，Err" + err.Error())
	//					}
	//				}
	//			}
	//		}
	//		//处理用户的文章收藏 end
	//
	//		//修改用户关注的产业
	//		listIndustryFllow, err := models.GetCygxIndustryFllowList(condition)
	//		if err != nil {
	//			fmt.Println("GetCygxIndustryFllowList ，Err" + err.Error())
	//		}
	//		for k, v := range listIndustryFllow {
	//			if v.Mobile != "" {
	//				user, err := models.GetWxUserItemByUserId(v.UserId)
	//				if err != nil && err.Error() != utils.ErrNoRow() {
	//					fmt.Println("GetWxUserItemByUserId ，Err" + err.Error())
	//				}
	//				if user != nil {
	//					fmt.Println(user.RealName, k)
	//					err = models.UpdateCygxIndustryFllow(user)
	//					if err != nil {
	//						fmt.Println("UpdateCygxIndustryFllow ，Err" + err.Error())
	//					}
	//				}
	//			}
	//		}
	//
	//		//修改用户产业关注的产业end
	//
	//		//修改用户的阅读记录
	//		listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
	//		if err != nil {
	//			fmt.Println("GetArticleHistoryRecordAllByMobileList ，Err" + err.Error())
	//		}
	//		for k, v := range listArticlePv {
	//			if v.Mobile != "" {
	//				user, err := models.GetWxUserItemByMobile(v.Mobile)
	//				if err != nil && err.Error() != utils.ErrNoRow() {
	//					fmt.Println("GetWxUserItemByUserId ，Err" + err.Error())
	//				}
	//				if user != nil {
	//					fmt.Println(user.RealName, k)
	//					err = models.UpdateCygxArticleHistoryRecordAll(user)
	//					if err != nil {
	//						fmt.Println("UpdateCygxArticleCollect ，Err" + err.Error())
	//					}
	//				}
	//			}
	//		}
	//		//修改用户的阅读记录end
	//
	//		//处理用户的搜索记录
	//		listSearch, err := models.GetCygxSearchKeyWordList(condition)
	//		if err != nil {
	//			fmt.Println("GetArticleHistoryRecordAllByMobileList ，Err" + err.Error())
	//		}
	//
	//		for k, v := range listSearch {
	//			if v.Mobile != "" {
	//				user, err := models.GetWxUserItemByUserId(v.UserId)
	//				if err != nil && err.Error() != utils.ErrNoRow() {
	//					fmt.Println("GetWxUserItemByUserId ，Err" + err.Error())
	//				}
	//				if user != nil {
	//					fmt.Println(user.RealName, k)
	//					err = models.UpdateCygxSearchKeyWord(user)
	//					if err != nil {
	//						fmt.Println("UpdateCygxSearchKeyWord ，Err" + err.Error())
	//					}
	//				}
	//			}
	//		}
	//
	//		// 处理用户的作者关注
	//		lisDepartmentF, err := models.GetArticleDepartmentFollowByMobileList(condition)
	//		if err != nil {
	//			fmt.Println("GetArticleDepartmentFollowByMobileList ，Err" + err.Error())
	//			return err
	//		}
	//		for k, v := range lisDepartmentF {
	//			if v.Mobile != "" {
	//				user, err := models.GetWxUserItemByUserId(v.UserId)
	//				if err != nil && err.Error() != utils.ErrNoRow() {
	//					fmt.Println("GetWxUserItemByUserId ，Err" + err.Error())
	//				}
	//				if user != nil {
	//					fmt.Println(user.RealName, k)
	//					err = models.UpdateCygxArticleDepartmentFollow(user)
	//					if err != nil {
	//						fmt.Println("UpdateCygxArticleDepartmentFollow ，Err" + err.Error())
	//					}
	//				}
	//			}
	//		}
	//		// 处理用户的作者关注end
	//
	//		// 处理用户的活动视频播放
	//		listActivityVideo, err := models.GetActivityVideoHistoryByMobileList(condition)
	//		if err != nil {
	//			fmt.Println("GetArticleDepartmentFollowByMobileList ，Err" + err.Error())
	//			return err
	//		}
	//		for k, v := range listActivityVideo {
	//			if v.Mobile != "" {
	//				user, err := models.GetWxUserItemByUserId(v.UserId)
	//				if err != nil && err.Error() != utils.ErrNoRow() {
	//					fmt.Println("GetWxUserItemByUserId ，Err" + err.Error())
	//				}
	//				if user != nil {
	//					fmt.Println(user.RealName, k)
	//					err = models.UpdateCygxActivityVideoHistory(user)
	//					if err != nil {
	//						fmt.Println("UpdateCygxActivityVideoHistory ，Err" + err.Error())
	//					}
	//				}
	//			}
	//		}
	//		// 处理用户的活动视频播放end
	//
	//		// 处理用户的活动音频播放
	//		listActivityVoice, err := models.GetActivityVoiceHistoryByMobileList(condition)
	//		if err != nil {
	//			fmt.Println("GetActivityVoiceHistoryByMobileList ，Err" + err.Error())
	//			return err
	//		}
	//		for k, v := range listActivityVoice {
	//			if v.Mobile != "" {
	//				user, err := models.GetWxUserItemByUserId(v.UserId)
	//				if err != nil && err.Error() != utils.ErrNoRow() {
	//					fmt.Println("GetWxUserItemByUserId ，Err" + err.Error())
	//				}
	//				if user != nil {
	//					fmt.Println(user.RealName, k)
	//					err = models.UpdateCygxActivityVoiceHistory(user)
	//					if err != nil {
	//						fmt.Println("UpdateCygxActivityVoiceHistory ，Err" + err.Error())
	//					}
	//				}
	//			}
	//		}
	//		// 处理用户的活动音频播放end
	//
	//		// 处理用户产业视频的播放记录
	//		listMicroRoadshow, err := models.GetMicroRoadshowVideoHistoryByMobileList(condition)
	//		if err != nil {
	//			fmt.Println("GetMicroRoadshowVideoHistoryByMobileList ，Err" + err.Error())
	//			return err
	//		}
	//		for k, v := range listMicroRoadshow {
	//			if v.Mobile != "" {
	//				user, err := models.GetWxUserItemByUserId(v.UserId)
	//				if err != nil && err.Error() != utils.ErrNoRow() {
	//					fmt.Println("GetWxUserItemByUserId ，Err" + err.Error())
	//				}
	//				if user != nil {
	//					fmt.Println(user.RealName, k)
	//					err = models.UpdateCygxMicroRoadshowVideoHistory(user)
	//					if err != nil {
	//						fmt.Println("UpdateCygxMicroRoadshowVideoHistory ，Err" + err.Error())
	//					}
	//				}
	//			}
	//		}
	//		// 处理用户产业视频的播放记录 end
	//
	//		//如果手机号不为空，则更新用户的报名信息
	//		if mobiles != "" {
	//			condition = ` AND mobile IN (` + mobiles + `)`
	//			listSingUp, err := models.GetCygxActivitySignupByMobileList(condition)
	//			if err != nil {
	//				fmt.Println("GetCygxChartCollectByMobileList ，Err" + err.Error())
	//			}
	//			//fmt.Println("更新用户的报名信息长度", len(listSingUp))
	//			for _, v := range listSingUp {
	//				if v.Mobile != "" {
	//					user, err := models.GetWxUserItemByMobile(v.Mobile)
	//					if err != nil && err.Error() != utils.ErrNoRow() {
	//						fmt.Println("GetWxUserItemByUserId ，Err" + err.Error())
	//					}
	//					if user != nil {
	//						err = models.UpdateCygxActivitySignup(user)
	//						if err != nil {
	//							fmt.Println("UpdateCygxActivitySignup ，Err" + err.Error())
	//							//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
	//		}
	//	}
	//}

	//处理用户、机构互动量数据
	{
		var userIds string
		var itemsInteraction []*models.CygxUserInteractionNum
		mapUserInteraction := make(map[int]int)
		mapCompanyInteraction := make(map[int]int)
		mapCompanyInteractionItem := make(map[int]*models.CygxCompanyInteractionNum)
		mapComapnyInteractionSeller := make(map[int]int)
		mapComapnyInteractionNumSeller := make(map[int]int) // 销售可查看的互动量
		//获取已经处理记录的用户并记录切片
		listUserInteractionNum, err := models.GetCygxUserInteractionNumList()
		if err != nil && err.Error() != utils.ErrNoRow() {
			fmt.Println("GetCygxUserInteractionNumList Err", err)
			return err
		}
		for _, v := range listUserInteractionNum {
			mapUserInteraction[v.UserId] = v.UserId
		}

		//获取跟销售建立绑定关系的用户并记录切片
		listUserSeller, err := models.GetUserSellerRelationUserList()
		if err != nil && err.Error() != utils.ErrNoRow() {
			fmt.Println("GetUserSellerRelationUserList Err", err)
			return err
		}
		for _, v := range listUserSeller {
			mapComapnyInteractionSeller[v.UserId] = v.UserId
		}

		listCompanyInteractionNum, err := models.GetCygxCompanyInteractionNumList()
		if err != nil && err.Error() != utils.ErrNoRow() {
			fmt.Println("GetCygxUserInteractionNumList Err", err)
			return err
		}
		for _, v := range listCompanyInteractionNum {
			mapCompanyInteraction[v.CompanyId] = v.CompanyId
		}

		//处理用户互动量数据
		for kUser, vUser := range listUser {
			userIds += strconv.Itoa(vUser.UserId) + ","
			//一次查询一百个避免用户过多
			if kUser%100 == 0 {
				userIds = strings.TrimRight(userIds, ",")
				userUserInteractionList, err := models.GetCygxCompanyUserUserInteraction(userIds)
				if err != nil {
					fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
					return err
				}
				//处理用户的互动量
				if len(userUserInteractionList) > 0 {
					for _, vsplit := range userUserInteractionList {
						interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum + vsplit.ChartCountNum + vsplit.TripNum + vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum + vsplit.TagNum
						if interactionNum > 0 {
							//更改用户的互动量
							err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
							if err != nil {
								fmt.Println("UpdateUserInteractionNum Err", err)
								return err
							}
							mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum

							itemInteraction := new(models.CygxUserInteractionNum)
							itemInteraction.UserId = int(vsplit.UserId)
							itemInteraction.ArticleHistoryNum = vsplit.HistoryNum
							itemInteraction.ArticleCountNum = vsplit.CountNum
							itemInteraction.ChartCountNum = vsplit.ChartCountNum
							itemInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
							itemInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
							itemInteraction.KeyWordNum = vsplit.KeyWordNum
							itemInteraction.ActivityOnLineNum = vsplit.OnLineNum
							itemInteraction.ActivityOfficeNum = vsplit.OfficeNum
							itemInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
							itemInteraction.TripNum = vsplit.TripNum
							itemInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
							itemInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
							itemInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
							itemInteraction.TagNum = vsplit.TagNum
							itemInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
							itemInteraction.CreateTime = time.Now()
							itemInteraction.ModifyTime = time.Now()

							//如果这个切片下的结构体没有值就给他初始值，如果有就跟后面的相加
							if mapCompanyInteractionItem[vsplit.CompanyId] == nil {
								itemCompanyInteraction := new(models.CygxCompanyInteractionNum)
								itemCompanyInteraction.CompanyId = vsplit.CompanyId
								itemCompanyInteraction.ArticleHistoryNum = vsplit.HistoryNum
								itemCompanyInteraction.ArticleCountNum = vsplit.CountNum
								itemCompanyInteraction.ChartCountNum = vsplit.ChartCountNum
								itemCompanyInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
								itemCompanyInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
								itemCompanyInteraction.KeyWordNum = vsplit.KeyWordNum
								itemCompanyInteraction.ActivityOnLineNum = vsplit.OnLineNum
								itemCompanyInteraction.ActivityOfficeNum = vsplit.OfficeNum
								itemCompanyInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
								itemCompanyInteraction.TripNum = vsplit.TripNum
								itemCompanyInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
								itemCompanyInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
								itemCompanyInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
								itemCompanyInteraction.TagNum = vsplit.TagNum
								itemCompanyInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
								mapCompanyInteractionItem[vsplit.CompanyId] = itemCompanyInteraction
								mapCompanyInteractionItem[vsplit.CompanyId].CreateTime = time.Now()
								mapCompanyInteractionItem[vsplit.CompanyId].ModifyTime = time.Now()
							} else {
								fmt.Println("公司ID", vsplit.CompanyId)
								mapCompanyInteractionItem[vsplit.CompanyId].CompanyId = vsplit.CompanyId
								mapCompanyInteractionItem[vsplit.CompanyId].ArticleHistoryNum += vsplit.HistoryNum
								mapCompanyInteractionItem[vsplit.CompanyId].ArticleCountNum += vsplit.CountNum
								mapCompanyInteractionItem[vsplit.CompanyId].ChartCountNum += vsplit.ChartCountNum
								mapCompanyInteractionItem[vsplit.CompanyId].IndustryFllowNum += vsplit.IndustryFllowNum
								mapCompanyInteractionItem[vsplit.CompanyId].DepartmentFollowNum += vsplit.DepartmentFollowNum
								mapCompanyInteractionItem[vsplit.CompanyId].KeyWordNum += vsplit.KeyWordNum
								mapCompanyInteractionItem[vsplit.CompanyId].ActivityOnLineNum += vsplit.OnLineNum
								mapCompanyInteractionItem[vsplit.CompanyId].ActivityOfficeNum += vsplit.OfficeNum
								mapCompanyInteractionItem[vsplit.CompanyId].ActivityNum += vsplit.OnLineNum + vsplit.OfficeNum
								mapCompanyInteractionItem[vsplit.CompanyId].TripNum += vsplit.TripNum
								mapCompanyInteractionItem[vsplit.CompanyId].RoadshowVideoNum += vsplit.RoadshowVideoNum
								mapCompanyInteractionItem[vsplit.CompanyId].ActivityVideoNum += vsplit.ActivityVideoNum
								mapCompanyInteractionItem[vsplit.CompanyId].ActivityVoiceNum += vsplit.ActivityVoiceNum
								mapCompanyInteractionItem[vsplit.CompanyId].TagNum += vsplit.TagNum
								mapCompanyInteractionItem[vsplit.CompanyId].RoadshowNum += vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum

							}

							//如果存在就修改不存在就新增
							if mapUserInteraction[int(vsplit.UserId)] == 0 {
								itemsInteraction = append(itemsInteraction, itemInteraction)
							} else {
								err = models.UpdateCygxUserInteractionNum(itemInteraction)
								if err != nil {
									fmt.Println("UpdateCygxUserInteractionNum Err", err)
									return err
								}
							}
						}
					}
				}
				userIds = ""
			}
		}

		userIds = strings.TrimRight(userIds, ",")
		if userIds != "" {
			userUserInteractionList, err := models.GetCygxCompanyUserUserInteraction(userIds)
			if err != nil {
				fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
				return err
			}
			//fmt.Println("处理用户剩余的")
			//处理用户的互动量
			if len(userUserInteractionList) > 0 {
				for _, vsplit := range userUserInteractionList {
					interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum + vsplit.ChartCountNum + vsplit.TripNum + vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum + vsplit.TagNum
					if interactionNum > 0 {
						err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
						if err != nil {
							fmt.Println("UpdateUserInteractionNum Err", err)
							return err
						}
						mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum

						if mapComapnyInteractionSeller[int(vsplit.UserId)] > 0 {
							mapComapnyInteractionNumSeller[vsplit.CompanyId] += interactionNum //如果销售可以看到这个人，那么就对销售可见的数量进行添加
						}

						itemInteraction := new(models.CygxUserInteractionNum)
						itemInteraction.UserId = int(vsplit.UserId)
						itemInteraction.ArticleHistoryNum = vsplit.HistoryNum
						itemInteraction.ArticleCountNum = vsplit.CountNum
						itemInteraction.ChartCountNum = vsplit.ChartCountNum
						itemInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
						itemInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
						itemInteraction.KeyWordNum = vsplit.KeyWordNum
						itemInteraction.ActivityOnLineNum = vsplit.OnLineNum
						itemInteraction.ActivityOfficeNum = vsplit.OfficeNum
						itemInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
						itemInteraction.TripNum = vsplit.TripNum
						itemInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
						itemInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
						itemInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
						itemInteraction.TagNum = vsplit.TagNum
						itemInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum

						//如果这个切片下的结构体没有值就给他初始值，如果有就跟后面的相加
						if mapCompanyInteractionItem[vsplit.CompanyId] == nil {
							itemCompanyInteraction := new(models.CygxCompanyInteractionNum)
							itemCompanyInteraction.CompanyId = vsplit.CompanyId
							itemCompanyInteraction.ArticleHistoryNum = vsplit.HistoryNum
							itemCompanyInteraction.ArticleCountNum = vsplit.CountNum
							itemCompanyInteraction.ChartCountNum = vsplit.ChartCountNum
							itemCompanyInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
							itemCompanyInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
							itemCompanyInteraction.KeyWordNum = vsplit.KeyWordNum
							itemCompanyInteraction.ActivityOnLineNum = vsplit.OnLineNum
							itemCompanyInteraction.ActivityOfficeNum = vsplit.OfficeNum
							itemCompanyInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
							itemCompanyInteraction.TripNum = vsplit.TripNum
							itemCompanyInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
							itemCompanyInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
							itemCompanyInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
							itemCompanyInteraction.TagNum = vsplit.TagNum
							itemCompanyInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
							mapCompanyInteractionItem[vsplit.CompanyId] = itemCompanyInteraction
							mapCompanyInteractionItem[vsplit.CompanyId].CreateTime = time.Now()
							mapCompanyInteractionItem[vsplit.CompanyId].ModifyTime = time.Now()
						} else {
							mapCompanyInteractionItem[vsplit.CompanyId].CompanyId = vsplit.CompanyId
							mapCompanyInteractionItem[vsplit.CompanyId].ArticleHistoryNum += vsplit.HistoryNum
							mapCompanyInteractionItem[vsplit.CompanyId].ArticleCountNum += vsplit.CountNum
							mapCompanyInteractionItem[vsplit.CompanyId].ChartCountNum += vsplit.ChartCountNum
							mapCompanyInteractionItem[vsplit.CompanyId].IndustryFllowNum += vsplit.IndustryFllowNum
							mapCompanyInteractionItem[vsplit.CompanyId].DepartmentFollowNum += vsplit.DepartmentFollowNum
							mapCompanyInteractionItem[vsplit.CompanyId].KeyWordNum += vsplit.KeyWordNum
							mapCompanyInteractionItem[vsplit.CompanyId].ActivityOnLineNum += vsplit.OnLineNum
							mapCompanyInteractionItem[vsplit.CompanyId].ActivityOfficeNum += vsplit.OfficeNum
							mapCompanyInteractionItem[vsplit.CompanyId].ActivityNum += vsplit.OnLineNum + vsplit.OfficeNum
							mapCompanyInteractionItem[vsplit.CompanyId].TripNum += vsplit.TripNum
							mapCompanyInteractionItem[vsplit.CompanyId].RoadshowVideoNum += vsplit.RoadshowVideoNum
							mapCompanyInteractionItem[vsplit.CompanyId].ActivityVideoNum += vsplit.ActivityVideoNum
							mapCompanyInteractionItem[vsplit.CompanyId].ActivityVoiceNum += vsplit.ActivityVoiceNum
							mapCompanyInteractionItem[vsplit.CompanyId].TagNum += vsplit.TagNum
							mapCompanyInteractionItem[vsplit.CompanyId].RoadshowNum += vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
						}

						//如果存在就修改不存在就新增
						if mapUserInteraction[int(vsplit.UserId)] == 0 {
							itemsInteraction = append(itemsInteraction, itemInteraction)
						} else {
							err = models.UpdateCygxUserInteractionNum(itemInteraction)
							if err != nil {
								fmt.Println("UpdateCygxUserInteractionNum Err", err)
								return err
							}
							//fmt.Println(itemInteraction.UserId)
							//err = models.UpdateCygxUserInteractionNum(itemInteraction)
						}
					}
				}
			}
		}
		fmt.Println("修改机构互动量信息")
		////修改机构互动量信息
		if len(mapComapnyInteractionNum) > 0 {
			for k, v := range mapComapnyInteractionNum {
				companyId := k
				err = models.UpdateComapanyInteractionNum(v, mapComapnyInteractionNumSeller[companyId], companyId)
				if err != nil {
					fmt.Println(" AddCygxUserInteractionNumList Err", err)
				}
			}
		}

		// 批量添加用户互动量信息
		if len(itemsInteraction) > 0 {
			_, err = models.AddCygxUserInteractionNumList(itemsInteraction)
			if err != nil {
				fmt.Println(" AddCygxUserInteractionNumList Err", err)
			}
		}

		// 批量添加用户互动量信息
		if len(mapCompanyInteractionItem) > 0 {
			fmt.Println("添加机构互动信息")
			for _, v := range mapCompanyInteractionItem {
				fmt.Println(v.CompanyId)
				if mapCompanyInteraction[v.CompanyId] > 0 {
					err = models.UpdateCygxCompanyInteractionNum(v)
					if err != nil {
						fmt.Println(" UpdateCygxCompanyInteractionNum Err", err)
					}
				} else {
					_, err = models.AddCygxCompanyInteractionNum(v)
					if err != nil {
						fmt.Println(" AddCygxCompanyInteractionNum Err", err)
					}
				}
			}
		}
	}

	//更新用户标签以及权重
	//go UpdateUserLabelWeight()
	return
}

func init123123() {
	var err error
	defer func() {
		if err != nil {
			go utils.SendAlarmMsg("更新用户标签失败;Err:"+err.Error(), 2)
		}
	}()
	var interactionNum int
	mapComapnyInteractionNum := make(map[int]int)

	listUser, err := models.GetUserRegisterListinit()
	if err != nil && err.Error() != utils.ErrNoRow() {
		fmt.Println("GetUserSellerRelationUserList Err", err)
		return
	}

	fmt.Println(len(listUser))
	//return
	//处理用户、机构互动量数据
	{
		var userIds string
		var itemsInteraction []*models.CygxUserInteractionNum
		mapUserInteraction := make(map[int]int)
		mapCompanyInteraction := make(map[int]int)
		mapCompanyInteractionItem := make(map[int]*models.CygxCompanyInteractionNum)
		mapComapnyInteractionSeller := make(map[int]int)
		mapComapnyInteractionNumSeller := make(map[int]int) // 销售可查看的互动量
		//获取已经处理记录的用户并记录切片
		listUserInteractionNum, err := models.GetCygxUserInteractionNumList()
		if err != nil && err.Error() != utils.ErrNoRow() {
			fmt.Println("GetCygxUserInteractionNumList Err", err)
			return
		}
		for _, v := range listUserInteractionNum {
			mapUserInteraction[v.UserId] = v.UserId
		}

		//获取跟销售建立绑定关系的用户并记录切片
		listUserSeller, err := models.GetUserSellerRelationUserList()
		if err != nil && err.Error() != utils.ErrNoRow() {
			fmt.Println("GetUserSellerRelationUserList Err", err)
			return
		}
		for _, v := range listUserSeller {
			mapComapnyInteractionSeller[v.UserId] = v.UserId
		}

		listCompanyInteractionNum, err := models.GetCygxCompanyInteractionNumList()
		if err != nil && err.Error() != utils.ErrNoRow() {
			fmt.Println("GetCygxUserInteractionNumList Err", err)
			return
		}
		for _, v := range listCompanyInteractionNum {
			mapCompanyInteraction[v.CompanyId] = v.CompanyId
		}

		//处理用户互动量数据
		for kUser, vUser := range listUser {
			userIds += strconv.Itoa(vUser.UserId) + ","
			//一次查询一百个避免用户过多
			if kUser%100 == 0 {
				userIds = strings.TrimRight(userIds, ",")
				userUserInteractionList, err := models.GetCygxCompanyUserUserInteraction(userIds)
				if err != nil {
					fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
					return
				}
				//处理用户的互动量
				if len(userUserInteractionList) > 0 {
					for _, vsplit := range userUserInteractionList {
						interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum + vsplit.ChartCountNum + vsplit.TripNum + vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum + vsplit.TagNum
						if interactionNum > 0 {
							//更改用户的互动量
							err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
							if err != nil {
								fmt.Println("UpdateUserInteractionNum Err", err)
								return
							}
							mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum

							itemInteraction := new(models.CygxUserInteractionNum)
							itemInteraction.UserId = int(vsplit.UserId)
							itemInteraction.ArticleHistoryNum = vsplit.HistoryNum
							itemInteraction.ArticleCountNum = vsplit.CountNum
							itemInteraction.ChartCountNum = vsplit.ChartCountNum
							itemInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
							itemInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
							itemInteraction.KeyWordNum = vsplit.KeyWordNum
							itemInteraction.ActivityOnLineNum = vsplit.OnLineNum
							itemInteraction.ActivityOfficeNum = vsplit.OfficeNum
							itemInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
							itemInteraction.TripNum = vsplit.TripNum
							itemInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
							itemInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
							itemInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
							itemInteraction.TagNum = vsplit.TagNum
							itemInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
							itemInteraction.CreateTime = time.Now()
							itemInteraction.ModifyTime = time.Now()

							//如果这个切片下的结构体没有值就给他初始值，如果有就跟后面的相加
							if mapCompanyInteractionItem[vsplit.CompanyId] == nil {
								itemCompanyInteraction := new(models.CygxCompanyInteractionNum)
								itemCompanyInteraction.CompanyId = vsplit.CompanyId
								itemCompanyInteraction.ArticleHistoryNum = vsplit.HistoryNum
								itemCompanyInteraction.ArticleCountNum = vsplit.CountNum
								itemCompanyInteraction.ChartCountNum = vsplit.ChartCountNum
								itemCompanyInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
								itemCompanyInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
								itemCompanyInteraction.KeyWordNum = vsplit.KeyWordNum
								itemCompanyInteraction.ActivityOnLineNum = vsplit.OnLineNum
								itemCompanyInteraction.ActivityOfficeNum = vsplit.OfficeNum
								itemCompanyInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
								itemCompanyInteraction.TripNum = vsplit.TripNum
								itemCompanyInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
								itemCompanyInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
								itemCompanyInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
								itemCompanyInteraction.TagNum = vsplit.TagNum
								itemCompanyInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
								mapCompanyInteractionItem[vsplit.CompanyId] = itemCompanyInteraction
								mapCompanyInteractionItem[vsplit.CompanyId].CreateTime = time.Now()
								mapCompanyInteractionItem[vsplit.CompanyId].ModifyTime = time.Now()
							} else {
								fmt.Println("公司ID", vsplit.CompanyId)
								mapCompanyInteractionItem[vsplit.CompanyId].CompanyId = vsplit.CompanyId
								mapCompanyInteractionItem[vsplit.CompanyId].ArticleHistoryNum += vsplit.HistoryNum
								mapCompanyInteractionItem[vsplit.CompanyId].ArticleCountNum += vsplit.CountNum
								mapCompanyInteractionItem[vsplit.CompanyId].ChartCountNum += vsplit.ChartCountNum
								mapCompanyInteractionItem[vsplit.CompanyId].IndustryFllowNum += vsplit.IndustryFllowNum
								mapCompanyInteractionItem[vsplit.CompanyId].DepartmentFollowNum += vsplit.DepartmentFollowNum
								mapCompanyInteractionItem[vsplit.CompanyId].KeyWordNum += vsplit.KeyWordNum
								mapCompanyInteractionItem[vsplit.CompanyId].ActivityOnLineNum += vsplit.OnLineNum
								mapCompanyInteractionItem[vsplit.CompanyId].ActivityOfficeNum += vsplit.OfficeNum
								mapCompanyInteractionItem[vsplit.CompanyId].ActivityNum += vsplit.OnLineNum + vsplit.OfficeNum
								mapCompanyInteractionItem[vsplit.CompanyId].TripNum += vsplit.TripNum
								mapCompanyInteractionItem[vsplit.CompanyId].RoadshowVideoNum += vsplit.RoadshowVideoNum
								mapCompanyInteractionItem[vsplit.CompanyId].ActivityVideoNum += vsplit.ActivityVideoNum
								mapCompanyInteractionItem[vsplit.CompanyId].ActivityVoiceNum += vsplit.ActivityVoiceNum
								mapCompanyInteractionItem[vsplit.CompanyId].TagNum += vsplit.TagNum
								mapCompanyInteractionItem[vsplit.CompanyId].RoadshowNum += vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum

							}

							//如果存在就修改不存在就新增
							if mapUserInteraction[int(vsplit.UserId)] == 0 {
								itemsInteraction = append(itemsInteraction, itemInteraction)
							} else {
								err = models.UpdateCygxUserInteractionNum(itemInteraction)
								if err != nil {
									fmt.Println("UpdateCygxUserInteractionNum Err", err)
									return
								}
								fmt.Println(itemInteraction.UserId)
							}
						}
					}
				}
				userIds = ""
			}
		}

		userIds = strings.TrimRight(userIds, ",")
		if userIds != "" {
			userUserInteractionList, err := models.GetCygxCompanyUserUserInteraction(userIds)
			if err != nil {
				fmt.Println("GetCygxCompanyUserUserInteraction Err", err)
				return
			}
			//fmt.Println("处理用户剩余的")
			//处理用户的互动量
			if len(userUserInteractionList) > 0 {
				for _, vsplit := range userUserInteractionList {
					interactionNum = vsplit.HistoryNum + vsplit.CountNum + vsplit.IndustryFllowNum + vsplit.DepartmentFollowNum + vsplit.KeyWordNum + vsplit.OnLineNum + vsplit.OfficeNum + vsplit.ChartCountNum + vsplit.TripNum + vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum + vsplit.TagNum
					if interactionNum > 0 {
						err = models.UpdateUserInteractionNum(interactionNum, int(vsplit.UserId))
						if err != nil {
							fmt.Println("UpdateUserInteractionNum Err", err)
							return
						}
						mapComapnyInteractionNum[vsplit.CompanyId] += interactionNum

						if mapComapnyInteractionSeller[int(vsplit.UserId)] > 0 {
							mapComapnyInteractionNumSeller[vsplit.CompanyId] += interactionNum //如果销售可以看到这个人，那么就对销售可见的数量进行添加
						}

						itemInteraction := new(models.CygxUserInteractionNum)
						itemInteraction.UserId = int(vsplit.UserId)
						itemInteraction.ArticleHistoryNum = vsplit.HistoryNum
						itemInteraction.ArticleCountNum = vsplit.CountNum
						itemInteraction.ChartCountNum = vsplit.ChartCountNum
						itemInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
						itemInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
						itemInteraction.KeyWordNum = vsplit.KeyWordNum
						itemInteraction.ActivityOnLineNum = vsplit.OnLineNum
						itemInteraction.ActivityOfficeNum = vsplit.OfficeNum
						itemInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
						itemInteraction.TripNum = vsplit.TripNum
						itemInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
						itemInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
						itemInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
						itemInteraction.TagNum = vsplit.TagNum
						itemInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum

						//如果这个切片下的结构体没有值就给他初始值，如果有就跟后面的相加
						if mapCompanyInteractionItem[vsplit.CompanyId] == nil {
							itemCompanyInteraction := new(models.CygxCompanyInteractionNum)
							itemCompanyInteraction.CompanyId = vsplit.CompanyId
							itemCompanyInteraction.ArticleHistoryNum = vsplit.HistoryNum
							itemCompanyInteraction.ArticleCountNum = vsplit.CountNum
							itemCompanyInteraction.ChartCountNum = vsplit.ChartCountNum
							itemCompanyInteraction.IndustryFllowNum = vsplit.IndustryFllowNum
							itemCompanyInteraction.DepartmentFollowNum = vsplit.DepartmentFollowNum
							itemCompanyInteraction.KeyWordNum = vsplit.KeyWordNum
							itemCompanyInteraction.ActivityOnLineNum = vsplit.OnLineNum
							itemCompanyInteraction.ActivityOfficeNum = vsplit.OfficeNum
							itemCompanyInteraction.ActivityNum = vsplit.OnLineNum + vsplit.OfficeNum
							itemCompanyInteraction.TripNum = vsplit.TripNum
							itemCompanyInteraction.RoadshowVideoNum = vsplit.RoadshowVideoNum
							itemCompanyInteraction.ActivityVideoNum = vsplit.ActivityVideoNum
							itemCompanyInteraction.ActivityVoiceNum = vsplit.ActivityVoiceNum
							itemCompanyInteraction.TagNum = vsplit.TagNum
							itemCompanyInteraction.RoadshowNum = vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
							mapCompanyInteractionItem[vsplit.CompanyId] = itemCompanyInteraction
							mapCompanyInteractionItem[vsplit.CompanyId].CreateTime = time.Now()
							mapCompanyInteractionItem[vsplit.CompanyId].ModifyTime = time.Now()
						} else {
							mapCompanyInteractionItem[vsplit.CompanyId].CompanyId = vsplit.CompanyId
							mapCompanyInteractionItem[vsplit.CompanyId].ArticleHistoryNum += vsplit.HistoryNum
							mapCompanyInteractionItem[vsplit.CompanyId].ArticleCountNum += vsplit.CountNum
							mapCompanyInteractionItem[vsplit.CompanyId].ChartCountNum += vsplit.ChartCountNum
							mapCompanyInteractionItem[vsplit.CompanyId].IndustryFllowNum += vsplit.IndustryFllowNum
							mapCompanyInteractionItem[vsplit.CompanyId].DepartmentFollowNum += vsplit.DepartmentFollowNum
							mapCompanyInteractionItem[vsplit.CompanyId].KeyWordNum += vsplit.KeyWordNum
							mapCompanyInteractionItem[vsplit.CompanyId].ActivityOnLineNum += vsplit.OnLineNum
							mapCompanyInteractionItem[vsplit.CompanyId].ActivityOfficeNum += vsplit.OfficeNum
							mapCompanyInteractionItem[vsplit.CompanyId].ActivityNum += vsplit.OnLineNum + vsplit.OfficeNum
							mapCompanyInteractionItem[vsplit.CompanyId].TripNum += vsplit.TripNum
							mapCompanyInteractionItem[vsplit.CompanyId].RoadshowVideoNum += vsplit.RoadshowVideoNum
							mapCompanyInteractionItem[vsplit.CompanyId].ActivityVideoNum += vsplit.ActivityVideoNum
							mapCompanyInteractionItem[vsplit.CompanyId].ActivityVoiceNum += vsplit.ActivityVoiceNum
							mapCompanyInteractionItem[vsplit.CompanyId].TagNum += vsplit.TagNum
							mapCompanyInteractionItem[vsplit.CompanyId].RoadshowNum += vsplit.RoadshowVideoNum + vsplit.ActivityVideoNum + vsplit.ActivityVoiceNum
						}

						////如果存在就修改不存在就新增
						//if mapUserInteraction[int(vsplit.UserId)] == 0 {
						//	itemsInteraction = append(itemsInteraction, itemInteraction)
						//} else {
						//	err = models.UpdateCygxUserInteractionNum(itemInteraction)
						//	if err != nil {
						//		fmt.Println("UpdateCygxUserInteractionNum Err", err)
						//		return
						//	}
						//	fmt.Println(itemInteraction.UserId)
						//	err = models.UpdateCygxUserInteractionNum(itemInteraction)
						//}
					}
				}
			}
		}
		fmt.Println("修改机构互动量信息")
		////修改机构互动量信息
		if len(mapComapnyInteractionNum) > 0 {
			for k, v := range mapComapnyInteractionNum {
				companyId := k
				err = models.UpdateComapanyInteractionNum(v, mapComapnyInteractionNumSeller[companyId], companyId)
				if err != nil {
					fmt.Println(" AddCygxUserInteractionNumList Err", err)
				}
			}
		}
	}
}

//func init() {
//	UpdateWxUserLabelNew()
//}

func UpdateWxUserLabel(cont context.Context) (err error) {
	//func UpdateWxUserLabel() (err error) {
	defer func() {
		if err != nil {
			fmt.Println(err)
			go utils.SendAlarmMsg(fmt.Sprint("更新用户标签失败UpdateWxUserLabel, err：", err.Error()), 2)
		}
	}()

	mapComapnyInteractionNum := make(map[int]int)                                   // 机构互动数量
	mapComapnyInteractionNumSeller := make(map[int]int)                             // 销售可查看的机构互动数量
	mapComapnyInteractionSeller := make(map[int]bool)                               // 跟销售建立绑定关系的用户
	mapComapnyInteractionNumItem := make(map[int]*models.CygxCompanyInteractionNum) // 公司互动详情结构体
	var comapnyInteractionNumItemAdd []*models.CygxCompanyInteractionNum            // 公司互动详情结构体新增
	var comapnyInteractionNumItemUpdate []*models.CygxCompanyInteractionNum         // 公司互动详情结构体修改

	//获取跟销售建立绑定关系的用户并记录切片
	listUserSeller, e := models.GetUserSellerRelationUserList()
	if e != nil && e.Error() != utils.ErrNoRow() {
		err = errors.New("GetUserSellerRelationUserList, Err: " + e.Error())
		return
	}
	for _, v := range listUserSeller {
		mapComapnyInteractionSeller[v.UserId] = true
	}

	var condition string
	//condition = ` AND h.create_time < '%s'  AND h.company_id IN ( 398,17773)  `
	condition = ` AND h.create_time < '%s'  `
	condition = fmt.Sprintf(condition, time.Now().Format(utils.FormatDate)) // 截止昨天的所有数据

	//fmt.Println(condition)
	//报告阅读记录1
	{
		listArticleHistoryRecord, e := models.GetCygxArticleHistoryRecordInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxArticleHistoryRecordInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listArticleHistoryRecord {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}
			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].ArticleHistoryNum += v.InteractionNum
		}

	}

	//报告收藏记录2
	{
		listArticleCollect, e := models.GetCygxArticleCollectInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxArticleCollectInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listArticleCollect {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}

			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].ArticleCountNum += v.InteractionNum
		}
	}

	//图表收藏记录3
	{
		listChartCollect, e := models.GetCygxChartCollectInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxChartCollectInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listChartCollect {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}
			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].ChartCountNum += v.InteractionNum
		}
	}

	//用户关注产业数量4
	{
		listIndustryFllow, e := models.GetCygxIndustryFllowInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxIndustryFllowInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listIndustryFllow {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}
			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].IndustryFllowNum += v.InteractionNum
		}
	}

	//用户搜索关键词数量5
	{
		listSearchKeyWord, e := models.GetCygxSearchKeyWordInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxSearchKeyWordInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listSearchKeyWord {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}
			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].KeyWordNum += v.InteractionNum
		}
	}

	//用户活动报名参会数量6
	{
		listActivitySignup, e := models.GetCygxActivitySignupInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxActivitySignupInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listActivitySignup {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}
			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].ActivityNum += v.InteractionNum
		}
	}

	//用户专项调研活动报名参会数量7
	{
		listActivitySpecialSignup, e := models.GetCygxActivitySpecialSignupInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxActivitySpecialSignupInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listActivitySpecialSignup {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}
			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].TripNum += v.InteractionNum
		}
	}

	//用户路演精华播放数量8
	{
		listMicroRoadshowVideoHistory, e := models.GetCygxMicroRoadshowVideoHistoryInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxMicroRoadshowVideoHistoryInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listMicroRoadshowVideoHistory {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}
			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].RoadshowNum += v.InteractionNum
		}
	}

	//用户活动视频播放数量9
	{
		listActivityVideoHistory, e := models.GetCygxActivityVideoHistoryInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxActivityVideoHistoryInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listActivityVideoHistory {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}
			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].ActivityVideoNum += v.InteractionNum
		}
	}

	//用户活动音频播放数量10
	{
		listActivityVoiceHistory, e := models.GetCygxActivityVoiceHistoryInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxActivityVoiceHistoryInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listActivityVoiceHistory {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}
			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].ActivityVoiceNum += v.InteractionNum
		}
	}

	//用户首页标签点击量数量11
	{
		listTagHistory, e := models.GetCygxTagHistoryInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxTagHistoryInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listTagHistory {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}
			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].TagNum += v.InteractionNum
		}
	}

	//用户关注文章作者数量12
	{
		listArticleDepartmentFollow, e := models.GetCygxArticleDepartmentFollowInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxArticleDepartmentFollowInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listArticleDepartmentFollow {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}
			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].DepartmentFollowNum += v.InteractionNum
		}
	}

	//用户收藏研选专栏数量13
	//{
	//	listYanxuanSpecialCollect, e := models.GetCygxYanxuanSpecialCollectInteractionNum(condition)
	//	if e != nil {
	//		err = errors.New("GetCygxYanxuanSpecialCollectInteractionNum, Err: " + e.Error())
	//		return
	//	}
	//	for _, v := range listYanxuanSpecialCollect {
	//		mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
	//		if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
	//			mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
	//		}
	//
	//		if mapComapnyInteractionNumItem[v.CompanyId] == nil {
	//			mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
	//		}
	//		mapComapnyInteractionNumItem[v.CompanyId].YanxuanSpecialCollectNum += v.InteractionNum
	//	}
	//}

	//用户关注研选专栏作者数量统计14
	//{
	//	listYanxuanSpecialFollow, e := models.GetCygxYanxuanSpecialFollowInteractionNum(condition)
	//	if e != nil {
	//		err = errors.New("GetCygxYanxuanSpecialFollowInteractionNum, Err: " + e.Error())
	//		return
	//	}
	//	for _, v := range listYanxuanSpecialFollow {
	//		mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
	//		if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
	//			mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
	//		}
	//		if mapComapnyInteractionNumItem[v.CompanyId] == nil {
	//			mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
	//		}
	//		mapComapnyInteractionNumItem[v.CompanyId].YanxuanSpecialFollowNum += v.InteractionNum
	//	}
	//}

	//用户研选专栏阅读数量数量15
	{
		listYanxuanSpecialFollow, e := models.GetCygxYanxuanSpecialRecordInteractionNum(condition)
		if e != nil {
			err = errors.New("GetCygxYanxuanSpecialRecordInteractionNum, Err: " + e.Error())
			return
		}
		for _, v := range listYanxuanSpecialFollow {
			mapComapnyInteractionNum[v.CompanyId] += v.InteractionNum
			if mapComapnyInteractionSeller[v.UserId] { //如果用户跟销售建立绑定关系，就对互动量进行累加
				mapComapnyInteractionNumSeller[v.CompanyId] += v.InteractionNum
			}

			if mapComapnyInteractionNumItem[v.CompanyId] == nil {
				mapComapnyInteractionNumItem[v.CompanyId] = new(models.CygxCompanyInteractionNum)
			}
			mapComapnyInteractionNumItem[v.CompanyId].YanxuanSpecialNum += v.InteractionNum
		}
	}

	mapCompanyInteraction := make(map[int]bool)
	mapCompanyInteractionItem := make(map[int]*models.CygxCompanyInteractionNum)
	listCompanyInteractionNum, e := models.GetCygxCompanyInteractionNumList() // 有过互动记录的公司
	if e != nil && e.Error() != utils.ErrNoRow() {
		err = errors.New("GetCygxCompanyInteractionNumList, Err: " + e.Error())
		return
	}

	for _, v := range listCompanyInteractionNum {
		mapCompanyInteraction[v.CompanyId] = true
		mapCompanyInteractionItem[v.CompanyId] = v

	}

	var itemsCompanyInteractionNums []*models.CompanyInteractionNumReq // 公司总的互动量结构体

	companyInteractionNumList, e := models.GetCompanyInteractionNumList() // 获取有机构互动的公司
	mapInteractionNumOld := make(map[int]int)                             //历史公司总的互动量
	mapInteractionNumSellerOld := make(map[int]int)                       //历史公司关联销售所能查看的互动量
	for _, v := range companyInteractionNumList {
		mapInteractionNumOld[v.CompanyId] = v.InteractionNum
		mapInteractionNumSellerOld[v.CompanyId] = v.InteractionNumSeller
	}

	for k, v := range mapComapnyInteractionNumItem {
		v.CompanyId = k
		if mapCompanyInteraction[k] {
			itemOld := mapCompanyInteractionItem[v.CompanyId]

			//ArticleHistoryNum        int       `description:"文章浏览数量"`
			//ArticleCountNum          int       `description:"文章收藏数量"`
			//ChartCountNum            int       `description:"图表收藏"`
			//IndustryFllowNum         int       `description:"产业关注数量"`
			//DepartmentFollowNum      int       `description:"作者关注数量"`
			//KeyWordNum               int       `description:"关键词搜索次数"`
			//ActivityOnLineNum        int       `description:"线上活动报名次数"`
			//ActivityOfficeNum        int       `description:"线下活动报名次数"`
			//ActivityNum              int       `description:"活动报名次数"`
			//TripNum                  int       `description:"专项产业调研数量"`
			//RoadshowVideoNum         int       `description:"产业视频播放量"`
			//ActivityVideoNum         int       `description:"活动视频播放量"`
			//ActivityVoiceNum         int       `description:"活动音频播放量"`
			//RoadshowNum              int       `description:"路演播放总数量"`
			//TagNum                   int       `description:"标签点击次数"`
			//YanxuanSpecialNum        int       `description:"研选专栏阅读数量"`
			//YanxuanSpecialCollectNum int       `description:"研选专栏收藏数量"`
			//YanxuanSpecialFollowNum  int       `description:"研选专栏作者关注数量"`

			//如果这些数据对比不一样，那么就对这条数据进行更新
			//if itemOld != nil && (itemOld.ArticleHistoryNum != v.ArticleHistoryNum || itemOld.ArticleCountNum != v.ArticleCountNum || itemOld.ChartCountNum != v.ChartCountNum || itemOld.IndustryFllowNum != v.IndustryFllowNum || itemOld.DepartmentFollowNum != v.DepartmentFollowNum || itemOld.KeyWordNum != v.KeyWordNum || itemOld.ActivityNum != v.ActivityNum || itemOld.TripNum != v.TripNum || itemOld.RoadshowVideoNum != v.RoadshowVideoNum || itemOld.ActivityVideoNum != v.ActivityVideoNum || itemOld.ActivityVoiceNum != v.ActivityVoiceNum || itemOld.RoadshowNum != v.RoadshowNum || itemOld.TagNum != v.TagNum || itemOld.YanxuanSpecialNum != v.YanxuanSpecialNum || itemOld.YanxuanSpecialCollectNum != v.YanxuanSpecialCollectNum || itemOld.YanxuanSpecialFollowNum != v.YanxuanSpecialFollowNum) {
			if itemOld != nil && (itemOld.ArticleHistoryNum != v.ArticleHistoryNum || itemOld.ArticleCountNum != v.ArticleCountNum || itemOld.ChartCountNum != v.ChartCountNum || itemOld.IndustryFllowNum != v.IndustryFllowNum || itemOld.DepartmentFollowNum != v.DepartmentFollowNum || itemOld.KeyWordNum != v.KeyWordNum || itemOld.ActivityNum != v.ActivityNum || itemOld.TripNum != v.TripNum || itemOld.RoadshowVideoNum != v.RoadshowVideoNum || itemOld.ActivityVideoNum != v.ActivityVideoNum || itemOld.ActivityVoiceNum != v.ActivityVoiceNum || itemOld.RoadshowNum != v.RoadshowNum || itemOld.TagNum != v.TagNum) {
				comapnyInteractionNumItemUpdate = append(comapnyInteractionNumItemUpdate, v)
			}

		} else {
			v.CreateTime = time.Now()
			v.ModifyTime = time.Now()
			comapnyInteractionNumItemAdd = append(comapnyInteractionNumItemAdd, v)
		}

		//对比历史数据如果不一样就进行修改
		if mapInteractionNumOld[v.CompanyId] != mapComapnyInteractionNum[v.CompanyId] || mapInteractionNumSellerOld[v.CompanyId] != mapComapnyInteractionNumSeller[v.CompanyId] {
			itemCompanyInteractionNums := new(models.CompanyInteractionNumReq)
			itemCompanyInteractionNums.CompanyId = k
			itemCompanyInteractionNums.InteractionNum = mapComapnyInteractionNum[v.CompanyId]
			itemCompanyInteractionNums.InteractionNumSeller = mapComapnyInteractionNumSeller[v.CompanyId]
			itemsCompanyInteractionNums = append(itemsCompanyInteractionNums, itemCompanyInteractionNums)
		}

	}

	//for _, v := range comapnyInteractionNumItemUpdate {
	//	fmt.Println(v)
	//}

	//return

	//批量插入公司互动详情
	if len(comapnyInteractionNumItemAdd) > 0 {
		_, e = models.AddCygxCompanyInteractionNumList(comapnyInteractionNumItemAdd)
		if e != nil {
			err = errors.New("AddCygxCompanyInteractionNumList, Err: " + e.Error())
			return
		}
	}

	// 批量修改公司互动详情
	if len(comapnyInteractionNumItemUpdate) > 0 {
		e = models.UpdateCygxCompanyInteractionNumMulti(comapnyInteractionNumItemUpdate)
		if e != nil {
			err = errors.New("UpdateCygxCompanyInteractionNumMulti, Err: " + e.Error())
			return
		}
	}

	// 批量修改公司互动总量
	if len(itemsCompanyInteractionNums) > 0 {
		e = models.UpdateCompanyInteractionNumMulti(itemsCompanyInteractionNums)
		if e != nil {
			err = errors.New("UpdateCompanyInteractionNumMulti, Err: " + e.Error())
			return
		}
	}

	//CompanyInteractionNumReq
	fmt.Println("add", len(comapnyInteractionNumItemAdd))
	fmt.Println("edit", len(comapnyInteractionNumItemUpdate))
	fmt.Println("Update", len(itemsCompanyInteractionNums))

	//fmt.Println(mapComapnyInteractionNum)
	return
}

func GetWxUserEndDate(user *models.WxUserItem) (isShowTerminateButton bool, endDataButton string) {
	companyId := user.CompanyId
	userId := user.UserId
	if companyId <= 1 {
		return
	}
	//添加一个key拦截
	key := "CYGX_WX_USER_END_DATE_KEY" + fmt.Sprint("C_", companyId, "U_", userId)
	if utils.Rc.IsExist(key) {
		return
	}
	utils.Rc.Put(key, 1, 3*time.Second)
	var err error
	defer func() {
		if err != nil {
			fmt.Println(err)
			go utils.SendAlarmMsg(fmt.Sprint("权益正式客户到期前30天弹窗消息提醒 失败GetWxUserEndDate, err：", err.Error(), "UserId", userId), 2)
		}
	}()
	productDetailCount, e := company.GetCompanyProductDetailByCompanyIdCount(companyId, 2)
	if e != nil {
		err = errors.New("GetCompanyProductDetailByCompanyIdCount, Err: " + e.Error())
		return
	}
	if productDetailCount == 0 {
		return
	}

	productDetail, e := company.GetCompanyProductDetailByCompanyId(companyId, 2)
	if e != nil {
		err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
		return
	}
	if productDetail.Status != utils.COMPANY_STATUS_FORMAL { // 不是正式状态不做处理
		return
	}
	endDate := utils.StrDateToTime(productDetail.EndDate)
	diff := endDate.Sub(time.Now())
	// 将差值转换为天数
	diffDay := int(diff.Hours() / 24)
	if endDate.After(time.Now()) {
		diffDay += 1 //不足一天的按照一天计算
	}
	if diffDay <= 30 {
		total, e := wx_user.GeWxUserEndDateLogCount(userId, productDetail.EndDate)
		if e != nil {
			err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
			return
		}

		if total == 0 {
			isShowTerminateButton = true
			endDataButton = productDetail.EndDate
			item := wx_user.WxUserEndDateLog{
				UserId:      user.UserId,
				Mobile:      user.Mobile,
				Email:       user.Email,
				CompanyId:   user.CompanyId,
				CompanyName: user.CompanyName,
				RealName:    user.RealName,
				EndDate:     endDataButton,
				CreateTime:  time.Now(),
				ModifyTime:  time.Now(),
			}
			_, e = wx_user.AddWxUserEndDateLog(&item)
			if e != nil {
				err = errors.New("AddWxUserEndDateLog, Err: " + e.Error())
				return
			}
			return
		}
	}
	return
}

// 获取某一个公司下所有用户的手机号
func GetUserMobileByComapnyId(comppanyId int) (mobileArr []string) {
	var err error
	defer func() {
		if err != nil {
			fmt.Println(err)
			go utils.SendAlarmMsg(fmt.Sprint("获取某一个公司下所有用户的手机号 失败 comppanyId", comppanyId, "err", err.Error()), 2)
		}
	}()
	listUser, e := models.GetWxUserListByCompanyId(comppanyId)
	if e != nil {
		err = errors.New("GetWxUserListByCompanyId" + e.Error())
		return
	}
	for _, v := range listUser {
		mobileArr = append(mobileArr, v.Mobile)
	}
	return
}
