# 设施设备领域技术方案

**领域编号**: 4.3  
**微服务**: ether-asset  
**最后更新**: 2026-04-26

> **更新记录**:
> - 2026-04-26: 反向同步实际代码实现到文档。主要变更：设备类型枚举更新为10种（新增ENERGY_METER/LANDSCAPE/KITCHEN，AC→HVAC，FIRE_FIGHTING→FIRE_PROTECTION，POWER_SUPPLY→ELECTRICAL，删除PARKING）；设备状态枚举更新（NORMAL→ACTIVE，FAULT→INACTIVE，MAINTAINING→MAINTENANCE）；新增4张专业扩展表（Elevator/Hvac/Fire/Energy）；新增系统类型（SystemType 9种）；新增归属管理（OwnershipType+OwnershipEntity）；新增健康评分算法（MTBF/MTTR），标注为Beta；新增故障历史（EquipmentFailureHistory）；新增设备照片/文档（JSONB内嵌）；新增Excel导入导出；新增特种设备管理；新增能耗标准字段；字段名变更（code→equipmentCode, name→equipmentName, locationDesc→installationLocation）；维保计划迁移至独立API；维保记录升级为维保工单；标注TODO: 维保完成率计算暂返回1.0。

---

## 一、领域概述

### 1.1 领域职责

设施设备领域负责管理物业资产全生命周期：

- 设备台账管理（电梯、空调、消防、给排水、供配电等）
- 设备维保计划与记录
- 设备故障管理
- 设备与工单联动

### 1.2 核心概念

| 概念 | 说明 | 对应实体 |
|------|------|----------|
| **设备台账** | 设备基础信息和运行状态 | Equipment |
| **电梯扩展** | 电梯专业参数（载重/速度/注册号等） | EquipmentElevator |
| **暖通扩展** | 暖通空调专业参数（制冷量/制热量/能效比等） | EquipmentHvac |
| **消防扩展** | 消防设备专业参数（探测范围/联动/分区等） | EquipmentFire |
| **能源计量扩展** | 能源表计专业参数（表常数/精度/通讯等） | EquipmentEnergy |
| **健康评分** | 设备健康度评估结果 | EquipmentHealthScore |
| **故障历史** | 设备故障与维修记录 | EquipmentFailureHistory |
| **归属主体** | 设备归属方信息 | OwnershipEntity |
| **维保计划** | 定期保养计划（已迁移至独立API） | MaintenancePlan |
| **维保工单** | 维保执行工单（原维保记录升级） | MaintenanceTask |

---

## 二、领域模型

### 2.1 聚合根设计

#### Equipment（设备台账）

