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