Browse Source

no message

xingzai 1 year ago
parent
commit
91f0e17311

+ 246 - 231
controllers/home.go

@@ -282,212 +282,224 @@ func (this *MobileHomeController) NewList() {
 	var conditionInit string
 	var pars []interface{}
 	var total int
+	var err error
 	resp := new(models.HomeResourceDataListNewResp)
 
-	var articleTypes, activityTypes, industries, subjectNames string
-	articleTypeCondSlice := make([]string, 0)
-	activityTypesCondSlice := make([]string, 0)
-	industriesCondSlice := make([]string, 0)
-	subjectNamesSlice := make([]string, 0)
-	articleTypeSlice := make([]string, 0)
-	if tagIds != "" {
-		tags := strings.Split(tagIds, ",")
-		for _, tagIdStr := range tags {
-			tagId, err := strconv.Atoi(tagIdStr)
-			if err != nil {
-				br.Msg = "转换失败"
-				br.ErrMsg = "tagid转换失败,Err:" + err.Error()
-				return
-			}
-			tagInfo, err := models.GetCygxTagByTagId(tagId)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				br.Msg = "获取失败"
-				br.ErrMsg = "GetCygxTagByTagId,Err:" + err.Error()
-				return
-			}
-			// 只有AB或CD的情况
-			if (tagInfo.ActivityTypes == "" && tagInfo.ArticleTypes == "") || (tagInfo.Industries == "" && tagInfo.SubjectNames == "") {
-				if tagInfo.ActivityTypes != "" {
-					activityTypes += tagInfo.ActivityTypes + ","
-				}
-				if tagInfo.ArticleTypes != "" {
-					articleTypes += tagInfo.ArticleTypes + ","
-				}
-				if tagInfo.Industries != "" {
-					industries += tagInfo.Industries + ","
-				}
-				if tagInfo.SubjectNames != "" {
-					subjectNames += tagInfo.SubjectNames + ","
-				}
-			} else {
-				// ABCD都有的情况
-				// 每一个tag都单独处理
-				var articleType, activityType, industry, subjectName string
-
-				if tagInfo.ActivityTypes != "" {
-					activityType = tagInfo.ActivityTypes
-				}
-				if tagInfo.ArticleTypes != "" {
-					articleType = tagInfo.ArticleTypes
-				}
-				if tagInfo.Industries != "" {
-					industry = tagInfo.Industries
-				}
-				if tagInfo.SubjectNames != "" {
-					subjectName = tagInfo.SubjectNames
-				}
-				articleTypeCond := ``
-				var articleTypeStr string
-				if articleType != "" {
-					articleTypeSlice := strings.Split(articleType, ",")
-					newArticleTypeSlice := make([]string, 0)
-					for _, s := range articleTypeSlice {
-						newArticleTypeSlice = append(newArticleTypeSlice, "'"+s+"'")
-					}
-					articleTypeStr = strings.Join(newArticleTypeSlice, ",")
-					articleTypeStr = strings.TrimRight(articleTypeStr, ",")
-					articleTypeCond += ` AND (art.sub_category_name In (` + articleTypeStr + `) OR (art.article_type_name In (` + articleTypeStr + `) AND art.article_type_name <> '路演精华' AND art.article_type_id <> 0 ) ) `
-				}
-				activityTypesCond := ``
-				if activityType != "" {
-					activityTypeSlice := strings.Split(activityType, ",")
-					newActivityTypeSlice := make([]string, 0)
-					for _, s := range activityTypeSlice {
-						newActivityTypeSlice = append(newActivityTypeSlice, "'"+s+"'")
-					}
-					activityTypeStr := strings.Join(newActivityTypeSlice, ",")
-					activityTypeStr = strings.TrimRight(activityTypeStr, ",")
-					activityTypesCond += ` AND act.activity_type_name In (` + activityTypeStr + `) `
-				}
-				industriesCond := ``
-				var industryStr string
-				if industry != "" {
-					industrieSlice := strings.Split(industry, ",")
-					newIndustrieSlice := make([]string, 0)
-					for _, s := range industrieSlice {
-						newIndustrieSlice = append(newIndustrieSlice, "'"+s+"'")
-					}
-					industryStr = strings.Join(newIndustrieSlice, ",")
-					industryStr = strings.TrimRight(industryStr, ",")
-					industriesCond += ` AND im.industry_name In (` + industryStr + `) `
-				}
-				subjectNamesCond := ``
-				var subjectNameStr string
-				if subjectName != "" {
-					subjectNameSlice := strings.Split(subjectName, ",")
-					newSubjectNameSlice := make([]string, 0)
-					for _, s := range subjectNameSlice {
-						newSubjectNameSlice = append(newSubjectNameSlice, "'"+s+"'")
-					}
-					subjectNameStr = strings.Join(newSubjectNameSlice, ",")
-					subjectNameStr = strings.TrimRight(subjectNameStr, ",")
-					subjectNamesCond += ` AND cis.subject_name In (` + subjectNameStr + `) `
-				}
-				articleTypeCondSlice = append(articleTypeCondSlice, articleTypeCond)
-				activityTypesCondSlice = append(activityTypesCondSlice, activityTypesCond)
-				industriesCondSlice = append(industriesCondSlice, industryStr)
-				subjectNamesSlice = append(subjectNamesSlice, subjectNameStr)
-				articleTypeSlice = append(articleTypeSlice, articleType)
-			}
-
-		}
-	}
+	//var articleTypes, activityTypes, industries, subjectNames string
+	//articleTypeCondSlice := make([]string, 0)
+	//activityTypesCondSlice := make([]string, 0)
+	//industriesCondSlice := make([]string, 0)
+	//subjectNamesSlice := make([]string, 0)
+	//articleTypeSlice := make([]string, 0)
+	//if tagIds != "" {
+	//	tags := strings.Split(tagIds, ",")
+	//	for _, tagIdStr := range tags {
+	//		tagId, err := strconv.Atoi(tagIdStr)
+	//		if err != nil {
+	//			br.Msg = "转换失败"
+	//			br.ErrMsg = "tagid转换失败,Err:" + err.Error()
+	//			return
+	//		}
+	//		tagInfo, err := models.GetCygxTagByTagId(tagId)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			br.Msg = "获取失败"
+	//			br.ErrMsg = "GetCygxTagByTagId,Err:" + err.Error()
+	//			return
+	//		}
+	//		// 只有AB或CD的情况
+	//		if (tagInfo.ActivityTypes == "" && tagInfo.ArticleTypes == "") || (tagInfo.Industries == "" && tagInfo.SubjectNames == "") {
+	//			if tagInfo.ActivityTypes != "" {
+	//				activityTypes += tagInfo.ActivityTypes + ","
+	//			}
+	//			if tagInfo.ArticleTypes != "" {
+	//				articleTypes += tagInfo.ArticleTypes + ","
+	//			}
+	//			if tagInfo.Industries != "" {
+	//				industries += tagInfo.Industries + ","
+	//			}
+	//			if tagInfo.SubjectNames != "" {
+	//				subjectNames += tagInfo.SubjectNames + ","
+	//			}
+	//		} else {
+	//			// ABCD都有的情况
+	//			// 每一个tag都单独处理
+	//			var articleType, activityType, industry, subjectName string
+	//
+	//			if tagInfo.ActivityTypes != "" {
+	//				activityType = tagInfo.ActivityTypes
+	//			}
+	//			if tagInfo.ArticleTypes != "" {
+	//				articleType = tagInfo.ArticleTypes
+	//			}
+	//			if tagInfo.Industries != "" {
+	//				industry = tagInfo.Industries
+	//			}
+	//			if tagInfo.SubjectNames != "" {
+	//				subjectName = tagInfo.SubjectNames
+	//			}
+	//			articleTypeCond := ``
+	//			var articleTypeStr string
+	//			if articleType != "" {
+	//				articleTypeSlice := strings.Split(articleType, ",")
+	//				newArticleTypeSlice := make([]string, 0)
+	//				for _, s := range articleTypeSlice {
+	//					newArticleTypeSlice = append(newArticleTypeSlice, "'"+s+"'")
+	//				}
+	//				articleTypeStr = strings.Join(newArticleTypeSlice, ",")
+	//				articleTypeStr = strings.TrimRight(articleTypeStr, ",")
+	//				articleTypeCond += ` AND (art.sub_category_name In (` + articleTypeStr + `) OR (art.article_type_name In (` + articleTypeStr + `) AND art.article_type_name <> '路演精华' AND art.article_type_id <> 0 ) ) `
+	//			}
+	//			activityTypesCond := ``
+	//			if activityType != "" {
+	//				activityTypeSlice := strings.Split(activityType, ",")
+	//				newActivityTypeSlice := make([]string, 0)
+	//				for _, s := range activityTypeSlice {
+	//					newActivityTypeSlice = append(newActivityTypeSlice, "'"+s+"'")
+	//				}
+	//				activityTypeStr := strings.Join(newActivityTypeSlice, ",")
+	//				activityTypeStr = strings.TrimRight(activityTypeStr, ",")
+	//				activityTypesCond += ` AND act.activity_type_name In (` + activityTypeStr + `) `
+	//			}
+	//			industriesCond := ``
+	//			var industryStr string
+	//			if industry != "" {
+	//				industrieSlice := strings.Split(industry, ",")
+	//				newIndustrieSlice := make([]string, 0)
+	//				for _, s := range industrieSlice {
+	//					newIndustrieSlice = append(newIndustrieSlice, "'"+s+"'")
+	//				}
+	//				industryStr = strings.Join(newIndustrieSlice, ",")
+	//				industryStr = strings.TrimRight(industryStr, ",")
+	//				industriesCond += ` AND im.industry_name In (` + industryStr + `) `
+	//			}
+	//			subjectNamesCond := ``
+	//			var subjectNameStr string
+	//			if subjectName != "" {
+	//				subjectNameSlice := strings.Split(subjectName, ",")
+	//				newSubjectNameSlice := make([]string, 0)
+	//				for _, s := range subjectNameSlice {
+	//					newSubjectNameSlice = append(newSubjectNameSlice, "'"+s+"'")
+	//				}
+	//				subjectNameStr = strings.Join(newSubjectNameSlice, ",")
+	//				subjectNameStr = strings.TrimRight(subjectNameStr, ",")
+	//				subjectNamesCond += ` AND cis.subject_name In (` + subjectNameStr + `) `
+	//			}
+	//			articleTypeCondSlice = append(articleTypeCondSlice, articleTypeCond)
+	//			activityTypesCondSlice = append(activityTypesCondSlice, activityTypesCond)
+	//			industriesCondSlice = append(industriesCondSlice, industryStr)
+	//			subjectNamesSlice = append(subjectNamesSlice, subjectNameStr)
+	//			articleTypeSlice = append(articleTypeSlice, articleType)
+	//		}
+	//
+	//	}
+	//}
+	//
+	//// 先拿abdc都有的tag取合集的ids。。。
+	//soloTagArticleIds, soloTagActivityIds, soloMmIds, err := models.GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityTypesCondSlice, industriesCondSlice, subjectNamesSlice, articleTypeSlice)
+	//if err != nil && err.Error() != utils.ErrNoRow() {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取活动权限数据失败,Err:" + err.Error()
+	//	return
+	//}
+	//
+	//articleTypes = strings.TrimRight(articleTypes, ",")
+	//activityTypes = strings.TrimRight(activityTypes, ",")
+	//industries = strings.TrimRight(industries, ",")
+	//subjectNames = strings.TrimRight(subjectNames, ",")
+	//
+	//articleTypesCond := ``
+	//var articleTypeStr string
+	//if articleTypes != "" {
+	//	articleTypeSlice := strings.Split(articleTypes, ",")
+	//	newArticleTypeSlice := make([]string, 0)
+	//	for _, s := range articleTypeSlice {
+	//		newArticleTypeSlice = append(newArticleTypeSlice, "'"+s+"'")
+	//	}
+	//	articleTypeStr = strings.Join(newArticleTypeSlice, ",")
+	//	articleTypeStr = strings.TrimRight(articleTypeStr, ",")
+	//	articleTypesCond += ` AND (art.sub_category_name In (` + articleTypeStr + `) OR (art.article_type_name In (` + articleTypeStr + `) AND art.article_type_name <> '路演精华' AND art.article_type_id <> 0 ) ) `
+	//}
+	//activityTypesCond := ``
+	//if activityTypes != "" {
+	//	activityTypeSlice := strings.Split(activityTypes, ",")
+	//	newActivityTypeSlice := make([]string, 0)
+	//	for _, s := range activityTypeSlice {
+	//		newActivityTypeSlice = append(newActivityTypeSlice, "'"+s+"'")
+	//	}
+	//	activityTypeStr := strings.Join(newActivityTypeSlice, ",")
+	//	activityTypeStr = strings.TrimRight(activityTypeStr, ",")
+	//	activityTypesCond += ` AND act.activity_type_name In (` + activityTypeStr + `) `
+	//}
+	//industriesCond := ``
+	//var industryStr string
+	//if industries != "" {
+	//	industrieSlice := strings.Split(industries, ",")
+	//	newIndustrieSlice := make([]string, 0)
+	//	for _, s := range industrieSlice {
+	//		newIndustrieSlice = append(newIndustrieSlice, "'"+s+"'")
+	//	}
+	//	industryStr = strings.Join(newIndustrieSlice, ",")
+	//	industryStr = strings.TrimRight(industryStr, ",")
+	//	industriesCond += ` AND im.industry_name In (` + industryStr + `) `
+	//}
+	//subjectNamesCond := ``
+	//var subjectNameStr string
+	//if subjectNames != "" {
+	//	subjectNameSlice := strings.Split(subjectNames, ",")
+	//	newSubjectNameSlice := make([]string, 0)
+	//	for _, s := range subjectNameSlice {
+	//		newSubjectNameSlice = append(newSubjectNameSlice, "'"+s+"'")
+	//	}
+	//	subjectNameStr = strings.Join(newSubjectNameSlice, ",")
+	//	subjectNameStr = strings.TrimRight(subjectNameStr, ",")
+	//	subjectNamesCond += ` AND cis.subject_name In (` + subjectNameStr + `) `
+	//}
+	//
+	//var tagArticleIds, tagActivityIds, mmIds string
+	//if articleTypesCond != "" || activityTypesCond != "" || industryStr != "" || subjectNameStr != "" {
+	//	tagArticleIds, tagActivityIds, mmIds, err = models.GetCygxCygxArticleListByCondition(articleTypesCond, activityTypesCond, industryStr, subjectNameStr, articleTypeStr)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		br.Msg = "获取失败"
+	//		br.ErrMsg = "获取单个标签ids失败,Err:" + err.Error()
+	//		return
+	//	}
+	//}
+	//
+	//if soloTagArticleIds != "" {
+	//	if tagArticleIds != "" {
+	//		tagArticleIds += "," + soloTagArticleIds
+	//	} else {
+	//		tagArticleIds = soloTagArticleIds
+	//	}
+	//}
+	//if soloTagActivityIds != "" {
+	//	if tagActivityIds != "" {
+	//		tagActivityIds += "," + soloTagActivityIds
+	//	} else {
+	//		tagActivityIds = soloTagActivityIds
+	//	}
+	//}
+	//if soloMmIds != "" {
+	//	if mmIds != "" {
+	//		mmIds += "," + soloMmIds
+	//	} else {
+	//		mmIds = soloMmIds
+	//	}
+	//}
 
