gunshi-project-ss/src/main/java/com/gunshi/project/ss/service/WarningRuleInfoService.java

112 lines
4.6 KiB
Java
Raw Normal View History

2025-12-29 17:13:09 +08:00
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;
2025-12-29 17:13:09 +08:00
import com.gunshi.project.ss.entity.so.WarningRulePageSo;
import com.gunshi.project.ss.mapper.WarningRuleInfoMapper;
import com.gunshi.project.ss.model.AuditProcess;
2025-12-29 17:13:09 +08:00
import com.gunshi.project.ss.model.WarningCondition;
import com.gunshi.project.ss.model.WarningRecObj;
2025-12-29 17:13:09 +08:00
import com.gunshi.project.ss.model.WarningRuleInfo;
import com.ruoyi.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
2025-11-26 18:00:57 +08:00
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;
2025-11-26 18:00:57 +08:00
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
2025-11-26 18:00:57 +08:00
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class WarningRuleInfoService extends ServiceImpl<WarningRuleInfoMapper,WarningRuleInfo> {
2025-11-26 18:00:57 +08:00
@Autowired
private WarningConditionService warningConditionService;
@Autowired
private AuditProcessService auditProcessService;
@Autowired
private WarningRecObjService objService;
2025-11-26 18:00:57 +08:00
public Page<WarningRuleInfo> pageQuery(WarningRulePageSo page) {
Page<WarningRuleInfo> warningRuleInfoPage = this.baseMapper.page(page.getPageSo().toPage(), page);
2025-11-26 18:00:57 +08:00
List<WarningRuleInfo> records = warningRuleInfoPage.getRecords();
for (WarningRuleInfo record : records) {
List<WarningCondition> listByRuleId = warningConditionService.getListByRuleId(record.getRuleId());
record.setConditions(listByRuleId);
}
return warningRuleInfoPage;
}
public Map<Integer, Long> infoStat(WarningRulePageSo page) {
List<WarningRuleInfo> list = this.baseMapper.infoStat(page);
return list.stream().collect(Collectors.groupingBy(WarningRuleInfo::getWarningLevel, Collectors.counting()));
}
public String publish(WarningRuleInfo warningRuleInfo) {
2026-03-10 13:14:44 +08:00
warningRuleInfo.setStatus(1);
Integer warningLevel = warningRuleInfo.getWarningLevel();
LambdaQueryWrapper<AuditProcess> 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);
2026-03-10 13:14:44 +08:00
objService.saveOrUpdateBatch(warningRuleInfo.getObjs());
return "发布成功";
}
public List<WarningRecObj> queryObj(Serializable id) {
LambdaQueryWrapper<WarningRecObj> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(WarningRecObj::getWarningInfoId,id);
return objService.list(queryWrapper);
}
public Page<WarningRuleInfo> 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);
}
}