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