xiejun
2023-08-01 87e43c42f5bccbbad9a922ee448834a70088d083
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
package com.vci.ubcs.codeapply;
 
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vci.base.ui.swing.VCIOptionPane;
import com.vci.base.ui.swing.VCISwingUtil;
import com.vci.base.ui.swing.components.*;
import com.vci.base.ui.tree.VCIBaseTree;
import com.vci.base.ui.tree.VCIBaseTreeModel;
import com.vci.base.ui.tree.VCIBaseTreeNode;
import com.vci.ubcs.code.vo.pagemodel.CodeClassifyTemplateVO;
import com.vci.ubcs.code.vo.pagemodel.CodeClassifyVO;
import com.vci.ubcs.codeapply.object.CodeClassify;
import com.vci.ubcs.codeapply.object.R;
import com.vci.ubcs.codeapply.utils.ConfigUtils;
import com.vci.ubcs.system.user.entity.User;
import lombok.SneakyThrows;
import net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
 
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
 
public class CodeApplyPanelFor410  extends VCIJPanel {
 
    //右侧面板
    private CodeApplyFor410MainPanel rightMainPanel = null;
    private VCIJScrollPane scrollLeftTreePane = new VCIJScrollPane();
    private VCIJSplitPane jspLeftToRight = new VCIJSplitPane(VCIJSplitPane.HORIZONTAL_SPLIT, scrollLeftTreePane, rightMainPanel);
    private CodeApplyPanelFor410ActionListener actionListener = new CodeApplyPanelFor410ActionListener(this);
    private VCIJButton applyBtn = VCISwingUtil.createVCIJButton("apply", "申请码值", "申请码值", "arrow-right.png", actionListener);
    private VCIJButton batchApplyBtn = VCISwingUtil.createVCIJButton("batchApply", "批量导入申请", "批量导入申请", "import.gif", actionListener);
    private VCIJButton btnSearch= VCISwingUtil.createVCIJButton("btnSearch", "查询代码", "查询代码", "search.png", actionListener);
    private VCIJButton clearBtn = VCISwingUtil.createVCIJButton("clear", "清空属性", "清空属性", "search.png", actionListener);
    private JLabel codeItemLabel = new JLabel("选择代码项:");
    private VCIJLabel applylbl = new VCIJLabel("申请码值:");
    public VCIJTextField applyTxt = new VCIJTextField(40);
    private JComboBox codeItemCombo = new JComboBox();
    private User userObj = null;;
 
    private CodeClassifyTemplateVO currentCodeClassifyTemplateVO;
    private boolean isIntegrate = false; //集成时不显示批量申请按钮
    /**
     * 存储分类的Map,key:分类名称,value:分类值
     */
    private String clsfName = null;
 
    private CodeApplyFor410Dialog owner;
    /**
     * 存储属性和值的Map,key:属性名称,value:属性值
     */
    private String deptName = null;
 
    private String[] libName = new String[]{};//代码项名称
    private VCIBaseTree leftTree = null;
    private VCIBaseTreeModel leftTreeModel = null;
    //左侧树
    private CodeApplyFor410TreePanel typeTreePanel = null;
    private TransmitTreeObject transmitTreeObject = new TransmitTreeObject();
 
 
    private String url=ConfigUtils.getConfigValue("410.code.url","http://127.0.0.1:36014/codeApplySwingController");
 
    /***
     *
     * @param userObj
     * @param isIntegrate
     * @param clsfName
     * @param deptName
     * @param libName
     */
    public CodeApplyPanelFor410(CodeApplyFor410Dialog owner , User userObj, boolean isIntegrate, String clsfName, String deptName, String[] libName){
        this.userObj = userObj;
        this.owner =owner;
        rightMainPanel = new CodeApplyFor410MainPanel(transmitTreeObject,userObj,getCurrentCodeClassifyTemplateVO());
        this.isIntegrate = isIntegrate;
        this.clsfName = clsfName;
        this.deptName = deptName;
        this.libName = libName;
        init();
        initActionListener();
    }
 
