summary_manage.go 25 KB

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