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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
package com.vci.client.omd.btm.ui;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.HighlighterFactory;
 
import com.vci.client.omd.linktype.LinkTypeStart;
import com.vci.client.ui.table.CheckBoxEditor;
import com.vci.client.ui.table.CheckBoxRenderer;
import com.vci.corba.common.VCIError;
 
public class DeleteDataDialog extends JDialog{
 
    /**
     * 
     */
    private static final long serialVersionUID = 2315167245802578900L;
    
    private String[] tables = new String[]{"pl_qtemplate", "PL_QTEMPLATEDEF", 
            "pl_typeright", "plcommandparameter", "plpagedefination", 
            "pluilayout", "pltabbutton", "pltabpage", "plportalvi",
            "plreleasedobj"
    };
    /**
     * workFlowTables 中的表有主外键关系,当表主键或唯一键被引用为外键时,
     * 就算引用方没有数据, truncate还不是不能删除表中数据, 而 delete可以.
     */
    private String[] workFlowTables = new String[]{
            //流程(自定义表)
            "PLPROCESSTEMPLATE", "PLPROCESSCATEGORY", "PLPROCESSTASK",//"PLRMTEMPLATEPROCESS", 
            "PLPROCESSTASKPROPERTY", "PLFLOWAPPROVEOPINION", "PLFLOWOBJECT", "PLFLOWINSTANCE",
            "WORKFLOW_TASK_CC_TABLE", "PLTASKDESC", "PLTASKSASSIGNED", "JBPM_SUBPROCESSTEM",
            "JBPM4_TASKANDUSERCONFIG", "PLREVOKEPOLICY", "JBPM4_TASKANDUSERCONFIGEX",
            //流程(JBPM系统表)
            "JBPM4_DEPLOYPROP", "JBPM4_HIST_DETAIL", "JBPM4_ID_MEMBERSHIP", "JBPM4_JOB",
            "JBPM4_PARTICIPATION", "JBPM4_VARIABLE", "JBPM4_HIST_ACTINST", "JBPM4_HIST_VAR",
            "JBPM4_ID_GROUP", "JBPM4_ID_USER", "JBPM4_LOB", "JBPM4_DEPLOYMENT",
            "JBPM4_HIST_PROCINST", "JBPM4_HIST_TASK", "JBPM4_TASK", "JBPM4_SWIMLANE",
            "JBPM4_EXECUTION", "JBPM4_PROPERTY"    
    };
    private List<String> btNames, ltNames;
    private JPanel centerPanel;
    private JPanel southPanel;
    private JButton btnDelete;
    private JButton btnCancel;
    private JXTable table;
    private TableModelWithCheckBox model;
    private final int TABLE_HEADER_HEIGHT = 25;
    private final int ROW_HEIGHT = 30;
    private JButton btnSelAll;
    private JButton btnSelOpp;
    private JPanel northPanel;
    
    /**
     * 
     * @param btNames
     * @param ltNames
     * @param exceptBts : 保留的业务类型
     */
    public DeleteDataDialog(List<String> btNames, List<String> ltNames){
        this.btNames = btNames;
        this.ltNames = ltNames;
        initUI();
        addListener();
        initData();
    }
 
