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

import com.railway.business.baseinfo.domain.BaseDeptStation;
import com.railway.business.baseinfo.domain.BusBlq;
import com.railway.business.baseinfo.domain.BusZzdzxx;
import com.railway.business.baseinfo.domain.vo.BusSmartQueryVo;
import com.railway.business.baseinfo.service.IBaseStationService;
import com.railway.business.baseinfo.service.IBusZzdzxxService;
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.RestController;

/**
 * @author wuhonghao
 */
@Api(value = "rest/catenary/bus/zzdzxx", tags = "基础管理 - 支柱吊柱信息")
@RestController
@Validated
@RequestMapping(value = "business/catenary/bus/zzdzxx")
public class BusZzdzxxController extends BaseController {

  private final IBusZzdzxxService busZzdzxxService;
  private final IBaseStationService stationService;

  public BusZzdzxxController(IBusZzdzxxService busZzdzxxService,
      IBaseStationService stationService) {
    this.busZzdzxxService = busZzdzxxService;
    this.stationService = stationService;
  }

  @ApiOperation(value = "新增")
  @PostMapping("/add")
  public AjaxResult add(@Validated @RequestBody BusZzdzxx busZzdzxx) {
    BaseDeptStation deptStation = stationService.getInfo(busZzdzxx.getDeptId(),
        busZzdzxx.getLineId(), busZzdzxx.getStationId());
    busZzdzxx.setDeptStationId(deptStation.getId());
    return toAjax(busZzdzxxService.create(busZzdzxx));
  }

  @ApiOperation(value = "删除")
  @DeleteMapping("/{ids}")
  public AjaxResult delete(@PathVariable String[] ids) {
    return toAjax(busZzdzxxService.delete(ids));
  }

  @ApiOperation(value = "更新")
  @PutMapping("/update")
  public AjaxResult update(@RequestBody @Valid BusZzdzxx busZzdzxx) {
    BaseDeptStation deptStation = stationService.getInfo(busZzdzxx.getDeptId(),
        busZzdzxx.getLineId(), busZzdzxx.getStationId());
    busZzdzxx.setDeptStationId(deptStation.getId());
    return toAjax(busZzdzxxService.update(busZzdzxx));
  }

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

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

  @ApiOperation(value = "智能查询")
  @GetMapping(value = "smartQuery")
  public TableDataInfo smartQuery(BusSmartQueryVo busSmartQueryVo) {
    startPage();
    List<BusZzdzxx> list = busZzdzxxService.smartQuery(busSmartQueryVo);
    return getDataTable(list);
  }

}
