123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- package models
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_api/utils"
- )
- type HomeList struct {
- ClassifyId int `orm:"column(id)"`
- ClassifyName string `description:"分类名称"`
- Child []*HomeClassifyItem
- }
- type HomeClassifyItem struct {
- ClassifyId int `orm:"column(id)"`
- ClassifyName string `description:"分类名称"`
- TitleType string `description:"标题类型,FICC或者权益"`
- Child *Report
- }
- func ListHome(userId, maxPermission, userPermission int, permissionStr string) (homeList []*HomeList, err error) {
- o := orm.NewOrmUsingDB("rddp")
- //sql := `SELECT id,classify_name FROM classify WHERE parent_id=0 ORDER BY create_time ASC `
- //暂时将双周报、月报隐藏
- items := make([]*HomeList, 0)
- sql := `SELECT id,classify_name FROM classify WHERE parent_id=0 and classify_name not IN("双周报","月报","晨报","周报","草根调研","需求报告","会议纪要","大事点评","年报合集") ORDER BY create_time ASC `
- _, err = o.Raw(sql).QueryRows(&items)
- if err != nil {
- fmt.Println("Get classify Err:" + err.Error())
- return
- }
- lenItem := len(items)
- fmt.Println("lenItem:", lenItem)
- for i := 0; i < lenItem; i++ {
- item := items[i]
- subItems := make([]*HomeClassifyItem, 0)
- subWhere := ``
- if maxPermission < 15 && userPermission == 0 {
- if permissionStr != "" {
- subWhere = ` WHERE parent_id=? AND classify_name IN(` + permissionStr + `) `
- } else {
- subWhere = ` WHERE parent_id=? `
- }
- } else {
- subWhere = ` WHERE parent_id=? `
- }
- subSql := `SELECT id ,classify_name FROM classify `
- subSql += subWhere
- subSql += ` and classify_name not IN("宏观点评")`
- subSql += ` ORDER BY sort 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.*,
- (SELECT COUNT(1) FROM report_view_log AS c WHERE c.user_id=? AND c.report_id=b.id ) AS is_show_new_label,
- 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
- WHERE b.state=2 AND a.id=?
- ORDER BY b.publish_time DESC LIMIT 1 `
- report := new(Report)
- err = o.Raw(reportSql, userId, subItem.ClassifyId).QueryRow(&report)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- return
- } else {
- err = nil
- }
- }
- subItems[k].Child = report
- }
- items[i].Child = subItems
- if lenSub > 0 {
- homeList = append(homeList, items[i])
- }
- }
- return
- }
- type PcHomeClassifyItem struct {
- ClassifyId int
- ClassifyName string `description:"分类名称"`
- Abstract string `description:"栏目简介"`
- Descript string `description:"分享描述"`
- ReportAuthor string `description:"栏目作者"`
- AuthorDescript string `description:"作者简介"`
- ColumnImgUrl string `description:"栏目配图"`
- HeadImgUrl string `description:"头部banner"`
- AvatarImgUrl string `description:"头像"`
- ReportImgUrl string `description:"报告配图"`
- HomeImgUrl string `description:"首页配图"`
- PcReport
- }
- func PcListHomeCount(classifyId int, endDate string) (count int, err error) {
- o := orm.NewOrmUsingDB("rddp")
- sql := `SELECT COUNT(1) AS count
- FROM classify AS a
- INNER JOIN report AS b ON a.id=b.classify_id_second
- WHERE b.state=2 AND b.classify_id_first=? AND b.publish_time>=?`
- err = o.Raw(sql, classifyId, endDate).QueryRow(&count)
- return
- }
- func PcListHome(classifyId, uid, startSize, pageSize int, endDate string) (items []*PcHomeClassifyItem, err error) {
- o := orm.NewOrmUsingDB("rddp")
- if uid > 0 {
- reportSql := ` SELECT a.id AS classify_id,a.head_img_url,a.avatar_img_url,a.column_img_url,a.report_img_url,a.home_img_url,b.*,
- (SELECT COUNT(1) FROM report_view_log AS c WHERE c.user_id=? AND c.report_id=b.id ) AS is_show_new_label,
- 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
- WHERE b.state=2 AND b.classify_id_first=? AND b.publish_time>=?
- ORDER BY b.publish_time DESC LIMIT ?,? `
- _, err = o.Raw(reportSql, uid, classifyId, endDate, startSize, pageSize).QueryRows(&items)
- } else {
- reportSql := ` SELECT a.id AS classify_id,a.head_img_url,a.avatar_img_url,a.column_img_url,a.report_img_url,a.home_img_url,b.*,
- 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
- WHERE b.state=2 AND b.classify_id_first=? AND b.publish_time>=?
- ORDER BY b.publish_time DESC LIMIT ?,? `
- _, err = o.Raw(reportSql, classifyId, endDate, startSize, pageSize).QueryRows(&items)
- }
- return
- }
- type PcListHomeResp struct {
- Paging *paging.PagingItem
- List []*PcHomeClassifyItem
- }
|