    private void initUI(){
        this.setTitle("清除数据框");
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        this.setSize(screenSize.width/2, screenSize.height/2);
        this.setModal(true);
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        this.setLayout(new BorderLayout());
        
        northPanel = new JPanel();
        northPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
        centerPanel = new JPanel();
        centerPanel.setLayout(new BorderLayout());
        southPanel = new JPanel();
        southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
        this.add(northPanel, BorderLayout.NORTH);
        this.add(centerPanel, BorderLayout.CENTER);
        this.add(southPanel, BorderLayout.SOUTH);
        
        btnSelAll = new JButton("全选");
        btnSelOpp = new JButton("反选");
        northPanel.add(btnSelAll);
        northPanel.add(btnSelOpp);
        
        table = new JXTable();
        model = new TableModelWithCheckBox();
        model.setColumnCount(4);
        model.setColumnIdentifiers(new String[]{"", "类型名 ", "类型", "清除状态"});
        table.setModel(model);
        TableColumn column = table.getColumn(0);
        column.setCellEditor(new CheckBoxEditor(new JCheckBox()));
        column.setCellRenderer(new CheckBoxRenderer());
        column.setPreferredWidth(10);
        table.setHorizontalScrollEnabled(true);
        table.setAutoscrolls(true);
        table.setSortable(false);
        table.setHighlighters(HighlighterFactory.createAlternateStriping());
        table.setRowHeight(ROW_HEIGHT);
        //设置表头高度
        JTableHeader tableHeader = table.getTableHeader();
        Dimension size = tableHeader.getPreferredSize();
        size.height = TABLE_HEADER_HEIGHT;
        tableHeader.setPreferredSize(size);        
        
        
        centerPanel.add(new JScrollPane(table), BorderLayout.CENTER);
        
        btnDelete = new JButton("清除");
        btnCancel = new JButton("关闭");
        southPanel.add(btnDelete);
        southPanel.add(btnCancel);
    }
    
    private void initData(){
        // 重新设置table的Cell的可编辑性
        model.setInitFlag(false);
        int btSize = btNames.size();
        int ltSize = ltNames.size();
        model.setRowCount(btSize + ltSize + tables.length + workFlowTables.length);
        for(int i = 0; i < btSize; i++){
            table.setValueAt(new JCheckBox(), i, 0);
            table.setValueAt(btNames.get(i), i, 1);
            table.setValueAt("业务类型", i, 2);
            table.setValueAt("未清除", i, 3);
        }
        
        for(int i = 0; i < ltSize; i++){
            table.setValueAt(new JCheckBox(), i + btSize, 0);
            table.setValueAt(ltNames.get(i), i + btSize, 1);
            table.setValueAt("链接类型", i + btSize, 2);
            table.setValueAt("未清除", i + btSize, 3);
        }
        
        for(int i = 0; i< tables.length; i++){
            table.setValueAt(new JCheckBox(), i + btSize + ltSize, 0);
            table.setValueAt(tables[i], i + btSize + ltSize, 1);
            table.setValueAt("-", i + btSize + ltSize, 2);
            table.setValueAt("未清除", i + btSize + ltSize, 3);
        }
        
        for(int i = 0; i< workFlowTables.length; i++){
            table.setValueAt(new JCheckBox(), i + btSize + ltSize + tables.length, 0);
            table.setValueAt(workFlowTables[i], i + btSize + ltSize + tables.length, 1);
            table.setValueAt("-", i + btSize + ltSize + tables.length, 2);
            table.setValueAt("未清除", i + btSize + ltSize + tables.length, 3);
        }
        // 重新设置table的Cell的可编辑性
        model.setInitFlag(true);
    }
    
