REQ-2135: 完善日志
This commit is contained in:
parent
00183bbf81
commit
427e5fe0a2
@ -58,6 +58,36 @@ public class PendingMessageBizConfig {
|
||||
*/
|
||||
private Map<String, DetailStyleInfo> name2DetailStyle;
|
||||
|
||||
/**
|
||||
* 分页查询获取待办时, 需要返回分析信息的token
|
||||
*/
|
||||
@Getter
|
||||
private String analysisToken = "123331";
|
||||
|
||||
/**
|
||||
* 按bizCode获取待办时的, 最大数量
|
||||
*/
|
||||
@Getter
|
||||
private int getLatestByBizCodeMaxSize = 500;
|
||||
|
||||
/**
|
||||
* 设置待办隐藏的隐藏时间
|
||||
*/
|
||||
@Getter
|
||||
private int pendingSetHideSeconds = 60;
|
||||
|
||||
/**
|
||||
* 待办最大的接收人数量
|
||||
*/
|
||||
@Getter
|
||||
private int pendingMaxReceivers = 500;
|
||||
|
||||
/**
|
||||
* 发送待办时, 如果没有传bizCode, 需要自动生成bizCode的模版
|
||||
*/
|
||||
@Getter
|
||||
private String genBizCodeTemplates = "";
|
||||
|
||||
public boolean hasMessageDetailStyle(String code) {
|
||||
return name2DetailStyle != null && name2DetailStyle.containsKey(code);
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import cn.axzo.msg.center.api.request.v3.PendingSendInfo;
|
||||
import cn.axzo.msg.center.service.dto.PersonDTO;
|
||||
import cn.axzo.msg.center.service.enums.OrganizationTypeEnum;
|
||||
import cn.axzo.msg.center.service.pending.request.PendingMessagePushRequest;
|
||||
import cn.axzo.msg.center.utils.UUIDUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@ -12,15 +13,16 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description
|
||||
* @author cold_blade
|
||||
* @date 2023/10/5
|
||||
* @version 1.0
|
||||
* @description
|
||||
* @date 2023/10/5
|
||||
*/
|
||||
@Slf4j
|
||||
@Setter
|
||||
@ -76,6 +78,14 @@ public class PendingMessagePushParam extends PendingSendInfo implements Serializ
|
||||
*/
|
||||
private String routerParams;
|
||||
|
||||
public boolean prepareBizCode(boolean tryGenRandom) {
|
||||
if (StringUtils.isBlank(bizCode)) {
|
||||
bizCode = tryGenRandom ? UUIDUtil.uuidString() : "";
|
||||
return tryGenRandom;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static PendingMessagePushParam from(PendingMessagePushRequest request) {
|
||||
return BeanConverter.convert(request, PendingMessagePushParam.class);
|
||||
}
|
||||
@ -84,4 +94,4 @@ public class PendingMessagePushParam extends PendingSendInfo implements Serializ
|
||||
public String toString() {
|
||||
return JSON.toJSONString(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -40,7 +40,7 @@ public class TemplateNodeService {
|
||||
|
||||
private final MessageGroupTreeNodeCacheService messageGroupTreeNodeCacheService;
|
||||
private final MessageTemplateGroupDao messageTemplateGroupDao;
|
||||
private final PendingMessageBizConfig pendingMessageBizConfig;
|
||||
private final PendingMessageBizConfig cfg;
|
||||
@Value("${message.group.maxDepth:100}")
|
||||
private int groupMaxDepth;
|
||||
|
||||
@ -49,7 +49,7 @@ public class TemplateNodeService {
|
||||
Set<MessageGroupNodeCategoryEnum> todoCategories =
|
||||
MessageGroupCategoryEnum.PENDING.getMsgGroupNodeCategories();
|
||||
Set<Long> configuredIds = new HashSet<>(
|
||||
pendingMessageBizConfig.fetchMessageGroupTreeNodeIds(terminal));
|
||||
cfg.fetchMessageGroupTreeNodeIds(terminal));
|
||||
ArrayList<ValueNode<NodeWrapper>> configuredNodes = new ArrayList<>();
|
||||
messageGroupTreeNodeCacheService.getRoot().unwrap().walkDown(node -> {
|
||||
if (node.isTreeRoot())
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package cn.axzo.msg.center.message.service.todo;
|
||||
|
||||
import cn.axzo.msg.center.inside.notices.config.PendingMessageBizConfig;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -10,17 +12,17 @@ import java.util.Set;
|
||||
* @author yanglin
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
class AnalysisConfig {
|
||||
|
||||
private final static Set<String> ENABLE_PROFILES = ImmutableSet.of("dev", "test", "pre");
|
||||
|
||||
@Value("${msg.center.pending.analysisToken:123331}")
|
||||
private String analysisToken;
|
||||
private final PendingMessageBizConfig cfg;
|
||||
@Value("${spring.profiles.active}")
|
||||
private String profile;
|
||||
|
||||
boolean determineAnalysisEnable(String analysisToken) {
|
||||
return ENABLE_PROFILES.contains(profile) || this.analysisToken.equals(analysisToken);
|
||||
return ENABLE_PROFILES.contains(profile) || cfg.getAnalysisToken().equals(analysisToken);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
package cn.axzo.msg.center.message.service.todo;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
*/
|
||||
@Component
|
||||
class QueryHelper {
|
||||
}
|
||||
@ -2,11 +2,13 @@ package cn.axzo.msg.center.message.service.todo;
|
||||
|
||||
import cn.axzo.basics.common.BeanMapper;
|
||||
import cn.axzo.msg.center.common.enums.TableIsDeleteEnum;
|
||||
import cn.axzo.msg.center.common.utils.BizAssertions;
|
||||
import cn.axzo.msg.center.dal.TodoBusinessDao;
|
||||
import cn.axzo.msg.center.dal.TodoDao;
|
||||
import cn.axzo.msg.center.domain.entity.PendingRecordAdapter;
|
||||
import cn.axzo.msg.center.domain.entity.Todo;
|
||||
import cn.axzo.msg.center.domain.entity.TodoBusiness;
|
||||
import cn.axzo.msg.center.inside.notices.config.PendingMessageBizConfig;
|
||||
import cn.axzo.msg.center.service.enums.TerminalTypeEnum;
|
||||
import cn.axzo.msg.center.service.enums.TodoType;
|
||||
import cn.axzo.msg.center.service.pending.request.PendingMessageByBizCodeRequest;
|
||||
@ -17,7 +19,6 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -37,11 +38,10 @@ import static java.util.stream.Collectors.toList;
|
||||
@RequiredArgsConstructor
|
||||
public class TodoSimpleQueryService {
|
||||
|
||||
@Value("${msg.center.pending.get-latest-by-biz-code.max:500}")
|
||||
private int getLatestByBizCodeMax;
|
||||
private final TodoBusinessDao todoBusinessDao;
|
||||
private final TodoDao todoDao;
|
||||
private final TodoRespBuilder todoRespBuilder;
|
||||
private final PendingMessageBizConfig cfg;
|
||||
|
||||
public PendingMessageResponse query(PendingMessageQueryRequest req) {
|
||||
// 虽然通过code可以查询到唯一的记录, 把一些事情交给数据库去库, 成本不高
|
||||
@ -90,10 +90,11 @@ public class TodoSimpleQueryService {
|
||||
List<String> bizCodes = param.determineBizCodes();
|
||||
if (CollectionUtils.isEmpty(bizCodes))
|
||||
return Collections.emptyList();
|
||||
BizAssertions.assertTrue(bizCodes.size() <= cfg.getGetLatestByBizCodeMaxSize(),
|
||||
String.format("bizCode的数量不能超过 %d", cfg.getGetLatestByBizCodeMaxSize()));
|
||||
List<Todo> todos = todoDao.lambdaQuery()
|
||||
.in(Todo::getBizCode, bizCodes)
|
||||
.eq(Todo::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.last("LIMIT " + getLatestByBizCodeMax)
|
||||
.list();
|
||||
Map<String, List<Todo>> bizCode2Todos = todos.stream()
|
||||
.collect(groupingBy(Todo::getBizCode));
|
||||
|
||||
@ -2,6 +2,7 @@ package cn.axzo.msg.center.message.service.todo.manage;
|
||||
|
||||
import cn.axzo.msg.center.dal.TodoDao;
|
||||
import cn.axzo.msg.center.domain.entity.Todo;
|
||||
import cn.axzo.msg.center.service.enums.PendingMessageStateEnum;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
|
||||
@ -14,23 +15,29 @@ import lombok.Getter;
|
||||
class StateAdvanceBuilder {
|
||||
|
||||
private final LambdaQueryChainWrapper<Todo> query;
|
||||
private final LambdaQueryChainWrapper<Todo> todoStateQuery;
|
||||
private final LambdaUpdateChainWrapper<Todo> update;
|
||||
private boolean sendPullNotification = true;
|
||||
|
||||
StateAdvanceBuilder(TodoDao todoDao) {
|
||||
this.query = todoDao.lambdaQuery();
|
||||
this.todoStateQuery = todoDao.lambdaQuery();
|
||||
this.update = todoDao.lambdaUpdate();
|
||||
}
|
||||
|
||||
StateAdvanceBuilder eq(SFunction<Todo, ?> column, Object val) {
|
||||
query.eq(column, val);
|
||||
update.eq(column, val);
|
||||
if (!(val instanceof PendingMessageStateEnum))
|
||||
todoStateQuery.eq(column, val);
|
||||
return this;
|
||||
}
|
||||
|
||||
StateAdvanceBuilder eq(boolean condition, SFunction<Todo, ?> column, Object val) {
|
||||
query.eq(condition, column, val);
|
||||
update.eq(condition, column, val);
|
||||
if (!(val instanceof PendingMessageStateEnum))
|
||||
todoStateQuery.eq(condition, column, val);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package cn.axzo.msg.center.message.service.todo.manage;
|
||||
|
||||
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
|
||||
import cn.axzo.basics.common.exception.ServiceException;
|
||||
import cn.axzo.framework.jackson.utility.JSON;
|
||||
import cn.axzo.framework.rocketmq.utils.TraceUtils;
|
||||
import cn.axzo.msg.center.api.mq.PresetButtonPressedMessage;
|
||||
import cn.axzo.msg.center.common.utils.BizAssertions;
|
||||
@ -9,6 +10,7 @@ import cn.axzo.msg.center.dal.TodoBusinessDao;
|
||||
import cn.axzo.msg.center.dal.TodoDao;
|
||||
import cn.axzo.msg.center.domain.entity.Todo;
|
||||
import cn.axzo.msg.center.domain.entity.TodoBusiness;
|
||||
import cn.axzo.msg.center.inside.notices.config.PendingMessageBizConfig;
|
||||
import cn.axzo.msg.center.message.domain.dto.MessageTemplateDTO;
|
||||
import cn.axzo.msg.center.message.domain.param.PendingMessagePushParam;
|
||||
import cn.axzo.msg.center.message.service.MessageTemplateNewService;
|
||||
@ -36,7 +38,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -56,10 +57,6 @@ import static java.util.stream.Collectors.toList;
|
||||
@RequiredArgsConstructor
|
||||
public class TodoManager {
|
||||
|
||||
@Value("${msg.center.pending.hide-seconds:60}")
|
||||
private int pendingDefaultHideSeconds;
|
||||
@Value("${msg.center.pending.max-receivers:1000}")
|
||||
private int pendingMaxReceivers;
|
||||
private final TodoBusinessDao todoBusinessDao;
|
||||
private final TodoDao todoDao;
|
||||
private final TodoRecordBuilder todoRecordBuilder;
|
||||
@ -68,6 +65,7 @@ public class TodoManager {
|
||||
private final MessageTemplateNewService messageTemplateNewService;
|
||||
private final MqProducer mqProducer;
|
||||
private final ErrorAssembler errorAssembler;
|
||||
private final PendingMessageBizConfig cfg;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<PushPendingMessageDTO> send(PendingMessagePushParam request) {
|
||||
@ -87,20 +85,22 @@ public class TodoManager {
|
||||
.orElseThrow(() -> new ServiceException(String.format(
|
||||
"Can't find template. templateCode=%s", request.getTemplateCode())));
|
||||
BizAssertions.assertNotEmpty(request.getExecutor(), "接受者不能为空");
|
||||
BizAssertions.assertTrue(request.getExecutor().size() <= pendingMaxReceivers,
|
||||
"待办接收者数量不能超过 " + pendingMaxReceivers);
|
||||
String bizCode = request.getBizCode();
|
||||
// 有几个业务方一直没有传bizCode
|
||||
if (StringUtils.isBlank(bizCode))
|
||||
bizCode = "";
|
||||
BizAssertions.assertTrue(request.getExecutor().size() <= cfg.getPendingMaxReceivers(),
|
||||
"待办接收者数量不能超过 " + cfg.getPendingMaxReceivers());
|
||||
// 线上有2个模版一直没有传bizCode. 在查询我发起的待办时, 会有问题, 有一些解决办法:
|
||||
// 1. 让他们改造, 传bizCode
|
||||
// 2. 待办自动生成bizCode
|
||||
boolean genBizCode = request.prepareBizCode(
|
||||
cfg.getGenBizCodeTemplates().contains(template.getCode()));
|
||||
// 如果已经存在对应的待办业务, 就把待办追加到对应的待办业务上
|
||||
// 流程会并发, 这里对业务进行加锁
|
||||
TodoBusiness business = todoBusinessDao
|
||||
.findForUpdate(request.getTemplateCode(), bizCode)
|
||||
.findForUpdate(request.getTemplateCode(), request.getBizCode())
|
||||
.orElse(null);
|
||||
boolean businessCreated = false;
|
||||
if (business == null) {
|
||||
business = todoRecordBuilder.buildBusiness(request, template);
|
||||
business.getRecordExt().setGenBizCode(genBizCode);
|
||||
todoBusinessDao.save(business);
|
||||
businessCreated = true;
|
||||
}
|
||||
@ -122,14 +122,16 @@ public class TodoManager {
|
||||
.addLogContent("content", business.getContent())
|
||||
.addLogContent("bizExtParams", business.getBizExtParam())
|
||||
.addLogContent("routerParams", business.getRouterParams())
|
||||
.addLogContent("state", sample.getState());
|
||||
.addLogContent("state", sample.getState())
|
||||
.addLogContent("genBizCode", genBizCode);
|
||||
// @formatter:on
|
||||
if (businessCreated)
|
||||
todoLogger.logBusinessUpdated(ctx, business);
|
||||
todoLogger.logTodosUpdated(ctx, todos);
|
||||
return todos.stream()
|
||||
.map(todo -> new PushPendingMessageDTO(
|
||||
todo.getId(), todo.getIdentityCode(), todo.getRequestNo(),
|
||||
todo.getId(), request.getBizCode(),
|
||||
todo.getIdentityCode(), todo.getRequestNo(),
|
||||
todo.getExecutorId(), todo.getExecutorPersonId()))
|
||||
.collect(toList());
|
||||
}
|
||||
@ -294,7 +296,7 @@ public class TodoManager {
|
||||
if (todos.isEmpty())
|
||||
return false;
|
||||
int seconds = request.getHideSeconds() == null
|
||||
? pendingDefaultHideSeconds : request.getHideSeconds();
|
||||
? cfg.getPendingSetHideSeconds() : request.getHideSeconds();
|
||||
Date expireTime = DateTime.now().plusSeconds(seconds).toDate();
|
||||
boolean updated = todoDao.lambdaUpdate()
|
||||
.eq(Todo::getType, TodoType.EXECUTABLE)
|
||||
@ -448,8 +450,9 @@ public class TodoManager {
|
||||
private StateAdvanceResult advanceState(StateAdvanceBuilder builder) {
|
||||
List<Todo> todos = builder.getQuery().list();
|
||||
if (todos.isEmpty()) {
|
||||
log.warn("尝试推进待办状态, 但是没有找到对应的待办. query={}",
|
||||
QueryFormatter.format(builder.getQuery()));
|
||||
Todo todoStateSample = builder.getTodoStateQuery().one();
|
||||
log.warn("尝试推进待办状态, 但是没有找到对应的待办. query={}, todoStateSample={}",
|
||||
QueryFormatter.format(builder.getQuery()), JSON.toJSONString(todoStateSample));
|
||||
return new StateAdvanceResult(false, null, Collections.emptyList());
|
||||
}
|
||||
boolean updated = builder.getUpdate().update();
|
||||
|
||||
@ -19,6 +19,11 @@ public class PushPendingMessageDTO {
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 业务编码
|
||||
*/
|
||||
private String bizCode;
|
||||
|
||||
/**
|
||||
* 消息唯一标识
|
||||
*/
|
||||
|
||||
@ -145,8 +145,11 @@ public class Todo extends BaseEntityExt<Todo> {
|
||||
*/
|
||||
private YesOrNo isOuIdMigrated;
|
||||
|
||||
/**
|
||||
* 保存额外的数据信息
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
private PendingRecordExt recordExt;
|
||||
private PendingRecordExt recordExt = new PendingRecordExt();
|
||||
|
||||
// !! helper
|
||||
|
||||
|
||||
@ -114,4 +114,9 @@ public class TodoBusiness extends BaseEntityExt<TodoBusiness> {
|
||||
*/
|
||||
private String orgName;
|
||||
|
||||
/**
|
||||
* 保存额外的数据信息
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
private TodoBusinessExt recordExt = new TodoBusinessExt();
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package cn.axzo.msg.center.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author yanglin
|
||||
*/
|
||||
@Data
|
||||
public class TodoBusinessExt {
|
||||
private Boolean genBizCode;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user