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

import com.railway.business.catenary.domain.BusJcebQmjcjl;
import com.railway.business.catenary.domain.vo.JcebQueryVo;
import com.railway.business.catenary.service.IBusJcebQmjcjlService;
import com.railway.common.core.controller.BaseController;
import com.railway.common.core.domain.AjaxResult;
import com.railway.common.core.page.TableDataInfo;
import com.railway.system.service.ISysFileService;
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 fenghao
 */
@Api(value = "rest/catenary/bus/jceb/qmjcjl", tags = "检测表 - 全面检查记录")
@RestController
@Validated
@RequestMapping(value = "business/catenary/bus/jceb/qmjcjl")
public class BusJcebQmjcjlController extends BaseController {

    private final IBusJcebQmjcjlService busJcbQmjcjlService;
    private final ISysFileService sysFileService;

    public BusJcebQmjcjlController(IBusJcebQmjcjlService busJcbQmjcjlService, ISysFileService sysFileService) {
        this.busJcbQmjcjlService = busJcbQmjcjlService;
        this.sysFileService = sysFileService;
    }

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody BusJcebQmjcjl busJcebQmjcjl) {
        return toAjax(busJcbQmjcjlService.create(busJcebQmjcjl));
    }

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

    @ApiOperation(value = "更新")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody @Valid BusJcebQmjcjl busJcebQmjcjl) {
        return toAjax(busJcbQmjcjlService.update(busJcebQmjcjl));
    }

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

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

    @ApiOperation(value = "导出excel")
    @GetMapping(value = "exportExcel")
    public AjaxResult exportExcel(JcebQueryVo query) {
        String localFilePath = busJcbQmjcjlService.exportExcel(query);
        return sysFileService.uploadFile(localFilePath);
    }

    @ApiOperation(value = "提交")
    @PutMapping("/submit")
    public AjaxResult submit(@RequestBody BusJcebQmjcjl busJcebQmjcjl) {
        return toAjax(busJcbQmjcjlService.submit(busJcebQmjcjl));
    }

    @ApiOperation(value = "退回")
    @PutMapping("/reject")
    public AjaxResult reject(@RequestBody BusJcebQmjcjl busJcebQmjcjl) {
        return toAjax(busJcbQmjcjlService.reject(busJcebQmjcjl));
    }

    @ApiOperation(value = "确认")
    @PutMapping("/confirm")
    public AjaxResult confirm(@RequestBody BusJcebQmjcjl busJcebQmjcjl) {
        return toAjax(busJcbQmjcjlService.confirm(busJcebQmjcjl));
    }

}
