user_service.go 23 KB

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