|
@@ -0,0 +1,91 @@
|
|
|
+package com.example.nngkxxdp.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.example.nngkxxdp.dao.MapDataDao;
|
|
|
+import com.example.nngkxxdp.entity.MapData;
|
|
|
+import com.example.nngkxxdp.service.MapDataService;
|
|
|
+import com.example.nngkxxdp.util.Blank;
|
|
|
+
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.ResourceUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ApplicationName: nngkxxdp
|
|
|
+ * @Title: MapDataServiceImpl
|
|
|
+ * @Package: com.example.nngkxxdp.service.impl
|
|
|
+ * @Description: 地图数据
|
|
|
+ * @author: YJQ
|
|
|
+ * @date: 2022年6月24日 下午2:54:34
|
|
|
+ * @version: V1.0.0
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Transactional
|
|
|
+public class MapDataServiceImpl implements MapDataService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MapDataDao mapDataDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer insertBatchByJson() {
|
|
|
+ File file = null;
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ try {
|
|
|
+ file = ResourceUtils.getFile("classpath:static/district/js/map.json");
|
|
|
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) {
|
|
|
+ String readLine = null;
|
|
|
+ while ((readLine = br.readLine()) != null) {
|
|
|
+ sb.append(readLine);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (Blank.isEmpty(sb.toString())) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ mapDataDao.clearMapData();
|
|
|
+ JSONObject obj = JSONUtil.parseObj(sb.toString());
|
|
|
+ for (String key : obj.keySet()) {
|
|
|
+ List<MapData> mapList = JSONArray.parseArray(obj.getStr(key), MapData.class);
|
|
|
+ for (MapData mapData : mapList) {
|
|
|
+ mapData.setDictType(key);
|
|
|
+ }
|
|
|
+ mapDataDao.insertBatch(mapList);
|
|
|
+ }
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<MapData> getMapDataByDictType(String dictType) {
|
|
|
+ return mapDataDao.getMapDataByDictType(dictType);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getMapDataAll() {
|
|
|
+ List<String> dictTypes = mapDataDao.getDictType();
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ for (String type : dictTypes) {
|
|
|
+ result.put(type, mapDataDao.getMapDataByDictType(type));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|