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.FlowFieldInput;
import com.fidms.web.service.IFlowFieldInputService;
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/flowIn")
public class FlowFieldInputController extends BaseController
{
    @Autowired
    private IFlowFieldInputService flowFieldInputService;

    /**
     * 查询流场输入列表
     */
    @PreAuthorize("@ss.hasPermi('data:flowIn:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlowFieldInput flowFieldInput)
    {
        startPage();
        List<FlowFieldInput> list = flowFieldInputService.selectFlowFieldInputList(flowFieldInput);
        return getDataTable(list);
    }

    /**
     * 导出流场输入列表
     */
    @PreAuthorize("@ss.hasPermi('data:flowIn:export')")
    @Log(title = "流场输入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlowFieldInput flowFieldInput)
    {
        List<FlowFieldInput> list = flowFieldInputService.selectFlowFieldInputList(flowFieldInput);
        ExcelUtil<FlowFieldInput> util = new ExcelUtil<FlowFieldInput>(FlowFieldInput.class);
        util.exportExcel(response, list, "流场输入数据");
    }

    /**
     * 获取流场输入详细信息
     */
    @PreAuthorize("@ss.hasPermi('data:flowIn:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(flowFieldInputService.selectFlowFieldInputById(id));
    }

    /**
     * 新增流场输入
     */
    @PreAuthorize("@ss.hasPermi('data:flowIn:add')")
    @Log(title = "流场输入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlowFieldInput flowFieldInput)
    {
        flowFieldInput.setCreateBy(getUsername());
        flowFieldInput.setUpdateBy(getUsername());
        return toAjax(flowFieldInputService.insertFlowFieldInput(flowFieldInput));
    }

    /**
     * 修改流场输入
     */
    @PreAuthorize("@ss.hasPermi('data:flowIn:edit')")
    @Log(title = "流场输入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlowFieldInput flowFieldInput)
    {
        flowFieldInput.setUpdateBy(getUsername());
        return toAjax(flowFieldInputService.updateFlowFieldInput(flowFieldInput));
    }

    /**
     * 删除流场输入
     */
    @PreAuthorize("@ss.hasPermi('data:flowIn:remove')")
    @Log(title = "流场输入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(flowFieldInputService.deleteFlowFieldInputByIds(ids));
    }

    @GetMapping("/getFlowFieldInOption")
    public AjaxResult getFlowFieldInOption()
    {return success(flowFieldInputService.getFlowFieldInputList());}
}
