article.go 40 KB

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