report.go 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_clpt/models"
  7. "hongze/hongze_clpt/services"
  8. "hongze/hongze_clpt/utils"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. // 报告
  14. type ReportController struct {
  15. BaseAuthController
  16. }
  17. type ReportCommonController struct {
  18. BaseCommonController
  19. }
  20. type MobileReportController struct {
  21. BaseAuthMobileController
  22. }
  23. // @Title 行业报告分类列表接口
  24. // @Description 获取行业报告分类列表接口
  25. // @Param ChartPermissionId query int true "分类ID"
  26. // @Success 200 {object} models.TradeReportMappingResp
  27. // @router /tradeList [get]
  28. func (this *MobileReportController) TradeList() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. user := this.User
  35. if user == nil {
  36. br.Msg = "请重新登录"
  37. br.Ret = 408
  38. return
  39. }
  40. fmt.Println(user)
  41. uid := user.UserId
  42. ChartPermissionId, _ := this.GetInt("ChartPermissionId")
  43. if ChartPermissionId < 1 {
  44. br.Msg = "请输入分类ID"
  45. return
  46. }
  47. //var result []*models.SearchItem
  48. var list []*models.TradeReportMapping
  49. var err error
  50. mapCategory := make(map[int]int)
  51. if ChartPermissionId == utils.CE_LUE_ID {
  52. listTrade, errTrade := models.GetReportMappingStrategyHomeAll()
  53. list = listTrade
  54. err = errTrade
  55. if user.Mobile != "" {
  56. //策略的处理
  57. categoryList, err := models.GetCygxXzsChooseCategoryList(user.Mobile)
  58. if err != nil && err.Error() != utils.ErrNoRow() {
  59. br.Msg = "获取信息失败"
  60. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  61. return
  62. }
  63. for _, v := range categoryList {
  64. mapCategory[v.CategoryId] = v.CategoryId
  65. }
  66. }
  67. } else {
  68. listTrade, errTrade := models.GetTradeAll(ChartPermissionId)
  69. err = errTrade
  70. list = listTrade
  71. }
  72. if err != nil {
  73. br.Msg = "获取信息失败"
  74. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  75. return
  76. }
  77. for k, v := range list {
  78. var condition string
  79. var pars []interface{}
  80. //categoryIdSet, errCategory := models.GetdetailByCategoryIdSet(v.CategoryId)
  81. //if errCategory != nil {
  82. // br.Msg = "获取信息失败"
  83. // br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(v.CategoryId)
  84. // return
  85. //}
  86. //if categoryIdSet != "" {
  87. // condition = ` AND a.category_id IN(` + categoryIdSet + `)`
  88. //} else {
  89. // condition = ` AND a.category_id IN(` + strconv.Itoa(v.CategoryId) + `)`
  90. //}
  91. if v.PolymerizationId != "" {
  92. condition = ` AND a.category_id IN(` + v.PolymerizationId + `)`
  93. } else {
  94. condition = ` AND a.category_id IN(` + strconv.Itoa(v.CategoryId) + `)`
  95. }
  96. if ChartPermissionId != utils.CE_LUE_ID {
  97. var pageSize int
  98. //if ChartPermissionId == utils.KE_JI_ID {
  99. // pageSize = 12
  100. //} else {
  101. // pageSize = 3
  102. //}
  103. pageSize = 3
  104. listArticle, err := models.GetHomeList(condition, pars, 0, pageSize)
  105. if err != nil {
  106. br.Msg = "获取信息失败"
  107. br.Msg = "GetHomeList,Err:" + err.Error()
  108. return
  109. }
  110. if len(listArticle) > 0 {
  111. list[k].UpdateTime = utils.StrTimeToTime(listArticle[0].PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  112. count, err := models.CheckThisCategoryNewArticleIsRead(uid, v.CategoryId)
  113. if err != nil {
  114. br.Msg = "获取信息失败"
  115. br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
  116. return
  117. }
  118. if count == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.UpdateTime)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.UpdateTime)) {
  119. list[k].IsRed = true
  120. }
  121. }
  122. list[k].ListArticle = listArticle
  123. } else {
  124. if mapCategory[v.CategoryId] > 0 {
  125. list[k].IsFollow = true
  126. }
  127. list[k].ListArticle = make([]*models.HomeArticle, 0)
  128. }
  129. }
  130. resp := new(models.TradeReportMappingResp)
  131. if len(list) == 0 {
  132. list = make([]*models.TradeReportMapping, 0)
  133. }
  134. resp.List = list
  135. br.Ret = 200
  136. br.Success = true
  137. br.Msg = "获取成功"
  138. br.Data = resp
  139. }
  140. // @Title 产业报告分类列表接口
  141. // @Description 获取产业报告分类列表接口
  142. // @Param ChartPermissionId query int true "分类ID"
  143. // @Param DeepCover query int false "是否选择深度覆盖,1是,0否 不填默认为0"
  144. // @Param RecommendFocus query int false "是否选择推荐关注,1是,0否 不填默认为0"
  145. // @Param PageSize query int true "每页数据条数"
  146. // @Param CurrentIndex query int true "当前页页码,从1开始"
  147. // @Param IsBillboard query bool false "是否属于榜单 是true 否 false"
  148. // @Success 200 {object} models.IndustrialManagementList
  149. // @router /industryList [get]
  150. func (this *MobileReportController) IndustryList() {
  151. br := new(models.BaseResponse).Init()
  152. defer func() {
  153. this.Data["json"] = br
  154. this.ServeJSON()
  155. }()
  156. user := this.User
  157. if user == nil {
  158. br.Msg = "请重新登录"
  159. br.Ret = 408
  160. return
  161. }
  162. uid := user.UserId
  163. ChartPermissionId, _ := this.GetInt("ChartPermissionId")
  164. orderColumn := this.GetString("OrderColumn")
  165. orderColumnNew := this.GetString("OrderColumn")
  166. isNewLabel := this.GetString("IsNewLabel")
  167. isDeepLabel := this.GetString("IsDeepLabel")
  168. pageSize, _ := this.GetInt("PageSize")
  169. currentIndex, _ := this.GetInt("CurrentIndex")
  170. deepCover, _ := this.GetInt("DeepCover")
  171. recommendFocus, _ := this.GetInt("RecommendFocus")
  172. isBillboard, _ := this.GetBool("IsBillboard", false)
  173. var orderSrt string
  174. var condition string
  175. var startSize int
  176. resp := new(models.IndustrialManagementList)
  177. if pageSize <= 0 {
  178. pageSize = utils.PageSize20
  179. }
  180. if currentIndex <= 0 {
  181. currentIndex = 1
  182. }
  183. startSize = paging.StartIndex(currentIndex, pageSize)
  184. if ChartPermissionId > 0 {
  185. condition += ` AND man.chart_permission_id IN (` + strconv.Itoa(ChartPermissionId) + `)`
  186. }
  187. // 获取近一个月产业报告阅读次数最多的产业
  188. var topCond string
  189. var topPars []interface{}
  190. topReadIndustryId := 0
  191. if ChartPermissionId > 0 {
  192. topCond += ` AND chart_permission_id = ?`
  193. topPars = append(topPars, ChartPermissionId)
  194. }
  195. topReadIndustry, e := models.GetTopOneMonthArtReadNumIndustry(topCond, topPars)
  196. if e != nil && e.Error() != utils.ErrNoRow() {
  197. br.Msg = "获取信息失败"
  198. br.ErrMsg = "获取近一个月报告阅读次数最多的产业失败, Err: " + e.Error()
  199. return
  200. }
  201. if topReadIndustry != nil {
  202. topReadIndustryId = topReadIndustry.IndustrialManagementId
  203. }
  204. // 深度覆盖
  205. if deepCover == 1 {
  206. // 查询深标签产业报告数
  207. var deepCondition string
  208. var deepPars []interface{}
  209. deepCondition += ` AND man.is_deep_label = 1`
  210. if ChartPermissionId > 0 {
  211. deepCondition += ` AND man.chart_permission_id = ?`
  212. deepPars = append(deepPars, ChartPermissionId)
  213. }
  214. industryCountList, e := models.GetIndustryArtCountByCondition(deepCondition, deepPars)
  215. if e != nil {
  216. br.Msg = "获取信息失败"
  217. br.ErrMsg = "获取深标签产业报告数失败, Err: " + e.Error()
  218. return
  219. }
  220. deepIdArr := make([]string, 0)
  221. for i := range industryCountList {
  222. if industryCountList[i].ArtNum > 10 {
  223. deepIdArr = append(deepIdArr, strconv.Itoa(industryCountList[i].IndustrialManagementId))
  224. }
  225. }
  226. deepIds := strings.Join(deepIdArr, ",")
  227. if deepIds != "" {
  228. condition = `AND man.industrial_management_id IN (` + deepIds + `)`
  229. }
  230. }
  231. // 推荐关注
  232. if recommendFocus == 1 {
  233. condition += ` AND man.recommended_index >= 80`
  234. }
  235. var list []*models.IndustrialManagement
  236. total, err := models.GetIndustrialManagementAllCount(condition)
  237. if err != nil {
  238. br.Msg = "获取信息失败"
  239. br.ErrMsg = "获取数量失败,Err:" + err.Error()
  240. return
  241. }
  242. if orderColumn == "" {
  243. orderColumn = "NewTime"
  244. }
  245. if orderColumn == "NewTime" {
  246. orderSrt = "update_time DESC"
  247. } else {
  248. orderSrt = "man.recommended_index DESC,update_time DESC"
  249. }
  250. if isBillboard {
  251. // 查询有已归类行业报告的行业IDs
  252. activeIndustryIds, e := models.GetActiveArticleIndustryIds()
  253. if e != nil {
  254. br.Msg = "获取失败"
  255. br.ErrMsg = "获取已归类行业失败, Err:" + e.Error()
  256. return
  257. }
  258. activeIndustryLen := len(activeIndustryIds)
  259. //topNum := pageSize
  260. condition = ""
  261. var parsBd []interface{}
  262. if ChartPermissionId > 0 {
  263. condition += ` AND man.chart_permission_id = ? `
  264. parsBd = append(parsBd, ChartPermissionId)
  265. }
  266. if activeIndustryLen > 0 {
  267. condition += ` AND man.industrial_management_id IN (` + utils.GetOrmInReplace(activeIndustryLen) + `)`
  268. parsBd = append(parsBd, activeIndustryIds)
  269. }
  270. nowTime := time.Now().Local()
  271. startTime := nowTime.AddDate(0, -1, 0)
  272. endTime := nowTime.AddDate(0, 0, -1)
  273. condition += ` AND idf.create_time BETWEEN ? AND ?`
  274. parsBd = append(parsBd, startTime, endTime)
  275. list, e = models.GetTopIndustryFollowData(0, pageSize, condition, parsBd)
  276. if e != nil {
  277. br.Msg = "获取失败"
  278. br.ErrMsg = "获取关注度最高的产业数据失败, Err:" + e.Error()
  279. return
  280. }
  281. } else {
  282. list, err = models.GetIndustrialManagementAll(uid, condition, orderSrt, startSize, pageSize, isBillboard)
  283. if err != nil {
  284. br.Msg = "获取信息失败"
  285. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  286. return
  287. }
  288. }
  289. list, err = services.HandleIndustryList(list, user, "")
  290. if err != nil {
  291. br.Msg = "获取信息失败"
  292. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  293. return
  294. }
  295. industrialIdArr := make([]int, 0)
  296. for k, v := range list {
  297. industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
  298. if topReadIndustryId > 0 && list[k].IndustrialManagementId == topReadIndustryId {
  299. list[k].IsHot = true
  300. }
  301. }
  302. if orderColumnNew != "" {
  303. item := new(models.CygxReportIndustrialSeaarchHistory)
  304. item.UserId = user.UserId
  305. item.Mobile = user.Mobile
  306. item.CompanyId = user.CompanyId
  307. item.CompanyName = user.CompanyName
  308. item.CreateTime = time.Now()
  309. item.IsDeepLabel = isDeepLabel
  310. item.IsNewLabel = isNewLabel
  311. item.ChartPermissionId = ChartPermissionId
  312. if orderColumnNew == "NewTime" {
  313. item.OrderColumn = "0"
  314. } else {
  315. item.OrderColumn = "1"
  316. }
  317. go models.AddCygxReportIndustrialSeaarchHistory(item)
  318. }
  319. if len(list) == 0 {
  320. list = make([]*models.IndustrialManagement, 0)
  321. }
  322. page := paging.GetPaging(currentIndex, pageSize, total)
  323. if isBillboard {
  324. total = len(list)
  325. }
  326. resp.List = list
  327. resp.Paging = page
  328. br.Ret = 200
  329. br.Success = true
  330. br.Msg = "获取成功"
  331. br.Data = resp
  332. }
  333. // @Title 产业下所关联的文章分类列表
  334. // @Description 产业下所关联的文章分类列表接口
  335. // @Param IndustrialManagementId query int true "产业ID"
  336. // @Success 200 {object} models.IndustrialToArticleCategoryListRep
  337. // @router /toArticleCategoryList [get]
  338. func (this *MobileReportController) ArticleCategoryList() {
  339. br := new(models.BaseResponse).Init()
  340. defer func() {
  341. this.Data["json"] = br
  342. this.ServeJSON()
  343. }()
  344. user := this.User
  345. if user == nil {
  346. br.Msg = "请重新登录"
  347. br.Ret = 408
  348. return
  349. }
  350. uid := user.UserId
  351. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  352. if industrialManagementId < 1 {
  353. br.Msg = "请输入分类ID"
  354. return
  355. }
  356. detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
  357. if err != nil {
  358. br.Msg = "获取信息失败"
  359. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  360. return
  361. }
  362. list, err := models.IndustrialToArticleCategory(industrialManagementId, detail.ChartPermissionId)
  363. if err != nil {
  364. br.Msg = "获取信息失败"
  365. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  366. return
  367. }
  368. for k, v := range list {
  369. recordCount, err := models.IndustrialUserRecordArticleCount(uid, industrialManagementId, v.CategoryId)
  370. if err != nil && err.Error() != utils.ErrNoRow() {
  371. br.Msg = "获取信息失败"
  372. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  373. return
  374. }
  375. Newdetail, err := models.GetNewIndustrialUserRecordArticle(industrialManagementId, v.CategoryId)
  376. if err != nil {
  377. br.Msg = "获取信息失败"
  378. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  379. return
  380. }
  381. if Newdetail != nil {
  382. if recordCount == 0 && user.CreatedTime.Before(utils.StrTimeToTime(Newdetail.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(Newdetail.PublishDate)) {
  383. list[k].IsRed = true
  384. }
  385. }
  386. }
  387. //标的列表
  388. industrialSubjectList, err := models.GetIndustrialSubjectAll(industrialManagementId)
  389. if err != nil {
  390. br.Msg = "获取信息失败"
  391. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  392. return
  393. }
  394. videoSimple, au, err := services.GetindustryVideo(user, industrialManagementId)
  395. if err != nil {
  396. br.Msg = "获取失败"
  397. br.ErrMsg = "获取用户权限失败, Err: " + err.Error()
  398. return
  399. }
  400. timeLineItem := models.IndustrialToArticleCategoryRep{
  401. CategoryId: utils.TIME_CATEGORYID,
  402. MatchTypeName: "时间线",
  403. }
  404. timeLineIsRed, err := services.GetShowTimeLineIsRed(user, industrialManagementId)
  405. if err != nil {
  406. br.Msg = "获取失败"
  407. br.ErrMsg = "获取用户权限失败, Err: " + err.Error()
  408. return
  409. }
  410. timeLineItem.IsRed = timeLineIsRed
  411. list = append([]*models.IndustrialToArticleCategoryRep{&timeLineItem}, list...)
  412. resp := new(models.IndustrialToArticleCategoryListRep)
  413. resp.List = list
  414. resp.ListSubject = industrialSubjectList
  415. resp.LayoutTime = utils.TimeRemoveHms(detail.LayoutTime)
  416. resp.IndustryName = detail.IndustryName
  417. resp.IndustrialManagementId = industrialManagementId
  418. if videoSimple != nil && videoSimple.Id > 0 {
  419. resp.IndustryVideo = videoSimple
  420. }
  421. resp.AuthInfo = au
  422. br.Ret = 200
  423. br.Success = true
  424. br.Msg = "获取成功"
  425. br.Data = resp
  426. }
  427. // @Title 根据行业分类获取文章列表
  428. // @Description根据行业分类获取文章列表接口
  429. // @Param PageSize query int true "每页数据条数"
  430. // @Param CurrentIndex query int true "当前页页码,从1开始"
  431. // @Param CategoryId query int true "分类ID"
  432. // @Param IndustrialManagementId query int false "产业ID"
  433. // @Success 200 {object} models.TacticsListResp
  434. // @router /articleList/byCategoryId [get]
  435. func (this *MobileReportController) List() {
  436. br := new(models.BaseResponse).Init()
  437. defer func() {
  438. this.Data["json"] = br
  439. this.ServeJSON()
  440. }()
  441. user := this.User
  442. if user == nil {
  443. br.Msg = "请重新登录"
  444. br.Ret = 408
  445. return
  446. }
  447. //uid := user.UserId
  448. pageSize, _ := this.GetInt("PageSize")
  449. currentIndex, _ := this.GetInt("CurrentIndex")
  450. categoryId, _ := this.GetInt("CategoryId")
  451. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  452. var startSize int
  453. if pageSize <= 0 {
  454. pageSize = utils.PageSize20
  455. }
  456. if currentIndex <= 0 {
  457. currentIndex = 1
  458. }
  459. startSize = paging.StartIndex(currentIndex, pageSize)
  460. var condition string
  461. var pars []interface{}
  462. var total int
  463. resp := new(models.TacticsListResp)
  464. page := paging.GetPaging(currentIndex, pageSize, total)
  465. list := make([]*models.HomeArticle, 0)
  466. if categoryId == utils.TIME_CATEGORYID {
  467. var err error
  468. list, total, err = models.GetTimeLineReportIndustrialList(industrialManagementId, startSize, pageSize)
  469. if err != nil {
  470. br.Msg = "获取信息失败"
  471. br.ErrMsg = "获取产业报告+晨会点评列表,Err:" + err.Error()
  472. return
  473. }
  474. } else {
  475. //获取该产业下所对应的行业图片
  476. var reportType int
  477. if industrialManagementId > 0 {
  478. reportType = 2
  479. } else {
  480. reportType = 1
  481. }
  482. detail, errCategory := models.GetdetailByCategoryIdOne(categoryId, reportType)
  483. if errCategory != nil {
  484. br.Msg = "获取信息失败"
  485. br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  486. return
  487. }
  488. //对应行业的图片
  489. detailChartPermissionUrl, err := models.GetConfigByCode("category_chart_permissionimg_url")
  490. if err != nil {
  491. br.Msg = "获取数据失败"
  492. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  493. return
  494. }
  495. chartPermissionUrlList := strings.Split(detailChartPermissionUrl.ConfigValue, "{|}")
  496. mapChartPermission := make(map[string]string)
  497. var permissionName string
  498. var imgUrlChartPermission string
  499. for _, v := range chartPermissionUrlList {
  500. vslice := strings.Split(v, "_")
  501. permissionName = vslice[0]
  502. imgUrlChartPermission = vslice[len(vslice)-1]
  503. mapChartPermission[permissionName] = imgUrlChartPermission
  504. }
  505. //对应分类的所图片
  506. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  507. if err != nil {
  508. br.Msg = "获取数据失败"
  509. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  510. return
  511. }
  512. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  513. mapCategoryUrl := make(map[string]string)
  514. var categoryIdStr string
  515. var imgUrlChart string
  516. for _, v := range categoryUrlList {
  517. vslice := strings.Split(v, "_")
  518. categoryIdStr = vslice[0]
  519. imgUrlChart = vslice[len(vslice)-1]
  520. mapCategoryUrl[categoryIdStr] = imgUrlChart
  521. }
  522. //condition += ` AND category_id_two=? `
  523. //pars = append(pars, categoryId)
  524. //categoryIdSet, errCategory := models.GetdetailByCategoryIdSet(categoryId)
  525. //if errCategory != nil {
  526. // br.Msg = "获取信息失败"
  527. // br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  528. // return
  529. //}
  530. //fmt.Println(detail.PolymerizationId)
  531. if detail.PolymerizationId != "" {
  532. condition = ` AND category_id IN(` + detail.PolymerizationId + `)`
  533. } else {
  534. categoryIdSet, errCategory := models.GetdetailByCategoryIdSet(categoryId)
  535. if errCategory != nil {
  536. br.Msg = "获取信息失败"
  537. br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  538. return
  539. }
  540. if categoryIdSet != "" {
  541. condition = ` AND category_id IN(` + categoryIdSet + `)`
  542. } else {
  543. condition = ` AND category_id IN(` + strconv.Itoa(categoryId) + `)`
  544. }
  545. //condition = ` AND category_id IN(` + strconv.Itoa(categoryId) + `)`
  546. //condition = ` AND match_type_name = '` + detail.MatchTypeName + `'`
  547. }
  548. if industrialManagementId > 0 {
  549. industrialManageentList, err := models.GetIndustrialArticleGroupManagementByIndustrialManagementId(industrialManagementId)
  550. if err != nil {
  551. br.Msg = "获取信息失败"
  552. br.Msg = "获取产业关联的文章ID失败,GetIndustrialArticleGroupManagementByIndustrialManagementIdErr:" + err.Error()
  553. return
  554. }
  555. articleIdList := make([]string, 0)
  556. for _, v := range industrialManageentList {
  557. articleIdList = append(articleIdList, strconv.Itoa(v.ArticleId))
  558. }
  559. condition += ` AND a.article_id IN ( ` + utils.GetOrmInReplace(len(articleIdList)) + ` ) `
  560. pars = append(pars, articleIdList)
  561. }
  562. total, err = models.GetHomeCount(condition, pars)
  563. if err != nil {
  564. br.Msg = "获取信息失败"
  565. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  566. return
  567. }
  568. list, err = models.GetHomeList(condition, pars, startSize, pageSize)
  569. if err != nil {
  570. br.Msg = "获取信息失败"
  571. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  572. return
  573. }
  574. for k, v := range list {
  575. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  576. if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  577. list[k].IsRed = true
  578. }
  579. }
  580. if categoryId > 0 {
  581. detail, errCategory := models.GetdetailByCategoryId(categoryId)
  582. if errCategory != nil {
  583. br.Msg = "获取信息失败"
  584. br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  585. return
  586. }
  587. resp.MatchTypeName = detail.MatchTypeName
  588. }
  589. resp.CategoryImgUrlPc = mapChartPermission[detail.ChartPermissionName]
  590. }
  591. lenList := len(list)
  592. for i := 0; i < lenList; i++ {
  593. item := list[i]
  594. list[i].Body = ""
  595. list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  596. list[i].Annotation, _ = services.GetReportContentTextSub(item.Annotation)
  597. list[i].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  598. //行业比较研究、资金流向,显示报告的摘要
  599. if resp.MatchTypeName == "行业比较研究" || resp.MatchTypeName == "资金流向" {
  600. list[i].Annotation = list[i].Abstract
  601. }
  602. }
  603. if len(list) == 0 {
  604. list = make([]*models.HomeArticle, 0)
  605. }
  606. page = paging.GetPaging(currentIndex, pageSize, total)
  607. resp.List = list
  608. resp.Paging = page
  609. br.Ret = 200
  610. br.Success = true
  611. br.Msg = "获取成功"
  612. br.Data = resp
  613. }
  614. // @Title 产业关注/取消关注
  615. // @Description 产业关注/取消关注 接口
  616. // @Param request body models.CygxIndustryFllowRep true "type json string"
  617. // @Success 200
  618. // @router /industrial/fllow [post]
  619. func (this *ReportController) IndustrialFllow() {
  620. br := new(models.BaseResponse).Init()
  621. defer func() {
  622. this.Data["json"] = br
  623. this.ServeJSON()
  624. }()
  625. user := this.User
  626. if user == nil {
  627. br.Msg = "请重新登录"
  628. br.Ret = 408
  629. return
  630. }
  631. uid := user.UserId
  632. var req models.CygxIndustryFllowRep
  633. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  634. if err != nil {
  635. br.Msg = "参数解析异常!"
  636. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  637. return
  638. }
  639. industrialManagementId := req.IndustrialManagementId
  640. var condition string
  641. countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
  642. if err != nil {
  643. br.Msg = "获取数据失败!"
  644. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  645. return
  646. }
  647. if countIndustrial == 0 {
  648. br.Msg = "产业不存在!"
  649. br.ErrMsg = "产业ID不存在:" + strconv.Itoa(industrialManagementId)
  650. return
  651. }
  652. count, err := models.GetCountCygxIndustryFllow(industrialManagementId, user.UserId, condition)
  653. if err != nil {
  654. br.Msg = "获取数据失败!"
  655. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  656. return
  657. }
  658. resp := new(models.CygxIndustryFllowResp)
  659. if count == 0 {
  660. item := new(models.CygxIndustryFllow)
  661. item.IndustrialManagementId = industrialManagementId
  662. item.UserId = uid
  663. item.Email = user.Email
  664. item.Mobile = user.Mobile
  665. item.RealName = user.RealName
  666. item.CompanyId = user.CompanyId
  667. item.CompanyName = user.CompanyName
  668. item.Type = 1
  669. item.CreateTime = time.Now()
  670. item.ModifyTime = time.Now()
  671. _, err = models.AddCygxIndustryFllow(item)
  672. if err != nil {
  673. br.Msg = "操作失败"
  674. br.ErrMsg = "操作失败,Err:" + err.Error()
  675. return
  676. }
  677. resp.Status = 1
  678. br.Msg = "关注成功"
  679. } else {
  680. err = models.RemoveCygxIndustryFllow(uid, industrialManagementId)
  681. if err != nil {
  682. br.Msg = "操作失败"
  683. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  684. return
  685. }
  686. resp.Status = 2
  687. br.Msg = "已取消关注"
  688. }
  689. //处理是否关注全部赛道字段
  690. go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
  691. br.Ret = 200
  692. br.Success = true
  693. br.Data = resp
  694. }
  695. // @Title 行业关注/取消关注
  696. // @Description 行业关注/取消关注 接口
  697. // @Param request body models.CygxCategoryFllowRep true "type json string"
  698. // @Success 200
  699. // @router /category/fllow [post]
  700. func (this *ReportController) CategoryFllow() {
  701. br := new(models.BaseResponse).Init()
  702. defer func() {
  703. this.Data["json"] = br
  704. this.ServeJSON()
  705. }()
  706. user := this.User
  707. if user == nil {
  708. br.Msg = "请重新登录"
  709. br.Ret = 408
  710. return
  711. }
  712. uid := user.UserId
  713. var req models.CygxCategoryFllowRep
  714. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  715. if err != nil {
  716. br.Msg = "参数解析异常!"
  717. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  718. return
  719. }
  720. categoryId := req.CategoryId
  721. var condition string
  722. countCategory, err := models.GetCategoryCount(categoryId)
  723. if err != nil {
  724. br.Msg = "获取数据失败!"
  725. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  726. return
  727. }
  728. if countCategory == 0 {
  729. br.Msg = "产业不存在!"
  730. br.ErrMsg = "产业ID不存在:" + strconv.Itoa(categoryId)
  731. return
  732. }
  733. count, err := models.GetCountCategoryFllow(categoryId, user.Mobile, condition)
  734. if err != nil {
  735. br.Msg = "获取数据失败!"
  736. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  737. return
  738. }
  739. resp := new(models.CygxIndustryFllowResp)
  740. if count == 0 {
  741. item := new(models.CygxXzsChooseCategory)
  742. item.CategoryId = categoryId
  743. item.UserId = uid
  744. item.Email = user.Email
  745. item.Mobile = user.Mobile
  746. item.RealName = user.RealName
  747. item.CompanyId = user.CompanyId
  748. item.CompanyName = user.CompanyName
  749. item.CreateTime = time.Now()
  750. item.ModifyTime = time.Now()
  751. _, err = models.AddCygxCategoryFllow(item)
  752. if err != nil {
  753. br.Msg = "操作失败"
  754. br.ErrMsg = "操作失败,Err:" + err.Error()
  755. return
  756. }
  757. resp.Status = 1
  758. br.Msg = "关注成功"
  759. } else {
  760. err = models.RemoveCygxCategoryFllow(user.Mobile, categoryId)
  761. if err != nil {
  762. br.Msg = "操作失败"
  763. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  764. return
  765. }
  766. resp.Status = 2
  767. br.Msg = "已取消关注"
  768. }
  769. br.Ret = 200
  770. br.Success = true
  771. br.Data = resp
  772. }
  773. // @Title 报告搜索
  774. // @Description 报告搜索接口
  775. // @Param PageSize query int true "每页数据条数"
  776. // @Param CurrentIndex query int true "当前页页码,从1开始"
  777. // @Param KeyWord query string true "搜索关键词"
  778. // @Param ArticleType query int true "文章类型,1弘则报告、2研选 "
  779. // @Param IsAll query bool true "是否为综合 "
  780. // @Success 200 {object} models.ReoprtSearchResp
  781. // @router /searchReport [get]
  782. func (this *MobileReportController) SearchReport() {
  783. br := new(models.BaseResponse).Init()
  784. defer func() {
  785. this.Data["json"] = br
  786. this.ServeJSON()
  787. }()
  788. user := this.User
  789. if user == nil {
  790. br.Msg = "请重新登录"
  791. br.Ret = 408
  792. return
  793. }
  794. pageSize, _ := this.GetInt("PageSize")
  795. currentIndex, _ := this.GetInt("CurrentIndex")
  796. articleType, _ := this.GetInt("ArticleType", 1)
  797. keyWord := this.GetString("KeyWord")
  798. isAll, _ := this.GetBool("IsAll")
  799. var condition string
  800. var pars []interface{}
  801. //var conditionSql string
  802. var total int
  803. var startSize int
  804. if pageSize <= 0 {
  805. pageSize = utils.PageSize20
  806. }
  807. if isAll {
  808. pageSize = utils.PageSize5
  809. }
  810. if currentIndex <= 0 {
  811. currentIndex = 1
  812. }
  813. startSize = paging.StartIndex(currentIndex, pageSize)
  814. resp := new(models.ReoprtSearchResp)
  815. //匹配报告标题、
  816. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  817. if err != nil {
  818. br.Msg = "获取信息失败"
  819. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  820. return
  821. }
  822. if articleTypeIds == "" {
  823. br.Msg = "获取信息失败"
  824. br.ErrMsg = "研选分类ID不能为空"
  825. return
  826. }
  827. //处理对应的文章类型标签按钮
  828. nameMap, styleMap, err := services.GetArticleTypeMap()
  829. if err != nil {
  830. br.Msg = "获取信息失败"
  831. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  832. return
  833. }
  834. if isAll {
  835. total = utils.PageSize5
  836. conditionHz := ` AND ( a.title LIKE '%` + keyWord + `%' OR a.body LIKE '%` + keyWord + `%' OR a.annotation LIKE '%` + keyWord + `%' OR a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 AND a.article_type_id NOT IN (` + articleTypeIds + `) `
  837. conditionYx := ` AND ( a.title LIKE '%` + keyWord + `%' OR a.body LIKE '%` + keyWord + `%' OR a.annotation LIKE '%` + keyWord + `%' OR a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 AND a.article_type_id IN (` + articleTypeIds + `) `
  838. listHz, err := models.GetArticleResearchListHz(conditionHz, pars, startSize, pageSize, user.UserId)
  839. if err != nil {
  840. br.Msg = "获取信息失败"
  841. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  842. return
  843. }
  844. listYx, err := models.GetArticleResearchList(conditionYx, pars, startSize, pageSize, user.UserId)
  845. if err != nil {
  846. br.Msg = "获取信息失败"
  847. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  848. return
  849. }
  850. listHz, err = services.HandleArticleCategoryImg(listHz, user)
  851. if err != nil {
  852. br.Msg = "获取信息失败"
  853. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  854. return
  855. }
  856. listYx, err = services.HandleArticleCategoryImg(listYx, user)
  857. if err != nil {
  858. br.Msg = "获取信息失败"
  859. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  860. return
  861. }
  862. for _, v := range listHz {
  863. item := models.ArticleResearchResp{
  864. ArticleId: v.ArticleId,
  865. ArticleTypeId: v.ArticleTypeId,
  866. Title: v.Title,
  867. PublishDate: v.PublishDate,
  868. DepartmentId: v.DepartmentId,
  869. NickName: v.NickName,
  870. IsCollect: v.IsCollect,
  871. Pv: v.Pv,
  872. CollectNum: v.CollectNum,
  873. Abstract: v.Abstract,
  874. Annotation: v.Annotation,
  875. ImgUrlPc: v.ImgUrlPc,
  876. ArticleTypeName: nameMap[v.ArticleTypeId],
  877. ButtonStyle: styleMap[v.ArticleTypeId],
  878. List: v.List,
  879. }
  880. resp.ListHz = append(resp.ListHz, &item)
  881. }
  882. for _, v := range listYx {
  883. item := models.ArticleResearchResp{
  884. ArticleId: v.ArticleId,
  885. ArticleTypeId: v.ArticleTypeId,
  886. Title: v.Title,
  887. PublishDate: v.PublishDate,
  888. DepartmentId: v.DepartmentId,
  889. NickName: v.NickName,
  890. IsCollect: v.IsCollect,
  891. Pv: v.Pv,
  892. CollectNum: v.CollectNum,
  893. Abstract: v.Abstract,
  894. Annotation: v.Annotation,
  895. ImgUrlPc: v.ImgUrlPc,
  896. ArticleTypeName: nameMap[v.ArticleTypeId],
  897. ButtonStyle: styleMap[v.ArticleTypeId],
  898. List: v.List,
  899. }
  900. resp.ListYx = append(resp.ListYx, &item)
  901. }
  902. } else {
  903. //condition = `AND ( a.title LIKE '%` + keyWord + `%' OR a.body LIKE '%` + keyWord + `%' OR a.annotation LIKE '%` + keyWord + `%' OR a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
  904. if articleType == 1 {
  905. condition = ` AND ( a.title LIKE '%` + keyWord + `%' OR a.body LIKE '%` + keyWord + `%' OR a.annotation LIKE '%` + keyWord + `%' OR a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 AND a.article_type_id NOT IN (` + articleTypeIds + `) `
  906. total, err = models.GetReoprtSearchCountHz(condition)
  907. } else {
  908. condition = ` AND ( a.title LIKE '%` + keyWord + `%' OR a.body LIKE '%` + keyWord + `%' OR a.annotation LIKE '%` + keyWord + `%' OR a.abstract LIKE '%` + keyWord + `%') AND a.publish_status = 1 AND a.article_type_id IN (` + articleTypeIds + `) `
  909. total, err = models.GetReoprtSearchCountYx(condition)
  910. }
  911. if err != nil {
  912. br.Msg = "获取信息失败"
  913. br.Msg = "获取总数失败,Err:" + err.Error()
  914. return
  915. }
  916. var list []*models.ArticleListResp
  917. //list := new([]models.ArticleResearchResp)
  918. if articleType == 1 {
  919. list, err = models.GetArticleResearchListHz(condition, pars, startSize, pageSize, user.UserId)
  920. } else {
  921. list, err = models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId)
  922. }
  923. if err != nil {
  924. br.Msg = "获取信息失败"
  925. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  926. return
  927. }
  928. //return
  929. list, err = services.HandleArticleCategoryImg(list, user)
  930. if err != nil {
  931. br.Msg = "获取信息失败"
  932. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  933. return
  934. }
  935. for _, v := range list {
  936. item := models.ArticleResearchResp{
  937. ArticleId: v.ArticleId,
  938. ArticleTypeId: v.ArticleTypeId,
  939. Title: v.Title,
  940. PublishDate: v.PublishDate,
  941. DepartmentId: v.DepartmentId,
  942. NickName: v.NickName,
  943. IsCollect: v.IsCollect,
  944. Pv: v.Pv,
  945. CollectNum: v.CollectNum,
  946. Abstract: v.Abstract,
  947. Annotation: v.Annotation,
  948. ImgUrlPc: v.ImgUrlPc,
  949. ArticleTypeName: nameMap[v.ArticleTypeId],
  950. ButtonStyle: styleMap[v.ArticleTypeId],
  951. List: v.List,
  952. }
  953. if articleType == 1 {
  954. resp.ListHz = append(resp.ListHz, &item)
  955. } else {
  956. resp.ListYx = append(resp.ListYx, &item)
  957. }
  958. }
  959. }
  960. if keyWord != "" {
  961. go services.AddUserSearchLog(user, keyWord, 5)
  962. }
  963. if len(resp.ListHz) == 0 {
  964. resp.ListHz = make([]*models.ArticleResearchResp, 0)
  965. }
  966. if len(resp.ListYx) == 0 {
  967. resp.ListYx = make([]*models.ArticleResearchResp, 0)
  968. }
  969. page := paging.GetPaging(currentIndex, pageSize, total)
  970. resp.Paging = page
  971. br.Ret = 200
  972. br.Success = true
  973. br.Msg = "获取成功"
  974. br.Data = resp
  975. }
  976. // @Title 资源包搜索
  977. // @Description 资源包搜索接口
  978. // @Param KeyWord query string true "搜索关键词"
  979. // @Success 200 {object} models.SearchResourceResp
  980. // @router /searchResource [get]
  981. func (this *MobileReportController) SearchResource() {
  982. br := new(models.BaseResponse).Init()
  983. defer func() {
  984. this.Data["json"] = br
  985. this.ServeJSON()
  986. }()
  987. user := this.User
  988. if user == nil {
  989. br.Msg = "请重新登录"
  990. br.Ret = 408
  991. return
  992. }
  993. uid := user.UserId
  994. fllowList, err := models.GetUserFllowIndustrialList(uid)
  995. if err != nil {
  996. br.Msg = "获取失败"
  997. br.ErrMsg = "获取失败,GetUserFllowIndustrialList Err:" + err.Error()
  998. return
  999. }
  1000. fllowMap := make(map[int]int)
  1001. if len(fllowList) > 0 {
  1002. for _, v := range fllowList {
  1003. fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
  1004. }
  1005. }
  1006. keyWord := this.GetString("KeyWord")
  1007. var condition string
  1008. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  1009. if err != nil {
  1010. br.Msg = "获取信息失败"
  1011. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  1012. return
  1013. }
  1014. if articleTypeIds == "" {
  1015. br.Msg = "获取信息失败"
  1016. br.ErrMsg = "研选分类ID不能为空"
  1017. return
  1018. }
  1019. condition = ` AND a.publish_status = 1 AND a.article_type_id NOT IN (` + articleTypeIds + `) AND (m.industry_name LIKE '%` + keyWord + `%' OR m.subject_names LIKE '%` + keyWord + `%' ) `
  1020. listHz, err := models.GetSearchResourceList(condition)
  1021. if err != nil {
  1022. br.Msg = "获取信息失败"
  1023. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1024. return
  1025. }
  1026. condition = ` AND a.publish_status = 1 AND a.article_type_id IN (` + articleTypeIds + `) AND (m.industry_name LIKE '%` + keyWord + `%' OR m.subject_names LIKE '%` + keyWord + `%' ) `
  1027. listYx, err := models.GetSearchResourceList(condition)
  1028. if err != nil {
  1029. br.Msg = "获取信息失败"
  1030. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1031. return
  1032. }
  1033. listYx, err = services.HandleIndustryList(listYx, user, "Yx")
  1034. if err != nil {
  1035. br.Msg = "获取信息失败"
  1036. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1037. return
  1038. }
  1039. listHz, err = services.HandleIndustryList(listHz, user, "Hz")
  1040. if err != nil {
  1041. br.Msg = "获取信息失败"
  1042. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1043. return
  1044. }
  1045. if keyWord != "" {
  1046. go services.AddUserSearchLog(user, keyWord, 4)
  1047. }
  1048. resp := new(models.SearchResourceResp)
  1049. if len(listHz) == 0 {
  1050. listHz = make([]*models.IndustrialManagement, 0)
  1051. }
  1052. if len(listYx) == 0 {
  1053. listYx = make([]*models.IndustrialManagement, 0)
  1054. }
  1055. resp.ListHz = listHz
  1056. resp.ListYx = listYx
  1057. br.Ret = 200
  1058. br.Success = true
  1059. br.Msg = "获取成功"
  1060. br.Data = resp
  1061. }
  1062. // @Title 报告搜索、资源包搜索接口
  1063. // @Description 报告搜索、资源包搜索接口接口
  1064. // @Param KeyWord query string true "搜索关键词"
  1065. // @Param PageSize query int true "每页数据条数"
  1066. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1067. // @Param SearchType query int true "1:综合,2:全部"
  1068. // @Success 200 {object} models.SearchReportAndResourceResp
  1069. // @router /searchReportAndResource [get]
  1070. func (this *MobileReportController) SearchReportAndResource() {
  1071. br := new(models.BaseResponse).Init()
  1072. defer func() {
  1073. this.Data["json"] = br
  1074. this.ServeJSON()
  1075. }()
  1076. user := this.User
  1077. if user == nil {
  1078. br.Msg = "请重新登录"
  1079. br.Ret = 408
  1080. return
  1081. }
  1082. //uid := user.UserId
  1083. keyWord := this.GetString("KeyWord")
  1084. pageSize, _ := this.GetInt("PageSize")
  1085. currentIndex, _ := this.GetInt("CurrentIndex")
  1086. searchType, _ := this.GetInt("SearchType")
  1087. var total int
  1088. var startSize int
  1089. if pageSize <= 0 {
  1090. pageSize = utils.PageSize20
  1091. }
  1092. if currentIndex <= 0 {
  1093. currentIndex = 1
  1094. }
  1095. startSize = paging.StartIndex(currentIndex, pageSize)
  1096. page := paging.GetPaging(currentIndex, pageSize, total)
  1097. var condition string
  1098. var conditionSql string
  1099. //匹配报告标题、
  1100. condition = ` AND ( a.title LIKE '%` + keyWord + `%' OR a.body LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
  1101. conditionSql = ` AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + condition + ` OR ( article_type = 'lyjh' ` + condition + ` ) `
  1102. total, err := models.GetReoprtSearchCount(conditionSql)
  1103. if err != nil {
  1104. br.Msg = "获取信息失败"
  1105. br.Msg = "获取总数失败,Err:" + err.Error()
  1106. return
  1107. }
  1108. if searchType == 1 {
  1109. pageSize = utils.PageSize5
  1110. }
  1111. ListHzReport, err := services.GetReoprtSearchListHz(conditionSql, user.UserId, startSize, pageSize)
  1112. if err != nil {
  1113. br.Msg = "获取失败"
  1114. br.ErrMsg = "获取失败,GetReoprtSearchListHz Err:" + err.Error()
  1115. return
  1116. }
  1117. if len(ListHzReport) == 0 {
  1118. ListHzReport = make([]*models.ArticleCollectionResp, 0)
  1119. }
  1120. var conditionOr string
  1121. conditionOr += ` OR ( m.subject_names LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + ` AND publish_status = 1 ) `
  1122. condition = ` AND m.industry_name LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + conditionOr
  1123. listHzResource, err := services.GetSearchResourceListHz(condition, user)
  1124. if err != nil {
  1125. br.Msg = "获取信息失败"
  1126. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1127. return
  1128. }
  1129. resp := new(models.SearchReportAndResourceResp)
  1130. if len(listHzResource) == 0 {
  1131. listHzResource = make([]*models.IndustrialManagement, 0)
  1132. }
  1133. if keyWord != "" {
  1134. go services.AddUserSearchLog(user, keyWord, 5)
  1135. }
  1136. page = paging.GetPaging(currentIndex, pageSize, total)
  1137. resp.Paging = page
  1138. resp.ListHzResource = listHzResource
  1139. resp.ListHzReport = ListHzReport
  1140. br.Ret = 200
  1141. br.Success = true
  1142. br.Msg = "获取成功"
  1143. br.Data = resp
  1144. }
  1145. // @Title 公司速览
  1146. // @Description 公司速览接口
  1147. // @Param ChartPermissionId query int false "分类ID"
  1148. // @Success 200 {object} models.ArticleDataLogoListResp
  1149. // @router /companyList [get]
  1150. func (this *ReportCommonController) CompanyList() {
  1151. br := new(models.BaseResponse).Init()
  1152. defer func() {
  1153. this.Data["json"] = br
  1154. this.ServeJSON()
  1155. }()
  1156. var condition string
  1157. var pars []interface{}
  1158. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  1159. if chartPermissionId > 1 {
  1160. categoryId, err := models.GetCategoryId(chartPermissionId)
  1161. if err != nil && err.Error() != utils.ErrNoRow() {
  1162. br.Msg = "获取信息失败"
  1163. br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  1164. return
  1165. }
  1166. if categoryId != "" {
  1167. condition += ` AND a.category_id IN (` + categoryId + `)`
  1168. }
  1169. }
  1170. condition += ` AND a.type_name = '综述报告' ORDER BY a.modify_time_by_cl DESC `
  1171. list, err := models.CygxArticleDataList(condition, pars)
  1172. if err != nil {
  1173. br.Msg = "获取失败"
  1174. br.ErrMsg = "获取报告封面图片失败, Err:" + err.Error()
  1175. return
  1176. }
  1177. listLogo := make([]*models.ArticleDataLogoResp, 0)
  1178. for i := range list {
  1179. v := list[i]
  1180. comapnyList := services.HandleArticleStock(v.Stock)
  1181. if len(comapnyList) > 1 {
  1182. for kC, vC := range comapnyList {
  1183. sliceCovers := strings.Split(v.Cover, "{|}")
  1184. cover := v.Cover
  1185. if len(sliceCovers) == len(comapnyList) {
  1186. cover = sliceCovers[kC]
  1187. }
  1188. listLogo = append(listLogo, &models.ArticleDataLogoResp{
  1189. ArticleId: v.ArticleId,
  1190. Cover: cover,
  1191. ComapnyList: services.HandleArticleStock(vC.ComapnyName),
  1192. })
  1193. }
  1194. } else {
  1195. listLogo = append(listLogo, &models.ArticleDataLogoResp{
  1196. ArticleId: v.ArticleId,
  1197. Cover: v.Cover,
  1198. ComapnyList: services.HandleArticleStock(v.Stock),
  1199. })
  1200. }
  1201. }
  1202. resp := new(models.ArticleDataLogoListResp)
  1203. resp.List = listLogo
  1204. br.Ret = 200
  1205. br.Success = true
  1206. br.Msg = "获取成功"
  1207. br.Data = resp
  1208. }
  1209. // @Title 时间线
  1210. // @Description 时间线接口
  1211. // @Param PageSize query int true "每页数据条数"
  1212. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1213. // @Param IndustrialManagementId query int false "产业ID"
  1214. // @Success 200 {object} models.TacticsListResp
  1215. // @router /timeline [get]
  1216. func (this *MobileReportController) Timeline() {
  1217. br := new(models.BaseResponse).Init()
  1218. defer func() {
  1219. this.Data["json"] = br
  1220. this.ServeJSON()
  1221. }()
  1222. user := this.User
  1223. if user == nil {
  1224. br.Msg = "请重新登录"
  1225. br.Ret = 408
  1226. return
  1227. }
  1228. pageSize, _ := this.GetInt("PageSize")
  1229. currentIndex, _ := this.GetInt("CurrentIndex")
  1230. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  1231. var startSize int
  1232. if pageSize <= 0 {
  1233. pageSize = utils.PageSize20
  1234. }
  1235. if currentIndex <= 0 {
  1236. currentIndex = 1
  1237. }
  1238. startSize = paging.StartIndex(currentIndex, pageSize)
  1239. var total int
  1240. resp := new(models.TacticsListTimeResp)
  1241. page := paging.GetPaging(currentIndex, pageSize, total)
  1242. list := make([]*models.TimeLineReportItem, 0)
  1243. var err error
  1244. list, total, err = models.GetTimeLineReportIndustrialListTime(user.UserId, industrialManagementId, startSize, pageSize)
  1245. if err != nil {
  1246. br.Msg = "获取信息失败"
  1247. br.ErrMsg = "获取产业报告+晨会点评列表,Err:" + err.Error()
  1248. return
  1249. }
  1250. //查询用户今天是否看过时间线
  1251. count, err := models.GetTimeLineRecordCount(user.UserId, industrialManagementId)
  1252. if err != nil {
  1253. br.Msg = "查询浏览记录数量失败"
  1254. br.ErrMsg = "查询浏览记录数量失败,Err:" + err.Error()
  1255. return
  1256. }
  1257. var recordItem *models.CygxPageHistoryRecord
  1258. if count > 1 {
  1259. recordItem, err = models.GetTimeLineRecordItem(user.UserId, industrialManagementId)
  1260. if err != nil {
  1261. br.Msg = "查询浏览记录失败"
  1262. br.ErrMsg = "查询浏览记录失败,Err:" + err.Error()
  1263. return
  1264. }
  1265. }
  1266. for k, v := range list {
  1267. if v.SubCategoryName != "时间线" && v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  1268. list[k].IsRed = true
  1269. }
  1270. timeLineRed := false
  1271. if count < 2 && v.SubCategoryName == "时间线" {
  1272. timeLineRed = true
  1273. } else if count > 1 && recordItem.CreateTime.Before(utils.StrTimeToTime(v.PublishDate)) {
  1274. timeLineRed = true
  1275. }
  1276. if v.SubCategoryName == "时间线" && timeLineRed {
  1277. list[k].IsRed = true
  1278. }
  1279. if v.VideoUrl != "" {
  1280. list[k].IsHaveVideo = true
  1281. }
  1282. }
  1283. if len(list) == 0 {
  1284. list = make([]*models.TimeLineReportItem, 0)
  1285. }
  1286. page = paging.GetPaging(currentIndex, pageSize, total)
  1287. resp.List = list
  1288. resp.Paging = page
  1289. br.Ret = 200
  1290. br.Success = true
  1291. br.Msg = "获取成功"
  1292. br.Data = resp
  1293. }
  1294. // @Title 文章留言接口
  1295. // @Description 文章留言接口
  1296. // @Param request body models.AddCygxActivityHelpAsk true "type json string"
  1297. // @Success 200 {object} models.TacticsListResp
  1298. // @router /commentAdd [post]
  1299. func (this *ReportController) CommentAdd() {
  1300. br := new(models.BaseResponse).Init()
  1301. defer func() {
  1302. this.Data["json"] = br
  1303. this.ServeJSON()
  1304. }()
  1305. user := this.User
  1306. if user == nil {
  1307. br.Msg = "请重新登录"
  1308. br.Ret = 408
  1309. return
  1310. }
  1311. var req models.AddCygxArticleCommentReq
  1312. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1313. if err != nil {
  1314. br.Msg = "参数解析异常!"
  1315. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1316. return
  1317. }
  1318. if req.ArticleId <= 0 {
  1319. br.Msg = "文章不存在"
  1320. br.ErrMsg = "文章不存在,文章ID错误"
  1321. return
  1322. }
  1323. if req.Content == "" {
  1324. br.Msg = "建议内容不可为空"
  1325. return
  1326. }
  1327. content := req.Content
  1328. if content == "" {
  1329. br.Msg = "留言内容不能为空!"
  1330. return
  1331. }
  1332. //itemToken, err := services.WxGetToken()
  1333. //if err != nil {
  1334. // br.Msg = "GetWxAccessToken Err:" + err.Error()
  1335. // return
  1336. //}
  1337. //if itemToken.AccessToken == "" {
  1338. // br.Msg = "accessToken is empty"
  1339. // return
  1340. //}
  1341. //commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  1342. //if err != nil {
  1343. // br.Msg = "内容校验失败!"
  1344. // br.ErrMsg = "内容校验失败,Err:" + err.Error()
  1345. // return
  1346. //}
  1347. //if commerr.ErrCode != 0 {
  1348. // br.Msg = "内容违规,请重新提交!"
  1349. // br.ErrMsg = "内容违规,Err:" + commerr.ErrMSG
  1350. // return
  1351. //}
  1352. articleId := req.ArticleId
  1353. articleInfo, errInfo := models.GetArticleDetailById(articleId)
  1354. if articleInfo == nil {
  1355. br.Msg = "操作失败"
  1356. br.ErrMsg = "文章ID错误,不存在articleId:" + strconv.Itoa(articleId)
  1357. return
  1358. }
  1359. if errInfo != nil {
  1360. br.Msg = "操作失败"
  1361. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1362. return
  1363. }
  1364. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  1365. if err != nil {
  1366. br.Msg = "提交失败!"
  1367. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1368. return
  1369. }
  1370. if companyDetail == nil {
  1371. br.Msg = "提交失败!"
  1372. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  1373. return
  1374. }
  1375. item := models.CygxArticleComment{
  1376. UserId: user.UserId,
  1377. ArticleId: req.ArticleId,
  1378. CreateTime: time.Now(),
  1379. Mobile: user.Mobile,
  1380. Email: user.Email,
  1381. CompanyId: user.CompanyId,
  1382. CompanyName: companyDetail.CompanyName,
  1383. Content: content,
  1384. Title: articleInfo.Title,
  1385. }
  1386. _, err = models.AddArticleComment(&item)
  1387. if err != nil {
  1388. br.Msg = "提交失败"
  1389. br.ErrMsg = "提交留言失败,Err:" + err.Error()
  1390. return
  1391. }
  1392. services.SendCommentWxTemplateMsg(req, user, articleInfo)
  1393. br.Ret = 200
  1394. br.Success = true
  1395. br.Msg = "提交成功"
  1396. }