Compare commits
No commits in common. "enumGenerator" and "master" have entirely different histories.
enumGenera
...
master
38
.gitignore
vendored
38
.gitignore
vendored
@ -1,38 +0,0 @@
|
|||||||
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
8
.idea/.gitignore
vendored
@ -1,8 +0,0 @@
|
|||||||
# 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="corretto-11" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
Binary file not shown.
BIN
EnumGenerator.7z
BIN
EnumGenerator.7z
Binary file not shown.
@ -1,35 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,42 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
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,51 +4,85 @@
|
|||||||
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>com.psbc</groupId>
|
<groupId>org.example</groupId>
|
||||||
<artifactId>EnumGenerator</artifactId>
|
<artifactId>test</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.freemarker</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>freemarker</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
<version>2.3.31</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>easyexcel</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>3.3.4</version>
|
<version>1.18.28</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.apache.maven.plugins</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>spring-boot-maven-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
12
run.bat
@ -1,12 +0,0 @@
|
|||||||
@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
12
run1.bat
@ -1,12 +0,0 @@
|
|||||||
@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
Normal file
BIN
simple_demo.pdf
Normal file
Binary file not shown.
@ -1,51 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,99 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
11
src/main/java/example/hrh/EmailApplication.java
Normal file
11
src/main/java/example/hrh/EmailApplication.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
5
src/main/java/example/hrh/api/EmailApi.java
Normal file
5
src/main/java/example/hrh/api/EmailApi.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package example.hrh.api;
|
||||||
|
|
||||||
|
public interface EmailApi {
|
||||||
|
|
||||||
|
}
|
20
src/main/java/example/hrh/controller/EmailController.java
Normal file
20
src/main/java/example/hrh/controller/EmailController.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
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!";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package example.hrh.controller;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
public class PdfTableController {
|
||||||
|
}
|
22
src/main/java/example/hrh/service/EmailService.java
Normal file
22
src/main/java/example/hrh/service/EmailService.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
16
src/main/java/example/hrh/service/PdfGenerationService.java
Normal file
16
src/main/java/example/hrh/service/PdfGenerationService.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
src/main/java/org/example/HtmlToPDF.java
Normal file
28
src/main/java/org/example/HtmlToPDF.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
31
src/main/java/org/example/ItextPdfDemo.java
Normal file
31
src/main/java/org/example/ItextPdfDemo.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
13
src/main/resources/application.yml
Normal file
13
src/main/resources/application.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
spring:
|
||||||
|
mail:
|
||||||
|
host: smtp.qq.com
|
||||||
|
port: 587
|
||||||
|
username: 645326698@qq.com
|
||||||
|
password: ndupedhumhaybfba
|
||||||
|
properties:
|
||||||
|
mail:
|
||||||
|
smtp:
|
||||||
|
auth: true
|
||||||
|
starttls:
|
||||||
|
enable: true
|
||||||
|
|
@ -1,39 +0,0 @@
|
|||||||
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