package com.persagy.proxy.object.model;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.persagy.proxy.adm.annotations.CascadeColumn;
import com.persagy.proxy.adm.model.AdmPoint;
import com.persagy.proxy.adm.model.AdmBaseEntity;
import com.persagy.proxy.dictionary.model.AdmObjectType;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import java.util.List;
import java.util.Map;

/**
 * ADM 设备 实体
 * @author lvxy
 * @date 2021/8/17
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class AdmEquipment extends AdmBaseEntity<AdmEquipment> {
    public static final String OBJ_TYPE = "equipment";
    /** 设备名称 */
    private String name;
    /** 本地编码 */
    private String localId;
    /** 本地名称 */
    private String localName;
    /** 二维码内容 */
    private String defaultQRCode;
    /** 设计图纸中编码 */
    //@JsonAlias({"cadId","cADID"})
//    @JsonProperty("cADID")
    private String cadId;
    /** 设计图纸中编码 */
    @JsonAlias({"cadId","cADID"})
    @JsonProperty("cADID")
    private String cADID;
    /** RFID标识 */
    @JSONField(name = "rFID")
    private String rfId;


    /** BIM模型中编码 */
    private String bimId;
    /** BIM构建编码 */
    private String bimTypeId;
    /** BIM模型中坐标 */
    private String bimLocation;
    /** 现场发现人员 */
    private String findPeople;

    /** 项目ID */
    private String projectId;
    /** 设备类型code */
    private String classCode;
    /** 设备所在建筑ID */
    private String buildingId;
    /** 设备所在楼层id */
    private String floorId;
    /** 设备关联的资产id */
    private String propertyId;

    /** 参见 EquipmentProSy **/
    /** 品牌型号id */
    private String dpManufacturerId;

    /** 供应商信息id */
    private String dpSupplierId;

    /** 维修商信息id */
    private String dpMaintainerId;

    /** 保险公司信息id */
    private String dpInsurerId;

    /** 设备型号id */
    private String dpSpecificationId;

    /** 品牌id */
    private String dpBrandId;



    /** Revit族 */
    private String bimFamilyName;
    /** Revit族类型 */
    private String bimFamilySymbol;
    /** 设备序号 */
    private String equipSerial;

    /** 部件关联设备的id */
    private String parentId;
    /** 系统id集合 */
    private List<String> systemList;
    /** 项目自定义类型 */
    private String customCategory;
    /** 任务状态 */
    private String taskState;
    /** 模型id */
    private String modelId;
    /** 贴码状态 */
    private String codeType  = "1";
    /** 备注 */
    private String note;

    /** 客户端id */
    private String appId;
    /** 方案id */
    private String schemeId;

    /** 系统编码 */
    private String systemCode;
    /** 系统名称 */
    private String systemName;
    /** 二维码图片 */
    private String qrcodePic;

    /** 对象类型 */
    private String objectType = OBJ_TYPE;
    /** 设备分类 */
    private Map<String, String> equipCategory;
    /** 更新的时候使用此字段保存楼层和建筑id */
    private String flowBuild;

    /** 资产信息实体类   资产对应设备设施关系 资产→设备设施*/
    @CascadeColumn(graphCode = "Property2Mech", relCode = "Pe2Eq", selectToObj = false)
    private AdmProperty property;
    /** 建筑信息实体类 */
    @CascadeColumn(graphCode = "MechInArch", relCode = "Eq2Bd")
    private AdmBuilding building;
    /** 楼层信息实体类 */
    @CascadeColumn(graphCode = "MechInArch", relCode = "Eq2Fl")
    private AdmFloor floor;
    /** 项目信息实体类 */
    @CascadeColumn(graphCode = "MechSubset", relCode = "Pj2Eq", selectToObj = false)
    private AdmProject project;
    /**BIM模型中坐标json，坐标x,y,z */
    private AdmPoint locationJson;
    public AdmPoint getLocationJson() {
        if (StrUtil.isNotEmpty(bimLocation)){
            String[] split = bimLocation.split(",");
            AdmPoint bimLocation = new AdmPoint();
            if (split.length == 3){
                bimLocation.setX(Double.valueOf(split[0]));
                bimLocation.setY(Double.valueOf(split[1]));
                bimLocation.setZ(Double.valueOf(split[2]));
            }else if (split.length == 2){
                bimLocation.setX(Double.valueOf(split[0]));
                bimLocation.setY(Double.valueOf(split[1]));
                bimLocation.setZ(0.0);
            }
            return bimLocation;
        }
        return null;
    }

    /** 级联-设备服务所在的空 */
    @CascadeColumn(graphCode = "MechForArch", relCode = "Eq2Sp")
    private List<AdmSpace> zoneSpaceForBase;
    /** 级联-设备服务所在的空 */
    @CascadeColumn(graphCode = "MechInArch", relCode = "Eq2Sp")
    private List<AdmSpace> zoneSpaceInBase;
    /** 级联-设备所在的竖井 */
    @CascadeColumn(graphCode = "MechInArch", relCode = "Eq2Sh")
    private List<AdmShaft> shaftList;
    /** 资产列表 */
    @CascadeColumn(graphCode = "Property2Mech", relCode = "Pe2Eq", selectToObj = false)
    private List<AdmProperty> propertyList;
    /** 级联-部件 */
    @CascadeColumn(graphCode = "MechSubset", relCode = "Eq2Ec")
    private List<AdmComponent> component;

    /******************************** 报表使用 **************************************/
    /** 资产id */
    @Column(name = "link_id")
    private String linkId;

    /** 资产名称 */
    @Column(name = "link_name")
    private String linkEquipName;

    /** 资产本地名称 */
    @Column(name = "link_local_name")
    private String linkEquipLocalName;

    /** 资产分类 */
    @Column(name = "link_family")
    private String linkFamily;

    /** 系统对象 */
    @CascadeColumn(graphCode = "MechSubset", relCode = "Sy2Eq", selectToObj = false)
    private List<AdmSystem> linkSystem;

    /** 部件数量 */
    private Integer count = 0;

    /** 级联-部件   table  对应关系表   idColumn 对应 本类的id    childIdColumn 级联对象的关系id */
    //@CascadeColumn(table="equipment", idColumn="class_code", childIdColumn="parent_id")
    private List<AdmObjectType> componentCategory;

    /** 类型名称 */
    private String codeName;

}
