田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
package com.vci.client.framework.systemConfig.stafforgmanage;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
 
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
 
import org.apache.poi.ss.formula.functions.T;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.VCIBasePanel;
import com.vci.client.common.objects.RoleObject;
import com.vci.client.common.objects.UserEntityObject;
import com.vci.client.common.objects.UserObject;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.framework.rightConfig.object.FunctionObject;
import com.vci.client.framework.specialrole.ModuleInterface.IModuleShow;
import com.vci.client.framework.util.RightControlUtil;
import com.vci.client.logon.client.LogonFrame;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJPanel;
import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider;
import com.vci.client.ui.swing.components.table.VCIJTableNode;
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
import com.vci.client.ui.util.UIHelper;
import com.vci.mw.ClientContextVariable;
/**
 * <p>Title:RoleTablePanel </p>
 * <p>Description: 角色管理界面</p>
 * <p>Copyright: Copyright (c) 2012</p>
 * <p>Company: VCI</p>
 * @author wangxl
 * @time 2012-5-11
 * @version 1.0
 */
public class RoleTablePanel extends VCIBasePanel implements IModuleShow{
 
    private static final long serialVersionUID = 1L;
    
    private VCIJButton addButton = VCISwingUtil.createVCIJButton("",LocaleDisplay.getI18nString("rmip.stafforg.operate.add", "RMIPFramework", getLocale()) ,LocaleDisplay.getI18nString("rmip.stafforg.operate.add", "RMIPFramework", getLocale()) , "create.gif",null);
    private VCIJButton editButton = VCISwingUtil.createVCIJButton("",LocaleDisplay.getI18nString("rmip.stafforg.operate.modify", "RMIPFramework", getLocale()) ,LocaleDisplay.getI18nString("rmip.stafforg.operate.modify", "RMIPFramework", getLocale()) , "modify.gif",null);
    private VCIJButton deleteButton = VCISwingUtil.createVCIJButton("",LocaleDisplay.getI18nString("rmip.stafforg.operate.delete", "RMIPFramework", getLocale()) ,LocaleDisplay.getI18nString("rmip.stafforg.operate.delete", "RMIPFramework", getLocale()), "delete.gif" ,null);
    private VCIJButton btnDisplay = VCISwingUtil.createVCIJButton("", "统计","统计","group.gif",null);
    private VCIJButton rightButton = VCISwingUtil.createVCIJButton("", "分配成员","分配成员", "user.gif" ,null);
    private VCIJButton btnImport = VCISwingUtil.createVCIJButton("", "导入角色","导入角色", "usertask.gif" ,null);
    private RightManagementClientDelegate rightDel = new RightManagementClientDelegate(LogonApplication.getUserEntityObject());
    private String userName = LogonApplication.getUserEntityObject().getUserName();
    
    private String logonUserId = "",logonRoleId;
    private String moduleName = "";
    private String iconName,moduleShowInfo ;
    
//    private SpecialRoleObject specialRoleObject = new SpecialRoleObject();
//    public SpecialRoleObject getSpecialRoleObject() {
//        return specialRoleObject;
//    }
//
//    public void setSpecialRoleObject(SpecialRoleObject specialRoleObject) {
//        this.specialRoleObject = specialRoleObject;
//    }
    public String getLogonUserId() {
        return logonUserId;
    }
    public void setLogonUserId(String logonUserId) {
        this.logonUserId = logonUserId;
    }
    public String getLogonRoleId() {
        return logonRoleId;
    }
    public void setLogonRoleId(String logonRoleId) {
        this.logonRoleId = logonRoleId;
    }
    public void setModuleName(String moduleName) {
        this.moduleName = moduleName;
    }
    public void setIconName(String iconName) {
        this.iconName = iconName;
    }
    public void setModuleShowInfo(String moduleShowInfo) {
        this.moduleShowInfo = moduleShowInfo;
    }
    private LinkedList<VCIJButton> selfCustomButtons = new LinkedList<VCIJButton>();
    {
        selfCustomButtons.add(addButton);
        selfCustomButtons.add(editButton);
        selfCustomButtons.add(deleteButton);
        
        UserObject user = LogonApplication.getUserObject();
        if (RightControlUtil.isAdminOrDeveloperOrRoot(user.getUserName()) || RightControlUtil.isThreeAdmin(RightControlUtil.ThreeAdminEnum.SECADMIN))
            selfCustomButtons.add(rightButton);
        
        selfCustomButtons.add(btnDisplay);
        selfCustomButtons.add(btnImport);
    }
    
    
    public RoleTablePanel(FunctionObject funcObj){
        super(funcObj);
        init();
//        checkPermission();
    }
    private void init() {
        //LogonApplication.getUserEntityObject().setModules(this.getClass().getName());
        LogonApplication.getUserEntityObject().setModules(this.getModuleName());//"角色管理");
        initComponents();
        initAction();//初始化按钮点击事件
    }
    private void initComponents() {
        setLayout(new BorderLayout());
        add(initTablePanel(), BorderLayout.CENTER);
    }
    
