cy
2022-06-22 425675051e544cf29b2132615cfbf7a93dc5e51f
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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
package cn.ksource.web.controller;
 
import cn.ksource.beans.GG_USER;
import cn.ksource.core.license.AESUtil;
import cn.ksource.core.license.LicenseController;
import cn.ksource.core.util.*;
import cn.ksource.core.web.LoginUser;
import cn.ksource.core.web.WebUtil;
import cn.ksource.web.Constants;
import cn.ksource.web.SysConstants;
import cn.ksource.web.controller.business.pages.xtpz.sjzd.address.AddressFacade;
import cn.ksource.web.entity.LoginEntity;
import cn.ksource.web.entity.PermissionEntity;
import cn.ksource.web.facade.BusinessFacade;
import cn.ksource.web.facade.JsglFacade;
import cn.ksource.web.facade.fileManage.DocFacade;
import cn.ksource.web.facade.sys.SysPtVersionFacade;
import de.schlichtherle.license.LicenseContent;
import sun.misc.BASE64Decoder;
 
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.ModelAndView;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
 
@Controller
@RequestMapping("/business/")
public class BusinessController {
 
    @Resource(name="businessFacade")
    private BusinessFacade businessFacade;
    
    @Resource(name="addressFacade")
    private AddressFacade addressFacade;
    
    @Autowired
    private SysPtVersionFacade sysPtVersionFacade;
    
    @Autowired
    private JsglFacade jsglFacade;
    @Autowired
    private DocFacade docFacade;
    
    @RequestMapping("sysinfo.html")
    public ModelAndView onSysInfoPageLoad(HttpServletRequest request,HttpServletResponse response){
        return new ModelAndView("/business/sysinfo");
    }
 
    @RequestMapping(value="login.html",method=RequestMethod.GET)
    public ModelAndView onLoginLoad(HttpServletRequest request,HttpServletResponse response){
        ModelAndView view = new ModelAndView("/business/login");
        view.addObject("qqurl", QQUtil.getAuthorizationCodeUrl());
        view.addObject("wechaturl", WechatUtil.getAuthorizationCodeUrl("123"));
        return view;
    }
    
    /**
     * 管理员登录
     * @param request
     * @param response
     * @return
     * @version V1.0.0
     * @author 杨凯
     * @date Feb 23, 2014 1:06:51 PM
     */
    @RequestMapping(value="login.html",method=RequestMethod.POST)
    public ModelAndView onLoginSubmit(HttpServletRequest request,HttpServletResponse response){
        
        String type = request.getParameter("type");
        if(!StringUtil.notEmpty(type)) {
            String checkCode = request.getParameter("checkCode");
            //验证码错误
            if (StringUtils.isBlank(checkCode) || !StringUtils.equalsIgnoreCase(checkCode, (String)request.getSession().getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY))) {
                return new ModelAndView("redirect:/business/login.html?err=2");
            }
        }
        
        
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String client_ip = IPUtil.getIpAddr(request);
        
        LoginEntity entity = businessFacade.doUserLogin(username, password, client_ip);
        
        if (entity.isLoginSuccess()) {
            ModelAndView view = getMainView(request, entity);
            return view;
        }
        
        //已经登录
        if (entity.isAlreadyLogined()) {
            request.getSession().setAttribute("temp_userMap", entity.getUser());
            return new ModelAndView("redirect:/business/Logined.html");
        }
        //是否默认密码
        if (entity.isDefaultPassword()) {
            request.getSession().setAttribute("temp_userMap", entity.getUser());
            return new ModelAndView("redirect:/business/changePwd.html");
        }
            
