From 6930e451c90bfe795726bd28e3c8a58a2dc2731c Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Sun, 21 Nov 2021 23:01:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=A8=A1=E5=9D=97=E4=B8=8D?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E7=9B=B8=E5=90=8C=E9=85=8D=E7=BD=AE=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E5=AD=98=E5=9C=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/service/biz/impl/NotifyServiceImpl.java | 14 ++++++++++++-- .../src/main/resources/hippo_manager.sql | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/NotifyServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/NotifyServiceImpl.java index d83b5ce8..d1267079 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/NotifyServiceImpl.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/NotifyServiceImpl.java @@ -1,6 +1,7 @@ package cn.hippo4j.config.service.biz.impl; import cn.hippo4j.common.toolkit.GroupKey; +import cn.hippo4j.common.web.exception.ServiceException; import cn.hippo4j.config.enums.DelEnum; import cn.hippo4j.config.mapper.NotifyInfoMapper; import cn.hippo4j.config.model.NotifyInfo; @@ -18,6 +19,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import lombok.AllArgsConstructor; +import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Service; import java.util.List; @@ -66,7 +68,11 @@ public class NotifyServiceImpl implements NotifyService { @Override public void save(NotifyReqDTO reqDTO) { - notifyInfoMapper.insert(BeanUtil.convert(reqDTO, NotifyInfo.class)); + try { + notifyInfoMapper.insert(BeanUtil.convert(reqDTO, NotifyInfo.class)); + } catch (DuplicateKeyException ex) { + throw new ServiceException("新增通知报警配置重复."); + } } @Override @@ -77,7 +83,11 @@ public class NotifyServiceImpl implements NotifyService { .eq(NotifyInfo::getItemId, reqDTO.getItemId()) .eq(NotifyInfo::getTpId, reqDTO.getTpId()); - notifyInfoMapper.update(notifyInfo, updateWrapper); + try { + notifyInfoMapper.update(notifyInfo, updateWrapper); + } catch (DuplicateKeyException ex) { + throw new ServiceException("修改通知报警配置重复."); + } } @Override diff --git a/hippo4j-server/src/main/resources/hippo_manager.sql b/hippo4j-server/src/main/resources/hippo_manager.sql index c71fef7e..93e1b9ff 100644 --- a/hippo4j-server/src/main/resources/hippo_manager.sql +++ b/hippo4j-server/src/main/resources/hippo_manager.sql @@ -157,7 +157,7 @@ CREATE TABLE `notify` ( `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', `del_flag` tinyint(1) NOT NULL COMMENT '是否删除', PRIMARY KEY (`id`), - KEY `uk_notify_biz_key` (`tenant_id`,`item_id`,`tp_id`,`platform`,`type`,`del_flag`) USING BTREE + UNIQUE KEY `uk_notify_biz_key` (`tenant_id`,`item_id`,`tp_id`,`platform`,`type`,`del_flag`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='通知表'; /* 租户 */