style: 优化部分代码格式

1.部分方法返回调整为内联
2.已抽取 ExcelBaseEnumConverter 至 ContiNew Starter CRUD 模块
3.移除无用类 UpdateStatusReq
This commit is contained in:
Charles7c 2024-01-13 16:13:12 +08:00
parent d5984087a3
commit 706e488e84
14 changed files with 43 additions and 213 deletions

View File

@ -1,93 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.charles7c.continew.admin.common.config.easyexcel;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
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.ClassUtil;
import top.charles7c.continew.starter.core.constant.StringConstants;
import top.charles7c.continew.starter.data.mybatis.plus.base.IBaseEnum;
/**
* Easy Excel 枚举接口转换器
*
* @see IBaseEnum
* @author Charles7c
* @since 2023/2/5 19:29
*/
public class ExcelBaseEnumConverter implements Converter<IBaseEnum<Integer>> {
@Override
public Class<IBaseEnum> supportJavaTypeKey() {
return IBaseEnum.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
/**
* 转换为 Java 数据读取 Excel
*/
@Override
public IBaseEnum convertToJavaData(ReadCellData<?> cellData,
ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return this.getEnum(IBaseEnum.class, Convert.toStr(cellData.getData()));
}
/**
* 转换为 Excel 数据写入 Excel
*/
@Override
public WriteCellData<String> convertToExcelData(IBaseEnum<Integer> value,
ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (null == value) {
return new WriteCellData<>(StringConstants.EMPTY);
}
return new WriteCellData<>(value.getDescription());
}
/**
* 通过 value 获取枚举对象获取不到时为 {@code null}
*
* @param enumType 枚举类型
* @param description 描述
* @return 对应枚举 获取不到时为 {@code null}
*/
private IBaseEnum<Integer> getEnum(Class<?> enumType, String description) {
Object[] enumConstants = enumType.getEnumConstants();
for (Object enumConstant : enumConstants) {
if (ClassUtil.isAssignable(IBaseEnum.class, enumType)) {
IBaseEnum<Integer> baseEnum = (IBaseEnum<Integer>)enumConstant;
if (baseEnum.getDescription().equals(description)) {
return baseEnum;
}
}
}
return null;
}
}

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.charles7c.continew.admin.common.model.req;
import java.io.Serial;
import java.io.Serializable;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
/**
* 修改状态信息
*
* @author Charles7c
* @since 2023/1/24 19:51
*/
@Data
@Schema(description = "修改状态信息")
public class UpdateStatusReq implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 状态
*/
@Schema(description = "状态1启用2禁用", type = "Integer", allowableValues = {"1", "2"}, example = "1")
@NotNull(message = "状态非法")
private DisEnableStatusEnum status;
}

View File

