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

import com.railway.business.catenary.domain.BusJcebLbjghjl;
import com.railway.business.catenary.domain.vo.JcebQueryVo;
import com.railway.business.catenary.service.IBusJcebLbjghjlService;
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/lbjghjl", tags = "检测表 - 零部件更换记录")
@RestController
@Validated
@RequestMapping(value = "business/catenary/bus/jceb/lbjghjl")
public class BusJcebLbjghjlController extends BaseController {

    private final IBusJcebLbjghjlService busJcbLbjghjlService;
    private final ISysFileService sysFileService;

    public BusJcebLbjghjlController(IBusJcebLbjghjlService busJcbLbjghjlService, ISysFileService sysFileService) {
        this.busJcbLbjghjlService = busJcbLbjghjlService;
        this.sysFileService = sysFileService;
    }

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody BusJcebLbjghjl busJcebLbjghjl) {
        return toAjax(busJcbLbjghjlService.create(busJcebLbjghjl));
    }

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

    @ApiOperation(value = "更新")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody @Valid BusJcebLbjghjl busJcebLbjghjl) {
        return toAjax(busJcbLbjghjlService.update(busJcebLbjghjl));
    }

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

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

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

    @ApiOperation(value = "提交")
    @PutMapping("/submit")
    public AjaxResult submit(@RequestBody BusJcebLbjghjl busJcebLbjghjl) {
        return toAjax(busJcbLbjghjlService.submit(busJcebLbjghjl));
    }

    @ApiOperation(value = "退回")
    @PutMapping("/reject")
    public AjaxResult reject(@RequestBody BusJcebLbjghjl busJcebLbjghjl) {
        return toAjax(busJcbLbjghjlService.reject(busJcebLbjghjl));
    }

    @ApiOperation(value = "确认")
    @PutMapping("/confirm")
    public AjaxResult confirm(@RequestBody BusJcebLbjghjl busJcebLbjghjl) {
        return toAjax(busJcbLbjghjlService.confirm(busJcebLbjghjl));
    }

}
