Exemplo n.º 1
0
def get_syncmsg(db, arg):
    listObj = {
        "total": 0,
        "list": [],
    }

    paras = arg["paras"]

    start = arg["paras"].get("start") or 0
    limit = arg["paras"].get("limit") or 100

    cond = "WHERE 1=1 "
    agentId = paras["agentId"]
    type = paras["type"]

    if agentId:
        cond += "AND M_AgentId='%s' " % agentId
    if type:
        cond += "AND M_Type='%s' " % type

    cond += "ORDER BY M_Time DESC"
    ret = db.select(TB_MSG, cond=cond, limit=int(limit), offset=int(start))
    if ret == -1:
        ERROR("get agent list error")
        return (DB_ERR, None)

    for dur in db.cur:
        obj = dbmysql.row_to_dict(TB_MSG, dur)
        item = Msg(db, dbObj=obj)
        item.loadFromObj()
        listObj["list"].append(item.toObj())

    listObj["total"] = getMsgCount(db, cond)

    return (OCT_SUCCESS, listObj)
Exemplo n.º 2
0
def get_products(db, paras):
    listObj = {
        "items": [],
        "total": 0,
    }
    type = paras["type"]

    cond = "WHERE 1=1 "
    if type:
        cond += "AND P_Type='%s' " % type

    state = paras["state"]
    if state:
        cond += "AND P_State='%s' " % state

    cond += "ORDER BY P_CreateTime "

    ret = db.select(TB_PRODUCT, cond=cond)
    if ret == -1:
        ERROR("get user list error")
        return (DB_ERR, None)

    for dur in db.cur:
        obj = dbmysql.row_to_dict(TB_PRODUCT, dur)
        product = Product(db, dbObj=obj)
        product.loadFromObj()

        listObj["items"].append(product.toObj())

    listObj["items"].sort(key=lambda x: x["infoObj"]["id"])

    listObj["total"] = len(listObj["items"])

    return (OCT_SUCCESS, listObj)
Exemplo n.º 3
0
def get_alluser(db, arg):
    listObj = {
        "total": 0,
        "users": [],
    }

    start = arg["paras"].get("start") or 0
    limit = arg["paras"].get("limit") or 100

    cond = "WHERE 1=1 "
    ret = db.select(TB_ACCOUNT, cond=cond, limit=int(limit), offset=int(start))
    if ret == -1:
        ERROR("get user list error")
        return (DB_ERR, None)

    for dur in db.cur:
        obj = dbmysql.row_to_dict(TB_ACCOUNT, dur)
        user = Account(db, dbObj=obj)
        user.loadFromObj()

        listObj["users"].append(user.toObj())

    listObj["total"] = getAccountCount(db)

    return (OCT_SUCCESS, listObj)
Exemplo n.º 4
0
def get_agents(db, arg):
    listObj = {
        "total": 0,
        "list": [],
    }

    start = arg["paras"].get("start") or 0
    limit = arg["paras"].get("limit") or 100

    cond = "WHERE 1=1 "
    ret = db.select(TB_AGENT, cond=cond, limit=int(limit), offset=int(start))
    if ret == -1:
        ERROR("get agent list error")
        return (DB_ERR, None)

    for dur in db.cur:
        obj = dbmysql.row_to_dict(TB_AGENT, dur)
        item = Agent(db, dbObj=obj)
        item.loadFromObj()

        listObj["list"].append(item.toObj())

    listObj["total"] = getAgentCount(db)

    return (OCT_SUCCESS, listObj)
Exemplo n.º 5
0
def get_allrobot(db, arg):

    listObj = {
        "total": 0,
        "robots": [],
    }

    start = arg["paras"].get("start") or 0
    limit = arg["paras"].get("limit") or 100

    cond = "WHERE 1=1 "
    cond += "AND R_AccountId='%s' " % arg["paras"]["accountId"]

    ret = db.select(TB_ROBOT, cond=cond, limit=int(limit), offset=int(start))
    if ret == -1:
        ERROR("get robot list error")
        return (DB_ERR, None)

    for dur in db.cur:
        obj = dbmysql.row_to_dict(TB_ROBOT, dur)
        robot = WCRobot(db, dbObj=obj)
        robot.loadFromObj()

        listObj["robots"].append(robot.toObj())

    listObj["total"] = getRobotCount(db, cond=cond)

    return (OCT_SUCCESS, listObj)
