package cn.lili.modules.sms.serviceimpl; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.common.vo.PageVO; import cn.lili.modules.sms.entity.dos.SmsSign; import cn.lili.modules.sms.mapper.SmsSignMapper; import cn.lili.modules.sms.plugin.SmsPluginFactory; import cn.lili.modules.sms.service.SmsSignService; import cn.lili.mybatis.util.PageUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 短信签名业务层实现 * * @author Chopper * @since 2021/1/30 4:27 下午 */ @Slf4j @Service public class SmsSignServiceImpl extends ServiceImpl implements SmsSignService { @Autowired private SmsPluginFactory smsPluginFactory; @Override @Transactional(rollbackFor = Exception.class) public void addSmsSign(SmsSign smsSign) { try { //如果短信签名已存在,不能重复申请 if (this.getOne(new QueryWrapper().eq("sign_name", smsSign.getSignName())) != null) { throw new ServiceException(ResultCode.SMS_SIGN_EXIST_ERROR); } smsPluginFactory.smsPlugin().addSmsSign(smsSign); smsSign.setSignStatus(0); this.save(smsSign); } catch (Exception e) { log.error("添加短信签名错误", e); } } @Override @Transactional(rollbackFor = Exception.class) public void deleteSmsSign(String id) { try { SmsSign smsSign = this.getById(id); if (smsSign != null) { smsPluginFactory.smsPlugin().deleteSmsSign(smsSign.getSignName()); this.removeById(id); } } catch (Exception e) { log.error("删除短信签名错误", e); } } @Override @Transactional(rollbackFor = Exception.class) public void querySmsSign() { try { Map map = new HashMap<>(16); //获取未审核通过的签名列表 List list = list(new LambdaQueryWrapper().ne(SmsSign::getSignStatus, 1)); //查询签名状态 for (SmsSign smsSign : list) { map = smsPluginFactory.smsPlugin().querySmsSign(smsSign.getSignName()); smsSign.setSignStatus((Integer) map.get("SignStatus")); smsSign.setReason(map.get("Reason").toString()); this.updateById(smsSign); } } catch (Exception e) { log.error("查询短信签名错误", e); } } @Override @Transactional(rollbackFor = Exception.class) public void modifySmsSign(SmsSign smsSign) { try { smsPluginFactory.smsPlugin().modifySmsSign(smsSign); this.updateById(smsSign); } catch (Exception e) { log.error("更新短信签名错误", e); } } @Override public IPage page(PageVO pageVO, Integer signStatus) { return this.page(PageUtil.initPage(pageVO), new QueryWrapper() .eq(signStatus != null, "sign_status", signStatus)); } }