Commit 563a5cbbff074f846c0935179b8172c06ccfea8f

Authored by 潘钊
2 parents edbc2ac2 c1567544

update

src/main/java/com/bsth/repository/oil/YlbRepository.java
... ... @@ -23,8 +23,9 @@ public interface YlbRepository extends BaseRepository<Ylb, Integer>{
23 23 @Modifying
24 24 @Query(value="SELECT a.* FROM bsth_c_ylb a where to_days(?1)-to_days(a.rq)=1"
25 25 + " and jcsx=(select max(b.jcsx) from bsth_c_ylb b where a.nbbm=b.nbbm and "
26   - + " to_days(?1)-to_days(b.rq)=1 )",nativeQuery=true)
27   - List<Ylb> obtainYlbefore(String rq);
  26 + + " to_days(?1)-to_days(b.rq)=1 ) and ssgsdm like %?2% and fgsdm like %?3% and "
  27 + + " xlbm like %?4% and nbbm like %?5% ",nativeQuery=true)
  28 + List<Ylb> obtainYlbefore(String rq,String gsbm,String fgsbm,String xlbm,String nbbm);
28 29  
29 30 /**
30 31 * 当天YLB信息
... ... @@ -50,6 +51,6 @@ public interface YlbRepository extends BaseRepository&lt;Ylb, Integer&gt;{
50 51 */
51 52 @Transactional
52 53 @Modifying
53   - @Query(value="select sum(jzl) as jzl,sum(zlc) as zlc ,sum(sh) as sh from bsth_c_ylb where nbbm=?1 and rq=?2",nativeQuery=true)
54   - List<Object[]> sumLcYl(String nbbm,Date rq);
  54 + @Query(value="select sum(jzl) as jzl,sum(zlc) as zlc ,sum(sh) as sh from bsth_c_ylb where nbbm=?1 and rq=?2 and xlbm like %?3%",nativeQuery=true)
  55 + List<Object[]> sumLcYl(String nbbm,Date rq,String xlbm);
55 56 }
... ...
src/main/java/com/bsth/repository/oil/YlxxbRepository.java
... ... @@ -19,8 +19,8 @@ public interface YlxxbRepository extends BaseRepository&lt;Ylxxb, Integer&gt;{
19 19 */
20 20 @Transactional
21 21 @Modifying
22   - @Query(value="SELECT * FROM bsth_c_ylxxb where to_days(?1)=to_days(yyrq) and nylx=?2",nativeQuery=true)
23   - List<Ylxxb> obtainYlxx(String rq,int nylx);
  22 + @Query(value="SELECT * FROM bsth_c_ylxxb where to_days(?1)=to_days(yyrq) and nylx=?2 and gsdm like %?3%",nativeQuery=true)
  23 + List<Ylxxb> obtainYlxx(String rq,int nylx,String gsdm);
24 24  
25 25 @Transactional
26 26 @Modifying
... ...
src/main/java/com/bsth/repository/realcontrol/ScheduleRealInfoRepository.java
... ... @@ -92,7 +92,7 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
92 92 @Query(value="select s from ScheduleRealInfo s where s.clZbh = ?1 and s.scheduleDate = str_to_date(?2,'%Y-%m-%d') and xlBm =?3 order by realExecDate,fcsj")
93 93 List<ScheduleRealInfo> queryListWaybill2(String clZbh,String date,String line);
94 94  
95   - @Query(value="select s from ScheduleRealInfo s where s.jGh = ?1 and s.clZbh = ?2 and s.scheduleDate = str_to_date(?3,'%Y-%m-%d') order by realExecDate,fcsj")
  95 + @Query(value="select s from ScheduleRealInfo s where s.jGh like %?1% and s.clZbh like %?2% and s.scheduleDate = str_to_date(?3,'%Y-%m-%d') order by realExecDate,fcsj")
96 96 List<ScheduleRealInfo> queryListWaybill3(String jName,String clZbh,String date);
97 97  
98 98 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') between str_to_date(?3,'%Y-%m-%d') and str_to_date(?4,'%Y-%m-%d') order by bcs")
... ... @@ -127,8 +127,8 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
127 127 @Query(value="select s from ScheduleRealInfo s where s.xlBm like %?1% and DATE_FORMAT(s.scheduleDate,'%Y-%m') = ?2 and s.bcType not in ('in','out') order by s.xlBm")
128 128 List<ScheduleRealInfo> scheduleByDateAndLine3(String line,String date);
129 129  
130   - @Query(value="select new map(s.scheduleDate as scheduleDate,s.xlBm as xlBm,s.clZbh as clZbh,s.jGh as jGh) from ScheduleRealInfo s where s.xlBm like %?1% and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 GROUP BY xlBm,clZbh,jGh,scheduleDate,jGh ORDER BY xlBm,clZbh")
131   - List<Map<String,Object>> yesterdayDataList(String line,String date);
  130 + @Query(value="select new map(s.scheduleDate as scheduleDate,s.xlBm as xlBm,s.clZbh as clZbh,s.jGh as jGh) from ScheduleRealInfo s where s.xlBm like %?1% and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 and s.gsBm like %?3% and s.fgsBm like %?4% GROUP BY xlBm,clZbh,jGh,scheduleDate,jGh ORDER BY xlBm,clZbh")
  131 + List<Map<String,Object>> yesterdayDataList(String line,String date,String gsbm,String fgsbm);
132 132  
133 133 @Query(value="select s from ScheduleRealInfo s where DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?1 ORDER BY xlBm,lpName,clZbh,xlDir")
134 134 List<ScheduleRealInfo> setLD(String date);
... ...
src/main/java/com/bsth/service/oil/impl/DlbServiceImpl.java
... ... @@ -77,6 +77,10 @@ public class DlbServiceImpl extends BaseServiceImpl&lt;Dlb,Integer&gt; implements DlbS
77 77 Cars c=carsList.get(i);
78 78 carsMap.put(c.getInsideCode(), c.getSfdc());
79 79 }
  80 + String gsbm="";
  81 + if(map2.get("ssgsdm_like")!=null){
  82 + gsbm=map2.get("ssgsdm_like").toString();
  83 + }
