yujian
2019-08-23 89e89fe2b2a1578a94b2e2c8ee81efbfbbf85f08
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
package com.yeshi.fanli.controller.client.v2;
 
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.JsonUtil;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.TypeAdapter;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail.TaoLiJinDetailTypeEnum;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserRank;
import com.yeshi.fanli.entity.integral.CodePublishRecord;
import com.yeshi.fanli.entity.integral.IntegralExchange;
import com.yeshi.fanli.entity.integral.IntegralTask;
import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum;
import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
import com.yeshi.fanli.exception.integral.IntegralExchangeException;
import com.yeshi.fanli.exception.integral.IntegralGetException;
import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.integral.CodePublishRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralDetailService;
import com.yeshi.fanli.service.inter.integral.IntegralExchangeRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralExchangeService;
import com.yeshi.fanli.service.inter.integral.IntegralGetService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskClassService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskRankService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.vo.integral.DailySignVO;
import com.yeshi.fanli.vo.integral.ExchangeTipVO;
import com.yeshi.fanli.vo.integral.IntegralDetailVO;
import com.yeshi.fanli.vo.integral.IntegralTaskClassVO;
import com.yeshi.fanli.vo.user.UserInfoExtraVO;
 
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("api/v2/integral")
public class IntegralControllerV2 {
 
    @Resource
    private ConfigService configService;
 
    @Resource
    private UserInfoService userInfoService;
 
    @Resource
    private UserInfoExtraService userInfoExtraService;
 
    @Resource
    private IntegralTaskClassService integralTaskClassService;
 
    @Resource
    private IntegralTaskRecordService integralTaskRecordService;
 
    @Resource
    private IntegralExchangeService integralExchangeService;
 
    @Resource
    private IntegralExchangeRecordService integralExchangeRecordService;
 
    @Resource
    private IntegralDetailService integralDetailService;
 
    @Resource
    private IntegralTaskRankService integralTaskRankService;
 
    @Resource
    private CodePublishRecordService codePublishRecordService;
 
    @Resource
    private IntegralTaskService integralTaskService;
 
    @Resource
    private IntegralGetService integralGetService;
 
