es_comprehensive.go 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647
  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. if v.TimeLineData == "" {
  1213. v.ListTimeLine = make([]models.TimeLineReportResp, 0)
  1214. } else {
  1215. if err = json.Unmarshal([]byte(v.TimeLineData), &v.ListTimeLine); err != nil {
  1216. e = errors.New("Unmarshal, Err: " + e.Error())
  1217. //return
  1218. }
  1219. }
  1220. v.Source = 1
  1221. mapItems[fmt.Sprint("industrialsourceHz", v.IndustrialManagementId)].IndustrialResource = v
  1222. }
  1223. }
  1224. if len(industrialResourceIdsYx) > 0 {
  1225. pars = make([]interface{}, 0)
  1226. var industrialResourceIdstring []string
  1227. for _, v := range industrialResourceIdsYx {
  1228. industrialResourceIdstring = append(industrialResourceIdstring, strconv.Itoa(v))
  1229. }
  1230. industrialId := strings.Join(industrialResourceIdstring, ",")
  1231. condition = ` AND m.industrial_management_id IN (` + industrialId + `) AND a.article_type_id > 0 `
  1232. listIndustrialResourceIds, e := models.GetSearchResourceList(user.UserId, condition, 0, len(industrialResourceIdsYx))
  1233. if e != nil {
  1234. err = errors.New("GetSearchResourceList, Err: " + e.Error())
  1235. return
  1236. }
  1237. //合并产业关联的标的
  1238. listSubjcet, e := models.GetIndustrialSubjectAllByIndustrialId(industrialResourceIdsYx)
  1239. if e != nil {
  1240. e = errors.New("GetIndustrialSubjectAllByIndustrialId, Err: " + e.Error())
  1241. return
  1242. }
  1243. mapIndustrial := make(map[string]int)
  1244. for _, v := range listSubjcet {
  1245. for k2, v2 := range listIndustrialResourceIds {
  1246. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Yx", v.SubjectName)] == 0 {
  1247. listIndustrialResourceIds[k2].IndustrialSubjectList = append(listIndustrialResourceIds[k2].IndustrialSubjectList, v)
  1248. }
  1249. }
  1250. }
  1251. for _, v := range listIndustrialResourceIds {
  1252. v.Source = 2
  1253. mapItems[fmt.Sprint("industrialsourceYx", v.IndustrialManagementId)].IndustrialResource = v
  1254. }
  1255. }
  1256. //处理图表
  1257. if len(newchartIds) > 0 {
  1258. pars = make([]interface{}, 0)
  1259. condition = ` AND a.chart_id IN (` + utils.GetOrmInReplace(len(newchartIds)) + `)`
  1260. pars = append(pars, newchartIds)
  1261. chartDateList, e := models.GetChartListCollectionNew(condition, pars, uid, 0, len(newchartIds))
  1262. if e != nil {
  1263. err = errors.New("GetResourceDataList, Err: " + e.Error())
  1264. return
  1265. }
  1266. for _, v := range chartDateList {
  1267. mapItems[fmt.Sprint("newchart", v.ChartId)].Newchart = v
  1268. }
  1269. }
  1270. //处理专项调研
  1271. if len(activityspecialIds) > 0 {
  1272. pars = make([]interface{}, 0)
  1273. condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityspecialIds)) + `)`
  1274. pars = append(pars, activityspecialIds)
  1275. activitySpeciallist, e := models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, 0, len(activityspecialIds))
  1276. if e != nil {
  1277. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  1278. return
  1279. }
  1280. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  1281. if e != nil {
  1282. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  1283. return
  1284. }
  1285. for _, v := range activitySpeciallist {
  1286. if mapChart[v.ChartPermissionName] != "" {
  1287. imgUrlResp = mapChart[v.ChartPermissionName]
  1288. }
  1289. if _, ok := UserMap[v.ActivityId]; ok {
  1290. v.IsTrip = 1
  1291. }
  1292. if v.Days == 0 {
  1293. v.TripStatus = 1
  1294. v.TripImgLink = v.TripImgLink
  1295. } else {
  1296. v.TripStatus = 2
  1297. v.TripImgLink = v.TripImgLinkFix
  1298. v.ActivityTimeText = v.ActivityTimeTextByDay
  1299. }
  1300. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  1301. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  1302. if resultTimeStart.After(time.Now()) {
  1303. v.ActiveState = 1
  1304. } else if time.Now().After(resultTimeEnd) {
  1305. v.ActiveState = 3
  1306. } else {
  1307. v.ActiveState = 2
  1308. }
  1309. v.ImgUrl = imgUrlResp
  1310. mapItems[fmt.Sprint("activityspecial", v.ActivityId)].Activityspecial = v
  1311. }
  1312. }
  1313. if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
  1314. audioIdstr := strings.Join(activityvoiceIds, ",")
  1315. activityVideoIdsStr := strings.Join(activityvideoIds, ",")
  1316. roadshowIdsStr := strings.Join(roadshowIds, ",")
  1317. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  1318. list, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
  1319. if e != nil {
  1320. err = errors.New("GetMicroRoadShowMycollectV12, Err: " + e.Error())
  1321. return
  1322. }
  1323. // 用户权限
  1324. authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  1325. if e != nil {
  1326. err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
  1327. return
  1328. }
  1329. // 获取默认图配置
  1330. audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
  1331. if e != nil {
  1332. err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
  1333. return
  1334. }
  1335. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  1336. for i := range list {
  1337. // 权限
  1338. au := new(models.UserPermissionAuthInfo)
  1339. au.SellerName = authInfo.SellerName
  1340. au.SellerMobile = authInfo.SellerMobile
  1341. au.HasPermission = authInfo.HasPermission
  1342. au.OperationMode = authInfo.OperationMode
  1343. if au.HasPermission == 1 {
  1344. // 非宏观权限进一步判断是否有权限
  1345. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  1346. au.HasPermission = 2
  1347. }
  1348. }
  1349. // 无权限的弹框提示
  1350. if au.HasPermission != 1 {
  1351. if au.OperationMode == UserPermissionOperationModeCall {
  1352. if list[i].Type == 1 {
  1353. au.PopupMsg = UserPermissionPopupMsgCallActivity
  1354. } else {
  1355. au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
  1356. }
  1357. } else {
  1358. if list[i].Type == 1 {
  1359. au.PopupMsg = UserPermissionPopupMsgApplyActivity
  1360. } else {
  1361. au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
  1362. }
  1363. }
  1364. }
  1365. list[i].AuthInfo = au
  1366. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  1367. // 默认图
  1368. if list[i].BackgroundImg == "" {
  1369. if list[i].Type == 1 {
  1370. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  1371. } else {
  1372. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  1373. }
  1374. }
  1375. // 分享图
  1376. if list[i].ShareImg == "" {
  1377. if list[i].Type == 1 {
  1378. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  1379. } else {
  1380. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  1381. }
  1382. }
  1383. }
  1384. //Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频"`
  1385. for _, item := range list {
  1386. if item.Type == 1 {
  1387. mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
  1388. } else if item.Type == 2 {
  1389. mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
  1390. } else if item.Type == 3 {
  1391. mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
  1392. } else if item.Type == 4 {
  1393. mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
  1394. }
  1395. }
  1396. }
  1397. //处理研选专栏
  1398. lenyanxuanSpecialIds := len(yanxuanSpecialIds)
  1399. if lenyanxuanSpecialIds > 0 {
  1400. pars = make([]interface{}, 0)
  1401. condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
  1402. pars = append(pars, yanxuanSpecialIds)
  1403. listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars, 0, 0)
  1404. if e != nil {
  1405. err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
  1406. return
  1407. }
  1408. for _, v := range listyanxuanSpecial {
  1409. v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
  1410. v.Annotation, _ = GetReportContentTextSubNew(v.Content)
  1411. if len(yanXuanbodyHighlight[v.Id]) > 0 {
  1412. v.BodyHighlight = yanXuanbodyHighlight[v.Id]
  1413. } else {
  1414. v.BodyHighlight = append(v.BodyHighlight, v.Annotation)
  1415. }
  1416. v.Annotation = "" //强制置空,兼容前端优先级
  1417. // Source PublishDate 字段兼容前端样式
  1418. v.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  1419. v.PublishDate = v.PublishTime
  1420. mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
  1421. }
  1422. }
  1423. //处理FICC研报
  1424. if len(ficcreporrtIds) > 0 {
  1425. pars = make([]interface{}, 0)
  1426. condition = ` AND a.report_id IN (` + utils.GetOrmInReplace(len(ficcreporrtIds)) + `)`
  1427. pars = append(pars, ficcreporrtIds)
  1428. listArticle, e := models.GetHomeList(condition, pars, 0, len(ficcreporrtIds))
  1429. if e != nil {
  1430. err = errors.New("GetHomeList, Err: " + e.Error())
  1431. return
  1432. }
  1433. listArticle, e = HandleArticleCategoryImg(listArticle)
  1434. if e != nil {
  1435. err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  1436. return
  1437. }
  1438. for _, v := range listArticle {
  1439. //fmt.Println(v.ArticleId)
  1440. v.Body = ""
  1441. v.Source = 0 //配合前端这里强制改为 0
  1442. v.ArticleResponse = 0 //配合前端这里强制改为 0
  1443. //v.Source = utils.CYGX_OBJ_YANXUANSPECIAL
  1444. mapItems[fmt.Sprint("ficcreport", v.ReportId)].FiccReport = v
  1445. }
  1446. //listArticle, e = HandleArticleCategoryImg(listArticle)
  1447. //if e != nil {
  1448. // err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
  1449. // return
  1450. //}
  1451. //for _, v := range listArticle {
  1452. // //reportInfoItem := new(ficc_report.ReportDetail)
  1453. // //reportInfoItem.ReportInfo.ReportId = v.ReportId
  1454. // //reportInfoItem.ReportInfo.PublishTime = utils.StrTimeToTime(v.PublishDate)
  1455. // //reportInfoItem.ReportInfo.Title = v.Title
  1456. // mapItems[fmt.Sprint("ficcreport", v.ArticleId)].FiccReport = v
  1457. //
  1458. //}
  1459. }
  1460. for _, vList := range list {
  1461. for _, v := range mapItems {
  1462. //如果这些类型都为空,那么就不合并
  1463. 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 {
  1464. continue
  1465. }
  1466. if v.SourceId == vList.SourceId && v.Source == vList.Source {
  1467. items = append(items, v)
  1468. }
  1469. }
  1470. }
  1471. for _, v := range items {
  1472. if v.IndustrialResource != nil {
  1473. v.Source = "industrialsource"
  1474. }
  1475. }
  1476. return
  1477. }
  1478. func SqlComprehensiveSearch(keyWord string, startSize, pageSize int) (result []*SearchComprehensiveItem, total int, err error) {
  1479. listListNoEnd, e := models.GetActivityIdListNoEnd()
  1480. var activityIds []string
  1481. for _, v := range listListNoEnd {
  1482. activityIds = append(activityIds, strconv.Itoa(v.ActivityId))
  1483. }
  1484. activityIds = append(activityIds, "0")
  1485. conditionActivity := " AND IF ( source IN('activity') , source_id IN (" + strings.Join(activityIds, ",") + ") ,1=1 )"
  1486. keyWord = "%" + keyWord + "%"
  1487. var conditionTitle string
  1488. var parsTitle []interface{}
  1489. conditionTitle = " AND is_hide = 0 AND search_title LIKE ? AND IF ( source IN('activityvoice','activityvideo') , chart_permission_id != 31 ,1=1 ) " + conditionActivity
  1490. parsTitle = append(parsTitle, keyWord)
  1491. totalTitle, e := models.GetResourceDataCount(conditionTitle, parsTitle)
  1492. if e != nil {
  1493. err = errors.New("GetResourceDataCount, Err: " + e.Error())
  1494. return
  1495. }
  1496. var conditionContent string
  1497. var parsContent []interface{}
  1498. 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 ) " + conditionActivity
  1499. parsContent = append(parsContent, keyWord, keyWord)
  1500. totalContent, e := models.GetResourceDataCount(conditionContent, parsContent)
  1501. if e != nil {
  1502. err = errors.New("AddCygxArticleViewRecord, Err: " + e.Error())
  1503. return
  1504. }
  1505. var searchTotal int
  1506. searchTotal = (startSize/pageSize + 1) * pageSize
  1507. var list []*models.CygxResourceData
  1508. //fmt.Println("totalTitle", totalTitle)
  1509. //fmt.Println("totalContent", totalContent)
  1510. //fmt.Println(searchTotal)
  1511. if totalTitle >= searchTotal {
  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. } else if totalTitle <= searchTotal-pageSize {
  1519. //全部都是内容搜索
  1520. startSize = startSize - totalTitle
  1521. list, e = models.GetResourceDataListCondition(conditionContent, parsContent, startSize, pageSize)
  1522. if e != nil && e.Error() != utils.ErrNoRow() {
  1523. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  1524. return
  1525. }
  1526. } else {
  1527. //一半标题搜索,一半内容搜索
  1528. list, e = models.GetResourceDataListCondition(conditionTitle, parsTitle, startSize, pageSize)
  1529. if e != nil && e.Error() != utils.ErrNoRow() {
  1530. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  1531. return
  1532. }
  1533. listContent, e := models.GetResourceDataListCondition(conditionContent, parsContent, 0, pageSize-totalContent%pageSize)
  1534. if e != nil && e.Error() != utils.ErrNoRow() {
  1535. err = errors.New("GetResourceDataListCondition, Err: " + e.Error())
  1536. return
  1537. }
  1538. for _, v := range listContent {
  1539. list = append(list, v)
  1540. }
  1541. }
  1542. for _, v := range list {
  1543. item := new(SearchComprehensiveItem)
  1544. item.SourceId = v.SourceId
  1545. item.Source = v.Source
  1546. result = append(result, item)
  1547. }
  1548. total = totalTitle + totalContent
  1549. return
  1550. }