summary_manage.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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. SubjectIds string `description:"报告所关联的标的"`
  129. AdminId int `description:"销售/管理员ID"`
  130. AdminName string `description:"销售/管理员姓名"`
  131. Annotation string `description:"核心观点"`
  132. VisibleRange int `description:"设置可见范围1全部,0内部"`
  133. TopTime int `description:"置顶时间"`
  134. }
  135. type GetSummaryManageListRep struct {
  136. Paging *paging.PagingItem `description:"分页数据"`
  137. List []*CygxArticleList
  138. }
  139. type ElasticTestArticleDetail struct {
  140. ArticleId int `description:"报告id"`
  141. Title string `description:"标题"`
  142. BodyText string `description:"内容"`
  143. PublishDate string `description:"发布时间"`
  144. ExpertBackground string `description:"专家背景"`
  145. CategoryId string `description:"文章分类"`
  146. Abstract string `description:"摘要"`
  147. Annotation string `description:"核心观点"`
  148. }
  149. // 添加文章
  150. func AddArticle(item *CygxArticle) (newId int64, err error) {
  151. o := orm.NewOrmUsingDB("hz_cygx")
  152. newId, err = o.Insert(item)
  153. fmt.Println(newId)
  154. return
  155. }
  156. //item.ExpertBackground = expertContentStr
  157. //item.ExpertNumber = expertNumStr
  158. //item.InterviewDate = interviewDateStr
  159. //item.FileLink = fileLink
  160. // 修改文章
  161. func EditArticle(item *CygxArticle, oldPublishStatus int) (err error) {
  162. o := orm.NewOrmUsingDB("hz_cygx")
  163. if oldPublishStatus == 1 {
  164. 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`
  165. _, 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()
  166. } else {
  167. if item.PublishStatus == 1 {
  168. 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`
  169. _, 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()
  170. } else {
  171. 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`
  172. _, 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()
  173. }
  174. }
  175. return
  176. }
  177. func GetMaxArticleIdInfo() (item *ArticleDetail, err error) {
  178. o := orm.NewOrmUsingDB("hz_cygx")
  179. sql := `SELECT * FROM cygx_article ORDER BY article_id desc LIMIT 1`
  180. err = o.Raw(sql).QueryRow(&item)
  181. return
  182. }
  183. // 通过纪要ID获取文章详情
  184. func GetArticleIdInfoBySummaryManageId(summaryManageId int) (item *CygxArticleResp, err error) {
  185. o := orm.NewOrmUsingDB("hz_cygx")
  186. sql := `SELECT art.* ,dm.nick_name FROM cygx_article as art
  187. LEFT JOIN cygx_article_department as dm ON dm.department_id = art.department_id WHERE id=? AND source = 1`
  188. err = o.Raw(sql, summaryManageId).QueryRow(&item)
  189. return
  190. }
  191. // 通过文章ID获取文章、以及所关联的标的详情
  192. func GetArticleInfoOtherByArticleId(articleId int) (item *CygxArticleResp, err error) {
  193. o := orm.NewOrmUsingDB("hz_cygx")
  194. sql := `SELECT art.* ,dm.nick_name FROM cygx_article as art
  195. LEFT JOIN cygx_article_department as dm ON dm.department_id = art.department_id WHERE article_id=? `
  196. err = o.Raw(sql, articleId).QueryRow(&item)
  197. return
  198. }
  199. // 通过纪要ID获取文章详情
  200. func GetArticleIdInfoByArticleId(articleId int) (item *CygxArticle, err error) {
  201. o := orm.NewOrmUsingDB("hz_cygx")
  202. sql := `SELECT * FROM cygx_article WHERE article_id= ?`
  203. err = o.Raw(sql, articleId).QueryRow(&item)
  204. return
  205. }
  206. func GetReportContentTextSub(content string) (contentSub string, err error) {
  207. content = html.UnescapeString(content)
  208. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  209. docText := doc.Text()
  210. bodyRune := []rune(docText)
  211. bodyRuneLen := len(bodyRune)
  212. if bodyRuneLen > 200 {
  213. bodyRuneLen = 200
  214. }
  215. body := string(bodyRune[:bodyRuneLen])
  216. contentSub = body
  217. return
  218. }
  219. // 修改发布状态
  220. func PublishAndCancel(item *CygxArticle) (err error) {
  221. sql := `UPDATE cygx_article SET publish_status=? ,admin_id =? ,admin_name =? WHERE article_id=? `
  222. o := orm.NewOrmUsingDB("hz_cygx")
  223. _, err = o.Raw(sql, item.PublishStatus, item.AdminId, item.AdminName, item.ArticleId).Exec()
  224. return
  225. }
  226. // 修改发布状态
  227. func ArticleVisibleRange(item *CygxArticle) (err error) {
  228. sql := `UPDATE cygx_article SET visible_range=? ,admin_id =? ,admin_name =? WHERE article_id=? `
  229. o := orm.NewOrmUsingDB("hz_cygx")
  230. _, err = o.Raw(sql, item.VisibleRange, item.AdminId, item.AdminName, item.ArticleId).Exec()
  231. return
  232. }
  233. // 修改发布状态
  234. func UpdateIsClassFail(item *CygxArticleResp) (err error) {
  235. sql := `UPDATE cygx_article SET is_class_fail=0 WHERE article_id=? `
  236. o := orm.NewOrmUsingDB("hz_cygx")
  237. _, err = o.Raw(sql, item.ArticleId).Exec()
  238. return
  239. }
  240. // 通过纪要ID获取文章详情
  241. func GetArticleIdInfoBySummaryManageIdEdit(summaryManageId int) (item *CygxArticle, err error) {
  242. o := orm.NewOrmUsingDB("hz_cygx")
  243. sql := `SELECT * FROM cygx_article WHERE id=? AND source = 1`
  244. err = o.Raw(sql, summaryManageId).QueryRow(&item)
  245. return
  246. }
  247. // 删除数据
  248. func DeleteSummaryManage(summaryManageId int) (err error) {
  249. o := orm.NewOrmUsingDB("hz_cygx")
  250. sql := ` DELETE FROM cygx_article WHERE id=? AND source = 1`
  251. _, err = o.Raw(sql, summaryManageId).Exec()
  252. return
  253. }
  254. type CygxArticleList struct {
  255. ArticleId int `description:"报告id"`
  256. CategoryName string `description:"行业分类名称"`
  257. Title string `description:"标题"`
  258. Abstract string `description:"摘要"`
  259. Body string `description:"内容"`
  260. PublishStatus int `description:"发布状态,0未发布 ,1已发布"`
  261. PublishDate string `description:"发布时间"`
  262. LastUpdatedTime string `description:"更新时间"`
  263. ArticleIdMd5 string `description:"ID,md5值"`
  264. Pv int `description:"PV"`
  265. Uv int `description:"UV"`
  266. CommentNum int `description:"留言总数"`
  267. CollectionNum int `description:"收藏"`
  268. NickName string `description:"作者昵称"`
  269. DepartmentId int `description:"作者ID"`
  270. IndustryName string `description:"产业名称"`
  271. SubjectName string `description:"标的名称"`
  272. ArticleTypeId int `description:"文章类型ID"`
  273. ArticleTypeName string `description:"文章类型名称"`
  274. VisibleRange int `description:"设置可见范围1全部,0内部"`
  275. TopTime int `description:"置顶时间"`
  276. }
  277. // 列表
  278. func GetSummaryManageList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxArticleList, err error) {
  279. o := orm.NewOrmUsingDB("hz_cygx")
  280. sql := ` SELECT
  281. (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,
  282. (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,
  283. (SELECT COUNT(1) FROM cygx_article_comment AS k WHERE k.article_id=art.article_id) AS comment_num,
  284. (SELECT COUNT(1) FROM cygx_article_collect AS c WHERE c.article_id = art.article_id ) AS collection_num,
  285. (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 ,
  286. 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
  287. FROM cygx_article as art
  288. LEFT JOIN cygx_article_department as dm ON dm.department_id = art.department_id
  289. LEFT JOIN cygx_industrial_article_group_management as mg ON mg.article_id = art.article_id
  290. LEFT JOIN cygx_industrial_management as m ON m.industrial_management_id = mg.industrial_management_id`
  291. if condition != "" {
  292. sql += condition
  293. }
  294. sql += ` LIMIT ?,?`
  295. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  296. return
  297. }
  298. // 列表
  299. func GetCygxArticleList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxReportArticle, err error) {
  300. o := orm.NewOrmUsingDB("hz_cygx")
  301. sql := ` SELECT *
  302. FROM cygx_article as art WHERE 1 =1 `
  303. if condition != "" {
  304. sql += condition
  305. } else {
  306. return
  307. }
  308. sql += ` LIMIT ?,?`
  309. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  310. return
  311. }
  312. type CygxArticleSubjectList struct {
  313. ArticleId int `description:"报告id"`
  314. SubjectName string `description:"标的名称"`
  315. }
  316. // 文章标的列表
  317. func GetArticleSubjectList(articleId string) (items []*CygxArticleSubjectList, err error) {
  318. if articleId == "" {
  319. articleId = "0"
  320. }
  321. o := orm.NewOrmUsingDB("hz_cygx")
  322. sql := ` SELECT GROUP_CONCAT( DISTINCT s.subject_name SEPARATOR '/' ) AS subject_name,
  323. sg.article_id
  324. FROM
  325. cygx_industrial_article_group_subject AS sg
  326. LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = sg.industrial_subject_id
  327. WHERE
  328. sg.article_id IN (` + articleId + `)
  329. GROUP BY sg.article_id`
  330. _, err = o.Raw(sql).QueryRows(&items)
  331. return
  332. }
  333. // 获取文章数量
  334. func GetASummaryManageCount(condition string, pars []interface{}) (count int, err error) {
  335. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_article as art `
  336. if condition != "" {
  337. sqlCount += condition
  338. }
  339. o := orm.NewOrmUsingDB("hz_cygx")
  340. err = o.Raw(sqlCount, pars).QueryRow(&count)
  341. return
  342. }
  343. // body 解析
  344. func BodyAnalysis(body string) (expertNumStr, expertContentStr, interviewDateStr, fileLink string) {
  345. body = html.UnescapeString(body)
  346. doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
  347. if err != nil {
  348. fmt.Println("create doc err:", err.Error())
  349. return
  350. }
  351. var expertNumArr []string
  352. var expertContentArr []string
  353. var interviewDateArr []string
  354. doc.Find("p").Each(func(i int, s *goquery.Selection) {
  355. contentTxt := s.Text()
  356. if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
  357. interviewDate := s.Next().Text()
  358. interviewDateArr = append(interviewDateArr, interviewDate)
  359. }
  360. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  361. expertContent := s.Next().Text()
  362. //Powered 是编辑器传过来的字段
  363. if expertContent == "" || strings.Contains(expertContent, "Powered") {
  364. expertContent = contentTxt
  365. }
  366. //如果内容中最前的文字是 "专家" 这个词,则认为这句话是专家背景
  367. if !strings.Contains(expertContent, "专家评价") && strings.Contains(expertContent, "专家") && strings.Index(expertContent, "专家") == 0 {
  368. expertContentArr = append(expertContentArr, expertContent)
  369. }
  370. if expertContent != "" {
  371. rightIndex := strings.Index(expertContent, ")")
  372. if rightIndex == 0 {
  373. rightIndex = strings.Index(expertContent, ")")
  374. }
  375. if rightIndex > 0 {
  376. expertNum := expertContent[:rightIndex]
  377. expertNum = strings.Replace(expertNum, "(", "", -1)
  378. expertNum = strings.Replace(expertNum, "(", "", -1)
  379. expertNum = strings.Replace(expertNum, "专家评价", "", -1)
  380. if expertNum != "" {
  381. expertNumArr = append(expertNumArr, expertNum)
  382. rightIndex = rightIndex
  383. expertContentStr := expertContent[rightIndex:]
  384. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  385. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  386. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  387. expertContentArr = append(expertContentArr, expertContentStr)
  388. }
  389. }
  390. if !strings.Contains(contentTxt, "(") || !strings.Contains(contentTxt, "(") {
  391. expertContentArr = append(expertContentArr, expertContent)
  392. }
  393. }
  394. }
  395. })
  396. if len(expertContentArr) == 0 {
  397. doc.Find("pre").Each(func(i int, s *goquery.Selection) {
  398. contentTxt := s.Text()
  399. if strings.Contains(contentTxt, "#访谈时间:") || strings.Contains(contentTxt, "访谈时间:") {
  400. interviewDate := s.Next().Text()
  401. numStar := strings.Index(contentTxt, " #访谈时间:")
  402. numEnd := strings.Index(contentTxt, " #纪要详情:")
  403. interviewDate = contentTxt[numStar+19 : numEnd]
  404. if interviewDate != "" {
  405. interviewDateArr = append(interviewDateArr, interviewDate)
  406. }
  407. }
  408. if strings.Contains(contentTxt, "#专家评价") || strings.Contains(contentTxt, "专家评价") {
  409. expertContent := s.Next().Text()
  410. if expertContent == "" {
  411. expertContent = contentTxt
  412. }
  413. if expertContent != "" {
  414. expertIsHave := strings.Index(expertContent, "专家评价")
  415. if expertIsHave > 0 {
  416. expertContent = expertContent[expertIsHave:]
  417. rightIndex := strings.Index(expertContent, ")")
  418. if rightIndex == 0 {
  419. rightIndex = strings.Index(expertContent, ")")
  420. }
  421. if rightIndex > 0 {
  422. expertNum := expertContent[:rightIndex]
  423. expertNum = strings.Replace(expertNum, "(", "", -1)
  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. if expertNum != "" {
  429. expertNumArr = append(expertNumArr, expertNum)
  430. rightIndex = rightIndex
  431. expertContentStr := expertContent[rightIndex:]
  432. expertContentStr = strings.Replace(expertContentStr, ")", "", -1)
  433. expertContentStr = strings.TrimLeft(expertContentStr, ":")
  434. expertContentStr = strings.TrimRight(expertContentStr, "(推荐")
  435. if expertContentStr != "" {
  436. expertContentArr = append(expertContentArr, expertContentStr)
  437. }
  438. }
  439. }
  440. }
  441. if !strings.Contains(contentTxt, "(") || !strings.Contains(contentTxt, "(") {
  442. expertContentArr = append(expertContentArr, expertContent)
  443. }
  444. }
  445. }
  446. })
  447. }
  448. if len(expertNumArr) > 0 {
  449. expertNumStr = expertNumArr[0]
  450. if expertNumStr != "" {
  451. expertNumStr = strings.Replace(expertNumStr, "#:", "", -1)
  452. expertNumStr = strings.Replace(expertNumStr, "# ", "", -1)
  453. expertNumStr = strings.Trim(expertNumStr, "")
  454. }
  455. }
  456. if len(expertContentArr) > 0 {
  457. expertContentStr = expertContentArr[0]
  458. }
  459. if len(expertContentStr) > 600 {
  460. strnum := strings.Index(expertContentStr, "#专家评价:")
  461. content := expertContentStr[strnum:]
  462. strnum2 := strings.Index(content, "(")
  463. content = content[strnum2+9:] //中文括号3位 专家编号6位
  464. expertContentStr = content
  465. }
  466. if len(interviewDateArr) > 0 {
  467. interviewDateStr = interviewDateArr[0]
  468. }
  469. return
  470. }
  471. // 列表
  472. func GetCygxArticleCollectionList(articleId int) (items []*CygxDepartmentFllowList, err error) {
  473. o := orm.NewOrmUsingDB("hz_cygx")
  474. sql := `SELECT
  475. f.*
  476. FROM
  477. cygx_article_collect AS f
  478. WHERE
  479. f.article_id = ?
  480. GROUP BY f.id`
  481. _, err = o.Raw(sql, articleId).QueryRows(&items)
  482. return
  483. }
  484. type ArticleHistoryRep struct {
  485. ArticleId int `description:"文章ID"`
  486. RealName string `description:"姓名"`
  487. Mobile string `description:"手机号"`
  488. CompanyName string `description:"公司名称"`
  489. SellerName string `description:"所属销售"`
  490. StopTime string `description:"阅读停留时间"`
  491. CreateTime string `description:"创建时间"`
  492. }
  493. // 列表
  494. func GetArticleHistoryList(articleId int, condition string) (items []*ArticleHistoryRep, err error) {
  495. o := orm.NewOrmUsingDB("hz_cygx")
  496. sql := `SELECT
  497. h.*
  498. FROM
  499. cygx_article_history_record_all AS h
  500. WHERE
  501. h.article_id = ?
  502. AND h.platfor = 1 AND h.is_del = 0 `
  503. if condition != "" {
  504. sql = sql + condition + ` GROUP BY h.id`
  505. }
  506. _, err = o.Raw(sql, articleId).QueryRows(&items)
  507. return
  508. }
  509. // 用户阅读记录,不过滤弘则内部的
  510. func GetArticleHistoryListOld(articleId int, condition string) (items []*ArticleHistoryRep, err error) {
  511. o := orm.NewOrmUsingDB("hz_cygx")
  512. sql := `SELECT
  513. h.*
  514. FROM
  515. cygx_article_history_record AS h
  516. WHERE
  517. h.article_id = ?
  518. AND c.product_id = 2`
  519. if condition != "" {
  520. sql = sql + condition + ` GROUP BY h.id`
  521. }
  522. _, err = o.Raw(sql, articleId).QueryRows(&items)
  523. return
  524. }
  525. // 列表
  526. func GetSellerUserMobileList(condition string) (items []*ArticleHistoryRep, err error) {
  527. o := orm.NewOrm()
  528. sql := `SELECT mobile FROM wx_user as h WHERE h.mobile != '' ` + condition
  529. _, err = o.Raw(sql).QueryRows(&items)
  530. return
  531. }
  532. type ArticleTypeAndAbstract struct {
  533. Abstract string
  534. ArticleTypeId int
  535. }
  536. func GetArticleTypeAndAbstract() (list []*ArticleTypeAndAbstract, err error) {
  537. o := orm.NewOrmUsingDB("hz_cygx")
  538. sql := `SELECT
  539. *
  540. FROM
  541. ( SELECT abstract, article_type_id FROM cygx_article GROUP BY publish_date DESC ) AS a
  542. GROUP BY
  543. a.article_type_id `
  544. _, err = o.Raw(sql).QueryRows(&list)
  545. return
  546. }
  547. // 更新文章置顶时间
  548. func UpdateArticleTopTime(activityId, topTime int) (err error) {
  549. o := orm.NewOrmUsingDB("hz_cygx")
  550. sql := ` UPDATE cygx_article SET top_time=? WHERE article_id=?`
  551. _, err = o.Raw(sql, topTime, activityId).Exec()
  552. return
  553. }