SectionController.java 2.8 KB
package com.bsth.controller;

import com.bsth.common.ResponseCode;
import com.bsth.entity.Section;
import com.bsth.entity.Station;
import com.bsth.repository.SectionRepository;
import com.bsth.service.SectionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * @ClassName: SectionController(路段控制器)
 * 
 * @Extends : BaseController
 * 
 * @Description: TODO(路段控制层)
 * 
 * @Author bsth@lq
 * 
 * @Date 2016年05月03日 上午9:21:17
 *
 * @Version 公交调度系统BS版 0.1
 * 
 */

@RestController
@RequestMapping("section")
public class SectionController extends BaseController<Section, Integer> {

	private final static Logger log = LoggerFactory.getLogger(SectionController.class);
	
	@Autowired
	SectionService sectionService;

	@Autowired
	SectionRepository sectionRepository;

	/**
	 * @Description :TODO(查询路段编码)
	 * 
	 * @return int <sectionCode路段编码>
	 */
	@RequestMapping(value="getSectionCode" , method = RequestMethod.GET)
	public long getSectionCode() {
		return sectionRepository.findLatestSectionId() + 1;
	}

	/**
	 * @Description :TODO(把路段截取位双路名路段)
	 *
	 * @return int <sectionCode路段编码>
	 */
	@RequestMapping(value="doubleName" , method = RequestMethod.POST)
	public Map<String, Object> doubleName(@RequestParam Map<String, Object> map) {
		return sectionService.doubleName(map);
	}

	@RequestMapping(value="add" , method = RequestMethod.POST)
	public Map<String, Object> add(Section section) {
		Map<String, Object> result = new HashMap<>();
		try {
			sectionService.add(section);
			result.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			result.put("status", ResponseCode.ERROR);
			log.error("", e);
		}

		return result;
	}

	@RequestMapping(value="modify" , method = RequestMethod.POST)
	public Map<String, Object> modify(Section section) {
		Map<String, Object> result = new HashMap<>();
		try {
			sectionService.modify(section);
			result.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			result.put("status", ResponseCode.ERROR);
			log.error("", e);
		}

		return result;
	}

	/**
	 * 根据路段名模糊搜索路段信息
	 * @param sectionName
	 * @return 站点列表
	 */
	@RequestMapping(value="findSectionByName" , method = RequestMethod.GET)
	public List<Section> findSectionByName(String sectionName) {
		return sectionService.findSectionByName(sectionName);
	}
}