TTInfoDetailServiceImpl.java 24.6 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
package com.bsth.service.schedule.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.entity.*;
import com.bsth.entity.schedule.GuideboardInfo;
import com.bsth.entity.schedule.TTInfoDetail;
import com.bsth.repository.CarParkRepository;
import com.bsth.repository.LineRepository;
import com.bsth.repository.StationRepository;
import com.bsth.repository.schedule.GuideboardInfoRepository;
import com.bsth.repository.schedule.TTInfoDetailRepository;
import com.bsth.repository.schedule.TTInfoRepository;
import com.bsth.repository.sys.SysUserRepository;
import com.bsth.service.CarParkService;
import com.bsth.service.LineInformationService;
import com.bsth.service.StationRouteService;
import com.bsth.service.schedule.GuideboardInfoService;
import com.bsth.service.schedule.TTInfoDetailService;
import com.bsth.service.schedule.datatools.TTInfoDetailForEdit;
import com.bsth.service.schedule.exception.ScheduleException;
import com.bsth.service.schedule.utils.DataToolsFile;
import com.bsth.service.schedule.utils.DataToolsFileType;
import com.bsth.service.schedule.utils.DataToolsService;
import com.bsth.service.schedule.utils.PoiUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by xu on 17/1/3.
 */
@Service
public class TTInfoDetailServiceImpl extends BServiceImpl<TTInfoDetail, Long> implements TTInfoDetailService {
    /** 日志记录器 */
    private static final Logger LOGGER = LoggerFactory.getLogger(TTInfoDetailServiceImpl.class);

    @Autowired
    private GuideboardInfoService guideboardInfoService;
    @Autowired
    private StationRouteService stationRouteService;
    @Autowired
    private LineInformationService lineInformationService;
    @Autowired
    private CarParkService carParkService;
    @Autowired
    private TTInfoDetailRepository ttInfoDetailRepository;
    @Autowired
    private LineRepository lineRepository;
    @Autowired
    private TTInfoRepository infoRepository;
    @Autowired
    private StationRepository staRepository;
    @Autowired
    private CarParkRepository carParkRepository;
    @Autowired
    private SysUserRepository sysUserRepository;
    @Autowired
    private GuideboardInfoRepository guideboardInfoRepository;

    @Autowired
    @Qualifier(value = "ttInfoDetail_dataTool")
    private DataToolsService dataToolsService;

    @Autowired
    @Qualifier(value = "ttInfoDetail_dataTool")
    private TTInfoDetailForEdit ttInfoDetailForEdit;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 查找站点和停车场集合
     * @param lineid 线路id
     * @param xldir 线路上下行
     * @return
     */
    public List<Map<String, Object>> findZdAndTcc(int lineid, int xldir, int lineversion) {
        String sql = "select * from " +
                "(" +
                "select station_code as zcode, station_name as zname, concat(station_name, '(站点)') as aname from bsth_c_ls_stationroute " +
                "where destroy = 0 and line = ? and directions = ? and versions = ? " +
                "union all " +
                "select park_code as zcode, park_name as zname, concat(park_name, '(停车场)') as aname from bsth_c_car_park " +
                "where destroy = 0 " +
                ") a ";

        return jdbcTemplate.queryForList(sql, lineid, xldir, lineversion);
    }

    @Override
    public Long findMaxFcno(Integer xlid, Long ttinfoid) {
        return ttInfoDetailRepository.findMaxFcno(xlid, ttinfoid);
    }

    @Override
    public TTInfoDetail findById(Long aLong) {
        return ttInfoDetailRepository.findOneExtend(aLong);
    }

    @Override
    public DataToolsFile uploadFile(String filename, byte[] filedata) throws ScheduleException {
        return dataToolsService.uploadFile(filename, filedata);
    }

    @Override
    public void importData(
            File file,
            Map<String, Object> params) throws ScheduleException {
        dataToolsService.importData(file, params);
    }