```java
@Entity
@Table(name = "asset_equipment")
@Data
public class Equipment {
    @Id
    private UUID id;
    private UUID projectId;

    private String equipmentCode;   // 设备编码（原code）
    private String equipmentName;   // 设备名称（原name）

    // 分类
    private EquipmentType type;     // 10种设备类型
    private EquipmentStatus status; // ACTIVE/INACTIVE/MAINTENANCE/SCRAPPED

    // 系统类型（新增）
    private SystemType systemType;  // 所属系统类型（9种）

    // 品牌型号
    private String brand;
    private String model;
    private String specifications;
    private String serialNumber;

    // 厂商信息
    private String manufacturer;
    private String supplier;
    private String supplierPhone;

    // 位置
    private UUID spaceNodeId;       // 关联空间节点
    private String installationLocation; // 安装位置（原locationDesc）

    // 时间
    private LocalDate purchaseDate;
    private LocalDate installDate;
    private LocalDate warrantyDate;
    private Integer lifespanYears;  // 设计寿命(年)

    // 维保
    private Integer maintenanceCycle;     // 保养周期(天)
    private LocalDate lastMaintenanceDate;
    private LocalDate nextMaintenanceDate;

    // 负责人
    private UUID managerId;
    private String managerName;
    private String contactPhone;

    // 归属管理（新增）
    private OwnershipType ownershipType;  // SELF(自持)/DEVELOPER(开发商)/OWNER(业主)/VENDOR(厂商)
    private UUID ownershipEntityId;       // 归属主体ID

    // 特种设备管理（新增）
    private Boolean isSpecialEquipment;   // 是否特种设备
    private String specialEquipmentCode;  // 特种设备使用登记证编号
    private String specialEquipmentType;  // 特种设备类型
    private LocalDate specialInspectionDate; // 特种设备检验日期
    private LocalDate nextSpecialInspectionDate; // 下次检验日期

    // 能耗标准（新增）
    private String energyStandard;        // 能效标准
    private BigDecimal ratedPower;        // 额定功率(kW)
    private BigDecimal energyEfficiencyRating; // 能效等级

    // 二维码
    private String qrCode;

    // 设备照片/文档（新增，JSONB内嵌）
    @JdbcTypeCode(SqlTypes.JSON)
    @Column(columnDefinition = "jsonb")
    private List<AttachmentDTO> photos;   // 设备照片列表

    @JdbcTypeCode(SqlTypes.JSON)
    @Column(columnDefinition = "jsonb")
    private List<AttachmentDTO> documents; // 设备文档列表

    // 扩展属性(JSONB)
    private String attributes;

    // 审计字段
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
}
```

**系统类型枚举（新增）**:

```java
public enum SystemType {
    ELEVATOR_SYSTEM("电梯系统"),
    HVAC_SYSTEM("暖通系统"),
    FIRE_SYSTEM("消防系统"),
    PLUMBING_SYSTEM("给排水系统"),
    ELECTRICAL_SYSTEM("供配电系统"),
    SECURITY_SYSTEM("安防系统"),
    LANDSCAPE_SYSTEM("园林系统"),
    DRAINAGE_SYSTEM("排污系统"),
    OTHER("其他");
}
```

**归属类型枚举（新增）**:

```java
public enum OwnershipType {
    SELF("自持"),
    DEVELOPER("开发商"),
    OWNER("业主"),
    VENDOR("厂商");
}
```

**附件DTO**:

```java
@Data
public class AttachmentDTO {
    private String name;      // 文件名
    private String url;       // 文件URL
    private String type;      // 文件类型
    private Long size;        // 文件大小
    private LocalDateTime uploadedAt; // 上传时间
}
```

**设备类型枚举**:

```java
// 设备类型枚举（10种）
public enum EquipmentType {
    ELEVATOR("电梯"),
    HVAC("暖通空调"),
    FIRE_PROTECTION("消防设备"),
    PLUMBING("给排水"),
    ELECTRICAL("供配电"),
    ENERGY_METER("能源计量"),
    SECURITY("安防设备"),
    LANDSCAPE("园林景观"),
    KITCHEN("厨房设备"),
    OTHER("其他设备");
}
```

#### EquipmentElevator（电梯扩展表，新增）

```java
@Entity
@Table(name = "asset_equipment_elevator")
@Data
public class EquipmentElevator {
    @Id
    private UUID id;
    private UUID equipmentId;       // 关联设备ID
    private UUID projectId;

    private Integer loadCapacity;   // 载重(kg)
    private BigDecimal speed;       // 速度(m/s)
    private Integer floors;         // 楼层数
    private Integer stops;          // 停站数
    private String doorType;        // 门类型
    private String driveType;       // 驱动方式
    private String registrationCode; // 使用登记证编号
    private LocalDate inspectionExpiryDate; // 检验有效期

    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
}
```

#### EquipmentHvac（暖通扩展表，新增）

```java
@Entity
@Table(name = "asset_equipment_hvac")
@Data
public class EquipmentHvac {
    @Id
    private UUID id;
    private UUID equipmentId;
    private UUID projectId;

    private BigDecimal coolingCapacity;  // 制冷量(kW)
    private BigDecimal heatingCapacity;  // 制热量(kW)
    private BigDecimal cop;              // 能效比
    private String refrigerant;          // 制冷剂
    private BigDecimal airflow;          // 风量(m³/h)
    private String pipeType;             // 管道类型
    private BigDecimal pipeLength;       // 管道长度(m)

    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
}
```

