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

@ -1345,9 +1345,10 @@ CREATE TABLE `system_dict_type` (
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' 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 '更新时间', `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 '是否删除', `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
PRIMARY KEY (`id`) USING BTREE, PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `dict_type`(`type` ASC) 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 = '字典类型表'; ) ENGINE = InnoDB AUTO_INCREMENT = 149 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '字典类型表';
-- ---------------------------- -- ----------------------------

View File

@ -2484,6 +2484,7 @@ CREATE TABLE "SYSTEM_DICT_TYPE" (
"CREATE_TIME" DATE NOT NULL, "CREATE_TIME" DATE NOT NULL,
"UPDATER" NVARCHAR2(64), "UPDATER" NVARCHAR2(64),
"UPDATE_TIME" DATE NOT NULL, "UPDATE_TIME" DATE NOT NULL,
"DELETED_TIME" DATE,
"DELETED" NUMBER(1,0) DEFAULT 0 NOT NULL "DELETED" NUMBER(1,0) DEFAULT 0 NOT NULL
) )
LOGGING LOGGING
@ -2503,25 +2504,54 @@ PARALLEL 1
NOCACHE NOCACHE
DISABLE ROW MOVEMENT DISABLE ROW MOVEMENT
; ;
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."ID" IS '字典主键'; COMMENT
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."NAME" IS '字典名称'; ON COLUMN "SYSTEM_DICT_TYPE"."ID" IS '字典主键';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."TYPE" IS '字典类型'; COMMENT
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."STATUS" IS '状态0正常 1停用'; ON COLUMN "SYSTEM_DICT_TYPE"."NAME" IS '字典名称';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."REMARK" IS '备注'; COMMENT
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."CREATOR" IS '创建者'; ON COLUMN "SYSTEM_DICT_TYPE"."TYPE" IS '字典类型';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."CREATE_TIME" IS '创建时间'; COMMENT
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."UPDATER" IS '更新者'; ON COLUMN "SYSTEM_DICT_TYPE"."STATUS" IS '状态0正常 1停用';
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."UPDATE_TIME" IS '更新时间'; COMMENT
COMMENT ON COLUMN "SYSTEM_DICT_TYPE"."DELETED" IS '是否删除'; ON COLUMN "SYSTEM_DICT_TYPE"."REMARK" IS '备注';
COMMENT ON TABLE "SYSTEM_DICT_TYPE" 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 -- 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",
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'); "UPDATE_TIME", "DELETED")
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'); VALUES ('1', '用户性别', 'system_user_sex', '0', NULL, 'admin',
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'); 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 ('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 ('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'); 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

@ -2367,28 +2367,48 @@ CREATE TABLE "system_dict_type" (
"create_time" timestamp(6) NOT NULL, "create_time" timestamp(6) NOT NULL,
"updater" varchar(64) COLLATE "pg_catalog"."default", "updater" varchar(64) COLLATE "pg_catalog"."default",
"update_time" timestamp(6) NOT NULL, "update_time" timestamp(6) NOT NULL,
"deleted_time" timestamp(6),
"deleted" int2 NOT NULL DEFAULT 0 "deleted" int2 NOT NULL DEFAULT 0
) )
; ;
COMMENT ON COLUMN "system_dict_type"."id" IS '字典主键'; COMMENT
COMMENT ON COLUMN "system_dict_type"."name" IS '字典名称'; ON COLUMN "system_dict_type"."id" IS '字典主键';
COMMENT ON COLUMN "system_dict_type"."type" IS '字典类型'; COMMENT
COMMENT ON COLUMN "system_dict_type"."status" IS '状态0正常 1停用'; ON COLUMN "system_dict_type"."name" IS '字典名称';
COMMENT ON COLUMN "system_dict_type"."remark" IS '备注'; COMMENT
COMMENT ON COLUMN "system_dict_type"."creator" IS '创建者'; ON COLUMN "system_dict_type"."type" IS '字典类型';
COMMENT ON COLUMN "system_dict_type"."create_time" IS '创建时间'; COMMENT
COMMENT ON COLUMN "system_dict_type"."updater" IS '更新者'; ON COLUMN "system_dict_type"."status" IS '状态0正常 1停用';
COMMENT ON COLUMN "system_dict_type"."update_time" IS '更新时间'; COMMENT
COMMENT ON COLUMN "system_dict_type"."deleted" IS '是否删除'; ON COLUMN "system_dict_type"."remark" IS '备注';
COMMENT ON TABLE "system_dict_type" 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 -- Records of system_dict_type
-- ---------------------------- -- ----------------------------
BEGIN; 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",
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); "update_time", "deleted")
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); 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 (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 (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); 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,16 +5813,49 @@ IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[sy
DROP TABLE [dbo].[system_dict_type] DROP TABLE [dbo].[system_dict_type]
GO GO
CREATE TABLE [dbo].[system_dict_type] ( 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, 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, [status] tinyint NOT NULL,
[remark] nvarchar(500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [remark] nvarchar
[creator] nvarchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, (
[create_time] datetime2(7) NOT NULL, 500
[updater] nvarchar(64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, ) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[update_time] datetime2(7) NOT 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 [deleted] bit DEFAULT 0 NOT NULL
) )
GO GO
@ -5885,21 +5918,24 @@ EXEC sp_addextendedproperty
'TABLE', N'system_dict_type', 'TABLE', N'system_dict_type',
'COLUMN', N'updater' 'COLUMN', N'updater'
GO GO
EXEC sp_addextendedproperty EXEC sp_addextendedproperty
'MS_Description', N'更新时间', 'MS_Description', N'更新时间',
'SCHEMA', N'dbo', 'SCHEMA', N'dbo',
'TABLE', N'system_dict_type', 'TABLE', N'system_dict_type',
'COLUMN', N'update_time' 'COLUMN', N'update_time'
GO GO
EXEC sp_addextendedproperty
'MS_Description', N'删除时间',
'SCHEMA', N'dbo',
'TABLE', N'system_dict_type',
'COLUMN', N'deleted_time'
GO
EXEC sp_addextendedproperty EXEC sp_addextendedproperty
'MS_Description', N'是否删除', 'MS_Description', N'是否删除',
'SCHEMA', N'dbo', 'SCHEMA', N'dbo',
'TABLE', N'system_dict_type', 'TABLE', N'system_dict_type',
'COLUMN', N'deleted' 'COLUMN', N'deleted'
GO GO
EXEC sp_addextendedproperty EXEC sp_addextendedproperty
'MS_Description', N'字典类型表', 'MS_Description', N'字典类型表',
'SCHEMA', N'dbo', 'SCHEMA', N'dbo',

View File

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

View File

@ -13,6 +13,7 @@ import com.google.common.annotations.VisibleForTesting;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 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); throw exception(DICT_TYPE_HAS_CHILDREN);
} }
// 删除字典类型 // 删除字典类型
dictTypeMapper.deleteById(id); dictType.setDeletedTime(LocalDateTime.now());
dictType.setDeleted(true);
dictTypeMapper.updateById(dictType);
} }
@Override @Override