    private void checkPermission(){
        checkRight(RightControlUtil.CREATE, addButton);
        checkRight(RightControlUtil.UPDATE, editButton);
        checkRight(RightControlUtil.DELETE, deleteButton);
        checkRight(RightControlUtil.FREEZE, rightButton);
        checkRight(RightControlUtil.DISCARD, btnDisplay);
    }
    
    class MyDataProvider extends AbstractVCIJTableDataProvider<RoleObject>{
 
        @Override
        public RoleObject[] getDatas(int pageNo, int pageSize) {
            RoleObject[] roleObjs = null;
            try {
                roleObjs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
                    .fetchRoleInfoByUserName(pageNo,pageSize,userName);
            } catch (VCIException e) {
                VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
                return null;
            }
            return roleObjs;
        }
 
        @Override
        public VCIJTableNode<RoleObject> getNewRowNode(RoleObject dataObj) {
            VCIJTableNode<RoleObject> node = new VCIJTableNode<RoleObject>(dataObj);
            node.setPropertyValue(getSpecialColumns()[0], dataObj.getName());
            node.setPropertyValue(getSpecialColumns()[1], dataObj.getDescription());
            return node;
        }
 
        @Override
        public String[] getSpecialColumns() {
            return "名称, 描述".split(",");
        }
 
        @Override
        public int getTotal() {
            try {
                total = new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
                .getRoleTotalByUserName(userName);
            } catch (VCIException e) {
                e.printStackTrace();
                VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
            }
            return this.total;
        }
        
    }
    
