es_comprehensive.go 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  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. if len(searchItem.Body) == 0 {
  231. bodyRune := []rune(article.BodyText)
  232. bodyRuneLen := len(bodyRune)
  233. if bodyRuneLen > 100 {
  234. bodyRuneLen = 100
  235. }
  236. body := string(bodyRune[:bodyRuneLen])
  237. searchItem.Body = []string{body}
  238. }
  239. var title string
  240. if len(v.Highlight["Title"]) > 0 {
  241. title = v.Highlight["Title"][0]
  242. } else {
  243. title = article.Title
  244. }
  245. searchItem.Title = title
  246. searchItem.Source = article.Source
  247. searchItem.PublishDate = article.PublishDate
  248. if !isAppend {
  249. result = append(result, searchItem)
  250. }
  251. }
  252. }
  253. total = searchByMatch.Hits.TotalHits.Value
  254. }
  255. return
  256. }
  257. //func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserItem) (items []*models.HomeResourceDataListNewResp, err error) {
  258. // var condition string
  259. // var pars []interface{}
  260. // uid := user.UserId
  261. //
  262. // mapItems := make(map[string]*models.CygxResourceDataNewResp)
  263. // for _, v := range list {
  264. // //预处理文章
  265. // item := new(models.CygxResourceDataNewResp)
  266. // item.SourceId = v.SourceId
  267. // item.Source = v.Source
  268. // if v.IsSummary == 1 {
  269. // item.BodyHeight = v.Body
  270. // } else {
  271. // item.BodyHeight = make([]string, 0)
  272. // }
  273. // item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  274. // mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  275. // }
  276. //
  277. // var articleIds []int
  278. // var newchartIds []int
  279. // var roadshowIds []string
  280. // var activityIds []int
  281. // var activityvideoIds []string
  282. // var activityvoiceIds []string
  283. // var activityspecialIds []int
  284. // var researchsummaryIds []int
  285. // var minutessummaryIds []int
  286. // var meetingreviewchaptIds []int
  287. // var productinteriorIds []int
  288. // var industrialResourceIds []int
  289. // //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt "`
  290. // for _, v := range list {
  291. // if v.Source == "article" {
  292. // articleIds = append(articleIds, v.SourceId)
  293. // } else if v.Source == "newchart" {
  294. // newchartIds = append(newchartIds, v.SourceId)
  295. // } else if v.Source == "roadshow" {
  296. // roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  297. // } else if v.Source == "activity" {
  298. // activityIds = append(activityIds, v.SourceId)
  299. // } else if v.Source == "activityvideo" {
  300. // activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  301. // } else if v.Source == "activityvoice" {
  302. // activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  303. // } else if v.Source == "activityspecial" {
  304. // activityspecialIds = append(activityspecialIds, v.SourceId)
  305. // } else if v.Source == "researchsummary" {
  306. // researchsummaryIds = append(researchsummaryIds, v.SourceId)
  307. // } else if v.Source == "minutessummary" {
  308. // minutessummaryIds = append(minutessummaryIds, v.SourceId)
  309. // } else if v.Source == "meetingreviewchapt" {
  310. // meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  311. // } else if v.Source == "productinterior" {
  312. // productinteriorIds = append(productinteriorIds, v.SourceId)
  313. // } else if v.Source == "industrialsource" {
  314. // industrialResourceIds = append(industrialResourceIds, v.SourceId)
  315. // }
  316. //
  317. // }
  318. // //处理文章
  319. // if len(articleIds) > 0 {
  320. // pars = make([]interface{}, 0)
  321. // condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  322. // pars = append(pars, articleIds)
  323. //
  324. // listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
  325. // if e != nil {
  326. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  327. // return
  328. // }
  329. //
  330. // listArticle, e = HandleArticleCategoryImg(listArticle)
  331. // if e != nil {
  332. // err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  333. // return
  334. // }
  335. // for _, v := range listArticle {
  336. // v.Body = ""
  337. // v.BodyHtml = ""
  338. // mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  339. // }
  340. // }
  341. //
  342. // //处理晨会精华
  343. // if len(meetingreviewchaptIds) > 0 {
  344. // pars = make([]interface{}, 0)
  345. // condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  346. // pars = append(pars, meetingreviewchaptIds)
  347. //
  348. // listrMeet, e := models.GetCygxMorningMeetingReviewChapterList(condition, pars)
  349. // if e != nil {
  350. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  351. // return
  352. // }
  353. // for _, v := range listrMeet {
  354. // v.Content = AnnotationHtml(v.Content)
  355. // v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  356. // mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  357. // }
  358. // }
  359. //
  360. // //处理上周纪要汇总
  361. // if len(minutessummaryIds) > 0 {
  362. // pars = make([]interface{}, 0)
  363. // condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  364. // pars = append(pars, minutessummaryIds)
  365. //
  366. // listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  367. // if e != nil {
  368. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  369. // return
  370. // }
  371. // for _, v := range listresearchsummary {
  372. // v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  373. // mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  374. // }
  375. // }
  376. //
  377. // //处理本周纪要汇总
  378. // if len(researchsummaryIds) > 0 {
  379. // pars = make([]interface{}, 0)
  380. // condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  381. // pars = append(pars, researchsummaryIds)
  382. //
  383. // listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  384. // if e != nil {
  385. // err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  386. // return
  387. // }
  388. // for _, v := range listresearchsummary {
  389. // v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  390. // mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  391. // }
  392. // }
  393. //
  394. // //处理产品内测
  395. // if len(productinteriorIds) > 0 {
  396. // pars = make([]interface{}, 0)
  397. // condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  398. // pars = append(pars, productinteriorIds)
  399. // listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  400. // if e != nil {
  401. // err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  402. // return
  403. // }
  404. // for _, v := range listProductInterior {
  405. // v.Body = ProductInteriorHtml(v.Body)
  406. // v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  407. // mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  408. // }
  409. // }
  410. //
  411. // detail, e := models.GetConfigByCode("city_img_url")
  412. // if e != nil {
  413. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  414. // return
  415. // }
  416. // detailChart, e := models.GetConfigByCode("chart_img_url")
  417. // if e != nil {
  418. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  419. // return
  420. // }
  421. // addressList := strings.Split(detail.ConfigValue, "{|}")
  422. // mapAddress := make(map[string]string)
  423. // chartList := strings.Split(detailChart.ConfigValue, "{|}")
  424. // mapChart := make(map[string]string)
  425. // var cityName string
  426. // var chartName string
  427. // var imgUrl string
  428. // var imgUrlChart string
  429. // for _, v := range addressList {
  430. // vslice := strings.Split(v, "_")
  431. // cityName = vslice[0]
  432. // imgUrl = vslice[len(vslice)-1]
  433. // mapAddress[cityName] = imgUrl
  434. // }
  435. // for _, v := range chartList {
  436. // vslice := strings.Split(v, "_")
  437. // chartName = vslice[0]
  438. // imgUrlChart = vslice[len(vslice)-1]
  439. // mapChart[chartName] = imgUrlChart
  440. // }
  441. // var imgUrlResp string
  442. // fmt.Println(activityIds)
  443. // //处理活动
  444. // if len(activityIds) > 0 {
  445. // for _, vss := range activityIds {
  446. // imgUrlResp += strconv.Itoa(vss) + ","
  447. // }
  448. // pars = make([]interface{}, 0)
  449. // condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
  450. // pars = append(pars, activityIds)
  451. // activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  452. // if e != nil {
  453. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  454. // return
  455. // }
  456. // //处理不同的报名方式按钮回显
  457. // mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  458. // if e != nil {
  459. // e = errors.New("GetActivitySignupResp, Err: " + e.Error())
  460. // return
  461. // }
  462. //
  463. // var activityListRersp []*models.ActivityDetail
  464. // for _, v := range activityList {
  465. // v.SignupType = mapActivitySignup[v.ActivityId]
  466. // activityListRersp = append(activityListRersp, ActivityButtonShow(v))
  467. // }
  468. // for _, v := range activityListRersp {
  469. // if v == nil {
  470. // continue
  471. // }
  472. // if v.ActivityType == 0 {
  473. // if mapAddress[v.City] != "" {
  474. // imgUrlResp = mapAddress[v.City]
  475. // } else {
  476. // imgUrlResp = mapAddress["其它"]
  477. // }
  478. // } else {
  479. // if mapChart[v.ChartPermissionName] != "" {
  480. // imgUrlResp = mapChart[v.ChartPermissionName]
  481. // }
  482. // }
  483. // v.SourceType = 1
  484. // v.Expert, _ = GetReportContentTextSub(v.Expert)
  485. // mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  486. // }
  487. // }
  488. //
  489. // //产业资源包
  490. // if len(industrialResourceIds) > 0 {
  491. // pars = make([]interface{}, 0)
  492. //
  493. // var industrialResourceIdstring []string
  494. // for _, v := range industrialResourceIds {
  495. // industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  496. // }
  497. // industrialId := strings.Join(industrialResourceIdstring, ",")
  498. // condition = ` AND m.industrial_management_id IN (` + industrialId + `) `
  499. // listIndustrialResourceIds, e := models.GetSearchResourceList(user.UserId, condition, 0, len(industrialResourceIds))
  500. // if e != nil {
  501. // err = errors.New("GetSearchResourceList, Err: " + e.Error())
  502. // return
  503. // }
  504. // //合并产业关联的标的
  505. // listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(industrialResourceIds)
  506. // if e != nil {
  507. // e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  508. // return
  509. // }
  510. // mapIndustrial := make(map[string]int)
  511. // for _, v := range listSubjcet {
  512. // for k2, v2 := range listIndustrialResourceIds {
  513. // if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Yx", v.SubjectName)] == 0 {
  514. // listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  515. // }
  516. // }
  517. // }
  518. // for _, v := range listIndustrialResourceIds {
  519. // mapItems[fmt.Sprint("industrialsource", v.IndustrialManagementId)].IndustrialResource = v
  520. // }
  521. // }
  522. //
  523. // //处理图表
  524. // if len(newchartIds) > 0 {
  525. // pars = make([]interface{}, 0)
  526. // condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  527. // pars = append(pars, newchartIds)
  528. // chartDateList, e := models.GetChartListCollectionNew(condition, pars, uid, 0, len(newchartIds))
  529. // if e != nil {
  530. // err = errors.New("GetResourceDataList, Err: " + e.Error())
  531. // return
  532. // }
  533. // for _, v := range chartDateList {
  534. // mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  535. // }
  536. // }
  537. //
  538. // //处理专项调研
  539. // if len(activityspecialIds) > 0 {
  540. // pars = make([]interface{}, 0)
  541. // condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  542. // pars = append(pars, activityspecialIds)
  543. // activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  544. // if e != nil {
  545. // err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  546. // return
  547. // }
  548. // UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  549. // if e != nil {
  550. // err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  551. // return
  552. // }
  553. // for _, v := range activitySpeciallist {
  554. // if mapChart[v.ChartPermissionName] != "" {
  555. // imgUrlResp = mapChart[v.ChartPermissionName]
  556. // }
  557. // if _, ok := UserMap[v.ActivityId]; ok {
  558. // v.IsTrip = 1
  559. // }
  560. // if v.Days == 0 {
  561. // v.TripStatus = 1
  562. // v.TripImgLink = v.TripImgLink
  563. // } else {
  564. // v.TripStatus = 2
  565. // v.TripImgLink = v.TripImgLinkFix
  566. // v.ActivityTimeText = v.ActivityTimeTextByDay
  567. // }
  568. // resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  569. // resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  570. // if resultTimeStart.After(time.Now()) {
  571. // v.ActiveState = 1
  572. // } else if time.Now().After(resultTimeEnd) {
  573. // v.ActiveState = 3
  574. // } else {
  575. // v.ActiveState = 2
  576. // }
  577. // v.ImgUrl = imgUrlResp
  578. // mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  579. //
  580. // }
  581. // }
  582. //
  583. // if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds) > 0 {
  584. //
  585. // audioIdstr := strings.Join(activityvoiceIds, ",")
  586. // ideoIdsStr := strings.Join(roadshowIds, ",")
  587. // activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  588. //
  589. // list, _, e := GetMicroRoadShowMycollect(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds), 0, audioIdstr, ideoIdsStr, activityVideoIdsStr)
  590. // if e != nil {
  591. // err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
  592. // return
  593. // }
  594. //
  595. // for _, item := range list {
  596. // if item.Type == 1 {
  597. // //音频
  598. // count, e := models.GetVoiceCollectCount(user.UserId, item.Id)
  599. // if e != nil {
  600. // err = errors.New("GetVoiceCollectCount, Err: " + e.Error())
  601. // return
  602. // }
  603. // if count > 0 {
  604. // item.IsCollect = true
  605. // }
  606. // } else if item.Type == 2 {
  607. // //活动视频
  608. // count, e := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  609. // if e != nil {
  610. // err = errors.New("GetActivityVideoCollectCount, Err: " + e.Error())
  611. // return
  612. // }
  613. // if count > 0 {
  614. // item.IsCollect = true
  615. // }
  616. // } else if item.Type == 3 {
  617. // //微路演视频
  618. // count, e := models.GetVideoCollectCount(user.UserId, item.Id)
  619. // if e != nil {
  620. // err = errors.New("GetVideoCollectCount, Err: " + e.Error())
  621. // return
  622. // }
  623. // if count > 0 {
  624. // item.IsCollect = true
  625. // }
  626. // }
  627. // }
  628. // // 用户权限
  629. // authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  630. // if e != nil {
  631. // err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  632. // return
  633. // }
  634. //
  635. // // 获取默认图配置
  636. // audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  637. // if e != nil {
  638. // err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  639. // return
  640. // }
  641. // //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  642. // for i := range list {
  643. // // 权限
  644. // au := new(models.UserPermissionAuthInfo)
  645. // au.SellerName = authInfo.SellerName
  646. // au.SellerMobile = authInfo.SellerMobile
  647. // au.HasPermission = authInfo.HasPermission
  648. // au.OperationMode = authInfo.OperationMode
  649. // if au.HasPermission == 1 {
  650. // // 非宏观权限进一步判断是否有权限
  651. // if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  652. // au.HasPermission = 2
  653. // }
  654. // }
  655. // // 无权限的弹框提示
  656. // if au.HasPermission != 1 {
  657. // if au.OperationMode == UserPermissionOperationModeCall {
  658. // if list[i].Type == 1 {
  659. // au.PopupMsg = UserPermissionPopupMsgCallActivity
  660. // } else {
  661. // au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  662. // }
  663. // } else {
  664. // if list[i].Type == 1 {
  665. // au.PopupMsg = UserPermissionPopupMsgApplyActivity
  666. // } else {
  667. // au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  668. // }
  669. // }
  670. // }
  671. // list[i].AuthInfo = au
  672. // list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  673. // // 默认图
  674. // if list[i].BackgroundImg == "" {
  675. // if list[i].Type == 1 {
  676. // list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  677. // } else {
  678. // list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  679. // }
  680. // }
  681. // // 分享图
  682. // if list[i].ShareImg == "" {
  683. // if list[i].Type == 1 {
  684. // list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  685. // } else {
  686. // list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  687. // }
  688. // }
  689. // }
  690. // //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  691. // for _, item := range list {
  692. // if item.Type == 1 {
  693. // mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  694. // } else if item.Type == 2 {
  695. // mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  696. // } else if item.Type == 3 {
  697. // mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  698. // }
  699. // }
  700. // }
  701. //
  702. // for _, vList := range list {
  703. // for _, v := range mapItems {
  704. // if v.SourceId == vList.SourceId {
  705. // items = append(items, v)
  706. // }
  707. // }
  708. // }
  709. // return
  710. //}
  711. func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserItem) (items []*models.CygxResourceDataNewResp, err error) {
  712. var condition string
  713. var pars []interface{}
  714. uid := user.UserId
  715. mapItems := make(map[string]*models.CygxResourceDataNewResp)
  716. for _, v := range list {
  717. //预处理文章
  718. item := new(models.CygxResourceDataNewResp)
  719. item.SourceId = v.SourceId
  720. item.Source = v.Source
  721. item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  722. mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  723. }
  724. var articleIds []int //报告
  725. var newchartIds []int //图表
  726. var roadshowIds []string //微路演
  727. var activityIds []int //活动
  728. var activityvideoIds []string // 活动视频
  729. var activityvoiceIds []string //活动音频
  730. var activityspecialIds []int //专项调研活动
  731. var researchsummaryIds []int //本周研究汇总
  732. var minutessummaryIds []int //上周纪要汇总
  733. var meetingreviewchaptIds []int //晨会精华
  734. var productinteriorIds []int //产品内测
  735. var industrialResourceIds []int // 产业资源包
  736. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior
  737. for _, v := range list {
  738. if v.Source == "article" {
  739. articleIds = append(articleIds, v.SourceId)
  740. } else if v.Source == "newchart" {
  741. newchartIds = append(newchartIds, v.SourceId)
  742. } else if v.Source == "roadshow" {
  743. roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  744. } else if v.Source == "activity" {
  745. activityIds = append(activityIds, v.SourceId)
  746. } else if v.Source == "activityvideo" {
  747. activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  748. } else if v.Source == "activityvoice" {
  749. activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  750. } else if v.Source == "activityspecial" {
  751. activityspecialIds = append(activityspecialIds, v.SourceId)
  752. } else if v.Source == "researchsummary" {
  753. researchsummaryIds = append(researchsummaryIds, v.SourceId)
  754. } else if v.Source == "minutessummary" {
  755. minutessummaryIds = append(minutessummaryIds, v.SourceId)
  756. } else if v.Source == "meetingreviewchapt" {
  757. meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  758. } else if v.Source == "productinterior" {
  759. productinteriorIds = append(productinteriorIds, v.SourceId)
  760. } else if v.Source == "industrialsource" {
  761. industrialResourceIds = append(industrialResourceIds, v.SourceId)
  762. }
  763. }
  764. detail, e := models.GetConfigByCode("city_img_url")
  765. if e != nil {
  766. err = errors.New("GetResourceDataList, Err: " + e.Error())
  767. return
  768. }
  769. detailChart, e := models.GetConfigByCode("chart_img_url")
  770. if e != nil {
  771. err = errors.New("GetResourceDataList, Err: " + e.Error())
  772. return
  773. }
  774. addressList := strings.Split(detail.ConfigValue, "{|}")
  775. mapAddress := make(map[string]string)
  776. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  777. mapChart := make(map[string]string)
  778. var cityName string
  779. var chartName string
  780. var imgUrl string
  781. var imgUrlChart string
  782. for _, v := range addressList {
  783. vslice := strings.Split(v, "_")
  784. cityName = vslice[0]
  785. imgUrl = vslice[len(vslice)-1]
  786. mapAddress[cityName] = imgUrl
  787. }
  788. for _, v := range chartList {
  789. vslice := strings.Split(v, "_")
  790. chartName = vslice[0]
  791. imgUrlChart = vslice[len(vslice)-1]
  792. mapChart[chartName] = imgUrlChart
  793. }
  794. var imgUrlResp string
  795. //处理文章
  796. if len(articleIds) > 0 {
  797. pars = make([]interface{}, 0)
  798. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  799. pars = append(pars, articleIds)
  800. articleList, e := models.GetHomeListPublic(condition, pars, 0, len(articleIds))
  801. if e != nil {
  802. err = errors.New("GetResourceDataList, Err: " + e.Error())
  803. return
  804. }
  805. articleList, e = HandleArticleCategoryImg(articleList, user)
  806. if e != nil {
  807. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  808. return
  809. }
  810. for _, v := range articleList {
  811. v.Body = ""
  812. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  813. }
  814. }
  815. //处理晨会精华
  816. if len(meetingreviewchaptIds) > 0 {
  817. pars = make([]interface{}, 0)
  818. condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  819. pars = append(pars, meetingreviewchaptIds)
  820. listrMeet, e := models.GetCygxMorningMeetingReviewChapterList(condition, pars)
  821. if e != nil {
  822. err = errors.New("GetResourceDataList, Err: " + e.Error())
  823. return
  824. }
  825. for _, v := range listrMeet {
  826. v.Content = AnnotationHtml(v.Content)
  827. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  828. mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  829. }
  830. }
  831. //处理上周纪要汇总
  832. if len(minutessummaryIds) > 0 {
  833. pars = make([]interface{}, 0)
  834. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  835. pars = append(pars, minutessummaryIds)
  836. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  837. if e != nil {
  838. err = errors.New("GetResourceDataList, Err: " + e.Error())
  839. return
  840. }
  841. for _, v := range listresearchsummary {
  842. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  843. mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  844. }
  845. }
  846. //处理本周纪要汇总
  847. if len(researchsummaryIds) > 0 {
  848. pars = make([]interface{}, 0)
  849. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  850. pars = append(pars, researchsummaryIds)
  851. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  852. if e != nil {
  853. err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  854. return
  855. }
  856. for _, v := range listresearchsummary {
  857. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  858. mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  859. }
  860. }
  861. //处理产品内测
  862. if len(productinteriorIds) > 0 {
  863. pars = make([]interface{}, 0)
  864. condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  865. pars = append(pars, productinteriorIds)
  866. listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  867. if e != nil {
  868. err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  869. return
  870. }
  871. for _, v := range listProductInterior {
  872. v.Body = ProductInteriorHtml(v.Body)
  873. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  874. mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  875. }
  876. }
  877. //处理活动
  878. if len(activityIds) > 0 {
  879. for _, vss := range activityIds {
  880. imgUrlResp += strconv.Itoa(vss) + ","
  881. }
  882. pars = make([]interface{}, 0)
  883. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  884. pars = append(pars, activityIds)
  885. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  886. if e != nil {
  887. err = errors.New("GetResourceDataList, Err: " + e.Error())
  888. return
  889. }
  890. var activityListRersp []*models.ActivityListResp
  891. for _, v := range activityList {
  892. activityListRersp = append(activityListRersp, ActivityButtonShow(v, user, make([]string, 0)))
  893. }
  894. //处理不同的报名方式按钮回显
  895. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  896. if e != nil {
  897. err = errors.New("GetActivitySignupResp, Err: " + e.Error())
  898. return
  899. }
  900. for _, v := range activityListRersp {
  901. if v == nil {
  902. continue
  903. }
  904. if v.ActivityType == 0 {
  905. if mapAddress[v.City] != "" {
  906. imgUrlResp = mapAddress[v.City]
  907. } else {
  908. imgUrlResp = mapAddress["其它"]
  909. }
  910. } else {
  911. if mapChart[v.ChartPermissionName] != "" {
  912. imgUrlResp = mapChart[v.ChartPermissionName]
  913. }
  914. }
  915. v.ImgUrl = imgUrlResp
  916. v.SourceType = mapActivitySignup[v.ActivityId]
  917. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  918. }
  919. }
  920. //产业资源包
  921. if len(industrialResourceIds) > 0 {
  922. pars = make([]interface{}, 0)
  923. var industrialResourceIdstring []string
  924. for _, v := range industrialResourceIds {
  925. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  926. }
  927. industrialId := strings.Join(industrialResourceIdstring, ",")
  928. condition = ` AND m.industrial_management_id IN (` + industrialId + `) `
  929. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  930. if e != nil {
  931. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  932. return
  933. }
  934. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIds)) + `)`
  935. pars = append(pars, industrialResourceIds)
  936. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  937. //合并产业关联的标的
  938. if e != nil {
  939. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  940. return
  941. }
  942. mapIndustrial := make(map[string]int)
  943. for _, v := range listSubjcet {
  944. for k2, v2 := range listIndustrialResourceIds {
  945. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Yx", v.SubjectName)] == 0 {
  946. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  947. }
  948. }
  949. }
  950. for _, v := range listIndustrialResourceIds {
  951. mapItems[fmt.Sprint("industrialsource", v.IndustrialManagementId)].IndustrialResource = v
  952. }
  953. }
  954. //处理图表
  955. if len(newchartIds) > 0 {
  956. pars = make([]interface{}, 0)
  957. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  958. pars = append(pars, newchartIds)
  959. chartDateList, e := models.GetChartListCollection(condition, pars, uid, 0, len(newchartIds))
  960. if e != nil {
  961. err = errors.New("GetResourceDataList, Err: " + e.Error())
  962. return
  963. }
  964. for _, v := range chartDateList {
  965. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  966. }
  967. }
  968. //处理专项调研
  969. if len(activityspecialIds) > 0 {
  970. pars = make([]interface{}, 0)
  971. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  972. pars = append(pars, activityspecialIds)
  973. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  974. if e != nil {
  975. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  976. return
  977. }
  978. UserMap, e := GetSpecialTripUserMap(activityspecialIds, user.UserId)
  979. if e != nil {
  980. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  981. return
  982. }
  983. for _, v := range activitySpeciallist {
  984. if mapChart[v.ChartPermissionName] != "" {
  985. imgUrlResp = mapChart[v.ChartPermissionName]
  986. }
  987. if _, ok := UserMap[v.ActivityId]; ok {
  988. v.IsTrip = 1
  989. }
  990. if v.Days == 0 {
  991. v.TripStatus = 1
  992. v.TripImgLink = v.TripImgLink
  993. } else {
  994. v.TripStatus = 2
  995. v.TripImgLink = v.TripImgLinkFix
  996. v.ActivityTimeText = v.ActivityTimeTextByDay
  997. }
  998. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  999. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  1000. if resultTimeStart.After(time.Now()) {
  1001. v.ActiveState = "1"
  1002. } else if time.Now().After(resultTimeEnd) {
  1003. v.ActiveState = "3"
  1004. } else {
  1005. v.ActiveState = "2"
  1006. }
  1007. v.ImgUrl = imgUrlResp
  1008. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  1009. }
  1010. }
  1011. //处理路演 处理路活动视频 处理路活音频
  1012. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds) > 0 {
  1013. audioIdstr := strings.Join(activityvoiceIds, ",")
  1014. ideoIdsStr := strings.Join(roadshowIds, ",")
  1015. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  1016. list, _, e := GetMicroRoadShowMycollect(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds), 0, audioIdstr, ideoIdsStr, activityVideoIdsStr)
  1017. if e != nil {
  1018. err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
  1019. return
  1020. }
  1021. for _, item := range list {
  1022. if item.Type == 1 {
  1023. //音频
  1024. count, e := models.GetVoiceCollectCount(user.UserId, item.Id)
  1025. if e != nil {
  1026. err = errors.New("GetVoiceCollectCount, Err: " + e.Error())
  1027. return
  1028. }
  1029. if count > 0 {
  1030. item.IsCollect = true
  1031. }
  1032. } else if item.Type == 2 {
  1033. //活动视频
  1034. count, e := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  1035. if e != nil {
  1036. err = errors.New("GetActivityVideoCollectCount, Err: " + e.Error())
  1037. return
  1038. }
  1039. if count > 0 {
  1040. item.IsCollect = true
  1041. }
  1042. } else if item.Type == 3 {
  1043. //微路演视频
  1044. count, e := models.GetVideoCollectCount(user.UserId, item.Id)
  1045. if e != nil {
  1046. err = errors.New("GetVideoCollectCount, Err: " + e.Error())
  1047. return
  1048. }
  1049. if count > 0 {
  1050. item.IsCollect = true
  1051. }
  1052. }
  1053. }
  1054. // 用户权限
  1055. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  1056. if e != nil {
  1057. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  1058. return
  1059. }
  1060. // 获取默认图配置
  1061. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  1062. if e != nil {
  1063. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  1064. return
  1065. }
  1066. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  1067. for i := range list {
  1068. // 权限
  1069. au := new(models.UserPermissionAuthInfo)
  1070. au.SellerName = authInfo.SellerName
  1071. au.SellerMobile = authInfo.SellerMobile
  1072. au.HasPermission = authInfo.HasPermission
  1073. au.OperationMode = authInfo.OperationMode
  1074. if au.HasPermission == 1 {
  1075. // 非宏观权限进一步判断是否有权限
  1076. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  1077. au.HasPermission = 2
  1078. }
  1079. }
  1080. // 无权限的弹框提示
  1081. if au.HasPermission != 1 {
  1082. if au.OperationMode == UserPermissionOperationModeCall {
  1083. if list[i].Type == 1 {
  1084. au.PopupMsg = UserPermissionPopupMsgCallActivity
  1085. } else {
  1086. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  1087. }
  1088. } else {
  1089. if list[i].Type == 1 {
  1090. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  1091. } else {
  1092. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  1093. }
  1094. }
  1095. }
  1096. list[i].AuthInfo = au
  1097. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  1098. // 默认图
  1099. if list[i].BackgroundImg == "" {
  1100. if list[i].Type == 1 {
  1101. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  1102. } else {
  1103. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  1104. }
  1105. }
  1106. // 分享图
  1107. if list[i].ShareImg == "" {
  1108. if list[i].Type == 1 {
  1109. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  1110. } else {
  1111. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  1112. }
  1113. }
  1114. }
  1115. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  1116. for _, item := range list {
  1117. if item.Type == 1 {
  1118. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  1119. } else if item.Type == 2 {
  1120. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  1121. } else if item.Type == 3 {
  1122. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  1123. }
  1124. }
  1125. }
  1126. for _, vList := range list {
  1127. for _, v := range mapItems {
  1128. //如果这些类型都为空,那么就不合并
  1129. 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 {
  1130. continue
  1131. }
  1132. if v.SourceId == vList.SourceId {
  1133. items = append(items, v)
  1134. }
  1135. }
  1136. }
  1137. return
  1138. }