    /***
     * 初始化界面
     */
    private void init() {
        try {
            this.setLayout(new BorderLayout());
            this.add(initCodeItemPal(), BorderLayout.NORTH);
            this.add(initMiddlePanel(), BorderLayout.CENTER);
            this.add(initBtnPal(), BorderLayout.SOUTH);
            this.setVisible(true);
        }catch (Exception ex){
            VCIOptionPane.showMessage(owner,ex.getMessage());
        }
    }
    private JPanel initMiddlePanel()  {
        JPanel middlePanel = new JPanel();
        middlePanel.setLayout(new BorderLayout());
        JTextField jTextField1 = new JTextField();//instead of up line
        JTextField jTextField2 = new JTextField();//instead of down line
        jTextField1.setPreferredSize(new Dimension(63,2));
        jTextField2.setPreferredSize(new Dimension(63,2));
        middlePanel.add(jTextField1, BorderLayout.NORTH);
        middlePanel.add(jTextField2, BorderLayout.SOUTH);
 
 
        jspLeftToRight.setDividerSize(10);
        jspLeftToRight.setContinuousLayout(true);
        jspLeftToRight.setOneTouchExpandable(true);
        jspLeftToRight.setDividerLocation(200);
        initLeftPanel();
        middlePanel.add(jspLeftToRight, BorderLayout.CENTER);
 
        return middlePanel;
    }
 
    private JPanel initBtnPal() {
        JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        bottomPanel.add(applylbl);
        bottomPanel.add(applyTxt);
        applyTxt.setEditable(false);
        bottomPanel.add(applyBtn);
 
        if (!this.isIntegrate) {
            bottomPanel.add(batchApplyBtn);
        } else {
            bottomPanel.add(btnSearch);
        }
        bottomPanel.add(clearBtn);
        return bottomPanel;
    }
 
    /***
     * 初始化代码项目
     * @return
     */
    private JPanel initCodeItemPal()  {
        VCIJPanel codeItemPal = new VCIJPanel(new FlowLayout(FlowLayout.LEFT));
        codeItemCombo.setPreferredSize(new Dimension(200,25));
        initCodeItemCombo();//初始化代码项下拉框数据
        codeItemPal.add(codeItemLabel);
        codeItemPal.add(codeItemCombo);
        return codeItemPal;
    }
    /**
     * 代码项事件:选择代码项后,自动刷新代码项下对应的规则码段和模板属性信息
     * <p>Description: </p>
     *
     * @author Administrator
     * @time 2013-3-23
     */
    public void initCodeItemCombo()  {
        CodeClassifyVO [] codeClassifyVOS = new CodeClassifyVO[0];
        Map<String,String> condtionMap=new HashMap<>();
        //condtionMap.put("parentOid",);
        //String url=ConfigUtils.getConfigValue("410.code.url","http://127.0.0.1:36014/codeApplySwingController");
        /**系统只加载代码项  如果libName不为空,直接获取对应的代码项**/
        if(libName.length>0) {
            condtionMap.put("libName", StringUtils.join(libName,",") );
        }
        R r=HttpUtil.sendGet(url+"/getRMLibByName",condtionMap,new HashMap<>());
        List<CodeClassify> codeClassifyList = new ArrayList<>();
        if(r.isSuccess()){
            Object object= r.getData();
            if(object!=null) {
                ObjectMapper objectMapper = new ObjectMapper();
                try {
                    codeClassifyList = objectMapper.readValue(object.toString(), new com.fasterxml.jackson.core.type.TypeReference<List<CodeClassify>>() {
                    });
                } catch (JsonProcessingException e) {
                    e.printStackTrace();
                }
            }
        }else{
            VCIOptionPane.showMessage(this,r.getMsg());
        }
        if(!CollectionUtils.isEmpty(codeClassifyList)){
            codeClassifyList.stream().forEach(codeClassify -> {
                codeItemCombo.addItem(codeClassify);
            });
            codeItemCombo.setSelectedIndex(0);
        }
        initLeftPanel();
    }
 
