*** Settings *** Library json Library Collections Library RequestsLibrary Library DateTime Resource ../../../03-Variable/BifangApiVariable.txt Resource ../../../02-Keyword/tsg_bfapi/policy_file_interface/FunctionalKeywords.robot Resource ../Common.robot *** Variables *** ${logUrl} /log ${arraySplitor} , ${itemSplitor} | ${valueSplitor} ^ *** Keywords *** GetLogSchema [Documentation] ... 日志schema查询 ... logType 日志类型 ... resData schema数据 [Arguments] ${logType} ${response} BaseFormRequest ${logUrl}/schema logType=${logType} ${version} ${rescode} Set Variable ${response['code']} Should Be Equal As Strings ${rescode} 200 ${resData} Set Variable ${response['data']} ${schema_query} Get From Dictionary ${resData['doc']} schema_query ${schema_type} Get From Dictionary ${resData['doc']} schema_type ${default_columns} Get From Dictionary ${resData['doc']} default_columns [Return] ${schema_query} ${schema_type} ${default_columns} ${resData['fields']} QueryLogs [Documentation] ... 日志列表查询 ... params字典列表 ... 注意如下字典字段格式 ... orderBy=field名字1|true,field名字2|false ... fields=name1|type,name2|type ... 当path为batch时,fields=name1|type|lang1,name2|type|lang2 ... conditions=field1|type|symbol|value1^value2,field2|type|symbol|value3^value4 ... value1^value2是使用^分隔的字符串解析后为[value1,value2]格式的数组 [Arguments] ${params} ${path} Should Not Be Empty ${params} ${return} ${pageSize} Run Keyword And Ignore Error Get From Dictionary ${params} pageSize Run Keyword If "${return}"=="PASS" and "${pageSize}"=="${EMPTY}" Remove From Dictionary ${params} pageSize Run Keyword If "${path}"=="batch" Remove From Dictionary ${params} pageSize ${return} ${pageNo} Run Keyword And Ignore Error Get From Dictionary ${params} pageNo Run Keyword If "${return}"=="PASS" and "${pageNo}"=="${EMPTY}" Remove From Dictionary ${params} pageNo Run Keyword If "${path}"=="batch" Remove From Dictionary ${params} pageNo Dictionary Should Contain Key ${params} logType ${logType} Get From Dictionary ${params} logType #处理排序 ${return} ${orderBy} Run Keyword And Ignore Error Get From Dictionary ${params} orderBy ${orderBy} Run Keyword If "${return}"=="FAIL" or "${orderBy}"=="${EMPTY}" Create List ... ELSE IF "${path}"=="list" or "${path}"=="batch" ManageOrderBy ${orderBy} ... ELSE IF "${path}"=="count" Set Variable ${orderBy} Run Keyword If "${path}"=="list" or "${path}"=="batch" Set To Dictionary ${params} orderBy=${orderBy} Run Keyword If "${path}"=="count" Remove From Dictionary ${params} orderBy ${return} ${fields} Run Keyword And Ignore Error Get From Dictionary ${params} fields ${fields} Run Keyword If "${return}"=="FAIL" Set Variable ${EMPTY} ... ELSE Set Variable ${fields} Run Keyword If "${path}"=="list" Should Not Be Empty ${fields} ${fields} Run Keyword If "${path}"=="list" or "${path}"=="batch" ManageFields ${fields} ... ELSE Create List Run Keyword If "${path}"=="list" or "${path}"=="batch" Set To Dictionary ${params} fields=${fields} Run Keyword If "${path}"=="count" Remove From Dictionary ${params} fields ${start_common_recv_time} Get From Dictionary ${params} start_common_recv_time Should Not Be Empty ${start_common_recv_time} ${end_common_recv_time} Get From Dictionary ${params} end_common_recv_time Should Not Be Empty ${end_common_recv_time} ${return} ${userTags} Run Keyword And Ignore Error Get From Dictionary ${params} userTags Run Keyword If "${return}"=="PASS" and "${userTags}"=="${EMPTY}" Remove From Dictionary ${params} userTags ${return} ${conditions} Run Keyword And Ignore Error Get From Dictionary ${params} conditions ${conditions} Run Keyword If "${return}"=="PASS" and "${conditions}"!="${EMPTY}" ManageConditions ${conditions} ... ELSE Create List Set To Dictionary ${params} conditions=${conditions} ${bodyJson} json.Dumps ${params} ensure_ascii=False ${response} Run Keyword If "${path}"!="batch" BasePostRequestForV2 ${logUrl}/${path} ${bodyJson} ${version} ... ELSE BasePostRequestReturnBinary ${logUrl}/${path} ${bodyJson} ${version} Run Keyword If "${path}"!="batch" Should Be Equal As Integers ${response['code']} 200 ${time} Get Current Date result_format=datetime exclude_millis=True ${resData} Run Keyword If "${path}"!="batch" Set Variable ${response['data']} ... ELSE WriteExcel downloads ${logType}${time.year}${time.month}${time.day}${time.hour}${time.minute}${time.second}.xlsx ${response} [Return] ${resData} ManageOrderBy [Documentation] ... 处理 order by [Arguments] ${orderBy} ${orderByList} Create List @{orderByArr} Split String ${orderBy} ${arraySplitor} FOR ${order} IN @{orderByArr} @{orderByArr} Split String ${order} ${itemSplitor} ${dict} Create Dictionary field=${orderByArr}[0] asc=${orderByArr}[1] Append To List ${orderByList} ${dict} END [Return] ${orderByList} ManageFields [Documentation] ... 处理fields [Arguments] ${fields} ${fieldsList} Create List @{fieldsArr} Split String ${fields} ${arraySplitor} FOR ${field} IN @{fieldsArr} @{fieldArr} Split String ${field} ${itemSplitor} ${dict} Create Dictionary name=${fieldArr}[0] type=${fieldArr}[1] ${len} Get Length ${fieldArr} # batch时有lang字段 Run Keyword If ${len}==3 Set To Dictionary ${dict} lang=${fieldArr}[2] Append To List ${fieldsList} ${dict} END [Return] ${fieldsList} ManageConditions [Documentation] ... 处理conditions [Arguments] ${conditions} ${conditionsList} Create List @{conditionsArr} Split String ${conditions} ${arraySplitor} FOR ${condition} IN @{conditionsArr} @{conditionArr} Split String ${condition} ${itemSplitor} @{value} Split String ${conditionArr}[3] ${valueSplitor} ${type} Set Variable ${conditionArr}[1] ${value} Run Keyword If "${type}"=="int" or "${type}"=="long" toDigitList ${value} ${type} ... ELSE Set Variable ${value} ${dict} Create Dictionary field=${conditionArr}[0] type=${type} symbol=${conditionArr}[2] value=${value} Append To List ${conditionsList} ${dict} END [Return] ${conditionsList} toDigitList [Documentation] ... 转换为int 或者long型的list [Arguments] ${values} ${type} ${list} Create List FOR ${var} IN @{values} #wx-fix python3中没有long类型,整形只有int类型,可以当做long类型使用 ${var} Evaluate int('${var}') Append To List ${list} ${var} END [Return] ${list} WriteExcel [Documentation] ... 二进制文件导出为Excel [Arguments] ${filePath} ${fileName} ${content} Create Binary File ${path}/${filePath}/${fileName} ${content} [Return] ${path}/${filePath}/${fileName}