浏览代码

no message

xingzai 1 年之前
父节点
当前提交
f0e569d09d
共有 4 个文件被更改,包括 79 次插入12 次删除
  1. 1 0
      models/db.go
  2. 16 0
      models/user_label.go
  3. 2 0
      services/task.go
  4. 60 12
      services/user_label.go

+ 1 - 0
models/db.go

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

+ 16 - 0
models/user_label.go

@@ -24,6 +24,7 @@ type CygxUserLabel struct {
 	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:"更新时间"`
 }
@@ -38,3 +39,18 @@ func GetCygxUserLabelCount(condition string, pars []interface{}) (count int, err
 	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
+}

+ 2 - 0
services/task.go

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

+ 60 - 12
services/user_label.go

@@ -2,9 +2,11 @@ package services
 
 import (
 	"encoding/json"
+	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
+	"time"
 )
 
 func UserLabelLogReduce() (err error) {
@@ -41,23 +43,69 @@ func UserLabelLogReduce() (err error) {
 	}
 }
 
+// 2产业关注
 func IndustryFllowUserLabelLogReduce(log models.CygxUserLabelLogRedis) (err error) {
 	defer func() {
 		if err != nil {
 			fmt.Println(err)
-			//msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
-			msg := ""
-			go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,处理Redis队列消息失败:"+err.Error(), 2)
 		}
 	}()
-
-	//type CygxActivitySigninLogRedis 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:"创建时间"`
-	//}
-
+	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
 }