package com.sandu.ximon.admin.newnova.utils;
|
|
import com.sandu.ximon.admin.newnova.conf.FilePathConfig;
|
import com.sandu.ximon.admin.newnova.vo.StatusVO;
|
import com.sandu.ximon.admin.utils.CountDownLatchUtil;
|
import com.sun.jna.Native;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Component;
|
|
import java.util.LinkedHashMap;
|
import java.util.Map;
|
|
/**
|
* @author LiuHaoNan
|
* @date 2022/11/9
|
*/
|
@Component
|
@AllArgsConstructor
|
public class NovaAPIUtil {
|
|
|
// @Value("${new-nova.string-path}")
|
// public String getStringPath() {
|
// return stringPath;
|
// }
|
|
private final FilePathConfig filePathConfig;
|
private final CountDownLatchUtil countDownLatchUtil;
|
private static Boolean g_bAPIReturn = false;
|
private static int g_code = 0;
|
private static String g_sn = "BZSA79353N1310006847"; //BZSA07313J0350000997
|
|
private static Map loginInfo = new LinkedHashMap();
|
|
|
|
// private static ViplexCore.CallBack callBack = new ViplexCore.CallBack() {
|
//
|
// @Override
|
// public void dataCallBack(int code, String data) {
|
// // TODO Auto-generated method stub
|
// g_code = code;
|
// String strCode = "\nViplexCore Demo code:" + code;
|
// String strData = "\nViplexCore Demo data:" + data;
|
// System.out.println(strCode);
|
// System.out.println(strData);
|
// g_bAPIReturn = true;
|
// }
|
//
|
// };
|
|
|
static void waitAPIReturn() throws InterruptedException {
|
while (!g_bAPIReturn) {
|
Thread.sleep(1000);
|
}
|
g_bAPIReturn = false;
|
}
|
|
|
/**
|
* 登录
|
*/
|
public StatusVO login(String sn) {
|
|
ViplexCore instance = (ViplexCore) Native.loadLibrary(filePathConfig.getStringPath(), ViplexCore.class);
|
String rootDir = System.getProperty("user.dir") + "/temp";
|
String companyInfo = "{\"company\":\"NovaStar\",\"phone\":\"029-68216000\",\"email\":\"hr@novastar.tech\"}";
|
instance.nvSetDevLang("Java");
|
System.out.println("nvInit(sdk 初始化):");
|
System.out.println(instance.nvInit(rootDir, companyInfo));
|
ViplexCore.CallBack callBack = new ViplexCore.CallBack() {
|
|
@Override
|
public void dataCallBack(int code, String data) {
|
// TODO Auto-generated method stub
|
g_code = code;
|
String strCode = "\nViplexCore Demo code:" + code;
|
String strData = "\nViplexCore Demo data:" + data;
|
System.out.println(strCode);
|
System.out.println(strData);
|
g_bAPIReturn = true;
|
}
|
|
};
|
|
|
System.out.println("ViplexCore Demo nvSearchTerminalAsync(搜索) begin... ");
|
StatusVO statusVO = new StatusVO();
|
instance.nvSearchTerminalAsync(callBack);
|
// countDownLatchUtil.push();
|
// instance.nvSearchTerminalAsync(new ViplexCore.CallBack() {
|
//
|
// @Override
|
// public void dataCallBack(int code, String data) {
|
// // TODO Auto-generated method stub
|
// g_code = code;
|
// statusVO.setStatusCode(code);
|
// statusVO.setStatusData(data);
|
// System.out.println("\nViplexCore Demo code:" + code);
|
// System.out.println("\nViplexCore Demo data:" + data);
|
// g_bAPIReturn = true;
|
// }
|
//
|
// });
|
|
|
|
try {
|
Thread.sleep(3000);
|
} catch (InterruptedException e) {
|
throw new RuntimeException(e);
|
}
|
g_bAPIReturn = false;
|
|
|
System.out.println("ViplexCore Demo nvLoginAsync(登录) begin... ");
|
String loginParam = String.format("{\"sn\":\"" + sn + "\",\"ip\":\"\",\"username\":\"admin\",\"rememberPwd\":0,\"password\":\"1234567890\",\"loginType\":0}"
|
, g_sn);
|
instance.nvLoginAsync(loginParam, new ViplexCore.CallBack() {
|
|
@Override
|
public void dataCallBack(int code, String data) {
|
// TODO Auto-generated method stub
|
g_code = code;
|
statusVO.setStatusCode(code);
|
statusVO.setStatusData(data);
|
System.out.println("\nViplexCore Demo code:" + code);
|
System.out.println("\nViplexCore Demo data:" + data);
|
g_bAPIReturn = true;
|
}
|
|
});
|
try {
|
waitAPIReturn();
|
} catch (InterruptedException e) {
|
throw new RuntimeException(e);
|
}
|
if (g_code != 0) {
|
System.out.println("ViplexCore Demo nvLoginAsync(登录) 失败!");
|
System.out.println("错误码:" + g_code);
|
return statusVO;
|
}
|
//登陆成功之后存入map保存登录信息
|
loginInfo.put(sn, instance);
|
return statusVO;
|
}
|
|
/**
|
* 创建节目
|
*/
|
public int createPro(String sn) throws InterruptedException {
|
ViplexCore instance = (ViplexCore) loginInfo.get(sn);
|
|
System.out.println("ViplexCore Demo nvCreateProgramAsync(创建节目) begin... ");
|
// instance.nvCreateProgramAsync(createProgram, callBack);
|
waitAPIReturn();
|
|
return 1;
|
}
|
|
|
}
|