luo
2023-12-25 23c4967b4cb8dbce8277f830f7152d315c5a4a57
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.JwtTokenUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.dao.AppUserMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.*;
import com.stylefeng.guns.modular.system.util.weChat.WXCore;
import com.stylefeng.guns.modular.system.util.weChat.WeChatUtil;
import com.stylefeng.guns.modular.system.warpper.req.*;
import com.stylefeng.guns.modular.system.warpper.res.*;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import sun.rmi.runtime.Log;
 
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author zhibing.pu
 * @Date 2023/11/7 11:07
 */
@Service
public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> implements IAppUserService {
 
    @Autowired
    private WeChatUtil weChatUtil;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private IRegionService regionService;
    @Autowired
    private IAppUserService appUserService;
    @Autowired
    private HouseResourceService houseResourceService;
    @Autowired
    private IHousingDemandService housingDemandService;
    @Autowired
    private CollectionHouseResourceServiceImpl collectionHouseResourceService;
    @Autowired
    private ICollectionHousingDemandService collectionHousingDemandService;
 
 
 
 
    /**
     * 通过token获取用户信息
     * @return
     */
    @Override
    public AppUser getAppUser() {
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = servletRequestAttributes.getRequest();
        String authorization = request.getHeader("Authorization");
        // todo 这里注释了一段代码
        // && authorization.contains("Bearer")
        if(ToolUtil.isNotEmpty(authorization) && authorization.contains("Bearer ") ){
            String token = authorization.substring(7);
            //通过token获取用户id
            Integer appUserId = getAppUserIdFromToken(token);
            return this.selectById(appUserId);
        }
        return null;
    }
 
 
 
 
 
 
    /**
     * 小程序登录
     * @return
     */
    @Override
    public ResultUtil<AppletLoginRes>
    appletLogin(RegisterAccountReq req) {
        try {
            //调用微信获取用户小程序openid
            Map<String, Object> map = weChatUtil.code2Session(req.getJscode());
            if(null == map){
                return ResultUtil.error("获取微信身份信息失败");
            }
            String openid = map.get("openid").toString();
            AppUser appUser = this.selectOne(new EntityWrapper<AppUser>()
                    .eq("wechat_openid", openid));
            if(null != appUser && appUser.getStatus() == 2){
                return ResultUtil.error("账号冻结");
            }
            AppletLoginRes appletLoginRes = new AppletLoginRes();
            // 当前微信号没有注册过
                if(null == appUser){
                    System.err.println("新增");
                    String sessionKey = map.get("sessionKey").toString();
                    //解密手机号
                    String phone = WXCore.decrypt(req.getEncryptedPhoneData(), sessionKey, req.getPhone_iv());
                    appUser = this.selectOne(new EntityWrapper<AppUser>()
                            .eq("phone", phone)
                            .eq("status", 1));
                        JSONObject jsonObject = JSONObject.parseObject(phone);
                        String phone1 = jsonObject.getString("phoneNumber");
                        System.err.println("看看json");
                        System.err.println(jsonObject);
                        System.err.println(phone1);
                        //注册新账号
                        appUser = addNewAppUser(openid, phone1);
                    }else{
                    String sessionKey = map.get("sessionKey").toString();
                    String phone = WXCore.decrypt(req.getEncryptedPhoneData(), sessionKey, req.getPhone_iv());
                    JSONObject jsonObject = JSONObject.parseObject(phone);
                    String phone1 = jsonObject.getString("phoneNumber");
                    appUser.setWechatOpenid(openid);
                    appUser.setPhone(phone1);
                    this.updateById(appUser);
                }
            //生成token
            String token = JwtTokenUtil.generateToken(appUser.getPhone());
 
            System.err.println("token1111--->" + token);
            appletLoginRes.setState(appUser.getAuth());
            appletLoginRes.setToken(token);
            appletLoginRes.setUserType(appUser.getUserType());
            System.err.println("看看TOKEN:"+token);
            //存入缓存中
            addTokenToRedis(token, appUser.getId());
            return ResultUtil.success(appletLoginRes);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 小程序注册账号
     * @param req
     * @return
     */
    @Override
    public ResultUtil<AppletLoginRes> registerAccount(RegisterAccountReq req) {
        try {
            //调用微信获取用户小程序openid
            Map<String, Object> map = weChatUtil.code2Session(req.getJscode());
            if(null == map){
                return ResultUtil.error("获取微信身份信息失败");
            }
            System.err.println("看看返回结果map");
            System.err.println(map);
            String openid = map.get("openid").toString();
            AppUser appUser = this.selectOne(new EntityWrapper<AppUser>()
                    .eq("wechat_openid", openid)
                    .ne("audit_status", 3)
                    .eq("status", 1));
            if(null != appUser && appUser.getAuditStatus() == 1){
                return ResultUtil.error("账号审核中");
            }
            AppletLoginRes appletLoginRes = new AppletLoginRes();
            if(null == appUser){
                String sessionKey = map.get("sessionKey").toString();
                //解密手机号
                String phone = WXCore.decrypt(req.getEncryptedPhoneData(), sessionKey, req.getPhone_iv());
                appUser = this.selectOne(new EntityWrapper<AppUser>()
                        .eq("phone", phone)
                        .eq("audit_status", 2)
                        .eq("status", 1));
                if(null == appUser){
                    JSONObject jsonObject = JSONObject.parseObject(phone);
                    String phone1 = jsonObject.getString("phoneNumber");
                    System.err.println("看看json");
                    System.err.println(jsonObject);
                    System.err.println(phone1);
                    //注册新账号
                    appUser = addNewAppUser(openid, phone1);
                }else{
                    appUser.setWechatOpenid(openid);
                    this.updateById(appUser);
                }
            }
            //生成token
            String token = JwtTokenUtil.generateToken(appUser.getPhone());
            appletLoginRes.setToken(token);
            appletLoginRes.setUserType(appUser.getUserType());
            //存入缓存中
            addTokenToRedis(token, appUser.getId());
            return ResultUtil.success(appletLoginRes);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
    @Override
    public SearchIntermediaryRes searchIntermediaryList(SearchIntermediaryReq req) {
        req.setPageNum((req.getPageNum() - 1) * req.getPageSize());
        //区域
        List<Integer> districtIds = new ArrayList<>();
        List<Integer> cityIds = new ArrayList<>();
        if (req.getDistrict() != null &&(!req.getDistrict().equals("")) ){
            // 一级id
            Integer integer = Integer.valueOf(req.getDistrict());
            districtIds.add(integer);
            if (req.getArea()!=null && (!req.getArea().equals(""))){
                String[] split = req.getArea().split(",");
                for (String s : split) {
                    cityIds.add(Integer.valueOf(s));
                }
            }
        }
        SearchIntermediaryRes searchIntermediaryRes = new SearchIntermediaryRes();
        List<SearchIntermediaryListRes> res =this.baseMapper.searchIntermediaryList(req,districtIds,cityIds);
        searchIntermediaryRes.setList(res);
        searchIntermediaryRes.setTotal(res.size());
        return searchIntermediaryRes;
    }
 
    @Override
    public ResultUtil<AppUser> userInfo() {
        // 获取当前登录用户
        AppUser appUser = appUserService.getAppUser();
        return ResultUtil.success(appUser);
 
    }
    public static boolean isToday(Date date) {
        // 将Date类型转换为LocalDate
        LocalDate inputDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 比较日期是否相等
        return inputDate.isEqual(currentDate);
    }
    @Override
    public ResultUtil<CollectRes> collect(UserInfoQuery query) {
        SearchHousingDemandRes searchHousingDemandRes = housingDemandService
                .searchHousingDemand1(appUserService.getAppUser().getId());
        List<SearchHousingDemandListRes> list1 = searchHousingDemandRes.getList();
        CollectRes searchIntermediaryRes = new CollectRes();
        List<CollectListRes> list = houseResourceService.collect(appUserService.getAppUser().getId());
        for (SearchHousingDemandListRes temp : list1) {
            // 判断顶上去时间是不是今天
            CollectListRes collectListRes = new CollectListRes();
            collectListRes.setSaleAmount(temp.getSaleAmount());
            collectListRes.setData(1);
            BeanUtils.copyProperties(temp,collectListRes);
            StringBuilder stringBuilder = new StringBuilder("");
            if (temp.getAddress()!=null){
                for (String address : temp.getAddress()) {
                    stringBuilder.append(address+",");
                }
                String string = stringBuilder.toString();
                String substring = string.substring(0, string.length() - 1);
                collectListRes.setAddress(substring);
            }
            list.add(collectListRes);
        }
        for (CollectListRes collectListRes : list) {
            // 没有顶过
            if (collectListRes.getUpTime() == null){
                collectListRes.setUp(1);
                continue;
            }
            if (isToday(collectListRes.getUpTime())){
                // 时间相同的话 就不能顶
                collectListRes.setUp(0);
            }else{
                collectListRes.setUp(1);
            }
        }
        List<CollectListRes> collect3 = list.stream().distinct().collect(Collectors.toList());
        // 房源数据
        List<CollectListRes> collect1 = collect3.stream().filter(t->t.getData()==2).distinct().collect(Collectors.toList());
        // 求房源数据
        List<CollectListRes> collect2 = collect3.stream().filter(t->t.getData()==1).distinct().collect(Collectors.toList());
        for (CollectListRes collectListRes : collect1) {
            // 查询这个房源的收藏
            int collect = collectionHouseResourceService.selectList(new EntityWrapper<CollectionHouseResource>()
                    .eq("house_resource_id", collectListRes.getId())).size();
            collectListRes.setCollect(collect);
            // 根据区id 查询下级
            if (collectListRes.getCityId()==null){
                continue;
            }
            Region city = regionService.selectById(collectListRes.getCityId());
            Region dis = regionService.selectById(collectListRes.getDistrictId());
            Region region = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",dis.getId()));
            StringBuilder stringBuilder = new StringBuilder("");
            stringBuilder.append(dis.getName());
            if (region!=null){
                stringBuilder.append("/"+region.getName());
                Region region1 = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",region.getId()));
                if (region!=null){
                    stringBuilder.append(region1.getName());
                    Region region2 = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",region1.getId()));
                    if (region2!=null){
                        stringBuilder.append("/"+region2.getName());
                    }
                }
            }
            collectListRes.setAddress(city.getName()+">"+stringBuilder.toString());
        }
        for (CollectListRes collectListRes : collect2) {
            // 查询这个房源的收藏
            int collect = collectionHousingDemandService.selectList(new EntityWrapper<CollectionHousingDemand>()
                    .eq("housing_demand_id", collectListRes.getId())).size();
            collectListRes.setCollect(collect);
 
        }
        collect1.addAll(collect2);
        List<CollectListRes> testing = testing(collect1.size(), query.getPageNum(), query.getPageSize(), collect1);
        List<CollectListRes> collect = testing.stream().filter(t -> t.getData() == 2).distinct().collect(Collectors.toList());
        List<CollectListRes> collectt = testing.stream().filter(t -> t.getData() == 1).distinct().collect(Collectors.toList());
 
        long count = collect.stream().filter(t -> t.getType() == 1).count();
        long count1 = collectt.stream().filter(t -> t.getType() == 1).count();
        // 草稿数量
        searchIntermediaryRes.setDraft(Integer.parseInt(String.valueOf(count))+Integer.parseInt(String.valueOf(count1)));
        // 上架房源数
        int size = collect.stream().filter(t -> t.getStatus() == 1 && t.getType()==2).collect(Collectors.toList()).size();
        int size2 = collectt.stream().filter(t -> t.getStatus() == 1 && t.getType()==2).collect(Collectors.toList()).size();
        searchIntermediaryRes.setOn(size+size2);
        // 下架房源数
        int size1 = collect.stream().filter(t -> t.getStatus() == 0 && t.getType()==2).collect(Collectors.toList()).size();
        int size3 = collectt.stream().filter(t -> t.getStatus() == 0 && t.getType()==2).collect(Collectors.toList()).size();
        searchIntermediaryRes.setOff(size1+size3);
//        @ApiModelProperty("是否有电梯(0=否,1=是)")
//        private Integer elevator;
//        @ApiModelProperty("是否有晾晒区(0=否,1=是)")
//        private Integer dryingArea;
//        @ApiModelProperty("是否有花园(0=否,1=是)")
//        private Integer garden;
//        @ApiModelProperty("是否有车位(0=否,1=是)")
//        private Integer carport;
//        @ApiModelProperty("是否有平台(0=否,1=是)")
//        private Integer balcony;
//        @ApiModelProperty("是否可养宠物(0=否,1=是)")
//        private Integer keepPet;
 
        for (CollectListRes t : testing) {
            StringBuilder temp = new StringBuilder("");
            if (t.getElevator()==null){
                temp.append("电梯,");
            }else if (t.getElevator()==1){
                temp.append("电梯,");
            }
            if (t.getDryingArea()==null){
                temp.append("晾晒区,");
            }else if (t.getDryingArea()==1){
                temp.append("晾晒区,");
            }
            if (t.getGarden()==null){
                temp.append("花园,");
            }else if (t.getGarden()==1){
                temp.append("花园,");
            }
            if (t.getCarport()==null){
                temp.append("车位,");
            }else if (t.getCarport()==1){
                temp.append("车位,");
            }
            if (t.getBalcony()==null){
                temp.append("平台,");
            }else if (t.getBalcony()==1){
                temp.append("平台,");
            }
            if (t.getKeepPet()==null){
                temp.append("宠物,");
            }else if (t.getKeepPet()==1){
                temp.append("宠物,");
            }
            String string = temp.toString();
            if (StringUtils.hasLength(string)){
                String substring = string.substring(0, string.length() - 1);
                t.setHead(substring);
            }else{
                t.setHead("");
            }
 
        }
        searchIntermediaryRes.setList(testing);
 
        searchIntermediaryRes.setTotal(testing.size());
 
        return ResultUtil.success(searchIntermediaryRes);
    }
 
 
    public static List<CollectListRes> testing(long total, long current, long size, List<CollectListRes> str){
        List<CollectListRes> result = new ArrayList<>();
        //获取初始化分页结构
        Page<CollectListRes> page = new Page().getPage(total, size, current - 1);
        //获取集合下标初始值
        long startIndex = page.getStartIndex();
        //获取集合下标结束值
        long endInddex = 0;
        /**
         * 如果初始值startIndex(size * current)超过总记录数 或者 入参size(一页显示多少条)大于总记录树,
         * 则下标结束值均设置为集合大小
         */
        if(startIndex + page.getCurrent() >= total || size > total){
            endInddex = total;
        }else {
            /**当最后一页,开始下标加上要取值的size 大于总条数,则最终索引改为集合大小-1=》为
             *集合的最后下标值,防止下标溢出
             **/
            if(total < startIndex + page.getSize()){
                endInddex = total - 1 ;
            }else {
                //否则为startIndex(size * current 从哪里开始取)加上一页显示多少条得到结束值
                endInddex = startIndex  + page.getSize();
            }
        }
        //如果输入的开始查询下标大于集合大小,则查询为空值
        if(startIndex > total){
            result = Collections.emptyList();
        }else{
            result = str.subList((int)startIndex,(int)endInddex);
        }
        /**
         * 此处返回结果可以改为Page<T> T为对应业务的实体类型,最终把分页结果再塞入page的records再返回则得到与
         * mybatisplus一样的结构
         *  page.setRecords(list);
         *  return page;
         */
        return result;
    }
    @Override
    public ResultUtil<CollectRes> release(UserInfoQuery query) {
        // 房源ids
        List<Integer> ids = collectionHouseResourceService.selectList(new EntityWrapper<CollectionHouseResource>()
                .eq("app_user_id", appUserService.getAppUser().getId()))
                .stream().map(CollectionHouseResource::getHouseResourceId).collect(Collectors.toList());
            List<Integer> collect = houseResourceService.selectList(new EntityWrapper<HouseResource>()
                    .eq("is_delete", 0)
                    .eq("status", 1)
                    .eq("auth_status", 2)
                    .in("id", ids)).stream().map(HouseResource::getId).collect(Collectors.toList());
        List<CollectListRes> list = new ArrayList<>();
        if (collect.size()==0){
            }else{
            list = houseResourceService.release(query,collect);
        }
 
            List<CollectListRes> collect1 = list.stream().distinct().collect(Collectors.toList());
        if (ids.size()==0){
            collect=new ArrayList<>();
            list = new ArrayList<>();
            collect1 = new ArrayList<>();
        }
        for (CollectListRes collectListRes : collect1) {
            // 根据区id 查询下级
            Region city = regionService.selectById(collectListRes.getCityId());
            StringBuilder stringBuilder = new StringBuilder("");
            if (city!=null){
                Region dis = regionService.selectById(collectListRes.getDistrictId());
                if (dis!=null){
                    Region region = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",dis.getId()));
                    stringBuilder.append(dis.getName());
                    if (region!=null){
                        stringBuilder.append("/"+region.getName());
                        Region region1 = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",region.getId()));
                        if (region!=null){
                            stringBuilder.append(region1.getName());
                            Region region2 = regionService.selectOne(new EntityWrapper<Region>().eq("parent_id",region1.getId()));
                            if (region2!=null){
                                stringBuilder.append("/"+region2.getName());
                            }
                        }
                    }
                    collectListRes.setAddress(city.getName()+">"+stringBuilder.toString());
                }
            }
        }
        // 查询收藏的求房源ids
        List<Integer> demand = collectionHousingDemandService.selectList
                (new EntityWrapper<CollectionHousingDemand>()
                        .eq("app_user_id", appUserService.getAppUser().getId()))
                .stream().map(CollectionHousingDemand::getHousingDemandId)
                .collect(Collectors.toList());
        if (demand.size()!=0){
            SearchHousingDemandRes searchHousingDemandRes = housingDemandService.searchHousingDemand2(demand);
            List<SearchHousingDemandListRes> list1 = searchHousingDemandRes.getList();
            for (SearchHousingDemandListRes temp : list1) {
                CollectListRes collectListRes = new CollectListRes();
                collectListRes.setSaleAmount(temp.getSaleAmount());
                collectListRes.setData(1);
                BeanUtils.copyProperties(temp,collectListRes);
                StringBuilder stringBuilder = new StringBuilder("");
                if (temp.getAddress()!=null){
                    for (String address : temp.getAddress()) {
                        stringBuilder.append(address+",");
                    }
                    String string = stringBuilder.toString();
                    String substring = string.substring(0, string.length() - 1);
                    collectListRes.setAddress(substring);
                }
                collect1.add(collectListRes);
            }
        }
 
 
        CollectRes searchIntermediaryRes = new CollectRes();
        List<CollectListRes> testing = testing(collect1.size(), query.getPageNum(), query.getPageSize(), collect1);
 
        searchIntermediaryRes.setList(testing);
        searchIntermediaryRes.setTotal(testing.size());
        return ResultUtil.success(searchIntermediaryRes);
    }
 
    @Override
    public SearchIntermediaryListRes searchIntermediaryInfo(Integer id) {
        return this.baseMapper.searchIntermediaryInfo(id);
 
    }
 
 
    /**
     * 添加新用户到数据库
     * @param openid    微信openid
     * @param phone     手机号
     */
    private AppUser addNewAppUser(String openid, String phone){
        AppUser appUser = new AppUser();
        appUser.setCode(UUIDUtil.getNumberRandom(16));
        appUser.setUserType(1);
        appUser.setPhone(phone);
        appUser.setWechatOpenid(openid);
        appUser.setAuditStatus(2);
        appUser.setStatus(1);
        appUser.setAuth(0);
        appUser.setInsertTime(new Date());
        this.insert(appUser);
        return appUser;
    }
 
 
    /**
     * 将用户标识存入缓存中用于后期接口的身份校验
     * @param token
     * @param id
     */
    private void addTokenToRedis(String token, Integer id){
        String key = token;
        int length = token.length();
        if(length > 32){
            key = token.substring(token.length() - 32);
        }
        //30天有效期
        redisUtil.setStrValue(key, id.toString(), 2592000);
    }
 
 
    /**
     * 通过token获取用户id
     * @param token
     * @return
     */
    private Integer getAppUserIdFromToken(String token){
        System.err.println("token--->" + token);
        String key = token;
        int length = token.length();
        if(length > 32){
            key = token.substring(token.length() - 32);
        }
        String value = redisUtil.getValue(key);
        if(ToolUtil.isEmpty(value)){
            return 0;
        }
        return Integer.valueOf(value);
    }
}