Quellcode durchsuchen

过滤没有报告的产业

xingzai vor 2 Jahren
Ursprung
Commit
087dc2eb5f

+ 80 - 31
controllers/user.go

@@ -58,6 +58,7 @@ func (this *UserController) ChooseDetail() {
 	}
 	mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
 	mapFllow := make(map[int]int)
+	mapCategory := make(map[int]int)
 	ampCheckList := make(map[int][]int, 0)
 	permissionIdList := make([]string, 0)
 	fllowList, err := models.GetCygxIndustryFllowList(mobile)
@@ -66,17 +67,37 @@ func (this *UserController) ChooseDetail() {
 		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
 		return
 	}
-
 	for _, v := range fllowList {
 		mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId
 	}
-	industrialList, err := models.GetindustrialManagement()
+
+	//策略的处理
+	categoryList, err := models.GetCygxXzsChooseCategoryList(mobile)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range categoryList {
+		mapCategory[v.CategoryId] = v.CategoryId
+	}
+	celueList, err := models.GetReportMappingStrategyAll()
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
 		return
 	}
-	celueList, err := models.GetReportMappingStrategyAll()
+
+	for k, v := range celueList {
+		if mapCategory[v.IndustrialManagementId] > 0 {
+			celueList[k].IsFllow = true
+			//添加所关注的行业赛道
+			ampCheckList[v.ChartPermissionId] = append(ampCheckList[v.ChartPermissionId], v.IndustrialManagementId)
+		}
+	}
+	//策略的处理 end
+
+	industrialList, err := models.GetindustrialManagement()
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
@@ -109,7 +130,6 @@ func (this *UserController) ChooseDetail() {
 		if v.PermissionName == utils.CE_LUE_NAME {
 			permissionList[k].List = celueList
 			permissionList[k].AllTracks = "全系列报告"
-			permissionList[k].CheckList = make([]int, 0)
 		} else {
 			permissionList[k].AllTracks = "全部赛道"
 			if len(mapIndustrial[v.ChartPermissionId]) == 0 {
@@ -117,13 +137,12 @@ func (this *UserController) ChooseDetail() {
 			} else {
 				permissionList[k].List = mapIndustrial[v.ChartPermissionId]
 			}
-			if len(ampCheckList[v.ChartPermissionId]) == 0 {
-				permissionList[k].CheckList = make([]int, 0)
-			} else {
-				permissionList[k].CheckList = ampCheckList[v.ChartPermissionId]
-			}
 		}
-
+		if len(ampCheckList[v.ChartPermissionId]) == 0 {
+			permissionList[k].CheckList = make([]int, 0)
+		} else {
+			permissionList[k].CheckList = ampCheckList[v.ChartPermissionId]
+		}
 	}
 	count, err := models.GetXzsChooseSendCountByMobile(mobile)
 	if err != nil {
@@ -183,32 +202,62 @@ func (this *UserController) ChooseSubmit() {
 		return
 	}
 	var industrialManagementIds string
-	industrialManagementList := req.List
+	var categoryIds string
+	industrialManagementList := req.IndustrialManagementIds
 	for _, v := range industrialManagementList {
-		if v.ChartPermissionId != 23 {
+		//如果为空就不做拼接处理
+		if v.IndustrialManagementIds == "" {
+			continue
+		}
+		if v.ChartPermissionId != utils.CE_LUE_ID {
 			industrialManagementIds += v.IndustrialManagementIds + ","
+		} else {
+			categoryIds += v.IndustrialManagementIds + ","
 		}
 	}
-	industrialManagementIds = strings.TrimRight(industrialManagementIds, ",")
-	sliceIndustrial := strings.Split(industrialManagementIds, ",")
+
 	var itemsFllow []*models.CygxIndustryFllow
-	for _, v := range sliceIndustrial {
-		item := new(models.CygxIndustryFllow)
-		industrialManagementId, _ := strconv.Atoi(v)
-		item.IndustrialManagementId = industrialManagementId
-		item.UserId = user.UserId
-		item.Mobile = user.Mobile
-		item.Email = user.Email
-		item.CompanyId = user.CompanyId
-		item.CompanyName = user.CompanyName
-		item.RealName = user.RealName
-		item.Type = 1
-		item.CreateTime = time.Now()
-		item.ModifyTime = time.Now()
-		item.Source = 2
-		itemsFllow = append(itemsFllow, item)
+	industrialManagementIds = strings.TrimRight(industrialManagementIds, ",")
+	if industrialManagementIds != "" {
+		sliceIndustrial := strings.Split(industrialManagementIds, ",")
+		for _, v := range sliceIndustrial {
+			item := new(models.CygxIndustryFllow)
+			industrialManagementId, _ := strconv.Atoi(v)
+			item.IndustrialManagementId = industrialManagementId
+			item.UserId = user.UserId
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.CompanyId = user.CompanyId
+			item.CompanyName = user.CompanyName
+			item.RealName = user.RealName
+			item.Type = 1
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			item.Source = 2
+			itemsFllow = append(itemsFllow, item)
+		}
 	}
 
+	//处理策略
+	var itemsCategory []*models.CygxXzsChooseCategory
+	categoryIds = strings.TrimRight(categoryIds, ",")
+	if categoryIds != "" {
+		sliceCategoryId := strings.Split(categoryIds, ",")
+		for _, v := range sliceCategoryId {
+			item := new(models.CygxXzsChooseCategory)
+			categoryId, _ := strconv.Atoi(v)
+			item.CategoryId = categoryId
+			item.UserId = user.UserId
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.CompanyId = user.CompanyId
+			item.CompanyName = user.CompanyName
+			item.RealName = user.RealName
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			itemsCategory = append(itemsCategory, item)
+		}
+	}
 	mobile := user.Mobile
 	item := new(models.CygxXzsChooseSend)
 	item.UserId = user.UserId
@@ -230,9 +279,9 @@ func (this *UserController) ChooseSubmit() {
 	}
 	//如果有记录就新增,没有记录就修改
 	if count == 0 {
-		err = models.AddCygxXzsChooseSend(item, itemsFllow)
+		err = models.AddCygxXzsChooseSend(item, itemsFllow, itemsCategory)
 	} else {
-		err = models.UpdateCygxXzsChooseSend(item, itemsFllow)
+		err = models.UpdateCygxXzsChooseSend(item, itemsFllow, itemsCategory)
 	}
 	if err != nil {
 		br.Msg = "保存失败!"

+ 1 - 0
models/db.go

@@ -27,6 +27,7 @@ func init() {
 		new(CygxXzsSession),
 		new(CygxXzsChooseSend),
 		new(CygxIndustryFllow),
+		new(CygxXzsChooseCategory),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 7 - 1
models/industrial_management.go

@@ -14,7 +14,13 @@ type IndustrialManagementRep struct {
 //获取所有的产业
 func GetindustrialManagement() (items []*IndustrialManagementRep, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_industrial_management `
+	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
 }

+ 0 - 21
models/industry_fllow.go

@@ -24,20 +24,6 @@ type CygxIndustryFllowRep struct {
 	IndustrialManagementId int `description:"产业D"`
 }
 
-//添加
-func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) {
-	o := orm.NewOrm()
-	lastId, err = o.Insert(item)
-	return
-}
-
-//  批量新增
-func AddCygxIndustryFllowMulti(items []*CygxIndustryFllow) (err error) {
-	o := orm.NewOrm()
-	_, err = o.InsertMulti(len(items), items)
-	return
-}
-
 //根据手机号获取用户关注的产业
 func GetCygxIndustryFllowList(mobile string) (items []*CygxIndustryFllow, err error) {
 	o := orm.NewOrm()
@@ -45,10 +31,3 @@ func GetCygxIndustryFllowList(mobile string) (items []*CygxIndustryFllow, err er
 	_, err = o.Raw(sql, mobile).QueryRows(&items)
 	return
 }
-
-func DelCygxIndustryFllow(activityId int) (err error) {
-	o := orm.NewOrm()
-	sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
-	_, err = o.Raw(sql, activityId).Exec()
-	return
-}

+ 27 - 0
models/xzs_choose_category.go

@@ -0,0 +1,27 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxXzsChooseCategory 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:"用户实际名称"`
+	CategoryId  int       `description:"权益文章对应分类,cygx_article"`
+	CreateTime  time.Time `description:"创建时间"`
+	ModifyTime  time.Time `description:"更新时间"`
+}
+
+//根据手机号获取用户关注的产业
+func GetCygxXzsChooseCategoryList(mobile string) (items []*CygxXzsChooseCategory, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_xzs_choose_category WHERE mobile = ?`
+	_, err = o.Raw(sql, mobile).QueryRows(&items)
+	return
+}

+ 50 - 10
models/xzs_choose_send.go

@@ -28,10 +28,10 @@ type CygxXzsChooseSendResp struct {
 }
 
 type SubmitChooseSendResp struct {
-	IsRefuse     int `description:"是否拒绝推送,0否、1是  如果为1 则不做任何推送"`
-	IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
-	IsObjective  int `description:"是否选择客观推送, 1 是 、 0否"`
-	List         []*IndustrialManagementIdResp
+	IsRefuse                int `description:"是否拒绝推送,0否、1是  如果为1 则不做任何推送"`
+	IsSubjective            int `description:"是否选择主观推送, 1 是 、 0否"`
+	IsObjective             int `description:"是否选择客观推送, 1 是 、 0否"`
+	IndustrialManagementIds []*IndustrialManagementIdResp
 }
 
 type IndustrialManagementIdResp struct {
@@ -40,7 +40,7 @@ type IndustrialManagementIdResp struct {
 }
 
 //添加
-func AddCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow) (err error) {
+func AddCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory) (err error) {
 	o, err := orm.NewOrm().Begin()
 	if err != nil {
 		return
@@ -56,13 +56,33 @@ func AddCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFll
 	//删除原有的关注记录
 	sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
 	_, err = o.Raw(sql, item.Mobile).Exec()
+	if err != nil {
+		return err
+	}
 
-	//批量添加新的关注记录
-	_, err = o.InsertMulti(len(itemsFllow), itemsFllow)
+	if len(itemsFllow) > 0 {
+		//批量添加新的关注记录
+		_, err = o.InsertMulti(len(itemsFllow), itemsFllow)
+		if err != nil {
+			return err
+		}
+	}
+
+	//删除原有策略报告的关注记录
+	sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ?`
+	_, err = o.Raw(sql, item.Mobile).Exec()
 	if err != nil {
 		return err
 	}
 
+	if len(itemsCategory) > 0 {
+		//批量添加新的关注记录
+		_, err = o.InsertMulti(len(itemsCategory), itemsCategory)
+		if err != nil {
+			return err
+		}
+	}
+
 	//添加所勾选的消息类型
 	_, err = o.Insert(item)
 	return
@@ -77,7 +97,7 @@ func GetXzsChooseSendCountByMobile(mobile string) (count int, err error) {
 }
 
 //添加
-func UpdateCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow) (err error) {
+func UpdateCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow, itemsCategory []*CygxXzsChooseCategory) (err error) {
 	o, err := orm.NewOrm().Begin()
 	if err != nil {
 		return
@@ -93,13 +113,33 @@ func UpdateCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustry
 	//删除原有的关注记录
 	sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
 	_, err = o.Raw(sql, item.Mobile).Exec()
+	if err != nil {
+		return err
+	}
 
-	//批量添加新的关注记录
-	_, err = o.InsertMulti(len(itemsFllow), itemsFllow)
+	if len(itemsFllow) > 0 {
+		//批量添加新的关注记录
+		_, err = o.InsertMulti(len(itemsFllow), itemsFllow)
+		if err != nil {
+			return err
+		}
+	}
+
+	//删除原有策略报告的关注记录
+	sql = `DELETE FROM cygx_xzs_choose_category WHERE mobile = ?`
+	_, err = o.Raw(sql, item.Mobile).Exec()
 	if err != nil {
 		return err
 	}
 
+	if len(itemsCategory) > 0 {
+		//批量添加新的关注记录
+		_, err = o.InsertMulti(len(itemsCategory), itemsCategory)
+		if err != nil {
+			return err
+		}
+	}
+
 	//修改现有的类型
 	updateParams := make(map[string]interface{})
 	updateParams["UserId"] = item.UserId