#### EquipmentFire（消防扩展表，新增）

```java
@Entity
@Table(name = "asset_equipment_fire")
@Data
public class EquipmentFire {
    @Id
    private UUID id;
    private UUID equipmentId;
    private UUID projectId;

    private String detectionRange;       // 探测范围
    private Boolean hasLinkage;          // 是否联动
    private String fireZone;             // 防火分区
    private String extinguishingAgent;   // 灭火剂类型
    private BigDecimal agentCapacity;    // 灭火剂容量
    private LocalDate lastTestDate;      // 上次测试日期
    private LocalDate nextTestDate;      // 下次测试日期

    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
}
```

#### EquipmentEnergy（能源计量扩展表，新增）

```java
@Entity
@Table(name = "asset_equipment_energy")
@Data
public class EquipmentEnergy {
    @Id
    private UUID id;
    private UUID equipmentId;
    private UUID projectId;

    private String meterConstant;        // 表常数
    private String accuracyClass;        // 精度等级
    private String communicationProtocol; // 通讯协议
    private String meterCategory;        // 表计类别
    private BigDecimal ctRatio;          // CT变比
    private BigDecimal ptRatio;          // PT变比
    private LocalDate calibrationDate;   // 校验日期
    private LocalDate nextCalibrationDate; // 下次校验日期

    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
}
```

#### EquipmentHealthScore（健康评分，新增，Beta）

```java
@Entity
@Table(name = "asset_equipment_health_score")
@Data
public class EquipmentHealthScore {
    @Id
    private UUID id;
    private UUID equipmentId;
    private UUID projectId;

    private BigDecimal score;            // 健康评分(0-100)
    private String level;                // 健康等级: EXCELLENT/GOOD/FAIR/POOR
    private BigDecimal mtbf;             // 平均故障间隔时间(MTBF, 小时)
    private BigDecimal mttr;             // 平均修复时间(MTTR, 小时)
    private Integer totalFailures;       // 总故障次数
    private Integer totalMaintenance;    // 总维保次数
    private BigDecimal availability;     // 可用率(%)
    private LocalDateTime calculatedAt;  // 计算时间

    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
}
```

> **Beta标注**: 健康评分算法基于MTBF/MTTR计算，当前为Beta版本，评分模型和权重参数需根据实际运行数据持续优化。

#### EquipmentFailureHistory（故障历史，新增）

```java
@Entity
@Table(name = "asset_equipment_failure_history")
@Data
public class EquipmentFailureHistory {
    @Id
    private UUID id;
    private UUID equipmentId;
    private UUID projectId;

    private LocalDateTime failureTime;   // 故障时间
    private String failureType;          // 故障类型
    private String failureDescription;   // 故障描述
    private String faultCause;           // 故障原因
    private String solution;             // 解决方案
    private UUID repairWorkOrderId;      // 关联维修工单
    private LocalDateTime resolvedTime;  // 修复时间
    private Long downtimeMinutes;        // 停机时长(分钟)
    private String reportedBy;           // 报告人

    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
}
```

#### OwnershipEntity（归属主体，新增）

```java
@Entity
@Table(name = "asset_ownership_entity")
@Data
public class OwnershipEntity {
    @Id
    private UUID id;
    private UUID projectId;

    private OwnershipType type;          // SELF/DEVELOPER/OWNER/VENDOR
    private String name;                 // 归属方名称
    private String contactPerson;        // 联系人
    private String contactPhone;         // 联系电话
    private String address;              // 地址
    private String description;          // 描述

    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
}
```

#### MaintenancePlan（维保计划）

> **注意**: 维保计划已迁移至独立API（`/api/asset/maintenance-plans`），不再嵌套在设备管理接口下。

