article.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "html"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. type ArticleController struct {
  14. BaseAuthController
  15. }
  16. type ArticleCommonController struct {
  17. BaseCommonController
  18. }
  19. // @Title 获取报告详情
  20. // @Description 获取报告详情接口
  21. // @Param ArticleId query int true "报告ID"
  22. // @Success 200 {object} models.ArticleDetailResp
  23. // @router /detail [get]
  24. func (this *ArticleController) Detail() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. user := this.User
  31. if user == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,用户信息为空"
  34. br.Ret = 408
  35. return
  36. }
  37. uid := user.UserId
  38. articleId, err := this.GetInt("ArticleId")
  39. if articleId <= 0 {
  40. br.Msg = "参数错误"
  41. br.ErrMsg = "参数错误"
  42. return
  43. }
  44. detail := new(models.ArticleDetail)
  45. hasPermission := 0
  46. hasFree := 0
  47. //判断是否已经申请过
  48. applyCount, err := models.GetApplyRecordCount(uid)
  49. if err != nil && err.Error() != utils.ErrNoRow() {
  50. br.Msg = "获取信息失败"
  51. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  52. return
  53. }
  54. fmt.Println(user.CompanyId)
  55. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  56. if user.CompanyId > 1 {
  57. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  58. if err != nil {
  59. br.Msg = "获取信息失败"
  60. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  61. return
  62. }
  63. detail, err = models.GetArticleDetailById(articleId)
  64. if err != nil {
  65. br.Msg = "获取信息失败"
  66. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  67. return
  68. }
  69. fmt.Println(detail.Department)
  70. detail.Body = html.UnescapeString(detail.Body)
  71. detail.Abstract = html.UnescapeString(detail.Abstract)
  72. fmt.Println(companyPermission)
  73. if companyPermission == "" {
  74. if applyCount > 0 {
  75. hasPermission = 5
  76. } else {
  77. hasPermission = 2
  78. }
  79. hasFree = 2
  80. goto Loop
  81. } else {
  82. hasFree = 1
  83. // 原有的权限校验 更改于 2021-05-18
  84. //articlePermission, err := models.GetArticlePermission(detail.SubCategoryName)
  85. //fmt.Println(articlePermission)
  86. //fmt.Println(detail.SubCategoryName)
  87. //if err != nil {
  88. // br.Msg = "获取信息失败"
  89. // br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  90. // return
  91. //}
  92. //if articlePermission == nil {
  93. // br.Msg = "获取信息失败"
  94. // br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  95. // return
  96. //}
  97. //for _, p := range articlePermission {
  98. // if strings.Contains(companyPermission, p.PermissionName) {
  99. // hasPermission = 1
  100. // historyRecord := new(models.CygxArticleHistoryRecord)
  101. // historyRecord.UserId = uid
  102. // historyRecord.ArticleId = articleId
  103. // historyRecord.CreateTime = time.Now()
  104. // historyRecord.Mobile = user.Mobile
  105. // historyRecord.Email = user.Email
  106. // historyRecord.CompanyId = user.CompanyId
  107. // historyRecord.CompanyName = user.CompanyName
  108. // go models.AddCygxArticleHistoryRecord(historyRecord)
  109. // break
  110. // } else { //无该行业权限
  111. // hasPermission = 3
  112. // }
  113. //}
  114. articlePermission, err := models.GetArticlePermission(detail.SubCategoryName)
  115. fmt.Println(articlePermission)
  116. fmt.Println(detail.SubCategoryName)
  117. if err != nil {
  118. br.Msg = "获取信息失败"
  119. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  120. return
  121. }
  122. if articlePermission == nil {
  123. br.Msg = "获取信息失败"
  124. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  125. return
  126. }
  127. for _, p := range articlePermission {
  128. if strings.Contains(companyPermission, p.PermissionName) {
  129. hasPermission = 1
  130. historyRecord := new(models.CygxArticleHistoryRecord)
  131. historyRecord.UserId = uid
  132. historyRecord.ArticleId = articleId
  133. historyRecord.CreateTime = time.Now()
  134. historyRecord.Mobile = user.Mobile
  135. historyRecord.Email = user.Email
  136. historyRecord.CompanyId = user.CompanyId
  137. historyRecord.CompanyName = user.CompanyName
  138. go models.AddCygxArticleHistoryRecord(historyRecord)
  139. break
  140. } else { //无该行业权限
  141. hasPermission = 3
  142. }
  143. }
  144. if hasPermission == 1 {
  145. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  146. if !utils.Rc.IsExist(key) {
  147. //新增浏览记录
  148. record := new(models.CygxArticleViewRecord)
  149. record.UserId = uid
  150. record.ArticleId = articleId
  151. record.CreateTime = time.Now()
  152. record.Mobile = user.Mobile
  153. record.Email = user.Email
  154. record.CompanyId = user.CompanyId
  155. record.CompanyName = user.CompanyName
  156. go models.AddCygxArticleViewRecord(record)
  157. utils.Rc.Put(key, 1, 5*time.Second)
  158. models.ModifyReportLastViewTime(uid)
  159. }
  160. }
  161. }
  162. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  163. if err != nil && err.Error() != utils.ErrNoRow() {
  164. br.Msg = "获取信息失败"
  165. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  166. return
  167. }
  168. if collectCount > 0 {
  169. detail.IsCollect = true
  170. }
  171. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  172. if err != nil && err.Error() != utils.ErrNoRow() {
  173. br.Msg = "获取信息失败"
  174. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  175. return
  176. }
  177. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  178. detail.IsInterviewApply = true
  179. detail.InterviewApplyStatus = interviewApplyItem.Status
  180. }
  181. //获取销售手机号
  182. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  183. if err != nil {
  184. br.Msg = "获取信息失败"
  185. br.ErrMsg = "获取销售数据失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  186. return
  187. }
  188. if sellerItem != nil {
  189. detail.SellerMobile = sellerItem.Mobile
  190. detail.SellerName = sellerItem.RealName
  191. }
  192. sellerList, err := models.GetSellerList(articleId)
  193. if err != nil {
  194. br.Msg = "获取信息失败"
  195. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  196. return
  197. }
  198. detail.SellerList = sellerList
  199. } else { //潜在客户
  200. if applyCount > 0 {
  201. hasPermission = 5
  202. } else {
  203. hasPermission = 4
  204. }
  205. }
  206. Loop:
  207. if hasPermission != 1 {
  208. detail.Body = ""
  209. detail.BodyText = ""
  210. }
  211. resp := new(models.ArticleDetailResp)
  212. resp.HasPermission = hasPermission
  213. resp.HasFree = hasFree
  214. resp.Detail = detail
  215. br.Ret = 200
  216. br.Success = true
  217. br.Msg = "获取成功"
  218. br.Data = resp
  219. }
  220. // @Title 收藏
  221. // @Description 收藏
  222. // @Param request body models.ArticleCollectReq true "type json string"
  223. // @Success 200 {object} models.FontsCollectResp
  224. // @router /collect [post]
  225. func (this *ArticleController) ArticleCollect() {
  226. br := new(models.BaseResponse).Init()
  227. defer func() {
  228. this.Data["json"] = br
  229. this.ServeJSON()
  230. }()
  231. user := this.User
  232. if user == nil {
  233. br.Msg = "请重新登录"
  234. br.Ret = 408
  235. return
  236. }
  237. uid := user.UserId
  238. var req models.ArticleCollectReq
  239. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  240. if err != nil {
  241. br.Msg = "参数解析异常!"
  242. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  243. return
  244. }
  245. count, err := models.GetArticleCollectCount(uid, req.ArticleId)
  246. if err != nil {
  247. br.Msg = "获取数据失败!"
  248. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  249. return
  250. }
  251. resp := new(models.ArticleCollectResp)
  252. if count <= 0 {
  253. item := new(models.CygxArticleCollect)
  254. item.ArticleId = req.ArticleId
  255. item.UserId = uid
  256. item.CreateTime = time.Now()
  257. _, err = models.AddCygxArticleCollect(item)
  258. if err != nil {
  259. br.Msg = "收藏失败"
  260. br.ErrMsg = "收藏失败,Err:" + err.Error()
  261. return
  262. }
  263. br.Msg = "收藏成功"
  264. resp.Status = 1
  265. } else {
  266. err = models.RemoveArticleCollect(uid, req.ArticleId)
  267. if err != nil {
  268. br.Msg = "取消收藏失败"
  269. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  270. return
  271. }
  272. br.Msg = "已取消收藏"
  273. resp.Status = 2
  274. }
  275. collectTotal, err := models.GetArticleCollectUsersCount(req.ArticleId)
  276. if err != nil {
  277. br.Msg = "获取数据失败"
  278. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  279. return
  280. }
  281. resp.CollectCount = collectTotal
  282. br.Ret = 200
  283. br.Success = true
  284. br.Data = resp
  285. }
  286. // @Title 访谈申请
  287. // @Description 访谈申请
  288. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  289. // @Success 200 {object} models.FontsCollectResp
  290. // @router /interview/apply [post]
  291. func (this *ArticleController) InterviewApply() {
  292. br := new(models.BaseResponse).Init()
  293. defer func() {
  294. this.Data["json"] = br
  295. this.ServeJSON()
  296. }()
  297. user := this.User
  298. if user == nil {
  299. br.Msg = "请重新登录"
  300. br.Ret = 408
  301. return
  302. }
  303. uid := user.UserId
  304. var req models.ArticleInterviewApplyReq
  305. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  306. if err != nil {
  307. br.Msg = "参数解析异常!"
  308. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  309. return
  310. }
  311. article, err := models.GetArticleDetailById(req.ArticleId)
  312. if err != nil {
  313. br.Msg = "获取纪要失败!"
  314. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  315. return
  316. }
  317. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  318. if err != nil {
  319. br.Msg = "获取数据失败!"
  320. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  321. return
  322. }
  323. resp := new(models.ArticleInterviewApplyResp)
  324. if count <= 0 {
  325. item := new(models.CygxInterviewApply)
  326. item.ArticleId = req.ArticleId
  327. item.UserId = uid
  328. item.CompanyId = user.CompanyId
  329. item.Status = "待邀请"
  330. item.Sort = 1
  331. item.ArticleTitle = article.Title
  332. item.CreateTime = time.Now()
  333. item.ModifyTime = time.Now()
  334. item.ArticleIdMd5 = article.ArticleIdMd5
  335. _, err = models.AddCygxInterviewApply(item)
  336. if err != nil {
  337. br.Msg = "申请失败"
  338. br.ErrMsg = "申请失败,Err:" + err.Error()
  339. return
  340. }
  341. br.Msg = "申请成功"
  342. resp.Status = 1
  343. //发送模板消息
  344. if user.CompanyId > 1 {
  345. mobile := user.Mobile
  346. if mobile == "" {
  347. mobile = user.Email
  348. }
  349. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  350. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  351. openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1)
  352. if openIpItem != nil && openIpItem.OpenId != "" {
  353. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  354. }
  355. }
  356. }
  357. } else {
  358. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  359. if err != nil {
  360. br.Msg = "取消申请失败"
  361. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  362. return
  363. }
  364. br.Msg = "已取消申请"
  365. resp.Status = 2
  366. if user.CompanyId > 1 {
  367. mobile := user.Mobile
  368. if mobile == "" {
  369. mobile = user.Email
  370. }
  371. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  372. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  373. openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1)
  374. if openIpItem != nil && openIpItem.OpenId != "" {
  375. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  376. }
  377. }
  378. }
  379. }
  380. br.Ret = 200
  381. br.Success = true
  382. br.Data = resp
  383. }
  384. // @Title 获取报告详情
  385. // @Description 获取报告详情接口
  386. // @Param ArticleIdMd5 query int true "报告ID"
  387. // @Success 200 {object} models.ArticleDetailResp
  388. // @router /look/detail [get]
  389. func (this *ArticleCommonController) Detail() {
  390. br := new(models.BaseResponse).Init()
  391. defer func() {
  392. this.Data["json"] = br
  393. this.ServeJSON()
  394. }()
  395. articleIdMd5 := this.GetString("ArticleIdMd5")
  396. if articleIdMd5 == "" {
  397. br.Msg = "参数错误"
  398. br.ErrMsg = "参数错误"
  399. return
  400. }
  401. resp := new(models.ArticleDetailResp)
  402. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  403. if err != nil && err.Error() != utils.ErrNoRow() {
  404. br.Msg = "获取信息失败"
  405. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  406. return
  407. }
  408. if detail == nil {
  409. resp.HasPermission = 2
  410. } else {
  411. resp.HasPermission = 1
  412. }
  413. if detail != nil {
  414. detail.Body = html.UnescapeString(detail.Body)
  415. detail.Abstract = html.UnescapeString(detail.Abstract)
  416. }
  417. sellerList, err := models.GetSellerList(detail.ArticleId)
  418. if err != nil {
  419. br.Msg = "获取信息失败"
  420. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(detail.ArticleId)
  421. return
  422. }
  423. detail.SellerList = sellerList
  424. resp.Detail = detail
  425. br.Ret = 200
  426. br.Success = true
  427. br.Msg = "获取成功"
  428. br.Data = resp
  429. }
  430. // @Title 获取报告同步
  431. // @Description 获取报告详情接口
  432. // @Param ArticleIdMd5 query int true "报告ID"
  433. // @Success 200 {object} models.ArticleDetailResp
  434. // @router /tongbu [get]
  435. //func (this *ArticleCommonController) Tongbu() {
  436. // br := new(models.BaseResponse).Init()
  437. // defer func() {
  438. // this.Data["json"] = br
  439. // this.ServeJSON()
  440. // }()
  441. //
  442. // fmt.Println("同步数据")
  443. // indexName := utils.IndexName
  444. // fmt.Println(indexName)
  445. // endDate := time.Now().AddDate(0, 0, -7).Format(utils.FormatDate)
  446. // list, err := models.GetTacticsList(endDate)
  447. // //list, err := models.GetTacticsListAll2()
  448. // if err != nil {
  449. // fmt.Println("GetTacticsList Err:", err.Error())
  450. // return
  451. // }
  452. // fmt.Println("list len:", len(list))
  453. //
  454. // summaryCategoryIds := "28,32,45,50,57,62,72,74,79,84,86,88,90,95,96" //纪要库的文章类型ID
  455. // listSummarys := strings.Split(summaryCategoryIds, ",")
  456. // fmt.Println(listSummarys)
  457. // for _, v := range listSummarys {
  458. // vs, _ := strconv.Atoi(v)
  459. // fmt.Printf("n 的类型 %T", vs)
  460. // }
  461. //
  462. // for _, v := range list {
  463. // for _, vs := range listSummarys {
  464. // vint, _ := strconv.Atoi(vs)
  465. // //fmt.Printf("vint 的类型 %T", vint)
  466. // //fmt.Println("————————————")
  467. // //fmt.Printf("vCategoryId 的类型 %T", v.CategoryId)
  468. // //fmt.Println("————————————")
  469. //
  470. // if v.CategoryId == vint {
  471. //
  472. // }
  473. // }
  474. // }
  475. //
  476. // br.Msg = "测试!"
  477. // br.ErrMsg = "参数解析失败,Err:"
  478. // return
  479. //listSummary, errsu := models.GetReportMappingCategoryID()
  480. //if errsu != nil {
  481. // fmt.Println("GetTacticsList Err:", errsu.Error())
  482. // return
  483. //}
  484. //
  485. //listPermission, errper := models.GetPermissionMappingCategoryID()
  486. //if errper != nil {
  487. // fmt.Println("GetTacticsList Err:", errper.Error())
  488. // return
  489. //}
  490. //for k, v := range list {
  491. //
  492. // //是否属于纪要库
  493. // //countSummary, err := models.GetPermissionMappingById(v.CategoryId)
  494. // //if err != nil && err.Error() != utils.ErrNoRow() {
  495. // // br.Msg = "参数解析异常!"
  496. // // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  497. // // return
  498. // //}
  499. // //if countSummary > 0 {
  500. // // v.IsSummary = 1
  501. // //}
  502. // for _, vSum := range listSummary {
  503. // if v.CategoryId == vSum.CategoryId {
  504. // v.IsSummary = 1
  505. // }
  506. // }
  507. // //是否属于报告
  508. // //countReport, err := models.GetReportMappingById(v.CategoryId)
  509. // //if err != nil && err.Error() != utils.ErrNoRow() {
  510. // // br.Msg = "参数解析异常!"
  511. // // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  512. // // return
  513. // //}
  514. // for _, vPer := range listPermission {
  515. // if v.CategoryId == vPer.CategoryId {
  516. // v.IsReport = 1
  517. // }
  518. // }
  519. // if v.IsReport > 0 {
  520. // //是否属于策略 策略自动归类
  521. // //是否属于行业报告 行业报告自动归类
  522. // if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 52 || v.CategoryId == 64 || v.CategoryId == 80 || v.CategoryId == 87 {
  523. // v.IsClass = 1
  524. // }
  525. // if v.CategoryId == 64 || v.CategoryId == 87 || v.CategoryId == 80 {
  526. // v.ReportType = 2 //是否属于行业报告
  527. // } else {
  528. // v.ReportType = 1 //是否属于产业报告
  529. // }
  530. // }
  531. // v.Department = "弘则权益研究"
  532. // fmt.Println(k, v.ArticleId)
  533. // hh, _ := time.ParseDuration("8h")
  534. // //pDate := publishDate.Add(hh)
  535. // v.PublishDate = v.PublishDate.Add(hh)
  536. // //判断是否已经存在
  537. // if v.ArticleId < 0 {
  538. // if err != nil {
  539. // br.Msg = "参数解析异常!"
  540. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  541. // return
  542. // }
  543. // }
  544. // count, err := models.GetArticleCountById(v.ArticleId)
  545. // if err != nil && err.Error() != utils.ErrNoRow() {
  546. // br.Msg = "参数解析异常!"
  547. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  548. // return
  549. // }
  550. // fmt.Println(v.IsClass)
  551. // v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  552. // expertNumStr, expertContentStr, interviewDateStr := services.BodyAnalysis(v.Body)
  553. // if count > 0 {
  554. // fmt.Println(k, v.ArticleId, "edit")
  555. // //articleInfo, err := models.GetArticleDetailById(v.ArticleId)
  556. // //if err != nil {
  557. // // br.Msg = "同步失败!文章ID:" + strconv.Itoa(v.ArticleId)
  558. // // br.ErrMsg = "同步失败,Err:" + err.Error()
  559. // // return
  560. // //}
  561. // //if articleInfo.IsClass == 1 {
  562. // // v.IsClass = 1
  563. // //}
  564. // bodyText, _ := services.GetReportContentTextSub(v.Body)
  565. // updateParams := make(map[string]interface{})
  566. // updateParams["Title"] = v.Title
  567. // updateParams["TitleEn"] = v.TitleEn
  568. // updateParams["UpdateFrequency"] = v.UpdateFrequency
  569. // updateParams["CreateDate"] = v.CreateDate
  570. // updateParams["PublishDate"] = v.PublishDate
  571. // updateParams["Body"] = html.EscapeString(v.Body)
  572. // updateParams["BodyText"] = bodyText
  573. // updateParams["Abstract"] = html.EscapeString(v.Abstract)
  574. // updateParams["CategoryName"] = v.CategoryName
  575. // updateParams["SubCategoryName"] = v.SubCategoryName
  576. // updateParams["CategoryId"] = v.CategoryId
  577. // updateParams["PublishStatus"] = v.PublishStatus
  578. // updateParams["ExpertBackground"] = expertContentStr
  579. // updateParams["ExpertNumber"] = expertNumStr
  580. // updateParams["InterviewDate"] = interviewDateStr
  581. // updateParams["IsClass"] = v.IsClass
  582. // updateParams["IsSummary"] = v.IsSummary
  583. // updateParams["IsReport"] = v.IsReport
  584. // updateParams["ReportType"] = v.ReportType
  585. // if v.Department != "弘则权益研究" {
  586. // v.Department = "弘则权益研究"
  587. // }
  588. // updateParams["Department"] = v.Department
  589. // whereParam := map[string]interface{}{"article_id": v.ArticleId}
  590. // err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  591. // if err != nil {
  592. // fmt.Println("UpdateByExpr Err:" + err.Error())
  593. // }
  594. // } else {
  595. // fmt.Println(k, v.ArticleId, "add")
  596. // item := new(models.CygxArticle)
  597. // articleIdInt := v.ArticleId
  598. // item.ArticleId = articleIdInt
  599. // item.Title = v.Title
  600. // item.TitleEn = v.TitleEn
  601. // item.UpdateFrequency = v.UpdateFrequency
  602. // item.CreateDate = v.CreateDate
  603. // item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  604. // item.Body = html.EscapeString(v.Body)
  605. // item.Abstract = html.EscapeString(v.Abstract)
  606. // item.CategoryName = v.CategoryName
  607. // item.SubCategoryName = v.SubCategoryName
  608. // item.CategoryId = v.CategoryId
  609. // item.PublishStatus = v.PublishStatus
  610. // item.ExpertBackground = expertContentStr
  611. // item.ExpertNumber = expertNumStr
  612. // item.InterviewDate = interviewDateStr
  613. // item.Department = v.Department
  614. // item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
  615. // item.IsClass = v.IsClass
  616. // item.IsSummary = v.IsSummary
  617. // item.IsReport = v.IsReport
  618. // item.ReportType = v.ReportType
  619. // _, err = models.AddCygxArticles(item)
  620. // if err != nil {
  621. // fmt.Println("AddCygxArticle Err:", err.Error())
  622. // br.Msg = "参数解析异常!"
  623. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  624. // return
  625. // }
  626. // }
  627. // //纪要库的数据同步到Es
  628. // if v.IsSummary == 1 {
  629. // content := html.UnescapeString(v.Body)
  630. // doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  631. // if err != nil {
  632. // fmt.Println("create doc err:", err.Error())
  633. // br.Msg = "参数解析异常!"
  634. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  635. // return
  636. // }
  637. // doc.Find("a").Each(func(i int, a *goquery.Selection) {
  638. // a.Remove()
  639. // })
  640. // bodyText := doc.Text()
  641. // item := new(services.ElasticTestArticleDetail)
  642. // item.ArticleId = v.ArticleId
  643. // item.Title = v.Title
  644. // item.BodyText = bodyText
  645. // item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  646. // services.EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
  647. // }
  648. //}
  649. //br.Ret = 200
  650. //br.Success = true
  651. //br.Msg = "同步成功"
  652. //}