| | |
| | | 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 void addEventStatistic(Long uid, String event, JSONObject params) throws IntegralGetException {
|
| | | 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;
|
| | | 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 {
|
| | | // TODO Auto-generated method stub
|
| | |
|
| | | }
|
| | |
|
| | | @Cacheable(value = "integralGetCache", key = "'addSearchResultScan-'+#uid+'-'+#kw")
|
| | | @Override
|
| | | public void addSearchResultScan(Long uid) throws IntegralGetException {
|
| | | // TODO Auto-generated method stub
|
| | |
|
| | | public void addSearchResultScan(Long uid, String kw) throws IntegralGetException {
|
| | | System.out.println("搜索");
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void addShareInvite(Long uid) throws IntegralGetException {
|
| | | // TODO Auto-generated method stub
|
| | |
|
| | | }
|
| | |
|