LineRegionController.java 1.89 KB
package com.bsth.controller;

import com.bsth.common.ResponseCode;
import com.bsth.entity.LineRegion;
import com.bsth.entity.LsStationRoute;
import com.bsth.service.LineRegionService;
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 java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Hill
 */
@RestController
@RequestMapping("/api/lineregion")
public class LineRegionController extends BaseController<LineRegion, Integer> {

	private Logger log = LoggerFactory.getLogger(LineRegionController.class);

	@Autowired
	private LineRegionService lineRegionService;

	@RequestMapping(path = "findStationRoutes")
	public List<LsStationRoute> findStationRoutes(@RequestParam(defaultValue = "id") Integer regionId) {
		return lineRegionService.findStationRoutes(regionId);
	}

	@RequestMapping(path = "add", method = RequestMethod.POST)
	public Map<String, Object> add(LineRegion lineRegion) {
		Map<String, Object> result = new HashMap<>();
		try {
			lineRegionService.add(lineRegion);
			result.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			log.error("添加线路区间异常", e);
			result.put("status", ResponseCode.ERROR);
		}

		return result;
	}

	@RequestMapping(path = "modify", method = RequestMethod.POST)
	public Map<String, Object> modify(LineRegion lineRegion) {
		Map<String, Object> result = new HashMap<>();
		try {
			lineRegionService.save(lineRegion);
			result.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			log.error("变更线路区间异常", e);
			result.put("status", ResponseCode.ERROR);
		}

		return result;
	}
}