summary_manage.go 25 KB

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