ludc
2023-09-19 8381325223bee254168855b1b697db31fc591b9e
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
package com.vci.rmip.code.client.codeapply.Apply410;
 
import com.alibaba.fastjson.JSONObject;
import com.vci.base.ui.swing.VCIOptionPane;
import com.vci.base.ui.swing.components.VCIJComboBox;
import com.vci.rmip.code.client.codeapply.Apply410.object.CodeClassify;
import com.vci.rmip.code.client.codeapply.Apply410.object.CodeClassifyTemplateVO;
import com.vci.rmip.code.client.codeapply.Apply410.object.R;
import com.vci.rmip.code.client.codeapply.Apply410.object.ubcscode.dto.CodeOrderDTO;
import com.vci.rmip.code.client.codeapply.Apply410.object.ubcscode.dto.CodeOrderSecDTO;
import com.vci.rmip.code.client.codeapply.Apply410.object.ubcscode.vo.CodeRuleVO;
import com.vci.rmip.code.client.codeapply.Apply410.object.ubcscode.vo.KeyValue;
import com.vci.rmip.code.client.codeapply.Apply410.utils.ConfigUtils;
import com.vci.rmip.code.client.codeapply.Apply410.utils.HttpUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
 
import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.event.ActionEvent;
import java.util.*;
 
public class CodeApplyPanelFor410ActionListener extends CommonActionListener {
    private CodeApplyPanelFor410 owner = null;
    private LinkedHashMap<String, Runnable> actionMaps = new LinkedHashMap<String, Runnable>();
    boolean codeAlreadExist = false;
    private String url= ConfigUtils.getConfigValue("410.code.url","http://127.0.0.1:36014/codeApplySwingController");
    private String classifyGroupCode= ConfigUtils.getConfigValue("410.code.codeApply.classifyGroupCode");
    public CodeApplyPanelFor410ActionListener(CodeApplyPanelFor410 owner){
        this.owner = owner;
        this.initActionMap();
    }
    @Override
    public void initActionMap(){
        actionMaps.put("batchApply", new Runnable() { public void run() {
            //batchApply();//批量导入申请代码
        }});
        actionMaps.put("apply", new Runnable() { public void run() {
            apply();//码值申请
        }});
        actionMaps.put("btnSearch", new Runnable() { public void run() {
            search();//代码查询
        }});
        actionMaps.put("clear", new Runnable() { public void run() {
            clear();//清空属性
        }});
 
 
    }
 
