cygx_research_summary.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. package services
  2. import (
  3. "context"
  4. "fmt"
  5. "hongze/hongze_task/models/data_manage"
  6. "hongze/hongze_task/services/alarm_msg"
  7. "hongze/hongze_task/utils"
  8. "regexp"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. func CygxResearchSummary(cont context.Context) (err error) {
  14. defer func() {
  15. if err != nil {
  16. go alarm_msg.SendAlarmMsg("CygxResearchSummary-定时本周生成研究汇总失败, ErrMsg:\n"+err.Error(), 3)
  17. fmt.Println(err)
  18. }
  19. }()
  20. //content := "本周研究汇总"
  21. friday := utils.GetNowWeekFriday().Add(15 * time.Hour)
  22. lastfriday := utils.GetLastWeekFriday().Add(15 * time.Hour)
  23. lastMonth := int(lastfriday.Month())
  24. month := int(friday.Month())
  25. lastDay := lastfriday.Day()
  26. day := friday.Day()
  27. //friday, _ = time.Parse(utils.FormatDateTime, "2022-09-02 15:00:00")
  28. //lastfriday, _ = time.Parse(utils.FormatDateTime, "2022-08-26 15:00:00")
  29. itemCrs := new(data_manage.CygxResearchSummary)
  30. itemCrs.AdminId = 11
  31. itemCrs.AdminName = "admin"
  32. itemCrs.Title = fmt.Sprintf("本周研究汇总(%d月%d日至%d月%d日)", lastMonth, lastDay, month, day)
  33. itemCrs.Department = "弘则产品组"
  34. itemCrs.Abstract = ""
  35. itemCrs.PublishStatus = 0
  36. //itemCrs.Periods = strconv.Itoa(total + 1)
  37. itemCrs.CreateTime = time.Now()
  38. itemCrs.LastUpdatedTime = time.Now()
  39. itemCrs.PublishDate = time.Now()
  40. articleId, e := data_manage.AddCygxResearchSummaryOrm(itemCrs)
  41. if e != nil {
  42. err = e
  43. return
  44. }
  45. mappingList, err := data_manage.CygxReportMappingist()
  46. if err != nil {
  47. return
  48. }
  49. CategoryChartPermissionIdMap := make(map[int]int)
  50. for _, item := range mappingList {
  51. CategoryChartPermissionIdMap[item.CategoryId] = item.ChartPermissionId
  52. }
  53. yanxMappingList, err := data_manage.CygxArticleTypeMappingList()
  54. if err != nil {
  55. return
  56. }
  57. articleTypeChartPermissionIdMap := make(map[int]int)
  58. for _, item := range yanxMappingList {
  59. articleTypeChartPermissionIdMap[item.ArticleTypeId] = item.YanxPermissionId
  60. }
  61. //深度报告
  62. {
  63. var condition string
  64. var pars []interface{}
  65. condition += ` AND publish_date < ? AND publish_date >= ? `
  66. pars = append(pars, friday, lastfriday)
  67. sdbgList := make([]*data_manage.CygxArticle, 0)
  68. //医药
  69. {
  70. newCondition := condition + ` AND category_id_two IN(65,102)`
  71. list, e := data_manage.GetReportArticleList(newCondition, pars)
  72. if e != nil {
  73. err = e
  74. fmt.Println("GetReportArticleList err:", e)
  75. return
  76. }
  77. for _, article := range list {
  78. sdbgList = append(sdbgList, article)
  79. }
  80. }
  81. //消费
  82. {
  83. newCondition := condition + ` AND category_id_two IN(67,1008)`
  84. list, e := data_manage.GetReportArticleList(newCondition, pars)
  85. if e != nil {
  86. err = e
  87. fmt.Println("GetReportArticleList err:", e)
  88. return
  89. }
  90. for _, article := range list {
  91. sdbgList = append(sdbgList, article)
  92. }
  93. }
  94. //科技
  95. {
  96. newCondition := condition + ` AND category_id_two IN(57,69,1009)`
  97. list, e := data_manage.GetReportArticleList(newCondition, pars)
  98. if e != nil {
  99. err = e
  100. fmt.Println("GetReportArticleList err:", e)
  101. return
  102. }
  103. for _, article := range list {
  104. sdbgList = append(sdbgList, article)
  105. }
  106. }
  107. //智造
  108. {
  109. newCondition := condition + ` AND category_id_two IN(66,85)`
  110. list, e := data_manage.GetReportArticleList(newCondition, pars)
  111. if e != nil {
  112. err = e
  113. fmt.Println("GetReportArticleList err:", e)
  114. return
  115. }
  116. for _, article := range list {
  117. sdbgList = append(sdbgList, article)
  118. }
  119. }
  120. var logItems []*data_manage.CygxResearchSummaryLog
  121. for _, article := range sdbgList {
  122. head := "<div class=\"title-content\">\n 【" + article.Title + "】 "
  123. sliceSubjects := strings.Split(article.Stock, "/")
  124. var company string
  125. if sliceSubjects[0] != "" {
  126. for _, vSubject := range sliceSubjects {
  127. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  128. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  129. subject := sliceXiahuaxian[0]
  130. company += "#" + subject
  131. }
  132. company = " <span style=\"color: #ff1720\">" + company + "</span>"
  133. }
  134. annotation := strings.ReplaceAll(article.Annotation, "<strong>", "")
  135. annotation = strings.ReplaceAll(annotation, "</strong>", "")
  136. annotation = strings.ReplaceAll(annotation, "</ol>", "</div>")
  137. annotation = strings.ReplaceAll(annotation, "<ol>", "<div>")
  138. annotation = strings.ReplaceAll(annotation, "</li>", "</p>")
  139. annotation = strings.ReplaceAll(annotation, "<li>", "<p>")
  140. re, _ := regexp.Compile("<strong.*?>")
  141. annotation = re.ReplaceAllString(annotation, "")
  142. reLi, _ := regexp.Compile("<li.*?>")
  143. annotation = reLi.ReplaceAllString(annotation, "")
  144. logItem := data_manage.CygxResearchSummaryLog{
  145. ArticleId: int(articleId),
  146. Type: "SDBG",
  147. ChartPermissionId: CategoryChartPermissionIdMap[article.CategoryIdTwo],
  148. CreateTime: time.Now(),
  149. Body: head + company + annotation,
  150. LinkArticleId: article.LinkArticleId,
  151. }
  152. if utils.RunMode == "debug" {
  153. logItem.ReportLink = "https://clpttest.hzinsights.com/material/info/" + strconv.Itoa(article.ArticleId)
  154. } else {
  155. logItem.ReportLink = "https://web.hzinsights.com/material/info/" + strconv.Itoa(article.ArticleId)
  156. }
  157. logItems = append(logItems, &logItem)
  158. }
  159. if len(logItems) > 0 {
  160. _, e := data_manage.AddCygxResearchSummaryLogOrm(logItems)
  161. if e != nil {
  162. err = e
  163. return
  164. }
  165. }
  166. }
  167. //产业调研纪要
  168. {
  169. var condition string
  170. var pars []interface{}
  171. condition += ` AND publish_date < ? AND publish_date >= ? `
  172. pars = append(pars, friday, lastfriday)
  173. cydyjyList := make([]*data_manage.CygxArticle, 0)
  174. //医药
  175. {
  176. newCondition := condition + ` AND category_id_two IN(28,93,301,71)`
  177. list, e := data_manage.GetReportArticleList(newCondition, pars)
  178. if e != nil {
  179. err = e
  180. fmt.Println("GetReportArticleList err:", e)
  181. return
  182. }
  183. for _, article := range list {
  184. cydyjyList = append(cydyjyList, article)
  185. }
  186. }
  187. //消费
  188. {
  189. newCondition := condition + ` AND category_id_two IN(32,58)`
  190. list, e := data_manage.GetReportArticleList(newCondition, pars)
  191. if e != nil {
  192. err = e
  193. fmt.Println("GetReportArticleList err:", e)
  194. return
  195. }
  196. for _, article := range list {
  197. cydyjyList = append(cydyjyList, article)
  198. }
  199. }
  200. //科技
  201. {
  202. newCondition := condition + ` AND category_id_two IN(79)`
  203. list, e := data_manage.GetReportArticleList(newCondition, pars)
  204. if e != nil {
  205. err = e
  206. fmt.Println("GetReportArticleList err:", e)
  207. return
  208. }
  209. for _, article := range list {
  210. cydyjyList = append(cydyjyList, article)
  211. }
  212. }
  213. //智造
  214. {
  215. newCondition := condition + ` AND category_id_two IN(84)`
  216. list, e := data_manage.GetReportArticleList(newCondition, pars)
  217. if e != nil {
  218. err = e
  219. fmt.Println("GetReportArticleList err:", e)
  220. return
  221. }
  222. for _, article := range list {
  223. cydyjyList = append(cydyjyList, article)
  224. }
  225. }
  226. var logItems []*data_manage.CygxResearchSummaryLog
  227. for _, article := range cydyjyList {
  228. head := "<div class=\"title-content\">\n 【" + article.Title + "】 "
  229. sliceSubjects := strings.Split(article.Stock, "/")
  230. var company string
  231. if sliceSubjects[0] != "" {
  232. for _, vSubject := range sliceSubjects {
  233. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  234. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  235. subject := sliceXiahuaxian[0]
  236. company += "#" + subject
  237. }
  238. company = " <span style=\"color: #ff1720\">" + company + "</span>"
  239. }
  240. annotation := strings.ReplaceAll(article.Annotation, "<strong>", "")
  241. annotation = strings.ReplaceAll(annotation, "</strong>", "")
  242. annotation = strings.ReplaceAll(annotation, "</ol>", "</div>")
  243. annotation = strings.ReplaceAll(annotation, "<ol>", "<div>")
  244. annotation = strings.ReplaceAll(annotation, "</li>", "</p>")
  245. annotation = strings.ReplaceAll(annotation, "<li>", "<p>")
  246. re, _ := regexp.Compile("<strong.*?>")
  247. annotation = re.ReplaceAllString(annotation, "")
  248. reLi, _ := regexp.Compile("<li.*?>")
  249. annotation = reLi.ReplaceAllString(annotation, "")
  250. logItem := data_manage.CygxResearchSummaryLog{
  251. ArticleId: int(articleId),
  252. Type: "CYDYJY",
  253. ChartPermissionId: CategoryChartPermissionIdMap[article.CategoryIdTwo],
  254. CreateTime: time.Now(),
  255. Body: head + company + annotation,
  256. LinkArticleId: article.LinkArticleId,
  257. }
  258. if utils.RunMode == "debug" {
  259. logItem.ReportLink = "https://clpttest.hzinsights.com/material/info/" + strconv.Itoa(article.ArticleId)
  260. } else {
  261. logItem.ReportLink = "https://web.hzinsights.com/material/info/" + strconv.Itoa(article.ArticleId)
  262. }
  263. logItems = append(logItems, &logItem)
  264. }
  265. if len(logItems) > 0 {
  266. _, e := data_manage.AddCygxResearchSummaryLogOrm(logItems)
  267. if e != nil {
  268. err = e
  269. return
  270. }
  271. }
  272. }
  273. //上市公司调研纪要
  274. {
  275. var condition string
  276. var pars []interface{}
  277. condition += ` AND publish_date < ? AND publish_date >= ? `
  278. pars = append(pars, friday, lastfriday)
  279. ssgsdyjyList := make([]*data_manage.CygxArticle, 0)
  280. //医药
  281. {
  282. newCondition := condition + ` AND category_id_two IN(74,96)`
  283. list, e := data_manage.GetReportArticleList(newCondition, pars)
  284. if e != nil {
  285. err = e
  286. fmt.Println("GetReportArticleList err:", e)
  287. return
  288. }
  289. for _, article := range list {
  290. ssgsdyjyList = append(ssgsdyjyList, article)
  291. }
  292. }
  293. //消费
  294. {
  295. newCondition := condition + ` AND category_id_two IN(88)`
  296. list, e := data_manage.GetReportArticleList(newCondition, pars)
  297. if e != nil {
  298. err = e
  299. fmt.Println("GetReportArticleList err:", e)
  300. return
  301. }
  302. for _, article := range list {
  303. ssgsdyjyList = append(ssgsdyjyList, article)
  304. }
  305. }
  306. //科技
  307. {
  308. newCondition := condition + ` AND category_id_two IN(45)`
  309. list, e := data_manage.GetReportArticleList(newCondition, pars)
  310. if e != nil {
  311. err = e
  312. fmt.Println("GetReportArticleList err:", e)
  313. return
  314. }
  315. for _, article := range list {
  316. ssgsdyjyList = append(ssgsdyjyList, article)
  317. }
  318. }
  319. //智造
  320. {
  321. newCondition := condition + ` AND category_id_two IN(86)`
  322. list, e := data_manage.GetReportArticleList(newCondition, pars)
  323. if e != nil {
  324. err = e
  325. fmt.Println("GetReportArticleList err:", e)
  326. return
  327. }
  328. for _, article := range list {
  329. ssgsdyjyList = append(ssgsdyjyList, article)
  330. }
  331. }
  332. var logItems []*data_manage.CygxResearchSummaryLog
  333. for _, article := range ssgsdyjyList {
  334. head := "<div class=\"title-content\">\n 【" + article.Title + "】 "
  335. sliceSubjects := strings.Split(article.Stock, "/")
  336. var company string
  337. if sliceSubjects[0] != "" {
  338. for _, vSubject := range sliceSubjects {
  339. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  340. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  341. subject := sliceXiahuaxian[0]
  342. company += "#" + subject
  343. }
  344. company = " <span style=\"color: #ff1720\">" + company + "</span>"
  345. }
  346. annotation := strings.ReplaceAll(article.Annotation, "<strong>", "")
  347. annotation = strings.ReplaceAll(annotation, "</strong>", "")
  348. annotation = strings.ReplaceAll(annotation, "</ol>", "</div>")
  349. annotation = strings.ReplaceAll(annotation, "<ol>", "<div>")
  350. annotation = strings.ReplaceAll(annotation, "</li>", "</p>")
  351. annotation = strings.ReplaceAll(annotation, "<li>", "<p>")
  352. re, _ := regexp.Compile("<strong.*?>")
  353. annotation = re.ReplaceAllString(annotation, "")
  354. reLi, _ := regexp.Compile("<li.*?>")
  355. annotation = reLi.ReplaceAllString(annotation, "")
  356. logItem := data_manage.CygxResearchSummaryLog{
  357. ArticleId: int(articleId),
  358. Type: "SSGS",
  359. ChartPermissionId: CategoryChartPermissionIdMap[article.CategoryIdTwo],
  360. CreateTime: time.Now(),
  361. Body: head + company + annotation,
  362. LinkArticleId: article.LinkArticleId,
  363. }
  364. if utils.RunMode == "debug" {
  365. logItem.ReportLink = "https://clpttest.hzinsights.com/material/info/" + strconv.Itoa(article.ArticleId)
  366. } else {
  367. logItem.ReportLink = "https://web.hzinsights.com/material/info/" + strconv.Itoa(article.ArticleId)
  368. }
  369. logItems = append(logItems, &logItem)
  370. }
  371. if len(logItems) > 0 {
  372. _, e := data_manage.AddCygxResearchSummaryLogOrm(logItems)
  373. if e != nil {
  374. err = e
  375. return
  376. }
  377. }
  378. }
  379. //买方研选
  380. //{
  381. // ids, e := data_manage.GetYanXuanArticleIdList()
  382. // if e != nil {
  383. // err = e
  384. // fmt.Println("GetReportArticleList err:", e)
  385. // return
  386. // }
  387. //
  388. // var condition string
  389. // var pars []interface{}
  390. // condition += ` AND publish_date < ? AND publish_date >= ? `
  391. // pars = append(pars, friday, lastfriday)
  392. // mfyxList := make([]*data_manage.CygxArticle, 0)
  393. //
  394. // //9.23新增研选所有类型的报告都要
  395. // newCondition := condition + ` AND article_type_id IN (`+ *ids +`) `
  396. // list, e := data_manage.GetReportArticleList(newCondition, pars)
  397. // if e != nil {
  398. // err = e
  399. // fmt.Println("GetReportArticleList err:", e)
  400. // return
  401. // }
  402. // for _, article := range list {
  403. // mfyxList = append(mfyxList, article)
  404. // }
  405. //
  406. // ////纪要
  407. // //{
  408. // // newCondition := condition + ` AND article_type_id = 1 `
  409. // // list, e := data_manage.GetReportArticleList(newCondition, pars)
  410. // // if e != nil {
  411. // // err = e
  412. // // fmt.Println("GetReportArticleList err:", e)
  413. // // return
  414. // // }
  415. // // for _, article := range list {
  416. // // mfyxList = append(mfyxList, article)
  417. // // }
  418. // //}
  419. // ////观点
  420. // //{
  421. // // newCondition := condition + ` AND article_type_id = 2 `
  422. // // list, e := data_manage.GetReportArticleList(newCondition, pars)
  423. // // if e != nil {
  424. // // err = e
  425. // // fmt.Println("GetReportArticleList err:", e)
  426. // // return
  427. // // }
  428. // // for _, article := range list {
  429. // // mfyxList = append(mfyxList, article)
  430. // // }
  431. // //}
  432. // ////沙龙
  433. // //{
  434. // // newCondition := condition + ` AND article_type_id = 13 `
  435. // // list, e := data_manage.GetReportArticleList(newCondition, pars)
  436. // // if e != nil {
  437. // // err = e
  438. // // fmt.Println("GetReportArticleList err:", e)
  439. // // return
  440. // // }
  441. // // for _, article := range list {
  442. // // mfyxList = append(mfyxList, article)
  443. // // }
  444. // //}
  445. // var articleIdStr string
  446. // for _, v := range mfyxList {
  447. // articleIdStr += strconv.Itoa(v.ArticleId) + ","
  448. // }
  449. // mapArticleSubject := make(map[int]string)
  450. // articleIdStr = strings.TrimRight(articleIdStr, ",")
  451. // listSubject, e := data_manage.GetArticleSubjectList(articleIdStr)
  452. // if e != nil {
  453. // err = e
  454. // fmt.Println("GetArticleSubjectList err:", e)
  455. // return
  456. // }
  457. // for _, v := range listSubject {
  458. // mapArticleSubject[v.ArticleId] = v.SubjectName
  459. // }
  460. // var logItems []*data_manage.CygxResearchSummaryLog
  461. // for _, article := range mfyxList {
  462. // head := "<div class=\"title-content\">\n 【" + article.Title + "】 "
  463. // body := strings.ReplaceAll(article.Body, "<strong>", "")
  464. // body = strings.ReplaceAll(body, "</strong>", "")
  465. // body = strings.ReplaceAll(body, "</ol>", "</div>")
  466. // body = strings.ReplaceAll(body, "<ol>", "<div>")
  467. // body = strings.ReplaceAll(body, "</li>", "</p>")
  468. // body = strings.ReplaceAll(body, "<li>", "<p>")
  469. // re, _ := regexp.Compile("<strong.*?>")
  470. // body = re.ReplaceAllString(body, "")
  471. // reLi, _ := regexp.Compile("<li.*?>")
  472. // body = reLi.ReplaceAllString(body, "")
  473. // //研选的公司需要单独处理
  474. // //sliceSubjects := strings.Split(article.Stock, "/")
  475. // var company string
  476. // //if sliceSubjects[0] != "" {
  477. // // for _, vSubject := range sliceSubjects {
  478. // // sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  479. // // sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  480. // // subject := sliceXiahuaxian[0]
  481. // // company += "#" + subject
  482. // // }
  483. // // company = " <span style=\"color: #ff1720\">" + company + "</span>"
  484. // //}
  485. // if mapArticleSubject[article.ArticleId] != "" {
  486. // company = " <span style=\"color: #ff1720\">" + "#" + mapArticleSubject[article.ArticleId] + "</span>"
  487. // }
  488. // var plus int
  489. // coreIndex := strings.Index(body, "核心观点:")
  490. // plus = 15
  491. // if coreIndex == -1 {
  492. // coreIndex = strings.Index(body, "核心观点:")
  493. // plus = 13
  494. // }
  495. // if coreIndex == -1 {
  496. // coreIndex = strings.Index(body, "核心观点")
  497. // plus = 12
  498. // }
  499. // if coreIndex == -1 {
  500. // coreIndex = strings.Index(body, "核心结论:")
  501. // plus = 15
  502. // }
  503. // if coreIndex == -1 {
  504. // coreIndex = strings.Index(body, "核心结论:")
  505. // plus = 13
  506. // }
  507. // if coreIndex == -1 {
  508. // coreIndex = strings.Index(body, "核心结论")
  509. // plus = 12
  510. // }
  511. // endIndex := strings.Index(body, "<hr")
  512. // fmt.Println("ID:", article.ArticleId)
  513. // fmt.Println("coreIndex:", coreIndex, endIndex)
  514. // if coreIndex != -1 && endIndex != -1 {
  515. // body = body[coreIndex+plus : endIndex]
  516. // logItem := data_manage.CygxResearchSummaryLog{
  517. // ArticleId: int(articleId),
  518. // Type: "YANX",
  519. // ChartPermissionId: articleTypeChartPermissionIdMap[article.ArticleTypeId],
  520. // CreateTime: time.Now(),
  521. // Body: head + company + body,
  522. // ReportLink: "https://details.hzinsights.com/cygx/report?id=" + article.ArticleIdMd5,
  523. // LinkArticleId: article.LinkArticleId,
  524. // }
  525. // logItems = append(logItems, &logItem)
  526. // }
  527. // }
  528. // if len(logItems) > 0 {
  529. // _, e := data_manage.AddCygxResearchSummaryLogOrm(logItems)
  530. // if e != nil {
  531. // err = e
  532. // return
  533. // }
  534. // }
  535. //
  536. //}
  537. return
  538. }
  539. func CygxLastWeekSummary(cont context.Context) (err error) {
  540. defer func() {
  541. if err != nil {
  542. go alarm_msg.SendAlarmMsg("CygxLastWeekSummary-定时生成上周纪要汇总失败, ErrMsg:\n"+err.Error(), 3)
  543. fmt.Println(err)
  544. }
  545. }()
  546. tuesday := utils.GetNowWeekTuesday().Add(8 * time.Hour)
  547. lastTuesday := utils.GetLastWeekTuesday().Add(8 * time.Hour)
  548. lastMonth := int(lastTuesday.Month())
  549. month := int(tuesday.Month())
  550. lastDay := lastTuesday.Day()
  551. day := tuesday.Day()
  552. itemCrs := new(data_manage.CygxMinutesSummary)
  553. itemCrs.AdminId = 11
  554. itemCrs.AdminName = "admin"
  555. itemCrs.Title = fmt.Sprintf("上周纪要汇总(%d月%d日至%d月%d日)", lastMonth, lastDay, month, day)
  556. itemCrs.Department = "弘则产品组"
  557. itemCrs.Abstract = ""
  558. itemCrs.PublishStatus = 0
  559. //itemCrs.Periods = strconv.Itoa(total + 1)
  560. itemCrs.CreateTime = time.Now()
  561. itemCrs.LastUpdatedTime = time.Now()
  562. itemCrs.PublishDate = time.Now()
  563. articleId, e := data_manage.AddCygxMinutesSummaryOrm(itemCrs)
  564. if e != nil {
  565. err = e
  566. return
  567. }
  568. mappingList, err := data_manage.CygxReportMappingist()
  569. if err != nil {
  570. return
  571. }
  572. CategoryChartPermissionIdMap := make(map[int]int)
  573. for _, item := range mappingList {
  574. CategoryChartPermissionIdMap[item.CategoryId] = item.ChartPermissionId
  575. }
  576. yanxMappingList, err := data_manage.CygxArticleTypeMappingList()
  577. if err != nil {
  578. return
  579. }
  580. articleTypeChartPermissionIdMap := make(map[int]int)
  581. for _, item := range yanxMappingList {
  582. articleTypeChartPermissionIdMap[item.ArticleTypeId] = item.YanxPermissionId
  583. }
  584. //产业调研纪要
  585. {
  586. var condition string
  587. var pars []interface{}
  588. condition += ` AND publish_date < ? AND publish_date >= ? `
  589. pars = append(pars, tuesday, lastTuesday)
  590. cydyjyList := make([]*data_manage.CygxArticle, 0)
  591. //医药
  592. {
  593. newCondition := condition + ` AND category_id_two IN(28,93,301,71)`
  594. list, e := data_manage.GetReportArticleList(newCondition, pars)
  595. if e != nil {
  596. err = e
  597. fmt.Println("GetReportArticleList err:", e)
  598. return
  599. }
  600. for _, article := range list {
  601. cydyjyList = append(cydyjyList, article)
  602. }
  603. }
  604. //消费
  605. {
  606. newCondition := condition + ` AND category_id_two IN(32,58,62)`
  607. list, e := data_manage.GetReportArticleList(newCondition, pars)
  608. if e != nil {
  609. err = e
  610. fmt.Println("GetReportArticleList err:", e)
  611. return
  612. }
  613. for _, article := range list {
  614. cydyjyList = append(cydyjyList, article)
  615. }
  616. }
  617. //科技
  618. {
  619. newCondition := condition + ` AND category_id_two IN(79)`
  620. list, e := data_manage.GetReportArticleList(newCondition, pars)
  621. if e != nil {
  622. err = e
  623. fmt.Println("GetReportArticleList err:", e)
  624. return
  625. }
  626. for _, article := range list {
  627. cydyjyList = append(cydyjyList, article)
  628. }
  629. }
  630. //智造
  631. {
  632. newCondition := condition + ` AND category_id_two IN(84)`
  633. list, e := data_manage.GetReportArticleList(newCondition, pars)
  634. if e != nil {
  635. err = e
  636. fmt.Println("GetReportArticleList err:", e)
  637. return
  638. }
  639. for _, article := range list {
  640. cydyjyList = append(cydyjyList, article)
  641. }
  642. }
  643. var logItems []*data_manage.CygxMinutesSummaryLog
  644. for _, article := range cydyjyList {
  645. head := "<div class=\"title-content\">\n 【" + article.Title + "】 "
  646. sliceSubjects := strings.Split(article.Stock, "/")
  647. var company string
  648. if sliceSubjects[0] != "" {
  649. for _, vSubject := range sliceSubjects {
  650. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  651. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  652. subject := sliceXiahuaxian[0]
  653. company += "#" + subject
  654. }
  655. company = " <span style=\"color: #ff1720\">" + company + "</span>"
  656. }
  657. annotation := strings.ReplaceAll(article.Annotation, "<strong>", "")
  658. annotation = strings.ReplaceAll(annotation, "</strong>", "")
  659. annotation = strings.ReplaceAll(annotation, "</ol>", "</div>")
  660. annotation = strings.ReplaceAll(annotation, "<ol>", "<div>")
  661. annotation = strings.ReplaceAll(annotation, "</li>", "</p>")
  662. annotation = strings.ReplaceAll(annotation, "<li>", "<p>")
  663. re, _ := regexp.Compile("<strong.*?>")
  664. annotation = re.ReplaceAllString(annotation, "")
  665. reLi, _ := regexp.Compile("<li.*?>")
  666. annotation = reLi.ReplaceAllString(annotation, "")
  667. logItem := data_manage.CygxMinutesSummaryLog{
  668. ArticleId: int(articleId),
  669. Type: "CYDYJY",
  670. ChartPermissionId: CategoryChartPermissionIdMap[article.CategoryIdTwo],
  671. CreateTime: time.Now(),
  672. Body: head + company + annotation,
  673. LinkArticleId: article.LinkArticleId,
  674. }
  675. if utils.RunMode == "debug" {
  676. logItem.ReportLink = "https://clpttest.hzinsights.com/material/info/" + strconv.Itoa(article.ArticleId)
  677. } else {
  678. logItem.ReportLink = "https://web.hzinsights.com/material/info/" + strconv.Itoa(article.ArticleId)
  679. }
  680. logItems = append(logItems, &logItem)
  681. }
  682. if len(logItems) > 0 {
  683. _, e := data_manage.AddCygxMinutesSummaryLogOrm(logItems)
  684. if e != nil {
  685. err = e
  686. return
  687. }
  688. }
  689. }
  690. //上市公司调研纪要
  691. {
  692. var condition string
  693. var pars []interface{}
  694. condition += ` AND publish_date < ? AND publish_date >= ? `
  695. pars = append(pars, tuesday, lastTuesday)
  696. ssgsdyjyList := make([]*data_manage.CygxArticle, 0)
  697. //医药
  698. {
  699. newCondition := condition + ` AND category_id_two IN(74,96)`
  700. list, e := data_manage.GetReportArticleList(newCondition, pars)
  701. if e != nil {
  702. err = e
  703. fmt.Println("GetReportArticleList err:", e)
  704. return
  705. }
  706. for _, article := range list {
  707. ssgsdyjyList = append(ssgsdyjyList, article)
  708. }
  709. }
  710. //消费
  711. {
  712. newCondition := condition + ` AND category_id_two IN(88)`
  713. list, e := data_manage.GetReportArticleList(newCondition, pars)
  714. if e != nil {
  715. err = e
  716. fmt.Println("GetReportArticleList err:", e)
  717. return
  718. }
  719. for _, article := range list {
  720. ssgsdyjyList = append(ssgsdyjyList, article)
  721. }
  722. }
  723. //科技
  724. {
  725. newCondition := condition + ` AND category_id_two IN(45)`
  726. list, e := data_manage.GetReportArticleList(newCondition, pars)
  727. if e != nil {
  728. err = e
  729. fmt.Println("GetReportArticleList err:", e)
  730. return
  731. }
  732. for _, article := range list {
  733. ssgsdyjyList = append(ssgsdyjyList, article)
  734. }
  735. }
  736. //智造
  737. {
  738. newCondition := condition + ` AND category_id_two IN(86)`
  739. list, e := data_manage.GetReportArticleList(newCondition, pars)
  740. if e != nil {
  741. err = e
  742. fmt.Println("GetReportArticleList err:", e)
  743. return
  744. }
  745. for _, article := range list {
  746. ssgsdyjyList = append(ssgsdyjyList, article)
  747. }
  748. }
  749. var logItems []*data_manage.CygxMinutesSummaryLog
  750. for _, article := range ssgsdyjyList {
  751. head := "<div class=\"title-content\">\n 【" + article.Title + "】 "
  752. sliceSubjects := strings.Split(article.Stock, "/")
  753. var company string
  754. if sliceSubjects[0] != "" {
  755. for _, vSubject := range sliceSubjects {
  756. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  757. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  758. subject := sliceXiahuaxian[0]
  759. company += "#" + subject
  760. }
  761. company = " <span style=\"color: #ff1720\">" + company + "</span>"
  762. }
  763. annotation := strings.ReplaceAll(article.Annotation, "<strong>", "")
  764. annotation = strings.ReplaceAll(annotation, "</strong>", "")
  765. annotation = strings.ReplaceAll(annotation, "</ol>", "</div>")
  766. annotation = strings.ReplaceAll(annotation, "<ol>", "<div>")
  767. annotation = strings.ReplaceAll(annotation, "</li>", "</p>")
  768. annotation = strings.ReplaceAll(annotation, "<li>", "<p>")
  769. re, _ := regexp.Compile("<strong.*?>")
  770. annotation = re.ReplaceAllString(annotation, "")
  771. reLi, _ := regexp.Compile("<li.*?>")
  772. annotation = reLi.ReplaceAllString(annotation, "")
  773. logItem := data_manage.CygxMinutesSummaryLog{
  774. ArticleId: int(articleId),
  775. Type: "SSGS",
  776. ChartPermissionId: CategoryChartPermissionIdMap[article.CategoryIdTwo],
  777. CreateTime: time.Now(),
  778. Body: head + company + annotation,
  779. LinkArticleId: article.LinkArticleId,
  780. }
  781. if utils.RunMode == "debug" {
  782. logItem.ReportLink = "https://clpttest.hzinsights.com/material/info/" + strconv.Itoa(article.ArticleId)
  783. } else {
  784. logItem.ReportLink = "https://web.hzinsights.com/material/info/" + strconv.Itoa(article.ArticleId)
  785. }
  786. logItems = append(logItems, &logItem)
  787. }
  788. if len(logItems) > 0 {
  789. _, e := data_manage.AddCygxMinutesSummaryLogOrm(logItems)
  790. if e != nil {
  791. err = e
  792. return
  793. }
  794. }
  795. }
  796. //买方研选
  797. //{
  798. // var condition string
  799. // var pars []interface{}
  800. // condition += ` AND publish_date < ? AND publish_date >= ? `
  801. // pars = append(pars, tuesday, lastTuesday)
  802. // mfyxList := make([]*data_manage.CygxArticle, 0)
  803. //
  804. // //纪要
  805. // {
  806. // newCondition := condition + ` AND article_type_id = 1 `
  807. // list, e := data_manage.GetReportArticleList(newCondition, pars)
  808. // if e != nil {
  809. // err = e
  810. // fmt.Println("GetReportArticleList err:", e)
  811. // return
  812. // }
  813. // for _, article := range list {
  814. // mfyxList = append(mfyxList, article)
  815. // }
  816. // }
  817. // ////观点
  818. // //{
  819. // // newCondition := condition + ` AND article_type_id = 2 `
  820. // // list ,e := data_manage.GetReportArticleList(newCondition, pars)
  821. // // if e != nil {
  822. // // err = e
  823. // // fmt.Println("GetReportArticleList err:", e)
  824. // // return
  825. // // }
  826. // // for _, article := range list {
  827. // // mfyxList = append(mfyxList, article)
  828. // // }
  829. // //}
  830. // ////沙龙
  831. // //{
  832. // // newCondition := condition + ` AND article_type_id = 13 `
  833. // // list ,e := data_manage.GetReportArticleList(newCondition, pars)
  834. // // if e != nil {
  835. // // err = e
  836. // // fmt.Println("GetReportArticleList err:", e)
  837. // // return
  838. // // }
  839. // // for _, article := range list {
  840. // // mfyxList = append(mfyxList, article)
  841. // // }
  842. // //}
  843. // fmt.Println("mfyxList:", len(mfyxList))
  844. // var articleIdStr string
  845. // for _, v := range mfyxList {
  846. // articleIdStr += strconv.Itoa(v.ArticleId) + ","
  847. // }
  848. // mapArticleSubject := make(map[int]string)
  849. // articleIdStr = strings.TrimRight(articleIdStr, ",")
  850. // listSubject, e := data_manage.GetArticleSubjectList(articleIdStr)
  851. // if e != nil {
  852. // err = e
  853. // fmt.Println("GetArticleSubjectList err:", e)
  854. // return
  855. // }
  856. // for _, v := range listSubject {
  857. // mapArticleSubject[v.ArticleId] = v.SubjectName
  858. // }
  859. // var logItems []*data_manage.CygxMinutesSummaryLog
  860. // for _, article := range mfyxList {
  861. // head := "<div class=\"title-content\">\n 【" + article.Title + "】 "
  862. // body := strings.ReplaceAll(article.Body, "<strong>", "")
  863. // body = strings.ReplaceAll(body, "</strong>", "")
  864. // body = strings.ReplaceAll(body, "</ol>", "</div>")
  865. // body = strings.ReplaceAll(body, "<ol>", "<div>")
  866. // body = strings.ReplaceAll(body, "</li>", "</p>")
  867. // body = strings.ReplaceAll(body, "<li>", "<p>")
  868. // re, _ := regexp.Compile("<strong.*?>")
  869. // body = re.ReplaceAllString(body, "")
  870. // reLi, _ := regexp.Compile("<li.*?>")
  871. // body = reLi.ReplaceAllString(body, "")
  872. // //研选的公司需要单独处理
  873. // //sliceSubjects := strings.Split(article.Stock, "/")
  874. // var company string
  875. // //if sliceSubjects[0] != "" {
  876. // // for _, vSubject := range sliceSubjects {
  877. // // sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  878. // // sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  879. // // subject := sliceXiahuaxian[0]
  880. // // company += "#" + subject
  881. // // }
  882. // // company = " <span style=\"color: #ff1720\">" + company + "</span>"
  883. // //}
  884. // if mapArticleSubject[article.ArticleId] != "" {
  885. // company = " <span style=\"color: #ff1720\">" + "#" + mapArticleSubject[article.ArticleId] + "</span>"
  886. // }
  887. // var plus int
  888. // coreIndex := strings.Index(body, "核心观点:")
  889. // plus = 15
  890. // if coreIndex == -1 {
  891. // coreIndex = strings.Index(body, "核心观点:")
  892. // plus = 13
  893. // }
  894. // if coreIndex == -1 {
  895. // coreIndex = strings.Index(body, "核心观点")
  896. // plus = 12
  897. // }
  898. // if coreIndex == -1 {
  899. // coreIndex = strings.Index(body, "核心结论:")
  900. // plus = 15
  901. // }
  902. // if coreIndex == -1 {
  903. // coreIndex = strings.Index(body, "核心结论:")
  904. // plus = 13
  905. // }
  906. // if coreIndex == -1 {
  907. // coreIndex = strings.Index(body, "核心结论")
  908. // plus = 12
  909. // }
  910. // endIndex := strings.Index(body, "<hr")
  911. // if coreIndex != -1 && endIndex != -1 {
  912. // body = body[coreIndex+plus : endIndex]
  913. // logItem := data_manage.CygxMinutesSummaryLog{
  914. // ArticleId: int(articleId),
  915. // Type: "YANX",
  916. // ChartPermissionId: articleTypeChartPermissionIdMap[article.ArticleTypeId],
  917. // CreateTime: time.Now(),
  918. // Body: head + company + body,
  919. // ReportLink: "https://details.hzinsights.com/cygx/report?id=" + article.ArticleIdMd5,
  920. // LinkArticleId: article.LinkArticleId,
  921. // }
  922. // logItems = append(logItems, &logItem)
  923. // }
  924. // }
  925. // if len(logItems) > 0 {
  926. // _, e := data_manage.AddCygxMinutesSummaryLogOrm(logItems)
  927. // if e != nil {
  928. // err = e
  929. // return
  930. // }
  931. // }
  932. //
  933. //}
  934. return
  935. }