派生自 projectDept/qhighschool

111
胡仁荣
2022-12-02 b94deda20c9abd2fb6248b831e10a620eb7daf68
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
package com.qxueyou.scc.sys.action;
 
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import com.qxueyou.scc.base.util.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import com.qxueyou.scc.admin.teacher.service.ITeacherService;
import com.qxueyou.scc.base.dao.CommonDAO;
import com.qxueyou.scc.base.model.Constants;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.model.UserInfoWrapper;
import com.qxueyou.scc.base.service.ICacheService;
import com.qxueyou.scc.base.service.ICommonService;
import com.qxueyou.scc.config.SccConfig;
import com.qxueyou.scc.org.service.IOrganizationService;
import com.qxueyou.scc.sys.model.CacheParamters;
import com.qxueyou.scc.sys.model.SysLog;
import com.qxueyou.scc.sys.service.IAuthorizeService;
import com.qxueyou.scc.sys.service.IPrivilegeService;
import com.qxueyou.scc.teach.student.model.StuStudent;
import com.qxueyou.scc.teach.student.service.IStudentService;
import com.qxueyou.scc.user.model.User;
import com.qxueyou.scc.user.model.UserRole;
import com.qxueyou.scc.user.service.IUserOperateService;
import com.qxueyou.scc.user.service.IUserRoleService;
import com.qxueyou.scc.user.service.IUserService;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
/**
 * ×¢²ácontroller Ìṩע²á£¬µÇ¼£¬×¢Ïú·þÎñ
 *
 * @author µÂ»¢
 * @history 2014-11-25 Ð½¨ Ïĵ»¢
 */
@Api(tags="µÇÈëÏà¹Ø½Ó¿Ú")
@Controller
@CrossOrigin(origins="*",maxAge=3600)
@EnableConfigurationProperties(SccConfig.class)
@RequestMapping(value = "/sys/login")
public class LoginController {
 
    @Autowired
    private CommonDAO commonDAO;
 
    @Autowired
    IPrivilegeService privilegeService;
 
    @Autowired
    IAuthorizeService service;
 
    @Autowired
    IUserRoleService userRoleService;
 
    @Autowired
    ITeacherService teacherService;
 
    @Autowired
    @Qualifier("commonAppService")
    ICommonService commonService;
 
    @Autowired
    IUserOperateService userOperateService;
 
    @Autowired
    IUserService userService;
 
    @Autowired
    ICacheService cacheService;
 
    @Autowired
    IStudentService studentService;
 
    @Resource
    RedisTemplate redisTemplate;
 
    @Autowired
    private IOrganizationService organizationService;
 
    public static String UUNUMBER="QXYUUNUMBER";
 
