1
This commit is contained in:
@@ -125,7 +125,10 @@ func (p *PrintNotice) SelectNoticeAddress(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
result, err := server.QueryPrintNotice(param)
|
||||
return result, "", err
|
||||
result, count, err := server.QueryPrintNotice(param)
|
||||
resultMap := make(map[string]interface{}, 2)
|
||||
resultMap["result"] = result
|
||||
resultMap["count"] = count
|
||||
return resultMap, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -46,11 +46,20 @@ func (p PrintNotice) DeletePrintNotice(id int) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p PrintNotice) SelectPrintNotice(param *editionModel.QueryPrintNotice) ([]*editionModel.PrintNotice, error) {
|
||||
func (p PrintNotice) SelectPrintNotice(param *editionModel.QueryPrintNotice) ([]*editionModel.PrintNotice, int, error) {
|
||||
var result []*editionModel.PrintNotice
|
||||
sql := `SELECT * FROM print_notice WHERE notice_type = ? ORDER BY created_at DESC LIMIT ? OFFSET ? `
|
||||
if err := globals.GetDB().Select(&result, sql, []interface{}{param.NoticeType, param.PageSize, (param.PageNumber - 1) * param.PageSize}...); err != nil {
|
||||
return nil, err
|
||||
sql := `SELECT SQL_CALC_FOUND_ROWS * FROM print_notice WHERE notice_type = ? ORDER BY created_at DESC LIMIT ? OFFSET ? `
|
||||
txDb := globals.GetTxDb()
|
||||
if err := txDb.Select(&result, sql, []interface{}{param.NoticeType, param.PageSize, (param.PageNumber - 1) * param.PageSize}...); err != nil {
|
||||
txDb.Rollback()
|
||||
return nil, 0, err
|
||||
}
|
||||
return result, nil
|
||||
|
||||
var countInfo []*editionModel.Count
|
||||
err := txDb.Select(&countInfo, "SELECT FOUND_ROWS() ct")
|
||||
if err != nil {
|
||||
txDb.Rollback()
|
||||
return nil, 0, err
|
||||
}
|
||||
return result, countInfo[0].Ct, nil
|
||||
}
|
||||
|
||||
@@ -28,3 +28,7 @@ type QueryPrintNotice struct {
|
||||
PageSize int `json:"page_size" form:"page_size" binding:"required"`
|
||||
PageNumber int `json:"page_number" form:"page_number" binding:"required"`
|
||||
}
|
||||
|
||||
type Count struct {
|
||||
Ct int `json:"ct"`
|
||||
}
|
||||
|
||||
@@ -22,6 +22,6 @@ func (p PrintNotice) DeletePrintNotice(param *editionModel.DeletePrintNotice) er
|
||||
return editionDao.PrintNoticeDao.DeletePrintNotice(param.Id)
|
||||
}
|
||||
|
||||
func (p PrintNotice) QueryPrintNotice(param *editionModel.QueryPrintNotice) ([]*editionModel.PrintNotice, error) {
|
||||
func (p PrintNotice) QueryPrintNotice(param *editionModel.QueryPrintNotice) ([]*editionModel.PrintNotice, int, error) {
|
||||
return editionDao.PrintNoticeDao.SelectPrintNotice(param)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user