report.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. package logic
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/common"
  6. reportResp "hongze/hongze_open_api/models/response/report"
  7. "hongze/hongze_open_api/models/tables/chart_permission"
  8. "hongze/hongze_open_api/models/tables/chart_permission_chapter_mapping"
  9. "hongze/hongze_open_api/models/tables/chart_permission_search_key_word_mapping"
  10. "hongze/hongze_open_api/models/tables/company_product"
  11. "hongze/hongze_open_api/models/tables/company_report_permission"
  12. "hongze/hongze_open_api/models/tables/daily_base_column"
  13. "hongze/hongze_open_api/models/tables/rddp/classify"
  14. "hongze/hongze_open_api/models/tables/rddp/report"
  15. "hongze/hongze_open_api/models/tables/rddp/report_chapter"
  16. "hongze/hongze_open_api/models/tables/rddp/report_chapter_ticker"
  17. "hongze/hongze_open_api/models/tables/report_chapter_type"
  18. "hongze/hongze_open_api/models/tables/wx_user"
  19. "hongze/hongze_open_api/services/company"
  20. "hongze/hongze_open_api/utils"
  21. "html"
  22. "net/url"
  23. "sort"
  24. "strconv"
  25. "strings"
  26. "time"
  27. )
  28. // GetReportList 获取报告列表
  29. func GetReportList(classifyId int, mobile, keyword string, startSize, pageSize int) (total int, list []*report.ReportList, err error, errMsg string) {
  30. //加密后的手机号
  31. encryptMobile := string(utils.DesBase64Encrypt([]byte(mobile)))
  32. errMsg = `获取失败`
  33. // 获取用户信息
  34. userInfo, err := wx_user.GetWxUserByMobileCountryCode(mobile, "86")
  35. if err != nil {
  36. errMsg = "获取用户信息失败"
  37. return
  38. }
  39. productId := 1
  40. companyProduct, err := company_product.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, productId)
  41. if err != nil {
  42. errMsg = "获取客户信息失败"
  43. return
  44. }
  45. //`is_suspend` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1:暂停,0:启用',
  46. if companyProduct.IsSuspend != 0 {
  47. errMsg = "客户状态异常"
  48. return
  49. }
  50. permissionList, err := company_report_permission.GetPermissionListByCompanyIdAndProductId(userInfo.CompanyId, productId)
  51. if err != nil {
  52. errMsg = "获取客户品种失败"
  53. return
  54. }
  55. if len(permissionList) == 0 {
  56. errMsg = "客户品种异常"
  57. return
  58. }
  59. //客户品种id列表
  60. permissionIdList := make([]int, 0)
  61. for _, v := range permissionList {
  62. permissionIdList = append(permissionIdList, v.ChartPermissionId)
  63. }
  64. // 获取分类信息
  65. classifyInfo, err := classify.GetClassify(classifyId)
  66. if err != nil {
  67. errMsg = "获取分类信息失败"
  68. return
  69. }
  70. var firstClassifyId, secondClassifyId int
  71. firstClassifyId = classifyInfo.ParentId
  72. secondClassifyId = classifyInfo.Id
  73. if classifyInfo.ParentId <= 0 {
  74. firstClassifyId = classifyInfo.Id
  75. secondClassifyId = 0
  76. }
  77. var condition string
  78. var pars []interface{}
  79. // 分类
  80. condition = ` AND state = 2 AND classify_id_first = ? AND classify_id_second = ? `
  81. pars = append(pars, firstClassifyId, secondClassifyId)
  82. //报告名称
  83. if keyword != "" {
  84. condition += ` AND title LIKE ? `
  85. pars = append(pars, `%`+keyword+`%`)
  86. }
  87. total, list, err = report.GetReportList(condition, pars, startSize, pageSize)
  88. encryptMobile = url.QueryEscape(encryptMobile) //转义 +
  89. nonceStr := common.GetRandString(10)
  90. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  91. for _, v := range list {
  92. //if v.Stage > 0 {
  93. // v.Title = fmt.Sprintf("【第%d期】%s", v.Stage, v.Title)
  94. //}
  95. //v.Title = fmt.Sprintf("%s(%s)", v.Title, v.CreateTime.Format(utils.FormatMonthDate))
  96. //跳转地址
  97. postData := make(map[string]string)
  98. reportId := strconv.Itoa(v.Id)
  99. parameter := "mobile=" + encryptMobile + "&report_id=" + reportId + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  100. postData["mobile"] = encryptMobile
  101. postData["report_id"] = reportId
  102. postData["appid"] = utils.ReportAppid
  103. postData["nonce_str"] = nonceStr
  104. postData["timestamp"] = timeUnix
  105. sign := utils.GetSign(postData)
  106. v.HttpUrl = utils.NewResearchReportUrl + "hzsl/report/new/detail?" + parameter + "&sign=" + sign
  107. }
  108. return
  109. }
  110. // GetReportDetail 获取报告详情
  111. func GetReportDetail(reportId int, mobile string) (reportDetail reportResp.ReportDetail, err error, errMsg string) {
  112. encryptMobile := string(utils.DesBase64Encrypt([]byte(mobile)))
  113. errMsg = `获取失败`
  114. // 获取用户信息
  115. userInfo, err := wx_user.GetWxUserByMobileCountryCode(mobile, "86")
  116. if err != nil {
  117. errMsg = "获取用户信息失败"
  118. return
  119. }
  120. // 判断用户状态是否是正常和永续
  121. var productAuthOk bool
  122. productId := 1
  123. companyProduct, err := company_product.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, productId)
  124. if err != nil {
  125. if err.Error() == utils.ErrNoRow() {
  126. err = nil
  127. } else {
  128. errMsg = err.Error()
  129. err = errors.New("查询用户购买产品出错")
  130. return
  131. }
  132. }
  133. if companyProduct != nil {
  134. // 无FICC权限的客户不可见
  135. if companyProduct.CompanyProductId > 0 {
  136. // 已购或者试用用户可见
  137. if strings.Contains("永续,正式", companyProduct.Status) || (companyProduct.Status == "试用" && companyProduct.IsSuspend != 1) {
  138. productAuthOk = true
  139. }
  140. }
  141. }
  142. reportInfo, err := report.GetById(reportId)
  143. if err != nil {
  144. errMsg = "获取报告失败"
  145. return
  146. }
  147. // `state` tinyint(2) DEFAULT '1' COMMENT '1:未发布,2:已发布',
  148. if reportInfo.State != 2 {
  149. errMsg = "报告未发布"
  150. err = errors.New("报告未发布")
  151. return
  152. }
  153. // 判断报告是否属于专栏报告
  154. firstClassify, e := classify.GetClassify(reportInfo.ClassifyIdFirst)
  155. if e != nil {
  156. errMsg = "报告异常"
  157. err = errors.New("报告一级分类有误")
  158. return
  159. }
  160. if firstClassify.IsShow != 1 {
  161. errMsg = "报告异常"
  162. err = errors.New("报告一级分类未发布")
  163. return
  164. }
  165. var authOk bool
  166. var permissionCheckInfo reportResp.PermissionCheckInfo
  167. var vaildWeekTypeIds []int
  168. if reportInfo.ClassifyNameFirst == "晨报" {
  169. authOk, permissionCheckInfo, err = CheckDayReportPermission(userInfo, productAuthOk)
  170. } else if reportInfo.ClassifyNameFirst == "周报" {
  171. authOk, permissionCheckInfo, vaildWeekTypeIds, err = CheckWeekReportPermission(userInfo, productAuthOk)
  172. } else {
  173. authOk, permissionCheckInfo, err = CheckReportPermission(userInfo, reportId, productAuthOk)
  174. }
  175. if err != nil {
  176. return
  177. }
  178. reportItem := reportResp.ReportItem{
  179. ReportId: reportInfo.Id,
  180. ClassifyNameFirst: reportInfo.ClassifyNameFirst,
  181. ClassifyNameSecond: reportInfo.ClassifyNameSecond,
  182. Title: reportInfo.Title,
  183. Abstract: reportInfo.Abstract,
  184. Author: reportInfo.Author,
  185. Frequency: reportInfo.Frequency,
  186. PublishTime: reportInfo.PublishTime,
  187. Stage: reportInfo.Stage,
  188. Content: html.UnescapeString(reportInfo.ContentSub),
  189. VideoUrl: "",
  190. VideoName: reportInfo.VideoName,
  191. VideoSize: reportInfo.VideoSize,
  192. VideoPlaySeconds: reportInfo.VideoPlaySeconds,
  193. VideoImg: "",
  194. ContentSub: "",
  195. BannerUrl: "",
  196. }
  197. if reportInfo.VideoName == "" && reportInfo.VideoUrl != "" {
  198. reportItem.VideoName = reportInfo.Title
  199. }
  200. var reportTypeList []*reportResp.ReportChapterListItem
  201. if reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报" {
  202. //(晨报和周报的banner图)
  203. if reportInfo.ClassifyNameFirst == "晨报" {
  204. reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_day.jpg"
  205. } else {
  206. reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_week.jpg"
  207. }
  208. if authOk {
  209. reportTypeList, err, errMsg = GetChapterListByReport(reportInfo.ClassifyNameFirst, reportInfo.Id, vaildWeekTypeIds, reportInfo.CreateTime)
  210. if err != nil {
  211. return
  212. }
  213. }
  214. } else {
  215. // 音频播放条图片用分类图片
  216. reportItem.VideoImg = utils.HZ_DEFAULT_AVATAR
  217. permissionIds, tmpErr := chart_permission_search_key_word_mapping.GetChartPermissionIdsByKeyWord(reportItem.ClassifyNameSecond)
  218. if tmpErr != nil {
  219. errMsg = tmpErr.Error()
  220. err = errors.New("查询报告权限失败")
  221. return
  222. }
  223. if len(permissionIds) > 0 {
  224. chartPermission, tmpErr := chart_permission.GetListByIds(permissionIds)
  225. if tmpErr != nil {
  226. errMsg = tmpErr.Error()
  227. err = errors.New("查询品种信息失败")
  228. return
  229. }
  230. lenChart := len(chartPermission)
  231. for i := 0; i < lenChart; i++ {
  232. if chartPermission[i].YbImgUrl != "" {
  233. reportItem.VideoImg = utils.ALIYUN_YBIMG_HOST + chartPermission[i].YbImgUrl
  234. break
  235. }
  236. }
  237. }
  238. }
  239. //如果有权限则展示content
  240. //var likeNum int64
  241. //var likeEnabled int8
  242. if authOk {
  243. //go AddViewRecord(userinfo, reportInfo.Id, reportInfo.ClassifyNameFirst, 0)
  244. reportItem.Content = html.UnescapeString(reportInfo.Content)
  245. reportItem.VideoUrl = reportInfo.VideoUrl
  246. //查询点赞数
  247. //likeNum,likeEnabled, _ = services.GetReportLikeByReportIdOldReportId(userinfo.UserID, reportInfo.Id, 0,0,0)
  248. }
  249. encryptMobile = url.QueryEscape(encryptMobile) //转义 +
  250. nonceStr := common.GetRandString(10)
  251. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  252. for _, v := range reportTypeList {
  253. //跳转地址
  254. postData := make(map[string]string)
  255. reportChapterId := strconv.Itoa(v.ReportChapterId)
  256. parameter := "mobile=" + encryptMobile + "&report_chapter_id=" + reportChapterId + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  257. postData["mobile"] = encryptMobile
  258. postData["report_chapter_id"] = reportChapterId
  259. postData["appid"] = utils.ReportAppid
  260. postData["nonce_str"] = nonceStr
  261. postData["timestamp"] = timeUnix
  262. sign := utils.GetSign(postData)
  263. v.HttpUrl = utils.NewResearchReportUrl + "hzsl/report/new/chapter/detail?" + parameter + "&sign=" + sign
  264. }
  265. reportDetail.ReportInfo = reportItem
  266. reportDetail.ReportChapterList = reportTypeList
  267. reportDetail.PermissionCheck = permissionCheckInfo
  268. reportDetail.AuthOk = authOk
  269. //reportDetail.LikeNum = likeNum
  270. //reportDetail.LikeEnabled = likeEnabled
  271. reportDetail.ReportShowType = firstClassify.ShowType
  272. return
  273. }
  274. // GetChapterListByReport 根据报告获取章节列表
  275. func GetChapterListByReport(classifyNameFirst string, reportId int, validWeekTypeIds []int, reportCreateTime time.Time) (reportTypeList reportResp.ReportChapterList, err error, errMsg string) {
  276. defer func() {
  277. if err != nil {
  278. utils.FileLog.Critical(fmt.Sprintf("GetChapterListByReport: err:%s, errMsg:%s", err.Error(), errMsg))
  279. }
  280. }()
  281. //查询有效的章节
  282. typeList, err := report_chapter_type.GetEffectTypes()
  283. if err != nil {
  284. errMsg = "章节类型查询出错"
  285. return
  286. }
  287. if len(typeList) == 0 {
  288. errMsg = "无有效的章节"
  289. err = errors.New("无有效的章节")
  290. return
  291. }
  292. typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
  293. var typeIds []int
  294. newTypeMap := make(map[int]bool)
  295. for _, v := range typeList {
  296. typeMap[v.ReportChapterTypeId] = v
  297. typeIds = append(typeIds, int(v.ReportChapterTypeId))
  298. }
  299. if classifyNameFirst == "周报" {
  300. for _, v := range validWeekTypeIds {
  301. newTypeMap[v] = true
  302. }
  303. }
  304. //获取所有当前研报的章节
  305. chapterList, err := report_chapter.GetListByReportId(reportId, classifyNameFirst)
  306. if err != nil {
  307. errMsg = "章节查询出错"
  308. return
  309. }
  310. if len(chapterList) == 0 {
  311. errMsg = "无有效章节"
  312. err = errors.New("无有效章节")
  313. return
  314. }
  315. for _, item := range chapterList {
  316. if typeItem, ok := typeMap[uint64(item.TypeId)]; ok {
  317. // 如果是周报只展示有权限的章节
  318. if classifyNameFirst == "周报" {
  319. if _, ok1 := newTypeMap[item.TypeId]; !ok1 {
  320. continue
  321. }
  322. }
  323. temp := new(reportResp.ReportChapterListItem)
  324. if reportCreateTime.Before(typeItem.PauseStartTime) || reportCreateTime.After(typeItem.PauseEndTime) {
  325. temp.ReportChapterId = item.ReportChapterId
  326. temp.TypeId = item.TypeId
  327. temp.TypeName = item.TypeName
  328. temp.Title = item.Title
  329. temp.Trend = item.Trend
  330. temp.ReportId = item.ReportId
  331. temp.Sort = typeItem.Sort
  332. temp.PublishTime = item.PublishTime
  333. temp.ReportChapterTypeKey = typeItem.ReportChapterTypeKey
  334. temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
  335. temp.ReportChapterTypeThumb = typeItem.YbIconUrl
  336. reportTypeList = append(reportTypeList, temp)
  337. }
  338. }
  339. }
  340. if len(reportTypeList) > 0 {
  341. sort.Sort(reportTypeList)
  342. }
  343. return
  344. }
  345. // GetChapterDetail 获取章节详情
  346. func GetChapterDetail(mobile string, reportChapterId int) (reportChapterDetail reportResp.ReportChapterDetail, err error, errMsg string) {
  347. defer func() {
  348. if err != nil {
  349. utils.FileLog.Critical(fmt.Sprintf("GetChapterDetail: mobile=%s, err:%s, errMsg:%s", mobile, err.Error(), errMsg))
  350. }
  351. }()
  352. encryptMobile := string(utils.DesBase64Encrypt([]byte(mobile)))
  353. errMsg = `获取失败`
  354. // 获取用户信息
  355. userInfo, err := wx_user.GetWxUserByMobileCountryCode(mobile, "86")
  356. if err != nil {
  357. errMsg = "获取用户信息失败"
  358. return
  359. }
  360. var authOk bool
  361. var productAuthOk bool
  362. var chapterAuthOk bool
  363. var permissionCheckInfo reportResp.PermissionCheckInfo
  364. //查询客户信息(判断客户状态是否是正常和永续)
  365. productId := 1
  366. companyProduct, err := company_product.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, productId)
  367. if err != nil {
  368. if err.Error() == utils.ErrNoRow() {
  369. err = nil
  370. } else {
  371. errMsg = err.Error()
  372. err = errors.New("查询用户购买产品出错")
  373. return
  374. }
  375. }
  376. if companyProduct != nil {
  377. // 无FICC权限的客户不可见
  378. if companyProduct.CompanyProductId > 0 {
  379. // 已购或者试用用户可见
  380. if strings.Contains("永续,正式", companyProduct.Status) || (companyProduct.Status == "试用" && companyProduct.IsSuspend != 1) {
  381. productAuthOk = true
  382. }
  383. }
  384. }
  385. //章节分类
  386. typeIds, err := report_chapter_type.GetEffectTypeID()
  387. if err != nil {
  388. errMsg = err.Error()
  389. err = errors.New("章节类型查询出错")
  390. return
  391. }
  392. if len(typeIds) == 0 {
  393. err = errors.New("无有效的章节类型")
  394. return
  395. }
  396. reportChapter, err := report_chapter.GetContentById(reportChapterId, typeIds)
  397. if err != nil {
  398. errMsg = err.Error()
  399. err = errors.New("章节查询出错")
  400. return
  401. }
  402. if reportChapter.ReportChapterId == 0 {
  403. err = errors.New("章节不存在")
  404. return
  405. }
  406. //报告信息
  407. reportInfo, tErr := report.GetById(reportChapter.ReportId)
  408. if tErr != nil {
  409. errMsg = tErr.Error()
  410. err = errors.New("报告查询出错")
  411. return
  412. }
  413. if reportInfo.Id == 0 {
  414. err = errors.New("报告不存在")
  415. return
  416. }
  417. if reportInfo.ClassifyNameFirst == "周报" && reportChapter.IsEdit != 1 {
  418. err = errors.New("章节未编辑")
  419. return
  420. }
  421. //判断权限
  422. var reportChapterTypeIds []int
  423. if reportInfo.ClassifyNameFirst == "晨报" {
  424. authOk, permissionCheckInfo, err = CheckDayReportPermission(userInfo, productAuthOk)
  425. if err != nil && err.Error() != utils.ErrNoRow() {
  426. errMsg = err.Error()
  427. err = errors.New("权限查询出错")
  428. return
  429. }
  430. } else if reportInfo.ClassifyNameFirst == "周报" {
  431. authOk, permissionCheckInfo, reportChapterTypeIds, err = CheckWeekReportPermission(userInfo, productAuthOk)
  432. if err != nil && err.Error() != utils.ErrNoRow() {
  433. errMsg = err.Error()
  434. err = errors.New("权限查询出错")
  435. return
  436. }
  437. for _, v := range reportChapterTypeIds {
  438. if v == reportChapter.TypeId {
  439. chapterAuthOk = true
  440. }
  441. }
  442. authOk = chapterAuthOk
  443. }
  444. videoImgMap := map[string]string{
  445. "day": "report_list_chen.png",
  446. "week": "report_list_zhou.png",
  447. }
  448. reportChapterItem := reportResp.ReportChapterItem{
  449. ReportChapterId: reportChapter.ReportChapterId,
  450. ReportId: reportChapter.ReportId,
  451. Title: reportChapter.Title,
  452. Abstract: reportChapter.Abstract,
  453. TypeId: reportChapter.TypeId,
  454. TypeName: reportChapter.TypeName,
  455. Trend: "",
  456. ReportChapterTypeName: "",
  457. PublishTime: reportChapter.PublishTime,
  458. Content: "",
  459. ContentSub: html.UnescapeString(reportChapter.ContentSub),
  460. VideoUrl: "",
  461. VideoName: reportChapter.VideoName,
  462. VideoPlaySeconds: reportChapter.VideoPlaySeconds,
  463. VideoSize: reportChapter.VideoSize,
  464. VideoImg: utils.ALIYUN_YBIMG_HOST + videoImgMap[reportChapter.ReportType],
  465. Author: reportChapter.Author,
  466. Stage: reportChapter.Stage,
  467. ClassifyIdFirst: reportChapter.ClassifyIdFirst,
  468. ClassifyNameFirst: reportChapter.ClassifyNameFirst,
  469. }
  470. if reportChapter.VideoUrl != "" && reportChapter.VideoName == "" {
  471. reportChapterItem.VideoName = reportChapter.Title
  472. }
  473. //var likeNum int64
  474. //var likeEnabled int8
  475. //底部菜单切换
  476. var chapterMenu []reportResp.ReportChapterMenu
  477. if authOk {
  478. reportChapterItem.Content = html.UnescapeString(reportChapter.Content)
  479. reportChapterItem.VideoUrl = reportChapter.VideoUrl
  480. //底部菜单切换
  481. if reportInfo.ClassifyNameFirst == "周报" {
  482. chapterMenu, err = GetMenuChapter(reportInfo.Id, reportChapterTypeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime, encryptMobile)
  483. } else {
  484. chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime, encryptMobile)
  485. }
  486. //查询点赞数
  487. //likeNum,likeEnabled, _ = services.GetReportLikeByReportIdOldReportId(user.UserID, reportInfo.Id, reportChapter.ReportChapterId,0,0)
  488. //go AddViewRecord(user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId)
  489. } else {
  490. reportChapterItem.ContentSub = html.UnescapeString(reportChapter.ContentSub)
  491. }
  492. //请求指标数据的参数
  493. tickerDataParams := ``
  494. {
  495. nonceStr := common.GetRandString(10)
  496. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  497. postData := make(map[string]string)
  498. reportChapterIdStr := strconv.Itoa(reportChapterId)
  499. parameter := "report_chapter_id=" + reportChapterIdStr + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  500. postData["mobile"] = encryptMobile
  501. postData["report_chapter_id"] = reportChapterIdStr
  502. postData["appid"] = utils.ReportAppid
  503. postData["nonce_str"] = nonceStr
  504. postData["timestamp"] = timeUnix
  505. sign := utils.GetSign(postData)
  506. tickerDataParams = parameter + "&sign=" + sign
  507. }
  508. reportChapterDetail = reportResp.ReportChapterDetail{
  509. ReportChapterItem: reportChapterItem,
  510. ReportChapterMenuList: chapterMenu,
  511. AuthOk: authOk,
  512. PermissionCheck: permissionCheckInfo,
  513. TickerDataParams: tickerDataParams,
  514. //LikeNum: 0,
  515. //LikeEnabled: 0,
  516. }
  517. //reportChapterDetail.PermissionCheck = &permissionCheckInfo
  518. //reportChapterDetail.LikeNum = likeNum
  519. //reportChapterDetail.LikeEnabled = likeEnabled
  520. return
  521. }
  522. // GetMenuChapter 获取章节下面的菜单
  523. func GetMenuChapter(reportId int, typeIds []int, classifyNameFirst string, reportCreateTime time.Time, encryptMobile string) (reportTypeList reportResp.ReportChapterMenuList, err error) {
  524. reportTypeList = make([]reportResp.ReportChapterMenu, 0)
  525. //查询有效的章节
  526. typeList, tErr := report_chapter_type.GetEffectTypes()
  527. if tErr != nil {
  528. return
  529. }
  530. if len(typeList) == 0 {
  531. err = errors.New("无有效的章节")
  532. return
  533. }
  534. typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
  535. for _, v := range typeList {
  536. typeMap[v.ReportChapterTypeId] = v
  537. }
  538. //获取所有当前研报的章节
  539. chapterList, tErr := report_chapter.GetListByReportIdTypeIds(reportId, typeIds, classifyNameFirst)
  540. if tErr != nil {
  541. return
  542. }
  543. encryptMobile = url.QueryEscape(encryptMobile) //转义 +
  544. nonceStr := common.GetRandString(10)
  545. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  546. if len(chapterList) > 0 {
  547. for _, item := range chapterList {
  548. if typeItem, ok := typeMap[uint64(item.TypeId)]; ok {
  549. if reportCreateTime.Before(typeItem.PauseStartTime) || reportCreateTime.After(typeItem.PauseEndTime) {
  550. //typeItem.ReportChapterTypeId
  551. //跳转地址
  552. postData := make(map[string]string)
  553. reportChapterId := strconv.Itoa(item.ReportChapterId)
  554. parameter := "mobile=" + encryptMobile + "&report_chapter_id=" + reportChapterId + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  555. postData["mobile"] = encryptMobile
  556. postData["report_chapter_id"] = reportChapterId
  557. postData["appid"] = utils.ReportAppid
  558. postData["nonce_str"] = nonceStr
  559. postData["timestamp"] = timeUnix
  560. sign := utils.GetSign(postData)
  561. temp := reportResp.ReportChapterMenu{
  562. ReportChapterId: item.ReportChapterId,
  563. ReportId: item.ReportId,
  564. ReportChapterTypeName: typeItem.ReportChapterTypeName,
  565. ReportChapterTypeThumb: typeItem.YbBottomIcon,
  566. PcSelectedThumb: typeItem.PcSelectedImage,
  567. PcUnselectedThumb: typeItem.PcUnselectedImage,
  568. Sort: typeItem.Sort,
  569. HttpUrl: utils.NewResearchReportUrl + "hzsl/report/new/chapter/detail?" + parameter + "&sign=" + sign,
  570. }
  571. reportTypeList = append(reportTypeList, temp)
  572. }
  573. }
  574. }
  575. }
  576. if len(reportTypeList) > 0 {
  577. sort.Sort(reportTypeList)
  578. }
  579. return
  580. }
  581. // CheckDayReportPermission 验证晨报的权限
  582. func CheckDayReportPermission(userInfo *wx_user.WxUser, productAuthOk bool) (authOk bool, permissionCheckInfo reportResp.PermissionCheckInfo, err error) {
  583. if productAuthOk {
  584. authOk = true
  585. return
  586. }
  587. authOk, permissionCheckInfo, _, err = company.GetCheckPermission(userInfo.CompanyId, int(userInfo.UserId), []int{})
  588. return
  589. }
  590. // CheckWeekReportPermission 验证周报的权限
  591. func CheckWeekReportPermission(userInfo *wx_user.WxUser, productAuthOk bool) (authOk bool, permissionCheckInfo reportResp.PermissionCheckInfo, validTypeIds []int, err error) {
  592. var permissionIds []int
  593. var validPermissionIds []int //最后允许显示的章节
  594. if productAuthOk {
  595. permissionIds, err = chart_permission_chapter_mapping.GetPermissionIdsByWeek()
  596. if err != nil && err.Error() != utils.ErrNoRow() {
  597. return
  598. }
  599. }
  600. authOk, permissionCheckInfo, validPermissionIds, err = company.GetCheckPermission(userInfo.CompanyId, int(userInfo.UserId), permissionIds)
  601. if err != nil {
  602. return
  603. }
  604. //返回可用的章节列表
  605. if len(validPermissionIds) > 0 {
  606. validTypeIds, err = chart_permission_chapter_mapping.GetReportChapterTypeIdsByPermissionIds(validPermissionIds, "week")
  607. }
  608. return
  609. }
  610. // CheckReportPermission 验证用户查看报告的权限
  611. func CheckReportPermission(userInfo *wx_user.WxUser, reportId int, productAuthOk bool) (authOk bool, permissionCheckInfo reportResp.PermissionCheckInfo, err error) {
  612. var permissionIds []int
  613. if productAuthOk {
  614. permissionIds, err = chart_permission_chapter_mapping.GetPermissionIdsByReportId(reportId, "rddp")
  615. if err != nil && err.Error() != utils.ErrNoRow() {
  616. return
  617. }
  618. }
  619. authOk, permissionCheckInfo, _, err = company.GetCheckPermission(userInfo.CompanyId, int(userInfo.UserId), permissionIds)
  620. return
  621. }
  622. // GetTickerData 获取指标数据
  623. func GetTickerData(reportChapterId int) (ret reportResp.TickerData, err error, errMsg string) {
  624. defer func() {
  625. if err != nil {
  626. utils.FileLog.Critical(fmt.Sprintf("GetTickerData: err:%s, errMsg:%s", err.Error(), errMsg))
  627. }
  628. }()
  629. //查询章节类型
  630. chapter, err := report_chapter.GetTypeIdById(reportChapterId)
  631. if err != nil {
  632. errMsg = err.Error()
  633. err = errors.New("查询章节失败")
  634. return
  635. }
  636. if chapter.ReportChapterId == 0 {
  637. err = errors.New("章节不存在或者未发布")
  638. return
  639. }
  640. tickers, err := report_chapter_ticker.GetTickerByChapterId(reportChapterId)
  641. if err != nil {
  642. errMsg = err.Error()
  643. err = errors.New("查询章节指标失败")
  644. return
  645. }
  646. var list []reportResp.TickerDataItem
  647. if len(tickers) > 0 {
  648. var tickerNames []string
  649. for _, v := range tickers {
  650. tickerNames = append(tickerNames, v.Ticker)
  651. }
  652. var dataList []*daily_base_column.TickerDataItem
  653. if chapter.TypeId == 17 {
  654. dataList, err = daily_base_column.GetDataByBaseColumnTickers17(tickerNames)
  655. } else {
  656. dataList, err = daily_base_column.GetDataByBaseColumnTickers(tickerNames)
  657. }
  658. if err != nil {
  659. errMsg = err.Error()
  660. err = errors.New("查询指标数据失败")
  661. return
  662. }
  663. chapterTypeInfo, tErr := report_chapter_type.GetTickerTitleByTypeId(chapter.TypeId)
  664. if tErr != nil {
  665. errMsg = tErr.Error()
  666. err = errors.New("查询章节类型失败")
  667. return
  668. }
  669. if len(dataList) >= 0 {
  670. for _, v := range dataList {
  671. temp := reportResp.TickerDataItem{
  672. Date: v.Date,
  673. Ticker: v.Ticker,
  674. BaseColumnName: v.BaseColumnName,
  675. }
  676. temp.TickerValue, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", v.TickerValue), 2)
  677. temp.LastValue, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", v.LastValue), 2)
  678. temp.MmValue, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", v.MmValue), 2)
  679. temp.DdValue, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", v.DdValue), 2)
  680. temp.WwValue, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", v.WwValue), 2)
  681. list = append(list, temp)
  682. }
  683. }
  684. tickerTitle := reportResp.TickerTitleData{
  685. TickerTitle: chapterTypeInfo.TickerTitle,
  686. ReportChapterTypeId: int(chapterTypeInfo.ReportChapterTypeId),
  687. ReportChapterTypeName: chapterTypeInfo.ReportChapterTypeName,
  688. DataTableImage: fmt.Sprintf("http://hongze.oss-cn-shanghai.aliyuncs.com/data_table/%s.png", chapterTypeInfo.ReportChapterTypeKey),
  689. }
  690. ret = reportResp.TickerData{
  691. List: list,
  692. TickerTitle: tickerTitle,
  693. }
  694. }
  695. return
  696. }