From 611dffa4e09eac0d2c54c96b2c1ec10229171677 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Wed, 11 Sep 2024 10:00:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=96=B0=E5=A2=9E=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E7=BC=96=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/Article.go | 16 ++++++++++++++-- api/controller/Video.go | 16 ++++++++++++++-- api/dto/Article.go | 3 +++ api/dto/Video.go | 3 +++ api/model/Article.go | 1 + api/model/Video.go | 1 + 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/api/controller/Article.go b/api/controller/Article.go index 9f7aa16..a0c3c4c 100644 --- a/api/controller/Article.go +++ b/api/controller/Article.go @@ -290,6 +290,8 @@ func (r *Article) AddArticle(c *gin.Context) { } }() + articleDao := dao.ArticleDao{} + article := &model.Article{ ArticleTitle: req.ArticleTitle, ArticleStatus: req.ArticleStatus, @@ -300,8 +302,18 @@ func (r *Article) AddArticle(c *gin.Context) { article.VoteNum = *req.VoteNum } - articleDao := dao.ArticleDao{} - article, err := articleDao.AddArticle(tx, article) + // 生成文章编号 + maps := make(map[string]interface{}) + total, err := articleDao.GetArticleCount(maps) + if err != nil { + tx.Rollback() + responses.FailWithMessage(err.Error(), c) + return + } + + article.ArticleNumber = fmt.Sprintf("%d", 1000+total) + + article, err = articleDao.AddArticle(tx, article) if err != nil { tx.Rollback() responses.FailWithMessage(err.Error(), c) diff --git a/api/controller/Video.go b/api/controller/Video.go index 07ba5c0..6ba6b37 100644 --- a/api/controller/Video.go +++ b/api/controller/Video.go @@ -294,6 +294,8 @@ func (r *Video) AddVideo(c *gin.Context) { } }() + videoDao := dao.VideoDao{} + video := &model.Video{ VideoTitle: req.VideoTitle, VideoStatus: req.VideoStatus, @@ -305,8 +307,18 @@ func (r *Video) AddVideo(c *gin.Context) { video.VoteNum = *req.VoteNum } - videoDao := dao.VideoDao{} - video, err := videoDao.AddVideo(tx, video) + // 生成视频编号 + maps := make(map[string]interface{}) + total, err := videoDao.GetVideoCount(maps) + if err != nil { + tx.Rollback() + responses.FailWithMessage(err.Error(), c) + return + } + + video.VideoNumber = fmt.Sprintf("%d", 1000+total) + + video, err = videoDao.AddVideo(tx, video) if err != nil { tx.Rollback() responses.FailWithMessage(err.Error(), c) diff --git a/api/dto/Article.go b/api/dto/Article.go index 1e35605..efd4e0c 100644 --- a/api/dto/Article.go +++ b/api/dto/Article.go @@ -10,6 +10,7 @@ type ArticleDto struct { ArticleId string `json:"article_id"` // 主键id ArticleTitle string `json:"article_title"` // 文章标题 ArticleStatus int `json:"article_status"` // 文章状态(1:正常 2:禁用) + ArticleNumber string `json:"article_number"` // 文章编号 VoteNum uint `json:"vote_num"` // 总票数 ArticleContent string `json:"article_content"` // 文章内容 CreatedAt model.LocalTime `json:"created_at"` // 创建时间 @@ -29,6 +30,7 @@ func GetArticleListDto(m []*model.Article) []*ArticleDto { ArticleId: fmt.Sprintf("%d", v.ArticleId), ArticleTitle: v.ArticleTitle, ArticleStatus: v.ArticleStatus, + ArticleNumber: v.ArticleNumber, VoteNum: v.VoteNum, ArticleContent: v.ArticleContent, CreatedAt: v.CreatedAt, @@ -54,6 +56,7 @@ func GetArticleDto(m *model.Article) *ArticleDto { ArticleId: fmt.Sprintf("%d", m.ArticleId), ArticleTitle: m.ArticleTitle, ArticleStatus: m.ArticleStatus, + ArticleNumber: m.ArticleNumber, VoteNum: m.VoteNum, ArticleContent: m.ArticleContent, CreatedAt: m.CreatedAt, diff --git a/api/dto/Video.go b/api/dto/Video.go index e36300f..b971a08 100644 --- a/api/dto/Video.go +++ b/api/dto/Video.go @@ -10,6 +10,7 @@ type VideoDto struct { VideoId string `json:"video_id"` // 主键id VideoTitle string `json:"video_title"` // 视频标题 VideoStatus int `json:"video_status"` // 视频状态(1:正常 2:禁用) + VideoNumber string `json:"video_number"` // 视频编号 VideoNo string `json:"video_no"` // 视频编号 VoteNum uint `json:"vote_num"` // 总票数 VideoContent string `json:"video_content"` // 视频内容 @@ -30,6 +31,7 @@ func GetVideoListDto(m []*model.Video) []*VideoDto { VideoId: fmt.Sprintf("%d", v.VideoId), VideoTitle: v.VideoTitle, VideoStatus: v.VideoStatus, + VideoNumber: v.VideoNumber, VideoNo: v.VideoNo, VoteNum: v.VoteNum, VideoContent: v.VideoContent, @@ -56,6 +58,7 @@ func GetVideoDto(m *model.Video) *VideoDto { VideoId: fmt.Sprintf("%d", m.VideoId), VideoTitle: m.VideoTitle, VideoStatus: m.VideoStatus, + VideoNumber: m.VideoNumber, VideoNo: m.VideoNo, VoteNum: m.VoteNum, VideoContent: m.VideoContent, diff --git a/api/model/Article.go b/api/model/Article.go index c1b6bb5..c0f64a3 100644 --- a/api/model/Article.go +++ b/api/model/Article.go @@ -11,6 +11,7 @@ type Article struct { ArticleId int64 `gorm:"column:article_id;type:bigint(19);primary_key;comment:主键id" json:"article_id"` ArticleTitle string `gorm:"column:article_title;type:varchar(200);comment:文章标题" json:"article_title"` ArticleStatus int `gorm:"column:article_status;type:tinyint(1);default:1;comment:文章状态(1:正常 2:禁用)" json:"article_status"` + ArticleNumber string `gorm:"column:article_number;type:varchar(10);comment:文章编号;NOT NULL" json:"article_number"` VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:总票数" json:"vote_num"` ArticleContent string `gorm:"column:article_content;type:text;comment:文章内容" json:"article_content"` Model diff --git a/api/model/Video.go b/api/model/Video.go index d9bff48..5e5a493 100644 --- a/api/model/Video.go +++ b/api/model/Video.go @@ -11,6 +11,7 @@ type Video struct { VideoId int64 `gorm:"column:video_id;type:bigint(19);primary_key;comment:主键id" json:"video_id"` VideoTitle string `gorm:"column:video_title;type:varchar(200);comment:视频标题" json:"video_title"` VideoStatus int `gorm:"column:video_status;type:tinyint(1);default:1;comment:视频状态(1:正常 2:禁用)" json:"video_status"` + VideoNumber string `gorm:"column:video_number;type:varchar(10);comment:视频编号;NOT NULL" json:"video_number"` VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:总票数" json:"vote_num"` VideoNo string `gorm:"column:video_no;type:varchar(255);comment:视频编号(保利)" json:"video_no"` VideoContent string `gorm:"column:video_content;type:text;comment:视频内容" json:"video_content"`