    private void addListener() {
        btnSelAll.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                selectAll();
            }
        });
        btnSelOpp.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                selectOpposite();
            }
        });
        btnDelete.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                if(!hasSelect()){
                    JOptionPane.showMessageDialog(getInstance(), "请选择要清楚的数据类型", "未选中数据", JOptionPane.INFORMATION_MESSAGE);
                    return;
                }
                int option = JOptionPane.showConfirmDialog(getInstance(), "确认删除所选类型数据?该操作不可回滚", "删除确认框", JOptionPane.YES_NO_OPTION);
                if(option != JOptionPane.YES_OPTION){
                    return;
                }
                int btSize = btNames.size();
                int ltSize = ltNames.size();
                //truncate业务类型数据
                for(int i = 0; i < btSize; i++){
                    if(!((JCheckBox)table.getValueAt(i, 0)).isSelected()){
                        continue;
                    }
                    String btName = (String) table.getValueAt(i, 1);
                    //String btmTableName = OmdTools.getBTTableName(btName);
                    try {
                        if(BtmClient.getService().truncateTable(btName)){
                            updateTable(i, 3, "成功");
                        }
                    } catch (VCIError e1) {
                        e1.printStackTrace();
                        updateTable(i, 3, "失败");
                    }
                }
                //truncate链接类型数据
                for(int i = 0; i < ltSize; i++){
                    if(!((JCheckBox)table.getValueAt(i + btSize, 0)).isSelected()){
                        continue;
                    }
                    String ltName = (String) table.getValueAt(i + btSize, 1);
                    //String ltTableName = OmdTools.getLTTableName(ltName);
                    try {
                        if(LinkTypeStart.getService().truncateTable(ltName)){
                            updateTable(i + btSize, 3, "成功");
                        }
                    } catch (VCIError e1) {
                        e1.printStackTrace();
                        updateTable(i + btSize, 3, "失败");
                    }
                }
                
                //truncate QT, RIGHT, UI数据
//                for(int i = 0; i < tables.length; i++){
//                    if(!((JCheckBox)table.getValueAt(i + btSize + ltSize, 0)).isSelected()){
//                        continue;
//                    }
//                    String tableName = (String) table.getValueAt(i + btSize + ltSize, 1);
//                    try {
//                        if(BtmClient.getService().truncateTable(tableName)){
//                            updateTable(i + btSize + ltSize, 3, "成功");
//                        }
//                    } catch (VCIError e1) {
//                        e1.printStackTrace();
//                        updateTable(i + btSize + ltSize, 3, "失败");
//                    }
//                }
                
                //workflow数据
//                for(int i = 0; i < workFlowTables.length; i++){
//                    if(!((JCheckBox)table.getValueAt(i + btSize + ltSize + tables.length, 0)).isSelected()){
//                        continue;
//                    }
//                    String tableName = (String) table.getValueAt(i + btSize + ltSize  + tables.length, 1);
//                    try {
//                        if(BtmClient.getService().deleteTable(tableName)){
//                            updateTable(i + btSize + ltSize + tables.length, 3, "成功");
//                        }
//                    } catch (VCIError e1) {
//                        e1.printStackTrace();
//                        updateTable(i + btSize + ltSize + tables.length, 3, "失败");
//                    }
//                }
                
                JOptionPane.showMessageDialog(getInstance(), "清楚数据完成", "清楚数据完成", JOptionPane.INFORMATION_MESSAGE);
            }
 
        });
        
        btnCancel.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                dipose_();
            }
        });
    }
    
    /**
     * 判断table中是否有选择的记录
     * @return
     */
    protected boolean hasSelect() {
        for(int i = 0; i < table.getRowCount(); i++){
            if(((JCheckBox)table.getValueAt(i, 0)).isSelected()){
                return true;
            }
        }
        return false;
    }
 
    /**
     * 更新table单元格的值
     * @param row
     * @param column
     * @param value
     */
    private void updateTable(int row, int column, String value) {
        // 重新设置table的Cell的可编辑性
        model.setInitFlag(false);
        table.setValueAt(value, row, column);
        model.setInitFlag(true);
        table.updateUI();
    }
 
    /**
     * 全选
     */
    private void selectAll() {
        for(int i = 0; i < table.getRowCount(); i++){
            ((JCheckBox)table.getValueAt(i, 0)).setSelected(true);
        }
        table.updateUI();
    }
    
    /**
     * 反选
     */
    private void selectOpposite() {
        for(int i = 0; i < table.getRowCount(); i++){
            JCheckBox chb = ((JCheckBox)table.getValueAt(i, 0));
            if(chb.isSelected()){
                chb.setSelected(false);
            }else{
                chb.setSelected(true);
            }
        }
        table.updateUI();
    }
 
    private void dipose_(){
        this.dispose();
    }
    
    
    private JDialog getInstance(){
        return this;
    }
 
}