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 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 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 authenticate(cls, username, password): """ 用户登录,登录成功返回token,写将登录时间写入数据库;登录失败返回失败原因 :param password: :return: json """ userInfo = db_session.query(UserInfo).filter( UserInfo.LOGIN_NAME == username).first() if (userInfo is None): return abort(401, "用户名或密码错误") else: if (userInfo.check_password(userInfo.USER_PWD, password)): login_time = int(time.time()) ###这里后期需要将登录时间写入缓存,提高性能 token = cls.__encode_auth_token(cls, userInfo.USER_KEY, login_time) dict_user = MySqlalchemy.convertToDict(userInfo) return dict_user, token.decode() else: return abort(401, "用户名或密码错误")
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()