Commit c3bea204c99856e9f6537dcfe166406ec9a4dfbe

Authored by 潘钊
2 parents effe23c8 4e501eed

Merge branch 'minhang' of http://222.66.0.204:8090/panzhaov5/bsth_control into minhang

src/main/java/com/bsth/controller/oil/YlbController.java
... ... @@ -163,8 +163,8 @@ public class YlbController extends BaseController<Ylb, Integer>{
163 163 }
164 164  
165 165 @RequestMapping(value = "/sumYlb",method = RequestMethod.GET)
166   - public List<Object[]> sumYlb(@RequestParam Map<String, Object> map){
167   - List<Object[]> list=yblService.sumYlb(map);
  166 + public Map<String, Object> sumYlb(@RequestParam Map<String, Object> map){
  167 + Map<String, Object> list=yblService.sumYlb(map);
168 168 return list;
169 169 }
170 170  
... ...
src/main/java/com/bsth/entity/oil/Ylb.java
... ... @@ -30,7 +30,7 @@ public class Ylb {
30 30 private Double jzlc=0.0;
31 31 private Double czyl=0.0;
32 32 private Double jzyl=0.0;
33   - private Double jzl;
  33 + private Double jzl=0.0;
34 34 private int sfkt;
35 35 private String jhsj;
36 36 private Double yh=0.0;
... ...
src/main/java/com/bsth/repository/oil/YlbRepository.java
... ... @@ -51,7 +51,7 @@ public interface YlbRepository extends BaseRepository&lt;Ylb, Integer&gt;{
51 51 */
52 52 @Transactional
53 53 @Modifying
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)
  54 + @Query(value="select ifnull(jzl,0),ifnull(zlc,0),ifnull(sh,0) from bsth_c_ylb where nbbm=?1 and rq=?2 and xlbm like %?3%",nativeQuery=true)
55 55 List<Object[]> sumLcYl(String nbbm,Date rq,String xlbm);
56 56  
57 57 /**
... ... @@ -71,7 +71,7 @@ public interface YlbRepository extends BaseRepository&lt;Ylb, Integer&gt;{
71 71 List<Object[]> checkNbmmNum(String rq, String gsbm,String fgsbm,String xlbm,String nbbm);
72 72  
73 73  
74   - @Query(value="select sum(s.jzl),sum(s.yh),sum(s.sh) from Ylb s "
  74 + @Query(value="select jzl,yh,sh from Ylb s "
75 75 + " where to_days(?1)=to_days(s.rq) "
76 76 + " and s.ssgsdm like %?2% "
77 77 + " and s.fgsdm like %?3%"
... ... @@ -81,7 +81,7 @@ public interface YlbRepository extends BaseRepository&lt;Ylb, Integer&gt;{
81 81  
82 82 @Transactional
83 83 @Modifying
84   - @Query(value="select sum(jzl),sum(yh),sum(sh) from bsth_c_ylb "
  84 + @Query(value="select ifnull(jzl,0),ifnull(yh,0),ifnull(sh,0) from bsth_c_ylb "
85 85 + " where to_days(?1)=to_days(rq) "
86 86 + " and ssgsdm like %?2% "
87 87 + " and fgsdm like %?3%"
... ...
src/main/java/com/bsth/repository/schedule/SchedulePlanInfoRepository.java
... ... @@ -49,7 +49,7 @@ public interface SchedulePlanInfoRepository extends BaseRepository&lt;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/oil/YlbService.java
... ... @@ -15,7 +15,7 @@ public interface YlbService extends BaseService&lt;Ylb, Integer&gt;{
15 15  
16 16 Map<String, Object> checkYl(Map<String, Object> map);
17 17  
18   - List<Object[]> sumYlb(Map<String, Object> map);
  18 + Map<String, Object> sumYlb(Map<String, Object> map);
19 19  
20 20 List<Ylb> oilListMonth(String line,String date);
21 21  
... ...
src/main/java/com/bsth/service/oil/impl/YlbServiceImpl.java
... ... @@ -38,6 +38,7 @@ import com.bsth.repository.oil.YlxxbRepository;
38 38 import com.bsth.service.impl.BaseServiceImpl;
39 39 import com.bsth.service.oil.YlbService;
40 40 import com.bsth.service.realcontrol.ScheduleRealInfoService;
  41 +import com.bsth.util.Arith;
41 42 import com.bsth.util.BatchSaveUtils;
42 43 import com.github.abel533.echarts.code.Y;
43 44  
... ... @@ -298,9 +299,16 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
298 299 Ylxxb ylxxb = ylxxList.get(j);
299 300 if (map.get("clZbh").toString().equals(ylxxb.getNbbm())
300 301 && map.get("jGh").toString().equals(ylxxb.getJsy())) {
301   - jzl += ylxxb.getJzl();
  302 +// jzl += ylxxb.getJzl();
  303 + jzl =Arith.add(jzl, ylxxb.getJzl());
302 304 }
303 305 }
  306 + if(map.get("clZbh").toString().equals("W0A-212")){
  307 + System.out.println();
  308 + }
  309 + if(map.get("clZbh").toString().equals("W0A-211")){
  310 + System.out.println();
  311 + }
304 312 t.setJzl(jzl);
305 313 t.setNbbm(map.get("clZbh").toString());
306 314 t.setJsy(map.get("jGh") == null ? "" : map.get("jGh").toString());
... ... @@ -389,13 +397,17 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
389 397 // 得到一天总的加油和里程(根据车,时间)
390 398 List<Object[]> sumList = repository.sumLcYl(nbbm_eq, rq_eq,ylb.getXlbm());
391 399 // 保存总的加油量
392   - Double jzl = Double.valueOf(sumList.get(0)[0].toString());
  400 + Double jzl = 0.0;
393 401 // 保存总的里程
394   - Double zlc = Double.valueOf(sumList.get(0)[1].toString());
395   -
396   - Double zsh = Double.valueOf(sumList.get(0)[2].toString());
397   -
398   - jzl=jzl-zsh;
  402 + Double zlc = 0.0;
  403 + //保存总的损耗
  404 + Double zsh = 0.0;
  405 + for (int j = 0; j < sumList.size(); j++) {
  406 + jzl = Arith.add(jzl, Double.valueOf(sumList.get(j)[0].toString()));
  407 + zlc = Arith.add(zlc, Double.valueOf(sumList.get(j)[1].toString()));
  408 + zsh = Arith.add(zsh, Double.valueOf(sumList.get(j)[2].toString()));
  409 + }
  410 + jzl = Arith.sub(jzl, zsh);
399 411 // 保留两位小数
400 412 DecimalFormat df = new DecimalFormat("#.00");
401 413 Double zyl = 0.0;
... ... @@ -417,17 +429,23 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
417 429 // 进场等于出场的操作 既 最后进场存油量等于第一次的出场存油量
418 430 Double yl = t.getCzyl();
419 431 Double jcyl = t.getCzyl();
420   - zyl = jcyl + jzl - yl;
  432 +// zyl = jcyl + jzl - yl;
  433 + zyl =Arith.sub( Arith.add(jcyl, jzl),yl);
421 434 Double yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
422 435 t.setYh(yh);
423   - nextJzyl = t.getJzl() + t.getCzyl() - yh;
424   - t.setJzyl(Double.parseDouble(df.format(nextJzyl)));
  436 +// nextJzyl = t.getJzl() + t.getCzyl() - yh;
  437 + nextJzyl =Arith.sub( Arith.add(t.getJzl(), t.getCzyl()),yh);
  438 +// t.setJzyl(Double.parseDouble(df.format(nextJzyl)));
  439 + t.setJzyl(nextJzyl);
425 440 } else {
426   - t.setCzyl(Double.parseDouble(df.format(nextJzyl)));
  441 +// t.setCzyl(Double.parseDouble(df.format(nextJzyl)));
  442 + t.setCzyl(nextJzyl);
427 443 Double yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
428 444 t.setYh(yh);
429   - nextJzyl = t.getJzl() + nextJzyl - yh;
430   - t.setJzyl(Double.parseDouble(df.format(nextJzyl)));
  445 +// nextJzyl = t.getJzl() + nextJzyl - yh;
  446 + nextJzyl =Arith.sub( Arith.add(t.getJzl(),nextJzyl),yh);
  447 +// t.setJzyl(Double.parseDouble(df.format(nextJzyl)));
  448 + t.setJzyl(nextJzyl);
431 449 }
432 450 repository.save(t);
433 451 }
... ... @@ -490,18 +508,27 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
490 508 // 得到一天总的加油和里程(根据车,时间)
491 509 List<Object[]> sumList = repository.sumLcYl(nbbm_eq, rq_eq,ylb.getXlbm());
492 510 // 保存总的加油量
493   - Double jzl = Double.valueOf(sumList.get(0)[0].toString());
  511 + Double jzl = 0.0;
494 512 // 保存总的里程
495   - Double zlc = Double.valueOf(sumList.get(0)[1].toString());
496   - // 保存总的损耗
497   - Double zsh = Double.valueOf(sumList.get(0)[2].toString());
  513 + Double zlc = 0.0;
  514 + //保存总的损耗
  515 + Double zsh = 0.0;
  516 + for (int j = 0; j < sumList.size(); j++) {
  517 + jzl = Arith.add(jzl, Double.valueOf(sumList.get(j)[0].toString()));
  518 + zlc = Arith.add(zlc, Double.valueOf(sumList.get(j)[1].toString()));
  519 + zsh = Arith.add(zsh, Double.valueOf(sumList.get(j)[2].toString()));
  520 + }
  521 + jzl = Arith.sub(jzl, zsh);
498 522  
499 523 //新的 损耗不等于 旧的损耗 总损耗从新算
500   - if(ylb.getSh() - sh >0.0000001 || ylb.getSh()-sh <0.00000001){
501   - zsh =zsh-ylb.getSh()+sh;
502   - jzl =jzl-zsh;
  524 + if(Arith.sub(ylb.getSh(),sh )!=0){
  525 +// zsh =zsh-ylb.getSh()+sh;
  526 + zsh =Arith.add(Arith.sub(zsh, ylb.getSh()), sh);
  527 +// jzl =jzl-zsh;
  528 + jzl =Arith.sub(jzl, zsh);
503 529 }else{
504   - jzl=jzl-zsh;
  530 +// jzl=jzl-zsh;
  531 + jzl =Arith.sub(jzl, zsh);
505 532 }
506 533 map.put("nbbm_eq", nbbm_eq);
507 534 map.put("rq_eq", rq_eq);
... ... @@ -523,25 +550,31 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
523 550 t.setShyy(shyy);
524 551 }
525 552 Double jcyl = t.getCzyl();
526   - zyl = jcyl + jzl - yl;
  553 +// zyl = jcyl + jzl - yl;
  554 + zyl = Arith.sub(Arith.add(jcyl, jzl), yl);
527 555 Double yh = 0.0;
528 556 if (zlc > 0 && t.getZlc() > 0) {
529 557 yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
530 558 }
531 559 t.setYh(yh);
532   - nextJzyl = t.getJzl() + t.getCzyl() - yh-t.getSh();
533   - t.setJzyl(Double.parseDouble(df.format(nextJzyl)));
  560 +// nextJzyl = t.getJzl() + t.getCzyl() - yh-t.getSh();
  561 + nextJzyl =Arith.sub(Arith.add(t.getJzl(), t.getCzyl()), Arith.add(yh, t.getSh()));
  562 +// t.setJzyl(Double.parseDouble(df.format(nextJzyl)));
  563 + t.setJzyl(nextJzyl);
534 564 } else {
535 565 if(t.getId()==id){
536 566 t.setSh(sh);
537 567 t.setShyy(shyy);
538 568 }
539 569 if (t.getZlc() != 0) {
540   - t.setCzyl(Double.parseDouble(df.format(nextJzyl)));
  570 +// t.setCzyl(Double.parseDouble(df.format(nextJzyl)));
  571 + t.setCzyl(nextJzyl);
541 572 Double yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
542 573 t.setYh(yh);
543   - nextJzyl = t.getJzl() + nextJzyl - yh-t.getSh();
544   - t.setJzyl(Double.parseDouble(df.format(nextJzyl)));
  574 +// nextJzyl = t.getJzl() + nextJzyl - yh-t.getSh();
  575 + nextJzyl = Arith.sub(Arith.add(t.getJzl(), nextJzyl), Arith.add(yh, t.getSh()));
  576 +// t.setJzyl(Double.parseDouble(df.format(nextJzyl)));
  577 + t.setJzyl(nextJzyl);
545 578 }
546 579  
547 580 }
... ... @@ -642,7 +675,8 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
642 675 for(int z=0;z<cylList.size();z++){
643 676 cyl=cylList.get(z);
644 677 if(t.getNbbm().equals(cyl.getNbbm())){
645   - cyl.setCyl(cyl.getCyl()+t.getJzl());
  678 +// cyl.setCyl(cyl.getCyl()+t.getJzl());
  679 + cyl.setCyl(Arith.add(cyl.getCyl(),t.getJzl()));
646 680 cyl.setUpdatetime(t.getRq());
647 681 status=true;
648 682 break;
... ... @@ -734,7 +768,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
734 768  
735 769  
736 770 @Override
737   - public List<Object[]> sumYlb(Map<String, Object> map) {
  771 + public Map<String, Object> sumYlb(Map<String, Object> map) {
738 772 // TODO Auto-generated method stub
739 773 List<String> stringList=new ArrayList<String>();
740 774 String rq=map.get("rq").toString();
... ... @@ -784,7 +818,17 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
784 818  
785 819 }
786 820  
  821 + Double jzl=0.0,yh=0.0,sh=0.0;
  822 + for (int i = 0; i < sumYlbList.size(); i++) {
  823 + jzl = Arith.add(jzl, Double.valueOf(sumYlbList.get(i)[0].toString()));
  824 + yh = Arith.add(yh, Double.valueOf(sumYlbList.get(i)[1].toString()));
  825 + sh = Arith.add(sh, Double.valueOf(sumYlbList.get(i)[2].toString()));
  826 + }
787 827  
  828 + Map<String, Object> sumMap=new HashMap<String,Object>();
  829 + sumMap.put("jzl", jzl);
  830 + sumMap.put("yh", yh);
  831 + sumMap.put("sh", sh);
788 832 // String sql="select sum(jzl),sum(yh),sum(sh) from bsth_c_ylb "
789 833 // + " where to_days('"+map.get("rq").toString()+"')=to_days(rq) "
790 834 // + " and ssgsdm like '%"+map.get("ssgsdm_like").toString()+"%' "
... ... @@ -794,7 +838,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
794 838 // if(map.get("nbbm_in")!=null){
795 839 //// sql +=" and nbbm in ("
796 840 // }
797   - return sumYlbList;
  841 + return sumMap;
798 842 }
799 843  
800 844  
... ...
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
... ... @@ -1530,7 +1530,26 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1530 1530 listSchedule.add(s);
1531 1531 //计算营运里程,空驶里程
1532 1532 if (!childTaskPlans.isEmpty()) {
1533   - String sqlPc = "select * from bsth_c_s_child_task where schedule=" + s.getId() + " order by start_date ";
  1533 + Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
  1534 + while (it.hasNext()) {
  1535 + ScheduleRealInfo t = new ScheduleRealInfo();
  1536 + ChildTaskPlan childTaskPlan = it.next();
  1537 + if (childTaskPlan.isDestroy()) {
  1538 + t.setFcsjActual("");
  1539 + t.setZdsjActual("");
  1540 + t.setJhlc(0.0);
  1541 + } else {
  1542 + t.setFcsjActual(childTaskPlan.getStartDate());
  1543 + t.setZdsjActual(childTaskPlan.getEndDate());
  1544 + t.setJhlc(Double.parseDouble(String.valueOf(childTaskPlan.getMileage())));
  1545 + }
  1546 + t.setQdzName(childTaskPlan.getStartStationName());
  1547 + t.setZdzName(childTaskPlan.getEndStationName());
  1548 + t.setRemarks(childTaskPlan.getRemarks());
  1549 + t.setAdjustExps("子");
  1550 + listSchedule.add(t);
  1551 + }
  1552 + /* String sqlPc = "select * from bsth_c_s_child_task where schedule=" + s.getId() + " order by start_date ";
1534 1553 List<ScheduleRealInfo> lists = jdbcTemplate.query(sqlPc,
1535 1554 new RowMapper<ScheduleRealInfo>() {
1536 1555 @Override
... ... @@ -1555,7 +1574,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
1555 1574 for (int j = 0; j < lists.size(); j++) {
1556 1575 ScheduleRealInfo t = lists.get(j);
1557 1576 listSchedule.add(t);
1558   - }
  1577 + }*/
1559 1578 }
1560 1579 }
1561 1580  
... ... @@ -2871,6 +2890,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
2871 2890 }
2872 2891  
2873 2892 public List<Map<String, Object>> yesterdayDataList(String line, String date,String gsbm,String fgsbm,String jGh,String nbbm) {
  2893 +// Arith arith=new Arith();
2874 2894 //前一天日期
2875 2895 // String date = sdfMonth.format(org.apache.commons.lang.time.DateUtils.addDays(new Date(), -1));
2876 2896 // String date = "2016-09-20";
... ... @@ -2885,7 +2905,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
2885 2905 String clZbh = yesterdayDataList.get(x).get("clZbh").toString();
2886 2906  
2887 2907 double jhlc = 0, yygl = 0, ksgl = 0, tempJhlc = 0, jcclc = 0;
2888   - float addMileage = 0l, remMileage = 0l;
  2908 + double addMileage = 0, remMileage = 0;
2889 2909 Map<String, Object> map = new HashMap<String, Object>();
2890 2910 boolean fage = true;
2891 2911 String company="";
... ... @@ -2906,16 +2926,19 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
2906 2926 tempJhlc = scheduleRealInfo.getJhlc() == null ? 0 : scheduleRealInfo.getJhlc();
2907 2927 if (scheduleRealInfo.isSflj()) {
2908 2928 if(scheduleRealInfo.getStatus() == -1){
2909   - addMileage += tempJhlc;
  2929 +// addMileage += tempJhlc;
  2930 + addMileage =Arith.add(addMileage, tempJhlc);
2910 2931 }
2911 2932 } else {
2912 2933 if (!(scheduleRealInfo.getBcType().equals("in")
2913 2934 || scheduleRealInfo.getBcType().equals("out"))) {
2914   - jhlc += tempJhlc;
  2935 +// jhlc += tempJhlc;
  2936 + jhlc =Arith.add(jhlc,tempJhlc);
2915 2937 }
2916 2938  
2917 2939 if (scheduleRealInfo.getStatus() == -1) {
2918   - remMileage += tempJhlc;
  2940 +// remMileage += tempJhlc;
  2941 + remMileage =Arith.add(remMileage,tempJhlc);
2919 2942 }
2920 2943 }
2921 2944 Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();
... ... @@ -2924,7 +2947,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
2924 2947 if (scheduleRealInfo.getBcType().equals("in") ||
2925 2948 scheduleRealInfo.getBcType().equals("out")) {
2926 2949 if (scheduleRealInfo.getStatus() != -1) {
2927   - jcclc += tempJhlc;
  2950 +// jcclc += tempJhlc;
  2951 + jcclc=Arith.add(jcclc,tempJhlc);
2928 2952 }
2929 2953 }
2930 2954 //主任务 放空班次属于营运
... ... @@ -2933,7 +2957,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
2933 2957 // }
2934 2958 else {
2935 2959 if (scheduleRealInfo.getStatus() != -1) {
2936   - yygl += tempJhlc;
  2960 +// yygl += tempJhlc;
  2961 + yygl=Arith.add(yygl,tempJhlc);
2937 2962 }
2938 2963 }
2939 2964 } else {
... ... @@ -2942,15 +2967,21 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
2942 2967 ChildTaskPlan childTaskPlan = it.next();
2943 2968 if (childTaskPlan.getMileageType().equals("empty")) {
2944 2969 if (childTaskPlan.isDestroy()) {
2945   - remMileage += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2970 +// remMileage += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2971 + remMileage=Arith.add(remMileage,childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage());
2946 2972 } else {
2947   - ksgl += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2973 +// ksgl += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2974 + ksgl += Arith.add(ksgl,childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage());
2948 2975 }
2949 2976 } else {
2950 2977 if (childTaskPlan.isDestroy()) {
2951   - remMileage += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2978 +// remMileage += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2979 + remMileage=Arith.add(remMileage,childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage());
  2980 +
2952 2981 } else {
2953   - yygl += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2982 +// yygl += childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage();
  2983 + yygl=Arith.add(yygl,childTaskPlan.getMileage() == null ? 0 : childTaskPlan.getMileage());
  2984 +
2954 2985 }
2955 2986 }
2956 2987 }
... ... @@ -2960,7 +2991,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
2960 2991 }
2961 2992 yesterdayDataList.get(x).put("company", company);
2962 2993 yesterdayDataList.get(x).put("bCompany", bCompany);
2963   - yesterdayDataList.get(x).put("totalKilometers", yygl + ksgl + jcclc);
  2994 + Double zgl=Arith.add(yygl,ksgl);
  2995 + yesterdayDataList.get(x).put("totalKilometers", Arith.add(zgl, jcclc));
