Commit 926f92c70a872fe9bf6b5796159a77eec73badb0

Authored by 娄高锋
1 parent 804f06f8

油电量计算保留三位小数;重新统计会删除电量表中混合动能车辆数据的问题,为解决生成环境中此问题故停用掉重新统计中的油电量重新统计功能;

Too many changes to show.

To preserve performance only 2 of 4 files are displayed.

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