summary_manage.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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 GetCygxArticleList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxReportArticle, err error) {
  301. o := orm.NewOrmUsingDB("hz_cygx")
  302. sql := ` SELECT *
  303. FROM cygx_article as art WHERE 1 =1 `
  304. if condition != "" {
  305. sql += condition
  306. } else {
  307. return
  308. }
  309. sql += ` LIMIT ?,?`
  310. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  311. return
  312. }
  313. type CygxArticleSubjectList struct {
  314. ArticleId int `description:"报告id"`
  315. SubjectName string `description:"标的名称"`
  316. }
  317. // 文章标的列表
  318. func GetArticleSubjectList(articleId string) (items []*CygxArticleSubjectList, err error) {
  319. if articleId == "" {
  320. articleId = "0"
  321. }
  322. o := orm.NewOrmUsingDB("hz_cygx")
  323. sql := ` SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) AS subject_name,
  324. sg.article_id
  325. FROM
  326. cygx_industrial_article_group_subject AS sg
  327. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  328. WHERE
  329. sg.article_id IN (` + articleId + `)
  330. GROUP BY sg.article_id`
  331. _, err = o.Raw(sql).QueryRows(&items)
  332. return
  333. }
  334. // 获取文章数量
  335. func GetASummaryManageCount(condition string, pars []interface{}) (count int, err error) {
  336. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article as art `
  337. if condition != "" {
  338. sqlCount += condition
  339. }
  340. o := orm.NewOrmUsingDB("hz_cygx")
  341. err = o.Raw(sqlCount, pars).QueryRow(&count)
  342. return
  343. }
  344. // body 解析
  345. func BodyAnalysis(body string) (expertNumStr, expertContentStr, interviewDateStr, fileLink string) {
  346. body = html.UnescapeString(body)
  347. doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
  348. if err != nil {
  349. fmt.Println("create doc err:", err.Error())
  350. return
  351. }
  352. var expertNumArr []string
  353. var expertContentArr []string
  354. var interviewDateArr []string
  355. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  356. contentTxt := s.Text()
  357. if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
  358. interviewDate := s.Next().Text()
  359. interviewDateArr = append(interviewDateArr, interviewDate)
  360. }
  361. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  362. expertContent := s.Next().Text()
  363. //Powered 是编辑器传过来的字段
  364. if expertContent == "" || strings.Contains(expertContent, "Powered") {
  365. expertContent = contentTxt
  366. }
  367. //如果内容中最前的文字是 "专家" 这个词,则认为这句话是专家背景
  368. if !strings.Contains(expertContent, "专家评价") && strings.Contains(expertContent, "专家") && strings.Index(expertContent, "专家") == 0 {
  369. expertContentArr = append(expertContentArr, expertContent)
  370. }
  371. if expertContent != "" {
  372. rightIndex := strings.Index(expertContent, ")")
  373. if rightIndex == 0 {
  374. rightIndex = strings.Index(expertContent, ")")
  375. }
  376. if rightIndex > 0 {
  377. expertNum := expertContent[:rightIndex]
  378. expertNum = strings.Replace(expertNum, "(", "", -1)
  379. expertNum = strings.Replace(expertNum, "(", "", -1)
  380. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  381. if expertNum != "" {
  382. expertNumArr = append(expertNumArr, expertNum)
  383. rightIndex = rightIndex
  384. expertContentStr := expertContent[rightIndex:]
  385. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  386. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  387. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  388. expertContentArr = append(expertContentArr, expertContentStr)
  389. }
  390. }
  391. if !strings.Contains(contentTxt, "(") || !strings.Contains(contentTxt, "(") {
  392. expertContentArr = append(expertContentArr, expertContent)
  393. }
  394. }
  395. }
  396. })
  397. if len(expertContentArr) == 0 {
  398. doc.Find("pre").Each(func(i int, s *goquery.Selection) {
  399. contentTxt := s.Text()
  400. if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
  401. interviewDate := s.Next().Text()
  402. numStar := strings.Index(contentTxt, " #访谈时间:")
  403. numEnd := strings.Index(contentTxt, " #纪要详情:")
  404. interviewDate = contentTxt[numStar+19 : numEnd]
  405. if interviewDate != "" {
  406. interviewDateArr = append(interviewDateArr, interviewDate)
  407. }
  408. }
  409. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  410. expertContent := s.Next().Text()
  411. if expertContent == "" {
  412. expertContent = contentTxt
  413. }
  414. if expertContent != "" {
  415. expertIsHave := strings.Index(expertContent, "专家评价")
  416. if expertIsHave > 0 {
  417. expertContent = expertContent[expertIsHave:]
  418. rightIndex := strings.Index(expertContent, ")")
  419. if rightIndex == 0 {
  420. rightIndex = strings.Index(expertContent, ")")
  421. }
  422. if rightIndex > 0 {
  423. expertNum := expertContent[:rightIndex]
  424. expertNum = strings.Replace(expertNum, "(", "", -1)
  425. expertNum = strings.Replace(expertNum, "(", "", -1)
  426. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  427. expertNum = strings.Replace(expertNum, ":", "", -1)
  428. expertNum = strings.Replace(expertNum, ":", "", -1)
  429. if expertNum != "" {
  430. expertNumArr = append(expertNumArr, expertNum)
  431. rightIndex = rightIndex
  432. expertContentStr := expertContent[rightIndex:]
  433. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  434. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  435. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  436. if expertContentStr != "" {
  437. expertContentArr = append(expertContentArr, expertContentStr)
  438. }
  439. }
  440. }
  441. }
  442. if !strings.Contains(contentTxt, "(") || !strings.Contains(contentTxt, "(") {
  443. expertContentArr = append(expertContentArr, expertContent)
  444. }
  445. }
  446. }
  447. })
  448. }
  449. if len(expertNumArr) > 0 {
  450. expertNumStr = expertNumArr[0]
  451. if expertNumStr != "" {
  452. expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
  453. expertNumStr = strings.Replace(expertNumStr, "# ", "", -1)
  454. expertNumStr = strings.Trim(expertNumStr, "")
  455. }
  456. }
  457. if len(expertContentArr) > 0 {
  458. expertContentStr = expertContentArr[0]
  459. }
  460. if len(expertContentStr) > 600 {
  461. strnum := strings.Index(expertContentStr, "#专家评价:")
  462. content := expertContentStr[strnum:]
  463. strnum2 := strings.Index(content, "(")
  464. content = content[strnum2+9:] //中文括号3位 专家编号6位
  465. expertContentStr = content
  466. }
  467. if len(interviewDateArr) > 0 {
  468. interviewDateStr = interviewDateArr[0]
  469. }
  470. return
  471. }
  472. // 列表
  473. func GetCygxArticleCollectionList(articleId int) (items []*CygxDepartmentFllowList, err error) {
  474. o := orm.NewOrmUsingDB("hz_cygx")
  475. sql := `SELECT
  476. f.*
  477. FROM
  478. cygx_article_collect AS f
  479. WHERE
  480. f.article_id = ?
  481. GROUP BY f.id`
  482. _, err = o.Raw(sql, articleId).QueryRows(&items)
  483. return
  484. }
  485. type ArticleHistoryRep struct {
  486. ArticleId int `description:"文章ID"`
  487. RealName string `description:"姓名"`
  488. Mobile string `description:"手机号"`
  489. CompanyName string `description:"公司名称"`
  490. SellerName string `description:"所属销售"`
  491. StopTime string `description:"阅读停留时间"`
  492. CreateTime string `description:"创建时间"`
  493. }
  494. // 列表
  495. func GetArticleHistoryList(articleId int, condition string) (items []*ArticleHistoryRep, err error) {
  496. o := orm.NewOrmUsingDB("hz_cygx")
  497. sql := `SELECT
  498. h.*
  499. FROM
  500. cygx_article_history_record_all AS h
  501. WHERE
  502. h.article_id = ?
  503. AND h.platfor = 1 AND h.is_del = 0 `
  504. if condition != "" {
  505. sql = sql + condition + ` GROUP BY h.id`
  506. }
  507. _, err = o.Raw(sql, articleId).QueryRows(&items)
  508. return
  509. }
  510. // 用户阅读记录,不过滤弘则内部的
  511. func GetArticleHistoryListOld(articleId int, condition string) (items []*ArticleHistoryRep, err error) {
  512. o := orm.NewOrmUsingDB("hz_cygx")
  513. sql := `SELECT
  514. h.*
  515. FROM
  516. cygx_article_history_record AS h
  517. WHERE
  518. h.article_id = ?
  519. AND c.product_id = 2`
  520. if condition != "" {
  521. sql = sql + condition + ` GROUP BY h.id`
  522. }
  523. _, err = o.Raw(sql, articleId).QueryRows(&items)
  524. return
  525. }
  526. // 列表
  527. func GetSellerUserMobileList(condition string) (items []*ArticleHistoryRep, err error) {
  528. o := orm.NewOrm()
  529. sql := `SELECT mobile FROM wx_user as h WHERE h.mobile != '' ` + condition
  530. _, err = o.Raw(sql).QueryRows(&items)
  531. return
  532. }
  533. type ArticleTypeAndAbstract struct {
  534. Abstract string
  535. ArticleTypeId int
  536. }
  537. func GetArticleTypeAndAbstract() (list []*ArticleTypeAndAbstract, err error) {
  538. o := orm.NewOrmUsingDB("hz_cygx")
  539. sql := `SELECT
  540. *
  541. FROM
  542. ( SELECT abstract, article_type_id FROM cygx_article GROUP BY publish_date DESC ) AS a
  543. GROUP BY
  544. a.article_type_id `
  545. _, err = o.Raw(sql).QueryRows(&list)
  546. return
  547. }
  548. // 更新文章置顶时间
  549. func UpdateArticleTopTime(activityId, topTime int) (err error) {
  550. o := orm.NewOrmUsingDB("hz_cygx")
  551. sql := ` UPDATE cygx_article SET top_time=? WHERE article_id=?`
  552. _, err = o.Raw(sql, topTime, activityId).Exec()
  553. return
  554. }
  555. // 添加朋友圈分享封面图片
  556. func UpdateCygxArticleMomentsImg(momentsImg string, articleId int) (err error) {
  557. sql := `UPDATE cygx_article SET moments_img=? WHERE article_id=? `
  558. o := orm.NewOrmUsingDB("hz_cygx")
  559. _, err = o.Raw(sql, momentsImg, articleId).Exec()
  560. return
  561. }