流程節點改派人/組

說明

我們在流程裏可能也會遇到這樣的需求:有人不想批這個單子了,或者太多批不過來了。。。想要把這個單子交給別人去批,那這個時候就改變這個節點的指派人/組就好啦,引擎自帶了setAssignee和addCandidateGroup接口,可以直接調用。改派一般有四種情況:人->人,人->組,組->人,組->組。我下面寫的邏輯爲:

①人->人的時候直接改;

②人->組的時候需要移除指定人,並且只能有一個組;

③組->人的時候需要移除之前的組,再添加人;

④組->組同樣是先移除之前的組,再添加組;

這段邏輯可以根據你自己的情況去改寫,比如你希望指派組不用移除之前的人/組,就不需要deleteCandidateGroup了。

快速開始

編寫一個controller,前端必傳taskId,username/groupId選一個

    @Autowired
    private TaskService taskService;
    @PostMapping("/changeAssigned/{taskId}")
    public String changeAssigned(@PathVariable String taskId,
                                    @RequestParam(name = "username", required = false) String username,
                                    @RequestParam(name = "groupId", required = false) String groupId) {
        // 需要先重置之前的指派
        List<IdentityLink> identityLinksForTask = taskService.getIdentityLinksForTask(taskId);
        for (IdentityLink identityLink : identityLinksForTask) {
            if (identityLink.getGroupId()==null) {
                continue;
            }
            taskService.deleteCandidateGroup(taskId, identityLink.getGroupId());
        }
        // 判斷是人/組任務
        if (username != null) {
            taskService.setAssignee(taskId, username);
        } else {
            taskService.addCandidateGroup(taskId, groupId);
            taskService.setAssignee(taskId, null);
        }
        return "改派成功";
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章