package cn.iocoder.yudao.module.bpm.controller.admin.task;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.elderly.BedChangePageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.elderly.BpmElderlyInfoVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.elderly.CheckInPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.elderly.CheckInWaitPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.elderly.ElderlyRetreatRecordPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO;
import cn.iocoder.yudao.module.bpm.convert.task.BpmProcessInstanceConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.business.BpmBusinessFormDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
import cn.iocoder.yudao.module.bpm.service.business.BpmBusinessFormService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmCategoryService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
import cn.iocoder.yudao.module.system.api.bpm.vo.*;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.system.enums.notice.NotieBusinessTypeEnum;
import cn.iocoder.yudao.module.system.enums.notice.NotifyTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.task.api.Task;
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 java.util.Map;
import java.util.Objects;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserNickname;

@Tag(name = "管理后台 - 流程实例") // 流程实例，通过流程定义创建的一次“申请”
@RestController
@RequestMapping("/bpm/process-instance")
@Validated
public class BpmProcessInstanceController {

    @Resource
    private BpmProcessInstanceService processInstanceService;
    @Resource
    private BpmTaskService taskService;
    @Resource
    private BpmProcessDefinitionService processDefinitionService;
    @Resource
    private BpmCategoryService categoryService;

    @Resource
    private AdminUserApi adminUserApi;
    @Resource
    private DeptApi deptApi;

    @Resource
    private BpmBusinessFormService businessFormService;

    @GetMapping("/my-page")
    @Operation(summary = "获得我的实例分页列表", description = "在【我的流程】菜单中，进行调用")
    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    public CommonResult<PageResult<BpmProcessInstanceRespVO>> getProcessInstanceMyPage(
            @Valid BpmProcessInstancePageReqVO pageReqVO) {
        PageResult<BpmProcessInstanceRespVO> pageResult = processInstanceService.getProcessInstancePage(
                getLoginUserId(), pageReqVO);
        if (CollUtil.isEmpty(pageResult.getList())) {
            return success(PageResult.empty(pageResult.getTotal()));
        }

//        // 拼接返回
//        Map<String, List<Task>> taskMap = taskService.getTaskMapByProcessInstanceIds(
//                convertList(pageResult.getList(), HistoricProcessInstance::getId));
//        Map<String, ProcessDefinition> processDefinitionMap = processDefinitionService.getProcessDefinitionMap(
//                convertSet(pageResult.getList(), HistoricProcessInstance::getProcessDefinitionId));
//        Map<String, BpmCategoryDO> categoryMap = categoryService.getCategoryMap(
//                convertSet(processDefinitionMap.values(), ProcessDefinition::getCategory));
//        Map<String, BpmProcessDefinitionInfoDO> processDefinitionInfoMap = processDefinitionService.getProcessDefinitionInfoMap(
//                convertSet(pageResult.getList(), HistoricProcessInstance::getProcessDefinitionId));
//        Map<String, BpmElderlyInfoVO> elelderMap = businessFormService.getElderMapByBusinessKey(
//                convertSet(pageResult.getList(), HistoricProcessInstance::getBusinessKey));
//        Map<String, BpmElderlyInfoVO> readMap = businessFormService.getReadMapById(
//                convertSet(pageResult.getList(), HistoricProcessInstance::getId));
//        return success(BpmProcessInstanceConvert.INSTANCE.buildProcessInstancePage(pageResult,
//                processDefinitionMap, categoryMap, taskMap, elelderMap, null, null, processDefinitionInfoMap, readMap));

        return success(pageResult);
    }

