燕山石化溯源三维电子沙盘-【后端】-服务
13693261870
2023-07-14 db44f336e46825afc855466512065cc08e5790bd
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
164
165
166
package com.yssh.service;
 
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import com.yssh.config.DatFilePathConfig;
import com.yssh.entity.MonitorPointPosition;
import com.yssh.utils.CalculateUtils;
import com.yssh.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
 
import com.yssh.mapper.CommonMapper;
 
import javax.annotation.Resource;
 
@Service
public class CommonService {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
 
    private static final String TABLE_SCHEMA = "yssh";
 
    private List<MonitorPointPosition> checkPoints2d = new ArrayList<>();
 
    private List<MonitorPointPosition> checkPoints3d = new ArrayList<>();
 
    @Resource
    private CommonMapper commonMapper;
 
    @Resource
    protected DatFilePathConfig datFilePathConfig;
 
    /**
     * 检查表是否存在
     */
    public boolean checkTableExists(String tableName) {
        try {
            Integer count = commonMapper.checkTableExistsWithSchema(TABLE_SCHEMA, tableName);
            return count == 1;
        } catch (Exception e) {
            logger.error("使用information_schema检测表失败", e);
            Map<String, String> list = commonMapper.checkTableExistsWithShow(tableName);
            if (StringUtils.isNotEmpty(list)) {
                return true;
            }
        }
        return false;
    }
 
    public void readDatData() throws Exception {
        File file2d = new File(datFilePathConfig.getFilePath2d());
        BufferedInputStream fis2d = new BufferedInputStream(new FileInputStream(file2d));
        BufferedReader reader2d = new BufferedReader(new InputStreamReader(fis2d, "utf-8"), 7 * 1024 * 1024);// 用7M的缓冲读取文本文件
        long count2d = 1;
        String line2d = "";
        while ((line2d = reader2d.readLine()) != null) {
            String[] f2d = line2d.split(" ");
            Integer x = Integer.parseInt(f2d[0]);
            Integer y = Integer.parseInt(f2d[1]);
            int z = 0;
            try {
                z = new Double(Math.round(Integer.parseInt(f2d[2]) * 1.0 / 10)).intValue();
            } catch (Exception e) {
                System.out.println(e.getStackTrace());
            }
            //if (x <= 699 && y <= 699)
            {
                MonitorPointPosition monitorPointPosition = new MonitorPointPosition();
                monitorPointPosition.setId(x + "_" + y + "_" + z);
                monitorPointPosition.setName("AI-" + (count2d < 10 ? "0" + count2d : count2d + ""));
                monitorPointPosition.setX(x);
                monitorPointPosition.setY(y);
                monitorPointPosition.setZ(z);
                monitorPointPosition.setLon(CalculateUtils.getLon(monitorPointPosition.getX(), monitorPointPosition.getY()));
                monitorPointPosition.setLat(CalculateUtils.getLat(monitorPointPosition.getX(), monitorPointPosition.getY()));
                checkPoints2d.add(monitorPointPosition);
                count2d++;
            }
        }
        reader2d.close();
 
        File file = new File(datFilePathConfig.getFilePath3d());
        BufferedInputStream fis = new BufferedInputStream(new FileInputStream(file));
        BufferedReader reader = new BufferedReader(new InputStreamReader(fis, "utf-8"), 7 * 1024 * 1024);// 用7M的缓冲读取文本文件
        long count3d = 1;
        String line = "";
        while ((line = reader.readLine()) != null) {
            String[] f3d = line.split(" ");
            Integer x = Integer.parseInt(f3d[0]);
            Integer y = Integer.parseInt(f3d[1]);
            int z = 0;
            try {
                z = new Double(Math.round(Integer.parseInt(f3d[2]) * 1.0 / 10)).intValue();
            } catch (Exception e) {
                System.out.println(e.getStackTrace());
            }
            if (count3d > 46) break;
            { //if (x <= 699 && y <= 699) {
                MonitorPointPosition monitorPointPosition = new MonitorPointPosition();
                monitorPointPosition.setId(x + "_" + y + "_" + z);
                monitorPointPosition.setName("AI-" + (count3d < 10 ? "0" + count3d : count3d + ""));
                monitorPointPosition.setX(x);
                monitorPointPosition.setY(y);
                monitorPointPosition.setZ(z);
                monitorPointPosition.setLon(CalculateUtils.getLon(monitorPointPosition.getX(), monitorPointPosition.getY()));
                monitorPointPosition.setLat(CalculateUtils.getLat(monitorPointPosition.getX(), monitorPointPosition.getY()));
                checkPoints3d.add(monitorPointPosition);
                count3d++;
            }
        }
        reader.close();
    }
 
    public List<MonitorPointPosition> getCheckPoints2d() {
        return checkPoints2d;
    }
 
    public List<MonitorPointPosition> getCheckPoints3d() {
        return checkPoints3d;
    }
 
    public MonitorPointPosition select2dCheckPointByName(String name) {
        for (MonitorPointPosition monitorPointPosition : checkPoints2d) {
            if (monitorPointPosition.getName().equals(name)) {
                return monitorPointPosition;
            }
        }
        return null;
    }
 
    public MonitorPointPosition select3dCheckPointByName(String name) {
        for (MonitorPointPosition monitorPointPosition : checkPoints3d) {
            if (monitorPointPosition.getName().equals(name)) {
                return monitorPointPosition;
            }
        }
        return null;
    }
 
    public MonitorPointPosition select2dCheckPointById(String id) {
        for (MonitorPointPosition monitorPointPosition : checkPoints2d) {
            if (monitorPointPosition.getName().equals(id)) {
                return monitorPointPosition;
            }
        }
        return null;
    }
 
    public MonitorPointPosition select3dCheckPointById(String id) {
        for (MonitorPointPosition monitorPointPosition : checkPoints3d) {
            //if (monitorPointPosition.getId().equals(id)) {
            String subId = id.substring(0, id.lastIndexOf("_") + 1);
            if (monitorPointPosition.getId().contains(subId)) {
                return monitorPointPosition;
            }
        }
        return null;
    }
}