ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package jnpf.flowable.mapper;
 
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.util.StringUtil;
import com.github.yulichang.extension.mapping.wrapper.MappingQuery;
import jnpf.base.mapper.SuperMapper;
import jnpf.flowable.entity.CandidatesEntity;
import jnpf.flowable.entity.OperatorEntity;
import jnpf.flowable.model.util.FlowNature;
import jnpf.util.RandomUtil;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 类的描述
 *
 * @author JNPF@YinMai Info. Co., Ltd
 * @version 5.0.x
 * @since 2024/4/18 16:00
 */
public interface CandidatesMapper extends SuperMapper<CandidatesEntity> {
 
    default List<CandidatesEntity> getList(String taskId, String nodeCode) {
        QueryWrapper<CandidatesEntity> queryWrapper = new QueryWrapper<>();
        if (StringUtil.isNotEmpty(taskId)) {
            queryWrapper.lambda().eq(CandidatesEntity::getTaskId, taskId);
        }
        if (StringUtil.isNotEmpty(nodeCode)) {
            queryWrapper.lambda().eq(CandidatesEntity::getNodeCode, nodeCode);
        }
        return this.selectList(queryWrapper);
    }
 
    default List<CandidatesEntity> getListByCode(String taskId, String nodeCode) {
        QueryWrapper<CandidatesEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(CandidatesEntity::getTaskId, taskId).eq(CandidatesEntity::getNodeCode, nodeCode);
        return this.selectList(queryWrapper);
    }
 
    default void deleteByCodes(String taskId, List<String> nodeIds) {
        QueryWrapper<CandidatesEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(CandidatesEntity::getTaskId, taskId);
        if (CollectionUtil.isNotEmpty(nodeIds)) {
            queryWrapper.lambda().in(CandidatesEntity::getNodeCode, nodeIds);
        }
        List<CandidatesEntity> list = this.selectList(queryWrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            this.deleteByIds(list);
        }
    }
 
    default void delete(String taskId, List<String> nodeIds, List<String> userId) {
        QueryWrapper<CandidatesEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(CandidatesEntity::getTaskId, taskId).in(CandidatesEntity::getHandleId, userId);
        if (CollectionUtil.isNotEmpty(nodeIds)) {
            queryWrapper.lambda().in(CandidatesEntity::getNodeCode, nodeIds);
        }
        List<CandidatesEntity> list = this.selectList(queryWrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            this.deleteByIds(list);
        }
    }
 
    default List<String> getBranch(String taskId, String nodeCode) {
        List<String> resList = new ArrayList<>();
        QueryWrapper<CandidatesEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(CandidatesEntity::getTaskId, taskId).eq(CandidatesEntity::getNodeCode, nodeCode)
                .eq(CandidatesEntity::getType, FlowNature.Branch);
        List<CandidatesEntity> list = this.selectList(queryWrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            for (CandidatesEntity entity : list) {
                if (jnpf.util.StringUtil.isNotEmpty(entity.getCandidates())) {
                    List<String> branch = Arrays.stream(entity.getCandidates().split(",")).collect(Collectors.toList());
                    resList.addAll(branch);
                }
            }
        }
        return resList;
    }
 
    default void createBranch(List<String> branchList, OperatorEntity operator) {
        if (CollectionUtil.isNotEmpty(branchList)) {
            this.deleteBranch(operator.getTaskId(), operator.getNodeCode());
            CandidatesEntity entity = new CandidatesEntity();
            entity.setId(RandomUtil.uuId());
            entity.setTaskId(operator.getTaskId());
            entity.setNodeCode(operator.getNodeCode());
            entity.setOperatorId(operator.getId());
            entity.setType(FlowNature.Branch);
            entity.setCandidates(String.join(",", branchList));
            this.insert(entity);
        }
    }
 
    default void deleteBranch(String taskId, String nodeCode) {
        QueryWrapper<CandidatesEntity> wrapper = new MappingQuery<>();
        wrapper.lambda().eq(CandidatesEntity::getTaskId, taskId).eq(CandidatesEntity::getNodeCode, nodeCode)
                .eq(CandidatesEntity::getType, FlowNature.Branch);
        this.delete(wrapper);
    }
 
}