report_service.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. package report
  2. import (
  3. "errors"
  4. logger "eta/eta_mini_ht_api/common/component/log"
  5. "eta/eta_mini_ht_api/common/exception"
  6. "eta/eta_mini_ht_api/common/utils/date"
  7. "eta/eta_mini_ht_api/common/utils/page"
  8. permissionService "eta/eta_mini_ht_api/domian/config"
  9. mediaService "eta/eta_mini_ht_api/domian/media"
  10. productService "eta/eta_mini_ht_api/domian/merchant"
  11. reportService "eta/eta_mini_ht_api/domian/report"
  12. userService "eta/eta_mini_ht_api/domian/user"
  13. productDao "eta/eta_mini_ht_api/models/merchant"
  14. "eta/eta_mini_ht_api/service/config"
  15. user "eta/eta_mini_ht_api/service/user"
  16. "fmt"
  17. "gorm.io/gorm"
  18. "strconv"
  19. "strings"
  20. "sync"
  21. "time"
  22. )
  23. const (
  24. SourceETA = "ETA"
  25. SourceHT = "HT"
  26. RiskLevelUnMatch = "unMatch"
  27. RiskLevelUnTest = "unTest"
  28. RiskLevelExpired = "expired"
  29. RiskLevelMatch = "match"
  30. defaultProductPrice = "0"
  31. )
  32. type PublishRankedReport struct {
  33. Id int `json:"reportId"`
  34. OrgId int `json:"orgId"`
  35. Title string `json:"title"`
  36. Abstract string `json:"abstract"`
  37. SecondPermissions map[int]string `json:"-"`
  38. Permissions map[int]string `json:"-"`
  39. PermissionNames interface{} `json:"permissionNames,omitempty"`
  40. PublishedTime string `json:"publishedTime"`
  41. CoverUrl string `json:"coverUrl"`
  42. RiskLevel string `json:"riskLevel"`
  43. IsFree bool `json:"isFree"`
  44. IsPackage bool `json:"isPackage"`
  45. Price string `json:"price"`
  46. IsSubscribe bool `json:"isSubscribe"`
  47. Login bool `json:"login"`
  48. ProductId int `json:"productId"`
  49. }
  50. type HotRankedReport struct {
  51. Id int `json:"reportId"`
  52. OrgId int `json:"orgId"`
  53. Abstract string `json:"abstract"`
  54. Count int `json:"count"`
  55. Title string `json:"title"`
  56. PublishedTime string `json:"publishedTime"`
  57. SecondPermissions map[int]string `json:"-"`
  58. Permissions map[int]string `json:"-"`
  59. PermissionNames interface{} `json:"permissionNames,omitempty"`
  60. CoverUrl string `json:"coverUrl"`
  61. RiskLevel string `json:"riskLevel"`
  62. IsFree bool `json:"isFree"`
  63. Price string `json:"price"`
  64. IsPackage bool `json:"isPackage"`
  65. ProductId int `json:"productId"`
  66. IsSubscribe bool `json:"isSubscribe"`
  67. Login bool `json:"login"`
  68. }
  69. type RecordCount struct {
  70. UserId int
  71. TraceId string
  72. Mobile string
  73. ReportId int
  74. IpAddress string
  75. Location string
  76. Referer string
  77. Additional string
  78. }
  79. func matchRiskLevel(userId int, report reportService.ReportDTO) (riskLevelMatch string, riskLevel string, err error) {
  80. userProfile, userErr := user.GetUserProfile(userId)
  81. if userErr != nil {
  82. if errors.Is(userErr, gorm.ErrRecordNotFound) {
  83. logger.Error("用户信息不存在,mobile:%d", userProfile.Mobile)
  84. err = exception.New(exception.TemplateUserNotFound)
  85. return
  86. } else {
  87. logger.Error("获取用户信息失败:%v", userErr)
  88. err = exception.New(exception.TemplateUserFoundFailed)
  89. return
  90. }
  91. }
  92. //比较风险等级
  93. if userProfile.RiskLevelStatus == user.RiskUnTest {
  94. logger.Info("客户风险等级未测试,mobile:%d", userProfile.Mobile)
  95. riskLevelMatch = RiskLevelUnTest
  96. return
  97. }
  98. if userProfile.RiskLevelStatus == user.RiskExpired {
  99. logger.Info("客户风险等级已过期,mobile:%v", userProfile.Mobile)
  100. riskLevelMatch = RiskLevelExpired
  101. return
  102. }
  103. level, err := permissionService.GetRiskMappingByCustomerRiskLevel(userProfile.RiskLevel)
  104. if err != nil {
  105. logger.Error("获取eta报告风险等级失败:%v", err)
  106. return
  107. }
  108. permissions := reportService.GetReportSecondPermissionsById(report.OrgId, report.Source)
  109. if len(permissions) == 0 {
  110. logger.Error("获取eta报告分类失败:%v", err)
  111. riskLevelMatch = RiskLevelUnMatch
  112. return
  113. }
  114. var permissionIds []int
  115. for _, permission := range permissions {
  116. permissionIds = append(permissionIds, permission.PermissionId)
  117. }
  118. permissionDTOs, err := permissionService.GetPermissionListByIds(permissionIds)
  119. if err != nil {
  120. logger.Error("获取品种风险等级失败:%v", err)
  121. return
  122. }
  123. //能够查看最高等级
  124. matchNum, err := config.ParseRiskLevel(level.ProductRiskLevel)
  125. if err != nil {
  126. logger.Error("解析风险等级失败:%v", err)
  127. return
  128. }
  129. if len(permissionDTOs) == 0 {
  130. logger.Error("当前报告对应品种未设置风险等级")
  131. err = exception.New(exception.ReportRiskLevelUnSet)
  132. return
  133. }
  134. //能够查看需要的最小等级
  135. //num := getLowestRiskLevel(permissionDTOs)
  136. num := config.GetHighestRiskLevel(permissionDTOs)
  137. riskLevel = fmt.Sprintf("R%d", num)
  138. if num > matchNum {
  139. riskLevelMatch = RiskLevelUnMatch
  140. return
  141. } else {
  142. riskLevelMatch = RiskLevelMatch
  143. return
  144. }
  145. }
  146. func GetReportById(reportId int, login bool, userId int) (report *reportService.ReportDTO, err error) {
  147. var reportInfo reportService.ReportDTO
  148. reportInfo, err = reportService.GetReportById(reportId)
  149. if err != nil {
  150. logger.Error("获取研报失败:%v", err)
  151. err = exception.New(exception.GetReportFailed)
  152. return
  153. }
  154. return DealReportInfo(&reportInfo, login, userId)
  155. }
  156. func GetTotalPageCountByPermissionIds(permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids map[string][]int, disCardIds []int) {
  157. return getCount(permissionIds, isLogin, userId)
  158. }
  159. // ParseRiskLevel 解析风险等级字符串,并返回数字部分
  160. func SearchReportList(key string, Ids []int, pageInfo page.PageInfo, isLogin bool, userId int) (list []reportService.ReportDTO, err error) {
  161. offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
  162. var reports []reportService.ReportDTO
  163. reports, err = reportService.SearchReportList(key, Ids, offset, pageInfo.PageSize, pageInfo.LatestId)
  164. list, err = dealReportInfo(reports, isLogin, userId)
  165. if err != nil {
  166. err = exception.New(exception.SearchReportPageFailed)
  167. }
  168. return
  169. }
  170. func SearchReportProduct(key string, docIds []int) (list []reportService.ReportDTO, err error) {
  171. list, err = reportService.SearchReportProduct(key, 100, 0, docIds)
  172. if err != nil {
  173. err = exception.New(exception.SearchReportPageFailed)
  174. }
  175. return
  176. }
  177. func RangeSearchByAnalyst(analystName string, userId int) (total int64, latestId int64, ids []int) {
  178. return getCountByAnalyst(nil, true, userId, analystName)
  179. }
  180. func RangeSearch(key string, isLogin bool, userId int) (total int64, latestId int64, reportIds []int, discardIds []int, err error) {
  181. var orgIds map[string][]int
  182. _, latestId, orgIds, discardIds = getCount(nil, isLogin, userId)
  183. reportIds, err = GetReportByIdListByOrgIds(orgIds)
  184. if err != nil {
  185. logger.Error("获取报告ID列表失败:%v", err)
  186. err = exception.NewWithException(exception.GetReportSearchRangeFailed, err.Error())
  187. return
  188. }
  189. total = reportService.SearchMaxReportIdWithRange(key, reportIds)
  190. return
  191. }
  192. func dealReportInfo(list []reportService.ReportDTO, isLogin bool, userId int) (resultList []reportService.ReportDTO, err error) {
  193. var wg sync.WaitGroup
  194. wg.Add(len(list))
  195. for i := 0; i < len(list); i++ {
  196. go func(report *reportService.ReportDTO) {
  197. defer wg.Done()
  198. report, err = DealReportInfo(report, isLogin, userId)
  199. if err != nil {
  200. logger.Error("处理报告信息失败:%v", err)
  201. }
  202. }(&list[i])
  203. }
  204. wg.Wait()
  205. resultList = list
  206. return
  207. }
  208. func DealReportInfo(report *reportService.ReportDTO, isLogin bool, userId int) (resultReport *reportService.ReportDTO, err error) {
  209. report.Login = isLogin
  210. report.Permissions, report.PermissionNames = GetReportPermissionNames(report.OrgId, report.Source)
  211. var permissions []permissionService.PermissionDTO
  212. permissions, report.SecondPermission = getReportSecondPermissions(report.OrgId, report.Source)
  213. if len(permissions) == 0 {
  214. resultReport = report
  215. return
  216. }
  217. riskNum := config.GetHighestRiskLevel(permissions)
  218. report.RiskLevel = strings.Join([]string{"R", strconv.Itoa(riskNum)}, "")
  219. var src string
  220. src, err = mediaService.GetImageSrc(report.CoverSrc)
  221. if err != nil {
  222. logger.Error("获取图片地址失败:%v", err)
  223. src = ""
  224. } else {
  225. report.CoverUrl = src
  226. }
  227. //套餐信息
  228. var packageList []productService.MerchantProductDTO
  229. //查询产品信息
  230. product, pdErr := productService.GetProductBySourceId(report.ReportID, productDao.Report)
  231. var permissionIds []int
  232. if len(permissions) > 0 {
  233. for _, permission := range permissions {
  234. permissionIds = append(permissionIds, permission.PermissionId)
  235. }
  236. //单品不存在的话查套餐
  237. packageList, err = productService.GetProductListBySourceIds(permissionIds, "package")
  238. if err != nil {
  239. logger.Error("获取套餐列表失败:%v", err)
  240. }
  241. }
  242. if pdErr != nil {
  243. //单品不存在的话查套餐
  244. if len(packageList) == 0 {
  245. logger.Error("获取套餐列表失败:%v", err)
  246. report.Price = defaultProductPrice
  247. report.IsFree = true
  248. report.IsSubscribe = false
  249. report.IsPackage = false
  250. } else {
  251. report.Price = packageList[0].Price
  252. report.IsFree = false
  253. report.IsSubscribe = false
  254. report.IsPackage = true
  255. report.ProductId = packageList[0].Id
  256. }
  257. } else {
  258. report.Price = product.Price
  259. report.IsFree = false
  260. report.ProductId = product.Id
  261. report.IsPackage = false
  262. }
  263. //最热最新的时候使用
  264. productList := append(packageList)
  265. if pdErr == nil {
  266. productList = append(productList, product)
  267. }
  268. if len(productList) == 0 {
  269. report.Show = true
  270. } else {
  271. for _, productItem := range productList {
  272. if productItem.SaleStatus == "on_sale" {
  273. report.Show = true
  274. break
  275. }
  276. }
  277. }
  278. if isLogin {
  279. var productIds []int
  280. if len(packageList) > 0 {
  281. for _, packageItem := range packageList {
  282. productIds = append(productIds, packageItem.Id)
  283. }
  284. }
  285. if product.Id > 0 {
  286. productIds = append(productIds, product.Id)
  287. }
  288. subscribeList, subscribeErr := userService.GetUserSubscribe(productIds, userId)
  289. if subscribeErr != nil {
  290. report.IsSubscribe = false
  291. } else {
  292. for _, subscribe := range subscribeList {
  293. if subscribe.Status == productDao.SubscribeValid {
  294. report.IsSubscribe = true
  295. break
  296. }
  297. }
  298. }
  299. }
  300. //report.RiskLevelStatus = RiskLevelUnMatch
  301. //if mappingRiskLevel != "" {
  302. // mappingRiskNum, parseErr := config.ParseRiskLevel(mappingRiskLevel)
  303. // if parseErr != nil {
  304. // return
  305. // }
  306. // var rpRiskNum int
  307. // rpRiskNum, parseErr = config.ParseRiskLevel(media.RiskLevel)
  308. // if parseErr != nil {
  309. // return
  310. // }
  311. // if rpRiskNum <= mappingRiskNum {
  312. // report.RiskLevelStatus = RiskLevelMatch
  313. // }
  314. //}
  315. //resultMedia = media
  316. //return
  317. resultReport = report
  318. return
  319. }
  320. // GetReportPage 分页获取报告列表
  321. func GetReportPage(pageInfo page.PageInfo, orgIds map[string][]int, discardIds []int, isLogin bool, userId int) (reports []reportService.ReportDTO, err error) {
  322. var list []reportService.ReportDTO
  323. list, err = reportService.GetReportPageByOrgIds(pageInfo, orgIds, discardIds)
  324. reports, err = dealReportInfo(list, isLogin, userId)
  325. if err != nil {
  326. err = exception.New(exception.QueryReportPageFailed)
  327. }
  328. return
  329. }
  330. func GetReportPageByAnalyst(pageInfo page.PageInfo, analyst string, reportIds []int, templateUserId int) (list []reportService.ReportDTO, err error) {
  331. list, err = reportService.GetReportPageByAnalyst(pageInfo, analyst, reportIds)
  332. list, err = dealReportInfo(list, true, templateUserId)
  333. if err != nil {
  334. err = exception.New(exception.QueryReportPageFailed)
  335. }
  336. return
  337. }
  338. func CountReport(count RecordCount) (traceId string, err error) {
  339. report, err := reportService.GetReportById(count.ReportId)
  340. if err != nil {
  341. err = exception.New(exception.GetReportFailed)
  342. return
  343. }
  344. dto := convertToRecordCountDTO(count)
  345. dto.SourceTitle = report.Title
  346. return userService.CountReport(dto)
  347. }
  348. func GetRandedReportByWeeklyHot(limit int, isLogin bool, userId int, pdRiskLevel string) (reports []HotRankedReport, err error) {
  349. end := time.Now()
  350. begin := date.GetBeginOfTheWeek(end, time.Monday)
  351. hotReports := userService.GetHotReports(begin.Format(time.DateOnly), end.Format(time.DateOnly), limit)
  352. if len(hotReports) > 0 {
  353. var dtoList []reportService.ReportDTO
  354. var ids []int
  355. for i := 0; i < len(hotReports); i++ {
  356. ids = append(ids, hotReports[i].ReportId)
  357. }
  358. dtoList, err = reportService.GetListByCondition("id", ids)
  359. if err != nil {
  360. logger.Error("获取本周最热研报列表失败:%v", err)
  361. err = exception.New(exception.GetHotRandListFailed)
  362. return
  363. }
  364. dtoList, err = dealReportInfo(dtoList, isLogin, userId)
  365. if err != nil {
  366. logger.Error("获取本周最热研报列表失败:%v", err)
  367. err = exception.New(exception.GetHotRandListFailed)
  368. return
  369. }
  370. var filterList []reportService.ReportDTO
  371. if pdRiskLevel != "" {
  372. for _, report := range dtoList {
  373. pdRiskNum, paresErr := config.ParseRiskLevel(report.RiskLevel)
  374. if paresErr != nil {
  375. logger.Error("解析风险等级失败:%v", err)
  376. continue
  377. }
  378. reRiskNum, paresErr := config.ParseRiskLevel(pdRiskLevel)
  379. if paresErr != nil {
  380. logger.Error("解析风险等级失败:%v", err)
  381. continue
  382. }
  383. if pdRiskNum <= reRiskNum && report.Show {
  384. filterList = append(filterList, report)
  385. }
  386. }
  387. } else {
  388. for _, report := range dtoList {
  389. if report.Show {
  390. filterList = append(filterList, report)
  391. }
  392. }
  393. }
  394. reports = make([]HotRankedReport, len(ids))
  395. for i := 0; i < len(filterList); i++ {
  396. report := convertToHotRankedReport(filterList[i])
  397. for j := 0; j < len(hotReports); j++ {
  398. if hotReports[j].ReportId == report.Id {
  399. report.Count = hotReports[j].Count
  400. reports[j] = report
  401. break
  402. }
  403. }
  404. }
  405. } else {
  406. reports = []HotRankedReport{}
  407. }
  408. return
  409. }
  410. func GetRandedReportByPublishTimeWeekly(limit int, week bool, isLogin bool, userId int, pdRiskLevel string) (reports []PublishRankedReport, err error) {
  411. dtoList, err := reportService.GetListOrderByConditionWeekly(week, "published_time", limit, reportService.DESC)
  412. if err != nil {
  413. logger.Error("获取最新发布的研报列表失败:%v", err)
  414. err = exception.New(exception.GetPublishedRandListFailed)
  415. return
  416. }
  417. var filterList []reportService.ReportDTO
  418. dtoList, err = dealReportInfo(dtoList, isLogin, userId)
  419. if err != nil {
  420. logger.Error("获取最新发布的研报列表失败:%v", err)
  421. err = exception.New(exception.GetPublishedRandListFailed)
  422. return
  423. }
  424. if pdRiskLevel != "" {
  425. for _, report := range dtoList {
  426. pdRiskNum, paresErr := config.ParseRiskLevel(report.RiskLevel)
  427. if paresErr != nil {
  428. logger.Error("解析风险等级失败:%v", err)
  429. continue
  430. }
  431. reRiskNum, paresErr := config.ParseRiskLevel(pdRiskLevel)
  432. if paresErr != nil {
  433. logger.Error("解析风险等级失败:%v", err)
  434. continue
  435. }
  436. if pdRiskNum <= reRiskNum && report.Show {
  437. filterList = append(filterList, report)
  438. }
  439. }
  440. } else {
  441. for _, report := range dtoList {
  442. if report.Show {
  443. filterList = append(filterList, report)
  444. }
  445. }
  446. }
  447. reports = convertToPublishRankedReportList(filterList)
  448. return
  449. }
  450. func GetReportPermissionNames(id int, source string) (permissionMap map[int]string, labels []string) {
  451. permissions := reportService.GetReportPermissionsById(id, source)
  452. permissionMap = make(map[int]string, len(permissions))
  453. if len(permissions) > 0 {
  454. for _, permission := range permissions {
  455. labels = append(labels, permission.PermissionName)
  456. permissionMap[permission.PermissionId] = permission.PermissionName
  457. }
  458. }
  459. return
  460. }
  461. func GetReportSecondPermissionsMap(id int, source string) (permissionMap map[int]string) {
  462. permissionMap = make(map[int]string)
  463. permissions := reportService.GetReportSecondPermissionsById(id, source)
  464. for _, permission := range permissions {
  465. permissionMap[permission.PermissionId] = permission.PermissionName
  466. }
  467. return
  468. }
  469. func getReportSecondPermissions(id int, source string) (permissionList []permissionService.PermissionDTO, secondPermissionMap map[int]string) {
  470. permissionList = reportService.GetReportSecondPermissionsById(id, source)
  471. if len(permissionList) > 0 {
  472. secondPermissionMap = make(map[int]string, len(permissionList))
  473. for _, permission := range permissionList {
  474. secondPermissionMap[permission.PermissionId] = permission.PermissionName
  475. }
  476. }
  477. return
  478. }
  479. func getReportPermissionsMap(id int, source string) (permissionMap map[int]string) {
  480. permissionMap = make(map[int]string)
  481. permissions := reportService.GetReportPermissionsById(id, source)
  482. for _, permission := range permissions {
  483. permissionMap[permission.PermissionId] = permission.PermissionName
  484. }
  485. return
  486. }
  487. func GetPermissionList() (root *permissionService.PermissionNode, err error) {
  488. return permissionService.GetPermissionList()
  489. }
  490. func convertToHotRankedReport(dto reportService.ReportDTO) (report HotRankedReport) {
  491. report = HotRankedReport{
  492. Id: dto.ReportID,
  493. OrgId: dto.OrgId,
  494. Abstract: dto.Abstract,
  495. PublishedTime: dto.PublishedTime,
  496. Title: dto.Title,
  497. SecondPermissions: dto.SecondPermission,
  498. Permissions: dto.Permissions,
  499. PermissionNames: dto.PermissionNames,
  500. CoverUrl: dto.CoverUrl,
  501. IsSubscribe: dto.IsSubscribe,
  502. IsFree: dto.IsFree,
  503. Price: dto.Price,
  504. RiskLevel: dto.RiskLevel,
  505. Login: dto.Login,
  506. ProductId: dto.ProductId,
  507. IsPackage: dto.IsPackage,
  508. }
  509. return
  510. }
  511. func convertToPublishRankedReportList(dtoList []reportService.ReportDTO) (reports []PublishRankedReport) {
  512. reports = []PublishRankedReport{}
  513. for _, dto := range dtoList {
  514. risk, err := config.ParseRiskLevel(dto.RiskLevel)
  515. if err != nil || risk == 0 {
  516. continue
  517. }
  518. src, err := mediaService.GetImageSrc(dto.CoverSrc)
  519. if err != nil {
  520. logger.Error("获取封面图片失败:%v", err)
  521. src = ""
  522. }
  523. report := PublishRankedReport{
  524. Id: dto.ReportID,
  525. OrgId: dto.OrgId,
  526. PublishedTime: dto.PublishedTime,
  527. Abstract: dto.Abstract,
  528. Title: dto.Title,
  529. Permissions: dto.Permissions,
  530. SecondPermissions: dto.SecondPermission,
  531. PermissionNames: dto.PermissionNames,
  532. CoverUrl: src,
  533. IsSubscribe: dto.IsSubscribe,
  534. IsFree: dto.IsFree,
  535. Price: dto.Price,
  536. RiskLevel: dto.RiskLevel,
  537. Login: dto.Login,
  538. ProductId: dto.ProductId,
  539. IsPackage: dto.IsPackage,
  540. }
  541. reports = append(reports, report)
  542. }
  543. return
  544. }
  545. func convertToRecordCountDTO(record RecordCount) (dto userService.RecordCountDTO) {
  546. return userService.RecordCountDTO{
  547. UserId: record.UserId,
  548. TraceId: record.TraceId,
  549. Mobile: record.Mobile,
  550. SourceId: record.ReportId,
  551. IpAddress: record.IpAddress,
  552. Location: record.Location,
  553. Referer: record.Referer,
  554. Additional: record.Additional,
  555. }
  556. }
  557. func GetReportByIdListByOrgIds(orgIds map[string][]int) (ids []int, err error) {
  558. ids, err = reportService.GetReportByIdListByOrgIds(orgIds)
  559. if err != nil {
  560. logger.Error("获取报告ID列表失败:%v", err)
  561. err = exception.New(exception.GetReportSearchRangeFailed)
  562. }
  563. return
  564. }
  565. func RangePermissionIds(isLogin bool, userId int) (filterPermissionIds []int, riskLevel string, err error) {
  566. return user.GetRiskLevelPermissionList(nil, isLogin, userId)
  567. }
  568. func getCount(permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids map[string][]int, discardIds []int) {
  569. filterPermissionIds, _, err := user.GetRiskLevelPermissionList(permissionIds, isLogin, userId)
  570. if err != nil {
  571. logger.Error("获取过滤品种信息失败:%v", err)
  572. return
  573. }
  574. if len(filterPermissionIds) == 0 {
  575. logger.Warn("不存在设置风险等级的品种信息")
  576. return
  577. }
  578. return reportService.GetTotalPageCountByPermissionIds(filterPermissionIds)
  579. }
  580. func getCountByAnalyst(permissionIds []int, isLogin bool, userId int, analystName string) (total int64, latestId int64, ids []int) {
  581. filterPermissionIds, _, err := user.GetRiskLevelPermissionList(permissionIds, isLogin, userId)
  582. if err != nil {
  583. logger.Error("校验用户风险等级失败:%v", err)
  584. return
  585. }
  586. return reportService.GetTotalPageCountByAnalyst(analystName, filterPermissionIds)
  587. }
  588. func CountPermissionWeight(ids []int) (permissionMap map[int]int) {
  589. list, err := reportService.CountPermissionWeight(ids)
  590. permissionMap = make(map[int]int)
  591. if err != nil {
  592. return
  593. }
  594. for _, item := range list {
  595. permissionMap[item.PermissionId] = item.Weight
  596. }
  597. return
  598. }