-	// 先拿abdc都有的tag取合集的ids。。。
-	soloTagArticleIds, soloTagActivityIds, soloMmIds, err := models.GetCygxCygxArticleListByConditionSoloTag(articleTypeCondSlice, activityTypesCondSlice, industriesCondSlice, subjectNamesSlice, articleTypeSlice)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取活动权限数据失败,Err:" + err.Error()
-		return
-	}
-
-	articleTypes = strings.TrimRight(articleTypes, ",")
-	activityTypes = strings.TrimRight(activityTypes, ",")
-	industries = strings.TrimRight(industries, ",")
-	subjectNames = strings.TrimRight(subjectNames, ",")
-
-	articleTypesCond := ``
-	var articleTypeStr string
-	if articleTypes != "" {
-		articleTypeSlice := strings.Split(articleTypes, ",")
-		newArticleTypeSlice := make([]string, 0)
-		for _, s := range articleTypeSlice {
-			newArticleTypeSlice = append(newArticleTypeSlice, "'"+s+"'")
-		}
-		articleTypeStr = strings.Join(newArticleTypeSlice, ",")
-		articleTypeStr = strings.TrimRight(articleTypeStr, ",")
-		articleTypesCond += ` AND (art.sub_category_name In (` + articleTypeStr + `) OR (art.article_type_name In (` + articleTypeStr + `) AND art.article_type_name <> '路演精华' AND art.article_type_id <> 0 ) ) `
-	}
-	activityTypesCond := ``
-	if activityTypes != "" {
-		activityTypeSlice := strings.Split(activityTypes, ",")
-		newActivityTypeSlice := make([]string, 0)
-		for _, s := range activityTypeSlice {
-			newActivityTypeSlice = append(newActivityTypeSlice, "'"+s+"'")
-		}
-		activityTypeStr := strings.Join(newActivityTypeSlice, ",")
-		activityTypeStr = strings.TrimRight(activityTypeStr, ",")
-		activityTypesCond += ` AND act.activity_type_name In (` + activityTypeStr + `) `
-	}
-	industriesCond := ``
-	var industryStr string
-	if industries != "" {
-		industrieSlice := strings.Split(industries, ",")
-		newIndustrieSlice := make([]string, 0)
-		for _, s := range industrieSlice {
-			newIndustrieSlice = append(newIndustrieSlice, "'"+s+"'")
-		}
-		industryStr = strings.Join(newIndustrieSlice, ",")
-		industryStr = strings.TrimRight(industryStr, ",")
-		industriesCond += ` AND im.industry_name In (` + industryStr + `) `
-	}
-	subjectNamesCond := ``
-	var subjectNameStr string
-	if subjectNames != "" {
-		subjectNameSlice := strings.Split(subjectNames, ",")
-		newSubjectNameSlice := make([]string, 0)
-		for _, s := range subjectNameSlice {
-			newSubjectNameSlice = append(newSubjectNameSlice, "'"+s+"'")
-		}
-		subjectNameStr = strings.Join(newSubjectNameSlice, ",")
-		subjectNameStr = strings.TrimRight(subjectNameStr, ",")
-		subjectNamesCond += ` AND cis.subject_name In (` + subjectNameStr + `) `
-	}
+	//查询近一个月的数据
+	conditionInit = " AND publish_date  >   '" + time.Now().AddDate(0, 0, -30).Format(utils.FormatDateTime) + "'"
 
