Commit 6a5549cf8fa4ecbb276ed86109bccc33669d4c99
1 parent
43b6ac5d
Update
Showing
7 changed files
with
561 additions
and
234 deletions
src/main/java/com/bsth/repository/schedule/SchedulePlanInfoRepository.java
| ... | ... | @@ -49,7 +49,7 @@ public interface SchedulePlanInfoRepository extends BaseRepository<SchedulePlanI |
| 49 | 49 | "where info.xl = ?1 and " + |
| 50 | 50 | "info.schedule_date = ?2 " + |
| 51 | 51 | "group by info.xl_name, info.schedule_date, info.lp, info.lp_name, info.cl, info.cl_zbh " + |
| 52 | - "order by info.xl_name, info.schedule_date, info.lp ", nativeQuery = true) | |
| 52 | + "order by info.xl_name, info.schedule_date, info.lp, info.fcno ", nativeQuery = true) | |
| 53 | 53 | List<Object[]> findGroupInfo(Integer xlid, Date scheduleDate); |
| 54 | 54 | |
| 55 | 55 | @Modifying | ... | ... |
src/main/java/com/bsth/service/schedule/impl/SchedulePlanServiceImpl.java
| 1 | 1 | package com.bsth.service.schedule.impl; |
| 2 | 2 | |
| 3 | -import com.bsth.entity.Business; | |
| 4 | 3 | import com.bsth.entity.Line; |
| 5 | -import com.bsth.entity.schedule.*; | |
| 4 | +import com.bsth.entity.schedule.SchedulePlan; | |
| 5 | +import com.bsth.entity.schedule.TTInfo; | |
| 6 | 6 | import com.bsth.entity.schedule.rule.ScheduleRule1Flat; |
| 7 | 7 | import com.bsth.repository.schedule.SchedulePlanInfoRepository; |
| 8 | 8 | import com.bsth.repository.schedule.SchedulePlanRepository; |
| ... | ... | @@ -12,7 +12,6 @@ import com.bsth.service.schedule.*; |
| 12 | 12 | import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input; |
| 13 | 13 | import com.bsth.service.schedule.rules.plan.PlanResult; |
| 14 | 14 | import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input; |
| 15 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output; | |
| 16 | 15 | import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; |
| 17 | 16 | import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input; |
| 18 | 17 | import com.bsth.service.schedule.rules.strategy.IStrategy; |
| ... | ... | @@ -21,8 +20,6 @@ import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output; |
| 21 | 20 | import com.bsth.service.schedule.rules.ttinfo.TTInfo_input; |
| 22 | 21 | import com.bsth.service.schedule.rules.ttinfo2.CalcuParam; |
| 23 | 22 | import com.bsth.service.schedule.rules.ttinfo2.Result; |
| 24 | -import com.google.common.collect.Multimap; | |
| 25 | -import org.apache.commons.lang3.StringUtils; | |
| 26 | 23 | import org.joda.time.DateTime; |
| 27 | 24 | import org.kie.api.KieBase; |
| 28 | 25 | import org.kie.api.runtime.KieSession; |
| ... | ... | @@ -209,6 +206,8 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im |
| 209 | 206 | session.setGlobal("tTInfoDetailService", ttInfoDetailService); |
| 210 | 207 | session.setGlobal("carConfigInfoService", carConfigInfoService); |
| 211 | 208 | session.setGlobal("employeeConfigInfoService", employeeConfigInfoService); |
| 209 | + session.setGlobal("lineService", lineService); | |
| 210 | + session.setGlobal("businessService", businessService); | |
| 212 | 211 | session.setGlobal("log", logger); // 设置日志 |
| 213 | 212 | |
| 214 | 213 | // 载入数据 |
| ... | ... | @@ -233,168 +232,177 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im |
| 233 | 232 | // 3、计划输出 |
| 234 | 233 | PlanResult planResult = planResultOutput(schedulePlan, scheduleResults_output, ttInfoResults_output); |
| 235 | 234 | |
| 236 | - // TODO: | |
| 235 | + schedulePlan.getSchedulePlanInfoList().addAll(planResult.getSchedulePlanInfos()); | |
| 236 | + schedulePlan.setTtInfoId("todo"); // TODO:待修正 | |
| 237 | + schedulePlan.setTtInfoNames("todo"); // TODO:待修正 | |
| 238 | + | |
| 239 | + super.save(schedulePlan); | |
| 237 | 240 | |
| 238 | 241 | return new SchedulePlan(); |
| 239 | 242 | } |
| 240 | 243 | |
| 241 | 244 | @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) |
| 242 | 245 | public SchedulePlan save(SchedulePlan schedulePlan) { |
| 243 | - // 测试 | |
| 244 | -// return save2(schedulePlan); | |
| 245 | - | |
| 246 | - // 1-1、查找线路具体信息 | |
| 247 | - Line xl = strategy.getLine(schedulePlan.getXl().getId()); | |
| 248 | - // 1-2、查出指定线路的所有规则 | |
| 249 | - TTInfo ttInfo = strategy.getTTInfo(xl.getId()).get(0); // 时刻表id | |
| 250 | - schedulePlan.setTtInfo(ttInfo); // TODO:关联的时刻表,之后改掉 | |
| 251 | - | |
| 252 | - // 2-1、构造drools规则输入数据,输出数据 | |
| 253 | - // 全局计算参数 | |
| 254 | - ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input(schedulePlan); | |
| 255 | - // 每个规则对应的输入参数 | |
| 256 | - List<ScheduleRule_input> scheduleRule_inputs = new ArrayList<>(); | |
| 257 | - Iterator<ScheduleRule1Flat> scheduleRule1FlatIterator = strategy.getScheduleRule(xl.getId()).iterator(); | |
| 258 | - while (scheduleRule1FlatIterator.hasNext()) { | |
| 259 | - ScheduleRule1Flat scheduleRule1Flat_temp = scheduleRule1FlatIterator.next(); | |
| 260 | - ScheduleRule_input scheduleRule_input = new ScheduleRule_input(scheduleRule1Flat_temp); | |
| 261 | - scheduleRule_inputs.add(scheduleRule_input); | |
| 262 | - } | |
| 263 | - // 规则输出数据 | |
| 264 | - ScheduleResults_output scheduleResults_output = new ScheduleResults_output(); | |
| 265 | - | |
| 266 | - // 2-2、构造drools session->载入数据->启动规则->计算->销毁session | |
| 267 | - // 创建session,内部配置的是stateful | |
| 268 | - KieSession session = kieBase.newKieSession(); | |
| 269 | - // 设置gloable对象,在drl中通过别名使用 | |
| 270 | - session.setGlobal("scheduleResult", scheduleResults_output); | |
| 271 | - session.setGlobal("log", logger); // 设置日志 | |
| 272 | - | |
| 273 | - // 载入数据 | |
| 274 | - session.insert(scheduleCalcuParam_input); | |
| 275 | - for (ScheduleRule_input scheduleRule_input : scheduleRule_inputs) { | |
| 276 | - session.insert(scheduleRule_input); | |
| 277 | - } | |
| 278 | - // 执行rule | |
| 279 | - session.fireAllRules(); | |
| 280 | - | |
| 281 | - // 执行完毕销毁,有日志的也要关闭 | |
| 282 | - session.dispose(); | |
| 283 | - | |
| 284 | - System.out.println(scheduleResults_output.showGuideboardDesc1()); | |
| 285 | - | |
| 286 | 246 | // 2-3、如果排班的数据之前已经有了,删除之前的数据 |
| 287 | 247 | schedulePlanInfoRepository.deleteByXlAndScheduleDateGreaterThanEqualAndScheduleDateLessThanEqual( |
| 288 | - xl.getId(), schedulePlan.getScheduleFromTime(), schedulePlan.getScheduleToTime() | |
| 248 | + schedulePlan.getXl().getId(), schedulePlan.getScheduleFromTime(), schedulePlan.getScheduleToTime() | |
| 289 | 249 | ); |
| 290 | 250 | |
| 291 | - // 3、根据规则返回,组合最后的输出数据 | |
| 292 | - // 3-1、根据注入的策略服务,获取原始数据 | |
| 293 | - Map<Date, Multimap<Long, TTInfoDetail>> gbdTTinfoMaps = strategy.getGuideboardXlTTInfoDetailMaps( | |
| 294 | - xl.getId(), schedulePlan.getScheduleFromTime(), schedulePlan.getScheduleToTime()); | |
| 295 | - | |
| 296 | - Map<Long, CarConfigInfo> carConfigMaps = strategy.getCarConfigMaps(xl.getId()); // 车辆配置对应车辆信息 | |
| 297 | - Map<Long, EmployeeConfigInfo> employeeConfigMaps = strategy.getEmployeeConfigMaps(xl.getId()); // 人员配置对应的人员信息 | |
| 298 | - | |
| 299 | - // 3-2、循环规则输出 | |
| 300 | - Map<Long, String> ttInfoMap = new HashMap<>(); // 时刻表映射,id和名字 | |
| 301 | - List<SchedulePlanInfo> schedulePlanInfos = new ArrayList<>(); | |
| 302 | - for (ScheduleResult_output scheduleResult_output : scheduleResults_output.getResults()) { | |
| 303 | - // 车辆配置对应的车辆 | |
| 304 | - CarConfigInfo configInfo = carConfigMaps.get(Long.valueOf(scheduleResult_output.getCarConfigId())); | |
| 305 | - // 人员配置对应的人员,这里需要分班处理的 | |
| 306 | - List<EmployeeConfigInfo> employeeConfigInfoList = new ArrayList<>(); | |
| 307 | - String[] eids = scheduleResult_output.getEmployeeConfigId().split("-"); | |
| 308 | - for (String eid : eids) { | |
| 309 | - employeeConfigInfoList.add(employeeConfigMaps.get(Long.valueOf(eid))); | |
| 310 | - } | |
| 311 | - // 排班明细(这个要迭代的) | |
| 312 | - Collection<TTInfoDetail> ttInfoDetails_ = gbdTTinfoMaps.get(scheduleResult_output.getSd().toDate()).get( | |
| 313 | - Long.parseLong(scheduleResult_output.getGuideboardId())); | |
| 314 | - List<TTInfoDetail> ttInfoDetails = new ArrayList<>(ttInfoDetails_); | |
| 315 | - | |
| 316 | - // 排序ttInfoDetails | |
| 317 | - Collections.sort(ttInfoDetails, new Comparator<TTInfoDetail>() { | |
| 318 | - @Override | |
| 319 | - public int compare(TTInfoDetail o1, TTInfoDetail o2) { | |
| 320 | - return o1.getFcno().compareTo(o2.getFcno()); | |
| 321 | - } | |
| 322 | - }); | |
| 323 | - | |
| 324 | - Boolean isFb = false; // 是否分班 | |
| 325 | - for (int i = 0; i < ttInfoDetails.size(); i++) { | |
| 326 | - TTInfoDetail ttInfoDetail = ttInfoDetails.get(i); | |
| 327 | - | |
| 328 | - if (ttInfoDetail.getIsFB()) | |
| 329 | - isFb = ttInfoDetail.getIsFB(); | |
| 330 | - | |
| 331 | - SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo( | |
| 332 | - xl, | |
| 333 | - scheduleResult_output, | |
| 334 | - ttInfoDetail, | |
| 335 | - isFb, | |
| 336 | - configInfo, | |
| 337 | - employeeConfigInfoList, | |
| 338 | - schedulePlan, | |
| 339 | - i == 0, | |
| 340 | - i == ttInfoDetails.size() - 1); | |
| 341 | - | |
| 342 | - // 获取公司,分公司信息 | |
| 343 | - String gsbm = xl.getCompany(); | |
| 344 | - String fgsbm = xl.getBrancheCompany(); | |
| 345 | - Business gs = null; | |
| 346 | - Business fgs = null; | |
| 347 | - | |
| 348 | - Map<String, Object> param = new HashMap<>(); | |
| 349 | - | |
| 350 | - if (StringUtils.isNotEmpty(gsbm)) { | |
| 351 | - param.clear(); | |
| 352 | - param.put("businessCode_eq", gsbm); | |
| 353 | - Iterator<Business> businessIterator = businessService.list(param).iterator(); | |
| 354 | - if (businessIterator.hasNext()) { | |
| 355 | - gs = businessIterator.next(); | |
| 356 | - } | |
| 357 | - } | |
| 358 | - if (StringUtils.isNotEmpty(gsbm) && StringUtils.isNotEmpty(fgsbm)) { | |
| 359 | - param.clear();; | |
| 360 | - param.put("upCode_eq", gsbm); | |
| 361 | - param.put("businessCode_eq", fgsbm); | |
| 362 | - Iterator<Business> businessIterator = businessService.list(param).iterator(); | |
| 363 | - if (businessIterator.hasNext()) { | |
| 364 | - fgs = businessIterator.next(); | |
| 365 | - } | |
| 366 | - } | |
| 367 | - | |
| 368 | - if (gs != null) { | |
| 369 | - schedulePlanInfo.setGsBm(gs.getBusinessCode()); | |
| 370 | - schedulePlanInfo.setGsName(gs.getBusinessName()); | |
| 371 | - } | |
| 372 | - if (fgs != null) { | |
| 373 | - schedulePlanInfo.setFgsBm(fgs.getBusinessCode()); | |
| 374 | - schedulePlanInfo.setFgsName(fgs.getBusinessName()); | |
| 375 | - } | |
| 376 | - | |
| 377 | - // 操作人,操作时间 | |
| 378 | - schedulePlanInfo.setCreateBy(schedulePlan.getCreateBy()); | |
| 379 | - schedulePlanInfo.setCreateDate(schedulePlan.getCreateDate()); | |
| 380 | - schedulePlanInfo.setUpdateBy(schedulePlan.getUpdateBy()); | |
| 381 | - schedulePlanInfo.setUpdateDate(schedulePlan.getUpdateDate()); | |
| 382 | - | |
| 383 | - schedulePlanInfos.add(schedulePlanInfo); | |
| 384 | - ttInfoMap.put(ttInfoDetail.getTtinfo().getId(), ttInfoDetail.getTtinfo().getName()); | |
| 385 | - | |
| 386 | - } | |
| 387 | - | |
| 388 | - } | |
| 389 | - | |
| 390 | - schedulePlan.setTtInfoId(StringUtils.join(ttInfoMap.keySet(), ",")); | |
| 391 | - schedulePlan.setTtInfoNames(StringUtils.join(ttInfoMap.values(), ",")); | |
| 392 | - | |
| 393 | - // 3-2、保存生成的排班和明细 | |
| 394 | - schedulePlan.getSchedulePlanInfoList().addAll(schedulePlanInfos); // 关联的排班明细信息 | |
| 395 | - super.save(schedulePlan); | |
| 396 | - | |
| 397 | - return new SchedulePlan(); | |
| 251 | + // 测试 | |
| 252 | + return save2(schedulePlan); | |
| 253 | + | |
| 254 | +// // 1-1、查找线路具体信息 | |
| 255 | +// Line xl = strategy.getLine(schedulePlan.getXl().getId()); | |
| 256 | +// // 1-2、查出指定线路的所有规则 | |
| 257 | +// TTInfo ttInfo = strategy.getTTInfo(xl.getId()).get(0); // 时刻表id | |
| 258 | +// schedulePlan.setTtInfo(ttInfo); // TODO:关联的时刻表,之后改掉 | |
| 259 | +// | |
| 260 | +// // 2-1、构造drools规则输入数据,输出数据 | |
| 261 | +// // 全局计算参数 | |
| 262 | +// ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input(schedulePlan); | |
| 263 | +// // 每个规则对应的输入参数 | |
| 264 | +// List<ScheduleRule_input> scheduleRule_inputs = new ArrayList<>(); | |
| 265 | +// Iterator<ScheduleRule1Flat> scheduleRule1FlatIterator = strategy.getScheduleRule(xl.getId()).iterator(); | |
| 266 | +// while (scheduleRule1FlatIterator.hasNext()) { | |
| 267 | +// ScheduleRule1Flat scheduleRule1Flat_temp = scheduleRule1FlatIterator.next(); | |
| 268 | +// ScheduleRule_input scheduleRule_input = new ScheduleRule_input(scheduleRule1Flat_temp); | |
| 269 | +// scheduleRule_inputs.add(scheduleRule_input); | |
| 270 | +// } | |
| 271 | +// // 规则输出数据 | |
| 272 | +// ScheduleResults_output scheduleResults_output = new ScheduleResults_output(); | |
| 273 | +// | |
| 274 | +// // 2-2、构造drools session->载入数据->启动规则->计算->销毁session | |
| 275 | +// // 创建session,内部配置的是stateful | |
| 276 | +// KieSession session = kieBase.newKieSession(); | |
| 277 | +// // 设置gloable对象,在drl中通过别名使用 | |
| 278 | +// session.setGlobal("scheduleResult", scheduleResults_output); | |
| 279 | +// session.setGlobal("log", logger); // 设置日志 | |
| 280 | +// | |
| 281 | +// // 载入数据 | |
| 282 | +// session.insert(scheduleCalcuParam_input); | |
| 283 | +// for (ScheduleRule_input scheduleRule_input : scheduleRule_inputs) { | |
| 284 | +// session.insert(scheduleRule_input); | |
| 285 | +// } | |
| 286 | +// // 执行rule | |
| 287 | +// session.fireAllRules(); | |
| 288 | +// | |
| 289 | +// // 执行完毕销毁,有日志的也要关闭 | |
| 290 | +// session.dispose(); | |
| 291 | +// | |
| 292 | +// System.out.println(scheduleResults_output.showGuideboardDesc1()); | |
| 293 | +// | |
| 294 | +// // 2-3、如果排班的数据之前已经有了,删除之前的数据 | |
| 295 | +// schedulePlanInfoRepository.deleteByXlAndScheduleDateGreaterThanEqualAndScheduleDateLessThanEqual( | |
| 296 | +// xl.getId(), schedulePlan.getScheduleFromTime(), schedulePlan.getScheduleToTime() | |
| 297 | +// ); | |
| 298 | +// | |
| 299 | +// // 3、根据规则返回,组合最后的输出数据 | |
| 300 | +// // 3-1、根据注入的策略服务,获取原始数据 | |
| 301 | +// Map<Date, Multimap<Long, TTInfoDetail>> gbdTTinfoMaps = strategy.getGuideboardXlTTInfoDetailMaps( | |
| 302 | +// xl.getId(), schedulePlan.getScheduleFromTime(), schedulePlan.getScheduleToTime()); | |
| 303 | +// | |
| 304 | +// Map<Long, CarConfigInfo> carConfigMaps = strategy.getCarConfigMaps(xl.getId()); // 车辆配置对应车辆信息 | |
| 305 | +// Map<Long, EmployeeConfigInfo> employeeConfigMaps = strategy.getEmployeeConfigMaps(xl.getId()); // 人员配置对应的人员信息 | |
| 306 | +// | |
| 307 | +// // 3-2、循环规则输出 | |
| 308 | +// Map<Long, String> ttInfoMap = new HashMap<>(); // 时刻表映射,id和名字 | |
| 309 | +// List<SchedulePlanInfo> schedulePlanInfos = new ArrayList<>(); | |
| 310 | +// for (ScheduleResult_output scheduleResult_output : scheduleResults_output.getResults()) { | |
| 311 | +// // 车辆配置对应的车辆 | |
| 312 | +// CarConfigInfo configInfo = carConfigMaps.get(Long.valueOf(scheduleResult_output.getCarConfigId())); | |
| 313 | +// // 人员配置对应的人员,这里需要分班处理的 | |
| 314 | +// List<EmployeeConfigInfo> employeeConfigInfoList = new ArrayList<>(); | |
| 315 | +// String[] eids = scheduleResult_output.getEmployeeConfigId().split("-"); | |
| 316 | +// for (String eid : eids) { | |
| 317 | +// employeeConfigInfoList.add(employeeConfigMaps.get(Long.valueOf(eid))); | |
| 318 | +// } | |
| 319 | +// // 排班明细(这个要迭代的) | |
| 320 | +// Collection<TTInfoDetail> ttInfoDetails_ = gbdTTinfoMaps.get(scheduleResult_output.getSd().toDate()).get( | |
| 321 | +// Long.parseLong(scheduleResult_output.getGuideboardId())); | |
| 322 | +// List<TTInfoDetail> ttInfoDetails = new ArrayList<>(ttInfoDetails_); | |
| 323 | +// | |
| 324 | +// // 排序ttInfoDetails | |
| 325 | +// Collections.sort(ttInfoDetails, new Comparator<TTInfoDetail>() { | |
| 326 | +// @Override | |
| 327 | +// public int compare(TTInfoDetail o1, TTInfoDetail o2) { | |
| 328 | +// return o1.getFcno().compareTo(o2.getFcno()); | |
| 329 | +// } | |
| 330 | +// }); | |
| 331 | +// | |
| 332 | +// Boolean isFb = false; // 是否分班 | |
| 333 | +// for (int i = 0; i < ttInfoDetails.size(); i++) { | |
| 334 | +// TTInfoDetail ttInfoDetail = ttInfoDetails.get(i); | |
| 335 | +// | |
| 336 | +// if (ttInfoDetail.getIsFB()) | |
| 337 | +// isFb = ttInfoDetail.getIsFB(); | |
| 338 | +// | |
| 339 | +// SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo( | |
| 340 | +// xl, | |
| 341 | +// scheduleResult_output, | |
| 342 | +// ttInfoDetail, | |
| 343 | +// isFb, | |
| 344 | +// configInfo, | |
| 345 | +// employeeConfigInfoList, | |
| 346 | +// schedulePlan, | |
| 347 | +// i == 0, | |
| 348 | +// i == ttInfoDetails.size() - 1); | |
| 349 | +// | |
| 350 | +// // 获取公司,分公司信息 | |
| 351 | +// String gsbm = xl.getCompany(); | |
| 352 | +// String fgsbm = xl.getBrancheCompany(); | |
| 353 | +// Business gs = null; | |
| 354 | +// Business fgs = null; | |
| 355 | +// | |
| 356 | +// Map<String, Object> param = new HashMap<>(); | |
| 357 | +// | |
| 358 | +// if (StringUtils.isNotEmpty(gsbm)) { | |
| 359 | +// param.clear(); | |
| 360 | +// param.put("businessCode_eq", gsbm); | |
| 361 | +// Iterator<Business> businessIterator = businessService.list(param).iterator(); | |
| 362 | +// if (businessIterator.hasNext()) { | |
| 363 | +// gs = businessIterator.next(); | |
| 364 | +// } | |
| 365 | +// } | |
| 366 | +// if (StringUtils.isNotEmpty(gsbm) && StringUtils.isNotEmpty(fgsbm)) { | |
| 367 | +// param.clear();; | |
| 368 | +// param.put("upCode_eq", gsbm); | |
| 369 | +// param.put("businessCode_eq", fgsbm); | |
| 370 | +// Iterator<Business> businessIterator = businessService.list(param).iterator(); | |
| 371 | +// if (businessIterator.hasNext()) { | |
| 372 | +// fgs = businessIterator.next(); | |
| 373 | +// } | |
| 374 | +// } | |
| 375 | +// | |
| 376 | +// if (gs != null) { | |
| 377 | +// schedulePlanInfo.setGsBm(gs.getBusinessCode()); | |
| 378 | +// schedulePlanInfo.setGsName(gs.getBusinessName()); | |
| 379 | +// } | |
| 380 | +// if (fgs != null) { | |
| 381 | +// schedulePlanInfo.setFgsBm(fgs.getBusinessCode()); | |
| 382 | +// schedulePlanInfo.setFgsName(fgs.getBusinessName()); | |
| 383 | +// } | |
| 384 | +// | |
| 385 | +// // 操作人,操作时间 | |
| 386 | +// schedulePlanInfo.setCreateBy(schedulePlan.getCreateBy()); | |
| 387 | +// schedulePlanInfo.setCreateDate(schedulePlan.getCreateDate()); | |
| 388 | +// schedulePlanInfo.setUpdateBy(schedulePlan.getUpdateBy()); | |
| 389 | +// schedulePlanInfo.setUpdateDate(schedulePlan.getUpdateDate()); | |
| 390 | +// | |
| 391 | +// schedulePlanInfos.add(schedulePlanInfo); | |
| 392 | +// ttInfoMap.put(ttInfoDetail.getTtinfo().getId(), ttInfoDetail.getTtinfo().getName()); | |
| 393 | +// | |
| 394 | +// } | |
| 395 | +// | |
| 396 | +// } | |
| 397 | +// | |
| 398 | +// schedulePlan.setTtInfoId(StringUtils.join(ttInfoMap.keySet(), ",")); | |
| 399 | +// schedulePlan.setTtInfoNames(StringUtils.join(ttInfoMap.values(), ",")); | |
| 400 | +// | |
| 401 | +// // 3-2、保存生成的排班和明细 | |
| 402 | +// schedulePlan.getSchedulePlanInfoList().addAll(schedulePlanInfos); // 关联的排班明细信息 | |
| 403 | +// super.save(schedulePlan); | |
| 404 | +// | |
| 405 | +// return new SchedulePlan(); | |
| 398 | 406 | } |
| 399 | 407 | |
| 400 | 408 | @Override | ... | ... |
src/main/java/com/bsth/service/schedule/rules/plan/PlanCalcuParam_input.java
| ... | ... | @@ -8,8 +8,10 @@ import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output; |
| 8 | 8 | * 排班规则-规则输入参数。 |
| 9 | 9 | */ |
| 10 | 10 | public class PlanCalcuParam_input { |
| 11 | - /** 线路id */ | |
| 12 | - private Integer xlId; | |
| 11 | + /** 线路Id */ | |
| 12 | + private String xlId; | |
| 13 | + /** 计划主对象 */ | |
| 14 | + private SchedulePlan schedulePlan; | |
| 13 | 15 | /** 循环规则输出 */ |
| 14 | 16 | private ScheduleResults_output scheduleResults_output; |
| 15 | 17 | /** 时刻表选择规则输出 */ |
| ... | ... | @@ -21,16 +23,17 @@ public class PlanCalcuParam_input { |
| 21 | 23 | SchedulePlan schedulePlan, |
| 22 | 24 | ScheduleResults_output scheduleResults_output, |
| 23 | 25 | TTInfoResults_output ttInfoResults_output) { |
| 24 | - this.xlId = schedulePlan.getXl().getId(); | |
| 26 | + this.schedulePlan = schedulePlan; | |
| 27 | + this.xlId = String.valueOf(schedulePlan.getXl().getId()); | |
| 25 | 28 | this.scheduleResults_output = scheduleResults_output; |
| 26 | 29 | this.ttInfoResults_output = ttInfoResults_output; |
| 27 | 30 | } |
| 28 | 31 | |
| 29 | - public Integer getXlId() { | |
| 32 | + public String getXlId() { | |
| 30 | 33 | return xlId; |
| 31 | 34 | } |
| 32 | 35 | |
| 33 | - public void setXlId(Integer xlId) { | |
| 36 | + public void setXlId(String xlId) { | |
| 34 | 37 | this.xlId = xlId; |
| 35 | 38 | } |
| 36 | 39 | |
| ... | ... | @@ -49,4 +52,12 @@ public class PlanCalcuParam_input { |
| 49 | 52 | public void setTtInfoResults_output(TTInfoResults_output ttInfoResults_output) { |
| 50 | 53 | this.ttInfoResults_output = ttInfoResults_output; |
| 51 | 54 | } |
| 55 | + | |
| 56 | + public SchedulePlan getSchedulePlan() { | |
| 57 | + return schedulePlan; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public void setSchedulePlan(SchedulePlan schedulePlan) { | |
| 61 | + this.schedulePlan = schedulePlan; | |
| 62 | + } | |
| 52 | 63 | } | ... | ... |
src/main/java/com/bsth/service/schedule/rules/shiftloop/GidFbTimeFunction.java
0 → 100644
| 1 | +package com.bsth.service.schedule.rules.shiftloop; | |
| 2 | + | |
| 3 | +import com.bsth.entity.schedule.TTInfoDetail; | |
| 4 | +import org.joda.time.LocalTime; | |
| 5 | +import org.joda.time.format.DateTimeFormat; | |
| 6 | +import org.kie.api.runtime.rule.AccumulateFunction; | |
| 7 | + | |
| 8 | +import java.io.*; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 时刻表路牌下的分班时间(起始时间)。 | |
| 12 | + */ | |
| 13 | +public class GidFbTimeFunction implements AccumulateFunction { | |
| 14 | + @Override | |
| 15 | + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | |
| 16 | + } | |
| 17 | + | |
| 18 | + @Override | |
| 19 | + public void writeExternal(ObjectOutput out) throws IOException { | |
| 20 | + } | |
| 21 | + | |
| 22 | + protected static class GidFbTimeData implements Externalizable { | |
| 23 | + public LocalTime fbsj; | |
| 24 | + public String fbsj_str; | |
| 25 | + public TTInfoDetail ttInfoDetail; | |
| 26 | + | |
| 27 | + public GidFbTimeData() {} | |
| 28 | + | |
| 29 | + @Override | |
| 30 | + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | |
| 31 | + fbsj_str = (String) in.readObject(); | |
| 32 | + ttInfoDetail = (TTInfoDetail) in.readObject(); | |
| 33 | + } | |
| 34 | + | |
| 35 | + @Override | |
| 36 | + public void writeExternal(ObjectOutput out) throws IOException { | |
| 37 | + out.writeObject(fbsj_str); | |
| 38 | + out.writeObject(ttInfoDetail); | |
| 39 | + } | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + public Serializable createContext() { | |
| 44 | + return new GidFbTimeData(); | |
| 45 | + } | |
| 46 | + | |
| 47 | + @Override | |
| 48 | + public void init(Serializable context) throws Exception { | |
| 49 | + GidFbTimeData gidFbTimeData = (GidFbTimeData) context; | |
| 50 | + gidFbTimeData.fbsj_str = "NULL"; // 注意:因为空的时间也要规则执行,所以返回一个表示空的字符串 | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + public void accumulate(Serializable context, Object value) { | |
| 55 | + GidFbTimeData gidFbTimeData = (GidFbTimeData) context; | |
| 56 | + TTInfoDetail ttInfoDetail = (TTInfoDetail) value; | |
| 57 | + | |
| 58 | + // 1块路牌有多个分班班次,取最早的时间作为起始分班时间 | |
| 59 | + if (ttInfoDetail.getIsFB()) { | |
| 60 | + LocalTime localTime = LocalTime.parse(ttInfoDetail.getFcsj(), DateTimeFormat.forPattern("HH:mm")); | |
| 61 | + | |
| 62 | + if (gidFbTimeData.fbsj == null) { | |
| 63 | + gidFbTimeData.fbsj = localTime; | |
| 64 | + gidFbTimeData.fbsj_str = ttInfoDetail.getFcsj(); | |
| 65 | + } else if (localTime.isBefore(gidFbTimeData.fbsj)) { | |
| 66 | + gidFbTimeData.fbsj = localTime; | |
| 67 | + gidFbTimeData.fbsj_str = ttInfoDetail.getFcsj(); | |
| 68 | + } | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public void reverse(Serializable serializable, Object o) throws Exception { | |
| 74 | + | |
| 75 | + } | |
| 76 | + | |
| 77 | + @Override | |
| 78 | + public boolean supportsReverse() { | |
| 79 | + return false; | |
| 80 | + } | |
| 81 | + | |
| 82 | + @Override | |
| 83 | + public Class<?> getResultType() { | |
| 84 | + return String.class; | |
| 85 | + } | |
| 86 | + | |
| 87 | + @Override | |
| 88 | + public Object getResult(Serializable context) throws Exception { | |
| 89 | + GidFbTimeData gidFbTimeData = (GidFbTimeData) context; | |
| 90 | + return gidFbTimeData.fbsj_str; | |
| 91 | + } | |
| 92 | +} | ... | ... |
src/main/java/com/bsth/service/schedule/rules/shiftloop/GidsCountFunction.java
0 → 100644
| 1 | +package com.bsth.service.schedule.rules.shiftloop; | |
| 2 | + | |
| 3 | +import com.bsth.entity.schedule.TTInfoDetail; | |
| 4 | +import org.kie.api.runtime.rule.AccumulateFunction; | |
| 5 | + | |
| 6 | +import java.io.*; | |
| 7 | +import java.util.ArrayList; | |
| 8 | +import java.util.HashSet; | |
| 9 | +import java.util.List; | |
| 10 | +import java.util.Set; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 计算时刻表里的路爬列表。 | |
| 14 | + */ | |
| 15 | +public class GidsCountFunction implements AccumulateFunction { | |
| 16 | + @Override | |
| 17 | + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | |
| 18 | + } | |
| 19 | + | |
| 20 | + @Override | |
| 21 | + public void writeExternal(ObjectOutput out) throws IOException { | |
| 22 | + } | |
| 23 | + | |
| 24 | + protected static class GidsCountData implements Externalizable { | |
| 25 | + public List<String> gids = new ArrayList<>(); | |
| 26 | + public Set<String> gids_temp = new HashSet<>(); | |
| 27 | + public TTInfoDetail ttInfoDetail; | |
| 28 | + | |
| 29 | + public GidsCountData() {} | |
| 30 | + | |
| 31 | + @Override | |
| 32 | + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | |
| 33 | + gids = (List<String>) in.readObject(); | |
| 34 | + ttInfoDetail = (TTInfoDetail) in.readObject(); | |
| 35 | + } | |
| 36 | + | |
| 37 | + @Override | |
| 38 | + public void writeExternal(ObjectOutput out) throws IOException { | |
| 39 | + out.writeObject(gids); | |
| 40 | + out.writeObject(ttInfoDetail); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + | |
| 44 | + @Override | |
| 45 | + public Serializable createContext() { | |
| 46 | + return new GidsCountData(); | |
| 47 | + } | |
| 48 | + | |
| 49 | + @Override | |
| 50 | + public void init(Serializable context) throws Exception { | |
| 51 | + GidsCountData gidsCountData = (GidsCountData) context; | |
| 52 | + gidsCountData.gids = new ArrayList<>(); | |
| 53 | + gidsCountData.gids_temp = new HashSet<>(); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @Override | |
| 57 | + public void accumulate(Serializable context, Object value) { | |
| 58 | + GidsCountData gidsCountData = (GidsCountData) context; | |
| 59 | + TTInfoDetail ttInfoDetail = (TTInfoDetail) value; | |
| 60 | + | |
| 61 | + if (ttInfoDetail.getLp() != null) { | |
| 62 | + gidsCountData.gids_temp.add( | |
| 63 | + String.valueOf(ttInfoDetail.getLp().getId())); | |
| 64 | + gidsCountData.gids.clear(); | |
| 65 | + gidsCountData.gids.addAll(gidsCountData.gids_temp); | |
| 66 | + } | |
| 67 | + | |
| 68 | + // TODO:以后还需要按照路牌排序 | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public void reverse(Serializable serializable, Object o) throws Exception { | |
| 73 | + | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 77 | + public boolean supportsReverse() { | |
| 78 | + return false; | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + public Object getResult(Serializable context) throws Exception { | |
| 83 | + GidsCountData gidsCountData = (GidsCountData) context; | |
| 84 | + return gidsCountData.gids; | |
| 85 | + | |
| 86 | + } | |
| 87 | + | |
| 88 | + @Override | |
| 89 | + public Class<?> getResultType() { | |
| 90 | + return List.class; | |
| 91 | + } | |
| 92 | +} | ... | ... |
src/main/resources/rules/functions.drl
| 1 | 1 | package com.bsth.service.schedule; |
| 2 | 2 | |
| 3 | -import accumulate com.bsth.service.schedule.rules.ttinfo2.ErrorBcCountFunction ecount; | |
| 4 | 3 | \ No newline at end of file |
| 4 | +import accumulate com.bsth.service.schedule.rules.ttinfo2.ErrorBcCountFunction ecount; | |
| 5 | +import accumulate com.bsth.service.schedule.rules.shiftloop.GidsCountFunction gidscount; | |
| 6 | +import accumulate com.bsth.service.schedule.rules.shiftloop.GidFbTimeFunction gidfbtime; | |
| 5 | 7 | \ No newline at end of file | ... | ... |
src/main/resources/rules/plan.drl
| ... | ... | @@ -10,10 +10,15 @@ import com.bsth.service.schedule.TTInfoService; |
| 10 | 10 | import com.bsth.service.schedule.TTInfoDetailService; |
| 11 | 11 | import com.bsth.service.schedule.CarConfigInfoService; |
| 12 | 12 | import com.bsth.service.schedule.EmployeeConfigInfoService; |
| 13 | +import com.bsth.service.LineService; | |
| 14 | +import com.bsth.service.BusinessService; | |
| 15 | + | |
| 13 | 16 | import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output; |
| 14 | 17 | import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; |
| 15 | 18 | import com.bsth.service.schedule.rules.ttinfo.TTInfoResult_output; |
| 16 | 19 | import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output; |
| 20 | +import com.bsth.entity.Line; | |
| 21 | +import com.bsth.entity.Business; | |
| 17 | 22 | |
| 18 | 23 | import com.bsth.entity.schedule.CarConfigInfo; |
| 19 | 24 | import com.bsth.entity.schedule.EmployeeConfigInfo; |
| ... | ... | @@ -21,7 +26,9 @@ import com.bsth.entity.schedule.TTInfo; |
| 21 | 26 | import com.bsth.entity.schedule.TTInfoDetail; |
| 22 | 27 | import com.bsth.entity.schedule.SchedulePlanInfo; |
| 23 | 28 | |
| 24 | -import org.slf4j.Logger; | |
| 29 | +import org.slf4j.Logger | |
| 30 | +import org.joda.time.format.DateTimeFormat | |
| 31 | +import org.apache.commons.lang3.StringUtils; | |
| 25 | 32 | |
| 26 | 33 | |
| 27 | 34 | // 全局日志类(一般使用调用此规则的service类) |
| ... | ... | @@ -30,6 +37,8 @@ global TTInfoDetailService tTInfoDetailService; |
| 30 | 37 | global TTInfoService tTInfoService; |
| 31 | 38 | global CarConfigInfoService carConfigInfoService; |
| 32 | 39 | global EmployeeConfigInfoService employeeConfigInfoService; |
| 40 | +global LineService lineService; | |
| 41 | +global BusinessService businessService; | |
| 33 | 42 | |
| 34 | 43 | // 输出 |
| 35 | 44 | global PlanResult planResult; |
| ... | ... | @@ -40,24 +49,46 @@ function Map ttidParams(String ttid) { |
| 40 | 49 | return param; |
| 41 | 50 | } |
| 42 | 51 | |
| 43 | -function Map xlidParams(Integer xlid) { | |
| 52 | +function Map xlidParams(String xlid) { | |
| 44 | 53 | Map param = new HashMap(); |
| 45 | - param.put("xl.id_eq", xlid); | |
| 54 | + param.put("xl.id_eq", Integer.valueOf(xlid)); | |
| 46 | 55 | return param; |
| 47 | 56 | } |
| 48 | 57 | |
| 58 | +function List ecList(EmployeeConfigInfoService service, String ecids) { | |
| 59 | + List<String> ids = Arrays.asList(ecids.split("-")); | |
| 60 | + List rst = new ArrayList(); | |
| 61 | + for (int i = 0; i < ids.size(); i++) { | |
| 62 | + rst.add(service.findById(Long.parseLong(ids.get(i)))); | |
| 63 | + } | |
| 64 | + return rst; | |
| 65 | +} | |
| 66 | + | |
| 67 | +function LocalTime fcsjTime(String fcsj) { | |
| 68 | + if ("NULL".equals(fcsj)) { | |
| 69 | + return null; | |
| 70 | + } | |
| 71 | + return LocalTime.parse(fcsj, DateTimeFormat.forPattern("HH:mm")); | |
| 72 | +} | |
| 73 | + | |
| 74 | +function String ttInfoId_sd(Map map, DateTime sd) { | |
| 75 | + TTInfoResult_output ttInfoResult_output = (TTInfoResult_output) map.get(sd); | |
| 76 | + return ttInfoResult_output.getTtInfoId(); | |
| 77 | +} | |
| 78 | + | |
| 49 | 79 | /* |
| 50 | 80 | 规则说明: |
| 51 | - 1、根据循环规则输出,时刻表选择规则输出,计算排班明细 | |
| 81 | + 根据循环规则输出,时刻表选择规则输出,组合计算排班明细 | |
| 52 | 82 | */ |
| 53 | 83 | |
| 54 | 84 | //-------------------- 第一阶段、计算迭代数据 -----------------// |
| 55 | 85 | declare Loop_result |
| 56 | - xlId: Integer // 线路id | |
| 86 | + xlId: String // 线路id | |
| 87 | + | |
| 57 | 88 | ruleLoop: List // 每天分配的规则 List<ScheduleResult_output> |
| 89 | + | |
| 58 | 90 | ttInfoMapLoop_temp: Map // 每天分配的时刻表 Map<DataTime, Collection<TTInfoResult_output>> |
| 59 | 91 | ttInfoMapLoop: Map // 每天分配的时刻表 Map<DataTime, TTInfoResult_output> |
| 60 | - | |
| 61 | 92 | ttInfoMap: Map // 总共用到的时刻表 Map<id, TTInfoResult_output> |
| 62 | 93 | end |
| 63 | 94 | |
| ... | ... | @@ -107,31 +138,7 @@ end |
| 107 | 138 | |
| 108 | 139 | //-------------------- 第二阶段、将时刻表班次,车辆配置,人员配置信息载入 -----------------// |
| 109 | 140 | |
| 110 | -declare TTInfoDetail_Wrap | |
| 111 | - ttInfoId: String // 时刻表id(cast字符串-方便比较) | |
| 112 | - gid: String // 路牌id(cast字符串-方便比较) | |
| 113 | - | |
| 114 | - self: TTInfoDetail // 原始数据 | |
| 115 | -end | |
| 116 | - | |
| 117 | -rule "calcu_TTInfoDetail_Wrap" | |
| 118 | - salience 800 | |
| 119 | - when | |
| 120 | - $lr: Loop_result($xlId: xlId) | |
| 121 | - $ttInfoId: String() from $lr.getTtInfoMap().keySet() | |
| 122 | - $ttInfoDetail: TTInfoDetail() from tTInfoDetailService.list(ttidParams($ttInfoId)) | |
| 123 | - then | |
| 124 | - TTInfoDetail_Wrap ttInfoDetail_wrap = new TTInfoDetail_Wrap(); | |
| 125 | - ttInfoDetail_wrap.setTtInfoId($ttInfoId); | |
| 126 | - ttInfoDetail_wrap.setGid(String.valueOf($ttInfoDetail.getLp().getId())); | |
| 127 | - ttInfoDetail_wrap.setSelf($ttInfoDetail); | |
| 128 | - | |
| 129 | -// log.info("时刻表id={}", $ttInfoId); | |
| 130 | -// log.info("时刻表明细id={}", $ttInfoDetail.getId()); | |
| 131 | - | |
| 132 | - insert(ttInfoDetail_wrap); | |
| 133 | -end | |
| 134 | - | |
| 141 | +//--------------- 车辆配置信息载入 -------------// | |
| 135 | 142 | declare CarConfig_Wrap |
| 136 | 143 | id: String // 车辆配置id(cast字符串-方便比较) |
| 137 | 144 | |
| ... | ... | @@ -151,6 +158,7 @@ rule "calcu_CarConfig_Wrap" |
| 151 | 158 | insert(carConfig_wrap); |
| 152 | 159 | end |
| 153 | 160 | |
| 161 | +//--------------- 人员配置信息载入 --------------// | |
| 154 | 162 | declare EmployeeConfig_Wrap |
| 155 | 163 | id: String // 人员配置id(cast字符串-方便比较) |
| 156 | 164 | |
| ... | ... | @@ -170,56 +178,170 @@ rule "calcu_EmployeeConfig_Wrap" |
| 170 | 178 | insert(employeeConfig_wrap); |
| 171 | 179 | end |
| 172 | 180 | |
| 173 | -declare ScheduleResult_output_Wrap | |
| 174 | - xlId: Integer // 线路id | |
| 175 | - sd: DateTime // 日期 | |
| 176 | - ruleId: String // 规则Id | |
| 177 | - eciIds: List // 人员配置ids | |
| 181 | +//----------------- 时刻表班次信息载入 -----------------// | |
| 182 | +declare TTInfo_gid_stat | |
| 183 | + xlId: String // 线路id(cast字符串-方便比较) | |
| 184 | + ttInfoId: String // 时刻表id(cast字符串-方便比较) | |
| 185 | + gid: String // 路牌id(cast字符串-方便比较) | |
| 178 | 186 | |
| 179 | - self: ScheduleResult_output // 原始数据 | |
| 187 | + maxFcno: Integer // 最大发车顺序号 | |
| 188 | + | |
| 189 | + fbTime: LocalTime // 分班时间 | |
| 180 | 190 | end |
| 181 | 191 | |
| 182 | -rule "calcu_ScheduleResult_output_Wrap" | |
| 192 | +rule "calcu_TTInfo_gid_stat" | |
| 183 | 193 | salience 800 |
| 184 | 194 | when |
| 185 | 195 | $lr: Loop_result($xlId: xlId) |
| 186 | - $sro: ScheduleResult_output() from $lr.getRuleLoop() | |
| 196 | + $ttInfoId: String() from $lr.getTtInfoMap().keySet() | |
| 197 | + $gids: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailService.list(ttidParams($ttInfoId)), gidscount($ttd)) | |
| 198 | + $gid: String() from $gids | |
| 199 | + $fbtime_str: String() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailService.list(ttidParams($ttInfoId)), gidfbtime($ttd)) | |
| 200 | + $maxfcno: Double() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailService.list(ttidParams($ttInfoId)), max($ttd.getFcno())) | |
| 187 | 201 | then |
| 188 | - ScheduleResult_output_Wrap scheduleResult_output_wrap = new ScheduleResult_output_Wrap(); | |
| 189 | - scheduleResult_output_wrap.setXlId($xlId); | |
| 190 | - scheduleResult_output_wrap.setSd($sro.getSd()); | |
| 191 | - scheduleResult_output_wrap.setRuleId($sro.getRuleId()); | |
| 192 | - scheduleResult_output_wrap.setEciIds(Arrays.asList( | |
| 193 | - $sro.getEmployeeConfigId().split("-"))); | |
| 194 | - scheduleResult_output_wrap.setSelf($sro); | |
| 195 | - | |
| 196 | - insert(scheduleResult_output_wrap); | |
| 202 | + TTInfo_gid_stat ttInfo_gid_stat = new TTInfo_gid_stat(); | |
| 203 | + ttInfo_gid_stat.setXlId($xlId); | |
| 204 | + ttInfo_gid_stat.setTtInfoId($ttInfoId); | |
| 205 | + ttInfo_gid_stat.setGid($gid); | |
| 206 | + | |
| 207 | + ttInfo_gid_stat.setMaxFcno($maxfcno.intValue()); | |
| 208 | + ttInfo_gid_stat.setFbTime(fcsjTime($fbtime_str)); | |
| 209 | + | |
| 210 | + insert(ttInfo_gid_stat); | |
| 211 | + | |
| 212 | + log.info("xlid={},ttid={},gid={},maxfcno={},fbtime={}", | |
| 213 | + $xlId, $ttInfoId, $gid, ttInfo_gid_stat.getMaxFcno(), ttInfo_gid_stat.getFbTime()); | |
| 214 | + | |
| 215 | +end | |
| 216 | + | |
| 217 | +declare TTInfoDetail_Wrap | |
| 218 | + xlId: String // 线路id(cast字符串-方便比较) | |
| 219 | + ttInfoId: String // 时刻表id(cast字符串-方便比较) | |
| 220 | + gid: String // 路牌id(cast字符串-方便比较) | |
| 221 | + | |
| 222 | + isFirstBc: Boolean = false // 是否是当前路牌的第一个班次 | |
| 223 | + isLastBc: Boolean = false // 是否是当前路牌的最后一个班次 | |
| 224 | + isFb: Boolean = false // 是否分班 | |
| 225 | + | |
| 226 | + self: TTInfoDetail // 原始数据 | |
| 227 | +end | |
| 228 | + | |
| 229 | +rule "calcu_TTInfoDetail_Wrap" | |
| 230 | + salience 800 | |
| 231 | + when | |
| 232 | + $lr: Loop_result($xlId: xlId) | |
| 233 | + $ttInfoId: String() from $lr.getTtInfoMap().keySet() | |
| 234 | + $ttInfoStat: TTInfo_gid_stat( | |
| 235 | + ttInfoId == $ttInfoId, | |
| 236 | + $gid: gid, $maxFcno: maxFcno) | |
| 237 | + $ttInfoDetail: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailService.list(ttidParams($ttInfoId)) | |
| 238 | + then | |
| 239 | + TTInfoDetail_Wrap ttInfoDetail_wrap = new TTInfoDetail_Wrap(); | |
| 240 | + ttInfoDetail_wrap.setXlId($xlId); | |
| 241 | + ttInfoDetail_wrap.setTtInfoId($ttInfoId); | |
| 242 | + ttInfoDetail_wrap.setGid($gid); | |
| 243 | + ttInfoDetail_wrap.setIsFirstBc(1 == $ttInfoDetail.getFcno()); | |
| 244 | + ttInfoDetail_wrap.setIsLastBc($maxFcno == $ttInfoDetail.getFcno()); | |
| 245 | + | |
| 246 | + LocalTime fcsj = fcsjTime($ttInfoDetail.getFcsj()); | |
| 247 | + LocalTime fbsj = $ttInfoStat.getFbTime(); | |
| 248 | + ttInfoDetail_wrap.setIsFb(fbsj == null ? false : (fcsj.isEqual(fbsj) || fcsj.isAfter(fbsj))); | |
| 249 | + | |
| 250 | + ttInfoDetail_wrap.setSelf($ttInfoDetail); | |
| 251 | + | |
| 252 | + insert(ttInfoDetail_wrap); | |
| 253 | + | |
| 254 | + log.info("xlid={},ttid={},gid={},isFirstBc={},isLastBc={},isFb={},fcsj={}", | |
| 255 | + $xlId, $ttInfoId, $gid, | |
| 256 | + ttInfoDetail_wrap.getIsFirstBc(), | |
| 257 | + ttInfoDetail_wrap.getIsLastBc(), | |
| 258 | + ttInfoDetail_wrap.getIsFb(), | |
| 259 | + $ttInfoDetail.getFcsj()); | |
| 197 | 260 | end |
| 198 | 261 | |
| 199 | 262 | //-------------------- 第三阶段、合并计算SchedulePlanInfo -----------------// |
| 200 | 263 | |
| 201 | -// TODO:暂时不考虑分班 | |
| 202 | - | |
| 203 | -//rule "Calcu_SchedulePlanInfo" | |
| 204 | -// salience 600 | |
| 205 | -// when | |
| 206 | -// $lr: Loop_result($xlId: xlId) | |
| 207 | -// $sro: ScheduleResult_output($sd: sd) from $lr.getRuleLoop() | |
| 208 | -// ScheduleResult_output_Wrap( | |
| 209 | -// xlId == $xlId, sd == $sro.sd, ruleId == $sro.ruleId, | |
| 210 | -// $eciIds: eciIds, $sr: self) | |
| 211 | -// $ecId: String() from $eciIds | |
| 212 | -// CarConfig_Wrap(id == $sro.carConfigId, $cc: self) | |
| 213 | -// EmployeeConfig_Wrap(id == $ecId, $ec: self) | |
| 214 | -// TTInfoDetail_Wrap( | |
| 215 | -// ttInfoId == ((TTInfoResult_output) $lr.getTtInfoMapLoop($sd))., | |
| 216 | -// gid == $sr.guideboardId, | |
| 217 | -// $ttInfoDetail: self | |
| 218 | -// ) | |
| 219 | -// then | |
| 220 | -// log.info("Calcu_SchedulePlanInfo"); | |
| 221 | -// | |
| 222 | -//end | |
| 264 | +rule "Calcu_SchedulePlanInfo" | |
| 265 | + salience 600 | |
| 266 | + when | |
| 267 | + $param: PlanCalcuParam_input($xlId: xlId) | |
| 268 | + $lr: Loop_result(xlId == $xlId) | |
| 269 | + $sro: ScheduleResult_output($sd: sd, $gid: guideboardId) from $lr.getRuleLoop() | |
| 270 | + CarConfig_Wrap(id == $sro.carConfigId, $cc: self) | |
| 271 | + TTInfoDetail_Wrap( | |
| 272 | + ttInfoId == ttInfoId_sd($lr.getTtInfoMapLoop(), $sd), | |
| 273 | + gid == $gid, | |
| 274 | + $isFb: isFb, $isFirstBc: isFirstBc, $isLastBc: isLastBc, | |
| 275 | + $ttInfoDetail: self | |
| 276 | + ) | |
| 277 | + then | |
| 278 | + // 线路 | |
| 279 | + Line xl = lineService.findById(Integer.valueOf($xlId)); | |
| 280 | + | |
| 281 | + SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo( | |
| 282 | + xl, | |
| 283 | + $sro, | |
| 284 | + $ttInfoDetail, | |
| 285 | + $isFb, | |
| 286 | + $cc, | |
| 287 | + ecList(employeeConfigInfoService, $sro.getEmployeeConfigId()), | |
| 288 | + $param.getSchedulePlan(), | |
| 289 | + $isFirstBc, | |
| 290 | + $isLastBc | |
| 291 | + ); | |
| 292 | + | |
| 293 | + // 获取公司,分公司信息 | |
| 294 | + String gsbm = xl.getCompany(); | |
| 295 | + String fgsbm = xl.getBrancheCompany(); | |
| 296 | + Business gs = null; | |
| 297 | + Business fgs = null; | |
| 298 | + | |
| 299 | + Map<String, Object> param = new HashMap<>(); | |
| 300 | + | |
| 301 | + if (StringUtils.isNotEmpty(gsbm)) { | |
| 302 | + param.clear(); | |
| 303 | + param.put("businessCode_eq", gsbm); | |
| 304 | + Iterator<Business> businessIterator = businessService.list(param).iterator(); | |
| 305 | + if (businessIterator.hasNext()) { | |
| 306 | + gs = businessIterator.next(); | |
| 307 | + } | |
| 308 | + } | |
| 309 | + if (StringUtils.isNotEmpty(gsbm) && StringUtils.isNotEmpty(fgsbm)) { | |
| 310 | + param.clear();; | |
| 311 | + param.put("upCode_eq", gsbm); | |
| 312 | + param.put("businessCode_eq", fgsbm); | |
| 313 | + Iterator<Business> businessIterator = businessService.list(param).iterator(); | |
| 314 | + if (businessIterator.hasNext()) { | |
| 315 | + fgs = businessIterator.next(); | |
| 316 | + } | |
| 317 | + } | |
| 318 | + | |
| 319 | + if (gs != null) { | |
| 320 | + schedulePlanInfo.setGsBm(gs.getBusinessCode()); | |
| 321 | + schedulePlanInfo.setGsName(gs.getBusinessName()); | |
| 322 | + } | |
| 323 | + if (fgs != null) { | |
| 324 | + schedulePlanInfo.setFgsBm(fgs.getBusinessCode()); | |
| 325 | + schedulePlanInfo.setFgsName(fgs.getBusinessName()); | |
| 326 | + } | |
| 327 | + | |
| 328 | + // 操作人,操作时间 | |
| 329 | + schedulePlanInfo.setCreateBy($param.getSchedulePlan().getCreateBy()); | |
| 330 | + schedulePlanInfo.setCreateDate($param.getSchedulePlan().getCreateDate()); | |
| 331 | + schedulePlanInfo.setUpdateBy($param.getSchedulePlan().getUpdateBy()); | |
| 332 | + schedulePlanInfo.setUpdateDate($param.getSchedulePlan().getUpdateDate()); | |
| 333 | + | |
| 334 | + // TODO: | |
| 335 | + $param.getSchedulePlan().setTtInfo($ttInfoDetail.getTtinfo()); | |
| 336 | + | |
| 337 | + // result 输出 | |
| 338 | + planResult.getSchedulePlanInfos().add(schedulePlanInfo); | |
| 339 | + | |
| 340 | + log.info("gid={},ecid={},ttInfoId={}", | |
| 341 | + $gid, ecList(employeeConfigInfoService, $sro.getEmployeeConfigId()), | |
| 342 | + ttInfoId_sd($lr.getTtInfoMapLoop(), $sd)); | |
| 343 | + | |
| 344 | +end | |
| 223 | 345 | |
| 224 | 346 | |
| 225 | 347 | ... | ... |