Przeglądaj źródła

若用户当前将某行业下的赛道全选,则该行业下新增赛道时,也默认为该用户勾选此赛道

xingzai 2 lat temu
rodzic
commit
5a661daef6

+ 4 - 16
controllers/report.go

@@ -589,28 +589,16 @@ func (this *ReportController) Fllow() {
 		}
 		resp.Status = 1
 	} else {
-		var doType int
-		condition = ` AND type = 1`
-		count, err = models.GetCountCygxIndustryFllow(uid, industrialManagementId, condition)
-		if err != nil {
-			br.Msg = "操作失败!"
-			br.ErrMsg = "获取数据失败,Err:" + err.Error()
-			return
-		}
-		if count == 1 {
-			resp.Status = 2
-			doType = 2
-		} else {
-			resp.Status = 1
-			doType = 1
-		}
-		err = models.RemoveCygxIndustryFllow(uid, industrialManagementId, doType)
+		err = models.RemoveCygxIndustryFllow(uid, industrialManagementId)
 		if err != nil {
 			br.Msg = "操作失败"
 			br.ErrMsg = "取消关注失败,Err:" + err.Error()
 			return
 		}
 	}
+
+	//处理是否关注全部赛道字段
+	go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
 	br.Msg = "操作成功"
 	br.Ret = 200
 	br.Success = true

+ 20 - 5
models/industrial_management.go

