添加河流空间数据接口
This commit is contained in:
parent
f47dea3e53
commit
65ee59f1ea
17
src/main/java/com/gis3c/spatial/dao/RiverDao.java
Normal file
17
src/main/java/com/gis3c/spatial/dao/RiverDao.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.gis3c.spatial.dao;
|
||||
|
||||
import com.gis3c.common.persistence.annotation.C3SpatialDao;
|
||||
import com.gis3c.spatial.entity.SeparatedRiver;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by hukekuan on 2018/4/12.
|
||||
*/
|
||||
@C3SpatialDao
|
||||
public interface RiverDao {
|
||||
public List<SeparatedRiver> findRiversByStationCodes(@Param("stationCodes") Set<String> stationCodes);
|
||||
public List<SeparatedRiver> findRiversByRiverCodes(@Param("riverCodes") Set<String> riverCodes);
|
||||
}
|
||||
52
src/main/java/com/gis3c/spatial/entity/SeparatedRiver.java
Normal file
52
src/main/java/com/gis3c/spatial/entity/SeparatedRiver.java
Normal file
@ -0,0 +1,52 @@
|
||||
package com.gis3c.spatial.entity;
|
||||
|
||||
/**
|
||||
* Created by hukekuan on 2018/4/12.
|
||||
*/
|
||||
public class SeparatedRiver extends BaseFeature{
|
||||
private String riverCode;
|
||||
private String riverName;
|
||||
private String stationCode;
|
||||
private String stationName;
|
||||
private String level;
|
||||
|
||||
public String getRiverCode() {
|
||||
return riverCode;
|
||||
}
|
||||
|
||||
public void setRiverCode(String riverCode) {
|
||||
this.riverCode = riverCode;
|
||||
}
|
||||
|
||||
public String getRiverName() {
|
||||
return riverName;
|
||||
}
|
||||
|
||||
public void setRiverName(String riverName) {
|
||||
this.riverName = riverName;
|
||||
}
|
||||
|
||||
public String getStationCode() {
|
||||
return stationCode;
|
||||
}
|
||||
|
||||
public void setStationCode(String stationCode) {
|
||||
this.stationCode = stationCode;
|
||||
}
|
||||
|
||||
public String getStationName() {
|
||||
return stationName;
|
||||
}
|
||||
|
||||
public void setStationName(String stationName) {
|
||||
this.stationName = stationName;
|
||||
}
|
||||
|
||||
public String getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(String level) {
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
11
src/main/java/com/gis3c/spatial/service/RiverService.java
Normal file
11
src/main/java/com/gis3c/spatial/service/RiverService.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.gis3c.spatial.service;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by hukekuan on 2018/4/12.
|
||||
*/
|
||||
public interface RiverService {
|
||||
public String findRiversByStationCodes(Set<String> stationCodes);
|
||||
public String findRiversByRiverCodes(Set<String> riverCodes);
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.gis3c.spatial.service.impl;
|
||||
|
||||
import com.gis3c.common.exception.BusinessException;
|
||||
import com.gis3c.spatial.common.FeatureUtilities;
|
||||
import com.gis3c.spatial.dao.RiverDao;
|
||||
import com.gis3c.spatial.entity.SeparatedRiver;
|
||||
import com.gis3c.spatial.service.RiverService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by hukekuan on 2018/4/12.
|
||||
*/
|
||||
@Service
|
||||
public class RiverServiceImpl implements RiverService {
|
||||
@Autowired
|
||||
private RiverDao riverDao;
|
||||
|
||||
@Override
|
||||
public String findRiversByStationCodes(Set<String> stationCodes) {
|
||||
String riverJson = null;
|
||||
List<SeparatedRiver> riverList
|
||||
= riverDao.findRiversByStationCodes(stationCodes);
|
||||
try {
|
||||
riverJson = FeatureUtilities.JavaBeans2Json(riverList);
|
||||
} catch (IllegalAccessException | IOException e) {
|
||||
throw new BusinessException("River实体转GeoJSON出错");
|
||||
}
|
||||
return riverJson;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String findRiversByRiverCodes(Set<String> riverCodes) {
|
||||
String riverJson = null;
|
||||
List<SeparatedRiver> riverList
|
||||
= riverDao.findRiversByRiverCodes(riverCodes);
|
||||
try {
|
||||
riverJson = FeatureUtilities.JavaBeans2Json(riverList);
|
||||
} catch (IllegalAccessException | IOException e) {
|
||||
throw new BusinessException("River实体转GeoJSON出错");
|
||||
}
|
||||
return riverJson;
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,7 @@ import com.gis3c.spatial.common.GeometryUtilities;
|
||||
import com.gis3c.spatial.entity.Region;
|
||||
import com.gis3c.spatial.entity.RegionType;
|
||||
import com.gis3c.spatial.service.RegionService;
|
||||
import com.gis3c.spatial.service.RiverService;
|
||||
import com.gis3c.spatial.service.TestService;
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Point;
|
||||
@ -36,14 +37,12 @@ public class App {
|
||||
return new ClassPathXmlApplicationContext("classpath:spring-config.xml");
|
||||
}
|
||||
public static void main(String[] args) throws IllegalAccessException, IOException {
|
||||
ApplicationContext context = ApplicationInit();
|
||||
|
||||
Set<Integer> data = new HashSet<>();
|
||||
data.add(1);
|
||||
data.add(2);
|
||||
data.add(3);
|
||||
|
||||
System.out.println(data.contains(1));
|
||||
// ApplicationContext context = ApplicationInit();
|
||||
// RiverService riverService = context.getBean(RiverService.class);
|
||||
//
|
||||
// String resilt = riverService.findRiversByRiverCodes(
|
||||
// new HashSet<>(Arrays.asList(new String[]{"3783","3363"})));
|
||||
// System.out.println(resilt);
|
||||
|
||||
|
||||
|
||||
|
||||
43
src/test/resources/mappings/spatial/RiverDao.xml
Normal file
43
src/test/resources/mappings/spatial/RiverDao.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?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.gis3c.spatial.dao.RiverDao">
|
||||
<resultMap id="separatedRiverResult" type="com.gis3c.spatial.entity.SeparatedRiver">
|
||||
<result property="riverCode" column="rivercode" />
|
||||
<result property="riverName" column="rivername" />
|
||||
<result property="stationCode" column="stationcod" />
|
||||
<result property="stationName" column="stationnam" />
|
||||
<result property="geometry" column="geom" javaType="Geometry"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="findRiversByStationCodes" resultMap="separatedRiverResult">
|
||||
SELECT t.rivercode, t.rivername,t.stationcod,t.stationnam, t.geom
|
||||
FROM separatedriver t
|
||||
<choose>
|
||||
<when test="stationCodes != null and stationCodes.size() > 0">
|
||||
where t.stationcod in
|
||||
<foreach collection ="stationCodes" item="item" index="index" open="(" separator="," close=")">
|
||||
#{item, javaType=java.lang.String}
|
||||
</foreach>
|
||||
</when>
|
||||
<otherwise>
|
||||
where t.stationcod in ('-1')
|
||||
</otherwise>
|
||||
</choose>
|
||||
</select>
|
||||
|
||||
<select id="findRiversByRiverCodes" resultMap="separatedRiverResult">
|
||||
SELECT t.rivercode, t.rivername,t.stationcod,t.stationnam, t.geom
|
||||
FROM separatedriver t
|
||||
<choose>
|
||||
<when test="riverCodes != null and riverCodes.size() > 0">
|
||||
where t.rivercode in
|
||||
<foreach collection ="riverCodes" item="item" index="index" open="(" separator="," close=")">
|
||||
#{item, javaType=java.lang.String}
|
||||
</foreach>
|
||||
</when>
|
||||
<otherwise>
|
||||
where t.rivercode in ('-1')
|
||||
</otherwise>
|
||||
</choose>
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user