隐患整改
This commit is contained in:
@ -6,6 +6,7 @@ import org.dromara.safety.domain.vo.HazardRuleNotifyObjectVo;
|
|||||||
import org.dromara.safety.domain.vo.HazardRuleVo;
|
import org.dromara.safety.domain.vo.HazardRuleVo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 隐患规则通知对象Service接口
|
* 隐患规则通知对象Service接口
|
||||||
@ -31,6 +32,15 @@ public interface IHazardRuleNotifyObjectService extends IService<HazardRuleNotif
|
|||||||
*/
|
*/
|
||||||
List<HazardRuleNotifyObjectVo> queryVo(List<HazardRuleNotifyObject> objectList);
|
List<HazardRuleNotifyObjectVo> queryVo(List<HazardRuleNotifyObject> objectList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据规则查询所有通知对象id
|
||||||
|
*
|
||||||
|
* @param ruleId 规则id
|
||||||
|
* @param projectId 项目id
|
||||||
|
* @return 通知对象id
|
||||||
|
*/
|
||||||
|
Set<Long> queryNotifyObjectIds(Long ruleId, Long projectId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 补充数据
|
* 补充数据
|
||||||
*
|
*
|
||||||
|
|||||||
@ -8,11 +8,14 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.core.utils.MapstructUtils;
|
import org.dromara.common.core.utils.MapstructUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
|
import org.dromara.common.sse.dto.SseMessageDto;
|
||||||
|
import org.dromara.common.sse.utils.SseMessageUtils;
|
||||||
import org.dromara.safety.domain.HazardHiddenDanger;
|
import org.dromara.safety.domain.HazardHiddenDanger;
|
||||||
import org.dromara.safety.domain.HazardHiddenDangerRectify;
|
import org.dromara.safety.domain.HazardHiddenDangerRectify;
|
||||||
import org.dromara.safety.domain.HazardRule;
|
import org.dromara.safety.domain.HazardRule;
|
||||||
@ -24,7 +27,9 @@ import org.dromara.safety.domain.vo.HiddenDangerCountVo;
|
|||||||
import org.dromara.safety.mapper.HazardHiddenDangerMapper;
|
import org.dromara.safety.mapper.HazardHiddenDangerMapper;
|
||||||
import org.dromara.safety.mapper.HazardHiddenDangerRectifyMapper;
|
import org.dromara.safety.mapper.HazardHiddenDangerRectifyMapper;
|
||||||
import org.dromara.safety.service.IHazardHiddenDangerService;
|
import org.dromara.safety.service.IHazardHiddenDangerService;
|
||||||
|
import org.dromara.safety.service.IHazardRuleNotifyObjectService;
|
||||||
import org.dromara.safety.service.IHazardRuleService;
|
import org.dromara.safety.service.IHazardRuleService;
|
||||||
|
import org.dromara.websocket.ChatServerHandler;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -32,6 +37,8 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 隐患信息Service业务层处理
|
* 隐患信息Service业务层处理
|
||||||
@ -39,6 +46,7 @@ import java.util.Map;
|
|||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
* @date 2025-12-03
|
* @date 2025-12-03
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Service
|
@Service
|
||||||
public class HazardHiddenDangerServiceImpl extends ServiceImpl<HazardHiddenDangerMapper, HazardHiddenDanger>
|
public class HazardHiddenDangerServiceImpl extends ServiceImpl<HazardHiddenDangerMapper, HazardHiddenDanger>
|
||||||
@ -50,6 +58,10 @@ public class HazardHiddenDangerServiceImpl extends ServiceImpl<HazardHiddenDange
|
|||||||
|
|
||||||
private final HazardHiddenDangerRectifyMapper hazardHiddenDangerRectifyMapper;
|
private final HazardHiddenDangerRectifyMapper hazardHiddenDangerRectifyMapper;
|
||||||
|
|
||||||
|
private final IHazardRuleNotifyObjectService hazardRuleNotifyObjectService;
|
||||||
|
|
||||||
|
private final ChatServerHandler chatServerHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询隐患信息
|
* 查询隐患信息
|
||||||
*
|
*
|
||||||
@ -225,20 +237,55 @@ public class HazardHiddenDangerServiceImpl extends ServiceImpl<HazardHiddenDange
|
|||||||
} else if (responseUnit.equals("1")) {
|
} else if (responseUnit.equals("1")) {
|
||||||
hazardHiddenDanger.setRectifyTime(now.plusMinutes(byId.getResponseTime()));
|
hazardHiddenDanger.setRectifyTime(now.plusMinutes(byId.getResponseTime()));
|
||||||
}
|
}
|
||||||
|
LocalDateTime rectifyTime = hazardHiddenDanger.getRectifyTime();
|
||||||
|
if (rectifyTime.isBefore(LocalDateTime.now())) {
|
||||||
|
throw new ServiceException("整改期限不能小于当前时间");
|
||||||
|
}
|
||||||
// 修改数据
|
// 修改数据
|
||||||
if (baseMapper.updateById(hazardHiddenDanger) <= 0) {
|
if (baseMapper.updateById(hazardHiddenDanger) <= 0) {
|
||||||
throw new ServiceException("数据修改失败");
|
throw new ServiceException("数据修改失败");
|
||||||
}
|
}
|
||||||
// 添加整改任务
|
// 添加整改任务
|
||||||
|
Long rectifyUserId = hazardHiddenDanger.getRectifyUserId();
|
||||||
HazardHiddenDangerRectify rectify = new HazardHiddenDangerRectify();
|
HazardHiddenDangerRectify rectify = new HazardHiddenDangerRectify();
|
||||||
rectify.setHiddenDangerId(dto.getId());
|
rectify.setHiddenDangerId(dto.getId());
|
||||||
rectify.setRectifyDeadline(hazardHiddenDanger.getRectifyTime());
|
rectify.setRectifyDeadline(rectifyTime);
|
||||||
rectify.setRectifyUserId(hazardHiddenDanger.getRectifyUserId());
|
rectify.setRectifyUserId(rectifyUserId);
|
||||||
rectify.setReviewUserId(hazardHiddenDanger.getEvaluator());
|
rectify.setReviewUserId(hazardHiddenDanger.getEvaluator());
|
||||||
rectify.setRectifyCount(1);
|
rectify.setRectifyCount(1);
|
||||||
if (hazardHiddenDangerRectifyMapper.insert(rectify) <= 0) {
|
if (hazardHiddenDangerRectifyMapper.insert(rectify) <= 0) {
|
||||||
throw new ServiceException("数据保存失败");
|
throw new ServiceException("数据保存失败");
|
||||||
}
|
}
|
||||||
|
Long projectId = hazardHiddenDanger.getProjectId();
|
||||||
|
// 通知对应人员
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
// 发送给整改人员
|
||||||
|
String titleRectify = "您有新的安全隐患工单需要整改,请及时处理!";
|
||||||
|
try {
|
||||||
|
chatServerHandler.sendSystemMessageToUser(rectifyUserId, titleRectify, "2");
|
||||||
|
SseMessageUtils.sendMessage(rectifyUserId, titleRectify);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("异步发送系统消息失败,用户ID: {}, 消息: {}", rectifyUserId, titleRectify, e);
|
||||||
|
}
|
||||||
|
// 发送给需要通知的对象
|
||||||
|
Set<Long> userIds = hazardRuleNotifyObjectService.queryNotifyObjectIds(hazardHiddenDanger.getDangerLevelId(), projectId);
|
||||||
|
SseMessageDto sseDto = new SseMessageDto();
|
||||||
|
String title = "您有新的安全隐患工单,请及时查看!";
|
||||||
|
for (Long userId : userIds) {
|
||||||
|
try {
|
||||||
|
chatServerHandler.sendSystemMessageToUser(userId, title, "2");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("异步发送系统消息失败,用户ID: {}, 消息: {}", userId, title, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sseDto.setUserIds(userIds.stream().toList());
|
||||||
|
sseDto.setMessage(title);
|
||||||
|
sseDto.setRoute("");
|
||||||
|
sseDto.setProjectId(projectId);
|
||||||
|
sseDto.setIsRecord(true);
|
||||||
|
SseMessageUtils.publishMessage(sseDto);
|
||||||
|
// 发送整改期限数据到消息队列
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import org.dromara.safety.domain.vo.HazardRuleNotifyObjectVo;
|
|||||||
import org.dromara.safety.domain.vo.HazardRuleVo;
|
import org.dromara.safety.domain.vo.HazardRuleVo;
|
||||||
import org.dromara.safety.mapper.HazardRuleNotifyObjectMapper;
|
import org.dromara.safety.mapper.HazardRuleNotifyObjectMapper;
|
||||||
import org.dromara.safety.service.IHazardRuleNotifyObjectService;
|
import org.dromara.safety.service.IHazardRuleNotifyObjectService;
|
||||||
|
import org.dromara.system.domain.SysUser;
|
||||||
import org.dromara.system.domain.vo.SysDeptVo;
|
import org.dromara.system.domain.vo.SysDeptVo;
|
||||||
import org.dromara.system.domain.vo.SysPostVo;
|
import org.dromara.system.domain.vo.SysPostVo;
|
||||||
import org.dromara.system.domain.vo.SysRoleVo;
|
import org.dromara.system.domain.vo.SysRoleVo;
|
||||||
@ -18,9 +19,7 @@ import org.dromara.system.service.ISysRoleService;
|
|||||||
import org.dromara.system.service.ISysUserService;
|
import org.dromara.system.service.ISysUserService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,6 +134,52 @@ public class HazardRuleNotifyObjectServiceImpl extends ServiceImpl<HazardRuleNot
|
|||||||
return voList;
|
return voList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据规则查询所有通知对象id
|
||||||
|
*
|
||||||
|
* @param ruleId 规则id
|
||||||
|
* @param projectId 项目id
|
||||||
|
* @return 通知对象id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Set<Long> queryNotifyObjectIds(Long ruleId, Long projectId) {
|
||||||
|
List<HazardRuleNotifyObject> objectList = this.lambdaQuery()
|
||||||
|
.eq(HazardRuleNotifyObject::getRuleId, ruleId)
|
||||||
|
.list();
|
||||||
|
if (CollUtil.isEmpty(objectList)) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
Set<Long> userIds = new HashSet<>();
|
||||||
|
Map<String, List<HazardRuleNotifyObject>> map = objectList.stream()
|
||||||
|
.collect(Collectors.groupingBy(HazardRuleNotifyObject::getNotifyType));
|
||||||
|
for (Map.Entry<String, List<HazardRuleNotifyObject>> entry : map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
List<HazardRuleNotifyObject> value = entry.getValue();
|
||||||
|
List<Long> ids = value.stream()
|
||||||
|
.map(HazardRuleNotifyObject::getNotifyId)
|
||||||
|
.toList();
|
||||||
|
switch (key) {
|
||||||
|
case "1" -> userIds.addAll(ids);
|
||||||
|
case "2" -> {
|
||||||
|
List<SysUser> userVos = userService.selectUserByRoleIdsAndProjectId(ids, projectId);
|
||||||
|
Set<Long> userSet = userVos.stream().map(SysUser::getUserId).collect(Collectors.toSet());
|
||||||
|
userIds.addAll(userSet);
|
||||||
|
}
|
||||||
|
case "3" -> {
|
||||||
|
List<SysUserVo> userVos = userService.selectUserListByDeptList(ids);
|
||||||
|
Set<Long> userSet = userVos.stream().map(SysUserVo::getUserId).collect(Collectors.toSet());
|
||||||
|
userIds.addAll(userSet);
|
||||||
|
}
|
||||||
|
case "4" -> {
|
||||||
|
List<SysUserVo> userVos = userService.selectUserListByPostList(ids);
|
||||||
|
Set<Long> userSet = userVos.stream().map(SysUserVo::getUserId).collect(Collectors.toSet());
|
||||||
|
userIds.addAll(userSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return userIds;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 补充数据
|
* 补充数据
|
||||||
*
|
*
|
||||||
|
|||||||
@ -84,7 +84,7 @@ public class HazardRuleServiceImpl extends ServiceImpl<HazardRuleMapper, HazardR
|
|||||||
LambdaQueryWrapper<HazardRule> lqw = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<HazardRule> lqw = Wrappers.lambdaQuery();
|
||||||
lqw.orderByDesc(HazardRule::getId);
|
lqw.orderByDesc(HazardRule::getId);
|
||||||
lqw.eq(bo.getProjectId() != null, HazardRule::getProjectId, bo.getProjectId());
|
lqw.eq(bo.getProjectId() != null, HazardRule::getProjectId, bo.getProjectId());
|
||||||
lqw.eq(StringUtils.isNotBlank(bo.getHazardLevel()), HazardRule::getHazardLevel, bo.getHazardLevel());
|
lqw.like(StringUtils.isNotBlank(bo.getHazardLevel()), HazardRule::getHazardLevel, bo.getHazardLevel());
|
||||||
lqw.eq(bo.getHazardWeight() != null, HazardRule::getHazardWeight, bo.getHazardWeight());
|
lqw.eq(bo.getHazardWeight() != null, HazardRule::getHazardWeight, bo.getHazardWeight());
|
||||||
lqw.eq(bo.getResponseTime() != null, HazardRule::getResponseTime, bo.getResponseTime());
|
lqw.eq(bo.getResponseTime() != null, HazardRule::getResponseTime, bo.getResponseTime());
|
||||||
lqw.eq(StringUtils.isNotBlank(bo.getResponseUnit()), HazardRule::getResponseUnit, bo.getResponseUnit());
|
lqw.eq(StringUtils.isNotBlank(bo.getResponseUnit()), HazardRule::getResponseUnit, bo.getResponseUnit());
|
||||||
|
|||||||
@ -248,6 +248,14 @@ public interface ISysUserService {
|
|||||||
*/
|
*/
|
||||||
List<SysUserVo> selectUserListByDept(Long deptId);
|
List<SysUserVo> selectUserListByDept(Long deptId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过部门id列表查询当前部门所有用户
|
||||||
|
*
|
||||||
|
* @param deptIds 部门id列表
|
||||||
|
* @return 列表
|
||||||
|
*/
|
||||||
|
List<SysUserVo> selectUserListByDeptList(List<Long> deptIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过岗位id列表查询岗位所有用户
|
* 通过岗位id列表查询岗位所有用户
|
||||||
*
|
*
|
||||||
|
|||||||
@ -839,6 +839,23 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|||||||
return baseMapper.selectVoList(lqw);
|
return baseMapper.selectVoList(lqw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过部门id列表查询当前部门所有用户
|
||||||
|
*
|
||||||
|
* @param deptIds 部门id列表
|
||||||
|
* @return 列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<SysUserVo> selectUserListByDeptList(List<Long> deptIds) {
|
||||||
|
if (CollUtil.isEmpty(deptIds)) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<SysUser> lqw = Wrappers.lambdaQuery();
|
||||||
|
lqw.in(SysUser::getDeptId, deptIds);
|
||||||
|
lqw.orderByAsc(SysUser::getUserId);
|
||||||
|
return baseMapper.selectVoList(lqw);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过岗位id列表查询岗位所有用户
|
* 通过岗位id列表查询岗位所有用户
|
||||||
*
|
*
|
||||||
|
|||||||
@ -2107,15 +2107,15 @@ insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component,
|
|||||||
values (1996413868087308295, '隐患整改情况导出', 1996413868087308290, '5', '#', '', 1, 0, 'F', '0', '0',
|
values (1996413868087308295, '隐患整改情况导出', 1996413868087308290, '5', '#', '', 1, 0, 'F', '0', '0',
|
||||||
'safety:hiddenDangerRectify:export', '#', 103, 1, sysdate(), null, null, '');
|
'safety:hiddenDangerRectify:export', '#', 103, 1, sysdate(), null, null, '');
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS mq_delay_task;
|
||||||
CREATE TABLE `hazard_delay_task`
|
CREATE TABLE `mq_delay_task`
|
||||||
(
|
(
|
||||||
`id` BIGINT PRIMARY KEY COMMENT '主键',
|
`id` BIGINT PRIMARY KEY COMMENT '主键',
|
||||||
`biz_type` VARCHAR(50) NOT NULL COMMENT '业务类型',
|
`biz_type` VARCHAR(64) NOT NULL COMMENT '业务类型',
|
||||||
`biz_id` BIGINT NOT NULL COMMENT '业务ID',
|
`biz_id` BIGINT NOT NULL COMMENT '业务ID',
|
||||||
`execute_time` DATETIME NOT NULL COMMENT '执行的时间点',
|
`execute_time` DATETIME NOT NULL COMMENT '执行的时间点',
|
||||||
`status` TINYINT NOT NULL DEFAULT 0 COMMENT '任务状态 0未执行 1执行中 2执行成功 3执行失败',
|
`status` TINYINT NOT NULL DEFAULT 0 COMMENT '任务状态 0未执行 1执行中 2执行成功 3执行失败',
|
||||||
`retry_count` INT NOT NULL DEFAULT 0 COMMENT '重试次数',
|
`retry_count` INT NOT NULL DEFAULT 0 COMMENT '重试次数',
|
||||||
`max_retry` INT NOT NULL DEFAULT 3 COMMENT '最大重试次数',
|
`max_retry` INT NOT NULL DEFAULT 3 COMMENT '最大重试次数',
|
||||||
`fail_reason` VARCHAR(1024) NULL COMMENT '失败原因'
|
`fail_reason` VARCHAR(1024) NULL COMMENT '失败原因'
|
||||||
);
|
) comment '延迟任务表';
|
||||||
|
|||||||
Reference in New Issue
Block a user