Browse Source

添加地图数据存储

yjq 2 years ago
parent
commit
9393369662

+ 74 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/MapDataController.java

@@ -0,0 +1,74 @@
+package com.example.nngkxxdp.controller;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.example.nngkxxdp.service.MapDataService;
+import com.example.nngkxxdp.util.Blank;
+import com.example.nngkxxdp.util.ConstStr;
+import com.example.nngkxxdp.util.SendUtil;
+
+/**
+ * @ApplicationName: nngkxxdp
+ * @Title: MapDataController
+ * @Package: com.example.nngkxxdp.controller
+ * @Description: 地图数据
+ * @author: YJQ
+ * @date: 2022年6月24日 下午2:51:49
+ * @version: V1.0.0
+ */
+@RestController
+@RequestMapping("mapdata")
+public class MapDataController {
+
+	@Autowired
+	private MapDataService mapDataService;
+
+	/**
+	 * @Title: insertBatchByJson
+	 * @Description: 批量保存地图数据
+	 * @author: YJQ
+	 * @date: 2022年6月24日 下午3:19:41
+	 * @returnType Map<String,Object>
+	 * @return
+	 */
+	@GetMapping("insertBatchByJson")
+	public Map<String, Object> insertBatchByJson() {
+		return SendUtil.send(true, ConstStr.RESULT_SUCCESS, mapDataService.insertBatchByJson());
+	}
+	
+	/**
+	 * @Title: getMapDataByDictType
+	 * @Description: 根据数据字典类型获取地图数据
+	 * @author: YJQ
+	 * @date: 2022年6月24日 下午3:52:14
+	 * @returnType Map<String,Object>
+	 * @param dictType
+	 * @return
+	 */
+	@GetMapping("getMapDataByDictType")
+	public Map<String, Object> getMapDataByDictType(String dictType) {
+		if (Blank.isEmpty(dictType)) {
+			return SendUtil.send(false, ConstStr.REQUEST_WRONGPARAMS);
+		}
+		return SendUtil.send(true, ConstStr.RESULT_SUCCESS, mapDataService.getMapDataByDictType(dictType));
+	}
+	
+	/**
+	 * @Title: getMapDataAll
+	 * @Description: 查询所有的地图数据信息
+	 * @author: YJQ
+	 * @date: 2022年6月24日 下午4:36:07
+	 * @returnType Map<String,Object>
+	 * @return
+	 */
+	@GetMapping("getMapDataAll")
+	public Map<String, Object> getMapDataAll() {
+		return SendUtil.send(true, ConstStr.RESULT_SUCCESS, mapDataService.getMapDataAll());
+	}
+
+}

+ 64 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/MapDataDao.java

@@ -0,0 +1,64 @@
+package com.example.nngkxxdp.dao;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import com.example.nngkxxdp.entity.MapData;
+
+/**
+ * @ApplicationName: nngkxxdp
+ * @Title: MapDataDao
+ * @Package: com.example.nngkxxdp.dao
+ * @Description: 地图数据
+ * @author: YJQ
+ * @date: 2022年6月24日 下午2:52:07
+ * @version: V1.0.0
+ */
+@Mapper
+public interface MapDataDao {
+
+	/**
+	 * @Title: insertBatch
+	 * @Description: 批量保存地图数据
+	 * @author: YJQ
+	 * @date: 2022年6月24日 下午3:23:16
+	 * @returnType Integer
+	 * @param mapDataList
+	 * @return
+	 */
+	Integer insertBatch(@Param("mapDataList") List<MapData> mapDataList);
+
+	/**
+	 * @Title: clearMapData
+	 * @Description: 清空表数据信息
+	 * @author: YJQ
+	 * @date: 2022年6月24日 下午5:03:02
+	 * @returnType Integer
+	 * @return
+	 */
+	Integer clearMapData();
+
+	/**
+	 * @Title: getMapDataByDictType
+	 * @Description: 根据数据字典类型获取地图数据
+	 * @author: YJQ
+	 * @date: 2022年6月24日 下午4:29:23
+	 * @returnType List<MapData>
+	 * @param dictType
+	 * @return
+	 */
+	List<MapData> getMapDataByDictType(@Param("dictType") String dictType);
+
+	/**
+	 * @Title: getDictType
+	 * @Description: 根据地图数据所有的字典类型
+	 * @author: YJQ
+	 * @date: 2022年6月24日 下午4:44:24
+	 * @returnType List<String>
+	 * @return
+	 */
+	List<String> getDictType();
+
+}

+ 110 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/entity/MapData.java