    @Override
    public DataToolsFile exportData(Map<String, Object> params) throws ScheduleException {
        return dataToolsService.exportData(params);
    }


    @Override
    public TTInfoDetailForEdit.EditInfo getEditInfo(Integer xlid, Long ttid, Long maxfcno) throws ScheduleException {
        return ttInfoDetailForEdit.getEditInfo(xlid, ttid, maxfcno);
    }

    public static void main(String[] args) {
        String test = "中1中111";
        System.out.println(test.replaceAll("(\\d+)$", ""));
    }

    @Override
    public void validateExcelSheet(String filename, String sheetname, Integer lineid, String linename, Integer zdlyversion) throws ScheduleException {
        try {
            File file = new File(filename);
            Workbook workbook;

            if (DataToolsFileType.XLS.isThisType(file)) {
                workbook = DataToolsFileType.XLS.getWorkBook(file);
            } else if (DataToolsFileType.XLSX.isThisType(file)) {
                workbook = DataToolsFileType.XLSX.getWorkBook(file);
            } else {
                throw new Exception("不是xls xlsx文件!");
            }

            Sheet sheet = workbook.getSheet(sheetname);
            int rowNums = sheet.getLastRowNum() + 1; // 基于0 base的,长度加1
            int colNums = sheet.getRow(0).getLastCellNum(); // 不需要加1,就是长度

            if (rowNums == 0 || colNums == 0) { // 工作区是否为空
                throw new Exception(String.format("%s 工作区没有数据!", sheetname));
            } else {
                if (rowNums <= 1 || rowNums <= 1) {
                    throw new Exception(String.format("工作区至少包含2行2列的数据"));
                } else {
                    Row firstRow = sheet.getRow(0); // 获取第一行数据列
                    for (int i = 0; i < colNums; i++) {
                        String cell_con = StringUtils.trimToEmpty(PoiUtils.getStringValueFromCell(firstRow.getCell(i))); // trimToEmpty

                        if (StringUtils.isEmpty(cell_con)) {
                            throw new Exception(String.format("第1行,第%d列数据不能为空", i + 1));
                        } else {
                            // 正则表达式去除右侧数字
//                            cell_con = cell_con.replaceAll("[\\d+]", "");
                            cell_con = cell_con.replaceAll("(\\d+)$", "");

                            if (i == 0) { // 第一列必须是路牌2个字
                                if (!"路牌".equals(cell_con.trim())) {
                                    throw new Exception("第1行,第1列数据必须是路牌2个字");
                                }
                            } else { // 排除出场,进场,其余内容到站点路由里查询,以各个方向的起点站为查询依据
                                if ((!"出场".equals(cell_con.trim())) &&
                                        (!"进场".equals(cell_con.trim()))) {
                                    Map<String, Object> p1 = new HashMap<>();
                                    p1.put("line.id_eq", lineid);
                                    p1.put("stationName_like", cell_con.trim() + "%"); // 使用模糊匹配
                                    p1.put("stationMark_eq", "B");
                                    p1.put("destroy_eq", 0); // 未撤销


                                    // TODO:这里要修改(起点站有启用撤销的标志的)

                                    if (zdlyversion == null) {
                                        List<StationRoute> stationRouteList = (List<StationRoute>) stationRouteService.list(p1);
                                        if (CollectionUtils.isEmpty(stationRouteList)) {
                                            throw new Exception(String.format("第1行,第%d列数据%s在%s站点路由中不是起点站", i + 1, cell_con.trim(), linename));
                                        } else if (stationRouteList.size() > 1) {
                                            throw new Exception(String.format("第1行,第%d列数据%s在%s站点路由中上下行都是起点站", i + 1, cell_con.trim(), linename));
                                        } else if (StringUtils.isEmpty(stationRouteList.get(0).getStationCode())) {
                                            throw new Exception(String.format("第1行,第%d列数据%s在%s站点路由中没有站点编码", i + 1, cell_con.trim(), linename));
                                        }
                                    } else {
                                        p1.put("versions_eq", zdlyversion);
                                        List<LsStationRoute> lsStationRoutes = (List<LsStationRoute>) stationRouteService.list_ls(p1);
                                        if (CollectionUtils.isEmpty(lsStationRoutes)) {
                                            throw new Exception(String.format("第1行,第%d列数据%s在%s站点路由中不是起点站", i + 1, cell_con.trim(), linename));
                                        } else if (lsStationRoutes.size() > 1) {
                                            throw new Exception(String.format("第1行,第%d列数据%s在%s站点路由中上下行都是起点站", i + 1, cell_con.trim(), linename));
                                        } else if (StringUtils.isEmpty(lsStationRoutes.get(0).getStationCode())) {
                                            throw new Exception(String.format("第1行,第%d列数据%s在%s站点路由中没有站点编码", i + 1, cell_con.trim(), linename));
                                        }
                                    }


                                }

                            }
                        }
                    }

                    // 验证路牌内容
                    Map<String, Integer> gbindexmap = new HashMap<>(); // 记录每个路牌在第几行
                    for (int i = 1; i < rowNums; i++) { // 从第2行开始验证数据
                        Cell cell = sheet.getRow(i).getCell(0); // 获取第1列
                        String bcell_con = StringUtils.trimToEmpty(PoiUtils.getStringValueFromCell(cell)); // trimToEmpty
                        if (StringUtils.isEmpty(bcell_con)) {
                            throw new Exception(String.format("第%d行,第1列路牌无数据", i + 1));
                        } else if (gbindexmap.get(bcell_con.trim()) != null) {
                            throw new Exception(String.format("第%d行,第1列的路牌数据与第%d行,第1列数据重复",
                                    i + 1,
                                    gbindexmap.get(bcell_con.trim())));
                        } else {
                            Map<String, Object> p2 = new HashMap<>();
                            p2.put("xl.id_eq", lineid);
                            p2.put("lpName_eq", bcell_con.trim());
                            p2.put("isCancel_eq", false);
                            List<GuideboardInfo> guideboardInfoList = (List<GuideboardInfo>) guideboardInfoService.list(p2);
                            if (CollectionUtils.isEmpty(guideboardInfoList)) {
                                throw new Exception(String.format("第%d行,第1列的路牌在%s中不存在", i + 1, linename));
                            } else if (guideboardInfoList.size() > 1) {
                                throw new Exception(String.format("第%d行,第1列的路牌在%s中重复", i + 1, linename));
                            } else {
                                gbindexmap.put(bcell_con.trim(), i + 1);
                            }
                        }
                    }

                    // 班次时间验证,正则表达式,格式hh:mm或者hhmm
                    String rex1 = "^([01]?[0-9]|2[0-3]):[0-5][0-9]$"; // hh:mm格式
                    String rex2 = "^([01]?[0-9]|2[0-3]),[0-5][0-9]$"; // hh,mm格式
                    String rex3 = "^([01]?[0-9]|2[0-3])[0-5][0-9]$"; // hhmm格式
                    Pattern p1 = Pattern.compile(rex1);
                    Pattern p2 = Pattern.compile(rex2);
                    Pattern p3 = Pattern.compile(rex3);

                    for (int i = 1; i < rowNums; i++) { // 从第2行开始验证数据
                        Row row = sheet.getRow(i);
                        for (int j = 1; j < colNums; j++) { // 从第2列开始
                            String bcell_con = StringUtils.trimToEmpty(PoiUtils.getStringValueFromCell(row.getCell(j))).replaceAll("\\s*", ""); // trimToEmpty
                            if (StringUtils.isNotEmpty(bcell_con)) {
                                Matcher m1 = p1.matcher(bcell_con.trim());
                                Matcher m2 = p2.matcher(bcell_con.trim());
                                Matcher m3 = p3.matcher(bcell_con.trim());
                                if ((!m1.matches()) && (!m2.matches()) && (!m3.matches())) {
                                    throw new Exception(String.format("第%d行,第%d列的发车时间格式不正确,格式应为hh:mm或hh,mm或hhmm", i + 1, j + 1));
                                }
                            }
                        }
                    }
                }

            }

        } catch (Exception exp) {
            exp.printStackTrace();
            throw new ScheduleException(exp.getMessage());
        }

    }

