package com.gunshi.project.ss.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gunshi.project.ss.entity.dto.WarningAuditDto; import com.gunshi.project.ss.entity.so.WarningRulePageSo; import com.gunshi.project.ss.mapper.WarningRuleInfoMapper; import com.gunshi.project.ss.model.AuditProcess; import com.gunshi.project.ss.model.WarningCondition; import com.gunshi.project.ss.model.WarningRecObj; import com.gunshi.project.ss.model.WarningRuleInfo; import com.ruoyi.common.utils.SecurityUtils; 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.io.Serializable; import java.time.LocalDateTime; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Service @Slf4j @Transactional(rollbackFor = Exception.class) public class WarningRuleInfoService extends ServiceImpl { @Autowired private WarningConditionService warningConditionService; @Autowired private AuditProcessService auditProcessService; @Autowired private WarningRecObjService objService; public Page pageQuery(WarningRulePageSo page) { Page warningRuleInfoPage = this.baseMapper.page(page.getPageSo().toPage(), page); List records = warningRuleInfoPage.getRecords(); for (WarningRuleInfo record : records) { List listByRuleId = warningConditionService.getListByRuleId(record.getRuleId()); record.setConditions(listByRuleId); } return warningRuleInfoPage; } public Map infoStat(WarningRulePageSo page) { List list = this.baseMapper.infoStat(page); return list.stream().collect(Collectors.groupingBy(WarningRuleInfo::getWarningLevel, Collectors.counting())); } public String publish(WarningRuleInfo warningRuleInfo) { warningRuleInfo.setStatus(1); Integer warningLevel = warningRuleInfo.getWarningLevel(); LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); queryWrapper.eq(AuditProcess::getWarningLevel,warningLevel); AuditProcess auditProcess = auditProcessService.getOne(queryWrapper); if (auditProcess == null) { return "未找到该预警级别对应的审批流程"; } warningRuleInfo.setInitAuditUserId(SecurityUtils.getUserId()); warningRuleInfo.setInitAuditUserName(SecurityUtils.getUsername()); warningRuleInfo.setInitAuditTime(LocalDateTime.now()); warningRuleInfo.setFirstAuditUserId(auditProcess.getFirstAuditUserId()); warningRuleInfo.setFirstAuditUserName(auditProcess.getFirstAuditUserName()); this.updateById(warningRuleInfo); objService.saveOrUpdateBatch(warningRuleInfo.getObjs()); return "发布成功"; } public List queryObj(Serializable id) { LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); queryWrapper.eq(WarningRecObj::getWarningInfoId,id); return objService.list(queryWrapper); } public Page auditPage(WarningRulePageSo page) { return this.baseMapper.auditPage(page.getPageSo().toPage(), page); } public Boolean audit(WarningAuditDto dto) { WarningRuleInfo info = this.getById(dto.getId()); if (info == null) { throw new IllegalArgumentException("id不存在"); } if (dto.getType() == 1) { if (!info.getFirstAuditUserId().equals(SecurityUtils.getUserId())) { throw new IllegalArgumentException("对不起,您没有审核权限"); } info.setFirstAuditStatus(dto.getStatus()); info.setFirstAuditTime(LocalDateTime.now()); if (info.getSecondAuditUserId() == null){ info.setStatus(dto.getStatus()); } } if (dto.getType() == 2) { if (!info.getSecondAuditUserId().equals(SecurityUtils.getUserId())) { throw new IllegalArgumentException("对不起,您没有审核权限"); } info.setSecondAuditStatus(dto.getStatus()); info.setSecondAuditTime(LocalDateTime.now()); info.setStatus(dto.getStatus()); } return this.updateById(info); } }