es_comprehensive.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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. //var pArr []string
  460. activityListRersp = ActivityArrButtonShow(activityList, user, make([]string, 0))
  461. //处理不同的报名方式按钮回显
  462. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  463. if e != nil {
  464. err = errors.New("GetActivitySignupResp, Err: " + e.Error())
  465. return
  466. }
  467. for _, v := range activityListRersp {
  468. if v == nil {
  469. continue
  470. }
  471. if v.ActivityType == 0 {
  472. if mapAddress[v.City] != "" {
  473. imgUrlResp = mapAddress[v.City]
  474. } else {
  475. imgUrlResp = mapAddress["其它"]
  476. }
  477. } else {
  478. if mapChart[v.ChartPermissionName] != "" {
  479. imgUrlResp = mapChart[v.ChartPermissionName]
  480. }
  481. }
  482. v.ImgUrl = imgUrlResp
  483. v.SourceType = mapActivitySignup[v.ActivityId]
  484. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  485. }
  486. }
  487. //产业资源包
  488. if len(industrialResourceIdsHz) > 0 {
  489. pars = make([]interface{}, 0)
  490. var industrialResourceIdstring []string
  491. for _, v := range industrialResourceIdsHz {
  492. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  493. }
  494. industrialId := strings.Join(industrialResourceIdstring, ",")
  495. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id = 0 `
  496. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  497. if e != nil {
  498. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  499. return
  500. }
  501. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIdsHz)) + `)`
  502. pars = append(pars, industrialResourceIdsHz)
  503. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  504. //合并产业关联的标的
  505. if e != nil {
  506. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  507. return
  508. }
  509. mapIndustrial := make(map[string]int)
  510. for _, v := range listSubjcet {
  511. for k2, v2 := range listIndustrialResourceIds {
  512. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] == 0 {
  513. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  514. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] = 1
  515. }
  516. }
  517. }
  518. //listIndustrialResourceIds, _ = HandleIndustryList(listIndustrialResourceIds, user, "Hz")
  519. for _, v := range listIndustrialResourceIds {
  520. v.Source = 1
  521. mapItems[fmt.Sprint("industrialsourceHz", v.IndustrialManagementId)].IndustrialResource = v
  522. }
  523. }
  524. //产业资源包
  525. if len(industrialResourceIdsYx) > 0 {
  526. pars = make([]interface{}, 0)
  527. var industrialResourceIdstring []string
  528. for _, v := range industrialResourceIdsYx {
  529. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  530. }
  531. industrialId := strings.Join(industrialResourceIdstring, ",")
  532. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id > 0 `
  533. listIndustrialResourceIds, e := models.GetSearchResourceList(condition)
  534. if e != nil {
  535. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  536. return
  537. }
  538. fmt.Println(listIndustrialResourceIds)
  539. conditionSubject := condition + ` AND m.industrial_management_id IN (` + utils.GetOrmInReplace(len(industrialResourceIdsYx)) + `)`
  540. pars = append(pars, industrialResourceIdsYx)
  541. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(pars, conditionSubject)
  542. //合并产业关联的标的
  543. if e != nil {
  544. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  545. return
  546. }
  547. mapIndustrial := make(map[string]int)
  548. for _, v := range listSubjcet {
  549. for k2, v2 := range listIndustrialResourceIds {
  550. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] == 0 {
  551. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  552. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, v.SubjectName)] = 1
  553. }
  554. }
  555. }
  556. //listIndustrialResourceIds, _ = HandleIndustryList(listIndustrialResourceIds, user, "Yx")
  557. for _, v := range listIndustrialResourceIds {
  558. v.Source = 2
  559. mapItems[fmt.Sprint("industrialsourceYx", v.IndustrialManagementId)].IndustrialResource = v
  560. }
  561. }
  562. //处理图表
  563. if len(newchartIds) > 0 {
  564. pars = make([]interface{}, 0)
  565. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  566. pars = append(pars, newchartIds)
  567. chartDateList, e := models.GetChartListCollection(condition, pars, uid, 0, len(newchartIds))
  568. if e != nil {
  569. err = errors.New("GetResourceDataList, Err: " + e.Error())
  570. return
  571. }
  572. for _, v := range chartDateList {
  573. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  574. }
  575. }
  576. //处理专项调研
  577. if len(activityspecialIds) > 0 {
  578. pars = make([]interface{}, 0)
  579. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  580. pars = append(pars, activityspecialIds)
  581. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  582. if e != nil {
  583. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  584. return
  585. }
  586. UserMap, e := GetSpecialTripUserMap(activityspecialIds, user.UserId)
  587. if e != nil {
  588. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  589. return
  590. }
  591. for _, v := range activitySpeciallist {
  592. if mapChart[v.ChartPermissionName] != "" {
  593. imgUrlResp = mapChart[v.ChartPermissionName]
  594. }
  595. if _, ok := UserMap[v.ActivityId]; ok {
  596. v.IsTrip = 1
  597. }
  598. if v.Days == 0 {
  599. v.TripStatus = 1
  600. v.TripImgLink = v.TripImgLink
  601. } else {
  602. v.TripStatus = 2
  603. v.TripImgLink = v.TripImgLinkFix
  604. v.ActivityTimeText = v.ActivityTimeTextByDay
  605. }
  606. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  607. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  608. if resultTimeStart.After(time.Now()) {
  609. v.ActiveState = "1"
  610. } else if time.Now().After(resultTimeEnd) {
  611. v.ActiveState = "3"
  612. } else {
  613. v.ActiveState = "2"
  614. }
  615. v.ImgUrl = imgUrlResp
  616. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  617. }
  618. }
  619. //处理路演 处理路活动视频 处理路活音频
  620. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds) > 0 {
  621. audioIdstr := strings.Join(activityvoiceIds, ",")
  622. ideoIdsStr := strings.Join(roadshowIds, ",")
  623. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  624. list, _, e := GetMicroRoadShowMycollect(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds), 0, audioIdstr, ideoIdsStr, activityVideoIdsStr)
  625. if e != nil {
  626. err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
  627. return
  628. }
  629. fmt.Println("list", list)
  630. for _, item := range list {
  631. if item.Type == 1 {
  632. //音频
  633. count, e := models.GetVoiceCollectCount(user.UserId, item.Id)
  634. if e != nil {
  635. err = errors.New("GetVoiceCollectCount, Err: " + e.Error())
  636. return
  637. }
  638. if count > 0 {
  639. item.IsCollect = true
  640. }
  641. } else if item.Type == 2 {
  642. //活动视频
  643. count, e := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  644. if e != nil {
  645. err = errors.New("GetActivityVideoCollectCount, Err: " + e.Error())
  646. return
  647. }
  648. if count > 0 {
  649. item.IsCollect = true
  650. }
  651. } else if item.Type == 3 {
  652. //微路演视频
  653. count, e := models.GetVideoCollectCount(user.UserId, item.Id)
  654. if e != nil {
  655. err = errors.New("GetVideoCollectCount, Err: " + e.Error())
  656. return
  657. }
  658. if count > 0 {
  659. item.IsCollect = true
  660. }
  661. }
  662. }
  663. // 用户权限
  664. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  665. if e != nil {
  666. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  667. return
  668. }
  669. // 获取默认图配置
  670. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  671. if e != nil {
  672. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  673. return
  674. }
  675. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  676. for i := range list {
  677. // 权限
  678. au := new(models.UserPermissionAuthInfo)
  679. au.SellerName = authInfo.SellerName
  680. au.SellerMobile = authInfo.SellerMobile
  681. au.HasPermission = authInfo.HasPermission
  682. au.OperationMode = authInfo.OperationMode
  683. if au.HasPermission == 1 {
  684. // 非宏观权限进一步判断是否有权限
  685. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  686. au.HasPermission = 2
  687. }
  688. }
  689. // 无权限的弹框提示
  690. if au.HasPermission != 1 {
  691. if au.OperationMode == UserPermissionOperationModeCall {
  692. if list[i].Type == 1 {
  693. au.PopupMsg = UserPermissionPopupMsgCallActivity
  694. } else {
  695. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  696. }
  697. } else {
  698. if list[i].Type == 1 {
  699. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  700. } else {
  701. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  702. }
  703. }
  704. }
  705. list[i].AuthInfo = au
  706. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  707. // 默认图
  708. if list[i].BackgroundImg == "" {
  709. if list[i].Type == 1 {
  710. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  711. } else {
  712. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  713. }
  714. }
  715. // 分享图
  716. if list[i].ShareImg == "" {
  717. if list[i].Type == 1 {
  718. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  719. } else {
  720. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  721. }
  722. }
  723. }
  724. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  725. for _, item := range list {
  726. if item.Type == 1 {
  727. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  728. } else if item.Type == 2 {
  729. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  730. } else if item.Type == 3 {
  731. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  732. }
  733. }
  734. }
  735. for _, vList := range list {
  736. for _, v := range mapItems {
  737. //如果这些类型都为空,那么就不合并
  738. 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 {
  739. continue
  740. }
  741. if v.Article != nil && v.SourceId == vList.SourceId {
  742. v.Article.Title = vList.Title
  743. }
  744. if v.Newchart != nil && v.SourceId == vList.SourceId {
  745. v.Newchart.Title = vList.Title
  746. }
  747. if v.Roadshow != nil && v.SourceId == vList.SourceId {
  748. v.Roadshow.Title = vList.Title
  749. }
  750. if v.Activity != nil && v.SourceId == vList.SourceId {
  751. v.Activity.ActivityName = vList.Title
  752. }
  753. if v.Activityvideo != nil && v.SourceId == vList.SourceId {
  754. v.Activityvideo.Title = vList.Title
  755. }
  756. if v.Activityvoice != nil && v.SourceId == vList.SourceId {
  757. v.Activityvoice.Title = vList.Title
  758. }
  759. if v.Activityspecial != nil && v.SourceId == vList.SourceId {
  760. v.Activityspecial.ResearchTheme = vList.Title
  761. }
  762. if v.Researchsummary != nil && v.SourceId == vList.SourceId {
  763. v.Researchsummary.Title = vList.Title
  764. }
  765. if v.Minutessummary != nil && v.SourceId == vList.SourceId {
  766. v.Minutessummary.Title = vList.Title
  767. }
  768. if v.ProductInterior != nil && v.SourceId == vList.SourceId {
  769. v.ProductInterior.Title = vList.Title
  770. }
  771. if v.IndustrialResource != nil && v.SourceId == vList.SourceId && v.Source == vList.Source {
  772. v.IndustrialResource.UpdateTime = strings.Replace(vList.PublishDate, "00:00:00", "", -1)
  773. }
  774. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  775. items = append(items, v)
  776. }
  777. }
  778. }
  779. for _, v := range items {
  780. if v.IndustrialResource != nil {
  781. v.Source = "industrialsource"
  782. }
  783. }
  784. return
  785. }