|
@@ -0,0 +1,309 @@
|
|
|
+package com.onemap.overlap.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.onemap.common.core.utils.StringUtils;
|
|
|
+import com.onemap.common.core.web.domain.RequestResult;
|
|
|
+import com.onemap.common.security.utils.SecurityUtils;
|
|
|
+import com.onemap.overlap.service.DataService;
|
|
|
+import com.onemap.overlap.utils.CustomUtils;
|
|
|
+import com.onemap.overlap.utils.ShpToSpatiaLite;
|
|
|
+import com.onemap.overlap.utils.SpatialiteUtils;
|
|
|
+import com.onemap.overlap.utils.UnPackageUtils;
|
|
|
+import org.apache.poi.xwpf.usermodel.BreakType;
|
|
|
+import org.json.simple.JSONArray;
|
|
|
+import org.json.simple.JSONObject;
|
|
|
+import org.json.simple.parser.JSONParser;
|
|
|
+import org.json.simple.parser.ParseException;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.Statement;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class DataImp implements DataService {
|
|
|
+ @Value("${file.temp}")
|
|
|
+ String localFilePath;
|
|
|
+ @Value("${file.wkid}")
|
|
|
+ Integer shpWkid;
|
|
|
+ @Value("${spatialite.filepath}")
|
|
|
+ String dbpath;
|
|
|
+ @Value("${file.prefix}")
|
|
|
+ String prefix;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestResult importIn(MultipartFile file, String path, String type, String name) {
|
|
|
+ if (file == null && path == null) {
|
|
|
+ return RequestResult.error("参数未传递", null);
|
|
|
+ }
|
|
|
+ String currentTime = CustomUtils.getCurrentTime();
|
|
|
+ String currentPath = localFilePath + "/" + currentTime + "/";
|
|
|
+ String username = SecurityUtils.getUsername();
|
|
|
+ if (StringUtils.isEmpty(username)) {
|
|
|
+ username = "admin";
|
|
|
+ }
|
|
|
+ String shpPath = path;
|
|
|
+ if (StringUtils.isEmpty(shpPath)) {
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ String filetype = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
+ String filename = fileName.replace(filetype, "").replace(".", "");
|
|
|
+ if (!filetype.equals("zip") && !filetype.equals("rar")) {
|
|
|
+ return RequestResult.error("请上传zip/rar压缩包文件", null);
|
|
|
+ }
|
|
|
+ String filepath = currentPath + "" + fileName;
|
|
|
+ File dest = new File(filepath);
|
|
|
+ File dir = dest.getParentFile();
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ String unzippath = currentPath;
|
|
|
+ try {
|
|
|
+ //上传文件
|
|
|
+ file.transferTo(dest);
|
|
|
+ //解压zip格式
|
|
|
+ if (filetype.equals("zip")) {
|
|
|
+ new UnPackageUtils().unPackZip(dest, unzippath);
|
|
|
+ } else {
|
|
|
+ //解压rar格式
|
|
|
+ new UnPackageUtils().unPackRar(dest, unzippath);
|
|
|
+ }
|
|
|
+ File[] files = new File(unzippath).listFiles();
|
|
|
+ for (File file1 : files) {
|
|
|
+ if (file1.getAbsolutePath().substring(file1.getAbsolutePath().lastIndexOf(".") + 1).equals("shp")) {
|
|
|
+ shpPath = file1.getAbsolutePath();
|
|
|
+ shpPath = shpPath.replaceAll("\\\\", "/");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!"".equals(shpPath)) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ return RequestResult.error("未检索到shp文件");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RequestResult.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String tablename = "";
|
|
|
+ String folderpath = "";
|
|
|
+ if (StringUtils.isEmpty(shpPath)) {
|
|
|
+ return RequestResult.error("未检索到shp文件!");
|
|
|
+ } else {
|
|
|
+ // 创建File对象
|
|
|
+ File currentfile = new File(shpPath);
|
|
|
+ // 获取文件名
|
|
|
+ String fileName = currentfile.getName();
|
|
|
+ folderpath = currentfile.getParentFile().getAbsolutePath();
|
|
|
+ String filetype = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
+ String filename = fileName.replace(filetype, "").replace(".", "");
|
|
|
+ tablename = prefix + filename + "_" + currentTime;
|
|
|
+ try {
|
|
|
+ Boolean bool = ShpToSpatiaLite.ImportShpToSpatialite(dbpath, shpPath, shpWkid, tablename);
|
|
|
+ if (!bool) {
|
|
|
+ return RequestResult.error("shp数据入库失败!");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ //注册数据到属性表
|
|
|
+ String insertSQL = "";
|
|
|
+ if ("base".equals(type)) {//管控数据
|
|
|
+ insertSQL = "insert into t_base_vector (layername , tablename) values ('" + name + "', '" + tablename + "')";
|
|
|
+ } else if ("analyse".equals(type)) {//分析图斑
|
|
|
+ insertSQL = "insert into t_analyse_vector (layername , tablename, path) values ('" + name + "', '" + tablename + "', '" + folderpath + "')";
|
|
|
+ }
|
|
|
+ statement.execute(insertSQL);
|
|
|
+ connection.close();
|
|
|
+ } catch (Exception w) {
|
|
|
+ w.printStackTrace();
|
|
|
+ }
|
|
|
+ return RequestResult.success("上传成功", tablename);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestResult modellist() {
|
|
|
+ try {
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ String querySQL = "select distinct(modelname) from t_model";
|
|
|
+ ResultSet resultSet = statement.executeQuery(querySQL);
|
|
|
+ List<String> res = new ArrayList<String>();
|
|
|
+ while (resultSet.next()) {
|
|
|
+ String name = resultSet.getString("modelname");
|
|
|
+ res.add(name);
|
|
|
+ }
|
|
|
+ connection.close();
|
|
|
+ return RequestResult.success("查询成功!", res);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return RequestResult.error("查询失败!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询模型详情
|
|
|
+ *
|
|
|
+ * @param modelname
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public RequestResult modeldetails(String modelname) {
|
|
|
+ try {
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ String querySQL = "select layername,type,isvalid from t_model where modelname = '" + modelname + "'";
|
|
|
+ ResultSet resultSet = statement.executeQuery(querySQL);
|
|
|
+ List<Map> res = new ArrayList<Map>();
|
|
|
+ while (resultSet.next()) {
|
|
|
+ Map cur = new HashMap();
|
|
|
+ cur.put("layername", resultSet.getString("layername"));
|
|
|
+ cur.put("type", resultSet.getString("type"));
|
|
|
+ cur.put("isvalid", resultSet.getString("isvalid"));
|
|
|
+ res.add(cur);
|
|
|
+ }
|
|
|
+ connection.close();
|
|
|
+ return RequestResult.success("查询成功!", res);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return RequestResult.error("查询失败!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询模型详情
|
|
|
+ *
|
|
|
+ * @param modelname
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public RequestResult modeldelete(String modelname) {
|
|
|
+ try {
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ String querySQL = "delete from t_model where modelname = '" + modelname + "'";
|
|
|
+ statement.execute(querySQL);
|
|
|
+ connection.close();
|
|
|
+ return RequestResult.success("删除成功!", 1);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return RequestResult.error("删除失败!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestResult modelupdate(HttpServletRequest request) {
|
|
|
+ try {
|
|
|
+ JSONObject parameters = (JSONObject) new JSONParser().parse(request.getReader());
|
|
|
+ String modelname = (String) parameters.get("modelname");
|
|
|
+ JSONArray details = (JSONArray) parameters.get("details");
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ String deleteSQL = "delete from t_model where modelname = '" + modelname + "'";
|
|
|
+ statement.execute(deleteSQL);
|
|
|
+ for(int i = 0 ; i < details.size() ; i ++){
|
|
|
+ JSONObject curObj = (JSONObject) details.get(i);
|
|
|
+ String layername = (String) curObj.get("layername");
|
|
|
+ String isvalid = (String) curObj.get("isvalid");
|
|
|
+ String type = (String) curObj.get("type");
|
|
|
+ String insertSQL = "insert into t_model (layername , type, \"index\" , isvalid, modelname) values ('" + layername + "' , '" + type + "', " + i + " , '" + isvalid + "', '" + modelname + "')";
|
|
|
+ statement.execute(insertSQL);
|
|
|
+ }
|
|
|
+ connection.close();
|
|
|
+ return RequestResult.success("修改成功!", 1);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return RequestResult.error("失败!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestResult basevectordelete(String tablename) {
|
|
|
+ try {
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ //删除主表
|
|
|
+ String deleteSQL = "delete from t_base_vector where tablename = '" + tablename + "'";
|
|
|
+ statement.execute(deleteSQL);
|
|
|
+ //删除模型分析因子项
|
|
|
+ deleteSQL = "delete from t_model where layername = (select layername from t_base_vector where tablename = '" + tablename + "')";
|
|
|
+ statement.execute(deleteSQL);
|
|
|
+ //删除矢量表
|
|
|
+ deleteSQL = "drop table " + tablename + "";
|
|
|
+ statement.execute(deleteSQL);
|
|
|
+// deleteSQL = "drop table idx_" + tablename + "_geom";
|
|
|
+// statement.execute(deleteSQL);
|
|
|
+ deleteSQL = "delete from geometry_columns where f_table_name = '" + tablename + "'";
|
|
|
+ statement.execute(deleteSQL);
|
|
|
+ connection.close();
|
|
|
+ return RequestResult.success("删除成功!", 1);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return RequestResult.error("失败!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestResult basevector() {
|
|
|
+ try {
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ String querySQL = "select * from t_base_vector";
|
|
|
+ ResultSet resultSet = statement.executeQuery(querySQL);
|
|
|
+ List<Map> res = new ArrayList<Map>();
|
|
|
+ while (resultSet.next()) {
|
|
|
+ Map cur = new HashMap();
|
|
|
+ cur.put("id", resultSet.getString("id"));
|
|
|
+ cur.put("layername", resultSet.getString("layername"));
|
|
|
+ cur.put("tablename", resultSet.getString("tablename"));
|
|
|
+ cur.put("serviceuri", resultSet.getString("serviceuri"));
|
|
|
+ cur.put("servicetype", resultSet.getString("servicetype"));
|
|
|
+ res.add(cur);
|
|
|
+ }
|
|
|
+ connection.close();
|
|
|
+ return RequestResult.success("查询成功!", res);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return RequestResult.error("查询失败!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestResult analysevector() {
|
|
|
+ try {
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ String querySQL = "select * from t_analyse_vector order by inserttime desc";
|
|
|
+ ResultSet resultSet = statement.executeQuery(querySQL);
|
|
|
+ List<Map> res = new ArrayList<Map>();
|
|
|
+ while (resultSet.next()) {
|
|
|
+ Map cur = new HashMap();
|
|
|
+ cur.put("id", resultSet.getString("id"));
|
|
|
+ cur.put("layername", resultSet.getString("layername"));
|
|
|
+ cur.put("tablename", resultSet.getString("tablename"));
|
|
|
+ cur.put("inserttime", resultSet.getString("inserttime"));
|
|
|
+ res.add(cur);
|
|
|
+ }
|
|
|
+ connection.close();
|
|
|
+ return RequestResult.success("查询成功!", res);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return RequestResult.error("查询失败!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|