80 84 String rq=map2.get("rq").toString();
81 85 String line="";
82 86 if(map2.get("xlbm_eq")!=null){
... ... @@ -91,14 +95,14 @@ public class DlbServiceImpl extends BaseServiceImpl&lt;Dlb,Integer&gt; implements DlbS
91 95 //当天DLB信息
92 96 List<Dlb> dlList=repository.obtainDl(rq);
93 97 //当天YLXXB信息
94   - List<Ylxxb> ylxxList=ylxxbRepository.obtainYlxx(rq,1);
  98 + List<Ylxxb> ylxxList=ylxxbRepository.obtainYlxx(rq,1,gsbm);
95 99 //当天加电信息表
96 100 List<Jdl> jdlList=jdlRepository.JdlList(rq);
97 101 //前一天所有车辆最后进场班次信息
98 102 List<Dlb> dlListBe=repository.obtainYlbefore(rq);
99 103 List<Cdl> cdyList=cdlRepository.obtainCdl();
100 104 //从排班表中计算出行驶的总里程
101   - List<Map<String,Object>> listpb=scheduleRealInfoService.yesterdayDataList(line,rq);
  105 + List<Map<String,Object>> listpb=scheduleRealInfoService.yesterdayDataList(line,rq,"","","","");
102 106 List<Ylb> addList=new ArrayList<Ylb>();
103 107 List<Ylb> updateList=new ArrayList<Ylb>();
104 108 for(int x=0;x<listpb.size();x++){
... ... @@ -244,14 +248,17 @@ public class DlbServiceImpl extends BaseServiceImpl&lt;Dlb,Integer&gt; implements DlbS
244 248 public Map<String, Object> checkDl(Map<String, Object> map) {
245 249 Map<String, Object> newMap=new HashMap<String,Object>();
246 250 String xlbm=map.get("xlbm_eq").toString();
247   -
  251 + String gsbm="";
  252 + if(map.get("ssgsdm_like")!=null){
  253 + gsbm=map.get("ssgsdm_like").toString();
  254 + }
248 255 // TODO Auto-generated method stub
249 256 try{
250 257 //获取车辆存油信息
251 258 // List<Cyl> cylList=cylRepository.findAll(new CustomerSpecs<Cyl>(newMap));
252 259 String rq=map.get("rq").toString();
253 260 List<Dlb> dlbList=repository.obtainDl(rq);
254   - List<Ylxxb> ylxxbList=ylxxbRepository.obtainYlxx(rq,1);
  261 + List<Ylxxb> ylxxbList=ylxxbRepository.obtainYlxx(rq,1,gsbm);
255 262 //当天加电信息表
256 263 List<Jdl> jdlList=jdlRepository.JdlList(rq);
257 264 for (int i = 0; i < ylxxbList.size(); i++) {
... ...
src/main/java/com/bsth/service/oil/impl/YlbServiceImpl.java
... ... @@ -97,10 +97,10 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
97 97 //当天YLXXB信息
98 98 // List<Ylxxb> ylxxList=ylxxbRepository.obtainYlxx(rq);
99 99 //前一天所有车辆最后进场班次信息
100   - List<Ylb> ylListBe=repository.obtainYlbefore(rq);
  100 + List<Ylb> ylListBe=repository.obtainYlbefore(rq,"","","","");
101 101 List<Cyl> clyList=cylRepository.obtainCyl("","");
102 102 //从排班表中计算出行驶的总里程
103   - List<Map<String,Object>> listpb=scheduleRealInfoService.yesterdayDataList("",rq);
  103 + List<Map<String,Object>> listpb=scheduleRealInfoService.yesterdayDataList("", rq, "", "", "", "");
104 104  
105 105 for(int x=0;x<listpb.size();x++){
106 106 boolean sfdc=true;
... ... @@ -222,14 +222,15 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
222 222 // 当天YLB信息
223 223 List<Ylb> ylList = repository.obtainYl(rq,gsbm,fgsbm,line,nbbm,"nbbm");
224 224 // 当天YLXXB信息
225   - List<Ylxxb> ylxxList = ylxxbRepository.obtainYlxx(rq, 0);
  225 + List<Ylxxb> ylxxList = ylxxbRepository.obtainYlxx(rq, 0,gsbm);
226 226 // 前一天所有车辆最后进场班次信息
227   - List<Ylb> ylListBe = repository.obtainYlbefore(rq);
  227 + List<Ylb> ylListBe = repository.obtainYlbefore(rq, gsbm, fgsbm, line, nbbm);
228 228 List<Cyl> clyList = cylRepository.obtainCyl(nbbm,gsbm);
229 229 // 从排班表中计算出行驶的总里程
230   - List<Map<String, Object>> listpb = scheduleRealInfoService.yesterdayDataList(line, rq);
  230 + List<Map<String, Object>> listpb = scheduleRealInfoService.yesterdayDataList(line, rq, gsbm, fgsbm, "", nbbm);
231 231 List<Ylb> addList = new ArrayList<Ylb>();
232 232 List<Ylb> updateList = new ArrayList<Ylb>();
  233 + String ins="";
233 234 for (int x = 0; x < listpb.size(); x++) {
234 235 String type = "add";
235 236 boolean sfdc = true;
... ... @@ -312,29 +313,34 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
312 313 t.setSsgsdm(map.get("company") == null ? "" : map.get("company").toString());
313 314 t.setFgsdm(map.get("bCompany") == null ? "" : map.get("bCompany").toString());
314 315 t.setRq(sdf.parse(rq));
315   - /*
316   - * if(type.equals("add")){ addList.add(t); }else{
317   - * updateList.add(t); }
318   - */
319   - repository.save(t);
  316 +
  317 + if(type.equals("add")){
  318 + addList.add(t);
  319 + }else{
  320 + updateList.add(t);
  321 + ins += t.getId().toString()+",";
  322 + }
  323 +// repository.save(t);
320 324 newMap.put("status", ResponseCode.SUCCESS);
321 325  
322 326 }
323 327 }
  328 + if(addList.size()>0){
  329 + new BatchSaveUtils<Ylb>().saveList(addList, Ylb.class);
  330 + }
  331 +
  332 + if(updateList.size()>0){
  333 + for (int i = 0; i < updateList.size(); i++) {
  334 + repository.save(updateList.get(i));
  335 + }
  336 + }
  337 + newMap.put("status", ResponseCode.SUCCESS);
324 338 } catch (ParseException e) {
325 339 // TODO Auto-generated catch block
326 340 newMap.put("status", ResponseCode.ERROR);
327 341 throw e;
328 342 }
329   - /*
330   - * try { if(addList.size()>0){ new
331   - * BatchSaveUtils<Ylb>().saveList(addList, Ylb.class); }
332   - *
333   - * if(updateList.size()>0){
334   - *
335   - * } newMap.put("status", ResponseCode.SUCCESS); } catch (Exception e) {
336   - * // TODO: handle exception newMap.put("status", ResponseCode.ERROR); }
337   - */
  343 +
338 344 return newMap;
339 345 }
340 346  
... ... @@ -383,7 +389,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
383 389 String nbbm_eq = ylb.getNbbm();
384 390 Date rq_eq = ylb.getRq();
385 391 // 得到一天总的加油和里程(根据车,时间)
386   - List<Object[]> sumList = repository.sumLcYl(nbbm_eq, rq_eq);
  392 + List<Object[]> sumList = repository.sumLcYl(nbbm_eq, rq_eq,ylb.getXlbm());
387 393 // 保存总的加油量
388 394 Double jzl = Double.valueOf(sumList.get(0)[0].toString());
389 395 // 保存总的里程
... ... @@ -484,7 +490,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
484 490 String nbbm_eq = ylb.getNbbm();
485 491 Date rq_eq = ylb.getRq();
486 492 // 得到一天总的加油和里程(根据车,时间)
487   - List<Object[]> sumList = repository.sumLcYl(nbbm_eq, rq_eq);
  493 + List<Object[]> sumList = repository.sumLcYl(nbbm_eq, rq_eq,ylb.getXlbm());
488 494 // 保存总的加油量
489 495 Double jzl = Double.valueOf(sumList.get(0)[0].toString());
490 496 // 保存总的里程
... ... @@ -610,7 +616,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
610 616 nbbm=map.get("nbbm_eq").toString();
611 617 }
612 618 List<Ylb> ylbList=repository.obtainYl(rq,gsbm,fgsbm,xlbm,nbbm,"nbbm");
613   - List<Ylxxb> ylxxbList=ylxxbRepository.obtainYlxx(rq,0);
  619 + List<Ylxxb> ylxxbList=ylxxbRepository.obtainYlxx(rq,0,gsbm);
614 620 for (int i = 0; i < ylxxbList.size(); i++) {
615 621 Boolean fage=true;
616 622 Ylxxb y1=ylxxbList.get(i);
... ...
src/main/java/com/bsth/service/realcontrol/ScheduleRealInfoService.java
... ... @@ -126,7 +126,7 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L
126 126 List<ScheduleRealInfo> realScheduleList(String line,String date);
127 127 List<ScheduleRealInfo> realScheduleListQp(String line,String date);
128 128  
129   - List<Map<String,Object>> yesterdayDataList(String line,String date);
  129 + List<Map<String,Object>> yesterdayDataList(String line,String date,String gsbm,String fgsbm,String jGh,String nbbm);
130 130  
131 131 List<Map<String,Object>> yesterdayDataList(String line);
132 132  
... ...
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
... ... @@ -1291,7 +1291,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1291 1291 // int ljbc = scheduleRealInfoRepository.findLjbc(jName, clZbh, lpName);
1292 1292 int jhbc = 0, cjbc = 0, ljbc = 0;
1293 1293 double jhlc = 0, yygl = 0, ksgl = 0, tempJhlc = 0, jcclc = 0;
1294   - float addMileage = 0l, remMileage = 0l;
  1294 + float addMileage = 0l, remMileage = 0l,addMileageYy = 0l,addMileageJc =0l;
1295 1295 Map<String, Object> map = new HashMap<String, Object>();
1296 1296 for (ScheduleRealInfo scheduleRealInfo : list) {
1297 1297 if (scheduleRealInfo != null) {
... ... @@ -1302,7 +1302,14 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1302 1302 tempJhlc = scheduleRealInfo.getJhlc() == null ? 0 : scheduleRealInfo.getJhlc();
1303 1303 if (scheduleRealInfo.isSflj()) {
1304 1304 addMileage += tempJhlc;
1305   - ljbc++;
  1305 + if (scheduleRealInfo.getBcType().equals("in")
  1306 + || scheduleRealInfo.getBcType().equals("out")) {
  1307 + addMileageJc +=tempJhlc;
  1308 + }else{
  1309 + ljbc++;
  1310 + addMileageYy +=tempJhlc;
  1311 + }
  1312 +
1306 1313 } else {
1307 1314 if (!(scheduleRealInfo.getBcType().equals("in")
1308 1315 || scheduleRealInfo.getBcType().equals("out"))) {
... ... @@ -1359,15 +1366,15 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1359 1366 map.put("jhlc", format.format(jhlc));
1360 1367 map.put("remMileage", format.format(remMileage));
1361 1368 map.put("addMileage", format.format(addMileage));
1362   - map.put("yygl", format.format(yygl));
  1369 + map.put("yygl", format.format(yygl+addMileageYy));
1363 1370 map.put("ksgl", format.format(ksgl));
1364   - map.put("realMileage", format.format(yygl + ksgl + jcclc));
  1371 + map.put("realMileage", format.format(yygl + ksgl + jcclc+addMileage));
1365 1372 map.put("jhbc", jhbc);
1366 1373 map.put("cjbc", cjbc);
1367 1374 map.put("ljbc", ljbc);
1368 1375 map.put("sjbc", jhbc - cjbc + ljbc);
1369 1376 map.put("jcclc", jcclc);
1370   - map.put("zkslc", format.format(ksgl + jcclc));
  1377 + map.put("zkslc", format.format(ksgl + jcclc+addMileageJc));
1371 1378 return map;
1372 1379 }
1373 1380  
... ... @@ -1501,6 +1508,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1501 1508 if (!childTaskPlans.isEmpty()) {
1502 1509 s.setFcsjActual("");
1503 1510 s.setZdsjActual("");
  1511 + s.setJhlc(0.0);
1504 1512 }
1505 1513  
1506 1514 if (s.isDestroy()) {
... ... @@ -2332,86 +2340,91 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
2332 2340 return list;
2333 2341 }
2334 2342  
2335   - public List<Map<String, Object>> yesterdayDataList(String line, String date) {
  2343 + public List<Map<String, Object>> yesterdayDataList(String line, String date,String gsbm,String fgsbm,String jGh,String nbbm) {
2336 2344 //前一天日期
2337 2345 // String date = sdfMonth.format(org.apache.commons.lang.time.DateUtils.addDays(new Date(), -1));
2338 2346 // String date = "2016-09-20";
2339   - List<Map<String, Object>> yesterdayDataList = scheduleRealInfoRepository.yesterdayDataList(line, date);
  2347 + List<Map<String, Object>> yesterdayDataList = scheduleRealInfoRepository.yesterdayDataList(line, date,gsbm,fgsbm);
2340 2348 // List<ScheduleRealInfo> list = scheduleRealInfoRepository.scheduleByDateAndLine(line, date);
  2349 + List<ScheduleRealInfo> lists = scheduleRealInfoRepository.queryListWaybill3(jGh, nbbm, date);
2341 2350 for (int x = 0; x < yesterdayDataList.size(); x++) {
2342 2351 String jName = yesterdayDataList.get(x).get("jGh").toString();
2343 2352 String clZbh = yesterdayDataList.get(x).get("clZbh").toString();
2344   - List<ScheduleRealInfo> lists = scheduleRealInfoRepository.queryListWaybill3(jName, clZbh, date);
  2353 +
2345 2354 double jhlc = 0, yygl = 0, ksgl = 0, tempJhlc = 0, jcclc = 0;
2346 2355 float addMileage = 0l, remMileage = 0l;
2347 2356 Map<String, Object> map = new HashMap<String, Object>();
2348 2357 boolean fage = true;
  2358 + String company="";
  2359 + String bCompany="";
2349 2360 for (ScheduleRealInfo scheduleRealInfo : lists) {
2350   - if (fage) {
2351   - //根据线路代码获取公司
2352   - Line li = lineRepository.findByLineCode(scheduleRealInfo.getXlBm());
2353   - yesterdayDataList.get(x).put("company", li.getCompany());
2354   - yesterdayDataList.get(x).put("bCompany", li.getBrancheCompany());
2355   - fage = false;
2356   - }
2357   - if (scheduleRealInfo != null) {
2358   - //计划里程(主任务过滤掉临加班次),
2359   - //烂班里程(主任务烂班),
2360   - //临加里程(主任务临加),
2361   - //计划班次,烂班班次,增加班次
2362   - tempJhlc = scheduleRealInfo.getJhlc() == null ? 0 : scheduleRealInfo.getJhlc();
2363   - if (scheduleRealInfo.isSflj()) {
2364   - addMileage += tempJhlc;
2365   - } else {
2366   - if (!(scheduleRealInfo.getBcType().equals("in")
2367   - || scheduleRealInfo.getBcType().equals("out"))) {
2368   - jhlc += tempJhlc;
2369   - }
2370   -
2371   - if (scheduleRealInfo.getStatus() == -1) {
2372   - remMileage += tempJhlc;
2373   - }
2374   - }
2375   - Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();
2376   - //计算营运里程,空驶里程
2377   - if (childTaskPlans.isEmpty()) {
2378   - if (scheduleRealInfo.getBcType().equals("in") ||
2379   - scheduleRealInfo.getBcType().equals("out")) {
2380   - if (scheduleRealInfo.getStatus() != -1) {
2381   - jcclc += tempJhlc;
2382   - }
2383   - }
2384   - //主任务 放空班次属于营运
2385   -// else if(scheduleRealInfo.getBcType().equals("venting")){
2386   -// ksgl += tempJhlc;
2387   -// }
2388   - else {
2389   - if (scheduleRealInfo.getStatus() != -1) {
2390   - yygl += tempJhlc;
2391   - }
2392   - }
2393   - } else {
2394   - Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
2395   - while (it.hasNext()) {
2396   - ChildTaskPlan childTaskPlan = it.next();
2397   - if (childTaskPlan.getMileageType().equals("empty")) {
2398   - if (childTaskPlan.isDestroy()) {
2399   - remMileage += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
2400   - } else {
2401   - ksgl += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
2402   - }
2403   - } else {
2404   - if (childTaskPlan.isDestroy()) {
2405   - remMileage += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
2406   - } else {
2407   - yygl += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
2408   - }
2409   - }
2410   - }
2411   - }
2412   - }
2413   - }
2414   -
  2361 + if(scheduleRealInfo.getjGh().equals(jName) && scheduleRealInfo.getClZbh().equals(clZbh)){
  2362 + if (fage) {
  2363 + //根据线路代码获取公司
  2364 + company=scheduleRealInfo.getGsBm();
  2365 + bCompany=scheduleRealInfo.getFgsBm();
  2366 + fage = false;
  2367 + }
  2368 + if (scheduleRealInfo != null) {
  2369 + //计划里程(主任务过滤掉临加班次),
  2370 + //烂班里程(主任务烂班),
  2371 + //临加里程(主任务临加),
  2372 + //计划班次,烂班班次,增加班次
  2373 + tempJhlc = scheduleRealInfo.getJhlc() == null ? 0 : scheduleRealInfo.getJhlc();
  2374 + if (scheduleRealInfo.isSflj()) {
  2375 + addMileage += tempJhlc;
  2376 + } else {
  2377 + if (!(scheduleRealInfo.getBcType().equals("in")
  2378 + || scheduleRealInfo.getBcType().equals("out"))) {
  2379 + jhlc += tempJhlc;
  2380 + }
  2381 +
  2382 + if (scheduleRealInfo.getStatus() == -1) {
  2383 + remMileage += tempJhlc;
  2384 + }
  2385 + }
  2386 + Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();
  2387 + //计算营运里程,空驶里程
  2388 + if (childTaskPlans.isEmpty()) {
  2389 + if (scheduleRealInfo.getBcType().equals("in") ||
  2390 + scheduleRealInfo.getBcType().equals("out")) {
  2391 + if (scheduleRealInfo.getStatus() != -1) {
  2392 + jcclc += tempJhlc;
  2393 + }
  2394 + }
  2395 + //主任务 放空班次属于营运
  2396 + // else if(scheduleRealInfo.getBcType().equals("venting")){
  2397 + // ksgl += tempJhlc;
  2398 + // }
  2399 + else {
  2400 + if (scheduleRealInfo.getStatus() != -1) {
  2401 + yygl += tempJhlc;
  2402 + }
  2403 + }
  2404 + } else {
  2405 + Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
  2406 + while (it.hasNext()) {
  2407 + ChildTaskPlan childTaskPlan = it.next();
  2408 + if (childTaskPlan.getMileageType().equals("empty")) {
  2409 + if (childTaskPlan.isDestroy()) {
  2410 + remMileage += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2411 + } else {
  2412 + ksgl += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2413 + }
  2414 + } else {
  2415 + if (childTaskPlan.isDestroy()) {
  2416 + remMileage += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2417 + } else {
  2418 + yygl += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2419 + }
  2420 + }
  2421 + }
  2422 + }
  2423 + }
  2424 + }
  2425 + }
  2426 + yesterdayDataList.get(x).put("company", company);
  2427 + yesterdayDataList.get(x).put("bCompany", bCompany);
2415 2428 yesterdayDataList.get(x).put("totalKilometers", yygl + ksgl + jcclc);
2416 2429  
2417 2430 }
... ... @@ -3119,7 +3132,9 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
3119 3132 }
3120 3133  
3121 3134 if (!c.isDestroy()) {
3122   - sjlc += c.getMileage() == null ? 0 : c.getMileage();
  3135 + if(c.getMileageType().equals("service")){
  3136 + sjlc += c.getMileage() == null ? 0 : c.getMileage();
  3137 + }
3123 3138 }
3124 3139  
3125 3140 }
... ...
src/main/java/com/bsth/service/schedule/rules/plan/PlanCalcuParam_input.java
1   -package com.bsth.service.schedule.rules.plan;
2   -
3   -import com.bsth.entity.schedule.SchedulePlan;
4   -import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
5   -import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output;
6   -
7   -/**
8   - * 排班规则-规则输入参数。
9   - */
10   -public class PlanCalcuParam_input {
11   - /** 线路id */
12   - private Integer xlId;
13   - /** 循环规则输出 */
14   - private ScheduleResults_output scheduleResults_output;
15   - /** 时刻表选择规则输出 */
16   - private TTInfoResults_output ttInfoResults_output;
17   -
18   - public PlanCalcuParam_input() {
19   - }
20   - public PlanCalcuParam_input(
21   - SchedulePlan schedulePlan,
22   - ScheduleResults_output scheduleResults_output,
23   - TTInfoResults_output ttInfoResults_output) {
24   - this.xlId = schedulePlan.getXl().getId();
25   - this.scheduleResults_output = scheduleResults_output;
26   - this.ttInfoResults_output = ttInfoResults_output;
27   - }
28   -
29   - public Integer getXlId() {
30   - return xlId;
31   - }
32   -
33   - public void setXlId(Integer xlId) {
34   - this.xlId = xlId;
35   - }
36   -
37   - public ScheduleResults_output getScheduleResults_output() {
38   - return scheduleResults_output;
39   - }
40   -
41   - public void setScheduleResults_output(ScheduleResults_output scheduleResults_output) {
42   - this.scheduleResults_output = scheduleResults_output;
43   - }
44   -
45   - public TTInfoResults_output getTtInfoResults_output() {
46   - return ttInfoResults_output;
47   - }
48   -
49   - public void setTtInfoResults_output(TTInfoResults_output ttInfoResults_output) {
50   - this.ttInfoResults_output = ttInfoResults_output;
51   - }
52   -}
  1 +package com.bsth.service.schedule.rules.plan;
  2 +
  3 +import com.bsth.entity.schedule.SchedulePlan;
  4 +import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
  5 +import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output;
  6 +
  7 +/**
  8 + * 排班规则-规则输入参数。
  9 + */
  10 +public class PlanCalcuParam_input {
  11 + /** 线路id */
  12 + private Integer xlId;
  13 + /** 循环规则输出 */
  14 + private ScheduleResults_output scheduleResults_output;
  15 + /** 时刻表选择规则输出 */
  16 + private TTInfoResults_output ttInfoResults_output;
  17 +
  18 + public PlanCalcuParam_input() {
  19 + }
  20 + public PlanCalcuParam_input(
  21 + SchedulePlan schedulePlan,
  22 + ScheduleResults_output scheduleResults_output,
  23 + TTInfoResults_output ttInfoResults_output) {
  24 + this.xlId = schedulePlan.getXl().getId();
  25 + this.scheduleResults_output = scheduleResults_output;
  26 + this.ttInfoResults_output = ttInfoResults_output;
  27 + }
  28 +
  29 + public Integer getXlId() {
  30 + return xlId;
  31 + }
  32 +
  33 + public void setXlId(Integer xlId) {
  34 + this.xlId = xlId;
  35 + }
  36 +
  37 + public ScheduleResults_output getScheduleResults_output() {
  38 + return scheduleResults_output;
  39 + }
  40 +
  41 + public void setScheduleResults_output(ScheduleResults_output scheduleResults_output) {
  42 + this.scheduleResults_output = scheduleResults_output;
  43 + }
  44 +
  45 + public TTInfoResults_output getTtInfoResults_output() {
  46 + return ttInfoResults_output;
  47 + }
  48 +
  49 + public void setTtInfoResults_output(TTInfoResults_output ttInfoResults_output) {
  50 + this.ttInfoResults_output = ttInfoResults_output;
  51 + }
  52 +}
... ...
src/main/java/com/bsth/service/schedule/rules/plan/PlanResult.java
1   -package com.bsth.service.schedule.rules.plan;
2   -
3   -import com.bsth.entity.schedule.SchedulePlanInfo;
4   -
5   -import java.util.ArrayList;
6   -import java.util.List;
7   -
8   -/**
9   - * 计划输出。
10   - */
11   -public class PlanResult {
12   - private List<SchedulePlanInfo> schedulePlanInfos = new ArrayList<>();
13   -
14   - public PlanResult() {
15   - }
16   -
17   - public void add(SchedulePlanInfo schedulePlanInfo) {
18   - schedulePlanInfos.add(schedulePlanInfo);
19   - }
20   -
21   - public List<SchedulePlanInfo> getSchedulePlanInfos() {
22   - return schedulePlanInfos;
23   - }
24   -
25   - public void setSchedulePlanInfos(List<SchedulePlanInfo> schedulePlanInfos) {
26   - this.schedulePlanInfos = schedulePlanInfos;
27   - }
28   -}
  1 +package com.bsth.service.schedule.rules.plan;
  2 +
  3 +import com.bsth.entity.schedule.SchedulePlanInfo;
  4 +
  5 +import java.util.ArrayList;
  6 +import java.util.List;
  7 +
  8 +/**
  9 + * 计划输出。
  10 + */
  11 +public class PlanResult {
  12 + private List<SchedulePlanInfo> schedulePlanInfos = new ArrayList<>();
  13 +
  14 + public PlanResult() {
  15 + }
  16 +
  17 + public void add(SchedulePlanInfo schedulePlanInfo) {
  18 + schedulePlanInfos.add(schedulePlanInfo);
  19 + }
  20 +
  21 + public List<SchedulePlanInfo> getSchedulePlanInfos() {
  22 + return schedulePlanInfos;
  23 + }
  24 +
  25 + public void setSchedulePlanInfos(List<SchedulePlanInfo> schedulePlanInfos) {
  26 + this.schedulePlanInfos = schedulePlanInfos;
  27 + }
  28 +}
... ...
src/main/java/com/bsth/service/schedule/rules/plan/readme.txt
1   -排班计划规则,构造计划明细输出
2   -1、使用shiftloop.drl和ttinfo.drl的输出作为输入,进行规则计算
  1 +排班计划规则,构造计划明细输出
  2 +1、使用shiftloop.drl和ttinfo.drl的输出作为输入,进行规则计算
3 3 2、计算后输出排班明细列表
4 4 \ No newline at end of file
... ...
src/main/resources/rules/plan.drl
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.service.schedule.TTInfoService;
10   -import com.bsth.service.schedule.TTInfoDetailService;
11   -import com.bsth.service.schedule.CarConfigInfoService;
12   -import com.bsth.service.schedule.EmployeeConfigInfoService;
13   -import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
14   -import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
15   -import com.bsth.service.schedule.rules.ttinfo.TTInfoResult_output;
16   -import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output;
17   -
18   -import com.bsth.entity.schedule.CarConfigInfo;
19   -import com.bsth.entity.schedule.EmployeeConfigInfo;
20   -import com.bsth.entity.schedule.TTInfo;
21   -import com.bsth.entity.schedule.TTInfoDetail;
22   -import com.bsth.entity.schedule.SchedulePlanInfo;
23   -
24   -import org.slf4j.Logger;
25   -
26   -
27   -// 全局日志类(一般使用调用此规则的service类)
28   -global Logger log;
29   -global TTInfoDetailService tTInfoDetailService;
30   -global TTInfoService tTInfoService;
31   -global CarConfigInfoService carConfigInfoService;
32   -global EmployeeConfigInfoService employeeConfigInfoService;
33   -
34   -// 输出
35   -global PlanResult planResult;
36   -
37   -function Map ttidParams(String ttid) {
38   - Map param = new HashMap();
39   - param.put("ttinfo.id_eq", Long.parseLong(ttid));
40   - return param;
41   -}
42   -
43   -function Map xlidParams(Integer xlid) {
44   - Map param = new HashMap();
45   - param.put("xl.id_eq", xlid);
46   - return param;
47   -}
48   -
49   -/*
50   - 规则说明:
51   - 1、根据循环规则输出,时刻表选择规则输出,计算排班明细
52   -*/
53   -
54   -//-------------------- 第一阶段、计算迭代数据 -----------------//
55   -declare Loop_result
56   - xlId: Integer // 线路id
57   - ruleLoop: List // 每天分配的规则 List<ScheduleResult_output>
58   - ttInfoMapLoop_temp: Map // 每天分配的时刻表 Map<DataTime, Collection<TTInfoResult_output>>
59   - ttInfoMapLoop: Map // 每天分配的时刻表 Map<DataTime, TTInfoResult_output>
60   -
61   - ttInfoMap: Map // 总共用到的时刻表 Map<id, TTInfoResult_output>
62   -end
63   -
64   -rule "calcu_step1_Loop_result"
65   - salience 1000
66   - when
67   - $param: PlanCalcuParam_input($xlId: xlId)
68   - then
69   - Loop_result loop_result = new Loop_result();
70   - loop_result.setXlId($xlId);
71   - loop_result.setRuleLoop($param.getScheduleResults_output().getResults());
72   -
73   - loop_result.setTtInfoMapLoop(new HashMap());
74   - loop_result.setTtInfoMap(new HashMap());
75   -
76   - com.google.common.collect.Multimap ttInfoMap_temp =
77   - (com.google.common.collect.Multimap)
78   - $param.getTtInfoResults_output().getResults().get(
79   - String.valueOf($xlId));
80   -
81   - loop_result.setTtInfoMapLoop_temp(ttInfoMap_temp.asMap());
82   -
83   - insert(loop_result);
84   -
85   - log.info("calcu_step1_Loop_result");
86   -end
87   -
88   -rule "calcu_step2_loop_result"
89   - salience 1000
90   - no-loop
91   - when
92   - $param: PlanCalcuParam_input($xlId: xlId)
93   - $lr: Loop_result(xlId == $xlId)
94   - $sd: DateTime() from $lr.ttInfoMapLoop_temp.keySet()
95   - then
96   - // 当天时刻表只取第一张 TODO:
97   - Collection col = (Collection) $lr.getTtInfoMapLoop_temp().get($sd);
98   - Iterator iter = col.iterator();
99   - TTInfoResult_output ttInfo_result = (TTInfoResult_output) iter.next();
100   - $lr.getTtInfoMapLoop().put($sd, ttInfo_result);
101   -
102   - // 总共使用的时刻表
103   - $lr.getTtInfoMap().put(ttInfo_result.getTtInfoId(), ttInfo_result);
104   -
105   - update($lr);
106   -end
107   -
108   -//-------------------- 第二阶段、将时刻表班次,车辆配置,人员配置信息载入 -----------------//
109   -
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   -
135   -declare CarConfig_Wrap
136   - id: String // 车辆配置id(cast字符串-方便比较)
137   -
138   - self: CarConfigInfo // 原始数据
139   -end
140   -
141   -rule "calcu_CarConfig_Wrap"
142   - salience 800
143   - when
144   - $lr: Loop_result($xlId: xlId)
145   - $ccf: CarConfigInfo() from carConfigInfoService.list(xlidParams($xlId))
146   - then
147   - CarConfig_Wrap carConfig_wrap = new CarConfig_Wrap();
148   - carConfig_wrap.setId(String.valueOf($ccf.getId()));
149   - carConfig_wrap.setSelf($ccf);
150   -
151   - insert(carConfig_wrap);
152   -end
153   -
154   -declare EmployeeConfig_Wrap
155   - id: String // 人员配置id(cast字符串-方便比较)
156   -
157   - self: EmployeeConfigInfo // 原始数据
158   -end
159   -
160   -rule "calcu_EmployeeConfig_Wrap"
161   - salience 800
162   - when
163   - $lr: Loop_result($xlId: xlId)
164   - $eci: EmployeeConfigInfo() from employeeConfigInfoService.list(xlidParams($xlId))
165   - then
166   - EmployeeConfig_Wrap employeeConfig_wrap = new EmployeeConfig_Wrap();
167   - employeeConfig_wrap.setId(String.valueOf($eci.getId()));
168   - employeeConfig_wrap.setSelf($eci);
169   -
170   - insert(employeeConfig_wrap);
171   -end
172   -
173   -declare ScheduleResult_output_Wrap
174   - xlId: Integer // 线路id
175   - sd: DateTime // 日期
176   - ruleId: String // 规则Id
177   - eciIds: List // 人员配置ids
178   -
179   - self: ScheduleResult_output // 原始数据
180   -end
181   -
182   -rule "calcu_ScheduleResult_output_Wrap"
183   - salience 800
184   - when
185   - $lr: Loop_result($xlId: xlId)
186   - $sro: ScheduleResult_output() from $lr.getRuleLoop()
187   - 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);
197   -end
198   -
199   -//-------------------- 第三阶段、合并计算SchedulePlanInfo -----------------//
200   -
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
223   -
224   -
225   -
226   -
227   -
228   -
229   -
230   -
231   -
232   -
233   -
234   -
235   -
236   -
  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.service.schedule.TTInfoService;
  10 +import com.bsth.service.schedule.TTInfoDetailService;
  11 +import com.bsth.service.schedule.CarConfigInfoService;
  12 +import com.bsth.service.schedule.EmployeeConfigInfoService;
  13 +import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
  14 +import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
  15 +import com.bsth.service.schedule.rules.ttinfo.TTInfoResult_output;
  16 +import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output;
  17 +
  18 +import com.bsth.entity.schedule.CarConfigInfo;
  19 +import com.bsth.entity.schedule.EmployeeConfigInfo;
  20 +import com.bsth.entity.schedule.TTInfo;
  21 +import com.bsth.entity.schedule.TTInfoDetail;
  22 +import com.bsth.entity.schedule.SchedulePlanInfo;
  23 +
  24 +import org.slf4j.Logger;
  25 +
  26 +
  27 +// 全局日志类(一般使用调用此规则的service类)
  28 +global Logger log;
  29 +global TTInfoDetailService tTInfoDetailService;
  30 +global TTInfoService tTInfoService;
  31 +global CarConfigInfoService carConfigInfoService;
  32 +global EmployeeConfigInfoService employeeConfigInfoService;
  33 +
  34 +// 输出
  35 +global PlanResult planResult;
  36 +
  37 +function Map ttidParams(String ttid) {
  38 + Map param = new HashMap();
  39 + param.put("ttinfo.id_eq", Long.parseLong(ttid));
  40 + return param;
  41 +}
  42 +
  43 +function Map xlidParams(Integer xlid) {
  44 + Map param = new HashMap();
  45 + param.put("xl.id_eq", xlid);
  46 + return param;
  47 +}
  48 +
  49 +/*
  50 + 规则说明:
  51 + 1、根据循环规则输出,时刻表选择规则输出,计算排班明细
  52 +*/
  53 +
  54 +//-------------------- 第一阶段、计算迭代数据 -----------------//
  55 +declare Loop_result
  56 + xlId: Integer // 线路id
  57 + ruleLoop: List // 每天分配的规则 List<ScheduleResult_output>
  58 + ttInfoMapLoop_temp: Map // 每天分配的时刻表 Map<DataTime, Collection<TTInfoResult_output>>
  59 + ttInfoMapLoop: Map // 每天分配的时刻表 Map<DataTime, TTInfoResult_output>
  60 +
  61 + ttInfoMap: Map // 总共用到的时刻表 Map<id, TTInfoResult_output>
  62 +end
  63 +
  64 +rule "calcu_step1_Loop_result"
  65 + salience 1000
  66 + when
  67 + $param: PlanCalcuParam_input($xlId: xlId)
  68 + then
  69 + Loop_result loop_result = new Loop_result();
  70 + loop_result.setXlId($xlId);
  71 + loop_result.setRuleLoop($param.getScheduleResults_output().getResults());
  72 +
  73 + loop_result.setTtInfoMapLoop(new HashMap());
  74 + loop_result.setTtInfoMap(new HashMap());
  75 +
  76 + com.google.common.collect.Multimap ttInfoMap_temp =
  77 + (com.google.common.collect.Multimap)
  78 + $param.getTtInfoResults_output().getResults().get(
  79 + String.valueOf($xlId));
  80 +
  81 + loop_result.setTtInfoMapLoop_temp(ttInfoMap_temp.asMap());
  82 +
  83 + insert(loop_result);
  84 +
  85 + log.info("calcu_step1_Loop_result");
  86 +end
  87 +
  88 +rule "calcu_step2_loop_result"
  89 + salience 1000
  90 + no-loop
  91 + when
  92 + $param: PlanCalcuParam_input($xlId: xlId)
  93 + $lr: Loop_result(xlId == $xlId)
  94 + $sd: DateTime() from $lr.ttInfoMapLoop_temp.keySet()
  95 + then
  96 + // 当天时刻表只取第一张 TODO:
  97 + Collection col = (Collection) $lr.getTtInfoMapLoop_temp().get($sd);
  98 + Iterator iter = col.iterator();
  99 + TTInfoResult_output ttInfo_result = (TTInfoResult_output) iter.next();
  100 + $lr.getTtInfoMapLoop().put($sd, ttInfo_result);
  101 +
  102 + // 总共使用的时刻表
  103 + $lr.getTtInfoMap().put(ttInfo_result.getTtInfoId(), ttInfo_result);
  104 +
  105 + update($lr);
  106 +end
  107 +
  108 +//-------------------- 第二阶段、将时刻表班次,车辆配置,人员配置信息载入 -----------------//
  109 +
  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 +
  135 +declare CarConfig_Wrap
  136 + id: String // 车辆配置id(cast字符串-方便比较)
  137 +
  138 + self: CarConfigInfo // 原始数据
  139 +end
  140 +
  141 +rule "calcu_CarConfig_Wrap"
  142 + salience 800
  143 + when
  144 + $lr: Loop_result($xlId: xlId)
  145 + $ccf: CarConfigInfo() from carConfigInfoService.list(xlidParams($xlId))
  146 + then
  147 + CarConfig_Wrap carConfig_wrap = new CarConfig_Wrap();
  148 + carConfig_wrap.setId(String.valueOf($ccf.getId()));
  149 + carConfig_wrap.setSelf($ccf);
  150 +
  151 + insert(carConfig_wrap);
  152 +end
  153 +
  154 +declare EmployeeConfig_Wrap
  155 + id: String // 人员配置id(cast字符串-方便比较)
  156 +
  157 + self: EmployeeConfigInfo // 原始数据
  158 +end
  159 +
  160 +rule "calcu_EmployeeConfig_Wrap"
  161 + salience 800
  162 + when
  163 + $lr: Loop_result($xlId: xlId)
  164 + $eci: EmployeeConfigInfo() from employeeConfigInfoService.list(xlidParams($xlId))
  165 + then
  166 + EmployeeConfig_Wrap employeeConfig_wrap = new EmployeeConfig_Wrap();
  167 + employeeConfig_wrap.setId(String.valueOf($eci.getId()));
  168 + employeeConfig_wrap.setSelf($eci);
  169 +
  170 + insert(employeeConfig_wrap);
  171 +end
  172 +
  173 +declare ScheduleResult_output_Wrap
  174 + xlId: Integer // 线路id
  175 + sd: DateTime // 日期
  176 + ruleId: String // 规则Id
  177 + eciIds: List // 人员配置ids
  178 +
  179 + self: ScheduleResult_output // 原始数据
  180 +end
  181 +
  182 +rule "calcu_ScheduleResult_output_Wrap"
  183 + salience 800
  184 + when
  185 + $lr: Loop_result($xlId: xlId)
  186 + $sro: ScheduleResult_output() from $lr.getRuleLoop()
  187 + 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);
  197 +end
  198 +
  199 +//-------------------- 第三阶段、合并计算SchedulePlanInfo -----------------//
  200 +
  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
  223 +
  224 +
  225 +
  226 +
  227 +
  228 +
  229 +
  230 +
  231 +
  232 +
  233 +
  234 +
  235 +
  236 +
... ...
src/main/resources/rules/shiftloop_fb.drl
1   -package com.bsth.service.schedule.shiftloop;
2   -
3   -import org.joda.time.*;
4   -import java.util.*;
5   -
6   -import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input;
7   -import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input;
8   -import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
9   -import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
10   -
11   -import org.slf4j.Logger;
12   -
13   -global Logger log;
14   -
15   -/*
16   - 存在(翻班格式)
17   -*/
18   -
19   -//------------------------- 第一阶段、计算规则准备数据(天数) ----------------------------//
20   -
21   -declare Calcu_days_result
22   - ruleId : String // 规则Id
23   - qyrq_days : Integer // 开始日期离启用日期的天数
24   - sdays : Integer // 总共需要排班的天数
25   - calcu_start_date : DateTime // 开始计算日期
26   - calcu_end_date : DateTime // 结束计算日期
27   -end
28   -
29   -/*
30   - 计算启用日期,开始计算日期,结束计算日期,相差天数
31   - 1、规则启用日期小于开始计算日期
32   - 2、规则启用日期大于等于开始日期,小于等于结束日期
33   -*/
34   -rule "calcu_days_1"
35   - salience 100
36   - when
37   - ScheduleCalcuParam_input(
38   - fromDate.isBefore(toDate) || fromDate.isEqual(toDate),
39   - $fromDate : fromDate,
40   - $toDate : toDate
41   - )
42   - ScheduleRule_input($ruleId : ruleId, $qyrq : qyrq)
43   - eval($qyrq.isBefore($fromDate))
44   - then
45   - // 构造Calcu_days_result对象,进行下一阶段计算
46   - Calcu_days_result cdr = new Calcu_days_result();
47   - cdr.setRuleId($ruleId);
48   - Period p1 = new Period($qyrq, $fromDate, PeriodType.days());
49   - cdr.setQyrq_days(p1.getDays());
50   - Period p2 = new Period($fromDate, $toDate, PeriodType.days());
51   - cdr.setSdays(p2.getDays() + 1);
52   - cdr.setCalcu_start_date($fromDate);
53   - cdr.setCalcu_end_date($toDate);
54   -
55   - log.info("开始日期离启用日期的天数 qyrq_days={}", p1.getDays());
56   - log.info("总共需要排班的天数 sdays={}", (p2.getDays() + 1));
57   -
58   - insert(cdr); // 插入fact数据,进入下一个阶段
59   -end
60   -
61   -rule "calcu_days_2"
62   - salience 100
63   - when
64   - ScheduleCalcuParam_input(
65   - fromDate.isBefore(toDate) || fromDate.isEqual(toDate),
66   - $fromDate : fromDate,
67   - $toDate : toDate
68   - )
69   - ScheduleRule_input($ruleId : ruleId, $qyrq : qyrq)
70   - eval((!$qyrq.isBefore($fromDate)) && (!$qyrq.isAfter($toDate)))
71   - then
72   - // 构造Calcu_days_result对象,进行下一阶段计算
73   - Calcu_days_result cdr = new Calcu_days_result();
74   - cdr.setRuleId($ruleId);
75   - cdr.setQyrq_days(0);
76   - Period p2 = new Period($qyrq, $toDate, PeriodType.days());
77   - cdr.setSdays(Integer.valueOf(p2.getDays() + 1));
78   - cdr.setCalcu_start_date($qyrq);
79   - cdr.setCalcu_end_date($toDate);
80   -
81   - log.info("开始日期离启用日期的天数 qyrq_days=0");
82   - log.info("总共需要排班的天数 sdays={}", (p2.getDays() + 1));
83   -
84   - insert(cdr); // 插入fact数据,进入下一个阶段
85   -end
86   -
87   -//------------------------- 第二阶段、计算规则准备数据2(起始索引) ----------------------------//
88   -
89   -//----------------------- 路牌范围循环计算 ------------------------//
90   -
91   -declare Calcu_guideboard_index_result
92   - ruleId : String // 规则Id
93   - calcu_index : Integer // 计算之后的起始索引
94   -end
95   -
96   -// 启用日期等于开始日期
97   -rule "calcu_guideboard_index_qyrq_eq_startrq"
98   - when
99   - $calcu_days_result : Calcu_days_result(
100   - qyrq_days == 0,
101   - $ruleId: ruleId
102   - )
103   - $scheduleRule_input : ScheduleRule_input(
104   - ruleId == $ruleId,
105   - $oindex : startGbdIndex
106   - )
107   - then
108   - Calcu_guideboard_index_result cgir = new Calcu_guideboard_index_result();
109   - cgir.setRuleId($ruleId);
110   - cgir.setCalcu_index($oindex);
111   -
112   - log.info("calcu_guideboard_index_qyrq_eq_startrq ruleId={}, calcu_index={}", $ruleId, cgir.getCalcu_index());
113   -
114   - insert(cgir);
115   -end
116   -
117   -// 开始日期大于启用日期
118   -rule "calcu_guideboard_index_startrq_gt_qyrq"
119   - when
120   - $calcu_days_result : Calcu_days_result(
121   - qyrq_days > 0,
122   - $ruleId: ruleId, $qyrq_days: qyrq_days,
123   - $calcu_start_date: calcu_start_date
124   - )
125   - $scheduleRule_input : ScheduleRule_input(
126   - ruleId == $ruleId,
127   - $qyrq: qyrq,
128   - $rangesize : guideboardIds.size(),
129   - $oindex : startGbdIndex,
130   - $weekdays: weekdays
131   - )
132   - then
133   - // 开始时间
134   - DateTime initDate = $qyrq;
135   - int index = $oindex;
136   - int resultIndex = index;
137   -
138   - while (!initDate.isAfter($calcu_start_date)) {
139   - if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue()) {
140   - resultIndex = index;
141   - index = (index + 1) % $rangesize;
142   - }
143   - initDate = initDate.plusDays(1);
144   - }
145   -
146   - Calcu_guideboard_index_result cgir = new Calcu_guideboard_index_result();
147   - cgir.setRuleId($ruleId);
148   - cgir.setCalcu_index(resultIndex);
149   -
150   - log.info("calcu_guideboard_index_startrq_gt_qyrq ruleId={}, calcu_index={}", $ruleId, cgir.getCalcu_index());
151   -
152   - insert(cgir);
153   -end
154   -
155   -//----------------------- 人员范围循环计算 ------------------------//
156   -
157   -declare Calcu_employee_index_result
158   - ruleId : String // 规则Id
159   - calcu_index : Integer // 计算之后的起始索引
160   -end
161   -
162   -// 启用日期等于开始日期
163   -rule "calcu_employee_index_qyrq_eq_startrq"
164   - when
165   - $calcu_days_result : Calcu_days_result(
166   - qyrq_days == 0,
167   - $ruleId: ruleId)
168   - $scheduleRule_input : ScheduleRule_input(
169   - ruleId == $ruleId,
170   - $oindex : startEIndex)
171   - then
172   - Calcu_employee_index_result cgir = new Calcu_employee_index_result();
173   - cgir.setRuleId($ruleId);
174   - cgir.setCalcu_index($oindex);
175   -
176   - log.info("calcu_employee_index_qyrq_eq_startrq ruleId={}, calcu_index={}", $ruleId, cgir.getCalcu_index());
177   -
178   - insert(cgir);
179   -end
180   -
181   -// 开始日期大于启用日期
182   -rule "calcu_employee_index_startrq_gt_qyrq"
183   - when
184   - $calcu_days_result : Calcu_days_result(
185   - qyrq_days > 0,
186   - $ruleId: ruleId, $qyrq_days: qyrq_days,
187   - $calcu_start_date: calcu_start_date
188   - )
189   - $scheduleRule_input : ScheduleRule_input(
190   - ruleId == $ruleId,
191   - $qyrq: qyrq,
192   - $rangesize : employeeConfigIds.size(),
193   - $oindex : startEIndex,
194   - $weekdays: weekdays
195   - )
196   - then
197   - // 开始时间
198   - DateTime initDate = $qyrq;
199   - int index = $oindex;
200   - int resultIndex = index;
201   -
202   - while (!initDate.isAfter($calcu_start_date)) {
203   - if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue()) {
204   - resultIndex = index;
205   - index = (index + 1) % $rangesize;
206   - }
207   - initDate = initDate.plusDays(1);
208   - }
209   -
210   - Calcu_employee_index_result cgir = new Calcu_employee_index_result();
211   - cgir.setRuleId($ruleId);
212   - cgir.setCalcu_index(resultIndex);
213   -
214   - log.info("calcu_employee_index_startrq_gt_qyrq ruleId={}, calcu_index={}", $ruleId, cgir.getCalcu_index());
215   -
216   - insert(cgir);
217   -
218   -end
219   -
220   -//------------------------- 第三阶段、循环计算 ------------------------//
221   -
222   -//----------------------- 路牌范围循环计算 ------------------------//
223   -declare loop_guideboard_result
224   - ruleId : String // 规则id
225   - go_list : List // 路牌循环的列表
226   -end
227   -
228   -// 循环路牌计算
229   -rule "Calcu_loop_guideboard_result"
230   - when
231   - Calcu_days_result(
232   - $ruleId: ruleId,
233   - $startDate : calcu_start_date,
234   - $calcu_end_date: calcu_end_date
235   - )
236   - $ruleData : ScheduleRule_input(
237   - ruleId == $ruleId,
238   - $rangesize : guideboardIds.size(),
239   - $weekdays: weekdays
240   - )
241   - $indexData : Calcu_guideboard_index_result(
242   - ruleId == $ruleId
243   - )
244   - then
245   - DateTime initDate = $startDate; // 开始时间
246   - DateTime endDate = $calcu_end_date; // 结束实际
247   - List<ScheduleResult_output> scheduleResult_outputs =
248   - new ArrayList<ScheduleResult_output>();
249   -
250   - int i = $indexData.getCalcu_index();
251   - if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue() == false) {
252   - i = (i + 1) % $rangesize;
253   - }
254   -
255   - while (!initDate.isAfter(endDate)) {
256   - if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue()) {
257   - ScheduleResult_output ro = new ScheduleResult_output();
258   - ro.setRuleId($ruleId);
259   - ro.setSd(initDate);
260   - ro.setGuideboardId($ruleData.getGuideboardIds().get(i));
261   - ro.setCarConfigId($ruleData.getCarConfigId());
262   - scheduleResult_outputs.add(ro);
263   -
264   - i = (i + 1) % $rangesize;
265   - }
266   -
267   - initDate = initDate.plusDays(1);
268   - }
269   -
270   - loop_guideboard_result clgr = new loop_guideboard_result();
271   - clgr.setRuleId($ruleId);
272   - clgr.setGo_list(scheduleResult_outputs);
273   -
274   - log.info(String.valueOf(scheduleResult_outputs.size()));
275   -
276   - insert(clgr);
277   -
278   -end
279   -
280   -//----------------------- 人员范围循环计算 ------------------------//
281   -declare loop_employee_result
282   - ruleId : String // 规则id
283   - eo_list : List // 人员循环的列表
284   -end
285   -
286   -// 循环人员计算
287   -rule "Calcu_loop_employee_result"
288   - when
289   - Calcu_days_result(
290   - $ruleId: ruleId,
291   - $startDate : calcu_start_date,
292   - $calcu_end_date: calcu_end_date
293   - )
294   - $ruleData : ScheduleRule_input(
295   - ruleId == $ruleId,
296   - $rangesize : employeeConfigIds.size(),
297   - $weekdays: weekdays
298   - )
299   - $indexData : Calcu_employee_index_result(
300   - ruleId == $ruleId
301   - )
302   - then
303   - DateTime initDate = $startDate; // 开始时间
304   - DateTime endDate = $calcu_end_date; // 结束实际
305   - List<ScheduleResult_output> scheduleResult_outputs =
306   - new ArrayList<ScheduleResult_output>();
307   -
308   - int i = $indexData.getCalcu_index();
309   - if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue() == false) {
310   - i = (i + 1) % $rangesize;
311   - }
312   -
313   - while (!initDate.isAfter(endDate)) {
314   - if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue()) {
315   - ScheduleResult_output ro = new ScheduleResult_output();
316   - ro.setRuleId($ruleId);
317   - ro.setSd(initDate);
318   - ro.setEmployeeConfigId($ruleData.getEmployeeConfigIds().get(i));
319   - ro.setCarConfigId($ruleData.getCarConfigId());
320   - scheduleResult_outputs.add(ro);
321   -
322   - i = (i + 1) % $rangesize;
323   - }
324   -
325   - initDate = initDate.plusDays(1);
326   - }
327   -
328   - loop_employee_result clgr = new loop_employee_result();
329   - clgr.setRuleId($ruleId);
330   - clgr.setEo_list(scheduleResult_outputs);
331   -
332   - log.info(String.valueOf(scheduleResult_outputs.size()));
333   -
334   - insert(clgr);
335   -end
336   -
337   -//------------------------- 第四阶段、范围组循环计算 ----------------------------//
338   -
339   -global ScheduleResults_output scheduleResult;
340   -
341   -rule "output"
342   - when
343   - loop_guideboard_result(
344   - go_list.size() > 0,
345   - $ruleId : ruleId, $go_list : go_list
346   - )
347   - loop_employee_result(
348   - ruleId == $ruleId,
349   - eo_list.size() == $go_list.size(),
350   - $eo_list : eo_list
351   - )
352   - then
353   - for (int i = 0; i < $go_list.size(); i++) {
354   - ScheduleResult_output go = (ScheduleResult_output) $go_list.get(i);
355   - ScheduleResult_output eo = (ScheduleResult_output) $eo_list.get(i);
356   - go.setEmployeeConfigId(eo.getEmployeeConfigId());
357   - scheduleResult.getResults().add(go);
358   - }
359   -
360   -end
361   -
362   -
363   -
364   -
365   -
366   -
367   -
368   -
369   -
370   -
371   -
372   -
373   -
374   -
375   -
376   -
  1 +package com.bsth.service.schedule.shiftloop;
  2 +
  3 +import org.joda.time.*;
  4 +import java.util.*;
  5 +
  6 +import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input;
  7 +import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input;
  8 +import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
  9 +import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
  10 +
  11 +import org.slf4j.Logger;
  12 +
  13 +global Logger log;
  14 +
  15 +/*
  16 + 存在(翻班格式)
  17 +*/
  18 +
  19 +//------------------------- 第一阶段、计算规则准备数据(天数) ----------------------------//
  20 +
  21 +declare Calcu_days_result
  22 + ruleId : String // 规则Id
  23 + qyrq_days : Integer // 开始日期离启用日期的天数
  24 + sdays : Integer // 总共需要排班的天数
  25 + calcu_start_date : DateTime // 开始计算日期
  26 + calcu_end_date : DateTime // 结束计算日期
  27 +end
  28 +
  29 +/*
  30 + 计算启用日期,开始计算日期,结束计算日期,相差天数
  31 + 1、规则启用日期小于开始计算日期
  32 + 2、规则启用日期大于等于开始日期,小于等于结束日期
  33 +*/
  34 +rule "calcu_days_1"
  35 + salience 100
  36 + when
  37 + ScheduleCalcuParam_input(
  38 + fromDate.isBefore(toDate) || fromDate.isEqual(toDate),
  39 + $fromDate : fromDate,
  40 + $toDate : toDate
  41 + )
  42 + ScheduleRule_input($ruleId : ruleId, $qyrq : qyrq)
  43 + eval($qyrq.isBefore($fromDate))
  44 + then
  45 + // 构造Calcu_days_result对象,进行下一阶段计算
  46 + Calcu_days_result cdr = new Calcu_days_result();
  47 + cdr.setRuleId($ruleId);
  48 + Period p1 = new Period($qyrq, $fromDate, PeriodType.days());
  49 + cdr.setQyrq_days(p1.getDays());
  50 + Period p2 = new Period($fromDate, $toDate, PeriodType.days());
  51 + cdr.setSdays(p2.getDays() + 1);
  52 + cdr.setCalcu_start_date($fromDate);
  53 + cdr.setCalcu_end_date($toDate);
  54 +
  55 + log.info("开始日期离启用日期的天数 qyrq_days={}", p1.getDays());
  56 + log.info("总共需要排班的天数 sdays={}", (p2.getDays() + 1));
  57 +
  58 + insert(cdr); // 插入fact数据,进入下一个阶段
  59 +end
  60 +
  61 +rule "calcu_days_2"
  62 + salience 100
  63 + when
  64 + ScheduleCalcuParam_input(
  65 + fromDate.isBefore(toDate) || fromDate.isEqual(toDate),
  66 + $fromDate : fromDate,
  67 + $toDate : toDate
  68 + )
  69 + ScheduleRule_input($ruleId : ruleId, $qyrq : qyrq)
  70 + eval((!$qyrq.isBefore($fromDate)) && (!$qyrq.isAfter($toDate)))
  71 + then
  72 + // 构造Calcu_days_result对象,进行下一阶段计算
  73 + Calcu_days_result cdr = new Calcu_days_result();
  74 + cdr.setRuleId($ruleId);
  75 + cdr.setQyrq_days(0);
  76 + Period p2 = new Period($qyrq, $toDate, PeriodType.days());
  77 + cdr.setSdays(Integer.valueOf(p2.getDays() + 1));
  78 + cdr.setCalcu_start_date($qyrq);
  79 + cdr.setCalcu_end_date($toDate);
  80 +
  81 + log.info("开始日期离启用日期的天数 qyrq_days=0");
  82 + log.info("总共需要排班的天数 sdays={}", (p2.getDays() + 1));
  83 +
  84 + insert(cdr); // 插入fact数据,进入下一个阶段
  85 +end
  86 +
  87 +//------------------------- 第二阶段、计算规则准备数据2(起始索引) ----------------------------//
  88 +
  89 +//----------------------- 路牌范围循环计算 ------------------------//
  90 +
  91 +declare Calcu_guideboard_index_result
  92 + ruleId : String // 规则Id
  93 + calcu_index : Integer // 计算之后的起始索引
  94 +end
  95 +
  96 +// 启用日期等于开始日期
  97 +rule "calcu_guideboard_index_qyrq_eq_startrq"
  98 + when
  99 + $calcu_days_result : Calcu_days_result(
  100 + qyrq_days == 0,
  101 + $ruleId: ruleId
  102 + )
  103 + $scheduleRule_input : ScheduleRule_input(
  104 + ruleId == $ruleId,
  105 + $oindex : startGbdIndex
  106 + )
  107 + then
  108 + Calcu_guideboard_index_result cgir = new Calcu_guideboard_index_result();
  109 + cgir.setRuleId($ruleId);
  110 + cgir.setCalcu_index($oindex);
  111 +
  112 + log.info("calcu_guideboard_index_qyrq_eq_startrq ruleId={}, calcu_index={}", $ruleId, cgir.getCalcu_index());
  113 +
  114 + insert(cgir);
  115 +end
  116 +
  117 +// 开始日期大于启用日期
  118 +rule "calcu_guideboard_index_startrq_gt_qyrq"
  119 + when
  120 + $calcu_days_result : Calcu_days_result(
  121 + qyrq_days > 0,
  122 + $ruleId: ruleId, $qyrq_days: qyrq_days,
  123 + $calcu_start_date: calcu_start_date
  124 + )
  125 + $scheduleRule_input : ScheduleRule_input(
  126 + ruleId == $ruleId,
  127 + $qyrq: qyrq,
  128 + $rangesize : guideboardIds.size(),
  129 + $oindex : startGbdIndex,
  130 + $weekdays: weekdays
  131 + )
  132 + then
  133 + // 开始时间
  134 + DateTime initDate = $qyrq;
  135 + int index = $oindex;
  136 + int resultIndex = index;
  137 +
  138 + while (!initDate.isAfter($calcu_start_date)) {
  139 + if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue()) {
  140 + resultIndex = index;
  141 + index = (index + 1) % $rangesize;
  142 + }
  143 + initDate = initDate.plusDays(1);
  144 + }
  145 +
  146 + Calcu_guideboard_index_result cgir = new Calcu_guideboard_index_result();
  147 + cgir.setRuleId($ruleId);
  148 + cgir.setCalcu_index(resultIndex);
  149 +
  150 + log.info("calcu_guideboard_index_startrq_gt_qyrq ruleId={}, calcu_index={}", $ruleId, cgir.getCalcu_index());
  151 +
  152 + insert(cgir);
  153 +end
  154 +
  155 +//----------------------- 人员范围循环计算 ------------------------//
  156 +
  157 +declare Calcu_employee_index_result
  158 + ruleId : String // 规则Id
  159 + calcu_index : Integer // 计算之后的起始索引
  160 +end
  161 +
  162 +// 启用日期等于开始日期
  163 +rule "calcu_employee_index_qyrq_eq_startrq"
  164 + when
  165 + $calcu_days_result : Calcu_days_result(
  166 + qyrq_days == 0,
  167 + $ruleId: ruleId)
  168 + $scheduleRule_input : ScheduleRule_input(
  169 + ruleId == $ruleId,
  170 + $oindex : startEIndex)
  171 + then
  172 + Calcu_employee_index_result cgir = new Calcu_employee_index_result();
  173 + cgir.setRuleId($ruleId);
  174 + cgir.setCalcu_index($oindex);
  175 +
  176 + log.info("calcu_employee_index_qyrq_eq_startrq ruleId={}, calcu_index={}", $ruleId, cgir.getCalcu_index());
  177 +
  178 + insert(cgir);
  179 +end
  180 +
  181 +// 开始日期大于启用日期
  182 +rule "calcu_employee_index_startrq_gt_qyrq"
  183 + when
  184 + $calcu_days_result : Calcu_days_result(
  185 + qyrq_days > 0,
  186 + $ruleId: ruleId, $qyrq_days: qyrq_days,
  187 + $calcu_start_date: calcu_start_date
  188 + )
  189 + $scheduleRule_input : ScheduleRule_input(
  190 + ruleId == $ruleId,
  191 + $qyrq: qyrq,
  192 + $rangesize : employeeConfigIds.size(),
  193 + $oindex : startEIndex,
  194 + $weekdays: weekdays
  195 + )
  196 + then
  197 + // 开始时间
  198 + DateTime initDate = $qyrq;
  199 + int index = $oindex;
  200 + int resultIndex = index;
  201 +
  202 + while (!initDate.isAfter($calcu_start_date)) {
  203 + if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue()) {
  204 + resultIndex = index;
  205 + index = (index + 1) % $rangesize;
  206 + }
  207 + initDate = initDate.plusDays(1);
  208 + }
  209 +
  210 + Calcu_employee_index_result cgir = new Calcu_employee_index_result();
  211 + cgir.setRuleId($ruleId);
  212 + cgir.setCalcu_index(resultIndex);
  213 +
  214 + log.info("calcu_employee_index_startrq_gt_qyrq ruleId={}, calcu_index={}", $ruleId, cgir.getCalcu_index());
  215 +
  216 + insert(cgir);
  217 +
  218 +end
  219 +
  220 +//------------------------- 第三阶段、循环计算 ------------------------//
  221 +
  222 +//----------------------- 路牌范围循环计算 ------------------------//
  223 +declare loop_guideboard_result
  224 + ruleId : String // 规则id
  225 + go_list : List // 路牌循环的列表
  226 +end
  227 +
  228 +// 循环路牌计算
  229 +rule "Calcu_loop_guideboard_result"
  230 + when
  231 + Calcu_days_result(
  232 + $ruleId: ruleId,
  233 + $startDate : calcu_start_date,
  234 + $calcu_end_date: calcu_end_date
  235 + )
  236 + $ruleData : ScheduleRule_input(
  237 + ruleId == $ruleId,
  238 + $rangesize : guideboardIds.size(),
  239 + $weekdays: weekdays
  240 + )
  241 + $indexData : Calcu_guideboard_index_result(
  242 + ruleId == $ruleId
  243 + )
  244 + then
  245 + DateTime initDate = $startDate; // 开始时间
  246 + DateTime endDate = $calcu_end_date; // 结束实际
  247 + List<ScheduleResult_output> scheduleResult_outputs =
  248 + new ArrayList<ScheduleResult_output>();
  249 +
  250 + int i = $indexData.getCalcu_index();
  251 + if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue() == false) {
  252 + i = (i + 1) % $rangesize;
  253 + }
  254 +
  255 + while (!initDate.isAfter(endDate)) {
  256 + if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue()) {
  257 + ScheduleResult_output ro = new ScheduleResult_output();
  258 + ro.setRuleId($ruleId);
  259 + ro.setSd(initDate);
  260 + ro.setGuideboardId($ruleData.getGuideboardIds().get(i));
  261 + ro.setCarConfigId($ruleData.getCarConfigId());
  262 + scheduleResult_outputs.add(ro);
  263 +
  264 + i = (i + 1) % $rangesize;
  265 + }
  266 +
  267 + initDate = initDate.plusDays(1);
  268 + }
  269 +
  270 + loop_guideboard_result clgr = new loop_guideboard_result();
  271 + clgr.setRuleId($ruleId);
  272 + clgr.setGo_list(scheduleResult_outputs);
  273 +
  274 + log.info(String.valueOf(scheduleResult_outputs.size()));
  275 +
  276 + insert(clgr);
  277 +
  278 +end
  279 +
  280 +//----------------------- 人员范围循环计算 ------------------------//
  281 +declare loop_employee_result
  282 + ruleId : String // 规则id
  283 + eo_list : List // 人员循环的列表
  284 +end
  285 +
  286 +// 循环人员计算
  287 +rule "Calcu_loop_employee_result"
  288 + when
  289 + Calcu_days_result(
  290 + $ruleId: ruleId,
  291 + $startDate : calcu_start_date,
  292 + $calcu_end_date: calcu_end_date
  293 + )
  294 + $ruleData : ScheduleRule_input(
  295 + ruleId == $ruleId,
  296 + $rangesize : employeeConfigIds.size(),
  297 + $weekdays: weekdays
  298 + )
  299 + $indexData : Calcu_employee_index_result(
  300 + ruleId == $ruleId
  301 + )
  302 + then
  303 + DateTime initDate = $startDate; // 开始时间
  304 + DateTime endDate = $calcu_end_date; // 结束实际
  305 + List<ScheduleResult_output> scheduleResult_outputs =
  306 + new ArrayList<ScheduleResult_output>();
  307 +
  308 + int i = $indexData.getCalcu_index();
  309 + if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue() == false) {
  310 + i = (i + 1) % $rangesize;
  311 + }
  312 +
  313 + while (!initDate.isAfter(endDate)) {
  314 + if (((Boolean) $weekdays.get(initDate.getDayOfWeek() - 1)).booleanValue()) {
  315 + ScheduleResult_output ro = new ScheduleResult_output();
  316 + ro.setRuleId($ruleId);
  317 + ro.setSd(initDate);
  318 + ro.setEmployeeConfigId($ruleData.getEmployeeConfigIds().get(i));
  319 + ro.setCarConfigId($ruleData.getCarConfigId());
  320 + scheduleResult_outputs.add(ro);
  321 +
  322 + i = (i + 1) % $rangesize;
  323 + }
  324 +
  325 + initDate = initDate.plusDays(1);
  326 + }
  327 +
  328 + loop_employee_result clgr = new loop_employee_result();
  329 + clgr.setRuleId($ruleId);
  330 + clgr.setEo_list(scheduleResult_outputs);
  331 +
  332 + log.info(String.valueOf(scheduleResult_outputs.size()));
  333 +
  334 + insert(clgr);
  335 +end
  336 +
  337 +//------------------------- 第四阶段、范围组循环计算 ----------------------------//
  338 +
  339 +global ScheduleResults_output scheduleResult;
  340 +
  341 +rule "output"
  342 + when
  343 + loop_guideboard_result(
  344 + go_list.size() > 0,
  345 + $ruleId : ruleId, $go_list : go_list
  346 + )
  347 + loop_employee_result(
  348 + ruleId == $ruleId,
  349 + eo_list.size() == $go_list.size(),
  350 + $eo_list : eo_list
  351 + )
  352 + then
  353 + for (int i = 0; i < $go_list.size(); i++) {
  354 + ScheduleResult_output go = (ScheduleResult_output) $go_list.get(i);
  355 + ScheduleResult_output eo = (ScheduleResult_output) $eo_list.get(i);
  356 + go.setEmployeeConfigId(eo.getEmployeeConfigId());
  357 + scheduleResult.getResults().add(go);
  358 + }
  359 +
  360 +end
  361 +
  362 +
  363 +
  364 +
  365 +
  366 +
  367 +
  368 +
  369 +
  370 +
  371 +
  372 +
  373 +
  374 +
  375 +
  376 +
