Compare commits
10 Commits
e83b15b03a
...
e92db9953e
| Author | SHA1 | Date | |
|---|---|---|---|
| e92db9953e | |||
| 3ca2e9e25f | |||
| b9b45b1789 | |||
| 311cda51b2 | |||
| d0ff21969e | |||
| 946edc6949 | |||
| bbfbccc406 | |||
| 0ecb3bf3d4 | |||
| a12f422136 | |||
| 3ac92da2db |
@ -109,18 +109,33 @@ func (r *Article) GetArticle(c *gin.Context) {
|
||||
|
||||
article.ArticleAuthor = articleAuthors
|
||||
|
||||
// 获取排名
|
||||
rank, _ := articleDao.GetArticleRank(article.ArticleId)
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetArticleDto(article)
|
||||
|
||||
// 获取排名开关限制
|
||||
systemConfigDao := dao.SystemConfigDao{}
|
||||
systemConfig, err := systemConfigDao.GetSystemConfigById(1)
|
||||
if err != nil {
|
||||
responses.OkWithData(nil, c)
|
||||
return
|
||||
}
|
||||
|
||||
if systemConfig.IsDisplayRank == 1 {
|
||||
// 获取大于某一投票数的文章
|
||||
maps := make(map[string]interface{})
|
||||
maps["article_status"] = 1
|
||||
articles, err := articleDao.GetArticleListGtVoteNum(maps, article.VoteNum)
|
||||
if err == nil {
|
||||
rank := len(articles) + 1
|
||||
|
||||
// 加载数据-作者排名
|
||||
g.LoadRank(rank)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载数据-作者
|
||||
g.LoadArticleAuthor(article.ArticleAuthor)
|
||||
|
||||
// 加载数据-作者排名
|
||||
g.LoadRank(rank)
|
||||
|
||||
// 检测用户今日是否投票
|
||||
userId := c.GetInt64("UserId")
|
||||
if userId != 0 {
|
||||
|
||||
@ -109,18 +109,33 @@ func (r *Video) GetVideo(c *gin.Context) {
|
||||
|
||||
video.VideoAuthor = videoAuthors
|
||||
|
||||
// 获取排名
|
||||
rank, _ := videoDao.GetVideoRank(video.VideoId)
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetVideoDto(video)
|
||||
|
||||
// 获取排名开关限制
|
||||
systemConfigDao := dao.SystemConfigDao{}
|
||||
systemConfig, err := systemConfigDao.GetSystemConfigById(1)
|
||||
if err != nil {
|
||||
responses.OkWithData(nil, c)
|
||||
return
|
||||
}
|
||||
|
||||
if systemConfig.IsDisplayRank == 1 {
|
||||
// 获取大于某一投票数的文章
|
||||
maps := make(map[string]interface{})
|
||||
maps["video_status"] = 1
|
||||
videos, err := videoDao.GetVideoListGtVoteNum(maps, video.VoteNum)
|
||||
if err == nil {
|
||||
rank := len(videos) + 1
|
||||
|
||||
// 加载数据-作者排名
|
||||
g.LoadRank(rank)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载数据-作者
|
||||
g.LoadVideoAuthor(video.VideoAuthor)
|
||||
|
||||
// 加载数据-作者排名
|
||||
g.LoadRank(rank)
|
||||
|
||||
// 检测用户今日是否投票
|
||||
userId := c.GetInt64("UserId")
|
||||
if userId != 0 {
|
||||
@ -159,24 +174,28 @@ func (r *Video) GetVideoRankList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var videoIds []int64
|
||||
|
||||
for _, video := range videos {
|
||||
videoIds = append(videoIds, video.VideoId)
|
||||
}
|
||||
|
||||
// 处理数据
|
||||
for i, video := range videos {
|
||||
videoIds = append(videoIds, video.VideoId)
|
||||
|
||||
// 判断最后两位票数是否相同
|
||||
if i == 14 {
|
||||
maps = make(map[string]interface{})
|
||||
maps["article_status"] = 1
|
||||
maps["video_status"] = 1
|
||||
maps["vote_num"] = video.VoteNum
|
||||
results, err := videoDao.GetVideoList(maps)
|
||||
results, err := videoDao.GetVideoListNotIn(maps, videoIds)
|
||||
if err != nil {
|
||||
responses.OkWithData(nil, c)
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
if result.VideoId == video.VideoId {
|
||||
continue
|
||||
}
|
||||
|
||||
videos = append(videos, result)
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,6 +210,15 @@ func (r *ArticleDao) GetArticleRankList(maps interface{}, orderField string, lim
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleListGtVoteNum 获取大于某一投票数的文章列表
|
||||
func (r *ArticleDao) GetArticleListGtVoteNum(maps interface{}, voteNum uint) (m []*model.Article, err error) {
|
||||
err = global.Db.Where(maps).Where("vote_num > ?", voteNum).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleRank 获取某一条数据的排名
|
||||
func (r *ArticleDao) GetArticleRank(articleID int64) (int, error) {
|
||||
var rank int
|
||||
|
||||
@ -73,6 +73,19 @@ func (r *VideoDao) GetVideoList(maps interface{}) (m []*model.Video, err error)
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoListNotIn 获取列表
|
||||
func (r *VideoDao) GetVideoListNotIn(maps interface{}, ids []int64) (m []*model.Video, err error) {
|
||||
err = global.Db.Where(maps).
|
||||
Preload("VideoAuthor").
|
||||
Preload("VideoAuthor.BaseHospital").
|
||||
Where("video_id NOT IN ?", ids).
|
||||
Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoCount 获取数量
|
||||
func (r *VideoDao) GetVideoCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.Video{}).Where(maps).Count(&total).Error
|
||||
@ -210,6 +223,15 @@ func (r *VideoDao) GetVideoRankList(maps interface{}, orderField string, limit i
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoListGtVoteNum 获取大于某一投票数的视频列表
|
||||
func (r *VideoDao) GetVideoListGtVoteNum(maps interface{}, voteNum uint) (m []*model.Video, err error) {
|
||||
err = global.Db.Where(maps).Where("vote_num > ?", voteNum).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoRank 获取某一条数据的排名
|
||||
func (r *VideoDao) GetVideoRank(videoID int64) (int, error) {
|
||||
var rank int
|
||||
|
||||
@ -38,6 +38,10 @@ func (r *SystemTimeService) CheckVoteValidStatus() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if duration > 5*time.Minute {
|
||||
duration = 5 * time.Minute
|
||||
}
|
||||
|
||||
// 添加缓存
|
||||
_, err = global.Redis.Set(context.Background(), redisKey, "1", duration).Result()
|
||||
if err != nil {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
port: 8500 # 启动端口
|
||||
port: 8501 # 启动端口
|
||||
|
||||
env: dev # 环境配置
|
||||
|
||||
@ -25,7 +25,7 @@ redis:
|
||||
port: 30002
|
||||
password: gdxz2022&dj.
|
||||
pool-size: 100
|
||||
db: 4
|
||||
db: 5
|
||||
|
||||
# [jwt]
|
||||
jwt:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user