@@ -0,0 +1,110 @@
+package com.example.nngkxxdp.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @ApplicationName: nngkxxdp
+ * @Title: MapData
+ * @Package: com.example.nngkxxdp.entity
+ * @Description: 地图数据
+ * @author: YJQ
+ * @date: 2022年6月24日 下午3:07:56
+ * @version: V1.0.0
+ */
+@Data
+public class MapData implements Serializable {
+
+	/**
+	 * @Fields serialVersionUID: TODO
+	 */
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 主键ID
+	 */
+	private Integer id;
+
+	/**
+	 * 数据类型字典
+	 */
+	private String dictType;
+
+	/**
+	 * 地址
+	 */
+	private String address;
+
+	/**
+	 * 描述
+	 */
+	private String content;
+
+	/**
+	 * 名称
+	 */
+	private String dep;
+
+	/**
+	 * 图片
+	 */
+	private String img;
+
+	/**
+	 * 服务类型
+	 */
+	private String sptype;
+
+	/**
+	 * 联系电话
+	 */
+	private String tel;
+
+	/**
+	 * 营业时间
+	 */
+	private String time;
+
+	/**
+	 * 链接地址
+	 */
+	private String url;
+
+	/**
+	 * 类型
+	 */
+	private String type;
+
+	/**
+	 * 标签
+	 */
+	private String tag;
+
+	/**
+	 * 标签2
+	 */
+	private String tag2;
+
+	/**
+	 * 标签3
+	 */
+	private String tag3;
+
+	/**
+	 * 特殊类型
+	 */
+	private String specialtype;
+
+	/**
+	 * 创建时间
+	 */
+	private Date createTime;
+
+	/**
+	 * 更新时间
+	 */
+	private Date updateTime;
+
+}

+ 50 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/MapDataService.java

@@ -0,0 +1,50 @@
+package com.example.nngkxxdp.service;
+
+import java.util.List;
+import java.util.Map;
+
+import com.example.nngkxxdp.entity.MapData;
+
+/**
+ * @ApplicationName: nngkxxdp
+ * @Title: MapDataService
+ * @Package: com.example.nngkxxdp.service
+ * @Description: 地图数据
+ * @author: YJQ
+ * @date: 2022年6月24日 下午2:53:09
+ * @version: V1.0.0
+ */
+public interface MapDataService {
+
+	/**
+	 * @Title: insertBatchByJson
+	 * @Description: 批量保存地图数据
+	 * @author: YJQ
+	 * @date: 2022年6月24日 下午3:20:06
+	 * @returnType Integer
+	 * @return
+	 */
+	Integer insertBatchByJson();
+
+	/**
+	 * @Title: getMapDataByDictType
+	 * @Description: 根据数据字典类型获取地图数据
+	 * @author: YJQ
+	 * @date: 2022年6月24日 下午3:54:08
+	 * @returnType List<MapData>
+	 * @param dictType
+	 * @return
+	 */
+	List<MapData> getMapDataByDictType(String dictType);
+
+	/**
+	 * @Title: getMapDataAll
+	 * @Description: 查询所有的地图数据信息
+	 * @author: YJQ
+	 * @date: 2022年6月24日 下午4:36:49
+	 * @returnType Map<String,Object>
+	 * @return
+	 */
+	Map<String, Object> getMapDataAll();
+	
+}

+ 91 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/MapDataServiceImpl.java

@@ -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;
+	}
+
+}

+ 45 - 0
nngkxxdp/src/main/resources/mapper/MapDataDao.xml

@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.example.nngkxxdp.dao.MapDataDao">
+
+	<sql id="all_base_data">
+		id, dict_type, address, content, dep, img, sptype, tel,
+		time, url, type, tag, tag2, tag3, specialtype, create_time,
+		update_time
+	</sql>
+
+	<!-- 批量保存地图数据 -->
+	<insert id="insertBatch" parameterType="java.util.List">
+		INSERT INTO s_map (
+		<include refid="all_base_data" />
+		)
+		VALUES
+		<foreach collection="mapDataList" item="map" separator=",">
+			(NULL,
+			#{map.dictType}, #{map.address}, #{map.content}, #{map.dep},
+			#{map.img}, #{map.sptype}, #{map.tel}, #{map.time}, #{map.url},
+			#{map.type}, #{map.tag}, #{map.tag2}, #{map.tag3},
+			#{map.specialtype}, NOW(), NOW())
+		</foreach>
+	</insert>
+	
+	<!-- 清空表数据信息 -->
+	<update id="clearMapData">
+		TRUNCATE TABLE s_map
+	</update>
+
+	<!-- 根据数据字典类型获取地图数据 -->
+	<select id="getMapDataByDictType"
+		resultType="com.example.nngkxxdp.entity.MapData">
+		SELECT
+		<include refid="all_base_data" />
+		FROM s_map
+		WHERE dict_type = #{dictType}
+	</select>
+	
+	<!-- 根据地图数据所有的字典类型 -->
+	<select id="getDictType" resultType="java.lang.String">
+		SELECT dict_type FROM s_map
+	</select>
+
+</mapper>