rerun.drl 5.81 KB
package com.bsth.service.schedule.rerun;

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

import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;

import com.bsth.service.schedule.rules.rerun.RerunRule_input;
import com.bsth.service.schedule.rules.rerun.RerunRule_param;

import com.bsth.repository.schedule.CarConfigInfoRepository;
import com.bsth.repository.schedule.EmployeeConfigInfoRepository;

import org.slf4j.Logger
import com.bsth.entity.schedule.CarConfigInfo
import java.util.HashMap
import com.bsth.entity.schedule.EmployeeConfigInfo
import com.bsth.entity.schedule.SchedulePlanInfo;

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

global CarConfigInfoRepository carConfigInfoRepository;
global EmployeeConfigInfoRepository employeeConfigInfoRepository;

// 输出


/*
    规则说明:
    1、对应路牌规则:将对应路牌的车辆,人员替换指定的套跑班次已有的配置
    2、对应班车规则:直接使用指定的人员,车辆替换指定的套跑班次已有的配置
*/

//-------------------- 第一阶段、计算对应路牌套跑的车辆配置,人员配置数据 -----------------//

//--------------- 车辆配置信息载入 -------------//
declare Dylp_CarConfig_Wraps
    xlId: String // 线路Id
    ccMap: Map // 车辆配置Map Map<id, CarConfigInfo>
end

rule "calcu_Dylp_CarConfig_Wraps"
    salience 1000
    when
        $rp: RerunRule_param($xlId: mxlid)
        $dylpxlid: String() from $rp.getXlIds_dylp()
    then
        List carConfigInfos =  carConfigInfoRepository.findByXlId(Integer.parseInt($dylpxlid));

        Dylp_CarConfig_Wraps carConfig_wraps = new Dylp_CarConfig_Wraps();
        carConfig_wraps.setXlId($dylpxlid);
        carConfig_wraps.setCcMap(new HashMap());

        for (int i = 0; i < carConfigInfos.size(); i++) {
            CarConfigInfo carConfigInfo = (CarConfigInfo) carConfigInfos.get(i);
            carConfig_wraps.getCcMap().put(carConfigInfo.getId().toString(), carConfigInfo);
        }

        insert(carConfig_wraps);

        log.info("calcu_Dylp_CarConfig_Wraps");

end

//--------------- 人员配置信息载入 --------------//
declare Dylp_EmployeeConfig_Wraps
    xlId: String // 线路Id
    ecMap: Map // 人员配置Map Map<id, EmployeeConfigInfo>
end

rule "calcu_Dylp_EmployeeConfig_Wraps"
    salience 1000
    when
        $rp: RerunRule_param($xlId: mxlid)
        $dylpxlid: String() from $rp.getXlIds_dylp()
    then
        List employeeConfigInfos = employeeConfigInfoRepository.findByXlId(Integer.parseInt($dylpxlid));

        Dylp_EmployeeConfig_Wraps employeeConfig_wraps = new Dylp_EmployeeConfig_Wraps();
        employeeConfig_wraps.setXlId($dylpxlid);
        employeeConfig_wraps.setEcMap(new HashMap());

        for (int i = 0; i < employeeConfigInfos.size(); i++) {
            EmployeeConfigInfo employeeConfigInfo = (EmployeeConfigInfo) employeeConfigInfos.get(i);
            employeeConfig_wraps.getEcMap().put(employeeConfigInfo.getId().toString(), employeeConfigInfo);
        }

        insert(employeeConfig_wraps);

        log.info("calcu_Dylp_EmployeeConfig_Wraps");

end

//-------------------- 第二阶段、包装对应路牌的循环规则输出 -----------------//

declare Dylp_ScheduleResult_output_wrap
    xlId: String // 线路
    sd: DateTime // 日期
    lp: String // 路牌
    cc: CarConfigInfo // 使用的车辆配置
    ec: List // 使用的人员配置 List<EmployeeConfigInfo>
end

rule "calcu_Dylp_ScheduleResult_output_wrap"
    salience 900
    when
        $sro: ScheduleResults_output($xlId: xlid)
        $sr: ScheduleResult_output() from $sro.getResults()
        Dylp_CarConfig_Wraps(xlId == $xlId, $ccmap: ccMap)
        Dylp_EmployeeConfig_Wraps(xlId == $xlId, $ecmap: ecMap)
    then
        Dylp_ScheduleResult_output_wrap wrap = new Dylp_ScheduleResult_output_wrap();
        wrap.setXlId($xlId);
        wrap.setSd($sr.getSd());
        wrap.setLp($sr.getGuideboardId());
        wrap.setCc((CarConfigInfo) $ccmap.get($sr.getCarConfigId()));

        List ecs = new ArrayList();
        String[] ecids = $sr.getEmployeeConfigId().split("-"); // 分班的人
        for (int i = 0; i < ecids.length; i++) {
            ecs.add($ecmap.get(ecids[i]));
        }
        wrap.setEc(ecs);

//        log.info("xlid = {}", $xlId);

        insert(wrap);
end

//-------------------- 第三阶段、套跑线路,替换班次的车辆,人员 --------------------//
rule "calcu_Dylp_rerun_update_dylp"
    salience 800
//    no-loop
    when
        $spi: SchedulePlanInfo($xlid: xl, $sd: scheduleDate, $lp: lp, $fcsj: fcsj, $ttinfo: ttInfo)
        $ri: RerunRule_input(
            type == "dylp",
            xl == $xlid.toString(),
            ttinfo == $ttinfo.toString(),
            lp == $lp.toString(),
            fcsj == $fcsj,
            $sxl: s_xl, $slp: s_lp, $type: usetype, $hrtype: userhrtype
        )
        $dsro: Dylp_ScheduleResult_output_wrap(
            xlId == $sxl,
            lp == $slp,
            sd.getMillis() == $sd.getTime()
        )
    then
//        log.info("TODO:测试 {}", $fcsj);

        $spi.setRerunInfoDylp($dsro.getCc(), $dsro.getEc(), $type, $hrtype);

end

rule "calcu_Dylp_rerun_update_dybc"
    salience 700
    when
        $spi: SchedulePlanInfo($xlid: xl, $sd: scheduleDate, $lp: lp, $fcsj: fcsj, $ttinfo: ttInfo)
        $ri: RerunRule_input(
            type == "dybc",
            xl == $xlid.toString(),
            ttinfo == $ttinfo.toString(),
            lp == $lp.toString(),
            fcsj == $fcsj
        )

    then

        $spi.setRerunInfoDybc($ri);


end