package com.railway.web.controller.business.baseinfo;

import com.railway.business.baseinfo.domain.BaseStation;
import com.railway.business.baseinfo.domain.vo.BaseStationQuery;
import com.railway.business.baseinfo.domain.vo.BaseStationVo;
import com.railway.business.baseinfo.service.IBaseStationService;
import com.railway.common.core.controller.BaseController;
import com.railway.common.core.domain.AjaxResult;
import com.railway.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaomn
 */
@Api(tags = "基础管理 - 区间站场信息")
@RestController
@Validated
@RequestMapping(value = "business/catenary/bus/station")
public class BaseStationController extends BaseController {

  private final IBaseStationService busStationService;

  public BaseStationController(IBaseStationService busStationService) {
    this.busStationService = busStationService;
  }

  @ApiOperation(value = "新增")
  @PostMapping("/add")
  public AjaxResult add(@Validated @RequestBody BaseStationVo baseStationVo) {
    return toAjax(busStationService.create(baseStationVo));
  }

  @ApiOperation(value = "删除")
  @DeleteMapping("/{stationIds}")
  public AjaxResult delete(@RequestParam Long[] stationIds) {
    return toAjax(busStationService.delete(stationIds));
  }

  @ApiOperation(value = "更新")
  @PutMapping("/update")
  public AjaxResult update(@RequestBody @Valid BaseStationVo baseStationVo) {
    return toAjax(busStationService.update(baseStationVo));
  }

  @ApiOperation(value = "单个")
  @GetMapping(value = {"/", "/{stationId}"})
  public AjaxResult getInfo(Long stationId) {
    BaseStation info = busStationService.getInfo(stationId);
    AjaxResult ajax = AjaxResult.success();
    ajax.put("info", info);
    return ajax;
  }

  @ApiOperation(value = "管理列表")
  @GetMapping(value = "list")
  public TableDataInfo getDetailList(BaseStationQuery query) {
    startPage();
    List<BaseStationVo> list = busStationService.getDetailList(query);
    return getDataTable(list);
  }

  @ApiOperation(value = "下拉列表")
  @GetMapping("/getListByDeptId")
  public TableDataInfo getListByDeptId(BaseStationQuery query) {
    startPage();
    List<BaseStation> list = busStationService.getListByDeptId(query);
    return getDataTable(list);
  }

}