    /***
     * 初始化按钮事件
     */
    private void initActionListener() {
        /**代码项下拉事件**/
        codeItemCombo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(codeItemCombo.getSelectedIndex() == -1) {
                    return;
                }
                try {
                    ruleComboActionListener();
                } catch (Exception ex) {
                    VCIOptionPane.showMessage(owner,ex.getMessage());
                }
            }
        });
 
    }
 
    /**
     * 处理代码项下拉事件
     * <p>Description: </p>
     *
     * @author Administrator
     * @time 2013-3-23
     */
    private void ruleComboActionListener()   {
        leftTree.removeAll();
        initLeftPanel();
    }
    private void initLeftPanel()  {
        CodeClassify currentCodeClassify= (CodeClassify) this.codeItemCombo.getSelectedItem();
        if(currentCodeClassify == null) {
            return;
        }
        String  libName=currentCodeClassify.getName();
        String classOid=currentCodeClassify.getOid();
        final CodeApplyPanelFor410 self = this;
        typeTreePanel = new CodeApplyFor410TreePanel(currentCodeClassify,userObj,clsfName, libName) {
            private static final long serialVersionUID = 8121108576137012228L;
            @Override
            public void tree_valueChanged(TreeSelectionEvent e) {
                self.leftTree_valueChanged(e);
            }
        };
        typeTreePanel.buildTreePanel();
        leftTree = typeTreePanel.getTree();
        leftTreeModel = typeTreePanel.getTreeModel();
        transmitTreeObject.setCurrentTreeNode(typeTreePanel.getSelNode());
        transmitTreeObject.setTree(leftTree);
        transmitTreeObject.setTreeModel(leftTreeModel);
        VCIJPanel rightPanel = new VCIJPanel();
        rightPanel.setLayout(new BorderLayout());
 
        jspLeftToRight.setRightComponent(rightPanel);
        rightPanel.add(scrollPane, BorderLayout.CENTER);
 
        Object obj =transmitTreeObject.getCurrentTreeNode();
        if(obj instanceof VCIBaseTreeNode){
            VCIBaseTreeNode vciBaseTreeNode=    (VCIBaseTreeNode)obj;
            Object node=vciBaseTreeNode.getObj();
            if(node instanceof CodeClassify) {
                CodeClassify codeClassify=(CodeClassify)node;
                classOid = codeClassify.getOid();
 
                //String url = ConfigUtils.getConfigValue("410.PDM.clsfTemplate.url", "http://127.0.0.1:36014/codeApplySwingController/getUsedTemplateByClassifyOid");
                /**系统只加载代码项  如果libName不为空,直接获取对应的代码项**/
                Map<String, String> condtionMap = new HashMap<>();
                condtionMap.put("codeClassifyOid", classOid);
                R r = HttpUtil.sendGet(url+"/getUsedTemplateByClassifyOid", condtionMap, new HashMap<>());
                boolean res = false;
                if (r.isSuccess()) {
                    //List<CodeClassifyTemplateVO> codeClassifyTemplateVOList=new ArrayList<>();
                    CodeClassifyTemplateVO codeClassifyTemplateVO = new CodeClassifyTemplateVO();
                    Object object = r.getData();
                    if (object != null) {
                        ObjectMapper objectMapper = new ObjectMapper();
                        try {
                            codeClassifyTemplateVO = objectMapper.readValue(object.toString(), CodeClassifyTemplateVO.class);
                            if (codeClassifyTemplateVO != null) {
                                setCurrentCodeClassifyTemplateVO(codeClassifyTemplateVO);
                                res = true;
                            }
                        } catch (JsonProcessingException e) {
                            e.printStackTrace();
                        }
                    }
                }/*else{
                    VCIOptionPane.showMessage(this,r.getMsg());
                }*/
                initBtnStatus(res);
            }
        }
        rightMainPanel = new CodeApplyFor410MainPanel(transmitTreeObject,userObj,deptName,getCurrentCodeClassifyTemplateVO());
        scrollPane.setViewportView(rightMainPanel);
        rightMainPanel.buildMainPanel(1);
        int location = jspLeftToRight.getDividerLocation();
        jspLeftToRight.setDividerLocation(location);
        scrollLeftTreePane.setViewportView(leftTree);
        leftTree.scrollPathToVisible(leftTree.getSelectionPath());
    }
 
    private void leftTree_valueChanged(TreeSelectionEvent e) {
        TreePath selectedTreePath = e.getPath();
        /**校验 判断选择的代码项是否包含模板 Begin**/
        VCIBaseTreeNode selectedTreeNode = (VCIBaseTreeNode)selectedTreePath.getLastPathComponent();
        Object obj = selectedTreeNode.getObj();
        boolean res=false;
        if(obj instanceof CodeClassify) {
            CodeClassify curentCodeClassify=(CodeClassify)obj;
            //String url=ConfigUtils.getConfigValue("410.PDM.clsfTemplate.url","http://127.0.0.1:36014/codeApplySwingController/getUsedTemplateByClassifyOid");
            /**系统只加载代码项  如果libName不为空,直接获取对应的代码项**/
            Map<String,String> condtionMap=new HashMap<>();
            condtionMap.put("codeClassifyOid",curentCodeClassify.getOid());
            R r=HttpUtil.sendGet(url+"/getUsedTemplateByClassifyOid",condtionMap,new HashMap<>() );
            if(r.isSuccess()) {
                CodeClassifyTemplateVO codeClassifyTemplateVO=new CodeClassifyTemplateVO();
                Object object= r.getData();
                if(object!=null) {
                    ObjectMapper objectMapper = new ObjectMapper();
                    try {
                        codeClassifyTemplateVO = objectMapper.readValue(object.toString(), CodeClassifyTemplateVO.class);
                        if(codeClassifyTemplateVO!=null){
                            setCurrentCodeClassifyTemplateVO(codeClassifyTemplateVO);
                            res=true;
                        }
                    } catch (JsonProcessingException e1) {
                        e1.printStackTrace();
                    }
                }
            }/*else{
                VCIOptionPane.showMessage(this.owner,r.getMsg());
            }*/
 
        }
        initBtnStatus(res);
        /*******************End**********************/
        initRightDataTablePanel(selectedTreeNode);
    }
 
    private void initBtnStatus(boolean enable) {
        applyBtn.setEnabled(enable);
        batchApplyBtn.setEnabled(enable);
        btnSearch.setEnabled(enable);
        clearBtn.setEnabled(enable);
    }
    private void initRightDataTablePanel(VCIBaseTreeNode selectedTreeNode) {
        leftTree = typeTreePanel.getTree();
        leftTreeModel = typeTreePanel.getTreeModel();
 
        transmitTreeObject.setTree(leftTree);
        transmitTreeObject.setTreeModel(leftTreeModel);
        transmitTreeObject.setCurrentTreeNode(selectedTreeNode);
        if(selectedTreeNode.isRoot() && selectedTreeNode.getObj() instanceof String) return;
        scrollPane = new JScrollPane();
        rightMainPanel = new CodeApplyFor410MainPanel(transmitTreeObject,userObj,deptName,getCurrentCodeClassifyTemplateVO());
        scrollPane.setViewportView(rightMainPanel);
        rightMainPanel.buildMainPanel(1);
        VCIJPanel rightPanel = new VCIJPanel();
        rightPanel.setLayout(new BorderLayout());
        rightPanel.add(scrollPane, BorderLayout.CENTER);
 
        applyTxt.setText("");
 
        jspLeftToRight.setRightComponent(rightPanel);
        int location = jspLeftToRight.getDividerLocation();
        jspLeftToRight.setDividerLocation(location);
    }
    private Map<String, String> attrNameAndValMap = new LinkedHashMap();
    private JScrollPane scrollPane = new JScrollPane();
 
    public Map<String, String> getAttrNameAndValMap() {
        return attrNameAndValMap;
    }
 
    public void setAttrNameAndValMap(Map<String, String> attrNameAndValMap) {
        this.attrNameAndValMap = attrNameAndValMap;
    }
 
    public String getApplyCode() {
        return this.applyTxt.getText().trim();
    }
    public void setApplyCode(String codeVal) {
        this.applyTxt.setText(codeVal);
    }
 
    public CodeClassifyTemplateVO getCurrentCodeClassifyTemplateVO() {
        return currentCodeClassifyTemplateVO;
    }
 
    public void setCurrentCodeClassifyTemplateVO(CodeClassifyTemplateVO currentCodeClassifyTemplateVO) {
        this.currentCodeClassifyTemplateVO = currentCodeClassifyTemplateVO;
    }
}