|
@@ -1,48 +1,37 @@
|
|
|
package cn.reghao.tnb.content.app.geo.service;
|
|
package cn.reghao.tnb.content.app.geo.service;
|
|
|
|
|
|
|
|
-import cn.reghao.jutil.jdk.text.TextFile;
|
|
|
|
|
|
|
+import cn.reghao.tnb.content.app.geo.db.mapper.GeoChinaMapper;
|
|
|
|
|
+import cn.reghao.tnb.content.app.geo.db.mapper.GeoPolygonMapper;
|
|
|
|
|
+import cn.reghao.tnb.content.app.geo.model.po.GeoChina;
|
|
|
import cn.reghao.tnb.content.app.geo.model.po.GeoPolygon;
|
|
import cn.reghao.tnb.content.app.geo.model.po.GeoPolygon;
|
|
|
-
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author reghao
|
|
* @author reghao
|
|
|
* @date 2024-09-09 15:39:46
|
|
* @date 2024-09-09 15:39:46
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service
|
|
|
public class GeoService {
|
|
public class GeoService {
|
|
|
- public static void main(String[] args) {
|
|
|
|
|
- TextFile textFile = new TextFile();
|
|
|
|
|
-
|
|
|
|
|
- String filePath = "/home/reghao/Downloads/geo/ok_geo.csv";
|
|
|
|
|
- List<String> list = textFile.read(filePath);
|
|
|
|
|
- Map<Integer, GeoPolygon> map = new HashMap<>();
|
|
|
|
|
- for (int i = 1; i < list.size(); i++) {
|
|
|
|
|
- String line = list.get(i);
|
|
|
|
|
- String[] arr = line.split(",\"");
|
|
|
|
|
- String[] arr1 = arr[0].split(",");
|
|
|
|
|
-
|
|
|
|
|
- if (arr1[0].startsWith("71")) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private final GeoChinaMapper geoChinaMapper;
|
|
|
|
|
+ private final GeoPolygonMapper geoPolygonMapper;
|
|
|
|
|
|
|
|
- Integer id = Integer.parseInt(arr1[0]);
|
|
|
|
|
- Integer pid = Integer.parseInt(arr1[1]);
|
|
|
|
|
- Integer deep = Integer.parseInt(arr1[2]);
|
|
|
|
|
- String name = arr[1];
|
|
|
|
|
- String extPath = arr[2];
|
|
|
|
|
- String geo = arr[3];
|
|
|
|
|
- String[] geoArr = geo.replace("\"", "").split(" ");
|
|
|
|
|
- BigDecimal lat = BigDecimal.valueOf(Double.parseDouble(geoArr[0]));
|
|
|
|
|
- BigDecimal lng = BigDecimal.valueOf(Double.parseDouble(geoArr[1]));
|
|
|
|
|
- String polygon = arr[4];
|
|
|
|
|
|
|
+ public GeoService(GeoChinaMapper geoChinaMapper, GeoPolygonMapper geoPolygonMapper) {
|
|
|
|
|
+ this.geoChinaMapper = geoChinaMapper;
|
|
|
|
|
+ this.geoPolygonMapper = geoPolygonMapper;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- GeoPolygon geoPolygon = new GeoPolygon(id, pid, deep, name, extPath, lat, lng, polygon);
|
|
|
|
|
- map.put(id, geoPolygon);
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void add(GeoChina geoChina, GeoPolygon geoPolygon) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ geoChinaMapper.save(geoChina);
|
|
|
|
|
+ geoPolygonMapper.save(geoPolygon);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.info("insert {} -> {} error", geoChina.getId(), geoChina.getExtName());
|
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- System.out.println();
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|