QlbServiceImpl.java 40.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
package com.bsth.service.oil.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.data.BasicData;
import com.bsth.entity.Cars;
import com.bsth.entity.Line;
import com.bsth.entity.oil.Jql;
import com.bsth.entity.oil.Nylog;
import com.bsth.entity.oil.Qlb;
import com.bsth.entity.oil.Ylxxb;
import com.bsth.entity.sys.SysUser;
import com.bsth.repository.CarsRepository;
import com.bsth.repository.oil.JdlRepository;
import com.bsth.repository.oil.JqlRepository;
import com.bsth.repository.oil.NylogRepository;
import com.bsth.repository.oil.QlbRepository;
import com.bsth.repository.oil.YlxxbRepository;
import com.bsth.security.util.SecurityUtils;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.oil.QlbService;
import com.bsth.service.realcontrol.ScheduleRealInfoService;
import com.bsth.util.Arith;
import com.bsth.util.BatchSaveUtils;

@Service
public class QlbServiceImpl extends BaseServiceImpl<Qlb,Integer> implements QlbService{
	@Autowired
	QlbRepository repository;
	@Autowired
	NylogRepository nylogRepository;
	@Autowired
	YlxxbRepository ylxxbRepository;
	@Autowired
	JdlRepository jdlRepository;
	@Autowired
	JqlRepository jqlRepository;
	@Autowired
	CarsRepository carsRepository;
	@Autowired
	ScheduleRealInfoService scheduleRealInfoService;
	@Autowired
	JdbcTemplate jdbcTemplate;
	
	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Transactional
	@Override
	public String obtainDsq() throws Exception{
		String result = "failure";
		List<Cars> carsList=carsRepository.findCars();
		 Map<String, Boolean> carsMap=new HashMap<String, Boolean>();
		 for (int i = 0; i < carsList.size(); i++) {
			 Cars c=carsList.get(i);
			 carsMap.put(c.getInsideCode(), c.getHydrogen());
		}
		 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			Date dNow = new Date();   //当前时间
			Date dBefore = new Date();
			Calendar calendar = Calendar.getInstance(); //得到日历
			calendar.setTime(dNow);//把当前时间赋给日历
			calendar.add(Calendar.DAY_OF_MONTH, -1);  //设置为前一天
			dBefore = calendar.getTime();   //得到前一天的时间
			String rq=sdf.format(dBefore);
//		 String rq="2017-11-02";
		String line="";
		//保留两位小数
		DecimalFormat df = new DecimalFormat("#.000");
		// TODO Auto-generated method stub
		Map<String, Object> newMap=new HashMap<String,Object>();
		//当天QLB信息
		List<Qlb> qlList=repository.obtainQl(rq, "", "", line, "", "nbbm");
		//当天加氢信息表
		List<Jql> jqlList=jqlRepository.JqlList(rq);
		//前一天所有车辆最后进场班次信息
		List<Qlb> qlListBe=repository.obtainQlbefore(rq, "", "", "", "");
		//从排班表中计算出行驶的总里程
		List<Map<String,Object>> listpb=scheduleRealInfoService.yesterdayDataList(line,rq,"","","","");
		for(int x=0;x<listpb.size();x++){
			String type="add";
			boolean sfHydrogen=false;
			Map<String, Object> map=listpb.get(x);
			if (carsMap.get(map.get("clZbh").toString())!=null) {
				sfHydrogen = carsMap.get(map.get("clZbh").toString());
			}else{
				sfHydrogen = false;
			}
			if(sfHydrogen){
				//判断驾驶员驾驶的该车辆是否已经存入了(查出的结果集中日期是相同的,根据驾驶员、内部编号、线路编码判断)
				Qlb t=new Qlb();
				for(int k=0;k<qlList.size();k++){
					Qlb t1=qlList.get(k);
					if(t1.getNbbm().equals(map.get("clZbh").toString())
							&&t1.getJsy().equals(map.get("jGh").toString())
							&&t1.getXlbm().equals(map.get("xlBm").toString())
							&&t1.getLp().equals(map.get("lpName").toString()))
					{
						t=t1;
						type="update";
					}
				}
				try {
					//当日的第一个班次,出场油量等于前一天的最后一个班次的进场油量
					Double jzl=0.0;
					if(map.get("seqNumber").toString().equals("1")){
						boolean fage=true;
						for (int i = 0; i < qlListBe.size(); i++) {
							Qlb qlb=qlListBe.get(i);
							if(map.get("clZbh").toString().equals(qlb.getNbbm())){
								t.setCzcl(qlb.getJzcl());
								fage=false;
								break;
							}
						}
						if(fage){
							t.setCzcl(0.0);
						}
						
						//手动导入没有驾驶员工号
						for (int i = 0; i < jqlList.size(); i++) {
							Jql jql=jqlList.get(i);
							if(map.get("clZbh").toString().equals(jql.getNbbm()) 
									&&map.get("jGh").toString().equals(jql.getJsy())){
								jzl+=jql.getJql();
							}
						}
					}
					
					
//					//把当天的YLXXB的加注量设置为当天YLB的加注量(根据车号,驾驶员判断)
//					for(int j=0;j<ylxxList.size();j++){
//						Ylxxb ylxxb = ylxxList.get(j);
//						if(map.get("clZbh").toString().equals(ylxxb.getNbbm()) &&map.get("jGh").toString().equals(ylxxb.getJsy())){
//							jzl+=ylxxb.getJzl();
//						}
//					}
					
					t.setJql(jzl);
					if(type.equals("add")){
						t.setHn(jzl);
						t.setJzcl(t.getCzcl());
					}
					
					t.setNbbm(map.get("clZbh").toString());
					t.setJsy(map.get("jGh")==null?"":map.get("jGh").toString());
					t.setZlc(map.get("totalKilometers")==null?0.0:Double.parseDouble(df.format(Double.parseDouble(map.get("totalKilometers").toString()))));
					t.setXlbm(map.get("xlBm")==null?"":map.get("xlBm").toString());
					t.setLinename(map.get("lineName")==null?"":map.get("lineName").toString());
					t.setJcsx(Integer.parseInt(map.get("seqNumber").toString()));
					t.setSsgsdm(map.get("company")==null?"":map.get("company").toString());
					t.setFgsdm(map.get("bCompany")==null?"":map.get("bCompany").toString());
					t.setJhsj(map.get("fcsj")==null?"":map.get("fcsj").toString());
					t.setLp(map.get("lpName").toString());
					t.setRq(sdf.parse(rq));
					t.setCreatetime(new Date());
					t.setJname(map.get("jName").toString());
					repository.save(t);
					newMap.put("status", ResponseCode.SUCCESS);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					newMap.put("status", ResponseCode.ERROR);
					e.printStackTrace();
				}
			}
		}
		return result;
	}
	
