hch
2018-12-24 c238e45c6695d627bcc776b34f8ff46823c57e71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
# ÐÞ¸ÄÕ˺źó׺
#-------------------------------------------------------------------------------
#
# Ð޸ıí
# GameLog: tagDBPlayerInfoLog
# GameUser: tagDSAccount tagDBPlayer tagDBBillboard
# ¿ÉÄÜ»áʹÓÃÒÑ´¦Àí tagAccIDSendPrize  tagDBGMIP  tagGameWorldEvent
# ×ֶβ»È·¶¨ÎÞ·¨´¦ÀíµÄ tagUniversalGameRec  ÐèÒªÑз¢ÈËÔ±ÅäºÏ  
# ²»»áʹÓõIJ»´¦Àí tagDBMailList tagExpiation tagPetExpiation tagAccCoins
#-------------------------------------------------------------------------------
# ver=1.2
#-------------------------------------------------------------------------------
 
import pymongo
from Collections import (DataServerPlayerData, )
DBConfig = __import__('Config.DBConfig')
 
 
def changeAccID(accID, spid, serverid):
    accpeice = accID.split("@")
    if len(accpeice) < 3:
        return ""
    
    if not spid:
        spid = accpeice[-2]
        
    if not serverid:
        serverid = accpeice[-1]
    
    accID = accID.replace("@%s@%s"%(accpeice[-2], accpeice[-1]), "@%s@%s"%(spid, serverid))
    return accID
 
def main():
 
    print "Connect %s:%s "%(DBConfig.USER_DB_IP, DBConfig.USER_DB_PORT)
    con = pymongo.Connection(DBConfig.USER_DB_IP, DBConfig.USER_DB_PORT)
    
    db = con.admin  
 
    if not db.authenticate(DBConfig.userdb_user, DBConfig.userdb_pwd):
        print "name(%s) or password(%s) error!, Plz try input them to continue again!"%(DBConfig.userdb_user, DBConfig.userdb_pwd)
        return
    
    db = con[DBConfig.USER_DB_NAME]
    # ÐÞ¸ÄÍæ¼Ò±íºÍÕ˺űíÖеÄÍæ¼ÒÕ˺Å
    col = db['tagDSAccount']
    
    cnt = 0
    for rec in col.find():
        accID = rec["ACCID"]
        accountObj = DataServerPlayerData.tagDSAccount()
        accountObj.ACCID = accID
        # ¼ÓÔØÊý¾Ý
        if not accountObj.adoLoad(col):
            print 'accid %s not found!'%accID
            continue
        
        newAccID = changeAccID(accID, DBConfig.Spid, DBConfig.Serverid)
        if not newAccID:
            continue
        # ÔØÈëÐÂÕ˺Å
        accountObj.ACCID = newAccID
        rec = accountObj.getRecord()
        col.update({'ACCID':accID}, {'$set':rec}, False, False, True, True)
        cnt += 1
    print 'table:tagDSAccount update  successfully! cnt=%s changeto %s-%s'%(cnt, DBConfig.Spid, DBConfig.Serverid)
    
    
    for table in ['tagDBPlayer', 'tagAccIDSendPrize', 'tagDBGMIP', 'tagGameWorldEvent']:
        # ÐÞ¸ÄÍæ¼Ò±íºÍÕ˺űíÖеÄÍæ¼ÒÕ˺Å
        colPlayer = db[table]
        cnt = 0
        keyName = "AccID"
        for rec in colPlayer.find():
            accID = rec[keyName]
            
            newAccID = changeAccID(accID, DBConfig.Spid, DBConfig.Serverid)
            if not newAccID:
                continue
            # ÔØÈëÐÂÕ˺Å
            rec[keyName]=newAccID
            del rec["_id"]
            colPlayer.update({keyName:accID}, {'$set':rec}, False, False, True, True)
            cnt += 1
        print 'table:%s update  successfully!  cnt=%s changeto %s-%s'%(table, cnt, DBConfig.Spid, DBConfig.Serverid)
    
    # ÅÅÐаñ
    # ÐÞ¸ÄÍæ¼Ò±íºÍÕ˺űíÖеÄÍæ¼ÒÕ˺Å
    colPlayer = db['tagDBBillboard']
    cnt = 0
    keyName = "Name2"
    for rec in colPlayer.find():
        accID = rec[keyName]
        
        newAccID = changeAccID(accID, DBConfig.Spid, DBConfig.Serverid)
        if not newAccID:
            continue
        # ÔØÈëÐÂÕ˺Å
        rec[keyName]=newAccID
        del rec["_id"]
        colPlayer.update({keyName:accID, 'Type':rec['Type']}, {'$set':rec}, False, False, True, True)
        cnt += 1
    print 'table:tagDBBillboard update  successfully!  cnt=%s changeto %s-%s'%(cnt, DBConfig.Spid, DBConfig.Serverid)
 
    
    
    db = con[DBConfig.USER_DB_Log]
    # ÐÞ¸ÄÍæ¼Ò±íºÍÕ˺űíÖеÄÍæ¼ÒÕ˺Å
    colPlayer = db['tagDBPlayerInfoLog']
    cnt = 0
    for rec in colPlayer.find():
        accID = rec["AccID"]
        
        newAccID = changeAccID(accID, DBConfig.Spid, DBConfig.Serverid)
        if not newAccID:
            continue
        # ÔØÈëÐÂÕ˺Å
        rec['AccID']=newAccID
        del rec["_id"]
        colPlayer.update({'AccID':accID}, {'$set':rec}, False, False, True, True)
        cnt += 1
        print 'table:tagDBPlayerInfoLog update  successfully!  cnt=%s changeto %s-%s'%(cnt, DBConfig.Spid, DBConfig.Serverid)
    
    
    
    con.disconnect()
        
 
 
if __name__ == "__main__":
    main()