article.go 40 KB

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