	/**
	 * 获取进存油信息
	 * @Transactional 回滚事物
	 */
	@Transactional  
	@Override
	public Map<String, Object> obtain(Map<String, Object> map2) throws Exception{
		Map<String, Object> newMap = new HashMap<String, Object>();
		try {
			Date date=new Date();
			List<Cars> carsList = carsRepository.findCars();
			Map<String, Boolean> carsMap = new HashMap<String, Boolean>();
			for (int i = 0; i < carsList.size(); i++) {
				Cars c = carsList.get(i);
				carsMap.put(c.getInsideCode(), c.getHydrogen());
			}
			String rq = map2.get("rq").toString();
			String line = "";
			if (map2.get("xlbm_like") != null) {
				line = map2.get("xlbm_like").toString().trim();
			}
			String gsbm="";
			if(map2.get("ssgsdm_like")!=null){
				gsbm=map2.get("ssgsdm_like").toString();
			}
			String fgsbm="";
			if(map2.get("fgsdm_like")!=null){
				fgsbm=map2.get("fgsdm_like").toString();
			}
			String nbbm="";
			if(map2.get("nbbm_eq")!=null){
				nbbm=map2.get("nbbm_eq").toString();
			}
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			// 保留两位小数
			DecimalFormat df = new DecimalFormat("#.000");
			// TODO Auto-generated method stub
			// 当天QLB信息
			List<Qlb> qlList = this.listOrderBy(rq,gsbm,fgsbm,"",nbbm,"nbbm");
			// 从排班表中计算出行驶的总里程
			List<Map<String, Object>> listpb =new ArrayList<Map<String, Object>>();
			List<Map<String, Object>> listpbs=scheduleRealInfoService.yesterdayDataList("", rq, gsbm, fgsbm, "", nbbm);
		    Map<String, Double> lcMap=new HashMap<String,Double>();
			for (int i = 0; i < listpbs.size(); i++) {
				String cl=listpbs.get(i).get("clZbh").toString();
				Double lc=listpbs.get(i).get("totalKilometers") == null ? 0.0
						: Double.parseDouble(listpbs.get(i).get("totalKilometers").toString());
				if(lcMap.get(cl)==null){
					lcMap.put(cl, lc);
				}else{
					double lc_=lcMap.get(cl);
					lcMap.remove(cl);
					lcMap.put(cl, Arith.add(lc, lc_));
				}
			}
			
			List<Jql> jqlList=jqlRepository.JqlList(rq);
			String sxtj=map2.get("sxtj").toString();
			if(sxtj.equals("0")){
				listpb=listpbs;
			}else{
				List<Object[]> objectLists=repository.checkNbmmNum(rq, gsbm, fgsbm, "", nbbm);
				List<String> stringList=new ArrayList<String>();
				for (int i = 0; i < objectLists.size(); i++) {
					String clbm=objectLists.get(i)[0].toString();
					int cs=Integer.parseInt(objectLists.get(i)[1].toString());
					//一车一单
					if(sxtj.equals("1")){
						if(cs==1){
							stringList.add(clbm);
						}
					}	
					//一车多单
					if(sxtj.equals("2")){
						if(cs>1){
							stringList.add(clbm);
						}
					}
				}
				
				for (int i = 0; i < stringList.size(); i++) {
					String strNbbm=stringList.get(i);
					for (int j = 0; j < listpbs.size(); j++) {
						Map<String, Object> map = listpbs.get(j);
						String mapNbbm=map.get("clZbh").toString();
						if(strNbbm.equals(mapNbbm)){
							listpb.add(map);
						}
					}
				}
			}
			Map<String, Object> newMap_=new HashMap<String,Object>();
			List<Qlb> addList = new ArrayList<Qlb>();
			List<Qlb> updateList = new ArrayList<Qlb>();
			Map<String, Object> cMap=new HashMap<String, Object>();
			List<Map<String, Object>> listpb_=listpb;
			Collections.sort(listpb,new NbbmJcsxMap2());
			for (int x = 0; x < listpb_.size(); x++) {
				String type = "add";
				boolean sfHydrogen = false;
				Map<String, Object> map_ = listpb_.get(x);
				if (carsMap.get(map_.get("clZbh").toString()) != null) {
					sfHydrogen = carsMap.get(map_.get("clZbh").toString());
				} else {
					sfHydrogen = false;
				}
				if (sfHydrogen) {
					if(newMap_.get(map_.get("clZbh").toString())==null){
						newMap_.put(map_.get("clZbh").toString(), map_.get("clZbh").toString());
						//车辆总里程
						double zlc =lcMap.get(map_.get("clZbh").toString());
						//车辆总加氢量
						double zjzl = 0.0;
//						for (int j = 0; j < ylxxList.size(); j++) {
//							Ylxxb ylxxb = ylxxList.get(j);
//							if (map_.get("clZbh").toString().equals(ylxxb.getNbbm())
//									&& map_.get("company").toString().equals(ylxxb.getGsdm())) {
//								zjzl = Arith.add(zjzl, ylxxb.getJzl());
//							}
//						}
						for (int i = 0; i < jqlList.size(); i++) {
							Jql jql=jqlList.get(i);
							if(map_.get("clZbh").toString().equals(jql.getNbbm()) 
									&&map_.get("company").toString().equals(jql.getGsBm())
									&&map_.get("bCompany").toString().equals(jql.getFgsBm())){
								zjzl = Arith.add(zjzl,jql.getJql());
							}
						}
						Double nextJzyl = 0.0;
						for (int i = 0; i < listpb.size(); i++) {
							Map<String, Object> map = listpb.get(i);
							if(map_.get("clZbh").toString().equals(map.get("clZbh").toString())){
								// 判断驾驶员驾驶的该车辆是否已经存入了(查出的结果集中日期是相同的,根据驾驶员、内部编号、线路编码判断)
								Qlb t = new Qlb();
								for (int k = 0; k < qlList.size(); k++) {
									Qlb t1 = qlList.get(k);
									if (t1.getNbbm().equals(map.get("clZbh").toString())
											&& t1.getJsy().equals(map.get("jGh").toString())
											&& t1.getXlbm().equals(map.get("xlBm").toString())) {
										if(t1.getLp()==null){
											//同人同车同线路不同路牌的过滤  (考虑到历史数据)
											if (cMap.get(map.get("clZbh").toString()+map.get("jGh").toString()+map.get("xlBm").toString())==null) {
												t = t1;
												type = "update";
												cMap.put(map.get("clZbh").toString()+map.get("jGh").toString()+map.get("xlBm").toString(),
														map.get("clZbh").toString());
											}
										}else{
											if(t1.getLp().equals(map.get("lpName").toString())){
												t = t1;
												type = "update";
											}
											
										}
									}
								}
								Double lc= Double.parseDouble(map.get("totalKilometers").toString());
								if(map.get("seqNumber").toString().equals("1")){
									// 当日的第一个班次,出场油量等于前一天的最后一个班次的进场油量
									Double dh=0.0;
									if(zlc>0){
										dh = Double.parseDouble(df.format(zjzl * (lc / zlc)));
									}
									nextJzyl =Arith.sub(zjzl,dh);
									if(zlc>0){
//										long l=Math.round(nextJzyl);
										double ylxs=nextJzyl;
										dh=Arith.add(dh, Arith.sub(nextJzyl,ylxs));
										if(dh<0){
											t.setHn(0.0);
											t.setJql(0.0);
											nextJzyl=Arith.add(ylxs, dh);
										}else{
											t.setHn(dh);
											t.setJql(dh);
											nextJzyl=ylxs;
										}
									}else{
										t.setHn(0.0);
										t.setJql(0.0);
									}
								}else{
									Double dh=0.0;
									if(zlc>0){
										dh = Double.parseDouble(df.format(zjzl * (lc / zlc)));
									}
									nextJzyl =Arith.sub( nextJzyl,dh);
									if(zlc>0){
//										long l=0l;
										double ylxs=0.0;
										if(i==listpb.size()-1){
//											ylxs=czyl;
										}else{
											if(listpb.get(i+1).get("clZbh").toString().equals(map.get("clZbh").toString())){
//												l=Math.round(nextJzyl);
												ylxs=nextJzyl;
											}
											
										}
										dh=Arith.add(dh, Arith.sub(nextJzyl,ylxs));
										if(dh<0){
											t.setHn(0.0);
											t.setJql(0.0);
											nextJzyl=Arith.add(ylxs, dh);
										}else{
											t.setHn(dh);
											t.setJql(dh);
											nextJzyl=ylxs;
										}
									}else{
										t.setHn(0.0);
										t.setJql(0.0);
									}
								}
								t.setCzcl(100.0);
								t.setJzcl(100.0);
								t.setNbbm(map.get("clZbh").toString());
								t.setJsy(map.get("jGh") == null ? "" : map.get("jGh").toString());
								t.setZlc(map.get("totalKilometers") == null ? 0.0
										: Double.parseDouble(map.get("totalKilometers").toString()));
								t.setXlbm(map.get("xlBm") == null ? "" : map.get("xlBm").toString());
								t.setLinename(map.get("lineName")==null?"":map.get("lineName").toString());
								t.setJcsx(Integer.parseInt(map.get("seqNumber").toString()));
								t.setSsgsdm(map.get("company") == null ? "" : map.get("company").toString());
								t.setFgsdm(map.get("bCompany") == null ? "" : map.get("bCompany").toString());
								t.setJhsj(map.get("fcsj")==null?"":map.get("fcsj").toString());
								t.setRq(sdf.parse(rq));
								t.setLp(map.get("lpName").toString());
								t.setJname(map.get("jName").toString());
								if (!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))) {
									if (t.getHn() < 0) {
										t.setHn(0.0);
									}
									if (t.getJql() < 0) {
										t.setJql(0.0);
									}
									if (type.equals("add")) {
										t.setCreatetime(date);
										addList.add(t);
									} else {
										t.setUpdatetime(date);
										updateList.add(t);
									}
								}
								newMap.put("status", ResponseCode.SUCCESS);
							}
						}
					}
				}
			}
			if(addList.size()>0){ 
				try {
					new BatchSaveUtils<Qlb>().saveList2(addList, Qlb.class); 
				} catch (Exception e) {
					// TODO: handle exception
					if(e.getMessage().indexOf("PK_QLB_UK")>0){
						newMap.put("fage", "存在相同数据,数据已经过滤");
						logger.info("获取:存在相同数据,数据已经过滤");
					}
				}
				
			}
			
