mirror of
				https://github.com/continew-org/continew-starter.git
				synced 2025-10-31 22:57:19 +08:00 
			
		
		
		
	refactor(extension/crud): AbstractBaseController => AbstractCrudController,BaseService => CrudService
This commit is contained in:
		| @@ -1,112 +0,0 @@ | |||||||
| /* |  | ||||||
|  * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. |  | ||||||
|  * <p> |  | ||||||
|  * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; |  | ||||||
|  * you may not use this file except in compliance with the License. |  | ||||||
|  * You may obtain a copy of the License at |  | ||||||
|  * <p> |  | ||||||
|  * http://www.gnu.org/licenses/lgpl.html |  | ||||||
|  * <p> |  | ||||||
|  * 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.starter.data.mp.base; |  | ||||||
|  |  | ||||||
| import cn.hutool.core.util.ClassUtil; |  | ||||||
| import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |  | ||||||
| import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; |  | ||||||
| import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |  | ||||||
| import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper; |  | ||||||
| import com.baomidou.mybatisplus.extension.toolkit.ChainWrappers; |  | ||||||
| import com.baomidou.mybatisplus.extension.toolkit.Db; |  | ||||||
|  |  | ||||||
| import java.util.Collection; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Mapper 基类 |  | ||||||
|  * |  | ||||||
|  * @param <T> 实体类 |  | ||||||
|  * @author Charles7c |  | ||||||
|  * @since 1.0.0 |  | ||||||
|  */ |  | ||||||
| public interface BaseMapper<T> extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T> { |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 批量插入记录 |  | ||||||
|      * |  | ||||||
|      * @param entityList 实体列表 |  | ||||||
|      * @return 是否成功 |  | ||||||
|      */ |  | ||||||
|     default boolean insertBatch(Collection<T> entityList) { |  | ||||||
|         return Db.saveBatch(entityList); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 批量更新记录 |  | ||||||
|      * |  | ||||||
|      * @param entityList 实体列表 |  | ||||||
|      * @return 是否成功 |  | ||||||
|      */ |  | ||||||
|     default boolean updateBatchById(Collection<T> entityList) { |  | ||||||
|         return Db.updateBatchById(entityList); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 链式查询 |  | ||||||
|      * |  | ||||||
|      * @return QueryWrapper 的包装类 |  | ||||||
|      */ |  | ||||||
|     default QueryChainWrapper<T> query() { |  | ||||||
|         return ChainWrappers.queryChain(this); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 链式查询(lambda 式) |  | ||||||
|      * |  | ||||||
|      * @return LambdaQueryWrapper 的包装类 |  | ||||||
|      */ |  | ||||||
|     default LambdaQueryChainWrapper<T> lambdaQuery() { |  | ||||||
|         return ChainWrappers.lambdaQueryChain(this, this.currentEntityClass()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 链式查询(lambda 式) |  | ||||||
|      * |  | ||||||
|      * @param entity 实体对象 |  | ||||||
|      * @return LambdaQueryWrapper 的包装类 |  | ||||||
|      */ |  | ||||||
|     default LambdaQueryChainWrapper<T> lambdaQuery(T entity) { |  | ||||||
|         return ChainWrappers.lambdaQueryChain(this, entity); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 链式更改 |  | ||||||
|      * |  | ||||||
|      * @return UpdateWrapper 的包装类 |  | ||||||
|      */ |  | ||||||
|     default UpdateChainWrapper<T> update() { |  | ||||||
|         return ChainWrappers.updateChain(this); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 链式更改(lambda 式) |  | ||||||
|      * |  | ||||||
|      * @return LambdaUpdateWrapper 的包装类 |  | ||||||
|      */ |  | ||||||
|     default LambdaUpdateChainWrapper<T> lambdaUpdate() { |  | ||||||
|         return ChainWrappers.lambdaUpdateChain(this); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 获取实体类 Class 对象 |  | ||||||
|      * |  | ||||||
|      * @return 实体类 Class 对象 |  | ||||||
|      */ |  | ||||||
|     default Class<T> currentEntityClass() { |  | ||||||
|         return (Class<T>)ClassUtil.getTypeArgument(this.getClass(), 0); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -16,6 +16,8 @@ | |||||||
|  |  | ||||||
| package top.continew.starter.data.mp.service; | package top.continew.starter.data.mp.service; | ||||||
|  |  | ||||||
|  | import com.baomidou.mybatisplus.extension.repository.IRepository; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * 通用业务接口 |  * 通用业务接口 | ||||||
|  * |  * | ||||||
| @@ -23,4 +25,4 @@ package top.continew.starter.data.mp.service; | |||||||
|  * @author Charles7c |  * @author Charles7c | ||||||
|  * @since 1.2.0 |  * @since 1.2.0 | ||||||
|  */ |  */ | ||||||
| public interface IService<T> extends com.baomidou.mybatisplus.extension.service.IService<T> {} | public interface IService<T> extends IRepository<T> {} | ||||||
|   | |||||||
| @@ -17,9 +17,10 @@ | |||||||
| package top.continew.starter.data.mp.service.impl; | package top.continew.starter.data.mp.service.impl; | ||||||
|  |  | ||||||
| import cn.hutool.core.util.ClassUtil; | import cn.hutool.core.util.ClassUtil; | ||||||
|  | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||||
|  | import com.baomidou.mybatisplus.extension.repository.CrudRepository; | ||||||
| import top.continew.starter.core.util.ReflectUtils; | import top.continew.starter.core.util.ReflectUtils; | ||||||
| import top.continew.starter.core.validation.CheckUtils; | import top.continew.starter.core.validation.CheckUtils; | ||||||
| import top.continew.starter.data.mp.base.BaseMapper; |  | ||||||
| import top.continew.starter.data.mp.service.IService; | import top.continew.starter.data.mp.service.IService; | ||||||
|  |  | ||||||
| import java.io.Serializable; | import java.io.Serializable; | ||||||
| @@ -34,7 +35,7 @@ import java.util.List; | |||||||
|  * @author Charles7c |  * @author Charles7c | ||||||
|  * @since 1.5.0 |  * @since 1.5.0 | ||||||
|  */ |  */ | ||||||
| public class ServiceImpl<M extends BaseMapper<T>, T> extends com.baomidou.mybatisplus.extension.service.impl.ServiceImpl<M, T> implements IService<T> { | public class ServiceImpl<M extends BaseMapper<T>, T> extends CrudRepository<M, T> implements IService<T> { | ||||||
|  |  | ||||||
|     private List<Field> entityFields; |     private List<Field> entityFields; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,7 +23,7 @@ import org.springframework.core.BridgeMethodResolver; | |||||||
| import org.springframework.core.annotation.AnnotatedElementUtils; | import org.springframework.core.annotation.AnnotatedElementUtils; | ||||||
| import org.springframework.util.ClassUtils; | import org.springframework.util.ClassUtils; | ||||||
| import top.continew.starter.extension.crud.annotation.CrudApi; | import top.continew.starter.extension.crud.annotation.CrudApi; | ||||||
| import top.continew.starter.extension.crud.controller.AbstractBaseController; | import top.continew.starter.extension.crud.controller.AbstractCrudController; | ||||||
|  |  | ||||||
| import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||||
| import java.util.Objects; | import java.util.Objects; | ||||||
| @@ -46,8 +46,8 @@ public class CrudApiAnnotationInterceptor implements MethodInterceptor { | |||||||
|         // 获取 @CrudApi 注解 |         // 获取 @CrudApi 注解 | ||||||
|         CrudApi crudApi = AnnotatedElementUtils.findMergedAnnotation(targetMethod, CrudApi.class); |         CrudApi crudApi = AnnotatedElementUtils.findMergedAnnotation(targetMethod, CrudApi.class); | ||||||
|         // 执行处理 |         // 执行处理 | ||||||
|         AbstractBaseController controller = (AbstractBaseController)invocation.getThis(); |         AbstractCrudController crudController = (AbstractCrudController)invocation.getThis(); | ||||||
|         controller.preHandle(crudApi, invocation.getArguments(), targetMethod, targetClass); |         crudController.preHandle(crudApi, invocation.getArguments(), targetMethod, targetClass); | ||||||
|         return invocation.proceed(); |         return invocation.proceed(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -33,23 +33,23 @@ import top.continew.starter.extension.crud.model.query.SortQuery; | |||||||
| import top.continew.starter.extension.crud.model.req.IdsReq; | import top.continew.starter.extension.crud.model.req.IdsReq; | ||||||
| import top.continew.starter.extension.crud.model.resp.IdResp; | import top.continew.starter.extension.crud.model.resp.IdResp; | ||||||
| import top.continew.starter.extension.crud.model.resp.BasePageResp; | import top.continew.starter.extension.crud.model.resp.BasePageResp; | ||||||
| import top.continew.starter.extension.crud.service.BaseService; | import top.continew.starter.extension.crud.service.CrudService; | ||||||
| import top.continew.starter.extension.crud.validation.CrudValidationGroup; | import top.continew.starter.extension.crud.validation.CrudValidationGroup; | ||||||
| 
 | 
 | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * 控制器抽象基类 |  * CRUD 控制器抽象基类 | ||||||
|  * |  * | ||||||
|  * @param <S> 业务接口 |  * @param <S> 业务接口 | ||||||
|  * @param <L> 列表类型 |  * @param <L> 列表类型 | ||||||
|  * @param <D> 详情类型 |  * @param <D> 详情类型 | ||||||
|  * @param <Q> 查询条件 |  * @param <Q> 查询条件类型 | ||||||
|  * @param <C> 创建或修改请求参数类型 |  * @param <C> 创建或修改请求参数类型 | ||||||
|  * @author Charles7c |  * @author Charles7c | ||||||
|  * @since 1.0.0 |  * @since 1.0.0 | ||||||
|  */ |  */ | ||||||
| public abstract class AbstractBaseController<S extends BaseService<L, D, Q, C>, L, D, Q, C> implements CrudApiHandler { | public abstract class AbstractCrudController<S extends CrudService<L, D, Q, C>, L, D, Q, C> implements CrudApiHandler { | ||||||
| 
 | 
 | ||||||
|     @Autowired |     @Autowired | ||||||
|     protected S baseService; |     protected S baseService; | ||||||
| @@ -26,16 +26,16 @@ import top.continew.starter.extension.crud.model.resp.LabelValueResp; | |||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * 业务接口基类 |  * CRUD 业务接口 | ||||||
|  * |  * | ||||||
|  * @param <L> 列表类型 |  * @param <L> 列表类型 | ||||||
|  * @param <D> 详情类型 |  * @param <D> 详情类型 | ||||||
|  * @param <Q> 查询条件 |  * @param <Q> 查询条件类型 | ||||||
|  * @param <C> 创建或修改请求参数类型 |  * @param <C> 创建或修改请求参数类型 | ||||||
|  * @author Charles7c |  * @author Charles7c | ||||||
|  * @since 1.0.0 |  * @since 1.0.0 | ||||||
|  */ |  */ | ||||||
| public interface BaseService<L, D, Q, C> { | public interface CrudService<L, D, Q, C> { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * 分页查询列表 |      * 分页查询列表 | ||||||
| @@ -52,18 +52,18 @@ import java.util.List; | |||||||
| import java.util.Optional; | import java.util.Optional; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * 业务实现基类 |  * CRUD 业务实现基类 | ||||||
|  * |  * | ||||||
|  * @param <M> Mapper 接口 |  * @param <M> Mapper 接口 | ||||||
|  * @param <T> 实体类型 |  * @param <T> 实体类型 | ||||||
|  * @param <L> 列表类型 |  * @param <L> 列表类型 | ||||||
|  * @param <D> 详情类型 |  * @param <D> 详情类型 | ||||||
|  * @param <Q> 查询条件 |  * @param <Q> 查询条件类型 | ||||||
|  * @param <C> 创建或修改请求参数类型 |  * @param <C> 创建或修改请求参数类型 | ||||||
|  * @author Charles7c |  * @author Charles7c | ||||||
|  * @since 1.0.0 |  * @since 1.0.0 | ||||||
|  */ |  */ | ||||||
| public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdDO, L, D, Q, C> extends ServiceImpl<M, T> implements BaseService<L, D, Q, C> { | public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseIdDO, L, D, Q, C> extends ServiceImpl<M, T> implements CrudService<L, D, Q, C> { | ||||||
| 
 | 
 | ||||||
|     protected final Class<L> listClass = this.currentListClass(); |     protected final Class<L> listClass = this.currentListClass(); | ||||||
|     protected final Class<D> detailClass = this.currentDetailClass(); |     protected final Class<D> detailClass = this.currentDetailClass(); | ||||||
| @@ -29,6 +29,7 @@ import cn.hutool.core.text.CharSequenceUtil; | |||||||
| import cn.hutool.core.util.ReflectUtil; | import cn.hutool.core.util.ReflectUtil; | ||||||
| import cn.hutool.extra.spring.SpringUtil; | import cn.hutool.extra.spring.SpringUtil; | ||||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||||||
|  | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||||
| import com.baomidou.mybatisplus.core.metadata.IPage; | import com.baomidou.mybatisplus.core.metadata.IPage; | ||||||
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||||||
| import jakarta.servlet.http.HttpServletResponse; | import jakarta.servlet.http.HttpServletResponse; | ||||||
| @@ -39,11 +40,9 @@ import top.continew.starter.core.util.ClassUtils; | |||||||
| import top.continew.starter.core.util.ReflectUtils; | import top.continew.starter.core.util.ReflectUtils; | ||||||
| import top.continew.starter.core.validation.CheckUtils; | import top.continew.starter.core.validation.CheckUtils; | ||||||
| import top.continew.starter.core.validation.ValidationUtils; | import top.continew.starter.core.validation.ValidationUtils; | ||||||
| import top.continew.starter.data.mp.base.BaseMapper; |  | ||||||
| import top.continew.starter.data.mp.service.impl.ServiceImpl; | import top.continew.starter.data.mp.service.impl.ServiceImpl; | ||||||
| import top.continew.starter.data.mp.util.QueryWrapperHelper; | import top.continew.starter.data.mp.util.QueryWrapperHelper; | ||||||
| import top.continew.starter.extension.crud.annotation.DictModel; | import top.continew.starter.extension.crud.annotation.DictModel; | ||||||
| import top.continew.starter.extension.crud.annotation.DictModel; |  | ||||||
| import top.continew.starter.extension.crud.annotation.TreeField; | import top.continew.starter.extension.crud.annotation.TreeField; | ||||||
| import top.continew.starter.extension.crud.autoconfigure.CrudProperties; | import top.continew.starter.extension.crud.autoconfigure.CrudProperties; | ||||||
| import top.continew.starter.extension.crud.autoconfigure.CrudTreeProperties; | import top.continew.starter.extension.crud.autoconfigure.CrudTreeProperties; | ||||||
| @@ -58,18 +57,18 @@ import java.lang.reflect.Field; | |||||||
| import java.util.*; | import java.util.*; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * 业务实现基类 |  * CRUD 业务实现基类 | ||||||
|  * |  * | ||||||
|  * @param <M> Mapper 接口 |  * @param <M> Mapper 接口 | ||||||
|  * @param <T> 实体类型 |  * @param <T> 实体类型 | ||||||
|  * @param <L> 列表类型 |  * @param <L> 列表类型 | ||||||
|  * @param <D> 详情类型 |  * @param <D> 详情类型 | ||||||
|  * @param <Q> 查询条件 |  * @param <Q> 查询条件类型 | ||||||
|  * @param <C> 创建或修改参数类型 |  * @param <C> 创建或修改参数类型 | ||||||
|  * @author Charles7c |  * @author Charles7c | ||||||
|  * @since 1.0.0 |  * @since 1.0.0 | ||||||
|  */ |  */ | ||||||
| public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdDO, L, D, Q, C> extends ServiceImpl<M, T> implements BaseService<L, D, Q, C> { | public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseIdDO, L, D, Q, C> extends ServiceImpl<M, T> implements CrudService<L, D, Q, C> { | ||||||
| 
 | 
 | ||||||
|     private Class<L> listClass; |     private Class<L> listClass; | ||||||
|     private Class<D> detailClass; |     private Class<D> detailClass; | ||||||
		Reference in New Issue
	
	Block a user