From 6a096f78e92448a1cf86d375d39ef9ca251ee7f4 Mon Sep 17 00:00:00 2001 From: wangyuan Date: Fri, 18 Jan 2019 12:12:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90java=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/src/main/java/ExcelUtils.java | 116 +++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 6 deletions(-) diff --git a/test/src/main/java/ExcelUtils.java b/test/src/main/java/ExcelUtils.java index afb70c898..03a457e1a 100644 --- a/test/src/main/java/ExcelUtils.java +++ b/test/src/main/java/ExcelUtils.java @@ -3,18 +3,34 @@ import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class ExcelUtils { private static boolean isWrite = true; - private static String excelPath ="tmp/"; - private static String path = "C:/ljsd/jieling_conf/"; + private static String excelPath ="D:/tmp/"; //excel 文件 + private static String path = "conf/server/"; + private static Set oldFileNames = new HashSet<>(); + private static String javaFilePath = "serverlogic/src/main/java/com/ljsd/jieling/config/"; public static void main(String[] args) throws IOException { + File oldfile = new File(path); + String[] list = oldfile.list(); + oldFileNames.addAll(Arrays.asList(list)); readExcelData(); + //只加载新文件 + Set newFileNames = new HashSet<>(); + File newfile = new File(path); + String[] newList = newfile.list(); + newFileNames.addAll(Arrays.asList(newList)); + newFileNames.removeAll(oldFileNames); + if(!newFileNames.isEmpty()){ + for(String newFileName : newFileNames){ + String finalNewFileName = newFileName.replaceAll(".txt", ""); + genJavaFile(finalNewFileName); + } + + } + } public static void readExcelData() throws IOException { @@ -40,6 +56,94 @@ public class ExcelUtils { } } + public static void genJavaFile(String fileName){ + + Map fieldInfo = new HashMap<>(); + File file = new File("conf/server/"+fileName +".txt"); + StringBuffer stringBuffer = new StringBuffer("package com.ljsd.jieling.config;\n" + + "\n" + + "import com.ljsd.jieling.logic.STableManager;\n" + + "import com.ljsd.jieling.logic.Table;\n" + + "\n" + + "import java.util.Map;\n" + + "\n" + + "@Table(name =\"").append(fileName).append("\")\r\n"); + stringBuffer.append("public class S").append(fileName).append(" implements BaseConfig {\n\n"); + StringBuffer getInfos = new StringBuffer(); + if(file.exists()){ + try { + BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); + String firstLine = bufferedReader.readLine(); + String secondLine = bufferedReader.readLine(); + String[] s = firstLine.split("\t"); + String[] s1 = secondLine.split("\t"); + + for(int i=0;i