def equip_infor(): received = request.get_data() equipInfor = received.decode(encoding="utf8", errors='ignore') equip_name, equip_disc, if_work, equip_adr, equip_ip, equip_posi = equipInfor.split( ",") equip = equipment.query.filter(equipment.equip_name == equip_name).first() if not equip: equip_data = equipment(equip_name=equip_name, equip_disc=equip_disc, if_work=if_work, equip_adr=equip_adr, equip_ip=equip_ip, equip_posi=equip_posi, equip_image=0) db.session.add(equip_data) db.session.commit() else: if_work = '\'%s\'' % if_work equip_name = '\'%s\'' % equip_name sql = 'update equipment set if_work=%s where equip_name=%s' % ( if_work, equip_name) cursor.execute(sql) database.commit() return 'jieshoucg'
def register(): openid = request.values.get('openid') username = request.values.get('name') id = wx_user.query.filter(wx_user.wx_id == openid).first() if id: return '该用户已注册' else: for k in r.scan_iter('wx_user*'): r.delete(k) user = wx_user(name=username, wx_id=openid, phone='无', email='无', password='******', info_number=0) db.session.add(user) db.session.commit() for k in r.scan_iter('wx_user*'): r.delete(k) wxuser = wx_user.query.filter(wx_user.wx_id == openid).first() id = wxuser.id sql = 'select * from upload_img' cursor.execute(sql) image_id = cursor.fetchall() for i in image_id: unread = "insert into information(user_id,image_id,equip_id) VALUE (%s,%s,%s)" % ( id, i[0], i[4]) # unread = information(user_id=id,image_id=i[0],equip_id=i[4]) cursor.execute(unread) database.commit() return ''
def equip_work(): received = request.get_data() equipStat = bytes.decode(received) equip_name, if_work = equipStat.split(',') if_work = '\'%s\'' % if_work equip_name = '\'%s\'' % equip_name sql = 'update equipment set if_work=%s where equip_name=%s' % (if_work, equip_name) cursor.execute(sql) database.commit() return 'jieshoucg'
def del_unread_data(): userid = request.args.get('userID') infor_id = request.args.get('inforID') read_flag = request.args.get('read_flag') if read_flag == 'unread_id': user_name = r.get(userid) wu = wx_user.query.filter(wx_user.name == user_name).first() #获取用户名 wxuser_id = wu.id #获取用户ID sql = 'delete from information where image_id=%s and user_id=%s' % ( infor_id, wxuser_id) cursor.execute(sql) database.commit() data = srch_hash_data('imgs', 'id', infor_id) return 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 ''
def changedata(): userid = request.args.get('id') name = request.args.get('name') phone = request.args.get('phone') email = request.args.get('email') u_name = '\'%s\'' % name u_phone = '\'%s\'' % phone u_mail = '\'%s\'' % email if len(r.keys('wx_user*')) != 0: for k in r.scan_iter('wx_user*'): r_userid = r.hget(k, 'id') if userid == r_userid: print("更新缓存") user_infor = {'name': name, 'phone': phone, 'email': email} r.hmset(k, user_infor) sql = 'update wx_user set name=%s,phone=%s,email=%s where id=%s' % ( u_name, u_phone, u_mail, userid) cursor.execute(sql) database.commit() json_data = srch_hash_data('wx_user', 'init', 'None') return json_data
def change_emails(): userid = request.form.get('userID') newmail = request.form.get('newMail') mailcode = request.form.get('mailcode') #用户输入的验证码 usermail = request.form.get('userMail') #用户接收验证码的邮箱 codeKey = "" + usermail + ":code" code = r.get(codeKey) if mailcode == '%s' % code: if len(r.keys('wx_user*')) != 0: for k in r.scan_iter('wx_user*'): r_username = r.hget(k, 'name') if r.get(userid) == r_username: user_infor = {'email': newmail} r.hset(k, user_infor) sql = 'update wx_user set email="' + newmail + '" where name="' + r.get( userid) + '"' cursor.execute(sql) database.commit() return ("0") else: return ("1")