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
package com.vci.client.framework.systemConfig.secretGrade;
 
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
 
import com.vci.client.LogonApplication;
import com.vci.client.bof.ClientBusinessObjectOperation;
import com.vci.client.common.VCIBasePanel;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.client.framework.appConfig.object.AppConfigCategoryObject;
import com.vci.client.framework.appConfig.object.AppConfigDetailObject;
import com.vci.client.framework.delegate.AppConfigCategoryClientDelegate;
import com.vci.client.framework.delegate.AppConfigDetailClientDelegate;
import com.vci.client.framework.rightConfig.object.FunctionObject;
import com.vci.client.framework.specialrole.ModuleInterface.IModuleShow;
import com.vci.client.ui.exception.VCIException;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.etm.EnumChild;
import com.vci.corba.omd.etm.EnumItem;
 
public class OpenOrCloseConfigForUserAndPcPanel extends VCIBasePanel implements IModuleShow {
 
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    private String logonUserId = "",logonRoleId;
    private String moduleName = "";
    private String iconName,moduleShowInfo;
    
    JCheckBox userSecuritySwith = new JCheckBox();
    JCheckBox ipSecuritySwitch = new JCheckBox();
 
    public OpenOrCloseConfigForUserAndPcPanel(FunctionObject funcObj) {
        super(funcObj);
        // TODO Auto-generated constructor stub
        init();
    }
    
    private void init() {
        this.setLayout(new BorderLayout());
        this.setBorder(new TitledBorder("用户\\机器密级停启用配置"));
        
        JPanel mainPanel = new JPanel();
        JPanel contentPanel = initContentPanel();
        JPanel buttonPanel = initButtonPanel();
        mainPanel.setLayout(new BorderLayout());
        
        mainPanel.add(contentPanel, BorderLayout.CENTER);
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);
 
