report.go 46 KB

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