/*
 * ********************************************************************************************************************
 *
 *                     :*$@@%$*:                         ;:                ;;    ;;
 *                   :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
 *                  :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
 *                  =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
 *                  =@*                                  %!              @ $= % %@=   =%@!      %=
 *             *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
 *           %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
 *         ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
 *         $@*   ;@@@%=!:                *@*
 *         =@$    ;;;!=%@@@@=!           =@!
 *          %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
 *           ;%@@$=$@@%*       *@@@$=%@@%;
 *              ::;::             ::;::                                              All rights reserved.
 *
 * ********************************************************************************************************************
 */

package cn.sagacloud.server.datacenter.models.entities

import cn.sagacloud.server.datacenter.models.entities.base.BaseInfo
import cn.sagacloud.server.datacenter.models.entities.task.SchemeUtils
import com.alibaba.fastjson.annotation.JSONField
import com.sybotan.service.models.annotations.SCascade
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty
import javax.persistence.Column
import javax.persistence.Id
import javax.persistence.Table

/**
 * 资产信息实体类
 *
 * @author  张维新
 */
@ApiModel(description = "资产信息实体类")
@Table(name = "property")
open class Property : BaseInfo(),Comparator<Property> {

    /** 资产id */
    @ApiModelProperty(value = "资产id", required = true)
    @Id
    @Column(name = "id")
    @JSONField(name = "EquipID")
    var id: String? = null

    /** 资产名称 */
    @ApiModelProperty(value = "资产名称", required = true)
    @Column(name = "name")
    @JSONField(name = "EquipName")
    var name: String? = null

    /** 资产本地编码 */
    @ApiModelProperty(value = "资产本地编码")
    @Column(name = "local_id")
    @JSONField(name = "EquipLocalID")
    var localId: String? = null

    /** 资产本地名称 */
    @ApiModelProperty(value = "资产本地名称")
    @Column(name = "local_name")
    @JSONField(name = "EquipLocalName")
    var localName: String? = null

    /** 资产二维码照片 */
    @ApiModelProperty(value = "资产二维码照片")
    @Column(name = "qr_code")
    @JSONField(name = "EquipQRCode")
    var qrCode: String? = null

    /** 设计图纸中编码 */
    @ApiModelProperty(value = "设计图纸中编码")
    @Column(name = "cad_id")
    @JSONField(name = "CADID")
    var cadId: String? = null

    /** BIM模型中编码 */
    @ApiModelProperty(value = "BIM模型中编码")
    @Column(name = "bim_id")
    @JSONField(name = "BIMID")
    var bimId: String? = null

    /** BIM模型中坐标 */
    @ApiModelProperty(value = "BIM模型中坐标")
    @Column(name = "bim_location")
    @JSONField(name = "BIMLocation")
    var bimLocation: String? = null


    /** BIM模型中坐标 */
    @ApiModelProperty(value = "BIM模型中坐标json")
    @JSONField(name = "LocationJson")
    var locationJson: BIMLocation? = null
        get() {
            if (!bimLocation.isNullOrEmpty()){

                val split = bimLocation!!.split(",")
                var bimLocation = BIMLocation()
                if (split.size == 3){
                    bimLocation!!.x = split[0].toDouble()
                    bimLocation!!.y = split[1].toDouble()
                    bimLocation!!.z = split[2].toDouble()
                }else if (split.size == 2){

                    bimLocation!!.x = split[0].toDouble()
                    bimLocation!!.y = split[1].toDouble()
                    bimLocation!!.z = 0.0
                }
                return bimLocation
            }
            return null
        }

    /** 项目id */
    @ApiModelProperty(value = "项目id", required = true)
    @Column(name = "project_id")
    @JSONField(name = "ProjectId")
    var projectId: String? = null

    /** 资产类型code */
    @ApiModelProperty(value = "资产类型code")
    @Column(name = "family")
    @JSONField(name = "Family")
    var family: String? = null

