-- ============================================================
-- Energy Module DDL - Generated from DO classes
-- Database: oneos_energy
-- Generated: 2026-03-16
-- ============================================================

-- 1. energy_hydrogen_record (加氢记录)
DROP TABLE IF EXISTS `energy_hydrogen_record`;
CREATE TABLE `energy_hydrogen_record` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT '租户编号',
  `station_id` bigint DEFAULT NULL COMMENT '加氢站ID',
  `plate_number` varchar(32) DEFAULT NULL COMMENT '车牌号',
  `hydrogen_date` date DEFAULT NULL COMMENT '加氢日期',
  `hydrogen_quantity` decimal(18,2) DEFAULT NULL COMMENT '加氢量(kg)',
  `unit_price` decimal(18,2) DEFAULT NULL COMMENT '单价',
  `amount` decimal(18,2) DEFAULT NULL COMMENT '金额',
  `mileage` decimal(18,2) DEFAULT NULL COMMENT '里程(km)',
  `source_type` int DEFAULT NULL COMMENT '来源类型',
  `match_status` int DEFAULT NULL COMMENT '匹配状态',
  `vehicle_id` bigint DEFAULT NULL COMMENT '车辆ID',
  `customer_id` bigint DEFAULT NULL COMMENT '客户ID',
  `upload_batch_no` varchar(64) 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 '是否删除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='加氢记录';

-- 2. energy_hydrogen_detail (加氢明细)
DROP TABLE IF EXISTS `energy_hydrogen_detail`;
CREATE TABLE `energy_hydrogen_detail` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT 租户编号,
  `record_id` bigint DEFAULT NULL COMMENT '加氢记录ID',
  `station_id` bigint DEFAULT NULL COMMENT '加氢站ID',
  `vehicle_id` bigint DEFAULT NULL COMMENT '车辆ID',
  `plate_number` varchar(32) DEFAULT NULL COMMENT '车牌号',
  `hydrogen_date` date DEFAULT NULL COMMENT '加氢日期',
  `hydrogen_quantity` decimal(18,2) DEFAULT NULL COMMENT '加氢量(kg)',
  `cost_price` decimal(18,2) DEFAULT NULL COMMENT '成本价',
  `cost_amount` decimal(18,2) DEFAULT NULL COMMENT '成本金额',
  `customer_price` decimal(18,2) DEFAULT NULL COMMENT '客户价',
  `customer_amount` decimal(18,2) DEFAULT NULL COMMENT '客户金额',
  `contract_id` bigint DEFAULT NULL COMMENT '合同ID',
  `customer_id` bigint DEFAULT NULL COMMENT '客户ID',
  `project_name` varchar(255) DEFAULT NULL COMMENT '项目名称',
  `cost_bearer` int DEFAULT NULL COMMENT '费用承担方',
  `pay_method` int DEFAULT NULL COMMENT '支付方式',
  `audit_status` int DEFAULT NULL COMMENT '审核状态',
  `audit_remark` varchar(500) DEFAULT NULL COMMENT '审核备注',
  `deduction_status` int DEFAULT NULL COMMENT '扣费状态',
  `settlement_status` int DEFAULT NULL COMMENT '结算状态',
  `bill_id` bigint DEFAULT NULL COMMENT '账单ID',
  `remark` varchar(500) 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 '是否删除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='加氢明细';

