es_comprehensive.go 54 KB

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