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

import com.railway.business.baseinfo.domain.BaseDeptStation;
import com.railway.business.baseinfo.domain.BusFdfxjyq;
import com.railway.business.baseinfo.service.IBaseStationService;
import com.railway.business.baseinfo.service.IBusFdfxjyqService;
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 wuhonghao
 */
@Api(value = "rest/catenary/bus/fdfxjyq", tags = "基础管理 - 分段分相绝缘器")
@RestController
@Validated
@RequestMapping(value = "business/catenary/bus/fdfxjyq")
public class BusFdfxjyqController extends BaseController {

  private final IBusFdfxjyqService busFdfxjyqService;
  private final IBaseStationService stationService;

  public BusFdfxjyqController(IBusFdfxjyqService busFdfxjyqService,
      IBaseStationService stationService) {
    this.busFdfxjyqService = busFdfxjyqService;
    this.stationService = stationService;
  }

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

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

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

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

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

}
