select t.test_id, t.test_name, t.creator_id, creator.nick_name creator_name, t.principal_id, principal.nick_name principal_name, t.test_type_id, ty.test_type_name, t.test_purpose, t.test_status, t.reception_status, t.monitor_timeout_minutes, t.started_at_utc, t.reception_boundary_at_utc, t.ended_at_utc, t.del_flag, t.create_by, t.create_time, t.update_by, t.update_time, t.remark, cast(t.logic_step_mappings_json as char) logic_step_mappings_json, cast(t.console_detail_json as char) console_detail_json, (select count(1) from t_test_battery b where b.test_id = t.test_id and b.del_flag = 0) battery_count, 0 runtime_attach from t_test t left join sys_user creator on creator.user_id = t.creator_id and creator.del_flag = '0' left join sys_user principal on principal.user_id = t.principal_id and principal.del_flag = '0' left join t_test_type ty on ty.test_type_id = t.test_type_id and ty.del_flag = 0 insert into t_test (test_name, creator_id, principal_id, test_type_id, test_purpose, test_status, reception_status, monitor_timeout_minutes, del_flag, create_by, create_time, remark) values (#{testName}, #{creatorId}, #{principalId}, #{testTypeId}, #{testPurpose}, #{testStatus}, #{receptionStatus}, #{monitorTimeoutMinutes}, 0, #{createBy}, #{createTime}, #{remark}) update t_test set test_name = #{testName}, principal_id = #{principalId}, test_type_id = #{testTypeId}, test_purpose = #{testPurpose}, monitor_timeout_minutes = #{monitorTimeoutMinutes}, remark = #{remark}, update_by = #{updateBy}, update_time = #{updateTime} where test_id = #{testId} and test_status = 'WAITING' and reception_status = 'NOT_STARTED' and del_flag = 0 delete from t_test where test_id = #{testId} delete from t_test_channel_binding where test_id = #{testId} delete from t_test_collector_channel where test_id = #{testId} delete from t_test_warning_threshold where test_id = #{testId} delete from t_test_battery where test_id = #{testId} and del_flag = 0 update t_test_warning_threshold set del_flag = threshold_id where test_id = #{testId} and del_flag = 0 insert into t_test_battery(test_id, group_id, battery_no, collector_id, del_flag) values(#{testId}, #{groupId}, #{batteryNo}, #{collectorId}, 0) insert into t_test_channel_binding(test_id, test_battery_id, channel_id, expected_barcode, claim_status) values(#{testId}, #{batteryRelationId}, #{channelId}, #{expectedBarcode}, #{claimStatus}) insert into t_test_collector_channel (test_id, test_battery_id, collector_id, measurement_code, measurement_name, channel_code) values(#{testId}, #{batteryRelationId}, #{collectorId}, #{measurementCode}, #{measurementName}, #{channelCode}) insert into t_test_warning_threshold(test_id, metric_code, min_value, max_value, unit, severity, del_flag) values(#{testId}, #{metricCode}, #{minValue}, #{maxValue}, #{unit}, #{severity}, 0) insert into t_test_warning_exception (test_id, threshold_id, source_type, source_identity, metric_code, abnormal_value, unit, rule_snapshot, severity, exception_status, first_occurred_at_utc, last_occurred_at_utc, occurrence_count) values (#{testId}, #{thresholdId}, #{sourceType}, #{sourceIdentity}, #{metricCode}, #{value}, #{unit}, cast(#{ruleSnapshot} as json), #{severity}, 'OPEN', #{occurredAt}, #{occurredAt}, 1) on duplicate key update abnormal_value = values(abnormal_value), unit = values(unit), last_occurred_at_utc = values(last_occurred_at_utc), occurrence_count = occurrence_count + 1, source_identity = values(source_identity), severity = values(severity), rule_snapshot = values(rule_snapshot) insert into t_test_warning_exception (test_id, exception_type, threshold_id, source_type, source_identity, metric_code, abnormal_value, unit, rule_snapshot, severity, exception_status, first_occurred_at_utc, last_occurred_at_utc, occurrence_count) values (#{testId}, 'DEVICE_OFFLINE', null, #{sourceType}, #{sourceIdentity}, 'DEVICE_ONLINE', null, '', '{"expectedStatus":"ONLINE"}', 'WARNING', 'OPEN', #{occurredAt}, #{occurredAt}, 1) on duplicate key update last_occurred_at_utc = values(last_occurred_at_utc), occurrence_count = occurrence_count + 1 update t_test_warning_exception set exception_status='CLOSED', handled_by=#{handledBy}, handled_at_utc=#{handledAt}, handling_note=#{handlingNote} where exception_id=#{exceptionId} and exception_status='OPEN' insert ignore into t_test_realtime_record (test_id, test_battery_id, binding_id, adapter_code, source_identity, source_record_id, cabinet_devtype, cabinet_devid, cabinet_subdevid, cabinet_chlid, cabinet_sequence_id, cabinet_device_time_utc, cabinet_device_time_raw, cabinet_adapter_timezone_id, collector_id, collector_channel_code, collector_sequence_id, collector_device_time_utc, collector_device_time_raw, collector_adapter_timezone_id, capture_slot_utc, server_received_at_utc, cycle_no, step_no, step_type, step_name, voltage_v, current_a, capacity_ah, energy_wh, temperature, positive_potential, negative_potential, extension_measurements_json, content_sha256) values (#{testId}, #{testBatteryId}, #{bindingId}, #{adapterCode}, #{sourceIdentity}, #{sourceRecordId}, #{cabinetDevtype}, #{cabinetDevid}, #{cabinetSubdevid}, #{cabinetChlid}, #{cabinetSequenceId}, #{cabinetDeviceTimeUtc}, #{cabinetDeviceTimeRaw}, #{cabinetAdapterTimezoneId}, #{collectorId}, #{collectorChannelCode}, #{collectorSequenceId}, #{collectorDeviceTimeUtc}, #{collectorDeviceTimeRaw}, #{collectorAdapterTimezoneId}, #{captureSlotUtc}, #{serverReceivedAtUtc}, #{cycleNo}, #{stepNo}, #{stepType}, #{stepName}, #{voltageV}, #{currentA}, #{capacityAh}, #{energyWh}, #{temperature}, #{positivePotential}, #{negativePotential}, cast(#{extensionMeasurementsJson} as json), #{contentSha256}) insert ignore into t_test_step_record (test_id, test_battery_id, binding_id, adapter_code, source_identity, source_record_id, dedupe_key, adapter_timezone_id, device_time_utc, device_time_raw, server_received_at_utc, cycle_no, step_no, step_type, step_name, voltage_v, current_a, capacity_ah, energy_wh, extension_measurements_json, content_sha256) values (#{testId}, #{testBatteryId}, #{bindingId}, #{adapterCode}, #{sourceIdentity}, #{sourceRecordId}, #{dedupeKey}, #{adapterTimezoneId}, #{deviceTimeUtc}, #{deviceTimeRaw}, #{serverReceivedAtUtc}, #{cycleNo}, #{stepNo}, #{stepType}, #{stepName}, #{voltageV}, #{currentA}, #{capacityAh}, #{energyWh}, cast(#{extensionMeasurementsJson} as json), #{contentSha256}) insert ignore into t_test_cycle_record (test_id, test_battery_id, binding_id, adapter_code, source_identity, source_record_id, source_kind, dedupe_key, adapter_timezone_id, device_time_utc, device_time_raw, server_received_at_utc, cycle_no, charge_capacity_ah, discharge_capacity_ah, charge_energy_wh, discharge_energy_wh, efficiency, extension_measurements_json, content_sha256) values (#{testId}, #{testBatteryId}, #{bindingId}, #{adapterCode}, #{sourceIdentity}, #{sourceRecordId}, #{sourceKind}, #{dedupeKey}, #{adapterTimezoneId}, #{deviceTimeUtc}, #{deviceTimeRaw}, #{serverReceivedAtUtc}, #{cycleNo}, #{chargeCapacityAh}, #{dischargeCapacityAh}, #{chargeEnergyWh}, #{dischargeEnergyWh}, #{efficiency}, cast(#{extensionMeasurementsJson} as json), #{contentSha256}) update t_test set logic_step_mappings_json = cast(#{mappingsJson} as json), update_by = #{updateBy}, update_time = #{updateTime} where test_id = #{testId} and del_flag = 0 update t_test set console_detail_json = cast(#{detailJson} as json) where test_id = #{testId} and del_flag = 0 update t_test set test_status = 'RUNNING', reception_status = 'RECEIVING', started_at_utc = coalesce(started_at_utc, #{startedAtUtc}), reception_boundary_at_utc = #{startedAtUtc}, update_by = #{updateBy}, update_time = #{startedAtUtc} where test_id = #{testId} and test_status = 'WAITING' and reception_status = 'NOT_STARTED' and del_flag = 0 update t_test set test_status = 'PAUSED', reception_status = 'PAUSED', update_by = #{updateBy}, update_time = #{updatedAtUtc} where test_id = #{testId} and test_status = 'RUNNING' and reception_status = 'RECEIVING' and del_flag = 0 update t_test set test_status = 'RUNNING', reception_status = 'RECEIVING', reception_boundary_at_utc = #{updatedAtUtc}, update_by = #{updateBy}, update_time = #{updatedAtUtc} where test_id = #{testId} and test_status = 'PAUSED' and reception_status = 'PAUSED' and del_flag = 0 update t_test set test_status = 'COMPLETED', reception_status = 'ENDED', ended_at_utc = #{endedAtUtc}, update_by = #{updateBy}, update_time = #{endedAtUtc} where test_id = #{testId} and ((test_status = 'RUNNING' and reception_status = 'RECEIVING') or (test_status = 'PAUSED' and reception_status = 'PAUSED')) and del_flag = 0 insert into t_test_data_revision_action (test_id, data_type, operation_type, scope_summary, identity_summary, before_content_json, changes_summary, reason, operator_id, operator_name, created_at_utc) values (#{testId}, #{dataType}, #{operationType}, #{scopeSummary}, cast(#{identitySummary} as json), cast(#{beforeContentJson} as json), cast(#{changesSummary} as json), #{reason}, #{operatorId}, #{operatorName}, #{createdAtUtc}) delete from t_test_realtime_record where test_id=#{testId} and record_id in #{id} delete from t_test_step_record where test_id=#{testId} and step_record_id in #{id} delete from t_test_cycle_record where test_id=#{testId} and cycle_record_id in #{id} delete from t_test_realtime_record where test_id=#{testId} delete from t_test_step_record where test_id=#{testId} delete from t_test_cycle_record where test_id=#{testId} delete from t_test_data_revision_action where test_id=#{testId} delete from t_test_warning_exception where test_id=#{testId} delete from t_test_logic_step_mapping where test_id=#{testId} t_test_realtime_recordt_test_step_recordt_test_cycle_record record_idstep_record_idcycle_record_id update set ${column}=#{value} where test_id=#{testId} and =#{recordId} delete from where test_id=#{testId} and =#{recordId} insert into (${column}) values (#{value})