package com.sysu.admin.controller.geo.qyz;

import com.alibaba.fastjson.annotation.JSONField;
import com.sysu.admin.utils.shape.GeoCastUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.locationtech.jts.geom.MultiPolygon;

import javax.persistence.*;

@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@FieldNameConstants(innerTypeName = "FIELDS")
@Table(name = "\"qy-z\"")
@Entity
@DynamicInsert
@DynamicUpdate
public class Qyz {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer gid;

    @Column(name = "pac")
    private Integer pac;

    @Column(name = "name")
    private String name;

    @JSONField(serialize = false)
    @Column(columnDefinition = "geom")
    private MultiPolygon geom;

    @Transient
    private String wkt;
    public String getWkt(){
        if(wkt == null && this.geom != null){
            this.wkt = GeoCastUtil.geomToWkt(this.geom);
        }
        return this.wkt;
    }

}
