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

import com.railway.business.catenary.domain.BusJlgz;
import com.railway.business.catenary.domain.vo.BusJlgzListByZzVo;
import com.railway.business.catenary.domain.vo.BusJlgzQueryVo;
import com.railway.business.catenary.service.IBusJlgzService;
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 fenghao
 */
@Api(value = "rest/catenary/bud/jlgz", tags = "接触网 - 记录故障")
@RestController
@Validated
@RequestMapping(value = "business/catenary/bus/jlgz")
public class BusJlgzController extends BaseController {

    private final IBusJlgzService budJlgzService;

    public BusJlgzController(IBusJlgzService budJlgzService) {
        this.budJlgzService = budJlgzService;
    }

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody BusJlgz busJlgz) {
        return toAjax(budJlgzService.create(busJlgz));
    }

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

    @ApiOperation(value = "更新")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody @Valid BusJlgz busJlgz) {
        return toAjax(budJlgzService.update(busJlgz));
    }

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

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

    @ApiOperation(value = "通过支柱信息获取历史故障统计", notes = "通过支柱信息获取历史故障统计", response = AjaxResult.class)
    @GetMapping("/getListByZz")
    public AjaxResult getListByZz(BusJlgzQueryVo busJlgzQueryVo) {
        List<BusJlgzListByZzVo> list = budJlgzService.getListByZz(busJlgzQueryVo);
        AjaxResult ajax = AjaxResult.success();
        ajax.put("info",list);
        return ajax;
    }

}
