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

package com.persagy.server.datacenter.models.entities.task

import com.alibaba.fastjson.annotation.JSONField
import com.persagy.server.datacenter.models.entities.base.BaseInfo
import com.persagy.server.datacenter.models.entities.dict.EquipCategory
import com.persagy.server.datacenter.models.entities.objects.*
import com.persagy.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 EquipmentTaskTwo : BaseInfo() {

    /** 设备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 = "cad_id")
    @JSONField(name = "CADID")
    var cadId: String? = null

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

    /** 设备类型code */
    @ApiModelProperty(value = "设备类型code")
    @Column(name = "category")
    @JSONField(name = "Category")
    var category: String? = 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
        }

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

} // Class EquipmentTaskTwo