refactor: 优化部分代码

1.修复 Sonar 扫描问题
2.使用常量替代部分魔法值
This commit is contained in:
2024-01-27 23:10:27 +08:00
parent ef0e99de83
commit 75fe5377df
9 changed files with 102 additions and 61 deletions

View File

@@ -17,6 +17,7 @@
package top.charles7c.continew.starter.data.mybatis.plus.autoconfigure;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import top.charles7c.continew.starter.core.constant.PropertiesConstants;
import java.lang.annotation.*;
@@ -29,6 +30,6 @@ import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Documented
@ConditionalOnProperty(prefix = "mybatis-plus.extension.data-permission", name = "enabled", havingValue = "true")
@ConditionalOnProperty(prefix = "mybatis-plus.extension.data-permission", name = PropertiesConstants.ENABLED, havingValue = "true")
public @interface ConditionalOnEnabledDataPermission {
}

View File

@@ -35,6 +35,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import top.charles7c.continew.starter.core.constant.PropertiesConstants;
import top.charles7c.continew.starter.core.util.GeneralPropertySourceFactory;
import top.charles7c.continew.starter.data.mybatis.plus.datapermission.DataPermissionFilter;
import top.charles7c.continew.starter.data.mybatis.plus.datapermission.DataPermissionHandlerImpl;
@@ -50,7 +51,7 @@ import top.charles7c.continew.starter.data.mybatis.plus.datapermission.DataPermi
@MapperScan("${mybatis-plus.extension.mapper-package}")
@EnableTransactionManagement(proxyTargetClass = true)
@EnableConfigurationProperties(MyBatisPlusExtensionProperties.class)
@ConditionalOnProperty(prefix = "mybatis-plus.extension", name = "enabled", havingValue = "true")
@ConditionalOnProperty(prefix = "mybatis-plus.extension", name = PropertiesConstants.ENABLED, havingValue = "true")
@PropertySource(value = "classpath:default-data-mybatis-plus.yml", factory = GeneralPropertySourceFactory.class)
public class MybatisPlusAutoConfiguration {

View File

@@ -100,6 +100,7 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
case DEPT -> expression = this.buildDeptExpression(dataPermission, currentUser, expression);
case SELF -> expression = this.buildSelfExpression(dataPermission, currentUser, expression);
case CUSTOM -> expression = this.buildCustomExpression(dataPermission, role, expression);
default -> throw new IllegalArgumentException(String.format("暂不支持 [%s] 数据权限", dataScope));
}
}
return null != where ? new AndExpression(where, new Parenthesis(expression)) : expression;