feat: 更新了一波工具类
更新了一波工具类更新了一波工具类
This commit is contained in:
@@ -96,6 +96,7 @@
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.4</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -3,9 +3,25 @@ package com.aos.fileidentify;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:29
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class AosFileIdentifyApplication {
|
||||
|
||||
/**
|
||||
* Main
|
||||
*
|
||||
* @param args args
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AosFileIdentifyApplication.class, args);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,12 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
@EnableSwagger2
|
||||
public class Knife4jConfiguration {
|
||||
|
||||
/**
|
||||
* Default api 2
|
||||
*
|
||||
* @return the docket
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Bean(value = "defaultApi2")
|
||||
public Docket defaultApi2() {
|
||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||
|
||||
@@ -26,6 +26,7 @@ import lombok.AllArgsConstructor;
|
||||
@AllArgsConstructor
|
||||
public class FileIdentifyController {
|
||||
|
||||
/** File identify service */
|
||||
private final FileIdentifyService fileIdentifyService;
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.aos.fileidentify.converter;
|
||||
|
||||
import com.alibaba.excel.converters.Converter;
|
||||
import com.alibaba.excel.enums.CellDataTypeEnum;
|
||||
import com.alibaba.excel.metadata.GlobalConfiguration;
|
||||
import com.alibaba.excel.metadata.data.WriteCellData;
|
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 用于EsayExel中转换实现{@link Serializable}的字段,将{@link Serializable#toString()}输出到excel中。
|
||||
* </p>
|
||||
*
|
||||
* @author xianzhiping
|
||||
* @version 2.3.0
|
||||
* @email "mailto:xianzhiping@fkhwl.com"
|
||||
* @date 2022.01.19 16:49
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public class SerializableStringConverter implements Converter<Serializable> {
|
||||
/**
|
||||
* Support java type key
|
||||
*
|
||||
* @return the class
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public Class supportJavaTypeKey() {
|
||||
return Serializable.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support excel type key
|
||||
*
|
||||
* @return the cell data type enum
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public CellDataTypeEnum supportExcelTypeKey() {
|
||||
return CellDataTypeEnum.STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert to excel data
|
||||
*
|
||||
* @param value value
|
||||
* @param contentProperty content property
|
||||
* @param globalConfiguration global configuration
|
||||
* @return the cell data
|
||||
* @throws Exception exception
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public WriteCellData convertToExcelData(Serializable value, ExcelContentProperty contentProperty,
|
||||
GlobalConfiguration globalConfiguration) throws Exception {
|
||||
return new WriteCellData<>(String.valueOf(value));
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,29 @@ import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:29
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Data
|
||||
public class BaseEntity {
|
||||
|
||||
/** Id */
|
||||
private String id;
|
||||
|
||||
/** Deleted */
|
||||
private String deleted;
|
||||
|
||||
/** Create time */
|
||||
private Date create_time;
|
||||
|
||||
/** Update time */
|
||||
private Date update_time;
|
||||
|
||||
}
|
||||
|
||||
@@ -5,55 +5,89 @@ import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:29
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Data
|
||||
public class EmployeeApproval extends BaseEntity {
|
||||
|
||||
/** Employee key */
|
||||
private String employeeKey;
|
||||
/** Name */
|
||||
@ExcelProperty("姓名")
|
||||
@NotNull
|
||||
private String name;
|
||||
/** Age */
|
||||
@ExcelProperty("年龄")
|
||||
private String age;
|
||||
/** Department */
|
||||
@ExcelProperty("部门")
|
||||
private String department;
|
||||
/** Project */
|
||||
@ExcelProperty("项目")
|
||||
private String project;
|
||||
/** Branch */
|
||||
@ExcelProperty("单位")
|
||||
private String branch;
|
||||
/** Current position */
|
||||
@ExcelProperty("现任职务")
|
||||
private String currentPosition;
|
||||
/** Gender */
|
||||
@ExcelProperty("性别")
|
||||
private String gender;
|
||||
/** Ethnic */
|
||||
@ExcelProperty("民族")
|
||||
private String ethnic;
|
||||
/** Birth */
|
||||
@ExcelProperty("出生年月")
|
||||
private String birth;
|
||||
/** Highest education */
|
||||
@ExcelProperty("最高学历")
|
||||
private String highestEducation;
|
||||
/** Full time edu qualifications */
|
||||
@ExcelProperty("全日制教育学历学位")
|
||||
private String fullTimeEduQualifications;
|
||||
/** Full time edu institutions */
|
||||
@ExcelProperty("全日制教育毕业院校及专业")
|
||||
private String fullTimeEduInstitutions;
|
||||
/** On job edu qualifications */
|
||||
@ExcelProperty("在职教育学历学位")
|
||||
private String onJobEduQualifications;
|
||||
/** On job edu institutions */
|
||||
@ExcelProperty("在职教育毕业院校及专业")
|
||||
private String onJobEduInstitutions;
|
||||
/** Join party time */
|
||||
@ExcelProperty("入党时间")
|
||||
private String joinPartyTime;
|
||||
/** Join work time */
|
||||
@ExcelProperty("参加工作时间")
|
||||
private String joinWorkTime;
|
||||
/** Current position time */
|
||||
@ExcelProperty("任现职时间")
|
||||
private String currentPositionTime;
|
||||
/** Current rank time */
|
||||
@ExcelProperty("任现职级时间")
|
||||
private String currentRankTime;
|
||||
/** Managers type */
|
||||
@ExcelProperty("经理人性质")
|
||||
private String managersType;
|
||||
/** Is concurrently */
|
||||
@ExcelProperty("兼职")
|
||||
private String isConcurrently;
|
||||
/** Appointment documents */
|
||||
@ExcelProperty("任命文件")
|
||||
private String appointmentDocuments;
|
||||
/** Post type */
|
||||
@ExcelProperty("岗位类型")
|
||||
private String postType;
|
||||
/** Remark */
|
||||
private String remark;
|
||||
|
||||
|
||||
|
||||
@@ -5,13 +5,30 @@ import lombok.Data;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:29
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Data
|
||||
public class EmployeeChange extends BaseEntity {
|
||||
/** Employee key */
|
||||
private String employee_key;
|
||||
/** Change type */
|
||||
private String change_type;
|
||||
/** Source branch */
|
||||
private String source_branch;
|
||||
/** Transfer branch */
|
||||
private String transfer_branch;
|
||||
/** Change time */
|
||||
private Date change_time;
|
||||
/** Change branch */
|
||||
private String change_branch;
|
||||
/** Change position */
|
||||
private String change_position;
|
||||
}
|
||||
|
||||
@@ -6,51 +6,83 @@ import lombok.Data;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:29
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Data
|
||||
public class EmployeeChangeDTO {
|
||||
|
||||
/** Employee key */
|
||||
private String employee_key;
|
||||
/** Change type */
|
||||
@ExcelProperty("异动类型")
|
||||
private String change_type;
|
||||
/** Change time */
|
||||
@ExcelProperty("异动时间")
|
||||
private Date change_time;
|
||||
/** Change branch */
|
||||
@ExcelProperty("拟任免部门")
|
||||
private String change_branch;
|
||||
/** Change position */
|
||||
@ExcelProperty("拟任免职务")
|
||||
private String change_position;
|
||||
/** Name */
|
||||
@ExcelProperty("姓名")
|
||||
@NotNull
|
||||
private String name;
|
||||
/** Branch */
|
||||
@ExcelProperty("单位")
|
||||
private String branch;
|
||||
/** Current position */
|
||||
@ExcelProperty("原职务")
|
||||
private String currentPosition;
|
||||
/** Gender */
|
||||
@ExcelProperty("性别")
|
||||
private String gender;
|
||||
/** Ethnic */
|
||||
@ExcelProperty("民族")
|
||||
private String ethnic;
|
||||
/** Birth */
|
||||
@ExcelProperty("出生年月")
|
||||
private String birth;
|
||||
/** Full time edu qualifications */
|
||||
@ExcelProperty("全日制教育学历学位")
|
||||
private String fullTimeEduQualifications;
|
||||
/** Full time edu institutions */
|
||||
@ExcelProperty("全日制教育毕业院校及专业")
|
||||
private String fullTimeEduInstitutions;
|
||||
/** On job edu qualifications */
|
||||
@ExcelProperty("在职教育学历学位")
|
||||
private String onJobEduQualifications;
|
||||
/** On job edu institutions */
|
||||
@ExcelProperty("在职教育毕业院校及专业")
|
||||
private String onJobEduInstitutions;
|
||||
/** Age */
|
||||
@ExcelProperty("年龄")
|
||||
private String age;
|
||||
/** Join party time */
|
||||
@ExcelProperty("入党时间")
|
||||
private String joinPartyTime;
|
||||
/** Join work time */
|
||||
@ExcelProperty("参加工作时间")
|
||||
private String joinWorkTime;
|
||||
/** Managers type */
|
||||
@ExcelProperty("经理人性质")
|
||||
private String managersType;
|
||||
/** Is concurrently */
|
||||
@ExcelProperty("兼职")
|
||||
private String isConcurrently;
|
||||
/** Appointment documents */
|
||||
@ExcelProperty("任命文件")
|
||||
private String appointmentDocuments;
|
||||
/** Post type */
|
||||
@ExcelProperty("岗位类型")
|
||||
private String postType;
|
||||
|
||||
|
||||
@@ -69,6 +69,12 @@ public class FileIdentifyServiceImpl implements FileIdentifyService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process excel
|
||||
*
|
||||
* @param file file
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Override
|
||||
public void processExcel(MultipartFile file) {
|
||||
Assert.notNull(file, "上传数据为空");
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
package com.aos.fileidentify.util;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.ExcelWriter;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.aos.fileidentify.converter.SerializableStringConverter;
|
||||
import com.aos.fileidentify.util.function.DataSupplier;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:29
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@UtilityClass
|
||||
public class ExcelUtils {
|
||||
/**
|
||||
* excel导出content-type
|
||||
*/
|
||||
public static final String EXCEL_CONTENT_TYPE = "application/vnd.ms-excel";
|
||||
/**
|
||||
* 每个工作表默认行数
|
||||
*/
|
||||
private static final int DEFAULT_EXCEL_SHEET_SIZE = 200000;
|
||||
/**
|
||||
* 默认查询数据sql每页条数
|
||||
*/
|
||||
private static final int DEFAULT_PAGE_LIMIT = 20000;
|
||||
|
||||
/**
|
||||
* 默认一次导出最大条数
|
||||
*/
|
||||
private static final int DEFAULT_MAX_EXPORT_SIZE = 20000;
|
||||
|
||||
/**
|
||||
* 查询数据sql每页条数
|
||||
*/
|
||||
private static int pageLimit = DEFAULT_PAGE_LIMIT;
|
||||
|
||||
/**
|
||||
* 是否限制excel导出条数
|
||||
*/
|
||||
private static boolean limitExportSize = true;
|
||||
/**
|
||||
* excel最大导出条数
|
||||
*/
|
||||
private static int maxExportSize = DEFAULT_MAX_EXPORT_SIZE;
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*
|
||||
* @param pageLimit page limit
|
||||
* @param limitExportSize 是否限制导出条数
|
||||
* @param maxExportSize max size
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static void init(Integer pageLimit, boolean limitExportSize, Integer maxExportSize) {
|
||||
ExcelUtils.limitExportSize = limitExportSize;
|
||||
ExcelUtils.pageLimit = pageLimit != null ? pageLimit : DEFAULT_PAGE_LIMIT;
|
||||
ExcelUtils.maxExportSize = maxExportSize != null ? maxExportSize : DEFAULT_MAX_EXPORT_SIZE;
|
||||
Assert.isTrue(ExcelUtils.pageLimit > 0, "查询数据sql每页条数必须大于0");
|
||||
Assert.isTrue(ExcelUtils.maxExportSize > 0, "excel最大导出条数必须大于0");
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel数据到HttpServletResponse
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param data 导出数据
|
||||
* @param head 表头
|
||||
* @param fileName 文件名
|
||||
* @param response HttpServletResponse
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static <T> void export(List<T> data, Class<T> head, String fileName, HttpServletResponse response) {
|
||||
ExcelUtils.export(data, head, fileName, response, DEFAULT_EXCEL_SHEET_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel数据到HttpServletResponse
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param data 导出数据
|
||||
* @param head 表头
|
||||
* @param fileName 文件名
|
||||
* @param response HttpServletResponse
|
||||
* @param rowNumPerSheet 工作表行数
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static <T> void export(List<T> data, Class<T> head, String fileName, HttpServletResponse response,
|
||||
int rowNumPerSheet) {
|
||||
try {
|
||||
ExcelUtils.export(data, head, fileName, response.getOutputStream(), rowNumPerSheet);
|
||||
ExcelUtils.setHeader(fileName, response);
|
||||
} catch (IOException e) {
|
||||
Assert.hasText("导出异常", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel数据到OutputStream
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param data 导出数据
|
||||
* @param head 表头
|
||||
* @param sheetName 工作表名
|
||||
* @param outputStream OutputStream
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static <T> void export(List<T> data, Class<T> head, String sheetName, OutputStream outputStream) {
|
||||
ExcelUtils.export(data, head, sheetName, outputStream, DEFAULT_EXCEL_SHEET_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel数据到OutputStream
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param data 导出数据
|
||||
* @param head 表头
|
||||
* @param sheetName sheet名
|
||||
* @param outputStream OutputStream
|
||||
* @param rowNumPerSheet 工作表行数
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static <T> void export(List<T> data, Class<T> head, String sheetName, OutputStream outputStream, int rowNumPerSheet) {
|
||||
Assert.notEmpty(data, "数据为空");
|
||||
Assert.notNull(sheetName, "工作表名不能为空");
|
||||
Assert.isTrue(rowNumPerSheet > 0, "工作表行数必须大于0");
|
||||
ExcelWriter excelWriter = ExcelUtils.createWriteBuilder(head, outputStream).build();
|
||||
if (data.size() > rowNumPerSheet) {
|
||||
List<List<T>> partitionData = Lists.partition(data, rowNumPerSheet);
|
||||
for (int i = 0; i < partitionData.size(); i++) {
|
||||
ExcelUtils.write(excelWriter, partitionData.get(i), sheetName + StringPool.DASH + i);
|
||||
}
|
||||
} else {
|
||||
ExcelUtils.write(excelWriter, data, sheetName);
|
||||
}
|
||||
excelWriter.finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据表头和OutputStream创建ExcelWriterBuilder
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param head 表头
|
||||
* @param outputStream OutputStream
|
||||
* @return ExcelWriterBuilder excel writer builder
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static <T> ExcelWriterBuilder createWriteBuilder(Class<T> head, OutputStream outputStream) {
|
||||
Assert.notNull(head, "表头不能为空");
|
||||
Assert.notNull(outputStream, "导出位置不能为空");
|
||||
return EasyExcel.write(outputStream, head)
|
||||
.autoCloseStream(true)
|
||||
.excelType(ExcelTypeEnum.XLSX)
|
||||
.registerConverter(new SerializableStringConverter());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建ExcelWriterSheet
|
||||
*
|
||||
* @param sheetName sheet名
|
||||
* @return the write sheet
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static WriteSheet createWriteSheet(String sheetName) {
|
||||
return EasyExcel.writerSheet(sheetName).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入sheet
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param excelWriter ExcelWriter
|
||||
* @param writeSheet WriteSheet
|
||||
* @param data sheet数据
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static <T> void write(ExcelWriter excelWriter, WriteSheet writeSheet, List<T> data) {
|
||||
excelWriter.write(data, writeSheet);
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入sheet
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param excelWriter ExcelWriter
|
||||
* @param data sheet数据
|
||||
* @param sheetName sheet名
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static <T> void write(ExcelWriter excelWriter, List<T> data, String sheetName) {
|
||||
WriteSheet writeSheet = ExcelUtils.createWriteSheet(sheetName);
|
||||
excelWriter.write(data, writeSheet);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置Header
|
||||
*
|
||||
* @param fileName 文件名
|
||||
* @param response HttpServletResponse
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static void setHeader(String fileName, HttpServletResponse response) {
|
||||
response.setContentType(EXCEL_CONTENT_TYPE);
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment;filename=" + UrlUtils.encodePath(fileName, StringPool.UTF_8) + ".xlsx");
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel数据到OutputStream
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param head 表头
|
||||
* @param fileName 文件名
|
||||
* @param response HttpServletResponse
|
||||
* @param supplier DataSupplier
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static <T> void stepwiseExport(Class<T> head, String fileName, HttpServletResponse response, DataSupplier<T> supplier) {
|
||||
ExcelUtils.stepwiseExport(head, fileName, response.getOutputStream(), supplier);
|
||||
ExcelUtils.setHeader(fileName, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel数据到OutputStream
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param head 表头
|
||||
* @param sheetName sheet名
|
||||
* @param outputStream OutputStream
|
||||
* @param supplier DataSupplier
|
||||
* @throws Exception exception
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public static <T> void stepwiseExport(Class<T> head, String sheetName, OutputStream outputStream, DataSupplier<T> supplier)
|
||||
throws Exception {
|
||||
Assert.notNull(supplier, "数据源不能为空");
|
||||
Assert.notNull(sheetName, "工作表名不能为空");
|
||||
ExcelUtils.checkExportSize(supplier);
|
||||
// 分页查询数据导出
|
||||
// 先查第一页数据
|
||||
IPage<T> data = supplier.get(1, ExcelUtils.pageLimit);
|
||||
Assert.isTrue(data.getTotal() > 0, "导出数据不能为空");
|
||||
// 当前页条数
|
||||
ExcelWriter excelWriter = ExcelUtils.createWriteBuilder(head, outputStream).build();
|
||||
WriteSheet writeSheet = ExcelUtils.createWriteSheet(sheetName);
|
||||
// 当前页小于等于总页数
|
||||
while (data != null && data.getCurrent() <= data.getPages()) {
|
||||
CompletableFuture<IPage<T>> nextPageFuture = null;
|
||||
if (data.getCurrent() < data.getPages()) {
|
||||
int nextPage = (int) (data.getCurrent() + 1);
|
||||
nextPageFuture = CompletableFuture.supplyAsync(() -> supplier.get(nextPage, ExcelUtils.pageLimit));
|
||||
}
|
||||
List<T> records = data.getRecords();
|
||||
ExcelUtils.write(excelWriter, writeSheet, records);
|
||||
// 当前页数达到最大页数停止
|
||||
data = nextPageFuture != null ? nextPageFuture.get() : null;
|
||||
}
|
||||
excelWriter.finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验导出条数限制
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param supplier DataSupplier
|
||||
* @since 2.3.0
|
||||
*/
|
||||
private static <T> void checkExportSize(DataSupplier<T> supplier) {
|
||||
if (ExcelUtils.limitExportSize) {
|
||||
// 开启限制导出条数
|
||||
IPage<T> data = supplier.get(1, 1);
|
||||
Assert.isTrue(data.getTotal() > 0, "导出数据不能为空");
|
||||
Assert.isTrue(data.getTotal() <= ExcelUtils.maxExportSize,
|
||||
"导出数据条数不能超过最大限制:" + ExcelUtils.maxExportSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,33 +58,60 @@ import java.util.zip.ZipOutputStream;
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class PdfUtils {
|
||||
/** FILE_DIR */
|
||||
public static final String FILE_DIR = "E:\\guor\\itext\\";
|
||||
/** CONST_JPG_JAVA */
|
||||
public static final String CONST_JPG_JAVA = FILE_DIR + "java.jpg";
|
||||
/** CONST_JPG_NGINX */
|
||||
public static final String CONST_JPG_NGINX = FILE_DIR + "nginx.jpg";
|
||||
/** CONST_NEZHA */
|
||||
private static final String CONST_NEZHA = "哪吒编程";
|
||||
/** CONST_NEZHA_PROGRAM */
|
||||
private static final String CONST_NEZHA_PROGRAM = "获取Java学习资料请关注公众号:哪吒编程";
|
||||
/** CONST_BIBIDONG */
|
||||
private static final String CONST_BIBIDONG = "比比东";
|
||||
/** CONST_YUNYUN */
|
||||
private static final String CONST_YUNYUN = "云韵";
|
||||
/** CONST_BAIDU */
|
||||
private static final String CONST_BAIDU = "百度一下 你就知道";
|
||||
/** CONST_BAIDU_URL */
|
||||
private static final String CONST_BAIDU_URL = "https://www.baidu.com";
|
||||
|
||||
/** CONST_PAGE_FIRST */
|
||||
private static final String CONST_PAGE_FIRST = "第一页";
|
||||
/** CONST_PAGE_SECOND */
|
||||
private static final String CONST_PAGE_SECOND = "第二页";
|
||||
/** CONST_PAGE_THIRD */
|
||||
private static final String CONST_PAGE_THIRD = "第三页";
|
||||
/** CONST_PAGE_FOUR */
|
||||
private static final String CONST_PAGE_FOUR = "第四页";
|
||||
/** CONST_PAGE_FIVE */
|
||||
private static final String CONST_PAGE_FIVE = "第五页";
|
||||
|
||||
/** CONST_TITLE_FIRST */
|
||||
private static final String CONST_TITLE_FIRST = "一级标题";
|
||||
/** CONST_TITLE_SECOND */
|
||||
private static final String CONST_TITLE_SECOND = "二级标题";
|
||||
/** CONST_CONTENT */
|
||||
private static final String CONST_CONTENT = "内容";
|
||||
|
||||
/** STATIC_FONT_CHINESE */
|
||||
// 普通中文字体
|
||||
public static Font STATIC_FONT_CHINESE = null;
|
||||
/** STATIC_FONT_LINK */
|
||||
// 超链字体
|
||||
public static Font STATIC_FONT_LINK = null;
|
||||
|
||||
/** document */
|
||||
public static Document document;
|
||||
|
||||
/**
|
||||
* Pdf font init
|
||||
*
|
||||
* @throws IOException io exception
|
||||
* @throws DocumentException document exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
private static void pdfFontInit() throws IOException, DocumentException {
|
||||
// 微软雅黑
|
||||
BaseFont chinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
|
||||
@@ -121,6 +148,10 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 创建一个 PDF 文件,并添加文本
|
||||
*
|
||||
* @throws IOException io exception
|
||||
* @throws DocumentException document exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void createPDF() throws IOException, DocumentException {
|
||||
// 实例化 document
|
||||
@@ -145,6 +176,10 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 创建PDF文件,修改文件的属性
|
||||
*
|
||||
* @throws FileNotFoundException file not found exception
|
||||
* @throws DocumentException document exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void createPDFWithColor() throws FileNotFoundException, DocumentException {
|
||||
// 页面大小
|
||||
@@ -169,6 +204,10 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 创建带密码的PDF
|
||||
*
|
||||
* @throws FileNotFoundException file not found exception
|
||||
* @throws DocumentException document exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void createPDFWithPassWord() throws FileNotFoundException, DocumentException {
|
||||
// 页面大小
|
||||
@@ -188,6 +227,10 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 为PDF添加页
|
||||
*
|
||||
* @throws FileNotFoundException file not found exception
|
||||
* @throws DocumentException document exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void createPDFWithNewPages() throws FileNotFoundException, DocumentException {
|
||||
document = new Document();
|
||||
@@ -210,6 +253,10 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 为PDF文件添加水印,背景图
|
||||
*
|
||||
* @throws IOException io exception
|
||||
* @throws DocumentException document exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void createPDFWithWaterMark() throws IOException, DocumentException {
|
||||
FileOutputStream out = new FileOutputStream(FILE_DIR + "createPDFWithWaterMark.pdf");
|
||||
@@ -272,6 +319,10 @@ public class PdfUtils {
|
||||
* Chunk : 块,PDF文档中描述的最小原子元素
|
||||
* Phrase : 短语,Chunk的集合
|
||||
* Paragraph : 段落,一个有序的Phrase集合
|
||||
*
|
||||
* @throws DocumentException document exception
|
||||
* @throws FileNotFoundException file not found exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void createPDFWithContent() throws DocumentException, FileNotFoundException {
|
||||
FileOutputStream out = new FileOutputStream(FILE_DIR + "createPDFWithContent.pdf");
|
||||
@@ -362,6 +413,11 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 插入锚Anchor, Image, 章节Chapter, 子列表Section
|
||||
*
|
||||
* @throws DocumentException document exception
|
||||
* @throws MalformedURLException malformed url exception
|
||||
* @throws IOException io exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void createPDFWithExtraContent() throws DocumentException, MalformedURLException, IOException {
|
||||
FileOutputStream out = new FileOutputStream(FILE_DIR + "createPDFWithExtraContent.pdf");
|
||||
@@ -419,6 +475,9 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 画图
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void draw() throws Exception {
|
||||
FileOutputStream out = new FileOutputStream(FILE_DIR + "draw.pdf");
|
||||
@@ -473,6 +532,9 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 设置段落
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void createPDFWithAlignment() throws Exception {
|
||||
FileOutputStream out = new FileOutputStream(FILE_DIR + "createPDFWithAlignment.pdf");
|
||||
@@ -522,6 +584,9 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 删除页
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void createPDFToDeletePage() throws Exception {
|
||||
|
||||
@@ -551,6 +616,9 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 插入 page
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void insertPage() throws Exception {
|
||||
|
||||
@@ -587,6 +655,9 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 分割 page
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void splitPDF() throws Exception {
|
||||
|
||||
@@ -637,6 +708,9 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 合并 PDF 文件
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void mergePDF() throws Exception {
|
||||
|
||||
@@ -677,6 +751,9 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 排序page
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void sortpage() throws Exception {
|
||||
FileOutputStream out = new FileOutputStream(FILE_DIR + "sortpage.pdf");
|
||||
@@ -705,6 +782,9 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 页眉页脚
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void setHeaderFooter() throws Exception {
|
||||
document = new Document();
|
||||
@@ -770,6 +850,12 @@ public class PdfUtils {
|
||||
document.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add column text
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void addColumnText() throws Exception {
|
||||
FileOutputStream out = new FileOutputStream(FILE_DIR + "addColumnText.pdf");
|
||||
|
||||
@@ -793,6 +879,9 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 文档视图
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void setView() throws Exception {
|
||||
FileOutputStream out = new FileOutputStream(FILE_DIR + "setView.pdf");
|
||||
@@ -829,6 +918,9 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 压缩PDF到Zip
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void pdfToZip() throws Exception {
|
||||
ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(FILE_DIR + "pdfToZip.zip"));
|
||||
@@ -848,6 +940,9 @@ public class PdfUtils {
|
||||
|
||||
/**
|
||||
* 添加注释
|
||||
*
|
||||
* @throws Exception exception
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public static void addAnnotation() throws Exception {
|
||||
FileOutputStream out = new FileOutputStream(FILE_DIR + "addAnnotation.pdf");
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
package com.aos.fileidentify.util;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.aos.fileidentify.util.basic.Charsets;
|
||||
import com.aos.fileidentify.util.basic.StringUtils;
|
||||
import com.aos.fileidentify.util.pools.StringPool;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:13
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Slf4j
|
||||
@UtilityClass
|
||||
public class UrlUtils extends org.springframework.web.util.UriUtils {
|
||||
|
||||
/**
|
||||
* Build url params by map
|
||||
*
|
||||
* @param map map
|
||||
* @return the string
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public static String buildUrlParamsByMap(Map<String, String> map) {
|
||||
if (map == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
sb.append(entry.getKey()).append(StringPool.EQUALS).append(entry.getValue()).append(StringPool.AMPERSAND);
|
||||
}
|
||||
String s = sb.toString();
|
||||
if (s.endsWith(StringPool.AMPERSAND)) {
|
||||
s = StringUtils.subBefore(s, StringPool.AMPERSAND);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build map by url params
|
||||
*
|
||||
* @param param param
|
||||
* @return the map
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public static @NotNull
|
||||
Map<String, String> buildMapByUrlParams(String param) {
|
||||
Map<String, String> map = Maps.newHashMap();
|
||||
if (StringUtils.isBlank(param)) {
|
||||
return map;
|
||||
}
|
||||
if (param.startsWith(StringPool.QUESTION_MARK)) {
|
||||
param = StringUtils.subAfter(param, StringPool.QUESTION_MARK);
|
||||
}
|
||||
String[] params = param.split(StringPool.AMPERSAND);
|
||||
for (String s : params) {
|
||||
String[] p = s.split(StringPool.EQUALS);
|
||||
if (p.length == 2) {
|
||||
map.put(p[0], p[1]);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* url 编码,同js decodeURIComponent
|
||||
*
|
||||
* @param source url
|
||||
* @param charset 字符集
|
||||
* @return 编码后的url string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
public static String encodeUrl(String source, @NotNull Charset charset) {
|
||||
return UrlUtils.encode(source, charset.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* url 解码
|
||||
*
|
||||
* @param source url
|
||||
* @param charset 字符集
|
||||
* @return 解码url string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
public static String decodeUrl(String source, @NotNull Charset charset) {
|
||||
return UrlUtils.decode(source, charset.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 url 路径
|
||||
*
|
||||
* @param uriStr 路径
|
||||
* @return url路径 path
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static String getPath(String uriStr) {
|
||||
URI uri;
|
||||
|
||||
try {
|
||||
uri = new URI(uriStr);
|
||||
} catch (URISyntaxException var3) {
|
||||
throw new RuntimeException(var3);
|
||||
}
|
||||
|
||||
return uri.getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* map 转为 url 参数, 默认需要参数编码
|
||||
*
|
||||
* @param source source
|
||||
* @return the string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
public static String asUrlParams(@NotNull Map<String, String> source) {
|
||||
return asUrlParams(source, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* map 转为 url 参数
|
||||
*
|
||||
* @param source source
|
||||
* @param urlEncoder url encoder
|
||||
* @return the string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
public static String asUrlParams(@NotNull Map<String, String> source, boolean urlEncoder) {
|
||||
Map<String, String> tmp = Maps.newHashMap();
|
||||
source.forEach((k, v) -> {
|
||||
if (k != null) {
|
||||
try {
|
||||
if (urlEncoder) {
|
||||
tmp.put(k, URLEncoder.encode(v, Charsets.UTF_8_NAME));
|
||||
} else {
|
||||
tmp.put(k, v);
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("url encode error", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
return Joiner.on("&").useForNull("").withKeyValueSeparator("=").join(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.aos.fileidentify.util.basic;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:16
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class Charsets {
|
||||
|
||||
/** 字符集ISO-8859-1 */
|
||||
public static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1;
|
||||
/** The constant ISO_8859_1_NAME. */
|
||||
public static final String ISO_8859_1_NAME = ISO_8859_1.name();
|
||||
/** 字符集GBK */
|
||||
public static final Charset GBK = of("GBK");
|
||||
/** The constant GBK_NAME. */
|
||||
public static final String GBK_NAME = GBK.name();
|
||||
/** 字符集utf-8 */
|
||||
public static final Charset UTF_8 = StandardCharsets.UTF_8;
|
||||
/** The constant UTF_8_NAME. */
|
||||
public static final String UTF_8_NAME = UTF_8.name();
|
||||
|
||||
/**
|
||||
* 转换为Charset对象
|
||||
*
|
||||
* @param charsetName 字符集,为空则返回默认字符集
|
||||
* @return Charsets charset
|
||||
* @throws UnsupportedCharsetException 编码不支持
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static Charset of(String charsetName) throws UnsupportedCharsetException {
|
||||
return StringUtils.hasText(charsetName) ? Charset.forName(charsetName) : Charset.defaultCharset();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
package com.aos.fileidentify.util.basic;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:27
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class NumberUtils extends org.springframework.util.NumberUtils {
|
||||
|
||||
/**
|
||||
* All possible chars for representing a number as a String
|
||||
*/
|
||||
public static final char[] DIGITS = {
|
||||
'0', '1', '2', '3', '4', '5',
|
||||
'6', '7', '8', '9', 'a', 'b',
|
||||
'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't',
|
||||
'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'A', 'B', 'C', 'D', 'E', 'F',
|
||||
'G', 'H', 'I', 'J', 'K', 'L',
|
||||
'M', 'N', 'O', 'P', 'Q', 'R',
|
||||
'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z'
|
||||
};
|
||||
|
||||
/**
|
||||
* <p>Convert a <code>String</code> to an <code>int</code>, returning
|
||||
* <code>zero</code> if the conversion fails.</p>
|
||||
* <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
|
||||
* <pre>
|
||||
* NumberUtil.toInt(null) = 0
|
||||
* NumberUtil.toInt("") = 0
|
||||
* NumberUtil.toInt("1") = 1
|
||||
* </pre>
|
||||
*
|
||||
* @param str the string to convert, may be null
|
||||
* @return the int represented by the string, or <code>zero</code> if conversion fails
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static int toInt(String str) {
|
||||
return toInt(str, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is numer boolean
|
||||
*
|
||||
* @param str str
|
||||
* @return the boolean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("null -> false")
|
||||
public static boolean isNumer(String str) {
|
||||
return NumberUtil.isNumber(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Convert a <code>String</code> to an <code>int</code>, returning a
|
||||
* default value if the conversion fails.</p>
|
||||
* <p>If the string is <code>null</code>, the default value is returned.</p>
|
||||
* <pre>
|
||||
* NumberUtil.toInt(null, 1) = 1
|
||||
* NumberUtil.toInt("", 1) = 1
|
||||
* NumberUtil.toInt("1", 0) = 1
|
||||
* </pre>
|
||||
*
|
||||
* @param str the string to convert, may be null
|
||||
* @param defaultValue the default value
|
||||
* @return the int represented by the string, or the default if conversion fails
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("null, _ -> param2")
|
||||
public static int toInt(@Nullable String str, int defaultValue) {
|
||||
if (str == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Convert a <code>String</code> to a <code>long</code>, returning
|
||||
* <code>zero</code> if the conversion fails.</p>
|
||||
* <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
|
||||
* <pre>
|
||||
* NumberUtil.toLong(null) = 0L
|
||||
* NumberUtil.toLong("") = 0L
|
||||
* NumberUtil.toLong("1") = 1L
|
||||
* </pre>
|
||||
*
|
||||
* @param str the string to convert, may be null
|
||||
* @return the long represented by the string, or <code>0</code> if conversion fails
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static long toLong(String str) {
|
||||
return toLong(str, 0L);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Convert a <code>String</code> to a <code>long</code>, returning a
|
||||
* default value if the conversion fails.</p>
|
||||
* <p>If the string is <code>null</code>, the default value is returned.</p>
|
||||
* <pre>
|
||||
* NumberUtil.toLong(null, 1L) = 1L
|
||||
* NumberUtil.toLong("", 1L) = 1L
|
||||
* NumberUtil.toLong("1", 0L) = 1L
|
||||
* </pre>
|
||||
*
|
||||
* @param str the string to convert, may be null
|
||||
* @param defaultValue the default value
|
||||
* @return the long represented by the string, or the default if conversion fails
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("null, _ -> param2")
|
||||
public static long toLong(@Nullable String str, long defaultValue) {
|
||||
if (str == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(str);
|
||||
} catch (NumberFormatException nfe) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Convert a <code>String</code> to a <code>Double</code>
|
||||
*
|
||||
* @param value value
|
||||
* @return double value
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("!null -> !null")
|
||||
public static Double toDouble(String value) {
|
||||
return toDouble(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Convert a <code>String</code> to a <code>Double</code>
|
||||
*
|
||||
* @param value value
|
||||
* @param defaultValue 默认值
|
||||
* @return double value
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("!null, _ -> !null; null, _ -> param2")
|
||||
public static Double toDouble(@Nullable String value, Double defaultValue) {
|
||||
if (value != null) {
|
||||
return Double.valueOf(value.trim());
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Convert a <code>String</code> to a <code>Double</code>
|
||||
*
|
||||
* @param value value
|
||||
* @return double value
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("!null -> !null")
|
||||
public static Float toFloat(String value) {
|
||||
return toFloat(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Convert a <code>String</code> to a <code>Double</code>
|
||||
*
|
||||
* @param value value
|
||||
* @param defaultValue 默认值
|
||||
* @return double value
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("!null, _ -> !null; null, _ -> param2")
|
||||
public static Float toFloat(@Nullable String value, Float defaultValue) {
|
||||
if (value != null) {
|
||||
return Float.valueOf(value.trim());
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 long 转短字符串 为 62 进制
|
||||
*
|
||||
* @param i 数字
|
||||
* @return 短字符串 string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
@Contract(value = "_ -> new", pure = true)
|
||||
public static String to62String(long i) {
|
||||
int radix = DIGITS.length;
|
||||
char[] buf = new char[65];
|
||||
int charPos = 64;
|
||||
i = -i;
|
||||
while (i <= -radix) {
|
||||
buf[charPos--] = DIGITS[(int) (-(i % radix))];
|
||||
i = i / radix;
|
||||
}
|
||||
buf[charPos] = DIGITS[(int) (-i)];
|
||||
|
||||
return new String(buf, charPos, (65 - charPos));
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
||||
package com.aos.fileidentify.util.function;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:06
|
||||
* @since 0.0.1
|
||||
*/
|
||||
public interface DataSupplier<T> {
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* @param page page
|
||||
* @param limit limit
|
||||
* @return the page
|
||||
* @since 2.3.0
|
||||
*/
|
||||
@NotNull IPage<T> get(int page, int limit);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.aos.fileidentify.util.pools;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:26
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
@SuppressWarnings("all")
|
||||
public class CharPool {
|
||||
/** UPPER_A */
|
||||
public static final char UPPER_A = 'A';
|
||||
/** LOWER_A */
|
||||
public static final char LOWER_A = 'a';
|
||||
/** UPPER_Z */
|
||||
public static final char UPPER_Z = 'Z';
|
||||
/** LOWER_Z */
|
||||
public static final char LOWER_Z = 'z';
|
||||
/** DOT */
|
||||
public static final char DOT = '.';
|
||||
/** AT */
|
||||
public static final char AT = '@';
|
||||
/** LEFT_BRACE */
|
||||
public static final char LEFT_BRACE = '{';
|
||||
/** RIGHT_BRACE */
|
||||
public static final char RIGHT_BRACE = '}';
|
||||
/** LEFT_BRACKET */
|
||||
public static final char LEFT_BRACKET = '(';
|
||||
/** RIGHT_BRACKET */
|
||||
public static final char RIGHT_BRACKET = ')';
|
||||
/** DASH */
|
||||
public static final char DASH = '-';
|
||||
/** PERCENT */
|
||||
public static final char PERCENT = '%';
|
||||
/** PIPE */
|
||||
public static final char PIPE = '|';
|
||||
/** PLUS */
|
||||
public static final char PLUS = '+';
|
||||
/** QUESTION_MARK */
|
||||
public static final char QUESTION_MARK = '?';
|
||||
/** EXCLAMATION_MARK */
|
||||
public static final char EXCLAMATION_MARK = '!';
|
||||
/** EQUALS */
|
||||
public static final char EQUALS = '=';
|
||||
/** AMPERSAND */
|
||||
public static final char AMPERSAND = '&';
|
||||
/** ASTERISK */
|
||||
public static final char ASTERISK = '*';
|
||||
/** STAR */
|
||||
public static final char STAR = ASTERISK;
|
||||
/** BACK_SLASH */
|
||||
public static final char BACK_SLASH = '\\';
|
||||
/** COLON */
|
||||
public static final char COLON = ':';
|
||||
/** COMMA */
|
||||
public static final char COMMA = ',';
|
||||
/** DOLLAR */
|
||||
public static final char DOLLAR = '$';
|
||||
/** SLASH */
|
||||
public static final char SLASH = '/';
|
||||
/** HASH */
|
||||
public static final char HASH = '#';
|
||||
/** HAT */
|
||||
public static final char HAT = '^';
|
||||
/** LEFT_CHEV */
|
||||
public static final char LEFT_CHEV = '<';
|
||||
/** NEWLINE */
|
||||
public static final char NEWLINE = '\n';
|
||||
/** N */
|
||||
public static final char N = 'n';
|
||||
/** Y */
|
||||
public static final char Y = 'y';
|
||||
/** QUOTE */
|
||||
public static final char QUOTE = '\"';
|
||||
/** RETURN */
|
||||
public static final char RETURN = '\r';
|
||||
/** TAB */
|
||||
public static final char TAB = '\t';
|
||||
/** RIGHT_CHEV */
|
||||
public static final char RIGHT_CHEV = '>';
|
||||
/** SEMICOLON */
|
||||
public static final char SEMICOLON = ';';
|
||||
/** SINGLE_QUOTE */
|
||||
public static final char SINGLE_QUOTE = '\'';
|
||||
/** BACKTICK */
|
||||
public static final char BACKTICK = '`';
|
||||
/** SPACE */
|
||||
public static final char SPACE = ' ';
|
||||
/** TILDA */
|
||||
public static final char TILDA = '~';
|
||||
/** LEFT_SQ_BRACKET */
|
||||
public static final char LEFT_SQ_BRACKET = '[';
|
||||
/** RIGHT_SQ_BRACKET */
|
||||
public static final char RIGHT_SQ_BRACKET = ']';
|
||||
/** UNDERSCORE */
|
||||
public static final char UNDERSCORE = '_';
|
||||
/** ONE */
|
||||
public static final char ONE = '1';
|
||||
/** ZERO */
|
||||
public static final char ZERO = '0';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.aos.fileidentify.util.pools;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author yangjiyu
|
||||
* @version 1.0.0
|
||||
* @email "mailto:yangjiyu@fkhwl.com"
|
||||
* @date 2022.07.05 14:07
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class StringPool {
|
||||
|
||||
/** AMPERSAND */
|
||||
public static final String AMPERSAND = "&";
|
||||
/** AND */
|
||||
public static final String AND = "and";
|
||||
/** AT */
|
||||
public static final String AT = "@";
|
||||
/** ASTERISK */
|
||||
public static final String ASTERISK = "*";
|
||||
/** STAR */
|
||||
public static final String STAR = ASTERISK;
|
||||
/** SLASH */
|
||||
public static final String SLASH = "/";
|
||||
/** DOUBLE_SLASH */
|
||||
public static final String DOUBLE_SLASH = "#//";
|
||||
/** COLON */
|
||||
public static final String COLON = ":";
|
||||
/** COMMA */
|
||||
public static final String COMMA = ",";
|
||||
/** DASH */
|
||||
public static final String DASH = "-";
|
||||
/** DOLLAR */
|
||||
public static final String DOLLAR = "$";
|
||||
/** DOT */
|
||||
public static final String DOT = ".";
|
||||
/** EMPTY */
|
||||
public static final String EMPTY = "";
|
||||
/** EMPTY_JSON */
|
||||
public static final String EMPTY_JSON = "{}";
|
||||
/** EQUALS */
|
||||
public static final String EQUALS = "=";
|
||||
/** FALSE */
|
||||
public static final String FALSE = "false";
|
||||
/** HASH */
|
||||
public static final String HASH = "#";
|
||||
/** HAT */
|
||||
public static final String HAT = "^";
|
||||
/** LEFT_BRACE */
|
||||
public static final String LEFT_BRACE = "{";
|
||||
/** LEFT_BRACKET */
|
||||
public static final String LEFT_BRACKET = "(";
|
||||
/** LEFT_CHEV */
|
||||
public static final String LEFT_CHEV = "<";
|
||||
/** NEWLINE */
|
||||
public static final String NEWLINE = "\n";
|
||||
/** N */
|
||||
public static final String N = "n";
|
||||
/** NO */
|
||||
public static final String NO = "no";
|
||||
/** NULL */
|
||||
public static final String NULL = "null";
|
||||
/** OFF */
|
||||
public static final String OFF = "off";
|
||||
/** ON */
|
||||
public static final String ON = "on";
|
||||
/** PERCENT */
|
||||
public static final String PERCENT = "%";
|
||||
/** PIPE */
|
||||
public static final String PIPE = "|";
|
||||
/** PLUS */
|
||||
public static final String PLUS = "+";
|
||||
/** QUESTION_MARK */
|
||||
public static final String QUESTION_MARK = "?";
|
||||
/** EXCLAMATION_MARK */
|
||||
public static final String EXCLAMATION_MARK = "!";
|
||||
/** QUOTE */
|
||||
public static final String QUOTE = "\"";
|
||||
/** RETURN */
|
||||
public static final String RETURN = "\r";
|
||||
/** TAB */
|
||||
public static final String TAB = "\t";
|
||||
/** RIGHT_BRACE */
|
||||
public static final String RIGHT_BRACE = "}";
|
||||
/** RIGHT_BRACKET */
|
||||
public static final String RIGHT_BRACKET = ")";
|
||||
/** RIGHT_CHEV */
|
||||
public static final String RIGHT_CHEV = ">";
|
||||
/** SEMICOLON */
|
||||
public static final String SEMICOLON = ";";
|
||||
/** SINGLE_QUOTE */
|
||||
public static final String SINGLE_QUOTE = "'";
|
||||
/** BACKTICK */
|
||||
public static final String BACKTICK = "`";
|
||||
/** SPACE */
|
||||
public static final String SPACE = " ";
|
||||
/** TILDA */
|
||||
public static final String TILDA = "~";
|
||||
/** LEFT_SQ_BRACKET */
|
||||
public static final String LEFT_SQ_BRACKET = "[";
|
||||
/** RIGHT_SQ_BRACKET */
|
||||
public static final String RIGHT_SQ_BRACKET = "]";
|
||||
/** TRUE */
|
||||
public static final String TRUE = "true";
|
||||
/** UNDERSCORE */
|
||||
public static final String UNDERSCORE = "_";
|
||||
/** Y */
|
||||
public static final String Y = "y";
|
||||
/** YES */
|
||||
public static final String YES = "yes";
|
||||
/** ONE */
|
||||
public static final String ONE = "1";
|
||||
/** ZERO */
|
||||
public static final String ZERO = "0";
|
||||
/** DOLLAR_LEFT_BRACE */
|
||||
public static final String DOLLAR_LEFT_BRACE = "${";
|
||||
/** NULL_STRING */
|
||||
public static final String NULL_STRING = "N/A";
|
||||
/** any_Url_Patterns */
|
||||
public static final String ANY_URL_PATTERNS = SLASH + ASTERISK;
|
||||
/** DOUBLE_ASTERISK */
|
||||
public static final String DOUBLE_ASTERISK = ASTERISK + ASTERISK;
|
||||
/** any_PATH */
|
||||
public static final String ANY_PATH = SLASH + DOUBLE_ASTERISK;
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user