package cn.ey.biz.module.system.controller.bpm.task;

import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.controller.bpm.task.vo.*;
import cn.ey.biz.module.system.service.bpm.BpmTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.ey.biz.common.pojo.R.success;
import static cn.ey.biz.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Api(tags = "流程管理 - 流程任务实例")
@RestController
@RequestMapping("/system/bpm/task")
@Validated
public class BpmTaskController {

    @Resource
    private BpmTaskService taskService;

    @PostMapping("/approve")
    @ApiOperation("通过任务")
    @PreAuthorize("@ss.hasPermission('bpm:task:update')")
    public R<Boolean> approveTask(@Valid @RequestBody BpmTaskApproveReqVO reqVO) {
        taskService.approveTask(getLoginUserId(), reqVO);
        return success(true);
    }

    @PostMapping("/reject")
    @ApiOperation("不通过任务")
    @PreAuthorize("@ss.hasPermission('bpm:task:update')")
    public R<Boolean> rejectTask(@Valid @RequestBody BpmTaskRejectReqVO reqVO) {
        taskService.rejectTask(getLoginUserId(), reqVO);
        return success(true);
    }

    @PostMapping("/batch-approve")
    @ApiOperation("批量通过任务")
    @PreAuthorize("@ss.hasPermission('bpm:task:update')")
    public R<Boolean> batchApprove(@Valid @RequestBody List<BpmTaskApproveReqVO> reqVO) {
        taskService.batchApproveTask(getLoginUserId(), reqVO);
        return success(true);
    }

    @PostMapping("/batch-reject")
    @ApiOperation("批量不通过任务")
    @PreAuthorize("@ss.hasPermission('bpm:task:update')")
    public R<Boolean> batchReject(@Valid @RequestBody List<BpmTaskRejectReqVO> reqVO) {
        taskService.batchRejectTask(getLoginUserId(), reqVO);
        return success(true);
    }



}
