ny
23 小时以前 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
package jnpf.flowable.mapper;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jnpf.base.mapper.SuperMapper;
import jnpf.flowable.entity.TaskLineEntity;
import jnpf.util.RandomUtil;
 
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * 类的描述
 *
 * @author JNPF@YinMai Info. Co., Ltd
 * @version 5.0.x
 * @since 2024/8/23 17:35
 */
public interface TaskLineMapper extends SuperMapper<TaskLineEntity> {
 
    default List<TaskLineEntity> getList(String taskId) {
        QueryWrapper<TaskLineEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(TaskLineEntity::getTaskId, taskId);
        return this.selectList(queryWrapper);
    }
 
    default void create(String taskId, Map<String, Boolean> conditionResMap) {
        if (CollectionUtil.isEmpty(conditionResMap)) {
            return;
        }
        List<TaskLineEntity> createList = new ArrayList<>();
        List<TaskLineEntity> updateList = new ArrayList<>();
 
        List<TaskLineEntity> list = this.getList(taskId);
 
        if (CollectionUtil.isNotEmpty(list)) {
            conditionResMap.forEach((k, v) -> {
                TaskLineEntity entity = list.stream().filter(e -> ObjectUtil.equals(k, e.getLineKey())).findFirst().orElse(null);
                if (null != entity) {
                    Boolean b = conditionResMap.get(entity.getLineKey());
                    if (null != b) {
                        entity.setLineValue(String.valueOf(b));
                        updateList.add(entity);
                    }
                } else {
                    entity = new TaskLineEntity();
                    entity.setId(RandomUtil.uuId());
                    entity.setTaskId(taskId);
                    entity.setLineKey(k);
                    entity.setLineValue(String.valueOf(v));
                    createList.add(entity);
                }
            });
        } else {
            conditionResMap.forEach((k, v) -> {
                TaskLineEntity entity = new TaskLineEntity();
                entity.setId(RandomUtil.uuId());
                entity.setTaskId(taskId);
                entity.setLineKey(k);
                entity.setLineValue(String.valueOf(v));
                createList.add(entity);
            });
        }
 
        if (CollectionUtil.isNotEmpty(createList)) {
            this.insert(createList);
        }
        if (CollectionUtil.isNotEmpty(updateList)) {
            this.updateById(updateList);
        }
    }
 
    default List<String> getLineKeyList(String taskId) {
        List<String> resList = new ArrayList<>();
        List<TaskLineEntity> list = this.getList(taskId);
        Map<String, List<TaskLineEntity>> collect = list.stream().collect(Collectors.groupingBy(TaskLineEntity::getLineKey));
        collect.forEach((k, v) -> {
            List<TaskLineEntity> sortList = v.stream().sorted(Comparator.comparing(TaskLineEntity::getCreatorTime).reversed()).collect(Collectors.toList());
            boolean bo = Boolean.parseBoolean(sortList.get(0).getLineValue());
            if (bo) {
                resList.add(k);
            }
        });
        return resList;
    }
 
}