style: 优化 == 及 != 表达式格式

1.将 null 或常量值调整到符号左侧
2.将无特殊意义的方法判空写法改为表达式判断写法
This commit is contained in:
Charles7c 2023-08-15 23:31:50 +08:00
parent 94f88bad22
commit 487fa82306
23 changed files with 67 additions and 72 deletions

View File

@ -151,7 +151,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
// 设置排序 // 设置排序
Sort sort = Opt.ofNullable(sortQuery).orElseGet(SortQuery::new).getSort(); Sort sort = Opt.ofNullable(sortQuery).orElseGet(SortQuery::new).getSort();
for (Sort.Order order : sort) { 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); List<T> entityList = baseMapper.selectList(queryWrapper);
return BeanUtil.copyToList(entityList, targetClass); return BeanUtil.copyToList(entityList, targetClass);
@ -168,7 +168,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Long add(C request) { public Long add(C request) {
if (request == null) { if (null == request) {
return 0L; return 0L;
} }
T entity = BeanUtil.copyProperties(request, entityClass); 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) { if (baseObj instanceof BaseVO) {
BaseVO baseVO = (BaseVO)baseObj; BaseVO baseVO = (BaseVO)baseObj;
Long createUser = baseVO.getCreateUser(); Long createUser = baseVO.getCreateUser();
if (createUser == null) { if (null == createUser) {
return; return;
} }
CommonUserService userService = SpringUtil.getBean(CommonUserService.class); CommonUserService userService = SpringUtil.getBean(CommonUserService.class);
@ -240,7 +240,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
this.fill(detailVO); this.fill(detailVO);
Long updateUser = detailVO.getUpdateUser(); Long updateUser = detailVO.getUpdateUser();
if (updateUser == null) { if (null == updateUser) {
return; return;
} }
CommonUserService userService = SpringUtil.getBean(CommonUserService.class); CommonUserService userService = SpringUtil.getBean(CommonUserService.class);

View File

@ -63,7 +63,7 @@ public class SwaggerConfiguration {
@Bean @Bean
public GlobalOpenApiCustomizer orderGlobalOpenApiCustomizer() { public GlobalOpenApiCustomizer orderGlobalOpenApiCustomizer() {
return openApi -> { return openApi -> {
if (openApi.getTags() != null) { if (null != openApi.getTags()) {
openApi.getTags() openApi.getTags()
.forEach(tag -> tag.setExtensions(MapUtil.of("x-order", RandomUtil.randomInt(0, 100)))); .forEach(tag -> tag.setExtensions(MapUtil.of("x-order", RandomUtil.randomInt(0, 100))));
} }

View File

@ -25,7 +25,6 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ClassUtil; import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ObjectUtil;
import top.charles7c.cnadmin.common.base.BaseEnum; import top.charles7c.cnadmin.common.base.BaseEnum;
import top.charles7c.cnadmin.common.constant.StringConsts; import top.charles7c.cnadmin.common.constant.StringConsts;
@ -63,7 +62,7 @@ public class ExcelBaseEnumConverter implements Converter<BaseEnum<Integer, Strin
@Override @Override
public WriteCellData<String> convertToExcelData(BaseEnum<Integer, String> value, public WriteCellData<String> convertToExcelData(BaseEnum<Integer, String> value,
ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
if (ObjectUtil.isNull(value)) { if (null == value) {
return new WriteCellData<>(StringConsts.EMPTY); return new WriteCellData<>(StringConsts.EMPTY);
} }
return new WriteCellData<>(value.getDescription()); return new WriteCellData<>(value.getDescription());

View File

@ -26,7 +26,6 @@ import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.alibaba.excel.metadata.property.ExcelContentProperty;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
/** /**
* Easy Excel 大数值转换器Excel 中对长度超过 15 位的数值输入是有限制的 16 位开始无论录入什么数字均会变为 0因此输入时只能以文本的形式进行录入 * Easy Excel 大数值转换器Excel 中对长度超过 15 位的数值输入是有限制的 16 位开始无论录入什么数字均会变为 0因此输入时只能以文本的形式进行录入
@ -66,7 +65,7 @@ public class ExcelBigNumberConverter implements Converter<Long> {
@Override @Override
public WriteCellData<Object> convertToExcelData(Long value, ExcelContentProperty contentProperty, public WriteCellData<Object> convertToExcelData(Long value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) { GlobalConfiguration globalConfiguration) {
if (ObjectUtil.isNotNull(value)) { if (null != value) {
String str = Long.toString(value); String str = Long.toString(value);
if (str.length() > MAX_LENGTH) { if (str.length() > MAX_LENGTH) {
return new WriteCellData<>(str); return new WriteCellData<>(str);

View File

@ -52,14 +52,14 @@ public class SimpleDeserializersWrapper extends SimpleDeserializers {
public JsonDeserializer<?> findEnumDeserializer(Class<?> type, DeserializationConfig config, public JsonDeserializer<?> findEnumDeserializer(Class<?> type, DeserializationConfig config,
BeanDescription beanDesc) throws JsonMappingException { BeanDescription beanDesc) throws JsonMappingException {
JsonDeserializer<?> deser = super.findEnumDeserializer(type, config, beanDesc); JsonDeserializer<?> deser = super.findEnumDeserializer(type, config, beanDesc);
if (deser != null) { if (null != deser) {
return deser; return deser;
} }
// 重写增强开始查找指定枚举类型的接口的反序列化器例如GenderEnum 枚举类型则是找它的接口 BaseEnum 的反序列化器 // 重写增强开始查找指定枚举类型的接口的反序列化器例如GenderEnum 枚举类型则是找它的接口 BaseEnum 的反序列化器
for (Class<?> typeInterface : type.getInterfaces()) { for (Class<?> typeInterface : type.getInterfaces()) {
deser = this._classMappings.get(new ClassKey(typeInterface)); deser = this._classMappings.get(new ClassKey(typeInterface));
if (deser != null) { if (null != deser) {
return deser; return deser;
} }
} }

View File

@ -21,7 +21,6 @@ import java.util.Collections;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler; 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); String methodName = mappedStatementId.substring(mappedStatementId.lastIndexOf(StringConsts.DOT) + 1);
Method[] methods = clazz.getDeclaredMethods(); Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) { for (Method method : methods) {
DataPermission annotation = method.getAnnotation(DataPermission.class); DataPermission dataPermission = method.getAnnotation(DataPermission.class);
if (ObjectUtils.isNotEmpty(annotation) if (null != dataPermission
&& (method.getName().equals(methodName) || (method.getName() + "_COUNT").equals(methodName))) { && (method.getName().equals(methodName) || (method.getName() + "_COUNT").equals(methodName))) {
// 获取当前登录用户 // 获取当前登录用户
LoginUser loginUser = LoginHelper.getLoginUser(); LoginUser loginUser = LoginHelper.getLoginUser();
if (ObjectUtils.isNotEmpty(loginUser) && !loginUser.isAdmin()) { if (null != loginUser && !loginUser.isAdmin()) {
return buildDataScopeFilter(loginUser, annotation.value(), where); return buildDataScopeFilter(loginUser, dataPermission.value(), where);
} }
} }
} }
@ -134,20 +133,19 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
InExpression inExpression = new InExpression(); InExpression inExpression = new InExpression();
inExpression.setLeftExpression(buildColumn(tableAlias, DEPT_ID)); inExpression.setLeftExpression(buildColumn(tableAlias, DEPT_ID));
inExpression.setRightExpression(subSelect); inExpression.setRightExpression(subSelect);
expression = expression = null != expression ? new OrExpression(expression, inExpression) : inExpression;
ObjectUtils.isNotEmpty(expression) ? new OrExpression(expression, inExpression) : inExpression;
} else if (DataScopeEnum.DEPT.equals(dataScope)) { } else if (DataScopeEnum.DEPT.equals(dataScope)) {
// select t1.* from table as t1 where t1.`dept_id` = xxx; // select t1.* from table as t1 where t1.`dept_id` = xxx;
EqualsTo equalsTo = new EqualsTo(); EqualsTo equalsTo = new EqualsTo();
equalsTo.setLeftExpression(buildColumn(tableAlias, DEPT_ID)); equalsTo.setLeftExpression(buildColumn(tableAlias, DEPT_ID));
equalsTo.setRightExpression(new LongValue(user.getDeptId())); 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)) { } else if (DataScopeEnum.SELF.equals(dataScope)) {
// select t1.* from table as t1 where t1.`create_user` = xxx; // select t1.* from table as t1 where t1.`create_user` = xxx;
EqualsTo equalsTo = new EqualsTo(); EqualsTo equalsTo = new EqualsTo();
equalsTo.setLeftExpression(buildColumn(tableAlias, CREATE_USER)); equalsTo.setLeftExpression(buildColumn(tableAlias, CREATE_USER));
equalsTo.setRightExpression(new LongValue(user.getId())); 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)) { } 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 // select t1.* from table as t1 where t1.`dept_id` in (select `dept_id` from `sys_role_dept` where
// `role_id` = xxx); // `role_id` = xxx);
@ -165,11 +163,10 @@ public class DataPermissionHandlerImpl implements DataPermissionHandler {
InExpression inExpression = new InExpression(); InExpression inExpression = new InExpression();
inExpression.setLeftExpression(buildColumn(tableAlias, DEPT_ID)); inExpression.setLeftExpression(buildColumn(tableAlias, DEPT_ID));
inExpression.setRightExpression(subSelect); inExpression.setRightExpression(subSelect);
expression = expression = null != expression ? new OrExpression(expression, inExpression) : inExpression;
ObjectUtils.isNotEmpty(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;
} }
/** /**

View File

@ -54,7 +54,7 @@ public class MyBatisPlusMetaObjectHandler implements MetaObjectHandler {
@Override @Override
public void insertFill(MetaObject metaObject) { public void insertFill(MetaObject metaObject) {
try { try {
if (ObjectUtil.isNull(metaObject)) { if (null == metaObject) {
return; return;
} }
@ -88,7 +88,7 @@ public class MyBatisPlusMetaObjectHandler implements MetaObjectHandler {
@Override @Override
public void updateFill(MetaObject metaObject) { public void updateFill(MetaObject metaObject) {
try { try {
if (ObjectUtil.isNull(metaObject)) { if (null == metaObject) {
return; return;
} }
@ -124,7 +124,7 @@ public class MyBatisPlusMetaObjectHandler implements MetaObjectHandler {
private void fillFieldValue(MetaObject metaObject, String fieldName, Object fillFieldValue, boolean isOverride) { private void fillFieldValue(MetaObject metaObject, String fieldName, Object fillFieldValue, boolean isOverride) {
if (metaObject.hasSetter(fieldName)) { if (metaObject.hasSetter(fieldName)) {
Object fieldValue = metaObject.getValue(fieldName); Object fieldValue = metaObject.getValue(fieldName);
setFieldValByName(fieldName, fieldValue != null && !isOverride ? fieldValue : fillFieldValue, metaObject); setFieldValByName(fieldName, null != fieldValue && !isOverride ? fieldValue : fillFieldValue, metaObject);
} }
} }
} }

View File

@ -41,7 +41,7 @@ public class CrudRequestMappingHandlerMapping extends RequestMappingHandlerMappi
@Override @Override
protected RequestMappingInfo getMappingForMethod(@NonNull Method method, @NonNull Class<?> handlerType) { protected RequestMappingInfo getMappingForMethod(@NonNull Method method, @NonNull Class<?> handlerType) {
RequestMappingInfo requestMappingInfo = super.getMappingForMethod(method, handlerType); RequestMappingInfo requestMappingInfo = super.getMappingForMethod(method, handlerType);
if (requestMappingInfo == null) { if (null == requestMappingInfo) {
return null; return null;
} }

View File

@ -69,7 +69,7 @@ public class PageDataVO<V> implements Serializable {
* @return 分页信息 * @return 分页信息
*/ */
public static <T, V> PageDataVO<V> build(IPage<T> page, Class<V> targetClass) { public static <T, V> PageDataVO<V> build(IPage<T> page, Class<V> targetClass) {
if (page == null) { if (null == page) {
return null; return null;
} }
PageDataVO<V> pageDataVO = new PageDataVO<>(); PageDataVO<V> pageDataVO = new PageDataVO<>();
@ -88,7 +88,7 @@ public class PageDataVO<V> implements Serializable {
* @return 分页信息 * @return 分页信息
*/ */
public static <V> PageDataVO<V> build(IPage<V> page) { public static <V> PageDataVO<V> build(IPage<V> page) {
if (page == null) { if (null == page) {
return null; return null;
} }
PageDataVO<V> pageDataVO = new PageDataVO<>(); PageDataVO<V> pageDataVO = new PageDataVO<>();

View File

@ -46,7 +46,7 @@ public class ExceptionUtils {
* 异常 * 异常
*/ */
public static void printException(Runnable runnable, Throwable throwable) { public static void printException(Runnable runnable, Throwable throwable) {
if (throwable == null && runnable instanceof Future<?>) { if (null == throwable && runnable instanceof Future<?>) {
try { try {
Future<?> future = (Future<?>)runnable; Future<?> future = (Future<?>)runnable;
if (future.isDone()) { if (future.isDone()) {
@ -60,7 +60,7 @@ public class ExceptionUtils {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }
if (throwable != null) { if (null != throwable) {
log.error(throwable.getMessage(), 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) { public static <T> T exToDefault(ExSupplier<T> exSupplier, T defaultValue, Consumer<Exception> exConsumer) {
try { try {
return exSupplier.get(); return exSupplier.get();
} catch (Exception ex) { } catch (Exception e) {
if (exConsumer != null) { if (null != exConsumer) {
exConsumer.accept(ex); exConsumer.accept(e);
} }
return defaultValue; return defaultValue;
} }

View File

@ -91,7 +91,7 @@ public class IpUtils {
} }
Ip2regionSearcher ip2regionSearcher = SpringUtil.getBean(Ip2regionSearcher.class); Ip2regionSearcher ip2regionSearcher = SpringUtil.getBean(Ip2regionSearcher.class);
IpInfo ipInfo = ip2regionSearcher.memorySearch(ip); IpInfo ipInfo = ip2regionSearcher.memorySearch(ip);
if (ipInfo != null) { if (null != ipInfo) {
return ipInfo.getAddress(); return ipInfo.getAddress();
} }
return null; return null;

View File

@ -65,7 +65,7 @@ public class ServletUtils {
* @return 浏览器及其版本信息 * @return 浏览器及其版本信息
*/ */
public static String getBrowser(HttpServletRequest request) { public static String getBrowser(HttpServletRequest request) {
if (request == null) { if (null == request) {
return null; return null;
} }
UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent")); UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));

View File

@ -54,7 +54,7 @@ public class LoginHelper {
* 登录用户信息 * 登录用户信息
*/ */
public static void login(LoginUser loginUser) { public static void login(LoginUser loginUser) {
if (loginUser == null) { if (null == loginUser) {
return; return;
} }
@ -64,7 +64,7 @@ public class LoginHelper {
loginUser.setLocation(IpUtils.getCityInfo(loginUser.getClientIp())); loginUser.setLocation(IpUtils.getCityInfo(loginUser.getClientIp()));
loginUser.setBrowser(ServletUtils.getBrowser(request)); loginUser.setBrowser(ServletUtils.getBrowser(request));
LogContext logContext = LogContextHolder.get(); LogContext logContext = LogContextHolder.get();
loginUser.setLoginTime(logContext != null ? logContext.getCreateTime() : LocalDateTime.now()); loginUser.setLoginTime(null != logContext ? logContext.getCreateTime() : LocalDateTime.now());
// 登录保存用户信息 // 登录保存用户信息
StpUtil.login(loginUser.getId()); StpUtil.login(loginUser.getId());
@ -79,7 +79,7 @@ public class LoginHelper {
*/ */
public static LoginUser getLoginUser() { public static LoginUser getLoginUser() {
LoginUser loginUser = (LoginUser)SaHolder.getStorage().get(CacheConsts.LOGIN_USER_KEY); LoginUser loginUser = (LoginUser)SaHolder.getStorage().get(CacheConsts.LOGIN_USER_KEY);
if (loginUser != null) { if (null != loginUser) {
return loginUser; return loginUser;
} }
loginUser = (LoginUser)StpUtil.getTokenSession().get(CacheConsts.LOGIN_USER_KEY); loginUser = (LoginUser)StpUtil.getTokenSession().get(CacheConsts.LOGIN_USER_KEY);

View File

@ -60,7 +60,7 @@ public class QueryHelper {
public static <Q, R> QueryWrapper<R> build(Q query) { public static <Q, R> QueryWrapper<R> build(Q query) {
QueryWrapper<R> queryWrapper = new QueryWrapper<>(); QueryWrapper<R> queryWrapper = new QueryWrapper<>();
// 没有查询条件直接返回 // 没有查询条件直接返回
if (query == null) { if (null == query) {
return queryWrapper; return queryWrapper;
} }
@ -90,7 +90,7 @@ public class QueryHelper {
field.setAccessible(true); field.setAccessible(true);
// 没有 @Query直接返回 // 没有 @Query直接返回
Query queryAnnotation = field.getAnnotation(Query.class); Query queryAnnotation = field.getAnnotation(Query.class);
if (queryAnnotation == null) { if (null == queryAnnotation) {
return; return;
} }

View File

@ -47,7 +47,7 @@ public class Validator {
* 异常类型 * 异常类型
*/ */
protected static void throwIfNull(Object obj, String message, Class<? extends RuntimeException> exceptionType) { 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) { 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, protected static void throwIf(BooleanSupplier conditionSupplier, String message,
Class<? extends RuntimeException> exceptionType) { Class<? extends RuntimeException> exceptionType) {
if (conditionSupplier != null && conditionSupplier.getAsBoolean()) { if (null != conditionSupplier && conditionSupplier.getAsBoolean()) {
log.error(message); log.error(message);
throw ReflectUtil.newInstance(exceptionType, message); throw ReflectUtil.newInstance(exceptionType, message);
} }

View File

@ -91,7 +91,7 @@ public class LogInterceptor implements HandlerInterceptor {
@NonNull Object handler, Exception e) { @NonNull Object handler, Exception e) {
// 记录请求耗时及异常信息 // 记录请求耗时及异常信息
LogDO logDO = this.logElapsedTimeAndException(); LogDO logDO = this.logElapsedTimeAndException();
if (logDO == null) { if (null == logDO) {
return; return;
} }
@ -127,7 +127,7 @@ public class LogInterceptor implements HandlerInterceptor {
private LogDO logElapsedTimeAndException() { private LogDO logElapsedTimeAndException() {
LogContext logContext = LogContextHolder.get(); LogContext logContext = LogContextHolder.get();
try { try {
if (logContext != null) { if (null != logContext) {
LogDO logDO = new LogDO(); LogDO logDO = new LogDO();
logDO.setCreateTime(logContext.getCreateTime()); logDO.setCreateTime(logContext.getCreateTime());
logDO logDO
@ -142,7 +142,7 @@ public class LogInterceptor implements HandlerInterceptor {
} }
// 记录异常详情 // 记录异常详情
Exception exception = logContext.getException(); Exception exception = logContext.getException();
if (exception != null) { if (null != exception) {
logDO.setStatus(LogStatusEnum.FAILURE); logDO.setStatus(LogStatusEnum.FAILURE);
logDO.setExceptionDetail(ExceptionUtil.stacktraceToString(exception, -1)); logDO.setExceptionDetail(ExceptionUtil.stacktraceToString(exception, -1));
} }
@ -169,16 +169,16 @@ public class LogInterceptor implements HandlerInterceptor {
// 例如@Tag(name = "部门管理") -> 部门管理 // 例如@Tag(name = "部门管理") -> 部门管理
// 本框架代码规范例如@Tag(name = "部门管理 API") -> 部门管理 // 本框架代码规范例如@Tag(name = "部门管理 API") -> 部门管理
if (classTag != null) { if (null != classTag) {
String name = classTag.name(); String name = classTag.name();
logDO logDO
.setModule(StrUtil.isNotBlank(name) ? name.replace("API", StringConsts.EMPTY).trim() : "请在该接口类上指定所属模块"); .setModule(StrUtil.isNotBlank(name) ? name.replace("API", StringConsts.EMPTY).trim() : "请在该接口类上指定所属模块");
} }
// 例如@Log(module = "部门管理") -> 部门管理 // 例如@Log(module = "部门管理") -> 部门管理
if (classLog != null && StrUtil.isNotBlank(classLog.module())) { if (null != classLog && StrUtil.isNotBlank(classLog.module())) {
logDO.setModule(classLog.module()); logDO.setModule(classLog.module());
} }
if (methodLog != null && StrUtil.isNotBlank(methodLog.module())) { if (null != methodLog && StrUtil.isNotBlank(methodLog.module())) {
logDO.setModule(methodLog.module()); logDO.setModule(methodLog.module());
} }
} }
@ -196,11 +196,11 @@ public class LogInterceptor implements HandlerInterceptor {
Log methodLog = handlerMethod.getMethodAnnotation(Log.class); Log methodLog = handlerMethod.getMethodAnnotation(Log.class);
// 例如@Operation(summary="新增部门") -> 新增部门 // 例如@Operation(summary="新增部门") -> 新增部门
if (methodOperation != null) { if (null != methodOperation) {
logDO.setDescription(StrUtil.blankToDefault(methodOperation.summary(), "请在该接口方法上指定日志描述")); logDO.setDescription(StrUtil.blankToDefault(methodOperation.summary(), "请在该接口方法上指定日志描述"));
} }
// 例如@Log("新增部门") -> 新增部门 // 例如@Log("新增部门") -> 新增部门
if (methodLog != null && StrUtil.isNotBlank(methodLog.value())) { if (null != methodLog && StrUtil.isNotBlank(methodLog.value())) {
logDO.setDescription(methodLog.value()); logDO.setDescription(methodLog.value());
} }
} }
@ -227,7 +227,7 @@ public class LogInterceptor implements HandlerInterceptor {
logDO.setLocation(IpUtils.getCityInfo(logDO.getClientIp())); logDO.setLocation(IpUtils.getCityInfo(logDO.getClientIp()));
logDO.setBrowser(ServletUtils.getBrowser(request)); logDO.setBrowser(ServletUtils.getBrowser(request));
logDO.setCreateUser(ObjectUtil.defaultIfNull(logDO.getCreateUser(), LoginHelper.getUserId())); logDO.setCreateUser(ObjectUtil.defaultIfNull(logDO.getCreateUser(), LoginHelper.getUserId()));
if (logDO.getCreateUser() == null && SysConsts.LOGIN_URI.equals(request.getRequestURI())) { if (null == logDO.getCreateUser() && SysConsts.LOGIN_URI.equals(request.getRequestURI())) {
LoginRequest loginRequest = JSONUtil.toBean(requestBody, LoginRequest.class); LoginRequest loginRequest = JSONUtil.toBean(requestBody, LoginRequest.class);
logDO.setCreateUser( logDO.setCreateUser(
ExceptionUtils.exToNull(() -> userService.getByUsername(loginRequest.getUsername()).getId())); ExceptionUtils.exToNull(() -> userService.getByUsername(loginRequest.getUsername()).getId()));
@ -291,7 +291,7 @@ public class LogInterceptor implements HandlerInterceptor {
private String getRequestBody(HttpServletRequest request) { private String getRequestBody(HttpServletRequest request) {
String requestBody = ""; String requestBody = "";
ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class); ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class);
if (wrapper != null) { if (null != wrapper) {
requestBody = StrUtil.utf8Str(wrapper.getContentAsByteArray()); requestBody = StrUtil.utf8Str(wrapper.getContentAsByteArray());
} }
return requestBody; return requestBody;
@ -308,7 +308,7 @@ public class LogInterceptor implements HandlerInterceptor {
String responseBody = ""; String responseBody = "";
ContentCachingResponseWrapper wrapper = ContentCachingResponseWrapper wrapper =
WebUtils.getNativeResponse(response, ContentCachingResponseWrapper.class); WebUtils.getNativeResponse(response, ContentCachingResponseWrapper.class);
if (wrapper != null) { if (null != wrapper) {
responseBody = StrUtil.utf8Str(wrapper.getContentAsByteArray()); responseBody = StrUtil.utf8Str(wrapper.getContentAsByteArray());
} }
return responseBody; return responseBody;
@ -340,22 +340,22 @@ public class LogInterceptor implements HandlerInterceptor {
Log methodLog = handlerMethod.getMethodAnnotation(Log.class); Log methodLog = handlerMethod.getMethodAnnotation(Log.class);
// 3.1 如果接口方法上既没有 @Log 注解也没有 @Operation 注解则不记录系统日志 // 3.1 如果接口方法上既没有 @Log 注解也没有 @Operation 注解则不记录系统日志
Operation methodOperation = handlerMethod.getMethodAnnotation(Operation.class); Operation methodOperation = handlerMethod.getMethodAnnotation(Operation.class);
if (methodLog == null && methodOperation == null) { if (null == methodLog && null == methodOperation) {
return false; return false;
} }
// 3.2 请求方式不要求记录且接口方法上没有 @Log 注解则不记录系统日志 // 3.2 请求方式不要求记录且接口方法上没有 @Log 注解则不记录系统日志
if (methodLog == null && operationLogProperties.getExcludeMethods().contains(request.getMethod())) { if (null == methodLog && operationLogProperties.getExcludeMethods().contains(request.getMethod())) {
return false; return false;
} }
// 3.3 如果接口被隐藏不记录系统日志 // 3.3 如果接口被隐藏不记录系统日志
if (methodOperation != null && methodOperation.hidden()) { if (null != methodOperation && methodOperation.hidden()) {
return false; return false;
} }
// 3.4 如果接口方法或类上有 @Log 注解但是要求忽略该接口则不记录系统日志 // 3.4 如果接口方法或类上有 @Log 注解但是要求忽略该接口则不记录系统日志
if (methodLog != null && methodLog.ignore()) { if (null != methodLog && methodLog.ignore()) {
return false; return false;
} }
Log classLog = handlerMethod.getBeanType().getDeclaredAnnotation(Log.class); Log classLog = handlerMethod.getBeanType().getDeclaredAnnotation(Log.class);
return classLog == null || !classLog.ignore(); return null == classLog || !classLog.ignore();
} }
} }

View File

@ -83,7 +83,7 @@ public class LogServiceImpl implements LogService {
PageDataVO<OperationLogVO> pageDataVO = PageDataVO.build(page, OperationLogVO.class); PageDataVO<OperationLogVO> pageDataVO = PageDataVO.build(page, OperationLogVO.class);
// 填充数据如果是查询个人操作日志只查询一次用户信息即可 // 填充数据如果是查询个人操作日志只查询一次用户信息即可
if (query.getUid() != null) { if (null != query.getUid()) {
String nickname = ExceptionUtils.exToNull(() -> commonUserService.getNicknameById(query.getUid())); String nickname = ExceptionUtils.exToNull(() -> commonUserService.getNicknameById(query.getUid()));
pageDataVO.getList().forEach(o -> o.setCreateUserString(nickname)); pageDataVO.getList().forEach(o -> o.setCreateUserString(nickname));
} else { } else {
@ -150,7 +150,7 @@ public class LogServiceImpl implements LogService {
*/ */
private void fill(LogVO logVO) { private void fill(LogVO logVO) {
Long createUser = logVO.getCreateUser(); Long createUser = logVO.getCreateUser();
if (createUser == null) { if (null == createUser) {
return; return;
} }
logVO.setCreateUserString(ExceptionUtils.exToNull(() -> commonUserService.getNicknameById(createUser))); logVO.setCreateUserString(ExceptionUtils.exToNull(() -> commonUserService.getNicknameById(createUser)));

View File

@ -97,7 +97,7 @@ public class SaTokenRedisDaoImpl implements SaTokenDao {
@Override @Override
public void setObject(String key, Object object, long timeout) { public void setObject(String key, Object object, long timeout) {
if (timeout == 0 || timeout <= SaTokenDao.NOT_VALUE_EXPIRE) { if (0 == timeout || timeout <= SaTokenDao.NOT_VALUE_EXPIRE) {
return; return;
} }
// 判断是否为永不过期 // 判断是否为永不过期

View File

@ -103,7 +103,7 @@ public class UserVO extends BaseVO {
} }
public String getPhone() { public String getPhone() {
if (phone == null) { if (null == phone) {
return null; return null;
} }
return DesensitizedUtil.mobilePhone(phone); return DesensitizedUtil.mobilePhone(phone);

View File

@ -153,7 +153,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptVO,
*/ */
private boolean checkNameExists(String name, Long parentId, Long id) { private boolean checkNameExists(String name, Long parentId, Long id) {
return baseMapper.lambdaQuery().eq(DeptDO::getName, name).eq(DeptDO::getParentId, parentId) return baseMapper.lambdaQuery().eq(DeptDO::getName, name).eq(DeptDO::getParentId, parentId)
.ne(id != null, DeptDO::getId, id).exists(); .ne(null != id, DeptDO::getId, id).exists();
} }
/** /**

View File

@ -100,6 +100,6 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, MenuDO, MenuVO,
*/ */
private boolean checkNameExists(String name, Long parentId, Long id) { private boolean checkNameExists(String name, Long parentId, Long id) {
return baseMapper.lambdaQuery().eq(MenuDO::getTitle, name).eq(MenuDO::getParentId, parentId) return baseMapper.lambdaQuery().eq(MenuDO::getTitle, name).eq(MenuDO::getParentId, parentId)
.ne(id != null, MenuDO::getId, id).exists(); .ne(null != id, MenuDO::getId, id).exists();
} }
} }

View File

@ -189,7 +189,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleVO,
* @return 是否存在 * @return 是否存在
*/ */
private boolean checkNameExists(String name, Long id) { private boolean checkNameExists(String name, Long id) {
return baseMapper.lambdaQuery().eq(RoleDO::getName, name).ne(id != null, RoleDO::getId, id).exists(); return baseMapper.lambdaQuery().eq(RoleDO::getName, name).ne(null != id, RoleDO::getId, id).exists();
} }
/** /**
@ -202,6 +202,6 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleVO,
* @return 是否存在 * @return 是否存在
*/ */
private boolean checkCodeExists(String code, Long id) { private boolean checkCodeExists(String code, Long id) {
return baseMapper.lambdaQuery().eq(RoleDO::getCode, code).ne(id != null, RoleDO::getId, id).exists(); return baseMapper.lambdaQuery().eq(RoleDO::getCode, code).ne(null != id, RoleDO::getId, id).exists();
} }
} }

View File

@ -175,7 +175,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO,
String avatarPath = localStorageProperties.getPath().getAvatar(); String avatarPath = localStorageProperties.getPath().getAvatar();
File newAvatarFile = FileUtils.upload(avatarFile, avatarPath, false); File newAvatarFile = FileUtils.upload(avatarFile, avatarPath, false);
CheckUtils.throwIfNull(newAvatarFile, "上传头像失败"); CheckUtils.throwIfNull(newAvatarFile, "上传头像失败");
assert newAvatarFile != null; assert null != newAvatarFile;
// 更新用户头像 // 更新用户头像
String newAvatar = newAvatarFile.getName(); String newAvatar = newAvatarFile.getName();
@ -266,7 +266,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO,
* @return 是否存在 * @return 是否存在
*/ */
private boolean checkNameExists(String name, Long id) { private boolean checkNameExists(String name, Long id) {
return baseMapper.lambdaQuery().eq(UserDO::getUsername, name).ne(id != null, UserDO::getId, id).exists(); return baseMapper.lambdaQuery().eq(UserDO::getUsername, name).ne(null != id, UserDO::getId, id).exists();
} }
/** /**
@ -279,7 +279,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO,
* @return 是否存在 * @return 是否存在
*/ */
private boolean checkEmailExists(String email, Long id) { private boolean checkEmailExists(String email, Long id) {
return baseMapper.lambdaQuery().eq(UserDO::getEmail, email).ne(id != null, UserDO::getId, id).exists(); return baseMapper.lambdaQuery().eq(UserDO::getEmail, email).ne(null != id, UserDO::getId, id).exists();
} }
/** /**
@ -292,6 +292,6 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO,
* @return 是否存在 * @return 是否存在
*/ */
private boolean checkPhoneExists(String phone, Long id) { private boolean checkPhoneExists(String phone, Long id) {
return baseMapper.lambdaQuery().eq(UserDO::getPhone, phone).ne(id != null, UserDO::getId, id).exists(); return baseMapper.lambdaQuery().eq(UserDO::getPhone, phone).ne(null != id, UserDO::getId, id).exists();
} }
} }