        this.add(mainPanel, BorderLayout.CENTER);
    }
    
    private JPanel initContentPanel() {
        JPanel contentPanel = new JPanel();
        
        AppConfigDetailClientDelegate delegate = new AppConfigDetailClientDelegate(LogonApplication.getUserEntityObject());
        try {
            AppConfigDetailObject userConfigDetail = delegate.getAppConfigDetailByKey("userSecuritySwith");
            AppConfigDetailObject ipConfigDetail = delegate.getAppConfigDetailByKey("ipSecuritySwitch");
            if ("on".equals(userConfigDetail.getValue())) {
                userSecuritySwith.setSelected(true);
            }
            if ("on".equals(ipConfigDetail.getValue())) {
                ipSecuritySwitch.setSelected(true);
            }
        } catch (VCIException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        userSecuritySwith.setLabel("用户密级");
        ipSecuritySwitch.setLabel("机器密级");
        contentPanel.add(userSecuritySwith);
        contentPanel.add(ipSecuritySwitch);
        
        return contentPanel;
    }
 
    private JPanel initButtonPanel() {
        JPanel buttonPanel = new JPanel();
        JButton saveBtn = new JButton("保存");
        buttonPanel.add(saveBtn);
        
        saveBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveSecretGrade();
            }
        });
        
        return buttonPanel;
    }
    
    private void saveSecretGrade() {
        boolean userSwich = userSecuritySwith.isSelected();
        boolean ipSwich = ipSecuritySwitch.isSelected();
        AppConfigDetailClientDelegate delegate = new AppConfigDetailClientDelegate(LogonApplication.getUserEntityObject());
        AppConfigCategoryClientDelegate category = new AppConfigCategoryClientDelegate(LogonApplication.getUserEntityObject());
        try {
            AppConfigCategoryObject[] categories = category.getAppConfigCategorys();
            String secretGradeCategoryId = "";
            for (int i = 0; i < categories.length; i++) {
                if ("系统密级配置".equals(categories[i].getName())) {
                    secretGradeCategoryId = categories[i].getId();
                    break;
                }
            }
            
            if ("".equals(secretGradeCategoryId)) {
                AppConfigCategoryObject categoryObj = new AppConfigCategoryObject();
                categoryObj.setName("系统密级配置");
                categoryObj.setDesc("系统密级配置");
                secretGradeCategoryId = category.saveAppConfigCategory(categoryObj);
            }
            
            AppConfigDetailObject userConfigDetail = delegate.getAppConfigDetailByKey("userSecuritySwith");
            AppConfigDetailObject ipConfigDetail = delegate.getAppConfigDetailByKey("ipSecuritySwitch");
            
            if (ipSwich) {
                if (ipConfigDetail.getId() != null && !"".equals(ipConfigDetail.getId())) {
                    ipConfigDetail.setValue("on");
                    boolean res = delegate.updateAppConfigDetail(ipConfigDetail);
                    System.out.println("ip配置修改结果-------" + res);
                } else {
                    ipConfigDetail = new AppConfigDetailObject();
                    ipConfigDetail.setKey("ipSecuritySwitch");
                    ipConfigDetail.setValue("on");
                    ipConfigDetail.setName("机器密级停启");
                    ipConfigDetail.setDesc("value值为on时代表机器密级开启,值为其他或者不配置时代表不开启。");
                    ipConfigDetail.setCategoryId(secretGradeCategoryId);
                    String res = delegate.saveAppConfigDetail(ipConfigDetail);
                    System.out.println("ip配置保存结果-------" + res);
                }
            } else {
                if (ipConfigDetail.getId() != null && !"".equals(ipConfigDetail.getId())) {
                    ipConfigDetail.setValue("off");
                    delegate.updateAppConfigDetail(ipConfigDetail);
                }
            }
            
            if (userSwich) {
                if (userConfigDetail.getId() != null && !"".equals(userConfigDetail.getId())) {
                    userConfigDetail.setValue("on");
                    boolean res = delegate.updateAppConfigDetail(userConfigDetail);
                    System.out.println("user配置修改结果-------" + res);
                } else {
                    userConfigDetail = new AppConfigDetailObject();
                    userConfigDetail.setKey("userSecuritySwith");
                    userConfigDetail.setValue("on");
                    userConfigDetail.setName("用户密级停启");
                    userConfigDetail.setCategoryId(secretGradeCategoryId);
                    userConfigDetail.setDesc("value值为on时代表用户密级开启,值为其他或者不配置时代表不开启。");
                    String res = delegate.saveAppConfigDetail(userConfigDetail);
                    System.out.println("user配置保存结果-------" + res);
                }
                updateUserSecretGrade();
            } else {
                if (userConfigDetail.getId() != null && !"".equals(userConfigDetail.getId())) {
                    userConfigDetail.setValue("off");
                    boolean res = delegate.updateAppConfigDetail(userConfigDetail);
                    System.out.println("user配置修改结果-------" + res);
                }
            }
            JOptionPane.showMessageDialog(this, "保存配置成功", "保存成功", JOptionPane.INFORMATION_MESSAGE);
        } catch (VCIException e) {
            JOptionPane.showMessageDialog(this, "保存配置失败", "保存失败", JOptionPane.INFORMATION_MESSAGE);
            e.printStackTrace();
        } catch (VCIError e) {
            JOptionPane.showMessageDialog(this, "保存配置失败", "保存失败", JOptionPane.INFORMATION_MESSAGE);
            e.printStackTrace();
        }
        
    }
    
    private void updateUserSecretGrade() throws VCIError {
        EnumItem enumItem = ServiceProvider.getOMDService().getEnumService().getEmItemByName("usersecurityenum");
        EnumChild[] children = enumItem.children;
        int grade = 10;
        if (children.length > 0) {
            grade = Integer.parseInt(children[0].value);
            for (int i = 0; i < children.length; i++) {
                EnumChild child = children[i];
                if (grade >= Integer.parseInt(child.value)) {
                    grade = Integer.parseInt(child.value);
                }
            }
        }
        String updateSql = "update pluser set plsecretgrade = '" + grade + "' " +
                "where plsecretgrade is null";
        ClientBusinessObjectOperation cboo = new ClientBusinessObjectOperation();
        cboo.executeUpdateSql(updateSql);
    }
    
    @Override
    public String getUserID() {
        return logonUserId;
    }
 
    @Override
    public String getRoleID() {
        return logonRoleId;
    }
 
    @Override
    public JPanel getModuleComponent() {
        return this;
    }
 
    @Override
    public String getModuleName() {
        return moduleName;
    }
 
    @Override
    public String getIconName() {
        return iconName;
    }
 
    @Override
    public String getModuleShowInfo() {
        return moduleShowInfo;
    }
 
}