From 556f3b6535e1ee6009dc98ae47a951faee093aee Mon Sep 17 00:00:00 2001 From: lcj <2331845269@qq.com> Date: Thu, 4 Dec 2025 10:18:26 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=90=E6=82=A3=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HazardRuleController.java | 33 ++-- .../safety/domain/HazardRuleNotifyObject.java | 3 + .../safety/domain/bo/HazardRuleBo.java | 13 +- .../domain/bo/HazardRuleNotifyObjectBo.java | 24 +-- .../domain/vo/HazardRuleNotifyObjectVo.java | 6 +- .../safety/domain/vo/HazardRuleVo.java | 5 + .../IHazardRuleNotifyObjectService.java | 54 ++----- .../HazardRuleNotifyObjectServiceImpl.java | 151 ++++++++---------- .../service/impl/HazardRuleServiceImpl.java | 59 ++++++- xinnengyuan/script/sql/xinnengyuan.sql | 70 ++++++-- 10 files changed, 236 insertions(+), 182 deletions(-) diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/controller/HazardRuleController.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/controller/HazardRuleController.java index 906b41a1..b109175d 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/controller/HazardRuleController.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/controller/HazardRuleController.java @@ -1,26 +1,27 @@ package org.dromara.safety.controller; -import java.util.List; - -import lombok.RequiredArgsConstructor; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; -import org.springframework.web.bind.annotation.*; -import org.springframework.validation.annotation.Validated; -import org.dromara.common.idempotent.annotation.RepeatSubmit; -import org.dromara.common.log.annotation.Log; -import org.dromara.common.web.core.BaseController; -import org.dromara.common.mybatis.core.page.PageQuery; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.RequiredArgsConstructor; import org.dromara.common.core.domain.R; import org.dromara.common.core.validate.AddGroup; import org.dromara.common.core.validate.EditGroup; -import org.dromara.common.log.enums.BusinessType; import org.dromara.common.excel.utils.ExcelUtil; -import org.dromara.safety.domain.vo.HazardRuleVo; -import org.dromara.safety.domain.bo.HazardRuleBo; -import org.dromara.safety.service.IHazardRuleService; +import org.dromara.common.idempotent.annotation.RepeatSubmit; +import org.dromara.common.log.annotation.Log; +import org.dromara.common.log.enums.BusinessType; +import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.common.web.core.BaseController; +import org.dromara.safety.domain.bo.HazardRuleBo; +import org.dromara.safety.domain.vo.HazardRuleVo; +import org.dromara.safety.service.IHazardRuleService; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; /** * 隐患分级通知规则 @@ -64,7 +65,7 @@ public class HazardRuleController extends BaseController { @SaCheckPermission("safety:rule:query") @GetMapping("/{id}") public R getInfo(@NotNull(message = "主键不能为空") - @PathVariable Long id) { + @PathVariable Long id) { return R.ok(hazardRuleService.queryById(id)); } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/HazardRuleNotifyObject.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/HazardRuleNotifyObject.java index 7b8120a8..ac379709 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/HazardRuleNotifyObject.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/HazardRuleNotifyObject.java @@ -1,5 +1,7 @@ package org.dromara.safety.domain; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -22,6 +24,7 @@ public class HazardRuleNotifyObject implements Serializable { /** * 规则ID */ + @TableId(type = IdType.INPUT) private Long ruleId; /** diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/bo/HazardRuleBo.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/bo/HazardRuleBo.java index fd13e90c..1ac99ebe 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/bo/HazardRuleBo.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/bo/HazardRuleBo.java @@ -10,6 +10,9 @@ import org.dromara.common.core.validate.EditGroup; import org.dromara.common.mybatis.core.domain.BaseEntity; import org.dromara.safety.domain.HazardRule; +import java.io.Serial; +import java.util.List; + /** * 隐患分级通知规则业务对象 hazard_rule * @@ -21,6 +24,9 @@ import org.dromara.safety.domain.HazardRule; @AutoMapper(target = HazardRule.class, reverseConvertGenerate = false) public class HazardRuleBo extends BaseEntity { + @Serial + private static final long serialVersionUID = 1523915364119852788L; + /** * 主键 */ @@ -72,7 +78,6 @@ public class HazardRuleBo extends BaseEntity { /** * 额外设置 */ - @NotBlank(message = "额外设置不能为空", groups = {AddGroup.class, EditGroup.class}) private String extraSetting; /** @@ -80,4 +85,10 @@ public class HazardRuleBo extends BaseEntity { */ private String remark; + /** + * 通知对象 + */ + @NotNull(message = "通知对象不能为空", groups = {AddGroup.class, EditGroup.class}) + private List notifyObjects; + } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/bo/HazardRuleNotifyObjectBo.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/bo/HazardRuleNotifyObjectBo.java index 1815b4c9..6b607f13 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/bo/HazardRuleNotifyObjectBo.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/bo/HazardRuleNotifyObjectBo.java @@ -1,13 +1,8 @@ package org.dromara.safety.domain.bo; -import org.dromara.safety.domain.HazardRuleNotifyObject; -import org.dromara.common.mybatis.core.domain.BaseEntity; -import org.dromara.common.core.validate.AddGroup; -import org.dromara.common.core.validate.EditGroup; -import io.github.linpeilie.annotations.AutoMapper; +import lombok.AllArgsConstructor; import lombok.Data; -import lombok.EqualsAndHashCode; -import jakarta.validation.constraints.*; +import lombok.NoArgsConstructor; /** * 隐患规则通知对象业务对象 hazard_rule_notify_object @@ -16,27 +11,18 @@ import jakarta.validation.constraints.*; * @date 2025-12-03 */ @Data -@EqualsAndHashCode(callSuper = true) -@AutoMapper(target = HazardRuleNotifyObject.class, reverseConvertGenerate = false) -public class HazardRuleNotifyObjectBo extends BaseEntity { - - /** - * 规则ID - */ - @NotNull(message = "规则ID不能为空", groups = { AddGroup.class, EditGroup.class }) - private Long ruleId; +@NoArgsConstructor +@AllArgsConstructor +public class HazardRuleNotifyObjectBo { /** * 通知ID */ - @NotNull(message = "通知ID不能为空", groups = { AddGroup.class, EditGroup.class }) private Long notifyId; /** * 通知类型 */ - @NotBlank(message = "通知类型不能为空", groups = { AddGroup.class, EditGroup.class }) private String notifyType; - } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/vo/HazardRuleNotifyObjectVo.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/vo/HazardRuleNotifyObjectVo.java index 285767d5..d6694a3e 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/vo/HazardRuleNotifyObjectVo.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/vo/HazardRuleNotifyObjectVo.java @@ -36,11 +36,15 @@ public class HazardRuleNotifyObjectVo implements Serializable { @ExcelProperty(value = "通知ID") private Long notifyId; + /** + * 通知名称 + */ + private String notifyName; + /** * 通知类型 */ @ExcelProperty(value = "通知类型") private String notifyType; - } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/vo/HazardRuleVo.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/vo/HazardRuleVo.java index 54c23bc0..72997c46 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/vo/HazardRuleVo.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/domain/vo/HazardRuleVo.java @@ -10,6 +10,7 @@ import org.dromara.safety.domain.HazardRule; import java.io.Serial; import java.io.Serializable; +import java.util.List; /** @@ -89,5 +90,9 @@ public class HazardRuleVo implements Serializable { @ExcelProperty(value = "备注") private String remark; + /** + * 通知对象 + */ + List notifyObjects; } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/IHazardRuleNotifyObjectService.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/IHazardRuleNotifyObjectService.java index e54a0b74..6f5b2f51 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/IHazardRuleNotifyObjectService.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/IHazardRuleNotifyObjectService.java @@ -1,13 +1,10 @@ package org.dromara.safety.service; import com.baomidou.mybatisplus.extension.service.IService; -import org.dromara.common.mybatis.core.page.PageQuery; -import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.safety.domain.HazardRuleNotifyObject; -import org.dromara.safety.domain.bo.HazardRuleNotifyObjectBo; import org.dromara.safety.domain.vo.HazardRuleNotifyObjectVo; +import org.dromara.safety.domain.vo.HazardRuleVo; -import java.util.Collection; import java.util.List; /** @@ -19,52 +16,25 @@ import java.util.List; public interface IHazardRuleNotifyObjectService extends IService { /** - * 查询隐患规则通知对象 + * 根据规则查询通知对象 * - * @param ruleId 主键 - * @return 隐患规则通知对象 + * @param ruleId 规则id + * @return 通知对象 */ - HazardRuleNotifyObjectVo queryById(Long ruleId); + List queryVoByRule(Long ruleId); /** - * 分页查询隐患规则通知对象列表 + * 根据对象列表查询对象列表 * - * @param bo 查询条件 - * @param pageQuery 分页参数 - * @return 隐患规则通知对象分页列表 + * @param objectList 对象列表 + * @return 对象列表 */ - TableDataInfo queryPageList(HazardRuleNotifyObjectBo bo, PageQuery pageQuery); + List queryVo(List objectList); /** - * 查询符合条件的隐患规则通知对象列表 + * 补充数据 * - * @param bo 查询条件 - * @return 隐患规则通知对象列表 + * @param voList 规则列表 */ - List queryList(HazardRuleNotifyObjectBo bo); - - /** - * 新增隐患规则通知对象 - * - * @param bo 隐患规则通知对象 - * @return 是否新增成功 - */ - Boolean insertByBo(HazardRuleNotifyObjectBo bo); - - /** - * 修改隐患规则通知对象 - * - * @param bo 隐患规则通知对象 - * @return 是否修改成功 - */ - Boolean updateByBo(HazardRuleNotifyObjectBo bo); - - /** - * 校验并批量删除隐患规则通知对象信息 - * - * @param ids 待删除的主键集合 - * @param isValid 是否进行有效性校验 - * @return 是否删除成功 - */ - Boolean deleteWithValidByIds(Collection ids, Boolean isValid); + void supplementDataByRule(List voList); } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/impl/HazardRuleNotifyObjectServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/impl/HazardRuleNotifyObjectServiceImpl.java index 3ce043b7..a5c0c869 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/impl/HazardRuleNotifyObjectServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/impl/HazardRuleNotifyObjectServiceImpl.java @@ -1,24 +1,21 @@ package org.dromara.safety.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.RequiredArgsConstructor; -import org.dromara.common.core.utils.MapstructUtils; -import org.dromara.common.core.utils.StringUtils; -import org.dromara.common.mybatis.core.page.PageQuery; -import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.safety.domain.HazardRuleNotifyObject; -import org.dromara.safety.domain.bo.HazardRuleNotifyObjectBo; import org.dromara.safety.domain.vo.HazardRuleNotifyObjectVo; +import org.dromara.safety.domain.vo.HazardRuleVo; import org.dromara.safety.mapper.HazardRuleNotifyObjectMapper; import org.dromara.safety.service.IHazardRuleNotifyObjectService; +import org.dromara.system.domain.vo.SysUserVo; +import org.dromara.system.service.ISysUserService; import org.springframework.stereotype.Service; -import java.util.Collection; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * 隐患规则通知对象Service业务层处理 @@ -31,101 +28,81 @@ import java.util.Map; public class HazardRuleNotifyObjectServiceImpl extends ServiceImpl implements IHazardRuleNotifyObjectService { + private final ISysUserService userService; + /** - * 查询隐患规则通知对象 + * 根据规则查询通知对象 * - * @param ruleId 主键 - * @return 隐患规则通知对象 + * @param ruleId 规则id + * @return 通知对象 */ @Override - public HazardRuleNotifyObjectVo queryById(Long ruleId) { - return baseMapper.selectVoById(ruleId); + public List queryVoByRule(Long ruleId) { + List objectList = this.lambdaQuery() + .eq(HazardRuleNotifyObject::getRuleId, ruleId) + .list(); + return this.queryVo(objectList); } /** - * 分页查询隐患规则通知对象列表 + * 根据对象列表查询对象列表 * - * @param bo 查询条件 - * @param pageQuery 分页参数 - * @return 隐患规则通知对象分页列表 + * @param objectList 对象列表 + * @return 对象列表 */ @Override - public TableDataInfo queryPageList(HazardRuleNotifyObjectBo bo, PageQuery pageQuery) { - LambdaQueryWrapper lqw = buildQueryWrapper(bo); - Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); - return TableDataInfo.build(result); - } - - /** - * 查询符合条件的隐患规则通知对象列表 - * - * @param bo 查询条件 - * @return 隐患规则通知对象列表 - */ - @Override - public List queryList(HazardRuleNotifyObjectBo bo) { - LambdaQueryWrapper lqw = buildQueryWrapper(bo); - return baseMapper.selectVoList(lqw); - } - - private LambdaQueryWrapper buildQueryWrapper(HazardRuleNotifyObjectBo bo) { - Map params = bo.getParams(); - LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); - lqw.eq(bo.getRuleId() != null, HazardRuleNotifyObject::getRuleId, bo.getRuleId()); - lqw.eq(bo.getNotifyId() != null, HazardRuleNotifyObject::getNotifyId, bo.getNotifyId()); - lqw.eq(StringUtils.isNotBlank(bo.getNotifyType()), HazardRuleNotifyObject::getNotifyType, bo.getNotifyType()); - return lqw; - } - - /** - * 新增隐患规则通知对象 - * - * @param bo 隐患规则通知对象 - * @return 是否新增成功 - */ - @Override - public Boolean insertByBo(HazardRuleNotifyObjectBo bo) { - HazardRuleNotifyObject add = MapstructUtils.convert(bo, HazardRuleNotifyObject.class); - validEntityBeforeSave(add); - boolean flag = baseMapper.insert(add) > 0; - if (flag) { - bo.setRuleId(add.getRuleId()); + public List queryVo(List objectList) { + List voList = new ArrayList<>(); + Map> map = objectList.stream() + .collect(Collectors.groupingBy(HazardRuleNotifyObject::getNotifyType)); + for (Map.Entry> entry : map.entrySet()) { + String key = entry.getKey(); + List value = entry.getValue(); + switch (key) { + case "1": { + List userIds = value.stream() + .map(HazardRuleNotifyObject::getNotifyId) + .toList(); + List userVos = userService.selectUserByIds(userIds, null); + Map userNameMap = userVos.stream() + .collect(Collectors.toMap(SysUserVo::getUserId, SysUserVo::getNickName, (k, v) -> k)); + List vos = value.stream().map(v -> { + HazardRuleNotifyObjectVo vo = new HazardRuleNotifyObjectVo(); + vo.setRuleId(v.getRuleId()); + vo.setNotifyId(v.getNotifyId()); + vo.setNotifyName(userNameMap.getOrDefault(v.getNotifyId(), "")); + vo.setNotifyType(key); + return vo; + }).toList(); + voList.addAll(vos); + } + case null, default: + break; + } } - return flag; + return voList; } /** - * 修改隐患规则通知对象 + * 补充数据 * - * @param bo 隐患规则通知对象 - * @return 是否修改成功 + * @param voList 规则列表 */ @Override - public Boolean updateByBo(HazardRuleNotifyObjectBo bo) { - HazardRuleNotifyObject update = MapstructUtils.convert(bo, HazardRuleNotifyObject.class); - validEntityBeforeSave(update); - return baseMapper.updateById(update) > 0; - } - - /** - * 保存前的数据校验 - */ - private void validEntityBeforeSave(HazardRuleNotifyObject entity) { - //TODO 做一些数据校验,如唯一约束 - } - - /** - * 校验并批量删除隐患规则通知对象信息 - * - * @param ids 待删除的主键集合 - * @param isValid 是否进行有效性校验 - * @return 是否删除成功 - */ - @Override - public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { - if (isValid) { - //TODO 做一些业务上的校验,判断是否需要校验 + public void supplementDataByRule(List voList) { + if (CollUtil.isEmpty(voList)) { + return; + } + List ruleIds = voList.stream().map(HazardRuleVo::getId).toList(); + List objectList = this.lambdaQuery() + .in(HazardRuleNotifyObject::getRuleId, ruleIds) + .list(); + List objectVos = this.queryVo(objectList); + Map> map = objectVos.stream() + .collect(Collectors.groupingBy(HazardRuleNotifyObjectVo::getRuleId)); + for (HazardRuleVo vo : voList) { + List vos = map.get(vo.getId()); + vo.setNotifyObjects(vos); } - return baseMapper.deleteByIds(ids) > 0; } } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/impl/HazardRuleServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/impl/HazardRuleServiceImpl.java index 768babfc..0c5f8cb5 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/impl/HazardRuleServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/safety/service/impl/HazardRuleServiceImpl.java @@ -5,20 +5,26 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.RequiredArgsConstructor; +import org.dromara.common.core.constant.HttpStatus; +import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.safety.domain.HazardRule; +import org.dromara.safety.domain.HazardRuleNotifyObject; import org.dromara.safety.domain.bo.HazardRuleBo; +import org.dromara.safety.domain.bo.HazardRuleNotifyObjectBo; +import org.dromara.safety.domain.vo.HazardRuleNotifyObjectVo; import org.dromara.safety.domain.vo.HazardRuleVo; import org.dromara.safety.mapper.HazardRuleMapper; +import org.dromara.safety.service.IHazardRuleNotifyObjectService; import org.dromara.safety.service.IHazardRuleService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.Collection; import java.util.List; -import java.util.Map; /** * 隐患分级通知规则Service业务层处理 @@ -31,6 +37,8 @@ import java.util.Map; public class HazardRuleServiceImpl extends ServiceImpl implements IHazardRuleService { + private final IHazardRuleNotifyObjectService hazardRuleNotifyObjectService; + /** * 查询隐患分级通知规则 * @@ -39,7 +47,10 @@ public class HazardRuleServiceImpl extends ServiceImpl objectVos = hazardRuleNotifyObjectService.queryVoByRule(id); + hazardRuleVo.setNotifyObjects(objectVos); + return hazardRuleVo; } /** @@ -53,6 +64,7 @@ public class HazardRuleServiceImpl extends ServiceImpl queryPageList(HazardRuleBo bo, PageQuery pageQuery) { LambdaQueryWrapper lqw = buildQueryWrapper(bo); Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); + hazardRuleNotifyObjectService.supplementDataByRule(result.getRecords()); return TableDataInfo.build(result); } @@ -69,7 +81,6 @@ public class HazardRuleServiceImpl extends ServiceImpl buildQueryWrapper(HazardRuleBo bo) { - Map params = bo.getParams(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); lqw.orderByDesc(HazardRule::getId); lqw.eq(bo.getProjectId() != null, HazardRule::getProjectId, bo.getProjectId()); @@ -90,12 +101,25 @@ public class HazardRuleServiceImpl extends ServiceImpl 0; if (flag) { bo.setId(add.getId()); + List notifyObjects = bo.getNotifyObjects(); + List objectList = notifyObjects.stream().map(item -> { + HazardRuleNotifyObject notifyObject = new HazardRuleNotifyObject(); + notifyObject.setRuleId(add.getId()); + notifyObject.setNotifyId(item.getNotifyId()); + notifyObject.setNotifyType(item.getNotifyType()); + return notifyObject; + }).toList(); + boolean b = hazardRuleNotifyObjectService.saveBatch(objectList); + if (!b) { + throw new ServiceException("数据库操作失败", HttpStatus.ERROR); + } } return flag; } @@ -107,10 +131,37 @@ public class HazardRuleServiceImpl extends ServiceImpl 0; + boolean b = baseMapper.updateById(update) > 0; + if (b) { + // 旧通知对象 + boolean remove = hazardRuleNotifyObjectService.remove(new LambdaQueryWrapper() + .eq(HazardRuleNotifyObject::getRuleId, bo.getId())); + if (!remove) { + throw new ServiceException("数据库操作失败", HttpStatus.ERROR); + } + // 新通知对象 + List notifyObjects = bo.getNotifyObjects(); + List objectList = notifyObjects.stream().map(item -> { + HazardRuleNotifyObject notifyObject = new HazardRuleNotifyObject(); + notifyObject.setRuleId(bo.getId()); + notifyObject.setNotifyId(item.getNotifyId()); + notifyObject.setNotifyType(item.getNotifyType()); + return notifyObject; + }).toList(); + boolean b1 = hazardRuleNotifyObjectService.saveBatch(objectList); + if (!b1) { + throw new ServiceException("数据库操作失败", HttpStatus.ERROR); + } + } + return b; } /** diff --git a/xinnengyuan/script/sql/xinnengyuan.sql b/xinnengyuan/script/sql/xinnengyuan.sql index 54a6fe2a..55ae5e37 100644 --- a/xinnengyuan/script/sql/xinnengyuan.sql +++ b/xinnengyuan/script/sql/xinnengyuan.sql @@ -2006,21 +2006,67 @@ CREATE TABLE hazard_rule_notify_object ) comment '隐患规则通知对象'; -- 菜单 SQL -insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) -values(1996139632219136001, '隐患分级通知规则', '1996118434672001025', '1', 'rule', 'safety/rule/index', 1, 0, 'C', '0', '0', 'safety:rule:list', '#', 103, 1, sysdate(), null, null, '隐患分级通知规则菜单'); +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, + status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values (1996139632219136001, '隐患分级通知规则', '1996118434672001025', '1', 'rule', 'safety/rule/index', 1, 0, 'C', + '0', '0', 'safety:rule:list', '#', 103, 1, sysdate(), null, null, '隐患分级通知规则菜单'); -- 按钮 SQL -insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) -values(1996139632219136002, '隐患分级通知规则查询', 1996139632219136001, '1', '#', '', 1, 0, 'F', '0', '0', 'safety:rule:query', '#', 103, 1, sysdate(), null, null, ''); +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, + status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values (1996139632219136002, '隐患分级通知规则查询', 1996139632219136001, '1', '#', '', 1, 0, 'F', '0', '0', + 'safety:rule:query', '#', 103, 1, sysdate(), null, null, ''); -insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) -values(1996139632219136003, '隐患分级通知规则新增', 1996139632219136001, '2', '#', '', 1, 0, 'F', '0', '0', 'safety:rule:add', '#', 103, 1, sysdate(), null, null, ''); +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, + status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values (1996139632219136003, '隐患分级通知规则新增', 1996139632219136001, '2', '#', '', 1, 0, 'F', '0', '0', + 'safety:rule:add', '#', 103, 1, sysdate(), null, null, ''); -insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) -values(1996139632219136004, '隐患分级通知规则修改', 1996139632219136001, '3', '#', '', 1, 0, 'F', '0', '0', 'safety:rule:edit', '#', 103, 1, sysdate(), null, null, ''); +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, + status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values (1996139632219136004, '隐患分级通知规则修改', 1996139632219136001, '3', '#', '', 1, 0, 'F', '0', '0', + 'safety:rule:edit', '#', 103, 1, sysdate(), null, null, ''); -insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) -values(1996139632219136005, '隐患分级通知规则删除', 1996139632219136001, '4', '#', '', 1, 0, 'F', '0', '0', 'safety:rule:remove', '#', 103, 1, sysdate(), null, null, ''); +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, + status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values (1996139632219136005, '隐患分级通知规则删除', 1996139632219136001, '4', '#', '', 1, 0, 'F', '0', '0', + 'safety:rule:remove', '#', 103, 1, sysdate(), null, null, ''); -insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) -values(1996139632219136006, '隐患分级通知规则导出', 1996139632219136001, '5', '#', '', 1, 0, 'F', '0', '0', 'safety:rule:export', '#', 103, 1, sysdate(), null, null, ''); +insert into sys_menu (menu_id, menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, + status, perms, icon, create_dept, create_by, create_time, update_by, update_time, remark) +values (1996139632219136006, '隐患分级通知规则导出', 1996139632219136001, '5', '#', '', 1, 0, 'F', '0', '0', + 'safety:rule:export', '#', 103, 1, sysdate(), null, null, ''); + + +-- 隐患整改情况表 +create table hazard_hidden_danger_rectify +( + `id` bigint not null auto_increment comment '主键', + hidden_danger_id bigint not null comment '关联隐患ID', + rectify_times int not null comment '整改次数', + + rectify_desc text null comment '整改说明', + rectify_files varchar(1000) null comment '整改凭证附件', + rectify_finish_time datetime null comment '完成整改时间', + + review_user_id bigint null comment '复查人ID', + review_opinion text null comment '复查意见', + review_files varchar(1000) null comment '复查凭证附件', + review_time datetime null comment '复查时间', + + review_status char not null default '0' comment '复查状态 0-待复查 1-复查通过 2-复查不通过', + `remark` varchar(512) null comment '备注', + `create_by` bigint null comment '创建者', + `update_by` bigint null comment '更新者', + `create_dept` bigint null comment '创建部门', + `create_time` datetime default CURRENT_TIMESTAMP null comment '创建时间', + `update_time` datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间', + PRIMARY KEY (`id`) USING BTREE, + index `idx_hidden_danger_id` (`hidden_danger_id` asc) using btree comment '关联隐患ID', +) + comment '隐患整改情况表' row_format = DYNAMIC; + +-- 索引 + +create index idx_rectify_times + on hazard_hidden_danger_rectify (hidden_danger_id, rectify_times);