Browse Source

Merge branch 'cygx_10.5.1' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

# Conflicts:
#	models/db.go
xingzai 1 year ago
parent
commit
0933f699fa

+ 2 - 2
controllers/report.go

@@ -894,8 +894,8 @@ func (this *ReportController) Fllow() {
 		}
 	}
 
-	//处理是否关注全部赛道字段
-	go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
+	go services.IndustryFllowWithTrack(industrialManagementId, count, uid)       //处理是否关注全部赛道字段
+	go services.IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid) //处理用户标签
 	br.Msg = "操作成功"
 	br.Ret = 200
 	br.Success = true

+ 1 - 0
models/db.go

@@ -147,6 +147,7 @@ func init() {
 		new(CygxBannerHistory),
 		new(CygxActivitySignupBreak),
 		new(CygxReportHistoryRecordLog),
+		new(CygxUserLabel),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 56 - 0
models/user_label.go

@@ -0,0 +1,56 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserLabelLogRedis struct {
+	UserId     int       `description:"用户ID"`
+	SourceId   int       `description:"资源ID"`
+	SourceType int       `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
+	IsFllow    int       `description:"1关注、0取消关注"`
+	CreateTime time.Time `description:"创建时间"`
+}
+
+type CygxUserLabel struct {
+	Id         int       `orm:"column(id);pk"`
+	UserId     int       `description:"用户ID"`
+	CompanyId  int       `description:"公司id"`
+	RealName   string    `description:"用户实际名称"`
+	Mobile     string    `description:"手机号"`
+	Email      string    `description:"邮箱"`
+	Label      string    `description:"标签内容"`
+	Weight     int       `description:"权重"`
+	SourceId   int       `description:"来源ID(产业ID,系列ID)"`
+	Source     int       `description:"来源1:产业、2:系列"`
+	IsFollow   int       `description:"是否关注,1是,0否"`
+	CreateTime time.Time `description:"创建时间"`
+	ModifyTime time.Time `description:"更新时间"`
+}
+
+// 获取数量
+func GetCygxUserLabelCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_user_label as art WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// 添加
+func AddCygxUserLabel(item *CygxUserLabel) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// 修改是否关注
+func UpdateCygxUserLabelIsFollow(isFollow, sourceId, source int, label string) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_user_label SET is_follow=?,label = ?  modify_time=NOW()  WHERE source_id=? AND source = ? `
+	_, err = o.Raw(sql, isFollow, label, sourceId, source).Exec()
+	return
+}

+ 30 - 0
services/industrial_management.go

@@ -299,6 +299,36 @@ func IndustryFllowWithTrack(industrialManagementId, count, uid int) (err error)
 	return err
 }
 
