yujian
2019-08-28 d88c167fc5973a2c15ff1539e4cdab36e4a7842c
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralGetServiceImpl.java
@@ -4,14 +4,16 @@
import javax.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.ThreeSaleMapper;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
import com.yeshi.fanli.entity.bus.user.UserRank;
import com.yeshi.fanli.entity.integral.IntegralTask;
import com.yeshi.fanli.entity.integral.IntegralTaskRank;
import com.yeshi.fanli.entity.integral.IntegralTask.FrequencyEnum;
import com.yeshi.fanli.entity.integral.IntegralTask.TaskUniqueKeyEnum;
import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
@@ -19,9 +21,12 @@
import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.integral.IntegralGetService;
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.util.RedisManager;
import com.yeshi.fanli.util.annotation.integral.IntegralGetFrequencyLimit;
import com.yeshi.fanli.util.annotation.integral.IntegralGetVersionLimit;
@Lazy
@@ -39,13 +44,19 @@
   @Resource
   private RedisManager redisManager;
   @Resource
   private UserInfoExtraService userInfoExtraService;
   @Resource
   private IntegralTaskRankService integralTaskRankService;
   // TODO 有bug
   private UserInfo getBossByUid(Long uid) {
      return threeSaleMapper.selectBoss(uid);
   }
   @IntegralGetVersionLimit(uid="#uid")
   @IntegralGetVersionLimit(uid = "#uid")
   @Override
   public IntegralTaskRecord addEventStatistic(Long uid, String event) throws IntegralGetException {
      Date nowDate = new Date();
@@ -68,10 +79,31 @@
         if (count > 0)
            throw new IntegralGetException(2, "事件触发达到上限");
      }
      UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
      if (userInfoExtra == null)
         throw new IntegralGetException(2, "额外信息不存在");
      UserRank userRank = userInfoExtra.getUserRank();
      if (userRank == null)
         throw new IntegralGetException(2,"等级信息不存在");
      int goldCoin = task.getGoldCoin();
      if (task.getDoubleNum() != null && task.getDoubleNum() > 0)
         goldCoin = task.getDoubleNum() * goldCoin;
      Long taskId = task.getId();
      IntegralTaskRank traskRank = integralTaskRankService.getByTsakIdAndRankId(taskId, userRank.getId());
      if (traskRank != null) {
         Integer addCoin = traskRank.getAddCoin();
         if (addCoin != null && addCoin > 0)
            goldCoin += addCoin;
         Integer doubleNum = traskRank.getDoubleNum();
         if (doubleNum != null && doubleNum > 0) {
            goldCoin = goldCoin * doubleNum;
         }
      }
      IntegralTaskRecord record = new IntegralTaskRecord();
      record.setCid(task.getTaskClass().getId());
@@ -88,7 +120,7 @@
      }
   }
   @Cacheable(value = "integralGetCache", key = "'addRecommendSearch-'+#uid")
   @IntegralGetFrequencyLimit(key = "'addRecommendSearch-'+#uid")
   @Override
   public IntegralTaskRecord addRecommendSearch(Long uid) {
      try {
@@ -99,7 +131,7 @@
      return null;
   }
   @Cacheable(value = "integralGetCache", key = "'addSearchResultScan-'+#uid+'-'+#kw")
   @IntegralGetFrequencyLimit(key = "'addSearchResultScan-'+#uid+'-'+#kw")
   @Override
   public IntegralTaskRecord addSearchResultScan(Long uid, String kw) {
      try {
@@ -111,7 +143,7 @@
      return null;
   }
   @Cacheable(value = "integralGetCache", key = "'addShareInvite-'+#uid")
   @IntegralGetFrequencyLimit(key = "'addShareInvite-'+#uid")
   @Override
   public IntegralTaskRecord addShareInvite(Long uid) {
      try {
@@ -122,7 +154,7 @@
      return null;
   }
   @Cacheable(value = "integralGetCache", key = "'addIntoShop-'+#uid+'-'+#shopUrlMD5")
   @IntegralGetFrequencyLimit(key = "'addIntoShop-'+#uid+'-'+#shopUrlMD5")
   @Override
   public IntegralTaskRecord addIntoShop(Long uid, String shopUrlMD5) {
      try {
@@ -157,7 +189,7 @@
      }
   }
   @Cacheable(value = "integralGetCache", key = "'addScanPushHistory-'+#uid")
   @IntegralGetFrequencyLimit(key = "'addScanPushHistory-'+#uid")
   @Override
   public IntegralTaskRecord addScanPushHistory(Long uid) {
      try {
@@ -168,7 +200,7 @@
      return null;
   }
   @Cacheable(value = "integralGetCache", key = "'addScanGoodsDetail-'+#uid+'-'+#goodsType+'-'+#goodsId")
   @IntegralGetFrequencyLimit(key = "'addScanGoodsDetail-'+#uid+'-'+#goodsType+'-'+#goodsId")
   @Override
   public IntegralTaskRecord addScanGoodsDetail(Long uid, int goodsType, Long goodsId) {
      try {
@@ -179,7 +211,7 @@
      return null;
   }
   @Cacheable(value = "integralGetCache", key = "'addScanRecommendBanner-'+#uid+'-'+#id")
   @IntegralGetFrequencyLimit(key = "'addScanRecommendBanner-'+#uid+'-'+#id")
   @Override
   public IntegralTaskRecord addScanRecommendBanner(Long uid, String id) {
      try {
@@ -190,7 +222,7 @@
      return null;
   }
   @Cacheable(value = "integralGetCache", key = "'addScanRecommendSpecial-'+#uid+'-'+#id")
   @IntegralGetFrequencyLimit(key = "'addScanRecommendSpecial-'+#uid+'-'+#id")
   @Override
   public IntegralTaskRecord addScanRecommendSpecial(Long uid, String id) {
      try {
@@ -202,7 +234,7 @@
      return null;
   }
   @Cacheable(value = "integralGetCache", key = "'addScanTaoBaoCart-'+#uid")
   @IntegralGetFrequencyLimit(key = "'addScanTaoBaoCart-'+#uid")
   @Override
   public IntegralTaskRecord addScanTaoBaoCart(Long uid) {
      try {
@@ -385,10 +417,6 @@
   @Override
   public void addRebateOrder(Long uid) {
      try {
         UserInfo boss = getBossByUid(uid);
         if (boss != null)
            addInviteOrderLevelOne(boss.getId());
         addEventStatistic(uid, TaskUniqueKeyEnum.rebateOrder.name());
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
@@ -402,12 +430,9 @@
    */
   @IntegralGetVersionLimit(uid = "#uid")
   @Async()
   private void addInviteOrderLevelOne(Long uid) {
   @Override
   public void addInviteOrderLevelOne(Long uid) {
      try {
         UserInfo boss = getBossByUid(uid);
         if (boss != null)
            addInviteOrderLevelTwo(boss.getId());
         addEventStatistic(uid, TaskUniqueKeyEnum.inviteOrderLevelOne.name());
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
@@ -421,7 +446,8 @@
    */
   @IntegralGetVersionLimit(uid = "#uid")
   @Async()
   private void addInviteOrderLevelTwo(Long uid) {
   @Override
   public void addInviteOrderLevelTwo(Long uid) {
      try {
         addEventStatistic(uid, TaskUniqueKeyEnum.inviteOrderLevelTwo.name());
      } catch (Exception e) {