jdbc.update("INSERT INTO tool_call(id,task_id,provider,tool_name,client_version,status,cost_units) VALUES(?,?,'LOCAL','ENTITY_CACHE','D3','SUCCEEDED',0)",call,child);
jdbc.update("INSERT INTO agent_task(id,user_id,operation,workflow,skill_version,request_json,request_hash,idempotency_key,status,max_calls,max_cost_units) VALUES(?,?,?,?,?,?,?,?,?,?,?)",
varprofiles=jdbc.queryForList("SELECT document FROM company_profile WHERE user_id=?",String.class,owner);
jdbc.update("UPDATE agent_task SET profile_snapshot=? WHERE id=?",profiles.isEmpty()?json.write(com.example.rzgb.profile.CompanyProfile.empty()):profiles.getFirst(),id);
if(!terminal(source.get("status").toString())||jdbc.queryForObject("SELECT COUNT(*) FROM research_entity WHERE task_id=? AND entity_key LIKE 'entity:%'",Integer.class,parent)!=r.companies().size())
if(r.targetProjectId()==null||jdbc.queryForObject("SELECT COUNT(*) FROM search_item WHERE batch_id=? AND project_id=?",Integer.class,parent,r.targetProjectId())!=1)
if(jdbc.queryForObject("SELECT COUNT(*) FROM agent_task WHERE parent_id=? AND status NOT IN ('SUCCEEDED','FAILED','PARTIAL','CANCELLED')",Integer.class,parent)>0)
varcandidate=json.convert(jdbc.queryForObject("SELECT snapshot FROM search_item WHERE batch_id=? AND project_id=?",String.class,parent,r.targetProjectId()),OpportunityRanking.Candidate.class);
jdbc.update("INSERT INTO tool_call(id,task_id,provider,tool_name,client_version,status) VALUES(?,?,?,?,?,'STARTED')",call,id,step.operation().zlbx()?"ZLBX":"DEEPSEEK",step.tool(),request.workflow().client);
if(call!=null&&jdbc.update("UPDATE tool_call SET status=?,error_code=?,http_status=?,duration_ms=? WHERE id=? AND status='STARTED'",code.equals("RESULT_UNKNOWN")?"UNKNOWN":"FAILED",code,einstanceofApiExceptiona?a.upstreamStatus:null,duration,call)>0)
if(!status(id).equals("CANCELLED"))transition(id,jdbc.queryForObject("SELECT COUNT(*) FROM research_step WHERE task_id=?",Integer.class,id)>0?"PARTIAL":"FAILED",message);
jdbc.update("UPDATE tool_call SET status='SUCCEEDED',http_status=?,cost_units=?,input_tokens=?,output_tokens=?,actual_model=?,duration_ms=? WHERE id=?",
jdbc.update("INSERT INTO search_item(batch_id,position,project_id,snapshot,analysis_snapshot,analysis_hash,ranking_snapshot,ranking_hash) VALUES(?,?,?,?,?,?,?,?)",id,position++,project,
returnoperation==null?jdbc.queryForList("SELECT id FROM agent_task WHERE user_id=? ORDER BY created_at DESC,id LIMIT 50",String.class,owner)
:jdbc.queryForList("SELECT id FROM agent_task WHERE user_id=? AND operation=? ORDER BY created_at DESC,id LIMIT 50",String.class,owner,operation.name());
returnjdbc.query("SELECT w.*,p.document FROM watch_record w JOIN project p ON p.id=w.project_id WHERE w.user_id=? ORDER BY w.created_at DESC,w.id",(rs,n)->{
row.put("tags",jdbc.queryForList("SELECT t.name FROM tag t JOIN watch_tag wt ON wt.tag_id=t.id WHERE wt.watch_id=? ORDER BY t.name",String.class,watch));
returnjdbc.query("SELECT status,note,created_at,record_version FROM watch_history WHERE watch_id=? ORDER BY COALESCE(record_version,1),created_at,id",(rs,n)->{
if(jdbc.queryForObject("SELECT COUNT(*) FROM watch_record WHERE user_id=? AND project_id=?",Integer.class,owner,projectId)==0){
Stringid=UUID.randomUUID().toString();
jdbc.update("INSERT INTO watch_record(id,user_id,project_id,status,note) VALUES(?,?,?,'已关注','')",id,owner,projectId);
jdbc.update("INSERT INTO watch_history(id,watch_id,status,note,actor_id,record_version) VALUES(?,?,'已关注','',?,1)",UUID.randomUUID().toString(),id,owner);
jdbc.update("UPDATE watch_record SET status=?,note=?,version=? WHERE id=?",status,note,version,id);
jdbc.update("INSERT INTO watch_history(id,watch_id,status,note,actor_id,record_version) VALUES(?,?,?,?,?,?)",UUID.randomUUID().toString(),id,status,note,owner,version);
returnjdbc.query("SELECT id,name FROM tag WHERE user_id=? ORDER BY name,id",(rs,n)->Map.of("id",rs.getString(1),"name",rs.getString(2)),user.id(auth));
jdbc.update("UPDATE watch_record SET version=version+1 WHERE user_id=? AND id IN (SELECT watch_id FROM watch_tag WHERE tag_id IN (SELECT id FROM tag WHERE id=? AND user_id=?))",owner,id,owner);
jdbc.update("DELETE FROM tag WHERE id=? AND user_id=?",id,owner);returnMap.of("deleted",true);
List<String>current=jdbc.queryForList("SELECT t.name FROM tag t JOIN watch_tag wt ON wt.tag_id=t.id WHERE wt.watch_id=? ORDER BY t.name",String.class,id);
longversion=selection.version();
if(!current.equals(names)){
jdbc.update("DELETE FROM watch_tag WHERE watch_id=?",id);
for(Stringtag:ids)jdbc.update("INSERT INTO watch_tag(watch_id,tag_id) VALUES(?,?)",id,tag);
jdbc.update("UPDATE watch_record SET version=version+1 WHERE id=?",id);version++;
Stringid=conversation(),other=UUID.randomUUID().toString();jdbc.update("INSERT INTO app_user(id,username,password_hash) VALUES(?,'d4-other','test-only')",other);