mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-11-14 03:01:38 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 24fda9a84e | |||
| 0f43e1cff7 | |||
| 171040b674 | |||
| ab4a72e0ff | |||
| ed15115e44 | |||
| 63d9e80240 | |||
| 98261b96da | |||
| a54294df6e | |||
| 12bdf3e44a | |||
| 36ce07b600 | |||
| 244a4db17c |
34
CHANGELOG.md
34
CHANGELOG.md
@@ -1,3 +1,37 @@
|
|||||||
|
## [v1.5.1](https://github.com/Charles7c/continew-starter/compare/v1.5.0...v1.5.1) (2024-03-23)
|
||||||
|
|
||||||
|
### ✨ 新特性
|
||||||
|
|
||||||
|
- 【web】FileUploadUtils 新增文件下载方法 ([171040b](https://github.com/Charles7c/continew-starter/commit/171040b674ae18dd6560f1501f7c0d47a1f4b8ba))
|
||||||
|
|
||||||
|
### 🐛 问题修复
|
||||||
|
|
||||||
|
- 【api-doc】修复接口级鉴权配置不生效的问题 ([ab4a72e](https://github.com/Charles7c/continew-starter/commit/ab4a72e0fffe20b492c2250cc997ba3e94794118))
|
||||||
|
|
||||||
|
### 📦 依赖升级
|
||||||
|
|
||||||
|
- 【dependencies】Redisson 3.27.1 => 3.27.2 ([0f43e1c](https://github.com/Charles7c/continew-starter/commit/0f43e1cff7f2fc58273de300acf4432f3a300af4))
|
||||||
|
- 【dependencies】Crane4j 2.6.0 => 2.6.1 ([0f43e1c](https://github.com/Charles7c/continew-starter/commit/0f43e1cff7f2fc58273de300acf4432f3a300af4))
|
||||||
|
|
||||||
|
## [v1.5.0](https://github.com/Charles7c/continew-starter/compare/v1.4.1...v1.5.0) (2024-03-08)
|
||||||
|
|
||||||
|
### 💎 功能优化
|
||||||
|
|
||||||
|
- 【data/mybatis-plus】重构 IService 及 BaseService 体系结构 ([36ce07b](https://github.com/Charles7c/continew-starter/commit/36ce07b600fc54eeca3682d09aa5992cb2b35c17))
|
||||||
|
- 【json/jackson】优化 Jackson 默认配置 ([a54294d](https://github.com/Charles7c/continew-starter/commit/a54294df6e24dc36d36cf6a94559af2ed4c32d44))
|
||||||
|
- 【extension/crud】调整 BaseController checkPermission 方法的访问修饰符 private => protected ([12bdf3e](https://github.com/Charles7c/continew-starter/commit/12bdf3e44a10e9683b8605642eac9c463c590af4))
|
||||||
|
|
||||||
|
### 📦 依赖升级
|
||||||
|
|
||||||
|
- 【dependencies】Spring Boot 3.1.8 => 3.1.9 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
|
||||||
|
- 【dependencies】Redisson 3.26.0 => 3.27.1 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
|
||||||
|
- 【dependencies】Crane4j 2.5.0 => 2.6.0 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
|
||||||
|
- 【dependencies】Hutool 5.8.25 => 5.8.26 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
|
||||||
|
- 【dependencies】CosId 2.6.5 => 2.6.6 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
|
||||||
|
- 【dependencies】Amazon S3 1.12.651 => 1.12.675 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
|
||||||
|
- 【dependencies】Ip2region 3.1.7 => 3.1.9 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
|
||||||
|
- 【dependencies】TTL 2.14.4 => 2.14.5 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
|
||||||
|
|
||||||
## [v1.4.1](https://github.com/Charles7c/continew-starter/compare/v1.4.0...v1.4.1) (2024-02-21)
|
## [v1.4.1](https://github.com/Charles7c/continew-starter/compare/v1.4.0...v1.4.1) (2024-02-21)
|
||||||
|
|
||||||
### ✨ 新特性
|
### ✨ 新特性
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<img src="https://img.shields.io/maven-central/v/top.charles7c.continew/continew-starter.svg?label=Maven%20Central&logo=sonatype&logoColor=FFF" alt="Release" />
|
<img src="https://img.shields.io/maven-central/v/top.charles7c.continew/continew-starter.svg?label=Maven%20Central&logo=sonatype&logoColor=FFF" alt="Release" />
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/Charles7c/continew-starter" target="_blank">
|
<a href="https://github.com/Charles7c/continew-starter" target="_blank">
|
||||||
<img src="https://img.shields.io/badge/RELEASE-v1.4.1-%23ff3f59.svg" alt="Release" />
|
<img src="https://img.shields.io/badge/RELEASE-v1.5.1-%23ff3f59.svg" alt="Release" />
|
||||||
</a>
|
</a>
|
||||||
<a href="https://app.codacy.com/gh/Charles7c/continew-starter/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade" target="_blank">
|
<a href="https://app.codacy.com/gh/Charles7c/continew-starter/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade" target="_blank">
|
||||||
<img src="https://app.codacy.com/project/badge/Grade/90ed633957a9410aa8745f0654827c01" alt="Codacy Badge" />
|
<img src="https://app.codacy.com/project/badge/Grade/90ed633957a9410aa8745f0654827c01" alt="Codacy Badge" />
|
||||||
|
|||||||
@@ -86,28 +86,27 @@ public class SpringDocAutoConfiguration implements WebMvcConfigurer {
|
|||||||
if (null != license) {
|
if (null != license) {
|
||||||
info.license(new License().name(license.getName()).url(license.getUrl()));
|
info.license(new License().name(license.getName()).url(license.getUrl()));
|
||||||
}
|
}
|
||||||
OpenAPI openAPI = new OpenAPI();
|
OpenAPI openApi = new OpenAPI();
|
||||||
openAPI.info(info);
|
openApi.info(info);
|
||||||
Components components = properties.getComponents();
|
Components components = properties.getComponents();
|
||||||
if (null != components) {
|
if (null != components) {
|
||||||
openAPI.components(components);
|
openApi.components(components);
|
||||||
// 鉴权配置
|
// 鉴权配置
|
||||||
Map<String, SecurityScheme> securitySchemeMap = components.getSecuritySchemes();
|
Map<String, SecurityScheme> securitySchemeMap = components.getSecuritySchemes();
|
||||||
if (MapUtil.isNotEmpty(securitySchemeMap)) {
|
if (MapUtil.isNotEmpty(securitySchemeMap)) {
|
||||||
SecurityRequirement securityRequirement = new SecurityRequirement();
|
SecurityRequirement securityRequirement = new SecurityRequirement();
|
||||||
List<String> list = securitySchemeMap.values().stream().map(SecurityScheme::getName).toList();
|
List<String> list = securitySchemeMap.values().stream().map(SecurityScheme::getName).toList();
|
||||||
list.forEach(securityRequirement::addList);
|
list.forEach(securityRequirement::addList);
|
||||||
openAPI.addSecurityItem(securityRequirement);
|
openApi.addSecurityItem(securityRequirement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return openAPI;
|
return openApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局自定义配置(全局添加鉴权参数)
|
* 全局自定义配置(全局添加鉴权参数)
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public GlobalOpenApiCustomizer globalOpenApiCustomizer(SpringDocExtensionProperties properties) {
|
public GlobalOpenApiCustomizer globalOpenApiCustomizer(SpringDocExtensionProperties properties) {
|
||||||
return openApi -> {
|
return openApi -> {
|
||||||
if (null != openApi.getPaths()) {
|
if (null != openApi.getPaths()) {
|
||||||
|
|||||||
@@ -14,9 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package top.charles7c.continew.starter.data.core.service;
|
package top.charles7c.continew.starter.data.mybatis.plus.service;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用业务接口
|
* 通用业务接口
|
||||||
@@ -25,13 +23,5 @@ import java.io.Serializable;
|
|||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 1.2.0
|
* @since 1.2.0
|
||||||
*/
|
*/
|
||||||
public interface IService<T> {
|
public interface IService<T> extends com.baomidou.mybatisplus.extension.service.IService<T> {
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据 ID 查询
|
|
||||||
*
|
|
||||||
* @param id ID
|
|
||||||
* @return 实体信息
|
|
||||||
*/
|
|
||||||
T getById(Serializable id);
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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.charles7c.continew.starter.data.mybatis.plus.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ClassUtil;
|
||||||
|
import top.charles7c.continew.starter.core.util.ReflectUtils;
|
||||||
|
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
|
||||||
|
import top.charles7c.continew.starter.data.mybatis.plus.base.BaseMapper;
|
||||||
|
import top.charles7c.continew.starter.data.mybatis.plus.service.IService;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用业务实现类
|
||||||
|
*
|
||||||
|
* @param <M> Mapper 接口
|
||||||
|
* @param <T> 实体类型
|
||||||
|
* @author Charles7c
|
||||||
|
* @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> {
|
||||||
|
|
||||||
|
protected final List<Field> entityFields = ReflectUtils.getNonStaticFields(this.entityClass);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T getById(Serializable id) {
|
||||||
|
return this.getById(id, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 ID 查询
|
||||||
|
*
|
||||||
|
* @param id ID
|
||||||
|
* @param isCheckExists 是否检查存在
|
||||||
|
* @return 实体信息
|
||||||
|
*/
|
||||||
|
protected T getById(Serializable id, boolean isCheckExists) {
|
||||||
|
T entity = baseMapper.selectById(id);
|
||||||
|
if (isCheckExists) {
|
||||||
|
CheckUtils.throwIfNotExists(entity, ClassUtil.getClassName(entityClass, true), "ID", id);
|
||||||
|
}
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
<version>3.1.8</version>
|
<version>3.1.9</version>
|
||||||
<relativePath/>
|
<relativePath/>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@@ -53,28 +53,28 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- 项目版本号 -->
|
<!-- 项目版本号 -->
|
||||||
<revision>1.4.1</revision>
|
<revision>1.5.1</revision>
|
||||||
<sa-token.version>1.37.0</sa-token.version>
|
<sa-token.version>1.37.0</sa-token.version>
|
||||||
<just-auth.version>1.16.6</just-auth.version>
|
<just-auth.version>1.16.6</just-auth.version>
|
||||||
<mybatis-plus.version>3.5.5</mybatis-plus.version>
|
<mybatis-plus.version>3.5.5</mybatis-plus.version>
|
||||||
<dynamic-datasource.version>4.3.0</dynamic-datasource.version>
|
<dynamic-datasource.version>4.3.0</dynamic-datasource.version>
|
||||||
<p6spy.version>3.9.1</p6spy.version>
|
<p6spy.version>3.9.1</p6spy.version>
|
||||||
<jetcache.version>2.7.5</jetcache.version>
|
<jetcache.version>2.7.5</jetcache.version>
|
||||||
<redisson.version>3.26.0</redisson.version>
|
<redisson.version>3.27.2</redisson.version>
|
||||||
<cosid.version>2.6.5</cosid.version>
|
<cosid.version>2.6.6</cosid.version>
|
||||||
<sms4j.version>3.1.1</sms4j.version>
|
<sms4j.version>3.1.1</sms4j.version>
|
||||||
<aj-captcha.version>1.3.0</aj-captcha.version>
|
<aj-captcha.version>1.3.0</aj-captcha.version>
|
||||||
<easy-captcha.version>1.6.2</easy-captcha.version>
|
<easy-captcha.version>1.6.2</easy-captcha.version>
|
||||||
<easy-excel.version>3.3.3</easy-excel.version>
|
<easy-excel.version>3.3.3</easy-excel.version>
|
||||||
<nashorn.version>15.4</nashorn.version>
|
<nashorn.version>15.4</nashorn.version>
|
||||||
<x-file-storage.version>2.1.0</x-file-storage.version>
|
<x-file-storage.version>2.1.0</x-file-storage.version>
|
||||||
<aws-s3.version>1.12.651</aws-s3.version>
|
<aws-s3.version>1.12.675</aws-s3.version>
|
||||||
<crane4j.version>2.5.0</crane4j.version>
|
<crane4j.version>2.6.1</crane4j.version>
|
||||||
<knife4j.version>4.5.0</knife4j.version>
|
<knife4j.version>4.5.0</knife4j.version>
|
||||||
<tlog.version>1.5.1</tlog.version>
|
<tlog.version>1.5.1</tlog.version>
|
||||||
<ttl.version>2.14.4</ttl.version>
|
<ttl.version>2.14.5</ttl.version>
|
||||||
<ip2region.version>3.1.7</ip2region.version>
|
<ip2region.version>3.1.9</ip2region.version>
|
||||||
<hutool.version>5.8.25</hutool.version>
|
<hutool.version>5.8.26</hutool.version>
|
||||||
<!-- Maven Plugin Versions -->
|
<!-- Maven Plugin Versions -->
|
||||||
<flatten.version>1.6.0</flatten.version>
|
<flatten.version>1.6.0</flatten.version>
|
||||||
<spotless.version>2.43.0</spotless.version>
|
<spotless.version>2.43.0</spotless.version>
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
|
|||||||
*
|
*
|
||||||
* @param api API 类型
|
* @param api API 类型
|
||||||
*/
|
*/
|
||||||
private void checkPermission(Api api) {
|
protected void checkPermission(Api api) {
|
||||||
CrudRequestMapping crudRequestMapping = this.getClass().getDeclaredAnnotation(CrudRequestMapping.class);
|
CrudRequestMapping crudRequestMapping = this.getClass().getDeclaredAnnotation(CrudRequestMapping.class);
|
||||||
String path = crudRequestMapping.value();
|
String path = crudRequestMapping.value();
|
||||||
String permissionPrefix = String.join(StringConstants.COLON, CharSequenceUtil
|
String permissionPrefix = String.join(StringConstants.COLON, CharSequenceUtil
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package top.charles7c.continew.starter.extension.crud.model.resp;
|
|||||||
|
|
||||||
import cn.crane4j.annotation.Assemble;
|
import cn.crane4j.annotation.Assemble;
|
||||||
import cn.crane4j.annotation.Mapping;
|
import cn.crane4j.annotation.Mapping;
|
||||||
|
import cn.crane4j.annotation.condition.ConditionOnPropertyNotNull;
|
||||||
import com.alibaba.excel.annotation.ExcelProperty;
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
@@ -41,6 +42,7 @@ public class BaseDetailResp extends BaseResp {
|
|||||||
* 修改人
|
* 修改人
|
||||||
*/
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
@ConditionOnPropertyNotNull
|
||||||
@Assemble(container = ContainerPool.USER_NICKNAME, props = @Mapping(ref = "updateUserString"))
|
@Assemble(container = ContainerPool.USER_NICKNAME, props = @Mapping(ref = "updateUserString"))
|
||||||
private Long updateUser;
|
private Long updateUser;
|
||||||
|
|
||||||
|
|||||||
@@ -65,15 +65,6 @@ public interface BaseService<L, D, Q, C extends BaseReq> {
|
|||||||
*/
|
*/
|
||||||
List<L> list(Q query, SortQuery sortQuery);
|
List<L> list(Q query, SortQuery sortQuery);
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询列表
|
|
||||||
*
|
|
||||||
* @return 列表信息
|
|
||||||
*/
|
|
||||||
default List<L> list() {
|
|
||||||
return list(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查看详情
|
* 查看详情
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -23,27 +23,24 @@ import cn.hutool.core.collection.CollUtil;
|
|||||||
import cn.hutool.core.lang.Opt;
|
import cn.hutool.core.lang.Opt;
|
||||||
import cn.hutool.core.lang.tree.Tree;
|
import cn.hutool.core.lang.tree.Tree;
|
||||||
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
||||||
import cn.hutool.core.util.ClassUtil;
|
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import cn.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.core.text.CharSequenceUtil;
|
||||||
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.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||||
import top.charles7c.continew.starter.core.util.ClassUtils;
|
import top.charles7c.continew.starter.core.util.ClassUtils;
|
||||||
import top.charles7c.continew.starter.core.util.ReflectUtils;
|
import top.charles7c.continew.starter.core.util.ReflectUtils;
|
||||||
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
|
|
||||||
import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
|
import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
|
||||||
import top.charles7c.continew.starter.data.mybatis.plus.base.BaseMapper;
|
import top.charles7c.continew.starter.data.mybatis.plus.base.BaseMapper;
|
||||||
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryWrapperHelper;
|
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryWrapperHelper;
|
||||||
|
import top.charles7c.continew.starter.data.mybatis.plus.service.impl.ServiceImpl;
|
||||||
import top.charles7c.continew.starter.extension.crud.annotation.TreeField;
|
import top.charles7c.continew.starter.extension.crud.annotation.TreeField;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.entity.BaseDO;
|
import top.charles7c.continew.starter.extension.crud.model.entity.BaseDO;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.req.BaseReq;
|
import top.charles7c.continew.starter.extension.crud.model.req.BaseReq;
|
||||||
import top.charles7c.continew.starter.data.core.service.IService;
|
|
||||||
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
|
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;
|
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;
|
||||||
@@ -51,7 +48,6 @@ import top.charles7c.continew.starter.extension.crud.service.BaseService;
|
|||||||
import top.charles7c.continew.starter.extension.crud.util.TreeUtils;
|
import top.charles7c.continew.starter.extension.crud.util.TreeUtils;
|
||||||
import top.charles7c.continew.starter.file.excel.util.ExcelUtils;
|
import top.charles7c.continew.starter.file.excel.util.ExcelUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -69,17 +65,12 @@ import java.util.Optional;
|
|||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO, L, D, Q, C extends BaseReq> implements BaseService<L, D, Q, C>, IService<T> {
|
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO, L, D, Q, C extends BaseReq> extends ServiceImpl<M, T> implements BaseService<L, D, Q, C> {
|
||||||
|
|
||||||
@Autowired
|
private final Class<?>[] typeArgumentCache = ClassUtils.getTypeArguments(this.getClass());
|
||||||
protected M baseMapper;
|
|
||||||
|
|
||||||
private final Class<?>[] typeArguments = ClassUtils.getTypeArguments(this.getClass());
|
|
||||||
protected final Class<T> entityClass = this.currentEntityClass();
|
|
||||||
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();
|
||||||
protected final Class<Q> queryClass = this.currentQueryClass();
|
protected final Class<Q> queryClass = this.currentQueryClass();
|
||||||
private final List<Field> entityFields = ReflectUtils.getNonStaticFields(this.entityClass);
|
|
||||||
private final List<Field> queryFields = ReflectUtils.getNonStaticFields(this.queryClass);
|
private final List<Field> queryFields = ReflectUtils.getNonStaticFields(this.queryClass);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -128,28 +119,9 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询列表
|
|
||||||
*
|
|
||||||
* @param query 查询条件
|
|
||||||
* @param sortQuery 排序查询条件
|
|
||||||
* @param targetClass 指定类型
|
|
||||||
* @return 列表信息
|
|
||||||
*/
|
|
||||||
protected <E> List<E> list(Q query, SortQuery sortQuery, Class<E> targetClass) {
|
|
||||||
QueryWrapper<T> queryWrapper = this.handleQueryWrapper(query);
|
|
||||||
// 设置排序
|
|
||||||
this.sort(queryWrapper, sortQuery);
|
|
||||||
List<T> entityList = baseMapper.selectList(queryWrapper);
|
|
||||||
if (entityClass == targetClass) {
|
|
||||||
return (List<E>)entityList;
|
|
||||||
}
|
|
||||||
return BeanUtil.copyToList(entityList, targetClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public D get(Long id) {
|
public D get(Long id) {
|
||||||
T entity = this.getById(id, false);
|
T entity = super.getById(id, false);
|
||||||
D detail = BeanUtil.toBean(entity, detailClass);
|
D detail = BeanUtil.toBean(entity, detailClass);
|
||||||
this.fill(detail);
|
this.fill(detail);
|
||||||
return detail;
|
return detail;
|
||||||
@@ -190,24 +162,23 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
|||||||
ExcelUtils.export(list, "导出数据", detailClass, response);
|
ExcelUtils.export(list, "导出数据", detailClass, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public T getById(Serializable id) {
|
|
||||||
return this.getById(id, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据 ID 查询
|
* 查询列表
|
||||||
*
|
*
|
||||||
* @param id ID
|
* @param query 查询条件
|
||||||
* @param isCheckExists 是否检查存在
|
* @param sortQuery 排序查询条件
|
||||||
* @return 实体信息
|
* @param targetClass 指定类型
|
||||||
|
* @return 列表信息
|
||||||
*/
|
*/
|
||||||
protected T getById(Serializable id, boolean isCheckExists) {
|
protected <E> List<E> list(Q query, SortQuery sortQuery, Class<E> targetClass) {
|
||||||
T entity = baseMapper.selectById(id);
|
QueryWrapper<T> queryWrapper = this.handleQueryWrapper(query);
|
||||||
if (isCheckExists) {
|
// 设置排序
|
||||||
CheckUtils.throwIfNotExists(entity, ClassUtil.getClassName(entityClass, true), "ID", id);
|
this.sort(queryWrapper, sortQuery);
|
||||||
|
List<T> entityList = baseMapper.selectList(queryWrapper);
|
||||||
|
if (entityClass == targetClass) {
|
||||||
|
return (List<E>)entityList;
|
||||||
}
|
}
|
||||||
return entity;
|
return BeanUtil.copyToList(entityList, targetClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -318,22 +289,13 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
|||||||
/* 删除后置处理 */
|
/* 删除后置处理 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前实体类型
|
|
||||||
*
|
|
||||||
* @return 当前实体类型
|
|
||||||
*/
|
|
||||||
protected Class<T> currentEntityClass() {
|
|
||||||
return (Class<T>)this.typeArguments[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前列表信息类型
|
* 获取当前列表信息类型
|
||||||
*
|
*
|
||||||
* @return 当前列表信息类型
|
* @return 当前列表信息类型
|
||||||
*/
|
*/
|
||||||
protected Class<L> currentListClass() {
|
protected Class<L> currentListClass() {
|
||||||
return (Class<L>)this.typeArguments[2];
|
return (Class<L>)this.typeArgumentCache[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -342,7 +304,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
|||||||
* @return 当前详情信息类型
|
* @return 当前详情信息类型
|
||||||
*/
|
*/
|
||||||
protected Class<D> currentDetailClass() {
|
protected Class<D> currentDetailClass() {
|
||||||
return (Class<D>)this.typeArguments[3];
|
return (Class<D>)this.typeArgumentCache[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -351,6 +313,6 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
|||||||
* @return 当前查询条件类型
|
* @return 当前查询条件类型
|
||||||
*/
|
*/
|
||||||
protected Class<Q> currentQueryClass() {
|
protected Class<Q> currentQueryClass() {
|
||||||
return (Class<Q>)this.typeArguments[4];
|
return (Class<Q>)this.typeArgumentCache[4];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,11 @@ spring:
|
|||||||
date-format: yyyy-MM-dd HH:mm:ss
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
# 序列化配置(Bean -> JSON)
|
# 序列化配置(Bean -> JSON)
|
||||||
serialization:
|
serialization:
|
||||||
|
# 不允许序列化日期时以 timestamps 输出(默认:true)
|
||||||
|
write-dates-as-timestamps: false
|
||||||
# 允许序列化无属性的 Bean
|
# 允许序列化无属性的 Bean
|
||||||
FAIL_ON_EMPTY_BEANS: false
|
fail-on-empty-beans: false
|
||||||
# 反序列化配置(JSON -> Bean)
|
# 反序列化配置(JSON -> Bean)
|
||||||
deserialization:
|
deserialization:
|
||||||
# 允许反序列化不存在的属性
|
# 允许反序列化不存在的属性
|
||||||
FAIL_ON_UNKNOWN_PROPERTIES: false
|
fail-on-unknown-properties: false
|
||||||
|
|||||||
@@ -18,17 +18,23 @@ package top.charles7c.continew.starter.web.util;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DatePattern;
|
import cn.hutool.core.date.DatePattern;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.io.file.FileNameUtil;
|
import cn.hutool.core.io.file.FileNameUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传工具类
|
* 文件工具类
|
||||||
*
|
*
|
||||||
* @author Zheng Jie(<a href="https://gitee.com/elunez/eladmin">ELADMIN</a>)
|
* @author Zheng Jie(<a href="https://gitee.com/elunez/eladmin">ELADMIN</a>)
|
||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
@@ -41,7 +47,7 @@ public class FileUploadUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件
|
* 上传
|
||||||
*
|
*
|
||||||
* @param multipartFile 源文件对象
|
* @param multipartFile 源文件对象
|
||||||
* @param filePath 文件路径
|
* @param filePath 文件路径
|
||||||
@@ -51,7 +57,6 @@ public class FileUploadUtils {
|
|||||||
public static File upload(MultipartFile multipartFile, String filePath, boolean isKeepOriginalFilename) {
|
public static File upload(MultipartFile multipartFile, String filePath, boolean isKeepOriginalFilename) {
|
||||||
String originalFilename = multipartFile.getOriginalFilename();
|
String originalFilename = multipartFile.getOriginalFilename();
|
||||||
String extensionName = FileNameUtil.extName(originalFilename);
|
String extensionName = FileNameUtil.extName(originalFilename);
|
||||||
|
|
||||||
String fileName;
|
String fileName;
|
||||||
if (isKeepOriginalFilename) {
|
if (isKeepOriginalFilename) {
|
||||||
fileName = "%s-%s.%s".formatted(FileNameUtil.getPrefix(originalFilename), DateUtil.format(LocalDateTime
|
fileName = "%s-%s.%s".formatted(FileNameUtil.getPrefix(originalFilename), DateUtil.format(LocalDateTime
|
||||||
@@ -59,7 +64,6 @@ public class FileUploadUtils {
|
|||||||
} else {
|
} else {
|
||||||
fileName = "%s.%s".formatted(IdUtil.fastSimpleUUID(), extensionName);
|
fileName = "%s.%s".formatted(IdUtil.fastSimpleUUID(), extensionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String pathname = filePath + fileName;
|
String pathname = filePath + fileName;
|
||||||
File dest = new File(pathname).getCanonicalFile();
|
File dest = new File(pathname).getCanonicalFile();
|
||||||
@@ -71,8 +75,35 @@ public class FileUploadUtils {
|
|||||||
multipartFile.transferTo(dest);
|
multipartFile.transferTo(dest);
|
||||||
return dest;
|
return dest;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Upload file occurred an error: {}. fileName: {}.", e.getMessage(), fileName, e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载
|
||||||
|
*
|
||||||
|
* @param request 请求对象
|
||||||
|
* @param response 响应对象
|
||||||
|
* @param file 文件
|
||||||
|
* @param autoDelete 下载后自动删除
|
||||||
|
*/
|
||||||
|
public static void download(HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
File file,
|
||||||
|
boolean autoDelete) {
|
||||||
|
response.setCharacterEncoding(request.getCharacterEncoding());
|
||||||
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||||
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName());
|
||||||
|
try (FileInputStream fis = new FileInputStream(file)) {
|
||||||
|
IoUtil.copy(fis, response.getOutputStream());
|
||||||
|
response.flushBuffer();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
if (autoDelete) {
|
||||||
|
file.deleteOnExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user