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.entity.message.Message; import com.ycl.entity.message.SmsAudit; import com.ycl.entity.user.UmsDepartManage; import com.ycl.mapper.message.SmsAuditMapper; import com.ycl.mapper.user.UmsDepartManageMapper; import com.ycl.service.message.ISmsAuditService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; /** *

* 短信审核 服务实现类 *

* * @author mg * @since 2022-10-17 */ @Service public class SmsAuditServiceImpl extends ServiceImpl implements ISmsAuditService { @Resource private UmsDepartManageMapper umsDepartManageMapper; @Override public IPage list(SmsAudit smsAudit) { Page page = new Page<>(smsAudit.getCurrent(), smsAudit.getPageSize()); /*LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); if (smsAudit.getAuditId() != null) { queryWrapper.eq(SmsAudit::getAuditId, smsAudit.getAuditId()); } if (smsAudit.getAuditStatus() != null) { queryWrapper.eq(SmsAudit::getAuditStatus, smsAudit.getAuditStatus()); } queryWrapper.orderByDesc(SmsAudit::getCreateTime); Page result = baseMapper.selectPage(page, queryWrapper);*/ Page result = baseMapper.selectCondPage(page, smsAudit); return result; } @Override public void startAuditSms(Message message) { String[] arr = message.getTargetTo().split(","); List ids = new ArrayList<>(); for (int i = 0; i < arr.length; i++) { ids.add(Long.parseLong(arr[i])); } //查询部门 LambdaQueryWrapper queryDeptWrapper = new LambdaQueryWrapper<>(); queryDeptWrapper.in(UmsDepartManage::getUserId, ids); List depts = umsDepartManageMapper.selectList(queryDeptWrapper); //部门去重 List uniques = depts.stream().collect( Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o->o.getDepartId()))), ArrayList::new)); List deptLeadIds = uniques.stream().map(UmsDepartManage::getDepartId).collect(Collectors.toList()); LambdaQueryWrapper queryDeptLeadWrapper = new LambdaQueryWrapper<>(); queryDeptLeadWrapper.in(UmsDepartManage::getDepartId, deptLeadIds).eq(UmsDepartManage::getIsLeader,1); List deptLeads = umsDepartManageMapper.selectList(queryDeptLeadWrapper); //添加短信审核 List audits = new ArrayList<>(); for (UmsDepartManage depart : deptLeads) { SmsAudit audit = new SmsAudit(); audit.setMessageId(message.getId()); audit.setAuditId(depart.getUserId()); //待审核状态 audit.setAuditStatus(0); Long userId = Long.parseLong(message.getTargetFrom()); audit.setCreateUser(userId); audit.setCreateTime(new Date()); audit.setUpdateUser(userId); audit.setUpdateTime(new Date()); audits.add(audit); } saveBatch(audits); } }