def post(self): user_data, rqmsg, msg, user_uuid = yield self.check_arguments( msgws.rqUserRenew(), None) self.write(mx.convertProtobuf(msg)) self.finish() del msg, rqmsg, user_data
def post(self): legal, rqmsg, msg = yield self.check_arguments(msgws.rqQueryDataEvents(), msgws.QueryDataEvents(), use_scode=1) try: if legal: strsql = "SELECT e.event_id,u.user_name,s.event_name,e.event_remark,e.event_time,e.event_ip from uas.events_log as e \ LEFT JOIN uas.events_info as s ON e.event_id=s.event_id \ LEFT JOIN uas.user_info as u ON e.user_id=u.user_id WHERE e.event_ip!=0 ORDER BY e.event_time desc, u.user_id" record_total, buffer_tag, paging_idx, paging_total, cur = yield self.mydata_collector( strsql, need_fetch=1, buffer_tag=msg.head.paging_buffer_tag, paging_idx=msg.head.paging_idx, paging_num=msg.head.paging_num) if record_total is None: msg.head.if_st = 45 else: msg.head.paging_record_total = record_total msg.head.paging_buffer_tag = buffer_tag msg.head.paging_idx = paging_idx msg.head.paging_total = paging_total for d in cur: env = msgws.QueryDataEvents.DataEventsView() env.events_id = int(d[0]) env.user_name = d[1] env.events_msg = '{0}'.format(d[2]) env.dt_happen = int(d[3]) env.remote_ip = mx.ip2int(d[4]) msg.data_events_view.extend([env]) del env msg.head.if_st = 1 msg.head.if_msg = "select events Success" except Exception as ex: msg.head.if_st = 0 msg.head.if_msg = str(ex.message) self.write(mx.convertProtobuf(msg)) self.finish() del msg, rqmsg
def post(self): pb2 = self.get_argument('pb2') rqmsg = msgws.rqUserDel() msg = msgws.CommAns() msg.head.ver = 160328 msg.head.if_dt = int(time.time()) try: rqmsg.ParseFromString(base64.b64decode(pb2)) msg.head.idx = rqmsg.head.idx msg.head.if_st = 1 except: msg.head.if_st = 46 # 删除用户 try: #判断是否admin账户,是则返回异常,不是则可以删除 if rqmsg.user != 'admin': # 检查用户名密码是否合法并且删除该用户 strsql = 'delete from {1}.user_info where user_name="{0}" '.format(rqmsg.user,self._db_uas) cur = yield self.mydata_collector(strsql, need_fetch=0, need_paging=0) affected_rows = cur[0][0] if affected_rows > 0: yield self.add_eventlog(3, rqmsg.user_id, 'successfully delete user {0}'.format(rqmsg.user)) msg.head.if_st = 1 msg.head.if_msg = 'successfully delete' else: yield self.add_eventlog(3, rqmsg.user_id, 'Wrong no such user') msg.head.if_st = 46 msg.head.if_msg = 'no such user' else: yield self.add_eventlog(3, rqmsg.user_id, 'Shall not remove the admin user') msg.head.if_st = 0 msg.head.if_msg = "Shall not remove the admin user" del cur, strsql except Exception as ex: msg.head.if_st = 0 msg.head.if_msg = str(ex.message) self.write(mx.convertProtobuf(msg)) self.finish()
def post(self): pb2 = self.get_argument('pb2') rqmsg = msgws.rqUserEdit() msg = msgws.CommAns() msg.head.ver = 160328 msg.head.if_dt = int(time.time()) try: rqmsg.ParseFromString(base64.b64decode(pb2)) msg.head.idx = rqmsg.head.idx msg.head.if_st = 1 except: msg.head.if_st = 46 try: strsql='' pd='' # 是否提交了用户旧密码 if rqmsg.pwd_old: pd=' and user_pwd={0}'.format(rqmsg.pwd_old) strsql = 'update {0}.user_info set user_name="{1}",user_alias="{2}", user_pwd="{3}",user_remark="{4}" \ where binary user_name="{5}" {6}'.format(self._db_uas,rqmsg.user,rqmsg.fullname, rqmsg.pwd, rqmsg.remark,rqmsg.user,pd) cur = yield self.mydata_collector(strsql, need_fetch=0, need_paging=0) affected_rows = cur[0][0] if affected_rows > 0: yield self.add_eventlog(2, rqmsg.user_id, 'successfully to edit user {0}'.format(rqmsg.user)) msg.head.if_st = 1 msg.head.if_msg = 'successfully to edit user {0}'.format(rqmsg.user) else: yield self.add_eventlog(2,rqmsg.user_id, 'Wrong username or password') msg.head.if_st = 40 msg.head.if_msg = 'Wrong username or password' except Exception as ex: msg.head.if_st = 0 msg.head.if_msg = str(ex.message) self.write(mx.convertProtobuf(msg)) self.finish()
def post(self): legal, rqmsg, msg = yield self.check_arguments(msgws.rqIpcCtl(), None, use_scode=1) if legal: scmd = rqmsg.ctl_cmd sdownlink = '' for devid in rqmsg.dev_id: if devid.startswith('901001'): if scmd == 'ipc.verf.get': sdownlink = 'QV\r\n' elif scmd == 'ipc.lscmd.get': sdownlink = 'QH\r\n' elif scmd == 'ipc.date.get': sdownlink = 'QD\r\n' elif scmd == 'ipc.time.get': sdownlink = 'QT\r\n' elif scmd == 'ipc.datetime.set': x = mx.stamp2time(rqmsg.dev_datetime) d, t = x.split(' ') y, m, dd = d.split('-') h, mm, s = t.split(':') sdownlink = '\r\nQC:{0},{1},{2},{3},{4},{5}'.format( y, m, dd, h, mm, s) elif scmd == 'ipc.qudat.get': sdownlink = 'QI\r\n' else: msg.head.if_st = 46 if len(sdownlink) > 0: msgpub = self.init_msgws(msgws.rqIpcUplink(), scmd) msgpub.dev_id = devid msgpub.raw_string = sdownlink libiisi.send_to_zmq_pub( 'ipc.req.{0}.{1}'.format(scmd, devid), msgpub.SerializeToString()) del msgpub self.write(mx.convertProtobuf(msg)) self.finish() del legal, rqmsg, msg
def post(self): pb2 = self.get_argument('pb2') rqmsg = msgws.rqUserLogin() msg = msgws.UserLogin() msg.head.ver = 160328 msg.head.if_dt = int(time.time()) try: rqmsg.ParseFromString(base64.b64decode(pb2)) msg.head.idx = rqmsg.head.idx msg.head.if_st = 1 except: msg.head.if_st = 46 # 检查用户名密码是否合法 strsql = 'select user_id,user_name,user_pwd,user_mobile,user_tel,user_email,user_remark from {2}.user_info \ where binary user_name="{0}" and user_pwd="{1}"'.format(rqmsg.user,rqmsg.pwd,self._db_uas) record_total, buffer_tag, paging_idx, paging_total, cur = yield self.mydata_collector( strsql, need_fetch=1, need_paging=0) if record_total is None or record_total == 0: yield self.add_eventlog(4, 0, 'Wrong username or password') msg.head.if_st = 47 msg.head.if_msg = 'Wrong username or password' else: for d in cur: msg.user_id = d[0] msg.fullname=d[1] msg.mobile=d[3] if d[3] is not None else 0 msg.tel=d[4] if d[4] is not None else '' msg.email=d[5] if d[5] is not None else '' msg.remark=d[6] if d[6] is not None else '' break yield self.add_eventlog(4, msg.user_id, 'successfully to login') msg.head.if_msg = 'successfully to login' print msg self.write(mx.convertProtobuf(msg)) self.finish()
def post(self): pb2 = self.get_argument('pb2') rqmsg = msgws.rqUserAdd() msg = msgws.UserAdd() msg.head.ver = 160328 msg.head.if_dt = int(time.time()) try: rqmsg.ParseFromString(base64.b64decode(pb2)) msg.head.idx = rqmsg.head.idx msg.head.if_st = 1 except: msg.head.if_st = 46 try: # 检查用户名密码是否存在 strsql = 'insert into {8}.user_info (user_name, user_pwd, user_alias,user_mobile,user_tel,user_email, create_time, user_remark) \ values ("{0}","{1}","{2}","{3}","{4}","{5}","{6}","{7}")'.format( rqmsg.user, rqmsg.pwd, rqmsg.fullname,rqmsg.mobile,rqmsg.tel,rqmsg.email, int(time.time()), rqmsg.remark,self._db_uas) cur = yield self.mydata_collector(strsql, need_fetch=0) affected_rows = cur[0][0] msg.user_id = cur[0][1] if affected_rows > 0: yield self.add_eventlog(1, msg.user_id, 'Add User {0} Success'.format(rqmsg.user)) msg.head.if_st = 1 msg.head.if_msg = 'Add User is Success' else: yield self.add_eventlog(1, msg.user_id, 'User {0} already exists'.format(rqmsg.user)) msg.head.if_st = 45 msg.head.if_msg = 'User already exists' except Exception as ex: msg.head.if_st = 0 msg.head.if_msg = str(ex.message) self.write(mx.convertProtobuf(msg)) self.finish() del msg, rqmsg
def sendServerMsg(msg, cmd): servermsg = initRtuProtobuf(cmd, [-1], [mx.ip2int('127.0.0.1')]) if len(msg) > 0: servermsg.syscmds.logger_msg = msg return mx.convertProtobuf(servermsg)
def post(self): legal, rqmsg, msg = yield self.check_arguments(msgws.rqIpcUplink(), msgws.CommAns(), use_scode=1) if legal: devid = rqmsg.dev_id raw_string = rqmsg.raw_string.replace('\r\n', '') createsql = '' insertsql = '' db_names = set() if devid[:6] == '901001': # 申欣环保 if raw_string.startswith('QI:'): data = raw_string.split(':')[1] lstdata = data.split(',') ym = mx.stamp2time(time.time(), format_type='%y%m') for i in libiisi.qudata_sxhb: db_names.add('sens_data_{0:03d}_month_{1}'.format( i, ym)) strsql = 'select TABLE_NAME from INFORMATION_SCHEMA.TABLES \ where TABLE_SCHEMA="{0}" and TABLE_NAME like "{1}"'.format( libiisi.cfg_dbname_dg, '%sens_data_%_month_%') record_total, buffer_tag, paging_idx, paging_total, cur = yield self.mydata_collector( strsql, need_fetch=1, buffer_tag=msg.head.paging_buffer_tag, paging_idx=msg.head.paging_idx, paging_num=msg.head.paging_num) if record_total is not None: for z in cur: db_names.discard(z[0]) del cur for z in db_names: createsql += libiisi.sqlstr_create_emtable.format(z) if len(createsql) > 0: createsql = 'use {0};'.format( libiisi.cfg_dbname_dg) + createsql yield self.mydata_collector(createsql, need_fetch=0) t = int(time.time()) for i in range(len(libiisi.qudata_sxhb)): try: insertsql += 'insert into {5}.sens_data_{0:03d}_month_{1} (dev_id,dev_data,date_create) values ({2},{3},{4});'.format( libiisi.qudata_sxhb[i], ym, devid, lstdata[i], t, libiisi.cfg_dbname_dg) except: pass if len(insertsql) > 0: yield self.mydata_collector(insertsql, need_fetch=0) elif raw_string.startswith('QH:'): # 读取支持的指令 msgpub = self.init_msgws(msgws.rqIpcCtl(), 'ipc.lscmd.get') msgpub.dev_id.extend([devid]) msgpub.dev_cmds = raw_string[3:].replace(' ', '').replace( '|', ',') libiisi.send_to_zmq_pub( 'ipc.rep.ipc.lscmd.get.{0}'.format(devid), msgpub.SerializeToString()) elif raw_string.startswith('QD:'): # 读取日期 msgpub = self.init_msgws(msgws.rqIpcCtl(), 'ipc.date.get') msgpub.dev_id.extend([devid]) s = raw_string[3:].split(',') msgpub.dev_datetime = int( mx.time2stamp('{0}-{1}-{2} 00:00:00'.format( s[0], s[1], s[2]))) libiisi.send_to_zmq_pub( 'ipc.rep.ipc.date.get.{0}'.format(devid), msgpub.SerializeToString()) elif raw_string.startswith('QT:'): # 读取时间 msgpub = self.init_msgws(msgws.rqIpcCtl(), 'ipc.time.get') msgpub.dev_id.extend([devid]) s = raw_string[3:].split(',') msgpub.dev_datetime = int( mx.time2stamp('{0}-{1}-{2} {3}:{4}:{5}'.format( time.localtime()[0], time.localtime()[1], time.localtime()[2], s[0], s[1], s[2]))) libiisi.send_to_zmq_pub( 'ipc.rep.ipc.time.get.{0}'.format(devid), msgpub.SerializeToString()) elif raw_string.startswith('QV:') or raw_string.startswith( 'Device ID:'): # 读取版本 msgpub = self.init_msgws(msgws.rqIpcCtl(), 'ipc.verf.get') msgpub.dev_id.extend([devid]) msgpub.dev_ver = raw_string libiisi.send_to_zmq_pub( 'ipc.rep.ipc.verf.get.{0}'.format(devid), msgpub.SerializeToString()) elif raw_string.startswith('QC:'): # 设置日期和时间 msgpub = self.init_msgws(msgws.rqIpcCtl(), 'ipc.datetime.set') msgpub.dev_id.extend([devid]) if 'completed' in raw_string: msgpub.dev_datetime = 1 else: msgpub.dev_datetime = 0 libiisi.send_to_zmq_pub( 'ipc.rep.ipc.datetime.set.{0}'.format(devid), msgpub.SerializeToString()) else: msg.head.if_st = 46 msg.head.if_msg = 'raw data error.' elif devid[:6] == "902001": # 武汉天河机场 x = "1,2,3,4,5,6,7,8,9,10" if os.path.isfile("list.txt"): with open("list.txt", "r") as f: x = f.readline() f.close() y = rqmsg.raw_string.split(',') tcsdata = dict() if y[1] == "1": # off for i in range(1, 7): tcsdata['k{0}'.format(i)] = 0 tcsmsg = libiisi.initRtuJson(2, 7, 1, 1, 1, 'wlst.rtu.4b00', self.request.remote_ip, 0, x, tcsdata) # libiisi.set_to_send(tcsmsg, 0, False) libiisi.send_to_zmq_pub( 'tcs.req.{0}.wlst.rtu.2210'.format( libiisi.cfg_tcs_port), json.dumps(tcsmsg, separators=(',', ':')).lower()) else: for i in range(1, 7): tcsdata['k{0}'.format(i)] = 1 tcsmsg = libiisi.initRtuJson(2, 7, 1, 1, 1, 'wlst.rtu.4b00', self.request.remote_ip, 0, x, tcsdata) # libiisi.set_to_send(tcsmsg, 0, False) libiisi.send_to_zmq_pub( 'tcs.req.{0}.wlst.rtu.2210'.format( libiisi.cfg_tcs_port), json.dumps(tcsmsg, separators=(',', ':')).lower()) del devid, raw_string, createsql, insertsql, db_names else: msg.head.if_st = 0 msg.head.if_msg = 'Security code error' self.write(mx.convertProtobuf(msg)) self.finish() del msg, rqmsg, legal
def post(self): legal, rqmsg, msg = yield self.check_arguments(msgws.rqQueryEMData(), msgws.QueryEMData(), use_scode=1) if legal: sdt, edt = self.process_input_date(rqmsg.dt_start, rqmsg.dt_end, to_chsarp=0) tdt = int(time.time()) edt = tdt if edt > tdt else edt devid = rqmsg.dev_id msg.dev_id = devid yms = [] if sdt > 0: # ym = mx.stamp2time(sdt, format_type='%y%m') sym = mx.stamp2time(sdt, format_type='%y%m') eym = mx.stamp2time(edt, format_type='%y%m') while int(sym) <= int(eym): yms.append(sym) if sym[2:] == '12': sym = str(int(sym[:2]) + 1) + '01' else: sym = sym[:2] + '{0:02d}'.format(int(sym[2:]) + 1) else: yms = [mx.stamp2time(time.time(), format_type='%y%m')] rebuild_cache = False xquery = msgws.QueryEMData() if devid.startswith('901001'): for ym in yms: strsql = 'select t{0}.dev_id,t{0}.date_create '.format( libiisi.qudata_sxhb[0]) for x in libiisi.qudata_sxhb: strsql += ', t{0}.dev_data as d{0}'.format(x) strsql += ' from {0}.sens_data_{1}_month_{2} as t{1}'.format( libiisi.cfg_dbname_dg, libiisi.qudata_sxhb[0], ym) for i in range(1, len(libiisi.qudata_sxhb)): strsql += ' left join {0}.sens_data_{1}_month_{2} as t{1} on t{3}.dev_id=t{1}.dev_id and t{3}.date_create=t{1}.date_create'.format( libiisi.cfg_dbname_dg, libiisi.qudata_sxhb[i], ym, libiisi.qudata_sxhb[0]) if sdt == 0 and edt == 0: # no, no2, co, co2, pm25, temp, rehu, pm10, o3, tvoc, h2s, so2 = libiisi.qudata_sxhb strsql += ' where t{0}.dev_id="{1}" order by t{0}.date_create desc limit 1'.format( libiisi.qudata_sxhb[0], devid) else: strsql += ' where t{0}.dev_id="{1}" and t{0}.date_create>={2} and t{0}.date_create<={3} order by t{0}.date_create'.format( libiisi.qudata_sxhb[0], devid, sdt, edt) # print(strsql) record_total, buffer_tag, paging_idx, paging_total, cur = yield self.mydata_collector( strsql, need_fetch=1, buffer_tag=msg.head.paging_buffer_tag, paging_idx=msg.head.paging_idx, paging_num=msg.head.paging_num) if record_total is None: msg.head.if_st = 45 else: msg.head.paging_record_total = record_total msg.head.paging_buffer_tag = buffer_tag msg.head.paging_idx = paging_idx msg.head.paging_total = paging_total for d in cur: qudata = msgws.QueryEMData.Qudata() qudata.no = float( d[2]) if d[2] is not None else 0.0 qudata.no2 = float( d[3]) if d[3] is not None else 0.0 qudata.co = float( d[4]) if d[4] is not None else 0.0 qudata.co2 = float( d[5]) if d[5] is not None else 0.0 qudata.pm25 = float( d[6]) if d[6] is not None else 0.0 qudata.temp = float( d[7]) if d[7] is not None else 0.0 qudata.rehu = float( d[8]) if d[8] is not None else 0.0 qudata.pm10 = float( d[9]) if d[9] is not None else 0.0 qudata.o3 = float( d[10]) if d[10] is not None else 0.0 qudata.tvoc = float( d[11]) if d[11] is not None else 0.0 qudata.h2s = float( d[12]) if d[12] is not None else 0.0 qudata.so2 = float( d[13]) if d[13] is not None else 0.0 qudata.dt_data = int( d[1]) if d[1] is not None else 0.0 msg.qudata.extend([qudata]) del qudata del cur, strsql self.write(mx.convertProtobuf(msg)) self.finish() del msg, rqmsg, legal