2964 2996  
2965 2997 }
2966 2998 System.out.println();
... ...
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&lt;SchedulePlan, Long&gt; 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&lt;SchedulePlan, Long&gt; 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
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 String xlId;
  13 + /** 计划主对象 */
  14 + private SchedulePlan schedulePlan;
  15 + /** 循环规则输出 */
  16 + private ScheduleResults_output scheduleResults_output;
  17 + /** 时刻表选择规则输出 */
  18 + private TTInfoResults_output ttInfoResults_output;
  19 +
  20 + public PlanCalcuParam_input() {
  21 + }
  22 + public PlanCalcuParam_input(
  23 + SchedulePlan schedulePlan,
  24 + ScheduleResults_output scheduleResults_output,
  25 + TTInfoResults_output ttInfoResults_output) {
  26 + this.schedulePlan = schedulePlan;
  27 + this.xlId = String.valueOf(schedulePlan.getXl().getId());
  28 + this.scheduleResults_output = scheduleResults_output;
  29 + this.ttInfoResults_output = ttInfoResults_output;
  30 + }
  31 +
  32 + public String getXlId() {
  33 + return xlId;
  34 + }
  35 +
  36 + public void setXlId(String xlId) {
  37 + this.xlId = xlId;
  38 + }
  39 +
  40 + public ScheduleResults_output getScheduleResults_output() {
  41 + return scheduleResults_output;
  42 + }
  43 +
  44 + public void setScheduleResults_output(ScheduleResults_output scheduleResults_output) {
  45 + this.scheduleResults_output = scheduleResults_output;
  46 + }
  47 +
  48 + public TTInfoResults_output getTtInfoResults_output() {
  49 + return ttInfoResults_output;
  50 + }
  51 +
  52 + public void setTtInfoResults_output(TTInfoResults_output ttInfoResults_output) {
  53 + this.ttInfoResults_output = ttInfoResults_output;
  54 + }
  55 +
  56 + public SchedulePlan getSchedulePlan() {
  57 + return schedulePlan;
  58 + }
  59 +
  60 + public void setSchedulePlan(SchedulePlan schedulePlan) {
  61 + this.schedulePlan = schedulePlan;
  62 + }
  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/java/com/bsth/util/Arith.java 0 → 100644
  1 +package com.bsth.util;
  2 +
  3 +import java.math.BigDecimal;
  4 +
  5 +public class Arith {
  6 + /**
  7 + * 由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精
  8 + * 确的浮点数运算,包括加减乘除和四舍五入。
  9 + */
  10 + //默认除法运算精度
  11 + private static final int DEF_DIV_SCALE = 10;
  12 +
  13 + //这个类不能实例化
  14 + private Arith(){
  15 + }
  16 +
  17 + /**
  18 + * 提供精确的加法运算。
  19 + * @param v1 被加数
  20 + * @param v2 加数
  21 + * @return 两个参数的和
  22 + */
  23 + public static double add(double v1,double v2){
  24 + BigDecimal b1 = new BigDecimal(Double.toString(v1));
  25 + BigDecimal b2 = new BigDecimal(Double.toString(v2));
  26 + return b1.add(b2).doubleValue();
  27 + }
  28 +
  29 + /**
  30 + * 提供精确的减法运算。
  31 + * @param v1 被减数
  32 + * @param v2 减数
  33 + * @return 两个参数的差
  34 + */
  35 + public static double sub(double v1,double v2){
  36 + BigDecimal b1 = new BigDecimal(Double.toString(v1));
  37 + BigDecimal b2 = new BigDecimal(Double.toString(v2));
  38 + return b1.subtract(b2).doubleValue();
  39 + }
  40 +
  41 + /**
  42 + * 提供精确的乘法运算。
  43 + * @param v1 被乘数
  44 + * @param v2 乘数
  45 + * @return 两个参数的积
  46 + */
  47 + public static double mul(double v1,double v2){
  48 + BigDecimal b1 = new BigDecimal(Double.toString(v1));
  49 + BigDecimal b2 = new BigDecimal(Double.toString(v2));
  50 + return b1.multiply(b2).doubleValue();
  51 + }
  52 +
  53 + /**
  54 + * 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到
  55 + * 小数点以后10位,以后的数字四舍五入。
  56 + * @param v1 被除数
  57 + * @param v2 除数
  58 + * @return 两个参数的商
  59 + */
  60 + public static double div(double v1,double v2){
  61 + return div(v1,v2,DEF_DIV_SCALE);
  62 + }
  63 +
  64 + /**
  65 + * 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指
  66 + * 定精度,以后的数字四舍五入。
  67 + * @param v1 被除数
  68 + * @param v2 除数
  69 + * @param scale 表示表示需要精确到小数点以后几位。
  70 + * @return 两个参数的商
  71 + */
  72 + public static double div(double v1,double v2,int scale){
  73 + if(scale<0){
  74 + throw new IllegalArgumentException(
  75 + "The scale must be a positive integer or zero");
  76 + }
  77 + BigDecimal b1 = new BigDecimal(Double.toString(v1));
  78 + BigDecimal b2 = new BigDecimal(Double.toString(v2));
  79 + return b1.divide(b2,scale,BigDecimal.ROUND_HALF_UP).doubleValue();
  80 + }
  81 +
  82 + /**
  83 + * 提供精确的小数位四舍五入处理。
  84 + * @param v 需要四舍五入的数字
  85 + * @param scale 小数点后保留几位
  86 + * @return 四舍五入后的结果
  87 + */
  88 + public static double round(double v,int scale){
  89 + if(scale<0){
  90 + throw new IllegalArgumentException(
  91 + "The scale must be a positive integer or zero");
  92 + }
  93 + BigDecimal b = new BigDecimal(Double.toString(v));
  94 + BigDecimal one = new BigDecimal("1");
  95 + return b.divide(one,scale,BigDecimal.ROUND_HALF_UP).doubleValue();
  96 + }
  97 +
  98 + /**
  99 + * 提供精确的类型转换(Float)
  100 + * @param v 需要被转换的数字
  101 + * @return 返回转换结果
  102 + */
  103 + public static float convertsToFloat(double v){
  104 + BigDecimal b = new BigDecimal(v);
  105 + return b.floatValue();
  106 + }
  107 +
  108 + /**
  109 + * 提供精确的类型转换(Int)不进行四舍五入
  110 + * @param v 需要被转换的数字
  111 + * @return 返回转换结果
  112 + */
  113 + public static int convertsToInt(double v){
  114 + BigDecimal b = new BigDecimal(v);
  115 + return b.intValue();
  116 + }
  117 +
  118 + /**
  119 + * 提供精确的类型转换(Long)
  120 + * @param v 需要被转换的数字
  121 + * @return 返回转换结果
  122 + */
  123 + public static long convertsToLong(double v){
  124 + BigDecimal b = new BigDecimal(v);
  125 + return b.longValue();
  126 + }
  127 +
  128 + /**
  129 + * 返回两个数中大的一个值
  130 + * @param v1 需要被对比的第一个数
  131 + * @param v2 需要被对比的第二个数
  132 + * @return 返回两个数中大的一个值
  133 + */
  134 + public static double returnMax(double v1,double v2){
  135 + BigDecimal b1 = new BigDecimal(v1);
  136 + BigDecimal b2 = new BigDecimal(v2);
  137 + return b1.max(b2).doubleValue();
  138 + }
  139 +
  140 + /**
  141 + * 返回两个数中小的一个值
  142 + * @param v1 需要被对比的第一个数
  143 + * @param v2 需要被对比的第二个数
  144 + * @return 返回两个数中小的一个值
  145 + */
  146 + public static double returnMin(double v1,double v2){
  147 + BigDecimal b1 = new BigDecimal(v1);
  148 + BigDecimal b2 = new BigDecimal(v2);
  149 + return b1.min(b2).doubleValue();
  150 + }
  151 +
  152 + /**
  153 + * 精确对比两个数字
  154 + * @param v1 需要被对比的第一个数
  155 + * @param v2 需要被对比的第二个数
  156 + * @return 如果两个数一样则返回0,如果第一个数比第二个数大则返回1,反之返回-1
  157 + */
  158 + public static int compareTo(double v1,double v2){
  159 + BigDecimal b1 = new BigDecimal(v1);
  160 + BigDecimal b2 = new BigDecimal(v2);
  161 + return b1.compareTo(b2);
  162 + }
  163 +}
