def wx_get_equip_data(): openid = request.values.get('openid') wu = wx_user.query.filter(wx_user.wx_id == openid).first() #获取用户名 wxuser_id = wu.id #获取用户ID equip_unread = [] database.ping(reconnect=True) counter_lock2 = threading.Lock() counter_lock2.acquire() sql = 'select id from equipment' cursor.execute(sql) # try: # cursor.execute(sql) # except: # database.ping(reconnect=True) # cursor.execute(sql) data = cursor.fetchall() for (i, ) in data: sql = 'select count(*) from information where user_id=%s and equip_id=%s' % ( wxuser_id, i) cursor.execute(sql) one = cursor.fetchall() for (i, ) in one: equip_unread.append(i) counter_lock2.release() equip_unread_data = json.dumps(equip_unread) return equip_unread_data
def getimformation(): Eqid = request.values.get('eqid') database.ping(reconnect=True) counter_lock2 = threading.Lock() counter_lock2.acquire() exist = r.exists("eqimfo" + Eqid) if exist == 0: sql = 'select * from upload_img where equip_id=%s order by date desc' % Eqid try: cursor.execute(sql) except: database.ping(reconnect=True) cursor.execute(sql) data = cursor.fetchall() message = [] y = [] for i in data: wxuser = wx_user.query.filter(wx_user.id == i[1]).first() name = wxuser.name y.append(i[0]) y.append(name) y.append(i[2]) y.append(i[3]) y.append(i[5]) y.append(i[6]) message.append(y) y = [] json_data = json.dumps(message, cls=CJsonEncoder) counter_lock2.release() r.set("eqimfo" + Eqid, json_data) return json_data else: return r.get("eqimfo" + Eqid)
def wx_get_unread_data(): openid = request.values.get('openid') eqid = request.values.get('eqid') wxuser = wx_user.query.filter(wx_user.wx_id == openid).first() wxuser_id = wxuser.id # image_id = information.query.filter(information.user_id==wxuser_id,information.equip_id==eqid).all() sql = 'select image_id from information where user_id=%s and equip_id=%s' % ( wxuser_id, eqid) try: cursor.execute(sql) except: database.ping(reconnect=True) cursor.execute(sql) image_id = cursor.fetchall() if image_id == (): return '' else: unread_arr = [] for (i, ) in image_id: sql = 'select id from upload_img where id=%s' % i cursor.execute(sql) unread_data = cursor.fetchall() unread_arr.append(unread_data[0][0]) json_data = json.dumps(unread_arr, cls=CJsonEncoder) return json_data
def get_personal(): openid = request.values.get('openid') database.ping(reconnect=True) counter_lock2 = threading.Lock() counter_lock2.acquire() sql = "select * from wx_user where wx_id = '" + openid + "'" cursor.execute(sql) data = cursor.fetchall() counter_lock2.release() json_data = json.dumps(data, cls=CJsonEncoder) return json_data
def wx_pictureContent(): id = request.values.get('id') sql = 'select * from upload_img where id=%s' % id try: cursor.execute(sql) except: database.ping() cursor.execute(sql) content = cursor.fetchall() json_data = json.dumps(content, cls=CJsonEncoder) return json_data
def wx_upload_count(): wxuser = wx_user.query.filter(wx_user.wx_id == openid).first() #获取用户名 wxuser_id = wxuser.id #将用户id当成上传id img_count = request.values.get('img_count') equip_id = request.values.get('equip_id') content = request.values.get('content') tittle = request.values.get('tittle') # upload_data=upload_img(user_id=wxuser.id,number=img_count)#将当前用户的wx_user.id作为upload_img的user_id upload_data = upload_img(user_id=wxuser_id, number=img_count, equip_id=equip_id, image_desc=content, image_title=tittle) db.session.add(upload_data) db.session.commit() upoload = upload_img.query.filter( upload_img.user_id == wxuser_id).order_by( upload_img.date.desc()).first() #获取刚刚上传图片数据的id image_id = upoload.id #获取当前上传用户的id sql = 'select id from wx_user' #查询所有用户的id try: cursor.execute(sql) except: database.ping(reconnect=True) cursor.execute(sql) user_id = cursor.fetchall() #获取所有用户的id #使用for/in循环对所有用户添加未读数据 for (i, ) in user_id: if (i == wxuser_id): continue info_data = information(user_id=i, image_id=image_id, equip_id=equip_id) #设备equip_id目前手动设置 db.session.add(info_data) db.session.commit() #将对应的设备未读信息数加一 sql = 'update wx_user set info_number=info_number+1 where id=%s' % i cursor.execute(sql) database.commit() return ''
def wx_del_unreaddata(): openid = request.values.get('openid') wxuser = wx_user.query.filter(wx_user.wx_id == openid).first() wxuser_id = wxuser.id id = request.values.get('id') sql = 'delete from information where image_id=%s and user_id=%s' % ( id, wxuser_id) try: cursor.execute(sql) except: database.ping(reconnect=True) cursor.execute(sql) database.commit() return ''