Esempio n. 1
0
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()
Esempio n. 2
0
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()
Esempio n. 3
0
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()