黑名单数据访问层、服务层
This commit is contained in:
@@ -125,6 +125,10 @@
|
||||
<artifactId>restful-sdk</artifactId>
|
||||
<version>1.0.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>msgpush-spring-boot-starter-protection</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.njcn.msgpush.module.push.checker;
|
||||
|
||||
import com.njcn.msgpush.module.push.checker.impl.BlacklistChecker;
|
||||
import com.njcn.msgpush.module.push.checker.impl.IdempotencyChecker;
|
||||
import com.njcn.msgpush.module.push.checker.impl.QuotaChecker;
|
||||
import com.njcn.msgpush.module.push.checker.impl.RateLimitChecker;
|
||||
import com.njcn.msgpush.module.push.controller.admin.message.vo.MessageRecordReqVO;
|
||||
@@ -19,7 +18,6 @@ public class MsgPushGuardChain {
|
||||
|
||||
public MsgPushGuardChain() {
|
||||
this.checkers = new ArrayList<>();
|
||||
this.checkers.add(new IdempotencyChecker());
|
||||
this.checkers.add(new BlacklistChecker());
|
||||
this.checkers.add(new QuotaChecker());
|
||||
this.checkers.add(new RateLimitChecker());
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.njcn.msgpush.module.push.checker.impl;
|
||||
|
||||
import com.njcn.msgpush.module.push.checker.IChecker;
|
||||
import com.njcn.msgpush.module.push.controller.admin.message.vo.MessageRecordReqVO;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-02-27
|
||||
* @description 接口幂等性检查器
|
||||
*/
|
||||
public class IdempotencyChecker implements IChecker {
|
||||
@Override
|
||||
public boolean check(MessageRecordReqVO reqVO) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,12 @@ import com.njcn.msgpush.module.push.client.factory.MessageProviderFactory;
|
||||
import com.njcn.msgpush.module.push.client.factory.impl.AliyunProviderFactory;
|
||||
import com.njcn.msgpush.module.push.client.factory.impl.TelecomProviderFactory;
|
||||
import com.njcn.msgpush.module.push.client.factory.impl.UniPushProviderFactory;
|
||||
import com.njcn.msgpush.module.push.client.sender.Sender;
|
||||
import com.njcn.msgpush.module.push.constant.MsgPushConstant;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.channel.ChannelProviderConfigDO;
|
||||
import com.njcn.msgpush.module.push.dal.mysql.channel.ChannelProviderConfigMapper;
|
||||
import com.njcn.msgpush.module.push.enums.ProviderTypeEnum;
|
||||
import com.njcn.msgpush.module.push.service.channel.ChannelProviderConfigService;
|
||||
import com.njcn.msgpush.module.push.service.channel.ProviderErrorCodeMappingService;
|
||||
import com.njcn.msgpush.module.push.service.retry.MessageRetryQueueService;
|
||||
import com.njcn.msgpush.module.push.util.RestTemplateUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -37,20 +31,20 @@ public class ClientConfiguration {
|
||||
Map<String, MessageProviderFactory> messageProviderFactoryMap = new HashMap<>();
|
||||
|
||||
for (ChannelProviderConfigDO config : activeProviders) {
|
||||
switch (config.getProviderType()) {
|
||||
case MsgPushConstant.PROVIDER_TYPE_ALI_YUN: {
|
||||
MessageProviderFactory orDefault = messageProviderFactoryMap.getOrDefault(MsgPushConstant.PROVIDER_TYPE_ALI_YUN, new AliyunProviderFactory());
|
||||
messageProviderFactoryMap.put(MsgPushConstant.PROVIDER_TYPE_ALI_YUN, orDefault);
|
||||
switch (ProviderTypeEnum.getByCode(config.getProviderType())) {
|
||||
case ALIYUN: {
|
||||
MessageProviderFactory orDefault = messageProviderFactoryMap.getOrDefault(ProviderTypeEnum.ALIYUN.getCode(), new AliyunProviderFactory());
|
||||
messageProviderFactoryMap.put(ProviderTypeEnum.ALIYUN.getCode(), orDefault);
|
||||
}
|
||||
break;
|
||||
case MsgPushConstant.PROVIDER_TYPE_TELECOM: {
|
||||
MessageProviderFactory orDefault = messageProviderFactoryMap.getOrDefault(MsgPushConstant.PROVIDER_TYPE_TELECOM, new TelecomProviderFactory());
|
||||
messageProviderFactoryMap.put(MsgPushConstant.PROVIDER_TYPE_TELECOM, orDefault);
|
||||
case TELECOM: {
|
||||
MessageProviderFactory orDefault = messageProviderFactoryMap.getOrDefault(ProviderTypeEnum.TELECOM.getCode(), new TelecomProviderFactory());
|
||||
messageProviderFactoryMap.put(ProviderTypeEnum.TELECOM.getCode(), orDefault);
|
||||
}
|
||||
break;
|
||||
case MsgPushConstant.PROVIDER_TYPE_UNI_PUSH: {
|
||||
MessageProviderFactory orDefault = messageProviderFactoryMap.getOrDefault(MsgPushConstant.PROVIDER_TYPE_UNI_PUSH, new UniPushProviderFactory());
|
||||
messageProviderFactoryMap.put(MsgPushConstant.PROVIDER_TYPE_UNI_PUSH, orDefault);
|
||||
case UNIPUSH: {
|
||||
MessageProviderFactory orDefault = messageProviderFactoryMap.getOrDefault(ProviderTypeEnum.UNIPUSH.getCode(), new UniPushProviderFactory());
|
||||
messageProviderFactoryMap.put(ProviderTypeEnum.UNIPUSH.getCode(), orDefault);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -5,13 +5,6 @@ package com.njcn.msgpush.module.push.constant;
|
||||
* @data 2026-02-11
|
||||
*/
|
||||
public class MsgPushConstant {
|
||||
public static final String PROVIDER_TYPE_ALI_YUN = "aliyun";
|
||||
public static final String PROVIDER_TYPE_TELECOM = "telecom";
|
||||
public static final String PROVIDER_TYPE_UNI_PUSH = "uniPush";
|
||||
|
||||
public static final String CHANNEL_SMS = "sms";
|
||||
public static final String CHANNEL_EMAIL = "email";
|
||||
public static final String CHANNEL_APP_PUSH = "app_push";
|
||||
|
||||
public static final String ERROR_MSG_UNKNOWN = "未知错误";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.njcn.msgpush.module.push.controller.admin.blacklist;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.msgpush.framework.common.pojo.CommonResult;
|
||||
import com.njcn.msgpush.module.push.controller.admin.blacklist.vo.BlacklistReqVO;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.blacklist.BlacklistDO;
|
||||
import com.njcn.msgpush.module.push.service.blacklist.BlacklistService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.njcn.msgpush.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-12
|
||||
*/
|
||||
@RestController("/push/blacklist")
|
||||
public class BlacklistController {
|
||||
@Autowired
|
||||
private BlacklistService blacklistService;
|
||||
|
||||
@PostMapping("/page")
|
||||
@Operation(summary = "分页查询黑名单列表")
|
||||
@PreAuthorize("@ss.hasPermission('push:blacklist:page')")
|
||||
public CommonResult<Page<BlacklistDO>> pageBlacklist(@Validated @RequestBody BlacklistReqVO reqVO) {
|
||||
Page<BlacklistDO> res = blacklistService.getPage(reqVO);
|
||||
return success(res);
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "添加黑名单")
|
||||
@PreAuthorize("@ss.hasPermission('push:blacklist:add')")
|
||||
public CommonResult<Boolean> add(@RequestBody BlacklistReqVO reqVO) {
|
||||
return CommonResult.success(blacklistService.save(BeanUtil.copyProperties(reqVO, BlacklistDO.class)));
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
@Operation(summary = "更新黑名单")
|
||||
@PreAuthorize("@ss.hasPermission('push:blacklist:update')")
|
||||
public CommonResult<Boolean> update(@RequestBody BlacklistReqVO reqVO) {
|
||||
return CommonResult.success(blacklistService.updateById(BeanUtil.copyProperties(reqVO, BlacklistDO.class)));
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
@Operation(summary = "删除黑名单")
|
||||
@PreAuthorize("@ss.hasPermission('push:blacklist:delete')")
|
||||
@Parameter(name = "ids", description = "id列表", required = true)
|
||||
public CommonResult<Boolean> delete(@RequestParam("ids") List<String> ids){
|
||||
return CommonResult.success(blacklistService.removeByIds(ids));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.njcn.msgpush.module.push.controller.admin.blacklist.vo;
|
||||
|
||||
import com.njcn.msgpush.framework.common.pojo.PageParam;
|
||||
import com.njcn.msgpush.framework.common.validation.InEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-12
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "管理后台 - 黑名单 Request VO")
|
||||
public class BlacklistReqVO extends PageParam {
|
||||
|
||||
/**
|
||||
* 主键 ID
|
||||
*/
|
||||
@Schema(description = "主键 ID", example = "123444")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 渠道类型:sms/email/app_push
|
||||
*/
|
||||
@Schema(description = "渠道类型:sms/email/app_push", example = "sms")
|
||||
@InEnum(value = com.njcn.msgpush.module.push.enums.ChannelTypeEnum.class, message = "渠道类型必须是 {value}")
|
||||
private String channel;
|
||||
|
||||
/**
|
||||
* 黑名单目标:手机号/邮箱/设备 Token
|
||||
*/
|
||||
@Schema(description = "黑名单目标:手机号/邮箱/设备 Token", example = "15601691000")
|
||||
@NotBlank(message = "黑名单目标不能为空")
|
||||
private String target;
|
||||
|
||||
/**
|
||||
* 加入原因:用户投诉/无效号码/频繁退订等
|
||||
*/
|
||||
@Schema(description = "加入原因:用户投诉/无效号码/频繁退订等", example = "用户投诉")
|
||||
private String reason;
|
||||
|
||||
/**
|
||||
* 操作来源:manual/auto/import
|
||||
*/
|
||||
@Schema(description = "操作来源:manual/auto/import", example = "manual")
|
||||
@InEnum(value = com.njcn.msgpush.module.push.enums.BlacklistSourceEnum.class, message = "操作来源必须是 {value}")
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 过期时间:-1=永久,时间戳=到期时间
|
||||
*/
|
||||
@Schema(description = "过期时间:-1=永久,时间戳=到期时间", example = "15601691000")
|
||||
@NotNull(message = "过期时间不能为空")
|
||||
@Min(value = -1L, message = "过期时间不能小于 -1")
|
||||
private Long expireTime;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
}
|
||||
@@ -7,15 +7,10 @@ import com.njcn.msgpush.module.push.client.factory.MessageProviderFactory;
|
||||
import com.njcn.msgpush.module.push.client.factory.impl.AliyunProviderFactory;
|
||||
import com.njcn.msgpush.module.push.client.factory.impl.TelecomProviderFactory;
|
||||
import com.njcn.msgpush.module.push.client.factory.impl.UniPushProviderFactory;
|
||||
import com.njcn.msgpush.module.push.client.sender.Sender;
|
||||
import com.njcn.msgpush.module.push.constant.MsgPushConstant;
|
||||
import com.njcn.msgpush.module.push.controller.admin.channel.vo.ChannelProviderConfigReqVO;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.channel.ChannelProviderConfigDO;
|
||||
import com.njcn.msgpush.module.push.enums.ProviderTypeEnum;
|
||||
import com.njcn.msgpush.module.push.service.channel.ChannelProviderConfigService;
|
||||
import com.njcn.msgpush.module.push.service.channel.ProviderErrorCodeMappingService;
|
||||
import com.njcn.msgpush.module.push.service.message.MessageRecordService;
|
||||
import com.njcn.msgpush.module.push.service.retry.MessageRetryQueueService;
|
||||
import com.njcn.msgpush.module.push.util.RestTemplateUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -100,17 +95,17 @@ public class ChannelProviderConfigController {
|
||||
* @param providerType 服务商类型,例如:aliyun\telecom\UniPush
|
||||
*/
|
||||
public void registerProviderBean(String providerType) {
|
||||
switch (providerType) {
|
||||
case MsgPushConstant.PROVIDER_TYPE_ALI_YUN: {
|
||||
messageProviderFactoryMap.put(MsgPushConstant.PROVIDER_TYPE_ALI_YUN, new AliyunProviderFactory());
|
||||
switch (ProviderTypeEnum.getByCode(providerType)) {
|
||||
case ALIYUN: {
|
||||
messageProviderFactoryMap.put(ProviderTypeEnum.ALIYUN.getCode(), new AliyunProviderFactory());
|
||||
}
|
||||
break;
|
||||
case MsgPushConstant.PROVIDER_TYPE_TELECOM: {
|
||||
messageProviderFactoryMap.put(MsgPushConstant.PROVIDER_TYPE_TELECOM, new TelecomProviderFactory());
|
||||
case TELECOM: {
|
||||
messageProviderFactoryMap.put(ProviderTypeEnum.TELECOM.getCode(), new TelecomProviderFactory());
|
||||
}
|
||||
break;
|
||||
case MsgPushConstant.PROVIDER_TYPE_UNI_PUSH: {
|
||||
messageProviderFactoryMap.put(MsgPushConstant.PROVIDER_TYPE_UNI_PUSH, new UniPushProviderFactory());
|
||||
case UNIPUSH: {
|
||||
messageProviderFactoryMap.put(ProviderTypeEnum.UNIPUSH.getCode(), new UniPushProviderFactory());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.njcn.msgpush.module.push.controller.admin.message;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.msgpush.framework.common.pojo.CommonResult;
|
||||
import com.njcn.msgpush.framework.idempotent.core.annotation.Idempotent;
|
||||
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;
|
||||
@@ -18,6 +19,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.njcn.msgpush.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@@ -33,6 +35,7 @@ public class MessageRecordController {
|
||||
@PermitAll
|
||||
@PostMapping("/send")
|
||||
@Operation(summary = "消息推送")
|
||||
@Idempotent(timeout = 60)
|
||||
public CommonResult<Boolean> send(@Valid @RequestBody List<MessageRecordReqVO> reqVOList) {
|
||||
Boolean result = messageRecordService.send(reqVOList);
|
||||
return CommonResult.success(result);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.njcn.msgpush.module.push.dal.dataobject.blacklist;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-12
|
||||
*/
|
||||
@Data
|
||||
@TableName("push_message_blacklist")
|
||||
public class BlacklistDO extends BaseDO {
|
||||
/**
|
||||
* 主键 ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 渠道类型:sms/email/app_push
|
||||
*/
|
||||
private String channel;
|
||||
|
||||
/**
|
||||
* 黑名单目标:手机号/邮箱/设备 Token
|
||||
*/
|
||||
private String target;
|
||||
|
||||
/**
|
||||
* 加入原因:用户投诉/无效号码/频繁退订等
|
||||
*/
|
||||
private String reason;
|
||||
|
||||
/**
|
||||
* 操作来源:manual/auto/import
|
||||
*/
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 过期时间:-1=永久,时间戳=到期时间
|
||||
*/
|
||||
private Long expireTime;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 命中次数
|
||||
*/
|
||||
private Integer hitCount;
|
||||
|
||||
/**
|
||||
* 最近命中时间
|
||||
*/
|
||||
private LocalDateTime lastHitTime;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.msgpush.module.push.dal.mysql.blacklist;
|
||||
|
||||
import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.blacklist.BlacklistDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-12
|
||||
*/
|
||||
@Mapper
|
||||
public interface BlacklistMapper extends BaseMapperX<BlacklistDO> {
|
||||
}
|
||||
@@ -2,10 +2,12 @@ package com.njcn.msgpush.module.push.dal.mysql.channel;
|
||||
|
||||
import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.channel.ProviderErrorCodeMappingDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-02
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProviderErrorCodeMappingMappper extends BaseMapperX<ProviderErrorCodeMappingDO> {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.njcn.msgpush.module.push.enums;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.njcn.msgpush.framework.common.core.ArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-12
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum BlacklistSourceEnum implements ArrayValuable<String> {
|
||||
MANUAL("manual", "手动"),
|
||||
AUTO("auto", "自动"),
|
||||
IMPORT("import", "导入");
|
||||
|
||||
public static final String[] ARRAYS = Arrays.stream(values()).map(BlacklistSourceEnum::getCode).toArray(String[]::new);
|
||||
|
||||
|
||||
private String code;
|
||||
private String msg;
|
||||
|
||||
@Override
|
||||
public String[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
public static BlacklistSourceEnum getByCode(String code) {
|
||||
return ArrayUtil.firstMatch(blacklistSourceEnum -> blacklistSourceEnum.getCode().equals(code), values());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.njcn.msgpush.module.push.enums;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.njcn.msgpush.framework.common.core.ArrayValuable;
|
||||
import com.njcn.msgpush.framework.common.enums.CommonStatusEnum;
|
||||
import com.njcn.msgpush.framework.common.enums.UserTypeEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-12
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ChannelTypeEnum implements ArrayValuable<String> {
|
||||
SMS("sms", "短信"),
|
||||
EMAIL("email", "邮箱"),
|
||||
APP_PUSH("app_push", "APP 推送"),;
|
||||
|
||||
public static final String[] ARRAYS = Arrays.stream(values()).map(ChannelTypeEnum::getCode).toArray(String[]::new);
|
||||
|
||||
private final String code;
|
||||
private final String msg;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
public static ChannelTypeEnum getByCode(String code) {
|
||||
return ArrayUtil.firstMatch(channelTypeEnum -> channelTypeEnum.getCode().equals(code), values());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.njcn.msgpush.module.push.enums;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.njcn.msgpush.framework.common.core.ArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-12
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ProviderTypeEnum implements ArrayValuable<String> {
|
||||
|
||||
ALIYUN("aliyun", "阿里云"),
|
||||
TELECOM("telecom", "电信"),
|
||||
UNIPUSH("uniPush", "uniPush");
|
||||
|
||||
public static final String[] ARRAYS = Arrays.stream(values()).map(ProviderTypeEnum::getCode).toArray(String[]::new);
|
||||
|
||||
|
||||
private String code;
|
||||
private String msg;
|
||||
|
||||
@Override
|
||||
public String[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
public static ProviderTypeEnum getByCode(String code) {
|
||||
return ArrayUtil.firstMatch(providerTypeEnum -> providerTypeEnum.getCode().equals(code), values());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.njcn.msgpush.module.push.service.blacklist;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.msgpush.module.push.controller.admin.blacklist.vo.BlacklistReqVO;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.blacklist.BlacklistDO;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-12
|
||||
*/
|
||||
public interface BlacklistService extends IService<BlacklistDO> {
|
||||
Page<BlacklistDO> getPage(BlacklistReqVO reqVO);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.msgpush.module.push.service.blacklist;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.msgpush.framework.common.util.object.PageUtils;
|
||||
import com.njcn.msgpush.module.push.controller.admin.blacklist.vo.BlacklistReqVO;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.blacklist.BlacklistDO;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.channel.ChannelProviderConfigDO;
|
||||
import com.njcn.msgpush.module.push.dal.mysql.blacklist.BlacklistMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-12
|
||||
*/
|
||||
@Service
|
||||
public class BlacklistServiceImpl extends ServiceImpl<BlacklistMapper, BlacklistDO> implements BlacklistService {
|
||||
@Override
|
||||
public Page<BlacklistDO> getPage(BlacklistReqVO reqVO) {
|
||||
QueryWrapper<BlacklistDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(BlacklistDO::getChannel, reqVO.getChannel());
|
||||
return this.page(new Page<>(PageUtils.getPageNum(reqVO), PageUtils.getPageSize(reqVO)), wrapper);
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,12 @@ import com.njcn.msgpush.framework.common.util.object.PageUtils;
|
||||
import com.njcn.msgpush.module.push.client.factory.MessageProviderFactory;
|
||||
import com.njcn.msgpush.module.push.client.sender.Sender;
|
||||
import com.njcn.msgpush.module.push.constant.MessageStatusConstant;
|
||||
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.enums.ChannelTypeEnum;
|
||||
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;
|
||||
@@ -70,13 +70,13 @@ public class MessageRecordServiceImpl extends ServiceImpl<MessageRecordMapper, M
|
||||
if (ObjectUtil.isNull(messageProviderFactory) || ObjectUtil.isNull(channelProviderConfigDO)) {
|
||||
throw new RuntimeException("暂不支持该供应商或者该供应商未激活:" + messageRecordDO.getProviderType());
|
||||
}
|
||||
boolean sendResult = switch (messageRecordDO.getChannel()) {
|
||||
case MsgPushConstant.CHANNEL_SMS -> messageProviderFactory.createSmsSender(channelProviderConfigDO, sender).sendSms(messageRecordDO);
|
||||
case MsgPushConstant.CHANNEL_EMAIL -> {
|
||||
boolean sendResult = switch (ChannelTypeEnum.getByCode(messageRecordDO.getChannel())) {
|
||||
case SMS -> messageProviderFactory.createSmsSender(channelProviderConfigDO, sender).sendSms(messageRecordDO);
|
||||
case EMAIL -> {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
yield messageProviderFactory.createEmailSender(channelProviderConfigDO, sender).sendEmail(messageRecordDO, params);
|
||||
}
|
||||
case MsgPushConstant.CHANNEL_APP_PUSH -> messageProviderFactory.createAppPushSender(channelProviderConfigDO, sender).appPush(messageRecordDO);
|
||||
case APP_PUSH -> messageProviderFactory.createAppPushSender(channelProviderConfigDO, sender).appPush(messageRecordDO);
|
||||
default -> throw new RuntimeException("暂不支持该渠道:" + messageRecordDO.getChannel());
|
||||
};
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.msgpush.framework.common.pojo.PageResult;
|
||||
import com.njcn.msgpush.module.push.constant.MessageStatusConstant;
|
||||
import com.njcn.msgpush.module.push.constant.MsgPushConstant;
|
||||
import com.njcn.msgpush.module.push.controller.admin.retry.vo.MessageRetryQueueReqVO;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.message.MessageRecordDO;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.retry.MessageRetryQueueDO;
|
||||
import com.njcn.msgpush.module.push.dal.dataobject.retry.RetryStrategyConfigDO;
|
||||
import com.njcn.msgpush.module.push.dal.mysql.retry.MessageRetryQueueMapper;
|
||||
import com.njcn.msgpush.module.push.dal.redis.MessageRetryRedisDAO;
|
||||
import com.njcn.msgpush.module.push.enums.ChannelTypeEnum;
|
||||
import com.njcn.msgpush.module.push.service.channel.ChannelProviderConfigService;
|
||||
import com.njcn.msgpush.module.push.service.message.MessageRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -126,8 +126,8 @@ public class MessageRetryQueueServiceImpl extends ServiceImpl<MessageRetryQueueM
|
||||
long plusSeconds = 0;
|
||||
if (ObjectUtil.isNull(strategyConfig)) {
|
||||
// 默认策略
|
||||
switch (channel) {
|
||||
case MsgPushConstant.CHANNEL_SMS: {
|
||||
switch (ChannelTypeEnum.getByCode(channel)) {
|
||||
case SMS: {
|
||||
if (retryCount == 1) {
|
||||
plusSeconds = 60 * 5;
|
||||
} else if (retryCount == 2) {
|
||||
@@ -137,7 +137,7 @@ public class MessageRetryQueueServiceImpl extends ServiceImpl<MessageRetryQueueM
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MsgPushConstant.CHANNEL_EMAIL: {
|
||||
case EMAIL: {
|
||||
if (retryCount == 1) {
|
||||
// plusSeconds = 60 * 10;
|
||||
plusSeconds = 60 * 2;
|
||||
@@ -152,7 +152,7 @@ public class MessageRetryQueueServiceImpl extends ServiceImpl<MessageRetryQueueM
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MsgPushConstant.CHANNEL_APP_PUSH: {
|
||||
case APP_PUSH: {
|
||||
if (retryCount == 1) {
|
||||
plusSeconds = 60 * 1;
|
||||
} else {
|
||||
|
||||
@@ -3,9 +3,10 @@ package com.njcn.msgpush.module.push.sms;
|
||||
import com.njcn.msgpush.module.push.client.factory.MessageProviderFactory;
|
||||
import com.njcn.msgpush.module.push.client.sender.Sender;
|
||||
import com.njcn.msgpush.module.push.client.sender.SmsSender;
|
||||
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.enums.ChannelTypeEnum;
|
||||
import com.njcn.msgpush.module.push.enums.ProviderTypeEnum;
|
||||
import com.njcn.msgpush.module.push.service.message.MessageRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -58,10 +59,10 @@ public class MsgPushClientTest {
|
||||
MessageRecordReqVO message = new MessageRecordReqVO();
|
||||
message.setMessageId(String.valueOf(UUID.randomUUID()));
|
||||
message.setAppName("NPQS-9000");
|
||||
message.setChannel(MsgPushConstant.CHANNEL_SMS);
|
||||
message.setChannel(ChannelTypeEnum.SMS.getMsg());
|
||||
message.setReceiver("18839431215");
|
||||
message.setContent("【南京灿能电力】测试短信" + i + ",请忽略。" + LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
message.setProviderType(MsgPushConstant.PROVIDER_TYPE_TELECOM);
|
||||
message.setProviderType(ProviderTypeEnum.TELECOM.getCode());
|
||||
messageIdList.add(message);
|
||||
}
|
||||
boolean sendResult = messageRecordService.send(messageIdList);
|
||||
@@ -72,7 +73,7 @@ public class MsgPushClientTest {
|
||||
|
||||
@Test
|
||||
public void templateSelect() {
|
||||
MessageProviderFactory messageProviderFactory = messageProviderFactoryMap.get(MsgPushConstant.PROVIDER_TYPE_TELECOM);
|
||||
MessageProviderFactory messageProviderFactory = messageProviderFactoryMap.get(ProviderTypeEnum.TELECOM.getCode());
|
||||
ChannelProviderConfigDO config = new ChannelProviderConfigDO();
|
||||
config.setApiUrl("https://sms.ymeeting.cn/smsv2");
|
||||
config.setAppKey("925631");
|
||||
|
||||
Reference in New Issue
Block a user