yujian
2019-11-11 3ce9e928e082ff8abf697dba560cbfbb412e89f8
fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java
@@ -1,5 +1,6 @@
package com.yeshi.fanli.service.impl.user.integral;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -15,7 +16,12 @@
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.DateUtil;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.Producer;
import com.google.gson.Gson;
import com.yeshi.fanli.dao.mybatis.integral.IntegralTaskRecordMapper;
import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
import com.yeshi.fanli.dto.mq.user.body.IntegralTaskMQMsg;
import com.yeshi.fanli.dto.msg.MsgOtherRewardIntegralDTO;
import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
import com.yeshi.fanli.entity.integral.IntegralDetail;
@@ -36,6 +42,7 @@
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
@Service
public class IntegralTaskRecordServiceImpl implements IntegralTaskRecordService {
@@ -62,6 +69,9 @@
   @Resource
   private ConfigService configService;
   @Resource(name = "producer")
   private Producer producer;
   @Override
   public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
      return integralTaskRecordMapper.getTotalGoldCoin(uid, cid, dateType);
@@ -79,7 +89,7 @@
      taskRecord.setCid(cid);
      taskRecord.setTaskId(taskId);
      taskRecord.setGoldCoin(goldCoin);
      taskRecord.setState(0);
      taskRecord.setState(IntegralTaskRecord.STATE_WAITING_RECIEVE);
      taskRecord.setCreateTime(new Date());
      taskRecord.setUpdateTime(new Date());
      integralTaskRecordMapper.insertSelective(taskRecord);
@@ -206,7 +216,7 @@
      // 更新金币
      userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
      return (userInfoExtra.getGoldCoin()==null?0:userInfoExtra.getGoldCoin()) + totalGoldCoin;
      return (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin()) + totalGoldCoin;
   }
   @Override
@@ -239,7 +249,7 @@
      // 更新金币
      userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
      return totalGoldCoin+(userInfoExtra.getGoldCoin()==null?0:userInfoExtra.getGoldCoin());
      return totalGoldCoin + (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin());
   }
   @Transactional
@@ -340,6 +350,7 @@
      return integralTaskRecordMapper.countGetCountByTaskIdAndDay(taskId, uid, minTime, maxTime);
   }
   @Transactional
   @Override
   public IntegralTaskRecord addRecord(IntegralTaskRecord record) throws IntegralTaskRecordException {
      if (record == null)
@@ -355,6 +366,14 @@
      if (record.getUpdateTime() == null)
         record.setUpdateTime(new Date());
      integralTaskRecordMapper.insertSelective(record);
      long count = integralTaskRecordMapper.getTotalGoldCoinByUid(record.getUid());
      if (count >= 200) {// 大于200发送消息
         IntegralTaskMQMsg msg = new IntegralTaskMQMsg(record.getUid(), count, new Date());
         Message message = new Message(MQTopicName.TOPIC_USER.name(), UserTopicTagEnum.integralTaskFinish.name(),
               new Gson().toJson(msg).getBytes());
         producer.send(message);
      }
      return record;
   }
@@ -375,14 +394,11 @@
      return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count);
   }
   @Override
   public long getTotalGoldCoinByUid(Long uid) {
      return integralTaskRecordMapper.getTotalGoldCoinByUid(uid);
   }
   @Async()
   @Override
   public void firstRebateOrderRewardBoss(Long uid, Long originUid, String beizu) {
@@ -493,4 +509,56 @@
      }
      userOtherMsgNotificationService.firstOrderRewardMsg(uid, null, msgOther);
   }
   /**
    * 推广红包折算金币
    *
    * @param uid
    * @param addGoldCoin
    * @param tlj
    */
   @Override
   public void taoLiJinExchange(Long uid, Integer addGoldCoin, BigDecimal tlj) {
      String uniqueKey = "taoLiJinExchange-" + uid.toString();
      IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey);
      if (detailRecord != null)
         return;
      UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(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.setUniqueKey(uniqueKey);
      detail.setCreateTime(new Date());
      integralDetailService.insertSelective(detail);
      // 消息
      MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO();
      msgOther.setTitle("推广红包");
      msgOther.setTotal("推广红包¥" + tlj.setScale(2));
      msgOther.setNum(addGoldCoin + "枚");
      msgOther.setSource("已进入到可用金币中");
      msgOther.setExplain("原推广红包功能下线,剩余推广红包按照10:1折算为金币 ");
      userOtherMsgNotificationService.taoLiJinExchangeMsg(uid, "本折算有且仅有一次", msgOther);
   }
}