零碎知识 将筛选条件遍历一次,并找出查无结果的记录

大海 · 2020年07月24日 · 1130 次阅读
背景要求

需要把筛选查询的条件,遍历一遍,看是否都能有结果,如果没有结果的话,找出来,然后去 ES 库里看是不是库里也没有这个数据,确认是筛选条件的问题还是数据的问题。

/qcc/kzz/company/searchKzzV2

/qcc/kzz/company/advancedSearchV2

UI 界面图


#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File    : demo.py
@Time    : 2020/07/16
@Author  : XXX
@Email   : XXX@XXX.com
"""


import json
import requests



s=["T","MN","E","YR","B","GT","A","N_A","CR","RE","IM","FIV","SMV","TF","TE","NJX","CI","F","K","LP","BL","LT","IVM","BM","XZXK","EP","YZWF","GQZY","AOP","ENP","TAB","SFPW","XJPG","PCCZ","TDDY","GSCG","QSGG","ZX","S","EC","XG","CPWS","FYGG","KTGG","GQDJ","LA","ZS","C","SC","TELB","APP","WP","WB","GZH","LIC","GW","P","M","N_T","N_MN","N_E","N_YR","N_B","N_GT","N_NT","N_CR","N_RE","N_IM","N_FIV","N_SMV","N_TF","N_TE","N_NJX","N_CI","N_F","N_K","N_LP","N_BL","N_LT","N_IVM","N_BM","N_XZXK","N_EP","N_YZWF","N_GQZY","N_AOP","N_ENP","N_TAB","N_SFPW","N_XJPG","N_PCCZ","N_TDDY","N_GSCG","N_QSGG","N_ZX","N_S","N_EC","N_XG","N_CPWS","N_FYGG","N_KTGG","N_GQDJ","N_LA","N_ZS","N_C","N_SC","N_TELB","N_APP","N_WP","N_WB","N_GZH","N_LIC","N_GW","N_P","N_M"]

simple_data={
    "pageSize": 100,
    "pageIndex": 1,
    "includeFields": ["id","name"],
    "filter": {
        "flag": [""]
},
    "searchKey": "公司",
    "searchIndex": ["name","product","scope","trademark","patent","tender","website","position","address"]
}

advacned_data = {
     "pageSize": 100,
     "pageIndex": 1,
     "searchObject": {
          "logic": "any",
          "children": [
               {
                    "type": "rule",
                    "searchRule": {
                         "field": "flag",
                         "value": "RE",
                         "operator": "contain"
                    }
               },
               {
                    "type": "rule",
                    "searchRule": {
                         "field": "name",
                         "value": "合伙",
                         "operator": "contain"
                    }
               }
          ]
     }
}


def check_simpleresult():
    """
    简单搜索中,遍历有无XX条件
    :return:
    """
    cookies = {}
    cookies['QCCSESSID'] = 'nv76kstgn260vql5v6r2lgkba0'
    baseurl = "http://XXX.XXX.XXX.com/qcc/kzz/company/searchKzzV2"
    for i in s:
        simple_data["filter"]["flag"] = [i]
        print(simple_data["filter"]["flag"])
        res = requests.post(url=baseurl, json=simple_data, cookies=cookies)
        # JSON文件转为字典格式
        resp_data = json.loads(res.text)
        print(resp_data)
        new_data_value = json.dumps(resp_data, ensure_ascii=False)
        # 字典转为JSON格式,作为附件内容加入报告中
        number_value = json.loads(new_data_value, strict=False)["Paging"]["TotalRecords"]["value"]
        if number_value == 0:
            with open(r"D:\QCC_KzzApiAutomation\value等于0的返回值(公司).txt", "a") as f:
                f.write(''.join((str(resp_data), "\n")))
                f.write(''.join(str(simple_data["filter"]["flag"])))
        else:
            assert True



def check_advanvedresult():
    """
    高级搜素中遍历有无XX条件
    :return:
    """
    cookies = {}
    cookies['QCCSESSID'] = 'nv76kstgn260vql5v6r2lgkba0'
    baseurl = "http://XXX.XXX.XXX.com/qcc/kzz/company/advancedSearchV2"
    for i in s:
        advacned_data["searchObject"]["children"][0]["searchRule"]["value"] = i
        print(advacned_data["searchObject"]["children"][0]["searchRule"]["value"])
        res = requests.post(url=baseurl, json=advacned_data, cookies=cookies)
        # JSON文件转为字典格式
        resp_data = json.loads(res.text)
        print(resp_data)
        new_data_value = json.dumps(resp_data, ensure_ascii=False)
        # 字典转为JSON格式,作为附件内容加入报告中
        number_value = json.loads(new_data_value, strict=False)["Paging"]["TotalRecords"]["value"]
        if number_value == 0:
            with open(r"D:\QCC_KzzApiAutomation\高级搜索中value等于0的返回值(合伙).txt", "a") as f:
                f.write(''.join((str(resp_data), "\n")))
                f.write(''.join(str(advacned_data["searchObject"]["children"][0]["searchRule"]["value"])))
        else:
            assert True










if __name__ == '__main__':
    check_simpleresult()
    check_advanvedresult()


如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册