燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-06-16 aa86cb57b09c5300db3c33d75d91d8b51a4b636f
src/main/java/com/yssh/service/impl/CommonServiceImpl.java
@@ -1,6 +1,5 @@
package com.yssh.service.impl;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
@@ -10,11 +9,8 @@
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yssh.config.CsvFilePathConfig;
@@ -25,114 +21,115 @@
import com.yssh.utils.CalculateUtils;
import com.yssh.utils.StringUtils;
import javax.annotation.Resource;
@Service
public class CommonServiceImpl implements ICommonService {
   protected final Log logger = LogFactory.getLog(this.getClass());
   protected final Logger logger = LoggerFactory.getLogger(this.getClass());
   private static final String TABLE_SCHEMA = "yssh";
   private List<MonitorPointPosition> checkPoints2d = new ArrayList<MonitorPointPosition>();
   private List<MonitorPointPosition> checkPoints3d = new ArrayList<MonitorPointPosition>();
   @Autowired
   private List<MonitorPointPosition> checkPoints2d = new ArrayList<>();
   private List<MonitorPointPosition> checkPoints3d = new ArrayList<>();
   @Resource
   private CommonMapper commonMapper;
   @Autowired
   @Resource
   protected DatFilePathConfig datFilePathConfig;
   @Autowired
   private CsvFilePathConfig csvFilePathConfig;
   /**
    * 检查表是否存在
    */
   @Override
   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;
         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;
   }
   @Override
   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;
      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();
            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)
         //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++;
            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();
      }
      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;
      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();
            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();
            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;
   }
   @Override
   public MonitorPointPosition select2dCheckPointByName(String name) {
      for (MonitorPointPosition monitorPointPosition : checkPoints2d) {
@@ -142,6 +139,7 @@
      }
      return null;
   }
   @Override
   public MonitorPointPosition select3dCheckPointByName(String name) {
      for (MonitorPointPosition monitorPointPosition : checkPoints3d) {
@@ -151,6 +149,7 @@
      }
      return null;
   }
   @Override
   public MonitorPointPosition select2dCheckPointById(String id) {
      for (MonitorPointPosition monitorPointPosition : checkPoints2d) {
@@ -160,10 +159,13 @@
      }
      return null;
   }
   @Override
   public MonitorPointPosition select3dCheckPointById(String id) {
      for (MonitorPointPosition monitorPointPosition : checkPoints3d) {
         if (monitorPointPosition.getId().equals(id)) {
         //if (monitorPointPosition.getId().equals(id)) {
         String subId = id.substring(0, id.lastIndexOf("_") + 1);
         if (monitorPointPosition.getId().contains(subId)) {
            return monitorPointPosition;
         }
      }