commit 93d33183d22da410f7c480d95370dd2a2e901cb7 Author: tuqiang <437016993@qq.com> Date: Thu Nov 14 15:33:08 2024 +0800 first commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..d535da1 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..29b7f1e --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..132404b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..b67a82e --- /dev/null +++ b/pom.xml @@ -0,0 +1,540 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.10.RELEASE + + + org.nl + test + 1.0-SNAPSHOT + + + UTF-8 + UTF-8 + 1.8 + 1.16 + 1.1.22 + 1.2.0.Final + 1.31.0 + 5.8.22 + 0.11.1 + 8.2.0 + + + 5.9.0 + 1.9 + 1.8 + + + + + org.jetbrains + annotations + 13.0 + + + org.codehaus.groovy + groovy-all + 3.0.13 + pom + + + + + org.dromara.dynamictp + dynamic-tp-spring-boot-starter-adapter-webserver + 1.1.7 + + + + + com.yomahub + tlog-all-spring-boot-starter + 1.5.0 + + + org.apache.lucene + lucene-core + ${lucene.version} + + + org.apache.lucene + lucene-highlighter + ${lucene.version} + + + org.apache.lucene + lucene-analyzers-common + ${lucene.version} + + + com.github.magese + ik-analyzer + ${lucene.version} + + + + + org.apache.lucene + lucene-analyzers-smartcn + ${lucene.version} + + + + org.apache.lucene + lucene-queryparser + ${lucene.version} + + + + + + + + + com.github.oshi + oshi-core + 5.0.1 + + + + + com.internetitem + logback-elasticsearch-appender + 1.6 + + + + + org.fusesource.jansi + jansi + 1.9 + + + + + cn.hutool + hutool-all + ${hutool.version} + + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.2.12 + + + org.mybatis + mybatis + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + cn.dev33 + sa-token-spring-boot-starter + ${sa-token.version} + + + cn.dev33 + sa-token-sso + ${sa-token.version} + + + + cn.dev33 + sa-token-jwt + ${sa-token.version} + + + + + org.springframework.boot + spring-boot-starter-cache + + + + org.apache.commons + commons-lang3 + + + + + org.bgee.log4jdbc-log4j2 + log4jdbc-log4j2-jdbc4.1 + ${log4jdbc.version} + + + + + mysql + mysql-connector-java + + + + + com.alibaba + druid-spring-boot-starter + ${druid.version} + + + + org.projectlombok + lombok + true + + + cn.dev33 + sa-token-dao-redis + 1.31.0 + + + com.baomidou + mybatis-plus-boot-starter + 3.4.0 + + + org.apache.velocity + velocity-engine-core + 2.3 + + + com.baomidou + mybatis-plus-generator + 3.4.0 + + + xerces + xercesImpl + 2.12.0 + + + + + + org.mapstruct + mapstruct + ${mapstruct.version} + + + org.mapstruct + mapstruct-processor + ${mapstruct.version} + provided + + + javax.inject + javax.inject + 1 + + + + + com.github.whvcse + easy-captcha + 1.6.2 + + + + + nl.basjes.parse.useragent + yauaa + 5.23 + + + + eu.bitwalker + UserAgentUtils + 1.21 + + + + + com.hynnet + jxl + 2.6.12.1 + + + + commons-beanutils + commons-beanutils-core + 1.8.0 + + + + + org.springframework.boot + spring-boot-starter-aop + + + + + org.springframework.boot + spring-boot-starter-freemarker + + + + + commons-configuration + commons-configuration + ${configuration.version} + + + + com.alicp.jetcache + jetcache-starter-redis + 2.5.14 + + + + com.oracle.database.jdbc + ojdbc5 + 11.2.0.4 + + + + + + + + org.springframework.boot + spring-boot-starter-websocket + + + org.redisson + redisson-spring-boot-starter + 3.16.4 + + + + io.jsonwebtoken + jjwt-impl + ${jjwt.version} + + + io.jsonwebtoken + jjwt-jackson + ${jjwt.version} + + + + + org.quartz-scheduler + quartz + + + + + ch.ethz.ganymed + ganymed-ssh2 + build210 + + + com.jcraft + jsch + 0.1.55 + + + + + com.alibaba + easyexcel + 2.2.6 + + + org.json + json + 20131018 + + + + commons-io + commons-io + 2.8.0 + + + org.openscada.jinterop + org.openscada.jinterop.core + 2.1.8 + + + org.bouncycastle + bcprov-jdk15on + + + + + org.openscada.jinterop + org.openscada.jinterop.deps + 1.5.0 + + + org.bouncycastle + bcprov-jdk15on + + + + + org.openscada.utgard + org.openscada.opc.dcom + 1.5.0 + + + org.openscada.utgard + org.openscada.opc.lib + 1.5.0 + + + + org.bouncycastle + bcprov-jdk15on + 1.54 + + + + + org.apache.commons + commons-csv + ${commons-csv.version} + + + + org.apache.poi + poi + 4.1.2 + + + org.apache.poi + poi-ooxml + 4.1.2 + + + org.apache.poi + poi-ooxml-schemas + 4.1.2 + + + org.springframework.retry + spring-retry + 1.2.5.RELEASE + + + io.swagger + swagger-annotations + 1.5.22 + + + junit + junit + 4.11 + test + + + + org.eclipse.milo + sdk-client + 0.6.3 + + + + org.eclipse.milo + sdk-server + 0.6.3 + + + + + org.apache.poi + poi-ooxml + 5.2.5 + + + com.alibaba + easyexcel + 3.1.0 + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + 2.2.10.RELEASE + + org.nl.AppRun + true + + + + + + repackage + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.2.2 + + false + ${project.artifactId} + + + + + + + + ${basedir}/src/main/java + + **/*.* + + + **/*.java + + + + ${basedir}/src/main/resources + + **/*.* + + + + + + + + + + diff --git a/src/main/java/org/nl/demo/Demo1.java b/src/main/java/org/nl/demo/Demo1.java new file mode 100644 index 0000000..ddcf246 --- /dev/null +++ b/src/main/java/org/nl/demo/Demo1.java @@ -0,0 +1,5 @@ +package org.nl.demo; + +public class Demo1 { + +} diff --git a/src/main/java/org/nl/fill/FillData.java b/src/main/java/org/nl/fill/FillData.java new file mode 100644 index 0000000..c63ae19 --- /dev/null +++ b/src/main/java/org/nl/fill/FillData.java @@ -0,0 +1,14 @@ +package org.nl.fill; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +@Data +@EqualsAndHashCode +public class FillData { + private String name; + private double number; + private Date date; +} diff --git a/src/main/java/org/nl/fill/FillTest.java b/src/main/java/org/nl/fill/FillTest.java new file mode 100644 index 0000000..6077691 --- /dev/null +++ b/src/main/java/org/nl/fill/FillTest.java @@ -0,0 +1,223 @@ +package org.nl.fill; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.enums.WriteDirectionEnum; +import com.alibaba.excel.util.ListUtils; +import com.alibaba.excel.util.MapUtils; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.metadata.fill.FillConfig; +import com.alibaba.excel.write.metadata.fill.FillWrapper; +import org.junit.jupiter.api.Test; +import org.nl.util.TestFileUtil; + +import java.io.File; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class FillTest { + /** + * 最简单的填充 + * + * @since 2.1.1 + */ + @Test + public void simpleFill() { + // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 + String templateFileName = + TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "simple.xlsx"; + + // 方案1 根据对象填充 + String fileName = TestFileUtil.getPath() + "simpleFill" + System.currentTimeMillis() + ".xlsx"; + // 这里 会填充到第一个sheet, 然后文件流会自动关闭 + FillData fillData = new FillData(); + fillData.setName("张三"); + fillData.setNumber(5.2); + EasyExcel.write(fileName).withTemplate(templateFileName).sheet().doFill(fillData); + + // 方案2 根据Map填充 + fileName = TestFileUtil.getPath() + "simpleFill" + System.currentTimeMillis() + ".xlsx"; + // 这里 会填充到第一个sheet, 然后文件流会自动关闭 + Map map = MapUtils.newHashMap(); + map.put("name", "张三"); + map.put("number", 5.2); + EasyExcel.write(fileName).withTemplate(templateFileName).sheet().doFill(map); + } + + /** + * 填充列表 + * + * @since 2.1.1 + */ + @Test + public void listFill() { + // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 + // 填充list 的时候还要注意 模板中{.} 多了个点 表示list + // 如果填充list的对象是map,必须包涵所有list的key,哪怕数据为null,必须使用map.put(key,null) + String templateFileName = + TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "list.xlsx"; + + // 方案1 一下子全部放到内存里面 并填充 + String fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx"; + // 这里 会填充到第一个sheet, 然后文件流会自动关闭 + EasyExcel.write(fileName).withTemplate(templateFileName).sheet().doFill(data()); + + // 方案2 分多次 填充 会使用文件缓存(省内存) + fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx"; + try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) { + WriteSheet writeSheet = EasyExcel.writerSheet().build(); + excelWriter.fill(data(), writeSheet); + excelWriter.fill(data(), writeSheet); + } + } + + /** + * 复杂的填充 + * + * @since 2.1.1 + */ + @Test + public void complexFill() { + // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 + // {} 代表普通变量 {.} 代表是list的变量 + String templateFileName = + TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "complex.xlsx"; + + String fileName = TestFileUtil.getPath() + "complexFill" + System.currentTimeMillis() + ".xlsx"; + // 方案1 + try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) { + WriteSheet writeSheet = EasyExcel.writerSheet().build(); + // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行,然后下面的数据往后移动。默认 是false,会直接使用下一行,如果没有则创建。 + // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了,所以慎用 + // 简单的说 如果你的模板有list,且list不是最后一行,下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存 + // 如果数据量大 list不是最后一行 参照下一个 + FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); + excelWriter.fill(data(), fillConfig, writeSheet); + excelWriter.fill(data(), fillConfig, writeSheet); + Map map = MapUtils.newHashMap(); + map.put("date", "2019年10月9日13:28:28"); + map.put("total", 1000); + excelWriter.fill(map, writeSheet); + } + } + + /** + * 数据量大的复杂填充 + *

+ * 这里的解决方案是 确保模板list为最后一行,然后再拼接table.还有03版没救,只能刚正面加内存。 + * + * @since 2.1.1 + */ + @Test + public void complexFillWithTable() { + // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 + // {} 代表普通变量 {.} 代表是list的变量 + // 这里模板 删除了list以后的数据,也就是统计的这一行 + String templateFileName = + TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "complexFillWithTable.xlsx"; + + String fileName = TestFileUtil.getPath() + "complexFillWithTable" + System.currentTimeMillis() + ".xlsx"; + + // 方案1 + try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) { + WriteSheet writeSheet = EasyExcel.writerSheet().build(); + // 直接写入数据 + excelWriter.fill(data(), writeSheet); + excelWriter.fill(data(), writeSheet); + + // 写入list之前的数据 + Map map = new HashMap(); + map.put("date", "2019年10月9日13:28:28"); + excelWriter.fill(map, writeSheet); + + // list 后面还有个统计 想办法手动写入 + // 这里偷懒直接用list 也可以用对象 + List> totalListList = ListUtils.newArrayList(); + List totalList = ListUtils.newArrayList(); + totalListList.add(totalList); + totalList.add(null); + totalList.add(null); + totalList.add(null); + // 第四列 + totalList.add("统计:1000"); + // 这里是write 别和fill 搞错了 + excelWriter.write(totalListList, writeSheet); + // 总体上写法比较复杂 但是也没有想到好的版本 异步的去写入excel 不支持行的删除和移动,也不支持备注这种的写入,所以也排除了可以 + // 新建一个 然后一点点复制过来的方案,最后导致list需要新增行的时候,后面的列的数据没法后移,后续会继续想想解决方案 + } + } + + /** + * 横向的填充 + * + * @since 2.1.1 + */ + @Test + public void horizontalFill() { + // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 + // {} 代表普通变量 {.} 代表是list的变量 + String templateFileName = + TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "horizontal.xlsx"; + + String fileName = TestFileUtil.getPath() + "horizontalFill" + System.currentTimeMillis() + ".xlsx"; + // 方案1 + try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) { + WriteSheet writeSheet = EasyExcel.writerSheet().build(); + FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build(); + excelWriter.fill(data(), fillConfig, writeSheet); + excelWriter.fill(data(), fillConfig, writeSheet); + + Map map = new HashMap<>(); + map.put("date", "2019年10月9日13:28:28"); + excelWriter.fill(map, writeSheet); + } + } + + /** + * 多列表组合填充填充 + * + * @since 2.2.0-beta1 + */ + @Test + public void compositeFill() { + // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 + // {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list + String templateFileName = + TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "composite.xlsx"; + + String fileName = TestFileUtil.getPath() + "compositeFill" + System.currentTimeMillis() + ".xlsx"; + + // 方案1 + try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) { + WriteSheet writeSheet = EasyExcel.writerSheet().build(); + FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build(); + // 如果有多个list 模板上必须有{前缀.} 这里的前缀就是 data1,然后多个list必须用 FillWrapper包裹 + excelWriter.fill(new FillWrapper("data1", data()), fillConfig, writeSheet); + excelWriter.fill(new FillWrapper("data1", data()), fillConfig, writeSheet); + excelWriter.fill(new FillWrapper("data2", data()), writeSheet); + excelWriter.fill(new FillWrapper("data2", data()), writeSheet); + excelWriter.fill(new FillWrapper("data3", data()), writeSheet); + excelWriter.fill(new FillWrapper("data3", data()), writeSheet); + + Map map = new HashMap(); + //map.put("date", "2019年10月9日13:28:28"); + map.put("date", new Date()); + + excelWriter.fill(map, writeSheet); + } + } + + private List data() { + List list = ListUtils.newArrayList(); + for (int i = 0; i < 10; i++) { + FillData fillData = new FillData(); + list.add(fillData); + fillData.setName("张三"); + fillData.setNumber(5.2); + fillData.setDate(new Date()); + } + return list; + } +} diff --git a/src/main/java/org/nl/util/TestFileUtil.java b/src/main/java/org/nl/util/TestFileUtil.java new file mode 100644 index 0000000..67e2b91 --- /dev/null +++ b/src/main/java/org/nl/util/TestFileUtil.java @@ -0,0 +1,74 @@ +package org.nl.util; + +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; + +import java.io.File; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +public class TestFileUtil { + public static InputStream getResourcesFileInputStream(String fileName) { + return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName); + } + + public static String getPath() { + return TestFileUtil.class.getResource("/").getPath(); + } + + public static TestPathBuild pathBuild() { + return new TestPathBuild(); + } + + public static File createNewFile(String pathName) { + File file = new File(getPath() + pathName); + if (file.exists()) { + file.delete(); + } else { + if (!file.getParentFile().exists()) { + file.getParentFile().mkdirs(); + } + } + return file; + } + + public static File readFile(String pathName) { + return new File(getPath() + pathName); + } + + public static File readUserHomeFile(String pathName) { + return new File(System.getProperty("user.home") + File.separator + pathName); + } + + /** + * build to test file path + **/ + public static class TestPathBuild { + private TestPathBuild() { + subPath = new ArrayList<>(); + } + + private final List subPath; + + public TestPathBuild sub(String dirOrFile) { + subPath.add(dirOrFile); + return this; + } + + public String getPath() { + if (CollectionUtils.isEmpty(subPath)) { + return TestFileUtil.class.getResource("/").getPath(); + } + if (subPath.size() == 1) { + return TestFileUtil.class.getResource("/").getPath() + subPath.get(0); + } + StringBuilder path = new StringBuilder(TestFileUtil.class.getResource("/").getPath()); + path.append(subPath.get(0)); + for (int i = 1; i < subPath.size(); i++) { + path.append(File.separator).append(subPath.get(i)); + } + return path.toString(); + } + + } +} diff --git a/target/classes/org/nl/fill/FillData.class b/target/classes/org/nl/fill/FillData.class new file mode 100644 index 0000000..4c1b0d9 Binary files /dev/null and b/target/classes/org/nl/fill/FillData.class differ diff --git a/target/classes/org/nl/fill/FillTest.class b/target/classes/org/nl/fill/FillTest.class new file mode 100644 index 0000000..96307f5 Binary files /dev/null and b/target/classes/org/nl/fill/FillTest.class differ diff --git a/target/classes/org/nl/util/TestFileUtil$1.class b/target/classes/org/nl/util/TestFileUtil$1.class new file mode 100644 index 0000000..d7c3ce8 Binary files /dev/null and b/target/classes/org/nl/util/TestFileUtil$1.class differ diff --git a/target/classes/org/nl/util/TestFileUtil$TestPathBuild.class b/target/classes/org/nl/util/TestFileUtil$TestPathBuild.class new file mode 100644 index 0000000..5854fa2 Binary files /dev/null and b/target/classes/org/nl/util/TestFileUtil$TestPathBuild.class differ diff --git a/target/classes/org/nl/util/TestFileUtil.class b/target/classes/org/nl/util/TestFileUtil.class new file mode 100644 index 0000000..2740462 Binary files /dev/null and b/target/classes/org/nl/util/TestFileUtil.class differ diff --git a/target/classes/simpleFill1731491705207.xlsx b/target/classes/simpleFill1731491705207.xlsx new file mode 100644 index 0000000..e69de29