package com.ruoyi.web.controller.ehs;

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

import com.ruoyi.common.utils.StringUtils;
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.ehsHiddenDanger.domain.EhsHiddenDanger;
import com.ruoyi.ehsHiddenDanger.service.IEhsHiddenDangerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 隐患信息Controller
 *
 * @author ruoyi
 * @date 2023-12-11
 */
@Api(tags="隐患信息管理")
@RestController
@RequestMapping("/ehsHiddenDanger/ehsHiddenDanger")
public class EhsHiddenDangerController extends BaseController
{
    @Autowired
    private IEhsHiddenDangerService ehsHiddenDangerService;

/**
 * 查询隐患信息列表
 */
@PreAuthorize("@ss.hasPermi('ehsHiddenDanger:ehsHiddenDanger:list')")
@GetMapping("/list")
	public TableDataInfo list(EhsHiddenDanger ehsHiddenDanger)
	{
		startPage();
		List<EhsHiddenDanger> list = ehsHiddenDangerService.selectEhsHiddenDangerList(ehsHiddenDanger);
		return getDataTable(list);
	}

	/**
	 * 导出隐患信息列表
	 */
	@PreAuthorize("@ss.hasPermi('ehsHiddenDanger:ehsHiddenDanger:export')")
	@Log(title = "隐患信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, EhsHiddenDanger ehsHiddenDanger)
	{
		List<EhsHiddenDanger> list = ehsHiddenDangerService.selectEhsHiddenDangerList(ehsHiddenDanger);
		ExcelUtil<EhsHiddenDanger> util = new ExcelUtil<EhsHiddenDanger>(EhsHiddenDanger.class);
		util.exportExcel(response, list, "隐患信息数据");
	}

	/**
	 * 获取隐患信息详细信息
	 */
	@PreAuthorize("@ss.hasPermi('ehsHiddenDanger:ehsHiddenDanger:query')")
	@GetMapping(value = "/{hiddenDangerId}")
	public AjaxResult getInfo(@PathVariable("hiddenDangerId") Long hiddenDangerId)
	{
		EhsHiddenDanger ehsHiddenDanger = ehsHiddenDangerService.selectEhsHiddenDangerByHiddenDangerId(hiddenDangerId);
		if(StringUtils.isNotEmpty(ehsHiddenDanger.getHiddenDangerLabel()) ){
			String[] s = ehsHiddenDanger.getHiddenDangerLabel().split(",");
			ehsHiddenDanger.setHiddenDangerLabelArray(s);
		}
		return success(ehsHiddenDanger);
	}

    /**
     * 新增隐患信息
     */
    @ApiOperation("新增隐患信息")
    @PreAuthorize("@ss.hasPermi('ehsHiddenDanger:ehsHiddenDanger:add')")
    @Log(title = "隐患信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EhsHiddenDanger ehsHiddenDanger)
    {
        return toAjax(ehsHiddenDangerService.save(ehsHiddenDanger));
    }

    /**
     * 修改隐患信息
     */
    @ApiOperation("修改隐患信息")
    @PreAuthorize("@ss.hasPermi('ehsHiddenDanger:ehsHiddenDanger:edit')")
    @Log(title = "隐患信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EhsHiddenDanger ehsHiddenDanger)
    {
        return toAjax(ehsHiddenDangerService.updateById(ehsHiddenDanger));
    }

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

	/**
	 * 督办
	 */
	@ApiOperation("督办隐患信息")
	//@PreAuthorize("@ss.hasPermi('ehsHiddenDanger:ehsHiddenDanger:supervise')")
	@Log(title = "督办信息", businessType = BusinessType.UPDATE)
	@GetMapping("/supervise/{hiddenDangerIds}")
	public AjaxResult supervise(@PathVariable Long[] hiddenDangerIds)
	{
		return toAjax(ehsHiddenDangerService.superviseEhsHiddenDanger(hiddenDangerIds));
	}

	/**
	 * 协办
	 */
	@ApiOperation("协办隐患信息")
	@PreAuthorize("@ss.hasPermi('ehsHiddenDanger:ehsHiddenDanger:assist')")
	@Log(title = "协办信息", businessType = BusinessType.UPDATE)
	@GetMapping("/assist")
	public AjaxResult assist(  EhsHiddenDanger ehsHiddenDanger )
	{
		return toAjax(ehsHiddenDangerService.assistEhsHiddenDanger(ehsHiddenDanger));
	}
}
