Parcourir la Source

会员管理代码

wwh il y a 1 semaine
Parent
commit
bc3f5c4ab6

+ 0 - 2
baqing-shop/src/main/java/com/ruoyi/web/modules/mall/constant/MallConfigConstants.java

@@ -37,8 +37,6 @@ public final class MallConfigConstants
37 37
 
38 38
     public static final String MSG_DEFAULT_AVATAR_REQUIRED = "请上传会员默认头像";
39 39
 
40
-    public static final String MSG_DEFAULT_AVATAR_URL_INVALID = "会员默认头像须为有效的图片地址";
41
-
42 40
     public static final String MSG_AUTO_CONFIRM_DAYS_INVALID = "自动确认收货天数须在 1~90 之间";
43 41
 
44 42
     public static final String MSG_AFTERSALE_DAYS_INVALID = "售后申请限制天数须在 1~365 之间";

+ 5 - 28
baqing-shop/src/main/java/com/ruoyi/web/modules/mall/service/impl/MallConfigServiceImpl.java

@@ -4,7 +4,6 @@ import org.springframework.beans.factory.annotation.Autowired;
4 4
 import org.springframework.stereotype.Service;
5 5
 import org.springframework.transaction.annotation.Transactional;
6 6
 import com.ruoyi.common.utils.StringUtils;
7
-import com.ruoyi.framework.config.ServerConfig;
8 7
 import com.ruoyi.web.modules.mall.constant.MallConfigConstants;
9 8
 import com.ruoyi.web.modules.mall.domain.BizMallConfig;
10 9
 import com.ruoyi.web.modules.mall.dto.MallSettingSaveDTO;
@@ -25,9 +24,6 @@ public class MallConfigServiceImpl implements IMallConfigService, IMallConfigFac
25 24
     @Autowired
26 25
     private BizMallConfigMapper mallConfigMapper;
27 26
 
28
-    @Autowired
29
-    private ServerConfig serverConfig;
30
-
31 27
     @Override
32 28
     public MallSettingVO getSettings()
33 29
     {
@@ -49,10 +45,7 @@ public class MallConfigServiceImpl implements IMallConfigService, IMallConfigFac
49 45
         update.setShowSales(dto.getShowSales());
50 46
         update.setAutoConfirmDays(dto.getAutoConfirmDays());
51 47
         update.setAftersaleLimitDays(dto.getAftersaleLimitDays());
52
-        String avatarUrl = MallConfigSupport.normalizeDefaultAvatarUrl(
53
-                dto.getDefaultAvatar().trim(), serverConfig.getUrl());
54
-        MallConfigSupport.validateDefaultAvatarUrl(avatarUrl);
55
-        update.setDefaultAvatar(avatarUrl);
48
+        update.setDefaultAvatar(dto.getDefaultAvatar().trim());
56 49
         update.setUpdateBy(operator);
57 50
         mallConfigMapper.update(update);
58 51
     }
@@ -84,7 +77,7 @@ public class MallConfigServiceImpl implements IMallConfigService, IMallConfigFac
84 77
             vo.setPsbLink(config.getPsbLink());
85 78
         }
86 79
         vo.setShowSales(MallConfigSupport.isYes(config.getShowSales()));
87
-        vo.setDefaultAvatar(resolveDefaultAvatarUrl(config.getDefaultAvatar()));
80
+        vo.setDefaultAvatar(StringUtils.isNotEmpty(config.getDefaultAvatar()) ? config.getDefaultAvatar() : null);
88 81
         vo.setCurrencySymbol(config.getCurrencySymbol());
89 82
         return vo;
90 83
     }
@@ -119,7 +112,8 @@ public class MallConfigServiceImpl implements IMallConfigService, IMallConfigFac
119 112
     @Override
120 113
     public String getDefaultAvatarUrl()
121 114
     {
122
-        return resolveDefaultAvatarUrl(requireConfig().getDefaultAvatar());
115
+        String avatar = requireConfig().getDefaultAvatar();
116
+        return StringUtils.isNotEmpty(avatar) ? avatar : null;
123 117
     }
124 118
 
125 119
     @Override
@@ -165,27 +159,10 @@ public class MallConfigServiceImpl implements IMallConfigService, IMallConfigFac
165 159
         vo.setAftersaleLimitDays(config.getAftersaleLimitDays());
166 160
         vo.setPaidOrderCancelable(Boolean.FALSE);
167 161
         vo.setShippedOrderCancelable(Boolean.FALSE);
