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.ApprovalInstance;
import com.bonus.material.approval.service.IApprovalInstanceService;
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/instance")
public class ApprovalInstanceController extends BaseController {

    @Resource
    private IApprovalInstanceService instanceService;

    /**
     * 查询审批实例列表
     */
    @ApiOperation("查询审批实例列表")
    //@RequiresPermissions("material:approval:instance:list")
    @GetMapping("/list")
    public TableDataInfo list(ApprovalInstance instance) {
        startPage();
        List<ApprovalInstance> list = instanceService.selectInstanceList(instance);
        return getDataTable(list);
    }

    /**
     * 获取审批实例详细信息
     */
    @ApiOperation("获取审批实例详细信息")
    //@RequiresPermissions("material:approval:instance:query")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(instanceService.selectInstanceById(id));
    }

    /**
     * 根据业务类型和业务ID查询审批实例
     */
    @ApiOperation("根据业务查询审批实例")
    //@RequiresPermissions("material:approval:instance:query")
    @GetMapping("/business/{businessType}/{businessId}")
    public AjaxResult getByBusiness(@PathVariable String businessType, @PathVariable String businessId) {
        return success(instanceService.selectInstanceByBusiness(businessType, businessId));
    }
}

