后台新增视频编号
This commit is contained in:
parent
89cf811898
commit
611dffa4e0
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user