package com.ruoyi.web.controller.ehs;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ehsRisk.domain.EhsRisk;
import com.ruoyi.ehsRisk.service.IEhsRiskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风险信息Controller
 *
 * @author ruoyi
 * @date 2023-12-13
 */
@Api(tags="风险信息管理")
@RestController
@RequestMapping("/ehsRisk/ehsRisk")
public class EhsRiskController extends BaseController
{
    @Autowired
    private IEhsRiskService ehsRiskService;

/**
 * 查询风险信息列表
 */
@PreAuthorize("@ss.hasPermi('ehsRisk:ehsRisk:list')")
@GetMapping("/list")
	public TableDataInfo list(EhsRisk ehsRisk)
	{
		startPage();
		List<EhsRisk> list = ehsRiskService.selectEhsRiskList(ehsRisk);
		return getDataTable(list);
	}

	/**
	 * 导出风险信息列表
	 */
	@PreAuthorize("@ss.hasPermi('ehsRisk:ehsRisk:export')")
	@Log(title = "风险信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, EhsRisk ehsRisk)
	{
		List<EhsRisk> list = ehsRiskService.selectEhsRiskList(ehsRisk);
		ExcelUtil<EhsRisk> util = new ExcelUtil<EhsRisk>(EhsRisk.class);
		util.exportExcel(response, list, "风险信息数据");
	}

	/**
	 * 获取风险信息详细信息
	 */
	@PreAuthorize("@ss.hasPermi('ehsRisk:ehsRisk:query')")
	@GetMapping(value = "/{riskId}")
	public AjaxResult getInfo(@PathVariable("riskId") Long riskId)
	{
		return success(ehsRiskService.selectEhsRiskByRiskId(riskId));
	}

    /**
     * 新增风险信息
     */
    @ApiOperation("新增风险信息")
    @PreAuthorize("@ss.hasPermi('ehsRisk:ehsRisk:add')")
    @Log(title = "风险信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EhsRisk ehsRisk)
    {
        return toAjax(ehsRiskService.save(ehsRisk));
    }

    /**
     * 修改风险信息
     */
    @ApiOperation("修改风险信息")
    @PreAuthorize("@ss.hasPermi('ehsRisk:ehsRisk:edit')")
    @Log(title = "风险信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EhsRisk ehsRisk)
    {
        return toAjax(ehsRiskService.updateById(ehsRisk));
    }

    /**
     * 删除风险信息
     */
    @ApiOperation("删除风险信息")
    @PreAuthorize("@ss.hasPermi('ehsRisk:ehsRisk:remove')")
    @Log(title = "风险信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{riskIds}")
    public AjaxResult remove(@PathVariable Long[] riskIds)
    {
        return toAjax(ehsRiskService.removeByIds(Arrays.asList(riskIds)));
    }
}
