-- =============================================
-- 资产管理系统 - 停车场和车型参数模块
-- 创建时间: 2026-03-12
-- =============================================

-- 1. 完善停车场表结构
ALTER TABLE `asset_parking` 
ADD COLUMN `principal` varchar(50) DEFAULT NULL COMMENT '公司负责人' AFTER `name`,
ADD COLUMN `contact_name` varchar(50) DEFAULT NULL COMMENT '联系人' AFTER `principal`,
ADD COLUMN `contact_phone` varchar(20) DEFAULT NULL COMMENT '联系电话' AFTER `contact_name`,
ADD COLUMN `parked_amount` int DEFAULT 0 COMMENT '已停车辆数' AFTER `capacity`,
ADD COLUMN `stock_area` int DEFAULT NULL COMMENT '库存区域（字典）' AFTER `address`,
ADD COLUMN `unusual_action_city` int DEFAULT NULL COMMENT '异动城市（字典）' AFTER `stock_area`,
ADD COLUMN `longitude` varchar(50) DEFAULT NULL COMMENT '经度' AFTER `address`,
ADD COLUMN `latitude` varchar(50) DEFAULT NULL COMMENT '纬度' AFTER `longitude`,
ADD COLUMN `remark` varchar(500) DEFAULT NULL COMMENT '备注' AFTER `latitude`;

-- 2. 创建车型参数表
CREATE TABLE `asset_vehicle_model` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
  `brand` int NOT NULL COMMENT '品牌（字典）',
  `model` int NOT NULL COMMENT '车型（字典）',
  `model_code` varchar(50) DEFAULT NULL COMMENT '车型编号',
  `model_name` varchar(100) NOT NULL COMMENT '车型名称',
  `notice_model` varchar(100) DEFAULT NULL COMMENT '车辆公告型号',
  `hydrogen_unit` int DEFAULT NULL COMMENT '仪表盘氢气单位（字典）',
  `hydrogen_capacity` int DEFAULT NULL COMMENT '氢瓶容量(L)',
  `electricity_mileage` int DEFAULT NULL COMMENT '电池公告可行驶里程(KM)',
  `reserve_electricity` decimal(10,2) DEFAULT NULL COMMENT '储电量(kwh)',
  `hydrogen_mileage` int DEFAULT NULL COMMENT '氢气公告可行驶里程(KM)',
  `fuel_type` int DEFAULT NULL COMMENT '燃料种类（字典）',
  `tire_size` varchar(50) DEFAULT NULL COMMENT '轮胎尺寸',
  `tire_number` int DEFAULT NULL COMMENT '轮胎数量',
  `truck_size` varchar(100) DEFAULT NULL COMMENT '车辆尺寸',
  `online_spread_enterprise` varchar(100) DEFAULT NULL COMMENT '电堆厂家',
  `battery_factory` varchar(100) DEFAULT NULL COMMENT '电池厂家',
  `refrigerator_factory` varchar(100) DEFAULT NULL COMMENT '冷机厂家',
  `creator` varchar(64) DEFAULT '' COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) DEFAULT '' COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  PRIMARY KEY (`id`),
  KEY `idx_brand` (`brand`),
  KEY `idx_model` (`model`),
  KEY `idx_model_name` (`model_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='车型参数表';

-- 3. 创建车型维保项目关联表
CREATE TABLE `asset_vehicle_model_maintain_item` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
  `vehicle_model_id` bigint NOT NULL COMMENT '车型ID',
  `maintain_item_id` bigint NOT NULL COMMENT '维保项目ID',
  `creator` varchar(64) DEFAULT '' COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) DEFAULT '' COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  PRIMARY KEY (`id`),
  KEY `idx_vehicle_model_id` (`vehicle_model_id`),
  KEY `idx_maintain_item_id` (`maintain_item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='车型维保项目关联表';

-- 4. 更新车型维保项目关联表（添加保养详情字段）
ALTER TABLE `asset_vehicle_model_maintain_item`
ADD COLUMN `maintain_item` varchar(100) DEFAULT NULL COMMENT '保养项目' AFTER `maintain_item_id`,
ADD COLUMN `maintain_content` varchar(500) DEFAULT NULL COMMENT '保养内容' AFTER `maintain_item`,
ADD COLUMN `materials_expenses` decimal(10,2) DEFAULT NULL COMMENT '材料费' AFTER `maintain_content`,
ADD COLUMN `hour_fee` decimal(10,2) DEFAULT NULL COMMENT '工时费' AFTER `materials_expenses`,
ADD COLUMN `kilometer_cycle` int DEFAULT NULL COMMENT '保养公里周期(KM)' AFTER `hour_fee`,
ADD COLUMN `time_cycle` int DEFAULT NULL COMMENT '保养时间周期(月)' AFTER `kilometer_cycle`;
