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.InfraredInput;
import com.fidms.web.service.IInfraredInputService;
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/infraredIn")
public class InfraredInputController extends BaseController
{
    @Autowired
    private IInfraredInputService infraredInputService;

    /**
     * 查询红外输入列表
     */
    @PreAuthorize("@ss.hasPermi('data:infraredIn:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfraredInput infraredInput)
    {
        startPage();
        List<InfraredInput> list = infraredInputService.selectInfraredInputList(infraredInput);
        return getDataTable(list);
    }

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

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

    /**
     * 新增红外输入
     */
    @PreAuthorize("@ss.hasPermi('data:infraredIn:add')")
    @Log(title = "红外输入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfraredInput infraredInput)
    {
        infraredInput.setCreateBy(getUsername());
        infraredInput.setUpdateBy(getUsername());
        return toAjax(infraredInputService.insertInfraredInput(infraredInput));
    }

    /**
     * 修改红外输入
     */
    @PreAuthorize("@ss.hasPermi('data:infraredIn:edit')")
    @Log(title = "红外输入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfraredInput infraredInput)
    {
        infraredInput.setUpdateBy(getUsername());
        return toAjax(infraredInputService.updateInfraredInput(infraredInput));
    }

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

    @GetMapping("/getInfraredInputOption")
    public AjaxResult getInfraredInputOption()
    {
        return success(infraredInputService.getInfraredInputOption());
    }
}
