def getDetail(adhocOrderId):
    log.info('------小程序查询临调订单明细------')
    response = request.get_params('/adhocOrder/getDetail',
                                  params={'orderId': adhocOrderId})
    assert response['msg'] == '请求成功'
    log.info('------查询订单详情------')
    response2 = request.get_params('/adhocOrder/getDetailByOrderId',
                                   params={'orderId': adhocOrderId})
    assert response2['msg'] == '请求成功'
    def add_tools(self, templateIds, warehouseId):
        """

        :param templateIds:  工具包ID
        :param warehouseId: 仓库ID
        :return:
        """
        url = '/kitStock/findAvailableGoodsStockByTemplateId'
        params = {'templateIds': templateIds, 'warehouseId': warehouseId}
        response = request.get_params(url, params)
        try:
            assert response['msg'] == '请求成功'
        except Exception:
            raise response
        goodsList = []
        goodsLotInfoIdList = []
        goodsQuantityList = []
        for i in response['data']:
            for j in i['defaultGoods']:
                goodsList.append(j['goodsId'])
                goodsLotInfoIdList.append(j['goodsLotInfoId'])
                goodsQuantityList.append(j['templateQuantity'])
            # print(goodsLotInfoIdList)
        kitTemplateId = response['data'][0]['id']
        kitTemplateName = response['data'][0]['templateName']
        # print(kitTemplateName)
        return kitTemplateId, kitTemplateName, warehouseId, goodsList, goodsLotInfoIdList, goodsQuantityList
 def get_packagingOrderList(self):
     url = '/packagingOrder/list'
     params = {
         'pageNum': 0,
         'pageSize': 50,
     }
     response = request.get_params(url, params)
     try:
         assert response['msg'] == '请求成功'
     except Exception:
         raise response
 def get_toolsKitCategoryId(self):
     url = '/category/getTree'
     params = {'pageNum': 0, 'pageSize': 50, 'parentCode': 'TOOLS_MATERIAL'}
     response = request.get_params(url, params)
     try:
         assert response['msg'] == '请求成功'
     except Exception:
         raise response
     # 获取工具包类别 id
     toolsKitCategory = response['data']['childCategory'][0]['id']
     return toolsKitCategory
 def get_ToolsList(self):
     url = '/goods/queryToolsList'
     params = {'pageNum': 0, 'pageSize': 50}
     response = request.get_params(url, params)
     try:
         assert response['msg'] == '请求成功'
     except Exception:
         raise response
     # 获取工具包模版 id
     id = response['data']['rows'][0]['id']
     return id
class TestPackagingOrder:
    templateIds = None
    warehouseId = None

    @pytest.fixture(scope="module")
    def get_allMsg(self):
        warehouseId = Material_Management.PackagingOrder().get_warehouse()
        templateIds = Material_Management.PackagingOrder(
        ).get_packagingFindTools(warehouseId)
        yield templateIds, warehouseId

    @pytest.fixture(scope="module")
    def get_toolsInfo(self, get_allMsg):
        response = Material_Management.PackagingOrder().add_tools(
            get_allMsg[0], get_allMsg[1])
        # kitTemplateId, kitTemplateName, warehouseId, goodsList, goodsLotInfoIdList, goodsQuantityList
        yield response

    data = [('正向流程', {
        'templateIds': 'templateIds',
        'warehouseId': 'warehouseId'
    }, '请求成功'),
            ('仓库未选择', {
                'templateIds': 'templateIds',
                'warehouseId': None
            }, '参数异常,请刷新后重试'),
            (
                '工具包未选择',
                {
                    'templateIds': None,
                    'warehouseId': 'warehouseId'
                },
                '请选择工具包',
            )]

    # ids = ['正向流程',
    #        '仓库未选择',
    #        '工具包未选择'
    #        ]
    @allure.story('添加工具')
    @allure.title('{title}')
    @pytest.mark.parametrize('title,case,expected', data)
    def test_add_tools(self, title, case, expected, get_allMsg):
        if case['templateIds'] == 'templateIds':
            case['templateIds'] = get_allMsg[0]
        if case['warehouseId'] == 'warehouseId':
            case['warehouseId'] = get_allMsg[1]
        url = '/kitStock/findAvailableGoodsStockByTemplateId'
        params = {
            'templateIds': case['templateIds'],
            'warehouseId': case['warehouseId']
        }
        response = request.get_params(url, params)
        assert response['msg'] == expected
 def get_packagingFindTools(self, warehouseId):
     url = '/kitTemplate/packagingFindToolsKitList'
     params = {'pageNum': 0, 'pageSize': 50, 'warehouseId': warehouseId}
     response = request.get_params(url, params)
     try:
         assert response['msg'] == '请求成功'
     except Exception:
         raise response
     for i in response['data']['rows']:
         if i['templateName'] == '钢板支架工具包':
             templateIds = i['id']
             return templateIds
 def get_kitStockId(self, sourceWarehouseId):
     url = '/kitStock/findKitStockListByAllocate'
     params = {
         'pageNum': 0,
         'pageSize': 50,
         'warehouseId': sourceWarehouseId
     }
     response = request.get_params(url, params)
     try:
         assert response['msg'] == '请求成功'
     except Exception:
         raise response
     kitStockId = response['data']['rows'][0]['id']
     return kitStockId
 def get_goodsInfo(self, sourceWarehouseId):
     url = '/goodsStock/findAllocateGoodsStockList'
     params = {
         'pageNum': 0,
         'pageSize': 50,
         'warehouseId': sourceWarehouseId
     }
     response = request.get_params(url, params)
     try:
         assert response['msg'] == '请求成功'
     except Exception:
         raise response
     goodsId = response['data']['rows'][0]['goodsId']
     goodsLotInfoId = response['data']['rows'][0]['goodsLotInfoId']
     return goodsId, goodsLotInfoId
    def get_KitTemplateList(self, toolKitName):
        """

        :param toolKitName: 工具包名称
        :return:
        """
        url = '/kitTemplate/queryToolsKitList'
        params = {'pageNum': 0, 'pageSize': 50, 'toolKitName': toolKitName}
        response = request.get_params(url, params)
        try:
            assert response['msg'] == '请求成功'
        except Exception:
            raise response
        # 获取工具包 id
        id = response['data']['rows'][0]['id']
        return id
    def getList(self, webKeyword, Type='material'):
        """

        :param webKeyword: 关键字
        :param Type: 'material' : 物资 、'tool' : 工具
        :return:
        """
        url = '/goods/queryGoodsList'
        params = {
            'pageNum': 0,
            'pageSize': 50,
            'type': Type,
            'webKeyword': webKeyword
        }
        response = request.get_params(url, params)
        try:
            assert response['msg'] == '请求成功'
        except Exception:
            raise response
        # 获取物资 id
        id = response['data']['rows'][0]['id']
        return id
    def get_goodsCategory(self):
        url = '/category/getTree'
        if self.type == 'material':
            params = {
                'pageNum': 0,
                'pageSize': 50,
                'parentCode': 'MATERIAL'  # 工具是 TOOLS_MATERIAL
            }
        else:
            params = {
                'pageNum': 0,
                'pageSize': 50,
                'parentCode': 'TOOLS_MATERIAL'  # 工具是 TOOLS_MATERIAL
            }

        response = request.get_params(url, params)
        try:
            assert response['msg'] == '请求成功'
        except Exception:
            raise response
        # 获取物资类别 id
        goodsCategory = response['data']['childCategory'][0]['id']
        return goodsCategory