user_service.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. package user
  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/page"
  8. permissionService "eta/eta_mini_ht_api/domian/config"
  9. analystService "eta/eta_mini_ht_api/domian/financial_analyst"
  10. reportDomian "eta/eta_mini_ht_api/domian/report"
  11. userService "eta/eta_mini_ht_api/domian/user"
  12. merchantDao "eta/eta_mini_ht_api/models/merchant"
  13. userDao "eta/eta_mini_ht_api/models/user"
  14. "eta/eta_mini_ht_api/service/config"
  15. chartService "eta/eta_mini_ht_api/service/media"
  16. reportService "eta/eta_mini_ht_api/service/report"
  17. "gorm.io/gorm"
  18. "sort"
  19. "sync"
  20. "time"
  21. )
  22. const (
  23. RiskValid = "valid"
  24. RiskExpired = "expired"
  25. RiskUnTest = "unTest"
  26. SubscribeExpired = "expired"
  27. UnSubscribe = "unSubscribe"
  28. Subscribing = "Subscribing"
  29. ReportBookMark = "report"
  30. ChartBookMark = "chart"
  31. )
  32. type User struct {
  33. Id int `json:"id"`
  34. Username string `json:"username"`
  35. AreaCode string `json:"areaCode"`
  36. Mobile string `json:"mobile"`
  37. OpenId string `json:"openId,omitempty"`
  38. }
  39. type AnalystDetail struct {
  40. AnalystName string `json:"analystName"`
  41. HeadImgUrl string `json:"headImgUrl"`
  42. Introduction string `json:"introduction"`
  43. Followed string `json:"followed"`
  44. Position string `json:"position"`
  45. InvestmentCertificate string `json:"investmentCertificate"`
  46. ProfessionalCertificate string `json:"professionalCertificate"`
  47. }
  48. type UserProfile struct {
  49. Mobile string `json:"mobile"`
  50. RiskLevel string `json:"riskLevel"`
  51. RiskLevelStatus string `json:"riskLevelStatus"`
  52. UserName string `json:"userName"`
  53. }
  54. func CheckUserRiskMatchStatus(userId int) (riskLevel string, userRiskLevelStatus string, err error) {
  55. if userId <= 0 {
  56. err = exception.New(exception.IllegalTemplateUserId)
  57. return
  58. }
  59. userProfile, userErr := GetUserProfile(userId)
  60. if userErr != nil {
  61. if errors.Is(userErr, gorm.ErrRecordNotFound) {
  62. err = exception.New(exception.TemplateUserNotFound)
  63. } else {
  64. err = exception.New(exception.TemplateUserFoundFailed)
  65. }
  66. logger.Error("获取临时客户信息失败:%v", err)
  67. return
  68. }
  69. userRiskLevelStatus = userProfile.RiskLevelStatus
  70. //获取产品风险等级
  71. if userProfile.RiskLevelStatus == RiskUnTest {
  72. logger.Warn("客户未做风险等级测评,mobile:%v", userProfile.Mobile)
  73. }
  74. if userProfile.RiskLevelStatus == RiskExpired {
  75. logger.Warn("客户风险等级已过期,mobile:%v", userProfile.Mobile)
  76. }
  77. if userProfile.RiskLevel != "" && userProfile.RiskLevelStatus == RiskValid {
  78. var mapping permissionService.CustomerProductRiskMappingDTO
  79. mapping, err = permissionService.GetRiskMappingByCustomerRiskLevel(userProfile.RiskLevel)
  80. if err != nil {
  81. logger.Error("查询产品风险等级映射失败:%v", err)
  82. return
  83. }
  84. riskLevel = mapping.ProductRiskLevel
  85. }
  86. return
  87. }
  88. // GetRiskLevelPermissionList 删选掉没有配置风险等级的品种,并校验客户的风险等级,riskLevel只有在客户
  89. func GetRiskLevelPermissionList(permissionIds []int, isLogin bool, userId int) (filterPermissionIds []int, riskLevel string, userRiskStatus string, err error) {
  90. if isLogin {
  91. userProfile, userErr := GetUserProfile(userId)
  92. if userErr != nil {
  93. if errors.Is(userErr, gorm.ErrRecordNotFound) {
  94. err = exception.New(exception.TemplateUserNotFound)
  95. } else {
  96. err = exception.New(exception.TemplateUserFoundFailed)
  97. }
  98. logger.Error("获取临时客户信息失败:%v", err)
  99. return
  100. }
  101. var permissionList []permissionService.PermissionDTO
  102. if len(permissionIds) == 0 {
  103. //获取所有设置风险等级的品种
  104. permissionList, err = permissionService.GetPermissionListWithRisk()
  105. } else {
  106. //更具id过滤设置了风险等级的品种
  107. permissionList, err = permissionService.GetPermissionListByIds(permissionIds)
  108. }
  109. if err != nil {
  110. logger.Error("查询有风险等级的品种列表失败:%v", err)
  111. return
  112. }
  113. userRiskStatus = userProfile.RiskLevelStatus
  114. //获取产品风险等级
  115. if userProfile.RiskLevelStatus == RiskUnTest {
  116. logger.Warn("客户未做风险等级测评,mobile:%v", userProfile.Mobile)
  117. //err = exception.New(exception.RiskUnTestError)
  118. }
  119. if userProfile.RiskLevelStatus == RiskExpired {
  120. logger.Warn("客户风险等级已过期,mobile:%v", userProfile.Mobile)
  121. //err = exception.New(exception.RiskExpiredError)
  122. }
  123. if userProfile.RiskLevel != "" && userProfile.RiskLevelStatus == RiskValid {
  124. var mapping permissionService.CustomerProductRiskMappingDTO
  125. mapping, err = permissionService.GetRiskMappingByCustomerRiskLevel(userProfile.RiskLevel)
  126. if err != nil {
  127. logger.Error("查询产品风险等级映射失败:%v", err)
  128. return
  129. }
  130. permissionList = filterPermissionsByRisk(permissionList, mapping.ProductRiskLevel)
  131. riskLevel = mapping.ProductRiskLevel
  132. }
  133. for _, permission := range permissionList {
  134. filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
  135. }
  136. return
  137. } else { //没有登录的时候展示所有设置了风险等级的品种报告,筛选的时候过滤传入ID中没有设置风险等级的品种
  138. var permissionList []permissionService.PermissionDTO
  139. if len(permissionIds) == 0 {
  140. //获取所有设置风险等级的品种
  141. permissionList, err = permissionService.GetPermissionListWithRisk()
  142. } else {
  143. //更具id过滤设置了风险等级的品种
  144. permissionList, err = permissionService.GetPermissionListByIds(permissionIds)
  145. }
  146. if err != nil {
  147. logger.Error("查询有风险等级的品种列表失败:%v", err)
  148. return
  149. }
  150. for _, permission := range permissionList {
  151. filterPermissionIds = append(filterPermissionIds, permission.PermissionId)
  152. }
  153. return
  154. }
  155. }
  156. func filterPermissionsByRisk(permissionList []permissionService.PermissionDTO, riskLevel string) (resultList []permissionService.PermissionDTO) {
  157. if riskLevel != "" {
  158. riskLevelNum, err := config.ParseRiskLevel(riskLevel)
  159. if err != nil {
  160. logger.Error("风险等级解析失败:%v", err)
  161. return
  162. }
  163. for _, permission := range permissionList {
  164. pRiskNum, riskErr := config.ParseRiskLevel(permission.RiskLevel)
  165. if riskErr != nil {
  166. logger.Error("解析品种风险等级失败 permission:%d,risk:%v", permission.PermissionId, permission.RiskLevel)
  167. continue
  168. }
  169. if pRiskNum <= riskLevelNum {
  170. resultList = append(resultList, permission)
  171. }
  172. }
  173. } else {
  174. resultList = permissionList
  175. }
  176. return
  177. }
  178. func convertUserDTOToProfile(dto userService.UserDTO) (profile UserProfile) {
  179. profile = UserProfile{
  180. Mobile: dto.Mobile,
  181. RiskLevel: dto.RiskLevel,
  182. UserName: dto.Username,
  183. }
  184. if profile.UserName == "" {
  185. profile.UserName = dto.Mobile
  186. }
  187. if dto.RiskLevel == "" {
  188. profile.RiskLevelStatus = RiskUnTest
  189. return
  190. }
  191. date, err := time.Parse(time.DateOnly, dto.RiskValidEndDate)
  192. if err != nil {
  193. logger.Error("解析日期失败:%v", err)
  194. profile.RiskLevelStatus = RiskExpired
  195. return
  196. }
  197. currentDate := time.Now().Truncate(24 * time.Hour)
  198. expiryDate := date.Truncate(24 * time.Hour)
  199. if expiryDate.Before(currentDate) {
  200. profile.RiskLevelStatus = RiskExpired
  201. return
  202. }
  203. profile.RiskLevelStatus = RiskValid
  204. return
  205. }
  206. func GetUserProfile(userId int) (userProfile UserProfile, err error) {
  207. userDTO, err := userService.GetUserById(userId)
  208. if err != nil {
  209. if errors.Is(err, gorm.ErrRecordNotFound) {
  210. logger.Error("用户不存在,用户Id:%d", userId)
  211. err = exception.New(exception.TemplateUserNotFound)
  212. } else {
  213. logger.Error("获取用户信息失败:%v", err)
  214. err = exception.New(exception.TemplateUserFoundFailed)
  215. }
  216. return
  217. }
  218. userProfile = convertUserDTOToProfile(userDTO)
  219. return
  220. }
  221. func GetAnalystDetail(userId int, analystId int) (analystDetail AnalystDetail, err error) {
  222. analyst, err := analystService.GetAnalystById(analystId)
  223. if err != nil {
  224. logger.Error("研究员信息不存在:%v", err)
  225. err = exception.New(exception.AnalystNotFound)
  226. }
  227. analystDetail = convertToAnalystDetail(analyst)
  228. //研究员关注状态
  229. analystDetail.Followed = userService.GetFollowed(userId, analystId)
  230. return
  231. }
  232. func convertToAnalystDetail(dto analystService.FinancialAnalystDTO) AnalystDetail {
  233. return AnalystDetail{
  234. AnalystName: dto.Name,
  235. HeadImgUrl: dto.HeadImgUrl,
  236. Introduction: dto.Introduction,
  237. Position: dto.Position,
  238. InvestmentCertificate: dto.InvestmentCertificate,
  239. ProfessionalCertificate: dto.ProfessionalCertificate,
  240. }
  241. }
  242. func FollowAnalystsByName(userId int, analystNames []string, followType string) (err error) {
  243. var followlist []userService.FollowDTO
  244. for _, analystName := range analystNames {
  245. FinancialAnalystDTO, followErr := analystService.GetAnalystByName(analystName)
  246. if followErr != nil {
  247. err = exception.New(exception.AnalystNotFound)
  248. }
  249. if FinancialAnalystDTO.Id == 0 || FinancialAnalystDTO.Name == "" {
  250. continue
  251. }
  252. followDTO := userService.FollowDTO{
  253. UserId: userId,
  254. AnalystId: FinancialAnalystDTO.Id,
  255. AnalystName: FinancialAnalystDTO.Name,
  256. FollowType: followType,
  257. }
  258. followlist = append(followlist, followDTO)
  259. }
  260. err = userService.FollowAnalystsByName(userId, followlist, followType)
  261. if err != nil {
  262. logger.Error("批量关注研究员失败:%v", err)
  263. err = exception.New(exception.BatchFollowingAnalystFailed)
  264. }
  265. return
  266. }
  267. func CheckFollowStatusByNames(userId int, names []string) (list []userService.FollowDTO, err error) {
  268. list, err = userService.CheckFollowStatusByNames(userId, names)
  269. if err != nil {
  270. logger.Error("获取关注状态失败:%v", err)
  271. err = exception.New(exception.CheckFollowStatusByNamesFailed)
  272. }
  273. return
  274. }
  275. func FollowAnalyst(userId int, analystId int, followType string) (err error) {
  276. FinancialAnalystDTO, err := analystService.GetAnalystById(analystId)
  277. if err != nil {
  278. err = exception.New(exception.AnalystNotFound)
  279. }
  280. if FinancialAnalystDTO.Id == 0 || FinancialAnalystDTO.Name == "" {
  281. err = exception.New(exception.AnalystNotFound)
  282. return
  283. }
  284. followDTO := userService.FollowDTO{
  285. UserId: userId,
  286. AnalystId: analystId,
  287. AnalystName: FinancialAnalystDTO.Name,
  288. FollowType: followType,
  289. }
  290. err = userService.FollowAnalyst(followDTO)
  291. if err != nil {
  292. logger.Error("关注研究员失败:%v", err)
  293. err = exception.New(exception.UserFollowAnalystFailed)
  294. }
  295. return
  296. }
  297. func GetFollowingAnalystList(userId int) (analysts []FollowAnalystDTO, err error) {
  298. logger.Info("用户ID:%d", userId)
  299. dtoList, err := userService.GetFollowingAnalystList(userId)
  300. if err != nil {
  301. logger.Error("获取关注列表失败:%v", err)
  302. err = exception.New(exception.GetFollowingAnalystListFailed)
  303. return
  304. }
  305. analysts, err = convertToAnalystList(dtoList)
  306. var wg sync.WaitGroup
  307. wg.Add(len(analysts))
  308. for i := 0; i < len(analysts); i++ {
  309. go func(followDTo *FollowAnalystDTO) {
  310. defer wg.Done()
  311. followDTo.NeedNotice = userService.NeedNotice(userId, followDTo.AnalystId)
  312. var analystsDTO analystService.FinancialAnalystDTO
  313. analystsDTO, err = analystService.GetAnalystById(followDTo.AnalystId)
  314. if err != nil {
  315. logger.Error("获取研究员信息失败")
  316. } else {
  317. followDTo.HeadImgUrl = analystsDTO.HeadImgUrl
  318. }
  319. }(&analysts[i])
  320. }
  321. wg.Wait()
  322. //排序
  323. sort.Slice(analysts, func(i, j int) bool {
  324. // 首先按 NeedNotice 排序
  325. if analysts[i].NeedNotice == analysts[j].NeedNotice {
  326. // 对于 NeedNotice 相同的情况下,进行倒序排列
  327. return analysts[i].FollowedTime.After(analysts[j].FollowedTime)
  328. }
  329. // NeedNotice 为 true 的排在 false 的前面
  330. return analysts[i].NeedNotice
  331. })
  332. //if err != nil {
  333. // logger.Error("转换研究员列表失败:%v", err)
  334. // err = exception.New(exception.TransferFollowingAnalystListFailed)
  335. //}
  336. return
  337. }
  338. func GetUnReadMessageList(userId int) (messages []userService.MyMessage, err error) {
  339. messages, err = userService.GetUnReadMessageList(userId)
  340. if err != nil {
  341. err = exception.New(exception.GetUserUnReadMsgFailed)
  342. }
  343. return
  344. }
  345. func ReadMessage(userId int, messageId int) bool {
  346. return userService.ReadMessage(userId, messageId)
  347. }
  348. func ReadMessages(userId int, analystId int) bool {
  349. return userService.ReadMessages(userId, analystId)
  350. }
  351. type FollowAnalystDTO struct {
  352. AnalystId int `json:"analystId"`
  353. AnalystName string `json:"analystName"`
  354. HeadImgUrl string `json:"headImgUrl"`
  355. FollowedTime time.Time `json:"followedTime"`
  356. NeedNotice bool `json:"needNotice"`
  357. }
  358. func convertToAnalystList(dtoList []userService.FollowDTO) (list []FollowAnalystDTO, err error) {
  359. for _, dto := range dtoList {
  360. analyst := FollowAnalystDTO{
  361. AnalystId: dto.AnalystId,
  362. AnalystName: dto.AnalystName,
  363. FollowedTime: dto.FollowedTime,
  364. NeedNotice: false,
  365. }
  366. list = append(list, analyst)
  367. }
  368. return
  369. }
  370. func FollowAnalystByName(userId int, analystName string, followType string) (err error) {
  371. FinancialAnalystDTO, err := analystService.GetAnalystByName(analystName)
  372. if err != nil {
  373. err = exception.New(exception.AnalystNotFound)
  374. }
  375. if FinancialAnalystDTO.Id == 0 || FinancialAnalystDTO.Name == "" {
  376. err = exception.New(exception.AnalystNotFound)
  377. return
  378. }
  379. followDTO := userService.FollowDTO{
  380. UserId: userId,
  381. AnalystId: FinancialAnalystDTO.Id,
  382. AnalystName: FinancialAnalystDTO.Name,
  383. FollowType: followType,
  384. }
  385. err = userService.FollowAnalyst(followDTO)
  386. if err != nil {
  387. logger.Error("关注研究员失败:%v", err)
  388. err = exception.New(exception.UserFollowAnalystFailed)
  389. }
  390. return
  391. }
  392. func FeedBack(userId int, mobile string, message string) (err error) {
  393. feedback := userService.FeedbackDTO{
  394. UserId: userId,
  395. Mobile: mobile,
  396. Message: message,
  397. }
  398. err = userService.FeedBack(feedback)
  399. if err != nil {
  400. err = exception.New(exception.FeedBackError)
  401. }
  402. return
  403. }
  404. func GetUserByMobile(mobile string) (user User, err error) {
  405. userDTO, err := userService.GetUserByMobile(mobile)
  406. if err != nil {
  407. if errors.Is(err, gorm.ErrRecordNotFound) {
  408. err = exception.New(exception.TemplateUserNotFound)
  409. } else {
  410. err = exception.New(exception.TemplateUserFoundFailed)
  411. }
  412. }
  413. user = convertToUser(userDTO)
  414. return
  415. }
  416. func GetUserByOpenId(openId string) (user User, err error) {
  417. userDTO, err := userService.GetUserByOpenId(openId)
  418. if err != nil {
  419. return
  420. }
  421. user = convertToUser(userDTO)
  422. return
  423. }
  424. func convertToUser(userDTO userService.UserDTO) User {
  425. return User{
  426. Id: userDTO.Id,
  427. Username: userDTO.Username,
  428. OpenId: userDTO.OpenId,
  429. AreaCode: userDTO.AreaCode,
  430. Mobile: userDTO.Mobile,
  431. }
  432. }
  433. func GetUserByTemplateUserId(templateUserId int) (officialUser userService.OfficialUserDTO, err error) {
  434. officialUser, err = userService.GetUserByTemplateUserId(templateUserId)
  435. if err != nil {
  436. if errors.Is(err, gorm.ErrRecordNotFound) {
  437. err = exception.New(exception.OfficialUserNotFound)
  438. logger.Info("用户未开户:%v", templateUserId)
  439. } else {
  440. err = exception.NewWithException(exception.OfficialUserFoundError, err.Error())
  441. logger.Error("获取正式用户信息失败:%v", err)
  442. }
  443. }
  444. return
  445. }
  446. func GetUserScribeStatus(productId int, templateUserId int) (subscribe string) {
  447. userSubscribe, err := userService.GetUserSubscribe([]int{productId}, templateUserId)
  448. if err != nil {
  449. logger.Error("获取用户订阅状态失败:%v", err)
  450. return UnSubscribe
  451. }
  452. if len(userSubscribe) == 0 {
  453. return UnSubscribe
  454. }
  455. if userSubscribe[0].ProductType != merchantDao.Package && userSubscribe[0].Status == merchantDao.SubscribeExpired {
  456. logger.Error("用户订阅状态异常:%v,单品状态为过期,productId:%d", productId)
  457. return UnSubscribe
  458. }
  459. switch userSubscribe[0].Status {
  460. case
  461. merchantDao.SubscribeClose:
  462. return UnSubscribe
  463. case merchantDao.SubscribeExpired:
  464. return SubscribeExpired
  465. case merchantDao.SubscribeValid:
  466. return Subscribing
  467. default:
  468. return UnSubscribe
  469. }
  470. }
  471. func BookMark(templateUserId int, sourceId int, sourceType string) error {
  472. return userService.BookMark(templateUserId, sourceId, sourceType)
  473. }
  474. func UnBookMark(templateUserId int, sourceId int, sourceType string) error {
  475. return userService.UnBookMark(templateUserId, sourceId, sourceType)
  476. }
  477. func CheckBookMarkStatus(templateUserId int, sourceId int, sourceType string) (isBookMarked bool, err error) {
  478. status, err := userService.CheckBookMarkStatus(templateUserId, sourceId, sourceType)
  479. if err != nil {
  480. logger.Error("获取收藏状态失败:%v", err)
  481. return
  482. }
  483. isBookMarked = status == string(userDao.Marked)
  484. return
  485. }
  486. func GetTotalBookMarkPageBySourceType(userId int, sourceType string) (total int64, sourceIds []int, err error) {
  487. return userService.GetTotalBookMarkPageBySourceType(userId, sourceType)
  488. }
  489. func GetBookMarkPageBySourceType(userId int, pageInfo page.PageInfo, sourceType string) (sourceIds []int, err error) {
  490. return userService.GetBookMarkPageBySourceType(userId, sourceType, pageInfo)
  491. }
  492. func GetBookMarkPageRangeBySourceType(userId int, pageInfo page.PageInfo, sourceType string, sourceIds []int) (filterSourceIds []int, err error) {
  493. return userService.GetBookMarkPageRangeBySourceType(userId, sourceType, pageInfo, sourceIds)
  494. }
  495. func GetReportBookMarked(sourceId int, templateUserId int) (collected bool, err error) {
  496. bookMark, err := userService.GetBookMarkedBySource(sourceId, templateUserId, ReportBookMark)
  497. if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
  498. return
  499. }
  500. if errors.Is(err, gorm.ErrRecordNotFound) {
  501. err = nil
  502. return
  503. }
  504. collected = bookMark.Status == string(userDao.Marked)
  505. return
  506. }
  507. type BookMarkChart struct {
  508. ChartName string `json:"chartName"`
  509. ChartImage string `json:"chartImage"`
  510. UniqueCode string `json:"uniqueCode"`
  511. ChartInfoId int `json:"chartInfoId"`
  512. }
  513. type BookMarkInterface interface {
  514. GetID() int
  515. GetSourceType() string
  516. }
  517. type BookMarkReport struct {
  518. Type string `json:"type"`
  519. ReportID int `json:"reportId"`
  520. OrgId int `json:"orgId"`
  521. Title string `json:"title"`
  522. Author string `json:"author"`
  523. AuthorInfo []reportDomian.Anthor `json:"authorInfo"`
  524. Source string `json:"source"`
  525. Abstract string `json:"abstract"`
  526. PublishedTime string `json:"publishedTime"`
  527. RiskLevel string `json:"riskLevel"`
  528. PlateName string `json:"-"`
  529. ClassifyId int `json:"-"`
  530. SecondPermission map[int]string `json:"-"`
  531. Permissions map[int]string `json:"-"`
  532. PermissionNames interface {
  533. } `json:"permissionNames"`
  534. Highlight []string `json:"highlight"`
  535. Detail json.RawMessage `json:"detail"`
  536. PdfUrl string `json:"pdfUrl"`
  537. CoverSrc int `json:"coverSrc"`
  538. CoverUrl string `json:"coverUrl"`
  539. Login bool `json:"login"`
  540. RiskLevelStatus string `json:"riskLevelStatus"`
  541. IsFree bool `json:"isFree"`
  542. IsSubscribe bool `json:"isSubscribe"`
  543. SubscribeStatus string `json:"subscribeStatus"`
  544. Price string `json:"price"`
  545. ProductId int `json:"productId"`
  546. IsPackage bool `json:"isPackage"`
  547. Score float64 `json:"score"`
  548. Show bool `json:"-"`
  549. }
  550. func (bk BookMarkReport) GetID() int {
  551. return bk.ReportID
  552. }
  553. func (bk BookMarkReport) GetSourceType() string {
  554. return ReportBookMark
  555. }
  556. func (bk BookMarkChart) GetID() int {
  557. return bk.ChartInfoId
  558. }
  559. func (bk BookMarkChart) GetSourceType() string {
  560. return ChartBookMark
  561. }
  562. func SearchBookMark(key string, sourceType string, ids []int, pageInfo page.PageInfo, userId int) (list []BookMarkInterface, err error) {
  563. switch sourceType {
  564. case ReportBookMark:
  565. reportList, reportErr := reportService.SearchReportBookMark(key, ids, pageInfo, true, userId)
  566. if reportErr != nil {
  567. logger.Error("搜索研报列表失败%v", err)
  568. err = exception.NewWithException(exception.GetBookMarkListFailed, reportErr.Error())
  569. return
  570. }
  571. for _, report := range reportList {
  572. list = append(list, ConvertToBookMarkReport(report))
  573. }
  574. return
  575. case ChartBookMark:
  576. offset := page.StartIndex(pageInfo.Current, pageInfo.PageSize)
  577. chartList, chartErr := chartService.SearchChartList(key, ids, offset, pageInfo.PageSize)
  578. if chartErr != nil {
  579. logger.Error("搜索研报列表失败%v", err)
  580. err = exception.NewWithException(exception.GetBookMarkListFailed, chartErr.Error())
  581. return
  582. }
  583. for _, chart := range chartList {
  584. list = append(list, ConvertToBookMarkChart(chart))
  585. }
  586. return
  587. default:
  588. err = exception.NewWithException(exception.GetBookMarkListFailed, "不支持的收藏类型")
  589. return
  590. }
  591. }
  592. func ConvertToBookMarkChart(chart chartService.ChartInfo) BookMarkChart {
  593. return BookMarkChart{
  594. ChartName: chart.ChartName,
  595. ChartImage: chart.ChartImage,
  596. UniqueCode: chart.UniqueCode,
  597. ChartInfoId: chart.ChartInfoId,
  598. }
  599. }
  600. func ConvertToBookMarkReport(report reportDomian.ReportDTO) BookMarkReport {
  601. return BookMarkReport{
  602. Abstract: report.Abstract,
  603. Author: report.Author,
  604. AuthorInfo: report.AuthorInfo,
  605. ClassifyId: report.ClassifyId,
  606. CoverSrc: report.CoverSrc,
  607. CoverUrl: report.CoverUrl,
  608. Detail: report.Detail,
  609. Highlight: report.Highlight,
  610. IsFree: report.IsFree,
  611. IsPackage: report.IsPackage,
  612. IsSubscribe: report.IsSubscribe,
  613. Login: report.Login,
  614. OrgId: report.OrgId,
  615. PdfUrl: report.PdfUrl,
  616. PermissionNames: report.PermissionNames,
  617. Permissions: report.Permissions,
  618. PlateName: report.PlateName,
  619. Price: report.Price,
  620. ProductId: report.ProductId,
  621. PublishedTime: report.PublishedTime,
  622. ReportID: report.ReportID,
  623. RiskLevel: report.RiskLevel,
  624. RiskLevelStatus: report.RiskLevelStatus,
  625. Score: report.Score,
  626. SecondPermission: report.SecondPermission,
  627. Show: report.Show,
  628. Source: report.Source,
  629. SubscribeStatus: report.SubscribeStatus,
  630. Title: report.Title,
  631. Type: report.Type,
  632. }
  633. }