wangting
2024-12-26 fa261e8c1220b31af54e8167e4de9c3320b1af27
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
package com.vci.client;
 
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
 
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
 
import com.vci.client.ClientSession;
import com.vci.client.common.ConfigUtils;
import com.vci.client.common.interfaces.IAppEventManager;
import com.vci.client.common.objects.ClientInfo;
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.delegate.SystemCfgClientDelegate;
import com.vci.client.framework.rightdistribution.object.RoleRightObject;
import com.vci.client.logon.client.BaseStyle;
import com.vci.client.logon.client.LogonFrame;
import com.vci.client.logon.client.VciFrame;
import com.vci.client.logon.client.ViewCodeFrame;
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.VCIJOptionPane;
import com.vci.common.resource.CommonProperties;
import com.vci.corba.framework.data.UserInfo;
import com.vci.mw.ClientContextVariable;
import com.vci.mw.LaunchModeEnum;
 
public class LogonApplication extends BaseStyle implements IAppEventManager {
 
    public static Frame frame = null;
    boolean packFrame = false;
    public static UserObject userObject = null;
    public static String urlBasePath = ".";
    public static RoleRightObject[] currentUserRoleRights = null;
    private Date loginTime = null;
    private int loginovertime = Integer.parseInt(CommonProperties.getStringProperty("logon.loginovertime"));
 
    public void setUserObject(UserObject userObj) {
        userObject = userObj;
    }
    
 
    @Override
    public boolean checkExpired()  {
        boolean expired = isExpired();
        if(expired){
            VCIOptionPane.showMessageDialog(LogonApplication.frame, "会话过期,请重新登录!!!!");
        }
        return expired;
    }
 
    
    @Override
    public void relogin() {
        if (frame != null){
            frame.dispose();
        }
        show(new String[]{});
    }
 
    /**
     * 检查Client会话是否过期
     * @return
     */
    private boolean isExpired(){
        boolean res = false;
        // add by xchao 2013.08.16 begin 根据选项配置,确定是否需要检查客户端UI是否超时
        if(!ClientSession.isCheckClientUITimeout())
            return false;
        // add by xchao 2013.08.16 end
        
        long betweenTime = 0;
        if (loginTime != null){
             // 当前时间 - 登录时间  -》 转换为分钟
            betweenTime = (System.currentTimeMillis() - loginTime.getTime()) / (60 * 1000);
        }
        
        // 与会话超时阀值进行比较
        if (betweenTime > loginovertime){
            betweenTime = 0;
            loginTime = null;
            res = true;
        }else{
            setLoginTime();
            res = false;
        }
        ClientSession.setTimeOutFlag(res);
        return res;
    }
 
    
    /**
     * 设置登录时间
     */
    private void setLoginTime(){
        loginTime = new Date();
    }
 
    public static UserObject getUserObject() {
        return userObject;
    }
 
    public static UserEntityObject userEntityObject;
 
    public static UserEntityObject getUserEntityObject() {
        return userEntityObject;
    }
 
    public void setUserEntityObject(UserEntityObject userEntityObject) {
        this.userEntityObject = userEntityObject;
    }
 
    private void setUserData(UserObject userObj) {
        this.userObject = userObj;
        String ip = this.getLocalIP();
        String userName = userObj.getUserName();
        UserEntityObject entityObj = new UserEntityObject(userName, ip);
        this.setUserEntityObject(entityObj);
    }
 
