resource_data.go 16 KB

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