summary_manage.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. package cygx
  2. import (
  3. "fmt"
  4. "github.com/PuerkitoBio/goquery"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "hongze/hz_crm_api/utils"
  8. "html"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. type SummaryManageAddRep struct {
  14. ArticleId int `description:"文章ID,等于0新增,大于0修改"`
  15. ArticleTypeId int `description:"文章类型ID"`
  16. ChartPermissionIds string `description:"行业ID ,多个用 , 隔开"`
  17. IndustryName string `description:"产业名称"`
  18. SubjectName string `description:"标的名称,多标的 用 , 隔开"`
  19. Title string `description:"标题"`
  20. Abstract string `description:"摘要"`
  21. Body string `description:"内容"`
  22. SellerAndMobile string `description:"销售和手机号"`
  23. DoType int `description:"操作类型 0,保存 、1,发布"`
  24. Department string `description:"作者"`
  25. IndustrialManagementIds string `description:"产业id 多个用 , 隔开"`
  26. IndustrialSubjectIds string `description:"标的id 多个用 , 隔开"`
  27. PublishDate string `description:"发布时间 列如 2020-03-23"`
  28. ReportLink string `description:"报告链接"`
  29. }
  30. type SummaryManageEditDetail struct {
  31. SummaryManageId int `description:"纪要ID 等于0新增纪要,大于0修改纪要"`
  32. ArticleId int `description:"文章ID"`
  33. //ChartPermissionId int `description:"行业ID"`
  34. ChartPermissionIds string `description:"行业ID ,多个用 , 隔开"`
  35. Title string `description:"标题"`
  36. Abstract string `description:"摘要"`
  37. Body string `description:"内容"`
  38. SellerAndMobile string `description:"销售和手机号"`
  39. SubjectName string `description:"标的名称"`
  40. IndustryName string `description:"产业名称"`
  41. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  42. ListIndustrial []*IndustrialActivityGroupManagementRep
  43. ListSubject []*SubjectActivityGroupManagementRep
  44. }
  45. type SummaryManageIdRep struct {
  46. ArticleId int `description:"文章ID"`
  47. }
  48. type CygxArticle struct {
  49. SummaryManageId int `orm:"column(id);pk"`
  50. CategoryName string `description:"行业分类名称"`
  51. CategoryId int `description:"行业分类ID"`
  52. CategoryIdTwo int `description:"分类id用作修改匹配类型使用"`
  53. ArticleId int `description:"文章ID"`
  54. Title string `description:"标题"`
  55. Abstract string `description:"摘要"`
  56. Body string `description:"内容"`
  57. BodyText string `description:"内容"`
  58. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  59. PublishDate time.Time `description:"发布时间"`
  60. CreateDate time.Time `description:"创建时间"`
  61. LastUpdatedTime time.Time `description:"更新时间"`
  62. IsSummary int `description:"是否属于纪要库 1是、0否"`
  63. IsReport int `description:"是否属于报告 1是、0否"`
  64. ReportType int `description:"'报告类型,1行业报告,2产业报告'"`
  65. Source int `description:"来源 0策略平台同步,1小程序后台添加"`
  66. MatchTypeName string `description:"匹配类型名称"`
  67. ArticleIdMd5 string `description:"ID,md5值"`
  68. UpdateFrequency string `description:"更新周期"`
  69. SellerAndMobile string `description:"销售和手机号"`
  70. Department string `description:"作者"`
  71. ExpertBackground string `description:"专家背景"`
  72. ExpertNumber string `description:"专家编号"`
  73. InterviewDate string `description:"访谈日期"`
  74. FileLink string `description:"下载预览链接"`
  75. ChartPermissionIds string `description:"行业ID ,多个用 , 隔开"`
  76. DepartmentId int `description:"作者ID"`
  77. Periods string `description:"期数"`
  78. ReportLink string `description:"报告链接"`
  79. ArticleType string `description:"文章类型 文章类型,lyjh:路演精华 "`
  80. HavePublish int `description:"是否发布过,1是 ,0 否"`
  81. IsClass int `description:"是否归类过,1是 ,0 否"`
  82. SubCategoryName string `description:"主题名称"`
  83. LinkArticleId int `description:"报告ID链接"`
  84. AdminId int `description:"销售/管理员ID"`
  85. AdminName string `description:"销售/管理员姓名"`
  86. ArticleTypeId int `description:"文章类型ID"`
  87. ArticleTypeName string `description:"文章类型名称"`
  88. Annotation string `description:"核心观点"`
  89. VisibleRange int `description:"设置可见范围1全部,0内部"`
  90. //NickName string `description:"作者昵称"`
  91. }
  92. type CygxArticleResp struct {
  93. SummaryManageId int `orm:"column(id);pk"`
  94. CategoryName string `description:"行业分类名称"`
  95. CategoryId int `description:"行业分类ID"`
  96. CategoryIdTwo int `description:"行业分类ID"`
  97. ArticleId int `description:"文章ID"`
  98. Title string `description:"标题"`
  99. Abstract string `description:"摘要"`
  100. Body string `description:"内容"`
  101. BodyText string `description:"内容"`
  102. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  103. PublishDate time.Time `description:"发布时间"`
  104. CreateDate time.Time `description:"创建时间"`
  105. LastUpdatedTime time.Time `description:"更新时间"`
  106. IsSummary int `description:"是否属于纪要库 1是、0否"`
  107. IsReport int `description:"是否属于报告 1是、0否"`
  108. Source int `description:"来源 0策略平台同步,1小程序后台添加"`
  109. ArticleIdMd5 string `description:"ID,md5值"`
  110. UpdateFrequency string `description:"更新周期"`
  111. SellerAndMobile string `description:"销售和手机号"`
  112. Department string `description:"作者"`
  113. ExpertBackground string `description:"专家背景"`
  114. ExpertNumber string `description:"专家编号"`
  115. InterviewDate string `description:"访谈日期"`
  116. FileLink string `description:"下载预览链接"`
  117. ChartPermissionIds string `description:"行业ID ,多个用 , 隔开"`
  118. DepartmentId int `description:"作者ID"`
  119. Periods string `description:"期数"`
  120. ReportLink string `description:"报告链接"`
  121. ArticleType string `description:"文章类型 文章类型,lyjh:路演精华 "`
  122. HavePublish int `description:"是否发布过,1是 ,0 否"`
  123. IsClass int `description:"是否归类过,1是 ,0 否"`
  124. IsClassFail int `description:"是否自动归类失败,1是 ,0 否"`
  125. SubCategoryName string `description:"主题名称"`
  126. LinkArticleId int `description:"报告ID链接"`
  127. NickName string `description:"作者昵称"`
  128. HeadImgUrl string `description:"作者头像"`
  129. SubjectIds string `description:"报告所关联的标的"`
  130. AdminId int `description:"销售/管理员ID"`
  131. AdminName string `description:"销售/管理员姓名"`
  132. Annotation string `description:"核心观点"`
  133. VisibleRange int `description:"设置可见范围1全部,0内部"`
  134. TopTime int `description:"置顶时间"`
  135. }
  136. type GetSummaryManageListRep struct {
  137. Paging *paging.PagingItem `description:"分页数据"`
  138. List []*CygxArticleList
  139. }
  140. type ElasticTestArticleDetail struct {
  141. ArticleId int `description:"报告id"`
  142. Title string `description:"标题"`
  143. BodyText string `description:"内容"`
  144. PublishDate string `description:"发布时间"`
  145. ExpertBackground string `description:"专家背景"`
  146. CategoryId string `description:"文章分类"`
  147. Abstract string `description:"摘要"`
  148. Annotation string `description:"核心观点"`
  149. }
  150. // 添加文章
  151. func AddArticle(item *CygxArticle) (newId int64, err error) {
  152. o := orm.NewOrmUsingDB("hz_cygx")
  153. newId, err = o.Insert(item)
  154. fmt.Println(newId)
  155. return
  156. }
  157. //item.ExpertBackground = expertContentStr
  158. //item.ExpertNumber = expertNumStr
  159. //item.InterviewDate = interviewDateStr
  160. //item.FileLink = fileLink
  161. // 修改文章
  162. func EditArticle(item *CygxArticle, oldPublishStatus int) (err error) {
  163. o := orm.NewOrmUsingDB("hz_cygx")
  164. if oldPublishStatus == 1 {
  165. sql := `UPDATE cygx_article SET category_name=?, title=?, abstract=?, body=?, body_text=?, publish_status=?,last_updated_time = ?,seller_and_mobile=?,expert_background =?, expert_number=? ,interview_date=?, file_link=? ,chart_permission_ids =? WHERE id=? AND source = 1`
  166. _, err = o.Raw(sql, item.CategoryName, item.Title, item.Abstract, item.Body, item.BodyText, item.PublishStatus, item.LastUpdatedTime, item.SellerAndMobile, item.ExpertBackground, item.ExpertNumber, item.InterviewDate, item.FileLink, item.ChartPermissionIds, item.SummaryManageId).Exec()
  167. } else {
  168. if item.PublishStatus == 1 {
  169. sql := `UPDATE cygx_article SET category_name=?, title=?, abstract=?, body=?, body_text=?, publish_status=?, publish_date =? ,last_updated_time = ?,seller_and_mobile=?,expert_background =?, expert_number=? ,interview_date=?, file_link=?,chart_permission_ids =? WHERE id=? AND source = 1`
  170. _, err = o.Raw(sql, item.CategoryName, item.Title, item.Abstract, item.Body, item.BodyText, item.PublishStatus, item.PublishDate, item.LastUpdatedTime, item.SellerAndMobile, item.ExpertBackground, item.ExpertNumber, item.InterviewDate, item.FileLink, item.ChartPermissionIds, item.SummaryManageId).Exec()
  171. } else {
  172. sql := `UPDATE cygx_article SET category_name=?, title=?, abstract=?, body=?, body_text=?, publish_status=?,last_updated_time = ?, publish_date = '' ,seller_and_mobile=?,expert_background =?, expert_number=? ,interview_date=?, file_link=?,chart_permission_ids =? WHERE id=? AND source = 1`
  173. _, err = o.Raw(sql, item.CategoryName, item.Title, item.Abstract, item.Body, item.BodyText, item.PublishStatus, item.LastUpdatedTime, item.SellerAndMobile, item.ExpertBackground, item.ExpertNumber, item.InterviewDate, item.FileLink, item.ChartPermissionIds, item.SummaryManageId).Exec()
  174. }
  175. }
  176. return
  177. }
  178. func GetMaxArticleIdInfo() (item *ArticleDetail, err error) {
  179. o := orm.NewOrmUsingDB("hz_cygx")
  180. sql := `SELECT * FROM cygx_article ORDER BY article_id desc LIMIT 1`
  181. err = o.Raw(sql).QueryRow(&item)
  182. return
  183. }
  184. // 通过纪要ID获取文章详情
  185. func GetArticleIdInfoBySummaryManageId(summaryManageId int) (item *CygxArticleResp, err error) {
  186. o := orm.NewOrmUsingDB("hz_cygx")
  187. sql := `SELECT art.* ,dm.nick_name FROM cygx_article as art
  188. LEFT JOIN cygx_article_department as dm ON dm.department_id = art.department_id WHERE id=? AND source = 1`
  189. err = o.Raw(sql, summaryManageId).QueryRow(&item)
  190. return
  191. }
  192. // 通过文章ID获取文章、以及所关联的标的详情
  193. func GetArticleInfoOtherByArticleId(articleId int) (item *CygxArticleResp, err error) {
  194. o := orm.NewOrmUsingDB("hz_cygx")
  195. sql := `SELECT art.* ,dm.nick_name ,dm.img_url as head_img_url FROM cygx_article as art
  196. LEFT JOIN cygx_article_department as dm ON dm.department_id = art.department_id WHERE article_id=? `
  197. err = o.Raw(sql, articleId).QueryRow(&item)
  198. return
  199. }
  200. // 通过纪要ID获取文章详情
  201. func GetArticleIdInfoByArticleId(articleId int) (item *CygxArticle, err error) {
  202. o := orm.NewOrmUsingDB("hz_cygx")
  203. sql := `SELECT * FROM cygx_article WHERE article_id= ?`
  204. err = o.Raw(sql, articleId).QueryRow(&item)
  205. return
  206. }
  207. func GetReportContentTextSub(content string) (contentSub string, err error) {
  208. content = html.UnescapeString(content)
  209. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  210. docText := doc.Text()
  211. bodyRune := []rune(docText)
  212. bodyRuneLen := len(bodyRune)
  213. if bodyRuneLen > 200 {
  214. bodyRuneLen = 200
  215. }
  216. body := string(bodyRune[:bodyRuneLen])
  217. contentSub = body
  218. return
  219. }
  220. // 修改发布状态
  221. func PublishAndCancel(item *CygxArticle) (err error) {
  222. sql := `UPDATE cygx_article SET publish_status=? ,admin_id =? ,admin_name =? WHERE article_id=? `
  223. o := orm.NewOrmUsingDB("hz_cygx")
  224. _, err = o.Raw(sql, item.PublishStatus, item.AdminId, item.AdminName, item.ArticleId).Exec()
  225. return
  226. }
  227. // 修改发布状态
  228. func ArticleVisibleRange(item *CygxArticle) (err error) {
  229. sql := `UPDATE cygx_article SET visible_range=? ,admin_id =? ,admin_name =? WHERE article_id=? `
  230. o := orm.NewOrmUsingDB("hz_cygx")
  231. _, err = o.Raw(sql, item.VisibleRange, item.AdminId, item.AdminName, item.ArticleId).Exec()
  232. return
  233. }
  234. // 修改发布状态
  235. func UpdateIsClassFail(item *CygxArticleResp) (err error) {
  236. sql := `UPDATE cygx_article SET is_class_fail=0 WHERE article_id=? `
  237. o := orm.NewOrmUsingDB("hz_cygx")
  238. _, err = o.Raw(sql, item.ArticleId).Exec()
  239. return
  240. }
  241. // 通过纪要ID获取文章详情
  242. func GetArticleIdInfoBySummaryManageIdEdit(summaryManageId int) (item *CygxArticle, err error) {
  243. o := orm.NewOrmUsingDB("hz_cygx")
  244. sql := `SELECT * FROM cygx_article WHERE id=? AND source = 1`
  245. err = o.Raw(sql, summaryManageId).QueryRow(&item)
  246. return
  247. }
  248. // 删除数据
  249. func DeleteSummaryManage(summaryManageId int) (err error) {
  250. o := orm.NewOrmUsingDB("hz_cygx")
  251. sql := ` DELETE FROM cygx_article WHERE id=? AND source = 1`
  252. _, err = o.Raw(sql, summaryManageId).Exec()
  253. return
  254. }
  255. type CygxArticleList struct {
  256. ArticleId int `description:"报告id"`
  257. CategoryName string `description:"行业分类名称"`
  258. Title string `description:"标题"`
  259. Abstract string `description:"摘要"`
  260. Body string `description:"内容"`
  261. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  262. PublishDate string `description:"发布时间"`
  263. LastUpdatedTime string `description:"更新时间"`
  264. ArticleIdMd5 string `description:"ID,md5值"`
  265. Pv int `description:"PV"`
  266. Uv int `description:"UV"`
  267. CommentNum int `description:"留言总数"`
  268. CollectionNum int `description:"收藏"`
  269. NickName string `description:"作者昵称"`
  270. DepartmentId int `description:"作者ID"`
  271. IndustryName string `description:"产业名称"`
  272. SubjectName string `description:"标的名称"`
  273. ArticleTypeId int `description:"文章类型ID"`
  274. ArticleTypeName string `description:"文章类型名称"`
  275. VisibleRange int `description:"设置可见范围1全部,0内部"`
  276. TopTime int `description:"置顶时间"`
  277. }
  278. // 列表
  279. func GetSummaryManageList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxArticleList, err error) {
  280. o := orm.NewOrmUsingDB("hz_cygx")
  281. sql := ` SELECT
  282. (SELECT COUNT(1) FROM cygx_article_history_record_newpv AS h WHERE h.article_id=art.article_id AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) + ` ) AS pv,
  283. (SELECT COUNT(DISTINCT h.user_id) FROM cygx_article_history_record_newpv AS h WHERE h.article_id=art.article_id AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) + ` ) AS uv,
  284. (SELECT COUNT(1) FROM cygx_article_comment AS k WHERE k.article_id=art.article_id) AS comment_num,
  285. (SELECT COUNT(1) FROM cygx_article_collect AS c WHERE c.article_id = art.article_id ) AS collection_num,
  286. (SELECT GROUP_CONCAT(DISTINCT s.subject_name SEPARATOR '/') FROM cygx_industrial_subject as s WHERE s.industrial_management_id = m.industrial_management_id) AS subject_name ,
  287. art.title ,art.category_name ,art.publish_date ,art.id,art.last_updated_time,art.publish_status,art.abstract,art.body,art.article_id_md5 ,art.article_id,dm.nick_name , art.department_id,m.industry_name,art.article_type_id,art.article_type_name,art.visible_range,art.top_time
  288. FROM cygx_article as art
  289. LEFT JOIN cygx_article_department as dm ON dm.department_id = art.department_id
  290. LEFT JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  291. LEFT JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id`
  292. if condition != "" {
  293. sql += condition
  294. }
  295. sql += ` LIMIT ?,?`
  296. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  297. return
  298. }
  299. // 列表
  300. func GetSummaryManageListInit(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxArticleList, err error) {
  301. o := orm.NewOrmUsingDB("hz_cygx")
  302. sql := `SELECT
  303. art.title,
  304. art.article_id,
  305. dm.nick_name,
  306. art.top_time
  307. FROM
  308. cygx_article AS art
  309. INNER JOIN cygx_article_department AS dm ON dm.department_id = art.department_id`
  310. if condition != "" {
  311. sql += condition
  312. }
  313. sql += ` LIMIT ?,?`
  314. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  315. return
  316. }
  317. // 列表
  318. func GetCygxArticleList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxReportArticle, err error) {
  319. o := orm.NewOrmUsingDB("hz_cygx")
  320. sql := ` SELECT *
  321. FROM cygx_article as art WHERE 1 =1 `
  322. if condition != "" {
  323. sql += condition
  324. } else {
  325. return
  326. }
  327. sql += ` LIMIT ?,?`
  328. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  329. return
  330. }
  331. type CygxArticleSubjectList struct {
  332. ArticleId int `description:"报告id"`
  333. SubjectName string `description:"标的名称"`
  334. }
  335. // 文章标的列表
  336. func GetArticleSubjectList(articleId string) (items []*CygxArticleSubjectList, err error) {
  337. if articleId == "" {
  338. articleId = "0"
  339. }
  340. o := orm.NewOrmUsingDB("hz_cygx")
  341. sql := ` SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) AS subject_name,
  342. sg.article_id
  343. FROM
  344. cygx_industrial_article_group_subject AS sg
  345. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  346. WHERE
  347. sg.article_id IN (` + articleId + `)
  348. GROUP BY sg.article_id`
  349. _, err = o.Raw(sql).QueryRows(&items)
  350. return
  351. }
  352. // 获取文章数量
  353. func GetASummaryManageCount(condition string, pars []interface{}) (count int, err error) {
  354. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article as art `
  355. if condition != "" {
  356. sqlCount += condition
  357. }
  358. o := orm.NewOrmUsingDB("hz_cygx")
  359. err = o.Raw(sqlCount, pars).QueryRow(&count)
  360. return
  361. }
  362. // body 解析
  363. func BodyAnalysis(body string) (expertNumStr, expertContentStr, interviewDateStr, fileLink string) {
  364. body = html.UnescapeString(body)
  365. doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
  366. if err != nil {
  367. fmt.Println("create doc err:", err.Error())
  368. return
  369. }
  370. var expertNumArr []string
  371. var expertContentArr []string
  372. var interviewDateArr []string
  373. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  374. contentTxt := s.Text()
  375. if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
  376. interviewDate := s.Next().Text()
  377. interviewDateArr = append(interviewDateArr, interviewDate)
  378. }
  379. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  380. expertContent := s.Next().Text()
  381. //Powered 是编辑器传过来的字段
  382. if expertContent == "" || strings.Contains(expertContent, "Powered") {
  383. expertContent = contentTxt
  384. }
  385. //如果内容中最前的文字是 "专家" 这个词,则认为这句话是专家背景
  386. if !strings.Contains(expertContent, "专家评价") && strings.Contains(expertContent, "专家") && strings.Index(expertContent, "专家") == 0 {
  387. expertContentArr = append(expertContentArr, expertContent)
  388. }
  389. if expertContent != "" {
  390. rightIndex := strings.Index(expertContent, ")")
  391. if rightIndex == 0 {
  392. rightIndex = strings.Index(expertContent, ")")
  393. }
  394. if rightIndex > 0 {
  395. expertNum := expertContent[:rightIndex]
  396. expertNum = strings.Replace(expertNum, "(", "", -1)
  397. expertNum = strings.Replace(expertNum, "(", "", -1)
  398. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  399. if expertNum != "" {
  400. expertNumArr = append(expertNumArr, expertNum)
  401. rightIndex = rightIndex
  402. expertContentStr := expertContent[rightIndex:]
  403. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  404. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  405. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  406. expertContentArr = append(expertContentArr, expertContentStr)
  407. }
  408. }
  409. if !strings.Contains(contentTxt, "(") || !strings.Contains(contentTxt, "(") {
  410. expertContentArr = append(expertContentArr, expertContent)
  411. }
  412. }
  413. }
  414. })
  415. if len(expertContentArr) == 0 {
  416. doc.Find("pre").Each(func(i int, s *goquery.Selection) {
  417. contentTxt := s.Text()
  418. if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
  419. interviewDate := s.Next().Text()
  420. numStar := strings.Index(contentTxt, " #访谈时间:")
  421. numEnd := strings.Index(contentTxt, " #纪要详情:")
  422. interviewDate = contentTxt[numStar+19 : numEnd]
  423. if interviewDate != "" {
  424. interviewDateArr = append(interviewDateArr, interviewDate)
  425. }
  426. }
  427. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  428. expertContent := s.Next().Text()
  429. if expertContent == "" {
  430. expertContent = contentTxt
  431. }
  432. if expertContent != "" {
  433. expertIsHave := strings.Index(expertContent, "专家评价")
  434. if expertIsHave > 0 {
  435. expertContent = expertContent[expertIsHave:]
  436. rightIndex := strings.Index(expertContent, ")")
  437. if rightIndex == 0 {
  438. rightIndex = strings.Index(expertContent, ")")
  439. }
  440. if rightIndex > 0 {
  441. expertNum := expertContent[:rightIndex]
  442. expertNum = strings.Replace(expertNum, "(", "", -1)
  443. expertNum = strings.Replace(expertNum, "(", "", -1)
  444. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  445. expertNum = strings.Replace(expertNum, ":", "", -1)
  446. expertNum = strings.Replace(expertNum, ":", "", -1)
  447. if expertNum != "" {
  448. expertNumArr = append(expertNumArr, expertNum)
  449. rightIndex = rightIndex
  450. expertContentStr := expertContent[rightIndex:]
  451. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  452. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  453. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  454. if expertContentStr != "" {
  455. expertContentArr = append(expertContentArr, expertContentStr)
  456. }
  457. }
  458. }
  459. }
  460. if !strings.Contains(contentTxt, "(") || !strings.Contains(contentTxt, "(") {
  461. expertContentArr = append(expertContentArr, expertContent)
  462. }
  463. }
  464. }
  465. })
  466. }
  467. if len(expertNumArr) > 0 {
  468. expertNumStr = expertNumArr[0]
  469. if expertNumStr != "" {
  470. expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
  471. expertNumStr = strings.Replace(expertNumStr, "# ", "", -1)
  472. expertNumStr = strings.Trim(expertNumStr, "")
  473. }
  474. }
  475. if len(expertContentArr) > 0 {
  476. expertContentStr = expertContentArr[0]
  477. }
  478. if len(expertContentStr) > 600 {
  479. strnum := strings.Index(expertContentStr, "#专家评价:")
  480. content := expertContentStr[strnum:]
  481. strnum2 := strings.Index(content, "(")
  482. content = content[strnum2+9:] //中文括号3位 专家编号6位
  483. expertContentStr = content
  484. }
  485. if len(interviewDateArr) > 0 {
  486. interviewDateStr = interviewDateArr[0]
  487. }
  488. return
  489. }
  490. // 列表
  491. func GetCygxArticleCollectionList(articleId int) (items []*CygxDepartmentFllowList, err error) {
  492. o := orm.NewOrmUsingDB("hz_cygx")
  493. sql := `SELECT
  494. f.*
  495. FROM
  496. cygx_article_collect AS f
  497. WHERE
  498. f.article_id = ?
  499. GROUP BY f.id`
  500. _, err = o.Raw(sql, articleId).QueryRows(&items)
  501. return
  502. }
  503. type ArticleHistoryRep struct {
  504. ArticleId int `description:"文章ID"`
  505. RealName string `description:"姓名"`
  506. Mobile string `description:"手机号"`
  507. CompanyName string `description:"公司名称"`
  508. CompanyId int `description:"文章ID"`
  509. SellerName string `description:"所属销售"`
  510. StopTime string `description:"阅读停留时间"`
  511. CreateTime string `description:"创建时间"`
  512. Ly string `description:"创建时间"`
  513. Source string `description:"创建时间"`
  514. }
  515. // 列表
  516. func GetArticleHistoryList(articleId int, condition string) (items []*ArticleHistoryRep, err error) {
  517. o := orm.NewOrmUsingDB("hz_cygx")
  518. sql := `SELECT
  519. h.*
  520. FROM
  521. cygx_article_history_record_all AS h
  522. WHERE
  523. h.article_id = ?
  524. AND h.platfor = 1 AND h.is_del = 0 `
  525. if condition != "" {
  526. sql = sql + condition + ` group by mobile `
  527. }
  528. _, err = o.Raw(sql, articleId).QueryRows(&items)
  529. return
  530. }
  531. // 列表
  532. func GetArticleHistoryList_H(articleId int, condition string) (items []*ArticleHistoryRep, err error) {
  533. o := orm.NewOrmUsingDB("hz_cygx")
  534. sql := `SELECT
  535. h.*
  536. FROM
  537. cygx_article_history_record_all AS h
  538. WHERE
  539. h.article_id = ?
  540. AND h.platfor = 1 AND h.is_del = 0 AND h.create_time <'2024-11-28 15:50' `
  541. if condition != "" {
  542. sql = sql + condition + ` group by mobile `
  543. }
  544. _, err = o.Raw(sql, articleId).QueryRows(&items)
  545. return
  546. }
  547. // 列表
  548. func GetArticleHistoryListInit(ArticleIds, companyIds []int) (items []*ArticleHistoryRep, err error) {
  549. o := orm.NewOrmUsingDB("hz_cygx")
  550. sql := `SELECT
  551. h.*
  552. FROM
  553. cygx_article_history_record_all AS h
  554. WHERE
  555. 1=1
  556. AND h.platfor = 1 AND create_time >= '2023.09.01' AND create_time < '2024.09.02' AND h.is_del = 0 AND article_id IN (` + utils.GetOrmInReplace(len(ArticleIds)) + `) AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) `
  557. sql += ` ORDER BY id DESC `
  558. _, err = o.Raw(sql, ArticleIds, companyIds).QueryRows(&items)
  559. return
  560. }
  561. // 用户阅读记录,不过滤弘则内部的
  562. func GetArticleHistoryListOld(articleId int, condition string) (items []*ArticleHistoryRep, err error) {
  563. o := orm.NewOrmUsingDB("hz_cygx")
  564. sql := `SELECT
  565. h.*
  566. FROM
  567. cygx_article_history_record AS h
  568. WHERE
  569. h.article_id = ?
  570. AND c.product_id = 2`
  571. if condition != "" {
  572. sql = sql + condition + ` GROUP BY h.id`
  573. }
  574. _, err = o.Raw(sql, articleId).QueryRows(&items)
  575. return
  576. }
  577. // 列表
  578. func GetSellerUserMobileList(condition string) (items []*ArticleHistoryRep, err error) {
  579. o := orm.NewOrm()
  580. sql := `SELECT mobile FROM wx_user as h WHERE h.mobile != '' ` + condition
  581. _, err = o.Raw(sql).QueryRows(&items)
  582. return
  583. }
  584. type ArticleTypeAndAbstract struct {
  585. Abstract string
  586. ArticleTypeId int
  587. }
  588. func GetArticleTypeAndAbstract() (list []*ArticleTypeAndAbstract, err error) {
  589. o := orm.NewOrmUsingDB("hz_cygx")
  590. sql := `SELECT
  591. *
  592. FROM
  593. ( SELECT abstract, article_type_id FROM cygx_article GROUP BY publish_date DESC ) AS a
  594. GROUP BY
  595. a.article_type_id `
  596. _, err = o.Raw(sql).QueryRows(&list)
  597. return
  598. }
  599. // 更新文章置顶时间
  600. func UpdateArticleTopTime(activityId, topTime int) (err error) {
  601. o := orm.NewOrmUsingDB("hz_cygx")
  602. sql := ` UPDATE cygx_article SET top_time=? WHERE article_id=?`
  603. _, err = o.Raw(sql, topTime, activityId).Exec()
  604. return
  605. }
  606. // 添加朋友圈分享封面图片
  607. func UpdateCygxArticleMomentsImg(momentsImg string, articleId int) (err error) {
  608. sql := `UPDATE cygx_article SET moments_img=? WHERE article_id=? `
  609. o := orm.NewOrmUsingDB("hz_cygx")
  610. _, err = o.Raw(sql, momentsImg, articleId).Exec()
  611. return
  612. }