168
-        vo.setDefaultAvatar(resolveDefaultAvatarUrl(config.getDefaultAvatar()));
162
+        vo.setDefaultAvatar(config.getDefaultAvatar());
169 163
         return vo;
170 164
     }
171 165
 
172
-    private String resolveDefaultAvatarUrl(String stored)
173
-    {
174
-        if (StringUtils.isEmpty(stored))
175
-        {
176
-            return null;
177
-        }
178
-        String serverUrl = null;
179
-        try
180
-        {
181
-            serverUrl = serverConfig.getUrl();
182
-        }
183
-        catch (Exception ignored)
184
-        {
185
-        }
186
-        return MallConfigSupport.normalizeDefaultAvatarUrl(stored, serverUrl);
187
-    }
188
-
189 166
     private String trimToNull(String value)
190 167
     {
191 168
         if (StringUtils.isEmpty(value))

+ 0 - 41
baqing-shop/src/main/java/com/ruoyi/web/modules/mall/support/MallConfigSupport.java

@@ -45,47 +45,6 @@ public final class MallConfigSupport
45 45
         validateOptionalUrl(dto.getPsbLink());
46 46
     }
47 47
 
48
-    /**
49
-     * 将会员默认头像规范为可访问的 HTTP(S) 地址;已是完整 URL 则原样返回。
50
-     */
51
-    public static String normalizeDefaultAvatarUrl(String avatar, String serverBaseUrl)
52
-    {
53
-        if (StringUtils.isEmpty(avatar))
54
-        {
55
-            return avatar;
56
-        }
57
-        String trimmed = avatar.trim();
58
-        if (trimmed.startsWith("http://") || trimmed.startsWith("https://"))
59
-        {
60
-            return trimmed;
61
-        }
62
-        if (StringUtils.isEmpty(serverBaseUrl))
63
-        {
64
-            return trimmed;
65
-        }
66
-        String base = serverBaseUrl.endsWith("/")
67
-                ? serverBaseUrl.substring(0, serverBaseUrl.length() - 1)
68
-                : serverBaseUrl;
69
-        if (!trimmed.startsWith("/"))
70
-        {
71
-            trimmed = "/" + trimmed;
72
-        }
73
-        return base + trimmed;
74
-    }
75
-
76
-    public static void validateDefaultAvatarUrl(String url)
77
-    {
78
-        if (StringUtils.isEmpty(url))
79
-        {
80
-            throw new ServiceException(MallConfigConstants.MSG_DEFAULT_AVATAR_REQUIRED);
81
-        }
82
-        String trimmed = url.trim();
83
-        if (!trimmed.startsWith("http://") && !trimmed.startsWith("https://"))
84
-        {
85
-            throw new ServiceException(MallConfigConstants.MSG_DEFAULT_AVATAR_URL_INVALID);
86
-        }
87
-    }
88
-
89 48
     public static boolean isYes(String flag)
