ScheduleRealInfoServiceImpl.java 26.2 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
package com.bsth.service.realcontrol.impl;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.entity.Cars;
import com.bsth.entity.Line;
import com.bsth.entity.Personnel;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.entity.schedule.CarConfigInfo;
import com.bsth.entity.schedule.EmployeeConfigInfo;
import com.bsth.entity.schedule.GuideboardInfo;
import com.bsth.entity.sys.SysUser;
import com.bsth.repository.LineRepository;
import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
import com.bsth.repository.schedule.CarConfigInfoRepository;
import com.bsth.repository.schedule.EmployeeConfigInfoRepository;
import com.bsth.repository.schedule.GuideboardInfoRepository;
import com.bsth.security.util.SecurityUtils;
import com.bsth.service.SectionRouteService;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.realcontrol.ScheduleRealInfoService;
import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
import com.bsth.util.ReportUtils;
import com.bsth.util.TransGPS;
import com.bsth.util.TransGPS.Location;
import com.bsth.vehicle.BorrowCenter;
import com.bsth.vehicle.common.CommonMapped;
import com.google.common.base.Splitter;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;

@Service
public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInfo, Long>
		implements ScheduleRealInfoService {

	@Autowired
	ScheduleRealInfoRepository scheduleRealInfoRepository;

	@Autowired
	EmployeeConfigInfoRepository employeeConfigInfoRepository;

	@Autowired
	CarConfigInfoRepository carConfigInfoRepository;
	
	@Autowired
	SectionRouteService sectionRouteService;
	
	@Autowired
	BorrowCenter borrowCenter;
	
	@Autowired
	LineRepository lineRepository;
	
	@Autowired
	GuideboardInfoRepository guideboardInfoRepository;

	Logger logger = LoggerFactory.getLogger(this.getClass());

	SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"),
			sdfMinute = new SimpleDateFormat("yyyy-MM-dd HH:mm"), sdfShort = new SimpleDateFormat("HH:mm");

	@Override
	public Map<String, Collection<ScheduleRealInfo>> findByLines(String lines) {
		List<String> lineList = Lists.newArrayList(Splitter.on(',').trimResults().omitEmptyStrings().split(lines));

		Multimap<String, ScheduleRealInfo> mMap = ArrayListMultimap.create();

		for (String lineCode : lineList) {
			mMap.putAll(lineCode, ScheduleBuffer.realSchedulListMap.get(lineCode));
		}
		return mMap.asMap();
	}

	@Override
	public Map<String, Object> outgoAdjust(Long id, String remarks, String dfsj, String nbbm,String jsy,String spy) {
		Map<String, Object> map = new HashMap<>();
		try {

			ScheduleRealInfo schedule = ScheduleBuffer.pkSchedulMap.get(id);
			schedule.setDfsjT(sdfMinute.parse(schedule.getRealExecDate() + " " + dfsj).getTime());
			schedule.setDfsj(dfsj);
			schedule.addRemarks(remarks);
			schedule.setClZbh(nbbm);
			if(jsy != null && jsy.indexOf("/") != -1){
				String[] jsyArray = jsy.split("/");
				schedule.setjGh(jsyArray[0]);
				schedule.setjName(jsyArray[1]);
			}
			
			if(spy != null && spy.indexOf("/") != -1){
				String[] spyArray = spy.split("/");
				schedule.setsGh(spyArray[0]);
				schedule.setsName(spyArray[1]);
			}
			
			// 持久化到数据库
			ScheduleBuffer.persistentList.add(schedule);

			map.put("status", ResponseCode.SUCCESS);
			map.put("t", schedule);
		} catch (Exception e) {
			logger.error("", e);
			map.put("status", ResponseCode.ERROR);
		}
		return map;
	}

	@Override
	public Map<String, Object> destroy(String idsStr, int spaceAdjust, String remarks, String reason, int spaceNum) {

		Map<String, Object> map = new HashMap<>();
		List<ScheduleRealInfo> rsList = new ArrayList<>();
		map.put("list", rsList);
		try {
			List<String> idList = Lists.newArrayList(Splitter.on(',').trimResults().omitEmptyStrings().split(idsStr));

			ScheduleRealInfo schedule = null;
			for (String id : idList) {
				schedule = ScheduleBuffer.pkSchedulMap.get(Long.parseLong(id));
				if(schedule.isDestroy()){
					map.put("status", ResponseCode.ERROR);
					map.put("msg", "不必要的重复烂班!");
					return map;
				}
				
				schedule.destroy();
				schedule.addRemarks(remarks);
				rsList.add(schedule);
			}

			// 调整间隔
			if (spaceAdjust == 1) {

				ScheduleRealInfo first = ScheduleBuffer.pkSchedulMap.get(Long.parseLong(idList.get(0)));
				String lineCode = first.getXlBm();
				String upDown = first.getXlDir();

				List<ScheduleRealInfo> schList = ScheduleBuffer.realSchedulListMap.get(lineCode),
						dirList = new ArrayList<>();
				// 筛选走向
				for (ScheduleRealInfo s : schList) {
					if (s.getXlDir().equals(upDown)) {
						dirList.add(s);
					}
				}

				int size = dirList.size();
				Long st = null;
				int diff = spaceNum * 60 * 1000;
				for (int i = 0; i < size; i++) {
					schedule = dirList.get(i);

					if (schedule.getId() == first.getId()) {
						if (i == 0)
							st = schedule.getDfsjT() - diff;
						else
							st = dirList.get(i - 1).getDfsjT();
						continue;
					}
					if (null == st || schedule.getStatus() == -1)
						continue;

					st = st + diff;
					schedule.setDfsjT(st);
					schedule.setDfsj(sdfShort.format(new Date(st)));

					ScheduleBuffer.persistentList.add(schedule);
					// 将调整的班次返回给页面
					rsList.add(schedule);
				}
			}

			map.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			logger.error("", e);
			map.put("status", ResponseCode.ERROR);
		}
		return map;
	}

	// 线路id获取驾驶员
	@Override
	public List<Map<String, String>> findDriverByLine(String lineCode) {
		List<EmployeeConfigInfo> list = employeeConfigInfoRepository.findBylineCode(lineCode);

		List<Map<String, String>> rsList = new ArrayList<>();
		Map<String, String> map = null;
		Personnel driver = null;
		String code = null;

		for (EmployeeConfigInfo employee : list) {
			driver = employee.getJsy();
			if (driver != null) {
				map = new HashMap<>();
				code = driver.getJobCode();
				map.put("id", code + "/" + driver.getPersonnelName());
				map.put("text", code + "/" + driver.getPersonnelName());
				rsList.add(map);
			}
		}
		return rsList;
	}

	// 线路id获取售票员
	@Override
	public List<Map<String, String>> findConductorByLine(String lineCode) {
		List<EmployeeConfigInfo> list = employeeConfigInfoRepository.findBylineCode(lineCode);

		List<Map<String, String>> rsList = new ArrayList<>();
		Map<String, String> map = null;
		Personnel conductor = null;
		String code = null;

		for (EmployeeConfigInfo employee : list) {
			conductor = employee.getSpy();
			if (conductor != null) {
				code = conductor.getJobCode();
				map = new HashMap<>();
				map.put("id", code + "/" + conductor.getPersonnelName());
				map.put("text", code + "/" + conductor.getPersonnelName());
				rsList.add(map);
			}
		}
		return rsList;
	}

	@Override
	public List<Map<String, String>> findCarByLine(String lineCode) {

		List<CarConfigInfo> list = carConfigInfoRepository.findBylineCode(lineCode);

		List<Map<String, String>> rsList = new ArrayList<>();
		Map<String, String> map = null;
		Cars car = null;
		String code = null;

		for (CarConfigInfo cci : list) {
			car = cci.getCl();
			if (car != null) {
				code = car.getInsideCode();
				map = new HashMap<>();
				map.put("id", code);
				map.put("text", code);
				rsList.add(map);
			}
		}
		return rsList;
	}

	/**
	 * 临加班次
	 */
	@Override
	public Map<String, Object> save(ScheduleRealInfo t) {
		SysUser user = SecurityUtils.getCurrentUser();
		Date d = new Date();
		
		t.setScheduleDate(d);
		t.setRealExecDate(sdfMonth.format(d));
		t.setCreateBy(user);
		t.syncTime();
		t.setSflj(true);
		Map<String, Object> map = super.save(t);

		// 加入缓存
		ScheduleBuffer.put(t);
		//将该临加之后的班次作为更新返回页面
		List<ScheduleRealInfo> list = ScheduleBuffer.findNextList(t)
				,rsList = null;
		
		for(ScheduleRealInfo sch : list){
			if(sch.getId() == t.getId())
				rsList = new ArrayList<>();
			
			if(rsList != null)
				rsList.add(sch);
		}
		
		map.put("ups", rsList);
		return map;
	}

	@Override
	public List<Map<String, String>> sreachVehic(String nbbm) {
		// 转大写
		nbbm = nbbm.toUpperCase();

		List<Map<String, String>> list = new ArrayList<>();
		Map<String, String> map;
		Set<String> allSet = CommonMapped.vehicCompanyMap.keySet();

		Line line;
		for (String k : allSet) {
			if (k.indexOf(nbbm) != -1) {
				// 所属线路
				map = new HashMap<>();
				line = CommonMapped.vehicLineMap.get(k);
				map.put("id", k);
				map.put("text", k);
				if (null != line) {
					map.put("lineName", line.getName());
					map.put("lineCode", line.getLineCode());
				}

				list.add(map);
			}

			if (list.size() > 20)
				break;
		}
		return list;
	}

	@Override
	public Map<String, Object> adjust(Long id, String nbbm, String jsy, String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) {
		// 班次
		ScheduleRealInfo schedule = ScheduleBuffer.pkSchedulMap.get(id);

		String rq = sdfMonth.format(new Date());
		// 换车
		if (!StringUtils.isBlank(nbbm)) {
			adjustCar(schedule, nbbm);
		}

		List<String> tempArray;
		// 换驾驶员
		if (!StringUtils.isBlank(jsy)) {
			tempArray = Splitter.on("/").splitToList(jsy);
			adjustDriver(schedule, tempArray.get(0), tempArray.get(1));
		}

		// 换售票员
		if (!StringUtils.isBlank(spy)) {
			tempArray = Splitter.on("/").splitToList(spy);
			adjustConductor(schedule, tempArray.get(0), tempArray.get(1));
		}
		
		if(borrowLine != null && borrowTimeStr != null){
			try {
				//跨线路借车
				Long t = sdfMinute.parse(rq + " " + borrowTimeStr).getTime();
				borrowCenter.put(nbbm, borrowLine, 0, t);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		
		if(revertLine != null && revertTimeStr != null){
			//定时还车
			try {
				Long t = sdfMinute.parse(rq + " " + revertTimeStr).getTime();
				borrowCenter.put(nbbm, revertLine, 1, t);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		ScheduleBuffer.persistentList.add(schedule);

		Map<String, Object> map = new HashMap<>();
		map.put("status", 200);
		map.put("t", schedule);
		return map;
	}

	@Override
	public void adjustCar(ScheduleRealInfo schedule, String car) {
		schedule.setClZbh(car);
	}

	@Override
	public void adjustDriver(ScheduleRealInfo schedule, String driver, String driverName) {
		schedule.setjGh(driver);
		schedule.setjName(driverName);
	}

	@Override
	public void adjustConductor(ScheduleRealInfo schedule, String conductor, String conductorName) {
		schedule.setsGh(conductor);
		schedule.setsName(conductorName);
	}

	@Override
	public List<ScheduleRealInfo> queryUserInfo(String line, String date) {
		return scheduleRealInfoRepository.queryUserInfo(line, date);
	}

	@Override
	public List<ScheduleRealInfo> exportWaybill(String jName, String clZbh, String lpName) {
		ReportUtils ee = new ReportUtils();
		List<Iterator<?>> list = new ArrayList<Iterator<?>>();
		List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.exportWaybill(jName, clZbh, lpName);
		ScheduleRealInfo scheduleRealInfo = scheduleRealInfoRepository.findOne(scheduleRealInfos.get(0).getId());
		
		String path = this.getClass().getResource("/").getPath()+"static\\pages\\forms\\";

		list.add(scheduleRealInfos.iterator());
		ee.excelReplace(list, new Object[] { scheduleRealInfo }, path+"mould\\waybill.xls",
				path+"export\\" + jName + ".xls");
		return scheduleRealInfos;
	}

	@Override
	public List<Map<String, Object>> dailyInfo(String line, String date) {
		DecimalFormat format = new DecimalFormat("0.00");
		List<Map<String, Object>> list = scheduleRealInfoRepository.dailyInfo(line, date);
		for(int i = 0;i < list.size();i++){
			list.get(i).put("zgl", format.format(Double.parseDouble(list.get(i).get("zgl")==null?"0":list.get(i).get("zgl").toString())));
			list.get(i).put("ksgl", format.format(Double.parseDouble(list.get(i).get("ksgl")==null?"0":list.get(i).get("ksgl").toString())));
		}
		return list;
	}

	@Override
	public List<Object[]> historyMessage(String line, String date, String code) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		List<Object[]> list = scheduleRealInfoRepository.historyMessage(line, date, code);
		for(Object[] obj:list){
			if(obj != null){
				obj[4] = sdf.format(new Date(Long.parseLong(obj[4].toString())));
			}
		}
		return list;
	}

	@Override
	public Map<Integer, Integer> trustStatus(String lineStr) {
		List<String> lineList = Lists.newArrayList(Splitter.on(',').trimResults().omitEmptyStrings().split(lineStr));

		Map<Integer, Integer> map = new HashMap<>();
		Integer code;
		for (String lineCode : lineList) {
			code = Integer.parseInt(lineCode);
			if (!ScheduleBuffer.trustMap.containsKey(lineCode))
				ScheduleBuffer.trustMap.put(code, 0);

			map.put(code, ScheduleBuffer.trustMap.get(code));
		}
		return map;
	}

	@Override
	public Map<String, Object> realOutAdjust(Long id, String fcsjActual, String remarks) {
		Map<String, Object> rs = new HashMap<>();
		List<ScheduleRealInfo> ts = new ArrayList<>();
		try {
			ScheduleRealInfo sch = ScheduleBuffer.findOne(id);

			Long t = sdfMinute.parse(sch.getRealExecDate() + " " + fcsjActual).getTime();
			/*sch.setFcsjActualTime(sdfMinute.parse(sch.getRealExecDate() + " " + fcsjActual).getTime());
			sch.setFcsjActual(fcsjActual);*/
			if(null != sch.getSjfcModel())
				sch.getSjfcModel().setPersonTime(t);
			
			sch.setFcsjActualAll(t);
			sch.addRemarks(remarks);
			sch.calcStatus();
			/*//改变状态
			if(sch.getZdsjActual() == null)
				sch.setStatus(1);*/
			
			ScheduleBuffer.persistentList.add(sch);
			
			ts.add(sch);
			//关联班次
			if(sch.existDependent())
				ts.add(sch.getTwins());
			
			rs.put("status", ResponseCode.SUCCESS);
			//rs.put("t", sch);
			rs.put("ts", ts);
		} catch (Exception e) {
			logger.error("", e);
			rs.put("status", ResponseCode.ERROR);
		}

		return rs;
	}

	@Override
	public Map<String, Object> revokeDestroy(Long id) {
		Map<String, Object> rs = new HashMap<>();
		try {
			ScheduleRealInfo sch = ScheduleBuffer.findOne(id);
			if (sch.getStatus() != -1) {
				rs.put("status", ResponseCode.ERROR);
				rs.put("msg", "未烂班,无法撤销!");
			} else {
				sch.setStatus(0);
				rs.put("status", ResponseCode.SUCCESS);
				rs.put("t", sch);

			}
		} catch (Exception e) {
			logger.error("", e);
			rs.put("status", ResponseCode.ERROR);
		}
		return rs;
	}

	@Override
	public Map<String, Object> revokeRealOutgo(Long id) {
		Map<String, Object> rs = new HashMap<>();
		List<ScheduleRealInfo> ts = new ArrayList<>();
		
		try {
			ScheduleRealInfo sch = ScheduleBuffer.findOne(id);
			if (sch.getFcsjActual() == null) {
				rs.put("status", ResponseCode.ERROR);
				rs.put("msg", "无实发时间,无法撤销!");
			} else {
				sch.revokeRealOutgo();
				rs.put("status", ResponseCode.SUCCESS);
				
				ts.add(sch);
				if(sch.existDependent()){
					//关联班次也撤销
					sch.getTwins().revokeRealOutgo();
					ts.add(sch.getTwins());
				}
					
				rs.put("ts", ts);

			}
		} catch (Exception e) {
			logger.error("", e);
			rs.put("status", ResponseCode.ERROR);
		}
		return rs;
	}

	@Override
	public Map<String, Object> spaceAdjust(Long[] ids, Integer space) {

		List<ScheduleRealInfo> list = new ArrayList<>();
		Map<String, Object> rs = new HashMap<>();
		try {
			ScheduleRealInfo sch;
			for (Long id : ids) {
				sch = ScheduleBuffer.findOne(id);
				if (null != sch)
					list.add(sch);
			}

			int size = list.size();
			if(size == 0){
				rs.put("status", ResponseCode.ERROR);
			}
			else{
				// 按发车时间排序
				Collections.sort(list, new ScheduleBuffer.ScheduleComparator());

				// 以第一个实际发车/待发时间为起点,调整间隔
				sch = list.get(0);
				Long st = sch.getFcsjActualTime()==null?sch.getDfsjT():sch.getFcsjActualTime()
					,plus = space * 60 * 1000L;
				
				for(int i = 1; i < size; i ++){
					st += plus;
					sch = list.get(i);
					sch.setDfsjAll(st);
					
					ScheduleBuffer.persistentList.add(sch);
				}
				
				rs.put("status", ResponseCode.SUCCESS);
				rs.put("list", list);
			}
			
		} catch (Exception e) {
			logger.error("", e);
			rs.put("status", ResponseCode.ERROR);
		}
		return rs;
	}

	@Override
	public Map<String, Object> schInfoFineTune(Map<String, String> map) {
		Map<String, Object> rs = new HashMap<>();
		List<ScheduleRealInfo> ts = new ArrayList<>();
		try {
			Long id = Long.parseLong(map.get("id"));
			//班次类型
			String bcType = map.get("bcType");
			//车辆自编号
			String clZbh = map.get("clZbh");
			//计划发车时间
			String fcsj = map.get("fcsj");
			//实际发车时间
			String fcsjActual = map.get("fcsjActual");
			
			//实际终点时间
			String zdsjActual = map.get("zdsjActual");
			//备注
			String remarks = map.get("remarks");
			
			ScheduleRealInfo sch = ScheduleBuffer.findOne(id);
			if(null != sch){
				//驾驶员
				if(StringUtils.isNotBlank(map.get("jsy"))){
					String[] jsy = map.get("jsy").split("/");
					sch.setjGh(jsy[0]);
					sch.setjName(jsy[1]);
				}
				
				//售票员
				if(StringUtils.isNotBlank(map.get("spy"))){
					String[] spy = map.get("spy").split("/");
					sch.setsGh(spy[0]);
					sch.setsName(spy[1]);
				}
				
				sch.setBcType(bcType);
				sch.setClZbh(clZbh);
				sch.setFcsjAll(fcsj);
				
				if(StringUtils.isNotBlank(fcsjActual)){
					
					if(!fcsjActual.equals(sch.getFcsjActual())){
						//调整实发
						sch.setFcsjActualAll(fcsjActual);
						if(null != sch.getSjfcModel())
							sch.getSjfcModel().setPersonTime(sch.getFcsjActualTime());
					}
				}
				else{
					/*sch.setFcsjActual(null);
					sch.setFcsjActualTime(null);
					if(null != sch.getSjfcModel())
						sch.getSjfcModel().resetNull();*/
					//撤销实发
					revokeRealOutgo(sch.getId());
				}
				
				//实达时间
				if(StringUtils.isNotBlank(zdsjActual)){
					if(!zdsjActual.equals(sch.getZdsjActual())){
						//调整实达
						sch.setZdsjActualAll(zdsjActual);
						//下一班次起点到达时间
						ScheduleRealInfo next = ScheduleBuffer.getNext(sch);
						next.setQdzArrDateSJ(zdsjActual);
						ts.add(next);
					}
				}
				else {
					//清除实达时间
					sch.clearZdsjActual();
					/*sch.setZdsjActual(null);
					sch.setZdsjActualTime(null);
					if(null != sch.getSjddModel())
						sch.getSjddModel().resetNull();*/
					
					//清除下一班次起点到达时间
					ScheduleRealInfo next = ScheduleBuffer.getNext(sch);
					next.setQdzArrDateSJ(null);
					ts.add(next);
				}
				
				sch.setRemarks(remarks);
			}
			
			//班次状态
			sch.calcStatus();
			ScheduleBuffer.persistentList.add(sch);
			//页面需要更新的班次信息
			ts.add(sch);
			if(sch.existDependent())
				ts.add(sch.getTwins());
			
			rs.put("status", ResponseCode.SUCCESS);
			rs.put("ts", ts);
			//rs.put("t", sch);
		} catch (Exception e) {
			logger.error("", e);
			rs.put("status", ResponseCode.ERROR);
		}
		return rs;
	}

	@Override
	public Map<String, Object> outgoAdjustAll(String params) {
		Map<String, Object> rs = new HashMap<>();
		try{
			JSONArray jsonArray = JSONArray.parseArray(params);
			
			ScheduleRealInfo schedule = null;
			JSONObject jsonObj;
			String dfsj;
			for(int i = 0; i < jsonArray.size(); i ++){
				jsonObj = jsonArray.getJSONObject(i);
				dfsj = jsonObj.getString("t");
				schedule = ScheduleBuffer.findOne(jsonObj.getLong("id"));
				//设置待发时间
				schedule.setDfsjAll(dfsj);
				ScheduleBuffer.persistentList.add(schedule);
			}
			
			rs.put("status", ResponseCode.SUCCESS);
			//将更新的最后一个班次返回
			rs.put("t", schedule);
		}catch(Exception e){
			logger.error("", e);
			rs.put("status", ResponseCode.ERROR);
		}
		return rs;
	}

	@Override
	public Map<String, Object> findRouteByLine(Integer lineId) {
		Map<String, Object> map = new HashMap<>();
		//上行
		map.put("line.id_eq", lineId);
		map.put("directions_eq", 0);
		List<Map<String, Object>>  upList = sectionRouteService.getSectionRoute(map);
		
		//下行
		map.put("directions_eq", 1);
		List<Map<String, Object>>  downList = sectionRouteService.getSectionRoute(map);
		
		Map<String, Object> rs = new HashMap<>();
		
		String upVectors = "", vec;
		//拼接上行路段
		for(Map<String, Object> temp : upList){
			vec = temp.get("sectionBsectionVector").toString();
			upVectors += vec.subSequence(11, vec.length() - 2) + " ";
		}
		
		//拼接下行路段
		String downVectors = "";
		for(Map<String, Object> temp : downList){//LINESTRING(
			vec = temp.get("sectionBsectionVector").toString();
			downVectors += vec.subSequence(11, vec.length() - 2) + " ";
		}
		
		
		rs.put("up", upVectors);
		//上行gcj
		rs.put("up_gcj", BdToGcjString(upVectors));
		rs.put("down", downVectors);
		//下行gcj
		rs.put("down_gcj", BdToGcjString(downVectors));
		rs.put("lineId", lineId);
		
		return rs;
	}
	
	/**
	 * 
	 * @Title: BdToGcjString 
	 * @Description: TODO(将百度路由字符串 转 成GCJ 字符串) 
	 * @param @param bdStr
	 * @throws
	 */
	public String BdToGcjString(String bdStr){
		String[] array = bdStr.split(",")
				,subArray;
		if(array.length == 0 || bdStr.length() < 2)
			return "";
		
		String gcjStr = "";
		Location location;
		for(String crd : array){
			subArray = crd.split(" ");
			if(subArray.length != 2)
				continue;
			location = TransGPS.bd_decrypt(TransGPS.LocationMake(Double.parseDouble(subArray[0]), Double.parseDouble(subArray[1])));
			
			gcjStr += location.getLng() + " " + location.getLat() + ",";
		}
		
		return gcjStr.substring(0, gcjStr.length() - 1);
	}
	public List<Map<String, String>> findLine(String line) {
		List<Line> listLine = lineRepository.findLine("%"+line+"%");
		List<Map<String,String>> list = new ArrayList<Map<String,String>>();
		Map<String,String> map;
		for(Line temp:listLine){
			if(temp != null){
				String xlName = temp.getName();
				if(xlName.indexOf(line) != -1){
					map = new HashMap<String, String>();
					map.put("id", temp.getLineCode());
					map.put("text", xlName);
					list.add(map);
				}
			}
		}
		return list;
	}
	
	public List<Map<String, String>> findLpName(String lpName) {
		List<GuideboardInfo> listLpName = guideboardInfoRepository.findLpName("%"+lpName+"%");
		List<Map<String,String>> list = new ArrayList<Map<String,String>>();
		Map<String,String> map;
		for(GuideboardInfo temp:listLpName){
			if(temp != null){
				String lp = temp.getLpName();
				if(lp.indexOf(lpName) != -1){
					map = new HashMap<String, String>();
					map.put("id", lp);
					map.put("text", lp);
					list.add(map);
				}
			}
		}
		return list;
	}

	@Override
	public Map<String, Object> findKMBC(String jName, String clZbh,
			String lpName) {
		List<ScheduleRealInfo> list = scheduleRealInfoRepository.exportWaybill(jName, clZbh, lpName);
		DecimalFormat format = new DecimalFormat("0.00");
		int cjbc = scheduleRealInfoRepository.findCjbc(jName, clZbh, lpName);
		int ljbc = scheduleRealInfoRepository.findLjbc(jName, clZbh, lpName);
		int jhbc = 0;
		double jhlc = 0;
		float realMileage = 0l,addMileage = 0l,remMileage = 0l;
		Map<String,Object> map = new HashMap<String, Object>();
		for(ScheduleRealInfo scheduleRealInfo : list){
			if(scheduleRealInfo != null){
				jhlc += scheduleRealInfo.getJhlc()==null?0:scheduleRealInfo.getJhlc();
				realMileage += scheduleRealInfo.getRealMileage()==null?0:scheduleRealInfo.getRealMileage();
				addMileage += scheduleRealInfo.getAddMileage()==null?0:scheduleRealInfo.getAddMileage();
				remMileage += scheduleRealInfo.getRemMileage()==null?0:scheduleRealInfo.getRemMileage();
				jhbc++;
			}
		}
		map.put("jhlc", format.format(jhlc));
		map.put("remMileage", format.format(remMileage));
		map.put("addMileage", format.format(addMileage));
		map.put("yygl", format.format(realMileage-addMileage));
		map.put("ksgl", format.format(realMileage-addMileage));
		map.put("realMileage", format.format(realMileage));
		map.put("jhbc", jhbc);
		map.put("cjbc", cjbc);
		map.put("ljbc", ljbc);
		map.put("sjbc", jhbc-cjbc+ljbc);
		return map;
	}

	@Override
	public List<Map<String, Object>> account(String line, String date,
			String code,String xlName) {
		List<Object[]> lsitObj = scheduleRealInfoRepository.account(line,date,code);
		List<Map<String,Object>> listMap = new ArrayList<Map<String,Object>>();
		Map<String,Object> map;
		for(Object[] obj : lsitObj){
			if(obj != null){
				map = new HashMap<String,Object>();
				map.put("xlName", xlName);
				map.put("clZbh", code);
				map.put("company", obj[0]);
				map.put("requestType", obj[1]);
				map.put("requestTime", obj[2]);
				listMap.add(map);
			}
		}
		return listMap;
	}

	@Override
	public List<ScheduleRealInfo> correctForm(String line, String startDate,
			String endDate, String lpName, String code) {
		List<ScheduleRealInfo> list = scheduleRealInfoRepository.correctForm(line,startDate,endDate,lpName);
		return list;
	}

	@Override
	public List<ScheduleRealInfo> queryListWaybill(String jName, String clZbh,
			String lpName) {
		return scheduleRealInfoRepository.queryListWaybill(jName,clZbh,lpName);
	}
}