Unverified 提交 b7683b25 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw 提交者: GitHub

Merge pull request #232 from dataease/pr@dev@feat_map

feat: 添加测试地图
......@@ -370,6 +370,18 @@
<artifactId>ST4</artifactId>
<version>4.0.8</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.4</version>
</dependency>
<!--<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>-->
</dependencies>
<build>
......
package io.dataease.base.domain;
import java.io.Serializable;
import lombok.Data;
@Data
public class AreaMapping implements Serializable {
private Long id;
private String provinceName;
private String provinceCode;
private String cityName;
private String cityCode;
private String countyName;
private String countyCode;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package io.dataease.base.mapper;
import io.dataease.base.domain.AreaMapping;
import io.dataease.base.domain.AreaMappingExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface AreaMappingMapper {
long countByExample(AreaMappingExample example);
int deleteByExample(AreaMappingExample example);
int deleteByPrimaryKey(Long id);
int insert(AreaMapping record);
int insertSelective(AreaMapping record);
List<AreaMapping> selectByExample(AreaMappingExample example);
AreaMapping selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") AreaMapping record, @Param("example") AreaMappingExample example);
int updateByExample(@Param("record") AreaMapping record, @Param("example") AreaMappingExample example);
int updateByPrimaryKeySelective(AreaMapping record);
int updateByPrimaryKey(AreaMapping record);
}
\ No newline at end of file
<?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="io.dataease.base.mapper.AreaMappingMapper">
<resultMap id="BaseResultMap" type="io.dataease.base.domain.AreaMapping">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="province_name" jdbcType="VARCHAR" property="provinceName" />
<result column="province_code" jdbcType="VARCHAR" property="provinceCode" />
<result column="city_name" jdbcType="VARCHAR" property="cityName" />
<result column="city_code" jdbcType="VARCHAR" property="cityCode" />
<result column="county_name" jdbcType="VARCHAR" property="countyName" />
<result column="county_code" jdbcType="VARCHAR" property="countyCode" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, province_name, province_code, city_name, city_code, county_name, county_code
</sql>
<select id="selectByExample" parameterType="io.dataease.base.domain.AreaMappingExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from area_mapping
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from area_mapping
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from area_mapping
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="io.dataease.base.domain.AreaMappingExample">
delete from area_mapping
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="io.dataease.base.domain.AreaMapping">
insert into area_mapping (id, province_name, province_code,
city_name, city_code, county_name,
county_code)
values (#{id,jdbcType=BIGINT}, #{provinceName,jdbcType=VARCHAR}, #{provinceCode,jdbcType=VARCHAR},
#{cityName,jdbcType=VARCHAR}, #{cityCode,jdbcType=VARCHAR}, #{countyName,jdbcType=VARCHAR},
#{countyCode,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.dataease.base.domain.AreaMapping">
insert into area_mapping
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="provinceName != null">
province_name,
</if>
<if test="provinceCode != null">
province_code,
</if>
<if test="cityName != null">
city_name,
</if>
<if test="cityCode != null">
city_code,
</if>
<if test="countyName != null">
county_name,
</if>
<if test="countyCode != null">
county_code,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="provinceName != null">
#{provinceName,jdbcType=VARCHAR},
</if>
<if test="provinceCode != null">
#{provinceCode,jdbcType=VARCHAR},
</if>
<if test="cityName != null">
#{cityName,jdbcType=VARCHAR},
</if>
<if test="cityCode != null">
#{cityCode,jdbcType=VARCHAR},
</if>
<if test="countyName != null">
#{countyName,jdbcType=VARCHAR},
</if>
<if test="countyCode != null">
#{countyCode,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.dataease.base.domain.AreaMappingExample" resultType="java.lang.Long">
select count(*) from area_mapping
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update area_mapping
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.provinceName != null">
province_name = #{record.provinceName,jdbcType=VARCHAR},
</if>
<if test="record.provinceCode != null">
province_code = #{record.provinceCode,jdbcType=VARCHAR},
</if>
<if test="record.cityName != null">
city_name = #{record.cityName,jdbcType=VARCHAR},
</if>
<if test="record.cityCode != null">
city_code = #{record.cityCode,jdbcType=VARCHAR},
</if>
<if test="record.countyName != null">
county_name = #{record.countyName,jdbcType=VARCHAR},
</if>
<if test="record.countyCode != null">
county_code = #{record.countyCode,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update area_mapping
set id = #{record.id,jdbcType=BIGINT},
province_name = #{record.provinceName,jdbcType=VARCHAR},
province_code = #{record.provinceCode,jdbcType=VARCHAR},
city_name = #{record.cityName,jdbcType=VARCHAR},
city_code = #{record.cityCode,jdbcType=VARCHAR},
county_name = #{record.countyName,jdbcType=VARCHAR},
county_code = #{record.countyCode,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="io.dataease.base.domain.AreaMapping">
update area_mapping
<set>
<if test="provinceName != null">
province_name = #{provinceName,jdbcType=VARCHAR},
</if>
<if test="provinceCode != null">
province_code = #{provinceCode,jdbcType=VARCHAR},
</if>
<if test="cityName != null">
city_name = #{cityName,jdbcType=VARCHAR},
</if>
<if test="cityCode != null">
city_code = #{cityCode,jdbcType=VARCHAR},
</if>
<if test="countyName != null">
county_name = #{countyName,jdbcType=VARCHAR},
</if>
<if test="countyCode != null">
county_code = #{countyCode,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="io.dataease.base.domain.AreaMapping">
update area_mapping
set province_name = #{provinceName,jdbcType=VARCHAR},
province_code = #{provinceCode,jdbcType=VARCHAR},
city_name = #{cityName,jdbcType=VARCHAR},
city_code = #{cityCode,jdbcType=VARCHAR},
county_name = #{countyName,jdbcType=VARCHAR},
county_code = #{countyCode,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
package io.dataease.map.api;
import io.dataease.map.dto.entity.AreaEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@RequestMapping("/api/map")
public interface MapApi {
@GetMapping("/resourceFull/{areaCode}")
String resourceFull(@PathVariable String areaCode);
@GetMapping("/asyncGeometry")
String asyncGeometry();
@GetMapping("/areaEntitys/{pcode}")
List<AreaEntity> areaEntitys(@PathVariable String pcode);
}
package io.dataease.map.dto.entity;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Data
@Builder
public class AreaEntity implements Serializable {
private static final long serialVersionUID = -1326667005437020282L;
private String code;
private String name;
private String pcode;
private List<AreaEntity> children;
public void addChild(AreaEntity entity) {
children = Optional.ofNullable(children).orElse(new ArrayList<>());
entity.setPcode(code);
children.add(entity);
}
}
package io.dataease.map.dto.entity;
public class Constants {
public static final String PROVINCE_CODE = "省gb";
public static final String PROVINCE_NAME = "省name";
public static final String CITY_CODE = "市gb";
public static final String CITY_NAME = "市name";
public static final String COUNTY_CODE = "县gb";
public static final String COUNTY_NAME = "县name";
}
package io.dataease.map.dto.entity;
import lombok.Data;
import java.util.List;
@Data
public class District {
private String adcode;
private String center;
private String citycode;
private String level;
private String name;
private String polyline;
private List<District> districts;
}
package io.dataease.map.dto.entity;
import lombok.Data;
import java.io.Serializable;
@Data
public class Feature implements Serializable {
private String type;
private Properties properties;
private Geometry geometry;
}
package io.dataease.map.dto.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class Geometry implements Serializable {
private String type;
// 多个面构成
// point一维数组 polyline二维数组 polygon三维数组 MultiPolygon四维数组
private List<List<List<List<Double>>>> coordinates;
}
package io.dataease.map.dto.entity;
import lombok.Data;
import java.io.Serializable;
@Data
public class Parent implements Serializable {
private String adcode;
}
package io.dataease.map.dto.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class Properties implements Serializable {
private String adcode;
private String name;
private List<Double> center;
private List<Double> centroid;
private Integer childrenNum;
private String level;
private Parent parent;
private Integer subFeatureIndex;
private List<Double> acroutes;
}
package io.dataease.map.dto.request;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
@Data
@Builder
public class MapRequest implements Serializable {
private String keywords;
private Integer subdistrict;
private String extensions;
private String key;
private Integer page = 1;
}
package io.dataease.map.dto.response;
import io.dataease.map.dto.entity.District;
import lombok.Data;
import java.util.List;
@Data
public class MapResponse {
private String status;
private String info;
private String infocode;
private String count;
private List<District> districts;
}
package io.dataease.map.dto.response;
import io.dataease.map.dto.entity.Feature;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class MapResultDto implements Serializable {
private String type;
private List<Feature> features;
}
package io.dataease.map.server;
import io.dataease.commons.utils.LogUtil;
import io.dataease.map.api.MapApi;
import io.dataease.map.dto.entity.AreaEntity;
import io.dataease.map.service.MapService;
import io.dataease.map.utils.MapUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
public class MapServer implements MapApi {
@Resource
private MapService mapService;
@Override
public String resourceFull(@PathVariable String areaCode) {
return mapService.geometry(areaCode);
}
@Override
public String asyncGeometry() {
try {
// List<AreaEntity> areaEntities = MapUtils.readAreaEntity();
List<AreaEntity> areaEntities = mapService.areaEntities();
MapUtils.recursionWriteFull(areaEntities);
}catch (Exception e) {
LogUtil.error(e);
return e.getMessage();
}
return "async success";
}
@Override
public List<AreaEntity> areaEntitys(@PathVariable String pcode) {
List<AreaEntity> areaEntities = mapService.areaEntities();
return mapService.entitysByPid(areaEntities, pcode);
/*return areaEntities.stream().filter(item -> StringUtils.equals(item.getPcode(), pcode)).map(item -> {
item.setChildren(null);
return item;
}).collect(Collectors.toList());*/
}
}
package io.dataease.map.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.file.FileReader;
import io.dataease.map.dto.entity.AreaEntity;
import io.dataease.map.utils.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class MapService {
private static final String dirPath = "/opt/dataease/data/feature/";
// 要不要加缓存呢?
public String geometry(String areaCode) {
String path = dirPath + "full/" + areaCode + "_full.json";
FileReader fileReader = new FileReader(path);
return fileReader.readString();
}
@Cacheable("sys_map_areas")
public List<AreaEntity> areaEntities() {
List<AreaEntity> areaEntities = MapUtils.readAreaEntity();
return areaEntities;
}
public List<AreaEntity> entitysByPid(List<AreaEntity> entities, String pid) {
for (int i = 0; i < entities.size(); i++) {
AreaEntity areaEntity = entities.get(i);
if (StringUtils.equals(pid, areaEntity.getCode())) {
return areaEntity.getChildren();
}
if (CollectionUtil.isNotEmpty(areaEntity.getChildren())) {
List<AreaEntity> areaEntities = entitysByPid(areaEntity.getChildren(), pid);
if (null != areaEntities){
return areaEntities;
}
}
}
return null;
}
}
package io.dataease.map.utils;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import io.dataease.map.dto.request.MapRequest;
import io.dataease.map.dto.response.MapResponse;
import java.util.Map;
public class HttpUtils {
private static final String url = "https://restapi.amap.com/v3/config/district";
private static final String key = "a5d10d5d05a3a0868cec67c4d66cf025";
private static final String extensions = "all";
private static final Integer subdistrict = 0;
public static MapResponse get(MapRequest request){
request.setKey(key);
request.setExtensions(extensions);
request.setSubdistrict(subdistrict);
Map<String, Object> param = BeanUtil.beanToMap(request);
String s = HttpUtil.get(url, param);
MapResponse mapResponse = JSONUtil.toBean(s, MapResponse.class);
return mapResponse;
}
public static MapResponse get(String code) {
MapRequest request = MapRequest.builder().keywords(code).build();
return get(request);
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -128,5 +128,15 @@
memoryStoreEvictionPolicy="LRU"
/>
<!--消息类型缓存-->
<cache
name="sys_map_areas"
eternal="true"
maxElementsInMemory="100"
maxElementsOnDisk="3000"
overflowToDisk="true"
diskPersistent="false"
/>
</ehcache>
\ No newline at end of file
<template>
<layout-content v-loading="$store.getters.loadingMap[$store.getters.currentPath]">
<div id="maptest" style="width: 100%;height:100%;" />
</layout-content>
</template>
<script>
import LayoutContent from '@/components/business/LayoutContent'
import { get } from '@/api/panel/panel'
export default {
components: { LayoutContent },
data() {
return {
myChart: null,
defaultPcode: '100000',
mapurl: '/api/map/resourceFull/'
}
},
created() {
},
mounted() {
const chartDom = document.getElementById('maptest')
this.myChart = this.$echarts.init(chartDom)
this.initMap(this.defaultPcode)
},
methods: {
initMap(pcode) {
this.myChart.showLoading()
get(this.mapurl + pcode).then(res => {
this.myChart.hideLoading()
const geoJson = res.data
this.$echarts.registerMap('HK', geoJson)
this.myChart.setOption({
series: [
{
type: 'map',
map: 'HK', // 自定义扩展图表类型
roam: true,
label: {
show: false
},
nameProperty: 'name'
}
]
})
this.queryAreaCodes(pcode).then(res => {
const areaEntitys = res.data
this.myChart.on('click', param => {
const name = param.name
for (let index = 0; index < areaEntitys.length; index++) {
const element = areaEntitys[index]
if (element.name === name) {
this.initMap(element.code)
}
}
})
})
})
},
queryAreaCodes(pcode) {
return get('/api/map/areaEntitys/' + pcode)
}
}
}
</script>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论