... ...
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
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.LineService;
  14 +import com.bsth.service.BusinessService;
  15 +
  16 +import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
  17 +import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
  18 +import com.bsth.service.schedule.rules.ttinfo.TTInfoResult_output;
  19 +import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output;
  20 +import com.bsth.entity.Line;
  21 +import com.bsth.entity.Business;
  22 +
  23 +import com.bsth.entity.schedule.CarConfigInfo;
  24 +import com.bsth.entity.schedule.EmployeeConfigInfo;
  25 +import com.bsth.entity.schedule.TTInfo;
  26 +import com.bsth.entity.schedule.TTInfoDetail;
  27 +import com.bsth.entity.schedule.SchedulePlanInfo;
  28 +
  29 +import org.slf4j.Logger
  30 +import org.joda.time.format.DateTimeFormat
  31 +import org.apache.commons.lang3.StringUtils;
  32 +
  33 +
  34 +// 全局日志类(一般使用调用此规则的service类)
  35 +global Logger log;
  36 +global TTInfoDetailService tTInfoDetailService;
  37 +global TTInfoService tTInfoService;
  38 +global CarConfigInfoService carConfigInfoService;
  39 +global EmployeeConfigInfoService employeeConfigInfoService;
  40 +global LineService lineService;
  41 +global BusinessService businessService;
  42 +
  43 +// 输出
  44 +global PlanResult planResult;
  45 +
  46 +function Map ttidParams(String ttid) {
  47 + Map param = new HashMap();
  48 + param.put("ttinfo.id_eq", Long.parseLong(ttid));
  49 + return param;
  50 +}
  51 +
  52 +function Map xlidParams(String xlid) {
  53 + Map param = new HashMap();
  54 + param.put("xl.id_eq", Integer.valueOf(xlid));
  55 + return param;
  56 +}
  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 +
  79 +/*
  80 + 规则说明:
  81 + 根据循环规则输出,时刻表选择规则输出,组合计算排班明细
  82 +*/
  83 +
  84 +//-------------------- 第一阶段、计算迭代数据 -----------------//
  85 +declare Loop_result
  86 + xlId: String // 线路id
  87 +
  88 + ruleLoop: List // 每天分配的规则 List<ScheduleResult_output>
  89 +
  90 + ttInfoMapLoop_temp: Map // 每天分配的时刻表 Map<DataTime, Collection<TTInfoResult_output>>
  91 + ttInfoMapLoop: Map // 每天分配的时刻表 Map<DataTime, TTInfoResult_output>
  92 + ttInfoMap: Map // 总共用到的时刻表 Map<id, TTInfoResult_output>
  93 +end
  94 +
  95 +rule "calcu_step1_Loop_result"
  96 + salience 1000
  97 + when
  98 + $param: PlanCalcuParam_input($xlId: xlId)
  99 + then
  100 + Loop_result loop_result = new Loop_result();
  101 + loop_result.setXlId($xlId);
  102 + loop_result.setRuleLoop($param.getScheduleResults_output().getResults());
  103 +
  104 + loop_result.setTtInfoMapLoop(new HashMap());
  105 + loop_result.setTtInfoMap(new HashMap());
  106 +
  107 + com.google.common.collect.Multimap ttInfoMap_temp =
  108 + (com.google.common.collect.Multimap)
  109 + $param.getTtInfoResults_output().getResults().get(
  110 + String.valueOf($xlId));
  111 +
  112 + loop_result.setTtInfoMapLoop_temp(ttInfoMap_temp.asMap());
  113 +
  114 + insert(loop_result);
  115 +
  116 + log.info("calcu_step1_Loop_result");
  117 +end
  118 +
  119 +rule "calcu_step2_loop_result"
  120 + salience 1000
  121 + no-loop
  122 + when
  123 + $param: PlanCalcuParam_input($xlId: xlId)
  124 + $lr: Loop_result(xlId == $xlId)
  125 + $sd: DateTime() from $lr.ttInfoMapLoop_temp.keySet()
  126 + then
  127 + // 当天时刻表只取第一张 TODO:
  128 + Collection col = (Collection) $lr.getTtInfoMapLoop_temp().get($sd);
  129 + Iterator iter = col.iterator();
  130 + TTInfoResult_output ttInfo_result = (TTInfoResult_output) iter.next();
  131 + $lr.getTtInfoMapLoop().put($sd, ttInfo_result);
  132 +
  133 + // 总共使用的时刻表
  134 + $lr.getTtInfoMap().put(ttInfo_result.getTtInfoId(), ttInfo_result);
  135 +
  136 + update($lr);
  137 +end
  138 +
  139 +//-------------------- 第二阶段、将时刻表班次,车辆配置,人员配置信息载入 -----------------//
  140 +
  141 +//--------------- 车辆配置信息载入 -------------//
  142 +declare CarConfig_Wrap
  143 + id: String // 车辆配置id(cast字符串-方便比较)
  144 +
  145 + self: CarConfigInfo // 原始数据
  146 +end
  147 +
  148 +rule "calcu_CarConfig_Wrap"
  149 + salience 800
  150 + when
  151 + $lr: Loop_result($xlId: xlId)
  152 + $ccf: CarConfigInfo() from carConfigInfoService.list(xlidParams($xlId))
  153 + then
  154 + CarConfig_Wrap carConfig_wrap = new CarConfig_Wrap();
  155 + carConfig_wrap.setId(String.valueOf($ccf.getId()));
  156 + carConfig_wrap.setSelf($ccf);
  157 +
  158 + insert(carConfig_wrap);
  159 +end
  160 +
  161 +//--------------- 人员配置信息载入 --------------//
  162 +declare EmployeeConfig_Wrap
  163 + id: String // 人员配置id(cast字符串-方便比较)
  164 +
  165 + self: EmployeeConfigInfo // 原始数据
  166 +end
  167 +
  168 +rule "calcu_EmployeeConfig_Wrap"
  169 + salience 800
  170 + when
  171 + $lr: Loop_result($xlId: xlId)
  172 + $eci: EmployeeConfigInfo() from employeeConfigInfoService.list(xlidParams($xlId))
  173 + then
  174 + EmployeeConfig_Wrap employeeConfig_wrap = new EmployeeConfig_Wrap();
  175 + employeeConfig_wrap.setId(String.valueOf($eci.getId()));
  176 + employeeConfig_wrap.setSelf($eci);
  177 +
  178 + insert(employeeConfig_wrap);
  179 +end
  180 +
  181 +//----------------- 时刻表班次信息载入 -----------------//
  182 +declare TTInfo_gid_stat
  183 + xlId: String // 线路id(cast字符串-方便比较)
  184 + ttInfoId: String // 时刻表id(cast字符串-方便比较)
  185 + gid: String // 路牌id(cast字符串-方便比较)
  186 +
  187 + maxFcno: Integer // 最大发车顺序号
  188 +
  189 + fbTime: LocalTime // 分班时间
  190 +end
  191 +
  192 +rule "calcu_TTInfo_gid_stat"
  193 + salience 800
  194 + when
  195 + $lr: Loop_result($xlId: xlId)
  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()))
  201 + then
  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());
  260 +end
  261 +
  262 +//-------------------- 第三阶段、合并计算SchedulePlanInfo -----------------//
  263 +
  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
  345 +
  346 +
  347 +
  348 +
  349 +
  350 +
  351 +
  352 +
  353 +
  354 +
  355 +
  356 +
  357 +
  358 +
  359 +
