zc-111 发表于 2013-2-3 14:43:21

ofbiz TemporalExpression 表达式

项目中遇到,这个表达式,不知道怎么写,后来Debug进去兜了一圈,转换日期呀序列呀对象啊什么的。今天说下这个表达式一些规则。

<!-- TemporalExpression field details... -->

    <!-- The TemporalExpression field meanings depend upon what type of expression it is. The integer
      values are typically obtained from the java.util.Calendar field constants. For more
      information, see the org.ofbiz.service.calendar.TemporalExpressions.java file.

      tempExprTypeId      integer1       integer2      date1date2string1    string2
      ================================== =============== ====== ====== ========== ========
      HOUR_RANGE            start      end
      DATE_RANGE                                           startend
      TIME_OF_DAY_RANGE interval    count                      start end
      DAY_OF_WEEK_RANGE   start       end
      MINUTE_RANGE          start    end
      MONTH_RANGE         start       end
      DAY_OF_MONTH_RANGE    start       end
      DAY_IN_MONTH          day       occurrence
      FREQUENCY             freq type freq count start

       hh:mm:ss
       Day of week: 1 = Sunday, 7 = Saturday
       Month: January = 0, Undecimber = 12
       Day of month: 1 to 31
       Integer: -5 to +5, zero excluded
       Second = 13, Minute = 12, Hour = 11, Day = 5, Month = 2, Year = 1
       Positive integer, zero excluded
       If null, defaults to system date when the expression was retrieved from storage.
       Second = 13, Minute = 12, Hour = 11 (default)
       Deprecated - do not use
       Integer: 0 to 23, midnight = 0
       Integer: 0 to 59
    -->

Integer1对应规则的类型,Integer2对应Integer1(规则类型)的倍数
示例:现在来定义一个14天后的表达式
<TemporalExpression tempExprId="PM" tempExprTypeId="FREQUENCY" description="Every Other Monday at 5pm" date1="2000-01-03 17:00:00.000" integer1="5" integer2="14"/>
integer1="5" 可以看出规则类型是Day,integer2="14",所以说是14天。

如果要表达一段时间,比如几点-几点,这样的话,上面的表达式就不能满足。
下面是一个星期一到星期五:
<TemporalExpression tempExprId="GOVT_WORK_SCHED" tempExprTypeId="DIFFERENCE" description="Monday to Friday without US Federal Holidays"/>
    <TemporalExpressionAssoc fromTempExprId="GOVT_WORK_SCHED" toTempExprId="MON_TO_FRI" exprAssocType="INCLUDE"/>
    <TemporalExpressionAssoc fromTempExprId="GOVT_WORK_SCHED" toTempExprId="US_FED_HOLIDAYS" exprAssocType="EXCLUDE"/>

这个东西跟ofbiz Job紧密结合。。。很灵活。。。最近在用这个东西做项目,所以先研究下。后续补上job配置及其东西分享给大家。
关于TemporalExpression的一些例子和介绍
https://cwiki.apache.org/OFBENDUSER/temporal-expressions.html
转载注明出处 Charles,http://juck.iteye.com/
页: [1]
查看完整版本: ofbiz TemporalExpression 表达式