/*
 * ********************************************************************************************************************
 *
 *                     :*$@@%$*:                         ;:                ;;    ;;
 *                   :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
 *                  :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
 *                  =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
 *                  =@*                                  %!              @ $= % %@=   =%@!      %=
 *             *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
 *           %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
 *         ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
 *         $@*   ;@@@%=!:                *@*
 *         =@$    ;;;!=%@@@@=!           =@!
 *          %@$:      =@%: :*@@@*       %@=                    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 = "equipment")
open class Equipment : BaseInfo() {


    /** 设备id */
    @ApiModelProperty(value = "设备id",required = true)
    @Id
    @Column(name = "id")
    @JSONField(name = "EquipID")
//    @JsonProperty("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_type_id")
    @JSONField(name = "BIMTypeID")
    var bimTypeId: String? = null

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

    /** BIM模型中坐标 */
    @ApiModelProperty(value = "BIM模型中坐标json")
//    @Column(name = "location_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 = "category")
    @JSONField(name = "Category")
    var category: 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 = "设备关联的资产id")
    @Column(name = "property_id",insertable = false,updatable = false )
    @JSONField(name = "PropertyId")
    var propertyId: String? = null

    /** Revit族 */
    @ApiModelProperty(value = "Revit族 ")
    @Column(name = "family_name")
    @JSONField(name = "BIMFamilyName")
    var familyName: String? = null

    /** Revit族类型 */
    @ApiModelProperty(value = "Revit族类型 ")
    @Column(name = "family_symbol")
    @JSONField(name = "BIMFamilySymbol")
    var familySymbol: String? = null

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

    /** 生产厂家ID */  //生产商的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 = "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

    /** 部件关联设备id */
    @ApiModelProperty(value = "部件关联设备id")
    @Column(name = "parent_id")
    @JSONField(name = "ParentId")
    var parentId: 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",serialize = false )
    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

    /** 系统id集合 */
    @ApiModelProperty(value = "系统id集合")
    @JSONField(name = "SystemList")
    var systemList: List<String>? = null

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

    /** 项目自定义类型 */
    @ApiModelProperty(value = "项目自定义类型")
    @Column(name = "custom_category")
    @JSONField(name = "CustomCategory")
    var customCategory: String? = null

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

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

    /** 反馈参数 */
    @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 = "code_type")
    @JSONField(name = "CodeType")
    var codeType: Int? = null

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

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

    /** 资产 */
    @ApiModelProperty(value = "级联-资产")
    @SCascade(table="property", idColumn="equip_id", childIdColumn="id")
    @JSONField(name = "Property")
    var property: Property? = null

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

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

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

    /** 级联-设备分类 */
    @ApiModelProperty(value = "级联-设备分类")
    @SCascade(table="equipment", idColumn="id", childIdColumn="category")
    @JSONField(name = "EquipCategory")
    var equipCategory: EquipCategory? = null

    /** 级联-设备服务的空间的 */
    @ApiModelProperty(value = "级联-设备服务的空间的")
    @SCascade(table="relationship.r_eq2sp", idColumn="eq_id", childIdColumn="sp_id",filter = "type = 'eq2sp_for'")
    @JSONField(name = "ZoneSpaceBaseFor")
    var zoneSpaceForBase: ArrayList<ZoneSpace>? = null

    /** 级联-设备所在的空间的 */
    @ApiModelProperty(value = "级联-设备所在的空间的")
    @SCascade(table="relationship.r_eq2sp", idColumn="eq_id", childIdColumn="sp_id",filter = "type = 'eq2sp_in'")
    @JSONField(name = "ZoneSpaceBaseIn")
    var zoneSpaceInBase: ArrayList<ZoneSpace>? = null

    /** 级联-设备所在的竖井 */
    @ApiModelProperty(value = "级联-设备所在的竖井")
    @SCascade(table="r_eq_in_sh", idColumn="equip_id", childIdColumn="shaft_id")
    @JSONField(name = "ShaftList")
    var shaftList: ArrayList<Shaft>? = null

    /** 资产列表 */
    @ApiModelProperty(value = "资产列表")
    @JSONField(name = "PropertyList")
    var propertyList: ArrayList<Property>? = null

    /** 级联-部件   table  对应关系表   idColumn 对应 本类的id    childIdColumn 级联对象的关系id */
    @ApiModelProperty(value = "级联-部件")
    @SCascade(table="equipment", idColumn="parent_id", childIdColumn="id")
    @JSONField(name = "Component")
    var component: ArrayList<Equipment>? = null

    /** 转换后的信息点 */
    @Column(name = "infos")
    var infos: Map<String,Any?>? = null

} // Class Equipment