@@ -10,11 +10,12 @@ import (
 )
 
 type IndustrialManagementRep struct {
-	IndustryName      string `description:"产业名称"`
-	ChartPermissionId int    `description:"权限id"`
-	RecommendedIndex  int    `description:"推荐指数"`
-	LayoutTime        string `description:"布局时间"`
-	ArticleReadNum    int    `description:"文章阅读数量"`
+	IndustryName           string `description:"产业名称"`
+	IndustrialManagementId int    `description:"产业id"`
+	ChartPermissionId      int    `description:"权限id"`
+	RecommendedIndex       int    `description:"推荐指数"`
+	LayoutTime             string `description:"布局时间"`
+	ArticleReadNum         int    `description:"文章阅读数量"`
 }
 
 type IndustrialManagementCount struct {
@@ -531,3 +532,17 @@ func UpdateIndustrialManagementFllowNum(num, industrialManagementId int) (err er
 	_, err = o.Raw(sql, num, industrialManagementId).Exec()
 	return
 }
+
+//获取所有的产业
+func GetindustrialManagement() (items []*IndustrialManagementRep, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			i.* 
+		FROM
+			cygx_industrial_management AS i
+			INNER JOIN cygx_industrial_article_group_management AS m ON m.industrial_management_id = i.industrial_management_id 
+		GROUP BY
+			i.industrial_management_id `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 37 - 1
models/industry_fllow.go

@@ -17,6 +17,7 @@ type CygxIndustryFllow struct {
 	CreateTime             time.Time `description:"创建时间"`
 	ModifyTime             time.Time `description:"更新时间"`
 	RealName               string    `description:"用户实际名称"`
+	Source                 int       `description:"来源1查研观向,2查研观向小助手,3勾选全部赛道的用户进行自动关注"`
 }
 
 type CygxIndustryFllowRep struct {
@@ -30,12 +31,22 @@ func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) {
 	return
 }
 
+//批量添加
+func AddCygxIndustryFllowMulti(items []*CygxIndustryFllow) (err error) {
+	o := orm.NewOrm()
+	if len(items) > 0 {
+		//批量添加新的关注记录
+		_, err = o.InsertMulti(len(items), items)
+	}
+	return
+}
+
 type CygxIndustryFllowResp struct {
 	Status   int  `description:"1:关注,2:取消关注"`
 	GoFollow bool `description:"是否去关注"`
 }
 
-func RemoveCygxIndustryFllow(userId, industrialManagementId, doType int) (err error) {
+func RemoveCygxIndustryFllow(userId, industrialManagementId int) (err error) {
 	o := orm.NewOrm()
 	sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? `
 	_, err = o.Raw(sql, userId, industrialManagementId).Exec()
@@ -121,3 +132,28 @@ func GetUserFllowIndustrialCountList() (items []*CygxIndustryFllowCountRep, err
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+//GetUserFllowIndustrialListByUserIdAndIndustrial 通过用户ID 跟产业ID获取用户关注的产业列表
+func GetUserFllowIndustrialListByUserIdAndIndustrial(userIds, industrials string) (items []*CygxIndustryFllow, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_industry_fllow 
+			WHERE 1 = 1 
+		AND user_id IN ( ` + userIds + ` ) 
+		AND industrial_management_id IN ( ` + industrials + `) `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//获取某个用户关注某个行业下的产业数量
+func GetCountCygxIndustryFllowByUidAndChartPermissionId(userId, ChartPermissionId int) (count int, err error) {
+	sql := `SELECT
+			COUNT( 1 ) AS count 
+		FROM
+			cygx_industry_fllow AS f
+			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id 
+		WHERE
+			user_id = ? 
+			AND m.chart_permission_id = ? `
+	err = orm.NewOrm().Raw(sql, userId, ChartPermissionId).QueryRow(&count)
+	return
+}

+ 10 - 0
models/wx_user.go

@@ -557,3 +557,13 @@ func GetWxUserByMobiles(mobiles []string) (items []*WxUser, err error) {
 	_, err = o.Raw(sql, mobiles).QueryRows(&items)
 	return
 }
+
+// GetWxUserListByUserIds 根据用户ID集合获取用户
+func GetWxUserListByUserIds(userIds string) (list []*WxUserItem, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT u.*, c.company_name FROM wx_user AS u
+			INNER JOIN company AS c ON c.company_id = u.company_id 
+			WHERE user_id IN (` + userIds + `) `
+	_, err = o.Raw(sql).QueryRows(&list)
+	return
+}

+ 1 - 25
models/wx_user_code.go

@@ -106,30 +106,6 @@ func GetCygxUserFllowCeLueOpenid(categoryId int) (items []*OpenIdList, err error
 	return
 }
 
-type CygxXzsChooseSend struct {
-	Id           int       `orm:"column(id);pk"`
-	UserId       int       `description:"用户ID"`
-	Mobile       string    `description:"手机号"`
-	Email        string    `description:"邮箱"`
-	CompanyId    int       `description:"公司id"`
-	CompanyName  string    `description:"公司名称"`
-	RealName     string    `description:"用户实际名称"`
-	IsRefuse     int       `description:"是否拒绝推送,0否、1是  如果为1 则不做任何推送"`
-	IsSubjective int       `description:"是否选择主观推送, 1 是 、 0否"`
-	IsObjective  int       `description:"是否选择客观推送, 1 是 、 0否"`
-	CreateTime   time.Time `description:"创建时间"`
-	ModifyTime   time.Time `description:"更新时间"`
-}
-
-//获取提交过推送规则用户的userId
-func GetCygxXzsChooseSend() (items []*CygxXzsChooseSend, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_xzs_choose_send `
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-
 //获取提交过推送规则用户的userId
 func GetCygxXzsChooseSendOpenIdByUserIds(idStr string) (items []*OpenIdList, err error) {
 	o := orm.NewOrm()
@@ -138,4 +114,4 @@ INNER JOIN cygx_user_record AS cr
 WHERE ur.user_id IN (` + idStr + `) AND create_platform=4 AND ur.union_id=cr.union_id `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
-}
+}

+ 51 - 0
models/xzs_choose_send.go

@@ -0,0 +1,51 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxXzsChooseSend struct {
+	Id           int       `orm:"column(id);pk"`
+	UserId       int       `description:"用户ID"`
+	Mobile       string    `description:"手机号"`
+	Email        string    `description:"邮箱"`
+	CompanyId    int       `description:"公司id"`
+	CompanyName  string    `description:"公司名称"`
+	RealName     string    `description:"用户实际名称"`
+	IsRefuse     int       `description:"是否拒绝推送,0否、1是  如果为1 则不做任何推送"`
+	IsSubjective int       `description:"是否选择主观推送, 1 是 、 0否"`
+	IsObjective  int       `description:"是否选择客观推送, 1 是 、 0否"`
+	CreateTime   time.Time `description:"创建时间"`
+	ModifyTime   time.Time `description:"更新时间"`
+	AllInYiYao   int       `description:"是否选择医药全部赛道"`
+	AllInXiaoFei int       `description:"是否选择消费全部赛道"`
+	AllInKeJi    int       `description:"是否选择科技全部赛道"`
+	AllInZhiZao  int       `description:"是否选择智造全部赛道"`
+	AllInCeLue   int       `description:"是否选择策略全部赛道"`
+	AllInYanXuan int       `description:"是否选择研选全部赛道"`
+}
+
+//获取提交过推送规则用户的userId
+func GetCygxXzsChooseSend() (items []*CygxXzsChooseSend, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_xzs_choose_send `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//获取某个行业勾选全部赛道的用户
+func GetCygxXzsChooseSendByAllIn(allIn string) (items []*CygxXzsChooseSend, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_xzs_choose_send  WHERE ` + allIn + ` = 1	`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//修改某个用户的行业是否勾选全部赛道
+func UpdateCygxXzsChooseSendIsAllIn(allIn string, isAllIn, userId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_xzs_choose_send SET ` + allIn + ` = ? WHERE user_id = ?`
+	_, err = o.Raw(sql, isAllIn, userId).Exec()
+	return
+}

+ 81 - 14
services/article.go

@@ -1198,6 +1198,86 @@ func DoArticleOnenIdWxTemplateMsg(articleId int) (err error) {
 		}
 		chartPermissionId = chartPermissionDetail.ChartPermissionId
 	}
+
+	//文章关联的产业
+	var industryName string
+	var industrialManagementId string
+	if chartPermissionId == utils.CE_LUE_ID {
+		industryName = reportMapDetail.SubCategoryName
+	} else {
+		detailIndustryNameList, err := models.GetIndustrialManagemenDetailByAaticleID(articleId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			return err
+		}
+		//如果不存在关联的产业则不推送
+		if len(detailIndustryNameList) == 0 {
+			return err
+		}
+		for _, v := range detailIndustryNameList {
+			industryName += v.IndustryName + ","
+			industrialManagementId += strconv.Itoa(v.IndustrialManagementId) + ","
+		}
+		industryName = strings.TrimRight(industryName, ",")
+		industrialManagementId = strings.TrimRight(industrialManagementId, ",")
+
+		//处理勾选了全部行业赛道的用户
+		var allIn string
+		allIn = DoXzsChooseSend(reportMapDetail.ChartPermissionName)
+		if allIn != "" {
+			allInList, err := models.GetCygxXzsChooseSendByAllIn(allIn)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				return err
+			}
+			if len(allInList) > 0 {
+				var allInUserId string
+				for _, v := range allInList {
+					allInUserId += strconv.Itoa(v.UserId) + ","
+				}
+				allInUserId = strings.TrimRight(allInUserId, ",")
+
+				userFllowIndustrialList, err := models.GetUserFllowIndustrialListByUserIdAndIndustrial(allInUserId, industrialManagementId)
+				if err != nil && err.Error() != utils.ErrNoRow() {
+					return err
+				}
+				mapUserFllowed := make(map[string]int)
+				for _, v := range userFllowIndustrialList {
+					//用户ID与其关注的产业组成唯一索引,判断是否存在,如果不存在就进行自动关注
+					mapUserFllowed[fmt.Sprint("uid:", v.UserId, "_Industrial:", v.IndustrialManagementId)] = v.UserId
+				}
+				//获取这些allIN用户的的信息进行遍历生成需要插入的数据
+				userList, err := models.GetWxUserListByUserIds(allInUserId)
+				if err != nil && err.Error() != utils.ErrNoRow() {
+					return err
+				}
+				var industryFllowItems []*models.CygxIndustryFllow
+				for _, v := range detailIndustryNameList {
+					for _, vUser := range userList {
+						//如果用户这个用户没有关注这个产业就进行自动关注
+						if mapUserFllowed[fmt.Sprint("uid:", vUser.UserId, "_Industrial:", v.IndustrialManagementId)] == 0 {
+							item := new(models.CygxIndustryFllow)
+							item.IndustrialManagementId = v.IndustrialManagementId
+							item.UserId = vUser.UserId
+							item.Email = vUser.Email
+							item.Mobile = vUser.Mobile
+							item.RealName = vUser.RealName
+							item.CompanyId = vUser.CompanyId
+							item.CompanyName = vUser.CompanyName
+							item.Source = 3
+							item.Type = 1
+							item.CreateTime = time.Now()
+							item.ModifyTime = time.Now()
+							industryFllowItems = append(industryFllowItems, item)
+						}
+					}
+				}
+				err = models.AddCygxIndustryFllowMulti(industryFllowItems)
+				if err != nil {
+					go utils.SendAlarmMsg("用户关注全部赛道,出现新赛道批量添加失败 ,AddCygxIndustryFllowMulti ErrMsg:"+err.Error(), 2)
+				}
+			}
+		}
+	}
+
 	// 获取所有有权的用户的 openid
 	mapOpenidPower := make(map[int]string)
 	permissionIdList := make([]string, 0)
@@ -1261,20 +1341,7 @@ func DoArticleOnenIdWxTemplateMsg(articleId int) (err error) {
 	}
 	//已经推送了的openid
 	mapOpenidPushed := make(map[int]string)
-	//文章关联的产业
-	var industryName string
-	if chartPermissionId != utils.CE_LUE_ID {
-		detailIndustryNameList, err := models.GetIndustrialManagemenDetailByAaticleID(articleId)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			return err
-		}
-		for _, v := range detailIndustryNameList {
-			industryName += v.IndustryName + ","
-		}
-		industryName = strings.TrimRight(industryName, ",")
-	} else {
-		industryName = reportMapDetail.SubCategoryName
-	}
+
 	keyword2 := articleInfo.Title
 	keyword3 := time.Now().Format(utils.FormatDateTime)
 	keyword4 := articleInfo.Abstract

+ 68 - 0
services/industrial_management.go

@@ -146,3 +146,71 @@ func ArticleCollectCountUpdate() (err error) {
 	}
 	return err
 }
+
+//根据行业处理所选的全部赛道字段
+func DoXzsChooseSend(chartPermissionName string) string {
+	var allIn string
+	if chartPermissionName == utils.YI_YAO_NAME {
+		allIn = "all_in_yi_yao"
+	} else if chartPermissionName == utils.XIAO_FEI_NAME {
+		allIn = "all_in_xiao_fei"
+	} else if chartPermissionName == utils.KE_JI_NAME {
+		allIn = "all_in_ke_ji"
+	} else if chartPermissionName == utils.ZHI_ZAO_NAME {
+		allIn = "all_in_zhi_zao"
+	} else if chartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
+		allIn = "all_in_yan_xuan"
+	}
+	return allIn
+}
+
+//行业关注或者取消关注的时候,对于用户全部赛道的影响
+func IndustryFllowWithTrack(industrialManagementId, count, uid int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败"+err.Error(), 2)
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改行业关注或者取消关注的时候,对于用户全部赛道的影响信息失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+	}()
+	detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
+	if err != nil {
+		return err
+	}
+	categoryinfo, err := models.GetChartPermissionById(detail.ChartPermissionId)
+	if err != nil {
+		return err
+	}
+	var allIn string
+	allIn = DoXzsChooseSend(categoryinfo.PermissionName)
+	if allIn != "" {
+		//如果取消关注就把该赛道设置为非全部赛道
+		if count == 1 {
+			err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 0, uid)
+			if err != nil {
+				return err
+			}
+		} else {
+			//医药、消费、科技、智造、研选下的产业赛道
+			mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
+			industrialList, err := models.GetindustrialManagement()
+			if err != nil {
+				return err
+			}
+			for _, v := range industrialList {
+				mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
+			}
+			fllowNum, err := models.GetCountCygxIndustryFllowByUidAndChartPermissionId(uid, detail.ChartPermissionId)
+			if err != nil {
+				return err
+			}
+			if fllowNum == len(mapIndustrial[detail.ChartPermissionId]) {
+				err = models.UpdateCygxXzsChooseSendIsAllIn(allIn, 1, uid)
+				if err != nil {
+					return err
+				}
+			}
+		}
+	}
+	return err
+}