    /** 资产所在建筑id */
    @ApiModelProperty(value = "资产所在建筑id")
    @Column(name = "building_id")
    @JSONField(name = "BuildingId")
    var buildingId: String? = null

    /** 资产所在楼层id */
    @ApiModelProperty(value = "资产所在楼层id")
    @Column(name = "floor_id")
    @JSONField(name = "FloorId")
    var floorId: String? = null

    /** 资产关联设备id */
    @ApiModelProperty(value = "关联的设备或部件")
    @Column(name = "equip_id")
    @JSONField(name = "EquipmentId")
    var equipId: String? = null

    /** 品牌型号id */
    @ApiModelProperty(value = "品牌型号id")
    @Column(name = "dp_manufacturer_id")
    @JSONField(name = "DPManufacturerID")
    var dpManufacturerID: String? = null

    /** 供应商信息id */
    @ApiModelProperty(value = "供应商信息id")
    @Column(name = "dp_supplier_id")
    @JSONField(name = "DPSupplierID")
    var dpSupplierID: String? = null

    /** 维修商信息id */
    @ApiModelProperty(value = "维修商信息id")
    @Column(name = "dp_maintainer_id")
    @JSONField(name = "DPMaintainerID")
    var dpMaintainerID: String? = null

    /** 保险公司信息id */
    @ApiModelProperty(value = "保险公司信息id")
    @Column(name = "dp_insurer_id")
    @JSONField(name = "DPInsurerID")
    var dpInsurerID: String? = null

    /** 设备型号id */
    @ApiModelProperty(value = "设备型号id")
    @Column(name = "dp_specification_id")
    @JSONField(name = "DPSpecificationID")
    var dpSpecificationID: String? = null

    /** 品牌id */
    @ApiModelProperty(value = "品牌id")
    @Column(name = "dp_brand_id")
    @JSONField(name = "DPBrandID")
    var dpBrandID: String? = null

    /** 设备序号 */
    @ApiModelProperty(value = "设备序号 ")
    @Column(name = "equip_serial")
    @JSONField(name = "EquipSerial")
    var equipSerial: String? = null

    /** 任务状态 待验证1、已验证0、未找到-1  */
    @ApiModelProperty(value = "任务状态-待验证1、已验证0、未找到-1")
    @Column(name = "task_state")
    @JSONField(name = "TaskState")
    var taskState: Int? = null

    /** 台账参数 */
    @ApiModelProperty(value = "台账参数")
    @Column(name = "ledger_param")
    @JSONField(name = "LedgerParam")
    var ledgerParam: HashMap<String, Any?>? = null

    /** 通讯参数 */
    @ApiModelProperty(value = "通讯参数")
    @Column(name = "comm_param")
    @JSONField(name = "CommParam")
    var commParam: HashMap<String, Any?>? = null

    /** 技术参数 */
    @ApiModelProperty(value = "技术参数")
    @Column(name = "tech_param")
    @JSONField(name = "TechParam")
    var techParam: HashMap<String, Any?>? = null

    /** 运行参数 */
    @ApiModelProperty(value = "运行参数")
    @Column(name = "run_param")
    @JSONField(name = "RunParam")
    var runParam: HashMap<String, Any?>? = null

    /** 设定参数 */
    @ApiModelProperty(value = "设定参数")
    @Column(name = "setting_param")
    @JSONField(name = "SettingParam")
    var settingParam: HashMap<String, Any?>? = null

    /** 报警信息 */
    @ApiModelProperty(value = "报警信息")
    @Column(name = "alram")
    @JSONField(name = "Alram")
    var alram: HashMap<String, Any?>? = null

    /** 自定义 */
    @ApiModelProperty(value = "自定义")
    @Column(name = "custom_param")
    @JSONField(name = "CustomParam")
    var customParam: HashMap<String, Any?>? = null

    /** 设备部件标志位，1设备，2部件 */
    @ApiModelProperty(value = "1设备，2部件")
    @Column(name = "type")
    @JSONField(name = "Type")
    var type: String? = null