    @Override
    public void validateAssoLineInfo(Integer lineinfoid) throws ScheduleException {
        LineInformation lineInformation = lineInformationService.findById(lineinfoid);
        if (lineInformation.getUpInMileage() == null) {
            throw new ScheduleException("上行进场里程为空");
        } else if (lineInformation.getUpInTimer() == null) {
            throw new ScheduleException("上行进场时间为空");
        } else if (lineInformation.getUpOutMileage() == null) {
            throw new ScheduleException("上行出场里程为空");
        } else if (lineInformation.getUpOutTimer() == null) {
            throw new ScheduleException("上行出场时间为空");
        } else if (lineInformation.getUpMileage() == null) {
            throw new ScheduleException("上行班次里程为空");
        } else if (lineInformation.getUpTravelTime() == null) {
            throw new ScheduleException("上行班次时间为空");
        } else if (lineInformation.getDownInMileage() == null) {
            throw new ScheduleException("下行进场里程为空");
        } else if (lineInformation.getDownInTimer() == null) {
            throw new ScheduleException("下行进场时间为空");
        } else if (lineInformation.getDownOutMileage() == null) {
            throw new ScheduleException("下行出场里程为空");
        } else if (lineInformation.getDownOutTimer() == null) {
            throw new ScheduleException("下行出场时间为空");
        } else if (lineInformation.getDownMileage() == null) {
            throw new ScheduleException("下行班次里程为空");
        } else if (lineInformation.getDownTravelTime() == null) {
            throw new ScheduleException("下行班次时间为空");
        } else if (StringUtils.isEmpty(lineInformation.getCarPark())) {
            throw new ScheduleException("停车场必须选择");
        }

        // 单独验证停车场信息
        String tcccode = lineInformation.getCarPark();
        Map<String, Object> p1 = new HashMap<>();
        p1.put("parkCode_eq", tcccode);
        List<CarPark> carParkList = (List<CarPark>) carParkService.list(p1);
        if (CollectionUtils.isEmpty(carParkList)) {
            throw new ScheduleException(String.format("线路标准里的停车场code=%s,在停车场信息中未找到", tcccode));
        } else if (carParkList.size() > 1) {
            throw new ScheduleException(String.format("线路标准里的停车场code=%s,在停车场信息中有重复数据", tcccode));
        } else {
            CarPark carPark = carParkList.get(0);
            if (StringUtils.isEmpty(carPark.getParkName())) {
                throw new ScheduleException(String.format("线路标准里的停车场code=%s,在停车场信息中没有停车场名字", tcccode));
            }
        }

    }

