浏览代码

首页 产业搜索分类 排序

xingzai 3 年之前
父节点
当前提交
76f22af523
共有 8 个文件被更改,包括 142 次插入23 次删除
  1. 54 3
      controllers/report.go
  2. 2 3
      controllers/tactics.go
  3. 1 1
      models/article.go
  4. 46 7
      models/industrial_management.go
  5. 2 0
      models/report.go
  6. 17 6
      models/report_mapping.go
  7. 1 3
      models/tactics.go
  8. 19 0
      utils/common.go

+ 54 - 3
controllers/report.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
 	"strings"
 	"time"
 )
@@ -28,17 +29,30 @@ func (this *ReportController) TradeList() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
 	ChartPermissionId, _ := this.GetInt("ChartPermissionId")
 	if ChartPermissionId < 1 {
 		br.Msg = "请输入分类ID"
 		return
 	}
-	list, err := models.GetTradeAll(ChartPermissionId)
+	list, err := models.GetTradeAll(uid, ChartPermissionId)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 		return
 	}
+	for k, v := range list {
+		list[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
+		if v.Readnum == 0 {
+			list[k].IsRed = true
+		}
+	}
 	resp := new(models.TradeReportMappingResp)
 	resp.List = list
 	br.Ret = 200
@@ -59,12 +73,50 @@ func (this *ReportController) IndustryList() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	uid = 50878
+	var orderSrt string
 	ChartPermissionId, _ := this.GetInt("ChartPermissionId")
+	orderColumn := this.GetString("OrderColumn")
+
+	if orderColumn == " " {
+		orderColumn = "NewTime"
+	}
 	if ChartPermissionId < 1 {
 		br.Msg = "请输入分类ID"
 		return
 	}
-	list, err := models.GetIndustrialManagementAll(ChartPermissionId)
+	listTop, err := models.GetIndustrialManagementTopAll(ChartPermissionId, uid)
+	for k, v := range listTop {
+		listTop[k].IsTop = true
+		if v.Readnum == 0 {
+			listTop[k].IsRed = true
+		}
+		listTop[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
+		listTop[k].LayoutTime = utils.TimeRemoveHms(v.LayoutTime)
+	}
+	if orderColumn == "NewTime" {
+		orderSrt = "art.publish_date DESC"
+	} else {
+		orderSrt = "man.recommended_index DESC"
+	}
+
+	list, err := models.GetIndustrialManagementAll(ChartPermissionId, uid, orderSrt)
+	for k, v := range list {
+		list[k].IsTop = true
+		if v.Readnum == 0 {
+			listTop[k].IsRed = true
+		}
+		list[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
+		list[k].LayoutTime = utils.TimeRemoveHms(v.LayoutTime)
+	}
+	list = append(listTop, list...)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
@@ -78,7 +130,6 @@ func (this *ReportController) IndustryList() {
 			br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 			return
 		}
-		list[k].AnalystList = analystList
 		industrialSubjectList, err := models.GetIndustrialSubjectAll(v.IndustrialManagementId)
 		if err != nil {
 			br.Msg = "获取信息失败"

+ 2 - 3
controllers/tactics.go

@@ -82,7 +82,7 @@ func (this *TacticsController) List() {
 		br.Msg = "获取帖子总数失败,Err:" + err.Error()
 		return
 	}
-	uid = 42017
+	uid = 46085
 	page = paging.GetPaging(currentIndex, pageSize, total)
 	list, err := models.GetReportTacticsList(condition, pars, uid, startSize, pageSize)
 	if err != nil {
@@ -99,8 +99,7 @@ func (this *TacticsController) List() {
 	}
 
 	for k, v := range list {
-		fmt.Println(v.Re)
-		if v.Re > 0 {
+		if v.Readnum > 0 {
 			list[k].IsRed = false
 		} else {
 			list[k].IsRed = true

+ 1 - 1
models/article.go

@@ -257,7 +257,7 @@ type ReportArticle struct {
 	SubCategoryName  string `description:"二级分类"`
 	ExpertBackground string `description:"专家背景"`
 	IsRed            bool   `description:"是否标记红点"`
-	Re               int    `description:"阅读数量"`
+	Readnum          int    `description:"阅读数量"`
 }
 
 func GetReportPermission(categoryName string) (item []*ChartPermission, err error) {

+ 46 - 7
models/industrial_management.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"rdluck_tools/orm"
+	"strconv"
 )
 
 type IndustrialManagementRep struct {
@@ -11,14 +12,52 @@ type IndustrialManagementRep struct {
 	LayoutTime        string `description:"布局时间"`
 }
 
-//产业列表
-func GetIndustrialManagementAll(ChartPermissionId int) (items []*IndustrialManagement, err error) {
+//产业列表 不置顶
+func GetIndustrialManagementAll(ChartPermissionId, uid int, orderSrt string) (items []*IndustrialManagement, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT *
-		FROM
-		cygx_industrial_management AS man 
-		WHERE
-		man.chart_permission_id = ?`
+	sql := `SELECT
+	man.*,
+	art.publish_date AS update_time,(
+	SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(uid) + ` AND rec.article_id = art.article_id ) AS readnum 
+FROM
+	cygx_industrial_management AS man
+	INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
+	INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
+	INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id 
+WHERE
+	man.chart_permission_id = ? 
+	AND man.industrial_management_id NOT IN ( SELECT industrial_management_id FROM cygx_industry_top WHERE user_id = ` + strconv.Itoa(uid) + ` ) 
+	AND re.report_type = 2 
+	AND art.is_report = 1
+GROUP BY
+	man.industry_name 
+ORDER BY ` + orderSrt
+	_, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
+	return
+}
+
+//产业列表 -置顶
+func GetIndustrialManagementTopAll(ChartPermissionId, uid int) (items []*IndustrialManagement, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	man.*,
+	art.publish_date AS update_time,(
+	SELECT COUNT( 1 ) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(uid) + ` AND rec.article_id = art.article_id ) AS readnum 
+FROM
+	cygx_industrial_management AS man
+	 INNER  JOIN cygx_industry_top as top ON man.industrial_management_id = top.industrial_management_id 
+	INNER JOIN cygx_report_mapping AS re ON re.chart_permission_id = man.chart_permission_id
+	INNER JOIN cygx_industrial_article_group_management AS man_g ON man_g.industrial_management_id = man.industrial_management_id
+	INNER JOIN cygx_article AS art ON art.article_id = man_g.article_id 
+WHERE
+	man.chart_permission_id = ? 
+	AND top.user_id = ` + strconv.Itoa(uid) + `
+	AND re.report_type = 2 
+	AND art.is_report = 1
+GROUP BY
+	man.industry_name 
+ORDER BY
+	art.publish_date DESC`
 	_, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
 	return
 }

+ 2 - 0
models/report.go

@@ -15,6 +15,8 @@ type IndustrialManagement struct {
 	AnalystList            []*IndustrialAnalyst `description:"分析师列表"`
 	Analyst                string               `description:"分析师"`
 	IndustrialSubjectList  []*IndustrialSubject `description:"标的列表"`
+	Readnum                int                  `description:"阅读数量"`
+	Topnum                 int                  `description:"置顶数量"`
 }
 
 type IndustrialAnalyst struct {

+ 17 - 6
models/report_mapping.go

@@ -5,14 +5,15 @@ import "rdluck_tools/orm"
 type ReportMapping struct {
 	CategoryId      int    `description:"分类ID"`
 	SubCategoryName string `description:"权限名称"`
-	IsRead          bool   `description:"是否标红"`
+	IsRed           bool   `description:"是否标红"`
 }
 
 type TradeReportMapping struct {
 	CategoryId      int    `description:"分类ID"`
 	SubCategoryName string `description:"权限名称"`
-	IsRead          bool   `description:"是否标红"`
+	IsRed           bool   `description:"是否标红"`
 	UpdateTime      string `description:"更新时间"`
+	Readnum         int    `description:"阅读数量"`
 }
 
 type ReportMappingResp struct {
@@ -32,17 +33,27 @@ func GetReportMappingStrategyAll() (items []*ReportMapping, err error) {
 }
 
 //行业列表
-func GetTradeAll(ChartPermissionId int) (items []*TradeReportMapping, err error) {
+func GetTradeAll(uid, ChartPermissionId int) (items []*TradeReportMapping, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_report_mapping WHERE chart_permission_id = ? AND report_type = 1;`
-	_, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
+	//sql := `SELECT * FROM cygx_report_mapping WHERE chart_permission_id = ? AND report_type = 1;`
+	sql := `SELECT
+	art.article_id,art.publish_date as update_time ,re.category_id,re.sub_category_name,( SELECT COUNT( 1 ) FROM  cygx_article_history_record AS rec WHERE rec.user_id = ? AND rec.article_id = art.article_id ) AS readnum
+	FROM
+		cygx_report_mapping  as re
+        INNER JOIN cygx_article  as art ON re.category_id = art.category_id
+	WHERE
+	re.chart_permission_id = ?
+	AND re.report_type = 1
+	ORDER BY art.publish_date DESC
+	LIMIT 0,1`
+	_, err = o.Raw(sql, uid, ChartPermissionId).QueryRows(&items)
 	return
 }
 
 type IndustrialToArticleCategoryRep struct {
 	CategoryId    int    `description:"分类ID"`
 	MatchTypeName string `description:"权限名称"`
-	IsRead        bool   `description:"是否标红"`
+	IsRed         bool   `description:"是否标红"`
 }
 
 type IndustrialToArticleCategoryListRep struct {

+ 1 - 3
models/tactics.go

@@ -1,7 +1,6 @@
 package models
 
 import (
-	"fmt"
 	"rdluck_tools/orm"
 	"rdluck_tools/paging"
 	"strconv"
@@ -119,14 +118,13 @@ type TacticsListResp struct {
 
 func GetReportTacticsList(condition string, pars []interface{}, userId, startSize, pageSize int) (items []*ReportArticle, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * ,(SELECT COUNT(1) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND  rec.article_id=a.article_id) AS re
+	sql := ` SELECT * ,(SELECT COUNT(1) FROM cygx_article_history_record AS rec WHERE rec.user_id = ` + strconv.Itoa(userId) + ` AND  rec.article_id=a.article_id) AS readnum
                  FROM cygx_article AS a
                 WHERE a.publish_status=1 `
 	if condition != "" {
 		sql += condition
 	}
 	sql += ` ORDER BY publish_date DESC LIMIT ?,? `
-	fmt.Println(sql)
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }

+ 19 - 0
utils/common.go

@@ -550,3 +550,22 @@ func ConvertToFormatDay(excelDaysString string) string {
 	resultTime := time.Unix(int64(baseOriginSecond+realDiffSecond), 0).Format("2006-01-02")
 	return resultTime
 }
+
+//字符串转换为time
+func StrTimeToTime(strTime string) time.Time {
+	timeLayout := "2006-01-02 15:04:05"  //转化所需模板
+	loc, _ := time.LoadLocation("Local") //重要:获取时区
+	resultTime, _ := time.ParseInLocation(timeLayout, strTime, loc)
+	return resultTime
+}
+
+//时间格式去掉时分秒
+func TimeRemoveHms(strTime string) string {
+	var Ymd string
+	var resultTime = StrTimeToTime(strTime)
+	year := resultTime.Year()
+	month := resultTime.Format("01")
+	day1 := time.Now().Day()
+	Ymd = strconv.Itoa(year) + "." + month + "." + strconv.Itoa(day1)
+	return Ymd
+}