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.common.constant.ChannelCode; 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 org.springframework.stereotype.Service; /** *

* 消息 服务实现类 *

* * @author mg * @since 2022-10-08 */ @Service public class MessageServiceImpl extends ServiceImpl implements IMessageService { @Override public Message sendMessage(MessageParam messageParam) { Message message = null; Provider provider = null; switch (messageParam.getChannelCode()) { //内站发送 case ChannelCode.INNER: provider = new InnerFactory(); break; //邮件发送 case ChannelCode.SMS: provider = new MailFactory(); //id换成邮箱号 //String targetToMail = adminService.getTargetTo(messageParam.getTargetTo(), messageParam.getChannelCode()); //messageParam.setTargetTo(targetToMail); break; //短信发送 case ChannelCode.MAIL: 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<>(); if (messageParam.getMessageType() != null) { queryWrapper.eq(Message::getMessageType, messageParam.getMessageType()); } if (messageParam.getStatus() != null) { queryWrapper.eq(Message::getStatus, messageParam.getStatus()); } queryWrapper.orderByDesc(Message::getCreateTime); Page result = baseMapper.selectPage(page, queryWrapper); return result; } }