zoukankan      html  css  js  c++  java
  • drools 7 日期时间段校验

    案例如下:电商品台新增一个促销活动,2019年10月份,限时每天10点至13点,下单9折活动。

    首先可以用 date-effective 和 date-expires 两个属性限制日期区间为2019-10-01 至 2019-10-31,但是每天10点至11点该怎样限制呢?

    1、方法一:利用function

    drl文件如下所示:

    package rules;//包名
    //引入类库
    import java.text.SimpleDateFormat
    import java.util.*
     
    //处理时间的function
    function boolean checkDate(String st ,String et){
         Calendar calendar = Calendar.getInstance();
         SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
         Date startTime = sdf.parse(st);
         Date endTime = sdf.parse(et);
         Date nowCal = sdf.parse(sdf.format(calendar.getTime()));
         if(nowCal.after(startTime)  && nowCal.before(endTime)){
            return true;
         }else{
             return false;
         }
    }
     
    //规则
    rule "function_rule"
    //属性限制起止日期
    date-effective '2019-10-01'
    date-expires '2019-10-31'
     
    when
    //对时间点进行校验
    eval(checkDate('10:00:00','13:00:00'))
    then
    System.out.println("success function_rule");
    end

    2、方法二:利用Calendar判断

    package rules;
     
    import java.text.SimpleDateFormat
    import java.util.*
     
    rule "method_2"
    date-effective "2019-10-01"
    date-expires "2019-10-31"
    when
    $c:Calendar((get(Calendar.HOUR_OF_DAY) >=10 && <17),(get(Calendar.MINUTE) >=0 && <=59),(get(Calendar.SECOND) >=0 && <=59))
    //(get(Calendar.HOUR_OF_DAY) >=10 && <17) 等价于 (get(Calendar.HOUR_OF_DAY) >=10,(get(Calendar.HOUR_OF_DAY)<17
    then
    System.out.println("success method_2");
    end

    引自: https://blog.csdn.net/u010952582/article/details/102698881

  • 相关阅读:
    解决Ubuntu下pycharm无法输入中文的问题
    爬取www.mmjpg.com网站图片,你懂得哦!
    批量查询ip地址归属地
    Opencv源码编译
    使用阿里云安装python模块
    Ansible运维自动化
    Mha-Atlas-MySQL高可用
    SVN
    Tomcat
    DHCP
  • 原文地址:https://www.cnblogs.com/hzh-666/p/12532991.html
Copyright © 2011-2022 走看看