report_service.go 21 KB

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