    MyDataProvider dataProvider = new MyDataProvider();
    VCIJTablePanel<RoleObject> tablePanel = new VCIJTablePanel<RoleObject>(dataProvider);
    private VCIJPanel tablePanel(){
        int startIndex = dataProvider.getDataColumnStartIndex();
        LinkedHashMap<Integer, Integer> widthMaps = new LinkedHashMap<Integer, Integer>();
        widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250);
        tablePanel.setColumnWidthMaps(widthMaps);
        tablePanel.setCustomButtonFlowAlign(FlowLayout.CENTER);
        tablePanel.setCustomButtons(selfCustomButtons);
        tablePanel.setShowPaging(true);
        tablePanel.setPageButtonFlowAlign(FlowLayout.CENTER);
        //add by caill 2016.1.20
        tablePanel.setShowExport(true);
        tablePanel.buildTablePanel();
        tablePanel.refreshTableData();
        return tablePanel;
    }
 
    
    private JPanel initTablePanel(){
        
        JPanel pal = new JPanel();
        pal.setLayout(new BorderLayout());
        pal.setBorder(new TitledBorder("角色管理"));
        pal.add(tablePanel(), BorderLayout.CENTER);
        pal.setVisible(true);
        return pal;
    }
    
    /**
     * 事件
     */
    private void initAction(){
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                addButton_conform();
            }
        });
        
         editButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    editButton_conform();
                }
         });
         
         deleteButton.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 deleteButton_conform();
             }
         });
         
         rightButton.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent arg0) {
                 rightButton_conform();
             }
         });
         
         btnDisplay.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    btnDisplay_conform();
                }
         });
        //add by caill start 2016.1.20为角色管理添加导入功能
         btnImport.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {
                ImportData();
                tablePanel.refreshTableData();    //刷新界面
         }});
            //add by caill end    
    }
    //add by caill start 2016.1.20 创建角色导入的界面
        private void ImportData(){
            RolesImportDialog eid = new RolesImportDialog(this);
            eid.init();
            eid.setSize(UIHelper.DIALOG_DEFAULT_WIDTH, UIHelper.DIALOG_DEFAULT_HEIGHT);
            eid.setLocationRelativeTo(ClientContextVariable.getFrame());
            eid.setVisible(true);
        }
        //add by caill end
    /**
     * 添加事件
     */
    private void addButton_conform(){
        new RoleDialog(this,"addRole");
    }
    
    /**
     * 修改事件
     */
    private void editButton_conform(){
        
        int len = tablePanel.getSelectedRowIndexs().length;
        if(len == 0){
            VCIOptionPane.showMessage(this, 
                    "请选择角色再进行修改操作!");
            return;
        }
        if (len > 1){
            VCIOptionPane.showMessage(this, 
                    LocaleDisplay.getI18nString("rmip.stafforg.operate.deptedit2", "RMIPFramework", getLocale()));
            return;
        }
        RoleObject obj = tablePanel.getSelectedRowObjects().get(0);
        try {
            UserObject fetchUserInfoByName = rightDel.fetchUserInfoByName(LogonApplication.getUserEntityObject().getUserName());
            if(fetchUserInfoByName.getUserType()!=0){
                if(obj.getType()==1){
                    VCIOptionPane.showMessage(this, 
                            "当前用户不可以修改三员角色");
                    return;
                }
            }
        } catch (VCIException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        new RoleDialog (this,obj,"editRole");
        
    }
    /**
     * 删除事件
     */
    private void deleteButton_conform(){
        int len = tablePanel.getSelectedRowIndexs().length;
        if(len == 0){
            VCIOptionPane.showMessage(this, 
                    "请选择要删除的对象!");
            return;
        }
        String[] puids = new String[len];
 
        Map<String, String> map = new HashMap<String, String>();
        for (int i = 0; i < len; i++) {
            RoleObject roleInfo = tablePanel.getSelectedRowObjects().get(i);
            try {
                UserObject fetchUserInfoByName = rightDel.fetchUserInfoByName(LogonApplication.getUserEntityObject().getUserName());
                if(fetchUserInfoByName.getUserType()!=0){
                    if(roleInfo.getType()==1){
                        VCIOptionPane.showMessage(this, 
                                "当前用户不可以删除三员角色");
                        return;
                    }
                }
            } catch (VCIException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            puids[i] = roleInfo.getId();
            map.put(roleInfo.getId(), roleInfo.getName());
        }
        RightManagementClientDelegate del = new RightManagementClientDelegate(LogonApplication.getUserEntityObject());
        for(int k=0;k<puids.length;k++) {
            int count = 0 ;
            try {
                count = del.checkRoleIsquotedCount(puids[k]);
                if(count > 0) {
                    VCIOptionPane.showMessageDialog(LogonApplication.frame, "角色:"+map.get(puids[k]) +"已经被引用,不能对其进行删除操作!");
                    return;
                }
                    
            } catch (VCIException e) {
                e.printStackTrace();
                VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
                return ;
            }
        }
        
        int ok=VCIOptionPane.showQuestion(LogonApplication.frame,
                LocaleDisplay.getI18nString("rmip.stafforg.operate.conformdelrole", "RMIPFramework", getLocale()));
       
        if (ok == 0) {
            boolean rs=true;
            try {
                rs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).deleteRole(puids);
            } catch (VCIException e) {
                VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
                return ;
            }
            if (!rs) {
                return;
            }
        }else{
            return;
        }
        tablePanel.refreshTableData();
    }
    /**
     * 分配成员事件
     */
    private void rightButton_conform(){
        int len = tablePanel.getSelectedRowIndexs().length;
        if (len == 0){
            VCIOptionPane.showMessage(this, "请选择角色进行成员分配!");
            return;
        }else if (len > 1){
            VCIOptionPane.showMessage(this, "一次只能对一个角色进行分配人员操作!");
            return;
        }else {
            RoleObject  rightRoleObj = tablePanel.getSelectedRowObjects().get(0);
            RightRoleDialog dialog = new RightRoleDialog(rightRoleObj);
            dialog.setVisible(true);
        }
    }
    private void btnDisplay_conform(){
        int len = tablePanel.getSelectedRowIndexs().length;
        DisplayDialog dialog = null;
        
        if(len == 0){
            VCIOptionPane.showMessage(this, "请选择角色!");
            return;
        }else if (len > 1){
            VCIOptionPane.showMessage(this, "最多只能选择一个角色进行统计!");
            return;
        }else{
            RoleObject[] roleObjs = new RoleObject[len];
            for (int i = 0 ; i < len ; i ++){
                roleObjs[i] = tablePanel.getSelectedRowObjects().get(i);
            }
            dialog = new DisplayDialog(roleObjs);
        }
        
        
        dialog.setModal(true);
        dialog.setVisible(true);
    }
    @Override
    public String getUserID() {
        return logonUserId;
    }
    @Override
    public String getRoleID() {
        return logonRoleId;
    }
    @Override
    public JPanel getModuleComponent() {
        return this;
    }
    @Override
    public String getModuleName() {
        if (this.getFuncObj() != null && this.getFuncObj().getName() != null)
            return this.getFuncObj().getName();
        else if (moduleName != null && !moduleName.isEmpty())
            return moduleName;
        else
            return this.getClass().getName();
    }
    @Override
    public String getIconName() {
        return iconName;
    }
    @Override
    public String getModuleShowInfo() {
        return moduleShowInfo;
    }
}