mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-12 06:57:13 +08:00
style: 优化 == 及 != 表达式格式
1.将 null 或常量值调整到符号左侧 2.将无特殊意义的方法判空写法改为表达式判断写法
This commit is contained in:
@@ -151,7 +151,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
||||
// 设置排序
|
||||
Sort sort = Opt.ofNullable(sortQuery).orElseGet(SortQuery::new).getSort();
|
||||
for (Sort.Order order : sort) {
|
||||
queryWrapper.orderBy(order != null, order.isAscending(), StrUtil.toUnderlineCase(order.getProperty()));
|
||||
queryWrapper.orderBy(null != order, order.isAscending(), StrUtil.toUnderlineCase(order.getProperty()));
|
||||
}
|
||||
List<T> entityList = baseMapper.selectList(queryWrapper);
|
||||
return BeanUtil.copyToList(entityList, targetClass);
|
||||
@@ -168,7 +168,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long add(C request) {
|
||||
if (request == null) {
|
||||
if (null == request) {
|
||||
return 0L;
|
||||
}
|
||||
T entity = BeanUtil.copyProperties(request, entityClass);
|
||||
@@ -220,7 +220,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
||||
if (baseObj instanceof BaseVO) {
|
||||
BaseVO baseVO = (BaseVO)baseObj;
|
||||
Long createUser = baseVO.getCreateUser();
|
||||
if (createUser == null) {
|
||||
if (null == createUser) {
|
||||
return;
|
||||
}
|
||||
CommonUserService userService = SpringUtil.getBean(CommonUserService.class);
|
||||
@@ -240,7 +240,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
||||
this.fill(detailVO);
|
||||
|
||||
Long updateUser = detailVO.getUpdateUser();
|
||||
if (updateUser == null) {
|
||||
if (null == updateUser) {
|
||||
return;
|
||||
}
|
||||
CommonUserService userService = SpringUtil.getBean(CommonUserService.class);
|
||||
|
@@ -63,7 +63,7 @@ public class SwaggerConfiguration {
|
||||
@Bean
|
||||
public GlobalOpenApiCustomizer orderGlobalOpenApiCustomizer() {
|
||||
return openApi -> {
|
||||
if (openApi.getTags() != null) {
|
||||
if (null != openApi.getTags()) {
|
||||
openApi.getTags()
|
||||
.forEach(tag -> tag.setExtensions(MapUtil.of("x-order", RandomUtil.randomInt(0, 100))));
|
||||
}
|
||||
|
@@ -25,7 +25,6 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
import top.charles7c.cnadmin.common.constant.StringConsts;
|
||||
@@ -63,7 +62,7 @@ public class ExcelBaseEnumConverter implements Converter<BaseEnum<Integer, Strin
|
||||
@Override
|
||||
public WriteCellData<String> convertToExcelData(BaseEnum<Integer, String> value,
|
||||
ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
if (ObjectUtil.isNull(value)) {
|
||||
if (null == value) {
|
||||
return new WriteCellData<>(StringConsts.EMPTY);
|
||||
}
|
||||
return new WriteCellData<>(value.getDescription());
|
||||
|
@@ -26,7 +26,6 @@ import com.alibaba.excel.metadata.data.WriteCellData;
|
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
|
||||
/**
|
||||
* Easy Excel 大数值转换器(Excel 中对长度超过 15 位的数值输入是有限制的,从 16 位开始无论录入什么数字均会变为 0,因此输入时只能以文本的形式进行录入)
|
||||
@@ -66,7 +65,7 @@ public class ExcelBigNumberConverter implements Converter<Long> {
|
||||
@Override
|
||||
public WriteCellData<Object> convertToExcelData(Long value, ExcelContentProperty contentProperty,
|
||||
GlobalConfiguration globalConfiguration) {
|
||||
if (ObjectUtil.isNotNull(value)) {
|
||||
if (null != value) {
|
||||
String str = Long.toString(value);
|
||||
if (str.length() > MAX_LENGTH) {
|
||||
return new WriteCellData<>(str);
|
||||
|
@@ -52,14 +52,14 @@ public class SimpleDeserializersWrapper extends SimpleDeserializers {
|
||||
public JsonDeserializer<?> findEnumDeserializer(Class<?> type, DeserializationConfig config,
|
||||
BeanDescription beanDesc) throws JsonMappingException {
|
||||
JsonDeserializer<?> deser = super.findEnumDeserializer(type, config, beanDesc);
|
||||
if (deser != null) {
|
||||
if (null != deser) {
|
||||
return deser;
|
||||
}
|
||||
|
||||
// 重写增强:开始查找指定枚举类型的接口的反序列化器(例如:GenderEnum 枚举类型,则是找它的接口 BaseEnum 的反序列化器)
|
||||
for (Class<?> typeInterface : type.getInterfaces()) {
|
||||
deser = this._classMappings.get(new ClassKey(typeInterface));
|
||||
if (deser != null) {
|
||||
if (null != deser) {
|
||||
return deser;
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,6 @@ import java.util.Collections;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler;
|
||||
|
||||
@@ -80,13 +79,13 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
|
||||
String methodName = mappedStatementId.substring(mappedStatementId.lastIndexOf(StringConsts.DOT) + 1);
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
DataPermission annotation = method.getAnnotation(DataPermission.class);
|
||||
if (ObjectUtils.isNotEmpty(annotation)
|
||||
DataPermission dataPermission = method.getAnnotation(DataPermission.class);
|
||||
if (null != dataPermission
|
||||
&& (method.getName().equals(methodName) || (method.getName() + "_COUNT").equals(methodName))) {
|
||||
// 获取当前登录用户
|
||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
if (ObjectUtils.isNotEmpty(loginUser) && !loginUser.isAdmin()) {
|
||||
return buildDataScopeFilter(loginUser, annotation.value(), where);
|
||||
if (null != loginUser && !loginUser.isAdmin()) {
|
||||
return buildDataScopeFilter(loginUser, dataPermission.value(), where);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,20 +133,19 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
|
||||
InExpression inExpression = new InExpression();
|
||||
inExpression.setLeftExpression(buildColumn(tableAlias, DEPT_ID));
|
||||
inExpression.setRightExpression(subSelect);
|
||||
expression =
|
||||
ObjectUtils.isNotEmpty(expression) ? new OrExpression(expression, inExpression) : inExpression;
|
||||
expression = null != expression ? new OrExpression(expression, inExpression) : inExpression;
|
||||
} else if (DataScopeEnum.DEPT.equals(dataScope)) {
|
||||
// select t1.* from table as t1 where t1.`dept_id` = xxx;
|
||||
EqualsTo equalsTo = new EqualsTo();
|
||||
equalsTo.setLeftExpression(buildColumn(tableAlias, DEPT_ID));
|
||||
equalsTo.setRightExpression(new LongValue(user.getDeptId()));
|
||||
expression = ObjectUtils.isNotEmpty(expression) ? new OrExpression(expression, equalsTo) : equalsTo;
|
||||
expression = null != expression ? new OrExpression(expression, equalsTo) : equalsTo;
|
||||
} else if (DataScopeEnum.SELF.equals(dataScope)) {
|
||||
// select t1.* from table as t1 where t1.`create_user` = xxx;
|
||||
EqualsTo equalsTo = new EqualsTo();
|
||||
equalsTo.setLeftExpression(buildColumn(tableAlias, CREATE_USER));
|
||||
equalsTo.setRightExpression(new LongValue(user.getId()));
|
||||
expression = ObjectUtils.isNotEmpty(expression) ? new OrExpression(expression, equalsTo) : equalsTo;
|
||||
expression = null != expression ? new OrExpression(expression, equalsTo) : equalsTo;
|
||||
} else if (DataScopeEnum.CUSTOM.equals(dataScope)) {
|
||||
// select t1.* from table as t1 where t1.`dept_id` in (select `dept_id` from `sys_role_dept` where
|
||||
// `role_id` = xxx);
|
||||
@@ -165,11 +163,10 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
|
||||
InExpression inExpression = new InExpression();
|
||||
inExpression.setLeftExpression(buildColumn(tableAlias, DEPT_ID));
|
||||
inExpression.setRightExpression(subSelect);
|
||||
expression =
|
||||
ObjectUtils.isNotEmpty(expression) ? new OrExpression(expression, inExpression) : inExpression;
|
||||
expression = null != expression ? new OrExpression(expression, inExpression) : inExpression;
|
||||
}
|
||||
}
|
||||
return ObjectUtils.isNotEmpty(where) ? new AndExpression(where, new Parenthesis(expression)) : expression;
|
||||
return null != where ? new AndExpression(where, new Parenthesis(expression)) : expression;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -54,7 +54,7 @@ public class MyBatisPlusMetaObjectHandler implements MetaObjectHandler {
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
try {
|
||||
if (ObjectUtil.isNull(metaObject)) {
|
||||
if (null == metaObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class MyBatisPlusMetaObjectHandler implements MetaObjectHandler {
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
try {
|
||||
if (ObjectUtil.isNull(metaObject)) {
|
||||
if (null == metaObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class MyBatisPlusMetaObjectHandler implements MetaObjectHandler {
|
||||
private void fillFieldValue(MetaObject metaObject, String fieldName, Object fillFieldValue, boolean isOverride) {
|
||||
if (metaObject.hasSetter(fieldName)) {
|
||||
Object fieldValue = metaObject.getValue(fieldName);
|
||||
setFieldValByName(fieldName, fieldValue != null && !isOverride ? fieldValue : fillFieldValue, metaObject);
|
||||
setFieldValByName(fieldName, null != fieldValue && !isOverride ? fieldValue : fillFieldValue, metaObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ public class CrudRequestMappingHandlerMapping extends RequestMappingHandlerMappi
|
||||
@Override
|
||||
protected RequestMappingInfo getMappingForMethod(@NonNull Method method, @NonNull Class<?> handlerType) {
|
||||
RequestMappingInfo requestMappingInfo = super.getMappingForMethod(method, handlerType);
|
||||
if (requestMappingInfo == null) {
|
||||
if (null == requestMappingInfo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@@ -69,7 +69,7 @@ public class PageDataVO<V> implements Serializable {
|
||||
* @return 分页信息
|
||||
*/
|
||||
public static <T, V> PageDataVO<V> build(IPage<T> page, Class<V> targetClass) {
|
||||
if (page == null) {
|
||||
if (null == page) {
|
||||
return null;
|
||||
}
|
||||
PageDataVO<V> pageDataVO = new PageDataVO<>();
|
||||
@@ -88,7 +88,7 @@ public class PageDataVO<V> implements Serializable {
|
||||
* @return 分页信息
|
||||
*/
|
||||
public static <V> PageDataVO<V> build(IPage<V> page) {
|
||||
if (page == null) {
|
||||
if (null == page) {
|
||||
return null;
|
||||
}
|
||||
PageDataVO<V> pageDataVO = new PageDataVO<>();
|
||||
|
@@ -46,7 +46,7 @@ public class ExceptionUtils {
|
||||
* 异常
|
||||
*/
|
||||
public static void printException(Runnable runnable, Throwable throwable) {
|
||||
if (throwable == null && runnable instanceof Future<?>) {
|
||||
if (null == throwable && runnable instanceof Future<?>) {
|
||||
try {
|
||||
Future<?> future = (Future<?>)runnable;
|
||||
if (future.isDone()) {
|
||||
@@ -60,7 +60,7 @@ public class ExceptionUtils {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
if (throwable != null) {
|
||||
if (null != throwable) {
|
||||
log.error(throwable.getMessage(), throwable);
|
||||
}
|
||||
}
|
||||
@@ -135,9 +135,9 @@ public class ExceptionUtils {
|
||||
public static <T> T exToDefault(ExSupplier<T> exSupplier, T defaultValue, Consumer<Exception> exConsumer) {
|
||||
try {
|
||||
return exSupplier.get();
|
||||
} catch (Exception ex) {
|
||||
if (exConsumer != null) {
|
||||
exConsumer.accept(ex);
|
||||
} catch (Exception e) {
|
||||
if (null != exConsumer) {
|
||||
exConsumer.accept(e);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
@@ -91,7 +91,7 @@ public class IpUtils {
|
||||
}
|
||||
Ip2regionSearcher ip2regionSearcher = SpringUtil.getBean(Ip2regionSearcher.class);
|
||||
IpInfo ipInfo = ip2regionSearcher.memorySearch(ip);
|
||||
if (ipInfo != null) {
|
||||
if (null != ipInfo) {
|
||||
return ipInfo.getAddress();
|
||||
}
|
||||
return null;
|
||||
|
@@ -65,7 +65,7 @@ public class ServletUtils {
|
||||
* @return 浏览器及其版本信息
|
||||
*/
|
||||
public static String getBrowser(HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
if (null == request) {
|
||||
return null;
|
||||
}
|
||||
UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
||||
|
@@ -54,7 +54,7 @@ public class LoginHelper {
|
||||
* 登录用户信息
|
||||
*/
|
||||
public static void login(LoginUser loginUser) {
|
||||
if (loginUser == null) {
|
||||
if (null == loginUser) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class LoginHelper {
|
||||
loginUser.setLocation(IpUtils.getCityInfo(loginUser.getClientIp()));
|
||||
loginUser.setBrowser(ServletUtils.getBrowser(request));
|
||||
LogContext logContext = LogContextHolder.get();
|
||||
loginUser.setLoginTime(logContext != null ? logContext.getCreateTime() : LocalDateTime.now());
|
||||
loginUser.setLoginTime(null != logContext ? logContext.getCreateTime() : LocalDateTime.now());
|
||||
|
||||
// 登录保存用户信息
|
||||
StpUtil.login(loginUser.getId());
|
||||
@@ -79,7 +79,7 @@ public class LoginHelper {
|
||||
*/
|
||||
public static LoginUser getLoginUser() {
|
||||
LoginUser loginUser = (LoginUser)SaHolder.getStorage().get(CacheConsts.LOGIN_USER_KEY);
|
||||
if (loginUser != null) {
|
||||
if (null != loginUser) {
|
||||
return loginUser;
|
||||
}
|
||||
loginUser = (LoginUser)StpUtil.getTokenSession().get(CacheConsts.LOGIN_USER_KEY);
|
||||
|
@@ -60,7 +60,7 @@ public class QueryHelper {
|
||||
public static <Q, R> QueryWrapper<R> build(Q query) {
|
||||
QueryWrapper<R> queryWrapper = new QueryWrapper<>();
|
||||
// 没有查询条件,直接返回
|
||||
if (query == null) {
|
||||
if (null == query) {
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class QueryHelper {
|
||||
field.setAccessible(true);
|
||||
// 没有 @Query,直接返回
|
||||
Query queryAnnotation = field.getAnnotation(Query.class);
|
||||
if (queryAnnotation == null) {
|
||||
if (null == queryAnnotation) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -47,7 +47,7 @@ public class Validator {
|
||||
* 异常类型
|
||||
*/
|
||||
protected static void throwIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
||||
throwIf(obj == null, message, exceptionType);
|
||||
throwIf(null == obj, message, exceptionType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +61,7 @@ public class Validator {
|
||||
* 异常类型
|
||||
*/
|
||||
protected static void throwIfNotNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) {
|
||||
throwIf(obj != null, message, exceptionType);
|
||||
throwIf(null != obj, message, exceptionType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +219,7 @@ public class Validator {
|
||||
*/
|
||||
protected static void throwIf(BooleanSupplier conditionSupplier, String message,
|
||||
Class<? extends RuntimeException> exceptionType) {
|
||||
if (conditionSupplier != null && conditionSupplier.getAsBoolean()) {
|
||||
if (null != conditionSupplier && conditionSupplier.getAsBoolean()) {
|
||||
log.error(message);
|
||||
throw ReflectUtil.newInstance(exceptionType, message);
|
||||
}
|
||||
|
Reference in New Issue
Block a user