xingzai 1 rok temu
rodzic
commit
f86bd70003
4 zmienionych plików z 195 dodań i 4 usunięć
  1. 3 0
      controllers/user.go
  2. 75 0
      models/user_label.go
  3. 109 0
      services/user_label.go
  4. 8 4
      utils/constants.go

+ 3 - 0
controllers/user.go

@@ -3,6 +3,7 @@ package controllers
 import (
 	"encoding/json"
 	"hongze/hongze_cygxzs/models"
+	"hongze/hongze_cygxzs/services"
 	"hongze/hongze_cygxzs/utils"
 	"strconv"
 	"strings"
@@ -353,6 +354,8 @@ func (this *UserController) ChooseSubmit() {
 		br.ErrMsg = "保存失败!,Err:" + err.Error()
 		return
 	}
+
+	go services.UserSubmit(itemsFllow, itemsCategory, user.UserId)
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "保存成功"

+ 75 - 0
models/user_label.go

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

+ 109 - 0
services/user_label.go

@@ -0,0 +1,109 @@
+package services
+
+import (
+	"fmt"
+	"hongze/hongze_cygxzs/models"
+	"hongze/hongze_cygxzs/utils"
+	"time"
+)
+
+func UserSubmit(itemsFllow []*models.CygxIndustryFllow, itemsCategory []*models.CygxXzsChooseCategory, userId int) (err error) {
+	e := models.UpdateCygxUserLabelNofollow(userId)
+	if e != nil {
+		go utils.SendAlarmMsg("用户关注产业更新相关标签,UpdateCygxUserLabelNofollow,Err :"+e.Error(), 2)
+	}
+	if len(itemsFllow) > 0 {
+		mapIndustryId := make(map[int]bool)
+		var condition string
+		var pars []interface{}
+		condition = ` AND is_follow=1  AND source = 1  AND  user_id = ?  `
+		pars = append(pars, userId)
+		list, e := models.GetCygxUserLabelList(condition, pars)
+		if e != nil {
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,查询相关信息失败:"+e.Error(), 2)
+		}
+		for _, v := range list {
+			mapIndustryId[v.SourceId] = true
+		}
+
+		for _, v := range itemsFllow {
+			if !mapIndustryId[v.IndustrialManagementId] {
+				IndustryFllowUserLabelLogAdd(v.IndustrialManagementId, 0, userId)
+			}
+		}
+	}
+	if len(itemsCategory) > 0 {
+		mapIndustryId := make(map[int]bool)
+		var condition string
+		var pars []interface{}
+		condition = ` AND is_follow=1  AND source = 2  AND  user_id = ?  `
+		pars = append(pars, userId)
+		list, e := models.GetCygxUserLabelList(condition, pars)
+		if e != nil {
+			go utils.SendAlarmMsg("用户关注系列更新相关标签,查询相关信息失败:"+e.Error(), 2)
+		}
+		for _, v := range list {
+			mapIndustryId[v.SourceId] = true
+		}
+
+		for _, v := range itemsCategory {
+			if !mapIndustryId[v.IdCygx] {
+				CategoryFllowUserLabelLogAdd(v.IdCygx, 0, userId)
+			}
+		}
+	}
+
+	return
+}
+
+//SourceType int       `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
+
+// 添加用户2产业关注标签到Redis
+func IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
+	var isFllow int
+	if count == 0 {
+		isFllow = 1
+	} else {
+		isFllow = 0
+	}
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
+		}
+	}()
+	log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 2, IsFllow: isFllow, CreateTime: time.Now()}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
+		if err != nil {
+			fmt.Println("RecordNewLogs LPush Err:" + err.Error())
+		}
+	}
+	return
+}
+
+// 添加用户4系列关注标签到Redis
+func CategoryFllowUserLabelLogAdd(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: 4, 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
+}

+ 8 - 4
utils/constants.go

@@ -4,7 +4,7 @@ const (
 	Md5Key = "Ks@h64WJ#tcVgG8$&WlNfqvLAtMgpxWN"
 )
 
-//常量定义
+// 常量定义
 const (
 	FormatTime             = "15:04:05"                //时间格式
 	FormatDate             = "2006-01-02"              //日期格式
@@ -25,14 +25,14 @@ const (
 	EmailSendToExpert = "jhwang@hzinsights.com;cxzhang@hzinsights.com"
 )
 
-//手机号,电子邮箱正则
+// 手机号,电子邮箱正则
 const (
 	RegularMobile         = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0-9])|(17[0-9])|(16[0-9])|(19[0-9]))\\d{8}$" //手机号码
 	RegularFixedTelephone = "^(\\(\\d{3,4}\\)|\\d{3,4}-|\\s)?\\d{7,14}$"                                              //手机号码
 	RegularEmail          = `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`                                             //匹配电子邮箱
 )
 
-//聚合短信
+// 聚合短信
 var (
 	JhGnTplId = "65692" //聚合国内模板编码
 	JhGjTplId = "10054" //聚合国内模板编码
@@ -41,7 +41,7 @@ var (
 	JhGjAppKey = "3326ad2c1047a4cd92ace153e6044ca3"
 )
 
-//OSS
+// OSS
 var (
 	Endpoint   string = "oss-cn-shanghai.aliyuncs.com"
 	Bucketname string = "hongze"
@@ -70,3 +70,7 @@ const (
 	ZHI_ZAO_NAME                     string = "智造"
 	ZHI_ZAO_ID                       int    = 19
 )
+
+const (
+	CYGX_USER_KEY_LABEL = "CYGX_USER_KEY_LABEL" //查研观向用户标签
+)