@@ -185,13 +185,17 @@ impl Db {
185185 . map_err ( Into :: into)
186186 }
187187
188- /// 追加一条 OCR 块(实时落库)。
188+ /// 追加一条 OCR 块(实时落库;v0.7.3 起双写 bbox/screen_id——REQ-156 )。
189189 pub fn add_ocr_block ( & self , new : & NewSessionOcrBlock ) -> Result < SessionOcrBlock > {
190190 let conn = self . conn . lock ( ) . expect ( "db lock poisoned" ) ;
191+ // bbox 序列化为 JSON {x,y,w,h}(帧坐标系;None → NULL=旧口径)
192+ let bbox_json = new. bbox . map ( |b| {
193+ serde_json:: json!( { "x" : b. x, "y" : b. y, "w" : b. w, "h" : b. h } ) . to_string ( )
194+ } ) ;
191195 conn. execute (
192- "INSERT INTO session_ocr_blocks (session_id, timestamp_ms, text, score, region, region_kind)
193- VALUES (?1, ?2, ?3, ?4, ?5, ?6)" ,
194- params ! [ new. session_id, new. timestamp_ms, new. text, new. score, new. region, new. region_kind] ,
196+ "INSERT INTO session_ocr_blocks (session_id, timestamp_ms, text, score, region, region_kind, bbox, screen_id )
197+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8 )" ,
198+ params ! [ new. session_id, new. timestamp_ms, new. text, new. score, new. region, new. region_kind, bbox_json , new . screen_id ] ,
195199 ) ?;
196200 Ok ( SessionOcrBlock {
197201 id : conn. last_insert_rowid ( ) ,
@@ -201,6 +205,8 @@ impl Db {
201205 score : new. score ,
202206 region : new. region . clone ( ) ,
203207 region_kind : new. region_kind . clone ( ) ,
208+ bbox : new. bbox ,
209+ screen_id : new. screen_id ,
204210 } )
205211 }
206212
@@ -275,11 +281,11 @@ impl Db {
275281 Ok ( affected > 0 )
276282 }
277283
278- /// 列出会话全部 OCR 块(按时间轴升序)。
284+ /// 列出会话全部 OCR 块(按时间轴升序;v0.7.3 起含 bbox/screen_id 列 )。
279285 pub fn list_ocr_blocks ( & self , session_id : i64 ) -> Result < Vec < SessionOcrBlock > > {
280286 let conn = self . conn . lock ( ) . expect ( "db lock poisoned" ) ;
281287 let mut stmt = conn. prepare (
282- "SELECT id, session_id, timestamp_ms, text, score, region, region_kind
288+ "SELECT id, session_id, timestamp_ms, text, score, region, region_kind, bbox, screen_id
283289 FROM session_ocr_blocks WHERE session_id = ?1 ORDER BY timestamp_ms ASC" ,
284290 ) ?;
285291 let rows = stmt. query_map ( params ! [ session_id] , row_to_ocr_block) ?;
0 commit comments