diff --git a/fw-hestia-server/src/main/java/cn/fw/hestia/server/controller/common/CommonController.java b/fw-hestia-server/src/main/java/cn/fw/hestia/server/controller/common/CommonController.java index 75e0f1b..0eefa6a 100644 --- a/fw-hestia-server/src/main/java/cn/fw/hestia/server/controller/common/CommonController.java +++ b/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; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import static cn.fw.common.web.util.ResultBuilder.success; @@ -41,4 +42,17 @@ public class CommonController { return success(messageCenterBizService.manualSend(sceneToken)); } + @GetMapping("/change/code") + @ControllerMethod("查询模板码") + public Message changeCode(@NotEmpty(message = "模板码不能为空") final String code) { + messageCenterBizService.changeRdsTemplateCode(code); + return success(); + } + + @GetMapping("/query/code") + @ControllerMethod("查询模板码") + public Message getCode() { + return success(messageCenterBizService.getRdsTemplateCode()); + } + } diff --git a/fw-hestia-service/src/main/java/cn/fw/hestia/service/buz/MessageCenterBizService.java b/fw-hestia-service/src/main/java/cn/fw/hestia/service/buz/MessageCenterBizService.java index 87d0520..5a5c031 100644 --- a/fw-hestia-service/src/main/java/cn/fw/hestia/service/buz/MessageCenterBizService.java +++ b/fw-hestia-service/src/main/java/cn/fw/hestia/service/buz/MessageCenterBizService.java @@ -25,6 +25,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.BoundValueOperations; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -50,12 +53,11 @@ public class MessageCenterBizService { private final SendLogService sendLogService; private final TemplateMessageService templateMessageService; private final SendMsgProducer sendMsgProducer; + private final StringRedisTemplate redisTemplate; - /** - * 消息模板Code - */ + @Value("${spring.cache.custom.global-prefix}:template:code") @Getter - private final String templateCode = "OPENTM412432053"; + private String keyPrefix; /** * 发送 @@ -228,6 +230,16 @@ public class MessageCenterBizService { return result; } + public void changeRdsTemplateCode(String code) { + BoundValueOperations boundValueOps = redisTemplate.boundValueOps(getKeyPrefix()); + boundValueOps.set(code); + } + + public String getRdsTemplateCode() { + BoundValueOperations boundValueOps = redisTemplate.boundValueOps(getKeyPrefix()); + return boundValueOps.get(); + } + private String saveLog(TMParam tmParam, Long messageId, Consumer cons) { String result = templateMessageService.sendTemplateMessage(tmParam); SendLog sendLog = new SendLog(); @@ -294,4 +306,13 @@ public class MessageCenterBizService { tmParam.setKeywords(history.getKeywords()); return tmParam; } + + private String getTemplateCode() { + BoundValueOperations operations = redisTemplate.boundValueOps(getKeyPrefix()); + String templateCode = operations.get(); + if (StringUtils.isEmpty(templateCode)) { + return "OPENTM412432053"; + } + return templateCode; + } }