package com.ruoyi.project.reliability.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.reliability.domain.TDeviceRisk;
import com.ruoyi.project.reliability.service.ITDeviceRiskService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 装置风险清单Controller
 *
 * @author ruoyi
 * @date 2022-07-07
 */
@RestController
@RequestMapping("/reliability/risk")
public class TDeviceRiskController extends BaseController
{
    @Autowired
    private ITDeviceRiskService tDeviceRiskService;

    /**
     * 查询装置风险清单列表
     */
    @PreAuthorize("@ss.hasPermi('reliability:risk:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDeviceRisk tDeviceRisk)
    {
        startPage();
        List<TDeviceRisk> list = tDeviceRiskService.selectTDeviceRiskList(tDeviceRisk);
        return getDataTable(list);
    }

    /**
     * 导出装置风险清单列表
     */
    @PreAuthorize("@ss.hasPermi('reliability:risk:export')")
    @Log(title = "装置风险清单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TDeviceRisk tDeviceRisk)
    {
        List<TDeviceRisk> list = tDeviceRiskService.selectTDeviceRiskList(tDeviceRisk);
        ExcelUtil<TDeviceRisk> util = new ExcelUtil<TDeviceRisk>(TDeviceRisk.class);
        return util.exportExcel(list, "risk");
    }

    /**
     * 获取装置风险清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('reliability:risk:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tDeviceRiskService.selectTDeviceRiskById(id));
    }

    /**
     * 新增装置风险清单
     */
    @PreAuthorize("@ss.hasPermi('reliability:risk:add')")
    @Log(title = "装置风险清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDeviceRisk tDeviceRisk)
    {
        return toAjax(tDeviceRiskService.insertTDeviceRisk(tDeviceRisk));
    }

    /**
     * 修改装置风险清单
     */
    @PreAuthorize("@ss.hasPermi('reliability:risk:edit')")
    @Log(title = "装置风险清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDeviceRisk tDeviceRisk)
    {
        return toAjax(tDeviceRiskService.updateTDeviceRisk(tDeviceRisk));
    }

    /**
     * 删除装置风险清单
     */
    @PreAuthorize("@ss.hasPermi('reliability:risk:remove')")
    @Log(title = "装置风险清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDeviceRiskService.deleteTDeviceRiskByIds(ids));
    }
}