    @Override
    public List<TTInfoDetail> findBcdetails(Integer xlId, Long ttinfoId, Long lpId) {
        return ttInfoDetailRepository.findBcdetails(xlId, ttinfoId, lpId);
    }

    /**
     * @description (TODO) 时刻表明细模型数据保存.
     * 
     * @param  map
     * 
     * @return : 返回保存操作后的状态.
     * 
     * @exception 处理所有抛出来的异常.
     * */
    @Transactional
   	public Map<String, Object> skbDetailMxSave(Map<String, Object> map) {
   		Map<String, Object> rs_m = new HashMap<String,Object>();
   		try {
   			// 1、获取数据.
   			String d = map.get("d") == null ? null : map.get("d").toString();
   			//boolean b = map.get("istidc") ==null ? false : Boolean.parseBoolean(map.get("istidc").toString());
   			Long ttinfoid = map.get("skb") ==null ? null : Long.parseLong(map.get("skb").toString());
   			Integer xlid = map.get("xl") ==null ? null : Integer.parseInt(map.get("xl").toString());
   			if(xlid !=null && ttinfoid !=null)  
   	    		ttInfoDetailRepository.deltidc(xlid,ttinfoid);
   	    	if(d!=null)
   	    		ttInfoDetailRepository.save(jsonArrayToListEntity(d));// 2、保存.
   		} catch (Exception e) {
   			e.printStackTrace();
   			rs_m.put("status", ResponseCode.ERROR);
   		}
   		rs_m.put("status", ResponseCode.SUCCESS);
   		return rs_m;
   	}
   	
