Station.java 8.17 KB
package com.bsth.entity;

import com.bsth.util.Geo.Point;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.annotations.Formula;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.WKBReader;

import javax.persistence.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;


/**
 * 
 * @ClassName : Station(站点实体类)
 * 
 * @Author : bsth@lq
 * 
 * @Description : TODO(站点)
 * 
 * @Data :2016-04-19
 *
 * @Version 公交调度系统BS版 0.1
 * 
 */

@Entity
@Table(name = "bsth_c_station")
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"})
public class Station {
	
	@Id
//	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	
	// 站点编码
	private String stationCod;
	
	// 站点名称
	private String stationName;
	 
	// 所在道路编码
	private String roadCoding;
	
	// 站点的具体地址
	private String addr;
	
	/**
	 * 经纬坐标类型 
	 * 
	 * --------- b:百度坐标系
	 * 
	 * --------- d:高德坐标系
	 */
	private String dbType;
	
	// 百度经纬度坐标
	private String bJwpoints;
	
	// 站点地理位置WGS坐标经度
	private Float gLonx;
	
	// 站点地理位置WGS坐标纬度
	private Float gLaty;
	
	// 城建坐标 x
	private Float x;
	
	// 城建坐标 y
	private Float y;
	
	/**
	 * 图形类型
	 * 
	 * ------ r:圆形
	 * 
	 * ------ p:多边形
	 */
	private String shapesType;
	
	// 圆形半径
	private Integer radius;
	
	// 多边形空间WGS坐标点集合
	private byte[] gPolygonGrid;
	
	// 多边形空间原坐标坐标点集合
	private byte[] bPolygonGrid;

	@Transient
	private String bdPolygon;
	
	/**
	 * 是否撤销
	 * 
	 * ------ 1:撤销
	 * 
	 * ------ 0:不撤销
	 */
	private Integer destroy; 
	
	// 版本号
	private Integer versions;
	
	/** 是否有电子站牌 这里是老调度系统的原始字段,暂时保留该字段。 */
	private Integer isHaveLed;
	
	/** 是否有候车亭  这里是老调度系统的原始字段,暂时保留该字段。*/
	private Integer isHaveShelter;
	
	/** 是否港湾式公交站  这里是老调度系统的原始字段,暂时保留该字段。*/
	private Integer isHarbourStation;
	
	// 描述
	private String descriptions;
	
	// 创建人
	private Integer createBy;
	
	// 修改人
	private Integer updateBy;
	
	// 创建日期
	@Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
	private Date createDate;
	
