瀏覽代碼

新增获取报告作者信息

rdluck 4 年之前
父節點
當前提交
019fc90637
共有 8 個文件被更改,包括 206 次插入45 次删除
  1. 26 0
      controllers/classify.go
  2. 43 6
      controllers/home.go
  3. 37 0
      controllers/report.go
  4. 8 0
      models/classify.go
  5. 38 32
      models/home.go
  6. 51 0
      models/report.go
  7. 3 0
      routers/router.go
  8. 0 7
      services/home.go

+ 26 - 0
controllers/classify.go

@@ -6,6 +6,10 @@ type ClassifyController struct {
 	BaseAuthController
 }
 
+type ClassifyCommonController struct {
+	BaseCommonController
+}
+
 // @Title 获取分类详情信息
 // @Description 获取分类详情信息接口
 // @Param   ClassifyId   query   int  true       "分类id"
@@ -39,3 +43,25 @@ func (this *ClassifyController) Detail() {
 	br.Msg = "获取数据成功"
 	br.Data = item
 }
+
+// @Title 获取一级分类列表
+// @Description 获取一级分类列表接口
+// @Success 200 {object} models.Classify
+// @router /pc/list [get]
+func (this *ClassifyCommonController) List() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	item, err := models.GetClassifyList()
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取数据成功"
+	br.Data = item
+}

+ 43 - 6
controllers/home.go

@@ -3,6 +3,8 @@ package controllers
 import (
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/services"
+	"hongze/hongze_api/utils"
+	"rdluck_tools/paging"
 )
 
 //首页
@@ -73,10 +75,12 @@ func (this *HomeController) ListBanner() {
 	br.Data = list
 }
 
-
 // @Title pc-首页列表接口
 // @Description pc-首页列表接口
