package com.ruoyi.project.configuration.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.configuration.domain.TMatterFeature;
import com.ruoyi.project.configuration.service.ITMatterFeatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 危害物质-危害性质Controller
 *
 * @author ruoyi
 * @date 2021-12-28
 */
@RestController
@RequestMapping("/configuration/feature")
public class TMatterFeatureController extends BaseController {

    @Autowired
    private ITMatterFeatureService tMatterFeatureService;

    /**
     * 查询危害物质-危害性质列表
     */
    @PreAuthorize("@ss.hasPermi('configuration:feature:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMatterFeature tMatterFeature) {
        startPage();
        List<TMatterFeature> list = tMatterFeatureService.selectTMatterFeatureList(tMatterFeature);
        return getDataTable(list);
    }

    /**
     * 导出危害物质-危害性质列表
     */
    @PreAuthorize("@ss.hasPermi('configuration:feature:export')")
    @Log(title = "危害物质-危害性质", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMatterFeature tMatterFeature) {
        List<TMatterFeature> list = tMatterFeatureService.selectTMatterFeatureList(tMatterFeature);
        ExcelUtil<TMatterFeature> util = new ExcelUtil<TMatterFeature>(TMatterFeature.class);
        return util.exportExcel(list, "feature");
    }

    /**
     * 获取危害物质-危害性质详细信息
     */
    @PreAuthorize("@ss.hasPermi('configuration:feature:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tMatterFeatureService.selectTMatterFeatureById(id));
    }

    /**
     * 新增危害物质-危害性质
     */
    @PreAuthorize("@ss.hasPermi('configuration:feature:add')")
    @Log(title = "危害物质-危害性质", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMatterFeature tMatterFeature) {
        return toAjax(tMatterFeatureService.insertTMatterFeature(tMatterFeature));
    }

    /**
     * 修改危害物质-危害性质
     */
    @PreAuthorize("@ss.hasPermi('configuration:feature:edit')")
    @Log(title = "危害物质-危害性质", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMatterFeature tMatterFeature) {
        return toAjax(tMatterFeatureService.updateTMatterFeature(tMatterFeature));
    }

    /**
     * 删除危害物质-危害性质
     */
    @PreAuthorize("@ss.hasPermi('configuration:feature:remove')")
    @Log(title = "危害物质-危害性质", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tMatterFeatureService.deleteTMatterFeatureByIds(ids));
    }
}
