fix: 逻辑删除唯一索引冲突的问题

This commit is contained in:
gaibu 2022-12-10 11:32:46 +08:00
parent 7f0c011123
commit 67435648b2
6 changed files with 194 additions and 97 deletions

View File

@ -1335,19 +1335,20 @@ COMMIT;
-- Table structure for system_dict_type
-- ----------------------------
DROP TABLE IF EXISTS `system_dict_type`;
CREATE TABLE `system_dict_type` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '字典主键',
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '字典名称',
`type` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '字典类型',
`status` tinyint NOT NULL DEFAULT 0 COMMENT '状态0正常 1停用',
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `dict_type`(`type` ASC) USING BTREE
CREATE TABLE `system_dict_type`(
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '字典主键',
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '字典名称',
`type` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '字典类型',
`status` tinyint NOT NULL DEFAULT 0 COMMENT '状态0正常 1停用',
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted_time` datetime DEFAULT NULL COMMENT '删除时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `dict_type`(`type` ASC,`deleted_time` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 149 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '字典类型表';
-- ----------------------------

View File

@ -2474,17 +2474,18 @@ COMMIT;
-- Table structure for SYSTEM_DICT_TYPE
-- ----------------------------
DROP TABLE "SYSTEM_DICT_TYPE";
CREATE TABLE "SYSTEM_DICT_TYPE" (
"ID" NUMBER(20,0) NOT NULL,
"NAME" NVARCHAR2(100),
"TYPE" NVARCHAR2(100),
"STATUS" NUMBER(4,0) NOT NULL,
"REMARK" NVARCHAR2(500),
"CREATOR" NVARCHAR2(64),
"CREATE_TIME" DATE NOT NULL,
"UPDATER" NVARCHAR2(64),
"UPDATE_TIME" DATE NOT NULL,
"DELETED" NUMBER(1,0) DEFAULT 0 NOT NULL
CREATE TABLE "SYSTEM_DICT_TYPE"(
"ID" NUMBER(20,0) NOT NULL,
"NAME" NVARCHAR2(100),
"TYPE" NVARCHAR2(100),
"STATUS" NUMBER(4,0) NOT NULL,
"REMARK" NVARCHAR2(500),
"CREATOR" NVARCHAR2(64),
"CREATE_TIME" DATE NOT NULL,
"UPDATER" NVARCHAR2(64),
"UPDATE_TIME" DATE NOT NULL,
"DELETED_TIME" DATE,
"DELETED" NUMBER(1,0) DEFAULT 0 NOT NULL
)
LOGGING
NOCOMPRESS
@ -2503,25 +2504,54 @@ PARALLEL 1
NOCACHE
DISABLE ROW MOVEMENT
;
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."ID" IS '字典主键';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."NAME" IS '字典名称';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."TYPE" IS '字典类型';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."STATUS" IS '状态0正常 1停用';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."REMARK" IS '备注';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."CREATOR" IS '创建者';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."CREATE_TIME" IS '创建时间';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."UPDATER" IS '更新者';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."UPDATE_TIME" IS '更新时间';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."DELETED" IS '是否删除';
COMMENT ON TABLE "SYSTEM_DICT_TYPE" IS '字典类型表';
COMMENT
ON COLUMN "SYSTEM_DICT_TYPE"."ID" IS '字典主键';
COMMENT
ON COLUMN "SYSTEM_DICT_TYPE"."NAME" IS '字典名称';
COMMENT
ON COLUMN "SYSTEM_DICT_TYPE"."TYPE" IS '字典类型';
COMMENT
ON COLUMN "SYSTEM_DICT_TYPE"."STATUS" IS '状态0正常 1停用';
COMMENT
ON COLUMN "SYSTEM_DICT_TYPE"."REMARK" IS '备注';
COMMENT
ON COLUMN "SYSTEM_DICT_TYPE"."CREATOR" IS '创建者';
COMMENT
ON COLUMN "SYSTEM_DICT_TYPE"."CREATE_TIME" IS '创建时间';
COMMENT
ON COLUMN "SYSTEM_DICT_TYPE"."UPDATER" IS '更新者';
COMMENT
ON COLUMN "SYSTEM_DICT_TYPE"."UPDATE_TIME" IS '更新时间';
COMMENT
ON COLUMN "SYSTEM_DICT_TYPE"."DELETED_TIME" IS '删除时间';
COMMENT
ON COLUMN "SYSTEM_DICT_TYPE"."DELETED" IS '是否删除';
COMMENT
ON TABLE "SYSTEM_DICT_TYPE" IS '字典类型表';
-- ----------------------------
-- Records of SYSTEM_DICT_TYPE
-- ----------------------------
INSERT INTO "SYSTEM_DICT_TYPE" ("ID", "NAME", "TYPE", "STATUS", "REMARK", "CREATOR", "CREATE_TIME", "UPDATER", "UPDATE_TIME", "DELETED") VALUES ('1', '用户性别', 'system_user_sex', '0', NULL, 'admin', TO_DATE('2021-01-05 17:03:48', 'SYYYY-MM-DD HH24:MI:SS'), '1', TO_DATE('2022-05-01 12:55:56', 'SYYYY-MM-DD HH24:MI:SS'), '0');
INSERT INTO "SYSTEM_DICT_TYPE" ("ID", "NAME", "TYPE", "STATUS", "REMARK", "CREATOR", "CREATE_TIME", "UPDATER", "UPDATE_TIME", "DELETED") VALUES ('6', '参数类型', 'infra_config_type', '0', NULL, 'admin', TO_DATE('2021-01-05 17:03:48', 'SYYYY-MM-DD HH24:MI:SS'), NULL, TO_DATE('2022-02-01 16:36:54', 'SYYYY-MM-DD HH24:MI:SS'), '0');
INSERT INTO "SYSTEM_DICT_TYPE" ("ID", "NAME", "TYPE", "STATUS", "REMARK", "CREATOR", "CREATE_TIME", "UPDATER", "UPDATE_TIME", "DELETED") VALUES ('7', '通知类型', 'system_notice_type', '0', NULL, 'admin', TO_DATE('2021-01-05 17:03:48', 'SYYYY-MM-DD HH24:MI:SS'), NULL, TO_DATE('2022-02-01 16:35:26', 'SYYYY-MM-DD HH24:MI:SS'), '0');
INSERT INTO "SYSTEM_DICT_TYPE" ("ID", "NAME", "TYPE", "STATUS", "REMARK", "CREATOR", "CREATE_TIME", "UPDATER", "UPDATE_TIME", "DELETED") VALUES ('9', '操作类型', 'system_operate_type', '0', NULL, 'admin', TO_DATE('2021-01-05 17:03:48', 'SYYYY-MM-DD HH24:MI:SS'), '1', TO_DATE('2022-02-16 09:32:21', 'SYYYY-MM-DD HH24:MI:SS'), '0');
INSERT INTO "SYSTEM_DICT_TYPE" ("ID", "NAME", "TYPE", "STATUS", "REMARK", "CREATOR", "CREATE_TIME", "UPDATER",
"UPDATE_TIME", "DELETED")
VALUES ('1', '用户性别', 'system_user_sex', '0', NULL, 'admin',
TO_DATE('2021-01-05 17:03:48', 'SYYYY-MM-DD HH24:MI:SS'), '1',
TO_DATE('2022-05-01 12:55:56', 'SYYYY-MM-DD HH24:MI:SS'), '0');
INSERT INTO "SYSTEM_DICT_TYPE" ("ID", "NAME", "TYPE", "STATUS", "REMARK", "CREATOR", "CREATE_TIME", "UPDATER",
"UPDATE_TIME", "DELETED")
VALUES ('6', '参数类型', 'infra_config_type', '0', NULL, 'admin',
TO_DATE('2021-01-05 17:03:48', 'SYYYY-MM-DD HH24:MI:SS'), NULL,
TO_DATE('2022-02-01 16:36:54', 'SYYYY-MM-DD HH24:MI:SS'), '0');
INSERT INTO "SYSTEM_DICT_TYPE" ("ID", "NAME", "TYPE", "STATUS", "REMARK", "CREATOR", "CREATE_TIME", "UPDATER",
"UPDATE_TIME", "DELETED")
VALUES ('7', '通知类型', 'system_notice_type', '0', NULL, 'admin',
TO_DATE('2021-01-05 17:03:48', 'SYYYY-MM-DD HH24:MI:SS'), NULL,
TO_DATE('2022-02-01 16:35:26', 'SYYYY-MM-DD HH24:MI:SS'), '0');
INSERT INTO "SYSTEM_DICT_TYPE" ("ID", "NAME", "TYPE", "STATUS", "REMARK", "CREATOR", "CREATE_TIME", "UPDATER",
"UPDATE_TIME", "DELETED")
VALUES ('9', '操作类型', 'system_operate_type', '0', NULL, 'admin',
TO_DATE('2021-01-05 17:03:48', 'SYYYY-MM-DD HH24:MI:SS'), '1',
TO_DATE('2022-02-16 09:32:21', 'SYYYY-MM-DD HH24:MI:SS'), '0');
INSERT INTO "SYSTEM_DICT_TYPE" ("ID", "NAME", "TYPE", "STATUS", "REMARK", "CREATOR", "CREATE_TIME", "UPDATER", "UPDATE_TIME", "DELETED") VALUES ('10', '系统状态', 'common_status', '0', NULL, 'admin', TO_DATE('2021-01-05 17:03:48', 'SYYYY-MM-DD HH24:MI:SS'), NULL, TO_DATE('2022-02-01 16:21:28', 'SYYYY-MM-DD HH24:MI:SS'), '0');
INSERT INTO "SYSTEM_DICT_TYPE" ("ID", "NAME", "TYPE", "STATUS", "REMARK", "CREATOR", "CREATE_TIME", "UPDATER", "UPDATE_TIME", "DELETED") VALUES ('11', 'Boolean 是否类型', 'infra_boolean_string', '0', 'boolean 转是否', NULL, TO_DATE('2021-01-19 03:20:08', 'SYYYY-MM-DD HH24:MI:SS'), NULL, TO_DATE('2022-02-01 16:37:10', 'SYYYY-MM-DD HH24:MI:SS'), '0');
INSERT INTO "SYSTEM_DICT_TYPE" ("ID", "NAME", "TYPE", "STATUS", "REMARK", "CREATOR", "CREATE_TIME", "UPDATER", "UPDATE_TIME", "DELETED") VALUES ('104', '登陆结果', 'system_login_result', '0', '登陆结果', NULL, TO_DATE('2021-01-18 06:17:11', 'SYYYY-MM-DD HH24:MI:SS'), NULL, TO_DATE('2022-02-01 16:36:00', 'SYYYY-MM-DD HH24:MI:SS'), '0');

View File

@ -2357,38 +2357,58 @@ COMMIT;
-- Table structure for system_dict_type
-- ----------------------------
DROP TABLE IF EXISTS "system_dict_type";
CREATE TABLE "system_dict_type" (
"id" int8 NOT NULL,
"name" varchar(100) COLLATE "pg_catalog"."default" NOT NULL,
"type" varchar(100) COLLATE "pg_catalog"."default" NOT NULL,
"status" int2 NOT NULL,
"remark" varchar(500) COLLATE "pg_catalog"."default",
"creator" varchar(64) COLLATE "pg_catalog"."default",
"create_time" timestamp(6) NOT NULL,
"updater" varchar(64) COLLATE "pg_catalog"."default",
"update_time" timestamp(6) NOT NULL,
"deleted" int2 NOT NULL DEFAULT 0
CREATE TABLE "system_dict_type"(
"id" int8 NOT NULL,
"name" varchar(100) COLLATE "pg_catalog"."default" NOT NULL,
"type" varchar(100) COLLATE "pg_catalog"."default" NOT NULL,
"status" int2 NOT NULL,
"remark" varchar(500) COLLATE "pg_catalog"."default",
"creator" varchar(64) COLLATE "pg_catalog"."default",
"create_time" timestamp(6) NOT NULL,
"updater" varchar(64) COLLATE "pg_catalog"."default",
"update_time" timestamp(6) NOT NULL,
"deleted_time" timestamp(6),
"deleted" int2 NOT NULL DEFAULT 0
)
;
COMMENT ON COLUMN "system_dict_type"."id" IS '字典主键';
COMMENT ON COLUMN "system_dict_type"."name" IS '字典名称';
COMMENT ON COLUMN "system_dict_type"."type" IS '字典类型';
COMMENT ON COLUMN "system_dict_type"."status" IS '状态0正常 1停用';
COMMENT ON COLUMN "system_dict_type"."remark" IS '备注';
COMMENT ON COLUMN "system_dict_type"."creator" IS '创建者';
COMMENT ON COLUMN "system_dict_type"."create_time" IS '创建时间';
COMMENT ON COLUMN "system_dict_type"."updater" IS '更新者';
COMMENT ON COLUMN "system_dict_type"."update_time" IS '更新时间';
COMMENT ON COLUMN "system_dict_type"."deleted" IS '是否删除';
COMMENT ON TABLE "system_dict_type" IS '字典类型表';
COMMENT
ON COLUMN "system_dict_type"."id" IS '字典主键';
COMMENT
ON COLUMN "system_dict_type"."name" IS '字典名称';
COMMENT
ON COLUMN "system_dict_type"."type" IS '字典类型';
COMMENT
ON COLUMN "system_dict_type"."status" IS '状态0正常 1停用';
COMMENT
ON COLUMN "system_dict_type"."remark" IS '备注';
COMMENT
ON COLUMN "system_dict_type"."creator" IS '创建者';
COMMENT
ON COLUMN "system_dict_type"."create_time" IS '创建时间';
COMMENT
ON COLUMN "system_dict_type"."updater" IS '更新者';
COMMENT
ON COLUMN "system_dict_type"."update_time" IS '更新时间';
COMMENT
ON COLUMN "system_dict_type"."deleted_time" IS '删除时间';
COMMENT
ON COLUMN "system_dict_type"."deleted" IS '是否删除';
COMMENT
ON TABLE "system_dict_type" IS '字典类型表';
-- ----------------------------
-- Records of system_dict_type
-- ----------------------------
BEGIN;
INSERT INTO "system_dict_type" ("id", "name", "type", "status", "remark", "creator", "create_time", "updater", "update_time", "deleted") VALUES (1, '用户性别', 'system_user_sex', 0, NULL, 'admin', '2021-01-05 17:03:48', '', '2022-02-01 16:30:31', 0);
INSERT INTO "system_dict_type" ("id", "name", "type", "status", "remark", "creator", "create_time", "updater", "update_time", "deleted") VALUES (6, '参数类型', 'infra_config_type', 0, NULL, 'admin', '2021-01-05 17:03:48', '', '2022-02-01 16:36:54', 0);
INSERT INTO "system_dict_type" ("id", "name", "type", "status", "remark", "creator", "create_time", "updater", "update_time", "deleted") VALUES (7, '通知类型', 'system_notice_type', 0, NULL, 'admin', '2021-01-05 17:03:48', '', '2022-02-01 16:35:26', 0);
INSERT INTO "system_dict_type" ("id", "name", "type", "status", "remark", "creator", "create_time", "updater",
"update_time", "deleted")
VALUES (1, '用户性别', 'system_user_sex', 0, NULL, 'admin', '2021-01-05 17:03:48', '', '2022-02-01 16:30:31', 0);
INSERT INTO "system_dict_type" ("id", "name", "type", "status", "remark", "creator", "create_time", "updater",
"update_time", "deleted")
VALUES (6, '参数类型', 'infra_config_type', 0, NULL, 'admin', '2021-01-05 17:03:48', '', '2022-02-01 16:36:54', 0);
INSERT INTO "system_dict_type" ("id", "name", "type", "status", "remark", "creator", "create_time", "updater",
"update_time", "deleted")
VALUES (7, '通知类型', 'system_notice_type', 0, NULL, 'admin', '2021-01-05 17:03:48', '', '2022-02-01 16:35:26', 0);
INSERT INTO "system_dict_type" ("id", "name", "type", "status", "remark", "creator", "create_time", "updater", "update_time", "deleted") VALUES (9, '操作类型', 'system_operate_type', 0, NULL, 'admin', '2021-01-05 17:03:48', '1', '2022-02-16 09:32:21', 0);
INSERT INTO "system_dict_type" ("id", "name", "type", "status", "remark", "creator", "create_time", "updater", "update_time", "deleted") VALUES (10, '系统状态', 'common_status', 0, NULL, 'admin', '2021-01-05 17:03:48', '', '2022-02-01 16:21:28', 0);
INSERT INTO "system_dict_type" ("id", "name", "type", "status", "remark", "creator", "create_time", "updater", "update_time", "deleted") VALUES (11, 'Boolean 是否类型', 'infra_boolean_string', 0, 'boolean 转是否', '', '2021-01-19 03:20:08', '', '2022-02-01 16:37:10', 0);

View File

@ -5813,18 +5813,51 @@ IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sy
DROP TABLE [dbo].[system_dict_type]
GO
CREATE TABLE [dbo].[system_dict_type] (
[id] bigint IDENTITY(1,1) NOT NULL,
[name] nvarchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[type] nvarchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[status] tinyint NOT NULL,
[remark] nvarchar(500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[creator] nvarchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[create_time] datetime2(7) NOT NULL,
[updater] nvarchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[update_time] datetime2(7) NOT NULL,
[deleted] bit DEFAULT 0 NOT NULL
)
CREATE TABLE [dbo].[system_dict_type]
(
[
id]
bigint
IDENTITY
(
1,
1
) NOT NULL,
[name] nvarchar
(
100
) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[type] nvarchar
(
100
) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[status] tinyint NOT NULL,
[remark] nvarchar
(
500
) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[creator] nvarchar
(
64
) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[create_time] datetime2
(
7
) NOT NULL,
[updater] nvarchar
(
64
) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[update_time] datetime2
(
7
) NOT NULL,
[deleted_time] datetime2
(
7
),
[deleted] bit DEFAULT 0 NOT NULL
)
GO
ALTER TABLE [dbo].[system_dict_type] SET (LOCK_ESCALATION = TABLE)
@ -5882,26 +5915,29 @@ GO
EXEC sp_addextendedproperty
'MS_Description', N'更新者',
'SCHEMA', N'dbo',
'TABLE', N'system_dict_type',
'COLUMN', N'updater'
GO
EXEC sp_addextendedproperty
'MS_Description', N'更新时间',
'SCHEMA', N'dbo',
'TABLE', N'system_dict_type',
'COLUMN', N'update_time'
GO
EXEC sp_addextendedproperty
'MS_Description', N'是否删除',
'SCHEMA', N'dbo',
'TABLE', N'system_dict_type',
'COLUMN', N'deleted'
GO
EXEC sp_addextendedproperty
'MS_Description', N'字典类型表',
'TABLE', N'system_dict_type',
'COLUMN', N'updater'
GO
EXEC sp_addextendedproperty
'MS_Description', N'更新时间',
'SCHEMA', N'dbo',
'TABLE', N'system_dict_type',
'COLUMN', N'update_time'
GO
EXEC sp_addextendedproperty
'MS_Description', N'删除时间',
'SCHEMA', N'dbo',
'TABLE', N'system_dict_type',
'COLUMN', N'deleted_time'
GO
EXEC sp_addextendedproperty
'MS_Description', N'是否删除',
'SCHEMA', N'dbo',
'TABLE', N'system_dict_type',
'COLUMN', N'deleted'
GO
EXEC sp_addextendedproperty
'MS_Description', N'字典类型表',
'SCHEMA', N'dbo',
'TABLE', N'system_dict_type'
GO

View File

@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.time.LocalDateTime;
/**
* 字典类型表
*
@ -47,4 +49,9 @@ public class DictTypeDO extends BaseDO {
*/
private String remark;
/**
* 删除时间
*/
private LocalDateTime deletedTime;
}

View File

@ -13,6 +13,7 @@ import com.google.common.annotations.VisibleForTesting;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -80,7 +81,9 @@ public class DictTypeServiceImpl implements DictTypeService {
throw exception(DICT_TYPE_HAS_CHILDREN);
}
// 删除字典类型
dictTypeMapper.deleteById(id);
dictType.setDeletedTime(LocalDateTime.now());
dictType.setDeleted(true);
dictTypeMapper.updateById(dictType);
}
@Override