书籍模块
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/book"
|
||||
bookReq "github.com/flipped-aurora/gin-vue-admin/server/model/book/request"
|
||||
bookRes "github.com/flipped-aurora/gin-vue-admin/server/model/book/response"
|
||||
commonReq "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
||||
)
|
||||
|
||||
@@ -37,18 +38,22 @@ func (s *BookAuthorRelationService) GetBookAuthorRelation(id uint) (item book.Bo
|
||||
return
|
||||
}
|
||||
|
||||
func (s *BookAuthorRelationService) GetBookAuthorRelationInfoList(info bookReq.BookAuthorRelationSearch) (list []book.BookAuthorRelation, total int64, err error) {
|
||||
db := global.GVA_DB.Model(&book.BookAuthorRelation{})
|
||||
func (s *BookAuthorRelationService) GetBookAuthorRelationInfoList(info bookReq.BookAuthorRelationSearch) (list []bookRes.BookAuthorRelationListItem, total int64, err error) {
|
||||
db := global.GVA_DB.Table("book_author_relation AS bar")
|
||||
if info.BookID != nil {
|
||||
db = db.Where("book_id = ?", *info.BookID)
|
||||
db = db.Where("bar.book_id = ?", *info.BookID)
|
||||
}
|
||||
if info.AuthorID != nil {
|
||||
db = db.Where("author_id = ?", *info.AuthorID)
|
||||
db = db.Where("bar.author_id = ?", *info.AuthorID)
|
||||
}
|
||||
err = db.Count(&total).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = db.Scopes(paginate(info.PageInfo)).Order("book_id asc, author_sort asc, id desc").Find(&list).Error
|
||||
err = db.Select("bar.*, ba.name AS author_name").
|
||||
Joins("LEFT JOIN book_author AS ba ON ba.id = bar.author_id").
|
||||
Scopes(paginate(info.PageInfo)).
|
||||
Order("bar.book_id asc, bar.author_sort asc, bar.id desc").
|
||||
Scan(&list).Error
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user