    /**
     * @description : (TODO) json班次数据转list班次.
     * 
     * @param  jsonStr 班次json字符串]
     * 
     * @return 返回一个list分装的班次数据.
     * 
     * @status OK.
     * */
   	public List<TTInfoDetail> jsonArrayToListEntity(String jsonStr) throws Exception {
   		// 1、创建list分装的时刻表明细实体对象数据.
   		List<TTInfoDetail> listTd = new ArrayList<TTInfoDetail>();
   		// 2、json字符串转json数组.
   		JSONArray jsonArray = JSONArray.parseArray(jsonStr);
   		// 3、json数组转list分装的时刻表明细实体对象数据.
   		for(int i =0; i<jsonArray.size();i++) {
   			JSONObject jsonObj = jsonArray.getJSONObject(i);
   			listTd.add(objToEntity(jsonObj));
   		}
   		return listTd;
   	}
   	
   	/**
   	 * @description : (TODO) 班次map对象转实体对象.
   	 * 
   	 * @param obj 班次map对象.
   	 * 
   	 * @return 返回一个班次实体对象.
   	 * 
   	 * @exception 异常暂先抛出去.
   	 * */
   	public TTInfoDetail objToEntity(JSONObject obj) throws Exception {
   		// 1、创建班次实体对象.
   		TTInfoDetail td = new TTInfoDetail();
   		// 2、获取线路id键值,并查询出该线路的实体对象.
   		Line xl = lineRepository.findOne(Integer.parseInt(obj.getString("xl"))); 
   		// 3、设置线路.
   		td.setXl(xl);
   		// 4、设置时刻表.
   		td.setTtinfo(obj.getString("ttinfo") == null ? null : infoRepository.findOne(Long.parseLong(obj.getString("ttinfo"))));
   		// 5、设置路牌.
   		td.setLp(obj.getString("lp") == null ? getLp(xl,obj.getString("lpName"),Integer.parseInt(obj.getString("lpNo")),obj.getString("lpType")) :
   			guideboardInfoRepository.findOne(Long.parseLong(obj.getString("lp"))));
   		// 6、设置发车序号.
   		td.setFcno(obj.getString("fcno") == null ? null : Integer.parseInt(obj.getString("fcno")));
   		// 7、设置线路方向
   		td.setXlDir(dirToCod(obj.get("xlDir").toString()));
   		// 8、设置起始站.
   		td.setQdz(obj.getString("qdz") ==null? null : staRepository.findOne(Integer.parseInt(obj.getString("qdz"))));
   		// 9、设置终点站.
   		td.setZdz(obj.getString("zdz") ==null ? null :staRepository.findOne(Integer.parseInt(obj.getString("zdz"))));
   		// 10、设置停车场.
   		td.setTcc(obj.getString("tcc") == null ? null : carParkRepository.findOne(Integer.parseInt(obj.getString("tcc"))));
   		// 11、设置发车时间.
   		td.setFcsj(obj.getString("fcsj")==null ? null : obj.getString("fcsj"));
   		// 12、设置班次序号.
   		td.setBcs(obj.getString("bcs") == null ? null : Integer.parseInt(obj.getString("bcs")));
   		// 13、设置计划里程.
   		td.setJhlc(obj.getString("jhlc")==null ? null : Double.parseDouble(obj.getString("jhlc")));
   		// 14、设置班次历时.
   		td.setBcsj(obj.getString("bcsj") == null ? null : Integer.parseInt(obj.getString("bcsj")));
   		// 15、设置班次类型.
   		td.setBcType(obj.getString("bcType")==null ? null : obj.getString("bcType"));
   		// 16、设置是否分班.
   		td.setIsFB(obj.getString("isfb") ==null ? null : intToBit(Integer.parseInt(obj.getString("isfb"))));
   		// 17、设置是否切换线路.
   		td.setIsSwitchXl(obj.getString("isSwitchXl") ==null ? null : intToBit(Integer.parseInt(obj.getString("isSwitchXl"))));
   		// 18、设置切换线路.
   		td.setSwitchXl(obj.getString("witchXl") ==null? null : lineRepository.findOne(Integer.parseInt(obj.getString("witchXl"))));
   		td.setSwitchXlDesc(obj.getString("switchXlDesc")==null ? null : obj.getString("switchXlDesc"));
   		// 19、设置说明描述
   		td.setRemark(obj.getString("remark")== null ? null : obj.getString("remark"));
   		// 20、设置创建人.
   		td.setCreateBy(obj.getString("createBy") == null ? null : sysUserRepository.findOne(Integer.parseInt(obj.getString("remark"))));
   		// 21、设置修改人.
   		td.setUpdateBy(obj.getString("updateBy") == null ? null : sysUserRepository.findOne(Integer.parseInt(obj.getString("updateBy"))));
   		// 22、返回实体对象.
   		return td;
   	}
   	
