package com.xinda.itsm.controller;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.xinda.common.annotation.Log;
import com.xinda.common.core.controller.BaseController;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.common.enums.BusinessType;
import com.xinda.itsm.domain.ProcessInfo;
import com.xinda.itsm.service.IProcessInfoService;
import com.xinda.common.utils.poi.ExcelUtil;
import com.xinda.common.core.page.TableDataInfo;

/**
 * 流程管理Controller
 *
 * @author kerwincui
 * @date 2025-04-27
 */
@RestController
@RequestMapping("/itsm/process")
@Api(tags = "流程管理")
public class ProcessInfoController extends BaseController
{
    @Autowired
    private IProcessInfoService processInfoService;

/**
 * 查询流程管理列表
 */
@PreAuthorize("@ss.hasPermi('itsm:process:list')")
@GetMapping("/list")
@ApiOperation("查询流程管理列表")
    public TableDataInfo list(ProcessInfo processInfo)
    {
        startPage();
        List<ProcessInfo> list = processInfoService.selectProcessInfoList(processInfo);
        return getDataTable(list);
    }

    /**
     * 导出流程管理列表
     */
    @ApiOperation("导出流程管理列表")
    @PreAuthorize("@ss.hasPermi('itsm:process:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProcessInfo processInfo)
    {
        List<ProcessInfo> list = processInfoService.selectProcessInfoList(processInfo);
        ExcelUtil<ProcessInfo> util = new ExcelUtil<ProcessInfo>(ProcessInfo.class);
        util.exportExcel(response, list, "流程管理数据");
    }

    /**
     * 获取流程管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('itsm:process:query')")
    @GetMapping(value = "/{processId}")
    @ApiOperation("获取流程管理详细信息")
    public AjaxResult getInfo(@PathVariable("processId") Long processId)
    {
        return success(processInfoService.selectProcessInfoByProcessId(processId));
    }

    /**
     * 新增流程管理
     */
    @PreAuthorize("@ss.hasPermi('itsm:process:add')")
    @PostMapping
    @ApiOperation("新增流程管理")
    public AjaxResult add(@RequestBody ProcessInfo processInfo)
    {
        return toAjax(processInfoService.insertProcessInfo(processInfo));
    }

    /**
     * 修改流程管理
     */
    @PreAuthorize("@ss.hasPermi('itsm:process:edit')")
    @PutMapping
    @ApiOperation("修改流程管理")
    public AjaxResult edit(@RequestBody ProcessInfo processInfo)
    {
        return toAjax(processInfoService.updateProcessInfo(processInfo));
    }

    /**
     * 删除流程管理
     */
    @PreAuthorize("@ss.hasPermi('itsm:process:remove')")
    @DeleteMapping("/{processIds}")
    @ApiOperation("删除流程管理")
    public AjaxResult remove(@PathVariable Long[] processIds)
    {
        return toAjax(processInfoService.deleteProcessInfoByProcessIds(processIds));
    }
}
