mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
【修复】字典类型逻辑删除时,唯一索引冲突的问题
This commit is contained in:
parent
2c3aaa8d7e
commit
5a4cc55917
@ -12,6 +12,11 @@ import java.time.LocalDateTime;
|
||||
*/
|
||||
public class LocalDateTimeUtils {
|
||||
|
||||
/**
|
||||
* 空的 LocalDateTime 对象,主要用于 DB 唯一索引的默认值
|
||||
*/
|
||||
public static LocalDateTime EMPTY = buildTime(1970, 1, 1);
|
||||
|
||||
public static LocalDateTime addTime(Duration duration) {
|
||||
return LocalDateTime.now().plus(duration);
|
||||
}
|
||||
|
@ -5,9 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictTypeDO;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
@ -43,10 +41,8 @@ public interface DictTypeMapper extends BaseMapperX<DictTypeDO> {
|
||||
return selectOne(DictTypeDO::getName, name);
|
||||
}
|
||||
|
||||
@Update("UPDATE system_dict_type SET DELETED = 1,DELETED_TIME=#{deletedTime} WHERE id = #{id}")
|
||||
int deleteById(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
|
||||
|
||||
default int deleteById(Long id) {
|
||||
return deleteById(id, LocalDateTime.now());
|
||||
}
|
||||
@Update("UPDATE system_dict_type SET deleted = 1, deleted_time = #{deletedTime} WHERE id = #{id}")
|
||||
void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.service.dict;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeCreateReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypeExportReqVO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dict.vo.type.DictTypePageReqVO;
|
||||
@ -58,7 +59,8 @@ public class DictTypeServiceImpl implements DictTypeService {
|
||||
// 校验正确性
|
||||
checkCreateOrUpdate(null, reqVO.getName(), reqVO.getType());
|
||||
// 插入字典类型
|
||||
DictTypeDO dictType = DictTypeConvert.INSTANCE.convert(reqVO);
|
||||
DictTypeDO dictType = DictTypeConvert.INSTANCE.convert(reqVO)
|
||||
.setDeletedTime(LocalDateTimeUtils.EMPTY); // 唯一索引,避免 null 值
|
||||
dictTypeMapper.insert(dictType);
|
||||
return dictType.getId();
|
||||
}
|
||||
@ -81,7 +83,7 @@ public class DictTypeServiceImpl implements DictTypeService {
|
||||
throw exception(DICT_TYPE_HAS_CHILDREN);
|
||||
}
|
||||
// 删除字典类型
|
||||
dictTypeMapper.deleteById(id);
|
||||
dictTypeMapper.updateToDelete(id, LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,6 +111,7 @@ CREATE TABLE IF NOT EXISTS "system_dict_type" (
|
||||
"updater" varchar(64) DEFAULT '',
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"deleted_time" timestamp NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '字典类型表';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user