Compare commits
No commits in common. "master" and "enumGenerator" have entirely different histories.
master
...
enumGenera
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
@ -8,7 +8,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="corretto-11" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
BIN
EnumGenerator-1.0-SNAPSHOT.jar
Normal file
BIN
EnumGenerator-1.0-SNAPSHOT.jar
Normal file
Binary file not shown.
BIN
EnumGenerator.7z
Normal file
BIN
EnumGenerator.7z
Normal file
Binary file not shown.
35
dependency-reduced-pom.xml
Normal file
35
dependency-reduced-pom.xml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.psbc</groupId>
|
||||||
|
<artifactId>EnumGenerator</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<transformers>
|
||||||
|
<transformer>
|
||||||
|
<mainClass>com.psbc.Main</mainClass>
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
</project>
|
42
output/EthicyEnum.java
Normal file
42
output/EthicyEnum.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
public enum Ethicy {
|
||||||
|
1("1", "汉族"),
|
||||||
|
2("2", "回族"),
|
||||||
|
3("3", "维吾尔族"),
|
||||||
|
4("4", "苗族"),
|
||||||
|
5("5", "藏族")
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
Ethicy(String code, String value) {
|
||||||
|
this.code = code;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Ethicy findByCode(String code) {
|
||||||
|
for (Ethicy constant : values()) {
|
||||||
|
if (constant.key.equals(code)) {
|
||||||
|
return constant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null; // 或者抛出 IllegalArgumentException
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Ethicy findByValue(String value) {
|
||||||
|
for (Ethicy constant : values()) {
|
||||||
|
if (constant.value.equals(value)) {
|
||||||
|
return constant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null; // 或者抛出 IllegalArgumentException
|
||||||
|
}
|
||||||
|
}
|
41
output/NationEnum.java
Normal file
41
output/NationEnum.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
public enum Nation {
|
||||||
|
A("A", "阿根廷"),
|
||||||
|
B("B", "巴西"),
|
||||||
|
C("C", "加拿大"),
|
||||||
|
D("D", "丹麦")
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
Nation(String code, String value) {
|
||||||
|
this.code = code;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Nation findByCode(String code) {
|
||||||
|
for (Nation constant : values()) {
|
||||||
|
if (constant.key.equals(code)) {
|
||||||
|
return constant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null; // 或者抛出 IllegalArgumentException
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Nation findByValue(String value) {
|
||||||
|
for (Nation constant : values()) {
|
||||||
|
if (constant.value.equals(value)) {
|
||||||
|
return constant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null; // 或者抛出 IllegalArgumentException
|
||||||
|
}
|
||||||
|
}
|
88
pom.xml
88
pom.xml
@ -4,85 +4,51 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>org.example</groupId>
|
<groupId>com.psbc</groupId>
|
||||||
<artifactId>test</artifactId>
|
<artifactId>EnumGenerator</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
|
||||||
<version>2.5.0</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- Web 功能 -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.freemarker</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>freemarker</artifactId>
|
||||||
|
<version>2.3.31</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>easyexcel</artifactId>
|
||||||
<version>1.18.28</version>
|
<version>3.3.4</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.itextpdf</groupId>
|
|
||||||
<artifactId>itext7-core</artifactId>
|
|
||||||
<version>7.1.1</version>
|
|
||||||
<type>pom</type>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.itextpdf</groupId>
|
|
||||||
<artifactId>font-asian</artifactId>
|
|
||||||
<version>7.1.1</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- iText布局引擎 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.itextpdf</groupId>
|
|
||||||
<artifactId>layout</artifactId>
|
|
||||||
<version>7.1.1</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- iText表单库 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.itextpdf</groupId>
|
|
||||||
<artifactId>forms</artifactId>
|
|
||||||
<version>7.1.1</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- iText PDF/A库 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.itextpdf</groupId>
|
|
||||||
<artifactId>pdfa</artifactId>
|
|
||||||
<version>7.1.1</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- iText PDF/A库 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.itextpdf</groupId>
|
|
||||||
<artifactId>html2pdf</artifactId>
|
|
||||||
<version>2.0.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-mail</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<transformers>
|
||||||
|
<transformer
|
||||||
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
|
<mainClass>com.psbc.Main</mainClass> <!-- 替换为你的主类 -->
|
||||||
|
</transformer>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
12
run.bat
Normal file
12
run.bat
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
@echo off
|
||||||
|
REM 设置JAR文件路径
|
||||||
|
set JAR_PATH=D:\myDeployment\EnumGenerator\EnumGenerator-1.0-SNAPSHOT.jar
|
||||||
|
|
||||||
|
REM 设置传递给JAR包的参数
|
||||||
|
set PARAM1=D:\myDeployment\EnumGenerator\test.xlsx
|
||||||
|
set PARAM2=D:\myDeployment\EnumGenerator\output\
|
||||||
|
mkdir %PARAM2%
|
||||||
|
REM 执行JAR包并传递参数
|
||||||
|
java -jar %JAR_PATH% %PARAM1% %PARAM2%
|
||||||
|
|
||||||
|
pause
|
12
run1.bat
Normal file
12
run1.bat
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
@echo off
|
||||||
|
REM 设置JAR文件路径
|
||||||
|
set JAR_PATH=.\EnumGenerator-1.0-SNAPSHOT.jar
|
||||||
|
|
||||||
|
REM 设置传递给JAR包的参数
|
||||||
|
set PARAM1=%1
|
||||||
|
set PARAM2=%2
|
||||||
|
mkdir .\%PARAM2%
|
||||||
|
REM 执行JAR包并传递参数
|
||||||
|
java -jar %JAR_PATH% %PARAM1% %PARAM2%
|
||||||
|
|
||||||
|
pause
|
BIN
simple_demo.pdf
BIN
simple_demo.pdf
Binary file not shown.
51
src/main/java/com/psbc/EnumGenerator.java
Normal file
51
src/main/java/com/psbc/EnumGenerator.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package com.psbc;
|
||||||
|
|
||||||
|
import freemarker.template.Configuration;
|
||||||
|
import freemarker.template.Template;
|
||||||
|
import freemarker.template.TemplateException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class EnumGenerator {
|
||||||
|
|
||||||
|
public static void main() {
|
||||||
|
// 定义枚举名称和常量
|
||||||
|
String enumName = "Color";
|
||||||
|
Map<String, String> constants = new HashMap<>();
|
||||||
|
constants.put("RED", "Red Color");
|
||||||
|
constants.put("GREEN", "Green Color");
|
||||||
|
constants.put("BLUE", "Blue Color");
|
||||||
|
|
||||||
|
// 配置FreeMarker
|
||||||
|
Configuration cfg = new Configuration(Configuration.VERSION_2_3_31);
|
||||||
|
try {
|
||||||
|
cfg.setDirectoryForTemplateLoading(new File("./src/templates"));
|
||||||
|
cfg.setDefaultEncoding("UTF-8");
|
||||||
|
|
||||||
|
// 加载模板
|
||||||
|
Template template = cfg.getTemplate("enumTemplate.ftl");
|
||||||
|
|
||||||
|
// 创建数据模型
|
||||||
|
Map<String, Object> dataModel = new HashMap<>();
|
||||||
|
dataModel.put("enumName", enumName);
|
||||||
|
dataModel.put("constants", constants.entrySet());
|
||||||
|
|
||||||
|
// 指定输出文件路径
|
||||||
|
String outputPath = "./src/output/" + enumName + "Enum.java";
|
||||||
|
|
||||||
|
// 生成文件
|
||||||
|
try (Writer fileWriter = new FileWriter(outputPath)) {
|
||||||
|
template.process(dataModel, fileWriter);
|
||||||
|
System.out.println("Enum file generated at: " + outputPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException | TemplateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
99
src/main/java/com/psbc/Main.java
Normal file
99
src/main/java/com/psbc/Main.java
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package com.psbc;
|
||||||
|
|
||||||
|
import com.alibaba.excel.EasyExcel;
|
||||||
|
import com.alibaba.excel.read.listener.PageReadListener;
|
||||||
|
import com.alibaba.excel.util.StringUtils;
|
||||||
|
import com.psbc.entity.DataOption;
|
||||||
|
import com.psbc.entity.FieldValue;
|
||||||
|
import freemarker.template.Configuration;
|
||||||
|
import freemarker.template.Template;
|
||||||
|
import freemarker.template.TemplateException;
|
||||||
|
import org.apache.poi.util.StringUtil;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||||
|
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static String outputPath = "";
|
||||||
|
public static void main(String[] args) throws TemplateException, IOException {
|
||||||
|
|
||||||
|
String jarPathgetProtectionDomain = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||||
|
if(StringUtils.isEmpty(args[0])){
|
||||||
|
System.out.println("请输入excel路径");
|
||||||
|
}
|
||||||
|
if(StringUtils.isEmpty(args[1])){
|
||||||
|
System.out.println("请输入枚举类输出路径");
|
||||||
|
}
|
||||||
|
String excelPath = args[0];
|
||||||
|
outputPath = args[1];
|
||||||
|
getAllExcelData(excelPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void getAllExcelData(String excelPath) throws TemplateException, IOException {
|
||||||
|
String[] inputDescs = {"民族代码", "国家地区代码"};
|
||||||
|
// 用于存储所有Sheet页的数据
|
||||||
|
List<DataOption> allDataOptions = new ArrayList<>();
|
||||||
|
List<FieldValue> fieldValues = new ArrayList<>();
|
||||||
|
// 读取Excel文件中的每个Sheet页
|
||||||
|
EasyExcel.read(excelPath, DataOption.class, new PageReadListener<DataOption>(allDataOptions::addAll)).sheet(0).doRead();
|
||||||
|
EasyExcel.read(excelPath, FieldValue.class, new PageReadListener<FieldValue>(fieldValues::addAll)).sheet(1).doRead();
|
||||||
|
|
||||||
|
|
||||||
|
// // 输出读取到的数据
|
||||||
|
// for (DataOption data : allDataOptions) {
|
||||||
|
// System.out.println("Desc: " + data.getDesc() + ", enumName: " + data.getEnumName() + ", Filed: " + data.getField());
|
||||||
|
// }
|
||||||
|
// for (FieldValue data : fieldValues) {
|
||||||
|
// System.out.println("Field: " + data.getField() + ", Code: " + data.getCode() + ", Value: " + data.getValue());
|
||||||
|
// }
|
||||||
|
//将字符串进行匹配
|
||||||
|
for (String inputDesc : inputDescs) {
|
||||||
|
dataMatcher(allDataOptions, fieldValues, inputDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void dataMatcher(List<DataOption> dataOptions, List<FieldValue> fieldValues, String inputDesc) throws TemplateException, IOException {
|
||||||
|
Optional<DataOption> matchedData = dataOptions.stream()
|
||||||
|
.filter(data -> inputDesc.equals(data.getDesc()))
|
||||||
|
.findFirst();
|
||||||
|
if (matchedData.isPresent()) {
|
||||||
|
Map<String, String> constantsMap = fieldValues.stream().filter(item ->
|
||||||
|
item.getField().equals(matchedData.get().getField())).collect(Collectors.toMap(FieldValue::getCode, FieldValue::getValue));
|
||||||
|
//有匹配项则生成enumClass
|
||||||
|
enumGenerator(matchedData.get().getEnumName(), constantsMap);
|
||||||
|
} else {
|
||||||
|
System.out.println("No matching data found for desc: " + inputDesc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void enumGenerator(String enumName, Map<String, String> constants) throws IOException, TemplateException {
|
||||||
|
Configuration cfg = new Configuration(Configuration.VERSION_2_3_31);
|
||||||
|
cfg.setDirectoryForTemplateLoading(new File("./src/templates"));
|
||||||
|
cfg.setDefaultEncoding("UTF-8");
|
||||||
|
|
||||||
|
// 加载模板
|
||||||
|
Template template = cfg.getTemplate("enumTemplate.ftl");
|
||||||
|
|
||||||
|
// 创建数据模型
|
||||||
|
Map<String, Object> dataModel = new HashMap<>();
|
||||||
|
dataModel.put("enumName", enumName);
|
||||||
|
dataModel.put("constants", constants.entrySet());
|
||||||
|
|
||||||
|
// 指定输出文件路径
|
||||||
|
String output= outputPath + enumName + "Enum.java";
|
||||||
|
|
||||||
|
// 生成文件
|
||||||
|
try (Writer fileWriter = new FileWriter(output)) {
|
||||||
|
template.process(dataModel, fileWriter);
|
||||||
|
System.out.println("Enum file generated at: " + output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
src/main/java/com/psbc/entity/DataOption.java
Normal file
37
src/main/java/com/psbc/entity/DataOption.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package com.psbc.entity;
|
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty;
|
||||||
|
|
||||||
|
public class DataOption {
|
||||||
|
@ExcelProperty(index = 0)
|
||||||
|
private String desc;
|
||||||
|
@ExcelProperty(index = 1)
|
||||||
|
private String enumName;
|
||||||
|
@ExcelProperty(index = 2)
|
||||||
|
private String field;
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public String getDesc() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEnumName() {
|
||||||
|
return enumName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnumName(String enumName) {
|
||||||
|
this.enumName = enumName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesc(String desc) {
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getField() {
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setField(String value) {
|
||||||
|
this.field = value;
|
||||||
|
}
|
||||||
|
}
|
32
src/main/java/com/psbc/entity/FieldValue.java
Normal file
32
src/main/java/com/psbc/entity/FieldValue.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package com.psbc.entity;
|
||||||
|
|
||||||
|
public class FieldValue {
|
||||||
|
private String field;
|
||||||
|
private String code;
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public String getField() {
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setField(String field) {
|
||||||
|
this.field = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,11 +0,0 @@
|
|||||||
package example.hrh;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
public class EmailApplication {
|
|
||||||
public static void main(String[] args){
|
|
||||||
SpringApplication.run(EmailApplication.class,args);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package example.hrh.api;
|
|
||||||
|
|
||||||
public interface EmailApi {
|
|
||||||
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package example.hrh.controller;
|
|
||||||
|
|
||||||
import example.hrh.service.EmailService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class EmailController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EmailService emailService;
|
|
||||||
|
|
||||||
@PostMapping("/sendEmail")
|
|
||||||
public String sendEmail(@RequestParam String to, @RequestParam String subject, @RequestParam String text) {
|
|
||||||
emailService.sendSimpleEmail(to, subject, text);
|
|
||||||
return "Email sent successfully!";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package example.hrh.controller;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
public class PdfTableController {
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package example.hrh.service;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class EmailService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JavaMailSender mailSender;
|
|
||||||
|
|
||||||
public void sendSimpleEmail(String to, String subject, String text) {
|
|
||||||
SimpleMailMessage message = new SimpleMailMessage();
|
|
||||||
message.setFrom("645326698@qq.com");
|
|
||||||
message.setTo(to);
|
|
||||||
message.setSubject(subject);
|
|
||||||
message.setText(text);
|
|
||||||
mailSender.send(message);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package example.hrh.service;
|
|
||||||
|
|
||||||
import com.itextpdf.html2pdf.HtmlConverter;
|
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class PdfGenerationService {
|
|
||||||
public void createPdfFromHtml(String htmlContent, String pdfDest) {
|
|
||||||
try {
|
|
||||||
HtmlConverter.convertToPdf(htmlContent, new FileOutputStream(pdfDest));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package org.example;
|
|
||||||
|
|
||||||
import com.itextpdf.html2pdf.HtmlConverter;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import example.hrh.service.PdfGenerationService;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
public class HtmlToPDF {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private PdfGenerationService pdfGenerationService;
|
|
||||||
private static final String ORIG = "C:\\Users\\hu645\\Desktop\\studentInfoTable.html";
|
|
||||||
private static final String OUTPUT_FOLDER = "D:\\itextpdf\\";
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
File htmlSource = new File(ORIG);
|
|
||||||
File pdfDest = new File(OUTPUT_FOLDER + "output.pdf");
|
|
||||||
HtmlConverter.convertToPdf(new FileInputStream(htmlSource), new FileOutputStream(pdfDest));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
|||||||
package org.example;
|
|
||||||
import com.itextpdf.kernel.pdf.PdfDocument;
|
|
||||||
import com.itextpdf.kernel.pdf.PdfWriter;
|
|
||||||
import com.itextpdf.layout.Document;
|
|
||||||
import com.itextpdf.layout.element.Paragraph;
|
|
||||||
|
|
||||||
|
|
||||||
public class ItextPdfDemo {
|
|
||||||
public static void main(String args[]) throws Exception {
|
|
||||||
// 1. Creating a PdfWriter
|
|
||||||
String dest = "example.pdf"; // Output file path
|
|
||||||
PdfWriter writer = new PdfWriter(dest);
|
|
||||||
|
|
||||||
// 2. Creating a PdfDocument
|
|
||||||
PdfDocument pdfDoc = new PdfDocument(writer);
|
|
||||||
|
|
||||||
// 3. Adding an empty page
|
|
||||||
pdfDoc.addNewPage();
|
|
||||||
|
|
||||||
// 4. Creating a Document
|
|
||||||
Document document = new Document(pdfDoc);
|
|
||||||
|
|
||||||
// 5. Adding a Paragraph
|
|
||||||
document.add(new Paragraph("Hello, World!"));
|
|
||||||
|
|
||||||
// 6. Closing the document
|
|
||||||
document.close();
|
|
||||||
|
|
||||||
System.out.println("PDF Created");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
spring:
|
|
||||||
mail:
|
|
||||||
host: smtp.qq.com
|
|
||||||
port: 587
|
|
||||||
username: 645326698@qq.com
|
|
||||||
password: ndupedhumhaybfba
|
|
||||||
properties:
|
|
||||||
mail:
|
|
||||||
smtp:
|
|
||||||
auth: true
|
|
||||||
starttls:
|
|
||||||
enable: true
|
|
||||||
|
|
39
src/templates/enumTemplate.ftl
Normal file
39
src/templates/enumTemplate.ftl
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
public enum ${enumName} {
|
||||||
|
<#list constants as constant>
|
||||||
|
${constant.key}("${constant.key}", "${constant.value}")<#if constant_has_next>,</#if>
|
||||||
|
</#list>;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
${enumName}(String code, String value) {
|
||||||
|
this.code = code;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ${enumName} findByCode(String code) {
|
||||||
|
for (${enumName} constant : values()) {
|
||||||
|
if (constant.key.equals(code)) {
|
||||||
|
return constant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null; // 或者抛出 IllegalArgumentException
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ${enumName} findByValue(String value) {
|
||||||
|
for (${enumName} constant : values()) {
|
||||||
|
if (constant.value.equals(value)) {
|
||||||
|
return constant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null; // 或者抛出 IllegalArgumentException
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user