-- 3. energy_bill (能源账单)
DROP TABLE IF EXISTS `energy_bill`;
CREATE TABLE `energy_bill` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT 租户编号,
  `bill_code` varchar(64) DEFAULT NULL COMMENT '账单编号',
  `energy_type` int DEFAULT NULL COMMENT '能源类型',
  `customer_id` bigint DEFAULT NULL COMMENT '客户ID',
  `customer_name` varchar(255) DEFAULT NULL COMMENT '客户名称',
  `contract_id` bigint DEFAULT NULL COMMENT '合同ID',
  `station_id` bigint DEFAULT NULL COMMENT '站点ID',
  `station_name` varchar(255) DEFAULT NULL COMMENT '站点名称',
  `cooperation_type` int DEFAULT NULL COMMENT '合作模式(1=预充值 2=月结算)',
  `bill_period_start` date DEFAULT NULL COMMENT '账单周期开始',
  `bill_period_end` date DEFAULT NULL COMMENT '账单周期结束',
  `receivable_amount` decimal(18,2) DEFAULT NULL COMMENT '应收金额',
  `actual_amount` decimal(18,2) DEFAULT NULL COMMENT '实收金额',
  `adjustment_amount` decimal(18,2) DEFAULT NULL COMMENT '调整金额',
  `paid_amount` decimal(18,2) DEFAULT NULL COMMENT '已付金额',
  `total_quantity` decimal(18,2) DEFAULT NULL COMMENT '总用量',
  `detail_count` int DEFAULT NULL COMMENT '明细条数',
  `status` int DEFAULT NULL COMMENT '账单状态',
  `audit_status` int DEFAULT NULL COMMENT '审核状态',
  `submit_status` int DEFAULT NULL COMMENT '提交状态',
  `payment_status` int DEFAULT NULL COMMENT '付款状态',
  `auditor_id` bigint DEFAULT NULL COMMENT '审核人ID',
  `audit_time` datetime DEFAULT NULL COMMENT '审核时间',
  `audit_remark` varchar(500) DEFAULT NULL COMMENT '审核备注',
  `submit_time` datetime DEFAULT NULL COMMENT '提交时间',
  `generate_time` datetime DEFAULT NULL COMMENT '生成时间',
  `yos_bill_code` varchar(64) DEFAULT NULL COMMENT 'YOS账单编号',
  `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 '是否删除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='能源账单';

-- 4. energy_bill_adjustment (账单调整)
DROP TABLE IF EXISTS `energy_bill_adjustment`;
CREATE TABLE `energy_bill_adjustment` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT 租户编号,
  `bill_id` bigint DEFAULT NULL COMMENT '账单ID',
  `detail_id` bigint DEFAULT NULL COMMENT '明细ID',
  `adjustment_type` int DEFAULT NULL COMMENT '调整类型',
  `amount` decimal(18,2) DEFAULT NULL COMMENT '调整金额',
  `reason` varchar(500) DEFAULT NULL COMMENT '调整原因',
  `attachment_urls` varchar(2000) DEFAULT NULL COMMENT '附件URLs',
  `operator_id` bigint DEFAULT NULL COMMENT '操作人ID',
  `operate_time` datetime 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 '是否删除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='账单调整';

-- 5. energy_station_config (站点配置)
DROP TABLE IF EXISTS `energy_station_config`;
CREATE TABLE `energy_station_config` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT 租户编号,
  `station_id` bigint DEFAULT NULL COMMENT '站点ID',
  `auto_deduct` bit(1) DEFAULT NULL COMMENT '是否自动扣费',
  `cooperation_type` int DEFAULT NULL COMMENT '合作类型',
  `auto_match` bit(1) DEFAULT NULL COMMENT '自动匹配开关',
  `remark` varchar(500) 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 '是否删除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='站点配置';

-- 6. energy_station_price (站点价格)
DROP TABLE IF EXISTS `energy_station_price`;
CREATE TABLE `energy_station_price` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT 租户编号,
  `station_id` bigint DEFAULT NULL COMMENT '站点ID',
  `customer_id` bigint DEFAULT NULL COMMENT '客户ID',
  `cost_price` decimal(18,2) DEFAULT NULL COMMENT '成本价',
  `customer_price` decimal(18,2) DEFAULT NULL COMMENT '客户价',
  `effective_date` date DEFAULT NULL COMMENT '生效日期',
  `expiry_date` date DEFAULT NULL COMMENT '失效日期',
  `status` int 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 '是否删除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='站点价格';

-- 7. energy_account (能源账户)
DROP TABLE IF EXISTS `energy_account`;
CREATE TABLE `energy_account` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT 租户编号,
  `customer_id` bigint DEFAULT NULL COMMENT '客户ID',
  `balance` decimal(18,2) DEFAULT NULL COMMENT '余额',
  `init_balance` decimal(18,2) DEFAULT NULL COMMENT '初始余额',
  `accumulated_recharge` decimal(18,2) DEFAULT NULL COMMENT '累计充值金额',
  `accumulated_hydrogen` decimal(18,2) DEFAULT NULL COMMENT '累计加氢金额',
  `accumulated_electric` decimal(18,2) DEFAULT NULL COMMENT '累计充电金额',
  `accumulated_consume` decimal(18,2) DEFAULT NULL COMMENT '累计消费金额',
  `reminder_threshold` decimal(18,2) DEFAULT NULL COMMENT '余额预警阈值',
  `account_status` int DEFAULT NULL COMMENT '账户状态',
  `last_recharge_date` date DEFAULT NULL COMMENT '最后充值日期',
  `version` int DEFAULT 0 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 '是否删除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='能源账户';

-- 8. energy_project_account (项目账户)
DROP TABLE IF EXISTS `energy_project_account`;
CREATE TABLE `energy_project_account` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT 租户编号,
  `account_id` bigint DEFAULT NULL COMMENT '账户ID',
  `contract_id` bigint DEFAULT NULL COMMENT '合同ID',
  `project_name` varchar(255) DEFAULT NULL COMMENT '项目名称',
  `project_balance` decimal(18,2) DEFAULT NULL COMMENT '项目余额',
  `project_remit_amount` decimal(18,2) DEFAULT NULL COMMENT '项目汇款总额',
  `project_hydrogen_amount` decimal(18,2) DEFAULT NULL COMMENT '项目加氢金额',
  `project_electric_amount` decimal(18,2) DEFAULT NULL COMMENT '项目充电金额',
  `project_consume_amount` decimal(18,2) DEFAULT NULL COMMENT '项目消费总额',
  `reminder_threshold` decimal(18,2) DEFAULT NULL COMMENT '余额预警阈值',
  `account_status` int DEFAULT NULL COMMENT '账户状态',
  `version` int DEFAULT 0 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 '是否删除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='项目账户';

-- 9. energy_account_flow (账户流水)
DROP TABLE IF EXISTS `energy_account_flow`;
CREATE TABLE `energy_account_flow` (
  `id` bigint NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint NOT NULL DEFAULT 1 COMMENT 租户编号,
  `account_id` bigint DEFAULT NULL COMMENT '账户ID',
  `project_account_id` bigint DEFAULT NULL COMMENT '项目账户ID',
  `flow_type` int DEFAULT NULL COMMENT '流水类型',
  `amount` decimal(18,2) DEFAULT NULL COMMENT '金额',
  `balance_before` decimal(18,2) DEFAULT NULL COMMENT '变更前余额',
  `balance_after` decimal(18,2) DEFAULT NULL COMMENT '变更后余额',
  `project_balance_before` decimal(18,2) DEFAULT NULL COMMENT '变更前项目余额',
  `project_balance_after` decimal(18,2) DEFAULT NULL COMMENT '变更后项目余额',
  `biz_type` int DEFAULT NULL COMMENT '业务类型',
  `biz_id` bigint DEFAULT NULL COMMENT '业务ID',
  `biz_code` varchar(64) DEFAULT NULL COMMENT '业务编号',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  `operator_id` bigint DEFAULT 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 '是否删除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='账户流水';