    @GetMapping("/manager-page")
    @Operation(summary = "获得管理流程实例的分页列表", description = "在【流程实例】菜单中，进行调用")
    @PreAuthorize("@ss.hasPermission('bpm:process-instance:manager-query')")
    public CommonResult<PageResult<BpmProcessInstanceRespVO>> getProcessInstanceManagerPage(
            @Valid BpmProcessInstancePageReqVO pageReqVO) {
        // TODO 管理员实例列表
//        PageResult<HistoricProcessInstance> pageResult = processInstanceService.getProcessInstancePage(
//                null, pageReqVO);
//        if (CollUtil.isEmpty(pageResult.getList())) {
//            return success(PageResult.empty(pageResult.getTotal()));
//        }
//
//        // 拼接返回
//        Map<String, List<Task>> taskMap = taskService.getTaskMapByProcessInstanceIds(
//                convertList(pageResult.getList(), HistoricProcessInstance::getId));
//        Map<String, ProcessDefinition> processDefinitionMap = processDefinitionService.getProcessDefinitionMap(
//                convertSet(pageResult.getList(), HistoricProcessInstance::getProcessDefinitionId));
//        Map<String, BpmCategoryDO> categoryMap = categoryService.getCategoryMap(
//                convertSet(processDefinitionMap.values(), ProcessDefinition::getCategory));
//        // 发起人信息
//        Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
//                convertSet(pageResult.getList(), processInstance -> NumberUtils.parseLong(processInstance.getStartUserId())));
//        Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(
//                convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
//        Map<String, BpmProcessDefinitionInfoDO> processDefinitionInfoMap = processDefinitionService.getProcessDefinitionInfoMap(
//                convertSet(pageResult.getList(), HistoricProcessInstance::getProcessDefinitionId));
//        Map<String, BpmElderlyInfoVO> elelderMap = businessFormService.getElderMapByBusinessKey(
//                convertSet(pageResult.getList(), HistoricProcessInstance::getBusinessKey));
//        Map<String, BpmElderlyInfoVO> readMap = businessFormService.getReadMapById(
//                convertSet(pageResult.getList(), HistoricProcessInstance::getId));
//        return success(BpmProcessInstanceConvert.INSTANCE.buildProcessInstancePage(pageResult,
//                processDefinitionMap, categoryMap, taskMap, elelderMap, userMap, deptMap, processDefinitionInfoMap, readMap));

        return null;

//        Map<String, BpmElderlyInfoVO> elelderMap = businessFormService.getElderMapByBusinessKey(
//                convertSet(pageResult.getList(), HistoricProcessInstance::getBusinessKey));
//        return success(BpmProcessInstanceConvert.INSTANCE.buildProcessInstancePage(pageResult,
//                processDefinitionMap, categoryMap, taskMap, elelderMap, userMap, deptMap));

    }

    @GetMapping("/getBpmListCount")
    @Operation(summary = "获取审批列表代办数量")
    @ApiAccessLog(enable = false) // 由于前端会不断轮询该接口，记录日志没有意义
    public CommonResult<BpmMyPageCountRespVO> getBpmListCount(@Valid BpmMyPageCountReqVO pageVO) {
        return success(processInstanceService.getBpmListCount(
                getLoginUserId(), UserTypeEnum.ADMIN.getValue(), pageVO.getQueryType()));
    }

    @PostMapping("/create")
    @Operation(summary = "新建流程实例")
    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    public CommonResult<String> createProcessInstance(@Valid @RequestBody BpmProcessInstanceCreateReqVO createReqVO) {
        return success(processInstanceService.createProcessInstance(getLoginUserId(), createReqVO));
    }

    @GetMapping("/get")
    @Operation(summary = "获得指定流程实例", description = "在【流程详细】界面中，进行调用")
    @Parameter(name = "id", description = "流程实例的编号", required = true)
    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    public CommonResult<BpmProcessInstanceRespVO> getProcessInstance(@RequestParam("id") String id) {
        HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(id);
        if (processInstance == null) {
            return success(null);
        }

        // 拼接返回
        ProcessDefinition processDefinition = processDefinitionService.getProcessDefinition(
                processInstance.getProcessDefinitionId());
        BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionService.getProcessDefinitionInfo(
                processInstance.getProcessDefinitionId());
        String bpmnXml = BpmnModelUtils.getBpmnXml(
                processDefinitionService.getProcessDefinitionBpmnModel(processInstance.getProcessDefinitionId()));
        AdminUserRespDTO startUser = adminUserApi.getUserTenantIgnore(NumberUtils.parseLong(processInstance.getStartUserId()));
        DeptRespDTO dept = null;
        if (startUser != null) {
            dept = deptApi.getDeptTenantIgnore(startUser.getDeptId());
        }
        return success(BpmProcessInstanceConvert.INSTANCE.buildProcessInstance(processInstance,
                processDefinition, processDefinitionInfo, bpmnXml, startUser, dept));
    }

    @DeleteMapping("/cancel-by-start-user")
    @Operation(summary = "用户取消流程实例", description = "取消发起的流程")
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:cancel')")
    public CommonResult<Boolean> cancelProcessInstanceByStartUser(
            @Valid @RequestBody BpmProcessInstanceCancelReqVO cancelReqVO) {
        processInstanceService.cancelProcessInstanceByStartUser(getLoginUserId(), cancelReqVO);
        return success(true);
    }

    @DeleteMapping("/cancel-by-admin")
    @Operation(summary = "管理员取消流程实例", description = "管理员撤回流程")
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:cancel-by-admin')")
    public CommonResult<Boolean> cancelProcessInstanceByManager(
            @Valid @RequestBody BpmProcessInstanceCancelReqVO cancelReqVO) {
        processInstanceService.cancelProcessInstanceByAdmin(getLoginUserId(), cancelReqVO);
        return success(true);
    }

