report.go 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "html"
  9. "rdluck_tools/paging"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. //报告
  15. type ReportController struct {
  16. BaseAuthController
  17. }
  18. type ReportCommonController struct {
  19. BaseCommonController
  20. }
  21. // @Title 行业报告分类列表接口
  22. // @Description 获取行业报告分类列表接口
  23. // @Param ChartPermissionId query int true "分类ID"
  24. // @Success 200 {object} models.IndustrialManagementList
  25. // @router /home/tradeList [get]
  26. func (this *ReportController) TradeList() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. user := this.User
  33. if user == nil {
  34. br.Msg = "请重新登录"
  35. br.Ret = 408
  36. return
  37. }
  38. uid := user.UserId
  39. ChartPermissionId, _ := this.GetInt("ChartPermissionId")
  40. if ChartPermissionId < 1 {
  41. br.Msg = "请输入分类ID"
  42. return
  43. }
  44. list, err := models.GetTradeAll(ChartPermissionId)
  45. if err != nil {
  46. br.Msg = "获取信息失败"
  47. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  48. return
  49. }
  50. for k, v := range list {
  51. list[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
  52. count, err := models.CheckThisCategoryNewArticleIsRead(uid, v.CategoryId)
  53. if err != nil {
  54. br.Msg = "获取信息失败"
  55. br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
  56. return
  57. }
  58. if count == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.UpdateTime)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.UpdateTime)) {
  59. list[k].IsRed = true
  60. }
  61. }
  62. resp := new(models.TradeReportMappingResp)
  63. resp.List = list
  64. br.Ret = 200
  65. br.Success = true
  66. br.Msg = "获取成功"
  67. br.Data = resp
  68. }
  69. // @Title 产业报告分类列表接口
  70. // @Description 获取产业报告分类列表接口
  71. // @Param ChartPermissionId query int true "分类ID"
  72. // @Param IsNewLabel query string true "是否属于新标签,1是,0否"
  73. // @Param IsDeepLabel query string true "是否属于深标签,1是,0否"
  74. // @Param KeyWord query string true "搜索关键词"
  75. // @Param OrderColumn query int true "排序字段 ,NewTime 最近更新 ,Recommend弘则推荐"
  76. // @Param PageSize query int true "每页数据条数"
  77. // @Param CurrentIndex query int true "当前页页码,从1开始"
  78. // @Success 200 {object} models.IndustrialManagementList
  79. // @router /home/industryList [get]
  80. func (this *ReportController) IndustryList() {
  81. br := new(models.BaseResponse).Init()
  82. defer func() {
  83. this.Data["json"] = br
  84. this.ServeJSON()
  85. }()
  86. user := this.User
  87. if user == nil {
  88. br.Msg = "请重新登录"
  89. br.Ret = 408
  90. return
  91. }
  92. uid := user.UserId
  93. fmt.Println(uid)
  94. ChartPermissionId, _ := this.GetInt("ChartPermissionId")
  95. orderColumn := this.GetString("OrderColumn")
  96. isNewLabel := this.GetString("IsNewLabel")
  97. isDeepLabel := this.GetString("IsDeepLabel")
  98. keyWord := this.GetString("KeyWord")
  99. pageSize, _ := this.GetInt("PageSize")
  100. currentIndex, _ := this.GetInt("CurrentIndex")
  101. var orderSrt string
  102. var condition string
  103. var startSize int
  104. resp := new(models.IndustrialManagementList)
  105. if pageSize <= 0 {
  106. pageSize = utils.PageSize20
  107. }
  108. if currentIndex <= 0 {
  109. currentIndex = 1
  110. }
  111. startSize = paging.StartIndex(currentIndex, pageSize)
  112. if isNewLabel == "1" {
  113. condition += ` AND is_new_label = ` + isNewLabel
  114. }
  115. if isDeepLabel == "1" {
  116. condition += ` AND is_deep_label = ` + isDeepLabel
  117. }
  118. if keyWord != "" {
  119. keyWordArr, err := services.GetIndustryMapNameSliceV2(keyWord)
  120. if err != nil {
  121. br.Msg = "获取信息失败"
  122. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  123. return
  124. }
  125. var conditionkeyWord string
  126. conditionkeyWord += ` subject_names LIKE '%` + keyWord + `%'`
  127. keyWordArr = services.RemoveDuplicatesAndEmpty(keyWordArr)
  128. keyWordLen := len(keyWordArr)
  129. if keyWordLen <= 0 {
  130. keyWordArr = append(keyWordArr, keyWord)
  131. keyWordLen = len(keyWordArr)
  132. }
  133. for _, v := range keyWordArr {
  134. conditionkeyWord += ` OR subject_names LIKE '%` + v + `%'`
  135. }
  136. industrialManagementIds, err := models.GetIndustrialManagementIdsBykeyWord(conditionkeyWord)
  137. if err != nil {
  138. br.Msg = "获取信息失败"
  139. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  140. return
  141. }
  142. if industrialManagementIds == "" {
  143. br.Ret = 200
  144. br.Success = true
  145. br.Msg = "获取成功"
  146. br.Data = resp
  147. return
  148. }
  149. condition += ` AND man.industrial_management_id IN (` + industrialManagementIds + `)`
  150. }
  151. var sqlChartPermissionId string
  152. if ChartPermissionId > 0 {
  153. sqlChartPermissionId += ` AND man_g.industrial_management_id IN ( SELECT industrial_management_id FROM cygx_industrial_management WHERE chart_permission_id = ` + strconv.Itoa(ChartPermissionId) + ` ) `
  154. condition += ` AND man.chart_permission_id IN (` + strconv.Itoa(ChartPermissionId) + `)`
  155. }
  156. //var total int
  157. var list []*models.IndustrialManagement
  158. //totalTopList, errTop := models.GetIndustrialManagemenCountTop(sqlChartPermissionId, uid, condition)
  159. //totalTop := len(totalTopList)
  160. //if errTop != nil {
  161. // br.Msg = "获取信息失败"
  162. // br.ErrMsg = "获取品种信息失败,Err:" + errTop.Error()
  163. // return
  164. //}
  165. //totalNoTopList, errNoTop := models.GetIndustrialManagemenCountNoTop(sqlChartPermissionId, uid, condition)
  166. //totalNoTop := len(totalNoTopList)
  167. //if errNoTop != nil {
  168. // br.Msg = "获取信息失败"
  169. // br.ErrMsg = "获取品种信息失败,Err:" + errNoTop.Error()
  170. // return
  171. //}
  172. total, err := models.GetIndustrialManagementAllCount(condition)
  173. if err != nil {
  174. br.Msg = "获取信息失败"
  175. br.ErrMsg = "获取数量失败,Err:" + err.Error()
  176. return
  177. }
  178. page := paging.GetPaging(currentIndex, pageSize, total)
  179. if orderColumn == "" {
  180. orderColumn = "NewTime"
  181. }
  182. if orderColumn == "NewTime" {
  183. orderSrt = "update_time DESC"
  184. } else {
  185. orderSrt = "man.recommended_index DESC,update_time DESC"
  186. }
  187. //全部都是置顶
  188. //if totalTop >= currentIndex*pageSize {
  189. // listTop, err := models.GetIndustrialManagementTopAll(uid, condition, startSize, pageSize)
  190. // for k, _ := range listTop {
  191. // listTop[k].IsTop = true
  192. // }
  193. // if err != nil {
  194. // br.Msg = "获取信息失败"
  195. // br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  196. // return
  197. // }
  198. // list = listTop
  199. //} else if totalTop < (currentIndex-1)*pageSize { //全部都是不置顶
  200. // listNoTop, err := models.GetIndustrialManagementAll(uid, condition, orderSrt, startSize-totalTop, pageSize)
  201. // if err != nil {
  202. // br.Msg = "获取信息失败"
  203. // br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  204. // return
  205. // }
  206. // list = listNoTop
  207. //} else { //部分置顶,部分不置顶
  208. // listTop, err := models.GetIndustrialManagementTopAll(uid, condition, startSize, pageSize)
  209. // if err != nil {
  210. // br.Msg = "获取信息失败"
  211. // br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  212. // return
  213. // }
  214. // for k, _ := range listTop {
  215. // listTop[k].IsTop = true
  216. // }
  217. // listNoTop, err := models.GetIndustrialManagementAll(uid, condition, orderSrt, 0, pageSize-len(listTop))
  218. // if err != nil {
  219. // br.Msg = "获取信息失败"
  220. // br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  221. // return
  222. // }
  223. // list = append(listTop, listNoTop...)
  224. //}
  225. if ChartPermissionId == 0 {
  226. ChartPermissionId = 20
  227. }
  228. detailHot3, err := models.GetIndustrialManagementHot3(ChartPermissionId)
  229. if err != nil {
  230. br.Msg = "获取信息失败"
  231. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  232. return
  233. }
  234. list, err = models.GetIndustrialManagementAll(uid, condition, orderSrt, startSize, pageSize)
  235. if err != nil {
  236. br.Msg = "获取信息失败"
  237. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  238. return
  239. }
  240. for k, v := range list {
  241. //var analystStr string
  242. //analystList, err := models.GetIndustrialAnalystAll(v.IndustrialManagementId)
  243. //if err != nil {
  244. // br.Msg = "获取信息失败"
  245. // br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  246. // return
  247. //}
  248. industrialSubjectList, err := models.GetIndustrialSubjectAll(v.IndustrialManagementId)
  249. if err != nil {
  250. br.Msg = "获取信息失败"
  251. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  252. return
  253. }
  254. list[k].IndustrialSubjectList = industrialSubjectList
  255. //if len(analystList) > 0 {
  256. // for _, v2 := range analystList {
  257. // analystStr += v2.AnalystName + "/"
  258. // }
  259. // analystStr = strings.TrimRight(analystStr, "/")
  260. //}
  261. //list[k].Analyst = analystStr
  262. list[k].LayoutTime = utils.TimeRemoveHms(v.LayoutTime)
  263. newArtinfo, err := models.GetIndustrialNewArticleDetail(v.IndustrialManagementId)
  264. if err != nil {
  265. br.Msg = "获取信息失败"
  266. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  267. return
  268. }
  269. list[k].UpdateTime = utils.TimeRemoveHms(newArtinfo.PublishDate)
  270. recordCount, err := models.GetUserToArticleCount(uid, newArtinfo.ArticleId)
  271. if err != nil && err.Error() != utils.ErrNoRow() {
  272. br.Msg = "获取信息失败"
  273. br.ErrMsg = "获取信息失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(newArtinfo.ArticleId)
  274. return
  275. }
  276. if recordCount == 0 && user.CreatedTime.Before(utils.StrTimeToTime(newArtinfo.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(newArtinfo.PublishDate)) {
  277. list[k].IsRed = true
  278. }
  279. if v.ArticleReadNum >= detailHot3.ArticleReadNum {
  280. list[k].IsHot = true
  281. }
  282. }
  283. resp.List = list
  284. resp.Paging = page
  285. br.Ret = 200
  286. br.Success = true
  287. br.Msg = "获取成功"
  288. br.Data = resp
  289. }
  290. // @Title 产业下所关联的文章分类列表
  291. // @Description 产业下所关联的文章分类列表接口
  292. // @Param IndustrialManagementId query int true "产业ID"
  293. // @Success 200 {object} models.IndustrialToArticleCategoryListRep
  294. // @router /toArticleCategoryList [get]
  295. func (this *ReportController) ArticleCategoryList() {
  296. br := new(models.BaseResponse).Init()
  297. defer func() {
  298. this.Data["json"] = br
  299. this.ServeJSON()
  300. }()
  301. user := this.User
  302. if user == nil {
  303. br.Msg = "请重新登录"
  304. br.Ret = 408
  305. return
  306. }
  307. uid := user.UserId
  308. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  309. if industrialManagementId < 1 {
  310. br.Msg = "请输入分类ID"
  311. return
  312. }
  313. list, err := models.IndustrialToArticleCategory(industrialManagementId)
  314. if err != nil {
  315. br.Msg = "获取信息失败"
  316. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  317. return
  318. }
  319. for k, v := range list {
  320. recordCount, err := models.IndustrialUserRecordArticleCount(uid, industrialManagementId, v.CategoryId)
  321. if err != nil && err.Error() != utils.ErrNoRow() {
  322. br.Msg = "获取信息失败"
  323. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  324. return
  325. }
  326. Newdetail, err := models.GetNewIndustrialUserRecordArticle(industrialManagementId, v.CategoryId)
  327. if err != nil {
  328. br.Msg = "获取信息失败"
  329. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  330. return
  331. }
  332. if recordCount == 0 && user.CreatedTime.Before(utils.StrTimeToTime(Newdetail.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(Newdetail.PublishDate)) {
  333. list[k].IsRed = true
  334. }
  335. }
  336. detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
  337. if err != nil {
  338. br.Msg = "获取信息失败"
  339. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  340. return
  341. }
  342. resp := new(models.IndustrialToArticleCategoryListRep)
  343. resp.List = list
  344. resp.LayoutTime = utils.TimeRemoveHms(detail.LayoutTime)
  345. resp.IndustryName = detail.IndustryName
  346. resp.IndustrialManagementId = industrialManagementId
  347. br.Ret = 200
  348. br.Success = true
  349. br.Msg = "获取成功"
  350. br.Data = resp
  351. }
  352. // @Title 产业文章列表接口
  353. // @Description 获取产业文章列表接口
  354. // @Param PageSize query int true "每页数据条数"
  355. // @Param CurrentIndex query int true "当前页页码,从1开始"
  356. // @Param CategoryId query int true "分类ID"
  357. // @Param IndustrialManagementId query int true "产业ID"
  358. // @Success 200 {object} models.TacticsListResp
  359. // @router /industry/ArticleList [get]
  360. func (this *ReportController) List() {
  361. br := new(models.BaseResponse).Init()
  362. defer func() {
  363. this.Data["json"] = br
  364. this.ServeJSON()
  365. }()
  366. user := this.User
  367. if user == nil {
  368. br.Msg = "请重新登录"
  369. br.Ret = 408
  370. return
  371. }
  372. uid := user.UserId
  373. pageSize, _ := this.GetInt("PageSize")
  374. currentIndex, _ := this.GetInt("CurrentIndex")
  375. categoryId, _ := this.GetInt("CategoryId")
  376. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  377. var startSize int
  378. if pageSize <= 0 {
  379. pageSize = utils.PageSize20
  380. }
  381. if currentIndex <= 0 {
  382. currentIndex = 1
  383. }
  384. startSize = paging.StartIndex(currentIndex, pageSize)
  385. var pars []interface{}
  386. var total int
  387. resp := new(models.TacticsListResp)
  388. page := paging.GetPaging(currentIndex, pageSize, total)
  389. if categoryId < 1 {
  390. br.Msg = "请输入分类ID"
  391. return
  392. }
  393. if industrialManagementId < 1 {
  394. br.Msg = "请输入产业ID"
  395. return
  396. }
  397. total, err := models.GetReportIndustrialCount(categoryId, industrialManagementId)
  398. if err != nil {
  399. br.Msg = "获取信息失败"
  400. br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
  401. return
  402. }
  403. page = paging.GetPaging(currentIndex, pageSize, total)
  404. list, err := models.GetReportIndustrialList(pars, categoryId, industrialManagementId, uid, startSize, pageSize)
  405. if err != nil {
  406. br.Msg = "获取信息失败"
  407. br.ErrMsg = "获取帖子数据失败,Err:" + err.Error()
  408. return
  409. }
  410. lenList := len(list)
  411. for i := 0; i < lenList; i++ {
  412. item := list[i]
  413. list[i].Body, _ = services.GetReportContentTextSub(item.Body)
  414. //list[i].Abstract = html.UnescapeString(item.Abstract)
  415. list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  416. }
  417. for k, v := range list {
  418. if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  419. list[k].IsRed = true
  420. }
  421. }
  422. resp.List = list
  423. resp.Paging = page
  424. br.Ret = 200
  425. br.Success = true
  426. br.Msg = "获取成功"
  427. br.Data = resp
  428. }
  429. // @Title 置顶/取消置顶
  430. // @Description 置顶
  431. // @Param request body models.CygxIndustryTopRep true "type json string"
  432. // @Success 200
  433. // @router /top [post]
  434. func (this *ReportController) ArticleCollect() {
  435. br := new(models.BaseResponse).Init()
  436. defer func() {
  437. this.Data["json"] = br
  438. this.ServeJSON()
  439. }()
  440. user := this.User
  441. if user == nil {
  442. br.Msg = "请重新登录"
  443. br.Ret = 408
  444. return
  445. }
  446. uid := user.UserId
  447. var req models.CygxIndustryTopRep
  448. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  449. if err != nil {
  450. br.Msg = "参数解析异常!"
  451. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  452. return
  453. }
  454. industrialManagementId := req.IndustrialManagementId
  455. countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
  456. if err != nil {
  457. br.Msg = "获取数据失败!"
  458. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  459. return
  460. }
  461. if countIndustrial == 0 {
  462. br.Msg = "产业不存在!"
  463. br.ErrMsg = "产业ID不存在:" + strconv.Itoa(industrialManagementId)
  464. return
  465. }
  466. count, err := models.GetCygxIndustryTop(uid, industrialManagementId)
  467. if err != nil {
  468. br.Msg = "获取数据失败!"
  469. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  470. return
  471. }
  472. resp := new(models.ArticleCollectResp)
  473. if count <= 0 {
  474. item := new(models.CygxIndustryTop)
  475. item.IndustrialManagementId = req.IndustrialManagementId
  476. item.UserId = uid
  477. item.CreateTime = time.Now()
  478. _, err = models.AddCygxIndustryTop(item)
  479. if err != nil {
  480. br.Msg = "置顶失败"
  481. br.ErrMsg = "置顶失败,Err:" + err.Error()
  482. return
  483. }
  484. br.Msg = "置顶成功"
  485. resp.Status = 1
  486. } else {
  487. err = models.RemoveCygxIndustryTop(uid, industrialManagementId)
  488. if err != nil {
  489. br.Msg = "取消置顶失败"
  490. br.ErrMsg = "取消置顶失败,Err:" + err.Error()
  491. return
  492. }
  493. br.Msg = "已取消置顶"
  494. resp.Status = 2
  495. }
  496. br.Ret = 200
  497. br.Success = true
  498. br.Data = resp
  499. }
  500. // @Title 关注/取消关注产业
  501. // @Description 关注/取消关注 接口
  502. // @Param request body models.CygxIndustryFllowRep true "type json string"
  503. // @Success 200
  504. // @router /fllow [post]
  505. func (this *ReportController) Fllow() {
  506. br := new(models.BaseResponse).Init()
  507. defer func() {
  508. this.Data["json"] = br
  509. this.ServeJSON()
  510. }()
  511. user := this.User
  512. if user == nil {
  513. br.Msg = "请重新登录"
  514. br.Ret = 408
  515. return
  516. }
  517. uid := user.UserId
  518. var req models.CygxIndustryFllowRep
  519. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  520. if err != nil {
  521. br.Msg = "参数解析异常!"
  522. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  523. return
  524. }
  525. industrialManagementId := req.IndustrialManagementId
  526. var condition string
  527. countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
  528. if err != nil {
  529. br.Msg = "获取数据失败!"
  530. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  531. return
  532. }
  533. if countIndustrial == 0 {
  534. br.Msg = "产业不存在!"
  535. br.ErrMsg = "产业ID不存在:" + strconv.Itoa(industrialManagementId)
  536. return
  537. }
  538. count, err := models.GetCountCygxIndustryFllow(uid, industrialManagementId, condition)
  539. if err != nil {
  540. br.Msg = "获取数据失败!"
  541. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  542. return
  543. }
  544. resp := new(models.CygxIndustryFllowResp)
  545. countUser, err := models.GetCountCygxIndustryFllowByUid(uid)
  546. if countUser == 0 {
  547. resp.GoFollow = true
  548. }
  549. if count == 0 {
  550. item := new(models.CygxIndustryFllow)
  551. item.IndustrialManagementId = industrialManagementId
  552. item.UserId = uid
  553. item.Email = user.Email
  554. item.Mobile = user.Mobile
  555. item.CompanyId = user.CompanyId
  556. item.CompanyName = user.CompanyName
  557. item.Type = 1
  558. item.CreateTime = time.Now()
  559. item.ModifyTime = time.Now()
  560. _, err = models.AddCygxIndustryFllow(item)
  561. if err != nil {
  562. br.Msg = "操作失败"
  563. br.ErrMsg = "操作失败,Err:" + err.Error()
  564. return
  565. }
  566. resp.Status = 1
  567. } else {
  568. var doType int
  569. condition = ` AND type = 1`
  570. count, err = models.GetCountCygxIndustryFllow(uid, industrialManagementId, condition)
  571. if err != nil {
  572. br.Msg = "操作失败!"
  573. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  574. return
  575. }
  576. if count == 1 {
  577. resp.Status = 2
  578. doType = 2
  579. } else {
  580. resp.Status = 1
  581. doType = 1
  582. }
  583. err = models.RemoveCygxIndustryFllow(uid, industrialManagementId, doType)
  584. if err != nil {
  585. br.Msg = "操作失败"
  586. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  587. return
  588. }
  589. }
  590. br.Msg = "操作成功"
  591. br.Ret = 200
  592. br.Success = true
  593. br.Data = resp
  594. }
  595. // @Title 产业报告分类关联作者列表接口
  596. // @Description 获取产业报告分类关联作者列表接口
  597. // @Param ChartPermissionId query int true "分类ID"
  598. // @Param PageSize query int true "每页数据条数"
  599. // @Param CurrentIndex query int true "当前页页码,从1开始"
  600. // @Success 200 {object} models.CygxArticleDepartmentList
  601. // @router /industryListByDepartment [get]
  602. func (this *ReportController) IndustryListByDepartment() {
  603. br := new(models.BaseResponse).Init()
  604. defer func() {
  605. this.Data["json"] = br
  606. this.ServeJSON()
  607. }()
  608. user := this.User
  609. if user == nil {
  610. br.Msg = "请重新登录"
  611. br.Ret = 408
  612. return
  613. }
  614. uid := user.UserId
  615. pageSize, _ := this.GetInt("PageSize")
  616. currentIndex, _ := this.GetInt("CurrentIndex")
  617. //chartPermissionId, _ := this.GetInt("ChartPermissionId")
  618. var startSize int
  619. var condition string
  620. //condition = ` AND a.publish_status=1 AND m.chart_permission_id =` + strconv.Itoa(chartPermissionId)
  621. condition = ` AND a.publish_status=1 `
  622. if pageSize <= 0 {
  623. pageSize = utils.PageSize20
  624. }
  625. if currentIndex <= 0 {
  626. currentIndex = 1
  627. }
  628. startSize = paging.StartIndex(currentIndex, pageSize)
  629. total, err := models.GetArticleDepartmentCount(condition)
  630. page := paging.GetPaging(currentIndex, pageSize, total)
  631. resp := new(models.CygxArticleDepartmentList)
  632. userType, _, err := services.GetUserType(user.CompanyId)
  633. if err != nil {
  634. br.Msg = "获取信息失败"
  635. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  636. return
  637. }
  638. if userType == 1 {
  639. resp.Paging = page
  640. br.Ret = 200
  641. br.Success = true
  642. br.Msg = "获取成功"
  643. br.Data = resp
  644. return
  645. }
  646. resp.HaveResearch = true
  647. //获取作者信息,并排序
  648. list, err := models.GetCygxArticleDepartmentList(startSize, pageSize, condition, uid)
  649. if err != nil {
  650. br.Msg = "获取信息失败"
  651. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  652. return
  653. }
  654. for k, v := range list {
  655. artList, err := models.GetArticleByDepartmentId(v.DepartmentId)
  656. if err != nil {
  657. br.Msg = "获取信息失败"
  658. br.ErrMsg = "获取文章信息失败,Err:" + err.Error()
  659. return
  660. }
  661. for k2, v2 := range artList {
  662. subjectNames, err := models.GetSubjectNames(v2.ArticleId)
  663. if err != nil {
  664. br.Msg = "获取失败" + strconv.Itoa(v2.ArticleId)
  665. br.ErrMsg = "获取失败,Err:" + err.Error()
  666. return
  667. }
  668. var subjectNamesNew string
  669. if len(subjectNames) > 0 {
  670. slice := strings.Split(subjectNames, "/")
  671. for k3, v3 := range slice {
  672. if k3 < 4 {
  673. subjectNamesNew += v3 + "/"
  674. }
  675. }
  676. }
  677. industryName, err := models.GetIndustrialNames(v2.ArticleId)
  678. if err != nil && err.Error() != utils.ErrNoRow() {
  679. br.Msg = "获取失败" + strconv.Itoa(v2.ArticleId)
  680. br.ErrMsg = "获取失败,Err:" + err.Error()
  681. return
  682. }
  683. subjectNamesNew = strings.TrimRight(subjectNamesNew, "/")
  684. artList[k2].SubjectName = subjectNamesNew
  685. artList[k2].DepartmentId = v.DepartmentId
  686. if subjectNamesNew == "" {
  687. artList[k2].IndustryName = industryName
  688. } else {
  689. artList[k2].IndustryName = industryName + "-" + subjectNamesNew
  690. }
  691. if artList[k2].IsReport == "1" {
  692. artList[k2].IndustryName = "【观点】" + artList[k2].IndustryName
  693. } else {
  694. artList[k2].IndustryName = "【纪要】" + artList[k2].IndustryName
  695. }
  696. }
  697. list[k].List = artList
  698. if v.FollowNum > 0 {
  699. list[k].IsMyFollow = true
  700. }
  701. }
  702. listnNew, err := models.GetIndustrialSubjectByDepartmentNew()
  703. if err != nil {
  704. br.Msg = "获取信息失败"
  705. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  706. return
  707. }
  708. if len(listnNew) > 0 {
  709. for _, v := range listnNew {
  710. firstStr := strings.Index(v.IndustrialAndSubjectIds, "—")
  711. Management := new(models.IndustrialManagementIdInt)
  712. if firstStr == 0 {
  713. Management.IndustryName = v.IndustryName
  714. } else {
  715. listSub, err := models.GetIndustrialManagementSubjectList(v.ArticleId)
  716. if err != nil {
  717. br.Msg = "获取信息失败"
  718. br.ErrMsg = "获取关联标的列表失败,Err:" + err.Error()
  719. return
  720. }
  721. var subjectNamesNew string
  722. for _, v1 := range listSub {
  723. subjectNamesNew += v1.SubjectName + "/"
  724. }
  725. subjectNamesNew = strings.TrimRight(subjectNamesNew, "/")
  726. Management.IndustryName = subjectNamesNew
  727. }
  728. Management.IndustrialManagementId = v.IndustrialManagementId
  729. Management.ArticleId = v.ArticleId
  730. resp.ListnNew = append(resp.ListnNew, Management)
  731. }
  732. }
  733. resp.List = list
  734. resp.Paging = page
  735. br.Ret = 200
  736. br.Success = true
  737. br.Msg = "获取成功"
  738. br.Data = resp
  739. }
  740. // @Title 关注作者/取消关注作者
  741. // @Description 关注作者/取消关注作者 接口
  742. // @Param request body models.CygxArticleDepartmentId true "type json string"
  743. // @Success 200
  744. // @router /fllowDepartment [post]
  745. func (this *ReportController) FllowDepartment() {
  746. br := new(models.BaseResponse).Init()
  747. defer func() {
  748. this.Data["json"] = br
  749. this.ServeJSON()
  750. }()
  751. user := this.User
  752. if user == nil {
  753. br.Msg = "请重新登录"
  754. br.Ret = 408
  755. return
  756. }
  757. uid := user.UserId
  758. var req models.CygxArticleDepartmentId
  759. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  760. if err != nil {
  761. br.Msg = "参数解析异常!"
  762. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  763. return
  764. }
  765. departmentId := req.DepartmentId
  766. var condition string
  767. countDepartment, err := models.GetDepartmentCount(departmentId)
  768. if err != nil {
  769. br.Msg = "获取数据失败!"
  770. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  771. return
  772. }
  773. if countDepartment == 0 {
  774. br.Msg = "作者不存在!"
  775. br.ErrMsg = "作者ID不存在:" + strconv.Itoa(departmentId)
  776. return
  777. }
  778. countUser, err := models.GetArticleDepartmentFollowByUid(uid)
  779. count, err := models.GetArticleDepartmentFollow(uid, departmentId, condition)
  780. if err != nil {
  781. br.Msg = "获取数据失败!"
  782. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  783. return
  784. }
  785. resp := new(models.CygxArticleDepartmentFollowResp)
  786. if countUser == 0 {
  787. resp.GoFollow = true
  788. }
  789. if count == 0 {
  790. item := new(models.CygxArticleDepartmentFollow)
  791. item.DepartmentId = departmentId
  792. item.UserId = uid
  793. item.Email = user.Email
  794. item.Mobile = user.Mobile
  795. item.CompanyId = user.CompanyId
  796. item.CompanyName = user.CompanyName
  797. item.Type = 1
  798. item.CreateTime = time.Now()
  799. item.ModifyTime = time.Now()
  800. _, err = models.AddArticleDepartmentFollow(item)
  801. if err != nil {
  802. br.Msg = "操作失败"
  803. br.ErrMsg = "操作失败,Err:" + err.Error()
  804. return
  805. }
  806. resp.Status = 1
  807. } else {
  808. var doType int
  809. condition = ` AND type = 1`
  810. count, err = models.GetArticleDepartmentFollow(uid, departmentId, condition)
  811. if err != nil {
  812. br.Msg = "操作失败!"
  813. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  814. return
  815. }
  816. if count == 1 {
  817. resp.Status = 2
  818. doType = 2
  819. } else {
  820. resp.Status = 1
  821. doType = 1
  822. }
  823. err = models.RemoveArticleDepartmentFollow(uid, departmentId, doType)
  824. if err != nil {
  825. br.Msg = "操作失败"
  826. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  827. return
  828. }
  829. }
  830. br.Msg = "操作成功"
  831. br.Ret = 200
  832. br.Success = true
  833. br.Data = resp
  834. }
  835. // @Title 研选文章列表接口
  836. // @Description 获取研选文章列表接口
  837. // @Param PageSize query int true "每页数据条数"
  838. // @Param CurrentIndex query int true "当前页页码,从1开始"
  839. // @Param ArticleId query int true "文章id"
  840. // @Param DepartmentId query int true "作者ID"
  841. // @Param IndustrialManagementId query int true "产业ID"
  842. // @Success 200 {object} models.ReportArticleWhichIndustrialRepList
  843. // @router /industry/reportList [get]
  844. func (this *ReportController) ReportList() {
  845. br := new(models.BaseResponse).Init()
  846. defer func() {
  847. this.Data["json"] = br
  848. this.ServeJSON()
  849. }()
  850. user := this.User
  851. if user == nil {
  852. br.Msg = "请重新登录"
  853. br.Ret = 408
  854. return
  855. }
  856. uid := user.UserId
  857. pageSize, _ := this.GetInt("PageSize")
  858. currentIndex, _ := this.GetInt("CurrentIndex")
  859. departmentId, _ := this.GetInt("DepartmentId")
  860. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  861. articleId, _ := this.GetInt("ArticleId")
  862. var condition string
  863. var startSize int
  864. if pageSize <= 0 {
  865. pageSize = utils.PageSize20
  866. }
  867. if currentIndex <= 0 {
  868. currentIndex = 1
  869. }
  870. startSize = paging.StartIndex(currentIndex, pageSize)
  871. var pars []interface{}
  872. var total int
  873. resp := new(models.ReportArticleWhichIndustrialRepList)
  874. page := paging.GetPaging(currentIndex, pageSize, total)
  875. userType, _, err := services.GetUserType(user.CompanyId)
  876. if err != nil {
  877. br.Msg = "获取信息失败"
  878. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  879. return
  880. }
  881. if userType == 1 {
  882. resp.Paging = page
  883. br.Ret = 200
  884. br.Success = true
  885. br.Msg = "获取成功"
  886. br.Data = resp
  887. return
  888. }
  889. resp.HaveResearch = true
  890. if departmentId > 0 {
  891. condition += ` AND art.department_id = ` + strconv.Itoa(departmentId)
  892. detail, err := models.GetArticleDepartmentDateilById(departmentId)
  893. if err != nil {
  894. br.Msg = "获取信息失败"
  895. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  896. return
  897. }
  898. resp.NickName = detail.NickName
  899. }
  900. if industrialManagementId > 0 {
  901. condition += ` AND m.industrial_management_id = ` + strconv.Itoa(industrialManagementId)
  902. }
  903. if articleId > 0 {
  904. detail, err := models.GetArticleDetailById(articleId)
  905. if err != nil {
  906. br.Msg = "获取信息失败"
  907. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  908. return
  909. }
  910. condition += ` AND art.subject_ids = '` + detail.SubjectIds + `'`
  911. }
  912. total, err = models.GetWhichDepartmentCount(condition)
  913. if err != nil {
  914. br.Msg = "获取信息失败"
  915. br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
  916. return
  917. }
  918. page = paging.GetPaging(currentIndex, pageSize, total)
  919. condition += ` GROUP BY art.article_id ORDER BY art.publish_date DESC`
  920. list, err := models.IndustrialToArticleWhichDepartment(condition, pars, uid, startSize, pageSize)
  921. if err != nil {
  922. br.Msg = "获取失败"
  923. br.ErrMsg = "获取失败,Err:" + err.Error()
  924. return
  925. }
  926. for k, v := range list {
  927. if v.Readnum == 0 {
  928. list[k].IsRed = true
  929. }
  930. list[k].IsResearch = true
  931. subjectNames, err := models.GetSubjectNames(v.ArticleId)
  932. if err != nil {
  933. br.Msg = "获取失败" + strconv.Itoa(v.ArticleId)
  934. br.ErrMsg = "获取失败,Err:" + err.Error()
  935. return
  936. }
  937. var subjectNamesNew string
  938. if len(subjectNames) > 0 {
  939. slice := strings.Split(subjectNames, "/")
  940. for k3, v3 := range slice {
  941. if k3 < 4 {
  942. subjectNamesNew += v3 + "/"
  943. }
  944. }
  945. }
  946. industryName, err := models.GetIndustrialNames(v.ArticleId)
  947. if err != nil && err.Error() != utils.ErrNoRow() {
  948. br.Msg = "获取失败" + strconv.Itoa(v.ArticleId)
  949. br.ErrMsg = "获取失败,Err:" + err.Error()
  950. return
  951. }
  952. subjectNamesNew = strings.TrimRight(subjectNamesNew, "/")
  953. list[k].SubjectName = subjectNamesNew
  954. if subjectNamesNew != "" {
  955. list[k].IndustryName = industryName + "-" + subjectNamesNew
  956. } else {
  957. list[k].IndustryName = industryName
  958. }
  959. resp.IndustryName = industryName
  960. }
  961. resp.List = list
  962. resp.Paging = page
  963. br.Ret = 200
  964. br.Success = true
  965. br.Msg = "获取成功"
  966. br.Data = resp
  967. }
  968. // @Title 研选最新主题关键词文章列表接口
  969. // @Description 获取研选最新主题关键词文章列表接口
  970. // @Param PageSize query int true "每页数据条数"
  971. // @Param CurrentIndex query int true "当前页页码,从1开始"
  972. // @Param ArticleId query int true "文章id"
  973. // @Success 200 {object} models.ReportArticleWhichIndustrialRepList
  974. // @router /industry/reportListNew [get]
  975. func (this *ReportController) ReportListNew() {
  976. br := new(models.BaseResponse).Init()
  977. defer func() {
  978. this.Data["json"] = br
  979. this.ServeJSON()
  980. }()
  981. user := this.User
  982. if user == nil {
  983. br.Msg = "请重新登录"
  984. br.Ret = 408
  985. return
  986. }
  987. uid := user.UserId
  988. pageSize, _ := this.GetInt("PageSize")
  989. currentIndex, _ := this.GetInt("CurrentIndex")
  990. articleId, _ := this.GetInt("ArticleId")
  991. var condition string
  992. var startSize int
  993. if pageSize <= 0 {
  994. pageSize = utils.PageSize20
  995. }
  996. if currentIndex <= 0 {
  997. currentIndex = 1
  998. }
  999. startSize = paging.StartIndex(currentIndex, pageSize)
  1000. var pars []interface{}
  1001. var total int
  1002. resp := new(models.ReportArticleWhichIndustrialRepList)
  1003. page := paging.GetPaging(currentIndex, pageSize, total)
  1004. userType, _, err := services.GetUserType(user.CompanyId)
  1005. if err != nil {
  1006. br.Msg = "获取信息失败"
  1007. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  1008. return
  1009. }
  1010. if userType == 1 {
  1011. resp.Paging = page
  1012. br.Ret = 200
  1013. br.Success = true
  1014. br.Msg = "获取成功"
  1015. br.Data = resp
  1016. return
  1017. }
  1018. resp.HaveResearch = true
  1019. if articleId > 0 {
  1020. detail, err := models.GetArticleDetailById(articleId)
  1021. if err != nil {
  1022. br.Msg = "获取信息失败"
  1023. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1024. return
  1025. }
  1026. firstStr := strings.Index(detail.IndustrialAndSubjectIds, "—")
  1027. if firstStr == 0 {
  1028. condition += ` AND art.industrial_management_id = '` + strconv.Itoa(detail.IndustrialManagementId) + `'`
  1029. } else {
  1030. condition += ` AND art.industrial_and_subject_ids = '` + detail.IndustrialAndSubjectIds + `'`
  1031. }
  1032. }
  1033. total, err = models.GetWhichDepartmentCount(condition)
  1034. if err != nil {
  1035. br.Msg = "获取信息失败"
  1036. br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
  1037. return
  1038. }
  1039. page = paging.GetPaging(currentIndex, pageSize, total)
  1040. condition += ` GROUP BY art.article_id ORDER BY art.publish_date DESC`
  1041. list, err := models.IndustrialToArticleWhichDepartment(condition, pars, uid, startSize, pageSize)
  1042. if err != nil {
  1043. br.Msg = "获取失败"
  1044. br.ErrMsg = "获取失败,Err:" + err.Error()
  1045. return
  1046. }
  1047. for k, v := range list {
  1048. if v.Readnum == 0 {
  1049. list[k].IsRed = true
  1050. }
  1051. list[k].IsResearch = true
  1052. subjectNames, err := models.GetSubjectNames(v.ArticleId)
  1053. if err != nil {
  1054. br.Msg = "获取失败" + strconv.Itoa(v.ArticleId)
  1055. br.ErrMsg = "获取失败,Err:" + err.Error()
  1056. return
  1057. }
  1058. var subjectNamesNew string
  1059. if len(subjectNames) > 0 {
  1060. slice := strings.Split(subjectNames, "/")
  1061. for k3, v3 := range slice {
  1062. if k3 < 4 {
  1063. subjectNamesNew += v3 + "/"
  1064. }
  1065. }
  1066. }
  1067. industryName, err := models.GetIndustrialNames(v.ArticleId)
  1068. if err != nil && err.Error() != utils.ErrNoRow() {
  1069. br.Msg = "获取失败" + strconv.Itoa(v.ArticleId)
  1070. br.ErrMsg = "获取失败,Err:" + err.Error()
  1071. return
  1072. }
  1073. subjectNamesNew = strings.TrimRight(subjectNamesNew, "/")
  1074. list[k].SubjectName = subjectNamesNew
  1075. if subjectNamesNew != "" {
  1076. list[k].IndustryName = industryName + "-" + subjectNamesNew
  1077. } else {
  1078. list[k].IndustryName = industryName
  1079. }
  1080. resp.IndustryName = industryName
  1081. }
  1082. resp.List = list
  1083. resp.Paging = page
  1084. br.Ret = 200
  1085. br.Success = true
  1086. br.Msg = "获取成功"
  1087. br.Data = resp
  1088. }
  1089. // @Title 是否展示绝密内参
  1090. // @Description 获取是否展示绝密内参接口
  1091. // @Param request body models.IsShow true "type json string"
  1092. // @Success 200
  1093. // @router /isShow [get]
  1094. func (this *ReportController) IsShow() {
  1095. br := new(models.BaseResponse).Init()
  1096. defer func() {
  1097. this.Data["json"] = br
  1098. this.ServeJSON()
  1099. }()
  1100. user := this.User
  1101. if user == nil {
  1102. br.Msg = "请重新登录"
  1103. br.Ret = 408
  1104. return
  1105. }
  1106. var resp models.IsShow
  1107. mobile := user.Mobile
  1108. if mobile == "" {
  1109. br.Ret = 200
  1110. br.Success = true
  1111. br.Data = resp
  1112. return
  1113. }
  1114. total, _ := models.GetUserIsAdminCount(mobile)
  1115. if total > 0 {
  1116. resp.IsShow = true
  1117. }
  1118. br.Ret = 200
  1119. br.Success = true
  1120. br.Data = resp
  1121. }
  1122. // @Title 报告精选、本周研究汇总、上周纪要汇总列表
  1123. // @Description 获取报告精选、本周研究汇总、上周纪要汇总列表接口
  1124. // @Param PageSize query int true "每页数据条数"
  1125. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1126. // @Param ReportType string query true "报告类型 ,1报告精选、2本周研究汇总、3上周纪要汇总"
  1127. // @Success 200 {object} models.CygxReportSelectionListPublicRep
  1128. // @router /reportList/byType [get]
  1129. func (this *ReportController) ReportListByType() {
  1130. br := new(models.BaseResponse).Init()
  1131. defer func() {
  1132. this.Data["json"] = br
  1133. this.ServeJSON()
  1134. }()
  1135. user := this.User
  1136. if user == nil {
  1137. br.Msg = "请重新登录"
  1138. br.Ret = 408
  1139. return
  1140. }
  1141. //uid := user.UserId
  1142. pageSize, _ := this.GetInt("PageSize")
  1143. currentIndex, _ := this.GetInt("CurrentIndex")
  1144. reportType := this.GetString("ReportType")
  1145. var condition string
  1146. var startSize int
  1147. if pageSize <= 0 {
  1148. pageSize = utils.PageSize20
  1149. }
  1150. if currentIndex <= 0 {
  1151. currentIndex = 1
  1152. }
  1153. startSize = paging.StartIndex(currentIndex, pageSize)
  1154. var pars []interface{}
  1155. var total int
  1156. resp := new(models.CygxReportSelectionListPublicRep)
  1157. page := paging.GetPaging(currentIndex, pageSize, total)
  1158. var tbdb string
  1159. if reportType == "1" {
  1160. tbdb = "cygx_report_selection"
  1161. } else if reportType == "2" {
  1162. tbdb = "cygx_research_summary"
  1163. } else if reportType == "3" {
  1164. tbdb = "cygx_minutes_summary"
  1165. } else {
  1166. br.Msg = "请选择报告类型"
  1167. return
  1168. }
  1169. fmt.Println(tbdb)
  1170. condition = ` AND publish_status = 1`
  1171. total, err := models.GetCygxReportSelectionPublic(condition, tbdb, pars)
  1172. if err != nil {
  1173. br.Msg = "获取信息失败"
  1174. br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
  1175. return
  1176. }
  1177. page = paging.GetPaging(currentIndex, pageSize, total)
  1178. list, err := models.GetReportSelectionListPublic(condition, tbdb, pars, startSize, pageSize)
  1179. if err != nil {
  1180. br.Msg = "获取失败"
  1181. br.ErrMsg = "获取失败,Err:" + err.Error()
  1182. return
  1183. }
  1184. for k, v := range list {
  1185. if reportType == "1" {
  1186. list[k].Abstract = v.UpdateDescription
  1187. }
  1188. list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format("2006-01-02")
  1189. }
  1190. resp.List = list
  1191. resp.Paging = page
  1192. br.Ret = 200
  1193. br.Success = true
  1194. br.Msg = "获取成功"
  1195. br.Data = resp
  1196. }
  1197. // @Title 获取报告精选详情
  1198. // @Description 获取报告精选详情接口
  1199. // @Param ArticleId query int true "报告ID"
  1200. // @Success 200 {object} models.ReportSelectionLetailResp
  1201. // @router /reportSelection/detail [get]
  1202. func (this *ReportController) Detail() {
  1203. br := new(models.BaseResponse).Init()
  1204. defer func() {
  1205. this.Data["json"] = br
  1206. this.ServeJSON()
  1207. }()
  1208. user := this.User
  1209. if user == nil {
  1210. br.Msg = "请重新登录"
  1211. br.Ret = 408
  1212. return
  1213. }
  1214. uid := user.UserId
  1215. articleId, _ := this.GetInt("ArticleId")
  1216. if articleId < 0 {
  1217. br.Msg = "参数错误"
  1218. br.ErrMsg = "参数错误"
  1219. return
  1220. }
  1221. resp := new(models.ReportSelectionLetailResp)
  1222. detail, err := models.GetCygxReportSelectionInfoById(articleId)
  1223. if err != nil {
  1224. br.Msg = "获取信息失败"
  1225. br.ErrMsg = "报告不存在,Err:" + err.Error() + "articleId:" + strconv.Itoa(articleId)
  1226. return
  1227. }
  1228. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  1229. existMap := make(map[int]int)
  1230. var items []*models.ReportSelectionChartPermission
  1231. listLog, err := models.GetReportSelectionlogListAll(articleId)
  1232. if err != nil {
  1233. br.Msg = "获取失败"
  1234. br.ErrMsg = "获取子类信息失败,Err:" + err.Error()
  1235. return
  1236. }
  1237. //var itemLogs []*models.CygxReportSelectionLogDetail
  1238. for _, v := range listLog {
  1239. item := new(models.ReportSelectionChartPermission)
  1240. if existMap[v.ChartPermissionId] == 0 {
  1241. item.PermissionName = v.PermissionName + "领域深度调研和报告"
  1242. listSonLog, err := models.GetReportSelectionlogSonListAll(articleId, v.ChartPermissionId)
  1243. if err != nil && err.Error() != utils.ErrNoRow() {
  1244. br.Msg = "获取信息失败"
  1245. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1246. return
  1247. }
  1248. for k2, v2 := range listSonLog {
  1249. if v2.IndustrialManagementId != "" {
  1250. listIndustrial, err := models.GetIndustrialByIds(v2.IndustrialManagementId)
  1251. if err != nil && err.Error() != utils.ErrNoRow() {
  1252. br.Msg = "获取信息失败"
  1253. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1254. return
  1255. }
  1256. listSonLog[k2].List = listIndustrial
  1257. }
  1258. }
  1259. item.List = listSonLog
  1260. items = append(items, item)
  1261. //itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)
  1262. }
  1263. existMap[v.ChartPermissionId] = v.ChartPermissionId
  1264. }
  1265. historyRecord := new(models.CygxReportHistoryRecord)
  1266. historyRecord.UserId = uid
  1267. historyRecord.ArticleId = articleId
  1268. historyRecord.CreateTime = time.Now()
  1269. historyRecord.Mobile = user.Mobile
  1270. historyRecord.Email = user.Email
  1271. historyRecord.CompanyId = user.CompanyId
  1272. historyRecord.CompanyName = user.CompanyName
  1273. historyRecord.ReportType = "bgjx"
  1274. go models.AddCygxReportHistoryRecord(historyRecord)
  1275. resp.List = items
  1276. resp.Detail = detail
  1277. br.Ret = 200
  1278. br.Success = true
  1279. br.Msg = "获取成功"
  1280. br.Data = resp
  1281. }
  1282. // @Title 获取本周研究汇总详情
  1283. // @Description 获取本周研究汇总详情接口
  1284. // @Param ArticleId query int true "报告ID"
  1285. // @Success 200 {object} models.ResearchSummaryLetailResp
  1286. // @router /researchSummary/detail [get]
  1287. func (this *ReportController) ResearchDetail() {
  1288. br := new(models.BaseResponse).Init()
  1289. defer func() {
  1290. this.Data["json"] = br
  1291. this.ServeJSON()
  1292. }()
  1293. user := this.User
  1294. if user == nil {
  1295. br.Msg = "请重新登录"
  1296. br.Ret = 408
  1297. return
  1298. }
  1299. uid := user.UserId
  1300. articleId, _ := this.GetInt("ArticleId")
  1301. if articleId < 0 {
  1302. br.Msg = "参数错误"
  1303. br.ErrMsg = "参数错误"
  1304. return
  1305. }
  1306. resp := new(models.ResearchSummaryLetailResp)
  1307. detail, err := models.GetCygxResearchSummaryInfoById(articleId)
  1308. if err != nil {
  1309. br.Msg = "获取信息失败"
  1310. br.ErrMsg = "报告不存在,Err:" + err.Error() + "articleId:" + strconv.Itoa(articleId)
  1311. return
  1312. }
  1313. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  1314. listFirst, err := models.GetResearchSummarylogListFirst(articleId)
  1315. if err != nil {
  1316. br.Msg = "获取失败"
  1317. br.ErrMsg = "获取子类信息失败,Err:" + err.Error()
  1318. return
  1319. }
  1320. for k, v := range listFirst {
  1321. listSecond, err := models.GetResearchSummarylogSonListSecond(articleId, v.Type)
  1322. if err != nil && err.Error() != utils.ErrNoRow() {
  1323. br.Msg = "获取信息失败"
  1324. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1325. return
  1326. }
  1327. for k2, v2 := range listSecond {
  1328. listThird, err := models.GetResearchSummarylogSonListThird(articleId, v2.ChartPermissionId, v.Type)
  1329. if err != nil && err.Error() != utils.ErrNoRow() {
  1330. br.Msg = "获取信息失败"
  1331. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1332. return
  1333. }
  1334. fmt.Println(listThird)
  1335. if len(listThird) > 0 {
  1336. listSecond[k2].List = listThird
  1337. }
  1338. }
  1339. if len(listSecond) > 0 {
  1340. listFirst[k].List = listSecond
  1341. }
  1342. //`description:"类型'SDBG深度报告片篇,’CYDYJY:产业调研纪要’,’SJDP事件点评,’BZCHJH:本周晨会精华’"`
  1343. if v.Type == "SDBG" {
  1344. listFirst[k].ListName = "深度报告"
  1345. } else if v.Type == "BZCHJH" {
  1346. listFirst[k].ListName = "本周晨会精华"
  1347. } else if v.Type == "CYDYJY" {
  1348. listFirst[k].ListName = "产业调研纪要"
  1349. } else {
  1350. listFirst[k].ListName = "事件点评"
  1351. }
  1352. }
  1353. historyRecord := new(models.CygxReportHistoryRecord)
  1354. historyRecord.UserId = uid
  1355. historyRecord.ArticleId = articleId
  1356. historyRecord.CreateTime = time.Now()
  1357. historyRecord.Mobile = user.Mobile
  1358. historyRecord.Email = user.Email
  1359. historyRecord.CompanyId = user.CompanyId
  1360. historyRecord.CompanyName = user.CompanyName
  1361. historyRecord.ReportType = "bzyjhz"
  1362. go models.AddCygxReportHistoryRecord(historyRecord)
  1363. resp.List = listFirst
  1364. resp.Detail = detail
  1365. br.Ret = 200
  1366. br.Success = true
  1367. br.Msg = "获取成功"
  1368. br.Data = resp
  1369. }
  1370. // @Title 上周纪要汇总内容详情
  1371. // @Description 获取上周纪要汇总内容详情接口
  1372. // @Param ArticleId query int true "报告ID"
  1373. // @Success 200 {object} models.MinutesSummaryLetailResp
  1374. // @router /minutesSummary/detail [get]
  1375. func (this *ReportController) MinutesDetail() {
  1376. br := new(models.BaseResponse).Init()
  1377. defer func() {
  1378. this.Data["json"] = br
  1379. this.ServeJSON()
  1380. }()
  1381. user := this.User
  1382. if user == nil {
  1383. br.Msg = "请重新登录"
  1384. br.Ret = 408
  1385. return
  1386. }
  1387. uid := user.UserId
  1388. articleId, _ := this.GetInt("ArticleId")
  1389. if articleId < 0 {
  1390. br.Msg = "参数错误"
  1391. br.ErrMsg = "参数错误"
  1392. return
  1393. }
  1394. resp := new(models.MinutesSummaryLetailResp)
  1395. detail, err := models.GetCygxMinutesSummaryInfoById(articleId)
  1396. if err != nil {
  1397. br.Msg = "获取信息失败"
  1398. br.ErrMsg = "报告不存在,Err:" + err.Error() + "articleId:" + strconv.Itoa(articleId)
  1399. return
  1400. }
  1401. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  1402. listLog, err := models.GetMinutesSummarylogListAll(articleId)
  1403. if err != nil {
  1404. br.Msg = "获取失败"
  1405. br.ErrMsg = "获取子类信息失败,Err:" + err.Error()
  1406. return
  1407. }
  1408. for k, v := range listLog {
  1409. listSonLog, err := models.GetMinutesSummarylogSonListAll(articleId, v.ChartPermissionId)
  1410. if err != nil && err.Error() != utils.ErrNoRow() {
  1411. br.Msg = "获取信息失败"
  1412. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1413. return
  1414. }
  1415. if len(listSonLog) > 0 {
  1416. listLog[k].List = listSonLog
  1417. }
  1418. }
  1419. historyRecord := new(models.CygxReportHistoryRecord)
  1420. historyRecord.UserId = uid
  1421. historyRecord.ArticleId = articleId
  1422. historyRecord.CreateTime = time.Now()
  1423. historyRecord.Mobile = user.Mobile
  1424. historyRecord.Email = user.Email
  1425. historyRecord.CompanyId = user.CompanyId
  1426. historyRecord.CompanyName = user.CompanyName
  1427. historyRecord.ReportType = "szjyhz"
  1428. go models.AddCygxReportHistoryRecord(historyRecord)
  1429. resp.List = listLog
  1430. resp.Detail = detail
  1431. br.Ret = 200
  1432. br.Success = true
  1433. br.Msg = "获取成功"
  1434. br.Data = resp
  1435. }
  1436. // @Title 获取报告详情
  1437. // @Description 获取报告详情接口
  1438. // @Param ArticleId query int true "报告ID"
  1439. // @Success 200 {object} models.RoadshowDetailResp
  1440. // @router /roadshowEssence/detail [get]
  1441. func (this *ReportController) RoadshowDetail() {
  1442. br := new(models.BaseResponse).Init()
  1443. defer func() {
  1444. this.Data["json"] = br
  1445. this.ServeJSON()
  1446. }()
  1447. user := this.User
  1448. if user == nil {
  1449. br.Msg = "请登录"
  1450. br.ErrMsg = "请登录,用户信息为空"
  1451. br.Ret = 408
  1452. return
  1453. }
  1454. uid := user.UserId
  1455. articleId, err := this.GetInt("ArticleId")
  1456. if articleId <= 0 {
  1457. br.Msg = "文章不存在"
  1458. br.ErrMsg = "文章不存在,文章ID错误"
  1459. return
  1460. }
  1461. detail := new(models.ReportDetailRoadshow)
  1462. hasPermission := 0
  1463. hasFree := 0
  1464. //判断是否已经申请过
  1465. applyCount, err := models.GetApplyRecordCount(uid)
  1466. if err != nil && err.Error() != utils.ErrNoRow() {
  1467. br.Msg = "获取信息失败"
  1468. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1469. return
  1470. }
  1471. //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
  1472. if user.CompanyId > 1 {
  1473. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  1474. if err != nil {
  1475. br.Msg = "获取信息失败"
  1476. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  1477. return
  1478. }
  1479. detail, err = models.GetReportRoadshowDetailById(articleId)
  1480. if err != nil {
  1481. br.Msg = "获取信息失败"
  1482. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1483. return
  1484. }
  1485. detail.Body = html.UnescapeString(detail.Body)
  1486. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  1487. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  1488. if companyPermission == "" {
  1489. if applyCount > 0 {
  1490. hasPermission = 5
  1491. } else {
  1492. hasPermission = 2
  1493. }
  1494. hasFree = 2
  1495. goto Loop
  1496. } else {
  1497. hasFree = 1
  1498. var articlePermissionPermissionName string
  1499. articlePermissionPermissionName = detail.CategoryName
  1500. var hasPersion bool
  1501. slice := strings.Split(articlePermissionPermissionName, ",")
  1502. for _, v := range slice {
  1503. if strings.Contains(companyPermission, v) {
  1504. hasPersion = true
  1505. }
  1506. }
  1507. if hasPersion {
  1508. hasPermission = 1
  1509. historyRecord := new(models.CygxArticleHistoryRecord)
  1510. historyRecord.UserId = uid
  1511. historyRecord.ArticleId = articleId
  1512. historyRecord.CreateTime = time.Now()
  1513. historyRecord.Mobile = user.Mobile
  1514. historyRecord.Email = user.Email
  1515. historyRecord.CompanyId = user.CompanyId
  1516. historyRecord.CompanyName = user.CompanyName
  1517. go models.AddCygxArticleHistoryRecord(historyRecord)
  1518. } else { //无该行业权限
  1519. hasPermission = 3
  1520. }
  1521. if hasPermission == 1 {
  1522. key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  1523. if !utils.Rc.IsExist(key) {
  1524. //新增浏览记录
  1525. record := new(models.CygxArticleViewRecord)
  1526. record.UserId = uid
  1527. record.ArticleId = articleId
  1528. record.CreateTime = time.Now()
  1529. record.Mobile = user.Mobile
  1530. record.Email = user.Email
  1531. record.CompanyId = user.CompanyId
  1532. record.CompanyName = user.CompanyName
  1533. go models.AddCygxArticleViewRecord(record)
  1534. utils.Rc.Put(key, 1, 5*time.Second)
  1535. models.ModifyReportLastViewTime(uid)
  1536. }
  1537. }
  1538. }
  1539. } else { //潜在客户
  1540. if applyCount > 0 {
  1541. hasPermission = 5
  1542. } else {
  1543. hasPermission = 4
  1544. }
  1545. }
  1546. Loop:
  1547. if hasPermission != 1 {
  1548. detail.Body = ""
  1549. detail.Abstract = ""
  1550. }
  1551. resp := new(models.RoadshowDetailResp)
  1552. resp.HasPermission = hasPermission
  1553. resp.HasFree = hasFree
  1554. resp.Detail = detail
  1555. br.Ret = 200
  1556. br.Success = true
  1557. br.Msg = "获取成功"
  1558. br.Data = resp
  1559. }