|
|
@@ -12,10 +12,12 @@ import com.siwei.common.core.exception.ServiceException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.ibatis.annotations.Param;
|
|
|
import org.gdal.ogr.*;
|
|
|
import org.gdal.osr.SpatialReference;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.nio.file.Files;
|
|
|
@@ -100,14 +102,12 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
s -> s.get("data_type"),
|
|
|
(existing, replacement) -> existing // 如果有重复键,保留第一个值
|
|
|
));
|
|
|
-
|
|
|
List<Map<String, Object>> theValueList = getValueList(layer,dbFieldNameAndTypeMap, haveGeom);
|
|
|
//这里直接数据入库,区分增量或者全量
|
|
|
Boolean addRes = fullDataStorage(layerName, theValueList);
|
|
|
log.error("当前图层{},入库结果 {}", layerName, addRes);
|
|
|
//Boolean checkRes2 = incrementalDataStorage(layer);
|
|
|
}
|
|
|
-
|
|
|
} catch (Exception e) {
|
|
|
log.error("矢量数据入库异常,uploadId: {}", uploadId, e);
|
|
|
throw new ServiceException("矢量数据入库异常," + e.getMessage());
|
|
|
@@ -116,6 +116,13 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取比较数据
|
|
|
*
|
|
|
@@ -334,7 +341,6 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
//这里移除校验字段(非属mdb中的字段)
|
|
|
dbFieldNameList.remove("valid_flag");
|
|
|
|
|
|
-
|
|
|
List<String> layerFieldNameList = this.getFieldName(layer, haveGeom);
|
|
|
// 判断是否包含相同的元素(不考虑顺序)
|
|
|
boolean areCollectionsEqual = CollectionUtils.isEqualCollection(dbFieldNameList, layerFieldNameList);
|
|
|
@@ -347,7 +353,7 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
//todo 这里根据表名获取相关校验字段信息
|
|
|
List<String> checkFieldList = new ArrayList<>();
|
|
|
//checkFieldList.add("111");
|
|
|
- //checkFieldList.add("bz");
|
|
|
+ checkFieldList.add("bz");
|
|
|
//仅获取图层属性
|
|
|
List<Map<String, Object>> theValueList = getValueList(layer,new LinkedHashMap<>(), false);
|
|
|
for (Map<String, Object> theMap : theValueList) {
|
|
|
@@ -360,6 +366,11 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
}
|
|
|
checkInfoVo.setCheckInfoList(checkInfoList);
|
|
|
//todo 这里需要放入到缓存中,并且可以下载为txt内容
|
|
|
+ if(checkInfoVo.getCheckStatus().equals(true)){
|
|
|
+ checkInfoList.add("当前矢量数据:"+name + "---" + "数据格式为gdb");
|
|
|
+ checkInfoList.add("当前矢量数据:"+name + "---" + "坐标系是CGCS2000");
|
|
|
+ checkInfoList.add("当前矢量数据:"+name + "---" + "检查校验通过!");
|
|
|
+ }
|
|
|
return checkInfoVo;
|
|
|
}
|
|
|
|
|
|
@@ -393,10 +404,10 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
*/
|
|
|
private List<Map<String, Object>> getValueList(Layer layer,Map<String,String> fieldNameAndTypeMap , Boolean haveGeom) {
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
- Map<String, Object> map = new LinkedHashMap<>();
|
|
|
layer.ResetReading();
|
|
|
Feature feature;
|
|
|
while ((feature = layer.GetNextFeature()) != null) {
|
|
|
+ Map<String, Object> map = new LinkedHashMap<>();
|
|
|
for (int i = 0; i < feature.GetFieldCount(); i++) {
|
|
|
String fieldName = feature.GetFieldDefnRef(i).GetName();
|
|
|
if(fieldNameAndTypeMap.containsKey(fieldName.toLowerCase())) {
|
|
|
@@ -428,6 +439,11 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
// // 为几何体设置空间参考(SRID 4326)
|
|
|
// geom.AssignSpatialReference(spatialRef);
|
|
|
// 将几何对象转换为 WKT 格式
|
|
|
+ geom = geom.MakeValid();
|
|
|
+ int type = geom.GetGeometryType() & 0xFF;
|
|
|
+ if (type != ogr.wkbPolygon && type != ogr.wkbMultiPolygon) {
|
|
|
+ continue; // 直接跳过
|
|
|
+ }
|
|
|
ewkt = "SRID=" + 4326 + ";" + geom.ExportToWkt();;
|
|
|
}
|
|
|
map.put("geom", ewkt);
|
|
|
@@ -437,7 +453,6 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 校验当前图层坐标系是否为:CGCS2000
|
|
|
*
|
|
|
@@ -487,13 +502,40 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 获取对比的矢量图层
|
|
|
*
|
|
|
* @param layer
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<String> getLayerGeom(Layer layer) {
|
|
|
+ private static List<String> getLayerGeom(Layer layer) {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ layer.ResetReading();
|
|
|
+ Feature feature;
|
|
|
+ while ((feature = layer.GetNextFeature()) != null) {
|
|
|
+ Geometry geom = feature.GetGeometryRef();
|
|
|
+ String ewkt = "";
|
|
|
+ if (geom != null) {
|
|
|
+ // 将几何对象转换为 WKT 格式
|
|
|
+ ewkt = "SRID=" + 4326 + ";" + geom.ExportToWkt();;
|
|
|
+ }
|
|
|
+ list.add(ewkt);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取对比的矢量图层
|
|
|
+ *
|
|
|
+ * @param layer
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> getLayerGeom_del(Layer layer) {
|
|
|
List<String> list = new ArrayList<>();
|
|
|
// 循环处理每个要素
|
|
|
for (int i = 0; i < layer.GetFeatureCount(0); i++) {
|
|
|
@@ -535,13 +577,19 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
* @param theValueList
|
|
|
* @return
|
|
|
*/
|
|
|
- private Boolean fullDataStorage(String tableName, List<Map<String, Object>> theValueList) {
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
+ public Boolean fullDataStorage(String tableName, List<Map<String, Object>> theValueList) {
|
|
|
boolean addRes = false;
|
|
|
+ Integer shpDbSRID = 4326;
|
|
|
if (!CollectionUtils.isEmpty(theValueList)) {
|
|
|
+ //先删除数据
|
|
|
+ cadastreFileMapper.deleteByValidFlag("1",tableName);
|
|
|
+ //先把当前版本都修改为历史版本
|
|
|
+ cadastreFileMapper.updateValidFlag("1","0",tableName);
|
|
|
for (Map<String, Object> map : theValueList) {
|
|
|
// Collection<Object> values = map.values();
|
|
|
// Collection<String> keys = map.keySet();
|
|
|
- Integer shpDbSRID = 4326;
|
|
|
+ map.put("valid_flag", 0);//有效数据标识
|
|
|
cadastreFileMapper.insertTableData(tableName,map,shpDbSRID);
|
|
|
}
|
|
|
}
|
|
|
@@ -613,10 +661,66 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
cadastreFileMapper.addValidFlagColumn(tableName);
|
|
|
System.out.println("正在处理表: " + tableName + " 完成");
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public String backToOldData(String uploadId) {
|
|
|
+ //1.获取所有表名。
|
|
|
+ //2.校验是否都有历史版本。
|
|
|
+ //3.如果都有历史版本,则把当前版本删除,把历史版本修改为当前版本。
|
|
|
+ List<String> layerNameList = getLayerNameList(uploadId);
|
|
|
+ for(String layerName : layerNameList){
|
|
|
+ if (!layerName.equalsIgnoreCase("T_CGZJ_CWTC_M")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验是否都有历史版本
|
|
|
+ Integer count = cadastreFileMapper.countByValidFlag("1", layerName.toLowerCase(Locale.ROOT));
|
|
|
+ if(count == 0){
|
|
|
+ throw new ServiceException("表"+layerName+"没有历史版本,无法回退");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(String layerName : layerNameList){
|
|
|
+ if (!layerName.equalsIgnoreCase("T_CGZJ_CWTC_M")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ cadastreFileMapper.deleteByValidFlag("0", layerName.toLowerCase(Locale.ROOT));
|
|
|
+ cadastreFileMapper.updateValidFlag("0","1", layerName.toLowerCase(Locale.ROOT));
|
|
|
+ log.info("正在回退表:{}。。。", layerName);
|
|
|
+ }
|
|
|
+ return "当前批次数据已回退到上一个版本!:"+uploadId;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取图层名称列表
|
|
|
+ * @param uploadId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> getLayerNameList(String uploadId) {
|
|
|
+ List<String> nameList = new ArrayList<>();
|
|
|
+ CadastreFile cadastreFile = cadastreFileMapper.get(uploadId);
|
|
|
+ String gdbPath = cadastreFile.getUnzipPath();
|
|
|
+ DataSource ds = ogr.Open(gdbPath + "/" + cadastreFile.getName(), 0); // 0 = 只读
|
|
|
+ if (ds == null) {
|
|
|
+ throw new ServiceException("无法打开 gdb" );
|
|
|
+ }
|
|
|
+ //这里进行遍历每个图层
|
|
|
+ for (int i = 0; i < ds.GetLayerCount(); i++) {
|
|
|
+ Layer layer = ds.GetLayer(i);
|
|
|
+ String layerName = layer.GetName();
|
|
|
+ nameList.add(layerName);
|
|
|
+ }
|
|
|
+ return nameList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|