初始化

This commit is contained in:
hukekuan@163.com 2018-04-03 09:01:29 +08:00
parent b19f1ccabd
commit 1bd88a9ad6
10 changed files with 205 additions and 3 deletions

View File

@ -0,0 +1,8 @@
package com.gis3c.common.bean;
/**
* Created by hukekuan on 2018/4/2.
*/
public interface IntEnum<E extends Enum<E>> {
Integer getIntValue();
}

View File

@ -2,6 +2,7 @@ package com.gis3c.ol.dao;
import com.gis3c.common.persistence.annotation.C3olDao;
import com.gis3c.ol.entity.Source;
import com.gis3c.ol.entity.TestStation;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
@ -26,4 +27,7 @@ public interface SourceDao {
public Integer insertSource(Source source);
public Integer updateSource(Source source);
public Integer deleteSourcesById(Set<String> sourceIds);
public Integer insertTestStation(TestStation testStation);
public List<TestStation> findTestStationList();
}

View File

@ -0,0 +1,38 @@
package com.gis3c.ol.entity;
import com.gis3c.common.bean.IntEnum;
/**
* Created by hukekuan on 2018/4/2.
*/
public enum StationStatus implements IntEnum<StationStatus> {
ZC(0,0), CB(1,1), TC(2,-1), GZ(3,-2);
private StationStatus(Integer index,Integer statusCode){
this.index = index;
this.statusCode = statusCode;
}
private Integer index;
private Integer statusCode;
public Integer getStatusCode() {
return statusCode;
}
public void setStatusCode(Integer statusCode) {
this.statusCode = statusCode;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
@Override
public Integer getIntValue() {
return this.index;
}
}

View File

@ -0,0 +1,34 @@
package com.gis3c.ol.entity;
/**
* Created by hukekuan on 2018/4/2.
*/
public class TestStation {
private Integer stationId;
private String stationName;
private StationStatus stationStatus;
public Integer getStationId() {
return stationId;
}
public void setStationId(Integer stationId) {
this.stationId = stationId;
}
public String getStationName() {
return stationName;
}
public void setStationName(String stationName) {
this.stationName = stationName;
}
public StationStatus getStationStatus() {
return stationStatus;
}
public void setStationStatus(StationStatus stationStatus) {
this.stationStatus = stationStatus;
}
}

View File

@ -1,7 +1,9 @@
package com.gis3c.ol.service;
import com.gis3c.ol.entity.Source;
import com.gis3c.ol.entity.TestStation;
import java.security.PublicKey;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@ -20,4 +22,7 @@ public interface SourceService {
public Integer insertSource(Source source);
public Integer updateSource(Source source);
public Integer deleteSourcesById(Set<String> sourceIds);
public Integer insertTestStation(TestStation testStation);
public List<TestStation> findTestStationList();
}

View File

@ -4,6 +4,7 @@ import com.gis3c.common.bean.BeanUtil;
import com.gis3c.common.exception.BusinessException;
import com.gis3c.ol.dao.SourceDao;
import com.gis3c.ol.entity.Source;
import com.gis3c.ol.entity.TestStation;
import com.gis3c.ol.service.SourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -72,4 +73,14 @@ public class SourceServiceImpl implements SourceService {
public Integer deleteSourcesById(Set<String> sourceIds) {
return sourceDao.deleteSourcesById(sourceIds);
}
@Override
public Integer insertTestStation(TestStation testStation) {
return sourceDao.insertTestStation(testStation);
}
@Override
public List<TestStation> findTestStationList() {
return sourceDao.findTestStationList();
}
}

View File

@ -0,0 +1,62 @@
package com.gis3c.spatial.postgis;
import com.gis3c.common.bean.IntEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.EnumSet;
import java.util.Map;
/**
* Created by hukekuan on 2018/4/2.
*/
public class IntEnumTypeHandler<E extends Enum<E> & IntEnum<E>> extends BaseTypeHandler<IntEnum> {
private Class<IntEnum> type;
public IntEnumTypeHandler(Class<IntEnum> type) {
if (type == null)
throw new IllegalArgumentException("Type argument cannot be null");
this.type = type;
}
private IntEnum convert(int status) {
IntEnum[] objs = type.getEnumConstants();
if(objs != null){
for (IntEnum em : objs) {
if (em.getIntValue() == status) {
return em;
}
}
}
return null;
}
@Override
public IntEnum getNullableResult(ResultSet rs, String columnName)
throws SQLException {
return convert(rs.getInt(columnName));
}
@Override
public IntEnum getNullableResult(ResultSet rs, int columnIndex)
throws SQLException {
return convert(rs.getInt(columnIndex));
}
@Override
public IntEnum getNullableResult(CallableStatement cs, int columnIndex)
throws SQLException {
return convert(cs.getInt(columnIndex));
}
@Override
public void setNonNullParameter(PreparedStatement ps, int i, IntEnum enumObj, JdbcType jdbcType)
throws SQLException {
// baseTypeHandler已经帮我们做了parameter的null判断
ps.setInt(i, enumObj.getIntValue());
}
}

View File

@ -1,6 +1,7 @@
package com.gis3c.spatial;
import com.gis3c.common.bean.BeanUtil;
import com.gis3c.common.bean.IntEnum;
import com.gis3c.ol.entity.*;
import com.gis3c.ol.entity.Map;
import com.gis3c.ol.service.LayerService;
@ -14,6 +15,7 @@ import com.gis3c.spatial.service.RegionService;
import com.gis3c.spatial.service.TestService;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Point;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.operation.TransformException;
@ -36,10 +38,26 @@ public class App {
public static void main(String[] args) throws IllegalAccessException, IOException {
ApplicationContext context = ApplicationInit();
IntEnum[] objs = StationStatus.class.getEnumConstants();
System.out.println(objs.length);
List<Double> data = new ArrayList<>(Arrays.asList(new Double[]{1.1,2.1,3.1}));
Double result = data.stream().max(Comparator.naturalOrder()).get();
System.out.println(result);
// SourceService sourceService = context.getBean(SourceService.class);
//
// List<TestStation> testStationList = sourceService.findTestStationList();
// System.out.println(testStationList.get(0).getStationStatus());
// TestStation station = new TestStation();
// station.setStationId(2);
// station.setStationName("bbb");
// station.setStationStatus(StationStatus.ZC);
// sourceService.insertTestStation(station);
// System.out.println(stationStatus1.equals(stationStatus2));
// List<Double> data = new ArrayList<>(Arrays.asList(new Double[]{1.1,2.1,3.1}));
// Double result = data.stream().max(Comparator.naturalOrder()).get();
// System.out.println(result);
// Point start = GeometryUtilities.CreatePoint(118.024444,36.802778);

View File

@ -9,6 +9,12 @@
<result property="options" column="options" javaType="ObjectJSON"/>
<result property="description" column="description" />
</resultMap>
<resultMap id="testStationResult" type="com.gis3c.ol.entity.TestStation">
<result property="stationId" column="stationid" />
<result property="stationName" column="stationname" />
<result property="stationStatus" column="stationstatus" jdbcType="BIT" javaType="IntEnum"/>
</resultMap>
<sql id="sourceColumns">
sourceId
@ -90,4 +96,18 @@
#{item, javaType=java.lang.String}
</foreach>
</delete>
<insert id="insertTestStation" parameterType="com.gis3c.ol.entity.TestStation">
INSERT INTO stationtest(stationid,stationname,stationstatus)
VALUES (
#{stationId},
#{stationName},
#{stationStatus,jdbcType=BIT,javaType=IntEnum}
);
</insert>
<select id="findTestStationList" resultMap="testStationResult">
SELECT stationid,stationname,stationstatus
FROM stationtest;
</select>
</mapper>

View File

@ -50,10 +50,12 @@
<typeAlias type="com.vividsolutions.jts.geom.Geometry" alias="Geometry" />
<typeAlias type="java.lang.Object" alias="ObjectArray" />
<typeAlias type="java.util.Map" alias="ObjectJSON" />
<typeAlias type="com.gis3c.common.bean.IntEnum" alias="IntEnum" />
</typeAliases>
<typeHandlers>
<typeHandler handler="com.gis3c.spatial.postgis.PostGISHandler" javaType="Geometry" />
<typeHandler handler="com.gis3c.spatial.postgis.ArrayTypeHandler" javaType="ObjectArray" />
<typeHandler handler="com.gis3c.spatial.postgis.JsonTypeHandler" javaType="ObjectJSON" />
<typeHandler handler="com.gis3c.spatial.postgis.IntEnumTypeHandler" javaType="IntEnum" />
</typeHandlers>
</configuration>