2025-12-29 17:13:09 +08:00
|
|
|
package com.gunshi.project.ss.service;
|
2025-11-20 16:22:07 +08:00
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
2026-03-04 14:31:38 +08:00
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
2025-11-20 16:22:07 +08:00
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
2026-03-04 14:31:38 +08:00
|
|
|
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;
|
2026-03-04 14:31:38 +08:00
|
|
|
import com.gunshi.project.ss.model.AuditProcess;
|
2025-12-29 17:13:09 +08:00
|
|
|
import com.gunshi.project.ss.model.WarningCondition;
|
2026-03-04 14:31:38 +08:00
|
|
|
import com.gunshi.project.ss.model.WarningRecObj;
|
2025-12-29 17:13:09 +08:00
|
|
|
import com.gunshi.project.ss.model.WarningRuleInfo;
|
2026-03-04 14:31:38 +08:00
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
2025-11-20 16:22:07 +08:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2025-11-26 18:00:57 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2025-11-20 16:22:07 +08:00
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
2026-03-04 14:31:38 +08:00
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.time.LocalDateTime;
|
2025-11-26 18:00:57 +08:00
|
|
|
import java.util.List;
|
2026-03-04 14:31:38 +08:00
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
2025-11-26 18:00:57 +08:00
|
|
|
|
2025-11-20 16:22:07 +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;
|
|
|
|
|
|
2026-03-04 14:31:38 +08:00
|
|
|
@Autowired
|
|
|
|
|
private AuditProcessService auditProcessService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private WarningRecObjService objService;
|
|
|
|
|
|
2025-11-26 18:00:57 +08:00
|
|
|
|
2025-11-20 16:22:07 +08:00
|
|
|
public Page<WarningRuleInfo> pageQuery(WarningRulePageSo page) {
|
2026-03-04 14:31:38 +08:00
|
|
|
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);
|
|
|
|
|
}
|
2025-11-20 16:22:07 +08:00
|
|
|
return warningRuleInfoPage;
|
|
|
|
|
}
|
2026-03-04 14:31:38 +08:00
|
|
|
|
|
|
|
|
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);
|
2026-03-04 14:31:38 +08:00
|
|
|
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
|
|
|
|
2026-03-04 14:31:38 +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);
|
|
|
|
|
}
|
2025-11-20 16:22:07 +08:00
|
|
|
}
|