article.go 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  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. url = ""
  886. method := "GET"
  887. client := &nhttp.Client{}
  888. req, err := nhttp.NewRequest(method, url, nil)
  889. if err != nil {
  890. fmt.Println(err)
  891. return
  892. }
  893. req.Header.Add("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag")
  894. res, err := client.Do(req)
  895. if err != nil {
  896. fmt.Println(err)
  897. return
  898. }
  899. defer res.Body.Close()
  900. body, err := ioutil.ReadAll(res.Body)
  901. if err != nil {
  902. fmt.Println(err)
  903. return
  904. }
  905. var pdfResult models.ArticleResultApi
  906. err = json.Unmarshal(body, &pdfResult)
  907. if err != nil {
  908. br.Msg = "获取失败"
  909. br.ErrMsg = "Unmarshal,Err:" + err.Error()
  910. return
  911. }
  912. exitMap := make(map[int]int)
  913. listMap, err := models.GetArticleApiMap()
  914. if err != nil {
  915. br.Msg = "获取失败"
  916. br.ErrMsg = "获取映射关系失败,Err:" + err.Error()
  917. return
  918. }
  919. //新旧分类 反向隐射
  920. for _, v := range listMap {
  921. exitMap[v.Id] = v.OldId
  922. }
  923. listData := pdfResult.Data
  924. var list []*models.Tactics2
  925. var listAuthor []*models.CygxArticleAuthor
  926. for _, v := range listData {
  927. if exitMap[v.SeriesId] > 0 {
  928. item := new(models.Tactics2)
  929. itemAuthor := new(models.CygxArticleAuthor)
  930. item.ArticleId = v.ArticleId
  931. item.Title = v.Title
  932. item.TitleEn = v.TitleEn
  933. if v.Frequency == "日度" {
  934. item.UpdateFrequency = "daily"
  935. } else if v.Frequency == "周度" {
  936. item.UpdateFrequency = "weekly"
  937. } else if v.Frequency == "月度" {
  938. item.UpdateFrequency = "monthly"
  939. } else if v.Frequency == "季度" {
  940. item.UpdateFrequency = "quarterly"
  941. } else if v.Frequency == "年度" {
  942. item.UpdateFrequency = "yearly"
  943. } else {
  944. item.UpdateFrequency = "unknow"
  945. }
  946. item.CreateDate = v.CreateDate
  947. item.PublishDate = v.PublishDate
  948. item.PublishStatus = v.PublishStatus
  949. item.Body = v.Content.Body
  950. item.Abstract = v.Content.Abstract
  951. item.CategoryName = v.Industry.Name
  952. item.CategoryId = exitMap[v.SeriesId]
  953. item.SubCategoryName = v.Series.Name
  954. list = append(list, item)
  955. itemAuthor.ArticleId = v.ArticleId
  956. itemAuthor.Name = v.Author.Name
  957. itemAuthor.Mobile = v.Author.PhoneNumber
  958. listAuthor = append(listAuthor, itemAuthor)
  959. }
  960. }
  961. //同步作者
  962. for _, v := range listAuthor {
  963. count, err := models.GetActivityAuthorCount(v.ArticleId, v.Mobile)
  964. if err != nil {
  965. fmt.Println("GetCount Err:", err.Error())
  966. return
  967. }
  968. if count == 0 {
  969. _, err := models.AddCygxActivityAuthor(v)
  970. if err != nil {
  971. fmt.Println("AddCygxActivityAuthor Err:", err.Error())
  972. return
  973. }
  974. }
  975. }
  976. fmt.Println("同步文章条数:", len(list))
  977. listCustomArticle, err := models.GetCustomArticleId() //手动归类的文章,不替换文章类型
  978. if err != nil {
  979. fmt.Println("GetTacticsList Err:", err.Error())
  980. return
  981. }
  982. listGetMatchTypeName, errMatch := models.GetMatchTypeNamenNotNull() //手动归类的文章,不替换文章类型
  983. if errMatch != nil {
  984. fmt.Println("GetTacticsList Err:", errMatch.Error())
  985. return
  986. }
  987. fmt.Println("list len:", len(list))
  988. summaryCategoryIds := "28,32,45,50,57,62,72,74,79,84,86,88,90,93,95,96" //纪要库的文章类型categoty_id
  989. listSummary := strings.Split(summaryCategoryIds, ",")
  990. 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
  991. listNoSummaryArticleIds := strings.Split(noSummaryArticleIds, ",")
  992. listPermission, errper := models.GetPermissionMappingCategoryID()
  993. if errper != nil {
  994. fmt.Println("GetTacticsList Err:", errper.Error())
  995. return
  996. }
  997. summaryMap := make(map[int]int)
  998. for _, vSum := range listSummary {
  999. vSumInt, _ := strconv.Atoi(vSum)
  1000. summaryMap[vSumInt] = 1
  1001. }
  1002. for k, v := range list {
  1003. //同步匹配类型
  1004. matchTypeName := ""
  1005. for _, vMatch := range listGetMatchTypeName {
  1006. if v.CategoryId == vMatch.CategoryId {
  1007. matchTypeName = vMatch.MatchTypeName
  1008. }
  1009. }
  1010. //是否属于纪要库的数据
  1011. if _, has := summaryMap[v.CategoryId]; has {
  1012. v.IsSummary = 1
  1013. }
  1014. //排除不属于纪要库类型的文章
  1015. for _, vArt := range listNoSummaryArticleIds {
  1016. vArtInt, _ := strconv.Atoi(vArt)
  1017. if v.ArticleId == vArtInt {
  1018. v.IsSummary = 0
  1019. }
  1020. }
  1021. for _, vPer := range listPermission {
  1022. if v.CategoryId == vPer.CategoryId {
  1023. v.IsReport = 1
  1024. }
  1025. }
  1026. if v.IsReport > 0 {
  1027. //是否属于策略 策略自动归类
  1028. //是否属于行业报告 行业报告自动归类
  1029. 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 {
  1030. v.IsClass = 1
  1031. v.ReportType = 1 //是否属于行业报告
  1032. } else {
  1033. v.ReportType = 2 //是否属于产业报告
  1034. }
  1035. }
  1036. v.Department = "弘则权益研究"
  1037. fmt.Println(k, v.ArticleId)
  1038. hh, _ := time.ParseDuration("8h")
  1039. //pDate := publishDate.Add(hh)
  1040. v.PublishDate = v.PublishDate.Add(hh)
  1041. //判断是否已经存在
  1042. if v.ArticleId < 0 {
  1043. fmt.Println("AddCygxArticle Err:")
  1044. return
  1045. }
  1046. count, err := models.GetArticleCountById(v.ArticleId)
  1047. if err != nil && err.Error() != utils.ErrNoRow() {
  1048. fmt.Println("AddCygxArticle Err:", err.Error())
  1049. return
  1050. }
  1051. v.Body = strings.Replace(v.Body, "http://vmp.hzinsights.com", "https://vmp.hzinsights.com", -1)
  1052. expertNumStr, expertContentStr, interviewDateStr, fileLink, bodyReturn := services.BodyAnalysis2(v.Body)
  1053. if strings.Index(v.Body, "报告全文(") > 0 && strings.Index(v.Body, "PDF格式报告下载.pdf") > 0 {
  1054. v.Body = strings.Replace(v.Body, "报告全文(", "", -1)
  1055. v.Body = strings.Replace(v.Body, "PDF格式报告下载.pdf", "", -1)
  1056. v.Body = strings.Replace(v.Body, "):", "", -1)
  1057. }
  1058. var titleNew string
  1059. titleNew = v.Title
  1060. // 7资金流向 、11大类资产 、51每日复盘 、80医药周报、9估值研究
  1061. if v.CategoryId == 7 || v.CategoryId == 11 || v.CategoryId == 51 || v.CategoryId == 9 {
  1062. if v.UpdateFrequency == "daily" {
  1063. var daystr string
  1064. daystr = strconv.Itoa(v.PublishDate.Day())
  1065. if len(daystr) == 1 {
  1066. daystr = "0" + daystr
  1067. }
  1068. titleNew = v.Title + "(" + strconv.Itoa(v.PublishDate.Year())[2:len(strconv.Itoa(v.PublishDate.Year()))-0] + v.PublishDate.Format("01") + daystr + ")"
  1069. } else if v.UpdateFrequency == "weekly" {
  1070. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  1071. }
  1072. }
  1073. if v.CategoryId == 80 {
  1074. titleNew = v.Title + utils.WeekByDate(v.PublishDate)
  1075. }
  1076. if count > 0 {
  1077. fmt.Println(k, v.ArticleId, "edit")
  1078. var isCustom bool
  1079. bodyText, _ := services.GetReportContentTextSub(v.Body)
  1080. updateParams := make(map[string]interface{})
  1081. //updateParams["Title"] = v.Title
  1082. updateParams["Title"] = titleNew
  1083. updateParams["TitleEn"] = v.TitleEn
  1084. updateParams["UpdateFrequency"] = v.UpdateFrequency
  1085. updateParams["CreateDate"] = v.CreateDate
  1086. updateParams["PublishDate"] = v.PublishDate
  1087. //updateParams["Body"] = html.EscapeString(v.Body)
  1088. updateParams["Body"] = html.EscapeString(bodyReturn)
  1089. updateParams["BodyText"] = bodyText
  1090. updateParams["Abstract"] = html.EscapeString(v.Abstract)
  1091. updateParams["CategoryName"] = v.CategoryName
  1092. for _, vCustom := range listCustomArticle {
  1093. if v.ArticleId == vCustom.ArticleId {
  1094. fmt.Println("手动归类的文章:" + strconv.Itoa(v.ArticleId))
  1095. isCustom = true
  1096. }
  1097. }
  1098. if isCustom == false {
  1099. updateParams["CategoryId"] = v.CategoryId
  1100. updateParams["MatchTypeName"] = matchTypeName
  1101. updateParams["IsSummary"] = v.IsSummary
  1102. updateParams["IsReport"] = v.IsReport
  1103. updateParams["ReportType"] = v.ReportType
  1104. updateParams["SubCategoryName"] = v.SubCategoryName
  1105. }
  1106. //updateParams["CategoryId"] = v.CategoryId
  1107. updateParams["PublishStatus"] = v.PublishStatus
  1108. updateParams["ExpertBackground"] = expertContentStr
  1109. updateParams["ExpertNumber"] = expertNumStr
  1110. updateParams["InterviewDate"] = interviewDateStr
  1111. //updateParams["IsClass"] = v.IsClass
  1112. if v.Department != "弘则权益研究" {
  1113. v.Department = "弘则权益研究"
  1114. }
  1115. updateParams["Department"] = v.Department
  1116. updateParams["FileLink"] = fileLink
  1117. whereParam := map[string]interface{}{"article_id": v.ArticleId}
  1118. err = models.UpdateByExpr(models.CygxArticle{}, whereParam, updateParams)
  1119. if err != nil {
  1120. fmt.Println("UpdateByExpr Err:" + err.Error())
  1121. }
  1122. } else {
  1123. fmt.Println(k, v.ArticleId, "add")
  1124. item := new(models.CygxArticle)
  1125. articleIdInt := v.ArticleId
  1126. item.ArticleId = articleIdInt
  1127. //item.Title = v.Title
  1128. item.Title = titleNew
  1129. item.TitleEn = v.TitleEn
  1130. item.UpdateFrequency = v.UpdateFrequency
  1131. item.CreateDate = v.CreateDate
  1132. item.PublishDate = v.PublishDate.Format(utils.FormatDateTime)
  1133. //item.Body = html.EscapeString(v.Body)
  1134. item.Body = html.EscapeString(bodyReturn)
  1135. item.Abstract = html.EscapeString(v.Abstract)
  1136. item.CategoryName = v.CategoryName
  1137. item.SubCategoryName = v.SubCategoryName
  1138. item.CategoryId = v.CategoryId
  1139. item.PublishStatus = v.PublishStatus
  1140. item.ExpertBackground = expertContentStr
  1141. item.ExpertNumber = expertNumStr
  1142. item.InterviewDate = interviewDateStr
  1143. item.Department = v.Department
  1144. item.ArticleIdMd5 = utils.MD5(strconv.Itoa(articleIdInt))
  1145. item.IsClass = v.IsClass
  1146. item.IsSummary = v.IsSummary
  1147. item.IsReport = v.IsReport
  1148. item.ReportType = v.ReportType
  1149. item.FileLink = fileLink
  1150. item.MatchTypeName = matchTypeName
  1151. _, err = models.AddCygxArticles(item)
  1152. if err != nil {
  1153. fmt.Println("AddCygxArticle Err:", err.Error())
  1154. return
  1155. }
  1156. }
  1157. }
  1158. br.Ret = 200
  1159. br.Success = true
  1160. br.Msg = "获取成功"
  1161. br.Data = string(body)
  1162. }
  1163. // @Title 同步参会记录
  1164. // @Description 获取报告详情接口
  1165. // @Param ArticleIdMd5 query int true "报告ID"
  1166. // @Success 200 {object} models.ArticleDetailResp
  1167. // @router /look/detaisl [get]
  1168. func (this *ArticleCommonController) Detaisl() {
  1169. br := new(models.BaseResponse).Init()
  1170. defer func() {
  1171. this.Data["json"] = br
  1172. this.ServeJSON()
  1173. }()
  1174. var condition string
  1175. fmt.Println(condition)
  1176. //list, err := models.GetOfflineMeetingDetailList()
  1177. //if err != nil {
  1178. // br.Msg = "获取失败"
  1179. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1180. // return
  1181. //}
  1182. //
  1183. //for _, v := range list {
  1184. // item := new(models.CygxActivityMeetDetailLog)
  1185. // item.ActivityId = v.ActivityId
  1186. // item.RealName = v.RealName
  1187. // item.Mobile = v.Mobile
  1188. // item.CompanyName = v.CompanyName
  1189. // item.CompanyId = v.CompanyId
  1190. // item.CreateTime = v.CreateTime
  1191. // newId, err := models.AddCygxActivityMeetDetailLog(item)
  1192. // if err != nil {
  1193. // br.Msg = "同步失败"
  1194. // br.ErrMsg = "新增优化建议失败,Err:" + err.Error()
  1195. // return
  1196. // }
  1197. // fmt.Println(newId)
  1198. //}
  1199. //list, err := models.GetActivityMeetDetailLog()
  1200. //if err != nil {
  1201. // br.Msg = "获取失败"
  1202. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1203. // return
  1204. //}
  1205. //for _, v := range list {
  1206. // condition = ` AND company_name = '` + v.CompanyName + `' `
  1207. // total, err := models.GetActivityMeetDetailLogCount(condition)
  1208. // if err != nil {
  1209. // br.Msg = "获取失败"
  1210. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1211. // return
  1212. // }
  1213. // fmt.Println(v.CompanyName, total)
  1214. // err = models.UpdateActivityMeetDetailLog(v.CompanyName, total)
  1215. // if err != nil {
  1216. // br.Msg = "获取失败"
  1217. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1218. // return
  1219. // }
  1220. //}
  1221. //list, err := models.GetActivityMeetDetailLogByMobile()
  1222. //if err != nil {
  1223. // br.Msg = "获取失败"
  1224. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1225. // return
  1226. //}
  1227. //for _, v := range list {
  1228. // condition = ` AND mobile = '` + v.Mobile + `' `
  1229. // total, err := models.GetActivityMeetDetailLogCount(condition)
  1230. // if err != nil {
  1231. // br.Msg = "获取失败"
  1232. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1233. // return
  1234. // }
  1235. // fmt.Println(v.Mobile, total)
  1236. // err = models.UpdateActivityMeetDetailLogByUser(v.Mobile, total)
  1237. // if err != nil {
  1238. // br.Msg = "获取失败"
  1239. // br.ErrMsg = "获取失败,Err:" + err.Error()
  1240. // return
  1241. // }
  1242. //}
  1243. resp := new(models.ArticleDetailResp)
  1244. br.Ret = 200
  1245. br.Success = true
  1246. br.Msg = "获取成功"
  1247. br.Data = resp
  1248. }
  1249. // @Title 同步策略报告分类
  1250. // @Description 同步策略报告内容接口
  1251. // @Param ArticleIdMd5 query int true "报告ID"
  1252. // @Success 200 {object} models.ArticleDetailResp
  1253. // @router /look/industry [get]
  1254. func (this *ArticleCommonController) Industry() {
  1255. br := new(models.BaseResponse).Init()
  1256. defer func() {
  1257. this.Data["json"] = br
  1258. this.ServeJSON()
  1259. }()
  1260. url := "https://vmp.hzinsights.com/v2api/articles/industry"
  1261. method := "GET"
  1262. client := &nhttp.Client{}
  1263. req, err := nhttp.NewRequest(method, url, nil)
  1264. if err != nil {
  1265. fmt.Println(err)
  1266. return
  1267. }
  1268. req.Header.Add("Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag")
  1269. res, err := client.Do(req)
  1270. if err != nil {
  1271. fmt.Println(err)
  1272. return
  1273. }
  1274. defer res.Body.Close()
  1275. body, err := ioutil.ReadAll(res.Body)
  1276. if err != nil {
  1277. fmt.Println(err)
  1278. return
  1279. }
  1280. var pdfResult models.ArticleIndustryApi
  1281. err = json.Unmarshal(body, &pdfResult)
  1282. if err != nil {
  1283. br.Msg = "获取失败"
  1284. br.ErrMsg = "Unmarshal,Err:" + err.Error()
  1285. return
  1286. }
  1287. listData := pdfResult.Data
  1288. //var list []*models.Tactics2
  1289. for _, v := range listData {
  1290. item := new(models.Tactics2)
  1291. for _, v2 := range v.Series {
  1292. fmt.Println(v2.Name)
  1293. item.Body = v2.Name
  1294. //fmt.Println(v.Name, "+", v2.Name, "+", v2.Id)
  1295. //fmt.Println(v.Name, "+", v2.Name, "+", v2.Id)
  1296. //fmt.Println(v.Name, "+", v2.Name, "+", v2.Id)
  1297. }
  1298. //list = append(list, item)
  1299. }
  1300. br.Ret = 200
  1301. br.Success = true
  1302. br.Msg = "获取成功"
  1303. br.Data = string(body)
  1304. }