Commit 6286a67612c9e9c51f1cda5b09167af35c427ef7

Authored by 娄高锋
1 parent 07c67de9

到离站报表站点筛选项排序问题修复,根据时间查询线路历史站点;油量进出场获取之前的进场油量作为出场油量时进场存油为0的也获取;预算报表导入公里异常修复;预算报表统计结果异常修复。

src/main/java/com/bsth/controller/report/ReportController.java
... ... @@ -218,8 +218,9 @@ public class ReportController {
218 218 return new ArrayList<Map<String, Object>>();
219 219 }
220 220 @RequestMapping(value = "/sreachZd", method = RequestMethod.GET)
221   - public List<Map<String, String>> sreachPersonnel(@RequestParam String line,@RequestParam int zdlx) {
222   - return service.sreachZd(line,zdlx);
  221 + public List<Map<String, String>> sreachPersonnel(@RequestParam String line,@RequestParam int zdlx,
  222 + @RequestParam String date1,@RequestParam String date2) {
  223 + return service.sreachZd(line,zdlx,date1,date2);
223 224 }
224 225  
225 226  
... ...
src/main/java/com/bsth/repository/LsStationRouteRepository.java
... ... @@ -3,7 +3,6 @@ package com.bsth.repository;
3 3 import java.util.List;
4 4 import java.util.Map;
5 5  
6   -import org.springframework.data.domain.Sort;
7 6 import org.springframework.data.jpa.repository.EntityGraph;
8 7 import org.springframework.data.jpa.repository.Modifying;
9 8 import org.springframework.data.jpa.repository.Query;
... ... @@ -11,7 +10,6 @@ import org.springframework.stereotype.Repository;
11 10 import org.springframework.transaction.annotation.Transactional;
12 11  
13 12 import com.bsth.entity.LsStationRoute;
14   -import com.bsth.entity.StationRoute;
15 13  
16 14 /**
17 15 *
... ... @@ -293,4 +291,14 @@ public interface LsStationRouteRepository extends BaseRepository&lt;LsStationRoute,
293 291  
294 292 @Query(value="select count(*) from bsth_c_ls_stationroute where line_code = ?1 and directions = ?2 and destroy = 0 and versions = ?3 ", nativeQuery=true)
295 293 int count(int line, int dir, int version);
  294 +
  295 + @Query(value = " select r.station_code, r.station_name, r.versions " +
  296 + "from bsth_c_ls_stationroute r where r.line_code = ?1 " +
  297 + "and r.directions=?2 and r.destroy = 0 and r.versions in(" +
  298 + "select v.versions from bsth_c_line_versions v where v.line_code=?1 " +
  299 + "and ((date_format(v.start_date, '%Y-%m-%d') >= ?3 and date_format(v.start_date, '%Y-%m-%d') <= ?4) " +
  300 + " or (date_format(v.start_date, '%Y-%m-%d') <= ?4 and date_format(v.end_date, '%Y-%m-%d') >= ?4) " +
  301 + " or (date_format(v.start_date, '%Y-%m-%d') >= ?3 and date_format(v.end_date, '%Y-%m-%d') <= ?4))" +
  302 + ") order by r.versions desc, r.station_route_code asc ", nativeQuery = true)
  303 + List<Object[]> findHistory(String lineCode, Integer updown, String date1, String date2);
296 304 }
... ...
src/main/java/com/bsth/repository/StationRouteRepository.java
... ... @@ -420,7 +420,7 @@ public interface StationRouteRepository extends BaseRepository&lt;StationRoute, Int
420 420 @Query("select r from StationRoute r where r.line.id=?1 and r.directions=?2 and r.destroy=0 order by r.stationRouteCode")
421 421 List<StationRoute> findByLine(Integer lineId, Integer dir);
422 422  
423   - @Query("select r from StationRoute r where r.lineCode=?1 and r.directions=?2 and versions is not null order by r.destroy, r.stationRouteCode")
  423 + @Query("select r from StationRoute r where r.lineCode=?1 and r.directions=?2 and r.destroy=0 order by r.stationRouteCode")
424 424 List<StationRoute> findAllByLine(String lineCode, int updown);
425 425  
426 426 @EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
... ...
src/main/java/com/bsth/repository/oil/YlbRepository.java
... ... @@ -47,7 +47,7 @@ public interface YlbRepository extends BaseRepository&lt;Ylb, Integer&gt;{
47 47 List<Ylb> listMaxRqJcsx(String rq,String gsbm,String fgsbm,String xlbm,String nbbm);
48 48  
49 49 @Query(value="select * from bsth_c_ylb where "
50   - + " DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= rq "
  50 + + " DATE_SUB(CURDATE(), INTERVAL 60 DAY) <= rq "
51 51 + " and rq< ?1 and ssgsdm like %?2%"
52 52 + " and fgsdm like %?3% and xlbm like %?4% and nbbm like %?5% "
53 53 + " order by nbbm , rq desc,jcsx desc,lp desc",nativeQuery=true)
... ...
src/main/java/com/bsth/service/forms/impl/BudgetServiceImpl.java
... ... @@ -150,7 +150,6 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
150 150  
151 151 for(int i = 0; i < textList.size(); i++){
152 152 String text = textList.get(i);
153   -// System.out.println(text);
154 153 String[] split = text.split(",");
155 154 int rowNo = Integer.valueOf(split[0].trim());
156 155 String year = split[1].trim();
... ... @@ -229,11 +228,11 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
229 228 Budget bud = budgets.get(0);
230 229 if(b.getFormalPerson() != null){
231 230 if(bud.getBudgetMileage() != null){
232   - bud.setChangeMileage(b.getFormalPerson());
  231 + bud.setChangeMileage(b.getFormalMileage());
233 232 } else {
234   - bud.setBudgetMileage(b.getFormalPerson());
  233 + bud.setBudgetMileage(b.getFormalMileage());
235 234 }
236   - bud.setFormalMileage(b.getFormalPerson());
  235 + bud.setFormalMileage(b.getFormalMileage());
237 236 }
238 237 if(b.getFormalPerson() != null){
239 238 if(bud.getBudgetPerson() != null){
... ... @@ -251,11 +250,11 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
251 250 }
252 251 bud.setFormalAmounts(b.getFormalAmounts());
253 252 }
254   - repository.update(bud.getBudgetMileage(), bud.getChangeMileage(), bud.getFormalPerson(),
  253 + repository.update(bud.getBudgetMileage(), bud.getChangeMileage(), bud.getFormalMileage(),
255 254 bud.getBudgetPerson(), bud.getChangePerson(), bud.getFormalPerson(),
256 255 bud.getBudgetAmounts(), bud.getChangeAmounts(), bud.getFormalAmounts(), bud.getId());
257 256 } else {
258   - b.setBudgetMileage(b.getFormalPerson());
  257 + b.setBudgetMileage(b.getFormalMileage());
259 258 b.setBudgetPerson(b.getFormalPerson());
260 259 b.setBudgetAmounts(b.getFormalAmounts());
261 260 insertList.add(b);
... ... @@ -380,7 +379,6 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
380 379 r.setXlName(lineAllMap.get(name).getName());
381 380 }
382 381 } else {
383   - boolean flag = true;
384 382 for(String key : lineAllMap.keySet()){
385 383 Line l = lineAllMap.get(key);
386 384 String name = l.getName();
... ... @@ -388,15 +386,11 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
388 386 name = name.replaceAll("区间", "") + l.getStartStationName().substring(0, 1);
389 387 }
390 388 if(l.getName().equals(lineName) || name.equals(lineName)){
391   - flag = false;
392 389 r.setXlBm(l.getLineCode());
393 390 r.setXlName(l.getName());
394 391 break;
395 392 }
396 393 }
397   -// if(flag){
398   -// System.out.println(m.get("lineName").toString() + " >> " + lineName);
399   -// }
400 394 }
401 395  
402 396 if(r.getXlBm() != null){
... ... @@ -432,6 +426,7 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
432 426 // TODO Auto-generated method stub
433 427 SimpleDateFormat sdfYY = new SimpleDateFormat("YYYY");
434 428 SimpleDateFormat sdfMM = new SimpleDateFormat("MM");
  429 + DecimalFormat df = new DecimalFormat("0.###");
435 430 List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
436 431 Map<String, Map<String, Object>> keyMap = new HashMap<String, Map<String, Object>>();
437 432 Map<String, Boolean> lineNature = lineService.lineNature();
... ... @@ -474,9 +469,9 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
474 469 m.put("xlName", xlName);
475 470 m.put("sfyy", sfyy);
476 471 m.put("sfjc", sfjc);
477   - m.put("budget", b.getBudgetMileage()!=null?b.getBudgetMileage():"");
478   - m.put("change", b.getChangeMileage()!=null?b.getChangeMileage():"");
479   - m.put("formal", b.getFormalMileage()!=null?b.getFormalMileage():"");
  472 + m.put("budget", b.getBudgetMileage()!=null?df.format(b.getBudgetMileage()):"");
  473 + m.put("change", b.getChangeMileage()!=null?df.format(b.getChangeMileage()):"");
  474 + m.put("formal", b.getFormalMileage()!=null?df.format(b.getFormalMileage()):"");
480 475 for(int i = 1; i <= 12; i++){
481 476 m.put("mon"+i, "");
482 477 m.put("bud"+i, "");
... ... @@ -494,28 +489,28 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
494 489 String bud = "bud" + Integer.valueOf(b.getYear().split("-")[1]);
495 490 if(b.getBudgetMileage()!=null){
496 491 if(m.get("budget").toString().length() > 0){
497   - m.put("budget", new BigDecimal(m.get("budget").toString()).add(
498   - new BigDecimal(b.getBudgetMileage())).doubleValue());
  492 + m.put("budget", df.format(new BigDecimal(m.get("budget").toString()).add(
  493 + new BigDecimal(b.getBudgetMileage())).doubleValue()));
499 494 } else {
500   - m.put("budget", b.getBudgetMileage());
  495 + m.put("budget", df.format(b.getBudgetMileage()));
501 496 }
502 497 }
503 498 if(b.getChangeMileage()!=null){
504 499 if(m.get("change").toString().length() > 0){
505   - m.put("change", new BigDecimal(m.get("change").toString()).add(
506   - new BigDecimal(b.getChangeMileage())).doubleValue());
  500 + m.put("change", df.format(new BigDecimal(m.get("change").toString()).add(
  501 + new BigDecimal(b.getChangeMileage())).doubleValue()));
507 502 } else {
508   - m.put("change", b.getChangeMileage());
  503 + m.put("change", df.format(b.getChangeMileage()));
509 504 }
510 505 }
511 506 if(b.getFormalMileage()!=null){
512 507 if(m.get("formal").toString().length() > 0){
513   - m.put("formal", new BigDecimal(m.get("formal").toString()).add(
514   - new BigDecimal(b.getFormalMileage())).doubleValue());
  508 + m.put("formal", df.format(new BigDecimal(m.get("formal").toString()).add(
  509 + new BigDecimal(b.getFormalMileage())).doubleValue()));
515 510 } else {
516   - m.put("formal", b.getFormalMileage());
  511 + m.put("formal", df.format(b.getFormalMileage()));
517 512 }
518   - m.put(bud, b.getFormalMileage());
  513 + m.put(bud, df.format(b.getFormalMileage()));
519 514 }
520 515 }
521 516 }
... ... @@ -611,6 +606,50 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
611 606 }
612 607 strList.add(gsBm + "_all");
613 608  
  609 + BigDecimal monAll = new BigDecimal("0");
  610 + BigDecimal preAll = new BigDecimal("0");
  611 + for(int i = 1; i <= 12; i++){
  612 + if(m.get("mon"+i).toString().length() > 0){
  613 + BigDecimal val = new BigDecimal(m.get("mon"+i).toString());
  614 + monAll = monAll.add(val);
  615 + val = val.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
  616 + m.put("mon"+i, val.doubleValue());
  617 + }
  618 + if(m.get("pre"+i).toString().length() > 0){
  619 + BigDecimal val = new BigDecimal(m.get("pre"+i).toString());
  620 + preAll = preAll.add(val);
  621 + val = val.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
  622 + m.put("pre"+i, val.doubleValue());
  623 + if(m.get("mon"+i).toString().length() > 0){
  624 + BigDecimal monVal = new BigDecimal(m.get("mon"+i).toString());
  625 + BigDecimal sub = monVal.subtract(val);
  626 + m.put("sub"+i, sub.doubleValue() > 0 ? "+" + sub.doubleValue() : sub.doubleValue());
  627 + } else {
  628 + m.put("sub"+i, "-" + val.doubleValue());
  629 + }
  630 + }
  631 + }
  632 + monAll = monAll.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
  633 + preAll = preAll.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
  634 + Double subAll = monAll.subtract(preAll).doubleValue();
  635 + m.put("monAll", monAll.doubleValue());
  636 + m.put("preAll", preAll.doubleValue());
  637 + m.put("subAll", subAll > 0 ? "+" + subAll : subAll);
  638 +
  639 + if(m.get("formal").toString().length() > 0 && m.get("monAll").toString().length() > 0
  640 + && new BigDecimal(m.get("formal").toString()).doubleValue() > 0d){
  641 + BigDecimal formal = new BigDecimal(m.get("formal").toString());
  642 + m.put("complete", monAll.divide(
  643 + formal, 4, BigDecimal.ROUND_HALF_UP).multiply(
  644 + new BigDecimal(100)).divide(
  645 + new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP)+ "%");
  646 + BigDecimal diff = monAll.subtract(formal);
  647 + m.put("diff", diff.doubleValue() > 0 ? "+" + diff.doubleValue() : diff.doubleValue());
  648 + } else {
  649 + m.put("complete", "");
  650 + m.put("diff", "");
  651 + }
  652 +
614 653 for(String str : strList){
615 654 if(!keyMap.containsKey(str)){
616 655 continue;
... ... @@ -652,7 +691,7 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
652 691 }
653 692 if(m.get(bud).toString().length() > 0){
654 693 if(map.get(bud).toString().length() > 0){
655   - map.put(mon, new BigDecimal(m.get(bud).toString()).add(
  694 + map.put(bud, new BigDecimal(m.get(bud).toString()).add(
656 695 new BigDecimal(map.get(bud).toString())).doubleValue());
657 696 } else {
658 697 map.put(bud, new BigDecimal(m.get(bud).toString()).doubleValue());
... ... @@ -670,50 +709,6 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
670 709 List<Map<String, Object>>dataList = (List<Map<String, Object>>)map.get("dataList");
671 710 dataList.add(m);
672 711 }
673   -
674   - BigDecimal monAll = new BigDecimal("0");
675   - BigDecimal preAll = new BigDecimal("0");
676   - for(int i = 1; i <= 12; i++){
677   - if(m.get("mon"+i).toString().length() > 0){
678   - BigDecimal val = new BigDecimal(m.get("mon"+i).toString());
679   - monAll = monAll.add(val);
680   - val = val.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
681   - m.put("mon"+i, val.doubleValue());
682   - }
683   - if(m.get("pre"+i).toString().length() > 0){
684   - BigDecimal val = new BigDecimal(m.get("pre"+i).toString());
685   - preAll = preAll.add(val);
686   - val = val.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
687   - m.put("pre"+i, val.doubleValue());
688   - if(m.get("mon"+i).toString().length() > 0){
689   - BigDecimal monVal = new BigDecimal(m.get("mon"+i).toString());
690   - BigDecimal sub = monVal.subtract(val);
691   - m.put("sub"+i, sub.doubleValue() > 0 ? "+" + sub.doubleValue() : sub.doubleValue());
692   - } else {
693   - m.put("sub"+i, "-" + val.doubleValue());
694   - }
695   - }
696   - }
697   - monAll = monAll.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
698   - preAll = preAll.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
699   - Double subAll = monAll.subtract(preAll).doubleValue();
700   - m.put("monAll", monAll.doubleValue());
701   - m.put("preAll", preAll.doubleValue());
702   - m.put("subAll", subAll > 0 ? "+" + subAll : subAll);
703   -
704   - if(m.get("formal").toString().length() > 0 && m.get("monAll").toString().length() > 0
705   - && new BigDecimal(m.get("formal").toString()).doubleValue() > 0d){
706   - BigDecimal formal = new BigDecimal(m.get("formal").toString());
707   - m.put("complete", monAll.divide(
708   - formal, 4, BigDecimal.ROUND_HALF_UP).multiply(
709   - new BigDecimal(100)).divide(
710   - new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP)+ "%");
711   - BigDecimal diff = monAll.subtract(formal);
712   - m.put("diff", diff.doubleValue() > 0 ? "+" + diff.doubleValue() : diff.doubleValue());
713   - } else {
714   - m.put("complete", "");
715   - m.put("diff", "");
716   - }
717 712 }
718 713  
719 714 for(String key : strs){
... ... @@ -764,14 +759,10 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
764 759 if(m.get("mon"+i).toString().length() > 0){
765 760 BigDecimal val = new BigDecimal(m.get("mon"+i).toString());
766 761 monAll = monAll.add(val);
767   - val = val.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
768   - m.put("mon"+i, val.doubleValue());
769 762 }
770 763 if(m.get("pre"+i).toString().length() > 0){
771 764 BigDecimal val = new BigDecimal(m.get("pre"+i).toString());
772 765 preAll = preAll.add(val);
773   - val = val.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
774   - m.put("pre"+i, val.doubleValue());
775 766 if(m.get("mon"+i).toString().length() > 0){
776 767 BigDecimal monVal = new BigDecimal(m.get("mon"+i).toString());
777 768 BigDecimal sub = monVal.subtract(val);
... ... @@ -781,8 +772,6 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
781 772 }
782 773 }
783 774 }
784   - monAll = monAll.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
785   - preAll = preAll.divide(new BigDecimal("10000"), 3, BigDecimal.ROUND_HALF_UP);
786 775 Double subAll = monAll.subtract(preAll).doubleValue();
787 776 m.put("monAll", monAll.doubleValue());
788 777 m.put("preAll", preAll.doubleValue());
... ... @@ -869,6 +858,7 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
869 858 // TODO Auto-generated method stub
870 859 SimpleDateFormat sdfYY = new SimpleDateFormat("YYYY");
871 860 SimpleDateFormat sdfMM = new SimpleDateFormat("MM");
  861 + DecimalFormat df = new DecimalFormat("0.###");
872 862 List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
873 863 Map<String, Map<String, Object>> keyMap = new HashMap<String, Map<String, Object>>();
874 864 Map<String, Boolean> lineNature = lineService.lineNature();
... ... @@ -882,7 +872,7 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
882 872 // TODO Auto-generated catch block
883 873 e.printStackTrace();
884 874 }
885   - List<Revenue> revenueList_1 = revenueRepository.findByDates(year_1+"-01-01", year_1+"-12-31");
  875 + List<Revenue> revenueList_1 = revenueRepository.findByDates(year_1+"-01-01", year_1+"-01-31");
886 876  
887 877 Map<String, Map<String, Object>> xlMap = new HashMap<String, Map<String, Object>>();
888 878 List<Map<String, Object>> xlList = new ArrayList<Map<String, Object>>();
... ... @@ -911,9 +901,9 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
911 901 m.put("xlName", xlName);
912 902 m.put("sfyy", sfyy);
913 903 m.put("sfjc", sfjc);
914   - m.put("budget", b.getBudgetPerson()!=null?b.getBudgetPerson():"");
915   - m.put("change", b.getChangePerson()!=null?b.getChangePerson():"");
916   - m.put("formal", b.getFormalPerson()!=null?b.getFormalPerson():"");
  904 + m.put("budget", b.getBudgetPerson()!=null?df.format(b.getBudgetPerson()):"");
  905 + m.put("change", b.getChangePerson()!=null?df.format(b.getChangePerson()):"");
  906 + m.put("formal", b.getFormalPerson()!=null?df.format(b.getFormalPerson()):"");
917 907 for(int i = 1; i <= 12; i++){
918 908 m.put("mon"+i, "");
919 909 m.put("bud"+i, "");
... ... @@ -931,28 +921,28 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
931 921 String bud = "bud" + Integer.valueOf(b.getYear().split("-")[1]);
932 922 if(b.getBudgetPerson()!=null){
933 923 if(m.get("budget").toString().length() > 0){
934   - m.put("budget", new BigDecimal(m.get("budget").toString()).add(
935   - new BigDecimal(b.getBudgetPerson())).doubleValue());
  924 + m.put("budget", df.format(new BigDecimal(m.get("budget").toString()).add(
  925 + new BigDecimal(b.getBudgetPerson())).doubleValue()));
936 926 } else {
937   - m.put("budget", b.getBudgetPerson());
  927 + m.put("budget", df.format(b.getBudgetPerson()));
938 928 }
939 929 }
940 930 if(b.getChangePerson()!=null){
941 931 if(m.get("change").toString().length() > 0){
942   - m.put("change", new BigDecimal(m.get("change").toString()).add(
943   - new BigDecimal(b.getChangePerson())).doubleValue());
  932 + m.put("change", df.format(new BigDecimal(m.get("change").toString()).add(
  933 + new BigDecimal(b.getChangePerson())).doubleValue()));
944 934 } else {
945   - m.put("change", b.getChangePerson());
  935 + m.put("change", df.format(b.getChangePerson()));
946 936 }
947 937 }
948 938 if(b.getFormalPerson()!=null){
949 939 if(m.get("formal").toString().length() > 0){
950   - m.put("formal", new BigDecimal(m.get("formal").toString()).add(
951   - new BigDecimal(b.getFormalPerson())).doubleValue());
  940 + m.put("formal", df.format(new BigDecimal(m.get("formal").toString()).add(
  941 + new BigDecimal(b.getFormalPerson())).doubleValue()));
952 942 } else {
953   - m.put("formal", b.getFormalPerson());
  943 + m.put("formal", df.format(b.getFormalPerson()));
954 944 }
955   - m.put(bud, b.getFormalPerson());
  945 + m.put(bud, df.format(b.getFormalPerson()));
956 946 }
957 947 }
958 948 }
... ... @@ -1091,7 +1081,7 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1091 1081 }
1092 1082 if(m.get(bud).toString().length() > 0){
1093 1083 if(map.get(bud).toString().length() > 0){
1094   - map.put(mon, new BigDecimal(m.get(bud).toString()).add(
  1084 + map.put(bud, new BigDecimal(m.get(bud).toString()).add(
1095 1085 new BigDecimal(map.get(bud).toString())).doubleValue());
1096 1086 } else {
1097 1087 map.put(bud, new BigDecimal(m.get(bud).toString()).doubleValue());
... ... @@ -1308,11 +1298,12 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1308 1298 // TODO Auto-generated method stub
1309 1299 SimpleDateFormat sdfYY = new SimpleDateFormat("YYYY");
1310 1300 SimpleDateFormat sdfMM = new SimpleDateFormat("MM");
  1301 + DecimalFormat df = new DecimalFormat("0.###");
1311 1302 List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
1312 1303 Map<String, Map<String, Object>> keyMap = new HashMap<String, Map<String, Object>>();
1313 1304 Map<String, Boolean> lineNature = lineService.lineNature();
1314 1305 List<Budget> findByYear = repository.findByYear(year);
1315   - List<Revenue> list = revenueRepository.findByDates(year+"-01-01", year+"-12-31");
  1306 + List<Revenue> list = revenueRepository.findByDates(year+"-01-01", year+"-01-31");
1316 1307  
1317 1308 String year_1 = "";
1318 1309 try {
... ... @@ -1321,8 +1312,8 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1321 1312 // TODO Auto-generated catch block
1322 1313 e.printStackTrace();
1323 1314 }
1324   - List<CalcStatistics> scheduleList_1 = calcStatisticsRepository.selectByDateAndLineTj3(year_1+"-01-01", year_1+"-12-31");
1325   - List<Revenue> revenueList_1 = revenueRepository.findByDates(year_1+"-01-01", year_1+"-12-31");
  1315 + List<CalcStatistics> scheduleList_1 = calcStatisticsRepository.selectByDateAndLineTj3(year_1+"-01-01", year_1+"-01-31");
  1316 + List<Revenue> revenueList_1 = revenueRepository.findByDates(year_1+"-01-01", year_1+"-01-31");
1326 1317  
1327 1318 Map<String, Map<String, Object>> xlMap = new HashMap<String, Map<String, Object>>();
1328 1319 List<Map<String, Object>> xlList = new ArrayList<Map<String, Object>>();
... ... @@ -1351,9 +1342,9 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1351 1342 m.put("xlName", xlName);
1352 1343 m.put("sfyy", sfyy);
1353 1344 m.put("sfjc", sfjc);
1354   - m.put("budget", b.getBudgetAmounts()!=null?b.getBudgetAmounts():"");
1355   - m.put("change", b.getChangeAmounts()!=null?b.getChangeAmounts():"");
1356   - m.put("formal", b.getFormalAmounts()!=null?b.getFormalAmounts():"");
  1345 + m.put("budget", b.getBudgetAmounts()!=null?df.format(b.getBudgetAmounts()):"");
  1346 + m.put("change", b.getChangeAmounts()!=null?df.format(b.getChangeAmounts()):"");
  1347 + m.put("formal", b.getFormalAmounts()!=null?df.format(b.getFormalAmounts()):"");
1357 1348 for(int i = 1; i <= 12; i++){
1358 1349 m.put("mon"+i, "");
1359 1350 m.put("bud"+i, "");
... ... @@ -1372,28 +1363,28 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1372 1363 String bud = "bud" + Integer.valueOf(b.getYear().split("-")[1]);
1373 1364 if(b.getBudgetAmounts()!=null){
1374 1365 if(m.get("budget").toString().length() > 0){
1375   - m.put("budget", new BigDecimal(m.get("budget").toString()).add(
1376   - new BigDecimal(b.getBudgetAmounts())).doubleValue());
  1366 + m.put("budget", df.format(new BigDecimal(m.get("budget").toString()).add(
  1367 + new BigDecimal(b.getBudgetAmounts())).doubleValue()));
1377 1368 } else {
1378   - m.put("budget", b.getBudgetAmounts());
  1369 + m.put("budget", df.format(b.getBudgetAmounts()));
1379 1370 }
1380 1371 }
1381 1372 if(b.getChangeAmounts()!=null){
1382 1373 if(m.get("change").toString().length() > 0){
1383   - m.put("change", new BigDecimal(m.get("change").toString()).add(
1384   - new BigDecimal(b.getChangeAmounts())).doubleValue());
  1374 + m.put("change", df.format(new BigDecimal(m.get("change").toString()).add(
  1375 + new BigDecimal(b.getChangeAmounts())).doubleValue()));
1385 1376 } else {
1386   - m.put("change", b.getChangeAmounts());
  1377 + m.put("change", df.format(b.getChangeAmounts()));
1387 1378 }
1388 1379 }
1389 1380 if(b.getFormalAmounts()!=null){
1390 1381 if(m.get("formal").toString().length() > 0){
1391   - m.put("formal", new BigDecimal(m.get("formal").toString()).add(
1392   - new BigDecimal(b.getFormalAmounts())).doubleValue());
  1382 + m.put("formal", df.format(new BigDecimal(m.get("formal").toString()).add(
  1383 + new BigDecimal(b.getFormalAmounts())).doubleValue()));
1393 1384 } else {
1394   - m.put("formal", b.getFormalAmounts());
  1385 + m.put("formal", df.format(b.getFormalAmounts()));
1395 1386 }
1396   - m.put(bud, b.getFormalAmounts());
  1387 + m.put(bud, df.format(b.getFormalAmounts()));
1397 1388 }
1398 1389 }
1399 1390 }
... ... @@ -1529,7 +1520,7 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1529 1520 }
1530 1521 }
1531 1522 for(int i = 1; i <= 12; i++){
1532   - String mon = "mon"+i, bud = "bud"+i;
  1523 + String mon = "mon"+i, bud = "bud"+i, pre = "pre"+i;
1533 1524 if(m.get(mon).toString().length() > 0){
1534 1525 if(map.get(mon).toString().length() > 0){
1535 1526 map.put(mon, new BigDecimal(m.get(mon).toString()).add(
... ... @@ -1540,12 +1531,20 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1540 1531 }
1541 1532 if(m.get(bud).toString().length() > 0){
1542 1533 if(map.get(bud).toString().length() > 0){
1543   - map.put(mon, new BigDecimal(m.get(bud).toString()).add(
  1534 + map.put(bud, new BigDecimal(m.get(bud).toString()).add(
1544 1535 new BigDecimal(map.get(bud).toString())).doubleValue());
1545 1536 } else {
1546 1537 map.put(bud, new BigDecimal(m.get(bud).toString()).doubleValue());
1547 1538 }
1548 1539 }
  1540 + if(m.get(pre).toString().length() > 0){
  1541 + if(map.get(pre).toString().length() > 0){
  1542 + map.put(pre, new BigDecimal(m.get(pre).toString()).add(
  1543 + new BigDecimal(map.get(pre).toString())).doubleValue());
  1544 + } else {
  1545 + map.put(pre, new BigDecimal(m.get(pre).toString()).doubleValue());
  1546 + }
  1547 + }
1549 1548 }
1550 1549 if(m.containsKey("num") && m.get("num").toString().length() > 0){
1551 1550 if(map.containsKey("num") && map.get("num").toString().length() > 0){
... ... @@ -1582,10 +1581,10 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1582 1581 }
1583 1582 }
1584 1583 }
1585   - BigDecimal monAll_ = monAll.divide(new BigDecimal("1000000"), 3, BigDecimal.ROUND_HALF_UP);
  1584 + monAll = monAll.divide(new BigDecimal("1000000"), 3, BigDecimal.ROUND_HALF_UP);
1586 1585 preAll = preAll.divide(new BigDecimal("1000000"), 3, BigDecimal.ROUND_HALF_UP);
1587   - Double subAll = monAll_.subtract(preAll).doubleValue();
1588   - m.put("monAll", monAll_.doubleValue());
  1586 + Double subAll = monAll.subtract(preAll).doubleValue();
  1587 + m.put("monAll", monAll.doubleValue());
1589 1588 m.put("preAll", preAll.doubleValue());
1590 1589 m.put("subAll", subAll > 0 ? "+" + subAll : subAll);
1591 1590  
... ... @@ -1687,10 +1686,10 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1687 1686 }
1688 1687 }
1689 1688 }
1690   - BigDecimal monAll_ = monAll.divide(new BigDecimal("1000000"), 3, BigDecimal.ROUND_HALF_UP);
  1689 + monAll = monAll.divide(new BigDecimal("1000000"), 3, BigDecimal.ROUND_HALF_UP);
1691 1690 preAll = preAll.divide(new BigDecimal("1000000"), 3, BigDecimal.ROUND_HALF_UP);
1692   - Double subAll = monAll_.subtract(preAll).doubleValue();
1693   - m.put("monAll", monAll_.doubleValue());
  1691 + Double subAll = monAll.subtract(preAll).doubleValue();
  1692 + m.put("monAll", monAll.doubleValue());
1694 1693 m.put("preAll", preAll.doubleValue());
1695 1694 m.put("subAll", subAll > 0 ? "+" + subAll : subAll);
1696 1695  
... ... @@ -1784,6 +1783,7 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1784 1783 // TODO Auto-generated method stub
1785 1784 SimpleDateFormat sdfYY = new SimpleDateFormat("YYYY");
1786 1785 SimpleDateFormat sdfMM = new SimpleDateFormat("MM");
  1786 + DecimalFormat df = new DecimalFormat("0.###");
1787 1787 List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
1788 1788 Map<String, Map<String, Object>> keyMap = new HashMap<String, Map<String, Object>>();
1789 1789 List<Budget> findByYear = repository.findByYear(year);
... ... @@ -1798,8 +1798,8 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1798 1798 // TODO Auto-generated catch block
1799 1799 e.printStackTrace();
1800 1800 }
1801   - List<CalcStatistics> scheduleList_1 = calcStatisticsRepository.selectByDateAndLineTj3(year_1+"-01-01", year_1+"-12-31");
1802   - List<Revenue> revenueList_1 = revenueRepository.findByDates(year_1+"-01-01", year_1+"-12-31");
  1801 + List<CalcStatistics> scheduleList_1 = calcStatisticsRepository.selectByDateAndLineTj3(year_1+"-01-01", year_1+"-01-31");
  1802 + List<Revenue> revenueList_1 = revenueRepository.findByDates(year_1+"-01-01", year_1+"-01-31");
1803 1803  
1804 1804 Map<String, Map<String, Object>> xlMap = new HashMap<String, Map<String, Object>>();
1805 1805 List<Map<String, Object>> xlList = new ArrayList<Map<String, Object>>();
... ... @@ -1834,9 +1834,9 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1834 1834 m.put("xlBm", xlBm);
1835 1835 m.put("xlName", xlName);
1836 1836 m.put("type", "公里");
1837   - m.put("budget", b.getBudgetMileage()!=null?b.getBudgetMileage():"");
1838   - m.put("change", b.getChangeMileage()!=null?b.getChangeMileage():"");
1839   - m.put("formal", b.getFormalMileage()!=null?b.getFormalMileage():"");
  1837 + m.put("budget", b.getBudgetMileage()!=null?df.format(b.getBudgetMileage()):"");
  1838 + m.put("change", b.getChangeMileage()!=null?df.format(b.getChangeMileage()):"");
  1839 + m.put("formal", b.getFormalMileage()!=null?df.format(b.getFormalMileage()):"");
1840 1840 for(int i = 1; i <= 12; i++){
1841 1841 m.put("mon"+i, "");
1842 1842 m.put("bud"+i, "");
... ... @@ -1844,7 +1844,7 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1844 1844 }
1845 1845 String bud = "bud" + Integer.valueOf(b.getYear().split("-")[1]);
1846 1846 if(b.getFormalMileage()!=null){
1847   - m.put(bud, b.getFormalMileage());
  1847 + m.put(bud, df.format(b.getFormalMileage()));
1848 1848 }
1849 1849 m.put("monAll", "0");
1850 1850 xlMap.put(key1, m);
... ... @@ -1854,28 +1854,28 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1854 1854 String bud = "bud" + Integer.valueOf(b.getYear().split("-")[1]);
1855 1855 if(b.getBudgetMileage()!=null){
1856 1856 if(m.get("budget").toString().length() > 0){
1857   - m.put("budget", new BigDecimal(m.get("budget").toString()).add(
1858   - new BigDecimal(b.getBudgetMileage())).doubleValue());
  1857 + m.put("budget", df.format(new BigDecimal(m.get("budget").toString()).add(
  1858 + new BigDecimal(b.getBudgetMileage())).doubleValue()));
1859 1859 } else {
1860   - m.put("budget", b.getBudgetMileage());
  1860 + m.put("budget", df.format(b.getBudgetMileage()));
1861 1861 }
1862 1862 }
1863 1863 if(b.getChangeMileage()!=null){
1864 1864 if(m.get("change").toString().length() > 0){
1865   - m.put("change", new BigDecimal(m.get("change").toString()).add(
1866   - new BigDecimal(b.getChangeMileage())).doubleValue());
  1865 + m.put("change", df.format(new BigDecimal(m.get("change").toString()).add(
  1866 + new BigDecimal(b.getChangeMileage())).doubleValue()));
1867 1867 } else {
1868   - m.put("change", b.getChangeMileage());
  1868 + m.put("change", df.format(b.getChangeMileage()));
1869 1869 }
1870 1870 }
1871 1871 if(b.getFormalMileage()!=null){
1872 1872 if(m.get("formal").toString().length() > 0){
1873   - m.put("formal", new BigDecimal(m.get("formal").toString()).add(
1874   - new BigDecimal(b.getFormalMileage())).doubleValue());
  1873 + m.put("formal", df.format(new BigDecimal(m.get("formal").toString()).add(
  1874 + new BigDecimal(b.getFormalMileage())).doubleValue()));
1875 1875 } else {
1876   - m.put("formal", b.getFormalMileage());
  1876 + m.put("formal", df.format(b.getFormalMileage()));
1877 1877 }
1878   - m.put(bud, b.getFormalMileage());
  1878 + m.put(bud, df.format(b.getFormalMileage()));
1879 1879 }
1880 1880 }
1881 1881 }
... ... @@ -1888,9 +1888,9 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1888 1888 m.put("xlBm", xlBm);
1889 1889 m.put("xlName", xlName);
1890 1890 m.put("type", "人次");
1891   - m.put("budget", b.getBudgetPerson()!=null?b.getBudgetPerson():"");
1892   - m.put("change", b.getChangePerson()!=null?b.getChangePerson():"");
1893   - m.put("formal", b.getFormalPerson()!=null?b.getFormalPerson():"");
  1891 + m.put("budget", b.getBudgetPerson()!=null?df.format(b.getBudgetPerson()):"");
  1892 + m.put("change", b.getChangePerson()!=null?df.format(b.getChangePerson()):"");
  1893 + m.put("formal", b.getFormalPerson()!=null?df.format(b.getFormalPerson()):"");
1894 1894 for(int i = 1; i <= 12; i++){
1895 1895 m.put("mon"+i, "");
1896 1896 m.put("bud"+i, "");
... ... @@ -1898,7 +1898,7 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1898 1898 }
1899 1899 String bud = "bud" + Integer.valueOf(b.getYear().split("-")[1]);
1900 1900 if(b.getFormalPerson()!=null){
1901   - m.put(bud, b.getFormalPerson());
  1901 + m.put(bud, df.format(b.getFormalPerson()));
1902 1902 }
1903 1903 m.put("monAll", "0");
1904 1904 xlMap.put(key2, m);
... ... @@ -1908,28 +1908,28 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1908 1908 String bud = "bud" + Integer.valueOf(b.getYear().split("-")[1]);
1909 1909 if(b.getBudgetPerson()!=null){
1910 1910 if(m.get("budget").toString().length() > 0){
1911   - m.put("budget", new BigDecimal(m.get("budget").toString()).add(
1912   - new BigDecimal(b.getBudgetPerson())).doubleValue());
  1911 + m.put("budget", df.format(new BigDecimal(m.get("budget").toString()).add(
  1912 + new BigDecimal(b.getBudgetPerson())).doubleValue()));
1913 1913 } else {
1914   - m.put("budget", b.getBudgetPerson());
  1914 + m.put("budget", df.format(b.getBudgetPerson()));
1915 1915 }
1916 1916 }
1917 1917 if(b.getChangePerson()!=null){
1918 1918 if(m.get("change").toString().length() > 0){
1919   - m.put("change", new BigDecimal(m.get("change").toString()).add(
1920   - new BigDecimal(b.getChangePerson())).doubleValue());
  1919 + m.put("change", df.format(new BigDecimal(m.get("change").toString()).add(
  1920 + new BigDecimal(b.getChangePerson())).doubleValue()));
1921 1921 } else {
1922   - m.put("change", b.getChangePerson());
  1922 + m.put("change", df.format(b.getChangePerson()));
1923 1923 }
1924 1924 }
1925 1925 if(b.getFormalPerson()!=null){
1926 1926 if(m.get("formal").toString().length() > 0){
1927   - m.put("formal", new BigDecimal(m.get("formal").toString()).add(
1928   - new BigDecimal(b.getFormalPerson())).doubleValue());
  1927 + m.put("formal", df.format(new BigDecimal(m.get("formal").toString()).add(
  1928 + new BigDecimal(b.getFormalPerson())).doubleValue()));
1929 1929 } else {
1930   - m.put("formal", b.getFormalPerson());
  1930 + m.put("formal", df.format(b.getFormalPerson()));
1931 1931 }
1932   - m.put(bud, b.getFormalPerson());
  1932 + m.put(bud, df.format(b.getFormalPerson()));
1933 1933 }
1934 1934 }
1935 1935 }
... ... @@ -1942,9 +1942,9 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1942 1942 m.put("xlBm", xlBm);
1943 1943 m.put("xlName", xlName);
1944 1944 m.put("type", "营收");
1945   - m.put("budget", b.getBudgetAmounts()!=null?b.getBudgetAmounts():"");
1946   - m.put("change", b.getChangeAmounts()!=null?b.getChangeAmounts():"");
1947   - m.put("formal", b.getFormalAmounts()!=null?b.getFormalAmounts():"");
  1945 + m.put("budget", b.getBudgetAmounts()!=null?df.format(b.getBudgetAmounts()):"");
  1946 + m.put("change", b.getChangeAmounts()!=null?df.format(b.getChangeAmounts()):"");
  1947 + m.put("formal", b.getFormalAmounts()!=null?df.format(b.getFormalAmounts()):"");
1948 1948 for(int i = 1; i <= 12; i++){
1949 1949 m.put("mon"+i, "");
1950 1950 m.put("bud"+i, "");
... ... @@ -1952,7 +1952,7 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1952 1952 }
1953 1953 String bud = "bud" + Integer.valueOf(b.getYear().split("-")[1]);
1954 1954 if(b.getFormalAmounts()!=null){
1955   - m.put(bud, b.getFormalAmounts());
  1955 + m.put(bud, df.format(b.getFormalAmounts()));
1956 1956 }
1957 1957 m.put("monAll", "0");
1958 1958 xlMap.put(key3, m);
... ... @@ -1962,28 +1962,28 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
1962 1962 String bud = "bud" + Integer.valueOf(b.getYear().split("-")[1]);
1963 1963 if(b.getBudgetAmounts()!=null){
1964 1964 if(m.get("budget").toString().length() > 0){
1965   - m.put("budget", new BigDecimal(m.get("budget").toString()).add(
1966   - new BigDecimal(b.getBudgetAmounts())).doubleValue());
  1965 + m.put("budget", df.format(new BigDecimal(m.get("budget").toString()).add(
  1966 + new BigDecimal(b.getBudgetAmounts())).doubleValue()));
1967 1967 } else {
1968   - m.put("budget", b.getBudgetAmounts());
  1968 + m.put("budget", df.format(b.getBudgetAmounts()));
1969 1969 }
1970 1970 }
1971 1971 if(b.getChangeAmounts()!=null){
1972 1972 if(m.get("change").toString().length() > 0){
1973   - m.put("change", new BigDecimal(m.get("change").toString()).add(
1974   - new BigDecimal(b.getChangeAmounts())).doubleValue());
  1973 + m.put("change", df.format(new BigDecimal(m.get("change").toString()).add(
  1974 + new BigDecimal(b.getChangeAmounts())).doubleValue()));
1975 1975 } else {
1976   - m.put("change", b.getChangeAmounts());
  1976 + m.put("change", df.format(b.getChangeAmounts()));
1977 1977 }
1978 1978 }
1979 1979 if(b.getFormalAmounts()!=null){
1980 1980 if(m.get("formal").toString().length() > 0){
1981   - m.put("formal", new BigDecimal(m.get("formal").toString()).add(
1982   - new BigDecimal(b.getFormalAmounts())).doubleValue());
  1981 + m.put("formal", df.format(new BigDecimal(m.get("formal").toString()).add(
  1982 + new BigDecimal(b.getFormalAmounts())).doubleValue()));
1983 1983 } else {
1984   - m.put("formal", b.getFormalAmounts());
  1984 + m.put("formal", df.format(b.getFormalAmounts()));
1985 1985 }
1986   - m.put(bud, b.getFormalAmounts());
  1986 + m.put(bud, df.format(b.getFormalAmounts()));
1987 1987 }
1988 1988 }
1989 1989 }
... ... @@ -2298,7 +2298,7 @@ public class BudgetServiceImpl extends BaseServiceImpl&lt;Budget, Integer&gt; implemen
2298 2298 }
2299 2299 if(m.get(bud).toString().length() > 0){
2300 2300 if(map.get(bud).toString().length() > 0){
2301   - map.put(mon, new BigDecimal(m.get(bud).toString()).add(
  2301 + map.put(bud, new BigDecimal(m.get(bud).toString()).add(
2302 2302 new BigDecimal(map.get(bud).toString())).doubleValue());
2303 2303 } else {
2304 2304 map.put(bud, new BigDecimal(m.get(bud).toString()).doubleValue());
... ...
src/main/java/com/bsth/service/oil/impl/YlbServiceImpl.java
1   -package com.bsth.service.oil.impl;
2   -
3   -import java.sql.ResultSet;
4   -import java.sql.SQLException;
5   -import java.text.DecimalFormat;
6   -import java.text.ParseException;
7   -import java.text.SimpleDateFormat;
8   -import java.util.ArrayList;
9   -import java.util.Calendar;
10   -import java.util.Date;
11   -import java.util.HashMap;
12   -import java.util.Iterator;
13   -import java.util.List;
14   -import java.util.Map;
15   -
16   -import javax.transaction.Transactional;
17   -
18   -import org.apache.commons.lang3.StringEscapeUtils;
19   -import org.apache.commons.lang3.StringUtils;
20   -import org.slf4j.Logger;
21   -import org.slf4j.LoggerFactory;
22   -import org.springframework.beans.factory.annotation.Autowired;
23   -import org.springframework.data.domain.Sort;
24   -import org.springframework.data.domain.Sort.Direction;
25   -import org.springframework.jdbc.core.JdbcTemplate;
26   -import org.springframework.jdbc.core.RowMapper;
27   -import org.springframework.stereotype.Service;
28   -
29   -import com.alibaba.fastjson.JSONArray;
30   -import com.alibaba.fastjson.JSONObject;
31   -import com.bsth.common.ResponseCode;
32   -import com.bsth.data.BasicData;
33   -import com.bsth.entity.Cars;
34   -import com.bsth.entity.Line;
35   -import com.bsth.entity.mcy_forms.Daily;
36   -import com.bsth.entity.oil.Cyl;
37   -import com.bsth.entity.oil.Dlb;
38   -import com.bsth.entity.oil.Nylog;
39   -import com.bsth.entity.oil.Ylb;
40   -import com.bsth.entity.oil.Ylxxb;
41   -import com.bsth.entity.search.CustomerSpecs;
42   -import com.bsth.entity.sys.SysUser;
43   -import com.bsth.repository.CarsRepository;
44   -import com.bsth.repository.LineRepository;
45   -import com.bsth.repository.oil.CylRepository;
46   -import com.bsth.repository.oil.DlbRepository;
47   -import com.bsth.repository.oil.NylogRepository;
48   -import com.bsth.repository.oil.YlbRepository;
49   -import com.bsth.repository.oil.YlxxbRepository;
50   -import com.bsth.security.util.SecurityUtils;
51   -import com.bsth.service.impl.BaseServiceImpl;
52   -import com.bsth.service.oil.DlbService;
53   -import com.bsth.service.oil.YlbService;
54   -import com.bsth.service.realcontrol.ScheduleRealInfoService;
55   -import com.bsth.util.Arith;
56   -import com.bsth.util.BatchSaveUtils;
57   -import com.bsth.util.ReportUtils;
58   -import com.github.abel533.echarts.code.Y;
59   -
60   -import javassist.bytecode.stackmap.BasicBlock.Catch;
61   -
62   -@Service
63   -public class YlbServiceImpl extends BaseServiceImpl<Ylb,Integer> implements YlbService{
64   - @Autowired
65   - YlbRepository repository;
66   - @Autowired
67   - NylogRepository nylogRepository;
68   - @Autowired
69   - YlxxbRepository ylxxbRepository;
70   -
71   - @Autowired
72   - DlbService dlbService;
73   -
74   - @Autowired
75   - DlbRepository dlbRepository;
76   -
77   - @Autowired
78   - CylRepository cylRepository;
79   -
80   - @Autowired
81   - CarsRepository carsRepository;
82   -
83   -
84   - @Autowired
85   - LineRepository lineRepository;
86   -
87   - @Autowired
88   - ScheduleRealInfoService scheduleRealInfoService;
89   -
90   - @Autowired
91   - JdbcTemplate jdbcTemplate;
92   -
93   - Logger logger = LoggerFactory.getLogger(this.getClass());
94   -
95   -
96   -
97   - /**
98   - * 获取进存油信息
99   - * @Transactional 回滚事物
100   - */
101   - @Transactional
102   - @Override
103   - public String obtainDsq() throws Exception{
104   - String result = "failure";
105   - try {
106   - List<Ylb> addList = new ArrayList<Ylb>();
107   - String type = "";
108   - List<Cars> carsList=carsRepository.findCars();
109   - Map<String, Boolean> carsMap=new HashMap<String, Boolean>();
110   - for (int i = 0; i < carsList.size(); i++) {
111   - Cars c=carsList.get(i);
112   - carsMap.put(c.getInsideCode(), c.getSfdc());
113   - }
114   - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
115   - Date dNow = new Date(); //当前时间
116   - Date dBefore = new Date();
117   - Calendar calendar = Calendar.getInstance(); //得到日历
118   - calendar.setTime(dNow);//把当前时间赋给日历
119   - calendar.add(Calendar.DAY_OF_MONTH, -1); //设置为前一天
120   - dBefore = calendar.getTime(); //得到前一天的时间
121   - String rq=sdf.format(dBefore);
122   - //保留两位小数
123   - DecimalFormat df = new DecimalFormat("#.00");
124   - // TODO Auto-generated method stub
125   - Map<String, Object> newMap=new HashMap<String,Object>();
126   - //当天YLB信息
127   -// List<Ylb> ylList=repository.obtainYl(rq,"","","","","nbbm");
128   - List<Ylb> ylList=this.listOrderBy(rq,"","","","","nbbm");
129   - //当天YLXXB信息
130   - // List<Ylxxb> ylxxList=ylxxbRepository.obtainYlxx(rq);
131   - //前一天所有车辆最后进场班次信息
132   - List<Ylb> ylListBe=this.listByRqJcsx(rq,"","","","");
133   -// List<Ylb> ylListBe=repository.listMaxRqJcsx(rq, "", "", "", "");
134   - List<Cyl> clyList=cylRepository.obtainCyl("","");
135   - //从排班表中计算出行驶的总里程
136   - List<Map<String,Object>> listpb=scheduleRealInfoService.yesterdayDataList("", rq, "", "", "", "");
137   -
138   - for(int x=0;x<listpb.size();x++){
139   - boolean sfdc=true;
140   - Map<String, Object> map=listpb.get(x);
141   - if (carsMap.get(map.get("clZbh").toString())!=null) {
142   - sfdc= carsMap.get(map.get("clZbh").toString());
143   - }else{
144   - sfdc=true;
145   - }
146   - if(!sfdc){
147   - //判断驾驶员驾驶的该车辆是否已经存入了(查出的结果集中日期是相同的,根据驾驶员、内部编号、线路编码判断)
148   - Ylb t=new Ylb();
149   - for(int k=0;k<ylList.size();k++){
150   - Ylb t1=ylList.get(k);
151   - if(t1.getNbbm().equals(map.get("clZbh").toString())
152   - &&t1.getJsy().equals(map.get("jGh").toString())
153   - &&t1.getXlbm().equals(map.get("xlBm").toString())
154   - &&t1.getLp().equals(map.get("lpName").toString()))
155   - {
156   - t=t1;
157   - type="update";
158   - }
159   - }
160   -
161   - //当日的第一个班次,出场油量等于前一天的最后一个班次的进场油量
162   - if(map.get("seqNumber").toString().equals("1")){
163   - boolean fage=true;
164   - for (int i = 0; i < ylListBe.size(); i++) {
165   - Ylb ylb=ylListBe.get(i);
166   - if(map.get("clZbh").toString().equals(ylb.getNbbm())){
167   - if(ylb.getJzyl()!=null){
168   - if(ylb.getJzyl()>0){
169   - t.setCzyl(ylb.getJzyl());
170   - fage=false;
171   - break;
172   - }
173   - }
174   -
175   - }
176   - }
177   - if(fage){
178   - for (int y = 0; y < clyList.size(); y++) {
179   - Cyl cyl=clyList.get(y);
180   - if(map.get("clZbh").toString().equals(cyl.getNbbm())){
181   - if(cyl.getCyl()!=null){
182   - t.setCzyl(cyl.getCyl());
183   - fage=false;
184   - break;
185   - }
186   - }
187   - }
188   - }
189   - if(fage){
190   - t.setCzyl(0.0);
191   - }
192   - }
193   - t.setNbbm(map.get("clZbh").toString());
194   - t.setJsy(map.get("jGh")==null?"":map.get("jGh").toString());
195   - t.setZlc(map.get("totalKilometers")==null?0.0:Double.parseDouble(map.get("totalKilometers").toString()));
196   - t.setXlbm(map.get("xlBm")==null?"":map.get("xlBm").toString());
197   - t.setLinename(map.get("lineName")==null?"":map.get("lineName").toString());
198   - t.setJcsx(Integer.parseInt(map.get("seqNumber").toString()));
199   - t.setSsgsdm(map.get("company")==null?"":map.get("company").toString());
200   - t.setFgsdm(map.get("bCompany")==null?"":map.get("bCompany").toString());
201   - t.setLp(map.get("lpName")==null?"":map.get("lpName").toString());
202   - t.setJhsj(map.get("fcsj")==null?"":map.get("fcsj").toString());
203   - t.setJname(map.get("jName").toString());
204   - t.setRq(sdf.parse(rq));
205   - t.setCreatetime(dNow);
206   - if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
207   - if(type.equals("update")){
208   - repository.save(t);
209   - }else{
210   - addList.add(t);
211   - }
212   - }
213   - }
214   -
215   - }
216   - if(addList.size()>0){
217   - try {
218   - new BatchSaveUtils<Ylb>().saveList2(addList, Ylb.class);
219   - } catch (Exception e) {
220   - // TODO: handle exception
221   - if(e.getMessage().indexOf("PK_YLB_UK")>0){
222   - newMap.put("fage", "存在相同数据,数据已经过滤");
223   - logger.info("定时器:存在相同数据,数据已经过滤");
224   - }
225   - }
226   - }
227   - result = "success";
228   - }catch (Exception e) {
229   - // TODO Auto-generated catch block
230   - throw e;
231   - }finally{
232   - logger.info("setDDRB:"+result);
233   - }
234   -
235   - return result;
236   - }
237   -
238   - /**
239   - * 获取进存油信息
240   - * @Transactional 回滚事物
241   - */
242   - @Transactional
243   - @Override
244   - public Map<String, Object> obtain(Map<String, Object> map2) throws Exception{
245   - Map<String, Object> newMap = new HashMap<String, Object>();
246   - try {
247   - Date date=new Date();
248   - List<Cars> carsList = carsRepository.findCars();
249   - Map<String, Boolean> carsMap = new HashMap<String, Boolean>();
250   - for (int i = 0; i < carsList.size(); i++) {
251   - Cars c = carsList.get(i);
252   - carsMap.put(c.getInsideCode(), c.getSfdc());
253   - }
254   - String rq = map2.get("rq").toString();
255   - String line = "";
256   - if (map2.get("xlbm_like") != null) {
257   - line = map2.get("xlbm_like").toString().trim();
258   - }
259   - String gsbm="";
260   - if(map2.get("ssgsdm_like")!=null){
261   - gsbm=map2.get("ssgsdm_like").toString();
262   - }
263   - String fgsbm="";
264   - if(map2.get("fgsdm_like")!=null){
265   - fgsbm=map2.get("fgsdm_like").toString();
266   - }
267   - String nbbm="";
268   - if(map2.get("nbbm_eq")!=null){
269   - nbbm=map2.get("nbbm_eq").toString();
270   - }
271   - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
272   - // 保留两位小数
273   - DecimalFormat df = new DecimalFormat("#.00");
274   - // TODO Auto-generated method stub
275   - // 当天YLB信息
276   - List<Ylb> ylList = this.listOrderBy(rq,gsbm,fgsbm,"",nbbm,"nbbm");
277   -
278   - // 当天YLXXB信息
279   - List<Ylxxb> ylxxList = ylxxbRepository.obtainYlxx(rq, 0,gsbm);
280   -
281   - // 前一天所有车辆最后进场班次信息
282   - List<Ylb> ylListBe = this.listByRqJcsx(rq, gsbm, fgsbm, "", nbbm);
283   - List<Cyl> clyList = cylRepository.obtainCyl(nbbm,gsbm);
284   -
285   - // 从排班表中计算出行驶的总里程
286   - List<Map<String, Object>> listpb =new ArrayList<Map<String, Object>>();
287   - List<Map<String, Object>> listpbs=scheduleRealInfoService.yesterdayDataList("", rq, gsbm, fgsbm, "", nbbm);
288   -
289   - String sxtj=map2.get("sxtj").toString();
290   - if(sxtj.equals("0")){
291   - listpb=listpbs;
292   - }else if (sxtj.equals("5")){
293   - List<String> stringList=new ArrayList<String>();
294   -
295   - List<Object[]> objectLists = repository.checkNbmmFgs(rq, gsbm);
296   - for (int i = 0; i < objectLists.size(); i++) {
297   - String clbm=objectLists.get(i)[0].toString();
298   - stringList.add(clbm);
299   - }
300   -
301   - for (int i = 0; i < stringList.size(); i++) {
302   - String strNbbm=stringList.get(i);
303   - for (int j = 0; j < listpbs.size(); j++) {
304   - Map<String, Object> map = listpbs.get(j);
305   - String mapNbbm=map.get("clZbh").toString();
306   - if(strNbbm.equals(mapNbbm)){
307   - listpb.add(map);
308   - }
309   - }
310   - }
311   -
312   - }else{
313   - List<Object[]> objectLists=repository.checkNbmmNum(rq, gsbm, fgsbm, "",nbbm);
314   - List<String> stringList=new ArrayList<String>();
315   - for (int i = 0; i < objectLists.size(); i++) {
316   - String clbm=objectLists.get(i)[0].toString();
317   - int cs=Integer.parseInt(objectLists.get(i)[1].toString());
318   - //一车一单
319   - if(sxtj.equals("1")){
320   - if(cs==1){
321   - stringList.add(clbm);
322   - }
323   - }
324   - //一车多单
325   - if(sxtj.equals("2")){
326   - if(cs>1){
327   - stringList.add(clbm);
328   - }
329   - }
330   - }
331   -
332   - for (int i = 0; i < stringList.size(); i++) {
333   - String strNbbm=stringList.get(i);
334   - for (int j = 0; j < listpbs.size(); j++) {
335   - Map<String, Object> map = listpbs.get(j);
336   - String mapNbbm=map.get("clZbh").toString();
337   - if(strNbbm.equals(mapNbbm)){
338   - listpb.add(map);
339   - }
340   - }
341   - }
342   - }
343   -
344   - List<Ylb> addList = new ArrayList<Ylb>();
345   - List<Ylb> updateList = new ArrayList<Ylb>();
346   - Map<String, Object> ylMap=new HashMap<String, Object>();
347   -
348   - Map<String, Object> cMap=new HashMap<String, Object>();
349   - for (int x = 0; x < listpb.size(); x++) {
350   - String type = "add";
351   - boolean sfdc = true;
352   - Map<String, Object> map = listpb.get(x);
353   - if (carsMap.get(map.get("clZbh").toString()) != null) {
354   - sfdc = carsMap.get(map.get("clZbh").toString());
355   - } else {
356   - sfdc = true;
357   - }
358   - if (!sfdc) {
359   - // 判断驾驶员驾驶的该车辆是否已经存入了(查出的结果集中日期是相同的,根据驾驶员、内部编号、线路编码判断)
360   - Ylb t = new Ylb();
361   - for (int k = 0; k < ylList.size(); k++) {
362   - Ylb t1 = ylList.get(k);
363   - if (t1.getNbbm().equals(map.get("clZbh").toString())
364   - && t1.getJsy().equals(map.get("jGh").toString())
365   - && t1.getXlbm().equals(map.get("xlBm").toString()
366   - )) {
367   - if(t1.getLp()==null){
368   - //同人同车同线路不同路牌的过滤 (考虑到历史数据)
369   - if (cMap.get(map.get("clZbh").toString()+map.get("jGh").toString()+map.get("xlBm").toString())==null) {
370   - t = t1;
371   - type = "update";
372   - cMap.put(map.get("clZbh").toString()+map.get("jGh").toString()+map.get("xlBm").toString(),
373   - map.get("clZbh").toString());
374   - }
375   - }else{
376   - if(t1.getLp().equals(map.get("lpName").toString())){
377   - t = t1;
378   - type = "update";
379   - }
380   -
381   - }
382   - }
383   - }
384   - // 当日的第一个班次,出场油量等于前一天的最后一个班次的进场油量
385   - if (map.get("seqNumber").toString().equals("1")) {
386   - boolean fage = true;
387   - if(line.equals("")){
388   - for (int i = 0; i < ylListBe.size(); i++) {
389   - Ylb ylb = ylListBe.get(i);
390   - if (map.get("clZbh").toString().equals(ylb.getNbbm())) {
391   - if(ylb.getJzyl()>0){
392   - t.setCzyl(ylb.getJzyl());
393   - fage = false;
394   - break;
395   - }
396   -
397   - }
398   - }
399   - if (fage) {
400   - for (int y = 0; y < clyList.size(); y++) {
401   - Cyl cyl = clyList.get(y);
402   - if (map.get("clZbh").toString().equals(cyl.getNbbm())) {
403   - if(cyl!=null){
404   - if(cyl.getCyl()>=0){
405   - t.setCzyl(cyl.getCyl());
406   - fage = false;
407   - break;
408   - }else {
409   - if(cyl.getCxrl()!=null){
410   - if(cyl.getCxrl()>0){
411   - t.setCzyl(cyl.getCxrl());
412   - fage = false;
413   - break;
414   - }
415   - }
416   - }
417   - }
418   - }
419   - }
420   - }
421   - if (fage) {
422   - t.setCzyl(0.0);
423   - }
424   - }else{
425   - if (line.equals(map.get("xlBm").toString())) {
426   - for (int i = 0; i < ylListBe.size(); i++) {
427   - Ylb ylb = ylListBe.get(i);
428   - if (map.get("clZbh").toString().equals(ylb.getNbbm())) {
429   - if(ylb.getJzyl()>0){
430   - t.setCzyl(ylb.getJzyl());
431   - fage = false;
432   - break;
433   - }
434   -
435   - }
436   - }
437   - if (fage) {
438   - for (int y = 0; y < clyList.size(); y++) {
439   - Cyl cyl = clyList.get(y);
440   - if (map.get("clZbh").toString().equals(cyl.getNbbm())) {
441   - if(cyl!=null){
442   - if(cyl.getCyl()>=0){
443   - t.setCzyl(cyl.getCyl());
444   - fage = false;
445   - break;
446   - }else {
447   - if(cyl.getCxrl()!=null){
448   - if(cyl.getCxrl()>0){
449   - t.setCzyl(cyl.getCxrl());
450   - fage = false;
451   - break;
452   - }
453   - }
454   - }
455   - }
456   - }
457   - }
458   - }
459   - if (fage) {
460   - t.setCzyl(0.0);
461   - }
462   - }
463   - }
464   -
465   - }
466   -
467   - Double jzl = 0.0;
468   - //一人一车加注量只匹配一次
469   - if(ylMap.get(map.get("clZbh").toString()+"_"+ map.get("jGh").toString())==null){
470   -
471   - boolean fage2=false;
472   - for (int i = 0; i < ylxxList.size(); i++) {
473   - Ylxxb ylxxb = ylxxList.get(i);
474   - if (map.get("clZbh").toString().equals(ylxxb.getNbbm())
475   - && map.get("jGh").toString().equals(ylxxb.getJsy())
476   - && ylxxb.getJylx()==1) {
477   - if(ylxxb.getJzl()>0){
478   - fage2=true;
479   - }
480   -
481   - }
482   - }
483   - //车辆的加注量如果有任工干预,略接口过来 数据
484   - if(fage2){
485   - // 把当天手工输入的的YLXXB的加注量设置为当天YLB的加注量(根据车号,驾驶员判断,加油类型为1)
486   - for (int j = 0; j < ylxxList.size(); j++) {
487   - Ylxxb ylxxb = ylxxList.get(j);
488   - if (map.get("clZbh").toString().equals(ylxxb.getNbbm())
489   - && map.get("jGh").toString().equals(ylxxb.getJsy())
490   - && ylxxb.getJylx()==1) {
491   - jzl =Arith.add(jzl, ylxxb.getJzl());
492   - }
493   - }
494   - ylMap.put(map.get("clZbh").toString()+"_"+ map.get("jGh").toString(),map.get("xlBm") == null ? "" : map.get("xlBm").toString());
495   - }else{
496   - // 把当天的YLXXB的加注量设置为当天YLB的加注量(根据车号,驾驶员判断)
497   - for (int j = 0; j < ylxxList.size(); j++) {
498   - Ylxxb ylxxb = ylxxList.get(j);
499   - if (map.get("clZbh").toString().equals(ylxxb.getNbbm())
500   - && map.get("jGh").toString().equals(ylxxb.getJsy())) {
501   - jzl =Arith.add(jzl, ylxxb.getJzl());
502   - }
503   - }
504   - ylMap.put(map.get("clZbh").toString()+"_"+ map.get("jGh").toString(),map.get("xlBm") == null ? "" : map.get("xlBm").toString());
505   - }
506   -
507   - }
508   - t.setJzl(jzl);
509   - t.setNbbm(map.get("clZbh").toString());
510   - t.setJsy(map.get("jGh") == null ? "" : map.get("jGh").toString());
511   - t.setZlc(map.get("totalKilometers") == null ? 0.0
512   - : Double.parseDouble(map.get("totalKilometers").toString()));
513   - t.setXlbm(map.get("xlBm") == null ? "" : map.get("xlBm").toString());
514   - t.setLinename(map.get("lineName")==null?"":map.get("lineName").toString());
515   - t.setJcsx(Integer.parseInt(map.get("seqNumber").toString()));
516   - t.setSsgsdm(map.get("company") == null ? "" : map.get("company").toString());
517   - t.setFgsdm(map.get("bCompany") == null ? "" : map.get("bCompany").toString());
518   - t.setJhsj(map.get("fcsj")==null?"":map.get("fcsj").toString());
519   - t.setRq(sdf.parse(rq));
520   - t.setLp(map.get("lpName")==null?"":map.get("lpName").toString());
521   - t.setJname(map.get("jName").toString());
522   - if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
523   - if(type.equals("add")){
524   - t.setCreatetime(date);
525   - addList.add(t);
526   - }else{
527   - t.setUpdatetime(date);
528   - updateList.add(t);
529   - }
530   - }
531   -// repository.save(t);
532   - newMap.put("status", ResponseCode.SUCCESS);
533   -
534   - }
535   - }
536   - if(addList.size()>0){
537   - try {
538   - new BatchSaveUtils<Ylb>().saveList2(addList, Ylb.class);
539   - } catch (Exception e) {
540   - // TODO: handle exception
541   - if(e.getMessage().indexOf("PK_YLB_UK")>0){
542   - newMap.put("fage", "存在相同数据,数据已经过滤");
543   - logger.info("获取:存在相同数据,数据已经过滤");
544   - }
545   - }
546   -
547   - }
548   - if(updateList.size()>0){
549   - for (int i = 0; i < updateList.size(); i++) {
550   - repository.save(updateList.get(i));
551   - }
552   - }
553   - SysUser user = SecurityUtils.getCurrentUser();
554   - Nylog nylog=new Nylog();
555   - nylog.setCreatedate(new Date());
556   - nylog.setCzmc("获取加存油");
557   - nylog.setNylx("油");
558   - nylog.setUserid(user.getUserName());
559   - nylog.setUsername(user.getName());
560   - nylog.setCxtj(rq+"-"+gsbm+"-"+fgsbm+"-"+line+"-"+nbbm+"-"+sxtj);
561   - nylogRepository.save(nylog);
562   - newMap.put("status", ResponseCode.SUCCESS);
563   - } catch (Exception e) {
564   - // TODO Auto-generated catch block
565   - newMap.put("status", ResponseCode.ERROR);
566   - throw e;
567   - }
568   -
569   - return newMap;
570   - }
571   -
572   -
573   - /**
574   - * 进场等于出场
575   - */
576   - @Transactional
577   - @Override
578   - public Map<String, Object> outAndIn(Map<String, Object> map) throws Exception{
579   - // TODO Auto-generated method stub
580   - String xlbm="";
581   - if(map.get("xlbm_like")!=null){
582   - xlbm= map.get("xlbm_like").toString().trim();
583   - }
584   - String gsbm="";
585   - if(map.get("ssgsdm_like")!=null){
586   - gsbm=map.get("ssgsdm_like").toString();
587   - }
588   - String fgsbm="";
589   - if(map.get("fgsdm_like")!=null){
590   - fgsbm=map.get("fgsdm_like").toString();
591   - }
592   - String rq = map.get("rq").toString();
593   - String nbbm="";
594   - if(map.get("nbbm_eq")!=null){
595   - nbbm=map.get("nbbm_eq").toString();
596   - }
597   -
598   - Map<String, Object> newMap=new HashMap<String,Object>();
599   - Map<String, Object> map2=new HashMap<String,Object>();
600   - try {
601   - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
602   -
603   - map.put("rq_eq", sdf.parse(rq));
604   -// List<Cyl> clyList = cylRepository.obtainCyl();
605   - // 获取车辆存油信息
606   - List<Cyl> cylList = cylRepository.obtainCyl(nbbm,gsbm);
607   - // 指定日期YLB信息
608   - List<Ylb> ylbList =new ArrayList<Ylb>();
609   - List<Ylb> ylbLists =new ArrayList<Ylb>();
610   - List<Ylb> iterator2=new ArrayList<Ylb>();
611   - ylbLists=this.listOrderBy(rq,gsbm,fgsbm,xlbm,nbbm,"jcsx");
612   - iterator2=this.listOrderBy(rq,gsbm,fgsbm,xlbm,nbbm,"nbbm,jcsx");
613   - // 从排班表中计算出行驶的总里程
614   -
615   - String sxtj=map.get("sxtj").toString();
616   - if(sxtj.equals("0")){
617   - ylbList=ylbLists;
618   - }else{
619   - List<Object[]> objectLists=repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm,nbbm);
620   - List<String> stringList=new ArrayList<String>();
621   - for (int i = 0; i < objectLists.size(); i++) {
622   - String clbm=objectLists.get(i)[0].toString();
623   - int cs=Integer.parseInt(objectLists.get(i)[1].toString());
624   - //一车一单
625   - if(sxtj.equals("1")){
626   - if(cs==1){
627   - stringList.add(clbm);
628   - }
629   - }
630   - //一车多单
631   - if(sxtj.equals("2")){
632   - if(cs>1){
633   - stringList.add(clbm);
634   - }
635   - }
636   - }
637   -
638   - for (int i = 0; i < stringList.size(); i++) {
639   - String strNbbm=stringList.get(i);
640   - for (int j = 0; j < ylbLists.size(); j++) {
641   - Ylb y = ylbLists.get(j);
642   - String mapNbbm=y.getNbbm();
643   - if(strNbbm.equals(mapNbbm)){
644   - ylbList.add(y);
645   - }
646   - }
647   - }
648   - }
649   -
650   - for (int i=0;i<ylbList.size();i++) {
651   - Ylb ylb = ylbList.get(i);
652   - // 判断是否已经计算过
653   - if (newMap.get("nbbm" + ylb.getNbbm()) == null) {
654   - String nbbm_eq = ylb.getNbbm();
655   - Date rq_eq = ylb.getRq();
656   - // 得到一天总的加油和里程(根据车,时间)
657   - List<Object[]> sumList = repository.sumLcYl(nbbm_eq, rq_eq,"",gsbm,fgsbm);
658   - // 保存总的加油量
659   - Double jzl = 0.0;
660   - // 保存总的里程
661   - Double zlc = 0.0;
662   - //保存总的损耗
663   - Double zsh = 0.0;
664   - for (int j = 0; j < sumList.size(); j++) {
665   - jzl = Arith.add(jzl, Double.valueOf(sumList.get(j)[0].toString()));
666   - zlc = Arith.add(zlc, Double.valueOf(sumList.get(j)[1].toString()));
667   - zsh = Arith.add(zsh, Double.valueOf(sumList.get(j)[2].toString()));
668   - }
669   -// jzl = Arith.sub(jzl, zsh);
670   - // 保留两位小数
671   - DecimalFormat df = new DecimalFormat("#.00");
672   - Double zyl = 0.0;
673   - Double nextJzyl = 0.0;
674   - // 保存已经计算过的车辆,相同车辆编号的车不在计算
675   - newMap.put("nbbm" + ylb.getNbbm(), ylb.getNbbm());
676   -
677   - // 查询指定车辆,设置进、存、耗油量
678   - map.remove("nbbm_eq");
679   - map.put("nbbm_eq", ylb.getNbbm());
680   - map.put("xlbm_like", ylb.getXlbm());
681   -// Iterator<Ylb> iterator2 = repository
682   -// .findAll(new CustomerSpecs<Ylb>(map), new Sort(Direction.ASC, "jcsx")).iterator();
683   - double czyl=0.0;
684   - for (int j = 0; j < iterator2.size(); j++) {
685   - Ylb t = iterator2.get(j);
686   - if(t.getNbbm().equals(ylb.getNbbm())){
687   - if (t.getJcsx() == 1) {
688   - // 进场等于出场的操作 既 最后进场存油量等于第一次的出场存油量
689   -// Double yl = t.getCzyl();
690   -// Double jcyl = t.getCzyl();
691   - czyl = t.getCzyl();
692   - zyl =jzl;
693   - Double yh=0.0;
694   - if(zlc>0 ){
695   - yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
696   - }
697   - nextJzyl =Arith.sub( Arith.add(t.getJzl(), t.getCzyl()),yh);
698   -// nextJzyl =Arith.sub( Arith.add(Arith.sub(t.getJzl(),t.getSh()), t.getCzyl()),yh);
699   - //把进场油量的小数和整数分别取出
700   -// int ylxs=(int) nextJzyl; 10.6--11 10.3--10
701   - if(zlc>0 && t.getZlc()>0){
702   - long l=Math.round(nextJzyl);
703   - double ylxs=l*100/100;
704   -// nextJzyl = Arith.add(nextJzyl,Arith.sub(nextJzyl,ylxs));
705   - yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
706   - t.setYh(yh);
707   - t.setJzyl(ylxs);
708   - nextJzyl=ylxs;
709   - }else{
710   - t.setYh(yh);
711   - t.setJzyl(nextJzyl);
712   - }
713   - } else {
714   - t.setCzyl(nextJzyl);
715   - Double yh=0.0;
716   - if(zlc>0){
717   - yh= Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
718   - }
719   - nextJzyl =Arith.sub( Arith.add(t.getJzl(),nextJzyl),yh);
720   -// nextJzyl =Arith.sub( Arith.add(Arith.sub(t.getJzl(),t.getSh()),nextJzyl),yh);
721   - if(zlc>0 && t.getZlc()>0){
722   - long l=0l;
723   - double ylxs=0.0;
724   - if(j==iterator2.size()-1){
725   - ylxs=czyl;
726   - }else{
727   - if(iterator2.get(j+1).getNbbm().equals(t.getNbbm())){
728   - l=Math.round(nextJzyl);
729   - ylxs=l*100/100;
730   - }else{
731   - ylxs=czyl;
732   - }
733   -
734   - }
735   - yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
736   -// nextJzyl = Arith.add(nextJzyl,Arith.sub(nextJzyl,ylxs));
737   -
738   - t.setYh(yh);
739   - t.setJzyl(ylxs);
740   - nextJzyl=ylxs;
741   - }else{
742   - t.setYh(yh);
743   - t.setJzyl(nextJzyl);
744   - }
745   - }
746   - if(t.getJzyl()<0){
747   - t.setJzyl(0.0);
748   - }
749   - if(t.getCzyl()<0){
750   - t.setCzyl(0.0);
751   - }
752   - if(t.getYh()<0){
753   - t.setYh(0.0);
754   - }
755   - if(t.getSh()<0){
756   - t.setSh(0.0);
757   - }
758   - repository.save(t);
759   - }
760   - map2.put("status", ResponseCode.SUCCESS);
761   - }
762   - }
763   - }
764   -
765   - SysUser user = SecurityUtils.getCurrentUser();
766   - Nylog nylog=new Nylog();
767   - nylog.setCreatedate(new Date());
768   - nylog.setCzmc("进场等于出场");
769   - nylog.setNylx("油");
770   - nylog.setUserid(user.getUserName());
771   - nylog.setUsername(user.getName());
772   - nylog.setCxtj(rq+"-"+gsbm+"-"+fgsbm+"-"+xlbm+"-"+nbbm+"-"+sxtj);
773   -
774   - nylogRepository.save(nylog);
775   - } catch (Exception e) {
776   - map2.put("status", ResponseCode.ERROR);
777   - logger.error("save erro.", e);
778   - throw e;
779   - }
780   - return map2;
781   - }
782   -
783   -
784   - /**
785   - * 核对,有加注没里程
786   - * @param map
787   - * @return
788   - */
789   - @Transactional
790   - @Override
791   - public Map<String, Object> checkYl(Map<String, Object> map) throws Exception{
792   - Map<String, Object> newMap=new HashMap<String,Object>();
793   -// String xlbm="";
794   -// if(map.get("xlbm_like")!=null){
795   -// xlbm=map.get("xlbm_like").toString();
796   -// }
797   - // TODO Auto-generated method stub
798   -
799   - List<Cars> carsList = carsRepository.findCars();
800   - Map<String, String> carsMap = new HashMap<String, String>();
801   - for (int i = 0; i < carsList.size(); i++) {
802   - Cars c = carsList.get(i);
803   - carsMap.put(c.getInsideCode(), c.getBrancheCompanyCode()==null?"":c.getBrancheCompanyCode());
804   - }
805   -
806   - try{
807   - //获取车辆存油信息
808   -
809   - String rq=map.get("rq").toString();
810   - String xlbm="";
811   - if(map.get("xlbm_like")!=null){
812   - xlbm= map.get("xlbm_like").toString().trim();
813   - }
814   - String gsbm="";
815   - if(map.get("ssgsdm_like")!=null){
816   - gsbm=map.get("ssgsdm_like").toString();
817   - }
818   - String fgsbm="";
819   - if(map.get("fgsdm_like")!=null){
820   - fgsbm=map.get("fgsdm_like").toString();
821   - }
822   - String nbbm="";
823   - if(map.get("nbbm_eq")!=null){
824   - nbbm=map.get("nbbm_eq").toString();
825   - }
826   -// List<Ylb> ylListBe=repository.obtainYlbefore(rq, gsbm, "", xlbm, nbbm);
827   - List<Ylb> ylListBe=this.listByRqJcsx(rq, gsbm, fgsbm, "", nbbm);
828   - List<Ylb> ylbList=this.listOrderBy(rq,gsbm,fgsbm,xlbm,nbbm,"nbbm");
829   -// repository.obtainYl(rq,gsbm,fgsbm,xlbm,nbbm,"nbbm");
830   -// List<Ylxxb> ylxxbList=ylxxbRepository.obtainYlxx(rq,0,gsbm);
831   - String sql="select * from bsth_c_ylxxb where yyrq='"+rq+"' "
832   - + " and gsdm ='"+gsbm+"' and nylx ='0' and nbbm "
833   - + " not in ( select nbbm from bsth_c_ylb "
834   - + " where rq='"+rq+"' "
835   - + " and ssgsdm='"+gsbm+"' and fgsdm ='"+fgsbm+"')"
836   - + " and nbbm in (select inside_code from "
837   - + " bsth_c_cars where business_code ='"+gsbm+"' "
838   - + " and branche_company_code='"+fgsbm+"')";
839   -
840   - List<Ylxxb> ylxxbList=jdbcTemplate.query(sql,
841   - new RowMapper<Ylxxb>(){
842   - @Override
843   - public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException {
844   - Ylxxb s = new Ylxxb();
845   - s.setId(rs.getInt("id"));
846   - s.setYyrq(rs.getDate("yyrq"));
847   - s.setNbbm(rs.getString("nbbm"));
848   - s.setGsdm(rs.getString("gsdm"));
849   - s.setFgsdm(rs.getString("fgsdm"));
850   - s.setJsy(rs.getString("jsy"));
851   - s.setJzl(rs.getDouble("jzl"));
852   - s.setStationid(rs.getString("stationid"));
853   - s.setNylx(rs.getInt("nylx"));
854   - s.setJyggh(rs.getString("jyggh"));
855   - s.setYj(rs.getDouble("yj"));
856   -// s.setLdgh(rs.getString("ldgh"));
857   - s.setBz(rs.getString("bz"));
858   - return s;
859   - }
860   - });
861   - Map<String, Object> m=new HashMap<String,Object>();
862   - for (int i = 0; i < ylxxbList.size(); i++) {
863   - Boolean fage=false;
864   - Ylxxb y1=ylxxbList.get(i);
865   - if(m.get(y1.getNbbm())==null){
866   - Line line=BasicData.nbbm2LineMap.get(y1.getNbbm());
867   - if(null !=line){
868   - if(!xlbm.equals("")){
869   - if(line.getLineCode().equals(xlbm)){
870   - fage=true;
871   - }
872   - }else{
873   - fage=true;
874   - }
875   - }
876   -
877   - if(fage){
878   - Ylb t=new Ylb();
879   - t.setNbbm(y1.getNbbm());
880   - t.setRq(y1.getYyrq());
881   - t.setJsy(y1.getJsy());
882   - t.setJname(BasicData.allPerson.get(y1.getGsdm()+"-"+y1.getJsy()));
883   - t.setJzl(y1.getJzl());
884   - t.setSsgsdm(y1.getGsdm());
885   - String fgsdm="";
886   - if(null !=carsMap.get(y1.getNbbm())){
887   - fgsdm=carsMap.get(y1.getNbbm());
888   - }
889   - t.setFgsdm(fgsdm);
890   - t.setJcsx(1);
891   - if(null !=line){
892   - t.setXlbm(line.getLineCode());
893   - }else{
894   - t.setXlbm("");
895   - }
896   - t.setJcsx(1);
897   - boolean status=true;
898   - for (int j = 0; j < ylListBe.size(); j++) {
899   - Ylb b=ylListBe.get(j);
900   - if(b.getNbbm().equals(y1.getNbbm())){
901   - t.setCzyl(b.getJzyl());
902   - status=false;
903   - break;
904   - }
905   - }
906   - if(status){
907   - t.setCzyl(0.0);
908   - }
909   - t.setJzyl(Arith.add(t.getJzl(), t.getCzyl()));
910   - t.setYh(0.0);
911   - if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
912   - t.setCreatetime(new Date());
913   - try {
914   - repository.save(t);
915   - m.put(t.getName(), t.getName());
916   - } catch (Exception e) {
917   - // TODO: handle exception
918   - if(e.getMessage().indexOf("PK_YLB_UK")>0){
919   - newMap.put("fage", "存在相同数据,数据已经过滤");
920   - logger.info("核对有存油没里程:存在相同数据,数据已经过滤");
921   - }
922   - }
923   - }
924   - }
925   - }
926   - }
927   -
928   - SysUser user = SecurityUtils.getCurrentUser();
929   - Nylog nylog=new Nylog();
930   - nylog.setCreatedate(new Date());
931   - nylog.setCzmc("核对加注量");
932   - nylog.setNylx("油");
933   - nylog.setUserid(user.getUserName());
934   - nylog.setUsername(user.getName());
935   - nylog.setCxtj(rq+"-"+gsbm+"-"+fgsbm+"-"+xlbm+"-"+nbbm+"-");
936   - nylogRepository.save(nylog);
937   - newMap.put("status", ResponseCode.SUCCESS);
938   - }catch(Exception e){
939   - newMap.put("status", ResponseCode.ERROR);
940   - logger.error("save erro.", e);
941   - throw e;
942   - }
943   -
944   - return newMap;
945   - }
946   -
947   -
948   - @Override
949   - public List<Map<String, Object>> oilListMonth(Map<String, Object> map) {
950   - SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"),
951   - sdfSimple = new SimpleDateFormat("yyyyMMdd");
952   -
953   - String type=map.get("type").toString();
954   - String date=map.get("date").toString().trim();
955   - String gsdm=map.get("gsdm").toString();
956   - String fgsdm=map.get("fgsdm").toString();
957   - String date2=date.substring(0, 8)+"01";
958   - String lineStr="";
959   - String line =map.get("line").toString().trim();
960   - /*if(line !=null && !line.equals("")){
961   - lineStr =" and xlbm= '"+ line +"'";
962   - }else{
963   - lineStr =" and ssgsdm='"+gsdm+"' and fgsdm ='"+fgsdm+"' ";
964   - }
965   - String sql="select a.nbbm,a.rq,a.jzyl from (" +
966   - " select x.nbbm,max(x.rq) as rq,max(x.jcsx) as jcsx from "
967   - + "(select nbbm,rq,max(jcsx) as jcsx from bsth_c_ylb where rq between '"
968   - + date2 +"' and '" + date+"' "+lineStr
969   - + " group by nbbm,rq) x group by x.nbbm ) b"
970   - + " left join (select nbbm,rq,jzyl,jcsx FROM bsth_c_ylb "
971   - + " where rq between '"
972   - + date2 +"' and '" + date+"' "+lineStr
973   - + ") a "
974   - + " on a.nbbm =b.nbbm and a.jcsx=b.jcsx and a.rq=b.rq "
975   - + " where a.nbbm is not null order by a.nbbm";
976   -
977   - // TODO Auto-generated method stub
978   - List<Ylb> list =jdbcTemplate.query(sql,
979   - new RowMapper<Ylb>(){
980   - @Override
981   - public Ylb mapRow(ResultSet rs, int rowNum) throws SQLException {
982   - Ylb s = new Ylb();
983   - s.setNbbm(rs.getString("nbbm"));
984   - s.setRq(rs.getDate("rq"));
985   - s.setJzyl(rs.getDouble("jzyl"));
986   - return s;
987   - }
988   - }); */
989   -
990   - double qtyy=0.0;//其他用油
991   - double cdyy=0.0;//车队用油
992   - double byyy=0.0;//保养用油
993   - double cjxx=0.0;//车间小修
994   - double cjgb=0.0;//车间高保
995   - double fyyyhj=0.0;//非营运用油合计
996   - List<Ylb> listYlb=repository.listByMonthJcsx(date2, date, gsdm, fgsdm, line);
997   -
998   - Map<String, Object> ms=new HashMap<String,Object>();
999   - List<Ylb> list=new ArrayList<Ylb>();
1000   - for (int i = 0; i < listYlb.size(); i++) {
1001   - Ylb t=listYlb.get(i);
1002   - fyyyhj =Arith.add(fyyyhj, t.getSh());
1003   - if(t.getShyy()==null){
1004   - qtyy=Arith.add(qtyy, t.getSh());
1005   - }else{
1006   - if(t.getShyy().equals("6")){
1007   - cdyy=Arith.add(cdyy, t.getSh());
1008   - }else if(t.getShyy().equals("2")){
1009   - byyy=Arith.add(byyy, t.getSh());
1010   - }else if(t.getShyy().equals("7")){
1011   - cjxx=Arith.add(cjxx, t.getSh());
1012   - }else if(t.getShyy().equals("8")){
1013   - cjgb=Arith.add(cjgb, t.getSh());
1014   - }else{
1015   - qtyy=Arith.add(qtyy, t.getSh());
1016   - }
1017   - }
1018   - if(ms.get(t.getNbbm())==null){
1019   - ms.put(t.getNbbm(), t.getNbbm());
1020   - list.add(t);
1021   - }
1022   - }
1023   -
1024   - List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
1025   - int size = 0;
1026   - Map<String, Object> m_ = new HashMap<String, Object>();
1027   - double ycyhj=0.0;
1028   - for(Ylb ylb : list){
1029   - ycyhj=Arith.add(ycyhj, ylb.getJzyl());
1030   - int x=size%3;
1031   - if(x==0 && size>0){
1032   - mapList.add(m_);
1033   - m_ = new HashMap<String, Object>();
1034   - }
1035   - size++;
1036   - m_.put("xh"+x, size);
1037   - m_.put("nbbm"+x, ylb.getNbbm()!=null?ylb.getNbbm():"");
1038   - m_.put("rq"+x, ylb.getRq()!=null?sdfMonth.format(ylb.getRq()):"");
1039   - m_.put("jzyl"+x, ylb.getJzyl()!=null?ylb.getJzyl():"");
1040   -
1041   - }
1042   - if(m_.get("nbbm0")!=null){
1043   - if(m_.get("nbbm1")==null){
1044   - m_.put("xh1", "");
1045   - m_.put("nbbm1" , "");
1046   - m_.put("rq1" , "");
1047   - m_.put("jzyl1" , "");
1048   - }
1049   - if(m_.get("nbbm2")==null){
1050   - m_.put("xh2", "");
1051   - m_.put("nbbm2" , "");
1052   - m_.put("rq2" , "");
1053   - m_.put("jzyl2" , "");
1054   - }
1055   - mapList.add(m_);
1056   - }
1057   -
1058   - if(type != null && type.equals("export")){
1059   - List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
1060   - Map<String, Object> m = new HashMap<String, Object>();
1061   - m.put("ycyhj", ycyhj);
1062   - m.put("qtyy", qtyy);
1063   - m.put("cdyy", cdyy);
1064   - m.put("byyy", byyy);
1065   - m.put("cjxx", cjxx);
1066   - m.put("cjgb", cjgb);
1067   - m.put("fyyyhj", fyyyhj);
1068   - ReportUtils ee = new ReportUtils();
1069   - try {
1070   - String lineName = "";
1071   - if(map.containsKey("lineName"))
1072   - lineName = map.get("lineName").toString();
1073   - listI.add(mapList.iterator());
1074   - String path = this.getClass().getResource("/").getPath()+"static/pages/forms/";
1075   - ee.excelReplace(listI, new Object[] { m }, path+"mould/oilListMonth.xls",
1076   - path+"export/" + sdfSimple.format(sdfMonth.parse(date))
1077   - + "-" + lineName + "-月存油报表.xls");
1078   - } catch (Exception e) {
1079   - // TODO: handle exception
1080   - e.printStackTrace();
1081   - }
1082   - }else{
1083   - m_=new HashMap<String,Object>();
1084   - m_.put("xh0", "99");
1085   - m_.put("nbbm0", "存油合计:"+ycyhj +" 非营运用油: 其他用油:"+qtyy +",车队:"+cdyy+",保养用油:"+byyy
1086   - +",车间(小修):"+cjxx+",车间(高保):"+cjgb+",非营运用油合计:"+fyyyhj);
1087   - mapList.add(m_);
1088   - }
1089   -
1090   - return mapList;
1091   - }
1092   -
1093   - @Override
1094   - public StringBuffer checkNbmmNum(String rq, String gsbm, String fgsbm, String xlbm,String nbbm,int lx) {
1095   - StringBuffer stringList =new StringBuffer();
1096   - List<Object[]> objectList=repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm,nbbm);
1097   - for (int i = 0; i < objectList.size(); i++) {
1098   - String clbm=objectList.get(i)[0].toString()+",";
1099   - int cs=Integer.parseInt(objectList.get(i)[1].toString());
1100   - //一车一单
1101   - if(lx==1){
1102   - if(cs==1){
1103   - stringList.append(clbm);
1104   - }
1105   - }
1106   - //一车多单
1107   - if(lx==2){
1108   - if(cs>1){
1109   - stringList.append(clbm);
1110   - }
1111   -
1112   - }
1113   - }
1114   - return stringList;
1115   - }
1116   -
1117   -
1118   -
1119   - @Override
1120   - public Map<String, Object> sumYlb(Map<String, Object> map) {
1121   - // TODO Auto-generated method stub
1122   - List<String> stringList=new ArrayList<String>();
1123   - String rq=map.get("rq").toString();
1124   - String gsbm=map.get("ssgsdm_like").toString();
1125   - String fgsbm=map.get("fgsdm_like").toString();
1126   - String xlbm=map.get("xlbm_like").toString().trim();
1127   - String nbbm=map.get("nbbm_eq").toString();
1128   - String sxtj=map.get("sxtj").toString();
1129   - String type=map.get("type").toString();
1130   - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1131   - List<Object[]> sumYlbList=new ArrayList<Object[]>();
1132   - try {
1133   - if(nbbm.trim()!=""){
1134   - stringList.add(nbbm);
1135   - }else{
1136   - if(!sxtj.equals("0")){
1137   - List<Object[]> objectLists;
1138   - if(sxtj.equals("3")){
1139   - //有加油没里程
1140   - objectLists=repository.checkNbmmYl(rq, gsbm, fgsbm, xlbm, nbbm);
1141   - for (int i = 0; i < objectLists.size(); i++) {
1142   - String clbm=objectLists.get(i)[0].toString();
1143   - double jzl=Double.parseDouble(objectLists.get(i)[1].toString());
1144   - double zlc=Double.parseDouble(objectLists.get(i)[2].toString());
1145   - if(jzl>0 && zlc<=0){
1146   - stringList.add(clbm);
1147   - }
1148   -
1149   - }
1150   -
1151   - }else if(sxtj.equals("4")){
1152   - //有里程没加油
1153   - objectLists=repository.checkNbmmYl(rq, gsbm, fgsbm, xlbm, nbbm);
1154   - for (int i = 0; i < objectLists.size(); i++) {
1155   - String clbm=objectLists.get(i)[0].toString();
1156   - double jzl=Double.parseDouble(objectLists.get(i)[1].toString());
1157   - double zlc=Double.parseDouble(objectLists.get(i)[2].toString());
1158   - if(zlc>0 && jzl<=0){
1159   - stringList.add(clbm);
1160   - }
1161   -
1162   - }
1163   - }else{
1164   - objectLists=repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm,nbbm);
1165   - for (int i = 0; i < objectLists.size(); i++) {
1166   - String clbm=objectLists.get(i)[0].toString();
1167   - int cs=Integer.parseInt(objectLists.get(i)[1].toString());
1168   - //一车一单
1169   -
1170   - if(sxtj.equals("1")){
1171   - if(cs==1){
1172   - stringList.add(clbm);
1173   - }
1174   - }
1175   - //一车多单
1176   - if(sxtj.equals("2")){
1177   - if(cs>1){
1178   - stringList.add(clbm);
1179   - }
1180   - }
1181   - }
1182   - }
1183   - }
1184   - }
1185   - if(sxtj.equals("0")){
1186   - sumYlbList=repository.sumYlb2(rq, gsbm, fgsbm, xlbm,nbbm);
1187   - }else{
1188   - if(stringList.size()>0){
1189   -
1190   -// String strings[]=new String[stringList.size()];
1191   -// for(int i=0;i<stringList.size();i++){
1192   -// strings[i]=stringList.get(i);
1193   -// }
1194   - if (type.equals("1"))
1195   - sumYlbList=repository.sumYlb(rq, gsbm, fgsbm, xlbm, stringList);
1196   - else
1197   - sumYlbList=repository.sumYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
1198   - }
1199   -// else{
1200   -// sumYlbList=repository.sumYlb2(rq, gsbm, fgsbm, xlbm, nbbm);
1201   -// }
1202   -
1203   - }
1204   - } catch (ParseException e) {
1205   - // TODO Auto-generated catch block
1206   - e.printStackTrace();
1207   - }
1208   - Double jzl=0.0,yh=0.0,sh=0.0;
1209   - for (int i = 0; i < sumYlbList.size(); i++) {
1210   - jzl = Arith.add(jzl, Double.valueOf(sumYlbList.get(i)[0].toString()));
1211   - yh = Arith.add(yh, Double.valueOf(sumYlbList.get(i)[1].toString()));
1212   - sh = Arith.add(sh, Double.valueOf(sumYlbList.get(i)[2].toString()));
1213   - }
1214   -
1215   - Map<String, Object> sumMap=new HashMap<String,Object>();
1216   - sumMap.put("jzl", jzl);
1217   - sumMap.put("yh", yh);
1218   - sumMap.put("sh", sh);
1219   -
1220   -// String sql="select sum(jzl),sum(yh),sum(sh) from bsth_c_ylb "
1221   -// + " where to_days('"+map.get("rq").toString()+"')=to_days(rq) "
1222   -// + " and ssgsdm like '%"+map.get("ssgsdm_like").toString()+"%' "
1223   -// + " and fgsdm like '%"+map.get("fgsdm_like").toString()+"%' "
1224   -// + " and xlbm like '%"+map.get("xlbm_like").toString()+ "%'"
1225   -// + " and nbbm like '%"+map.get("nbbm_eq").toString()+"% '";
1226   -// if(map.get("nbbm_in")!=null){
1227   -//// sql +=" and nbbm in ("
1228   -// }
1229   - return sumMap;
1230   - }
1231   -
1232   -
1233   -
1234   - @Override
1235   - public List<Ylb> listYlb(Map<String, Object> map) {
1236   - // TODO Auto-generated method stub
1237   - List<Ylb> listYlb = new ArrayList<Ylb>();
1238   - try {
1239   - List<String> stringList = new ArrayList<String>();
1240   - String rq = map.get("rq").toString();
1241   - String gsbm = map.get("ssgsdm_like").toString();
1242   - String fgsbm = map.get("fgsdm_like").toString();
1243   - String xlbm = map.get("xlbm_like").toString().trim();
1244   - String nbbm = map.get("nbbm_eq").toString();
1245   - String sxtj = map.get("sxtj").toString();
1246   - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1247   - String type = map.get("type").toString();
1248   - if (nbbm.trim() != "") {
1249   - stringList.add(nbbm);
1250   - List<Object[]> objectLists = repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm, nbbm);
1251   - if (objectLists.size() > 0) {
1252   - int cs = Integer.parseInt(objectLists.get(0)[1].toString());
1253   - if (sxtj.equals("1")) {
1254   - if (cs == 1) {
1255   - if (type.equals("1"))
1256   - listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
1257   - else
1258   - listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
1259   -
1260   - }
1261   - } else if (sxtj.equals("2")) {
1262   - if (cs > 1) {
1263   - if (type.equals("1"))
1264   - listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
1265   - else
1266   - listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
1267   - }
1268   - } else {
1269   - if (type.equals("1"))
1270   - listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
1271   - else
1272   - listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
1273   - }
1274   - }
1275   -
1276   - } else {
1277   - // 全部
1278   - if (sxtj.equals("0")) {
1279   - List<Object[]> objectLists = repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm, nbbm);
1280   - for (int i = 0; i < objectLists.size(); i++) {
1281   - String clbm = objectLists.get(i)[0].toString();
1282   - stringList.add(clbm);
1283   - }
1284   - if (stringList.size() > 0) {
1285   - if (type.equals("1"))
1286   - listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
1287   - else
1288   - listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
1289   - }
1290   - }else if(sxtj.equals("5")){
1291   - List<Object[]> objectLists = repository.checkNbmmFgs(rq, gsbm);
1292   - for (int i = 0; i < objectLists.size(); i++) {
1293   - String clbm =objectLists.get(i)[0].toString();
1294   - stringList.add(clbm);
1295   - }
1296   -
1297   - if (stringList.size() > 0) {
1298   - if (type.equals("1"))
1299   - listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
1300   - else
1301   - listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
1302   - }
1303   - } else {
1304   - List<Object[]> objectLists;
1305   - if (sxtj.equals("3")) {
1306   - // 有加油没里程
1307   - objectLists = repository.checkNbmmYl(rq, gsbm, fgsbm, xlbm, nbbm);
1308   - for (int i = 0; i < objectLists.size(); i++) {
1309   - String clbm = objectLists.get(i)[0].toString();
1310   - double jzl = Double.parseDouble(objectLists.get(i)[1].toString());
1311   - double zlc = Double.parseDouble(objectLists.get(i)[2].toString());
1312   - if (jzl > 0 && zlc <= 0) {
1313   - stringList.add(clbm);
1314   - }
1315   -
1316   - }
1317   -
1318   - } else if (sxtj.equals("4")) {
1319   - // 有里程没加油
1320   - objectLists = repository.checkNbmmYl(rq, gsbm, fgsbm, xlbm, nbbm);
1321   - for (int i = 0; i < objectLists.size(); i++) {
1322   - String clbm = objectLists.get(i)[0].toString();
1323   - double jzl = Double.parseDouble(objectLists.get(i)[1].toString());
1324   - double zlc = Double.parseDouble(objectLists.get(i)[2].toString());
1325   - if (zlc > 0 && jzl <= 0) {
1326   - stringList.add(clbm);
1327   - }
1328   -
1329   - }
1330   - } else {
1331   - objectLists = repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm, nbbm);
1332   - for (int i = 0; i < objectLists.size(); i++) {
1333   - String clbm = objectLists.get(i)[0].toString();
1334   - int cs = Integer.parseInt(objectLists.get(i)[1].toString());
1335   - // 一车一单
1336   - if (sxtj.equals("1")) {
1337   - if (cs == 1) {
1338   - stringList.add(clbm);
1339   - }
1340   - }
1341   - // 一车多单
1342   - if (sxtj.equals("2")) {
1343   - if (cs > 1) {
1344   - stringList.add(clbm);
1345   - }
1346   - }
1347   - }
1348   - }
1349   -
1350   - if (stringList.size() > 0) {
1351   - if (type.equals("1"))
1352   - listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
1353   - else
1354   - listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
1355   - }
1356   - }
1357   - }
1358   - } catch (ParseException e) {
1359   - // TODO Auto-generated catch block
1360   - e.printStackTrace();
1361   - }
1362   - return listYlb;
1363   - }
1364   -
1365   - @Transactional
1366   - @Override
1367   - public Map<String, Object> saveYlbList(Map<String, Object> map) throws Exception {
1368   - // TODO Auto-generated method stub
1369   - Map<String, Object> newMap=new HashMap<String,Object>();
1370   - try{
1371   - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
1372   - String json =StringEscapeUtils.unescapeHtml4(map.get("ylbList").toString());
1373   - JSONArray jsonArray=JSONArray.parseArray(json);
1374   - JSONObject jsonObject;
1375   - // 获取车辆存油信息
1376   - List<Cyl> cylList = cylRepository.obtainCyl("","");
1377   - for (int i = 0; i < jsonArray.size(); i++) {
1378   -// Ylb t=new Ylb();
1379   - jsonObject=jsonArray.getJSONObject(i);
1380   - double czyl = jsonObject.getDoubleValue("czyl");
1381   - double jzl =jsonObject.getDoubleValue("jzl");
1382   - double jzyl =jsonObject.getDoubleValue("jzyl");
1383   - double sh =jsonObject.getDoubleValue("sh");
1384   - String shyy =jsonObject.getString("shyy");
1385   - double ns = jsonObject.getDoubleValue("ns");
1386   - String rylx =jsonObject.getString("rylx");
1387   - int yhlx =jsonObject.getIntValue("yhlx");
1388   - Integer id =jsonObject.getInteger("id");
1389   - String nbbm =jsonObject.getString("nbbm");
1390   - String rq=jsonObject.getString("rq");
1391   - double yh = Arith.sub(Arith.add(czyl, jzl),jzyl);
1392   - if(yh<0){
1393   - yh=0.0;
1394   - }
1395   - repository.ylbUpdate(id, czyl, jzyl, yh, sh, shyy, ns, rylx,yhlx);
1396   - }
1397   -// List<Map<String, Object>> list=(List<Map<String, Object>>) map.get("ylbList");
1398   - SysUser user = SecurityUtils.getCurrentUser();
1399   - Nylog nylog=new Nylog();
1400   - nylog.setCreatedate(new Date());
1401   - nylog.setCzmc("保存全部");
1402   - nylog.setNylx("油");
1403   - nylog.setUserid(user.getUserName());
1404   - nylog.setUsername(user.getName());
1405   - nylog.setCxtj("");
1406   - nylogRepository.save(nylog);
1407   - newMap.put("status", ResponseCode.SUCCESS);
1408   - }catch(Exception e){
1409   - newMap.put("status", ResponseCode.ERROR);
1410   - logger.error("save erro.", e);
1411   - throw e;
1412   - }
1413   - return newMap;
1414   - }
1415   -
1416   - /**
1417   - * 拆分
1418   - */
1419   - @Transactional
1420   - @Override
1421   - public Map<String, Object> sort(Map<String, Object> map) throws Exception{
1422   - // TODO Auto-generated method stub
1423   - Map<String, Object> newMap = new HashMap<String, Object>();
1424   - SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
1425   -
1426   - try {
1427   - List<Cyl> cylList = cylRepository.findAll(new CustomerSpecs<Cyl>(newMap));
1428   - String json =StringEscapeUtils.unescapeHtml4(map.get("ylbList").toString());
1429   - String fgsbm="999";
1430   - if(map.get("fgsbm")!=null){
1431   - fgsbm=map.get("fgsbm").toString();
1432   - }
1433   - JSONArray jsonArray=JSONArray.parseArray(json);
1434   - JSONObject jsonObject;
1435   - for (int x = 0; x < jsonArray.size(); x++) {
1436   - jsonObject=jsonArray.getJSONObject(x);
1437   - Double yl =jsonObject.getDoubleValue("jzyl");
1438   - Double sh =jsonObject.getDoubleValue("sh");
1439   - String shyy =jsonObject.getString("shyy");
1440   - Double ns = jsonObject.getDoubleValue("ns");
1441   - String rylx =jsonObject.getString("rylx");
1442   - Integer id =jsonObject.getInteger("id");
1443   - Ylb ylb = repository.findById(id).get();
1444   - String nbbm_eq = ylb.getNbbm();
1445   - Date rq_eq = ylb.getRq();
1446   - // 得到一天总的加油和里程(根据车,时间)
1447   - List<Object[]> sumList=new ArrayList<Object[]>();
1448   - if(fgsbm.equals(""))
1449   - sumList = repository.sumLcYl(nbbm_eq, rq_eq,"",ylb.getSsgsdm(),fgsbm);
1450   - else
1451   - sumList = repository.sumLcYl(nbbm_eq, rq_eq,"",ylb.getSsgsdm(),ylb.getFgsdm());
1452   -
1453   - // 保存总的加油量
1454   - Double jzl = 0.0;
1455   - // 保存总的里程
1456   - Double zlc = 0.0;
1457   - //保存总的损耗
1458   - Double zsh = 0.0;
1459   - for (int j = 0; j < sumList.size(); j++) {
1460   - jzl = Arith.add(jzl, Double.valueOf(sumList.get(j)[0].toString()));
1461   - zlc = Arith.add(zlc, Double.valueOf(sumList.get(j)[1].toString()));
1462   - zsh = Arith.add(zsh, Double.valueOf(sumList.get(j)[2].toString()));
1463   - }
1464   -// jzl = Arith.sub(jzl, zsh);
1465   - //新的 损耗不等于 旧的损耗 总损耗从新算
1466   - /*if(Arith.sub(ylb.getSh(),sh )!=0){
1467   - zsh =Arith.add(Arith.sub(zsh, ylb.getSh()), sh);
1468   - jzl =Arith.sub(jzl, zsh);
1469   - }else{
1470   - jzl =Arith.sub(jzl, zsh);
1471   - }*/
1472   - map.put("nbbm_eq", nbbm_eq);
1473   - map.put("rq_eq", rq_eq);
1474   - List<Ylb> iterator2=null;
1475   - if(fgsbm.equals(""))
1476   - iterator2=this.listOrderBy(sdf.format(rq_eq),ylb.getSsgsdm(),fgsbm,"",
1477   - ylb.getNbbm(),"jcsx");
1478   - else
1479   - iterator2=this.listOrderBy(sdf.format(rq_eq),ylb.getSsgsdm(),ylb.getFgsdm(),"",
1480   - ylb.getNbbm(),"jcsx");
1481   -
1482   -// repository.obtainYl(sdf.format(rq_eq),ylb.getSsgsdm(),ylb.getFgsdm(),"",
1483   -// ylb.getNbbm(),"jcsx");
1484   - DecimalFormat df = new DecimalFormat("#.00");
1485   - Double zyl = 0.0;
1486   - Double nextJzyl = 0.0;
1487   - // 车的,进,出油量及耗油
1488   - double czyl=0.0;
1489   - for (int i = 0; i < iterator2.size(); i++) {
1490   - Ylb t = iterator2.get(i);
1491   - if (t.getJcsx() == 1) {
1492   - if(t.getId()==id){
1493   - t.setSh(sh);
1494   - t.setShyy(shyy);
1495   - }
1496   - czyl=t.getCzyl();
1497   - Double jcyl = t.getCzyl();
1498   - zyl = Arith.sub(Arith.add(jcyl, jzl), yl);
1499   - Double yh = 0.0;
1500   - if (zlc > 0 && t.getZlc() > 0) {
1501   - yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
1502   - }
1503   - nextJzyl =Arith.sub(Arith.add(t.getJzl(), t.getCzyl()), yh);
1504   -// nextJzyl =Arith.sub(Arith.add(t.getJzl(), t.getCzyl()), Arith.add(yh, t.getSh()));
1505   - if(zlc>0 && t.getZlc() > 0){
1506   - long l=Math.round(nextJzyl);
1507   - double ylxs=l*100/100;
1508   -// nextJzyl = Arith.add(nextJzyl,Arith.sub(nextJzyl,ylxs));
1509   - yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
1510   - t.setYh(yh);
1511   - t.setJzyl(ylxs);
1512   - nextJzyl=ylxs;
1513   - }else{
1514   - t.setYh(yh);
1515   - t.setJzyl(nextJzyl);
1516   - }
1517   - } else {
1518   - if(t.getId()==id){
1519   - t.setSh(sh);
1520   - t.setShyy(shyy);
1521   - }
1522   - t.setCzyl(nextJzyl);
1523   - Double yh =0.0;
1524   - if (t.getZlc() >= 0) {
1525   - yh= Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
1526   - }
1527   -// nextJzyl = Arith.sub(Arith.add(t.getJzl(), nextJzyl), Arith.add(yh, t.getSh()));
1528   - nextJzyl = Arith.sub(Arith.add(t.getJzl(), nextJzyl), yh);
1529   - if(zlc>0 && t.getZlc() >0){
1530   - long l=0l;
1531   - double ylxs=0.0;
1532   - if(i==iterator2.size()-1){
1533   - ylxs=yl;
1534   - }else{
1535   - l=Math.round(nextJzyl);
1536   - ylxs=l*100/100;
1537   - }
1538   - yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
1539   - t.setYh(yh);
1540   - t.setJzyl(ylxs);
1541   - nextJzyl=ylxs;
1542   - }else{
1543   - t.setYh(yh);
1544   - t.setJzyl(nextJzyl);
1545   - }
1546   - }
1547   - if(t.getJzyl()<0){
1548   - t.setJzyl(0.0);
1549   - }
1550   - if(t.getCzyl()<0){
1551   - t.setCzyl(0.0);
1552   - }
1553   - if(t.getYh()<0){
1554   - t.setYh(0.0);
1555   - }
1556   - if(t.getSh()<0){
1557   - t.setSh(0.0);
1558   - }
1559   - repository.save(t);
1560   - }
1561   - newMap.put("status", ResponseCode.SUCCESS);
1562   - }
1563   -
1564   - SysUser user = SecurityUtils.getCurrentUser();
1565   - Nylog nylog=new Nylog();
1566   - nylog.setCreatedate(new Date());
1567   - nylog.setCzmc("拆分");
1568   - nylog.setNylx("油");
1569   - nylog.setUserid(user.getUserName());
1570   - nylog.setUsername(user.getName());
1571   - nylog.setCxtj("");
1572   - nylogRepository.save(nylog);
1573   - } catch (Exception e) {
1574   - newMap.put("status", ResponseCode.ERROR);
1575   - logger.error("save erro.", e);
1576   - throw e;
1577   - }
1578   - return newMap;
1579   - }
1580   -
1581   -
1582   - @Override
1583   - public String checkJsy(Map<String, Object> map) {
1584   - // TODO Auto-generated method stub
1585   - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
1586   - String rq=map.get("date").toString();
1587   - String nbbm=map.get("nbbm").toString();
1588   - String jsy =map.get("jsy").toString();
1589   - String xlbm=map.get("xlbm").toString();
1590   - List<Ylb> list= repository.checkYlb(rq, nbbm, jsy,xlbm,"nbbm");
1591   - String type="1";
1592   - if(list.size()>0){
1593   - type="0";
1594   - }
1595   - return type;
1596   - }
1597   -
1598   - @Override
1599   - public String checkDate(Map<String, Object> map) {
1600   - // TODO Auto-generated method stub
1601   - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
1602   - String rq=map.get("rq").toString();
1603   - String gsbm=map.get("ssgsdm_like").toString();
1604   - String type="1";
1605   - if(gsbm.equals("26")){
1606   - Date date=new Date();
1607   - try {
1608   - long day2=date.getTime();
1609   - long day1=sdf.parse(rq).getTime();
1610   - long days = (day2 - day1) / (24*3600*1000);
1611   - if(days>3){
1612   - type="2";
1613   - }
1614   - } catch (ParseException e) {
1615   - // TODO Auto-generated catch block
1616   - e.printStackTrace();
1617   - }
1618   - }
1619   - return type;
1620   - }
1621   -
1622   -
1623   -
1624   - @Override
1625   - public Map<String, Object> saveYlb(Ylb t) {
1626   - Map<String, Object> map = new HashMap<>();
1627   - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
1628   - String rq=sdf.format(t.getRq());
1629   - String gsdm=t.getSsgsdm();
1630   - String fgsdm=t.getFgsdm();
1631   - String xlbm=t.getXlbm();
1632   - String jhsj=t.getJhsj();
1633   - String jsy=t.getJsy();
1634   - String nbbm=t.getNbbm();
1635   - t.setCreatetime(new Date());
1636   - String[] jhsjStr = jhsj.split(":");
1637   - long fcsjL= Long.parseLong(jhsjStr[0])*60+Long.parseLong(jhsjStr[1]);
1638   - List<Ylb> list=this.listOrderBy(rq, gsdm, fgsdm, xlbm, nbbm, "jhsj");
1639   -// repository.obtainYl(rq, gsdm, fgsdm, xlbm, nbbm, "jhsj");
1640   - int jcsx=1;
1641   - if(list.size()>0){
1642   - for (int i = 0; i < list.size(); i++) {
1643   - Ylb y=list.get(i);
1644   - String[] fcsjStr = y.getJhsj().split(":");
1645   - long fcsj=Long.parseLong(fcsjStr[0])*60+Long.parseLong(fcsjStr[1]);
1646   - if(fcsjL>fcsj){
1647   - jcsx=jcsx+y.getJcsx();
1648   - }else{
1649   - y.setJcsx(y.getJcsx()+1);
1650   - repository.save(y);
1651   - }
1652   - }
1653   -
1654   - }
1655   - t.setJcsx(jcsx);
1656   - repository.save(t);
1657   -
1658   - SysUser user = SecurityUtils.getCurrentUser();
1659   - Nylog nylog=new Nylog();
1660   - nylog.setCreatedate(new Date());
1661   - nylog.setCzmc("手动添加");
1662   - nylog.setNylx("油");
1663   - nylog.setUserid(user.getUserName());
1664   - nylog.setUsername(user.getName());
1665   - nylog.setCxtj("");
1666   - nylogRepository.save(nylog);
1667   - map.put("status", ResponseCode.SUCCESS);
1668   - map.put("t", t);
1669   - return map;
1670   - }
1671   - @Transactional
1672   - @Override
1673   - public Map<String, Object> deleteIds(Map<String, Object> map) throws Exception{
1674   - // TODO Auto-generated method stub
1675   - Map<String, Object> maps = new HashMap<>();
1676   - try{
1677   - String json =StringEscapeUtils.unescapeHtml4(map.get("ids").toString());
1678   - JSONArray jsonArray=JSONArray.parseArray(json);
1679   - JSONObject jsonObject;
1680   - for (int x = 0; x < jsonArray.size(); x++) {
1681   - jsonObject=jsonArray.getJSONObject(x);
1682   - Integer id =jsonObject.getInteger("id");
1683   - repository.deleteById(id);
1684   - }
1685   -
1686   - SysUser user = SecurityUtils.getCurrentUser();
1687   - Nylog nylog=new Nylog();
1688   - nylog.setCreatedate(new Date());
1689   - nylog.setCzmc("删除");
1690   - nylog.setNylx("油");
1691   - nylog.setUserid(user.getUserName());
1692   - nylog.setUsername(user.getName());
1693   - nylog.setCxtj("");
1694   - nylogRepository.save(nylog);
1695   - maps.put("status", ResponseCode.SUCCESS);
1696   - } catch (Exception e) {
1697   - maps.put("status", ResponseCode.ERROR);
1698   - logger.error("save erro.", e);
1699   - throw e;
1700   - }
1701   - return maps;
1702   - }
1703   -
1704   - public List<Ylb> listOrderBy(String rq,String gsdm,
1705   - String fgsdm,String xlbm,String nbbm,
1706   - String px) {
1707   - // TODO Auto-generated method stub
1708   - String sql="SELECT * FROM bsth_c_ylb "
1709   - + " where rq ='"+rq+"' and ssgsdm like '%"+gsdm+"%' "
1710   - + " and fgsdm like '%"+fgsdm+"%'";
1711   - if(xlbm.equals("")){
1712   - sql+= " and xlbm like '%"+xlbm+"%' ";
1713   - }else{
1714   - sql+= " and xlbm = '"+xlbm+"' ";
1715   - }
1716   -
1717   - sql += "and nbbm like '%"+nbbm+"%' order by "+px+" asc ";
1718   -
1719   - List<Ylb> list = jdbcTemplate.query(sql, new RowMapper<Ylb>() {
1720   - @Override
1721   - public Ylb mapRow(ResultSet arg0, int arg1) throws SQLException {
1722   - Ylb y = new Ylb();
1723   - y.setId(arg0.getInt("id"));
1724   - return y;
1725   - }
1726   - });
1727   - List<Ylb> lists=new ArrayList<Ylb>();
1728   - List<Ylb> ylbLists=repository.obtainYl(rq,gsdm,fgsdm,xlbm,nbbm,"jcsx");
1729   - for (int i = 0; i < list.size(); i++) {
1730   - Ylb t=list.get(i);
1731   - for (int j = 0; j < ylbLists.size(); j++) {
1732   - Ylb t2=ylbLists.get(j);
1733   - if(t.getId().intValue()==t2.getId().intValue()){
1734   - lists.add(t2);
1735   - break;
1736   - }
1737   - }
1738   - }
1739   -
1740   - return lists;
1741   - }
1742   -
1743   - @Override
1744   - public Map<String, Object> updateHistory(Map<String, Object> map) throws Exception {
1745   - // TODO Auto-generated method stub
1746   - Map<String, Object> newMap = new HashMap<String, Object>();
1747   -
1748   - List<Cars> carsList = carsRepository.findCars();
1749   - Map<String, Boolean> carsMap = new HashMap<String, Boolean>();
1750   - for (int i = 0; i < carsList.size(); i++) {
1751   - Cars c = carsList.get(i);
1752   - carsMap.put(c.getInsideCode(), c.getSfdc());
1753   - }
1754   - try{
1755   - String date = map.get("date").toString();
1756   - String line = map.get("line").toString();
1757   - List<Line> listLine=lineRepository.findLineByCode(line);
1758   - String gsdm ="";
1759   - String fgsdm ="";
1760   - if(listLine.size()>0){
1761   - Line l=listLine.get(0);
1762   - gsdm=l.getCompany();
1763   - fgsdm=l.getBrancheCompany();
1764   - }
1765   -
1766   - String nbbmstr="";
1767   - List<Map<String, Object>> listpbYc=new ArrayList<Map<String, Object>>();//油车数据
1768   - List<Map<String, Object>> listpbDc=new ArrayList<Map<String, Object>>();//电车数据
1769   - List<Map<String,Object>> listpb=scheduleRealInfoService.yesterdayDataList("", date,gsdm, fgsdm, "", "");
1770   - for (int i = 0; i < listpb.size(); i++) {
1771   - if(listpb.get(i).get("xlBm").toString().equals(line)){
1772   - nbbmstr +=listpb.get(i).get("clZbh").toString();
1773   - }
1774   - }
1775   - for (int i = 0; i < listpb.size(); i++) {
1776   - boolean sfdc=true;
1777   - Map<String, Object> m = listpb.get(i);
1778   - if (carsMap.get(m.get("clZbh").toString()) != null) {
1779   - sfdc = carsMap.get(m.get("clZbh").toString());
1780   - } else {
1781   - sfdc = true;
1782   - }
1783   - if(nbbmstr.indexOf(m.get("clZbh").toString())>-1){
1784   - if(sfdc){
1785   - listpbDc.add(m);
1786   - }else{
1787   - listpbYc.add(m);
1788   - }
1789   - }
1790   - }
1791   - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
1792   - //初始存油量
1793   - List<Cyl> clyList = cylRepository.obtainCyl("",gsdm);
1794   - List<Ylxxb> ylxxList = ylxxbRepository.obtainYlxx(date, 0,gsdm);
1795   - //重新统计油车数据开始
1796   - List<Ylb> ylListBe =repository.listByRqJcsx(date, gsdm, fgsdm, "", "");
1797   - List<Ylb> ylbList=this.listOrderBy(date,gsdm,fgsdm,"","","nbbm");
1798   - List<Ylb> ylbList_upd=new ArrayList<Ylb>();
1799   - List<Ylb> ylbList_del=new ArrayList<Ylb>();
1800   -
1801   - for (int j = 0; j < ylbList.size(); j++) {
1802   - Ylb t=ylbList.get(j);
1803   - boolean fage=true;
1804   - if(StringUtils.isEmpty(t.getLp())){
1805   - fage=false;
1806   - }else{
1807   - for (int i = 0; i < listpbYc.size(); i++) {
1808   - Map<String, Object> m = listpbYc.get(i);
1809   - if(t.getNbbm().equals(m.get("clZbh").toString())
1810   - &&t.getJsy().equals(m.get("jGh").toString())
1811   - &&t.getXlbm().equals(m.get("xlBm").toString())
1812   - &&t.getLp().equals(m.get("lpName").toString())){
1813   - //该条记录不用删除
1814   - fage =false;
1815   - ylbList_upd.add(t);
1816   - }
1817   - }
1818   - }
1819   - if(fage){
1820   - if(t.getXlbm().equals(line)){
1821   - ylbList_del.add(t);
1822   - }
1823   - }
1824   -
1825   - }
1826   - String nbbmStr="";
1827   - List<Ylb> list=new ArrayList<Ylb>();
1828   - /*
1829   - * 第一步 修改车辆里程 和加注量
1830   - */
1831   - Map<String, Object> ylMap=new HashMap<String, Object>();
1832   - for (int x = 0; x < listpbYc.size(); x++) {
1833   - String type = "add";
1834   - Map<String, Object> maps = listpbYc.get(x);
1835   - // 判断驾驶员驾驶的该车辆是否已经存入了(查出的结果集中日期是相同的,根据驾驶员、内部编号、线路编码判断)
1836   - Ylb t = new Ylb();
1837   - for (int k = 0; k < ylbList_upd.size(); k++) {
1838   - Ylb t1 = ylbList_upd.get(k);
1839   - if (t1.getNbbm().equals(maps.get("clZbh").toString())
1840   - && t1.getJsy().equals(maps.get("jGh").toString())
1841   - && t1.getXlbm().equals(maps.get("xlBm").toString())
1842   - && t1.getLp().equals(maps.get("lpName").toString())) {
1843   - t = t1;
1844   - type = "update";
1845   - }
1846   - }
1847   - if(type.equals("add")){
1848   - // 当日的第一个班次,出场油量等于前一天的最后一个班次的进场油量
1849   - if (maps.get("seqNumber").toString().equals("1")) {
1850   - boolean fage = true;
1851   - for (int i = 0; i < ylListBe.size(); i++) {
1852   - Ylb ylb = ylListBe.get(i);
1853   - if (maps.get("clZbh").toString().equals(ylb.getNbbm())) {
1854   - if(ylb.getJzyl()>0){
1855   - t.setCzyl(ylb.getJzyl());
1856   - fage = false;
1857   - break;
1858   - }
1859   - }
1860   - }
1861   - if (fage) {
1862   - for (int y = 0; y < clyList.size(); y++) {
1863   - Cyl cyl = clyList.get(y);
1864   - if (maps.get("clZbh").toString().equals(cyl.getNbbm())) {
1865   - if(cyl!=null){
1866   - if(cyl.getCyl()>=0){
1867   - t.setCzyl(cyl.getCyl());
1868   - fage = false;
1869   - break;
1870   - }else {
1871   - if(cyl.getCxrl()!=null){
1872   - if(cyl.getCxrl()>0){
1873   - t.setCzyl(cyl.getCxrl());
1874   - fage = false;
1875   - break;
1876   - }
1877   - }
1878   - }
1879   - }
1880   - }
1881   - }
1882   - }
1883   - if (fage) {
1884   - t.setCzyl(0.0);
1885   - }
1886   - }
1887   - }
1888   -
1889   - Double jzl = 0.0;
1890   - //一人一车加注量只匹配一次
1891   - if(ylMap.get(maps.get("clZbh").toString()+"_"+ maps.get("jGh").toString())!=null){
1892   - }else{
1893   - boolean fage2=false;
1894   - for (int i = 0; i < ylxxList.size(); i++) {
1895   - Ylxxb ylxxb = ylxxList.get(i);
1896   - if (maps.get("clZbh").toString().equals(ylxxb.getNbbm())
1897   - && maps.get("jGh").toString().equals(ylxxb.getJsy())
1898   - && ylxxb.getJylx()==1) {
1899   - if(ylxxb.getJzl()>0){
1900   - fage2=true;
1901   - }
1902   - }
1903   - }
1904   - //车辆的加注量如果有任工干预,略接口过来 数据
1905   - if(fage2){
1906   - // 把当天手工输入的的YLXXB的加注量设置为当天YLB的加注量(根据车号,驾驶员判断,加油类型为1)
1907   - for (int j = 0; j < ylxxList.size(); j++) {
1908   - Ylxxb ylxxb = ylxxList.get(j);
1909   - if (maps.get("clZbh").toString().equals(ylxxb.getNbbm())
1910   - && maps.get("jGh").toString().equals(ylxxb.getJsy())
1911   - && ylxxb.getJylx()==1) {
1912   - jzl =Arith.add(jzl, ylxxb.getJzl());
1913   - }
1914   - }
1915   - ylMap.put(maps.get("clZbh").toString()+"_"+ maps.get("jGh").toString(),maps.get("xlBm") == null ? "" : maps.get("xlBm").toString());
1916   - }else{
1917   - // 把当天的YLXXB的加注量设置为当天YLB的加注量(根据车号,驾驶员判断)
1918   - for (int j = 0; j < ylxxList.size(); j++) {
1919   - Ylxxb ylxxb = ylxxList.get(j);
1920   - if (maps.get("clZbh").toString().equals(ylxxb.getNbbm())
1921   - && maps.get("jGh").toString().equals(ylxxb.getJsy())) {
1922   - jzl =Arith.add(jzl, ylxxb.getJzl());
1923   - }
1924   - }
1925   - ylMap.put(maps.get("clZbh").toString()+"_"+ maps.get("jGh").toString(),maps.get("xlBm") == null ? "" : maps.get("xlBm").toString());
1926   - }
1927   - }
1928   - t.setJzl(jzl);
1929   - t.setNbbm(maps.get("clZbh").toString());
1930   - t.setJsy(maps.get("jGh") == null ? "" : maps.get("jGh").toString());
1931   - t.setJname(maps.get("jName").toString());
1932   - t.setZlc(maps.get("totalKilometers") == null ? 0.0
1933   - : Double.parseDouble(maps.get("totalKilometers").toString()));
1934   - t.setXlbm(maps.get("xlBm") == null ? "" : maps.get("xlBm").toString());
1935   - t.setJcsx(Integer.parseInt(maps.get("seqNumber").toString()));
1936   - t.setSsgsdm(maps.get("company") == null ? "" : maps.get("company").toString());
1937   - t.setFgsdm(maps.get("bCompany") == null ? "" : maps.get("bCompany").toString());
1938   - t.setJhsj(maps.get("fcsj")==null?"":maps.get("fcsj").toString());
1939   - t.setRq(sdf.parse(date));
1940   - t.setLp(maps.get("lpName")==null?"":maps.get("lpName").toString());
1941   - if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
1942   - if(type.equals("add")){
1943   - if(nbbmStr.indexOf(t.getNbbm())<0){
1944   - nbbmStr +=t.getNbbm()+",";
1945   - }
1946   - t.setCreatetime(new Date());
1947   - }else{
1948   - t.setUpdatetime(new Date());
1949   - }
1950   - }
1951   - try {
1952   - repository.save(t);
1953   - } catch (Exception e) {
1954   - // TODO: handle exception
1955   - if(e.getMessage().indexOf("PK_YLB_UK")>0){
1956   - newMap.put("fage", "存在相同数据,数据已经过滤");
1957   - logger.info("油量存在相同数据,数据已经过滤");
1958   - }
1959   - }
1960   -
1961   - }
1962   - for (int i = 0; i < ylbList_del.size(); i++) {
1963   - Ylb y=ylbList_del.get(i);
1964   - if(nbbmStr.indexOf(y.getNbbm())<0){
1965   - nbbmStr +=y.getNbbm()+",";
1966   - }
1967   - repository.deleteById(y.getId());
1968   - }
1969   -
1970   - //重新计算删除了的或者新增了的车的车的油耗信息(考虑车辆可能跨线路,从分公司赛选计算)
1971   - double czyl=0.0;
1972   - List<Ylb> iterator2=this.listOrderBy(date,gsdm,fgsdm,"","","nbbm,jcsx");
1973   - String[] nbbms=nbbmStr.split(",");
1974   - for (int i = 0; i < nbbms.length; i++) {
1975   - String clzbm=nbbms[i];
1976   - // 得到一天总的加油和里程(根据车,时间)
1977   - List<Object[]> sumList = repository.sumLcYl(clzbm, sdf.parse(date),"",gsdm,fgsdm);
1978   - // 保存总的加油量
1979   - Double jzl = 0.0;
1980   - // 保存总的里程
1981   - Double zlc = 0.0;
1982   - for (int j = 0; j < sumList.size(); j++) {
1983   - jzl = Arith.add(jzl, Double.valueOf(sumList.get(j)[0].toString()));
1984   - zlc = Arith.add(zlc, Double.valueOf(sumList.get(j)[1].toString()));
1985   - }
1986   - // 保留两位小数
1987   - DecimalFormat df = new DecimalFormat("#.00");
1988   - Double zyl = 0.0;
1989   - Double nextJzyl = 0.0;
1990   - for (int j = 0; j < iterator2.size(); j++) {
1991   - Ylb t = iterator2.get(j);
1992   - if(t.getNbbm().equals(clzbm)){
1993   - if (t.getJcsx() == 1) {
1994   - // 进场等于出场的操作 既 最后进场存油量等于第一次的出场存油量
1995   - czyl = t.getCzyl();
1996   - zyl =jzl;
1997   - Double yh=0.0;
1998   - if(zlc>0 ){
1999   - yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
2000   - }
2001   - nextJzyl =Arith.sub( Arith.add(t.getJzl(), t.getCzyl()),yh);
2002   - //把进场油量的小数和整数分别取出
2003   - if(zlc>0 && t.getZlc()>0){
2004   - long l=Math.round(nextJzyl);
2005   - double ylxs=l*100/100;
2006   - yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
2007   - t.setYh(yh);
2008   - t.setJzyl(ylxs);
2009   - nextJzyl=ylxs;
2010   - }else{
2011   - t.setYh(yh);
2012   - t.setJzyl(nextJzyl);
2013   - }
2014   - } else {
2015   - t.setCzyl(nextJzyl);
2016   - Double yh=0.0;
2017   - if(zlc>0){
2018   - yh= Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
2019   - }
2020   - nextJzyl =Arith.sub( Arith.add(t.getJzl(),nextJzyl),yh);
2021   - if(zlc>0 && t.getZlc()>0){
2022   - long l=0l;
2023   - double ylxs=0.0;
2024   - if(j==iterator2.size()-1){
2025   - ylxs=czyl;
2026   - }else{
2027   - if(iterator2.get(j+1).getNbbm().equals(t.getNbbm())){
2028   - l=Math.round(nextJzyl);
2029   - ylxs=l*100/100;
2030   - }else{
2031   - ylxs=czyl;
2032   - }
2033   -
2034   - }
2035   - yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
2036   - t.setYh(yh);
2037   - t.setJzyl(ylxs);
2038   - nextJzyl=ylxs;
2039   - }else{
2040   - t.setYh(yh);
2041   - t.setJzyl(nextJzyl);
2042   - }
2043   - }
2044   - if(t.getJzyl()<0){
2045   - t.setJzyl(0.0);
2046   - }
2047   - if(t.getCzyl()<0){
2048   - t.setCzyl(0.0);
2049   - }
2050   - if(t.getYh()<0){
2051   - t.setYh(0.0);
2052   - }
2053   - if(t.getSh()<0){
2054   - t.setSh(0.0);
2055   - }
2056   - repository.save(t);
2057   - }
2058   - }
2059   - }
2060   -
2061   - //重新统计油车数据结束
2062   -
2063   -
2064   - //重新获取电耗数据开始
2065   - Map<String, List<Dlb>> mapList=dlbService.updeteHistory(listpbDc, date, gsdm, fgsdm, line);
2066   - List<Dlb> delDlb=mapList.get("delList");
2067   - for (int i = 0; i < delDlb.size(); i++) {
2068   - Dlb d=delDlb.get(i);
2069   - dlbRepository.deleteById(d.getId());
2070   - }
2071   - List<Dlb> updDlb=mapList.get("updList");
2072   - for (int i = 0; i < updDlb.size(); i++) {
2073   - Dlb d=updDlb.get(i);
2074   - try {
2075   - dlbRepository.save(d);
2076   - } catch (Exception e) {
2077   - // TODO: handle exception
2078   - if(e.getMessage().indexOf("PK_DLB_UK")>0){
2079   - newMap.put("fage", "存在相同数据,数据已经过滤");
2080   - logger.info("电量存在相同数据,数据已经过滤");
2081   - }
2082   - }
2083   - }
2084   - //重新获取电耗数据结束
2085   -
2086   - SysUser user = SecurityUtils.getCurrentUser();
2087   - Nylog nylog=new Nylog();
2088   - nylog.setCreatedate(new Date());
2089   - nylog.setCzmc("重新统计");
2090   - nylog.setNylx("油");
2091   - nylog.setUserid(user.getUserName());
2092   - nylog.setUsername(user.getName());
2093   - nylog.setCxtj(line+"-"+ date+"-"+gsdm+"-"+fgsdm);
2094   - nylogRepository.save(nylog);
2095   - newMap.put("status", ResponseCode.SUCCESS);
2096   - }catch(Exception e){
2097   - // TODO Auto-generated catch block
2098   - newMap.put("status", ResponseCode.ERROR);
2099   - throw e;
2100   - }
2101   -
2102   -
2103   - return newMap;
2104   - }
2105   -
2106   - public List<Ylb> listByRqJcsx(String rq,String gsdm,String fgsdm,String xlbm,String nbbm) {
2107   - List<Ylb> list=repository.listByRqJcsx(rq, gsdm, fgsdm, xlbm, nbbm);
2108   - Map<String, Object> m=new HashMap<String,Object>();
2109   - List<Ylb> list_=new ArrayList<Ylb>();
2110   - for (int i = 0; i < list.size(); i++) {
2111   - Ylb t=list.get(i);
2112   - if(m.get(t.getNbbm())==null){
2113   - m.put(t.getNbbm(), t.getNbbm());
2114   - list_.add(t);
2115   - }
2116   - }
2117   - return list_;
2118   - }
2119   -
2120   - @Override
2121   - public Map<String, Object> update(Map<String, Object> map) {
2122   - if(map.get("id")!=null){
2123   - if(map.get("id").toString().length()>0){
2124   - Integer id=Integer.parseInt(map.get("id").toString());
2125   - String jsy=map.get("jsy").toString();
2126   - Ylb t=repository.findById(id).get();
2127   - t.setJsy(jsy);
2128   - repository.save(t);
2129   - map.put("status", ResponseCode.SUCCESS);
2130   - }
2131   - }
2132   - return map;
2133   - }
2134   -}
  1 +package com.bsth.service.oil.impl;
  2 +
  3 +import java.sql.ResultSet;
  4 +import java.sql.SQLException;
  5 +import java.text.DecimalFormat;
  6 +import java.text.ParseException;
  7 +import java.text.SimpleDateFormat;
  8 +import java.util.ArrayList;
  9 +import java.util.Calendar;
  10 +import java.util.Date;
  11 +import java.util.HashMap;
  12 +import java.util.Iterator;
  13 +import java.util.List;
  14 +import java.util.Map;
  15 +
  16 +import javax.transaction.Transactional;
  17 +
  18 +import org.apache.commons.lang3.StringEscapeUtils;
  19 +import org.apache.commons.lang3.StringUtils;
  20 +import org.slf4j.Logger;
  21 +import org.slf4j.LoggerFactory;
  22 +import org.springframework.beans.factory.annotation.Autowired;
  23 +import org.springframework.data.domain.Sort;
  24 +import org.springframework.data.domain.Sort.Direction;
  25 +import org.springframework.jdbc.core.JdbcTemplate;
  26 +import org.springframework.jdbc.core.RowMapper;
  27 +import org.springframework.stereotype.Service;
  28 +
  29 +import com.alibaba.fastjson.JSONArray;
  30 +import com.alibaba.fastjson.JSONObject;
  31 +import com.bsth.common.ResponseCode;
  32 +import com.bsth.data.BasicData;
  33 +import com.bsth.entity.Cars;
  34 +import com.bsth.entity.Line;
  35 +import com.bsth.entity.mcy_forms.Daily;
  36 +import com.bsth.entity.oil.Cyl;
  37 +import com.bsth.entity.oil.Dlb;
  38 +import com.bsth.entity.oil.Nylog;
  39 +import com.bsth.entity.oil.Ylb;
  40 +import com.bsth.entity.oil.Ylxxb;
  41 +import com.bsth.entity.search.CustomerSpecs;
  42 +import com.bsth.entity.sys.SysUser;
  43 +import com.bsth.repository.CarsRepository;
  44 +import com.bsth.repository.LineRepository;
  45 +import com.bsth.repository.oil.CylRepository;
  46 +import com.bsth.repository.oil.DlbRepository;
  47 +import com.bsth.repository.oil.NylogRepository;
  48 +import com.bsth.repository.oil.YlbRepository;
  49 +import com.bsth.repository.oil.YlxxbRepository;
  50 +import com.bsth.security.util.SecurityUtils;
  51 +import com.bsth.service.impl.BaseServiceImpl;
  52 +import com.bsth.service.oil.DlbService;
  53 +import com.bsth.service.oil.YlbService;
  54 +import com.bsth.service.realcontrol.ScheduleRealInfoService;
  55 +import com.bsth.util.Arith;
  56 +import com.bsth.util.BatchSaveUtils;
  57 +import com.bsth.util.ReportUtils;
  58 +import com.github.abel533.echarts.code.Y;
  59 +
  60 +import javassist.bytecode.stackmap.BasicBlock.Catch;
  61 +
  62 +@Service
  63 +public class YlbServiceImpl extends BaseServiceImpl<Ylb,Integer> implements YlbService{
  64 + @Autowired
  65 + YlbRepository repository;
  66 + @Autowired
  67 + NylogRepository nylogRepository;
  68 + @Autowired
  69 + YlxxbRepository ylxxbRepository;
  70 +
  71 + @Autowired
  72 + DlbService dlbService;
  73 +
  74 + @Autowired
  75 + DlbRepository dlbRepository;
  76 +
  77 + @Autowired
  78 + CylRepository cylRepository;
  79 +
  80 + @Autowired
  81 + CarsRepository carsRepository;
  82 +
  83 +
  84 + @Autowired
  85 + LineRepository lineRepository;
  86 +
  87 + @Autowired
  88 + ScheduleRealInfoService scheduleRealInfoService;
  89 +
  90 + @Autowired
  91 + JdbcTemplate jdbcTemplate;
  92 +
  93 + Logger logger = LoggerFactory.getLogger(this.getClass());
  94 +
  95 +
  96 +
  97 + /**
  98 + * 获取进存油信息
  99 + * @Transactional 回滚事物
  100 + */
  101 + @Transactional
  102 + @Override
  103 + public String obtainDsq() throws Exception{
  104 + String result = "failure";
  105 + try {
  106 + List<Ylb> addList = new ArrayList<Ylb>();
  107 + String type = "";
  108 + List<Cars> carsList=carsRepository.findCars();
  109 + Map<String, Boolean> carsMap=new HashMap<String, Boolean>();
  110 + for (int i = 0; i < carsList.size(); i++) {
  111 + Cars c=carsList.get(i);
  112 + carsMap.put(c.getInsideCode(), c.getSfdc());
  113 + }
  114 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  115 + Date dNow = new Date(); //当前时间
  116 + Date dBefore = new Date();
  117 + Calendar calendar = Calendar.getInstance(); //得到日历
  118 + calendar.setTime(dNow);//把当前时间赋给日历
  119 + calendar.add(Calendar.DAY_OF_MONTH, -1); //设置为前一天
  120 + dBefore = calendar.getTime(); //得到前一天的时间
  121 + String rq=sdf.format(dBefore);
  122 + //保留两位小数
  123 + DecimalFormat df = new DecimalFormat("#.00");
  124 + // TODO Auto-generated method stub
  125 + Map<String, Object> newMap=new HashMap<String,Object>();
  126 + //当天YLB信息
  127 +// List<Ylb> ylList=repository.obtainYl(rq,"","","","","nbbm");
  128 + List<Ylb> ylList=this.listOrderBy(rq,"","","","","nbbm");
  129 + //当天YLXXB信息
  130 + // List<Ylxxb> ylxxList=ylxxbRepository.obtainYlxx(rq);
  131 + //前一天所有车辆最后进场班次信息
  132 + List<Ylb> ylListBe=this.listByRqJcsx(rq,"","","","");
  133 +// List<Ylb> ylListBe=repository.listMaxRqJcsx(rq, "", "", "", "");
  134 + List<Cyl> clyList=cylRepository.obtainCyl("","");
  135 + //从排班表中计算出行驶的总里程
  136 + List<Map<String,Object>> listpb=scheduleRealInfoService.yesterdayDataList("", rq, "", "", "", "");
  137 +
  138 + for(int x=0;x<listpb.size();x++){
  139 + boolean sfdc=true;
  140 + Map<String, Object> map=listpb.get(x);
  141 + if (carsMap.get(map.get("clZbh").toString())!=null) {
  142 + sfdc= carsMap.get(map.get("clZbh").toString());
  143 + }else{
  144 + sfdc=true;
  145 + }
  146 + if(!sfdc){
  147 + //判断驾驶员驾驶的该车辆是否已经存入了(查出的结果集中日期是相同的,根据驾驶员、内部编号、线路编码判断)
  148 + Ylb t=new Ylb();
  149 + for(int k=0;k<ylList.size();k++){
  150 + Ylb t1=ylList.get(k);
  151 + if(t1.getNbbm().equals(map.get("clZbh").toString())
  152 + &&t1.getJsy().equals(map.get("jGh").toString())
  153 + &&t1.getXlbm().equals(map.get("xlBm").toString())
  154 + &&t1.getLp().equals(map.get("lpName").toString()))
  155 + {
  156 + t=t1;
  157 + type="update";
  158 + }
  159 + }
  160 +
  161 + //当日的第一个班次,出场油量等于前一天的最后一个班次的进场油量
  162 + if(map.get("seqNumber").toString().equals("1")){
  163 + boolean fage=true;
  164 + for (int i = 0; i < ylListBe.size(); i++) {
  165 + Ylb ylb=ylListBe.get(i);
  166 + if(map.get("clZbh").toString().equals(ylb.getNbbm())){
  167 + if(ylb.getJzyl()!=null){
  168 + if(ylb.getJzyl()>=0){
  169 + t.setCzyl(ylb.getJzyl());
  170 + fage=false;
  171 + break;
  172 + }
  173 + }
  174 +
  175 + }
  176 + }
  177 + if(fage){
  178 + for (int y = 0; y < clyList.size(); y++) {
  179 + Cyl cyl=clyList.get(y);
  180 + if(map.get("clZbh").toString().equals(cyl.getNbbm())){
  181 + if(cyl.getCyl()!=null){
  182 + t.setCzyl(cyl.getCyl());
  183 + fage=false;
  184 + break;
  185 + }
  186 + }
  187 + }
  188 + }
  189 + if(fage){
  190 + t.setCzyl(0.0);
  191 + }
  192 + }
  193 + t.setNbbm(map.get("clZbh").toString());
  194 + t.setJsy(map.get("jGh")==null?"":map.get("jGh").toString());
  195 + t.setZlc(map.get("totalKilometers")==null?0.0:Double.parseDouble(map.get("totalKilometers").toString()));
  196 + t.setXlbm(map.get("xlBm")==null?"":map.get("xlBm").toString());
  197 + t.setLinename(map.get("lineName")==null?"":map.get("lineName").toString());
  198 + t.setJcsx(Integer.parseInt(map.get("seqNumber").toString()));
  199 + t.setSsgsdm(map.get("company")==null?"":map.get("company").toString());
  200 + t.setFgsdm(map.get("bCompany")==null?"":map.get("bCompany").toString());
  201 + t.setLp(map.get("lpName")==null?"":map.get("lpName").toString());
  202 + t.setJhsj(map.get("fcsj")==null?"":map.get("fcsj").toString());
  203 + t.setJname(map.get("jName").toString());
  204 + t.setRq(sdf.parse(rq));
  205 + t.setCreatetime(dNow);
  206 + if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
  207 + if(type.equals("update")){
  208 + repository.save(t);
  209 + }else{
  210 + addList.add(t);
  211 + }
  212 + }
  213 + }
  214 +
  215 + }
  216 + if(addList.size()>0){
  217 + try {
  218 + new BatchSaveUtils<Ylb>().saveList2(addList, Ylb.class);
  219 + } catch (Exception e) {
  220 + // TODO: handle exception
  221 + if(e.getMessage().indexOf("PK_YLB_UK")>0){
  222 + newMap.put("fage", "存在相同数据,数据已经过滤");
  223 + logger.info("定时器:存在相同数据,数据已经过滤");
  224 + }
  225 + }
  226 + }
  227 + result = "success";
  228 + }catch (Exception e) {
  229 + // TODO Auto-generated catch block
  230 + throw e;
  231 + }finally{
  232 + logger.info("setDDRB:"+result);
  233 + }
  234 +
  235 + return result;
  236 + }
  237 +
  238 + /**
  239 + * 获取进存油信息
  240 + * @Transactional 回滚事物
  241 + */
  242 + @Transactional
  243 + @Override
  244 + public Map<String, Object> obtain(Map<String, Object> map2) throws Exception{
  245 + Map<String, Object> newMap = new HashMap<String, Object>();
  246 + try {
  247 + Date date=new Date();
  248 + List<Cars> carsList = carsRepository.findCars();
  249 + Map<String, Boolean> carsMap = new HashMap<String, Boolean>();
  250 + for (int i = 0; i < carsList.size(); i++) {
  251 + Cars c = carsList.get(i);
  252 + carsMap.put(c.getInsideCode(), c.getSfdc());
  253 + }
  254 + String rq = map2.get("rq").toString();
  255 + String line = "";
  256 + if (map2.get("xlbm_like") != null) {
  257 + line = map2.get("xlbm_like").toString().trim();
  258 + }
  259 + String gsbm="";
  260 + if(map2.get("ssgsdm_like")!=null){
  261 + gsbm=map2.get("ssgsdm_like").toString();
  262 + }
  263 + String fgsbm="";
  264 + if(map2.get("fgsdm_like")!=null){
  265 + fgsbm=map2.get("fgsdm_like").toString();
  266 + }
  267 + String nbbm="";
  268 + if(map2.get("nbbm_eq")!=null){
  269 + nbbm=map2.get("nbbm_eq").toString();
  270 + }
  271 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  272 + // 保留两位小数
  273 + DecimalFormat df = new DecimalFormat("#.00");
  274 + // TODO Auto-generated method stub
  275 + // 当天YLB信息
  276 + List<Ylb> ylList = this.listOrderBy(rq,gsbm,fgsbm,"",nbbm,"nbbm");
  277 +
  278 + // 当天YLXXB信息
  279 + List<Ylxxb> ylxxList = ylxxbRepository.obtainYlxx(rq, 0,gsbm);
  280 +
  281 + // 前一天所有车辆最后进场班次信息
  282 + List<Ylb> ylListBe = this.listByRqJcsx(rq, gsbm, fgsbm, "", nbbm);
  283 + List<Cyl> clyList = cylRepository.obtainCyl(nbbm,gsbm);
  284 +
  285 + // 从排班表中计算出行驶的总里程
  286 + List<Map<String, Object>> listpb =new ArrayList<Map<String, Object>>();
  287 + List<Map<String, Object>> listpbs=scheduleRealInfoService.yesterdayDataList("", rq, gsbm, fgsbm, "", nbbm);
  288 +
  289 + String sxtj=map2.get("sxtj").toString();
  290 + if(sxtj.equals("0")){
  291 + listpb=listpbs;
  292 + }else if (sxtj.equals("5")){
  293 + List<String> stringList=new ArrayList<String>();
  294 +
  295 + List<Object[]> objectLists = repository.checkNbmmFgs(rq, gsbm);
  296 + for (int i = 0; i < objectLists.size(); i++) {
  297 + String clbm=objectLists.get(i)[0].toString();
  298 + stringList.add(clbm);
  299 + }
  300 +
  301 + for (int i = 0; i < stringList.size(); i++) {
  302 + String strNbbm=stringList.get(i);
  303 + for (int j = 0; j < listpbs.size(); j++) {
  304 + Map<String, Object> map = listpbs.get(j);
  305 + String mapNbbm=map.get("clZbh").toString();
  306 + if(strNbbm.equals(mapNbbm)){
  307 + listpb.add(map);
  308 + }
  309 + }
  310 + }
  311 +
  312 + }else{
  313 + List<Object[]> objectLists=repository.checkNbmmNum(rq, gsbm, fgsbm, "",nbbm);
  314 + List<String> stringList=new ArrayList<String>();
  315 + for (int i = 0; i < objectLists.size(); i++) {
  316 + String clbm=objectLists.get(i)[0].toString();
  317 + int cs=Integer.parseInt(objectLists.get(i)[1].toString());
  318 + //一车一单
  319 + if(sxtj.equals("1")){
  320 + if(cs==1){
  321 + stringList.add(clbm);
  322 + }
  323 + }
  324 + //一车多单
  325 + if(sxtj.equals("2")){
  326 + if(cs>1){
  327 + stringList.add(clbm);
  328 + }
  329 + }
  330 + }
  331 +
  332 + for (int i = 0; i < stringList.size(); i++) {
  333 + String strNbbm=stringList.get(i);
  334 + for (int j = 0; j < listpbs.size(); j++) {
  335 + Map<String, Object> map = listpbs.get(j);
  336 + String mapNbbm=map.get("clZbh").toString();
  337 + if(strNbbm.equals(mapNbbm)){
  338 + listpb.add(map);
  339 + }
  340 + }
  341 + }
  342 + }
  343 +
  344 + List<Ylb> addList = new ArrayList<Ylb>();
  345 + List<Ylb> updateList = new ArrayList<Ylb>();
  346 + Map<String, Object> ylMap=new HashMap<String, Object>();
  347 +
  348 + Map<String, Object> cMap=new HashMap<String, Object>();
  349 + for (int x = 0; x < listpb.size(); x++) {
  350 + String type = "add";
  351 + boolean sfdc = true;
  352 + Map<String, Object> map = listpb.get(x);
  353 + if (carsMap.get(map.get("clZbh").toString()) != null) {
  354 + sfdc = carsMap.get(map.get("clZbh").toString());
  355 + } else {
  356 + sfdc = true;
  357 + }
  358 + if (!sfdc) {
  359 + // 判断驾驶员驾驶的该车辆是否已经存入了(查出的结果集中日期是相同的,根据驾驶员、内部编号、线路编码判断)
  360 + Ylb t = new Ylb();
  361 + for (int k = 0; k < ylList.size(); k++) {
  362 + Ylb t1 = ylList.get(k);
  363 + if (t1.getNbbm().equals(map.get("clZbh").toString())
  364 + && t1.getJsy().equals(map.get("jGh").toString())
  365 + && t1.getXlbm().equals(map.get("xlBm").toString()
  366 + )) {
  367 + if(t1.getLp()==null){
  368 + //同人同车同线路不同路牌的过滤 (考虑到历史数据)
  369 + if (cMap.get(map.get("clZbh").toString()+map.get("jGh").toString()+map.get("xlBm").toString())==null) {
  370 + t = t1;
  371 + type = "update";
  372 + cMap.put(map.get("clZbh").toString()+map.get("jGh").toString()+map.get("xlBm").toString(),
  373 + map.get("clZbh").toString());
  374 + }
  375 + }else{
  376 + if(t1.getLp().equals(map.get("lpName").toString())){
  377 + t = t1;
  378 + type = "update";
  379 + }
  380 +
  381 + }
  382 + }
  383 + }
  384 + // 当日的第一个班次,出场油量等于前一天的最后一个班次的进场油量
  385 + if (map.get("seqNumber").toString().equals("1")) {
  386 + boolean fage = true;
  387 + if(line.equals("")){
  388 + for (int i = 0; i < ylListBe.size(); i++) {
  389 + Ylb ylb = ylListBe.get(i);
  390 + if (map.get("clZbh").toString().equals(ylb.getNbbm())) {
  391 + if(ylb.getJzyl()>=0){
  392 + t.setCzyl(ylb.getJzyl());
  393 + fage = false;
  394 + break;
  395 + }
  396 +
  397 + }
  398 + }
  399 + if (fage) {
  400 + for (int y = 0; y < clyList.size(); y++) {
  401 + Cyl cyl = clyList.get(y);
  402 + if (map.get("clZbh").toString().equals(cyl.getNbbm())) {
  403 + if(cyl!=null){
  404 + if(cyl.getCyl()>=0){
  405 + t.setCzyl(cyl.getCyl());
  406 + fage = false;
  407 + break;
  408 + }else {
  409 + if(cyl.getCxrl()!=null){
  410 + if(cyl.getCxrl()>0){
  411 + t.setCzyl(cyl.getCxrl());
  412 + fage = false;
  413 + break;
  414 + }
  415 + }
  416 + }
  417 + }
  418 + }
  419 + }
  420 + }
  421 + if (fage) {
  422 + t.setCzyl(0.0);
  423 + }
  424 + }else{
  425 + if (line.equals(map.get("xlBm").toString())) {
  426 + for (int i = 0; i < ylListBe.size(); i++) {
  427 + Ylb ylb = ylListBe.get(i);
  428 + if (map.get("clZbh").toString().equals(ylb.getNbbm())) {
  429 + if(ylb.getJzyl()>=0){
  430 + t.setCzyl(ylb.getJzyl());
  431 + fage = false;
  432 + break;
  433 + }
  434 +
  435 + }
  436 + }
  437 + if (fage) {
  438 + for (int y = 0; y < clyList.size(); y++) {
  439 + Cyl cyl = clyList.get(y);
  440 + if (map.get("clZbh").toString().equals(cyl.getNbbm())) {
  441 + if(cyl!=null){
  442 + if(cyl.getCyl()>=0){
  443 + t.setCzyl(cyl.getCyl());
  444 + fage = false;
  445 + break;
  446 + }else {
  447 + if(cyl.getCxrl()!=null){
  448 + if(cyl.getCxrl()>0){
  449 + t.setCzyl(cyl.getCxrl());
  450 + fage = false;
  451 + break;
  452 + }
  453 + }
  454 + }
  455 + }
  456 + }
  457 + }
  458 + }
  459 + if (fage) {
  460 + t.setCzyl(0.0);
  461 + }
  462 + }
  463 + }
  464 +
  465 + }
  466 +
  467 + Double jzl = 0.0;
  468 + //一人一车加注量只匹配一次
  469 + if(ylMap.get(map.get("clZbh").toString()+"_"+ map.get("jGh").toString())==null){
  470 +
  471 + boolean fage2=false;
  472 + for (int i = 0; i < ylxxList.size(); i++) {
  473 + Ylxxb ylxxb = ylxxList.get(i);
  474 + if (map.get("clZbh").toString().equals(ylxxb.getNbbm())
  475 + && map.get("jGh").toString().equals(ylxxb.getJsy())
  476 + && ylxxb.getJylx()==1) {
  477 + if(ylxxb.getJzl()>0){
  478 + fage2=true;
  479 + }
  480 +
  481 + }
  482 + }
  483 + //车辆的加注量如果有任工干预,略接口过来 数据
  484 + if(fage2){
  485 + // 把当天手工输入的的YLXXB的加注量设置为当天YLB的加注量(根据车号,驾驶员判断,加油类型为1)
  486 + for (int j = 0; j < ylxxList.size(); j++) {
  487 + Ylxxb ylxxb = ylxxList.get(j);
  488 + if (map.get("clZbh").toString().equals(ylxxb.getNbbm())
  489 + && map.get("jGh").toString().equals(ylxxb.getJsy())
  490 + && ylxxb.getJylx()==1) {
  491 + jzl =Arith.add(jzl, ylxxb.getJzl());
  492 + }
  493 + }
  494 + ylMap.put(map.get("clZbh").toString()+"_"+ map.get("jGh").toString(),map.get("xlBm") == null ? "" : map.get("xlBm").toString());
  495 + }else{
  496 + // 把当天的YLXXB的加注量设置为当天YLB的加注量(根据车号,驾驶员判断)
  497 + for (int j = 0; j < ylxxList.size(); j++) {
  498 + Ylxxb ylxxb = ylxxList.get(j);
  499 + if (map.get("clZbh").toString().equals(ylxxb.getNbbm())
  500 + && map.get("jGh").toString().equals(ylxxb.getJsy())) {
  501 + jzl =Arith.add(jzl, ylxxb.getJzl());
  502 + }
  503 + }
  504 + ylMap.put(map.get("clZbh").toString()+"_"+ map.get("jGh").toString(),map.get("xlBm") == null ? "" : map.get("xlBm").toString());
  505 + }
  506 +
  507 + }
  508 + t.setJzl(jzl);
  509 + t.setNbbm(map.get("clZbh").toString());
  510 + t.setJsy(map.get("jGh") == null ? "" : map.get("jGh").toString());
  511 + t.setZlc(map.get("totalKilometers") == null ? 0.0
  512 + : Double.parseDouble(map.get("totalKilometers").toString()));
  513 + t.setXlbm(map.get("xlBm") == null ? "" : map.get("xlBm").toString());
  514 + t.setLinename(map.get("lineName")==null?"":map.get("lineName").toString());
  515 + t.setJcsx(Integer.parseInt(map.get("seqNumber").toString()));
  516 + t.setSsgsdm(map.get("company") == null ? "" : map.get("company").toString());
  517 + t.setFgsdm(map.get("bCompany") == null ? "" : map.get("bCompany").toString());
  518 + t.setJhsj(map.get("fcsj")==null?"":map.get("fcsj").toString());
  519 + t.setRq(sdf.parse(rq));
  520 + t.setLp(map.get("lpName")==null?"":map.get("lpName").toString());
  521 + t.setJname(map.get("jName").toString());
  522 + if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
  523 + if(type.equals("add")){
  524 + t.setCreatetime(date);
  525 + addList.add(t);
  526 + }else{
  527 + t.setUpdatetime(date);
  528 + updateList.add(t);
  529 + }
  530 + }
  531 +// repository.save(t);
  532 + newMap.put("status", ResponseCode.SUCCESS);
  533 +
  534 + }
  535 + }
  536 + if(addList.size()>0){
  537 + try {
  538 + new BatchSaveUtils<Ylb>().saveList2(addList, Ylb.class);
  539 + } catch (Exception e) {
  540 + // TODO: handle exception
  541 + if(e.getMessage().indexOf("PK_YLB_UK")>0){
  542 + newMap.put("fage", "存在相同数据,数据已经过滤");
  543 + logger.info("获取:存在相同数据,数据已经过滤");
  544 + }
  545 + }
  546 +
  547 + }
  548 + if(updateList.size()>0){
  549 + for (int i = 0; i < updateList.size(); i++) {
  550 + repository.save(updateList.get(i));
  551 + }
  552 + }
  553 + SysUser user = SecurityUtils.getCurrentUser();
  554 + Nylog nylog=new Nylog();
  555 + nylog.setCreatedate(new Date());
  556 + nylog.setCzmc("获取加存油");
  557 + nylog.setNylx("油");
  558 + nylog.setUserid(user.getUserName());
  559 + nylog.setUsername(user.getName());
  560 + nylog.setCxtj(rq+"-"+gsbm+"-"+fgsbm+"-"+line+"-"+nbbm+"-"+sxtj);
  561 + nylogRepository.save(nylog);
  562 + newMap.put("status", ResponseCode.SUCCESS);
  563 + } catch (Exception e) {
  564 + // TODO Auto-generated catch block
  565 + newMap.put("status", ResponseCode.ERROR);
  566 + throw e;
  567 + }
  568 +
  569 + return newMap;
  570 + }
  571 +
  572 +
  573 + /**
  574 + * 进场等于出场
  575 + */
  576 + @Transactional
  577 + @Override
  578 + public Map<String, Object> outAndIn(Map<String, Object> map) throws Exception{
  579 + // TODO Auto-generated method stub
  580 + String xlbm="";
  581 + if(map.get("xlbm_like")!=null){
  582 + xlbm= map.get("xlbm_like").toString().trim();
  583 + }
  584 + String gsbm="";
  585 + if(map.get("ssgsdm_like")!=null){
  586 + gsbm=map.get("ssgsdm_like").toString();
  587 + }
  588 + String fgsbm="";
  589 + if(map.get("fgsdm_like")!=null){
  590 + fgsbm=map.get("fgsdm_like").toString();
  591 + }
  592 + String rq = map.get("rq").toString();
  593 + String nbbm="";
  594 + if(map.get("nbbm_eq")!=null){
  595 + nbbm=map.get("nbbm_eq").toString();
  596 + }
  597 +
  598 + Map<String, Object> newMap=new HashMap<String,Object>();
  599 + Map<String, Object> map2=new HashMap<String,Object>();
  600 + try {
  601 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  602 +
  603 + map.put("rq_eq", sdf.parse(rq));
  604 +// List<Cyl> clyList = cylRepository.obtainCyl();
  605 + // 获取车辆存油信息
  606 + List<Cyl> cylList = cylRepository.obtainCyl(nbbm,gsbm);
  607 + // 指定日期YLB信息
  608 + List<Ylb> ylbList =new ArrayList<Ylb>();
  609 + List<Ylb> ylbLists =new ArrayList<Ylb>();
  610 + List<Ylb> iterator2=new ArrayList<Ylb>();
  611 + ylbLists=this.listOrderBy(rq,gsbm,fgsbm,xlbm,nbbm,"jcsx");
  612 + iterator2=this.listOrderBy(rq,gsbm,fgsbm,xlbm,nbbm,"nbbm,jcsx");
  613 + // 从排班表中计算出行驶的总里程
  614 +
  615 + String sxtj=map.get("sxtj").toString();
  616 + if(sxtj.equals("0")){
  617 + ylbList=ylbLists;
  618 + }else{
  619 + List<Object[]> objectLists=repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm,nbbm);
  620 + List<String> stringList=new ArrayList<String>();
  621 + for (int i = 0; i < objectLists.size(); i++) {
  622 + String clbm=objectLists.get(i)[0].toString();
  623 + int cs=Integer.parseInt(objectLists.get(i)[1].toString());
  624 + //一车一单
  625 + if(sxtj.equals("1")){
  626 + if(cs==1){
  627 + stringList.add(clbm);
  628 + }
  629 + }
  630 + //一车多单
  631 + if(sxtj.equals("2")){
  632 + if(cs>1){
  633 + stringList.add(clbm);
  634 + }
  635 + }
  636 + }
  637 +
  638 + for (int i = 0; i < stringList.size(); i++) {
  639 + String strNbbm=stringList.get(i);
  640 + for (int j = 0; j < ylbLists.size(); j++) {
  641 + Ylb y = ylbLists.get(j);
  642 + String mapNbbm=y.getNbbm();
  643 + if(strNbbm.equals(mapNbbm)){
  644 + ylbList.add(y);
  645 + }
  646 + }
  647 + }
  648 + }
  649 +
  650 + for (int i=0;i<ylbList.size();i++) {
  651 + Ylb ylb = ylbList.get(i);
  652 + // 判断是否已经计算过
  653 + if (newMap.get("nbbm" + ylb.getNbbm()) == null) {
  654 + String nbbm_eq = ylb.getNbbm();
  655 + Date rq_eq = ylb.getRq();
  656 + // 得到一天总的加油和里程(根据车,时间)
  657 + List<Object[]> sumList = repository.sumLcYl(nbbm_eq, rq_eq,"",gsbm,fgsbm);
  658 + // 保存总的加油量
  659 + Double jzl = 0.0;
  660 + // 保存总的里程
  661 + Double zlc = 0.0;
  662 + //保存总的损耗
  663 + Double zsh = 0.0;
  664 + for (int j = 0; j < sumList.size(); j++) {
  665 + jzl = Arith.add(jzl, Double.valueOf(sumList.get(j)[0].toString()));
  666 + zlc = Arith.add(zlc, Double.valueOf(sumList.get(j)[1].toString()));
  667 + zsh = Arith.add(zsh, Double.valueOf(sumList.get(j)[2].toString()));
  668 + }
  669 +// jzl = Arith.sub(jzl, zsh);
  670 + // 保留两位小数
  671 + DecimalFormat df = new DecimalFormat("#.00");
  672 + Double zyl = 0.0;
  673 + Double nextJzyl = 0.0;
  674 + // 保存已经计算过的车辆,相同车辆编号的车不在计算
  675 + newMap.put("nbbm" + ylb.getNbbm(), ylb.getNbbm());
  676 +
  677 + // 查询指定车辆,设置进、存、耗油量
  678 + map.remove("nbbm_eq");
  679 + map.put("nbbm_eq", ylb.getNbbm());
  680 + map.put("xlbm_like", ylb.getXlbm());
  681 +// Iterator<Ylb> iterator2 = repository
  682 +// .findAll(new CustomerSpecs<Ylb>(map), new Sort(Direction.ASC, "jcsx")).iterator();
  683 + double czyl=0.0;
  684 + for (int j = 0; j < iterator2.size(); j++) {
  685 + Ylb t = iterator2.get(j);
  686 + if(t.getNbbm().equals(ylb.getNbbm())){
  687 + if (t.getJcsx() == 1) {
  688 + // 进场等于出场的操作 既 最后进场存油量等于第一次的出场存油量
  689 +// Double yl = t.getCzyl();
  690 +// Double jcyl = t.getCzyl();
  691 + czyl = t.getCzyl();
  692 + zyl =jzl;
  693 + Double yh=0.0;
  694 + if(zlc>0 ){
  695 + yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
  696 + }
  697 + nextJzyl =Arith.sub( Arith.add(t.getJzl(), t.getCzyl()),yh);
  698 +// nextJzyl =Arith.sub( Arith.add(Arith.sub(t.getJzl(),t.getSh()), t.getCzyl()),yh);
  699 + //把进场油量的小数和整数分别取出
  700 +// int ylxs=(int) nextJzyl; 10.6--11 10.3--10
  701 + if(zlc>0 && t.getZlc()>0){
  702 + long l=Math.round(nextJzyl);
  703 + double ylxs=l*100/100;
  704 +// nextJzyl = Arith.add(nextJzyl,Arith.sub(nextJzyl,ylxs));
  705 + yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
  706 + t.setYh(yh);
  707 + t.setJzyl(ylxs);
  708 + nextJzyl=ylxs;
  709 + }else{
  710 + t.setYh(yh);
  711 + t.setJzyl(nextJzyl);
  712 + }
  713 + } else {
  714 + t.setCzyl(nextJzyl);
  715 + Double yh=0.0;
  716 + if(zlc>0){
  717 + yh= Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
  718 + }
  719 + nextJzyl =Arith.sub( Arith.add(t.getJzl(),nextJzyl),yh);
  720 +// nextJzyl =Arith.sub( Arith.add(Arith.sub(t.getJzl(),t.getSh()),nextJzyl),yh);
  721 + if(zlc>0 && t.getZlc()>0){
  722 + long l=0l;
  723 + double ylxs=0.0;
  724 + if(j==iterator2.size()-1){
  725 + ylxs=czyl;
  726 + }else{
  727 + if(iterator2.get(j+1).getNbbm().equals(t.getNbbm())){
  728 + l=Math.round(nextJzyl);
  729 + ylxs=l*100/100;
  730 + }else{
  731 + ylxs=czyl;
  732 + }
  733 +
  734 + }
  735 + yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
  736 +// nextJzyl = Arith.add(nextJzyl,Arith.sub(nextJzyl,ylxs));
  737 +
  738 + t.setYh(yh);
  739 + t.setJzyl(ylxs);
  740 + nextJzyl=ylxs;
  741 + }else{
  742 + t.setYh(yh);
  743 + t.setJzyl(nextJzyl);
  744 + }
  745 + }
  746 + if(t.getJzyl()<0){
  747 + t.setJzyl(0.0);
  748 + }
  749 + if(t.getCzyl()<0){
  750 + t.setCzyl(0.0);
  751 + }
  752 + if(t.getYh()<0){
  753 + t.setYh(0.0);
  754 + }
  755 + if(t.getSh()<0){
  756 + t.setSh(0.0);
  757 + }
  758 + repository.save(t);
  759 + }
  760 + map2.put("status", ResponseCode.SUCCESS);
  761 + }
  762 + }
  763 + }
  764 +
  765 + SysUser user = SecurityUtils.getCurrentUser();
  766 + Nylog nylog=new Nylog();
  767 + nylog.setCreatedate(new Date());
  768 + nylog.setCzmc("进场等于出场");
  769 + nylog.setNylx("油");
  770 + nylog.setUserid(user.getUserName());
  771 + nylog.setUsername(user.getName());
  772 + nylog.setCxtj(rq+"-"+gsbm+"-"+fgsbm+"-"+xlbm+"-"+nbbm+"-"+sxtj);
  773 +
  774 + nylogRepository.save(nylog);
  775 + } catch (Exception e) {
  776 + map2.put("status", ResponseCode.ERROR);
  777 + logger.error("save erro.", e);
  778 + throw e;
  779 + }
  780 + return map2;
  781 + }
  782 +
  783 +
  784 + /**
  785 + * 核对,有加注没里程
  786 + * @param map
  787 + * @return
  788 + */
  789 + @Transactional
  790 + @Override
  791 + public Map<String, Object> checkYl(Map<String, Object> map) throws Exception{
  792 + Map<String, Object> newMap=new HashMap<String,Object>();
  793 +// String xlbm="";
  794 +// if(map.get("xlbm_like")!=null){
  795 +// xlbm=map.get("xlbm_like").toString();
  796 +// }
  797 + // TODO Auto-generated method stub
  798 +
  799 + List<Cars> carsList = carsRepository.findCars();
  800 + Map<String, String> carsMap = new HashMap<String, String>();
  801 + for (int i = 0; i < carsList.size(); i++) {
  802 + Cars c = carsList.get(i);
  803 + carsMap.put(c.getInsideCode(), c.getBrancheCompanyCode()==null?"":c.getBrancheCompanyCode());
  804 + }
  805 +
  806 + try{
  807 + //获取车辆存油信息
  808 +
  809 + String rq=map.get("rq").toString();
  810 + String xlbm="";
  811 + if(map.get("xlbm_like")!=null){
  812 + xlbm= map.get("xlbm_like").toString().trim();
  813 + }
  814 + String gsbm="";
  815 + if(map.get("ssgsdm_like")!=null){
  816 + gsbm=map.get("ssgsdm_like").toString();
  817 + }
  818 + String fgsbm="";
  819 + if(map.get("fgsdm_like")!=null){
  820 + fgsbm=map.get("fgsdm_like").toString();
  821 + }
  822 + String nbbm="";
  823 + if(map.get("nbbm_eq")!=null){
  824 + nbbm=map.get("nbbm_eq").toString();
  825 + }
  826 +// List<Ylb> ylListBe=repository.obtainYlbefore(rq, gsbm, "", xlbm, nbbm);
  827 + List<Ylb> ylListBe=this.listByRqJcsx(rq, gsbm, fgsbm, "", nbbm);
  828 + List<Ylb> ylbList=this.listOrderBy(rq,gsbm,fgsbm,xlbm,nbbm,"nbbm");
  829 +// repository.obtainYl(rq,gsbm,fgsbm,xlbm,nbbm,"nbbm");
  830 +// List<Ylxxb> ylxxbList=ylxxbRepository.obtainYlxx(rq,0,gsbm);
  831 + String sql="select * from bsth_c_ylxxb where yyrq='"+rq+"' "
  832 + + " and gsdm ='"+gsbm+"' and nylx ='0' and nbbm "
  833 + + " not in ( select nbbm from bsth_c_ylb "
  834 + + " where rq='"+rq+"' "
  835 + + " and ssgsdm='"+gsbm+"' and fgsdm ='"+fgsbm+"')"
  836 + + " and nbbm in (select inside_code from "
  837 + + " bsth_c_cars where business_code ='"+gsbm+"' "
  838 + + " and branche_company_code='"+fgsbm+"')";
  839 +
  840 + List<Ylxxb> ylxxbList=jdbcTemplate.query(sql,
  841 + new RowMapper<Ylxxb>(){
  842 + @Override
  843 + public Ylxxb mapRow(ResultSet rs, int rowNum) throws SQLException {
  844 + Ylxxb s = new Ylxxb();
  845 + s.setId(rs.getInt("id"));
  846 + s.setYyrq(rs.getDate("yyrq"));
  847 + s.setNbbm(rs.getString("nbbm"));
  848 + s.setGsdm(rs.getString("gsdm"));
  849 + s.setFgsdm(rs.getString("fgsdm"));
  850 + s.setJsy(rs.getString("jsy"));
  851 + s.setJzl(rs.getDouble("jzl"));
  852 + s.setStationid(rs.getString("stationid"));
  853 + s.setNylx(rs.getInt("nylx"));
  854 + s.setJyggh(rs.getString("jyggh"));
  855 + s.setYj(rs.getDouble("yj"));
  856 +// s.setLdgh(rs.getString("ldgh"));
  857 + s.setBz(rs.getString("bz"));
  858 + return s;
  859 + }
  860 + });
  861 + Map<String, Object> m=new HashMap<String,Object>();
  862 + for (int i = 0; i < ylxxbList.size(); i++) {
  863 + Boolean fage=false;
  864 + Ylxxb y1=ylxxbList.get(i);
  865 + if(m.get(y1.getNbbm())==null){
  866 + Line line=BasicData.nbbm2LineMap.get(y1.getNbbm());
  867 + if(null !=line){
  868 + if(!xlbm.equals("")){
  869 + if(line.getLineCode().equals(xlbm)){
  870 + fage=true;
  871 + }
  872 + }else{
  873 + fage=true;
  874 + }
  875 + }
  876 +
  877 + if(fage){
  878 + Ylb t=new Ylb();
  879 + t.setNbbm(y1.getNbbm());
  880 + t.setRq(y1.getYyrq());
  881 + t.setJsy(y1.getJsy());
  882 + t.setJname(BasicData.allPerson.get(y1.getGsdm()+"-"+y1.getJsy()));
  883 + t.setJzl(y1.getJzl());
  884 + t.setSsgsdm(y1.getGsdm());
  885 + String fgsdm="";
  886 + if(null !=carsMap.get(y1.getNbbm())){
  887 + fgsdm=carsMap.get(y1.getNbbm());
  888 + }
  889 + t.setFgsdm(fgsdm);
  890 + t.setJcsx(1);
  891 + if(null !=line){
  892 + t.setXlbm(line.getLineCode());
  893 + }else{
  894 + t.setXlbm("");
  895 + }
  896 + t.setJcsx(1);
  897 + boolean status=true;
  898 + for (int j = 0; j < ylListBe.size(); j++) {
  899 + Ylb b=ylListBe.get(j);
  900 + if(b.getNbbm().equals(y1.getNbbm())){
  901 + t.setCzyl(b.getJzyl());
  902 + status=false;
  903 + break;
  904 + }
  905 + }
  906 + if(status){
  907 + t.setCzyl(0.0);
  908 + }
  909 + t.setJzyl(Arith.add(t.getJzl(), t.getCzyl()));
  910 + t.setYh(0.0);
  911 + if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
  912 + t.setCreatetime(new Date());
  913 + try {
  914 + repository.save(t);
  915 + m.put(t.getName(), t.getName());
  916 + } catch (Exception e) {
  917 + // TODO: handle exception
  918 + if(e.getMessage().indexOf("PK_YLB_UK")>0){
  919 + newMap.put("fage", "存在相同数据,数据已经过滤");
  920 + logger.info("核对有存油没里程:存在相同数据,数据已经过滤");
  921 + }
  922 + }
  923 + }
  924 + }
  925 + }
  926 + }
  927 +
  928 + SysUser user = SecurityUtils.getCurrentUser();
  929 + Nylog nylog=new Nylog();
  930 + nylog.setCreatedate(new Date());
  931 + nylog.setCzmc("核对加注量");
  932 + nylog.setNylx("油");
  933 + nylog.setUserid(user.getUserName());
  934 + nylog.setUsername(user.getName());
  935 + nylog.setCxtj(rq+"-"+gsbm+"-"+fgsbm+"-"+xlbm+"-"+nbbm+"-");
  936 + nylogRepository.save(nylog);
  937 + newMap.put("status", ResponseCode.SUCCESS);
  938 + }catch(Exception e){
  939 + newMap.put("status", ResponseCode.ERROR);
  940 + logger.error("save erro.", e);
  941 + throw e;
  942 + }
  943 +
  944 + return newMap;
  945 + }
  946 +
  947 +
  948 + @Override
  949 + public List<Map<String, Object>> oilListMonth(Map<String, Object> map) {
  950 + SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"),
  951 + sdfSimple = new SimpleDateFormat("yyyyMMdd");
  952 +
  953 + String type=map.get("type").toString();
  954 + String date=map.get("date").toString().trim();
  955 + String gsdm=map.get("gsdm").toString();
  956 + String fgsdm=map.get("fgsdm").toString();
  957 + String date2=date.substring(0, 8)+"01";
  958 + String lineStr="";
  959 + String line =map.get("line").toString().trim();
  960 + /*if(line !=null && !line.equals("")){
  961 + lineStr =" and xlbm= '"+ line +"'";
  962 + }else{
  963 + lineStr =" and ssgsdm='"+gsdm+"' and fgsdm ='"+fgsdm+"' ";
  964 + }
  965 + String sql="select a.nbbm,a.rq,a.jzyl from (" +
  966 + " select x.nbbm,max(x.rq) as rq,max(x.jcsx) as jcsx from "
  967 + + "(select nbbm,rq,max(jcsx) as jcsx from bsth_c_ylb where rq between '"
  968 + + date2 +"' and '" + date+"' "+lineStr
  969 + + " group by nbbm,rq) x group by x.nbbm ) b"
  970 + + " left join (select nbbm,rq,jzyl,jcsx FROM bsth_c_ylb "
  971 + + " where rq between '"
  972 + + date2 +"' and '" + date+"' "+lineStr
  973 + + ") a "
  974 + + " on a.nbbm =b.nbbm and a.jcsx=b.jcsx and a.rq=b.rq "
  975 + + " where a.nbbm is not null order by a.nbbm";
  976 +
  977 + // TODO Auto-generated method stub
  978 + List<Ylb> list =jdbcTemplate.query(sql,
  979 + new RowMapper<Ylb>(){
  980 + @Override
  981 + public Ylb mapRow(ResultSet rs, int rowNum) throws SQLException {
  982 + Ylb s = new Ylb();
  983 + s.setNbbm(rs.getString("nbbm"));
  984 + s.setRq(rs.getDate("rq"));
  985 + s.setJzyl(rs.getDouble("jzyl"));
  986 + return s;
  987 + }
  988 + }); */
  989 +
  990 + double qtyy=0.0;//其他用油
  991 + double cdyy=0.0;//车队用油
  992 + double byyy=0.0;//保养用油
  993 + double cjxx=0.0;//车间小修
  994 + double cjgb=0.0;//车间高保
  995 + double fyyyhj=0.0;//非营运用油合计
  996 + List<Ylb> listYlb=repository.listByMonthJcsx(date2, date, gsdm, fgsdm, line);
  997 +
  998 + Map<String, Object> ms=new HashMap<String,Object>();
  999 + List<Ylb> list=new ArrayList<Ylb>();
  1000 + for (int i = 0; i < listYlb.size(); i++) {
  1001 + Ylb t=listYlb.get(i);
  1002 + fyyyhj =Arith.add(fyyyhj, t.getSh());
  1003 + if(t.getShyy()==null){
  1004 + qtyy=Arith.add(qtyy, t.getSh());
  1005 + }else{
  1006 + if(t.getShyy().equals("6")){
  1007 + cdyy=Arith.add(cdyy, t.getSh());
  1008 + }else if(t.getShyy().equals("2")){
  1009 + byyy=Arith.add(byyy, t.getSh());
  1010 + }else if(t.getShyy().equals("7")){
  1011 + cjxx=Arith.add(cjxx, t.getSh());
  1012 + }else if(t.getShyy().equals("8")){
  1013 + cjgb=Arith.add(cjgb, t.getSh());
  1014 + }else{
  1015 + qtyy=Arith.add(qtyy, t.getSh());
  1016 + }
  1017 + }
  1018 + if(ms.get(t.getNbbm())==null){
  1019 + ms.put(t.getNbbm(), t.getNbbm());
  1020 + list.add(t);
  1021 + }
  1022 + }
  1023 +
  1024 + List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
  1025 + int size = 0;
  1026 + Map<String, Object> m_ = new HashMap<String, Object>();
  1027 + double ycyhj=0.0;
  1028 + for(Ylb ylb : list){
  1029 + ycyhj=Arith.add(ycyhj, ylb.getJzyl());
  1030 + int x=size%3;
  1031 + if(x==0 && size>0){
  1032 + mapList.add(m_);
  1033 + m_ = new HashMap<String, Object>();
  1034 + }
  1035 + size++;
  1036 + m_.put("xh"+x, size);
  1037 + m_.put("nbbm"+x, ylb.getNbbm()!=null?ylb.getNbbm():"");
  1038 + m_.put("rq"+x, ylb.getRq()!=null?sdfMonth.format(ylb.getRq()):"");
  1039 + m_.put("jzyl"+x, ylb.getJzyl()!=null?ylb.getJzyl():"");
  1040 +
  1041 + }
  1042 + if(m_.get("nbbm0")!=null){
  1043 + if(m_.get("nbbm1")==null){
  1044 + m_.put("xh1", "");
  1045 + m_.put("nbbm1" , "");
  1046 + m_.put("rq1" , "");
  1047 + m_.put("jzyl1" , "");
  1048 + }
  1049 + if(m_.get("nbbm2")==null){
  1050 + m_.put("xh2", "");
  1051 + m_.put("nbbm2" , "");
  1052 + m_.put("rq2" , "");
  1053 + m_.put("jzyl2" , "");
  1054 + }
  1055 + mapList.add(m_);
  1056 + }
  1057 +
  1058 + if(type != null && type.equals("export")){
  1059 + List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
  1060 + Map<String, Object> m = new HashMap<String, Object>();
  1061 + m.put("ycyhj", ycyhj);
  1062 + m.put("qtyy", qtyy);
  1063 + m.put("cdyy", cdyy);
  1064 + m.put("byyy", byyy);
  1065 + m.put("cjxx", cjxx);
  1066 + m.put("cjgb", cjgb);
  1067 + m.put("fyyyhj", fyyyhj);
  1068 + ReportUtils ee = new ReportUtils();
  1069 + try {
  1070 + String lineName = "";
  1071 + if(map.containsKey("lineName"))
  1072 + lineName = map.get("lineName").toString();
  1073 + listI.add(mapList.iterator());
  1074 + String path = this.getClass().getResource("/").getPath()+"static/pages/forms/";
  1075 + ee.excelReplace(listI, new Object[] { m }, path+"mould/oilListMonth.xls",
  1076 + path+"export/" + sdfSimple.format(sdfMonth.parse(date))
  1077 + + "-" + lineName + "-月存油报表.xls");
  1078 + } catch (Exception e) {
  1079 + // TODO: handle exception
  1080 + e.printStackTrace();
  1081 + }
  1082 + }else{
  1083 + m_=new HashMap<String,Object>();
  1084 + m_.put("xh0", "99");
  1085 + m_.put("nbbm0", "存油合计:"+ycyhj +" 非营运用油: 其他用油:"+qtyy +",车队:"+cdyy+",保养用油:"+byyy
  1086 + +",车间(小修):"+cjxx+",车间(高保):"+cjgb+",非营运用油合计:"+fyyyhj);
  1087 + mapList.add(m_);
  1088 + }
  1089 +
  1090 + return mapList;
  1091 + }
  1092 +
  1093 + @Override
  1094 + public StringBuffer checkNbmmNum(String rq, String gsbm, String fgsbm, String xlbm,String nbbm,int lx) {
  1095 + StringBuffer stringList =new StringBuffer();
  1096 + List<Object[]> objectList=repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm,nbbm);
  1097 + for (int i = 0; i < objectList.size(); i++) {
  1098 + String clbm=objectList.get(i)[0].toString()+",";
  1099 + int cs=Integer.parseInt(objectList.get(i)[1].toString());
  1100 + //一车一单
  1101 + if(lx==1){
  1102 + if(cs==1){
  1103 + stringList.append(clbm);
  1104 + }
  1105 + }
  1106 + //一车多单
  1107 + if(lx==2){
  1108 + if(cs>1){
  1109 + stringList.append(clbm);
  1110 + }
  1111 +
  1112 + }
  1113 + }
  1114 + return stringList;
  1115 + }
  1116 +
  1117 +
  1118 +
  1119 + @Override
  1120 + public Map<String, Object> sumYlb(Map<String, Object> map) {
  1121 + // TODO Auto-generated method stub
  1122 + List<String> stringList=new ArrayList<String>();
  1123 + String rq=map.get("rq").toString();
  1124 + String gsbm=map.get("ssgsdm_like").toString();
  1125 + String fgsbm=map.get("fgsdm_like").toString();
  1126 + String xlbm=map.get("xlbm_like").toString().trim();
  1127 + String nbbm=map.get("nbbm_eq").toString();
  1128 + String sxtj=map.get("sxtj").toString();
  1129 + String type=map.get("type").toString();
  1130 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1131 + List<Object[]> sumYlbList=new ArrayList<Object[]>();
  1132 + try {
  1133 + if(nbbm.trim()!=""){
  1134 + stringList.add(nbbm);
  1135 + }else{
  1136 + if(!sxtj.equals("0")){
  1137 + List<Object[]> objectLists;
  1138 + if(sxtj.equals("3")){
  1139 + //有加油没里程
  1140 + objectLists=repository.checkNbmmYl(rq, gsbm, fgsbm, xlbm, nbbm);
  1141 + for (int i = 0; i < objectLists.size(); i++) {
  1142 + String clbm=objectLists.get(i)[0].toString();
  1143 + double jzl=Double.parseDouble(objectLists.get(i)[1].toString());
  1144 + double zlc=Double.parseDouble(objectLists.get(i)[2].toString());
  1145 + if(jzl>0 && zlc<=0){
  1146 + stringList.add(clbm);
  1147 + }
  1148 +
  1149 + }
  1150 +
  1151 + }else if(sxtj.equals("4")){
  1152 + //有里程没加油
  1153 + objectLists=repository.checkNbmmYl(rq, gsbm, fgsbm, xlbm, nbbm);
  1154 + for (int i = 0; i < objectLists.size(); i++) {
  1155 + String clbm=objectLists.get(i)[0].toString();
  1156 + double jzl=Double.parseDouble(objectLists.get(i)[1].toString());
  1157 + double zlc=Double.parseDouble(objectLists.get(i)[2].toString());
  1158 + if(zlc>0 && jzl<=0){
  1159 + stringList.add(clbm);
  1160 + }
  1161 +
  1162 + }
  1163 + }else{
  1164 + objectLists=repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm,nbbm);
  1165 + for (int i = 0; i < objectLists.size(); i++) {
  1166 + String clbm=objectLists.get(i)[0].toString();
  1167 + int cs=Integer.parseInt(objectLists.get(i)[1].toString());
  1168 + //一车一单
  1169 +
  1170 + if(sxtj.equals("1")){
  1171 + if(cs==1){
  1172 + stringList.add(clbm);
  1173 + }
  1174 + }
  1175 + //一车多单
  1176 + if(sxtj.equals("2")){
  1177 + if(cs>1){
  1178 + stringList.add(clbm);
  1179 + }
  1180 + }
  1181 + }
  1182 + }
  1183 + }
  1184 + }
  1185 + if(sxtj.equals("0")){
  1186 + sumYlbList=repository.sumYlb2(rq, gsbm, fgsbm, xlbm,nbbm);
  1187 + }else{
  1188 + if(stringList.size()>0){
  1189 +
  1190 +// String strings[]=new String[stringList.size()];
  1191 +// for(int i=0;i<stringList.size();i++){
  1192 +// strings[i]=stringList.get(i);
  1193 +// }
  1194 + if (type.equals("1"))
  1195 + sumYlbList=repository.sumYlb(rq, gsbm, fgsbm, xlbm, stringList);
  1196 + else
  1197 + sumYlbList=repository.sumYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
  1198 + }
  1199 +// else{
  1200 +// sumYlbList=repository.sumYlb2(rq, gsbm, fgsbm, xlbm, nbbm);
  1201 +// }
  1202 +
  1203 + }
  1204 + } catch (ParseException e) {
  1205 + // TODO Auto-generated catch block
  1206 + e.printStackTrace();
  1207 + }
  1208 + Double jzl=0.0,yh=0.0,sh=0.0;
  1209 + for (int i = 0; i < sumYlbList.size(); i++) {
  1210 + jzl = Arith.add(jzl, Double.valueOf(sumYlbList.get(i)[0].toString()));
  1211 + yh = Arith.add(yh, Double.valueOf(sumYlbList.get(i)[1].toString()));
  1212 + sh = Arith.add(sh, Double.valueOf(sumYlbList.get(i)[2].toString()));
  1213 + }
  1214 +
  1215 + Map<String, Object> sumMap=new HashMap<String,Object>();
  1216 + sumMap.put("jzl", jzl);
  1217 + sumMap.put("yh", yh);
  1218 + sumMap.put("sh", sh);
  1219 +
  1220 +// String sql="select sum(jzl),sum(yh),sum(sh) from bsth_c_ylb "
  1221 +// + " where to_days('"+map.get("rq").toString()+"')=to_days(rq) "
  1222 +// + " and ssgsdm like '%"+map.get("ssgsdm_like").toString()+"%' "
  1223 +// + " and fgsdm like '%"+map.get("fgsdm_like").toString()+"%' "
  1224 +// + " and xlbm like '%"+map.get("xlbm_like").toString()+ "%'"
  1225 +// + " and nbbm like '%"+map.get("nbbm_eq").toString()+"% '";
  1226 +// if(map.get("nbbm_in")!=null){
  1227 +//// sql +=" and nbbm in ("
  1228 +// }
  1229 + return sumMap;
  1230 + }
  1231 +
  1232 +
  1233 +
  1234 + @Override
  1235 + public List<Ylb> listYlb(Map<String, Object> map) {
  1236 + // TODO Auto-generated method stub
  1237 + List<Ylb> listYlb = new ArrayList<Ylb>();
  1238 + try {
  1239 + List<String> stringList = new ArrayList<String>();
  1240 + String rq = map.get("rq").toString();
  1241 + String gsbm = map.get("ssgsdm_like").toString();
  1242 + String fgsbm = map.get("fgsdm_like").toString();
  1243 + String xlbm = map.get("xlbm_like").toString().trim();
  1244 + String nbbm = map.get("nbbm_eq").toString();
  1245 + String sxtj = map.get("sxtj").toString();
  1246 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1247 + String type = map.get("type").toString();
  1248 + if (nbbm.trim() != "") {
  1249 + stringList.add(nbbm);
  1250 + List<Object[]> objectLists = repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm, nbbm);
  1251 + if (objectLists.size() > 0) {
  1252 + int cs = Integer.parseInt(objectLists.get(0)[1].toString());
  1253 + if (sxtj.equals("1")) {
  1254 + if (cs == 1) {
  1255 + if (type.equals("1"))
  1256 + listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
  1257 + else
  1258 + listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
  1259 +
  1260 + }
  1261 + } else if (sxtj.equals("2")) {
  1262 + if (cs > 1) {
  1263 + if (type.equals("1"))
  1264 + listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
  1265 + else
  1266 + listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
  1267 + }
  1268 + } else {
  1269 + if (type.equals("1"))
  1270 + listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
  1271 + else
  1272 + listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
  1273 + }
  1274 + }
  1275 +
  1276 + } else {
  1277 + // 全部
  1278 + if (sxtj.equals("0")) {
  1279 + List<Object[]> objectLists = repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm, nbbm);
  1280 + for (int i = 0; i < objectLists.size(); i++) {
  1281 + String clbm = objectLists.get(i)[0].toString();
  1282 + stringList.add(clbm);
  1283 + }
  1284 + if (stringList.size() > 0) {
  1285 + if (type.equals("1"))
  1286 + listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
  1287 + else
  1288 + listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
  1289 + }
  1290 + }else if(sxtj.equals("5")){
  1291 + List<Object[]> objectLists = repository.checkNbmmFgs(rq, gsbm);
  1292 + for (int i = 0; i < objectLists.size(); i++) {
  1293 + String clbm =objectLists.get(i)[0].toString();
  1294 + stringList.add(clbm);
  1295 + }
  1296 +
  1297 + if (stringList.size() > 0) {
  1298 + if (type.equals("1"))
  1299 + listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
  1300 + else
  1301 + listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
  1302 + }
  1303 + } else {
  1304 + List<Object[]> objectLists;
  1305 + if (sxtj.equals("3")) {
  1306 + // 有加油没里程
  1307 + objectLists = repository.checkNbmmYl(rq, gsbm, fgsbm, xlbm, nbbm);
  1308 + for (int i = 0; i < objectLists.size(); i++) {
  1309 + String clbm = objectLists.get(i)[0].toString();
  1310 + double jzl = Double.parseDouble(objectLists.get(i)[1].toString());
  1311 + double zlc = Double.parseDouble(objectLists.get(i)[2].toString());
  1312 + if (jzl > 0 && zlc <= 0) {
  1313 + stringList.add(clbm);
  1314 + }
  1315 +
  1316 + }
  1317 +
  1318 + } else if (sxtj.equals("4")) {
  1319 + // 有里程没加油
  1320 + objectLists = repository.checkNbmmYl(rq, gsbm, fgsbm, xlbm, nbbm);
  1321 + for (int i = 0; i < objectLists.size(); i++) {
  1322 + String clbm = objectLists.get(i)[0].toString();
  1323 + double jzl = Double.parseDouble(objectLists.get(i)[1].toString());
  1324 + double zlc = Double.parseDouble(objectLists.get(i)[2].toString());
  1325 + if (zlc > 0 && jzl <= 0) {
  1326 + stringList.add(clbm);
  1327 + }
  1328 +
  1329 + }
  1330 + } else {
  1331 + objectLists = repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm, nbbm);
  1332 + for (int i = 0; i < objectLists.size(); i++) {
  1333 + String clbm = objectLists.get(i)[0].toString();
  1334 + int cs = Integer.parseInt(objectLists.get(i)[1].toString());
  1335 + // 一车一单
  1336 + if (sxtj.equals("1")) {
  1337 + if (cs == 1) {
  1338 + stringList.add(clbm);
  1339 + }
  1340 + }
  1341 + // 一车多单
  1342 + if (sxtj.equals("2")) {
  1343 + if (cs > 1) {
  1344 + stringList.add(clbm);
  1345 + }
  1346 + }
  1347 + }
  1348 + }
  1349 +
  1350 + if (stringList.size() > 0) {
  1351 + if (type.equals("1"))
  1352 + listYlb = repository.listYlb(rq, gsbm, fgsbm, xlbm, stringList);
  1353 + else
  1354 + listYlb = repository.listYlb_s(sdf.parse(rq+" 00:00:00"), gsbm, fgsbm, xlbm, stringList);
  1355 + }
  1356 + }
  1357 + }
  1358 + } catch (ParseException e) {
  1359 + // TODO Auto-generated catch block
  1360 + e.printStackTrace();
  1361 + }
  1362 + return listYlb;
  1363 + }
  1364 +
  1365 + @Transactional
  1366 + @Override
  1367 + public Map<String, Object> saveYlbList(Map<String, Object> map) throws Exception {
  1368 + // TODO Auto-generated method stub
  1369 + Map<String, Object> newMap=new HashMap<String,Object>();
  1370 + try{
  1371 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  1372 + String json =StringEscapeUtils.unescapeHtml4(map.get("ylbList").toString());
  1373 + JSONArray jsonArray=JSONArray.parseArray(json);
  1374 + JSONObject jsonObject;
  1375 + // 获取车辆存油信息
  1376 + List<Cyl> cylList = cylRepository.obtainCyl("","");
  1377 + for (int i = 0; i < jsonArray.size(); i++) {
  1378 +// Ylb t=new Ylb();
  1379 + jsonObject=jsonArray.getJSONObject(i);
  1380 + double czyl = jsonObject.getDoubleValue("czyl");
  1381 + double jzl =jsonObject.getDoubleValue("jzl");
  1382 + double jzyl =jsonObject.getDoubleValue("jzyl");
  1383 + double sh =jsonObject.getDoubleValue("sh");
  1384 + String shyy =jsonObject.getString("shyy");
  1385 + double ns = jsonObject.getDoubleValue("ns");
  1386 + String rylx =jsonObject.getString("rylx");
  1387 + int yhlx =jsonObject.getIntValue("yhlx");
  1388 + Integer id =jsonObject.getInteger("id");
  1389 + String nbbm =jsonObject.getString("nbbm");
  1390 + String rq=jsonObject.getString("rq");
  1391 + double yh = Arith.sub(Arith.add(czyl, jzl),jzyl);
  1392 + if(yh<0){
  1393 + yh=0.0;
  1394 + }
  1395 + repository.ylbUpdate(id, czyl, jzyl, yh, sh, shyy, ns, rylx,yhlx);
  1396 + }
  1397 +// List<Map<String, Object>> list=(List<Map<String, Object>>) map.get("ylbList");
  1398 + SysUser user = SecurityUtils.getCurrentUser();
  1399 + Nylog nylog=new Nylog();
  1400 + nylog.setCreatedate(new Date());
  1401 + nylog.setCzmc("保存全部");
  1402 + nylog.setNylx("油");
  1403 + nylog.setUserid(user.getUserName());
  1404 + nylog.setUsername(user.getName());
  1405 + nylog.setCxtj("");
  1406 + nylogRepository.save(nylog);
  1407 + newMap.put("status", ResponseCode.SUCCESS);
  1408 + }catch(Exception e){
  1409 + newMap.put("status", ResponseCode.ERROR);
  1410 + logger.error("save erro.", e);
  1411 + throw e;
  1412 + }
  1413 + return newMap;
  1414 + }
  1415 +
  1416 + /**
  1417 + * 拆分
  1418 + */
  1419 + @Transactional
  1420 + @Override
  1421 + public Map<String, Object> sort(Map<String, Object> map) throws Exception{
  1422 + // TODO Auto-generated method stub
  1423 + Map<String, Object> newMap = new HashMap<String, Object>();
  1424 + SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
  1425 +
  1426 + try {
  1427 + List<Cyl> cylList = cylRepository.findAll(new CustomerSpecs<Cyl>(newMap));
  1428 + String json =StringEscapeUtils.unescapeHtml4(map.get("ylbList").toString());
  1429 + String fgsbm="999";
  1430 + if(map.get("fgsbm")!=null){
  1431 + fgsbm=map.get("fgsbm").toString();
  1432 + }
  1433 + JSONArray jsonArray=JSONArray.parseArray(json);
  1434 + JSONObject jsonObject;
  1435 + for (int x = 0; x < jsonArray.size(); x++) {
  1436 + jsonObject=jsonArray.getJSONObject(x);
  1437 + Double yl =jsonObject.getDoubleValue("jzyl");
  1438 + Double sh =jsonObject.getDoubleValue("sh");
  1439 + String shyy =jsonObject.getString("shyy");
  1440 + Double ns = jsonObject.getDoubleValue("ns");
  1441 + String rylx =jsonObject.getString("rylx");
  1442 + Integer id =jsonObject.getInteger("id");
  1443 + Ylb ylb = repository.findById(id).get();
  1444 + String nbbm_eq = ylb.getNbbm();
  1445 + Date rq_eq = ylb.getRq();
  1446 + // 得到一天总的加油和里程(根据车,时间)
  1447 + List<Object[]> sumList=new ArrayList<Object[]>();
  1448 + if(fgsbm.equals(""))
  1449 + sumList = repository.sumLcYl(nbbm_eq, rq_eq,"",ylb.getSsgsdm(),fgsbm);
  1450 + else
  1451 + sumList = repository.sumLcYl(nbbm_eq, rq_eq,"",ylb.getSsgsdm(),ylb.getFgsdm());
  1452 +
  1453 + // 保存总的加油量
  1454 + Double jzl = 0.0;
  1455 + // 保存总的里程
  1456 + Double zlc = 0.0;
  1457 + //保存总的损耗
  1458 + Double zsh = 0.0;
  1459 + for (int j = 0; j < sumList.size(); j++) {
  1460 + jzl = Arith.add(jzl, Double.valueOf(sumList.get(j)[0].toString()));
  1461 + zlc = Arith.add(zlc, Double.valueOf(sumList.get(j)[1].toString()));
  1462 + zsh = Arith.add(zsh, Double.valueOf(sumList.get(j)[2].toString()));
  1463 + }
  1464 +// jzl = Arith.sub(jzl, zsh);
  1465 + //新的 损耗不等于 旧的损耗 总损耗从新算
  1466 + /*if(Arith.sub(ylb.getSh(),sh )!=0){
  1467 + zsh =Arith.add(Arith.sub(zsh, ylb.getSh()), sh);
  1468 + jzl =Arith.sub(jzl, zsh);
  1469 + }else{
  1470 + jzl =Arith.sub(jzl, zsh);
  1471 + }*/
  1472 + map.put("nbbm_eq", nbbm_eq);
  1473 + map.put("rq_eq", rq_eq);
  1474 + List<Ylb> iterator2=null;
  1475 + if(fgsbm.equals(""))
  1476 + iterator2=this.listOrderBy(sdf.format(rq_eq),ylb.getSsgsdm(),fgsbm,"",
  1477 + ylb.getNbbm(),"jcsx");
  1478 + else
  1479 + iterator2=this.listOrderBy(sdf.format(rq_eq),ylb.getSsgsdm(),ylb.getFgsdm(),"",
  1480 + ylb.getNbbm(),"jcsx");
  1481 +
  1482 +// repository.obtainYl(sdf.format(rq_eq),ylb.getSsgsdm(),ylb.getFgsdm(),"",
  1483 +// ylb.getNbbm(),"jcsx");
  1484 + DecimalFormat df = new DecimalFormat("#.00");
  1485 + Double zyl = 0.0;
  1486 + Double nextJzyl = 0.0;
  1487 + // 车的,进,出油量及耗油
  1488 + double czyl=0.0;
  1489 + for (int i = 0; i < iterator2.size(); i++) {
  1490 + Ylb t = iterator2.get(i);
  1491 + if (t.getJcsx() == 1) {
  1492 + if(t.getId()==id){
  1493 + t.setSh(sh);
  1494 + t.setShyy(shyy);
  1495 + }
  1496 + czyl=t.getCzyl();
  1497 + Double jcyl = t.getCzyl();
  1498 + zyl = Arith.sub(Arith.add(jcyl, jzl), yl);
  1499 + Double yh = 0.0;
  1500 + if (zlc > 0 && t.getZlc() > 0) {
  1501 + yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
  1502 + }
  1503 + nextJzyl =Arith.sub(Arith.add(t.getJzl(), t.getCzyl()), yh);
  1504 +// nextJzyl =Arith.sub(Arith.add(t.getJzl(), t.getCzyl()), Arith.add(yh, t.getSh()));
  1505 + if(zlc>0 && t.getZlc() > 0){
  1506 + long l=Math.round(nextJzyl);
  1507 + double ylxs=l*100/100;
  1508 +// nextJzyl = Arith.add(nextJzyl,Arith.sub(nextJzyl,ylxs));
  1509 + yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
  1510 + t.setYh(yh);
  1511 + t.setJzyl(ylxs);
  1512 + nextJzyl=ylxs;
  1513 + }else{
  1514 + t.setYh(yh);
  1515 + t.setJzyl(nextJzyl);
  1516 + }
  1517 + } else {
  1518 + if(t.getId()==id){
  1519 + t.setSh(sh);
  1520 + t.setShyy(shyy);
  1521 + }
  1522 + t.setCzyl(nextJzyl);
  1523 + Double yh =0.0;
  1524 + if (t.getZlc() >= 0) {
  1525 + yh= Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
  1526 + }
  1527 +// nextJzyl = Arith.sub(Arith.add(t.getJzl(), nextJzyl), Arith.add(yh, t.getSh()));
  1528 + nextJzyl = Arith.sub(Arith.add(t.getJzl(), nextJzyl), yh);
  1529 + if(zlc>0 && t.getZlc() >0){
  1530 + long l=0l;
  1531 + double ylxs=0.0;
  1532 + if(i==iterator2.size()-1){
  1533 + ylxs=yl;
  1534 + }else{
  1535 + l=Math.round(nextJzyl);
  1536 + ylxs=l*100/100;
  1537 + }
  1538 + yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
  1539 + t.setYh(yh);
  1540 + t.setJzyl(ylxs);
  1541 + nextJzyl=ylxs;
  1542 + }else{
  1543 + t.setYh(yh);
  1544 + t.setJzyl(nextJzyl);
  1545 + }
  1546 + }
  1547 + if(t.getJzyl()<0){
  1548 + t.setJzyl(0.0);
  1549 + }
  1550 + if(t.getCzyl()<0){
  1551 + t.setCzyl(0.0);
  1552 + }
  1553 + if(t.getYh()<0){
  1554 + t.setYh(0.0);
  1555 + }
  1556 + if(t.getSh()<0){
  1557 + t.setSh(0.0);
  1558 + }
  1559 + repository.save(t);
  1560 + }
  1561 + newMap.put("status", ResponseCode.SUCCESS);
  1562 + }
  1563 +
  1564 + SysUser user = SecurityUtils.getCurrentUser();
  1565 + Nylog nylog=new Nylog();
  1566 + nylog.setCreatedate(new Date());
  1567 + nylog.setCzmc("拆分");
  1568 + nylog.setNylx("油");
  1569 + nylog.setUserid(user.getUserName());
  1570 + nylog.setUsername(user.getName());
  1571 + nylog.setCxtj("");
  1572 + nylogRepository.save(nylog);
  1573 + } catch (Exception e) {
  1574 + newMap.put("status", ResponseCode.ERROR);
  1575 + logger.error("save erro.", e);
  1576 + throw e;
  1577 + }
  1578 + return newMap;
  1579 + }
  1580 +
  1581 +
  1582 + @Override
  1583 + public String checkJsy(Map<String, Object> map) {
  1584 + // TODO Auto-generated method stub
  1585 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  1586 + String rq=map.get("date").toString();
  1587 + String nbbm=map.get("nbbm").toString();
  1588 + String jsy =map.get("jsy").toString();
  1589 + String xlbm=map.get("xlbm").toString();
  1590 + List<Ylb> list= repository.checkYlb(rq, nbbm, jsy,xlbm,"nbbm");
  1591 + String type="1";
  1592 + if(list.size()>0){
  1593 + type="0";
  1594 + }
  1595 + return type;
  1596 + }
  1597 +
  1598 + @Override
  1599 + public String checkDate(Map<String, Object> map) {
  1600 + // TODO Auto-generated method stub
  1601 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  1602 + String rq=map.get("rq").toString();
  1603 + String gsbm=map.get("ssgsdm_like").toString();
  1604 + String type="1";
  1605 + if(gsbm.equals("26")){
  1606 + Date date=new Date();
  1607 + try {
  1608 + long day2=date.getTime();
  1609 + long day1=sdf.parse(rq).getTime();
  1610 + long days = (day2 - day1) / (24*3600*1000);
  1611 + if(days>3){
  1612 + type="2";
  1613 + }
  1614 + } catch (ParseException e) {
  1615 + // TODO Auto-generated catch block
  1616 + e.printStackTrace();
  1617 + }
  1618 + }
  1619 + return type;
  1620 + }
  1621 +
  1622 +
  1623 +
  1624 + @Override
  1625 + public Map<String, Object> saveYlb(Ylb t) {
  1626 + Map<String, Object> map = new HashMap<>();
  1627 + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  1628 + String rq=sdf.format(t.getRq());
  1629 + String gsdm=t.getSsgsdm();
  1630 + String fgsdm=t.getFgsdm();
  1631 + String xlbm=t.getXlbm();
  1632 + String jhsj=t.getJhsj();
  1633 + String jsy=t.getJsy();
  1634 + String nbbm=t.getNbbm();
  1635 + t.setCreatetime(new Date());
  1636 + String[] jhsjStr = jhsj.split(":");
  1637 + long fcsjL= Long.parseLong(jhsjStr[0])*60+Long.parseLong(jhsjStr[1]);
  1638 + List<Ylb> list=this.listOrderBy(rq, gsdm, fgsdm, xlbm, nbbm, "jhsj");
  1639 +// repository.obtainYl(rq, gsdm, fgsdm, xlbm, nbbm, "jhsj");
  1640 + int jcsx=1;
  1641 + if(list.size()>0){
  1642 + for (int i = 0; i < list.size(); i++) {
  1643 + Ylb y=list.get(i);
  1644 + String[] fcsjStr = y.getJhsj().split(":");
  1645 + long fcsj=Long.parseLong(fcsjStr[0])*60+Long.parseLong(fcsjStr[1]);
  1646 + if(fcsjL>fcsj){
  1647 + jcsx=jcsx+y.getJcsx();
  1648 + }else{
  1649 + y.setJcsx(y.getJcsx()+1);
  1650 + repository.save(y);
  1651 + }
  1652 + }
  1653 +
  1654 + }
  1655 + t.setJcsx(jcsx);
  1656 + repository.save(t);
  1657 +
  1658 + SysUser user = SecurityUtils.getCurrentUser();
  1659 + Nylog nylog=new Nylog();
  1660 + nylog.setCreatedate(new Date());
  1661 + nylog.setCzmc("手动添加");
  1662 + nylog.setNylx("油");
  1663 + nylog.setUserid(user.getUserName());
  1664 + nylog.setUsername(user.getName());
  1665 + nylog.setCxtj("");
  1666 + nylogRepository.save(nylog);
  1667 + map.put("status", ResponseCode.SUCCESS);
  1668 + map.put("t", t);
  1669 + return map;
  1670 + }
  1671 + @Transactional
  1672 + @Override
  1673 + public Map<String, Object> deleteIds(Map<String, Object> map) throws Exception{
  1674 + // TODO Auto-generated method stub
  1675 + Map<String, Object> maps = new HashMap<>();
  1676 + try{
  1677 + String json =StringEscapeUtils.unescapeHtml4(map.get("ids").toString());
  1678 + JSONArray jsonArray=JSONArray.parseArray(json);
  1679 + JSONObject jsonObject;
  1680 + for (int x = 0; x < jsonArray.size(); x++) {
  1681 + jsonObject=jsonArray.getJSONObject(x);
  1682 + Integer id =jsonObject.getInteger("id");
  1683 + repository.deleteById(id);
  1684 + }
  1685 +
  1686 + SysUser user = SecurityUtils.getCurrentUser();
  1687 + Nylog nylog=new Nylog();
  1688 + nylog.setCreatedate(new Date());
  1689 + nylog.setCzmc("删除");
  1690 + nylog.setNylx("油");
  1691 + nylog.setUserid(user.getUserName());
  1692 + nylog.setUsername(user.getName());
  1693 + nylog.setCxtj("");
  1694 + nylogRepository.save(nylog);
  1695 + maps.put("status", ResponseCode.SUCCESS);
  1696 + } catch (Exception e) {
  1697 + maps.put("status", ResponseCode.ERROR);
  1698 + logger.error("save erro.", e);
  1699 + throw e;
  1700 + }
  1701 + return maps;
  1702 + }
  1703 +
  1704 + public List<Ylb> listOrderBy(String rq,String gsdm,
  1705 + String fgsdm,String xlbm,String nbbm,
  1706 + String px) {
  1707 + // TODO Auto-generated method stub
  1708 + String sql="SELECT * FROM bsth_c_ylb "
  1709 + + " where rq ='"+rq+"' and ssgsdm like '%"+gsdm+"%' "
  1710 + + " and fgsdm like '%"+fgsdm+"%'";
  1711 + if(xlbm.equals("")){
  1712 + sql+= " and xlbm like '%"+xlbm+"%' ";
  1713 + }else{
  1714 + sql+= " and xlbm = '"+xlbm+"' ";
  1715 + }
  1716 +
  1717 + sql += "and nbbm like '%"+nbbm+"%' order by "+px+" asc ";
  1718 +
  1719 + List<Ylb> list = jdbcTemplate.query(sql, new RowMapper<Ylb>() {
  1720 + @Override
  1721 + public Ylb mapRow(ResultSet arg0, int arg1) throws SQLException {
  1722 + Ylb y = new Ylb();
  1723 + y.setId(arg0.getInt("id"));
  1724 + return y;
  1725 + }
  1726 + });
  1727 + List<Ylb> lists=new ArrayList<Ylb>();
  1728 + List<Ylb> ylbLists=repository.obtainYl(rq,gsdm,fgsdm,xlbm,nbbm,"jcsx");
  1729 + for (int i = 0; i < list.size(); i++) {
  1730 + Ylb t=list.get(i);
  1731 + for (int j = 0; j < ylbLists.size(); j++) {
  1732 + Ylb t2=ylbLists.get(j);
  1733 + if(t.getId().intValue()==t2.getId().intValue()){
  1734 + lists.add(t2);
  1735 + break;
  1736 + }
  1737 + }
  1738 + }
  1739 +
  1740 + return lists;
  1741 + }
  1742 +
  1743 + @Override
  1744 + public Map<String, Object> updateHistory(Map<String, Object> map) throws Exception {
  1745 + // TODO Auto-generated method stub
  1746 + Map<String, Object> newMap = new HashMap<String, Object>();
  1747 +
  1748 + List<Cars> carsList = carsRepository.findCars();
  1749 + Map<String, Boolean> carsMap = new HashMap<String, Boolean>();
  1750 + for (int i = 0; i < carsList.size(); i++) {
  1751 + Cars c = carsList.get(i);
  1752 + carsMap.put(c.getInsideCode(), c.getSfdc());
  1753 + }
  1754 + try{
  1755 + String date = map.get("date").toString();
  1756 + String line = map.get("line").toString();
  1757 + List<Line> listLine=lineRepository.findLineByCode(line);
  1758 + String gsdm ="";
  1759 + String fgsdm ="";
  1760 + if(listLine.size()>0){
  1761 + Line l=listLine.get(0);
  1762 + gsdm=l.getCompany();
  1763 + fgsdm=l.getBrancheCompany();
  1764 + }
  1765 +
  1766 + String nbbmstr="";
  1767 + List<Map<String, Object>> listpbYc=new ArrayList<Map<String, Object>>();//油车数据
  1768 + List<Map<String, Object>> listpbDc=new ArrayList<Map<String, Object>>();//电车数据
  1769 + List<Map<String,Object>> listpb=scheduleRealInfoService.yesterdayDataList("", date,gsdm, fgsdm, "", "");
  1770 + for (int i = 0; i < listpb.size(); i++) {
  1771 + if(listpb.get(i).get("xlBm").toString().equals(line)){
  1772 + nbbmstr +=listpb.get(i).get("clZbh").toString();
  1773 + }
  1774 + }
  1775 + for (int i = 0; i < listpb.size(); i++) {
  1776 + boolean sfdc=true;
  1777 + Map<String, Object> m = listpb.get(i);
  1778 + if (carsMap.get(m.get("clZbh").toString()) != null) {
  1779 + sfdc = carsMap.get(m.get("clZbh").toString());
  1780 + } else {
  1781 + sfdc = true;
  1782 + }
  1783 + if(nbbmstr.indexOf(m.get("clZbh").toString())>-1){
  1784 + if(sfdc){
  1785 + listpbDc.add(m);
  1786 + }else{
  1787 + listpbYc.add(m);
  1788 + }
  1789 + }
  1790 + }
  1791 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  1792 + //初始存油量
  1793 + List<Cyl> clyList = cylRepository.obtainCyl("",gsdm);
  1794 + List<Ylxxb> ylxxList = ylxxbRepository.obtainYlxx(date, 0,gsdm);
  1795 + //重新统计油车数据开始
  1796 + List<Ylb> ylListBe =repository.listByRqJcsx(date, gsdm, fgsdm, "", "");
  1797 + List<Ylb> ylbList=this.listOrderBy(date,gsdm,fgsdm,"","","nbbm");
  1798 + List<Ylb> ylbList_upd=new ArrayList<Ylb>();
  1799 + List<Ylb> ylbList_del=new ArrayList<Ylb>();
  1800 +
  1801 + for (int j = 0; j < ylbList.size(); j++) {
  1802 + Ylb t=ylbList.get(j);
  1803 + boolean fage=true;
  1804 + if(StringUtils.isEmpty(t.getLp())){
  1805 + fage=false;
  1806 + }else{
  1807 + for (int i = 0; i < listpbYc.size(); i++) {
  1808 + Map<String, Object> m = listpbYc.get(i);
  1809 + if(t.getNbbm().equals(m.get("clZbh").toString())
  1810 + &&t.getJsy().equals(m.get("jGh").toString())
  1811 + &&t.getXlbm().equals(m.get("xlBm").toString())
  1812 + &&t.getLp().equals(m.get("lpName").toString())){
  1813 + //该条记录不用删除
  1814 + fage =false;
  1815 + ylbList_upd.add(t);
  1816 + }
  1817 + }
  1818 + }
  1819 + if(fage){
  1820 + if(t.getXlbm().equals(line)){
  1821 + ylbList_del.add(t);
  1822 + }
  1823 + }
  1824 +
  1825 + }
  1826 + String nbbmStr="";
  1827 + List<Ylb> list=new ArrayList<Ylb>();
  1828 + /*
  1829 + * 第一步 修改车辆里程 和加注量
  1830 + */
  1831 + Map<String, Object> ylMap=new HashMap<String, Object>();
  1832 + for (int x = 0; x < listpbYc.size(); x++) {
  1833 + String type = "add";
  1834 + Map<String, Object> maps = listpbYc.get(x);
  1835 + // 判断驾驶员驾驶的该车辆是否已经存入了(查出的结果集中日期是相同的,根据驾驶员、内部编号、线路编码判断)
  1836 + Ylb t = new Ylb();
  1837 + for (int k = 0; k < ylbList_upd.size(); k++) {
  1838 + Ylb t1 = ylbList_upd.get(k);
  1839 + if (t1.getNbbm().equals(maps.get("clZbh").toString())
  1840 + && t1.getJsy().equals(maps.get("jGh").toString())
  1841 + && t1.getXlbm().equals(maps.get("xlBm").toString())
  1842 + && t1.getLp().equals(maps.get("lpName").toString())) {
  1843 + t = t1;
  1844 + type = "update";
  1845 + }
  1846 + }
  1847 + if(type.equals("add")){
  1848 + // 当日的第一个班次,出场油量等于前一天的最后一个班次的进场油量
  1849 + if (maps.get("seqNumber").toString().equals("1")) {
  1850 + boolean fage = true;
  1851 + for (int i = 0; i < ylListBe.size(); i++) {
  1852 + Ylb ylb = ylListBe.get(i);
  1853 + if (maps.get("clZbh").toString().equals(ylb.getNbbm())) {
  1854 + if(ylb.getJzyl()>=0){
  1855 + t.setCzyl(ylb.getJzyl());
  1856 + fage = false;
  1857 + break;
  1858 + }
  1859 + }
  1860 + }
  1861 + if (fage) {
  1862 + for (int y = 0; y < clyList.size(); y++) {
  1863 + Cyl cyl = clyList.get(y);
  1864 + if (maps.get("clZbh").toString().equals(cyl.getNbbm())) {
  1865 + if(cyl!=null){
  1866 + if(cyl.getCyl()>=0){
  1867 + t.setCzyl(cyl.getCyl());
  1868 + fage = false;
  1869 + break;
  1870 + }else {
  1871 + if(cyl.getCxrl()!=null){
  1872 + if(cyl.getCxrl()>0){
  1873 + t.setCzyl(cyl.getCxrl());
  1874 + fage = false;
  1875 + break;
  1876 + }
  1877 + }
  1878 + }
  1879 + }
  1880 + }
  1881 + }
  1882 + }
  1883 + if (fage) {
  1884 + t.setCzyl(0.0);
  1885 + }
  1886 + }
  1887 + }
  1888 +
  1889 + Double jzl = 0.0;
  1890 + //一人一车加注量只匹配一次
  1891 + if(ylMap.get(maps.get("clZbh").toString()+"_"+ maps.get("jGh").toString())!=null){
  1892 + }else{
  1893 + boolean fage2=false;
  1894 + for (int i = 0; i < ylxxList.size(); i++) {
  1895 + Ylxxb ylxxb = ylxxList.get(i);
  1896 + if (maps.get("clZbh").toString().equals(ylxxb.getNbbm())
  1897 + && maps.get("jGh").toString().equals(ylxxb.getJsy())
  1898 + && ylxxb.getJylx()==1) {
  1899 + if(ylxxb.getJzl()>0){
  1900 + fage2=true;
  1901 + }
  1902 + }
  1903 + }
  1904 + //车辆的加注量如果有任工干预,略接口过来 数据
  1905 + if(fage2){
  1906 + // 把当天手工输入的的YLXXB的加注量设置为当天YLB的加注量(根据车号,驾驶员判断,加油类型为1)
  1907 + for (int j = 0; j < ylxxList.size(); j++) {
  1908 + Ylxxb ylxxb = ylxxList.get(j);
  1909 + if (maps.get("clZbh").toString().equals(ylxxb.getNbbm())
  1910 + && maps.get("jGh").toString().equals(ylxxb.getJsy())
  1911 + && ylxxb.getJylx()==1) {
  1912 + jzl =Arith.add(jzl, ylxxb.getJzl());
  1913 + }
  1914 + }
  1915 + ylMap.put(maps.get("clZbh").toString()+"_"+ maps.get("jGh").toString(),maps.get("xlBm") == null ? "" : maps.get("xlBm").toString());
  1916 + }else{
  1917 + // 把当天的YLXXB的加注量设置为当天YLB的加注量(根据车号,驾驶员判断)
  1918 + for (int j = 0; j < ylxxList.size(); j++) {
  1919 + Ylxxb ylxxb = ylxxList.get(j);
  1920 + if (maps.get("clZbh").toString().equals(ylxxb.getNbbm())
  1921 + && maps.get("jGh").toString().equals(ylxxb.getJsy())) {
  1922 + jzl =Arith.add(jzl, ylxxb.getJzl());
  1923 + }
  1924 + }
  1925 + ylMap.put(maps.get("clZbh").toString()+"_"+ maps.get("jGh").toString(),maps.get("xlBm") == null ? "" : maps.get("xlBm").toString());
  1926 + }
  1927 + }
  1928 + t.setJzl(jzl);
  1929 + t.setNbbm(maps.get("clZbh").toString());
  1930 + t.setJsy(maps.get("jGh") == null ? "" : maps.get("jGh").toString());
  1931 + t.setJname(maps.get("jName").toString());
  1932 + t.setZlc(maps.get("totalKilometers") == null ? 0.0
  1933 + : Double.parseDouble(maps.get("totalKilometers").toString()));
  1934 + t.setXlbm(maps.get("xlBm") == null ? "" : maps.get("xlBm").toString());
  1935 + t.setJcsx(Integer.parseInt(maps.get("seqNumber").toString()));
  1936 + t.setSsgsdm(maps.get("company") == null ? "" : maps.get("company").toString());
  1937 + t.setFgsdm(maps.get("bCompany") == null ? "" : maps.get("bCompany").toString());
  1938 + t.setJhsj(maps.get("fcsj")==null?"":maps.get("fcsj").toString());
  1939 + t.setRq(sdf.parse(date));
  1940 + t.setLp(maps.get("lpName")==null?"":maps.get("lpName").toString());
  1941 + if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
  1942 + if(type.equals("add")){
  1943 + if(nbbmStr.indexOf(t.getNbbm())<0){
  1944 + nbbmStr +=t.getNbbm()+",";
  1945 + }
  1946 + t.setCreatetime(new Date());
  1947 + }else{
  1948 + t.setUpdatetime(new Date());
  1949 + }
  1950 + }
  1951 + try {
  1952 + repository.save(t);
  1953 + } catch (Exception e) {
  1954 + // TODO: handle exception
  1955 + if(e.getMessage().indexOf("PK_YLB_UK")>0){
  1956 + newMap.put("fage", "存在相同数据,数据已经过滤");
  1957 + logger.info("油量存在相同数据,数据已经过滤");
  1958 + }
  1959 + }
  1960 +
  1961 + }
  1962 + for (int i = 0; i < ylbList_del.size(); i++) {
  1963 + Ylb y=ylbList_del.get(i);
  1964 + if(nbbmStr.indexOf(y.getNbbm())<0){
  1965 + nbbmStr +=y.getNbbm()+",";
  1966 + }
  1967 + repository.deleteById(y.getId());
  1968 + }
  1969 +
  1970 + //重新计算删除了的或者新增了的车的车的油耗信息(考虑车辆可能跨线路,从分公司赛选计算)
  1971 + double czyl=0.0;
  1972 + List<Ylb> iterator2=this.listOrderBy(date,gsdm,fgsdm,"","","nbbm,jcsx");
  1973 + String[] nbbms=nbbmStr.split(",");
  1974 + for (int i = 0; i < nbbms.length; i++) {
  1975 + String clzbm=nbbms[i];
  1976 + // 得到一天总的加油和里程(根据车,时间)
  1977 + List<Object[]> sumList = repository.sumLcYl(clzbm, sdf.parse(date),"",gsdm,fgsdm);
  1978 + // 保存总的加油量
  1979 + Double jzl = 0.0;
  1980 + // 保存总的里程
  1981 + Double zlc = 0.0;
  1982 + for (int j = 0; j < sumList.size(); j++) {
  1983 + jzl = Arith.add(jzl, Double.valueOf(sumList.get(j)[0].toString()));
  1984 + zlc = Arith.add(zlc, Double.valueOf(sumList.get(j)[1].toString()));
  1985 + }
  1986 + // 保留两位小数
  1987 + DecimalFormat df = new DecimalFormat("#.00");
  1988 + Double zyl = 0.0;
  1989 + Double nextJzyl = 0.0;
  1990 + for (int j = 0; j < iterator2.size(); j++) {
  1991 + Ylb t = iterator2.get(j);
  1992 + if(t.getNbbm().equals(clzbm)){
  1993 + if (t.getJcsx() == 1) {
  1994 + // 进场等于出场的操作 既 最后进场存油量等于第一次的出场存油量
  1995 + czyl = t.getCzyl();
  1996 + zyl =jzl;
  1997 + Double yh=0.0;
  1998 + if(zlc>0 ){
  1999 + yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
  2000 + }
  2001 + nextJzyl =Arith.sub( Arith.add(t.getJzl(), t.getCzyl()),yh);
  2002 + //把进场油量的小数和整数分别取出
  2003 + if(zlc>0 && t.getZlc()>0){
  2004 + long l=Math.round(nextJzyl);
  2005 + double ylxs=l*100/100;
  2006 + yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
  2007 + t.setYh(yh);
  2008 + t.setJzyl(ylxs);
  2009 + nextJzyl=ylxs;
  2010 + }else{
  2011 + t.setYh(yh);
  2012 + t.setJzyl(nextJzyl);
  2013 + }
  2014 + } else {
  2015 + t.setCzyl(nextJzyl);
  2016 + Double yh=0.0;
  2017 + if(zlc>0){
  2018 + yh= Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
  2019 + }
  2020 + nextJzyl =Arith.sub( Arith.add(t.getJzl(),nextJzyl),yh);
  2021 + if(zlc>0 && t.getZlc()>0){
  2022 + long l=0l;
  2023 + double ylxs=0.0;
  2024 + if(j==iterator2.size()-1){
  2025 + ylxs=czyl;
  2026 + }else{
  2027 + if(iterator2.get(j+1).getNbbm().equals(t.getNbbm())){
  2028 + l=Math.round(nextJzyl);
  2029 + ylxs=l*100/100;
  2030 + }else{
  2031 + ylxs=czyl;
  2032 + }
  2033 +
  2034 + }
  2035 + yh=Arith.add(yh, Arith.sub(nextJzyl,ylxs));
  2036 + t.setYh(yh);
  2037 + t.setJzyl(ylxs);
  2038 + nextJzyl=ylxs;
  2039 + }else{
  2040 + t.setYh(yh);
  2041 + t.setJzyl(nextJzyl);
  2042 + }
  2043 + }
  2044 + if(t.getJzyl()<0){
  2045 + t.setJzyl(0.0);
  2046 + }
  2047 + if(t.getCzyl()<0){
  2048 + t.setCzyl(0.0);
  2049 + }
  2050 + if(t.getYh()<0){
  2051 + t.setYh(0.0);
  2052 + }
  2053 + if(t.getSh()<0){
  2054 + t.setSh(0.0);
  2055 + }
  2056 + repository.save(t);
  2057 + }
  2058 + }
  2059 + }
  2060 +
  2061 + //重新统计油车数据结束
  2062 +
  2063 +
  2064 + //重新获取电耗数据开始
  2065 + Map<String, List<Dlb>> mapList=dlbService.updeteHistory(listpbDc, date, gsdm, fgsdm, line);
  2066 + List<Dlb> delDlb=mapList.get("delList");
  2067 + for (int i = 0; i < delDlb.size(); i++) {
  2068 + Dlb d=delDlb.get(i);
  2069 + dlbRepository.deleteById(d.getId());
  2070 + }
  2071 + List<Dlb> updDlb=mapList.get("updList");
  2072 + for (int i = 0; i < updDlb.size(); i++) {
  2073 + Dlb d=updDlb.get(i);
  2074 + try {
  2075 + dlbRepository.save(d);
  2076 + } catch (Exception e) {
  2077 + // TODO: handle exception
  2078 + if(e.getMessage().indexOf("PK_DLB_UK")>0){
  2079 + newMap.put("fage", "存在相同数据,数据已经过滤");
  2080 + logger.info("电量存在相同数据,数据已经过滤");
  2081 + }
  2082 + }
  2083 + }
  2084 + //重新获取电耗数据结束
  2085 +
  2086 + SysUser user = SecurityUtils.getCurrentUser();
  2087 + Nylog nylog=new Nylog();
  2088 + nylog.setCreatedate(new Date());
  2089 + nylog.setCzmc("重新统计");
  2090 + nylog.setNylx("油");
  2091 + nylog.setUserid(user.getUserName());
  2092 + nylog.setUsername(user.getName());
  2093 + nylog.setCxtj(line+"-"+ date+"-"+gsdm+"-"+fgsdm);
  2094 + nylogRepository.save(nylog);
  2095 + newMap.put("status", ResponseCode.SUCCESS);
  2096 + }catch(Exception e){
  2097 + // TODO Auto-generated catch block
  2098 + newMap.put("status", ResponseCode.ERROR);
  2099 + throw e;
  2100 + }
  2101 +
  2102 +
  2103 + return newMap;
  2104 + }
  2105 +
  2106 + public List<Ylb> listByRqJcsx(String rq,String gsdm,String fgsdm,String xlbm,String nbbm) {
  2107 + List<Ylb> list=repository.listByRqJcsx(rq, gsdm, fgsdm, xlbm, nbbm);
  2108 + Map<String, Object> m=new HashMap<String,Object>();
  2109 + List<Ylb> list_=new ArrayList<Ylb>();
  2110 + for (int i = 0; i < list.size(); i++) {
  2111 + Ylb t=list.get(i);
  2112 + if(m.get(t.getNbbm())==null){
  2113 + m.put(t.getNbbm(), t.getNbbm());
  2114 + list_.add(t);
  2115 + }
  2116 + }
  2117 + return list_;
  2118 + }
  2119 +
  2120 + @Override
  2121 + public Map<String, Object> update(Map<String, Object> map) {
  2122 + if(map.get("id")!=null){
  2123 + if(map.get("id").toString().length()>0){
  2124 + Integer id=Integer.parseInt(map.get("id").toString());
  2125 + String jsy=map.get("jsy").toString();
  2126 + Ylb t=repository.findById(id).get();
  2127 + t.setJsy(jsy);
  2128 + repository.save(t);
  2129 + map.put("status", ResponseCode.SUCCESS);
  2130 + }
  2131 + }
  2132 + return map;
  2133 + }
  2134 +}
