ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package com.vci.common.qt.object;
 
import java.util.Iterator;
import java.util.Map;
 
public class Condition {
    private String rootCIName;
    private Map<String, ConditionItem> ciMap;
    
    public String getRootCIName() {
        return rootCIName;
    }
    public void setRootCIName(String rootCIName) {
        this.rootCIName = rootCIName;
    }
    
    /**
     * 根据CIMap解析出根节点
     * @param ciMap
     * @return
     */
    public String getRootCINameByCIMap(Map<String, ConditionItem> ciMap){
        String rootCIName = "";
        if(ciMap != null){
            for(Iterator<String> i = ciMap.keySet().iterator(); i.hasNext();){
                String ciName = i.next();
                if(rootCIName.equals("")){
                    rootCIName = ciName;
                }else{
                    int rootInt = Integer.valueOf(rootCIName.substring(2));
                    int ciInt = Integer.valueOf(ciName.substring(2));
                    if(ciInt > rootInt){
                        rootCIName = ciName;
                    }
                }
            }
        }
        return rootCIName;
    }
    public Map<String, ConditionItem> getCIMap() {
        return ciMap;
    }
    public void setCIMap(Map<String, ConditionItem> cIMap) {
        this.ciMap = cIMap;
    }
    
    /**
     * 将查询条件解析成sql
     * @param qt
     * @param addGrandRightFlag 是否加上权限的条件, 默认应为true
     *     当权限开关开启(right.switch=on), 并且addGrandRightFlag=true时才会加权限条件
     * @return
     */
//    public String getSql(QueryTemplate qt, boolean addGrandRightFlag){
//        StringBuilder strb = new StringBuilder("");
//        ConditionItem rootCI = ciMap.get(this.getRootCIName());
//        if(rootCI.isLeaf()){
//            strb.append(rootCI.getSql(qt, addGrandRightFlag));
//        }else{
//            ConditionItem root = rootCI;
//            ConditionItem left = ciMap.get(root.getChildrenInfo().getLeftCIName());
//            ConditionItem right = ciMap.get(root.getChildrenInfo().getRightCIName());
//            String treeSql = parseTree(left, root, right, qt, addGrandRightFlag);
//            strb.append(treeSql);
//        }
//        
//        return strb.toString();
//    }
    
    /**
     * 将查询条件中的link条件解析成sql
     * @param qt
     * @return
     */
//    public String getLinkConditionSql(QueryTemplate qt, boolean addGrandRightFlag){
//        StringBuilder stb = new StringBuilder("");
//        ConditionItem rootCI = ciMap.get(this.getRootCIName());
//        if(rootCI.isLeaf()){
//            if(!isBtmContidionItem(rootCI)){
//                return rootCI.getSql(qt, addGrandRightFlag);
//            }else{
//                return stb.toString();
//            }
//        }else{
//            ConditionItem root = rootCI;
//            ConditionItem left = ciMap.get(root.getChildrenInfo().getLeftCIName());
//            ConditionItem right = ciMap.get(root.getChildrenInfo().getRightCIName());
//            if(!isBtmContidionItem(left) && !isBtmContidionItem(right)){
//                String treeSql = parseTree(left, root, right, qt, addGrandRightFlag);
//                stb.append(treeSql);
//            }else if(!isBtmContidionItem(left)){
//                String rootCIName = this.getRootCIName();
//                this.setRootCIName(left.getId());
//                String sql = getSql(qt, addGrandRightFlag);
//                this.setRootCIName(rootCIName);
//                return sql;
//            }else if(!isBtmContidionItem(right)){
//                String rootCIName = this.getRootCIName();
//                this.setRootCIName(right.getId());
//                String sql = getSql(qt, addGrandRightFlag);
//                this.setRootCIName(rootCIName);
//                return sql;
//            }else{
//                return stb.toString();
//            }
//        }
//        
//        return stb.toString();
//    }
    
