es_comprehensive.go 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "hongze/hongze_clpt/models"
  7. "hongze/hongze_clpt/utils"
  8. "strconv"
  9. //"strconv"
  10. "errors"
  11. "strings"
  12. "time"
  13. )
  14. type SearchComprehensiveItem struct {
  15. SourceId int `description:"资源ID"`
  16. IsSummary int `description:"是否是纪要"`
  17. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior"`
  18. Title string `description:"标题"`
  19. BodyText string `description:"内容"`
  20. PublishDate string `description:"发布时间"`
  21. Abstract string `description:"摘要"`
  22. Annotation string `description:"核心观点"`
  23. IndustryName string `description:"产业名称"`
  24. SubjectNames string `description:"标的名称"`
  25. Body []string
  26. }
  27. type ElasticComprehensiveDetail struct {
  28. SourceId int `description:"资源ID"`
  29. IsSummary int `description:"是否是纪要"`
  30. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior 、 产业资源包:industrialsource"`
  31. Title string `description:"标题"`
  32. BodyText string `description:"内容"`
  33. PublishDate string `description:"发布时间"`
  34. Abstract string `description:"摘要"`
  35. Annotation string `description:"核心观点"`
  36. IndustryName string `description:"产业名称"`
  37. SubjectNames string `description:"标的名称"`
  38. }
  39. func EsComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int64, err error) {
  40. indexName := utils.IndexNameComprehensive
  41. client := utils.Client
  42. keyWordArr, err := GetIndustryMapNameSliceV3(keyWord)
  43. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  44. keyWordLen := len(keyWordArr)
  45. if keyWordLen <= 0 {
  46. keyWordArr = append(keyWordArr, keyWord)
  47. keyWordLen = len(keyWordArr)
  48. }
  49. fmt.Println(keyWordArr)
  50. //Es 的高级查询有 自定义排序 文档一时半会儿撸不懂,先做多次查询手动过滤 2023.2.2
  51. //ikType 查询方式 ,0:查所有 、 1:查询键入词 、 2:查询除了查询键入词之外的联想词
  52. mustMap := make([]interface{}, 0)
  53. shouldMap := make(map[string]interface{}, 0)
  54. shouldMapquery := make([]interface{}, 0)
  55. mustNotMap := make([]interface{}, 0)
  56. shouldNotMap := make(map[string]interface{}, 0)
  57. shouldNotMapquery := make([]interface{}, 0)
  58. // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
  59. //keyWordWeight := GetWeight(keyWordLen)
  60. var boost int
  61. //lenkeyWordArr := len(keyWordArr)
  62. for k, v := range keyWordArr {
  63. if k > 0 {
  64. continue
  65. }
  66. if k == 0 {
  67. boost = 2 * 1000
  68. } else {
  69. boost = 1
  70. }
  71. if v != "" {
  72. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  73. "function_score": map[string]interface{}{
  74. "query": map[string]interface{}{
  75. "multi_match": map[string]interface{}{
  76. //"boost": (lenkeyWordArr - k) * boost, //给查询的值赋予权重
  77. "boost": boost, //给查询的值赋予权重
  78. "fields": []interface{}{"Title"},
  79. "query": v,
  80. },
  81. },
  82. },
  83. })
  84. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  85. "function_score": map[string]interface{}{
  86. "query": map[string]interface{}{
  87. "multi_match": map[string]interface{}{
  88. "boost": boost, //给查询的值赋予权重
  89. "fields": []interface{}{"Abstract"},
  90. "query": v,
  91. },
  92. },
  93. },
  94. })
  95. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  96. "function_score": map[string]interface{}{
  97. "query": map[string]interface{}{
  98. "multi_match": map[string]interface{}{
  99. "boost": boost, //给查询的值赋予权重
  100. "fields": []interface{}{"Annotation"},
  101. "query": v,
  102. },
  103. },
  104. },
  105. })
  106. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  107. "function_score": map[string]interface{}{
  108. "query": map[string]interface{}{
  109. "multi_match": map[string]interface{}{
  110. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  111. "boost": boost, //给查询的值赋予权重
  112. "fields": []interface{}{"BodyText"},
  113. "query": v,
  114. },
  115. },
  116. },
  117. })
  118. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  119. "function_score": map[string]interface{}{
  120. "query": map[string]interface{}{
  121. "multi_match": map[string]interface{}{
  122. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  123. "boost": boost, //给查询的值赋予权重
  124. "fields": []interface{}{"IndustryName"},
  125. "query": v,
  126. },
  127. },
  128. },
  129. })
  130. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  131. "function_score": map[string]interface{}{
  132. "query": map[string]interface{}{
  133. "multi_match": map[string]interface{}{
  134. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  135. "boost": boost, //给查询的值赋予权重
  136. "fields": []interface{}{"SubjectNames"},
  137. "query": v,
  138. },
  139. },
  140. },
  141. })
  142. }
  143. }
  144. shouldMap = map[string]interface{}{
  145. "should": shouldMapquery,
  146. }
  147. shouldNotMap = map[string]interface{}{
  148. "should": shouldNotMapquery,
  149. }
  150. //排序
  151. sortMap := make([]interface{}, 0)
  152. //时间
  153. sortMap = append(sortMap, map[string]interface{}{
  154. "PublishDate": map[string]interface{}{
  155. "order": "desc",
  156. },
  157. })
  158. //sortMap = append(sortMap, map[string]interface{}{
  159. // "_score": map[string]interface{}{
  160. // "order": "desc",
  161. // },
  162. //})
  163. //高亮
  164. highlightMap := make(map[string]interface{}, 0)
  165. highlightMap = map[string]interface{}{
  166. "fields": map[string]interface{}{
  167. "BodyText": map[string]interface{}{},
  168. "Title": map[string]interface{}{},
  169. "Abstract": map[string]interface{}{},
  170. "Annotation": map[string]interface{}{},
  171. },
  172. //样式 红色
  173. "post_tags": []interface{}{"</font>"},
  174. "pre_tags": []interface{}{"<font color='red'>"},
  175. "fragment_size": 50,
  176. }
  177. mustMap = append(mustMap, map[string]interface{}{
  178. "bool": shouldMap,
  179. })
  180. mustNotMap = append(mustNotMap, map[string]interface{}{
  181. "bool": shouldNotMap,
  182. })
  183. queryMap := map[string]interface{}{
  184. "query": map[string]interface{}{
  185. "bool": map[string]interface{}{
  186. "must": mustMap,
  187. },
  188. },
  189. }
  190. queryMap["sort"] = sortMap
  191. queryMap["from"] = startSize
  192. queryMap["size"] = pageSize
  193. queryMap["highlight"] = highlightMap
  194. jsonBytes, _ := json.Marshal(queryMap)
  195. fmt.Println(string(jsonBytes))
  196. //utils.FileLog.Info(string(jsonBytes))
  197. request := client.Search(indexName).Source(queryMap) // sets the JSON request
  198. searchByMatch, err := request.Do(context.Background())
  199. if searchByMatch != nil {
  200. if searchByMatch.Hits != nil {
  201. for _, v := range searchByMatch.Hits.Hits {
  202. var isAppend bool
  203. articleJson, err := v.Source.MarshalJSON()
  204. if err != nil {
  205. return nil, 0, err
  206. }
  207. article := new(ElasticComprehensiveDetail)
  208. err = json.Unmarshal(articleJson, &article)
  209. if err != nil {
  210. return nil, 0, err
  211. }
  212. fmt.Println(article.SourceId, article.Title, article.Source)
  213. searchItem := new(SearchComprehensiveItem)
  214. searchItem.SourceId = article.SourceId
  215. if len(v.Highlight["Annotation"]) > 0 {
  216. for _, vText := range v.Highlight["Annotation"] {
  217. searchItem.Body = append(searchItem.Body, vText)
  218. }
  219. }
  220. if len(v.Highlight["Abstract"]) > 0 {
  221. for _, vText := range v.Highlight["Abstract"] {
  222. searchItem.Body = append(searchItem.Body, vText)
  223. }
  224. }
  225. if len(v.Highlight["BodyText"]) > 0 {
  226. for _, vText := range v.Highlight["BodyText"] {
  227. searchItem.Body = append(searchItem.Body, vText)
  228. }
  229. }
  230. searchItem.IsSummary = article.IsSummary
  231. if len(searchItem.Body) == 0 {
  232. bodyRune := []rune(article.BodyText)
  233. bodyRuneLen := len(bodyRune)
  234. if bodyRuneLen > 100 {
  235. bodyRuneLen = 100
  236. }
  237. body := string(bodyRune[:bodyRuneLen])
  238. searchItem.Body = []string{body}
  239. }
  240. var title string
  241. if len(v.Highlight["Title"]) > 0 {
  242. title = v.Highlight["Title"][0]
  243. } else {
  244. title = article.Title
  245. }
  246. searchItem.Title = title
  247. searchItem.Source = article.Source
  248. searchItem.PublishDate = article.PublishDate
  249. if !isAppend {
  250. result = append(result, searchItem)
  251. }
  252. }
  253. }
  254. total = searchByMatch.Hits.TotalHits.Value
  255. }
  256. return
  257. }
  258. //func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserItem) (items []*models.HomeResourceDataListNewResp, err error) {
  259. // var condition string
  260. // var pars []interface{}
  261. // uid := user.UserId
  262. //
  263. // mapItems := make(map[string]*models.CygxResourceDataNewResp)
  264. // for _, v := range list {
  265. // //预处理文章
  266. // item := new(models.CygxResourceDataNewResp)
  267. // item.SourceId = v.SourceId
  268. // item.Source = v.Source
  269. // if v.IsSummary == 1 {
  270. // item.BodyHeight = v.Body
  271. // } else {
  272. // item.BodyHeight = make([]string, 0)
  273. // }
  274. // item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  275. // mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  276. // }
  277. //
  278. // var articleIds []int
  279. // var newchartIds []int
  280. // var roadshowIds []string
  281. // var activityIds []int
  282. // var activityvideoIds []string
  283. // var activityvoiceIds []string
  284. // var activityspecialIds []int
  285. // var researchsummaryIds []int
  286. // var minutessummaryIds []int
  287. // var meetingreviewchaptIds []int
  288. // var productinteriorIds []int
  289. // var industrialResourceIds []int
  290. // //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt "`
  291. // for _, v := range list {
  292. // if v.Source == "article" {
  293. // articleIds = append(articleIds, v.SourceId)
  294. // } else if v.Source == "newchart" {
  295. // newchartIds = append(newchartIds, v.SourceId)
  296. // } else if v.Source == "roadshow" {
  297. // roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  298. // } else if v.Source == "activity" {
  299. // activityIds = append(activityIds, v.SourceId)
  300. // } else if v.Source == "activityvideo" {
  301. // activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  302. // } else if v.Source == "activityvoice" {
  303. // activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  304. // } else if v.Source == "activityspecial" {
  305. // activityspecialIds = append(activityspecialIds, v.SourceId)
  306. // } else if v.Source == "researchsummary" {
  307. // researchsummaryIds = append(researchsummaryIds, v.SourceId)
  308. // } else if v.Source == "minutessummary" {
  309. // minutessummaryIds = append(minutessummaryIds, v.SourceId)
  310. // } else if v.Source == "meetingreviewchapt" {
  311. // meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  312. // } else if v.Source == "productinterior" {
  313. // productinteriorIds = append(productinteriorIds, v.SourceId)
  314. // } else if v.Source == "industrialsource" {
  315. // industrialResourceIds = append(industrialResourceIds, v.SourceId)
  316. // }
  317. //
  318. // }
  319. // //处理文章
  320. // if len(articleIds) > 0 {
  321. // pars = make([]interface{}, 0)
  322. // condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  323. // pars = append(pars, articleIds)
  324. //
  325. // listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
  326. // if e != nil {
  327. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  328. // return
  329. // }
  330. //
  331. // listArticle, e = HandleArticleCategoryImg(listArticle)
  332. // if e != nil {
  333. // err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  334. // return
  335. // }
  336. // for _, v := range listArticle {
  337. // v.Body = ""
  338. // v.BodyHtml = ""
  339. // mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  340. // }
  341. // }
  342. //
  343. // //处理晨会精华
  344. // if len(meetingreviewchaptIds) > 0 {
  345. // pars = make([]interface{}, 0)
  346. // condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  347. // pars = append(pars, meetingreviewchaptIds)
  348. //
  349. // listrMeet, e := models.GetCygxMorningMeetingReviewChapterList(condition, pars)
  350. // if e != nil {
  351. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  352. // return
  353. // }
  354. // for _, v := range listrMeet {
  355. // v.Content = AnnotationHtml(v.Content)
  356. // v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  357. // mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  358. // }
  359. // }
  360. //
  361. // //处理上周纪要汇总
  362. // if len(minutessummaryIds) > 0 {
  363. // pars = make([]interface{}, 0)
  364. // condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  365. // pars = append(pars, minutessummaryIds)
  366. //
  367. // listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  368. // if e != nil {
  369. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  370. // return
  371. // }
  372. // for _, v := range listresearchsummary {
  373. // v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  374. // mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  375. // }
  376. // }
  377. //
  378. // //处理本周纪要汇总
  379. // if len(researchsummaryIds) > 0 {
  380. // pars = make([]interface{}, 0)
  381. // condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  382. // pars = append(pars, researchsummaryIds)
  383. //
  384. // listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  385. // if e != nil {
  386. // err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  387. // return
  388. // }
  389. // for _, v := range listresearchsummary {
  390. // v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  391. // mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  392. // }
  393. // }
  394. //
  395. // //处理产品内测
  396. // if len(productinteriorIds) > 0 {
  397. // pars = make([]interface{}, 0)
  398. // condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  399. // pars = append(pars, productinteriorIds)
  400. // listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  401. // if e != nil {
  402. // err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  403. // return
  404. // }
  405. // for _, v := range listProductInterior {
  406. // v.Body = ProductInteriorHtml(v.Body)
  407. // v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  408. // mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  409. // }
  410. // }
  411. //
  412. // detail, e := models.GetConfigByCode("city_img_url")
  413. // if e != nil {
  414. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  415. // return
  416. // }
  417. // detailChart, e := models.GetConfigByCode("chart_img_url")
  418. // if e != nil {
  419. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  420. // return
  421. // }
  422. // addressList := strings.Split(detail.ConfigValue, "{|}")
  423. // mapAddress := make(map[string]string)
  424. // chartList := strings.Split(detailChart.ConfigValue, "{|}")
  425. // mapChart := make(map[string]string)
  426. // var cityName string
  427. // var chartName string
  428. // var imgUrl string
  429. // var imgUrlChart string
  430. // for _, v := range addressList {
  431. // vslice := strings.Split(v, "_")
  432. // cityName = vslice[0]
  433. // imgUrl = vslice[len(vslice)-1]
  434. // mapAddress[cityName] = imgUrl
  435. // }
  436. // for _, v := range chartList {
  437. // vslice := strings.Split(v, "_")
  438. // chartName = vslice[0]
  439. // imgUrlChart = vslice[len(vslice)-1]
  440. // mapChart[chartName] = imgUrlChart
  441. // }
  442. // var imgUrlResp string
  443. // fmt.Println(activityIds)
  444. // //处理活动
  445. // if len(activityIds) > 0 {
  446. // for _, vss := range activityIds {
  447. // imgUrlResp += strconv.Itoa(vss) + ","
  448. // }
  449. // pars = make([]interface{}, 0)
  450. // condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
  451. // pars = append(pars, activityIds)
  452. // activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  453. // if e != nil {
  454. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  455. // return
  456. // }
  457. // //处理不同的报名方式按钮回显
  458. // mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  459. // if e != nil {
  460. // e = errors.New("GetActivitySignupResp, Err: " + e.Error())
  461. // return
  462. // }
  463. //
  464. // var activityListRersp []*models.ActivityDetail
  465. // for _, v := range activityList {
  466. // v.SignupType = mapActivitySignup[v.ActivityId]
  467. // activityListRersp = append(activityListRersp, ActivityButtonShow(v))
  468. // }
  469. // for _, v := range activityListRersp {
  470. // if v == nil {
  471. // continue
  472. // }
  473. // if v.ActivityType == 0 {
  474. // if mapAddress[v.City] != "" {
  475. // imgUrlResp = mapAddress[v.City]
  476. // } else {
  477. // imgUrlResp = mapAddress["其它"]
  478. // }
  479. // } else {
  480. // if mapChart[v.ChartPermissionName] != "" {
  481. // imgUrlResp = mapChart[v.ChartPermissionName]
  482. // }
  483. // }
  484. // v.SourceType = 1
  485. // v.Expert, _ = GetReportContentTextSub(v.Expert)
  486. // mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  487. // }
  488. // }
  489. //
  490. // //产业资源包
  491. // if len(industrialResourceIds) > 0 {
  492. // pars = make([]interface{}, 0)
  493. //
  494. // var industrialResourceIdstring []string
  495. // for _, v := range industrialResourceIds {
  496. // industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  497. // }
  498. // industrialId := strings.Join(industrialResourceIdstring, ",")
  499. // condition = ` AND m.industrial_management_id IN (` + industrialId + `) `
  500. // listIndustrialResourceIds, e := models.GetSearchResourceList(user.UserId, condition, 0, len(industrialResourceIds))
  501. // if e != nil {
  502. // err = errors.New("GetSearchResourceList, Err: " + e.Error())
  503. // return
  504. // }
  505. // //合并产业关联的标的
  506. // listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(industrialResourceIds)
  507. // if e != nil {
  508. // e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  509. // return
  510. // }
  511. // mapIndustrial := make(map[string]int)
  512. // for _, v := range listSubjcet {
  513. // for k2, v2 := range listIndustrialResourceIds {
  514. // if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Yx", v.SubjectName)] == 0 {
  515. // listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  516. // }
  517. // }
  518. // }
  519. // for _, v := range listIndustrialResourceIds {
  520. // mapItems[fmt.Sprint("industrialsource", v.IndustrialManagementId)].IndustrialResource = v
  521. // }
  522. // }
  523. //
  524. // //处理图表
  525. // if len(newchartIds) > 0 {
  526. // pars = make([]interface{}, 0)
  527. // condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  528. // pars = append(pars, newchartIds)
  529. // chartDateList, e := models.GetChartListCollectionNew(condition, pars, uid, 0, len(newchartIds))
  530. // if e != nil {
  531. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  532. // return
  533. // }
  534. // for _, v := range chartDateList {
  535. // mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  536. // }
  537. // }
  538. //
  539. // //处理专项调研
  540. // if len(activityspecialIds) > 0 {
  541. // pars = make([]interface{}, 0)
  542. // condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  543. // pars = append(pars, activityspecialIds)
  544. // activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  545. // if e != nil {
  546. // err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  547. // return
  548. // }
  549. // UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  550. // if e != nil {
  551. // err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  552. // return
  553. // }
  554. // for _, v := range activitySpeciallist {
  555. // if mapChart[v.ChartPermissionName] != "" {
  556. // imgUrlResp = mapChart[v.ChartPermissionName]
  557. // }
  558. // if _, ok := UserMap[v.ActivityId]; ok {
  559. // v.IsTrip = 1
  560. // }
  561. // if v.Days == 0 {
  562. // v.TripStatus = 1
  563. // v.TripImgLink = v.TripImgLink
  564. // } else {
  565. // v.TripStatus = 2
  566. // v.TripImgLink = v.TripImgLinkFix
  567. // v.ActivityTimeText = v.ActivityTimeTextByDay
  568. // }
  569. // resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  570. // resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  571. // if resultTimeStart.After(time.Now()) {
  572. // v.ActiveState = 1
  573. // } else if time.Now().After(resultTimeEnd) {
  574. // v.ActiveState = 3
  575. // } else {
  576. // v.ActiveState = 2
  577. // }
  578. // v.ImgUrl = imgUrlResp
  579. // mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  580. //
  581. // }
  582. // }
  583. //
  584. // if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds) > 0 {
  585. //
  586. // audioIdstr := strings.Join(activityvoiceIds, ",")
  587. // ideoIdsStr := strings.Join(roadshowIds, ",")
  588. // activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  589. //
  590. // list, _, e := GetMicroRoadShowMycollect(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds), 0, audioIdstr, ideoIdsStr, activityVideoIdsStr)
  591. // if e != nil {
  592. // err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
  593. // return
  594. // }
  595. //
  596. // for _, item := range list {
  597. // if item.Type == 1 {
  598. // //音频
  599. // count, e := models.GetVoiceCollectCount(user.UserId, item.Id)
  600. // if e != nil {
  601. // err = errors.New("GetVoiceCollectCount, Err: " + e.Error())
  602. // return
  603. // }
  604. // if count > 0 {
  605. // item.IsCollect = true
  606. // }
  607. // } else if item.Type == 2 {
  608. // //活动视频
  609. // count, e := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  610. // if e != nil {
  611. // err = errors.New("GetActivityVideoCollectCount, Err: " + e.Error())
  612. // return
  613. // }
  614. // if count > 0 {
  615. // item.IsCollect = true
  616. // }
  617. // } else if item.Type == 3 {
  618. // //微路演视频
  619. // count, e := models.GetVideoCollectCount(user.UserId, item.Id)
  620. // if e != nil {
  621. // err = errors.New("GetVideoCollectCount, Err: " + e.Error())
  622. // return
  623. // }
  624. // if count > 0 {
  625. // item.IsCollect = true
  626. // }
  627. // }
  628. // }
  629. // // 用户权限
  630. // authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  631. // if e != nil {
  632. // err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  633. // return
  634. // }
  635. //
  636. // // 获取默认图配置
  637. // audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  638. // if e != nil {
  639. // err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  640. // return
  641. // }
  642. // //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  643. // for i := range list {
  644. // // 权限
  645. // au := new(models.UserPermissionAuthInfo)
  646. // au.SellerName = authInfo.SellerName
  647. // au.SellerMobile = authInfo.SellerMobile
  648. // au.HasPermission = authInfo.HasPermission
  649. // au.OperationMode = authInfo.OperationMode
  650. // if au.HasPermission == 1 {
  651. // // 非宏观权限进一步判断是否有权限
  652. // if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  653. // au.HasPermission = 2
  654. // }
  655. // }
  656. // // 无权限的弹框提示
  657. // if au.HasPermission != 1 {
  658. // if au.OperationMode == UserPermissionOperationModeCall {
  659. // if list[i].Type == 1 {
  660. // au.PopupMsg = UserPermissionPopupMsgCallActivity
  661. // } else {
  662. // au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  663. // }
  664. // } else {
  665. // if list[i].Type == 1 {
  666. // au.PopupMsg = UserPermissionPopupMsgApplyActivity
  667. // } else {
  668. // au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  669. // }
  670. // }
  671. // }
  672. // list[i].AuthInfo = au
  673. // list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  674. // // 默认图
  675. // if list[i].BackgroundImg == "" {
  676. // if list[i].Type == 1 {
  677. // list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  678. // } else {
  679. // list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  680. // }
  681. // }
  682. // // 分享图
  683. // if list[i].ShareImg == "" {
  684. // if list[i].Type == 1 {
  685. // list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  686. // } else {
  687. // list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  688. // }
  689. // }
  690. // }
  691. // //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  692. // for _, item := range list {
  693. // if item.Type == 1 {
  694. // mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  695. // } else if item.Type == 2 {
  696. // mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  697. // } else if item.Type == 3 {
  698. // mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  699. // }
  700. // }
  701. // }
  702. //
  703. // for _, vList := range list {
  704. // for _, v := range mapItems {
  705. // if v.SourceId == vList.SourceId {
  706. // items = append(items, v)
  707. // }
  708. // }
  709. // }
  710. // return
  711. //}
  712. func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserItem) (items []*models.CygxResourceDataNewResp, err error) {
  713. var condition string
  714. var pars []interface{}
  715. uid := user.UserId
  716. titleHighlight := make(map[int]string)
  717. bodyHighlight := make(map[int][]string)
  718. mapItems := make(map[string]*models.CygxResourceDataNewResp)
  719. for _, v := range list {
  720. //预处理文章
  721. item := new(models.CygxResourceDataNewResp)
  722. item.SourceId = v.SourceId
  723. item.Source = v.Source
  724. item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  725. if v.IsSummary == 1 {
  726. item.BodyHighlight = v.Body
  727. titleHighlight[v.SourceId] = v.Title
  728. bodyHighlight[v.SourceId] = v.Body
  729. //fmt.Println(v.Title)
  730. } else {
  731. item.BodyHighlight = make([]string, 0)
  732. }
  733. mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  734. }
  735. var articleIds []int //报告
  736. var newchartIds []int //图表
  737. var roadshowIds []string //微路演
  738. var activityIds []int //活动
  739. var activityvideoIds []string // 活动视频
  740. var activityvoiceIds []string //活动音频
  741. var activityspecialIds []int //专项调研活动
  742. var researchsummaryIds []int //本周研究汇总
  743. var minutessummaryIds []int //上周纪要汇总
  744. var meetingreviewchaptIds []int //晨会精华
  745. var productinteriorIds []int //产品内测
  746. var industrialResourceIds []int // 产业资源包
  747. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior
  748. for _, v := range list {
  749. if v.Source == "article" {
  750. articleIds = append(articleIds, v.SourceId)
  751. } else if v.Source == "newchart" {
  752. newchartIds = append(newchartIds, v.SourceId)
  753. } else if v.Source == "roadshow" {
  754. roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  755. } else if v.Source == "activity" {
  756. activityIds = append(activityIds, v.SourceId)
  757. } else if v.Source == "activityvideo" {
  758. activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  759. } else if v.Source == "activityvoice" {
  760. activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  761. } else if v.Source == "activityspecial" {
  762. activityspecialIds = append(activityspecialIds, v.SourceId)
  763. } else if v.Source == "researchsummary" {
  764. researchsummaryIds = append(researchsummaryIds, v.SourceId)
  765. } else if v.Source == "minutessummary" {
  766. minutessummaryIds = append(minutessummaryIds, v.SourceId)
  767. } else if v.Source == "meetingreviewchapt" {
  768. meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  769. } else if v.Source == "productinterior" {
  770. productinteriorIds = append(productinteriorIds, v.SourceId)
  771. } else if v.Source == "industrialsource" {
  772. industrialResourceIds = append(industrialResourceIds, v.SourceId)
  773. }
  774. }
  775. detail, e := models.GetConfigByCode("city_img_url")
  776. if e != nil {
  777. err = errors.New("GetResourceDataList, Err: " + e.Error())
  778. return
  779. }
  780. detailChart, e := models.GetConfigByCode("chart_img_url")
  781. if e != nil {
  782. err = errors.New("GetResourceDataList, Err: " + e.Error())
  783. return
  784. }
  785. addressList := strings.Split(detail.ConfigValue, "{|}")
  786. mapAddress := make(map[string]string)
  787. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  788. mapChart := make(map[string]string)
  789. var cityName string
  790. var chartName string
  791. var imgUrl string
  792. var imgUrlChart string
  793. for _, v := range addressList {
  794. vslice := strings.Split(v, "_")
  795. cityName = vslice[0]
  796. imgUrl = vslice[len(vslice)-1]
  797. mapAddress[cityName] = imgUrl
  798. }
  799. for _, v := range chartList {
  800. vslice := strings.Split(v, "_")
  801. chartName = vslice[0]
  802. imgUrlChart = vslice[len(vslice)-1]
  803. mapChart[chartName] = imgUrlChart
  804. }
  805. var imgUrlResp string
  806. //处理文章
  807. if len(articleIds) > 0 {
  808. pars = make([]interface{}, 0)
  809. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  810. pars = append(pars, articleIds)
  811. articleList, e := models.GetHomeListPublic(condition, pars, 0, len(articleIds))
  812. if e != nil {
  813. err = errors.New("GetResourceDataList, Err: " + e.Error())
  814. return
  815. }
  816. articleList, e = HandleArticleCategoryImg(articleList, user)
  817. if e != nil {
  818. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  819. return
  820. }
  821. for _, v := range articleList {
  822. v.Body = ""
  823. if titleHighlight[v.ArticleId] != "" {
  824. v.Title = titleHighlight[v.ArticleId]
  825. }
  826. if len(bodyHighlight[v.ArticleId]) > 0 {
  827. v.Abstract = ""
  828. v.Annotation = ""
  829. v.BodyHighlight = bodyHighlight[v.ArticleId]
  830. }
  831. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  832. }
  833. }
  834. //处理晨会精华
  835. if len(meetingreviewchaptIds) > 0 {
  836. pars = make([]interface{}, 0)
  837. condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  838. pars = append(pars, meetingreviewchaptIds)
  839. listrMeet, e := models.GetCygxMorningMeetingReviewChapterList(condition, pars)
  840. if e != nil {
  841. err = errors.New("GetResourceDataList, Err: " + e.Error())
  842. return
  843. }
  844. for _, v := range listrMeet {
  845. v.Content = AnnotationHtml(v.Content)
  846. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  847. mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  848. }
  849. }
  850. //处理上周纪要汇总
  851. if len(minutessummaryIds) > 0 {
  852. pars = make([]interface{}, 0)
  853. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  854. pars = append(pars, minutessummaryIds)
  855. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  856. if e != nil {
  857. err = errors.New("GetResourceDataList, Err: " + e.Error())
  858. return
  859. }
  860. for _, v := range listresearchsummary {
  861. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  862. mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  863. }
  864. }
  865. //处理本周纪要汇总
  866. if len(researchsummaryIds) > 0 {
  867. pars = make([]interface{}, 0)
  868. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  869. pars = append(pars, researchsummaryIds)
  870. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  871. if e != nil {
  872. err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  873. return
  874. }
  875. for _, v := range listresearchsummary {
  876. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  877. mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  878. }
  879. }
  880. //处理产品内测
  881. if len(productinteriorIds) > 0 {
  882. pars = make([]interface{}, 0)
  883. condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  884. pars = append(pars, productinteriorIds)
  885. listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  886. if e != nil {
  887. err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  888. return
  889. }
  890. for _, v := range listProductInterior {
  891. v.Body = ProductInteriorHtml(v.Body)
  892. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  893. mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  894. }
  895. }
  896. //处理活动
  897. if len(activityIds) > 0 {
  898. for _, vss := range activityIds {
  899. imgUrlResp += strconv.Itoa(vss) + ","
  900. }
  901. pars = make([]interface{}, 0)
  902. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  903. pars = append(pars, activityIds)
  904. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  905. if e != nil {
  906. err = errors.New("GetResourceDataList, Err: " + e.Error())
  907. return
  908. }
  909. var activityListRersp []*models.ActivityListResp
  910. for _, v := range activityList {
  911. activityListRersp = append(activityListRersp, ActivityButtonShow(v, user, make([]string, 0)))
  912. }
  913. //处理不同的报名方式按钮回显
  914. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  915. if e != nil {
  916. err = errors.New("GetActivitySignupResp, Err: " + e.Error())
  917. return
  918. }
  919. for _, v := range activityListRersp {
  920. if v == nil {
  921. continue
  922. }
  923. if v.ActivityType == 0 {
  924. if mapAddress[v.City] != "" {
  925. imgUrlResp = mapAddress[v.City]
  926. } else {
  927. imgUrlResp = mapAddress["其它"]
  928. }
  929. } else {
  930. if mapChart[v.ChartPermissionName] != "" {
  931. imgUrlResp = mapChart[v.ChartPermissionName]
  932. }
  933. }
  934. v.ImgUrl = imgUrlResp
  935. v.SourceType = mapActivitySignup[v.ActivityId]
  936. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  937. }
  938. }
  939. //产业资源包
  940. if len(industrialResourceIds) > 0 {
  941. pars = make([]interface{}, 0)
  942. var industrialResourceIdstring []string
  943. for _, v := range industrialResourceIds {
  944. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  945. }
  946. industrialId := strings.Join(industrialResourceIdstring, ",")
  947. condition = ` AND m.industrial_management_id IN (` + industrialId + `) `
  948. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  949. if e != nil {
  950. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  951. return
  952. }
  953. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIds)) + `)`
  954. pars = append(pars, industrialResourceIds)
  955. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  956. //合并产业关联的标的
  957. if e != nil {
  958. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  959. return
  960. }
  961. mapIndustrial := make(map[string]int)
  962. for _, v := range listSubjcet {
  963. for k2, v2 := range listIndustrialResourceIds {
  964. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Yx", v.SubjectName)] == 0 {
  965. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  966. }
  967. }
  968. }
  969. for _, v := range listIndustrialResourceIds {
  970. mapItems[fmt.Sprint("industrialsource", v.IndustrialManagementId)].IndustrialResource = v
  971. }
  972. }
  973. //处理图表
  974. if len(newchartIds) > 0 {
  975. pars = make([]interface{}, 0)
  976. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  977. pars = append(pars, newchartIds)
  978. chartDateList, e := models.GetChartListCollection(condition, pars, uid, 0, len(newchartIds))
  979. if e != nil {
  980. err = errors.New("GetResourceDataList, Err: " + e.Error())
  981. return
  982. }
  983. for _, v := range chartDateList {
  984. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  985. }
  986. }
  987. //处理专项调研
  988. if len(activityspecialIds) > 0 {
  989. pars = make([]interface{}, 0)
  990. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  991. pars = append(pars, activityspecialIds)
  992. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  993. if e != nil {
  994. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  995. return
  996. }
  997. UserMap, e := GetSpecialTripUserMap(activityspecialIds, user.UserId)
  998. if e != nil {
  999. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  1000. return
  1001. }
  1002. for _, v := range activitySpeciallist {
  1003. if mapChart[v.ChartPermissionName] != "" {
  1004. imgUrlResp = mapChart[v.ChartPermissionName]
  1005. }
  1006. if _, ok := UserMap[v.ActivityId]; ok {
  1007. v.IsTrip = 1
  1008. }
  1009. if v.Days == 0 {
  1010. v.TripStatus = 1
  1011. v.TripImgLink = v.TripImgLink
  1012. } else {
  1013. v.TripStatus = 2
  1014. v.TripImgLink = v.TripImgLinkFix
  1015. v.ActivityTimeText = v.ActivityTimeTextByDay
  1016. }
  1017. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  1018. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  1019. if resultTimeStart.After(time.Now()) {
  1020. v.ActiveState = "1"
  1021. } else if time.Now().After(resultTimeEnd) {
  1022. v.ActiveState = "3"
  1023. } else {
  1024. v.ActiveState = "2"
  1025. }
  1026. v.ImgUrl = imgUrlResp
  1027. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  1028. }
  1029. }
  1030. //处理路演 处理路活动视频 处理路活音频
  1031. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds) > 0 {
  1032. audioIdstr := strings.Join(activityvoiceIds, ",")
  1033. ideoIdsStr := strings.Join(roadshowIds, ",")
  1034. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  1035. list, _, e := GetMicroRoadShowMycollect(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds), 0, audioIdstr, ideoIdsStr, activityVideoIdsStr)
  1036. if e != nil {
  1037. err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
  1038. return
  1039. }
  1040. for _, item := range list {
  1041. if item.Type == 1 {
  1042. //音频
  1043. count, e := models.GetVoiceCollectCount(user.UserId, item.Id)
  1044. if e != nil {
  1045. err = errors.New("GetVoiceCollectCount, Err: " + e.Error())
  1046. return
  1047. }
  1048. if count > 0 {
  1049. item.IsCollect = true
  1050. }
  1051. } else if item.Type == 2 {
  1052. //活动视频
  1053. count, e := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  1054. if e != nil {
  1055. err = errors.New("GetActivityVideoCollectCount, Err: " + e.Error())
  1056. return
  1057. }
  1058. if count > 0 {
  1059. item.IsCollect = true
  1060. }
  1061. } else if item.Type == 3 {
  1062. //微路演视频
  1063. count, e := models.GetVideoCollectCount(user.UserId, item.Id)
  1064. if e != nil {
  1065. err = errors.New("GetVideoCollectCount, Err: " + e.Error())
  1066. return
  1067. }
  1068. if count > 0 {
  1069. item.IsCollect = true
  1070. }
  1071. }
  1072. }
  1073. // 用户权限
  1074. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  1075. if e != nil {
  1076. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  1077. return
  1078. }
  1079. // 获取默认图配置
  1080. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  1081. if e != nil {
  1082. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  1083. return
  1084. }
  1085. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  1086. for i := range list {
  1087. // 权限
  1088. au := new(models.UserPermissionAuthInfo)
  1089. au.SellerName = authInfo.SellerName
  1090. au.SellerMobile = authInfo.SellerMobile
  1091. au.HasPermission = authInfo.HasPermission
  1092. au.OperationMode = authInfo.OperationMode
  1093. if au.HasPermission == 1 {
  1094. // 非宏观权限进一步判断是否有权限
  1095. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  1096. au.HasPermission = 2
  1097. }
  1098. }
  1099. // 无权限的弹框提示
  1100. if au.HasPermission != 1 {
  1101. if au.OperationMode == UserPermissionOperationModeCall {
  1102. if list[i].Type == 1 {
  1103. au.PopupMsg = UserPermissionPopupMsgCallActivity
  1104. } else {
  1105. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  1106. }
  1107. } else {
  1108. if list[i].Type == 1 {
  1109. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  1110. } else {
  1111. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  1112. }
  1113. }
  1114. }
  1115. list[i].AuthInfo = au
  1116. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  1117. // 默认图
  1118. if list[i].BackgroundImg == "" {
  1119. if list[i].Type == 1 {
  1120. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  1121. } else {
  1122. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  1123. }
  1124. }
  1125. // 分享图
  1126. if list[i].ShareImg == "" {
  1127. if list[i].Type == 1 {
  1128. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  1129. } else {
  1130. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  1131. }
  1132. }
  1133. }
  1134. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  1135. for _, item := range list {
  1136. if item.Type == 1 {
  1137. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  1138. } else if item.Type == 2 {
  1139. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  1140. } else if item.Type == 3 {
  1141. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  1142. }
  1143. }
  1144. }
  1145. for _, vList := range list {
  1146. for _, v := range mapItems {
  1147. //如果这些类型都为空,那么就不合并
  1148. 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 {
  1149. continue
  1150. }
  1151. if v.SourceId == vList.SourceId {
  1152. items = append(items, v)
  1153. }
  1154. }
  1155. }
  1156. return
  1157. }