def importLogLogin(): myRes = MyResponse() try: ###添加注入清单信息 f = request.files['Ffile'] uploadFile = UploadFile(f) uploadFile.import_file() xlrdReader = XlrdReader( os.path.join(uploadFile.filepath, uploadFile.filename)) xlrdReader.readSheetToList() reader_data = xlrdReader.datas reader_titles = xlrdReader.titles for index_row, row in enumerate(reader_data): sysLog = LogLogin() sysLog.FuserId = row[0] sysLog.FcreateTime = getSysDateTime() sysLog.Ffunc = row[1] sysLog.FipAddress = row[2] sysLog.Fremark = row[5] db_session.add(sysLog) db_session.commit() myRes.code = ResState.HTTP_SUCCESS except ExcelError as ex: mylog.error(ex) abort(404, "读取excel错误") except SQLAlchemyError as ex: db_session.rollback() mylog.error(ex) abort(404, sys.exc_info()[1]) finally: pass return myRes.to_json()
def exportLogOper(): start_time = time.time() searchName = MyRequest.get("searchName", type=str).strip() startDate = MyRequest.get_verify_date("startDate") endDate = MyRequest.get_verify_date("endDate") downLoadFile = DownLoadFile() xlsxwriterWriter = XlsxwriterWriter() try: query_data = db_session.query(LogOper).all() from app.apis.utils.thread_helper import convertToListThread dataArray = convertToListThread(query_data) end_time = time.time() print(end_time - start_time) print(len(dataArray)) # df = pandas.DataFrame(dataArray) # xlsxwriterWriter.open() # xlsxwriterWriter.writeSheetbyList(df, titles=None, sheetname="ttt") # downLoadFile.filepath = xlsxwriterWriter.filepath # downLoadFile.filename=xlsxwriterWriter.filename # downLoadFile.newfilename = "操作日志"+getSysDateTimeStr()+".xlsx" except ExcelError as ex: mylog.error(ex) abort(404, "写入excel错误") except SQLAlchemyError as ex: mylog.error(ex) abort(404, sys.exc_info()[1]) except Exception as ex: mylog.error(ex) abort(404, sys.exc_info()[1]) finally: xlsxwriterWriter.close() myRes = MyResponse() print("ok") 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()
def not_found(error): """ URL Not Found 如果资源不存在并且从来没存在过则抛出。 :param error: :return: """ ###传统方式 myRes = MyResponse() myRes.msg = error.description myRes.code=404 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 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 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() 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 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 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 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 exportLogLogin(): myRes = MyResponse() searchName = MyRequest.get("searchName", type=str).strip() startDate = MyRequest.get_verify_date("startDate") endDate = MyRequest.get_verify_date("endDate") downLoadFile = DownLoadFile() xlsxwriterWriter = XlsxwriterWriter() try: db_query = db_session.query(UserInfo.Fid, UserInfo.FloginName, UserInfo.Fname, LogLogin.FcreateTime, LogLogin.Fremark, LogLogin.FipAddress) db_query = db_query.outerjoin(UserInfo, UserInfo.Fid == LogLogin.FuserId) db_query = db_query.filter( LogLogin.FcreateTime.between(startDate, endDate)) if searchName != '': db_query = db_query.filter( UserInfo.FloginName.like("%" + searchName + "%")) query_data = db_query.order_by(LogLogin.FcreateTime.desc()) dataArray = MySqlalchemy.convertToDict(query_data) df = pandas.DataFrame(dataArray) xlsxwriterWriter.open() xlsxwriterWriter.writeSheetbyList(df, titles=None, sheetname="ttt") downLoadFile.filepath = xlsxwriterWriter.filepath downLoadFile.filename = xlsxwriterWriter.filename downLoadFile.newfilename = "操作日志" + getSysDateTimeStr() + ".xlsx" myRes.data = [] myRes.code = ResState.HTTP_SUCCESS myRes.msg = "操作成功" except ExcelError as ex: mylog.error(ex) abort(404, "写入excel错误") except SQLAlchemyError as ex: mylog.error(ex) abort(404, sys.exc_info()[1]) finally: xlsxwriterWriter.close() return downLoadFile.download()
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() 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 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 getDetail(): myRes = MyResponse() DPT_KEY = MyRequest.get_verify_empty("DPT_KEY", errmsg="部门ID不能为空") try: query_data=db_session.query(DptInfo).filter(DptInfo.DPT_KEY==DPT_KEY).one() dict_menu=MySqlalchemy.convertToDict(query_data) myRes.data = dict_menu myRes.code = ResState.HTTP_SUCCESS except SQLAlchemyError as ex: mylog.error(ex) myRes.msg=str(ex) 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 getDetail(): myRes = MyResponse() Fid = MyRequest.get_verify_empty("Fid", errmsg="Fid不能为空") try: query_menu = db_session.query(MenuInfo).filter( MenuInfo.Fid == Fid).one() dict_menu = MySqlalchemy.convertToDict(query_menu) myRes.data = dict_menu myRes.code = ResState.HTTP_SUCCESS except SQLAlchemyError as ex: mylog.error(ex) myRes.msg = str(ex) return myRes.to_json()
def getDetail(): myRes = MyResponse() ROLE_KEY = MyRequest.get("ROLE_KEY", type=int) try: query_data = db_session.query(RoleInfo).filter( RoleInfo.ROLE_KEY == ROLE_KEY).one() dict_data = MySqlalchemy.convertToDict(query_data) myRes.code = ResState.HTTP_SUCCESS myRes.data = dict_data 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 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()