@ -16,19 +16,16 @@
package top.charles7c.continew.admin.system.model.resp;
import java.io.Serial;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import top.charles7c.continew.admin.common.config.easyexcel.ExcelBaseEnumConverter;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
import top.charles7c.continew.starter.extension.crud.base.BaseDetailResp;
import top.charles7c.continew.starter.extension.crud.converter.ExcelBaseEnumConverter;
import java.io.Serial;
/**
* 部门详情信息

View File

@ -25,7 +25,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import top.charles7c.continew.admin.common.config.easyexcel.ExcelBaseEnumConverter;
import top.charles7c.continew.starter.extension.crud.converter.ExcelBaseEnumConverter;
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
import top.charles7c.continew.admin.common.enums.MenuTypeEnum;
import top.charles7c.continew.starter.extension.crud.annotation.TreeField;

View File

@ -26,7 +26,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import top.charles7c.continew.admin.common.config.easyexcel.ExcelBaseEnumConverter;
import top.charles7c.continew.starter.extension.crud.converter.ExcelBaseEnumConverter;
import top.charles7c.continew.admin.common.enums.DataScopeEnum;
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
import top.charles7c.continew.starter.extension.crud.base.BaseDetailResp;

View File

@ -25,7 +25,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import top.charles7c.continew.admin.common.config.easyexcel.ExcelBaseEnumConverter;
import top.charles7c.continew.starter.extension.crud.converter.ExcelBaseEnumConverter;
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
import top.charles7c.continew.admin.system.enums.StorageTypeEnum;
import top.charles7c.continew.starter.extension.crud.base.BaseDetailResp;

View File

@ -28,7 +28,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import top.charles7c.continew.admin.common.config.easyexcel.ExcelBaseEnumConverter;
import top.charles7c.continew.starter.extension.crud.converter.ExcelBaseEnumConverter;
import top.charles7c.continew.admin.common.enums.DisEnableStatusEnum;
import top.charles7c.continew.admin.common.enums.GenderEnum;
import top.charles7c.continew.admin.common.util.helper.LoginHelper;

View File

@ -16,22 +16,16 @@
package top.charles7c.continew.admin.webapi.auth;
import java.util.List;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import top.charles7c.continew.admin.auth.model.req.AccountLoginReq;
import top.charles7c.continew.admin.auth.model.req.EmailLoginReq;
import top.charles7c.continew.admin.auth.model.req.PhoneLoginReq;
@ -51,6 +45,8 @@ import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
import top.charles7c.continew.starter.extension.crud.model.resp.R;
import top.charles7c.continew.starter.log.common.annotation.Log;
import java.util.List;
/**
* 认证 API
*
@ -136,8 +132,6 @@ public class AuthController {
@Operation(summary = "获取路由信息", description = "获取登录用户的路由信息")
@GetMapping("/route")
public R<List<RouteResp>> listRoute() {
Long userId = LoginHelper.getUserId();
List<RouteResp> routeTree = loginService.buildRouteTree(userId);
return R.ok(routeTree);
return R.ok(loginService.buildRouteTree(LoginHelper.getUserId()));
}
}

View File

@ -16,39 +16,27 @@
package top.charles7c.continew.admin.webapi.common;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.x.file.storage.core.FileInfo;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.StrUtil;
import top.charles7c.continew.admin.common.constant.CacheConstants;
import top.charles7c.continew.admin.common.model.resp.LabelValueResp;
import top.charles7c.continew.admin.system.model.query.DeptQuery;
import top.charles7c.continew.admin.system.model.query.MenuQuery;
import top.charles7c.continew.admin.system.model.query.OptionQuery;
import top.charles7c.continew.admin.system.model.query.RoleQuery;
import top.charles7c.continew.admin.system.model.resp.RoleResp;
import top.charles7c.continew.admin.system.service.*;
import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties;
import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
@ -57,6 +45,12 @@ import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
import top.charles7c.continew.starter.extension.crud.model.resp.R;
import top.charles7c.continew.starter.log.common.annotation.Log;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 公共 API
*
@ -91,23 +85,19 @@ public class CommonController {
@Operation(summary = "查询部门树", description = "查询树结构的部门列表")
@GetMapping("/tree/dept")
public R<List<Tree<Long>>> listDeptTree(DeptQuery query, SortQuery sortQuery) {
List<Tree<Long>> treeList = deptService.tree(query, sortQuery, true);
return R.ok(treeList);
return R.ok(deptService.tree(query, sortQuery, true));
}
@Operation(summary = "查询菜单树", description = "查询树结构的菜单列表")
@GetMapping("/tree/menu")
public R<List<Tree<Long>>> listMenuTree(MenuQuery query, SortQuery sortQuery) {
List<Tree<Long>> treeList = menuService.tree(query, sortQuery, true);
return R.ok(treeList);
return R.ok(menuService.tree(query, sortQuery, true));
}
@Operation(summary = "查询角色字典", description = "查询角色字典列表")
@GetMapping("/dict/role")
public R<List<LabelValueResp<Long>>> listRoleDict(RoleQuery query, SortQuery sortQuery) {
List<RoleResp> list = roleService.list(query, sortQuery);
List<LabelValueResp<Long>> labelValueList = roleService.buildDict(list);
return R.ok(labelValueList);
return R.ok(roleService.buildDict(roleService.list(query, sortQuery)));
}
@Operation(summary = "查询字典", description = "查询字典列表")

View File

@ -60,24 +60,21 @@ public class LogController {
@Operation(summary = "分页查询登录日志列表", description = "分页查询登录日志列表")
@GetMapping("/login")
public R<PageResp<LoginLogResp>> page(LoginLogQuery query, @Validated PageQuery pageQuery) {
PageResp<LoginLogResp> pageData = logService.page(query, pageQuery);
return R.ok(pageData);
return R.ok(logService.page(query, pageQuery));
}
@Log(module = "操作日志")
@Operation(summary = "分页查询操作日志列表", description = "分页查询操作日志列表")
@GetMapping("/operation")
public R<PageResp<OperationLogResp>> page(OperationLogQuery query, @Validated PageQuery pageQuery) {
PageResp<OperationLogResp> pageData = logService.page(query, pageQuery);
return R.ok(pageData);
return R.ok(logService.page(query, pageQuery));
}
@Log(module = "系统日志")
@Operation(summary = "分页查询系统日志列表", description = "分页查询系统日志列表")
@GetMapping("/system")
public R<PageResp<SystemLogResp>> page(SystemLogQuery query, @Validated PageQuery pageQuery) {
PageResp<SystemLogResp> pageData = logService.page(query, pageQuery);
return R.ok(pageData);
return R.ok(logService.page(query, pageQuery));
}
@Log(module = "系统日志")
@ -85,7 +82,6 @@ public class LogController {
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@GetMapping("/system/{id}")
public R<SystemLogDetailResp> get(@PathVariable Long id) {
SystemLogDetailResp detail = logService.get(id);
return R.ok(detail);
return R.ok(logService.get(id));
}
}

View File

@ -55,8 +55,7 @@ public class OnlineUserController {
@SaCheckPermission("monitor:online:user:list")
@GetMapping
public R<PageResp<OnlineUserResp>> page(OnlineUserQuery query, @Validated PageQuery pageQuery) {
PageResp<OnlineUserResp> pageData = onlineUserService.page(query, pageQuery);
return R.ok(pageData);
return R.ok(onlineUserService.page(query, pageQuery));
}
@Operation(summary = "强退在线用户", description = "强退在线用户")

View File

@ -16,18 +16,13 @@
package top.charles7c.continew.admin.webapi.system;
import java.util.List;
import lombok.RequiredArgsConstructor;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.charles7c.continew.admin.common.util.helper.LoginHelper;
import top.charles7c.continew.admin.system.model.query.MessageQuery;
import top.charles7c.continew.admin.system.model.resp.MessageResp;
@ -39,6 +34,8 @@ import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;
import top.charles7c.continew.starter.extension.crud.model.resp.R;
import top.charles7c.continew.starter.log.common.annotation.Log;
import java.util.List;
/**
* 消息管理 API
*
@ -58,8 +55,7 @@ public class MessageController {
@GetMapping
public R<PageResp<MessageResp>> page(MessageQuery query, @Validated PageQuery pageQuery) {
query.setUserId(LoginHelper.getUserId());
PageResp<MessageResp> pageData = baseService.page(query, pageQuery);
return R.ok(pageData);
return R.ok(baseService.page(query, pageQuery));
}
@Operation(summary = "删除数据", description = "删除数据")

View File

@ -5,5 +5,5 @@
\____|\___/ |_| |_| \__||_||_| \_| \___| \_/\_/ /_/ \_\\__,_||_| |_| |_||_||_| |_|
:: ${project.name} :: v${project.version}
:: ContiNew Starter :: v1.1.0-SNAPSHOT
:: ContiNew Starter :: v1.2.0-SNAPSHOT
:: Spring Boot :: v${spring-boot.version}

View File

@ -87,12 +87,12 @@ spring.cache:
--- ### 验证码配置
continew-starter.captcha:
# 行为验证码
## 行为验证码
behavior:
enabled: true
cache-type: REDIS
water-mark: ${project.app-name}
# 图形验证码
## 图形验证码
graphic:
enabled: true
# 类型