... ...
src/main/resources/static/pages/oil/checkJyryList.html
... ... @@ -20,7 +20,7 @@
20 20 class="caption-subject font-dark sbold uppercase">加油人员不符</span>
21 21 </div>
22 22 <div class="actions">
23   - <a class="btn btn-circle blue" href="cylAdd.html" data-pjax><i class="fa fa-plus"></i> 添加</a>
  23 +<!-- <a class="btn btn-circle blue" href="cylAdd.html" data-pjax><i class="fa fa-plus"></i> 添加</a> -->
24 24 <button type="button" class="btn btn-circle blue" id="saveButton"><i class="fa fa-minus-square"></i> 保存</button>
25 25 <!-- <button type="button" class="btn btn-circle red" disabled="disabled" id="removeButton"><i class="fa fa-trash"></i> 删除用户</button> -->
26 26 <!-- <div class="btn-group">
... ...
src/main/resources/static/pages/oil/list_ph.html
... ... @@ -21,7 +21,7 @@
21 21 </div>
22 22 <div class="actions">
23 23 <a class="btn btn-circle blue" href="add.html" data-pjax><i class="fa fa-plus"></i> 添加</a>
24   - <!-- <button type="button" class="btn btn-circle blue" id="removeButton"><i class="fa fa-trash-o"></i> 删除</button> -->
  24 + <button type="button" class="btn btn-circle blue" id="removeButton"><i class="fa fa-trash-o"></i> 删除</button>
