1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package home
- import (
- logger "eta/eta_mini_ht_api/common/component/log"
- "eta/eta_mini_ht_api/common/exception"
- "eta/eta_mini_ht_api/common/utils/page"
- "eta/eta_mini_ht_api/controllers"
- homeService "eta/eta_mini_ht_api/service/home"
- "eta/eta_mini_ht_api/service/user"
- "time"
- )
- type HomeController struct {
- controllers.ListController
- }
- func isLogin(listType string) bool {
- if listType == "logout" {
- logger.Info("当前用户未登录,展示部分详情")
- return false
- }
- if listType == "login" {
- return true
- }
- return false
- }
- // Search 搜索报告列表
- // @Description 搜索报告列表
- // @Success 200 {object}
- // @router /search [get]
- func (r *HomeController) Search(key string) {
- controllers.Wrap(&r.BaseController, func() (result *controllers.WrapData, err error) {
- result = r.InitWrapData("分页搜索列表失败")
- if key == "" {
- err = exception.New(exception.SearchKeyEmptyError)
- r.FailedResult("分页搜索报告列表失败", result)
- return
- }
- detailType := r.Data["detailType"].(string)
- userInfo := r.Data["user"].(user.User)
- pageRes := page.Page{
- Current: r.PageInfo.Current,
- PageSize: r.PageInfo.PageSize,
- }
- if r.PageInfo.TimeStamp == 0 {
- r.PageInfo.TimeStamp = time.Now().Unix()
- } else {
- pageRes.LatestId = r.PageInfo.LatestId
- pageRes.Total = r.PageInfo.Total
- }
- var total int64
- var list []homeService.HomeSearch
- list, total, err = homeService.Search(key, r.PageInfo, isLogin(detailType), userInfo.Id)
- if err != nil {
- r.FailedResult("分页搜索报告列表失败", result)
- return
- }
- var dataList []interface{}
- for _, item := range list {
- switch item.ResultType {
- case homeService.ReportResultType:
- dataList = append(dataList, item.Report)
- case homeService.MediaResultType:
- dataList = append(dataList, item.Media)
- }
- }
- r.PageInfo.Total = total
- pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
- reports := new(page.PageResult)
- reports.Data = dataList
- reports.Page = pageRes
- r.SuccessResult("分页搜索报告列表成功", reports, result)
- return
- })
- }
|