Ejemplo n.º 1
0
 def on_message(self, getdata):
     logininfo = json.loads(getdata)
     sha256 = hashlib.sha256()
     sha256.update(logininfo[0]['pwd'].encode('utf-8'))
     passwordsha = sha256.hexdigest()
     word = 'select id from `members-login` where loginuser = "******"'
     print(word)
     mydb = myDb()
     getdata = mydb.getData(word)
     print(getdata)
     word = 'select pass,userlimit,userlevel,mininame from `members-infor` where id = "' + str(
         getdata[0][0]) + '"'
     print(word)
     getdata = mydb.getData(word)
     print(getdata)
     if (getdata[0][0] == passwordsha):
         loginsend = {}
         loginsend['onlineuser'] = logininfo[0]['user']
         loginsend['mininame'] = getdata[0][3]
         loginsend['userlimit'] = getdata[0][1]
         loginsend['userlevel'] = getdata[0][2]
         loginsend['time'] = time.time()
         cache = myCache()
         random = cache.randomkey()
         online = random + '_' + cache.dataconfig[
             'db'] + '_' + 'onlineuser' + '_user' + '_'
         online = online + logininfo[0]['user'] + '_0'
         #print(online)
         onlinedata = {}
         onlinedata[online] = time.time()
         temp = cache.createCache(onlinedata)
         self.write_message(json.dumps(loginsend).encode())
Ejemplo n.º 2
0
 def insert_cache(self, key, tmpdata):
     cache = myCache()
     value = cache.getValue(key)
     if (value == ''):
         insertdata = {}
         insertdata[key] = tmpdata
         cache.createCache(insertdata)
     elif (value != ''):
         cache.updateValue(key, tmpdata)
Ejemplo n.º 3
0
 def get_cache(self, key):
     cache = myCache()
     return cache.getValue(key)
Ejemplo n.º 4
0
 def __init__(self):
     self.mydb = myDb()
     self.mycache = myCache()
Ejemplo n.º 5
0
 def on_message(self, getdata):
     #print(type(getdata))
     if (type(getdata) == str):
         data = json.loads(getdata)
         filebyte = {}
         if ('user' in data):
             cache = myCache()
             key = 'uploadexcel_' + data['user'] + '_' + str(data['size'])
             receivecache = {}
             receivecache[key] = ''
             cache.createCache(receivecache)
             filebyte['size'] = 0
             self.write_message(json.dumps(filebyte).encode())
             #print('数据对接成功')
         #保存修改的最终数据
         elif (('date' in data) & ('xmb' in data)):
             #print('开始保存工资信息')
             if (os.path.exists('tmp/stamp.wenq') == False):
                 fp = open('tmp/stamp.wenq', 'w')
                 fp.write(str(100000000))
                 fp.close()
             if (os.path.exists('tmp/stamp.wenq')):
                 fp = open('tmp/stamp.wenq', 'r')
                 stamp = fp.read()
                 fp.close()
                 stamp = int(stamp) + 1
                 fp = open('tmp/stamp.wenq', 'w')
                 fp.write(str(stamp))
                 fp.close()
                 stamp = str(
                     time.strftime('%Y%m%d', time.localtime(
                         time.time()))) + str(stamp)
             if ((data['date'] != None) & (data['xmb'] != None) &
                 (len(data['datainfo']) != 0)):
                 cache = myCache()
                 getdate = data['date'].split('-')
                 xmb = data['xmb']
                 uploader = data['uploader']
                 redishead = cache.dataconfig[
                     'db'] + '_' + 'members-wages' + '_'
                 for item in data['datainfo']:
                     numrandom = cache.randomkey()
                     wages = str(item)
                     redisset = {}
                     redisdata = numrandom + '_' + redishead + 'batch' + '_' + item[
                         '姓名'] + '_1'
                     redisset[redisdata] = stamp
                     redisdata = numrandom + '_' + redishead + 'name' + '_' + item[
                         '姓名'] + '_1'
                     redisset[redisdata] = item['姓名']
                     redisdata = numrandom + '_' + redishead + 'year' + '_' + item[
                         '姓名'] + '_1'
                     redisset[redisdata] = getdate[0]
                     redisdata = numrandom + '_' + redishead + 'month' + '_' + item[
                         '姓名'] + '_1'
                     redisset[redisdata] = getdate[1]
                     redisdata = numrandom + '_' + redishead + 'uploader' + '_' + item[
                         '姓名'] + '_1'
                     redisset[redisdata] = uploader
                     redisdata = numrandom + '_' + redishead + 'wages' + '_' + item[
                         '姓名'] + '_1'
                     redisset[redisdata] = wages
                     redisdata = numrandom + '_' + redishead + 'userlimit' + '_' + item[
                         '姓名'] + '_1'
                     redisset[redisdata] = data['xmb']
                     cache.createCache(redisset)
                 self.write_message(json.dumps({'log': '上传成功!'}).encode())
     elif (type(getdata) == bytes):
         filename = str(
             time.strftime('%Y%m%d%H%M%S', time.localtime(
                 time.time()))) + str(random.randint(10000, 99999)) + '.xls'
         url = 'tmp/' + filename
         #print(url)
         fp = open(url, 'wb')
         fp.write(getdata)
         fp.close()
         getdisc = self.fenxiexcel(url)
         self.write_message(json.dumps(getdisc).encode())