123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- package media
- 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"
- reportService "eta/eta_mini_ht_api/domian/report"
- "eta/eta_mini_ht_api/service/media"
- "eta/eta_mini_ht_api/service/user"
- "sync"
- )
- type MediaController 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 (m *MediaController) Search(mediaType string, key string) {
- controllers.Wrap(&m.BaseController, func() (result *controllers.WrapData, err error) {
- result = m.InitWrapData("分页搜索媒体列表失败")
- if key == "" {
- err = exception.New(exception.SearchKeyEmptyError)
- m.FailedResult("分页搜索报告列表失败", result)
- return
- }
- detailType := m.Data["detailType"].(string)
- userInfo := m.Data["user"].(user.User)
- pageRes := page.Page{
- Current: m.PageInfo.Current,
- PageSize: m.PageInfo.PageSize,
- }
- //获取当前可以被搜索的报告原始ID
- var mediaIds []int
- var mappingRiskLevel string
- var userRiskStatus string
- //先要限制查询的id范围
- pageRes.Total, pageRes.LatestId, mediaIds, mappingRiskLevel, userRiskStatus = media.RangeSearch(mediaType, isLogin(detailType), userInfo.Id)
- if len(mediaIds) == 0 {
- reports := new(page.PageResult)
- reports.Data = []reportService.ReportDTO{}
- reports.Page = pageRes
- logger.Info("没有可以查询的媒体列表")
- m.SuccessResult("分页搜索媒体列表成功", reports, result)
- return
- }
- if m.PageInfo.LatestId == 0 {
- //pageRes.Total, pageRes.LatestId = media.SearchMaxMediaId(mediaType, key)
- m.PageInfo.LatestId = pageRes.LatestId
- } else {
- pageRes.LatestId = m.PageInfo.LatestId
- pageRes.Total = m.PageInfo.Total
- }
- pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
- list, err := media.SearchMediaList(mediaType, key, mediaIds, m.PageInfo, isLogin(detailType), userInfo.Id, mappingRiskLevel, userRiskStatus)
- if err != nil {
- m.FailedResult("分页搜索媒体列表失败", result)
- return
- }
- reports := new(page.PageResult)
- reports.Data = list
- reports.Page = pageRes
- m.SuccessResult("分页搜索媒体列表成功", reports, result)
- return
- })
- }
- // List 获取媒体列表
- // @Description 获取媒体列表
- // @Success 200 {object}
- // @router /list [get]
- func (m *MediaController) List(mediaType string, permissionIds string) {
- controllers.Wrap(&m.BaseController, func() (result *controllers.WrapData, err error) {
- result = m.InitWrapData("分页查询媒体列表失败")
- if mediaType == "" || !m.CheckMediaType(mediaType) {
- err = exception.New(exception.MediaTypeError)
- m.FailedResult("分页查询媒体列表失败", result)
- return
- }
- permissionIdList, err := m.TransPermissionIds(permissionIds)
- if err != nil {
- logger.Error("品种列表解析错误:%v", err)
- m.FailedResult("分页查询媒体列表失败", result)
- err = exception.New(exception.QueryReportPageFailed)
- return
- }
- pageRes := page.Page{
- Current: m.PageInfo.Current,
- PageSize: m.PageInfo.PageSize,
- }
- detailType := m.Data["detailType"].(string)
- userInfo := m.Data["user"].(user.User)
- var mediaIds []int
- var mappingRiskLevel string
- var userRiskStatus string
- pageRes.Total, pageRes.LatestId, mediaIds, mappingRiskLevel, userRiskStatus = media.GetTotalPageCountByPermissionIds(mediaType, permissionIdList, isLogin(detailType), userInfo.Id)
- if err != nil {
- logger.Error("分页查询媒体列表失败:%v", err)
- m.FailedResult("分页查询媒体列表失败", result)
- return
- }
- if m.PageInfo.LatestId == 0 {
- m.PageInfo.LatestId = pageRes.LatestId
- m.PageInfo.Total = pageRes.Total
- } else {
- pageRes.LatestId = m.PageInfo.LatestId
- pageRes.Total = m.PageInfo.Total
- }
- pageRes.TotalPage = page.TotalPages(pageRes.Total, pageRes.PageSize)
- list, err := media.GetMediaPageByIds(mediaType, m.PageInfo, mediaIds, isLogin(detailType), userInfo.Id, mappingRiskLevel, userRiskStatus)
- if err != nil {
- m.FailedResult("分页查询媒体列表失败", result)
- return
- }
- mediaList := new(page.PageResult)
- mediaList.Data = list
- mediaList.Page = pageRes
- m.SuccessResult("分页查询媒体列表成功", mediaList, result)
- return
- })
- }
- type RecordCountReq struct {
- MediaId int `json:"mediaId"`
- MediaName string `json:"mediaName"`
- TraceId string `json:"traceId"`
- MediaType string `json:"mediaType"`
- }
- // Count 获取品种列表
- // @Description 获取最新发布的报告列表
- // @Success 200 {object}
- // @router /count [post]
- func (m *MediaController) Count() {
- controllers.Wrap(&m.BaseController, func() (result *controllers.WrapData, err error) {
- result = m.InitWrapData("媒体点击记录成功")
- var userInfo user.User
- userInfo = m.Data["user"].(user.User)
- recordReq := new(RecordCountReq)
- m.GetPostParams(recordReq)
- if recordReq.MediaType == "" || !m.CheckMediaType(recordReq.MediaType) {
- err = exception.New(exception.MediaTypeError)
- m.FailedResult("媒体点击记录失败", result)
- return
- }
- record := convertToRecordCount(recordReq)
- record.UserId = userInfo.Id
- record.Mobile = userInfo.Mobile
- traceId, err := media.CountMedia(record)
- if err != nil {
- err = exception.New(exception.MediaRecordClickCountFailed)
- m.FailedResult("媒体点击记录失败", result)
- return
- }
- countResp := struct {
- TraceId string `json:"traceId"`
- }{TraceId: traceId}
- m.SuccessResult("媒体点击记录成功", countResp, result)
- return
- })
- }
- // GetMedia 获取媒体详情
- // @Description 获取媒体详情
- // @Success 200 {object}
- // @router /media [get]
- func (m *MediaController) GetMedia(mediaType string, mediaId int, productId int) {
- controllers.Wrap(&m.BaseController, func() (result *controllers.WrapData, err error) {
- result = m.InitWrapData("获取媒体详情失败")
- if mediaType == "" || !m.CheckMediaType(mediaType) {
- err = exception.New(exception.MediaTypeError)
- m.FailedResult("获取媒体详情失败", result)
- return
- }
- userInfo := m.Data["user"].(user.User)
- detailType := m.Data["detailType"].(string)
- var subscribeStatus string
- if productId > 0 {
- var wg sync.WaitGroup
- wg.Add(1)
- go func() {
- defer wg.Done()
- subscribeStatus = user.GetUserScribeStatus(productId, userInfo.Id)
- }()
- } else {
- subscribeStatus = user.UnSubscribe
- }
- mediaDetail, err := media.GetMediaById(mediaType, mediaId, isLogin(detailType), userInfo.Id)
- if err != nil {
- m.FailedResult("获取媒体详情失败", result)
- return
- }
- mediaDetail.SubscribeStatus = subscribeStatus
- m.SuccessResult("获取媒体详情成功", mediaDetail, result)
- return
- })
- }
- func convertToRecordCount(req *RecordCountReq) media.RecordCount {
- return media.RecordCount{
- MediaId: req.MediaId,
- TraceId: req.TraceId,
- MediaType: req.MediaType,
- Additional: "",
- }
- }
|