Преглед на файлове

Merge branch 'bzq/dev' of eta_mini/eta_mini_bridge into debug

鲍自强 преди 11 месеца
родител
ревизия
de28336361
променени са 6 файла, в които са добавени 205 реда и са изтрити 54 реда
  1. 1 1
      controllers/chart_permission.go
  2. 24 0
      controllers/classify.go
  3. 90 11
      controllers/report.go
  4. 8 0
      models/classify.go
  5. 73 42
      models/report.go
  6. 9 0
      routers/commentsRouter.go

+ 1 - 1
controllers/chart_permission.go

@@ -189,7 +189,7 @@ func (this *ChartPermissionController) Private() {
 // DetailByClassify
 // @Title 获取品种权限根据分类id
 // @Description 获取品种权限根据分类id
-// @Param   ClassifyId   query   int  true       "二级分类的id"
+// @Param   ClassifyId   query   int  true       "分类的id"
 // @Param   Scope   query   int  true       "0:获取二级权限,1:获取一级权限,2:获取所有权限"
 // @Success 200 {object} []models.ChartPermission
 // @router /classify/detail [get]

+ 24 - 0
controllers/classify.go

@@ -90,3 +90,27 @@ func (this *ClassifyController) FirstChartPermission() {
 	br.Ret = 200
 	br.Msg = "获取成功"
 }
+
+// @Title 获取所有分类
+// @Description 获取所有分类
+// @Success 200 {object} []models.ClassifyView
+// @router /list [get]
+func (this *ClassifyController) AllClassify() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	classifyList, err := models.GetClassifyList()
+	if err != nil {
+		br.Msg = "获取分类失败"
+		br.ErrMsg = "获取分类失败,系统错误,Err:" + err.Error()
+		return
+	}
+
+	br.Data = classifyList
+	br.Success = true
+	br.Ret = 200
+	br.Msg = "获取成功"
+}

+ 90 - 11
controllers/report.go

@@ -62,9 +62,34 @@ func (this *ReportController) List() {
 		currentIndex = 1
 	}
 	startSize = utils.StartIndex(currentIndex, pageSize)
-
+	classifyList, err := models.GetClassifyList()
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	classifyMap := make(map[int]*models.ClassifyView)
+	isHas := false
+	for _, v := range classifyList {
+		if v.Id == classifyId && classifyId != 0 {
+			isHas = true
+		}
+		classifyMap[v.Id] = v
+	}
+	if !isHas && classifyId != 0 {
+		br.Msg = "分类不存在"
+		return
+	}
+	leafClassifyIds := getLeafClassifyIds(classifyMap, classifyId)
+	classifyIdMap := make(map[int]struct{})
+	for _, v := range leafClassifyIds {
+		classifyIdMap[v] = struct{}{}
+	}
 	var total int
 	var reportList []*models.ReportList
