Commit cf5b675fb3ea18fd2e6a0575900f0ed5e7b1c5a9

Authored by 张志伟
1 parent 04d4da77

feature(*): 对接新版模板消息

- 对接新版模板消息
fw-hestia-domain/src/main/java/cn/fw/hestia/domain/db/MessageHistory.java
... ... @@ -28,6 +28,7 @@ public class MessageHistory extends Model<MessageHistory> {
28 28 private Long memberId;
29 29 /**
30 30 * 模板code
  31 + * 新版对应模板id
31 32 */
32 33 private String templateCode;
33 34 /**
... ...
fw-hestia-rpc/src/main/java/cn/fw/hestia/rpc/passport/TemplateMessageService.java
... ... @@ -40,11 +40,7 @@ public class TemplateMessageService {
40 40 try {
41 41 WxMpTempMessageParam param = new WxMpTempMessageParam();
42 42 param.setCusId(messageParam.getMemberId());
43   - param.setTempCode(messageParam.getTemplateCode());
44   - WxMpTempMessageData remark = new WxMpTempMessageData();
45   - remark.setValue(messageParam.getRemark());
46   - param.setRemark(remark);
47   - param.setTitle(new WxMpTempMessageData(messageParam.getTitle()));
  43 + param.setTempId(messageParam.getTemplateCode());
48 44 if (StringUtils.isValid(messageParam.getKeywords())) {
49 45 List<WxMpTempMessageData> keywords = JSONArray.parseArray(messageParam.getKeywords(), WxMpTempMessageData.class);
50 46 param.setKeyWordList(keywords);
... ...
fw-hestia-rpc/src/main/java/cn/fw/hestia/rpc/passport/dto/TMParam.java
... ... @@ -42,6 +42,9 @@ public class TMParam {
42 42  
43 43  
44 44 private Long sceneToken;
45   -
  45 + /**
  46 + * 模板code
  47 + * 新版对应模板id
  48 + */
46 49 private String templateCode;
47 50 }
... ...
fw-hestia-sdk/src/main/java/cn/fw/hestia/sdk/params/TemplateMessageParam.java
... ... @@ -41,6 +41,10 @@ public class TemplateMessageParam {
41 41 @NotBlank(message = "消息内容不能为空")
42 42 private String content;
43 43 /**
  44 + * 门店名称
  45 + */
  46 + private String shopName;
  47 + /**
44 48 * 额外展示内容
45 49 */
46 50 @Size(max = 5, message = "最多展示5条额外信息")
... ...
fw-hestia-server/src/main/java/cn/fw/hestia/server/Application.java
1 1 package cn.fw.hestia.server;
2 2  
  3 +import cn.fw.hestia.component.SettingProperty;
3 4 import cn.fw.security.auth.client.EnableAuthClient;
4 5 import org.mybatis.spring.annotation.MapperScan;
5 6 import org.springframework.boot.SpringApplication;
6 7 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  8 +import org.springframework.boot.context.properties.EnableConfigurationProperties;
7 9 import org.springframework.cache.annotation.EnableCaching;
8 10 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
9 11 import org.springframework.cloud.openfeign.EnableFeignClients;
... ... @@ -26,6 +28,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
26 28 @EnableAutoConfiguration
27 29 @Configuration
28 30 @EnableRedisRepositories
  31 +@EnableConfigurationProperties({SettingProperty.class})
29 32 @MapperScan("cn.fw.hestia.**.dao")
30 33 @ComponentScan({"cn.fw.hestia.*"})
31 34 @EnableFeignClients({"cn.fw.**.sdk"})
... ...
fw-hestia-server/src/main/java/cn/fw/hestia/server/controller/common/CommonController.java
... ... @@ -42,17 +42,9 @@ public class CommonController {
42 42 return success(messageCenterBizService.manualSend(sceneToken));
43 43 }
44 44  
45   - @GetMapping("/change/code")
46   - @ControllerMethod("修改模板码")
47   - public Message<Void> changeCode(@NotEmpty(message = "模板码不能为空") final String code) {
48   - messageCenterBizService.changeRdsTemplateCode(code);
49   - return success();
50   - }
51   -
52 45 @GetMapping("/query/code")
53 46 @ControllerMethod("查询模板码")
54 47 public Message<String> getCode() {
55 48 return success(messageCenterBizService.getRdsTemplateCode());
56 49 }
57   -
58 50 }
... ...
fw-hestia-server/src/main/resources/application.yml
... ... @@ -132,4 +132,9 @@ management:
132 132  
133 133 task:
134 134 switch: 'on'
135   - max-size: 1000
136 135 \ No newline at end of file
  136 + max-size: 1000
  137 +
  138 +mptemplate:
  139 + tempId: CH-nLDVe5bHggBTXQJJWudqn1UnaBQNDmp5GEeYXSMM
  140 + typeSort1: thing3
  141 + typeSort2: thing13
137 142 \ No newline at end of file
... ...
fw-hestia-service/src/main/java/cn/fw/hestia/component/SettingProperty.java 0 → 100644
  1 +package cn.fw.hestia.component;
  2 +
  3 +import lombok.Getter;
  4 +import lombok.Setter;
  5 +import org.springframework.boot.context.properties.ConfigurationProperties;
  6 +
  7 +/**
  8 + * 模板配置信息
  9 + *
  10 + * @author : kurisu
  11 + * @version : 2.0
  12 + * @desc : 模板配置信息
  13 + * @date : 2023-07-20 18:03
  14 + */
  15 +@Getter
  16 +@Setter
  17 +@ConfigurationProperties(prefix = "mptemplate")
  18 +public class SettingProperty {
  19 + private String tempId;
  20 + private String thing3;
  21 + private String thing13;
  22 +
  23 + @Override
  24 + public String toString() {
  25 + return "SettingProperty{" +
  26 + "tempId='" + tempId + '\'' +
  27 + ", thing3='" + thing3 + '\'' +
  28 + ", thing13='" + thing13 + '\'' +
  29 + '}';
  30 + }
  31 +}
