def get_child_businesses(self, parent_business_code): ''' 通过父业务编码获取子业务 ''' child_business = pg_update.select("business", order_by='id', where=" parent_business_code = '%s' " % parent_business_code) for business in child_business: if business['is_leaf'] == 0: business['child'] = pg_update.select("business", order_by='id', where=" parent_business_code = '%s' " % parent_business_code) return child_business
def get_child_businesses(parent_business_code): ''' 通过父业务编码获取子业务 ''' child_business = pg_update.select("business", order_by='id', where=" parent_business_code = '%s' " % parent_business_code) for business in child_business: if business['is_leaf'] == 0: business['child'] = pg_update.select("business", order_by='id', where=" parent_business_code = '%s' " % parent_business_code) return child_business
def get_user_by_ap(self, user): ''' 通过用户名密码获取用户 ''' where = " account = '%s' and password = '******' " % (user['account'], user['password']) return pg_update.select("user_info", where=where, columns='id,account')
def get_role_parent_role_code(slef, role_code): ''' 获取所有角色 create by chenli at 16/01/07 11:37 ''' parent_role_code = pg_update.select("role", where="role_code = '%s' " % role_code)[0]['parent_role_code'] return 'root' if parent_role_code == 'None' else parent_role_code
def get_user_by_account(self, account): ''' 通过帐号获取用户 ''' return pg_update.select("user_info", where=" account = '%s' " % account, columns='id,account')
def get_component_businesses(self): ''' 获取所有业务 ''' return pg_update.select("business", order_by="id", where="component is not null", limit=-1)
def get_user_by_id(user_id): sql = ''' select * from role where role_code in ( select r.role_code from user_info u,user_role r where u.id = %s and u.account = r.account and r.status=0) ''' % user_id roles = pg_update.selectBySql(sql) user = pg_update.select("user_info", where=' id = %s ' % user_id, columns='id,account')[0] user['roles'] = roles return user
def get_businesses_by_role_code(self, role_code): ''' 获取某角色拥有的所有业务 ''' business_codes = pg_update.select("role_business", where="role_code = '%s'" % role_code) where = '' for business_code in business_codes: where += "or seq_code like '%%%s%%'" % business_code['business_code'] sql = ''' select * from ( select * from business where status = 0 ) b where %s ''' % where[2:] return pg_update.selectBySql(sql)
def get_businesses_by_role_code(self, role_code): ''' 获取某角色拥有的所有业务 ''' business_codes = pg_update.select("role_business", where="role_code = '%s'" % role_code) where = '' for business_code in business_codes: where += "or seq_code like '%%%s%%'" % business_code[ 'business_code'] sql = ''' select * from ( select * from business where status = 0 ) b where %s ''' % where[2:] return pg_update.selectBySql(sql)
def __addApi(): ''' 将其api接口函数信息添加到api表中 ''' funs = __getFuns() for fun in funs: if pg_update.select("api", where=" api = '%s' " % fun.__name__): # 已存在则跳过 continue data_map = {} data_map['api'] = fun.__name__ data_map['api_explain'] = fun.__doc__.strip('\n').split('\n')[0].strip( ' ').strip('\n') if fun.__doc__ else '' data_map['path'] = fun.__module__ data_map['disable'] = 0 data_map['error'] = 0 data_map['session'] = 1 data_map['restrict'] = (0 if fun.__module__ == 'model.businessLayer.base_business' else 1) pg_update.insertOne("api", data_map)
def add_session_by_account(self, account): ''' session注册 ''' where = "account = '%s' and status = 0 and invalid_time > now() " % account session = pg_update.select("session", where=where) if session: raise CooError(text='该帐号已被登陆!') data = {} data['account'] = account data['session'] = str(uuid.uuid4()) # 60秒后失效 data['invalid_time'] = str(datetime.datetime.now() + datetime.timedelta(seconds=600))[:19] try: pg_update.insertOne("session", data) return data['session'] except Exception, e: if str(e).find('unique') != -1: return add_session_by_account(account) else: print e raise CooError(text='未知错误')
def get_businesses(): ''' 获取所有业务 ''' datas = pg_update.select("business", order_by="id", limit=-1) return datas
def get_businesses_by_api(self, api): ''' 通过api获取业务api数据 ''' return pg_update.select("business_api", where=" api = '%s' " % api)
def get_session_by_session(self, session): where = "session = '%s' and status = 0 and invalid_time > now() " % session return pg_update.select("session", where=where)
def get_businesses(self): ''' 获取所有业务 ''' return pg_update.select("business", order_by="id", limit=-1)
def get_user_head_file_name_by_account(self, account): return pg_update.select("user_detail", where=" account = '%s' and status = 0 " % account)
def get_roles(slef): ''' 获取所有角色 create by chenli at 16/01/07 11:37 ''' return pg_update.select("role", order_by="id", limit=-1)