admin
2019-09-16 cc55ffcea74c7d23dadaa0860befbcdf98f35341
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java
@@ -9,11 +9,14 @@
import javax.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.DateUtil;
import com.yeshi.fanli.dao.mybatis.integral.IntegralTaskRecordMapper;
import com.yeshi.fanli.dto.msg.MsgOtherRewardIntegralDTO;
import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
import com.yeshi.fanli.entity.integral.IntegralDetail;
import com.yeshi.fanli.entity.integral.IntegralTask;
@@ -24,11 +27,14 @@
import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
import com.yeshi.fanli.exception.user.UserInfoExtraException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.integral.IntegralDetailService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskClassService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskService;
import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
@Service
@@ -46,8 +52,17 @@
   @Resource
   private IntegralTaskService integralTaskService;
   @Lazy
   @Resource
   private IntegralTaskClassService integralTaskClassService;
   @Resource
   private UserOtherMsgNotificationService userOtherMsgNotificationService;
   @Resource
   private ConfigService configService;
   @Override
   public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
@@ -116,7 +131,7 @@
      List<IntegralTaskRecord> listRecord = new ArrayList<IntegralTaskRecord>();
      try {
         // 签到时间正序序查询近7天数据
         List<IntegralTaskRecord> list = integralTaskRecordMapper.listDaySignRecord(uid, cid);
         List<IntegralTaskRecord> list = integralTaskRecordMapper.listDateSignRecord(uid, cid);
         if (list != null && list.size() > 0) {
            Date date = new Date();
            for (IntegralTaskRecord record : list) {
@@ -134,6 +149,33 @@
      return listRecord;
   }
   @Override
   public List<IntegralTaskRecord> getSign7DaysRecord(long uid, Long cid) {
      List<IntegralTaskRecord> listRecord = new ArrayList<IntegralTaskRecord>();
      try {
         // 签到时间正序序查询近7天数据
         List<IntegralTaskRecord> list = integralTaskRecordMapper.listDaySignRecord(uid, cid);
         if (list != null && list.size() > 0) {
            Date date = new Date();
            for (IntegralTaskRecord record : list) {
               Date createTime = record.getCreateTime();
               if (DateUtil.daysBetween2(createTime, date) > 1) {
                  break; // 天数未连续
               }
               date = createTime;
               listRecord.add(record);
               if(listRecord.size() >= 7)
                  break;
            }
         }
      } catch (Exception e) {
         LogHelper.errorDetailInfo(e);
      }
      return listRecord;
   }
   @Override
   public List<IntegralTaskRecord> listNotReceived(int count, long uid) {
      return integralTaskRecordMapper.listNotReceived(count, uid);
@@ -191,13 +233,18 @@
      if (userInfoExtra == null) {
         throw new IntegralTaskRecordException(1, "用户信息不全");
      }
      Integer totalGoldCoin = 0;
      for (Long id : idList) {
         IntegralTaskRecord record = integralTaskRecordMapper.selectByPrimaryKey(id);
         if (record == null)
            continue;
         // 已领取
         Integer state = record.getState();
         if (state != null && state == 1)
            continue;
         if (addDetail(uid, record))
            totalGoldCoin += record.getGoldCoin();
      }
@@ -279,19 +326,18 @@
         }
         detail.setTitle(taskClass.getName() + "-第" + num + "天");
      } else {
         int num = 0;
         FrequencyEnum frequency = integralTask.getFrequency();
         if (frequency == FrequencyEnum.everyday) {
            num = integralTaskRecordMapper.countByTaskIdTodayNum(uid, taskId,
            int num = integralTaskRecordMapper.countByTaskIdTodayNum(uid, taskId,
                  TimeUtil.getWholeTime(record.getCreateTime().getTime()));
            if (num <= 0)
               num = 1;
            String title = taskClass.getName() + "-" + integralTask.getName() + "-第" + num + "次";
            detail.setTitle(title);
         } else if (frequency == FrequencyEnum.onlyOne) {
            num = 1;
            String title = taskClass.getName() + "-" + integralTask.getName();
            detail.setTitle(title);
         }
         if (num <= 0)
            num = 1;
         String title = taskClass.getName() + "-" + integralTask.getName() + "-" + num + "次";
         detail.setTitle(title);
      }
      detail.setUid(uid);
@@ -303,12 +349,17 @@
   }
   @Override
   public Integer countGetCountByTaskIdAndDay(Long taskId, Long uid, Date day) {
      if (day == null)
         return null;
      Date minTime = new Date(
            TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(day.getTime(), "yyyy-MM-dd"), "yyyy-MM-dd"));
      Date maxTime = new Date(minTime.getTime() + 1000 * 60 * 60 * 24L);
   public int countGetCountByTaskIdAndDay(Long taskId, Long uid, Date day) {
      Date minTime = null;
      Date maxTime = null;
      if (day == null) {
         minTime = new Date(TimeUtil.convertToTimeTemp("1970-01-01", "yyyy-MM-dd"));
         maxTime = new Date(TimeUtil.convertToTimeTemp("2100-01-01", "yyyy-MM-dd"));
      } else {
         minTime = new Date(
               TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(day.getTime(), "yyyy-MM-dd"), "yyyy-MM-dd"));
         maxTime = new Date(minTime.getTime() + 1000 * 60 * 60 * 24L);
      }
      return integralTaskRecordMapper.countGetCountByTaskIdAndDay(taskId, uid, minTime, maxTime);
   }
