package com.ycl.service.message.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ycl.dto.message.MessageParam; import com.ycl.entity.message.Message; import com.ycl.exception.ApiException; import com.ycl.mapper.message.MessageMapper; import com.ycl.service.message.IMessageService; import com.ycl.service.message.Provider; import com.ycl.service.message.Sender; import com.ycl.service.message.factory.InnerFactory; import com.ycl.service.message.factory.MailFactory; import com.ycl.service.message.factory.SmsFactory; import com.ycl.service.user.UmsAdminService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** *

* 消息 服务实现类 *

* * @author mg * @since 2022-10-08 */ @Service public class MessageServiceImpl extends ServiceImpl implements IMessageService { @Autowired private UmsAdminService adminService; @Override public Message sendMessage(MessageParam messageParam) { Message message = null; Provider provider = null; switch (messageParam.getChannelCode()) { //内站发送 case "01": provider = new InnerFactory(); break; //邮件发送 case "02": provider = new MailFactory(); //id换成邮箱号 String targetToMail = adminService.getTargetTo(messageParam.getTargetTo(), messageParam.getChannelCode()); messageParam.setTargetTo(targetToMail); break; //短信发送 case "03": provider = new SmsFactory(); //id换成手机号 String targetToPhone = adminService.getTargetTo(messageParam.getTargetTo(), messageParam.getChannelCode()); messageParam.setTargetTo(targetToPhone); break; default: throw new ApiException("未匹配到该类型"); } Sender sender = provider.produce(); sender.sendMessage(messageParam); return message; } @Override public IPage list(MessageParam messageParam) { Page page = new Page<>(messageParam.getCurrent(), messageParam.getPageSize()); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); Page result = baseMapper.selectPage(page, queryWrapper); return result; } }