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