Compare commits
No commits in common. "e92db9953e055258898c62110c8d122533fb48ee" and "e83b15b03a4cd915c22ad4ca510aa10dbe2acb70" have entirely different histories.
e92db9953e
...
e83b15b03a
@ -109,32 +109,17 @@ 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.LoadArticleAuthor(article.ArticleAuthor)
|
||||
|
||||
// 加载数据-作者排名
|
||||
g.LoadRank(rank)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载数据-作者
|
||||
g.LoadArticleAuthor(article.ArticleAuthor)
|
||||
|
||||
// 检测用户今日是否投票
|
||||
userId := c.GetInt64("UserId")
|
||||
|
||||
@ -109,32 +109,17 @@ 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.LoadVideoAuthor(video.VideoAuthor)
|
||||
|
||||
// 加载数据-作者排名
|
||||
g.LoadRank(rank)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载数据-作者
|
||||
g.LoadVideoAuthor(video.VideoAuthor)
|
||||
|
||||
// 检测用户今日是否投票
|
||||
userId := c.GetInt64("UserId")
|
||||
@ -174,28 +159,24 @@ 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["video_status"] = 1
|
||||
maps["article_status"] = 1
|
||||
maps["vote_num"] = video.VoteNum
|
||||
results, err := videoDao.GetVideoListNotIn(maps, videoIds)
|
||||
results, err := videoDao.GetVideoList(maps)
|
||||
if err != nil {
|
||||
responses.OkWithData(nil, c)
|
||||
return
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
if result.VideoId == video.VideoId {
|
||||
continue
|
||||
}
|
||||
|
||||
videos = append(videos, result)
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,15 +210,6 @@ 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,19 +73,6 @@ 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
|
||||
@ -223,15 +210,6 @@ 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,10 +38,6 @@ 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: 8501 # 启动端口
|
||||
port: 8500 # 启动端口
|
||||
|
||||
env: dev # 环境配置
|
||||
|
||||
@ -25,7 +25,7 @@ redis:
|
||||
port: 30002
|
||||
password: gdxz2022&dj.
|
||||
pool-size: 100
|
||||
db: 5
|
||||
db: 4
|
||||
|
||||
# [jwt]
|
||||
jwt:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user