... ...
src/main/java/com/bsth/service/report/ReportService.java
... ... @@ -20,7 +20,7 @@ public interface ReportService {
20 20 List<Map<String, Object>> queryInOutStrtion(String line,String date,int zd,String lzsj);
21 21  
22 22 List<Map<String, Object>> queryInOutStrtions(String line,String date,int zd,String lzsj);
23   - List<Map<String, String>> sreachZd(String line,int zdlx);
  23 + List<Map<String, String>> sreachZd(String line,int zdlx, String date1, String date2);
24 24  
25 25 List<Object[]> historyMessageCount(String line, String date, String code);
26 26 List<Object[]> historyMessageList(String line, String date, String code,String type);
... ...
src/main/java/com/bsth/service/report/impl/ReportServiceImpl.java
... ... @@ -4,7 +4,6 @@ import com.bsth.data.BasicData;
4 4 import com.bsth.entity.Line;
5 5 import com.bsth.entity.Personnel;
6 6 import com.bsth.entity.StationRoute;
7   -import com.bsth.entity.calc.CalcStatistics;
8 7 import com.bsth.entity.excep.ArrivalInfo;
9 8 import com.bsth.entity.mcy_forms.Singledata;
10 9 import com.bsth.entity.oil.Dlb;
... ... @@ -14,6 +13,7 @@ import com.bsth.entity.realcontrol.ScheduleRealInfo;
14 13 import com.bsth.entity.sys.Dictionary;
15 14 import com.bsth.entity.sys.Interval;
16 15 import com.bsth.repository.LineRepository;
  16 +import com.bsth.repository.LsStationRouteRepository;
17 17 import com.bsth.repository.StationRouteRepository;
18 18 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
19 19 import com.bsth.service.LineService;
... ... @@ -74,6 +74,8 @@ public class ReportServiceImpl implements ReportService{
74 74 @Autowired
75 75 StationRouteRepository stationRouteRepository;
76 76 @Autowired
  77 + LsStationRouteRepository lsStationRouteRepository;
  78 + @Autowired
77 79 CulateMileageService culateMileageService;
78 80 @Autowired
79 81 DictionaryService dictionaryService;
... ... @@ -285,74 +287,24 @@ public class ReportServiceImpl implements ReportService{
285 287 return list;
286 288 }
287 289 @Override
288   - public List<Map<String, String>> sreachZd(String line, int zdlx) {
  290 + public List<Map<String, String>> sreachZd(String line, int zdlx, String date1, String date2) {
289 291 List<Map<String, String>> list = new ArrayList<>();
290 292 // TODO Auto-generated method stub
291   -
292   - List<StationRoute> listSr = stationRoutRepository.findAllByLine(line, zdlx);
293   - List<String> temp0List = new ArrayList<String>(),
294   - temp1List = new ArrayList<String>();
295   - Map<String, List<String>> temp0 = new HashMap<String, List<String>>();
296   - Map<String, List<String>> temp1 = new HashMap<String, List<String>>();
297   - for(StationRoute sr : listSr){
298   - String stationCode = sr.getStationCode().trim();
299   - String stationName = sr.getStationName().trim();
300   - if(sr.getDestroy() == 0){
301   - if(!temp0.containsKey(stationName)){
302   - temp0.put(stationName, new ArrayList<String>());
303   - temp0List.add(stationName);
  293 + if(date1.length() >= 10 && date1.length() >= 10){
  294 + date1 = date1.substring(0, 10);
  295 + date2 = date2.substring(0, 10);
  296 + List<Object[]> findHistory = lsStationRouteRepository.findHistory(line, zdlx, date1, date2);
  297 + Set<String> tempSet = new HashSet<String>();
  298 + for(Object[] obj : findHistory){
  299 + if(obj[2] != null && obj[2].toString().trim().length() > 0){
  300 + tempSet.add(obj[2].toString().trim());
304 301 }
305   - temp0.get(stationName).add(stationCode);
306   - } else if(sr.getDestroy() == 1){
307   - if(!temp1.containsKey(stationName)){
308   - temp1.put(stationName, new ArrayList<String>());
309   - temp1List.add(stationName);
310   - }
311   - temp1.get(stationName).add(stationCode);
312 302 }
313   - }
314   -
315   - Set<String> keySet = temp0.keySet();
316   - for(String key : temp0List){
317   - Map<String, String> reMap = new HashMap<String, String>();
318   - String stationCode_s = "";
319   - List<String> list0 = temp0.get(key);
320   - for(String sc : list0){
321   - if(stationCode_s.length() > 0)
322   - stationCode_s += ",";
323   - stationCode_s += sc;
324   - }
325   - if(temp1.containsKey(key)){
326   - List<String> list1 = temp1.get(key);
327   - String sc1 = "";
328   - for(String sc : list1){
329   - if(sc1.length() > 0)
330   - sc1 += ",";
331   - sc1 += sc;
332   - }
333   - if(sc1.length() > 0 && stationCode_s.length() > 0){
334   - stationCode_s = sc1 + "," + stationCode_s;
335   - } else {
336   - stationCode_s = sc1 + stationCode_s;
337   - }
338   - }
339   - reMap.put("id", stationCode_s);
340   - reMap.put("text", key);
341   - list.add(reMap);
342   - }
343   -
344   - for(String key : temp1List){
345   - if(!(keySet.contains(key))){
  303 + for(Object[] obj : findHistory){
  304 + int length = tempSet.toArray().length;
346 305 Map<String, String> reMap = new HashMap<String, String>();
347   - String stationCode_s = "";
348   - List<String> list1 = temp1.get(key);
349   - for(String sc : list1){
350   - if(stationCode_s.length() > 0)
351   - stationCode_s += ",";
352   - stationCode_s += sc;
353   - }
354   - reMap.put("id", stationCode_s);
355   - reMap.put("text", key + " (历史)");
  306 + reMap.put("id", obj[0].toString());
  307 + reMap.put("text", obj[1] + (length > 1 ? (" -版本" + obj[2]) : ""));
356 308 list.add(reMap);
357 309 }
358 310 }
... ...
src/main/resources/static/pages/forms/budget/budgetAmounts.html
... ... @@ -269,6 +269,39 @@
269 269 params['type'] = "query";
270 270 var i = layer.load(2);
271 271 $post('/budget/budgetAmounts',params,function(result){
  272 +// $(result).each(function(ii, ee){
  273 +// for(var kk in ee){
  274 +// if(kk != "key" && kk != "dataList" && kk.indexOf("com") < 0 && parseFloat(ee[kk])){
  275 +// var bb = "", cc = ee[kk] + "";
  276 +// if(cc.indexOf("%") > -1){
  277 +// bb = "%";
  278 +// }
  279 +// var dd = 0;
  280 +// $(ee.dataList).each(function(jj, ff){
  281 +// if(parseFloat(ff[kk])){
  282 +// dd += parseFloat(ff[kk]);
  283 +// }
  284 +// });
  285 +// var aa = parseFloat(dd);
  286 +// ee[kk] = parseFloat(aa.toFixed(3))+bb;
  287 +// }
  288 +// }
  289 +// for(var yy = 0; yy <= 12; yy++){
  290 +// var mon = "mon"+yy, bud = "bud"+yy, com = "com"+yy;
  291 +// if(yy == 0){
  292 +// mon = "monAll";
  293 +// bud = "formal";
  294 +// com = "complete";
  295 +// }
  296 +// if(ee[mon] > 0 && parseFloat(ee[mon]) && parseFloat(ee[bud])){
  297 +// var comV = (parseFloat(ee[mon]) / parseFloat(ee[bud]) * 100).toFixed(2) + "%";
  298 +// ee[com] = comV;
  299 +// } else {
  300 +// ee[com] = "0%";
  301 +// }
  302 +
  303 +// }
  304 +// });
272 305 layer.close(i);
273 306 // 把数据填充到模版中
274 307 var tbodyHtml = template('budget_amounts',{list:result});
... ... @@ -292,6 +325,18 @@
292 325 $.each(resList, function(i, g){
293 326 if(key == g.key){
294 327 var dataList = g.dataList;
  328 +// $(dataList).each(function(ii, ee){
  329 +// for(var kk in ee){
  330 +// if(kk != "xlName" && parseFloat(ee[kk])){
  331 +// var bb = "", cc = ee[kk] + "";
  332 +// if(cc.indexOf("%") > -1){
  333 +// bb = "%";
  334 +// }
  335 +// var aa = parseFloat(ee[kk]);
  336 +// ee[kk] = parseFloat(aa.toFixed(3))+bb;
  337 +// }
  338 +// }
  339 +// });
295 340 var tbodyHtml = template('budget_amounts_dataList', {list:dataList});
296 341 $("#datas_hidden").removeClass("hidden");
297 342 $("#datas_hidden").height($(window).height()-280);
... ...
src/main/resources/static/pages/forms/budget/budgetMileage.html
... ... @@ -267,6 +267,39 @@
267 267 params['type'] = "query";
268 268 var i = layer.load(2);
269 269 $post('/budget/budgetMileage',params,function(result){
  270 +// $(result).each(function(ii, ee){
  271 +// for(var kk in ee){
  272 +// if(kk != "key" && kk != "dataList" && kk.indexOf("com") < 0 && parseFloat(ee[kk])){
  273 +// var bb = "", cc = ee[kk] + "";
  274 +// if(cc.indexOf("%") > -1){
  275 +// bb = "%";
  276 +// }
  277 +// var dd = 0;
  278 +// $(ee.dataList).each(function(jj, ff){
  279 +// if(parseFloat(ff[kk])){
  280 +// dd += parseFloat(ff[kk]);
  281 +// }
  282 +// });
  283 +// var aa = parseFloat(dd);
  284 +// ee[kk] = parseFloat(aa.toFixed(3))+bb;
  285 +// }
  286 +// }
  287 +// for(var yy = 0; yy <= 12; yy++){
  288 +// var mon = "mon"+yy, bud = "bud"+yy, com = "com"+yy;
  289 +// if(yy == 0){
  290 +// mon = "monAll";
  291 +// bud = "formal";
  292 +// com = "complete";
  293 +// }
  294 +// if(ee[mon] > 0 && parseFloat(ee[mon]) && parseFloat(ee[bud])){
  295 +// var comV = (parseFloat(ee[mon]) / parseFloat(ee[bud]) * 100).toFixed(2) + "%";
  296 +// ee[com] = comV;
  297 +// } else {
  298 +// ee[com] = "0%";
  299 +// }
  300 +
  301 +// }
  302 +// });
270 303 layer.close(i);
271 304 // 把数据填充到模版中
272 305 var tbodyHtml = template('budget_mileage',{list:result});
... ... @@ -290,6 +323,18 @@
290 323 $.each(resList, function(i, g){
291 324 if(key == g.key){
292 325 var dataList = g.dataList;
  326 +// $(dataList).each(function(ii, ee){
  327 +// for(var kk in ee){
  328 +// if(kk != "xlName" && parseFloat(ee[kk])){
  329 +// var bb = "", cc = ee[kk] + "";
  330 +// if(cc.indexOf("%") > -1){
  331 +// bb = "%";
  332 +// }
  333 +// var aa = parseFloat(ee[kk]);
  334 +// ee[kk] = parseFloat(aa.toFixed(3))+bb;
  335 +// }
  336 +// }
  337 +// });
293 338 var tbodyHtml = template('budget_mileage_dataList', {list:dataList});
294 339 $("#datas_hidden").removeClass("hidden");
295 340 $("#datas_hidden").height($(window).height()-280);
... ...
src/main/resources/static/pages/forms/budget/budgetPerson.html
... ... @@ -267,6 +267,39 @@
267 267 params['type'] = "query";
268 268 var i = layer.load(2);
269 269 $post('/budget/budgetPerson',params,function(result){
  270 +// $(result).each(function(ii, ee){
  271 +// for(var kk in ee){
  272 +// if(kk != "key" && kk != "dataList" && kk.indexOf("com") < 0 && parseFloat(ee[kk])){
  273 +// var bb = "", cc = ee[kk] + "";
  274 +// if(cc.indexOf("%") > -1){
  275 +// bb = "%";
  276 +// }
  277 +// var dd = 0;
  278 +// $(ee.dataList).each(function(jj, ff){
  279 +// if(parseFloat(ff[kk])){
  280 +// dd += parseFloat(ff[kk]);
  281 +// }
  282 +// });
  283 +// var aa = parseFloat(dd);
  284 +// ee[kk] = parseFloat(aa.toFixed(3))+bb;
  285 +// }
  286 +// }
  287 +// for(var yy = 0; yy <= 12; yy++){
  288 +// var mon = "mon"+yy, bud = "bud"+yy, com = "com"+yy;
  289 +// if(yy == 0){
  290 +// mon = "monAll";
  291 +// bud = "formal";
  292 +// com = "complete";
  293 +// }
  294 +// if(ee[mon] > 0 && parseFloat(ee[mon]) && parseFloat(ee[bud])){
  295 +// var comV = (parseFloat(ee[mon]) / parseFloat(ee[bud]) * 100).toFixed(2) + "%";
  296 +// ee[com] = comV;
  297 +// } else {
  298 +// ee[com] = "0%";
  299 +// }
  300 +
  301 +// }
  302 +// });
270 303 layer.close(i);
271 304 // 把数据填充到模版中
272 305 var tbodyHtml = template('budget_person',{list:result});
... ... @@ -290,6 +323,18 @@
290 323 $.each(resList, function(i, g){
291 324 if(key == g.key){
292 325 var dataList = g.dataList;
  326 +// $(dataList).each(function(ii, ee){
  327 +// for(var kk in ee){
  328 +// if(kk != "xlName" && parseFloat(ee[kk])){
  329 +// var bb = "", cc = ee[kk] + "";
  330 +// if(cc.indexOf("%") > -1){
  331 +// bb = "%";
  332 +// }
  333 +// var aa = parseFloat(ee[kk]);
  334 +// ee[kk] = parseFloat(aa.toFixed(3))+bb;
  335 +// }
  336 +// }
  337 +// });
293 338 var tbodyHtml = template('budget_person_dataList', {list:dataList});
294 339 $("#datas_hidden").removeClass("hidden");
295 340 $("#datas_hidden").height($(window).height()-280);
... ...
src/main/resources/static/pages/forms/budget/budgetSum.html
... ... @@ -277,6 +277,39 @@
277 277 params['type'] = "query";
278 278 var i = layer.load(2);
279 279 $post('/budget/budgetSum',params,function(result){
  280 +// $(result).each(function(ii, ee){
  281 +// for(var kk in ee){
  282 +// if(kk != "key" && kk != "dataList" && kk.indexOf("com") < 0 && parseFloat(ee[kk])){
  283 +// var bb = "", cc = ee[kk] + "";
  284 +// if(cc.indexOf("%") > -1){
  285 +// bb = "%";
  286 +// }
  287 +// var dd = 0;
  288 +// $(ee.dataList).each(function(jj, ff){
  289 +// if(parseFloat(ff[kk])){
  290 +// dd += parseFloat(ff[kk]);
  291 +// }
  292 +// });
  293 +// var aa = parseFloat(dd);
  294 +// ee[kk] = parseFloat(aa.toFixed(3))+bb;
  295 +// }
  296 +// }
  297 +// for(var yy = 0; yy <= 12; yy++){
  298 +// var mon = "mon"+yy, bud = "bud"+yy, com = "com"+yy;
  299 +// if(yy == 0){
  300 +// mon = "monAll";
  301 +// bud = "formal";
  302 +// com = "complete";
  303 +// }
  304 +// if(ee[mon] > 0 && parseFloat(ee[mon]) && parseFloat(ee[bud])){
  305 +// var comV = (parseFloat(ee[mon]) / parseFloat(ee[bud]) * 100).toFixed(2) + "%";
  306 +// ee[com] = comV;
  307 +// } else {
  308 +// ee[com] = "0%";
  309 +// }
  310 +
  311 +// }
  312 +// });
280 313 layer.close(i);
281 314 // 把数据填充到模版中
282 315 var tbodyHtml = template('budget_sum',{list:result});
... ... @@ -300,6 +333,18 @@
300 333 $.each(resList, function(i, g){
301 334 if(key == g.key){
302 335 var dataList = g.dataList;
  336 +// $(dataList).each(function(ii, ee){
  337 +// for(var kk in ee){
  338 +// if(kk != "xlName" && parseFloat(ee[kk])){
  339 +// var bb = "", cc = ee[kk] + "";
  340 +// if(cc.indexOf("%") > -1){
  341 +// bb = "%";
  342 +// }
  343 +// var aa = parseFloat(ee[kk]);
  344 +// ee[kk] = parseFloat(aa.toFixed(3))+bb;
  345 +// }
  346 +// }
  347 +// });
303 348 var tbodyHtml = template('budget_sum_dataList', {list:dataList});
304 349 $("#datas_hidden").removeClass("hidden");
305 350 $("#datas_hidden").height($(window).height()-280);
... ...
src/main/resources/static/pages/forms/export/import_budget.xls
No preview for this file type
src/main/resources/static/pages/report/inoutstation.html
... ... @@ -67,7 +67,7 @@
67 67 <input class="form-control" type="text" id="date2" style="width: 180px;"/>
68 68 <span class="item-label" style="width: 80px;">站点: </span>
69 69 <select class="form-control sreach-zd" id="zdlx" >
70   - <option value="">请选择</option>
  70 + <option value=" ">请选择</option>
71 71 <option value="0">上行</option>
72 72 <option value="1">下行</option>
73 73 </select>
... ... @@ -188,6 +188,19 @@
188 188 locale : 'zh-cn'
189 189 });
190 190  
  191 + var d = new Date();
  192 + d.setTime(d.getTime());
  193 + var year = d.getFullYear();
  194 + var month = d.getMonth() + 1;
  195 + var day = d.getDate();
  196 + if(month < 10)
  197 + month = "0" + month;
  198 + if(day < 10)
  199 + day = "0" + day;
  200 + var dt = year + "-" + month + "-" + day;
  201 + $("#date").val(dt);
  202 + $("#date1,#date2").val(dt + " 00:00");
  203 +
191 204  
192 205 /* $.get('/basic/lineCode2Name',function(result){
193 206 var data=[];
... ... @@ -444,22 +457,26 @@
444 457 });
445 458 }
446 459 })
  460 +
447 461 $(".sreach-zd").on("change",initZd);
  462 + $("#date1,#date2").on("blur",initZd);
448 463 var status=false;
449 464  
450 465 function initZd(){
451 466 var line = $("#line").val();
452 467 var zdlx = $("#zdlx").val();
453   - console.log(line+"===="+zdlx);
454   - if(line==null|| line =="" || zdlx ==null || zdlx==""){
  468 + var date1 = $("#date1").val();
  469 + var date2 = $("#date2").val();
  470 + if(line==null || line=="" || zdlx==null || zdlx==""
  471 + || date1==null || date1 =="" || date2==null || date2==""){
455 472 }else{
456   - $.get('/report/sreachZd',{line: line,zdlx:zdlx},function(result){
  473 + $.get('/report/sreachZd',{line:line,zdlx:zdlx,date1:date1,date2:date2},function(result){
457 474 var zdList=result;
458 475 if(status){
459 476 $("#zd").select2("destroy").html('');
460 477 }
461 478 var datas=[];
462   - datas.push({id:" ",text:"全部"});
  479 + datas.push({id:" ",text:"请选择..."});
463 480 for(var i=0;i<zdList.length;i++){
464 481 datas.push({id: zdList[i]["id"], text: zdList[i]["text"]});
465 482 }
... ...