```java
@Entity
@Table(name = "asset_maintenance_plan")
@Data
public class MaintenancePlan {
    @Id
    private UUID id;
    private UUID projectId;
    private UUID equipmentId;      // 关联设备

    private String name;
    private MaintenanceType type;  // DAILY/WEEKLY/MONTHLY/QUARTERLY/YEARLY

    // 周期
    private Integer cycleDays;     // 周期天数
    private String cronExpression; // Cron表达式

    // 内容
    private String content;        // 保养内容描述
    private String checkItems;     // 检查项清单(JSON)

    // 负责人
    private UUID maintainerId;
    private String maintainerName;

    // 提醒
    private Integer remindDays;    // 提前提醒天数

    // 状态
    private Boolean enabled;

    // 审计字段
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
}
```

#### MaintenanceTask（维保工单，原MaintenanceRecord升级）

> **注意**: 原MaintenanceRecord已升级为MaintenanceTask（维保工单），增加了工单状态流转、费用记录、签名确认等字段。

```java
@Entity
@Table(name = "asset_maintenance_task")
@Data
public class MaintenanceTask {
    @Id
    private UUID id;
    private UUID equipmentId;
    private UUID planId;           // 关联计划
    private UUID projectId;

    // 工单信息
    private String taskCode;       // 工单编号
    private MaintenanceTaskStatus status; // PENDING/IN_PROGRESS/COMPLETED/CANCELLED

    // 维保信息
    private LocalDate maintenanceDate;
    private MaintenanceType type;
    private String content;

    // 执行人
    private UUID maintainerId;
    private String maintainerName;

    // 结果
    private MaintenanceResult result; // NORMAL/ABNORMAL
    private String remark;
    private String images;

    // 检查项结果
    private String checkResults;   // [{"item":"检查A","result":"PASS"}]

    // 费用（新增）
    private BigDecimal laborCost;  // 人工费
    private BigDecimal partsCost;  // 材料费
    private BigDecimal totalCost;  // 总费用

    // 签名确认（新增）
    private String signature;      // 签名图片URL

    // 关联工单
    private UUID workOrderId;      // 异常时关联的维修工单

    // 下次维保
    private LocalDate nextMaintenanceDate;

    // 审计字段
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
}

public enum MaintenanceTaskStatus {
    PENDING("待执行"),
    IN_PROGRESS("执行中"),
    COMPLETED("已完成"),
    CANCELLED("已取消");
}
```

---

## 三、设备与工单联动

### 3.1 故障自动报修

```java
@Component
public class EquipmentFaultHandler {

    @Autowired
    private WorkOrderService workOrderService;

    @EventListener
    public void onEquipmentFault(EquipmentFaultEvent event) {
        Equipment equipment = event.getEquipment();

        // 创建设备维修工单
        WorkOrder workOrder = new WorkOrder();
        workOrder.setOrderType(WorkOrderType.REPAIR);
        workOrder.setTitle("设备故障: " + equipment.getEquipmentName());
        workOrder.setDescription(event.getFaultDescription());
        workOrder.setEquipmentId(equipment.getId());
        workOrder.setSpaceNodeId(equipment.getSpaceNodeId());
        workOrder.setPriority(WorkOrderPriority.HIGH);
        workOrder.setSource(WorkOrderSource.FAULT);

        workOrderService.create(workOrder);

        // 更新设备状态
        equipment.setStatus(EquipmentStatus.INACTIVE);
        equipmentRepository.save(equipment);
    }
}
```

### 3.2 维保到期提醒

```java
@Component
public class MaintenanceReminderJob {

    @Scheduled(cron = "0 0 9 * * ?") // 每天9点执行
    public void remindUpcomingMaintenance() {
        // 查询7天内到期的维保计划
        LocalDate targetDate = LocalDate.now().plusDays(7);

        List<Equipment> equipments = equipmentRepository
            .findByNextMaintenanceDateBeforeAndStatus(targetDate, EquipmentStatus.ACTIVE);

        for (Equipment equipment : equipments) {
            notificationService.sendMaintenanceReminder(equipment);
        }
    }
}
```