Exemplo n.º 6
0
def getApis(db, arg):
    listObj = {"data": [], "total": 0}
    cond = "WHERE 1=1 "

    accountId = arg["paras"].get("accountId")
    start = arg["paras"].get("start") or 0
    limit = arg["paras"].get("limit") or 10
    keyword = arg["paras"].get("keyword") or ""
    type = arg["paras"].get("type")
    apiName = arg["paras"].get("apiName")
    serverTaskId = arg["paras"].get("serverTaskId")

    if (accountId and accountId != DEFAULT_ACCOUNT_ID):
        cond += "AND AT_AccountId='%s' " % (accountId)

    if (type):
        cond += "AND AT_Type='%s' " % type

    if (apiName):
        cond += "AND AT_Name LIKE '%%%s%%' " % (apiName)

    if (keyword):
        cond += "AND AT_ApiId LIKE '%%%s%%' " % (keyword)

    if (serverTaskId):
        cond += "AND AT_ServerTaskId='%s' " % serverTaskId

    cond += "ORDER BY AT_StartTime DESC"

    ret = db.select(TB_APITRACE,
                    cond=cond,
                    limit=int(limit),
                    offset=int(start))
    if ret == -1:
        ERROR("get modules list error")
        return (OCT_SUCCESS, listObj)

    hashStr = ""
    for dur in db.cur:
        obj = dbmysql.row_to_dict(TB_APITRACE, dur)
        api = Api(db, dbObj=obj)
        api.loadFromObj()
        obj = api.toObj()
        hashStr += api.myId
        hashStr += api.state
        listObj["data"].append(obj)

    listObj["total"] = getApiCount(db, cond=cond)
    listObj["hashValue"] = CRC32(hashStr)

    return (OCT_SUCCESS, listObj)
Exemplo n.º 7
0
def get_userlist(db):
    user_list = []

    ret = db.select(TB_ACCOUNT, cond="")
    if ret == -1:
        ERROR("get user list error")
        return (DB_ERR, None)

    for dur in db.cur:
        obj = dbmysql.row_to_dict(TB_ACCOUNT, dur)
        temp = {
            "id": obj["ID"],
            "name": obj["U_Name"],
        }
        user_list.append(temp)

    DEBUG(user_list)

    return (OCT_SUCCESS, user_list)
Exemplo n.º 8
0
def get_robotlist(db, arg):

    robot_list = []

    cond = "WHERE 1=1 "
    cond += "AND R_AccountId='%s' " % arg["paras"]["accountId"]

    ret = db.select(TB_ROBOT, cond="")
    if ret == -1:
        ERROR("get robot list error")
        return (DB_ERR, None)

    for dur in db.cur:
        obj = dbmysql.row_to_dict(TB_ROBOT, dur)
        temp = {
            "id": obj["ID"],
            "name": obj["R_Name"],
        }
        robot_list.append(temp)

    DEBUG(robot_list)

    return (OCT_SUCCESS, robot_list)
Exemplo n.º 9
0
def get_queryresults(db, paras):
    listObj = {
        "items": [],
        "total": 0,
    }
    type = paras["type"]

    cond = "WHERE 1=1 "
    if type:
        cond += "AND QR_Type='%s' " % type

    date = paras["date"]
    if date:
        now = get_current_time()
        cond += "AND QR_CreateTime >= %ld " % (now -
                                               date * 24 * 60 * 60 * 1000)

    keyword = paras["keyword"]
    if keyword:
        cond += "AND QR_Name LIKE '%%%s%%' " % keyword

    ret = db.select(TB_QUERYRESULT, cond=cond)
    if ret == -1:
        ERROR("get user list error")
        return (DB_ERR, None)

    for dur in db.cur:
        obj = dbmysql.row_to_dict(TB_QUERYRESULT, dur)
        item = PricingResult(db, dbObj=obj)
        item.loadFromObj()

        listObj["items"].append(item.toObj())

    listObj["total"] = len(listObj["items"])

    return (OCT_SUCCESS, listObj)