|
@@ -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
|
|
|
+}
|