MyEMS 数据库设计:13 个业务库
目录
- 数据库架构设计
- 数据库详细说明
- 1. 系统数据库 (myems_system_db)
- 2. 历史数据库 (myems_historical_db)
- 3. 能耗数据库 (myems_energy_db)
- 4. 费用数据库 (myems_billing_db)
- 5. 碳排放数据库 (myems_carbon_db)
- 6. 能耗基准数据库 (myems_energy_baseline_db)
- 7. 能耗模型数据库 (myems_energy_model_db)
- 8. 能耗计划数据库 (myems_energy_plan_db)
- 9. 能耗预测数据库 (myems_energy_prediction_db)
- 10. FDD 数据库 (myems_fdd_db)
- 11. 用户数据库 (myems_user_db)
- 12. 报表数据库 (myems_reporting_db)
- 13. 产量数据库 (myems_production_db)
- 数据流转关系
- 表结构设计规范
数据库架构设计
MyEMS 使用 13 个 MySQL 数据库。安装脚本位于 database/install。每个脚本创建一个数据库,字符集为 utf8mb4,排序规则为 utf8mb4_unicode_ci。表使用 BIGINT 主键、UTC 的 DATETIME 列,测量值和汇总值使用 DECIMAL(21, 6)。
| 数据库 | 表数量 | 用途 |
|---|---|---|
myems_system_db | 166 | 主数据:空间、计量表、数据点、设备、电站、费率和关联关系 |
myems_historical_db | 12 | 数据点原始值和上传的费用、离线表、修复、计划文件 |
myems_energy_db | 39 | 小时能耗汇总 |
myems_billing_db | 39 | 小时费用汇总,表集合与能耗库相同 |
myems_carbon_db | 39 | 小时碳排放汇总,表集合与能耗库相同 |
myems_energy_baseline_db | 39 | 小时基准,表集合与能耗库相同 |
myems_energy_model_db | 39 | 8760 小时典型年,对象集合与能耗库相同 |
myems_energy_plan_db | 39 | 小时计划,表集合与能耗库相同 |
myems_energy_prediction_db | 39 | 小时预测,表集合与能耗库相同 |
myems_fdd_db | 9 | 故障规则,以及邮件、短信、网页和微信消息 |
myems_user_db | 10 | 用户、权限、会话、API 密钥和审计日志 |
myems_reporting_db | 4 | 报表定义、模板、生成文件和报表邮件 |
myems_production_db | 8 | 产品、班组、班次和小时产量 |
设计理念
| 数据库 | 职责 | 写入方 |
|---|---|---|
myems_system_db | 配置和拓扑 | Web 界面经 myems-api |
myems_historical_db | 数据点时间序列和上传的工作簿 | 数据采集和文件导入 |
myems_energy_db | 小时能耗 | 规范化和汇总 |
myems_billing_db | 小时费用 | 计费,依据能耗值和费率 |
myems_carbon_db | 小时排放 | 碳排放计算,依据能耗值和排放因子 |
myems_energy_baseline_db | 小时基准 | 基准服务 |
myems_energy_model_db | 非闰年每个小时一个值 | 建模服务 |
myems_energy_plan_db | 小时计划 | 计划服务 |
myems_energy_prediction_db | 小时预测 | 预测服务 |
myems_fdd_db | 规则和出站通知 | FDD 服务 |
myems_user_db | 身份和权限 | API |
myems_reporting_db | 定时报表 | 报表服务 |
myems_production_db | 用于能耗强度的产量 | 产量导入和汇总 |
配置对象之间用 id 互相引用。跨库表保存同一个 id,不声明指向另一个数据库的外键。
命名规范
| 对象 | 规则 | 示例 |
|---|---|---|
| 数据库 | myems_ 前缀,_db 后缀 | myems_system_db |
| 表 | tbl_ 前缀 | tbl_meters |
| 关联表 | tbl_{owner}_{child} | tbl_spaces_meters |
| 小时事实表 | {object}_{measure}_hourly | tbl_meter_hourly |
| 模型事实表 | 同一对象集合,_8760 后缀 | tbl_meter_8760 |
| 主键 | id | id BIGINT NOT NULL AUTO_INCREMENT |
| 业务键 | 配置对象上的 uuid CHAR(36) | 计量表、空间、设备 |
| 时间 | *_datetime_utc 或 utc_date_time | start_datetime_utc |
| 索引 | {table}_index_{n} | tbl_meters_index_1 |
数据库详细说明
1. 系统数据库 (myems_system_db)
myems_system_db 保存主数据,共 166 张表。配置对象通常包含 id、name、uuid 和 description。关联表只保存两个外键(以及 id)。电站下的部件表为每台物理设备存一行,并配有对应的 *_points 表。
能源分类
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_energy_categories | name, uuid, unit_of_measure, kgce, kgco2e | 能源分类及默认换算系数 |
tbl_energy_items | name, uuid, energy_category_id | 分类下的分项 |
kgce 和 kgco2e 是分类上的默认系数。有时间范围的价格和排放因子存放在费率和排放因子表中。
计量表和数据点
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_meters | energy_category_id, energy_item_id, cost_center_id, master_meter_id, is_counted, is_enabled, hourly_low_limit, hourly_high_limit | 在线计量表 |
tbl_offline_meters | 相同的限值和分类字段,没有 master_meter_id | 手工录入的计量表 |
tbl_virtual_meters | equation (LONGTEXT), energy_category_id, energy_item_id, is_counted, is_enabled | 由公式计算的计量表 |
tbl_variables | name, virtual_meter_id, meter_type, meter_id | 虚拟表公式中的变量绑 定 |
tbl_points | data_source_id, object_type, units, high_limit, low_limit, higher_limit, lower_limit, ratio, offset_constant, is_trend, is_virtual, address, faults, definitions | 数据点。address、faults 和 definitions 为 JSON 文本。数据点没有 uuid |
tbl_points_set_values | point_id, utc_date_time, set_value, is_set | 数据点的设定值 |
tbl_meters_points | meter_id, point_id | 计量表与数据点的绑定 |
tbl_meters_commands | meter_id, command_id | 计量表与命令的绑定 |
tbl_points 上的 higher_limit、lower_limit 和 is_in_alarm 供 FDD 服务使用。ratio 和 offset_constant 用于缩放原始值。
数据采集
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_gateways | name, uuid, token, last_seen_datetime_utc | 采集网关 |
tbl_data_sources | gateway_id, protocol, connection (LONGTEXT), process_id, last_seen_datetime_utc | 网关下的连接。connection 为 JSON |
tbl_protocols | name, code | 协议目录 |
tbl_sensors | name, uuid | 传感器 |
tbl_sensors_points | sensor_id, point_id | 传感器与数据点的绑定 |
tbl_iot_sim_cards | iccid, imsi, operator, status, used_traffic, total_traffic | SIM 卡台账。此表没有 uuid |
空间和成本中心
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_spaces | parent_space_id, area, number_of_occupants, timezone_id, contact_id, cost_center_id, latitude, longitude, is_input_counted, is_output_counted | 空间树 |
tbl_cost_centers | name, uuid, external_id | 成本中心 |
tbl_contacts | name, uuid, email, phone | 联系人 |
tbl_timezones | name, utc_offset | 时区 |
tbl_working_calendars | name | 工作日历 |
tbl_working_calendars_non_working_days | working_calendar_id, date_local, description | 非工作日 |
空间通过关联表连接下级对象,这些对象上没有 space_id 列:
tbl_spaces_meters, tbl_spaces_offline_meters, tbl_spaces_virtual_meters, tbl_spaces_points, tbl_spaces_sensors, tbl_spaces_equipments, tbl_spaces_combined_equipments, tbl_spaces_commands, tbl_spaces_shopfloors, tbl_spaces_stores, tbl_spaces_tenants, tbl_spaces_charging_stations, tbl_spaces_microgrids, tbl_spaces_photovoltaic_power_stations, tbl_spaces_energy_storage_power_stations, tbl_spaces_wind_farms, tbl_spaces_distribution_systems, tbl_spaces_energy_flow_diagrams, tbl_spaces_working_calendars.
设备
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_equipments | is_input_counted, is_output_counted, is_enabled, cost_center_id, efficiency_indicator, svg_id, camera_url | 设备 |
tbl_combined_equipments | 与 tbl_equipments 相同的字段 | 组合设备 |
tbl_combined_equipments_equipments | combined_equipment_id, equipment_id | 组合设备的成员 |
两类设备都绑定计量表、离线表、虚拟表、参数、数据源和命令:
tbl_equipments_meters,tbl_equipments_offline_meters,tbl_equipments_virtual_meters,tbl_equipments_parameters,tbl_equipments_data_sources,tbl_equipments_commandstbl_combined_equipments_meters,tbl_combined_equipments_offline_meters,tbl_combined_equipments_virtual_meters,tbl_combined_equipments_parameters,tbl_combined_equipments_data_sources,tbl_combined_equipments_commands
车间、门店和租户
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_shopfloors | area, is_input_counted, is_enabled, contact_id, cost_center_id | 车间 |
tbl_stores | address, latitude, longitude, area, store_type_id, is_input_counted, is_enabled, contact_id, cost_center_id | 门店 |
tbl_store_types | name, uuid, simplified_code | 门店类型 |
tbl_tenants | buildings, floors, rooms, area, tenant_type_id, is_input_counted, is_enabled, is_key_tenant, lease_number, lease_start_datetime_utc, lease_end_datetime_utc, is_in_lease, contact_id, cost_center_id | 租户 |
tbl_tenant_types | name, uuid, simplified_code | 租户类型 |
这三类对象都有计量表、离线表、虚拟表、数据点、传感器、命令和工作日历的关联表。车间还有 tbl_shopfloors_equipments。
光伏电站
tbl_photovoltaic_power_stations 保存 station_code、address、latitude、longitude、latitude_point_id、longitude_point_id、rated_capacity、rated_power、contact_id、cost_center_id、五个 SVG 槽位(svg_id 到 svg5_id)、is_cost_data_displayed、phase_of_lifecycle 和 commissioning_date。
子表:
| 表 | 作用 |
|---|---|
tbl_photovoltaic_power_stations_invertors / _invertors_points | 逆变器及其数据点 |
tbl_photovoltaic_power_stations_grids / _grids_points | 电网连接及其数据点 |
tbl_photovoltaic_power_stations_loads / _loads_points | 负荷及其数据点 |
tbl_photovoltaic_power_stations_data_sources | 数据源 |
tbl_photovoltaic_power_stations_users | 绑定的用户 |
储能
tbl_energy_storage_containers 保存 rated_capacity、rated_power、contact_id 和 cost_center_id。部件表及列出的配套 *_points 表:
| 部件表 | 数据点表 |
|---|---|
tbl_energy_storage_containers_batteries(soc_point_id、power_point_id、charge_meter_id、discharge_meter_id) | — |
tbl_energy_storage_containers_power_conversion_systems | tbl_energy_storage_containers_pcses_points |
| — | tbl_energy_storage_containers_bmses_points(bms_id、point_id;没有 BMS 主表) |
tbl_energy_storage_containers_dcdcs | tbl_energy_storage_containers_dcdcs_points |
tbl_energy_storage_containers_stses | tbl_energy_storage_containers_stses_points |
tbl_energy_storage_containers_grids | tbl_energy_storage_containers_grids_points |
tbl_energy_storage_containers_loads | tbl_energy_storage_containers_loads_points |
tbl_energy_storage_containers_hvacs | tbl_energy_storage_containers_hvacs_points |
tbl_energy_storage_containers_firecontrols | tbl_energy_storage_containers_firecontrols_points |
另外还有:tbl_energy_storage_containers_commands、tbl_energy_storage_containers_data_sources、tbl_energy_storage_containers_schedules。
tbl_energy_storage_power_stations 使用与光伏电站相同的站点字段(address、坐标、额定容量和功率、联系人、成本中心、五个 SVG、生命周期)。集装箱分组在 tbl_energy_storage_power_stations_containers,用户分组在 tbl_energy_storage_power_stations_users。
微电网
tbl_microgrids 在站点字段之外增加 postal_code 和 serial_number。子表:
| 部件 | 数据点 |
|---|---|
tbl_microgrids_batteries | — |
| — | tbl_microgrids_bmses_points(bms_id、point_id;没有 BMS 主表) |
tbl_microgrids_power_conversion_systems | tbl_microgrids_pcses_points |
tbl_microgrids_photovoltaics | tbl_microgrids_pvs_points |
tbl_microgrids_evchargers | tbl_microgrids_evchargers_points |
tbl_microgrids_generators | tbl_microgrids_generators_points |
tbl_microgrids_grids | tbl_microgrids_grids_points |
tbl_microgrids_heatpumps | tbl_microgrids_heatpumps_points |
tbl_microgrids_loads | tbl_microgrids_loads_points |
另外还有:tbl_microgrids_commands、tbl_microgrids_data_sources、tbl_microgrids_schedules、tbl_microgrids_sensors、tbl_microgrids_users。
其他电站和积分器
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_charging_stations | 地 址、坐标、rated_capacity、rated_power、联系人、成本中心、五个 SVG、生命周期 | 充电站 |
tbl_wind_farms | 地址、坐标、rated_power、联系人、成本中心、五个 SVG | 风电场 |
tbl_virtual_power_plants | cost_center_id, balancing_price_point_id, svg_id | 虚拟电厂 |
tbl_virtual_power_plants_microgrids | virtual_power_plant_id, microgrid_id | 虚拟电厂中的微电网 |
tbl_power_integrators | power_point_id, result_point_id, is_enabled | 将功率积分成能耗 |
tbl_fuel_integrators | model, power_point_id, result_point_id, is_enabled | 燃料积分器 |
tbl_heat_integrators | high_temperature_point_id, low_temperature_point_id, flow_point_id, heat_capacity, liquid_density, coefficient, result_point_id, is_enabled | 热量积分器 |
命令和控制
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_commands | topic, payload (LONGTEXT), set_value | 命令定义 |
tbl_control_modes | name, uuid, is_active | 控制模式 |
tbl_control_modes_times | control_mode_id, start_time_of_day, end_time_of_day, power_value, power_point_id, power_equation | 控制模式中的一个时段 |
费率和排放因子
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_tariffs | energy_category_id, tariff_type, unit_of_price, valid_from_datetime_utc, valid_through_datetime_utc | 费率。tariff_type 为 timeofuse |
tbl_tariffs_timeofuses | tariff_id, start_time_of_day, end_time_of_day, peak_type, price DECIMAL(23, 8) | 一天中一个时段的价格。peak_type 为 toppeak、onpeak、midpeak、offpeak 或 deep |
tbl_cost_centers_tariffs | cost_center_id, tariff_id | 费率绑定 |
tbl_emission_factors | energy_category_id, unit_of_factor, valid_from_datetime_utc, valid_through_datetime_utc | 有时间范围的排放因子 |
tbl_emission_factors_timeofuses | emission_factor_id, start_time_of_day, end_time_of_day, factor | 一天中一个时段的因子 |
tbl_cost_centers_emission_factors | cost_center_id, emission_factor_id | 因子绑定 |
图纸、菜单、文件和工单
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_distribution_systems | name, uuid, svg_id | 配电系统 |
tbl_distribution_circuits | distribution_system_id, distribution_room, switchgear, peak_load, peak_current, customers, meters | 回路 |
tbl_distribution_circuits_points | distribution_circuit_id, point_id | 回路数据点 |
tbl_energy_flow_diagrams | name, uuid | 能流图 |
tbl_energy_flow_diagrams_nodes | energy_flow_diagram_id, name | 节点 |
tbl_energy_flow_diagrams_links | energy_flow_diagram_id, source_node_id, target_node_id, meter_uuid | 连线 |
tbl_svgs | name, uuid, source_code (LONGTEXT) | SVG 图形 |
tbl_menus | name, route, parent_menu_id, is_hidden | 菜单树。没有 uuid |
tbl_knowledge_files | file_name, uuid, upload_datetime_utc, upload_user_uuid, file_object (LONGBLOB) | 知识库文件 |
tbl_work_orders | number, category, title, priority, status, belong_to_object_type, belong_to_object_id, source_type, source_id, creator_user_id, assignee_user_id,计划时间和实际时间 | 工单 |
tbl_work_order_logs | work_order_id, user_id, action, from_status, to_status, comment, created_datetime_utc | 状态日志 |
tbl_work_order_files | work_order_id, file_name, file_path, file_size, uploaded_by_user_id | 附件路径。文件字节存放在磁盘上 |
tbl_versions | version, release_date | 模式版本 |
2. 历史数据库 (myems_historical_db)
myems_historical_db 保存数据点原始值和上传的工作簿,共 12 张表。
每一类数值都有一张历史表和一张最新值表。历史行包含 is_bad 和 is_published。最新值行只保留 point_id、utc_date_time 和 actual_value。两者都按 (point_id, utc_date_time) 和 utc_date_time 建索引。
| 表 | actual_value 类型 | 说明 |
|---|---|---|
tbl_analog_value, tbl_analog_value_latest | DECIMAL(21, 6) | 模拟量 |
tbl_energy_value, tbl_energy_value_latest | DECIMAL(21, 6) | 累计能耗 |
tbl_digital_value, tbl_digital_value_latest | INT | 数字量 |
tbl_text_value, tbl_text_value_latest | LONGTEXT | 文本 |
上传文件共用 file_name、uuid、upload_datetime_utc、status(new、done、error)和 file_object(LONGBLOB):
| 表 | 用途 |
|---|---|
tbl_cost_files | 费用工作簿 |
tbl_offline_meter_files | 离线表工作簿 |
tbl_data_repair_files | 数据修复工作簿 |
tbl_energy_plan_files | 能耗计划工作簿 |
3. 能耗数据库 (myems_energy_db)
myems_energy_db 保存小时实际能耗,共 39 张表,没有日、月、年汇总表。报表在查询时把小时向上汇总。
每张表都有 id、父对象 id、start_datetime_utc 和 actual_value DECIMAL(21, 6)。分类表还有 energy_category_id。分项表还有 energy_item_id。组合索引为 (object_id, [分类或分项 id], start_datetime_utc)。
| 分组 | 表 |
|---|---|
| 计量表 | tbl_meter_hourly, tbl_offline_meter_hourly, tbl_virtual_meter_hourly |
| 设备 | tbl_equipment_input_category_hourly, tbl_equipment_input_item_hourly, tbl_equipment_output_category_hourly |
| 组合设备 | tbl_combined_equipment_input_category_hourly, tbl_combined_equipment_input_item_hourly, tbl_combined_equipment_output_category_hourly |
| 空间 | tbl_space_input_category_hourly, tbl_space_input_item_hourly, tbl_space_output_category_hourly |
| 车间 | tbl_shopfloor_input_category_hourly, tbl_shopfloor_input_item_hourly |
| 门店 | tbl_store_input_category_hourly, tbl_store_input_item_hourly |
| 租户 | tbl_tenant_input_category_hourly, tbl_tenant_input_item_hourly |
| 储能集装箱 | tbl_energy_storage_container_{charge,discharge,grid_buy,grid_sell,load}_hourly |
| 储能电站 | tbl_energy_storage_power_station_{charge,discharge,grid_buy,grid_sell,load}_hourly |
| 微电网 | tbl_microgrid_{charge,discharge,evcharger,grid_buy,grid_sell,load,photovoltaic}_hourly |
| 光伏电站 | tbl_photovoltaic_power_station_{generation,grid_buy,grid_sell,load}_hourly |
计量表、离线表、虚拟表、储能、微电网和光伏电站表没有能源分类列。分类由父对象决定。
4. 费用数据库 (myems_billing_db)
myems_billing_db 与 myems_energy_db 拥有相同的 39 张小时表和相同的列。actual_value 是费率货币下的费用。计费读取小时能耗以及绑定到成本中心的费率。
5. 碳排放数据库 (myems_carbon_db)
myems_carbon_db 拥有相同的 39 张小时表。actual_value 是排放量。计算使用小时能耗,以及 tbl_energy_categories.kgco2e 或 tbl_emission_factors 中的分时行。
6. 能耗基准数据库 (myems_energy_baseline_db)
myems_energy_baseline_db 拥有相同的 39 张小时表。actual_value 是该小时的基准值。
7. 能耗模型数据库 (myems_energy_model_db)
myems_energy_model_db 拥有相同的 39 组对象。表名以 _8760 结尾,而不是 _hourly,时间列是 hour_of_year(INT),而不是 start_datetime_utc。示例:tbl_meter_8760(meter_id, hour_of_year, actual_value)。
8. 能耗计划数据库 (myems_energy_plan_db)
myems_energy_plan_db 与 myems_energy_db 拥有相同的 39 张小时表。actual_value 是计划量。计划工作簿先进入 myems_historical_db.tbl_energy_plan_files。
9. 能耗预测数据库 (myems_energy_prediction_db)
myems_energy_prediction_db 拥有相同的 39 张小时表。actual_value 是预测量。
10. FDD 数据库 (myems_fdd_db)
myems_fdd_db 有 9 张表。
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_rules | name, uuid, category, fdd_code, priority, channel, expression, message_template, is_enabled, last_run_datetime_utc, next_run_datetime_utc, is_run_immediately | 故障规则。expression 为 JSON。message_template 是支持 $ 替换的纯文本 |
tbl_email_servers | host, port, requires_authentication, user_name, password, from_addr | SMTP 服务器 |
tbl_email_messages | rule_id, recipient_email, subject, message, attachment_file_object, scheduled_datetime_utc, status | 出站邮件 |
tbl_text_messages_outbox | rule_id, recipient_mobile, message, acknowledge_code, status | 出站短信 |
tbl_text_messages_inbox | sender_mobile, message, received_datetime_utc, status | 入站短信 |
tbl_web_messages | rule_id, user_id, subject, category, priority, message, status, reply, belong_to_object_type, belong_to_object_id | 网页消息 |
tbl_wechat_configs | api_server, app_id, app_secret, access_token, expires_datetime_utc | 微信应用 |
tbl_wechat_messages_outbox | rule_id, recipient_openid, message_template_id, message_data, status | 出站微信消息 |
tbl_wechat_messages_inbox | sender_openid, message, received_datetime_utc, status | 入站微信消息 |
tbl_rules.category 取值为 REALTIME、SYSTEM、SPACE、METER、TENANT、STORE、SHOPFLOOR、EQUIPMENT、COMBINEDEQUIPMENT 之一。priority 为 CRITICAL、HIGH、MEDIUM 或 LOW。channel 为 WEB、EMAIL、SMS、WECHAT 或 CALL。fdd_code 标识规则,例如 REALTIME01 或 SPACE02。
11. 用户数据库 (myems_user_db)
myems_user_db 有 10 张表。
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_users | name, uuid, display_name, email, phone, salt, password, is_admin, is_read_only, privilege_id, account_expiration_datetime_utc, password_expiration_datetime_utc, failed_login_count | 用户。password 是加盐哈希(VARCHAR(256)) |
tbl_privileges | name, data (LONGTEXT, JSON) | 权限集 |
tbl_sessions | user_uuid, token, utc_expires | 登录会话 |
tbl_logs | user_uuid, request_datetime_utc, request_method, resource_type, resource_id, request_body | API 审计日志。request_body 为 JSON |
tbl_api_keys | name, token, created_datetime_utc, expires_datetime_utc | API 密钥。id 为 INT |
tbl_new_users | name, uuid, display_name, email, salt, password | 待审核注册 |
tbl_email_messages | recipient_email, subject, message, scheduled_datetime_utc, status | 用户邮件,例如重置密码。status 为 new、sent 或 timeout |
tbl_email_message_sessions | recipient_email, token, expires_datetime_utc | 邮件操作令牌 |
tbl_verification_codes | recipient_email, verification_code, created_datetime_utc, expires_datetime_utc | 邮箱验证码。id 为 INT |
tbl_notifications | user_id, created_datetime_utc, status, subject, message, url | 站内通知。status 为 unread、read 或 archived |
12. 报表数据库 (myems_reporting_db)
myems_reporting_db 有 4 张表。
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_reports | name, uuid, expression, is_enabled, last_run_datetime_utc, next_run_datetime_utc, is_run_immediately | 报表计划。expression 为 JSON |
tbl_template_files | uuid, report_id, file_name, file_type, file_object | 绑定到报表的模板 |
tbl_reports_files | uuid, create_datetime_utc, file_name, file_type, file_object | 生成的文件 |
tbl_email_messages | recipient_email, subject, message, attachment_file_object, scheduled_datetime_utc, status | 报表投递邮件。此表没有 rule_id |
13. 产量数据库 (myems_production_db)
myems_production_db 有 8 张表。小时产量共用 start_datetime_utc、product_id 和 product_count。
| 表 | 关键字段 | 说明 |
|---|---|---|
tbl_products | name, uuid, unit_of_measure, tag, standard_product_coefficient | 产品 |
tbl_teams | name, uuid, description | 班组 |
tbl_shopfloors_products | shopfloor_id, product_id | 车间生产的产品 |
tbl_shopfloors_teams | shopfloor_id, team_id | 车间上的班组 |
tbl_shifts | shopfloor_id, team_id, product_id, product_count, start_datetime_utc, end_datetime_utc, reference_timestamp | 班次记录 |
tbl_equipment_hourly | equipment_id, start_datetime_utc, product_id, product_count | 单台设备的小时产量 |
tbl_shopfloor_hourly | shopfloor_id, start_datetime_utc, product_id, product_count | 车间的小时产量 |
tbl_space_hourly | space_id, start_datetime_utc, product_id, product_count | 汇总到空间的小时产量 |
数据流转关系
处理顺序:
- 网关把数据点值写入
myems_historical_db。上传的工作簿进入同一数据库的文件表。 - 规范化根据
tbl_points的ratio和offset_constant把数据点值转换成计量表读数。 - 汇总为计量表以及每个父对象(设备、空间、 门店、租户、车间、储能、微电网、光伏电站)在
myems_energy_db写入小时行。 - 计费用
tbl_tariffs/tbl_tariffs_timeofuses乘以这些小时值,写入myems_billing_db。 - 碳排放用
kgco2e或tbl_emission_factors乘以这些小时值,写入myems_carbon_db。 - 基准、模型、计划和预测服务写入各自的数据库。模型库保存
hour_of_year,而不是时间戳。 - FDD 用
tbl_rules.expression对照数据点限值和汇总值求值,然后把邮件、短信、网页或微信消息放入队列。 - 报表读取能耗、费用和碳排放,填入
tbl_template_files,并把结果存入tbl_reports_files。 myems_production_db中的小时产量是能耗强度的分母。
表结构设计规范
通用字段
myems_system_db 中的配置表通常包含:
| 字段 | 类型 | 说明 |
|---|---|---|
id | BIGINT NOT NULL AUTO_INCREMENT | 主键 |
name | VARCHAR(128) 或 VARCHAR(255) | 显示名称 |
uuid | CHAR(36) NOT NULL | 稳定的业务键 |
description | VARCHAR(255) | 可选说明 |
时间序列表和关联表不遵循这一组字段。事实表使用 id、外键和 actual_value。许多关联表只有 id 和两个外键。tbl_points、tbl_menus 和 tbl_iot_sim_cards 没有 uuid。
数据类型
| 用途 | 类型 |
|---|---|
| 主键和外键 | BIGINT(tbl_api_keys 和 tbl_verification_codes 为 INT) |
| 能耗、费用、碳排放、限值、面积 | DECIMAL(21, 6) |
| 费率时段价格 | DECIMAL(23, 8) |
| 纬度 | DECIMAL(12, 10) |
| 经度 | DECIMAL(13, 10) |
| 时间戳 | DATETIME,以 UTC 存储 |
| 日历日期 | DATE |
| 一天中的时间 | TIME |
| 标志 | BOOL |
| 短代码和状态 | VARCHAR |
JSON 文档(address、faults、definitions、connection、规则和报表的 expression、权限 data、request_body) | LONGTEXT |
公式(tbl_virtual_meters.equation、power_equation) | LONGTEXT |
| 数字量数据点值 | INT |
| 文件 | LONGBLOB |
索引
二级索引命名为 {table_name}_index_{n}。
| 模式 | 示例 |
|---|---|
| 按名称查找 | tbl_meters_index_1 (name) |
| 父对象加时间 | tbl_meter_hourly_index_1 (meter_id, start_datetime_utc) |
| 分类加时间 | tbl_space_input_category_hourly_index_1 (space_id, energy_category_id, start_datetime_utc) |
| 数据点历史 | tbl_analog_value_index_1 (point_id, utc_date_time), tbl_analog_value_index_2 (utc_date_time) |
| 费率有效期 | tbl_tariffs_index_2 (energy_category_id, valid_from_datetime_utc, valid_through_datetime_utc) |
脚本不声明外键。引用完整性由 API 保证。