package com.cn.fdapfe.biz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.cn.fdapfe.common.annotation.Log;
import com.cn.fdapfe.common.core.controller.BaseController;
import com.cn.fdapfe.common.core.domain.AjaxResult;
import com.cn.fdapfe.common.enums.BusinessType;
import com.cn.fdapfe.biz.domain.Workflow;
import com.cn.fdapfe.biz.service.IWorkflowService;
import com.cn.fdapfe.common.utils.poi.ExcelUtil;
import com.cn.fdapfe.common.core.page.TableDataInfo;

/**
 * 流程任务Controller
 * 
 * @author Allen
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/workflow/workflow")
public class WorkflowController extends BaseController
{
    @Autowired
    private IWorkflowService workflowService;

    /**
     * 查询流程任务列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:workflow:list')")
    @GetMapping("/list")
    public TableDataInfo list(Workflow workflow)
    {
        startPage();
        List<Workflow> list = workflowService.selectWorkflowList(workflow);
        return getDataTable(list);
    }

    /**
     * 导出流程任务列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:workflow:export')")
    @Log(title = "流程任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Workflow workflow)
    {
        List<Workflow> list = workflowService.selectWorkflowList(workflow);
        ExcelUtil<Workflow> util = new ExcelUtil<Workflow>(Workflow.class);
        util.exportExcel(response, list, "流程任务数据");
    }

    /**
     * 获取流程任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('workflow:workflow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workflowService.selectWorkflowById(id));
    }

    /**
     * 新增流程任务
     */
    @PreAuthorize("@ss.hasPermi('workflow:workflow:add')")
    @Log(title = "流程任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Workflow workflow)
    {
        return toAjax(workflowService.insertWorkflow(workflow));
    }

    /**
     * 修改流程任务
     */
    @PreAuthorize("@ss.hasPermi('workflow:workflow:edit')")
    @Log(title = "流程任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Workflow workflow)
    {
        return toAjax(workflowService.updateWorkflow(workflow));
    }

    /**
     * 删除流程任务
     */
    @PreAuthorize("@ss.hasPermi('workflow:workflow:remove')")
    @Log(title = "流程任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workflowService.deleteWorkflowByIds(ids));
    }
}
