kBase2_wrap_rule.drl 4.36 KB
package com.bsth.service.schedule.impl.plan.kBase2.wrap.rule;

import org.joda.time.*;
import java.util.*;
import org.slf4j.Logger;

import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleCalcuParam_input;
import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleRule_input;
import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleRule_Type;
import com.bsth.service.schedule.impl.plan.kBase1.core.rerun.RerunRule_input;

import com.bsth.repository.schedule.RerunRuleRepository;
import com.bsth.repository.schedule.ScheduleRule1FlatRepository;

import com.bsth.service.schedule.impl.plan.ScheduleRuleService;

import com.bsth.entity.Line;
import com.bsth.entity.schedule.CarConfigInfo
import com.bsth.entity.schedule.EmployeeConfigInfo
import javax.print.attribute.standard.DateTimeAtCompleted;

// 全局日志类(一般使用调用此规则的service类)
global Logger log;

global ScheduleRule1FlatRepository srf;
global RerunRuleRepository rrr;
global ScheduleRuleService srservice;
global List sriList;


declare Sri_Wrap
    xlId : String // 线路id
    lpIds : List // 路牌id
    srf : Object // ScheduleRule1Flat类型
    sri : ScheduleRule_input; // ScheduleRule_input输入
end

rule "rw1"
    salience 1000
    when
        ScheduleCalcuParam_input(
            $fromDate : fromDate,
            $toDate : toDate,
            $xlId: xlId
        )
        $srf : Object() from srf.findByXlId(Integer.parseInt($xlId))
    then
        // 创建Sri_Wrap
        Sri_Wrap sw = new Sri_Wrap();
        sw.setXlId($xlId);
        sw.setSrf($srf);
        ScheduleRule_input sri = new ScheduleRule_input((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf());
        sw.setSri(sri);
        sw.setLpIds(sri.getGuideboardIds());

        insert(sw);

end

rule "rw2"
    salience 800
    no-loop
    when
        ScheduleCalcuParam_input(
            $fromDate : fromDate,
            $toDate : toDate,
            $xlId: xlId
        )
        $reu : RerunRule_input($lpId : lp) from srservice.findRerunrule(Integer.parseInt($xlId))
        not Sri_Wrap(xlId == $xlId, lpIds contains $lpId)
    then
        // 套跑中有规则,主线路的路牌,主线路该路牌不存在,添加一个临时的,做处理
        Sri_Wrap sw = new Sri_Wrap();
        sw.setSrf(new com.bsth.entity.schedule.rule.ScheduleRule1Flat());
        // 线路
        Line xl = new Line();
        xl.setId(Integer.valueOf($xlId));
        ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setXl(xl);
        // id,使用当前日期作为原始值加上路牌id最为临时id值
        DateTime dt = new DateTime(new Date());
        DateTime dt2 = new DateTime(dt.year().get(), dt.monthOfYear().get(), dt.dayOfMonth().get(), 0, 0, 0);
        long id = (dt2.toDate().getTime() + Long.parseLong($lpId));
        ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setId(id);
        // 启用日期
        ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setQyrq($fromDate.toDate());
        // 车辆配置
        CarConfigInfo cci = new CarConfigInfo();
        cci.setId(new Date().getTime());
        ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setCarConfigInfo(cci);
        // 人员配置
        ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyConfigIds("TEMP");
        // 人员搭班编码
        ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyDbbms("TEMP");
        // 起始人员
        ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyStart(1);
        // 路牌id
        ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setLpIds($lpId);
        // 起始路牌
        ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setLpStart(1);

        ScheduleRule_input sri = new ScheduleRule_input((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf());
        sri.setsType(ScheduleRule_Type.RERUN);
        sw.setSri(sri);

        sw.setXlId($xlId);

        List lpIds = new ArrayList();
        lpIds.add($lpId);
        sw.setLpIds(lpIds);

        insert(sw);
end

rule "rw3"
    salience 600
    when
        $sri_wrap : Sri_Wrap($sri : sri, $xlId: xlId, $lpIds : lpIds)
    then
        log.info("线路id={},type={},ruleId={},lpids={}", $xlId, $sri.getsType(), $sri.getRuleId(), $lpIds);
        sriList.add($sri);
end