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 checkPoints2d = new ArrayList<>(); private List 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 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 getCheckPoints2d() { return checkPoints2d; } public List 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; } }