Commit 1ca919f875612224f54c71fadec6f48923254487

Authored by 徐烜
1 parent a0638d3c

Update

src/main/java/com/bsth/service/schedule/impl/SchedulePlanServiceImpl.java
... ... @@ -244,11 +244,12 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im
244 244 Date end4 = new Date();
245 245  
246 246  
247   - logger.info("删除数据 {} ms,drool时刻表每日路牌计算 {} ms,drool循环规则计算 {} ms,drool计划数据 {} ms,插入数据 {} ms",
  247 + logger.info("删除数据 {} ms,drool时刻表每日路牌计算 {} ms,drool循环规则计算 {} ms,drool计划数据 {} ms,插入数据 {} 条 耗时 {} ms",
248 248 endpre.getTime() - startpre.getTime(),
249 249 end1.getTime() - start1.getTime(),
250 250 end2.getTime() - start2.getTime(),
251 251 end3.getTime() - start3.getTime(),
  252 + planResult.getSchedulePlanInfos().size(),
252 253 end4.getTime() - start4.getTime());
253 254  
254 255  
... ...
src/main/java/com/bsth/service/schedule/rules/MyDroolsConfiguration.java
... ... @@ -76,12 +76,12 @@ public class MyDroolsConfiguration {
76 76 // 4、创建KieBuilder,使用KieFileSystem构建
77 77 KieBuilder kieBuilder = kieServices.newKieBuilder(kfs).buildAll();
78 78 Results results = kieBuilder.getResults();
79   -// if (results.hasMessages(Message.Level.ERROR))
80   -// throw new IllegalStateException("构建drools6错误:" + results.getMessages());
81   - if (results.hasMessages(Message.Level.ERROR)) {
82   - logger.info("构建drools6错误:" + results.getMessages());
83   - return null;
84   - }
  79 + if (results.hasMessages(Message.Level.ERROR))
  80 + throw new IllegalStateException("构建drools6错误:" + results.getMessages());
  81 +// if (results.hasMessages(Message.Level.ERROR)) {
  82 +// logger.info("构建drools6错误:" + results.getMessages());
  83 +// return null;
  84 +// }
85 85  
86 86 // 5、获取KieContainer
87 87 // TODO:ReleaseId用处很大,以后再议
... ...
src/main/resources/logback.xml
... ... @@ -159,6 +159,32 @@
159 159 <!--<appender-ref ref="STDOUT" />-->
160 160 <!--</logger>-->
161 161  
  162 + <!--JdbcTemplate的日志输出器 -->
  163 + <logger name="org.springframework.jdbc.core.StatementCreatorUtils"
  164 + additivity="false" level="TRACE">
  165 + <appender-ref ref="STDOUT" />
  166 + </logger>
  167 + <logger name="org.springframework.jdbc.core" additivity="true">
  168 + <level value="DEBUG" />
  169 + <appender-ref ref="STDOUT" />
  170 + </logger>
  171 + <logger name="java.sql.Connection" additivity="true">
  172 + <level value="DEBUG" />
  173 + <appender-ref ref="STDOUT" />
  174 + </logger>
  175 + <logger name="java.sql.Statement" additivity="true">
  176 + <level value="DEBUG" />
  177 + <appender-ref ref="STDOUT" />
  178 + </logger>
  179 + <logger name="java.sql.PreparedStatement" additivity="true">
  180 + <level value="DEBUG" />
  181 + <appender-ref ref="STDOUT" />
  182 + </logger>
  183 + <logger name="java.sql.ResultSet" additivity="true">
  184 + <level value="DEBUG" />
  185 + <appender-ref ref="STDOUT" />
  186 + </logger>
  187 +
162 188 <!-- 日志输出级别 -->
163 189 <root level="info">
164 190 <appender-ref ref="STDOUT" />
... ...
src/main/resources/rules/legacy/plan.drl 0 → 100644
  1 +package com.bsth.service.schedule.plan;
  2 +
  3 +import org.joda.time.*;
  4 +import java.util.*;
  5 +
  6 +import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input;
  7 +import com.bsth.service.schedule.rules.plan.PlanResult;
  8 +
  9 +import com.bsth.repository.schedule.TTInfoDetailRepository;
  10 +import com.bsth.repository.schedule.CarConfigInfoRepository;
  11 +import com.bsth.repository.schedule.EmployeeConfigInfoRepository;
  12 +import com.bsth.repository.LineRepository;
  13 +import com.bsth.repository.BusinessRepository;
  14 +
  15 +import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
  16 +import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
  17 +import com.bsth.service.schedule.rules.ttinfo.TTInfoResult_output;
  18 +import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output;
  19 +import com.bsth.entity.Line;
  20 +import com.bsth.entity.Business;
  21 +
  22 +import com.bsth.entity.schedule.CarConfigInfo;
  23 +import com.bsth.entity.schedule.EmployeeConfigInfo;
  24 +import com.bsth.entity.schedule.TTInfo;
  25 +import com.bsth.entity.schedule.TTInfoDetail;
  26 +import com.bsth.entity.schedule.SchedulePlanInfo;
  27 +
  28 +import org.slf4j.Logger
  29 +import org.joda.time.format.DateTimeFormat
  30 +import org.apache.commons.lang3.StringUtils;
  31 +
  32 +
  33 +// 全局日志类(一般使用调用此规则的service类)
  34 +global Logger log;
  35 +
  36 +global TTInfoDetailRepository tTInfoDetailRepository;
  37 +global CarConfigInfoRepository carConfigInfoRepository;
  38 +global EmployeeConfigInfoRepository employeeConfigInfoRepository;
  39 +global LineRepository lineRepository;
  40 +global BusinessRepository businessRepository;
  41 +
  42 +// 输出
  43 +global PlanResult planResult;
  44 +
  45 +function Map xlidParams(String xlid) {
  46 + Map param = new HashMap();
  47 + param.put("xl.id_eq", Integer.valueOf(xlid));
  48 + return param;
  49 +}
  50 +
  51 +function List ecList(EmployeeConfigInfoRepository repo, String ecids) {
  52 + List<String> ids = Arrays.asList(ecids.split("-"));
  53 + List rst = new ArrayList();
  54 + for (int i = 0; i < ids.size(); i++) {
  55 + rst.add(repo.findOne(Long.parseLong(ids.get(i))));
  56 + }
  57 + return rst;
  58 +}
  59 +
  60 +function LocalTime fcsjTime(String fcsj) {
  61 + if ("NULL".equals(fcsj)) {
  62 + return null;
  63 + }
  64 + return LocalTime.parse(fcsj, DateTimeFormat.forPattern("HH:mm"));
  65 +}
  66 +
  67 +function String ttInfoId_sd(Map map, DateTime sd) {
  68 + TTInfoResult_output ttInfoResult_output = (TTInfoResult_output) map.get(sd);
  69 + return ttInfoResult_output.getTtInfoId();
  70 +}
  71 +
  72 +/*
  73 + 规则说明:
  74 + 根据循环规则输出,时刻表选择规则输出,组合计算排班明细
  75 +*/
  76 +
  77 +//-------------------- 第一阶段、计算迭代数据 -----------------//
  78 +declare Loop_result
  79 + xlId: String // 线路id
  80 +
  81 + ruleLoop: List // 每天分配的规则 List<ScheduleResult_output>
  82 +
  83 + ttInfoMapLoop_temp: Map // 每天分配的时刻表 Map<DataTime, Collection<TTInfoResult_output>>
  84 + ttInfoMapLoop: Map // 每天分配的时刻表 Map<DataTime, TTInfoResult_output>
  85 + ttInfoMap: Map // 总共用到的时刻表 Map<id, TTInfoResult_output>
  86 +end
  87 +
  88 +rule "calcu_step1_Loop_result"
  89 + salience 1000
  90 + when
  91 + $param: PlanCalcuParam_input($xlId: xlId)
  92 + then
  93 + Loop_result loop_result = new Loop_result();
  94 + loop_result.setXlId($xlId);
  95 + loop_result.setRuleLoop($param.getScheduleResults_output().getResults());
  96 +
  97 + loop_result.setTtInfoMapLoop(new HashMap());
  98 + loop_result.setTtInfoMap(new HashMap());
  99 +
  100 + com.google.common.collect.Multimap ttInfoMap_temp =
  101 + (com.google.common.collect.Multimap)
  102 + $param.getTtInfoResults_output().getResults().get(
  103 + String.valueOf($xlId));
  104 +
  105 + loop_result.setTtInfoMapLoop_temp(ttInfoMap_temp.asMap());
  106 +
  107 + insert(loop_result);
  108 +
  109 +// log.info("calcu_step1_Loop_result");
  110 +end
  111 +
  112 +rule "calcu_step2_loop_result"
  113 + salience 1000
  114 + no-loop
  115 + when
  116 + $param: PlanCalcuParam_input($xlId: xlId)
  117 + $lr: Loop_result(xlId == $xlId)
  118 + $sd: DateTime() from $lr.ttInfoMapLoop_temp.keySet()
  119 + then
  120 + // 当天时刻表只取第一张 TODO:
  121 + Collection col = (Collection) $lr.getTtInfoMapLoop_temp().get($sd);
  122 + Iterator iter = col.iterator();
  123 + TTInfoResult_output ttInfo_result = (TTInfoResult_output) iter.next();
  124 + $lr.getTtInfoMapLoop().put($sd, ttInfo_result);
  125 +
  126 + // 总共使用的时刻表
  127 + $lr.getTtInfoMap().put(ttInfo_result.getTtInfoId(), ttInfo_result);
  128 +
  129 + update($lr);
  130 +
  131 +// log.info("calcu_step2_Loop_result");
  132 +end
  133 +
  134 +//-------------------- 第二阶段、将时刻表班次,车辆配置,人员配置信息载入 -----------------//
  135 +
  136 +//--------------- 车辆配置信息载入 -------------//
  137 +declare CarConfig_Wrap
  138 + id: String // 车辆配置id(cast字符串-方便比较)
  139 +
  140 + self: CarConfigInfo // 原始数据
  141 +end
  142 +
  143 +rule "calcu_CarConfig_Wrap"
  144 + salience 800
  145 + when
  146 + $lr: Loop_result($xlId: xlId)
  147 + $ccf: CarConfigInfo() from carConfigInfoRepository.findByXlId(Integer.parseInt($xlId))
  148 + then
  149 + CarConfig_Wrap carConfig_wrap = new CarConfig_Wrap();
  150 + carConfig_wrap.setId(String.valueOf($ccf.getId()));
  151 + carConfig_wrap.setSelf($ccf);
  152 +
  153 + insert(carConfig_wrap);
  154 +
  155 +// log.info("calcu_CarConfig_Wrap");
  156 +end
  157 +
  158 +//--------------- 人员配置信息载入 --------------//
  159 +declare EmployeeConfig_Wrap
  160 + id: String // 人员配置id(cast字符串-方便比较)
  161 +
  162 + self: EmployeeConfigInfo // 原始数据
  163 +end
  164 +
  165 +rule "calcu_EmployeeConfig_Wrap"
  166 + salience 800
  167 + when
  168 + $lr: Loop_result($xlId: xlId)
  169 + $eci: EmployeeConfigInfo() from employeeConfigInfoRepository.findByXlId(Integer.parseInt($xlId))
  170 + then
  171 + EmployeeConfig_Wrap employeeConfig_wrap = new EmployeeConfig_Wrap();
  172 + employeeConfig_wrap.setId(String.valueOf($eci.getId()));
  173 + employeeConfig_wrap.setSelf($eci);
  174 +
  175 + insert(employeeConfig_wrap);
  176 +
  177 +// log.info("calcu_EmployeeConfig_Wrap");
  178 +end
  179 +
  180 +//----------------- 时刻表班次信息载入 -----------------//
  181 +declare TTInfo_gid_stat
  182 + xlId: String // 线路id(cast字符串-方便比较)
  183 + ttInfoId: String // 时刻表id(cast字符串-方便比较)
  184 + gid: String // 路牌id(cast字符串-方便比较)
  185 +
  186 + maxFcno: Integer // 最大发车顺序号
  187 +
  188 + fbTime: LocalTime // 分班时间
  189 +end
  190 +
  191 +rule "calcu_TTInfo_gid_stat"
  192 + salience 800
  193 + when
  194 + $lr: Loop_result($xlId: xlId)
  195 + $ttInfoId: String() from $lr.getTtInfoMap().keySet()
  196 + $gids: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), gidscount($ttd))
  197 + $gid: String() from $gids
  198 + $fbtime_str: String() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), gidfbtime($ttd))
  199 + $maxfcno: Double() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), max($ttd.getFcno()))
  200 + then
  201 + TTInfo_gid_stat ttInfo_gid_stat = new TTInfo_gid_stat();
  202 + ttInfo_gid_stat.setXlId($xlId);
  203 + ttInfo_gid_stat.setTtInfoId($ttInfoId);
  204 + ttInfo_gid_stat.setGid($gid);
  205 +
  206 + ttInfo_gid_stat.setMaxFcno($maxfcno.intValue());
  207 + ttInfo_gid_stat.setFbTime(fcsjTime($fbtime_str));
  208 +
  209 + insert(ttInfo_gid_stat);
  210 +
  211 +// log.info("xlid={},ttid={},gid={},maxfcno={},fbtime={}",
  212 +// $xlId, $ttInfoId, $gid, ttInfo_gid_stat.getMaxFcno(), ttInfo_gid_stat.getFbTime());
  213 +
  214 +end
  215 +
  216 +declare TTInfoDetail_Wrap
  217 + xlId: String // 线路id(cast字符串-方便比较)
  218 + ttInfoId: String // 时刻表id(cast字符串-方便比较)
  219 + gid: String // 路牌id(cast字符串-方便比较)
  220 +
  221 + isFirstBc: Boolean = false // 是否是当前路牌的第一个班次
  222 + isLastBc: Boolean = false // 是否是当前路牌的最后一个班次
  223 + isFb: Boolean = false // 是否分班
  224 +
  225 + self: TTInfoDetail // 原始数据
  226 +end
  227 +
  228 +rule "calcu_TTInfoDetail_Wrap"
  229 + salience 800
  230 + when
  231 + $lr: Loop_result($xlId: xlId)
  232 + $ttInfoId: String() from $lr.getTtInfoMap().keySet()
  233 + $ttInfoStat: TTInfo_gid_stat(
  234 + ttInfoId == $ttInfoId,
  235 + $gid: gid, $maxFcno: maxFcno)
  236 + $ttInfoDetail: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId))
  237 + then
  238 + TTInfoDetail_Wrap ttInfoDetail_wrap = new TTInfoDetail_Wrap();
  239 + ttInfoDetail_wrap.setXlId($xlId);
  240 + ttInfoDetail_wrap.setTtInfoId($ttInfoId);
  241 + ttInfoDetail_wrap.setGid($gid);
  242 + ttInfoDetail_wrap.setIsFirstBc(1 == $ttInfoDetail.getFcno());
  243 + ttInfoDetail_wrap.setIsLastBc($maxFcno == $ttInfoDetail.getFcno());
  244 +
  245 + LocalTime fcsj = fcsjTime($ttInfoDetail.getFcsj());
  246 + LocalTime fbsj = $ttInfoStat.getFbTime();
  247 + ttInfoDetail_wrap.setIsFb(fbsj == null ? false : (fcsj.isEqual(fbsj) || fcsj.isAfter(fbsj)));
  248 +
  249 + ttInfoDetail_wrap.setSelf($ttInfoDetail);
  250 +
  251 + insert(ttInfoDetail_wrap);
  252 +
  253 +// log.info("xlid={},ttid={},gid={},isFirstBc={},isLastBc={},isFb={},fcsj={}",
  254 +// $xlId, $ttInfoId, $gid,
  255 +// ttInfoDetail_wrap.getIsFirstBc(),
  256 +// ttInfoDetail_wrap.getIsLastBc(),
  257 +// ttInfoDetail_wrap.getIsFb(),
  258 +// $ttInfoDetail.getFcsj());
  259 +end
  260 +
  261 +//-------------------- 第三阶段、合并计算SchedulePlanInfo -----------------//
  262 +
  263 +rule "Calcu_SchedulePlanInfo"
  264 + salience 600
  265 + when
  266 + $param: PlanCalcuParam_input($xlId: xlId)
  267 + $lr: Loop_result(xlId == $xlId)
  268 + $sro: ScheduleResult_output($sd: sd, $gid: guideboardId) from $lr.getRuleLoop()
  269 + CarConfig_Wrap(id == $sro.carConfigId, $cc: self)
  270 + TTInfoDetail_Wrap(
  271 + ttInfoId == ttInfoId_sd($lr.getTtInfoMapLoop(), $sd),
  272 + gid == $gid,
  273 + $isFb: isFb, $isFirstBc: isFirstBc, $isLastBc: isLastBc,
  274 + $ttInfoDetail: self
  275 + )
  276 + then
  277 + // 线路
  278 + Line xl = lineRepository.findOne(Integer.parseInt($xlId));
  279 +
  280 + SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo(
  281 + xl,
  282 + $sro,
  283 + $ttInfoDetail,
  284 + $isFb,
  285 + $cc,
  286 + ecList(employeeConfigInfoRepository, $sro.getEmployeeConfigId()),
  287 + $param.getSchedulePlan(),
  288 + $isFirstBc,
  289 + $isLastBc
  290 + );
  291 +
  292 + // 获取公司,分公司信息
  293 + String gsbm = xl.getCompany();
  294 + String fgsbm = xl.getBrancheCompany();
  295 + Business gs = null;
  296 + Business fgs = null;
  297 +
  298 + if (StringUtils.isNotEmpty(gsbm)) {
  299 + Iterator<Business> businessIterator1 = businessRepository.findByBusinessCode(gsbm).iterator();
  300 + if (businessIterator1.hasNext()) {
  301 + gs = (Business) businessIterator1.next();
  302 + }
  303 + }
  304 + if (StringUtils.isNotEmpty(gsbm) && StringUtils.isNotEmpty(fgsbm)) {
  305 + Iterator<Business> businessIterator2 = businessRepository.findByUpCodeAndBusinessCode(gsbm, fgsbm).iterator();
  306 + if (businessIterator2.hasNext()) {
  307 + fgs = (Business) businessIterator2.next();
  308 + }
  309 + }
  310 +
  311 + if (gs != null) {
  312 + schedulePlanInfo.setGsBm(gs.getBusinessCode());
  313 + schedulePlanInfo.setGsName(gs.getBusinessName());
  314 + }
  315 + if (fgs != null) {
  316 + schedulePlanInfo.setFgsBm(fgs.getBusinessCode());
  317 + schedulePlanInfo.setFgsName(fgs.getBusinessName());
  318 + }
  319 +
  320 + // 操作人,操作时间
  321 + schedulePlanInfo.setCreateBy($param.getSchedulePlan().getCreateBy());
  322 + schedulePlanInfo.setCreateDate($param.getSchedulePlan().getCreateDate());
  323 + schedulePlanInfo.setUpdateBy($param.getSchedulePlan().getUpdateBy());
  324 + schedulePlanInfo.setUpdateDate($param.getSchedulePlan().getUpdateDate());
  325 +
  326 + // result 输出
  327 + planResult.getSchedulePlanInfos().add(schedulePlanInfo);
  328 +
  329 + log.info("gid={},ecid={},ttInfoId={}",
  330 + $gid, ecList(employeeConfigInfoRepository, $sro.getEmployeeConfigId()),
  331 + ttInfoId_sd($lr.getTtInfoMapLoop(), $sd));
  332 +
  333 +end
  334 +
  335 +
  336 +
  337 +
  338 +
  339 +
  340 +
  341 +
  342 +
  343 +
  344 +
  345 +
  346 +
  347 +
  348 +
... ...
src/main/resources/rules/plan.drl
... ... @@ -69,6 +69,34 @@ function String ttInfoId_sd(Map map, DateTime sd) {
69 69 return ttInfoResult_output.getTtInfoId();
70 70 }
71 71  
  72 +function Map gsMap(List gses) {
  73 + Map gsMap = new HashMap();
  74 + for (int i = 0; i < gses.size(); i++) {
  75 + Business gs = (Business) gses.get(i);
  76 + if (StringUtils.isNotEmpty(gs.getBusinessCode())) {
  77 + if ("88".equals(gs.getUpCode())) { // 浦东公交
  78 + gsMap.put(gs.getBusinessCode(), gs);
  79 + }
  80 + if (gs.getBusinessCode().equals(gs.getUpCode())) { // 闵行,青浦
  81 + gsMap.put(gs.getBusinessCode(), gs);
  82 + }
  83 + }
  84 + }
  85 + return gsMap;
  86 +}
  87 +
  88 +function Map fgsMap(List gses) {
  89 + // 这里简单将 businessCode和upCode合并
  90 + Map fgsMap = new HashMap();
  91 + for (int i = 0; i < gses.size(); i++) {
  92 + Business gs = (Business) gses.get(i);
  93 + if (StringUtils.isNotEmpty(gs.getBusinessCode()) && StringUtils.isNotEmpty(gs.getUpCode())) {
  94 + fgsMap.put(gs.getUpCode() + "_" + gs.getBusinessCode(), gs);
  95 + }
  96 + }
  97 + return fgsMap;
  98 +}
  99 +
72 100 /*
73 101 规则说明:
74 102 根据循环规则输出,时刻表选择规则输出,组合计算排班明细
... ... @@ -106,7 +134,7 @@ rule &quot;calcu_step1_Loop_result&quot;
106 134  
107 135 insert(loop_result);
108 136  
109   - log.info("calcu_step1_Loop_result");
  137 +// log.info("calcu_step1_Loop_result");
110 138 end
111 139  
112 140 rule "calcu_step2_loop_result"
... ... @@ -128,51 +156,61 @@ rule &quot;calcu_step2_loop_result&quot;
128 156  
129 157 update($lr);
130 158  
131   - log.info("calcu_step2_Loop_result");
  159 +// log.info("calcu_step2_Loop_result");
132 160 end
133 161  
134 162 //-------------------- 第二阶段、将时刻表班次,车辆配置,人员配置信息载入 -----------------//
135 163  
136 164 //--------------- 车辆配置信息载入 -------------//
137   -declare CarConfig_Wrap
138   - id: String // 车辆配置id(cast字符串-方便比较)
139   -
140   - self: CarConfigInfo // 原始数据
  165 +declare CarConfig_Wraps
  166 + xlId: String // 线路Id
  167 + ccMap: Map // 车辆配置Map Map<id, CarConfigInfo>
141 168 end
142 169  
143   -rule "calcu_CarConfig_Wrap"
  170 +rule "calcu_CarConfig_Wraps"
144 171 salience 800
145 172 when
146 173 $lr: Loop_result($xlId: xlId)
147   - $ccf: CarConfigInfo() from carConfigInfoRepository.findByXlId(Integer.parseInt($xlId))
148 174 then
149   - CarConfig_Wrap carConfig_wrap = new CarConfig_Wrap();
150   - carConfig_wrap.setId(String.valueOf($ccf.getId()));
151   - carConfig_wrap.setSelf($ccf);
  175 + List carConfigInfos = carConfigInfoRepository.findByXlId(Integer.parseInt($xlId));
  176 +
  177 + CarConfig_Wraps carConfig_wraps = new CarConfig_Wraps();
  178 + carConfig_wraps.setXlId($xlId);
  179 + carConfig_wraps.setCcMap(new HashMap());
  180 +
  181 + for (int i = 0; i < carConfigInfos.size(); i++) {
  182 + CarConfigInfo carConfigInfo = (CarConfigInfo) carConfigInfos.get(i);
  183 + carConfig_wraps.getCcMap().put(carConfigInfo.getId().toString(), carConfigInfo);
  184 + }
152 185  
153   - insert(carConfig_wrap);
  186 + insert(carConfig_wraps);
154 187  
155 188 log.info("calcu_CarConfig_Wrap");
156 189 end
157 190  
158 191 //--------------- 人员配置信息载入 --------------//
159   -declare EmployeeConfig_Wrap
160   - id: String // 人员配置id(cast字符串-方便比较)
161   -
162   - self: EmployeeConfigInfo // 原始数据
  192 +declare EmployeeConfig_Wraps
  193 + xlId: String // 线路Id
  194 + ecMap: Map // 人员配置Map Map<id, EmployeeConfigInfo>
163 195 end
164 196  
165   -rule "calcu_EmployeeConfig_Wrap"
  197 +rule "calcu_EmployeeConfig_Wraps"
166 198 salience 800
167 199 when
168 200 $lr: Loop_result($xlId: xlId)
169   - $eci: EmployeeConfigInfo() from employeeConfigInfoRepository.findByXlId(Integer.parseInt($xlId))
170 201 then
171   - EmployeeConfig_Wrap employeeConfig_wrap = new EmployeeConfig_Wrap();
172   - employeeConfig_wrap.setId(String.valueOf($eci.getId()));
173   - employeeConfig_wrap.setSelf($eci);
  202 + List employeeConfigInfos = employeeConfigInfoRepository.findByXlId(Integer.parseInt($xlId));
  203 +
  204 + EmployeeConfig_Wraps employeeConfig_wraps = new EmployeeConfig_Wraps();
  205 + employeeConfig_wraps.setXlId($xlId);
  206 + employeeConfig_wraps.setEcMap(new HashMap());
  207 +
  208 + for (int i = 0; i < employeeConfigInfos.size(); i++) {
  209 + EmployeeConfigInfo employeeConfigInfo = (EmployeeConfigInfo) employeeConfigInfos.get(i);
  210 + employeeConfig_wraps.getEcMap().put(employeeConfigInfo.getId().toString(), employeeConfigInfo);
  211 + }
174 212  
175   - insert(employeeConfig_wrap);
  213 + insert(employeeConfig_wraps);
176 214  
177 215 log.info("calcu_EmployeeConfig_Wrap");
178 216 end
... ... @@ -208,16 +246,12 @@ rule &quot;calcu_TTInfo_gid_stat&quot;
208 246  
209 247 insert(ttInfo_gid_stat);
210 248  
211   - log.info("xlid={},ttid={},gid={},maxfcno={},fbtime={}",
212   - $xlId, $ttInfoId, $gid, ttInfo_gid_stat.getMaxFcno(), ttInfo_gid_stat.getFbTime());
  249 +// log.info("xlid={},ttid={},gid={},maxfcno={},fbtime={}",
  250 +// $xlId, $ttInfoId, $gid, ttInfo_gid_stat.getMaxFcno(), ttInfo_gid_stat.getFbTime());
213 251  
214 252 end
215 253  
216 254 declare TTInfoDetail_Wrap
217   - xlId: String // 线路id(cast字符串-方便比较)
218   - ttInfoId: String // 时刻表id(cast字符串-方便比较)
219   - gid: String // 路牌id(cast字符串-方便比较)
220   -
221 255 isFirstBc: Boolean = false // 是否是当前路牌的第一个班次
222 256 isLastBc: Boolean = false // 是否是当前路牌的最后一个班次
223 257 isFb: Boolean = false // 是否分班
... ... @@ -225,110 +259,193 @@ declare TTInfoDetail_Wrap
225 259 self: TTInfoDetail // 原始数据
226 260 end
227 261  
228   -rule "calcu_TTInfoDetail_Wrap"
229   - salience 800
  262 +declare TTInfoDetail_Wraps
  263 + xlId: String // 线路id(cast字符串-方便比较)
  264 + ttInfoId: String // 时刻表id(cast字符串-方便比较)
  265 +
  266 + detailsMap: Map // 明细Map,Map<路牌id, List<TTInfoDetail_Wrap>>
  267 +end
  268 +
  269 +rule "calcu_TTInfoDetail_Wraps"
  270 + salience 700
230 271 when
231 272 $lr: Loop_result($xlId: xlId)
232 273 $ttInfoId: String() from $lr.getTtInfoMap().keySet()
233   - $ttInfoStat: TTInfo_gid_stat(
234   - ttInfoId == $ttInfoId,
235   - $gid: gid, $maxFcno: maxFcno)
236   - $ttInfoDetail: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId))
  274 + $ttInfoStatList: List(size > 0) from collect (TTInfo_gid_stat(ttInfoId == $ttInfoId))
237 275 then
238   - TTInfoDetail_Wrap ttInfoDetail_wrap = new TTInfoDetail_Wrap();
239   - ttInfoDetail_wrap.setXlId($xlId);
240   - ttInfoDetail_wrap.setTtInfoId($ttInfoId);
241   - ttInfoDetail_wrap.setGid($gid);
242   - ttInfoDetail_wrap.setIsFirstBc(1 == $ttInfoDetail.getFcno());
243   - ttInfoDetail_wrap.setIsLastBc($maxFcno == $ttInfoDetail.getFcno());
244   -
245   - LocalTime fcsj = fcsjTime($ttInfoDetail.getFcsj());
246   - LocalTime fbsj = $ttInfoStat.getFbTime();
247   - ttInfoDetail_wrap.setIsFb(fbsj == null ? false : (fcsj.isEqual(fbsj) || fcsj.isAfter(fbsj)));
248   -
249   - ttInfoDetail_wrap.setSelf($ttInfoDetail);
250   -
251   - insert(ttInfoDetail_wrap);
252   -
253   - log.info("xlid={},ttid={},gid={},isFirstBc={},isLastBc={},isFb={},fcsj={}",
254   - $xlId, $ttInfoId, $gid,
255   - ttInfoDetail_wrap.getIsFirstBc(),
256   - ttInfoDetail_wrap.getIsLastBc(),
257   - ttInfoDetail_wrap.getIsFb(),
258   - $ttInfoDetail.getFcsj());
  276 + TTInfoDetail_Wraps ttInfoDetail_wraps = new TTInfoDetail_Wraps();
  277 + ttInfoDetail_wraps.setXlId($xlId);
  278 + ttInfoDetail_wraps.setTtInfoId($ttInfoId);
  279 + ttInfoDetail_wraps.setDetailsMap(new HashMap());
  280 +
  281 + // 将list的形式变成 Map<路牌id, TTInfo_gid_stat>
  282 + Map statMap = new HashMap();
  283 + for (int i = 0; i < $ttInfoStatList.size(); i++) {
  284 + TTInfo_gid_stat ttInfo_gid_stat = (TTInfo_gid_stat) $ttInfoStatList.get(i);
  285 + statMap.put(ttInfo_gid_stat.getGid(), ttInfo_gid_stat);
  286 + }
  287 +
  288 + // 迭代ttinfodetail,拼装 TTInfoDetail_Wraps
  289 + List detaillist = tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId));
  290 + for (int j = 0; j < detaillist.size(); j++) {
  291 + TTInfoDetail ttInfoDetail = (TTInfoDetail) detaillist.get(j);
  292 + String gid = String.valueOf(ttInfoDetail.getLp().getId());
  293 +
  294 + if (ttInfoDetail_wraps.getDetailsMap().get(gid) == null) {
  295 + ttInfoDetail_wraps.getDetailsMap().put(gid, new ArrayList());
  296 + }
  297 +
  298 + // 获取stat
  299 + TTInfo_gid_stat ttInfo_gid_stat = (TTInfo_gid_stat) statMap.get(gid);
  300 +
  301 + TTInfoDetail_Wrap ttInfoDetail_wrap = new TTInfoDetail_Wrap();
  302 + ttInfoDetail_wrap.setIsFirstBc(1 == ttInfoDetail.getFcno());
  303 + ttInfoDetail_wrap.setIsLastBc(ttInfo_gid_stat.getMaxFcno() == ttInfoDetail.getFcno());
  304 +
  305 + LocalTime fcsj = fcsjTime(ttInfoDetail.getFcsj());
  306 + LocalTime fbsj = ttInfo_gid_stat.getFbTime();
  307 + ttInfoDetail_wrap.setIsFb(fbsj == null ? false : (fcsj.isEqual(fbsj) || fcsj.isAfter(fbsj)));
  308 +
  309 + ttInfoDetail_wrap.setSelf(ttInfoDetail);
  310 +
  311 + ((List) ttInfoDetail_wraps.getDetailsMap().get(gid)).add(ttInfoDetail_wrap);
  312 +
  313 + }
  314 +
  315 +
  316 + insert(ttInfoDetail_wraps);
  317 +
  318 + log.info("xlid={}, ttinfoid={}, lpstatCount={}, detailLpCount={}",
  319 + $xlId, $ttInfoId, $ttInfoStatList.size(), ttInfoDetail_wraps.getDetailsMap().keySet().size());
  320 +
  321 +
  322 +end
  323 +
  324 +declare TTInfoDetail_Wraps_map
  325 + xlId: String // 线路id(cast字符串-方便比较)
  326 +
  327 + wrapsMap: Map // 明细Map,Map<时刻表Id, TTInfoDetail_Wraps>
  328 +end
  329 +
  330 +rule "calcu_TTInfoDetail_Wraps_toMap"
  331 + salience 600
  332 + when
  333 + $lr: Loop_result($xlId: xlId)
  334 + $wrapsList: List(size > 0) from collect (TTInfoDetail_Wraps(xlId == $xlId))
  335 + then
  336 + // 转换成Map
  337 + TTInfoDetail_Wraps_map all = new TTInfoDetail_Wraps_map();
  338 + all.setXlId($xlId);
  339 + all.setWrapsMap(new HashMap());
  340 +
  341 + for (int i = 0; i < $wrapsList.size(); i++) {
  342 + TTInfoDetail_Wraps ttInfoDetail_wraps = (TTInfoDetail_Wraps) $wrapsList.get(i);
  343 + all.getWrapsMap().put(ttInfoDetail_wraps.getTtInfoId(), ttInfoDetail_wraps);
  344 + }
  345 +
  346 + insert(all);
259 347 end
260 348  
  349 +
  350 +
  351 +
261 352 //-------------------- 第三阶段、合并计算SchedulePlanInfo -----------------//
262 353  
  354 +
263 355 rule "Calcu_SchedulePlanInfo"
264   - salience 600
  356 + salience 500
265 357 when
266 358 $param: PlanCalcuParam_input($xlId: xlId)
267 359 $lr: Loop_result(xlId == $xlId)
268   - $sro: ScheduleResult_output($sd: sd, $gid: guideboardId) from $lr.getRuleLoop()
269   - CarConfig_Wrap(id == $sro.carConfigId, $cc: self)
270   - TTInfoDetail_Wrap(
271   - ttInfoId == ttInfoId_sd($lr.getTtInfoMapLoop(), $sd),
272   - gid == $gid,
273   - $isFb: isFb, $isFirstBc: isFirstBc, $isLastBc: isLastBc,
274   - $ttInfoDetail: self
275   - )
  360 + $ccs: CarConfig_Wraps(xlId == $xlId)
  361 + $ecs: EmployeeConfig_Wraps(xlId == $xlId)
  362 + $tts: TTInfoDetail_Wraps_map(xlId == $xlId)
276 363 then
277 364 // 线路
278 365 Line xl = lineRepository.findOne(Integer.parseInt($xlId));
279 366  
280   - SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo(
281   - xl,
282   - $sro,
283   - $ttInfoDetail,
284   - $isFb,
285   - $cc,
286   - ecList(employeeConfigInfoRepository, $sro.getEmployeeConfigId()),
287   - $param.getSchedulePlan(),
288   - $isFirstBc,
289   - $isLastBc
290   - );
291   -
292   - // 获取公司,分公司信息
293   - String gsbm = xl.getCompany();
294   - String fgsbm = xl.getBrancheCompany();
295   - Business gs = null;
296   - Business fgs = null;
297   -
298   - if (StringUtils.isNotEmpty(gsbm)) {
299   - Iterator<Business> businessIterator1 = businessRepository.findByBusinessCode(gsbm).iterator();
300   - if (businessIterator1.hasNext()) {
301   - gs = (Business) businessIterator1.next();
  367 + // 查找公司
  368 + List gses = (List) businessRepository.findAll();
  369 + // 构造公司代码对应map
  370 + Map gsMap = gsMap(gses);
  371 + // 构造分公司对应的map
  372 + Map fgsMap = fgsMap(gses);
  373 +
  374 + for (int i = 0; i < $lr.getRuleLoop().size(); i++) {
  375 + ScheduleResult_output sro = (ScheduleResult_output) $lr.getRuleLoop().get(i);
  376 +
  377 + // 日期
  378 + DateTime sd = sro.getSd();
  379 + // 路牌
  380 + String gid = sro.getGuideboardId();
  381 + // 车辆配置
  382 + CarConfigInfo carConfigInfo = (CarConfigInfo) $ccs.getCcMap().get(sro.getCarConfigId());
  383 + // 人员配置
  384 + List eclist = ecList(employeeConfigInfoRepository, sro.getEmployeeConfigId());
  385 +
  386 + // 时刻表id
  387 + String ttInfoId = ttInfoId_sd($lr.getTtInfoMapLoop(), sd);
  388 + TTInfoDetail_Wraps ttInfoDetail_wraps = (TTInfoDetail_Wraps) $tts.getWrapsMap().get(ttInfoId);
  389 + List detaillist = (List) ttInfoDetail_wraps.getDetailsMap().get(gid);
  390 +
  391 + if (detaillist == null) {
  392 + // 这里翻到的路牌时刻表里可能没有,
  393 + // 因为没有考虑翻班格式(就是做几休几)
  394 + // 所有翻班格式全由时刻表决定,即时刻表有的路牌就做,没有不做
  395 + continue;
302 396 }
303   - }
304   - if (StringUtils.isNotEmpty(gsbm) && StringUtils.isNotEmpty(fgsbm)) {
305   - Iterator<Business> businessIterator2 = businessRepository.findByUpCodeAndBusinessCode(gsbm, fgsbm).iterator();
306   - if (businessIterator2.hasNext()) {
307   - fgs = (Business) businessIterator2.next();
308   - }
309   - }
310 397  
311   - if (gs != null) {
312   - schedulePlanInfo.setGsBm(gs.getBusinessCode());
313   - schedulePlanInfo.setGsName(gs.getBusinessName());
314   - }
315   - if (fgs != null) {
316   - schedulePlanInfo.setFgsBm(fgs.getBusinessCode());
317   - schedulePlanInfo.setFgsName(fgs.getBusinessName());
318   - }
  398 + for (int j = 0; j < detaillist.size(); j++) {
  399 + TTInfoDetail_Wrap wrap = (TTInfoDetail_Wrap) detaillist.get(j);
  400 +
  401 + SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo(
  402 + xl,
  403 + sro,
  404 + wrap.getSelf(),
  405 + wrap.getIsFb(),
  406 + carConfigInfo,
  407 + eclist,
  408 + $param.getSchedulePlan(),
  409 + wrap.getIsFirstBc(),
  410 + wrap.getIsLastBc()
  411 + );
  412 +
  413 + // 获取公司,分公司信息
  414 + String gsbm = xl.getCompany();
  415 + String fgsbm = xl.getBrancheCompany();
  416 + Business gs = null;
  417 + Business fgs = null;
  418 +
  419 + if (StringUtils.isNotEmpty(gsbm)) {
  420 + gs = (Business) gsMap.get(gsbm);
  421 + }
  422 + if (StringUtils.isNotEmpty(gsbm) && StringUtils.isNotEmpty(fgsbm)) {
  423 + fgs = (Business) fgsMap.get(gsbm + "_" + fgsbm);
  424 + }
  425 +
  426 + if (gs != null) {
  427 + schedulePlanInfo.setGsBm(gs.getBusinessCode());
  428 + schedulePlanInfo.setGsName(gs.getBusinessName());
  429 + }
  430 + if (fgs != null) {
  431 + schedulePlanInfo.setFgsBm(fgs.getBusinessCode());
  432 + schedulePlanInfo.setFgsName(fgs.getBusinessName());
  433 + }
  434 +
  435 + // 操作人,操作时间
  436 + schedulePlanInfo.setCreateBy($param.getSchedulePlan().getCreateBy());
  437 + schedulePlanInfo.setCreateDate($param.getSchedulePlan().getCreateDate());
  438 + schedulePlanInfo.setUpdateBy($param.getSchedulePlan().getUpdateBy());
  439 + schedulePlanInfo.setUpdateDate($param.getSchedulePlan().getUpdateDate());
  440 +
  441 + // result 输出
  442 + planResult.getSchedulePlanInfos().add(schedulePlanInfo);
319 443  
320   - // 操作人,操作时间
321   - schedulePlanInfo.setCreateBy($param.getSchedulePlan().getCreateBy());
322   - schedulePlanInfo.setCreateDate($param.getSchedulePlan().getCreateDate());
323   - schedulePlanInfo.setUpdateBy($param.getSchedulePlan().getUpdateBy());
324   - schedulePlanInfo.setUpdateDate($param.getSchedulePlan().getUpdateDate());
  444 + }
325 445  
326   - // result 输出
327   - planResult.getSchedulePlanInfos().add(schedulePlanInfo);
  446 + }
328 447  
329   - log.info("gid={},ecid={},ttInfoId={}",
330   - $gid, ecList(employeeConfigInfoRepository, $sro.getEmployeeConfigId()),
331   - ttInfoId_sd($lr.getTtInfoMapLoop(), $sd));
  448 + log.info("xlid={} plan ok!", $xlId);
332 449  
333 450 end
334 451  
... ... @@ -345,4 +462,3 @@ end
345 462  
346 463  
347 464  
348   -
... ...
src/test/resources/testdata/problem.txt 0 → 100644
  1 +1、时刻表明细导入,线路标准里所有的高峰低谷时间需要带入时刻表班次时间里,标准可以点击切换到线路标准界面
  2 +2、时刻表明细编辑功能,数据工具移到时刻表里,类似工具栏的样子
  3 +3、时刻表导入,可以选一个已经存在的时刻表导入,而不是excel文件
  4 +4、所有的删除,作废,都要有提示框操作
  5 +5、排班计划错误提示,如果选的排班日期之前没有排班,提示错误,排班结果有重复与时刻表不符合,显示错误
  6 +6、调度执行日报,显示最近排班日期,修改操作强化
  7 +7、警告功能,如时刻表选择相同的常规有效日,特殊有效日,车辆,人员配置重复等等
  8 +8、时刻表明细编辑,颜色覆盖冲突
  9 +9、下拉框貌似中文不能搜索
  10 +10、时刻表明细编辑,环线,选上下行,上下的站点在下行站点列表里
  11 +11、人员基础信息导入问题,工号前要加公司代码
0 12 \ No newline at end of file
... ...