吉安感知网项目-后端
xiebin
2026-01-06 d207a86cdf1ab52ef8cb7cd83bad8fceab8038cf
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
package org.sxkj.common.utils;
 
import com.alibaba.fastjson.JSONObject;
 
import java.io.*;
import java.util.Random;
import java.util.stream.Collectors;
 
public class DockerExecSignExtractor {
    /**
     * 将db文件进行质检,获取sign
     * @param fileName
     * @param password
     * @return
     * @throws IOException
     * @throws InterruptedException
     */
    public static String executeAndGetSign(String fileName, String password) throws IOException, InterruptedException {
        // 定义目标文件路径
        String directoryPath = "/software/service/drone/server/sqlite/download/";
        String command = String.format(
            "docker exec -it base_dev_dotnet dotnet /software/service/drone/server/sqlite/LandCloudCGDBPreCheckTool/LandCloud.CGDBPreCheckTool.dll checkdb --file=%s%s --pwd=%s",
            directoryPath, fileName, password
        );
 
        // 执行命令
        ProcessBuilder processBuilder = new ProcessBuilder("bash", "-c", command);
        processBuilder.redirectErrorStream(true);
        Process process = processBuilder.start();
        int exitCode = process.waitFor();
        if (exitCode != 0) {
            throw new RuntimeException("命令执行错误: " + exitCode);
        }
 
        // 定义生成的 .sign 文件路径
        File signFile = new File(directoryPath + fileName + ".sign");
        if (!signFile.exists()) {
            throw new RuntimeException("没用找到签章文件: " + signFile.getAbsolutePath());
        }
 
        // 读取 .sign 文件并解析 JSON
        try (BufferedReader reader = new BufferedReader(new FileReader(signFile))) {
            StringBuilder content = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                content.append(line);
            }
            JSONObject jsonObject = JSONObject.parseObject(content.toString());
            return jsonObject.getString("sign");
        }
    }
 
    public static String test() throws FileNotFoundException {
        File signFile = new File("D:\\wayline\\task1838486031293353984.sign");
        if (!signFile.exists()) {
            throw new RuntimeException("没用找到签章文件: " + signFile.getAbsolutePath());
        }
 
        // 读取 .sign 文件并解析 JSON
        try (BufferedReader reader = new BufferedReader(new FileReader(signFile))) {
            StringBuilder content = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                content.append(line);
            }
            JSONObject jsonObject = JSONObject.parseObject(content.toString());
            return jsonObject.getString("sign");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}