Commit cbdc12e2d642e70a347f7a40f55c6724b97b18da

Authored by 王通
1 parent f7038746

1.修复历史修正班次时不同角色的日期范围问题

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