Browse Source

no message

xingzai 1 year ago
parent
commit
fc6a993a10
2 changed files with 81 additions and 8 deletions
  1. 12 8
      controllers/report.go
  2. 69 0
      models/report.go

+ 12 - 8
controllers/report.go

@@ -830,6 +830,7 @@ func (this *MobileReportController) SearchReport() {
 	keyWord := this.GetString("KeyWord")
 	isAll, _ := this.GetBool("IsAll")
 	var condition string
+	var conditionYxSpecial string
 	var pars []interface{}
 	//var conditionSql string
 	var total int
@@ -940,13 +941,16 @@ func (this *MobileReportController) SearchReport() {
 		}
 	} else {
 
-		//condition = `AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
-		if articleType == 1 {
-			condition = `  AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1  AND a.article_type_id NOT IN (` + articleTypeIds + `)  `
-			total, err = models.GetReoprtSearchCountHz(condition)
-		} else {
-			condition = `  AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1  AND a.article_type_id  IN (` + articleTypeIds + `)  `
-			total, err = models.GetReoprtSearchCountYx(condition)
+		if keyWord != "" {
+			if articleType == 1 {
+				condition = `  AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1  AND a.article_type_id NOT IN (` + articleTypeIds + `)  `
+				total, err = models.GetReoprtSearchCountHz(condition)
+			} else {
+				condition = `  AND ( a.title LIKE '%` + keyWord + `%' OR  a.body LIKE '%` + keyWord + `%' OR  a.annotation LIKE '%` + keyWord + `%' OR  a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1  AND a.article_type_id  IN (` + articleTypeIds + `)  `
+				total, err = models.GetReoprtSearchCountYx(condition)
+			}
+
+			conditionYxSpecial = `   AND ( a.title LIKE '%` + keyWord + `%' OR  a.content LIKE '%` + keyWord + `%')  `
 		}
 		if err != nil {
 			br.Msg = "获取信息失败"
@@ -958,7 +962,7 @@ func (this *MobileReportController) SearchReport() {
 		if articleType == 1 {
 			list, err = models.GetArticleResearchListHz(condition, pars, startSize, pageSize, user.UserId)
 		} else {
-			list, err = models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId, true)
+			total, list, err = models.GetArticleResearchAndYxSpecialList(condition, conditionYxSpecial, pars, startSize, pageSize, user.UserId, true)
 		}
 		if err != nil {
 			br.Msg = "获取信息失败"

+ 69 - 0
models/report.go

@@ -935,6 +935,75 @@ func GetArticleResearchList(condition string, pars []interface{}, startSize, pag
 	return
 }
 
+func GetArticleResearchAndYxSpecialList(condition, conditionYxSpecial string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (total int, items []*ArticleListResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			a.article_id,
+			a.title,
+			a.body,
+			a.annotation,
+			a.abstract,
+			a.publish_date,
+			a.article_type_id,
+			d.nick_name,
+			d.department_id,
+			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac    WHERE ac.article_id = a.article_id  ) AS collect_num, 
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac   WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time )  ) AS collect_num_order, 
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id  AND user_id = ? ) AS my_collect_num,
+			0 AS is_special,
+			0 AS special_type,
+			0 AS special_column_id,
+			'' AS company_tags, 
+			'' AS industry_tags
+		FROM
+			cygx_article AS a
+			LEFT JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
+			LEFT JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
+			INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id 
+		WHERE
+			1 = 1  AND a.publish_status = 1  `
+	if condition != "" {
+		sql += condition
+	}
+	if needYanxuanSpecial {
+		sql += `UNION ALL
+	SELECT
+		a.id AS article_id,
+		a.title AS title,
+		'' AS body,
+		a.content AS annotation,
+		'' AS abstract,
+		a.publish_time AS publish_date,
+		-1 AS article_type_id,
+		b.nick_name AS nick_name,
+		0 AS department_id,
+		( SELECT count( 1 ) FROM cygx_yanxuan_special_record AS h WHERE h.yanxuan_special_id = a.id ) AS pv,
+		( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac   WHERE ac.yanxuan_special_id = a.id  ) AS collect_num,
+		0 AS collect_num_order,
+		( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id  AND user_id = ? ) AS my_collect_num,
+		1 AS is_special,
+		a.type AS special_type,
+		b.id AS special_column_id,
+		a.company_tags AS company_tags, 
+		a.industry_tags AS industry_tags 
+	FROM
+	cygx_yanxuan_special AS a
+	JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
+	WHERE
+	1 = 1  AND a.status = 3 ` + conditionYxSpecial
+
+		totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
+		err = o.Raw(totalSql, userId, userId, pars).QueryRow(&total)
+		sql += ` GROUP BY article_id ORDER  BY publish_date DESC  LIMIT ?,? `
+		_, err = o.Raw(sql, userId, userId, pars, startSize, pageSize).QueryRows(&items)
+	} else {
+		sql += ` GROUP BY a.article_id ORDER  BY a.publish_date DESC  LIMIT ?,? `
+		_, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
+	}
+	return
+}
+
 func GetArticleResearchListHz(condition string, pars []interface{}, startSize, pageSize, userId int) (items []*ArticleListResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT