resource_data.go 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_web_mfyx/models"
  6. "hongze/hongze_web_mfyx/utils"
  7. "strconv"
  8. "strings"
  9. )
  10. func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int, user *models.WxUserItem) (items []*models.CygxResourceDataNewResp, err error) {
  11. uid := user.UserId
  12. list, e := models.GetResourceDataList(condition, pars, startSize, pageSize)
  13. if e != nil {
  14. err = errors.New("GetResourceDataList, Err: " + e.Error())
  15. return
  16. }
  17. mapItems := make(map[string]*models.CygxResourceDataNewResp)
  18. for _, v := range list {
  19. //预处理文章
  20. item := new(models.CygxResourceDataNewResp)
  21. item.Id = v.Id
  22. item.SourceId = v.SourceId
  23. item.Source = v.Source
  24. //item.Title = v.Title
  25. //item.Annotation = v.Annotation
  26. //item.Abstract = v.Abstract
  27. item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  28. mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  29. }
  30. var articleIds []int //报告
  31. var activityIds []int //活动
  32. var activityvideoIds []string // 活动视频
  33. var activityvoiceIds []string //活动音频
  34. var yanxuanSpecialIds []int // 研选专栏
  35. var roadshowIds []string //微路演
  36. var askserieVideoIds []string //问答系列视频
  37. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior
  38. for _, v := range list {
  39. if v.Source == "article" {
  40. articleIds = append(articleIds, v.SourceId)
  41. } else if v.Source == "activity" {
  42. activityIds = append(activityIds, v.SourceId)
  43. } else if v.Source == "activityvideo" {
  44. activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  45. } else if v.Source == "activityvoice" {
  46. activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  47. } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL {
  48. yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
  49. }
  50. }
  51. detail, e := models.GetConfigByCode("city_img_url")
  52. if e != nil {
  53. err = errors.New("GetResourceDataList, Err: " + e.Error())
  54. return
  55. }
  56. detailChart, e := models.GetConfigByCode("chart_img_url")
  57. if e != nil {
  58. err = errors.New("GetResourceDataList, Err: " + e.Error())
  59. return
  60. }
  61. addressList := strings.Split(detail.ConfigValue, "{|}")
  62. mapAddress := make(map[string]string)
  63. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  64. mapChart := make(map[string]string)
  65. var cityName string
  66. var chartName string
  67. var imgUrl string
  68. var imgUrlChart string
  69. for _, v := range addressList {
  70. vslice := strings.Split(v, "_")
  71. cityName = vslice[0]
  72. imgUrl = vslice[len(vslice)-1]
  73. mapAddress[cityName] = imgUrl
  74. }
  75. for _, v := range chartList {
  76. vslice := strings.Split(v, "_")
  77. chartName = vslice[0]
  78. imgUrlChart = vslice[len(vslice)-1]
  79. mapChart[chartName] = imgUrlChart
  80. }
  81. var imgUrlResp string
  82. //处理文章
  83. if len(articleIds) > 0 {
  84. pars = make([]interface{}, 0)
  85. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  86. pars = append(pars, articleIds)
  87. articleList, e := models.GetHomeListPublic(condition, pars, 0, len(articleIds))
  88. if e != nil {
  89. err = errors.New("GetResourceDataList, Err: " + e.Error())
  90. return
  91. }
  92. articleList, e = HandleArticleCategoryImg(articleList, user)
  93. if e != nil {
  94. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  95. return
  96. }
  97. for _, v := range articleList {
  98. v.Body = ""
  99. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  100. }
  101. }
  102. //处理活动
  103. if len(activityIds) > 0 {
  104. //for _, vss := range activityIds {
  105. // imgUrlResp += strconv.Itoa(vss) + ","
  106. //}
  107. pars = make([]interface{}, 0)
  108. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  109. pars = append(pars, activityIds)
  110. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  111. if e != nil {
  112. err = errors.New("GetResourceDataList, Err: " + e.Error())
  113. return
  114. }
  115. var activityListRersp []*models.ActivityListResp
  116. //for _, v := range activityList {
  117. // activityListRersp = append(activityListRersp, ActivityButtonShow(v, user, make([]string, 0)))
  118. //}
  119. activityListRersp = ActivityArrButtonShow(activityList, user, make([]string, 0))
  120. //处理不同的报名方式按钮回显
  121. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  122. if e != nil {
  123. err = errors.New("GetActivitySignupResp, Err: " + e.Error())
  124. return
  125. }
  126. for _, v := range activityListRersp {
  127. if v == nil {
  128. continue
  129. }
  130. if v.ActivityType == 0 {
  131. if mapAddress[v.City] != "" {
  132. imgUrlResp = mapAddress[v.City]
  133. } else {
  134. imgUrlResp = mapAddress["其它"]
  135. }
  136. } else {
  137. if mapChart[v.ChartPermissionName] != "" {
  138. imgUrlResp = mapChart[v.ChartPermissionName]
  139. }
  140. }
  141. v.ImgUrl = imgUrlResp
  142. v.SourceType = mapActivitySignup[v.ActivityId]
  143. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  144. }
  145. }
  146. //处理研选专栏
  147. lenyanxuanSpecialIds := len(yanxuanSpecialIds)
  148. if lenyanxuanSpecialIds > 0 {
  149. pars = make([]interface{}, 0)
  150. condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
  151. pars = append(pars, yanxuanSpecialIds)
  152. listyanxuanSpecial, e := models.GetYanxuanSpecialListHome(user.UserId, condition, pars, 0, 0)
  153. if e != nil {
  154. err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
  155. return
  156. }
  157. yanxuanSpecialPv := GetYanxuanSpecialRecordByYanxuanSpecialId(yanxuanSpecialIds) // 专栏Pv
  158. for _, v := range listyanxuanSpecial {
  159. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  160. v.Annotation, _ = GetReportContentTextSubNew(v.Content)
  161. v.Content = ""
  162. v.Pv = yanxuanSpecialPv[v.Id]
  163. v.LabelKeywordImgLink = utils.LABEL_ICO_4
  164. mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
  165. }
  166. }
  167. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
  168. audioIdstr := strings.Join(activityvoiceIds, ",")
  169. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  170. roadshowIdsStr := strings.Join(roadshowIds, ",")
  171. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  172. listv, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
  173. if e != nil {
  174. err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
  175. return
  176. }
  177. // 用户权限
  178. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  179. if e != nil {
  180. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  181. return
  182. }
  183. // 获取默认图配置
  184. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  185. if e != nil {
  186. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  187. return
  188. }
  189. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  190. for i := range listv {
  191. // 权限
  192. au := new(models.UserPermissionAuthInfo)
  193. au.SellerName = authInfo.SellerName
  194. au.SellerMobile = authInfo.SellerMobile
  195. au.HasPermission = authInfo.HasPermission
  196. au.OperationMode = authInfo.OperationMode
  197. if au.HasPermission == 1 {
  198. // 非宏观权限进一步判断是否有权限
  199. if listv[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, listv[i].ChartPermissionName) {
  200. au.HasPermission = 2
  201. }
  202. }
  203. // 无权限的弹框提示
  204. if au.HasPermission != 1 {
  205. if au.OperationMode == UserPermissionOperationModeCall {
  206. if listv[i].Type == 1 {
  207. au.PopupMsg = UserPermissionPopupMsgCallActivity
  208. } else {
  209. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  210. }
  211. } else {
  212. if listv[i].Type == 1 {
  213. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  214. } else {
  215. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  216. }
  217. }
  218. }
  219. listv[i].AuthInfo = au
  220. listv[i].PublishTime = utils.StrTimeToTime(listv[i].PublishTime).Format(utils.FormatDate)
  221. // 默认图
  222. if listv[i].BackgroundImg == "" {
  223. if listv[i].Type == 1 {
  224. listv[i].BackgroundImg = audioMap[listv[i].ChartPermissionId]
  225. } else {
  226. listv[i].BackgroundImg = videoMap[listv[i].ChartPermissionId]
  227. }
  228. }
  229. // 分享图
  230. if listv[i].ShareImg == "" {
  231. if listv[i].Type == 1 {
  232. listv[i].ShareImg = audioShareMap[listv[i].ChartPermissionId]
  233. } else {
  234. listv[i].ShareImg = videoShareMap[listv[i].ChartPermissionId]
  235. }
  236. }
  237. listv[i].LabelKeywordImgLink = utils.LABEL_ICO_10
  238. }
  239. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  240. for _, item := range listv {
  241. if item.Type == 1 {
  242. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  243. } else if item.Type == 2 {
  244. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  245. } else if item.Type == 3 {
  246. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  247. } else if item.Type == 4 {
  248. mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
  249. }
  250. }
  251. }
  252. for _, vList := range list {
  253. for _, v := range mapItems {
  254. //如果这些类型都为空,那么就不合并
  255. if v.Article == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.YanxuanSpecial == nil {
  256. continue
  257. }
  258. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  259. items = append(items, v)
  260. }
  261. }
  262. }
  263. return
  264. }