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

import com.railway.business.baseinfo.domain.BaseDeptLine;
import com.railway.business.baseinfo.domain.BaseLine;
import com.railway.business.baseinfo.domain.vo.BaseLineQuery;
import com.railway.business.baseinfo.domain.vo.BaseLineVo;
import com.railway.business.baseinfo.service.IBaseLineService;
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.PathVariable;
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/line")
public class BaseLineController extends BaseController {

  private final IBaseLineService busLineService;

  public BaseLineController(IBaseLineService busLineService) {
    this.busLineService = busLineService;
  }

  @ApiOperation(value = "新增")
  @PostMapping("/add")
  public AjaxResult add(@Validated @RequestBody BaseLineVo busLine) {
    return toAjax(busLineService.create(busLine));
  }

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

  @ApiOperation(value = "更新")
  @PutMapping("/update")
  public AjaxResult update(@RequestBody @Valid BaseLineVo busLine) {
    return toAjax(busLineService.update(busLine));
  }

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

  @ApiOperation(value = "线路管理列表")
  @GetMapping(value = "list")
  public TableDataInfo getDetailList(BaseLineQuery query) {
    startPage();
    List<BaseLineVo> list = busLineService.getDetailList(query);
    return getDataTable(list);
  }

  @ApiOperation(value = "下拉列表")
  @GetMapping(value = {"/getListByDeptId/", "/getListByDeptId/{deptId}"})
  public TableDataInfo getListByDeptId(Long deptId) {
    startPage();
    List<BaseLine> list = busLineService.getListByDeptId(deptId);
    return getDataTable(list);
  }

  @ApiOperation(value = "线路所属车间下拉列表")
  @GetMapping(value = "/getDeptByLineId/{lineId}")
  public TableDataInfo getDeptByLineId(@PathVariable Long lineId) {
    startPage();
    List<BaseDeptLine> list = busLineService.getDeptByLineId(lineId);
    return getDataTable(list);
  }

}