-// @Success 200 {object} models.HomeList
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ClassifyId   query   int  true       "分类id"
+// @Success 200 {object} models.PcListHomeResp
 // @router /pc/list [get]
 func (this *HomeCommonController) ListHome() {
 	br := new(models.BaseResponse).Init()
@@ -84,7 +88,32 @@ func (this *HomeCommonController) ListHome() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	list, err := services.PcHomeList()
+	authorization := this.Ctx.Input.Header("Authorization")
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+
+	classifyId, _ := this.GetInt("ClassifyId")
+	if classifyId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误"
+		return
+	}
+	total, err := models.PcListHomeCount(classifyId)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	list, err := models.PcListHome(classifyId, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取数据失败"
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
@@ -93,13 +122,21 @@ func (this *HomeCommonController) ListHome() {
 	for i := 0; i < len(list); i++ {
 		item := list[i]
 		if item.ClassifyName == "权益研报" {
-			list[i].TitleType = "权益"
+			list[i].ReportInfo.TitleType = "权益"
 		} else {
-			list[i].TitleType = "FICC"
+			list[i].ReportInfo.TitleType = "FICC"
+		}
+
+		if authorization == "" {
+			list[i].ReportInfo.VideoUrl = ""
 		}
 	}
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(models.PcListHomeResp)
+	resp.Paging = page
+	resp.List = list
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取数据成功"
-	br.Data = list
+	br.Data = resp
 }

+ 37 - 0
controllers/report.go

@@ -429,3 +429,40 @@ func (this *ReportController) AddAudioRecord() {
 //	utils.FileLog.Info("%s",newContent)
 //	fmt.Println("end")
 //}
+
+// @Title 获取报告作者详情
+// @Description 获取报告作者详情
+// @Param   ReportAuthor   query   string  true       "作者名称"
+// @Success 200 {object} models.ReportDetailResp
+// @router /author/detail [get]
+func (this *ReportController) AuthorDetail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+
+	reportAuthor := this.GetString("ReportAuthor")
+	if reportAuthor == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "作者名称不能为空"
+		return
+	}
+	author, err := models.GetReportAuthor(reportAuthor)
+	if err != nil {
+		br.Msg = "获取作者详情失败"
+		br.ErrMsg = "获取作者详情失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = author
+}

+ 8 - 0
models/classify.go

@@ -23,3 +23,11 @@ func GetClassifyById(classifyId int) (item *Classify, err error) {
 	err = o.Raw(sql, classifyId).QueryRow(&item)
 	return
 }
+
+func GetClassifyList() (item []*Classify, err error) {
+	sql := ` SELECT * FROM classify WHERE parent_id = 0  `
+	o := orm.NewOrm()
+	o.Using("rddp")
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}

+ 38 - 32
models/home.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"hongze/hongze_api/utils"
 	"rdluck_tools/orm"
+	"rdluck_tools/paging"
 )
 
 type HomeList struct {
@@ -77,50 +78,55 @@ func ListHome(userId, maxPermission, userPermission int, permissionStr string) (
 	return
 }
 
-func PcListHome() (items []*HomeList, err error) {
+type PcHomeClassifyItem struct {
+	ClassifyId   int    `orm:"column(id)"`
+	ClassifyName string `description:"分类名称"`
+	ReportInfo   *PcReport
+}
+
+func PcListHomeCount(classifyId int) (count int, err error) {
 	o := orm.NewOrm()
 	o.Using("rddp")
-	sql := `SELECT id,classify_name FROM classify WHERE parent_id=0 ORDER BY create_time ASC `
-	_, err = o.Raw(sql).QueryRows(&items)
+	sql := `SELECT COUNT(1) AS count FROM classify WHERE parent_id=? `
+	err = o.Raw(sql, classifyId).QueryRow(&count)
+	return
+}
+
+func PcListHome(classifyId, startSize, pageSize int) (items []*PcHomeClassifyItem, err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	subSql := ` SELECT id ,classify_name FROM classify WHERE parent_id=?  `
+	subSql += ` ORDER BY create_time ASC LIMIT ?,? `
+	_, err = o.Raw(subSql, classifyId, startSize, pageSize).QueryRows(&items)
 	if err != nil {
-		fmt.Println("Get classify Err:" + err.Error())
+		fmt.Println("Sub Err:" + err.Error())
 		return
 	}
-	lenItem := len(items)
-	for i := 0; i < lenItem; i++ {
-		item := items[i]
-		subItems := make([]*HomeClassifyItem, 0)
-		subWhere := ``
-		subWhere = ` WHERE parent_id=? `
-		subSql := `SELECT id ,classify_name FROM classify   `
-		subSql += subWhere
-		subSql += ` ORDER BY create_time ASC `
-		_, err = o.Raw(subSql, item.ClassifyId).QueryRows(&subItems)
-		if err != nil {
-			fmt.Println("Sub Err:" + err.Error())
-			return
-		}
-		lenSub := len(subItems)
-		for k := 0; k < lenSub; k++ {
-			subItem := subItems[k]
-			reportSql := ` SELECT a.id,a.classify_name,b.*,
+	lenSub := len(items)
+	for k := 0; k < lenSub; k++ {
+		subItem := items[k]
+		reportSql := ` SELECT a.id,a.classify_name,b.*,c.*,
                 CASE WHEN DATE(b.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
                 FROM classify AS a
                 INNER JOIN report AS b ON a.id=b.classify_id_second
+                INNER JOIN report_author AS c ON b.author=c.report_author
                 WHERE b.state=2 AND a.id=?
                 ORDER BY b.publish_time DESC LIMIT 1  `
-			report := new(Report)
-			err = o.Raw(reportSql, subItem.ClassifyId).QueryRow(&report)
-			if err != nil {
-				if err.Error() != utils.ErrNoRow() {
-					return
-				} else {
-					err = nil
-				}
+		report := new(PcReport)
+		err = o.Raw(reportSql, subItem.ClassifyId).QueryRow(&report)
+		if err != nil {
+			if err.Error() != utils.ErrNoRow() {
+				return
+			} else {
+				err = nil
 			}
-			subItems[k].Child = report
 		}
-		items[i].Child = subItems
+		items[k].ReportInfo = report
 	}
 	return
 }
+
+type PcListHomeResp struct {
+	Paging *paging.PagingItem
+	List   []*PcHomeClassifyItem
+}

+ 51 - 0
models/report.go

@@ -210,3 +210,54 @@ func GetReportByCode(reportCode string) (item *Report, err error) {
 type ReportShareDetailResp struct {
 	Report *Report `description:"报告"`
 }
+
+type PcReport struct {
+	Id                 int       `description:"报告Id"`
+	AddType            int       `description:"新增方式:1:新增报告,2:继承报告"`
+	ClassifyIdFirst    int       `description:"一级分类id"`
+	ClassifyNameFirst  string    `description:"一级分类名称"`
+	ClassifyIdSecond   int       `description:"二级分类id"`
+	ClassifyNameSecond string    `description:"二级分类名称"`
+	Title              string    `description:"标题"`
+	Abstract           string    `description:"摘要"`
+	Author             string    `description:"作者"`
+	Frequency          string    `description:"频度"`
+	CreateTime         string    `description:"创建时间"`
+	ModifyTime         time.Time `description:"修改时间"`
+	State              int       `description:"1:未发布,2:已发布"`
+	PublishTime        string    `description:"发布时间"`
+	Stage              int       `description:"期数"`
+	MsgIsSend          int       `description:"消息是否已发送,0:否,1:是"`
+	Content            string    `json:"-" description:"内容"`
+	VideoUrl           string    `description:"音频文件URL"`
+	VideoName          string    `description:"音频文件名称"`
+	VideoPlaySeconds   string    `description:"音频播放时长"`
+	ContentSub         string    `json:"-" description:"内容前两个章节"`
+	IsShowNewLabel     int       `description:"是否显示新标签"`
+	IsCurrentDate      int       `description:"是否当前日期"`
+	ClassifyName       string    `description:"分类名称"`
+	TitleType          string    `description:"标题类型,FICC或者权益"`
+	ReportAuthor
+}
+
+type ReportAuthor struct {
+	ReportAuthor             string `description:"报告作者名称"`
+	AuthorTitle              string `description:"标题"`
+	AuthorSummaryBase        string `description:"基础介绍"`
+	AuthorHeadSmallUrl       string `description:"小头像"`
+	AuthorHeadSmallDoubleUrl string `description:"两倍小头像"`
+	AuthorHeadBigUrl         string `description:"大头像"`
+	AuthorHeadBigDoubleUrl   string `description:"两倍大头像"`
+	AuthorSummaryExt         string `description:"扩展介绍"`
+	SpeakerBase              string `description:"主讲人"`
+	SpeakerExt               string `description:"主讲人"`
+	AuthorHeadSquare         string `description:"方形头像"`
+}
+
+func GetReportAuthor(reportAuthor string) (item *ReportAuthor, err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	sql := `SELECT * FROM report_author WHERE report_author=? `
+	err = o.Raw(sql, reportAuthor).QueryRow(&item)
+	return
+}

+ 3 - 0
routers/router.go

@@ -43,6 +43,9 @@ func init() {
 			beego.NSInclude(
 				&controllers.ClassifyController{},
 			),
+			beego.NSInclude(
+				&controllers.ClassifyCommonController{},
+			),
 		),
 		beego.NSNamespace("/wechat",
 			beego.NSInclude(

+ 0 - 7
services/home.go

@@ -39,10 +39,3 @@ func HomeList(userId, companyId int) (items []*models.HomeList, err error) {
 	}
 	return
 }
-
-
-func PcHomeList() (items []*models.HomeList, err error) {
-	items, err = models.PcListHome()
-	return
-}
-