mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-21 04:57:10 +08:00
build: continew-starter 2.12.2 => 2.13.0
1.引入 continew-starter-validation(从 core 拆分)、sa-token-sign(从 sa-token-core 拆分并调整了部分 API) 2.Starter import 包路径调整 - EasyExcel 替换为 FastExcel:com.alibaba.excel(EasyExcel) => cn.idev.excel(FastExcel) - top.continew.starter.file.excel => top.continew.starter.excel - top.continew.starter.core.validation.constraints => top.continew.starter.validation.constraints - top.continew.starter.core.validation.ValidationUtils、CheckUtils、Validator => top.continew.starter.core.util.validation - cn.dev33.satoken.sign => cn.dev33.satoken.sign.template - top.continew.starter.core.autoconfigure.project => top.continew.starter.core.autoconfigure.application - top.continew.starter.data.core、top.continew.starter.data.mp => top.continew.starter.data - top.continew.starter.data.mp.base.BaseMapper => top.continew.starter.data.mapper.BaseMapper 2.Starter 基础类命名调整 CRUD:AbstractBaseController => AbstractCrudController,BaseService => CrudService,BaseServiceImpl => CrudServiceImpl Core:ProjectProperties(项目配置,project.xxx) => ApplicationProperties(应用配置更为贴切,且变量 application.xx 可以和 Maven 变量显著区分开) 3.groupId 调整:top.continew.starter、top.continew.admin(避免部分童鞋全局替换包名时出现把 starter 也一起替换了!) 4.Admin import 包路径调整:BaseController、BaseDO等 => common.base 5.新增 BaseService、BaseServiceImpl 替代 Starter 原 BaseXxx,方便用户根据项目实际需要重写或新增全局通用接口、方法 6.snail-job server 数据库脚本更新至 v1.5.0 7.Valid 及 Validated 使用梳理(CrudService 支持通过在实现类添加 Validated 注解来实现 Service 层基础校验)
This commit is contained in:
@@ -14,54 +14,74 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.common.controller;
|
||||
package top.continew.admin.common.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.context.model.SaRequest;
|
||||
import cn.dev33.satoken.sign.SaSignTemplate;
|
||||
import cn.dev33.satoken.sign.template.SaSignTemplate;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.annotation.AnnotationUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import top.continew.admin.common.base.service.BaseService;
|
||||
import top.continew.starter.core.constant.StringConstants;
|
||||
import top.continew.starter.extension.crud.annotation.CrudApi;
|
||||
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
|
||||
import top.continew.starter.extension.crud.controller.AbstractBaseController;
|
||||
import top.continew.starter.extension.crud.controller.AbstractCrudController;
|
||||
import top.continew.starter.extension.crud.enums.Api;
|
||||
import top.continew.starter.extension.crud.service.BaseService;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 控制器基类
|
||||
*
|
||||
* <p>
|
||||
* 根据实际项目需要,自行重写 CRUD 接口或增加自定义通用业务接口
|
||||
* </p>
|
||||
*
|
||||
* @param <S> 业务接口
|
||||
* @param <L> 列表类型
|
||||
* @param <D> 详情类型
|
||||
* @param <Q> 查询条件
|
||||
* @param <C> 创建或修改参数类型
|
||||
* @param <Q> 查询条件类型
|
||||
* @param <C> 创建或修改请求参数类型
|
||||
* @author Charles7c
|
||||
* @since 2024/12/6 20:30
|
||||
*/
|
||||
public class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, C> extends AbstractBaseController<S, L, D, Q, C> {
|
||||
public class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, C> extends AbstractCrudController<S, L, D, Q, C> {
|
||||
|
||||
@Override
|
||||
public void preHandle(CrudApi crudApi, Object[] args, Method targetMethod, Class<?> targetClass) throws Exception {
|
||||
// 忽略带 sign 请求权限校验
|
||||
SaRequest saRequest = SaHolder.getRequest();
|
||||
Collection<String> paramNames = saRequest.getParamNames();
|
||||
if (paramNames.stream().anyMatch(SaSignTemplate.sign::equals)) {
|
||||
return;
|
||||
}
|
||||
// 忽略接口类或接口方法上带 @SaIgnore 注解的权限校验
|
||||
if (AnnotationUtil.hasAnnotation(targetMethod, SaIgnore.class) || AnnotationUtil
|
||||
.hasAnnotation(targetClass, SaIgnore.class)) {
|
||||
return;
|
||||
}
|
||||
// 校验权限,例如:创建用户接口(POST /system/user) => 校验 system:user:create 权限
|
||||
CrudRequestMapping crudRequestMapping = targetClass.getDeclaredAnnotation(CrudRequestMapping.class);
|
||||
String path = crudRequestMapping.value();
|
||||
String prefix = String.join(StringConstants.COLON, CharSequenceUtil.splitTrim(path, StringConstants.SLASH));
|
||||
Api api = crudApi.value();
|
||||
String apiName = Api.PAGE.equals(api) || Api.TREE.equals(api) ? Api.LIST.name() : api.name();
|
||||
String apiName = this.getApiName(crudApi.value());
|
||||
StpUtil.checkPermission("%s:%s".formatted(prefix, apiName.toLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 API 名称
|
||||
*
|
||||
* @param api API
|
||||
* @return API 名称
|
||||
*/
|
||||
private String getApiName(Api api) {
|
||||
return switch (api) {
|
||||
case PAGE, TREE, LIST -> Api.LIST.name();
|
||||
case DELETE, BATCH_DELETE -> Api.DELETE.name();
|
||||
default -> api.name();
|
||||
};
|
||||
}
|
||||
}
|
@@ -14,13 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.common.config.mybatis;
|
||||
package top.continew.admin.common.base.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.continew.starter.data.mp.base.BaseMapper;
|
||||
import top.continew.starter.data.mapper.BaseMapper;
|
||||
import top.continew.starter.extension.datapermission.annotation.DataPermission;
|
||||
|
||||
import java.io.Serializable;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.common.model.entity;
|
||||
package top.continew.admin.common.base.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.common.model.entity;
|
||||
package top.continew.admin.common.base.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.common.model.entity;
|
||||
package top.continew.admin.common.base.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.common.model.req;
|
||||
package top.continew.admin.common.base.model.req;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
@@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.common.model.resp;
|
||||
package top.continew.admin.common.base.model.resp;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import cn.crane4j.annotation.condition.ConditionOnPropertyNotNull;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.common.model.resp;
|
||||
package top.continew.admin.common.base.model.resp;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.continew.admin.common.base.service;
|
||||
|
||||
import top.continew.starter.extension.crud.service.CrudService;
|
||||
|
||||
/**
|
||||
* 业务接口基类
|
||||
*
|
||||
* <p>
|
||||
* 根据实际项目需要,自行重写 CRUD 接口或增加自定义通用业务方法
|
||||
* </p>
|
||||
*
|
||||
* @param <L> 列表类型
|
||||
* @param <D> 详情类型
|
||||
* @param <Q> 查询条件类型
|
||||
* @param <C> 创建或修改请求参数类型
|
||||
* @author Charles7c
|
||||
* @since 2024/12/6 20:30
|
||||
*/
|
||||
public interface BaseService<L, D, Q, C> extends CrudService<L, D, Q, C> {
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.continew.admin.common.base.service;
|
||||
|
||||
import top.continew.starter.data.mapper.BaseMapper;
|
||||
import top.continew.starter.extension.crud.model.entity.BaseIdDO;
|
||||
import top.continew.starter.extension.crud.service.CrudServiceImpl;
|
||||
|
||||
/**
|
||||
* 业务实现基类
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* 根据实际项目需要,自行重写 CRUD 接口或增加自定义通用业务方法实现
|
||||
* </p>
|
||||
*
|
||||
* @param <M> Mapper 接口
|
||||
* @param <T> 实体类型
|
||||
* @param <L> 列表类型
|
||||
* @param <D> 详情类型
|
||||
* @param <Q> 查询条件类型
|
||||
* @param <C> 创建或修改请求参数类型
|
||||
* @author Charles7c
|
||||
* @since 2024/12/6 20:30
|
||||
*/
|
||||
public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdDO, L, D, Q, C> extends CrudServiceImpl<M, T, L, D, Q, C> implements BaseService<L, D, Q, C> {
|
||||
}
|
@@ -19,11 +19,11 @@ package top.continew.admin.common.config.excel;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.excel.converters.Converter;
|
||||
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.idev.excel.converters.Converter;
|
||||
import cn.idev.excel.metadata.GlobalConfiguration;
|
||||
import cn.idev.excel.metadata.data.ReadCellData;
|
||||
import cn.idev.excel.metadata.data.WriteCellData;
|
||||
import cn.idev.excel.metadata.property.ExcelContentProperty;
|
||||
import top.continew.admin.common.service.CommonDictItemService;
|
||||
import top.continew.starter.core.constant.StringConstants;
|
||||
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
|
||||
|
@@ -20,7 +20,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import top.continew.admin.common.context.UserContextHolder;
|
||||
import top.continew.admin.common.model.entity.BaseDO;
|
||||
import top.continew.admin.common.base.model.entity.BaseDO;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
@@ -22,7 +22,7 @@ import cn.hutool.crypto.asymmetric.KeyType;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import top.continew.admin.common.config.properties.RsaProperties;
|
||||
import top.continew.starter.core.exception.BusinessException;
|
||||
import top.continew.starter.core.validation.ValidationUtils;
|
||||
import top.continew.starter.core.util.validation.ValidationUtils;
|
||||
import top.continew.starter.security.crypto.autoconfigure.CryptoProperties;
|
||||
import top.continew.starter.security.crypto.encryptor.AesEncryptor;
|
||||
import top.continew.starter.security.crypto.encryptor.IEncryptor;
|
||||
|
Reference in New Issue
Block a user