multi slct del

This commit is contained in:
2026-05-26 15:34:06 +05:30
parent b99d02e29a
commit f83724951f
4 changed files with 269 additions and 43 deletions

View File

@@ -2109,14 +2109,45 @@ pub async fn export_assets(
"source" => {
// Round-trippable JSON in the same shape import_*_assets accept.
// Fixed and range objects are written into separate top-level keys
// so the user can re-feed each via the matching importer. Includes
// deleted=true rows so the audit state survives a round-trip.
// so the user can re-feed each via the matching importer. BBox
// fields are merged inline using the same prefixed-key convention
// the importer parses (`bbox_*` for fixed, `start_bbox_*` /
// `mid_bbox_*` / `end_bbox_*` for range) so a re-import preserves
// every bbox the user drew.
let bbox_rows: Vec<(i64, String, f64, f64, f64, f64)> =
sqlx::query_as(
"SELECT b.asset_id, b.slot, b.x1, b.y1, b.x2, b.y2
FROM asset_bboxes b
JOIN assets a ON a.id = b.asset_id
WHERE a.deleted = 0",
)
.fetch_all(&state.pool)
.await
.map_err(|e| e.to_string())?;
let mut bbox_by_asset: std::collections::HashMap<
i64,
std::collections::HashMap<String, (f64, f64, f64, f64)>,
> = std::collections::HashMap::new();
for (aid, slot, x1, y1, x2, y2) in bbox_rows {
bbox_by_asset
.entry(aid)
.or_default()
.insert(slot, (x1, y1, x2, y2));
}
let inject_bbox = |obj: &mut serde_json::Value, prefix: &str, bb: &(f64, f64, f64, f64)| {
if let Some(map) = obj.as_object_mut() {
map.insert(format!("{prefix}bbox_x1"), serde_json::json!(bb.0));
map.insert(format!("{prefix}bbox_y1"), serde_json::json!(bb.1));
map.insert(format!("{prefix}bbox_x2"), serde_json::json!(bb.2));
map.insert(format!("{prefix}bbox_y2"), serde_json::json!(bb.3));
}
};
let mut fixed_arr: Vec<serde_json::Value> = vec![];
let mut range_arr: Vec<serde_json::Value> = vec![];
for a in &assets {
if a.asset_type == "fixed" {
if let (Some(la), Some(ln)) = (a.lat, a.lng) {
fixed_arr.push(serde_json::json!({
let mut obj = serde_json::json!({
"row_id": a.row_id,
"asset_name": a.asset_name,
"video_name": a.video_name,
@@ -2124,13 +2155,19 @@ pub async fn export_assets(
"coord": [la, ln],
"deleted": a.deleted != 0,
"side": a.side,
}));
});
if let Some(slots) = bbox_by_asset.get(&a.id) {
if let Some(bb) = slots.get("fixed") {
inject_bbox(&mut obj, "", bb);
}
}
fixed_arr.push(obj);
}
} else if a.asset_type == "range" {
if let (Some(la), Some(ln), Some(sla), Some(sln), Some(ela), Some(eln)) =
(a.lat, a.lng, a.start_lat, a.start_lng, a.end_lat, a.end_lng)
{
range_arr.push(serde_json::json!({
let mut obj = serde_json::json!({
"row_id": a.row_id,
"asset_name": a.asset_name,
"video_name": a.video_name,
@@ -2145,7 +2182,19 @@ pub async fn export_assets(
"image_path3": a.image_path3,
"deleted": a.deleted != 0,
"side": a.side,
}));
});
if let Some(slots) = bbox_by_asset.get(&a.id) {
if let Some(bb) = slots.get("start") {
inject_bbox(&mut obj, "start_", bb);
}
if let Some(bb) = slots.get("mid") {
inject_bbox(&mut obj, "mid_", bb);
}
if let Some(bb) = slots.get("end") {
inject_bbox(&mut obj, "end_", bb);
}
}
range_arr.push(obj);
}
}
}