package com.fidms.web.controller;

import com.fidms.common.annotation.Log;
import com.fidms.common.core.controller.BaseController;
import com.fidms.common.core.domain.AjaxResult;
import com.fidms.common.core.page.TableDataInfo;
import com.fidms.common.enums.BusinessType;
import com.fidms.common.utils.poi.ExcelUtil;
import com.fidms.web.domain.InfraredOutput;
import com.fidms.web.service.IInfraredOutputService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 红外输出Controller
 * 
 * @author Allen
 * @date 2023-05-08
 */
@RestController
@RequestMapping("/data/infraredOut")
public class InfraredOutputController extends BaseController
{
    @Autowired
    private IInfraredOutputService infraredOutputService;

    /**
     * 查询红外输出列表
     */
    @PreAuthorize("@ss.hasPermi('data:infraredOut:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfraredOutput infraredOutput)
    {
        startPage();
        List<InfraredOutput> list = infraredOutputService.selectInfraredOutputList(infraredOutput);
        return getDataTable(list);
    }

    /**
     * 导出红外输出列表
     */
    @PreAuthorize("@ss.hasPermi('data:infraredOut:export')")
    @Log(title = "红外输出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfraredOutput infraredOutput)
    {
        List<InfraredOutput> list = infraredOutputService.selectInfraredOutputList(infraredOutput);
        ExcelUtil<InfraredOutput> util = new ExcelUtil<InfraredOutput>(InfraredOutput.class);
        util.exportExcel(response, list, "红外输出数据");
    }

    /**
     * 获取红外输出详细信息
     */
    @PreAuthorize("@ss.hasPermi('data:infraredOut:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(infraredOutputService.selectInfraredOutputById(id));
    }

    /**
     * 新增红外输出
     */
    @PreAuthorize("@ss.hasPermi('data:infraredOut:add')")
    @Log(title = "红外输出", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfraredOutput infraredOutput)
    {
        infraredOutput.setCreateBy(getUsername());
        infraredOutput.setUpdateBy(getUsername());
        return toAjax(infraredOutputService.insertInfraredOutput(infraredOutput));
    }

    /**
     * 修改红外输出
     */
    @PreAuthorize("@ss.hasPermi('data:infraredOut:edit')")
    @Log(title = "红外输出", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfraredOutput infraredOutput)
    {
        infraredOutput.setUpdateBy(getUsername());
        return toAjax(infraredOutputService.updateInfraredOutput(infraredOutput));
    }

    /**
     * 删除红外输出
     */
    @PreAuthorize("@ss.hasPermi('data:infraredOut:remove')")
    @Log(title = "红外输出", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(infraredOutputService.deleteInfraredOutputByIds(ids));
    }
}
