获取周报列表时增加ids

master
ymm 2022-02-15 12:04:16 +08:00
parent 3af73b9dbc
commit e659a60e6e
3 changed files with 24 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import (
"goweb-gin-demo/global"
"goweb-gin-demo/model/common/request"
"goweb-gin-demo/model/common/response"
"goweb-gin-demo/model/wt"
wtReq "goweb-gin-demo/model/wt/request"
"strconv"
)
@ -108,12 +109,13 @@ func (wtReportsApi *WtReportsApi) GetWtReportsList(c *gin.Context) {
var searchInfo wtReq.WtReportsSearch
_ = c.ShouldBindQuery(&searchInfo)
if err, list, total := wtReportsService.GetWtReportsInfoList(searchInfo); err != nil {
if err, list, total, ids := wtReportsService.GetWtReportsInfoList(searchInfo); err != nil {
global.GLOBAL_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
response.OkWithDetailed(wt.PageResult{
List: list,
Ids: ids,
Total: total,
Page: searchInfo.Page,
PageSize: searchInfo.PageSize,

View File

@ -30,3 +30,11 @@ type UploadFileJson struct {
Key string `json:"key"`
Name string `json:"name"`
}
type PageResult struct {
List interface{} `json:"list"`
Ids []int `json:"ids"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}

View File

@ -10,6 +10,7 @@ import (
wtRes "goweb-gin-demo/model/wt/response"
"goweb-gin-demo/service/system"
"strconv"
"strings"
)
type WtReportsService struct {
@ -45,7 +46,7 @@ func (wtReportsService *WtReportsService) GetWtReports(id uint) (err error, repo
}
// GetWtReportsInfoList 分页获取周报
func (wtReportsService *WtReportsService) GetWtReportsInfoList(info wtReq.WtReportsSearch) (err error, list []wtRes.WtReportsSearchResult, total int64) {
func (wtReportsService *WtReportsService) GetWtReportsInfoList(info wtReq.WtReportsSearch) (err error, list []wtRes.WtReportsSearchResult, total int64, ids []int) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
@ -67,7 +68,7 @@ func (wtReportsService *WtReportsService) GetWtReportsInfoList(info wtReq.WtRepo
// 条件高级查询
if info.UserId > 0 {
condition += " and user_id = " + strconv.Itoa(int(info.UserId))
}else {
} else {
condition += " OR user_id = " + strconv.Itoa(int(info.CurrUserId)) + " "
}
@ -92,9 +93,15 @@ func (wtReportsService *WtReportsService) GetWtReportsInfoList(info wtReq.WtRepo
err = global.GLOBAL_DB.Raw(querySql, limit, offset).Scan(&reportsSearchBOList).Error
// 获取所有周报内容的id列表
idsSplit := strings.Split(querySql, "FROM wt_reports")
idsSql := "SELECT id FROM wt_reports " + idsSplit[1]
err = global.GLOBAL_DB.Select("id").Raw(idsSql, int(total), 0).Scan(&ids).Error
reportsSearchResultList := reportsToSearchResult(reportsSearchBOList)
return err, reportsSearchResultList, total
return err, reportsSearchResultList, total, ids
}
//数据转换一下, 需要把json数据转换为字符串
@ -143,9 +150,9 @@ func reportToSearchResult(searchBO wtRes.WtReportsSearchBO, user systemModel.Sys
searchResult.CommentCount = searchBO.CommentCount
if len(user.NickName) == 0 {
searchResult.NickName = searchBO.UserName
searchResult.NickName = searchBO.UserName
} else {
searchResult.NickName = user.NickName
searchResult.NickName = user.NickName
}
json.Unmarshal([]byte(searchBO.SendTo), &searchResult.SendTo)