   	/**
   	 * @description : (TODO) int转boolean类型.
   	 * 
   	 * @param value--int类型的数值]
   	 * 
   	 * @return : 返回一个布尔类型值.
   	 * */
   	public Boolean intToBit(int value) {
   		Boolean tag = null;
   		if(value==0)
   			tag = false;
   		else if(value ==1)
   			tag = true;
   		return tag;
   	} 
   	
   	/**
   	 * @description (TODO) 获取路牌.
   	 * 
   	 * @param xl --线路,name--路牌名称,code--路牌编码,lpType--路牌类型]
   	 * 
   	 * @return 返回路牌.
   	 * */
   	public GuideboardInfo getLp(Line xl,String name, int code, String lpType) throws Exception {
   		// 1、创建路牌实体对象.
   		GuideboardInfo entity = new GuideboardInfo();
   		// 2、验证是否存在该路牌.如果数据库存在,则使用已有的.否则保存一块新的路牌.
   		List<GuideboardInfo> lgi = guideboardInfoRepository.validateLp(xl, name, code,lpType);
   		if(lgi.size()>0) {
   			entity = lgi.get(0);
   		}else{
   			// 1、设置线路.
   			entity.setXl(xl);
   			// 2、设置路牌编码.
   			entity.setLpNo(code);
   			// 3、设置路牌名称.
   			entity.setLpName(name);
   			// 4、设置路牌类型.
   			entity.setLpType(lpType);
   			// 5、标记是否已删除.
   			entity.setIsCancel(false);
   			// 6、设置创建人.
   			entity.setCreateBy(null);
   			// 7、设置修改人.
   			entity.setUpdateBy(null);
   			// 8、保存路牌.
   			guideboardInfoRepository.save(entity);
   		} 
   		// 9、返回路牌.
   		return entity;
   	}
   	
   	/**
   	 * @description : (TODO) 线路方向转代码.
   	 * 
   	 * @param str--方向字符串]
   	 * 
   	 * @return 返回方向代码.
   	 * 
   	 * @exception 异常暂先抛出.
   	 * */
   	public String dirToCod(String str) throws Exception {
   		String c = "";
   		if(str.equals("relationshipGraph-up"))
   			c = "0";// 上行.
   		else if(str.equals("relationshipGraph-down"))
   			c = "1";// 下行.
   		return c;
   	}
}