Browse Source

用户模块 优化修改头像逻辑,当为默认头像时不删除默认头像

songfuqiang 1 năm trước cách đây
mục cha
commit
dc993078ca

+ 6 - 2
backend-core/src/main/java/cn/kdan/pdf/backend/core/service/impl/AvatarServiceImpl.java

@@ -43,6 +43,8 @@ public class AvatarServiceImpl implements AvatarService {
     @Autowired
     private OssProperties ossProperties;
 
+    private static String defaultAvatarUrl = "avatars/2018/01/02/f183029426a996325853fa244e7df661.jpg";
+
     // 图片文件类型
     public static String IMG_TYPE_PNG = "PNG";
     public static String IMG_TYPE_JPG = "JPG";
@@ -100,9 +102,11 @@ public class AvatarServiceImpl implements AvatarService {
         Date now = new Date();
         if(!CollectionUtils.isEmpty(list)){
             Avatars avatars = list.get(0);
-            // 将用户原来的头像数据先删除
+            // 将用户原来的头像数据先删除,默认头像不删除
             String oldUrl = avatars.getAvatar();
-            ossFileClient.delete(oldUrl);
+            if(!defaultAvatarUrl.equals(oldUrl)){
+                ossFileClient.delete(oldUrl);
+            }
             avatars.setAvatar(ossFileName);
             avatars.setUpdatedAt(now);
             avatarsMapper.updateByPrimaryKey(avatars);