    /**
     * 获取任务列表
     * 
     * @param acceptData
     * @param uid
     * @param page
     * @param out
     */
//    @RequestSerializableByKey(key="#acceptData.device")
    @RequestMapping(value = "getTaskList", method = RequestMethod.POST)
    public void getTaskList(AcceptData acceptData, Long uid, Integer page, PrintWriter out) {
        if (uid == null || uid <= 0) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
 
        if (page == null || page < 1) {
            out.print(JsonUtil.loadFalseResult(1, "页码不正确"));
            return;
        }
 
        GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
        Gson gson = gsonBuilder.create();
        try {
            JSONObject data = new JSONObject();
            List<IntegralTaskClassVO> list = integralTaskClassService.getIntegralTaskClassVO(uid,
                    (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
            if (list == null) {
                list = new ArrayList<IntegralTaskClassVO>();
            }
            long count = integralTaskClassService.countTaskClass();
 
            // 用户签到
            Integer signState = 0;
            if (page == 1) {
 
                // 签到
                try {
                    signState = integralTaskClassService.finishedDailySign(uid);
                } catch (Exception e) {
                    e.printStackTrace();
                }
 
                UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
                if (extraVO == null) {
                    out.print(JsonUtil.loadFalseResult(1, "用户相关信息不存在"));
                    return;
                }
 
                UserInfo userInfo = extraVO.getUserInfo();
                if (userInfo == null) {
                    out.print(JsonUtil.loadFalseResult(1, "查询用户信息不全"));
                    return;
                }
 
                UserRank userRank = extraVO.getUserRank();
                if (userRank == null) {
                    out.print(JsonUtil.loadFalseResult(1, "用户等级不存在"));
                    return;
                }
 
                // 签到日期信息
                DailySignVO dailySignVO = integralTaskClassService.getDailySignList(uid, userRank.getId());
 
                boolean ejectSign = false;
                if (signState == 1)
                    ejectSign = true;
 
                data.put("signState", ejectSign);
                data.put("goldCoin", extraVO.getGoldCoin());
                data.put("portrait", userInfo.getPortrait());
                data.put("userRank", gson.toJson(userRank));
                data.put("dailySign", dailySignVO);
            }
 
            for (IntegralTaskClassVO taskClassVO : list) {
                String progress = taskClassVO.getProgress();
                if (StringUtil.isNullOrEmpty(progress))
                    continue;
 
                Integer taskNum = taskClassVO.getTaskNum();
                if (taskNum == null)
                    continue;
 
                UniqueKeyEnum uniqueKey = taskClassVO.getUniqueKey();
                if (uniqueKey == UniqueKeyEnum.dailySign) {
                    if (signState == 0) {
                        taskClassVO.setLightUp(true); // 签到失败
                    } else if (signState == 1) {
                        taskClassVO.setLightUp(false);
                    } else if (signState == 2) {
                        taskClassVO.setLightUp(false);
                    }
 
                    // 根据天数变化更改签到金额
                    Integer num = integralTaskRecordService.getNowdaySignNum(uid, taskClassVO.getId());
 
                    String uniqueKeyTask = UniqueKeyEnum.dailySign.name() + num;
                    IntegralTask integralTask = integralTaskService.getByCidAndUniqueKey(taskClassVO.getId(),
                            uniqueKeyTask);
                    Integer goldCoin = 0;
                    if (integralTask != null) {
                        goldCoin = integralTask.getGoldCoin();
                        Integer baseDoubleNum = integralTask.getDoubleNum();
                        if (baseDoubleNum != null && baseDoubleNum > 0)
                            goldCoin = goldCoin * baseDoubleNum;
                    }
                    taskClassVO.setTotalCoin(goldCoin);
                } else {
                    taskClassVO.setLightUp(true);
                }
 
                Integer dateType = 1; // 查询当日
                if (uniqueKey == UniqueKeyEnum.orderReward)
                    dateType = null; // 查询历史
 
                Long id = taskClassVO.getId();
                int countFinished = 0;
                Integer totalGoldCoin = integralTaskRecordService.getTotalGoldCoin(uid, id, dateType);
                if (totalGoldCoin != null && totalGoldCoin > 0) {
                    taskClassVO.setFinishedCoin("+" + totalGoldCoin);
                    if (uniqueKey != UniqueKeyEnum.dailySign)
                        countFinished = integralTaskRecordService.countFinished(uid, id, dateType);
                }
                progress = progress.replace("{已完成}", countFinished + "").replace("{总任务}", taskNum + "");
 
                if (signState == 0 && uniqueKey == UniqueKeyEnum.dailySign) {
                    progress = "未签到";
                    taskClassVO.setBtnName("签到");
                }
                taskClassVO.setProgress(progress);
            }
 
            data.put("count", count);
            data.put("list", gson.toJson(list));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
    }
 
    /**
     * 获取已完成任务 未领取金币
     * 
     * @param acceptData
     * @param uid
     * @param out
     */
    @RequestMapping(value = "getNotReceived", method = RequestMethod.POST)
    public void getNotReceived(AcceptData acceptData, Long uid, PrintWriter out) {
        if (uid == null || uid <= 0) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
 
        int count = 5;
        if ("android".equalsIgnoreCase(acceptData.getPlatform())) {
            count = Integer.MAX_VALUE;
        }
 
        List<IntegralTaskRecord> list = integralTaskRecordService.listNotReceived(count, uid);
        if (list == null) {
            list = new ArrayList<IntegralTaskRecord>();
        }
 
        GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
        Gson gson = gsonBuilder.create();
 
        JSONObject data = new JSONObject();
        data.put("list", gson.toJson(list));
        out.print(JsonUtil.loadTrueResult(data));
    }
 
    /**
     * 领取金币
     * 
     * @param acceptData
     * @param uid
     * @param ids
     *            // 领取id
     * @param gids
     *            // 未领取id
     * @param out
     */
    @RequestMapping(value = "receiveGoldCoin", method = RequestMethod.POST)
    public void receiveGoldCoin(AcceptData acceptData, Long uid, Integer type, String ids, String gids,
            PrintWriter out) {
        if (uid == null || uid <= 0) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
 
        try {
            // 全部领取
            if (type != null && type == 1) {
                Integer goldCoin = integralTaskRecordService.receiveGoldCoinALL(uid);
                JSONObject data = new JSONObject();
                data.put("goldCoin", goldCoin);
                out.print(JsonUtil.loadTrueResult(data));
                return;
            }
 
            // 部分领取
            Gson gson = new Gson();
            Set<Long> idList = gson.fromJson(ids, new TypeToken<HashSet<Long>>() {
            }.getType());
            if (idList == null || idList.size() == 0) {
                out.print(JsonUtil.loadFalseResult("领取id不能为空"));
                return;
            }
            Integer goldCoin = integralTaskRecordService.receiveGoldCoin(uid, idList);
            Set<Long> gidList = gson.fromJson(gids, new TypeToken<HashSet<Long>>() {
            }.getType());
            List<IntegralTaskRecord> list = null;
            if (gidList != null && gidList.size() > 0) {
                list = integralTaskRecordService.listNotReceivedExcludeId(5 - gidList.size(), uid, gidList);
            } else {
                list = integralTaskRecordService.listNotReceivedExcludeId(5, uid, null);
            }
 
            if (list == null) {
                list = new ArrayList<IntegralTaskRecord>();
            }
            GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
            Gson gson2 = gsonBuilder.create();
 
            JSONObject data = new JSONObject();
            data.put("goldCoin", goldCoin);
            data.put("list", gson2.toJson(list));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (IntegralTaskRecordException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
        }
    }
 
    /**
     * 金币兑换列表
     * 
     * @param acceptData
     * @param uid
     * @param ids
     * @param out
     */
    @RequestMapping(value = "getExchangeList", method = RequestMethod.POST)
    public void getExchangeList(AcceptData acceptData, Long uid, Integer page, PrintWriter out) {
        if (uid == null || uid <= 0) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
 
        if (page == null || page < 1) {
            out.print(JsonUtil.loadFalseResult(1, "页码不正确"));
            return;
        }
 
        UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
        if (extraVO == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户相关信息不存在"));
            return;
        }
 
        List<IntegralExchange> list = integralExchangeRecordService.listExchange((page - 1) * Constant.PAGE_SIZE,
                Constant.PAGE_SIZE, uid);
        if (list == null)
            list = new ArrayList<IntegralExchange>();
 
        // Long count = integralExchangeService.countValid();
 
        GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
        Gson gson = gsonBuilder.create();
 
        JSONObject data = new JSONObject();
        data.put("goldCoin", extraVO.getGoldCoin() + "枚");
        data.put("count", list.size());
        data.put("list", gson.toJson(list));
        out.print(JsonUtil.loadTrueResult(data));
    }
 
    /**
     * 兑换金币检验
     * 
     * @param acceptData
     * @param uid
     * @param id
     * @param out
     */
    @RequestMapping(value = "verifyExchange", method = RequestMethod.POST)
    public void verifyExchange(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
        try {
            ExchangeTipVO exchange = integralExchangeService.verifyExchange(uid, id);
 
            GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
            Gson gson = gsonBuilder.create();
 
            JSONObject data = new JSONObject();
            data.put("result", gson.toJson(exchange));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (IntegralExchangeException e) {
            out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
        }
    }
    
 
    /**
     * 兑换金币
     * 
     * @param acceptData
     * @param uid
     * @param id
     * @param out
     */
    @RequestMapping(value = "exchange", method = RequestMethod.POST)
    public void exchange(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
        try {
            IntegralExchange exchange = integralExchangeService.exchange(uid, id);
 
            GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
            Gson gson = gsonBuilder.create();
 
            JSONObject data = new JSONObject();
            data.put("result", gson.toJson(exchange));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (IntegralExchangeException e) {
            out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
        }
    }
 
    /**
     * 兑换金币检验-邀请码
     * 
     * @param acceptData
     * @param uid
     * @param id
     * @param out
     */
    @RequestMapping(value = "verifyInviteCode", method = RequestMethod.POST)
    public void verifyInviteCode(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
        try {
            ExchangeTipVO exchange = integralExchangeService.verifyInviteCode(uid, id);
 
            GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
            Gson gson = gsonBuilder.create();
 
            JSONObject data = new JSONObject();
            data.put("result", gson.toJson(exchange));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (IntegralExchangeException e) {
            out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
        }
    }
 
    /**
     * 兑换金币-邀请码
     * 
     * @param acceptData
     * @param uid
     * @param id
     * @param out
     */
    @RequestMapping(value = "exchangeInviteCode", method = RequestMethod.POST)
    public void exchangeInviteCode(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
        try {
            String inviteCode = integralExchangeService.exchangeInviteCode(uid, id);
            JSONObject data = new JSONObject();
            data.put("msg", "兑换成功,金币已消耗 ");
            data.put("inviteCode", inviteCode);
            out.print(JsonUtil.loadTrueResult(data));
        } catch (IntegralExchangeException e) {
            out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
        }
    }
 
    /**
     * 邀请码发布列表
     * 
     * @param acceptData
     * @param page
     * @param out
     */
    @RequestMapping(value = "getPublishList", method = RequestMethod.POST)
    public void getPublishList(AcceptData acceptData, Integer page, PrintWriter out) {
        if (page == null || page < 1) {
            out.print(JsonUtil.loadFalseResult(1, "页码不正确"));
            return;
        }
        
        try {
            List<CodePublishRecord> list = codePublishRecordService.listValid((page - 1) * Constant.PAGE_SIZE,
                    Constant.PAGE_SIZE);
            if (list == null) {
                list = new ArrayList<CodePublishRecord>();
            }
 
            long count = codePublishRecordService.countValid();
 
            JSONObject data = new JSONObject();
            data.put("count", count);
            data.put("list", getGson().toJson(list));
            data.put("helpLink", configService.get("publish_list_help_link"));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult(1, "获取失败"));
            return;
        }
    }
 
    /**
     * 事件推送
     * 
     * @param acceptData
     * @param event
     * @param uid
     * @param out
     */
    @RequestMapping(value = "pushEvent", method = RequestMethod.POST)
    public void pushEvent(AcceptData acceptData, String event, Long uid, PrintWriter out) {
        if (uid == null || uid == 0) {
            out.print(JsonUtil.loadFalseResult("用户尚未登录"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(event)) {
            out.print(JsonUtil.loadFalseResult("事件为空"));
            return;
        }
        IntegralTaskRecord record = null;
        try {
            record = integralGetService.addEventStatistic(uid, event, null);
        } catch (IntegralGetException e) {
        }
        if (record == null) {
            out.print(JsonUtil.loadFalseResult("添加失败"));
            return;
        }
 
        JSONObject data = new JSONObject();
        if ("recommendSearch".equalsIgnoreCase(event) || "scanGoods".equalsIgnoreCase(event)
                || "scanTBCart".equalsIgnoreCase(event)) {
            JSONObject notify = new JSONObject();
            switch (event) {
            case "recommendSearch":
                notify.put("name", "完成一次智能搜索");
                break;
            case "scanGoods":
                notify.put("name", "完成一次商品浏览");
                break;
            case "scanTBCart":
                notify.put("name", "完成一次购物车浏览");
                break;
            }
            notify.put("score", String.format("+%s金币", record.getGoldCoin()));
            data.put("notify", notify);
        }
        out.print(JsonUtil.loadTrueResult(data));
    }
 
    /**
     * 时间处理
     * 
     * @return
     */
    private Gson getGson() {
        GsonBuilder gb = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder());
        gb.excludeFieldsWithoutExposeAnnotation();
        gb.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
            @Override
            public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
                String desc = "";
                if (value != null) {
                    // 判断是否是同一天
 
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(value);
                    int y1 = calendar.get(Calendar.YEAR);// 获取年份
                    int d1 = calendar.get(Calendar.DAY_OF_YEAR);// 获取年中第几天
 
                    Date nowDate = new Date();
                    Calendar calendar2 = Calendar.getInstance();
                    calendar2.setTime(nowDate);
                    int y2 = calendar2.get(Calendar.YEAR);// 获取年份
                    int d2 = calendar2.get(Calendar.DAY_OF_YEAR);// 获取年中第几天
 
                    long old = value.getTime();
                    long now = nowDate.getTime();
                    if (y1 == y2) {
                        if (d1 == d2) {
                            long cha = now - old;
                            if (cha < 1000 * 60 * 2L) {
                                desc = "刚刚";
                            } else if (cha < 1000 * 60 * 60L) {
                                desc = (cha / (1000 * 60)) + "分钟前";
                            } else {
                                desc = (cha / (1000 * 60 * 60)) + "小时前";
                            }
                        } else if (d2 - d1 == 1) {
                            desc = "昨天";
                        } else {
                            desc = (d2 - d1) + "天前";
                        }
                    } else {
                        int timeDistance = 0;
                        for (int i = y1; i < y2; i++) {
                            if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
                                timeDistance += 366; // 闰年
                            } else {
                                timeDistance += 365; // 不是闰年
                            }
                        }
                        desc = timeDistance + (d2 - d1) + "天前";
                    }
 
                    return new JsonPrimitive(desc);
                }
 
                return new JsonPrimitive("");
            }
        });
 
        Gson gson = gb.create();
        return gson;
    }
 
    /**
     * 明细详情
     * 
     * @param acceptData
     * @param uid
     * @param index
     *            List最末的主键ID
     * @param year
     *            年份
     * @param month
     *            月份
     * @param type
     *            统计类型 0全部 1
     * @param out
     */
    @RequestMapping(value = "getDetails")
    public void getDetails(AcceptData acceptData, Long uid, Long index, Integer year, Integer month, Integer type,
            PrintWriter out) {
        if (uid == null || uid == 0) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
 
        if ((year == null && month != null) || (year != null && month == null)) {
            out.print(JsonUtil.loadFalseResult(1, "日期不完整"));
            return;
        }
 
        Date date = null;
 
        if (year != null && month != null) {
            date = new Date(TimeUtil.convertToTimeTemp(year + "-" + month, "yyyy-M"));
            Calendar ca = Calendar.getInstance();
            ca.setTime(date);
            ca.add(Calendar.MONTH, 1);
            date = new Date(ca.getTimeInMillis() - 1);
        }
 
        // 查询列表
        List<IntegralDetailVO> list = integralDetailService.listDetailForClient(uid, index, date, type);
        // 统计总条数
        long count = integralDetailService.countDetailForClient(uid, index, date, type);
 
        GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
        gsonBuilder.registerTypeAdapter(TaoLiJinDetailTypeEnum.class, new TypeAdapter<TaoLiJinDetailTypeEnum>() {
            @Override
            public TaoLiJinDetailTypeEnum read(JsonReader arg0) throws IOException {
                return null;
            }
 
            @Override
            public void write(JsonWriter out, TaoLiJinDetailTypeEnum arg1) throws IOException {
                out.beginObject();
                out.name("portrait").value(arg1.getPicture());
                out.endObject();
            }
        }).registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
            @Override
            public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
                if (value == null) {
                    return new JsonPrimitive("");
                } else {
                    return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy.MM.dd HH:mm"));
                }
            }
        });
 
        Gson gson = gsonBuilder.create();
 
        JSONObject data = new JSONObject();
        data.put("count", count);
        data.put("data", gson.toJson(list));
        out.print(JsonUtil.loadTrueResult(data));
    }
}