-	var tagArticleIds, tagActivityIds, mmIds string
-	if articleTypesCond != "" || activityTypesCond != "" || industryStr != "" || subjectNameStr != "" {
-		tagArticleIds, tagActivityIds, mmIds, err = models.GetCygxCygxArticleListByCondition(articleTypesCond, activityTypesCond, industryStr, subjectNameStr, articleTypeStr)
-		if err != nil && err.Error() != utils.ErrNoRow() {
+	if tagIds != "" {
+		conditionTagIdsInit, err := services.GetConditionInitByTagIds(tagIds)
+		if err != nil {
 			br.Msg = "获取失败"
-			br.ErrMsg = "获取单个标签ids失败,Err:" + err.Error()
+			br.ErrMsg = "获取活动权限数据失败,GetConditionInitByTagIds Err:" + err.Error()
 			return
 		}
+		conditionInit += conditionTagIdsInit
 	}
-
-	if soloTagArticleIds != "" {
-		if tagArticleIds != "" {
-			tagArticleIds += "," + soloTagArticleIds
-		} else {
-			tagArticleIds = soloTagArticleIds
-		}
-	}
-	if soloTagActivityIds != "" {
-		if tagActivityIds != "" {
-			tagActivityIds += "," + soloTagActivityIds
-		} else {
-			tagActivityIds = soloTagActivityIds
-		}
-	}
-	if soloMmIds != "" {
-		if mmIds != "" {
-			mmIds += "," + soloMmIds
-		} else {
-			mmIds = soloMmIds
-		}
-	}
-
-	//查询近一个月的数据
-	conditionInit = " AND publish_date  >   '" + time.Now().AddDate(0, 0, -30).Format(utils.FormatDateTime) + "'"
+	//return
 	//conditionInit += `  AND source IN ('newchart')`
 	if user.CompanyId <= 1 {
 		condition += " AND source IN ('roadshow','article') "
@@ -536,37 +548,37 @@ func (this *MobileHomeController) NewList() {
 		}
 		lenActivityspecialIds := len(activityspecialIds)
 
-		if tagIds != "" {
-			if tagArticleIds != "" {
-				condition = ` AND ((source = 'article' AND source_id IN (` + tagArticleIds + `) ) `
-				if mmIds != "" {
-					condition += ` OR ( source = 'meetingreviewchapt' AND source_id IN (` + mmIds + `) )   `
-				}
-				if tagActivityIds != "" && lenActivityIds > 0 {
-					condition += ` OR (source = 'activity' AND source_id IN (` + tagActivityIds + `) AND source_id IN (` + utils.GetOrmInReplace(lenActivityIds) + `) )) `
-					pars = append(pars, activityIds)
-				} else {
-					// 无可见活动
-					condition += ` OR (source = 'activity' AND source_id IN (0))) `
-				}
-			} else if tagActivityIds != "" {
-				condition = ` AND ((source = 'article' AND source_id IN (0))  `
-				if mmIds != "" {
-					condition += ` OR ( source = 'meetingreviewchapt' AND source_id IN (` + mmIds + `) )   `
-				}
-				if tagActivityIds != "" && lenActivityIds > 0 {
-					condition += ` OR (source = 'activity' AND source_id IN (` + tagActivityIds + `) AND source_id IN (` + utils.GetOrmInReplace(lenActivityIds) + `))) `
-					pars = append(pars, activityIds)
-				} else {
-					// 无可见活动
-					condition += ` OR (source = 'activity' AND source_id IN (0))) `
-				}
-			} else if mmIds != "" {
-				condition = ` AND ( source = 'meetingreviewchapt' AND source_id IN (` + mmIds + `) )   `
-			} else {
-				condition += ` AND ((source = 'article' AND source_id IN (0)) OR (source = 'activity' AND source_id IN (0))) `
-			}
-		}
+		//if tagIds != "" {
+		//	if tagArticleIds != "" {
+		//		condition = ` AND ((source = 'article' AND source_id IN (` + tagArticleIds + `) ) `
+		//		if mmIds != "" {
+		//			condition += ` OR ( source = 'meetingreviewchapt' AND source_id IN (` + mmIds + `) )   `
+		//		}
+		//		if tagActivityIds != "" && lenActivityIds > 0 {
+		//			condition += ` OR (source = 'activity' AND source_id IN (` + tagActivityIds + `) AND source_id IN (` + utils.GetOrmInReplace(lenActivityIds) + `) )) `
+		//			pars = append(pars, activityIds)
+		//		} else {
+		//			// 无可见活动
+		//			condition += ` OR (source = 'activity' AND source_id IN (0))) `
+		//		}
+		//	} else if tagActivityIds != "" {
+		//		condition = ` AND ((source = 'article' AND source_id IN (0))  `
+		//		if mmIds != "" {
+		//			condition += ` OR ( source = 'meetingreviewchapt' AND source_id IN (` + mmIds + `) )   `
+		//		}
+		//		if tagActivityIds != "" && lenActivityIds > 0 {
+		//			condition += ` OR (source = 'activity' AND source_id IN (` + tagActivityIds + `) AND source_id IN (` + utils.GetOrmInReplace(lenActivityIds) + `))) `
+		//			pars = append(pars, activityIds)
+		//		} else {
+		//			// 无可见活动
+		//			condition += ` OR (source = 'activity' AND source_id IN (0))) `
+		//		}
+		//	} else if mmIds != "" {
+		//		condition = ` AND ( source = 'meetingreviewchapt' AND source_id IN (` + mmIds + `) )   `
+		//	} else {
+		//		condition += ` AND ((source = 'article' AND source_id IN (0)) OR (source = 'activity' AND source_id IN (0))) `
+		//	}
+		//}
 
 		if lenActivityIds > 0 && tagIds == "" {
 			condition += ` OR ( source = 'activity' AND source_id IN (` + utils.GetOrmInReplace(lenActivityIds) + `) ` + conditionInit + ` )    `
@@ -578,14 +590,14 @@ func (this *MobileHomeController) NewList() {
 			pars = append(pars, activityspecialIds)
 		}
 	}
-
+	//return
 	total, err = models.GetResourceDataCount(condition, pars)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
 		return
 	}
-
+	//return
 	if user.CompanyId <= 1 {
 		total = utils.PageSize5
 	}
@@ -598,6 +610,9 @@ func (this *MobileHomeController) NewList() {
 		br.ErrMsg = "获取数据列表失败,Err:" + err.Error()
 		return
 	}
+	if len(list) == 0 {
+		list = make([]*models.CygxResourceDataNewResp, 0)
+	}
 	page = paging.GetPaging(currentIndex, pageSize, total)
 	resp.Paging = page
 	resp.List = list

+ 17 - 0
models/cygx_tag.go

@@ -53,6 +53,23 @@ type CygxTagList struct {
 	CheckList     []string // ABCD勾选了哪几列
 }
 
+// 列表
+func GetCygxTagListCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxTagList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_tag as a WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	if startSize+pageSize > 0 {
+		sql += ` LIMIT ?,?  `
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	} else {
+		_, err = o.Raw(sql, pars).QueryRows(&items)
+	}
+
+	return
+}
+
 // 获取tag列表
 func GetCygxTagList(cond string) (items []*CygxTagList, err error) {
 	o := orm.NewOrm()

+ 1 - 47
models/industrial_activity_group_management.go

@@ -21,52 +21,6 @@ type CygxIndustrialActivityGroupSubject struct {
 	CreateTime          time.Time `description:"创建时间"`
 }
 
-type CygxIndustrialSubject struct {
-	IndustrialSubjectId    int       `orm:"column(industrial_subject_id);pk" description:"标的id"`
-	IndustrialManagementId int       `description:"产业id"`
-	SubjectName            string    `description:"标的名称"`
-	CreateTime             time.Time `description:"创建时间"`
-	Source                 int       `description:"来源,1正常添加,2:通过文章添加,3通过活动添加(默认为1)"`
-}
-
-//获取标的列表
-func GetCygxIndustrialSubjectList(subjectName string) (items []*CygxIndustrialSubject, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT
-				s.*
-			FROM
-				cygx_industrial_subject as s 
-				INNER JOIN  cygx_industrial_management as m ON  m.industrial_management_id = s.industrial_management_id
-			WHERE
-				subject_name = ? `
-	_, err = o.Raw(sql, subjectName).QueryRows(&items)
-	return
-}
-
-// AddCygxActiuvityGroupMulti 批量添加
-func AddCygxActiuvityGroupMulti(items []*CygxIndustrialActivityGroupManagement, itemsSubject []*CygxIndustrialActivityGroupSubject) (err error) {
-	o, err := orm.NewOrm().Begin()
-	if err != nil {
-		return
-	}
-	defer func() {
-		if err == nil {
-			o.Commit()
-		} else {
-			o.Rollback()
-		}
-	}()
-	if len(items) > 0 {
-		//批量添加关联的产业
-		_, err = o.InsertMulti(len(items), items)
-	}
-	if len(itemsSubject) > 0 {
-		//批量添加关联的标的
-		_, err = o.InsertMulti(len(itemsSubject), itemsSubject)
-	}
-	return
-}
-
 // GetActivityIndustryRelationList 获取活动与产业关联列表
 func GetActivityIndustryRelationList(condition string, pars []interface{}) (list []*CygxIndustrialActivityGroupManagement, err error) {
 	sql := `SELECT
@@ -84,7 +38,7 @@ func GetActivityIndustryRelationList(condition string, pars []interface{}) (list
 	return
 }
 
-//列表
+// 列表
 func GetIndustrialActivityGroupManagementList(activityId int) (items []*IndustrialManagementRep, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT

+ 19 - 0
models/industrial_subject.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"time"
 )
 
 type IndustrialSubjectByArticle struct {
@@ -17,6 +18,14 @@ type SubjectArticlGroupList struct {
 	IndustrialSubjectId int    `description:"cygx_industrial_subject表的文章ID"`
 }
 
+type CygxIndustrialSubject struct {
+	IndustrialSubjectId    int       `orm:"column(industrial_subject_id);pk" description:"标的id"`
+	IndustrialManagementId int       `description:"产业id"`
+	SubjectName            string    `description:"标的名称"`
+	CreateTime             time.Time `description:"创建时间"`
+	Source                 int       `description:"来源,1正常添加,2:通过文章添加,3通过活动添加(默认为1)"`
+}
+
 // 获取标的列表
 func GetArticleGroupSubjectList(pars []interface{}, condition string) (items []*IndustrialSubjectByArticle, err error) {
 	o := orm.NewOrm()
@@ -55,3 +64,13 @@ func GetcygxIndustrialSubject(industrialManagementId int) (items []*IndustrialSu
 	_, err = o.Raw(sql, industrialManagementId).QueryRows(&items)
 	return
 }
+
+// GetCygxIndustrialSubjectList 获取标的列表
+func GetCygxIndustrialSubjectList(condition string, pars []interface{}) (items []*CygxIndustrialSubject, err error) {
+	sql := `SELECT * FROM cygx_industrial_subject WHERE 1 = 1 `
+	if condition != `` {
+		sql += condition
+	}
+	_, err = orm.NewOrm().Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 60 - 0
models/resource_data_industrial_group_management.go

@@ -0,0 +1,60 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// 首页资源表与产业的关系
+type CygxResourceDataIndustrialGroupManagement struct {
+	Id                     int       `orm:"column(id);pk" description:"主键ID"`
+	ResourceDataId         int       `description:"cygx_resource_data 主键ID"`
+	SourceId               int       `description:"资源ID"`
+	Source                 string    `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
+	IndustrialManagementId int       `description:"cygx_industrial_management表的主键ID"`
+	CreateTime             time.Time `description:"创建时间"`
+}
+
+// 首页资源表与产业的关系
+type CygxResourceDataIndustrialGroupSubject struct {
+	Id                  int       `orm:"column(id);pk" description:"主键ID"`
+	ResourceDataId      int       `description:"cygx_resource_data 主键ID"`
+	SourceId            int       `description:"资源ID"`
+	Source              string    `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
+	IndustrialSubjectId int       `description:"cygx_industrial_subject表的主键ID"`
+	CreateTime          time.Time `description:"创建时间"`
+}
+
+// 关联产业列表
+func GetCygxResourceDataIndustrialGroupManagementList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceDataIndustrialGroupManagement, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_resource_data_industrial_group_management as a WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	if startSize+pageSize > 0 {
+		sql += ` LIMIT ?,?  `
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	} else {
+		_, err = o.Raw(sql, pars).QueryRows(&items)
+	}
+
+	return
+}
+
+// 关联标的列表
+func GetCygxResourceDataIndustrialGroupSubjectList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxResourceDataIndustrialGroupSubject, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_resource_data_industrial_group_subject as a WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	if startSize+pageSize > 0 {
+		sql += ` LIMIT ?,?  `
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	} else {
+		_, err = o.Raw(sql, pars).QueryRows(&items)
+	}
+
+	return
+}

+ 129 - 0
services/tag.go

@@ -1,9 +1,11 @@
 package services
 
 import (
+	"errors"
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/utils"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -36,3 +38,130 @@ func AddCygxTagHistory(user *models.WxUserItem, tagId int) (err error) {
 	_, err = models.AddCygxTagHistory(historyRecord)
 	return
 }
+
+//func init() {
+//	conditionInit, err := GetConditionInitByTagIds("20,21,26")
+//	fmt.Println(err)
+//	fmt.Println(conditionInit)
+//}
+
+func GetConditionInitByTagIds(tagIds string) (conditionInit string, err error) {
+	if tagIds == "" {
+		return
+	}
+	var condition string
+	var pars []interface{}
+	var searchTag, industries, subjectNames []string
+	tagslice := strings.Split(tagIds, ",")
+	condition = ` AND tag_id IN (` + utils.GetOrmInReplace(len(tagslice)) + `)`
+	pars = append(pars, tagslice)
+	listTag, e := models.GetCygxTagListCondition(condition, pars, 0, 0)
+	if e != nil {
+		err = errors.New("GetActivityListByCondition, Err: " + e.Error())
+		return
+	}
+
+	for _, tagInfo := range listTag {
+		//ActivityTypes 与 ArticleTypes 进行合并
+		if tagInfo.ActivityTypes != "" {
+			searchTag = append(searchTag, tagInfo.ActivityTypes)
+		}
+		if tagInfo.ArticleTypes != "" {
+			searchTag = append(searchTag, tagInfo.ArticleTypes)
+		}
+		if tagInfo.Industries != "" {
+			industries = append(industries, tagInfo.Industries)
+		}
+		if tagInfo.SubjectNames != "" {
+			subjectNames = append(subjectNames, tagInfo.SubjectNames)
+		}
+	}
+
+	//拼接search_tag 搜索内容
+	if len(searchTag) > 0 {
+		conditionInit += " AND search_tag IN  ('" + strings.Join(searchTag, "','") + "')"
+	}
+
+	var resourceDataIds []int //cygx_resource_data 主键ID
+	//如果产业有组合,那么就去捞产业相关的内容
+	if len(industries) > 0 {
+		// 获取近一个月产业报告阅读次数最多的产业
+		var conditionIndustry string
+		var parsIndustry []interface{}
+		conditionIndustry += " AND industry_name IN  ('" + strings.Join(industries, "','") + "')"
+		listIndustry, e := models.GetTopOneMonthArtReadNumIndustryAll(conditionIndustry, parsIndustry)
+		if e != nil {
+			err = errors.New("GetTopOneMonthArtReadNumIndustryAll, Err: " + e.Error())
+			return
+		}
+		var industrialManagementIds []int // 产业ID合集
+		for _, v := range listIndustry {
+			industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
+		}
+
+		var conditionIndustryResource string
+		var parsIndustryResource []interface{}
+		lenArrindustrial := len(industrialManagementIds)
+		conditionIndustryResource = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(lenArrindustrial) + `)`
+		parsIndustryResource = append(parsIndustryResource, industrialManagementIds)
+
+		if lenArrindustrial > 0 {
+			listResourceDataIndustrial, e := models.GetCygxResourceDataIndustrialGroupManagementList(conditionIndustryResource, parsIndustryResource, 0, 0)
+			//return
+			if e != nil {
+				err = errors.New("GetCygxResourceDataIndustrialGroupManagementList, Err: " + e.Error())
+				return
+			}
+			for _, v := range listResourceDataIndustrial {
+				resourceDataIds = append(resourceDataIds, v.ResourceDataId)
+			}
+		}
+	}
+	//return
+	//如果标的有组合,那么就去捞标的相关的内容
+	if len(subjectNames) > 0 {
+		// 获取近一个月产业报告阅读次数最多的产业
+		var conditionsubject string
+		var parssubject []interface{}
+		conditionsubject += " AND subject_name IN  ('" + strings.Join(subjectNames, "','") + "')"
+		listsubject, e := models.GetCygxIndustrialSubjectList(conditionsubject, parssubject)
+		if e != nil {
+			err = errors.New("GetTopOneMonthArtReadNumIndustry, Err: " + e.Error())
+			return
+		}
+		var industrialsubjectIds []int // 标的ID集合
+		for _, v := range listsubject {
+			industrialsubjectIds = append(industrialsubjectIds, v.IndustrialSubjectId)
+		}
+		var conditionsubjectResource string
+		var parssubjectResource []interface{}
+		lenArrsubject := len(industrialsubjectIds)
+		conditionsubjectResource = ` AND industrial_subject_id IN (` + utils.GetOrmInReplace(lenArrsubject) + `)`
+		parssubjectResource = append(parssubjectResource, industrialsubjectIds)
+		if lenArrsubject > 0 {
+			listResourceDatasubject, e := models.GetCygxResourceDataIndustrialGroupSubjectList(conditionsubjectResource, parssubjectResource, 0, 0)
+			if e != nil {
+				err = errors.New("GetCygxResourceDataIndustrialGroupSubjectList, Err: " + e.Error())
+				return
+			}
+			for _, v := range listResourceDatasubject {
+				resourceDataIds = append(resourceDataIds, v.ResourceDataId)
+			}
+		}
+	}
+
+	//拼接 cygx_resource_data 表主键查询ID
+	if len(resourceDataIds) > 0 {
+		var resourceDataIdStrs []string
+		resourceDataIdMap := make(map[int]bool)
+		for _, v := range resourceDataIds {
+			if resourceDataIdMap[v] {
+				continue
+			}
+			resourceDataIdStrs = append(resourceDataIdStrs, strconv.Itoa(v))
+			resourceDataIdMap[v] = true
+		}
+		conditionInit += " AND id IN  (" + strings.Join(resourceDataIdStrs, ",") + ") "
+	}
+	return
+}