    private static String getLocalIP() {
        String ip = "127.0.0.1";
        try {
            ip = java.net.InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return ip;
    }
 
    public LogonApplication(final UserObject userObj) {
        ClientSession.setAppEventManager(this);
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                    
                ClientSession.setTimeOutFlag(false);
                setUserData(userObj);
                VciFrame vciFrame = new VciFrame(userObj);
                try {
                    vciFrame.init();
                } catch (Exception e) {
                    e.printStackTrace();
                    VCIOptionPane.showError(vciFrame, LocaleDisplay.getI18nString("100001", "RMIPFramework", Locale.getDefault()));
                }
                if (packFrame) {
                    vciFrame.pack();
                } else {
                    vciFrame.validate();
                }
                showMainFrame(vciFrame);
            }
        });
    }
    
    @Deprecated
    public static void loadJar() {
        // nothing 
    }
 
    /**
     * 单点登录使用方法
     * @param userObj
     * @param message 业务系统传递的信息
     */
    public LogonApplication(final UserObject userObj,final String[] taskMessage) {
        ClientSession.setAppEventManager(this);
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
        
                ClientSession.setTimeOutFlag(false);
                setUserData(userObj);
                VciFrame vciFrame = new VciFrame(userObj);
                vciFrame.setTaskMessage(taskMessage);
                try {
                    vciFrame.init();
                } catch (Exception e) {
                    VCIOptionPane.showError(vciFrame, LocaleDisplay.getI18nString("100001", "RMIPFramework", Locale.getDefault()));
                }
                if (packFrame) {
                    vciFrame.pack();
                } else {
                    vciFrame.validate();
                }
                showMainFrame(vciFrame);
            }
        });
    }
    
    private void showMainFrame(VciFrame vciFrame){
        vciFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        VCISwingUtil.setClientMainFrame(vciFrame);
        vciFrame.setFocusableWindowState(true);
        setSizeAndLocation(vciFrame);
        vciFrame.setVisible(true);
        frame = vciFrame;
 
        // 集成(单点)登录或是B/S登录界面登录时,Client启动时,重新ClientContextVariable
        LogonApplication.frame = vciFrame;
        ClientContextVariable.setFrame(vciFrame);
        try {
            vciFrame.loadTab1(0);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    private Dimension getCurrentSizeAndSetLocation(VciFrame frame){
        Dimension d = new Dimension();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        Insets insets  = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
        int top = insets.top;
        int left = insets.left;
        int right = insets.right;
        int bottom = insets.bottom;
        int width = dim.width - left - right;
        int height = dim.height - top - bottom;
        int x = insets.left;
        int y = insets.top;
        frame.setLocation(x, y);
        d = new Dimension(width, height);
        return d;
    }
    private boolean manualSetSize = false;
    private void setSizeAndLocation(final VciFrame frame){
        Insets insets  = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
        Dimension size = getCurrentSizeAndSetLocation(frame);
        frame.setPreferredSize(size);
        frame.setSize(size);
        Point location = new Point(insets.left, insets.top);
        frame.setLocation(location);
        frame.setLocationByPlatform(true);
        frame.setLocationRelativeTo(null);
        frame.addComponentListener(new ComponentAdapter() {
            
            @Override
            public void componentResized(ComponentEvent e) {
                if(e.getSource() instanceof VciFrame){
                    if(manualSetSize){
                        manualSetSize = false;
                        return;
                    }
                    VciFrame vf = (VciFrame)e.getSource();
                    int extendedState = vf.getExtendedState();
                    if((extendedState & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH){
                        manualSetSize = true;
                        Dimension size = getCurrentSizeAndSetLocation(frame);
                        frame.setPreferredSize(size);
                        frame.setSize(size);
                        return;
                    }
//                    
//                    //paramString -> COMPONENT_RESIZED (0,0 1600x856)
//                    String[] widthXHeights = e.paramString()
//                            .replaceAll("COMPONENT_RESIZED", "").trim()
//                            .replaceAll("\\(", "")
//                            .replaceAll("\\)", "")
//                            .split(" ")[1].split("x");
//                    int widthNew = Integer.valueOf(widthXHeights[0]);
//                    int heightNew = Integer.valueOf(widthXHeights[1]);
//                    Dimension maxSize = vf.getMaximumSize();
//                    if(heightNew > maxSize.height){
//                        heightNew = maxSize.height;
//                        manualSetSize = true;
//                        vf.setSize(widthNew, heightNew);
//                    }
                }
            }
        });
    }
    
    public static void main(String[] args) {
        System.out.println("");
        System.out.println("\t***************************************************************");
        System.out.println("\t* VCI-Platform Client V2024 www.vci-tech.com                  *");
        System.out.println("\t* (C)Beijing Hongbo Yuanda Sciense and Technology Co. , Ltd.  *");
        System.out.println("\t***************************************************************");
        System.out.println("");
        
 
        for(String a : args){
            System.out.println("args = "+ a);
        }
//         args = new String[]{"intUser_xc","taskType_EDIT","taskId_840033", "ViewCode_false"};
        
        // add by xchao 2013.08.16 begin 设置客户端UI需要检查是否超时
        ClientSession.setCheckClientUITimeout(true);
        // add by xchao 2013.08.16 end
        
        // launchMode_1 -> 此时代表常规模式,如:通过命令行或调试模式 normal
        // launchMode_2 -> jnlpwebstart 此时代表通过 使用 jnlp 方式启动 
        // webBasePath_http://ip:port/xxx -> http://ip:port/xxx  是 jnlp 方式启动的 .jnlp 主地址
        for(String arg : args){
            if(arg.contains("_")){
                String[] kvs = arg.split("_");
                if(kvs.length >= 2){
                    if("launchMode".equalsIgnoreCase(kvs[0])){
                        LaunchModeEnum launchMode = LaunchModeEnum.getByIntVal(Integer.valueOf(kvs[1]));
                        ClientContextVariable.setClientLanuchMode(launchMode);
                    } else if("webBasePath".equalsIgnoreCase(kvs[0])){
                        String webBasePath = arg.substring(arg.indexOf("_")+1);
                        if(!"".equals(webBasePath)){
                            ClientContextVariable.setWebBasePath(webBasePath);
                        }
                    }
                }
            }
        }
//        System.out.println("launchMode:" + ClientContextVariable.getClientLanuchMode().getLabel());
//        System.out.println("webBasePath:" + ClientContextVariable.getWebBasePath());
//        if(ClientContextVariable.getClientLanuchMode() == LaunchModeEnum.Normal){
//            new ClassLoaderUtil().loadNeedLoadJars();
//        }
        show(args);
    }
 
    public static void show(final String[] argsInput){
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                
                try {
                    String sLookFeel = ConfigUtils.getConfigValue("LookAndFeel");
                    if (!sLookFeel.isEmpty() && !sLookFeel.equals("LookAndFeel"))
                        VCISwingUtil.setLookAndFeel(sLookFeel);
                    else
                        VCISwingUtil.setLookAndFeel();
 
                    JFrame.setDefaultLookAndFeelDecorated(true);
                    JDialog.setDefaultLookAndFeelDecorated(true);
                    //设置主题 
                    //SubstanceLookAndFeel.setCurrentTheme(new SubstanceEbonyTheme());
                    //设置按钮外观
                    //SubstanceLookAndFeel.setCurrentButtonShaper(new ClassicButtonShaper());
                    
                    //VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_PlasticLookAndFeel);
                    //VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_WindowsLookAndFeel);
                    //VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_AlloyLookAndFeel);
                    //VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_NimbusLookAndFeel);
                    //VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_MetalLookAndFeel);
                    //VCISwingUtil.setLookAndFeel("org.pushingpixels.substance.api.SubstanceBusinessBlackSteelLookAndFeel");
                    //VCISwingUtil.setLookAndFeel();
                    String intUserName = "";
                    String taskType = "";
                    String taskId = "";
                    String codes = "";
                    if(argsInput.length >0){
                        // 从传入的参数中,解析出集成用户,参数信息 intUser_XXX
                        String[] innerName = argsInput[0].split("_");
                        if(innerName!=null && innerName.length==2){
                            for(int i = 0; i < innerName.length; i++){
                                String arg = innerName[i];
                                if(arg.trim().equals("intUser")){
                                    if((i+1)<innerName.length){
                                        intUserName = innerName[i+1];
                                    }
                                }
                            }
                        }
                        if (argsInput.length >= 2) {
                            urlBasePath = argsInput[1];
                        }
                    }
                    if(argsInput.length > 2){
                        //从传入的参数中,解析出流程任务类型表示,参数信息 taskType_xxx
                        String[] taskTypeArgs = argsInput[1].split("_");
                        if(taskTypeArgs!=null && taskTypeArgs.length==2){
                            for(int i = 0; i < taskTypeArgs.length; i++){
                                String arg = taskTypeArgs[i];
                                if(arg.trim().equals("taskType")){
                                    if((i+1)<taskTypeArgs.length){
                                        taskType = getTaskTypeByProcessMark(taskTypeArgs[i+1]);
                                    }
                                }
                            }
                        }
                        //从传入的参数中,解析出流程任务ID,参数信息taskId_xxx
                        String[] taskIdArgs = argsInput[2].split("_");
                        if(taskIdArgs!=null && taskIdArgs.length==2){
                            for(int i = 0; i < taskIdArgs.length; i++){
                                String task = taskIdArgs[i];
                                if(task.trim().equals("taskId")){
                                    if((i+1)<taskIdArgs.length){
                                        taskId = taskIdArgs[i+1];
                                    }
                                }
                            }
                        }
                        
                        // add by xchao 2013.05.20 begin
                        // for 014 
                        // 代码申请,最后 的完成事件中会将申请成功的代码发送给申请人员(通过创建待办通知的方式)
                        // 当申请人员查阅了申请到的代码后,需要执行‘已阅知’,将待办任务从协同平台中删除
                        // 以下代码是配合‘向申请人员发送代码’使用的
                        // 以下代码的书写,是建立在‘待办任务回调URL地址中的参数书写是有顺序的’
                        String[] viewCodeArgs = argsInput[3].split("_");
                        if(viewCodeArgs != null && viewCodeArgs.length == 2){
                            String param = viewCodeArgs[0];
                            String value = viewCodeArgs[1];
                            if("ViewCode".equals(param) && "true".equals(value)){
                                // 发送这个待办时,taskId传递的就是全部的CODE,通过逗号分隔
                                codes = taskId;
                            }
                        }
                        // add by xchao 2013.05.20 end
                        
                    }
                    //System.out.println("innerName = "+intUserName+" taskType = "+taskType +"  taskId = "+taskId);
                    boolean isLoginSecurity = new SystemCfgClientDelegate(new UserEntityObject("", "")).getConfigValue("logon.Security").equalsIgnoreCase("true");
 
                    if(!intUserName.equals("")){
                        UserObject userObj = new RightManagementClientDelegate().getUserObjectByUserName(intUserName);
                        
                        if(userObj != null){
                            if(codes != null && !"".equals(codes)){
                                // 查看代码的窗口
                                final String codess = codes;
                                VCISwingUtil.invokeLater(new Runnable() {
                                    @Override
                                    public void run() {
                                        new ViewCodeFrame(codess).setVisible(true);
                                    }
                                }, 0);
                            } else if(!(taskType != null && taskType.equals("") && taskId != null && taskId.equals(""))){
                                String[] message = new String[]{"任务箱",taskType,"待办任务",taskId};
                                setContextInfo(userObj);
                                new LogonApplication(userObj,message);
                            }else{
                                setContextInfo(userObj);
                                new LogonApplication(userObj);
                            }
                        }else if (!isLoginSecurity){
                            showLoginFrame();    
                        }
                    } else if (!isLoginSecurity){
                        showLoginFrame();    
                    }
                }catch (VCIException e){
                    System.out.println(LocaleDisplay.getI18nString(e.getException_code(), "RMIPFramework", Locale.getDefault()));
                }catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    
    private static void setContextInfo(UserObject userObj){
        RightManagementClientDelegate rmcd = new RightManagementClientDelegate();
        UserInfo userInfo = rmcd.changeUserObjectToUserInfo(userObj);
        ClientInfo clientInfo = new ClientInfo();
        clientInfo.setIp(getLocalIP());
        try{
            rmcd.initContextInfo(userInfo, clientInfo);
        }catch(VCIException e){
            e.printStackTrace();
            VCIJOptionPane.showConfirm(null, "设置客户端上下文信息时发生错误!\n" + e.toString());
        }
    }
    
    /**
     * 根据流程类型确定流程任务类别
     * <p>Description: </p>
     * 
     * @time 2013-4-26
     * @param taskType 流程标示
     * @return
     */
    private static String getTaskTypeByProcessMark(String taskType){
        Map<String, String> map = new HashMap<String, String>();
        map.put("ADD", "申请任务");
        map.put("BATCHAPPLY", "申请任务");
        map.put("EDIT", "更改任务");
        map.put("DELETE", "删除任务");
        map.put("FREEZE", "停用任务");
        map.put("UNFREZE", "启用任务");
        String result= map.get(taskType);
        return result;        
    }
    
    /****
     * 重新登陆时调用该构造
     * 
     * @param s
     *            传递一个空的字符串即可
     */
    public LogonApplication() {
        show(new String[]{});
    }
//    public static void setTaskMessage(String[] taskMessage) {
//        taskMessage = taskMessage;
//    }
 
    private static void showLoginFrame() {
        LogonFrame logonFrame = new LogonFrame();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension dialogSize = logonFrame.getPreferredSize();
        logonFrame.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
        logonFrame.setVisible(true);
    }
}