    @GetMapping("/get-approval-detail")
    @Operation(summary = "获得审批详情")
    @Parameter(name = "id", description = "流程实例的编号", required = true)
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    public CommonResult<BpmApprovalDetailRespVO> getApprovalDetail(@Valid BpmApprovalDetailReqVO reqVO) {
        return success(processInstanceService.getApprovalDetail(getLoginUserId(), reqVO));
    }

    @GetMapping("/get-bpmn-model-view")
    @Operation(summary = "获取流程实例的 BPMN 模型视图", description = "在【流程详细】界面中，进行调用")
    @Parameter(name = "id", description = "流程实例的编号", required = true)
    public CommonResult<BpmProcessInstanceBpmnModelViewRespVO> getProcessInstanceBpmnModelView(@RequestParam(value = "id") String id) {
        return success(processInstanceService.getProcessInstanceBpmnModelView(id));
    }

    @GetMapping("/elderly-checkin-page")
    @Operation(summary = "获取入住申请流程实例", description = "在【我的流程】菜单中，进行调用")
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyCheckinInfoRespVO>> getProcessInstanceElderlyCheckinPage(
            @Valid ElderlyCheckinRecordPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(pageReqVO.getTenantIds() == null ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<ElderlyCheckinInfoRespVO> pageResult = processInstanceService.getElderlyCheckinPage(getLoginUserId(), pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/elderly-retreat-page")
    @Operation(summary = "获取入住申请流程实例", description = "在【我的流程】菜单中，进行调用")
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    @TenantIgnore
    public CommonResult<PageResult<ElderlyRetreatRecordRespVO>> getProcessInstanceElderlyRetreatPage(
            @Valid ElderlyRetreatRecordPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<ElderlyRetreatRecordRespVO> pageResult = processInstanceService.getElderlyRetreatPage(getLoginUserId(), pageReqVO);
        return success(BeanUtils.toBean(pageResult, ElderlyRetreatRecordRespVO.class));
    }

    @GetMapping("/getBusinessId")
//    @PreAuthorize("@ss.hasPermission('bpm:apply-retreat:getBusinessId')")
    @Parameter(name = "processInstanceId", description = "流程实例id", required = true, example = "bd728f76-5a11-11ef-98ac-00155d6a6c52")
    @Operation(summary = "根据流程id获取业务id")
    public CommonResult<BpmBusinessFormDO> getBusinessId(@RequestParam("processInstanceId") String processInstanceId) {
        BpmBusinessFormDO businessFormDO = businessFormService.getBusinessFormByInstanceId(processInstanceId);
        return success(businessFormDO);
    }

    @GetMapping("/bed-change-page")
    @Operation(summary = "获取床位变更流程实例", description = "在【我的流程】菜单中，进行调用")
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    @TenantIgnore
    public CommonResult<PageResult<BedChangeRecordRespVO>> getProcessInstanceBedChangePage(
            @Valid BedChangePageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<BedChangeRecordRespVO> pageResult = processInstanceService.getProcessInstanceBedChangePage(getLoginUserId(), pageReqVO);
        return success(BeanUtils.toBean(pageResult, BedChangeRecordRespVO.class));
    }

    @GetMapping("/nurse-change-page")
    @Operation(summary = "获取护理变更流程实例", description = "在【我的流程】菜单中，进行调用")
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    @TenantIgnore
    public CommonResult<PageResult<NurseChangeRecordRespVO>> getProcessInstanceNurseChangePage(
            @Valid BedChangePageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<NurseChangeRecordRespVO> pageResult = processInstanceService.getProcessInstanceNurseChangePage(getLoginUserId(), pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/catering-change-page")
    @Operation(summary = "获取餐饮变更流程实例", description = "在【我的流程】菜单中，进行调用")
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    @TenantIgnore
    public CommonResult<PageResult<CateringChangeRecordRespVO>> getProcessInstanceCateringChangePage(
            @Valid BedChangePageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<CateringChangeRecordRespVO> pageResult = processInstanceService.getProcessInstanceCateringChangePage(getLoginUserId(), pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/price-change-page")
    @Operation(summary = "获取价格变更流程实例", description = "在【我的流程】菜单中，进行调用")
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    @TenantIgnore
    public CommonResult<PageResult<PriceChangeRecordRespVO>> getProcessInstancePriceChangePage(
            @Valid BedChangePageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<PriceChangeRecordRespVO> pageResult = processInstanceService.getProcessInstancePriceChangePage(getLoginUserId(), pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/transfer-change-page")
    @Operation(summary = "获取转院变更流程实例", description = "在【我的流程】菜单中，进行调用")
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    @TenantIgnore
    public CommonResult<PageResult<TransferChangeRecordRespVO>> getProcessInstanceTransferChangePage(
            @Valid BedChangePageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()}  : pageReqVO.getTenantIds());
        PageResult<TransferChangeRecordRespVO> pageResult = processInstanceService.getProcessInstanceTransferChangePage(getLoginUserId(), pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/my-bpm-page")
    @Operation(summary = "我的流程-业务结合", description = "在【我的流程】菜单中，进行调用")
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    public CommonResult<PageResult<?>> getBpmPage(@Valid BpmMyPageReqVO pageReqVO) {


        if (0 == pageReqVO.getQueryType()) {

        }

        if (1 == pageReqVO.getQueryType()) {
            BpmTaskPageReqVO pageVO = BeanUtils.toBean(pageReqVO, BpmTaskPageReqVO.class);
            PageResult<BpmTaskRespVO> pageResult = taskService.getTaskTodoPage(WebFrameworkUtils.getLoginUserId(), pageVO);
            if (CollUtil.isEmpty(pageResult.getList())) {
                return success(PageResult.empty());
            }
            return success(pageResult);
        }

        if (2 == pageReqVO.getQueryType()) {
            BpmTaskPageReqVO pageVO = BeanUtils.toBean(pageReqVO, BpmTaskPageReqVO.class);
            PageResult<BpmTaskRespVO> pageResult = taskService.getTaskDonePage(WebFrameworkUtils.getLoginUserId(), pageVO);
//            BpmProcessInstancePageReqVO pageVO = BeanUtils.toBean(pageReqVO, BpmProcessInstancePageReqVO.class);
//            PageResult<BpmProcessInstanceRespVO> pageResult = processInstanceService.getDoneProcessInstancePage(
//                    getLoginUserId(), pageVO);
            if (CollUtil.isEmpty(pageResult.getList())) {
                return success(PageResult.empty());
            }
            return success(pageResult);
        }

        if (3 == pageReqVO.getQueryType()) {
            BpmProcessInstancePageReqVO pageVO = BeanUtils.toBean(pageReqVO, BpmProcessInstancePageReqVO.class);
            PageResult<BpmProcessInstanceRespVO> pageResult = processInstanceService.getProcessInstancePage(
                    getLoginUserId(), pageVO);




            if (CollUtil.isEmpty(pageResult.getList())) {
                return success(PageResult.empty(pageResult.getTotal()));
            }
            return success(pageResult);
        }

        if (4 == pageReqVO.getQueryType()) {

        }

        if (5 == pageReqVO.getQueryType()) {

        }
        PageResult<BpmElderlyInfoVO> pageResult = processInstanceService.getMyBpmPage(getLoginUserId(), getLoginUserNickname(), pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/check-in-page")
    @Operation(summary = "获取办理入住流程实例", description = "在【我的流程】菜单中，进行调用")
//    @PreAuthorize("@ss.hasPermission('bpm:process-instance:query')")
    @TenantIgnore
    public CommonResult<PageResult<CheckInRecordRespVO>> getProcessInstanceCheckInPage(
            @Valid CheckInPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(pageReqVO.getTenantIds() == null ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<CheckInRecordRespVO> pageResult = processInstanceService.getProcessInstanceCheckInPage(getLoginUserId(), pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/check-in-wait-page")
    @Operation(summary = "获取轮候入住流程实例", description = "在【我的流程】菜单中，进行调用")
    @TenantIgnore
    public CommonResult<PageResult<CheckInWaitRecordRespVO>> getProcessInstanceCheckInWaitPage(
            @Valid CheckInWaitPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(pageReqVO.getTenantIds() == null ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<CheckInWaitRecordRespVO> pageResult = processInstanceService.getProcessInstanceCheckInWaitPage(getLoginUserId(), pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/deleteAllHistoricProcessInstance")
    public CommonResult<Boolean> deleteAllHistoricProcessInstance() {
        processInstanceService.deleteAllHistoricProcessInstance();
        return success(Boolean.TRUE);
    }

    @DeleteMapping("/timedClosureProcess")
    public CommonResult<Boolean> timedClosureProcess(
            @Valid @RequestBody BpmProcessInstanceCancelReqVO cancelReqVO) {
        processInstanceService.cancelProcessInstanceByAdmin(getLoginUserId(), cancelReqVO);
        return success(true);
    }




}
