package com.pwt.web.controller;

import com.pwt.common.annotation.Log;
import com.pwt.common.core.controller.BaseController;
import com.pwt.common.core.domain.AjaxResult;
import com.pwt.common.core.page.TableDataInfo;
import com.pwt.common.enums.BusinessType;
import com.pwt.common.utils.poi.ExcelUtil;
import com.pwt.web.domain.PwtRobotFault;
import com.pwt.web.service.IPwtRobotFaultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 机器人故障信息Controller
 *
 * @author pwt
 * @date 2022-11-23
 */
@RestController
@RequestMapping("/web/robotFault")
public class PwtRobotFaultController extends BaseController
{
    @Autowired
    private IPwtRobotFaultService pwtRobotFaultService;

    /**
     * @Description: 导入故障信息
     * @Author: linyun
     * @Date: 2022/11/24 9:24
     * @Param:[file 导入的故障信息excel表格]
     * @Return:void
     **/
    @PostMapping("/importData")
    public void importData(MultipartFile file) throws Exception
    {
        ExcelUtil<PwtRobotFault> util = new ExcelUtil<>(PwtRobotFault.class);
        List<PwtRobotFault> list = util.importExcel(file.getInputStream());
        for (PwtRobotFault fault : list)
        {
            pwtRobotFaultService.insertPwtRobotFault(fault);
        }
    }

    /**
     * 查询机器人故障信息列表
     */
    @PreAuthorize("@ss.hasPermi('web:robotFault:list')")
    @GetMapping("/list")
    public TableDataInfo list(PwtRobotFault pwtRobotFault)
    {
        startPage();
        List<PwtRobotFault> list = pwtRobotFaultService.selectPwtRobotFaultList(pwtRobotFault);
        return getDataTable(list);
    }

    /**
     * 导出机器人故障信息列表
     */
    @PreAuthorize("@ss.hasPermi('web:robotFault:export')")
    @Log(title = "机器人故障信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PwtRobotFault pwtRobotFault)
    {
        List<PwtRobotFault> list = pwtRobotFaultService.selectPwtRobotFaultList(pwtRobotFault);
        ExcelUtil<PwtRobotFault> util = new ExcelUtil<PwtRobotFault>(PwtRobotFault.class);
        util.exportExcel(response, list, "机器人故障信息数据");
    }

    /**
     * 获取机器人故障信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('web:robotFault:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pwtRobotFaultService.selectPwtRobotFaultById(id));
    }

    /**
     * 新增机器人故障信息
     */
    @PreAuthorize("@ss.hasPermi('web:robotFault:add')")
    @Log(title = "机器人故障信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PwtRobotFault pwtRobotFault)
    {
        return toAjax(pwtRobotFaultService.insertPwtRobotFault(pwtRobotFault));
    }

    /**
     * 修改机器人故障信息
     */
    @PreAuthorize("@ss.hasPermi('web:robotFault:edit')")
    @Log(title = "机器人故障信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PwtRobotFault pwtRobotFault)
    {
        return toAjax(pwtRobotFaultService.updatePwtRobotFault(pwtRobotFault));
    }

    /**
     * 删除机器人故障信息
     */
    @PreAuthorize("@ss.hasPermi('web:robotFault:remove')")
    @Log(title = "机器人故障信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pwtRobotFaultService.deletePwtRobotFaultByIds(ids));
    }
}