+	classifyFirstIds := make([]int, 0)
+	classifySecondIds := make([]int, 0)
+	classifyThirdIds := make([]int, 0)
 	switch level {
 	case 2:
 		classifyIds, err := models.GetClassifyIdsListById(chartPermissionId)
@@ -78,26 +103,44 @@ func (this *ReportController) List() {
 			br.ErrMsg = "获取数据失败,品种id:" + strconv.Itoa(chartPermissionId)
 			return
 		}
+
+		classifyIds = utils.Unique(classifyIds)
 		// 根据分类筛选报告
 		var selectedClassifyId []int
 		if classifyId > 0 {
 			for _, v := range classifyIds {
-				if v == classifyId {
+				if _, ok := classifyIdMap[v]; ok {
 					selectedClassifyId = append(selectedClassifyId, v)
-					break
 				}
 			}
 		} else {
 			selectedClassifyId = classifyIds
 		}
-		tmptotal, err := models.GetReportCountByClassifyIds(selectedClassifyId, condition)
+
+		classifyList, err := models.GetClassifyListByIds(selectedClassifyId)
+		if err != nil {
+			br.Msg = "获取报告列表失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range classifyList {
+			switch v.Level {
+			case 1:
+				classifyFirstIds = append(classifyFirstIds, v.Id)
+			case 2:
+				classifySecondIds = append(classifySecondIds, v.Id)
+			case 3:
+				classifyThirdIds = append(classifyThirdIds, v.Id)
+			}
+		}
+		tmptotal, err := models.GetReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
 		if err != nil {
 			br.Msg = "获取数据失败"
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
 			return
 		}
 		total = tmptotal
-		tmpReportList, err := models.GetReportListByClassifyIds(selectedClassifyId, condition, startSize, pageSize)
+		tmpReportList, err := models.GetReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition, startSize, pageSize)
 		if err != nil {
 			br.Msg = "获取报告列表失败"
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
@@ -126,26 +169,43 @@ func (this *ReportController) List() {
 			br.Msg = "该品种下没有绑定分类"
 			return
 		}
+		classifyIds = utils.Unique(classifyIds)
 		// 根据分类筛选报告
 		var selectedClassifyId []int
 		if classifyId > 0 {
 			for _, v := range classifyIds {
-				if v == classifyId {
+				if _, ok := classifyIdMap[v]; ok {
 					selectedClassifyId = append(selectedClassifyId, v)
-					break
 				}
 			}
 		} else {
 			selectedClassifyId = classifyIds
 		}
-		tmptotal, err := models.GetReportCountByClassifyIds(selectedClassifyId, condition)
+
+		classifyList, err := models.GetClassifyListByIds(selectedClassifyId)
+		if err != nil {
+			br.Msg = "获取报告列表失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range classifyList {
+			switch v.Level {
+			case 1:
+				classifyFirstIds = append(classifyFirstIds, v.Id)
+			case 2:
+				classifySecondIds = append(classifySecondIds, v.Id)
+			case 3:
+				classifyThirdIds = append(classifyThirdIds, v.Id)
+			}
+		}
+		tmptotal, err := models.GetReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition)
 		if err != nil {
 			br.Msg = "获取数据失败"
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
 			return
 		}
 		total = tmptotal
-		tmpReportList, err := models.GetReportListByClassifyIds(selectedClassifyId, condition, startSize, pageSize)
+		tmpReportList, err := models.GetReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds, condition, startSize, pageSize)
 		if err != nil {
 			br.Msg = "获取报告列表失败"
 			br.ErrMsg = "获取报告列表失败,Err:" + err.Error()
@@ -168,6 +228,25 @@ func (this *ReportController) List() {
 	br.Data = resp
 }
 
+func getLeafClassifyIds(classifyMap map[int]*models.ClassifyView, keyId int) []int {
+	var leafClassifyIds []int
+	curClassify := classifyMap[keyId]
+	if curClassify.HasChild == 0 {
+		leafClassifyIds = append(leafClassifyIds, curClassify.Id)
+		return leafClassifyIds
+	}
+	for _, v := range classifyMap {
+		if v.ParentId == curClassify.Id {
+			if v.HasChild == 0 {
+				leafClassifyIds = append(leafClassifyIds, v.Id)
+			} else {
+				leafClassifyIds = append(leafClassifyIds, getLeafClassifyIds(classifyMap, v.Id)...)
+			}
+		}
+	}
+	return leafClassifyIds
+}
+
 // @Title 研报详情
 // @Description 研报详情接口
 // @Param   ReportId   query   int  true       "报告id"
@@ -238,10 +317,10 @@ func (this *ReportController) Detail() {
 			utils.FileLog.Warn("版尾数据获取失败,Err:" + err.Error())
 		}
 		if headImg != nil {
-			report.HeadResourceUrl = headImg.ImgUrl
+			report.HeadResource = headImg
 		}
 		if endImg != nil {
-			report.EndResourceUrl = endImg.ImgUrl
+			report.EndResource = endImg
 		}
 	}
 

+ 8 - 0
models/classify.go

@@ -25,6 +25,7 @@ type ClassifyView struct {
 	CreateTime   time.Time       `description:"创建时间"`
 	ModifyTime   time.Time       `description:"修改时间"`
 	Level        int             `description:"分类层级"`
+	HasChild     int             `description:"是否有子分类0:下面没有子分类,1:下面有子分类"`
 	Child        []*ClassifyView `description:"子分类"`
 }
 
@@ -63,3 +64,10 @@ func GetClassifyById(id int) (item *ClassifyView, err error) {
 	err = o.Raw(sql, id).QueryRow(&item)
 	return
 }
+
+func GetClassifyList() (items []*ClassifyView, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM classify`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 73 - 42
models/report.go

@@ -91,7 +91,30 @@ func GetReportRecentList(startSize, pageSize int) (items []*ReportList, err erro
 	return
 }
 
-func GetReportCountByClassifyIds(classifyIds []int, condition string) (count int, err error) {
+func GetReportCountByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string) (count int, err error) {
+	if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT  COUNT(*) AS count  FROM report AS a WHERE (a.state=2 OR a.state=6)  `
+
+	if len(classifyFirstIds) > 0 {
+		sql += fmt.Sprintf(" OR a.classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
+	}
+	if len(classifySecondIds) > 0 {
+		sql += fmt.Sprintf(" OR a.classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
+	}
+	if len(classifyThirdIds) > 0 {
+		sql += fmt.Sprintf(" OR a.classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
+	}
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, classifyFirstIds, classifySecondIds, classifyThirdIds).QueryRow(&count)
+	return
+}
+
+func GetReportByClassifyIds(classifyIds []int, condition string) (count int, err error) {
 	if len(classifyIds) == 0 {
 		return
 	}
@@ -106,8 +129,8 @@ func GetReportCountByClassifyIds(classifyIds []int, condition string) (count int
 	return
 }
 
-func GetReportListByClassifyIds(classifyIds []int, condition string, startSize, pageSize int) (items []*ReportList, err error) {
-	if len(classifyIds) == 0 {
+func GetReportListByClassifyIds(classifyFirstIds, classifySecondIds, classifyThirdIds []int, condition string, startSize, pageSize int) (items []*ReportList, err error) {
+	if len(classifyFirstIds) == 0 && len(classifySecondIds) == 0 && len(classifyThirdIds) == 0 {
 		return
 	}
 	o := orm.NewOrmUsingDB("rddp")
@@ -117,53 +140,61 @@ func GetReportListByClassifyIds(classifyIds []int, condition string, startSize,
             CASE WHEN DATE(a.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
             FROM report AS a
 			INNER JOIN  classify AS b ON a.classify_id_second=b.id
-			WHERE (a.state=2 OR a.state=6) AND a.classify_id_second IN (%s) `
-
-	sql = fmt.Sprintf(sql, utils.GetOrmReplaceHolder(len(classifyIds)))
+			WHERE (a.state=2 OR a.state=6) `
+	// AND (a.classify_id_first IN (%s) OR a.classify_id_second IN (%s) OR a.classify_id_third IN (%s)) `
+	if len(classifyFirstIds) > 0 {
+		sql += fmt.Sprintf(" OR a.classify_id_first IN (%s) ", utils.GetOrmReplaceHolder(len(classifyFirstIds)))
+	}
+	if len(classifySecondIds) > 0 {
+		sql += fmt.Sprintf(" OR a.classify_id_second IN (%s) ", utils.GetOrmReplaceHolder(len(classifySecondIds)))
+	}
+	if len(classifyThirdIds) > 0 {
+		sql += fmt.Sprintf(" OR a.classify_id_third IN (%s) ", utils.GetOrmReplaceHolder(len(classifyThirdIds)))
+	}
 	if condition != "" {
 		sql += condition
 	}
 	sql += ` ORDER BY  a.publish_time DESC LIMIT ?,? `
-	_, err = o.Raw(sql, classifyIds, startSize, pageSize).QueryRows(&items)
+	_, err = o.Raw(sql, classifyFirstIds, classifySecondIds, classifyThirdIds, startSize, pageSize).QueryRows(&items)
 	return
 }
 
 type ReportDetail 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         string           `description:"修改时间"`
-	State              int              `description:"1:未发布,2:已发布"`
-	PublishTime        string           `description:"发布时间"`
-	Stage              int              `description:"期数"`
-	MsgIsSend          int              `description:"消息是否已发送,0:否,1:是"`
-	Content            string           `description:"内容"`
-	ChapterContent     []*ReportChapter `description:"章节内容"`
-	VideoUrl           string           `description:"音频文件URL"`
-	VideoName          string           `description:"音频文件名称"`
-	VideoPlaySeconds   string           `description:"音频播放时长"`
-	VideoSize          string           `description:"音频文件大小,单位M"`
-	ContentSub         string           `description:"内容前两个章节"`
-	IsShowNewLabel     int              `description:"是否显示新标签"`
-	IsCurrentDate      int              `description:"是否当前日期"`
-	ClassifyName       string           `description:"分类名称"`
-	TitleType          string           `description:"标题类型,FICC或者权益"`
-	IsPublic           bool             `description:"是否是公共报告 "`
-	HeadResourceId     int              `description:"版头资源库id"`
-	EndResourceId      int              `description:"版尾资源库id"`
-	HeadResourceUrl    string           `description:"版头资源库Url"`
-	EndResourceUrl     string           `description:"版尾资源库Url"`
-	CollaborateType    int              `description:"合作类型, 1:个人,2:多人协作"`
-	ReportLayout       int              `description:"报告布局, 1:常规布局,2:智能布局"`
-	HasChapter         int              `description:"是否有章节: 0-否 1-是"`
+	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         string               `description:"修改时间"`
+	State              int                  `description:"1:未发布,2:已发布"`
+	PublishTime        string               `description:"发布时间"`
+	Stage              int                  `description:"期数"`
+	MsgIsSend          int                  `description:"消息是否已发送,0:否,1:是"`
+	Content            string               `description:"内容"`
+	ChapterContent     []*ReportChapter     `description:"章节内容"`
+	VideoUrl           string               `description:"音频文件URL"`
+	VideoName          string               `description:"音频文件名称"`
+	VideoPlaySeconds   string               `description:"音频播放时长"`
+	VideoSize          string               `description:"音频文件大小,单位M"`
+	ContentSub         string               `description:"内容前两个章节"`
+	IsShowNewLabel     int                  `description:"是否显示新标签"`
+	IsCurrentDate      int                  `description:"是否当前日期"`
+	ClassifyName       string               `description:"分类名称"`
+	TitleType          string               `description:"标题类型,FICC或者权益"`
+	IsPublic           bool                 `description:"是否是公共报告 "`
+	HeadResourceId     int                  `description:"版头资源库id"`
+	EndResourceId      int                  `description:"版尾资源库id"`
+	HeadResource       *SmartReportResource `description:"版头资源库"`
+	EndResource        *SmartReportResource `description:"版尾资源库"`
+	CollaborateType    int                  `description:"合作类型, 1:个人,2:多人协作"`
+	ReportLayout       int                  `description:"报告布局, 1:常规布局,2:智能布局"`
+	HasChapter         int                  `description:"是否有章节: 0-否 1-是"`
 }
 
 type ReportChapter struct {

+ 9 - 0
routers/commentsRouter.go

@@ -115,6 +115,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_bridge/controllers:ClassifyController"] = append(beego.GlobalControllerRouter["eta/eta_mini_bridge/controllers:ClassifyController"],
+        beego.ControllerComments{
+            Method: "AllClassify",
+            Router: `/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_bridge/controllers:ReportController"] = append(beego.GlobalControllerRouter["eta/eta_mini_bridge/controllers:ReportController"],
         beego.ControllerComments{
             Method: "Today",