			if(updateList.size()>0){
				for (int i = 0; i < updateList.size(); i++) {
					repository.save(updateList.get(i));
				}
			}
			SysUser user = SecurityUtils.getCurrentUser();
			Nylog nylog=new Nylog();
			nylog.setCreatedate(new Date());
			nylog.setCzmc("获取");
			nylog.setNylx("氢");
			nylog.setUserid(user.getUserName());
			nylog.setUsername(user.getName());
			nylog.setCxtj(line+"-"+ date+"-"+gsbm+"-"+fgsbm);
			nylogRepository.save(nylog);
			newMap.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			newMap.put("status", ResponseCode.ERROR);
			throw e;
		}

		return newMap;
	}
	
	/**
	 * 拆分
	 */
	@Transactional  
	@Override
	public Map<String, Object> sort(Map<String, Object> map) {
		// TODO Auto-generated method stub
		Map<String, Object> newMap = new HashMap<String, Object>();
		try{
			int id=Integer.parseInt(map.get("id").toString());
			//最后存油量
			Double jzcl=Double.parseDouble(map.get("jzdl").toString());
			Double hn=Double.parseDouble(map.get("hdl").toString());
			Qlb qlb=repository.findById(id).get();
			qlb.setJzcl(jzcl);
			qlb.setHn(hn);
			repository.save(qlb);
			newMap.put("status", ResponseCode.SUCCESS);
		}catch(Exception e){
			newMap.put("status", ResponseCode.ERROR);
			logger.error("save erro.", e);
		}
		return newMap;
	}

	
	/**
	 * 核对,有加注没里程
	 * @param map
	 * @return
	 */
	@Transactional
	@Override
	public Map<String, Object> checkQl(Map<String, Object> map) {
		Map<String, Object> newMap=new HashMap<String,Object>();
		
		try{
			//获取车辆存油信息
			
			String rq=map.get("rq").toString();
			String xlbm="";
			if(map.get("xlbm_like")!=null){
				xlbm= map.get("xlbm_like").toString().trim();
			}
			String gsbm="";
			if(map.get("ssgsdm_like")!=null){
				gsbm=map.get("ssgsdm_like").toString();
			}
			String fgsbm="";
			if(map.get("fgsdm_like")!=null){
				fgsbm=map.get("fgsdm_like").toString();
			}
			String nbbm="";
			if(map.get("nbbm_eq")!=null){
				nbbm=map.get("nbbm_eq").toString();
			}
			
			String sql="select * from bsth_c_jql j where"
					+ " j.gs_bm = ? and j.fgs_bm = ? and rq = ? "
					+ " and nbbm not in (select nbbm from bsth_c_qlb d "
					+ " where ssgsdm = ? and fgsdm = ?  and rq = ?)";
			Object[] objects = {gsbm, fgsbm, rq, gsbm, fgsbm, rq};
			List<Jql> listJql=jdbcTemplate.query(sql,
					objects,
					new RowMapper<Jql>(){
				@Override
				public Jql mapRow(ResultSet rs, int rowNum) throws SQLException {
					Jql s  = new Jql();
					s.setNbbm(rs.getString("nbbm"));
					s.setGsBm(rs.getString("gs_bm"));
					s.setFgsBm(rs.getString("fgs_bm"));
					s.setJql(rs.getDouble("jql"));
					s.setRq(rs.getDate("rq"));
					return s;
				}
			});
			for (int i = 0; i < listJql.size(); i++) {
				Jql j=listJql.get(i);
				Qlb t=new Qlb();
				Line line = BasicData.nbbm2LineMap.get(j.getNbbm());
				if(null !=line){
					t.setJql(j.getJql());
					t.setNbbm(j.getNbbm());
					t.setRq(j.getRq());
					t.setJsy("");
					t.setJql(j.getJql());
					t.setSsgsdm(j.getGsBm());
					t.setFgsdm(j.getFgsBm());
					t.setJzcl(100.0);
					t.setCzcl(100.0);
					t.setHn(0.0);
					t.setJcsx(1);
					t.setXlbm(line.getLineCode());
					t.setLp("");
					repository.save(t);
				}
			}
			
			SysUser user = SecurityUtils.getCurrentUser();
			Nylog nylog=new Nylog();
			nylog.setCreatedate(new Date());
			nylog.setCzmc("核对");
			nylog.setNylx("氢");
			nylog.setUserid(user.getUserName());
			nylog.setUsername(user.getName());
			nylog.setCxtj(xlbm+"-"+ rq+"-"+gsbm+"-"+fgsbm);
			nylogRepository.save(nylog);
			newMap.put("status", ResponseCode.SUCCESS);
		}catch(Exception e){
			newMap.put("status", ResponseCode.ERROR);
			logger.error("save erro.", e);
			throw e;
		}
		
		return newMap;
	}

	@Override
	public List<Qlb> listQlb(Map<String, Object> map) {
		// TODO Auto-generated method stub
		List<Qlb> listQlb = new ArrayList<Qlb>();
		List<String> stringList = new ArrayList<String>();
		String rq = map.get("rq").toString();
		String gsbm = map.get("ssgsdm_like").toString();
		String fgsbm = map.get("fgsdm_like").toString();
		String xlbm = map.get("xlbm_like").toString().trim();
		String nbbm = map.get("nbbm_eq").toString();
		String sxtj = map.get("sxtj").toString();
		String type = map.get("type").toString();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			if (nbbm.trim() != "") {
				stringList.add(nbbm);
				if (type.equals("1"))
					listQlb = repository.listQlb(rq, gsbm, fgsbm, xlbm, stringList);
				else
					listQlb = repository.listQlb_s(sdf.parse(rq + " 00:00:00"), gsbm, fgsbm, xlbm, stringList);

			} else {
				// 全部
				if (sxtj.equals("0")) {
					List<Object[]> objectLists = repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm, nbbm);
					for (int i = 0; i < objectLists.size(); i++) {
						String clbm = objectLists.get(i)[0].toString();
						stringList.add(clbm);
					}
					if (stringList.size() > 0) {
						if (type.equals("1"))
							listQlb = repository.listQlb(rq, gsbm, fgsbm, xlbm, stringList);
						else
							listQlb = repository.listQlb_s(sdf.parse(rq + " 00:00:00"), gsbm, fgsbm, xlbm, stringList);
					}
				} else {
					List<Object[]> objectLists;
					if (sxtj.equals("3")) {
						// 有加油没里程
						objectLists = repository.checkNbmmQl(rq, gsbm, fgsbm, xlbm, nbbm);
						for (int i = 0; i < objectLists.size(); i++) {
							String clbm = objectLists.get(i)[0].toString();
							double jzl = Double.parseDouble(objectLists.get(i)[1].toString());
							double zlc = Double.parseDouble(objectLists.get(i)[2].toString());
							if (jzl > 0 && zlc <= 0) {
								stringList.add(clbm);
							}

						}

					} else if (sxtj.equals("4")) {
						// 有里程没加油
						objectLists = repository.checkNbmmQl(rq, gsbm, fgsbm, xlbm, nbbm);
						for (int i = 0; i < objectLists.size(); i++) {
							String clbm = objectLists.get(i)[0].toString();
							double jzl = Double.parseDouble(objectLists.get(i)[1].toString());
							double zlc = Double.parseDouble(objectLists.get(i)[2].toString());
							if (zlc > 0 && jzl <= 0) {
								stringList.add(clbm);
							}

						}
					} else {
						objectLists = repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm, nbbm);
						for (int i = 0; i < objectLists.size(); i++) {
							String clbm = objectLists.get(i)[0].toString();
							int cs = Integer.parseInt(objectLists.get(i)[1].toString());
							// 一车一单
							if (sxtj.equals("1")) {
								if (cs == 1) {
									stringList.add(clbm);
								}
							}
							// 一车多单
							if (sxtj.equals("2")) {
								if (cs > 1) {
									stringList.add(clbm);
								}
							}
						}
					}

					if (stringList.size() > 0) {
						if (type.equals("1"))
							listQlb = repository.listQlb(rq, gsbm, fgsbm, xlbm, stringList);
						else
							listQlb = repository.listQlb_s(sdf.parse(rq + " 00:00:00"), gsbm, fgsbm, xlbm, stringList);
					}
				}
			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return listQlb;
	}

	@Override
	public Map<String, Object> sumQlb(Map<String, Object> map) {
		// TODO Auto-generated method stub
		List<String> stringList = new ArrayList<String>();
		String rq = map.get("rq").toString();
		String gsbm = map.get("ssgsdm_like").toString();
		String fgsbm = map.get("fgsdm_like").toString();
		String xlbm = map.get("xlbm_like").toString().trim();
		String nbbm = map.get("nbbm_eq").toString();
		String sxtj = map.get("sxtj").toString();
		String type = map.get("type").toString();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		List<Object[]> sumQlbList = new ArrayList<Object[]>();
		try {
			if (nbbm.trim() != "") {
				stringList.add(nbbm);
			} else {
				if (!sxtj.equals("0")) {
					List<Object[]> objectLists;
					if (sxtj.equals("3")) {
						// 有加油没里程
						objectLists = repository.checkNbmmQl(rq, gsbm, fgsbm, xlbm, nbbm);
						for (int i = 0; i < objectLists.size(); i++) {
							String clbm = objectLists.get(i)[0].toString();
							double jzl = Double.parseDouble(objectLists.get(i)[1].toString());
							double zlc = Double.parseDouble(objectLists.get(i)[2].toString());
							if (jzl > 0 && zlc <= 0) {
								stringList.add(clbm);
							}

						}

					} else if (sxtj.equals("4")) {
						// 有里程没加油
						objectLists = repository.checkNbmmQl(rq, gsbm, fgsbm, xlbm, nbbm);
						for (int i = 0; i < objectLists.size(); i++) {
							String clbm = objectLists.get(i)[0].toString();
							double jzl = Double.parseDouble(objectLists.get(i)[1].toString());
							double zlc = Double.parseDouble(objectLists.get(i)[2].toString());
							if (zlc > 0 && jzl <= 0) {
								stringList.add(clbm);
							}

						}
					} else {
						objectLists = repository.checkNbmmNum(rq, gsbm, fgsbm, xlbm, nbbm);
						for (int i = 0; i < objectLists.size(); i++) {
							String clbm = objectLists.get(i)[0].toString();
							int cs = Integer.parseInt(objectLists.get(i)[1].toString());
							// 一车一单
							if (sxtj.equals("1")) {
								if (cs == 1) {
									stringList.add(clbm);
								}
							}
							// 一车多单
							if (sxtj.equals("2")) {
								if (cs > 1) {
									stringList.add(clbm);
								}
							}
						}
					}
				}
			}
			if (sxtj.equals("0")) {
				sumQlbList = repository.sumQlb2(rq, gsbm, fgsbm, xlbm, nbbm);
			} else {
				if (stringList.size() > 0) {
					if (type.equals("1"))
						sumQlbList = repository.sumQlb(rq, gsbm, fgsbm, xlbm, stringList);
					else
						sumQlbList = repository.sumQlb_s(sdf.parse(rq + " 00:00:00"), gsbm, fgsbm, xlbm, stringList);

				}
			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Double jzl = 0.0, yh = 0.0, sh = 0.0;
		for (int i = 0; i < sumQlbList.size(); i++) {
			jzl = Arith.add(jzl, Double.valueOf(sumQlbList.get(i)[0].toString()));
			yh = Arith.add(yh, Double.valueOf(sumQlbList.get(i)[1].toString()));
			sh = Arith.add(sh, Double.valueOf(sumQlbList.get(i)[2].toString()));
		}

		Map<String, Object> sumMap = new HashMap<String, Object>();
		sumMap.put("jzl", jzl);
		sumMap.put("yh", yh);
		sumMap.put("sh", sh);
		return sumMap;
	}
	
	
	@Transactional  
	@Override
	public Map<String, Object> saveQlbList(Map<String, Object> map) throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> newMap=new HashMap<String,Object>();
		try{
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		String json =StringEscapeUtils.unescapeHtml4(map.get("qlbList").toString());
		JSONArray jsonArray=JSONArray.parseArray(json);
		JSONObject jsonObject;
		for (int i = 0; i < jsonArray.size(); i++) {
			jsonObject=jsonArray.getJSONObject(i);
			double czcl = jsonObject.getDoubleValue("czcl");
//			double jql =jsonObject.getDoubleValue("jql");
			double jzcl =jsonObject.getDoubleValue("jzcl");
			double sh =jsonObject.getDoubleValue("sh");
			String shyy =jsonObject.getString("shyy");
			double hn = jsonObject.getDoubleValue("hn");
			int nhlx =jsonObject.getIntValue("nhlx");
			Integer id =jsonObject.getInteger("id");
			repository.qlbUpdate(id, czcl, jzcl, hn, sh, shyy, nhlx);
		
		}
		
		SysUser user = SecurityUtils.getCurrentUser();
		Nylog nylog=new Nylog();
		nylog.setCreatedate(new Date());
		nylog.setCzmc("保存全部");
		nylog.setNylx("氢");
		nylog.setUserid(user.getUserName());
		nylog.setUsername(user.getName());
		nylog.setCxtj("");
		nylogRepository.save(nylog);
		newMap.put("status", ResponseCode.SUCCESS);
		}catch(Exception e){
			newMap.put("status", ResponseCode.ERROR);
			logger.error("save erro.", e);
			throw e;
		}
		return newMap;
	}
	
	public  List<Qlb> listOrderBy(String rq,String gsdm,
			String fgsdm,String xlbm,String nbbm,
			String px) {
		
		List<String> objList = new ArrayList<>();
		String sql="SELECT * FROM bsth_c_qlb "
				+ " where rq=? ";
		objList.add(rq);
		if(gsdm.trim().length() > 0 && fgsdm.trim().length() > 0){
			sql += " and ssgsdm like CONCAT('%',?,'%') "
				+ " and fgsdm like CONCAT('%',?,'%') ";
			objList.add(gsdm);
			objList.add(fgsdm);
		} else if(gsdm.trim().length() > 0){
			sql += " and ssgsdm like CONCAT('%',?,'%') ";
			objList.add(gsdm);
		}
		if(xlbm.trim().length() > 0){
			sql+= " and xlbm = ? ";
			objList.add(xlbm);
		}
		sql += "and nbbm like CONCAT('%',?,'%') order by "+px+" asc ";
		objList.add(nbbm);
		
		List<Qlb> list = jdbcTemplate.query(sql, objList.toArray(), new RowMapper<Qlb>() {
			@Override
			public Qlb mapRow(ResultSet arg0, int arg1) throws SQLException {
				Qlb y = new Qlb();
				y.setId(arg0.getInt("id"));
				return y;
			}
		});
		List<Qlb> lists=new ArrayList<Qlb>();
		List<Qlb> qlbLists=repository.obtainQl(rq,gsdm,fgsdm,xlbm,nbbm,"jcsx");
		for (int i = 0; i < list.size(); i++) {
			Qlb t=list.get(i);
			for (int j = 0; j < qlbLists.size(); j++) {
				Qlb t2=qlbLists.get(j);
				if(t.getId().intValue()==t2.getId().intValue()){
					lists.add(t2);
					break;
				}
			}
		}
		
		return lists;
	}
	
	
	@Override
	public String checkJsy(Map<String, Object> map) {
		// TODO Auto-generated method stub
		String rq=map.get("date").toString();
		String nbbm=map.get("nbbm").toString();
		String jsy =map.get("jsy").toString();
		String xlbm=map.get("xlbm").toString();
		List<Qlb> list= repository.queryListQlb(rq, nbbm, jsy, xlbm);
		String type="1";
		if(list.size()>0){
			type="0";
		}
		return type;
	}

	@Override
	public Map<String, Object> saveQlb(Qlb t) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		String rq=sdf.format(t.getRq());
		String gsdm=t.getSsgsdm();
		String fgsdm=t.getFgsdm();
		String xlbm=t.getXlbm();
		String jhsj=t.getJhsj();
		String nbbm=t.getNbbm();
		t.setCreatetime(new Date());
		String[] jhsjStr = jhsj.split(":");
		long fcsjL= Long.parseLong(jhsjStr[0])*60+Long.parseLong(jhsjStr[1]);
		List<Qlb> list=this.listOrderBy(rq, gsdm, fgsdm, xlbm, nbbm, "jhsj");
		int jcsx=1;
		if(list.size()>0){
			for (int i = 0; i < list.size(); i++) {
				Qlb y=list.get(i);
				String[] fcsjStr = y.getJhsj().split(":");
				long fcsj=Long.parseLong(fcsjStr[0])*60+Long.parseLong(fcsjStr[1]);
				if(fcsjL>fcsj){
					jcsx=jcsx+y.getJcsx();
				}else{
					y.setJcsx(y.getJcsx()+1);
					repository.save(y);
				}
			}
		}
		t.setJcsx(jcsx);
		repository.save(t);
		
		SysUser user = SecurityUtils.getCurrentUser();
		Nylog nylog=new Nylog();
		nylog.setCreatedate(new Date());
		nylog.setCzmc("手动添加");
		nylog.setNylx("氢");
		nylog.setUserid(user.getUserName());
		nylog.setUsername(user.getName());
		nylog.setCxtj("");
		nylogRepository.save(nylog);
		map.put("status", ResponseCode.SUCCESS);
        map.put("t", t);
		return map;
	}
	
	@Transactional  
	@Override
	public Map<String, Object> deleteIds(Map<String, Object> map) throws Exception{
		// TODO Auto-generated method stub
		Map<String, Object> maps = new HashMap<>();
		try{
		String json =StringEscapeUtils.unescapeHtml4(map.get("ids").toString());
		JSONArray jsonArray=JSONArray.parseArray(json);
		JSONObject jsonObject;
		for (int x = 0; x < jsonArray.size(); x++) {
			jsonObject=jsonArray.getJSONObject(x);
			Integer id =jsonObject.getInteger("id");
			repository.deleteById(id);
		}
		
		SysUser user = SecurityUtils.getCurrentUser();
		Nylog nylog=new Nylog();
		nylog.setCreatedate(new Date());
		nylog.setCzmc("删除");
		nylog.setNylx("氢");
		nylog.setUserid(user.getUserName());
		nylog.setUsername(user.getName());
		nylog.setCxtj("");
		nylogRepository.save(nylog);
		maps.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			maps.put("status", ResponseCode.ERROR);
			logger.error("save erro.", e);
			throw e; 
		}
		return maps;
	}

	@Override
	public Map<String, List<Qlb>> updeteHistory(List<Map<String, Object>> listpbQc,String date,
			String gsdm,String fgsdm,String line) {
		// TODO Auto-generated method stub
		Map<String, List<Qlb>> mapList=new HashMap<String,List<Qlb>>();
		 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		// 保留两位小数
		DecimalFormat df = new DecimalFormat("#.000");
		List<Qlb> qlbList=this.listOrderBy(date,gsdm,fgsdm,"","","nbbm");
		List<Qlb> qlbList_upd=new ArrayList<Qlb>(); 
		List<Qlb> qlbList_del=new ArrayList<Qlb>(); 
		try{
		for (int j = 0; j < qlbList.size(); j++) {
			Qlb t=qlbList.get(j);
			boolean fage=true;
			if(StringUtils.isEmpty(t.getLp())){
				fage=false;
			}else{
				for (int i = 0; i < listpbQc.size(); i++) {
					Map<String, Object> m = listpbQc.get(i);
					if(t.getNbbm().equals(m.get("clZbh").toString())
					&&t.getJsy().equals(m.get("jGh").toString())
					&&t.getXlbm().equals(m.get("xlBm").toString())
					&&t.getLp().equals(m.get("lpName").toString())){
						//该条记录不用删除
						fage =false;
						qlbList_upd.add(t);
					}
				}
			}
			
			if(fage){
				if(t.getXlbm().equals(line)){
					qlbList_del.add(t);
				}
			}
		}
		mapList.put("delList", qlbList_del);
		Map<String, Double> lcMap=new HashMap<String,Double>();
		for (int i = 0; i < listpbQc.size(); i++) {
			String cl=listpbQc.get(i).get("clZbh").toString();
			Double lc= listpbQc.get(i).get("totalKilometers") == null ? 0.0
					: Double.parseDouble(listpbQc.get(i).get("totalKilometers").toString());
			if(lcMap.get(cl)==null){
				lcMap.put(cl, lc);
			}else{
				double lc_=lcMap.get(cl);
				lcMap.remove(cl);
				lcMap.put(cl, Arith.add(lc, lc_));
			}
		}
		Map<String, Double> shMap=new HashMap<String,Double>();
		for (int i = 0; i < qlbList_upd.size(); i++) {
			Qlb qlb=qlbList_upd.get(i);
			String cl=qlb.getNbbm();
			if(shMap.get(cl)==null){
				shMap.put(cl, qlb.getSh());
			}else{
				double sh=shMap.get(cl);
				shMap.remove(cl);
				shMap.put(cl, Arith.add(sh, qlb.getSh()));
			}
		}
		List<Jql> jqlList=jqlRepository.JqlList(date);
		Map<String, Object> newMap_=new HashMap<String,Object>();
		Map<String, Object> cMap=new HashMap<String, Object>();
		List<Map<String, Object>> listpb_=listpbQc;
		Collections.sort(listpbQc,new NbbmJcsxMap2());
		List<Qlb> updateQlb=new ArrayList<Qlb>();
		for (int x = 0; x < listpb_.size(); x++) {
			String type = "add";
			Map<String, Object> map_ = listpb_.get(x);
				if(newMap_.get(map_.get("clZbh").toString())==null){
					newMap_.put(map_.get("clZbh").toString(), map_.get("clZbh").toString());
					//车辆总里程
					double zlc =lcMap.get(map_.get("clZbh").toString());
					//车辆总加氢量
					double zjzl = 0.0;
//					for (int j = 0; j < ylxxList.size(); j++) {
//						Ylxxb ylxxb = ylxxList.get(j);
//						if (map_.get("clZbh").toString().equals(ylxxb.getNbbm())
//								&& map_.get("company").toString().equals(ylxxb.getGsdm())) {
//							zjzl = Arith.add(zjzl, ylxxb.getJzl());
//						}
//					}
					for (int i = 0; i < jqlList.size(); i++) {
						Jql jql=jqlList.get(i);
						if(map_.get("clZbh").toString().equals(jql.getNbbm()) 
								&&map_.get("company").toString().equals(jql.getGsBm())
								&&map_.get("bCompany").toString().equals(jql.getFgsBm())){
							zjzl = Arith.add(zjzl,jql.getJql());
						}
					}
					double clsh=0.0;
					if(shMap.get(map_.get("clZbh").toString())==null){
						clsh=0.0;
					}else{
						clsh=shMap.get(map_.get("clZbh").toString());
					}
					zjzl =Arith.sub(zjzl, clsh);
					Double nextJzyl = 0.0;
					for (int i = 0; i < listpbQc.size(); i++) {
						Map<String, Object> map = listpbQc.get(i);
						if(map_.get("clZbh").toString().equals(map.get("clZbh").toString())){
							// 判断驾驶员驾驶的该车辆是否已经存入了(查出的结果集中日期是相同的,根据驾驶员、内部编号、线路编码判断)
							Qlb t = new Qlb();
							for (int k = 0; k < qlbList_upd.size(); k++) {
								Qlb t1 = qlbList_upd.get(k);
								if (t1.getNbbm().equals(map.get("clZbh").toString())
										&& t1.getJsy().equals(map.get("jGh").toString())
										&& t1.getXlbm().equals(map.get("xlBm").toString())
										&& t1.getLp().equals(map.get("lpName").toString())) {
											t = t1;
											type = "update";
								}
								
							}
							Double lc= Double.parseDouble(map.get("totalKilometers").toString());
							if(map.get("seqNumber").toString().equals("1")){
								// 当日的第一个班次,出场油量等于前一天的最后一个班次的进场油量
								Double dh=0.0;
								if(zlc>0){
									dh = Double.parseDouble(df.format(zjzl * (lc / zlc)));
								}
								nextJzyl =Arith.sub(zjzl,dh);
								if(zlc>0){
//									long l=Math.round(nextJzyl);
									double ylxs=nextJzyl;
									dh=Arith.add(dh, Arith.sub(nextJzyl,ylxs));
									if(dh<0){
										t.setHn(0.0);
										t.setJql(0.0);
										nextJzyl=Arith.add(ylxs, dh);
									}else{
										t.setHn(dh);
										t.setJql(dh);
										nextJzyl=ylxs;
									}
								}else{
									t.setHn(0.0);
									t.setJql(0.0);
								}
							}else{
								Double dh=0.0;
								if(zlc>0){
									dh = Double.parseDouble(df.format(zjzl * (lc / zlc)));
								}
								nextJzyl =Arith.sub( nextJzyl,dh);
								if(zlc>0){
//									long l=0l;
									double ylxs=0.0;
									if(i==listpbQc.size()-1){
//										ylxs=czyl;
									}else{
										if(listpbQc.get(i+1).get("clZbh").toString().equals(map.get("clZbh").toString())){
//											l=Math.round(nextJzyl);
											ylxs=nextJzyl;
										}
										
									}
									dh=Arith.add(dh, Arith.sub(nextJzyl,ylxs));
									if(dh<0){
										t.setHn(0.0);
										t.setJql(0.0);
										nextJzyl=Arith.add(ylxs, dh);
									}else{
										t.setHn(dh);
										t.setJql(dh);
										nextJzyl=ylxs;
									}
								}else{
									t.setHn(0.0);
									t.setJql(0.0);
								}
							}
							t.setCzcl(100.0);
							t.setJzcl(100.0);
							t.setNbbm(map.get("clZbh").toString());
							t.setJsy(map.get("jGh") == null ? "" : map.get("jGh").toString());
							t.setZlc(map.get("totalKilometers") == null ? 0.0
									: Double.parseDouble(map.get("totalKilometers").toString()));
							t.setXlbm(map.get("xlBm") == null ? "" : map.get("xlBm").toString());
							t.setJcsx(Integer.parseInt(map.get("seqNumber").toString()));
							t.setSsgsdm(map.get("company") == null ? "" : map.get("company").toString());
							t.setFgsdm(map.get("bCompany") == null ? "" : map.get("bCompany").toString());
							t.setJhsj(map.get("fcsj")==null?"":map.get("fcsj").toString());
							t.setRq(sdf.parse(date));
							t.setLp(map.get("lpName").toString());
							t.setJql(Arith.add(t.getJql(), t.getSh()));
							if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
								 if(type.equals("add")){
									 t.setCreatetime(new Date());
								 }else{
									 t.setUpdatetime(new Date());
								 }
							 }
							
							if(t.getHn()<0){
								t.setHn(0.0);
							}
							if(t.getJql()<0){
								t.setJql(0.0);
							}
							updateQlb.add(t);
						}
					}
				}
			}
			mapList.put("updList", updateQlb);
		}catch(Exception e){
			logger.error("save erro.", e);
		}
		return mapList;
	}
	
	@Override
	public Map<String, Object> update(Map<String, Object> map) {
		if(map.get("id")!=null){
			if(map.get("id").toString().length()>0){
				Integer id=Integer.parseInt(map.get("id").toString());
				String jsy=map.get("jsy").toString();
				Qlb t=repository.findById(id).get();
				t.setJsy(jsy);
				repository.save(t);
				map.put("status", ResponseCode.SUCCESS);
			}
		}
		return map;
	}
	
}

class NbbmJcsxMap2 implements Comparator<Map<String, Object>>{
	 @Override
		public int compare(Map<String, Object> o1, Map<String, Object> o2) {
			// TODO Auto-generated method stub
			return  (o1.get("clZbh").toString()+o1.get("seqNumber").toString()).compareTo((o2.get("clZbh").toString()+o1.get("seqNumber").toString()));
		}
}