report.go 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/company"
  7. "eta/eta_api/models/system"
  8. "eta/eta_api/services/alarm_msg"
  9. "eta/eta_api/services/public_api"
  10. "eta/eta_api/utils"
  11. "fmt"
  12. "github.com/PuerkitoBio/goquery"
  13. "github.com/rdlucklib/rdluck_tools/http"
  14. "html"
  15. "os"
  16. "regexp"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. func GetReportContentSub(content string) (contentSub string, err error) {
  22. content = html.UnescapeString(content)
  23. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  24. if err != nil {
  25. fmt.Println("create doc err:", err.Error())
  26. return
  27. }
  28. n := 0
  29. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  30. if n >= 5 {
  31. return
  32. }
  33. n++
  34. phtml, err := s.Html()
  35. if err != nil {
  36. fmt.Println("get html err", err.Error())
  37. return
  38. }
  39. if s.Text() != "" || strings.Contains(phtml, "src") {
  40. contentSub = contentSub + "<p>" + phtml + "</p>"
  41. }
  42. })
  43. return
  44. }
  45. type ZgParam struct {
  46. }
  47. // 找钢网
  48. func ZhaoGangSend(report *models.ReportDetail) (err error) {
  49. defer func() {
  50. if err != nil {
  51. go alarm_msg.SendAlarmMsg("发送报告至找刚网失败,Err"+err.Error(), 3)
  52. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送报告至找刚网失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  53. }
  54. }()
  55. reportIdStr := strconv.Itoa(report.Id)
  56. articleId := utils.MD5(reportIdStr)
  57. var reportType int
  58. if report.ClassifyNameSecond == "知白守黑日评" {
  59. reportType = 1
  60. } else {
  61. reportType = 2
  62. }
  63. contentHtml := html.UnescapeString(report.Content)
  64. doc, err := goquery.NewDocumentFromReader(strings.NewReader(contentHtml))
  65. if err != nil {
  66. fmt.Println("Create Doc Err:" + err.Error())
  67. err = errors.New("Create Doc Err:" + err.Error())
  68. return
  69. }
  70. doc.Find("p").Each(func(i int, p *goquery.Selection) {
  71. phtml, err := p.Html()
  72. if err != nil {
  73. fmt.Println("Err:" + err.Error())
  74. return
  75. }
  76. if phtml == "<br/>" {
  77. if i == 0 {
  78. p.Remove()
  79. } else {
  80. p.ReplaceWithHtml("<br/>")
  81. }
  82. } else {
  83. p.SetAttr("style", "line-height:30px")
  84. }
  85. })
  86. doc.Find("img").Each(func(i int, img *goquery.Selection) {
  87. img.SetAttr("style", "width:100%;")
  88. })
  89. contentHtml, _ = doc.Find("body").Html()
  90. createDate, _ := time.Parse(utils.FormatDateTime, report.CreateTime)
  91. createDay := createDate.Format("0102")
  92. title := "【第 " + strconv.Itoa(report.Stage) + "期|FICC" + "】 " + report.Title + "(" + createDay + ")"
  93. contentSummary := report.Abstract
  94. postUrl := `http://appserver.index.zhaogang.com/double.index.appserver.service/api/v1/wechat/article/hongze/push`
  95. signStr := "zhaogang_data_vip" + "articleId" + articleId + "type" + strconv.Itoa(reportType) + "title" + title + "contentSummary" + contentSummary + "zhaogang_data_vip"
  96. fmt.Println("signStr:", signStr)
  97. sign := utils.MD5(signStr)
  98. disclaimers := `<p>1、本报告仅供弘则弥道(上海)投资咨询有限公司正式签约的机构客户使用,不会仅因接收人/接受机构收到本报告而将其视为客户。</p >         <p>2、本报告根据国际和行业通行的准则,以合法渠道获得这些信息,尽可能保证可靠、准确和完整,但并不保证报告所述信息的准确性和完整性,也不保证本报告所包含的信息或建议在本报告发出后不会发生任何变更。本报告中所提供的信息仅供参考。</p >         <p>3、报告中的内容不对投资者做出的最终操作建议做任何的担保,也没有任何形式的分享投资收益或者分担投资损失的书面或口头承诺。不作为客户在投资、法律、会计或税务等方面的最终操作建议,也不作为道义的、责任的和法律的依据或者凭证,无论是否已经明示或者暗示。</p >         <p>4、在任何情况下,本公司不对客户/接受人/接受机构因使用报告中内容所引致的一切损失负责任,客户/接受人/接受机构需自行承担全部风险。</p >`
  99. param := make(map[string]interface{})
  100. dataMap := make(map[string]interface{})
  101. contentMap := make(map[string]interface{})
  102. dataMap["articleId"] = articleId
  103. dataMap["type"] = reportType
  104. dataMap["title"] = title
  105. dataMap["contentSummary"] = contentSummary
  106. contentMap["contentHtml"] = contentHtml
  107. contentMap["articleAuthor"] = report.Author
  108. //contentMap["publishedTime"] = report.PublishTime.Format(utils.FormatDateTime)
  109. contentMap["publishedTime"] = report.PublishTime
  110. contentMap["audioName"] = report.VideoName
  111. contentMap["audioUrl"] = report.VideoUrl
  112. videoPlaySeconds := report.VideoPlaySeconds
  113. f, _ := strconv.ParseFloat(videoPlaySeconds, 64)
  114. contentMap["audioLength"] = f * 1000
  115. contentMap["disclaimers"] = disclaimers
  116. param["cardData"] = dataMap
  117. param["contentData"] = contentMap
  118. param["sign"] = strings.ToUpper(sign)
  119. paramJson, err := json.Marshal(param)
  120. if err != nil {
  121. fmt.Println("param json.Marshal Err:" + err.Error())
  122. err = errors.New("param json.Marshal Err:" + err.Error())
  123. return
  124. }
  125. utils.FileLog.Info("ZhaoGangSend parms:%s", string(paramJson))
  126. result, err := http.Post(postUrl, string(paramJson), "application/json")
  127. if err != nil {
  128. fmt.Println("post err:" + err.Error())
  129. err = errors.New("post Err:" + err.Error())
  130. return
  131. }
  132. utils.FileLog.Info("ZhaoGangSend Result:%s", string(result))
  133. //返回数据校验
  134. mapResult := make(map[string]interface{})
  135. err = json.Unmarshal(result, &mapResult)
  136. if err != nil {
  137. fmt.Println("找钢网返回数据转json失败: err:", err.Error(), ";返回数据:", string(result))
  138. err = errors.New(fmt.Sprint("找钢网返回数据转json失败: err:", err.Error(), ";返回数据:", string(result)))
  139. return
  140. }
  141. if resultCode, ok := mapResult["code"]; ok {
  142. tmpResultCode := resultCode.(float64)
  143. if tmpResultCode != 200 {
  144. fmt.Println("找钢网返回数据异常,code返回参异常;返回数据:", string(result))
  145. err = errors.New(fmt.Sprint("找钢网返回数据异常,code返回参异常;返回数据:", string(result)))
  146. return
  147. }
  148. } else {
  149. fmt.Println("找钢网返回数据异常,缺少code返回参;返回数据:", string(result))
  150. err = errors.New(fmt.Sprint("找钢网返回数据异常,缺少code返回参;返回数据:", string(result)))
  151. return
  152. }
  153. utils.FileLog.Info("%s", string(result))
  154. return
  155. }
  156. /*func init() {
  157. fmt.Println("start")
  158. vint := 845
  159. report, err := models.GetReportById(vint)
  160. if err != nil {
  161. fmt.Println("GetReportById Err", err.Error())
  162. return
  163. }
  164. ZhaoGangSend(report)
  165. fmt.Println("end")
  166. return
  167. }*/
  168. // PublishDayWeekReport 发布晨周报
  169. func PublishDayWeekReport(reportId int) (tips string, err error) {
  170. report, err := models.GetReportByReportId(reportId)
  171. if err != nil {
  172. return
  173. }
  174. if report.State == 2 {
  175. return
  176. }
  177. chapters, err := models.GetChapterListByReportId(reportId)
  178. if err != nil {
  179. return
  180. }
  181. chapterLen := len(chapters)
  182. if chapterLen <= 0 {
  183. err = errors.New("报告章节为空,不可发布")
  184. return
  185. }
  186. reportType := chapters[0].ReportType
  187. // 校验章节
  188. publishReport, tips, publishIdArr, unPublishIdArr, err := checkDayWeekChapterWrite(chapters, reportType)
  189. if err != nil {
  190. return
  191. }
  192. publishLen := len(publishIdArr)
  193. if publishLen <= 0 {
  194. err = errors.New("报告章节均不可发布")
  195. return
  196. }
  197. // 需发布整期
  198. updateCols := make([]string, 0)
  199. if publishReport {
  200. updateCols = append(updateCols, "Title", "State", "ModifyTime")
  201. // 发布后标题调整
  202. title := report.Title
  203. title = strings.ReplaceAll(title, "【弘则FICC晨报】", "")
  204. title = strings.ReplaceAll(title, "【弘则FICC周报】", "")
  205. if title == "" {
  206. // 取第一个需发布章节的标题
  207. firstId := publishIdArr[0]
  208. firstTitle := ""
  209. for i := 0; i < chapterLen; i++ {
  210. if chapters[i].ReportChapterId == firstId {
  211. firstTitle = chapters[i].Title
  212. break
  213. }
  214. }
  215. title = firstTitle
  216. }
  217. report.Title = title
  218. report.State = 2
  219. // 研报后台4.4 只在没有发布过时更新发布时间,其余均按模版消息发送时间当作发布时间
  220. if report.MsgIsSend == 0 || report.PublishTime.IsZero() {
  221. report.PublishTime = time.Now().Local()
  222. updateCols = append(updateCols, "PublishTime")
  223. }
  224. report.ModifyTime = time.Now().Local()
  225. }
  226. publishIdStr := utils.IntArr2joinString(publishIdArr, ",")
  227. //unPublishIdStr := utils.IntArr2joinString(unPublishIdArr, ",")
  228. if e := models.PublishReportAndChapter(report, publishIdArr, unPublishIdArr, publishReport, updateCols); e != nil {
  229. err = errors.New("发布报告及章节失败")
  230. return
  231. }
  232. // 生成章节音频
  233. go func() {
  234. _ = UpdateChaptersVideo(publishIdStr)
  235. }()
  236. // 更新报告ES
  237. go func() {
  238. _ = UpdateReportEs(report.Id, 2)
  239. }()
  240. // 发布时备份内容
  241. go SaveReportLogs(report, chapters, report.AdminId, report.AdminRealName)
  242. return
  243. }
  244. // UpdateChaptersVideo 更新章节音频
  245. func UpdateChaptersVideo(chapterIds string) (err error) {
  246. defer func() {
  247. if err != nil {
  248. utils.FileLog.Error("UpdateChaptersVideo, chapterIds:%s, Err:%s", chapterIds, err.Error())
  249. go alarm_msg.SendAlarmMsg("更新章节音频失败, 章节ID: "+chapterIds+", Err: "+err.Error(), 3)
  250. }
  251. }()
  252. if chapterIds == "" {
  253. return
  254. }
  255. ids := make([]int, 0)
  256. chapterIdArr := strings.Split(chapterIds, ",")
  257. for _, v := range chapterIdArr {
  258. id, e := strconv.Atoi(v)
  259. if e != nil {
  260. return
  261. }
  262. ids = append(ids, id)
  263. }
  264. chapterList, err := models.GetChapterListByChapterIds(ids)
  265. if err != nil {
  266. return
  267. }
  268. // 生成video
  269. nowTime := time.Now()
  270. updateCols := make([]string, 0)
  271. updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds")
  272. for i := 0; i < len(chapterList); i++ {
  273. item := chapterList[i]
  274. // 忽略已有音频的章节
  275. if item.VideoUrl != "" && item.VideoName != "" && item.VideoSize != "" && item.VideoPlaySeconds != "" {
  276. continue
  277. }
  278. videoUrl, videoName, videoSize, videoPlaySeconds, e := CreateReportVideo(item.Title, html.UnescapeString(item.Content), nowTime.Format(utils.FormatDateTime))
  279. if e != nil {
  280. err = e
  281. return
  282. }
  283. item.VideoUrl = videoUrl
  284. item.VideoName = videoName
  285. item.VideoSize = videoSize
  286. item.VideoPlaySeconds = fmt.Sprintf("%.2f", videoPlaySeconds)
  287. if e = item.UpdateChapter(updateCols); e != nil {
  288. err = e
  289. }
  290. }
  291. return
  292. }
  293. // PublishTodayDayReport 发布今日晨报
  294. func PublishTodayDayReport() (err error) {
  295. nowTime := time.Now()
  296. startTime := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, time.Local)
  297. endTime := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 23, 59, 59, 0, time.Local)
  298. todayReport, err := models.GetUnPublishDayReport(startTime, endTime)
  299. if err != nil {
  300. if err.Error() == utils.ErrNoRow() { //如果是找不到待发送的晨报,那么需要将err置空
  301. err = nil
  302. }
  303. return
  304. }
  305. if todayReport != nil {
  306. if _, tmpErr := PublishDayWeekReport(todayReport.Id); tmpErr != nil {
  307. err = tmpErr
  308. return
  309. }
  310. // 定时发布的晨报自动推送客群
  311. reportDetail, tmpErr := models.GetReportById(todayReport.Id)
  312. if tmpErr != nil {
  313. err = tmpErr
  314. return
  315. }
  316. // 推送模板消息
  317. if tmpErr = SendMiniProgramReportWxMsg(todayReport.Id); tmpErr != nil {
  318. err = tmpErr
  319. return
  320. }
  321. if tmpErr = models.ModifyReportThsMsgIsSend(reportDetail); tmpErr != nil {
  322. err = tmpErr
  323. return
  324. }
  325. }
  326. return
  327. }
  328. // UpdateReportEs 更新报告/章节Es
  329. func UpdateReportEs(reportId int, publishState int) (err error) {
  330. if reportId <= 0 {
  331. return
  332. }
  333. reportInfo, err := models.GetReportByReportId(reportId)
  334. if err != nil {
  335. return
  336. }
  337. categories := ""
  338. if reportInfo.HasChapter == 1 {
  339. // 晨周报
  340. chapterList, tmpErr := models.GetPublishedChapterListByReportId(reportInfo.Id)
  341. if tmpErr != nil {
  342. return
  343. }
  344. if len(chapterList) > 0 {
  345. for i := 0; i < len(chapterList); i++ {
  346. // 章节对应的品种
  347. permissionList, tmpErr := models.GetChapterTypePermissionByTypeIdAndResearchType(chapterList[i].TypeId, chapterList[i].ReportType)
  348. if tmpErr != nil {
  349. return
  350. }
  351. categoryArr := make([]string, 0)
  352. if len(permissionList) > 0 {
  353. for ii := 0; ii < len(permissionList); ii++ {
  354. categoryArr = append(categoryArr, permissionList[ii].PermissionName)
  355. }
  356. }
  357. aliasArr, _ := addCategoryAliasToArr(categoryArr)
  358. chapterCategories := strings.Join(aliasArr, ",")
  359. esChapter := &models.ElasticReportDetail{
  360. ReportId: chapterList[i].ReportId,
  361. ReportChapterId: chapterList[i].ReportChapterId,
  362. Title: chapterList[i].Title,
  363. Abstract: chapterList[i].Abstract,
  364. BodyContent: utils.TrimHtml(html.UnescapeString(chapterList[i].Content)),
  365. PublishTime: chapterList[i].PublishTime.Format(utils.FormatDateTime),
  366. PublishState: chapterList[i].PublishState,
  367. Author: chapterList[i].Author,
  368. ClassifyIdFirst: chapterList[i].ClassifyIdFirst,
  369. ClassifyNameFirst: chapterList[i].ClassifyNameFirst,
  370. ClassifyIdSecond: 0,
  371. ClassifyNameSecond: "",
  372. Categories: chapterCategories,
  373. StageStr: strconv.Itoa(chapterList[i].Stage),
  374. }
  375. chapterDocId := fmt.Sprintf("%d-%d", reportInfo.Id, chapterList[i].ReportChapterId)
  376. if err = EsAddOrEditReport(utils.EsReportIndexName, chapterDocId, esChapter); err != nil {
  377. return
  378. }
  379. }
  380. }
  381. } else {
  382. if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  383. permissionList, tmpErr := models.GetChartPermissionNameFromMappingByKeyword(reportInfo.ClassifyNameSecond, "rddp")
  384. if tmpErr != nil {
  385. return
  386. }
  387. categoryArr := make([]string, 0)
  388. for i := 0; i < len(permissionList); i++ {
  389. categoryArr = append(categoryArr, permissionList[i].PermissionName)
  390. }
  391. aliasArr, _ := addCategoryAliasToArr(categoryArr)
  392. categories = strings.Join(aliasArr, ",")
  393. }
  394. }
  395. // 新增报告ES
  396. esReport := &models.ElasticReportDetail{
  397. ReportId: reportInfo.Id,
  398. ReportChapterId: 0,
  399. Title: reportInfo.Title,
  400. Abstract: reportInfo.Abstract,
  401. BodyContent: utils.TrimHtml(html.UnescapeString(reportInfo.Content)),
  402. PublishTime: reportInfo.PublishTime.Format(utils.FormatDateTime),
  403. PublishState: publishState,
  404. Author: reportInfo.Author,
  405. ClassifyIdFirst: reportInfo.ClassifyIdFirst,
  406. ClassifyNameFirst: reportInfo.ClassifyNameFirst,
  407. ClassifyIdSecond: reportInfo.ClassifyIdSecond,
  408. ClassifyNameSecond: reportInfo.ClassifyNameSecond,
  409. Categories: categories,
  410. StageStr: strconv.Itoa(reportInfo.Stage),
  411. }
  412. docId := fmt.Sprintf("%d-%d", reportInfo.Id, 0)
  413. if err = EsAddOrEditReport(utils.EsReportIndexName, docId, esReport); err != nil {
  414. return
  415. }
  416. return
  417. }
  418. // addCategoryAliasToArr 品种别名
  419. func addCategoryAliasToArr(categoryArr []string) (aliasArr []string, err error) {
  420. aliasArr = categoryArr
  421. if len(categoryArr) > 0 {
  422. for i := 0; i < len(categoryArr); i++ {
  423. if strings.Contains(categoryArr[i], "沥青") {
  424. aliasArr = append(aliasArr, "BU")
  425. }
  426. if strings.Contains(categoryArr[i], "MEG") {
  427. aliasArr = append(aliasArr, "EG", "乙二醇")
  428. }
  429. if strings.Contains(categoryArr[i], "聚酯") {
  430. aliasArr = append(aliasArr, "长丝", "短纤", "瓶片")
  431. }
  432. if strings.Contains(categoryArr[i], "纯苯+苯乙烯") {
  433. aliasArr = append(aliasArr, "EB")
  434. }
  435. if strings.Contains(categoryArr[i], "聚乙烯") {
  436. aliasArr = append(aliasArr, "PP", "PE")
  437. }
  438. if strings.Contains(categoryArr[i], "玻璃纯碱") {
  439. aliasArr = append(aliasArr, "玻璃", "纯碱", "FG", "SA")
  440. }
  441. if strings.Contains(categoryArr[i], "甲醇") {
  442. aliasArr = append(aliasArr, "甲醇", "MA")
  443. }
  444. if strings.Contains(categoryArr[i], "橡胶") {
  445. aliasArr = append(aliasArr, "橡胶", "RU")
  446. }
  447. }
  448. }
  449. return
  450. }
  451. // UpdateReportChapterEs 更新报告章节ES
  452. func UpdateReportChapterEs(reportChapterId int) (err error) {
  453. if reportChapterId <= 0 {
  454. return
  455. }
  456. chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  457. if err != nil {
  458. return
  459. }
  460. // 章节对应的品种
  461. permissionList, tmpErr := models.GetChapterTypePermissionByTypeIdAndResearchType(chapterInfo.TypeId, chapterInfo.ReportType)
  462. if tmpErr != nil {
  463. return
  464. }
  465. categoryArr := make([]string, 0)
  466. if len(permissionList) > 0 {
  467. for ii := 0; ii < len(permissionList); ii++ {
  468. categoryArr = append(categoryArr, permissionList[ii].PermissionName)
  469. }
  470. }
  471. aliasArr, _ := addCategoryAliasToArr(categoryArr)
  472. categories := strings.Join(aliasArr, ",")
  473. // 新增/编辑ES
  474. esChapter := &models.ElasticReportDetail{
  475. ReportId: chapterInfo.ReportId,
  476. ReportChapterId: chapterInfo.ReportChapterId,
  477. Title: chapterInfo.Title,
  478. Abstract: chapterInfo.Abstract,
  479. BodyContent: utils.TrimHtml(html.EscapeString(chapterInfo.Content)),
  480. PublishTime: chapterInfo.PublishTime.Format(utils.FormatDateTime),
  481. PublishState: chapterInfo.PublishState,
  482. Author: chapterInfo.Author,
  483. ClassifyIdFirst: chapterInfo.ClassifyIdFirst,
  484. ClassifyNameFirst: chapterInfo.ClassifyNameFirst,
  485. ClassifyIdSecond: 0,
  486. ClassifyNameSecond: "",
  487. Categories: categories,
  488. StageStr: strconv.Itoa(chapterInfo.Stage),
  489. }
  490. chapterDocId := fmt.Sprintf("%d-%d", chapterInfo.ReportId, chapterInfo.ReportChapterId)
  491. if err = EsAddOrEditReport(utils.EsReportIndexName, chapterDocId, esChapter); err != nil {
  492. return
  493. }
  494. return
  495. }
  496. // DeleteReportAndChapter 删除报告及章节
  497. func DeleteReportAndChapter(reportId int) (err error) {
  498. reportInfo, err := models.GetReportByReportId(reportId)
  499. if err != nil {
  500. err = errors.New("报告信息有误, Err: " + err.Error())
  501. return
  502. }
  503. if reportInfo.State == 2 {
  504. err = errors.New("报告已发布,不可删除")
  505. return
  506. }
  507. // 更新ES
  508. _ = UpdateReportEs(reportId, 1)
  509. // 删除
  510. if reportInfo.HasChapter == 1 && (reportInfo.ChapterType == utils.REPORT_TYPE_DAY || reportInfo.ChapterType == utils.REPORT_TYPE_WEEK) {
  511. err = models.DeleteDayWeekReportAndChapter(reportId)
  512. } else {
  513. err = models.DeleteReport(reportId)
  514. }
  515. if err != nil {
  516. err = errors.New("删除失败, Err: " + err.Error())
  517. return
  518. }
  519. // 重置PPT关联报告
  520. go func() {
  521. _ = ResetPPTReport(reportId, false)
  522. }()
  523. return
  524. }
  525. // UpdatePublishedReportToEs 更新已发布的报告ES
  526. func UpdatePublishedReportToEs() (err error) {
  527. // 获取所有已发布的报告
  528. var condition string
  529. var pars []interface{}
  530. condition = ` AND state IN (2, 6) `
  531. reportList, err := models.GetReportList(condition, pars, "ficc", 1, 5000)
  532. count := 0
  533. failCount := 0
  534. for i := 0; i < len(reportList); i++ {
  535. if err = UpdateReportEs(reportList[i].Id, 2); err != nil {
  536. fmt.Printf("更新失败, report_id: %d, Err: %s\n", reportList[i].Id, err.Error())
  537. failCount += 1
  538. } else {
  539. count += 1
  540. }
  541. }
  542. fmt.Printf("报告总数:%d, 更新成功数: %d, 更新失败数: %d", len(reportList), count, failCount)
  543. return
  544. }
  545. // 替换报告内容中的base64图片
  546. func replaceReportBase64ToImg(content string) (newContent string, err error) {
  547. if content == "" {
  548. return
  549. }
  550. pattern := "data:([a-z]+\\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?"
  551. re, _ := regexp.Compile(pattern)
  552. matcher := re.FindAllString(content, 999)
  553. if len(matcher) > 0 {
  554. for _, v := range matcher {
  555. imgUrl, tmpErr := reportBase64ToImg(v)
  556. if tmpErr != nil {
  557. err = tmpErr
  558. return
  559. }
  560. content = strings.ReplaceAll(content, v, imgUrl)
  561. }
  562. }
  563. newContent = content
  564. return
  565. }
  566. // 转换base64图片为img并上传
  567. func reportBase64ToImg(imageBase64 string) (resourceUrl string, err error) {
  568. if imageBase64 == "" {
  569. err = errors.New("图片为空")
  570. return
  571. }
  572. ext := ".png"
  573. uploadDir := "./static"
  574. randStr := utils.GetRandStringNoSpecialChar(28)
  575. fileName := randStr + ext
  576. fpath := uploadDir + "/" + fileName
  577. b, _ := regexp.MatchString(`^data:\s*image\/(\w+);base64,`, imageBase64)
  578. if !b {
  579. err = errors.New("图片格式不正确")
  580. return
  581. }
  582. re, _ := regexp.Compile(`^data:\s*image\/(\w+);base64,`)
  583. base64Str := re.ReplaceAllString(imageBase64, "")
  584. base64Str = strings.Replace(base64Str, " ", "", -1)
  585. err = utils.SaveBase64ToFile(base64Str, fpath)
  586. if err != nil {
  587. err = errors.New("图片保存失败" + err.Error())
  588. return
  589. }
  590. defer os.Remove(fpath)
  591. hzUploadDir := "static/images/"
  592. savePath := hzUploadDir + time.Now().Format("200601/20060102/")
  593. savePath += fileName
  594. //上传到阿里云 和 minio
  595. //if utils.ObjectStorageClient == "minio" {
  596. // err = UploadFileToMinIo(fileName, fpath, savePath)
  597. // if err != nil {
  598. // err = errors.New("文件上传失败" + err.Error())
  599. // return
  600. // }
  601. // resourceUrl = utils.MinIoImghost + savePath
  602. //} else {
  603. // err = UploadFileToAliyun(fileName, fpath, savePath)
  604. // if err != nil {
  605. // err = errors.New("文件上传失败" + err.Error())
  606. // return
  607. // }
  608. // resourceUrl = utils.Imghost + savePath
  609. //}
  610. ossClient := NewOssClient()
  611. if ossClient == nil {
  612. err = fmt.Errorf("初始化OSS服务失败")
  613. return
  614. }
  615. resourceUrl, err = ossClient.UploadFile(fileName, fpath, savePath)
  616. if err != nil {
  617. err = fmt.Errorf("文件上传失败, Err: %s", err.Error())
  618. return
  619. }
  620. item := new(models.Resource)
  621. item.ResourceUrl = resourceUrl
  622. item.ResourceType = 1
  623. item.CreateTime = time.Now()
  624. _, err = models.AddResource(item)
  625. if err != nil {
  626. err = errors.New("资源上传失败" + err.Error())
  627. return
  628. }
  629. return
  630. }
  631. // UpdateReportVideo 更新报告及其章节音频
  632. func UpdateReportVideo(reportId int) (err error) {
  633. defer func() {
  634. if err != nil {
  635. utils.FileLog.Error("UpdateReportVideo, reportId:%s, Err:%s", strconv.Itoa(reportId), err.Error())
  636. go alarm_msg.SendAlarmMsg("更新报告音频失败, 报告ID: "+strconv.Itoa(reportId)+", Err: "+err.Error(), 3)
  637. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "更新报告音频失败, 报告ID: " + reportIdStr + ", Err: "+err.Error(), utils.EmailSendToUsers)
  638. }
  639. }()
  640. if reportId == 0 {
  641. return
  642. }
  643. reportInfo, err := models.GetReportByReportId(reportId)
  644. if err != nil {
  645. return
  646. }
  647. if reportInfo.HasChapter == 1 {
  648. // 更新章节音频
  649. chapterList, tmpErr := models.GetPublishedChapterListByReportId(reportInfo.Id)
  650. if tmpErr != nil {
  651. err = tmpErr
  652. return
  653. }
  654. chapterIdArr := make([]string, 0)
  655. for i := 0; i < len(chapterList); i++ {
  656. chapterIdArr = append(chapterIdArr, strconv.Itoa(chapterList[i].ReportChapterId))
  657. }
  658. chapterIds := strings.Join(chapterIdArr, ",")
  659. //go UpdateChaptersVideo(chapterIds)
  660. err = UpdateChaptersVideo(chapterIds)
  661. } else {
  662. // 更新报告音频
  663. if reportInfo.VideoUrl != "" {
  664. return
  665. }
  666. nowTime := time.Now()
  667. updateCols := make([]string, 0)
  668. updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds")
  669. videoUrl, videoName, videoSize, videoPlaySeconds, tmpErr := CreateReportVideo(reportInfo.Title, html.UnescapeString(reportInfo.Content), nowTime.Format(utils.FormatDateTime))
  670. reportInfo.VideoUrl = videoUrl
  671. reportInfo.VideoName = videoName
  672. reportInfo.VideoSize = videoSize
  673. reportInfo.VideoPlaySeconds = fmt.Sprintf("%.2f", videoPlaySeconds)
  674. tmpErr = reportInfo.UpdateReport(updateCols)
  675. if tmpErr != nil {
  676. err = tmpErr
  677. return
  678. }
  679. }
  680. return
  681. }
  682. func UpdateEmptyVideoReportVideo() (err error) {
  683. list, err := models.GetSyncEmptyVideoReport()
  684. if err != nil {
  685. return
  686. }
  687. listLen := len(list)
  688. if listLen <= 0 {
  689. fmt.Println("无报告需要更新音频")
  690. return
  691. }
  692. fmt.Println("Start 待更新报告音频数: ", listLen)
  693. for i := 0; i < listLen; i++ {
  694. if err = UpdateReportVideo(list[i].Id); err != nil {
  695. fmt.Printf("更新音频失败")
  696. fmt.Println(err.Error())
  697. return
  698. }
  699. }
  700. fmt.Println("End 报告音频更新完毕")
  701. return
  702. }
  703. // checkDayWeekChapterWrite 校验晨周报已写章节与本期应写章节
  704. func checkDayWeekChapterWrite(chapters []*models.ReportChapter, reportType string) (publishReport bool, tips string, publishIdArr, unPublishIdArr []int, err error) {
  705. nowTime := time.Now().Local()
  706. updateTypeArr := make([]int, 0) // 需更新的章节类型IDs
  707. publishIdArr = make([]int, 0) // 需发布的章节IDs
  708. unPublishIdArr = make([]int, 0) // 需取消发布/未发布的章节IDs
  709. // 校验章节内容
  710. if reportType == utils.REPORT_TYPE_DAY {
  711. // 晨报章节不能都为空
  712. isEmpty := true
  713. for i := 0; i < len(chapters); i++ {
  714. if chapters[i].Content != "" && chapters[i].Title != "" {
  715. isEmpty = false
  716. break
  717. }
  718. }
  719. if isEmpty {
  720. err = errors.New("报告章节内容均为空或标题为空,不可发布")
  721. return
  722. }
  723. } else {
  724. // 周报章节需至少有一篇已编辑且有标题
  725. editNum := 0
  726. for i := 0; i < len(chapters); i++ {
  727. if chapters[i].IsEdit == 1 && chapters[i].Title != "" {
  728. editNum += 1
  729. }
  730. }
  731. if editNum == 0 {
  732. err = errors.New("报告均未编辑或标题为空,不可发布")
  733. return
  734. }
  735. }
  736. // 章节类型列表
  737. types, e := models.GetReportChapterTypeListByResearchType(reportType)
  738. if e != nil {
  739. err = errors.New("获取章节类型列表失败")
  740. return
  741. }
  742. // 本期需更新的章节IDs
  743. typeLen := len(types)
  744. for i := 0; i < typeLen; i++ {
  745. if types[i].IsSet != 1 && types[i].Enabled != 0 {
  746. // 正常更新
  747. updateTypeArr = append(updateTypeArr, types[i].ReportChapterTypeId)
  748. } else {
  749. // 被设置为零值的也算作正常更新
  750. if types[i].PauseStartTime == utils.EmptyDateStr && types[i].PauseEndTime == utils.EmptyDateStr {
  751. updateTypeArr = append(updateTypeArr, types[i].ReportChapterTypeId)
  752. continue
  753. }
  754. // 暂停更新需校验时间
  755. startTime, _ := time.Parse(utils.FormatDate, types[i].PauseStartTime)
  756. endTime, _ := time.Parse(utils.FormatDate, types[i].PauseEndTime)
  757. if nowTime.Before(startTime) || nowTime.After(endTime.AddDate(0, 0, 1)) {
  758. updateTypeArr = append(updateTypeArr, types[i].ReportChapterTypeId)
  759. }
  760. }
  761. }
  762. // 校验本期需更新的章节是否都已编辑
  763. chapterLen := len(chapters)
  764. updateTypeLen := len(updateTypeArr)
  765. tipsArr := make([]string, 0)
  766. for i := 0; i < chapterLen; i++ {
  767. isWrite := false
  768. for ii := 0; ii < updateTypeLen; ii++ {
  769. // 本期应发布的章节
  770. if chapters[i].TypeId == updateTypeArr[ii] {
  771. // 标题或者内容为空的情况下, 记录tips提示信息且不发布该章节
  772. if chapters[i].Title == "" || chapters[i].Content == "" {
  773. tipsArr = append(tipsArr, chapters[i].TypeName)
  774. break
  775. }
  776. isWrite = true
  777. break
  778. }
  779. }
  780. if isWrite {
  781. publishIdArr = append(publishIdArr, chapters[i].ReportChapterId)
  782. } else {
  783. unPublishIdArr = append(unPublishIdArr, chapters[i].ReportChapterId)
  784. }
  785. }
  786. if len(tipsArr) > 0 {
  787. tips = "部分章节未发布:" + strings.Join(tipsArr, "、") + "未填写标题/内容"
  788. }
  789. // 周报需发布的章节与需更新的章节数相等则表示可发布整期, 晨报无限制
  790. if reportType == utils.REPORT_TYPE_DAY {
  791. publishReport = true
  792. } else {
  793. if len(publishIdArr) == updateTypeLen {
  794. publishReport = true
  795. }
  796. }
  797. return
  798. }
  799. // PcCreateAndUploadSunCode 生成太阳码并上传OSS
  800. func PcCreateAndUploadSunCode(scene, page string) (imgUrl string, err error) {
  801. if page == "" {
  802. err = errors.New("page不能为空")
  803. return
  804. }
  805. // scene超过32位会生成失败,md5处理至32位
  806. sceneMD5 := "a=1"
  807. if scene != "" {
  808. sceneMD5 = utils.MD5(scene)
  809. }
  810. picByte, err := GetSunCode(page, sceneMD5)
  811. if err != nil {
  812. return
  813. }
  814. // 生成图片
  815. localPath := "./static/imgs"
  816. fileName := utils.GetRandStringNoSpecialChar(28) + ".png"
  817. fpath := fmt.Sprint(localPath, "/", fileName)
  818. f, err := os.Create(fpath)
  819. if err != nil {
  820. fmt.Println("11111")
  821. return
  822. }
  823. if _, err = f.Write(picByte); err != nil {
  824. return
  825. }
  826. defer func() {
  827. f.Close()
  828. os.Remove(fpath)
  829. }()
  830. // 上传OSS
  831. fileDir := "yb/suncode/"
  832. //上传到阿里云 和 minio
  833. //if utils.ObjectStorageClient == "minio" {
  834. // imgUrl, err = UploadMinIoToDir(fileName, fpath, "", fileDir)
  835. // if err != nil {
  836. // return
  837. // }
  838. //} else {
  839. // imgUrl, err = UploadAliyunToDir(fileName, fpath, "", fileDir)
  840. // if err != nil {
  841. // return
  842. // }
  843. //}
  844. savePath := fileDir + time.Now().Format("200601/20060102/") + fileName
  845. ossClient := NewOssClient()
  846. if ossClient == nil {
  847. err = fmt.Errorf("初始化OSS服务失败")
  848. return
  849. }
  850. imgUrl, err = ossClient.UploadFile(fileName, fpath, savePath)
  851. if err != nil {
  852. err = fmt.Errorf("文件上传失败, Err: %s", err.Error())
  853. return
  854. }
  855. if err != nil {
  856. return
  857. }
  858. // 记录参数
  859. if scene != "" {
  860. newSuncode := &models.YbPcSuncode{
  861. Scene: scene,
  862. SceneMd5: sceneMD5,
  863. CodePage: page,
  864. SuncodeUrl: imgUrl,
  865. CreateTime: time.Now(),
  866. }
  867. err = models.AddYbPcSunCode(newSuncode)
  868. }
  869. // 记录参数md5
  870. if scene != "" {
  871. newPars := &models.YbSuncodePars{
  872. Scene: scene,
  873. SceneKey: sceneMD5,
  874. CreateTime: time.Now(),
  875. }
  876. err = models.AddYbSuncodePars(newPars)
  877. }
  878. return
  879. }
  880. // CreateNewReport 创建新报告
  881. func CreateNewReport(req models.AddReq, adminInfo *system.Admin) (newReportId int64, reportCode, errMsg string, err error) {
  882. contentSub := ""
  883. if req.Content != "" {
  884. contentClean, e := FilterReportContentBr(req.Content)
  885. if e != nil {
  886. errMsg = "内容去除前后空格失败"
  887. err = errors.New("内容去除前后空格失败, Err: " + e.Error())
  888. return
  889. }
  890. req.Content = contentClean
  891. sub, e := GetReportContentSub(req.Content)
  892. if e != nil {
  893. go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+e.Error(), 3)
  894. }
  895. contentSub = sub
  896. }
  897. maxStage, e := models.GetReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond)
  898. if e != nil {
  899. errMsg = "期数获取失败!"
  900. err = errors.New("期数获取失败,Err:" + e.Error())
  901. return
  902. }
  903. item := new(models.Report)
  904. item.AddType = req.AddType
  905. item.ClassifyIdFirst = req.ClassifyIdFirst
  906. item.ClassifyNameFirst = req.ClassifyNameFirst
  907. item.ClassifyIdSecond = req.ClassifyIdSecond
  908. item.ClassifyNameSecond = req.ClassifyNameSecond
  909. item.Title = req.Title
  910. item.Abstract = req.Abstract
  911. item.Author = req.Author
  912. item.Frequency = req.Frequency
  913. item.State = req.State
  914. item.Content = html.EscapeString(req.Content)
  915. item.Stage = maxStage + 1
  916. item.ContentSub = html.EscapeString(contentSub)
  917. item.CreateTime = req.CreateTime
  918. item.ModifyTime = time.Now()
  919. item.ReportVersion = req.ReportVersion
  920. item.AdminId = adminInfo.AdminId
  921. item.AdminRealName = adminInfo.RealName
  922. newReportId, e = models.AddReport(item)
  923. if e != nil {
  924. errMsg = "保存失败"
  925. err = errors.New("保存失败,Err:" + e.Error())
  926. return
  927. }
  928. // 处理权限
  929. if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  930. go func() {
  931. permissionItems, e := models.GetPermission(req.ClassifyNameSecond)
  932. if e != nil {
  933. alarm_msg.SendAlarmMsg("获取权限失败,Err:"+err.Error(), 3)
  934. }
  935. for _, v := range permissionItems {
  936. e = models.AddChartPermissionChapterMapping(v.ChartPermissionId, newReportId)
  937. if e != nil {
  938. alarm_msg.SendAlarmMsg("新增权限失败,Err:"+err.Error(), 3)
  939. }
  940. }
  941. }()
  942. }
  943. reportCode = utils.MD5(strconv.Itoa(int(newReportId)))
  944. //修改唯一编码
  945. {
  946. go models.ModifyReportCode(newReportId, reportCode)
  947. }
  948. return
  949. }
  950. // FilterReportContentBr 过滤报告正文前后换行符
  951. func FilterReportContentBr(content string) (res string, err error) {
  952. newContent := content
  953. //content = `<p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><strong>四季度验证投产预期</strong></p><p style=\"font-size: 16px;\"><strong>&nbsp;</strong></p><p style=\"font-size: 16px;\"><strong>PTA:<strong><strong>近端短缺的格局出现缓解的迹象,表现在:PX进口回升;国内重整及常减压提负;PTA、PX投产在即</strong></strong><strong>。正套部分或全部止盈。</strong></strong></p><p style=\"font-size: 16px;\"><strong>&nbsp;</strong></p><p style=\"font-size: 16px;\"><strong>乙二醇:</strong><strong style=\"font-weight: 700; color: rgb(0, 0, 0); font-family: ;\">到港预报集中的情况下仍在去库,4200-4600区间震荡操作,节前没有明显方向,不建议在节前备货的时间段布局空单</strong><strong>。</strong></p><p style=\"font-size: 16px;\"><strong>&nbsp;</strong></p><p style=\"font-size: 16px;\"><strong>1、PX国内供应本周回落,PTA工厂负荷变动滞后于PX装置。</strong></p><p style=\"font-size: 16px;\">PX装置变动:</p><p style=\"font-size: 16px;\">海南炼化一期66万吨PX装置因故障停车检修,重启时间待跟踪,其二期100万吨PX装置预计在此装置重启后停车检修。</p><p style=\"font-size: 16px;\">天津石化一套100万吨重整已于20日重启中,其39万吨PX预计下周初出产品。</p><p style=\"font-size: 16px;\">韩国SK 位于仁川的130万吨PX装置按计划在23日停车检修,计划检修时长45天左右。</p><p style=\"font-size: 16px;\">截至周五,中国国内PX负荷小幅回落至73.4%(前值<span style=\"color: rgb(65, 65, 65); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;\">76.8</span>%),亚洲PX负荷小幅回落至68.7%(<span style=\"color: rgb(65, 65, 65); font-family: sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;\">72</span>%)。</p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/4VcA2eUE1Sgkx0KQ0NjchM0ajIis.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/vi3laEb3qejWISetD0SjGTwuAxUg.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=760c86a78c35ab9286903e9ce52a6682\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=1e36d11158bf146313f3f65a65dbc5f3\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=7a69494b1a84520b2cdf1dccb3c78bda\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=0a2e374c0689d5fba4a9dc40474a33b0\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"font-size: 16px;\">PXN本周延续回落至380美金附近。</p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=ad1b869f60ab31060730e8bd58260d8c\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=d1c87cb3adff22aea0fc37dfb1870626\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=bac98256b0b86e92ed4084fbbd223f5b\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><span style=\"font-size: 16px; font-family: Arial, Helvetica, sans-serif;\">PX平衡表</span></p><p style=\"margin: 0px; padding: 0px; font-size: 16px; color: rgb(0, 0, 0); font-family: ;\">海关统计,国内8月PX进口总量在78.8万吨,环比增加17.3万吨,增幅28%;同比减少30.8万吨,降幅28.1%;8月PX出口量0.47万吨,环比下降5万吨。</p><p style=\"margin: 0px; padding: 0px; font-size: 16px; color: rgb(0, 0, 0); font-family: ;\"><span style=\"color: rgb(0, 0, 0); font-family: ;\">PX 8月进口量大幅回升至79万吨附近,其中8月从韩国进口的PX量达到33.65万吨。9月目前公布的1-20号从韩国进口PX的量已经接近8月全月的水平,即环比8月仍是大幅增加的情况:</span><span style=\"font-size: 16px;\">据悉,9月1-20日韩国PX出口总量在30.9万吨,其中出口至中国27.9万吨。</span></p><p style=\"margin: 0px; padding: 0px; font-size: 16px; color: rgb(0, 0, 0); font-family: ;\"><span style=\"font-size: 16px;\">预计9月进口量环比8月进一步增加。</span></p><p style=\"margin: 0px; padding: 0px; font-size: 16px; color: rgb(0, 0, 0); font-family: ;\"><span style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/TD59rptBDNwJ7J2qpxd8HXi4X5cQ.png\" class=\"fr-fic fr-dib fr-draggable\"></span></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><strong><span style=\"color: rgb(0, 0, 0); font-family: ;\">原油本周偏弱,欧美汽油利润本周均出现了明显回升。</span></strong></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><strong><span style=\"color: rgb(0, 0, 0); font-family: ;\"><span style=\"color: rgb(34, 34, 34); font-family: system-ui, -apple-system, BlinkMacSystemFont, ;\">美国飓风将在下周登陆墨西哥湾,届时或将影响海上钻机的运行以及炼厂开工。</span>&nbsp;</span></strong></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=ef172d65e20b986351ed50545f3d36d1\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=4930c0981fc33ab125e6ef346c9cbd5b\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=f0cae34883508273d482d4cf8c577410\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><strong>2、</strong><strong>乙烯连续跌价至900美金,PX投产压力临近PXN延续压缩。石脑油亏损本周延续修复。</strong></p><p style=\"font-size: 16px;\">PTA:按照PX11-12月上1054美金(石脑油672美金,Brent86.15美金)计算,醋酸3075元,目前含醋酸的原料成本在5670元附近。可以发现虽然Brent和PX环比上周都出现了明显的下跌,但石脑油相对上周环比上涨,石脑油亏损本周延续修复,目前石脑油-Brent价差回升至0以上。</p><p style=\"font-size: 16px;\">给到200-300的最低加工成本,PTA的估值在5870-5970元。周五日盘收盘后TA11合约5742,11月及之后的PTA合约均亏损。</p><p style=\"font-size: 16px;\">PTA基差再度回升至1000附近,周五小幅走弱至970。</p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=3e743a3907292d9ad2dce6033ae7d8a4\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/Csak38HlAbt8XsbBsPeSWlaUKJiO.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/LOPKDaDnRnbJauWqlvbhQ5VNxa03.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/Ocdq2m3bMDqZnM8PTXVyj8XILt7Z.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=268b3f7204aa21accb8d292154cf4e3c\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"font-size: 16px;\">乙二醇:静态来看,按照盘面(煤价按照900元),锚定石脑油672美金,乙烯900美金,甲醇2640元,北美乙烷价格38美分/加仑计算,乙二醇的综合成本仍在5050元附近。周五日盘收盘01合约按照综合成本亏损700元附近。</p><p style=\"font-size: 16px;\">国内外采乙烷制乙二醇目前扭亏为盈。</p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=f1e3ba1df230353571d00af2dfb7e92a\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=0d17c186dda211dab039f2ccd39a8d76\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=3a93cb16f02731bc5c74b560f9590456\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=e1a38d9058b719d8dd5bf746bc9739be\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/drjYJ468Tpnr3Bno52CQZXRuayow.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/bv4JvZN7OxhXFnx0xL0EW6yGFlX8.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220918/54TYCFo1ulvOhbJpk9jQPJcnDyan.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/fZayI9g8kS2ILeVu799dBnAdugNB.png\" class=\"fr-fic fr-dib fr-draggable\"></p><ol style=\"margin: 0px; padding: 0px; list-style: none; color: rgb(0, 0, 0); font-family: ;\"><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><strong>3、</strong><span style=\"font-size: 16px; color: rgb(0, 0, 0); font-family: ;\"><strong>需求端本周仍偏弱:继上周加弹负荷下滑后,本周织造负荷下滑。延续坯布库存回升同时原料库存下降,聚酯连续累库(瓶片低库存优势也明显减弱),两家大厂减产执行过程和节前备货中和,因此减产去库成效甚微</strong><strong>。</strong></span><span style=\"font-size: 16px;\">&nbsp;</span></li><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><span style=\"font-size: 18px !important; color: rgb(0, 0, 0); font-family: Tahoma, ;\">终端:江浙加弹综合开工微幅回升至77%(前值</span><span style=\"font-size: 16px; color: rgb(0, 0, 0); font-family: Tahoma, ;\">76</span><span style=\"font-size: 18px !important; color: rgb(0, 0, 0); font-family: Tahoma, ;\">%);江浙织机综合开工回落至69%(前值</span><span style=\"font-size: 16px; color: rgb(0, 0, 0); font-family: Tahoma, ;\">71</span><span style=\"font-size: 18px !important; color: rgb(0, 0, 0); font-family: Tahoma, ;\">%);</span><span style=\"font-size: 18px !important; color: rgb(0, 0, 0); font-family: Tahoma, ;\">江浙印染综合开工维持在77%</span><span style=\"font-size: 18px !important; color: rgb(0, 0, 0); font-family: Tahoma, ;\">&nbsp;。</span></li><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><span style=\"font-size: 18px !important; color: rgb(0, 0, 0); font-family: Tahoma, ;\">本周,涤丝仅周三稍有放量,整体涤丝销售氛围偏弱为主。终端在新订单氛围走弱和成本端偏弱氛围下,原料不再进一步跟进,消化前期备货为主,综合原料备货有所下降。截至目前,原料备货集中在10-15天,偏高备货至10月底。</span></li><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><span style=\"font-size: 18px !important; color: rgb(0, 0, 0); font-family: Tahoma, ;\">订单情况:近期的织造端新单氛围整体走弱明显,前期较好的圆机和经编工厂尤为明显,出货量也有所放缓,部分工厂生产前期订单为主。</span><br><span style=\"font-size: 18px !important; color: rgb(0, 0, 0); font-family: Tahoma, ;\">直接需求:</span>近期装置轮动检修与重启,长丝大厂陆续执行减产动作,但也有几套切片装置恢复,整体而言聚酯负荷仍以区间波动为主。截至本周五,初步核算聚酯负荷在83.9%(前值84.3%)。</li></ol><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=9c163c32bf7fca689c0067e285eb1a30\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"font-size: 16px;\">轻纺城成交量节前震荡回升但仍在偏低水平。</p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/sHBC03ZwLXP1jUK1mDdd0hUjEtQo.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=5e2a381802d34c5cf33502d8a9649bd6\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><p style=\"text-align: left; margin-top: 10px; font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=e47bcc409b9b7e9178805ac6c4a00bc1\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe><br></p><p style=\"font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=12be062cbc0c61819f99648cef6e2740\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe><br></p><p style=\"font-size: 16px;\"><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=fea70f6d5bf7f1899394be0619cc2da1\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe><br><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=8a50b210b7ebb4fbb890d8ad58a817f6\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe><br><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=800bf3710951ca96c2e5a3693c94a20d\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe><br><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=fd1bff8836af41d0c32d0ed168c8b748\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe><br><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=baf493ba32b3c39e070e24ac5546fd6b\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></p><ul style=\"margin: 0px; padding: 0px; list-style: none; color: rgb(0, 0, 0); font-family: ;\"><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><strong>4、PTA行情沙盘推演<strong>2022.9.23:</strong><strong>PTA近端短缺的格局出现缓解的迹象,表现在:PX进口回升;国内重整及常减压提负;PTA、PX投产在即</strong></strong><strong>。正套部分或全部止盈。</strong></li></ul><p style=\"font-size: 16px;\"><img style=\"width: 100%;\" src=\"https://hzstatic.hzinsights.com/static/images/202209/20220922/d1HYjIFoBG9L2bGuWrXq7sBPpnT7.png\" class=\"fr-fic fr-dii fr-draggable\"><br></p><p style=\"font-size: 16px;\">PTA库存结构变化跟踪:本期PTA库存大幅去化17.9万吨附近(本周仓单集中注销,仓单库存大幅下降至0附近),聚酯成品折算PTA库存大幅累库9.3万吨,叠加PTA库存在聚酯成品库存累库的情况下去库8.6万吨。</p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/qYivQYoLkxJrmWGI5kNOy8i05q8P.png\" class=\"fr-fic fr-dib fr-draggable\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/cvLkXlLwczkvzktkN4R2SKCoHFby.png\" class=\"fr-fic fr-dib fr-draggable\" style=\"width: 572px;\"></p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/EzRc4yuCqVcbdw2lb5FS2MCWvHd1.png\" class=\"fr-fic fr-dib fr-draggable\" style=\"width: 595px;\"></p><p style=\"font-size: 16px;\">PTA平衡表——按照Q4有500万吨新装置投产(东营威联化学250万吨及嘉通能源250万吨分别在11、12月计入产能基数)计算,按照9-10月聚酯月均负荷84%(下调1%)、87%(下调1%)预估,8-12月出口预计25万吨附近。8-10月目前预估均为去库格局。</p><p style=\"font-size: 16px;\">PX折算PTA与PTA合计9月去库幅度修正后大幅收窄。</p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/6VzQkr5nkbeqlCakRzTvZgl1PeFE.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"margin: 0px; padding: 0px; font-size: 16px;\"><br></p><p style=\"margin: 0px; padding: 0px; font-size: 16px;\"><strong style=\"color: rgb(0, 0, 0); font-family: ;\">5、</strong><strong style=\"color: rgb(0, 0, 0); font-family: ;\">乙二醇行情沙盘推演2022.9.23:到港预报集中的情况下仍在去库,4200-4600区间震荡操作,节前没有明显方向,不建议在节前备货的时间段布局空单。</strong></p><p style=\"margin: 0px; padding: 0px; font-size: 16px;\"><strong style=\"color: rgb(0, 0, 0); font-family: ;\"><img style=\"width: 100%;\" src=\"https://hzstatic.hzinsights.com/static/images/202209/20220916/e5XTMMmx04X6wpKITZ2NgjUyz8sI.png\" class=\"fr-fic fr-dii fr-draggable\"></strong><br></p><p style=\"margin: 0px; padding: 0px; font-size: 16px;\">乙二醇国内供需:</p><ul style=\"margin: 0px; padding: 0px; list-style: none; color: rgb(0, 0, 0); font-family: ;\"><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><span style=\"color: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 28px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;\">乙二醇负荷低位仍在下降:截至9月22日,中国大陆地区乙二醇整体开工负荷在43.98%(较上期下降2.44%),其中煤制乙二醇开工负荷在28.67%(较上期下降2.08%)。</span><span style=\"font-family: Arial, Helvetica, sans-serif;\">&nbsp;</span></li><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\">后续供应存增加预期:</span></li><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\">上周意外停车的大连大型装置预计本周末或下周初开车。</span></li><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\">内蒙古40万吨装置装置周内正常出料,负荷回升中。</span></li><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\">陕西30万吨装置将于近日重启,预计9月底前后出料;内蒙古26万吨装置计划本月底前后投料重启。</span></li><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/Yy4lTK54zBA3ifN4DFdpAhE1TQ4w.png\" class=\"fr-fic fr-dib fr-draggable\"></span><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/eXC4GZApxmJQLQSZZ15HV6J1nGdK.png\" class=\"fr-fic fr-dib fr-draggable\"></li></ul><p style=\"font-size: 16px;\">乙二醇到港预报与实际到港:</p><p style=\"font-size: 16px;\"><span style=\"font-size: 16px; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; font-family: Arial, Helvetica, sans-serif; text-indent: 32px; float: none; display: inline !important;\"><span style=\"color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 32px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;\">隆众口径:截至9月29日,国内乙二醇华东总到港量预计在19.21万吨,较上一期增加3.45万吨,提升21.93个百分点。</span>&nbsp;</span></p><p style=\"font-size: 16px;\"><span style=\"font-size: 16px; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; font-family: Arial, Helvetica, sans-serif; text-indent: 32px; float: none; display: inline !important;\">港口发货节前回升。</span></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/WXVwl3NV0U68hnEjeNX5RFPGowq3.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/2FuGYgp5dpx6XbCNXLdSzdh4uzvp.png\" class=\"fr-fic fr-dib fr-draggable\"></p><p style=\"font-size: 16px;\">海外装置:</p><p style=\"font-size: 16px;\">印度IOC 32.5万吨装置将于近期停车技改,预计停车将持续至12月份。</p><p style=\"font-size: 16px;\">伊朗 Marun 44.5万吨装置目前处于停车状态,该装置此前货源供应印度市场为主。</p><p style=\"font-size: 16px;\">美国Sasol 28万吨装置计划于10月上旬停车检修,预计检修时长在一个月附近。</p><p style=\"font-size: 16px;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/CRzzaHscEcvhW8KXdajvLqABw11g.png\" class=\"fr-fic fr-dib fr-draggable\"></p><ul style=\"margin: 0px; padding: 0px; list-style: none; color: rgb(0, 0, 0); font-family: ;\"><li style=\"margin: 0px; padding: 0px; font-size: 16px;\">库存:</li><li style=\"margin: 0px; padding: 0px; font-size: 16px;\">隆众口径:<span style=\"font-size: 16px; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; font-family: Arial, Helvetica, sans-serif; text-indent: 32px; float: none; display: inline !important;\">截至9月22日,华东主港地区MEG港口库存总量81.6万吨,较上一统计周期减少3.64万吨,降低4.27%。受周末台风天气影响,主港本周到货延迟且整体出货尚可,本周港口库存延续去库走势。</span></li></ul><ul style=\"margin: 0px; padding: 0px; list-style: none;\"><li style=\"margin: 0px; padding: 0px; color: rgb(0, 0, 0); font-family: ;\">节前备货,聚酯工厂的乙二醇备货量本周小幅回升至84万吨附近。</li><li><br></li><li><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=c13c3e669ae5940893d1fd0e669754a5\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></li><li><iframe src=\"https://chartlib.hzinsights.com/chartshow?code=0fac897a91cbfcdb67958ae9e5d039a7\" width=\"100%\" height=\"350\" style=\"border-width:0px; min-height:350px;\"></iframe></li><li style=\"margin: 0px; padding: 0px;\"><span style=\"font-size: 16px; font-family: Arial, Helvetica, sans-serif;\">乙二醇平衡表:</span></li><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><span style=\"color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;\">2022年8月我国乙二醇当月进口量为598134.40吨,累计进口量为5189987.09吨,进口量环比升4.83%,进口量同比下跌23.97%,累计进口量比去年同期降9.28%。&nbsp;</span></li><li style=\"margin: 0px; padding: 0px; font-size: 16px;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\">按照9-10月聚酯月均负荷84%、87%,8月进口量比预估略多,9月因受到台风影响到港持续延迟,压力预计在9月下旬至9月底显现,因此预计也只有55万吨附近,Q4进口预计仍有差别,10-12月目前预计进口60-65万吨(其中10月或偏多)。</span></li><li style=\"margin: 0px; padding: 0px; font-size: 16px; font-family: Arial, Helvetica, sans-serif;\">进口量调整后,8月去库收窄至16万吨偏下,9月目前预计去库14万吨附近,10月累库压力来自于到港集中及新装置开始贡献产量,11月累库压力来自于需求回落+新装置产量提升。</li><li style=\"margin: 0px; padding: 0px; font-size: 16px; font-family: Arial, Helvetica, sans-serif;\">11-12月警惕供应端的超预期缩量。</li><li style=\"margin: 0px; padding: 0px; font-size: 16px; font-family: Arial, Helvetica, sans-serif;\"><img src=\"https://hongze.oss-accelerate.aliyuncs.com/static/images/202209/20220925/VEW93DsD4vrzXuNUfTMCFiJSU8Y3.png\" class=\"fr-fic fr-dib fr-draggable\"></li></ul><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p><p style=\"font-size: 16px;\"><br></p>`
  954. content = html.UnescapeString(content)
  955. if content == "" {
  956. return
  957. }
  958. // 过滤编辑器版权html
  959. content = strings.Replace(content, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
  960. defer func() {
  961. if err != nil {
  962. go alarm_msg.SendAlarmMsg("过滤报告正文前后换行符及空格失败, ErrMsg: "+err.Error(), 3)
  963. }
  964. }()
  965. // 做一个配置,有问题的时候随时关闭
  966. configKey := "report_filter_br"
  967. conf, e := company.GetConfigDetailByCode(configKey)
  968. if e != nil {
  969. err = errors.New("获取报告过滤配置失败, Err: " + e.Error())
  970. return
  971. }
  972. if conf.ConfigValue != "1" {
  973. return content, nil
  974. }
  975. // 找出所有<p>标签, <p>标签的索引
  976. re := regexp.MustCompile(`(?is:<p(.*?)</p>)`)
  977. arr := re.FindAllString(content, -1)
  978. indexArr := re.FindAllIndex([]byte(content), -1)
  979. // 空<p>正则
  980. emptyRe := `<p[^>]*>(<br>|<br/>)+</p>`
  981. startIsBr := false
  982. countEmptyBr := 0 // 需要连续替换的空<p>总数
  983. lastBrRange := 0 // 最后一个空<p>右侧index, 用来判断是否为连续的空<p>
  984. // 注:以下逻辑只适用于去除前面的空行, 由于编辑器始终会在文章最后面跟上自己的html标签, 此处不再进行后面空行的去除=_=!
  985. for i := range arr {
  986. byteRange := indexArr[i]
  987. if len(byteRange) == 2 {
  988. // 内容开头不为<p>直接跳出遍历, 否则才进行空<p>的判断
  989. if i == 0 && byteRange[0] == 0 {
  990. startIsBr = true
  991. }
  992. if !startIsBr {
  993. break
  994. }
  995. if lastBrRange != 0 {
  996. // 说明不是连续的空<p>, 中间出现了其他标签, 那么结束遍历, 进行最终的文本替换
  997. if lastBrRange != byteRange[0] {
  998. break
  999. }
  1000. }
  1001. // 正则匹配为空<p>则计数, 记录该空<p>右侧index
  1002. m, e := regexp.Match(emptyRe, []byte(arr[i]))
  1003. if e != nil {
  1004. err = e
  1005. return
  1006. }
  1007. if m {
  1008. countEmptyBr += 1
  1009. lastBrRange = byteRange[1]
  1010. continue
  1011. }
  1012. // 遍历到该<p>标签不为空了, 结束遍历
  1013. break
  1014. }
  1015. }
  1016. if countEmptyBr > 0 {
  1017. reg, e := regexp.Compile(emptyRe)
  1018. if e != nil {
  1019. err = errors.New("正则解析失败, Err: " + e.Error())
  1020. return
  1021. }
  1022. counted := 0 // 已替换数
  1023. res = reg.ReplaceAllStringFunc(content, func(s string) string {
  1024. counted += 1
  1025. if counted <= countEmptyBr {
  1026. return ""
  1027. } else {
  1028. return s
  1029. }
  1030. })
  1031. if res == "" {
  1032. res = newContent
  1033. }
  1034. } else {
  1035. res = content
  1036. if res == "" {
  1037. res = newContent
  1038. }
  1039. }
  1040. return
  1041. }
  1042. // GetEnglishReportOverview 获取英文研报overview部分
  1043. func GetEnglishReportOverview(content string) (res string, err error) {
  1044. content = html.UnescapeString(content)
  1045. doc, e := goquery.NewDocumentFromReader(strings.NewReader(content))
  1046. if e != nil {
  1047. err = errors.New("Create Doc Err: " + e.Error())
  1048. return
  1049. }
  1050. target := "overview"
  1051. label := "</strong>"
  1052. start := -1
  1053. end := -1
  1054. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  1055. h, e := s.Html()
  1056. if e != nil {
  1057. err = errors.New("Get Html1 Err: " + e.Error())
  1058. return
  1059. }
  1060. h = strings.ToLower(h)
  1061. t := s.Text()
  1062. t = strings.ToLower(t)
  1063. if strings.Contains(h, label) && t != "" && strings.Contains(t, target) {
  1064. start = i
  1065. }
  1066. if start != -1 && end == -1 && i > start && strings.Contains(h, label) {
  1067. end = i
  1068. }
  1069. })
  1070. if start != -1 && end != -1 {
  1071. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  1072. if i > start && i < end {
  1073. h, e := s.Html()
  1074. if e != nil {
  1075. err = errors.New("Get Html2 Err: " + e.Error())
  1076. return
  1077. }
  1078. // 包含iframe则过滤掉
  1079. if strings.Contains(h, "iframe") {
  1080. return
  1081. }
  1082. res += `<p>` + h + `</p>`
  1083. }
  1084. })
  1085. }
  1086. return
  1087. }
  1088. // GetReportContentSubWithoutIframe 获取报告正文前几段,过滤iframe
  1089. func GetReportContentSubWithoutIframe(content string) (contentSub string, err error) {
  1090. content = html.UnescapeString(content)
  1091. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  1092. if err != nil {
  1093. fmt.Println("create doc err:", err.Error())
  1094. return
  1095. }
  1096. label := "iframe"
  1097. n := 0
  1098. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  1099. if n >= 5 {
  1100. return
  1101. }
  1102. n++
  1103. h, err := s.Html()
  1104. if err != nil {
  1105. fmt.Println("get html err", err.Error())
  1106. return
  1107. }
  1108. // 包含iframe则过滤掉
  1109. if strings.Contains(h, label) {
  1110. return
  1111. }
  1112. if s.Text() != "" || strings.Contains(h, "src") {
  1113. contentSub = contentSub + "<p>" + h + "</p>"
  1114. }
  1115. })
  1116. return
  1117. }
  1118. // UpdateReportEditMark 更新研报当前更新状态
  1119. // status 枚举值 1:编辑中,0:完成编辑, 2:只做查询
  1120. func UpdateReportEditMark(reportId, nowUserId, status int, nowUserName string) (ret models.MarkReportResp, err error) {
  1121. //更新标记key
  1122. key := fmt.Sprint(`crm:report:edit:`, reportId)
  1123. ret.Status = 0
  1124. ret.Msg = "无人编辑"
  1125. opUserId, e := utils.Rc.RedisInt(key)
  1126. var opUser models.MarkReportItem
  1127. var classifyNameFirst string
  1128. if e != nil {
  1129. opUserInfoStr, tErr := utils.Rc.RedisString(key)
  1130. if tErr == nil {
  1131. tErr = json.Unmarshal([]byte(opUserInfoStr), &opUser)
  1132. if tErr == nil {
  1133. opUserId = opUser.AdminId
  1134. }
  1135. }
  1136. }
  1137. //判断是否是晨报或者周报,如果是则跳过
  1138. var reportInfo *models.ReportDetail
  1139. classifyNameFirst = opUser.ReportClassifyNameFirst
  1140. if reportId > 0 && status != 2 && classifyNameFirst == "" {
  1141. //查询报告ID信息
  1142. reportInfo, err = models.GetReportById(reportId)
  1143. if err != nil {
  1144. err = fmt.Errorf("报告不存在")
  1145. return
  1146. }
  1147. classifyNameFirst = reportInfo.ClassifyNameFirst
  1148. }
  1149. if classifyNameFirst == "晨报" || classifyNameFirst == "周报" {
  1150. return
  1151. }
  1152. if opUserId > 0 && opUserId != nowUserId {
  1153. editor := opUser.Editor
  1154. if editor == "" {
  1155. //查询账号的用户姓名
  1156. otherInfo, e := system.GetSysAdminById(opUserId)
  1157. if e != nil {
  1158. err = fmt.Errorf("查询其他编辑者信息失败")
  1159. return
  1160. }
  1161. editor = otherInfo.RealName
  1162. }
  1163. ret.Status = 1
  1164. ret.Msg = fmt.Sprintf("当前%s正在编辑报告", editor)
  1165. ret.Editor = editor
  1166. return
  1167. }
  1168. if status == 1 {
  1169. nowUser := &models.MarkReportItem{AdminId: nowUserId, Editor: nowUserName, ReportClassifyNameFirst: classifyNameFirst}
  1170. bt, e := json.Marshal(nowUser)
  1171. if e != nil {
  1172. err = fmt.Errorf("格式化编辑者信息失败")
  1173. return
  1174. }
  1175. if opUserId > 0 {
  1176. utils.Rc.Do("SETEX", key, int64(180), string(bt)) //3分钟缓存
  1177. } else {
  1178. utils.Rc.SetNX(key, string(bt), time.Second*60*3) //3分钟缓存
  1179. }
  1180. } else if status == 0 {
  1181. //清除编辑缓存
  1182. _ = utils.Rc.Delete(key)
  1183. }
  1184. return
  1185. }
  1186. // HandleVideoDecibel 处理报告中的音频文件
  1187. func HandleVideoDecibel(chapterInfo *models.ReportChapter) {
  1188. public_api.HandleVideoDecibel(chapterInfo.ReportChapterId)
  1189. return
  1190. }
  1191. // SaveReportLogs 记录报告日志
  1192. func SaveReportLogs(item *models.Report, chapters []*models.ReportChapter, adminId int, adminRealName string) {
  1193. if item == nil && len(chapters) == 0 {
  1194. return
  1195. }
  1196. var err error
  1197. defer func() {
  1198. if err != nil {
  1199. tips := fmt.Sprintf("报告日志记录, SaveReportLogs error: %s", err.Error())
  1200. go alarm_msg.SendAlarmMsg(tips, 2)
  1201. }
  1202. }()
  1203. if item != nil {
  1204. e := models.AddReportSaveLog(item.Id, item.AdminId, item.Content, item.ContentSub, item.AdminRealName)
  1205. if e != nil {
  1206. err = fmt.Errorf("AddReportSaveLog: %s", e.Error())
  1207. return
  1208. }
  1209. }
  1210. if len(chapters) > 0 {
  1211. e := models.MultiAddReportChaptersSaveLog(chapters, adminId, adminRealName)
  1212. if e != nil {
  1213. err = fmt.Errorf("MultiAddReportChaptersSaveLog: %s", e.Error())
  1214. return
  1215. }
  1216. }
  1217. return
  1218. }