From 1fea3eea8bf676ac6cf35c6b98e42efdbc5b897e Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期日, 29 九月 2024 11:50:08 +0800
Subject: [PATCH] 模型生成代码后备份dll和jar,用于测试运行模型

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/GenUtils.java |   97 ++++++------------------------------------------
 1 files changed, 13 insertions(+), 84 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/GenUtils.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/GenUtils.java
index e411574..b1a1611 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/GenUtils.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/GenUtils.java
@@ -21,81 +21,6 @@
 
 @Slf4j
 public class GenUtils {
-    public static List<String> getTemplates(){
-        List<String> templates = new ArrayList<String>();
-        templates.add("abstract.java.vm");
-        templates.add("impl.java.vm");
-        templates.add("cpp.vm");
-        templates.add("Jni.cpp.vm");
-        templates.add("h.vm");
-        templates.add("Jni.h.vm");
-        return templates;
-    }
-    /**
-     * 生成代码
-     */
-    public static void generatorCode(MpkFileDTO entity, ZipOutputStream zip){
-        //设置velocity资源加载器
-        Properties prop = new Properties();
-        prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
-        Velocity.init(prop);
-
-        //封装模板数据
-        Map<String, Object> map = new HashMap<>();
-        map.put("pkgName",entity.getPkgName());
-        map.put("modelMethods",entity.getModelMethods());
-        map.put("pyName",entity.getPyName());
-        map.put("pyModule",entity.getPyModule());
-
-        VelocityContext context = new VelocityContext(map);
-
-        //获取模板列表
-        List<String> templates = getTemplates();
-        for(String template : templates){
-            //渲染模板
-            StringWriter sw = drawTemplate(template,context);
-
-            try {
-                //添加到zip
-                zip.putNextEntry(new ZipEntry(getFileName(template, entity.getPyName(),entity.getPkgName(),entity.getPyModule())));
-                IOUtils.write(sw.toString(), zip, "UTF-8");
-                IOUtils.closeQuietly(sw);
-                zip.closeEntry();
-            } catch (IOException e) {
-                log.error("渲染模板失败,模型名称:" + entity.getPyName(), e);
-                throw new RuntimeException("渲染模板失败,模型名称:" + entity.getPyName(), e);
-            }
-        }
-    }
-
-    /**
-     * 获取文件名
-     */
-    public static String getFileName(String template, String moduleName, String pkgName, String pyModule) {
-        // java
-        if (template.equals("abstract.java.vm")) {
-            return pkgName.replace(".", File.separator) + File.separator + moduleName + ".java";
-        }
-        if (template.equals("impl.java.vm")) {
-            return pkgName.replace(".", File.separator) + File.separator + MdkConstant.IMPL + File.separator + moduleName + "Impl.java";
-        }
-        // c++
-        if (template.equals("cpp.vm")) {
-            return pyModule.replace(".", File.separator) + File.separator + moduleName + ".cpp";
-        }
-        if (template.equals("h.vm")) {
-            return pyModule.replace(".", File.separator) + File.separator + moduleName + ".h";
-        }
-        // Jni c++
-        if (template.equals("Jni.cpp.vm")) {
-            return pyModule.replace(".", File.separator) + File.separator + MdkConstant.JNI + File.separator + moduleName + "Jni.cpp";
-        }
-        if (template.equals("Jni.h.vm")) {
-            return pyModule.replace(".", File.separator) + File.separator + MdkConstant.JNI + File.separator + moduleName + "Jni.h";
-        }
-        return null;
-    }
-
     /**
      * 渲染模板
      **/
@@ -116,21 +41,25 @@
         return writer;
     }
 
-    public static void drawTemplate(String template,Map<String, Object> map,File toFile) throws IOException {
+    public static void drawTemplate(String template,Map<String, Object> map,File toFile) {
         VelocityContext context = new VelocityContext(map);
         drawTemplate(template,context,toFile);
     }
 
-    public static void drawTemplate(String template,VelocityContext context,File toFile) throws IOException {
-        StringWriter writer = drawTemplate(template,context);
+    public static void drawTemplate(String template,VelocityContext context,File toFile) {
+        try {
+            StringWriter writer = drawTemplate(template,context);
 
-        FileUtil.mkParentDirs(toFile);
+            FileUtil.mkParentDirs(toFile);
 
-        if (!toFile.exists()) {
-            toFile.createNewFile();
+            if (!toFile.exists()) {
+                toFile.createNewFile();
+            }
+
+            FileUtil.writeUtf8String(writer.toString(),toFile);
+            IOUtils.closeQuietly(writer);
+        } catch (IOException e) {
+            throw new RuntimeException("模板渲染异常");
         }
-
-        FileUtil.writeUtf8String(writer.toString(),toFile);
-        IOUtils.closeQuietly(writer);
     }
 }

--
Gitblit v1.9.3