resource_data.go 17 KB

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