iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/ind/IndItemApi.java
@@ -17,7 +17,7 @@ * @createTime 2024年08月19日 */ @FeignClient(name = ApiConstants.NAME) @Tag(name = "指标项服务") @Tag(name = "指标数据") public interface IndItemApi { String PREFIX = ApiConstants.PREFIX + "/ind-item"; iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/DataPointApi.java
@@ -5,10 +5,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; @@ -19,34 +16,34 @@ * @createTime 2024年08月19日 */ @FeignClient(name = ApiConstants.NAME) @Tag(name = "数据测点服务") @Tag(name = "测点接口") public interface DataPointApi { String PREFIX = ApiConstants.PREFIX + "/point"; @PostMapping(PREFIX + "/point-no/{pointNo}") @Operation(summary = "查询测点信息") ApiPointDTO getPointByNo(@PathVariable("pointNo") String pointNo); @GetMapping(PREFIX + "/info/no/{pointNo}") @Operation(summary = "根据测点编号查询测点信息") ApiPointDTO getInfoByNo(@PathVariable("pointNo") String pointNo); @PostMapping(PREFIX + "/point-id/{pointId}") @Operation(summary = "查询测点信息") ApiPointDTO getPointById(@PathVariable("pointId") String pointId); @GetMapping(PREFIX + "/info/id/{pointId}") @Operation(summary = "根据测点ID查询测点信息") ApiPointDTO getInfoById(@PathVariable("pointId") String pointId); @PostMapping(PREFIX + "/current") @PostMapping(PREFIX + "/query-points/real-value") @Operation(summary = "查询多个测点当前值") Map<String, Object> pointsCurrent(@RequestParam("pointNos") List<String> pointNos); Map<String, Object> queryPointsRealValue(@RequestParam("pointNos") List<String> pointNos); @PostMapping(PREFIX + "/history") @PostMapping(PREFIX + "/query-points/history-value") @Operation(summary = "查询多个测点历史值") Map<String, List<Map<String, Object>>> pointsHistory(@RequestBody ApiPointsValueQueryDTO queryDto); Map<String, List<Map<String, Object>>> queryPointsHistoryValue(@RequestBody ApiPointsValueQueryDTO queryDto); @PostMapping(PREFIX + "/value/get") @GetMapping(PREFIX + "/query-point/history-value") @Operation(summary = "查询单个测点历史值") List<ApiPointValueDTO> getValue(@RequestBody ApiPointValueQueryDTO queryDto); List<ApiPointValueDTO> queryPointHistoryValue(@RequestParam ApiPointValueQueryDTO queryDto); @PostMapping(PREFIX + "/value/set") @Operation(summary = "设置单个测点值") Boolean setValue(@RequestBody ApiPointValueWriteDTO queryDto); @PutMapping(PREFIX + "/write-point/real-value") @Operation(summary = "写入单个测点值") Boolean writePointRealValue(@RequestBody ApiPointValueWriteDTO queryDto); } iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/point/dto/ApiPointValueWriteDTO.java
@@ -20,5 +20,5 @@ private String pointNo; @Schema(description = "测点值") private Object pointValue; private Object value; } iailab-module-data/iailab-module-data-biz/db/mysql/tenant.sql
@@ -283,7 +283,7 @@ `item_no` VARCHAR(36) COMMENT '指标编码' , `item_name` VARCHAR(36) COMMENT '指标名称' , `item_type` VARCHAR(20) COMMENT '指标类型' , `item_category` VARCHAR(20) COMMENT '指标分类' , `item_category` VARCHAR(36) COMMENT '指标分类' , `coefficient` decimal(10, 4) COMMENT '转换系数', `precision` int COMMENT '指标精度', `time_granularity` VARCHAR(10) COMMENT '时间粒度' , iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/point/DataPointApiImpl.java
@@ -17,32 +17,32 @@ public class DataPointApiImpl implements DataPointApi { @Override public ApiPointDTO getPointByNo(String pointNo) { public ApiPointDTO getInfoByNo(String pointNo) { return null; } @Override public ApiPointDTO getPointById(String pointId) { public ApiPointDTO getInfoById(String pointId) { return null; } @Override public Map<String, Object> pointsCurrent(List<String> pointNos) { public Map<String, Object> queryPointsRealValue(List<String> pointNos) { return null; } @Override public Map<String, List<Map<String, Object>>> pointsHistory(ApiPointsValueQueryDTO queryDto) { public Map<String, List<Map<String, Object>>> queryPointsHistoryValue(ApiPointsValueQueryDTO queryDto) { return null; } @Override public List<ApiPointValueDTO> getValue(ApiPointValueQueryDTO queryDto) { public List<ApiPointValueDTO> queryPointHistoryValue(ApiPointValueQueryDTO queryDto) { return null; } @Override public Boolean setValue(ApiPointValueWriteDTO queryDto) { public Boolean writePointRealValue(ApiPointValueWriteDTO queryDto) { return null; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndTimeRangeConst.java
对比新文件 @@ -0,0 +1,60 @@ package com.iailab.module.data.common.enums; /** * @author PanZhibao * @Description * @createTime 2024年05月27日 */ public interface IndTimeRangeConst { /** * 自定义 */ String CUSTOM = "CUSTOM"; /** * 今天 */ String TODAY = "TODAY"; /** * 昨天 */ String YESTERDAY = "YESTERDAY"; /** * 最近7天 */ String LAST_DAY_7 = "LAST_DAY_7"; /** * 最近30天 */ String LAST_DAY_30 = "LAST_DAY_30"; /** * 当前月 */ String THIS_MONTH = "THIS_MONTH"; /** * 最近12个月 */ String LAST_MONTH_12 = "LAST_MONTH_12"; /** * 当年月份 */ String THIS_YEAR_MONTH = "THIS_YEAR_MONTH"; /** * 去年 */ String LAST_YEAR = "LAST_YEAR"; /** * 今年 */ String THIS_YEAR = "THIS_YEAR"; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/IndTimeRangeEnum.java
对比新文件 @@ -0,0 +1,42 @@ package com.iailab.module.data.common.enums; /** * @author PanZhibao * @Description * @createTime 2024年05月25日 */ public enum IndTimeRangeEnum { LAST_YEAR("LAST_YEAR", "LAST_YEAR"), THIS_YEAR("THIS_YEAR", "THIS_YEAR"), LAST_MONTH_12("LAST_MONTH_12", "LAST_MONTH_12"), YESTERDAY("YESTERDAY", "YESTERDAY"), TODAY("TODAY", "TODAY"), LAST_DAY_7("LAST_DAY_7", "LAST_DAY_7"), LAST_DAY_30("LAST_DAY_30", "LAST_DAY_30"); private String code; private String name; IndTimeRangeEnum(String code, String name) { this.code = code; this.name = name; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getName() { return name; } public void setName(String name) { this.name = name; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/ItemTypeEnum.java
@@ -4,6 +4,8 @@ import lombok.Getter; /** * 指标类型 * * @author PanZhibao * @Description * @createTime 2023年05月03日 19:10:00 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/item/service/impl/IndItemServiceImpl.java
@@ -50,7 +50,6 @@ } @Override @Transactional(rollbackFor = Exception.class) @DSTransactional(rollbackFor= Exception.class) public void create(IndItemSaveReqVO createReqVO) { IndItemEntity entity = BeanUtils.toBean(createReqVO, IndItemEntity.class); iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/service/impl/DaPointServiceImpl.java
@@ -74,8 +74,6 @@ @Override public List<DaPointDTO> list(Map<String, Object> params) { Object page = params.get("page"); Object limit = params.get("limit"); Object pointType = params.get("pointType"); List<String> pointNos = new ArrayList<>(); if (params.get("pointNos") != null) { iailab-module-data/iailab-module-data-biz/src/main/resources/application.yml
@@ -198,6 +198,8 @@ - t_ind_item_category - t_ind_item - t_ind_item_atom - t_ind_item_der - t_ind_item_cal app: app-key: data app-secret: 85b0df7edc3df3611913df34ed695011 iailab-module-model/.flattened-pom.xml
对比新文件 @@ -0,0 +1,23 @@ <?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.iailab</groupId> <artifactId>iailab-plat</artifactId> <version>0.0.1</version> </parent> <groupId>com.iailab</groupId> <artifactId>iailab-module-model</artifactId> <version>0.0.1</version> <packaging>pom</packaging> <modules> <module>iailab-module-model-biz</module> <module>iailab-module-model-api</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> </project> iailab-module-model/iailab-module-model-api/.flattened-pom.xml
对比新文件 @@ -0,0 +1,38 @@ <?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.iailab</groupId> <artifactId>iailab-module-model</artifactId> <version>0.0.1</version> </parent> <groupId>com.iailab</groupId> <artifactId>iailab-module-model-api</artifactId> <version>0.0.1</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common</artifactId> </dependency> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <optional>true</optional> </dependency> </dependencies> </project> iailab-module-model/iailab-module-model-biz/.flattened-pom.xml
对比新文件 @@ -0,0 +1,179 @@ <?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.iailab</groupId> <artifactId>iailab-module-model</artifactId> <version>0.0.1</version> </parent> <groupId>com.iailab</groupId> <artifactId>iailab-module-model-biz</artifactId> <version>0.0.1</version> <properties> <mdk.version>MDK.taisteel.202308231710</mdk.version> <easypoi.version>4.1.0</easypoi.version> <commons.io.version>2.11.0</commons.io.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>8</maven.compiler.source> <velocity.version>1.7</velocity.version> <maven.compiler.target>8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-env</artifactId> </dependency> <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> <groupId>com.iailab</groupId> <artifactId>iailab-module-system-api</artifactId> <version>${revision}</version> </dependency> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-biz-data-permission</artifactId> </dependency> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-biz-tenant</artifactId> </dependency> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-biz-ip</artifactId> </dependency> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-module-model-api</artifactId> <version>${revision}</version> </dependency> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-security</artifactId> </dependency> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-mybatis</artifactId> </dependency> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-rpc</artifactId> </dependency> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-monitor</artifactId> </dependency> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-biz-data-permission</artifactId> </dependency> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.iailab</groupId> <artifactId>iailab-common-excel</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.1</version> </dependency> <dependency> <groupId>com.iail</groupId> <artifactId>IAILMDK</artifactId> <version>0.94.9</version> </dependency> <dependency> <groupId>com.iail</groupId> <artifactId>MDK</artifactId> <version>${mdk.version}</version> </dependency> <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> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>${velocity.version}</version> </dependency> </dependencies> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.boot.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>flatten-maven-plugin</artifactId> <version>1.1.0</version> <executions> <execution> <id>flatten</id> <phase>process-resources</phase> <goals> <goal>flatten</goal> </goals> </execution> <execution> <id>flatten.clean</id> <phase>clean</phase> <goals> <goal>clean</goal> </goals> </execution> </executions> <configuration> <updatePomFile>true</updatePomFile> <flattenMode>resolveCiFriendliesOnly</flattenMode> </configuration> </plugin> </plugins> </build> </project> iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/ModelServiceApplication.java
@@ -1,10 +1,13 @@ package com.iailab; import iail.mdk.model.common.Environment; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableAsync; import java.io.File; import java.io.InputStream; import java.util.Properties; @EnableAsync @@ -15,13 +18,17 @@ //加载动态链接库 try { Properties properties = new Properties(); // InputStream in = ModelServiceApplication.class.getClassLoader().getResourceAsStream("iailmdk.properties"); // properties.load(in); // String mdkInitPath = properties.getProperty("mdk-init-path"); // System.out.println("mdkInitPath=" + mdkInitPath); // System.load(mdkInitPath + File.separator + "IAIL.MDK.Mid.Windows.dll"); // Environment env = new Environment(); // env.init(); InputStream in = ModelServiceApplication.class.getClassLoader().getResourceAsStream("iailmdk.properties"); properties.load(in); String mdkInitPath = properties.getProperty("mdk-init-path"); System.out.println("mdkInitPath=" + mdkInitPath); File file = new File(mdkInitPath + File.separator + "IAIL.MDK.Mid.Windows.dll"); if (!file.exists()) { throw new RuntimeException("动态链接库IAIL.MDK.Mid.Windows.dll文件不存在," + file.getAbsolutePath()); } System.load(file.getAbsolutePath()); Environment env = new Environment(); env.init(); } catch (Exception e) { e.printStackTrace(); System.out.println("动态链接库IAIL.MDK.Mid.Windows.dll初始化失败"); iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java
@@ -40,7 +40,7 @@ resultMap.put(itemOutPutList.get(0).getId(), predictResult.getPredictList()); return resultMap; } ApiPointDTO point = dataPointApi.getPointById(itemOutPutList.get(0).getPointId()); ApiPointDTO point = dataPointApi.getInfoById(itemOutPutList.get(0).getPointId()); List<Date> dateTimeList = new ArrayList<>(); Integer rows = predictResult.getPredictMatrix().length; Integer columns = predictResult.getPredictMatrix()[0].length; iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java
@@ -67,7 +67,7 @@ Date endTime = predictTime; ItemVO itemEntity = itemEntityFactory.getItemByItemNo(itemNo); List<MmItemOutputVO> outPutList = itemEntityFactory.getOutPutByItemId(itemEntity.getId()); ApiPointDTO pointEntity = dataPointApi.getPointById(outPutList.get(0).getPointId()); ApiPointDTO pointEntity = dataPointApi.getInfoById(outPutList.get(0).getPointId()); Calendar calendar = Calendar.getInstance(); calendar.setTime(endTime); iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java
@@ -122,12 +122,12 @@ String paramType = columnItem.getParamType(); switch (paramType) { case "DATAPOINT": ApiPointDTO point = dataPointApi.getPointById(columnItem.getId()); ApiPointDTO point = dataPointApi.getInfoById(columnItem.getId()); ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); queryDto.setPointNo(point.getPointNo()); queryDto.setStart(columnItem.getStartTime()); queryDto.setEnd(columnItem.getEndTime()); List<ApiPointValueDTO> pointValueList = dataPointApi.getValue(queryDto); List<ApiPointValueDTO> pointValueList = dataPointApi.queryPointHistoryValue(queryDto); dataList = ConvertUtils.sourceToTarget(pointValueList, DataValueVO.class); break; case "PREDICTITEM": iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java
@@ -8,9 +8,7 @@ import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; import com.iailab.module.model.mdk.sample.dto.SampleInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -68,7 +66,7 @@ calendar.setTime(originalTime); switch (columnItem.getParamType()) { case "DATAPOINT": ApiPointDTO dataPoint = dataPointApi.getPointById(columnItem.getParamId()); ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); if (dataPoint == null) { return null; } @@ -103,7 +101,7 @@ calendar.setTime(originalTime); switch (columnItem.getParamType()) { case "DATAPOINT": ApiPointDTO dataPoint = dataPointApi.getPointById(columnItem.getParamId()); ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); if (dataPoint == null) { return null; } @@ -135,7 +133,7 @@ Integer granularity = 60; switch (columnItem.getParamType()) { case "DATAPOINT": ApiPointDTO dataPoint = dataPointApi.getPointById(columnItem.getParamId()); ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); granularity = DataPointFreq.getEumByCode(dataPoint.getMinfreqid()).getValue(); break; case "PREDICTITEM": iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java
对比新文件 @@ -0,0 +1,128 @@ package com.iailab.module.model.mpk.common.utils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import sun.misc.URLClassPath; import java.io.File; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.util.Iterator; import java.util.Vector; @Slf4j public class DllUtils { /** * @description: 加载dll到指定class下 * @author: dzd * @date: 2024/9/30 14:27 **/ public static void loadDll(Class<?> clazz, String dllPath) { try { Method method = Runtime.class.getDeclaredMethod("load0", Class.class,String.class); boolean accessible = method.isAccessible(); method.setAccessible(true); method.invoke(Runtime.getRuntime(), clazz,dllPath); method.setAccessible(accessible); log.info("成功加载dll:"+ dllPath); } catch (Exception e) { throw new RuntimeException("加载dll异常",e); } } /** * @description: 卸载classLoader下全部dll * @author: dzd * @date: 2024/9/30 14:31 **/ public static synchronized void uploadDll(URLClassLoader classLoader) { try { Field field = ClassLoader.class.getDeclaredField("nativeLibraries"); field.setAccessible(true); Vector<Object> libs = (Vector<Object>) field.get(classLoader); Iterator<Object> it = libs.iterator(); Object o; while (it.hasNext()) { o = it.next(); Method method = o.getClass().getDeclaredMethod("finalize"); boolean accessible = method.isAccessible(); method.setAccessible(true); method.invoke(o); method.setAccessible(accessible); Field nameDield = o.getClass().getDeclaredField("name"); nameDield.setAccessible(true); String name = (String) nameDield.get(o); log.info("成功卸载dll:" + name); } } catch (Exception e) { throw new RuntimeException("卸载dll异常",e); } } /** * @description: 从classLoader中卸载dll,如果dllName传null,则默认删除全部dll * @author: dzd * @date: 2024/9/30 14:52 **/ public static synchronized void uploadDllName(URLClassLoader classLoader,String dllName) { try { Field field = ClassLoader.class.getDeclaredField("nativeLibraries"); field.setAccessible(true); Vector<Object> libs = (Vector<Object>) field.get(classLoader); Iterator<Object> it = libs.iterator(); Object o; while (it.hasNext()) { o = it.next(); Field nameDield = o.getClass().getDeclaredField("name"); nameDield.setAccessible(true); String name = (String) nameDield.get(o); // dllName不为null 并且 不等于name,跳出(dllName为null默认全部删除) if (StringUtils.isNotEmpty(dllName) && !dllName.equals(name)) { return; } Method method = o.getClass().getDeclaredMethod("finalize"); boolean accessible = method.isAccessible(); method.setAccessible(true); method.invoke(o); method.setAccessible(accessible); log.info("成功卸载dll:" + name); } } catch (Exception e) { throw new RuntimeException("卸载dll异常",e); } } /** * @description: 加载jar到特定的URLClassLoader,并返回URLClassLoader * @author: dzd * @date: 2024/9/30 14:20 **/ public static synchronized URLClassLoader loadJar(String jarPath) { File jarFile = new File(jarPath); if (!jarFile.exists()) { throw new RuntimeException("jar沒有找到!"); } else { try { URLClassLoader urlClassLoader = new URLClassLoader(new URL[]{jarFile.toURI().toURL()}); log.info("成功加载jar包:"+ jarFile.getAbsolutePath()); return urlClassLoader; } catch (Exception e) { throw new RuntimeException("加载jar异常",e); } } } public static synchronized void uploadJar(URLClassLoader urlClassLoader) { try { urlClassLoader.close(); log.info("成功卸载jar包。"); } catch (Exception e) { throw new RuntimeException("卸载jar异常",e); } } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/GenUtils.java
@@ -59,7 +59,7 @@ FileUtil.writeUtf8String(writer.toString(),toFile); IOUtils.closeQuietly(writer); } catch (IOException e) { throw new RuntimeException("模板渲染异常"); throw new RuntimeException("模板渲染异常",e); } } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/Readtxt.java
@@ -110,32 +110,36 @@ } 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(); List<double[][]> datas; try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) { //获取工作薄里面sheet的个数 int sheetNum = workbook.getNumberOfSheets(); 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; } doubles2[j] = doubles1; datas.add(doubles2); } datas.add(doubles2); } catch (Exception e) { throw new RuntimeException("解析Excel异常",e); } return datas; iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MdkController.java
@@ -5,17 +5,17 @@ import com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.module.model.mpk.common.MdkConstant; import com.iailab.module.model.mpk.common.utils.DllUtils; import com.iailab.module.model.mpk.common.utils.Readtxt; import com.iailab.module.model.mpk.dto.MdkDTO; import io.swagger.v3.oas.annotations.Operation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.HashMap; @@ -30,6 +30,7 @@ * @createTime 2024年08月08日 */ @RestController @Slf4j @RequestMapping("/model/mpk/api") public class MdkController { @Value("${mpk.bak-file-path}") @@ -38,7 +39,8 @@ @PostMapping("run") public CommonResult<String> run(@RequestBody MdkDTO dto) { Class<?> clazz; URLClassLoader classLoader; try { File jarFile = new File(mpkBakFilePath + File.separator + MdkConstant.JAR + File.separator + dto.getPyName() + ".jar"); if (!jarFile.exists()) { @@ -46,13 +48,16 @@ } File dllFile = new File(mpkBakFilePath + File.separator + MdkConstant.DLL + File.separator + dto.getPyName() + ".dll"); if (!dllFile.exists()) { throw new RuntimeException("dllw文件不存在,请先生成代码。dllPath:" + dllFile.getAbsolutePath()); throw new RuntimeException("dll文件不存在,请先生成代码。dllPath:" + dllFile.getAbsolutePath()); } // 加载jar包 loadJar(jarFile.getAbsolutePath()); // 加载dll System.load(dllFile.getAbsolutePath()); classLoader = DllUtils.loadJar(jarFile.getAbsolutePath()); // 实现类 clazz = classLoader.loadClass(dto.getClassName()); // 加载dll到实现类 DllUtils.loadDll(clazz,dllFile.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("加载运行环境失败。"); } @@ -92,14 +97,16 @@ 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); HashMap result = (HashMap) clazz.getDeclaredMethod(dto.getMethodName(), paramsArray).invoke(clazz.newInstance(), paramsValueArray); return success(JSON.toJSONString(result)); } catch (Exception ex) { ex.printStackTrace(); return error(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"运行异常"); } finally { if (classLoader != null) { DllUtils.uploadDll(classLoader); DllUtils.uploadJar(classLoader); } System.gc(); } } @@ -117,20 +124,5 @@ } } return success(result); } private void loadJar(String jarPath) throws Exception { File jarFile = new File(jarPath); if (!jarFile.exists()) { throw new Exception("jar沒有找到!"); } else { Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); boolean accessible = method.isAccessible(); method.setAccessible(true); URLClassLoader classLoader = (URLClassLoader)ClassLoader.getSystemClassLoader(); URL url = jarFile.toURI().toURL(); method.invoke(classLoader, url); method.setAccessible(accessible); } } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MpkFileController.java
@@ -102,7 +102,7 @@ IOUtils.write(data, response.getOutputStream()); } catch (Exception e) { throw new RuntimeException("代码生成异常"); throw new RuntimeException("代码生成异常",e); } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java
@@ -36,6 +36,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.*; import java.nio.file.Files; import java.util.*; import java.util.stream.Collectors; @@ -123,6 +124,8 @@ public void save(MpkFileDTO dto) { MpkFileEntity entity = ConvertUtils.sourceToTarget(dto, MpkFileEntity.class); entity.setId(UUID.randomUUID().toString()); entity.setPkgName(dto.getPkgName().trim()); entity.setFilePath(dto.getFilePath().trim()); entity.setCreator(SecurityFrameworkUtils.getLoginUserId()); entity.setCreateDate(new Date()); insert(entity); @@ -189,9 +192,13 @@ VelocityContext dataContext = new VelocityContext(map); //临时文件夹 File dirPath = new File("D:/DLUT/tmp/"); dirPath.deleteOnExit(); dirPath.mkdirs(); File dirPath = null; try { dirPath = Files.createTempDirectory("generatorCodeTmp").toFile(); log.info("生成临时文件夹," + dirPath.getAbsolutePath()); } catch (IOException e) { throw new RuntimeException("创建临时文件夹异常",e); } List<String> javaFilePaths = new ArrayList<>(); List<String> cppFilePaths = new ArrayList<>(); @@ -273,7 +280,7 @@ try { FileUtils.deleteDirectory(dirPath); } catch (IOException e) { throw new RuntimeException("删除临时文件异常"); throw new RuntimeException("删除临时文件异常",e); } return bytes; } @@ -289,9 +296,13 @@ // VelocityContext context = new VelocityContext(map); //临时文件夹 File dirPath = new File("D:/DLUT/tmp/"); dirPath.deleteOnExit(); dirPath.mkdirs(); File dirPath = null; try { dirPath = Files.createTempDirectory("packageModelTmp").toFile(); log.info("生成临时文件夹," + dirPath.getAbsolutePath()); } catch (IOException e) { throw new RuntimeException("创建临时文件夹异常",e); } //设置velocity资源加载器 Properties prop = new Properties(); @@ -434,7 +445,7 @@ // 等待命令执行完成 process.waitFor(); } catch (Exception e) { throw new RuntimeException("执行cmd命令生成dll异常"); throw new RuntimeException("执行cmd命令生成dll异常",e); } } @@ -492,7 +503,7 @@ process.waitFor(); return jarSavePath; } catch (InterruptedException e) { throw new RuntimeException("执行cmd命令打jar包异常"); throw new RuntimeException("执行cmd命令打jar包异常",e); } } @@ -513,7 +524,7 @@ Process process = RuntimeUtil.exec(sb.toString()); process.waitFor(); } catch (InterruptedException e) { throw new RuntimeException("执行cmd命令生成class异常"); throw new RuntimeException("执行cmd命令生成class异常",e); } } } iailab-module-model/iailab-module-model-biz/src/main/resources/application-test.yml
对比新文件 @@ -0,0 +1,53 @@ spring: autoconfigure: exclude: - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure datasource: druid: web-stat-filter: enabled: true stat-view-servlet: enabled: true allow: url-pattern: /druid/* login-username: login-password: filter: stat: enabled: true log-slow-sql: true slow-sql-millis: 100 merge-sql: true wall: config: multi-statement-allow: true dynamic: druid: initial-size: 1 min-idle: 1 max-active: 20 max-wait: 600000 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000 max-evictable-idle-time-millis: 900000 validation-query: SELECT 1 FROM DUAL test-while-idle: true test-on-borrow: false test-on-return: false primary: master datasource: master: #url: jdbc:mysql://127.0.0.1:3306/iailab_expert_tenant_zjgt?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true url: jdbc:mysql://172.16.8.100:3306/iailab_expert_master?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true username: root password: 123456 redis: host: 172.16.8.100 port: 6379 database: 0 password: 123456 mpk: bakFilePath: D:\DLUT\mpkBakFile model-file-path: D:\DLUT\MDK\Model\miail\ iailab-module-model/iailab-module-model-biz/src/main/resources/bak/IAILMDK/common/Environment.java
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/IAILMDK/utils/AlgsUtils.java
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/libs/IAIL.MDK.Mid.Windows.dllBinary files differ
iailab-module-model/iailab-module-model-biz/src/main/resources/bak/libs/status_code.xml
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/resources/bak/libs/version.xml
文件已删除 logs/log-debug.2024-09-30.log
对比新文件 文件太大