package com.xtd.project.activiti.controller;

import com.xtd.framework.web.controller.BaseController;
import com.xtd.framework.web.domain.AjaxResult;
import com.xtd.framework.web.page.TableDataInfo;
import com.xtd.project.activiti.domain.TreeVo;
import com.xtd.project.activiti.service.ProcessInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/processInstance")
public class ProcessInstanceController extends BaseController {
    @Autowired
    private ProcessInstanceService processInstanceService;
    @GetMapping("list")
    public TableDataInfo list() {
        TableDataInfo list = processInstanceService.list();
        return list;
    }

    @GetMapping("listTask/{processInstanceId}")
    public AjaxResult listTask(@PathVariable("processInstanceId") String processInstanceId) {
        List<TreeVo> list = processInstanceService.listTask(processInstanceId);
        return AjaxResult.success(list);
    }
    @GetMapping("listUser")
    public AjaxResult listUser() {
        List<TreeVo> list = processInstanceService.listUser();
        return AjaxResult.success(list);
    }

    /**
     *  挂起流程实例
     * @param processInstanceId
     * @return
     */
    @PostMapping("suspend/{processInstanceId}/{status}")
    public AjaxResult suspendProcess(@PathVariable("processInstanceId") String processInstanceId,@PathVariable("status")Integer status){
        processInstanceService.suspendProcess(processInstanceId,status);
        return AjaxResult.success();
    }

    /**
     * 转办流程
     * @param taskId
     * @param userId
     * @return
     */
    @PostMapping("transToOffice/{taskId}/{userId}")
    public AjaxResult transToOffice(@PathVariable("taskId") String taskId,@PathVariable("userId")String userId){
        processInstanceService.transToOffice(taskId,userId);
        return AjaxResult.success();
    }

    /**
     * 委托
     * @param taskId
     * @param userId
     * @return
     */
    @PostMapping("entrust/{taskId}/{userId}")
    public AjaxResult entrust(@PathVariable("taskId") String taskId,@PathVariable("userId")String userId){
        processInstanceService.entrust(taskId,userId);
        return AjaxResult.success();
    }



    /**
     *  删除流程实例
     * @param processInstanceId
     * @return
     */
    @DeleteMapping("{processInstanceId}")
    public AjaxResult deleteProcess(@PathVariable("processInstanceId") String processInstanceId){
        processInstanceService.deleteProcess(processInstanceId);
        return AjaxResult.success();
    }

    /**
     *  删除流程实例
     * @param list
     * @return
     */
    @DeleteMapping()
    public AjaxResult deleteProcess(@RequestBody List<String> list){
        processInstanceService.deleteProcess(list);
        return AjaxResult.success();
    }
}
