es_comprehensive.go 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639
  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_cygx/models"
  11. "hongze/hongze_cygx/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. //func init() {
  44. // //AddComprehensiveIndustrialSource("Hz", 0)
  45. // AddComprehensiveRoadshow()
  46. //}
  47. // 添加文章:报告、纪要
  48. func AddComprehensiveArticle(articleId int) {
  49. var err error
  50. defer func() {
  51. if err != nil {
  52. fmt.Println(err)
  53. go utils.SendAlarmMsg("删除数据综合页面数据Es失败"+err.Error(), 2)
  54. }
  55. }()
  56. var condition string
  57. var pars []interface{}
  58. condition += ` AND publish_status = 1 `
  59. if articleId > 0 {
  60. condition = ` AND article_id = ? `
  61. pars = append(pars, articleId)
  62. }
  63. articleList, e := models.GetArticleList(condition, pars)
  64. if e != nil {
  65. err = errors.New("GetArticleList, Err: " + e.Error())
  66. return
  67. }
  68. //indexName := utils.IndexNameComprehensive
  69. for _, v := range articleList {
  70. content := html.UnescapeString(v.Body)
  71. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  72. if err != nil {
  73. fmt.Println("create doc err:", err.Error())
  74. return
  75. }
  76. bodyText := doc.Text()
  77. item := new(ElasticComprehensiveDetail)
  78. item.SourceId = v.ArticleId
  79. item.IsSummary = v.IsSummary
  80. item.Source = "article"
  81. item.Title = v.Title
  82. item.PublishDate = v.PublishDate
  83. item.BodyText = bodyText
  84. item.Annotation, _ = GetReportContentTextSubNew(v.Annotation)
  85. item.Abstract, _ = GetReportContentTextSubNew(v.Abstract)
  86. EsAddOrEditComprehensiveData(item)
  87. fmt.Println(v.ArticleId)
  88. }
  89. }
  90. // 添加图表
  91. func AddComprehensiveChart(chartId int) {
  92. var err error
  93. defer func() {
  94. if err != nil {
  95. fmt.Println(err)
  96. go utils.SendAlarmMsg("AddComprehensiveChart Err"+err.Error()+fmt.Sprint(chartId), 2)
  97. }
  98. }()
  99. var condition string
  100. var pars []interface{}
  101. condition += ` AND publish_status = 1 `
  102. if chartId > 0 {
  103. condition = ` AND chart_id = ? `
  104. pars = append(pars, chartId)
  105. }
  106. list, e := models.GetChartList(condition, pars, 0, 1000000)
  107. if e != nil {
  108. err = errors.New("GetChartList, Err: " + e.Error())
  109. return
  110. }
  111. //indexName := utils.IndexNameComprehensive
  112. for _, v := range list {
  113. item := new(ElasticComprehensiveDetail)
  114. item.SourceId = v.ChartId
  115. item.Source = "newchart"
  116. item.Title = v.Title
  117. item.PublishDate = v.CreateDate
  118. EsAddOrEditComprehensiveData(item)
  119. fmt.Println(v.ChartId)
  120. }
  121. }
  122. // 添加产业资源包
  123. func AddComprehensiveIndustrialSource(sourceType string, articleId int) {
  124. var err error
  125. defer func() {
  126. if err != nil {
  127. fmt.Println(err)
  128. go utils.SendAlarmMsg("AddComprehensiveIndustrialSource"+err.Error(), 2)
  129. }
  130. }()
  131. var condition string
  132. var pars []interface{}
  133. mapActivitySubject := make(map[int][]string, 0)
  134. listsubject, e := models.GetCygxIndustrialSubjectListCondition(condition, pars)
  135. if e != nil {
  136. err = errors.New("GetIndustrialManagementRepList, Err: " + e.Error())
  137. return
  138. }
  139. for _, v := range listsubject {
  140. mapActivitySubject[v.IndustrialManagementId] = append(mapActivitySubject[v.IndustrialManagementId], v.SubjectName)
  141. }
  142. var industrialsource string
  143. if sourceType == "Hz" {
  144. condition = " AND a.article_type_id = 0 " // 弘则资源包
  145. industrialsource = "industrialsourceHz"
  146. } else {
  147. condition = " AND a.article_type_id > 0 " //研选资源包
  148. industrialsource = "industrialsourceYx"
  149. }
  150. if articleId > 0 {
  151. condition += " AND a.article_id = " + strconv.Itoa(articleId)
  152. }
  153. list, err := models.GetSearchResourceList(0, condition, 0, 0)
  154. if err != nil {
  155. fmt.Println(err)
  156. return
  157. }
  158. //indexName := utils.IndexNameComprehensive
  159. for _, v := range list {
  160. item := new(ElasticComprehensiveDetail)
  161. item.SourceId = v.IndustrialManagementId
  162. item.Source = industrialsource
  163. item.IndustryName = v.IndustryName
  164. item.SubjectNames = strings.Join(mapActivitySubject[v.IndustrialManagementId], ",")
  165. item.PublishDate = v.PublishDate + " 00:00:00"
  166. EsAddOrEditComprehensiveData(item)
  167. fmt.Println(item)
  168. }
  169. }
  170. // 添加晨会精华
  171. func AddComprehensiveMeetingreviewchapt() {
  172. var condition string
  173. var pars []interface{}
  174. IndustrialManagementRespMap, _ := GetIndustrialManagementRespMap()
  175. list, err := models.GetCygxMorningMeetingReviewChapterList(condition, pars)
  176. if err != nil {
  177. fmt.Println(err)
  178. return
  179. }
  180. //indexName := utils.IndexNameComprehensive
  181. for _, v := range list {
  182. content := html.UnescapeString(v.Content)
  183. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  184. if err != nil {
  185. fmt.Println("create doc err:", err.Error())
  186. return
  187. }
  188. bodyText := doc.Text()
  189. item := new(ElasticComprehensiveDetail)
  190. item.SourceId = v.Id
  191. item.Source = "meetingreviewchapt"
  192. item.IndustryName = IndustrialManagementRespMap[v.IndustryId]
  193. item.PublishDate = v.PublishTime
  194. item.BodyText = bodyText
  195. EsAddOrEditComprehensiveData(item)
  196. fmt.Println(item)
  197. }
  198. }
  199. // 添加活动
  200. func AddComprehensiveActivity() {
  201. var condition string
  202. var pars []interface{}
  203. condition = ` AND publish_status = 1 `
  204. //condition = ` AND publish_status = 1 AND activity_id = 2407 `
  205. list, err := models.GetCygxActivityList(condition, pars, 0, 100000)
  206. if err != nil {
  207. fmt.Println(err)
  208. return
  209. }
  210. IndustrialManagementRespMap, _ := GetIndustrialManagementRespMap()
  211. IndustrialSubjectMap, _ := GetCygxIndustrialSubjectMap()
  212. var condition1 string
  213. var pars1 []interface{}
  214. mapActivityIndustrialManagement := make(map[int][]string)
  215. industrialgroupList, e := models.GetCygxIndustrialActivityGroupManagementList(condition1+" AND source = 1 ", pars1)
  216. if e != nil {
  217. fmt.Println(e)
  218. return
  219. }
  220. for _, v := range industrialgroupList {
  221. if v.ActivityId == 0 {
  222. continue
  223. }
  224. mapActivityIndustrialManagement[v.ActivityId] = append(mapActivityIndustrialManagement[v.ActivityId], IndustrialManagementRespMap[v.IndustrialManagementId])
  225. }
  226. mapActivitySubject := make(map[int][]string)
  227. SubjectgroupList, e := models.GetCygxIndustrialActivityGroupSubjectList(condition1+" AND source = 1 ", pars1)
  228. if e != nil {
  229. fmt.Println(e)
  230. return
  231. }
  232. for _, v := range SubjectgroupList {
  233. if v.ActivityId == 0 {
  234. continue
  235. }
  236. mapActivitySubject[v.ActivityId] = append(mapActivitySubject[v.ActivityId], IndustrialSubjectMap[v.IndustrialSubjectId])
  237. }
  238. fmt.Println(mapActivitySubject[141])
  239. fmt.Println(mapActivityIndustrialManagement[141])
  240. //return
  241. for _, v := range list {
  242. item := new(ElasticComprehensiveDetail)
  243. item.SourceId = v.ActivityId
  244. //item.IsSummary = v.IsSummary
  245. item.Source = "activity"
  246. //item.SubjectNames = json.Sprint(mapActivitySubject[v.ActivityId])
  247. item.SubjectNames = strings.Join(mapActivitySubject[v.ActivityId], ",")
  248. item.IndustryName = strings.Join(mapActivityIndustrialManagement[v.ActivityId], ",")
  249. item.Title = v.ActivityName
  250. item.PublishDate = v.ActivityTime
  251. //item.BodyText = bodyText
  252. //item.Annotation, _ = GetReportContentTextSubNew(v.Annotation)
  253. //item.Abstract, _ = GetReportContentTextSubNew(v.Abstract)
  254. //EsAddOrEditComprehensiveData(indexName, item)
  255. EsAddOrEditComprehensiveData(item)
  256. fmt.Println(item)
  257. }
  258. }
  259. // 添加专项调研活动
  260. func AddComprehensiveActivitySpecial() {
  261. var condition string
  262. var pars []interface{}
  263. condition = ` AND publish_status = 1 `
  264. list, err := models.GetActivitySpecialListAll(condition, pars, 0, 100000)
  265. if err != nil {
  266. fmt.Println(err)
  267. return
  268. }
  269. //indexName := utils.IndexNameComprehensive
  270. IndustrialManagementRespMap, _ := GetIndustrialManagementRespMap() // 产业标签
  271. IndustrialSubjectMap, _ := GetCygxIndustrialSubjectMap() // 标的标签
  272. var condition1 string
  273. var pars1 []interface{}
  274. mapActivityIndustrialManagement := make(map[int][]string)
  275. industrialgroupList, e := models.GetCygxIndustrialActivityGroupManagementList(condition1+" AND source = 2 ", pars1)
  276. if e != nil {
  277. fmt.Println(e)
  278. return
  279. }
  280. for _, v := range industrialgroupList {
  281. if v.ActivityId == 0 {
  282. continue
  283. }
  284. mapActivityIndustrialManagement[v.ActivityId] = append(mapActivityIndustrialManagement[v.ActivityId], IndustrialManagementRespMap[v.IndustrialManagementId])
  285. }
  286. mapActivitySubject := make(map[int][]string)
  287. SubjectgroupList, e := models.GetCygxIndustrialActivityGroupSubjectList(condition1+" AND source = 2 ", pars1)
  288. if e != nil {
  289. fmt.Println(e)
  290. return
  291. }
  292. for _, v := range SubjectgroupList {
  293. if v.ActivityId == 0 {
  294. continue
  295. }
  296. mapActivitySubject[v.ActivityId] = append(mapActivitySubject[v.ActivityId], IndustrialSubjectMap[v.IndustrialSubjectId])
  297. }
  298. for _, v := range list {
  299. item := new(ElasticComprehensiveDetail)
  300. item.SourceId = v.ActivityId
  301. item.Source = "activityspecial"
  302. item.Title = v.ResearchTheme
  303. item.PublishDate = v.ActivityTime
  304. if v.ActivityTime == utils.FormatDateTimeInit {
  305. item.PublishDate = v.LastUpdatedTime.Format(utils.FormatDateTime)
  306. } else {
  307. item.PublishDate = v.ActivityTime
  308. }
  309. item.SubjectNames = strings.Join(mapActivitySubject[v.ActivityId], ",")
  310. item.IndustryName = strings.Join(mapActivityIndustrialManagement[v.ActivityId], ",")
  311. EsAddOrEditComprehensiveData(item)
  312. }
  313. }
  314. // 添加活动视频
  315. func AddComprehensiveActivityVideo() {
  316. var err error
  317. defer func() {
  318. if err != nil {
  319. fmt.Println(err)
  320. go utils.SendAlarmMsg("添加活动视频综合页面数据Es失败"+err.Error(), 2)
  321. }
  322. }()
  323. var condition string
  324. var pars []interface{}
  325. list, e := models.GetActivityVideoListAll(condition, pars, 0, 100000)
  326. if e != nil {
  327. err = errors.New("GetActivityVideoListAll, Err: " + e.Error())
  328. return
  329. }
  330. if len(list) == 0 {
  331. return
  332. }
  333. var activityIds []int
  334. for _, v := range list {
  335. activityIds = append(activityIds, v.ActivityId)
  336. }
  337. pars = make([]interface{}, 0)
  338. condition = ` AND publish_status = 1 AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
  339. pars = append(pars, activityIds)
  340. listArt, e := models.GetCygxActivityList(condition, pars, 0, 100000)
  341. if e != nil {
  342. err = errors.New("GetCygxActivityList, Err: " + e.Error())
  343. return
  344. }
  345. mapActivity := make(map[int]string)
  346. for _, v := range listArt {
  347. mapActivity[v.ActivityId] = v.ActivityName
  348. }
  349. IndustrialManagementRespMap, _ := GetIndustrialManagementRespMap()
  350. IndustrialSubjectMap, _ := GetCygxIndustrialSubjectMap()
  351. var condition1 string
  352. var pars1 []interface{}
  353. mapActivityIndustrialManagement := make(map[int][]string)
  354. industrialgroupList, e := models.GetCygxIndustrialActivityGroupManagementList(condition1+" AND source = 1 ", pars1)
  355. if e != nil {
  356. fmt.Println(e)
  357. return
  358. }
  359. //产业名称
  360. for _, v := range industrialgroupList {
  361. if v.ActivityId == 0 {
  362. continue
  363. }
  364. mapActivityIndustrialManagement[v.ActivityId] = append(mapActivityIndustrialManagement[v.ActivityId], IndustrialManagementRespMap[v.IndustrialManagementId])
  365. }
  366. //标的名称
  367. mapActivitySubject := make(map[int][]string)
  368. SubjectgroupList, e := models.GetCygxIndustrialActivityGroupSubjectList(condition1+" AND source = 1 ", pars1)
  369. if e != nil {
  370. fmt.Println(e)
  371. return
  372. }
  373. for _, v := range SubjectgroupList {
  374. if v.ActivityId == 0 {
  375. continue
  376. }
  377. mapActivitySubject[v.ActivityId] = append(mapActivitySubject[v.ActivityId], IndustrialSubjectMap[v.IndustrialSubjectId])
  378. }
  379. //indexName := utils.IndexNameComprehensive
  380. for _, v := range list {
  381. item := new(ElasticComprehensiveDetail)
  382. item.SourceId = v.ActivityId
  383. item.Source = "activityvideo"
  384. item.Title = v.Title
  385. item.PublishDate = v.ActivityTime
  386. item.BodyText = mapActivity[v.ActivityId]
  387. item.SubjectNames = strings.Join(mapActivitySubject[v.ActivityId], ",")
  388. item.IndustryName = strings.Join(mapActivityIndustrialManagement[v.ActivityId], ",")
  389. EsAddOrEditComprehensiveData(item)
  390. fmt.Println(item)
  391. }
  392. }
  393. // 添加活动音频
  394. func AddComprehensiveActivityVoice() {
  395. var err error
  396. defer func() {
  397. if err != nil {
  398. fmt.Println(err)
  399. go utils.SendAlarmMsg("AddComprehensiveActivityVoice"+err.Error(), 2)
  400. }
  401. }()
  402. var condition string
  403. var pars []interface{}
  404. list, err := models.GetActivityVoiceList(condition, pars, 0, 100000)
  405. if err != nil {
  406. fmt.Println(err)
  407. return
  408. }
  409. if len(list) == 0 {
  410. return
  411. }
  412. var activityIds []int
  413. for _, v := range list {
  414. activityIds = append(activityIds, v.ActivityId)
  415. }
  416. pars = make([]interface{}, 0)
  417. condition = ` AND publish_status = 1 AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
  418. pars = append(pars, activityIds)
  419. listArt, e := models.GetCygxActivityList(condition, pars, 0, 100000)
  420. if e != nil {
  421. err = errors.New("GetCygxActivityList, Err: " + e.Error())
  422. return
  423. }
  424. mapActivity := make(map[int]string)
  425. for _, v := range listArt {
  426. mapActivity[v.ActivityId] = v.ActivityName
  427. }
  428. IndustrialManagementRespMap, _ := GetIndustrialManagementRespMap()
  429. IndustrialSubjectMap, _ := GetCygxIndustrialSubjectMap()
  430. var condition1 string
  431. var pars1 []interface{}
  432. mapActivityIndustrialManagement := make(map[int][]string)
  433. industrialgroupList, e := models.GetCygxIndustrialActivityGroupManagementList(condition1+" AND source = 1 ", pars1)
  434. if e != nil {
  435. fmt.Println(e)
  436. return
  437. }
  438. //产业名称
  439. for _, v := range industrialgroupList {
  440. if v.ActivityId == 0 {
  441. continue
  442. }
  443. mapActivityIndustrialManagement[v.ActivityId] = append(mapActivityIndustrialManagement[v.ActivityId], IndustrialManagementRespMap[v.IndustrialManagementId])
  444. }
  445. //标的名称
  446. mapActivitySubject := make(map[int][]string)
  447. SubjectgroupList, e := models.GetCygxIndustrialActivityGroupSubjectList(condition1+" AND source = 1 ", pars1)
  448. if e != nil {
  449. fmt.Println(e)
  450. return
  451. }
  452. for _, v := range SubjectgroupList {
  453. if v.ActivityId == 0 {
  454. continue
  455. }
  456. mapActivitySubject[v.ActivityId] = append(mapActivitySubject[v.ActivityId], IndustrialSubjectMap[v.IndustrialSubjectId])
  457. }
  458. //indexName := utils.IndexNameComprehensive
  459. for _, v := range list {
  460. item := new(ElasticComprehensiveDetail)
  461. item.SourceId = v.ActivityId
  462. item.Source = "activityvoice"
  463. item.Title = v.VoiceName
  464. item.PublishDate = v.ActivityTime
  465. item.BodyText = mapActivity[v.ActivityId]
  466. item.SubjectNames = strings.Join(mapActivitySubject[v.ActivityId], ",")
  467. item.IndustryName = strings.Join(mapActivityIndustrialManagement[v.ActivityId], ",")
  468. EsAddOrEditComprehensiveData(item)
  469. fmt.Println(item)
  470. }
  471. }
  472. // 微路演
  473. func AddComprehensiveRoadshow() {
  474. var condition string
  475. var pars []interface{}
  476. IndustrialManagementRespMap, _ := GetIndustrialManagementRespMap()
  477. list, err := models.GetMicroRoadshowVideoListBycondition(condition, pars, 0, 100000)
  478. if err != nil {
  479. fmt.Println(err)
  480. return
  481. }
  482. //indexName := utils.IndexNameComprehensive
  483. for _, v := range list {
  484. item := new(ElasticComprehensiveDetail)
  485. item.SourceId = v.VideoId
  486. item.Source = "roadshow"
  487. item.IndustryName = IndustrialManagementRespMap[v.IndustryId]
  488. item.Title = v.VideoName
  489. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  490. EsAddOrEditComprehensiveData(item)
  491. fmt.Println(item)
  492. }
  493. }
  494. // 新增和修改数据
  495. func EsAddOrEditComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  496. indexName := utils.IndexNameComprehensive
  497. //return
  498. defer func() {
  499. if err != nil {
  500. fmt.Println(err, item.SourceId)
  501. //go utils.SendAlarmMsg("更新综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  502. }
  503. }()
  504. client := utils.Client
  505. mustMap := make([]interface{}, 0)
  506. mustMap = append(mustMap, map[string]interface{}{
  507. "term": map[string]interface{}{
  508. "SourceId": item.SourceId,
  509. },
  510. })
  511. mustMap = append(mustMap, map[string]interface{}{
  512. "term": map[string]interface{}{
  513. "Source": item.Source,
  514. },
  515. })
  516. queryMap := map[string]interface{}{
  517. "query": map[string]interface{}{
  518. "bool": map[string]interface{}{
  519. "must": mustMap,
  520. },
  521. },
  522. }
  523. requestTotalHits := client.Count(indexName).BodyJson(queryMap)
  524. total, e := requestTotalHits.Do(context.Background())
  525. if e != nil {
  526. err = errors.New("requestTotalHits.Do(context.Background()), Err: " + e.Error())
  527. return
  528. }
  529. //return
  530. //根据来源以及ID ,判断内容是否存在,如果存在就新增,如果不存在就修改
  531. if total == 0 {
  532. resp, e := client.Index().Index(indexName).BodyJson(item).Do(context.Background())
  533. if e != nil {
  534. err = errors.New("client.Index().Index(indexName).BodyJson(item).Do(context.Background()), Err: " + e.Error())
  535. return
  536. }
  537. if resp.Status == 0 && resp.Result == "created" {
  538. //fmt.Println("新增成功")
  539. //err = nil
  540. return
  541. } else {
  542. //err = errors.New(fmt.Sprint(resp))
  543. err = errors.New(fmt.Sprint("articleId", item.SourceId))
  544. return
  545. }
  546. } else {
  547. //拼接需要改动的前置条件
  548. bool_query := elastic.NewBoolQuery()
  549. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  550. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  551. //设置需要改动的内容
  552. var script string
  553. script += fmt.Sprint("ctx._source['SubjectNames'] = '", item.SubjectNames, "';")
  554. script += fmt.Sprint("ctx._source['PublishDate'] = '", item.PublishDate, "';")
  555. script += fmt.Sprint("ctx._source['IsSummary'] = ", item.IsSummary, ";")
  556. script += fmt.Sprint("ctx._source['Abstract'] = '", item.Abstract, "';")
  557. script += fmt.Sprint("ctx._source['Title'] = '", item.Title, "';")
  558. script += fmt.Sprint("ctx._source['BodyText'] = '", item.BodyText, "';")
  559. script += fmt.Sprint("ctx._source['Annotation'] = '", item.Annotation, "';")
  560. script += fmt.Sprint("ctx._source['IndustryName'] = '", item.IndustryName, "'")
  561. _, e = client.UpdateByQuery(indexName).
  562. Query(bool_query).
  563. Script(elastic.NewScriptInline(script)).
  564. Refresh("true").
  565. Do(context.Background())
  566. if e != nil && e.Error() != "elastic: Error 400 (Bad Request): compile error [type=script_exception]" {
  567. //文本内容过长的时候,修改会报 400 的错误,暂时先不处理
  568. //fmt.Println("err", e.Error())
  569. ////err = e
  570. //err = errors.New("client.UpdateByQuery(indexName), Err: " + e.Error())
  571. return
  572. }
  573. }
  574. return
  575. }
  576. // 删除数据
  577. func EsDeleteComprehensiveData(item *ElasticComprehensiveDetail) (err error) {
  578. defer func() {
  579. if err != nil {
  580. fmt.Println(err)
  581. go utils.SendAlarmMsg("删除数据综合页面数据Es失败"+err.Error()+fmt.Sprint(item), 2)
  582. }
  583. }()
  584. indexName := utils.IndexNameComprehensive
  585. client := utils.Client
  586. //拼接需要删除的前置条件
  587. bool_query := elastic.NewBoolQuery()
  588. bool_query.Must(elastic.NewTermQuery("SourceId", item.SourceId))
  589. bool_query.Must(elastic.NewTermQuery("Source", item.Source))
  590. _, e := client.DeleteByQuery(indexName).
  591. Query(bool_query).
  592. Do(context.Background())
  593. if e != nil {
  594. err = errors.New(" client.DeleteByQuery(indexName), Err: " + e.Error())
  595. return
  596. }
  597. return
  598. }
  599. //func EsComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int64, err error) {
  600. // indexName := utils.IndexNameComprehensive
  601. // client := utils.Client
  602. // var keyWordArr []string
  603. // keyWordArr = append(keyWordArr, keyWord)
  604. //
  605. // //Es 的高级查询有 自定义排序 文档一时半会儿撸不懂,先做多次查询手动过滤 2023.2.2
  606. // //ikType 查询方式 ,0:查所有 、 1:查询键入词 、 2:查询除了查询键入词之外的联想词
  607. // mustMap := make([]interface{}, 0)
  608. // shouldMap := make(map[string]interface{}, 0)
  609. // shouldMapquery := make([]interface{}, 0)
  610. //
  611. // mustNotMap := make([]interface{}, 0)
  612. // shouldNotMap := make(map[string]interface{}, 0)
  613. // shouldNotMapquery := make([]interface{}, 0)
  614. // var boost int
  615. // //lenkeyWordArr := len(keyWordArr)
  616. // for k, v := range keyWordArr {
  617. // if k > 0 {
  618. // continue
  619. // }
  620. // if k == 0 {
  621. // boost = 2 * 1000
  622. // } else {
  623. // boost = 1
  624. // }
  625. //
  626. // if v != "" {
  627. // shouldMapquery = append(shouldMapquery, map[string]interface{}{
  628. // "function_score": map[string]interface{}{
  629. // "query": map[string]interface{}{
  630. // "multi_match": map[string]interface{}{
  631. // //"boost": (lenkeyWordArr - k) * boost, //给查询的值赋予权重
  632. // "boost": boost, //给查询的值赋予权重
  633. // "fields": []interface{}{"Title"},
  634. // "query": v,
  635. // },
  636. // },
  637. // },
  638. // })
  639. // shouldMapquery = append(shouldMapquery, map[string]interface{}{
  640. // "function_score": map[string]interface{}{
  641. // "query": map[string]interface{}{
  642. // "multi_match": map[string]interface{}{
  643. // "boost": boost, //给查询的值赋予权重
  644. // "fields": []interface{}{"Abstract"},
  645. // "query": v,
  646. // },
  647. // },
  648. // },
  649. // })
  650. // shouldMapquery = append(shouldMapquery, map[string]interface{}{
  651. // "function_score": map[string]interface{}{
  652. // "query": map[string]interface{}{
  653. // "multi_match": map[string]interface{}{
  654. // "boost": boost, //给查询的值赋予权重
  655. // "fields": []interface{}{"Annotation"},
  656. // "query": v,
  657. // },
  658. // },
  659. // },
  660. // })
  661. //
  662. // shouldMapquery = append(shouldMapquery, map[string]interface{}{
  663. // "function_score": map[string]interface{}{
  664. // "query": map[string]interface{}{
  665. // "multi_match": map[string]interface{}{
  666. // //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  667. // "boost": boost, //给查询的值赋予权重
  668. // "fields": []interface{}{"BodyText"},
  669. // "query": v,
  670. // },
  671. // },
  672. // },
  673. // })
  674. //
  675. // shouldMapquery = append(shouldMapquery, map[string]interface{}{
  676. // "function_score": map[string]interface{}{
  677. // "query": map[string]interface{}{
  678. // "multi_match": map[string]interface{}{
  679. // //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  680. // "boost": boost, //给查询的值赋予权重
  681. // "fields": []interface{}{"IndustryName"},
  682. // "query": v,
  683. // },
  684. // },
  685. // },
  686. // })
  687. //
  688. // shouldMapquery = append(shouldMapquery, map[string]interface{}{
  689. // "function_score": map[string]interface{}{
  690. // "query": map[string]interface{}{
  691. // "multi_match": map[string]interface{}{
  692. // //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  693. // "boost": boost, //给查询的值赋予权重
  694. // "fields": []interface{}{"SubjectNames"},
  695. // "query": v,
  696. // },
  697. // },
  698. // },
  699. // })
  700. // }
  701. // }
  702. // shouldMap = map[string]interface{}{
  703. // "should": shouldMapquery,
  704. // }
  705. //
  706. // shouldNotMap = map[string]interface{}{
  707. // "should": shouldNotMapquery,
  708. // }
  709. // //排序
  710. // sortMap := make([]interface{}, 0)
  711. //
  712. // //时间
  713. // sortMap = append(sortMap, map[string]interface{}{
  714. // "PublishDate": map[string]interface{}{
  715. // "order": "desc",
  716. // },
  717. // })
  718. // //sortMap = append(sortMap, map[string]interface{}{
  719. // // "_score": map[string]interface{}{
  720. // // "order": "desc",
  721. // // },
  722. // //})
  723. // //高亮
  724. // highlightMap := make(map[string]interface{}, 0)
  725. // highlightMap = map[string]interface{}{
  726. // "fields": map[string]interface{}{
  727. // "BodyText": map[string]interface{}{},
  728. // "Title": map[string]interface{}{},
  729. // "Abstract": map[string]interface{}{},
  730. // "Annotation": map[string]interface{}{},
  731. // },
  732. // //样式 红色
  733. // "post_tags": []interface{}{"</font>"},
  734. // "pre_tags": []interface{}{"<font color='red'>"},
  735. // "fragment_size": 50,
  736. // }
  737. //
  738. // mustMap = append(mustMap, map[string]interface{}{
  739. // "bool": shouldMap,
  740. // })
  741. //
  742. // mustNotMap = append(mustNotMap, map[string]interface{}{
  743. // "term": shouldNotMap,
  744. // })
  745. // //mustMap = append(mustMap, map[string]interface{}{
  746. // // "term": map[string]interface{}{
  747. // // "IsSummary": "1",
  748. // // },
  749. // //})
  750. // queryMap := map[string]interface{}{
  751. // "query": map[string]interface{}{
  752. // "bool": map[string]interface{}{
  753. // "must": mustMap,
  754. // },
  755. // },
  756. // }
  757. //
  758. // queryMap["sort"] = sortMap
  759. // queryMap["from"] = startSize
  760. // queryMap["size"] = pageSize
  761. // queryMap["highlight"] = highlightMap
  762. // //jsonBytes, _ := json.Marshal(queryMap)
  763. // //fmt.Println(string(jsonBytes))
  764. // //utils.FileLog.Info(string(jsonBytes))
  765. // request := client.Search(indexName).Source(queryMap) // sets the JSON request
  766. // searchByMatch, err := request.Do(context.Background())
  767. // if searchByMatch != nil {
  768. // if searchByMatch.Hits != nil {
  769. // for _, v := range searchByMatch.Hits.Hits {
  770. // var isAppend bool
  771. // articleJson, err := v.Source.MarshalJSON()
  772. // if err != nil {
  773. // return nil, 0, err
  774. // }
  775. // article := new(ElasticComprehensiveDetail)
  776. // err = json.Unmarshal(articleJson, &article)
  777. // if err != nil {
  778. // return nil, 0, err
  779. // }
  780. // //fmt.Println(article.SourceId, article.Title, article.Source)
  781. // searchItem := new(SearchComprehensiveItem)
  782. // searchItem.SourceId = article.SourceId
  783. // if len(v.Highlight["Annotation"]) > 0 {
  784. // for _, vText := range v.Highlight["Annotation"] {
  785. // searchItem.Body = append(searchItem.Body, vText)
  786. // }
  787. // }
  788. // if len(v.Highlight["Abstract"]) > 0 {
  789. // for _, vText := range v.Highlight["Abstract"] {
  790. // searchItem.Body = append(searchItem.Body, vText)
  791. // }
  792. // }
  793. // if len(v.Highlight["BodyText"]) > 0 {
  794. // for _, vText := range v.Highlight["BodyText"] {
  795. // searchItem.Body = append(searchItem.Body, vText)
  796. // }
  797. // }
  798. // searchItem.IsSummary = article.IsSummary
  799. // if len(searchItem.Body) == 0 {
  800. // bodyRune := []rune(article.BodyText)
  801. // bodyRuneLen := len(bodyRune)
  802. // if bodyRuneLen > 100 {
  803. // bodyRuneLen = 100
  804. // }
  805. // body := string(bodyRune[:bodyRuneLen])
  806. // searchItem.Body = []string{body}
  807. // }
  808. // var title string
  809. // if len(v.Highlight["Title"]) > 0 {
  810. // title = v.Highlight["Title"][0]
  811. // } else {
  812. // title = article.Title
  813. // }
  814. // searchItem.Title = title
  815. // searchItem.Source = article.Source
  816. // searchItem.PublishDate = article.PublishDate
  817. //
  818. // if !isAppend {
  819. // result = append(result, searchItem)
  820. // }
  821. // }
  822. // }
  823. // total = searchByMatch.Hits.TotalHits.Value
  824. // }
  825. // return
  826. //}
  827. func EsComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int64, err error) {
  828. indexName := utils.IndexNameComprehensive
  829. client := utils.Client
  830. keyWordArr, err := GetIndustryMapNameSliceV3(keyWord)
  831. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  832. keyWordLen := len(keyWordArr)
  833. if keyWordLen <= 0 {
  834. keyWordArr = append(keyWordArr, keyWord)
  835. keyWordLen = len(keyWordArr)
  836. }
  837. //Es 的高级查询有 自定义排序 文档一时半会儿撸不懂,先做多次查询手动过滤 2023.2.2
  838. //ikType 查询方式 ,0:查所有 、 1:查询键入词 、 2:查询除了查询键入词之外的联想词
  839. mustMap := make([]interface{}, 0)
  840. shouldMap := make(map[string]interface{}, 0)
  841. shouldMapquery := make([]interface{}, 0)
  842. mustNotMap := make([]interface{}, 0)
  843. shouldNotMap := make(map[string]interface{}, 0)
  844. shouldNotMapquery := make([]interface{}, 0)
  845. // @Param OrderColumn query int true "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
  846. //keyWordWeight := GetWeight(keyWordLen)
  847. var boost int
  848. //lenkeyWordArr := len(keyWordArr)
  849. for k, v := range keyWordArr {
  850. if k > 0 {
  851. continue
  852. }
  853. if k == 0 {
  854. boost = 2 * 1000
  855. } else {
  856. boost = 1
  857. }
  858. if v != "" {
  859. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  860. "function_score": map[string]interface{}{
  861. "query": map[string]interface{}{
  862. "multi_match": map[string]interface{}{
  863. //"boost": (lenkeyWordArr - k) * boost, //给查询的值赋予权重
  864. "boost": boost, //给查询的值赋予权重
  865. "fields": []interface{}{"Title"},
  866. "query": v,
  867. },
  868. },
  869. },
  870. })
  871. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  872. "function_score": map[string]interface{}{
  873. "query": map[string]interface{}{
  874. "multi_match": map[string]interface{}{
  875. "boost": boost, //给查询的值赋予权重
  876. "fields": []interface{}{"Abstract"},
  877. "query": v,
  878. },
  879. },
  880. },
  881. })
  882. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  883. "function_score": map[string]interface{}{
  884. "query": map[string]interface{}{
  885. "multi_match": map[string]interface{}{
  886. "boost": boost, //给查询的值赋予权重
  887. "fields": []interface{}{"Annotation"},
  888. "query": v,
  889. },
  890. },
  891. },
  892. })
  893. //shouldMapquery = append(shouldMapquery, map[string]interface{}{
  894. // "function_score": map[string]interface{}{
  895. // "query": map[string]interface{}{
  896. // "multi_match": map[string]interface{}{
  897. // //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  898. // "boost": boost, //给查询的值赋予权重
  899. // "fields": []interface{}{"BodyText"},
  900. // "query": v,
  901. // },
  902. // },
  903. // },
  904. //})
  905. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  906. "function_score": map[string]interface{}{
  907. "query": map[string]interface{}{
  908. "multi_match": map[string]interface{}{
  909. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  910. "boost": boost, //给查询的值赋予权重
  911. "fields": []interface{}{"IndustryName"},
  912. "query": v,
  913. },
  914. },
  915. },
  916. })
  917. shouldMapquery = append(shouldMapquery, map[string]interface{}{
  918. "function_score": map[string]interface{}{
  919. "query": map[string]interface{}{
  920. "multi_match": map[string]interface{}{
  921. //"boost": (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
  922. "boost": boost, //给查询的值赋予权重
  923. "fields": []interface{}{"SubjectNames"},
  924. "query": v,
  925. },
  926. },
  927. },
  928. })
  929. }
  930. }
  931. shouldMap = map[string]interface{}{
  932. "should": shouldMapquery,
  933. }
  934. shouldNotMap = map[string]interface{}{
  935. "should": shouldNotMapquery,
  936. }
  937. //排序
  938. sortMap := make([]interface{}, 0)
  939. //时间
  940. sortMap = append(sortMap, map[string]interface{}{
  941. "PublishDate": map[string]interface{}{
  942. "order": "desc",
  943. },
  944. })
  945. //sortMap = append(sortMap, map[string]interface{}{
  946. // "_score": map[string]interface{}{
  947. // "order": "desc",
  948. // },
  949. //})
  950. //高亮
  951. highlightMap := make(map[string]interface{}, 0)
  952. highlightMap = map[string]interface{}{
  953. "fields": map[string]interface{}{
  954. //"BodyText": map[string]interface{}{},
  955. "Title": map[string]interface{}{},
  956. "Abstract": map[string]interface{}{},
  957. "Annotation": map[string]interface{}{},
  958. },
  959. //样式 红色
  960. "post_tags": []interface{}{"</font>"},
  961. "pre_tags": []interface{}{"<font color='red'>"},
  962. "fragment_size": 50,
  963. }
  964. mustMap = append(mustMap, map[string]interface{}{
  965. "bool": shouldMap,
  966. })
  967. mustNotMap = append(mustNotMap, map[string]interface{}{
  968. "bool": shouldNotMap,
  969. })
  970. queryMap := map[string]interface{}{
  971. "query": map[string]interface{}{
  972. "bool": map[string]interface{}{
  973. "must": mustMap,
  974. },
  975. },
  976. }
  977. queryMap["sort"] = sortMap
  978. queryMap["from"] = startSize
  979. queryMap["size"] = pageSize
  980. queryMap["highlight"] = highlightMap
  981. //jsonBytes, _ := json.Marshal(queryMap)
  982. //fmt.Println(string(jsonBytes))
  983. //utils.FileLog.Info(string(jsonBytes))
  984. request := client.Search(indexName).Source(queryMap) // sets the JSON request
  985. searchByMatch, err := request.Do(context.Background())
  986. if searchByMatch != nil {
  987. if searchByMatch.Hits != nil {
  988. for _, v := range searchByMatch.Hits.Hits {
  989. var isAppend bool
  990. articleJson, err := v.Source.MarshalJSON()
  991. if err != nil {
  992. return nil, 0, err
  993. }
  994. article := new(ElasticComprehensiveDetail)
  995. err = json.Unmarshal(articleJson, &article)
  996. if err != nil {
  997. return nil, 0, err
  998. }
  999. //fmt.Println(article.SourceId, article.Title, article.Source)
  1000. searchItem := new(SearchComprehensiveItem)
  1001. searchItem.SourceId = article.SourceId
  1002. if len(v.Highlight["Annotation"]) > 0 {
  1003. for _, vText := range v.Highlight["Annotation"] {
  1004. searchItem.Body = append(searchItem.Body, vText)
  1005. }
  1006. }
  1007. if len(v.Highlight["Abstract"]) > 0 {
  1008. for _, vText := range v.Highlight["Abstract"] {
  1009. searchItem.Body = append(searchItem.Body, vText)
  1010. }
  1011. }
  1012. if len(v.Highlight["BodyText"]) > 0 {
  1013. for _, vText := range v.Highlight["BodyText"] {
  1014. searchItem.Body = append(searchItem.Body, vText)
  1015. }
  1016. }
  1017. //searchItem.IsSummary = article.IsSummary
  1018. if len(searchItem.Body) == 0 {
  1019. bodyRune := []rune(article.BodyText)
  1020. bodyRuneLen := len(bodyRune)
  1021. if bodyRuneLen > 100 {
  1022. bodyRuneLen = 100
  1023. }
  1024. body := string(bodyRune[:bodyRuneLen])
  1025. searchItem.Body = []string{body}
  1026. }
  1027. var title string
  1028. if len(v.Highlight["Title"]) > 0 {
  1029. title = v.Highlight["Title"][0]
  1030. } else {
  1031. title = article.Title
  1032. }
  1033. searchItem.Title = title
  1034. searchItem.Source = article.Source
  1035. searchItem.PublishDate = article.PublishDate
  1036. if !isAppend {
  1037. result = append(result, searchItem)
  1038. }
  1039. }
  1040. }
  1041. total = searchByMatch.Hits.TotalHits.Value
  1042. }
  1043. return
  1044. }
  1045. func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserItem) (items []*models.CygxResourceDataResp, err error) {
  1046. var condition string
  1047. var pars []interface{}
  1048. uid := user.UserId
  1049. titleHighlight := make(map[int]string)
  1050. bodyHighlight := make(map[int][]string)
  1051. //var bodyHighlight []string
  1052. mapItems := make(map[string]*models.CygxResourceDataResp)
  1053. for _, v := range list {
  1054. //预处理文章
  1055. item := new(models.CygxResourceDataResp)
  1056. item.SourceId = v.SourceId
  1057. item.Source = v.Source
  1058. //if v.IsSummary == 1 {
  1059. item.BodyHighlight = v.Body
  1060. titleHighlight[v.SourceId] = v.Title
  1061. bodyHighlight[v.SourceId] = v.Body
  1062. //fmt.Println(v.Title)
  1063. //} else {
  1064. // item.BodyHighlight = make([]string, 0)
  1065. //}
  1066. item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  1067. mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
  1068. }
  1069. var articleIds []int
  1070. var newchartIds []int
  1071. var roadshowIds []string
  1072. var activityIds []int
  1073. var activityvideoIds []string
  1074. var activityvoiceIds []string
  1075. var activityspecialIds []int
  1076. var researchsummaryIds []int
  1077. var minutessummaryIds []int
  1078. var meetingreviewchaptIds []int
  1079. var productinteriorIds []int
  1080. var industrialResourceIdsHz []int // 弘则产业资源包
  1081. var industrialResourceIdsYx []int // 研选产业资源包
  1082. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial 、 本周研究汇总: researchsummary 、 上周纪要汇总 :minutessummary 、晨会精华 :meetingreviewchapt "`
  1083. for _, v := range list {
  1084. if v.Source == "article" {
  1085. articleIds = append(articleIds, v.SourceId)
  1086. } else if v.Source == "newchart" {
  1087. newchartIds = append(newchartIds, v.SourceId)
  1088. } else if v.Source == "roadshow" {
  1089. roadshowIds = append(roadshowIds, strconv.Itoa(v.SourceId))
  1090. } else if v.Source == "activity" {
  1091. activityIds = append(activityIds, v.SourceId)
  1092. } else if v.Source == "activityvideo" {
  1093. activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
  1094. } else if v.Source == "activityvoice" {
  1095. activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
  1096. } else if v.Source == "activityspecial" {
  1097. activityspecialIds = append(activityspecialIds, v.SourceId)
  1098. } else if v.Source == "researchsummary" {
  1099. researchsummaryIds = append(researchsummaryIds, v.SourceId)
  1100. } else if v.Source == "minutessummary" {
  1101. minutessummaryIds = append(minutessummaryIds, v.SourceId)
  1102. } else if v.Source == "meetingreviewchapt" {
  1103. meetingreviewchaptIds = append(meetingreviewchaptIds, v.SourceId)
  1104. } else if v.Source == "productinterior" {
  1105. productinteriorIds = append(productinteriorIds, v.SourceId)
  1106. } else if v.Source == "industrialsourceHz" {
  1107. industrialResourceIdsHz = append(industrialResourceIdsHz, v.SourceId)
  1108. } else if v.Source == "industrialResourceIdsYx" {
  1109. industrialResourceIdsHz = append(industrialResourceIdsYx, v.SourceId)
  1110. }
  1111. }
  1112. //处理文章
  1113. if len(articleIds) > 0 {
  1114. pars = make([]interface{}, 0)
  1115. condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  1116. pars = append(pars, articleIds)
  1117. listArticle, e := models.GetHomeList(condition, pars, 0, len(articleIds))
  1118. if e != nil {
  1119. err = errors.New("GetResourceDataList, Err: " + e.Error())
  1120. return
  1121. }
  1122. listArticle, e = HandleArticleCategoryImg(listArticle)
  1123. if e != nil {
  1124. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  1125. return
  1126. }
  1127. for _, v := range listArticle {
  1128. v.Body = ""
  1129. v.BodyHtml = ""
  1130. if titleHighlight[v.ArticleId] != "" {
  1131. v.Title = titleHighlight[v.ArticleId]
  1132. }
  1133. if len(bodyHighlight[v.ArticleId]) > 0 {
  1134. v.Abstract = ""
  1135. v.Annotation = ""
  1136. v.BodyHighlight = bodyHighlight[v.ArticleId]
  1137. } else {
  1138. v.BodyHighlight = make([]string, 0)
  1139. }
  1140. mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
  1141. }
  1142. }
  1143. //处理晨会精华
  1144. if len(meetingreviewchaptIds) > 0 {
  1145. pars = make([]interface{}, 0)
  1146. condition = ` AND c.id IN (` + utils.GetOrmInReplace(len(meetingreviewchaptIds)) + `)`
  1147. pars = append(pars, meetingreviewchaptIds)
  1148. listrMeet, e := models.GetCygxMorningMeetingReviewChapterList(condition, pars)
  1149. if e != nil {
  1150. err = errors.New("GetResourceDataList, Err: " + e.Error())
  1151. return
  1152. }
  1153. for _, v := range listrMeet {
  1154. v.Content = AnnotationHtml(v.Content)
  1155. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  1156. mapItems[fmt.Sprint("meetingreviewchapt", v.Id)].Meetingreviewchapt = v
  1157. }
  1158. }
  1159. //处理上周纪要汇总
  1160. if len(minutessummaryIds) > 0 {
  1161. pars = make([]interface{}, 0)
  1162. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(minutessummaryIds)) + `)`
  1163. pars = append(pars, minutessummaryIds)
  1164. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_minutes_summary", pars, 0, len(minutessummaryIds))
  1165. if e != nil {
  1166. err = errors.New("GetResourceDataList, Err: " + e.Error())
  1167. return
  1168. }
  1169. for _, v := range listresearchsummary {
  1170. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  1171. mapItems[fmt.Sprint("minutessummary", v.ArticleId)].Minutessummary = v
  1172. }
  1173. }
  1174. //处理本周纪要汇总
  1175. if len(researchsummaryIds) > 0 {
  1176. pars = make([]interface{}, 0)
  1177. condition = ` AND article_id IN (` + utils.GetOrmInReplace(len(researchsummaryIds)) + `)`
  1178. pars = append(pars, researchsummaryIds)
  1179. listresearchsummary, e := models.GetReportSelectionListHome(condition, "cygx_research_summary", pars, 0, len(researchsummaryIds))
  1180. if e != nil {
  1181. err = errors.New("GetReportSelectionListHome, Err: " + e.Error())
  1182. return
  1183. }
  1184. for _, v := range listresearchsummary {
  1185. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  1186. mapItems[fmt.Sprint("researchsummary", v.ArticleId)].Researchsummary = v
  1187. }
  1188. }
  1189. //处理产品内测
  1190. if len(productinteriorIds) > 0 {
  1191. pars = make([]interface{}, 0)
  1192. condition = ` AND art.status = 1 AND art.product_interior_id IN (` + utils.GetOrmInReplace(len(productinteriorIds)) + `)`
  1193. pars = append(pars, productinteriorIds)
  1194. listProductInterior, e := models.GetCygxProductInteriorList(condition, pars, 0, len(productinteriorIds))
  1195. if e != nil {
  1196. err = errors.New("GetCygxProductInteriorList, Err: " + e.Error())
  1197. return
  1198. }
  1199. for _, v := range listProductInterior {
  1200. v.Body = ProductInteriorHtml(v.Body)
  1201. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  1202. mapItems[fmt.Sprint("productinterior", v.ProductInteriorId)].ProductInterior = v
  1203. }
  1204. }
  1205. detail, e := models.GetConfigByCode("city_img_url")
  1206. if e != nil {
  1207. err = errors.New("GetResourceDataList, Err: " + e.Error())
  1208. return
  1209. }
  1210. detailChart, e := models.GetConfigByCode("chart_img_url")
  1211. if e != nil {
  1212. err = errors.New("GetResourceDataList, Err: " + e.Error())
  1213. return
  1214. }
  1215. addressList := strings.Split(detail.ConfigValue, "{|}")
  1216. mapAddress := make(map[string]string)
  1217. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  1218. mapChart := make(map[string]string)
  1219. var cityName string
  1220. var chartName string
  1221. var imgUrl string
  1222. var imgUrlChart string
  1223. for _, v := range addressList {
  1224. vslice := strings.Split(v, "_")
  1225. cityName = vslice[0]
  1226. imgUrl = vslice[len(vslice)-1]
  1227. mapAddress[cityName] = imgUrl
  1228. }
  1229. for _, v := range chartList {
  1230. vslice := strings.Split(v, "_")
  1231. chartName = vslice[0]
  1232. imgUrlChart = vslice[len(vslice)-1]
  1233. mapChart[chartName] = imgUrlChart
  1234. }
  1235. var imgUrlResp string
  1236. //处理活动
  1237. if len(activityIds) > 0 {
  1238. for _, vss := range activityIds {
  1239. imgUrlResp += strconv.Itoa(vss) + ","
  1240. }
  1241. pars = make([]interface{}, 0)
  1242. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `)`
  1243. pars = append(pars, activityIds)
  1244. activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
  1245. if e != nil {
  1246. err = errors.New("GetResourceDataList, Err: " + e.Error())
  1247. return
  1248. }
  1249. //处理不同的报名方式按钮回显
  1250. mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
  1251. if e != nil {
  1252. e = errors.New("GetActivitySignupResp, Err: " + e.Error())
  1253. return
  1254. }
  1255. var activityListRersp []*models.ActivityDetail
  1256. for _, v := range activityList {
  1257. v.SignupType = mapActivitySignup[v.ActivityId]
  1258. activityListRersp = append(activityListRersp, ActivityButtonShow(v))
  1259. }
  1260. for _, v := range activityListRersp {
  1261. if v == nil {
  1262. continue
  1263. }
  1264. if v.ActivityType == 0 {
  1265. if mapAddress[v.City] != "" {
  1266. imgUrlResp = mapAddress[v.City]
  1267. } else {
  1268. imgUrlResp = mapAddress["其它"]
  1269. }
  1270. } else {
  1271. if mapChart[v.ChartPermissionName] != "" {
  1272. imgUrlResp = mapChart[v.ChartPermissionName]
  1273. }
  1274. }
  1275. v.SourceType = 1
  1276. v.Expert, _ = GetReportContentTextSub(v.Expert)
  1277. mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
  1278. }
  1279. }
  1280. //产业资源包
  1281. if len(industrialResourceIdsHz) > 0 {
  1282. pars = make([]interface{}, 0)
  1283. var industrialResourceIdstring []string
  1284. for _, v := range industrialResourceIdsHz {
  1285. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  1286. }
  1287. industrialId := strings.Join(industrialResourceIdstring, ",")
  1288. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type = 0 `
  1289. listIndustrialResourceIds, e := models.GetSearchResourceList(user.UserId, condition, 0, len(industrialResourceIdsHz))
  1290. if e != nil {
  1291. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  1292. return
  1293. }
  1294. //合并产业关联的标的
  1295. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(industrialResourceIdsHz)
  1296. if e != nil {
  1297. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  1298. return
  1299. }
  1300. mapIndustrial := make(map[string]int)
  1301. for _, v := range listSubjcet {
  1302. for k2, v2 := range listIndustrialResourceIds {
  1303. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  1304. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  1305. }
  1306. }
  1307. }
  1308. for _, v := range listIndustrialResourceIds {
  1309. v.Source = 1
  1310. mapItems[fmt.Sprint("industrialsourceHz", v.IndustrialManagementId)].IndustrialResource = v
  1311. }
  1312. }
  1313. if len(industrialResourceIdsYx) > 0 {
  1314. pars = make([]interface{}, 0)
  1315. var industrialResourceIdstring []string
  1316. for _, v := range industrialResourceIdsYx {
  1317. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  1318. }
  1319. industrialId := strings.Join(industrialResourceIdstring, ",")
  1320. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type > 0 `
  1321. listIndustrialResourceIds, e := models.GetSearchResourceList(user.UserId, condition, 0, len(industrialResourceIdsYx))
  1322. if e != nil {
  1323. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  1324. return
  1325. }
  1326. //合并产业关联的标的
  1327. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(industrialResourceIdsYx)
  1328. if e != nil {
  1329. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  1330. return
  1331. }
  1332. mapIndustrial := make(map[string]int)
  1333. for _, v := range listSubjcet {
  1334. for k2, v2 := range listIndustrialResourceIds {
  1335. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Yx", v.SubjectName)] == 0 {
  1336. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  1337. }
  1338. }
  1339. }
  1340. for _, v := range listIndustrialResourceIds {
  1341. v.Source = 2
  1342. mapItems[fmt.Sprint("industrialsourceYx", v.IndustrialManagementId)].IndustrialResource = v
  1343. }
  1344. }
  1345. //处理图表
  1346. if len(newchartIds) > 0 {
  1347. pars = make([]interface{}, 0)
  1348. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  1349. pars = append(pars, newchartIds)
  1350. chartDateList, e := models.GetChartListCollectionNew(condition, pars, uid, 0, len(newchartIds))
  1351. if e != nil {
  1352. err = errors.New("GetResourceDataList, Err: " + e.Error())
  1353. return
  1354. }
  1355. for _, v := range chartDateList {
  1356. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  1357. }
  1358. }
  1359. //处理专项调研
  1360. if len(activityspecialIds) > 0 {
  1361. pars = make([]interface{}, 0)
  1362. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  1363. pars = append(pars, activityspecialIds)
  1364. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  1365. if e != nil {
  1366. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  1367. return
  1368. }
  1369. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  1370. if e != nil {
  1371. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  1372. return
  1373. }
  1374. for _, v := range activitySpeciallist {
  1375. if mapChart[v.ChartPermissionName] != "" {
  1376. imgUrlResp = mapChart[v.ChartPermissionName]
  1377. }
  1378. if _, ok := UserMap[v.ActivityId]; ok {
  1379. v.IsTrip = 1
  1380. }
  1381. if v.Days == 0 {
  1382. v.TripStatus = 1
  1383. v.TripImgLink = v.TripImgLink
  1384. } else {
  1385. v.TripStatus = 2
  1386. v.TripImgLink = v.TripImgLinkFix
  1387. v.ActivityTimeText = v.ActivityTimeTextByDay
  1388. }
  1389. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  1390. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  1391. if resultTimeStart.After(time.Now()) {
  1392. v.ActiveState = 1
  1393. } else if time.Now().After(resultTimeEnd) {
  1394. v.ActiveState = 3
  1395. } else {
  1396. v.ActiveState = 2
  1397. }
  1398. v.ImgUrl = imgUrlResp
  1399. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  1400. }
  1401. }
  1402. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds) > 0 {
  1403. audioIdstr := strings.Join(activityvoiceIds, ",")
  1404. ideoIdsStr := strings.Join(roadshowIds, ",")
  1405. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  1406. list, _, e := GetMicroRoadShowMycollect(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds), 0, audioIdstr, ideoIdsStr, activityVideoIdsStr)
  1407. if e != nil {
  1408. err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
  1409. return
  1410. }
  1411. for _, item := range list {
  1412. if item.Type == 1 {
  1413. //音频
  1414. count, e := models.GetVoiceCollectCount(user.UserId, item.Id)
  1415. if e != nil {
  1416. err = errors.New("GetVoiceCollectCount, Err: " + e.Error())
  1417. return
  1418. }
  1419. if count > 0 {
  1420. item.IsCollect = true
  1421. }
  1422. } else if item.Type == 2 {
  1423. //活动视频
  1424. count, e := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  1425. if e != nil {
  1426. err = errors.New("GetActivityVideoCollectCount, Err: " + e.Error())
  1427. return
  1428. }
  1429. if count > 0 {
  1430. item.IsCollect = true
  1431. }
  1432. } else if item.Type == 3 {
  1433. //微路演视频
  1434. count, e := models.GetVideoCollectCount(user.UserId, item.Id)
  1435. if e != nil {
  1436. err = errors.New("GetVideoCollectCount, Err: " + e.Error())
  1437. return
  1438. }
  1439. if count > 0 {
  1440. item.IsCollect = true
  1441. }
  1442. }
  1443. }
  1444. // 用户权限
  1445. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  1446. if e != nil {
  1447. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  1448. return
  1449. }
  1450. // 获取默认图配置
  1451. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  1452. if e != nil {
  1453. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  1454. return
  1455. }
  1456. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  1457. for i := range list {
  1458. // 权限
  1459. au := new(models.UserPermissionAuthInfo)
  1460. au.SellerName = authInfo.SellerName
  1461. au.SellerMobile = authInfo.SellerMobile
  1462. au.HasPermission = authInfo.HasPermission
  1463. au.OperationMode = authInfo.OperationMode
  1464. if au.HasPermission == 1 {
  1465. // 非宏观权限进一步判断是否有权限
  1466. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  1467. au.HasPermission = 2
  1468. }
  1469. }
  1470. // 无权限的弹框提示
  1471. if au.HasPermission != 1 {
  1472. if au.OperationMode == UserPermissionOperationModeCall {
  1473. if list[i].Type == 1 {
  1474. au.PopupMsg = UserPermissionPopupMsgCallActivity
  1475. } else {
  1476. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  1477. }
  1478. } else {
  1479. if list[i].Type == 1 {
  1480. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  1481. } else {
  1482. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  1483. }
  1484. }
  1485. }
  1486. list[i].AuthInfo = au
  1487. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  1488. // 默认图
  1489. if list[i].BackgroundImg == "" {
  1490. if list[i].Type == 1 {
  1491. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  1492. } else {
  1493. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  1494. }
  1495. }
  1496. // 分享图
  1497. if list[i].ShareImg == "" {
  1498. if list[i].Type == 1 {
  1499. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  1500. } else {
  1501. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  1502. }
  1503. }
  1504. }
  1505. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  1506. for _, item := range list {
  1507. if item.Type == 1 {
  1508. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  1509. } else if item.Type == 2 {
  1510. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  1511. } else if item.Type == 3 {
  1512. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  1513. }
  1514. }
  1515. }
  1516. for _, vList := range list {
  1517. for _, v := range mapItems {
  1518. //如果这些类型都为空,那么就不合并
  1519. 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 {
  1520. continue
  1521. }
  1522. if v.Article != nil {
  1523. v.Article.Title = vList.Title
  1524. }
  1525. if v.Newchart != nil {
  1526. v.Newchart.Title = vList.Title
  1527. }
  1528. if v.Roadshow != nil {
  1529. v.Roadshow.Title = vList.Title
  1530. }
  1531. if v.Activity != nil {
  1532. v.Activity.ActivityName = vList.Title
  1533. }
  1534. if v.Activityvideo != nil {
  1535. v.Activityvideo.Title = vList.Title
  1536. }
  1537. if v.Activityvoice != nil {
  1538. v.Activityvoice.Title = vList.Title
  1539. }
  1540. if v.Activityspecial != nil {
  1541. v.Activityspecial.ResearchTheme = vList.Title
  1542. }
  1543. if v.Researchsummary != nil {
  1544. v.Researchsummary.Title = vList.Title
  1545. }
  1546. if v.Minutessummary != nil {
  1547. v.Minutessummary.Title = vList.Title
  1548. }
  1549. if v.ProductInterior != nil {
  1550. v.ProductInterior.Title = vList.Title
  1551. }
  1552. if v.IndustrialResource != nil {
  1553. v.Source = "industrialsource"
  1554. }
  1555. if v.SourceId == vList.SourceId {
  1556. items = append(items, v)
  1557. }
  1558. }
  1559. }
  1560. return
  1561. }