Bladeren bron

修改用户默认头像功能提交

zsy 2 maanden geleden
bovenliggende
commit
01c124b399

+ 10 - 4
src/main/java/com/rf/help/user/rest/UserController.java

@@ -31,6 +31,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.Random;
 
 /**
  * @Description: 用户注册登录等相关接口
@@ -87,8 +88,13 @@ public class UserController extends BaseController {
             userEntity.setPhone("-");
             userEntity.setGender("0");
             userEntity.setPassword("-");
-            userEntity.setAvatar("-");
-
+            Random rand = new Random();
+            int number = rand.nextInt(3) + 1;
+            if (userEntity.getGender().equals("1")){
+                userEntity.setAvatar("./userAvatar/man"+number+".png");
+            }else {
+                userEntity.setAvatar("./userAvatar/woman"+number+".png");
+            }
             userEntity = this.userService.save(userEntity);
             resultJson.put("improve",true);
         }
@@ -156,9 +162,9 @@ public class UserController extends BaseController {
                     File fileLocal = new File(FILEDIR, fileName);
                     FileUtils.copyInputStreamToFile(avatar.getInputStream(), fileLocal);
                     avatarUrl = FILEDIR + fileName;
-                    userEntity.setAvatar(avatarUrl);
+                    /*userEntity.setAvatar(avatarUrl);
                     userEntity.setUpdateTime(DateUtil.now());
-                    this.userService.save(userEntity);
+                    this.userService.save(userEntity);*/
                     return success(avatarUrl);
                 } catch (Exception e) {
                     e.printStackTrace();

BIN
userAvatar/man1.png


BIN
userAvatar/man2.png


BIN
userAvatar/man3.png


BIN
userAvatar/woman1.png


BIN
userAvatar/woman2.png


BIN
userAvatar/woman3.png