LineController.java 1.75 KB
package com.bsth.controller;

import java.util.HashMap;
import java.util.Map;

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 com.bsth.common.ResponseCode;
import com.bsth.entity.Line;
import com.bsth.service.LineService;
import com.bsth.util.GetUIDAndCode;

/**
 * 
 * @ClassName: LineController(线路控制器)
 * 
 * @Extends : BaseController
 * 
 * @Description: TODO(线路控制层)
 * 
 * @Author bsth@lq
 * 
 * @Date 2016年4月28日 上午9:21:17
 *
 * @Version 公交调度系统BS版 0.1
 * 
 */
@RestController
@RequestMapping("line")
public class LineController extends BaseController<Line, Integer> {
	
	@Autowired
	private LineService service;
	
	/**
	 * 获取线路编码与ID
	 * 
	 * @return int <lineCode:线路编码>
	 */
	@RequestMapping(value = "getLineCode", method = RequestMethod.GET)
	public long getLineCode() {
		return GetUIDAndCode.getLineId();
	}
	
	/**
	 * 
	 * 保存
	 * 
	 */
	@RequestMapping(method = RequestMethod.POST)
	public Map<String, Object> save(Line t){
		Map<String, Object> map = new HashMap<>();
		if(t.getId()==null) {
			
			t.setId(Integer.valueOf(t.getLineCode()));
			
		}
		if( (t.getId().toString().length()) > 6) {
			
			map.put("status", ResponseCode.ERROR); 
			return map;
		}
		return service.save(t);
	} 
	
	@RequestMapping(value ="/findById" , method = RequestMethod.GET)
	Line findByID(@RequestParam(defaultValue = "id") Integer id){
		return service.findById(id);
	}
}