67 lines
2.8 KiB
Python
67 lines
2.8 KiB
Python
import traceback
|
|
|
|
from pymongo import UpdateOne
|
|
from pydantic import Field
|
|
import pandas as pd
|
|
|
|
from .task import Task
|
|
from utils import *
|
|
from model import IntStr, IntFloat, BaseModel, ValidationError
|
|
|
|
|
|
class FirstRecharge(Task):
|
|
"""
|
|
首次充值记录
|
|
"""
|
|
|
|
class Model(BaseModel):
|
|
role_level: int = Field(None, title='角色等级')
|
|
role_vip: int = Field(None, title='vip等级')
|
|
role_stage: IntStr = Field(None, title='关卡')
|
|
event_time: int = Field(..., title="事件时间", alias='_event_time')
|
|
money: IntFloat = Field(..., title='金额')
|
|
game_role_id: str = Field(..., min_length=1, title='角色id', alias='_game_role_id')
|
|
orderid: str = Field(..., min_length=1, title='订单号')
|
|
proid: str = Field(..., min_length=1, title='计费点')
|
|
cdate: int = Field(..., title='当天0点')
|
|
|
|
|
|
def cleaning(self, cursor_list):
|
|
for cursor in cursor_list: # type:dict
|
|
for source_coll, ts in cursor.items(): # type:str,dict
|
|
if ts['cursor_st'] == ts['cursor_et']:
|
|
continue
|
|
logger.info(f'开始处理{self.game_name} 处理 {source_coll} 游标 {ts}')
|
|
where = {
|
|
'_ut': {
|
|
'$gte': ts['cursor_st'],
|
|
'$lt': ts['cursor_et'],
|
|
}
|
|
}
|
|
|
|
projection = self.Model.get_fields()
|
|
bulk_data = []
|
|
for item in self.local_db[source_coll].find(where, projection):
|
|
try:
|
|
item['cdate'] = int(pd.Timestamp(item['_event_time'], unit='s', tz=self.timezone) \
|
|
.normalize().timestamp())
|
|
model = self.Model(**item)
|
|
data = model.dict(by_alias=True)
|
|
_game_role_id = data.pop('_game_role_id')
|
|
bulk_data.append(
|
|
UpdateOne({'_game_role_id': _game_role_id, 'is_recharge': {'$exists': False}},
|
|
{'$set': {'is_recharge': data}}))
|
|
except ValidationError as e:
|
|
msg = traceback.format_exc()
|
|
ddsend_msg(f'{self.game_name}.{source_coll}字段验证异常 {msg}\n{e.json()}')
|
|
logger.error(repr(e))
|
|
|
|
except Exception as e:
|
|
msg = traceback.format_exc()
|
|
ddsend_msg(f'未知异常 {msg}')
|
|
logger.error(repr(e))
|
|
if bulk_data:
|
|
self.local_db[self.dest_coll].bulk_write(bulk_data, ordered=False)
|
|
self.remote_db[self.dest_coll].bulk_write(bulk_data, ordered=False)
|
|
self.set_cursor(cursor_st=ts['cursor_st'], cursor_et=ts['cursor_et'])
|