    /** 温度传感器 */
    @ApiModelProperty(value = "温度传感器")
    @Column(name = "temp_sensor")
    @JSONField(name = "TempSensor")
    var tempSensor: HashMap<String,Any?>? = null

    /** 技术参数-通用 */
    @ApiModelProperty(value = "技术参数-通用")
    @Column(name = "tech_param_general")
    @JSONField(name = "TechParamGeneral")
    var techParamGeneral: HashMap<String,Any?>? = null

    /** 运行参数-通用 */
    @ApiModelProperty(value = "运行参数-通用")
    @Column(name = "run_param_general")
    @JSONField(name = "RunParamGeneral")
    var runParamGeneral: HashMap<String,Any?>? = null

    /** 速度传感器 */
    @ApiModelProperty(value = "速度传感器")
    @Column(name = "speed_sensor")
    @JSONField(name = "SpeedSensor")
    var speedSensor: HashMap<String,Any?>? = null

    /** 声音传感器 */
    @ApiModelProperty(value = "声音传感器")
    @Column(name = "sound_sensor")
    @JSONField(name = "SoundSensor")
    var soundSensor: HashMap<String,Any?>? = null

    /** 湿度传感器 */
    @ApiModelProperty(value = "湿度传感器")
    @Column(name = "humidity_sensor")
    @JSONField(name = "HumiditySensor")
    var humiditySensor: HashMap<String,Any?>? = null

    /** 压力传感器 */
    @ApiModelProperty(value = "压力传感器")
    @Column(name = "press_transd")
    @JSONField(name = "PressTransd")
    var pressTransd: HashMap<String,Any?>? = null

    /** 热量传感器 */
    @ApiModelProperty(value = "热量传感器")
    @Column(name = "heat_sensor")
    @JSONField(name = "HeatSensor")
    var heatSensor: HashMap<String,Any?>? = null

    /** 流量传感器 */
    @ApiModelProperty(value = "流量传感器")
    @Column(name = "flow_sensor")
    @JSONField(name = "FlowSensor")
    var flowSensor: HashMap<String,Any?>? = null

    /** 电度传感器 */
    @ApiModelProperty(value = "电度传感器")
    @Column(name = "electricity_sensor")
    @JSONField(name = "ElectricitySensor")
    var electricitySensor: HashMap<String,Any?>? = null

    /** 位移传感器 */
    @ApiModelProperty(value = "位移传感器")
    @Column(name = "displ_sensor")
    @JSONField(name = "DisplSensor")
    var displSensor: HashMap<String,Any?>? = null

    /** 浓度传感器 */
    @ApiModelProperty(value = "浓度传感器")
    @Column(name = "concent_sensor")
    @JSONField(name = "ConcentSensor")
    var concentSensor: HashMap<String,Any?>? = null

    /** 图像传感器 */
    @ApiModelProperty(value = "图像传感器")
    @Column(name = "image_sensor")
    @JSONField(name = "ImageSensor")
    var imageSensor: HashMap<String,Any?>? = null

    /** 对象类型 */
    @ApiModelProperty(value = "对象类型")
    @Column(name = "object_type")
    @JSONField(name = "ObjectType")
    override var objectType: String? = "Property"

    /** 反馈参数 */
    @ApiModelProperty(value = "反馈参数")
    @Column(name = "feedback_param")
    @JSONField(name = "FeedbackParam")
    var feedbackParam: HashMap<String,Any?>? = null

    /** 人流量传感器 */
    @ApiModelProperty(value = "人流量传感器")
    @Column(name = "man_flow_sensor")
    @JSONField(name = "ManFlowSensor")
    var manFlowSensor: HashMap<String,Any?>? = null

    /** 位置信息 */
    @ApiModelProperty(value = "位置信息")
    @Column(name = "position")
    @JSONField(name = "Position")
    var position: String? = null

    /** 贴码状态 */
    @ApiModelProperty(value = "贴码状态")
    @Column(name = "code_type")
    @JSONField(name = "CodeType")
    var codeType: Int? = null

    /** 选择状态 */
    @ApiModelProperty(value = "选择状态")
    @Column(name = "checked")
    @JSONField(name = "Checked")
    var checked: Boolean? = null

    /** 空间id */
    @ApiModelProperty(value = "空间id")
    @Column(name = "space_id")
    @JSONField(name = "SpaceId")
    var spaceId: String? = null

    /** 备注 */
    @ApiModelProperty(value = "备注")
    @Column(name = "note")
    @JSONField(name = "Note")
    var note: Boolean? = null

    /** 点位id */
    @ApiModelProperty(value = "点位id")
    @Column(name = "point_id")
    @JSONField(name = "PointId")
    var pointId: String? = null

    /** 区分是哪里创建的资产 app  ,web */
    @ApiModelProperty(value = "区分是哪里创建的资产 app  ,web")
    @Column(name = "source")
    @JSONField(name = "Source")
    var source: String? = null

    /** 模型文件id */
    @ApiModelProperty(value = "模型文件id")
    @Column(name = "model_id")
    @JSONField(name = "ModelId")
    var modelId: String? = null

    @ApiModelProperty(value = "方案id")
//    @Column(name = "scheme_id")
    @JSONField(name = "SchemeId")
    var schemeId: String? = null
        get() {
            if (!family.isNullOrEmpty()){
                return SchemeUtils.setScheme(family!!)
            }
            return null
        }

    /** 设备 */
    @ApiModelProperty(value = "级联-设备")
    @SCascade(table="property", idColumn="id", childIdColumn="equip_id")
    @JSONField(name = "Equipment")
    var equipment: Equipment? = null

    /** 建筑   table  对应关系表   idColumn 对应 本类的id    childIdColumn 级联对象的关系id */
    @ApiModelProperty(value = "级联-建筑")
    @SCascade(table="property", idColumn="id", childIdColumn="building_id")
    @JSONField(name = "Building")
    var building: Building? = null

    /** 级联-楼层   table  对应关系表   idColumn 对应 本类的id    childIdColumn 级联对象的关系id */
    @ApiModelProperty(value = "级联-楼层")
    @SCascade(table="property", idColumn="id", childIdColumn="floor_id")
    @JSONField(name = "Floor")
    var floor: Floor? = null

    /** 级联-项目 */
    @ApiModelProperty(value = "级联-项目")
    @SCascade(table="property", idColumn="id", childIdColumn="project_id")
    @JSONField(name = "Project")
    var project: Project? = null

    /** 级联-资产设备族 */
    @ApiModelProperty(value = "级联-资产设备族")
    @SCascade(table="property", idColumn="id", childIdColumn="family")
    @JSONField(name = "EquipFamilyList")
    var equipFamilyList: ArrayList<EquipFamilyCategory>? = null

    /** 级联-资产设备族名称 */
    @ApiModelProperty(value = "级联-资产设备族名称")
    @SCascade(table="property", idColumn="id", childIdColumn="family")
    @JSONField(name = "FamilyName")
    var familyName: Family? = null

    /** 级联-资产所在的空间的 */
    @ApiModelProperty(value = "级联-设备所在的空间的")
    @SCascade(table="r_pe_in_sp_base", idColumn="equip_id", childIdColumn="space_id")
    @JSONField(name = "ZoneSpaceBaseIn")
    var zoneSpaceInBase: ArrayList<ZoneSpaceBaseTable>? = null

    /** 距离*/
    @ApiModelProperty(value = "距离")
    @JSONField(name = "Distance")
    var distance: Double? = null

    override fun compare(o1: Property?, o2: Property?): Int {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        if (o1!!.distance!=null&&o2!!.distance!=null&&o1!!.distance!!>o2.distance!!){
            return 1
        }else{
            -1
        }
    }

} // Class Property