def updRolePermission(): myRes = MyResponse() RESOURCE_KEYS = MyRequest.get_verify_list("RESOURCE_KEYS") ROLE_KEY = MyRequest.get("ROLE_KEY", type=int) RESOURCE_TYPE = MyRequest.get("RESOURCE_TYPE", type=int) try: db_session.begin_nested() db_session.query(RolePermission).filter( RolePermission.ROLE_KEY == ROLE_KEY).filter( RolePermission.RESOURCE_TYPE == RESOURCE_TYPE).delete( synchronize_session=False) for key in RESOURCE_KEYS: rolePermission = RolePermission() rolePermission.ROLE_KEY = ROLE_KEY rolePermission.RESOURCE_KEY = key rolePermission.RESOURCE_TYPE = RESOURCE_TYPE db_session.add(rolePermission) db_session.commit() myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: db_session.rollback() mylog.error(ex) myRes.msg = str(ex) finally: db_session.close() return myRes.to_json()
def add(): myRes = MyResponse() MENU_NAME = MyRequest.get_verify_empty("MENU_NAME", errmsg="菜单名称不能为空") MENU_PKEY = MyRequest.get_verify_empty("MENU_PKEY", errmsg="MENU_PKEY") MENU_URL = MyRequest.get("MENU_URL", type=str) MENU_ICON = MyRequest.get("MENU_ICON", type=str) MENU_SOFT = MyRequest.get("MENU_SOFT", type=str) try: mybrother = db_session.query( MenuInfo.MENU_KEY).filter(MenuInfo.MENU_PKEY == MENU_PKEY).all() if mybrother: array_id = [int(x.MENU_KEY) for x in mybrother] ###取最大的ID MENU_KEY = str(max(array_id) + 1) elif MENU_PKEY == "0": MENU_KEY = "101" else: MENU_KEY = MENU_PKEY + "001" menu = MenuInfo() menu.MENU_KEY = MENU_KEY menu.MENU_NAME = MENU_NAME menu.MENU_PKEY = MENU_PKEY menu.MENU_URL = MENU_URL menu.MENU_ICON = MENU_ICON menu.MENU_SOFT = MENU_SOFT MySqlalchemy.comAdd(menu) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def add(): myRes = MyResponse() DPT_PKEY = MyRequest.get_verify_empty("DPT_PKEY", errmsg="请选择一个父节点") DPT_NAME = MyRequest.get_verify_empty("DPT_NAME", errmsg="部门名称不能为空") DPT_SOFT = MyRequest.get("DPT_SOFT", type=int) try: mybrother = db_session.query(DptInfo.DPT_KEY).filter(DptInfo.DPT_PKEY == DPT_PKEY).all() if mybrother: array_id = [int(x.DPT_KEY) for x in mybrother] ###取最大的ID DPT_KEY = str(max(array_id) + 1) elif DPT_PKEY=="0": DPT_KEY = "101" else: DPT_KEY=DPT_PKEY+"001" dpt = DptInfo() dpt.DPT_KEY=DPT_KEY dpt.DPT_PKEY = DPT_PKEY dpt.DPT_NAME = DPT_NAME dpt.DPT_SOFT = DPT_SOFT MySqlalchemy.comAdd(dpt) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg=ResState.ERROR_DB return myRes.to_json()
def add(): myRes = MyResponse() OPER_NAME = MyRequest.get_verify_empty("OPER_NAME", errmsg="操作名称不能为空") OPER_PKEY = MyRequest.get_verify_empty("OPER_PKEY", errmsg="OPER_PKEY不能为空") OPER_URL = MyRequest.get("OPER_URL", type=str) OPER_TYPE = MyRequest.get("OPER_TYPE", type=int) OPER_SOFT = MyRequest.get("OPER_SOFT", type=int) try: mybrother = db_session.query( OperInfo.OPER_KEY).filter(OperInfo.OPER_PKEY == OPER_PKEY).all() if mybrother: array_id = [int(x.OPER_KEY) for x in mybrother] ###取最大的ID OPER_KEY = str(max(array_id) + 1) elif OPER_PKEY == "0": OPER_KEY = "101" else: OPER_KEY = OPER_PKEY + "001" operInfo = OperInfo() operInfo.OPER_KEY = OPER_KEY operInfo.OPER_NAME = OPER_NAME operInfo.OPER_URL = OPER_URL operInfo.OPER_TYPE = OPER_TYPE operInfo.OPER_PKEY = OPER_PKEY operInfo.OPER_SOFT = OPER_SOFT MySqlalchemy.comAdd(operInfo) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getPageListLogin(): myRes = MyResponse() currentPage = MyRequest.get("currentPage", type=int) pageSize = MyRequest.get("pageSize", type=int) searchName = MyRequest.get("searchName", type=str).strip() startDate = MyRequest.get_verify_date("startDate") endDate = MyRequest.get_verify_date("endDate") try: columns = [ LogLogin.LOGL_KEY, LogLogin.TIME_CREATE, LogLogin.DESCRIPT, LogLogin.IP_ADDRESS, UserInfo.LOGIN_NAME, UserInfo.USER_NAME ] outerjoins = [(UserInfo, UserInfo.USER_KEY == LogLogin.USER_KEY)] filters = [LogLogin.TIME_CREATE.between(startDate, endDate)] if searchName != '': filters.append(UserInfo.FloginName.like("%" + searchName + "%")) myRes.data = MySqlalchemy.get_page_list( currentPage, pageSize, LogLogin.LOGL_KEY, columns, outerjoins=outerjoins, filters=filters, orders=[LogLogin.TIME_CREATE.desc()]) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getList(): myRes = MyResponse() try: myRes.data=MySqlalchemy.get_all(DptInfo,orders=DptInfo.DPT_SOFT.asc()) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = ResState.ERROR_DB return myRes.to_json()
def getList(): myRes = MyResponse() try: query_data = db_session.query(UserInfo).all() myRes.data = MySqlalchemy.convertToList(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def delete(): myRes = MyResponse() USER_KEY = MyRequest.get("USER_KEY", type=int) try: MySqlalchemy.comDel(UserInfo, [UserInfo.USER_KEY == USER_KEY]) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = ResState.ERROR_DB return myRes.to_json()
def getList(): myRes = MyResponse() try: query_data = db_session.query(RoleInfo).order_by( RoleInfo.TIME_MODIFY.desc()) myRes.data = MySqlalchemy.convertToList(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getList(): myRes = MyResponse() try: query_menuButton = db_session.query(OperInfo).order_by( OperInfo.OPER_SOFT.asc()).all() myRes.data = MySqlalchemy.convertToList(query_menuButton) print(myRes.data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getList(): myRes = MyResponse() try: query_menu = db_session.query( MenuInfo.MENU_KEY, MenuInfo.MENU_PKEY, MenuInfo.MENU_NAME, MenuInfo.MENU_URL, MenuInfo.MENU_ICON, MenuInfo.MENU_SOFT).order_by(MenuInfo.MENU_SOFT.asc()).all() myRes.data = MySqlalchemy.convertToList(query_menu) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def delete(): myRes = MyResponse() ROLE_KEY = MyRequest.get("ROLE_KEY", type=int) try: MySqlalchemy.comDel(RoleInfo, [RoleInfo.ROLE_KEY == ROLE_KEY]) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: db_session.rollback() mylog.error(ex) myRes.msg = str(ex) finally: db_session.close() return myRes.to_json()
def update(): myRes = MyResponse() DPT_KEY = MyRequest.get_verify_empty("DPT_KEY", errmsg="ID不能为空") upd_attr={} upd_attr["DPT_NAME"] = MyRequest.get_verify_empty("DPT_NAME", errmsg="部门名称不能为空") upd_attr["DPT_SOFT"] = MyRequest.get("DPT_SOFT", type=int) try: MySqlalchemy.comUpdate(DptInfo,[DptInfo.DPT_KEY==DPT_KEY],upd_attr) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = ResState.ERROR_DB return myRes.to_json()
def getRoleMenuAndOperList(): myRes = MyResponse() ROLE_KEY = MyRequest.get("ROLE_KEY", type=int) try: query_data = db_session.query(RolePermission.ROLE_KEY, RolePermission.RESOURCE_KEY, RolePermission.RESOURCE_TYPE).filter( RolePermission.ROLE_KEY == ROLE_KEY) myRes.data = MySqlalchemy.convertToList(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getRoleListByUserKey(): myRes = MyResponse() USER_KEY = MyRequest.get("USER_KEY", type=int) try: clomns = [UserRole.USER_KEY, RoleInfo.ROLE_NAME, UserRole.ROLE_KEY] query_data = db_session.query(*clomns).outerjoin( RoleInfo, RoleInfo.ROLE_KEY == UserRole.ROLE_KEY).filter( UserRole.USER_KEY == USER_KEY) myRes.data = MySqlalchemy.convertToList(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getPageList(): myRes = MyResponse() currentPage = MyRequest.get("currentPage", type=int) pageSize = MyRequest.get("pageSize", type=int) searchDptKey = MyRequest.get("searchDptKey", type=str) searchName = MyRequest.get("searchName", type=str).strip() columns = [ UserInfo.USER_KEY, UserInfo.USER_NAME, UserInfo.LOGIN_NAME, UserInfo.USER_SEX, UserInfo.USER_POSITION, UserInfo.DPT_KEY, DptInfo.DPT_NAME, UserInfo.TIME_MODIFY, UserInfo.PHONE ] filters = [] outerjoins = [(DptInfo, DptInfo.DPT_KEY == UserInfo.DPT_KEY)] try: USER_KEY = g.USER_KEY if USER_KEY != 1: filters.append(UserInfo.USER_KEY != 1) if searchDptKey != 0: filters.append(UserInfo.DPT_KEY.like(searchDptKey + "%")) if searchName is not None: filters.append(UserInfo.USER_NAME.like("%" + searchName + "%")) user_page_info = MySqlalchemy.get_page_list( currentPage, pageSize, UserInfo.USER_KEY, columns, outerjoins=outerjoins, filters=filters, orders=[UserInfo.TIME_MODIFY.desc()]) ###拼接用户角色 query_data_role = db_session.query( UserRole.USER_KEY, RoleInfo.ROLE_NAME, UserRole.ROLE_KEY).outerjoin( RoleInfo, RoleInfo.ROLE_KEY == UserRole.ROLE_KEY) list_role = MySqlalchemy.convertToList(query_data_role) for xuser in user_page_info["data"]: list_roleName = [] for xrole in list_role: if xuser["USER_KEY"] == xrole["USER_KEY"]: list_roleName.append(xrole["ROLE_NAME"]) xuser["ROLE_NAMES"] = ",".join(list_roleName) myRes.data = user_page_info myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def resetPwdByUserKey(): myRes = MyResponse() USER_KEY = MyRequest.get("USER_KEY", type=int) try: q_model = db_session.query(UserInfo).filter( UserInfo.USER_KEY == USER_KEY).one() q_model.set_password("123456") db_session.commit() myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) finally: db_session.close() return myRes.to_json()
def getDptAndUserList(): myRes = MyResponse() try: query_data_dpt = db_session.query(DptInfo.DPT_KEY, DptInfo.DPT_PKEY, DptInfo.DPT_NAME) query_data_user = db_session.query( UserInfo.USER_KEY, UserInfo.DPT_KEY, UserInfo.USER_NAME).filter(UserInfo.USER_KEY != 1) query_data = query_data_dpt.union_all(query_data_user) myRes.data = MySqlalchemy.convertToList(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def delete(): myRes = MyResponse() DPT_KEY = MyRequest.get_verify_empty("DPT_KEY", errmsg="ID不能为空") try: rows = db_session.query(DptInfo).filter(DptInfo.DPT_KEY.like(DPT_KEY+"%")).delete(synchronize_session=False) db_session.commit() if rows < 1: raise SQLAlchemyError("操作失败") myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = ResState.ERROR_DB finally: db_session.close() return myRes.to_json()
def update(): myRes = MyResponse() ROLE_KEY = MyRequest.get("ROLE_KEY", type=int) role_attrs = {} role_attrs["ROLE_NAME"] = MyRequest.get_verify_empty("ROLE_NAME") role_attrs["DESCRIPT"] = MyRequest.get("DESCRIPT") role_attrs["TIME_MODIFY"] = getSysDateTime() try: MySqlalchemy.comUpdate(RoleInfo, [RoleInfo.ROLE_KEY == ROLE_KEY], role_attrs) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def update(): myRes = MyResponse() MENU_KEY = MyRequest.get_verify_empty("MENU_KEY", errmsg="MENU_KEY不能为空") menu_attrs = {} menu_attrs["MENU_NAME"] = MyRequest.get("MENU_NAME", type=str) menu_attrs["MENU_URL"] = MyRequest.get("MENU_URL", type=str) menu_attrs["MENU_ICON"] = MyRequest.get("MENU_ICON", type=str) menu_attrs["MENU_SOFT"] = MyRequest.get("MENU_SOFT", type=str) try: MySqlalchemy.comUpdate(MenuInfo, [MenuInfo.MENU_KEY == MENU_KEY], menu_attrs) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getLoginUserPermissionList(): myRes = MyResponse() try: USER_KEY = g.USER_KEY outerjoins_menu = [] outerjoins_oper = [] filters = [] columns_menu = [ MenuInfo.MENU_SOFT, MenuInfo.MENU_KEY, MenuInfo.MENU_ICON, MenuInfo.MENU_URL, MenuInfo.MENU_PKEY, MenuInfo.MENU_NAME ] columns_oper = [OperInfo.OPER_NAME, OperInfo.OPER_URL] if USER_KEY != 12: outerjoins_menu = [ (RolePermission, and_(MenuInfo.MENU_KEY == RolePermission.RESOURCE_KEY, RolePermission.RESOURCE_TYPE == 0)), (UserRole, UserRole.ROLE_KEY == RolePermission.ROLE_KEY) ] outerjoins_oper = [ (RolePermission, and_(OperInfo.OPER_KEY == RolePermission.RESOURCE_KEY, RolePermission.RESOURCE_TYPE == 1)), (UserRole, UserRole.ROLE_KEY == RolePermission.ROLE_KEY) ] filters = [(UserRole.USER_KEY == USER_KEY)] query_data_menu = MySqlalchemy.get_all(columns_menu, outerjoins=outerjoins_menu, filters=filters, orders=[ (MenuInfo.MENU_SOFT.asc()) ]) query_data_oper = MySqlalchemy.get_all(columns_oper, outerjoins=outerjoins_oper, filters=filters, orders=[ (OperInfo.OPER_SOFT.asc()) ]) myRes.data = {"menuList": query_data_menu, "operList": query_data_oper} myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def update(): myRes = MyResponse() OPER_KEY = MyRequest.get_verify_empty("OPER_KEY", errmsg="OPER_KEY不能为空") oper_attrs = {} oper_attrs["OPER_NAME"] = MyRequest.get_verify_empty("OPER_NAME", errmsg="按钮编码不能为空") oper_attrs["OPER_URL"] = MyRequest.get("OPER_URL", type=str) oper_attrs["OPER_TYPE"] = MyRequest.get("OPER_TYPE", type=int) oper_attrs["OPER_SOFT"] = MyRequest.get("OPER_SOFT", type=int) try: MySqlalchemy.comUpdate(OperInfo, [OperInfo.OPER_KEY == OPER_KEY], oper_attrs) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def updMyInfo(): myRes = MyResponse() USER_KEY = g.USER_KEY upd_attr = {} upd_attr["USER_NAME"] = MyRequest.get_verify_empty("USER_NAME", errmsg="姓名不能为空") upd_attr["PHONE"] = MyRequest.get("PHONE", type=str) try: MySqlalchemy.comUpdate(UserInfo, [UserInfo.USER_KEY == USER_KEY], upd_attr) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) finally: db_session.close() return myRes.to_json()
def add(): myRes = MyResponse() ROLE_NAME = MyRequest.get_verify_empty("ROLE_NAME") DESCRIPT = MyRequest.get("DESCRIPT") try: role = RoleInfo() role.ROLE_NAME = ROLE_NAME role.DESCRIPT = DESCRIPT role.TIME_CREATE = getSysDateTime() role.TIME_MODIFY = getSysDateTime() MySqlalchemy.comAdd(role) myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except MyError as ex: myRes.msg = ex except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = ResState.ERROR_DB return myRes.to_json()
def internal_server_error(error): """ Internal Server Error 如果一个内部服务错误发生则抛出。如果在调度时一个未知错误发生,这是一个很好的后备东西。 :param error: :return: """ myRes = MyResponse() myRes.msg = error.description myRes.code = 500 return myRes.to_json()
def not_found(error): """ Method Not Allowed 如果服务器使用一个资源无法处理的方法,则抛出。 :param error: :return: """ myRes=MyResponse() myRes.msg=error.description myRes.code=405 return myRes.to_json()
def not_found(error): """ Forbidden 如果用户没有权限请求该资源但是已经认证过了,则抛出。 :param error: :return: """ myRes = MyResponse() myRes.msg = error.description myRes.code = 403 return myRes.to_json()
def not_found(error): """ Unauthorized 如果用户没有认证则抛出 :param error: :return: """ myRes = MyResponse() myRes.msg = error.description myRes.code = 401 return myRes.to_json()
def not_found(error): """ Bad Request 如果浏览器发送一些东西给应用,应用或服务器无法处理,则抛出,可用于参数校验 :param error: :return: """ myRes = MyResponse() myRes.msg = error.description myRes.code = 400 return myRes.to_json()