package com.bonus.material.approval.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.material.approval.domain.ApprovalProcess;
import com.bonus.material.approval.service.IApprovalProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 审批流程配置Controller
 * 
 * @author bonus
 * @date 2024-11-18
 */
@Api(tags = "审批流程配置")
@RestController
@RequestMapping("/approval/process")
public class ApprovalProcessController extends BaseController {

    @Resource
    private IApprovalProcessService processService;

    /**
     * 查询审批流程列表
     */
    @ApiOperation("查询审批流程列表")
    //@RequiresPermissions("material:approval:process:list")
    @GetMapping("/list")
    public TableDataInfo list(ApprovalProcess process) {
        startPage();
        List<ApprovalProcess> list = processService.selectProcessList(process);
        return getDataTable(list);
    }

    /**
     * 获取审批流程详细信息
     */
    @ApiOperation("获取审批流程详细信息")
    //@RequiresPermissions("material:approval:process:query")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(processService.selectProcessById(id));
    }

    /**
     * 根据业务类型和组织机构ID查询审批流程
     */
    @ApiOperation("根据业务类型和组织机构ID查询审批流程")
    //@RequiresPermissions("material:approval:process:query")
    @GetMapping("/query")
    public AjaxResult queryByBusinessTypeAndOrgId(@RequestParam("businessType") String businessType, @RequestParam(value = "orgId", required = false) Long orgId) {
        ApprovalProcess process = processService.selectProcessByBusinessTypeAndOrgId(businessType, orgId);
        return success(process);
    }

    /**
     * 新增审批流程
     */
    @ApiOperation("新增审批流程")
    //@RequiresPermissions("material:approval:process:add")
    @PostMapping
    public AjaxResult add(@RequestBody ApprovalProcess process) {
        return toAjax(processService.insertProcess(process));
    }

    /**
     * 修改审批流程
     */
    @ApiOperation("修改审批流程")
    //@RequiresPermissions("material:approval:process:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody ApprovalProcess process) {
        return toAjax(processService.updateProcess(process));
    }

    /**
     * 删除审批流程
     */
    @ApiOperation("删除审批流程")
   // @RequiresPermissions("material:approval:process:remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(processService.deleteProcessByIds(ids));
    }

    /**
     * 启用流程
     */
    @ApiOperation("启用流程")
    //@RequiresPermissions("material:approval:process:edit")
    @PutMapping("/enable/{id}")
    public AjaxResult enable(@PathVariable Long id) {
        return toAjax(processService.enableProcess(id));
    }

    /**
     * 停用流程
     */
    @ApiOperation("停用流程")
    //@RequiresPermissions("material:approval:process:edit")
    @PutMapping("/disable/{id}")
    public AjaxResult disable(@PathVariable Long id) {
        return toAjax(processService.disableProcess(id));
    }
}

