zoukankan      html  css  js  c++  java
  • Moqui学习之代码分析mantle priceServices.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    This software is in the public domain under CC0 1.0 Universal plus a 
    Grant of Patent License.
    
    To the extent possible under law, the author(s) have dedicated all
    copyright and related and neighboring rights to this software to the
    public domain worldwide. This software is distributed without any
    warranty.
    
    You should have received a copy of the CC0 Public Domain Dedication
    along with this software (see the LICENSE.md file). If not, see
    <http://creativecommons.org/publicdomain/zero/1.0/>.
    -->
    <services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-definition-1.6.xsd">
        <!--从这里可以得知该方法名称为getProductPrice-->
        <service verb="get" noun="ProductPrice" authenticate="anonymous-view">
            <description>Use the ProductPrice entity to determine the price to charge or pay for a Product.</description>
            <in-parameters>
    <!--这是一些输入参数所对应的 required若为true则表示为必须的参数 type表示输入的字段的数据类型 default为默认值-->
    <parameter name="productId" required="true"/> <parameter name="quantity" type="BigDecimal" default="1"/> <parameter name="priceUomId" default-value="USD"/> <parameter name="pricePurposeEnumId" default-value="PppPurchase"/> <parameter name="productStoreId"/> <parameter name="vendorPartyId"/> <parameter name="customerPartyId"/> <!-- TODO: to support look for records with this first and then with null: <parameter name="agreementId"/> --> <!-- TODO: to support look for records with this first and then with null: <parameter name="agreementItemSeqId"/> --> </in-parameters> <out-parameters>
    <!--这是输出参数 type表示输出参数的数据类型 -->
    <parameter name="price" type="BigDecimal"/> <parameter name="listPrice" type="BigDecimal"/> <parameter name="priceUomId"/> </out-parameters> <actions> <!-- get PptCurrent price --> <!-- try most constrained, back off from there -->
    <!--根据条件进行查询 其中service-call标签表示的是要调用的方法 in-map表示传入的参数 -->
    <if condition="productStoreId &amp;&amp; vendorPartyId &amp;&amp; customerPartyId"> <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context" in-map="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity, priceTypeEnumId:'PptCurrent', productStoreId:productStoreId, vendorPartyId:vendorPartyId, customerPartyId:customerPartyId]"/> </if> <!-- try just vendor and customer --> <if condition="!productPrice &amp;&amp; vendorPartyId &amp;&amp; customerPartyId"> <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context" in-map="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity, priceTypeEnumId:'PptCurrent', vendorPartyId:vendorPartyId, customerPartyId:customerPartyId]"/> </if> <!-- try just customer and store --> <if condition="!productPrice &amp;&amp; productStoreId &amp;&amp; customerPartyId"> <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context" in-map="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity,
    priceTypeEnumId:'PptCurrent', productStoreId:productStoreId, customerPartyId:customerPartyId]"
    />
    </if>
    <!-- try just store -->
    <if condition="!productPrice &amp;&amp; productStoreId">
    <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context"
    in-map
    ="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity,
    priceTypeEnumId:'PptCurrent', productStoreId:productStoreId]"
    />
    </if>
    <!-- try just vendor -->
    <if condition="!productPrice &amp;&amp; vendorPartyId">
    <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context"
    in-map
    ="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity,
    priceTypeEnumId:'PptCurrent', vendorPartyId:vendorPartyId]"
    />
    </if>
    <set field="price" from="productPrice?.price"/>
    <!-- get PptList price -->
    <set field="productPrice" from="null"/>
    <!-- try most constrained, back off from there -->
    <if condition="productStoreId &amp;&amp; vendorPartyId &amp;&amp; customerPartyId">
    <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context"
    in-map
    ="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity,
    priceTypeEnumId:'PptList', productStoreId:productStoreId, vendorPartyId:vendorPartyId, customerPartyId:customerPartyId]"
    />
    </if>
    <!-- try just vendor and customer -->
    <if condition="!productPrice &amp;&amp; vendorPartyId &amp;&amp; customerPartyId">
    <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context"
    in-map
    ="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity,
    priceTypeEnumId:'PptList', vendorPartyId:vendorPartyId, customerPartyId:customerPartyId]"
    />
    </if>
    <!-- try just customer and store -->
    <if condition="!productPrice &amp;&amp; productStoreId &amp;&amp; customerPartyId">
    <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context"
    in-map
    ="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity,
    priceTypeEnumId:'PptList', productStoreId:productStoreId, customerPartyId:customerPartyId]"
    />
    </if>
    <!-- try just store -->
    <if condition="!productPrice &amp;&amp; productStoreId">
    <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context"
    in-map
    ="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity,
    priceTypeEnumId:'PptList', productStoreId:productStoreId]"
    />
    </if>
    <!-- try just vendor -->
    <if condition="!productPrice &amp;&amp; vendorPartyId">
    <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context"
    in-map
    ="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity,
    priceTypeEnumId:'PptList', vendorPartyId:vendorPartyId]"
    />
    </if>
    <!--设置输出参数的显示-->
    <set field="listPrice" from="productPrice?.price"/>
    <set field="price" from="price ?: listPrice ?: 0"/>
    <!-- <log level="warn" message="========== BEFORE rules productId=${productId}, price=${price}, listPrice=${listPrice}"/> -->
    <!-- run the ProductPriceKS knowledge session rules -->
    <script>ec.getStatelessKieSession("ProductPriceKS").execute([])</script>
    <!-- <log level="warn" message="========== AFTER rules productId=${productId}, price=${price}, listPrice=${listPrice}"/> -->
    </actions>
    </service>
    <service verb="find" noun="ProductPriceRecord">
    <description>This is an internal service called by get#ProductPrice.</description>
    <in-parameters>
    <parameter name="productId" required="true"/>
    <parameter name="priceUomId" required="true"/>
    <parameter name="pricePurposeEnumId" required="true"/>
    <parameter name="priceTypeEnumId" required="true"/>
    <parameter name="quantity" type="BigDecimal" required="true"/>
    <parameter name="productStoreId"/>
    <parameter name="vendorPartyId"/>
    <parameter name="customerPartyId"/>
    </in-parameters>
    <out-parameters><parameter name="productPrice" type="EntityValue"/>
    </
    out-parameters>
    <actions>
    <!-- <log level="warn" message="finding price record with context: ${context}"/> -->
    <entity-find entity-name="mantle.product.ProductPrice" list="productPriceList" cache="true">
    <econdition-object field="[productId:productId, priceUomId:priceUomId,
    pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId]"
    />
    <econdition field-name="minQuantity" operator="less-equals" from="quantity"/>
    <econdition field-name="productStoreId" ignore-if-empty="true"/>
    <econdition field-name="vendorPartyId" ignore-if-empty="true"/>
    <econdition field-name="customerPartyId" ignore-if-empty="true"/>
    <order-by field-name="-fromDate"/>
    <!-- get most recent price records first -->
    <order-by field-name="-minQuantity"/>
    <!-- get highest qualifying (<=quantity) minQuantity records first -->
    </entity-find>
    <!-- <log level="warn" message="CALC productPriceList: ${productPriceList}"/> -->
    <filter-map-list list="productPriceList"><date-filter/></filter-map-list>
    <set field="productPrice" from="productPriceList?.first"/>
    </actions>
    </service>
    </
    services>


    这是刚开始时进入的界面,从这里可以看出他所需要的输入参数和输出参数:

     1 <in-parameters>
     2             <parameter name="productId" required="true"/>
     3             <parameter name="quantity" type="BigDecimal" default="1"/>
     4 
     5             <parameter name="priceUomId" default-value="USD"/>
     6             <parameter name="pricePurposeEnumId" default-value="PppPurchase"/>
     7 
     8             <parameter name="productStoreId"/>
     9             <parameter name="vendorPartyId"/>
    10             <parameter name="customerPartyId"/>
    11 
    12             <!-- TODO: to support look for records with this first and then with null: <parameter name="agreementId"/> -->
    13             <!-- TODO: to support look for records with this first and then with null: <parameter name="agreementItemSeqId"/> -->
    14         </in-parameters>

    这是定义输入参数的代码,与页面对应。

    1 <out-parameters>
    2             <parameter name="price" type="BigDecimal"/>
    3             <parameter name="listPrice" type="BigDecimal"/>
    4             <parameter name="priceUomId"/>
    5         </out-parameters>

    这是定义输出参数的代码,与页面对应。

    从actions中的代码可以看出他是调用的另一个service的方法:即mantle.product.PriceServices,find#ProductPriceRecord方法。

     <!-- get PptCurrent price -->
                <!-- try most constrained, back off from there -->
                <if condition="productStoreId &amp;&amp; vendorPartyId &amp;&amp; customerPartyId">
                    <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context"
                            in-map="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity,
                                priceTypeEnumId:'PptCurrent', productStoreId:productStoreId, vendorPartyId:vendorPartyId, customerPartyId:customerPartyId]"/>
                </if>

    下面就来看这个service方法的定义:

     <service verb="find" noun="ProductPriceRecord">
            <description>This is an internal service called by get#ProductPrice.</description>
            <in-parameters>
                <parameter name="productId" required="true"/>
                <parameter name="priceUomId" required="true"/>
                <parameter name="pricePurposeEnumId" required="true"/>
                <parameter name="priceTypeEnumId" required="true"/>
                <parameter name="quantity" type="BigDecimal" required="true"/>
                <parameter name="productStoreId"/>
                <parameter name="vendorPartyId"/>
                <parameter name="customerPartyId"/>
            </in-parameters>
            <out-parameters><parameter name="productPrice" type="EntityValue"/></out-parameters>
    </service>

    从这里可以看出该方法的输入参数和输出参数,它执行时所需要的参数是通过上一个方法传入的,具体是:

    1 <if condition="productStoreId &amp;&amp; vendorPartyId &amp;&amp; customerPartyId">
    2                 <service-call name="mantle.product.PriceServices.find#ProductPriceRecord" out-map="context"
    3                         in-map="[productId:productId, priceUomId:priceUomId, pricePurposeEnumId:pricePurposeEnumId, priceTypeEnumId:priceTypeEnumId, quantity:quantity,
    4                             priceTypeEnumId:'PptCurrent', productStoreId:productStoreId, vendorPartyId:vendorPartyId, customerPartyId:customerPartyId]"/>
    5             </if>

    通过service-call标签中的in-map元素来实现的。

  • 相关阅读:
    SpringBoot(十):SpringBoot的简单事务管理
    SpringBoot(九):SpringBoot集成Mybatis
    独立式智能扫码插座
    STC-51开发板-单片机控制数码管&按键&点阵综合操作
    单片机定时器与数码管静态显示
    半导体器件
    电路模型与规律
    单片机-引脚并行口结构讲解
    单片机-基础知识,存储原理,引脚简介———(第一个小程序)
    C语言-综合知识点
  • 原文地址:https://www.cnblogs.com/dream-to-pku/p/5472924.html
Copyright © 2011-2022 走看看