feat(REQ-1465): 消息模板列表查询接口实现
背景: https://jira.axzo.cn/browse/REQ-1465?goToView=1 修改: 1、消息模板列表查询接口实现 影响: 无
This commit is contained in:
parent
cc87013d2e
commit
364a7551f3
@ -14,6 +14,9 @@ import cn.azxo.framework.common.model.Page;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息模板管理
|
* 消息模板管理
|
||||||
*
|
*
|
||||||
@ -49,6 +52,11 @@ public class MessageTemplateController implements MessageTemplateClient {
|
|||||||
return CommonResponse.success(messageTemplateNewService.page(request));
|
return CommonResponse.success(messageTemplateNewService.page(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResponse<List<MessageTemplatePageResponse>> listByCodes(Collection<String> templateCodes) {
|
||||||
|
return CommonResponse.success(messageTemplateNewService.listByCodes(templateCodes));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResponse<Void> updateStatus(MessageTemplateUpdateStatusRequest request) {
|
public CommonResponse<Void> updateStatus(MessageTemplateUpdateStatusRequest request) {
|
||||||
messageTemplateNewService.updateStatus(request.getOperatorId(), request.getTemplateCode(), request.getStatus());
|
messageTemplateNewService.updateStatus(request.getOperatorId(), request.getTemplateCode(), request.getStatus());
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import cn.axzo.msg.center.service.template.response.MessageTemplateDetailRespons
|
|||||||
import cn.axzo.msg.center.service.template.response.MessageTemplatePageResponse;
|
import cn.axzo.msg.center.service.template.response.MessageTemplatePageResponse;
|
||||||
import cn.azxo.framework.common.model.Page;
|
import cn.azxo.framework.common.model.Page;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -74,4 +75,12 @@ public interface MessageTemplateNewService {
|
|||||||
* @return 模板数据列表
|
* @return 模板数据列表
|
||||||
*/
|
*/
|
||||||
Page<MessageTemplatePageResponse> page(MessageTemplatePageRequest request);
|
Page<MessageTemplatePageResponse> page(MessageTemplatePageRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过模板编码查询对应的模板
|
||||||
|
*
|
||||||
|
* @param templateCodes 模板编码集合
|
||||||
|
* @return 模板列表
|
||||||
|
*/
|
||||||
|
List<MessageTemplatePageResponse> listByCodes(Collection<String> templateCodes);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public class MessageGroupNodeServiceImpl implements MessageGroupNodeService {
|
|||||||
.map(messageGroupTreeNodeCacheService::queryLeafNodePath)
|
.map(messageGroupTreeNodeCacheService::queryLeafNodePath)
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
.map(Optional::get)
|
.map(Optional::get)
|
||||||
.collect(Collectors.toMap(GroupTreeNodePathDTO::getNodeCode,
|
.collect(Collectors.toMap(GroupTreeNodePathDTO::getNodeCodePath,
|
||||||
GroupTreeNodePathDTO::getNodeNamePath, (cur, pre) -> cur));
|
GroupTreeNodePathDTO::getNodeNamePath, (cur, pre) -> cur));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -175,7 +175,7 @@ public class MessageGroupTreeNodeCacheServiceImpl implements MessageGroupTreeNod
|
|||||||
pathNodeStack.push(node);
|
pathNodeStack.push(node);
|
||||||
if (CollectionUtils.isEmpty(node.getNodeChildren())) {
|
if (CollectionUtils.isEmpty(node.getNodeChildren())) {
|
||||||
// 当前结点为树的叶结点(逻辑上的,有可能不是业务维度的叶结点)
|
// 当前结点为树的叶结点(逻辑上的,有可能不是业务维度的叶结点)
|
||||||
paths.add(GroupTreeNodePathDTO.of(node.getNodeCode(), pathNodeStack));
|
paths.add(GroupTreeNodePathDTO.of(node.getNodeCode(), reverseStack(pathNodeStack)));
|
||||||
pathNodeStack.pop();
|
pathNodeStack.pop();
|
||||||
} else {
|
} else {
|
||||||
stack.addAll(node.getNodeChildren());
|
stack.addAll(node.getNodeChildren());
|
||||||
@ -183,4 +183,12 @@ public class MessageGroupTreeNodeCacheServiceImpl implements MessageGroupTreeNod
|
|||||||
}
|
}
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<GroupTreeNodeDTO> reverseStack(LinkedList<GroupTreeNodeDTO> pathNodeStack) {
|
||||||
|
List<GroupTreeNodeDTO> list = Lists.newArrayList();
|
||||||
|
for (GroupTreeNodeDTO node : pathNodeStack) {
|
||||||
|
list.add(0, node);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,6 +58,8 @@ public class MessageTemplateNewServiceImpl implements MessageTemplateNewService
|
|||||||
private static final long TRY_LOCK_TIMEOUT_MILLS = 1000;
|
private static final long TRY_LOCK_TIMEOUT_MILLS = 1000;
|
||||||
private static final int RETRY_CNT_MAX = 3;
|
private static final int RETRY_CNT_MAX = 3;
|
||||||
|
|
||||||
|
private static final int MAX_NUM_ONCE_QUERY = 1000;
|
||||||
|
|
||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
private final MessageBaseTemplateDao messageBaseTemplateDao;
|
private final MessageBaseTemplateDao messageBaseTemplateDao;
|
||||||
private final MessageGroupNodeService messageGroupNodeService;
|
private final MessageGroupNodeService messageGroupNodeService;
|
||||||
@ -202,6 +204,31 @@ public class MessageTemplateNewServiceImpl implements MessageTemplateNewService
|
|||||||
return Page.toPage(request.getPage(), request.getPageSize(), result.getTotal(), records);
|
return Page.toPage(request.getPage(), request.getPageSize(), result.getTotal(), records);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MessageTemplatePageResponse> listByCodes(Collection<String> templateCodes) {
|
||||||
|
if (CollectionUtils.isEmpty(templateCodes)) {
|
||||||
|
log.info("the templateCodes is empty.");
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
AssertUtil.isTrue(templateCodes.size() <= MAX_NUM_ONCE_QUERY, "the collection of templateCodes is too large");
|
||||||
|
// 查询模板基础数据
|
||||||
|
List<MessageBaseTemplate> records = messageBaseTemplateDao.lambdaQuery()
|
||||||
|
.in(MessageBaseTemplate::getCode, templateCodes)
|
||||||
|
.eq(MessageBaseTemplate::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||||
|
.list();
|
||||||
|
// 查询模板的分类结点编码path
|
||||||
|
templateCodes = records.stream().map(MessageBaseTemplate::getCode).collect(Collectors.toList());
|
||||||
|
Map<String, List<String>> groupNodePaths = messageTemplateGroupService
|
||||||
|
.listMessageTemplateGroupPaths(templateCodes);
|
||||||
|
// 将模板分类结点编码path转化为分类名称path
|
||||||
|
Map<String, String> codeNameMap = messageGroupNodeService.groupNodeNamePaths(groupNodePaths.values().stream()
|
||||||
|
.flatMap(Collection::stream).collect(Collectors.toList()));
|
||||||
|
// 转化为页面展示的数据模型
|
||||||
|
return records.stream()
|
||||||
|
.map(e -> convert(e, groupNodePaths, codeNameMap))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
private String saveTemplate(MessageTemplateSaveOrUpdateParam param) {
|
private String saveTemplate(MessageTemplateSaveOrUpdateParam param) {
|
||||||
String templateCode = UUIDUtil.uuidString();
|
String templateCode = UUIDUtil.uuidString();
|
||||||
MessageBaseTemplate template = convert(param);
|
MessageBaseTemplate template = convert(param);
|
||||||
|
|||||||
@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息模板管理
|
* 消息模板管理
|
||||||
@ -66,6 +68,15 @@ public interface MessageTemplateClient {
|
|||||||
@PostMapping(value = "/message/template/page", produces = {MediaType.APPLICATION_JSON_VALUE})
|
@PostMapping(value = "/message/template/page", produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||||
CommonResponse<Page<MessageTemplatePageResponse>> page(@RequestBody MessageTemplatePageRequest request);
|
CommonResponse<Page<MessageTemplatePageResponse>> page(@RequestBody MessageTemplatePageRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过模板编码查询对应的模板
|
||||||
|
*
|
||||||
|
* @param templateCodes 模板编码集合
|
||||||
|
* @return 模板列表
|
||||||
|
*/
|
||||||
|
@PostMapping(value = "/message/template/list", produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||||
|
CommonResponse<List<MessageTemplatePageResponse>> listByCodes(@RequestParam("templateCodes") Collection<String> templateCodes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启用/禁用消息模板
|
* 启用/禁用消息模板
|
||||||
*
|
*
|
||||||
|
|||||||
@ -12,6 +12,9 @@ import cn.azxo.framework.common.model.Page;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description
|
* @description
|
||||||
*
|
*
|
||||||
@ -46,6 +49,12 @@ public class MessageTemplateClientFallback implements MessageTemplateClient {
|
|||||||
return CommonResponse.error("fall back while paging query template");
|
return CommonResponse.error("fall back while paging query template");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResponse<List<MessageTemplatePageResponse>> listByCodes(Collection<String> templateCodes) {
|
||||||
|
log.error("fall back while listing templates. templateCodes:{}", templateCodes);
|
||||||
|
return CommonResponse.error("fall back while listing template");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResponse<Void> updateStatus(MessageTemplateUpdateStatusRequest request) {
|
public CommonResponse<Void> updateStatus(MessageTemplateUpdateStatusRequest request) {
|
||||||
log.error("fall back while updating template status. request:{}", request);
|
log.error("fall back while updating template status. request:{}", request);
|
||||||
|
|||||||
@ -0,0 +1,60 @@
|
|||||||
|
package cn.axzo.msg.center.service.template.response;
|
||||||
|
|
||||||
|
import cn.axzo.msg.center.service.enums.MessageCategoryEnum;
|
||||||
|
import cn.axzo.msg.center.service.enums.StatusEnum;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author cold_blade
|
||||||
|
* @date 2023/10/17
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class MessageTemplateListResponse implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 4748193413608569743L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板名称
|
||||||
|
*/
|
||||||
|
private String templateName;
|
||||||
|
/**
|
||||||
|
* 模板编码
|
||||||
|
*/
|
||||||
|
private String templateCode;
|
||||||
|
/**
|
||||||
|
* 消息类型
|
||||||
|
* GENERAL_MESSAGE: 普通消息
|
||||||
|
* PENDING_MESSAGE: 待办消息
|
||||||
|
*/
|
||||||
|
private MessageCategoryEnum category;
|
||||||
|
/**
|
||||||
|
* 消息标题
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
/**
|
||||||
|
* 消息内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
/**
|
||||||
|
* 分类路径,eg:发薪管理/发薪提醒/提醒工人
|
||||||
|
*/
|
||||||
|
private List<String> groupNodeNamePaths;
|
||||||
|
/**
|
||||||
|
* 模板状态
|
||||||
|
* ENABLE: 启用
|
||||||
|
* DISABLE: 禁用
|
||||||
|
*/
|
||||||
|
private StatusEnum status;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return JSON.toJSONString(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user