---

## 四、实现状态与差异

### 4.1 实现状态

| 功能模块 | 实现状态 | 备注 |
|---------|---------|------|
| Equipment | 🟢 已实现 | 基础CRUD，字段名已更新(equipmentCode/equipmentName/installationLocation) |
| EquipmentElevator | 🟢 已实现 | 电梯专业扩展表 |
| EquipmentHvac | 🟢 已实现 | 暖通专业扩展表 |
| EquipmentFire | 🟢 已实现 | 消防专业扩展表 |
| EquipmentEnergy | 🟢 已实现 | 能源计量扩展表 |
| EquipmentHealthScore | 🟢 已实现(Beta) | 健康评分，MTBF/MTTR算法，Beta版本 |
| EquipmentFailureHistory | 🟢 已实现 | 故障历史记录 |
| OwnershipEntity | 🟢 已实现 | 归属主体管理 |
| MaintenancePlan | 🟢 已实现 | 已迁移至独立API |
| MaintenanceTask | 🟢 已实现 | 原MaintenanceRecord升级为维保工单 |
| 设备二维码 | 🟢 已实现 | 支持扫码查看设备信息 |
| Excel导入导出 | 🟢 已实现 | 设备台账Excel导入导出 |
| 特种设备管理 | 🟢 已实现 | 特种设备登记证/检验日期 |
| 能耗标准字段 | 🟢 已实现 | 能效标准/额定功率/能效等级 |
| 设备照片/文档 | 🟢 已实现 | JSONB内嵌存储 |
| 故障自动工单 | 🟡 部分实现 | 设备状态变更可关联工单 |
| 维保完成率计算 | 🟡 部分实现 | TODO: 当前暂返回1.0，需实现真实计算 |
| IoT集成 | 🔴 未实现 | 待开发 |

### 4.2 与设计方案的差异

| 设计项 | 设计方案 | 现有实现 | 差异分析 |
|--------|----------|----------|----------|
| **维保归属** | ether-asset | ether-asset | 已修正：维保实体已统一在 ether-asset |
| **设备管理** | ether-asset | ether-asset | 已修正：设备实体已统一在 ether-asset |
| **设备联动** | 故障自动工单 | 部分实现 | 功能完善中 |
| **设备类型** | 8种枚举 | 10种枚举 | 已扩展：新增ENERGY_METER/LANDSCAPE/KITCHEN |
| **设备状态** | NORMAL/FAULT | ACTIVE/INACTIVE | 已修正：语义更清晰 |
| **专业扩展** | 无 | 4张扩展表 | 已新增：Elevator/Hvac/Fire/Energy |
| **健康评分** | 无 | Beta实现 | 已新增：基于MTBF/MTTR |
| **归属管理** | 无 | OwnershipEntity | 已新增：4种归属类型 |
| **维保记录** | MaintenanceRecord | MaintenanceTask | 已升级：增加工单状态/费用/签名 |
| **字段命名** | code/name/locationDesc | equipmentCode/equipmentName/installationLocation | 已修正：命名更规范 |

### 4.3 改进计划

| 优先级 | 改进项 | 说明 |
|--------|--------|------|
| P0 | 维保完成率计算 | 当前暂返回1.0，需实现真实计算逻辑 |
| P1 | 健康评分优化 | Beta版评分模型需根据实际运行数据持续优化 |
| P1 | 完善故障自动工单 | 设备状态变更时自动创建维修工单 |
| P2 | 完善设备二维码功能 | 支持扫码报修 |
| P3 | IoT传感器接入 | 对接传感器数据 |

---

## 五、数据库表结构

