服务提供商启用\禁用逻辑调整,确保只有一个渠道只有一个服务提供商
This commit is contained in:
@@ -1,60 +0,0 @@
|
|||||||
package com.njcn.msgpush.module.push.client;
|
|
||||||
|
|
||||||
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.dal.dataobject.channel.ChannelProviderConfigDO;
|
|
||||||
import com.njcn.msgpush.module.push.enums.ProviderTypeEnum;
|
|
||||||
import com.njcn.msgpush.module.push.service.channel.ChannelProviderConfigService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author caozehui
|
|
||||||
* @data 2026-02-10
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class ClientConfiguration {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ChannelProviderConfigService channelProviderConfigService;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Map<String, MessageProviderFactory> messageProviderFactoryMap() throws Exception {
|
|
||||||
List<ChannelProviderConfigDO> activeProviders = channelProviderConfigService.getActiveProviders();
|
|
||||||
Map<String, MessageProviderFactory> messageProviderFactoryMap = new HashMap<>();
|
|
||||||
|
|
||||||
for (ChannelProviderConfigDO config : activeProviders) {
|
|
||||||
switch (ProviderTypeEnum.getByCode(config.getProviderType())) {
|
|
||||||
case ALIYUN: {
|
|
||||||
MessageProviderFactory orDefault = messageProviderFactoryMap.getOrDefault(ProviderTypeEnum.ALIYUN.getCode(), new AliyunProviderFactory());
|
|
||||||
messageProviderFactoryMap.put(ProviderTypeEnum.ALIYUN.getCode(), orDefault);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TELECOM: {
|
|
||||||
MessageProviderFactory orDefault = messageProviderFactoryMap.getOrDefault(ProviderTypeEnum.TELECOM.getCode(), new TelecomProviderFactory());
|
|
||||||
messageProviderFactoryMap.put(ProviderTypeEnum.TELECOM.getCode(), orDefault);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case UNIPUSH: {
|
|
||||||
MessageProviderFactory orDefault = messageProviderFactoryMap.getOrDefault(ProviderTypeEnum.UNIPUSH.getCode(), new UniPushProviderFactory());
|
|
||||||
messageProviderFactoryMap.put(ProviderTypeEnum.UNIPUSH.getCode(), orDefault);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("该" + config.getProviderType() + "服务商暂不支持");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (messageProviderFactoryMap.isEmpty()) {
|
|
||||||
throw new Exception("当前没有激活的渠道服务商!");
|
|
||||||
}
|
|
||||||
return messageProviderFactoryMap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.njcn.msgpush.module.push.client.factory;
|
||||||
|
|
||||||
|
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.enums.ProviderTypeEnum;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class MessageProviderFactoryRegistry {
|
||||||
|
|
||||||
|
private final Map<String, MessageProviderFactory> factoryMap;
|
||||||
|
|
||||||
|
public MessageProviderFactoryRegistry() {
|
||||||
|
Map<String, MessageProviderFactory> factories = new HashMap<>();
|
||||||
|
factories.put(ProviderTypeEnum.ALIYUN.getCode(), new AliyunProviderFactory());
|
||||||
|
factories.put(ProviderTypeEnum.TELECOM.getCode(), new TelecomProviderFactory());
|
||||||
|
factories.put(ProviderTypeEnum.UNIPUSH.getCode(), new UniPushProviderFactory());
|
||||||
|
this.factoryMap = Collections.unmodifiableMap(factories);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageProviderFactory getFactory(String providerType) {
|
||||||
|
return factoryMap.get(providerType);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,30 +3,27 @@ package com.njcn.msgpush.module.push.controller.admin.channel;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.njcn.msgpush.framework.common.pojo.CommonResult;
|
import com.njcn.msgpush.framework.common.pojo.CommonResult;
|
||||||
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.controller.admin.channel.vo.ChannelProviderConfigReqVO;
|
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.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.ChannelProviderConfigService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static com.njcn.msgpush.framework.common.pojo.CommonResult.success;
|
import static com.njcn.msgpush.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
|
||||||
@Tag(name = "管理后台 - 渠道服务商")
|
@Tag(name = "管理后台 - 渠道服务商")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Validated
|
@Validated
|
||||||
@@ -37,10 +34,6 @@ public class ChannelProviderConfigController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ChannelProviderConfigService channelProviderConfigService;
|
private ChannelProviderConfigService channelProviderConfigService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Qualifier("messageProviderFactoryMap")
|
|
||||||
private Map<String, MessageProviderFactory> messageProviderFactoryMap;
|
|
||||||
|
|
||||||
@PostMapping("/page")
|
@PostMapping("/page")
|
||||||
@Operation(summary = "分页查询渠道服务商列表")
|
@Operation(summary = "分页查询渠道服务商列表")
|
||||||
@PreAuthorize("@ss.hasPermission('push:channel:page')")
|
@PreAuthorize("@ss.hasPermission('push:channel:page')")
|
||||||
@@ -67,9 +60,9 @@ public class ChannelProviderConfigController {
|
|||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
@Operation(summary = "删除渠道服务商")
|
@Operation(summary = "删除渠道服务商")
|
||||||
@PreAuthorize("@ss.hasPermission('push:channel:delete')")
|
@PreAuthorize("@ss.hasPermission('push:channel:delete')")
|
||||||
@Parameter(name = "ids", description = "id列表", required = true)
|
@Parameter(name = "ids", description = "id 列表", required = true)
|
||||||
public CommonResult<Boolean> delete(@RequestParam("ids") List<String> ids) {
|
public CommonResult<Boolean> delete(@RequestParam("ids") List<String> ids) {
|
||||||
boolean res = channelProviderConfigService.removeBatchByIds(ids);
|
boolean res = channelProviderConfigService.deleteByIds(ids);
|
||||||
return success(res);
|
return success(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,46 +71,7 @@ public class ChannelProviderConfigController {
|
|||||||
@PreAuthorize("@ss.hasPermission('push:channel:toggle')")
|
@PreAuthorize("@ss.hasPermission('push:channel:toggle')")
|
||||||
@Parameter(name = "id", description = "id", required = true)
|
@Parameter(name = "id", description = "id", required = true)
|
||||||
public CommonResult<Void> toggleEnableChannelProvider(@RequestParam("id") String id) {
|
public CommonResult<Void> toggleEnableChannelProvider(@RequestParam("id") String id) {
|
||||||
ChannelProviderConfigDO channelProviderConfigDO = channelProviderConfigService.toggleEnableField(id);
|
channelProviderConfigService.toggleEnableField(id);
|
||||||
|
|
||||||
if (channelProviderConfigDO.getEnabled() == 1) {
|
|
||||||
registerProviderBean(channelProviderConfigDO.getProviderType());
|
|
||||||
} else {
|
|
||||||
removeProviderBean(channelProviderConfigDO.getProviderType());
|
|
||||||
}
|
|
||||||
return success(null);
|
return success(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加指定providerType服务商对应的bean
|
|
||||||
*
|
|
||||||
* @param providerType 服务商类型,例如:aliyun\telecom\UniPush
|
|
||||||
*/
|
|
||||||
public void registerProviderBean(String providerType) {
|
|
||||||
switch (ProviderTypeEnum.getByCode(providerType)) {
|
|
||||||
case ALIYUN: {
|
|
||||||
messageProviderFactoryMap.put(ProviderTypeEnum.ALIYUN.getCode(), new AliyunProviderFactory());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TELECOM: {
|
|
||||||
messageProviderFactoryMap.put(ProviderTypeEnum.TELECOM.getCode(), new TelecomProviderFactory());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case UNIPUSH: {
|
|
||||||
messageProviderFactoryMap.put(ProviderTypeEnum.UNIPUSH.getCode(), new UniPushProviderFactory());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("该" + providerType + "服务商暂不支持");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 移除指定providerType服务商对应的bean
|
|
||||||
*
|
|
||||||
* @param providerType 服务商类型,例如:aliyun\telecom\UniPush
|
|
||||||
*/
|
|
||||||
public void removeProviderBean(String providerType) {
|
|
||||||
messageProviderFactoryMap.remove(providerType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,6 @@ import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX;
|
|||||||
import com.njcn.msgpush.module.push.dal.dataobject.channel.ChannelProviderConfigDO;
|
import com.njcn.msgpush.module.push.dal.dataobject.channel.ChannelProviderConfigDO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface ChannelProviderConfigMapper extends BaseMapperX<ChannelProviderConfigDO> {
|
public interface ChannelProviderConfigMapper extends BaseMapperX<ChannelProviderConfigDO> {
|
||||||
|
|
||||||
List<ChannelProviderConfigDO> getActiveProviders();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.njcn.msgpush.module.push.dal.mysql.channel.ChannelProviderConfigMapper">
|
|
||||||
|
|
||||||
<select id="getActiveProviders"
|
|
||||||
resultType="com.njcn.msgpush.module.push.dal.dataobject.channel.ChannelProviderConfigDO">
|
|
||||||
select *
|
|
||||||
from push_channel_provider_config
|
|
||||||
where enabled = 1
|
|
||||||
</select>
|
|
||||||
</mapper>
|
|
||||||
@@ -18,6 +18,7 @@ public interface MessageRetryQueueMapper extends BaseMapperX<MessageRetryQueueDO
|
|||||||
* @param limit 限制数量
|
* @param limit 限制数量
|
||||||
* @return 待重试消息列表
|
* @return 待重试消息列表
|
||||||
*/
|
*/
|
||||||
List<MessageRetryQueueDO> selectNeedRetryMessages(@Param("currentTime") LocalDateTime currentTime,
|
List<MessageRetryQueueDO> selectNeedRetryMessages(@Param("channel") String channel,
|
||||||
|
@Param("currentTime") LocalDateTime currentTime,
|
||||||
@Param("limit") int limit);
|
@Param("limit") int limit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
<select id="selectNeedRetryMessages" resultType="com.njcn.msgpush.module.push.dal.dataobject.retry.MessageRetryQueueDO">
|
<select id="selectNeedRetryMessages" resultType="com.njcn.msgpush.module.push.dal.dataobject.retry.MessageRetryQueueDO">
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM push_message_retry_queue
|
FROM push_message_retry_queue
|
||||||
WHERE next_retry_time <![CDATA[ <= ]]> #{currentTime}
|
WHERE channel = #{channel}
|
||||||
|
AND next_retry_time <![CDATA[ <= ]]> #{currentTime}
|
||||||
AND deleted = 0
|
AND deleted = 0
|
||||||
ORDER BY next_retry_time ASC
|
ORDER BY next_retry_time ASC
|
||||||
LIMIT #{limit}
|
LIMIT #{limit}
|
||||||
|
|||||||
@@ -8,25 +8,11 @@ import com.njcn.msgpush.module.push.dal.dataobject.channel.ChannelProviderConfig
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ChannelProviderConfigService extends IService<ChannelProviderConfigDO> {
|
public interface ChannelProviderConfigService extends IService<ChannelProviderConfigDO> {
|
||||||
|
|
||||||
Page<ChannelProviderConfigDO> getPage(ChannelProviderConfigReqVO reqVO);
|
Page<ChannelProviderConfigDO> getPage(ChannelProviderConfigReqVO reqVO);
|
||||||
|
|
||||||
List<ChannelProviderConfigDO> getActiveProviders();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 切换服务提供商enable字段
|
|
||||||
*
|
|
||||||
* @param id 服务提供商id
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
ChannelProviderConfigDO toggleEnableField(String id);
|
ChannelProviderConfigDO toggleEnableField(String id);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据类型和渠道获取服务提供商
|
|
||||||
*
|
|
||||||
* @param providerType 服务提供商类型
|
|
||||||
* @param channel 渠道
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
ChannelProviderConfigDO getByTypeAndChannel(String providerType, String channel);
|
ChannelProviderConfigDO getByTypeAndChannel(String providerType, String channel);
|
||||||
|
|
||||||
void failureUpdate(String providerType, String channel);
|
void failureUpdate(String providerType, String channel);
|
||||||
@@ -34,4 +20,6 @@ public interface ChannelProviderConfigService extends IService<ChannelProviderCo
|
|||||||
void successUpdate(String providerType, String channel);
|
void successUpdate(String providerType, String channel);
|
||||||
|
|
||||||
List<ChannelProviderConfigDO> getEnabledProviders(String channel);
|
List<ChannelProviderConfigDO> getEnabledProviders(String channel);
|
||||||
|
|
||||||
|
boolean deleteByIds(List<String> ids);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.njcn.msgpush.module.push.service.channel;
|
package com.njcn.msgpush.module.push.service.channel;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.stream.CollectorUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@@ -12,6 +14,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.njcn.msgpush.framework.common.exception.util.ServiceExceptionUtil.invalidParamException;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ChannelProviderConfigServiceImpl extends ServiceImpl<ChannelProviderConfigMapper, ChannelProviderConfigDO> implements ChannelProviderConfigService {
|
public class ChannelProviderConfigServiceImpl extends ServiceImpl<ChannelProviderConfigMapper, ChannelProviderConfigDO> implements ChannelProviderConfigService {
|
||||||
@@ -24,14 +29,31 @@ public class ChannelProviderConfigServiceImpl extends ServiceImpl<ChannelProvide
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ChannelProviderConfigDO> getActiveProviders() {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
return this.lambdaQuery().eq(ChannelProviderConfigDO::getEnabled, true).list();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChannelProviderConfigDO toggleEnableField(String id) {
|
public ChannelProviderConfigDO toggleEnableField(String id) {
|
||||||
ChannelProviderConfigDO channelProviderConfigDO = this.getById(id);
|
ChannelProviderConfigDO channelProviderConfigDO = this.getById(id);
|
||||||
channelProviderConfigDO.setEnabled(channelProviderConfigDO.getEnabled() ^ 0X0001);
|
if (channelProviderConfigDO == null) {
|
||||||
|
throw invalidParamException("渠道服务商配置不存在,id={}", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean enable = !Integer.valueOf(1).equals(channelProviderConfigDO.getEnabled());
|
||||||
|
if (enable) {
|
||||||
|
this.lambdaUpdate()
|
||||||
|
.eq(ChannelProviderConfigDO::getChannel, channelProviderConfigDO.getChannel())
|
||||||
|
.ne(ChannelProviderConfigDO::getId, channelProviderConfigDO.getId())
|
||||||
|
.set(ChannelProviderConfigDO::getEnabled, 0)
|
||||||
|
.update();
|
||||||
|
} else {
|
||||||
|
long enabledCount = this.lambdaQuery()
|
||||||
|
.eq(ChannelProviderConfigDO::getChannel, channelProviderConfigDO.getChannel())
|
||||||
|
.eq(ChannelProviderConfigDO::getEnabled, 1)
|
||||||
|
.count();
|
||||||
|
if (enabledCount <= 1) {
|
||||||
|
throw invalidParamException("渠道 {} 必须保留一个启用服务商,请先启用其它服务商后再禁用当前配置", channelProviderConfigDO.getChannel());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
channelProviderConfigDO.setEnabled(enable ? 1 : 0);
|
||||||
this.updateById(channelProviderConfigDO);
|
this.updateById(channelProviderConfigDO);
|
||||||
return channelProviderConfigDO;
|
return channelProviderConfigDO;
|
||||||
}
|
}
|
||||||
@@ -64,6 +86,26 @@ public class ChannelProviderConfigServiceImpl extends ServiceImpl<ChannelProvide
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ChannelProviderConfigDO> getEnabledProviders(String channel) {
|
public List<ChannelProviderConfigDO> getEnabledProviders(String channel) {
|
||||||
return this.lambdaQuery().eq(ChannelProviderConfigDO::getChannel, channel).list();
|
return this.lambdaQuery()
|
||||||
|
.eq(ChannelProviderConfigDO::getChannel, channel)
|
||||||
|
.eq(ChannelProviderConfigDO::getEnabled, 1)
|
||||||
|
.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean deleteByIds(List<String> ids) {
|
||||||
|
List<ChannelProviderConfigDO> configs = this.listByIds(ids);
|
||||||
|
List<ChannelProviderConfigDO> enabledConfigs = configs.stream()
|
||||||
|
.filter(config -> Integer.valueOf(1).equals(config.getEnabled()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtil.isNotEmpty(enabledConfigs)) {
|
||||||
|
String channels = enabledConfigs.stream()
|
||||||
|
.map(ChannelProviderConfigDO::getChannel)
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
throw invalidParamException("启用中的服务商配置禁止删除,请先禁用后再删除。涉及渠道:{}", channels);
|
||||||
|
}
|
||||||
|
return this.removeBatchByIds(ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.njcn.msgpush.framework.common.util.object.PageUtils;
|
import com.njcn.msgpush.framework.common.util.object.PageUtils;
|
||||||
import com.njcn.msgpush.module.push.checker.MsgPushGuardChain;
|
import com.njcn.msgpush.module.push.checker.MsgPushGuardChain;
|
||||||
import com.njcn.msgpush.module.push.client.factory.MessageProviderFactory;
|
import com.njcn.msgpush.module.push.client.factory.MessageProviderFactory;
|
||||||
|
import com.njcn.msgpush.module.push.client.factory.MessageProviderFactoryRegistry;
|
||||||
import com.njcn.msgpush.module.push.client.sender.SendOutcome;
|
import com.njcn.msgpush.module.push.client.sender.SendOutcome;
|
||||||
import com.njcn.msgpush.module.push.client.sender.SendResult;
|
import com.njcn.msgpush.module.push.client.sender.SendResult;
|
||||||
import com.njcn.msgpush.module.push.client.sender.Sender;
|
import com.njcn.msgpush.module.push.client.sender.Sender;
|
||||||
@@ -29,7 +30,6 @@ import com.njcn.msgpush.module.push.service.channel.ChannelProviderConfigService
|
|||||||
import com.njcn.msgpush.module.push.service.retry.MessageRetryHistoryService;
|
import com.njcn.msgpush.module.push.service.retry.MessageRetryHistoryService;
|
||||||
import com.njcn.msgpush.module.push.service.retry.MessageRetryQueueService;
|
import com.njcn.msgpush.module.push.service.retry.MessageRetryQueueService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -37,7 +37,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class MessageRecordServiceImpl extends ServiceImpl<MessageRecordMapper, MessageRecordDO> implements MessageRecordService {
|
public class MessageRecordServiceImpl extends ServiceImpl<MessageRecordMapper, MessageRecordDO> implements MessageRecordService {
|
||||||
@@ -55,8 +54,7 @@ public class MessageRecordServiceImpl extends ServiceImpl<MessageRecordMapper, M
|
|||||||
public ChannelProviderConfigService channelProviderConfigService;
|
public ChannelProviderConfigService channelProviderConfigService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("messageProviderFactoryMap")
|
private MessageProviderFactoryRegistry messageProviderFactoryRegistry;
|
||||||
private Map<String, MessageProviderFactory> messageProviderFactoryMap;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MsgPushGuardChain msgPushGuardChain;
|
private MsgPushGuardChain msgPushGuardChain;
|
||||||
@@ -126,7 +124,7 @@ public class MessageRecordServiceImpl extends ServiceImpl<MessageRecordMapper, M
|
|||||||
SendResult sendResult = null;
|
SendResult sendResult = null;
|
||||||
if (CollectionUtil.isNotEmpty(enabledProviders)) {
|
if (CollectionUtil.isNotEmpty(enabledProviders)) {
|
||||||
ChannelProviderConfigDO channelProviderConfigDO = enabledProviders.get(0);
|
ChannelProviderConfigDO channelProviderConfigDO = enabledProviders.get(0);
|
||||||
MessageProviderFactory messageProviderFactory = messageProviderFactoryMap.get(channelProviderConfigDO.getProviderType());
|
MessageProviderFactory messageProviderFactory = messageProviderFactoryRegistry.getFactory(channelProviderConfigDO.getProviderType());
|
||||||
sendResult = this.validateProviderAndChannel(messageRecordDO, channelProviderConfigDO, messageProviderFactory);
|
sendResult = this.validateProviderAndChannel(messageRecordDO, channelProviderConfigDO, messageProviderFactory);
|
||||||
|
|
||||||
messageRecordDO.setProviderType(channelProviderConfigDO.getProviderType());
|
messageRecordDO.setProviderType(channelProviderConfigDO.getProviderType());
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ public class MessageRetryQueueServiceImpl extends ServiceImpl<MessageRetryQueueM
|
|||||||
* @param channel
|
* @param channel
|
||||||
*/
|
*/
|
||||||
private void fallbackToDatabaseDirectly(String channel) {
|
private void fallbackToDatabaseDirectly(String channel) {
|
||||||
List<MessageRetryQueueDO> dbRecords = baseMapper.selectNeedRetryMessages(LocalDateTime.now(), DEFAULT_BATCH_SIZE);
|
List<MessageRetryQueueDO> dbRecords = baseMapper.selectNeedRetryMessages(channel, LocalDateTime.now(), DEFAULT_BATCH_SIZE);
|
||||||
|
|
||||||
if (CollUtil.isEmpty(dbRecords)) {
|
if (CollUtil.isEmpty(dbRecords)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -34,5 +34,11 @@ public interface RetryStrategyConfigService {
|
|||||||
*/
|
*/
|
||||||
boolean updateStrategyConfig(RetryStrategyConfigReqVO strategyConfigReqVO);
|
boolean updateStrategyConfig(RetryStrategyConfigReqVO strategyConfigReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切换重试策略的启用/禁用状态
|
||||||
|
*
|
||||||
|
* @param id 重试策略配置ID
|
||||||
|
* @return 是否切换成功
|
||||||
|
*/
|
||||||
boolean toggleEnableField(String id);
|
boolean toggleEnableField(String id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.njcn.msgpush.module.push.sms;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.njcn.msgpush.module.push.client.factory.MessageProviderFactory;
|
import com.njcn.msgpush.module.push.client.factory.MessageProviderFactory;
|
||||||
|
import com.njcn.msgpush.module.push.client.factory.MessageProviderFactoryRegistry;
|
||||||
import com.njcn.msgpush.module.push.client.sender.Sender;
|
import com.njcn.msgpush.module.push.client.sender.Sender;
|
||||||
import com.njcn.msgpush.module.push.client.sender.SmsSender;
|
import com.njcn.msgpush.module.push.client.sender.SmsSender;
|
||||||
import com.njcn.msgpush.module.push.controller.admin.message.vo.MessageRecordReqVO;
|
import com.njcn.msgpush.module.push.controller.admin.message.vo.MessageRecordReqVO;
|
||||||
@@ -13,14 +14,12 @@ import com.njcn.msgpush.module.push.service.message.MessageRecordService;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
@@ -35,8 +34,7 @@ public class MsgPushClientTest {
|
|||||||
private MessageRecordService messageRecordService;
|
private MessageRecordService messageRecordService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("messageProviderFactoryMap")
|
private MessageProviderFactoryRegistry messageProviderFactoryRegistry;
|
||||||
private Map<String, MessageProviderFactory> messageProviderFactoryMap;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Sender sender;
|
private Sender sender;
|
||||||
@@ -56,23 +54,23 @@ public class MsgPushClientTest {
|
|||||||
// message.setProviderType(MsgPushConstant.PROVIDER_TYPE_ALI_YUN);
|
// message.setProviderType(MsgPushConstant.PROVIDER_TYPE_ALI_YUN);
|
||||||
// messageIdList.add(message);
|
// messageIdList.add(message);
|
||||||
// }
|
// }
|
||||||
for (int i = 0; i < 1; i++) {
|
// for (int i = 0; i < 1; i++) {
|
||||||
MessageRecordReqVO message = new MessageRecordReqVO();
|
// MessageRecordReqVO message = new MessageRecordReqVO();
|
||||||
message.setId(1234567890L);
|
// message.setId(1234567890L);
|
||||||
message.setChannel(ChannelTypeEnum.SMS.getMsg());
|
// message.setChannel(ChannelTypeEnum.SMS.getMsg());
|
||||||
message.setReceiver("18839431215");
|
// message.setReceiver("18839431215");
|
||||||
message.setContent("【南京灿能电力】测试短信" + i + ",请忽略。" + LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
// message.setContent("【南京灿能电力】测试短信" + i + ",请忽略。" + LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||||
messageIdList.add(message);
|
// messageIdList.add(message);
|
||||||
}
|
// }
|
||||||
List<MessageSendResultVO> sendResult = messageRecordService.send(messageIdList, ChannelTypeEnum.SMS);
|
// List<MessageSendResultVO> sendResult = messageRecordService.send(messageIdList, ChannelTypeEnum.SMS);
|
||||||
|
//
|
||||||
Thread.sleep(9000);
|
// Thread.sleep(9000);
|
||||||
System.out.println(JSON.toJSONString(sendResult));
|
// System.out.println(JSON.toJSONString(sendResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void templateSelect() {
|
public void templateSelect() {
|
||||||
MessageProviderFactory messageProviderFactory = messageProviderFactoryMap.get(ProviderTypeEnum.TELECOM.getCode());
|
MessageProviderFactory messageProviderFactory = messageProviderFactoryRegistry.getFactory(ProviderTypeEnum.TELECOM.getCode());
|
||||||
ChannelProviderConfigDO config = new ChannelProviderConfigDO();
|
ChannelProviderConfigDO config = new ChannelProviderConfigDO();
|
||||||
config.setApiUrl("https://sms.ymeeting.cn/smsv2");
|
config.setApiUrl("https://sms.ymeeting.cn/smsv2");
|
||||||
config.setAppKey("925631");
|
config.setAppKey("925631");
|
||||||
|
|||||||
Reference in New Issue
Block a user