... ...
fw-hestia-service/src/main/java/cn/fw/hestia/service/buz/MessageCenterBizService.java
... ... @@ -6,6 +6,7 @@ import cn.fw.hestia.common.constant.MessageConstant;
6 6 import cn.fw.hestia.common.utils.DateUtil;
7 7 import cn.fw.hestia.common.utils.StringUtils;
8 8 import cn.fw.hestia.component.SendMsgProducer;
  9 +import cn.fw.hestia.component.SettingProperty;
9 10 import cn.fw.hestia.domain.db.MessageHistory;
10 11 import cn.fw.hestia.domain.db.SendLog;
11 12 import cn.fw.hestia.domain.enums.MessageStateEnum;
... ... @@ -28,7 +29,6 @@ import lombok.extern.slf4j.Slf4j;
28 29 import org.springframework.beans.factory.annotation.Value;
29 30 import org.springframework.cache.annotation.Cacheable;
30 31 import org.springframework.data.redis.core.BoundSetOperations;
31   -import org.springframework.data.redis.core.BoundValueOperations;
32 32 import org.springframework.data.redis.core.StringRedisTemplate;
33 33 import org.springframework.stereotype.Service;
34 34 import org.springframework.transaction.annotation.Transactional;
... ... @@ -59,6 +59,7 @@ public class MessageCenterBizService {
59 59 private final TemplateMessageService templateMessageService;
60 60 private final SendMsgProducer sendMsgProducer;
61 61 private final StringRedisTemplate redisTemplate;
  62 + private final SettingProperty settingProperty;
62 63  
63 64 @Value("${spring.cache.custom.global-prefix}:template:code")
64 65 @Getter
... ... @@ -183,6 +184,7 @@ public class MessageCenterBizService {
183 184 * @param sceneToken
184 185 * @return
185 186 */
  187 + @Transactional(rollbackFor = Exception.class)
186 188 @Cacheable(cacheNames = "ExchangePageParam", key = "':Exchange-Page-Param:' + #sceneToken", condition = "#result != null")
187 189 public Map<String, String> queryPageParams(Long sceneToken) {
188 190 MessageHistory history = messageHistoryService.getById(sceneToken);
... ... @@ -247,8 +249,7 @@ public class MessageCenterBizService {
247 249 messageHistoryService.updateBatchById(list);
248 250 }
249 251  
250   - @Transactional(rollbackFor = Exception.class)
251   - protected void readMessage(MessageHistory history) {
  252 + public void readMessage(MessageHistory history) {
252 253 if (Boolean.FALSE.equals(history.getReadz())) {
253 254 history.setReadz(Boolean.TRUE);
254 255 history.setState(MessageStateEnum.SUMI);
... ... @@ -268,14 +269,8 @@ public class MessageCenterBizService {
268 269 return result;
269 270 }
270 271  
271   - public void changeRdsTemplateCode(String code) {
272   - BoundValueOperations<String, String> boundValueOps = redisTemplate.boundValueOps(getKeyPrefix());
273   - boundValueOps.set(code);
274   - }
275   -
276 272 public String getRdsTemplateCode() {
277   - BoundValueOperations<String, String> boundValueOps = redisTemplate.boundValueOps(getKeyPrefix());
278   - return boundValueOps.get();
  273 + return settingProperty.getTempId();
279 274 }
280 275  
281 276 private String saveLog(TMParam tmParam, Long messageId, Consumer<SendLog> cons) {
... ... @@ -302,7 +297,7 @@ public class MessageCenterBizService {
302 297 private MessageHistory createBeans(TemplateMessageParam param) {
303 298 MessageHistory messageHistory = new MessageHistory();
304 299 messageHistory.setMemberId(param.getMemberId());
305   - messageHistory.setTemplateCode(getTemplateCode());
  300 + messageHistory.setTemplateCode(settingProperty.getTempId());
306 301 messageHistory.setTitle(param.getTitle());
307 302 StringBuilder content = new StringBuilder(param.getContent());
308 303 if (!CollectionUtils.isEmpty(param.getExtraMap())) {
... ... @@ -323,8 +318,8 @@ public class MessageCenterBizService {
323 318 messageHistory.setSendTime(new Date());
324 319 messageHistory.setState(MessageStateEnum.MADA);
325 320 List<WxMpTempMessageData> keywords = Arrays.asList(
326   - new WxMpTempMessageData(param.getTitle()),
327   - new WxMpTempMessageData("无")
  321 + new WxMpTempMessageData(settingProperty.getThing3(), param.getTitle()),
  322 + new WxMpTempMessageData(settingProperty.getThing13(), StringUtils.isEmpty(param.getShopName()) ? "无" : param.getShopName())
328 323 );
329 324 messageHistory.setKeywords(JSONArray.toJSONString(keywords));
330 325 if (!CollectionUtils.isEmpty(param.getParamMap())) {
... ... @@ -345,15 +340,6 @@ public class MessageCenterBizService {
345 340 return tmParam;
346 341 }
347 342  
348   - private String getTemplateCode() {
349   - BoundValueOperations<String, String> operations = redisTemplate.boundValueOps(getKeyPrefix());
350   - String templateCode = operations.get();
351   - if (StringUtils.isEmpty(templateCode)) {
352   - return "OPENTM412432053";
353   - }
354   - return templateCode;
355   - }
356   -
357 343 private String getSendDataPrefix() {
358 344 String today = LocalDate.now().toString();
359 345 return this.sendDataPrefix + today;
... ...