首页 > 解决方案 > 将 OData 结果传输到销售订单模拟实体时,销售订单模拟实体中缺少导航值 to_ScheduleLine

问题描述

我正在使用 SAP Cloud SDK 调用 OData 服务 API_SALES_ORDER_SIMULATION_SRV 来进行销售订单模拟。

我使用的有效载荷如下:

{
    "SalesOrderType"            : "**",
    "SalesOrganization"         : "**",
    "DistributionChannel"       : "01",
    "OrganizationDivision"      : "01",
    "SoldToParty"               : "1000",
    "TransactionCurrency"       : "EUR",
    "PurchaseOrderByCustomer"   : "E2E S4HANA",
    "to_Item":[
        { "SalesOrderItem" : "10",
          "Material"       : "**",
          "RequestedQuantity"  : "1000",
          "to_ScheduleLine"    : []
        }
    ]
}

我从 S/4HANA 得到的回复。

{
    "d": {
        "__metadata": {
            "id": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderSimulation('')",
            "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderSimulation('')",
            "type": "API_SALES_ORDER_SIMULATION_SRV.A_SalesOrderSimulationType"
        },
        "SalesOrder": "",
        "SalesOrderType": "YTA",
        "SalesOrganization": "***",
        "DistributionChannel": "01",
        "OrganizationDivision": "01",
        "SalesGroup": "",
        "SalesOffice": "",
        "SalesDistrict": "000002",
        "SoldToParty": "***",
        "PurchaseOrderByCustomer": "E2E S4HANA",
        "CustomerPurchaseOrderType": "",
        "CustomerPurchaseOrderDate": null,
        "SalesOrderDate": "/Date(1571875200000)/",
        "TransactionCurrency": "EUR",
        "SDDocumentReason": "",
        "PricingDate": "/Date(1571875200000)/",
        "RequestedDeliveryDate": "/Date(1571875200000)/",
        "ShippingCondition": "",
        "CompleteDeliveryIsDefined": false,
        "ShippingType": "",
        "IncotermsClassification": "***",
        "IncotermsTransferLocation": "***",
        "IncotermsLocation1": "***",
        "IncotermsLocation2": "",
        "IncotermsVersion": "",
        "CustomerPaymentTerms": "0001",
        "PaymentMethod": "",
        "to_Credit": {
            "__deferred": {
                "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderSimulation('')/to_Credit"
            }
        },
        "to_Item": {
            "results": [
                {
                    "__metadata": {
                        "id": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderItemSimulation(SalesOrder='',SalesOrderItem='10')",
                        "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderItemSimulation(SalesOrder='',SalesOrderItem='10')",
                        "type": "API_SALES_ORDER_SIMULATION_SRV.A_SalesOrderItemSimulationType"
                    },
                    "SalesOrder": "",
                    "SalesOrderItem": "10",
                    "HigherLevelItem": "0",
                    "SalesOrderItemCategory": "***",
                    "SalesOrderItemText": "***",
                    "PurchaseOrderByCustomer": "E2E S4HANA",
                    "Material": "***",
                    "MaterialByCustomer": "***",
                    "PricingDate": "/Date(1571875200000)/",
                    "RequestedQuantity": "10000000",
                    "RequestedQuantityUnit": "PC",
                    "TransactionCurrency": "EUR",
                    "NetAmount": "0.00",
                    "TaxAmount": "0.00",
                    "CostAmount": "0.00",
                    "Subtotal1Amount": "0.00",
                    "Subtotal2Amount": "0.00",
                    "Subtotal3Amount": "0.00",
                    "Subtotal4Amount": "0.00",
                    "Subtotal5Amount": "0.00",
                    "Subtotal6Amount": "0.00",
                    "MaterialGroup": "01",
                    "MaterialPricingGroup": "",
                    "Batch": "",
                    "Plant": "***",
                    "StorageLocation": "",
                    "DeliveryGroup": "0",
                    "ShippingPoint": "***",
                    "ShippingType": "",
                    "DeliveryPriority": "0",
                    "IncotermsClassification": "***",
                    "IncotermsTransferLocation": "***",
                    "IncotermsLocation1": "***",
                    "IncotermsLocation2": "",
                    "CustomerPaymentTerms": "0001",
                    "SalesDocumentRjcnReason": "",
                    "to_Partner": {
                        "__deferred": {
                            "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderItemSimulation(SalesOrder='',SalesOrderItem='10')/to_Partner"
                        }
                    },
                    "to_PricingElement": {
                        "__deferred": {
                            "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderItemSimulation(SalesOrder='',SalesOrderItem='10')/to_PricingElement"
                        }
                    },
                    "to_SalesOrder": {
                        "__deferred": {
                            "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderItemSimulation(SalesOrder='',SalesOrderItem='10')/to_SalesOrder"
                        }
                    },
                    "to_ScheduleLine": {
                        "results": [
                            {
                                "__metadata": {
                                    "id": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderScheduleLineSimln(SalesOrder='',SalesOrderItem='10',ScheduleLine='1')",
                                    "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderScheduleLineSimln(SalesOrder='',SalesOrderItem='10',ScheduleLine='1')",
                                    "type": "API_SALES_ORDER_SIMULATION_SRV.A_SalesOrderScheduleLineSimlnType"
                                },
                                "SalesOrder": "",
                                "SalesOrderItem": "10",
                                "ScheduleLine": "1",
                                "RequestedDeliveryDate": "/Date(1571875200000)/",
                                "ConfirmedDeliveryDate": null,
                                "OrderQuantityUnit": "PC",
                                "ScheduleLineOrderQuantity": "10000000",
                                "ConfdOrderQtyByMatlAvailCheck": "0",
                                "OpenConfdDelivQtyInOrdQtyUnit": "0",
                                "CorrectedQtyInOrderQtyUnit": "10000000",
                                "to_SalesOrder": {
                                    "__deferred": {
                                        "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderScheduleLineSimln(SalesOrder='',SalesOrderItem='10',ScheduleLine='1')/to_SalesOrder"
                                    }
                                },
                                "to_SalesOrderItem": {
                                    "__deferred": {
                                        "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderScheduleLineSimln(SalesOrder='',SalesOrderItem='10',ScheduleLine='1')/to_SalesOrderItem"
                                    }
                                }
                            },
                            {
                                "__metadata": {
                                    "id": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderScheduleLineSimln(SalesOrder='',SalesOrderItem='10',ScheduleLine='2')",
                                    "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderScheduleLineSimln(SalesOrder='',SalesOrderItem='10',ScheduleLine='2')",
                                    "type": "API_SALES_ORDER_SIMULATION_SRV.A_SalesOrderScheduleLineSimlnType"
                                },
                                "SalesOrder": "",
                                "SalesOrderItem": "10",
                                "ScheduleLine": "2",
                                "RequestedDeliveryDate": null,
                                "ConfirmedDeliveryDate": "/Date(1571961600000)/",
                                "OrderQuantityUnit": "PC",
                                "ScheduleLineOrderQuantity": "0",
                                "ConfdOrderQtyByMatlAvailCheck": "18595.5",
                                "OpenConfdDelivQtyInOrdQtyUnit": "0",
                                "CorrectedQtyInOrderQtyUnit": "0",
                                "to_SalesOrder": {
                                    "__deferred": {
                                        "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderScheduleLineSimln(SalesOrder='',SalesOrderItem='10',ScheduleLine='2')/to_SalesOrder"
                                    }
                                },
                                "to_SalesOrderItem": {
                                    "__deferred": {
                                        "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderScheduleLineSimln(SalesOrder='',SalesOrderItem='10',ScheduleLine='2')/to_SalesOrderItem"
                                    }
                                }
                            }
                        ]
                    }
                }
            ]
        },
        "to_Partner": {
            "__deferred": {
                "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderSimulation('')/to_Partner"
            }
        },
        "to_Pricing": {
            "__deferred": {
                "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderSimulation('')/to_Pricing"
            }
        },
        "to_PricingElement": {
            "__deferred": {
                "uri": "http://host:port/sap/opu/odata/sap/API_SALES_ORDER_SIMULATION_SRV/A_SalesOrderSimulation('')/to_PricingElement"
            }
        }
    }
}

