高级算法修改

This commit is contained in:
2023-07-26 15:31:32 +08:00
parent f4b5786236
commit d2a0f3ff85
2 changed files with 7 additions and 60 deletions

View File

@@ -1,5 +1,6 @@
package com.njcn.advance.utils; package com.njcn.advance.utils;
import cn.hutool.core.date.TimeInterval;
import com.njcn.advance.pojo.bo.QtIdxArray; import com.njcn.advance.pojo.bo.QtIdxArray;
import com.njcn.advance.pojo.bo.QvvrDataStruct; import com.njcn.advance.pojo.bo.QvvrDataStruct;
import com.njcn.advance.pojo.dto.BalanceInfo; import com.njcn.advance.pojo.dto.BalanceInfo;
@@ -43,18 +44,15 @@ public class GetBalanceUtils {
// 如果newList为空则不带入dll计算 // 如果newList为空则不带入dll计算
if (newList.size() > 0) { if (newList.size() > 0) {
packageData(newList, qvvrDataStruct); packageData(newList, qvvrDataStruct);
JnaCallDllOrSo jnaCallDll = new JnaCallBalance("qvvr_balance.dll"); JnaCallDllOrSo jnaCallDll = new JnaCallBalance("qvvr_balance");
System.out.println("路径>>>>>>>"+jnaCallDll.getStrpath()); System.out.println("路径>>>>>>>"+jnaCallDll.getStrpath());
jnaCallDll.setPath(); jnaCallDll.setPath();
System.out.println("路径++++"+jnaCallDll.getStrpath());
// 计算暂降综合评估 // 计算暂降综合评估
try { try {
JnaCallBalance.Balancelibrary INSTANTCE = JnaCallBalance.Balancelibrary.INSTANTCE; JnaCallBalance.Balancelibrary INSTANTCE = JnaCallBalance.Balancelibrary.INSTANTCE;
TimeInterval timeInterval = new TimeInterval();
INSTANTCE.qvvr_fun_cause(qvvrDataStruct); INSTANTCE.qvvr_fun_cause(qvvrDataStruct);
System.out.println("dll算法时长:+++++++++++"+timeInterval);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return; return;

View File

@@ -16,24 +16,23 @@ public class JnaCallDllOrSo {
private String path = ""; private String path = "";
private String pathDll = ""; private String pathDll = "";
private String nameDll; private String nameDll;
public static String jarPath = ""; public static String jarPath = "";
public JnaCallDllOrSo(String name) { public JnaCallDllOrSo(String name) {
super(); super();
this.nameDll = name;
try { try {
// 获取当前操作系统的类型
String os = System.getProperty("os.name"); String os = System.getProperty("os.name");
// windows操作系统为1 否则为0 // windows操作系统为1 否则为0
int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0; int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0;
if(beginIndex == 0){ if(beginIndex == 0){
//linux操作系统 //linux操作系统
this.nameDll = name+".os";
this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8"); this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8");
}else { }else {
this.nameDll = name+".dll";
this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replaceFirst("/", ""), "UTF-8"); this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replaceFirst("/", ""), "UTF-8");
} }
System.out.println("初始化路径************"+this.path);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
log.error(e.getMessage()); log.error(e.getMessage());
@@ -43,59 +42,9 @@ public class JnaCallDllOrSo {
} }
} }
public String packagePath(String path) {
return path + "/" + this.nameDll;
}
public boolean judgeFileType() { //判断打包方式是否为jar方式
String pathPackage = this.getClass().getPackage().toString().replaceAll("package ", "/");
pathPackage = pathPackage.replace('.', '/');
this.pathDll = packagePath(path + pathPackage);
this.pathDll = path + pathPackage + "/" + this.nameDll;
//如果dll在jar包内部返回true否则返回true
return path.endsWith(".jar");
}
public boolean exitFile() {//判断dll文件是否存在
File file = new File(packagePath(JnaCallDllOrSo.jarPath));
return file.exists() || file.isFile();
}
public void copyDll2Path() {//复制jar包中的dll到指定位置
InputStream is = this.getClass().getResourceAsStream(nameDll);
File file = new File(packagePath(JnaCallDllOrSo.jarPath));
byte[] bytes = new byte[1024];
int readBytes;
try {
OutputStream os = new FileOutputStream(file);
while ((readBytes = is.read(bytes)) != -1) {
os.write(bytes, 0, readBytes);
}
os.close();
} catch (FileNotFoundException e) {
log.error(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
} finally {
try {
is.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
}
public String getStrpath() { public String getStrpath() {
/* if (judgeFileType()) {
if (!exitFile()) {
copyDll2Path();
}
return packagePath(JnaCallDllOrSo.jarPath);
} else {
return this.pathDll;
}*/
String aa = this.path+this.nameDll; String aa = this.path+this.nameDll;
String bb= aa.replace("/", File.separator); String bb= aa.replace("/", File.separator);
return bb; return bb;