Powerjob-server 服务管理端 4.3.6 版本
zrj
2024-09-24 1216a77e26cb2c788fa6a78991e073e671f0f59d
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
package tech.powerjob.worker.persistence;
 
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
 
/**
 * 简单查询直接类,只支持 select * from task_info where xxx = xxx and xxx = xxx 的查询
 *
 * @author tjq
 * @since 2020/3/17
 */
@Data
public class SimpleTaskQuery {
 
    private static final String LINK = " and ";
 
    private String taskId;
    private Long subInstanceId;
    private Long instanceId;
    private String taskName;
    private String address;
    private Integer status;
 
    // 自定义的查询条件(where 后面的语句),如 crated_time > 10086 and status = 3
    private String queryCondition;
    // 自定义的查询条件,如 GROUP BY status
    private String otherCondition;
 
    // 查询内容,默认为 *
    private String queryContent = " * ";
 
    private Integer limit;
 
    public String getQueryCondition() {
        StringBuilder sb = new StringBuilder();
        if (!StringUtils.isEmpty(taskId)) {
            sb.append("task_id = '").append(taskId).append("'").append(LINK);
        }
        if (subInstanceId != null) {
            sb.append("sub_instance_id = ").append(subInstanceId).append(LINK);
        }
        if (instanceId != null) {
            sb.append("instance_id = ").append(instanceId).append(LINK);
        }
        if (!StringUtils.isEmpty(address)) {
            sb.append("address = '").append(address).append("'").append(LINK);
        }
        if (!StringUtils.isEmpty(taskName)) {
            sb.append("task_name = '").append(taskName).append("'").append(LINK);
        }
        if (status != null) {
            sb.append("status = ").append(status).append(LINK);
        }
 
        if (!StringUtils.isEmpty(queryCondition)) {
            sb.append(queryCondition).append(LINK);
        }
 
        String substring = sb.substring(0, sb.length() - LINK.length());
 
        if (!StringUtils.isEmpty(otherCondition)) {
            substring += otherCondition;
        }
 
        if (limit != null) {
            substring = substring + " limit " + limit;
        }
        return substring;
    }
}