resource_data.go 12 KB

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