Browse Source

修复关注不存在研究员导致的异常数据

kobe6258 6 months ago
parent
commit
d786c999af
2 changed files with 12 additions and 1 deletions
  1. 1 1
      controllers/user/user_controller.go
  2. 11 0
      service/user/user_service.go

+ 1 - 1
controllers/user/user_controller.go

@@ -144,7 +144,7 @@ func (u *UserController) FollowAnalysts() {
 		var nameList []string
 		names := followAnalyst.AnalystNames
 		if strings.HasPrefix(names, ",") {
-			names = names[1:len(names)]
+			names = names[1:]
 		}
 		if strings.HasSuffix(names, ",") {
 			names = names[0 : len(names)-1]

+ 11 - 0
service/user/user_service.go

@@ -53,6 +53,9 @@ func FollowAnalystsByName(userId int, analystNames []string, followType string)
 
 			err = exception.New(exception.AnalystNotFound)
 		}
+		if FinancialAnalystDTO.Id == 0 || FinancialAnalystDTO.Name == "" {
+			continue
+		}
 		followDTO := userService.FollowDTO{
 			UserId:      userId,
 			AnalystId:   FinancialAnalystDTO.Id,
@@ -81,6 +84,10 @@ func FollowAnalyst(userId int, analystId int, followType string) (err error) {
 	if err != nil {
 		err = exception.New(exception.AnalystNotFound)
 	}
+	if FinancialAnalystDTO.Id == 0 || FinancialAnalystDTO.Name == "" {
+		err = exception.New(exception.AnalystNotFound)
+		return
+	}
 	followDTO := userService.FollowDTO{
 		UserId:      userId,
 		AnalystId:   analystId,
@@ -177,6 +184,10 @@ func FollowAnalystByName(userId int, analystName string, followType string) (err
 	if err != nil {
 		err = exception.New(exception.AnalystNotFound)
 	}
+	if FinancialAnalystDTO.Id == 0 || FinancialAnalystDTO.Name == "" {
+		err = exception.New(exception.AnalystNotFound)
+		return
+	}
 	followDTO := userService.FollowDTO{
 		UserId:      userId,
 		AnalystId:   FinancialAnalystDTO.Id,