2021与蓝度共同重构项目,服务端
liuhaonan
2022-11-10 6554fd4bf83e50d39fc75f1c4ac3fbf6675f1962
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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;
    }
 
 
}