fix: write_holding_strategy保留full_analysis+reassessed_at防止被清空
This commit is contained in:
+18
-2
@@ -1083,6 +1083,18 @@ def write_holding_strategy(conn, code: str, name: str, data: dict) -> tuple[bool
|
||||
quality_issues_j = _json.dumps(data.get('quality_issues', {}), ensure_ascii=False) if isinstance(data.get('quality_issues'), dict) else data.get('quality_issues_json', '')
|
||||
signal_factors_j = _json.dumps(data.get('signal_factors', []), ensure_ascii=False) if isinstance(data.get('signal_factors'), list) else data.get('signal_factors_json', '')
|
||||
|
||||
# 在DELETE前保留现有的full_analysis和reassessed_at(防止被regenerate_all等清空)
|
||||
_existing_fa = data.get('full_analysis', '')
|
||||
_existing_ra = data.get('reassessed_at', '')
|
||||
if not _existing_fa:
|
||||
try:
|
||||
_old = conn.execute("SELECT full_analysis, reassessed_at FROM holding_strategies WHERE code=? ORDER BY id DESC LIMIT 1", (code,)).fetchone()
|
||||
if _old:
|
||||
if _old[0]: _existing_fa = _old[0]
|
||||
if _old[1]: _existing_ra = _old[1]
|
||||
except:
|
||||
pass
|
||||
|
||||
# DELETE + INSERT
|
||||
conn.execute("DELETE FROM holding_strategies WHERE code=?", (code,))
|
||||
conn.execute("""
|
||||
@@ -1094,10 +1106,11 @@ def write_holding_strategy(conn, code: str, name: str, data: dict) -> tuple[bool
|
||||
source, reason, updated_at,
|
||||
avg_price, decision_timestamp, note, quality_check,
|
||||
quality_checked_at, quality_issues_json, position_advice,
|
||||
signal_factors_json, time_horizon, decision_type)
|
||||
signal_factors_json, time_horizon, decision_type,
|
||||
full_analysis, reassessed_at)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
|
||||
datetime('now','localtime'),
|
||||
?,?,?,?,?,?,?,?,?,?)
|
||||
?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
""", (
|
||||
code, name,
|
||||
data.get('version', 1), data.get('price'), data.get('cost'),
|
||||
@@ -1120,6 +1133,9 @@ def write_holding_strategy(conn, code: str, name: str, data: dict) -> tuple[bool
|
||||
signal_factors_j,
|
||||
data.get('time_horizon', ''),
|
||||
data.get('type', data.get('strategy_type', 'holding')),
|
||||
# 保留full_analysis和reassessed_at
|
||||
_existing_fa,
|
||||
_existing_ra,
|
||||
))
|
||||
conn.commit()
|
||||
return True, f"策略 {code} 已写入"
|
||||
|
||||
Reference in New Issue
Block a user