当前位置: 首页 > news >正文

如何批量做网站网站优化排名软件推广

如何批量做网站,网站优化排名软件推广,绵阳网站建设费用,一个公司做网站需要注意什么本文介绍项目中常用的策略模式工厂模式的案例,该案例是针对策略类比较少的情况;下一篇会讲解策略类比较多的案例,下面直接开始: 案例1:项目中对系统中的客户和销售进行事件通知(短信、邮件、钉钉) 首先要有通知的策略…

本文介绍项目中常用的策略模式+工厂模式的案例,该案例是针对策略类比较少的情况下一篇会讲解策略类比较多的案例,下面直接开始:

案例1:项目中对系统中的客户和销售进行事件通知(短信、邮件、钉钉)

首先要有通知的策略接口,接口里面要有一个方法就是通知的方法

public interface PushChannelStrategy{// 通知方法SendResult send(MessagePushParam param,BaseMsg baseMsg);}

有了接口那必然有实现类,三个实现类短信、邮件、钉钉

短信:

@Slf4j
@Component
public class SmsPushChannelStrategy implements PushChannelStrategy{@Autowiredprivate NoticeClient noticeClient;@Overridepublic SendResult send(MessagePushParam param,BaseMsg baseMsg){//1、before send check//2、send smsNoticeResult noticeResult=noticeClient.sendSms(xxxx);sendResult.setMessageStatus(MessageStatusEnum.SUCCESS);return sendResult;}
}

邮件:

@Slf4j
@Component
public class EmailPushChannelStrategy implements PushChannelStrategy{@Autowiredprivate NoticeClient noticeClient;@Overridepublic SendResult send(MessagePushParam param,BaseMsg baseMsg){//1、before send check//2、send emailEmail emailMsg=(Email)baseMsg;NoticeResult noticeResult=noticeClient.sendEmail(xxxx);sendResult.setMessageStatus(MessageStatusEnum.SUCCESS);return sendResult;}
}

钉钉:

@Slf4j
@Component
public class DingTalkPushChannelStrategy implements PushChannelStrategy{@Autowiredprivate DingTalkClient dingTalkClient;@Overridepublic SendResult send(MessagePushParam param,BaseMsg baseMsg){//1、before send check//2、send ding talkSendResult sendResult=dingTalkClient.send(xxx);// 其他结果参数组装return sendResult;}
}

然后通过策略工厂来获取具体的策略类:(由于只有三个策略类,所以通过注入的方式对channel进行判断)

@Component
public class PushChannelStrategyFactory{@Autowired private DingTalkPushChannelStrategy dingTalkPushChannelStrategy;@Autowiredprivate SmsPushChannelStrategy smsPushChannelStrategy;@Autowiredprivate EmailPushChannelStrategy emailPushChannelStrategy;public PushChannelStrategy getStrategy(PushChannel pushChannel){switch(pushChannel){case DING_TALK:return dingTalkPushChannelStrategy;case SMS:return smsPushChannelStrategy;case EMAIL:return emailPushChannelStrategy;default:throw new RuntimeException("不支持的类型");}}
}

当然策略工厂针对策略实现类比较少的情况还可以这样写:

@Component
public class PushChannelStrategyFactory2{@Autowiredprivate DingTalkPushChannelStrategy dingTalkPushChannelStrategy;@Autowiredprivate SmsPushChannelStrategy smsPushChannelStrategy;@Autowiredprivate EmailPushChannelStrategy emailPushChannelStrategy;private static final Map<PushChannel,PushChannelStrategy> pushChannelBuilderMap=new HashMap<>();@PostConstructpublic void init(){pushChannelBuilderMap.put(PushChannel.SMS,smsPushChannelStrategy);pushChannelBuilderMap.put(PushChannel.Email,emailPushChannelStrategy);pushChannelBuilderMap.put(PushChannel.DING_TALK,dingTalkPushChannelStrategy);}Public PushChannelStrategy getStrategy(PushChannel PushChannel){if(PushChannel==null){return null;}return pushChannelBuilderMap.get(PushChannel);}
}

用到的枚举类:

@Getter
public enum PushChannel{SMS("sms","短信"),EMAIL("email","邮件"),DING_TALK("dingTalk","钉钉");private final String value;PushChannel(String value,String desc){this.value=value;}public static PushChannel getPushChannel(String pushChannel){if(pushChannel==null){return null;}for(PushChannel channel:PushChannel.values()){if(pushChannel.equals(channel.getValue())){return channel;}}return null;}
}

在使用的时候通过策略工厂里面的方法获取具体的策略类:

@Slf4j
@Servicepublic class MessagePushService{@Autowiredprivate PushChannelStrategyFactory pushChannelStrategyFactory;@Autowiredprivate MessageRecordRepository messageRecordRepository;public ResultDTO<Boolean> pushSync(MessagePushCommand command){MessagePushParam messagePushParam =MessagePushAssembler.convert(command);//1,业务逻辑处理//2、根据渠道进行触达PushChannel pushChannel=messagePushParam.getChannel();if(pushChannel==null){throw new MessagePushException(xxx);}//3、获取具体的策略类PushChannelStrategy pushChannelStrategy=pushChannelStrategyFactory.getStrategy(pushChannel);SendResult sendResult=PushChannelStrategy.send(messagePushParam,xxx);//4,记录落库return ResultDTO.getSuccessResult(true);}}

到此该版本的策略模式+工厂模式就结束了,欢迎点评和指出不足之处。

http://www.ds6.com.cn/news/48157.html

相关文章:

  • 常州好搜网络科技有限公司优化网站搜索排名
  • wordpress购物盒子seo在线论坛
  • 章丘做网站搜索引擎最新排名
  • 网站建设常规自适应怎么优化
  • 网站建设成本图怎么去做推广
  • 江门网站建设价格微信推广方案
  • 色彩搭配比较好的网站年度关键词有哪些
  • 北京网站建设培训班上海百度首页优化
  • 免备案的网站建设搜索引擎推广的三种方式
  • 购物网站大全棉鞋做销售找客户渠道
  • 泰安网站开发推广上海站群优化公司
  • 生成静态页面网站源码郑州外语网站建站优化
  • 徐东网站建设福州360手机端seo
  • 网页制作素材是什么seo搜索排名优化
  • 机械设备行业网站建设一键优化软件
  • 和平区网站建设优化大师windows
  • 网站下载app免费安全seo快速排名软件平台
  • 湖南省建设信息网北京推广优化公司
  • 广告网站留电话不用验证码新品推广计划与方案
  • 做网站建设哪家公司靠谱友情链接交换网
  • 药业做网站的网站目标分析西安网站建设
  • 网站seo优化推广外包目前最火的自媒体平台
  • 网站建设创业公司策划方案做seo有什么好处
  • wordpress 如何 删除授权山东网站seo推广优化价格
  • 网站开发设计合同优化关键词的方法有哪些
  • 商城网站建设特点网站网页的优化方法
  • 广州制作网站公司口碑营销ppt
  • 大连网站开发工资简述网络营销的主要方法
  • 三明做网站关键词优化师
  • b站上值得看的纪录片搜索引擎优化seo怎么做