它在 SAP Gateway Client 中运行良好,它返回我想要的所有数据,包括项目中的 to_ScheduleLine 导航数据。

但是当我使用 Cloud SDK 调用 API 并设置相同的有效负载时,返回的销售订单模拟数据没有 to_ScheduleLine 导航数据。

我深入查看了SDK的源码,发现响应中包含了这部分数据。但是在将odata结果传输到销售订单模拟实体时,数据会丢失。

OData 响应

使用类 FluentHelperCreate.class 中的属性构造 EntityT 时,计划行属性会丢失。

@Override
@Nonnull
public EntityT execute( @Nonnull final HttpDestinationProperties destination )
    throws ODataException
{
    final HttpClient httpClient = HttpClientAccessor.getHttpClient(destination);
    notifyQueryListeners(destination, getEntity());
    final ODataCreateResult result = toQuery().execute(httpClient);

    final EntityT createdEntity = new VdmEntityUtil<>(getEntityClass()).fromFields(result.asMap());
    createdEntity.attachToService(getServicePath(), destination);
    return createdEntity;
}

to_ScheduleLine 数据对我们的业务工作流程非常重要。因为客户在模拟销售订单并提供item的RequestedQuantity时,需要知道存储是否足够。

你能帮忙看看这个问题吗?

SAP Cloud SDK 版本:3.3.1 S/4HANA 本地版本:1909

