article.go 39 KB

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