chore(deps): 更新 fastexcel 依赖版本
- 将 fastexcel 版本从 1.2.0 升级到 1.3.0 - 更新 cutejava-springboot3 模块中的 fastexcel 版本属性
This commit is contained in:
@@ -55,7 +55,7 @@
|
|||||||
<commons-net.version>3.11.1</commons-net.version>
|
<commons-net.version>3.11.1</commons-net.version>
|
||||||
<joda-time.version>2.12.7</joda-time.version>
|
<joda-time.version>2.12.7</joda-time.version>
|
||||||
<pinyin.version>2.0.3.RELEASE</pinyin.version>
|
<pinyin.version>2.0.3.RELEASE</pinyin.version>
|
||||||
<fastexcel.version>1.2.0</fastexcel.version>
|
<fastexcel.version>1.3.0</fastexcel.version>
|
||||||
<rhino.version>1.8.0</rhino.version>
|
<rhino.version>1.8.0</rhino.version>
|
||||||
<guava.version>33.5.0-jre</guava.version>
|
<guava.version>33.5.0-jre</guava.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package cn.odboy.util.xlsx;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface KitXlsxExportDataTransferRowHandler<O, T> {
|
||||||
|
|
||||||
|
List<T> doHandler(O o);
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package cn.odboy.util.xlsx;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.idev.excel.FastExcel;
|
||||||
|
import cn.odboy.framework.exception.BadRequestException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xlsx文件导出工具
|
||||||
|
*
|
||||||
|
* @author odboy
|
||||||
|
* @date 2025-12-29
|
||||||
|
*/
|
||||||
|
@UtilityClass
|
||||||
|
public class KitXlsxExportUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param response HttpServletResponse
|
||||||
|
* @param title 标题
|
||||||
|
* @param dataObjectList 数据源,一般为从数据库直接查询的数据
|
||||||
|
* @param targetClazz 目标对象Class
|
||||||
|
* @param rowHandler 数据对象 -> 目标对象 映射逻辑
|
||||||
|
* @param <O> 数据源对象类型
|
||||||
|
* @param <T> 目标对象类型
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static <O, T> void exportFile(HttpServletResponse response, String title, List<O> dataObjectList, Class<T> targetClazz, KitXlsxExportDataTransferRowHandler<O, T> rowHandler) throws IOException {
|
||||||
|
if (response == null) {
|
||||||
|
throw new BadRequestException("参数 HttpServletResponse(response) 必填");
|
||||||
|
}
|
||||||
|
if (CollUtil.isEmpty(dataObjectList)) {
|
||||||
|
throw new BadRequestException("参数 数据源(dataObjectList) 必填");
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(title)) {
|
||||||
|
throw new BadRequestException("参数 标题(title) 必填");
|
||||||
|
}
|
||||||
|
String sheetName = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_MS_PATTERN);
|
||||||
|
List<T> resultList = new ArrayList<>();
|
||||||
|
for (O o : dataObjectList) {
|
||||||
|
List<T> rows = rowHandler.doHandler(o);
|
||||||
|
resultList.addAll(rows);
|
||||||
|
}
|
||||||
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
response.setCharacterEncoding("utf-8");
|
||||||
|
String fileName = URLEncoder.encode(sheetName + "_" + title, StandardCharsets.UTF_8);
|
||||||
|
response.setHeader("Content-disposition",
|
||||||
|
"attachment;filename*=utf-8''" + fileName + ".xlsx");
|
||||||
|
FastExcel.write(response.getOutputStream(), targetClazz)
|
||||||
|
.sheet(sheetName)
|
||||||
|
.doWrite(resultList);
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
package cn.odboy.system.constant;
|
||||||
|
|
||||||
|
public interface SystemYesOrNoChConst {
|
||||||
|
String YES_STR = "是";
|
||||||
|
String NO_STR = "否";
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package cn.odboy.system.constant;
|
||||||
|
|
||||||
|
public interface SystemZhConst {
|
||||||
|
|
||||||
|
String YES_STR = "是";
|
||||||
|
String NO_STR = "否";
|
||||||
|
String ENABLE_STR = "启用";
|
||||||
|
String DISABLE_STR = "停用";
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package cn.odboy.system.dal.model;
|
||||||
|
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import cn.odboy.base.KitObject;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class SystemDeptExportRowVo extends KitObject {
|
||||||
|
|
||||||
|
@ExcelProperty("部门名称")
|
||||||
|
private String name;
|
||||||
|
@ExcelProperty("部门状态")
|
||||||
|
private String enabled;
|
||||||
|
@ExcelProperty("创建日期")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package cn.odboy.system.dal.model;
|
||||||
|
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import cn.odboy.base.KitObject;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class SystemDictExportRowVo extends KitObject {
|
||||||
|
@ExcelProperty("字典名称")
|
||||||
|
private String name;
|
||||||
|
@ExcelProperty("字典描述")
|
||||||
|
private String description;
|
||||||
|
@ExcelProperty("字典标签")
|
||||||
|
private String label;
|
||||||
|
@ExcelProperty("字典值")
|
||||||
|
private String value;
|
||||||
|
@ExcelProperty("创建日期")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package cn.odboy.system.dal.model;
|
||||||
|
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import cn.odboy.base.KitObject;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class SystemJobExportRowVo extends KitObject {
|
||||||
|
|
||||||
|
@ExcelProperty("岗位名称")
|
||||||
|
private String name;
|
||||||
|
@ExcelProperty("岗位状态")
|
||||||
|
private String enabled;
|
||||||
|
@ExcelProperty("创建日期")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package cn.odboy.system.dal.model;
|
||||||
|
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import cn.odboy.base.KitObject;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class SystemLocalStorageExportRowVo extends KitObject {
|
||||||
|
|
||||||
|
@ExcelProperty(value = "文件名")
|
||||||
|
private String realName;
|
||||||
|
@ExcelProperty(value = "备注名")
|
||||||
|
private String name;
|
||||||
|
@ExcelProperty(value = "文件类型")
|
||||||
|
private String type;
|
||||||
|
@ExcelProperty(value = "文件大小")
|
||||||
|
private String size;
|
||||||
|
@ExcelProperty(value = "创建者")
|
||||||
|
private String createBy;
|
||||||
|
@ExcelProperty(value = "创建日期")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
package cn.odboy.system.dal.model;
|
||||||
|
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import cn.odboy.base.KitObject;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class SystemMenuExportRowVo extends KitObject {
|
||||||
|
|
||||||
|
@ExcelProperty("菜单标题")
|
||||||
|
private String title;
|
||||||
|
@ExcelProperty("菜单类型")
|
||||||
|
private String type;
|
||||||
|
@ExcelProperty("权限标识")
|
||||||
|
private String permission;
|
||||||
|
@ExcelProperty("外链菜单")
|
||||||
|
private String iFrame;
|
||||||
|
@ExcelProperty("菜单可见")
|
||||||
|
private String hidden;
|
||||||
|
@ExcelProperty("是否缓存")
|
||||||
|
private String cache;
|
||||||
|
@ExcelProperty("创建日期")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package cn.odboy.system.dal.model;
|
||||||
|
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import cn.odboy.base.KitObject;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class SystemOssStorageExportRowVo extends KitObject {
|
||||||
|
|
||||||
|
@ExcelProperty("服务类型")
|
||||||
|
private String serviceType;
|
||||||
|
@ExcelProperty("服务地址")
|
||||||
|
private String endpoint;
|
||||||
|
@ExcelProperty("存储桶名称")
|
||||||
|
private String bucketName;
|
||||||
|
@ExcelProperty("文件名称")
|
||||||
|
private String fileName;
|
||||||
|
@ExcelProperty("文件大小")
|
||||||
|
private String fileSizeDesc;
|
||||||
|
@ExcelProperty("文件类型")
|
||||||
|
private String fileMime;
|
||||||
|
@ExcelProperty("创建人")
|
||||||
|
private String createBy;
|
||||||
|
@ExcelProperty("创建日期")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package cn.odboy.system.dal.model;
|
||||||
|
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import cn.odboy.base.KitObject;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class SystemQuartzJobExportRowVo extends KitObject {
|
||||||
|
|
||||||
|
@ExcelProperty("任务名称")
|
||||||
|
private String jobName;
|
||||||
|
@ExcelProperty("Bean名称")
|
||||||
|
private String beanName;
|
||||||
|
@ExcelProperty("执行方法")
|
||||||
|
private String methodName;
|
||||||
|
@ExcelProperty("参数")
|
||||||
|
private String params;
|
||||||
|
@ExcelProperty("表达式")
|
||||||
|
private String cronExpression;
|
||||||
|
@ExcelProperty("状态")
|
||||||
|
private String isPause;
|
||||||
|
@ExcelProperty("描述")
|
||||||
|
private String description;
|
||||||
|
@ExcelProperty("创建日期")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package cn.odboy.system.dal.model;
|
||||||
|
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import cn.odboy.base.KitObject;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class SystemQuartzLogExportRowVo extends KitObject {
|
||||||
|
@ExcelProperty("任务名称")
|
||||||
|
private String jobName;
|
||||||
|
@ExcelProperty("Bean名称")
|
||||||
|
private String beanName;
|
||||||
|
@ExcelProperty("执行方法")
|
||||||
|
private String methodName;
|
||||||
|
@ExcelProperty("参数")
|
||||||
|
private String params;
|
||||||
|
@ExcelProperty("表达式")
|
||||||
|
private String cronExpression;
|
||||||
|
@ExcelProperty("异常详情")
|
||||||
|
private String exceptionDetail;
|
||||||
|
@ExcelProperty("耗时/毫秒")
|
||||||
|
private Long time;
|
||||||
|
@ExcelProperty("状态")
|
||||||
|
private String status;
|
||||||
|
@ExcelProperty("创建日期")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package cn.odboy.system.dal.model;
|
||||||
|
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import cn.odboy.base.KitObject;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class SystemRoleExportRowVo extends KitObject {
|
||||||
|
@ExcelProperty("角色名称")
|
||||||
|
private String name;
|
||||||
|
@ExcelProperty("角色级别")
|
||||||
|
private Integer level;
|
||||||
|
@ExcelProperty("描述")
|
||||||
|
private String description;
|
||||||
|
@ExcelProperty("角色名称")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package cn.odboy.system.dal.model;
|
||||||
|
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import cn.odboy.base.KitObject;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class SystemUserExportRowVo extends KitObject {
|
||||||
|
|
||||||
|
@ExcelProperty("用户名")
|
||||||
|
private String username;
|
||||||
|
@ExcelProperty("角色")
|
||||||
|
private String roles;
|
||||||
|
@ExcelProperty("部门")
|
||||||
|
private String dept;
|
||||||
|
@ExcelProperty("岗位")
|
||||||
|
private String jobs;
|
||||||
|
@ExcelProperty("邮箱")
|
||||||
|
private String email;
|
||||||
|
@ExcelProperty("状态")
|
||||||
|
private String status;
|
||||||
|
@ExcelProperty("手机号码")
|
||||||
|
private String mobile;
|
||||||
|
@ExcelProperty("修改密码的时间")
|
||||||
|
private Date updatePwdTime;
|
||||||
|
@ExcelProperty("创建日期")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package cn.odboy.system.dal.model;
|
||||||
|
|
||||||
|
import cn.idev.excel.annotation.ExcelProperty;
|
||||||
|
import cn.odboy.base.KitObject;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class SystemUserOnlineExportRowVo extends KitObject {
|
||||||
|
|
||||||
|
@ExcelProperty("用户名")
|
||||||
|
private String userName;
|
||||||
|
@ExcelProperty("部门")
|
||||||
|
private String dept;
|
||||||
|
@ExcelProperty("登录IP")
|
||||||
|
private String ip;
|
||||||
|
@ExcelProperty("登录地点")
|
||||||
|
private String address;
|
||||||
|
@ExcelProperty("浏览器")
|
||||||
|
private String browser;
|
||||||
|
@ExcelProperty("登录日期")
|
||||||
|
private String loginTime;
|
||||||
|
}
|
||||||
+180
-180
@@ -1,180 +1,180 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021-2025 Odboy
|
* Copyright 2021-2025 Odboy
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package cn.odboy.system.service.impl;
|
package cn.odboy.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.odboy.base.KitPageResult;
|
import cn.odboy.base.KitPageResult;
|
||||||
import cn.odboy.framework.exception.BadRequestException;
|
import cn.odboy.framework.exception.BadRequestException;
|
||||||
import cn.odboy.framework.properties.AppProperties;
|
import cn.odboy.framework.properties.AppProperties;
|
||||||
import cn.odboy.framework.properties.model.StorageOSSModel;
|
import cn.odboy.framework.properties.model.StorageOSSModel;
|
||||||
import cn.odboy.framework.server.core.KitFileLocalUploadHelper;
|
import cn.odboy.framework.server.core.KitFileLocalUploadHelper;
|
||||||
import cn.odboy.system.dal.dataobject.SystemOssStorageTb;
|
import cn.odboy.system.dal.dataobject.SystemOssStorageTb;
|
||||||
import cn.odboy.system.dal.model.SystemOssStorageVo;
|
import cn.odboy.system.dal.model.SystemOssStorageVo;
|
||||||
import cn.odboy.system.dal.model.SystemQueryStorageArgs;
|
import cn.odboy.system.dal.model.SystemQueryStorageArgs;
|
||||||
import cn.odboy.system.dal.mysql.SystemOssStorageMapper;
|
import cn.odboy.system.dal.mysql.SystemOssStorageMapper;
|
||||||
import cn.odboy.system.framework.storage.minio.MinioRepository;
|
import cn.odboy.system.framework.storage.minio.MinioRepository;
|
||||||
import cn.odboy.system.service.SystemOssStorageService;
|
import cn.odboy.system.service.SystemOssStorageService;
|
||||||
import cn.odboy.util.KitDateUtil;
|
import cn.odboy.util.KitDateUtil;
|
||||||
import cn.odboy.util.KitFileUtil;
|
import cn.odboy.util.KitFileUtil;
|
||||||
import cn.odboy.util.KitPageUtil;
|
import cn.odboy.util.KitPageUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* OSS存储 服务实现类
|
* OSS存储 Minio服务实现类
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author codegen
|
* @author codegen
|
||||||
* @since 2025-07-15
|
* @since 2025-07-15
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SystemOssStorageServiceImpl extends ServiceImpl<SystemOssStorageMapper, SystemOssStorageTb>
|
public class SystemMinioStorageServiceImpl extends ServiceImpl<SystemOssStorageMapper, SystemOssStorageTb>
|
||||||
implements SystemOssStorageService {
|
implements SystemOssStorageService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MinioRepository minioRepository;
|
private MinioRepository minioRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
private AppProperties properties;
|
private AppProperties properties;
|
||||||
@Autowired
|
@Autowired
|
||||||
private KitFileLocalUploadHelper fileLocalUploadHelper;
|
private KitFileLocalUploadHelper fileLocalUploadHelper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemOssStorageMapper systemOssStorageMapper;
|
private SystemOssStorageMapper systemOssStorageMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KitPageResult<SystemOssStorageVo> searchOssStorage(SystemQueryStorageArgs args,
|
public KitPageResult<SystemOssStorageVo> searchOssStorage(SystemQueryStorageArgs args,
|
||||||
Page<SystemOssStorageTb> page) {
|
Page<SystemOssStorageTb> page) {
|
||||||
IPage<SystemOssStorageTb> ossStorageTbs = this.selectOssStorageByArgs(args, page);
|
IPage<SystemOssStorageTb> ossStorageTbs = this.selectOssStorageByArgs(args, page);
|
||||||
IPage<SystemOssStorageVo> convert = ossStorageTbs.convert(c -> {
|
IPage<SystemOssStorageVo> convert = ossStorageTbs.convert(c -> {
|
||||||
SystemOssStorageVo storageVo = BeanUtil.copyProperties(c, SystemOssStorageVo.class);
|
SystemOssStorageVo storageVo = BeanUtil.copyProperties(c, SystemOssStorageVo.class);
|
||||||
storageVo.setFileSizeDesc(KitFileUtil.getSize(storageVo.getFileSize()));
|
storageVo.setFileSizeDesc(KitFileUtil.getSize(storageVo.getFileSize()));
|
||||||
return storageVo;
|
return storageVo;
|
||||||
});
|
});
|
||||||
return KitPageUtil.toPage(convert);
|
return KitPageUtil.toPage(convert);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IPage<SystemOssStorageTb> selectOssStorageByArgs(SystemQueryStorageArgs args,
|
private IPage<SystemOssStorageTb> selectOssStorageByArgs(SystemQueryStorageArgs args,
|
||||||
Page<SystemOssStorageTb> page) {
|
Page<SystemOssStorageTb> page) {
|
||||||
LambdaQueryWrapper<SystemOssStorageTb> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SystemOssStorageTb> wrapper = new LambdaQueryWrapper<>();
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
wrapper.and(StrUtil.isNotBlank(args.getBlurry()),
|
wrapper.and(StrUtil.isNotBlank(args.getBlurry()),
|
||||||
c -> c.like(SystemOssStorageTb::getFileName, args.getBlurry()).or()
|
c -> c.like(SystemOssStorageTb::getFileName, args.getBlurry()).or()
|
||||||
.like(SystemOssStorageTb::getFilePrefix, args.getBlurry()).or()
|
.like(SystemOssStorageTb::getFilePrefix, args.getBlurry()).or()
|
||||||
.like(SystemOssStorageTb::getFileMime, args.getBlurry()).or()
|
.like(SystemOssStorageTb::getFileMime, args.getBlurry()).or()
|
||||||
.like(SystemOssStorageTb::getFileMd5, args.getBlurry()));
|
.like(SystemOssStorageTb::getFileMd5, args.getBlurry()));
|
||||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||||
wrapper.between(SystemOssStorageTb::getUpdateTime, args.getCreateTime().get(0),
|
wrapper.between(SystemOssStorageTb::getUpdateTime, args.getCreateTime().get(0),
|
||||||
args.getCreateTime().get(1));
|
args.getCreateTime().get(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wrapper.orderByAsc(SystemOssStorageTb::getId);
|
wrapper.orderByAsc(SystemOssStorageTb::getId);
|
||||||
return systemOssStorageMapper.selectPage(page, wrapper);
|
return systemOssStorageMapper.selectPage(page, wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SystemOssStorageVo> queryOssStorage(SystemQueryStorageArgs args) {
|
public List<SystemOssStorageVo> queryOssStorage(SystemQueryStorageArgs args) {
|
||||||
// 防止刷数据
|
// 防止刷数据
|
||||||
Page<SystemOssStorageTb> page = new Page<>(1, 500);
|
Page<SystemOssStorageTb> page = new Page<>(1, 500);
|
||||||
return searchOssStorage(args, page).getContent();
|
return searchOssStorage(args, page).getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportOssStorageExcel(List<SystemOssStorageVo> ossStorages, HttpServletResponse response)
|
public void exportOssStorageExcel(List<SystemOssStorageVo> ossStorages, HttpServletResponse response)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (SystemOssStorageVo ossStorage : ossStorages) {
|
for (SystemOssStorageVo ossStorage : ossStorages) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("服务类型", ossStorage.getServiceType());
|
map.put("服务类型", ossStorage.getServiceType());
|
||||||
map.put("服务地址", ossStorage.getEndpoint());
|
map.put("服务地址", ossStorage.getEndpoint());
|
||||||
map.put("存储桶名称", ossStorage.getBucketName());
|
map.put("存储桶名称", ossStorage.getBucketName());
|
||||||
map.put("文件名称", ossStorage.getFileName());
|
map.put("文件名称", ossStorage.getFileName());
|
||||||
map.put("文件大小", ossStorage.getFileSizeDesc());
|
map.put("文件大小", ossStorage.getFileSizeDesc());
|
||||||
map.put("文件类型", ossStorage.getFileMime());
|
map.put("文件类型", ossStorage.getFileMime());
|
||||||
map.put("创建人", ossStorage.getCreateBy());
|
map.put("创建人", ossStorage.getCreateBy());
|
||||||
map.put("创建日期", ossStorage.getCreateTime());
|
map.put("创建日期", ossStorage.getCreateTime());
|
||||||
list.add(map);
|
list.add(map);
|
||||||
}
|
}
|
||||||
KitFileUtil.downloadExcel(list, response);
|
KitFileUtil.downloadExcel(list, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public String uploadFile(MultipartFile file) {
|
public String uploadFile(MultipartFile file) {
|
||||||
String originalFilename = file.getOriginalFilename();
|
String originalFilename = file.getOriginalFilename();
|
||||||
if (StrUtil.isBlank(originalFilename)) {
|
if (StrUtil.isBlank(originalFilename)) {
|
||||||
throw new BadRequestException("文件名不能为空");
|
throw new BadRequestException("文件名不能为空");
|
||||||
}
|
}
|
||||||
StorageOSSModel ossConfig = properties.getOss();
|
StorageOSSModel ossConfig = properties.getOss();
|
||||||
long fileSize = file.getSize();
|
long fileSize = file.getSize();
|
||||||
String contentType = file.getContentType();
|
String contentType = file.getContentType();
|
||||||
KitFileUtil.checkSize(ossConfig.getMaxSize(), fileSize);
|
KitFileUtil.checkSize(ossConfig.getMaxSize(), fileSize);
|
||||||
// 按天分组
|
// 按天分组
|
||||||
String nowDateStr = KitDateUtil.getNowDateStr();
|
String nowDateStr = KitDateUtil.getNowDateStr();
|
||||||
// 上传到本地临时目录
|
// 上传到本地临时目录
|
||||||
File tempFile = KitFileUtil.upload(file, fileLocalUploadHelper.getPath() + nowDateStr + File.separator);
|
File tempFile = KitFileUtil.upload(file, fileLocalUploadHelper.getPath() + nowDateStr + File.separator);
|
||||||
if (tempFile == null) {
|
if (tempFile == null) {
|
||||||
throw new BadRequestException("上传失败");
|
throw new BadRequestException("上传失败");
|
||||||
}
|
}
|
||||||
// 校验文件md5, 看是否已存在云端(不确定, 可能云端已经删除, 但是正常来说云端是不允许私自删除的, 所以这里忽略云端不存在的情况)
|
// 校验文件md5, 看是否已存在云端(不确定, 可能云端已经删除, 但是正常来说云端是不允许私自删除的, 所以这里忽略云端不存在的情况)
|
||||||
String md5 = KitFileUtil.getMd5(tempFile);
|
String md5 = KitFileUtil.getMd5(tempFile);
|
||||||
SystemOssStorageTb systemOssStorageTb = this.getOssStorageByMd5(md5);
|
SystemOssStorageTb systemOssStorageTb = this.getOssStorageByMd5(md5);
|
||||||
if (systemOssStorageTb != null) {
|
if (systemOssStorageTb != null) {
|
||||||
// 重新生成7天链接
|
// 重新生成7天链接
|
||||||
return minioRepository.generatePreviewUrl(systemOssStorageTb.getObjectName());
|
return minioRepository.generatePreviewUrl(systemOssStorageTb.getObjectName());
|
||||||
}
|
}
|
||||||
// 上传到OSS
|
// 上传到OSS
|
||||||
SystemOssStorageTb storageTb = minioRepository.upload(tempFile, originalFilename, fileSize, contentType, md5);
|
SystemOssStorageTb storageTb = minioRepository.upload(tempFile, originalFilename, fileSize, contentType, md5);
|
||||||
if (storageTb == null) {
|
if (storageTb == null) {
|
||||||
throw new BadRequestException("文件上传失败");
|
throw new BadRequestException("文件上传失败");
|
||||||
}
|
}
|
||||||
save(storageTb);
|
save(storageTb);
|
||||||
return minioRepository.generatePreviewUrl(storageTb.getObjectName());
|
return minioRepository.generatePreviewUrl(storageTb.getObjectName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 多选删除
|
* 多选删除
|
||||||
*
|
*
|
||||||
* @param ids /
|
* @param ids /
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteFileByIds(Long[] ids) {
|
public void deleteFileByIds(Long[] ids) {
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
SystemOssStorageTb storage = getById(id);
|
SystemOssStorageTb storage = getById(id);
|
||||||
minioRepository.removeBucketFile(storage.getObjectName());
|
minioRepository.removeBucketFile(storage.getObjectName());
|
||||||
removeById(storage);
|
removeById(storage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SystemOssStorageTb getOssStorageByMd5(String md5) {
|
private SystemOssStorageTb getOssStorageByMd5(String md5) {
|
||||||
return lambdaQuery().eq(SystemOssStorageTb::getFileMd5, md5).one();
|
return lambdaQuery().eq(SystemOssStorageTb::getFileMd5, md5).one();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -367,7 +367,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.idev.excel</groupId>
|
<groupId>cn.idev.excel</groupId>
|
||||||
<artifactId>fastexcel</artifactId>
|
<artifactId>fastexcel</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user