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

import com.railway.business.catenary.domain.BusJcebJyzqsjl;
import com.railway.business.catenary.domain.vo.JcebQueryVo;
import com.railway.business.catenary.service.IBusJcebJyzqsjlService;
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 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/jceb/jyzqsjl", tags = "检测表 - 绝缘子清扫记录")
@RestController
@Validated
@RequestMapping(value = "business/catenary/bus/jceb/jyzqsjl")
public class BusJcebJyzqsjlController extends BaseController {

    private final IBusJcebJyzqsjlService busJcebJyzqsjlService;
    private final ISysFileService sysFileService;

    public BusJcebJyzqsjlController(IBusJcebJyzqsjlService busJcebJyzqsjlService,ISysFileService sysFileService) {
        this.busJcebJyzqsjlService = busJcebJyzqsjlService;
        this.sysFileService = sysFileService;
    }

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody BusJcebJyzqsjl busJcebJyzqsjl) {
        return toAjax(busJcebJyzqsjlService.create(busJcebJyzqsjl));
    }

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

    @ApiOperation(value = "更新")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody @Valid BusJcebJyzqsjl busJcebJyzqsjl) {
        return toAjax(busJcebJyzqsjlService.update(busJcebJyzqsjl));
    }

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

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

    @ApiOperation(value = "提交")
    @PutMapping("/submit")
    public AjaxResult submit(@RequestBody BusJcebJyzqsjl busJcebJyzqsjl) {
        return toAjax(busJcebJyzqsjlService.submit(busJcebJyzqsjl));
    }

    @ApiOperation(value = "退回")
    @PutMapping("/reject")
    public AjaxResult reject(@RequestBody BusJcebJyzqsjl busJcebJyzqsjl) {
        return toAjax(busJcebJyzqsjlService.reject(busJcebJyzqsjl));
    }

    @ApiOperation(value = "确认")
    @PutMapping("/confirm")
    public AjaxResult confirm(@RequestBody BusJcebJyzqsjl busJcebJyzqsjl) {
        return toAjax(busJcebJyzqsjlService.confirm(busJcebJyzqsjl));
    }

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

}
