From ab8d7d27e2cb284a020fa6c1411e20f6a10ba20c Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期二, 20 一月 2026 16:00:01 +0800
Subject: [PATCH] 经销商管理
---
server/dmmall_service/src/main/java/com/doumee/core/utils/CodeGenerator.java | 79 ++++++++++++++++++++++-----------------
1 files changed, 44 insertions(+), 35 deletions(-)
diff --git a/server/dmmall_service/src/main/java/com/doumee/core/utils/CodeGenerator.java b/server/dmmall_service/src/main/java/com/doumee/core/utils/CodeGenerator.java
index 7e38616..b729a3a 100644
--- a/server/dmmall_service/src/main/java/com/doumee/core/utils/CodeGenerator.java
+++ b/server/dmmall_service/src/main/java/com/doumee/core/utils/CodeGenerator.java
@@ -16,18 +16,42 @@
// 婕旂ず渚嬪瓙锛屾墽琛� main 鏂规硶鎺у埗鍙拌緭鍏ユā鍧楄〃鍚嶅洖杞﹁嚜鍔ㄧ敓鎴愬搴旈」鐩洰褰曚腑
public class CodeGenerator {
-public static String packName ="com.doumee";
+ public static String packName ="com.doumee";
+ // 璁剧疆杈撳嚭鐩綍
+ public static String rootFileDir = "D:/code/idea/initCode/";
+ public static String outputDirEntity =rootFileDir+"src/main/java/com/doumee/dao/business/model/"; // 杈撳嚭鐨勪唬鐮佹枃浠跺す璺緞
+ public static String outputDirMapper = rootFileDir+"src/main/java/com/doumee/dao/business/"; // 杈撳嚭鐨勪唬鐮佹枃浠跺す璺緞
+ public static String outputDirService =rootFileDir+"src/main/java/com/doumee/service/business/"; // 杈撳嚭鐨勪唬鐮佹枃浠跺す璺緞
+ public static String outputDirServiceImpl = rootFileDir+"src/main/java/com/doumee/service/business/impl/"; // 杈撳嚭鐨勪唬鐮佹枃浠跺す璺緞
+ public static String outputDirController =rootFileDir+"src/main/java/com/doumee/api/business/"; // 杈撳嚭鐨勪唬鐮佹枃浠跺す璺緞
+ public static String outputDirDb =rootFileDir+"db/"; // 杈撳嚭鐨勪唬鐮佹枃浠跺す璺緞
public static void main(String[] args) {
// 閰嶇疆鏁版嵁搴撹繛鎺�
String url = "jdbc:mysql://192.168.0.211:3306/dmmall_full";
String username = "root";
String password = "Doumee@168";
String database = "dmmall_full";
- String tableName = "car_driver";
- // 鑾峰彇琛ㄤ俊鎭苟鐢熸垚浠g爜
- Map<String, Object> tableInfo = getTableInfo(url, username, password, database, tableName);
- generateCode(tableInfo);
+ List<String> tables = new ArrayList<>();
+ tables.add("member");
+ tables.add("labels");
+ tables.add("goods");
+ tables.add("goodsorder");
+ tables.add("integral");
+
+ for(String tableName : tables){
+ // 鑾峰彇琛ㄤ俊鎭苟鐢熸垚浠g爜
+ try {
+ System.out.println(tableName+"===================鐢熸垚寮�濮�===================");
+ Map<String, Object> tableInfo = getTableInfo(url, username, password, database, tableName);
+ generateCode(tableInfo);
+ System.out.println(tableName+"===================鐢熸垚缁撴潫===================");
+ }catch (Exception e){
+ System.err.println(tableName+"===================鐢熸垚寮傚父==================="+e.getMessage());
+ }
+ }
+
}
+
public static Map<String, Object> getTableInfo(String url, String username, String password, String database, String tableName) {
Map<String, Object> map = new HashMap<>();
@@ -117,42 +141,22 @@
String tableComment = (String) tableInfo.get("tableComment");
List<Map<String, String>> columns = (List<Map<String, String>>) tableInfo.get("columns");
- String templateDir = "D:\\code\\idea\\doumee_code\\server\\src\\main\\resources\\templates"; // 妯℃澘鏂囦欢鐨勮矾寰�
- Properties p = new Properties();
- // 鎸囧畾妯℃澘鐨勫姞杞戒綅缃�
- p.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, templateDir);
- // 鎸囧畾杈撳叆缂栫爜
- p.setProperty(VelocityEngine.INPUT_ENCODING, "UTF-8");
-
- p.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
- p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
- p.setProperty("velocimacro.library", "macro_library.vm"); // 璁剧疆瀹忓簱鏂囦欢鍚�
- p.setProperty("velocimacro.library.autoreload", "true"); // 鍏佽鑷姩閲嶆柊鍔犺浇瀹忓簱
- p.setProperty("velocimacro.permissions.allow.inline.to.replace.global", "true"); // 鍏佽鍐呰仈瀹忔浛鎹㈠叏灞�瀹�
- p.setProperty("velocimacro.library", "/templates/macro_library.vm"); // 璁剧疆瀹忓簱鏂囦欢鍚�
- p.setProperty("velocimacro.library.autoreload", "true"); // 鍏佽鑷姩閲嶆柊鍔犺浇瀹忓簱
// 璁剧疆 Velocity 閰嶇疆
VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityEngine.init();
-
// 閰嶇疆妯℃澘鐩綍
-
-
- // 璁剧疆杈撳嚭鐩綍
- String outputDir = "D:\\code\\idea\\doumee_code\\server\\src\\main\\java\\com\\testcom"; // 杈撳嚭鐨勪唬鐮佹枃浠跺す璺緞
-
String baseName = entityName.substring(0, 1).toUpperCase() + entityName.substring(1);
// 鍒涘缓 Velocity 涓婁笅鏂�
Map<String,String> pack = new HashMap<>();
pack.put("Base",packName);
- pack.put("Entity",packName+".dao.businees.model");
- pack.put("Controller",packName+".api.businees");
- pack.put("Mapper",packName+".dao.businees");
- pack.put("Service",packName+".service.businees");
- pack.put("ServiceImpl",packName+".service.businees.impl");
+ pack.put("Entity",packName+".dao.business.model");
+ pack.put("Controller",packName+".api.business");
+ pack.put("Mapper",packName+".dao.business");
+ pack.put("Service",packName+".service.business");
+ pack.put("ServiceImpl",packName+".service.business.impl");
VelocityContext context = new VelocityContext();
context.put("package",pack); // 璁剧疆鍖呰矾寰�
context.put("entityName", baseName);
@@ -164,19 +168,20 @@
context.put("nowDate", DateUtil.getPlusTime2(new Date()));
// 鐢熸垚 Entity 鏂囦欢
- generateFile(velocityEngine, context, "entity.vm", baseName, outputDir + "/dao/businees/model/" , ".java");
+ generateFile(velocityEngine, context, "entity.vm", baseName, outputDirEntity , ".java");
// 鐢熸垚 Mapper 鏂囦欢
- generateFile(velocityEngine, context, "mapper.vm", baseName, outputDir + "/dao/businees/" , "Mapper.java");
+ generateFile(velocityEngine, context, "mapper.vm", baseName, outputDirMapper , "Mapper.java");
// 鐢熸垚 Service 鎺ュ彛鏂囦欢
- generateFile(velocityEngine, context, "service.vm", baseName, outputDir + "/service/businees/" , "Service.java");
+ generateFile(velocityEngine, context, "service.vm", baseName, outputDirService , "Service.java");
// 鐢熸垚 ServiceImpl 鏂囦欢
- generateFile(velocityEngine, context, "serviceImpl.vm", baseName, outputDir + "/service/businees/impl/" , "ServiceImpl.java");
+ generateFile(velocityEngine, context, "serviceImpl.vm", baseName, outputDirServiceImpl + "" , "ServiceImpl.java");
// 鐢熸垚 Controller 鏂囦欢
- generateFile(velocityEngine, context, "controller.vm", baseName, outputDir + "/api/businees/", "Controller.java");
+ generateFile(velocityEngine, context, "controller.vm", baseName, outputDirController , "Controller.java");
+ generateFile(velocityEngine, context, "db.vm", baseName, outputDirDb , "Permissions.sql");
}
private static void generateFile(VelocityEngine velocityEngine, VelocityContext context, String templateName, String baseName,String outputFilePath,String endName) {
@@ -190,6 +195,8 @@
// 鍒涘缓鏂囦欢杈撳嚭娴�
try{
+
+ System.out.println(outputFilePath+baseName+endName+"===================鐢熸垚寮�濮�===================");
File f = new File(outputFilePath+baseName+endName);
if(f.isFile()){
f.delete();
@@ -200,7 +207,9 @@
template.merge(context, writer);
writer.flush();
writer.close();
+ System.out.println(outputFilePath+baseName+endName+"===================鐢熸垚缁撴潫===================");
} catch (IOException e) {
+ System.err.println(outputFilePath+baseName+endName+"===================鐢熸垚寮傚父===================");
e.printStackTrace();
}
}
--
Gitblit v1.9.3