iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/ModelServiceApplication.java
@@ -1,5 +1,6 @@ package com.iailab; import iail.mdk.model.common.Environment; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -24,10 +25,12 @@ properties.load(in); String mdkInitPath = properties.getProperty("mdk-init-path"); System.out.println("mdkInitPath=" + mdkInitPath); IAILMDK.initWithBean(mdkInitPath, false); System.load(mdkInitPath + File.separator + "IAIL.MDK.Mid.Windows.dll"); Environment env = new Environment(); env.init(); } catch (Exception e) { e.printStackTrace(); System.out.println("动态链接库IAILMDK初始化失败"); System.out.println("动态链接库IAIL.MDK.Mid.Windows.dll初始化失败"); } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/MdkConstant.java
@@ -18,4 +18,20 @@ * impl */ String C = "C++"; /** * Algs */ String ALGS = "Algs"; /** * libs */ String LIBS = "libs"; /** * dll */ String DLL = "dll"; /** * jar */ String JAR = "jar"; } 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); } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MdkController.java
@@ -1,32 +1,25 @@ package com.iailab.module.model.mpk.controller.admin; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.converters.longconverter.LongStringConverter; import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.iailab.framework.common.enums.CommonStatusEnum; import com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.excel.core.handler.SelectSheetWriteHandler; import com.iailab.framework.excel.core.util.ExcelUtils; import com.iailab.module.model.mpk.common.MdkConstant; import com.iailab.module.model.mpk.common.utils.Readtxt; import com.iailab.module.model.mpk.dto.MdkDTO; import com.iailab.module.system.enums.common.SexEnum; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.File; import java.lang.reflect.Method; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.*; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import static com.iailab.framework.common.pojo.CommonResult.error; import static com.iailab.framework.common.pojo.CommonResult.success; @@ -39,8 +32,30 @@ @RestController @RequestMapping("/model/mpk/api") public class MdkController { @Value("${mpk.bak-file-path}") private String mpkBakFilePath; @PostMapping("run") public CommonResult<String> run(@RequestBody MdkDTO dto) { try { File jarFile = new File(mpkBakFilePath + File.separator + MdkConstant.JAR + File.separator + dto.getPyName() + ".jar"); if (!jarFile.exists()) { throw new RuntimeException("jar包不存在,请先生成代码。jarPath:" + jarFile.getAbsolutePath()); } File dllFile = new File(mpkBakFilePath + File.separator + MdkConstant.DLL + File.separator + dto.getPyName() + ".dll"); if (!dllFile.exists()) { throw new RuntimeException("dllw文件不存在,请先生成代码。dllPath:" + dllFile.getAbsolutePath()); } // 加载jar包 loadJar(jarFile.getAbsolutePath()); // 加载dll System.load(dllFile.getAbsolutePath()); } catch (Exception e) { throw new RuntimeException("加载运行环境失败。"); } System.out.println("runTime=" + System.currentTimeMillis()); try { List<String> datas = dto.getDatas(); @@ -103,4 +118,19 @@ } return success(result); } private void loadJar(String jarPath) throws Exception { File jarFile = new File(jarPath); if (!jarFile.exists()) { throw new Exception("jar沒有找到!"); } else { Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); boolean accessible = method.isAccessible(); method.setAccessible(true); URLClassLoader classLoader = (URLClassLoader)ClassLoader.getSystemClassLoader(); URL url = jarFile.toURI().toURL(); method.invoke(classLoader, url); method.setAccessible(accessible); } } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MpkFileController.java
@@ -91,15 +91,19 @@ } @GetMapping("generat") public void generat(String id, String remark,String zipFileName, HttpServletResponse response) throws IOException { byte[] data = mpkFileService.generatorCode(id, remark,zipFileName); public void generat(String id, String remark,String zipFileName, HttpServletResponse response) { try { byte[] data = mpkFileService.generatorCode(id, remark,zipFileName); response.reset(); response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(zipFileName, "UTF-8") + "\""); response.addHeader("Content-Length", "" + data.length); response.setContentType("application/octet-stream; charset=UTF-8"); response.reset(); response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(zipFileName, "UTF-8") + "\""); response.addHeader("Content-Length", "" + data.length); response.setContentType("application/octet-stream; charset=UTF-8"); IOUtils.write(data, response.getOutputStream()); IOUtils.write(data, response.getOutputStream()); } catch (Exception e) { throw new RuntimeException("代码生成异常"); } } @GetMapping("packageModel") iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/dto/MdkDTO.java
@@ -15,6 +15,8 @@ public class MdkDTO implements Serializable { private static final long serialVersionUID = 1L; private String pyName; private String className; private String methodName; iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java
@@ -16,12 +16,16 @@ import com.iailab.module.model.mpk.common.MdkConstant; import com.iailab.module.model.mpk.common.utils.GenUtils; import com.iailab.module.model.mpk.dao.MpkFileDao; import com.iailab.module.model.mpk.dto.*; import com.iailab.module.model.mpk.entity.*; import com.iailab.module.model.mpk.dto.GeneratorCodeHistoryDTO; import com.iailab.module.model.mpk.dto.ModelMethodDTO; import com.iailab.module.model.mpk.dto.MpkFileDTO; import com.iailab.module.model.mpk.dto.ProjectPackageHistoryDTO; import com.iailab.module.model.mpk.entity.GeneratorCodeHistoryEntity; import com.iailab.module.model.mpk.entity.MpkFileEntity; import com.iailab.module.model.mpk.entity.ProjectPackageHistoryModelEntity; import com.iailab.module.model.mpk.service.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.Velocity; @@ -32,10 +36,8 @@ import org.springframework.web.multipart.MultipartFile; import java.io.*; import java.nio.file.Files; import java.util.*; import java.util.stream.Collectors; import java.util.zip.ZipOutputStream; /** * @author PanZhibao @@ -61,8 +63,11 @@ @Autowired private ConfigApi configApi; @Value("${mpk.bakFilePath}") @Value("${mpk.bak-file-path}") private String mpkBakFilePath; @Value("${mpk.bak-resources}") private String mpkResources; /*@PostConstruct public void init() { @@ -169,46 +174,110 @@ @Override public byte[] generatorCode(String id, String remark, String zipFileName) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(outputStream); MpkFileDTO entity = baseDao.get(id); //生成代码 GenUtils.generatorCode(entity, zip); IOUtils.closeQuietly(zip); //设置velocity资源加载器 Properties prop = new Properties(); prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); Velocity.init(prop); File file = null; OutputStream fileOutputStream = null; //文件备份 try { String dirPath = mpkBakFilePath; File dir = new File(dirPath); if (!dir.exists()) { dir.mkdirs(); } String filePath = dirPath + File.separator + zipFileName; file = new File(filePath); file.createNewFile(); fileOutputStream = Files.newOutputStream(file.toPath()); IOUtils.write(outputStream.toByteArray(), fileOutputStream); } catch (IOException e) { log.error("生成代码文件备份失败," + entity.getPyName(), e); throw new RuntimeException(e); } finally { IOUtils.closeQuietly(fileOutputStream); } //封装模板数据 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 dataContext = new VelocityContext(map); //临时文件夹 File dirPath = new File("D:/DLUT/tmp/"); dirPath.deleteOnExit(); dirPath.mkdirs(); List<String> javaFilePaths = new ArrayList<>(); List<String> cppFilePaths = new ArrayList<>(); //生成java文件 File javaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + entity.getPkgName().replace(".", File.separator) + File.separator + entity.getPyName() + ".java"); GenUtils.drawTemplate("abstract.java.vm", dataContext, javaFile); javaFilePaths.add(javaFile.getAbsolutePath()); //生成Impl.java文件 File implJavaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + entity.getPkgName().replace(".", File.separator) + File.separator + MdkConstant.IMPL + File.separator + entity.getPyName() + "Impl.java"); GenUtils.drawTemplate("impl.java.vm", dataContext, implJavaFile); javaFilePaths.add(implJavaFile.getAbsolutePath()); //生成.cpp文件 File cppFile = new File(dirPath.getAbsolutePath() + File.separator + MdkConstant.C + File.separator + entity.getPyName() + ".cpp"); GenUtils.drawTemplate("cpp.vm", dataContext, cppFile); cppFilePaths.add(cppFile.getAbsolutePath()); //生成Jni.cpp文件 File jniCppFile = new File(dirPath.getAbsolutePath() + File.separator + MdkConstant.C + File.separator + entity.getPyName() + "Jni.cpp"); GenUtils.drawTemplate("Jni.cpp.vm", dataContext, jniCppFile); cppFilePaths.add(jniCppFile.getAbsolutePath()); //生成.h文件 File hFile = new File(dirPath.getAbsolutePath() + File.separator + MdkConstant.C + File.separator + entity.getPyName() + ".h"); GenUtils.drawTemplate("h.vm", dataContext, hFile); //生成Jni.h文件 File jniHFile = new File(dirPath.getAbsolutePath() + File.separator + MdkConstant.C + File.separator + entity.getPyName() + "Jni.h"); GenUtils.drawTemplate("Jni.h.vm", dataContext, jniHFile); // 资源文件 FileUtil.copy(mpkResources + File.separator + "libs", dirPath.getAbsolutePath(), true); //生成dll文件 String dllSavePath = dirPath.getAbsolutePath() + File.separator + MdkConstant.LIBS + File.separator + "IAIL.MDK.Mid.Jni.dll"; createDllFile(dirPath.getAbsolutePath(),cppFilePaths,dllSavePath); //备份dll文件,用于后续运行 String dllBakPath = mpkBakFilePath + File.separator + MdkConstant.DLL + File.separator + entity.getPyName() + ".dll"; FileUtil.mkParentDirs(dllBakPath); FileUtil.copy(dllSavePath, dllBakPath, true); //utils + env java文件 File utilsJavaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + "iail" + File.separator + "mdk" + File.separator + "model" + File.separator + "utils" + File.separator + "AlgsUtils.java"); FileUtil.mkParentDirs(utilsJavaFile); FileUtil.copy(mpkResources + File.separator +"IAILMDK/utils/AlgsUtils.java", utilsJavaFile.getAbsolutePath(), true); javaFilePaths.add(utilsJavaFile.getAbsolutePath()); File envJavaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + "iail" + File.separator + "mdk" + File.separator + "model" + File.separator + "common" + File.separator + "Environment.java"); FileUtil.mkParentDirs(envJavaFile); FileUtil.copy(mpkResources + File.separator +"IAILMDK/common/Environment.java", envJavaFile.getAbsolutePath(), true); javaFilePaths.add(envJavaFile.getAbsolutePath()); // 生成class文件 createClassFile(javaFilePaths); // 删除java源文件 deleteJavaFile(javaFilePaths); // 打jar包 String jarSavePath = pkgJar(dirPath.getAbsolutePath()); //备份jar文件,用于后续运行 String jarBakPath = mpkBakFilePath + File.separator + MdkConstant.JAR + File.separator + entity.getPyName() + ".jar"; FileUtil.mkParentDirs(dllBakPath); FileUtil.copy(jarSavePath, jarBakPath, true); // 打zip包 String zipPath = mpkBakFilePath + File.separator + zipFileName; ZipUtil.zip(dirPath.getAbsolutePath(), zipPath); byte[] bytes = FileUtil.readBytes(zipPath); //代码生成历史记录 GeneratorCodeHistoryEntity historyEntity = new GeneratorCodeHistoryEntity(); historyEntity.setId(UUID.randomUUID().toString()); historyEntity.setMdkId(id); historyEntity.setFileName(file.getName()); historyEntity.setFilePath(file.getAbsolutePath()); historyEntity.setFileName(zipFileName); historyEntity.setFilePath(zipPath); historyEntity.setRemark(remark); historyEntity.setCreateTime(new Date()); generatorCodeHistoryService.insert(historyEntity); return outputStream.toByteArray(); // 删除临时文件 try { FileUtils.deleteDirectory(dirPath); } catch (IOException e) { throw new RuntimeException("删除临时文件异常"); } return bytes; } @Override @@ -217,15 +286,14 @@ List<MpkFileDTO> entities = baseDao.selectByIds(ids); //模板数据 Map<String, Object> map = new HashMap<>(); map.put("entities", entities); VelocityContext context = new VelocityContext(map); // Map<String, Object> map = new HashMap<>(); // map.put("entities", entities); // VelocityContext context = new VelocityContext(map); //临时文件夹 File dirPath = new File("C:/DLUT/tmp/"); if (!dirPath.exists()) { dirPath.mkdirs(); } File dirPath = new File("D:/DLUT/tmp/"); dirPath.deleteOnExit(); dirPath.mkdirs(); //设置velocity资源加载器 Properties prop = new Properties(); @@ -236,11 +304,8 @@ LinkedHashMap<String, LinkedHashMap<String, List<MpkFileDTO>>> collect = entities.stream().collect(Collectors.groupingBy(MpkFileDTO::getMenuName, LinkedHashMap::new, Collectors.groupingBy(e -> StringUtils.isNotBlank(e.getGroupName()) ? e.getGroupName() : "default_group",LinkedHashMap::new,Collectors.toList()))); Map<String, Object> map1 = new HashMap<>(); map1.put("collects", collect); File xmlFile = new File(dirPath.getAbsolutePath() + File.separator + "menu.xml"); File xmlFile = new File(dirPath.getAbsolutePath() + File.separator + MdkConstant.LIBS + File.separator + "menu.xml"); GenUtils.drawTemplate("menu.xml.vm", new VelocityContext(map1), xmlFile); // C++源文件 FileUtil.copy("bak/C++", dirPath.getAbsolutePath(), true); List<String> javaFilePaths = new ArrayList<>(); List<String> cppFilePaths = new ArrayList<>(); @@ -283,23 +348,26 @@ GenUtils.drawTemplate("Jni.h.vm", dataContext, jniHFile); // 添加python源文件 String pyFilePath = dirPath.getAbsolutePath() + File.separator + "py" + File.separator + entity.getPyName() + ".pyd"; String pyFilePath = dirPath.getAbsolutePath() + File.separator + MdkConstant.ALGS + File.separator + entity.getPyModule().replace(".", File.separator) + File.separator + entity.getPyName() + ".pyd"; FileUtil.mkParentDirs(pyFilePath); FileUtil.copy(entity.getFilePath(), pyFilePath, true); } // 资源文件 FileUtil.copy(mpkResources + File.separator + "libs", dirPath.getAbsolutePath(), true); //生成dll文件 String dllSavePath = dirPath.getAbsolutePath() + File.separator + "IAIL.MDK.Mid.Windows.dll"; String dllSavePath = dirPath.getAbsolutePath() + File.separator + MdkConstant.LIBS + File.separator + "IAIL.MDK.Mid.Jni.dll"; createDllFile(dirPath.getAbsolutePath(),cppFilePaths,dllSavePath); //utils + env java文件 File utilsJavaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + "utils" + File.separator + "AlgsUtils.java"); File utilsJavaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + "iail" + File.separator + "mdk" + File.separator + "model" + File.separator + "utils" + File.separator + "AlgsUtils.java"); FileUtil.mkParentDirs(utilsJavaFile); FileUtil.copy("bak/IAILMDK/utils/AlgsUtils.java", utilsJavaFile.getAbsolutePath(), true); FileUtil.copy(mpkResources + File.separator +"IAILMDK/utils/AlgsUtils.java", utilsJavaFile.getAbsolutePath(), true); javaFilePaths.add(utilsJavaFile.getAbsolutePath()); File envJavaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + "common" + File.separator + "Environment.java"); File envJavaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + "iail" + File.separator + "mdk" + File.separator + "model" + File.separator + "common" + File.separator + "Environment.java"); FileUtil.mkParentDirs(envJavaFile); FileUtil.copy("bak/IAILMDK/common/Environment.java", envJavaFile.getAbsolutePath(), true); FileUtil.copy(mpkResources + File.separator +"IAILMDK/common/Environment.java", envJavaFile.getAbsolutePath(), true); javaFilePaths.add(envJavaFile.getAbsolutePath()); // 生成class文件 createClassFile(javaFilePaths); @@ -347,32 +415,29 @@ projectPackageHistoryModelService.insertBatch(historyModelList); // 删除临时文件 FileUtils.deleteDirectory(dirPath); // FileUtils.delete(new File(zipPath)); return bytes; } private void createDllFile(String dirPath, List<String> cppFilePaths, String dllSavePath) throws InterruptedException, IOException { cppFilePaths.add(dirPath + File.separator + "C++" + File.separator + "pch.cpp"); cppFilePaths.add(dirPath + File.separator + "C++" + File.separator + "dllmain.cpp"); cppFilePaths.add(dirPath + File.separator + "C++" + File.separator + "Environment.cpp"); cppFilePaths.add(dirPath + File.separator + "C++" + File.separator + "pyutils.cpp"); cppFilePaths.add(dirPath + File.separator + "C++" + File.separator + "convertutils.cpp"); String paths = cppFilePaths.stream().collect(Collectors.joining(" ")); String command = "cl /LD " + paths + " /EHsc /o " + dllSavePath; // String command = "cmd.exe /c cl -o " + dllSavePath + " /LD D:\\work\\mdk\\code\\makeDll\\src\\main\\java\\org\\example\\MakeDll.c D:\\work\\mdk\\code\\makeDll\\src\\main\\java\\org\\example\\MakeDll2.c"; log.info("执行cmd命令生成dll:" + command); ProcessBuilder builder = new ProcessBuilder("cmd", "/c", command); builder.directory(new File(dirPath + File.separator + "C++")); Process process = builder.start(); // 获取命令输出结果 InputStream inputStream = process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "GBK")); // 设置编码为GBK String line; while ((line = reader.readLine()) != null) { System.out.println(line); private void createDllFile(String dirPath, List<String> cppFilePaths, String dllSavePath) { try { String paths = cppFilePaths.stream().collect(Collectors.joining(" ")); String command = "cl /LD " + paths + " /EHsc /o " + dllSavePath + " /link " + "IAIL.MDK.Mid.Windows.lib"; log.info("执行cmd命令生成dll:" + command); ProcessBuilder builder = new ProcessBuilder("cmd", "/c", command); builder.directory(new File(dirPath + File.separator + MdkConstant.LIBS)); Process process = builder.start(); // 获取命令输出结果 InputStream inputStream = process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "GBK")); // 设置编码为GBK String line; while ((line = reader.readLine()) != null) { log.info(line); } // 等待命令执行完成 process.waitFor(); } catch (Exception e) { throw new RuntimeException("执行cmd命令生成dll异常"); } // 等待命令执行完成 process.waitFor(); } @Override @@ -382,7 +447,9 @@ dir.mkdirs(); } String fileName = file.getOriginalFilename(); File saveFile = new File(dir.getAbsolutePath() + File.separator + fileName); String fileSuffix = fileName.substring(fileName.lastIndexOf(".")); File saveFile = new File(dir.getAbsolutePath() + File.separator + UUID.randomUUID() + fileSuffix); saveFile.createNewFile(); // 保存 file.transferTo(saveFile); @@ -415,14 +482,20 @@ GenUtils.drawTemplate("log.txt.vm", data, logFile); } private void pkgJar(String dirPath) throws InterruptedException { StringBuilder sb = new StringBuilder(); sb.append("jar -cvf"); sb.append(" ").append(dirPath).append(File.separator).append("IAILMDK.jar"); sb.append(" -C ").append(dirPath).append(File.separator).append("IAILMDK").append(File.separator).append(" ."); log.info("执行cmd命令打jar包:" + sb); Process process = RuntimeUtil.exec(sb.toString()); process.waitFor(); private String pkgJar(String dirPath) { try { String jarSavePath = dirPath + File.separator + MdkConstant.LIBS + File.separator + "IAILMDK.jar"; StringBuilder sb = new StringBuilder(); sb.append("jar -cvf"); sb.append(" ").append(jarSavePath); sb.append(" -C ").append(dirPath).append(File.separator).append("IAILMDK").append(File.separator).append(" ."); log.info("执行cmd命令打jar包:" + sb); Process process = RuntimeUtil.exec(sb.toString()); process.waitFor(); return jarSavePath; } catch (InterruptedException e) { throw new RuntimeException("执行cmd命令打jar包异常"); } } private void deleteJavaFile(List<String> javaFilePaths) { @@ -431,14 +504,18 @@ } } private void createClassFile(List<String> javaFilePaths) throws InterruptedException { StringBuilder sb = new StringBuilder(); sb.append("javac -encoding utf-8"); for (String path : javaFilePaths) { sb.append(" ").append(path); private void createClassFile(List<String> javaFilePaths){ try { StringBuilder sb = new StringBuilder(); sb.append("javac -encoding utf-8"); for (String path : javaFilePaths) { sb.append(" ").append(path); } log.info("执行cmd命令生成class:" + sb); Process process = RuntimeUtil.exec(sb.toString()); process.waitFor(); } catch (InterruptedException e) { throw new RuntimeException("执行cmd命令生成class异常"); } log.info("执行cmd命令生成class:" + sb); Process process = RuntimeUtil.exec(sb.toString()); process.waitFor(); } } iailab-module-model/iailab-module-model-biz/src/main/resources/application-dev.yml
@@ -49,5 +49,6 @@ # password: 123456 mpk: bakFilePath: D:\DLUT\mpkBakFile bak-file-path: D:\DLUT\mpkBakFile bak-resources: D:\DLUT\mpkResources model-file-path: D:\DLUT\MDK\Model\miail\ iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/Environment.cpp
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/PyGILThreadLock.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/convertutils.cpp
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/dllmain.cpp
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/Environment.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/PyGILThreadLock.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/PyGILThreadLock_bak.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/convertutils.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/framework.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/jawt.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/jawt_md.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/jdwpTransport.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/jni.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/jni_md.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/jvmti.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/jvmticmlr.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/opt.cpp
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/pch.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/pyutils.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/stdafx.cpp
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/stdafx.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/include/targetver.h
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/pch.cpp
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/C++/pyutils.cpp
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/IAILMDK/common/Environment.java
@@ -1,4 +1,4 @@ package common; package iail.mdk.model.common; /** * @Description iailab-module-model/iailab-module-model-biz/src/main/resources/bak/IAILMDK/utils/AlgsUtils.java
@@ -1,4 +1,4 @@ package utils; package iail.mdk.model.utils; import java.util.HashMap; iailab-module-model/iailab-module-model-biz/src/main/resources/bak/libs/IAIL.MDK.Mid.Windows.dllBinary files differ
iailab-module-model/iailab-module-model-biz/src/main/resources/bak/libs/status_code.xml
对比新文件 @@ -0,0 +1,20 @@ <status-codes> <status-code code="100" tips="系统正常运行"/> <status-code code="200" tips="算法模块加载失败"/> <status-code code="201" tips="算法方法加载失败"/> <status-code code="202" tips="类型不匹配"/> <status-code code="203" tips="找不到模型存储路径"/> <status-code code="204" tips="模型参数文件加载失败"/> <status-code code="205" tips="计算过程中的数据或数组维度不匹配"/> <status-code code="206" tips="数值错误"/> <status-code code="207" tips="第三方库问题"/> <status-code code="208" tips="评价指标计算错误"/> <status-code code="209" tips="数据长度问题"/> <status-code code="210" tips="初始化失败"/> <status-code code="211" tips="train/predict函数输入格式错误"/> <status-code code="212" tips="train/predict函数输出格式错误"/> <status-code code="300" tips="MDK未配置"/> <status-code code="301" tips="缺少依赖库"/> <status-code code="400" tips="系统异常,未知错误"/> <status-code code="401" tips="未能进入 Python"/> </status-codes> iailab-module-model/iailab-module-model-biz/src/main/resources/bak/libs/version.xml
对比新文件 @@ -0,0 +1,30 @@ <algorithm-list name="算法版本列表"> <!-- 说明:version="0.11" 即现行算法未显式标注版本的算法--> <algorithms name = "预测"> <algorithm name="非周期短期点预测" type="非周期完整数据" fileName="PredAperioComShortPoint" version="2.0"/> <algorithm name="类周期短期点预测" type="类周期完整数据" fileName="PredPerioComShortPoint" version="2.0"/> <algorithm name="中长期点预测" type="类周期完整数据" fileName="PredPerioComLongPoint" version="0.9.1"/> <algorithm name="N型数据集点预测" type="N型" fileName="PredNTypeComShortPoint" version="0.20.0"/> <algorithm name="调整用户短期点预测" type="阶跃" fileName="PredStepComShortPoint" version="1.0.5"/> <algorithm name="因素预测" type="短期点预测" fileName="PredFactComShortPoint" version="1.1.13"/> </algorithms> <algorithms name="数据预处理"> <algorithm name="滤波" fileName="PrepFilter" version="1.2.6"/> <algorithm name="数据填补" fileName="PrepDaImput" version="0.12.0"/> <algorithm name="异常点检测" fileName="PrepOutDetect" version="1.2.3"/> <algorithm name="特征选择" fileName="prepFeaSelect" version="0.9.5"/> </algorithms> <algorithms name="调度"> <algorithm name="单介质调度" fileName="scheSingleEgy" version="1.0.1"/> <algorithm name="热电调度" fileName="MSCoSchedul" version="1.0.1"/> <algorithm name="调度建议" fileName="schedulSuggest" version="1.0.1"/> </algorithms> </algorithm-list> iailab-module-model/iailab-module-model-biz/src/main/resources/template/cpp.vm
@@ -80,7 +80,7 @@ cout << "ConvertPydictToJhmap error" << endl; throw "函数返回值异常!"; } delete pModule; /*delete pModule; pModule = nullptr; delete pModule; @@ -106,7 +106,7 @@ delete[] pArg; pArg = nullptr; delete pArg; delete pArg;*/ return result; } iailab-module-model/iailab-module-model-biz/src/main/resources/template/impl.java.vm
@@ -1,7 +1,7 @@ package ${pkgName}.impl; import ${pkgName}.${pyName}; import utils.AlgsUtils; import iail.mdk.model.utils.AlgsUtils; import java.util.HashMap;