Commit 7c7391acdb8f8d77672a00f93e60c39f1e8fce54

Authored by 张志伟
1 parent af764bb9

:tada: 缓存模板code

fw-hestia-server/src/main/java/cn/fw/hestia/server/controller/common/CommonController.java
... ... @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping;
12 12 import org.springframework.web.bind.annotation.RequestMapping;
13 13 import org.springframework.web.bind.annotation.RestController;
14 14  
  15 +import javax.validation.constraints.NotEmpty;
15 16 import javax.validation.constraints.NotNull;
16 17  
17 18 import static cn.fw.common.web.util.ResultBuilder.success;
... ... @@ -41,4 +42,17 @@ public class CommonController {
41 42 return success(messageCenterBizService.manualSend(sceneToken));
42 43 }
43 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 + @GetMapping("/query/code")
  53 + @ControllerMethod("查询模板码")
  54 + public Message<String> getCode() {
  55 + return success(messageCenterBizService.getRdsTemplateCode());
  56 + }
  57 +
44 58 }
... ...
fw-hestia-service/src/main/java/cn/fw/hestia/service/buz/MessageCenterBizService.java
... ... @@ -25,6 +25,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
25 25 import lombok.Getter;
26 26 import lombok.RequiredArgsConstructor;
27 27 import lombok.extern.slf4j.Slf4j;
  28 +import org.springframework.beans.factory.annotation.Value;
  29 +import org.springframework.data.redis.core.BoundValueOperations;
  30 +import org.springframework.data.redis.core.StringRedisTemplate;
28 31 import org.springframework.stereotype.Service;
29 32 import org.springframework.transaction.annotation.Transactional;
30 33 import org.springframework.util.CollectionUtils;
... ... @@ -50,12 +53,11 @@ public class MessageCenterBizService {
50 53 private final SendLogService sendLogService;
51 54 private final TemplateMessageService templateMessageService;
52 55 private final SendMsgProducer sendMsgProducer;
  56 + private final StringRedisTemplate redisTemplate;
53 57  
54   - /**
55   - * 消息模板Code
56   - */
  58 + @Value("${spring.cache.custom.global-prefix}:template:code")
57 59 @Getter
58   - private final String templateCode = "OPENTM412432053";
  60 + private String keyPrefix;
59 61  
60 62 /**
61 63 * 发送
... ... @@ -228,6 +230,16 @@ public class MessageCenterBizService {
228 230 return result;
229 231 }
230 232  
  233 + public void changeRdsTemplateCode(String code) {
  234 + BoundValueOperations<String, String> boundValueOps = redisTemplate.boundValueOps(getKeyPrefix());
  235 + boundValueOps.set(code);
  236 + }
  237 +
  238 + public String getRdsTemplateCode() {
  239 + BoundValueOperations<String, String> boundValueOps = redisTemplate.boundValueOps(getKeyPrefix());
  240 + return boundValueOps.get();
  241 + }
  242 +
231 243 private String saveLog(TMParam tmParam, Long messageId, Consumer<SendLog> cons) {
232 244 String result = templateMessageService.sendTemplateMessage(tmParam);
233 245 SendLog sendLog = new SendLog();
... ... @@ -294,4 +306,13 @@ public class MessageCenterBizService {
294 306 tmParam.setKeywords(history.getKeywords());
295 307 return tmParam;
296 308 }
  309 +
  310 + private String getTemplateCode() {
  311 + BoundValueOperations<String, String> operations = redisTemplate.boundValueOps(getKeyPrefix());
  312 + String templateCode = operations.get();
  313 + if (StringUtils.isEmpty(templateCode)) {
  314 + return "OPENTM412432053";
  315 + }
  316 + return templateCode;
  317 + }
297 318 }
... ...