StationRouteServiceImpl.java 37.8 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
package com.bsth.service.impl;

import com.bsth.common.ResponseCode;
import com.bsth.entity.*;
import com.bsth.entity.search.CustomerSpecs;
import com.bsth.repository.*;
import com.bsth.service.StationRouteService;
import com.bsth.util.CoordinateConverter;
import com.bsth.util.ExcelUtil;
import com.bsth.util.FTPClientUtils;
import com.bsth.util.Geo.GeoUtils;
import com.bsth.util.Geo.Point;
import com.bsth.util.PackTarGZUtils;
import com.bsth.util.db.DBUtils_MS;
import com.google.common.base.Splitter;
import org.apache.commons.lang3.StringUtils;
import org.geolatte.geom.Polygon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.*;

/**
 * 
 * @ClassName: StationRouteServiceImpl(站点路由service业务层实现类)
 * 
 * @Extends : BaseService
 * 
 * @Description: TODO(站点路由service业务层)
 * 
 * @Author bsth@lq
 * 
 * @Date 2016年5月03日 上午9:21:17
 *
 * @Version 公交调度系统BS版 0.1
 * 
 */

@Service
public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integer> implements StationRouteService{
	
	@Autowired
	private StationRouteRepository stationRouteRepository;
	
	@Autowired
	private SectionRouteRepository sectionRouteRepository;
	
	@Autowired
	private LineRepository lineRepository;
	
	@Autowired
	private StationRepository stationRepository;

	@Autowired
	private BusinessRepository businessRepository;

    @Autowired
    private LsStationRouteRepository lsStationRouteRepository;

    @Autowired
    private LsSectionRouteRepository lsSectionRouteRepository;

	@Autowired
	private LineRegionRepository lineRegionRepository;
    @Autowired
    private LineVersionsRepository lineVersionsRepository;

	@Override
	public Iterable<StationRoute> list(Map<String, Object> map) {
		List<Sort.Order> orders = new ArrayList<>();
		orders.add(new Sort.Order(Direction.ASC, "directions"));
		orders.add(new Sort.Order(Direction.ASC, "stationRouteCode"));

		return stationRouteRepository.findAll(new CustomerSpecs<>(map), Sort.by(orders));
	}
	
	@Override
	public Map<String, Object> getSectionRouteExport(Integer id, HttpServletResponse resp) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			// List<Map<String, Object>> resultList = new ArrayList<Map<String,Object>>();
			Map<String,Object> resultExcel = new HashMap<String,Object>();//导出参数的对象
			/* 添加表头*/
			List<String> title = new ArrayList<String>();
			title.add("线路ID");
			title.add("方向");
			title.add("站点编码");
			title.add("站点顺序号");
			title.add("站点备注");
			title.add("站点名称");
			title.add("站点距离(km)");
			title.add("站点时长(min)");
			title.add("线路名称");
			resultExcel.put("title", title);
			/* 添加表单*/
			Map<String,List<String>> temp = new HashMap<String,List<String>>();
			List<StationRoute> strtionList = stationRouteRepository.findStationExport(id);
			if(strtionList == null){
				logger.info("没有数据导,出用户信息失败!");
			} else {

				for (int i = 0; i < strtionList.size(); i++) {
					StationRoute station = strtionList.get(i);

					List<String> varList = new ArrayList<String>();
					varList.add(station.getLine().getId().toString());
					varList.add(station.getDirections().toString());
					varList.add(station.getStationCode());
					varList.add(station.getStationRouteCode().toString());
					varList.add(station.getStationMark());
					varList.add(station.getStationName());
					varList.add(station.getDistances().toString());
					varList.add(station.getToTime().toString());
					varList.add(station.getLine().getName());
					temp.put((i+1)+"", varList);
				}
			}
			resultExcel.put("content", temp);
			ExcelUtil excelUtil = new ExcelUtil();
			excelUtil.buildExcelDocument(resultExcel, strtionList.get(0).getLine().getName()+"线路站点",resp);
			resultMap.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			resultMap.put("status", ResponseCode.ERROR);
			logger.error("save erro.", e);
		}
		return resultMap;
	}
	
	/**
	 * @Description :TODO(查询树站点与路段数据)
	 * 
	 * @param map <line.id_eq:线路ID; directions_eq:方向>
	 * 
	 * @return List<Map<String, Object>>
	 */
	@Override
	public Map<String, Object> findRoutes(Map<String, Object> map) {
		Map<String, Object> result = new HashMap<>();
		List<StationRoute> stationList = stationRouteRepository.findAll(new CustomerSpecs<>(map), Sort.by(Direction.ASC, "directions", "stationRouteCode"));
		List<SectionRoute> sectionList = sectionRouteRepository.findAll(new CustomerSpecs<>(map), Sort.by(Direction.ASC, "directions", "sectionrouteCode"));

		result.put("stationRoutes", stationList);
		result.put("sectionRoutes", sectionList);

		return result;
	}
	
	@Override
	public Map<String, Object> systemQuote(Map<String, Object> map) {
		Map<String, Object> resultmap = new HashMap<>();
		try{
			
			StationRoute route = new StationRoute();
			
			Integer lineId = map.get("lineId").equals("") ? null : Integer.parseInt(map.get("lineId").toString());
			
			Integer stationId = map.get("stationId").equals("") ? null : Integer.parseInt(map.get("stationId").toString());
			
			Line line = lineRepository.findById(lineId).get();
			
			Station station = stationRepository.findById(stationId).get();
			
			route.setLine(line);
			
			route.setStation(station);
			
			//baseRepository.save(t);
			resultmap.put("status", ResponseCode.SUCCESS);
		}catch(Exception e){
			resultmap.put("status", ResponseCode.ERROR);
			logger.error("save erro.", e);
		}
		return resultmap;
	}
	
	/**
	 * @Description :TODO(查询线路某方向下的站点序号与类型)
	 * 
	 * @param map <lineId:线路ID; direction:方向;stationRouteCode:站点编码>
	 * 
	 * @return List<Map<String, Object>> 
	 */
	@Override
	public List<Map<String, Object>> findUpStationRouteCode(Map<String, Object> map) {
		Integer lineId = map.get("lineId").equals("") ? null : Integer.parseInt(map.get("lineId").toString());
		Integer direction = map.get("direction").equals("") ? null : Integer.parseInt(map.get("direction").toString());
		Integer stationRouteCode = map.get("stationRouteCode").equals("") ? null : Integer.parseInt(map.get("stationRouteCode").toString());
		List<Object[]> reslutList = stationRouteRepository.findUpStationRouteCode(lineId, direction, stationRouteCode);
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		if(reslutList.size()>0) {
			for(int i = 0 ; i <reslutList.size() ;i++){
				Map<String, Object> tempM = new HashMap<String, Object>();
				tempM.put("stationRouteCode", reslutList.get(i)[0]);
				tempM.put("stationRouteMarke", reslutList.get(i)[1]);
				list.add(tempM);
			}
		}
		return list;
	}

	private void traversalStation(List<LsStationRoute> stationRoutes, List<Map<String, Object>> resultList, int len) {
		for(int i = 0 ; i < len; i++) {
			LsStationRoute stationRoute = stationRoutes.get(i);
            Map<String, Object> tempM = new HashMap<String,Object>();

            tempM.put("stationRouteLine", stationRoute.getLine().getId());

            tempM.put("stationRouteStation", stationRoute.getStation().getId());

            tempM.put("stationRouteCode", stationRoute.getStationRouteCode());

            tempM.put("stationRouteLIneCode", stationRoute.getLineCode());

            tempM.put("stationRouteStationMark", stationRoute.getStationMark());

            tempM.put("stationOutStationNmber", stationRoute.getOutStationNmber());

            tempM.put("stationRoutedirections", stationRoute.getDirections());

            tempM.put("stationRouteDistances", stationRoute.getDistances());

            tempM.put("stationRouteToTime", stationRoute.getToTime());

            tempM.put("staitonRouteFirstTime", stationRoute.getFirstTime());

            tempM.put("stationRouteEndTime", stationRoute.getEndTime());

            tempM.put("stationRouteDescriptions", stationRoute.getDescriptions());

            tempM.put("stationRouteDestroy", stationRoute.getDestroy());

            tempM.put("stationRouteVersions", stationRoute.getVersions());

            tempM.put("stationRouteCreateBy", stationRoute.getCreateBy());

            tempM.put("stationRouteCreateDate", stationRoute.getCreateDate());

            tempM.put("stationRouteUpdateBy", stationRoute.getUpdateBy());

            tempM.put("stationRouteUpdateDate", stationRoute.getUpdateDate());

            tempM.put("stationId", stationRoute.getStation().getId());

            tempM.put("stationCode", stationRoute.getStation().getStationCode());

            tempM.put("stationRouteName", stationRoute.getStationName());

            tempM.put("stationRoadCoding", stationRoute.getStation().getRoadCoding());

            tempM.put("stationJwpoints", stationRoute.getStation().getCenterPoint().toString());

			CoordinateConverter.Location location = CoordinateConverter.LocationMake(stationRoute.getStation().getCenterPointWgs().toString());
            tempM.put("stationGlonx", location.getLng());

            tempM.put("stationGlaty", location.getLat());

			Polygon polygon = stationRoute.getBufferPolygon(), polygonWgs = stationRoute.getBufferPolygonWgs();
            tempM.put("stationBPolyonGrid", polygon == null ? "" : polygon.toString());

            tempM.put("stationGPloyonGrid", polygonWgs == null ? "" : polygonWgs.toString());

            tempM.put("stationDestroy", stationRoute.getStation().getDestroy());

            tempM.put("stationRadius", stationRoute.getRadius());

            tempM.put("stationShapesType", stationRoute.getShapedType());

            tempM.put("stationVersions", stationRoute.getStation().getVersions());

            tempM.put("sttationDescriptions", stationRoute.getStation().getDescriptions());

            tempM.put("stationCreateBy", stationRoute.getStation().getCreateBy());

            tempM.put("stationCreateDate", stationRoute.getStation().getCreateDate());

            tempM.put("stationUpdateBy", stationRoute.getStation().getUpdateBy());

            tempM.put("stationUpdateDate", stationRoute.getStation().getUpdateDate());

            tempM.put("stationRouteId", stationRoute.getId());
            tempM.put("zdmc", stationRoute.getStationName());
            // 行业编码
            tempM.put("industryCode", stationRoute.getIndustryCode());
            try {
                tempM.put("stationNameEn", stationRoute.getStationNameEn());
			} catch (Exception e) {
				e.printStackTrace();
			}

            resultList.add(tempM);
        }
	}

	/**
	  * @Description :TODO(查询线路某方向下所有站点的中心百度坐标)
	  * 
	  * @param map <lineId:线路ID; direction:方向>
	  * 
	  * @return List<Map<String, Object>> 
	  */
	@Override
	public List<Map<String, Object>> getStationRouteCenterPoints(Map<String, Object> map) {
		
		List<Map<String, Object>> resultList = new ArrayList<Map<String,Object>>();
		
		// 线路ID
		Integer lineId = map.get("lineId").equals("") ? null : Integer.parseInt(map.get("lineId").toString());
		
		// 方向
		Integer direction = map.get("direction").equals("") ? null : Integer.parseInt(map.get("direction").toString());
		
		List<Object[]> list = stationRouteRepository.getSelectStationRouteCenterPoints(lineId, direction);
		
		if(list.size()>0) {
			
			for(int i = 0;i<list.size();i++) {
				
				Map<String, Object> tempM = new HashMap<String,Object>();
				
				tempM.put("bJwpoints", list.get(i)[0]);
				
				tempM.put("stationName", list.get(i)[1]);
				
				resultList.add(tempM);
				
			}
			
		}
		
		return resultList;
	}

	/**
	 * @Description :TODO(查询线路某方向下所有站点)
	 *
	 * @param map <lineId:线路ID; direction:方向>
	 *
	 * @return List<Map<String, Object>>
	 */
	@Override
	public List<Map<String, Object>> getStationRouteList(Map<String, Object> map) {
		if (map.get("line.id_eq") == null || map.get("directions_eq") == null || map.get("versions_eq") == null) {
			throw new IllegalArgumentException("需正确传入线路、方向、版本参数");
		}
		map.put("destroy_eq", 0);
		List<LsStationRoute> stationRoutes = lsStationRouteRepository.findAll(new CustomerSpecs<>(map), Sort.by(Direction.ASC, "stationRouteCode"));
		
		List<Map<String, Object>> resultList = new ArrayList<>();

		int len = stationRoutes.size();

		if(len > 0) {
			// 遍历站点
			traversalStation(stationRoutes, resultList, len);
		}
		return resultList;
	}
	
	/**
	 * @Description :TODO(撤销站点)
	 * 
	 * @param map <lineId:线路ID; destroy:是否撤销(0:否;1:是)>
	 * 
	 * @return Map<String, Object> <SUCCESS ; ERROR>
	 */
	@Override
	public Map<String, Object> stationRouteIsDestroy(Map<String, Object> map) {
		Map<String, Object> resultMap = new HashMap<String,Object>();
		
		try {
			
			Integer stationRouteId = map.get("stationRouteId").equals("") ? 0 : Integer.parseInt(map.get("stationRouteId").toString());
			
			Integer destroy = map.get("destroy").equals("") ? 0 : Integer.parseInt(map.get("destroy").toString());

			lsStationRouteRepository.deleteById(stationRouteId);

			resultMap.put("status", ResponseCode.SUCCESS);
			
		} catch (Exception e) {
			
			resultMap.put("status", ResponseCode.ERROR);
			
			logger.error("save erro.", e);
			
		}
		
		return resultMap;
	}
	
	/**
	 * @Description : TODO(根据线路ID生成行单)
	 * 
	 * @param map <lineId:线路ID>
	 * 
	 * @return Map<String, Object> <SUCCESS ; ERROR ; NOTDATA>
	 */
	@Override
	public Map<String, Object> usingSingle(Map<String, Object> map) {
		// 返回值map
		Map<String, Object> resultMap = new HashMap<String,Object>();
		try {
			// 获取线路ID
			Integer lineId = map.get("lineId").equals("") ? 0 : Integer.parseInt(map.get("lineId").toString());
			Integer version = lineVersionsRepository.findCurrentVersion(lineId);
			Map<String, Object> param = new HashMap<>();
			param.put("line_eq", lineId);
			param.put("version_eq", version);
			/** 查询线路信息 @param:<lineId:线路ID> */
			Line line = lineRepository.findById(lineId).get();

			Business company = businessRepository.findByBusinessCode(line.getCompany()).get(0);

			Integer fileVersions = lineRepository.findfileVersions(lineId);
			if(fileVersions == null) {
				lineRepository.addFileVersions(line.getId(), line.getLineCode());
				fileVersions = 1;
			} else {
				fileVersions = fileVersions + 1;
				lineRepository.editFileVersions(line.getId(),fileVersions);
			}
//			Integer fileVersions = map.get("fileVersions").equals("") ? 1 : Integer.parseInt(map.get("fileVersions").toString());// 没有输入就默认1
			/** 查询线路信息下的站点路由信息 @param:<lineId:线路ID> */
			List<Object[]> objects = stationRouteRepository.usingSingle(lineId);
			List<LineRegion> lineRegions = lineRegionRepository.findAll(new CustomerSpecs<>(param));
			if (objects.size()>0) {
				/** 获取配置文件里的ftp登录参数 */
				Map<String, Object> FTPParamMap = readPropertiesGetFTPParam();
				// 压缩文件名
				String odlGzFileName = line.getLineCode() + ".txt.gz";
				// txt文件名
				String textFileName  = line.getLineCode() + ".txt";
				// 创建一个ftp上传实例
				FTPClientUtils clientUtils = new FTPClientUtils();
				// IP
				String url = FTPParamMap.get("url").toString();
				// 端口
				int port = Integer.valueOf(FTPParamMap.get("port").toString());
				// 用户名
				String username = FTPParamMap.get("username").toString();
				// 密码
				String password = FTPParamMap.get("password").toString();
				// 相对路径
				String remotePath = FTPParamMap.get("remotePath").toString();
				/** 如果已存在相同行单文件名则先删除 */
				clientUtils.deleteFtpFile(url, port, username, password, remotePath, odlGzFileName);
				clientUtils.deleteFtpFile(url, port, username, password, remotePath, textFileName);
				clientUtils.deleteFtpFile(url, port, username, password, remotePath + "/voice/", textFileName);
				String textStr = "";
//				boolean tempTag = ishxType(objects);
				Integer linePlayType = line.getLinePlayType() == null ? -1:line.getLinePlayType();
				if(linePlayType == 1)
					textStr = hxTextFileToFtp(objects,lineId);// 环线行单文件内容
				else if (linePlayType == 0)
					textStr = newTextFileToFTP(objects,lineId);/** 双向行单文件内容 @param:<objects:站点路由;lineId:线路ID>*/
				else
					resultMap.put("status","NOLinePlayType");// 线路无线路规划类型

				textStr = line.getName() + " " + fileVersions + "\r\n" + textStr;
				InputStream input = new ByteArrayInputStream(textStr.getBytes("gbk"));
				/** 生成txt文件,上传ftp */
				clientUtils.uploadFile(url, port, username, password, remotePath, textFileName, input);
				// 创建打包实例
				PackTarGZUtils packTarGZUtils= new PackTarGZUtils();
				/** 获取txt文件 */
				File textFile = clientUtils.GetFtpFile(url, port, username, password, remotePath, textFileName);
				File target = new File(odlGzFileName);
				// 将txt文件打包
				File targetFile = PackTarGZUtils.compress(textFile, target);
				clientUtils.FTPUpLoadFromDisk(targetFile, targetFile.getName(), url, port, username, password, remotePath);
				// 删除文件
				textFile.delete();
				targetFile.delete();


				textStr = newTextVoiceFileToFTP(objects,lineId);

				String lineName = line.getName();

				/*try {
					lineName = Integer.parseInt(line.getName().replace("路", "")) + "";
				} catch (Exception e) {
				}*/

				String head = lineName + " " + fileVersions + " " + line.getStartStationFirstTime() + "-" + line.getStartStationEndTime() + " " + line.getEndStationFirstTime() + "-" + line.getEndStationEndTime() + " " + line.getTicketPrice() +  " " + company.getBusinessName() + " " + (company.getPhoneNum()== null ? "-" : company.getPhoneNum());

				textStr =  head +"\r\n" + textStr;

				input = new ByteArrayInputStream(textStr.getBytes("gbk"));

				clientUtils.uploadFile(url, port, username, password, remotePath + "/voice/", textFileName, input);

//				textFile.delete();
				if (lineRegions.size() > 0) {
					FTPClientUtils.deleteFileByPrefix(String.format("%s-", line.getLineCode()), url, port, username, password, String.format("%s/voice/", remotePath));
					for (LineRegion lineRegion : lineRegions) {
						textStr = String.format("%s\r\n%s", head, subLine2Ftp(lineRegion));
						input = new ByteArrayInputStream(textStr.getBytes("gbk"));
						clientUtils.uploadFile(url, port, username, password, remotePath + "/voice/", String.format("%s-%d.txt", line.getLineCode(), lineRegion.getSeq()), input);
					}
				}

				resultMap.put("status", ResponseCode.SUCCESS);
			}else {
				resultMap.put("status","NOTDATA");
			}
		} catch (Exception e) {
			resultMap.put("status", ResponseCode.ERROR);
			logger.error("save erro.", e);
		} finally {
			return resultMap;
		}
	}
	
	/**
	 * @Description : TODO(形成行单文件内容)
	 * 
	 * @param objects :站点路由信息
	 * 	
	 * 					{[0]:g_lonx(GPS经度);[1]:g_laty(GPS纬度);[2]:b_jwpoints(百度经纬度坐标)
	 * 							
	 * 					[3]:station_mark(站点类型);[4]:station_route_code(站点序号);[5]:station_cod(站点编码);
	 * 
	 * 				    [6]:distances(站点距离);[7]:station_name(站点名称);[8]:directions(方向)}
	 * 
	 * @param lineId :线路ID
	 * 
	 * @return String
	 */ 
	public String  newTextFileToFTP(List<Object[]> objects,Integer lineId) {

		// 返回值String
		String stationRStr = "";
		// windows下的文本文件换行符
		//String enterStr = "\r\n";
		// linux/unix下的文本文件换行符
		String enterStr = "\r";
		int defaultZdxh = 0;
		if(objects.size()>0) {
			for(int i = 0; i<objects.size();i++) {
				defaultZdxh ++ ;
				// 经度
				String lng = objects.get(i)[0].equals("") ? "0" : objects.get(i)[0].toString();
				
				// 纬度
				String lat = objects.get(i)[1].equals("") ? "0" : objects.get(i)[1].toString();
				
				Point point = new Point(Double.valueOf(lng), Double.valueOf(lat));
				
				lat = "\t" +  lat;
				
				// 站点类型
				String stationMakeStr =  objects.get(i)[3].equals("") ? "" : objects.get(i)[3].toString();
				
				String stationMake = "";
				
				if(stationMakeStr.equals("E")) {
					stationMake = "\t2";
				}else {
					stationMake ="\t1";
				}
				
				// 站点序号 
				// String stationNo =  objects.get(i)[4].equals("") ? "" : objects.get(i)[4].toString();
				String stationNo =  String.valueOf(defaultZdxh);
				
				stationNo = "\t" + stationNo;
				
				// 站点编码
				String stationCode = objects.get(i)[5].equals("") ? "" : objects.get(i)[5].toString();
				
				int len = stationCode.length();
				if(len<8) {
					int dx = 8 - len;
					String addStr = "";
					for(int p =0;p<dx;p++) {
						addStr  = addStr + "0";
					}
					stationCode = addStr + stationCode;
				}else if(len>8){
					stationCode = stationCode.substring(8);
				}
				
				stationCode =  "\t" +stationCode;
				
				double dis = objects.get(i)[6]==null  ? 0.0 : Double.parseDouble(objects.get(i)[6].toString())*1000;
				
				String tempDistc = String.valueOf((int) dis);
				
				// 站点距离
				String staitondistance = "\t" + tempDistc;
				
				// 站点名称
				String stationName =  objects.get(i)[7].equals("") ? "" : objects.get(i)[7].toString();
				
				stationName = "\t" +stationName;
				
				// 限速
				// String sleepStr = " " + "60";
				
				// 限速
				String sleepStr = "";
				// 方向
				int directions = objects.get(i)[8]==null ? null : Integer.valueOf(objects.get(i)[8].toString());
				/** 获取路段路由信息 @pararm:<lineId:线路ID;directions:方向> */
				List<Object[]> sobje = sectionRouteRepository.sectionRouteVector(lineId,directions);
				if(sobje.size()==1) {
					double dsleepStrt = sobje.get(0)[2] == null ? 60d : Double.valueOf(sobje.get(0)[2].toString());
					sleepStr =  "\t" +  new DecimalFormat("0").format(dsleepStrt);
//					int dsleepStr = sobje.get(0)[2] == null || sobje.get(0)[2].equals("") ? 60 : Integer.valueOf(sobje.get(0)[2].toString());
//					sleepStr =  "\t" +  String.valueOf(dsleepStr);
				}else if(sobje.size()>1){
					for(int j =0;j<sobje.size();j++) {
						double dsleepStrt = sobje.get(j)[2] == null || sobje.get(j)[2].equals("") ? 60d : Double.valueOf(sobje.get(j)[2].toString());
						String pointsStr = sobje.get(j)[1]==null || sobje.get(j)[1].equals("") ? null : sobje.get(j)[1].toString();
						pointsStr = pointsStr.substring(11, pointsStr.length()-1);
						List<Point> ps = new ArrayList<>();
						String[] pArray = pointsStr.split(",");
						for(int a = 0; a <pArray.length; a++) {
							String[] tmepA = pArray[a].split(" ");
							Point temp = new Point(Double.valueOf(tmepA[0]), Double.valueOf(tmepA[1]));
							ps.add(temp);
						}
						if(GeoUtils.isInSection(ps, point)) {
							sleepStr = "\t" + String.valueOf((int)dsleepStrt);
							break;
						}
					}
				}
				if(sleepStr.equals("")) 
					sleepStr  =  "\t" + "60";
				stationRStr = stationRStr + lng + lat + stationMake + stationNo + stationCode + staitondistance + sleepStr + stationName + enterStr;
			}
			
		}
		return stationRStr;
	
	}
	
	public String  newTextVoiceFileToFTP(List<Object[]> objects,Integer lineId) {

		// 返回值String
		String stationRStr = "";
		// windows下的文本文件换行符
		String enterStr = "\r\n";
		// linux/unix下的文本文件换行符
//		String enterStr = "\r";
		int defaultZdxh = 0;
		if(objects.size()>0) {
			for(int i = 0; i<objects.size();i++) {
				defaultZdxh ++ ;
				// 经度
				String lng = objects.get(i)[0].equals("") ? "0" : objects.get(i)[0].toString();
				
				// 纬度
				String lat = objects.get(i)[1].equals("") ? "0" : objects.get(i)[1].toString();
				
				Point point = new Point(Double.valueOf(lng), Double.valueOf(lat));
				
				lat = "\t" +  lat;
				
				// 站点类型
				String stationMakeStr =  objects.get(i)[3].equals("") ? "" : objects.get(i)[3].toString();
				
				String stationMake = "";
				
				if(stationMakeStr.equals("E")) {
					stationMake = "\t2";
				}else {
					stationMake ="\t1";
				}
				
				// 站点序号 
				// String stationNo =  objects.get(i)[4].equals("") ? "" : objects.get(i)[4].toString();
				String stationNo =  String.valueOf(defaultZdxh);
				
				stationNo = "\t" + stationNo;
				
				// 站点编码
				String stationCode = objects.get(i)[5].equals("") ? "" : objects.get(i)[5].toString();
				
				int len = stationCode.length();
				if(len<8) {
					int dx = 8 - len;
					String addStr = "";
					for(int p =0;p<dx;p++) {
						addStr  = addStr + "0";
					}
					stationCode = addStr + stationCode;
				}else if(len>8){
					stationCode = stationCode.substring(8);
				}
				
				stationCode =  "\t" +stationCode;
				
				double dis = objects.get(i)[6]==null  ? 0.0 : Double.parseDouble(objects.get(i)[6].toString())*1000;
				
				String tempDistc = String.valueOf((int) dis);
				
				// 站点距离
				String staitondistance = "\t" + tempDistc;
				
				// 站点名称
				String stationName =  objects.get(i)[7].equals("") ? " " : objects.get(i)[7].toString();
				
				String stationNameEn = " ";
				if(objects.get(i)[9] != null){
					stationNameEn =  objects.get(i)[9].equals("") ? " " : objects.get(i)[9].toString();
				}
				
				
				stationName = "\t" +stationName;
				stationNameEn = "\t" +stationNameEn;
				
				// 限速
				// String sleepStr = " " + "60";
				
				// 限速
				String sleepStr = "";
				// 方向
				int directions = objects.get(i)[8]==null ? null : Integer.valueOf(objects.get(i)[8].toString());
				if (directions == 1) {
					stationName = stationName.replaceAll("\\(起点站\\)", "").replaceAll("\\(终点站\\)", "").replaceAll("(起点站)", "").replaceAll("(终点站)", "");
				}
				/** 获取路段路由信息 @pararm:<lineId:线路ID;directions:方向> */
				List<Object[]> sobje = sectionRouteRepository.sectionRouteVector(lineId,directions);
				if(sobje.size()==1) {
					double dsleepStrt = sobje.get(0)[2] == null ? 60d : Double.valueOf(sobje.get(0)[2].toString());
					sleepStr =  "\t" +  new DecimalFormat("0").format(dsleepStrt);
//					int dsleepStr = sobje.get(0)[2] == null || sobje.get(0)[2].equals("") ? 60 : Integer.valueOf(sobje.get(0)[2].toString());
//					sleepStr =  "\t" +  String.valueOf(dsleepStr);
				}else if(sobje.size()>1){
					for(int j =0;j<sobje.size();j++) {
						double dsleepStrt = sobje.get(j)[2] == null || sobje.get(j)[2].equals("") ? 60d : Double.valueOf(sobje.get(j)[2].toString());
						String pointsStr = sobje.get(j)[1]==null || sobje.get(j)[1].equals("") ? null : sobje.get(j)[1].toString();
						pointsStr = pointsStr.substring(11, pointsStr.length()-1);
						List<Point> ps = new ArrayList<>();
						String[] pArray = pointsStr.split(",");
						for(int a = 0; a <pArray.length; a++) {
							String[] tmepA = pArray[a].split(" ");
							Point temp = new Point(Double.valueOf(tmepA[0]), Double.valueOf(tmepA[1]));
							ps.add(temp);
						}
						if(GeoUtils.isInSection(ps, point)) {
							sleepStr = "\t" + String.valueOf((int)dsleepStrt);
							break;
						}
					}
				}
				if(sleepStr.equals("")) 
					sleepStr  =  "\t" + "60";
				stationRStr = stationRStr + lng + lat + stationMake + stationNo + stationCode + staitondistance + sleepStr + stationName + stationNameEn + enterStr;
			}
			
		}
		return stationRStr;
	
	}
	
	public String hxTextFileToFtp(List<Object[]> objects,Integer lineId) {
		String restStr = "";
		// windows下的文本文件换行符
		//String enterStr = "\r\n";
		// linux/unix下的文本文件换行符
		String enterStr = "\r";
		int xh = 1 ;
		for(int x =0;x<2;x++) {
			for(int i = 0; i<objects.size();i++) {
				if(Integer.valueOf(objects.get(i)[8].toString())==0) {
					// 经度
					String lng = objects.get(i)[0].equals("") ? "0" : objects.get(i)[0].toString();
					
					// 纬度
					String lat = objects.get(i)[1].equals("") ? "0" : objects.get(i)[1].toString();
					
					Point point = new Point(Double.valueOf(lng), Double.valueOf(lat));
					lat = "\t" +  lat;
					// 站点类型
					String stationMakeStr =  objects.get(i)[3].equals("") ? "" : objects.get(i)[3].toString();
					String stationMake = "";
					if(stationMakeStr.equals("E")) {
						stationMake = "\t2";
					}else {
						stationMake ="\t1";
					}
					// 站点序号 
					// String stationNo =  objects.get(i)[4].equals("") ? "" : objects.get(i)[4].toString();
					String stationNo = "\t" + xh;
					// 站点编码
					String stationCode = objects.get(i)[5].equals("") ? "" : objects.get(i)[5].toString();
					int len = stationCode.length();
					if(len<8) {
						int dx = 8 - len;
						String addStr = "";
						for(int p =0;p<dx;p++) {
							addStr  = addStr + "0";
						}
						stationCode = addStr + stationCode;
					}else if(len>8){
						stationCode = stationCode.substring(8);
					}
					stationCode =  "\t" +stationCode;
					double dis = objects.get(i)[6]==null  ? 0.0 : Double.parseDouble(objects.get(i)[6].toString())*1000;
					String tempDistc = String.valueOf((int) dis);
					// 站点距离
					String staitondistance = "\t" + tempDistc;
					// 站点名称
					String stationName =  objects.get(i)[7].equals("") ? "" : objects.get(i)[7].toString();
					stationName = "\t" +stationName;
					// 限速
					String sleepStr = "";
					// 方向
					int directions = objects.get(i)[8]==null ? null : Integer.valueOf(objects.get(i)[8].toString());
					if (directions == 1) {
						stationName = stationName.replaceAll("\\(起点站\\)", "").replaceAll("\\(终点站\\)", "").replaceAll("(起点站)", "").replaceAll("(终点站)", "");
					}
					/** 获取路段路由信息 @pararm:<lineId:线路ID;directions:方向> */
					List<Object[]> sobje = sectionRouteRepository.sectionRouteVector(lineId,directions);
					if(sobje.size()==1) {
//						int dsleepStr = sobje.get(0)[2] == null || sobje.get(0)[2].equals("") ? 60 : Integer.valueOf(sobje.get(0)[2].toString());
//						sleepStr =  "\t" +  String.valueOf(dsleepStr);
						double dsleepStrt = sobje.get(0)[2] == null ? 60d : Double.valueOf(sobje.get(0)[2].toString());
						sleepStr =  "\t" +  new DecimalFormat("0").format(dsleepStrt);
					}else if(sobje.size()>1){
						for(int j =0;j<sobje.size();j++) {
							double dsleepStrt = sobje.get(j)[2] == null || sobje.get(j)[2].equals("") ? 60d : Double.valueOf(sobje.get(j)[2].toString());
							String pointsStr = sobje.get(j)[1]==null || sobje.get(j)[1].equals("") ? null : sobje.get(j)[1].toString();
							pointsStr = pointsStr.substring(11, pointsStr.length()-1);
							List<Point> ps = new ArrayList<>();
							String[] pArray = pointsStr.split(",");
							for(int a = 0; a <pArray.length; a++) {
								String[] tmepA = pArray[a].split(" ");
								Point temp = new Point(Double.valueOf(tmepA[0]), Double.valueOf(tmepA[1]));
								ps.add(temp);
							}
							if(GeoUtils.isInSection(ps, point)) {
								sleepStr = "\t" + String.valueOf((int)dsleepStrt);
								break;
							}
						}
					}
					if(sleepStr.equals("")) 
						sleepStr  =  "\t" + "60";
					xh++;
					restStr = restStr + lng + lat + stationMake + stationNo + stationCode + staitondistance + sleepStr + stationName + enterStr;
				}
			}
		}
		System.out.println(restStr);
		return restStr;
	}
	
	public boolean isPointOnPolyline (Map<String, Object> point, List<Map<String, Object>> listMap ){
		
		boolean success = false;
		
		for(int l = 0; l < listMap.size() - 1; l	++){
			
			Map<String, Object> tempM = listMap.get(l);
			
			Map<String, Object> nextTempM = listMap.get(l+1);
			
			 if (Double.valueOf(point.get("lng").toString())>= Math.min(Double.valueOf(tempM.get("lng").toString()), Double.valueOf(nextTempM.get("lng").toString())) && Double.valueOf(point.get("lng").toString()) <= Math.max(Double.valueOf(tempM.get("lng").toString()), Double.valueOf(nextTempM.get("lng").toString())) &&
					 Double.valueOf(point.get("lat").toString()) >= Math.min(Double.valueOf(tempM.get("lat").toString()), Double.valueOf(nextTempM.get("lat").toString())) &&  Double.valueOf(point.get("lat").toString()) <= Math.max(Double.valueOf(tempM.get("lat").toString()), Double.valueOf(nextTempM.get("lat").toString()))){
				 
				 
				 double precision = (Double.valueOf(tempM.get("lng").toString()) - Double.valueOf(point.get("lng").toString())) * (Double.valueOf(nextTempM.get("lat").toString()) - Double.valueOf(point.get("lat").toString())) - 
		                    (Double.valueOf(nextTempM.get("lng").toString()) - Double.valueOf(tempM.get("lng").toString())) * (Double.valueOf(tempM.get("lat").toString()) - Double.valueOf(nextTempM.get("lat").toString()));
				 
				 if(precision < 2e-10 && precision > -2e-10){
					 
					//实质判断是否接近0
					 success = true;
	                
				 }  
				 
			 }
			
		}
		
		return success;
	}
	
	/**
	 * @Description:TOOD(获取FTP登录参数) 这里暂时只做一个map值返回,以后可以作为ftp登录类提出来
	 * 
	 * @return : Map<String, Object> <url:IP;port:端口;username:用户名;password:密码;remotePath:相对路径>
	 */
	public Map<String, Object> readPropertiesGetFTPParam(){
		
		// 返回值map
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		Properties env = new Properties();
		
		try {
			
			env.load(DBUtils_MS.class.getClassLoader().getResourceAsStream("ftp.properties"));
			
			resultMap.put("url", env.getProperty("ftp.url"));
			
			resultMap.put("port", env.getProperty("ftp.port"));
			
			resultMap.put("username", env.getProperty("ftp.username"));
			
			resultMap.put("password", env.getProperty("ftp.password"));
			
			resultMap.put("remotePath", env.getProperty("ftp.path"));
			
		} catch (Exception e) {

			e.printStackTrace();
			
		}
		
		return resultMap ;
	}

	@Override
	public Map<String, Object> findByMultiLine(String lineIds) {
		Map<String, Object> rs = new HashMap<>();
		try{
			List<String> idx = Splitter.on(',').splitToList(lineIds);
			//路由
			List<StationRoute> list = new ArrayList<>();


			/**
			 * in 查询符 无法和 @EntityGraph 同时配合使用,这可能是一个bug
			 * 暂时只能循环单线路查询
			 */
			//stationRouteRepository.multiLine(idx)
			for(String id : idx){
				list.addAll(stationRouteRepository.findByLineCode(id));
			}

			for(StationRoute sr : list){
				sr.setLine(null);
			}
			//过滤部分字段
			/*String jsonStr = JSON.toJSONString(list, new PropertyFilter() {
				
				@Override
				public boolean apply(Object object, String name, Object value) {
					if(name.equals("line"))
						return false;
					return true;
				}
			});*/
			
			rs.put("status", ResponseCode.SUCCESS);
			rs.put("list", list);
		}catch(Exception e){
			logger.error("", e);
			rs.put("status", ResponseCode.ERROR);
		}
		
		return rs;
	}

	public void matchCode(List<StationRoute> stationRoutes,List<StationMatchData> stationMatchData, List<StationRoute> listMactah){
		int listsSize = stationRoutes.size();
		if(listsSize > 0 && stationMatchData.size() > 0){
			if(stationMatchData.size() == listsSize){
				for (int i=0; i<listsSize; i++) {
					if(!StringUtils.isEmpty(stationMatchData.get(i).getStationStandardCode())){
						stationRoutes.get(i).setIndustryCode(stationMatchData.get(i).getStationStandardCode());
						listMactah.add(stationRoutes.get(i));
					}
				}
			} else {
				Map<String,String> smdMap = new HashMap<>();
				for (int i=0; i<listsSize; i++) {

					String name = stationRoutes.get(i).getStationName();
					String names[] = null;
					if(name.indexOf("(") != -1){
						names = name.split("(");
					} else if(name.indexOf("(") != -1){
						names = name.split("\\(");
					}

					for (StationMatchData smd:stationMatchData) {
						smdMap.put(smd.getStationName(),smd.getStationStandardCode());
						String stationName =smd.getStationName();
						String stationName2 =smd.getStationName2();
						String industryCode =smd.getStationStandardCode();
						if(StringUtils.isEmpty(industryCode)){
							continue;
						}
						if(names != null && names.length > 1){
//							if(stationRoutes.get(i).getStationMark().equals(smd.getStationType()) && (stationName.indexOf(names[0]) != -1 || stationName.indexOf(names[1].substring(0,names[1].length()-1)) != -1 || stationName2.indexOf(names[0]) != -1 || stationName2.indexOf(names[1].substring(0,names[1].length()-1)) != -1)){
							if((stationName.indexOf(names[0]) != -1 || stationName.indexOf(names[1].substring(0,names[1].length()-1)) != -1 || stationName2.indexOf(names[0]) != -1 || stationName2.indexOf(names[1].substring(0,names[1].length()-1)) != -1)){
								stationRoutes.get(i).setIndustryCode(industryCode);
								listMactah.add(stationRoutes.get(i));
								break;
							}
						}else {
//							if(stationRoutes.get(i).getStationMark().equals(smd.getStationType()) && (stationName.indexOf(name) != -1 || stationName2.indexOf(name) != -1)){
							if(stationName.indexOf(name) != -1 || stationName2.indexOf(name) != -1){
//							if(stationRoutes.get(i).getStationMark().equals(smd.getStationType()) && (name.equals(stationName) || name.equals(stationName2))){

								stationRoutes.get(i).setIndustryCode(industryCode);
								listMactah.add(stationRoutes.get(i));
								break;
							}
						}
					}
				}
			}
		}
	}

	private String subLine2Ftp(LineRegion lineRegion) {
		StringBuilder builder = new StringBuilder();
		int len = lineRegion.getStationRoutes().size();
		int idx = 1;
		for (int i = 0;i < len;i++) {
			LsStationRoute route = lineRegion.getStationRoutes().get(i);
			builder.append(route.getCenterPointWgs().getPosition().getCoordinate(0))
			.append("\t").append(route.getCenterPointWgs().getPosition().getCoordinate(1))
			.append("\t").append(i == len - 1 ? 2 : 1)
			.append("\t").append(idx).append("\t");
			for (int j = 0;j < 8 - route.getStationCode().length();j++) {
				builder.append("0");
			}
			builder.append(route.getStationCode())
			.append("\t").append((int) route.getDistances().doubleValue() * 1000)
			.append("\t0")
			.append("\t").append(route.getStationName())
			.append("\t").append(route.getStationNameEn())
			.append("\r\n");

			idx++;
		}

		return builder.toString();
	}
}