25 25 <button type="button" class="btn btn-circle blue" id="sortButton"><i class="fa fa-minus-square"></i>
26 26 拆分/保存
27 27 </button>
... ... @@ -293,7 +293,8 @@
293 293 } else {
294 294 layer.msg('请选择日期.');
295 295 }
296   - })
  296 + });
  297 +
297 298 //拆分
298 299 $("#sortButton").on('click', function () {
299 300 if ($("#rq").val() != "") {
... ... @@ -489,10 +490,11 @@
489 490 }
490 491 layer.close(l);
491 492 $get('/ylb/sumYlb',params,function(returns){
492   - console.log(returns[0])
493   - $("#sumJzl").html(returns[0][0]);
494   - $("#sumYh").html(returns[0][1]);
495   - $("#sumSh").html(returns[0][2]);
  493 + console.log(returns);
  494 + console.log(returns.jzl);
  495 + $("#sumJzl").html(returns.jzl);
  496 + $("#sumYh").html(returns.yh);
  497 + $("#sumSh").html(returns.sh);
496 498 });
497 499 startOptJzylLink($('#ll_oil_list .in_carpark_jzyl'));
498 500 startOptShylLink($('#ll_oil_list .in_carpark_shyl'));
... ... @@ -582,13 +584,15 @@
582 584  
583 585 //删除
584 586 $('#removeButton').on('click', function () {
585   - if ($(this).attr('disabled'))
586   - return;
587   -
588   - var id = $('input.icheck:checked').data('id');
589   - removeConfirm('确定要删除选中的数据?', '/resource/' + id, function () {
590   - $('tr.filter .filter-submit').click();
591   - });
  587 + var id = $('input.icheck:checked').data('id');
  588 + if (typeof(id) == 'undefined') {
  589 + layer.msg("请选择要删除的数据");
  590 + }else{
  591 + removeConfirm('确定要删除选中的数据?', '/ylb/' + id, function () {
  592 + var params=getParamsList();
  593 + jsDoQuery(params, true);
  594 + });
  595 + }
592 596 });
593 597  
594 598 //搜索线路
... ...