    /**
     * 将查询条件中的btm条件解析成sql
     * @param qt
     * @return
     */
//    public String getBtmConditionSql(QueryTemplate qt, boolean addGrandRightFlag){
//        StringBuilder stb = new StringBuilder("");
//        ConditionItem rootCI = ciMap.get(this.getRootCIName());
//        if(rootCI.isLeaf()){
//            if(isBtmContidionItem(rootCI)){
//                return rootCI.getSql(qt, addGrandRightFlag);
//            }else{
//                return stb.toString();
//            }
//        }else{
//            ConditionItem root = rootCI;
//            ConditionItem left = ciMap.get(root.getChildrenInfo().getLeftCIName());
//            ConditionItem right = ciMap.get(root.getChildrenInfo().getRightCIName());
//            if(isBtmContidionItem(left) && isBtmContidionItem(right)){
//                String treeSql = parseTree(left, root, right, qt, addGrandRightFlag);
//                stb.append(treeSql);
//            }else if(isBtmContidionItem(left)){
//                String rootCIName = this.getRootCIName();
//                this.setRootCIName(left.getId());
//                String sql = getSql(qt, addGrandRightFlag);
//                this.setRootCIName(rootCIName);
//                return sql;
//            }else if(isBtmContidionItem(right)){
//                String rootCIName = this.getRootCIName();
//                this.setRootCIName(right.getId());
//                String sql = getSql(qt, addGrandRightFlag);
//                this.setRootCIName(rootCIName);
//                return sql;
//            }else{
//                return stb.toString();
//            }
//        }
//        
//        return stb.toString();
//    }
    
    /**
     * 递归解析ConditionItem树结构
     * @param left
     * @param root
     * @param right
     * @return
     */
//    public String parseTree(ConditionItem left, ConditionItem root, ConditionItem right, QueryTemplate qt, boolean addGrandRightFlag){
//        StringBuilder strb = new StringBuilder("");
//        strb.append(Symbol.LEFT_PAREN);
//        if(left.isLeaf()){
//            strb.append(left.getSql(qt, addGrandRightFlag));
//        }else{
//            ConditionItem left_ = ciMap.get(left.getChildrenInfo().getLeftCIName());
//            ConditionItem root_ = left;
//            ConditionItem right_ = ciMap.get(left.getChildrenInfo().getRightCIName());
//            String treeSql = parseTree(left_, root_, right_, qt, addGrandRightFlag);
//            strb.append(treeSql);
//        }
//        strb.append(Symbol.SPACE);
//        String connector = root.getChildrenInfo().getConnector();
//        if(connector.equals(Connector.ANDCN)){
//            connector = Connector.AND;
//        }
//        if(connector.equals(Connector.ORCN)){
//            connector = Connector.OR;
//        }
//        strb.append(connector);
//        strb.append(Symbol.SPACE);
//        if(right.isLeaf()){
//            strb.append(right.getSql(qt, addGrandRightFlag));
//        }else{
//            ConditionItem left_ = ciMap.get(right.getChildrenInfo().getLeftCIName());
//            ConditionItem root_ = right;
//            ConditionItem right_ = ciMap.get(right.getChildrenInfo().getRightCIName());
//            String treeSql = parseTree(left_, root_, right_, qt, addGrandRightFlag);
//            strb.append(treeSql);
//        }
//        strb.append(Symbol.RIGHT_PAREN);
//        return strb.toString();
//    }
    
//    /**
//     * 在链接查询的查询条件中
//     * 判断查询条件项是否是约束业务对象的
//     * @return
//     */
//    public boolean isBtmContidionItem(ConditionItem ci){
//        while(!ci.isLeaf()){
//            ci = ciMap.get(ci.getChildrenInfo().getRightCIName());
//        }
//        String clause = ci.getLeafInfo().getClause();
//        if(clause.startsWith("T_OID.") || clause.startsWith("F_OID.")){
//            return true;
//        }
//        return false;
//    }
}