예제 #1
0
def set_server_partner_list(server_id, server_zone, partner_ids):
    server_partner_list = get_server_partner_list(server_id)
    delete_partner = []

    partner_id_set = set()
    partner_id_list = partner_ids.split(",")
    #增加的parnter
    params = []
    for partner_id in partner_id_list:
        partner_id_set.add(partner_id)
        params.append([
            partner_id,
        ])

    for server_partner in server_partner_list:
        if server_partner.partner_id not in partner_id_set:
            partner = Partner.load(partner_id=server_partner.partner_id)
            if partner.server_zone != server_zone:
                continue
            delete_partner.append(server_partner.partner_id)

    cursor = connection.cursor()
    try:
        if delete_partner:
            cursor.execute(
                "delete from server_partner_list where server_id = '%s' and partner_id in (%s)"
                % (server_id, ",".join(delete_partner)))
        sql = "insert ignore into server_partner_list(server_id, partner_id, created_time) values('%s', %%s, now())" % server_id
        cursor.executemany(sql, params)
    finally:
        cursor.close()
예제 #2
0
def set_server_partner_list(server_id, server_zone, partner_ids):
    server_partner_list = get_server_partner_list(server_id)
    delete_partner = []
    
    partner_id_set = set()
    partner_id_list = partner_ids.split(",")
    #增加的parnter
    params = []
    for partner_id in partner_id_list:
        partner_id_set.add(partner_id)
        params.append([partner_id, ])
        
    for server_partner in server_partner_list:
        if server_partner.partner_id not in partner_id_set:
            partner = Partner.load(partner_id=server_partner.partner_id)
            if partner.server_zone != server_zone:
                continue
            delete_partner.append(server_partner.partner_id)
        
    cursor = connection.cursor()
    try:
        if delete_partner:
            cursor.execute("delete from server_partner_list where server_id = '%s' and partner_id in (%s)" % (server_id, ",".join(delete_partner)))
        sql = "insert ignore into server_partner_list(server_id, partner_id, created_time) values('%s', %%s, now())" % server_id
        cursor.executemany(sql, params)
    finally:
        cursor.close()
예제 #3
0
def get_all_partner_list():
    return Partner.query(condition="is_del=0")
예제 #4
0
def get_partner(partner_id):
    return Partner.load(partner_id=partner_id)
예제 #5
0
def delete_partner(partner_id):
    partner = Partner()
    partner.partner_id = partner_id
    partner.is_del = 1
    partner.persist()
예제 #6
0
def get_partner_list(page=1, pagesize=20):
    return Partner.paging(page, pagesize, condition="is_del=0")
예제 #7
0
def add_partner(partner_id, name, server_zone):
    partner = Partner()
    partner.partner_id = partner_id
    partner.name = name
    partner.server_zone = server_zone
    partner.persist()
예제 #8
0
def get_partner_list_by_server_zone(server_zone):
    return Partner.query(condition=" server_zone = %s and is_del=0" % server_zone)