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/resources/templates/controller.vm | 2
server/dmmall_admin/src/main/java/com/doumee/api/BaseController.java | 17 ++++++++
server/dmmall_service/src/main/java/com/doumee/core/utils/CodeGenerator.java | 79 ++++++++++++++++++++++-----------------
server/dmmall_service/src/main/resources/templates/db.vm | 6 +++
4 files changed, 68 insertions(+), 36 deletions(-)
diff --git a/server/dmmall_admin/src/main/java/com/doumee/api/BaseController.java b/server/dmmall_admin/src/main/java/com/doumee/api/BaseController.java
index fd5ef6c..c0d1883 100644
--- a/server/dmmall_admin/src/main/java/com/doumee/api/BaseController.java
+++ b/server/dmmall_admin/src/main/java/com/doumee/api/BaseController.java
@@ -3,11 +3,14 @@
import com.doumee.config.Jwt.JwtTokenUtil;
import com.doumee.core.model.LoginUserInfo;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.List;
/**
* Controller鍩虹被
@@ -47,5 +50,19 @@
return obj != null ? (Integer) obj : null;
}
+ public List<Integer> getIdList(String ids){
+ if(StringUtils.isBlank(ids)){
+ return null;
+ }
+ String [] idArray = ids.split(",");
+ List<Integer> idList = new ArrayList<>();
+ for (String id : idArray) {
+ try {
+ idList.add(Integer.valueOf(id));
+ }catch (Exception e){
+ }
+ }
+ return idList;
+ }
}
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();
}
}
diff --git a/server/dmmall_service/src/main/resources/templates/controller.vm b/server/dmmall_service/src/main/resources/templates/controller.vm
index 77255ce..d6a4fdc 100644
--- a/server/dmmall_service/src/main/resources/templates/controller.vm
+++ b/server/dmmall_service/src/main/resources/templates/controller.vm
@@ -73,7 +73,7 @@
@PostMapping("/exportExcel")
@RequiresPermissions("business:${entityNameLowerFull}:exportExcel")
public void exportExcel (@RequestBody PageWrap<${entityName}> pageWrap, HttpServletResponse response) {
- ExcelExporter.build(${entityName}.class).export(${entityNameLower}Service.findPage(pageWrap).getRecords(), "鏈堝彴_浣滀笟鎿嶄綔鍘嗗彶琛�", response);
+ ExcelExporter.build(${entityName}.class).export(${entityNameLower}Service.findPage(pageWrap).getRecords(), "${tableComment}", response);
}
@ApiOperation("鏍规嵁ID鏌ヨ")
diff --git a/server/dmmall_service/src/main/resources/templates/db.vm b/server/dmmall_service/src/main/resources/templates/db.vm
new file mode 100644
index 0000000..3735148
--- /dev/null
+++ b/server/dmmall_service/src/main/resources/templates/db.vm
@@ -0,0 +1,6 @@
+INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('business:${entityNameLowerFull}:create', '鏂板缓${tableComment}', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
+INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('business:${entityNameLowerFull}:delete', '鍒犻櫎${tableComment}', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
+INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('business:${entityNameLowerFull}:update', '淇敼${tableComment}', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
+INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('business:${entityNameLowerFull}:query', '鏌ヨ${tableComment}', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
+INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('business:${entityNameLowerFull}:exportExcel', '瀵煎嚭${tableComment}(Excel)', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
+
--
Gitblit v1.9.3