Commit 97972c487e16da7e51ee838bad3af652eeb34602
1 parent
0c97c499
feature(*): 自动填充username
- 自动填充username
Showing
8 changed files
with
323 additions
and
3 deletions
fw-hestia-common/src/main/java/cn/fw/hestia/common/constant/Constant.java
0 → 100644
1 | +package cn.fw.hestia.common.constant; | |
2 | + | |
3 | +/** | |
4 | + * 常量 | |
5 | + * | |
6 | + * @author : kurisu | |
7 | + * @version : 2.0 | |
8 | + * @desc : 常量 | |
9 | + * @date : 2023-08-10 10:51 | |
10 | + */ | |
11 | +public interface Constant { | |
12 | + String MEMBER_INFO_CACHE = "member:info:id"; | |
13 | + String MEMBER_INFO_MOBILE_CACHE = "member:info:mobile"; | |
14 | +} | ... | ... |
fw-hestia-rpc/pom.xml
... | ... | @@ -27,6 +27,10 @@ |
27 | 27 | <groupId>cn.fw</groupId> |
28 | 28 | <artifactId>fw-passport-sdk</artifactId> |
29 | 29 | </dependency> |
30 | + <dependency> | |
31 | + <groupId>cn.fw</groupId> | |
32 | + <artifactId>fw-member-sdk</artifactId> | |
33 | + </dependency> | |
30 | 34 | <!-- fw common --> |
31 | 35 | <dependency> |
32 | 36 | <groupId>cn.fw</groupId> | ... | ... |
fw-hestia-rpc/src/main/java/cn/fw/hestia/rpc/member/MemberRpcService.java
0 → 100644
1 | +package cn.fw.hestia.rpc.member; | |
2 | + | |
3 | +import cn.fw.common.util.MobileUtil; | |
4 | +import cn.fw.data.base.domain.common.Message; | |
5 | +import cn.fw.hestia.common.constant.Constant; | |
6 | +import cn.fw.hestia.rpc.member.dto.MemberUserDTO; | |
7 | +import cn.fw.member.sdk.api.FunctionApi; | |
8 | +import cn.fw.member.sdk.api.MemberApi; | |
9 | +import cn.fw.member.sdk.vo.BatchUserParam; | |
10 | +import cn.fw.member.sdk.vo.MobileLocation; | |
11 | +import cn.fw.member.sdk.vo.UserBaseInfoVO; | |
12 | +import cn.fw.member.sdk.vo.UserRegistryVO; | |
13 | +import lombok.extern.slf4j.Slf4j; | |
14 | +import org.apache.commons.lang3.StringUtils; | |
15 | +import org.springframework.beans.BeanUtils; | |
16 | +import org.springframework.beans.factory.annotation.Autowired; | |
17 | +import org.springframework.cache.annotation.Cacheable; | |
18 | +import org.springframework.stereotype.Service; | |
19 | +import org.springframework.util.CollectionUtils; | |
20 | + | |
21 | +import java.util.ArrayList; | |
22 | +import java.util.Collections; | |
23 | +import java.util.List; | |
24 | +import java.util.Objects; | |
25 | + | |
26 | +import static org.apache.commons.lang3.Validate.isTrue; | |
27 | +import static org.apache.commons.lang3.Validate.notNull; | |
28 | + | |
29 | +/** | |
30 | + * 会员服务 | |
31 | + * | |
32 | + * @author kurisu | |
33 | + */ | |
34 | +@Slf4j | |
35 | +@Service | |
36 | +public class MemberRpcService { | |
37 | + /** | |
38 | + * 会员服务 | |
39 | + */ | |
40 | + private final MemberApi memberApi; | |
41 | + private final FunctionApi functionApi; | |
42 | + | |
43 | + /** | |
44 | + * 默认构造器 | |
45 | + */ | |
46 | + @Autowired | |
47 | + public MemberRpcService(final MemberApi memberApi, | |
48 | + final FunctionApi functionApi) { | |
49 | + this.memberApi = memberApi; | |
50 | + this.functionApi = functionApi; | |
51 | + } | |
52 | + | |
53 | + /** | |
54 | + * 根据会员ID获取会员信息 | |
55 | + * | |
56 | + * @param userId 会员ID | |
57 | + * @return 会员信息 | |
58 | + */ | |
59 | + @Cacheable(cacheNames = Constant.MEMBER_INFO_CACHE, key = "#userId", unless = "#result == null ") | |
60 | + public MemberUserDTO user(final Long userId) { | |
61 | + if (userId == null) { | |
62 | + return null; | |
63 | + } | |
64 | + try { | |
65 | + final Message<UserBaseInfoVO> msg = memberApi.queryUserByuserId(userId); | |
66 | + if (!msg.isSuccess()) { | |
67 | + log.warn("调用Member[根据会员ID[{}]获取会员信息]系统失败, 原因:{}", userId, msg.getResult()); | |
68 | + return null; | |
69 | + } | |
70 | + final UserBaseInfoVO user = msg.getData(); | |
71 | + if (user != null) { | |
72 | + final MemberUserDTO userDTO = new MemberUserDTO(); | |
73 | + BeanUtils.copyProperties(user, userDTO); | |
74 | + return userDTO; | |
75 | + } | |
76 | + } catch (Exception e) { | |
77 | + log.error("调用Member[根据会员ID[{}]获取会员信息]系统失败", userId, e); | |
78 | + } | |
79 | + return null; | |
80 | + } | |
81 | + | |
82 | + /** | |
83 | + * 根据会员ID集合获取会员列表 | |
84 | + * | |
85 | + * @param userIds 会员ID集合 | |
86 | + * @return 会员列表 | |
87 | + */ | |
88 | + public List<MemberUserDTO> users(final List<Long> userIds) { | |
89 | + if (CollectionUtils.isEmpty(userIds)) { | |
90 | + return Collections.emptyList(); | |
91 | + } | |
92 | + try { | |
93 | + final BatchUserParam param = new BatchUserParam(); | |
94 | + param.setUserIdList(userIds); | |
95 | + final Message<List<UserBaseInfoVO>> msg = memberApi.batchUserByUserId(param); | |
96 | + if (!msg.isSuccess()) { | |
97 | + log.warn("调用Member[根据会员ID集合[{}]获取会员列表]系统失败, 原因:{}", userIds, msg.getResult()); | |
98 | + return Collections.emptyList(); | |
99 | + } | |
100 | + final List<UserBaseInfoVO> users = msg.getData(); | |
101 | + if (!CollectionUtils.isEmpty(users)) { | |
102 | + final List<MemberUserDTO> members = new ArrayList<>(); | |
103 | + users.forEach(item -> { | |
104 | + final MemberUserDTO userDTO = new MemberUserDTO(); | |
105 | + BeanUtils.copyProperties(item, userDTO); | |
106 | + members.add(userDTO); | |
107 | + }); | |
108 | + return members; | |
109 | + } | |
110 | + } catch (Exception e) { | |
111 | + log.error("调用Member[根据会员ID集合[{}]获取会员列表]系统失败", userIds, e); | |
112 | + } | |
113 | + return Collections.emptyList(); | |
114 | + } | |
115 | + | |
116 | + /** | |
117 | + * 根据手机号查询会员信息 | |
118 | + * | |
119 | + * @param mobile 手机号 | |
120 | + * @return 会员信息 | |
121 | + */ | |
122 | + @Cacheable(cacheNames = Constant.MEMBER_INFO_MOBILE_CACHE, key = "#mobile", unless = "#result == null ") | |
123 | + public MemberUserDTO queryByMobile(final String mobile) { | |
124 | + if (StringUtils.isBlank(mobile)) { | |
125 | + return null; | |
126 | + } | |
127 | + try { | |
128 | + final Message<UserBaseInfoVO> msg = memberApi.queryUserByMobile(mobile); | |
129 | + isTrue(msg.isSuccess(), String.format("调用Member系统失败: [根据会员手机号[%s]获取会员信息]", mobile)); | |
130 | + final UserBaseInfoVO user = msg.getData(); | |
131 | + if (Objects.isNull(user)) { | |
132 | + return null; | |
133 | + } | |
134 | + final MemberUserDTO userDTO = new MemberUserDTO(); | |
135 | + BeanUtils.copyProperties(user, userDTO); | |
136 | + return userDTO; | |
137 | + } catch (Exception e) { | |
138 | + log.error("调用Member系统根据会员手机号[{}]获取会员信息失败", mobile, e); | |
139 | + } | |
140 | + return null; | |
141 | + } | |
142 | + | |
143 | + /** | |
144 | + * 注册会员 | |
145 | + * | |
146 | + * @param memberUser 注册信息 | |
147 | + * @return 会员 | |
148 | + */ | |
149 | + public MemberUserDTO register(final MemberUserDTO memberUser) { | |
150 | + notNull(memberUser, "会员注册信息不能为空"); | |
151 | + UserRegistryVO vo = new UserRegistryVO(); | |
152 | + BeanUtils.copyProperties(memberUser, vo); | |
153 | + vo.setNickName(StringUtils.isNotBlank(memberUser.getNickName()) ? memberUser.getNickName() : memberUser.getRealName()); | |
154 | + final Message<UserBaseInfoVO> msg = memberApi.register(vo); | |
155 | + isTrue(msg.isSuccess(), String.format("调用Member[注册会员[%s]]系统失败", vo)); | |
156 | + final UserBaseInfoVO user = msg.getData(); | |
157 | + notNull(user, String.format("调用Member[注册会员[%s]]系统失败,返回会员信息为空", vo)); | |
158 | + final MemberUserDTO userDTO = new MemberUserDTO(); | |
159 | + BeanUtils.copyProperties(user, userDTO); | |
160 | + return userDTO; | |
161 | + } | |
162 | + | |
163 | + /** | |
164 | + * 查询手机号归属地 | |
165 | + * | |
166 | + * @param mobile | |
167 | + * @return | |
168 | + */ | |
169 | + @Cacheable(cacheNames = "mobile:attribution", key = "#mobile", unless = "#result.isEmpty()") | |
170 | + public String attribution(final String mobile) { | |
171 | + if (StringUtils.isBlank(mobile)) { | |
172 | + return ""; | |
173 | + } | |
174 | + try { | |
175 | + MobileUtil.Result result = MobileUtil.attribution(mobile); | |
176 | + String att = ""; | |
177 | + if (Objects.nonNull(result)) { | |
178 | + att = result.getProvince().concat(" ").concat(result.getCity()); | |
179 | + } | |
180 | + | |
181 | + if (!StringUtils.isBlank(att.trim())) { | |
182 | + return att.trim(); | |
183 | + } | |
184 | + | |
185 | + Message<MobileLocation> msg = functionApi.queryMobileLocation(mobile); | |
186 | + if (!msg.isSuccess()) { | |
187 | + return ""; | |
188 | + } | |
189 | + MobileLocation data = msg.getData(); | |
190 | + if (data != null) { | |
191 | + String province = data.getProvince(); | |
192 | + String city = data.getCity(); | |
193 | + att = province.concat(" ").concat(city); | |
194 | + } | |
195 | + return att.trim(); | |
196 | + } catch (Exception e) { | |
197 | + log.warn("查询手机号归属地失败:", e); | |
198 | + } | |
199 | + return ""; | |
200 | + } | |
201 | + | |
202 | +} | ... | ... |
fw-hestia-rpc/src/main/java/cn/fw/hestia/rpc/member/dto/MemberUserDTO.java
0 → 100644
1 | +package cn.fw.hestia.rpc.member.dto; | |
2 | + | |
3 | +import lombok.Data; | |
4 | + | |
5 | +import java.io.Serializable; | |
6 | +import java.util.Date; | |
7 | + | |
8 | +/** | |
9 | + * 会员信息 | |
10 | + * <p> | |
11 | + * create at 2019-05-09 | |
12 | + * | |
13 | + * @author kurisu | |
14 | + */ | |
15 | +@Data | |
16 | +public class MemberUserDTO implements Serializable { | |
17 | + /** | |
18 | + * 用户Id | |
19 | + */ | |
20 | + private Long userId; | |
21 | + | |
22 | + /** | |
23 | + * 真实姓名 | |
24 | + */ | |
25 | + private String realName; | |
26 | + | |
27 | + /** | |
28 | + * 会员昵称 | |
29 | + */ | |
30 | + private String nickName; | |
31 | + | |
32 | + /** | |
33 | + * 手机号 | |
34 | + */ | |
35 | + private String phone; | |
36 | + | |
37 | + /** | |
38 | + * 用户头像URL | |
39 | + */ | |
40 | + private String avatarUrl; | |
41 | + | |
42 | + /** | |
43 | + * 证件类型 | |
44 | + */ | |
45 | + private Integer credentType; | |
46 | + | |
47 | + /** | |
48 | + * 证件号码 | |
49 | + */ | |
50 | + private String credentNo; | |
51 | + | |
52 | + /** | |
53 | + * 性别 | |
54 | + */ | |
55 | + private Integer sex; | |
56 | + | |
57 | + /** | |
58 | + * 生日 | |
59 | + */ | |
60 | + private Date birthday; | |
61 | + | |
62 | +} | ... | ... |
fw-hestia-rpc/src/main/java/cn/fw/hestia/rpc/member/dto/MemberUserLevelDTO.java
0 → 100644
1 | +package cn.fw.hestia.rpc.member.dto; | |
2 | + | |
3 | +import lombok.Data; | |
4 | + | |
5 | +/** | |
6 | + * 客户level | |
7 | + * <p> | |
8 | + * create at 2019-05-16 | |
9 | + * | |
10 | + * @author kurisu | |
11 | + */ | |
12 | +@Data | |
13 | +public class MemberUserLevelDTO { | |
14 | + private Long cusId; | |
15 | + private Integer levelType; | |
16 | + private Integer growth; | |
17 | + private String cusName; | |
18 | + private String phone; | |
19 | +} | ... | ... |
fw-hestia-server/src/main/resources/application.yml
fw-hestia-service/src/main/java/cn/fw/hestia/service/buz/MessageCenterBizService.java
... | ... | @@ -12,6 +12,8 @@ import cn.fw.hestia.domain.db.SendLog; |
12 | 12 | import cn.fw.hestia.domain.enums.MessageStateEnum; |
13 | 13 | import cn.fw.hestia.domain.vo.HistoryQuery; |
14 | 14 | import cn.fw.hestia.domain.vo.MessageHistoryVO; |
15 | +import cn.fw.hestia.rpc.member.MemberRpcService; | |
16 | +import cn.fw.hestia.rpc.member.dto.MemberUserDTO; | |
15 | 17 | import cn.fw.hestia.rpc.passport.TemplateMessageService; |
16 | 18 | import cn.fw.hestia.rpc.passport.dto.TMParam; |
17 | 19 | import cn.fw.hestia.sdk.params.TemplateMessageParam; |
... | ... | @@ -60,6 +62,7 @@ public class MessageCenterBizService { |
60 | 62 | private final SendMsgProducer sendMsgProducer; |
61 | 63 | private final StringRedisTemplate redisTemplate; |
62 | 64 | private final SettingProperty settingProperty; |
65 | + private final MemberRpcService memberRpcService; | |
63 | 66 | |
64 | 67 | @Value("${spring.cache.custom.global-prefix}:template:code") |
65 | 68 | @Getter |
... | ... | @@ -295,8 +298,9 @@ public class MessageCenterBizService { |
295 | 298 | } |
296 | 299 | |
297 | 300 | private MessageHistory createBeans(TemplateMessageParam param) { |
301 | + Long memberId = param.getMemberId(); | |
298 | 302 | MessageHistory messageHistory = new MessageHistory(); |
299 | - messageHistory.setMemberId(param.getMemberId()); | |
303 | + messageHistory.setMemberId(memberId); | |
300 | 304 | messageHistory.setTemplateCode(settingProperty.getTempId()); |
301 | 305 | messageHistory.setTitle(param.getTitle()); |
302 | 306 | StringBuilder content = new StringBuilder(param.getContent()); |
... | ... | @@ -317,8 +321,13 @@ public class MessageCenterBizService { |
317 | 321 | messageHistory.setYn(Boolean.TRUE); |
318 | 322 | messageHistory.setSendTime(new Date()); |
319 | 323 | messageHistory.setState(MessageStateEnum.MADA); |
324 | + String userName = "佚名"; | |
325 | + MemberUserDTO memberInfo = memberRpcService.user(memberId); | |
326 | + if (Objects.nonNull(memberInfo)) { | |
327 | + userName = StringUtils.isEmpty(memberInfo.getRealName()) ? memberInfo.getNickName() : memberInfo.getRealName(); | |
328 | + } | |
320 | 329 | List<WxMpTempMessageData> keywords = Arrays.asList( |
321 | - new WxMpTempMessageData(settingProperty.getThing3(), param.getTitle()), | |
330 | + new WxMpTempMessageData(settingProperty.getThing3(), userName), | |
322 | 331 | new WxMpTempMessageData(settingProperty.getThing13(), StringUtils.isEmpty(param.getShopName()) ? "无" : param.getShopName()) |
323 | 332 | ); |
324 | 333 | messageHistory.setKeywords(JSONArray.toJSONString(keywords)); | ... | ... |
pom.xml
... | ... | @@ -39,6 +39,7 @@ |
39 | 39 | <fw-passport-sdk.version>2.2.0</fw-passport-sdk.version> |
40 | 40 | <yitter.idgenerator>1.0.6</yitter.idgenerator> |
41 | 41 | <hutool.version>5.2.5</hutool.version> |
42 | + <fw-member-sdk.version>2.0</fw-member-sdk.version> | |
42 | 43 | </properties> |
43 | 44 | |
44 | 45 | <dependencyManagement> |
... | ... | @@ -99,6 +100,11 @@ |
99 | 100 | </dependency> |
100 | 101 | <dependency> |
101 | 102 | <groupId>cn.fw</groupId> |
103 | + <artifactId>fw-member-sdk</artifactId> | |
104 | + <version>${fw-member-sdk.version}</version> | |
105 | + </dependency> | |
106 | + <dependency> | |
107 | + <groupId>cn.fw</groupId> | |
102 | 108 | <artifactId>fw-hestia-sdk</artifactId> |
103 | 109 | <version>${fw.hestia.sdk.version}</version> |
104 | 110 | </dependency> | ... | ... |