Ejemplo 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()
Ejemplo n.º 2
0
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()