    @Override
    public void actionPerformed(ActionEvent e) {
        String key = e.getActionCommand();
        if(actionMaps.containsKey(key)){
            actionMaps.get(key).run();
        }
    }
    private void apply() {
        codeAlreadExist = false;
        if(null == this.owner.getTransmitTreeObject().getCurrentTreeNode()) {
            return;
        }
        CodeClassify codeClassify = (CodeClassify) this.owner.getTransmitTreeObject().getCurrentTreeNode().getObj();
        if(codeClassify == null || "".equals(codeClassify.getOid())){
            VCIOptionPane.showMessage(this.owner, "请选择编码项分类!");
            return;
        }
        CodeClassifyTemplateVO codeClassifyTemplateVO = this.owner.getCurrentCodeClassifyTemplateVO();
        if(codeClassifyTemplateVO!=null&&"".equals(codeClassifyTemplateVO.getOid())) {
            VCIOptionPane.showMessageDialog(this.owner, "代码项没有配置模板,不允许申请!");
            return;
        }
        CodeRuleVO codeRuleVO= this.owner.getRightMainPanel().getCodeRuleVO();
        /**选择的分类是否包含规则的校验**/
        if(codeRuleVO==null||"".equals(codeRuleVO.getOid())) {
            VCIOptionPane.showMessage(this.owner, "分类:" + codeClassify.getName() + " 没有包含规则,无法申请!");
            return;
        }
        //校验规则是否填写合格
        if(!this.owner.getRightMainPanel().checkIsAllowed()) {
            return;
        }
 
        //  检查模板各属性的输入值是否满足要求
        String[][] inputValues = this.owner.getRightMainPanel().checkInputValues();
        //获取属性名称和值的集合
        Map<String, String> attrNameAndValMap = getAttrMap(inputValues);
        String[] fields = inputValues[0];
        String[] values = inputValues[1];
        String[] dataTypes = inputValues[2];
        String[] outNames = inputValues[3];
        Map<String,String> dataMap=new HashMap<>();
        for (int i=0;i<fields.length;i++){
            dataMap.put(fields[i],values[i]);
        }
        List<KeyValue> keyValueList= this.owner.getRightMainPanel().getSectionValues();
        if(CollectionUtils.isEmpty(keyValueList)){
            VCIOptionPane.showMessage(this.owner, "分类:" + codeClassify.getName() + " 没有获取规则码段选择值信息,无法申请!");
            return;
        }
        CodeOrderDTO codeOrderDTO=new CodeOrderDTO();
        /**系统只加载代码项  如果libName不为空,直接获取对应的代码项**/
        codeOrderDTO.setCodeClassifyOid(codeClassify.getOid());
        codeOrderDTO.setTemplateOid(codeClassifyTemplateVO.getOid());
        codeOrderDTO.setCodeRuleOid(codeRuleVO.getOid());
        List<CodeOrderSecDTO> secDTOList=new ArrayList<>();
        for (KeyValue keyValue : keyValueList) {
            CodeOrderSecDTO codeOrderSecDTO=new CodeOrderSecDTO();
            codeOrderSecDTO.setSecOid(keyValue.getKey());
            codeOrderSecDTO.setSecValue(keyValue.getValue());
            secDTOList.add(codeOrderSecDTO);
        }
        codeOrderDTO.setLcStatus("Released");
        codeOrderDTO.setSecDTOList(secDTOList);
        codeOrderDTO.setData(dataMap);
        Object object = JSONObject.toJSON(codeOrderDTO);
        Map<String,String> headerMap=new HashMap<>();
        headerMap.put("content-type","application/json");
        headerMap.put("Blade-Auth",this.owner.getTokenUserObject().getAccess_token());
        String code="";        
        //校验关键属性存在的数据直接返回编码
        R checkKeyAttrOnOrderR= HttpUtil.sendPost(url+"/checkKeyAttrOnOrderFordatas",object.toString(),headerMap);
        
 
        Map<String,String>parmarMap=new HashMap<String, String>();
        parmarMap.put("oid", codeClassify.getOid());
        parmarMap.put("classifyGroupCode",classifyGroupCode);
        //查询当前申请编码的类型
        /*R checkGroupCode= HttpUtil.sendGet(url+"/checkGroupCode?oid="+codeClassify.getOid()+
            "&classifyGroupCode="+classifyGroupCode,null,headerMap);*/
        R checkGroupCode= HttpUtil.sendGet(url+"/checkGroupCode",parmarMap,headerMap);
        if(checkKeyAttrOnOrderR.isSuccess()){
            List<Map> list=(List)checkKeyAttrOnOrderR.getData();
            if(!CollectionUtils.isEmpty(list)) {
                code=list.get(0).get("ID")!=null?list.get(0).get("ID").toString():"";
                if(checkGroupCode.isSuccess()){
                    if(checkGroupCode.getData().equals("true")){
                        code="";
                         code=list.get(0).get("GROUPCODE")!=null?list.get(0).get("GROUPCODE").toString():"";
                         if(StringUtils.isBlank(code)){
                             VCIOptionPane.showMessage(this.owner, "根据关键属性校验,系统中存在该数据,需等待集团申请集团码:"+code);
                         }else{
                             code=list.get(0).get("ID")!=null?list.get(0).get("ID").toString():"";
                         }
                    }
                }else {
                    code="";
                    VCIOptionPane.showMessage(this.owner,"校验该分类是否取集团码失败!");
                }
                this.owner.setApplyCode(code);
                this.owner.getApplyTxt().requestFocusInWindow();
                this.owner.getApplyTxt().selectAll();
                this.owner.setAttrNameAndValMap(attrNameAndValMap);
                return;
            }
        }
        R r= HttpUtil.sendPost(url+"/addSaveCode",object.toString(),headerMap);
        if(r.isSuccess()){
            code=r.getData().toString();
            if(checkGroupCode.isSuccess()){
                if(checkGroupCode.getData().equals("true")){
                    code="";
                    Map<String,String> applyMap = new HashMap<>();
                    applyMap.put("oids",codeClassify.getOid());
                    applyMap.put("btmName",codeClassify.getBtmname());
                    Object applyGroupCodeData = JSONObject.toJSON(applyMap);
                    R applyResult= HttpUtil.sendPost(url+"/DockingPreApplyCode/applyGroupCode",applyGroupCodeData.toString(),headerMap);
                    if(!applyResult.isSuccess()){
                        VCIOptionPane.showMessage(this.owner, "集团码申请失败,"+r.getMsg());
                    }else{
                        VCIOptionPane.showMessage(this.owner, "保存数据成功,等待集团码申请!");
                    }
                }
            }else{
                code="";
                VCIOptionPane.showMessage(this.owner,"校验该分类是否取集团码失败!");
            }
            this.owner.setApplyCode(code);
            this.owner.getApplyTxt().requestFocusInWindow();
            this.owner.getApplyTxt().selectAll();
            this.owner.setAttrNameAndValMap(attrNameAndValMap);
        }else{
            VCIOptionPane.showMessage(this.owner,r.getMsg());
        }
        
 
    }
    private Map<String, String>  getAttrMap(String[][] inputValues) {
        Map<String, String> attrNameAndValMap = new LinkedHashMap<String, String>();
        String[] fields = inputValues[0];
        String[] values = inputValues[1];
        String[] outNames = inputValues[3];
        for(int k = 0;k < fields.length;k++) {
            attrNameAndValMap.put(fields[k], values[k]);//属性内部名称
            attrNameAndValMap.put(outNames[k], values[k]);//属性外部名称
        }
 
        return attrNameAndValMap;
    }
    /***
     * 清空属性
     */
    private void clear(){
        CodeApplyFor410MainPanel rightMainPanel2 = this.owner.getRightMainPanel();
        LinkedHashMap<String, JComponent> attrInnerNameToCtrlMaps = rightMainPanel2.getAttrInnerNameToCtrlMaps();
        if(attrInnerNameToCtrlMaps!=null&&attrInnerNameToCtrlMaps.size()>0){
            for(String key : attrInnerNameToCtrlMaps.keySet()){
                JComponent component = attrInnerNameToCtrlMaps.get(key);
                if(component instanceof JTextComponent){
                    if(((JTextComponent) component).isEnabled())
                        ((JTextComponent) component).setText("");
                }else if(component instanceof VCIJComboBox){
                    if(((VCIJComboBox) component).isEnabled())
                        ((VCIJComboBox) component).setSelectedIndex(0);
                }
            }
        }
        String applyCode = this.owner.getApplyCode();
        if(StringUtils.isBlank(applyCode)) {
            this.owner.setApplyCode("");
        }
    }
 
    /**
     *
     * 查询代码
     */
    private void search(){
        if(null == this.owner.getRightMainPanel().getTransTreeObject().getCurrentTreeNode()) {
            return;
        }
        CodeClassify rmType = (CodeClassify) this.owner.getRightMainPanel().getTransTreeObject().getCurrentTreeNode().getObj();
        if(rmType == null || "".equals(rmType.getId())){
            VCIOptionPane.showMessage(this.owner, "请选择代码项分类!");
            return;
        }
 
        CodeApplyFor410SearchDialog dialog = new CodeApplyFor410SearchDialog(this.owner);
        String str = dialog.getStr();
        if (!str.equals("")) {
            owner.applyTxt.setText(str);
        }
 
    }
 
 
}