package com.dcs.dcs.controller;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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 com.dcs.common.annotation.Log;
import com.dcs.common.core.controller.BaseController;
import com.dcs.common.core.domain.AjaxResult;
import com.dcs.common.enums.BusinessType;
import com.dcs.dcs.domain.DcsFlow;
import com.dcs.dcs.service.IDcsFlowService;
import com.dcs.common.utils.poi.ExcelUtil;
import com.dcs.common.core.page.TableDataInfo;

/**
 * 流程Controller
 * 
 * @author hmy
 * @date 2025-03-08
 */
@RestController
@RequestMapping("/dcs/flow")
@Api
public class DcsFlowController extends BaseController
{
    @Autowired
    private IDcsFlowService dcsFlowService;

    /**
     * 获取流程列表（用于下拉框）需传一个参数equipmentId
     */
    @GetMapping("/getFlowList")
    @ApiOperation(value = "获取设备对应流程列表（用于下拉框）")
    public AjaxResult getFlowListByEquipmentId(@ApiParam(name = "equipmentId" ,value="设备id") Long equipmentId){
        return success(dcsFlowService.getFlowListByEquipmentId(equipmentId));
    }

    /**
     * 查询流程列表
     */
    @PreAuthorize("@ss.hasPermi('dcs:flow:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询流程列表")
    public TableDataInfo list(@ApiParam(name = "流程" ,value="流程",required = true) DcsFlow dcsFlow)
    {
        startPage();
        List<DcsFlow> list = dcsFlowService.selectDcsFlowList(dcsFlow);
        return getDataTable(list);
    }

    /**
     * 导出流程列表
     */
    @PreAuthorize("@ss.hasPermi('dcs:flow:export')")
    @Log(title = "流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出流程列表")
    public void export(HttpServletResponse response, DcsFlow dcsFlow)
    {
        List<DcsFlow> list = dcsFlowService.selectDcsFlowList(dcsFlow);
        ExcelUtil<DcsFlow> util = new ExcelUtil<DcsFlow>(DcsFlow.class);
        util.exportExcel(response, list, "流程数据");
    }

    /**
     * 获取流程详细信息
     */
    @PreAuthorize("@ss.hasPermi('dcs:flow:query')")
    @GetMapping(value = "/{flowId}")
    @ApiOperation(value = "获取流程详细信息")
    public AjaxResult getInfo(@PathVariable("flowId") Long flowId)
    {
        return success(dcsFlowService.selectDcsFlowByFlowId(flowId));
    }

    /**
     * 新增流程
     */
    @PreAuthorize("@ss.hasPermi('dcs:flow:add')")
    @Log(title = "流程", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增流程")
    public AjaxResult add(@RequestBody DcsFlow dcsFlow)
    {
        return toAjax(dcsFlowService.insertDcsFlow(dcsFlow));
    }

    /**
     * 修改流程
     */
    @PreAuthorize("@ss.hasPermi('dcs:flow:edit')")
    @Log(title = "流程", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改流程")
    public AjaxResult edit(@RequestBody DcsFlow dcsFlow)
    {
        return toAjax(dcsFlowService.updateDcsFlow(dcsFlow));
    }

    /**
     * 删除流程
     */
    @ApiOperation(value = "删除流程")
    @PreAuthorize("@ss.hasPermi('dcs:flow:remove')")
    @Log(title = "流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flowIds}")
    public AjaxResult remove(@PathVariable Long[] flowIds)
    {
        return toAjax(dcsFlowService.deleteDcsFlowByFlowIds(flowIds));
    }
}
