短信发送校验功能使用策略模式,结构搭建

main
heqijun 4 months ago
parent 1a683d216d
commit c3ad285992

@ -1,10 +1,10 @@
package com.mashibing.api.controller;
import com.mashibing.api.pojo.SingleSendRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.mashibing.api.service.sendCheck.SendCheckContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
/**
* @author heqijun
@ -15,11 +15,15 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("sms")
@RefreshScope
public class SMSController {
@PostMapping("singleSend")
public String singleSend(@RequestParam SingleSendRequest request) {
@Autowired
SendCheckContext sendCheckContext;
return null;
@PostMapping("singleSend")
public String singleSend(@RequestBody SingleSendRequest request) {
sendCheckContext.check(request);
return "接口测试!!!";
}
}

@ -0,0 +1,40 @@
package com.mashibing.api.service.sendCheck;
import com.mashibing.api.pojo.SingleSendRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author heqijun
* @ClassName: SendCheckContext
* @Description: TODO()
* @date 2025/6/4 20:19
*/
@Component
@RefreshScope
public class SendCheckContext {
//Spring的IoC容器会把所有管理的bean方到一个map里
//可以指定bean的类型获取到bean的map集合
@Autowired
Map<String, SendCheckService> sendCheckServiceMap;
// 从配置中心获取到的校验项目和顺序
@Value("${filters}")
private String[] filters;
public void check(SingleSendRequest request) {
for (String filter : filters) {
SendCheckService check = sendCheckServiceMap.get(filter);
if (check != null) {
check.check(request);
}
}
}
}

@ -0,0 +1,16 @@
package com.mashibing.api.service.sendCheck;
import com.mashibing.api.pojo.SingleSendRequest;
/**
* @author heqijun
* @ClassName: SendCheckService
* @Description:
* @date 2025/6/4 19:29
*/
public interface SendCheckService {
void check(SingleSendRequest request);
}

@ -0,0 +1,23 @@
package com.mashibing.api.service.sendCheck.impl;
import com.mashibing.api.pojo.SingleSendRequest;
import com.mashibing.api.service.sendCheck.SendCheckService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author heqijun
* @ClassName: ApikeyServiceImpl
* @Description: Apikey
* @date 2025/6/4 19:30
*/
@Slf4j
@Service("ApikeySendCheck")
public class ApikeySendCheckServiceImpl implements SendCheckService {
@Override
public void check(SingleSendRequest request) {
log.info("Check apikey...");
}
}

@ -0,0 +1,22 @@
package com.mashibing.api.service.sendCheck.impl;
import com.mashibing.api.pojo.SingleSendRequest;
import com.mashibing.api.service.sendCheck.SendCheckService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author heqijun
* @ClassName: FeeSendCheckServiceImpl
* @Description:
* @date 2025/6/4 19:37
*/
@Slf4j
@Service("FeeSendCheck")
public class FeeSendCheckServiceImpl implements SendCheckService {
@Override
public void check(SingleSendRequest request) {
log.info("Check Fee Send Check");
}
}

@ -0,0 +1,22 @@
package com.mashibing.api.service.sendCheck.impl;
import com.mashibing.api.pojo.SingleSendRequest;
import com.mashibing.api.service.sendCheck.SendCheckService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author heqijun
* @ClassName: IpSendCheckServiceImpl
* @Description: ip
* @date 2025/6/4 19:34
*/
@Slf4j
@Service("IpSendCheck")
public class IpSendCheckServiceImpl implements SendCheckService {
@Override
public void check(SingleSendRequest request) {
log.info("Check IpSendCheck");
}
}

@ -0,0 +1,22 @@
package com.mashibing.api.service.sendCheck.impl;
import com.mashibing.api.pojo.SingleSendRequest;
import com.mashibing.api.service.sendCheck.SendCheckService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author heqijun
* @ClassName: MobileSendCheckServiceImpl
* @Description:
* @date 2025/6/4 19:36
*/
@Slf4j
@Service("MobileSendCheck")
public class MobileSendCheckServiceImpl implements SendCheckService {
@Override
public void check(SingleSendRequest request) {
log.info("Check mobile send check");
}
}

@ -0,0 +1,22 @@
package com.mashibing.api.service.sendCheck.impl;
import com.mashibing.api.pojo.SingleSendRequest;
import com.mashibing.api.service.sendCheck.SendCheckService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author heqijun
* @ClassName: SignSendCheckServiceImpl
* @Description:
* @date 2025/6/4 19:34
*/
@Slf4j
@Service("SignSendCheck")
public class SignSendCheckServiceImpl implements SendCheckService {
@Override
public void check(SingleSendRequest request) {
log.info("Check SignSendCheck");
}
}

@ -0,0 +1,22 @@
package com.mashibing.api.service.sendCheck.impl;
import com.mashibing.api.pojo.SingleSendRequest;
import com.mashibing.api.service.sendCheck.SendCheckService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* @author heqijun
* @ClassName: TemplateSendCheckServiceImpl
* @Description:
* @date 2025/6/4 19:35
*/
@Slf4j
@Service("TemplateSendCheck")
public class TemplateSendCheckServiceImpl implements SendCheckService {
@Override
public void check(SingleSendRequest request) {
log.info("Check TemplateSendCheckServiceImpl");
}
}
Loading…
Cancel
Save