update 优化 项目中的一些存在null的问题 与一些性能问题 小优化

This commit is contained in:
疯狂的狮子Li
2026-03-31 18:52:37 +08:00
parent 26464c0051
commit d11990bfd8
21 changed files with 137 additions and 91 deletions

View File

@@ -241,9 +241,7 @@ public class GenTableServiceImpl implements IGenTableService {
genTable.setOptions(options);
int row = baseMapper.updateById(genTable);
if (row > 0) {
for (GenTableColumn cenTableColumn : genTable.getColumns()) {
genTableColumnMapper.updateById(cenTableColumn);
}
genTableColumnMapper.updateBatchById(genTable.getColumns());
}
}
@@ -289,6 +287,7 @@ public class GenTableServiceImpl implements IGenTableService {
}
}
} catch (Exception e) {
log.error("导入失败", e);
throw new ServiceException("导入失败:" + e.getMessage());
}
}
@@ -471,7 +470,7 @@ public class GenTableServiceImpl implements IGenTableService {
zip.flush();
zip.closeEntry();
} catch (IOException e) {
log.error("渲染模板失败,表名:" + table.getTableName(), e);
log.error("渲染模板失败,表名:{}", table.getTableName(), e);
}
}
}

View File

@@ -180,7 +180,7 @@ public class GenUtils {
String text = replacementm;
for (String searchString : searchList) {
if (replacementm.startsWith(searchString)) {
text = replacementm.replaceFirst(searchString, StringUtils.EMPTY);
text = StringUtils.removeStart(replacementm, searchString);
break;
}
}
@@ -220,6 +220,10 @@ public class GenUtils {
public static Integer getColumnLength(String columnType) {
if (StringUtils.indexOf(columnType, "(") > 0) {
String length = StringUtils.substringBetween(columnType, "(", ")");
// 处理 decimal(10,2) 这类带精度的类型,只取长度部分
if (length.contains(",")) {
length = StringUtils.substringBefore(length, ",");
}
return Integer.valueOf(length);
} else {
return 0;

View File

@@ -73,7 +73,6 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo>, MPJBa
default List<SysUserExportVo> selectUserExportList(SysUserBo user, List<Long> deptIds) {
MPJLambdaWrapper<SysUser> wrapper = JoinWrappers.lambda("u", SysUser.class)
.selectAll(SysUser.class)
.selectAs(SysDept::getDeptName, SysUserExportVo::getDeptName)
.selectAs("u1", SysUser::getUserName, SysUserExportVo::getLeaderName)
.leftJoin(SysDept.class, "d", SysDept::getDeptId, SysUser::getDeptId)
.leftJoin(SysUser.class, "u1", SysUser::getUserId, SysDept::getLeader)

View File

@@ -152,7 +152,7 @@ public class SysConfigServiceImpl implements ISysConfigService, ConfigService {
SysConfig config = MapstructUtils.convert(bo, SysConfig.class);
if (config.getConfigId() != null) {
SysConfig temp = baseMapper.selectById(config.getConfigId());
if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) {
if (ObjectUtil.isNotNull(temp) && !StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) {
CacheUtils.evict(CacheNames.SYS_CONFIG, temp.getConfigKey());
}
row = baseMapper.updateById(config);

View File

@@ -216,7 +216,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Override
public Long selectDeptLeaderById(Long deptId) {
SysDeptVo vo = SpringUtils.getAopProxy(this).selectDeptById(deptId);
return vo.getLeader();
return ObjectUtil.isNull(vo) ? null : vo.getLeader();
}
/**
@@ -312,7 +312,10 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Override
public int insertDept(SysDeptBo bo) {
SysDept info = baseMapper.selectById(bo.getParentId());
// 如果父节点不为正常状态,则不允许新增子节点
// 如果父节点不存在或不为正常状态,则不允许新增子节点
if (ObjectUtil.isNull(info)) {
throw new ServiceException("父部门不存在");
}
if (!SystemConstants.NORMAL.equals(info.getStatus())) {
throw new ServiceException("部门停用,不允许新增");
}
@@ -390,7 +393,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
for (SysDept child : children) {
SysDept dept = new SysDept();
dept.setDeptId(child.getDeptId());
dept.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
dept.setAncestors(StringUtils.replaceOnce(child.getAncestors(), oldAncestors, newAncestors));
list.add(dept);
}
if (CollUtil.isNotEmpty(list)) {
@@ -408,7 +411,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
*/
@Caching(evict = {
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId"),
@CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, key = "#deptId")
@CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, allEntries = true)
})
@Override
public int deleteDeptById(Long deptId) {

View File

@@ -108,7 +108,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService
@Override
public List<SysDictDataVo> selectDictDataByType(String dictType) {
List<SysDictDataVo> dictDatas = dictDataMapper.selectDictDataByType(dictType);
return CollUtil.isNotEmpty(dictDatas) ? dictDatas : null;
return CollUtil.isNotEmpty(dictDatas) ? dictDatas : Collections.emptyList();
}
/**