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

import com.alibaba.fastjson.annotation.JSONField
import com.persagy.server.datacenter.models.entities.assistant.BIMLocation
import com.persagy.server.datacenter.models.entities.assistant.TaskPic
import com.persagy.server.datacenter.models.entities.base.RBaseInfo
import com.persagy.server.datacenter.models.entities.dict.EquipCategory
import com.persagy.server.datacenter.models.entities.objects.Building
import com.persagy.server.datacenter.models.entities.objects.Floor
import com.persagy.server.datacenter.models.entities.objects.Project
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 = "scantask.model_scan_task")
class ModelScanTaskQuery : RBaseInfo() {

    /** 任务id */
    @ApiModelProperty(value = "任务id")
    @Id
    @Column(name = "id")
    @JSONField(name = "TaskId")
    var id: String? = null

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

    /** 设备或部件或资产名称 */
    @ApiModelProperty(value = "设备或部件或资产名称")
    @Column(name = "equip_name")
    @JSONField(name = "EquipName")
    var equipName: 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

    /** BIM模型中编码 */
    @ApiModelProperty(value = "BIM模型中编码")
    @Column(name = "bim_id")
    @JSONField(name = "BIMID")
    var bimId: String? = 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

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

    /** 安装位置 */
    @ApiModelProperty(value = "安装位置")
    @Column(name = "install_location")
    @JSONField(name = "InstallLocation")
    var installLocation: String? = null

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

    /** 方案id */
    @ApiModelProperty(value = "方案id")
    @Column(name = "scheme_id")
    @JSONField(name = "SchemeId")
    var schemeId: String? = null

    /** 执行人 */
    @ApiModelProperty(value = "执行人")
    @Column(name = "worker_id")
    @JSONField(name = "WorkerId")
    var workerId: String? = null

    /** 执行人名称 */
    @ApiModelProperty(value = "执行人名称")
    @Column(name = "worker_name")
    @JSONField(name = "WorkerName")
    var workerName: String? = null

    /** 任务执行时间 */
    @ApiModelProperty(value = "任务执行时间", example = "2017-10-15 08:30:00")
    @Column(name = "process_time")
    @JSONField(name = "ProcessTime")
    var processTime: String? = null

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

    /** 图片视频列表 */
    @ApiModelProperty(value = "图片视频列表")
    @Column(name = "task_pic_list")
    @JSONField(name = "TaskPicList")
    var taskPicList: java.util.ArrayList<TaskPic>? = null

    /** 任务数据源  模型1 ，设备2，资产3 */
    @ApiModelProperty(value = "任务数据源 模型1 ，设备2，资产3,部件4 ")
    @Column(name = "task_source")
    @JSONField(name = "TaskSource")
    var taskSource: Int? = null

    /** 任务类型 - 资产的撕贴换码状态 */
    @ApiModelProperty(value = "任务类型 - 资产的撕贴换码状态 换码 2   撕码 3")
    @Column(name = "task_type")
    @JSONField(name = "TaskType")
    var taskType: String? = null

    /** 是否找到时间 */
    @ApiModelProperty(value = "是否找到时间")
    @Column(name = "is_find_time")
    @JSONField(name = "IsFindTime")
    var isFindTime: String? = null

    /** 确认信息时间 */
    @ApiModelProperty(value = "确认信息时间")
    @Column(name = "confirm_time")
    @JSONField(name = "ConfirmTime")
    var confirmTime: String? = null

    /** 打印二维码时间 */
    @ApiModelProperty(value = "打印二维码时间")
    @Column(name = "qr_code_time")
    @JSONField(name = "QrCodeTime")
    var qrCodeTime: String? = null

    /** 补充铭牌照片时间 */
    @ApiModelProperty(value = "补充铭牌照片时间")
    @Column(name = "nameplate_time")
    @JSONField(name = "NameplateTime")
    var nameplateTime: String? = null

    /** 正面照片时间 */
    @ApiModelProperty(value = "正面照片时间")
    @Column(name = "positive_photo_time")
    @JSONField(name = "PositivePhotoTime")
    var positivePhotoTime: String? = null

    /** 侧面照片时间 */
    @ApiModelProperty(value = "侧面照片时间")
    @Column(name = "side_photo_time")
    @JSONField(name = "SidePhotoTime")
    var sidePhotoTime: String? = null

    /** 局部照片时间 */
    @ApiModelProperty(value = "局部照片时间")
    @Column(name = "region_photo_time")
    @JSONField(name = "RegionPhotoTime")
    var regionPhotoTime: String? = null

