Beispiel #1
0
 def update_pan_account_by_acc_id(cls, acc_id, params):
     _params = {
         p: params[p]
         for p in params if p in PanAccounts.field_names()
     }
     with db:
         PanAccounts.update(**_params).where(
             PanAccounts.user_id == acc_id).execute()
Beispiel #2
0
 def check_pan_token_validation(self, pan_acc: PanAccounts):
     if compare_dt_by_now(pan_acc.expires_at) <= 0:
         new_pan = self.fresh_token(pan_acc.id)
         if new_pan:
             pan_acc.access_token = new_pan.access_token
             pan_acc.refresh_token = new_pan.refresh_token
             pan_acc.expires_at = new_pan.expires_at
             pan_acc.token_updated_at = new_pan.token_updated_at
     return pan_acc
Beispiel #3
0
 def update_pan_account_used(cls, params):
     with db:
         for item in params:
             _id = item['id']
             used = item['used']
             used_str = "+%s" % used
             if used < 0:
                 used_str = "%s" % used
             sql = "update panaccounts set use_count=use_count%s where id=%s" % (
                 used_str, _id)
             print("sql:", sql)
             PanAccounts.raw(sql).execute()
Beispiel #4
0
 def update_pan_account_by_pk(cls, pk_id, params):
     """
     :param pk_id:
     :param params:
     :return:
     """
     _params = {
         p: params[p]
         for p in params if p in PanAccounts.field_names()
     }
     print("update_pan_account_by_pk _params:", _params)
     with db:
         PanAccounts.update(**_params).where(
             PanAccounts.id == pk_id).execute()
Beispiel #5
0
 def pan_account_list(cls, account_id=None, transfer_to_dict=True):
     if account_id:
         _pan_account_list = PanAccounts.select().where(
             PanAccounts.user_id == account_id)
     else:
         _pan_account_list = PanAccounts.select().order_by(
             PanAccounts.use_count)[0:50]
     pan_acc_list = []
     # print("pan_account_list:", _pan_account_list)
     for acc in _pan_account_list:
         if transfer_to_dict:
             pan_acc_list.append(PanAccounts.to_dict(acc))
         else:
             pan_acc_list.append(acc)
     return pan_acc_list
Beispiel #6
0
    def new_pan_account(cls,
                        user_id,
                        name,
                        client_id,
                        client_secret,
                        access_token,
                        refresh_token,
                        expires_at,
                        now,
                        pin=0,
                        bd_uid=0) -> int:

        with db:
            pan_acc: PanAccounts = PanAccounts(user_id=user_id,
                                               name=name,
                                               client_id=client_id,
                                               client_secret=client_secret,
                                               access_token=access_token,
                                               refresh_token=refresh_token,
                                               expires_at=expires_at,
                                               token_updated_at=now,
                                               pin=pin,
                                               bd_uid=bd_uid)
            pan_acc.save(force_insert=True)
            pan_acc_id = pan_acc.id
        if pan_acc_id:
            return pan_acc_id
        return 0
Beispiel #7
0
 def check_expired_pan_account_by_id(cls, pan_id, callback=None):
     _pan_account_list = PanAccounts.select().where(
         PanAccounts.id == pan_id,
         PanAccounts.expires_at < get_now_datetime())
     if callback:
         return callback(_pan_account_list)
     return None
Beispiel #8
0
 def check_expired_pan_account(cls, size=10, callback=None):
     fetch_size = size
     while fetch_size == size:
         _pan_account_list = PanAccounts.select().where(
             PanAccounts.expires_at < get_now_datetime()).limit(size)
         fetch_size = len(_pan_account_list)
         if callback:
             callback(_pan_account_list)
Beispiel #9
0
 def pan_account_list(cls, account_id=None, cnt=5) -> list:
     if account_id:
         _pan_account_list = PanAccounts.select().where(
             PanAccounts.user_id == account_id).order_by(
                 PanAccounts.pin.desc()).order_by(
                     PanAccounts.use_count).offset(0).limit(cnt)
     else:
         _pan_account_list = PanAccounts.select().order_by(
             PanAccounts.pin.desc()).order_by(
                 PanAccounts.use_count).offset(0).limit(cnt)
     logger.info("pan_account_list:{}".format(_pan_account_list))
     # for acc in _pan_account_list:
     #     if transfer_to_dict:
     #         pan_acc_list.append(PanAccounts.to_dict(acc))
     #     else:
     #         pan_acc_list.append(acc)
     # if account_id:
     #     return pan_acc_list[0] if pan_acc_list else None
     return _pan_account_list
Beispiel #10
0
 def query_pan_acc_count_by_acc_id(cls, acc_id):
     model_rs: ModelSelect = PanAccounts.select(fn.count(
         PanAccounts.id)).where(
             PanAccounts.user_id == acc_id).alias('count')
     if model_rs:
         model_dict = model_rs.dicts()
         if model_dict:
             v = model_dict[0].get('count')
             if v:
                 return v
     return 0
Beispiel #11
0
def update_access_token():
    try:
        from dao.models import PanAccounts
        # sync_pan_service.clear_all_expired_share_log()
        pan_acc_list = PanAccounts.select().where(PanAccounts.user_id == 1)
        for pan_acc in pan_acc_list:
            logger.info("will validation pan acc id:{}, name:{}".format(pan_acc.id, pan_acc.name))
            auth_service.check_pan_token_validation(pan_acc)
    except Exception as e:
        traceback.print_exc()
        print("update_access_token err:", e)
        pass
    finally:
        try_release_conn()
Beispiel #12
0
 def pan_account_by_bd_uid(cls, account_id, bd_uid) -> PanAccounts:
     return PanAccounts.select().where(
         PanAccounts.user_id == account_id,
         PanAccounts.bd_uid == bd_uid).first()
Beispiel #13
0
 def pan_account_by_name(cls, account_id, name) -> PanAccounts:
     return PanAccounts.select().where(PanAccounts.user_id == account_id,
                                       PanAccounts.name == name).first()
Beispiel #14
0
 def pan_account_by_id(cls, pk_id):
     return PanAccounts.select().where(PanAccounts.id == pk_id).first()
Beispiel #15
0
 def pan_accounts_dict(self) -> list:
     pan_acc_list = DataDao.pan_account_list()
     rs = []
     for acc in pan_acc_list:
         rs.append(PanAccounts.to_dict(acc))
     return rs