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.TDeviceNagetiveFactor;
import com.ruoyi.project.reliability.service.ITDeviceNagetiveFactorService;
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/factor")
public class TDeviceNagetiveFactorController extends BaseController
{
    @Autowired
    private ITDeviceNagetiveFactorService tDeviceNagetiveFactorService;

    /**
     * 查询不良因素清单列表
     */
    @PreAuthorize("@ss.hasPermi('reliability:factor:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDeviceNagetiveFactor tDeviceNagetiveFactor)
    {
        startPage();
        List<TDeviceNagetiveFactor> list = tDeviceNagetiveFactorService.selectTDeviceNagetiveFactorList(tDeviceNagetiveFactor);
        return getDataTable(list);
    }

    /**
     * 导出不良因素清单列表
     */
    @PreAuthorize("@ss.hasPermi('reliability:factor:export')")
    @Log(title = "不良因素清单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TDeviceNagetiveFactor tDeviceNagetiveFactor)
    {
        List<TDeviceNagetiveFactor> list = tDeviceNagetiveFactorService.selectTDeviceNagetiveFactorList(tDeviceNagetiveFactor);
        ExcelUtil<TDeviceNagetiveFactor> util = new ExcelUtil<TDeviceNagetiveFactor>(TDeviceNagetiveFactor.class);
        return util.exportExcel(list, "factor");
    }

    /**
     * 获取不良因素清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('reliability:factor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tDeviceNagetiveFactorService.selectTDeviceNagetiveFactorById(id));
    }

    /**
     * 新增不良因素清单
     */
    @PreAuthorize("@ss.hasPermi('reliability:factor:add')")
    @Log(title = "不良因素清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDeviceNagetiveFactor tDeviceNagetiveFactor)
    {
        return toAjax(tDeviceNagetiveFactorService.insertTDeviceNagetiveFactor(tDeviceNagetiveFactor));
    }

    /**
     * 修改不良因素清单
     */
    @PreAuthorize("@ss.hasPermi('reliability:factor:edit')")
    @Log(title = "不良因素清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDeviceNagetiveFactor tDeviceNagetiveFactor)
    {
        return toAjax(tDeviceNagetiveFactorService.updateTDeviceNagetiveFactor(tDeviceNagetiveFactor));
    }

    /**
     * 删除不良因素清单
     */
    @PreAuthorize("@ss.hasPermi('reliability:factor:remove')")
    @Log(title = "不良因素清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDeviceNagetiveFactorService.deleteTDeviceNagetiveFactorByIds(ids));
    }
}
