SectionRouteServiceImpl.java 5.3 KB
package com.bsth.service.impl;

import com.bsth.common.ResponseCode;
import com.bsth.entity.Line;
import com.bsth.entity.LsSectionRoute;
import com.bsth.entity.Section;
import com.bsth.entity.SectionRoute;
import com.bsth.entity.search.CustomerSpecs;
import com.bsth.repository.LineRepository;
import com.bsth.repository.LsSectionRouteRepository;
import com.bsth.repository.SectionRepository;
import com.bsth.repository.SectionRouteRepository;
import com.bsth.service.SectionRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

@Service
public class SectionRouteServiceImpl extends BaseServiceImpl<SectionRoute, Integer> implements SectionRouteService {

	@Autowired
	SectionRouteRepository sectionRouteRepository;

	@Autowired
	LsSectionRouteRepository lsSectionRouteRepository;

	@Autowired
	SectionRepository sectionRepository;

	@Autowired
	LineRepository lineRepository;
	
	@Override
	public Iterable<SectionRoute> 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, "sectionrouteCode"));

		return sectionRouteRepository.findAll(new CustomerSpecs<>(map), Sort.by(orders));
	}

	/**
	 * @Description :TODO(查询路段信息)
	 * 
	 * @param map <line.id_eq:线路ID; directions_eq:方向>
	 * 
	 * @return Map<String, Object>
	 */
	@Override
	public List<Map<String, Object>> getSectionRoute(Map<String, Object> map) {
		int lineId = map.get("line.id_eq").equals("") ? 0 : Integer.parseInt(map.get("line.id_eq").toString());
		int directions = map.get("directions_eq").equals("") ? 0
				: Integer.parseInt(map.get("directions_eq").toString());
		List<Object[]> listObjArray = sectionRouteRepository.getSectionRoute(lineId, directions);
		List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
		if (listObjArray.size() > 0) {
			for (int i = 0; i < listObjArray.size(); i++) {
				Map<String, Object> tempM = new HashMap<String, Object>();
				tempM.put("sectionrouteId", listObjArray.get(i)[0]);
				tempM.put("sectionrouteLine", listObjArray.get(i)[1]);
				tempM.put("sectionrouteLineCode", listObjArray.get(i)[2]);
				tempM.put("sectionrouteSection", listObjArray.get(i)[3]);
				tempM.put("sectionrouteSectionCode", listObjArray.get(i)[4]);
				tempM.put("sectionrouteCode", listObjArray.get(i)[5]);
				tempM.put("sectionrouteDirections", listObjArray.get(i)[6]);
				tempM.put("sectionId", listObjArray.get(i)[7]);
				tempM.put("sectionCode", listObjArray.get(i)[8]);
				tempM.put("sectionName", listObjArray.get(i)[9]);
				tempM.put("sectionCrosesRoad", listObjArray.get(i)[10]);
				tempM.put("sectionEndNode", listObjArray.get(i)[11]);
				tempM.put("sectionStartNode", listObjArray.get(i)[12]);
				tempM.put("sectionMiddleNode", listObjArray.get(i)[13]);
				tempM.put("sectionType", listObjArray.get(i)[14]);
				tempM.put("sectionCsectionVector", listObjArray.get(i)[15]);
				tempM.put("sectionBsectionVector", listObjArray.get(i)[16]);
				tempM.put("sectionGsectionVector", listObjArray.get(i)[17]);
				tempM.put("sectionRoadCoding", listObjArray.get(i)[18]);
				tempM.put("sectionDistance", listObjArray.get(i)[19]);
				tempM.put("sectionTime", listObjArray.get(i)[20]);
				tempM.put("sectiondbType", listObjArray.get(i)[21]);
				tempM.put("sectionSpeedLimit", listObjArray.get(i)[22]);
				tempM.put("destroy", listObjArray.get(i)[23]);
				tempM.put("versions", listObjArray.get(i)[24]);
				tempM.put("descriptions", listObjArray.get(i)[25]);
				tempM.put("isRoadeSpeed", listObjArray.get(i)[26]);
				resultList.add(tempM);
			}
		}
		return resultList;
	}

	/**
	 * @Description :TODO(查询线路某方向下的上一个路段序号)
	 * 
	 * @param map <lineId:线路ID; direction:方向;sectionRouteCode:路段编码>
	 * 
	 * @return List<Map<String, Object>>
	 */
	@Override
	public List<Map<String, Object>> findUpSectionRouteCode(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("sectionRouteCode").equals("") ? null
				: Integer.parseInt(map.get("sectionRouteCode").toString());
		List<Object[]> reslutList = sectionRouteRepository.findUpSectionRouteCode(lineId, direction, stationRouteCode);
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		if (reslutList.get(0) != null) {
			for (int i = 0; i < reslutList.size(); i++) {
				Map<String, Object> tempM = new HashMap<String, Object>();
				tempM.put("sectionrouteCode", reslutList.get(i));
				list.add(tempM);
			}
		}
		return list;
	}
}