==================================================== ============================

更新

根项目中的 pom.xml

<?xml version='1.0' encoding='utf-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <name>Test3.11 - Root</name>
    <description>Test3.11 - Root</description>

    <groupId>com.bosch.test</groupId>
    <artifactId>Test3.11</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <spring-boot.version>2.2.1.RELEASE</spring-boot.version>

        <java.version>1.8</java.version>

        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <maven.compiler.testSource>${java.version}</maven.compiler.testSource>
        <maven.compiler.testTarget>${java.version}</maven.compiler.testTarget>

        <project.build.resourceEncoding>UTF-8</project.build.resourceEncoding>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.sap.cloud.sdk</groupId>
                <artifactId>sdk-bom</artifactId>
                <version>3.13.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>javax.validation</groupId>
                <artifactId>validation-api</artifactId>
                <version>2.0.1.Final</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <modules>
        <module>application</module>
        <module>unit-tests</module>
        <module>integration-tests</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>3.0.0-M2</version>
                <executions>
                    <execution>
                        <id>SAP Cloud SDK Project Structure Checks</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <version>3.5</version>
                                </requireMavenVersion>
                                <requireJavaVersion>
                                    <version>${java.version}</version>
                                </requireJavaVersion>
                                <requireProperty>
                                    <property>project.artifactId</property>
                                    <regex>[^_]+</regex>
                                    <regexMessage>"The artifactId should not contain underscores (_) as this causes issues when deploying to Cloud Foundry."</regexMessage>
                                </requireProperty>
                                <reactorModuleConvergence />
                            </rules>
                            <fail>true</fail>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

应用程序项目中的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <name>Test3.11 - Application</name>
    <description>Test3.11 - Application</description>

    <artifactId>Test3.11-application</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>com.bosch.test</groupId>
        <artifactId>Test3.11</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <dependencies>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- mybatis  -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <!--<version>42.2.8</version>-->
        </dependency>

        <dependency>
            <groupId>com.sap.xs2.security</groupId>
            <artifactId>security-commons</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sap.xs2.security</groupId>
            <artifactId>java-container-security</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sap.xs2.security</groupId>
            <artifactId>java-container-security-api</artifactId>
            <version>0.28.6</version>
        </dependency>
        <dependency>
            <groupId>com.sap.security.nw.sso.linuxx86_64.opt</groupId>
            <artifactId>sapjwt.linuxx86_64</artifactId>
            <version>1.1.19</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-jwt</artifactId>
            <version>1.0.10.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sap.cloud.security.xsuaa</groupId>
            <artifactId>api</artifactId>
            <version>2.2.0</version>
        </dependency>

        <dependency>
            <groupId>com.github.ben-manes.caffeine</groupId>
            <artifactId>jcache</artifactId>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.sap.cloud.sdk.cloudplatform</groupId>
            <artifactId>scp-cf</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sap.cloud.sdk.s4hana</groupId>
            <artifactId>s4hana-all</artifactId>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sap.hcp.cf.logging</groupId>
            <artifactId>cf-java-logging-support-logback</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--
        Since com.sap.xs2.security:java-container-security is not available in Maven Central as of today,
        you need to download this dependency manually.

        The library is available for download at:
        https://launchpad.support.sap.com/#/softwarecenter/search/XS_JAVA
        -->

        <!-- Dependencies for security setup -->
        <!--
        <dependency>
            <groupId>com.sap.xs2.security</groupId>
            <artifactId>java-container-security</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.unboundid.components</groupId>
                    <artifactId>json</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
        </dependency>
        -->

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
                <configuration>
                    <attach>false</attach>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.sap.cloud.sdk.plugins</groupId>
                <artifactId>usage-analytics-maven-plugin</artifactId>
                <version>3.13.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>usage-analytics</goal>
                        </goals>
                        <configuration>
                            <skipUsageAnalytics>false</skipUsageAnalytics>
                            <generateSalt>true</generateSalt>
                            <!--
                            Note: A random salt is auto-generated once the project is built for the first time.
                            Please keep the generated salt in the POM file, for example, when pushing to git.

                            To learn more, visit: https://blogs.sap.com/2018/10/23/usage-analytics-s4sdk/
                            -->
                            <salt>438271d5d965d55c65e6913db160e0f9b6001952410dcb2f8e3d6956cbf14112</salt>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

谢谢,

杰瑞

标签: sap-cloud-sdk

解决方案


请更新到3.14.0SAP Cloud SDK的版本。


为了重现这个问题,我将评论中描述的我之前的测试结果与来自 Wiremock 测试和版本3.13.0(以及更早版本)的结果进行了比较。事实证明,您所描述的问题在一次迭代后得到了修复。它被固定在3.14.0.


推荐阅读