Commit e10b6aea authored by 陈涛's avatar 陈涛

修改定时任务执行处理逻辑

parent 9cf72fd9
...@@ -68,7 +68,8 @@ async def calculate_nav(fund_id, calc_time=None, beach_service=BeaconChaService( ...@@ -68,7 +68,8 @@ async def calculate_nav(fund_id, calc_time=None, beach_service=BeaconChaService(
result = await cursor.to_list(length=None) result = await cursor.to_list(length=None)
total_fund_share = sum(-item["fund_share"] if item["bill_type"] == "redemption" else item["fund_share"] for item in result) total_fund_share = sum(-item["fund_share"] if item["bill_type"] == "redemption" else item["fund_share"] for item in result)
value = sum(nav.values()) value = sum(nav.values())
net_value = round(value / total_fund_share, 2) net_value = round(value / total_fund_share, 2) if total_fund_share else fund_data["base_nav"]
await fund_collect.update_one({'id': fund_id}, {"$set": {"nva": net_value}})
nav_collect = get_nav_collect(app.state.mongodb_manager) nav_collect = get_nav_collect(app.state.mongodb_manager)
nav_record = await nav_collect.find_one({"fund_id": fund_id, "record_date": date}) nav_record = await nav_collect.find_one({"fund_id": fund_id, "record_date": date})
if nav_record: if nav_record:
...@@ -85,7 +86,7 @@ async def calculate_nav(fund_id, calc_time=None, beach_service=BeaconChaService( ...@@ -85,7 +86,7 @@ async def calculate_nav(fund_id, calc_time=None, beach_service=BeaconChaService(
else: else:
fund_nav[key] = value fund_nav[key] = value
fund_nav["record_date"] = date fund_nav["record_date"] = date
fund_nav["net_value"] = net_value fund_nav["nav"] = net_value
insert = await nav_collect.insert_one(fund_nav) insert = await nav_collect.insert_one(fund_nav)
if not insert.acknowledged: if not insert.acknowledged:
error = f'写入净值记录失败 [{fund_nav}] [mongo] [{date}]' error = f'写入净值记录失败 [{fund_nav}] [mongo] [{date}]'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment