chenjiahe
2021-11-09 2f5b030b8510c7cbf6ef71d6d3f4be2fbf0e3202
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
package com.hx.phip.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hx.common.BaseController;
import com.hx.mp.util.MPWeixinBaseUtil;
import com.hx.mybatisTool.SqlSentence;
import com.hx.phiappt.model.*;
import com.hx.phip.common.wx.corp.WeiXinCorpMpUtil;
import com.hx.phip.dao.mapper.*;
import com.hx.phip.entity.EmployeeQrLogin;
import com.hx.phip.entity.EmployeeRoleLogin;
import com.hx.phip.model.ApplyParameter;
import com.hx.phip.model.SysParameter;
import com.hx.phip.tool.ApplyParameterTool;
import com.hx.redis.RedisUtil;
import com.hx.util.AesUtil;
import com.hx.util.HttpServletRequestUtil;
import com.hx.util.JwtTool;
import com.hx.util.StringUtils;
import com.hx.util.corp.CorpMpUtil;
import com.hx.util.corp.entity.OpenIdAUserId;
import com.hx.util.corp.entity.WeiXinInfo;
import com.platform.exception.PlatTipsException;
import com.platform.resultTool.PlatformCode;
import com.platform.resultTool.PlatformResult;
import com.platform.resultTool.SystemCode;
import com.platform.util.corp.PersonnelTool;
import com.platform.util.corp.entity.PersonnelQr;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 公共平台登录接口
 *
 * @USER: wangrenhuang
 * @DATE: 2021/10/14
 **/
@RestController
@RequestMapping("/employee")
public class EmployeeLoginController extends BaseController {
 
    //log4j日志
    private static Logger logger = LoggerFactory.getLogger(EmployeeLoginController.class.getName());
    @Resource
    private RedisUtil redisUtil;
 
    /**有效时间(秒)*/
    private static final long ttlMillis = 42300;
 
    /**企业员工-扫码登录
     */
    @RequestMapping(value = "/login/qr",method = RequestMethod.POST)
    public PlatformResult loginQr(HttpServletRequest request) {
 
        //获取返回参数
        String bodydata = HttpServletRequestUtil.getBody(request);
        if(StringUtils.isEmpty(bodydata)){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
        EmployeeQrLogin employeeQrLogin = null;
        try{
            employeeQrLogin = JSONObject.parseObject(bodydata,EmployeeQrLogin.class);
        }catch (Exception e){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
 
        if(employeeQrLogin == null){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
 
        if (StringUtils.isEmpty(employeeQrLogin.getCode())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"code is required");
        }
 
        if (StringUtils.isEmpty(employeeQrLogin.getCorpId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"corpId is required");
        }
 
        if (StringUtils.isEmpty(employeeQrLogin.getMpId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"mpId is required");
        }
 
        //获取应用数据
        ApplyParameter applyParameter = ApplyParameterTool.getApplyParameter(employeeQrLogin.getCorpId(),employeeQrLogin.getMpId(),commonService);
        if(applyParameter == null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"corpId or mpId is error");
        }
 
        //获取token
        SysParameter sysParameter = WeiXinCorpMpUtil.getApplicationAccessToken(commonService,applyParameter.getCorpId(), AesUtil.aesDecryp(applyParameter.getApplySecretKey()));
        if(sysParameter == null){
            throw new PlatTipsException(PlatformCode.ERROR_SYSTEM,"服务错误"+ SystemCode.ERROR_GET_CORP_TOKEN);
        }
 
       //解析code
        PersonnelQr personnelQr = PersonnelTool.qrLoginInfo(sysParameter.getParamValue(),employeeQrLogin.getCode());
 
        logger.info("扫码登录:"+personnelQr.toString());
 
        if(personnelQr == null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"人员信息不存在");
        }
 
        if(!"0".equals(personnelQr.getErrcode())){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"人员信息信息异常");
        }
        String userId = personnelQr.getPersonnelQrInfo().getUserid();
 