@@ -341,4 +392,122 @@
   public long countByCidAndUidAndCreateTime(Long cid, Long uid, Date minTime, Date maxTime) {
      return integralTaskRecordMapper.countByCidAndUidAndCreateTime(cid, uid, minTime, maxTime);
   }
   @Override
   public List<IntegralTaskRecord> listByUidAndTaskId(Long uid, Long taskId, int page, int count) {
      return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count);
   }
   @Async()
   @Override
   public void firstRebateOrderRewardBoss(Long uid, Long originUid, String beizu) {
      if (uid == null || originUid == null)
         return;
      String reward = configService.get("first_order_reward_boss");
      if (StringUtil.isNullOrEmpty(reward))
         return;
      firstOrderReward(uid, originUid, Integer.parseInt(reward), "一", beizu);
   }
   @Async()
   @Override
   public void firstRebateOrderRewardBossSuper(Long uid, Long originUid, String beizu) {
      if (uid == null || originUid == null)
         return;
      String reward = configService.get("first_order_reward_boss_super");
      if (StringUtil.isNullOrEmpty(reward))
         return;
      firstOrderReward(uid, originUid, Integer.parseInt(reward), "二", beizu);
   }
   @Async()
   @Override
   public void firstShareOrderReward(Long uid, String beizu) {
      if(uid == null)
         return;
      String reward = configService.get("first_share_order_reward");
      if (StringUtil.isNullOrEmpty(reward))
         return;
      firstOrderReward(uid, null, Integer.parseInt(reward), null, beizu);
   }
   @Async()
   @Override
   public void firstSharerOrderRewardBoss(Long uid, Long originUid, String beizu) {
      if (uid == null || originUid == null)
         return;
      String reward = configService.get("first_share_order_reward_boss");
      if (StringUtil.isNullOrEmpty(reward))
         return;
      firstOrderReward(uid, originUid, Integer.parseInt(reward), "一", beizu);
   }
   /**
    * 队员首单奖励金币
    * @param uid
    * @param addGoldCoin
    * @param level 所属哪级队员
    * @param beizu
    */
   private void firstOrderReward(Long uid, Long originUid, Integer addGoldCoin, String level, String beizu) {
      String uniqueKey = "firstOrder-"+ uid.toString();
      if (originUid != null)
         uniqueKey = uniqueKey + "-" + originUid;
      // 判断是否已领取
      IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey);
      if (detailRecord != null)
         return;
      UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
      if (userInfoExtra == null)
         return;
      Integer goldCoin = userInfoExtra.getGoldCoin();
      if (goldCoin == null)
         goldCoin = 0;
      goldCoin = goldCoin + addGoldCoin;
      try {
         UserInfoExtra extra = new UserInfoExtra();
         extra.setId(userInfoExtra.getId());
         extra.setGoldCoin(goldCoin);
         userInfoExtraService.saveUserInfoExtra(extra);
      } catch (UserInfoExtraException e) {
         LogHelper.errorDetailInfo(e);
         return;
      }
      // 金币详情
      IntegralDetail detail = new IntegralDetail();
      detail.setTitle("金币奖励");
      detail.setUid(uid);
      detail.setMoney(addGoldCoin);
      detail.setRemark(beizu);
      detail.setUniqueKey(uniqueKey);
      detail.setCreateTime(new Date());
      integralDetailService.insertSelective(detail);
      // 消息
      MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO();
      msgOther.setTitle("金币奖励");
      msgOther.setNum(addGoldCoin + "金币");
      msgOther.setTotal(goldCoin + "金币");
      if (StringUtil.isNullOrEmpty(level)) {
         msgOther.setSource("首笔分享订单,系统奖励金币 ");
         msgOther.setExplain("首笔分享订单得到的奖金不足0.01元时奖励 ");
      } else {
         msgOther.setSource(level + "级队员首次下单,系统奖励金币 ");
         msgOther.setExplain("仅新邀请队员首下单你得到的奖金不足0.01元时奖励 ");
      }
      userOtherMsgNotificationService.firstOrderRewardMsg(uid, null, msgOther);
   }
}