    @ApiOperation(value = "µÇÈë½Ó¿Ú", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "Õ˺Å", required = true, paramType="query", dataType = "String"),
            @ApiImplicitParam(name = "password", value = "ÃÜÂë", required = true, paramType="query", dataType = "String"),
    })
    @RequestMapping(value = "beforeLogin", method = RequestMethod.POST)
    @ResponseBody
    public Result beforeLogin(@RequestParam("account") String account, @RequestParam("password") String password,
                                HttpServletRequest request, HttpServletResponse response) {
        if(StringUtils.isEmpty(account)||StringUtils.isEmpty(password)) {
            return new Result(false, "Óû§Õ˺ÅÃÜÂë²»ÄÜΪ¿Õ");
        }
        // ²éѯÓû§ÐÅÏ¢
        String uuNumber=null;
        String uuReNumber=null;
        String hql = "from User where deleteFlag is false and account = ? and password = ? ";
        List<Object> params =  CollectionUtils.newList(account,password);
        User user = commonDAO.findUnique(hql,params, User.class);
        if (user == null ) {
            return new Result(false, "Óû§ÕË»§¡¢ÃÜÂë´íÎó");
        }
        if (user.getSource() == null || "".equals(user.getSource())) {
            return new Result(false, "ûÓÐȨÏÞ");
        }
        if("exam".equals(user.getSource())){
//            //»ñÈ¡Session´æÈëuuNumber
//            uuNumber = UUIDUtils.generateSpecialUuid(8)+account;
//            HttpSession session = request.getSession();
//            //ÉèÖÃsession×Ô¶¯¹ýÆÚʱ¼ä 60·ÖÖÓ
//            session.setMaxInactiveInterval(60*60);
//            session.setAttribute("uuNumber", uuNumber);
            //uuNumberʹÓù̶¨
            uuNumber=UUNUMBER;
        }else if("reExam".equals(user.getSource())){
            //»ñÈ¡Session´æÈëuuNumber
            uuReNumber = UUIDUtils.generateSpecialUuid(8)+account;
            HttpSession session = request.getSession();
            //ÉèÖÃsession×Ô¶¯¹ýÆÚʱ¼ä 60·ÖÖÓ
            session.setMaxInactiveInterval(60*60);
            session.setAttribute("uuReNumber", uuReNumber);
        }else {
            return new Result(false, "ûÓÐȨÏÞ");
        }
        // ²åÈëÈÕÖ¾
        insertLoginLog(request, user, account, "SYS-LOGIN");
        // ·µ»Ø
        return new Result(true, "ÑéÖ¤³É¹¦",CollectionUtils.newObjectMap("uuNumber",uuNumber,"uuReNumber",uuReNumber));
    }
 
    @ApiOperation(value = "µÇÈë½Ó¿Ú", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uuNumber", value = "uuNumber", required = true, paramType="query", dataType = "String"),
            @ApiImplicitParam(name = "uuReNumber", value = "uuReNumber", required = true, paramType="query", dataType = "String"),
    })
    @RequestMapping(value = "examLogin", method = RequestMethod.GET)
    @ResponseBody
    public Result examLogin(String uuNumber,String uuReNumber,
                              HttpServletRequest request, HttpServletResponse response) {
        if(StringUtils.isEmpty(uuNumber)&&StringUtils.isEmpty(uuReNumber)){
            return new Result(false, "Ñé֤ʧ°Ü");
        }
        if (StringUtils.isNotEmpty(uuNumber)) {
            //ÓÐuunumber
            String uu=ClientUtils.getUserInfo().getInfo("email");
            if(StringUtils.isEmpty(uu)||!uuNumber.equals(uu)){
                return new Result(false, "uuNumberÑé֤ʧ°Ü");
            }
        } else {
            //ÓÐuurenumber
            HttpSession session = request.getSession();
            String uu=(String) session.getAttribute("uuReNumber");
            if(StringUtils.isEmpty(uu)||!uuReNumber.equals(uu)){
                return new Result(false, "uuReNumberÑé֤ʧ°Ü");
            }
            //ÑéÖ¤ºóɾ³ý
            request.getSession().removeAttribute("uuReNumber");
//            String uu=ClientUtils.getUserInfo().getInfo("email");
//            if(StringUtils.isEmpty(uu)||!uuReNumber.equals(uu)){
//                return new Result(false, "uuReNumberÑé֤ʧ°Ü");
//            }
        }
        // ·µ»Ø
        return new Result(true, "ÑéÖ¤³É¹¦");
    }
 
    @ApiOperation(value = "µÇÈë½Ó¿Ú", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uuNumber", value = "uuNumber", required = true, paramType="query", dataType = "String"),
            @ApiImplicitParam(name = "uuReNumber", value = "uuReNumber", required = true, paramType="query", dataType = "String"),
    })
    @RequestMapping(value = "examssLogin", method = RequestMethod.GET)
    @ResponseBody
    public Result examssLogin(String uuNumber,String uuReNumber,
                              HttpServletRequest request, HttpServletResponse response) {
        //Á½¸ö¶¼Îª¿Õ£¬±íʾûÓвÎÊý
        if(StringUtils.isEmpty(uuNumber)&&StringUtils.isEmpty(uuReNumber)){
            return new Result(false, "Ñé֤ʧ°Ü");
        }
 
        if (StringUtils.isNotEmpty(uuNumber)) {
            //ÓÐuunumber
//            HttpSession session = request.getSession();
//            String uu=(String) session.getAttribute("uuNumber");
            String uu=UUNUMBER;
            if(StringUtils.isEmpty(uu)||!uuNumber.equals(uu)){
                return new Result(false, "uuNumberÑé֤ʧ°Ü");
            }
        } else {
            //ÓÐuurenumber
            HttpSession session = request.getSession();
            String uu=(String) session.getAttribute("uuReNumber");
            if(StringUtils.isEmpty(uu)||!uuReNumber.equals(uu)){
                return new Result(false, "uuReNumberÑé֤ʧ°Ü");
            }
        }
        // ·µ»Ø
        return new Result(true, "ÑéÖ¤³É¹¦");
    }
 
    //Í˳öµÇ¼ Çå³ýsession
    @RequestMapping(value = "khdloginout", method = RequestMethod.POST)
    @ResponseBody
    public void khdloginout(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("Çå³ýsession");
        HttpSession session = request.getSession();
        redisTemplate.delete(UserInfoWrapper.SESSION_USER_INFO_KEY);
        System.out.println(session.getAttribute("userId"));
        System.out.println(session.getAttribute("classId"));
        session.invalidate();
    }
 
    /**
     * Ñ§Ô±¶ËµÇ¼
     *
     * @param account  ÕË»§
     * @param password ÃÜÂë
     * @return
     */
    @ApiOperation(value = "µÇÈë½Ó¿Ú", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "Õ˺Å", required = true, paramType="query", dataType = "String"),
            @ApiImplicitParam(name = "password", value = "ÃÜÂë", required = true, paramType="query", dataType = "String"),
            @ApiImplicitParam(name = "organizationId", value = "»ú¹¹id", required = true, paramType="query", dataType = "String"),
            @ApiImplicitParam(name = "platForm", value = "µÇÈëÆ½Ì¨£¨app£¬web£¬qLive£¬pc£¬weixin£©", required = true, paramType="query", dataType = "String"),
            @ApiImplicitParam(name = "logType", value = "µÇÈëtype£¨studyѧԱ£¬teacher½Ìʦ,·ñÔòΪºǫ́£©", required = true, paramType="query", dataType = "String"),
    })
    @RequestMapping(value = "studentLogin", method = RequestMethod.POST)
    @ResponseBody
    public Result studentLogin(@RequestParam("userId") String userId,HttpServletRequest request, HttpServletResponse response, String logType,String organizationId, String platForm){
 
        String hql = null;
        List<Object> params = null;
        hql = "from User where deleteFlag is false and userId = ?";
        params =  CollectionUtils.newList(userId);
        // ²éѯÓû§ÐÅÏ¢
        User user = commonDAO.findUnique(hql,params, User.class);
        CacheParamters param = new CacheParamters();
        param.setUserId(user.getUserId());
        param.setCustomRoleValue(user.getEmail());
        param.setCustomOrgId(user.getImei());
        param.setCacheIpFlag(true);
        param.setPlatForm(StringUtils.isEmpty(platForm) ? Constants.LOGIN_PLATFORM_WEB : platForm);
        param.setIp(RequestClientUtils.getRemoteIP(request));
//         »º´æµ½ÇëÇóÏß³Ì
        UserInfoWrapper wrapper = cacheUserInfo(param, null);
        // ´æµ½redis
        redisTemplate.opsForValue().set(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper);
        request.getSession().setAttribute(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper);
 
        return new Result(true, "success",
                CollectionUtils.newObjectMap("userId", user.getUserId(), "userName", user.getName(), "imgPath",
                        user.getImgPath(), "orgName", ClientUtils.getOrgName(),"orgId", ClientUtils.getOrgId(), "orgLogo",
                        ClientUtils.getOrgLogoPath(), "className", ClientUtils.getClassName(), "classId",
                        ClientUtils.getClassId(), "orgShortName", ClientUtils.getOrgShortName()));
//        return this.loginValidate(user, 1, request, response, "study", platForm, organizationId);
    }
 
    /**
     * ºǫ́µÇ¼
     *
     * @param account  ÕË»§
     * @param password ÃÜÂë
     * @return
     */
    @ApiOperation(value = "µÇÈë½Ó¿Ú", notes = "")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "account", value = "Õ˺Å", required = true, paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "password", value = "ÃÜÂë", required = true, paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "organizationId", value = "»ú¹¹id", required = true, paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "platForm", value = "µÇÈëÆ½Ì¨£¨app£¬web£¬qLive£¬pc£¬weixin£©", required = true, paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "logType", value = "µÇÈëtype£¨studyѧԱ£¬teacher½Ìʦ,·ñÔòΪºǫ́£©", required = true, paramType="query", dataType = "String"),
    })
    @RequestMapping(value = "platformLogin", method = RequestMethod.POST)
    @ResponseBody
    public Result platformLogin(@RequestParam("account") String account, @RequestParam("password") String password,String uuNumber,String uuReNumber,
                                HttpServletRequest request, HttpServletResponse response, String logType,String organizationId, String platForm) {
//        response.setHeader("Access-Control-Allow-Origin", "*");
        if(StringUtils.isEmpty(account)) {
            return new Result(false, "Óû§Õ˺Ų»ÄÜΪ¿Õ");
        }
//        System.out.println(account+password);
//        System.out.println("-------------------------"+organizationId+"--------------"+platForm+"-----------"+logType);
        String hql = null;
        List<Object> params = null;
//        boolean flag=true;
        if("study".equals(logType)){
            hql = "from User where deleteFlag is false and account = ? and password = ? ";
            params =  CollectionUtils.newList(account,password);
        }else{
            if(StringUtils.isEmpty(password)) {
                return new Result(false, "Óû§ÃÜÂë²»ÄÜΪ¿Õ");
            }
            hql = "from User where deleteFlag is false and account = ? and password = ? ";
            params =  CollectionUtils.newList(account,password);
        }
 
        if(StringUtils.isNotEmpty(organizationId)){
            hql = hql.concat(" and organizationId=? ");
            params.add(organizationId);
        }
 
        // ²éѯÓû§ÐÅÏ¢
        User user = commonDAO.findUnique(hql,params, User.class);
 
        if(uuNumber!=null&&!"".equals(uuNumber)&&!"null".equals(uuNumber)){
            //µÇ¼³É¹¦´æÈëuserÀɾ³ýsessionÀïµÄuuNumber£¬Ï¸öÈËÎÞ·¨Ê¹ÓÃ
            user.setEmail(uuNumber);
//            request.getSession().removeAttribute("uuNumber");
        }
//        if(uuReNumber!=null&&!"".equals(uuReNumber)&&!"null".equals(uuReNumber)){
//            //µÇ¼³É¹¦´æÈëuserÀɾ³ýsessionÀïµÄuuReNumber£¬Ï¸öÈËÎÞ·¨Ê¹ÓÃ
//            user.setImei(uuReNumber);
//            request.getSession().removeAttribute("uuReNumber");
//        }
 
        // ²åÈëÈÕÖ¾
        insertLoginLog(request, user, account, "SYS-LOGIN");
 
        //¿¼ÊԵǼ»á¿ØÖÆflag±äÁ¿ ÆäËûµÇ¼²»»á Ä¬ÈÏtrue
        if (user == null) {
            return new Result(false, "Óû§ÕË»§¡¢ÃÜÂë´íÎó»òȱÉÙÆ¾Ö¤");
        }
 
        // ·µ»ØÓû§»ù±¾ÐÅÏ¢
        return this.loginValidate(user, 1, request, response, logType, platForm, organizationId);
    }
 
    /**
     * µÇÈëÑéÖ¤
     * @param user
     * @param type
     * @param request
     * @param response
     * @param logType
     * @param platForm
     * @param organizationId
     * @return
     */
    private Result loginValidate(User user, int type, HttpServletRequest request, HttpServletResponse response,
            String logType, String platForm, String organizationId) {
        HttpSession session = request.getSession();
        // »º´æÓû§ÐÅÏ¢
        CacheParamters param = new CacheParamters();
        param.setUserId(user.getUserId());
        param.setCustomRoleValue(user.getEmail());
        param.setCustomOrgId(user.getImei());
        param.setCacheIpFlag(true);
        param.setPlatForm(StringUtils.isEmpty(platForm) ? Constants.LOGIN_PLATFORM_WEB : platForm);
        param.setIp(RequestClientUtils.getRemoteIP(request));
//         »º´æµ½ÇëÇóÏß³Ì
        UserInfoWrapper wrapper = cacheUserInfo(param, null);
        // ´æµ½redis
        redisTemplate.opsForValue().set(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper);
        request.getSession().setAttribute(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper);
        if ("study".equals(logType)) {
            /*if (StringUtils.isEmpty(ClientUtils.getClassId()) && user.getRoles() == null) {
                return new Result(false, "¸ÃÓû§Î´¼ÓÈëÈκΰ༶»òδ¼¤»î£¬ÇëÁªÏµ°àÖ÷ÈÎ");
            }*/
 
            if (StringUtils.isEmpty(user.getOrganizationId())) {
                return new Result(false, "¸ÃÓû§²»ÊôÓÚÈκλú¹¹£¬ÎÞ·¨µÇÈë");
            }
            if (StringUtils.isNoneBlank(organizationId) && !user.getOrganizationId().equals(organizationId)) {
                return new Result(false, "Ñ¡ÔñµÄ»ú¹¹´íÎó£¬ÇëÈ·ÈÏ");
            }
 
            //ÅжÏÊÇ·ñΪѧÉú£¬Èç¹ûÊÇѧÉú£¬ÅжÏÊÇ·ñÒѶ³½á»òÒÆ³ý£¬¶³½á»òÒÆ³ýµÄѧÉú²»ÈõǼ
            StuStudent stu = this.studentService.getStudentByUserId(user.getUserId());
            if(stu!=null && (stu.getDeleteFlag() || stu.getStatus().equalsIgnoreCase(StuStudent.STATUS_DEACTIVE))){
                return new Result(false, "Óû§ÕË»§ÒѾ­±»¶³½á»òÒÆ³ý");
            }
 
            /*if(StringUtils.isEmpty(wrapper.getInfo(UserInfoWrapper.INF_CLASS_ID))) {
                return new Result(false, "¸ÃÓû§Î´¼ÓÈëÈκΰ༶£¬ÎÞ·¨µÇÈë");
            }*/
            // ±£´æµ½sessionÖÐ
            return new Result(true, "success",
                    CollectionUtils.newObjectMap("userId", user.getUserId(), "userName", user.getName(), "imgPath",
                            user.getImgPath(), "orgName", ClientUtils.getOrgName(),"orgId", ClientUtils.getOrgId(), "orgLogo",
                                ClientUtils.getOrgLogoPath(), "className", ClientUtils.getClassName(), "classId",
                            ClientUtils.getClassId(), "orgShortName", ClientUtils.getOrgShortName()));
        }else if("teacher".equals(logType)) {
            String teacherId = teacherService.getTeacherIdByUserId(user.getUserId());
            if (StringUtils.isEmpty(teacherId)) {
                return new Result(false, "¸ÃÕË»§²»ÊÇÀÏʦ½ÇÉ«£¬ÎÞ·¨µÇÈë");
            }
            if (StringUtils.isEmpty(user.getOrganizationId())) {
                return new Result(false, "¸ÃÓû§²»ÊôÓÚÈκλú¹¹£¬ÎÞ·¨µÇÈë");
            }
            if (StringUtils.isNoneBlank(organizationId) && !user.getOrganizationId().equals(organizationId)) {
                return new Result(false, "Ñ¡ÔñµÄ»ú¹¹´íÎó£¬ÇëÈ·ÈÏ");
            }
 
            //»ñÈ¡Óû§¶ÔÓ¦µÄsessionIdÊÇ·ñÓë±£´æÔÚredisÖеÄÒ»Ö£¬Èç¹û²»Ò»ÖÂÔòÌø×ªµ½µÇÂ¼Ò³Ãæ
//            stringRedisTemplate.opsForHash().put(UserInfoWrapper.REDIS_USER_ONLINE_MAP_KEY, user.getUserId(), request.getSession().getId());
            return new Result(true, "success",
                    CollectionUtils.newObjectMap("userId", user.getUserId(), "userName", user.getName(), "imgPath",
                            user.getImgPath(), "orgName", ClientUtils.getOrgName(),"orgId", ClientUtils.getOrgId(), "orgLogo", ClientUtils.getOrgLogoPath(), "orgShortName", ClientUtils.getOrgShortName()));
        }else {
            Result result = privilegeService.getMenus(user);
            Integer roleType = result.getDataT("roleType");
 
            // ±£´æ¹ÜÀíÔ±ÌØÊâ½ÇÉ«ÐÅÏ¢
            if (UserRole.ROLE_TYPE_ADMIN.equals(roleType)) {
//                boolean a=true;
//                wrapper.setAdmin(true);
                session.setAttribute("admin",true);
//                System.out.println(session.getAttribute("admin"));
            }
//            request.getSession().setAttribute(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper);
//            System.out.println("ccc"+wrapper.getInfo(UserInfoWrapper.INF_USER_ID));
////            request.getSession().setAttribute("userId", user.getUserId());
//            System.out.println("sess"+request.getSession().getAttribute("userId"));
//            System.out.println("aaa"+ClientUtils.getUserId());
            return result;
        }
 
    }
 
    /**
     * ºǫ́£ºÍ˳öµÇ¼,ºǫ́ϵͳ
     *
     * @param account ÕË»§
     * @return
     */
    @ApiOperation(value = "Í˳öºǫ́ϵͳ²Ù×÷", notes = "")
    @RequestMapping(value = "release", method = RequestMethod.GET)
    public String release(HttpServletRequest httpRequest, HttpServletResponse response) {
        doRelease(httpRequest, response);
        return "redirect:/web/admin/index.html#login";
    }
 
    /**
     * ºǫ́£ºÍ˳öµÇ¼,ºǫ́ϵͳ
     *
     * @return
     */
    @ApiOperation(value = "Í˳öappϵͳ²Ù×÷", notes = "")
    @RequestMapping(value = "loginOut", method = RequestMethod.GET)
    public @ResponseBody Result loginOut(HttpServletRequest httpRequest, HttpServletResponse response) {
        doRelease(httpRequest, response);
        return new Result(true);
    }
 
    /**
     * »º´æÓû§ÐÅÏ¢(°àÖ÷ÈΠ¡¢ Ñ§Ô± ½ÇÉ« »º´æºǫ́clientUtilsÐÅÏ¢)
     *
     * @param userId
     * @param cookieValue
     * @param request
     * @param charderClassId
     * @param sutdentClassId
     * @param adminOrgId
     * @param teacherClassId
     * @param customOrgId
     */
    private UserInfoWrapper cacheUserInfo(CacheParamters param, UserRole role) {
        UserInfoWrapper wrapper = userService.initUserInfoWrapper(param, true);
        service.addClientInfo(wrapper);
        return wrapper;
    }
 
    /**
     * ²åÈëµÇ¼ÈÕÖ¾
     *
     * @param request
     * @param lstUser
     * @param account
     * @param module
     */
    private void insertLoginLog(HttpServletRequest request, User user, String account, String module) {
 
        String userAgent = request.getHeader("user-agent");
        String userId = user == null? null : user.getUserId();
        String userName = user == null ? null : user.getName();
        String ip = RequestClientUtils.getRemoteIP(request);
        SysLog lg = new SysLog();
 
        TraceUtils.setCreateActiveTrace(lg);
        lg.setDeleteFlag(false);
        lg.setContent(userAgent);
        lg.setDesp(account);
        lg.setIp(ip);
        lg.setModule(module);
        lg.setType(SysLog.LOG_TYPE_SYS);
        lg.setUserId(userId);
        lg.setUserName(userName);
 
        commonService.save(lg);
 
    }
 
    /**
     * Í˳öºǫ́ϵͳ²Ù×÷
     *
     * @param account ÕË»§
     * @return
     */
    private void doRelease(HttpServletRequest httpRequest, HttpServletResponse response) {
        HttpSession se = httpRequest.getSession();
        se.removeAttribute(UserInfoWrapper.SESSION_USER_INFO_KEY);
        redisTemplate.delete(UserInfoWrapper.SESSION_USER_INFO_KEY);
        se.invalidate();
    }
 
    /**
     * Óû§ÐÞ¸ÄÃÜÂë
     */
    @ApiOperation(value = "ÐÞ¸ÄÃÜÂë", notes = "")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "usedPass", value = "ÀÏÃÜÂë", required = false, paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "pass", value = "ÐÂÃÜÂë", required = false, paramType="query", dataType = "String"),
    })
    @RequestMapping(value = "updatePassword", method = RequestMethod.POST)
    @ResponseBody
    public Result updatePassword(String userId, String usedPass, String pass) {
        return userService.updatePassword(StringUtils.isEmpty(userId)?ClientUtils.getUserId():userId, usedPass, pass);
    }
 
    /**
     * »ñÈ¡µ±Ç°Óû§
     */
    @ApiOperation(value = "»ñÈ¡µ±Ç°Óû§", notes = "")
    @RequestMapping(value = "getCurrUser", method = RequestMethod.POST)
    @ResponseBody
    public Result getCurrUser() {
        User u = this.commonDAO.read(User.class, ClientUtils.getUserId());
 
        return new Result(true, "success", CollectionUtils.newObjectMap("name",u.getName(),"account",
                u.getAccount(), "mobilePhone", u.getMobilePhone(), "imgPath", u.getImgPath(), "sex", u.getSex()));
    }
 
    /**
     * »ñÈ¡µ±Ç°Óû§
     */
    @ApiOperation(value = "»ñÈ¡µ±Ç°½ÌʦÐÅÏ¢", notes = "")
    @RequestMapping(value = "getCurrTeacher", method = RequestMethod.GET)
    @ResponseBody
    public Result getCurrTeacher() {
        return this.teacherService.getTeacherInfo();
    }
 
    /**
     * Óû§ÐÞ¸ÄÃÜÂë
     */
    @ApiOperation(value = "ÐÞ¸ÄÍ·Ïñ", notes = "")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "headPath", value = "Í·ÏñµØÖ·", required = false, paramType="query", dataType = "String"),
    })
    @RequestMapping(value = "updateUserHead", method = RequestMethod.POST)
    @ResponseBody
    public Result updateUserHead(String headPath) {
        return userService.updateUserHead(ClientUtils.getUserId(), headPath);
    }
 
    /**
     * ÐÞ¸ÄÓû§ÆäËûÊý¾Ý
     */
    @ApiOperation(value = "ÐÞ¸ÄÓû§ÆäËûÊý¾Ý", notes = "")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "mobilePhone", value = "ÀÏÃÜÂë", required = false, paramType="query", dataType = "String"),
    })
    @RequestMapping(value = "updateUserInfo", method = RequestMethod.POST)
    @ResponseBody
    public Result updateUserInfo(String mobilePhone) {
        return userService.updateUserInfo(ClientUtils.getUserId(), mobilePhone);
    }
 
    /**
     * »ñȡϵͳµ±Ç°Ê±¼ä
     */
    @RequestMapping(value = "currentTime", method = RequestMethod.GET)
    @ResponseBody
    public long getCurrentTime() {
        return System.currentTimeMillis();
    }
 
    @ApiOperation(value = "»ñÈ¡»ú¹¹Áбí", notes = "")
    @RequestMapping(value = "getOrgLst", method = RequestMethod.GET)
    @ResponseBody
    public Result getOrgLst() {
        List<Map<String, Object>> orgLst = organizationService.getOrgLst();
        return new Result(true, "success", orgLst);
    }
 
    @ApiOperation(value = "»ñÈ¡»ú¹¹µÄÐÅÏ¢", notes = "°üº¬»ù±¾ÐÅÏ¢ºÍbannerͼºÍappÐÅÏ¢")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "appCode", value = "appcode£¨android£ºandroidTeacherApp£¬androidTeacherH5£¬androidStudentApp£¬ androidStudentH5"
                + "IOS:IosTeacherApp,IosStudentApp£©", required = false, paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "orgId", value = "»ú¹¹id", required = false, paramType="query", dataType = "String")
    })
    @RequestMapping(value = "getOrgInfo", method = RequestMethod.GET)
    @ResponseBody
    public Result getOrgInfo(String appCode, String orgId) {
        return this.organizationService.getOrgInfo(appCode, orgId);
    }
 
    /**
     * APP2.0:  »ñÈ¡android APP°æ±¾
     *
     * @return|
     */
    @ApiOperation(value = "»ñÈ¡android APP°æ±¾")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "appName", value = "appÃû³Æ£¨android£ºteacherApp£¬teacherH5£¬studentApp£¬ studentH5£©", required = false, paramType="query", dataType = "String"),
    })
    @RequestMapping(value="getAndroidAppVersion",method=RequestMethod.GET)
    public @ResponseBody Result getAppVersion(String appName) {
 
        // °æ±¾ºÅ
        String versionName = "";
        String versionTips = "";
        String versionCode = "";
        String downloadUrl = "";
 
        if("teacherApp".equals(appName)) {
            versionName = commonDAO.queryConfigValue("android_teacher_app_name");
            versionTips = commonDAO.queryConfigValue("android_teacher_app_tips");
            versionCode = commonDAO.queryConfigValue("android_teacher_app_code");
            downloadUrl = commonDAO.queryConfigValue("android_teacher_app_download_url");
        }else if("teacherH5".equals(appName)){
            versionName = commonDAO.queryConfigValue("android_teacher_h5_name");
            versionTips = commonDAO.queryConfigValue("android_teacher_h5_tips");
            versionCode = commonDAO.queryConfigValue("android_teacher_h5_code");
            downloadUrl = commonDAO.queryConfigValue("android_teacher_h5_download_url");
        }else if("studentApp".equals(appName)){
            versionName = commonDAO.queryConfigValue("android_student_app_name");
            versionTips = commonDAO.queryConfigValue("android_student_app_tips");
            versionCode = commonDAO.queryConfigValue("android_student_app_code");
            downloadUrl = commonDAO.queryConfigValue("android_student_app_download_url");
        }else if("studentH5".equals(appName)){
            versionName = commonDAO.queryConfigValue("android_student_h5_name");
            versionTips = commonDAO.queryConfigValue("android_student_h5_tips");
            versionCode = commonDAO.queryConfigValue("android_student_h5_code");
            downloadUrl = commonDAO.queryConfigValue("android_student_h5_download_url");
        }else {
            versionName = commonDAO.queryConfigValue(Constants.CONFIG_ANDROID_APP_VERSION);
            versionTips = commonDAO.queryConfigValue(Constants.CONFIG_APP_VERSION_TIPS);
            versionCode = commonDAO.queryConfigValue(Constants.CONFIG_ANDROID_APP_VERSION_CODE);
            downloadUrl = commonDAO.queryConfigValue(Constants.CONFIG_ANDROID_APP_DOWNLOAD_URL);
        }
 
        return new Result(true, "", CollectionUtils.newObjectMap("versionName", versionName, "versionCode", versionCode, "versionTips", versionTips, "downloadUrl", downloadUrl));
    }
 
 
    /**
     * APP2.0:  »ñÈ¡ios APP°æ±¾
     *
     * @return
     */
    @ApiOperation(value = "»ñÈ¡ios APP°æ±¾")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "appName", value = "appÃû³Æ£¨ios£ºteacherApp£¬studentApp£©", required = false, paramType="query", dataType = "String"),
    })
    @RequestMapping(value="getIosAppVersion",method=RequestMethod.GET)
    public @ResponseBody Result getIOSAppVersion(String appName) {
        // °æ±¾ºÅ
        String versionCode = "";
        String versionNo = "";
        String versionTips = "";
        String downloadUrl = "";
 
        if("teacherApp".equals(appName)) {
            versionCode = commonDAO.queryConfigValue("ios_teacher_app_code");
            versionNo = commonDAO.queryConfigValue("ios_teacher_app_no");
            versionTips = commonDAO.queryConfigValue("ios_teacher_app_tips");
            downloadUrl = commonDAO.queryConfigValue("ios_teacher_app_download_url");
        }else{
            versionCode = commonDAO.queryConfigValue("ios_student_app_code");
            versionNo = commonDAO.queryConfigValue("ios_student_app_no");
            versionTips = commonDAO.queryConfigValue("ios_student_app_tips");
            downloadUrl = commonDAO.queryConfigValue("ios_student_app_download_url");
        }
 
        return new Result(true, "", CollectionUtils.newObjectMap("versionCode", versionCode, "versionNo", versionNo, "versionTips", versionTips, "downloadUrl", downloadUrl));
    }
 
    /**
     * APP2.0:  »ñÈ¡ios °æ±¾
     *
     * @return
     */
    @ApiOperation(value = "»ñÈ¡ios²Ëµ¥")
    @RequestMapping(value="getIosMenu",method=RequestMethod.GET)
    public @ResponseBody Result getIOSAppVersion() {
        //"¿Î¼þ","¿¼ÊÔ","×÷Òµ","Ö±²¥"
        return new Result(true, "", new String[]{"¿Î¼þ","Ö±²¥","¿¼ÊÔ","×÷Òµ"});
    }
 
 
}