resource_data.go 17 KB

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