From fc98146d74aad6caf4ab95a5932b5a8a355a94a3 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 09 十月 2024 10:17:27 +0800 Subject: [PATCH] 1 --- src/main/java/com/se/simu/service/GedbService.java | 149 +++++++++++++++++++++++-------------------------- 1 files changed, 69 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/se/simu/service/GedbService.java b/src/main/java/com/se/simu/service/GedbService.java index 8910364..0222eea 100644 --- a/src/main/java/com/se/simu/service/GedbService.java +++ b/src/main/java/com/se/simu/service/GedbService.java @@ -4,6 +4,7 @@ import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.se.simu.config.PropertiesConfig; import com.se.simu.domain.dto.GeDb; import com.se.simu.domain.dto.GeField; import com.se.simu.domain.dto.GeFile; @@ -17,7 +18,7 @@ import org.gdal.gdal.WarpOptions; import org.gdal.gdal.gdal; import org.gdal.gdalconst.gdalconst; -import org.springframework.beans.factory.annotation.Value; +import org.gdal.osr.SpatialReference; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; @@ -42,66 +43,16 @@ @Service @SuppressWarnings("ALL") public class GedbService { - @Value("${sys.path.in}") - String inPath; - - @Value("${gedb.host}") - String host; - - @Value("${gedb.user}") - String user; - - @Value("${gedb.pwd}") - String pwd; - - @Value("${gedb.dbName}") - String dbName; - - @Value("${gedb.pageSize}") - Integer pageSize; - - @Value("#{'${gedb.layerNames}'}") - List<String> layerNames; - - @Value("#{'${gedb.shpNames}'}") - List<String> shpNames; - - @Value("#{'${gedb.sysFields}'}") - List<String> sysFields; - - @Value("${gedb.demFile}") - String demFile; - - @Value("${gedb.demType}") - String demType; - - @Value("${gedb.demName}") - String demName; - String password; + + @Resource + PropertiesConfig config; @Resource RestTemplate restTemplate; public boolean test(DataPo data) throws Exception { - /*String token = getToken(); - GeDb db = getSeDb(token); - db.setBbox(bbox); - - List<GeLayer> layers = getLayers(token, db); - queryData(token, db, layers); - - String basePath = inPath + File.separator + taskName; - createPath(basePath); - createShps(basePath, layers); - - GeDb fileDb = getFileDb(token); - String fileId = getFileId(token, fileDb.getDbid()); - List<GeFile> files = getFileNames(token, fileDb.getDbid(), fileId); - - String filePath = inPath + File.separator + fileDb.getDbid(); - downloadFiles(token, filePath, files, fileDb.getDbid(), fileId); - clipDemFile(filePath, files, basePath, bbox, 4548);*/ + createPath(config.getInPath() + File.separator + data.getInPath()); String token = getToken(); GeDb db = connectGedb(token, data); @@ -123,10 +74,10 @@ public String getToken() throws Exception { Map<String, Object> map = new HashMap<>(2); - map.put("userid", user); + map.put("userid", config.getUser()); map.put("password", getPassword()); - JSONObject obj = restTemplate.postForObject(host + "account-service/security/login", map, JSONObject.class); + JSONObject obj = restTemplate.postForObject(config.getHost() + "account-service/security/login", map, JSONObject.class); JSONObject data = obj.getJSONObject("data"); @@ -137,7 +88,7 @@ if (StringHelper.isEmpty(password)) { String key = getPublicKey(); RsaHelper.setPublicKey(key); - password = RsaHelper.encrypt(pwd); + password = RsaHelper.encrypt(config.getPwd()); } return password; @@ -145,7 +96,7 @@ private String getPublicKey() { //{"datetime":"2024-09-12 17:24:38","code":200,"data":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtFwJCh2taVTEi05C8qT2oG7Y+rDmJhlO4zicpSeRtiro9LsytePeWI7BXM6sfDU0WeKun1izawcfgGkZgnoJuMBluAOKI1tL0uCrR+DreNLqMVtnXHwoWEIk/hGJedDWaf3q22aGDyEB5h9qCq0JklSShP1Ih4ppap4LmgxdTPQIDAQAB"} - JSONObject obj = restTemplate.getForObject(host + "account-service/security/publickey", JSONObject.class); + JSONObject obj = restTemplate.getForObject(config.getHost() + "account-service/security/publickey", JSONObject.class); return obj.getStr("data"); } @@ -162,17 +113,17 @@ Map<String, Object> map = new HashMap<>(1); map.put("token", token); - JSONObject obj = restTemplate.postForObject(host + "geo-service/entitydb/list/canview", map, JSONObject.class); + JSONObject obj = restTemplate.postForObject(config.getHost() + "geo-service/entitydb/list/canview", map, JSONObject.class); JSONArray data = obj.getJSONArray("data"); List<GeDb> list = JSONUtil.toList(data, GeDb.class); if (CollectionUtils.isEmpty(list)) return null; - return list.stream().filter(db -> null != db.getName() && db.getName().contains(dbName)).findFirst().orElse(null); + return list.stream().filter(db -> null != db.getName() && db.getName().contains(config.getDbName())).findFirst().orElse(null); } public List<GeLayer> getLayers(String token, GeDb db) { - String uri = String.format("%sgeo-service/entitydb/map/config?dbid=%s&token=%s", host, db.getDbid(), token); + String uri = String.format("%sgeo-service/entitydb/map/config?dbid=%s&token=%s", config.getHost(), db.getDbid(), token); JSONObject obj = restTemplate.getForObject(uri, JSONObject.class); JSONObject data = obj.getJSONObject("data"); @@ -183,12 +134,12 @@ for (int i = 0, c = arr.size(); i < c; i++) { JSONObject jb = arr.getJSONObject(i); String name = jb.getStr("name"); - if (layerNames.contains(name)) { + if (config.getLayerNames().contains(name)) { String id = jb.getStr("id"); String queryType = getQueryType(jb); List<GeField> fields = JSONUtil.toList(jb.getJSONArray("fields"), GeField.class); - fields = fields.stream().filter(f -> !sysFields.contains(f.getName())).collect(Collectors.toList()); - String shpName = shpNames.get(layerNames.indexOf(name)); + fields = fields.stream().filter(f -> !config.getSysFields().contains(f.getName())).collect(Collectors.toList()); + String shpName = config.getShpNames().get(config.getLayerNames().indexOf(name)); layers.add(new GeLayer(id, name, queryType, fields, shpName, db)); } @@ -216,9 +167,9 @@ int count = getCount(token, db, layer); if (0 == count) throw new Exception(layer.getName() + "锛屽浘灞傛暟鎹负绌�"); - int pageCount = (count - 1) / pageSize + 1; + int pageCount = (count - 1) / config.getPageSize() + 1; for (int i = 0; i < pageCount; i++) { - JSONArray data = query(token, db, layer, i + 1, pageSize); + JSONArray data = query(token, db, layer, i + 1, config.getPageSize()); if (null != data && data.size() > 0) { layer.addData(data); } @@ -235,7 +186,7 @@ map.put("returnCountOnly", true); map.put("inSR", 4326); - JSONObject obj = restTemplate.postForObject(host + "geo-service/entitydbdata/layer/query", map, JSONObject.class); + JSONObject obj = restTemplate.postForObject(config.getHost() + "geo-service/entitydbdata/layer/query", map, JSONObject.class); if (null == obj || 200 != obj.getInt("code")) return 0; return obj.getInt("data"); @@ -253,7 +204,7 @@ map.put("querytype", layer.getQueryType()); map.put("inSR", 4326); - JSONObject obj = restTemplate.postForObject(host + "geo-service/entitydbdata/layer/query", map, JSONObject.class); + JSONObject obj = restTemplate.postForObject(config.getHost() + "geo-service/entitydbdata/layer/query", map, JSONObject.class); if (null == obj || 200 != obj.getInt("code")) return null; JSONObject data = obj.getJSONObject("data"); @@ -262,20 +213,58 @@ } public void copeVectors(String token, DataPo data, GeDb db) throws Exception { - String basePath = inPath + File.separator + data.getInPath(); + String basePath = config.getInPath() + File.separator + data.getInPath(); List<GeLayer> layers = getLayers(token, db); queryData(token, db, layers); createShps(basePath, layers); + createZoneShp(basePath, data, db.getSpatialReference()); + if (data.getPid() > 0) { + createFloodShp(basePath, data, db.getSpatialReference()); + } } private void createShps(String basePath, List<GeLayer> layers) throws Exception { for (GeLayer layer : layers) { - String path = String.format("%s\\%s.shp", basePath, layer.getShpName()); + String path = basePath + File.separator + layer.getShpName(); if (!ShpHelper.createShp(path, layer)) { throw new Exception(layer.getName() + "锛屽垱寤篠hapeFile鏂囦欢澶辫触锛�"); } + // 绠$綉闆嗘按鐐� + if (layer.getShpName().equals(config.getShpNames().get(0))) { + GeLayer juncLayer = new GeLayer(layer, filterLayerData(layer.getData())); + if (!ShpHelper.createShp(basePath + File.separator + config.getJunctionName(), juncLayer)) { + throw new Exception("闆嗘按鐐�" + "锛屽垱寤篠hapeFile鏂囦欢澶辫触锛�"); + } + } } + } + + private JSONArray filterLayerData(JSONArray data) { + JSONArray arr = new JSONArray(); + String[] strs = config.getJunctionFilter().split("="); + for (int i = 0, c = data.size(); i < c; i++) { + JSONObject obj = data.getJSONObject(i).getJSONObject("properties"); + if (strs[1].equals(obj.getStr(strs[0]))) { + arr.put(data.getJSONObject(i)); + } + } + + return arr; + } + + private void createZoneShp(String basePath, DataPo data, SpatialReference sr) { + String filePath = basePath + File.separator + config.getZoneName(); + ShpHelper.createShp(filePath,null, sr, data.getMinx(), data.getMiny(), data.getMaxx(), data.getMaxy()); + } + + private void createFloodShp(String basePath, DataPo data, SpatialReference sr) { + String filePath = basePath + File.separator + config.getBarrierName(); + Map<String, Object> map = new HashMap<>(); + map.put("height", data.getFloodHeight()); + map.put("type", data.getFloodType()); + + ShpHelper.createShp(filePath, map, sr, data.getFloodMinx(), data.getFloodMiny(), data.getFloodMaxx(), data.getFloodMaxy()); } public void copeDem(String token, DataPo data) throws Exception { @@ -283,32 +272,32 @@ String fileId = getFileId(token, fileDb.getDbid()); List<GeFile> files = getFileNames(token, fileDb.getDbid(), fileId); - String filePath = inPath + File.separator + fileDb.getDbid(); + String filePath = config.getInPath() + File.separator + fileDb.getDbid(); downloadFiles(token, filePath, files, fileDb.getDbid(), fileId); clipDemFile(filePath, files, data); } private GeDb getFileDb(String token) { - String uri = String.format("%sfile-service/docdb/query/canview?token=%s", host, token); + String uri = String.format("%sfile-service/docdb/query/canview?token=%s", config.getHost(), token); JSONObject obj = restTemplate.getForObject(uri, JSONObject.class); JSONArray data = obj.getJSONArray("data"); List<GeDb> list = JSONUtil.toList(data, GeDb.class); if (CollectionUtils.isEmpty(list)) return null; - return list.stream().filter(db -> null != db.getName() && db.getName().contains(dbName)).findFirst().orElse(null); + return list.stream().filter(db -> null != db.getName() && db.getName().contains(config.getDbName())).findFirst().orElse(null); } private String getFileId(String token, String dbid) { String uri = String.format("%sfile-service/doc/catagory/file/query?token=%s&dbid=%s&catagory=%s&count=%d&start=%d&like=", - host, token, dbid, "image", 9999, 1); + config.getHost(), token, dbid, "image", 9999, 1); JSONObject obj = restTemplate.getForObject(uri, JSONObject.class); JSONArray items = obj.getJSONObject("data").getJSONArray("items"); for (int i = 0, c = items.size(); i < c; i++) { JSONObject jb = items.getJSONObject(i); - if (demName.equals(jb.getStr("filename"))) { + if (config.getDemName().equals(jb.getStr("filename"))) { return jb.getStr("fileid"); } } @@ -318,7 +307,7 @@ private List<GeFile> getFileNames(String token, String dbid, String fileId) { String uri = String.format("%sfile-service/doc/cluster/struct/list?token=%s&dbid=%s&cluster_fileid=%s&onlychild=true&folder_stairs=", - host, token, dbid, fileId); + config.getHost(), token, dbid, fileId); JSONObject obj = restTemplate.getForObject(uri, JSONObject.class); JSONArray data = obj.getJSONArray("data"); @@ -343,7 +332,7 @@ } String uri = String.format("%sfile-service/fileparser/cluster/download/%s?token=%s&dbid=%s&cluster_fileid=%s", - host, geFile.getName(), token, dbid, fileId); + config.getHost(), geFile.getName(), token, dbid, fileId); downloadFile(uri, filePath); } } @@ -368,9 +357,9 @@ } private void clipDemFile(String filePath, List<GeFile> files, DataPo data) throws Exception { - String target = inPath + File.separator + data.getInPath() + File.separator + demFile; + String target = config.getInPath() + File.separator + data.getInPath() + File.separator + config.getDemFile(); for (GeFile file : files) { - if (file.getName().toLowerCase().endsWith(demType)) { + if (file.getName().toLowerCase().endsWith(config.getDemType())) { String source = filePath + File.separator + file.getName(); clipDem(source, target, data); break; -- Gitblit v1.9.3