... ...
src/test/java/com/bsth/service/schedule/rules/DroolsRulesTest2.java
1   -package com.bsth.service.schedule.rules;
2   -
3   -import com.bsth.Application;
4   -import org.junit.runner.RunWith;
5   -import org.kie.api.KieBase;
6   -import org.springframework.beans.factory.annotation.Autowired;
7   -import org.springframework.boot.test.SpringApplicationConfiguration;
8   -import org.springframework.context.annotation.ComponentScan;
9   -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10   -
11   -/**
12   - * 测试类。
13   - */
14   -@RunWith(SpringJUnit4ClassRunner.class)
15   -@SpringApplicationConfiguration(classes = {Application.class})
16   -@ComponentScan(basePackages = {"com.bsth.entity"})
17   -public class DroolsRulesTest2 {
18   - @Autowired
19   - private KieBase kieBase;
20   -
21   - @org.junit.Test
22   - public void test1() throws Exception {
23   - System.out.println("dfdfdfdfd");
24   - }
25   -
26   -}
  1 +package com.bsth.service.schedule.rules;
  2 +
  3 +import com.bsth.Application;
  4 +import org.junit.runner.RunWith;
  5 +import org.kie.api.KieBase;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.boot.test.SpringApplicationConfiguration;
  8 +import org.springframework.context.annotation.ComponentScan;
  9 +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  10 +
  11 +/**
  12 + * 测试类。
  13 + */
  14 +@RunWith(SpringJUnit4ClassRunner.class)
  15 +@SpringApplicationConfiguration(classes = {Application.class})
  16 +@ComponentScan(basePackages = {"com.bsth.entity"})
  17 +public class DroolsRulesTest2 {
  18 + @Autowired
  19 + private KieBase kieBase;
  20 +
  21 + @org.junit.Test
  22 + public void test1() throws Exception {
  23 + System.out.println("dfdfdfdfd");
  24 + }
  25 +
  26 +}
... ...