package com.yida.data.form.apply.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.form.apply.service.CoreApprovalProcessService;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.applyForm.CoreApprovalProcess;
import com.yida.data.customForm.dto.apply.ApprovalProcessSelectPageDTO;
import com.yida.data.customForm.vo.apply.ApprovalProcessInfoVO;
import com.yida.data.customForm.vo.apply.ApprovalProcessSelectPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 审核流程节点管理 Controller
 *
 * @author ZYJ
 * @date 2023/11/21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/process")
@Api(tags = "后台--审核流程管理")
public class CoreApprovalProcessController {

    private final CoreApprovalProcessService coreApprovalProcessService;

    @ApiOperation("查询审核流程节点列表数据")
    @PostMapping("/listApprovalProcessPage")
    public ResultBean<IPage<ApprovalProcessSelectPageVO>> listApprovalProcessPage(ApprovalProcessSelectPageDTO dto) {
        IPage<ApprovalProcessSelectPageVO> page = coreApprovalProcessService.listApprovalProcessPage(dto);
        return ResultBean.buildSuccess(page);
    }

    @ApiOperation("查询所有审核流程节点数据(排除当前表单包含的数据)")
    @PostMapping("/listApprovalProcess")
    public ResultBean<List<CoreApprovalProcess>> listApprovalProcess(
            @ApiParam(value = "表单id", required = true) @RequestParam Long formId) {
        return ResultBean.buildSuccess(coreApprovalProcessService.listApprovalProcess(formId));
    }

    @ApiOperation("查询审核流程节点详情")
    @GetMapping("/getApprovalProcessInfo")
    public ResultBean<ApprovalProcessInfoVO> getApprovalProcessInfo(
            @RequestParam @ApiParam(value = "审核流程节点id", required = true) Long id) {
        return ResultBean.buildSuccess(coreApprovalProcessService.getApprovalProcessInfo(id));
    }

    @ApiOperation("删除审核流程节点")
    @GetMapping("/deleteApprovalProcess")
    public ResultBean<String> deleteApprovalProcess(
            @RequestParam @ApiParam(value = "审核流程节点id", required = true) Long id) {
        coreApprovalProcessService.deleteApprovalProcess(id);
        return ResultBean.buildSuccess();
    }

    @ApiOperation(value = "保存审核流程节点", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/saveApprovalProcess", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean<String> saveApprovalProcess(@RequestBody CoreApprovalProcess process) {
        coreApprovalProcessService.saveApprovalProcess(process);
        return ResultBean.buildSuccess();
    }
}