```sql
-- 设备台账表
CREATE TABLE asset_equipment (
    id UUID PRIMARY KEY,
    project_id UUID NOT NULL,
    equipment_code VARCHAR(50) NOT NULL,
    equipment_name VARCHAR(100) NOT NULL,
    type VARCHAR(20) NOT NULL,
    status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE',
    system_type VARCHAR(30),
    brand VARCHAR(100),
    model VARCHAR(100),
    specifications VARCHAR(500),
    serial_number VARCHAR(100),
    manufacturer VARCHAR(100),
    supplier VARCHAR(100),
    supplier_phone VARCHAR(20),
    space_node_id UUID,
    installation_location VARCHAR(255),
    purchase_date DATE,
    install_date DATE,
    warranty_date DATE,
    lifespan_years INTEGER,
    maintenance_cycle INTEGER,
    last_maintenance_date DATE,
    next_maintenance_date DATE,
    manager_id UUID,
    manager_name VARCHAR(100),
    contact_phone VARCHAR(20),
    ownership_type VARCHAR(20),
    ownership_entity_id UUID,
    is_special_equipment BOOLEAN DEFAULT FALSE,
    special_equipment_code VARCHAR(100),
    special_equipment_type VARCHAR(50),
    special_inspection_date DATE,
    next_special_inspection_date DATE,
    energy_standard VARCHAR(100),
    rated_power DECIMAL(10,2),
    energy_efficiency_rating DECIMAL(3,1),
    qr_code VARCHAR(255),
    photos JSONB,
    documents JSONB,
    attributes JSONB,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
    UNIQUE(project_id, equipment_code)
);

-- 电梯扩展表
CREATE TABLE asset_equipment_elevator (
    id UUID PRIMARY KEY,
    equipment_id UUID NOT NULL REFERENCES asset_equipment(id),
    project_id UUID NOT NULL,
    load_capacity INTEGER,
    speed DECIMAL(5,2),
    floors INTEGER,
    stops INTEGER,
    door_type VARCHAR(50),
    drive_type VARCHAR(50),
    registration_code VARCHAR(100),
    inspection_expiry_date DATE,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

-- 暖通扩展表
CREATE TABLE asset_equipment_hvac (
    id UUID PRIMARY KEY,
    equipment_id UUID NOT NULL REFERENCES asset_equipment(id),
    project_id UUID NOT NULL,
    cooling_capacity DECIMAL(10,2),
    heating_capacity DECIMAL(10,2),
    cop DECIMAL(5,2),
    refrigerant VARCHAR(50),
    airflow DECIMAL(10,2),
    pipe_type VARCHAR(50),
    pipe_length DECIMAL(10,2),
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

-- 消防扩展表
CREATE TABLE asset_equipment_fire (
    id UUID PRIMARY KEY,
    equipment_id UUID NOT NULL REFERENCES asset_equipment(id),
    project_id UUID NOT NULL,
    detection_range VARCHAR(100),
    has_linkage BOOLEAN,
    fire_zone VARCHAR(100),
    extinguishing_agent VARCHAR(50),
    agent_capacity DECIMAL(10,2),
    last_test_date DATE,
    next_test_date DATE,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

-- 能源计量扩展表
CREATE TABLE asset_equipment_energy (
    id UUID PRIMARY KEY,
    equipment_id UUID NOT NULL REFERENCES asset_equipment(id),
    project_id UUID NOT NULL,
    meter_constant VARCHAR(50),
    accuracy_class VARCHAR(20),
    communication_protocol VARCHAR(50),
    meter_category VARCHAR(50),
    ct_ratio DECIMAL(10,2),
    pt_ratio DECIMAL(10,2),
    calibration_date DATE,
    next_calibration_date DATE,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

-- 健康评分表
CREATE TABLE asset_equipment_health_score (
    id UUID PRIMARY KEY,
    equipment_id UUID NOT NULL REFERENCES asset_equipment(id),
    project_id UUID NOT NULL,
    score DECIMAL(5,2),
    level VARCHAR(20),
    mtbf DECIMAL(12,2),
    mttr DECIMAL(12,2),
    total_failures INTEGER DEFAULT 0,
    total_maintenance INTEGER DEFAULT 0,
    availability DECIMAL(5,2),
    calculated_at TIMESTAMP,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

-- 故障历史表
CREATE TABLE asset_equipment_failure_history (
    id UUID PRIMARY KEY,
    equipment_id UUID NOT NULL REFERENCES asset_equipment(id),
    project_id UUID NOT NULL,
    failure_time TIMESTAMP NOT NULL,
    failure_type VARCHAR(50),
    failure_description TEXT,
    fault_cause TEXT,
    solution TEXT,
    repair_work_order_id UUID,
    resolved_time TIMESTAMP,
    downtime_minutes BIGINT,
    reported_by VARCHAR(100),
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

-- 归属主体表
CREATE TABLE asset_ownership_entity (
    id UUID PRIMARY KEY,
    project_id UUID NOT NULL,
    type VARCHAR(20) NOT NULL,
    name VARCHAR(100) NOT NULL,
    contact_person VARCHAR(100),
    contact_phone VARCHAR(20),
    address VARCHAR(255),
    description TEXT,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

-- 维保计划表
CREATE TABLE asset_maintenance_plan (
    id UUID PRIMARY KEY,
    project_id UUID NOT NULL,
    equipment_id UUID NOT NULL,
    name VARCHAR(100) NOT NULL,
    type VARCHAR(20) NOT NULL,
    cycle_days INTEGER,
    cron_expression VARCHAR(50),
    content TEXT,
    check_items JSONB,
    maintainer_id UUID,
    maintainer_name VARCHAR(100),
    remind_days INTEGER DEFAULT 3,
    enabled BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

-- 维保工单表（原维保记录表升级）
CREATE TABLE asset_maintenance_task (
    id UUID PRIMARY KEY,
    equipment_id UUID NOT NULL,
    plan_id UUID,
    project_id UUID NOT NULL,
    task_code VARCHAR(50),
    status VARCHAR(20) NOT NULL DEFAULT 'PENDING',
    maintenance_date DATE NOT NULL,
    type VARCHAR(20) NOT NULL,
    content TEXT,
    maintainer_id UUID,
    maintainer_name VARCHAR(100),
    result VARCHAR(20),
    remark VARCHAR(500),
    images TEXT,
    check_results JSONB,
    labor_cost DECIMAL(10,2),
    parts_cost DECIMAL(10,2),
    total_cost DECIMAL(10,2),
    signature VARCHAR(255),
    work_order_id UUID,
    next_maintenance_date DATE,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

-- 创建索引
CREATE INDEX idx_equipment_project ON asset_equipment(project_id);
CREATE INDEX idx_equipment_type ON asset_equipment(type);
CREATE INDEX idx_equipment_status ON asset_equipment(status);
CREATE INDEX idx_equipment_space ON asset_equipment(space_node_id);
CREATE INDEX idx_equipment_next_maintenance ON asset_equipment(next_maintenance_date);
CREATE INDEX idx_equipment_system_type ON asset_equipment(system_type);
CREATE INDEX idx_equipment_ownership ON asset_equipment(ownership_entity_id);
CREATE INDEX idx_equipment_special ON asset_equipment(is_special_equipment) WHERE is_special_equipment = TRUE;
CREATE INDEX idx_maintenance_plan_equipment ON asset_maintenance_plan(equipment_id);
CREATE INDEX idx_maintenance_task_equipment ON asset_maintenance_task(equipment_id);
CREATE INDEX idx_maintenance_task_status ON asset_maintenance_task(status);
CREATE INDEX idx_failure_history_equipment ON asset_equipment_failure_history(equipment_id);
CREATE INDEX idx_health_score_equipment ON asset_equipment_health_score(equipment_id);
```

---

**文档维护**: 本领域技术方案由 ether-asset 服务负责人维护