        return new ModelAndView("redirect:/business/login.html?err="+entity.getResult());
    }
 
    private ModelAndView getMainView(HttpServletRequest request, LoginEntity entity) {
        LoginUser loginUser = new LoginUser();
        loginUser.setLoginUser(entity.getUser());
        PermissionEntity permissionEntity = entity.getPermissionEntity();
        loginUser.setYjgnList(permissionEntity.getYjgnList());
        loginUser.setGnMap(permissionEntity.getGnMap());
        loginUser.setPermissionMap(permissionEntity.getQxMap());
        loginUser.setEjgnMap(permissionEntity.getEjgnMap());
        request.getSession().setAttribute(SysConstants.LOGIN_INFO_KEY, loginUser);
        Map userMap = WebUtil.getLoginUser(request).getLoginUser();
        List allList = loginUser.getYjgnList();
        Map<String,Map> linkMap = permissionEntity.getLinkMap();
        loginUser.setLinkMap(linkMap);
        request.getSession().setAttribute(SysConstants.YJGN, allList);
        
        //用户角色
        Map roleMap = businessFacade.getRoleMapByUserId(ConvertUtil.obj2StrBlank(entity.getUser().get("ID")));
        loginUser.setRoleMap(roleMap);
        System.out.println(loginUser.getRoles());
        userMap.put("roles", loginUser.getRoles());
        request.getSession().setAttribute("loguser", userMap);
        String VERSION_CODE=businessFacade.getV();
        request.getSession().setAttribute("VERSION_CODE", VERSION_CODE);
        ModelAndView view = new ModelAndView();
        //默认地址
        String url = "/business/pages/desktop/defaultDesk.html";
        List<Map> roles = jsglFacade.getRolesByUserId(WebUtil.getLoginedUserId(request), 1);
        if(roles.size()>1){
            url = "/business/pages/desktop/selDesk.html";
        }else if(roles.size()==1){
            String identify = ConvertUtil.obj2StrBlank(roles.get(0).get("identify"));
            if (StringUtil.isNotBlank(identify)) {
                url = Constants.getINDEX(identify);
            }
        }
        view.setViewName("redirect:"+url);
        //ModelAndView view = new ModelAndView();
        return view;
    }
    
    
    @RequestMapping(value="changePwd.html",method=RequestMethod.GET)
    public ModelAndView onChangePwdLoad(HttpServletRequest request,HttpServletResponse response){
        return new ModelAndView("/business/changePwd");
    }
    
    @RequestMapping(value="changePwd.html",method=RequestMethod.POST)
    public ModelAndView onChangePwdSubmit(HttpServletRequest request,HttpServletResponse response){
        String password = request.getParameter("password");
        
        Map userMap = (Map)request.getSession().getAttribute("temp_userMap");
        
        LoginEntity entity = businessFacade.doChangePwdSubmit(userMap.get("LOGINNAME").toString(), password);
        
        if (entity.isLoginSuccess()) {
            ModelAndView view = getMainView(request, entity);
            return view;
        }
        
        //已经登录
        if (entity.isAlreadyLogined()) {
            request.getSession().setAttribute("temp_userMap", entity.getUser());
            return new ModelAndView("redirect:/business/Logined.html");
        }
        
        request.getSession().removeAttribute("temp_userMap");
        
        return new ModelAndView("redirect:/business/pages/main.html");
    }
    
    
    @RequestMapping(value="Logined.html")
    public ModelAndView onLoginedPageLoad(HttpServletRequest request,HttpServletResponse response){
        Map userMap = (Map)request.getSession().getAttribute("temp_userMap");  
        return new ModelAndView("/business/Logined","user",userMap);
    }
    
    @RequestMapping(value="KickedOut.html")
    public ModelAndView onKickedOutLoad(HttpServletRequest request,HttpServletResponse response){
        Map userMap = (Map)request.getSession().getAttribute("temp_userMap");  
        String ip = IPUtil.getIpAddr(request);
        
        LoginEntity entity = businessFacade.doKickedOutSubmit(userMap.get("LOGINNAME").toString(), ip);
        request.getSession().removeAttribute("temp_userMap");        
        ModelAndView view = getMainView(request, entity);
        return view;
    }
    
    @RequestMapping("LoginFailure.html")
    public ModelAndView onLogOut(HttpServletRequest request,HttpServletResponse response){
        response.setHeader("Cache-Control", "no-cache");
        HttpSession session = request.getSession();
        session.removeAttribute(SysConstants.LOGIN_INFO_KEY);
        session.invalidate();
        return new ModelAndView("/business/LoginFailure",SysConstants.login_Failure_Err_Message,"正在退出登录...");
    }
    
    @RequestMapping("logout.html")
    public ModelAndView logout(HttpServletRequest request,HttpServletResponse response){
        HttpSession session = request.getSession();
        session.removeAttribute(SysConstants.LOGIN_INFO_KEY);
        session.invalidate();
        ModelAndView view = new ModelAndView("redirect:/business/login.html");
        return view;
    }
    
    /**
     * 无权限使用此功能
     * @param request
     * @param response
     * @return
     * @version V1.0.0
     * @author 杨凯
     * @date Jan 13, 2014 5:10:25 PM
     */
    @RequestMapping("nopermission.html")
    public ModelAndView nopermission(HttpServletRequest request,HttpServletResponse response){
        
        return new ModelAndView("/business/nopermission");
    }
    
    
    @RequestMapping(value = "remote.html",method=RequestMethod.GET)
    public void onRemote(HttpServletRequest request,HttpServletResponse response){
        String name = request.getParameter("name");
        
        Map map = new HashMap();
        if (StringUtils.equalsIgnoreCase(name, "1")) {
            map.put("name", "杨凯");
        } else {
            map.put("name", "杨凯1222312313");
        }
        map.put("age", "20");
        map.put("address", "河南郑州市");
        map.put("aaa", "23");
        String json = JsonUtil.map2Json(map);
        WebUtil.write(response, json);
    }
    
    
    
    
    /**
     * 查询地区三级分类树
     */
    @RequestMapping("areaSelector.html")
    public String areaSelector(Model model,HttpServletRequest request) {
        //查询三级树形结构
        String areaId = request.getParameter("areaId");
        @SuppressWarnings("rawtypes")
        List trees = addressFacade.getAreaTree(areaId);
        model.addAttribute("trees", trees);
        return "/business/pages/xtgl/xtpz/sjzd/address/areaSelector";
    }
    
    /**
     * QQ登录回调页面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("loginCallBack.html")
    public ModelAndView getCallBack(HttpServletRequest request,HttpServletResponse response){
        ModelAndView view1 = new ModelAndView("/business/loginCallBack");
        String code = request.getParameter("code");
        if(StringUtil.notEmpty(code)) {
            String accessTokenUrl = QQUtil.getAccessTokenUrl(code);
            String result = HttpUtil.doGet(accessTokenUrl, null, HttpCharset.UTF8);
            System.out.println("result---------->"+result);
            if(StringUtil.notEmpty(result) && result.contains("access_token")) {
                String[] arr = result.split("&");
                Map<String,String> resultMap = new HashMap<String,String>();
                for(String str : arr) {
                    String[] msg = str.split("=");
                    resultMap.put(msg[0], msg[1]);
                }
                
                String access_token = resultMap.get("access_token");
                String openIdUrl = QQUtil.getOpenIdUrl(access_token);
                String openIdResult =  HttpUtil.doGet(openIdUrl, null, HttpCharset.UTF8);
                System.out.println("access_token-------------->"+access_token+"=============openIdResult-------------->"+openIdResult);
                if(openIdResult.contains("callback") && openIdResult.contains("openid")) {
                    String json = openIdResult.substring(openIdResult.indexOf("(")+1, openIdResult.lastIndexOf(")"));
                    Map jsonMap = JsonUtil.json2Map(json);
                    
                    String openId = ConvertUtil.obj2StrBlank(jsonMap.get("openid"));
                    System.out.println("openId------------------->"+openId);
                    
                    //通过QQ的openId判断用户是否已经绑定过
                    Map msg = businessFacade.queryUserMsgByQQ(openId);
                    if(null==msg || msg.size()==0) {
                        ModelAndView modelAndView = new ModelAndView("/business/qqBind");
                        //获取用户昵称信息
                        String userInfoUrl = QQUtil.getUserInfoUrl(access_token, openId);
                        System.out.println("userInfoUrl-------------->"+userInfoUrl);
                        String userInfo = HttpUtil.doGet(userInfoUrl, null, HttpCharset.UTF8);
                        Map user = JsonUtil.json2Map(userInfo);
                        String nickname = ConvertUtil.obj2StrBlank(user.get("nickname"));
                        modelAndView.addObject("nickname", nickname);
                        modelAndView.addObject("openid",openId);
                        return modelAndView;
                    }
                    
                    
                    String loginName = ConvertUtil.obj2StrBlank(msg.get("LOGINNAME"));
                    String client_ip = IPUtil.getIpAddr(request);
                    LoginEntity entity = businessFacade.doQQUserLogin(loginName,client_ip);
                    if (entity.isLoginSuccess()) {
                        ModelAndView view = getMainView(request, entity);
                        return view;
                    }
                    //已经登录
                    if (entity.isAlreadyLogined()) {
                        request.getSession().setAttribute("temp_userMap", entity.getUser());
                        return new ModelAndView("redirect:/business/Logined.html");
                    }
                    
                    
                    
                    ModelAndView modelAndView =  new ModelAndView("redirect:/business/login.html");
                    Map err = new HashMap();
                    err.put("err", entity.getResult());
                    request.getSession().setAttribute("err", err);
                    return modelAndView;
                }
            }
        }
        return view1;
    }
    
    
    @RequestMapping(value="qqBind.html",method=RequestMethod.POST)
    public ModelAndView qqBinds(HttpServletRequest request,HttpServletResponse response){
        ModelAndView modelAndView =  new ModelAndView("/business/qqBind");
        String openid = request.getParameter("openid");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String nickname = request.getParameter("nickname");
        
        
        modelAndView.addObject("nickname", nickname);
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("username", username);
        modelAndView.addObject("password", password);
        Map err = new HashMap();
        
        String client_ip = IPUtil.getIpAddr(request);
            
        LoginEntity entity = businessFacade.doUserLogin(username, password, client_ip);
            
        if (entity.isLoginSuccess()) {
            //判断该账户是否已经绑定过QQ
            Map user = entity.getUser();
            String qqOpenId = ConvertUtil.obj2StrBlank(user.get("QQ_OPEN_ID"));
            if(StringUtil.notEmpty(qqOpenId)) {
                modelAndView.addObject("err", "该账号已经绑定过QQ");
                return modelAndView;
            }
            
            
            //执行绑定操作
            GG_USER gg_user = new GG_USER();
            gg_user.setId(ConvertUtil.obj2StrBlank(user.get("ID")));
            gg_user.setQq_open_id(openid).setQq(nickname);
            gg_user.update();
            
            
            ModelAndView view = getMainView(request, entity);
            return view;
        }
    
        //已经登录
        if (entity.isAlreadyLogined()) {
            request.getSession().setAttribute("temp_userMap", entity.getUser());
            return new ModelAndView("redirect:/business/Logined.html");
        }
        
        //是否默认密码
        if (entity.isDefaultPassword()) {
            request.getSession().setAttribute("temp_userMap", entity.getUser());
            //判断加盟商是否已经进行了系统初始化操作,如果没有,需要初始化基础数据
            request.getSession().setAttribute("temp_userMap", entity.getUser());
            return new ModelAndView("redirect:/business/changePwd.html");
        }
        
        
        modelAndView.addObject("err", LoginEntity.Login_Result_Info.get(entity.getResult()));
        
        
        return modelAndView;
            
            
    }
    
    
    
    
    /**
     * 微信登录回调页面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("wechatCallBack.html")
    public ModelAndView wechatCallBack(HttpServletRequest request,HttpServletResponse response){
        ModelAndView view1 = new ModelAndView("/business/loginCallBack");
        String code = request.getParameter("code");
        if(StringUtil.notEmpty(code)) {
            String accessTokenUrl = WechatUtil.getAccessTokenUrl(code);
            String result = HttpUtil.doGet(accessTokenUrl, null, HttpCharset.UTF8);
            System.out.println("result---------->"+result);
            if(StringUtil.notEmpty(result) && result.contains("access_token")) {
                Map resultMap = JsonUtil.json2Map(result);
                String access_token = ConvertUtil.obj2StrBlank(resultMap.get("access_token"));
                String openId = ConvertUtil.obj2StrBlank(resultMap.get("openid"));
                System.out.println("openId------------------->"+openId);
                
                //通过QQ的openId判断用户是否已经绑定过
                Map msg = businessFacade.queryUserMsgByWechat(openId);
                if(null==msg || msg.size()==0) {
                    ModelAndView modelAndView = new ModelAndView("/business/qqBind");
                    //获取用户昵称信息
                    String userInfoUrl = WechatUtil.getUserInfoUrl(access_token, openId);
                    System.out.println("userInfoUrl-------------->"+userInfoUrl);
                    String userInfo = HttpUtil.doGet(userInfoUrl, null, HttpCharset.UTF8);
                    Map user = JsonUtil.json2Map(userInfo);
                    String nickname = ConvertUtil.obj2StrBlank(user.get("nickname"));
                    modelAndView.addObject("nickname", nickname);
                    modelAndView.addObject("openid",openId);
                    return modelAndView;
                }
                
                
                String loginName = ConvertUtil.obj2StrBlank(msg.get("LOGINNAME"));
                String client_ip = IPUtil.getIpAddr(request);
                LoginEntity entity = businessFacade.doQQUserLogin(loginName,client_ip);
                if (entity.isLoginSuccess()) {
                    ModelAndView view = getMainView(request, entity);
                    return view;
                }
                //已经登录
                if (entity.isAlreadyLogined()) {
                    request.getSession().setAttribute("temp_userMap", entity.getUser());
                    return new ModelAndView("redirect:/business/Logined.html");
                }
                
                
                
                ModelAndView modelAndView =  new ModelAndView("redirect:/business/login.html");
                Map err = new HashMap();
                err.put("err", entity.getResult());
                request.getSession().setAttribute("err", err);
                return modelAndView;
            }
        }
        return view1;
    }
    
    
    @RequestMapping(value="wechatBind.html",method=RequestMethod.POST)
    public ModelAndView wechatBind(HttpServletRequest request,HttpServletResponse response){
        ModelAndView modelAndView =  new ModelAndView("/business/wechatBind");
        String openid = request.getParameter("openid");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String nickname = request.getParameter("nickname");
        
        
        modelAndView.addObject("nickname", nickname);
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("username", username);
        modelAndView.addObject("password", password);
        Map err = new HashMap();
        
        String client_ip = IPUtil.getIpAddr(request);
            
        LoginEntity entity = businessFacade.doUserLogin(username, password, client_ip);
            
        if (entity.isLoginSuccess()) {
            //判断该账户是否已经绑定过QQ
            Map user = entity.getUser();
            String wechatLoginOpenId = ConvertUtil.obj2StrBlank(user.get("WECHAT_LOGIN_OPEN_ID"));
            if(StringUtil.notEmpty(wechatLoginOpenId)) {
                modelAndView.addObject("err", "该账号已经绑定过微信");
                return modelAndView;
            }
            
            
            //执行绑定操作
            GG_USER gg_user = new GG_USER();
            gg_user.setId(ConvertUtil.obj2StrBlank(user.get("ID")));
            gg_user.setWechat_login_open_id(openid).setWechat_nickname(nickname);
            gg_user.update();
            
            
            ModelAndView view = getMainView(request, entity);
            return view;
        }
    
        //已经登录
        if (entity.isAlreadyLogined()) {
            request.getSession().setAttribute("temp_userMap", entity.getUser());
            return new ModelAndView("redirect:/business/Logined.html");
        }
        
        //是否默认密码
        if (entity.isDefaultPassword()) {
            request.getSession().setAttribute("temp_userMap", entity.getUser());
            //判断加盟商是否已经进行了系统初始化操作,如果没有,需要初始化基础数据
            request.getSession().setAttribute("temp_userMap", entity.getUser());
            return new ModelAndView("redirect:/business/changePwd.html");
        }
        
        
        modelAndView.addObject("err", LoginEntity.Login_Result_Info.get(entity.getResult()));
        
        
        return modelAndView;
            
            
    }
    
    
    
    
    
    
    
    
    /**
     * 忘记密码
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="findPwd.html",method=RequestMethod.GET)
    public ModelAndView findPwd(HttpServletRequest request,HttpServletResponse response){
        ModelAndView view = new ModelAndView("/business/findPwd");
        
        return view;
    }
    
    /**
     * 通过用户名查询加盟商用户名是否存在
     */
    
    @RequestMapping("queryUser.html")
    public void queryUser(HttpServletRequest request,HttpServletResponse response) {
        String username = request.getParameter("param");
        Map map = businessFacade.queryUserByName(username);
        Map resultMap = new HashMap();
        if(null!=map&&map.size()>0) {
            resultMap.put("info", "用户名输入正确");
            resultMap.put("status", "y");
        } else {
            resultMap.put("info", "用户名不存在");
            resultMap.put("status", "n");
        }
        WebUtil.write(response, JsonUtil.map2Json(resultMap));
    }
    
    /**
     * 判断验证码是否正确
     */
    @RequestMapping("checkCode.html")
    public void checkCode(HttpServletResponse response,HttpServletRequest request) {
        //获取验证码
        String checkCode = request.getParameter("param");
        Map map = new HashMap();
        if (StringUtil.notEmpty(checkCode) && (StringUtils.equalsIgnoreCase(checkCode, (String) request.getSession().getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY)))) {
            map.put("info", "验证码输入正确");
            map.put("status", "y");
        } else {
            map.put("info", "验证码输入错误");
            map.put("status", "n");
        }
        WebUtil.write(response, JsonUtil.map2Json(map));
    }
    
    /**
     * 进入到身份验证页面
     */
    @RequestMapping(value="vaildPage.html",method=RequestMethod.POST)
    public ModelAndView validPage(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView("/business/vaildPage");
        String username = request.getParameter("username");
        Map map = businessFacade.queryUserByName(username);
        modelAndView.addObject("user", map);
        request.getSession().setAttribute("username", username);
        return modelAndView;
    }
    
    /**
     * 进入到身份验证页面
     */
    @RequestMapping(value="sendfindpwd.html",method=RequestMethod.POST)
    public void sendfindpwd(HttpServletRequest request,HttpServletResponse response) {
        String typename = request.getParameter("typename");
        String type = request.getParameter("type");
        String result = "";
        String random = StringUtil.randomNumber(6);
        request.getSession().setAttribute("random", random);
        System.out.println(random);
        if("1".equals(type)){
            if(StringUtil.notEmpty(typename)) {
                
                String[] emails = new String[]{typename}; 
                String title = Constants.company_name+"忘记密码验证";
                String content = "<div class='email' style=' margin:20px;'>" +
                            "<h2 style='font-size:16px;color:#2b2b2b; line-height:60px;'>亲爱的用户:</h2>" +
                            "<p style='line-height:24px; font-size:14px;list-style:none;'>您好!感谢您使用"+Constants.company_name+",您正在进行邮箱验证,本次请求的验证码为:</p>" +
                            "<p style='line-height:24px; font-size:14px;list-style:none;' ><span style='color:#2866c9; font-weight:bold;'>"+random+"</span><font style='color:#acacae;'>(为了保障您账号的安全性,请在1小时内完成验证。)</font></p>" +
                            "<p style='line-height:24px; font-size:14px;margin-top:50px;list-style:none;'>"+Constants.company_name+"服务团队</p>" +
                            "<p style='line-height:24px; font-size:14px;list-style:none;'>"+DateUtil.getToday("yyyy-MM-dd")+"</p></div>";
                try {
                    boolean flag = EmailUtil.sendEmail(emails, title, content, null);
                    if(flag){
                        result = "0";
                    }else{
                        result = "发送失败";
                    }
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }else{
            String message = SMSUtil.getfindpwdCodeMsg(random);
            //System.out.println(message);
            try {
                result = SMSUtil.sendSMS(message,typename );
                result = "0";
                if(!result.equals("0")) {
                    result = "发送失败";
                }
            } catch (Exception e) {
                result = "发送失败";
            }
        }
        WebUtil.write(response, result);
    }
    
    /**
     * 判断验证码是否正确
     */
    @RequestMapping("checkfindpwdCode.html")
    public void checkfindpwdCode(HttpServletResponse response,HttpServletRequest request) {
        //获取验证码
        String checkCode = request.getParameter("param");
        String sessionRandom = (String)request.getSession().getAttribute("random");
        Map map = new HashMap();
        if (StringUtil.notEmpty(checkCode) && checkCode.equals(sessionRandom)) {
            map.put("info", "验证码输入正确");
            map.put("status", "y");
        } else {
            map.put("info", "验证码输入错误");
            map.put("status", "n");
        }
        WebUtil.write(response, JsonUtil.map2Json(map));
    }
    
    /**
     * 跳转到加盟商重置密码页面
     */
    @RequestMapping(value="confirmCheck.html",method=RequestMethod.POST)
    public ModelAndView confirmCheck(HttpServletResponse response,HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView("/business/resetPwd");
        String checkCode = request.getParameter("checkCode");
        if(checkCode.equals(request.getSession().getAttribute("random"))) {
            request.getSession().removeAttribute("random");
            //获取用户的邮箱信息
            Map map = businessFacade.queryUserByName((String)request.getSession().getAttribute("username"));
            String email = ConvertUtil.obj2StrBlank(map.get("EMAIL"));
            String phone = ConvertUtil.obj2StrBlank(map.get("SJHM"));
            
            //将邮箱地址放入到session中
            
            request.getSession().setAttribute("email", email);
            request.getSession().setAttribute("phone", phone);
            //生成隐式验证码
            String random = StringUtil.randomNumber(6);
            request.getSession().setAttribute("random", random);
            modelAndView.addObject("random", random);
            
            return modelAndView;
        }
        return new ModelAndView("/business/error/404");
    }
    
    /**
     * 加盟商重置密码
     */
    @RequestMapping(value="resetPwd.html",method=RequestMethod.POST)
    public void resetPwd(HttpServletResponse response,HttpServletRequest request) {
        String random = request.getParameter("random");
        String password = request.getParameter("password");
        String sessionRandom = (String)request.getSession().getAttribute("random");
        request.getSession().removeAttribute("random");
        Map resultMap = new HashMap();
        if(random.equals(sessionRandom)) {
            //通过用户名和邮箱重新查询用户信息,以免在此过程中恶意修改用户名或者邮箱
            String username = (String)request.getSession().getAttribute("username");
            String email = (String)request.getSession().getAttribute("email");
            String phone = (String)request.getSession().getAttribute("phone");
            if(StringUtil.isEmpty(email)){
                email = phone;
            }
            boolean b = businessFacade.doResetPwd(username,email,password);
            if(b) {
                resultMap.put("status", "0");
                resultMap.put("msg", "success");
            } else {
                resultMap.put("status", "1");
                resultMap.put("msg", "找回密码失败<br>请联系我们的客服人员");
            }
            WebUtil.write(response, JsonUtil.map2Json(resultMap));
        }
    }
    /**
     * 文件下载
     */
    @RequestMapping(value="fileDownload.html")
    public void  fileDownload(HttpServletResponse response,HttpServletRequest request) {
        Map fileMsg=docFacade.queryFileMsg(request.getParameter("id"));
        if(null!=fileMsg && fileMsg.size()>0) {
            String fileName = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_NAME"));
            String filePath = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_PATH"));
            String basePath = request.getSession().getServletContext().getRealPath("");
            System.out.println("path------------------------>"+basePath+filePath);
            File file = new File(basePath+filePath);
            try {
                DownloadUtil.download(response, file, fileName, false);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    
    
    /**
     * 测试网络拓扑
     */
    @RequestMapping("topo.html")
    public ModelAndView topo(HttpServletRequest request,HttpServletResponse response) {
        ModelAndView modelAndView = new ModelAndView("/business/topo/topo");
        return modelAndView;
    }
    @RequestMapping("getJsonData.html")
    public void getJsonData(HttpServletRequest request,HttpServletResponse response) {
        ModelAndView modelAndView = new ModelAndView("/business/topo/testData");
        String json =businessFacade.getJsonData();
        WebUtil.write(response, json);
    }
    
    @RequestMapping("saveData.html")
    public void saveData(HttpServletRequest request,HttpServletResponse response) {
        String relations = request.getParameter("relations");
        System.out.println("relations--------------->"+relations);
        String nodes = request.getParameter("nodes");
        System.out.println("nodes----------------->"+nodes);
        
        boolean result = businessFacade.saveData(relations,nodes);
        WebUtil.write(response, "1");
    }
    
    public static void main(String[] args) {
        System.out.println("fdd3372e-b102-4b1f-bd6c-140c843d".length());
    }
    
    /**
     * app下载页面
     */
    @RequestMapping("appdown.html")
    public ModelAndView appdown(HttpServletRequest request,HttpServletResponse response) {
        ModelAndView modelAndView = new ModelAndView("/business/appdown");
        return modelAndView;
    }
    
    
    @RequestMapping("testEhcache.html")
    public void testEhcache(HttpServletRequest request,HttpServletResponse response) {
        String result = businessFacade.testEhache();
        WebUtil.write(response, result);
    }
    
    /**
     * 文件下载
     */
    @RequestMapping("appdownload.html")
    public void appdownload(HttpServletRequest request,HttpServletResponse response) {
        String basePath = request.getSession().getServletContext().getRealPath("");
        File file = new File(basePath+"/upload/app/larks_base.apk");
        try {
            DownloadUtil.download(response, file, "larks_base.apk", false);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    /**
     * 页脚弹出版本信息详情页面
     * */
    @RequestMapping("ptVersionInfo.html")
    public ModelAndView ptVersionInfo(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("/business/pages/include/ptVersionInfo");
        view.addObject("info", sysPtVersionFacade.getCurrentVersion());
        return view;
    }
    
    /**
     * 加载页脚版本号
     * */
    @RequestMapping("loadVersion.html")
    public void loadVersion(HttpServletResponse response) {
        Map<String, String> info = sysPtVersionFacade.getCurrentVersion();
        String versionCode = new String();
        if(StringUtil.notEmpty(info.get("VERSION_CODE"))){
            versionCode = info.get("VERSION_CODE");
        }
        WebUtil.write(response, versionCode);
    }
    
    @RequestMapping("licenseErr.html")
    public String licenseErr(Model model){
        InetAddrUtil util = new InetAddrUtil();
        try {
            String ip = util.getLocIp();
            InetAddress ia = InetAddress.getLocalHost();
            String mac = util.getLocalMacByIp(ia);
            String code = ip + ";" + mac;
 
            System.out.println("========"+mac);
            System.out.println("========"+ip);
 
            //加密
            byte[] encryptResult = AESUtil.encrypt(code, Constants.AES_PWD);
            String encryptCode = AESUtil.parseByte2HexStr(encryptResult);
            model.addAttribute("encryptCode", encryptCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "/business/pages/licenseErr";
    }
    
    @RequestMapping(value="importLicense.html",method=RequestMethod.POST)
    public void importLicense(@RequestParam CommonsMultipartFile file, HttpServletRequest request,HttpServletResponse response) throws IllegalStateException, IOException {
        String path = this.getClass().getClassLoader().getResource("").getPath().replace("WEB-INF/classes/", "").replace("%20", " ");
        System.out.print("1111"+path);
        String filename = path + "license.lic";
        File tarFile = new File(filename);
        file.transferTo(tarFile);
        LicenseController licenseController = new LicenseController();
        LicenseContent license;
        try {
            license = licenseController.installLicense(filename);
            SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
            String endDate = df.format(license.getNotAfter());
            businessFacade.updatePartnerInfo(endDate, DateUtil.getCurrentDate14());
        } catch (Exception e) {
            e.printStackTrace();
        }
        WebUtil.write(response, "1");
    }
    
    /**
     * 到期提醒
     * @param request
     * @param response
     * @return
     * @author chenlong
     */
    @RequestMapping("expireInfo.html")
    public String expireInfo(HttpServletRequest request,HttpServletResponse response) {
        return "business/expireInfo";
    }
    
}