def on_get(self,req,resp,action): params = req.params kw = {} kw['table'] = self.table kw['dbname']= self.dbname kw['fields']= params.get('fields','') if action == 'getbyname': """根据帐号获取一条用户帐号信息""" name = params.get('name','') if not name : raise falcon.HTTPBadRequest('illegal_argument','name must provided') kw['where'] = "name='%s'" % name kw['order'] ='id desc' result = dbhandle.getlist(kw) elif action == 'getinfobyemail': """根据邮箱获取一条用户帐号信息""" email = params.get('email','') if not email : raise falcon.HTTPBadRequest('illegal_argument','email must provided') kw['where'] = "email='%s'" % email kw['order'] = 'id desc' res,desc = dbhandle.getlist(kw) if res ==0 and desc: desc = desc[0] result = res,desc else: raise falcon.HTTPError(falcon.HTTP_404,'invalid_grant','invalid action %s' % action) if result[0] == -1: raise falcon.HTTPBadRequest('invalid_sql_syntax',str(result[1])) result={'result':result[1]} resp.body = JSONEncoder().encode(result)
def on_get(self,req,resp,dbname,table,action): if dbname not in self.databases: raise falcon.HTTPError(falcon.HTTP_404,'invalid_grant',"invalid databases name %s" % dbname) if '.' in table: raise falcon.HTTPError(falcon.HTTP_404,'invalid_grant',"invalid table name %s" % table) kw = req.params kw['table'] = table kw['dbname']= dbname if action == 'getbyid': if 'ids' not in kw: raise falcon.HTTPBadRequest('illegal_argument','ids must provided') result = dbhandle.getbyid(kw) elif action == 'getcount': result = dbhandle.getcount(kw) elif action == 'getlist': result = dbhandle.getlist(kw) else: raise falcon.HTTPError(falcon.HTTP_404,'invalid_grant','invalid action %s' % action) if result[0] == -1: raise falcon.HTTPBadRequest('invalid_sql_syntax',str(result[1])) result={'result':result[1]} resp.body = JSONEncoder().encode(result)
def on_get(self,req,resp,action): params = req.params kw = {} kw['table'] = self.table kw['dbname']= self.dbname kw['fields']= params.get('fields','') if action == 'getgroupbycomid': """根据公司ID获取统计列表""" com_id = params.get('com_id','') if not com_id : raise falcon.HTTPBadRequest('illegal_argument','com_id must provided') kw['group'] = params.get('group','status') kw['fields'] = '%s,count(id) as num' % kw['group'] kw['order'] = 'NULL' kw['where'] = "com_id=%s" % com_id result = dbhandle.getlist(kw) elif action == 'getlistbycomid': """获取公司招商列表数量""" com_id = params.get('com_id','') if not com_id : raise falcon.HTTPBadRequest('illegal_argument','com_id must provided') kw['page'] = params.get('page',1) kw['pagesize'] = params.get('pagesize',sconf.PAGE_SIZE) kw['order'] = params.get('order') kw['where'] = "com_id='%s'" % com_id result = dbhandle.getlist(kw) elif action == 'getcount': """获取公司招商列表数量""" com_id = params.get('com_id','') if not com_id : raise falcon.HTTPBadRequest('illegal_argument','com_id must provided') kw['fields'] = 'count(id) as n' kw['where'] = "com_id='%s'" % com_id result = dbhandle.query(kw) if result[0] == 0: n = result[1][0]['n'] result = 0,n else: raise falcon.HTTPError(falcon.HTTP_404,'invalid_grant','invalid action %s' % action) if result[0] == -1: raise falcon.HTTPBadRequest('invalid_sql_syntax',str(result[1])) result={'result':result[1]} resp.body = JSONEncoder().encode(result)
def on_get(self,req,resp,dbname,table): if '.' in table: raise falcon.HTTPBadRequest('invalid_grant',"invalid table name %s" % table) kw = req.params kw['table'] = table kw['dbname']= dbname if dbname in self.databases: result = dbhandle.getlist(kw) if result[0] == -1: raise falcon.HTTPBadRequest('invalid_sql_syntax',result[1] ) else: raise falcon.HTTPBadRequest('invalid_grant',"invalid databases name %s" % dbname) logger.info("t:%s bodylen:%s" %(req.date,len(str(result)))) result={'result':result[1]} resp.body = JSONEncoder().encode(result)
def on_get(self,req,resp,action): params = req.params kw = {} kw['table'] = self.table kw['dbname']= self.dbname kw['fields']= params.get('fields','') if action == 'getcachebyuserid': """根据会员ID获取公司档案缓存信息""" user_id = params.get('user_id','') if not user_id : raise falcon.HTTPBadRequest('illegal_argument','user_id must provided') kw['where'] = "user_id=%s" % user_id kw['order'] ='id desc' result = dbhandle.getlist(kw) else: raise falcon.HTTPError(falcon.HTTP_404,'invalid_grant','invalid action %s' % action) if result[0] == -1: raise falcon.HTTPBadRequest('invalid_sql_syntax',str(result[1])) result={'result':result[1]} resp.body = JSONEncoder().encode(result)
def on_get(self,req,resp,action): params = req.params kw = {} kw['table'] = self.table kw['dbname']= self.dbname kw['fields']= params.get('fields','') if action == 'getgroupbycomid': """根据公司ID获取统计列表""" com_id = params.get('com_id','') if not com_id : raise falcon.HTTPBadRequest('illegal_argument','com_id must provided') kw['group'] = params.get('group','status') kw['fields'] = '%s,count(id) as num' % kw['group'] kw['order'] = 'NULL' kw['where'] = "com_id=%s" % com_id result = dbhandle.getlist(kw) elif action == 'getlistbycomid': """获取公司求购列表数量""" com_id = params.get('com_id','') if not com_id : raise falcon.HTTPBadRequest('illegal_argument','com_id must provided') kw['page'] = params.get('page',1) kw['pagesize'] = params.get('pagesize',sconf.PAGE_SIZE) kw['order'] = params.get('order') kw['where'] = "com_id=%s" % com_id result = dbhandle.getlist(kw) elif action == 'getcountbycomid': """根据公司ID获取产品列表数量""" com_id = params.get('com_id','') if not com_id : raise falcon.HTTPBadRequest('illegal_argument','com_id must provided') kw['fields'] = 'count(id) as n' kw['where'] = "com_id='%s'" % com_id result = dbhandle.query(kw) if result[0] == 0: n = result[1][0]['n'] result = 0,n elif action == 'getlistbyname': """根据标题或标题+公司名称判断是否有重复值(多条信息) 参数说明: title 必须 com_id 可选 返回值: status 不存在返回1,存在返回2 data 数据 """ com_id = params.get('com_id','') title = params.get('title','') if not title: raise falcon.HTTPBadRequest('illegal_argument','title must provided') kw['where'] = "title='%s'" % title if com_id: kw['where'] = "com_id=%s and %s" % (com_id,kw['where']) res, desc = dbhandle.getlist(kw) if res ==0: rs = {'status':1,'data':[]} if desc : rs['status'] = 2 rs['data'] = desc result = 0,rs else: result = res, desc else: raise falcon.HTTPError(falcon.HTTP_404,'invalid_grant','invalid action %s' % action) if result[0] == -1: raise falcon.HTTPBadRequest('invalid_sql_syntax',str(result[1])) result={'result':result[1]} resp.body = JSONEncoder().encode(result)
def on_get(self,req,resp,action): params = req.params kw = {} kw['table'] = self.table kw['dbname']= self.dbname kw['fields']= params.get('fields','') if action == 'getbyname': """根据公司名称获取对应的信息""" com_name = params.get('com_name','') if not com_name : raise falcon.HTTPBadRequest('illegal_argument','com_name must provided') kw['where'] = "com_name='%s'" % com_name result = dbhandle.getlist(kw) elif action == 'getbydomain': """根据公司三级域名获取对应的信息""" domain = params.get('domain','') if not domain : raise falcon.HTTPBadRequest('illegal_argument','domain must provided') kw['where'] = "domain='%s'" % domain result = dbhandle.getlist(kw) elif action == 'getmaxid': """获取公司的最大ID""" kw['fields'] = 'max(id) as mx' result = dbhandle.query(kw) if result[0] == 0: mx = result[1][0]['mx'] result = 0,mx elif action == 'getlistbyuserid': """根据用户id获取公司的信息(多条信息)""" user_id = params.get('user_id','') if not user_id : raise falcon.HTTPBadRequest('illegal_argument','user_id must provided') kw['where'] = "user_id=%s" % user_id result = dbhandle.getlist(kw) elif action == 'getbyuserid': """根据用户id获取公司的信息(单条信息)""" user_id = params.get('user_id','') if not user_id : raise falcon.HTTPBadRequest('illegal_argument','user_id must provided') kw['where'] = "user_id=%s" % user_id kw['limit'] = "1" result = dbhandle.getlist(kw) elif action == 'gettagbycomid': """根据公司id获取一条公司标签关联值""" kw['table'] = 'com_tag_relate' com_id = params.get('com_id','') if not com_id : raise falcon.HTTPBadRequest('illegal_argument','com_id must provided') kw['where'] = "com_id=%s" % com_id kw['limit'] = "1" result = dbhandle.getlist(kw) elif action == 'getkeywbycomid': """根据公司id获取公司展厅关键字""" kw['table'] = 'com_keyword' com_id = params.get('com_id','') if not com_id : raise falcon.HTTPBadRequest('illegal_argument','com_id must provided') kw['where'] = "com_id=%s" % com_id kw['limit'] = "1" result = dbhandle.getlist(kw) else: raise falcon.HTTPError(falcon.HTTP_404,'invalid_grant','invalid action %s' % action) if result[0] == -1: raise falcon.HTTPBadRequest('invalid_sql_syntax',str(result[1])) result={'result':result[1]} resp.body = JSONEncoder().encode(result)