【问题标题】:How do you design a Pricing Integration for Hybris with SAP ERP for B2B application您如何为 Hybris 与 SAP ERP 为 B2B 应用程序设计定价集成
【发布时间】:2017-05-22 13:30:25
【问题描述】:

如果 ERP 中有一个定价模块可以为每个用户实时计算价格,我们有什么方法可以在不权衡性能的情况下得到它?

【问题讨论】:

  • 我想说只是实现一些缓存以避免对您的 ERP 进行过多调用。

标签: hybris


【解决方案1】:

您可以维护缓存以避免多次调用 ERP 系统。

这是一个示例代码,您可以尝试实现缓存 --

CustomCache.java

public class CustomCache
{

    @Resource(name = customCacheRegion)
    protected CacheAccess customCacheAccess;

    //Fetch result from cache
    public ResultData readCachedData(final B2BUnitModel customer, final Date date)
    {
       return (ResultData) customCacheAccess.get(createCacheKey(customer, date));
    }

    //Update result to cache
    public void cacheResult(final B2BUnitModel customer, final Date date,
        final ResultData resultData)
    {

       try
       {
          customCacheAccess.put(createCacheKey(customer, date), resultData);

       }
       catch (final SAPHybrisCacheException e)
       {
        //error
       }
    }

    protected CustomCacheKey createCacheKey(final B2BUnitModel customer, final Date date)
    {
       return new CustomCacheKey(customer, date);
    }

}

缓存键 -

  public class CustomCacheKey extends AbstractCacheKey
  {
        private final B2BUnitModel customer;

        private final Date date; 

        @Override
        public int hashCode()
        {
            final int prime = 31;
            int result = super.hashCode();
            result = prime * result + ((customer == null) ? 0 : customer.hashCode());
            return result;
        }

        @Override
        public boolean equals(final Object obj)
        {
           if (obj == null)
           {
              return false;
           }

           if (!super.equals(obj))
           {
               return false;
           }

           final CustomCacheKey customCacheKey = (CustomCacheKey ) obj;
           if (customer == null)
           {
                if (customCacheKey.customer != null)
                {
                   return false;
                }
           }
           else if (!customer.equals(customCacheKey.customer))
           {
               return false;
           }

           if (date == null)
           {
               if (customCacheKey.date != null)
               {
                 return false;
           }
        }
        else if (!DateUtils.isSameDay(date, customCacheKey.date))
        {
           return false;
        }

        return true;
     }
}

*-spring.xml --

 <bean id="customCacheRegion" parent="sapCoreCacheRegion">
    <constructor-arg name="name"
        value="customCacheRegion" />
    <constructor-arg name="maxEntries" value="10000" />
    <constructor-arg name="evictionPolicy" value="FIFO" />
    <constructor-arg name="statsEnabled" value="true" />
    <constructor-arg name="exclusiveComputation" value="false" />
    <constructor-arg name="ttlSeconds" value="300" />
</bean>

<bean
    class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject" ref="cacheRegionsList" />
    <property name="targetMethod" value="add" />
    <property name="arguments">
        <ref bean="customCacheRegion" />
    </property>
</bean>

所以缓存是一种映射,你可以在其中定义键值对并从键本身获取缓存的值。

最后在您的服务层中,在调用 ERP 系统之前,只需检查特定客户(或您的情况下的某些其他条件)的数据是否在缓存中可用。如果可用,则直接从缓存中获取,否则调用 ERP 系统并将结果更新到缓存。

【讨论】:

  • 感谢 Shreshtt Bhatt。这对我很有帮助。
  • @racha11 如果可行,请您接受这个答案:)
  • 如果同一用户更改条目/产品,如何区分是返回最后缓存的价格还是调用 ERP?
  • @staticvoidmain 我们需要重写 equals() 方法以添加所有可能的唯一条件,以便如果任何条目/产品发生更改,equals() 方法只会返回 false 并且由于哪个键不会存在于缓存映射中,属于 ERP 调用。
猜你喜欢
  • 2017-03-31
  • 2017-05-17
  • 1970-01-01
  • 2011-07-17
  • 2011-02-12
  • 1970-01-01
  • 2020-11-09
  • 2021-04-30
  • 1970-01-01
相关资源
最近更新 更多