resource_data.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int, user *models.WxUserItem) (items []*models.CygxResourceDataNewResp, err error) {
  12. uid := user.UserId
  13. list, e := models.GetResourceDataList(condition, pars, startSize, pageSize)
  14. if e != nil {
  15. err = errors.New("GetResourceDataList, Err: " + e.Error())
  16. return
  17. }
  18. mapItems := make(map[string]*models.CygxResourceDataNewResp)
  19. for _, v := range list {
  20. //预处理文章
  21. item := new(models.CygxResourceDataNewResp)
  22. item.Id = v.Id
  23. item.SourceId = v.SourceId
  24. item.Source = v.Source
  25. //item.Title = v.Title
  26. //item.Annotation = v.Annotation
  27. //item.Abstract = v.Abstract
  28. item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  29. mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  30. }
  31. var articleIds []int //报告
  32. var newchartIds []int //图表
  33. var roadshowIds []string //微路演
  34. var activityIds []int //活动
  35. var activityvideoIds []string // 活动视频
  36. var activityvoiceIds []string //活动音频
  37. var activityspecialIds []int //专项调研活动
  38. var researchsummaryIds []int //本周研究汇总
  39. var minutessummaryIds []int //上周纪要汇总
  40. var meetingreviewchaptIds []int //晨会精华
  41. var productinteriorIds []int //产品内测
  42. var reportselectionIds []int // 报告精选
  43. var yanxuanSpecialIds []int // 研选专栏
  44. var askserieVideoIds []string //问答系列视频
  45. var ficcreporrtIds []string //FICC研报
  46. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior
  47. for _, v := range list {
  48. if v.Source == "article" {
  49. articleIds = append(articleIds, v.SourceId)
  50. } else if v.Source == "newchart" {
  51. newchartIds = append(newchartIds, v.SourceId)
  52. } else if v.Source == "roadshow" {
  53. roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  54. } else if v.Source == "activity" {
  55. activityIds = append(activityIds, v.SourceId)
  56. } else if v.Source == "activityvideo" {
  57. activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  58. } else if v.Source == "activityvoice" {
  59. activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  60. } else if v.Source == "activityspecial" {
  61. activityspecialIds = append(activityspecialIds, v.SourceId)
  62. } else if v.Source == "researchsummary" {
  63. researchsummaryIds = append(researchsummaryIds, v.SourceId)
  64. } else if v.Source == "minutessummary" {
  65. minutessummaryIds = append(minutessummaryIds, v.SourceId)
  66. } else if v.Source == "meetingreviewchapt" {
  67. meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  68. } else if v.Source == "productinterior" {
  69. productinteriorIds = append(productinteriorIds, v.SourceId)
  70. } else if v.Source == "reportselection" {
  71. reportselectionIds = append(reportselectionIds, v.SourceId)
  72. } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL {
  73. yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
  74. } else if v.Source == utils.CYGX_OBJ_ASKSERIEVIDEO {
  75. askserieVideoIds = append(askserieVideoIds, strconv.Itoa(v.SourceId))
  76. } else if v.Source == utils.CYGX_OBJ_FICC_REPORT {
  77. ficcreporrtIds = append(ficcreporrtIds, strconv.Itoa(v.SourceId))
  78. }
  79. }
  80. detail, e := models.GetConfigByCode("city_img_url")
  81. if e != nil {
  82. err = errors.New("GetResourceDataList, Err: " + e.Error())
  83. return
  84. }
  85. detailChart, e := models.GetConfigByCode("chart_img_url")
  86. if e != nil {
  87. err = errors.New("GetResourceDataList, Err: " + e.Error())
  88. return
  89. }
  90. addressList := strings.Split(detail.ConfigValue, "{|}")
  91. mapAddress := make(map[string]string)
  92. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  93. mapChart := make(map[string]string)
  94. var cityName string
  95. var chartName string
  96. var imgUrl string
  97. var imgUrlChart string
  98. for _, v := range addressList {
  99. vslice := strings.Split(v, "_")
  100. cityName = vslice[0]
  101. imgUrl = vslice[len(vslice)-1]
  102. mapAddress[cityName] = imgUrl
  103. }
  104. for _, v := range chartList {
  105. vslice := strings.Split(v, "_")
  106. chartName = vslice[0]
  107. imgUrlChart = vslice[len(vslice)-1]
  108. mapChart[chartName] = imgUrlChart
  109. }
  110. var imgUrlResp string
  111. //处理文章
  112. if len(articleIds) > 0 {
  113. pars = make([]interface{}, 0)
  114. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  115. pars = append(pars, articleIds)
  116. articleList, e := models.GetHomeListPublic(condition, pars, 0, len(articleIds))
  117. if e != nil {
  118. err = errors.New("GetResourceDataList, Err: " + e.Error())
  119. return
  120. }
  121. articleList, e = HandleArticleCategoryImg(articleList, user)
  122. if e != nil {
  123. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  124. return
  125. }
  126. for _, v := range articleList {
  127. v.Body = ""
  128. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  129. }
  130. }
  131. //处理晨会精华
  132. if len(meetingreviewchaptIds) > 0 {
  133. //pars = make([]interface{}, 0)
  134. //condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  135. //pars = append(pars, meetingreviewchaptIds)
  136. //
  137. listrMeet, e := GetCygxMorningMeetingReviewChapterListByIds(meetingreviewchaptIds)
  138. if e != nil {
  139. err = errors.New("GetCygxMorningMeetingReviewChapterListByIds, Err: " + e.Error())
  140. return
  141. }
  142. for _, v := range listrMeet {
  143. v.Content = AnnotationHtml(v.Content)
  144. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  145. mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  146. }
  147. }
  148. //处理上周纪要汇总
  149. if len(minutessummaryIds) > 0 {
  150. pars = make([]interface{}, 0)
  151. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  152. pars = append(pars, minutessummaryIds)
  153. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  154. if e != nil {
  155. err = errors.New("GetResourceDataList, Err: " + e.Error())
  156. return
  157. }
  158. mapPv := GetCygxReportHistoryRecordListMap(minutessummaryIds, "szjyhz")
  159. for _, v := range listresearchsummary {
  160. v.Pv = mapPv[v.ArticleId]
  161. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  162. mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  163. }
  164. }
  165. //处理本周纪要汇总
  166. if len(researchsummaryIds) > 0 {
  167. pars = make([]interface{}, 0)
  168. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  169. pars = append(pars, researchsummaryIds)
  170. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  171. if e != nil {
  172. err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  173. return
  174. }
  175. mapPv := GetCygxReportHistoryRecordListMap(researchsummaryIds, "bzyjhz")
  176. for _, v := range listresearchsummary {
  177. v.Pv = mapPv[v.ArticleId]
  178. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  179. mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  180. }
  181. }
  182. //处理产品内测
  183. if len(productinteriorIds) > 0 {
  184. pars = make([]interface{}, 0)
  185. condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  186. pars = append(pars, productinteriorIds)
  187. listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  188. if e != nil {
  189. err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  190. return
  191. }
  192. ProductInteriorHistoryMap := GetCygxProductInteriorHistoryListPvMap(productinteriorIds)
  193. for _, v := range listProductInterior {
  194. v.Body = ProductInteriorHtml(v.Body)
  195. v.Pv = ProductInteriorHistoryMap[v.ProductInteriorId]
  196. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  197. mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  198. }
  199. }
  200. //处理活动
  201. if len(activityIds) > 0 {
  202. for _, vss := range activityIds {
  203. imgUrlResp += strconv.Itoa(vss) + ","
  204. }
  205. pars = make([]interface{}, 0)
  206. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  207. pars = append(pars, activityIds)
  208. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  209. if e != nil {
  210. err = errors.New("GetResourceDataList, Err: " + e.Error())
  211. return
  212. }
  213. var activityListRersp []*models.ActivityListResp
  214. //for _, v := range activityList {
  215. // activityListRersp = append(activityListRersp, ActivityButtonShow(v, user, make([]string, 0)))
  216. //}
  217. activityListRersp = ActivityArrButtonShow(activityList, user, make([]string, 0))
  218. //处理不同的报名方式按钮回显
  219. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  220. if e != nil {
  221. err = errors.New("GetActivitySignupResp, Err: " + e.Error())
  222. return
  223. }
  224. for _, v := range activityListRersp {
  225. if v == nil {
  226. continue
  227. }
  228. if v.ActivityType == 0 {
  229. if mapAddress[v.City] != "" {
  230. imgUrlResp = mapAddress[v.City]
  231. } else {
  232. imgUrlResp = mapAddress["其它"]
  233. }
  234. } else {
  235. if mapChart[v.ChartPermissionName] != "" {
  236. imgUrlResp = mapChart[v.ChartPermissionName]
  237. }
  238. }
  239. v.ImgUrl = imgUrlResp
  240. v.SourceType = mapActivitySignup[v.ActivityId]
  241. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  242. }
  243. }
  244. //处理图表
  245. if len(newchartIds) > 0 {
  246. pars = make([]interface{}, 0)
  247. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  248. pars = append(pars, newchartIds)
  249. chartDateList, e := models.GetChartListCollection(condition, pars, uid, 0, len(newchartIds))
  250. if e != nil {
  251. err = errors.New("GetResourceDataList, Err: " + e.Error())
  252. return
  253. }
  254. for _, v := range chartDateList {
  255. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  256. }
  257. }
  258. //处理专项调研
  259. if len(activityspecialIds) > 0 {
  260. pars = make([]interface{}, 0)
  261. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  262. pars = append(pars, activityspecialIds)
  263. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  264. if e != nil {
  265. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  266. return
  267. }
  268. UserMap, e := GetSpecialTripUserMap(activityspecialIds, user.UserId)
  269. if e != nil {
  270. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  271. return
  272. }
  273. for _, v := range activitySpeciallist {
  274. if mapChart[v.ChartPermissionName] != "" {
  275. imgUrlResp = mapChart[v.ChartPermissionName]
  276. }
  277. if _, ok := UserMap[v.ActivityId]; ok {
  278. v.IsTrip = 1
  279. }
  280. if v.Days == 0 {
  281. v.TripStatus = 1
  282. v.TripImgLink = v.TripImgLink
  283. } else {
  284. v.TripStatus = 2
  285. v.TripImgLink = v.TripImgLinkFix
  286. v.ActivityTimeText = v.ActivityTimeTextByDay
  287. }
  288. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  289. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  290. if resultTimeStart.After(time.Now()) {
  291. v.ActiveState = "1"
  292. } else if time.Now().After(resultTimeEnd) {
  293. v.ActiveState = "3"
  294. } else {
  295. v.ActiveState = "2"
  296. }
  297. v.ImgUrl = imgUrlResp
  298. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  299. }
  300. }
  301. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
  302. audioIdstr := strings.Join(activityvoiceIds, ",")
  303. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  304. roadshowIdsStr := strings.Join(roadshowIds, ",")
  305. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  306. list, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
  307. if e != nil {
  308. err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
  309. return
  310. }
  311. // 用户权限
  312. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  313. if e != nil {
  314. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  315. return
  316. }
  317. // 获取默认图配置
  318. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  319. if e != nil {
  320. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  321. return
  322. }
  323. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  324. for i := range list {
  325. // 权限
  326. au := new(models.UserPermissionAuthInfo)
  327. au.SellerName = authInfo.SellerName
  328. au.SellerMobile = authInfo.SellerMobile
  329. au.HasPermission = authInfo.HasPermission
  330. au.OperationMode = authInfo.OperationMode
  331. if au.HasPermission == 1 {
  332. // 非宏观权限进一步判断是否有权限
  333. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  334. au.HasPermission = 2
  335. }
  336. }
  337. // 无权限的弹框提示
  338. if au.HasPermission != 1 {
  339. if au.OperationMode == UserPermissionOperationModeCall {
  340. if list[i].Type == 1 {
  341. au.PopupMsg = UserPermissionPopupMsgCallActivity
  342. } else {
  343. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  344. }
  345. } else {
  346. if list[i].Type == 1 {
  347. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  348. } else {
  349. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  350. }
  351. }
  352. }
  353. list[i].AuthInfo = au
  354. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  355. // 默认图
  356. if list[i].BackgroundImg == "" {
  357. if list[i].Type == 1 {
  358. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  359. } else {
  360. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  361. }
  362. }
  363. // 分享图
  364. if list[i].ShareImg == "" {
  365. if list[i].Type == 1 {
  366. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  367. } else {
  368. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  369. }
  370. }
  371. }
  372. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  373. for _, item := range list {
  374. if item.Type == 1 {
  375. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  376. } else if item.Type == 2 {
  377. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  378. } else if item.Type == 3 {
  379. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  380. } else if item.Type == 4 {
  381. mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
  382. }
  383. }
  384. }
  385. //处理报告精选
  386. lenreportselectionIds := len(reportselectionIds)
  387. if lenreportselectionIds > 0 {
  388. pars = make([]interface{}, 0)
  389. condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenreportselectionIds) + `)`
  390. pars = append(pars, reportselectionIds)
  391. listreportselection, e := models.GetReportSelectionList(condition, pars, 0, lenreportselectionIds)
  392. if e != nil {
  393. err = errors.New("GetReportSelectionList, Err: " + e.Error())
  394. return
  395. }
  396. mapPv := GetCygxReportHistoryRecordListMap(reportselectionIds, "bgjx")
  397. for _, v := range listreportselection {
  398. v.Title += "(第" + v.Periods + "期)"
  399. v.MarketStrategy = AnnotationHtml(v.MarketStrategy)
  400. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  401. v.Pv = mapPv[v.ArticleId]
  402. mapItems[fmt.Sprint("reportselection", v.ArticleId)].ReportSelection = v
  403. }
  404. }
  405. //处理研选专栏
  406. lenyanxuanSpecialIds := len(yanxuanSpecialIds)
  407. if lenyanxuanSpecialIds > 0 {
  408. pars = make([]interface{}, 0)
  409. condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
  410. pars = append(pars, yanxuanSpecialIds)
  411. listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars, 0, 0)
  412. if e != nil {
  413. err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
  414. return
  415. }
  416. yanxuanSpecialPv := GetYanxuanSpecialRecordByYanxuanSpecialId(yanxuanSpecialIds)
  417. for _, v := range listyanxuanSpecial {
  418. v.Pv = yanxuanSpecialPv[v.Id]
  419. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  420. v.Annotation, _ = GetReportContentTextSubNew(v.Content)
  421. mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
  422. }
  423. }
  424. //处理FICC研报
  425. if len(ficcreporrtIds) > 0 {
  426. pars = make([]interface{}, 0)
  427. condition = ` AND a.report_id IN (` + utils.GetOrmInReplace(len(ficcreporrtIds)) + `)`
  428. pars = append(pars, ficcreporrtIds)
  429. articleList, e := models.GetHomeListPublic(condition, pars, 0, len(ficcreporrtIds))
  430. if e != nil {
  431. err = errors.New("GetHomeListPublic, Err: " + e.Error())
  432. return
  433. }
  434. articleList, e = HandleArticleCategoryImg(articleList, user)
  435. if e != nil {
  436. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  437. return
  438. }
  439. for _, v := range articleList {
  440. v.Body = ""
  441. mapItems[fmt.Sprint("ficcreport", v.ReportId)].FiccReport = v
  442. }
  443. }
  444. for _, vList := range list {
  445. for _, v := range mapItems {
  446. //如果这些类型都为空,那么就不合并
  447. 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 && v.FiccReport == nil {
  448. continue
  449. }
  450. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  451. items = append(items, v)
  452. }
  453. }
  454. }
  455. return
  456. }