+func init() {
+	//IndustryFllowUserLabel(136, 16, 5660)
+	//UserLabelLogReduce()
+}
+
+// 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。
+func IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
+	var isFllow int
+	if count == 0 {
+		isFllow = 1
+	} else {
+		isFllow = 0
+	}
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
+		}
+	}()
+	log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 2, IsFllow: isFllow, CreateTime: time.Now()}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
+		if err != nil {
+			fmt.Println("RecordNewLogs LPush Err:" + err.Error())
+		}
+	}
+	return
+}
+
 // GetIndustryNewLabelMap 获取产业【新】标签Map
 func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error) {
 	labelMap = make(map[int]bool, 0)

+ 4 - 4
services/keyword.go

@@ -8,7 +8,7 @@ import (
 	"time"
 )
 
-//AddSearchKeyWord 记录用户搜索关键词
+// AddSearchKeyWord 记录用户搜索关键词
 func AddSearchKeyWord(user *models.WxUserItem, keyWord string, source int) (err error) {
 	//cacheKey := fmt.Sprint("Search_uid:", user.UserId, "_KeyWord:", keyWord, "_Source:", source)
 	//isExist := utils.Rc.IsExist(cacheKey)
@@ -31,7 +31,7 @@ func AddSearchKeyWord(user *models.WxUserItem, keyWord string, source int) (err
 	keyWordItem.CompanyName = user.CompanyName
 	keyWordItem.RealName = user.RealName
 	_, err = models.AddSearchKeyWord(keyWordItem)
-	//go AddUserSearchLog(user, keyWord, source)
+	go AddUserSearchLog(user, keyWord, source)
 	////一分钟之内的相同搜索词不重复记录
 	//setNX := utils.Rc.SetNX(cacheKey, keyWord, time.Minute*1)
 	//if !setNX {
@@ -40,7 +40,7 @@ func AddSearchKeyWord(user *models.WxUserItem, keyWord string, source int) (err
 	return
 }
 
-//AddUserSearchLog 记录用户搜索关键词的日志
+// AddUserSearchLog 记录用户搜索关键词的日志
 func AddUserSearchLog(user *models.WxUserItem, keyWord string, source int) (err error) {
 	defer func() {
 		if err != nil {
@@ -64,7 +64,7 @@ func AddUserSearchLog(user *models.WxUserItem, keyWord string, source int) (err
 	return
 }
 
-//用户搜索操作操作行为,模板消息推送
+// 用户搜索操作操作行为,模板消息推送
 func SearchKeywordUserRmind(user *models.WxUserItem, keyWord string) (err error) {
 	defer func() {
 		if err != nil {

+ 2 - 0
services/task.go

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

+ 111 - 0
services/user_label.go

@@ -0,0 +1,111 @@
+package services
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"time"
+)
+
+func UserLabelLogReduce() (err error) {
+	for {
+		//SourceType int       `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
+		utils.Rc.Brpop(utils.CYGX_USER_KEY_LABEL, func(b []byte) {
+			var log models.CygxUserLabelLogRedis
+			if err := json.Unmarshal(b, &log); err != nil {
+				fmt.Println("json unmarshal wrong!")
+				go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+err.Error()+string(b), 2)
+			}
+			switch log.SourceType {
+			case 1:
+				fmt.Println("文章阅读")
+				break
+			case 2:
+				go IndustryFllowUserLabelLogReduce(log)
+				fmt.Println("2产业关注")
+				break
+			case 3:
+				fmt.Println("活动到会")
+				break
+			case 4:
+				fmt.Println("4系列关注")
+				break
+			case 5:
+				fmt.Println("5专项调研活动到会")
+				break
+			default:
+				fmt.Println(string(b))
+				go utils.SendAlarmMsg("用户更新相关标签处理Redis队列消息失败:"+string(b), 2)
+			}
+		})
+	}
+}
+
+// 2产业关注
+func IndustryFllowUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,处理Redis队列消息失败:"+err.Error(), 2)
+		}
+	}()
+	isFllow := log.IsFllow
+	industrialManagementId := log.SourceId
+	userId := log.UserId
+	detailIndustrial, e := models.GetIndustrialManagementDetail(industrialManagementId)
+	if e != nil {
+		err = errors.New("GetIndustrialManagementDetail" + e.Error())
+		return
+	}
+	label := detailIndustrial.IndustryName
+	if isFllow == 0 {
+		e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, 1, label)
+		if e != nil {
+			err = errors.New("UpdateCygxUserLabelIsFollow" + e.Error())
+			return
+		}
+	} else {
+		var condition string
+		var pars []interface{}
+		condition += ` AND art.status = 1 `
+		total, e := models.GetCygxUserLabelCount(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxProductInteriorCount" + e.Error())
+			return
+		}
+		if total == 0 {
+			user, e := models.GetWxUserItemByUserId(userId)
+			if e != nil {
+				err = errors.New("GetWxUserItemByUserId" + e.Error())
+				return
+			}
+			item := new(models.CygxUserLabel)
+			item.UserId = user.UserId
+			item.CompanyId = user.CompanyId
+			item.RealName = user.RealName
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.Label = label
+			item.SourceId = industrialManagementId
+			item.Source = 1
+			item.IsFollow = 1
+			item.CreateTime = time.Now()
+			item.CreateTime = time.Now()
+			_, e = models.AddCygxUserLabel(item)
+			if e != nil {
+				err = errors.New("AddCygxUserLabel" + e.Error())
+				return
+			}
+		} else {
+			//source 来源1:产业、2:系列
+			e = models.UpdateCygxUserLabelIsFollow(isFllow, industrialManagementId, 1, label)
+			if e != nil {
+				err = errors.New("UpdateCygxUserLabelIsFollow" + e.Error())
+				return
+			}
+		}
+	}
+	return
+}

+ 1 - 0
utils/constants.go

@@ -121,6 +121,7 @@ const (
 
 const (
 	YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY = "YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY" //易董证通云的token,存Redis使用
+	CYGX_USER_KEY_LABEL              = "CYGX_USER_KEY_LABEL"              //查研观向用户标签
 )
 
 const (