|
@@ -12,6 +12,12 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+const (
|
|
|
+ riskValid = "valid"
|
|
|
+ riskExpired = "expired"
|
|
|
+ riskUnTest = "unTest"
|
|
|
+)
|
|
|
+
|
|
|
type User struct {
|
|
|
Id int `json:"id"`
|
|
|
Username string `json:"username"`
|
|
@@ -27,6 +33,56 @@ type AnalystDetail struct {
|
|
|
Followed string `json:"Followed"`
|
|
|
}
|
|
|
|
|
|
+type UserProfile struct {
|
|
|
+ Mobile string `json:"mobile"`
|
|
|
+ RiskLevel string `json:"riskLevel"`
|
|
|
+ RiskLevelStatus string `json:"riskLevelStatus"`
|
|
|
+ UserName string `json:"userName"`
|
|
|
+}
|
|
|
+
|
|
|
+func convertUserDTOToProfile(dto userService.UserDTO) (profile UserProfile) {
|
|
|
+ profile = UserProfile{
|
|
|
+ Mobile: dto.Mobile,
|
|
|
+ RiskLevel: dto.RiskLevel,
|
|
|
+ UserName: dto.Username,
|
|
|
+ }
|
|
|
+ if profile.UserName == "" {
|
|
|
+ profile.UserName = dto.Mobile
|
|
|
+ }
|
|
|
+ if dto.RiskLevel == "" {
|
|
|
+ profile.RiskLevelStatus = riskUnTest
|
|
|
+ return
|
|
|
+ }
|
|
|
+ date, err := time.Parse(time.DateOnly, dto.RiskValidEndDate)
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("解析日期失败:%v", err)
|
|
|
+ profile.RiskLevelStatus = riskExpired
|
|
|
+ return
|
|
|
+ }
|
|
|
+ currentDate := time.Now().Truncate(24 * time.Hour)
|
|
|
+ expiryDate := date.Truncate(24 * time.Hour)
|
|
|
+ if expiryDate.Before(currentDate) {
|
|
|
+ profile.RiskLevelStatus = riskExpired
|
|
|
+ return
|
|
|
+ }
|
|
|
+ profile.RiskLevelStatus = riskValid
|
|
|
+ return
|
|
|
+}
|
|
|
+func GetUserProfile(userId int) (userProfile UserProfile, err error) {
|
|
|
+ userDTO, err := userService.GetUserById(userId)
|
|
|
+ if err != nil {
|
|
|
+ if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ logger.Error("用户不存在,用户Id:%d", userId)
|
|
|
+ err = exception.New(exception.TemplateUserNotFound)
|
|
|
+ } else {
|
|
|
+ logger.Error("获取用户信息失败:%v", err)
|
|
|
+ err = exception.New(exception.TemplateUserFoundFailed)
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ userProfile = convertUserDTOToProfile(userDTO)
|
|
|
+ return
|
|
|
+}
|
|
|
func GetAnalystDetail(userId int, analystId int) (analystDetail AnalystDetail, err error) {
|
|
|
analyst, err := analystService.GetAnalystById(analystId)
|
|
|
if err != nil {
|