| | |
| | | <result property="devid" column="devid"/> |
| | | <result property="subdevid" column="subdevid"/> |
| | | <result property="chlid" column="chlid"/> |
| | | <result property="vendorChannelNo" column="vendor_channel_no"/> |
| | | <result property="recordSequence" column="record_sequence"/> |
| | | <result property="recordKey" column="record_key"/> |
| | | <result property="sourceRef" column="source_ref"/> |
| | |
| | | </resultMap> |
| | | |
| | | <!-- 落地行的显式列名,顺序与建表脚本一致;列集合不随运行期表结构变化。 --> |
| | | <sql id="ingestColumns">ingest_id, adapter_code, payload_kind, devtype, devid, subdevid, chlid, record_sequence, record_key, |
| | | <sql id="ingestColumns">ingest_id, adapter_code, payload_kind, devtype, devid, subdevid, chlid, vendor_channel_no, |
| | | record_sequence, record_key, |
| | | source_ref, device_time_utc, device_time_raw, timezone_id, cycle_no, step_no, relative_time_seconds, |
| | | voltage_v, current_a, charge_capacity_ah, discharge_capacity_ah, charge_energy_wh, discharge_energy_wh, |
| | | payload_json, content_sha256, received_at_utc</sql> |
| | |
| | | <result property="devid" column="devid"/> |
| | | <result property="subdevid" column="subdevid"/> |
| | | <result property="chlid" column="chlid"/> |
| | | <result property="vendorChannelNo" column="vendor_channel_no"/> |
| | | <result property="lastDataAt" column="last_data_at"/> |
| | | </resultMap> |
| | | |
| | |
| | | <insert id="insertIngestRecord" parameterType="com.battery.business.domain.TDeviceIngestRecord" |
| | | useGeneratedKeys="true" keyProperty="ingestId"> |
| | | insert ignore into t_device_ingest_record |
| | | (adapter_code, payload_kind, devtype, devid, subdevid, chlid, record_sequence, record_key, source_ref, |
| | | (adapter_code, payload_kind, devtype, devid, subdevid, chlid, vendor_channel_no, record_sequence, record_key, |
| | | source_ref, |
| | | device_time_utc, device_time_raw, timezone_id, cycle_no, step_no, relative_time_seconds, |
| | | voltage_v, current_a, charge_capacity_ah, discharge_capacity_ah, charge_energy_wh, discharge_energy_wh, |
| | | payload_json, content_sha256, received_at_utc) |
| | | values (#{adapterCode}, #{payloadKind}, #{devtype}, #{devid}, #{subdevid}, #{chlid}, #{recordSequence}, |
| | | values (#{adapterCode}, #{payloadKind}, #{devtype}, #{devid}, #{subdevid}, #{chlid}, #{vendorChannelNo}, |
| | | #{recordSequence}, |
| | | #{recordKey}, #{sourceRef}, #{deviceTimeUtc}, #{deviceTimeRaw}, #{timezoneId}, #{cycleNo}, #{stepNo}, |
| | | #{relativeTimeSeconds}, #{voltageV}, #{currentA}, #{chargeCapacityAh}, #{dischargeCapacityAh}, |
| | | #{chargeEnergyWh}, #{dischargeEnergyWh}, cast(#{payloadJson} as json), #{contentSha256}, #{receivedAtUtc}) |
| | |
| | | <!-- 心跳单独占一行并覆盖接收时间:它只表示"取数程序还在推",不是设备事实,没有保留历史的意义。 --> |
| | | <insert id="upsertHeartbeat" parameterType="com.battery.business.domain.TDeviceIngestRecord"> |
| | | insert into t_device_ingest_record |
| | | (adapter_code, payload_kind, devtype, devid, subdevid, chlid, record_sequence, record_key, source_ref, |
| | | (adapter_code, payload_kind, devtype, devid, subdevid, chlid, vendor_channel_no, record_sequence, record_key, |
| | | source_ref, |
| | | device_time_utc, device_time_raw, timezone_id, cycle_no, step_no, relative_time_seconds, |
| | | voltage_v, current_a, charge_capacity_ah, discharge_capacity_ah, charge_energy_wh, discharge_energy_wh, |
| | | payload_json, content_sha256, received_at_utc) |
| | | values (#{adapterCode}, #{payloadKind}, #{devtype}, #{devid}, #{subdevid}, #{chlid}, #{recordSequence}, |
| | | values (#{adapterCode}, #{payloadKind}, #{devtype}, #{devid}, #{subdevid}, #{chlid}, #{vendorChannelNo}, |
| | | #{recordSequence}, |
| | | #{recordKey}, #{sourceRef}, #{deviceTimeUtc}, #{deviceTimeRaw}, #{timezoneId}, #{cycleNo}, #{stepNo}, |
| | | #{relativeTimeSeconds}, #{voltageV}, #{currentA}, #{chargeCapacityAh}, #{dischargeCapacityAh}, |
| | | #{chargeEnergyWh}, #{dischargeEnergyWh}, cast(#{payloadJson} as json), #{contentSha256}, #{receivedAtUtc}) |
| | | on duplicate key update received_at_utc = values(received_at_utc) |
| | | </insert> |
| | | |
| | | <!-- 拓扑行是声明不是设备事实:重复上报刷新声明内容(例如来源补上它自己的通道号),不追加新行。 --> |
| | | <insert id="upsertTopology" parameterType="com.battery.business.domain.TDeviceIngestRecord"> |
| | | insert into t_device_ingest_record |
| | | (adapter_code, payload_kind, devtype, devid, subdevid, chlid, vendor_channel_no, record_sequence, record_key, |
| | | source_ref, |
| | | device_time_utc, device_time_raw, timezone_id, cycle_no, step_no, relative_time_seconds, |
| | | voltage_v, current_a, charge_capacity_ah, discharge_capacity_ah, charge_energy_wh, discharge_energy_wh, |
| | | payload_json, content_sha256, received_at_utc) |
| | | values (#{adapterCode}, #{payloadKind}, #{devtype}, #{devid}, #{subdevid}, #{chlid}, #{vendorChannelNo}, |
| | | #{recordSequence}, |
| | | #{recordKey}, #{sourceRef}, #{deviceTimeUtc}, #{deviceTimeRaw}, #{timezoneId}, #{cycleNo}, #{stepNo}, |
| | | #{relativeTimeSeconds}, #{voltageV}, #{currentA}, #{chargeCapacityAh}, #{dischargeCapacityAh}, |
| | | #{chargeEnergyWh}, #{dischargeEnergyWh}, cast(#{payloadJson} as json), #{contentSha256}, #{receivedAtUtc}) |
| | | on duplicate key update vendor_channel_no = values(vendor_channel_no), |
| | | payload_json = values(payload_json), content_sha256 = values(content_sha256), |
| | | received_at_utc = values(received_at_utc) |
| | | </insert> |
| | | |
| | | <select id="selectIngestRecordHashByKey" resultType="string"> |
| | |
| | | |
| | | <!-- 最近数据时间取该通道自己的采样行:没有新采样行就是没有,不按拓扑上报时间代替。 --> |
| | | <select id="selectTopologyChannels" resultMap="TDeviceIngestChannelResultMap"> |
| | | select t.devtype, t.devid, t.subdevid, t.chlid, |
| | | select t.devtype, t.devid, t.subdevid, t.chlid, t.vendor_channel_no, |
| | | (select max(prior.device_time_utc) from t_device_ingest_record prior |
| | | where prior.adapter_code = t.adapter_code and prior.payload_kind = 'SAMPLE' |
| | | and prior.devtype = t.devtype and prior.devid = t.devid |