es_comprehensive.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/PuerkitoBio/goquery"
  7. "github.com/olivere/elastic/v7"
  8. "strconv"
  9. //"go/doc"
  10. "hongze/hongze_mfyx/models"
  11. "hongze/hongze_mfyx/utils"
  12. "html"
  13. //"strconv"
  14. "errors"
  15. "strings"
  16. "time"
  17. )
  18. type SearchComprehensiveItem struct {
  19. SourceId int `description:"资源ID"`
  20. IsSummary int `description:"是否是纪要"`
  21. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior"`
  22. Title string `description:"标题"`
  23. BodyText string `description:"内容"`
  24. PublishDate string `description:"发布时间"`
  25. Abstract string `description:"摘要"`
  26. Annotation string `description:"核心观点"`
  27. IndustryName string `description:"产业名称"`
  28. SubjectNames string `description:"标的名称"`
  29. Body []string
  30. }
  31. type ElasticComprehensiveDetail struct {
  32. SourceId int `description:"资源ID"`
  33. IsSummary int `description:"是否是纪要"`
  34. Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior 、 产业资源包:industrialsource"`
  35. Title string `description:"标题"`
  36. BodyText string `description:"内容"`
  37. PublishDate string `description:"发布时间"`
  38. Abstract string `description:"摘要"`
  39. Annotation string `description:"核心观点"`
  40. IndustryName string `description:"产业名称"`
  41. SubjectNames string `description:"标的名称"`
  42. }
  43. // Es研选专栏
  44. func EsAddYanxuanSpecial(sourceId int) {
  45. var err error
  46. defer func() {
  47. if err != nil {
  48. fmt.Println("err:", err)
  49. go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败sourceId: ", sourceId), 2)
  50. }
  51. }()
  52. detail, e := models.GetYanxuanSpecialItemById(sourceId)
  53. if e != nil {
  54. err = errors.New("GetArticleInfoOtherByArticleId" + e.Error())
  55. return
  56. }
  57. content := html.UnescapeString(detail.Content)
  58. doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
  59. if e != nil {
  60. err = errors.New("goquery.NewDocumentFromReader" + e.Error())
  61. return
  62. }
  63. bodyText := doc.Text()
  64. item := new(ElasticComprehensiveDetail)
  65. item.SourceId = detail.Id
  66. item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  67. item.Title = detail.Title
  68. item.PublishDate = detail.PublishTime
  69. item.BodyText = bodyText
  70. item.Abstract = bodyText
  71. item.IndustryName = detail.IndustryTags
  72. item.SubjectNames = detail.CompanyTags + detail.Tags
  73. if detail.Status == 3 {
  74. EsAddOrEditComprehensiveData(item) //如果发布了就新增
  75. } else {
  76. EsDeleteComprehensiveData(item) // 没有发布就删除
  77. }
  78. return
  79. }
  80. // 新增和修改数据
  81. func EsAddOrEditComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  82. indexName := utils.IndexNameComprehensive
  83. //return
  84. defer func() {
  85. if err != nil {
  86. fmt.Println(err, item.SourceId)
  87. //go utils.SendAlarmMsg("更新综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  88. }
  89. }()
  90. client := utils.Client
  91. mustMap := make([]interface{}, 0)
  92. mustMap = append(mustMap, map[string]interface{}{
  93. "term": map[string]interface{}{
  94. "SourceId": item.SourceId,
  95. },
  96. })
  97. mustMap = append(mustMap, map[string]interface{}{
  98. "term": map[string]interface{}{
  99. "Source": item.Source,
  100. },
  101. })
  102. queryMap := map[string]interface{}{
  103. "query": map[string]interface{}{
  104. "bool": map[string]interface{}{
  105. "must": mustMap,
  106. },
  107. },
  108. }
  109. requestTotalHits := client.Count(indexName).BodyJson(queryMap)
  110. total, e := requestTotalHits.Do(context.Background())
  111. if e != nil {
  112. err = errors.New("requestTotalHits.Do(context.Background()), Err: " + e.Error())
  113. return
  114. }
  115. //return
  116. //根据来源以及ID ,判断内容是否存在,如果存在就新增,如果不存在就修改
  117. if total == 0 {
  118. resp, e := client.Index().Index(indexName).BodyJson(item).Do(context.Background())
  119. if e != nil {
  120. err = errors.New("client.Index().Index(indexName).BodyJson(item).Do(context.Background()), Err: " + e.Error())
  121. return
  122. }
  123. if resp.Status == 0 && resp.Result == "created" {
  124. //fmt.Println("新增成功")
  125. //err = nil
  126. return
  127. } else {
  128. //err = errors.New(fmt.Sprint(resp))
  129. err = errors.New(fmt.Sprint("articleId", item.SourceId))
  130. return
  131. }
  132. } else {
  133. //拼接需要改动的前置条件
  134. bool_query := elastic.NewBoolQuery()
  135. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  136. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  137. //设置需要改动的内容
  138. var script string
  139. script += fmt.Sprint("ctx._source['SubjectNames'] = '", item.SubjectNames, "';")
  140. script += fmt.Sprint("ctx._source['PublishDate'] = '", item.PublishDate, "';")
  141. script += fmt.Sprint("ctx._source['IsSummary'] = ", item.IsSummary, ";")
  142. script += fmt.Sprint("ctx._source['Abstract'] = '", item.Abstract, "';")
  143. script += fmt.Sprint("ctx._source['Title'] = '", item.Title, "';")
  144. script += fmt.Sprint("ctx._source['BodyText'] = '", item.BodyText, "';")
  145. script += fmt.Sprint("ctx._source['Annotation'] = '", item.Annotation, "';")
  146. script += fmt.Sprint("ctx._source['IndustryName'] = '", item.IndustryName, "'")
  147. _, e = client.UpdateByQuery(indexName).
  148. Query(bool_query).
  149. Script(elastic.NewScriptInline(script)).
  150. Refresh("true").
  151. Do(context.Background())
  152. if e != nil && e.Error() != "elastic: Error 400 (Bad Request): compile error [type=script_exception]" {
  153. //文本内容过长的时候,修改会报 400 的错误,暂时先不处理
  154. //fmt.Println("err", e.Error())
  155. ////err = e
  156. //err = errors.New("client.UpdateByQuery(indexName), Err: " + e.Error())
  157. return
  158. }
  159. }
  160. return
  161. }
  162. // 删除数据
  163. func EsDeleteComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  164. defer func() {
  165. if err != nil {
  166. fmt.Println(err)
  167. go utils.SendAlarmMsg("删除数据综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  168. }
  169. }()
  170. indexName := utils.IndexNameComprehensive
  171. client := utils.Client
  172. //拼接需要删除的前置条件
  173. bool_query := elastic.NewBoolQuery()
  174. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  175. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  176. _, e := client.DeleteByQuery(indexName).
  177. Query(bool_query).
  178. Do(context.Background())
  179. if e != nil {
  180. err = errors.New(" client.DeleteByQuery(indexName), Err: " + e.Error())
  181. return
  182. }
  183. return
  184. }
  185. func EsComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int64, err error) {
  186. indexName := utils.IndexNameComprehensive
  187. client := utils.Client
  188. keyWordArr, err := GetIndustryMapNameSliceV3(keyWord)
  189. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  190. keyWordLen := len(keyWordArr)
  191. if keyWordLen <= 0 {
  192. keyWordArr = append(keyWordArr, keyWord)
  193. keyWordLen = len(keyWordArr)
  194. }
  195. //Es 的高级查询有 自定义排序 文档一时半会儿撸不懂,先做多次查询手动过滤 2023.2.2
  196. //ikType 查询方式 ,0:查所有 、 1:查询键入词 、 2:查询除了查询键入词之外的联想词
  197. mustMap := make([]interface{}, 0)
  198. shouldMap := make(map[string]interface{}, 0)
  199. shouldMapquery := make([]interface{}, 0)
  200. mustNotMap := make([]interface{}, 0)
  201. shouldNotMap := make(map[string]interface{}, 0)
  202. shouldNotMapquery := make([]interface{}, 0)
  203. // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
  204. //keyWordWeight := GetWeight(keyWordLen)
  205. var boost int
  206. //lenkeyWordArr := len(keyWordArr)
  207. for k, v := range keyWordArr {
  208. if k > 0 {
  209. continue
  210. }
  211. if k == 0 {
  212. boost = 2 * 1000
  213. } else {
  214. boost = 1
  215. }
  216. if v != "" {
  217. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  218. "function_score": map[string]interface{}{
  219. "query": map[string]interface{}{
  220. "multi_match": map[string]interface{}{
  221. //"boost": (lenkeyWordArr - k) * boost, //给查询的值赋予权重
  222. "boost": boost, //给查询的值赋予权重
  223. "fields": []interface{}{"Title"},
  224. "query": v,
  225. },
  226. },
  227. },
  228. })
  229. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  230. "function_score": map[string]interface{}{
  231. "query": map[string]interface{}{
  232. "multi_match": map[string]interface{}{
  233. "boost": boost, //给查询的值赋予权重
  234. "fields": []interface{}{"Abstract"},
  235. "query": v,
  236. },
  237. },
  238. },
  239. })
  240. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  241. "function_score": map[string]interface{}{
  242. "query": map[string]interface{}{
  243. "multi_match": map[string]interface{}{
  244. "boost": boost, //给查询的值赋予权重
  245. "fields": []interface{}{"Annotation"},
  246. "query": v,
  247. },
  248. },
  249. },
  250. })
  251. //shouldMapquery = append(shouldMapquery, map[string]interface{}{
  252. // "function_score": map[string]interface{}{
  253. // "query": map[string]interface{}{
  254. // "multi_match": map[string]interface{}{
  255. // //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  256. // "boost": boost, //给查询的值赋予权重
  257. // "fields": []interface{}{"BodyText"},
  258. // "query": v,
  259. // },
  260. // },
  261. // },
  262. //})
  263. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  264. "function_score": map[string]interface{}{
  265. "query": map[string]interface{}{
  266. "multi_match": map[string]interface{}{
  267. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  268. "boost": boost, //给查询的值赋予权重
  269. "fields": []interface{}{"IndustryName"},
  270. "query": v,
  271. },
  272. },
  273. },
  274. })
  275. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  276. "function_score": map[string]interface{}{
  277. "query": map[string]interface{}{
  278. "multi_match": map[string]interface{}{
  279. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  280. "boost": boost, //给查询的值赋予权重
  281. "fields": []interface{}{"SubjectNames"},
  282. "query": v,
  283. },
  284. },
  285. },
  286. })
  287. }
  288. }
  289. shouldMap = map[string]interface{}{
  290. "should": shouldMapquery,
  291. }
  292. shouldNotMap = map[string]interface{}{
  293. "should": shouldNotMapquery,
  294. }
  295. //排序
  296. sortMap := make([]interface{}, 0)
  297. //时间
  298. sortMap = append(sortMap, map[string]interface{}{
  299. "PublishDate": map[string]interface{}{
  300. "order": "desc",
  301. },
  302. })
  303. //sortMap = append(sortMap, map[string]interface{}{
  304. // "_score": map[string]interface{}{
  305. // "order": "desc",
  306. // },
  307. //})
  308. //高亮
  309. highlightMap := make(map[string]interface{}, 0)
  310. highlightMap = map[string]interface{}{
  311. "fields": map[string]interface{}{
  312. //"BodyText": map[string]interface{}{},
  313. "Title": map[string]interface{}{},
  314. "Abstract": map[string]interface{}{},
  315. "Annotation": map[string]interface{}{},
  316. },
  317. //样式 红色
  318. "post_tags": []interface{}{"</font>"},
  319. "pre_tags": []interface{}{"<font color='red'>"},
  320. "fragment_size": 50,
  321. }
  322. mustMap = append(mustMap, map[string]interface{}{
  323. "bool": shouldMap,
  324. })
  325. mustNotMap = append(mustNotMap, map[string]interface{}{
  326. "bool": shouldNotMap,
  327. })
  328. queryMap := map[string]interface{}{
  329. "query": map[string]interface{}{
  330. "bool": map[string]interface{}{
  331. "must": mustMap,
  332. },
  333. },
  334. }
  335. queryMap["sort"] = sortMap
  336. queryMap["from"] = startSize
  337. queryMap["size"] = pageSize
  338. queryMap["highlight"] = highlightMap
  339. //jsonBytes, _ := json.Marshal(queryMap)
  340. //fmt.Println(string(jsonBytes))
  341. //utils.FileLog.Info(string(jsonBytes))
  342. request := client.Search(indexName).Source(queryMap) // sets the JSON request
  343. searchByMatch, err := request.Do(context.Background())
  344. if searchByMatch != nil {
  345. if searchByMatch.Hits != nil {
  346. for _, v := range searchByMatch.Hits.Hits {
  347. var isAppend bool
  348. articleJson, err := v.Source.MarshalJSON()
  349. if err != nil {
  350. return nil, 0, err
  351. }
  352. article := new(ElasticComprehensiveDetail)
  353. err = json.Unmarshal(articleJson, &article)
  354. if err != nil {
  355. return nil, 0, err
  356. }
  357. //fmt.Println(article.SourceId, article.Title, article.Source)
  358. searchItem := new(SearchComprehensiveItem)
  359. searchItem.SourceId = article.SourceId
  360. if len(v.Highlight["Annotation"]) > 0 {
  361. for _, vText := range v.Highlight["Annotation"] {
  362. searchItem.Body = append(searchItem.Body, vText)
  363. }
  364. }
  365. if len(v.Highlight["Abstract"]) > 0 {
  366. for _, vText := range v.Highlight["Abstract"] {
  367. searchItem.Body = append(searchItem.Body, vText)
  368. }
  369. }
  370. if len(v.Highlight["BodyText"]) > 0 {
  371. for _, vText := range v.Highlight["BodyText"] {
  372. searchItem.Body = append(searchItem.Body, vText)
  373. }
  374. }
  375. //searchItem.IsSummary = article.IsSummary
  376. //if len(searchItem.Body) == 0 {
  377. // bodyRune := []rune(article.BodyText)
  378. // bodyRuneLen := len(bodyRune)
  379. // if bodyRuneLen > 100 {
  380. // bodyRuneLen = 100
  381. // }
  382. // body := string(bodyRune[:bodyRuneLen])
  383. // searchItem.Body = []string{body}
  384. //}
  385. var title string
  386. if len(v.Highlight["Title"]) > 0 {
  387. title = v.Highlight["Title"][0]
  388. } else {
  389. title = article.Title
  390. }
  391. searchItem.Title = title
  392. searchItem.Source = article.Source
  393. searchItem.PublishDate = article.PublishDate
  394. if !isAppend {
  395. result = append(result, searchItem)
  396. }
  397. }
  398. }
  399. total = searchByMatch.Hits.TotalHits.Value
  400. }
  401. return
  402. }
  403. func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserItem) (items []*models.CygxResourceDataResp, err error) {
  404. var condition string
  405. var pars []interface{}
  406. uid := user.UserId
  407. titleHighlight := make(map[int]string)
  408. bodyHighlight := make(map[int][]string)
  409. yanXuanbodyHighlight := make(map[int][]string)
  410. //var bodyHighlight []string
  411. mapItems := make(map[string]*models.CygxResourceDataResp)
  412. for _, v := range list {
  413. //预处理文章
  414. item := new(models.CygxResourceDataResp)
  415. item.SourceId = v.SourceId
  416. item.Source = v.Source
  417. //if v.IsSummary == 1 {
  418. item.BodyHighlight = v.Body
  419. titleHighlight[v.SourceId] = v.Title
  420. bodyHighlight[v.SourceId] = v.Body
  421. //fmt.Println(v.Title)
  422. //} else {
  423. // item.BodyHighlight = make([]string, 0)
  424. //}
  425. item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  426. mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  427. }
  428. var articleIds []int
  429. var newchartIds []int
  430. var roadshowIds []string
  431. var activityIds []int
  432. var activityvideoIds []string
  433. var activityvoiceIds []string
  434. var activityspecialIds []int
  435. var researchsummaryIds []int
  436. var minutessummaryIds []int
  437. var meetingreviewchaptIds []int
  438. var productinteriorIds []int
  439. var industrialResourceIdsHz []int // 弘则产业资源包
  440. var industrialResourceIdsYx []int // 研选产业资源包
  441. var yanxuanSpecialIds []int // 研选专栏
  442. var askserieVideoIds []string //问答系列视频
  443. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt "`
  444. for _, v := range list {
  445. if v.Source == "article" {
  446. articleIds = append(articleIds, v.SourceId)
  447. } else if v.Source == "newchart" {
  448. newchartIds = append(newchartIds, v.SourceId)
  449. } else if v.Source == "roadshow" {
  450. roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  451. } else if v.Source == "activity" {
  452. activityIds = append(activityIds, v.SourceId)
  453. } else if v.Source == "activityvideo" {
  454. activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  455. } else if v.Source == "activityvoice" {
  456. activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  457. } else if v.Source == "activityspecial" {
  458. activityspecialIds = append(activityspecialIds, v.SourceId)
  459. } else if v.Source == "researchsummary" {
  460. researchsummaryIds = append(researchsummaryIds, v.SourceId)
  461. } else if v.Source == "minutessummary" {
  462. minutessummaryIds = append(minutessummaryIds, v.SourceId)
  463. } else if v.Source == "meetingreviewchapt" {
  464. meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  465. } else if v.Source == "productinterior" {
  466. productinteriorIds = append(productinteriorIds, v.SourceId)
  467. } else if v.Source == "industrialsourceHz" {
  468. industrialResourceIdsHz = append(industrialResourceIdsHz, v.SourceId)
  469. } else if v.Source == "industrialsourceYx" {
  470. industrialResourceIdsYx = append(industrialResourceIdsYx, v.SourceId)
  471. } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL {
  472. yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
  473. yanXuanbodyHighlight[v.SourceId] = v.Body
  474. } else if v.Source == utils.CYGX_OBJ_ASKSERIEVIDEO {
  475. askserieVideoIds = append(askserieVideoIds, strconv.Itoa(v.SourceId))
  476. }
  477. }
  478. //处理文章
  479. if len(articleIds) > 0 {
  480. pars = make([]interface{}, 0)
  481. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  482. pars = append(pars, articleIds)
  483. listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
  484. if e != nil {
  485. err = errors.New("GetResourceDataList, Err: " + e.Error())
  486. return
  487. }
  488. listArticle, e = HandleArticleCategoryImg(listArticle)
  489. if e != nil {
  490. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  491. return
  492. }
  493. for _, v := range listArticle {
  494. v.Body = ""
  495. v.BodyHtml = ""
  496. if titleHighlight[v.ArticleId] != "" {
  497. v.Title = titleHighlight[v.ArticleId]
  498. }
  499. if len(bodyHighlight[v.ArticleId]) > 0 {
  500. v.Abstract = ""
  501. v.Annotation = ""
  502. v.BodyHighlight = bodyHighlight[v.ArticleId]
  503. } else {
  504. v.BodyHighlight = make([]string, 0)
  505. }
  506. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  507. }
  508. }
  509. //处理晨会精华
  510. if len(meetingreviewchaptIds) > 0 {
  511. //pars = make([]interface{}, 0)
  512. //condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  513. //pars = append(pars, meetingreviewchaptIds)
  514. listrMeet, e := GetCygxMorningMeetingReviewChapterListByIds(meetingreviewchaptIds)
  515. if e != nil {
  516. err = errors.New("GetResourceDataList, Err: " + e.Error())
  517. return
  518. }
  519. for _, v := range listrMeet {
  520. v.Content = AnnotationHtml(v.Content)
  521. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  522. mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  523. }
  524. }
  525. //处理上周纪要汇总
  526. if len(minutessummaryIds) > 0 {
  527. pars = make([]interface{}, 0)
  528. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  529. pars = append(pars, minutessummaryIds)
  530. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  531. if e != nil {
  532. err = errors.New("GetResourceDataList, Err: " + e.Error())
  533. return
  534. }
  535. for _, v := range listresearchsummary {
  536. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  537. mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  538. }
  539. }
  540. //处理本周纪要汇总
  541. if len(researchsummaryIds) > 0 {
  542. pars = make([]interface{}, 0)
  543. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  544. pars = append(pars, researchsummaryIds)
  545. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  546. if e != nil {
  547. err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  548. return
  549. }
  550. for _, v := range listresearchsummary {
  551. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  552. mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  553. }
  554. }
  555. //处理产品内测
  556. if len(productinteriorIds) > 0 {
  557. pars = make([]interface{}, 0)
  558. condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  559. pars = append(pars, productinteriorIds)
  560. listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  561. if e != nil {
  562. err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  563. return
  564. }
  565. for _, v := range listProductInterior {
  566. v.Body = ProductInteriorHtml(v.Body)
  567. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  568. mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  569. }
  570. }
  571. detail, e := models.GetConfigByCode("city_img_url")
  572. if e != nil {
  573. err = errors.New("GetResourceDataList, Err: " + e.Error())
  574. return
  575. }
  576. detailChart, e := models.GetConfigByCode("chart_img_url")
  577. if e != nil {
  578. err = errors.New("GetResourceDataList, Err: " + e.Error())
  579. return
  580. }
  581. addressList := strings.Split(detail.ConfigValue, "{|}")
  582. mapAddress := make(map[string]string)
  583. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  584. mapChart := make(map[string]string)
  585. var cityName string
  586. var chartName string
  587. var imgUrl string
  588. var imgUrlChart string
  589. for _, v := range addressList {
  590. vslice := strings.Split(v, "_")
  591. cityName = vslice[0]
  592. imgUrl = vslice[len(vslice)-1]
  593. mapAddress[cityName] = imgUrl
  594. }
  595. for _, v := range chartList {
  596. vslice := strings.Split(v, "_")
  597. chartName = vslice[0]
  598. imgUrlChart = vslice[len(vslice)-1]
  599. mapChart[chartName] = imgUrlChart
  600. }
  601. var imgUrlResp string
  602. //处理活动
  603. if len(activityIds) > 0 {
  604. for _, vss := range activityIds {
  605. imgUrlResp += strconv.Itoa(vss) + ","
  606. }
  607. pars = make([]interface{}, 0)
  608. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
  609. pars = append(pars, activityIds)
  610. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  611. if e != nil {
  612. err = errors.New("GetResourceDataList, Err: " + e.Error())
  613. return
  614. }
  615. //处理不同的报名方式按钮回显
  616. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  617. if e != nil {
  618. e = errors.New("GetActivitySignupResp, Err: " + e.Error())
  619. return
  620. }
  621. activityTypeIdMap := GetActivityTypeIdMap()
  622. var activityListRersp []*models.ActivityDetail
  623. for _, v := range activityList {
  624. v.SignupType = mapActivitySignup[v.ActivityId]
  625. v.ActivityType = activityTypeIdMap[v.ActivityTypeId] // 线上还是线下
  626. activityListRersp = append(activityListRersp, ActivityButtonShow(v))
  627. }
  628. for _, v := range activityListRersp {
  629. if v == nil {
  630. continue
  631. }
  632. if v.ActivityType == 0 {
  633. if mapAddress[v.City] != "" {
  634. imgUrlResp = mapAddress[v.City]
  635. } else {
  636. imgUrlResp = mapAddress["其它"]
  637. }
  638. } else {
  639. if mapChart[v.ChartPermissionName] != "" {
  640. imgUrlResp = mapChart[v.ChartPermissionName]
  641. }
  642. }
  643. v.SourceType = 1
  644. v.Expert, _ = GetReportContentTextSub(v.Expert)
  645. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  646. }
  647. }
  648. //产业资源包
  649. if len(industrialResourceIdsHz) > 0 {
  650. pars = make([]interface{}, 0)
  651. var industrialResourceIdstring []string
  652. for _, v := range industrialResourceIdsHz {
  653. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  654. }
  655. industrialId := strings.Join(industrialResourceIdstring, ",")
  656. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id = 0 `
  657. listIndustrialResourceIds, e := models.GetSearchResourceList(user.UserId, condition, 0, len(industrialResourceIdsHz))
  658. if e != nil {
  659. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  660. return
  661. }
  662. //合并产业关联的标的
  663. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(industrialResourceIdsHz)
  664. if e != nil {
  665. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  666. return
  667. }
  668. mapIndustrial := make(map[string]int)
  669. for _, v := range listSubjcet {
  670. for k2, v2 := range listIndustrialResourceIds {
  671. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  672. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  673. }
  674. }
  675. }
  676. for _, v := range listIndustrialResourceIds {
  677. v.Source = 1
  678. mapItems[fmt.Sprint("industrialsourceHz", v.IndustrialManagementId)].IndustrialResource = v
  679. }
  680. }
  681. if len(industrialResourceIdsYx) > 0 {
  682. pars = make([]interface{}, 0)
  683. var industrialResourceIdstring []string
  684. for _, v := range industrialResourceIdsYx {
  685. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  686. }
  687. industrialId := strings.Join(industrialResourceIdstring, ",")
  688. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id > 0 `
  689. listIndustrialResourceIds, e := models.GetSearchResourceList(user.UserId, condition, 0, len(industrialResourceIdsYx))
  690. if e != nil {
  691. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  692. return
  693. }
  694. //合并产业关联的标的
  695. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(industrialResourceIdsYx)
  696. if e != nil {
  697. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  698. return
  699. }
  700. mapIndustrial := make(map[string]int)
  701. for _, v := range listSubjcet {
  702. for k2, v2 := range listIndustrialResourceIds {
  703. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Yx", v.SubjectName)] == 0 {
  704. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  705. }
  706. }
  707. }
  708. for _, v := range listIndustrialResourceIds {
  709. v.Source = 2
  710. mapItems[fmt.Sprint("industrialsourceYx", v.IndustrialManagementId)].IndustrialResource = v
  711. }
  712. }
  713. //处理专项调研
  714. if len(activityspecialIds) > 0 {
  715. pars = make([]interface{}, 0)
  716. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  717. pars = append(pars, activityspecialIds)
  718. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  719. if e != nil {
  720. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  721. return
  722. }
  723. for _, v := range activitySpeciallist {
  724. if mapChart[v.ChartPermissionName] != "" {
  725. imgUrlResp = mapChart[v.ChartPermissionName]
  726. }
  727. if v.Days == 0 {
  728. v.TripStatus = 1
  729. v.TripImgLink = v.TripImgLink
  730. } else {
  731. v.TripStatus = 2
  732. v.TripImgLink = v.TripImgLinkFix
  733. v.ActivityTimeText = v.ActivityTimeTextByDay
  734. }
  735. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  736. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  737. if resultTimeStart.After(time.Now()) {
  738. v.ActiveState = 1
  739. } else if time.Now().After(resultTimeEnd) {
  740. v.ActiveState = 3
  741. } else {
  742. v.ActiveState = 2
  743. }
  744. v.ImgUrl = imgUrlResp
  745. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  746. }
  747. }
  748. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
  749. audioIdstr := strings.Join(activityvoiceIds, ",")
  750. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  751. roadshowIdsStr := strings.Join(roadshowIds, ",")
  752. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  753. list, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
  754. if e != nil {
  755. err = errors.New("GetMicroRoadShowMycollectV12, Err: " + e.Error())
  756. return
  757. }
  758. // 用户权限
  759. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  760. if e != nil {
  761. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  762. return
  763. }
  764. // 获取默认图配置
  765. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  766. if e != nil {
  767. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  768. return
  769. }
  770. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  771. for i := range list {
  772. // 权限
  773. au := new(models.UserPermissionAuthInfo)
  774. au.SellerName = authInfo.SellerName
  775. au.SellerMobile = authInfo.SellerMobile
  776. au.HasPermission = authInfo.HasPermission
  777. au.OperationMode = authInfo.OperationMode
  778. if au.HasPermission == 1 {
  779. // 非宏观权限进一步判断是否有权限
  780. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  781. au.HasPermission = 2
  782. }
  783. }
  784. // 无权限的弹框提示
  785. if au.HasPermission != 1 {
  786. if au.OperationMode == UserPermissionOperationModeCall {
  787. if list[i].Type == 1 {
  788. au.PopupMsg = UserPermissionPopupMsgCallActivity
  789. } else {
  790. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  791. }
  792. } else {
  793. if list[i].Type == 1 {
  794. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  795. } else {
  796. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  797. }
  798. }
  799. }
  800. list[i].AuthInfo = au
  801. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  802. // 默认图
  803. if list[i].BackgroundImg == "" {
  804. if list[i].Type == 1 {
  805. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  806. } else {
  807. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  808. }
  809. }
  810. // 分享图
  811. if list[i].ShareImg == "" {
  812. if list[i].Type == 1 {
  813. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  814. } else {
  815. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  816. }
  817. }
  818. }
  819. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  820. for _, item := range list {
  821. if item.Type == 1 {
  822. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  823. } else if item.Type == 2 {
  824. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  825. } else if item.Type == 3 {
  826. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  827. } else if item.Type == 4 {
  828. mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
  829. }
  830. }
  831. }
  832. //处理研选专栏
  833. lenyanxuanSpecialIds := len(yanxuanSpecialIds)
  834. if lenyanxuanSpecialIds > 0 {
  835. pars = make([]interface{}, 0)
  836. condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
  837. pars = append(pars, yanxuanSpecialIds)
  838. listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars, 0, 0)
  839. if e != nil {
  840. err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
  841. return
  842. }
  843. for _, v := range listyanxuanSpecial {
  844. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  845. v.Annotation, _ = GetReportContentTextSubNew(v.Content)
  846. if len(yanXuanbodyHighlight[v.Id]) > 0 {
  847. v.BodyHighlight = yanXuanbodyHighlight[v.Id]
  848. } else {
  849. v.BodyHighlight = append(v.BodyHighlight, v.Annotation)
  850. }
  851. v.Annotation = "" //强制置空,兼容前端优先级
  852. // Source PublishDate 字段兼容前端样式
  853. v.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  854. v.PublishDate = v.PublishTime
  855. mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
  856. }
  857. }
  858. for _, vList := range list {
  859. for _, v := range mapItems {
  860. //如果这些类型都为空,那么就不合并
  861. if v.Article == nil && v.Roadshow == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.Activityspecial == nil && v.Researchsummary == nil && v.Minutessummary == nil && v.Meetingreviewchapt == nil && v.ProductInterior == nil && v.IndustrialResource == nil && v.YanxuanSpecial == nil && v.AskserieVideo == nil {
  862. continue
  863. }
  864. if v.Article != nil && v.SourceId == vList.SourceId {
  865. v.Article.Title = vList.Title
  866. }
  867. if v.Roadshow != nil && v.SourceId == vList.SourceId {
  868. v.Roadshow.Title = vList.Title
  869. }
  870. if v.Activity != nil && v.SourceId == vList.SourceId {
  871. v.Activity.ActivityName = vList.Title
  872. }
  873. if v.Activityvideo != nil && v.SourceId == vList.SourceId {
  874. v.Activityvideo.Title = vList.Title
  875. }
  876. if v.Activityvoice != nil && v.SourceId == vList.SourceId {
  877. v.Activityvoice.Title = vList.Title
  878. }
  879. if v.Activityspecial != nil && v.SourceId == vList.SourceId {
  880. v.Activityspecial.ResearchTheme = vList.Title
  881. }
  882. if v.Researchsummary != nil && v.SourceId == vList.SourceId {
  883. v.Researchsummary.Title = vList.Title
  884. }
  885. if v.Minutessummary != nil && v.SourceId == vList.SourceId {
  886. v.Minutessummary.Title = vList.Title
  887. }
  888. if v.ProductInterior != nil && v.SourceId == vList.SourceId {
  889. v.ProductInterior.Title = vList.Title
  890. }
  891. //if v.IndustrialResource != nil && v.SourceId == vList.SourceId {
  892. // v.IndustrialResource.UpdateTime = vList.PublishDate
  893. //}
  894. if v.YanxuanSpecial != nil && v.SourceId == vList.SourceId {
  895. v.YanxuanSpecial.Title = vList.Title
  896. }
  897. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  898. items = append(items, v)
  899. }
  900. }
  901. }
  902. for _, v := range items {
  903. if v.IndustrialResource != nil {
  904. v.Source = "industrialsource"
  905. }
  906. }
  907. return
  908. }