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.FlowFieldOutput;
import com.fidms.web.service.IFlowFieldOutputService;
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/flowOut")
public class FlowFieldOutputController extends BaseController
{
    @Autowired
    private IFlowFieldOutputService flowFieldOutputService;

    /**
     * 查询流场输出列表
     */
    @PreAuthorize("@ss.hasPermi('data:flowOut:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlowFieldOutput flowFieldOutput)
    {
        startPage();
        List<FlowFieldOutput> list = flowFieldOutputService.selectFlowFieldOutputList(flowFieldOutput);
        return getDataTable(list);
    }

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

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

    /**
     * 新增流场输出
     */
    @PreAuthorize("@ss.hasPermi('data:flowOut:add')")
    @Log(title = "流场输出", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlowFieldOutput flowFieldOutput)
    {
        flowFieldOutput.setCreateBy(getUsername());
        flowFieldOutput.setUpdateBy(getUsername());
        return toAjax(flowFieldOutputService.insertFlowFieldOutput(flowFieldOutput));
    }

    /**
     * 修改流场输出
     */
    @PreAuthorize("@ss.hasPermi('data:flowOut:edit')")
    @Log(title = "流场输出", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlowFieldOutput flowFieldOutput)
    {
        flowFieldOutput.setUpdateBy(getUsername());
        return toAjax(flowFieldOutputService.updateFlowFieldOutput(flowFieldOutput));
    }

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

    @GetMapping("/getFlowOutputOption")
    public AjaxResult getFlowFieldOutputOption()
    {return success(flowFieldOutputService.getFlowFieldOutputOption());}
}