90 49
     {
91 50
         return MallConfigConstants.FLAG_YES.equals(flag);

+ 0 - 32
baqing-shop/src/test/java/com/ruoyi/web/modules/mall/service/MallConfigServiceImplTest.java

@@ -8,12 +8,10 @@ import static org.mockito.Mockito.verify;
8 8
 import static org.mockito.Mockito.when;
9 9
 import org.junit.jupiter.api.Test;
10 10
 import org.junit.jupiter.api.extension.ExtendWith;
11
-import org.mockito.ArgumentCaptor;
12 11
 import org.mockito.InjectMocks;
13 12
 import org.mockito.Mock;
14 13
 import org.mockito.junit.jupiter.MockitoExtension;
15 14
 import com.ruoyi.common.exception.ServiceException;
16
-import com.ruoyi.framework.config.ServerConfig;
17 15
 import com.ruoyi.web.modules.mall.constant.MallConfigConstants;
18 16
 import com.ruoyi.web.modules.mall.domain.BizMallConfig;
19 17
 import com.ruoyi.web.modules.mall.dto.MallSettingSaveDTO;
@@ -27,9 +25,6 @@ class MallConfigServiceImplTest
27 25
     @Mock
28 26
     private BizMallConfigMapper mallConfigMapper;
29 27
 
30
-    @Mock
31
-    private ServerConfig serverConfig;
32
-
33 28
     @InjectMocks
34 29
     private MallConfigServiceImpl mallConfigService;
35 30
 
@@ -68,39 +63,12 @@ class MallConfigServiceImplTest
68 63
     void updateSettings_success()
69 64
     {
70 65
         when(mallConfigMapper.selectById(MallConfigConstants.CONFIG_ID)).thenReturn(config());
71
-        when(serverConfig.getUrl()).thenReturn("http://localhost:8020");
72 66
 
73 67
         mallConfigService.updateSettings(validDto(), "admin");
74 68
 
75 69
         verify(mallConfigMapper).update(any(BizMallConfig.class));
76 70
     }
77 71
 
78
-    @Test
79
-    void updateSettings_normalizesRelativeAvatarToHttpUrl()
80
-    {
81
-        when(mallConfigMapper.selectById(MallConfigConstants.CONFIG_ID)).thenReturn(config());
82
-        when(serverConfig.getUrl()).thenReturn("http://localhost:8020");
83
-        MallSettingSaveDTO dto = validDto();
84
-        dto.setDefaultAvatar("/profile/upload/2026/05/26/a.png");
85
-
86
-        mallConfigService.updateSettings(dto, "admin");
87
-
88
-        ArgumentCaptor<BizMallConfig> captor = ArgumentCaptor.forClass(BizMallConfig.class);
89
-        verify(mallConfigMapper).update(captor.capture());
90
-        assertEquals("http://localhost:8020/profile/upload/2026/05/26/a.png", captor.getValue().getDefaultAvatar());
91
-    }
92
-
93
-    @Test
94
-    void getDefaultAvatarUrl_resolvesLegacyRelativePath()
95
-    {
96
-        BizMallConfig c = config();
97
-        c.setDefaultAvatar("/profile/upload/default.png");
98
-        when(mallConfigMapper.selectById(MallConfigConstants.CONFIG_ID)).thenReturn(c);
99
-        when(serverConfig.getUrl()).thenReturn("http://localhost:8020");
100
-
101
-        assertEquals("http://localhost:8020/profile/upload/default.png", mallConfigService.getDefaultAvatarUrl());
102
-    }
103
-
104 72
     private MallSettingSaveDTO validDto()
105 73
     {
106 74
         MallSettingSaveDTO dto = new MallSettingSaveDTO();

+ 0 - 45
baqing-shop/src/test/java/com/ruoyi/web/modules/mall/support/MallConfigSupportTest.java

@@ -1,45 +0,0 @@
1
-package com.ruoyi.web.modules.mall.support;
2
-
3
-import static org.junit.jupiter.api.Assertions.assertEquals;
4
-import static org.junit.jupiter.api.Assertions.assertThrows;
5
-import org.junit.jupiter.api.Test;
6
-import com.ruoyi.common.exception.ServiceException;
7
-import com.ruoyi.web.modules.mall.constant.MallConfigConstants;
8
-
9
-class MallConfigSupportTest
10
-{
11
-    @Test
12
-    void normalizeDefaultAvatarUrl_keepsHttpUrl()
13
-    {
14
-        assertEquals("https://cdn.example.com/a.png",
15
-                MallConfigSupport.normalizeDefaultAvatarUrl("https://cdn.example.com/a.png", "http://localhost:8020"));
16
-    }
17
-
18
-    @Test
19
-    void normalizeDefaultAvatarUrl_prependsServerBase()
20
-    {
21
-        assertEquals("http://localhost:8020/profile/upload/a.png",
22
-                MallConfigSupport.normalizeDefaultAvatarUrl("/profile/upload/a.png", "http://localhost:8020"));
23
-    }
24
-
25
-    @Test
26
-    void validateDefaultAvatarUrl_rejectsRelativePath()
27
-    {
28
-        assertThrows(ServiceException.class,
29
-                () -> MallConfigSupport.validateDefaultAvatarUrl("/profile/upload/a.png"));
30
-    }
31
-
32
-    @Test
33
-    void validateDefaultAvatarUrl_acceptsHttpUrl()
34
-    {
35
-        MallConfigSupport.validateDefaultAvatarUrl("https://example.com/a.png");
36
-    }
37
-
38
-    @Test
39
-    void validateDefaultAvatarUrl_emptyThrowsRequiredMessage()
40
-    {
41
-        ServiceException ex = assertThrows(ServiceException.class,
42
-                () -> MallConfigSupport.validateDefaultAvatarUrl(""));
43
-        assertEquals(MallConfigConstants.MSG_DEFAULT_AVATAR_REQUIRED, ex.getMessage());
44
-    }
45
-}