	// 修改日期
	@Column(name = "update_date", columnDefinition = "timestamp  DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
	private Date updateDate;
	
	public Integer getIsHaveLed() {
		return isHaveLed;
	}

	public void setIsHaveLed(Integer isHaveLed) {
		this.isHaveLed = isHaveLed;
	}

	public Integer getIsHaveShelter() {
		return isHaveShelter;
	}

	public void setIsHaveShelter(Integer isHaveShelter) {
		this.isHaveShelter = isHaveShelter;
	}

	public Integer getIsHarbourStation() {
		return isHarbourStation;
	}

	public void setIsHarbourStation(Integer isHarbourStation) {
		this.isHarbourStation = isHarbourStation;
	}

	public String getAddr() {
		return addr;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getStationCod() {
		return stationCod;
	}

	public void setStationCod(String stationCod) {
		this.stationCod = stationCod;
	}

	public String getStationName() {
		return stationName;
	}

	public void setStationName(String stationName) {
		this.stationName = stationName;
	}

	public String getRoadCoding() {
		return roadCoding;
	}

	public void setRoadCoding(String roadCoding) {
		this.roadCoding = roadCoding;
	}

	public String getDbType() {
		return dbType;
	}

	public void setDbType(String dbType) {
		this.dbType = dbType;
	}
	
	public String getbJwpoints() {
		return bJwpoints;
	}

	public void setbJwpoints(String bJwpoints) {
		this.bJwpoints = bJwpoints;
	}

	public Float getgLonx() {
		return gLonx;
	}

	public void setgLonx(Float gLonx) {
		this.gLonx = gLonx;
	}

	public Float getgLaty() {
		return gLaty;
	}

	public void setgLaty(Float gLaty) {
		this.gLaty = gLaty;
	}

	public Float getX() {
		return x;
	}

	public void setX(Float x) {
		this.x = x;
	}

	public Float getY() {
		return y;
	}

	public void setY(Float y) {
		this.y = y;
	}

	public String getShapesType() {
		return shapesType;
	}

	public void setShapesType(String shapesType) {
		this.shapesType = shapesType;
	}

	public Integer getRadius() {
		return radius;
	}

	public void setRadius(Integer radius) {
		this.radius = radius;
	}

	public byte[] getgPolygonGrid() {
		return gPolygonGrid;
	}

	public void setgPolygonGrid(byte[] gPolygonGrid) {
		this.gPolygonGrid = gPolygonGrid;
	}
	
	public byte[] getbPolygonGrid() {
		return bPolygonGrid;
	}

	public void setbPolygonGrid(byte[] bPolygonGrid) {
		this.bPolygonGrid = bPolygonGrid;
	}

	public String getBdPolygon() {
		if (bPolygonGrid == null) {
			return null;
		}
		Geometry geometry = getGeometryFromBytes(getbPolygonGrid());
		if (geometry == null) {
			return null;
		}
		return geometry.toString();
	}

	public Integer getDestroy() {
		return destroy;
	}

	public void setDestroy(Integer destroy) {
		this.destroy = destroy;
	}

	public Integer getVersions() {
		return versions;
	}

	public void setVersions(Integer versions) {
		this.versions = versions;
	}

	public String getDescriptions() {
		return descriptions;
	}

	public void setDescriptions(String descriptions) {
		this.descriptions = descriptions;
	}

	public Integer getCreateBy() {
		return createBy;
	}

	public void setCreateBy(Integer createBy) {
		this.createBy = createBy;
	}

	public Integer getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(Integer updateBy) {
		this.updateBy = updateBy;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	private static Geometry getGeometryFromBytes(byte[] geometryAsBytes) {
		Geometry geometry = null;
		try {
			// 字节数组小于5,说明geometry有问题
			if (geometryAsBytes.length < 5) {
				throw new Exception("Invalid geometry inputStream - less than five bytes");
			}

			//first four bytes of the geometry are the SRID,
			//followed by the actual WKB.  Determine the SRID
			//这里是取字节数组的前4个来解析srid
			byte[] sridBytes = new byte[4];
			System.arraycopy(geometryAsBytes, 0, sridBytes, 0, 4);
			boolean bigEndian = (geometryAsBytes[4] == 0x00);
			// 解析srid
			int srid = 0;
			if (bigEndian) {
				for (int i = 0; i < sridBytes.length; i++) {
					srid = (srid << 8) + (sridBytes[i] & 0xff);
				}
			} else {
				for (int i = 0; i < sridBytes.length; i++) {
					srid += (sridBytes[i] & 0xff) << (8 * i);
				}
			}

			//use the JTS WKBReader for WKB parsing
			WKBReader wkbReader = new WKBReader();
			// 使用geotool的WKBReader 把字节数组转成geometry对象。
			//copy the byte array, removing the first four
			//SRID bytes
			byte[] wkb = new byte[geometryAsBytes.length - 4];
			System.arraycopy(geometryAsBytes, 4, wkb, 0, wkb.length);
			geometry = wkbReader.read(wkb);
			geometry.setSRID(srid);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return geometry;
	}

	@Override
	public String toString() {
		return "Station [id=" + id + ", stationCod=" + stationCod + ", stationName=" + stationName + ", roadCoding="
				+ roadCoding + ", addr=" + addr + ", dbType=" + dbType + ", bJwpoints=" + bJwpoints + ", gLonx=" + gLonx
				+ ", gLaty=" + gLaty + ", x=" + x + ", y=" + y + ", shapesType=" + shapesType + ", radius=" + radius
				+ ", gPolygonGrid=" + Arrays.toString(gPolygonGrid) + ", bPolygonGrid=" + Arrays.toString(bPolygonGrid)
				+ ", destroy=" + destroy + ", versions=" + versions + ", isHaveLed=" + isHaveLed + ", isHaveShelter="
				+ isHaveShelter + ", isHarbourStation=" + isHarbourStation + ", descriptions=" + descriptions
				+ ", createBy=" + createBy + ", updateBy=" + updateBy + ", createDate=" + createDate + ", updateDate="
				+ updateDate + "]";
	}
	
}