微调
This commit is contained in:
@@ -2,6 +2,7 @@ package com.njcn.msgpush.module.infra;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* 项目的启动类
|
||||
@@ -9,6 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
*
|
||||
* @author hongawen
|
||||
*/
|
||||
@EnableFeignClients
|
||||
@SpringBootApplication
|
||||
public class InfraServerApplication {
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.njcn.msgpush.module.push.dal.dataobject.retry;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-04
|
||||
*/
|
||||
@Data
|
||||
@TableName("push_message_retry_queue")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MessageRetryHistoryDO extends BaseDO {
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 关联 message_record 的 message_id
|
||||
*/
|
||||
private String messageId;
|
||||
|
||||
/**
|
||||
* 重试序号:0=首次发送,1=第1次重试,2=第2次重试
|
||||
*/
|
||||
private Integer retrySequence;
|
||||
|
||||
/**
|
||||
* 使用的服务商类型
|
||||
*/
|
||||
private String providerType;
|
||||
|
||||
/**
|
||||
* 发送时间
|
||||
*/
|
||||
private LocalDateTime sendTime;
|
||||
|
||||
/**
|
||||
* 耗时(毫秒)
|
||||
*/
|
||||
private Integer costTime;
|
||||
|
||||
/**
|
||||
* 状态:success/failed
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
private String errorCode;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private String errorMsg;
|
||||
|
||||
/**
|
||||
* 第三方消息ID
|
||||
*/
|
||||
private String thirdPartyId;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.msgpush.module.push.dal.mysql.retry;
|
||||
|
||||
import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.retry.MessageRetryHistoryDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-04
|
||||
*/
|
||||
@Mapper
|
||||
public interface MessageRetryHistoryMapper extends BaseMapperX<MessageRetryHistoryDO> {
|
||||
}
|
||||
@@ -14,8 +14,10 @@ import com.njcn.msgpush.module.push.constant.MsgPushConstant;
|
||||
import com.njcn.msgpush.module.push.controller.admin.message.vo.MessageRecordReqVO;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.channel.ChannelProviderConfigDO;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.message.MessageRecordDO;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.retry.MessageRetryHistoryDO;
|
||||
import com.njcn.msgpush.module.push.dal.mysql.message.MessageRecordMapper;
|
||||
import com.njcn.msgpush.module.push.service.channel.ChannelProviderConfigService;
|
||||
import com.njcn.msgpush.module.push.service.retry.MessageRetryHistoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -33,6 +35,9 @@ public class MessageRecordServiceImpl extends ServiceImpl<MessageRecordMapper, M
|
||||
@Autowired
|
||||
private Sender sender;
|
||||
|
||||
@Autowired
|
||||
private MessageRetryHistoryService messageRetryHistoryService;
|
||||
|
||||
@Autowired
|
||||
public ChannelProviderConfigService channelProviderConfigService;
|
||||
|
||||
@@ -73,6 +78,10 @@ public class MessageRecordServiceImpl extends ServiceImpl<MessageRecordMapper, M
|
||||
};
|
||||
|
||||
this.updateStatus(messageRecordDO.getMessageId(), sendResult ? MessageStatusConstant.SUCCESS : MessageStatusConstant.FAILED);
|
||||
|
||||
MessageRetryHistoryDO messageRetryHistoryDO = BeanUtil.copyProperties(messageRecordDO, MessageRetryHistoryDO.class, "id");
|
||||
messageRetryHistoryDO.setRetrySequence(messageRetryHistoryService.getMaxRetrySequence(messageRecordDO.getMessageId()));
|
||||
messageRetryHistoryService.add(messageRetryHistoryDO);
|
||||
return sendResult;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.njcn.msgpush.module.push.service.retry;
|
||||
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.retry.MessageRetryHistoryDO;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-04
|
||||
*/
|
||||
public interface MessageRetryHistoryService {
|
||||
boolean add(MessageRetryHistoryDO messageRetryHistoryDO);
|
||||
|
||||
/**
|
||||
* 获取最大重试序号
|
||||
*
|
||||
* @param messageId 消息ID
|
||||
* @return
|
||||
*/
|
||||
Integer getMaxRetrySequence(String messageId);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.msgpush.module.push.service.retry;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.retry.MessageRetryHistoryDO;
|
||||
import com.njcn.msgpush.module.push.dal.mysql.retry.MessageRetryHistoryMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-04
|
||||
*/
|
||||
@Service
|
||||
public class MessageRetryHistoryServiceImpl extends ServiceImpl<MessageRetryHistoryMapper, MessageRetryHistoryDO> implements MessageRetryHistoryService {
|
||||
@Override
|
||||
public boolean add(MessageRetryHistoryDO messageRetryHistoryDO) {
|
||||
return this.add(messageRetryHistoryDO);
|
||||
}
|
||||
|
||||
public Integer getMaxRetrySequence(String messageId) {
|
||||
MessageRetryHistoryDO one = this.lambdaQuery().eq(MessageRetryHistoryDO::getMessageId, messageId)
|
||||
.orderByDesc(MessageRetryHistoryDO::getRetrySequence)
|
||||
.last("limit 1")
|
||||
.one();
|
||||
return ObjectUtil.isNull(one) ? 0 : one.getRetrySequence() + 1;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
--- #################### 注册中心 + 配置中心相关配置 ####################
|
||||
|
||||
#spring:
|
||||
# cloud:
|
||||
# nacos:
|
||||
# server-addr: 192.168.1.103:18848 # Nacos 服务器地址
|
||||
# username: # Nacos 账号
|
||||
# password: # Nacos 密码
|
||||
# discovery: # 【配置中心】配置项
|
||||
# namespace: msgCenter # 命名空间。这里使用 dev 开发环境
|
||||
# group: DEV # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
# metadata:
|
||||
# version: 1.0.0 # 服务实例的版本号,可用于灰度发布
|
||||
# config: # 【注册中心】配置项
|
||||
# namespace: msgCenter # 命名空间。这里使用 dev 开发环境
|
||||
# group: DEV # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
enabled: false
|
||||
config:
|
||||
enabled: false
|
||||
server-addr: 192.168.1.103:18848 # Nacos 服务器地址
|
||||
username: # Nacos 账号
|
||||
password: # Nacos 密码
|
||||
discovery: # 【配置中心】配置项
|
||||
namespace: dev # 命名空间。这里使用 dev 开发环境
|
||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
metadata:
|
||||
version: 1.0.0 # 服务实例的版本号,可用于灰度发布
|
||||
config: # 【注册中心】配置项
|
||||
namespace: dev # 命名空间。这里使用 dev 开发环境
|
||||
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
|
||||
#spring:
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# enabled: false
|
||||
# config:
|
||||
# enabled: false
|
||||
|
||||
|
||||
--- #################### 数据库相关配置 ####################
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.njcn.msgpush.module.system;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* 项目的启动类
|
||||
|
||||
Reference in New Issue
Block a user