summary_manage.go 25 KB

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