article.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  1. package controllers
  2. import (
  3. //"bufio"
  4. //"io"
  5. //"path"
  6. //"rdluck_tools/http"
  7. "bufio"
  8. "io"
  9. "io/ioutil"
  10. //"bufio"
  11. "encoding/json"
  12. "fmt"
  13. "github.com/medivhzhan/weapp/v2"
  14. "hongze/hongze_cygx/models"
  15. "hongze/hongze_cygx/services"
  16. "hongze/hongze_cygx/utils"
  17. "html"
  18. "rdluck_tools/http"
  19. //"rdluck_tools/http"
  20. //"io"
  21. nhttp "net/http"
  22. "os"
  23. //"rdluck_tools/http"
  24. //"path"
  25. //"rdluck_tools/http"
  26. "regexp"
  27. "strconv"
  28. "strings"
  29. "time"
  30. )
  31. type ArticleController struct {
  32. BaseAuthController
  33. }
  34. type ArticleCommonController struct {
  35. BaseCommonController
  36. }
  37. // @Title 获取报告详情
  38. // @Description 获取报告详情接口
  39. // @Param ArticleId query int true "报告ID"
  40. // @Success 200 {object} models.ArticleDetailResp
  41. // @router /detail [get]
  42. func (this *ArticleController) Detail() {
  43. br := new(models.BaseResponse).Init()
  44. defer func() {
  45. this.Data["json"] = br
  46. this.ServeJSON()
  47. }()
  48. user := this.User
  49. if user == nil {
  50. br.Msg = "请登录"
  51. br.ErrMsg = "请登录,用户信息为空"
  52. br.Ret = 408
  53. return
  54. }
  55. uid := user.UserId
  56. articleId, err := this.GetInt("ArticleId")
  57. if articleId <= 0 {
  58. br.Msg = "文章不存在"
  59. br.ErrMsg = "文章不存在,文章ID错误"
  60. return
  61. }
  62. detail := new(models.ArticleDetail)
  63. hasPermission := 0
  64. hasFree := 0
  65. var haveResearch bool
  66. //判断是否已经申请过
  67. applyCount, err := models.GetApplyRecordCount(uid)
  68. if err != nil && err.Error() != utils.ErrNoRow() {
  69. br.Msg = "获取信息失败"
  70. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  71. return
  72. }
  73. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  74. if user.CompanyId > 1 {
  75. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  76. if err != nil {
  77. br.Msg = "获取信息失败"
  78. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  79. return
  80. }
  81. detail, err = models.GetArticleDetailById(articleId)
  82. if err != nil {
  83. br.Msg = "获取信息失败"
  84. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  85. return
  86. }
  87. detail.Body = html.UnescapeString(detail.Body)
  88. //detail.Abstract = html.UnescapeString(detail.Abstract)
  89. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  90. if companyPermission == "" {
  91. if applyCount > 0 {
  92. hasPermission = 5
  93. } else {
  94. hasPermission = 2
  95. }
  96. hasFree = 2
  97. goto Loop
  98. } else {
  99. hasFree = 1
  100. var articlePermissionPermissionName string
  101. if detail.CategoryId > 0 {
  102. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  103. if err != nil {
  104. br.Msg = "获取信息失败"
  105. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  106. return
  107. }
  108. if articlePermission == nil {
  109. br.Msg = "获取信息失败"
  110. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  111. return
  112. }
  113. articlePermissionPermissionName = articlePermission.PermissionName
  114. } else {
  115. articlePermissionPermissionName = detail.CategoryName
  116. }
  117. var hasPersion bool
  118. slice := strings.Split(articlePermissionPermissionName, ",")
  119. for _, v := range slice {
  120. if strings.Contains(companyPermission, v) {
  121. hasPersion = true
  122. }
  123. }
  124. if strings.Contains(detail.CategoryName, "研选") {
  125. detail.IsResearch = true
  126. }
  127. userType, _, err := services.GetUserType(user.CompanyId)
  128. if err != nil {
  129. br.Msg = "获取信息失败"
  130. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  131. return
  132. }
  133. if userType == 1 && strings.Contains(detail.CategoryName, "研选") {
  134. hasPersion = false
  135. }
  136. if hasPersion {
  137. hasPermission = 1
  138. historyRecord := new(models.CygxArticleHistoryRecord)
  139. historyRecord.UserId = uid
  140. historyRecord.ArticleId = articleId
  141. historyRecord.CreateTime = time.Now()
  142. historyRecord.Mobile = user.Mobile
  143. historyRecord.Email = user.Email
  144. historyRecord.CompanyId = user.CompanyId
  145. historyRecord.CompanyName = user.CompanyName
  146. recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
  147. if recordCount == 0 {
  148. go models.AddCygxArticleHistoryRecord(historyRecord)
  149. } else {
  150. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  151. if err != nil {
  152. br.Msg = "获取信息失败"
  153. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  154. return
  155. }
  156. if detailNew.StopTime > 0 {
  157. go models.AddCygxArticleHistoryRecord(historyRecord)
  158. }
  159. }
  160. } else { //无该行业权限
  161. hasPermission = 3
  162. }
  163. if hasPermission == 1 {
  164. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  165. if !utils.Rc.IsExist(key) {
  166. //新增浏览记录
  167. record := new(models.CygxArticleViewRecord)
  168. record.UserId = uid
  169. record.ArticleId = articleId
  170. record.CreateTime = time.Now()
  171. record.Mobile = user.Mobile
  172. record.Email = user.Email
  173. record.CompanyId = user.CompanyId
  174. record.CompanyName = user.CompanyName
  175. go models.AddCygxArticleViewRecord(record)
  176. utils.Rc.Put(key, 1, 5*time.Second)
  177. models.ModifyReportLastViewTime(uid)
  178. }
  179. }
  180. }
  181. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  182. if err != nil && err.Error() != utils.ErrNoRow() {
  183. br.Msg = "获取信息失败"
  184. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  185. return
  186. }
  187. if collectCount > 0 {
  188. detail.IsCollect = true
  189. }
  190. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  191. if err != nil && err.Error() != utils.ErrNoRow() {
  192. br.Msg = "获取信息失败"
  193. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  194. return
  195. }
  196. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  197. detail.IsInterviewApply = true
  198. detail.InterviewApplyStatus = interviewApplyItem.Status
  199. }
  200. //获取销售手机号
  201. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  202. if err != nil {
  203. br.Msg = "获取信息失败"
  204. br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  205. return
  206. }
  207. if sellerItem != nil {
  208. detail.SellerMobile = sellerItem.Mobile
  209. detail.SellerName = sellerItem.RealName
  210. }
  211. sellerList, err := models.GetSellerList(articleId)
  212. if err != nil {
  213. br.Msg = "获取信息失败"
  214. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  215. return
  216. }
  217. fmt.Println(detail.SellerAndMobile)
  218. if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
  219. strnum := strings.Index(detail.SellerAndMobile, "-")
  220. detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
  221. fmt.Println(detail.SellerAndMobile)
  222. if strnum > 0 {
  223. nickName := detail.SellerAndMobile[0:strnum]
  224. sellerAndMobile := &models.SellerRep{
  225. SellerMobile: "",
  226. SellerName: nickName,
  227. }
  228. sellerList = append(sellerList, sellerAndMobile)
  229. }
  230. }
  231. detail.SellerList = sellerList
  232. } else { //潜在客户
  233. if applyCount > 0 {
  234. hasPermission = 5
  235. } else {
  236. hasPermission = 4
  237. }
  238. }
  239. Loop:
  240. if hasPermission != 1 {
  241. detail.Body = ""
  242. detail.BodyText = ""
  243. } else {
  244. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  245. if err != nil {
  246. br.Msg = "获取信息失败"
  247. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  248. return
  249. }
  250. detail.FollowNum = articleFollowdetail.DNum
  251. detail.CollectionNum = articleFollowdetail.AcNum
  252. if articleFollowdetail.MdNum > 0 {
  253. detail.IsFollow = true
  254. }
  255. if detail.IsSummary == 1 {
  256. detail.IsBelongSummary = true
  257. }
  258. if detail.IsReport == 1 {
  259. detail.IsBelongReport = true
  260. }
  261. haveResearch = true
  262. }
  263. resp := new(models.ArticleDetailResp)
  264. resp.HasPermission = hasPermission
  265. resp.HaveResearch = haveResearch
  266. resp.HasFree = hasFree
  267. resp.Detail = detail
  268. if user.Mobile != "" {
  269. resp.Mobile = user.Mobile
  270. } else {
  271. resp.Mobile = user.Email
  272. }
  273. br.Ret = 200
  274. br.Success = true
  275. br.Msg = "获取成功"
  276. br.Data = resp
  277. }
  278. // @Title 收藏
  279. // @Description 收藏
  280. // @Param request body models.ArticleCollectReq true "type json string"
  281. // @Success 200 {object} models.FontsCollectResp
  282. // @router /collect [post]
  283. func (this *ArticleController) ArticleCollect() {
  284. br := new(models.BaseResponse).Init()
  285. defer func() {
  286. this.Data["json"] = br
  287. this.ServeJSON()
  288. }()
  289. user := this.User
  290. if user == nil {
  291. br.Msg = "请重新登录"
  292. br.Ret = 408
  293. return
  294. }
  295. uid := user.UserId
  296. var req models.ArticleCollectReq
  297. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  298. if err != nil {
  299. br.Msg = "参数解析异常!"
  300. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  301. return
  302. }
  303. count, err := models.GetArticleCollectCount(uid, req.ArticleId)
  304. if err != nil {
  305. br.Msg = "获取数据失败!"
  306. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  307. return
  308. }
  309. resp := new(models.ArticleCollectResp)
  310. if count <= 0 {
  311. item := new(models.CygxArticleCollect)
  312. item.ArticleId = req.ArticleId
  313. item.UserId = uid
  314. item.CreateTime = time.Now()
  315. _, err = models.AddCygxArticleCollect(item)
  316. if err != nil {
  317. br.Msg = "收藏失败"
  318. br.ErrMsg = "收藏失败,Err:" + err.Error()
  319. return
  320. }
  321. br.Msg = "收藏成功"
  322. resp.Status = 1
  323. } else {
  324. err = models.RemoveArticleCollect(uid, req.ArticleId)
  325. if err != nil {
  326. br.Msg = "取消收藏失败"
  327. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  328. return
  329. }
  330. br.Msg = "已取消收藏"
  331. resp.Status = 2
  332. }
  333. collectTotal, err := models.GetArticleCollectUsersCount(req.ArticleId)
  334. if err != nil {
  335. br.Msg = "获取数据失败"
  336. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  337. return
  338. }
  339. resp.CollectCount = collectTotal
  340. br.Ret = 200
  341. br.Success = true
  342. br.Data = resp
  343. }
  344. // @Title 访谈申请
  345. // @Description 访谈申请
  346. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  347. // @Success 200 {object} models.FontsCollectResp
  348. // @router /interview/apply [post]
  349. func (this *ArticleController) InterviewApply() {
  350. br := new(models.BaseResponse).Init()
  351. defer func() {
  352. this.Data["json"] = br
  353. this.ServeJSON()
  354. }()
  355. user := this.User
  356. if user == nil {
  357. br.Msg = "请重新登录"
  358. br.Ret = 408
  359. return
  360. }
  361. uid := user.UserId
  362. var req models.ArticleInterviewApplyReq
  363. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  364. if err != nil {
  365. br.Msg = "参数解析异常!"
  366. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  367. return
  368. }
  369. article, err := models.GetArticleDetailById(req.ArticleId)
  370. if err != nil {
  371. br.Msg = "获取纪要失败!"
  372. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  373. return
  374. }
  375. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  376. if err != nil {
  377. br.Msg = "获取数据失败!"
  378. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  379. return
  380. }
  381. resp := new(models.ArticleInterviewApplyResp)
  382. if count <= 0 {
  383. item := new(models.CygxInterviewApply)
  384. item.ArticleId = req.ArticleId
  385. item.UserId = uid
  386. item.CompanyId = user.CompanyId
  387. item.Status = "待邀请"
  388. item.Sort = 1
  389. item.ArticleTitle = article.Title
  390. item.CreateTime = time.Now()
  391. item.ModifyTime = time.Now()
  392. item.ArticleIdMd5 = article.ArticleIdMd5
  393. _, err = models.AddCygxInterviewApply(item)
  394. if err != nil {
  395. br.Msg = "申请失败"
  396. br.ErrMsg = "申请失败,Err:" + err.Error()
  397. return
  398. }
  399. br.Msg = "申请成功"
  400. resp.Status = 1
  401. //发送模板消息
  402. if user.CompanyId > 1 {
  403. mobile := user.Mobile
  404. if mobile == "" {
  405. mobile = user.Email
  406. }
  407. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  408. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  409. openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1)
  410. if openIpItem != nil && openIpItem.OpenId != "" {
  411. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  412. }
  413. }
  414. }
  415. } else {
  416. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  417. if err != nil {
  418. br.Msg = "取消申请失败"
  419. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  420. return
  421. }
  422. br.Msg = "已取消申请"
  423. resp.Status = 2
  424. if user.CompanyId > 1 {
  425. mobile := user.Mobile
  426. if mobile == "" {
  427. mobile = user.Email
  428. }
  429. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  430. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  431. openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1)
  432. if openIpItem != nil && openIpItem.OpenId != "" {
  433. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId)
  434. }
  435. }
  436. }
  437. }
  438. br.Ret = 200
  439. br.Success = true
  440. br.Data = resp
  441. }
  442. // @Title 获取报告详情
  443. // @Description 获取报告详情接口
  444. // @Param ArticleIdMd5 query int true "报告ID"
  445. // @Success 200 {object} models.ArticleDetailResp
  446. // @router /look/detail [get]
  447. func (this *ArticleCommonController) Detail() {
  448. br := new(models.BaseResponse).Init()
  449. defer func() {
  450. this.Data["json"] = br
  451. this.ServeJSON()
  452. }()
  453. articleIdMd5 := this.GetString("ArticleIdMd5")
  454. if articleIdMd5 == "" {
  455. br.Msg = "参数错误"
  456. br.ErrMsg = "参数错误"
  457. return
  458. }
  459. resp := new(models.ArticleDetailResp)
  460. detail, err := models.GetArticleDetailByIdMd5(articleIdMd5)
  461. if err != nil && err.Error() != utils.ErrNoRow() {
  462. br.Msg = "获取信息失败"
  463. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  464. return
  465. }
  466. if detail == nil {
  467. resp.HasPermission = 2
  468. } else {
  469. resp.HasPermission = 1
  470. }
  471. if detail != nil {
  472. detail.Body = html.UnescapeString(detail.Body)
  473. detail.Abstract = html.UnescapeString(detail.Abstract)
  474. }
  475. sellerList, err := models.GetSellerList(detail.ArticleId)
  476. if err != nil {
  477. br.Msg = "获取信息失败"
  478. br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(detail.ArticleId)
  479. return
  480. }
  481. if detail.ArticleId > 1000000 {
  482. var hrefRegexp = regexp.MustCompile("[0-9]\\d*")
  483. match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1)
  484. if match != nil {
  485. for _, v := range match {
  486. sellerAndMobile := &models.SellerRep{
  487. SellerMobile: v,
  488. SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1),
  489. }
  490. sellerList = append(sellerList, sellerAndMobile)
  491. }
  492. }
  493. }
  494. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  495. detail.SellerList = sellerList
  496. resp.Detail = detail
  497. br.Ret = 200
  498. br.Success = true
  499. br.Msg = "获取成功"
  500. br.Data = resp
  501. }
  502. // @Title 上传文章阅读时间
  503. // @Description 上传文章阅读时间接口
  504. // @Param request body models.AddStopTimeRep true "type json string"
  505. // @Success 200 {object} models.ArticleDetailResp
  506. // @router /addStopTime [post]
  507. func (this *ArticleController) AddStopTime() {
  508. br := new(models.BaseResponse).Init()
  509. defer func() {
  510. this.Data["json"] = br
  511. this.ServeJSON()
  512. }()
  513. user := this.User
  514. if user == nil {
  515. br.Msg = "请登录"
  516. br.ErrMsg = "请登录,用户信息为空"
  517. br.Ret = 408
  518. return
  519. }
  520. var req models.AddStopTimeRep
  521. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  522. if err != nil {
  523. br.Msg = "参数解析异常!"
  524. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  525. return
  526. }
  527. uid := user.UserId
  528. articleId := req.ArticleId
  529. stopTime := req.StopTime
  530. if articleId <= 0 {
  531. br.Msg = "参数错误"
  532. br.ErrMsg = "参数错误"
  533. return
  534. }
  535. if stopTime == 0 {
  536. stopTime = 1
  537. //br.Msg = "时间格式错误"
  538. //br.ErrMsg = "时间错误"
  539. //return
  540. }
  541. detail := new(models.ArticleDetail)
  542. hasPermission := 0
  543. hasFree := 0
  544. //判断是否已经申请过
  545. applyCount, err := models.GetApplyRecordCount(uid)
  546. if err != nil && err.Error() != utils.ErrNoRow() {
  547. br.Msg = "获取信息失败"
  548. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  549. return
  550. }
  551. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  552. if user.CompanyId > 1 {
  553. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  554. if err != nil {
  555. br.Msg = "获取信息失败"
  556. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  557. return
  558. }
  559. detail, err = models.GetArticleDetailById(articleId)
  560. if err != nil {
  561. br.Msg = "获取信息失败"
  562. br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  563. return
  564. }
  565. if companyPermission == "" {
  566. if applyCount > 0 {
  567. hasPermission = 5
  568. } else {
  569. hasPermission = 2
  570. }
  571. hasFree = 2
  572. goto Loop
  573. } else {
  574. hasFree = 1
  575. var articlePermissionPermissionName string
  576. if detail.CategoryId > 0 {
  577. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  578. if err != nil {
  579. br.Msg = "获取信息失败"
  580. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  581. return
  582. }
  583. if articlePermission == nil {
  584. br.Msg = "获取信息失败"
  585. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  586. return
  587. }
  588. articlePermissionPermissionName = articlePermission.PermissionName
  589. } else {
  590. articlePermissionPermissionName = detail.CategoryName
  591. }
  592. var hasPersion bool
  593. slice := strings.Split(articlePermissionPermissionName, ",")
  594. for _, v := range slice {
  595. if strings.Contains(companyPermission, v) {
  596. hasPersion = true
  597. }
  598. }
  599. if hasPersion {
  600. detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
  601. if err == nil {
  602. //br.Msg = "获取信息失败"
  603. //br.ErrMsg = "获取最新阅读信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  604. //return
  605. hasPermission = 1
  606. historyRecord := new(models.AddStopTimeNewRep)
  607. historyRecord.StopTime = detailNew.StopTime + stopTime
  608. historyRecord.Id = detailNew.Id
  609. go models.AddArticleStopTime(historyRecord)
  610. }
  611. } else { //无该行业权限
  612. hasPermission = 3
  613. }
  614. }
  615. } else { //潜在客户
  616. if applyCount > 0 {
  617. hasPermission = 5
  618. } else {
  619. hasPermission = 4
  620. }
  621. }
  622. Loop:
  623. resp := new(models.ArticleDetailAddStopTimeRep)
  624. resp.HasPermission = hasPermission
  625. resp.HasFree = hasFree
  626. br.Ret = 200
  627. br.Success = true
  628. br.Msg = "操作成功"
  629. br.Data = resp
  630. }
  631. // @Title 文章带问
  632. // @Description 新增文章带问接口
  633. // @Param request body models.AddArticleAskRep true "type json string"
  634. // @Success Ret=200 新增成功
  635. // @router /askAdd [post]
  636. func (this *ArticleController) AskAdd() {
  637. br := new(models.BaseResponse).Init()
  638. defer func() {
  639. this.Data["json"] = br
  640. this.ServeJSON()
  641. }()
  642. user := this.User
  643. if user == nil {
  644. br.Msg = "请登录"
  645. br.ErrMsg = "请登录,SysUser Is Empty"
  646. br.Ret = 408
  647. return
  648. }
  649. var req models.AddArticleAskRep
  650. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  651. if err != nil {
  652. br.Msg = "参数解析异常!"
  653. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  654. return
  655. }
  656. if req.Content == "" {
  657. br.Msg = "建议内容不可为空"
  658. return
  659. }
  660. content := req.Content
  661. itemToken, err := services.WxGetToken()
  662. if err != nil {
  663. br.Msg = "GetWxAccessToken Err:" + err.Error()
  664. return
  665. }
  666. if itemToken.AccessToken == "" {
  667. br.Msg = "accessToken is empty"
  668. return
  669. }
  670. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  671. if err != nil {
  672. br.Msg = "内容校验失败!"
  673. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  674. return
  675. }
  676. if commerr.ErrCode != 0 {
  677. br.Msg = "内容违规,请重新提交!"
  678. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  679. return
  680. }
  681. articleId := req.ArticleId
  682. count, _ := models.GetArticleCountById(articleId)
  683. if count == 0 {
  684. br.Msg = "操作失败"
  685. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  686. return
  687. }
  688. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  689. if err != nil {
  690. br.Msg = "提交失败!"
  691. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  692. return
  693. }
  694. if companyDetail == nil {
  695. br.Msg = "提交失败!"
  696. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  697. return
  698. }
  699. item := new(models.CygxArticleAsk)
  700. item.UserId = user.UserId
  701. item.ArticleId = req.ArticleId
  702. item.CompanyId = user.CompanyId
  703. item.CompanyName = companyDetail.CompanyName
  704. item.CreateTime = time.Now()
  705. item.Mobile = user.Mobile
  706. item.Email = user.Email
  707. item.Content = content
  708. _, err = models.AddArticleAsk(item)
  709. if err != nil {
  710. br.Msg = "提交失败"
  711. br.ErrMsg = "提交失败,Err:" + err.Error()
  712. return
  713. }
  714. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  715. if err != nil {
  716. br.Msg = "获取信息失败"
  717. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  718. return
  719. }
  720. var mobile string
  721. if utils.WxMsgTemplateIdAskMsgMobile == "" {
  722. //mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  723. mobile = utils.WxMsgTemplateIdAskMsgMobileAll
  724. } else {
  725. mobile = utils.WxMsgTemplateIdAskMsgMobile
  726. }
  727. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  728. if err != nil {
  729. br.Msg = "提交失败"
  730. br.ErrMsg = "提交失败,Err:" + err.Error()
  731. return
  732. }
  733. detail, err := models.GetArticleDetailById(articleId)
  734. if err != nil {
  735. br.Msg = "获取信息失败"
  736. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  737. return
  738. }
  739. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  740. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  741. br.Ret = 200
  742. br.Success = true
  743. br.Msg = "提交成功"
  744. }
  745. // @Title 下载PDF打水印
  746. // @Description 下载PDF打水印接口
  747. // @Param ArticleId query int true "报告ID"
  748. // @Success 200 {object} models.ArticleDetailFileLink
  749. // @router /pdfwatermark [get]
  750. func (this *ArticleController) Pdfwatermark() {
  751. br := new(models.BaseResponse).Init()
  752. defer func() {
  753. this.Data["json"] = br
  754. this.ServeJSON()
  755. }()
  756. user := this.User
  757. if user == nil {
  758. br.Msg = "请登录"
  759. br.ErrMsg = "请登录,用户信息为空"
  760. br.Ret = 408
  761. return
  762. }
  763. articleId, err := this.GetInt("ArticleId")
  764. if articleId <= 0 {
  765. br.Msg = "文章不存在"
  766. br.ErrMsg = "文章不存在,文章ID错误"
  767. return
  768. }
  769. detail := new(models.ArticleDetail)
  770. detail, err = models.GetArticleDetailById(articleId)
  771. if err != nil {
  772. br.Msg = "获取信息失败"
  773. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  774. return
  775. }
  776. fileLink := detail.FileLink
  777. if fileLink == "" {
  778. br.Msg = "下载失败"
  779. br.ErrMsg = "下载失败,报告链接不存在"
  780. return
  781. }
  782. mobile := user.Mobile
  783. if mobile == "" {
  784. mobile = user.Email
  785. }
  786. dataMap := make(map[string]interface{})
  787. dataMap["Mobile"] = mobile
  788. //dataMap["Name"] = user.RealName
  789. dataMap["Name"] = ""
  790. pdfPath := "static/"
  791. pdfUrl := fileLink
  792. fileName := utils.GetRandStringNoSpecialChar(28) + ".pdf"
  793. res, err := nhttp.Get(pdfUrl)
  794. if err != nil {
  795. fmt.Println("A error occurred!")
  796. return
  797. }
  798. defer res.Body.Close()
  799. // 获得get请求响应的reader对象
  800. reader := bufio.NewReaderSize(res.Body, 32*1024)
  801. file, err := os.Create(pdfPath + fileName)
  802. if err != nil {
  803. panic(err)
  804. }
  805. //获得文件的writer对象
  806. writer := bufio.NewWriter(file)
  807. written, _ := io.Copy(writer, reader)
  808. fmt.Printf("Total length: %d", written)
  809. str, _ := os.Getwd()
  810. fileLink = str + "/" + pdfPath + fileName
  811. dataMap["FileLink"] = fileLink
  812. postUrl := "http://127.0.0.1:5007/pdfwatermark/" //
  813. fmt.Println("postUrl:", postUrl)
  814. postData, err := json.Marshal(dataMap)
  815. if err != nil {
  816. br.Msg = "下载失败"
  817. br.ErrMsg = "解析,Marshal,Err:" + err.Error()
  818. return
  819. }
  820. fmt.Println("publish ppt param:", string(postData))
  821. result, err := http.Post(postUrl, string(postData))
  822. if err != nil {
  823. br.Msg = "下载失败"
  824. br.ErrMsg = "Marshal,Err:" + err.Error()
  825. return
  826. }
  827. fmt.Println("publish pdf result:", string(result))
  828. var pdfResult PublishPdfResult
  829. err = json.Unmarshal(result, &pdfResult)
  830. if err != nil {
  831. br.Msg = "下载失败"
  832. br.ErrMsg = "Unmarshal,Err:" + err.Error()
  833. return
  834. }
  835. //fmt.Println(pdfResult)
  836. resp := new(models.ArticleDetailFileLink)
  837. filePathName := strings.TrimLeft(pdfResult.FilePath, ".")
  838. //filePathOldName := strings.TrimLeft(pdfResult.FileOldPath, ".")
  839. filePath := pdfResult.Pdfpath + filePathName
  840. //filePathOld := pdfResult.Pdfpath + filePathOldName
  841. randStr := utils.GetRandStringNoSpecialChar(28)
  842. fileName = randStr + ".pdf"
  843. hzUploadDir := "static/pdf/"
  844. savePath := hzUploadDir + time.Now().Format("200601/20060102/")
  845. savePath += fileName
  846. //上传到阿里云
  847. err = services.UploadFileToAliyun(fileName, filePath, savePath)
  848. if err != nil {
  849. br.Msg = "下载失败"
  850. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  851. return
  852. }
  853. utils.FileLog.Info("%s:", time.Now().Format(utils.FormatDateTime))
  854. utils.FileLog.Info("end update oss ")
  855. fileHost := "https://hzstatic.hzinsights.com/"
  856. resourceUrl := fileHost + savePath
  857. defer func() {
  858. os.Remove(filePath)
  859. os.Remove(fileLink)
  860. }()
  861. resp.FileLink = resourceUrl
  862. br.Ret = 200
  863. br.Success = true
  864. br.Msg = "获取成功"
  865. br.Data = resp
  866. }
  867. type PublishPdfResult struct {
  868. Result string `json:"result"`
  869. FilePath string `json:"file_path"`
  870. FileOldPath string `json:"file_old_path"`
  871. Pdfpath string `json:"pdfpath"`
  872. }
  873. // @Title 同步策略报告内容
  874. // @Description 同步策略报告内容接口
  875. // @Param ArticleIdMd5 query int true "报告ID"
  876. // @Success 200 {object} models.ArticleDetailResp
  877. // @router /look/listApi [get]
  878. func (this *ArticleCommonController) ListApi() {
  879. br := new(models.BaseResponse).Init()
  880. defer func() {
  881. this.Data["json"] = br
  882. this.ServeJSON()
  883. }()
  884. url := "https://vmp.hzinsights.com/v2api/articles/mp?take=20&skip=0&publish_status=1"
  885. method := "GET"
  886. client := &nhttp.Client{}
  887. req, err := nhttp.NewRequest(method, url, nil)
  888. if err != nil {
  889. fmt.Println(err)
  890. return
  891. }
  892. req.Header.Add("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag")
  893. res, err := client.Do(req)
  894. if err != nil {
  895. fmt.Println(err)
  896. return
  897. }
  898. defer res.Body.Close()
  899. body, err := ioutil.ReadAll(res.Body)
  900. if err != nil {
  901. fmt.Println(err)
  902. return
  903. }
  904. var pdfResult models.ArticleResultApi
  905. err = json.Unmarshal(body, &pdfResult)
  906. if err != nil {
  907. br.Msg = "获取失败"
  908. br.ErrMsg = "Unmarshal,Err:" + err.Error()
  909. return
  910. }
  911. exitMap := make(map[int]int)
  912. listMap, err := models.GetArticleApiMap()
  913. if err != nil {
  914. br.Msg = "获取失败"
  915. br.ErrMsg = "获取映射关系失败,Err:" + err.Error()
  916. return
  917. }
  918. //新旧分类 反向隐射
  919. for _, v := range listMap {
  920. exitMap[v.Id] = v.OldId
  921. }
  922. listData := pdfResult.Data
  923. var list []*models.Tactics2
  924. var listAuthor []*models.CygxArticleAuthor
  925. for _, v := range listData {
  926. if exitMap[v.SeriesId] > 0 {
  927. item := new(models.Tactics2)
  928. itemAuthor := new(models.CygxArticleAuthor)
  929. item.ArticleId = v.ArticleId
  930. item.Title = v.Title
  931. item.TitleEn = v.TitleEn
  932. if v.Frequency == "日度" {
  933. item.UpdateFrequency = "daily"
  934. } else if v.Frequency == "周度" {
  935. item.UpdateFrequency = "weekly"
  936. } else if v.Frequency == "月度" {
  937. item.UpdateFrequency = "monthly"
  938. } else if v.Frequency == "季度" {
  939. item.UpdateFrequency = "quarterly"
  940. } else if v.Frequency == "年度" {
  941. item.UpdateFrequency = "yearly"
  942. } else {
  943. item.UpdateFrequency = "unknow"
  944. }
  945. item.CreateDate = v.CreateDate
  946. item.PublishDate = v.PublishDate
  947. item.PublishStatus = v.PublishStatus
  948. item.Body = v.Content.Body
  949. item.Abstract = v.Content.Abstract
  950. item.CategoryName = v.Industry.Name
  951. item.CategoryId = exitMap[v.SeriesId]
  952. item.SubCategoryName = v.Series.Name
  953. list = append(list, item)
  954. itemAuthor.ArticleId = v.ArticleId
  955. itemAuthor.Name = v.Author.Name
  956. itemAuthor.Mobile = v.Author.PhoneNumber
  957. listAuthor = append(listAuthor, itemAuthor)
  958. }
  959. }
  960. //同步作者
  961. for _, v := range listAuthor {
  962. count, err := models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
  963. if err != nil {
  964. fmt.Println("GetCount Err:", err.Error())
  965. return
  966. }
  967. if count == 0 {
  968. _, err := models.AddCygxActivityAuthor(v)
  969. if err != nil {
  970. fmt.Println("AddCygxActivityAuthor Err:", err.Error())
  971. return
  972. }
  973. }
  974. }
  975. fmt.Println("同步文章条数:", len(list))
  976. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  977. if err != nil {
  978. fmt.Println("GetTacticsList Err:", err.Error())
  979. return
  980. }
  981. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  982. if errMatch != nil {
  983. fmt.Println("GetTacticsList Err:", errMatch.Error())
  984. return
  985. }
  986. fmt.Println("list len:", len(list))
  987. summaryCategoryIds := "28,32,45,50,57,62,72,74,79,84,86,88,90,93,95,96" //纪要库的文章类型categoty_id
  988. listSummary := strings.Split(summaryCategoryIds, ",")
  989. noSummaryArticleIds := "3454,3456,3457,3459,2449,2450,2453,2454,2459,2530,2583,2663,2670,2699,2715,2732,2748,2759,2399,2356,2870,3173,2978,2826,3470" //非纪要库类型的文章ID
  990. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  991. listPermission, errper := models.GetPermissionMappingCategoryID()
  992. if errper != nil {
  993. fmt.Println("GetTacticsList Err:", errper.Error())
  994. return
  995. }
  996. summaryMap := make(map[int]int)
  997. for _, vSum := range listSummary {
  998. vSumInt, _ := strconv.Atoi(vSum)
  999. summaryMap[vSumInt] = 1
  1000. }
  1001. for k, v := range list {
  1002. //同步匹配类型
  1003. matchTypeName := ""
  1004. for _, vMatch := range listGetMatchTypeName {
  1005. if v.CategoryId == vMatch.CategoryId {
  1006. matchTypeName = vMatch.MatchTypeName
  1007. }
  1008. }
  1009. //是否属于纪要库的数据
  1010. if _, has := summaryMap[v.CategoryId]; has {
  1011. v.IsSummary = 1
  1012. }
  1013. //排除不属于纪要库类型的文章
  1014. for _, vArt := range listNoSummaryArticleIds {
  1015. vArtInt, _ := strconv.Atoi(vArt)
  1016. if v.ArticleId == vArtInt {
  1017. v.IsSummary = 0
  1018. }
  1019. }
  1020. for _, vPer := range listPermission {
  1021. if v.CategoryId == vPer.CategoryId {
  1022. v.IsReport = 1
  1023. }
  1024. }
  1025. if v.IsReport > 0 {
  1026. //是否属于策略 策略自动归类
  1027. //是否属于行业报告 行业报告自动归类
  1028. if v.CategoryId == 7 || v.CategoryId == 9 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 52 || v.CategoryId == 64 || v.CategoryId == 80 || v.CategoryId == 87 {
  1029. v.IsClass = 1
  1030. v.ReportType = 1 //是否属于行业报告
  1031. } else {
  1032. v.ReportType = 2 //是否属于产业报告
  1033. }
  1034. }
  1035. v.Department = "弘则权益研究"
  1036. fmt.Println(k, v.ArticleId)
  1037. hh, _ := time.ParseDuration("8h")
  1038. //pDate := publishDate.Add(hh)
  1039. v.PublishDate = v.PublishDate.Add(hh)
  1040. //判断是否已经存在
  1041. if v.ArticleId < 0 {
  1042. fmt.Println("AddCygxArticle Err:")
  1043. return
  1044. }
  1045. count, err := models.GetArticleCountById(v.ArticleId)
  1046. if err != nil && err.Error() != utils.ErrNoRow() {
  1047. fmt.Println("AddCygxArticle Err:", err.Error())
  1048. return
  1049. }
  1050. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  1051. expertNumStr, expertContentStr, interviewDateStr, fileLink, bodyReturn := services.BodyAnalysis2(v.Body)
  1052. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  1053. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  1054. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  1055. v.Body = strings.Replace(v.Body, "):", "", -1)
  1056. }
  1057. var titleNew string
  1058. titleNew = v.Title
  1059. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  1060. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  1061. if v.UpdateFrequency == "daily" {
  1062. var daystr string
  1063. daystr = strconv.Itoa(v.PublishDate.Day())
  1064. if len(daystr) == 1 {
  1065. daystr = "0" + daystr
  1066. }
  1067. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  1068. } else if v.UpdateFrequency == "weekly" {
  1069. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  1070. }
  1071. }
  1072. if v.CategoryId == 80 {
  1073. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  1074. }
  1075. if count > 0 {
  1076. fmt.Println(k, v.ArticleId, "edit")
  1077. var isCustom bool
  1078. bodyText, _ := services.GetReportContentTextSub(v.Body)
  1079. updateParams := make(map[string]interface{})
  1080. //updateParams["Title"] = v.Title
  1081. updateParams["Title"] = titleNew
  1082. updateParams["TitleEn"] = v.TitleEn
  1083. updateParams["UpdateFrequency"] = v.UpdateFrequency
  1084. updateParams["CreateDate"] = v.CreateDate
  1085. updateParams["PublishDate"] = v.PublishDate
  1086. //updateParams["Body"] = html.EscapeString(v.Body)
  1087. updateParams["Body"] = html.EscapeString(bodyReturn)
  1088. updateParams["BodyText"] = bodyText
  1089. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  1090. updateParams["CategoryName"] = v.CategoryName
  1091. for _, vCustom := range listCustomArticle {
  1092. if v.ArticleId == vCustom.ArticleId {
  1093. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  1094. isCustom = true
  1095. }
  1096. }
  1097. if isCustom == false {
  1098. updateParams["CategoryId"] = v.CategoryId
  1099. updateParams["MatchTypeName"] = matchTypeName
  1100. updateParams["IsSummary"] = v.IsSummary
  1101. updateParams["IsReport"] = v.IsReport
  1102. updateParams["ReportType"] = v.ReportType
  1103. updateParams["SubCategoryName"] = v.SubCategoryName
  1104. }
  1105. //updateParams["CategoryId"] = v.CategoryId
  1106. updateParams["PublishStatus"] = v.PublishStatus
  1107. updateParams["ExpertBackground"] = expertContentStr
  1108. updateParams["ExpertNumber"] = expertNumStr
  1109. updateParams["InterviewDate"] = interviewDateStr
  1110. //updateParams["IsClass"] = v.IsClass
  1111. if v.Department != "弘则权益研究" {
  1112. v.Department = "弘则权益研究"
  1113. }
  1114. updateParams["Department"] = v.Department
  1115. updateParams["FileLink"] = fileLink
  1116. whereParam := map[string]interface{}{"article_id": v.ArticleId}
  1117. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  1118. if err != nil {
  1119. fmt.Println("UpdateByExpr Err:" + err.Error())
  1120. }
  1121. } else {
  1122. fmt.Println(k, v.ArticleId, "add")
  1123. item := new(models.CygxArticle)
  1124. articleIdInt := v.ArticleId
  1125. item.ArticleId = articleIdInt
  1126. //item.Title = v.Title
  1127. item.Title = titleNew
  1128. item.TitleEn = v.TitleEn
  1129. item.UpdateFrequency = v.UpdateFrequency
  1130. item.CreateDate = v.CreateDate
  1131. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  1132. //item.Body = html.EscapeString(v.Body)
  1133. item.Body = html.EscapeString(bodyReturn)
  1134. item.Abstract = html.EscapeString(v.Abstract)
  1135. item.CategoryName = v.CategoryName
  1136. item.SubCategoryName = v.SubCategoryName
  1137. item.CategoryId = v.CategoryId
  1138. item.PublishStatus = v.PublishStatus
  1139. item.ExpertBackground = expertContentStr
  1140. item.ExpertNumber = expertNumStr
  1141. item.InterviewDate = interviewDateStr
  1142. item.Department = v.Department
  1143. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
  1144. item.IsClass = v.IsClass
  1145. item.IsSummary = v.IsSummary
  1146. item.IsReport = v.IsReport
  1147. item.ReportType = v.ReportType
  1148. item.FileLink = fileLink
  1149. item.MatchTypeName = matchTypeName
  1150. _, err = models.AddCygxArticles(item)
  1151. if err != nil {
  1152. fmt.Println("AddCygxArticle Err:", err.Error())
  1153. return
  1154. }
  1155. }
  1156. }
  1157. br.Ret = 200
  1158. br.Success = true
  1159. br.Msg = "获取成功"
  1160. br.Data = string(body)
  1161. }
  1162. // @Title 同步参会记录
  1163. // @Description 获取报告详情接口
  1164. // @Param ArticleIdMd5 query int true "报告ID"
  1165. // @Success 200 {object} models.ArticleDetailResp
  1166. // @router /look/detaisl [get]
  1167. func (this *ArticleCommonController) Detaisl() {
  1168. br := new(models.BaseResponse).Init()
  1169. defer func() {
  1170. this.Data["json"] = br
  1171. this.ServeJSON()
  1172. }()
  1173. var condition string
  1174. fmt.Println(condition)
  1175. //list, err := models.GetOfflineMeetingDetailList()
  1176. //if err != nil {
  1177. // br.Msg = "获取失败"
  1178. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1179. // return
  1180. //}
  1181. //
  1182. //for _, v := range list {
  1183. // item := new(models.CygxActivityMeetDetailLog)
  1184. // item.ActivityId = v.ActivityId
  1185. // item.RealName = v.RealName
  1186. // item.Mobile = v.Mobile
  1187. // item.CompanyName = v.CompanyName
  1188. // item.CompanyId = v.CompanyId
  1189. // item.CreateTime = v.CreateTime
  1190. // newId, err := models.AddCygxActivityMeetDetailLog(item)
  1191. // if err != nil {
  1192. // br.Msg = "同步失败"
  1193. // br.ErrMsg = "新增优化建议失败,Err:" + err.Error()
  1194. // return
  1195. // }
  1196. // fmt.Println(newId)
  1197. //}
  1198. //list, err := models.GetActivityMeetDetailLog()
  1199. //if err != nil {
  1200. // br.Msg = "获取失败"
  1201. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1202. // return
  1203. //}
  1204. //for _, v := range list {
  1205. // condition = ` AND company_name = '` + v.CompanyName + `' `
  1206. // total, err := models.GetActivityMeetDetailLogCount(condition)
  1207. // if err != nil {
  1208. // br.Msg = "获取失败"
  1209. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1210. // return
  1211. // }
  1212. // fmt.Println(v.CompanyName, total)
  1213. // err = models.UpdateActivityMeetDetailLog(v.CompanyName, total)
  1214. // if err != nil {
  1215. // br.Msg = "获取失败"
  1216. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1217. // return
  1218. // }
  1219. //}
  1220. //list, err := models.GetActivityMeetDetailLogByMobile()
  1221. //if err != nil {
  1222. // br.Msg = "获取失败"
  1223. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1224. // return
  1225. //}
  1226. //for _, v := range list {
  1227. // condition = ` AND mobile = '` + v.Mobile + `' `
  1228. // total, err := models.GetActivityMeetDetailLogCount(condition)
  1229. // if err != nil {
  1230. // br.Msg = "获取失败"
  1231. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1232. // return
  1233. // }
  1234. // fmt.Println(v.Mobile, total)
  1235. // err = models.UpdateActivityMeetDetailLogByUser(v.Mobile, total)
  1236. // if err != nil {
  1237. // br.Msg = "获取失败"
  1238. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1239. // return
  1240. // }
  1241. //}
  1242. resp := new(models.ArticleDetailResp)
  1243. br.Ret = 200
  1244. br.Success = true
  1245. br.Msg = "获取成功"
  1246. br.Data = resp
  1247. }
  1248. // @Title 同步策略报告分类
  1249. // @Description 同步策略报告内容接口
  1250. // @Param ArticleIdMd5 query int true "报告ID"
  1251. // @Success 200 {object} models.ArticleDetailResp
  1252. // @router /look/industry [get]
  1253. func (this *ArticleCommonController) Industry() {
  1254. br := new(models.BaseResponse).Init()
  1255. defer func() {
  1256. this.Data["json"] = br
  1257. this.ServeJSON()
  1258. }()
  1259. url := "https://vmp.hzinsights.com/v2api/articles/industry"
  1260. method := "GET"
  1261. client := &nhttp.Client{}
  1262. req, err := nhttp.NewRequest(method, url, nil)
  1263. if err != nil {
  1264. fmt.Println(err)
  1265. return
  1266. }
  1267. req.Header.Add("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag")
  1268. res, err := client.Do(req)
  1269. if err != nil {
  1270. fmt.Println(err)
  1271. return
  1272. }
  1273. defer res.Body.Close()
  1274. body, err := ioutil.ReadAll(res.Body)
  1275. if err != nil {
  1276. fmt.Println(err)
  1277. return
  1278. }
  1279. var pdfResult models.ArticleIndustryApi
  1280. err = json.Unmarshal(body, &pdfResult)
  1281. if err != nil {
  1282. br.Msg = "获取失败"
  1283. br.ErrMsg = "Unmarshal,Err:" + err.Error()
  1284. return
  1285. }
  1286. listData := pdfResult.Data
  1287. //var list []*models.Tactics2
  1288. for _, v := range listData {
  1289. item := new(models.Tactics2)
  1290. for _, v2 := range v.Series {
  1291. fmt.Println(v2.Name)
  1292. item.Body = v2.Name
  1293. //fmt.Println(v.Name, "+", v2.Name, "+", v2.Id)
  1294. //fmt.Println(v.Name, "+", v2.Name, "+", v2.Id)
  1295. //fmt.Println(v.Name, "+", v2.Name, "+", v2.Id)
  1296. }
  1297. //list = append(list, item)
  1298. }
  1299. br.Ret = 200
  1300. br.Success = true
  1301. br.Msg = "获取成功"
  1302. br.Data = string(body)
  1303. }