package models import ( "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" "time" ) type CygxArticleDepartment struct { DepartmentId int `orm:"column(department_id);pk;主键ID"` CreateTime time.Time `description:"创建时间"` NickName string `description:"昵称"` Remark string `description:"备注"` Remarks string `description:"备注辅助字段"` Content string `description:"初始内容"` } type DepartmentResp struct { DepartmentId int `description:"作者ID"` CreateTime string `description:"创建时间"` PublishDate string `description:"更新时间"` NickName string `description:"昵称"` ImgUrl string `description:"头像链接"` IsFollow bool `description:"是否关注"` IsHot bool `description:"是否标红"` FllowNum int `description:"关注数量"` List []*IndustrialDepartmentListResp } type DepartmentListResp struct { Paging *paging.PagingItem `description:"分页数据"` List []*DepartmentResp } type CygxArticleDepartmentId struct { DepartmentId int `description:"作者ID"` } // 获取作者数量 func GetDepartmentCount(departmentId int) (count int, err error) { sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article_department WHERE department_id=? ` o := orm.NewOrm() err = o.Raw(sqlCount, departmentId).QueryRow(&count) return } func GetArticleDepartmentDateilById(departmentId int) (item *DepartmentResp, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_article_department WHERE department_id = ? ` err = o.Raw(sql, departmentId).QueryRow(&item) return } // 数量 func GetArticleDepartmentCount(condition string) (count int, err error) { o := orm.NewOrm() sql := ` SELECT COUNT(*) count FROM ( SELECT COUNT(1) FROM cygx_article_department AS d INNER JOIN cygx_article AS a ON a.department_id = d.department_id INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id WHERE 1= 1 ` if condition != "" { sql += condition } sql += ` GROUP BY d.department_id ) AS num ` err = o.Raw(sql).QueryRow(&count) return } type IndustrialSubjectList struct { SubjectName string `description:"标的名称"` } // 作者列表 func GetDepartmentList(condition, conditionOrder string, userId, startSize, pageSize int) (items []*DepartmentResp, err error) { o := orm.NewOrm() sql := `SELECT d.nick_name, d.department_id, d.img_url, MAX( a.publish_date ) AS publish_date, ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND user_id =? AND f.type= 1 ) AS fllow_num, ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.type= 1 ) +( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id IN (SELECT article_id FROM cygx_article WHERE department_id = d.department_id ) AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time ) ) AS sum_num FROM cygx_article_department AS d INNER JOIN cygx_article AS a ON d.department_id = a.department_id WHERE 1 = 1 AND a.article_type_id > 0 AND publish_status = 1 ` + condition + ` GROUP BY d.department_id ` + conditionOrder + ` , last_updated_time DESC LIMIT ?,?` _, err = o.Raw(sql, userId, startSize, pageSize).QueryRows(&items) return } // 用户收藏榜start type DepartmentDetailResp struct { DepartmentId int `description:"作者Id"` NickName string `description:"作者昵称"` ImgUrl string `description:"图片链接"` FllowNum int `description:"多少人关注"` ArticleNum int `description:"文章数量"` CollectNum int `description:"收藏人数"` IsFollow bool `description:"是否关注"` List []*ArticleResearchResp ListIndustrial []*IndustrialManagementNewResp Paging *paging.PagingItem } type IndustrialManagementNewResp struct { IndustrialManagementId int `description:"产业Id"` IndustryName string `description:"产业名称"` IsHot bool `description:"是否是热门"` ArticleReadNum int `description:"文章阅读数量"` } type DepartmentDetail struct { DepartmentId int `description:"作者Id"` NickName string `description:"作者昵称"` ImgUrl string `description:"图片链接"` FllowNum int `description:"多少人关注"` ArticleNum int `description:"文章数量"` CollectNum int `description:"收藏人数"` IsFollow bool `description:"是否关注"` MyFllowNum int `description:"本人是否关注"` } // 作者详情 func GetDepartmentDetail(userId, departmentId int, condition string) (item DepartmentDetail, err error) { o := orm.NewOrm() sql := `SELECT d.department_id, d.nick_name, d.img_url, ( SELECT count( 1 ) FROM cygx_article_department_follow AS af WHERE af.user_id = ? AND af.department_id = d.department_id AND af.type= 1 ) AS my_fllow_num, ( SELECT count( 1 ) FROM cygx_article_department_follow AS f WHERE f.department_id = d.department_id AND f.type= 1 ) AS fllow_num, ( SELECT count( 1 ) FROM cygx_article AS a WHERE a.department_id = d.department_id ` + condition + ` ) AS article_num, ( SELECT count( 1 ) FROM cygx_article_collect AS c WHERE c.article_id IN (SELECT article_id FROM cygx_article AS a WHERE a.department_id = d.department_id ` + condition + ` )) AS collect_num FROM cygx_article_department AS d WHERE d.department_id = ?` err = o.Raw(sql, userId, departmentId).QueryRow(&item) return } //end