diff --git a/src/main/java/com/gis3c/common/bean/IntEnum.java b/src/main/java/com/gis3c/common/bean/IntEnum.java new file mode 100644 index 0000000..ec81c46 --- /dev/null +++ b/src/main/java/com/gis3c/common/bean/IntEnum.java @@ -0,0 +1,8 @@ +package com.gis3c.common.bean; + +/** + * Created by hukekuan on 2018/4/2. + */ +public interface IntEnum> { + Integer getIntValue(); +} diff --git a/src/main/java/com/gis3c/ol/dao/SourceDao.java b/src/main/java/com/gis3c/ol/dao/SourceDao.java index 19581bb..666bfa6 100644 --- a/src/main/java/com/gis3c/ol/dao/SourceDao.java +++ b/src/main/java/com/gis3c/ol/dao/SourceDao.java @@ -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 sourceIds); + + public Integer insertTestStation(TestStation testStation); + public List findTestStationList(); } diff --git a/src/main/java/com/gis3c/ol/entity/StationStatus.java b/src/main/java/com/gis3c/ol/entity/StationStatus.java new file mode 100644 index 0000000..1262f54 --- /dev/null +++ b/src/main/java/com/gis3c/ol/entity/StationStatus.java @@ -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 { + 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; + } +} diff --git a/src/main/java/com/gis3c/ol/entity/TestStation.java b/src/main/java/com/gis3c/ol/entity/TestStation.java new file mode 100644 index 0000000..8a27271 --- /dev/null +++ b/src/main/java/com/gis3c/ol/entity/TestStation.java @@ -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; + } +} diff --git a/src/main/java/com/gis3c/ol/service/SourceService.java b/src/main/java/com/gis3c/ol/service/SourceService.java index ae49f57..dc991a1 100644 --- a/src/main/java/com/gis3c/ol/service/SourceService.java +++ b/src/main/java/com/gis3c/ol/service/SourceService.java @@ -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 sourceIds); + + public Integer insertTestStation(TestStation testStation); + public List findTestStationList(); } diff --git a/src/main/java/com/gis3c/ol/service/impl/SourceServiceImpl.java b/src/main/java/com/gis3c/ol/service/impl/SourceServiceImpl.java index 6df34b7..502fa0e 100644 --- a/src/main/java/com/gis3c/ol/service/impl/SourceServiceImpl.java +++ b/src/main/java/com/gis3c/ol/service/impl/SourceServiceImpl.java @@ -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 sourceIds) { return sourceDao.deleteSourcesById(sourceIds); } + + @Override + public Integer insertTestStation(TestStation testStation) { + return sourceDao.insertTestStation(testStation); + } + + @Override + public List findTestStationList() { + return sourceDao.findTestStationList(); + } } diff --git a/src/main/java/com/gis3c/spatial/postgis/IntEnumTypeHandler.java b/src/main/java/com/gis3c/spatial/postgis/IntEnumTypeHandler.java new file mode 100644 index 0000000..1874579 --- /dev/null +++ b/src/main/java/com/gis3c/spatial/postgis/IntEnumTypeHandler.java @@ -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 & IntEnum> extends BaseTypeHandler { + private Class type; + + public IntEnumTypeHandler(Class 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()); + } +} diff --git a/src/test/java/com/gis3c/spatial/App.java b/src/test/java/com/gis3c/spatial/App.java index a56e8d7..76129ef 100644 --- a/src/test/java/com/gis3c/spatial/App.java +++ b/src/test/java/com/gis3c/spatial/App.java @@ -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 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 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 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); diff --git a/src/test/resources/mappings/ol/SourceDao.xml b/src/test/resources/mappings/ol/SourceDao.xml index 14a380a..49c779d 100644 --- a/src/test/resources/mappings/ol/SourceDao.xml +++ b/src/test/resources/mappings/ol/SourceDao.xml @@ -9,6 +9,12 @@ + + + + + + sourceId @@ -90,4 +96,18 @@ #{item, javaType=java.lang.String} + + + + INSERT INTO stationtest(stationid,stationname,stationstatus) + VALUES ( + #{stationId}, + #{stationName}, + #{stationStatus,jdbcType=BIT,javaType=IntEnum} + ); + + \ No newline at end of file diff --git a/src/test/resources/sql-map-config-mybatis.xml b/src/test/resources/sql-map-config-mybatis.xml index 1408add..19356e4 100644 --- a/src/test/resources/sql-map-config-mybatis.xml +++ b/src/test/resources/sql-map-config-mybatis.xml @@ -50,10 +50,12 @@ + + \ No newline at end of file