es_comprehensive.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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. //Es 的高级查询有 自定义排序 文档一时半会儿撸不懂,先做多次查询手动过滤 2023.2.2
  50. //ikType 查询方式 ,0:查所有 、 1:查询键入词 、 2:查询除了查询键入词之外的联想词
  51. mustMap := make([]interface{}, 0)
  52. shouldMap := make(map[string]interface{}, 0)
  53. shouldMapquery := make([]interface{}, 0)
  54. mustNotMap := make([]interface{}, 0)
  55. shouldNotMap := make(map[string]interface{}, 0)
  56. shouldNotMapquery := make([]interface{}, 0)
  57. // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
  58. //keyWordWeight := GetWeight(keyWordLen)
  59. var boost int
  60. //lenkeyWordArr := len(keyWordArr)
  61. for k, v := range keyWordArr {
  62. if k > 0 {
  63. continue
  64. }
  65. if k == 0 {
  66. boost = 2 * 1000
  67. } else {
  68. boost = 1
  69. }
  70. if v != "" {
  71. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  72. "function_score": map[string]interface{}{
  73. "query": map[string]interface{}{
  74. "multi_match": map[string]interface{}{
  75. //"boost": (lenkeyWordArr - k) * boost, //给查询的值赋予权重
  76. "boost": boost, //给查询的值赋予权重
  77. "fields": []interface{}{"Title"},
  78. "query": v,
  79. },
  80. },
  81. },
  82. })
  83. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  84. "function_score": map[string]interface{}{
  85. "query": map[string]interface{}{
  86. "multi_match": map[string]interface{}{
  87. "boost": boost, //给查询的值赋予权重
  88. "fields": []interface{}{"Abstract"},
  89. "query": v,
  90. },
  91. },
  92. },
  93. })
  94. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  95. "function_score": map[string]interface{}{
  96. "query": map[string]interface{}{
  97. "multi_match": map[string]interface{}{
  98. "boost": boost, //给查询的值赋予权重
  99. "fields": []interface{}{"Annotation"},
  100. "query": v,
  101. },
  102. },
  103. },
  104. })
  105. //shouldMapquery = append(shouldMapquery, map[string]interface{}{
  106. // "function_score": map[string]interface{}{
  107. // "query": map[string]interface{}{
  108. // "multi_match": map[string]interface{}{
  109. // //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  110. // "boost": boost, //给查询的值赋予权重
  111. // "fields": []interface{}{"BodyText"},
  112. // "query": v,
  113. // },
  114. // },
  115. // },
  116. //})
  117. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  118. "function_score": map[string]interface{}{
  119. "query": map[string]interface{}{
  120. "multi_match": map[string]interface{}{
  121. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  122. "boost": boost, //给查询的值赋予权重
  123. "fields": []interface{}{"IndustryName"},
  124. "query": v,
  125. },
  126. },
  127. },
  128. })
  129. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  130. "function_score": map[string]interface{}{
  131. "query": map[string]interface{}{
  132. "multi_match": map[string]interface{}{
  133. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  134. "boost": boost, //给查询的值赋予权重
  135. "fields": []interface{}{"SubjectNames"},
  136. "query": v,
  137. },
  138. },
  139. },
  140. })
  141. }
  142. }
  143. shouldMap = map[string]interface{}{
  144. "should": shouldMapquery,
  145. }
  146. shouldNotMap = map[string]interface{}{
  147. "should": shouldNotMapquery,
  148. }
  149. //排序
  150. sortMap := make([]interface{}, 0)
  151. //时间
  152. sortMap = append(sortMap, map[string]interface{}{
  153. "PublishDate": map[string]interface{}{
  154. "order": "desc",
  155. },
  156. })
  157. //sortMap = append(sortMap, map[string]interface{}{
  158. // "_score": map[string]interface{}{
  159. // "order": "desc",
  160. // },
  161. //})
  162. //高亮
  163. highlightMap := make(map[string]interface{}, 0)
  164. highlightMap = map[string]interface{}{
  165. "fields": map[string]interface{}{
  166. //"BodyText": map[string]interface{}{},
  167. "Title": map[string]interface{}{},
  168. "Abstract": map[string]interface{}{},
  169. "Annotation": map[string]interface{}{},
  170. },
  171. //样式 红色
  172. "post_tags": []interface{}{"</font>"},
  173. "pre_tags": []interface{}{"<font color='red'>"},
  174. "fragment_size": 50,
  175. }
  176. mustMap = append(mustMap, map[string]interface{}{
  177. "bool": shouldMap,
  178. })
  179. mustNotMap = append(mustNotMap, map[string]interface{}{
  180. "bool": shouldNotMap,
  181. })
  182. queryMap := map[string]interface{}{
  183. "query": map[string]interface{}{
  184. "bool": map[string]interface{}{
  185. "must": mustMap,
  186. },
  187. },
  188. }
  189. queryMap["sort"] = sortMap
  190. queryMap["from"] = startSize
  191. queryMap["size"] = pageSize
  192. queryMap["highlight"] = highlightMap
  193. //jsonBytes, _ := json.Marshal(queryMap)
  194. //fmt.Println(string(jsonBytes))
  195. //utils.FileLog.Info(string(jsonBytes))
  196. request := client.Search(indexName).Source(queryMap) // sets the JSON request
  197. searchByMatch, err := request.Do(context.Background())
  198. if searchByMatch != nil {
  199. if searchByMatch.Hits != nil {
  200. for _, v := range searchByMatch.Hits.Hits {
  201. var isAppend bool
  202. articleJson, err := v.Source.MarshalJSON()
  203. if err != nil {
  204. return nil, 0, err
  205. }
  206. article := new(ElasticComprehensiveDetail)
  207. err = json.Unmarshal(articleJson, &article)
  208. if err != nil {
  209. return nil, 0, err
  210. }
  211. //fmt.Println(article.SourceId, article.Title, article.Source)
  212. searchItem := new(SearchComprehensiveItem)
  213. searchItem.SourceId = article.SourceId
  214. if len(v.Highlight["Annotation"]) > 0 {
  215. for _, vText := range v.Highlight["Annotation"] {
  216. searchItem.Body = append(searchItem.Body, vText)
  217. }
  218. }
  219. if len(v.Highlight["Abstract"]) > 0 {
  220. for _, vText := range v.Highlight["Abstract"] {
  221. searchItem.Body = append(searchItem.Body, vText)
  222. }
  223. }
  224. if len(v.Highlight["BodyText"]) > 0 {
  225. for _, vText := range v.Highlight["BodyText"] {
  226. searchItem.Body = append(searchItem.Body, vText)
  227. }
  228. }
  229. //searchItem.IsSummary = article.IsSummary
  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.CygxResourceDataNewResp, err error) {
  258. var condition string
  259. var pars []interface{}
  260. uid := user.UserId
  261. titleHighlight := make(map[int]string)
  262. bodyHighlight := make(map[int][]string)
  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. item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  270. item.BodyHighlight = v.Body
  271. item.TitleHighlight = v.Title
  272. titleHighlight[v.SourceId] = v.Title
  273. bodyHighlight[v.SourceId] = v.Body
  274. mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  275. }
  276. var articleIds []int //报告
  277. var newchartIds []int //图表
  278. var roadshowIds []string //微路演
  279. var activityIds []int //活动
  280. var activityvideoIds []string // 活动视频
  281. var activityvoiceIds []string //活动音频
  282. var activityspecialIds []int //专项调研活动
  283. var researchsummaryIds []int //本周研究汇总
  284. var minutessummaryIds []int //上周纪要汇总
  285. var meetingreviewchaptIds []int //晨会精华
  286. var productinteriorIds []int //产品内测
  287. var industrialResourceIdsHz []int // 弘则产业资源包
  288. var industrialResourceIdsYx []int // 研选产业资源包
  289. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt 、 产品内测:productinterior
  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 == "industrialsourceHz" {
  314. industrialResourceIdsHz = append(industrialResourceIdsHz, v.SourceId)
  315. } else if v.Source == "industrialsourceYx" {
  316. industrialResourceIdsYx = append(industrialResourceIdsYx, v.SourceId)
  317. }
  318. }
  319. detail, e := models.GetConfigByCode("city_img_url")
  320. if e != nil {
  321. err = errors.New("GetResourceDataList, Err: " + e.Error())
  322. return
  323. }
  324. detailChart, e := models.GetConfigByCode("chart_img_url")
  325. if e != nil {
  326. err = errors.New("GetResourceDataList, Err: " + e.Error())
  327. return
  328. }
  329. addressList := strings.Split(detail.ConfigValue, "{|}")
  330. mapAddress := make(map[string]string)
  331. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  332. mapChart := make(map[string]string)
  333. var cityName string
  334. var chartName string
  335. var imgUrl string
  336. var imgUrlChart string
  337. for _, v := range addressList {
  338. vslice := strings.Split(v, "_")
  339. cityName = vslice[0]
  340. imgUrl = vslice[len(vslice)-1]
  341. mapAddress[cityName] = imgUrl
  342. }
  343. for _, v := range chartList {
  344. vslice := strings.Split(v, "_")
  345. chartName = vslice[0]
  346. imgUrlChart = vslice[len(vslice)-1]
  347. mapChart[chartName] = imgUrlChart
  348. }
  349. var imgUrlResp string
  350. //处理文章
  351. if len(articleIds) > 0 {
  352. pars = make([]interface{}, 0)
  353. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  354. pars = append(pars, articleIds)
  355. articleList, e := models.GetHomeListPublic(condition, pars, 0, len(articleIds))
  356. if e != nil {
  357. err = errors.New("GetResourceDataList, Err: " + e.Error())
  358. return
  359. }
  360. articleList, e = HandleArticleCategoryImg(articleList, user)
  361. if e != nil {
  362. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  363. return
  364. }
  365. for _, v := range articleList {
  366. v.Body = ""
  367. if titleHighlight[v.ArticleId] != "" {
  368. v.Title = titleHighlight[v.ArticleId]
  369. }
  370. if len(bodyHighlight[v.ArticleId]) > 0 {
  371. v.Abstract = ""
  372. v.Annotation = ""
  373. v.BodyHighlight = bodyHighlight[v.ArticleId]
  374. } else {
  375. v.BodyHighlight = make([]string, 0)
  376. }
  377. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  378. }
  379. }
  380. //处理晨会精华
  381. if len(meetingreviewchaptIds) > 0 {
  382. pars = make([]interface{}, 0)
  383. condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  384. pars = append(pars, meetingreviewchaptIds)
  385. listrMeet, e := models.GetCygxMorningMeetingReviewChapterList(condition, pars)
  386. if e != nil {
  387. err = errors.New("GetResourceDataList, Err: " + e.Error())
  388. return
  389. }
  390. for _, v := range listrMeet {
  391. v.Content = AnnotationHtml(v.Content)
  392. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  393. mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  394. }
  395. }
  396. //处理上周纪要汇总
  397. if len(minutessummaryIds) > 0 {
  398. pars = make([]interface{}, 0)
  399. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  400. pars = append(pars, minutessummaryIds)
  401. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  402. if e != nil {
  403. err = errors.New("GetResourceDataList, Err: " + e.Error())
  404. return
  405. }
  406. for _, v := range listresearchsummary {
  407. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  408. mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  409. }
  410. }
  411. //处理本周纪要汇总
  412. if len(researchsummaryIds) > 0 {
  413. pars = make([]interface{}, 0)
  414. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  415. pars = append(pars, researchsummaryIds)
  416. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  417. if e != nil {
  418. err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  419. return
  420. }
  421. for _, v := range listresearchsummary {
  422. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  423. mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  424. }
  425. }
  426. //处理产品内测
  427. if len(productinteriorIds) > 0 {
  428. pars = make([]interface{}, 0)
  429. condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  430. pars = append(pars, productinteriorIds)
  431. listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  432. if e != nil {
  433. err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  434. return
  435. }
  436. for _, v := range listProductInterior {
  437. v.Body = ProductInteriorHtml(v.Body)
  438. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  439. mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  440. }
  441. }
  442. //处理活动
  443. if len(activityIds) > 0 {
  444. for _, vss := range activityIds {
  445. imgUrlResp += strconv.Itoa(vss) + ","
  446. }
  447. pars = make([]interface{}, 0)
  448. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  449. pars = append(pars, activityIds)
  450. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  451. if e != nil {
  452. err = errors.New("GetResourceDataList, Err: " + e.Error())
  453. return
  454. }
  455. var activityListRersp []*models.ActivityListResp
  456. for _, v := range activityList {
  457. activityListRersp = append(activityListRersp, ActivityButtonShow(v, user, make([]string, 0)))
  458. }
  459. //处理不同的报名方式按钮回显
  460. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  461. if e != nil {
  462. err = errors.New("GetActivitySignupResp, Err: " + e.Error())
  463. return
  464. }
  465. for _, v := range activityListRersp {
  466. if v == nil {
  467. continue
  468. }
  469. if v.ActivityType == 0 {
  470. if mapAddress[v.City] != "" {
  471. imgUrlResp = mapAddress[v.City]
  472. } else {
  473. imgUrlResp = mapAddress["其它"]
  474. }
  475. } else {
  476. if mapChart[v.ChartPermissionName] != "" {
  477. imgUrlResp = mapChart[v.ChartPermissionName]
  478. }
  479. }
  480. v.ImgUrl = imgUrlResp
  481. v.SourceType = mapActivitySignup[v.ActivityId]
  482. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  483. }
  484. }
  485. //产业资源包
  486. if len(industrialResourceIdsHz) > 0 {
  487. pars = make([]interface{}, 0)
  488. var industrialResourceIdstring []string
  489. for _, v := range industrialResourceIdsHz {
  490. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  491. }
  492. industrialId := strings.Join(industrialResourceIdstring, ",")
  493. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id = 0 `
  494. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  495. if e != nil {
  496. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  497. return
  498. }
  499. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIdsHz)) + `)`
  500. pars = append(pars, industrialResourceIdsHz)
  501. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  502. //合并产业关联的标的
  503. if e != nil {
  504. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  505. return
  506. }
  507. mapIndustrial := make(map[string]int)
  508. for _, v := range listSubjcet {
  509. for k2, v2 := range listIndustrialResourceIds {
  510. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] == 0 {
  511. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  512. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] = 1
  513. }
  514. }
  515. }
  516. //listIndustrialResourceIds, _ = HandleIndustryList(listIndustrialResourceIds, user, "Hz")
  517. for _, v := range listIndustrialResourceIds {
  518. v.Source = 1
  519. mapItems[fmt.Sprint("industrialsourceHz", v.IndustrialManagementId)].IndustrialResource = v
  520. }
  521. }
  522. //产业资源包
  523. if len(industrialResourceIdsYx) > 0 {
  524. pars = make([]interface{}, 0)
  525. var industrialResourceIdstring []string
  526. for _, v := range industrialResourceIdsYx {
  527. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  528. }
  529. industrialId := strings.Join(industrialResourceIdstring, ",")
  530. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id > 0 `
  531. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  532. if e != nil {
  533. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  534. return
  535. }
  536. fmt.Println(listIndustrialResourceIds)
  537. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIdsYx)) + `)`
  538. pars = append(pars, industrialResourceIdsYx)
  539. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  540. //合并产业关联的标的
  541. if e != nil {
  542. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  543. return
  544. }
  545. mapIndustrial := make(map[string]int)
  546. for _, v := range listSubjcet {
  547. for k2, v2 := range listIndustrialResourceIds {
  548. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] == 0 {
  549. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  550. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] = 1
  551. }
  552. }
  553. }
  554. //listIndustrialResourceIds, _ = HandleIndustryList(listIndustrialResourceIds, user, "Yx")
  555. for _, v := range listIndustrialResourceIds {
  556. v.Source = 2
  557. mapItems[fmt.Sprint("industrialsourceYx", v.IndustrialManagementId)].IndustrialResource = v
  558. }
  559. }
  560. //处理图表
  561. if len(newchartIds) > 0 {
  562. pars = make([]interface{}, 0)
  563. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  564. pars = append(pars, newchartIds)
  565. chartDateList, e := models.GetChartListCollection(condition, pars, uid, 0, len(newchartIds))
  566. if e != nil {
  567. err = errors.New("GetResourceDataList, Err: " + e.Error())
  568. return
  569. }
  570. for _, v := range chartDateList {
  571. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  572. }
  573. }
  574. //处理专项调研
  575. if len(activityspecialIds) > 0 {
  576. pars = make([]interface{}, 0)
  577. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  578. pars = append(pars, activityspecialIds)
  579. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  580. if e != nil {
  581. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  582. return
  583. }
  584. UserMap, e := GetSpecialTripUserMap(activityspecialIds, user.UserId)
  585. if e != nil {
  586. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  587. return
  588. }
  589. for _, v := range activitySpeciallist {
  590. if mapChart[v.ChartPermissionName] != "" {
  591. imgUrlResp = mapChart[v.ChartPermissionName]
  592. }
  593. if _, ok := UserMap[v.ActivityId]; ok {
  594. v.IsTrip = 1
  595. }
  596. if v.Days == 0 {
  597. v.TripStatus = 1
  598. v.TripImgLink = v.TripImgLink
  599. } else {
  600. v.TripStatus = 2
  601. v.TripImgLink = v.TripImgLinkFix
  602. v.ActivityTimeText = v.ActivityTimeTextByDay
  603. }
  604. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  605. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  606. if resultTimeStart.After(time.Now()) {
  607. v.ActiveState = "1"
  608. } else if time.Now().After(resultTimeEnd) {
  609. v.ActiveState = "3"
  610. } else {
  611. v.ActiveState = "2"
  612. }
  613. v.ImgUrl = imgUrlResp
  614. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  615. }
  616. }
  617. //处理路演 处理路活动视频 处理路活音频
  618. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds) > 0 {
  619. audioIdstr := strings.Join(activityvoiceIds, ",")
  620. ideoIdsStr := strings.Join(roadshowIds, ",")
  621. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  622. list, _, e := GetMicroRoadShowMycollect(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds), 0, audioIdstr, ideoIdsStr, activityVideoIdsStr)
  623. if e != nil {
  624. err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
  625. return
  626. }
  627. fmt.Println("list", list)
  628. for _, item := range list {
  629. if item.Type == 1 {
  630. //音频
  631. count, e := models.GetVoiceCollectCount(user.UserId, item.Id)
  632. if e != nil {
  633. err = errors.New("GetVoiceCollectCount, Err: " + e.Error())
  634. return
  635. }
  636. if count > 0 {
  637. item.IsCollect = true
  638. }
  639. } else if item.Type == 2 {
  640. //活动视频
  641. count, e := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  642. if e != nil {
  643. err = errors.New("GetActivityVideoCollectCount, Err: " + e.Error())
  644. return
  645. }
  646. if count > 0 {
  647. item.IsCollect = true
  648. }
  649. } else if item.Type == 3 {
  650. //微路演视频
  651. count, e := models.GetVideoCollectCount(user.UserId, item.Id)
  652. if e != nil {
  653. err = errors.New("GetVideoCollectCount, Err: " + e.Error())
  654. return
  655. }
  656. if count > 0 {
  657. item.IsCollect = true
  658. }
  659. }
  660. }
  661. // 用户权限
  662. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  663. if e != nil {
  664. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  665. return
  666. }
  667. // 获取默认图配置
  668. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  669. if e != nil {
  670. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  671. return
  672. }
  673. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  674. for i := range list {
  675. // 权限
  676. au := new(models.UserPermissionAuthInfo)
  677. au.SellerName = authInfo.SellerName
  678. au.SellerMobile = authInfo.SellerMobile
  679. au.HasPermission = authInfo.HasPermission
  680. au.OperationMode = authInfo.OperationMode
  681. if au.HasPermission == 1 {
  682. // 非宏观权限进一步判断是否有权限
  683. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  684. au.HasPermission = 2
  685. }
  686. }
  687. // 无权限的弹框提示
  688. if au.HasPermission != 1 {
  689. if au.OperationMode == UserPermissionOperationModeCall {
  690. if list[i].Type == 1 {
  691. au.PopupMsg = UserPermissionPopupMsgCallActivity
  692. } else {
  693. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  694. }
  695. } else {
  696. if list[i].Type == 1 {
  697. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  698. } else {
  699. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  700. }
  701. }
  702. }
  703. list[i].AuthInfo = au
  704. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  705. // 默认图
  706. if list[i].BackgroundImg == "" {
  707. if list[i].Type == 1 {
  708. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  709. } else {
  710. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  711. }
  712. }
  713. // 分享图
  714. if list[i].ShareImg == "" {
  715. if list[i].Type == 1 {
  716. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  717. } else {
  718. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  719. }
  720. }
  721. }
  722. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  723. for _, item := range list {
  724. if item.Type == 1 {
  725. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  726. } else if item.Type == 2 {
  727. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  728. } else if item.Type == 3 {
  729. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  730. }
  731. }
  732. }
  733. for _, vList := range list {
  734. for _, v := range mapItems {
  735. //如果这些类型都为空,那么就不合并
  736. 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 {
  737. continue
  738. }
  739. if v.Article != nil && v.SourceId == vList.SourceId {
  740. v.Article.Title = vList.Title
  741. }
  742. if v.Newchart != nil && v.SourceId == vList.SourceId {
  743. v.Newchart.Title = vList.Title
  744. }
  745. if v.Roadshow != nil && v.SourceId == vList.SourceId {
  746. v.Roadshow.Title = vList.Title
  747. }
  748. if v.Activity != nil && v.SourceId == vList.SourceId {
  749. v.Activity.ActivityName = vList.Title
  750. }
  751. if v.Activityvideo != nil && v.SourceId == vList.SourceId {
  752. v.Activityvideo.Title = vList.Title
  753. }
  754. if v.Activityvoice != nil && v.SourceId == vList.SourceId {
  755. v.Activityvoice.Title = vList.Title
  756. }
  757. if v.Activityspecial != nil && v.SourceId == vList.SourceId {
  758. v.Activityspecial.ResearchTheme = vList.Title
  759. }
  760. if v.Researchsummary != nil && v.SourceId == vList.SourceId {
  761. v.Researchsummary.Title = vList.Title
  762. }
  763. if v.Minutessummary != nil && v.SourceId == vList.SourceId {
  764. v.Minutessummary.Title = vList.Title
  765. }
  766. if v.ProductInterior != nil && v.SourceId == vList.SourceId {
  767. v.ProductInterior.Title = vList.Title
  768. }
  769. if v.IndustrialResource != nil && v.SourceId == vList.SourceId {
  770. v.IndustrialResource.UpdateTime = strings.Replace(vList.PublishDate, "00:00:00", "", -1)
  771. }
  772. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  773. items = append(items, v)
  774. }
  775. }
  776. }
  777. for _, v := range items {
  778. if v.IndustrialResource != nil {
  779. v.Source = "industrialsource"
  780. }
  781. }
  782. return
  783. }