    /** 全景照片 */
    @ApiModelProperty(value = "全景照片")
    @Column(name = "panoramic_photo_time")
    @JSONField(name = "PanoramicPhotoTime")
    var panoramicPhotoTime: String? = null

    /** 视频时间 */
    @ApiModelProperty(value = "视频时间")
    @Column(name = "video_time")
    @JSONField(name = "VideoTime")
    var videoTime: String? = null

    /** 设备问题时间 */
    @ApiModelProperty(value = "设备问题时间")
    @Column(name = "equip_problem_time")
    @JSONField(name = "EquipProblemTime")
    var equipProblemTime: String? = null

    /** 设备问题 */
    @ApiModelProperty(value = "设备问题")
    @Column(name = "equip_problem")
    @JSONField(name = "EquipProblem")
    var equipProblem: String? = null

    /** 补充说明时间 */
    @ApiModelProperty(value = "补充说明时间")
    @Column(name = "explain_time")
    @JSONField(name = "ExplainTime")
    var explainTime: String? = null

    /** 生产厂家 */
    @ApiModelProperty(value = "生产厂家")
    @Column(name = "manufacturer")
    @JSONField(name = "Manufacturer")
    var manufacturer: String? = null

    /** 型号 */
    @ApiModelProperty(value = "型号")
    @Column(name = "specification")
    @JSONField(name = "Specification")
    var specification: String? = null

    /** 供应商 */
    @ApiModelProperty(value = "供应商")
    @Column(name = "supplier")
    @JSONField(name = "Supplier")
    var supplier: String? = null

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

    /** 任务确认人员名 */
    @ApiModelProperty(value = "任务确认人员名")
    @Column(name = "confirming_person_name")
    @JSONField(name = "ConfirmingPersonName")
    var confirmingPersonName: String? = null

    /** 任务确认人id */
    @ApiModelProperty(value = "任务确认人id")
    @Column(name = "confirming_person_id")
    @JSONField(name = "ConfirmingPersonId")
    var confirmingPersonId: 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")
    @Column(name = "folder_id")
    @JSONField(name = "FolderId")
    var folderId: String? = null

    /** 文件夹名 */
    @ApiModelProperty(value = "文件夹名")
    @Column(name = "folder_name")
    @JSONField(name = "FolderName")
    var folderName: String? = null

    /** 文件id */
    @ApiModelProperty(value = "文件id")
    @Column(name = "file_id")
    @JSONField(name = "FileId")
    var fileId: String? = null

    /** 文件名 */
    @ApiModelProperty(value = "文件名")
    @Column(name = "file_name")
    @JSONField(name = "FileName")
    var fileName: String? = null

    /** 父类id */
    @ApiModelProperty(value = "父类id")
    @Column(name = "parent_id")
    @Id
    @JSONField(name = "ParentId")
    var parentId: String? = null

    @ApiModelProperty(value = "部件指向父类设备任务id")
    @Column(name = "task_parent_id")
    @JSONField(name = "TaskParentId")
    var taskParentId: String? = null

    /** 级联-项目   table  对应关系表   idColumn 对应 本类的id    childIdColumn 级联对象的关系id */
    @ApiModelProperty(value = "级联-项目")
    @SCascade(table="scantask.model_scan_task", idColumn="id", childIdColumn="project_id")
    @JSONField(name = "Project")
    var project: Project? = null

    /** 级联-建筑 */
    @ApiModelProperty(value = "级联-建筑")
    @SCascade(table="scantask.model_scan_task", idColumn="id", childIdColumn="building_id")
    @JSONField(name = "Building")
    var building: Building? = null

    /** 级联-楼层 */
    @ApiModelProperty(value = "级联-楼层")
    @SCascade(table="scantask.model_scan_task", idColumn="id", childIdColumn="floor_id")
    @JSONField(name = "Floor")
    var floor: Floor? = null

    /** 级联-方案*/
    @ApiModelProperty(value = "级联-方案")
    @SCascade(table="scantask.model_scan_task", idColumn="id", childIdColumn="scheme_id")
    @JSONField(name = "ScanScheme")
    var scanScheme: ScanScheme? = null

    /** 级联-部件*/
    @ApiModelProperty(value = "级联-部件")
    @SCascade(table="scantask.model_scan_task", idColumn="parent_id", childIdColumn="equip_id")
    @JSONField(name = "Component")
    var component: ArrayList<ModelScanTaskQuery>? = null
//    @ApiModelProperty(value = "级联-部件")
////    @SCascade(table="scantask.model_scan_task", idColumn="id", childIdColumn="equip_id")
////    @JSONField(name = "Equipment")
////    var equipment: Equipment? = null

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

} // Class ModelScanTask