| | |
| | | <groupId>com.iailab</groupId> |
| | | <artifactId>iailab-common</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.baomidou</groupId> |
| | | <artifactId>mybatis-plus-boot-starter</artifactId> <!-- 捕获mybatis全局异常 --> |
| | | </dependency> |
| | | |
| | | <!-- Spring Boot 配置所需依赖 --> |
| | | <dependency> |
| | |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| | | import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; |
| | | import org.springframework.web.servlet.NoHandlerFoundException; |
| | | import org.springframework.dao.DuplicateKeyException; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.validation.ConstraintViolation; |
| | |
| | | } |
| | | if (ex instanceof AccessDeniedException) { |
| | | return accessDeniedExceptionHandler(request, (AccessDeniedException) ex); |
| | | } |
| | | if (ex instanceof DuplicateKeyException) { |
| | | return duplicateKeyExceptionHandler((DuplicateKeyException) ex); |
| | | } |
| | | return defaultExceptionHandler(request, ex); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 处理业务异常 SQLIntegrityConstraintViolationException |
| | | * |
| | | * 数据库存在重复数据 |
| | | */ |
| | | @ExceptionHandler(value = DuplicateKeyException.class) |
| | | public CommonResult<?> duplicateKeyExceptionHandler(DuplicateKeyException ex) { |
| | | log.warn("[duplicateKeyExceptionHandler]", ex); |
| | | return CommonResult.error(DATA_REPETITION.getCode(), DATA_REPETITION.getMsg()); |
| | | } |
| | | |
| | | /** |
| | | * 处理业务异常 ServiceException |
| | | * |
| | | * 例如说,商品库存不足,用户手机号已存在。 |
| | |
| | | ErrorCode FORBIDDEN = new ErrorCode(403, "没有该操作权限"); |
| | | ErrorCode NOT_FOUND = new ErrorCode(404, "请求未找到"); |
| | | ErrorCode METHOD_NOT_ALLOWED = new ErrorCode(405, "请求方法不正确"); |
| | | ErrorCode DATA_REPETITION = new ErrorCode(406, "数据库存在重复数据"); |
| | | ErrorCode LOCKED = new ErrorCode(423, "请求失败,请稍后重试"); // 并发请求,不允许 |
| | | ErrorCode TOO_MANY_REQUESTS = new ErrorCode(429, "请求过于频繁,请稍后重试"); |
| | | |
| | |
| | | return result; |
| | | } |
| | | |
| | | public static CommonResult<String> success() { |
| | | CommonResult<String> result = new CommonResult<>(); |
| | | result.code = GlobalErrorCodeConstants.SUCCESS.getCode(); |
| | | result.msg = "success"; |
| | | return result; |
| | | } |
| | | |
| | | public static boolean isSuccess(Integer code) { |
| | | return Objects.equals(code, GlobalErrorCodeConstants.SUCCESS.getCode()); |
| | | } |
| | |
| | | public static final long SECOND_MILLIS = 1000; |
| | | |
| | | public static final String FORMAT_YEAR_MONTH_DAY = "yyyy-MM-dd"; |
| | | /** 时间格式(yyyy.MM.dd) */ |
| | | public final static String DATE_PATTERN_POINT = "yyyy.MM.dd"; |
| | | |
| | | public static final String FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND = "yyyy-MM-dd HH:mm:ss"; |
| | | |
| | | public final static String DATE_TIME_PATTERN_STRING = "yyyyMMddHHmmss"; |
| | | |
| | | /** |
| | | * 日期格式化 日期格式为:yyyy-MM-dd |
| | | * @param date 日期 |
| | |
| | | <maven.compiler.target>8</maven.compiler.target> |
| | | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| | | <mdk.version>MDK.taisteel.202308231710</mdk.version> |
| | | <easypoi.version>4.1.0</easypoi.version> |
| | | <commons.io.version>2.11.0</commons.io.version> |
| | | <velocity.version>1.7</velocity.version> |
| | | </properties> |
| | | |
| | | <dependencies> |
| | |
| | | <dependency> |
| | | <groupId>com.iailab</groupId> |
| | | <artifactId>iailab-module-data-api</artifactId> |
| | | <version>${revision}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.iailab</groupId> |
| | | <artifactId>iailab-module-infra-api</artifactId> |
| | | <version>${revision}</version> |
| | | </dependency> |
| | | <dependency> |
| | |
| | | <version>0.94.9</version> |
| | | </dependency> |
| | | |
| | | <!-- MPK --> |
| | | <dependency> |
| | | <groupId>cn.afterturn</groupId> |
| | | <artifactId>easypoi-base</artifactId> |
| | | <version>${easypoi.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>cn.afterturn</groupId> |
| | | <artifactId>easypoi-web</artifactId> |
| | | <version>${easypoi.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>cn.afterturn</groupId> |
| | | <artifactId>easypoi-annotation</artifactId> |
| | | <version>${easypoi.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-io</groupId> |
| | | <artifactId>commons-io</artifactId> |
| | | <version>${commons.io.version}</version> |
| | | </dependency> |
| | | <dependency> |
| | | <artifactId>velocity</artifactId> |
| | | <groupId>org.apache.velocity</groupId> |
| | | <version>${velocity.version}</version> |
| | | </dependency> |
| | | |
| | | |
| | | </dependencies> |
| | | |
| | |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import com.iail.IAILMDK; |
| | | import org.springframework.cloud.openfeign.EnableFeignClients; |
| | | import org.springframework.scheduling.annotation.EnableAsync; |
| | | |
| | | import java.io.File; |
| | | import java.io.InputStream; |
| | | import java.util.Objects; |
| | | import java.util.Properties; |
| | | |
| | | @EnableAsync |
| | |
| | | e.printStackTrace(); |
| | | System.out.println("动态链接库IAILMDK初始化失败"); |
| | | } |
| | | |
| | | try { |
| | | System.out.println("动态加载dll"); |
| | | String dllDir = Objects.requireNonNull(ModelServiceApplication.class.getClassLoader().getResource("dll")).getPath(); |
| | | File dir = new File(dllDir); |
| | | if (dir.exists()) { |
| | | File[] files = dir.listFiles(); |
| | | if (files.length > 0) { |
| | | for (File file : files) { |
| | | System.out.println("加载:" + file.getAbsolutePath()); |
| | | System.load(file.getAbsolutePath()); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | System.out.println("动态加载dll失败"); |
| | | } |
| | | |
| | | } |
| | | */ |
| | | |
| | |
| | | |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.infra.api.config.ConfigApi; |
| | | import com.iailab.module.infra.api.file.FileApi; |
| | | import com.iailab.module.system.api.tenant.TenantApi; |
| | | import com.iailab.module.system.api.user.AdminUserApi; |
| | | import org.springframework.cloud.openfeign.EnableFeignClients; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | @Configuration(proxyBeanMethods = false) |
| | | @EnableFeignClients(clients = {FileApi.class, AdminUserApi.class, ConfigApi.class, TenantApi.class, DataPointApi.class}) |
| | | @EnableFeignClients(clients = {DataPointApi.class,ConfigApi.class}) |
| | | public class RpcConfiguration { |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.common; |
| | | |
| | | /** |
| | | * @Description |
| | | * @Author Forrest |
| | | * @Mail 1255187617@qq.com |
| | | * @Date 2021/1/12 |
| | | */ |
| | | public class Environment { |
| | | private native int jniInit(); |
| | | |
| | | private native int jniIsInit(); |
| | | |
| | | private native void jniRelease(); |
| | | |
| | | private native int statusCode(); |
| | | |
| | | /** |
| | | * 初始化环境 |
| | | */ |
| | | public int init() { |
| | | return jniInit(); |
| | | } |
| | | |
| | | /** |
| | | * 获取初始化状态 |
| | | */ |
| | | public int isInit() { |
| | | return jniIsInit(); |
| | | } |
| | | |
| | | /** |
| | | * 释放资源 |
| | | */ |
| | | public void release() { |
| | | jniRelease(); |
| | | } |
| | | /** |
| | | *校验机器码 |
| | | * */ |
| | | // public int checkMachineCode(String mCode){ |
| | | // return statusCode(); |
| | | // } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.common; |
| | | |
| | | /** |
| | | * 常量 |
| | | * |
| | | * @author Mark sunlightcs@gmail.com |
| | | */ |
| | | public interface MdkConstant { |
| | | /** |
| | | * JNI |
| | | */ |
| | | String JNI = "JNI"; |
| | | /** |
| | | * impl |
| | | */ |
| | | String IMPL = "impl"; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.common.utils; |
| | | |
| | | import java.util.HashMap; |
| | | |
| | | |
| | | /** |
| | | * @Auther: Forrest |
| | | * @Date: 2020/6/8 14:05 |
| | | * @Description: |
| | | */ |
| | | public class AlgsUtils { |
| | | private HashMap<String, Object> model = new HashMap<String, Object>(); |
| | | |
| | | public HashMap<String, Object> createPredictHashmap(HashMap<String, Object> models) { |
| | | if ((models.containsKey("iail/mdk/model"))) { |
| | | if (((String) ((HashMap) models.get("iail/mdk/model")).get("param1")).isEmpty()) { |
| | | String aaa = "error"; |
| | | model.put("param1", aaa); |
| | | } else { |
| | | String model_train = (String) ((HashMap) models.get("iail/mdk/model")).get("param1"); |
| | | model.put("param1", model_train); |
| | | } |
| | | } else { |
| | | model = models; |
| | | } |
| | | return model; |
| | | } |
| | | |
| | | public HashMap<String, Object> createPredictHashmapplus(HashMap<String, Object> models) { |
| | | if (models != null && models.containsKey("models")) { |
| | | if (((String) ((HashMap) models.get("models")).get("paramFile")).isEmpty()) { |
| | | String aaa = "error"; |
| | | model.put("param1", aaa); |
| | | } else { |
| | | String model_train = (String) ((HashMap) models.get("models")).get("paramFile"); |
| | | model.put("paramFile", model_train); |
| | | if (((HashMap) models.get("models")).containsKey("dim")) { |
| | | Object dim = ((HashMap) models.get("models")).get("dim"); |
| | | model.put("dim", dim); |
| | | } |
| | | } |
| | | } else { |
| | | model = models; |
| | | } |
| | | return model; |
| | | } |
| | | |
| | | private HashMap<String, Object> eval_pre = new HashMap<String, Object>(); |
| | | |
| | | /** |
| | | * 对返回码进行转换 |
| | | * |
| | | * @param models |
| | | * @return |
| | | */ |
| | | public int reverseResultCode(HashMap<String, Object> models) { |
| | | if ((models.containsKey("result_code"))) { |
| | | return Integer.parseInt((String) models.get("result_code")); |
| | | } |
| | | return -2; |
| | | } |
| | | |
| | | /** |
| | | * 对评价指标进行转换 |
| | | * |
| | | * @param models |
| | | * @return |
| | | */ |
| | | public HashMap<String, Object> reverseEval(HashMap<String, Object> models) { |
| | | if ((models.containsKey("eval"))) { |
| | | if (((HashMap) models.get("eval")).containsKey("MAE")) { |
| | | double MAE = Double.parseDouble((String) ((HashMap) models.get("eval")).get("MAE")); |
| | | eval_pre.put("MAE", MAE); |
| | | } |
| | | if (((HashMap) models.get("eval")).containsKey("MAPE")) { |
| | | double MAPE = Double.parseDouble((String) ((HashMap) models.get("eval")).get("MAPE")); |
| | | eval_pre.put("MAPE", MAPE); |
| | | } |
| | | if (((HashMap) models.get("eval")).containsKey("RMSE")) { |
| | | double MAE = Double.parseDouble((String) ((HashMap) models.get("eval")).get("RMSE")); |
| | | eval_pre.put("RMSE", MAE); |
| | | } |
| | | } |
| | | |
| | | return eval_pre; |
| | | } |
| | | |
| | | /** |
| | | * 对models里面的参数进行转换 |
| | | */ |
| | | private HashMap<String, Object> train_result_models = new HashMap<String, Object>(); |
| | | |
| | | public HashMap<String, Object> reverseModels(HashMap<String, Object> train_result) { |
| | | if (train_result.containsKey("models")) { |
| | | train_result_models = (HashMap) train_result.get("models"); |
| | | if (((HashMap) train_result.get("models")).containsKey("dim")) { |
| | | double dim = Double.parseDouble((String) ((HashMap) train_result.get("models")).get("dim")); |
| | | train_result_models.put("dim", dim); |
| | | } |
| | | train_result.put("models", train_result_models); |
| | | } |
| | | return train_result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取二维数组行列数 |
| | | * |
| | | * @param arr |
| | | * @return |
| | | */ |
| | | public int[] getColAndRow(double[][] arr) { |
| | | int row = arr.length; |
| | | int col = arr[0].length; |
| | | int[] result = new int[2]; |
| | | result[0] = row; |
| | | result[1] = col; |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 两个二维数组进行合并 |
| | | * |
| | | * @param data |
| | | * @param refs |
| | | * @return |
| | | */ |
| | | public double[][] getMathergeArr(double[][] data, double[][] refs) { |
| | | |
| | | int[] dataRowAndCol = getColAndRow(data); |
| | | int rowData = dataRowAndCol[0]; |
| | | int colData = dataRowAndCol[1]; |
| | | |
| | | int[] refsRowAndCol = getColAndRow(refs); |
| | | int rowrefs = refsRowAndCol[0]; |
| | | int colrefs = refsRowAndCol[1]; |
| | | |
| | | double[][] newData = new double[rowData + rowrefs][colData]; |
| | | for (int i = 0; i < rowData; i++) { |
| | | for (int j = 0; j < colData; j++) { |
| | | newData[i][j] = data[i][j]; |
| | | } |
| | | } |
| | | |
| | | for (int i = 0; i < rowrefs; i++) { |
| | | for (int j = 0; j < colrefs; j++) { |
| | | newData[i + rowData][j] = refs[i][j]; |
| | | } |
| | | } |
| | | return newData; |
| | | } |
| | | |
| | | /** |
| | | * 对训练方法进行处理,实现评价指标的转换 |
| | | */ |
| | | public HashMap<String, Object> trainUtil(HashMap<String, Object> train_result, HashMap<String, Object> eval, String time) { |
| | | if (train_result.containsKey("eval")) { |
| | | eval = (HashMap<String, Object>) train_result.get("eval"); |
| | | eval.put("time", time); |
| | | train_result.put("eval", eval); |
| | | } |
| | | train_result.put("result_code", reverseResultCode(train_result)); |
| | | return train_result; |
| | | } |
| | | |
| | | /** |
| | | * 对预测方法进行处理 |
| | | */ |
| | | // public HashMap<String,Object> predictUtil(){ |
| | | // |
| | | // } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.common.utils; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import com.iailab.module.model.mpk.common.MdkConstant; |
| | | import com.iailab.module.model.mpk.dto.MpkFileDTO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.velocity.Template; |
| | | import org.apache.velocity.VelocityContext; |
| | | import org.apache.velocity.app.Velocity; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.StringWriter; |
| | | import java.nio.file.Files; |
| | | import java.util.*; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipOutputStream; |
| | | |
| | | @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(); |
| | | |
| | | if (template.equals("cpp.vm")) { |
| | | File dirPath = new File("C:/DLUT/tmp/"); |
| | | if (!dirPath.exists()) { |
| | | dirPath.mkdirs(); |
| | | } |
| | | // 生成临时cpp文件 |
| | | File cppFile = new File(dirPath.getAbsolutePath() + File.separator + entity.getPyName() + ".cpp"); |
| | | cppFile.createNewFile(); |
| | | OutputStream cppOutputStream = Files.newOutputStream(cppFile.toPath()); |
| | | IOUtils.write(sw.toString(), cppOutputStream, "UTF-8"); |
| | | IOUtils.closeQuietly(cppOutputStream); |
| | | } |
| | | |
| | | if (template.equals("Jni.cpp.vm")) { |
| | | File dirPath = new File("C:/DLUT/tmp/"); |
| | | if (!dirPath.exists()) { |
| | | dirPath.mkdirs(); |
| | | } |
| | | |
| | | // 生成临时Jni.cpp文件 |
| | | File cppFile = new File(dirPath.getAbsolutePath() + File.separator + entity.getPyName() + ".cpp"); |
| | | File jniCppFile = new File(dirPath.getAbsolutePath() + File.separator + entity.getPyName() + "Jni.cpp"); |
| | | jniCppFile.createNewFile(); |
| | | OutputStream jniCppOutputStream = Files.newOutputStream(jniCppFile.toPath()); |
| | | IOUtils.write(sw.toString(), jniCppOutputStream, "UTF-8"); |
| | | IOUtils.closeQuietly(jniCppOutputStream); |
| | | try { |
| | | // 根据file 通过cmd命令 生成dll |
| | | String dllSavePath = dirPath.getAbsolutePath() + File.separator + entity.getPyName() + ".dll"; |
| | | String cppFilePath = cppFile.getAbsolutePath(); |
| | | String jniCppFilePath = jniCppFile.getAbsolutePath(); |
| | | // String command = "cmd.exe /c cl -o " + dllSavePath + " /LD " + jniCppFilePath + " " + cppFilePath; |
| | | 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"; |
| | | Process process = Runtime.getRuntime().exec(command); |
| | | // 等待命令执行完成 |
| | | process.waitFor(); |
| | | |
| | | File dllFile = new File(dllSavePath); |
| | | //添加到zip |
| | | zip.putNextEntry(new ZipEntry("dll" + File.separator + entity.getPyName() + ".dll")); |
| | | IOUtils.write(FileUtils.readFileToByteArray(dllFile), zip); |
| | | zip.closeEntry(); |
| | | |
| | | FileUtils.deleteDirectory(dirPath); |
| | | } catch (InterruptedException e) { |
| | | log.error("DLL生成失败" + entity.getPyName(), e); |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } 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; |
| | | } |
| | | |
| | | /** |
| | | * 渲染模板 |
| | | **/ |
| | | public static StringWriter drawTemplate(String template,Map<String, Object> map) { |
| | | //模板数据 |
| | | VelocityContext context = new VelocityContext(map); |
| | | return drawTemplate(template,context); |
| | | } |
| | | |
| | | public static StringWriter drawTemplate(String template,VelocityContext context) { |
| | | Properties prop = new Properties(); |
| | | prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); |
| | | Velocity.init(prop); |
| | | |
| | | StringWriter writer = new StringWriter(); |
| | | Template tpl = Velocity.getTemplate("template/" + template, "UTF-8"); |
| | | tpl.merge(context, writer); |
| | | return writer; |
| | | } |
| | | |
| | | public static void drawTemplate(String template,Map<String, Object> map,File toFile) throws IOException { |
| | | 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); |
| | | |
| | | FileUtil.mkParentDirs(toFile); |
| | | |
| | | if (!toFile.exists()) { |
| | | toFile.createNewFile(); |
| | | } |
| | | |
| | | FileUtil.writeUtf8String(writer.toString(),toFile); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.common.utils; |
| | | |
| | | |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.*; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Auther: Forrest |
| | | * @Date: 2020/4/23 09:50 |
| | | * @Description: |
| | | */ |
| | | public class Readtxt { |
| | | public float[] read(String filePath, int filelength) { |
| | | float data[] = new float[filelength]; |
| | | try { |
| | | File file = new File(filePath); |
| | | if (file.isFile() && file.exists()) { |
| | | InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "utf-8"); |
| | | BufferedReader br = new BufferedReader(isr); |
| | | for (int i = 0; i < filelength; i++) |
| | | data[i] = Float.parseFloat(br.readLine()); |
| | | br.close(); |
| | | } else { |
| | | System.out.print("文件不存在"); |
| | | } |
| | | } catch (Exception e) { |
| | | System.out.println("文件读取错误"); |
| | | } |
| | | return data; |
| | | |
| | | } |
| | | |
| | | public float[] read1(String filePath, int filelength) { |
| | | float data[] = new float[filelength]; |
| | | try { |
| | | File file = new File(filePath); |
| | | if (file.isFile() && file.exists()) { |
| | | InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "utf-8"); |
| | | BufferedReader br = new BufferedReader(isr); |
| | | br.readLine(); |
| | | for (int i = 0; i < filelength; i++) |
| | | data[i] = Float.parseFloat(br.readLine()); |
| | | br.close(); |
| | | } else { |
| | | System.out.println("文件不存在"); |
| | | } |
| | | } catch (Exception e) { |
| | | System.out.println("文件读取错误"); |
| | | } |
| | | return data; |
| | | |
| | | } |
| | | |
| | | public double[][] readCSV(String filePath, int row, int col) { |
| | | double[][] res = new double[row][col]; |
| | | String line = null; |
| | | try { |
| | | //BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); |
| | | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "utf-8")); |
| | | |
| | | int i = 0; |
| | | while ((line = bufferedReader.readLine()) != null && i < row) { |
| | | //数据行 |
| | | String[] items = line.split(","); |
| | | for (int j = 0; j < col; j++) { |
| | | res[i][j] = Double.parseDouble(items[j]); |
| | | } |
| | | i++; |
| | | } |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | return res; |
| | | } |
| | | |
| | | |
| | | public String[][] readCSVString(String filePath, int row, int col) { |
| | | String[][] res = new String[row][col]; |
| | | String line = null; |
| | | try { |
| | | //BufferedReader bufferedReader=new BufferedReader(new FileReader(filePath)); |
| | | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "utf-8")); |
| | | |
| | | int i = 0; |
| | | while ((line = bufferedReader.readLine()) != null && i < row) { |
| | | //数据行 |
| | | String[] items = line.split("\t"); |
| | | for (int j = 0; j < col; j++) { |
| | | res[i][j] = items[j]; |
| | | } |
| | | i++; |
| | | } |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | return res; |
| | | } |
| | | |
| | | public static List<double[][]> readMethodExcel(MultipartFile file) throws IOException { |
| | | Workbook workbook = WorkbookFactory.create(file.getInputStream()); |
| | | //获取工作薄里面sheet的个数 |
| | | int sheetNum = workbook.getNumberOfSheets(); |
| | | List<double[][]> datas = new ArrayList<>(sheetNum - 1); |
| | | //从第二个sheet开始读,第一个为示例 |
| | | for (int i = 1; i < sheetNum; i++) { |
| | | Sheet sheet = workbook.getSheetAt(i); |
| | | //获取sheet中有数据的行数 |
| | | int rows = sheet.getPhysicalNumberOfRows(); |
| | | double[][] doubles2 = new double[rows][]; |
| | | for (int j = 0; j < rows; j++) { |
| | | //获取每一行的数据 |
| | | Row row = sheet.getRow(j); |
| | | //得到每一行中有效单元格的数据 |
| | | short cells = row.getLastCellNum(); |
| | | //定义一个doubles数组用来存储读取单元格的数据 |
| | | double[] doubles1 = new double[cells]; |
| | | //遍历每一个有效的单元格数据 |
| | | for (int k = 0; k < cells; k++) { |
| | | //获取每一个单元格的数据 |
| | | Cell cell = row.getCell(k, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); |
| | | doubles1[k] = cell.getNumericCellValue(); |
| | | } |
| | | doubles2[j] = doubles1; |
| | | } |
| | | datas.add(doubles2); |
| | | } |
| | | |
| | | return datas; |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.controller.admin; |
| | | |
| | | |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.module.model.mpk.dto.GeneratorCodeHistoryDTO; |
| | | import com.iailab.module.model.mpk.service.GeneratorCodeHistoryService; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.Map; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | | |
| | | /** |
| | | * @description: 生成代码记录表 |
| | | * @author: dzd |
| | | * @date: 2024/8/20 11:49 |
| | | **/ |
| | | @RestController |
| | | @RequestMapping("/model/mpk/generatorCodeHistory") |
| | | public class GeneratorCodeHistoryController { |
| | | @Autowired |
| | | private GeneratorCodeHistoryService generatorCodeHistoryService; |
| | | |
| | | @GetMapping("page") |
| | | public CommonResult<PageData<GeneratorCodeHistoryDTO>> page(@RequestParam Map<String, Object> params){ |
| | | PageData<GeneratorCodeHistoryDTO> page = generatorCodeHistoryService.page(params); |
| | | |
| | | return success(page); |
| | | } |
| | | |
| | | @GetMapping("{id}") |
| | | public CommonResult<GeneratorCodeHistoryDTO> get(@PathVariable("id") Long id){ |
| | | GeneratorCodeHistoryDTO data = generatorCodeHistoryService.get(id); |
| | | |
| | | return success(data); |
| | | } |
| | | |
| | | @PostMapping |
| | | public CommonResult save(@RequestBody GeneratorCodeHistoryDTO dto){ |
| | | |
| | | generatorCodeHistoryService.save(dto); |
| | | |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @PutMapping |
| | | public CommonResult update(@RequestBody GeneratorCodeHistoryDTO dto){ |
| | | |
| | | generatorCodeHistoryService.update(dto); |
| | | |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @DeleteMapping |
| | | public CommonResult delete(@RequestBody Long[] ids){ |
| | | |
| | | generatorCodeHistoryService.delete(ids); |
| | | |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @GetMapping("download") |
| | | public void generat(String id, HttpServletResponse response) throws IOException { |
| | | GeneratorCodeHistoryDTO dto = generatorCodeHistoryService.get(id); |
| | | byte[] data = generatorCodeHistoryService.download(dto); |
| | | |
| | | response.reset(); |
| | | response.setHeader("Content-Disposition", "attachment; filename=\"" + dto.getFileName() + "\""); |
| | | response.addHeader("Content-Length", "" + data.length); |
| | | response.setContentType("application/octet-stream; charset=UTF-8"); |
| | | |
| | | IOUtils.write(data, response.getOutputStream()); |
| | | } |
| | | |
| | | } |
对比新文件 |
| | |
| | | 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.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.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.lang.reflect.Method; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.*; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.error; |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2024年08月08日 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/model/mpk/api") |
| | | public class MdkController { |
| | | @PostMapping("run") |
| | | public CommonResult<String> run(@RequestBody MdkDTO dto) { |
| | | System.out.println("runTime=" + System.currentTimeMillis()); |
| | | try { |
| | | List<String> datas = dto.getDatas(); |
| | | |
| | | int paramLength = dto.getHasModel() ? datas.size() + 2 : datas.size() + 1; |
| | | Object[] paramsValueArray = new Object[paramLength]; |
| | | Class<?>[] paramsArray = new Class[paramLength]; |
| | | |
| | | try { |
| | | for (int i = 0; i < datas.size(); i++) { |
| | | String json = datas.get(i); |
| | | JSONArray jsonArray = JSON.parseArray(json); |
| | | double[][] data = new double[jsonArray.size()][jsonArray.getJSONArray(0).size()]; |
| | | for (int j = 0; j < jsonArray.size(); j++) { |
| | | for (int k = 0; k < jsonArray.getJSONArray(j).size(); k++) { |
| | | data[j][k] = jsonArray.getJSONArray(j).getDoubleValue(k); |
| | | } |
| | | } |
| | | paramsValueArray[i] = data; |
| | | paramsArray[i] = double[][].class; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),"参数错误,请检查!"); |
| | | } |
| | | |
| | | if (dto.getHasModel()) { |
| | | paramsValueArray[datas.size()] = dto.getModel(); |
| | | paramsValueArray[datas.size() + 1] = dto.getModelSettings(); |
| | | paramsArray[datas.size()] = HashMap.class; |
| | | paramsArray[datas.size() + 1] = HashMap.class; |
| | | }else { |
| | | paramsValueArray[datas.size()] = dto.getModelSettings(); |
| | | paramsArray[datas.size()] = HashMap.class; |
| | | } |
| | | |
| | | Class<?> clazz = Class.forName(dto.getClassName()); |
| | | Method method = clazz.getMethod(dto.getMethodName(), paramsArray); |
| | | HashMap result = (HashMap)method.invoke(clazz.newInstance(), paramsValueArray); |
| | | return success(JSON.toJSONString(result)); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | return error(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"运行异常"); |
| | | } finally { |
| | | System.gc(); |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | @Operation(summary = "导入参数") |
| | | public CommonResult<List<String>> importExcel(@RequestParam("file") MultipartFile file) throws Exception { |
| | | List<double[][]> datas = Readtxt.readMethodExcel(file); |
| | | List<String> result = new ArrayList<>(); |
| | | if (!CollectionUtils.isEmpty(datas)) { |
| | | for (double[][] data : datas) { |
| | | if (data.length > 0) { |
| | | result.add(JSON.toJSONString(data)); |
| | | } |
| | | } |
| | | } |
| | | return success(result); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.controller.admin; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.model.mpk.common.utils.Readtxt; |
| | | import com.iailab.module.model.mpk.dto.MpkFileDTO; |
| | | import com.iailab.module.model.mpk.service.MdkFileService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | 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.net.URLEncoder; |
| | | import java.util.*; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | | /** |
| | | * @author dzd |
| | | * @Description |
| | | * @createTime 2024年08月14日 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/model/mpk/file") |
| | | public class MpkFileController { |
| | | @Autowired |
| | | private MdkFileService mdkFileService; |
| | | |
| | | @GetMapping("page") |
| | | @Operation(summary = "分页") |
| | | public CommonResult<PageData<MpkFileDTO>> page(@RequestParam Map<String, Object> params) { |
| | | PageData<MpkFileDTO> page = mdkFileService.page(params); |
| | | |
| | | return success(page); |
| | | } |
| | | |
| | | @GetMapping("{id}") |
| | | public CommonResult<MpkFileDTO> info(@PathVariable("id") String id) { |
| | | MpkFileDTO schedule = mdkFileService.get(id); |
| | | |
| | | return success(schedule); |
| | | } |
| | | |
| | | @GetMapping("list") |
| | | public CommonResult<List<MpkFileDTO>> list() { |
| | | List<MpkFileDTO> list = mdkFileService.list(new HashMap<>()); |
| | | |
| | | return success(list); |
| | | } |
| | | |
| | | @PostMapping |
| | | public CommonResult save(@RequestBody MpkFileDTO dto) { |
| | | mdkFileService.save(dto); |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @DeleteMapping |
| | | public CommonResult delete(String id) { |
| | | mdkFileService.delete(id); |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @PutMapping |
| | | public CommonResult update(@RequestBody MpkFileDTO dto) { |
| | | mdkFileService.update(dto); |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @GetMapping("generat") |
| | | public void generat(String id, String remark,String zipFileName, HttpServletResponse response) throws IOException { |
| | | byte[] data = mdkFileService.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"); |
| | | |
| | | IOUtils.write(data, response.getOutputStream()); |
| | | } |
| | | |
| | | @GetMapping("packageModel") |
| | | public void packageModel(String ids ,String projectId,String log ,String projectName,String version,String zipFileName,HttpServletResponse response) throws IOException { |
| | | byte[] data; |
| | | try { |
| | | data = mdkFileService.packageModel(Arrays.asList(ids.split(",")),projectId,projectName,zipFileName,log,version); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException("模型打包失败",e); |
| | | } |
| | | |
| | | 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()); |
| | | } |
| | | |
| | | @PostMapping("/upload") |
| | | @Operation(summary = "python文件上传") |
| | | public CommonResult<Map<String,String>> importExcel(@RequestParam("file") MultipartFile file) throws Exception { |
| | | Map<String,String> result = mdkFileService.savePyFile(file); |
| | | return success(result); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.controller.admin; |
| | | |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.module.model.mpk.dto.MpkFileDTO; |
| | | import com.iailab.module.model.mpk.dto.ProjectDTO; |
| | | import com.iailab.module.model.mpk.dto.ProjectPackageHistoryModelDTO; |
| | | import com.iailab.module.model.mpk.service.ProjectService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:40 |
| | | **/ |
| | | @RestController |
| | | @RequestMapping("/model/mpk/project") |
| | | public class ProjectController { |
| | | @Autowired |
| | | private ProjectService projectService; |
| | | |
| | | @GetMapping("page") |
| | | public CommonResult<PageData<ProjectDTO>> page(@RequestParam Map<String, Object> params){ |
| | | PageData<ProjectDTO> page = projectService.page(params); |
| | | |
| | | return success(page); |
| | | } |
| | | |
| | | @GetMapping("list") |
| | | public CommonResult<List<ProjectDTO>> list() { |
| | | List<ProjectDTO> list = projectService.list(new HashMap<>()); |
| | | |
| | | return success(list); |
| | | } |
| | | |
| | | @GetMapping("{id}") |
| | | public CommonResult<ProjectDTO> get(@PathVariable("id") String id){ |
| | | ProjectDTO data = projectService.get(id); |
| | | |
| | | return success(data); |
| | | } |
| | | |
| | | @PostMapping |
| | | public CommonResult save(@RequestBody ProjectDTO dto){ |
| | | projectService.save(dto); |
| | | |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @PutMapping |
| | | public CommonResult update(@RequestBody ProjectDTO dto){ |
| | | dto.setUpdateTime(new Date()); |
| | | projectService.update(dto); |
| | | |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @DeleteMapping |
| | | public CommonResult delete(String id){ |
| | | |
| | | projectService.delete(id); |
| | | |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @GetMapping("getProjectModel") |
| | | public CommonResult<PageData<MpkFileDTO>> getProjectModel(@RequestParam Map<String, Object> params){ |
| | | PageData<MpkFileDTO> page = projectService.getProjectModel(params); |
| | | |
| | | return CommonResult.success(page); |
| | | } |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.controller.admin; |
| | | |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.module.model.mpk.dto.ProjectPackageHistoryDTO; |
| | | import com.iailab.module.model.mpk.dto.ProjectPackageHistoryModelDTO; |
| | | import com.iailab.module.model.mpk.service.ProjectPackageHistoryModelService; |
| | | import com.iailab.module.model.mpk.service.ProjectPackageHistoryService; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | | * 项目打包历史记录表 |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2024-08-22 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/model/mpk/projectPackageHistory") |
| | | public class ProjectPackageHistoryController { |
| | | @Autowired |
| | | private ProjectPackageHistoryService projectPackageHistoryService; |
| | | @Autowired |
| | | private ProjectPackageHistoryModelService projectPackageHistoryModelService; |
| | | |
| | | @GetMapping("page") |
| | | public CommonResult<PageData<ProjectPackageHistoryDTO>> page(@RequestParam Map<String, Object> params){ |
| | | PageData<ProjectPackageHistoryDTO> page = projectPackageHistoryService.page(params); |
| | | |
| | | return CommonResult.success(page); |
| | | } |
| | | |
| | | @GetMapping("download") |
| | | public void generat(String filePath, String fileName, HttpServletResponse response) throws IOException { |
| | | byte[] data = projectPackageHistoryService.download(filePath); |
| | | |
| | | response.reset(); |
| | | response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(fileName,"utf-8") + "\""); |
| | | response.addHeader("Content-Length", "" + data.length); |
| | | response.setContentType("application/octet-stream; charset=UTF-8"); |
| | | |
| | | IOUtils.write(data, response.getOutputStream()); |
| | | } |
| | | |
| | | @GetMapping("getPackageModel") |
| | | public CommonResult<PageData<ProjectPackageHistoryModelDTO>> getPackageModel(@RequestParam Map<String, Object> params){ |
| | | PageData<ProjectPackageHistoryModelDTO> page = projectPackageHistoryModelService.page(params); |
| | | |
| | | return CommonResult.success(page); |
| | | } |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dao; |
| | | |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.module.model.mpk.entity.GeneratorCodeHistoryEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @description: 生成代码记录表 |
| | | * @author: dzd |
| | | * @date: 2024/8/20 11:49 |
| | | **/ |
| | | @Mapper |
| | | public interface GeneratorCodeHistoryDao extends BaseDao<GeneratorCodeHistoryEntity> { |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dao; |
| | | |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.module.model.mpk.entity.ModelMethodEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/9/9 10:55 |
| | | **/ |
| | | @Mapper |
| | | public interface ModelMethodDao extends BaseDao<ModelMethodEntity> { |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dao; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.module.model.mpk.dto.MpkFileDTO; |
| | | import com.iailab.module.model.mpk.dto.ProjectDTO; |
| | | import com.iailab.module.model.mpk.entity.MpkFileEntity; |
| | | import com.iailab.module.model.mpk.entity.ProjectEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * MDK模型文件 |
| | | * |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2024年08月14日 |
| | | */ |
| | | @Mapper |
| | | public interface MpkFileDao extends BaseDao<MpkFileEntity> { |
| | | MpkFileDTO get(String id); |
| | | |
| | | List<MpkFileDTO> selectByIds(@Param("ids") List<String> ids); |
| | | |
| | | int getProjectModelCount(String projectId); |
| | | |
| | | List<MpkFileDTO> getProjectModel(@Param("params") Map<String, Object> params); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dao; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.module.model.mpk.dto.ProjectDTO; |
| | | import com.iailab.module.model.mpk.entity.ProjectEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | @Mapper |
| | | public interface ProjectDao extends BaseDao<ProjectEntity> { |
| | | |
| | | IPage<ProjectDTO> getPageList(IPage<ProjectEntity> page, @Param("params") Map<String, Object> params); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dao; |
| | | |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.module.model.mpk.entity.ProjectModelEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | @Mapper |
| | | public interface ProjectModelDao extends BaseDao<ProjectModelEntity> { |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dao; |
| | | |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.module.model.mpk.entity.ProjectPackageHistoryEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * 项目打包历史记录表 |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2024-08-22 |
| | | */ |
| | | @Mapper |
| | | public interface ProjectPackageHistoryDao extends BaseDao<ProjectPackageHistoryEntity> { |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dao; |
| | | |
| | | import com.iailab.framework.common.dao.BaseDao; |
| | | import com.iailab.module.model.mpk.entity.ProjectPackageHistoryModelEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | @Mapper |
| | | public interface ProjectPackageHistoryModelDao extends BaseDao<ProjectPackageHistoryModelEntity> { |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dto; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @description: 生成代码记录表 |
| | | * @author: dzd |
| | | * @date: 2024/8/20 11:36 |
| | | **/ |
| | | @Data |
| | | public class GeneratorCodeHistoryDTO implements Serializable { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | @TableId |
| | | private String id; |
| | | |
| | | /** |
| | | * mdk_id |
| | | */ |
| | | private String mdkId; |
| | | |
| | | /** |
| | | * 文件名 |
| | | */ |
| | | private String fileName; |
| | | |
| | | /** |
| | | * 文件保存路径 |
| | | */ |
| | | private String filePath; |
| | | |
| | | /** |
| | | * 备注 |
| | | */ |
| | | private String remark; |
| | | |
| | | /** |
| | | * 生成时间 |
| | | */ |
| | | private Date createTime; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2024年08月08日 |
| | | */ |
| | | @Data |
| | | public class MdkDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String className; |
| | | |
| | | private String methodName; |
| | | |
| | | private Boolean hasModel; |
| | | |
| | | private HashMap<String, Object> model; |
| | | |
| | | private HashMap<String, Object> modelSettings; |
| | | |
| | | private List<String> datas; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dto; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * @description: MPK模型方法 |
| | | * @author: dzd |
| | | * @date: 2024/9/9 10:52 |
| | | **/ |
| | | @Data |
| | | public class ModelMethodDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String id; |
| | | |
| | | private String mpkFileId; |
| | | |
| | | private String methodName; |
| | | |
| | | private Integer dataLength; |
| | | |
| | | private Integer model; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dto; |
| | | |
| | | import com.iailab.module.model.mpk.entity.ModelMethodEntity; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2024年08月14日 |
| | | */ |
| | | @Data |
| | | public class MpkFileDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String id; |
| | | |
| | | private String pyName; |
| | | |
| | | private String filePath; |
| | | |
| | | private String pyType; |
| | | |
| | | private String pkgName; |
| | | |
| | | private String className; |
| | | |
| | | private String pyModule; |
| | | |
| | | private String remark; |
| | | |
| | | private Long updater; |
| | | |
| | | private Date updateDate; |
| | | |
| | | private Long creator; |
| | | |
| | | private Date createDate; |
| | | |
| | | private List<ModelMethodEntity> modelMethods; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * @description: 项目表 |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | @Data |
| | | public class ProjectDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String id; |
| | | |
| | | private String projectName; |
| | | |
| | | private String projectCode; |
| | | |
| | | private Date createTime; |
| | | |
| | | private Date updateTime; |
| | | |
| | | private List<MpkFileDTO> models; |
| | | |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | |
| | | /** |
| | | * @description: 项目模型关联表 |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | @Data |
| | | public class ProjectModelDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String id; |
| | | |
| | | private String projectId; |
| | | |
| | | private String modelId; |
| | | |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | |
| | | /** |
| | | * 项目打包历史记录表 |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2024-08-22 |
| | | */ |
| | | @Data |
| | | public class ProjectPackageHistoryDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private String id; |
| | | |
| | | private String projectId; |
| | | |
| | | private String fileName; |
| | | |
| | | private String filePath; |
| | | |
| | | private String log; |
| | | |
| | | private String version; |
| | | |
| | | private String modelNames; |
| | | |
| | | private Date createTime; |
| | | |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | |
| | | /** |
| | | * @description: 打包历史模型关联表 |
| | | * @author: dzd |
| | | * @date: 2024/9/11 11:38 |
| | | **/ |
| | | @Data |
| | | public class ProjectPackageHistoryModelDTO implements Serializable { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | private String id; |
| | | /** |
| | | * 项目id |
| | | */ |
| | | private String projectId; |
| | | /** |
| | | * 打包历史id |
| | | */ |
| | | private String packageHistoryId; |
| | | /** |
| | | * 模型名称 |
| | | */ |
| | | private String pyName; |
| | | /** |
| | | * 包名 |
| | | */ |
| | | private String pkgName; |
| | | /** |
| | | * 模型路径 |
| | | */ |
| | | private String pyModule; |
| | | /** |
| | | * 备注 |
| | | */ |
| | | private String remark; |
| | | /** |
| | | * 模型方法信息 |
| | | */ |
| | | private String methodInfo; |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @description: 生成代码记录表 |
| | | * @author: dzd |
| | | * @date: 2024/8/20 11:36 |
| | | **/ |
| | | @Data |
| | | @TableName("t_mpk_generator_code_history") |
| | | public class GeneratorCodeHistoryEntity implements Serializable { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | @TableId |
| | | private String id; |
| | | |
| | | /** |
| | | * mdk_id |
| | | */ |
| | | private String mdkId; |
| | | |
| | | /** |
| | | * 文件名 |
| | | */ |
| | | private String fileName; |
| | | |
| | | /** |
| | | * 文件保存路径 |
| | | */ |
| | | private String filePath; |
| | | |
| | | /** |
| | | * 备注 |
| | | */ |
| | | private String remark; |
| | | |
| | | /** |
| | | * 生成时间 |
| | | */ |
| | | private Date createTime; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.FieldFill; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @description: MPK模型方法 |
| | | * @author: dzd |
| | | * @date: 2024/9/9 10:52 |
| | | **/ |
| | | @Data |
| | | @TableName("t_mpk_model_method") |
| | | public class ModelMethodEntity implements Serializable { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | @TableId |
| | | private String id; |
| | | |
| | | /** |
| | | * 模型文件id |
| | | */ |
| | | private String mpkFileId; |
| | | |
| | | /** |
| | | * 模型方法名 |
| | | */ |
| | | private String methodName; |
| | | |
| | | /** |
| | | * 输入个数 |
| | | */ |
| | | private Integer dataLength; |
| | | |
| | | /** |
| | | * 是否有model(0:否,1:是) |
| | | */ |
| | | private Integer model; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.FieldFill; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * MPK模型文件 |
| | | * |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2024年08月14日 |
| | | */ |
| | | @Data |
| | | @TableName("t_mpk_file") |
| | | public class MpkFileEntity implements Serializable { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | @TableId |
| | | private String id; |
| | | |
| | | /** |
| | | * 模型名称 |
| | | */ |
| | | private String pyName; |
| | | |
| | | /** |
| | | * 源文件保存路径 |
| | | */ |
| | | private String filePath; |
| | | |
| | | /** |
| | | * 模型类型 |
| | | */ |
| | | private String pyType; |
| | | |
| | | /** |
| | | * 包名 |
| | | */ |
| | | private String pkgName; |
| | | |
| | | /** |
| | | * 类名 |
| | | */ |
| | | private String className; |
| | | |
| | | /** |
| | | * 模型路径 |
| | | */ |
| | | private String pyModule; |
| | | |
| | | /** |
| | | * 备注 |
| | | */ |
| | | private String remark; |
| | | |
| | | /** |
| | | * 更新者 |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private Long updater; |
| | | /** |
| | | * 更新时间 |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private Date updateDate; |
| | | |
| | | /** |
| | | * 创建者 |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Long creator; |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private Date createDate; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @description: 项目表 |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | @Data |
| | | @TableName("t_mpk_project") |
| | | public class ProjectEntity { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | private String id; |
| | | /** |
| | | * 项目名称 |
| | | */ |
| | | private String projectName; |
| | | /** |
| | | * 项目编码 |
| | | */ |
| | | private String projectCode; |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | private Date createTime; |
| | | /** |
| | | * 修改时间 |
| | | */ |
| | | private Date updateTime; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @description: 项目模型关联表 |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | @Data |
| | | @TableName("t_mpk_project_model") |
| | | public class ProjectModelEntity { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | private String id; |
| | | /** |
| | | * 项目id |
| | | */ |
| | | private String projectId; |
| | | /** |
| | | * 模型id |
| | | */ |
| | | private String modelId; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 项目打包历史记录表 |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2024-08-22 |
| | | */ |
| | | @Data |
| | | @TableName("t_mpk_project_package_history") |
| | | public class ProjectPackageHistoryEntity { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | private String id; |
| | | /** |
| | | * 项目id |
| | | */ |
| | | private String projectId; |
| | | /** |
| | | * 文件名 |
| | | */ |
| | | private String fileName; |
| | | /** |
| | | * 文件路径 |
| | | */ |
| | | private String filePath; |
| | | /** |
| | | * 更新日志 |
| | | */ |
| | | private String log; |
| | | /** |
| | | * 版本号 |
| | | */ |
| | | private String version; |
| | | /** |
| | | * 打包模型名称(“,”分割) |
| | | */ |
| | | private String modelNames; |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | private Date createTime; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @description: 打包历史模型关联表 |
| | | * @author: dzd |
| | | * @date: 2024/9/11 11:38 |
| | | **/ |
| | | @Data |
| | | @TableName("t_mpk_project_package_history_model") |
| | | public class ProjectPackageHistoryModelEntity { |
| | | |
| | | /** |
| | | * id |
| | | */ |
| | | private String id; |
| | | /** |
| | | * 项目id |
| | | */ |
| | | private String projectId; |
| | | /** |
| | | * 打包历史id |
| | | */ |
| | | private String packageHistoryId; |
| | | /** |
| | | * 模型名称 |
| | | */ |
| | | private String pyName; |
| | | /** |
| | | * 包名 |
| | | */ |
| | | private String pkgName; |
| | | /** |
| | | * 模型路径 |
| | | */ |
| | | private String pyModule; |
| | | /** |
| | | * 备注 |
| | | */ |
| | | private String remark; |
| | | /** |
| | | * 模型方法信息 |
| | | */ |
| | | private String methodInfo; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service; |
| | | |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.service.CrudService; |
| | | import com.iailab.module.model.mpk.dto.GeneratorCodeHistoryDTO; |
| | | import com.iailab.module.model.mpk.entity.GeneratorCodeHistoryEntity; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: 生成代码记录表 |
| | | * @author: dzd |
| | | * @date: 2024/8/20 11:49 |
| | | **/ |
| | | public interface GeneratorCodeHistoryService extends CrudService<GeneratorCodeHistoryEntity, GeneratorCodeHistoryDTO> { |
| | | |
| | | PageData<GeneratorCodeHistoryDTO> page(Map<String, Object> params); |
| | | |
| | | GeneratorCodeHistoryDTO get(String id); |
| | | |
| | | byte[] download(GeneratorCodeHistoryDTO dto) throws IOException; |
| | | |
| | | void deleteByMap(Map<String, Object> map); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service; |
| | | |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.mpk.dto.MpkFileDTO; |
| | | import com.iailab.module.model.mpk.entity.MpkFileEntity; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2024年08月14日 |
| | | */ |
| | | public interface MdkFileService extends BaseService<MpkFileEntity> { |
| | | |
| | | PageData<MpkFileDTO> page(Map<String, Object> params); |
| | | |
| | | List<MpkFileDTO> list(Map<String, Object> params); |
| | | |
| | | MpkFileDTO get(String id); |
| | | |
| | | void save(MpkFileDTO dto); |
| | | |
| | | void update(MpkFileDTO dto); |
| | | |
| | | void delete(String id); |
| | | |
| | | byte[] generatorCode(String id, String remark, String zipFileName); |
| | | |
| | | byte[] packageModel(List<String> ids,String projectId,String projectName,String fileName,String log,String version) throws IOException, InterruptedException; |
| | | |
| | | Map<String,String> savePyFile(MultipartFile file) throws IOException; |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service; |
| | | |
| | | import com.iailab.framework.common.service.BaseService; |
| | | import com.iailab.module.model.mpk.entity.ModelMethodEntity; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/9/9 10:51 |
| | | **/ |
| | | public interface ModelMethodService extends BaseService<ModelMethodEntity> { |
| | | |
| | | void deleteByMap(Map<String, Object> map); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service; |
| | | |
| | | import com.iailab.framework.common.service.CrudService; |
| | | import com.iailab.module.model.mpk.dto.ProjectModelDTO; |
| | | import com.iailab.module.model.mpk.entity.ProjectModelEntity; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | public interface ProjectModelService extends CrudService<ProjectModelEntity, ProjectModelDTO> { |
| | | |
| | | List<ProjectModelDTO> list(Map<String, Object> params); |
| | | |
| | | void deleteByMap(Map<String,Object> map); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service; |
| | | |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.service.CrudService; |
| | | import com.iailab.module.model.mpk.dto.ProjectPackageHistoryModelDTO; |
| | | import com.iailab.module.model.mpk.entity.ProjectPackageHistoryModelEntity; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/9/11 11:39 |
| | | **/ |
| | | public interface ProjectPackageHistoryModelService extends CrudService<ProjectPackageHistoryModelEntity, ProjectPackageHistoryModelDTO> { |
| | | |
| | | PageData<ProjectPackageHistoryModelDTO> page(Map<String, Object> params); |
| | | |
| | | void deleteByMap(Map<String,Object> map); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service; |
| | | |
| | | import com.iailab.framework.common.service.CrudService; |
| | | import com.iailab.module.model.mpk.dto.ProjectPackageHistoryDTO; |
| | | import com.iailab.module.model.mpk.dto.ProjectPackageHistoryModelDTO; |
| | | import com.iailab.module.model.mpk.entity.ProjectPackageHistoryEntity; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 项目打包历史记录表 |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2024-08-22 |
| | | */ |
| | | public interface ProjectPackageHistoryService extends CrudService<ProjectPackageHistoryEntity, ProjectPackageHistoryDTO> { |
| | | |
| | | byte[] download(String filePath) throws IOException; |
| | | |
| | | void deleteByMap(Map<String, Object> map); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service; |
| | | |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.service.CrudService; |
| | | import com.iailab.module.model.mpk.dto.MpkFileDTO; |
| | | import com.iailab.module.model.mpk.dto.ProjectDTO; |
| | | import com.iailab.module.model.mpk.entity.ProjectEntity; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | public interface ProjectService extends CrudService<ProjectEntity, ProjectDTO> { |
| | | PageData<ProjectDTO> page(Map<String, Object> params); |
| | | |
| | | List<ProjectDTO> list(Map<String, Object> params); |
| | | |
| | | ProjectDTO get(String id); |
| | | |
| | | void save(ProjectDTO dto); |
| | | |
| | | void update(ProjectDTO dto); |
| | | |
| | | void delete(String id); |
| | | |
| | | PageData<MpkFileDTO> getProjectModel(Map<String, Object> params); |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.service.impl.CrudServiceImpl; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.model.mpk.dao.GeneratorCodeHistoryDao; |
| | | import com.iailab.module.model.mpk.dto.GeneratorCodeHistoryDTO; |
| | | import com.iailab.module.model.mpk.entity.GeneratorCodeHistoryEntity; |
| | | import com.iailab.module.model.mpk.service.GeneratorCodeHistoryService; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: 生成代码记录表 |
| | | * @author: dzd |
| | | * @date: 2024/8/20 11:49 |
| | | **/ |
| | | |
| | | @Service |
| | | public class GeneratorCodeHistoryServiceImpl extends CrudServiceImpl<GeneratorCodeHistoryDao, GeneratorCodeHistoryEntity, GeneratorCodeHistoryDTO> implements GeneratorCodeHistoryService { |
| | | |
| | | @Override |
| | | public PageData<GeneratorCodeHistoryDTO> page(Map<String, Object> params) { |
| | | IPage<GeneratorCodeHistoryEntity> page = baseDao.selectPage( |
| | | getPage(params, "create_time", false), |
| | | getWrapper(params) |
| | | ); |
| | | |
| | | return getPageData(page, GeneratorCodeHistoryDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public GeneratorCodeHistoryDTO get(String id) { |
| | | GeneratorCodeHistoryEntity entity = baseDao.selectById(id); |
| | | |
| | | return ConvertUtils.sourceToTarget(entity, GeneratorCodeHistoryDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public byte[] download(GeneratorCodeHistoryDTO dto) throws IOException { |
| | | File file = new File(dto.getFilePath()); |
| | | if (!file.exists()) { |
| | | log.error("文件不存在,路径:" + dto.getFilePath()); |
| | | } |
| | | return FileUtils.readFileToByteArray(file); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByMap(Map<String, Object> map) { |
| | | baseDao.delete(getWrapper(map)); |
| | | } |
| | | |
| | | @Override |
| | | public QueryWrapper<GeneratorCodeHistoryEntity> getWrapper(Map<String, Object> params){ |
| | | String id = (String)params.get("id"); |
| | | String mdkId = (String)params.get("mdkId"); |
| | | String startTime = (String)params.get("startTime"); |
| | | String endTime = (String)params.get("endTime"); |
| | | |
| | | QueryWrapper<GeneratorCodeHistoryEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq(StringUtils.isNotBlank(id), "id", id); |
| | | wrapper.eq(StringUtils.isNotBlank(mdkId), "mdk_id", mdkId); |
| | | wrapper.ge(StringUtils.isNotBlank(startTime), "create_time", startTime); |
| | | wrapper.le(StringUtils.isNotBlank(endTime), "create_time", endTime); |
| | | |
| | | return wrapper; |
| | | } |
| | | |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service.impl; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.util.RuntimeUtil; |
| | | import cn.hutool.core.util.ZipUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.framework.security.core.util.SecurityFrameworkUtils; |
| | | import com.iailab.module.infra.api.config.ConfigApi; |
| | | 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.GeneratorCodeHistoryDTO; |
| | | 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.ModelMethodEntity; |
| | | 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; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.nio.file.Files; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.zip.ZipOutputStream; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2024年08月14日 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class MdkFileServiceImpl extends BaseServiceImpl<MpkFileDao, MpkFileEntity> implements MdkFileService { |
| | | |
| | | @Autowired |
| | | private GeneratorCodeHistoryService generatorCodeHistoryService; |
| | | @Autowired |
| | | private ProjectModelService projectModelService; |
| | | @Autowired |
| | | private ProjectPackageHistoryService projectPackageHistoryService; |
| | | @Autowired |
| | | private ModelMethodService modelMethodService; |
| | | @Autowired |
| | | private ProjectPackageHistoryModelService projectPackageHistoryModelService; |
| | | |
| | | @Autowired |
| | | private ConfigApi configApi; |
| | | |
| | | private String mpkBakFilePath; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | mpkBakFilePath = configApi.getConfigValueByKey("mpkBakFilePath").getCheckedData(); |
| | | } |
| | | |
| | | @Override |
| | | public PageData<MpkFileDTO> page(Map<String, Object> params) { |
| | | IPage<MpkFileEntity> page = baseDao.selectPage( |
| | | getPage(params, "create_date", false), |
| | | getWrapper(params) |
| | | ); |
| | | |
| | | return getPageData(page, MpkFileDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<MpkFileDTO> list(Map<String, Object> params) { |
| | | List<MpkFileEntity> entityList = baseDao.selectList(getWrapper(params).orderByDesc("create_date")); |
| | | |
| | | return ConvertUtils.sourceToTarget(entityList, MpkFileDTO.class); |
| | | } |
| | | |
| | | private QueryWrapper<MpkFileEntity> getWrapper(Map<String, Object> params){ |
| | | String pyName = (String) params.get("pyName"); |
| | | String pyType = (String) params.get("pyType"); |
| | | String remark = (String) params.get("remark"); |
| | | |
| | | QueryWrapper<MpkFileEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.like(StringUtils.isNotBlank(pyName), "py_name", pyName) |
| | | .eq(StringUtils.isNotBlank(pyType), "py_type", pyType) |
| | | .like(StringUtils.isNotBlank(remark), "remark", remark); |
| | | return wrapper; |
| | | } |
| | | |
| | | @Override |
| | | public MpkFileDTO get(String id) { |
| | | MpkFileDTO entity = baseDao.get(id); |
| | | |
| | | return entity; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void save(MpkFileDTO dto) { |
| | | MpkFileEntity entity = ConvertUtils.sourceToTarget(dto, MpkFileEntity.class); |
| | | String mpkId = UUID.randomUUID().toString(); |
| | | entity.setId(mpkId); |
| | | entity.setCreator(SecurityFrameworkUtils.getLoginUserId()); |
| | | entity.setCreateDate(new Date()); |
| | | insert(entity); |
| | | |
| | | // 添加模型方法 |
| | | insertModelMethod(dto.getModelMethods(),mpkId); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(MpkFileDTO dto) { |
| | | MpkFileEntity entity = ConvertUtils.sourceToTarget(dto, MpkFileEntity.class); |
| | | entity.setUpdater(SecurityFrameworkUtils.getLoginUserId()); |
| | | entity.setUpdateDate(new Date()); |
| | | updateById(entity); |
| | | |
| | | String mpkId = dto.getId(); |
| | | // 删除模型方法 |
| | | deleteModelMethod(mpkId); |
| | | |
| | | // 添加模型方法 |
| | | insertModelMethod(dto.getModelMethods(),mpkId); |
| | | } |
| | | |
| | | private void insertModelMethod(List<ModelMethodEntity> modelMethods,String mpkId) { |
| | | if (!CollectionUtils.isEmpty(modelMethods)) { |
| | | modelMethods.forEach(e -> { |
| | | e.setId(UUID.randomUUID().toString()); |
| | | e.setMpkFileId(mpkId); |
| | | }); |
| | | modelMethodService.insertBatch(modelMethods); |
| | | } |
| | | } |
| | | private void deleteModelMethod(String mpkId) { |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("mpkFileId", mpkId); |
| | | modelMethodService.deleteByMap(map); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void delete(String id) { |
| | | |
| | | //删除源文件 |
| | | MpkFileEntity mpkFileEntity = selectById(id); |
| | | if (StringUtils.isNoneBlank(mpkFileEntity.getFilePath())) { |
| | | File mpkFile = new File(mpkFileEntity.getFilePath()); |
| | | if (mpkFile.exists()) { |
| | | mpkFile.delete(); |
| | | log.info("删除源文件备份文件:" + mpkFileEntity.getFilePath()); |
| | | } |
| | | } |
| | | |
| | | //删除 |
| | | deleteById(id); |
| | | |
| | | //删除备份文件 |
| | | Map<String,Object> map1 = new HashMap<>(); |
| | | map1.put("mdkId",id); |
| | | List<GeneratorCodeHistoryDTO> list = generatorCodeHistoryService.list(map1); |
| | | list.forEach(e -> { |
| | | File file = new File(e.getFilePath()); |
| | | if (file.exists()) { |
| | | file.delete(); |
| | | log.info("删除生成代码备份文件:" + e.getFilePath()); |
| | | } |
| | | }); |
| | | |
| | | //删除生成历史 |
| | | |
| | | generatorCodeHistoryService.deleteByMap(map1); |
| | | |
| | | //删除关联项目 |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("modelId",id); |
| | | projectModelService.deleteByMap(map); |
| | | |
| | | //删除模型方法 |
| | | deleteModelMethod(id); |
| | | |
| | | } |
| | | |
| | | @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); |
| | | |
| | | 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); |
| | | } |
| | | |
| | | //代码生成历史记录 |
| | | GeneratorCodeHistoryEntity historyEntity = new GeneratorCodeHistoryEntity(); |
| | | historyEntity.setId(UUID.randomUUID().toString()); |
| | | historyEntity.setMdkId(id); |
| | | historyEntity.setFileName(file.getName()); |
| | | historyEntity.setFilePath(file.getAbsolutePath()); |
| | | historyEntity.setRemark(remark); |
| | | historyEntity.setCreateTime(new Date()); |
| | | generatorCodeHistoryService.insert(historyEntity); |
| | | |
| | | return outputStream.toByteArray(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public byte[] packageModel(List<String> ids,String projectId,String projectName,String zipFileName,String log,String version) throws IOException, InterruptedException { |
| | | List<MpkFileDTO> entities = baseDao.selectByIds(ids); |
| | | |
| | | //模板数据 |
| | | 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(); |
| | | } |
| | | |
| | | //设置velocity资源加载器 |
| | | Properties prop = new Properties(); |
| | | prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); |
| | | Velocity.init(prop); |
| | | |
| | | //生成cpp文件 |
| | | File cppFile = new File(dirPath.getAbsolutePath() + File.separator + UUID.randomUUID() + ".cpp"); |
| | | GenUtils.drawTemplate("pkg.cpp.vm",context,cppFile); |
| | | |
| | | //生成Jni.cpp文件 |
| | | File jniCppFile = new File(dirPath.getAbsolutePath() + File.separator + UUID.randomUUID() + "Jni.cpp"); |
| | | GenUtils.drawTemplate("pkg.Jni.cpp.vm",context,jniCppFile); |
| | | |
| | | //生成dll文件 |
| | | String dllSavePath = dirPath.getAbsolutePath() + File.separator + "IAIL.MDK.Mid.Windows.dll"; |
| | | String cppFilePath = cppFile.getAbsolutePath(); |
| | | String jniCppFilePath = jniCppFile.getAbsolutePath(); |
| | | // String command = "cmd.exe /c cl -o " + dllSavePath + " /LD " + jniCppFilePath + " " + cppFilePath; |
| | | 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"; |
| | | Process process = RuntimeUtil.exec(command); |
| | | // 等待命令执行完成 |
| | | process.waitFor(); |
| | | List<String> javaFilePaths = new ArrayList<>(); |
| | | |
| | | //生成java文件 |
| | | for (MpkFileDTO entity : entities) { |
| | | //封装模板数据 |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("pkgName",entity.getPkgName()); |
| | | data.put("modelMethods",entity.getModelMethods()); |
| | | data.put("pyName",entity.getPyName()); |
| | | data.put("pyModule",entity.getPyModule()); |
| | | VelocityContext dataContext = new VelocityContext(data); |
| | | //生成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()); |
| | | |
| | | // 添加python源文件 |
| | | String pyFilePath = dirPath.getAbsolutePath() + File.separator + "py" + File.separator + entity.getPyName() + ".pyd"; |
| | | FileUtil.mkParentDirs(pyFilePath); |
| | | FileUtil.copy(entity.getFilePath(),pyFilePath,true); |
| | | } |
| | | |
| | | //utils + env java文件 |
| | | File utilsJavaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + "utils" + File.separator + "AlgsUtils.java"); |
| | | FileUtil.mkParentDirs(utilsJavaFile); |
| | | FileUtil.copy("bak/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"); |
| | | FileUtil.mkParentDirs(envJavaFile); |
| | | FileUtil.copy("bak/Environment.java",envJavaFile.getAbsolutePath(),true); |
| | | javaFilePaths.add(envJavaFile.getAbsolutePath()); |
| | | // 生成class文件 |
| | | createClassFile(javaFilePaths); |
| | | // 删除java源文件 |
| | | deleteJavaFile(javaFilePaths); |
| | | // 打jar包 |
| | | pkgJar(dirPath.getAbsolutePath()); |
| | | // 本次更新日志 |
| | | ProjectPackageHistoryDTO dto = new ProjectPackageHistoryDTO(); |
| | | String historyId = UUID.randomUUID().toString(); |
| | | dto.setId(historyId); |
| | | dto.setProjectId(projectId); |
| | | dto.setFileName(zipFileName); |
| | | dto.setLog(log); |
| | | dto.setVersion(version); |
| | | dto.setModelNames(entities.stream().map(MpkFileDTO::getPyName).collect(Collectors.joining(","))); |
| | | dto.setCreateTime(new Date()); |
| | | // 生成更新日志 |
| | | createLog(projectId,projectName,dirPath.getAbsolutePath(),dto,version); |
| | | // 打zip包 |
| | | String zipPath = mpkBakFilePath + File.separator + zipFileName; |
| | | ZipUtil.zip(dirPath.getAbsolutePath(),zipPath); |
| | | byte[] bytes = FileUtil.readBytes(zipPath); |
| | | // 记录打包日志 |
| | | dto.setFilePath(zipPath); |
| | | projectPackageHistoryService.save(dto); |
| | | // 插入打包历史-模型关联表 |
| | | List<ProjectPackageHistoryModelEntity> historyModelList = new ArrayList<>(entities.size()); |
| | | entities.forEach(e -> { |
| | | ProjectPackageHistoryModelEntity entity = new ProjectPackageHistoryModelEntity(); |
| | | entity.setId(UUID.randomUUID().toString()); |
| | | entity.setProjectId(projectId); |
| | | entity.setPackageHistoryId(historyId); |
| | | entity.setPyName(e.getPyName()); |
| | | entity.setPkgName(e.getPkgName()); |
| | | entity.setPyModule(e.getPyModule()); |
| | | entity.setRemark(e.getRemark()); |
| | | List<ModelMethodEntity> methods = e.getModelMethods(); |
| | | if (!CollectionUtils.isEmpty(methods)) { |
| | | entity.setMethodInfo(JSON.toJSONString(methods)); |
| | | } |
| | | historyModelList.add(entity); |
| | | }); |
| | | projectPackageHistoryModelService.insertBatch(historyModelList); |
| | | // 删除临时文件 |
| | | FileUtils.deleteDirectory(dirPath); |
| | | // FileUtils.delete(new File(zipPath)); |
| | | return bytes; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String,String> savePyFile(MultipartFile file) throws IOException { |
| | | File dir = new File(mpkBakFilePath); |
| | | if (!dir.exists()) { |
| | | dir.mkdirs(); |
| | | } |
| | | String fileName = file.getOriginalFilename(); |
| | | File saveFile = new File(dir.getAbsolutePath() + File.separator + fileName); |
| | | saveFile.createNewFile(); |
| | | // 保存 |
| | | file.transferTo(saveFile); |
| | | |
| | | Map<String,String> result = new HashMap<>(2); |
| | | result.put("filePath",saveFile.getAbsolutePath()); |
| | | result.put("fileName", fileName); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private void createLog(String projectId,String projectName,String dirPath,ProjectPackageHistoryDTO dto,String version) throws IOException { |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("projectId",projectId); |
| | | List<ProjectPackageHistoryDTO> list = projectPackageHistoryService.list(map); |
| | | list.add(dto); |
| | | // 按照日期分组再排序 |
| | | HashMap<String, List<ProjectPackageHistoryDTO>> dataMap = list.stream().collect( |
| | | Collectors.groupingBy(e -> DateUtils.format(e.getCreateTime(), DateUtils.DATE_PATTERN_POINT), |
| | | LinkedHashMap::new, |
| | | Collectors.collectingAndThen(Collectors.toList(), e -> e.stream().sorted(Comparator.comparing(ProjectPackageHistoryDTO::getCreateTime)).collect(Collectors.toList())))); |
| | | |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("dataMap",dataMap); |
| | | data.put("projectName",projectName); |
| | | data.put("version",version); |
| | | data.put("now",DateUtils.format(new Date(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | |
| | | File logFile = new File(dirPath + File.separator + "更新日志.txt"); |
| | | 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 void deleteJavaFile(List<String> javaFilePaths) { |
| | | for (String javaFilePath : javaFilePaths) { |
| | | FileUtil.del(javaFilePath); |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | log.info("执行cmd命令生成class:" + sb); |
| | | Process process = RuntimeUtil.exec(sb.toString()); |
| | | process.waitFor(); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.module.model.mpk.dao.ModelMethodDao; |
| | | import com.iailab.module.model.mpk.entity.ModelMethodEntity; |
| | | import com.iailab.module.model.mpk.service.ModelMethodService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/9/9 10:51 |
| | | **/ |
| | | @Slf4j |
| | | @Service |
| | | public class ModelMethodServiceImpl extends BaseServiceImpl<ModelMethodDao, ModelMethodEntity> implements ModelMethodService { |
| | | |
| | | |
| | | @Override |
| | | public void deleteByMap(Map<String, Object> map) { |
| | | baseDao.delete(getWrapper(map)); |
| | | } |
| | | |
| | | private QueryWrapper<ModelMethodEntity> getWrapper(Map<String, Object> params) { |
| | | String mpkFileId = (String) params.get("mpkFileId"); |
| | | |
| | | QueryWrapper<ModelMethodEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq(StringUtils.isNotBlank(mpkFileId), "mpk_file_id", mpkFileId); |
| | | |
| | | return wrapper; |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.service.impl.CrudServiceImpl; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.model.mpk.dao.ProjectModelDao; |
| | | import com.iailab.module.model.mpk.dto.ProjectModelDTO; |
| | | import com.iailab.module.model.mpk.entity.ProjectModelEntity; |
| | | import com.iailab.module.model.mpk.service.ProjectModelService; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | @Service |
| | | public class ProjectModelServiceImpl extends CrudServiceImpl<ProjectModelDao, ProjectModelEntity, ProjectModelDTO> implements ProjectModelService { |
| | | @Override |
| | | public List<ProjectModelDTO> list(Map<String, Object> params) { |
| | | List<ProjectModelEntity> entityList = baseDao.selectList(getWrapper(params)); |
| | | |
| | | return ConvertUtils.sourceToTarget(entityList, ProjectModelDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByMap(Map<String,Object> map) { |
| | | baseDao.delete(getWrapper(map)); |
| | | } |
| | | |
| | | @Override |
| | | public QueryWrapper<ProjectModelEntity> getWrapper(Map<String, Object> params){ |
| | | String id = (String)params.get("id"); |
| | | String projectId = (String)params.get("projectId"); |
| | | String modelId = (String)params.get("modelId"); |
| | | |
| | | QueryWrapper<ProjectModelEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq(StringUtils.isNotBlank(id), "id", id) |
| | | .eq(StringUtils.isNotBlank(projectId), "project_id", projectId) |
| | | .eq(StringUtils.isNotBlank(modelId),"model_id",modelId); |
| | | |
| | | return wrapper; |
| | | } |
| | | |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.service.impl.CrudServiceImpl; |
| | | import com.iailab.module.model.mpk.dao.ProjectPackageHistoryModelDao; |
| | | import com.iailab.module.model.mpk.dto.ProjectPackageHistoryModelDTO; |
| | | import com.iailab.module.model.mpk.entity.ProjectPackageHistoryModelEntity; |
| | | import com.iailab.module.model.mpk.service.ProjectPackageHistoryModelService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @description: |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:41 |
| | | **/ |
| | | @Service |
| | | public class ProjectPackageHistoryModelServiceImpl extends CrudServiceImpl<ProjectPackageHistoryModelDao, ProjectPackageHistoryModelEntity, ProjectPackageHistoryModelDTO> implements ProjectPackageHistoryModelService { |
| | | |
| | | @Override |
| | | public PageData<ProjectPackageHistoryModelDTO> page(Map<String, Object> params) { |
| | | IPage<ProjectPackageHistoryModelEntity> page = baseDao.selectPage( |
| | | getPage(params, "py_name", true), |
| | | getWrapper(params) |
| | | ); |
| | | |
| | | return getPageData(page, ProjectPackageHistoryModelDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByMap(Map<String,Object> map) { |
| | | baseDao.delete(getWrapper(map)); |
| | | } |
| | | |
| | | @Override |
| | | public QueryWrapper<ProjectPackageHistoryModelEntity> getWrapper(Map<String, Object> params){ |
| | | String id = (String)params.get("id"); |
| | | String packageHistoryId = (String)params.get("packageHistoryId"); |
| | | String projectId = (String)params.get("projectId"); |
| | | String pyName = (String)params.get("pyName"); |
| | | |
| | | QueryWrapper<ProjectPackageHistoryModelEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq(StringUtils.isNotBlank(id), "id", id) |
| | | .eq(StringUtils.isNotBlank(packageHistoryId), "package_history_id", packageHistoryId) |
| | | .eq(StringUtils.isNotBlank(projectId),"project_id",projectId) |
| | | .like(StringUtils.isNotBlank(pyName),"py_name",pyName); |
| | | |
| | | return wrapper; |
| | | } |
| | | |
| | | |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.service.impl.CrudServiceImpl; |
| | | import com.iailab.module.model.mpk.dao.ProjectPackageHistoryDao; |
| | | import com.iailab.module.model.mpk.dto.ProjectPackageHistoryDTO; |
| | | import com.iailab.module.model.mpk.entity.ProjectPackageHistoryEntity; |
| | | import com.iailab.module.model.mpk.service.ProjectPackageHistoryService; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 项目打包历史记录表 |
| | | * |
| | | * @author Dzd |
| | | * @since 1.0.0 2024-08-22 |
| | | */ |
| | | @Service |
| | | public class ProjectPackageHistoryServiceImpl extends CrudServiceImpl<ProjectPackageHistoryDao, ProjectPackageHistoryEntity, ProjectPackageHistoryDTO> implements ProjectPackageHistoryService { |
| | | |
| | | @Override |
| | | public QueryWrapper<ProjectPackageHistoryEntity> getWrapper(Map<String, Object> params){ |
| | | String id = (String)params.get("id"); |
| | | String projectId = (String)params.get("projectId"); |
| | | String startTime = (String)params.get("startTime"); |
| | | String endTime = (String)params.get("endTime"); |
| | | |
| | | QueryWrapper<ProjectPackageHistoryEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq(StringUtils.isNotBlank(id), "id", id); |
| | | wrapper.eq(StringUtils.isNotBlank(projectId), "project_id", projectId); |
| | | wrapper.ge(StringUtils.isNotBlank(startTime), "create_time", startTime); |
| | | wrapper.le(StringUtils.isNotBlank(endTime), "create_time", endTime); |
| | | wrapper.orderByDesc("create_time"); |
| | | |
| | | return wrapper; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public byte[] download(String filePath) throws IOException { |
| | | File file = new File(filePath); |
| | | if (!file.exists()) { |
| | | log.error("文件不存在,路径:" + filePath); |
| | | } |
| | | return FileUtils.readFileToByteArray(file); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByMap(Map<String, Object> map) { |
| | | baseDao.delete(getWrapper(map)); |
| | | } |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.model.mpk.service.impl; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.iailab.framework.common.page.PageData; |
| | | import com.iailab.framework.common.service.impl.CrudServiceImpl; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.model.mpk.dao.MpkFileDao; |
| | | import com.iailab.module.model.mpk.dao.ProjectDao; |
| | | import com.iailab.module.model.mpk.dto.MpkFileDTO; |
| | | import com.iailab.module.model.mpk.dto.ProjectDTO; |
| | | import com.iailab.module.model.mpk.dto.ProjectModelDTO; |
| | | import com.iailab.module.model.mpk.dto.ProjectPackageHistoryDTO; |
| | | import com.iailab.module.model.mpk.entity.ProjectEntity; |
| | | import com.iailab.module.model.mpk.entity.ProjectModelEntity; |
| | | import com.iailab.module.model.mpk.entity.ProjectPackageHistoryModelEntity; |
| | | import com.iailab.module.model.mpk.service.ProjectModelService; |
| | | import com.iailab.module.model.mpk.service.ProjectPackageHistoryModelService; |
| | | import com.iailab.module.model.mpk.service.ProjectPackageHistoryService; |
| | | import com.iailab.module.model.mpk.service.ProjectService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.File; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @description: 项目表 |
| | | * @author: dzd |
| | | * @date: 2024/8/22 14:40 |
| | | **/ |
| | | @Service |
| | | @Slf4j |
| | | public class ProjectServiceImpl extends CrudServiceImpl<ProjectDao, ProjectEntity, ProjectDTO> implements ProjectService { |
| | | |
| | | @Autowired |
| | | ProjectModelService projectModelService; |
| | | @Autowired |
| | | ProjectPackageHistoryService projectPackageHistoryService; |
| | | @Autowired |
| | | ProjectPackageHistoryModelService projectPackageHistoryModelService; |
| | | @Autowired |
| | | MpkFileDao mpkFileDao; |
| | | |
| | | @Override |
| | | public PageData<ProjectDTO> page(Map<String, Object> params) { |
| | | IPage<ProjectDTO> page = baseDao.getPageList( |
| | | getPage(params, null, false), |
| | | params |
| | | ); |
| | | |
| | | return getPageData(page, ProjectDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public List<ProjectDTO> list(Map<String, Object> params) { |
| | | List<ProjectEntity> entityList = baseDao.selectList(getWrapper(params).orderByDesc("create_time")); |
| | | |
| | | return ConvertUtils.sourceToTarget(entityList, ProjectDTO.class); |
| | | } |
| | | |
| | | @Override |
| | | public ProjectDTO get(String id) { |
| | | ProjectEntity entity = baseDao.selectById(id); |
| | | ProjectDTO dto = ConvertUtils.sourceToTarget(entity, ProjectDTO.class); |
| | | |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("projectId",id); |
| | | List<ProjectModelDTO> projectModelList = projectModelService.list(map); |
| | | dto.setModels(projectModelList.stream().map(e -> { |
| | | MpkFileDTO mdkFileDTO = new MpkFileDTO(); |
| | | mdkFileDTO.setId(e.getModelId()); |
| | | return mdkFileDTO; |
| | | }).collect(Collectors.toList())); |
| | | |
| | | return dto; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void save(ProjectDTO dto) { |
| | | ProjectEntity entity = ConvertUtils.sourceToTarget(dto, ProjectEntity.class); |
| | | String projectId = UUID.randomUUID().toString(); |
| | | entity.setId(projectId); |
| | | entity.setCreateTime(new Date()); |
| | | insert(entity); |
| | | |
| | | //关联模型 |
| | | List<MpkFileDTO> models = dto.getModels(); |
| | | if (CollectionUtils.isNotEmpty(models)) { |
| | | List<ProjectModelEntity> projectModelList = new ArrayList<>(models.size()); |
| | | for (MpkFileDTO model : models) { |
| | | ProjectModelEntity projectModel = new ProjectModelEntity(); |
| | | projectModel.setId(UUID.randomUUID().toString()); |
| | | projectModel.setProjectId(projectId); |
| | | projectModel.setModelId(model.getId()); |
| | | projectModelList.add(projectModel); |
| | | } |
| | | projectModelService.insertBatch(projectModelList); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(ProjectDTO dto) { |
| | | ProjectEntity entity = ConvertUtils.sourceToTarget(dto, ProjectEntity.class); |
| | | entity.setUpdateTime(new Date()); |
| | | updateById(entity); |
| | | |
| | | String projectId = dto.getId(); |
| | | //删除关联 |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("projectId",projectId); |
| | | projectModelService.deleteByMap(map); |
| | | |
| | | //关联模型 |
| | | List<MpkFileDTO> models = dto.getModels(); |
| | | if (CollectionUtils.isNotEmpty(models)) { |
| | | List<ProjectModelEntity> projectModelList = new ArrayList<>(models.size()); |
| | | for (MpkFileDTO model : models) { |
| | | ProjectModelEntity projectModel = new ProjectModelEntity(); |
| | | projectModel.setId(UUID.randomUUID().toString()); |
| | | projectModel.setProjectId(projectId); |
| | | projectModel.setModelId(model.getId()); |
| | | projectModelList.add(projectModel); |
| | | } |
| | | projectModelService.insertBatch(projectModelList); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void delete(String id) { |
| | | |
| | | //删除 |
| | | baseDao.deleteById(id); |
| | | |
| | | //删除模型关联 |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("projectId",id); |
| | | projectModelService.deleteByMap(map); |
| | | |
| | | //删除备份文件 |
| | | List<ProjectPackageHistoryDTO> list = projectPackageHistoryService.list(map); |
| | | list.forEach(e -> { |
| | | File file = new File(e.getFilePath()); |
| | | if (file.exists()) { |
| | | file.delete(); |
| | | log.info("删除打包备份文件:" + e.getFilePath()); |
| | | } |
| | | }); |
| | | |
| | | //删除打包历史 |
| | | projectPackageHistoryService.deleteByMap(map); |
| | | |
| | | //删除打包历史模型关联 |
| | | projectPackageHistoryModelService.deleteByMap(map); |
| | | } |
| | | |
| | | @Override |
| | | public PageData<MpkFileDTO> getProjectModel(Map<String, Object> params) { |
| | | String projectId = (String) params.get("projectId"); |
| | | |
| | | int total = mpkFileDao.getProjectModelCount(projectId); |
| | | if (total == 0) { |
| | | return new PageData<>(new ArrayList<>(), 0); |
| | | } |
| | | int page = Integer.parseInt((String) params.get("page")); |
| | | int pageSize = Integer.parseInt((String) params.get("pageSize")); |
| | | int offset = (page - 1)*pageSize; |
| | | params.put("offset",offset); |
| | | params.put("pageSize",pageSize); |
| | | List<MpkFileDTO> list = mpkFileDao.getProjectModel(params); |
| | | |
| | | return new PageData<>(list,total); |
| | | } |
| | | |
| | | @Override |
| | | public QueryWrapper<ProjectEntity> getWrapper(Map<String, Object> params){ |
| | | String id = (String)params.get("id"); |
| | | String projectName = (String)params.get("projectName"); |
| | | |
| | | QueryWrapper<ProjectEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq(StringUtils.isNotBlank(id), "id", id) |
| | | .like(StringUtils.isNotBlank(projectName),"project_name",projectName); |
| | | |
| | | return wrapper; |
| | | } |
| | | |
| | | |
| | | } |
对比新文件 |
| | |
| | | package utils; |
| | | |
| | | import java.util.HashMap; |
| | | |
| | | |
| | | /** |
| | | * @Auther: Forrest |
| | | * @Date: 2020/6/8 14:05 |
| | | * @Description: |
| | | */ |
| | | public class AlgsUtils { |
| | | private HashMap<String, Object> model = new HashMap<String, Object>(); |
| | | |
| | | public HashMap<String, Object> createPredictHashmap(HashMap<String, Object> models) { |
| | | if ((models.containsKey("iail/mdk/model"))) { |
| | | if (((String) ((HashMap) models.get("iail/mdk/model")).get("param1")).isEmpty()) { |
| | | String aaa = "error"; |
| | | model.put("param1", aaa); |
| | | } else { |
| | | String model_train = (String) ((HashMap) models.get("iail/mdk/model")).get("param1"); |
| | | model.put("param1", model_train); |
| | | } |
| | | } else { |
| | | model = models; |
| | | } |
| | | return model; |
| | | } |
| | | |
| | | public HashMap<String, Object> createPredictHashmapplus(HashMap<String, Object> models) { |
| | | if (models != null && models.containsKey("models")) { |
| | | if (((String) ((HashMap) models.get("models")).get("paramFile")).isEmpty()) { |
| | | String aaa = "error"; |
| | | model.put("param1", aaa); |
| | | } else { |
| | | String model_train = (String) ((HashMap) models.get("models")).get("paramFile"); |
| | | model.put("paramFile", model_train); |
| | | if (((HashMap) models.get("models")).containsKey("dim")) { |
| | | Object dim = ((HashMap) models.get("models")).get("dim"); |
| | | model.put("dim", dim); |
| | | } |
| | | } |
| | | } else { |
| | | model = models; |
| | | } |
| | | return model; |
| | | } |
| | | |
| | | private HashMap<String, Object> eval_pre = new HashMap<String, Object>(); |
| | | |
| | | /** |
| | | * 对返回码进行转换 |
| | | * |
| | | * @param models |
| | | * @return |
| | | */ |
| | | public int reverseResultCode(HashMap<String, Object> models) { |
| | | if ((models.containsKey("result_code"))) { |
| | | return Integer.parseInt((String) models.get("result_code")); |
| | | } |
| | | return -2; |
| | | } |
| | | |
| | | /** |
| | | * 对评价指标进行转换 |
| | | * |
| | | * @param models |
| | | * @return |
| | | */ |
| | | public HashMap<String, Object> reverseEval(HashMap<String, Object> models) { |
| | | if ((models.containsKey("eval"))) { |
| | | if (((HashMap) models.get("eval")).containsKey("MAE")) { |
| | | double MAE = Double.parseDouble((String) ((HashMap) models.get("eval")).get("MAE")); |
| | | eval_pre.put("MAE", MAE); |
| | | } |
| | | if (((HashMap) models.get("eval")).containsKey("MAPE")) { |
| | | double MAPE = Double.parseDouble((String) ((HashMap) models.get("eval")).get("MAPE")); |
| | | eval_pre.put("MAPE", MAPE); |
| | | } |
| | | if (((HashMap) models.get("eval")).containsKey("RMSE")) { |
| | | double MAE = Double.parseDouble((String) ((HashMap) models.get("eval")).get("RMSE")); |
| | | eval_pre.put("RMSE", MAE); |
| | | } |
| | | } |
| | | |
| | | return eval_pre; |
| | | } |
| | | |
| | | /** |
| | | * 对models里面的参数进行转换 |
| | | */ |
| | | private HashMap<String, Object> train_result_models = new HashMap<String, Object>(); |
| | | |
| | | public HashMap<String, Object> reverseModels(HashMap<String, Object> train_result) { |
| | | if (train_result.containsKey("models")) { |
| | | train_result_models = (HashMap) train_result.get("models"); |
| | | if (((HashMap) train_result.get("models")).containsKey("dim")) { |
| | | double dim = Double.parseDouble((String) ((HashMap) train_result.get("models")).get("dim")); |
| | | train_result_models.put("dim", dim); |
| | | } |
| | | train_result.put("models", train_result_models); |
| | | } |
| | | return train_result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取二维数组行列数 |
| | | * |
| | | * @param arr |
| | | * @return |
| | | */ |
| | | public int[] getColAndRow(double[][] arr) { |
| | | int row = arr.length; |
| | | int col = arr[0].length; |
| | | int[] result = new int[2]; |
| | | result[0] = row; |
| | | result[1] = col; |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 两个二维数组进行合并 |
| | | * |
| | | * @param data |
| | | * @param refs |
| | | * @return |
| | | */ |
| | | public double[][] getMathergeArr(double[][] data, double[][] refs) { |
| | | |
| | | int[] dataRowAndCol = getColAndRow(data); |
| | | int rowData = dataRowAndCol[0]; |
| | | int colData = dataRowAndCol[1]; |
| | | |
| | | int[] refsRowAndCol = getColAndRow(refs); |
| | | int rowrefs = refsRowAndCol[0]; |
| | | int colrefs = refsRowAndCol[1]; |
| | | |
| | | double[][] newData = new double[rowData + rowrefs][colData]; |
| | | for (int i = 0; i < rowData; i++) { |
| | | for (int j = 0; j < colData; j++) { |
| | | newData[i][j] = data[i][j]; |
| | | } |
| | | } |
| | | |
| | | for (int i = 0; i < rowrefs; i++) { |
| | | for (int j = 0; j < colrefs; j++) { |
| | | newData[i + rowData][j] = refs[i][j]; |
| | | } |
| | | } |
| | | return newData; |
| | | } |
| | | |
| | | /** |
| | | * 对训练方法进行处理,实现评价指标的转换 |
| | | */ |
| | | public HashMap<String, Object> trainUtil(HashMap<String, Object> train_result, HashMap<String, Object> eval, String time) { |
| | | if (train_result.containsKey("eval")) { |
| | | eval = (HashMap<String, Object>) train_result.get("eval"); |
| | | eval.put("time", time); |
| | | train_result.put("eval", eval); |
| | | } |
| | | train_result.put("result_code", reverseResultCode(train_result)); |
| | | return train_result; |
| | | } |
| | | |
| | | /** |
| | | * 对预测方法进行处理 |
| | | */ |
| | | // public HashMap<String,Object> predictUtil(){ |
| | | // |
| | | // } |
| | | } |
对比新文件 |
| | |
| | | package common; |
| | | |
| | | /** |
| | | * @Description |
| | | * @Author Forrest |
| | | * @Mail 1255187617@qq.com |
| | | * @Date 2021/1/12 |
| | | */ |
| | | public class Environment { |
| | | private native int jniInit(); |
| | | |
| | | private native int jniIsInit(); |
| | | |
| | | private native void jniRelease(); |
| | | |
| | | private native int statusCode(); |
| | | |
| | | /** |
| | | * 初始化环境 |
| | | */ |
| | | public int init() { |
| | | return jniInit(); |
| | | } |
| | | |
| | | /** |
| | | * 获取初始化状态 |
| | | */ |
| | | public int isInit() { |
| | | return jniIsInit(); |
| | | } |
| | | |
| | | /** |
| | | * 释放资源 |
| | | */ |
| | | public void release() { |
| | | jniRelease(); |
| | | } |
| | | /** |
| | | *校验机器码 |
| | | * */ |
| | | // public int checkMachineCode(String mCode){ |
| | | // return statusCode(); |
| | | // } |
| | | } |
对比新文件 |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
| | | <mapper namespace="com.iailab.module.model.mpk.dao.MpkFileDao"> |
| | | |
| | | <resultMap id="mpkFile" type="com.iailab.module.model.mpk.dto.MpkFileDTO"> |
| | | <id property="id" column="id"/> |
| | | <result property="pyName" column="py_name"/> |
| | | <result property="filePath" column="file_path"/> |
| | | <result property="pkgName" column="pkg_name"/> |
| | | <result property="className" column="class_name"/> |
| | | <result property="pyModule" column="py_module"/> |
| | | <result property="remark" column="remark"/> |
| | | <result property="creator" column="creator"/> |
| | | <result property="createDate" column="create_date"/> |
| | | <result property="updater" column="updater"/> |
| | | <result property="updateDate" column="update_date"/> |
| | | <collection property="modelMethods" ofType="com.iailab.module.model.mpk.entity.ModelMethodEntity"> |
| | | <id property="id" column="method_id"/> |
| | | <result property="methodName" column="method_name"/> |
| | | <result property="dataLength" column="data_length"/> |
| | | <result property="model" column="model"/> |
| | | </collection> |
| | | </resultMap> |
| | | |
| | | <select id="get" resultMap="mpkFile"> |
| | | SELECT |
| | | a.*, |
| | | b.id method_id, |
| | | b.method_name, |
| | | b.data_length, |
| | | b.model |
| | | FROM |
| | | t_mpk_file a |
| | | LEFT JOIN t_mpk_model_method b ON a.id = b.mpk_file_id |
| | | WHERE a.id = #{id} |
| | | </select> |
| | | <select id="selectByIds" resultMap="mpkFile"> |
| | | SELECT |
| | | a.*, |
| | | b.id method_id, |
| | | b.method_name, |
| | | b.data_length, |
| | | b.model |
| | | FROM |
| | | t_mpk_file a |
| | | LEFT JOIN t_mpk_model_method b ON a.id = b.mpk_file_id |
| | | WHERE a.id in |
| | | <foreach collection="ids" item="item" open="(" close=")" separator=","> |
| | | #{item} |
| | | </foreach> |
| | | </select> |
| | | <select id="getProjectModelCount" resultType="java.lang.Integer" parameterType="java.lang.String"> |
| | | SELECT |
| | | count(*) |
| | | FROM |
| | | t_mpk_project_model |
| | | WHERE |
| | | project_id = #{projectId} |
| | | </select> |
| | | <select id="getProjectModel" resultMap="mpkFile"> |
| | | SELECT |
| | | t3.*,t4.method_name,t4.data_length,t4.model |
| | | FROM |
| | | ( |
| | | SELECT |
| | | t2.id, |
| | | t2.py_name, |
| | | t2.pkg_name, |
| | | t2.py_module, |
| | | t2.remark, |
| | | t2.create_date |
| | | FROM |
| | | t_mpk_project_model t1 |
| | | LEFT JOIN t_mpk_file t2 ON t1.model_id = t2.id |
| | | WHERE |
| | | t1.project_id = #{params.projectId} |
| | | <if test="params.pyName != null and params.pyName != ''"> |
| | | AND t2.py_name LIKE CONCAT('%',#{params.pyName},'%') |
| | | </if> |
| | | ORDER BY |
| | | t2.create_date DESC |
| | | LIMIT #{params.offset},#{params.pageSize} |
| | | ) t3 |
| | | LEFT JOIN t_mpk_model_method t4 ON t3.id = t4.mpk_file_id |
| | | </select> |
| | | </mapper> |
对比新文件 |
| | |
| | | <?xml version="1.0" encoding="UTF-8" ?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
| | | <mapper namespace="com.iailab.module.model.mpk.dao.ProjectDao"> |
| | | |
| | | <resultMap id="projectModel" type="com.iailab.module.model.mpk.dto.ProjectDTO"> |
| | | <id property="id" column="id"/> |
| | | <result property="projectName" column="project_name"/> |
| | | <result property="projectCode" column="project_code"/> |
| | | <result property="createTime" column="create_time"/> |
| | | <collection property="models" ofType="com.iailab.module.model.mpk.dto.MpkFileDTO"> |
| | | <id property="id" column="model_id"/> |
| | | <result property="pyName" column="py_name"/> |
| | | </collection> |
| | | </resultMap> |
| | | |
| | | <select id="getPageList" resultMap="projectModel" resultType="com.iailab.module.model.mpk.dto.ProjectDTO"> |
| | | SELECT |
| | | t1.id, |
| | | t1.project_name, |
| | | t1.project_code, |
| | | t1.create_time, |
| | | t2.model_id, |
| | | t3.py_name |
| | | FROM |
| | | t_mpk_project t1 |
| | | LEFT JOIN t_mpk_project_model t2 on t1.id = t2.project_id |
| | | LEFT JOIN t_mpk_file t3 ON t2.model_id = t3.id |
| | | <where> |
| | | <if test="params.projectName != null and params.projectName != ''"> |
| | | and t1.project_name like CONCAT('%',#{params.projectName},'%') |
| | | </if> |
| | | <if test="params.projectCode != null and params.projectCode != ''"> |
| | | and t1.project_code like CONCAT('%',#{params.projectCode},'%') |
| | | </if> |
| | | </where> |
| | | order by t1.create_time desc |
| | | </select> |
| | | </mapper> |
对比新文件 |
| | |
| | | \#include "pch.h" |
| | | \#include"cstring" |
| | | \#include <iostream> |
| | | \#include "framework.h" |
| | | \#include <fstream> |
| | | \#include <stdio.h> |
| | | \#include <stdlib.h> |
| | | \#include <string.h> |
| | | \#include"${pyName}Jni.h" |
| | | |
| | | #{foreach} ($entity in $modelMethods) |
| | | JNIEXPORT jobject JNICALL Java_${pkgName.replace('.','_')}_impl_${pyName}Impl_${pyName}${entity.methodName}(JNIEnv* env, jobject object1, #{foreach} ($column in [1..$entity.dataLength])jobjectArray data${column}, #{end}#{if}($entity.model==1)jobject model_path_, #{end}jobject settings) |
| | | { |
| | | jclass class_hashmap = env->FindClass("java/util/HashMap"); |
| | | jmethodID hashmap_construct_method = env->GetMethodID(class_hashmap, "<init>", "()V"); |
| | | jobject obj_hashmap = env->NewObject(class_hashmap, hashmap_construct_method, ""); |
| | | env->DeleteLocalRef(class_hashmap); |
| | | |
| | | obj_hashmap = ${pyName}_${entity.methodName}(env, #{foreach} ($column in [1..$entity.dataLength])data${column}, #{end}#{if}($entity.model==1)model_path_, #{end}settings); |
| | | return obj_hashmap; |
| | | } |
| | | #{end} |
对比新文件 |
| | |
| | | #pragma once |
| | | /* DO NOT EDIT THIS FILE - it is machine generated */ |
| | | //修改 |
| | | \#include "jni.h" |
| | | //\#include "common.h" |
| | | \#include"${pyName}.h" |
| | | /* Header for class Jni */ |
| | | |
| | | //修改cycleCom_impl_CycleComAlg_predFactGuiComShortPointLossRateV2Train |
| | | #ifndef _Included_iail_mdk_model_pred_fact_impl_${pyName}Impl_ |
| | | \#define _Included_iail_mdk_model_pred_fact_impl_${pyName}Impl_ |
| | | #ifdef __cplusplus |
| | | extern "C" { |
| | | #endif |
| | | /* |
| | | |
| | | */ |
| | | //修改Java_iail_mdk_model_pred_spred_impl_LssvmAlg_LssvmPredict |
| | | #{foreach} ($entity in $modelMethods) |
| | | JNIEXPORT jobject JNICALL Java_${pkgName.replace('.','_')}_impl_${pyName}Impl_${pyName}${entity.methodName} |
| | | (JNIEnv*, jobject, #{foreach} ($column in [1..$entity.dataLength])jobjectArray, #{end}#{if}($entity.model==1)jobject, #{end}jobject); |
| | | #{end} |
| | | |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | | #endif |
| | | #endif |
对比新文件 |
| | |
| | | package ${pkgName}; |
| | | |
| | | import java.util.HashMap; |
| | | |
| | | public abstract class ${pyName} { |
| | | |
| | | #{foreach} ($entity in $modelMethods) |
| | | public abstract HashMap<String, Object> ${entity.methodName}(#{foreach} ($column in [1..$entity.dataLength])double data${column}[][], #{end}#{if}($entity.model==1)HashMap<String, Object> model, #{end}HashMap<String, Object> settings); |
| | | |
| | | #{end} |
| | | } |
对比新文件 |
| | |
| | | \#include "stdafx.h" |
| | | \#include "pch.h" |
| | | \#include "${pyName}.h" |
| | | \#include <string> |
| | | \#include "pyutils.h" |
| | | \#include "jni.h" |
| | | \#include "Python.h" |
| | | \#include "PyGILThreadLock.h" |
| | | \#include "convertutils.h" |
| | | |
| | | using namespace std; |
| | | |
| | | #{foreach} ($entity in $modelMethods) |
| | | jobject ${pyName}_${entity.methodName}(JNIEnv* env, #{foreach} ($column in [1..$entity.dataLength])jobjectArray data${column}, #{end}#{if}($entity.model==1)jobject model_path_, #{end}jobject settings) |
| | | { |
| | | try |
| | | { |
| | | |
| | | PyGILThreadLock lock; |
| | | PyObject* pModule = create_py_module("${pyModule}.${pyName}"); |
| | | if (pModule == NULL) |
| | | { |
| | | cout << "model error" << endl; |
| | | throw "模块调用失败!"; |
| | | } |
| | | |
| | | //*************导入函数****************** |
| | | PyObject* pFunc = PyObject_GetAttrString(pModule, "${entity.methodName}"); |
| | | if (pFunc == NULL) |
| | | { |
| | | cout << "func error" << endl; |
| | | throw "函数调用失败!"; |
| | | } |
| | | #{foreach} ($column in [1..$entity.dataLength]) |
| | | PyObject* data_${column} = ConvertJdarrToPydarr(env, data${column}); |
| | | #{end} |
| | | #{if}($entity.model==1) |
| | | PyObject* model_path = ConvertJhmapToPydict(env, model_path_); |
| | | #{end} |
| | | PyObject* settings_1 = ConvertJhmapToPydict(env, settings); |
| | | |
| | | |
| | | //************构造参数数据 ******************** |
| | | #{if}($entity.model==1) |
| | | #set($a=$entity.dataLength + 2) |
| | | PyObject* pArg = PyTuple_New(${a}); |
| | | #{else} |
| | | #set($a=$entity.dataLength + 1) |
| | | PyObject* pArg = PyTuple_New(${a}); |
| | | #{end} |
| | | #{foreach} ($column in [1..$entity.dataLength]) |
| | | #set($a=$column - 1) |
| | | PyTuple_SetItem(pArg, ${a}, data_${column}); |
| | | #{end} |
| | | #{if}($entity.model==1) |
| | | PyTuple_SetItem(pArg, ${entity.dataLength}, model_path); |
| | | #set($a=$entity.dataLength + 1) |
| | | PyTuple_SetItem(pArg, ${a}, settings_1); |
| | | #{else} |
| | | PyTuple_SetItem(pArg, ${entity.dataLength}, settings_1); |
| | | #{end} |
| | | |
| | | /*PyTuple_SetItem(pArg, 1, parseCppData(data_in->feature_range));*/ |
| | | |
| | | |
| | | //********************调用python方法计算***************** |
| | | PyObject* pReturn = PyEval_CallObject(pFunc, pArg); |
| | | if (pReturn == NULL) |
| | | { |
| | | cout << "return error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | //*******************返回数据封装************************ |
| | | // 开辟返回数据内存空间,转换数据,拆分数据 |
| | | |
| | | /*jobject result = jhmappydict_(env, pReturn);*/ |
| | | jobject result = ConvertPydictToJhmap(env, pReturn); |
| | | if (result == NULL) |
| | | { |
| | | cout << "ConvertPydictToJhmap error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | delete pModule; |
| | | pModule = nullptr; |
| | | delete pModule; |
| | | |
| | | delete pFunc; |
| | | pFunc = nullptr; |
| | | delete pFunc; |
| | | |
| | | #{foreach} ($column in [1..$entity.dataLength]) |
| | | delete[] data_${column}; |
| | | data_${column} = nullptr; |
| | | delete data_${column}; |
| | | |
| | | #{end} |
| | | #{if}($entity.model==1) |
| | | delete model_path; |
| | | model_path = nullptr; |
| | | delete model_path; |
| | | #{end} |
| | | |
| | | delete settings_1; |
| | | settings_1 = nullptr; |
| | | delete settings_1; |
| | | |
| | | delete[] pArg; |
| | | pArg = nullptr; |
| | | delete pArg; |
| | | |
| | | return result; |
| | | } |
| | | catch (const char* msg) |
| | | { |
| | | cout << "${entity.methodName} error" << endl; |
| | | return NULL; |
| | | } |
| | | } |
| | | |
| | | #{end} |
对比新文件 |
| | |
| | | #pragma once |
| | | |
| | | #ifndef ${pyName}_H |
| | | \#define ${pyName}_H |
| | | |
| | | #endif //PCH_H |
| | | |
| | | #ifdef _EXPORTING |
| | | \#define API_DECLSPEC extern "C" __declspec(dllexport) |
| | | \#else |
| | | \#define API_DECLSPEC extern "C" __declspec(dllimport) |
| | | #endif |
| | | // 输入参数 |
| | | |
| | | \#include <string> |
| | | //\#include "PyGILThreadLock.h" |
| | | \#include <iostream> |
| | | \#include "Python.h" |
| | | \#include "jni.h" |
| | | |
| | | using namespace std; |
| | | |
| | | #{foreach} ($entity in $modelMethods) |
| | | jobject ${pyName}_${entity.methodName}(JNIEnv* env, #{foreach} ($column in [1..$entity.dataLength])jobjectArray data${column}, #{end}#{if}($entity.model==1)jobject model_path, #{end}jobject settings); |
| | | |
| | | #{end} |
对比新文件 |
| | |
| | | package ${pkgName}.impl; |
| | | |
| | | import ${pkgName}.${pyName}; |
| | | import utils.AlgsUtils; |
| | | |
| | | import java.util.HashMap; |
| | | |
| | | public class ${pyName}Impl extends ${pyName} { |
| | | private AlgsUtils utils = new AlgsUtils(); |
| | | //输出map |
| | | private HashMap<String, Object> result; |
| | | //predict输入模型 |
| | | private HashMap<String, Object> model; |
| | | |
| | | #{foreach} ($entity in $modelMethods) |
| | | public native HashMap<String, Object> ${pyName}${entity.methodName}(#foreach ($column in [1..$entity.dataLength])double data${column}[][], #{end}#{if}($entity.model==1)HashMap<String, Object> models, #{end}HashMap<String, Object> settings); |
| | | |
| | | @Override |
| | | public HashMap<String, Object> ${entity.methodName}(#foreach ($column in [1..$entity.dataLength])double data${column}[][], #{end}#{if}($entity.model==1)HashMap<String, Object> models, #{end}HashMap<String, Object> settings) { |
| | | #{if}($entity.model==1) |
| | | model = utils.createPredictHashmapplus(models); |
| | | #{end} |
| | | if (#{foreach} ($column in [1..$entity.dataLength])#{if}($column==1)data${column} == null || data${column}.length == 0 || data${column}[0].length == 0#{else} || data${column} == null || data${column}.length == 0 || data${column}[0].length == 0#{end}#{end}) { |
| | | result = new HashMap<String, Object>(); |
| | | result.put("status_code", -4); |
| | | return result; |
| | | } |
| | | result = ${pyName}${entity.methodName}(#foreach ($column in [1..$entity.dataLength])data${column}, #{end}#{if}($entity.model==1)model, #{end}settings); |
| | | |
| | | return result; |
| | | } |
| | | #{end} |
| | | } |
对比新文件 |
| | |
| | | MPK ${projectName} 【${version}】 ${now} 更新日志 |
| | | |
| | | #{foreach} ($entry in $dataMap.entrySet()) |
| | | -------------${entry.getKey()}-------------- |
| | | #{foreach} ($dto in $entry.getValue()) |
| | | ${foreach.count}.【${dto.version}】${dto.log} |
| | | #{end} |
| | | |
| | | #{end} |
对比新文件 |
| | |
| | | \#include "pch.h" |
| | | \#include"cstring" |
| | | \#include <iostream> |
| | | \#include "framework.h" |
| | | \#include <fstream> |
| | | \#include <stdio.h> |
| | | \#include <stdlib.h> |
| | | \#include <string.h> |
| | | |
| | | #{foreach} ($mpkEntity in $entities) |
| | | #{foreach} ($entity in $mpkEntity.modelMethods) |
| | | JNIEXPORT jobject JNICALL Java_${mpkEntity.pkgName.replace('.','_')}_impl_${mpkEntity.pyName}Impl_${mpkEntity.pyName}${entity.methodName}(JNIEnv* env, jobject object1, #{foreach} ($column in [1..$entity.dataLength])jobjectArray data${column}, #{end}#{if}($entity.model==1)jobject model_path_, #{end}jobject settings) |
| | | { |
| | | jclass class_hashmap = env->FindClass("java/util/HashMap"); |
| | | jmethodID hashmap_construct_method = env->GetMethodID(class_hashmap, "<init>", "()V"); |
| | | jobject obj_hashmap = env->NewObject(class_hashmap, hashmap_construct_method, ""); |
| | | env->DeleteLocalRef(class_hashmap); |
| | | |
| | | obj_hashmap = ${mpkEntity.pyName}_${entity.methodName}(env, #{foreach} ($column in [1..$entity.dataLength])data${column}, #{end}#{if}($entity.model==1)model_path_, #{end}settings); |
| | | return obj_hashmap; |
| | | } |
| | | #{end} |
| | | |
| | | #{end} |
对比新文件 |
| | |
| | | \#include "stdafx.h" |
| | | \#include "pch.h" |
| | | \#include <string> |
| | | \#include "pyutils.h" |
| | | \#include "jni.h" |
| | | \#include "Python.h" |
| | | \#include "PyGILThreadLock.h" |
| | | \#include "convertutils.h" |
| | | |
| | | using namespace std; |
| | | |
| | | #{foreach} ($mpkEntity in $entities) |
| | | #{foreach} ($entity in $mpkEntity.modelMethods) |
| | | jobject ${mpkEntity.pyName}_${entity.methodName}(JNIEnv* env, #{foreach} ($column in [1..$entity.dataLength])jobjectArray data${column}, #{end}#{if}($entity.model==1)jobject model_path_, #{end}jobject settings) |
| | | { |
| | | try |
| | | { |
| | | |
| | | PyGILThreadLock lock; |
| | | PyObject* pModule = create_py_module("${mpkEntity.pyModule}.${mpkEntity.pyName}"); |
| | | if (pModule == NULL) |
| | | { |
| | | cout << "model error" << endl; |
| | | throw "模块调用失败!"; |
| | | } |
| | | |
| | | //*************导入函数****************** |
| | | PyObject* pFunc = PyObject_GetAttrString(pModule, "${entity.methodName}"); |
| | | if (pFunc == NULL) |
| | | { |
| | | cout << "func error" << endl; |
| | | throw "函数调用失败!"; |
| | | } |
| | | #{foreach} ($column in [1..$entity.dataLength]) |
| | | PyObject* data_${column} = ConvertJdarrToPydarr(env, data${column}); |
| | | #{end} |
| | | #{if}($entity.model==1) |
| | | PyObject* model_path = ConvertJhmapToPydict(env, model_path_); |
| | | #{end} |
| | | PyObject* settings_1 = ConvertJhmapToPydict(env, settings); |
| | | |
| | | |
| | | //************构造参数数据 ******************** |
| | | #{if}($entity.model==1) |
| | | #set($a=$entity.dataLength + 2) |
| | | PyObject* pArg = PyTuple_New(${a}); |
| | | #{else} |
| | | #set($a=$entity.dataLength + 1) |
| | | PyObject* pArg = PyTuple_New(${a}); |
| | | #{end} |
| | | #{foreach} ($column in [1..$entity.dataLength]) |
| | | #set($a=$column - 1) |
| | | PyTuple_SetItem(pArg, ${a}, data_${column}); |
| | | #{end} |
| | | #{if}($entity.model==1) |
| | | PyTuple_SetItem(pArg, ${entity.dataLength}, model_path); |
| | | #set($a=$entity.dataLength + 1) |
| | | PyTuple_SetItem(pArg, ${a}, settings_1); |
| | | #{else} |
| | | PyTuple_SetItem(pArg, ${entity.dataLength}, settings_1); |
| | | #{end} |
| | | |
| | | /*PyTuple_SetItem(pArg, 1, parseCppData(data_in->feature_range));*/ |
| | | |
| | | |
| | | //********************调用python方法计算***************** |
| | | PyObject* pReturn = PyEval_CallObject(pFunc, pArg); |
| | | if (pReturn == NULL) |
| | | { |
| | | cout << "return error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | //*******************返回数据封装************************ |
| | | // 开辟返回数据内存空间,转换数据,拆分数据 |
| | | |
| | | /*jobject result = jhmappydict_(env, pReturn);*/ |
| | | jobject result = ConvertPydictToJhmap(env, pReturn); |
| | | if (result == NULL) |
| | | { |
| | | cout << "ConvertPydictToJhmap error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | delete pModule; |
| | | pModule = nullptr; |
| | | delete pModule; |
| | | |
| | | delete pFunc; |
| | | pFunc = nullptr; |
| | | delete pFunc; |
| | | |
| | | #{foreach} ($column in [1..$entity.dataLength]) |
| | | delete[] data_${column}; |
| | | data_${column} = nullptr; |
| | | delete data_${column}; |
| | | |
| | | #{end} |
| | | #{if}($entity.model==1) |
| | | delete model_path; |
| | | model_path = nullptr; |
| | | delete model_path; |
| | | #{end} |
| | | |
| | | delete settings_1; |
| | | settings_1 = nullptr; |
| | | delete settings_1; |
| | | |
| | | delete[] pArg; |
| | | pArg = nullptr; |
| | | delete pArg; |
| | | |
| | | return result; |
| | | } |
| | | catch (const char* msg) |
| | | { |
| | | cout << "${entity.methodName} error" << endl; |
| | | return NULL; |
| | | } |
| | | } |
| | | |
| | | #{end} |
| | | |
| | | #{end} |
对比新文件 |
| | |
| | | \#include "pch.h" |
| | | \#include"cstring" |
| | | \#include <iostream> |
| | | \#include "framework.h" |
| | | \#include <fstream> |
| | | \#include <stdio.h> |
| | | \#include <stdlib.h> |
| | | \#include <string.h> |
| | | \#include"${pyName}Jni.h" |
| | | |
| | | JNIEXPORT jobject JNICALL Java_${pkgName.replace('.','_')}_impl_${pyName}Impl_${pyName}Train(JNIEnv* env, jobject object1, jobjectArray data_train, jobject settings) |
| | | { |
| | | jclass class_hashmap = env->FindClass("java/util/HashMap"); |
| | | jmethodID hashmap_construct_method = env->GetMethodID(class_hashmap, "<init>", "()V"); |
| | | jobject obj_hashmap = env->NewObject(class_hashmap, hashmap_construct_method, ""); |
| | | env->DeleteLocalRef(class_hashmap); |
| | | |
| | | obj_hashmap = ${pyName}_train(env, data_train, settings); |
| | | return obj_hashmap; |
| | | } |
| | | |
| | | JNIEXPORT jobject JNICALL Java_${pkgName.replace('.','_')}_impl_${pyName}Impl_${pyName}Predict(JNIEnv* env, jobject object1, #{foreach} ($column in [1..$dataLength])jobjectArray data${column}, #{end}jobject model_path_, jobject settings) |
| | | { |
| | | jclass class_hashmap = env->FindClass("java/util/HashMap"); |
| | | jmethodID hashmap_construct_method = env->GetMethodID(class_hashmap, "<init>", "()V"); |
| | | jobject obj_hashmap = env->NewObject(class_hashmap, hashmap_construct_method, ""); |
| | | env->DeleteLocalRef(class_hashmap); |
| | | |
| | | obj_hashmap = ${pyName}_predict(env, #{foreach} ($column in [1..$dataLength])data${column}, #{end}model_path_, settings); |
| | | return obj_hashmap; |
| | | } |
对比新文件 |
| | |
| | | #pragma once |
| | | /* DO NOT EDIT THIS FILE - it is machine generated */ |
| | | //修改 |
| | | \#include "jni.h" |
| | | //\#include "common.h" |
| | | \#include"${pyName}.h" |
| | | /* Header for class Jni */ |
| | | |
| | | //修改cycleCom_impl_CycleComAlg_predFactGuiComShortPointLossRateV2Train |
| | | #ifndef _Included_iail_mdk_model_pred_fact_impl_${pyName}Impl_ |
| | | \#define _Included_iail_mdk_model_pred_fact_impl_${pyName}Impl_ |
| | | #ifdef __cplusplus |
| | | extern "C" { |
| | | #endif |
| | | /* |
| | | |
| | | */ |
| | | //修改Java_iail_mdk_model_pred_spred_impl_LssvmAlg_LssvmPredict |
| | | JNIEXPORT jobject JNICALL Java_${pkgName.replace('.','_')}_impl_${pyName}Impl_${pyName}Predict |
| | | (JNIEnv*, jobject, #{foreach} ($column in [1..$dataLength])jobjectArray, #{end}jobject, jobject); |
| | | JNIEXPORT jobject JNICALL Java_${pkgName.replace('.','_')}_impl_${pyName}Impl_${pyName}Train |
| | | (JNIEnv*, jobject, jobjectArray, jobject); |
| | | |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | | #endif |
| | | #endif |
对比新文件 |
| | |
| | | package ${pkgName}; |
| | | |
| | | import java.util.HashMap; |
| | | |
| | | public abstract class ${pyName} { |
| | | public abstract HashMap<String, Object> train(double data[][], HashMap<String, Object> settings); |
| | | |
| | | public abstract HashMap<String, Object> predict(#foreach ($column in [1..$dataLength])double data${column}[][], #{end}HashMap<String, Object> model, HashMap<String, Object> settings); |
| | | } |
对比新文件 |
| | |
| | | \#include "stdafx.h" |
| | | \#include "pch.h" |
| | | \#include "${pyName}.h" |
| | | \#include <string> |
| | | \#include "pyutils.h" |
| | | \#include "jni.h" |
| | | \#include "Python.h" |
| | | \#include "PyGILThreadLock.h" |
| | | \#include "convertutils.h" |
| | | |
| | | using namespace std; |
| | | |
| | | jobject ${pyName}_train(JNIEnv* env, jobjectArray data_train, jobject settings) |
| | | { |
| | | try |
| | | { |
| | | PyGILThreadLock lock; |
| | | PyObject* pModule = create_py_module("${pyModule}.${pyName}"); |
| | | if (pModule == NULL) |
| | | { |
| | | cout << "pModule error" << endl; |
| | | throw "模块调用失败!"; |
| | | } |
| | | |
| | | //*************导入函数****************** |
| | | PyObject* pFunc = PyObject_GetAttrString(pModule, "train"); |
| | | if (pFunc == NULL) |
| | | { |
| | | cout << "pfunc error" << endl; |
| | | throw "函数调用失败!"; |
| | | } |
| | | PyObject* data_1 = ConvertJdarrToPydarr(env, data_train); |
| | | PyObject* settings_ = ConvertJhmapToPydict(env, settings); |
| | | |
| | | //************构造参数数据 ******************** |
| | | PyObject* pArg = PyTuple_New(2); |
| | | PyTuple_SetItem(pArg, 0, data_1); |
| | | PyTuple_SetItem(pArg, 1, settings_); |
| | | |
| | | /*PyTuple_SetItem(pArg, 1, parseCppData(data_in->feature_range));*/ |
| | | |
| | | |
| | | //********************调用python方法计算***************** |
| | | PyObject* pReturn = PyEval_CallObject(pFunc, pArg); |
| | | if (pReturn == NULL) |
| | | { |
| | | cout << "pReturn error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | //*******************返回数据封装************************ |
| | | // 开辟返回数据内存空间,转换数据,拆分数据 |
| | | |
| | | /*jobject result = jhmappydict_(env, pReturn);*/ |
| | | jobject result = ConvertPydictToJhmap(env, pReturn); |
| | | if (result == NULL) |
| | | { |
| | | cout << "ConvertPydictToJhmap error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | delete pModule, pFunc, data_1, settings_, pArg; |
| | | return result; |
| | | } |
| | | catch (const char* msg) |
| | | { |
| | | cout << "train error" << endl; |
| | | return NULL; |
| | | } |
| | | } |
| | | |
| | | jobject ${pyName}_predict(JNIEnv* env, #{foreach} ($column in [1..$dataLength])jobjectArray data${column}, #{end}jobject model_path_,jobject settings) |
| | | { |
| | | try |
| | | { |
| | | |
| | | PyGILThreadLock lock; |
| | | PyObject* pModule = create_py_module("${pyModule}.${pyName}"); |
| | | if (pModule == NULL) |
| | | { |
| | | cout << "model error" << endl; |
| | | throw "模块调用失败!"; |
| | | } |
| | | |
| | | //*************导入函数****************** |
| | | PyObject* pFunc = PyObject_GetAttrString(pModule, "predict"); |
| | | if (pFunc == NULL) |
| | | { |
| | | cout << "func error" << endl; |
| | | throw "函数调用失败!"; |
| | | } |
| | | #{foreach} ($column in [1..$dataLength]) |
| | | PyObject* data_${column} = ConvertJdarrToPydarr(env, data${column}); |
| | | #{end} |
| | | PyObject* model_path = ConvertJhmapToPydict(env, model_path_); |
| | | PyObject* settings_1 = ConvertJhmapToPydict(env, settings); |
| | | |
| | | |
| | | //************构造参数数据 ******************** |
| | | #set($a=$dataLength + 2) |
| | | PyObject* pArg = PyTuple_New(${a}); |
| | | #{foreach} ($column in [1..$dataLength]) |
| | | #set($a=$column - 1) |
| | | PyTuple_SetItem(pArg, ${a}, data_${column}); |
| | | #{end} |
| | | PyTuple_SetItem(pArg, ${dataLength}, model_path); |
| | | #set($a=$dataLength + 1) |
| | | PyTuple_SetItem(pArg, ${a}, settings_1); |
| | | |
| | | /*PyTuple_SetItem(pArg, 1, parseCppData(data_in->feature_range));*/ |
| | | |
| | | |
| | | //********************调用python方法计算***************** |
| | | PyObject* pReturn = PyEval_CallObject(pFunc, pArg); |
| | | if (pReturn == NULL) |
| | | { |
| | | cout << "return error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | //*******************返回数据封装************************ |
| | | // 开辟返回数据内存空间,转换数据,拆分数据 |
| | | |
| | | /*jobject result = jhmappydict_(env, pReturn);*/ |
| | | jobject result = ConvertPydictToJhmap(env, pReturn); |
| | | if (result == NULL) |
| | | { |
| | | cout << "ConvertPydictToJhmap error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | delete pModule; |
| | | pModule = nullptr; |
| | | delete pModule; |
| | | |
| | | delete pFunc; |
| | | pFunc = nullptr; |
| | | delete pFunc; |
| | | |
| | | #{foreach} ($column in [1..$dataLength]) |
| | | delete[] data_${column}; |
| | | data_${column} = nullptr; |
| | | delete data_${column}; |
| | | |
| | | #{end} |
| | | delete model_path; |
| | | model_path = nullptr; |
| | | delete model_path; |
| | | |
| | | delete settings_1; |
| | | settings_1 = nullptr; |
| | | delete settings_1; |
| | | |
| | | delete[] pArg; |
| | | pArg = nullptr; |
| | | delete pArg; |
| | | |
| | | return result; |
| | | } |
| | | catch (const char* msg) |
| | | { |
| | | cout << "predict error" << endl; |
| | | return NULL; |
| | | } |
| | | } |
对比新文件 |
| | |
| | | #pragma once |
| | | |
| | | #ifndef ${pyName}_H |
| | | \#define ${pyName}_H |
| | | |
| | | #endif //PCH_H |
| | | |
| | | #ifdef _EXPORTING |
| | | \#define API_DECLSPEC extern "C" __declspec(dllexport) |
| | | \#else |
| | | \#define API_DECLSPEC extern "C" __declspec(dllimport) |
| | | #endif |
| | | // 输入参数 |
| | | |
| | | \#include <string> |
| | | //\#include "PyGILThreadLock.h" |
| | | \#include <iostream> |
| | | \#include "Python.h" |
| | | \#include "jni.h" |
| | | |
| | | using namespace std; |
| | | |
| | | jobject ${pyName}_train(JNIEnv* env, jobjectArray data_train, jobject settings); |
| | | jobject ${pyName}_predict(JNIEnv* env, #{foreach} ($column in [1..$dataLength])jobjectArray data${column}, #{end}jobject model_path, jobject settings); |
对比新文件 |
| | |
| | | package ${pkgName}.impl; |
| | | |
| | | import ${pkgName}.${pyName}; |
| | | import utils.AlgsUtils; |
| | | |
| | | import java.util.HashMap; |
| | | |
| | | public class ${pyName}Impl extends ${pyName} { |
| | | private AlgsUtils utils = new AlgsUtils(); |
| | | //train的输出map |
| | | private HashMap<String, Object> train_result; |
| | | //predict输入模型 |
| | | private HashMap<String, Object> model; |
| | | //predict输出模型 |
| | | private HashMap<String, Object> predict_result; |
| | | |
| | | public native HashMap<String, Object> ${pyName}Train(double[][] dataone, HashMap<String, Object> settings); |
| | | |
| | | @Override |
| | | public HashMap<String, Object> train(double[][] dataone, HashMap<String, Object> settings) { |
| | | double startTime = System.currentTimeMillis(); //获取开始时间 |
| | | |
| | | if (dataone == null || dataone.length == 0 || dataone[0].length == 0) { |
| | | train_result = new HashMap<String, Object>(); |
| | | train_result.put("status_code", -4); |
| | | return train_result; |
| | | } |
| | | |
| | | train_result = ${pyName}Train(dataone, settings); |
| | | return train_result; |
| | | } |
| | | |
| | | public native HashMap<String, Object> ${pyName}Predict(#foreach ($column in [1..$dataLength])double data${column}[][], #{end}HashMap<String, Object> models, HashMap<String, Object> settings); |
| | | |
| | | @Override |
| | | public HashMap<String, Object> predict(#foreach ($column in [1..$dataLength])double data${column}[][], #{end}HashMap<String, Object> models, HashMap<String, Object> settings) { |
| | | model = utils.createPredictHashmapplus(models); |
| | | if (#{foreach} ($column in [1..$dataLength])#{if}($column==1)data${column} == null || data${column}.length == 0 || data${column}[0].length == 0#{else} || data${column} == null || data${column}.length == 0 || data${column}[0].length == 0#{end}#{end}) { |
| | | predict_result = new HashMap<String, Object>(); |
| | | predict_result.put("status_code", -4); |
| | | return predict_result; |
| | | } |
| | | predict_result = ${pyName}Predict(#foreach ($column in [1..$dataLength])data${column}, #{end}model, settings); |
| | | |
| | | // predict_result.put("result_code",utils.reverseResultCode(predict_result)); |
| | | return predict_result; |
| | | } |
| | | } |
对比新文件 |
| | |
| | | MDK ${projectName} ${now} 更新日志 |
| | | |
| | | #{foreach} ($entry in $dataMap.entrySet()) |
| | | -------------${entry.getKey()}-------------- |
| | | #{foreach} ($dto in $entry.getValue()) |
| | | ${foreach.count}.${dto.getLog()} |
| | | #{end} |
| | | |
| | | #{end} |
对比新文件 |
| | |
| | | \#include "pch.h" |
| | | \#include"cstring" |
| | | \#include <iostream> |
| | | \#include "framework.h" |
| | | \#include <fstream> |
| | | \#include <stdio.h> |
| | | \#include <stdlib.h> |
| | | \#include <string.h> |
| | | |
| | | #{foreach} ($entity in $entities) |
| | | JNIEXPORT jobject JNICALL Java_${entity.pkgName.replace('.','_')}_impl_${entity.pyName}Impl_${entity.pyName}Train(JNIEnv* env, jobject object1, jobjectArray data_train, jobject settings) |
| | | { |
| | | jclass class_hashmap = env->FindClass("java/util/HashMap"); |
| | | jmethodID hashmap_construct_method = env->GetMethodID(class_hashmap, "<init>", "()V"); |
| | | jobject obj_hashmap = env->NewObject(class_hashmap, hashmap_construct_method, ""); |
| | | env->DeleteLocalRef(class_hashmap); |
| | | |
| | | obj_hashmap = ${entity.pyName}_train(env, data_train, settings); |
| | | return obj_hashmap; |
| | | } |
| | | |
| | | JNIEXPORT jobject JNICALL Java_${entity.pkgName.replace('.','_')}_impl_${entity.pyName}Impl_${entity.pyName}Predict(JNIEnv* env, jobject object1, #{foreach} ($column in [1..$entity.dataLength])jobjectArray data${column}, #{end}jobject model_path_, jobject settings) |
| | | { |
| | | jclass class_hashmap = env->FindClass("java/util/HashMap"); |
| | | jmethodID hashmap_construct_method = env->GetMethodID(class_hashmap, "<init>", "()V"); |
| | | jobject obj_hashmap = env->NewObject(class_hashmap, hashmap_construct_method, ""); |
| | | env->DeleteLocalRef(class_hashmap); |
| | | |
| | | obj_hashmap = ${entity.pyName}_predict(env, #{foreach} ($column in [1..$entity.dataLength])data${column}, #{end}model_path_, settings); |
| | | return obj_hashmap; |
| | | } |
| | | |
| | | #{end} |
对比新文件 |
| | |
| | | \#include "stdafx.h" |
| | | \#include "pch.h" |
| | | \#include <string> |
| | | \#include "pyutils.h" |
| | | \#include "jni.h" |
| | | \#include "Python.h" |
| | | \#include "PyGILThreadLock.h" |
| | | \#include "convertutils.h" |
| | | |
| | | using namespace std; |
| | | |
| | | #{foreach} ($entity in $entities) |
| | | jobject ${entity.pyName}_train(JNIEnv* env, jobjectArray data_train, jobject settings) |
| | | { |
| | | try |
| | | { |
| | | PyGILThreadLock lock; |
| | | PyObject* pModule = create_py_module("${entity.pyModule}.${entity.pyName}"); |
| | | if (pModule == NULL) |
| | | { |
| | | cout << "pModule error" << endl; |
| | | throw "模块调用失败!"; |
| | | } |
| | | |
| | | //*************导入函数****************** |
| | | PyObject* pFunc = PyObject_GetAttrString(pModule, "train"); |
| | | if (pFunc == NULL) |
| | | { |
| | | cout << "pfunc error" << endl; |
| | | throw "函数调用失败!"; |
| | | } |
| | | PyObject* data_1 = ConvertJdarrToPydarr(env, data_train); |
| | | PyObject* settings_ = ConvertJhmapToPydict(env, settings); |
| | | |
| | | //************构造参数数据 ******************** |
| | | PyObject* pArg = PyTuple_New(2); |
| | | PyTuple_SetItem(pArg, 0, data_1); |
| | | PyTuple_SetItem(pArg, 1, settings_); |
| | | |
| | | /*PyTuple_SetItem(pArg, 1, parseCppData(data_in->feature_range));*/ |
| | | |
| | | |
| | | //********************调用python方法计算***************** |
| | | PyObject* pReturn = PyEval_CallObject(pFunc, pArg); |
| | | if (pReturn == NULL) |
| | | { |
| | | cout << "pReturn error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | //*******************返回数据封装************************ |
| | | // 开辟返回数据内存空间,转换数据,拆分数据 |
| | | |
| | | /*jobject result = jhmappydict_(env, pReturn);*/ |
| | | jobject result = ConvertPydictToJhmap(env, pReturn); |
| | | if (result == NULL) |
| | | { |
| | | cout << "ConvertPydictToJhmap error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | delete pModule, pFunc, data_1, settings_, pArg; |
| | | return result; |
| | | } |
| | | catch (const char* msg) |
| | | { |
| | | cout << "train error" << endl; |
| | | return NULL; |
| | | } |
| | | } |
| | | |
| | | jobject ${entity.pyName}_predict(JNIEnv* env, #{foreach} ($column in [1..$entity.dataLength])jobjectArray data${column}, #{end}jobject model_path_,jobject settings) |
| | | { |
| | | try |
| | | { |
| | | |
| | | PyGILThreadLock lock; |
| | | PyObject* pModule = create_py_module("${entity.pyModule}.${entity.pyName}"); |
| | | if (pModule == NULL) |
| | | { |
| | | cout << "model error" << endl; |
| | | throw "模块调用失败!"; |
| | | } |
| | | |
| | | //*************导入函数****************** |
| | | PyObject* pFunc = PyObject_GetAttrString(pModule, "predict"); |
| | | if (pFunc == NULL) |
| | | { |
| | | cout << "func error" << endl; |
| | | throw "函数调用失败!"; |
| | | } |
| | | #{foreach} ($column in [1..$entity.dataLength]) |
| | | PyObject* data_${column} = ConvertJdarrToPydarr(env, data${column}); |
| | | #{end} |
| | | PyObject* model_path = ConvertJhmapToPydict(env, model_path_); |
| | | PyObject* settings_1 = ConvertJhmapToPydict(env, settings); |
| | | |
| | | |
| | | //************构造参数数据 ******************** |
| | | #set($a=$entity.dataLength + 2) |
| | | PyObject* pArg = PyTuple_New(${a}); |
| | | #{foreach} ($column in [1..$entity.dataLength]) |
| | | #set($a=$column - 1) |
| | | PyTuple_SetItem(pArg, ${a}, data_${column}); |
| | | #{end} |
| | | PyTuple_SetItem(pArg, ${entity.dataLength}, model_path); |
| | | #set($a=$entity.dataLength + 1) |
| | | PyTuple_SetItem(pArg, ${a}, settings_1); |
| | | |
| | | /*PyTuple_SetItem(pArg, 1, parseCppData(data_in->feature_range));*/ |
| | | |
| | | |
| | | //********************调用python方法计算***************** |
| | | PyObject* pReturn = PyEval_CallObject(pFunc, pArg); |
| | | if (pReturn == NULL) |
| | | { |
| | | cout << "return error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | //*******************返回数据封装************************ |
| | | // 开辟返回数据内存空间,转换数据,拆分数据 |
| | | |
| | | /*jobject result = jhmappydict_(env, pReturn);*/ |
| | | jobject result = ConvertPydictToJhmap(env, pReturn); |
| | | if (result == NULL) |
| | | { |
| | | cout << "ConvertPydictToJhmap error" << endl; |
| | | throw "函数返回值异常!"; |
| | | } |
| | | delete pModule; |
| | | pModule = nullptr; |
| | | delete pModule; |
| | | |
| | | delete pFunc; |
| | | pFunc = nullptr; |
| | | delete pFunc; |
| | | |
| | | #{foreach} ($column in [1..$entity.dataLength]) |
| | | delete[] data_${column}; |
| | | data_${column} = nullptr; |
| | | delete data_${column}; |
| | | |
| | | #{end} |
| | | delete model_path; |
| | | model_path = nullptr; |
| | | delete model_path; |
| | | |
| | | delete settings_1; |
| | | settings_1 = nullptr; |
| | | delete settings_1; |
| | | |
| | | delete[] pArg; |
| | | pArg = nullptr; |
| | | delete pArg; |
| | | |
| | | return result; |
| | | } |
| | | catch (const char* msg) |
| | | { |
| | | cout << "predict error" << endl; |
| | | return NULL; |
| | | } |
| | | } |
| | | |
| | | #{end} |