yujian
2019-08-22 11c098089f8c4714188e91032e5a19e8fe94bf96
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
package com.yeshi.fanli.service.impl.integral;
 
import java.util.Date;
 
import javax.annotation.Resource;
 
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.entity.integral.IntegralTask;
import com.yeshi.fanli.entity.integral.IntegralTask.FrequencyEnum;
import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
import com.yeshi.fanli.exception.integral.IntegralGetException;
import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
import com.yeshi.fanli.service.inter.integral.IntegralGetService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskService;
import com.yeshi.fanli.util.RedisManager;
 
import net.sf.json.JSONObject;
 
@Service
public class IntegralGetServiceImpl implements IntegralGetService {
 
    @Resource
    private IntegralTaskService integralTaskService;
 
    @Resource
    private IntegralTaskRecordService integralTaskRecordService;
 
    @Resource
    private RedisManager redisManager;
 
    @Override
    public IntegralTaskRecord addEventStatistic(Long uid, String event, JSONObject params) throws IntegralGetException {
        Date nowDate = new Date();
        IntegralTask task = integralTaskService.getByCidAndUniqueKey(null, event);
        if (task == null)
            throw new IntegralGetException(1, "事件类型不存在");
        if (task.getFrequency() == FrequencyEnum.everyday) {
            int count = integralTaskRecordService.countGetCountByTaskIdAndDay(task.getId(), uid, nowDate);
            if (count >= task.getUpperLimit())
                throw new IntegralGetException(2, "事件触发达到上限");
        } else if (task.getFrequency() == FrequencyEnum.onlyOne) {
            int count = integralTaskRecordService.countGetCountByTaskIdAndDay(task.getId(), uid, null);
            if (count > 0)
                throw new IntegralGetException(2, "事件触发达到上限");
        }
 
        int goldCoin = task.getGoldCoin();
        if (task.getDoubleNum() != null && task.getDoubleNum() > 0)
            goldCoin = task.getDoubleNum() * goldCoin;
 
        IntegralTaskRecord record = new IntegralTaskRecord();
        record.setCid(task.getTaskClass().getId());
        record.setGoldCoin(goldCoin);
        record.setState(IntegralTaskRecord.STATE_WAITING_RECIEVE);
        record.setTaskId(task.getId());
        record.setUid(uid);
 
        try {
            return integralTaskRecordService.addRecord(record);
        } catch (IntegralTaskRecordException e) {
            throw new IntegralGetException(3, "添加记录失败");
        }
 
        // switch (event) {
        // case "recommendSearch":
        // break;
        // case "shareInvite":
        // break;
        // case "inShop":
        // break;
        // case "scanPush":
        // break;
        // case "scanGoods":
        // break;
        // case "scanHomeBanner":
        // break;
        // case "scanSpecial":
        // break;
        // case "scanTBCart":
        // break;
        // }
    }
 
    @Override
    public void addRecommendSearch(Long uid) throws IntegralGetException {
 
    }
 
    @Cacheable(value = "integralGetCache", key = "'addSearchResultScan-'+#uid+'-'+kw")
    @Override
    public void addSearchResultScan(Long uid, String kw) throws IntegralGetException {
        System.out.println("搜索");
    }
 
    @Override
    public void addShareInvite(Long uid) throws IntegralGetException {
 
    }
 
    @Override
    public void addIntoShop(Long uid) throws IntegralGetException {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void addScanPushHistory(Long uid) throws IntegralGetException {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void addScanGoodsDetail(Long uid, int goodsType, Long goodsId) {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void addScanRecommendBanner(Long uid) {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void addScanRecommendSpecial(Long uid) {
        // TODO Auto-generated method stub
 
    }
 
    @Override
    public void addScanTaoBaoCart(Long uid) {
        // TODO Auto-generated method stub
 
    }
 
}