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

import com.railway.business.baseinfo.domain.BaseSubstation;
import com.railway.business.baseinfo.domain.vo.BaseDeptSubstationVo;
import com.railway.business.baseinfo.service.IBaseSubstationService;
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 org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zhaomn
 */
@Api(tags = "基础管理 - 变电所信息")
@RestController
@Validated
@RequestMapping(value = "business/catenary/bus/substation")
public class BaseSubstationController extends BaseController {

  private final IBaseSubstationService busSubstationService;

  public BaseSubstationController(IBaseSubstationService busSubstationService) {
    this.busSubstationService = busSubstationService;
  }

  @ApiOperation(value = "新增")
  @PostMapping("/add")
  public AjaxResult add(@Validated @RequestBody BaseSubstation baseSubstation) {
    return toAjax(busSubstationService.create(baseSubstation));
  }

  @ApiOperation(value = "删除")
  @DeleteMapping("/{substationIds}")
  public AjaxResult delete(@RequestParam String[] substationIds) {
    return toAjax(busSubstationService.delete(substationIds));
  }

  @ApiOperation(value = "更新")
  @PutMapping("/update")
  public AjaxResult update(@RequestBody @Valid BaseSubstation baseSubstation) {
    return toAjax(busSubstationService.update(baseSubstation));
  }

  @ApiOperation(value = "单个")
  @GetMapping(value = {"/", "/{substationId}"})
  public AjaxResult getInfo(String substationId) {
    BaseSubstation info = busSubstationService.getInfo(substationId);
    AjaxResult ajax = AjaxResult.success();
    ajax.put("info", info);
    return ajax;
  }

  @ApiOperation(value = "列表")
  @GetMapping(value = "list")
  public TableDataInfo getList(BaseSubstation baseSubstation) {
    startPage();
    List<BaseSubstation> list = busSubstationService.getList(baseSubstation);
    return getDataTable(list);
  }

  @ApiOperation(value = "通过线别id查询变电所列表")
  @GetMapping(value = "getDeptSubList")
  public TableDataInfo getDeptSubList(BaseSubstation baseSubstation) {
    startPage();
    List<BaseDeptSubstationVo> list = busSubstationService.getDeptSubList(baseSubstation.getLineId());
    return getDataTable(list);
  }

}