        if (StringUtils.isEmpty(userId)) {
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"人员没有权限登录");
        }
 
        // 查询企业微信员工是否离职
        WeiXinInfo weiXinInfo = CorpMpUtil.userInfo(userId, sysParameter.getParamValue());
        if (weiXinInfo == null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该员工不存在企业微信");
        }
        if (1 != weiXinInfo.getStatus()){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该员工在企业微信中已离职");
        }
 
        SqlSentence sqlSentence = new SqlSentence();
        Map<String, Object> values = new HashMap<>();
        sqlSentence.setM(values);
        values.put("userId", userId);
        sqlSentence.setSqlSentence(" select * from employee where userId = #{m.userId} and isDel = 0 ");
        List<Employee> employees = commonService.selectList(EmployeeMapper.class,sqlSentence);
        if(employees.size() > 1){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该人员信息存在多个");
        }else if(employees.size() <= 0){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该人员不存在");
        }
 
        Employee employee = employees.get(0);
        if(employee.getIsJob() != Employee.YES){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该人员已离职");
        }
 
        values.clear();
        values.put("employeeId",employee.getId());
        values.put("isDel",EmployeeRole.NO);
        sqlSentence.setSqlSentence(" select o.id,ert.id AS roleTypeId,ert.name,ert.uniqueStr,s.id AS shopId,s.name AS shopName from employee_role o JOIN employee_role_type ert ON ert.isDel = 0" +
                " AND ert.id = o.roleTypeId LEFT JOIN shop s ON s.id = o.shopId WHERE o.employeeId = #{m.employeeId} AND o.isDel = #{m.isDel}");
        List<Map<String,Object>> roleList = commonService.selectListMap(EmployeeRoleTypeMapper.class,sqlSentence);
 
        Map<String,Object> data = new HashMap<>();
        data.put("roleList", roleList);
        data.put("preId", employee.getId());
        data.put("cnName", employee.getCnName());
        data.put("enName", employee.getEnName());
        data.put("tel", employee.getTel());
        data.put("email", employee.getEmail());
        data.put("imgUrl", employee.getImgUrl());
        data.put("gender", employee.getGender());
        data.put("loginToken", JwtTool.createJWT(employee.getId(), null, ttlMillis));
 
        JSONObject redisObj = new JSONObject();
        redisObj.put("id",employee.getId());
        redisObj.put("cnName",employee.getCnName());
        redisObj.put("enName",employee.getEnName());
        redisObj.put("userId",employee.getUserId());
 
        redisUtil.set(employee.getId(),redisObj,ttlMillis);
        return PlatformResult.success(data);
    }
 
    /**企业员工-网页登录(企业小程序)
     * @param request
     * @return
     */
    @RequestMapping(value = "/login/webpage",method = RequestMethod.POST)
    public PlatformResult loginWebpage(HttpServletRequest request) {
 
        //获取返回参数
        String bodydata = HttpServletRequestUtil.getBody(request);
        if(StringUtils.isEmpty(bodydata)){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
        EmployeeQrLogin employeeQrLogin = null;
        try{
            employeeQrLogin = JSONObject.parseObject(bodydata,EmployeeQrLogin.class);
        }catch (Exception e){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
 
        if(employeeQrLogin == null){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
 
        if (StringUtils.isEmpty(employeeQrLogin.getCode())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"code is required");
        }
 
        if (StringUtils.isEmpty(employeeQrLogin.getCorpId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"corpId is required");
        }
 
        if (StringUtils.isEmpty(employeeQrLogin.getMpId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"mpId is required");
        }
 
        //获取应用数据
        ApplyParameter applyParameter = ApplyParameterTool.getApplyParameter(employeeQrLogin.getCorpId(),employeeQrLogin.getMpId(),commonService);
        if(applyParameter == null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"corpId or mpId is error");
        }
 
        //获取token
        SysParameter sysParameter = WeiXinCorpMpUtil.getApplicationAccessToken(commonService,applyParameter.getCorpId(),AesUtil.aesDecryp(applyParameter.getApplySecretKey()));
        if(sysParameter == null){
            throw new PlatTipsException(PlatformCode.ERROR_SYSTEM,"服务错误"+ SystemCode.ERROR_GET_CORP_TOKEN);
        }
 
 
        //获取userId
        net.sf.json.JSONObject oauthObj = com.hx.mp.util.CorpMpUtil.code2Session(sysParameter.getParamValue(),employeeQrLogin.getCode());
        //String errcode = oauthObj.optString("errcode", "");// 有错误的时候才有
       // String corpId = oauthObj.optString("corpid", "");// 有错误的时候才有
        String userId = oauthObj.optString("userid", "");
       // String sessionKey = oauthObj.optString("session_key");
 
        logger.info("网页登录:"+oauthObj.toString());
 
        if (StringUtils.isEmpty(userId)) {
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"人员没有权限登录");
        }
 
        // 查询企业微信员工是否离职
        WeiXinInfo weiXinInfo = CorpMpUtil.userInfo(userId, sysParameter.getParamValue());
        if (weiXinInfo == null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该员工不存在企业微信");
        }
        if (1 != weiXinInfo.getStatus()){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该员工在企业微信中已离职");
        }
 
        SqlSentence sqlSentence = new SqlSentence();
        Map<String, Object> values = new HashMap<>();
        sqlSentence.setM(values);
        values.put("userId", userId);
        sqlSentence.setSqlSentence(" select * from employee where userId = #{m.userId} and isDel = 0 ");
        List<Employee> employees = commonService.selectList(EmployeeMapper.class,sqlSentence);
        if(employees.size() > 1){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该人员信息存在多个");
        }else if(employees.size() <= 0){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该人员不存在");
        }
 
        Employee employee = employees.get(0);
        if(employee.getIsJob() != Employee.YES){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该人员已离职");
        }
 
        values.clear();
        values.put("employeeId",employee.getId());
        values.put("isDel",EmployeeRole.NO);
        sqlSentence.setSqlSentence(" select o.id,ert.id AS roleTypeId,ert.name,ert.uniqueStr,s.id AS shopId,s.name AS shopName from employee_role o JOIN employee_role_type ert ON ert.isDel = 0" +
                " AND ert.id = o.roleTypeId LEFT JOIN shop s ON s.id = o.shopId WHERE o.employeeId = #{m.employeeId} AND o.isDel = #{m.isDel}");
        List<Map<String,Object>> roleList = commonService.selectListMap(EmployeeRoleTypeMapper.class,sqlSentence);
 
        Map<String,Object> data = new HashMap<>();
        data.put("roleList", roleList);
        data.put("preId", employee.getId());
        data.put("cnName", employee.getCnName());
        data.put("enName", employee.getEnName());
        data.put("tel", employee.getTel());
        data.put("email", employee.getEmail());
        data.put("imgUrl", employee.getImgUrl());
        data.put("gender", employee.getGender());
        data.put("loginToken", JwtTool.createJWT(employee.getId(), null, ttlMillis));
 
        JSONObject redisObj = new JSONObject();
        redisObj.put("id",employee.getId());
        redisObj.put("cnName",employee.getCnName());
        redisObj.put("enName",employee.getEnName());
        redisObj.put("userId",employee.getUserId());
 
        redisUtil.set(employee.getId(),redisObj,ttlMillis);
 
        return PlatformResult.success(data);
    }
 
    /**企业员工-网页登录(普通小程序)
     * 普通小程序登录
     * @param request
     * @return
     */
    @RequestMapping(value = "/login/mp/webpage",method = RequestMethod.POST)
    public PlatformResult loginMpWebpage(HttpServletRequest request) {
 
        //获取返回参数
        String bodydata = HttpServletRequestUtil.getBody(request);
        if(StringUtils.isEmpty(bodydata)){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
        EmployeeQrLogin employeeQrLogin = null;
        try{
            employeeQrLogin = JSONObject.parseObject(bodydata,EmployeeQrLogin.class);
        }catch (Exception e){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
 
        if(employeeQrLogin == null){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
 
        if (StringUtils.isEmpty(employeeQrLogin.getCode())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"code is required");
        }
 
        if (StringUtils.isEmpty(employeeQrLogin.getCorpId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"corpId is required");
        }
 
        if (StringUtils.isEmpty(employeeQrLogin.getMpId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"mpId is required");
        }
 
        //获取应用数据
        ApplyParameter applyParameter = ApplyParameterTool.getApplyParameter(employeeQrLogin.getCorpId(),employeeQrLogin.getMpId(),commonService);
        if(applyParameter == null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"corpId or mpId is error");
        }
 
        //获取openId
        net.sf.json.JSONObject oauthObj = MPWeixinBaseUtil.getJscode2session(applyParameter.getMpAppId(),AesUtil.aesDecryp(applyParameter.getMpSecretKey()),employeeQrLogin.getCode());
        String errcode = oauthObj.optString("errcode", "");// 有错误的时候才有
        String openId = oauthObj.optString("openid", "");
        //String session_key = oauthObj.optString("session_key");
        //String unionid = oauthObj.optString("unionid", "");
 
        if(StringUtils.noNull(errcode)){
            logger.error("企业员工-网页登录(普通小程序):"+oauthObj.toString());
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"解析code获取用户信息失败");
        }
 
        //获取token
        SysParameter sysParameter = WeiXinCorpMpUtil.getApplicationAccessToken(commonService,applyParameter.getCorpId(),AesUtil.aesDecryp(applyParameter.getApplySecretKey()));
        if(sysParameter == null){
            throw new PlatTipsException(PlatformCode.ERROR_SYSTEM,"服务错误"+ SystemCode.ERROR_GET_CORP_TOKEN);
        }
 
        //openId转userId
        OpenIdAUserId openIdAUserId =  CorpMpUtil.openIdToUserId(openId,sysParameter.getParamValue());
        if(openIdAUserId.getErrcode() != 0){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,openIdAUserId.getErrmsg());
        }
 
        if (StringUtils.isEmpty(openIdAUserId.getUserid())) {
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"人员没有权限登录");
        }
 
        // 查询企业微信员工是否离职
        WeiXinInfo weiXinInfo = CorpMpUtil.userInfo(openIdAUserId.getUserid(), sysParameter.getParamValue());
        if (weiXinInfo == null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该员工不存在企业微信");
        }
        if (1 != weiXinInfo.getStatus()){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该员工在企业微信中已离职");
        }
 
        SqlSentence sqlSentence = new SqlSentence();
        Map<String, Object> values = new HashMap<>();
        sqlSentence.setM(values);
        values.put("userId", openIdAUserId.getUserid());
        sqlSentence.setSqlSentence(" select * from employee where userId = #{m.userId} and isDel = 0 ");
        List<Employee> employees = commonService.selectList(EmployeeMapper.class,sqlSentence);
        if(employees.size() > 1){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该人员信息存在多个");
        }else if(employees.size() <= 0){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该人员不存在");
        }
 
        Employee employee = employees.get(0);
        if(employee.getIsJob() != Employee.YES){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该人员已离职");
        }
 
        values.clear();
        values.put("employeeId",employee.getId());
        values.put("isDel",EmployeeRole.NO);
        sqlSentence.setSqlSentence(" select o.id,ert.id AS roleTypeId,ert.name,ert.uniqueStr,s.id AS shopId,s.name AS shopName from employee_role o JOIN employee_role_type ert ON ert.isDel = 0" +
                " AND ert.id = o.roleTypeId LEFT JOIN shop s ON s.id = o.shopId WHERE o.employeeId = #{m.employeeId} AND o.isDel = #{m.isDel}");
        List<Map<String,Object>> roleList = commonService.selectListMap(EmployeeRoleTypeMapper.class,sqlSentence);
 
        Map<String,Object> data = new HashMap<>();
        data.put("roleList", roleList);
        data.put("preId", employee.getId());
        data.put("cnName", employee.getCnName());
        data.put("enName", employee.getEnName());
        data.put("tel", employee.getTel());
        data.put("email", employee.getEmail());
        data.put("imgUrl", employee.getImgUrl());
        data.put("gender", employee.getGender());
        data.put("loginToken", JwtTool.createJWT(employee.getId(), null, ttlMillis));
 
        JSONObject redisObj = new JSONObject();
        redisObj.put("id",employee.getId());
        redisObj.put("cnName",employee.getCnName());
        redisObj.put("enName",employee.getEnName());
        redisObj.put("userId",employee.getUserId());
        redisUtil.set(employee.getId(),redisObj,ttlMillis);
 
        return PlatformResult.success(data);
    }
 
    /**选择登录角色*/
    @RequestMapping(value ="/login/role",method = RequestMethod.POST)
    public PlatformResult selectLoginRole(HttpServletRequest request) {
        String bodyData = HttpServletRequestUtil.getBody(request);
        if(StringUtils.isEmpty(bodyData)){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
        EmployeeRoleLogin employeeRoleLogin = null;
        try {
            employeeRoleLogin = JSONObject.parseObject(bodyData,EmployeeRoleLogin.class);
        }catch (Exception e){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
 
        if(employeeRoleLogin == null){
            throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误");
        }
 
        if(StringUtils.isEmpty(employeeRoleLogin.getRoleId())){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"Role ID is required");
        }
 
        if(StringUtils.isEmpty(employeeRoleLogin.getPreId())){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"Pre ID is required");
        }
 
        SqlSentence sqlSentence = new SqlSentence();
        Map<String, Object> values = new HashMap<>();
 
        values.put("roleId", employeeRoleLogin.getRoleId());
        values.put("employeeId", employeeRoleLogin.getPreId());
        sqlSentence.sqlSentence(" SELECT o.*,ert.name AS roleName FROM employee_role o JOIN employee_role_type ert ON ert.isDel = 0" +
                " AND ert.id = o.roleTypeId WHERE o.id = #{m.roleId} AND o.isDel = 0 AND o.employeeId = #{m.employeeId}",values);
        EmployeeRole employeeRole = commonService.selectOne(EmployeeRoleMapper.class,sqlSentence);
        if(employeeRole == null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"角色不存在");
        }
 
        EmployeeRoleType employeeRoleType = commonService.selectOneByKey(EmployeeRoleTypeMapper.class,employeeRole.getRoleTypeId());
        if(employeeRoleType == null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"角色信息有误!");
        }
        if(employeeRoleType.getIsUp() == EmployeeRoleType.NO){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"角色权限!");
        }
 
        values.clear();
        values.put("roleTypeId",employeeRole.getRoleTypeId());
        values.put("isDel", EmployeeRoleAdminAuthority.NO);
        sqlSentence.sqlSentence("SELECT saa.tag FROM emloyee_role_admin_authority o JOIN sys_admin_authority saa ON saa.isDel = #{m.isDel} AND saa.id = o.sysAdAuId WHERE o.roleTypeId = #{m.roleTypeId} AND o.isDel = #{m.isDel}",values);
        List<SysAdminAuthority> authList = commonService.selectList(SysAdminAuthorityMapper.class,sqlSentence);
 
        JSONArray arrAuth = new JSONArray();
        for(SysAdminAuthority sysAdminAuthority:authList){
            JSONObject objAuth = new JSONObject();
            objAuth.put("tag",sysAdminAuthority.getTag());
            arrAuth.add(objAuth);
        }
 
        JSONObject data = new JSONObject();
        data.put("loginToken", JwtTool.createJWT(employeeRole.getRoleTypeId(), null, ttlMillis));
        data.put("id", employeeRole.getId());
        data.put("preId", employeeRole.getEmployeeId());
        data.put("uniqueStr", employeeRole.getRoleUniqueStr());
        data.put("roleName", employeeRole.getRoleName());
        data.put("shopId", employeeRole.getShopId());
        Shop shop = commonService.selectOneByKey(ShopMapper.class,employeeRole.getShopId());
        if(shop != null){
            data.put("shopName",shop.getName());
        }
        data.put("authList", arrAuth);
 
        JSONObject redisObj = new JSONObject();
        redisObj.put("id",employeeRole.getId());
        redisObj.put("roleTypeId",employeeRole.getRoleTypeId());
        redisObj.put("roleName",employeeRole.getRoleName());
        redisObj.put("uniqueStr",employeeRole.getRoleUniqueStr());
        redisObj.put("preId",employeeRole.getEmployeeId());
        redisObj.put("arrAuth",arrAuth);
        redisObj.put("shopId",employeeRole.getShopId());
        if(shop != null){
            redisObj.put("shopName", shop.getName());
        }
 
        redisUtil.set(employeeRole.getId(),redisObj,ttlMillis);
        return PlatformResult.success(data);
    }
 
    @RequestMapping(value ="/test",method = RequestMethod.POST)
    public PlatformResult test(HttpServletRequest request){
        //redisUtil.set("222","44444444444");
        System.out.println(redisUtil.get("222"));
        return PlatformResult.success("2222222");
    }
 
}