refactor: 优化部分代码

修复 Sonar 扫描问题
This commit is contained in:
Charles7c 2024-01-27 15:26:49 +08:00
parent d972a4466a
commit 03038d3b64
7 changed files with 20 additions and 24 deletions

View File

@ -16,13 +16,15 @@
package top.charles7c.continew.admin.common.constant;
import top.charles7c.continew.starter.extension.crud.constant.ContainerPool;
/**
* 数据源容器相关常量Crane4j 数据填充组件使用
*
* @author Charles7c
* @since 2024/1/20 12:33
*/
public class ContainerConstants implements top.charles7c.continew.starter.extension.crud.constant.ContainerConstants {
public class ContainerConstants extends ContainerPool {
private ContainerConstants() {
}

View File

@ -30,6 +30,9 @@ import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
*/
public class SecureUtils {
private SecureUtils() {
}
/**
* 公钥加密
*
@ -74,7 +77,4 @@ public class SecureUtils {
public static String md5Salt(String data, String salt) {
return SecureUtil.md5(SecureUtil.md5(data) + salt);
}
private SecureUtils() {
}
}

View File

@ -42,6 +42,9 @@ import java.time.LocalDateTime;
*/
public class LoginHelper {
private LoginHelper() {
}
/**
* 用户登录并缓存用户信息
*
@ -133,7 +136,4 @@ public class LoginHelper {
public static String getNickname(Long userId) {
return ExceptionUtils.exToNull(() -> SpringUtil.getBean(CommonUserService.class).getNicknameById(userId));
}
private LoginHelper() {
}
}

View File

@ -16,14 +16,13 @@
package top.charles7c.continew.admin.system.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import top.charles7c.continew.admin.common.model.resp.LabelValueResp;
import top.charles7c.continew.admin.system.model.entity.DictItemDO;
import top.charles7c.continew.starter.data.mybatis.plus.base.BaseMapper;
import java.util.List;
/**
* 字典项 Mapper
*

View File

@ -143,17 +143,15 @@ public class FieldConfigDO implements Serializable {
private LocalDateTime createTime;
public FieldConfigDO(@NonNull Column column) {
String columnType = StrUtil.splitToArray(column.getTypeName(), StringConstants.SPACE)[0].toLowerCase();
boolean isRequired = !column.isPk() && !column.isNullable();
this.tableName = column.getTableName();
this.setTableName(column.getTableName());
this.setColumnName(column.getName());
this.setColumnType(columnType);
this.setColumnType(StrUtil.splitToArray(column.getTypeName(), StringConstants.SPACE)[0].toLowerCase());
this.setColumnSize(column.getSize());
this.setComment(column.getComment());
this.setIsRequired(isRequired);
this.setIsRequired(!column.isPk() && !column.isNullable());
this.setShowInList(true);
this.setShowInForm(isRequired);
this.setShowInQuery(isRequired);
this.setShowInForm(this.getIsRequired());
this.setShowInQuery(this.getIsRequired());
this.setFormType(FormTypeEnum.TEXT);
this.setQueryType("String".equals(this.getFieldType()) ? QueryTypeEnum.LIKE : QueryTypeEnum.EQ);
}

View File

@ -134,7 +134,7 @@ public class GeneratorServiceImpl implements GeneratorService {
return columnList.stream().map(FieldConfigDO::new).collect(Collectors.toList());
}
// 同步最新数据表列信息
if (requireSync) {
if (Boolean.TRUE.equals(requireSync)) {
Collection<Column> columnList = MetaUtils.getColumns(dataSource, tableName);
// 移除已不存在的字段配置
List<String> columnNameList = columnList.stream().map(Column::getName).collect(Collectors.toList());
@ -286,7 +286,7 @@ public class GeneratorServiceImpl implements GeneratorService {
.getPackageName(), StringConstants.DOT));
File classFile = new File(classParentFile, codePreview.getFileName());
// 如果已经存在且不允许覆盖则跳过
if (classFile.exists() && !isOverride) {
if (classFile.exists() && Boolean.FALSE.equals(isOverride)) {
continue;
}
FileUtil.writeUtf8String(codePreview.getContent(), classFile);
@ -309,7 +309,7 @@ public class GeneratorServiceImpl implements GeneratorService {
// 例如D:/continew-admin-ui/src/api/tool/xxx.ts
File apiParentFile = FileUtil.file(frontendModulePath, "src", "api", apiModuleName);
File apiFile = new File(apiParentFile, apiCodePreview.getFileName());
if (apiFile.exists() && !isOverride) {
if (apiFile.exists() && Boolean.FALSE.equals(isOverride)) {
return;
}
FileUtil.writeUtf8String(apiCodePreview.getContent(), apiFile);
@ -318,7 +318,7 @@ public class GeneratorServiceImpl implements GeneratorService {
// 例如D:/continew-admin-ui/src/views/tool/xxx/index.vue
File indexFile = FileUtil.file(frontendPath, apiModuleName, StrUtil
.lowerFirst(classNamePrefix), "index.vue");
if (indexFile.exists() && !isOverride) {
if (indexFile.exists() && Boolean.FALSE.equals(isOverride)) {
return;
}
FileUtil.writeUtf8String(viewCodePreview.getContent(), indexFile);

View File

@ -73,10 +73,7 @@
<!-- 如果配置的日志等级,和 application.yml 中的日志等级配置重叠application.yml 配置优先级高 -->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<!--<appender-ref ref="ASYNC_FILE"/>-->
</root>
<!-- 日志保留天数 -->
<!--<property name="FILE_MAX_HISTORY" value="15"/>-->
</springProfile>
<!-- 生产环境:打印到控制台并输出到文件 -->